]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinmainwindow.cpp
let the information sidebar react on selection changes
[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 // TODO: make a static method for opening the settings dialog
954 DolphinSettingsDialog dlg(this);
955 dlg.exec();
956 }
957
958 void DolphinMainWindow::init()
959 {
960 // Check whether Dolphin runs the first time. If yes then
961 // a proper default window size is given at the end of DolphinMainWindow::init().
962 GeneralSettings* generalSettings = DolphinSettings::instance().generalSettings();
963 const bool firstRun = generalSettings->firstRun();
964 if (firstRun) {
965 generalSettings->setViewPropsTimestamp(QDateTime::currentDateTime());
966 }
967
968 setAcceptDrops(true);
969
970 m_splitter = new QSplitter(this);
971
972 DolphinSettings& settings = DolphinSettings::instance();
973
974 setupActions();
975
976 const KUrl& homeUrl = settings.generalSettings()->homeUrl();
977 setCaption(homeUrl.fileName());
978 ViewProperties props(homeUrl);
979 m_view[PrimaryIdx] = new DolphinView(this,
980 m_splitter,
981 homeUrl,
982 props.viewMode(),
983 props.showHiddenFiles());
984
985 m_activeView = m_view[PrimaryIdx];
986 connectViewSignals(PrimaryIdx);
987 m_view[PrimaryIdx]->reload();
988 m_view[PrimaryIdx]->show();
989
990 setCentralWidget(m_splitter);
991 setupDockWidgets();
992
993 setupGUI(Keys | Save | Create | ToolBar);
994 createGUI();
995
996 stateChanged("new_file");
997 setAutoSaveSettings();
998
999 QClipboard* clipboard = QApplication::clipboard();
1000 connect(clipboard, SIGNAL(dataChanged()),
1001 this, SLOT(updatePasteAction()));
1002 updatePasteAction();
1003 updateGoActions();
1004
1005 loadSettings();
1006
1007 if (firstRun) {
1008 // assure a proper default size if Dolphin runs the first time
1009 resize(640, 480);
1010 }
1011 #ifdef HAVE_KMETADATA
1012 if (!MetaDataWidget::metaDataAvailable())
1013 activeView()->statusBar()->setMessage(i18n("Failed to contact Nepomuk service, annotation and tagging are disabled."), DolphinStatusBar::Error);
1014 #endif
1015
1016 emit urlChanged(homeUrl);
1017 }
1018
1019 void DolphinMainWindow::loadSettings()
1020 {
1021 GeneralSettings* settings = DolphinSettings::instance().generalSettings();
1022
1023 KToggleAction* splitAction = static_cast<KToggleAction*>(actionCollection()->action("split_view"));
1024 if (settings->splitView()) {
1025 splitAction->setChecked(true);
1026 toggleSplitView();
1027 }
1028
1029 updateViewActions();
1030 }
1031
1032 void DolphinMainWindow::setupActions()
1033 {
1034 // setup 'File' menu
1035 m_newMenu = new DolphinNewMenu(this);
1036 KMenu* menu = m_newMenu->menu();
1037 menu->setTitle(i18n("Create New"));
1038 menu->setIcon(KIcon("document-new"));
1039 connect(menu, SIGNAL(aboutToShow()),
1040 this, SLOT(updateNewMenu()));
1041
1042 QAction* newWindow = actionCollection()->addAction("new_window");
1043 newWindow->setIcon(KIcon("window-new"));
1044 newWindow->setText(i18n("New &Window"));
1045 newWindow->setShortcut(Qt::CTRL | Qt::Key_N);
1046 connect(newWindow, SIGNAL(triggered()), this, SLOT(openNewMainWindow()));
1047
1048 QAction* rename = actionCollection()->addAction("rename");
1049 rename->setText(i18n("Rename..."));
1050 rename->setShortcut(Qt::Key_F2);
1051 connect(rename, SIGNAL(triggered()), this, SLOT(rename()));
1052
1053 QAction* moveToTrash = actionCollection()->addAction("move_to_trash");
1054 moveToTrash->setText(i18n("Move to Trash"));
1055 moveToTrash->setIcon(KIcon("edit-trash"));
1056 moveToTrash->setShortcut(QKeySequence::Delete);
1057 connect(moveToTrash, SIGNAL(triggered()), this, SLOT(moveToTrash()));
1058
1059 QAction* deleteAction = actionCollection()->addAction("delete");
1060 deleteAction->setText(i18n("Delete"));
1061 deleteAction->setShortcut(Qt::SHIFT | Qt::Key_Delete);
1062 deleteAction->setIcon(KIcon("edit-delete"));
1063 connect(deleteAction, SIGNAL(triggered()), this, SLOT(deleteItems()));
1064
1065 QAction* properties = actionCollection()->addAction("properties");
1066 properties->setText(i18n("Properties"));
1067 properties->setShortcut(Qt::ALT | Qt::Key_Return);
1068 connect(properties, SIGNAL(triggered()), this, SLOT(properties()));
1069
1070 KStandardAction::quit(this, SLOT(quit()), actionCollection());
1071
1072 // setup 'Edit' menu
1073 KStandardAction::undo(this,
1074 SLOT(undo()),
1075 actionCollection());
1076
1077 KStandardAction::cut(this, SLOT(cut()), actionCollection());
1078 KStandardAction::copy(this, SLOT(copy()), actionCollection());
1079 KStandardAction::paste(this, SLOT(paste()), actionCollection());
1080
1081 QAction* selectAll = actionCollection()->addAction("select_all");
1082 selectAll->setText(i18n("Select All"));
1083 selectAll->setShortcut(Qt::CTRL + Qt::Key_A);
1084 connect(selectAll, SIGNAL(triggered()), this, SLOT(selectAll()));
1085
1086 QAction* invertSelection = actionCollection()->addAction("invert_selection");
1087 invertSelection->setText(i18n("Invert Selection"));
1088 invertSelection->setShortcut(Qt::CTRL | Qt::SHIFT | Qt::Key_A);
1089 connect(invertSelection, SIGNAL(triggered()), this, SLOT(invertSelection()));
1090
1091 // setup 'View' menu
1092 KStandardAction::zoomIn(this,
1093 SLOT(zoomIn()),
1094 actionCollection());
1095
1096 KStandardAction::zoomOut(this,
1097 SLOT(zoomOut()),
1098 actionCollection());
1099
1100 KToggleAction* iconsView = actionCollection()->add<KToggleAction>("icons");
1101 iconsView->setText(i18n("Icons"));
1102 iconsView->setShortcut(Qt::CTRL | Qt::Key_1);
1103 iconsView->setIcon(KIcon("view-icon"));
1104 connect(iconsView, SIGNAL(triggered()), this, SLOT(setIconsView()));
1105
1106 KToggleAction* detailsView = actionCollection()->add<KToggleAction>("details");
1107 detailsView->setText(i18n("Details"));
1108 detailsView->setShortcut(Qt::CTRL | Qt::Key_2);
1109 detailsView->setIcon(KIcon("fileview-text"));
1110 connect(detailsView, SIGNAL(triggered()), this, SLOT(setDetailsView()));
1111
1112 KToggleAction* columnView = actionCollection()->add<KToggleAction>("columns");
1113 columnView->setText(i18n("Columns"));
1114 columnView->setShortcut(Qt::CTRL | Qt::Key_3);
1115 columnView->setIcon(KIcon("fileview-column"));
1116 connect(columnView, SIGNAL(triggered()), this, SLOT(setColumnView()));
1117
1118 QActionGroup* viewModeGroup = new QActionGroup(this);
1119 viewModeGroup->addAction(iconsView);
1120 viewModeGroup->addAction(detailsView);
1121 viewModeGroup->addAction(columnView);
1122
1123 KToggleAction* sortByName = actionCollection()->add<KToggleAction>("by_name");
1124 sortByName->setText(i18n("By Name"));
1125 connect(sortByName, SIGNAL(triggered()), this, SLOT(sortByName()));
1126
1127 KToggleAction* sortBySize = actionCollection()->add<KToggleAction>("by_size");
1128 sortBySize->setText(i18n("By Size"));
1129 connect(sortBySize, SIGNAL(triggered()), this, SLOT(sortBySize()));
1130
1131 KToggleAction* sortByDate = actionCollection()->add<KToggleAction>("by_date");
1132 sortByDate->setText(i18n("By Date"));
1133 connect(sortByDate, SIGNAL(triggered()), this, SLOT(sortByDate()));
1134
1135 KToggleAction* sortByPermissions = actionCollection()->add<KToggleAction>("by_permissions");
1136 sortByPermissions->setText(i18n("By Permissions"));
1137 connect(sortByPermissions, SIGNAL(triggered()), this, SLOT(sortByPermissions()));
1138
1139 KToggleAction* sortByOwner = actionCollection()->add<KToggleAction>("by_owner");
1140 sortByOwner->setText(i18n("By Owner"));
1141 connect(sortByOwner, SIGNAL(triggered()), this, SLOT(sortByOwner()));
1142
1143 KToggleAction* sortByGroup = actionCollection()->add<KToggleAction>("by_group");
1144 sortByGroup->setText(i18n("By Group"));
1145 connect(sortByGroup, SIGNAL(triggered()), this, SLOT(sortByGroup()));
1146
1147 KToggleAction* sortByType = actionCollection()->add<KToggleAction>("by_type");
1148 sortByType->setText(i18n("By Type"));
1149 connect(sortByType, SIGNAL(triggered()), this, SLOT(sortByType()));
1150
1151 QActionGroup* sortGroup = new QActionGroup(this);
1152 sortGroup->addAction(sortByName);
1153 sortGroup->addAction(sortBySize);
1154 sortGroup->addAction(sortByDate);
1155 sortGroup->addAction(sortByPermissions);
1156 sortGroup->addAction(sortByOwner);
1157 sortGroup->addAction(sortByGroup);
1158 sortGroup->addAction(sortByType);
1159
1160 KToggleAction* sortDescending = actionCollection()->add<KToggleAction>("descending");
1161 sortDescending->setText(i18n("Descending"));
1162 connect(sortDescending, SIGNAL(triggered()), this, SLOT(toggleSortOrder()));
1163
1164 KToggleAction* sortCategorized = actionCollection()->add<KToggleAction>("categorized");
1165 sortCategorized->setText(i18n("Categorized"));
1166 connect(sortCategorized, SIGNAL(triggered()), this, SLOT(toggleSortCategorization()));
1167
1168 KToggleAction* clearInfo = actionCollection()->add<KToggleAction>("clear_info");
1169 clearInfo->setText(i18n("No Information"));
1170 connect(clearInfo, SIGNAL(triggered()), this, SLOT(clearInfo()));
1171
1172 KToggleAction* showMimeInfo = actionCollection()->add<KToggleAction>("show_mime_info");
1173 showMimeInfo->setText(i18n("Type"));
1174 connect(showMimeInfo, SIGNAL(triggered()), this, SLOT(showMimeInfo()));
1175
1176 KToggleAction* showSizeInfo = actionCollection()->add<KToggleAction>("show_size_info");
1177 showSizeInfo->setText(i18n("Size"));
1178 connect(showSizeInfo, SIGNAL(triggered()), this, SLOT(showSizeInfo()));
1179
1180 KToggleAction* showDateInfo = actionCollection()->add<KToggleAction>("show_date_info");
1181 showDateInfo->setText(i18n("Date"));
1182 connect(showDateInfo, SIGNAL(triggered()), this, SLOT(showDateInfo()));
1183
1184 QActionGroup* infoGroup = new QActionGroup(this);
1185 infoGroup->addAction(clearInfo);
1186 infoGroup->addAction(showMimeInfo);
1187 infoGroup->addAction(showSizeInfo);
1188 infoGroup->addAction(showDateInfo);
1189
1190 KToggleAction* showPreview = actionCollection()->add<KToggleAction>("show_preview");
1191 showPreview->setText(i18n("Preview"));
1192 showPreview->setIcon(KIcon("thumbnail-show"));
1193 connect(showPreview, SIGNAL(triggered()), this, SLOT(togglePreview()));
1194
1195 KToggleAction* showHiddenFiles = actionCollection()->add<KToggleAction>("show_hidden_files");
1196 showHiddenFiles->setText(i18n("Show Hidden Files"));
1197 showHiddenFiles->setShortcut(Qt::ALT | Qt::Key_Period);
1198 connect(showHiddenFiles, SIGNAL(triggered()), this, SLOT(toggleShowHiddenFiles()));
1199
1200 KToggleAction* split = actionCollection()->add<KToggleAction>("split_view");
1201 split->setText(i18n("Split"));
1202 split->setShortcut(Qt::Key_F10);
1203 split->setIcon(KIcon("view-left-right"));
1204 connect(split, SIGNAL(triggered()), this, SLOT(toggleSplitView()));
1205
1206 QAction* reload = actionCollection()->addAction("reload");
1207 reload->setText(i18n("Reload"));
1208 reload->setShortcut(Qt::Key_F5);
1209 reload->setIcon(KIcon("view-refresh"));
1210 connect(reload, SIGNAL(triggered()), this, SLOT(reloadView()));
1211
1212 QAction* stop = actionCollection()->addAction("stop");
1213 stop->setText(i18n("Stop"));
1214 stop->setIcon(KIcon("process-stop"));
1215 connect(stop, SIGNAL(triggered()), this, SLOT(stopLoading()));
1216
1217 // TODO: the URL navigator must emit a signal if the editable state has been
1218 // changed, so that the corresponding showFullLocation action is updated. Also
1219 // the naming "Show full Location" is currently confusing...
1220 KToggleAction* showFullLocation = actionCollection()->add<KToggleAction>("editable_location");
1221 showFullLocation->setText(i18n("Show Full Location"));
1222 showFullLocation->setShortcut(Qt::CTRL | Qt::Key_L);
1223 connect(showFullLocation, SIGNAL(triggered()), this, SLOT(toggleEditLocation()));
1224
1225 QAction* editLocation = actionCollection()->addAction("edit_location");
1226 editLocation->setText(i18n("Edit Location"));
1227 editLocation->setShortcut(Qt::Key_F6);
1228 connect(editLocation, SIGNAL(triggered()), this, SLOT(editLocation()));
1229
1230 QAction* adjustViewProps = actionCollection()->addAction("view_properties");
1231 adjustViewProps->setText(i18n("Adjust View Properties..."));
1232 connect(adjustViewProps, SIGNAL(triggered()), this, SLOT(adjustViewProperties()));
1233
1234 // setup 'Go' menu
1235 KStandardAction::back(this, SLOT(goBack()), actionCollection());
1236 KStandardAction::forward(this, SLOT(goForward()), actionCollection());
1237 KStandardAction::up(this, SLOT(goUp()), actionCollection());
1238 KStandardAction::home(this, SLOT(goHome()), actionCollection());
1239
1240 // setup 'Tools' menu
1241 QAction* openTerminal = actionCollection()->addAction("open_terminal");
1242 openTerminal->setText(i18n("Open Terminal"));
1243 openTerminal->setShortcut(Qt::Key_F4);
1244 openTerminal->setIcon(KIcon("konsole"));
1245 connect(openTerminal, SIGNAL(triggered()), this, SLOT(openTerminal()));
1246
1247 QAction* findFile = actionCollection()->addAction("find_file");
1248 findFile->setText(i18n("Find File..."));
1249 findFile->setShortcut(Qt::CTRL | Qt::Key_F);
1250 findFile->setIcon(KIcon("file-find"));
1251 connect(findFile, SIGNAL(triggered()), this, SLOT(findFile()));
1252
1253 KToggleAction* showFilterBar = actionCollection()->add<KToggleAction>("show_filter_bar");
1254 showFilterBar->setText(i18n("Show Filter Bar"));
1255 showFilterBar->setShortcut(Qt::Key_Slash);
1256 connect(showFilterBar, SIGNAL(triggered()), this, SLOT(showFilterBar()));
1257
1258 QAction* compareFiles = actionCollection()->addAction("compare_files");
1259 compareFiles->setText(i18n("Compare Files"));
1260 compareFiles->setIcon(KIcon("kompare"));
1261 compareFiles->setEnabled(false);
1262 connect(compareFiles, SIGNAL(triggered()), this, SLOT(compareFiles()));
1263
1264 // setup 'Settings' menu
1265 KStandardAction::preferences(this, SLOT(editSettings()), actionCollection());
1266 }
1267
1268 void DolphinMainWindow::setupDockWidgets()
1269 {
1270 // setup "Information"
1271 QDockWidget* infoDock = new QDockWidget(i18n("Information"));
1272 infoDock->setObjectName("infoDock");
1273 infoDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
1274 SidebarPage* infoWidget = new InfoSidebarPage(infoDock);
1275 infoDock->setWidget(infoWidget);
1276
1277 infoDock->toggleViewAction()->setText(i18n("Show Information Panel"));
1278 actionCollection()->addAction("show_info_panel", infoDock->toggleViewAction());
1279
1280 addDockWidget(Qt::RightDockWidgetArea, infoDock);
1281 connect(this, SIGNAL(urlChanged(KUrl)),
1282 infoWidget, SLOT(setUrl(KUrl)));
1283 connect(this, SIGNAL(selectionChanged(KFileItemList)),
1284 infoWidget, SLOT(setSelection(KFileItemList)));
1285
1286 // setup "Tree View"
1287 QDockWidget* treeViewDock = new QDockWidget(i18n("Folders"));
1288 treeViewDock->setObjectName("treeViewDock");
1289 treeViewDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
1290 TreeViewSidebarPage* treeWidget = new TreeViewSidebarPage(treeViewDock);
1291 treeViewDock->setWidget(treeWidget);
1292
1293 treeViewDock->toggleViewAction()->setText(i18n("Show Folders Panel"));
1294 actionCollection()->addAction("show_folders_panel", treeViewDock->toggleViewAction());
1295
1296 addDockWidget(Qt::LeftDockWidgetArea, treeViewDock);
1297 connect(this, SIGNAL(urlChanged(KUrl)),
1298 treeWidget, SLOT(setUrl(KUrl)));
1299 connect(treeWidget, SIGNAL(changeUrl(KUrl)),
1300 this, SLOT(changeUrl(KUrl)));
1301 connect(treeWidget, SIGNAL(changeSelection(KFileItemList)),
1302 this, SLOT(changeSelection(KFileItemList)));
1303 connect(treeWidget, SIGNAL(urlsDropped(KUrl::List, KUrl)),
1304 this, SLOT(dropUrls(KUrl::List, KUrl)));
1305
1306 const bool firstRun = DolphinSettings::instance().generalSettings()->firstRun();
1307 if (firstRun) {
1308 infoDock->hide();
1309 treeViewDock->hide();
1310 }
1311
1312 QDockWidget *placesDock = new QDockWidget(i18n("Places"));
1313 placesDock->setObjectName("placesDock");
1314 placesDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
1315 KFilePlacesView *listView = new KFilePlacesView(placesDock);
1316 placesDock->setWidget(listView);
1317 listView->setModel(DolphinSettings::instance().placesModel());
1318
1319 placesDock->toggleViewAction()->setText(i18n("Show Places Panel"));
1320 actionCollection()->addAction("show_places_panel", placesDock->toggleViewAction());
1321
1322 addDockWidget(Qt::LeftDockWidgetArea, placesDock);
1323 connect(listView, SIGNAL(urlChanged(KUrl)),
1324 this, SLOT(changeUrl(KUrl)));
1325 connect(this, SIGNAL(urlChanged(KUrl)),
1326 listView, SLOT(setUrl(KUrl)));
1327 }
1328
1329 void DolphinMainWindow::updateHistory()
1330 {
1331 const KUrlNavigator* urlNavigator = m_activeView->urlNavigator();
1332 const int index = urlNavigator->historyIndex();
1333
1334 QAction* backAction = actionCollection()->action("go_back");
1335 if (backAction != 0) {
1336 backAction->setEnabled(index < urlNavigator->historySize() - 1);
1337 }
1338
1339 QAction* forwardAction = actionCollection()->action("go_forward");
1340 if (forwardAction != 0) {
1341 forwardAction->setEnabled(index > 0);
1342 }
1343 }
1344
1345 void DolphinMainWindow::updateEditActions()
1346 {
1347 const KFileItemList list = m_activeView->selectedItems();
1348 if (list.isEmpty()) {
1349 stateChanged("has_no_selection");
1350 } else {
1351 stateChanged("has_selection");
1352
1353 QAction* renameAction = actionCollection()->action("rename");
1354 if (renameAction != 0) {
1355 renameAction->setEnabled(list.count() >= 1);
1356 }
1357
1358 bool enableMoveToTrash = true;
1359
1360 KFileItemList::const_iterator it = list.begin();
1361 const KFileItemList::const_iterator end = list.end();
1362 while (it != end) {
1363 KFileItem* item = *it;
1364 const KUrl& url = item->url();
1365 // only enable the 'Move to Trash' action for local files
1366 if (!url.isLocalFile()) {
1367 enableMoveToTrash = false;
1368 }
1369 ++it;
1370 }
1371
1372 QAction* moveToTrashAction = actionCollection()->action("move_to_trash");
1373 moveToTrashAction->setEnabled(enableMoveToTrash);
1374 }
1375 updatePasteAction();
1376 }
1377
1378 void DolphinMainWindow::updateViewActions()
1379 {
1380 QAction* zoomInAction = actionCollection()->action(KStandardAction::stdName(KStandardAction::ZoomIn));
1381 if (zoomInAction != 0) {
1382 zoomInAction->setEnabled(m_activeView->isZoomInPossible());
1383 }
1384
1385 QAction* zoomOutAction = actionCollection()->action(KStandardAction::stdName(KStandardAction::ZoomOut));
1386 if (zoomOutAction != 0) {
1387 zoomOutAction->setEnabled(m_activeView->isZoomOutPossible());
1388 }
1389
1390 QAction* action = 0;
1391 switch (m_activeView->mode()) {
1392 case DolphinView::IconsView:
1393 action = actionCollection()->action("icons");
1394 break;
1395 case DolphinView::DetailsView:
1396 action = actionCollection()->action("details");
1397 break;
1398 case DolphinView::ColumnView:
1399 action = actionCollection()->action("columns");
1400 break;
1401 default:
1402 break;
1403 }
1404
1405 if (action != 0) {
1406 KToggleAction* toggleAction = static_cast<KToggleAction*>(action);
1407 toggleAction->setChecked(true);
1408 }
1409
1410 slotSortingChanged(m_activeView->sorting());
1411 slotSortOrderChanged(m_activeView->sortOrder());
1412 slotCategorizedSortingChanged();
1413 slotAdditionalInfoChanged(m_activeView->additionalInfo());
1414
1415 KToggleAction* showFilterBarAction =
1416 static_cast<KToggleAction*>(actionCollection()->action("show_filter_bar"));
1417 showFilterBarAction->setChecked(m_activeView->isFilterBarVisible());
1418
1419 KToggleAction* showPreviewAction =
1420 static_cast<KToggleAction*>(actionCollection()->action("show_preview"));
1421 showPreviewAction->setChecked(m_activeView->showPreview());
1422
1423 KToggleAction* showHiddenFilesAction =
1424 static_cast<KToggleAction*>(actionCollection()->action("show_hidden_files"));
1425 showHiddenFilesAction->setChecked(m_activeView->showHiddenFiles());
1426
1427 KToggleAction* splitAction = static_cast<KToggleAction*>(actionCollection()->action("split_view"));
1428 splitAction->setChecked(m_view[SecondaryIdx] != 0);
1429
1430 KToggleAction* editableLocactionAction =
1431 static_cast<KToggleAction*>(actionCollection()->action("editable_location"));
1432 editableLocactionAction->setChecked(m_activeView->isUrlEditable());
1433 }
1434
1435 void DolphinMainWindow::updateGoActions()
1436 {
1437 QAction* goUpAction = actionCollection()->action(KStandardAction::stdName(KStandardAction::Up));
1438 const KUrl& currentUrl = m_activeView->url();
1439 goUpAction->setEnabled(currentUrl.upUrl() != currentUrl);
1440 }
1441
1442 void DolphinMainWindow::copyUrls(const KUrl::List& source, const KUrl& dest)
1443 {
1444 KonqOperations::copy(this, KonqOperations::COPY, source, dest);
1445 m_undoCommandTypes.append(KonqUndoManager::COPY);
1446 }
1447
1448 void DolphinMainWindow::moveUrls(const KUrl::List& source, const KUrl& dest)
1449 {
1450 KonqOperations::copy(this, KonqOperations::MOVE, source, dest);
1451 m_undoCommandTypes.append(KonqUndoManager::MOVE);
1452 }
1453
1454 void DolphinMainWindow::linkUrls(const KUrl::List& source, const KUrl& dest)
1455 {
1456 KonqOperations::copy(this, KonqOperations::LINK, source, dest);
1457 m_undoCommandTypes.append(KonqUndoManager::LINK);
1458 }
1459
1460 void DolphinMainWindow::clearStatusBar()
1461 {
1462 m_activeView->statusBar()->clear();
1463 }
1464
1465 void DolphinMainWindow::connectViewSignals(int viewIndex)
1466 {
1467 DolphinView* view = m_view[viewIndex];
1468 connect(view, SIGNAL(modeChanged()),
1469 this, SLOT(slotViewModeChanged()));
1470 connect(view, SIGNAL(showPreviewChanged()),
1471 this, SLOT(slotShowPreviewChanged()));
1472 connect(view, SIGNAL(showHiddenFilesChanged()),
1473 this, SLOT(slotShowHiddenFilesChanged()));
1474 connect(view, SIGNAL(categorizedSortingChanged()),
1475 this, SLOT(slotCategorizedSortingChanged()));
1476 connect(view, SIGNAL(sortingChanged(DolphinView::Sorting)),
1477 this, SLOT(slotSortingChanged(DolphinView::Sorting)));
1478 connect(view, SIGNAL(sortOrderChanged(Qt::SortOrder)),
1479 this, SLOT(slotSortOrderChanged(Qt::SortOrder)));
1480 connect(view, SIGNAL(additionalInfoChanged(KFileItemDelegate::AdditionalInformation)),
1481 this, SLOT(slotAdditionalInfoChanged(KFileItemDelegate::AdditionalInformation)));
1482 connect(view, SIGNAL(selectionChanged(KFileItemList)),
1483 this, SLOT(slotSelectionChanged(KFileItemList)));
1484 connect(view, SIGNAL(showFilterBarChanged(bool)),
1485 this, SLOT(updateFilterBarAction(bool)));
1486 connect(view, SIGNAL(urlChanged(KUrl)),
1487 this, SLOT(changeUrl(KUrl)));
1488
1489 const KUrlNavigator* navigator = view->urlNavigator();
1490 connect(navigator, SIGNAL(urlChanged(const KUrl&)),
1491 this, SLOT(changeUrl(const KUrl&)));
1492 connect(navigator, SIGNAL(historyChanged()),
1493 this, SLOT(slotHistoryChanged()));
1494 }
1495
1496 DolphinMainWindow::UndoUiInterface::UndoUiInterface(DolphinMainWindow* mainWin) :
1497 KonqUndoManager::UiInterface(mainWin),
1498 m_mainWin(mainWin)
1499 {
1500 Q_ASSERT(m_mainWin != 0);
1501 }
1502
1503 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
1504 {
1505 }
1506
1507 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job* job)
1508 {
1509 DolphinStatusBar* statusBar = m_mainWin->activeView()->statusBar();
1510 statusBar->setMessage(job->errorString(), DolphinStatusBar::Error);
1511 }
1512
1513 #include "dolphinmainwindow.moc"