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