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