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> *
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"
24 #include <config-nepomuk.h>
26 #include "dolphinapplication.h"
27 #include "dolphindockwidget.h"
28 #include "dolphincontextmenu.h"
29 #include "dolphinnewfilemenu.h"
30 #include "dolphinviewcontainer.h"
32 #include "panels/search/searchpanel.h"
33 #include <Nepomuk/ResourceManager>
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/viewproperties.h"
47 #include "panels/terminal/terminalpanel.h"
50 #include "dolphin_generalsettings.h"
51 #include "dolphin_searchsettings.h"
53 #include <KAcceleratorManager>
55 #include <KActionCollection>
56 #include <KActionMenu>
58 #include <KDesktopFile>
59 #include <kdeversion.h>
60 #include <kdualaction.h>
61 #include <KFileDialog>
62 #include <KFilePlacesModel>
67 #include <KIconLoader>
68 #include <KIO/NetAccess>
69 #include <KInputDialog>
71 #include <KProtocolManager>
74 #include <KMessageBox>
75 #include <KFileItemListProperties>
76 #include <konqmimedata.h>
77 #include <KProtocolInfo>
80 #include <KStandardDirs>
81 #include <kstatusbar.h>
82 #include <KStandardAction>
84 #include <KToggleAction>
85 #include <KUrlNavigator>
87 #include <KUrlComboBox>
88 #include <KToolInvocation>
90 #include "views/dolphinplacesmodel.h"
92 #include <QDesktopWidget>
93 #include <QDBusMessage>
96 #include <QToolButton>
100 // Used for GeneralSettings::version() to determine whether
101 // an updated version of Dolphin is running.
102 const int CurrentDolphinVersion
= 200;
106 * Menu shown when pressing the configure-button in the toolbar.
108 class ToolBarMenu
: public KMenu
111 ToolBarMenu(QWidget
* parent
);
112 virtual ~ToolBarMenu();
114 virtual void showEvent(QShowEvent
* event
);
118 * Remembers the tab configuration if a tab has been closed.
119 * Each closed tab can be restored by the menu
120 * "Go -> Recently Closed Tabs".
128 Q_DECLARE_METATYPE(ClosedTab
)
130 DolphinMainWindow::DolphinMainWindow() :
134 m_activeViewContainer(0),
135 m_centralWidgetLayout(0),
142 m_openToolBarMenuButton(0),
143 m_updateToolBarTimer(0),
144 m_lastHandleUrlStatJob(0),
145 m_searchDockIsTemporaryVisible(false)
147 DolphinPlacesModel::setModel(new KFilePlacesModel(this));
148 connect(DolphinPlacesModel::instance(), SIGNAL(errorMessage(QString
)),
149 this, SLOT(showErrorMessage(QString
)));
151 // Workaround for a X11-issue in combination with KModifierInfo
152 // (see DolphinContextMenu::initializeModifierKeyInfo() for
153 // more information):
154 DolphinContextMenu::initializeModifierKeyInfo();
156 setObjectName("Dolphin#");
158 m_viewTab
.append(ViewTab());
159 ViewTab
& viewTab
= m_viewTab
[m_tabIndex
];
160 viewTab
.wasActive
= true; // The first opened tab is automatically active
162 KIO::FileUndoManager
* undoManager
= KIO::FileUndoManager::self();
163 undoManager
->setUiInterface(new UndoUiInterface());
165 connect(undoManager
, SIGNAL(undoAvailable(bool)),
166 this, SLOT(slotUndoAvailable(bool)));
167 connect(undoManager
, SIGNAL(undoTextChanged(QString
)),
168 this, SLOT(slotUndoTextChanged(QString
)));
169 connect(undoManager
, SIGNAL(jobRecordingStarted(CommandType
)),
170 this, SLOT(clearStatusBar()));
171 connect(undoManager
, SIGNAL(jobRecordingFinished(CommandType
)),
172 this, SLOT(showCommand(CommandType
)));
174 GeneralSettings
* generalSettings
= GeneralSettings::self();
175 const bool firstRun
= (generalSettings
->version() < 200);
177 generalSettings
->setViewPropsTimestamp(QDateTime::currentDateTime());
180 setAcceptDrops(true);
182 viewTab
.splitter
= new QSplitter(this);
183 viewTab
.splitter
->setChildrenCollapsible(false);
187 const KUrl
homeUrl(generalSettings
->homeUrl());
188 setUrlAsCaption(homeUrl
);
189 m_actionHandler
= new DolphinViewActionHandler(actionCollection(), this);
190 connect(m_actionHandler
, SIGNAL(actionBeingHandled()), SLOT(clearStatusBar()));
191 connect(m_actionHandler
, SIGNAL(createDirectory()), SLOT(createDirectory()));
193 viewTab
.primaryView
= createViewContainer(homeUrl
, viewTab
.splitter
);
195 m_activeViewContainer
= viewTab
.primaryView
;
196 connectViewSignals(m_activeViewContainer
);
197 DolphinView
* view
= m_activeViewContainer
->view();
198 m_activeViewContainer
->show();
199 m_actionHandler
->setCurrentView(view
);
201 m_remoteEncoding
= new DolphinRemoteEncoding(this, m_actionHandler
);
202 connect(this, SIGNAL(urlChanged(KUrl
)),
203 m_remoteEncoding
, SLOT(slotAboutToOpenUrl()));
205 m_tabBar
= new KTabBar(this);
206 m_tabBar
->setMovable(true);
207 m_tabBar
->setTabsClosable(true);
208 connect(m_tabBar
, SIGNAL(currentChanged(int)),
209 this, SLOT(setActiveTab(int)));
210 connect(m_tabBar
, SIGNAL(tabCloseRequested(int)),
211 this, SLOT(closeTab(int)));
212 connect(m_tabBar
, SIGNAL(contextMenu(int,QPoint
)),
213 this, SLOT(openTabContextMenu(int,QPoint
)));
214 connect(m_tabBar
, SIGNAL(newTabRequest()),
215 this, SLOT(openNewTab()));
216 connect(m_tabBar
, SIGNAL(testCanDecode(const QDragMoveEvent
*,bool&)),
217 this, SLOT(slotTestCanDecode(const QDragMoveEvent
*,bool&)));
218 connect(m_tabBar
, SIGNAL(mouseMiddleClick(int)),
219 this, SLOT(closeTab(int)));
220 connect(m_tabBar
, SIGNAL(tabMoved(int,int)),
221 this, SLOT(slotTabMoved(int,int)));
222 connect(m_tabBar
, SIGNAL(receivedDropEvent(int,QDropEvent
*)),
223 this, SLOT(tabDropEvent(int,QDropEvent
*)));
225 m_tabBar
->blockSignals(true); // signals get unblocked after at least 2 tabs are open
227 QWidget
* centralWidget
= new QWidget(this);
228 m_centralWidgetLayout
= new QVBoxLayout(centralWidget
);
229 m_centralWidgetLayout
->setSpacing(0);
230 m_centralWidgetLayout
->setMargin(0);
231 m_centralWidgetLayout
->addWidget(m_tabBar
);
232 m_centralWidgetLayout
->addWidget(viewTab
.splitter
, 1);
234 setCentralWidget(centralWidget
);
236 emit
urlChanged(homeUrl
);
238 setupGUI(Keys
| Save
| Create
| ToolBar
);
239 stateChanged("new_file");
241 QClipboard
* clipboard
= QApplication::clipboard();
242 connect(clipboard
, SIGNAL(dataChanged()),
243 this, SLOT(updatePasteAction()));
245 if (generalSettings
->splitView()) {
252 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
253 showFilterBarAction
->setChecked(generalSettings
->filterBar());
256 menuBar()->setVisible(false);
257 // Assure a proper default size if Dolphin runs the first time
261 const bool showMenu
= !menuBar()->isHidden();
262 QAction
* showMenuBarAction
= actionCollection()->action(KStandardAction::name(KStandardAction::ShowMenubar
));
263 showMenuBarAction
->setChecked(showMenu
); // workaround for bug #171080
265 createToolBarMenuButton();
269 DolphinMainWindow::~DolphinMainWindow()
273 void DolphinMainWindow::openDirectories(const QList
<KUrl
>& dirs
)
275 if (dirs
.isEmpty()) {
279 if (dirs
.count() == 1) {
280 m_activeViewContainer
->setUrl(dirs
.first());
284 const int oldOpenTabsCount
= m_viewTab
.count();
286 const bool hasSplitView
= GeneralSettings::splitView();
288 // Open each directory inside a new tab. If the "split view" option has been enabled,
289 // always show two directories within one tab.
290 QList
<KUrl
>::const_iterator it
= dirs
.begin();
291 while (it
!= dirs
.end()) {
295 if (hasSplitView
&& (it
!= dirs
.end())) {
296 const int tabIndex
= m_viewTab
.count() - 1;
297 m_viewTab
[tabIndex
].secondaryView
->setUrl(*it
);
302 // Remove the previously opened tabs
303 for (int i
= 0; i
< oldOpenTabsCount
; ++i
) {
308 void DolphinMainWindow::openFiles(const QList
<KUrl
>& files
)
310 if (files
.isEmpty()) {
314 // Get all distinct directories from 'files' and open a tab
315 // for each directory. If the "split view" option is enabled, two
316 // directories are shown inside one tab (see openDirectories()).
318 foreach (const KUrl
& url
, files
) {
319 const KUrl
dir(url
.directory());
320 if (!dirs
.contains(dir
)) {
325 openDirectories(dirs
);
327 // Select the files. Although the files can be split between several
328 // tabs, there is no need to split 'files' accordingly, as
329 // the DolphinView will just ignore invalid selections.
330 const int tabCount
= m_viewTab
.count();
331 for (int i
= 0; i
< tabCount
; ++i
) {
332 m_viewTab
[i
].primaryView
->view()->markUrlsAsSelected(files
);
333 m_viewTab
[i
].primaryView
->view()->markUrlAsCurrent(files
.at(0));
334 if (m_viewTab
[i
].secondaryView
) {
335 m_viewTab
[i
].secondaryView
->view()->markUrlsAsSelected(files
);
336 m_viewTab
[i
].secondaryView
->view()->markUrlAsCurrent(files
.at(0));
341 void DolphinMainWindow::showCommand(CommandType command
)
343 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
345 case KIO::FileUndoManager::Copy
:
346 statusBar
->setMessage(i18nc("@info:status", "Successfully copied."),
347 DolphinStatusBar::OperationCompleted
);
349 case KIO::FileUndoManager::Move
:
350 statusBar
->setMessage(i18nc("@info:status", "Successfully moved."),
351 DolphinStatusBar::OperationCompleted
);
353 case KIO::FileUndoManager::Link
:
354 statusBar
->setMessage(i18nc("@info:status", "Successfully linked."),
355 DolphinStatusBar::OperationCompleted
);
357 case KIO::FileUndoManager::Trash
:
358 statusBar
->setMessage(i18nc("@info:status", "Successfully moved to trash."),
359 DolphinStatusBar::OperationCompleted
);
361 case KIO::FileUndoManager::Rename
:
362 statusBar
->setMessage(i18nc("@info:status", "Successfully renamed."),
363 DolphinStatusBar::OperationCompleted
);
366 case KIO::FileUndoManager::Mkdir
:
367 statusBar
->setMessage(i18nc("@info:status", "Created folder."),
368 DolphinStatusBar::OperationCompleted
);
376 void DolphinMainWindow::pasteIntoFolder()
378 m_activeViewContainer
->view()->pasteIntoFolder();
381 void DolphinMainWindow::changeUrl(const KUrl
& url
)
383 if (!KProtocolManager::supportsListing(url
)) {
384 // The URL navigator only checks for validity, not
385 // if the URL can be listed. An error message is
386 // shown due to DolphinViewContainer::restoreView().
390 DolphinViewContainer
* view
= activeViewContainer();
396 setUrlAsCaption(url
);
397 if (m_viewTab
.count() > 1) {
398 m_tabBar
->setTabText(m_tabIndex
, squeezedText(tabName(m_activeViewContainer
->url())));
400 const QString iconName
= KMimeType::iconNameForUrl(url
);
401 m_tabBar
->setTabIcon(m_tabIndex
, KIcon(iconName
));
402 emit
urlChanged(url
);
406 void DolphinMainWindow::slotEditableStateChanged(bool editable
)
408 KToggleAction
* editableLocationAction
=
409 static_cast<KToggleAction
*>(actionCollection()->action("editable_location"));
410 editableLocationAction
->setChecked(editable
);
413 void DolphinMainWindow::slotSelectionChanged(const KFileItemList
& selection
)
417 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
);
418 int selectedUrlsCount
= m_viewTab
[m_tabIndex
].primaryView
->view()->selectedItemsCount();
419 if (m_viewTab
[m_tabIndex
].secondaryView
) {
420 selectedUrlsCount
+= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedItemsCount();
423 QAction
* compareFilesAction
= actionCollection()->action("compare_files");
424 if (selectedUrlsCount
== 2) {
425 compareFilesAction
->setEnabled(isKompareInstalled());
427 compareFilesAction
->setEnabled(false);
430 emit
selectionChanged(selection
);
433 void DolphinMainWindow::slotRequestItemInfo(const KFileItem
& item
)
435 emit
requestItemInfo(item
);
438 void DolphinMainWindow::updateHistory()
440 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
441 const int index
= urlNavigator
->historyIndex();
443 QAction
* backAction
= actionCollection()->action("go_back");
445 backAction
->setToolTip(i18nc("@info", "Go back"));
446 backAction
->setEnabled(index
< urlNavigator
->historySize() - 1);
449 QAction
* forwardAction
= actionCollection()->action("go_forward");
451 forwardAction
->setToolTip(i18nc("@info", "Go forward"));
452 forwardAction
->setEnabled(index
> 0);
456 void DolphinMainWindow::updateFilterBarAction(bool show
)
458 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
459 showFilterBarAction
->setChecked(show
);
462 void DolphinMainWindow::openNewMainWindow()
464 KRun::run("dolphin", KUrl::List(), this);
467 void DolphinMainWindow::openNewTab()
469 const bool isUrlEditable
= m_activeViewContainer
->urlNavigator()->isUrlEditable();
471 openNewTab(m_activeViewContainer
->url());
472 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
474 // The URL navigator of the new tab should have the same editable state
475 // as the current tab
476 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
477 navigator
->setUrlEditable(isUrlEditable
);
480 // If a new tab is opened and the URL is editable, assure that
481 // the user can edit the URL without manually setting the focus
482 navigator
->setFocus();
486 void DolphinMainWindow::openNewTab(const KUrl
& url
)
488 QWidget
* focusWidget
= QApplication::focusWidget();
490 if (m_viewTab
.count() == 1) {
491 // Only one view is open currently and hence no tab is shown at
492 // all. Before creating a tab for 'url', provide a tab for the current URL.
493 const KUrl currentUrl
= m_activeViewContainer
->url();
494 m_tabBar
->addTab(KIcon(KMimeType::iconNameForUrl(currentUrl
)),
495 squeezedText(tabName(currentUrl
)));
496 m_tabBar
->blockSignals(false);
499 m_tabBar
->addTab(KIcon(KMimeType::iconNameForUrl(url
)),
500 squeezedText(tabName(url
)));
503 viewTab
.splitter
= new QSplitter(this);
504 viewTab
.splitter
->setChildrenCollapsible(false);
505 viewTab
.primaryView
= createViewContainer(url
, viewTab
.splitter
);
506 viewTab
.primaryView
->setActive(false);
507 connectViewSignals(viewTab
.primaryView
);
509 m_viewTab
.append(viewTab
);
511 actionCollection()->action("close_tab")->setEnabled(true);
513 // provide a split view, if the startup settings are set this way
514 if (GeneralSettings::splitView()) {
515 const int newTabIndex
= m_viewTab
.count() - 1;
516 createSecondaryView(newTabIndex
);
517 viewTab
.secondaryView
->setActive(true);
518 viewTab
.isPrimaryViewActive
= false;
522 // The DolphinViewContainer grabbed the keyboard focus. As the tab is opened
523 // in background, assure that the previous focused widget gets the focus back.
524 focusWidget
->setFocus();
528 void DolphinMainWindow::activateNextTab()
530 if (m_viewTab
.count() >= 2) {
531 const int tabIndex
= (m_tabBar
->currentIndex() + 1) % m_tabBar
->count();
532 m_tabBar
->setCurrentIndex(tabIndex
);
536 void DolphinMainWindow::activatePrevTab()
538 if (m_viewTab
.count() >= 2) {
539 int tabIndex
= m_tabBar
->currentIndex() - 1;
540 if (tabIndex
== -1) {
541 tabIndex
= m_tabBar
->count() - 1;
543 m_tabBar
->setCurrentIndex(tabIndex
);
547 void DolphinMainWindow::openInNewTab()
549 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
550 if (list
.isEmpty()) {
551 openNewTab(m_activeViewContainer
->url());
552 } else if ((list
.count() == 1) && list
[0].isDir()) {
553 openNewTab(list
[0].url());
557 void DolphinMainWindow::openInNewWindow()
561 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
562 if (list
.isEmpty()) {
563 newWindowUrl
= m_activeViewContainer
->url();
564 } else if ((list
.count() == 1) && list
[0].isDir()) {
565 newWindowUrl
= list
[0].url();
568 if (!newWindowUrl
.isEmpty()) {
569 KRun::run("dolphin", KUrl::List() << newWindowUrl
, this);
573 void DolphinMainWindow::toggleActiveView()
575 if (!m_viewTab
[m_tabIndex
].secondaryView
) {
576 // only one view is available
580 Q_ASSERT(m_activeViewContainer
);
581 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
);
583 DolphinViewContainer
* left
= m_viewTab
[m_tabIndex
].primaryView
;
584 DolphinViewContainer
* right
= m_viewTab
[m_tabIndex
].secondaryView
;
585 setActiveViewContainer(m_activeViewContainer
== right
? left
: right
);
588 void DolphinMainWindow::showEvent(QShowEvent
* event
)
590 KXmlGuiWindow::showEvent(event
);
591 if (!event
->spontaneous()) {
592 m_activeViewContainer
->view()->setFocus();
596 void DolphinMainWindow::closeEvent(QCloseEvent
* event
)
598 // Find out if Dolphin is closed directly by the user or
599 // by the session manager because the session is closed
600 bool closedByUser
= true;
601 DolphinApplication
*application
= qobject_cast
<DolphinApplication
*>(qApp
);
602 if (application
&& application
->sessionSaving()) {
603 closedByUser
= false;
606 if (m_viewTab
.count() > 1 && GeneralSettings::confirmClosingMultipleTabs() && closedByUser
) {
607 // Ask the user if he really wants to quit and close all tabs.
608 // Open a confirmation dialog with 3 buttons:
609 // KDialog::Yes -> Quit
610 // KDialog::No -> Close only the current tab
611 // KDialog::Cancel -> do nothing
612 KDialog
*dialog
= new KDialog(this, Qt::Dialog
);
613 dialog
->setCaption(i18nc("@title:window", "Confirmation"));
614 dialog
->setButtons(KDialog::Yes
| KDialog::No
| KDialog::Cancel
);
615 dialog
->setModal(true);
616 dialog
->setButtonGuiItem(KDialog::Yes
, KStandardGuiItem::quit());
617 dialog
->setButtonGuiItem(KDialog::No
, KGuiItem(i18n("C&lose Current Tab"), KIcon("tab-close")));
618 dialog
->setButtonGuiItem(KDialog::Cancel
, KStandardGuiItem::cancel());
619 dialog
->setDefaultButton(KDialog::Yes
);
621 bool doNotAskAgainCheckboxResult
= false;
623 const int result
= KMessageBox::createKMessageBox(dialog
,
624 QMessageBox::Warning
,
625 i18n("You have multiple tabs open in this window, are you sure you want to quit?"),
627 i18n("Do not ask again"),
628 &doNotAskAgainCheckboxResult
,
629 KMessageBox::Notify
);
631 if (doNotAskAgainCheckboxResult
) {
632 GeneralSettings::setConfirmClosingMultipleTabs(false);
640 // Close only the current tab
648 GeneralSettings::setVersion(CurrentDolphinVersion
);
649 GeneralSettings::self()->writeConfig();
651 if (m_searchDockIsTemporaryVisible
) {
652 QDockWidget
* searchDock
= findChild
<QDockWidget
*>("searchDock");
656 m_searchDockIsTemporaryVisible
= false;
659 KXmlGuiWindow::closeEvent(event
);
662 void DolphinMainWindow::saveProperties(KConfigGroup
& group
)
664 const int tabCount
= m_viewTab
.count();
665 group
.writeEntry("Tab Count", tabCount
);
666 group
.writeEntry("Active Tab Index", m_tabBar
->currentIndex());
668 for (int i
= 0; i
< tabCount
; ++i
) {
669 const DolphinViewContainer
* cont
= m_viewTab
[i
].primaryView
;
670 group
.writeEntry(tabProperty("Primary URL", i
), cont
->url().url());
671 group
.writeEntry(tabProperty("Primary Editable", i
),
672 cont
->urlNavigator()->isUrlEditable());
674 cont
= m_viewTab
[i
].secondaryView
;
676 group
.writeEntry(tabProperty("Secondary URL", i
), cont
->url().url());
677 group
.writeEntry(tabProperty("Secondary Editable", i
),
678 cont
->urlNavigator()->isUrlEditable());
683 void DolphinMainWindow::readProperties(const KConfigGroup
& group
)
685 const int tabCount
= group
.readEntry("Tab Count", 1);
686 for (int i
= 0; i
< tabCount
; ++i
) {
687 DolphinViewContainer
* cont
= m_viewTab
[i
].primaryView
;
689 cont
->setUrl(group
.readEntry(tabProperty("Primary URL", i
)));
690 const bool editable
= group
.readEntry(tabProperty("Primary Editable", i
), false);
691 cont
->urlNavigator()->setUrlEditable(editable
);
693 cont
= m_viewTab
[i
].secondaryView
;
694 const QString secondaryUrl
= group
.readEntry(tabProperty("Secondary URL", i
));
695 if (!secondaryUrl
.isEmpty()) {
697 // a secondary view should be shown, but no one is available
698 // currently -> create a new view
700 cont
= m_viewTab
[i
].secondaryView
;
704 cont
->setUrl(secondaryUrl
);
705 const bool editable
= group
.readEntry(tabProperty("Secondary Editable", i
), false);
706 cont
->urlNavigator()->setUrlEditable(editable
);
708 // no secondary view should be shown, but the default setting shows
709 // one already -> close the view
713 // openNewTab() needs to be called only tabCount - 1 times
714 if (i
!= tabCount
- 1) {
719 const int index
= group
.readEntry("Active Tab Index", 0);
720 m_tabBar
->setCurrentIndex(index
);
723 void DolphinMainWindow::updateNewMenu()
725 m_newFileMenu
->setViewShowsHiddenFiles(activeViewContainer()->view()->hiddenFilesShown());
726 m_newFileMenu
->checkUpToDate();
727 m_newFileMenu
->setPopupFiles(activeViewContainer()->url());
730 void DolphinMainWindow::createDirectory()
732 m_newFileMenu
->setViewShowsHiddenFiles(activeViewContainer()->view()->hiddenFilesShown());
733 m_newFileMenu
->setPopupFiles(activeViewContainer()->url());
734 m_newFileMenu
->createDirectory();
737 void DolphinMainWindow::quit()
742 void DolphinMainWindow::showErrorMessage(const QString
& message
)
744 if (!message
.isEmpty()) {
745 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
746 statusBar
->setMessage(message
, DolphinStatusBar::Error
);
750 void DolphinMainWindow::slotUndoAvailable(bool available
)
752 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
754 undoAction
->setEnabled(available
);
758 void DolphinMainWindow::restoreClosedTab(QAction
* action
)
760 if (action
->data().toBool()) {
761 // clear all actions except the "Empty Recently Closed Tabs"
762 // action and the separator
763 QList
<QAction
*> actions
= m_recentTabsMenu
->menu()->actions();
764 const int count
= actions
.size();
765 for (int i
= 2; i
< count
; ++i
) {
766 m_recentTabsMenu
->menu()->removeAction(actions
.at(i
));
769 const ClosedTab closedTab
= action
->data().value
<ClosedTab
>();
770 openNewTab(closedTab
.primaryUrl
);
771 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
773 if (closedTab
.isSplit
) {
774 // create secondary view
776 m_viewTab
[m_tabIndex
].secondaryView
->setUrl(closedTab
.secondaryUrl
);
779 m_recentTabsMenu
->removeAction(action
);
782 if (m_recentTabsMenu
->menu()->actions().count() == 2) {
783 m_recentTabsMenu
->setEnabled(false);
787 void DolphinMainWindow::slotUndoTextChanged(const QString
& text
)
789 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
791 undoAction
->setText(text
);
795 void DolphinMainWindow::undo()
798 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
799 KIO::FileUndoManager::self()->undo();
802 void DolphinMainWindow::cut()
804 m_activeViewContainer
->view()->cutSelectedItems();
807 void DolphinMainWindow::copy()
809 m_activeViewContainer
->view()->copySelectedItems();
812 void DolphinMainWindow::paste()
814 m_activeViewContainer
->view()->paste();
817 void DolphinMainWindow::find()
819 m_activeViewContainer
->setSearchModeEnabled(true);
822 void DolphinMainWindow::slotSearchLocationChanged()
825 QDockWidget
* searchDock
= findChild
<QDockWidget
*>("searchDock");
830 SearchPanel
* searchPanel
= qobject_cast
<SearchPanel
*>(searchDock
->widget());
832 searchPanel
->setSearchLocation(SearchSettings::location() == QLatin1String("FromHere")
833 ? SearchPanel::FromCurrentDir
834 : SearchPanel::Everywhere
);
839 void DolphinMainWindow::updatePasteAction()
841 QAction
* pasteAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Paste
));
842 QPair
<bool, QString
> pasteInfo
= m_activeViewContainer
->view()->pasteInfo();
843 pasteAction
->setEnabled(pasteInfo
.first
);
844 pasteAction
->setText(pasteInfo
.second
);
847 void DolphinMainWindow::selectAll()
851 // if the URL navigator is editable and focused, select the whole
852 // URL instead of all items of the view
854 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
855 QLineEdit
* lineEdit
= urlNavigator
->editor()->lineEdit(); // krazy:exclude=qclasses
856 const bool selectUrl
= urlNavigator
->isUrlEditable() &&
857 lineEdit
->hasFocus();
859 lineEdit
->selectAll();
861 m_activeViewContainer
->view()->selectAll();
865 void DolphinMainWindow::invertSelection()
868 m_activeViewContainer
->view()->invertSelection();
871 void DolphinMainWindow::toggleSplitView()
873 if (!m_viewTab
[m_tabIndex
].secondaryView
) {
874 createSecondaryView(m_tabIndex
);
875 setActiveViewContainer(m_viewTab
[m_tabIndex
].secondaryView
);
876 } else if (m_activeViewContainer
== m_viewTab
[m_tabIndex
].secondaryView
) {
877 // remove secondary view
878 m_viewTab
[m_tabIndex
].secondaryView
->close();
879 m_viewTab
[m_tabIndex
].secondaryView
->deleteLater();
880 m_viewTab
[m_tabIndex
].secondaryView
= 0;
882 setActiveViewContainer(m_viewTab
[m_tabIndex
].primaryView
);
884 // The primary view is active and should be closed. Hence from a users point of view
885 // the content of the secondary view should be moved to the primary view.
886 // From an implementation point of view it is more efficient to close
887 // the primary view and exchange the internal pointers afterwards.
889 m_viewTab
[m_tabIndex
].primaryView
->close();
890 m_viewTab
[m_tabIndex
].primaryView
->deleteLater();
891 m_viewTab
[m_tabIndex
].primaryView
= m_viewTab
[m_tabIndex
].secondaryView
;
892 m_viewTab
[m_tabIndex
].secondaryView
= 0;
894 setActiveViewContainer(m_viewTab
[m_tabIndex
].primaryView
);
900 void DolphinMainWindow::reloadView()
903 m_activeViewContainer
->view()->reload();
906 void DolphinMainWindow::stopLoading()
908 m_activeViewContainer
->view()->stopLoading();
911 void DolphinMainWindow::enableStopAction()
913 actionCollection()->action("stop")->setEnabled(true);
916 void DolphinMainWindow::disableStopAction()
918 actionCollection()->action("stop")->setEnabled(false);
921 void DolphinMainWindow::showFilterBar()
923 m_activeViewContainer
->setFilterBarVisible(true);
926 void DolphinMainWindow::toggleEditLocation()
930 QAction
* action
= actionCollection()->action("editable_location");
931 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
932 urlNavigator
->setUrlEditable(action
->isChecked());
935 void DolphinMainWindow::replaceLocation()
937 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
938 navigator
->setUrlEditable(true);
939 navigator
->setFocus();
941 // select the whole text of the combo box editor
942 QLineEdit
* lineEdit
= navigator
->editor()->lineEdit(); // krazy:exclude=qclasses
943 lineEdit
->selectAll();
946 void DolphinMainWindow::togglePanelLockState()
948 const bool newLockState
= !GeneralSettings::lockPanels();
949 foreach (QObject
* child
, children()) {
950 DolphinDockWidget
* dock
= qobject_cast
<DolphinDockWidget
*>(child
);
952 dock
->setLocked(newLockState
);
956 GeneralSettings::setLockPanels(newLockState
);
959 void DolphinMainWindow::slotPlacesPanelVisibilityChanged(bool visible
)
961 const int tabCount
= m_viewTab
.count();
962 for (int i
= 0; i
< tabCount
; ++i
) {
963 ViewTab
& tab
= m_viewTab
[i
];
964 Q_ASSERT(tab
.primaryView
);
965 tab
.primaryView
->urlNavigator()->setPlacesSelectorVisible(!visible
);
966 if (tab
.secondaryView
) {
967 tab
.secondaryView
->urlNavigator()->setPlacesSelectorVisible(!visible
);
972 void DolphinMainWindow::goBack()
974 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
975 urlNavigator
->goBack();
977 if (urlNavigator
->locationState().isEmpty()) {
978 // An empty location state indicates a redirection URL,
979 // which must be skipped too
980 urlNavigator
->goBack();
984 void DolphinMainWindow::goForward()
986 m_activeViewContainer
->urlNavigator()->goForward();
989 void DolphinMainWindow::goUp()
991 m_activeViewContainer
->urlNavigator()->goUp();
994 void DolphinMainWindow::goHome()
996 m_activeViewContainer
->urlNavigator()->goHome();
999 void DolphinMainWindow::goBack(Qt::MouseButtons buttons
)
1001 // The default case (left button pressed) is handled in goBack().
1002 if (buttons
== Qt::MidButton
) {
1003 KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigator();
1004 const int index
= urlNavigator
->historyIndex() + 1;
1005 openNewTab(urlNavigator
->locationUrl(index
));
1009 void DolphinMainWindow::goForward(Qt::MouseButtons buttons
)
1011 // The default case (left button pressed) is handled in goForward().
1012 if (buttons
== Qt::MidButton
) {
1013 KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigator();
1014 const int index
= urlNavigator
->historyIndex() - 1;
1015 openNewTab(urlNavigator
->locationUrl(index
));
1019 void DolphinMainWindow::goUp(Qt::MouseButtons buttons
)
1021 // The default case (left button pressed) is handled in goUp().
1022 if (buttons
== Qt::MidButton
) {
1023 openNewTab(activeViewContainer()->url().upUrl());
1027 void DolphinMainWindow::compareFiles()
1029 // The method is only invoked if exactly 2 files have
1030 // been selected. The selected files may be:
1031 // - both in the primary view
1032 // - both in the secondary view
1033 // - one in the primary view and the other in the secondary
1035 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
);
1040 KFileItemList items
= m_viewTab
[m_tabIndex
].primaryView
->view()->selectedItems();
1042 switch (items
.count()) {
1044 Q_ASSERT(m_viewTab
[m_tabIndex
].secondaryView
);
1045 items
= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedItems();
1046 Q_ASSERT(items
.count() == 2);
1047 urlA
= items
[0].url();
1048 urlB
= items
[1].url();
1053 urlA
= items
[0].url();
1054 Q_ASSERT(m_viewTab
[m_tabIndex
].secondaryView
);
1055 items
= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedItems();
1056 Q_ASSERT(items
.count() == 1);
1057 urlB
= items
[0].url();
1062 urlA
= items
[0].url();
1063 urlB
= items
[1].url();
1068 // may not happen: compareFiles may only get invoked if 2
1069 // files are selected
1074 QString
command("kompare -c \"");
1075 command
.append(urlA
.pathOrUrl());
1076 command
.append("\" \"");
1077 command
.append(urlB
.pathOrUrl());
1078 command
.append('\"');
1079 KRun::runCommand(command
, "Kompare", "kompare", this);
1082 void DolphinMainWindow::toggleShowMenuBar()
1084 const bool visible
= menuBar()->isVisible();
1085 menuBar()->setVisible(!visible
);
1087 createToolBarMenuButton();
1089 deleteToolBarMenuButton();
1093 void DolphinMainWindow::openTerminal()
1095 QString
dir(QDir::homePath());
1097 // If the given directory is not local, it can still be the URL of an
1098 // ioslave using UDS_LOCAL_PATH which to be converted first.
1099 KUrl url
= KIO::NetAccess::mostLocalUrl(m_activeViewContainer
->url(), this);
1101 //If the URL is local after the above conversion, set the directory.
1102 if (url
.isLocalFile()) {
1103 dir
= url
.toLocalFile();
1106 KToolInvocation::invokeTerminal(QString(), dir
);
1109 void DolphinMainWindow::editSettings()
1111 if (!m_settingsDialog
) {
1112 const KUrl url
= activeViewContainer()->url();
1113 DolphinSettingsDialog
* settingsDialog
= new DolphinSettingsDialog(url
, this);
1114 connect(settingsDialog
, SIGNAL(settingsChanged()), this, SLOT(refreshViews()));
1115 settingsDialog
->setAttribute(Qt::WA_DeleteOnClose
);
1116 settingsDialog
->show();
1117 m_settingsDialog
= settingsDialog
;
1119 m_settingsDialog
.data()->raise();
1123 void DolphinMainWindow::setActiveTab(int index
)
1125 Q_ASSERT(index
>= 0);
1126 Q_ASSERT(index
< m_viewTab
.count());
1127 if (index
== m_tabIndex
) {
1131 // hide current tab content
1132 ViewTab
& hiddenTab
= m_viewTab
[m_tabIndex
];
1133 hiddenTab
.isPrimaryViewActive
= hiddenTab
.primaryView
->isActive();
1134 hiddenTab
.primaryView
->setActive(false);
1135 if (hiddenTab
.secondaryView
) {
1136 hiddenTab
.secondaryView
->setActive(false);
1138 QSplitter
* splitter
= m_viewTab
[m_tabIndex
].splitter
;
1140 m_centralWidgetLayout
->removeWidget(splitter
);
1142 // show active tab content
1145 ViewTab
& viewTab
= m_viewTab
[index
];
1146 m_centralWidgetLayout
->addWidget(viewTab
.splitter
, 1);
1147 viewTab
.primaryView
->show();
1148 if (viewTab
.secondaryView
) {
1149 viewTab
.secondaryView
->show();
1151 viewTab
.splitter
->show();
1153 if (!viewTab
.wasActive
) {
1154 viewTab
.wasActive
= true;
1156 // If the tab has not been activated yet the size of the KItemListView is
1157 // undefined and results in an unwanted animation. To prevent this a
1158 // reloading of the directory gets triggered.
1159 viewTab
.primaryView
->view()->reload();
1160 if (viewTab
.secondaryView
) {
1161 viewTab
.secondaryView
->view()->reload();
1165 setActiveViewContainer(viewTab
.isPrimaryViewActive
? viewTab
.primaryView
:
1166 viewTab
.secondaryView
);
1169 void DolphinMainWindow::closeTab()
1171 closeTab(m_tabBar
->currentIndex());
1174 void DolphinMainWindow::closeTab(int index
)
1176 Q_ASSERT(index
>= 0);
1177 Q_ASSERT(index
< m_viewTab
.count());
1178 if (m_viewTab
.count() == 1) {
1179 // the last tab may never get closed
1183 if (index
== m_tabIndex
) {
1184 // The tab that should be closed is the active tab. Activate the
1185 // previous tab before closing the tab.
1186 m_tabBar
->setCurrentIndex((index
> 0) ? index
- 1 : 1);
1188 rememberClosedTab(index
);
1191 m_viewTab
[index
].primaryView
->deleteLater();
1192 if (m_viewTab
[index
].secondaryView
) {
1193 m_viewTab
[index
].secondaryView
->deleteLater();
1195 m_viewTab
[index
].splitter
->deleteLater();
1196 m_viewTab
.erase(m_viewTab
.begin() + index
);
1198 m_tabBar
->blockSignals(true);
1199 m_tabBar
->removeTab(index
);
1201 if (m_tabIndex
> index
) {
1203 Q_ASSERT(m_tabIndex
>= 0);
1206 // if only one tab is left, also remove the tab entry so that
1207 // closing the last tab is not possible
1208 if (m_viewTab
.count() == 1) {
1209 m_tabBar
->removeTab(0);
1210 actionCollection()->action("close_tab")->setEnabled(false);
1212 m_tabBar
->blockSignals(false);
1216 void DolphinMainWindow::openTabContextMenu(int index
, const QPoint
& pos
)
1220 QAction
* newTabAction
= menu
.addAction(KIcon("tab-new"), i18nc("@action:inmenu", "New Tab"));
1221 newTabAction
->setShortcut(actionCollection()->action("new_tab")->shortcut());
1223 QAction
* detachTabAction
= menu
.addAction(KIcon("tab-detach"), i18nc("@action:inmenu", "Detach Tab"));
1225 QAction
* closeOtherTabsAction
= menu
.addAction(KIcon("tab-close-other"), i18nc("@action:inmenu", "Close Other Tabs"));
1227 QAction
* closeTabAction
= menu
.addAction(KIcon("tab-close"), i18nc("@action:inmenu", "Close Tab"));
1228 closeTabAction
->setShortcut(actionCollection()->action("close_tab")->shortcut());
1229 QAction
* selectedAction
= menu
.exec(pos
);
1230 if (selectedAction
== newTabAction
) {
1231 const ViewTab
& tab
= m_viewTab
[index
];
1232 Q_ASSERT(tab
.primaryView
);
1233 const KUrl url
= tab
.secondaryView
&& tab
.secondaryView
->isActive() ?
1234 tab
.secondaryView
->url() : tab
.primaryView
->url();
1236 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
1237 } else if (selectedAction
== detachTabAction
) {
1238 const QString
separator(QLatin1Char(' '));
1239 QString command
= QLatin1String("dolphin");
1241 const ViewTab
& tab
= m_viewTab
[index
];
1242 Q_ASSERT(tab
.primaryView
);
1244 command
+= separator
+ tab
.primaryView
->url().url();
1245 if (tab
.secondaryView
) {
1246 command
+= separator
+ tab
.secondaryView
->url().url();
1247 command
+= separator
+ QLatin1String("-split");
1250 KRun::runCommand(command
, this);
1253 } else if (selectedAction
== closeOtherTabsAction
) {
1254 const int count
= m_tabBar
->count();
1255 for (int i
= 0; i
< index
; ++i
) {
1258 for (int i
= index
+ 1; i
< count
; ++i
) {
1261 } else if (selectedAction
== closeTabAction
) {
1266 void DolphinMainWindow::slotTabMoved(int from
, int to
)
1268 m_viewTab
.move(from
, to
);
1269 m_tabIndex
= m_tabBar
->currentIndex();
1272 void DolphinMainWindow::handlePlacesClick(const KUrl
& url
, Qt::MouseButtons buttons
)
1274 if (buttons
& Qt::MidButton
) {
1276 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
1282 void DolphinMainWindow::slotTestCanDecode(const QDragMoveEvent
* event
, bool& canDecode
)
1284 canDecode
= KUrl::List::canDecode(event
->mimeData());
1287 void DolphinMainWindow::handleUrl(const KUrl
& url
)
1289 delete m_lastHandleUrlStatJob
;
1290 m_lastHandleUrlStatJob
= 0;
1292 if (url
.isLocalFile() && QFileInfo(url
.toLocalFile()).isDir()) {
1293 activeViewContainer()->setUrl(url
);
1294 } else if (KProtocolManager::supportsListing(url
)) {
1295 // stat the URL to see if it is a dir or not
1296 m_lastHandleUrlStatJob
= KIO::stat(url
, KIO::HideProgressInfo
);
1297 connect(m_lastHandleUrlStatJob
, SIGNAL(result(KJob
*)),
1298 this, SLOT(slotHandleUrlStatFinished(KJob
*)));
1301 new KRun(url
, this);
1305 void DolphinMainWindow::slotHandleUrlStatFinished(KJob
* job
)
1307 m_lastHandleUrlStatJob
= 0;
1308 const KIO::UDSEntry entry
= static_cast<KIO::StatJob
*>(job
)->statResult();
1309 const KUrl url
= static_cast<KIO::StatJob
*>(job
)->url();
1310 if (entry
.isDir()) {
1311 activeViewContainer()->setUrl(url
);
1313 new KRun(url
, this);
1317 void DolphinMainWindow::tabDropEvent(int tab
, QDropEvent
* event
)
1319 const KUrl::List urls
= KUrl::List::fromMimeData(event
->mimeData());
1320 if (!urls
.isEmpty() && tab
!= -1) {
1321 const ViewTab
& viewTab
= m_viewTab
[tab
];
1322 const KUrl destPath
= viewTab
.isPrimaryViewActive
? viewTab
.primaryView
->url() : viewTab
.secondaryView
->url();
1324 //DragAndDropHelper::instance().dropUrls(KFileItem(), destPath, event, m_tabBar);
1328 void DolphinMainWindow::slotWriteStateChanged(bool isFolderWritable
)
1330 newFileMenu()->setEnabled(isFolderWritable
);
1333 void DolphinMainWindow::slotSearchModeChanged(bool enabled
)
1336 const DolphinSearchInformation
& searchInfo
= DolphinSearchInformation::instance();
1337 if (!searchInfo
.isIndexingEnabled()) {
1341 QDockWidget
* searchDock
= findChild
<QDockWidget
*>("searchDock");
1347 if (!searchDock
->isVisible()) {
1348 m_searchDockIsTemporaryVisible
= true;
1352 if (searchDock
->isVisible() && m_searchDockIsTemporaryVisible
) {
1355 m_searchDockIsTemporaryVisible
= false;
1358 SearchPanel
* searchPanel
= qobject_cast
<SearchPanel
*>(searchDock
->widget());
1364 SearchPanel::SearchLocation searchLocation
= SearchPanel::Everywhere
;
1365 const KUrl url
= m_activeViewContainer
->url();
1366 const bool isSearchUrl
= (url
.protocol() == QLatin1String("nepomuksearch"));
1367 if ((SearchSettings::location() == QLatin1String("FromHere") && !isSearchUrl
)) {
1368 searchLocation
= SearchPanel::FromCurrentDir
;
1370 searchPanel
->setSearchLocation(searchLocation
);
1372 searchPanel
->setSearchLocation(SearchPanel::Everywhere
);
1379 void DolphinMainWindow::openContextMenu(const QPoint
& pos
,
1380 const KFileItem
& item
,
1382 const QList
<QAction
*>& customActions
)
1384 QWeakPointer
<DolphinContextMenu
> contextMenu
= new DolphinContextMenu(this, pos
, item
, url
);
1385 contextMenu
.data()->setCustomActions(customActions
);
1386 const DolphinContextMenu::Command command
= contextMenu
.data()->open();
1389 case DolphinContextMenu::OpenParentFolderInNewWindow
: {
1390 KRun::run("dolphin", KUrl::List() << item
.url().upUrl(), this);
1394 case DolphinContextMenu::OpenParentFolderInNewTab
:
1395 openNewTab(item
.url().upUrl());
1398 case DolphinContextMenu::None
:
1403 delete contextMenu
.data();
1406 void DolphinMainWindow::updateToolBarMenu()
1408 KMenu
* menu
= qobject_cast
<KMenu
*>(sender());
1411 // All actions get cleared by KMenu::clear(). The sub-menus are deleted
1412 // by connecting to the aboutToHide() signal from the parent-menu.
1415 KActionCollection
* ac
= actionCollection();
1417 // Add "Edit" actions
1418 bool added
= addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::Undo
)), menu
) |
1419 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::Find
)), menu
) |
1420 addActionToMenu(ac
->action("select_all"), menu
) |
1421 addActionToMenu(ac
->action("invert_selection"), menu
);
1424 menu
->addSeparator();
1427 // Add "View" actions
1428 if (!GeneralSettings::showZoomSlider()) {
1429 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ZoomIn
)), menu
);
1430 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ZoomOut
)), menu
);
1431 menu
->addSeparator();
1434 added
= addActionToMenu(ac
->action("view_mode"), menu
) |
1435 addActionToMenu(ac
->action("sort"), menu
) |
1436 addActionToMenu(ac
->action("additional_info"), menu
) |
1437 addActionToMenu(ac
->action("show_preview"), menu
) |
1438 addActionToMenu(ac
->action("show_in_groups"), menu
) |
1439 addActionToMenu(ac
->action("show_hidden_files"), menu
);
1442 menu
->addSeparator();
1445 added
= addActionToMenu(ac
->action("split_view"), menu
) |
1446 addActionToMenu(ac
->action("reload"), menu
) |
1447 addActionToMenu(ac
->action("view_properties"), menu
);
1449 menu
->addSeparator();
1452 addActionToMenu(ac
->action("panels"), menu
);
1453 KMenu
* locationBarMenu
= new KMenu(i18nc("@action:inmenu", "Location Bar"), menu
);
1454 locationBarMenu
->addAction(ac
->action("editable_location"));
1455 locationBarMenu
->addAction(ac
->action("replace_location"));
1456 menu
->addMenu(locationBarMenu
);
1458 menu
->addSeparator();
1461 KMenu
* goMenu
= new KMenu(i18nc("@action:inmenu", "Go"), menu
);
1462 connect(menu
, SIGNAL(aboutToHide()), goMenu
, SLOT(deleteLater()));
1463 goMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Back
)));
1464 goMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Forward
)));
1465 goMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Up
)));
1466 goMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Home
)));
1467 goMenu
->addAction(ac
->action("closed_tabs"));
1468 menu
->addMenu(goMenu
);
1471 KMenu
* toolsMenu
= new KMenu(i18nc("@action:inmenu", "Tools"), menu
);
1472 connect(menu
, SIGNAL(aboutToHide()), toolsMenu
, SLOT(deleteLater()));
1473 toolsMenu
->addAction(ac
->action("show_filter_bar"));
1474 toolsMenu
->addAction(ac
->action("compare_files"));
1475 toolsMenu
->addAction(ac
->action("open_terminal"));
1476 toolsMenu
->addAction(ac
->action("change_remote_encoding"));
1477 menu
->addMenu(toolsMenu
);
1479 // Add "Settings" menu entries
1480 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::KeyBindings
)), menu
);
1481 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ConfigureToolbars
)), menu
);
1482 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::Preferences
)), menu
);
1485 KMenu
* helpMenu
= new KMenu(i18nc("@action:inmenu", "Help"), menu
);
1486 connect(menu
, SIGNAL(aboutToHide()), helpMenu
, SLOT(deleteLater()));
1487 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::HelpContents
)));
1488 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::WhatsThis
)));
1489 helpMenu
->addSeparator();
1490 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::ReportBug
)));
1491 helpMenu
->addSeparator();
1492 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::SwitchApplicationLanguage
)));
1493 helpMenu
->addSeparator();
1494 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::AboutApp
)));
1495 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::AboutKDE
)));
1496 menu
->addMenu(helpMenu
);
1498 menu
->addSeparator();
1499 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ShowMenubar
)), menu
);
1502 void DolphinMainWindow::updateToolBar()
1504 if (!menuBar()->isVisible()) {
1505 createToolBarMenuButton();
1509 void DolphinMainWindow::slotToolBarSpacerDeleted()
1511 m_toolBarSpacer
= 0;
1512 m_updateToolBarTimer
->start();
1515 void DolphinMainWindow::slotToolBarMenuButtonDeleted()
1517 m_openToolBarMenuButton
= 0;
1518 m_updateToolBarTimer
->start();
1521 void DolphinMainWindow::slotToolBarIconSizeChanged(const QSize
& iconSize
)
1523 if (m_openToolBarMenuButton
) {
1524 m_openToolBarMenuButton
->setIconSize(iconSize
);
1528 void DolphinMainWindow::setActiveViewContainer(DolphinViewContainer
* viewContainer
)
1530 Q_ASSERT(viewContainer
);
1531 Q_ASSERT((viewContainer
== m_viewTab
[m_tabIndex
].primaryView
) ||
1532 (viewContainer
== m_viewTab
[m_tabIndex
].secondaryView
));
1533 if (m_activeViewContainer
== viewContainer
) {
1537 m_activeViewContainer
->setActive(false);
1538 m_activeViewContainer
= viewContainer
;
1540 // Activating the view container might trigger a recursive setActiveViewContainer() call
1541 // inside DolphinMainWindow::toggleActiveView() when having a split view. Temporary
1542 // disconnect the activated() signal in this case:
1543 disconnect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1544 m_activeViewContainer
->setActive(true);
1545 connect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1547 m_actionHandler
->setCurrentView(viewContainer
->view());
1550 updateEditActions();
1551 updateViewActions();
1554 const KUrl url
= m_activeViewContainer
->url();
1555 setUrlAsCaption(url
);
1556 if (m_viewTab
.count() > 1) {
1557 m_tabBar
->setTabText(m_tabIndex
, tabName(url
));
1558 m_tabBar
->setTabIcon(m_tabIndex
, KIcon(KMimeType::iconNameForUrl(url
)));
1561 emit
urlChanged(url
);
1564 DolphinViewContainer
* DolphinMainWindow::createViewContainer(const KUrl
& url
, QWidget
* parent
)
1566 DolphinViewContainer
* container
= new DolphinViewContainer(url
, parent
);
1568 // The places-selector from the URL navigator should only be shown
1569 // if the places dock is invisible
1570 QDockWidget
* placesDock
= findChild
<QDockWidget
*>("placesDock");
1571 container
->urlNavigator()->setPlacesSelectorVisible(!placesDock
|| !placesDock
->isVisible());
1576 void DolphinMainWindow::setupActions()
1578 // setup 'File' menu
1579 m_newFileMenu
= new DolphinNewFileMenu(this);
1580 KMenu
* menu
= m_newFileMenu
->menu();
1581 menu
->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1582 menu
->setIcon(KIcon("document-new"));
1583 connect(menu
, SIGNAL(aboutToShow()),
1584 this, SLOT(updateNewMenu()));
1586 KAction
* newWindow
= actionCollection()->addAction("new_window");
1587 newWindow
->setIcon(KIcon("window-new"));
1588 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
1589 newWindow
->setShortcut(Qt::CTRL
| Qt::Key_N
);
1590 connect(newWindow
, SIGNAL(triggered()), this, SLOT(openNewMainWindow()));
1592 KAction
* newTab
= actionCollection()->addAction("new_tab");
1593 newTab
->setIcon(KIcon("tab-new"));
1594 newTab
->setText(i18nc("@action:inmenu File", "New Tab"));
1595 newTab
->setShortcut(KShortcut(Qt::CTRL
| Qt::Key_T
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_N
));
1596 connect(newTab
, SIGNAL(triggered()), this, SLOT(openNewTab()));
1598 KAction
* closeTab
= actionCollection()->addAction("close_tab");
1599 closeTab
->setIcon(KIcon("tab-close"));
1600 closeTab
->setText(i18nc("@action:inmenu File", "Close Tab"));
1601 closeTab
->setShortcut(Qt::CTRL
| Qt::Key_W
);
1602 closeTab
->setEnabled(false);
1603 connect(closeTab
, SIGNAL(triggered()), this, SLOT(closeTab()));
1605 KStandardAction::quit(this, SLOT(quit()), actionCollection());
1607 // setup 'Edit' menu
1608 KStandardAction::undo(this,
1610 actionCollection());
1612 // need to remove shift+del from cut action, else the shortcut for deletejob
1614 KAction
* cut
= KStandardAction::cut(this, SLOT(cut()), actionCollection());
1615 KShortcut cutShortcut
= cut
->shortcut();
1616 cutShortcut
.remove(Qt::SHIFT
| Qt::Key_Delete
, KShortcut::KeepEmpty
);
1617 cut
->setShortcut(cutShortcut
);
1618 KStandardAction::copy(this, SLOT(copy()), actionCollection());
1619 KAction
* paste
= KStandardAction::paste(this, SLOT(paste()), actionCollection());
1620 // The text of the paste-action is modified dynamically by Dolphin
1621 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1622 // due to the long text, the text "Paste" is used:
1623 paste
->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1625 KStandardAction::find(this, SLOT(find()), actionCollection());
1627 KAction
* selectAll
= actionCollection()->addAction("select_all");
1628 selectAll
->setText(i18nc("@action:inmenu Edit", "Select All"));
1629 selectAll
->setShortcut(Qt::CTRL
| Qt::Key_A
);
1630 connect(selectAll
, SIGNAL(triggered()), this, SLOT(selectAll()));
1632 KAction
* invertSelection
= actionCollection()->addAction("invert_selection");
1633 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1634 invertSelection
->setShortcut(Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
1635 connect(invertSelection
, SIGNAL(triggered()), this, SLOT(invertSelection()));
1637 // setup 'View' menu
1638 // (note that most of it is set up in DolphinViewActionHandler)
1640 KAction
* split
= actionCollection()->addAction("split_view");
1641 split
->setShortcut(Qt::Key_F3
);
1642 updateSplitAction();
1643 connect(split
, SIGNAL(triggered()), this, SLOT(toggleSplitView()));
1645 KAction
* reload
= actionCollection()->addAction("reload");
1646 reload
->setText(i18nc("@action:inmenu View", "Reload"));
1647 reload
->setShortcut(Qt::Key_F5
);
1648 reload
->setIcon(KIcon("view-refresh"));
1649 connect(reload
, SIGNAL(triggered()), this, SLOT(reloadView()));
1651 KAction
* stop
= actionCollection()->addAction("stop");
1652 stop
->setText(i18nc("@action:inmenu View", "Stop"));
1653 stop
->setToolTip(i18nc("@info", "Stop loading"));
1654 stop
->setIcon(KIcon("process-stop"));
1655 connect(stop
, SIGNAL(triggered()), this, SLOT(stopLoading()));
1657 KToggleAction
* editableLocation
= actionCollection()->add
<KToggleAction
>("editable_location");
1658 editableLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1659 editableLocation
->setShortcut(Qt::CTRL
| Qt::Key_L
);
1660 connect(editableLocation
, SIGNAL(triggered()), this, SLOT(toggleEditLocation()));
1662 KAction
* replaceLocation
= actionCollection()->addAction("replace_location");
1663 replaceLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1664 replaceLocation
->setShortcut(Qt::Key_F6
);
1665 connect(replaceLocation
, SIGNAL(triggered()), this, SLOT(replaceLocation()));
1668 KAction
* backAction
= KStandardAction::back(this, SLOT(goBack()), actionCollection());
1669 connect(backAction
, SIGNAL(triggered(Qt::MouseButtons
,Qt::KeyboardModifiers
)), this, SLOT(goBack(Qt::MouseButtons
)));
1670 KShortcut backShortcut
= backAction
->shortcut();
1671 backShortcut
.setAlternate(Qt::Key_Backspace
);
1672 backAction
->setShortcut(backShortcut
);
1674 m_recentTabsMenu
= new KActionMenu(i18n("Recently Closed Tabs"), this);
1675 m_recentTabsMenu
->setIcon(KIcon("edit-undo"));
1676 actionCollection()->addAction("closed_tabs", m_recentTabsMenu
);
1677 connect(m_recentTabsMenu
->menu(), SIGNAL(triggered(QAction
*)),
1678 this, SLOT(restoreClosedTab(QAction
*)));
1680 QAction
* action
= new QAction(i18n("Empty Recently Closed Tabs"), m_recentTabsMenu
);
1681 action
->setIcon(KIcon("edit-clear-list"));
1682 action
->setData(QVariant::fromValue(true));
1683 m_recentTabsMenu
->addAction(action
);
1684 m_recentTabsMenu
->addSeparator();
1685 m_recentTabsMenu
->setEnabled(false);
1687 KAction
* forwardAction
= KStandardAction::forward(this, SLOT(goForward()), actionCollection());
1688 connect(forwardAction
, SIGNAL(triggered(Qt::MouseButtons
,Qt::KeyboardModifiers
)), this, SLOT(goForward(Qt::MouseButtons
)));
1690 KAction
* upAction
= KStandardAction::up(this, SLOT(goUp()), actionCollection());
1691 connect(upAction
, SIGNAL(triggered(Qt::MouseButtons
,Qt::KeyboardModifiers
)), this, SLOT(goUp(Qt::MouseButtons
)));
1693 KStandardAction::home(this, SLOT(goHome()), actionCollection());
1695 // setup 'Tools' menu
1696 KAction
* showFilterBar
= actionCollection()->addAction("show_filter_bar");
1697 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Show Filter Bar"));
1698 showFilterBar
->setIcon(KIcon("view-filter"));
1699 showFilterBar
->setShortcut(Qt::CTRL
| Qt::Key_I
);
1700 connect(showFilterBar
, SIGNAL(triggered()), this, SLOT(showFilterBar()));
1702 KAction
* compareFiles
= actionCollection()->addAction("compare_files");
1703 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1704 compareFiles
->setIcon(KIcon("kompare"));
1705 compareFiles
->setEnabled(false);
1706 connect(compareFiles
, SIGNAL(triggered()), this, SLOT(compareFiles()));
1708 KAction
* openTerminal
= actionCollection()->addAction("open_terminal");
1709 openTerminal
->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
1710 openTerminal
->setIcon(KIcon("utilities-terminal"));
1711 openTerminal
->setShortcut(Qt::SHIFT
| Qt::Key_F4
);
1712 connect(openTerminal
, SIGNAL(triggered()), this, SLOT(openTerminal()));
1714 // setup 'Settings' menu
1715 KToggleAction
* showMenuBar
= KStandardAction::showMenubar(0, 0, actionCollection());
1716 connect(showMenuBar
, SIGNAL(triggered(bool)), // Fixes #286822
1717 this, SLOT(toggleShowMenuBar()), Qt::QueuedConnection
);
1718 KStandardAction::preferences(this, SLOT(editSettings()), actionCollection());
1720 // not in menu actions
1721 QList
<QKeySequence
> nextTabKeys
;
1722 nextTabKeys
.append(KStandardShortcut::tabNext().primary());
1723 nextTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::Key_Tab
));
1725 QList
<QKeySequence
> prevTabKeys
;
1726 prevTabKeys
.append(KStandardShortcut::tabPrev().primary());
1727 prevTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::SHIFT
| Qt::Key_Tab
));
1729 KAction
* activateNextTab
= actionCollection()->addAction("activate_next_tab");
1730 activateNextTab
->setText(i18nc("@action:inmenu", "Activate Next Tab"));
1731 connect(activateNextTab
, SIGNAL(triggered()), SLOT(activateNextTab()));
1732 activateNextTab
->setShortcuts(QApplication::isRightToLeft() ? prevTabKeys
: nextTabKeys
);
1734 KAction
* activatePrevTab
= actionCollection()->addAction("activate_prev_tab");
1735 activatePrevTab
->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
1736 connect(activatePrevTab
, SIGNAL(triggered()), SLOT(activatePrevTab()));
1737 activatePrevTab
->setShortcuts(QApplication::isRightToLeft() ? nextTabKeys
: prevTabKeys
);
1740 KAction
* openInNewTab
= actionCollection()->addAction("open_in_new_tab");
1741 openInNewTab
->setText(i18nc("@action:inmenu", "Open in New Tab"));
1742 openInNewTab
->setIcon(KIcon("tab-new"));
1743 connect(openInNewTab
, SIGNAL(triggered()), this, SLOT(openInNewTab()));
1745 KAction
* openInNewWindow
= actionCollection()->addAction("open_in_new_window");
1746 openInNewWindow
->setText(i18nc("@action:inmenu", "Open in New Window"));
1747 openInNewWindow
->setIcon(KIcon("window-new"));
1748 connect(openInNewWindow
, SIGNAL(triggered()), this, SLOT(openInNewWindow()));
1751 void DolphinMainWindow::setupDockWidgets()
1753 const bool lock
= GeneralSettings::lockPanels();
1755 KDualAction
* lockLayoutAction
= actionCollection()->add
<KDualAction
>("lock_panels");
1756 lockLayoutAction
->setActiveText(i18nc("@action:inmenu Panels", "Unlock Panels"));
1757 lockLayoutAction
->setActiveIcon(KIcon("object-unlocked"));
1758 lockLayoutAction
->setInactiveText(i18nc("@action:inmenu Panels", "Lock Panels"));
1759 lockLayoutAction
->setInactiveIcon(KIcon("object-locked"));
1760 lockLayoutAction
->setActive(lock
);
1761 connect(lockLayoutAction
, SIGNAL(triggered()), this, SLOT(togglePanelLockState()));
1763 // Setup "Information"
1764 DolphinDockWidget
* infoDock
= new DolphinDockWidget(i18nc("@title:window", "Information"));
1765 infoDock
->setLocked(lock
);
1766 infoDock
->setObjectName("infoDock");
1767 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1768 Panel
* infoPanel
= new InformationPanel(infoDock
);
1769 infoPanel
->setCustomContextMenuActions(QList
<QAction
*>() << lockLayoutAction
);
1770 connect(infoPanel
, SIGNAL(urlActivated(KUrl
)), this, SLOT(handleUrl(KUrl
)));
1771 infoDock
->setWidget(infoPanel
);
1773 QAction
* infoAction
= infoDock
->toggleViewAction();
1774 createPanelAction(KIcon("dialog-information"), Qt::Key_F11
, infoAction
, "show_information_panel");
1776 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
1777 connect(this, SIGNAL(urlChanged(KUrl
)),
1778 infoPanel
, SLOT(setUrl(KUrl
)));
1779 connect(this, SIGNAL(selectionChanged(KFileItemList
)),
1780 infoPanel
, SLOT(setSelection(KFileItemList
)));
1781 connect(this, SIGNAL(requestItemInfo(KFileItem
)),
1782 infoPanel
, SLOT(requestDelayedItemInfo(KFileItem
)));
1785 DolphinDockWidget
* foldersDock
= new DolphinDockWidget(i18nc("@title:window", "Folders"));
1786 foldersDock
->setLocked(lock
);
1787 foldersDock
->setObjectName("foldersDock");
1788 foldersDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1789 FoldersPanel
* foldersPanel
= new FoldersPanel(foldersDock
);
1790 foldersPanel
->setCustomContextMenuActions(QList
<QAction
*>() << lockLayoutAction
);
1791 foldersDock
->setWidget(foldersPanel
);
1793 QAction
* foldersAction
= foldersDock
->toggleViewAction();
1794 createPanelAction(KIcon("folder"), Qt::Key_F7
, foldersAction
, "show_folders_panel");
1796 addDockWidget(Qt::LeftDockWidgetArea
, foldersDock
);
1797 connect(this, SIGNAL(urlChanged(KUrl
)),
1798 foldersPanel
, SLOT(setUrl(KUrl
)));
1799 connect(foldersPanel
, SIGNAL(changeUrl(KUrl
,Qt::MouseButtons
)),
1800 this, SLOT(handlePlacesClick(KUrl
,Qt::MouseButtons
)));
1804 DolphinDockWidget
* terminalDock
= new DolphinDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
1805 terminalDock
->setLocked(lock
);
1806 terminalDock
->setObjectName("terminalDock");
1807 terminalDock
->setAllowedAreas(Qt::TopDockWidgetArea
| Qt::BottomDockWidgetArea
);
1808 Panel
* terminalPanel
= new TerminalPanel(terminalDock
);
1809 terminalPanel
->setCustomContextMenuActions(QList
<QAction
*>() << lockLayoutAction
);
1810 terminalDock
->setWidget(terminalPanel
);
1812 connect(terminalPanel
, SIGNAL(hideTerminalPanel()), terminalDock
, SLOT(hide()));
1813 connect(terminalDock
, SIGNAL(visibilityChanged(bool)),
1814 terminalPanel
, SLOT(dockVisibilityChanged()));
1816 QAction
* terminalAction
= terminalDock
->toggleViewAction();
1817 createPanelAction(KIcon("utilities-terminal"), Qt::Key_F4
, terminalAction
, "show_terminal_panel");
1819 addDockWidget(Qt::BottomDockWidgetArea
, terminalDock
);
1820 connect(this, SIGNAL(urlChanged(KUrl
)),
1821 terminalPanel
, SLOT(setUrl(KUrl
)));
1826 DolphinDockWidget
* searchDock
= new DolphinDockWidget(i18nc("@title:window", "Search"));
1827 searchDock
->setLocked(lock
);
1828 searchDock
->setObjectName("searchDock");
1829 searchDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1830 Panel
* searchPanel
= new SearchPanel(searchDock
);
1831 searchPanel
->setCustomContextMenuActions(QList
<QAction
*>() << lockLayoutAction
);
1832 connect(searchPanel
, SIGNAL(urlActivated(KUrl
)), this, SLOT(handleUrl(KUrl
)));
1833 searchDock
->setWidget(searchPanel
);
1835 QAction
* searchAction
= searchDock
->toggleViewAction();
1836 createPanelAction(KIcon("system-search"), Qt::Key_F12
, searchAction
, "show_search_panel");
1837 addDockWidget(Qt::RightDockWidgetArea
, searchDock
);
1838 connect(this, SIGNAL(urlChanged(KUrl
)),
1839 searchPanel
, SLOT(setUrl(KUrl
)));
1842 if (GeneralSettings::version() < 200) {
1844 foldersDock
->hide();
1846 terminalDock
->hide();
1854 DolphinDockWidget
* placesDock
= new DolphinDockWidget(i18nc("@title:window", "Places"));
1855 placesDock
->setLocked(lock
);
1856 placesDock
->setObjectName("placesDock");
1857 placesDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1859 PlacesPanel
* placesPanel
= new PlacesPanel(placesDock
);
1860 QAction
* separator
= new QAction(placesPanel
);
1861 separator
->setSeparator(true);
1862 QList
<QAction
*> placesActions
;
1863 placesActions
.append(separator
);
1864 placesActions
.append(lockLayoutAction
);
1865 placesPanel
->addActions(placesActions
);
1866 placesPanel
->setModel(DolphinPlacesModel::instance());
1867 placesPanel
->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff
);
1868 placesDock
->setWidget(placesPanel
);
1870 QAction
* placesAction
= placesDock
->toggleViewAction();
1871 createPanelAction(KIcon("bookmarks"), Qt::Key_F9
, placesAction
, "show_places_panel");
1873 addDockWidget(Qt::LeftDockWidgetArea
, placesDock
);
1874 connect(placesPanel
, SIGNAL(urlChanged(KUrl
,Qt::MouseButtons
)),
1875 this, SLOT(handlePlacesClick(KUrl
,Qt::MouseButtons
)));
1876 connect(this, SIGNAL(urlChanged(KUrl
)),
1877 placesPanel
, SLOT(setUrl(KUrl
)));
1878 connect(placesDock
, SIGNAL(visibilityChanged(bool)),
1879 this, SLOT(slotPlacesPanelVisibilityChanged(bool)));
1881 // Add actions into the "Panels" menu
1882 KActionMenu
* panelsMenu
= new KActionMenu(i18nc("@action:inmenu View", "Panels"), this);
1883 actionCollection()->addAction("panels", panelsMenu
);
1884 panelsMenu
->setDelayed(false);
1885 const KActionCollection
* ac
= actionCollection();
1886 panelsMenu
->addAction(ac
->action("show_places_panel"));
1887 panelsMenu
->addAction(ac
->action("show_information_panel"));
1888 panelsMenu
->addAction(ac
->action("show_folders_panel"));
1890 panelsMenu
->addAction(ac
->action("show_terminal_panel"));
1893 panelsMenu
->addAction(ac
->action("show_search_panel"));
1895 panelsMenu
->addSeparator();
1896 panelsMenu
->addAction(lockLayoutAction
);
1899 void DolphinMainWindow::updateEditActions()
1901 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
1902 if (list
.isEmpty()) {
1903 stateChanged("has_no_selection");
1905 stateChanged("has_selection");
1907 KActionCollection
* col
= actionCollection();
1908 QAction
* renameAction
= col
->action("rename");
1909 QAction
* moveToTrashAction
= col
->action("move_to_trash");
1910 QAction
* deleteAction
= col
->action("delete");
1911 QAction
* cutAction
= col
->action(KStandardAction::name(KStandardAction::Cut
));
1912 QAction
* deleteWithTrashShortcut
= col
->action("delete_shortcut"); // see DolphinViewActionHandler
1914 KFileItemListProperties
capabilities(list
);
1915 const bool enableMoveToTrash
= capabilities
.isLocal() && capabilities
.supportsMoving();
1917 renameAction
->setEnabled(capabilities
.supportsMoving());
1918 moveToTrashAction
->setEnabled(enableMoveToTrash
);
1919 deleteAction
->setEnabled(capabilities
.supportsDeleting());
1920 deleteWithTrashShortcut
->setEnabled(capabilities
.supportsDeleting() && !enableMoveToTrash
);
1921 cutAction
->setEnabled(capabilities
.supportsMoving());
1923 updatePasteAction();
1926 void DolphinMainWindow::updateViewActions()
1928 m_actionHandler
->updateViewActions();
1930 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
1931 showFilterBarAction
->setChecked(m_activeViewContainer
->isFilterBarVisible());
1933 updateSplitAction();
1935 QAction
* editableLocactionAction
= actionCollection()->action("editable_location");
1936 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
1937 editableLocactionAction
->setChecked(urlNavigator
->isUrlEditable());
1940 void DolphinMainWindow::updateGoActions()
1942 QAction
* goUpAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Up
));
1943 const KUrl currentUrl
= m_activeViewContainer
->url();
1944 goUpAction
->setEnabled(currentUrl
.upUrl() != currentUrl
);
1947 void DolphinMainWindow::createToolBarMenuButton()
1949 if (m_toolBarSpacer
&& m_openToolBarMenuButton
) {
1952 Q_ASSERT(!m_toolBarSpacer
);
1953 Q_ASSERT(!m_openToolBarMenuButton
);
1955 m_toolBarSpacer
= new QWidget(this);
1956 m_toolBarSpacer
->setSizePolicy(QSizePolicy::MinimumExpanding
, QSizePolicy::MinimumExpanding
);
1958 m_openToolBarMenuButton
= new QToolButton(this);
1959 m_openToolBarMenuButton
->setIcon(KIcon("configure"));
1960 m_openToolBarMenuButton
->setPopupMode(QToolButton::InstantPopup
);
1961 m_openToolBarMenuButton
->setToolTip(i18nc("@info:tooltip", "Configure and control Dolphin"));
1963 KMenu
* toolBarMenu
= new ToolBarMenu(m_openToolBarMenuButton
);
1964 connect(toolBarMenu
, SIGNAL(aboutToShow()), this, SLOT(updateToolBarMenu()));
1966 m_openToolBarMenuButton
->setMenu(toolBarMenu
);
1968 toolBar()->addWidget(m_toolBarSpacer
);
1969 toolBar()->addWidget(m_openToolBarMenuButton
);
1970 connect(toolBar(), SIGNAL(iconSizeChanged(QSize
)), this, SLOT(slotToolBarIconSizeChanged(QSize
)));
1972 // The added widgets are owned by the toolbar and may get deleted when e.g. the toolbar
1973 // gets edited. In this case we must add them again. The adding is done asynchronously by
1974 // m_updateToolBarTimer.
1975 connect(m_toolBarSpacer
, SIGNAL(destroyed()), this, SLOT(slotToolBarSpacerDeleted()));
1976 connect(m_openToolBarMenuButton
, SIGNAL(destroyed()), this, SLOT(slotToolBarMenuButtonDeleted()));
1977 m_updateToolBarTimer
= new QTimer(this);
1978 m_updateToolBarTimer
->setInterval(500);
1979 connect(m_updateToolBarTimer
, SIGNAL(timeout()), this, SLOT(updateToolBar()));
1982 void DolphinMainWindow::deleteToolBarMenuButton()
1984 delete m_toolBarSpacer
;
1985 m_toolBarSpacer
= 0;
1987 delete m_openToolBarMenuButton
;
1988 m_openToolBarMenuButton
= 0;
1990 delete m_updateToolBarTimer
;
1991 m_updateToolBarTimer
= 0;
1994 bool DolphinMainWindow::addActionToMenu(QAction
* action
, KMenu
* menu
)
1999 const KToolBar
* toolBarWidget
= toolBar();
2000 foreach (const QWidget
* widget
, action
->associatedWidgets()) {
2001 if (widget
== toolBarWidget
) {
2006 menu
->addAction(action
);
2010 void DolphinMainWindow::rememberClosedTab(int index
)
2012 KMenu
* tabsMenu
= m_recentTabsMenu
->menu();
2014 const QString primaryPath
= m_viewTab
[index
].primaryView
->url().path();
2015 const QString iconName
= KMimeType::iconNameForUrl(primaryPath
);
2017 QAction
* action
= new QAction(squeezedText(primaryPath
), tabsMenu
);
2019 ClosedTab closedTab
;
2020 closedTab
.primaryUrl
= m_viewTab
[index
].primaryView
->url();
2022 if (m_viewTab
[index
].secondaryView
) {
2023 closedTab
.secondaryUrl
= m_viewTab
[index
].secondaryView
->url();
2024 closedTab
.isSplit
= true;
2026 closedTab
.isSplit
= false;
2029 action
->setData(QVariant::fromValue(closedTab
));
2030 action
->setIcon(KIcon(iconName
));
2032 // add the closed tab menu entry after the separator and
2033 // "Empty Recently Closed Tabs" entry
2034 if (tabsMenu
->actions().size() == 2) {
2035 tabsMenu
->addAction(action
);
2037 tabsMenu
->insertAction(tabsMenu
->actions().at(2), action
);
2040 // assure that only up to 8 closed tabs are shown in the menu
2041 if (tabsMenu
->actions().size() > 8) {
2042 tabsMenu
->removeAction(tabsMenu
->actions().last());
2044 actionCollection()->action("closed_tabs")->setEnabled(true);
2045 KAcceleratorManager::manage(tabsMenu
);
2048 void DolphinMainWindow::refreshViews()
2050 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
);
2052 // remember the current active view, as because of
2053 // the refreshing the active view might change to
2054 // the secondary view
2055 DolphinViewContainer
* activeViewContainer
= m_activeViewContainer
;
2057 const int tabCount
= m_viewTab
.count();
2058 for (int i
= 0; i
< tabCount
; ++i
) {
2059 m_viewTab
[i
].primaryView
->refresh();
2060 if (m_viewTab
[i
].secondaryView
) {
2061 m_viewTab
[i
].secondaryView
->refresh();
2065 setActiveViewContainer(activeViewContainer
);
2067 if (GeneralSettings::modifiedStartupSettings()) {
2068 // The startup settings have been changed by the user (see bug #254947).
2069 // Synchronize the split-view setting with the active view:
2070 const bool splitView
= GeneralSettings::splitView();
2071 const ViewTab
& activeTab
= m_viewTab
[m_tabIndex
];
2072 const bool toggle
= ( splitView
&& !activeTab
.secondaryView
)
2073 || (!splitView
&& activeTab
.secondaryView
);
2080 void DolphinMainWindow::clearStatusBar()
2082 m_activeViewContainer
->statusBar()->clear();
2085 void DolphinMainWindow::connectViewSignals(DolphinViewContainer
* container
)
2087 connect(container
, SIGNAL(showFilterBarChanged(bool)),
2088 this, SLOT(updateFilterBarAction(bool)));
2089 connect(container
, SIGNAL(writeStateChanged(bool)),
2090 this, SLOT(slotWriteStateChanged(bool)));
2091 connect(container
, SIGNAL(searchModeChanged(bool)),
2092 this, SLOT(slotSearchModeChanged(bool)));
2094 const DolphinSearchBox
* searchBox
= container
->searchBox();
2095 connect(searchBox
, SIGNAL(searchLocationChanged(SearchLocation
)),
2096 this, SLOT(slotSearchLocationChanged()));
2098 DolphinView
* view
= container
->view();
2099 connect(view
, SIGNAL(selectionChanged(KFileItemList
)),
2100 this, SLOT(slotSelectionChanged(KFileItemList
)));
2101 connect(view
, SIGNAL(requestItemInfo(KFileItem
)),
2102 this, SLOT(slotRequestItemInfo(KFileItem
)));
2103 connect(view
, SIGNAL(activated()),
2104 this, SLOT(toggleActiveView()));
2105 connect(view
, SIGNAL(tabRequested(KUrl
)),
2106 this, SLOT(openNewTab(KUrl
)));
2107 connect(view
, SIGNAL(requestContextMenu(QPoint
,KFileItem
,KUrl
,QList
<QAction
*>)),
2108 this, SLOT(openContextMenu(QPoint
,KFileItem
,KUrl
,QList
<QAction
*>)));
2109 connect(view
, SIGNAL(startedPathLoading(KUrl
)),
2110 this, SLOT(enableStopAction()));
2111 connect(view
, SIGNAL(finishedPathLoading(KUrl
)),
2112 this, SLOT(disableStopAction()));
2114 const KUrlNavigator
* navigator
= container
->urlNavigator();
2115 connect(navigator
, SIGNAL(urlChanged(KUrl
)),
2116 this, SLOT(changeUrl(KUrl
)));
2117 connect(navigator
, SIGNAL(historyChanged()),
2118 this, SLOT(updateHistory()));
2119 connect(navigator
, SIGNAL(editableStateChanged(bool)),
2120 this, SLOT(slotEditableStateChanged(bool)));
2121 connect(navigator
, SIGNAL(tabRequested(KUrl
)),
2122 this, SLOT(openNewTab(KUrl
)));
2125 void DolphinMainWindow::updateSplitAction()
2127 QAction
* splitAction
= actionCollection()->action("split_view");
2128 if (m_viewTab
[m_tabIndex
].secondaryView
) {
2129 if (m_activeViewContainer
== m_viewTab
[m_tabIndex
].secondaryView
) {
2130 splitAction
->setText(i18nc("@action:intoolbar Close right view", "Close"));
2131 splitAction
->setToolTip(i18nc("@info", "Close right view"));
2132 splitAction
->setIcon(KIcon("view-right-close"));
2134 splitAction
->setText(i18nc("@action:intoolbar Close left view", "Close"));
2135 splitAction
->setToolTip(i18nc("@info", "Close left view"));
2136 splitAction
->setIcon(KIcon("view-left-close"));
2139 splitAction
->setText(i18nc("@action:intoolbar Split view", "Split"));
2140 splitAction
->setToolTip(i18nc("@info", "Split view"));
2141 splitAction
->setIcon(KIcon("view-right-new"));
2145 QString
DolphinMainWindow::tabName(const KUrl
& url
) const
2148 if (url
.equals(KUrl("file:///"))) {
2151 name
= url
.fileName();
2152 if (name
.isEmpty()) {
2153 name
= url
.protocol();
2155 // Make sure that a '&' inside the directory name is displayed correctly
2156 // and not misinterpreted as a keyboard shortcut in QTabBar::setTabText()
2157 name
.replace('&', "&&");
2163 bool DolphinMainWindow::isKompareInstalled() const
2165 static bool initialized
= false;
2166 static bool installed
= false;
2168 // TODO: maybe replace this approach later by using a menu
2169 // plugin like kdiff3plugin.cpp
2170 installed
= !KGlobal::dirs()->findExe("kompare").isEmpty();
2176 void DolphinMainWindow::createSecondaryView(int tabIndex
)
2178 ViewTab
& viewTab
= m_viewTab
[tabIndex
];
2180 QSplitter
* splitter
= viewTab
.splitter
;
2181 const int newWidth
= (viewTab
.primaryView
->width() - splitter
->handleWidth()) / 2;
2183 const DolphinView
* view
= viewTab
.primaryView
->view();
2184 viewTab
.secondaryView
= createViewContainer(view
->url(), 0);
2185 splitter
->addWidget(viewTab
.secondaryView
);
2186 splitter
->setSizes(QList
<int>() << newWidth
<< newWidth
);
2188 connectViewSignals(viewTab
.secondaryView
);
2189 viewTab
.secondaryView
->setActive(false);
2190 viewTab
.secondaryView
->resize(newWidth
, viewTab
.primaryView
->height());
2191 viewTab
.secondaryView
->show();
2194 QString
DolphinMainWindow::tabProperty(const QString
& property
, int tabIndex
) const
2196 return "Tab " + QString::number(tabIndex
) + ' ' + property
;
2199 void DolphinMainWindow::setUrlAsCaption(const KUrl
& url
)
2202 if (!url
.isLocalFile()) {
2203 caption
.append(url
.protocol() + " - ");
2204 if (url
.hasHost()) {
2205 caption
.append(url
.host() + " - ");
2209 const QString fileName
= url
.fileName().isEmpty() ? "/" : url
.fileName();
2210 caption
.append(fileName
);
2212 setCaption(caption
);
2215 QString
DolphinMainWindow::squeezedText(const QString
& text
) const
2217 const QFontMetrics fm
= fontMetrics();
2218 return fm
.elidedText(text
, Qt::ElideMiddle
, fm
.maxWidth() * 10);
2221 void DolphinMainWindow::createPanelAction(const KIcon
& icon
,
2222 const QKeySequence
& shortcut
,
2223 QAction
* dockAction
,
2224 const QString
& actionName
)
2226 KAction
* panelAction
= actionCollection()->addAction(actionName
);
2227 panelAction
->setCheckable(true);
2228 panelAction
->setChecked(dockAction
->isChecked());
2229 panelAction
->setText(dockAction
->text());
2230 panelAction
->setIcon(icon
);
2231 panelAction
->setShortcut(shortcut
);
2233 connect(panelAction
, SIGNAL(triggered()), dockAction
, SLOT(trigger()));
2234 connect(dockAction
, SIGNAL(toggled(bool)), panelAction
, SLOT(setChecked(bool)));
2237 DolphinMainWindow::UndoUiInterface::UndoUiInterface() :
2238 KIO::FileUndoManager::UiInterface()
2242 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
2246 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
* job
)
2248 DolphinMainWindow
* mainWin
= qobject_cast
<DolphinMainWindow
*>(parentWidget());
2250 DolphinStatusBar
* statusBar
= mainWin
->activeViewContainer()->statusBar();
2251 statusBar
->setMessage(job
->errorString(), DolphinStatusBar::Error
);
2253 KIO::FileUndoManager::UiInterface::jobError(job
);
2257 ToolBarMenu::ToolBarMenu(QWidget
* parent
) :
2262 ToolBarMenu::~ToolBarMenu()
2266 void ToolBarMenu::showEvent(QShowEvent
* event
)
2268 KMenu::showEvent(event
);
2270 // Adjust the position of the menu to be shown within the
2271 // Dolphin window to reduce the cases that sub-menus might overlap
2272 // the right screen border.
2274 QWidget
* button
= parentWidget();
2275 if (layoutDirection() == Qt::RightToLeft
) {
2276 pos
= button
->mapToGlobal(QPoint(0, button
->height()));
2278 pos
= button
->mapToGlobal(QPoint(button
->width(), button
->height()));
2279 pos
.rx() -= width();
2282 // Assure that the menu is not shown outside the screen boundaries and
2283 // that it does not overlap with the parent button.
2284 const QRect screen
= QApplication::desktop()->screenGeometry(QCursor::pos());
2285 if (pos
.x() < screen
.x()) {
2286 pos
.rx() = screen
.x();
2287 } else if (pos
.x() + width() > screen
.x() + screen
.width()) {
2288 pos
.rx() = screen
.x() + screen
.width() - width();
2291 if (pos
.y() < screen
.y()) {
2292 pos
.ry() = screen
.y();
2293 } else if (pos
.y() + height() > screen
.y() + screen
.height()) {
2294 pos
.ry() = button
->mapToGlobal(QPoint(0, 0)).y() - height();
2300 #include "dolphinmainwindow.moc"