]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinmainwindow.cpp
coding style cleanup: fix wrong indenting of members in constructor
[dolphin.git] / src / dolphinmainwindow.cpp
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz <peter.penz@gmx.at> *
3 * Copyright (C) 2006 by Stefan Monov <logixoul@gmail.com> *
4 * Copyright (C) 2006 by Cvetoslav Ludmiloff <ludmiloff@gmail.com> *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the *
18 * Free Software Foundation, Inc., *
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
20 ***************************************************************************/
21
22 #include <config-kmetadata.h>
23 #include "dolphinmainwindow.h"
24
25 #include "dolphinapplication.h"
26 #include "dolphinnewmenu.h"
27 #include "dolphinsettings.h"
28 #include "dolphinsettingsdialog.h"
29 #include "dolphinstatusbar.h"
30 #include "infosidebarpage.h"
31 #include "metadatawidget.h"
32 #include "mainwindowadaptor.h"
33 #include "treeviewsidebarpage.h"
34 #include "kurlnavigator.h"
35 #include "viewpropertiesdialog.h"
36 #include "viewproperties.h"
37 #include "kfileplacesmodel.h"
38 #include "kfileplacesview.h"
39
40 #include "dolphin_generalsettings.h"
41
42 #include <kaction.h>
43 #include <kactioncollection.h>
44 #include <kconfig.h>
45 #include <kdesktopfile.h>
46 #include <kdeversion.h>
47 #include <kfiledialog.h>
48 #include <kglobal.h>
49 #include <kicon.h>
50 #include <kiconloader.h>
51 #include <kio/netaccess.h>
52 #include <kio/deletejob.h>
53 #include <kio/renamedialog.h>
54 #include <kinputdialog.h>
55 #include <klocale.h>
56 #include <kmenu.h>
57 #include <kmessagebox.h>
58 #include <konqmimedata.h>
59 #include <konq_operations.h>
60 #include <kpropertiesdialog.h>
61 #include <kprotocolinfo.h>
62 #include <ktoggleaction.h>
63 #include <krun.h>
64 #include <kshell.h>
65 #include <kstandarddirs.h>
66 #include <kstatusbar.h>
67 #include <kstandardaction.h>
68 #include <kurl.h>
69
70 #include <QCloseEvent>
71 #include <QClipboard>
72 #include <QSplitter>
73 #include <QDockWidget>
74
75 DolphinMainWindow::DolphinMainWindow(int id) :
76 KXmlGuiWindow(0),
77 m_newMenu(0),
78 m_splitter(0),
79 m_activeView(0),
80 m_id(id)
81 {
82 setObjectName("Dolphin");
83 m_view[PrimaryIdx] = 0;
84 m_view[SecondaryIdx] = 0;
85
86 new MainWindowAdaptor(this);
87 QDBusConnection::sessionBus().registerObject(QString("/dolphin/MainWindow%1").arg(m_id), this);
88
89 KonqUndoManager::incRef();
90
91 KonqUndoManager* undoManager = KonqUndoManager::self();
92 undoManager->setUiInterface(new UndoUiInterface(this));
93
94 connect(undoManager, SIGNAL(undoAvailable(bool)),
95 this, SLOT(slotUndoAvailable(bool)));
96 connect(undoManager, SIGNAL(undoTextChanged(const QString&)),
97 this, SLOT(slotUndoTextChanged(const QString&)));
98 }
99
100 DolphinMainWindow::~DolphinMainWindow()
101 {
102 KonqUndoManager::decRef();
103 DolphinApplication::app()->removeMainWindow(this);
104 }
105
106 void DolphinMainWindow::setActiveView(DolphinView* view)
107 {
108 Q_ASSERT((view == m_view[PrimaryIdx]) || (view == m_view[SecondaryIdx]));
109 if (m_activeView == view) {
110 return;
111 }
112
113 m_activeView = view;
114
115 updateHistory();
116 updateEditActions();
117 updateViewActions();
118 updateGoActions();
119
120 setCaption(m_activeView->url().fileName());
121
122 emit activeViewChanged();
123 }
124
125 void DolphinMainWindow::dropUrls(const KUrl::List& urls,
126 const KUrl& destination)
127 {
128 Qt::DropAction action = Qt::CopyAction;
129
130 Qt::KeyboardModifiers modifier = QApplication::keyboardModifiers();
131 const bool shiftPressed = modifier & Qt::ShiftModifier;
132 const bool controlPressed = modifier & Qt::ControlModifier;
133 if (shiftPressed && controlPressed) {
134 // shortcut for 'Link Here' is used
135 action = Qt::LinkAction;
136 } else if (shiftPressed) {
137 // shortcut for 'Move Here' is used
138 action = Qt::MoveAction;
139 } else if (controlPressed) {
140 // shortcut for 'Copy Here' is used
141 action = Qt::CopyAction;
142 } else {
143 // open a context menu which offers the following actions:
144 // - Move Here
145 // - Copy Here
146 // - Link Here
147 // - Cancel
148
149 KMenu popup(this);
150
151 QString seq = QKeySequence(Qt::ShiftModifier).toString();
152 seq.chop(1); // chop superfluous '+'
153 QAction* moveAction = popup.addAction(KIcon("goto-page"),
154 i18n("&Move Here") + '\t' + seq);
155
156 seq = QKeySequence(Qt::ControlModifier).toString();
157 seq.chop(1);
158 QAction* copyAction = popup.addAction(KIcon("edit-copy"),
159 i18n("&Copy Here") + '\t' + seq);
160
161 seq = QKeySequence(Qt::ControlModifier + Qt::ShiftModifier).toString();
162 seq.chop(1);
163 QAction* linkAction = popup.addAction(KIcon("www"),
164 i18n("&Link Here") + '\t' + seq);
165
166 popup.addSeparator();
167 popup.addAction(KIcon("process-stop"), i18n("Cancel"));
168
169 QAction* activatedAction = popup.exec(QCursor::pos());
170 if (activatedAction == moveAction) {
171 action = Qt::MoveAction;
172 } else if (activatedAction == copyAction) {
173 action = Qt::CopyAction;
174 } else if (activatedAction == linkAction) {
175 action = Qt::LinkAction;
176 } else {
177 return;
178 }
179 }
180
181 switch (action) {
182 case Qt::MoveAction:
183 moveUrls(urls, destination);
184 break;
185
186 case Qt::CopyAction:
187 copyUrls(urls, destination);
188 break;
189
190 case Qt::LinkAction:
191 linkUrls(urls, destination);
192 break;
193
194 default:
195 break;
196 }
197 }
198
199 void DolphinMainWindow::rename(const KUrl& oldUrl, const KUrl& newUrl)
200 {
201 clearStatusBar();
202 KonqOperations::rename(this, oldUrl, newUrl);
203 m_undoCommandTypes.append(KonqUndoManager::RENAME);
204 }
205
206 void DolphinMainWindow::refreshViews()
207 {
208 const bool split = DolphinSettings::instance().generalSettings()->splitView();
209 const bool isPrimaryViewActive = (m_activeView == m_view[PrimaryIdx]);
210 KUrl url;
211 for (int i = PrimaryIdx; i <= SecondaryIdx; ++i) {
212 if (m_view[i] != 0) {
213 url = m_view[i]->url();
214
215 // delete view instance...
216 m_view[i]->close();
217 m_view[i]->deleteLater();
218 m_view[i] = 0;
219 }
220
221 if (split || (i == PrimaryIdx)) {
222 // ... and recreate it
223 ViewProperties props(url);
224 m_view[i] = new DolphinView(this,
225 m_splitter,
226 url,
227 props.viewMode(),
228 props.showHiddenFiles());
229 connectViewSignals(i);
230 m_view[i]->reload();
231 m_view[i]->show();
232 }
233 }
234
235 m_activeView = isPrimaryViewActive ? m_view[PrimaryIdx] : m_view[SecondaryIdx];
236 Q_ASSERT(m_activeView != 0);
237
238 updateViewActions();
239 emit activeViewChanged();
240 }
241
242 void DolphinMainWindow::changeUrl(const KUrl& url)
243 {
244 if (activeView() != 0) {
245 activeView()->setUrl(url);
246 updateEditActions();
247 updateViewActions();
248 updateGoActions();
249 setCaption(url.fileName());
250 emit urlChanged(url);
251 }
252 }
253
254 void DolphinMainWindow::changeSelection(const KFileItemList& selection)
255 {
256 activeView()->changeSelection(selection);
257 }
258
259 void DolphinMainWindow::slotViewModeChanged()
260 {
261 updateViewActions();
262 }
263
264 void DolphinMainWindow::slotShowPreviewChanged()
265 {
266 // It is not enough to update the 'Show Preview' action, also
267 // the 'Zoom In' and 'Zoom Out' actions must be adapted.
268 updateViewActions();
269 }
270
271 void DolphinMainWindow::slotShowHiddenFilesChanged()
272 {
273 KToggleAction* showHiddenFilesAction =
274 static_cast<KToggleAction*>(actionCollection()->action("show_hidden_files"));
275 showHiddenFilesAction->setChecked(m_activeView->showHiddenFiles());
276 }
277
278 void DolphinMainWindow::slotCategorizedSortingChanged()
279 {
280 KToggleAction* categorizedSortingAction =
281 static_cast<KToggleAction*>(actionCollection()->action("categorized"));
282 categorizedSortingAction->setChecked(m_activeView->categorizedSorting());
283 categorizedSortingAction->setEnabled(m_activeView->supportsCategorizedSorting());
284 }
285
286 void DolphinMainWindow::slotSortingChanged(DolphinView::Sorting sorting)
287 {
288 QAction* action = 0;
289 switch (sorting) {
290 case DolphinView::SortByName:
291 action = actionCollection()->action("by_name");
292 break;
293 case DolphinView::SortBySize:
294 action = actionCollection()->action("by_size");
295 break;
296 case DolphinView::SortByDate:
297 action = actionCollection()->action("by_date");
298 break;
299 case DolphinView::SortByPermissions:
300 action = actionCollection()->action("by_permissions");
301 break;
302 case DolphinView::SortByOwner:
303 action = actionCollection()->action("by_owner");
304 break;
305 case DolphinView::SortByGroup:
306 action = actionCollection()->action("by_group");
307 break;
308 case DolphinView::SortByType:
309 action = actionCollection()->action("by_type");
310 default:
311 break;
312 }
313
314 if (action != 0) {
315 KToggleAction* toggleAction = static_cast<KToggleAction*>(action);
316 toggleAction->setChecked(true);
317 }
318 }
319
320 void DolphinMainWindow::slotSortOrderChanged(Qt::SortOrder order)
321 {
322 KToggleAction* descending = static_cast<KToggleAction*>(actionCollection()->action("descending"));
323 const bool sortDescending = (order == Qt::DescendingOrder);
324 descending->setChecked(sortDescending);
325 }
326
327 void DolphinMainWindow::slotAdditionalInfoChanged(KFileItemDelegate::AdditionalInformation info)
328 {
329 QAction* action = 0;
330 switch (info) {
331 case KFileItemDelegate::FriendlyMimeType:
332 action = actionCollection()->action("show_mime_info");
333 break;
334 case KFileItemDelegate::Size:
335 action = actionCollection()->action("show_size_info");
336 break;
337 case KFileItemDelegate::ModificationTime:
338 action = actionCollection()->action("show_date_info");
339 break;
340 case KFileItemDelegate::NoInformation:
341 default:
342 action = actionCollection()->action("clear_info");
343 break;
344 }
345
346 if (action != 0) {
347 KToggleAction* toggleAction = static_cast<KToggleAction*>(action);
348 toggleAction->setChecked(true);
349
350 QActionGroup* group = toggleAction->actionGroup();
351 Q_ASSERT(group != 0);
352 group->setEnabled(m_activeView->mode() == DolphinView::IconsView);
353 }
354 }
355
356 void DolphinMainWindow::slotSelectionChanged(const KFileItemList& selection)
357 {
358 updateEditActions();
359
360 Q_ASSERT(m_view[PrimaryIdx] != 0);
361 int selectedUrlsCount = m_view[PrimaryIdx]->selectedUrls().count();
362 if (m_view[SecondaryIdx] != 0) {
363 selectedUrlsCount += m_view[SecondaryIdx]->selectedUrls().count();
364 }
365
366 QAction* compareFilesAction = actionCollection()->action("compare_files");
367 compareFilesAction->setEnabled(selectedUrlsCount == 2);
368
369 m_activeView->updateStatusBar();
370
371 emit selectionChanged(selection);
372 }
373
374 void DolphinMainWindow::slotHistoryChanged()
375 {
376 updateHistory();
377 }
378
379 void DolphinMainWindow::updateFilterBarAction(bool show)
380 {
381 KToggleAction* showFilterBarAction =
382 static_cast<KToggleAction*>(actionCollection()->action("show_filter_bar"));
383 showFilterBarAction->setChecked(show);
384 }
385
386 void DolphinMainWindow::openNewMainWindow()
387 {
388 DolphinApplication::app()->createMainWindow()->show();
389 }
390
391 void DolphinMainWindow::closeEvent(QCloseEvent* event)
392 {
393 DolphinSettings& settings = DolphinSettings::instance();
394 GeneralSettings* generalSettings = settings.generalSettings();
395 generalSettings->setFirstRun(false);
396
397 settings.save();
398
399 KXmlGuiWindow::closeEvent(event);
400 }
401
402 void DolphinMainWindow::saveProperties(KConfig* config)
403 {
404 KConfigGroup primaryView = config->group("Primary view");
405 primaryView.writeEntry("Url", m_view[PrimaryIdx]->url().url());
406 primaryView.writeEntry("Editable Url", m_view[PrimaryIdx]->isUrlEditable());
407 if (m_view[SecondaryIdx] != 0) {
408 KConfigGroup secondaryView = config->group("Secondary view");
409 secondaryView.writeEntry("Url", m_view[SecondaryIdx]->url().url());
410 secondaryView.writeEntry("Editable Url", m_view[SecondaryIdx]->isUrlEditable());
411 }
412 }
413
414 void DolphinMainWindow::readProperties(KConfig* config)
415 {
416 const KConfigGroup primaryView = config->group("Primary view");
417 m_view[PrimaryIdx]->setUrl(primaryView.readEntry("Url"));
418 m_view[PrimaryIdx]->setUrlEditable(primaryView.readEntry("Editable Url", false));
419 if (config->hasGroup("Secondary view")) {
420 const KConfigGroup secondaryView = config->group("Secondary view");
421 if (m_view[SecondaryIdx] == 0) {
422 toggleSplitView();
423 }
424 m_view[SecondaryIdx]->setUrl(secondaryView.readEntry("Url"));
425 m_view[SecondaryIdx]->setUrlEditable(secondaryView.readEntry("Editable Url", false));
426 } else if (m_view[SecondaryIdx] != 0) {
427 toggleSplitView();
428 }
429 }
430
431 void DolphinMainWindow::updateNewMenu()
432 {
433 m_newMenu->slotCheckUpToDate();
434 m_newMenu->setPopupFiles(activeView()->url());
435 }
436
437 void DolphinMainWindow::rename()
438 {
439 clearStatusBar();
440 m_activeView->renameSelectedItems();
441 }
442
443 void DolphinMainWindow::moveToTrash()
444 {
445 clearStatusBar();
446 const KUrl::List selectedUrls = m_activeView->selectedUrls();
447 KonqOperations::del(this, KonqOperations::TRASH, selectedUrls);
448 m_undoCommandTypes.append(KonqUndoManager::TRASH);
449 }
450
451 void DolphinMainWindow::deleteItems()
452 {
453 clearStatusBar();
454
455 const KUrl::List list = m_activeView->selectedUrls();
456 const bool del = KonqOperations::askDeleteConfirmation(list,
457 KonqOperations::DEL,
458 KonqOperations::DEFAULT_CONFIRMATION,
459 this);
460
461 if (del) {
462 KIO::Job* job = KIO::del(list);
463 connect(job, SIGNAL(result(KJob*)),
464 this, SLOT(slotHandleJobError(KJob*)));
465 connect(job, SIGNAL(result(KJob*)),
466 this, SLOT(slotDeleteFileFinished(KJob*)));
467 }
468 }
469
470 void DolphinMainWindow::properties()
471 {
472 const KFileItemList list = m_activeView->selectedItems();
473 new KPropertiesDialog(list, this);
474 }
475
476 void DolphinMainWindow::quit()
477 {
478 close();
479 }
480
481 void DolphinMainWindow::slotHandleJobError(KJob* job)
482 {
483 if (job->error() != 0) {
484 DolphinStatusBar* statusBar = m_activeView->statusBar();
485 statusBar->setMessage(job->errorString(),
486 DolphinStatusBar::Error);
487 }
488 }
489
490 void DolphinMainWindow::slotDeleteFileFinished(KJob* job)
491 {
492 if (job->error() == 0) {
493 DolphinStatusBar* statusBar = m_activeView->statusBar();
494 statusBar->setMessage(i18n("Delete operation completed."),
495 DolphinStatusBar::OperationCompleted);
496 }
497 }
498
499 void DolphinMainWindow::slotUndoAvailable(bool available)
500 {
501 QAction* undoAction = actionCollection()->action(KStandardAction::stdName(KStandardAction::Undo));
502 if (undoAction != 0) {
503 undoAction->setEnabled(available);
504 }
505
506 if (available && (m_undoCommandTypes.count() > 0)) {
507 const KonqUndoManager::CommandType command = m_undoCommandTypes.takeFirst();
508 DolphinStatusBar* statusBar = m_activeView->statusBar();
509 switch (command) {
510 case KonqUndoManager::COPY:
511 statusBar->setMessage(i18n("Copy operation completed."),
512 DolphinStatusBar::OperationCompleted);
513 break;
514 case KonqUndoManager::MOVE:
515 statusBar->setMessage(i18n("Move operation completed."),
516 DolphinStatusBar::OperationCompleted);
517 break;
518 case KonqUndoManager::LINK:
519 statusBar->setMessage(i18n("Link operation completed."),
520 DolphinStatusBar::OperationCompleted);
521 break;
522 case KonqUndoManager::TRASH:
523 statusBar->setMessage(i18n("Move to trash operation completed."),
524 DolphinStatusBar::OperationCompleted);
525 break;
526 case KonqUndoManager::RENAME:
527 statusBar->setMessage(i18n("Renaming operation completed."),
528 DolphinStatusBar::OperationCompleted);
529 break;
530
531 case KonqUndoManager::MKDIR:
532 statusBar->setMessage(i18n("Created folder."),
533 DolphinStatusBar::OperationCompleted);
534 break;
535
536 default:
537 break;
538 }
539
540 }
541 }
542
543 void DolphinMainWindow::slotUndoTextChanged(const QString& text)
544 {
545 QAction* undoAction = actionCollection()->action(KStandardAction::stdName(KStandardAction::Undo));
546 if (undoAction != 0) {
547 undoAction->setText(text);
548 }
549 }
550
551 void DolphinMainWindow::undo()
552 {
553 clearStatusBar();
554 KonqUndoManager::self()->undo();
555 }
556
557 void DolphinMainWindow::cut()
558 {
559 QMimeData* mimeData = new QMimeData();
560 const KUrl::List kdeUrls = m_activeView->selectedUrls();
561 const KUrl::List mostLocalUrls;
562 KonqMimeData::populateMimeData(mimeData, kdeUrls, mostLocalUrls, true);
563 QApplication::clipboard()->setMimeData(mimeData);
564 }
565
566 void DolphinMainWindow::copy()
567 {
568 QMimeData* mimeData = new QMimeData();
569 const KUrl::List kdeUrls = m_activeView->selectedUrls();
570 const KUrl::List mostLocalUrls;
571 KonqMimeData::populateMimeData(mimeData, kdeUrls, mostLocalUrls, false);
572
573 QApplication::clipboard()->setMimeData(mimeData);
574 }
575
576 void DolphinMainWindow::paste()
577 {
578 QClipboard* clipboard = QApplication::clipboard();
579 const QMimeData* mimeData = clipboard->mimeData();
580
581 clearStatusBar();
582
583 const KUrl::List sourceUrls = KUrl::List::fromMimeData(mimeData);
584
585 // per default the pasting is done into the current Url of the view
586 KUrl destUrl(m_activeView->url());
587
588 // check whether the pasting should be done into a selected directory
589 KUrl::List selectedUrls = m_activeView->selectedUrls();
590 if (selectedUrls.count() == 1) {
591 const KFileItem fileItem(S_IFDIR,
592 KFileItem::Unknown,
593 selectedUrls.first(),
594 true);
595 if (fileItem.isDir()) {
596 // only one item is selected which is a directory, hence paste
597 // into this directory
598 destUrl = selectedUrls.first();
599 }
600 }
601
602 if (KonqMimeData::decodeIsCutSelection(mimeData)) {
603 moveUrls(sourceUrls, destUrl);
604 clipboard->clear();
605 } else {
606 copyUrls(sourceUrls, destUrl);
607 }
608 }
609
610 void DolphinMainWindow::updatePasteAction()
611 {
612 QAction* pasteAction = actionCollection()->action(KStandardAction::stdName(KStandardAction::Paste));
613 if (pasteAction == 0) {
614 return;
615 }
616
617 QString text(i18n("Paste"));
618 QClipboard* clipboard = QApplication::clipboard();
619 const QMimeData* mimeData = clipboard->mimeData();
620
621 KUrl::List urls = KUrl::List::fromMimeData(mimeData);
622 if (!urls.isEmpty()) {
623 pasteAction->setEnabled(true);
624
625 pasteAction->setText(i18np("Paste One File", "Paste %1 Files", urls.count()));
626 } else {
627 pasteAction->setEnabled(false);
628 pasteAction->setText(i18n("Paste"));
629 }
630
631 if (pasteAction->isEnabled()) {
632 KUrl::List urls = m_activeView->selectedUrls();
633 const uint count = urls.count();
634 if (count > 1) {
635 // pasting should not be allowed when more than one file
636 // is selected
637 pasteAction->setEnabled(false);
638 } else if (count == 1) {
639 // Only one file is selected. Pasting is only allowed if this
640 // file is a directory.
641 // TODO: this doesn't work with remote protocols; instead we need a
642 // m_activeView->selectedFileItems() to get the real KFileItems
643 const KFileItem fileItem(S_IFDIR,
644 KFileItem::Unknown,
645 urls.first(),
646 true);
647 pasteAction->setEnabled(fileItem.isDir());
648 }
649 }
650 }
651
652 void DolphinMainWindow::selectAll()
653 {
654 clearStatusBar();
655 m_activeView->selectAll();
656 }
657
658 void DolphinMainWindow::invertSelection()
659 {
660 clearStatusBar();
661 m_activeView->invertSelection();
662 }
663 void DolphinMainWindow::setIconsView()
664 {
665 m_activeView->setMode(DolphinView::IconsView);
666 }
667
668 void DolphinMainWindow::setDetailsView()
669 {
670 m_activeView->setMode(DolphinView::DetailsView);
671 }
672
673 void DolphinMainWindow::setColumnView()
674 {
675 m_activeView->setMode(DolphinView::ColumnView);
676 }
677
678 void DolphinMainWindow::sortByName()
679 {
680 m_activeView->setSorting(DolphinView::SortByName);
681 }
682
683 void DolphinMainWindow::sortBySize()
684 {
685 m_activeView->setSorting(DolphinView::SortBySize);
686 }
687
688 void DolphinMainWindow::sortByDate()
689 {
690 m_activeView->setSorting(DolphinView::SortByDate);
691 }
692
693 void DolphinMainWindow::sortByPermissions()
694 {
695 m_activeView->setSorting(DolphinView::SortByPermissions);
696 }
697
698 void DolphinMainWindow::sortByOwner()
699 {
700 m_activeView->setSorting(DolphinView::SortByOwner);
701 }
702
703 void DolphinMainWindow::sortByGroup()
704 {
705 m_activeView->setSorting(DolphinView::SortByGroup);
706 }
707
708 void DolphinMainWindow::sortByType()
709 {
710 m_activeView->setSorting(DolphinView::SortByType);
711 }
712
713 void DolphinMainWindow::toggleSortOrder()
714 {
715 const Qt::SortOrder order = (m_activeView->sortOrder() == Qt::AscendingOrder) ?
716 Qt::DescendingOrder :
717 Qt::AscendingOrder;
718 m_activeView->setSortOrder(order);
719 }
720
721 void DolphinMainWindow::toggleSortCategorization()
722 {
723 const bool categorizedSorting = m_activeView->categorizedSorting();
724 m_activeView->setCategorizedSorting(!categorizedSorting);
725 }
726
727 void DolphinMainWindow::clearInfo()
728 {
729 m_activeView->setAdditionalInfo(KFileItemDelegate::NoInformation);
730 }
731
732 void DolphinMainWindow::showMimeInfo()
733 {
734 clearStatusBar();
735 m_activeView->setAdditionalInfo(KFileItemDelegate::FriendlyMimeType);
736 }
737
738 void DolphinMainWindow::showSizeInfo()
739 {
740 clearStatusBar();
741 m_activeView->setAdditionalInfo(KFileItemDelegate::Size);
742 }
743
744 void DolphinMainWindow::showDateInfo()
745 {
746 clearStatusBar();
747 m_activeView->setAdditionalInfo(KFileItemDelegate::ModificationTime);
748 }
749
750 void DolphinMainWindow::toggleSplitView()
751 {
752 if (m_view[SecondaryIdx] == 0) {
753 const int newWidth = (m_view[PrimaryIdx]->width() - m_splitter->handleWidth()) / 2;
754 // create a secondary view
755 m_view[SecondaryIdx] = new DolphinView(this,
756 0,
757 m_view[PrimaryIdx]->url(),
758 m_view[PrimaryIdx]->mode(),
759 m_view[PrimaryIdx]->showHiddenFiles());
760 connectViewSignals(SecondaryIdx);
761 m_splitter->addWidget(m_view[SecondaryIdx]);
762 m_splitter->setSizes(QList<int>() << newWidth << newWidth);
763 m_view[SecondaryIdx]->reload();
764 m_view[SecondaryIdx]->show();
765 } else {
766 // remove secondary view
767 if (m_activeView == m_view[PrimaryIdx]) {
768 m_view[SecondaryIdx]->close();
769 m_view[SecondaryIdx]->deleteLater();
770 m_view[SecondaryIdx] = 0;
771 setActiveView(m_view[PrimaryIdx]);
772 } else {
773 // The secondary view is active, hence from the users point of view
774 // the content of the secondary view should be moved to the primary view.
775 // From an implementation point of view it is more efficient to close
776 // the primary view and exchange the internal pointers afterwards.
777 m_view[PrimaryIdx]->close();
778 delete m_view[PrimaryIdx];
779 m_view[PrimaryIdx] = m_view[SecondaryIdx];
780 m_view[SecondaryIdx] = 0;
781 setActiveView(m_view[PrimaryIdx]);
782 }
783 }
784 emit activeViewChanged();
785 }
786
787 void DolphinMainWindow::reloadView()
788 {
789 clearStatusBar();
790 m_activeView->reload();
791 }
792
793 void DolphinMainWindow::stopLoading()
794 {}
795
796 void DolphinMainWindow::togglePreview()
797 {
798 clearStatusBar();
799
800 const KToggleAction* showPreviewAction =
801 static_cast<KToggleAction*>(actionCollection()->action("show_preview"));
802 const bool show = showPreviewAction->isChecked();
803 m_activeView->setShowPreview(show);
804 }
805
806 void DolphinMainWindow::toggleShowHiddenFiles()
807 {
808 clearStatusBar();
809
810 const KToggleAction* showHiddenFilesAction =
811 static_cast<KToggleAction*>(actionCollection()->action("show_hidden_files"));
812 const bool show = showHiddenFilesAction->isChecked();
813 m_activeView->setShowHiddenFiles(show);
814 }
815
816 void DolphinMainWindow::showFilterBar()
817 {
818 const KToggleAction* showFilterBarAction =
819 static_cast<KToggleAction*>(actionCollection()->action("show_filter_bar"));
820 const bool show = showFilterBarAction->isChecked();
821 m_activeView->showFilterBar(show);
822 }
823
824 void DolphinMainWindow::zoomIn()
825 {
826 m_activeView->zoomIn();
827 updateViewActions();
828 }
829
830 void DolphinMainWindow::zoomOut()
831 {
832 m_activeView->zoomOut();
833 updateViewActions();
834 }
835
836 void DolphinMainWindow::toggleEditLocation()
837 {
838 clearStatusBar();
839
840 KToggleAction* action = static_cast<KToggleAction*>(actionCollection()->action("editable_location"));
841
842 bool editOrBrowse = action->isChecked();
843 m_activeView->setUrlEditable(editOrBrowse);
844 }
845
846 void DolphinMainWindow::editLocation()
847 {
848 m_activeView->setUrlEditable(true);
849 }
850
851 void DolphinMainWindow::adjustViewProperties()
852 {
853 clearStatusBar();
854 ViewPropertiesDialog dlg(m_activeView);
855 dlg.exec();
856 }
857
858 void DolphinMainWindow::goBack()
859 {
860 clearStatusBar();
861 m_activeView->goBack();
862 }
863
864 void DolphinMainWindow::goForward()
865 {
866 clearStatusBar();
867 m_activeView->goForward();
868 }
869
870 void DolphinMainWindow::goUp()
871 {
872 clearStatusBar();
873 m_activeView->goUp();
874 }
875
876 void DolphinMainWindow::goHome()
877 {
878 clearStatusBar();
879 m_activeView->goHome();
880 }
881
882 void DolphinMainWindow::openTerminal()
883 {
884 QString command("konsole --workdir \"");
885 command.append(m_activeView->url().path());
886 command.append('\"');
887
888 KRun::runCommand(command, "Konsole", "konsole");
889 }
890
891 void DolphinMainWindow::findFile()
892 {
893 KRun::run("kfind", m_activeView->url());
894 }
895
896 void DolphinMainWindow::compareFiles()
897 {
898 // The method is only invoked if exactly 2 files have
899 // been selected. The selected files may be:
900 // - both in the primary view
901 // - both in the secondary view
902 // - one in the primary view and the other in the secondary
903 // view
904 Q_ASSERT(m_view[PrimaryIdx] != 0);
905
906 KUrl urlA;
907 KUrl urlB;
908 KUrl::List urls = m_view[PrimaryIdx]->selectedUrls();
909
910 switch (urls.count()) {
911 case 0: {
912 Q_ASSERT(m_view[SecondaryIdx] != 0);
913 urls = m_view[SecondaryIdx]->selectedUrls();
914 Q_ASSERT(urls.count() == 2);
915 urlA = urls[0];
916 urlB = urls[1];
917 break;
918 }
919
920 case 1: {
921 urlA = urls[0];
922 Q_ASSERT(m_view[SecondaryIdx] != 0);
923 urls = m_view[SecondaryIdx]->selectedUrls();
924 Q_ASSERT(urls.count() == 1);
925 urlB = urls[0];
926 break;
927 }
928
929 case 2: {
930 urlA = urls[0];
931 urlB = urls[1];
932 break;
933 }
934
935 default: {
936 // may not happen: compareFiles may only get invoked if 2
937 // files are selected
938 Q_ASSERT(false);
939 }
940 }
941
942 QString command("kompare -c \"");
943 command.append(urlA.pathOrUrl());
944 command.append("\" \"");
945 command.append(urlB.pathOrUrl());
946 command.append('\"');
947 KRun::runCommand(command, "Kompare", "kompare");
948
949 }
950
951 void DolphinMainWindow::editSettings()
952 {
953 DolphinSettingsDialog dialog(this);
954 dialog.exec();
955 }
956
957 void DolphinMainWindow::init()
958 {
959 // Check whether Dolphin runs the first time. If yes then
960 // a proper default window size is given at the end of DolphinMainWindow::init().
961 GeneralSettings* generalSettings = DolphinSettings::instance().generalSettings();
962 const bool firstRun = generalSettings->firstRun();
963 if (firstRun) {
964 generalSettings->setViewPropsTimestamp(QDateTime::currentDateTime());
965 }
966
967 setAcceptDrops(true);
968
969 m_splitter = new QSplitter(this);
970
971 DolphinSettings& settings = DolphinSettings::instance();
972
973 setupActions();
974
975 const KUrl& homeUrl = settings.generalSettings()->homeUrl();
976 setCaption(homeUrl.fileName());
977 ViewProperties props(homeUrl);
978 m_view[PrimaryIdx] = new DolphinView(this,
979 m_splitter,
980 homeUrl,
981 props.viewMode(),
982 props.showHiddenFiles());
983
984 m_activeView = m_view[PrimaryIdx];
985 connectViewSignals(PrimaryIdx);
986 m_view[PrimaryIdx]->reload();
987 m_view[PrimaryIdx]->show();
988
989 setCentralWidget(m_splitter);
990 setupDockWidgets();
991
992 setupGUI(Keys | Save | Create | ToolBar);
993 createGUI();
994
995 stateChanged("new_file");
996 setAutoSaveSettings();
997
998 QClipboard* clipboard = QApplication::clipboard();
999 connect(clipboard, SIGNAL(dataChanged()),
1000 this, SLOT(updatePasteAction()));
1001 updatePasteAction();
1002 updateGoActions();
1003
1004 loadSettings();
1005
1006 if (firstRun) {
1007 // assure a proper default size if Dolphin runs the first time
1008 resize(640, 480);
1009 }
1010 #ifdef HAVE_KMETADATA
1011 if (!MetaDataWidget::metaDataAvailable())
1012 activeView()->statusBar()->setMessage(i18n("Failed to contact Nepomuk service, annotation and tagging are disabled."), DolphinStatusBar::Error);
1013 #endif
1014
1015 emit urlChanged(homeUrl);
1016 }
1017
1018 void DolphinMainWindow::loadSettings()
1019 {
1020 GeneralSettings* settings = DolphinSettings::instance().generalSettings();
1021
1022 KToggleAction* splitAction = static_cast<KToggleAction*>(actionCollection()->action("split_view"));
1023 if (settings->splitView()) {
1024 splitAction->setChecked(true);
1025 toggleSplitView();
1026 }
1027
1028 updateViewActions();
1029 }
1030
1031 void DolphinMainWindow::setupActions()
1032 {
1033 // setup 'File' menu
1034 m_newMenu = new DolphinNewMenu(this);
1035 KMenu* menu = m_newMenu->menu();
1036 menu->setTitle(i18n("Create New"));
1037 menu->setIcon(KIcon("document-new"));
1038 connect(menu, SIGNAL(aboutToShow()),
1039 this, SLOT(updateNewMenu()));
1040
1041 QAction* newWindow = actionCollection()->addAction("new_window");
1042 newWindow->setIcon(KIcon("window-new"));
1043 newWindow->setText(i18n("New &Window"));
1044 newWindow->setShortcut(Qt::CTRL | Qt::Key_N);
1045 connect(newWindow, SIGNAL(triggered()), this, SLOT(openNewMainWindow()));
1046
1047 QAction* rename = actionCollection()->addAction("rename");
1048 rename->setText(i18n("Rename..."));
1049 rename->setShortcut(Qt::Key_F2);
1050 connect(rename, SIGNAL(triggered()), this, SLOT(rename()));
1051
1052 QAction* moveToTrash = actionCollection()->addAction("move_to_trash");
1053 moveToTrash->setText(i18n("Move to Trash"));
1054 moveToTrash->setIcon(KIcon("edit-trash"));
1055 moveToTrash->setShortcut(QKeySequence::Delete);
1056 connect(moveToTrash, SIGNAL(triggered()), this, SLOT(moveToTrash()));
1057
1058 QAction* deleteAction = actionCollection()->addAction("delete");
1059 deleteAction->setText(i18n("Delete"));
1060 deleteAction->setShortcut(Qt::SHIFT | Qt::Key_Delete);
1061 deleteAction->setIcon(KIcon("edit-delete"));
1062 connect(deleteAction, SIGNAL(triggered()), this, SLOT(deleteItems()));
1063
1064 QAction* properties = actionCollection()->addAction("properties");
1065 properties->setText(i18n("Properties"));
1066 properties->setShortcut(Qt::ALT | Qt::Key_Return);
1067 connect(properties, SIGNAL(triggered()), this, SLOT(properties()));
1068
1069 KStandardAction::quit(this, SLOT(quit()), actionCollection());
1070
1071 // setup 'Edit' menu
1072 KStandardAction::undo(this,
1073 SLOT(undo()),
1074 actionCollection());
1075
1076 KStandardAction::cut(this, SLOT(cut()), actionCollection());
1077 KStandardAction::copy(this, SLOT(copy()), actionCollection());
1078 KStandardAction::paste(this, SLOT(paste()), actionCollection());
1079
1080 QAction* selectAll = actionCollection()->addAction("select_all");
1081 selectAll->setText(i18n("Select All"));
1082 selectAll->setShortcut(Qt::CTRL + Qt::Key_A);
1083 connect(selectAll, SIGNAL(triggered()), this, SLOT(selectAll()));
1084
1085 QAction* invertSelection = actionCollection()->addAction("invert_selection");
1086 invertSelection->setText(i18n("Invert Selection"));
1087 invertSelection->setShortcut(Qt::CTRL | Qt::SHIFT | Qt::Key_A);
1088 connect(invertSelection, SIGNAL(triggered()), this, SLOT(invertSelection()));
1089
1090 // setup 'View' menu
1091 KStandardAction::zoomIn(this,
1092 SLOT(zoomIn()),
1093 actionCollection());
1094
1095 KStandardAction::zoomOut(this,
1096 SLOT(zoomOut()),
1097 actionCollection());
1098
1099 KToggleAction* iconsView = actionCollection()->add<KToggleAction>("icons");
1100 iconsView->setText(i18n("Icons"));
1101 iconsView->setShortcut(Qt::CTRL | Qt::Key_1);
1102 iconsView->setIcon(KIcon("view-icon"));
1103 connect(iconsView, SIGNAL(triggered()), this, SLOT(setIconsView()));
1104
1105 KToggleAction* detailsView = actionCollection()->add<KToggleAction>("details");
1106 detailsView->setText(i18n("Details"));
1107 detailsView->setShortcut(Qt::CTRL | Qt::Key_2);
1108 detailsView->setIcon(KIcon("fileview-text"));
1109 connect(detailsView, SIGNAL(triggered()), this, SLOT(setDetailsView()));
1110
1111 KToggleAction* columnView = actionCollection()->add<KToggleAction>("columns");
1112 columnView->setText(i18n("Columns"));
1113 columnView->setShortcut(Qt::CTRL | Qt::Key_3);
1114 columnView->setIcon(KIcon("fileview-column"));
1115 connect(columnView, SIGNAL(triggered()), this, SLOT(setColumnView()));
1116
1117 QActionGroup* viewModeGroup = new QActionGroup(this);
1118 viewModeGroup->addAction(iconsView);
1119 viewModeGroup->addAction(detailsView);
1120 viewModeGroup->addAction(columnView);
1121
1122 KToggleAction* sortByName = actionCollection()->add<KToggleAction>("by_name");
1123 sortByName->setText(i18n("By Name"));
1124 connect(sortByName, SIGNAL(triggered()), this, SLOT(sortByName()));
1125
1126 KToggleAction* sortBySize = actionCollection()->add<KToggleAction>("by_size");
1127 sortBySize->setText(i18n("By Size"));
1128 connect(sortBySize, SIGNAL(triggered()), this, SLOT(sortBySize()));
1129
1130 KToggleAction* sortByDate = actionCollection()->add<KToggleAction>("by_date");
1131 sortByDate->setText(i18n("By Date"));
1132 connect(sortByDate, SIGNAL(triggered()), this, SLOT(sortByDate()));
1133
1134 KToggleAction* sortByPermissions = actionCollection()->add<KToggleAction>("by_permissions");
1135 sortByPermissions->setText(i18n("By Permissions"));
1136 connect(sortByPermissions, SIGNAL(triggered()), this, SLOT(sortByPermissions()));
1137
1138 KToggleAction* sortByOwner = actionCollection()->add<KToggleAction>("by_owner");
1139 sortByOwner->setText(i18n("By Owner"));
1140 connect(sortByOwner, SIGNAL(triggered()), this, SLOT(sortByOwner()));
1141
1142 KToggleAction* sortByGroup = actionCollection()->add<KToggleAction>("by_group");
1143 sortByGroup->setText(i18n("By Group"));
1144 connect(sortByGroup, SIGNAL(triggered()), this, SLOT(sortByGroup()));
1145
1146 KToggleAction* sortByType = actionCollection()->add<KToggleAction>("by_type");
1147 sortByType->setText(i18n("By Type"));
1148 connect(sortByType, SIGNAL(triggered()), this, SLOT(sortByType()));
1149
1150 QActionGroup* sortGroup = new QActionGroup(this);
1151 sortGroup->addAction(sortByName);
1152 sortGroup->addAction(sortBySize);
1153 sortGroup->addAction(sortByDate);
1154 sortGroup->addAction(sortByPermissions);
1155 sortGroup->addAction(sortByOwner);
1156 sortGroup->addAction(sortByGroup);
1157 sortGroup->addAction(sortByType);
1158
1159 KToggleAction* sortDescending = actionCollection()->add<KToggleAction>("descending");
1160 sortDescending->setText(i18n("Descending"));
1161 connect(sortDescending, SIGNAL(triggered()), this, SLOT(toggleSortOrder()));
1162
1163 KToggleAction* sortCategorized = actionCollection()->add<KToggleAction>("categorized");
1164 sortCategorized->setText(i18n("Categorized"));
1165 connect(sortCategorized, SIGNAL(triggered()), this, SLOT(toggleSortCategorization()));
1166
1167 KToggleAction* clearInfo = actionCollection()->add<KToggleAction>("clear_info");
1168 clearInfo->setText(i18n("No Information"));
1169 connect(clearInfo, SIGNAL(triggered()), this, SLOT(clearInfo()));
1170
1171 KToggleAction* showMimeInfo = actionCollection()->add<KToggleAction>("show_mime_info");
1172 showMimeInfo->setText(i18n("Type"));
1173 connect(showMimeInfo, SIGNAL(triggered()), this, SLOT(showMimeInfo()));
1174
1175 KToggleAction* showSizeInfo = actionCollection()->add<KToggleAction>("show_size_info");
1176 showSizeInfo->setText(i18n("Size"));
1177 connect(showSizeInfo, SIGNAL(triggered()), this, SLOT(showSizeInfo()));
1178
1179 KToggleAction* showDateInfo = actionCollection()->add<KToggleAction>("show_date_info");
1180 showDateInfo->setText(i18n("Date"));
1181 connect(showDateInfo, SIGNAL(triggered()), this, SLOT(showDateInfo()));
1182
1183 QActionGroup* infoGroup = new QActionGroup(this);
1184 infoGroup->addAction(clearInfo);
1185 infoGroup->addAction(showMimeInfo);
1186 infoGroup->addAction(showSizeInfo);
1187 infoGroup->addAction(showDateInfo);
1188
1189 KToggleAction* showPreview = actionCollection()->add<KToggleAction>("show_preview");
1190 showPreview->setText(i18n("Preview"));
1191 showPreview->setIcon(KIcon("thumbnail-show"));
1192 connect(showPreview, SIGNAL(triggered()), this, SLOT(togglePreview()));
1193
1194 KToggleAction* showHiddenFiles = actionCollection()->add<KToggleAction>("show_hidden_files");
1195 showHiddenFiles->setText(i18n("Show Hidden Files"));
1196 showHiddenFiles->setShortcut(Qt::ALT | Qt::Key_Period);
1197 connect(showHiddenFiles, SIGNAL(triggered()), this, SLOT(toggleShowHiddenFiles()));
1198
1199 KToggleAction* split = actionCollection()->add<KToggleAction>("split_view");
1200 split->setText(i18n("Split"));
1201 split->setShortcut(Qt::Key_F10);
1202 split->setIcon(KIcon("view-left-right"));
1203 connect(split, SIGNAL(triggered()), this, SLOT(toggleSplitView()));
1204
1205 QAction* reload = actionCollection()->addAction("reload");
1206 reload->setText(i18n("Reload"));
1207 reload->setShortcut(Qt::Key_F5);
1208 reload->setIcon(KIcon("view-refresh"));
1209 connect(reload, SIGNAL(triggered()), this, SLOT(reloadView()));
1210
1211 QAction* stop = actionCollection()->addAction("stop");
1212 stop->setText(i18n("Stop"));
1213 stop->setIcon(KIcon("process-stop"));
1214 connect(stop, SIGNAL(triggered()), this, SLOT(stopLoading()));
1215
1216 // TODO: the URL navigator must emit a signal if the editable state has been
1217 // changed, so that the corresponding showFullLocation action is updated. Also
1218 // the naming "Show full Location" is currently confusing...
1219 KToggleAction* showFullLocation = actionCollection()->add<KToggleAction>("editable_location");
1220 showFullLocation->setText(i18n("Show Full Location"));
1221 showFullLocation->setShortcut(Qt::CTRL | Qt::Key_L);
1222 connect(showFullLocation, SIGNAL(triggered()), this, SLOT(toggleEditLocation()));
1223
1224 QAction* editLocation = actionCollection()->addAction("edit_location");
1225 editLocation->setText(i18n("Edit Location"));
1226 editLocation->setShortcut(Qt::Key_F6);
1227 connect(editLocation, SIGNAL(triggered()), this, SLOT(editLocation()));
1228
1229 QAction* adjustViewProps = actionCollection()->addAction("view_properties");
1230 adjustViewProps->setText(i18n("Adjust View Properties..."));
1231 connect(adjustViewProps, SIGNAL(triggered()), this, SLOT(adjustViewProperties()));
1232
1233 // setup 'Go' menu
1234 KStandardAction::back(this, SLOT(goBack()), actionCollection());
1235 KStandardAction::forward(this, SLOT(goForward()), actionCollection());
1236 KStandardAction::up(this, SLOT(goUp()), actionCollection());
1237 KStandardAction::home(this, SLOT(goHome()), actionCollection());
1238
1239 // setup 'Tools' menu
1240 QAction* openTerminal = actionCollection()->addAction("open_terminal");
1241 openTerminal->setText(i18n("Open Terminal"));
1242 openTerminal->setShortcut(Qt::Key_F4);
1243 openTerminal->setIcon(KIcon("konsole"));
1244 connect(openTerminal, SIGNAL(triggered()), this, SLOT(openTerminal()));
1245
1246 QAction* findFile = actionCollection()->addAction("find_file");
1247 findFile->setText(i18n("Find File..."));
1248 findFile->setShortcut(Qt::CTRL | Qt::Key_F);
1249 findFile->setIcon(KIcon("file-find"));
1250 connect(findFile, SIGNAL(triggered()), this, SLOT(findFile()));
1251
1252 KToggleAction* showFilterBar = actionCollection()->add<KToggleAction>("show_filter_bar");
1253 showFilterBar->setText(i18n("Show Filter Bar"));
1254 showFilterBar->setShortcut(Qt::Key_Slash);
1255 connect(showFilterBar, SIGNAL(triggered()), this, SLOT(showFilterBar()));
1256
1257 QAction* compareFiles = actionCollection()->addAction("compare_files");
1258 compareFiles->setText(i18n("Compare Files"));
1259 compareFiles->setIcon(KIcon("kompare"));
1260 compareFiles->setEnabled(false);
1261 connect(compareFiles, SIGNAL(triggered()), this, SLOT(compareFiles()));
1262
1263 // setup 'Settings' menu
1264 KStandardAction::preferences(this, SLOT(editSettings()), actionCollection());
1265 }
1266
1267 void DolphinMainWindow::setupDockWidgets()
1268 {
1269 // setup "Information"
1270 QDockWidget* infoDock = new QDockWidget(i18n("Information"));
1271 infoDock->setObjectName("infoDock");
1272 infoDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
1273 SidebarPage* infoWidget = new InfoSidebarPage(infoDock);
1274 infoDock->setWidget(infoWidget);
1275
1276 infoDock->toggleViewAction()->setText(i18n("Show Information Panel"));
1277 actionCollection()->addAction("show_info_panel", infoDock->toggleViewAction());
1278
1279 addDockWidget(Qt::RightDockWidgetArea, infoDock);
1280 connect(this, SIGNAL(urlChanged(KUrl)),
1281 infoWidget, SLOT(setUrl(KUrl)));
1282 connect(this, SIGNAL(selectionChanged(KFileItemList)),
1283 infoWidget, SLOT(setSelection(KFileItemList)));
1284
1285 // setup "Tree View"
1286 QDockWidget* treeViewDock = new QDockWidget(i18n("Folders"));
1287 treeViewDock->setObjectName("treeViewDock");
1288 treeViewDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
1289 TreeViewSidebarPage* treeWidget = new TreeViewSidebarPage(treeViewDock);
1290 treeViewDock->setWidget(treeWidget);
1291
1292 treeViewDock->toggleViewAction()->setText(i18n("Show Folders Panel"));
1293 actionCollection()->addAction("show_folders_panel", treeViewDock->toggleViewAction());
1294
1295 addDockWidget(Qt::LeftDockWidgetArea, treeViewDock);
1296 connect(this, SIGNAL(urlChanged(KUrl)),
1297 treeWidget, SLOT(setUrl(KUrl)));
1298 connect(treeWidget, SIGNAL(changeUrl(KUrl)),
1299 this, SLOT(changeUrl(KUrl)));
1300 connect(treeWidget, SIGNAL(changeSelection(KFileItemList)),
1301 this, SLOT(changeSelection(KFileItemList)));
1302 connect(treeWidget, SIGNAL(urlsDropped(KUrl::List, KUrl)),
1303 this, SLOT(dropUrls(KUrl::List, KUrl)));
1304
1305 const bool firstRun = DolphinSettings::instance().generalSettings()->firstRun();
1306 if (firstRun) {
1307 infoDock->hide();
1308 treeViewDock->hide();
1309 }
1310
1311 QDockWidget *placesDock = new QDockWidget(i18n("Places"));
1312 placesDock->setObjectName("placesDock");
1313 placesDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
1314 KFilePlacesView *listView = new KFilePlacesView(placesDock);
1315 placesDock->setWidget(listView);
1316 listView->setModel(DolphinSettings::instance().placesModel());
1317
1318 placesDock->toggleViewAction()->setText(i18n("Show Places Panel"));
1319 actionCollection()->addAction("show_places_panel", placesDock->toggleViewAction());
1320
1321 addDockWidget(Qt::LeftDockWidgetArea, placesDock);
1322 connect(listView, SIGNAL(urlChanged(KUrl)),
1323 this, SLOT(changeUrl(KUrl)));
1324 connect(this, SIGNAL(urlChanged(KUrl)),
1325 listView, SLOT(setUrl(KUrl)));
1326 }
1327
1328 void DolphinMainWindow::updateHistory()
1329 {
1330 const KUrlNavigator* urlNavigator = m_activeView->urlNavigator();
1331 const int index = urlNavigator->historyIndex();
1332
1333 QAction* backAction = actionCollection()->action("go_back");
1334 if (backAction != 0) {
1335 backAction->setEnabled(index < urlNavigator->historySize() - 1);
1336 }
1337
1338 QAction* forwardAction = actionCollection()->action("go_forward");
1339 if (forwardAction != 0) {
1340 forwardAction->setEnabled(index > 0);
1341 }
1342 }
1343
1344 void DolphinMainWindow::updateEditActions()
1345 {
1346 const KFileItemList list = m_activeView->selectedItems();
1347 if (list.isEmpty()) {
1348 stateChanged("has_no_selection");
1349 } else {
1350 stateChanged("has_selection");
1351
1352 QAction* renameAction = actionCollection()->action("rename");
1353 if (renameAction != 0) {
1354 renameAction->setEnabled(list.count() >= 1);
1355 }
1356
1357 bool enableMoveToTrash = true;
1358
1359 KFileItemList::const_iterator it = list.begin();
1360 const KFileItemList::const_iterator end = list.end();
1361 while (it != end) {
1362 KFileItem* item = *it;
1363 const KUrl& url = item->url();
1364 // only enable the 'Move to Trash' action for local files
1365 if (!url.isLocalFile()) {
1366 enableMoveToTrash = false;
1367 }
1368 ++it;
1369 }
1370
1371 QAction* moveToTrashAction = actionCollection()->action("move_to_trash");
1372 moveToTrashAction->setEnabled(enableMoveToTrash);
1373 }
1374 updatePasteAction();
1375 }
1376
1377 void DolphinMainWindow::updateViewActions()
1378 {
1379 QAction* zoomInAction = actionCollection()->action(KStandardAction::stdName(KStandardAction::ZoomIn));
1380 if (zoomInAction != 0) {
1381 zoomInAction->setEnabled(m_activeView->isZoomInPossible());
1382 }
1383
1384 QAction* zoomOutAction = actionCollection()->action(KStandardAction::stdName(KStandardAction::ZoomOut));
1385 if (zoomOutAction != 0) {
1386 zoomOutAction->setEnabled(m_activeView->isZoomOutPossible());
1387 }
1388
1389 QAction* action = 0;
1390 switch (m_activeView->mode()) {
1391 case DolphinView::IconsView:
1392 action = actionCollection()->action("icons");
1393 break;
1394 case DolphinView::DetailsView:
1395 action = actionCollection()->action("details");
1396 break;
1397 case DolphinView::ColumnView:
1398 action = actionCollection()->action("columns");
1399 break;
1400 default:
1401 break;
1402 }
1403
1404 if (action != 0) {
1405 KToggleAction* toggleAction = static_cast<KToggleAction*>(action);
1406 toggleAction->setChecked(true);
1407 }
1408
1409 slotSortingChanged(m_activeView->sorting());
1410 slotSortOrderChanged(m_activeView->sortOrder());
1411 slotCategorizedSortingChanged();
1412 slotAdditionalInfoChanged(m_activeView->additionalInfo());
1413
1414 KToggleAction* showFilterBarAction =
1415 static_cast<KToggleAction*>(actionCollection()->action("show_filter_bar"));
1416 showFilterBarAction->setChecked(m_activeView->isFilterBarVisible());
1417
1418 KToggleAction* showPreviewAction =
1419 static_cast<KToggleAction*>(actionCollection()->action("show_preview"));
1420 showPreviewAction->setChecked(m_activeView->showPreview());
1421
1422 KToggleAction* showHiddenFilesAction =
1423 static_cast<KToggleAction*>(actionCollection()->action("show_hidden_files"));
1424 showHiddenFilesAction->setChecked(m_activeView->showHiddenFiles());
1425
1426 KToggleAction* splitAction = static_cast<KToggleAction*>(actionCollection()->action("split_view"));
1427 splitAction->setChecked(m_view[SecondaryIdx] != 0);
1428
1429 KToggleAction* editableLocactionAction =
1430 static_cast<KToggleAction*>(actionCollection()->action("editable_location"));
1431 editableLocactionAction->setChecked(m_activeView->isUrlEditable());
1432 }
1433
1434 void DolphinMainWindow::updateGoActions()
1435 {
1436 QAction* goUpAction = actionCollection()->action(KStandardAction::stdName(KStandardAction::Up));
1437 const KUrl& currentUrl = m_activeView->url();
1438 goUpAction->setEnabled(currentUrl.upUrl() != currentUrl);
1439 }
1440
1441 void DolphinMainWindow::copyUrls(const KUrl::List& source, const KUrl& dest)
1442 {
1443 KonqOperations::copy(this, KonqOperations::COPY, source, dest);
1444 m_undoCommandTypes.append(KonqUndoManager::COPY);
1445 }
1446
1447 void DolphinMainWindow::moveUrls(const KUrl::List& source, const KUrl& dest)
1448 {
1449 KonqOperations::copy(this, KonqOperations::MOVE, source, dest);
1450 m_undoCommandTypes.append(KonqUndoManager::MOVE);
1451 }
1452
1453 void DolphinMainWindow::linkUrls(const KUrl::List& source, const KUrl& dest)
1454 {
1455 KonqOperations::copy(this, KonqOperations::LINK, source, dest);
1456 m_undoCommandTypes.append(KonqUndoManager::LINK);
1457 }
1458
1459 void DolphinMainWindow::clearStatusBar()
1460 {
1461 m_activeView->statusBar()->clear();
1462 }
1463
1464 void DolphinMainWindow::connectViewSignals(int viewIndex)
1465 {
1466 DolphinView* view = m_view[viewIndex];
1467 connect(view, SIGNAL(modeChanged()),
1468 this, SLOT(slotViewModeChanged()));
1469 connect(view, SIGNAL(showPreviewChanged()),
1470 this, SLOT(slotShowPreviewChanged()));
1471 connect(view, SIGNAL(showHiddenFilesChanged()),
1472 this, SLOT(slotShowHiddenFilesChanged()));
1473 connect(view, SIGNAL(categorizedSortingChanged()),
1474 this, SLOT(slotCategorizedSortingChanged()));
1475 connect(view, SIGNAL(sortingChanged(DolphinView::Sorting)),
1476 this, SLOT(slotSortingChanged(DolphinView::Sorting)));
1477 connect(view, SIGNAL(sortOrderChanged(Qt::SortOrder)),
1478 this, SLOT(slotSortOrderChanged(Qt::SortOrder)));
1479 connect(view, SIGNAL(additionalInfoChanged(KFileItemDelegate::AdditionalInformation)),
1480 this, SLOT(slotAdditionalInfoChanged(KFileItemDelegate::AdditionalInformation)));
1481 connect(view, SIGNAL(selectionChanged(KFileItemList)),
1482 this, SLOT(slotSelectionChanged(KFileItemList)));
1483 connect(view, SIGNAL(showFilterBarChanged(bool)),
1484 this, SLOT(updateFilterBarAction(bool)));
1485 connect(view, SIGNAL(urlChanged(KUrl)),
1486 this, SLOT(changeUrl(KUrl)));
1487
1488 const KUrlNavigator* navigator = view->urlNavigator();
1489 connect(navigator, SIGNAL(urlChanged(const KUrl&)),
1490 this, SLOT(changeUrl(const KUrl&)));
1491 connect(navigator, SIGNAL(historyChanged()),
1492 this, SLOT(slotHistoryChanged()));
1493 }
1494
1495 DolphinMainWindow::UndoUiInterface::UndoUiInterface(DolphinMainWindow* mainWin) :
1496 KonqUndoManager::UiInterface(mainWin),
1497 m_mainWin(mainWin)
1498 {
1499 Q_ASSERT(m_mainWin != 0);
1500 }
1501
1502 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
1503 {
1504 }
1505
1506 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job* job)
1507 {
1508 DolphinStatusBar* statusBar = m_mainWin->activeView()->statusBar();
1509 statusBar->setMessage(job->errorString(), DolphinStatusBar::Error);
1510 }
1511
1512 #include "dolphinmainwindow.moc"