1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz <peter.penz@gmx.at> *
3 * Copyright (C) 2006 by Stefan Monov <logixoul@gmail.com> *
4 * Copyright (C) 2006 by Cvetoslav Ludmiloff <ludmiloff@gmail.com> *
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. *
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. *
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 ***************************************************************************/
22 #include "dolphinmainwindow.h"
23 #include "dolphinviewactionhandler.h"
24 #include "dolphinremoteencoding.h"
26 #include <config-nepomuk.h>
28 #include "search/dolphinsearchoptionsconfigurator.h"
31 #include "dolphinapplication.h"
32 #include "dolphinnewmenu.h"
33 #include "search/dolphinsearchbox.h"
34 #include "settings/dolphinsettings.h"
35 #include "settings/dolphinsettingsdialog.h"
36 #include "dolphinviewcontainer.h"
37 #include "panels/folders/folderspanel.h"
38 #include "panels/places/placespanel.h"
39 #include "panels/information/informationpanel.h"
40 #include "mainwindowadaptor.h"
41 #include "statusbar/dolphinstatusbar.h"
42 #include "viewproperties.h"
45 #include "panels/terminal/terminalpanel.h"
48 #include "dolphin_generalsettings.h"
49 #include "dolphin_iconsmodesettings.h"
50 #include "draganddrophelper.h"
53 #include <kactioncollection.h>
55 #include <kdesktopfile.h>
56 #include <kdeversion.h>
57 #include <kfiledialog.h>
58 #include <kfileplacesmodel.h>
60 #include <klineedit.h>
63 #include <kiconloader.h>
64 #include <kio/netaccess.h>
65 #include <kinputdialog.h>
67 #include <kprotocolmanager.h>
70 #include <kmessagebox.h>
71 #include <kfileitemlistproperties.h>
72 #include <konqmimedata.h>
73 #include <kprotocolinfo.h>
76 #include <kstandarddirs.h>
77 #include <kstatusbar.h>
78 #include <kstandardaction.h>
80 #include <ktoggleaction.h>
81 #include <kurlnavigator.h>
83 #include <kurlcombobox.h>
84 #include <ktoolinvocation.h>
86 #include <QDBusMessage>
90 #include <QDockWidget>
91 #include <kacceleratormanager.h>
94 * Remembers the tab configuration if a tab has been closed.
95 * Each closed tab can be restored by the menu
96 * "Go -> Recently Closed Tabs".
104 Q_DECLARE_METATYPE(ClosedTab
)
106 DolphinMainWindow::DolphinMainWindow(int id
) :
111 m_activeViewContainer(0),
112 m_centralWidgetLayout(0),
115 m_searchOptionsConfigurator(0),
125 setObjectName("Dolphin#");
127 m_viewTab
.append(ViewTab());
129 new MainWindowAdaptor(this);
130 QDBusConnection::sessionBus().registerObject(QString("/dolphin/MainWindow%1").arg(m_id
), this);
132 KIO::FileUndoManager
* undoManager
= KIO::FileUndoManager::self();
133 undoManager
->setUiInterface(new UndoUiInterface());
135 connect(undoManager
, SIGNAL(undoAvailable(bool)),
136 this, SLOT(slotUndoAvailable(bool)));
137 connect(undoManager
, SIGNAL(undoTextChanged(const QString
&)),
138 this, SLOT(slotUndoTextChanged(const QString
&)));
139 connect(undoManager
, SIGNAL(jobRecordingStarted(CommandType
)),
140 this, SLOT(clearStatusBar()));
141 connect(undoManager
, SIGNAL(jobRecordingFinished(CommandType
)),
142 this, SLOT(showCommand(CommandType
)));
143 connect(DolphinSettings::instance().placesModel(), SIGNAL(errorMessage(const QString
&)),
144 this, SLOT(showErrorMessage(const QString
&)));
145 connect(&DragAndDropHelper::instance(), SIGNAL(errorMessage(const QString
&)),
146 this, SLOT(showErrorMessage(const QString
&)));
149 DolphinMainWindow::~DolphinMainWindow()
151 DolphinApplication::app()->removeMainWindow(this);
154 void DolphinMainWindow::openDirectories(const QList
<KUrl
>& dirs
)
156 if (dirs
.isEmpty()) {
160 const int oldOpenTabsCount
= m_viewTab
.count();
162 const GeneralSettings
* generalSettings
= DolphinSettings::instance().generalSettings();
163 const bool hasSplitView
= generalSettings
->splitView();
165 // Open each directory inside a new tab. If the "split view" option has been enabled,
166 // always show two directories within one tab.
167 QList
<KUrl
>::const_iterator it
= dirs
.begin();
168 while (it
!= dirs
.end()) {
172 if (hasSplitView
&& (it
!= dirs
.end())) {
173 const int tabIndex
= m_viewTab
.count() - 1;
174 m_viewTab
[tabIndex
].secondaryView
->setUrl(*it
);
179 // remove the previously opened tabs
180 for (int i
= 0; i
< oldOpenTabsCount
; ++i
) {
185 void DolphinMainWindow::openFiles(const QList
<KUrl
>& files
)
187 if (files
.isEmpty()) {
191 // Get all distinct directories from 'files' and open a tab
192 // for each directory. If the "split view" option is enabled, two
193 // directories are shown inside one tab (see openDirectories()).
195 foreach (const KUrl
& url
, files
) {
196 const KUrl
dir(url
.directory());
197 if (!dirs
.contains(dir
)) {
202 openDirectories(dirs
);
204 // Select the files. Although the files can be split between several
205 // tabs, there is no need to split 'files' accordingly, as
206 // the DolphinView will just ignore invalid selections.
207 const int tabCount
= m_viewTab
.count();
208 for (int i
= 0; i
< tabCount
; ++i
) {
209 m_viewTab
[i
].primaryView
->view()->markUrlsAsSelected(files
);
210 if (m_viewTab
[i
].secondaryView
!= 0) {
211 m_viewTab
[i
].secondaryView
->view()->markUrlsAsSelected(files
);
216 void DolphinMainWindow::toggleViews()
218 if (m_viewTab
[m_tabIndex
].primaryView
== 0) {
222 // move secondary view from the last position of the splitter
223 // to the first position
224 m_viewTab
[m_tabIndex
].splitter
->insertWidget(0, m_viewTab
[m_tabIndex
].secondaryView
);
226 DolphinViewContainer
* container
= m_viewTab
[m_tabIndex
].primaryView
;
227 m_viewTab
[m_tabIndex
].primaryView
= m_viewTab
[m_tabIndex
].secondaryView
;
228 m_viewTab
[m_tabIndex
].secondaryView
= container
;
231 void DolphinMainWindow::showCommand(CommandType command
)
233 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
235 case KIO::FileUndoManager::Copy
:
236 statusBar
->setMessage(i18nc("@info:status", "Successfully copied."),
237 DolphinStatusBar::OperationCompleted
);
239 case KIO::FileUndoManager::Move
:
240 statusBar
->setMessage(i18nc("@info:status", "Successfully moved."),
241 DolphinStatusBar::OperationCompleted
);
243 case KIO::FileUndoManager::Link
:
244 statusBar
->setMessage(i18nc("@info:status", "Successfully linked."),
245 DolphinStatusBar::OperationCompleted
);
247 case KIO::FileUndoManager::Trash
:
248 statusBar
->setMessage(i18nc("@info:status", "Successfully moved to trash."),
249 DolphinStatusBar::OperationCompleted
);
251 case KIO::FileUndoManager::Rename
:
252 statusBar
->setMessage(i18nc("@info:status", "Successfully renamed."),
253 DolphinStatusBar::OperationCompleted
);
256 case KIO::FileUndoManager::Mkdir
:
257 statusBar
->setMessage(i18nc("@info:status", "Created folder."),
258 DolphinStatusBar::OperationCompleted
);
266 void DolphinMainWindow::refreshViews()
268 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
!= 0);
270 // remember the current active view, as because of
271 // the refreshing the active view might change to
272 // the secondary view
273 DolphinViewContainer
* activeViewContainer
= m_activeViewContainer
;
275 const int tabCount
= m_viewTab
.count();
276 for (int i
= 0; i
< tabCount
; ++i
) {
277 m_viewTab
[i
].primaryView
->refresh();
278 if (m_viewTab
[i
].secondaryView
!= 0) {
279 m_viewTab
[i
].secondaryView
->refresh();
283 setActiveViewContainer(activeViewContainer
);
286 void DolphinMainWindow::pasteIntoFolder()
288 m_activeViewContainer
->view()->pasteIntoFolder();
291 void DolphinMainWindow::changeUrl(const KUrl
& url
)
293 if (!KProtocolManager::supportsListing(url
)) {
294 // The URL navigator only checks for validity, not
295 // if the URL can be listed. An error message is
296 // shown due to DolphinViewContainer::restoreView().
300 DolphinViewContainer
* view
= activeViewContainer();
306 setUrlAsCaption(url
);
307 if (m_viewTab
.count() > 1) {
308 m_tabBar
->setTabText(m_tabIndex
, squeezedText(tabName(m_activeViewContainer
->url())));
310 const QString iconName
= KMimeType::iconNameForUrl(url
);
311 m_tabBar
->setTabIcon(m_tabIndex
, KIcon(iconName
));
312 emit
urlChanged(url
);
316 void DolphinMainWindow::slotEditableStateChanged(bool editable
)
318 KToggleAction
* editableLocationAction
=
319 static_cast<KToggleAction
*>(actionCollection()->action("editable_location"));
320 editableLocationAction
->setChecked(editable
);
323 void DolphinMainWindow::slotSelectionChanged(const KFileItemList
& selection
)
327 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
!= 0);
328 int selectedUrlsCount
= m_viewTab
[m_tabIndex
].primaryView
->view()->selectedItemsCount();
329 if (m_viewTab
[m_tabIndex
].secondaryView
!= 0) {
330 selectedUrlsCount
+= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedItemsCount();
333 QAction
* compareFilesAction
= actionCollection()->action("compare_files");
334 if (selectedUrlsCount
== 2) {
335 compareFilesAction
->setEnabled(isKompareInstalled());
337 compareFilesAction
->setEnabled(false);
340 emit
selectionChanged(selection
);
343 void DolphinMainWindow::slotWheelMoved(int wheelDelta
)
345 if (wheelDelta
> 0) {
352 void DolphinMainWindow::slotRequestItemInfo(const KFileItem
& item
)
354 emit
requestItemInfo(item
);
357 void DolphinMainWindow::updateHistory()
359 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
360 const int index
= urlNavigator
->historyIndex();
362 QAction
* backAction
= actionCollection()->action("go_back");
363 backAction
->setToolTip(i18nc("@info", "Go back"));
364 if (backAction
!= 0) {
365 backAction
->setEnabled(index
< urlNavigator
->historySize() - 1);
368 QAction
* forwardAction
= actionCollection()->action("go_forward");
369 forwardAction
->setToolTip(i18nc("@info", "Go forward"));
370 if (forwardAction
!= 0) {
371 forwardAction
->setEnabled(index
> 0);
375 void DolphinMainWindow::updateFilterBarAction(bool show
)
377 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
378 showFilterBarAction
->setChecked(show
);
381 void DolphinMainWindow::openNewMainWindow()
383 DolphinApplication::app()->createMainWindow()->show();
386 void DolphinMainWindow::openNewTab()
388 openNewTab(m_activeViewContainer
->url());
389 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
391 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
392 if (navigator
->isUrlEditable()) {
393 // if a new tab is opened and the URL is editable, assure that
394 // the user can edit the URL without manually setting the focus
395 navigator
->setFocus();
399 void DolphinMainWindow::openNewTab(const KUrl
& url
)
401 QWidget
* focusWidget
= QApplication::focusWidget();
403 if (m_viewTab
.count() == 1) {
404 // Only one view is open currently and hence no tab is shown at
405 // all. Before creating a tab for 'url', provide a tab for the current URL.
406 const KUrl currentUrl
= m_activeViewContainer
->url();
407 m_tabBar
->addTab(KIcon(KMimeType::iconNameForUrl(currentUrl
)),
408 squeezedText(tabName(currentUrl
)));
409 m_tabBar
->blockSignals(false);
412 m_tabBar
->addTab(KIcon(KMimeType::iconNameForUrl(url
)),
413 squeezedText(tabName(url
)));
416 viewTab
.splitter
= new QSplitter(this);
417 viewTab
.splitter
->setChildrenCollapsible(false);
418 viewTab
.primaryView
= new DolphinViewContainer(this, viewTab
.splitter
, url
);
419 viewTab
.primaryView
->setActive(false);
420 connectViewSignals(viewTab
.primaryView
);
421 viewTab
.primaryView
->view()->reload();
423 m_viewTab
.append(viewTab
);
425 actionCollection()->action("close_tab")->setEnabled(true);
427 // provide a split view, if the startup settings are set this way
428 const GeneralSettings
* generalSettings
= DolphinSettings::instance().generalSettings();
429 if (generalSettings
->splitView()) {
430 const int tabIndex
= m_viewTab
.count() - 1;
431 createSecondaryView(tabIndex
);
432 m_viewTab
[tabIndex
].secondaryView
->setActive(true);
433 m_viewTab
[tabIndex
].isPrimaryViewActive
= false;
436 if (focusWidget
!= 0) {
437 // The DolphinViewContainer grabbed the keyboard focus. As the tab is opened
438 // in background, assure that the previous focused widget gets the focus back.
439 focusWidget
->setFocus();
443 void DolphinMainWindow::activateNextTab()
445 if ((m_viewTab
.count() == 1) || (m_tabBar
->count() < 2)) {
449 const int tabIndex
= (m_tabBar
->currentIndex() + 1) % m_tabBar
->count();
450 m_tabBar
->setCurrentIndex(tabIndex
);
453 void DolphinMainWindow::activatePrevTab()
455 if ((m_viewTab
.count() == 1) || (m_tabBar
->count() < 2)) {
459 int tabIndex
= m_tabBar
->currentIndex() - 1;
460 if (tabIndex
== -1) {
461 tabIndex
= m_tabBar
->count() - 1;
463 m_tabBar
->setCurrentIndex(tabIndex
);
466 void DolphinMainWindow::openInNewTab()
468 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
469 if ((list
.count() == 1) && list
[0].isDir()) {
470 openNewTab(m_activeViewContainer
->view()->selectedUrls()[0]);
474 void DolphinMainWindow::openInNewWindow()
476 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
477 if ((list
.count() == 1) && list
[0].isDir()) {
478 DolphinMainWindow
* window
= DolphinApplication::app()->createMainWindow();
479 window
->changeUrl(m_activeViewContainer
->view()->selectedUrls()[0]);
484 void DolphinMainWindow::toggleActiveView()
486 if (m_viewTab
[m_tabIndex
].secondaryView
== 0) {
487 // only one view is available
491 Q_ASSERT(m_activeViewContainer
!= 0);
492 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
!= 0);
494 DolphinViewContainer
* left
= m_viewTab
[m_tabIndex
].primaryView
;
495 DolphinViewContainer
* right
= m_viewTab
[m_tabIndex
].secondaryView
;
496 setActiveViewContainer(m_activeViewContainer
== right
? left
: right
);
499 void DolphinMainWindow::showEvent(QShowEvent
* event
)
501 KXmlGuiWindow::showEvent(event
);
502 if (!event
->spontaneous()) {
503 m_activeViewContainer
->view()->setFocus();
507 void DolphinMainWindow::closeEvent(QCloseEvent
* event
)
509 DolphinSettings
& settings
= DolphinSettings::instance();
510 GeneralSettings
* generalSettings
= settings
.generalSettings();
512 // Find out if Dolphin is closed directly by the user or
513 // by the session manager because the session is closed
514 bool closedByUser
= true;
515 DolphinApplication
*application
= qobject_cast
<DolphinApplication
*>(qApp
);
516 if (application
&& application
->sessionSaving()) {
517 closedByUser
= false;
520 if ((m_viewTab
.count() > 1) && generalSettings
->confirmClosingMultipleTabs() && closedByUser
) {
521 // Ask the user if he really wants to quit and close all tabs.
522 // Open a confirmation dialog with 3 buttons:
523 // KDialog::Yes -> Quit
524 // KDialog::No -> Close only the current tab
525 // KDialog::Cancel -> do nothing
526 KDialog
*dialog
= new KDialog(this, Qt::Dialog
);
527 dialog
->setCaption(i18nc("@title:window", "Confirmation"));
528 dialog
->setButtons(KDialog::Yes
| KDialog::No
| KDialog::Cancel
);
529 dialog
->setModal(true);
530 dialog
->showButtonSeparator(true);
531 dialog
->setButtonGuiItem(KDialog::Yes
, KStandardGuiItem::quit());
532 dialog
->setButtonGuiItem(KDialog::No
, KGuiItem(i18n("C&lose Current Tab"), KIcon("tab-close")));
533 dialog
->setButtonGuiItem(KDialog::Cancel
, KStandardGuiItem::cancel());
534 dialog
->setDefaultButton(KDialog::Yes
);
536 bool doNotAskAgainCheckboxResult
= false;
538 const int result
= KMessageBox::createKMessageBox(dialog
,
539 QMessageBox::Warning
,
540 i18n("You have multiple tabs open in this window, are you sure you want to quit?"),
542 i18n("Do not ask again"),
543 &doNotAskAgainCheckboxResult
,
544 KMessageBox::Notify
);
546 if (doNotAskAgainCheckboxResult
) {
547 generalSettings
->setConfirmClosingMultipleTabs(false);
555 // Close only the current tab
563 generalSettings
->setFirstRun(false);
567 KXmlGuiWindow::closeEvent(event
);
570 void DolphinMainWindow::saveProperties(KConfigGroup
& group
)
572 const int tabCount
= m_viewTab
.count();
573 group
.writeEntry("Tab Count", tabCount
);
574 group
.writeEntry("Active Tab Index", m_tabBar
->currentIndex());
576 for (int i
= 0; i
< tabCount
; ++i
) {
577 const DolphinViewContainer
* cont
= m_viewTab
[i
].primaryView
;
578 group
.writeEntry(tabProperty("Primary URL", i
), cont
->url().url());
579 group
.writeEntry(tabProperty("Primary Editable", i
), cont
->isUrlEditable());
581 cont
= m_viewTab
[i
].secondaryView
;
583 group
.writeEntry(tabProperty("Secondary URL", i
), cont
->url().url());
584 group
.writeEntry(tabProperty("Secondary Editable", i
), cont
->isUrlEditable());
589 void DolphinMainWindow::readProperties(const KConfigGroup
& group
)
591 const int tabCount
= group
.readEntry("Tab Count", 1);
592 for (int i
= 0; i
< tabCount
; ++i
) {
593 DolphinViewContainer
* cont
= m_viewTab
[i
].primaryView
;
595 cont
->setUrl(group
.readEntry(tabProperty("Primary URL", i
)));
596 const bool editable
= group
.readEntry(tabProperty("Primary Editable", i
), false);
597 cont
->urlNavigator()->setUrlEditable(editable
);
599 cont
= m_viewTab
[i
].secondaryView
;
600 const QString secondaryUrl
= group
.readEntry(tabProperty("Secondary URL", i
));
601 if (!secondaryUrl
.isEmpty()) {
603 // a secondary view should be shown, but no one is available
604 // currently -> create a new view
606 cont
= m_viewTab
[i
].secondaryView
;
610 cont
->setUrl(secondaryUrl
);
611 const bool editable
= group
.readEntry(tabProperty("Secondary Editable", i
), false);
612 cont
->urlNavigator()->setUrlEditable(editable
);
613 } else if (cont
!= 0) {
614 // no secondary view should be shown, but the default setting shows
615 // one already -> close the view
619 // openNewTab() needs to be called only tabCount - 1 times
620 if (i
!= tabCount
- 1) {
625 const int index
= group
.readEntry("Active Tab Index", 0);
626 m_tabBar
->setCurrentIndex(index
);
629 void DolphinMainWindow::updateNewMenu()
631 m_newMenu
->setViewShowsHiddenFiles(activeViewContainer()->view()->showHiddenFiles());
632 m_newMenu
->slotCheckUpToDate();
633 m_newMenu
->setPopupFiles(activeViewContainer()->url());
636 void DolphinMainWindow::createDirectory()
638 m_newMenu
->setViewShowsHiddenFiles(activeViewContainer()->view()->showHiddenFiles());
639 m_newMenu
->setPopupFiles(activeViewContainer()->url());
640 m_newMenu
->createDirectory();
643 void DolphinMainWindow::quit()
648 void DolphinMainWindow::showErrorMessage(const QString
& message
)
650 if (!message
.isEmpty()) {
651 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
652 statusBar
->setMessage(message
, DolphinStatusBar::Error
);
656 void DolphinMainWindow::slotUndoAvailable(bool available
)
658 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
659 if (undoAction
!= 0) {
660 undoAction
->setEnabled(available
);
664 void DolphinMainWindow::restoreClosedTab(QAction
* action
)
666 if (action
->data().toBool()) {
667 // clear all actions except the "Empty Recently Closed Tabs"
668 // action and the separator
669 QList
<QAction
*> actions
= m_recentTabsMenu
->menu()->actions();
670 const int count
= actions
.size();
671 for (int i
= 2; i
< count
; ++i
) {
672 m_recentTabsMenu
->menu()->removeAction(actions
.at(i
));
675 const ClosedTab closedTab
= action
->data().value
<ClosedTab
>();
676 openNewTab(closedTab
.primaryUrl
);
677 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
679 if (closedTab
.isSplit
) {
680 // create secondary view
682 m_viewTab
[m_tabIndex
].secondaryView
->setUrl(closedTab
.secondaryUrl
);
685 m_recentTabsMenu
->removeAction(action
);
688 if (m_recentTabsMenu
->menu()->actions().count() == 2) {
689 m_recentTabsMenu
->setEnabled(false);
693 void DolphinMainWindow::slotUndoTextChanged(const QString
& text
)
695 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
696 if (undoAction
!= 0) {
697 undoAction
->setText(text
);
701 void DolphinMainWindow::undo()
704 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
705 KIO::FileUndoManager::self()->undo();
708 void DolphinMainWindow::cut()
710 m_activeViewContainer
->view()->cutSelectedItems();
713 void DolphinMainWindow::copy()
715 m_activeViewContainer
->view()->copySelectedItems();
718 void DolphinMainWindow::paste()
720 m_activeViewContainer
->view()->paste();
723 void DolphinMainWindow::updatePasteAction()
725 QAction
* pasteAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Paste
));
726 QPair
<bool, QString
> pasteInfo
= m_activeViewContainer
->view()->pasteInfo();
727 pasteAction
->setEnabled(pasteInfo
.first
);
728 pasteAction
->setText(pasteInfo
.second
);
731 void DolphinMainWindow::selectAll()
735 // if the URL navigator is editable and focused, select the whole
736 // URL instead of all items of the view
738 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
739 QLineEdit
* lineEdit
= urlNavigator
->editor()->lineEdit(); // krazy:exclude=qclasses
740 const bool selectUrl
= urlNavigator
->isUrlEditable() &&
741 lineEdit
->hasFocus();
743 lineEdit
->selectAll();
745 m_activeViewContainer
->view()->selectAll();
749 void DolphinMainWindow::invertSelection()
752 m_activeViewContainer
->view()->invertSelection();
755 void DolphinMainWindow::toggleSplitView()
757 if (m_viewTab
[m_tabIndex
].secondaryView
== 0) {
758 createSecondaryView(m_tabIndex
);
759 setActiveViewContainer(m_viewTab
[m_tabIndex
].secondaryView
);
760 } else if (m_activeViewContainer
== m_viewTab
[m_tabIndex
].secondaryView
) {
761 // remove secondary view
762 m_viewTab
[m_tabIndex
].secondaryView
->close();
763 m_viewTab
[m_tabIndex
].secondaryView
->deleteLater();
764 m_viewTab
[m_tabIndex
].secondaryView
= 0;
766 setActiveViewContainer(m_viewTab
[m_tabIndex
].primaryView
);
768 // The primary view is active and should be closed. Hence from a users point of view
769 // the content of the secondary view should be moved to the primary view.
770 // From an implementation point of view it is more efficient to close
771 // the primary view and exchange the internal pointers afterwards.
773 m_viewTab
[m_tabIndex
].primaryView
->close();
774 m_viewTab
[m_tabIndex
].primaryView
->deleteLater();
775 m_viewTab
[m_tabIndex
].primaryView
= m_viewTab
[m_tabIndex
].secondaryView
;
776 m_viewTab
[m_tabIndex
].secondaryView
= 0;
778 setActiveViewContainer(m_viewTab
[m_tabIndex
].primaryView
);
784 void DolphinMainWindow::reloadView()
787 m_activeViewContainer
->view()->reload();
790 void DolphinMainWindow::stopLoading()
794 void DolphinMainWindow::toggleFilterBarVisibility(bool show
)
796 m_activeViewContainer
->showFilterBar(show
);
799 void DolphinMainWindow::toggleEditLocation()
803 QAction
* action
= actionCollection()->action("editable_location");
804 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
805 urlNavigator
->setUrlEditable(action
->isChecked());
808 void DolphinMainWindow::replaceLocation()
810 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
811 navigator
->setUrlEditable(true);
812 navigator
->setFocus();
814 // select the whole text of the combo box editor
815 QLineEdit
* lineEdit
= navigator
->editor()->lineEdit(); // krazy:exclude=qclasses
816 const QString text
= lineEdit
->text();
817 lineEdit
->setSelection(0, text
.length());
820 void DolphinMainWindow::goBack()
823 m_activeViewContainer
->urlNavigator()->goBack();
826 void DolphinMainWindow::goForward()
829 m_activeViewContainer
->urlNavigator()->goForward();
832 void DolphinMainWindow::goUp()
835 m_activeViewContainer
->urlNavigator()->goUp();
838 void DolphinMainWindow::goBack(Qt::MouseButtons buttons
)
840 // The default case (left button pressed) is handled in goBack().
841 if (buttons
== Qt::MidButton
) {
842 KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigator();
843 openNewTab(urlNavigator
->historyUrl(urlNavigator
->historyIndex() + 1));
847 void DolphinMainWindow::goForward(Qt::MouseButtons buttons
)
849 // The default case (left button pressed) is handled in goForward().
850 if (buttons
== Qt::MidButton
) {
851 KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigator();
852 openNewTab(urlNavigator
->historyUrl(urlNavigator
->historyIndex() - 1));
856 void DolphinMainWindow::goUp(Qt::MouseButtons buttons
)
858 // The default case (left button pressed) is handled in goUp().
859 if (buttons
== Qt::MidButton
) {
860 openNewTab(activeViewContainer()->url().upUrl());
864 void DolphinMainWindow::goHome()
867 m_activeViewContainer
->urlNavigator()->goHome();
870 void DolphinMainWindow::compareFiles()
872 // The method is only invoked if exactly 2 files have
873 // been selected. The selected files may be:
874 // - both in the primary view
875 // - both in the secondary view
876 // - one in the primary view and the other in the secondary
878 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
!= 0);
882 KUrl::List urls
= m_viewTab
[m_tabIndex
].primaryView
->view()->selectedUrls();
884 switch (urls
.count()) {
886 Q_ASSERT(m_viewTab
[m_tabIndex
].secondaryView
!= 0);
887 urls
= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedUrls();
888 Q_ASSERT(urls
.count() == 2);
896 Q_ASSERT(m_viewTab
[m_tabIndex
].secondaryView
!= 0);
897 urls
= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedUrls();
898 Q_ASSERT(urls
.count() == 1);
910 // may not happen: compareFiles may only get invoked if 2
911 // files are selected
916 QString
command("kompare -c \"");
917 command
.append(urlA
.pathOrUrl());
918 command
.append("\" \"");
919 command
.append(urlB
.pathOrUrl());
920 command
.append('\"');
921 KRun::runCommand(command
, "Kompare", "kompare", this);
924 void DolphinMainWindow::toggleShowMenuBar()
926 const bool visible
= menuBar()->isVisible();
927 menuBar()->setVisible(!visible
);
930 void DolphinMainWindow::openTerminal()
932 QString
dir(QDir::homePath());
934 // If the given directory is not local, it can still be the URL of an
935 // ioslave using UDS_LOCAL_PATH which to be converted first.
936 KUrl url
= KIO::NetAccess::mostLocalUrl(m_activeViewContainer
->url(), this);
938 //If the URL is local after the above conversion, set the directory.
939 if (url
.isLocalFile()) {
940 dir
= url
.toLocalFile();
943 KToolInvocation::invokeTerminal(QString(), dir
);
946 void DolphinMainWindow::editSettings()
948 if (m_settingsDialog
== 0) {
949 const KUrl
& url
= activeViewContainer()->url();
950 m_settingsDialog
= new DolphinSettingsDialog(url
, this);
951 m_settingsDialog
->setAttribute(Qt::WA_DeleteOnClose
);
952 m_settingsDialog
->show();
954 m_settingsDialog
->raise();
958 void DolphinMainWindow::setActiveTab(int index
)
960 Q_ASSERT(index
>= 0);
961 Q_ASSERT(index
< m_viewTab
.count());
962 if (index
== m_tabIndex
) {
966 // hide current tab content
967 ViewTab
& hiddenTab
= m_viewTab
[m_tabIndex
];
968 hiddenTab
.isPrimaryViewActive
= hiddenTab
.primaryView
->isActive();
969 hiddenTab
.primaryView
->setActive(false);
970 if (hiddenTab
.secondaryView
!= 0) {
971 hiddenTab
.secondaryView
->setActive(false);
973 QSplitter
* splitter
= m_viewTab
[m_tabIndex
].splitter
;
975 m_centralWidgetLayout
->removeWidget(splitter
);
977 // show active tab content
980 ViewTab
& viewTab
= m_viewTab
[index
];
981 m_centralWidgetLayout
->addWidget(viewTab
.splitter
, 1);
982 viewTab
.primaryView
->show();
983 if (viewTab
.secondaryView
!= 0) {
984 viewTab
.secondaryView
->show();
986 viewTab
.splitter
->show();
988 setActiveViewContainer(viewTab
.isPrimaryViewActive
? viewTab
.primaryView
:
989 viewTab
.secondaryView
);
992 void DolphinMainWindow::closeTab()
994 closeTab(m_tabBar
->currentIndex());
997 void DolphinMainWindow::closeTab(int index
)
999 Q_ASSERT(index
>= 0);
1000 Q_ASSERT(index
< m_viewTab
.count());
1001 if (m_viewTab
.count() == 1) {
1002 // the last tab may never get closed
1006 if (index
== m_tabIndex
) {
1007 // The tab that should be closed is the active tab. Activate the
1008 // previous tab before closing the tab.
1009 m_tabBar
->setCurrentIndex((index
> 0) ? index
- 1 : 1);
1011 rememberClosedTab(index
);
1014 m_viewTab
[index
].primaryView
->deleteLater();
1015 if (m_viewTab
[index
].secondaryView
!= 0) {
1016 m_viewTab
[index
].secondaryView
->deleteLater();
1018 m_viewTab
[index
].splitter
->deleteLater();
1019 m_viewTab
.erase(m_viewTab
.begin() + index
);
1021 m_tabBar
->blockSignals(true);
1022 m_tabBar
->removeTab(index
);
1024 if (m_tabIndex
> index
) {
1026 Q_ASSERT(m_tabIndex
>= 0);
1029 // if only one tab is left, also remove the tab entry so that
1030 // closing the last tab is not possible
1031 if (m_viewTab
.count() == 1) {
1032 m_tabBar
->removeTab(0);
1033 actionCollection()->action("close_tab")->setEnabled(false);
1035 m_tabBar
->blockSignals(false);
1039 void DolphinMainWindow::openTabContextMenu(int index
, const QPoint
& pos
)
1043 QAction
* newTabAction
= menu
.addAction(KIcon("tab-new"), i18nc("@action:inmenu", "New Tab"));
1044 newTabAction
->setShortcut(actionCollection()->action("new_tab")->shortcut());
1046 QAction
* closeOtherTabsAction
= menu
.addAction(KIcon("tab-close-other"), i18nc("@action:inmenu", "Close Other Tabs"));
1048 QAction
* closeTabAction
= menu
.addAction(KIcon("tab-close"), i18nc("@action:inmenu", "Close Tab"));
1049 closeTabAction
->setShortcut(actionCollection()->action("close_tab")->shortcut());
1050 QAction
* selectedAction
= menu
.exec(pos
);
1051 if (selectedAction
== newTabAction
) {
1052 const ViewTab
& tab
= m_viewTab
[index
];
1053 Q_ASSERT(tab
.primaryView
!= 0);
1054 const KUrl url
= (tab
.secondaryView
!= 0) && tab
.secondaryView
->isActive() ?
1055 tab
.secondaryView
->url() : tab
.primaryView
->url();
1057 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
1058 } else if (selectedAction
== closeOtherTabsAction
) {
1059 const int count
= m_tabBar
->count();
1060 for (int i
= 0; i
< index
; ++i
) {
1063 for (int i
= index
+ 1; i
< count
; ++i
) {
1066 } else if (selectedAction
== closeTabAction
) {
1071 void DolphinMainWindow::handlePlacesClick(const KUrl
& url
, Qt::MouseButtons buttons
)
1073 if (buttons
& Qt::MidButton
) {
1075 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
1081 void DolphinMainWindow::slotTestCanDecode(const QDragMoveEvent
* event
, bool& canDecode
)
1083 canDecode
= KUrl::List::canDecode(event
->mimeData());
1086 void DolphinMainWindow::searchItems()
1089 const KUrl nepomukSearchUrl
= m_searchOptionsConfigurator
->nepomukSearchUrl();
1090 m_activeViewContainer
->setUrl(nepomukSearchUrl
);
1094 void DolphinMainWindow::slotTabMoved(int from
, int to
)
1096 m_viewTab
.move(from
, to
);
1097 m_tabIndex
= m_tabBar
->currentIndex();
1100 void DolphinMainWindow::showSearchOptions()
1103 m_searchOptionsConfigurator
->show();
1107 void DolphinMainWindow::init()
1109 DolphinSettings
& settings
= DolphinSettings::instance();
1111 // Check whether Dolphin runs the first time. If yes then
1112 // a proper default window size is given at the end of DolphinMainWindow::init().
1113 GeneralSettings
* generalSettings
= settings
.generalSettings();
1114 const bool firstRun
= generalSettings
->firstRun();
1116 generalSettings
->setViewPropsTimestamp(QDateTime::currentDateTime());
1119 setAcceptDrops(true);
1121 m_viewTab
[m_tabIndex
].splitter
= new QSplitter(this);
1122 m_viewTab
[m_tabIndex
].splitter
->setChildrenCollapsible(false);
1126 const KUrl
& homeUrl
= generalSettings
->homeUrl();
1127 setUrlAsCaption(homeUrl
);
1128 m_actionHandler
= new DolphinViewActionHandler(actionCollection(), this);
1129 connect(m_actionHandler
, SIGNAL(actionBeingHandled()), SLOT(clearStatusBar()));
1130 connect(m_actionHandler
, SIGNAL(createDirectory()), SLOT(createDirectory()));
1131 ViewProperties
props(homeUrl
);
1132 m_viewTab
[m_tabIndex
].primaryView
= new DolphinViewContainer(this,
1133 m_viewTab
[m_tabIndex
].splitter
,
1136 m_activeViewContainer
= m_viewTab
[m_tabIndex
].primaryView
;
1137 connectViewSignals(m_activeViewContainer
);
1138 DolphinView
* view
= m_activeViewContainer
->view();
1140 m_activeViewContainer
->show();
1141 m_actionHandler
->setCurrentView(view
);
1143 m_remoteEncoding
= new DolphinRemoteEncoding(this, m_actionHandler
);
1144 connect(this, SIGNAL(urlChanged(const KUrl
&)),
1145 m_remoteEncoding
, SLOT(slotAboutToOpenUrl()));
1148 m_searchOptionsConfigurator
= new DolphinSearchOptionsConfigurator(this);
1149 m_searchOptionsConfigurator
->hide();
1150 connect(m_searchOptionsConfigurator
, SIGNAL(searchOptionsChanged()),
1151 this, SLOT(searchItems()));
1152 connect(this, SIGNAL(urlChanged(KUrl
)), m_searchOptionsConfigurator
, SLOT(setDirectory(KUrl
)));
1155 m_tabBar
= new KTabBar(this);
1156 m_tabBar
->setMovable(true);
1157 m_tabBar
->setTabsClosable(true);
1158 connect(m_tabBar
, SIGNAL(currentChanged(int)),
1159 this, SLOT(setActiveTab(int)));
1160 connect(m_tabBar
, SIGNAL(tabCloseRequested(int)),
1161 this, SLOT(closeTab(int)));
1162 connect(m_tabBar
, SIGNAL(contextMenu(int, const QPoint
&)),
1163 this, SLOT(openTabContextMenu(int, const QPoint
&)));
1164 connect(m_tabBar
, SIGNAL(newTabRequest()),
1165 this, SLOT(openNewTab()));
1166 connect(m_tabBar
, SIGNAL(testCanDecode(const QDragMoveEvent
*, bool&)),
1167 this, SLOT(slotTestCanDecode(const QDragMoveEvent
*, bool&)));
1168 connect(m_tabBar
, SIGNAL(wheelDelta(int)),
1169 this, SLOT(slotWheelMoved(int)));
1170 connect(m_tabBar
, SIGNAL(mouseMiddleClick(int)),
1171 this, SLOT(closeTab(int)));
1172 connect(m_tabBar
, SIGNAL(tabMoved(int, int)),
1173 this, SLOT(slotTabMoved(int, int)));
1175 m_tabBar
->blockSignals(true); // signals get unblocked after at least 2 tabs are open
1177 QWidget
* centralWidget
= new QWidget(this);
1178 m_centralWidgetLayout
= new QVBoxLayout(centralWidget
);
1179 m_centralWidgetLayout
->setSpacing(0);
1180 m_centralWidgetLayout
->setMargin(0);
1182 m_centralWidgetLayout
->addWidget(m_searchOptionsConfigurator
);
1184 m_centralWidgetLayout
->addWidget(m_tabBar
);
1185 m_centralWidgetLayout
->addWidget(m_viewTab
[m_tabIndex
].splitter
, 1);
1187 setCentralWidget(centralWidget
);
1189 emit
urlChanged(homeUrl
);
1191 setupGUI(Keys
| Save
| Create
| ToolBar
);
1193 m_searchBox
->setParent(toolBar("searchToolBar"));
1194 m_searchBox
->show();
1195 connect(m_searchBox
, SIGNAL(requestSearchOptions()),
1196 this, SLOT(showSearchOptions()));
1198 connect(m_searchBox
, SIGNAL(searchTextChanged(QString
)),
1199 m_searchOptionsConfigurator
, SLOT(setCustomSearchQuery(QString
)));
1202 stateChanged("new_file");
1204 QClipboard
* clipboard
= QApplication::clipboard();
1205 connect(clipboard
, SIGNAL(dataChanged()),
1206 this, SLOT(updatePasteAction()));
1207 updatePasteAction();
1210 if (generalSettings
->splitView()) {
1213 updateViewActions();
1215 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
1216 showFilterBarAction
->setChecked(generalSettings
->filterBar());
1219 // assure a proper default size if Dolphin runs the first time
1223 m_showMenuBar
->setChecked(!menuBar()->isHidden()); // workaround for bug #171080
1226 void DolphinMainWindow::setActiveViewContainer(DolphinViewContainer
* viewContainer
)
1228 Q_ASSERT(viewContainer
!= 0);
1229 Q_ASSERT((viewContainer
== m_viewTab
[m_tabIndex
].primaryView
) ||
1230 (viewContainer
== m_viewTab
[m_tabIndex
].secondaryView
));
1231 if (m_activeViewContainer
== viewContainer
) {
1235 m_activeViewContainer
->setActive(false);
1236 m_activeViewContainer
= viewContainer
;
1238 // Activating the view container might trigger a recursive setActiveViewContainer() call
1239 // inside DolphinMainWindow::toggleActiveView() when having a split view. Temporary
1240 // disconnect the activated() signal in this case:
1241 disconnect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1242 m_activeViewContainer
->setActive(true);
1243 connect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1245 m_actionHandler
->setCurrentView(viewContainer
->view());
1248 updateEditActions();
1249 updateViewActions();
1252 const KUrl
& url
= m_activeViewContainer
->url();
1253 setUrlAsCaption(url
);
1254 if (m_viewTab
.count() > 1 && m_viewTab
[m_tabIndex
].secondaryView
!= 0) {
1255 m_tabBar
->setTabText(m_tabIndex
, tabName(url
));
1256 m_tabBar
->setTabIcon(m_tabIndex
, KIcon(KMimeType::iconNameForUrl(url
)));
1259 emit
urlChanged(url
);
1262 void DolphinMainWindow::setupActions()
1264 // setup 'File' menu
1265 m_newMenu
= new DolphinNewMenu(this, this);
1266 KMenu
* menu
= m_newMenu
->menu();
1267 menu
->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1268 menu
->setIcon(KIcon("document-new"));
1269 connect(menu
, SIGNAL(aboutToShow()),
1270 this, SLOT(updateNewMenu()));
1272 KAction
* newWindow
= actionCollection()->addAction("new_window");
1273 newWindow
->setIcon(KIcon("window-new"));
1274 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
1275 newWindow
->setShortcut(Qt::CTRL
| Qt::Key_N
);
1276 connect(newWindow
, SIGNAL(triggered()), this, SLOT(openNewMainWindow()));
1278 KAction
* newTab
= actionCollection()->addAction("new_tab");
1279 newTab
->setIcon(KIcon("tab-new"));
1280 newTab
->setText(i18nc("@action:inmenu File", "New Tab"));
1281 newTab
->setShortcut(KShortcut(Qt::CTRL
| Qt::Key_T
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_N
));
1282 connect(newTab
, SIGNAL(triggered()), this, SLOT(openNewTab()));
1284 KAction
* closeTab
= actionCollection()->addAction("close_tab");
1285 closeTab
->setIcon(KIcon("tab-close"));
1286 closeTab
->setText(i18nc("@action:inmenu File", "Close Tab"));
1287 closeTab
->setShortcut(Qt::CTRL
| Qt::Key_W
);
1288 closeTab
->setEnabled(false);
1289 connect(closeTab
, SIGNAL(triggered()), this, SLOT(closeTab()));
1291 KStandardAction::quit(this, SLOT(quit()), actionCollection());
1293 // setup 'Edit' menu
1294 KStandardAction::undo(this,
1296 actionCollection());
1298 // need to remove shift+del from cut action, else the shortcut for deletejob
1300 KAction
* cut
= KStandardAction::cut(this, SLOT(cut()), actionCollection());
1301 KShortcut cutShortcut
= cut
->shortcut();
1302 cutShortcut
.remove(Qt::SHIFT
+ Qt::Key_Delete
, KShortcut::KeepEmpty
);
1303 cut
->setShortcut(cutShortcut
);
1304 KStandardAction::copy(this, SLOT(copy()), actionCollection());
1305 KAction
* paste
= KStandardAction::paste(this, SLOT(paste()), actionCollection());
1306 // The text of the paste-action is modified dynamically by Dolphin
1307 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1308 // due to the long text, the text "Paste" is used:
1309 paste
->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1311 KAction
* selectAll
= actionCollection()->addAction("select_all");
1312 selectAll
->setText(i18nc("@action:inmenu Edit", "Select All"));
1313 selectAll
->setShortcut(Qt::CTRL
+ Qt::Key_A
);
1314 connect(selectAll
, SIGNAL(triggered()), this, SLOT(selectAll()));
1316 KAction
* invertSelection
= actionCollection()->addAction("invert_selection");
1317 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1318 invertSelection
->setShortcut(Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
1319 connect(invertSelection
, SIGNAL(triggered()), this, SLOT(invertSelection()));
1321 // setup 'View' menu
1322 // (note that most of it is set up in DolphinViewActionHandler)
1324 KAction
* split
= actionCollection()->addAction("split_view");
1325 split
->setShortcut(Qt::Key_F3
);
1326 updateSplitAction();
1327 connect(split
, SIGNAL(triggered()), this, SLOT(toggleSplitView()));
1329 KAction
* reload
= actionCollection()->addAction("reload");
1330 reload
->setText(i18nc("@action:inmenu View", "Reload"));
1331 reload
->setShortcut(Qt::Key_F5
);
1332 reload
->setIcon(KIcon("view-refresh"));
1333 connect(reload
, SIGNAL(triggered()), this, SLOT(reloadView()));
1335 KAction
* stop
= actionCollection()->addAction("stop");
1336 stop
->setText(i18nc("@action:inmenu View", "Stop"));
1337 stop
->setToolTip(i18nc("@info", "Stop loading"));
1338 stop
->setIcon(KIcon("process-stop"));
1339 connect(stop
, SIGNAL(triggered()), this, SLOT(stopLoading()));
1341 KToggleAction
* showFullLocation
= actionCollection()->add
<KToggleAction
>("editable_location");
1342 showFullLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1343 showFullLocation
->setShortcut(Qt::CTRL
| Qt::Key_L
);
1344 connect(showFullLocation
, SIGNAL(triggered()), this, SLOT(toggleEditLocation()));
1346 KAction
* replaceLocation
= actionCollection()->addAction("replace_location");
1347 replaceLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1348 replaceLocation
->setShortcut(Qt::Key_F6
);
1349 connect(replaceLocation
, SIGNAL(triggered()), this, SLOT(replaceLocation()));
1352 KAction
* backAction
= KStandardAction::back(this, SLOT(goBack()), actionCollection());
1353 connect(backAction
, SIGNAL(triggered(Qt::MouseButtons
, Qt::KeyboardModifiers
)), this, SLOT(goBack(Qt::MouseButtons
)));
1354 KShortcut backShortcut
= backAction
->shortcut();
1355 backShortcut
.setAlternate(Qt::Key_Backspace
);
1356 backAction
->setShortcut(backShortcut
);
1358 m_recentTabsMenu
= new KActionMenu(i18n("Recently Closed Tabs"), this);
1359 m_recentTabsMenu
->setIcon(KIcon("edit-undo"));
1360 actionCollection()->addAction("closed_tabs", m_recentTabsMenu
);
1361 connect(m_recentTabsMenu
->menu(), SIGNAL(triggered(QAction
*)),
1362 this, SLOT(restoreClosedTab(QAction
*)));
1364 QAction
* action
= new QAction("Empty Recently Closed Tabs", m_recentTabsMenu
);
1365 action
->setIcon(KIcon("edit-clear-list"));
1366 action
->setData(QVariant::fromValue(true));
1367 m_recentTabsMenu
->addAction(action
);
1368 m_recentTabsMenu
->addSeparator();
1369 m_recentTabsMenu
->setEnabled(false);
1371 KAction
* forwardAction
= KStandardAction::forward(this, SLOT(goForward()), actionCollection());
1372 connect(forwardAction
, SIGNAL(triggered(Qt::MouseButtons
, Qt::KeyboardModifiers
)), this, SLOT(goForward(Qt::MouseButtons
)));
1374 KAction
* upAction
= KStandardAction::up(this, SLOT(goUp()), actionCollection());
1375 connect(upAction
, SIGNAL(triggered(Qt::MouseButtons
, Qt::KeyboardModifiers
)), this, SLOT(goUp(Qt::MouseButtons
)));
1377 KStandardAction::home(this, SLOT(goHome()), actionCollection());
1379 // setup 'Tools' menu
1380 KToggleAction
* showSearchBar
= actionCollection()->add
<KToggleAction
>("show_search_bar");
1381 showSearchBar
->setText(i18nc("@action:inmenu Tools", "Show Search Bar"));
1382 showSearchBar
->setShortcut(Qt::CTRL
| Qt::Key_S
);
1383 connect(showSearchBar
, SIGNAL(triggered(bool)), this, SLOT(toggleFilterBarVisibility(bool)));
1385 KToggleAction
* showFilterBar
= actionCollection()->add
<KToggleAction
>("show_filter_bar");
1386 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Show Filter Bar"));
1387 showFilterBar
->setIcon(KIcon("view-filter"));
1388 showFilterBar
->setShortcut(Qt::CTRL
| Qt::Key_I
);
1389 connect(showFilterBar
, SIGNAL(triggered(bool)), this, SLOT(toggleFilterBarVisibility(bool)));
1391 KAction
* compareFiles
= actionCollection()->addAction("compare_files");
1392 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1393 compareFiles
->setIcon(KIcon("kompare"));
1394 compareFiles
->setEnabled(false);
1395 connect(compareFiles
, SIGNAL(triggered()), this, SLOT(compareFiles()));
1397 KAction
* openTerminal
= actionCollection()->addAction("open_terminal");
1398 openTerminal
->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
1399 openTerminal
->setIcon(KIcon("utilities-terminal"));
1400 openTerminal
->setShortcut(Qt::SHIFT
| Qt::Key_F4
);
1401 connect(openTerminal
, SIGNAL(triggered()), this, SLOT(openTerminal()));
1403 // setup 'Settings' menu
1404 m_showMenuBar
= KStandardAction::showMenubar(this, SLOT(toggleShowMenuBar()), actionCollection());
1405 KStandardAction::preferences(this, SLOT(editSettings()), actionCollection());
1407 // not in menu actions
1408 KAction
* activateNextTab
= actionCollection()->addAction("activate_next_tab");
1409 activateNextTab
->setText(i18nc("@action:inmenu", "Activate Next Tab"));
1410 connect(activateNextTab
, SIGNAL(triggered()), SLOT(activateNextTab()));
1411 activateNextTab
->setShortcuts(QApplication::isRightToLeft() ? KStandardShortcut::tabPrev() :
1412 KStandardShortcut::tabNext());
1414 KAction
* activatePrevTab
= actionCollection()->addAction("activate_prev_tab");
1415 activatePrevTab
->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
1416 connect(activatePrevTab
, SIGNAL(triggered()), SLOT(activatePrevTab()));
1417 activatePrevTab
->setShortcuts(QApplication::isRightToLeft() ? KStandardShortcut::tabNext() :
1418 KStandardShortcut::tabPrev());
1421 KAction
* openInNewTab
= actionCollection()->addAction("open_in_new_tab");
1422 openInNewTab
->setText(i18nc("@action:inmenu", "Open in New Tab"));
1423 openInNewTab
->setIcon(KIcon("tab-new"));
1424 connect(openInNewTab
, SIGNAL(triggered()), this, SLOT(openInNewTab()));
1426 KAction
* openInNewWindow
= actionCollection()->addAction("open_in_new_window");
1427 openInNewWindow
->setText(i18nc("@action:inmenu", "Open in New Window"));
1428 openInNewWindow
->setIcon(KIcon("window-new"));
1429 connect(openInNewWindow
, SIGNAL(triggered()), this, SLOT(openInNewWindow()));
1432 m_searchBox
= new DolphinSearchBox(this);
1433 connect(m_searchBox
, SIGNAL(search(QString
)), this, SLOT(searchItems()));
1435 KAction
* search
= new KAction(this);
1436 actionCollection()->addAction("search_bar", search
);
1437 search
->setText(i18nc("@action:inmenu", "Search Bar"));
1438 search
->setDefaultWidget(m_searchBox
);
1439 search
->setShortcutConfigurable(false);
1442 void DolphinMainWindow::setupDockWidgets()
1444 // setup "Information"
1445 QDockWidget
* infoDock
= new QDockWidget(i18nc("@title:window", "Information"));
1446 infoDock
->setObjectName("infoDock");
1447 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1448 Panel
* infoPanel
= new InformationPanel(infoDock
);
1449 connect(infoPanel
, SIGNAL(urlActivated(KUrl
)), this, SLOT(handleUrl(KUrl
)));
1450 infoDock
->setWidget(infoPanel
);
1452 KAction
* infoAction
= new KAction(this);
1453 infoAction
->setText(i18nc("@title:window", "Information"));
1454 infoAction
->setShortcut(Qt::Key_F11
);
1455 infoAction
->setIcon(KIcon("dialog-information"));
1456 actionCollection()->addAction("show_info_panel", infoAction
);
1457 connect(infoAction
, SIGNAL(triggered()), infoDock
->toggleViewAction(), SLOT(trigger()));
1459 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
1460 connect(this, SIGNAL(urlChanged(KUrl
)),
1461 infoPanel
, SLOT(setUrl(KUrl
)));
1462 connect(this, SIGNAL(selectionChanged(KFileItemList
)),
1463 infoPanel
, SLOT(setSelection(KFileItemList
)));
1464 connect(this, SIGNAL(requestItemInfo(KFileItem
)),
1465 infoPanel
, SLOT(requestDelayedItemInfo(KFileItem
)));
1468 QDockWidget
* foldersDock
= new QDockWidget(i18nc("@title:window", "Folders"));
1469 foldersDock
->setObjectName("foldersDock");
1470 foldersDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1471 FoldersPanel
* foldersPanel
= new FoldersPanel(foldersDock
);
1472 foldersDock
->setWidget(foldersPanel
);
1474 KAction
* foldersAction
= new KAction(this);
1475 foldersAction
->setText(i18nc("@title:window", "Folders"));
1476 foldersAction
->setShortcut(Qt::Key_F7
);
1477 foldersAction
->setIcon(KIcon("folder"));
1478 actionCollection()->addAction("show_folders_panel", foldersAction
);
1479 connect(foldersAction
, SIGNAL(triggered()), foldersDock
->toggleViewAction(), SLOT(trigger()));
1481 addDockWidget(Qt::LeftDockWidgetArea
, foldersDock
);
1482 connect(this, SIGNAL(urlChanged(KUrl
)),
1483 foldersPanel
, SLOT(setUrl(KUrl
)));
1484 connect(foldersPanel
, SIGNAL(changeUrl(KUrl
, Qt::MouseButtons
)),
1485 this, SLOT(handlePlacesClick(KUrl
, Qt::MouseButtons
)));
1489 QDockWidget
* terminalDock
= new QDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
1490 terminalDock
->setObjectName("terminalDock");
1491 terminalDock
->setAllowedAreas(Qt::TopDockWidgetArea
| Qt::BottomDockWidgetArea
);
1492 Panel
* terminalPanel
= new TerminalPanel(terminalDock
);
1493 terminalDock
->setWidget(terminalPanel
);
1495 connect(terminalPanel
, SIGNAL(hideTerminalPanel()), terminalDock
, SLOT(hide()));
1497 KAction
* terminalAction
= new KAction(this);
1498 terminalAction
->setText(i18nc("@title:window Shell terminal", "Terminal"));
1499 terminalAction
->setShortcut(Qt::Key_F4
);
1500 terminalAction
->setIcon(KIcon("utilities-terminal"));
1501 actionCollection()->addAction("show_terminal_panel", terminalAction
);
1502 connect(terminalAction
, SIGNAL(triggered()), terminalDock
->toggleViewAction(), SLOT(trigger()));
1504 addDockWidget(Qt::BottomDockWidgetArea
, terminalDock
);
1505 connect(this, SIGNAL(urlChanged(KUrl
)),
1506 terminalPanel
, SLOT(setUrl(KUrl
)));
1509 const bool firstRun
= DolphinSettings::instance().generalSettings()->firstRun();
1511 foldersDock
->hide();
1513 terminalDock
->hide();
1518 QDockWidget
* placesDock
= new QDockWidget(i18nc("@title:window", "Places"));
1519 placesDock
->setObjectName("placesDock");
1520 placesDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1522 PlacesPanel
* placesPanel
= new PlacesPanel(placesDock
);
1523 placesDock
->setWidget(placesPanel
);
1524 placesPanel
->setModel(DolphinSettings::instance().placesModel());
1525 placesPanel
->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff
);
1527 KAction
* placesAction
= new KAction(this);
1528 placesAction
->setText(i18nc("@title:window", "Places"));
1529 placesAction
->setShortcut(Qt::Key_F9
);
1530 placesAction
->setIcon(KIcon("bookmarks"));
1531 actionCollection()->addAction("show_places_panel", placesAction
);
1532 connect(placesAction
, SIGNAL(triggered()), placesDock
->toggleViewAction(), SLOT(trigger()));
1534 addDockWidget(Qt::LeftDockWidgetArea
, placesDock
);
1535 connect(placesPanel
, SIGNAL(urlChanged(KUrl
, Qt::MouseButtons
)),
1536 this, SLOT(handlePlacesClick(KUrl
, Qt::MouseButtons
)));
1537 connect(this, SIGNAL(urlChanged(KUrl
)),
1538 placesPanel
, SLOT(setUrl(KUrl
)));
1541 void DolphinMainWindow::updateEditActions()
1543 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
1544 if (list
.isEmpty()) {
1545 stateChanged("has_no_selection");
1547 stateChanged("has_selection");
1549 KActionCollection
* col
= actionCollection();
1550 QAction
* renameAction
= col
->action("rename");
1551 QAction
* moveToTrashAction
= col
->action("move_to_trash");
1552 QAction
* deleteAction
= col
->action("delete");
1553 QAction
* cutAction
= col
->action(KStandardAction::name(KStandardAction::Cut
));
1554 QAction
* deleteWithTrashShortcut
= col
->action("delete_shortcut"); // see DolphinViewActionHandler
1556 KFileItemListProperties
capabilities(list
);
1557 const bool enableMoveToTrash
= capabilities
.isLocal() && capabilities
.supportsMoving();
1559 renameAction
->setEnabled(capabilities
.supportsMoving());
1560 moveToTrashAction
->setEnabled(enableMoveToTrash
);
1561 deleteAction
->setEnabled(capabilities
.supportsDeleting());
1562 deleteWithTrashShortcut
->setEnabled(capabilities
.supportsDeleting() && !enableMoveToTrash
);
1563 cutAction
->setEnabled(capabilities
.supportsMoving());
1565 updatePasteAction();
1568 void DolphinMainWindow::updateViewActions()
1570 m_actionHandler
->updateViewActions();
1572 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
1573 showFilterBarAction
->setChecked(m_activeViewContainer
->isFilterBarVisible());
1575 updateSplitAction();
1577 QAction
* editableLocactionAction
= actionCollection()->action("editable_location");
1578 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
1579 editableLocactionAction
->setChecked(urlNavigator
->isUrlEditable());
1582 void DolphinMainWindow::updateGoActions()
1584 QAction
* goUpAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Up
));
1585 const KUrl
& currentUrl
= m_activeViewContainer
->url();
1586 goUpAction
->setEnabled(currentUrl
.upUrl() != currentUrl
);
1589 void DolphinMainWindow::rememberClosedTab(int index
)
1591 KMenu
* tabsMenu
= m_recentTabsMenu
->menu();
1593 const QString primaryPath
= m_viewTab
[index
].primaryView
->url().path();
1594 const QString iconName
= KMimeType::iconNameForUrl(primaryPath
);
1596 QAction
* action
= new QAction(squeezedText(primaryPath
), tabsMenu
);
1598 ClosedTab closedTab
;
1599 closedTab
.primaryUrl
= m_viewTab
[index
].primaryView
->url();
1601 if (m_viewTab
[index
].secondaryView
!= 0) {
1602 closedTab
.secondaryUrl
= m_viewTab
[index
].secondaryView
->url();
1603 closedTab
.isSplit
= true;
1605 closedTab
.isSplit
= false;
1608 action
->setData(QVariant::fromValue(closedTab
));
1609 action
->setIcon(KIcon(iconName
));
1611 // add the closed tab menu entry after the separator and
1612 // "Empty Recently Closed Tabs" entry
1613 if (tabsMenu
->actions().size() == 2) {
1614 tabsMenu
->addAction(action
);
1616 tabsMenu
->insertAction(tabsMenu
->actions().at(2), action
);
1619 // assure that only up to 8 closed tabs are shown in the menu
1620 if (tabsMenu
->actions().size() > 8) {
1621 tabsMenu
->removeAction(tabsMenu
->actions().last());
1623 actionCollection()->action("closed_tabs")->setEnabled(true);
1624 KAcceleratorManager::manage(tabsMenu
);
1627 void DolphinMainWindow::clearStatusBar()
1629 m_activeViewContainer
->statusBar()->clear();
1632 void DolphinMainWindow::connectViewSignals(DolphinViewContainer
* container
)
1634 connect(container
, SIGNAL(showFilterBarChanged(bool)),
1635 this, SLOT(updateFilterBarAction(bool)));
1637 DolphinView
* view
= container
->view();
1638 connect(view
, SIGNAL(selectionChanged(KFileItemList
)),
1639 this, SLOT(slotSelectionChanged(KFileItemList
)));
1640 connect(view
, SIGNAL(requestItemInfo(KFileItem
)),
1641 this, SLOT(slotRequestItemInfo(KFileItem
)));
1642 connect(view
, SIGNAL(activated()),
1643 this, SLOT(toggleActiveView()));
1644 connect(view
, SIGNAL(tabRequested(const KUrl
&)),
1645 this, SLOT(openNewTab(const KUrl
&)));
1647 const KUrlNavigator
* navigator
= container
->urlNavigator();
1648 connect(navigator
, SIGNAL(urlChanged(const KUrl
&)),
1649 this, SLOT(changeUrl(const KUrl
&)));
1650 connect(navigator
, SIGNAL(historyChanged()),
1651 this, SLOT(updateHistory()));
1652 connect(navigator
, SIGNAL(editableStateChanged(bool)),
1653 this, SLOT(slotEditableStateChanged(bool)));
1656 void DolphinMainWindow::updateSplitAction()
1658 QAction
* splitAction
= actionCollection()->action("split_view");
1659 if (m_viewTab
[m_tabIndex
].secondaryView
!= 0) {
1660 if (m_activeViewContainer
== m_viewTab
[m_tabIndex
].secondaryView
) {
1661 splitAction
->setText(i18nc("@action:intoolbar Close right view", "Close"));
1662 splitAction
->setToolTip(i18nc("@info", "Close right view"));
1663 splitAction
->setIcon(KIcon("view-right-close"));
1665 splitAction
->setText(i18nc("@action:intoolbar Close left view", "Close"));
1666 splitAction
->setToolTip(i18nc("@info", "Close left view"));
1667 splitAction
->setIcon(KIcon("view-left-close"));
1670 splitAction
->setText(i18nc("@action:intoolbar Split view", "Split"));
1671 splitAction
->setToolTip(i18nc("@info", "Split view"));
1672 splitAction
->setIcon(KIcon("view-right-new"));
1676 QString
DolphinMainWindow::tabName(const KUrl
& url
) const
1679 if (url
.equals(KUrl("file:///"))) {
1682 name
= url
.fileName();
1683 if (name
.isEmpty()) {
1684 name
= url
.protocol();
1686 // Make sure that a '&' inside the directory name is displayed correctly
1687 // and not misinterpreted as a keyboard shortcut in QTabBar::setTabText()
1688 name
.replace('&', "&&");
1694 bool DolphinMainWindow::isKompareInstalled() const
1696 static bool initialized
= false;
1697 static bool installed
= false;
1699 // TODO: maybe replace this approach later by using a menu
1700 // plugin like kdiff3plugin.cpp
1701 installed
= !KGlobal::dirs()->findExe("kompare").isEmpty();
1707 void DolphinMainWindow::createSecondaryView(int tabIndex
)
1709 QSplitter
* splitter
= m_viewTab
[tabIndex
].splitter
;
1710 const int newWidth
= (m_viewTab
[tabIndex
].primaryView
->width() - splitter
->handleWidth()) / 2;
1712 const DolphinView
* view
= m_viewTab
[tabIndex
].primaryView
->view();
1713 m_viewTab
[tabIndex
].secondaryView
= new DolphinViewContainer(this, 0, view
->rootUrl());
1714 splitter
->addWidget(m_viewTab
[tabIndex
].secondaryView
);
1715 splitter
->setSizes(QList
<int>() << newWidth
<< newWidth
);
1716 connectViewSignals(m_viewTab
[tabIndex
].secondaryView
);
1717 m_viewTab
[tabIndex
].secondaryView
->view()->reload();
1718 m_viewTab
[tabIndex
].secondaryView
->setActive(false);
1719 m_viewTab
[tabIndex
].secondaryView
->show();
1722 QString
DolphinMainWindow::tabProperty(const QString
& property
, int tabIndex
) const
1724 return "Tab " + QString::number(tabIndex
) + ' ' + property
;
1727 void DolphinMainWindow::setUrlAsCaption(const KUrl
& url
)
1729 delete m_captionStatJob
;
1730 m_captionStatJob
= 0;
1732 if (url
.protocol() == QLatin1String("file")) {
1734 if (url
.equals(KUrl("file:///"))) {
1737 caption
= url
.fileName();
1738 if (caption
.isEmpty()) {
1739 caption
= url
.protocol();
1743 setCaption(caption
);
1745 m_captionStatJob
= KIO::stat(url
, KIO::HideProgressInfo
);
1746 connect(m_captionStatJob
, SIGNAL(result(KJob
*)),
1747 this, SLOT(slotCaptionStatFinished(KJob
*)));
1751 void DolphinMainWindow::handleUrl(const KUrl
& url
)
1753 if (KProtocolManager::supportsListing(url
)) {
1754 activeViewContainer()->setUrl(url
);
1756 new KRun(url
, this);
1760 void DolphinMainWindow::slotCaptionStatFinished(KJob
* job
)
1762 m_captionStatJob
= 0;
1763 const KIO::UDSEntry entry
= static_cast<KIO::StatJob
*>(job
)->statResult();
1764 const QString name
= entry
.stringValue(KIO::UDSEntry::UDS_DISPLAY_NAME
);
1768 QString
DolphinMainWindow::squeezedText(const QString
& text
) const
1770 const QFontMetrics fm
= fontMetrics();
1771 return fm
.elidedText(text
, Qt::ElideMiddle
, fm
.maxWidth() * 10);
1774 DolphinMainWindow::UndoUiInterface::UndoUiInterface() :
1775 KIO::FileUndoManager::UiInterface()
1779 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
1783 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
* job
)
1785 DolphinMainWindow
* mainWin
= qobject_cast
<DolphinMainWindow
*>(parentWidget());
1787 DolphinStatusBar
* statusBar
= mainWin
->activeViewContainer()->statusBar();
1788 statusBar
->setMessage(job
->errorString(), DolphinStatusBar::Error
);
1790 KIO::FileUndoManager::UiInterface::jobError(job
);
1794 #include "dolphinmainwindow.moc"