]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinmainwindow.cpp
Fixed a bug in the "Recently Closed Tabs" menu that would cause it to show more recen...
[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 "dolphinmainwindow.h"
23 #include "dolphinviewactionhandler.h"
24
25 #include <config-nepomuk.h>
26
27 #include "dolphinapplication.h"
28 #include "dolphinnewmenu.h"
29 #include "settings/dolphinsettings.h"
30 #include "settings/dolphinsettingsdialog.h"
31 #include "dolphinsearchbox.h"
32 #include "dolphinstatusbar.h"
33 #include "dolphinviewcontainer.h"
34 #include "panels/folders/folderspanel.h"
35 #include "panels/places/placespanel.h"
36 #include "panels/information/informationpanel.h"
37 #include "panels/information/metadatawidget.h"
38 #include "mainwindowadaptor.h"
39 #include "viewproperties.h"
40
41 #ifndef Q_OS_WIN
42 #include "panels/terminal/terminalpanel.h"
43 #endif
44
45 #include "dolphin_generalsettings.h"
46 #include "dolphin_iconsmodesettings.h"
47 #include "draganddrophelper.h"
48
49 #include <kaction.h>
50 #include <kactioncollection.h>
51 #include <kconfig.h>
52 #include <kdesktopfile.h>
53 #include <kdeversion.h>
54 #include <kfiledialog.h>
55 #include <kfileplacesmodel.h>
56 #include <kglobal.h>
57 #include <klineedit.h>
58 #include <ktoolbar.h>
59 #include <kicon.h>
60 #include <kiconloader.h>
61 #include <kio/netaccess.h>
62 #include <kinputdialog.h>
63 #include <klocale.h>
64 #include <kprotocolmanager.h>
65 #include <kmenu.h>
66 #include <kmenubar.h>
67 #include <kmessagebox.h>
68 #include <konq_fileitemcapabilities.h>
69 #include <konqmimedata.h>
70 #include <kprotocolinfo.h>
71 #include <krun.h>
72 #include <kshell.h>
73 #include <kstandarddirs.h>
74 #include <kstatusbar.h>
75 #include <kstandardaction.h>
76 #include <ktabbar.h>
77 #include <ktoggleaction.h>
78 #include <kurlnavigator.h>
79 #include <kurl.h>
80 #include <kurlcombobox.h>
81
82 #include <QDBusMessage>
83 #include <QKeyEvent>
84 #include <QClipboard>
85 #include <QLineEdit>
86 #include <QSplitter>
87 #include <QDockWidget>
88
89 DolphinMainWindow::DolphinMainWindow(int id) :
90 KXmlGuiWindow(0),
91 m_newMenu(0),
92 m_showMenuBar(0),
93 m_tabBar(0),
94 m_activeViewContainer(0),
95 m_centralWidgetLayout(0),
96 m_searchBox(0),
97 m_id(id),
98 m_tabIndex(0),
99 m_viewTab(),
100 m_actionHandler(0),
101 m_settingsDialog(0)
102 {
103 setObjectName("Dolphin#");
104
105 m_viewTab.append(ViewTab());
106
107 new MainWindowAdaptor(this);
108 QDBusConnection::sessionBus().registerObject(QString("/dolphin/MainWindow%1").arg(m_id), this);
109
110 KIO::FileUndoManager* undoManager = KIO::FileUndoManager::self();
111 undoManager->setUiInterface(new UndoUiInterface());
112
113 connect(undoManager, SIGNAL(undoAvailable(bool)),
114 this, SLOT(slotUndoAvailable(bool)));
115 connect(undoManager, SIGNAL(undoTextChanged(const QString&)),
116 this, SLOT(slotUndoTextChanged(const QString&)));
117 connect(undoManager, SIGNAL(jobRecordingStarted(CommandType)),
118 this, SLOT(clearStatusBar()));
119 connect(undoManager, SIGNAL(jobRecordingFinished(CommandType)),
120 this, SLOT(showCommand(CommandType)));
121 connect(DolphinSettings::instance().placesModel(), SIGNAL(errorMessage(const QString&)),
122 this, SLOT(showErrorMessage(const QString&)));
123 connect(&DragAndDropHelper::instance(), SIGNAL(errorMessage(const QString&)),
124 this, SLOT(showErrorMessage(const QString&)));
125 }
126
127 DolphinMainWindow::~DolphinMainWindow()
128 {
129 DolphinApplication::app()->removeMainWindow(this);
130 }
131
132 void DolphinMainWindow::toggleViews()
133 {
134 if (m_viewTab[m_tabIndex].primaryView == 0) {
135 return;
136 }
137
138 // move secondary view from the last position of the splitter
139 // to the first position
140 m_viewTab[m_tabIndex].splitter->insertWidget(0, m_viewTab[m_tabIndex].secondaryView);
141
142 DolphinViewContainer* container = m_viewTab[m_tabIndex].primaryView;
143 m_viewTab[m_tabIndex].primaryView = m_viewTab[m_tabIndex].secondaryView;
144 m_viewTab[m_tabIndex].secondaryView = container;
145 }
146
147 void DolphinMainWindow::showCommand(CommandType command)
148 {
149 DolphinStatusBar* statusBar = m_activeViewContainer->statusBar();
150 switch (command) {
151 case KIO::FileUndoManager::Copy:
152 statusBar->setMessage(i18nc("@info:status", "Copy operation completed."),
153 DolphinStatusBar::OperationCompleted);
154 break;
155 case KIO::FileUndoManager::Move:
156 statusBar->setMessage(i18nc("@info:status", "Move operation completed."),
157 DolphinStatusBar::OperationCompleted);
158 break;
159 case KIO::FileUndoManager::Link:
160 statusBar->setMessage(i18nc("@info:status", "Link operation completed."),
161 DolphinStatusBar::OperationCompleted);
162 break;
163 case KIO::FileUndoManager::Trash:
164 statusBar->setMessage(i18nc("@info:status", "Move to trash operation completed."),
165 DolphinStatusBar::OperationCompleted);
166 break;
167 case KIO::FileUndoManager::Rename:
168 statusBar->setMessage(i18nc("@info:status", "Renaming operation completed."),
169 DolphinStatusBar::OperationCompleted);
170 break;
171
172 case KIO::FileUndoManager::Mkdir:
173 statusBar->setMessage(i18nc("@info:status", "Created folder."),
174 DolphinStatusBar::OperationCompleted);
175 break;
176
177 default:
178 break;
179 }
180 }
181
182 void DolphinMainWindow::refreshViews()
183 {
184 Q_ASSERT(m_viewTab[m_tabIndex].primaryView != 0);
185
186 // remember the current active view, as because of
187 // the refreshing the active view might change to
188 // the secondary view
189 DolphinViewContainer* activeViewContainer = m_activeViewContainer;
190
191 const int tabCount = m_viewTab.count();
192 for (int i = 0; i < tabCount; ++i) {
193 m_viewTab[i].primaryView->refresh();
194 if (m_viewTab[i].secondaryView != 0) {
195 m_viewTab[i].secondaryView->refresh();
196 }
197 }
198
199 setActiveViewContainer(activeViewContainer);
200 }
201
202 void DolphinMainWindow::pasteIntoFolder()
203 {
204 m_activeViewContainer->view()->pasteIntoFolder();
205 }
206
207 void DolphinMainWindow::changeUrl(const KUrl& url)
208 {
209 if (!KProtocolManager::supportsListing(url)) {
210 // The URL navigator only checks for validity, not
211 // if the URL can be listed. An error message is
212 // shown due to DolphinViewContainer::restoreView().
213 return;
214 }
215
216 DolphinViewContainer* view = activeViewContainer();
217 if (view != 0) {
218 view->setUrl(url);
219 updateEditActions();
220 updateViewActions();
221 updateGoActions();
222 setCaption(url.fileName());
223 if (m_viewTab.count() > 1) {
224 m_tabBar->setTabText(m_tabIndex, tabName(url));
225 }
226 emit urlChanged(url);
227 }
228 }
229
230 void DolphinMainWindow::changeSelection(const KFileItemList& selection)
231 {
232 activeViewContainer()->view()->changeSelection(selection);
233 }
234
235 void DolphinMainWindow::slotEditableStateChanged(bool editable)
236 {
237 KToggleAction* editableLocationAction =
238 static_cast<KToggleAction*>(actionCollection()->action("editable_location"));
239 editableLocationAction->setChecked(editable);
240 }
241
242 void DolphinMainWindow::slotSelectionChanged(const KFileItemList& selection)
243 {
244 updateEditActions();
245
246 Q_ASSERT(m_viewTab[m_tabIndex].primaryView != 0);
247 int selectedUrlsCount = m_viewTab[m_tabIndex].primaryView->view()->selectedItemsCount();
248 if (m_viewTab[m_tabIndex].secondaryView != 0) {
249 selectedUrlsCount += m_viewTab[m_tabIndex].secondaryView->view()->selectedItemsCount();
250 }
251
252 QAction* compareFilesAction = actionCollection()->action("compare_files");
253 if (selectedUrlsCount == 2) {
254 compareFilesAction->setEnabled(isKompareInstalled());
255 } else {
256 compareFilesAction->setEnabled(false);
257 }
258
259 #if defined(QUICK_VIEW)
260 const bool activeViewHasSelection = (activeViewContainer()->view()->selectedItemsCount() > 0);
261 actionCollection()->action("quick_view")->setEnabled(activeViewHasSelection);
262 #endif
263
264 m_activeViewContainer->updateStatusBar();
265
266 emit selectionChanged(selection);
267 }
268
269 void DolphinMainWindow::slotWheelMoved(int wheelDelta)
270 {
271 if (wheelDelta > 0) {
272 activatePrevTab();
273 } else {
274 activateNextTab();
275 }
276 }
277
278 void DolphinMainWindow::slotRequestItemInfo(const KFileItem& item)
279 {
280 emit requestItemInfo(item);
281 }
282
283 void DolphinMainWindow::updateHistory()
284 {
285 const KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator();
286 const int index = urlNavigator->historyIndex();
287
288 QAction* backAction = actionCollection()->action("go_back");
289 if (backAction != 0) {
290 backAction->setEnabled(index < urlNavigator->historySize() - 1);
291 }
292
293 QAction* forwardAction = actionCollection()->action("go_forward");
294 if (forwardAction != 0) {
295 forwardAction->setEnabled(index > 0);
296 }
297 }
298
299 void DolphinMainWindow::updateFilterBarAction(bool show)
300 {
301 QAction* showFilterBarAction = actionCollection()->action("show_filter_bar");
302 showFilterBarAction->setChecked(show);
303 }
304
305 void DolphinMainWindow::openNewMainWindow()
306 {
307 DolphinApplication::app()->createMainWindow()->show();
308 }
309
310 void DolphinMainWindow::openNewTab()
311 {
312 openNewTab(m_activeViewContainer->url());
313 m_tabBar->setCurrentIndex(m_viewTab.count() - 1);
314
315 KUrlNavigator* navigator = m_activeViewContainer->urlNavigator();
316 if (navigator->isUrlEditable()) {
317 // if a new tab is opened and the URL is editable, assure that
318 // the user can edit the URL without manually setting the focus
319 navigator->setFocus();
320 }
321 }
322
323 void DolphinMainWindow::openNewTab(const KUrl& url)
324 {
325 if (m_viewTab.count() == 1) {
326 // Only one view is open currently and hence no tab is shown at
327 // all. Before creating a tab for 'url', provide a tab for the current URL.
328 m_tabBar->addTab(KIcon("folder"), tabName(m_activeViewContainer->url()));
329 m_tabBar->blockSignals(false);
330 }
331
332 m_tabBar->addTab(KIcon("folder"), tabName(url));
333
334 ViewTab viewTab;
335 viewTab.splitter = new QSplitter(this);
336 viewTab.primaryView = new DolphinViewContainer(this, viewTab.splitter, url);
337 viewTab.primaryView->setActive(false);
338 connectViewSignals(viewTab.primaryView);
339 viewTab.primaryView->view()->reload();
340
341 m_viewTab.append(viewTab);
342
343 actionCollection()->action("close_tab")->setEnabled(true);
344
345 // provide a split view, if the startup settings are set this way
346 const GeneralSettings* generalSettings = DolphinSettings::instance().generalSettings();
347 if (generalSettings->splitView()) {
348 const int tabIndex = m_viewTab.count() - 1;
349 createSecondaryView(tabIndex);
350 m_viewTab[tabIndex].secondaryView->setActive(true);
351 m_viewTab[tabIndex].isPrimaryViewActive = false;
352 }
353 }
354
355 void DolphinMainWindow::activateNextTab()
356 {
357 if (m_viewTab.count() == 1 || m_tabBar->count() < 2) {
358 return;
359 }
360
361 const int tabIndex = (m_tabBar->currentIndex() + 1) % m_tabBar->count();
362 m_tabBar->setCurrentIndex(tabIndex);
363 }
364
365 void DolphinMainWindow::activatePrevTab()
366 {
367 if (m_viewTab.count() == 1 || m_tabBar->count() < 2) {
368 return;
369 }
370
371 int tabIndex = m_tabBar->currentIndex() - 1;
372 if (tabIndex == -1) {
373 tabIndex = m_tabBar->count() - 1;
374 }
375 m_tabBar->setCurrentIndex(tabIndex);
376 }
377
378 void DolphinMainWindow::openInNewTab()
379 {
380 const KFileItemList list = m_activeViewContainer->view()->selectedItems();
381 if ((list.count() == 1) && list[0].isDir()) {
382 openNewTab(m_activeViewContainer->view()->selectedUrls()[0]);
383 }
384 }
385
386 void DolphinMainWindow::openInNewWindow()
387 {
388 const KFileItemList list = m_activeViewContainer->view()->selectedItems();
389 if ((list.count() == 1) && list[0].isDir()) {
390 DolphinMainWindow* window = DolphinApplication::app()->createMainWindow();
391 window->changeUrl(m_activeViewContainer->view()->selectedUrls()[0]);
392 window->show();
393 }
394 }
395
396 void DolphinMainWindow::toggleActiveView()
397 {
398 if (m_viewTab[m_tabIndex].secondaryView == 0) {
399 // only one view is available
400 return;
401 }
402
403 Q_ASSERT(m_activeViewContainer != 0);
404 Q_ASSERT(m_viewTab[m_tabIndex].primaryView != 0);
405
406 DolphinViewContainer* left = m_viewTab[m_tabIndex].primaryView;
407 DolphinViewContainer* right = m_viewTab[m_tabIndex].secondaryView;
408 setActiveViewContainer(m_activeViewContainer == right ? left : right);
409 }
410
411 void DolphinMainWindow::closeEvent(QCloseEvent* event)
412 {
413 DolphinSettings& settings = DolphinSettings::instance();
414 GeneralSettings* generalSettings = settings.generalSettings();
415 generalSettings->setFirstRun(false);
416
417 settings.save();
418
419 KXmlGuiWindow::closeEvent(event);
420 }
421
422 void DolphinMainWindow::saveProperties(KConfigGroup& group)
423 {
424 // TODO: remember tabs
425 DolphinViewContainer* cont = m_viewTab[m_tabIndex].primaryView;
426 group.writeEntry("Primary Url", cont->url().url());
427 group.writeEntry("Primary Editable Url", cont->isUrlEditable());
428
429 cont = m_viewTab[m_tabIndex].secondaryView;
430 if (cont != 0) {
431 group.writeEntry("Secondary Url", cont->url().url());
432 group.writeEntry("Secondary Editable Url", cont->isUrlEditable());
433 }
434 }
435
436 void DolphinMainWindow::readProperties(const KConfigGroup& group)
437 {
438 // TODO: read tabs
439 DolphinViewContainer* cont = m_viewTab[m_tabIndex].primaryView;
440
441 cont->setUrl(group.readEntry("Primary Url"));
442 bool editable = group.readEntry("Primary Editable Url", false);
443 cont->urlNavigator()->setUrlEditable(editable);
444
445 cont = m_viewTab[m_tabIndex].secondaryView;
446 const QString secondaryUrl = group.readEntry("Secondary Url");
447 if (!secondaryUrl.isEmpty()) {
448 if (cont == 0) {
449 // a secondary view should be shown, but no one is available
450 // currently -> create a new view
451 toggleSplitView();
452 cont = m_viewTab[m_tabIndex].secondaryView;
453 Q_ASSERT(cont != 0);
454 }
455
456 cont->setUrl(secondaryUrl);
457 bool editable = group.readEntry("Secondary Editable Url", false);
458 cont->urlNavigator()->setUrlEditable(editable);
459 } else if (cont != 0) {
460 // no secondary view should be shown, but the default setting shows
461 // one already -> close the view
462 toggleSplitView();
463 }
464 }
465
466 void DolphinMainWindow::updateNewMenu()
467 {
468 m_newMenu->slotCheckUpToDate();
469 m_newMenu->setPopupFiles(activeViewContainer()->url());
470 }
471
472 void DolphinMainWindow::quit()
473 {
474 close();
475 }
476
477 void DolphinMainWindow::showErrorMessage(const QString& message)
478 {
479 if (!message.isEmpty()) {
480 DolphinStatusBar* statusBar = m_activeViewContainer->statusBar();
481 statusBar->setMessage(message, DolphinStatusBar::Error);
482 }
483 }
484
485 void DolphinMainWindow::slotUndoAvailable(bool available)
486 {
487 QAction* undoAction = actionCollection()->action(KStandardAction::name(KStandardAction::Undo));
488 if (undoAction != 0) {
489 undoAction->setEnabled(available);
490 }
491 }
492
493 void DolphinMainWindow::restoreClosedTab(QAction* action)
494 {
495 //The Clear Recently Closed Tabs List QAction, has it's data set to true, so we can detect it in here, as it's an exception.
496 if (action->data().toBool() == true) {
497 // Lets preserve the separator, and the clear action within this menu.
498 QList<QAction*> actionlist = m_recentTabsMenu->menu()->actions();
499 for (int i = 2; i < actionlist.size(); i++) {
500 m_recentTabsMenu->menu()->removeAction(actionlist.at(i));
501 }
502 } else {
503 const ClosedTab closedTab = action->data().value<ClosedTab>();
504
505 openNewTab(closedTab.primaryUrl);
506 m_tabBar->setCurrentIndex(m_viewTab.count() - 1);
507
508 if (closedTab.isSplit) {
509 //Create secondary view.
510 toggleSplitView();
511 m_viewTab[m_tabIndex].secondaryView->setUrl(closedTab.secondaryUrl);
512 }
513
514 m_recentTabsMenu->removeAction(action);
515 }
516
517 if (m_recentTabsMenu->menu()->actions().count() == 2) {
518 m_recentTabsMenu->setEnabled(false);
519 }
520 }
521
522 void DolphinMainWindow::slotUndoTextChanged(const QString& text)
523 {
524 QAction* undoAction = actionCollection()->action(KStandardAction::name(KStandardAction::Undo));
525 if (undoAction != 0) {
526 undoAction->setText(text);
527 }
528 }
529
530 void DolphinMainWindow::undo()
531 {
532 clearStatusBar();
533 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
534 KIO::FileUndoManager::self()->undo();
535 }
536
537 void DolphinMainWindow::cut()
538 {
539 m_activeViewContainer->view()->cutSelectedItems();
540 }
541
542 void DolphinMainWindow::copy()
543 {
544 m_activeViewContainer->view()->copySelectedItems();
545 }
546
547 void DolphinMainWindow::paste()
548 {
549 m_activeViewContainer->view()->paste();
550 }
551
552 void DolphinMainWindow::updatePasteAction()
553 {
554 QAction* pasteAction = actionCollection()->action(KStandardAction::name(KStandardAction::Paste));
555 QPair<bool, QString> pasteInfo = m_activeViewContainer->view()->pasteInfo();
556 pasteAction->setEnabled(pasteInfo.first);
557 pasteAction->setText(pasteInfo.second);
558 }
559
560 void DolphinMainWindow::selectAll()
561 {
562 clearStatusBar();
563
564 // if the URL navigator is editable and focused, select the whole
565 // URL instead of all items of the view
566
567 KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator();
568 QLineEdit* lineEdit = urlNavigator->editor()->lineEdit();
569 const bool selectUrl = urlNavigator->isUrlEditable() &&
570 lineEdit->hasFocus();
571 if (selectUrl) {
572 lineEdit->selectAll();
573 } else {
574 m_activeViewContainer->view()->selectAll();
575 }
576 }
577
578 void DolphinMainWindow::invertSelection()
579 {
580 clearStatusBar();
581 m_activeViewContainer->view()->invertSelection();
582 }
583
584 void DolphinMainWindow::toggleSplitView()
585 {
586 if (m_viewTab[m_tabIndex].secondaryView == 0) {
587 createSecondaryView(m_tabIndex);
588 setActiveViewContainer(m_viewTab[m_tabIndex].secondaryView);
589 } else if (m_activeViewContainer == m_viewTab[m_tabIndex].secondaryView) {
590 // remove secondary view
591 m_viewTab[m_tabIndex].secondaryView->close();
592 m_viewTab[m_tabIndex].secondaryView->deleteLater();
593 m_viewTab[m_tabIndex].secondaryView = 0;
594
595 setActiveViewContainer(m_viewTab[m_tabIndex].primaryView);
596 } else {
597 // The primary view is active and should be closed. Hence from a users point of view
598 // the content of the secondary view should be moved to the primary view.
599 // From an implementation point of view it is more efficient to close
600 // the primary view and exchange the internal pointers afterwards.
601
602 m_viewTab[m_tabIndex].primaryView->close();
603 m_viewTab[m_tabIndex].primaryView->deleteLater();
604 m_viewTab[m_tabIndex].primaryView = m_viewTab[m_tabIndex].secondaryView;
605 m_viewTab[m_tabIndex].secondaryView = 0;
606
607 setActiveViewContainer(m_viewTab[m_tabIndex].primaryView);
608 }
609
610 updateViewActions();
611 }
612
613 void DolphinMainWindow::reloadView()
614 {
615 clearStatusBar();
616 m_activeViewContainer->view()->reload();
617 }
618
619 void DolphinMainWindow::stopLoading()
620 {
621 }
622
623 void DolphinMainWindow::toggleFilterBarVisibility(bool show)
624 {
625 m_activeViewContainer->showFilterBar(show);
626 }
627
628 void DolphinMainWindow::toggleEditLocation()
629 {
630 clearStatusBar();
631
632 QAction* action = actionCollection()->action("editable_location");
633 KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator();
634 urlNavigator->setUrlEditable(action->isChecked());
635 }
636
637 void DolphinMainWindow::replaceLocation()
638 {
639 KUrlNavigator* navigator = m_activeViewContainer->urlNavigator();
640 navigator->setUrlEditable(true);
641 navigator->setFocus();
642
643 // select the whole text of the combo box editor
644 QLineEdit* lineEdit = navigator->editor()->lineEdit();
645 const QString text = lineEdit->text();
646 lineEdit->setSelection(0, text.length());
647 }
648
649 void DolphinMainWindow::goBack()
650 {
651 clearStatusBar();
652 m_activeViewContainer->urlNavigator()->goBack();
653 }
654
655 void DolphinMainWindow::goForward()
656 {
657 clearStatusBar();
658 m_activeViewContainer->urlNavigator()->goForward();
659 }
660
661 void DolphinMainWindow::goUp()
662 {
663 clearStatusBar();
664 m_activeViewContainer->urlNavigator()->goUp();
665 }
666
667 void DolphinMainWindow::goHome()
668 {
669 clearStatusBar();
670 m_activeViewContainer->urlNavigator()->goHome();
671 }
672
673 void DolphinMainWindow::compareFiles()
674 {
675 // The method is only invoked if exactly 2 files have
676 // been selected. The selected files may be:
677 // - both in the primary view
678 // - both in the secondary view
679 // - one in the primary view and the other in the secondary
680 // view
681 Q_ASSERT(m_viewTab[m_tabIndex].primaryView != 0);
682
683 KUrl urlA;
684 KUrl urlB;
685 KUrl::List urls = m_viewTab[m_tabIndex].primaryView->view()->selectedUrls();
686
687 switch (urls.count()) {
688 case 0: {
689 Q_ASSERT(m_viewTab[m_tabIndex].secondaryView != 0);
690 urls = m_viewTab[m_tabIndex].secondaryView->view()->selectedUrls();
691 Q_ASSERT(urls.count() == 2);
692 urlA = urls[0];
693 urlB = urls[1];
694 break;
695 }
696
697 case 1: {
698 urlA = urls[0];
699 Q_ASSERT(m_viewTab[m_tabIndex].secondaryView != 0);
700 urls = m_viewTab[m_tabIndex].secondaryView->view()->selectedUrls();
701 Q_ASSERT(urls.count() == 1);
702 urlB = urls[0];
703 break;
704 }
705
706 case 2: {
707 urlA = urls[0];
708 urlB = urls[1];
709 break;
710 }
711
712 default: {
713 // may not happen: compareFiles may only get invoked if 2
714 // files are selected
715 Q_ASSERT(false);
716 }
717 }
718
719 QString command("kompare -c \"");
720 command.append(urlA.pathOrUrl());
721 command.append("\" \"");
722 command.append(urlB.pathOrUrl());
723 command.append('\"');
724 KRun::runCommand(command, "Kompare", "kompare", this);
725 }
726
727 void DolphinMainWindow::quickView()
728 {
729 const KUrl::List urls = activeViewContainer()->view()->selectedUrls();
730 Q_ASSERT(urls.count() > 0);
731
732 QDBusMessage msg = QDBusMessage::createMethodCall("org.kde.plasma", "/Previewer", "", "openFile");
733 foreach (const KUrl& url, urls) {
734 msg.setArguments(QList<QVariant>() << url.prettyUrl());
735 QDBusConnection::sessionBus().send(msg);
736 }
737 }
738
739 void DolphinMainWindow::toggleShowMenuBar()
740 {
741 const bool visible = menuBar()->isVisible();
742 menuBar()->setVisible(!visible);
743 }
744
745 void DolphinMainWindow::editSettings()
746 {
747 if (m_settingsDialog == 0) {
748 const KUrl& url = activeViewContainer()->url();
749 m_settingsDialog = new DolphinSettingsDialog(url, this);
750 m_settingsDialog->setAttribute(Qt::WA_DeleteOnClose);
751 m_settingsDialog->show();
752 } else {
753 m_settingsDialog->raise();
754 }
755 }
756
757 void DolphinMainWindow::setActiveTab(int index)
758 {
759 Q_ASSERT(index >= 0);
760 Q_ASSERT(index < m_viewTab.count());
761 if (index == m_tabIndex) {
762 return;
763 }
764
765 // hide current tab content
766 ViewTab& hiddenTab = m_viewTab[m_tabIndex];
767 hiddenTab.isPrimaryViewActive = hiddenTab.primaryView->isActive();
768 hiddenTab.primaryView->setActive(false);
769 if (hiddenTab.secondaryView != 0) {
770 hiddenTab.secondaryView->setActive(false);
771 }
772 QSplitter* splitter = m_viewTab[m_tabIndex].splitter;
773 splitter->hide();
774 m_centralWidgetLayout->removeWidget(splitter);
775
776 // show active tab content
777 m_tabIndex = index;
778
779 ViewTab& viewTab = m_viewTab[index];
780 m_centralWidgetLayout->addWidget(viewTab.splitter);
781 viewTab.primaryView->show();
782 if (viewTab.secondaryView != 0) {
783 viewTab.secondaryView->show();
784 }
785 viewTab.splitter->show();
786
787 setActiveViewContainer(viewTab.isPrimaryViewActive ? viewTab.primaryView :
788 viewTab.secondaryView);
789 }
790
791 void DolphinMainWindow::closeTab()
792 {
793 closeTab(m_tabBar->currentIndex());
794 }
795
796 void DolphinMainWindow::closeTab(int index)
797 {
798 Q_ASSERT(index >= 0);
799 Q_ASSERT(index < m_viewTab.count());
800 if (m_viewTab.count() == 1) {
801 // the last tab may never get closed
802 return;
803 }
804
805 if (index == m_tabIndex) {
806 // The tab that should be closed is the active tab. Activate the
807 // previous tab before closing the tab.
808 m_tabBar->setCurrentIndex((index > 0) ? index - 1 : 1);
809 }
810 rememberClosedTab(index);
811 //Delete this tab.
812 m_viewTab[index].primaryView->deleteLater();
813 if (m_viewTab[index].secondaryView != 0) {
814 m_viewTab[index].secondaryView->deleteLater();
815 }
816 m_viewTab[index].splitter->deleteLater();
817 m_viewTab.erase(m_viewTab.begin() + index);
818
819 m_tabBar->blockSignals(true);
820 m_tabBar->removeTab(index);
821
822 if (m_tabIndex > index) {
823 m_tabIndex--;
824 Q_ASSERT(m_tabIndex >= 0);
825 }
826
827 // if only one tab is left, also remove the tab entry so that
828 // closing the last tab is not possible
829 if (m_viewTab.count() == 1) {
830 m_tabBar->removeTab(0);
831 actionCollection()->action("close_tab")->setEnabled(false);
832 } else {
833 m_tabBar->blockSignals(false);
834 }
835 }
836
837 void DolphinMainWindow::openTabContextMenu(int index, const QPoint& pos)
838 {
839 KMenu menu(this);
840
841 QAction* newTabAction = menu.addAction(KIcon("tab-new"), i18nc("@action:inmenu", "New Tab"));
842 newTabAction->setShortcut(actionCollection()->action("new_tab")->shortcut());
843
844 QAction* closeOtherTabsAction = menu.addAction(KIcon("tab-close-other"), i18nc("@action:inmenu", "Close Other Tabs"));
845
846 QAction* closeTabAction = menu.addAction(KIcon("tab-close"), i18nc("@action:inmenu", "Close Tab"));
847 closeTabAction->setShortcut(actionCollection()->action("close_tab")->shortcut());
848
849 QAction* selectedAction = menu.exec(pos);
850 if (selectedAction == newTabAction) {
851 const ViewTab& tab = m_viewTab[index];
852 Q_ASSERT(tab.primaryView != 0);
853 const KUrl url = (tab.secondaryView != 0) && tab.secondaryView->isActive() ?
854 tab.secondaryView->url() : tab.primaryView->url();
855 openNewTab(url);
856 m_tabBar->setCurrentIndex(m_viewTab.count() - 1);
857 } else if (selectedAction == closeOtherTabsAction) {
858 const int count = m_tabBar->count();
859 for (int i = 0; i < index; ++i) {
860 closeTab(0);
861 }
862 for (int i = index + 1; i < count; ++i) {
863 closeTab(1);
864 }
865 } else if (selectedAction == closeTabAction) {
866 closeTab(index);
867 }
868 }
869
870 void DolphinMainWindow::handlePlacesClick(const KUrl& url, Qt::MouseButtons buttons)
871 {
872 if (buttons & Qt::MidButton) {
873 openNewTab(url);
874 m_tabBar->setCurrentIndex(m_viewTab.count() - 1);
875 } else {
876 changeUrl(url);
877 }
878 }
879
880 void DolphinMainWindow::slotTestCanDecode(const QDragMoveEvent* event, bool& canDecode)
881 {
882 canDecode = KUrl::List::canDecode(event->mimeData());
883 }
884
885 void DolphinMainWindow::searchItems(const KUrl& url)
886 {
887 m_activeViewContainer->setUrl(url);
888 }
889
890
891 void DolphinMainWindow::init()
892 {
893 DolphinSettings& settings = DolphinSettings::instance();
894
895 // Check whether Dolphin runs the first time. If yes then
896 // a proper default window size is given at the end of DolphinMainWindow::init().
897 GeneralSettings* generalSettings = settings.generalSettings();
898 const bool firstRun = generalSettings->firstRun();
899 if (firstRun) {
900 generalSettings->setViewPropsTimestamp(QDateTime::currentDateTime());
901 }
902
903 setAcceptDrops(true);
904
905 m_viewTab[m_tabIndex].splitter = new QSplitter(this);
906
907 setupActions();
908
909 const KUrl& homeUrl = generalSettings->homeUrl();
910 setCaption(homeUrl.fileName());
911 m_actionHandler = new DolphinViewActionHandler(actionCollection(), this);
912 connect(m_actionHandler, SIGNAL(actionBeingHandled()), SLOT(clearStatusBar()));
913 ViewProperties props(homeUrl);
914 m_viewTab[m_tabIndex].primaryView = new DolphinViewContainer(this,
915 m_viewTab[m_tabIndex].splitter,
916 homeUrl);
917
918 m_activeViewContainer = m_viewTab[m_tabIndex].primaryView;
919 connectViewSignals(m_activeViewContainer);
920 DolphinView* view = m_activeViewContainer->view();
921 view->reload();
922 m_activeViewContainer->show();
923 m_actionHandler->setCurrentView(view);
924
925 m_tabBar = new KTabBar(this);
926 m_tabBar->setMovable(true);
927 m_tabBar->setTabsClosable(true);
928 connect(m_tabBar, SIGNAL(currentChanged(int)),
929 this, SLOT(setActiveTab(int)));
930 connect(m_tabBar, SIGNAL(closeRequest(int)),
931 this, SLOT(closeTab(int)));
932 connect(m_tabBar, SIGNAL(contextMenu(int, const QPoint&)),
933 this, SLOT(openTabContextMenu(int, const QPoint&)));
934 connect(m_tabBar, SIGNAL(newTabRequest()),
935 this, SLOT(openNewTab()));
936 connect(m_tabBar, SIGNAL(testCanDecode(const QDragMoveEvent*, bool&)),
937 this, SLOT(slotTestCanDecode(const QDragMoveEvent*, bool&)));
938 connect(m_tabBar, SIGNAL(wheelDelta(int)),
939 this, SLOT(slotWheelMoved(int)));
940 connect(m_tabBar, SIGNAL(mouseMiddleClick(int)),
941 this, SLOT(closeTab(int)));
942
943 m_tabBar->blockSignals(true); // signals get unblocked after at least 2 tabs are open
944
945 QWidget* centralWidget = new QWidget(this);
946 m_centralWidgetLayout = new QVBoxLayout(centralWidget);
947 m_centralWidgetLayout->setSpacing(0);
948 m_centralWidgetLayout->setMargin(0);
949 m_centralWidgetLayout->addWidget(m_tabBar);
950 m_centralWidgetLayout->addWidget(m_viewTab[m_tabIndex].splitter);
951
952 setCentralWidget(centralWidget);
953 setupDockWidgets();
954 emit urlChanged(homeUrl);
955
956 setupGUI(Keys | Save | Create | ToolBar);
957
958 m_searchBox->setParent(toolBar("searchToolBar"));
959 m_searchBox->show();
960
961 stateChanged("new_file");
962
963 QClipboard* clipboard = QApplication::clipboard();
964 connect(clipboard, SIGNAL(dataChanged()),
965 this, SLOT(updatePasteAction()));
966 updatePasteAction();
967 updateGoActions();
968
969 if (generalSettings->splitView()) {
970 toggleSplitView();
971 }
972 updateViewActions();
973
974 QAction* showFilterBarAction = actionCollection()->action("show_filter_bar");
975 showFilterBarAction->setChecked(generalSettings->filterBar());
976
977 if (firstRun) {
978 // assure a proper default size if Dolphin runs the first time
979 resize(750, 500);
980 }
981
982 m_showMenuBar->setChecked(!menuBar()->isHidden()); // workaround for bug #171080
983 }
984
985 void DolphinMainWindow::setActiveViewContainer(DolphinViewContainer* viewContainer)
986 {
987 Q_ASSERT(viewContainer != 0);
988 Q_ASSERT((viewContainer == m_viewTab[m_tabIndex].primaryView) ||
989 (viewContainer == m_viewTab[m_tabIndex].secondaryView));
990 if (m_activeViewContainer == viewContainer) {
991 return;
992 }
993
994 m_activeViewContainer->setActive(false);
995 m_activeViewContainer = viewContainer;
996
997 // Activating the view container might trigger a recursive setActiveViewContainer() call
998 // inside DolphinMainWindow::toggleActiveView() when having a split view. Temporary
999 // disconnect the activated() signal in this case:
1000 disconnect(m_activeViewContainer->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1001 m_activeViewContainer->setActive(true);
1002 connect(m_activeViewContainer->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1003
1004 m_actionHandler->setCurrentView(viewContainer->view());
1005
1006 updateHistory();
1007 updateEditActions();
1008 updateViewActions();
1009 updateGoActions();
1010
1011 const KUrl& url = m_activeViewContainer->url();
1012 setCaption(url.fileName());
1013 if (m_viewTab.count() > 1) {
1014 m_tabBar->setTabText(m_tabIndex, tabName(url));
1015 }
1016
1017 emit urlChanged(url);
1018 }
1019
1020 void DolphinMainWindow::setupActions()
1021 {
1022 // setup 'File' menu
1023 m_newMenu = new DolphinNewMenu(this, this);
1024 KMenu* menu = m_newMenu->menu();
1025 menu->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1026 menu->setIcon(KIcon("document-new"));
1027 connect(menu, SIGNAL(aboutToShow()),
1028 this, SLOT(updateNewMenu()));
1029
1030 KAction* newWindow = actionCollection()->addAction("new_window");
1031 newWindow->setIcon(KIcon("window-new"));
1032 newWindow->setText(i18nc("@action:inmenu File", "New &Window"));
1033 newWindow->setShortcut(Qt::CTRL | Qt::Key_N);
1034 connect(newWindow, SIGNAL(triggered()), this, SLOT(openNewMainWindow()));
1035
1036 KAction* newTab = actionCollection()->addAction("new_tab");
1037 newTab->setIcon(KIcon("tab-new"));
1038 newTab->setText(i18nc("@action:inmenu File", "New Tab"));
1039 newTab->setShortcut(KShortcut(Qt::CTRL | Qt::Key_T, Qt::CTRL | Qt::SHIFT | Qt::Key_N));
1040 connect(newTab, SIGNAL(triggered()), this, SLOT(openNewTab()));
1041
1042 KAction* closeTab = actionCollection()->addAction("close_tab");
1043 closeTab->setIcon(KIcon("tab-close"));
1044 closeTab->setText(i18nc("@action:inmenu File", "Close Tab"));
1045 closeTab->setShortcut(Qt::CTRL | Qt::Key_W);
1046 closeTab->setEnabled(false);
1047 connect(closeTab, SIGNAL(triggered()), this, SLOT(closeTab()));
1048
1049 KStandardAction::quit(this, SLOT(quit()), actionCollection());
1050
1051 // setup 'Edit' menu
1052 KStandardAction::undo(this,
1053 SLOT(undo()),
1054 actionCollection());
1055
1056 // need to remove shift+del from cut action, else the shortcut for deletejob
1057 // doesn't work
1058 KAction* cut = KStandardAction::cut(this, SLOT(cut()), actionCollection());
1059 KShortcut cutShortcut = cut->shortcut();
1060 cutShortcut.remove(Qt::SHIFT + Qt::Key_Delete, KShortcut::KeepEmpty);
1061 cut->setShortcut(cutShortcut);
1062 KStandardAction::copy(this, SLOT(copy()), actionCollection());
1063 KStandardAction::paste(this, SLOT(paste()), actionCollection());
1064
1065 KAction* selectAll = actionCollection()->addAction("select_all");
1066 selectAll->setText(i18nc("@action:inmenu Edit", "Select All"));
1067 selectAll->setShortcut(Qt::CTRL + Qt::Key_A);
1068 connect(selectAll, SIGNAL(triggered()), this, SLOT(selectAll()));
1069
1070 KAction* invertSelection = actionCollection()->addAction("invert_selection");
1071 invertSelection->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1072 invertSelection->setShortcut(Qt::CTRL | Qt::SHIFT | Qt::Key_A);
1073 connect(invertSelection, SIGNAL(triggered()), this, SLOT(invertSelection()));
1074
1075 // setup 'View' menu
1076 // (note that most of it is set up in DolphinViewActionHandler)
1077
1078 KAction* split = actionCollection()->addAction("split_view");
1079 split->setShortcut(Qt::Key_F3);
1080 updateSplitAction();
1081 connect(split, SIGNAL(triggered()), this, SLOT(toggleSplitView()));
1082
1083 KAction* reload = actionCollection()->addAction("reload");
1084 reload->setText(i18nc("@action:inmenu View", "Reload"));
1085 reload->setShortcut(Qt::Key_F5);
1086 reload->setIcon(KIcon("view-refresh"));
1087 connect(reload, SIGNAL(triggered()), this, SLOT(reloadView()));
1088
1089 KAction* stop = actionCollection()->addAction("stop");
1090 stop->setText(i18nc("@action:inmenu View", "Stop"));
1091 stop->setIcon(KIcon("process-stop"));
1092 connect(stop, SIGNAL(triggered()), this, SLOT(stopLoading()));
1093
1094 KToggleAction* showFullLocation = actionCollection()->add<KToggleAction>("editable_location");
1095 showFullLocation->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1096 showFullLocation->setShortcut(Qt::CTRL | Qt::Key_L);
1097 connect(showFullLocation, SIGNAL(triggered()), this, SLOT(toggleEditLocation()));
1098
1099 KAction* replaceLocation = actionCollection()->addAction("replace_location");
1100 replaceLocation->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1101 replaceLocation->setShortcut(Qt::Key_F6);
1102 connect(replaceLocation, SIGNAL(triggered()), this, SLOT(replaceLocation()));
1103
1104 // setup 'Go' menu
1105 KAction* backAction = KStandardAction::back(this, SLOT(goBack()), actionCollection());
1106 KShortcut backShortcut = backAction->shortcut();
1107 backShortcut.setAlternate(Qt::Key_Backspace);
1108 backAction->setShortcut(backShortcut);
1109
1110 m_recentTabsMenu = new KActionMenu(i18n("&Recently Closed Tabs"), this);
1111 m_recentTabsMenu->setIcon(KIcon("edit-undo"));
1112 actionCollection()->addAction("closed_tabs", m_recentTabsMenu);
1113 connect(m_recentTabsMenu->menu(), SIGNAL(triggered(QAction *)),
1114 this, SLOT(restoreClosedTab(QAction *)));
1115
1116 QAction* action = new QAction("&Empty Recently Closed Tabs", m_recentTabsMenu);
1117 action->setIcon(KIcon("edit-clear-list"));
1118 action->setData(QVariant::fromValue(true));
1119 m_recentTabsMenu->addAction(action);
1120 m_recentTabsMenu->addSeparator();
1121 m_recentTabsMenu->setEnabled(false);
1122
1123 KStandardAction::forward(this, SLOT(goForward()), actionCollection());
1124 KStandardAction::up(this, SLOT(goUp()), actionCollection());
1125 KStandardAction::home(this, SLOT(goHome()), actionCollection());
1126
1127 // setup 'Tools' menu
1128 KToggleAction* showSearchBar = actionCollection()->add<KToggleAction>("show_search_bar");
1129 showSearchBar->setText(i18nc("@action:inmenu Tools", "Show Search Bar"));
1130 showSearchBar->setShortcut(Qt::CTRL | Qt::Key_S);
1131 connect(showSearchBar, SIGNAL(triggered(bool)), this, SLOT(toggleFilterBarVisibility(bool)));
1132
1133 KToggleAction* showFilterBar = actionCollection()->add<KToggleAction>("show_filter_bar");
1134 showFilterBar->setText(i18nc("@action:inmenu Tools", "Show Filter Bar"));
1135 showFilterBar->setShortcut(Qt::CTRL | Qt::Key_I);
1136 connect(showFilterBar, SIGNAL(triggered(bool)), this, SLOT(toggleFilterBarVisibility(bool)));
1137
1138 KAction* compareFiles = actionCollection()->addAction("compare_files");
1139 compareFiles->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1140 compareFiles->setIcon(KIcon("kompare"));
1141 compareFiles->setEnabled(false);
1142 connect(compareFiles, SIGNAL(triggered()), this, SLOT(compareFiles()));
1143
1144 // disabled Quick View
1145 #if defined(QUICK_VIEW)
1146 KAction* quickView = actionCollection()->addAction("quick_view");
1147 quickView->setText(i18nc("@action:inmenu Tools", "Quick View"));
1148 quickView->setIcon(KIcon("view-preview"));
1149 quickView->setShortcut(Qt::CTRL + Qt::Key_Return);
1150 quickView->setEnabled(false);
1151 connect(quickView, SIGNAL(triggered()), this, SLOT(quickView()));
1152 #endif
1153
1154 // setup 'Settings' menu
1155 m_showMenuBar = KStandardAction::showMenubar(this, SLOT(toggleShowMenuBar()), actionCollection());
1156 KStandardAction::preferences(this, SLOT(editSettings()), actionCollection());
1157
1158 // not in menu actions
1159 KAction* activateNextTab = actionCollection()->addAction("activate_next_tab");
1160 activateNextTab->setText(i18nc("@action:inmenu", "Activate Next Tab"));
1161 connect(activateNextTab, SIGNAL(triggered()), SLOT(activateNextTab()));
1162 activateNextTab->setShortcuts(QApplication::isRightToLeft() ? KStandardShortcut::tabPrev() :
1163 KStandardShortcut::tabNext());
1164
1165 KAction* activatePrevTab = actionCollection()->addAction("activate_prev_tab");
1166 activatePrevTab->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
1167 connect(activatePrevTab, SIGNAL(triggered()), SLOT(activatePrevTab()));
1168 activatePrevTab->setShortcuts(QApplication::isRightToLeft() ? KStandardShortcut::tabNext() :
1169 KStandardShortcut::tabPrev());
1170
1171 // for context menu
1172 KAction* openInNewTab = actionCollection()->addAction("open_in_new_tab");
1173 openInNewTab->setText(i18nc("@action:inmenu", "Open in New Tab"));
1174 openInNewTab->setIcon(KIcon("tab-new"));
1175 connect(openInNewTab, SIGNAL(triggered()), this, SLOT(openInNewTab()));
1176
1177 KAction* openInNewWindow = actionCollection()->addAction("open_in_new_window");
1178 openInNewWindow->setText(i18nc("@action:inmenu", "Open in New Window"));
1179 openInNewWindow->setIcon(KIcon("window-new"));
1180 connect(openInNewWindow, SIGNAL(triggered()), this, SLOT(openInNewWindow()));
1181
1182 // 'Search' toolbar
1183 m_searchBox = new DolphinSearchBox(this);
1184 connect(m_searchBox, SIGNAL(search(KUrl)), this, SLOT(searchItems(KUrl)));
1185
1186 KAction* search = new KAction(this);
1187 actionCollection()->addAction("search_bar", search);
1188 search->setText(i18nc("@action:inmenu", "Search Bar"));
1189 search->setDefaultWidget(m_searchBox);
1190 search->setShortcutConfigurable(false);
1191 }
1192
1193 void DolphinMainWindow::setupDockWidgets()
1194 {
1195 // setup "Information"
1196 QDockWidget* infoDock = new QDockWidget(i18nc("@title:window", "Information"));
1197 infoDock->setObjectName("infoDock");
1198 infoDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
1199 Panel* infoPanel = new InformationPanel(infoDock);
1200 infoDock->setWidget(infoPanel);
1201
1202 QAction* infoAction = infoDock->toggleViewAction();
1203 infoAction->setText(i18nc("@title:window", "Information"));
1204 infoAction->setShortcut(Qt::Key_F11);
1205 infoAction->setIcon(KIcon("dialog-information"));
1206 actionCollection()->addAction("show_info_panel", infoDock->toggleViewAction());
1207
1208 addDockWidget(Qt::RightDockWidgetArea, infoDock);
1209 connect(this, SIGNAL(urlChanged(KUrl)),
1210 infoPanel, SLOT(setUrl(KUrl)));
1211 connect(this, SIGNAL(selectionChanged(KFileItemList)),
1212 infoPanel, SLOT(setSelection(KFileItemList)));
1213 connect(this, SIGNAL(requestItemInfo(KFileItem)),
1214 infoPanel, SLOT(requestDelayedItemInfo(KFileItem)));
1215
1216 // setup "Folders"
1217 QDockWidget* foldersDock = new QDockWidget(i18nc("@title:window", "Folders"));
1218 foldersDock->setObjectName("foldersDock");
1219 foldersDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
1220 FoldersPanel* foldersPanel = new FoldersPanel(foldersDock);
1221 foldersDock->setWidget(foldersPanel);
1222
1223 QAction* foldersAction = foldersDock->toggleViewAction();
1224 foldersAction->setText(i18nc("@title:window", "Folders"));
1225 foldersAction->setShortcut(Qt::Key_F7);
1226 foldersAction->setIcon(KIcon("folder"));
1227 actionCollection()->addAction("show_folders_panel", foldersDock->toggleViewAction());
1228
1229 addDockWidget(Qt::LeftDockWidgetArea, foldersDock);
1230 connect(this, SIGNAL(urlChanged(KUrl)),
1231 foldersPanel, SLOT(setUrl(KUrl)));
1232 connect(foldersPanel, SIGNAL(changeUrl(KUrl, Qt::MouseButtons)),
1233 this, SLOT(handlePlacesClick(KUrl, Qt::MouseButtons)));
1234 connect(foldersPanel, SIGNAL(changeSelection(KFileItemList)),
1235 this, SLOT(changeSelection(KFileItemList)));
1236
1237 // setup "Terminal"
1238 #ifndef Q_OS_WIN
1239 QDockWidget* terminalDock = new QDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
1240 terminalDock->setObjectName("terminalDock");
1241 terminalDock->setAllowedAreas(Qt::TopDockWidgetArea | Qt::BottomDockWidgetArea);
1242 Panel* terminalPanel = new TerminalPanel(terminalDock);
1243 terminalDock->setWidget(terminalPanel);
1244
1245 connect(terminalPanel, SIGNAL(hideTerminalPanel()), terminalDock, SLOT(hide()));
1246
1247 QAction* terminalAction = terminalDock->toggleViewAction();
1248 terminalAction->setText(i18nc("@title:window Shell terminal", "Terminal"));
1249 terminalAction->setShortcut(Qt::Key_F4);
1250 terminalAction->setIcon(KIcon("terminal"));
1251 actionCollection()->addAction("show_terminal_panel", terminalDock->toggleViewAction());
1252
1253 addDockWidget(Qt::BottomDockWidgetArea, terminalDock);
1254 connect(this, SIGNAL(urlChanged(KUrl)),
1255 terminalPanel, SLOT(setUrl(KUrl)));
1256 #endif
1257
1258 const bool firstRun = DolphinSettings::instance().generalSettings()->firstRun();
1259 if (firstRun) {
1260 foldersDock->hide();
1261 #ifndef Q_OS_WIN
1262 terminalDock->hide();
1263 #endif
1264 }
1265
1266 QDockWidget* placesDock = new QDockWidget(i18nc("@title:window", "Places"));
1267 placesDock->setObjectName("placesDock");
1268 placesDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
1269
1270 PlacesPanel* placesPanel = new PlacesPanel(placesDock);
1271 placesDock->setWidget(placesPanel);
1272 placesPanel->setModel(DolphinSettings::instance().placesModel());
1273 placesPanel->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
1274
1275 QAction* placesAction = placesDock->toggleViewAction();
1276 placesAction->setText(i18nc("@title:window", "Places"));
1277 placesAction->setShortcut(Qt::Key_F9);
1278 placesAction->setIcon(KIcon("bookmarks"));
1279 actionCollection()->addAction("show_places_panel", placesDock->toggleViewAction());
1280
1281 addDockWidget(Qt::LeftDockWidgetArea, placesDock);
1282 connect(placesPanel, SIGNAL(urlChanged(KUrl, Qt::MouseButtons)),
1283 this, SLOT(handlePlacesClick(KUrl, Qt::MouseButtons)));
1284 connect(this, SIGNAL(urlChanged(KUrl)),
1285 placesPanel, SLOT(setUrl(KUrl)));
1286 }
1287
1288 void DolphinMainWindow::updateEditActions()
1289 {
1290 const KFileItemList list = m_activeViewContainer->view()->selectedItems();
1291 if (list.isEmpty()) {
1292 stateChanged("has_no_selection");
1293 } else {
1294 stateChanged("has_selection");
1295
1296 KActionCollection* col = actionCollection();
1297 QAction* renameAction = col->action("rename");
1298 QAction* moveToTrashAction = col->action("move_to_trash");
1299 QAction* deleteAction = col->action("delete");
1300 QAction* cutAction = col->action(KStandardAction::name(KStandardAction::Cut));
1301 QAction* deleteWithTrashShortcut = col->action("delete_shortcut"); // see DolphinViewActionHandler
1302
1303 KonqFileItemCapabilities capabilities(list);
1304 const bool enableMoveToTrash = capabilities.isLocal() && capabilities.supportsMoving();
1305
1306 renameAction->setEnabled(capabilities.supportsMoving());
1307 moveToTrashAction->setEnabled(enableMoveToTrash);
1308 deleteAction->setEnabled(capabilities.supportsDeleting());
1309 deleteWithTrashShortcut->setEnabled(capabilities.supportsDeleting() && !enableMoveToTrash);
1310 cutAction->setEnabled(capabilities.supportsMoving());
1311 }
1312 updatePasteAction();
1313 }
1314
1315 void DolphinMainWindow::updateViewActions()
1316 {
1317 m_actionHandler->updateViewActions();
1318
1319 QAction* showFilterBarAction = actionCollection()->action("show_filter_bar");
1320 showFilterBarAction->setChecked(m_activeViewContainer->isFilterBarVisible());
1321
1322 updateSplitAction();
1323
1324 QAction* editableLocactionAction = actionCollection()->action("editable_location");
1325 const KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator();
1326 editableLocactionAction->setChecked(urlNavigator->isUrlEditable());
1327 }
1328
1329 void DolphinMainWindow::updateGoActions()
1330 {
1331 QAction* goUpAction = actionCollection()->action(KStandardAction::name(KStandardAction::Up));
1332 const KUrl& currentUrl = m_activeViewContainer->url();
1333 goUpAction->setEnabled(currentUrl.upUrl() != currentUrl);
1334 }
1335
1336 void DolphinMainWindow::rememberClosedTab(int index)
1337 {
1338 KMenu* tabsMenu = m_recentTabsMenu->menu();
1339
1340 const QString primaryPath = m_viewTab[index].primaryView->url().path();
1341 const QString iconName = KMimeType::iconNameForUrl(primaryPath);
1342
1343 QAction* action = new QAction(primaryPath, tabsMenu);
1344
1345 ClosedTab closedTab;
1346 closedTab.primaryUrl = m_viewTab[index].primaryView->url();
1347
1348 if (m_viewTab[index].secondaryView != 0) {
1349 closedTab.secondaryUrl = m_viewTab[index].secondaryView->url();
1350 closedTab.isSplit = true;
1351 } else {
1352 closedTab.isSplit = false;
1353 }
1354
1355 action->setData(QVariant::fromValue(closedTab));
1356 action->setIcon(KIcon(iconName));
1357
1358 //Add our action after the separator and the clear list actions
1359 if (tabsMenu->actions().size() == 2) {
1360 tabsMenu->addAction(action);
1361 } else {
1362
1363 tabsMenu->insertAction(tabsMenu->actions().at(2), action);
1364 }
1365 actionCollection()->action("closed_tabs")->setEnabled(true);
1366 }
1367
1368 void DolphinMainWindow::clearStatusBar()
1369 {
1370 m_activeViewContainer->statusBar()->clear();
1371 }
1372
1373 void DolphinMainWindow::connectViewSignals(DolphinViewContainer* container)
1374 {
1375 connect(container, SIGNAL(showFilterBarChanged(bool)),
1376 this, SLOT(updateFilterBarAction(bool)));
1377
1378 DolphinView* view = container->view();
1379 connect(view, SIGNAL(selectionChanged(KFileItemList)),
1380 this, SLOT(slotSelectionChanged(KFileItemList)));
1381 connect(view, SIGNAL(requestItemInfo(KFileItem)),
1382 this, SLOT(slotRequestItemInfo(KFileItem)));
1383 connect(view, SIGNAL(activated()),
1384 this, SLOT(toggleActiveView()));
1385 connect(view, SIGNAL(tabRequested(const KUrl&)),
1386 this, SLOT(openNewTab(const KUrl&)));
1387
1388 const KUrlNavigator* navigator = container->urlNavigator();
1389 connect(navigator, SIGNAL(urlChanged(const KUrl&)),
1390 this, SLOT(changeUrl(const KUrl&)));
1391 connect(navigator, SIGNAL(historyChanged()),
1392 this, SLOT(updateHistory()));
1393 connect(navigator, SIGNAL(editableStateChanged(bool)),
1394 this, SLOT(slotEditableStateChanged(bool)));
1395 }
1396
1397 void DolphinMainWindow::updateSplitAction()
1398 {
1399 QAction* splitAction = actionCollection()->action("split_view");
1400 if (m_viewTab[m_tabIndex].secondaryView != 0) {
1401 if (m_activeViewContainer == m_viewTab[m_tabIndex].secondaryView) {
1402 splitAction->setText(i18nc("@action:intoolbar Close right view", "Close"));
1403 splitAction->setIcon(KIcon("view-right-close"));
1404 } else {
1405 splitAction->setText(i18nc("@action:intoolbar Close left view", "Close"));
1406 splitAction->setIcon(KIcon("view-left-close"));
1407 }
1408 } else {
1409 splitAction->setText(i18nc("@action:intoolbar Split view", "Split"));
1410 splitAction->setIcon(KIcon("view-right-new"));
1411 }
1412 }
1413
1414 QString DolphinMainWindow::tabName(const KUrl& url) const
1415 {
1416 QString name;
1417 if (url.equals(KUrl("file:///"))) {
1418 name = "/";
1419 } else {
1420 name = url.fileName();
1421 if (name.isEmpty()) {
1422 name = url.protocol();
1423 } else {
1424 // Make sure that a '&' inside the directory name is displayed correctly
1425 // and not misinterpreted as a keyboard shortcut in QTabBar::setTabText()
1426 name.replace('&', "&&");
1427 }
1428 }
1429 return name;
1430 }
1431
1432 bool DolphinMainWindow::isKompareInstalled() const
1433 {
1434 static bool initialized = false;
1435 static bool installed = false;
1436 if (!initialized) {
1437 // TODO: maybe replace this approach later by using a menu
1438 // plugin like kdiff3plugin.cpp
1439 installed = !KGlobal::dirs()->findExe("kompare").isEmpty();
1440 initialized = true;
1441 }
1442 return installed;
1443 }
1444
1445 void DolphinMainWindow::createSecondaryView(int tabIndex)
1446 {
1447 QSplitter* splitter = m_viewTab[tabIndex].splitter;
1448 const int newWidth = (m_viewTab[tabIndex].primaryView->width() - splitter->handleWidth()) / 2;
1449
1450 const DolphinView* view = m_viewTab[tabIndex].primaryView->view();
1451 m_viewTab[tabIndex].secondaryView = new DolphinViewContainer(this, 0, view->rootUrl());
1452 splitter->addWidget(m_viewTab[tabIndex].secondaryView);
1453 splitter->setSizes(QList<int>() << newWidth << newWidth);
1454 connectViewSignals(m_viewTab[tabIndex].secondaryView);
1455 m_viewTab[tabIndex].secondaryView->view()->reload();
1456 m_viewTab[tabIndex].secondaryView->setActive(false);
1457 m_viewTab[tabIndex].secondaryView->show();
1458 }
1459
1460 DolphinMainWindow::UndoUiInterface::UndoUiInterface() :
1461 KIO::FileUndoManager::UiInterface()
1462 {
1463 }
1464
1465 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
1466 {
1467 }
1468
1469 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job* job)
1470 {
1471 DolphinMainWindow* mainWin= qobject_cast<DolphinMainWindow *>(parentWidget());
1472 if (mainWin) {
1473 DolphinStatusBar* statusBar = mainWin->activeViewContainer()->statusBar();
1474 statusBar->setMessage(job->errorString(), DolphinStatusBar::Error);
1475 } else {
1476 KIO::FileUndoManager::UiInterface::jobError(job);
1477 }
1478 }
1479
1480 #include "dolphinmainwindow.moc"