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