]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinmainwindow.cpp
Show places selector of URL navigator only when required
[dolphin.git] / src / dolphinmainwindow.cpp
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz <peter.penz19@gmail.com> *
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
24 #include <config-nepomuk.h>
25
26 #include "dolphinapplication.h"
27 #include "dolphindockwidget.h"
28 #include "dolphincontextmenu.h"
29 #include "dolphinnewfilemenu.h"
30 #include "dolphinviewcontainer.h"
31 #include "mainwindowadaptor.h"
32 #ifdef HAVE_NEPOMUK
33 #include "panels/search/searchpanel.h"
34 #include <Nepomuk/ResourceManager>
35 #endif
36 #include "panels/folders/folderspanel.h"
37 #include "panels/places/placespanel.h"
38 #include "panels/information/informationpanel.h"
39 #include "search/dolphinsearchinformation.h"
40 #include "settings/dolphinsettings.h"
41 #include "settings/dolphinsettingsdialog.h"
42 #include "statusbar/dolphinstatusbar.h"
43 #include "views/dolphinviewactionhandler.h"
44 #include "views/dolphinremoteencoding.h"
45 #include "views/draganddrophelper.h"
46 #include "views/viewproperties.h"
47
48 #ifndef Q_OS_WIN
49 #include "panels/terminal/terminalpanel.h"
50 #endif
51
52 #include "dolphin_generalsettings.h"
53 #include "dolphin_iconsmodesettings.h"
54 #include "dolphin_searchsettings.h"
55
56 #include <KAction>
57 #include <KActionCollection>
58 #include <KActionMenu>
59 #include <KConfig>
60 #include <KDesktopFile>
61 #include <kdeversion.h>
62 #include <kdualaction.h>
63 #include <KFileDialog>
64 #include <KFilePlacesModel>
65 #include <KGlobal>
66 #include <KLineEdit>
67 #include <ktoolbar.h>
68 #include <KIcon>
69 #include <KIconLoader>
70 #include <KIO/NetAccess>
71 #include <KInputDialog>
72 #include <KLocale>
73 #include <KProtocolManager>
74 #include <KMenu>
75 #include <KMenuBar>
76 #include <KMessageBox>
77 #include <KFileItemListProperties>
78 #include <konqmimedata.h>
79 #include <KProtocolInfo>
80 #include <KRun>
81 #include <KShell>
82 #include <KStandardDirs>
83 #include <kstatusbar.h>
84 #include <KStandardAction>
85 #include <ktabbar.h>
86 #include <KToggleAction>
87 #include <KUrlNavigator>
88 #include <KUrl>
89 #include <KUrlComboBox>
90 #include <KToolInvocation>
91
92 #include <QDBusMessage>
93 #include <QKeyEvent>
94 #include <QClipboard>
95 #include <QSplitter>
96 #include <kacceleratormanager.h>
97
98 /*
99 * Remembers the tab configuration if a tab has been closed.
100 * Each closed tab can be restored by the menu
101 * "Go -> Recently Closed Tabs".
102 */
103 struct ClosedTab
104 {
105 KUrl primaryUrl;
106 KUrl secondaryUrl;
107 bool isSplit;
108 };
109 Q_DECLARE_METATYPE(ClosedTab)
110
111 DolphinMainWindow::DolphinMainWindow(int id) :
112 KXmlGuiWindow(0),
113 m_newFileMenu(0),
114 m_showMenuBar(0),
115 m_tabBar(0),
116 m_activeViewContainer(0),
117 m_centralWidgetLayout(0),
118 m_id(id),
119 m_tabIndex(0),
120 m_viewTab(),
121 m_actionHandler(0),
122 m_remoteEncoding(0),
123 m_settingsDialog(0),
124 m_lastHandleUrlStatJob(0),
125 m_searchDockIsTemporaryVisible(false)
126 {
127 // Workaround for a X11-issue in combination with KModifierInfo
128 // (see DolphinContextMenu::initializeModifierKeyInfo() for
129 // more information):
130 DolphinContextMenu::initializeModifierKeyInfo();
131
132 setObjectName("Dolphin#");
133
134 m_viewTab.append(ViewTab());
135
136 new MainWindowAdaptor(this);
137 QDBusConnection::sessionBus().registerObject(QString("/dolphin/MainWindow%1").arg(m_id), this);
138
139 KIO::FileUndoManager* undoManager = KIO::FileUndoManager::self();
140 undoManager->setUiInterface(new UndoUiInterface());
141
142 connect(undoManager, SIGNAL(undoAvailable(bool)),
143 this, SLOT(slotUndoAvailable(bool)));
144 connect(undoManager, SIGNAL(undoTextChanged(const QString&)),
145 this, SLOT(slotUndoTextChanged(const QString&)));
146 connect(undoManager, SIGNAL(jobRecordingStarted(CommandType)),
147 this, SLOT(clearStatusBar()));
148 connect(undoManager, SIGNAL(jobRecordingFinished(CommandType)),
149 this, SLOT(showCommand(CommandType)));
150 connect(DolphinSettings::instance().placesModel(), SIGNAL(errorMessage(const QString&)),
151 this, SLOT(showErrorMessage(const QString&)));
152 connect(&DragAndDropHelper::instance(), SIGNAL(errorMessage(const QString&)),
153 this, SLOT(showErrorMessage(const QString&)));
154 }
155
156 DolphinMainWindow::~DolphinMainWindow()
157 {
158 DolphinApplication::app()->removeMainWindow(this);
159 }
160
161 void DolphinMainWindow::openDirectories(const QList<KUrl>& dirs)
162 {
163 if (dirs.isEmpty()) {
164 return;
165 }
166
167 if (dirs.count() == 1) {
168 m_activeViewContainer->setUrl(dirs.first());
169 return;
170 }
171
172 const int oldOpenTabsCount = m_viewTab.count();
173
174 const GeneralSettings* generalSettings = DolphinSettings::instance().generalSettings();
175 const bool hasSplitView = generalSettings->splitView();
176
177 // Open each directory inside a new tab. If the "split view" option has been enabled,
178 // always show two directories within one tab.
179 QList<KUrl>::const_iterator it = dirs.begin();
180 while (it != dirs.end()) {
181 openNewTab(*it);
182 ++it;
183
184 if (hasSplitView && (it != dirs.end())) {
185 const int tabIndex = m_viewTab.count() - 1;
186 m_viewTab[tabIndex].secondaryView->setUrl(*it);
187 ++it;
188 }
189 }
190
191 // remove the previously opened tabs
192 for (int i = 0; i < oldOpenTabsCount; ++i) {
193 closeTab(0);
194 }
195 }
196
197 void DolphinMainWindow::openFiles(const QList<KUrl>& files)
198 {
199 if (files.isEmpty()) {
200 return;
201 }
202
203 // Get all distinct directories from 'files' and open a tab
204 // for each directory. If the "split view" option is enabled, two
205 // directories are shown inside one tab (see openDirectories()).
206 QList<KUrl> dirs;
207 foreach (const KUrl& url, files) {
208 const KUrl dir(url.directory());
209 if (!dirs.contains(dir)) {
210 dirs.append(dir);
211 }
212 }
213
214 openDirectories(dirs);
215
216 // Select the files. Although the files can be split between several
217 // tabs, there is no need to split 'files' accordingly, as
218 // the DolphinView will just ignore invalid selections.
219 const int tabCount = m_viewTab.count();
220 for (int i = 0; i < tabCount; ++i) {
221 m_viewTab[i].primaryView->view()->markUrlsAsSelected(files);
222 if (m_viewTab[i].secondaryView) {
223 m_viewTab[i].secondaryView->view()->markUrlsAsSelected(files);
224 }
225 }
226 }
227
228 void DolphinMainWindow::showCommand(CommandType command)
229 {
230 DolphinStatusBar* statusBar = m_activeViewContainer->statusBar();
231 switch (command) {
232 case KIO::FileUndoManager::Copy:
233 statusBar->setMessage(i18nc("@info:status", "Successfully copied."),
234 DolphinStatusBar::OperationCompleted);
235 break;
236 case KIO::FileUndoManager::Move:
237 statusBar->setMessage(i18nc("@info:status", "Successfully moved."),
238 DolphinStatusBar::OperationCompleted);
239 break;
240 case KIO::FileUndoManager::Link:
241 statusBar->setMessage(i18nc("@info:status", "Successfully linked."),
242 DolphinStatusBar::OperationCompleted);
243 break;
244 case KIO::FileUndoManager::Trash:
245 statusBar->setMessage(i18nc("@info:status", "Successfully moved to trash."),
246 DolphinStatusBar::OperationCompleted);
247 break;
248 case KIO::FileUndoManager::Rename:
249 statusBar->setMessage(i18nc("@info:status", "Successfully renamed."),
250 DolphinStatusBar::OperationCompleted);
251 break;
252
253 case KIO::FileUndoManager::Mkdir:
254 statusBar->setMessage(i18nc("@info:status", "Created folder."),
255 DolphinStatusBar::OperationCompleted);
256 break;
257
258 default:
259 break;
260 }
261 }
262
263 void DolphinMainWindow::refreshViews()
264 {
265 Q_ASSERT(m_viewTab[m_tabIndex].primaryView);
266
267 // remember the current active view, as because of
268 // the refreshing the active view might change to
269 // the secondary view
270 DolphinViewContainer* activeViewContainer = m_activeViewContainer;
271
272 const int tabCount = m_viewTab.count();
273 for (int i = 0; i < tabCount; ++i) {
274 m_viewTab[i].primaryView->refresh();
275 if (m_viewTab[i].secondaryView) {
276 m_viewTab[i].secondaryView->refresh();
277 }
278 }
279
280 setActiveViewContainer(activeViewContainer);
281
282 const GeneralSettings* generalSettings = DolphinSettings::instance().generalSettings();
283 if (generalSettings->modifiedStartupSettings()) {
284 // The startup settings have been changed by the user (see bug #254947).
285 // Synchronize the split-view setting with the active view:
286 const bool splitView = generalSettings->splitView();
287 const ViewTab& activeTab = m_viewTab[m_tabIndex];
288 const bool toggle = ( splitView && !activeTab.secondaryView)
289 || (!splitView && activeTab.secondaryView);
290 if (toggle) {
291 toggleSplitView();
292 }
293 }
294 }
295
296 void DolphinMainWindow::pasteIntoFolder()
297 {
298 m_activeViewContainer->view()->pasteIntoFolder();
299 }
300
301 void DolphinMainWindow::changeUrl(const KUrl& url)
302 {
303 if (!KProtocolManager::supportsListing(url)) {
304 // The URL navigator only checks for validity, not
305 // if the URL can be listed. An error message is
306 // shown due to DolphinViewContainer::restoreView().
307 return;
308 }
309
310 DolphinViewContainer* view = activeViewContainer();
311 if (view) {
312 view->setUrl(url);
313 updateEditActions();
314 updateViewActions();
315 updateGoActions();
316 setUrlAsCaption(url);
317 if (m_viewTab.count() > 1) {
318 m_tabBar->setTabText(m_tabIndex, squeezedText(tabName(m_activeViewContainer->url())));
319 }
320 const QString iconName = KMimeType::iconNameForUrl(url);
321 m_tabBar->setTabIcon(m_tabIndex, KIcon(iconName));
322 emit urlChanged(url);
323 }
324 }
325
326 void DolphinMainWindow::slotEditableStateChanged(bool editable)
327 {
328 KToggleAction* editableLocationAction =
329 static_cast<KToggleAction*>(actionCollection()->action("editable_location"));
330 editableLocationAction->setChecked(editable);
331 }
332
333 void DolphinMainWindow::slotSelectionChanged(const KFileItemList& selection)
334 {
335 updateEditActions();
336
337 Q_ASSERT(m_viewTab[m_tabIndex].primaryView);
338 int selectedUrlsCount = m_viewTab[m_tabIndex].primaryView->view()->selectedItemsCount();
339 if (m_viewTab[m_tabIndex].secondaryView) {
340 selectedUrlsCount += m_viewTab[m_tabIndex].secondaryView->view()->selectedItemsCount();
341 }
342
343 QAction* compareFilesAction = actionCollection()->action("compare_files");
344 if (selectedUrlsCount == 2) {
345 compareFilesAction->setEnabled(isKompareInstalled());
346 } else {
347 compareFilesAction->setEnabled(false);
348 }
349
350 emit selectionChanged(selection);
351 }
352
353 void DolphinMainWindow::slotRequestItemInfo(const KFileItem& item)
354 {
355 emit requestItemInfo(item);
356 }
357
358 void DolphinMainWindow::updateHistory()
359 {
360 const KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator();
361 const int index = urlNavigator->historyIndex();
362
363 QAction* backAction = actionCollection()->action("go_back");
364 backAction->setToolTip(i18nc("@info", "Go back"));
365 if (backAction) {
366 backAction->setEnabled(index < urlNavigator->historySize() - 1);
367 }
368
369 QAction* forwardAction = actionCollection()->action("go_forward");
370 forwardAction->setToolTip(i18nc("@info", "Go forward"));
371 if (forwardAction) {
372 forwardAction->setEnabled(index > 0);
373 }
374 }
375
376 void DolphinMainWindow::updateFilterBarAction(bool show)
377 {
378 QAction* showFilterBarAction = actionCollection()->action("show_filter_bar");
379 showFilterBarAction->setChecked(show);
380 }
381
382 void DolphinMainWindow::openNewMainWindow()
383 {
384 DolphinApplication::app()->createMainWindow()->show();
385 }
386
387 void DolphinMainWindow::openNewTab()
388 {
389 const bool isUrlEditable = m_activeViewContainer->urlNavigator()->isUrlEditable();
390
391 openNewTab(m_activeViewContainer->url());
392 m_tabBar->setCurrentIndex(m_viewTab.count() - 1);
393
394 // The URL navigator of the new tab should have the same editable state
395 // as the current tab
396 KUrlNavigator* navigator = m_activeViewContainer->urlNavigator();
397 navigator->setUrlEditable(isUrlEditable);
398
399 if (isUrlEditable) {
400 // If a new tab is opened and the URL is editable, assure that
401 // the user can edit the URL without manually setting the focus
402 navigator->setFocus();
403 }
404 }
405
406 void DolphinMainWindow::openNewTab(const KUrl& url)
407 {
408 QWidget* focusWidget = QApplication::focusWidget();
409
410 if (m_viewTab.count() == 1) {
411 // Only one view is open currently and hence no tab is shown at
412 // all. Before creating a tab for 'url', provide a tab for the current URL.
413 const KUrl currentUrl = m_activeViewContainer->url();
414 m_tabBar->addTab(KIcon(KMimeType::iconNameForUrl(currentUrl)),
415 squeezedText(tabName(currentUrl)));
416 m_tabBar->blockSignals(false);
417 }
418
419 m_tabBar->addTab(KIcon(KMimeType::iconNameForUrl(url)),
420 squeezedText(tabName(url)));
421
422 ViewTab viewTab;
423 viewTab.splitter = new QSplitter(this);
424 viewTab.splitter->setChildrenCollapsible(false);
425 viewTab.primaryView = createViewContainer(url, viewTab.splitter);
426 viewTab.primaryView->setActive(false);
427 connectViewSignals(viewTab.primaryView);
428
429 m_viewTab.append(viewTab);
430
431 actionCollection()->action("close_tab")->setEnabled(true);
432
433 // provide a split view, if the startup settings are set this way
434 const GeneralSettings* generalSettings = DolphinSettings::instance().generalSettings();
435 if (generalSettings->splitView()) {
436 const int tabIndex = m_viewTab.count() - 1;
437 createSecondaryView(tabIndex);
438 m_viewTab[tabIndex].secondaryView->setActive(true);
439 m_viewTab[tabIndex].isPrimaryViewActive = false;
440 }
441
442 if (focusWidget) {
443 // The DolphinViewContainer grabbed the keyboard focus. As the tab is opened
444 // in background, assure that the previous focused widget gets the focus back.
445 focusWidget->setFocus();
446 }
447 }
448
449 void DolphinMainWindow::activateNextTab()
450 {
451 if ((m_viewTab.count() == 1) || (m_tabBar->count() < 2)) {
452 return;
453 }
454
455 const int tabIndex = (m_tabBar->currentIndex() + 1) % m_tabBar->count();
456 m_tabBar->setCurrentIndex(tabIndex);
457 }
458
459 void DolphinMainWindow::activatePrevTab()
460 {
461 if ((m_viewTab.count() == 1) || (m_tabBar->count() < 2)) {
462 return;
463 }
464
465 int tabIndex = m_tabBar->currentIndex() - 1;
466 if (tabIndex == -1) {
467 tabIndex = m_tabBar->count() - 1;
468 }
469 m_tabBar->setCurrentIndex(tabIndex);
470 }
471
472 void DolphinMainWindow::openInNewTab()
473 {
474 const KFileItemList list = m_activeViewContainer->view()->selectedItems();
475 if (list.isEmpty()) {
476 openNewTab(m_activeViewContainer->url());
477 } else if ((list.count() == 1) && list[0].isDir()) {
478 openNewTab(list[0].url());
479 }
480 }
481
482 void DolphinMainWindow::openInNewWindow()
483 {
484 KUrl newWindowUrl;
485
486 const KFileItemList list = m_activeViewContainer->view()->selectedItems();
487 if (list.isEmpty()) {
488 newWindowUrl = m_activeViewContainer->url();
489 } else if ((list.count() == 1) && list[0].isDir()) {
490 newWindowUrl = list[0].url();
491 }
492
493 if (!newWindowUrl.isEmpty()) {
494 DolphinMainWindow* window = DolphinApplication::app()->createMainWindow();
495 window->changeUrl(newWindowUrl);
496 window->show();
497 }
498 }
499
500 void DolphinMainWindow::toggleActiveView()
501 {
502 if (!m_viewTab[m_tabIndex].secondaryView) {
503 // only one view is available
504 return;
505 }
506
507 Q_ASSERT(m_activeViewContainer);
508 Q_ASSERT(m_viewTab[m_tabIndex].primaryView);
509
510 DolphinViewContainer* left = m_viewTab[m_tabIndex].primaryView;
511 DolphinViewContainer* right = m_viewTab[m_tabIndex].secondaryView;
512 setActiveViewContainer(m_activeViewContainer == right ? left : right);
513 }
514
515 void DolphinMainWindow::showEvent(QShowEvent* event)
516 {
517 KXmlGuiWindow::showEvent(event);
518 if (!event->spontaneous()) {
519 m_activeViewContainer->view()->setFocus();
520 }
521 }
522
523 void DolphinMainWindow::closeEvent(QCloseEvent* event)
524 {
525 DolphinSettings& settings = DolphinSettings::instance();
526 GeneralSettings* generalSettings = settings.generalSettings();
527
528 // Find out if Dolphin is closed directly by the user or
529 // by the session manager because the session is closed
530 bool closedByUser = true;
531 DolphinApplication *application = qobject_cast<DolphinApplication*>(qApp);
532 if (application && application->sessionSaving()) {
533 closedByUser = false;
534 }
535
536 if ((m_viewTab.count() > 1) && generalSettings->confirmClosingMultipleTabs() && closedByUser) {
537 // Ask the user if he really wants to quit and close all tabs.
538 // Open a confirmation dialog with 3 buttons:
539 // KDialog::Yes -> Quit
540 // KDialog::No -> Close only the current tab
541 // KDialog::Cancel -> do nothing
542 KDialog *dialog = new KDialog(this, Qt::Dialog);
543 dialog->setCaption(i18nc("@title:window", "Confirmation"));
544 dialog->setButtons(KDialog::Yes | KDialog::No | KDialog::Cancel);
545 dialog->setModal(true);
546 dialog->setButtonGuiItem(KDialog::Yes, KStandardGuiItem::quit());
547 dialog->setButtonGuiItem(KDialog::No, KGuiItem(i18n("C&lose Current Tab"), KIcon("tab-close")));
548 dialog->setButtonGuiItem(KDialog::Cancel, KStandardGuiItem::cancel());
549 dialog->setDefaultButton(KDialog::Yes);
550
551 bool doNotAskAgainCheckboxResult = false;
552
553 const int result = KMessageBox::createKMessageBox(dialog,
554 QMessageBox::Warning,
555 i18n("You have multiple tabs open in this window, are you sure you want to quit?"),
556 QStringList(),
557 i18n("Do not ask again"),
558 &doNotAskAgainCheckboxResult,
559 KMessageBox::Notify);
560
561 if (doNotAskAgainCheckboxResult) {
562 generalSettings->setConfirmClosingMultipleTabs(false);
563 }
564
565 switch (result) {
566 case KDialog::Yes:
567 // Quit
568 break;
569 case KDialog::No:
570 // Close only the current tab
571 closeTab();
572 default:
573 event->ignore();
574 return;
575 }
576 }
577
578 generalSettings->setFirstRun(false);
579
580 settings.save();
581
582 if (m_searchDockIsTemporaryVisible) {
583 QDockWidget* searchDock = findChild<QDockWidget*>("searchDock");
584 if (searchDock) {
585 searchDock->hide();
586 }
587 m_searchDockIsTemporaryVisible = false;
588 }
589
590 KXmlGuiWindow::closeEvent(event);
591 }
592
593 void DolphinMainWindow::saveProperties(KConfigGroup& group)
594 {
595 const int tabCount = m_viewTab.count();
596 group.writeEntry("Tab Count", tabCount);
597 group.writeEntry("Active Tab Index", m_tabBar->currentIndex());
598
599 for (int i = 0; i < tabCount; ++i) {
600 const DolphinViewContainer* cont = m_viewTab[i].primaryView;
601 group.writeEntry(tabProperty("Primary URL", i), cont->url().url());
602 group.writeEntry(tabProperty("Primary Editable", i),
603 cont->urlNavigator()->isUrlEditable());
604
605 cont = m_viewTab[i].secondaryView;
606 if (cont) {
607 group.writeEntry(tabProperty("Secondary URL", i), cont->url().url());
608 group.writeEntry(tabProperty("Secondary Editable", i),
609 cont->urlNavigator()->isUrlEditable());
610 }
611 }
612 }
613
614 void DolphinMainWindow::readProperties(const KConfigGroup& group)
615 {
616 const int tabCount = group.readEntry("Tab Count", 1);
617 for (int i = 0; i < tabCount; ++i) {
618 DolphinViewContainer* cont = m_viewTab[i].primaryView;
619
620 cont->setUrl(group.readEntry(tabProperty("Primary URL", i)));
621 const bool editable = group.readEntry(tabProperty("Primary Editable", i), false);
622 cont->urlNavigator()->setUrlEditable(editable);
623
624 cont = m_viewTab[i].secondaryView;
625 const QString secondaryUrl = group.readEntry(tabProperty("Secondary URL", i));
626 if (!secondaryUrl.isEmpty()) {
627 if (!cont) {
628 // a secondary view should be shown, but no one is available
629 // currently -> create a new view
630 toggleSplitView();
631 cont = m_viewTab[i].secondaryView;
632 Q_ASSERT(cont);
633 }
634
635 cont->setUrl(secondaryUrl);
636 const bool editable = group.readEntry(tabProperty("Secondary Editable", i), false);
637 cont->urlNavigator()->setUrlEditable(editable);
638 } else if (cont) {
639 // no secondary view should be shown, but the default setting shows
640 // one already -> close the view
641 toggleSplitView();
642 }
643
644 // openNewTab() needs to be called only tabCount - 1 times
645 if (i != tabCount - 1) {
646 openNewTab();
647 }
648 }
649
650 const int index = group.readEntry("Active Tab Index", 0);
651 m_tabBar->setCurrentIndex(index);
652 }
653
654 void DolphinMainWindow::updateNewMenu()
655 {
656 m_newFileMenu->setViewShowsHiddenFiles(activeViewContainer()->view()->showHiddenFiles());
657 m_newFileMenu->checkUpToDate();
658 m_newFileMenu->setPopupFiles(activeViewContainer()->url());
659 }
660
661 void DolphinMainWindow::createDirectory()
662 {
663 m_newFileMenu->setViewShowsHiddenFiles(activeViewContainer()->view()->showHiddenFiles());
664 m_newFileMenu->setPopupFiles(activeViewContainer()->url());
665 m_newFileMenu->createDirectory();
666 }
667
668 void DolphinMainWindow::quit()
669 {
670 close();
671 }
672
673 void DolphinMainWindow::showErrorMessage(const QString& message)
674 {
675 if (!message.isEmpty()) {
676 DolphinStatusBar* statusBar = m_activeViewContainer->statusBar();
677 statusBar->setMessage(message, DolphinStatusBar::Error);
678 }
679 }
680
681 void DolphinMainWindow::slotUndoAvailable(bool available)
682 {
683 QAction* undoAction = actionCollection()->action(KStandardAction::name(KStandardAction::Undo));
684 if (undoAction) {
685 undoAction->setEnabled(available);
686 }
687 }
688
689 void DolphinMainWindow::restoreClosedTab(QAction* action)
690 {
691 if (action->data().toBool()) {
692 // clear all actions except the "Empty Recently Closed Tabs"
693 // action and the separator
694 QList<QAction*> actions = m_recentTabsMenu->menu()->actions();
695 const int count = actions.size();
696 for (int i = 2; i < count; ++i) {
697 m_recentTabsMenu->menu()->removeAction(actions.at(i));
698 }
699 } else {
700 const ClosedTab closedTab = action->data().value<ClosedTab>();
701 openNewTab(closedTab.primaryUrl);
702 m_tabBar->setCurrentIndex(m_viewTab.count() - 1);
703
704 if (closedTab.isSplit) {
705 // create secondary view
706 toggleSplitView();
707 m_viewTab[m_tabIndex].secondaryView->setUrl(closedTab.secondaryUrl);
708 }
709
710 m_recentTabsMenu->removeAction(action);
711 }
712
713 if (m_recentTabsMenu->menu()->actions().count() == 2) {
714 m_recentTabsMenu->setEnabled(false);
715 }
716 }
717
718 void DolphinMainWindow::slotUndoTextChanged(const QString& text)
719 {
720 QAction* undoAction = actionCollection()->action(KStandardAction::name(KStandardAction::Undo));
721 if (undoAction) {
722 undoAction->setText(text);
723 }
724 }
725
726 void DolphinMainWindow::undo()
727 {
728 clearStatusBar();
729 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
730 KIO::FileUndoManager::self()->undo();
731 }
732
733 void DolphinMainWindow::cut()
734 {
735 m_activeViewContainer->view()->cutSelectedItems();
736 }
737
738 void DolphinMainWindow::copy()
739 {
740 m_activeViewContainer->view()->copySelectedItems();
741 }
742
743 void DolphinMainWindow::paste()
744 {
745 m_activeViewContainer->view()->paste();
746 }
747
748 void DolphinMainWindow::find()
749 {
750 m_activeViewContainer->setSearchModeEnabled(true);
751 }
752
753 void DolphinMainWindow::updatePasteAction()
754 {
755 QAction* pasteAction = actionCollection()->action(KStandardAction::name(KStandardAction::Paste));
756 QPair<bool, QString> pasteInfo = m_activeViewContainer->view()->pasteInfo();
757 pasteAction->setEnabled(pasteInfo.first);
758 pasteAction->setText(pasteInfo.second);
759 }
760
761 void DolphinMainWindow::selectAll()
762 {
763 clearStatusBar();
764
765 // if the URL navigator is editable and focused, select the whole
766 // URL instead of all items of the view
767
768 KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator();
769 QLineEdit* lineEdit = urlNavigator->editor()->lineEdit(); // krazy:exclude=qclasses
770 const bool selectUrl = urlNavigator->isUrlEditable() &&
771 lineEdit->hasFocus();
772 if (selectUrl) {
773 lineEdit->selectAll();
774 } else {
775 m_activeViewContainer->view()->selectAll();
776 }
777 }
778
779 void DolphinMainWindow::invertSelection()
780 {
781 clearStatusBar();
782 m_activeViewContainer->view()->invertSelection();
783 }
784
785 void DolphinMainWindow::toggleSplitView()
786 {
787 if (!m_viewTab[m_tabIndex].secondaryView) {
788 createSecondaryView(m_tabIndex);
789 setActiveViewContainer(m_viewTab[m_tabIndex].secondaryView);
790 } else if (m_activeViewContainer == m_viewTab[m_tabIndex].secondaryView) {
791 // remove secondary view
792 m_viewTab[m_tabIndex].secondaryView->close();
793 m_viewTab[m_tabIndex].secondaryView->deleteLater();
794 m_viewTab[m_tabIndex].secondaryView = 0;
795
796 setActiveViewContainer(m_viewTab[m_tabIndex].primaryView);
797 } else {
798 // The primary view is active and should be closed. Hence from a users point of view
799 // the content of the secondary view should be moved to the primary view.
800 // From an implementation point of view it is more efficient to close
801 // the primary view and exchange the internal pointers afterwards.
802
803 m_viewTab[m_tabIndex].primaryView->close();
804 m_viewTab[m_tabIndex].primaryView->deleteLater();
805 m_viewTab[m_tabIndex].primaryView = m_viewTab[m_tabIndex].secondaryView;
806 m_viewTab[m_tabIndex].secondaryView = 0;
807
808 setActiveViewContainer(m_viewTab[m_tabIndex].primaryView);
809 }
810
811 updateViewActions();
812 }
813
814 void DolphinMainWindow::reloadView()
815 {
816 clearStatusBar();
817 m_activeViewContainer->view()->reload();
818 }
819
820 void DolphinMainWindow::stopLoading()
821 {
822 m_activeViewContainer->view()->stopLoading();
823 }
824
825 void DolphinMainWindow::enableStopAction()
826 {
827 actionCollection()->action("stop")->setEnabled(true);
828 }
829
830 void DolphinMainWindow::disableStopAction()
831 {
832 actionCollection()->action("stop")->setEnabled(false);
833 }
834
835 void DolphinMainWindow::showFilterBar()
836 {
837 m_activeViewContainer->setFilterBarVisible(true);
838 }
839
840 void DolphinMainWindow::toggleEditLocation()
841 {
842 clearStatusBar();
843
844 QAction* action = actionCollection()->action("editable_location");
845 KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator();
846 urlNavigator->setUrlEditable(action->isChecked());
847 }
848
849 void DolphinMainWindow::replaceLocation()
850 {
851 KUrlNavigator* navigator = m_activeViewContainer->urlNavigator();
852 navigator->setUrlEditable(true);
853 navigator->setFocus();
854
855 // select the whole text of the combo box editor
856 QLineEdit* lineEdit = navigator->editor()->lineEdit(); // krazy:exclude=qclasses
857 lineEdit->selectAll();
858 }
859
860 void DolphinMainWindow::togglePanelLockState()
861 {
862 GeneralSettings* generalSettings = DolphinSettings::instance().generalSettings();
863
864 const bool newLockState = !generalSettings->lockPanels();
865 foreach (QObject* child, children()) {
866 DolphinDockWidget* dock = qobject_cast<DolphinDockWidget*>(child);
867 if (dock) {
868 dock->setLocked(newLockState);
869 }
870 }
871
872 generalSettings->setLockPanels(newLockState);
873 }
874
875 void DolphinMainWindow::slotPlacesPanelVisibilityChanged(bool visible)
876 {
877 const int tabCount = m_viewTab.count();
878 for (int i = 0; i < tabCount; ++i) {
879 ViewTab& tab = m_viewTab[i];
880 Q_ASSERT(tab.primaryView);
881 tab.primaryView->urlNavigator()->setPlacesSelectorVisible(!visible);
882 if (tab.secondaryView) {
883 tab.secondaryView->urlNavigator()->setPlacesSelectorVisible(!visible);
884 }
885 }
886 }
887
888 void DolphinMainWindow::goBack()
889 {
890 clearStatusBar();
891
892 KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator();
893 urlNavigator->goBack();
894
895 if (urlNavigator->locationState().isEmpty()) {
896 // An empty location state indicates a redirection URL,
897 // which must be skipped too
898 urlNavigator->goBack();
899 }
900 }
901
902 void DolphinMainWindow::goForward()
903 {
904 clearStatusBar();
905 m_activeViewContainer->urlNavigator()->goForward();
906 }
907
908 void DolphinMainWindow::goUp()
909 {
910 clearStatusBar();
911 m_activeViewContainer->urlNavigator()->goUp();
912 }
913
914 void DolphinMainWindow::goBack(Qt::MouseButtons buttons)
915 {
916 // The default case (left button pressed) is handled in goBack().
917 if (buttons == Qt::MidButton) {
918 KUrlNavigator* urlNavigator = activeViewContainer()->urlNavigator();
919 const int index = urlNavigator->historyIndex() + 1;
920 openNewTab(urlNavigator->locationUrl(index));
921 }
922 }
923
924 void DolphinMainWindow::goForward(Qt::MouseButtons buttons)
925 {
926 // The default case (left button pressed) is handled in goForward().
927 if (buttons == Qt::MidButton) {
928 KUrlNavigator* urlNavigator = activeViewContainer()->urlNavigator();
929 const int index = urlNavigator->historyIndex() - 1;
930 openNewTab(urlNavigator->locationUrl(index));
931 }
932 }
933
934 void DolphinMainWindow::goUp(Qt::MouseButtons buttons)
935 {
936 // The default case (left button pressed) is handled in goUp().
937 if (buttons == Qt::MidButton) {
938 openNewTab(activeViewContainer()->url().upUrl());
939 }
940 }
941
942 void DolphinMainWindow::goHome()
943 {
944 clearStatusBar();
945 m_activeViewContainer->urlNavigator()->goHome();
946 }
947
948 void DolphinMainWindow::compareFiles()
949 {
950 // The method is only invoked if exactly 2 files have
951 // been selected. The selected files may be:
952 // - both in the primary view
953 // - both in the secondary view
954 // - one in the primary view and the other in the secondary
955 // view
956 Q_ASSERT(m_viewTab[m_tabIndex].primaryView);
957
958 KUrl urlA;
959 KUrl urlB;
960
961 KFileItemList items = m_viewTab[m_tabIndex].primaryView->view()->selectedItems();
962
963 switch (items.count()) {
964 case 0: {
965 Q_ASSERT(m_viewTab[m_tabIndex].secondaryView);
966 items = m_viewTab[m_tabIndex].secondaryView->view()->selectedItems();
967 Q_ASSERT(items.count() == 2);
968 urlA = items[0].url();
969 urlB = items[1].url();
970 break;
971 }
972
973 case 1: {
974 urlA = items[0].url();
975 Q_ASSERT(m_viewTab[m_tabIndex].secondaryView);
976 items = m_viewTab[m_tabIndex].secondaryView->view()->selectedItems();
977 Q_ASSERT(items.count() == 1);
978 urlB = items[0].url();
979 break;
980 }
981
982 case 2: {
983 urlA = items[0].url();
984 urlB = items[1].url();
985 break;
986 }
987
988 default: {
989 // may not happen: compareFiles may only get invoked if 2
990 // files are selected
991 Q_ASSERT(false);
992 }
993 }
994
995 QString command("kompare -c \"");
996 command.append(urlA.pathOrUrl());
997 command.append("\" \"");
998 command.append(urlB.pathOrUrl());
999 command.append('\"');
1000 KRun::runCommand(command, "Kompare", "kompare", this);
1001 }
1002
1003 void DolphinMainWindow::toggleShowMenuBar()
1004 {
1005 const bool visible = menuBar()->isVisible();
1006 menuBar()->setVisible(!visible);
1007 }
1008
1009 void DolphinMainWindow::openTerminal()
1010 {
1011 QString dir(QDir::homePath());
1012
1013 // If the given directory is not local, it can still be the URL of an
1014 // ioslave using UDS_LOCAL_PATH which to be converted first.
1015 KUrl url = KIO::NetAccess::mostLocalUrl(m_activeViewContainer->url(), this);
1016
1017 //If the URL is local after the above conversion, set the directory.
1018 if (url.isLocalFile()) {
1019 dir = url.toLocalFile();
1020 }
1021
1022 KToolInvocation::invokeTerminal(QString(), dir);
1023 }
1024
1025 void DolphinMainWindow::editSettings()
1026 {
1027 if (!m_settingsDialog) {
1028 const KUrl url = activeViewContainer()->url();
1029 m_settingsDialog = new DolphinSettingsDialog(url, this);
1030 m_settingsDialog->setAttribute(Qt::WA_DeleteOnClose);
1031 m_settingsDialog->show();
1032 } else {
1033 m_settingsDialog->raise();
1034 }
1035 }
1036
1037 void DolphinMainWindow::setActiveTab(int index)
1038 {
1039 Q_ASSERT(index >= 0);
1040 Q_ASSERT(index < m_viewTab.count());
1041 if (index == m_tabIndex) {
1042 return;
1043 }
1044
1045 // hide current tab content
1046 ViewTab& hiddenTab = m_viewTab[m_tabIndex];
1047 hiddenTab.isPrimaryViewActive = hiddenTab.primaryView->isActive();
1048 hiddenTab.primaryView->setActive(false);
1049 if (hiddenTab.secondaryView) {
1050 hiddenTab.secondaryView->setActive(false);
1051 }
1052 QSplitter* splitter = m_viewTab[m_tabIndex].splitter;
1053 splitter->hide();
1054 m_centralWidgetLayout->removeWidget(splitter);
1055
1056 // show active tab content
1057 m_tabIndex = index;
1058
1059 ViewTab& viewTab = m_viewTab[index];
1060 m_centralWidgetLayout->addWidget(viewTab.splitter, 1);
1061 viewTab.primaryView->show();
1062 if (viewTab.secondaryView) {
1063 viewTab.secondaryView->show();
1064 }
1065 viewTab.splitter->show();
1066
1067 setActiveViewContainer(viewTab.isPrimaryViewActive ? viewTab.primaryView :
1068 viewTab.secondaryView);
1069 }
1070
1071 void DolphinMainWindow::closeTab()
1072 {
1073 closeTab(m_tabBar->currentIndex());
1074 }
1075
1076 void DolphinMainWindow::closeTab(int index)
1077 {
1078 Q_ASSERT(index >= 0);
1079 Q_ASSERT(index < m_viewTab.count());
1080 if (m_viewTab.count() == 1) {
1081 // the last tab may never get closed
1082 return;
1083 }
1084
1085 if (index == m_tabIndex) {
1086 // The tab that should be closed is the active tab. Activate the
1087 // previous tab before closing the tab.
1088 m_tabBar->setCurrentIndex((index > 0) ? index - 1 : 1);
1089 }
1090 rememberClosedTab(index);
1091
1092 // delete tab
1093 m_viewTab[index].primaryView->deleteLater();
1094 if (m_viewTab[index].secondaryView) {
1095 m_viewTab[index].secondaryView->deleteLater();
1096 }
1097 m_viewTab[index].splitter->deleteLater();
1098 m_viewTab.erase(m_viewTab.begin() + index);
1099
1100 m_tabBar->blockSignals(true);
1101 m_tabBar->removeTab(index);
1102
1103 if (m_tabIndex > index) {
1104 m_tabIndex--;
1105 Q_ASSERT(m_tabIndex >= 0);
1106 }
1107
1108 // if only one tab is left, also remove the tab entry so that
1109 // closing the last tab is not possible
1110 if (m_viewTab.count() == 1) {
1111 m_tabBar->removeTab(0);
1112 actionCollection()->action("close_tab")->setEnabled(false);
1113 } else {
1114 m_tabBar->blockSignals(false);
1115 }
1116 }
1117
1118 void DolphinMainWindow::openTabContextMenu(int index, const QPoint& pos)
1119 {
1120 KMenu menu(this);
1121
1122 QAction* newTabAction = menu.addAction(KIcon("tab-new"), i18nc("@action:inmenu", "New Tab"));
1123 newTabAction->setShortcut(actionCollection()->action("new_tab")->shortcut());
1124
1125 QAction* detachTabAction = menu.addAction(KIcon("tab-detach"), i18nc("@action:inmenu", "Detach Tab"));
1126
1127 QAction* closeOtherTabsAction = menu.addAction(KIcon("tab-close-other"), i18nc("@action:inmenu", "Close Other Tabs"));
1128
1129 QAction* closeTabAction = menu.addAction(KIcon("tab-close"), i18nc("@action:inmenu", "Close Tab"));
1130 closeTabAction->setShortcut(actionCollection()->action("close_tab")->shortcut());
1131 QAction* selectedAction = menu.exec(pos);
1132 if (selectedAction == newTabAction) {
1133 const ViewTab& tab = m_viewTab[index];
1134 Q_ASSERT(tab.primaryView);
1135 const KUrl url = tab.secondaryView && tab.secondaryView->isActive() ?
1136 tab.secondaryView->url() : tab.primaryView->url();
1137 openNewTab(url);
1138 m_tabBar->setCurrentIndex(m_viewTab.count() - 1);
1139 } else if (selectedAction == detachTabAction) {
1140 const ViewTab& tab = m_viewTab[index];
1141 Q_ASSERT(tab.primaryView);
1142 const KUrl primaryUrl = tab.primaryView->url();
1143 DolphinMainWindow* window = DolphinApplication::app()->createMainWindow();
1144 window->changeUrl(primaryUrl);
1145
1146 if (tab.secondaryView) {
1147 const KUrl secondaryUrl = tab.secondaryView->url();
1148 if (!window->m_viewTab[0].secondaryView) {
1149 window->toggleSplitView();
1150 }
1151 window->m_viewTab[0].secondaryView->setUrl(secondaryUrl);
1152 if (tab.primaryView->isActive()) {
1153 window->m_viewTab[0].primaryView->setActive(true);
1154 } else {
1155 window->m_viewTab[0].secondaryView->setActive(true);
1156 }
1157 }
1158 window->show();
1159 closeTab(index);
1160 } else if (selectedAction == closeOtherTabsAction) {
1161 const int count = m_tabBar->count();
1162 for (int i = 0; i < index; ++i) {
1163 closeTab(0);
1164 }
1165 for (int i = index + 1; i < count; ++i) {
1166 closeTab(1);
1167 }
1168 } else if (selectedAction == closeTabAction) {
1169 closeTab(index);
1170 }
1171 }
1172
1173 void DolphinMainWindow::slotTabMoved(int from, int to)
1174 {
1175 m_viewTab.move(from, to);
1176 m_tabIndex = m_tabBar->currentIndex();
1177 }
1178
1179 void DolphinMainWindow::handlePlacesClick(const KUrl& url, Qt::MouseButtons buttons)
1180 {
1181 if (buttons & Qt::MidButton) {
1182 openNewTab(url);
1183 m_tabBar->setCurrentIndex(m_viewTab.count() - 1);
1184 } else {
1185 changeUrl(url);
1186 }
1187 }
1188
1189 void DolphinMainWindow::slotTestCanDecode(const QDragMoveEvent* event, bool& canDecode)
1190 {
1191 canDecode = KUrl::List::canDecode(event->mimeData());
1192 }
1193
1194 void DolphinMainWindow::handleUrl(const KUrl& url)
1195 {
1196 delete m_lastHandleUrlStatJob;
1197 m_lastHandleUrlStatJob = 0;
1198
1199 if (url.isLocalFile() && QFileInfo(url.toLocalFile()).isDir()) {
1200 activeViewContainer()->setUrl(url);
1201 } else if (KProtocolManager::supportsListing(url)) {
1202 // stat the URL to see if it is a dir or not
1203 m_lastHandleUrlStatJob = KIO::stat(url, KIO::HideProgressInfo);
1204 connect(m_lastHandleUrlStatJob, SIGNAL(result(KJob*)),
1205 this, SLOT(slotHandleUrlStatFinished(KJob*)));
1206
1207 } else {
1208 new KRun(url, this);
1209 }
1210 }
1211
1212 void DolphinMainWindow::slotHandleUrlStatFinished(KJob* job)
1213 {
1214 m_lastHandleUrlStatJob = 0;
1215 const KIO::UDSEntry entry = static_cast<KIO::StatJob*>(job)->statResult();
1216 const KUrl url = static_cast<KIO::StatJob*>(job)->url();
1217 if (entry.isDir()) {
1218 activeViewContainer()->setUrl(url);
1219 } else {
1220 new KRun(url, this);
1221 }
1222 }
1223
1224 void DolphinMainWindow::tabDropEvent(int tab, QDropEvent* event)
1225 {
1226 const KUrl::List urls = KUrl::List::fromMimeData(event->mimeData());
1227 if (!urls.isEmpty() && tab != -1) {
1228 const ViewTab& viewTab = m_viewTab[tab];
1229 const KUrl destPath = viewTab.isPrimaryViewActive ? viewTab.primaryView->url() : viewTab.secondaryView->url();
1230 DragAndDropHelper::instance().dropUrls(KFileItem(), destPath, event, m_tabBar);
1231 }
1232 }
1233
1234 void DolphinMainWindow::slotWriteStateChanged(bool isFolderWritable)
1235 {
1236 newFileMenu()->setEnabled(isFolderWritable);
1237 }
1238
1239 void DolphinMainWindow::slotSearchModeChanged(bool enabled)
1240 {
1241 #ifdef HAVE_NEPOMUK
1242 const KUrl url = m_activeViewContainer->url();
1243 const DolphinSearchInformation& searchInfo = DolphinSearchInformation::instance();
1244 if (!searchInfo.isIndexingEnabled() || !searchInfo.isPathIndexed(url)) {
1245 return;
1246 }
1247
1248 QDockWidget* searchDock = findChild<QDockWidget*>("searchDock");
1249 if (!searchDock) {
1250 return;
1251 }
1252
1253 if (enabled) {
1254 if (!searchDock->isVisible()) {
1255 m_searchDockIsTemporaryVisible = true;
1256 }
1257 searchDock->show();
1258 } else {
1259 if (searchDock->isVisible() && m_searchDockIsTemporaryVisible) {
1260 searchDock->hide();
1261 }
1262 m_searchDockIsTemporaryVisible = false;
1263 }
1264
1265 SearchPanel* searchPanel = qobject_cast<SearchPanel*>(searchDock->widget());
1266 if (searchPanel) {
1267 // Per default any search-operation triggered by the Search Panel is done
1268 // "Everywhere".
1269 SearchPanel::SearchMode searchMode = SearchPanel::Everywhere;
1270
1271 if (enabled && (SearchSettings::location() == QLatin1String("FromHere"))) {
1272 // Only if the search-mode is enabled it is visible for the user whether
1273 // a searching is done "Everywhere" or "From Here" (= current directory).
1274 searchMode = SearchPanel::FromCurrentDir;
1275 }
1276 searchPanel->setSearchMode(searchMode);
1277 }
1278 #else
1279 Q_UNUSED(enabled);
1280 #endif
1281 }
1282
1283 void DolphinMainWindow::openContextMenu(const KFileItem& item,
1284 const KUrl& url,
1285 const QList<QAction*>& customActions)
1286 {
1287 QPointer<DolphinContextMenu> contextMenu = new DolphinContextMenu(this, item, url);
1288 contextMenu->setCustomActions(customActions);
1289 const DolphinContextMenu::Command command = contextMenu->open();
1290
1291 switch (command) {
1292 case DolphinContextMenu::OpenParentFolderInNewWindow: {
1293 DolphinMainWindow* window = DolphinApplication::app()->createMainWindow();
1294 window->changeUrl(item.url().upUrl());
1295 window->show();
1296 break;
1297 }
1298
1299 case DolphinContextMenu::OpenParentFolderInNewTab:
1300 openNewTab(item.url().upUrl());
1301 break;
1302
1303 case DolphinContextMenu::None:
1304 default:
1305 break;
1306 }
1307
1308 delete contextMenu;
1309 }
1310
1311 void DolphinMainWindow::init()
1312 {
1313 DolphinSettings& settings = DolphinSettings::instance();
1314
1315 // Check whether Dolphin runs the first time. If yes then
1316 // a proper default window size is given at the end of DolphinMainWindow::init().
1317 GeneralSettings* generalSettings = settings.generalSettings();
1318 const bool firstRun = generalSettings->firstRun();
1319 if (firstRun) {
1320 generalSettings->setViewPropsTimestamp(QDateTime::currentDateTime());
1321 }
1322
1323 setAcceptDrops(true);
1324
1325 m_viewTab[m_tabIndex].splitter = new QSplitter(this);
1326 m_viewTab[m_tabIndex].splitter->setChildrenCollapsible(false);
1327
1328 setupActions();
1329
1330 const KUrl homeUrl(generalSettings->homeUrl());
1331 setUrlAsCaption(homeUrl);
1332 m_actionHandler = new DolphinViewActionHandler(actionCollection(), this);
1333 connect(m_actionHandler, SIGNAL(actionBeingHandled()), SLOT(clearStatusBar()));
1334 connect(m_actionHandler, SIGNAL(createDirectory()), SLOT(createDirectory()));
1335
1336 m_viewTab[m_tabIndex].primaryView = createViewContainer(homeUrl, m_viewTab[m_tabIndex].splitter);
1337
1338 m_activeViewContainer = m_viewTab[m_tabIndex].primaryView;
1339 connectViewSignals(m_activeViewContainer);
1340 DolphinView* view = m_activeViewContainer->view();
1341 m_activeViewContainer->show();
1342 m_actionHandler->setCurrentView(view);
1343
1344 m_remoteEncoding = new DolphinRemoteEncoding(this, m_actionHandler);
1345 connect(this, SIGNAL(urlChanged(const KUrl&)),
1346 m_remoteEncoding, SLOT(slotAboutToOpenUrl()));
1347
1348 m_tabBar = new KTabBar(this);
1349 m_tabBar->setMovable(true);
1350 m_tabBar->setTabsClosable(true);
1351 connect(m_tabBar, SIGNAL(currentChanged(int)),
1352 this, SLOT(setActiveTab(int)));
1353 connect(m_tabBar, SIGNAL(tabCloseRequested(int)),
1354 this, SLOT(closeTab(int)));
1355 connect(m_tabBar, SIGNAL(contextMenu(int, const QPoint&)),
1356 this, SLOT(openTabContextMenu(int, const QPoint&)));
1357 connect(m_tabBar, SIGNAL(newTabRequest()),
1358 this, SLOT(openNewTab()));
1359 connect(m_tabBar, SIGNAL(testCanDecode(const QDragMoveEvent*, bool&)),
1360 this, SLOT(slotTestCanDecode(const QDragMoveEvent*, bool&)));
1361 connect(m_tabBar, SIGNAL(mouseMiddleClick(int)),
1362 this, SLOT(closeTab(int)));
1363 connect(m_tabBar, SIGNAL(tabMoved(int, int)),
1364 this, SLOT(slotTabMoved(int, int)));
1365 connect(m_tabBar, SIGNAL(receivedDropEvent(int, QDropEvent*)),
1366 this, SLOT(tabDropEvent(int, QDropEvent*)));
1367
1368 m_tabBar->blockSignals(true); // signals get unblocked after at least 2 tabs are open
1369
1370 QWidget* centralWidget = new QWidget(this);
1371 m_centralWidgetLayout = new QVBoxLayout(centralWidget);
1372 m_centralWidgetLayout->setSpacing(0);
1373 m_centralWidgetLayout->setMargin(0);
1374 m_centralWidgetLayout->addWidget(m_tabBar);
1375 m_centralWidgetLayout->addWidget(m_viewTab[m_tabIndex].splitter, 1);
1376
1377 setCentralWidget(centralWidget);
1378 setupDockWidgets();
1379 emit urlChanged(homeUrl);
1380
1381 setupGUI(Keys | Save | Create | ToolBar);
1382 stateChanged("new_file");
1383
1384 QClipboard* clipboard = QApplication::clipboard();
1385 connect(clipboard, SIGNAL(dataChanged()),
1386 this, SLOT(updatePasteAction()));
1387
1388 if (generalSettings->splitView()) {
1389 toggleSplitView();
1390 }
1391 updateEditActions();
1392 updateViewActions();
1393 updateGoActions();
1394
1395 QAction* showFilterBarAction = actionCollection()->action("show_filter_bar");
1396 showFilterBarAction->setChecked(generalSettings->filterBar());
1397
1398 if (firstRun) {
1399 // assure a proper default size if Dolphin runs the first time
1400 resize(750, 500);
1401 }
1402
1403 m_showMenuBar->setChecked(!menuBar()->isHidden()); // workaround for bug #171080
1404 }
1405
1406 void DolphinMainWindow::setActiveViewContainer(DolphinViewContainer* viewContainer)
1407 {
1408 Q_ASSERT(viewContainer);
1409 Q_ASSERT((viewContainer == m_viewTab[m_tabIndex].primaryView) ||
1410 (viewContainer == m_viewTab[m_tabIndex].secondaryView));
1411 if (m_activeViewContainer == viewContainer) {
1412 return;
1413 }
1414
1415 m_activeViewContainer->setActive(false);
1416 m_activeViewContainer = viewContainer;
1417
1418 // Activating the view container might trigger a recursive setActiveViewContainer() call
1419 // inside DolphinMainWindow::toggleActiveView() when having a split view. Temporary
1420 // disconnect the activated() signal in this case:
1421 disconnect(m_activeViewContainer->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1422 m_activeViewContainer->setActive(true);
1423 connect(m_activeViewContainer->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1424
1425 m_actionHandler->setCurrentView(viewContainer->view());
1426
1427 updateHistory();
1428 updateEditActions();
1429 updateViewActions();
1430 updateGoActions();
1431
1432 const KUrl url = m_activeViewContainer->url();
1433 setUrlAsCaption(url);
1434 if (m_viewTab.count() > 1) {
1435 m_tabBar->setTabText(m_tabIndex, tabName(url));
1436 m_tabBar->setTabIcon(m_tabIndex, KIcon(KMimeType::iconNameForUrl(url)));
1437 }
1438
1439 emit urlChanged(url);
1440 }
1441
1442 DolphinViewContainer* DolphinMainWindow::createViewContainer(const KUrl& url, QWidget* parent)
1443 {
1444 DolphinViewContainer* container = new DolphinViewContainer(url, parent);
1445
1446 // The places-selector from the URL navigator should only be shown
1447 // if the places dock is invisible
1448 QDockWidget* placesDock = findChild<QDockWidget*>("placesDock");
1449 container->urlNavigator()->setPlacesSelectorVisible(!placesDock || !placesDock->isVisible());
1450
1451 return container;
1452 }
1453
1454 void DolphinMainWindow::setupActions()
1455 {
1456 // setup 'File' menu
1457 m_newFileMenu = new DolphinNewFileMenu(this);
1458 KMenu* menu = m_newFileMenu->menu();
1459 menu->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1460 menu->setIcon(KIcon("document-new"));
1461 connect(menu, SIGNAL(aboutToShow()),
1462 this, SLOT(updateNewMenu()));
1463
1464 KAction* newWindow = actionCollection()->addAction("new_window");
1465 newWindow->setIcon(KIcon("window-new"));
1466 newWindow->setText(i18nc("@action:inmenu File", "New &Window"));
1467 newWindow->setShortcut(Qt::CTRL | Qt::Key_N);
1468 connect(newWindow, SIGNAL(triggered()), this, SLOT(openNewMainWindow()));
1469
1470 KAction* newTab = actionCollection()->addAction("new_tab");
1471 newTab->setIcon(KIcon("tab-new"));
1472 newTab->setText(i18nc("@action:inmenu File", "New Tab"));
1473 newTab->setShortcut(KShortcut(Qt::CTRL | Qt::Key_T, Qt::CTRL | Qt::SHIFT | Qt::Key_N));
1474 connect(newTab, SIGNAL(triggered()), this, SLOT(openNewTab()));
1475
1476 KAction* closeTab = actionCollection()->addAction("close_tab");
1477 closeTab->setIcon(KIcon("tab-close"));
1478 closeTab->setText(i18nc("@action:inmenu File", "Close Tab"));
1479 closeTab->setShortcut(Qt::CTRL | Qt::Key_W);
1480 closeTab->setEnabled(false);
1481 connect(closeTab, SIGNAL(triggered()), this, SLOT(closeTab()));
1482
1483 KStandardAction::quit(this, SLOT(quit()), actionCollection());
1484
1485 // setup 'Edit' menu
1486 KStandardAction::undo(this,
1487 SLOT(undo()),
1488 actionCollection());
1489
1490 // need to remove shift+del from cut action, else the shortcut for deletejob
1491 // doesn't work
1492 KAction* cut = KStandardAction::cut(this, SLOT(cut()), actionCollection());
1493 KShortcut cutShortcut = cut->shortcut();
1494 cutShortcut.remove(Qt::SHIFT | Qt::Key_Delete, KShortcut::KeepEmpty);
1495 cut->setShortcut(cutShortcut);
1496 KStandardAction::copy(this, SLOT(copy()), actionCollection());
1497 KAction* paste = KStandardAction::paste(this, SLOT(paste()), actionCollection());
1498 // The text of the paste-action is modified dynamically by Dolphin
1499 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1500 // due to the long text, the text "Paste" is used:
1501 paste->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1502
1503 KStandardAction::find(this, SLOT(find()), actionCollection());
1504
1505 KAction* selectAll = actionCollection()->addAction("select_all");
1506 selectAll->setText(i18nc("@action:inmenu Edit", "Select All"));
1507 selectAll->setShortcut(Qt::CTRL | Qt::Key_A);
1508 connect(selectAll, SIGNAL(triggered()), this, SLOT(selectAll()));
1509
1510 KAction* invertSelection = actionCollection()->addAction("invert_selection");
1511 invertSelection->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1512 invertSelection->setShortcut(Qt::CTRL | Qt::SHIFT | Qt::Key_A);
1513 connect(invertSelection, SIGNAL(triggered()), this, SLOT(invertSelection()));
1514
1515 // setup 'View' menu
1516 // (note that most of it is set up in DolphinViewActionHandler)
1517
1518 KAction* split = actionCollection()->addAction("split_view");
1519 split->setShortcut(Qt::Key_F3);
1520 updateSplitAction();
1521 connect(split, SIGNAL(triggered()), this, SLOT(toggleSplitView()));
1522
1523 KAction* reload = actionCollection()->addAction("reload");
1524 reload->setText(i18nc("@action:inmenu View", "Reload"));
1525 reload->setShortcut(Qt::Key_F5);
1526 reload->setIcon(KIcon("view-refresh"));
1527 connect(reload, SIGNAL(triggered()), this, SLOT(reloadView()));
1528
1529 KAction* stop = actionCollection()->addAction("stop");
1530 stop->setText(i18nc("@action:inmenu View", "Stop"));
1531 stop->setToolTip(i18nc("@info", "Stop loading"));
1532 stop->setIcon(KIcon("process-stop"));
1533 connect(stop, SIGNAL(triggered()), this, SLOT(stopLoading()));
1534
1535 KToggleAction* showFullLocation = actionCollection()->add<KToggleAction>("editable_location");
1536 showFullLocation->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1537 showFullLocation->setShortcut(Qt::CTRL | Qt::Key_L);
1538 connect(showFullLocation, SIGNAL(triggered()), this, SLOT(toggleEditLocation()));
1539
1540 KAction* replaceLocation = actionCollection()->addAction("replace_location");
1541 replaceLocation->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1542 replaceLocation->setShortcut(Qt::Key_F6);
1543 connect(replaceLocation, SIGNAL(triggered()), this, SLOT(replaceLocation()));
1544
1545 // setup 'Go' menu
1546 KAction* backAction = KStandardAction::back(this, SLOT(goBack()), actionCollection());
1547 connect(backAction, SIGNAL(triggered(Qt::MouseButtons, Qt::KeyboardModifiers)), this, SLOT(goBack(Qt::MouseButtons)));
1548 KShortcut backShortcut = backAction->shortcut();
1549 backShortcut.setAlternate(Qt::Key_Backspace);
1550 backAction->setShortcut(backShortcut);
1551
1552 m_recentTabsMenu = new KActionMenu(i18n("Recently Closed Tabs"), this);
1553 m_recentTabsMenu->setIcon(KIcon("edit-undo"));
1554 actionCollection()->addAction("closed_tabs", m_recentTabsMenu);
1555 connect(m_recentTabsMenu->menu(), SIGNAL(triggered(QAction *)),
1556 this, SLOT(restoreClosedTab(QAction *)));
1557
1558 QAction* action = new QAction("Empty Recently Closed Tabs", m_recentTabsMenu);
1559 action->setIcon(KIcon("edit-clear-list"));
1560 action->setData(QVariant::fromValue(true));
1561 m_recentTabsMenu->addAction(action);
1562 m_recentTabsMenu->addSeparator();
1563 m_recentTabsMenu->setEnabled(false);
1564
1565 KAction* forwardAction = KStandardAction::forward(this, SLOT(goForward()), actionCollection());
1566 connect(forwardAction, SIGNAL(triggered(Qt::MouseButtons, Qt::KeyboardModifiers)), this, SLOT(goForward(Qt::MouseButtons)));
1567
1568 KAction* upAction = KStandardAction::up(this, SLOT(goUp()), actionCollection());
1569 connect(upAction, SIGNAL(triggered(Qt::MouseButtons, Qt::KeyboardModifiers)), this, SLOT(goUp(Qt::MouseButtons)));
1570
1571 KStandardAction::home(this, SLOT(goHome()), actionCollection());
1572
1573 // setup 'Tools' menu
1574 KAction* showFilterBar = actionCollection()->addAction("show_filter_bar");
1575 showFilterBar->setText(i18nc("@action:inmenu Tools", "Show Filter Bar"));
1576 showFilterBar->setIcon(KIcon("view-filter"));
1577 showFilterBar->setShortcut(Qt::CTRL | Qt::Key_I);
1578 connect(showFilterBar, SIGNAL(triggered()), this, SLOT(showFilterBar()));
1579
1580 KAction* compareFiles = actionCollection()->addAction("compare_files");
1581 compareFiles->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1582 compareFiles->setIcon(KIcon("kompare"));
1583 compareFiles->setEnabled(false);
1584 connect(compareFiles, SIGNAL(triggered()), this, SLOT(compareFiles()));
1585
1586 KAction* openTerminal = actionCollection()->addAction("open_terminal");
1587 openTerminal->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
1588 openTerminal->setIcon(KIcon("utilities-terminal"));
1589 openTerminal->setShortcut(Qt::SHIFT | Qt::Key_F4);
1590 connect(openTerminal, SIGNAL(triggered()), this, SLOT(openTerminal()));
1591
1592 // setup 'Settings' menu
1593 m_showMenuBar = KStandardAction::showMenubar(this, SLOT(toggleShowMenuBar()), actionCollection());
1594 KStandardAction::preferences(this, SLOT(editSettings()), actionCollection());
1595
1596 // not in menu actions
1597 QList<QKeySequence> nextTabKeys;
1598 nextTabKeys.append(KStandardShortcut::tabNext().primary());
1599 nextTabKeys.append(QKeySequence(Qt::CTRL | Qt::Key_Tab));
1600
1601 QList<QKeySequence> prevTabKeys;
1602 prevTabKeys.append(KStandardShortcut::tabPrev().primary());
1603 prevTabKeys.append(QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_Tab));
1604
1605 KAction* activateNextTab = actionCollection()->addAction("activate_next_tab");
1606 activateNextTab->setText(i18nc("@action:inmenu", "Activate Next Tab"));
1607 connect(activateNextTab, SIGNAL(triggered()), SLOT(activateNextTab()));
1608 activateNextTab->setShortcuts(QApplication::isRightToLeft() ? prevTabKeys : nextTabKeys);
1609
1610 KAction* activatePrevTab = actionCollection()->addAction("activate_prev_tab");
1611 activatePrevTab->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
1612 connect(activatePrevTab, SIGNAL(triggered()), SLOT(activatePrevTab()));
1613 activatePrevTab->setShortcuts(QApplication::isRightToLeft() ? nextTabKeys : prevTabKeys);
1614
1615 // for context menu
1616 KAction* openInNewTab = actionCollection()->addAction("open_in_new_tab");
1617 openInNewTab->setText(i18nc("@action:inmenu", "Open in New Tab"));
1618 openInNewTab->setIcon(KIcon("tab-new"));
1619 connect(openInNewTab, SIGNAL(triggered()), this, SLOT(openInNewTab()));
1620
1621 KAction* openInNewWindow = actionCollection()->addAction("open_in_new_window");
1622 openInNewWindow->setText(i18nc("@action:inmenu", "Open in New Window"));
1623 openInNewWindow->setIcon(KIcon("window-new"));
1624 connect(openInNewWindow, SIGNAL(triggered()), this, SLOT(openInNewWindow()));
1625 }
1626
1627 void DolphinMainWindow::setupDockWidgets()
1628 {
1629 const bool lock = DolphinSettings::instance().generalSettings()->lockPanels();
1630
1631 KDualAction* lockLayoutAction = actionCollection()->add<KDualAction>("lock_panels");
1632 lockLayoutAction->setActiveText(i18nc("@action:inmenu Panels", "Unlock Panels"));
1633 lockLayoutAction->setActiveIcon(KIcon("object-unlocked"));
1634 lockLayoutAction->setInactiveText(i18nc("@action:inmenu Panels", "Lock Panels"));
1635 lockLayoutAction->setInactiveIcon(KIcon("object-locked"));
1636 lockLayoutAction->setActive(lock);
1637 connect(lockLayoutAction, SIGNAL(triggered()), this, SLOT(togglePanelLockState()));
1638
1639 // Setup "Information"
1640 DolphinDockWidget* infoDock = new DolphinDockWidget(i18nc("@title:window", "Information"));
1641 infoDock->setLocked(lock);
1642 infoDock->setObjectName("infoDock");
1643 infoDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
1644 Panel* infoPanel = new InformationPanel(infoDock);
1645 infoPanel->setCustomContextMenuActions(QList<QAction*>() << lockLayoutAction);
1646 connect(infoPanel, SIGNAL(urlActivated(KUrl)), this, SLOT(handleUrl(KUrl)));
1647 infoDock->setWidget(infoPanel);
1648
1649 QAction* infoAction = infoDock->toggleViewAction();
1650 infoAction->setIcon(KIcon("dialog-information"));
1651 infoAction->setShortcut(Qt::Key_F11);
1652 addActionCloneToCollection(infoAction, "show_information_panel");
1653
1654 addDockWidget(Qt::RightDockWidgetArea, infoDock);
1655 connect(this, SIGNAL(urlChanged(KUrl)),
1656 infoPanel, SLOT(setUrl(KUrl)));
1657 connect(this, SIGNAL(selectionChanged(KFileItemList)),
1658 infoPanel, SLOT(setSelection(KFileItemList)));
1659 connect(this, SIGNAL(requestItemInfo(KFileItem)),
1660 infoPanel, SLOT(requestDelayedItemInfo(KFileItem)));
1661
1662 // Setup "Folders"
1663 DolphinDockWidget* foldersDock = new DolphinDockWidget(i18nc("@title:window", "Folders"));
1664 foldersDock->setLocked(lock);
1665 foldersDock->setObjectName("foldersDock");
1666 foldersDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
1667 FoldersPanel* foldersPanel = new FoldersPanel(foldersDock);
1668 foldersPanel->setCustomContextMenuActions(QList<QAction*>() << lockLayoutAction);
1669 foldersDock->setWidget(foldersPanel);
1670
1671 QAction* foldersAction = foldersDock->toggleViewAction();
1672 foldersAction->setShortcut(Qt::Key_F7);
1673 foldersAction->setIcon(KIcon("folder"));
1674 addActionCloneToCollection(foldersAction, "show_folders_panel");
1675
1676 addDockWidget(Qt::LeftDockWidgetArea, foldersDock);
1677 connect(this, SIGNAL(urlChanged(KUrl)),
1678 foldersPanel, SLOT(setUrl(KUrl)));
1679 connect(foldersPanel, SIGNAL(changeUrl(KUrl, Qt::MouseButtons)),
1680 this, SLOT(handlePlacesClick(KUrl, Qt::MouseButtons)));
1681
1682 // Setup "Terminal"
1683 #ifndef Q_OS_WIN
1684 DolphinDockWidget* terminalDock = new DolphinDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
1685 terminalDock->setLocked(lock);
1686 terminalDock->setObjectName("terminalDock");
1687 terminalDock->setAllowedAreas(Qt::TopDockWidgetArea | Qt::BottomDockWidgetArea);
1688 Panel* terminalPanel = new TerminalPanel(terminalDock);
1689 terminalPanel->setCustomContextMenuActions(QList<QAction*>() << lockLayoutAction);
1690 terminalDock->setWidget(terminalPanel);
1691
1692 connect(terminalPanel, SIGNAL(hideTerminalPanel()), terminalDock, SLOT(hide()));
1693
1694 QAction* terminalAction = terminalDock->toggleViewAction();
1695 terminalAction->setShortcut(Qt::Key_F4);
1696 terminalAction->setIcon(KIcon("utilities-terminal"));
1697 addActionCloneToCollection(terminalAction, "show_terminal_panel");
1698
1699 addDockWidget(Qt::BottomDockWidgetArea, terminalDock);
1700 connect(this, SIGNAL(urlChanged(KUrl)),
1701 terminalPanel, SLOT(setUrl(KUrl)));
1702 #endif
1703
1704 // Setup "Search"
1705 #ifdef HAVE_NEPOMUK
1706 DolphinDockWidget* searchDock = new DolphinDockWidget(i18nc("@title:window", "Search"));
1707 searchDock->setLocked(lock);
1708 searchDock->setObjectName("searchDock");
1709 searchDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
1710 Panel* searchPanel = new SearchPanel(searchDock);
1711 searchPanel->setCustomContextMenuActions(QList<QAction*>() << lockLayoutAction);
1712 connect(searchPanel, SIGNAL(urlActivated(KUrl)), this, SLOT(handleUrl(KUrl)));
1713 searchDock->setWidget(searchPanel);
1714
1715 QAction* searchAction = searchDock->toggleViewAction();
1716 searchAction->setShortcut(Qt::Key_F12);
1717 searchAction->setIcon(KIcon("system-search"));
1718 addActionCloneToCollection(searchAction, "show_search_panel");
1719 addDockWidget(Qt::RightDockWidgetArea, searchDock);
1720 connect(this, SIGNAL(urlChanged(KUrl)),
1721 searchPanel, SLOT(setUrl(KUrl)));
1722 #endif
1723
1724 const bool firstRun = DolphinSettings::instance().generalSettings()->firstRun();
1725 if (firstRun) {
1726 infoDock->hide();
1727 foldersDock->hide();
1728 #ifndef Q_OS_WIN
1729 terminalDock->hide();
1730 #endif
1731 #ifdef HAVE_NEPOMUK
1732 searchDock->hide();
1733 #endif
1734 }
1735
1736 // Setup "Places"
1737 DolphinDockWidget* placesDock = new DolphinDockWidget(i18nc("@title:window", "Places"));
1738 placesDock->setLocked(lock);
1739 placesDock->setObjectName("placesDock");
1740 placesDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
1741
1742 PlacesPanel* placesPanel = new PlacesPanel(placesDock);
1743 QAction* separator = new QAction(placesPanel);
1744 separator->setSeparator(true);
1745 QList<QAction*> placesActions;
1746 placesActions.append(separator);
1747 placesActions.append(lockLayoutAction);
1748 placesPanel->addActions(placesActions);
1749 placesPanel->setModel(DolphinSettings::instance().placesModel());
1750 placesPanel->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
1751 placesDock->setWidget(placesPanel);
1752
1753 QAction* placesAction = placesDock->toggleViewAction();
1754 placesAction->setShortcut(Qt::Key_F9);
1755 placesAction->setIcon(KIcon("bookmarks"));
1756 addActionCloneToCollection(placesAction, "show_places_panel");
1757
1758 addDockWidget(Qt::LeftDockWidgetArea, placesDock);
1759 connect(placesPanel, SIGNAL(urlChanged(KUrl, Qt::MouseButtons)),
1760 this, SLOT(handlePlacesClick(KUrl, Qt::MouseButtons)));
1761 connect(this, SIGNAL(urlChanged(KUrl)),
1762 placesPanel, SLOT(setUrl(KUrl)));
1763 connect(placesDock, SIGNAL(visibilityChanged(bool)),
1764 this, SLOT(slotPlacesPanelVisibilityChanged(bool)));
1765
1766 // Add actions into the "Panels" menu
1767 KActionMenu* panelsMenu = new KActionMenu(i18nc("@action:inmenu View", "Panels"), this);
1768 actionCollection()->addAction("panels", panelsMenu);
1769 panelsMenu->setDelayed(false);
1770 panelsMenu->addAction(placesAction);
1771 panelsMenu->addAction(infoAction);
1772 panelsMenu->addAction(foldersAction);
1773 #ifndef Q_OS_WIN
1774 panelsMenu->addAction(terminalAction);
1775 #endif
1776 #ifdef HAVE_NEPOMUK
1777 panelsMenu->addAction(searchAction);
1778 #endif
1779 panelsMenu->addSeparator();
1780 panelsMenu->addAction(lockLayoutAction);
1781 }
1782
1783 void DolphinMainWindow::updateEditActions()
1784 {
1785 const KFileItemList list = m_activeViewContainer->view()->selectedItems();
1786 if (list.isEmpty()) {
1787 stateChanged("has_no_selection");
1788 } else {
1789 stateChanged("has_selection");
1790
1791 KActionCollection* col = actionCollection();
1792 QAction* renameAction = col->action("rename");
1793 QAction* moveToTrashAction = col->action("move_to_trash");
1794 QAction* deleteAction = col->action("delete");
1795 QAction* cutAction = col->action(KStandardAction::name(KStandardAction::Cut));
1796 QAction* deleteWithTrashShortcut = col->action("delete_shortcut"); // see DolphinViewActionHandler
1797
1798 KFileItemListProperties capabilities(list);
1799 const bool enableMoveToTrash = capabilities.isLocal() && capabilities.supportsMoving();
1800
1801 renameAction->setEnabled(capabilities.supportsMoving());
1802 moveToTrashAction->setEnabled(enableMoveToTrash);
1803 deleteAction->setEnabled(capabilities.supportsDeleting());
1804 deleteWithTrashShortcut->setEnabled(capabilities.supportsDeleting() && !enableMoveToTrash);
1805 cutAction->setEnabled(capabilities.supportsMoving());
1806 }
1807 updatePasteAction();
1808 }
1809
1810 void DolphinMainWindow::updateViewActions()
1811 {
1812 m_actionHandler->updateViewActions();
1813
1814 QAction* showFilterBarAction = actionCollection()->action("show_filter_bar");
1815 showFilterBarAction->setChecked(m_activeViewContainer->isFilterBarVisible());
1816
1817 updateSplitAction();
1818
1819 QAction* editableLocactionAction = actionCollection()->action("editable_location");
1820 const KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator();
1821 editableLocactionAction->setChecked(urlNavigator->isUrlEditable());
1822 }
1823
1824 void DolphinMainWindow::updateGoActions()
1825 {
1826 QAction* goUpAction = actionCollection()->action(KStandardAction::name(KStandardAction::Up));
1827 const KUrl currentUrl = m_activeViewContainer->url();
1828 goUpAction->setEnabled(currentUrl.upUrl() != currentUrl);
1829 }
1830
1831 void DolphinMainWindow::rememberClosedTab(int index)
1832 {
1833 KMenu* tabsMenu = m_recentTabsMenu->menu();
1834
1835 const QString primaryPath = m_viewTab[index].primaryView->url().path();
1836 const QString iconName = KMimeType::iconNameForUrl(primaryPath);
1837
1838 QAction* action = new QAction(squeezedText(primaryPath), tabsMenu);
1839
1840 ClosedTab closedTab;
1841 closedTab.primaryUrl = m_viewTab[index].primaryView->url();
1842
1843 if (m_viewTab[index].secondaryView) {
1844 closedTab.secondaryUrl = m_viewTab[index].secondaryView->url();
1845 closedTab.isSplit = true;
1846 } else {
1847 closedTab.isSplit = false;
1848 }
1849
1850 action->setData(QVariant::fromValue(closedTab));
1851 action->setIcon(KIcon(iconName));
1852
1853 // add the closed tab menu entry after the separator and
1854 // "Empty Recently Closed Tabs" entry
1855 if (tabsMenu->actions().size() == 2) {
1856 tabsMenu->addAction(action);
1857 } else {
1858 tabsMenu->insertAction(tabsMenu->actions().at(2), action);
1859 }
1860
1861 // assure that only up to 8 closed tabs are shown in the menu
1862 if (tabsMenu->actions().size() > 8) {
1863 tabsMenu->removeAction(tabsMenu->actions().last());
1864 }
1865 actionCollection()->action("closed_tabs")->setEnabled(true);
1866 KAcceleratorManager::manage(tabsMenu);
1867 }
1868
1869 void DolphinMainWindow::clearStatusBar()
1870 {
1871 m_activeViewContainer->statusBar()->clear();
1872 }
1873
1874 void DolphinMainWindow::connectViewSignals(DolphinViewContainer* container)
1875 {
1876 connect(container, SIGNAL(showFilterBarChanged(bool)),
1877 this, SLOT(updateFilterBarAction(bool)));
1878 connect(container, SIGNAL(writeStateChanged(bool)),
1879 this, SLOT(slotWriteStateChanged(bool)));
1880 connect(container, SIGNAL(searchModeChanged(bool)),
1881 this, SLOT(slotSearchModeChanged(bool)));
1882
1883 DolphinView* view = container->view();
1884 connect(view, SIGNAL(selectionChanged(KFileItemList)),
1885 this, SLOT(slotSelectionChanged(KFileItemList)));
1886 connect(view, SIGNAL(requestItemInfo(KFileItem)),
1887 this, SLOT(slotRequestItemInfo(KFileItem)));
1888 connect(view, SIGNAL(activated()),
1889 this, SLOT(toggleActiveView()));
1890 connect(view, SIGNAL(tabRequested(const KUrl&)),
1891 this, SLOT(openNewTab(const KUrl&)));
1892 connect(view, SIGNAL(requestContextMenu(KFileItem, const KUrl&, const QList<QAction*>&)),
1893 this, SLOT(openContextMenu(KFileItem, const KUrl&, const QList<QAction*>&)));
1894 connect(view, SIGNAL(startedPathLoading(KUrl)),
1895 this, SLOT(enableStopAction()));
1896 connect(view, SIGNAL(finishedPathLoading(KUrl)),
1897 this, SLOT(disableStopAction()));
1898
1899 const KUrlNavigator* navigator = container->urlNavigator();
1900 connect(navigator, SIGNAL(urlChanged(const KUrl&)),
1901 this, SLOT(changeUrl(const KUrl&)));
1902 connect(navigator, SIGNAL(historyChanged()),
1903 this, SLOT(updateHistory()));
1904 connect(navigator, SIGNAL(editableStateChanged(bool)),
1905 this, SLOT(slotEditableStateChanged(bool)));
1906 connect(navigator, SIGNAL(tabRequested(const KUrl&)),
1907 this, SLOT(openNewTab(KUrl)));
1908 }
1909
1910 void DolphinMainWindow::updateSplitAction()
1911 {
1912 QAction* splitAction = actionCollection()->action("split_view");
1913 if (m_viewTab[m_tabIndex].secondaryView) {
1914 if (m_activeViewContainer == m_viewTab[m_tabIndex].secondaryView) {
1915 splitAction->setText(i18nc("@action:intoolbar Close right view", "Close"));
1916 splitAction->setToolTip(i18nc("@info", "Close right view"));
1917 splitAction->setIcon(KIcon("view-right-close"));
1918 } else {
1919 splitAction->setText(i18nc("@action:intoolbar Close left view", "Close"));
1920 splitAction->setToolTip(i18nc("@info", "Close left view"));
1921 splitAction->setIcon(KIcon("view-left-close"));
1922 }
1923 } else {
1924 splitAction->setText(i18nc("@action:intoolbar Split view", "Split"));
1925 splitAction->setToolTip(i18nc("@info", "Split view"));
1926 splitAction->setIcon(KIcon("view-right-new"));
1927 }
1928 }
1929
1930 QString DolphinMainWindow::tabName(const KUrl& url) const
1931 {
1932 QString name;
1933 if (url.equals(KUrl("file:///"))) {
1934 name = '/';
1935 } else {
1936 name = url.fileName();
1937 if (name.isEmpty()) {
1938 name = url.protocol();
1939 } else {
1940 // Make sure that a '&' inside the directory name is displayed correctly
1941 // and not misinterpreted as a keyboard shortcut in QTabBar::setTabText()
1942 name.replace('&', "&&");
1943 }
1944 }
1945 return name;
1946 }
1947
1948 bool DolphinMainWindow::isKompareInstalled() const
1949 {
1950 static bool initialized = false;
1951 static bool installed = false;
1952 if (!initialized) {
1953 // TODO: maybe replace this approach later by using a menu
1954 // plugin like kdiff3plugin.cpp
1955 installed = !KGlobal::dirs()->findExe("kompare").isEmpty();
1956 initialized = true;
1957 }
1958 return installed;
1959 }
1960
1961 void DolphinMainWindow::createSecondaryView(int tabIndex)
1962 {
1963 QSplitter* splitter = m_viewTab[tabIndex].splitter;
1964 const int newWidth = (m_viewTab[tabIndex].primaryView->width() - splitter->handleWidth()) / 2;
1965
1966 const DolphinView* view = m_viewTab[tabIndex].primaryView->view();
1967 m_viewTab[tabIndex].secondaryView = createViewContainer(view->rootUrl(), 0);
1968 splitter->addWidget(m_viewTab[tabIndex].secondaryView);
1969 splitter->setSizes(QList<int>() << newWidth << newWidth);
1970 connectViewSignals(m_viewTab[tabIndex].secondaryView);
1971 m_viewTab[tabIndex].secondaryView->setActive(false);
1972 m_viewTab[tabIndex].secondaryView->show();
1973 }
1974
1975 QString DolphinMainWindow::tabProperty(const QString& property, int tabIndex) const
1976 {
1977 return "Tab " + QString::number(tabIndex) + ' ' + property;
1978 }
1979
1980 void DolphinMainWindow::setUrlAsCaption(const KUrl& url)
1981 {
1982 QString caption;
1983 if (!url.isLocalFile()) {
1984 caption.append(url.protocol() + " - ");
1985 if (url.hasHost()) {
1986 caption.append(url.host() + " - ");
1987 }
1988 }
1989
1990 const QString fileName = url.fileName().isEmpty() ? "/" : url.fileName();
1991 caption.append(fileName);
1992
1993 setCaption(caption);
1994 }
1995
1996 QString DolphinMainWindow::squeezedText(const QString& text) const
1997 {
1998 const QFontMetrics fm = fontMetrics();
1999 return fm.elidedText(text, Qt::ElideMiddle, fm.maxWidth() * 10);
2000 }
2001
2002 void DolphinMainWindow::addActionCloneToCollection(QAction* action, const QString& actionName)
2003 {
2004 KAction* actionClone = actionCollection()->addAction(actionName);
2005 actionClone->setText(action->text());
2006 actionClone->setIcon(action->icon());
2007 connect(actionClone, SIGNAL(triggered()), action, SLOT(trigger()));
2008 }
2009
2010 DolphinMainWindow::UndoUiInterface::UndoUiInterface() :
2011 KIO::FileUndoManager::UiInterface()
2012 {
2013 }
2014
2015 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
2016 {
2017 }
2018
2019 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job* job)
2020 {
2021 DolphinMainWindow* mainWin= qobject_cast<DolphinMainWindow *>(parentWidget());
2022 if (mainWin) {
2023 DolphinStatusBar* statusBar = mainWin->activeViewContainer()->statusBar();
2024 statusBar->setMessage(job->errorString(), DolphinStatusBar::Error);
2025 } else {
2026 KIO::FileUndoManager::UiInterface::jobError(job);
2027 }
2028 }
2029
2030 #include "dolphinmainwindow.moc"