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