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());
160 KIO::FileUndoManager
* undoManager
= KIO::FileUndoManager::self();
161 undoManager
->setUiInterface(new UndoUiInterface());
163 connect(undoManager
, SIGNAL(undoAvailable(bool)),
164 this, SLOT(slotUndoAvailable(bool)));
165 connect(undoManager
, SIGNAL(undoTextChanged(QString
)),
166 this, SLOT(slotUndoTextChanged(QString
)));
167 connect(undoManager
, SIGNAL(jobRecordingStarted(CommandType
)),
168 this, SLOT(clearStatusBar()));
169 connect(undoManager
, SIGNAL(jobRecordingFinished(CommandType
)),
170 this, SLOT(showCommand(CommandType
)));
172 GeneralSettings
* generalSettings
= GeneralSettings::self();
173 const bool firstRun
= (generalSettings
->version() < 200);
175 generalSettings
->setViewPropsTimestamp(QDateTime::currentDateTime());
178 setAcceptDrops(true);
180 m_viewTab
[m_tabIndex
].splitter
= new QSplitter(this);
181 m_viewTab
[m_tabIndex
].splitter
->setChildrenCollapsible(false);
185 const KUrl
homeUrl(generalSettings
->homeUrl());
186 setUrlAsCaption(homeUrl
);
187 m_actionHandler
= new DolphinViewActionHandler(actionCollection(), this);
188 connect(m_actionHandler
, SIGNAL(actionBeingHandled()), SLOT(clearStatusBar()));
189 connect(m_actionHandler
, SIGNAL(createDirectory()), SLOT(createDirectory()));
191 m_viewTab
[m_tabIndex
].primaryView
= createViewContainer(homeUrl
, m_viewTab
[m_tabIndex
].splitter
);
193 m_activeViewContainer
= m_viewTab
[m_tabIndex
].primaryView
;
194 connectViewSignals(m_activeViewContainer
);
195 DolphinView
* view
= m_activeViewContainer
->view();
196 m_activeViewContainer
->show();
197 m_actionHandler
->setCurrentView(view
);
199 m_remoteEncoding
= new DolphinRemoteEncoding(this, m_actionHandler
);
200 connect(this, SIGNAL(urlChanged(KUrl
)),
201 m_remoteEncoding
, SLOT(slotAboutToOpenUrl()));
203 m_tabBar
= new KTabBar(this);
204 m_tabBar
->setMovable(true);
205 m_tabBar
->setTabsClosable(true);
206 connect(m_tabBar
, SIGNAL(currentChanged(int)),
207 this, SLOT(setActiveTab(int)));
208 connect(m_tabBar
, SIGNAL(tabCloseRequested(int)),
209 this, SLOT(closeTab(int)));
210 connect(m_tabBar
, SIGNAL(contextMenu(int,QPoint
)),
211 this, SLOT(openTabContextMenu(int,QPoint
)));
212 connect(m_tabBar
, SIGNAL(newTabRequest()),
213 this, SLOT(openNewTab()));
214 connect(m_tabBar
, SIGNAL(testCanDecode(const QDragMoveEvent
*,bool&)),
215 this, SLOT(slotTestCanDecode(const QDragMoveEvent
*,bool&)));
216 connect(m_tabBar
, SIGNAL(mouseMiddleClick(int)),
217 this, SLOT(closeTab(int)));
218 connect(m_tabBar
, SIGNAL(tabMoved(int,int)),
219 this, SLOT(slotTabMoved(int,int)));
220 connect(m_tabBar
, SIGNAL(receivedDropEvent(int,QDropEvent
*)),
221 this, SLOT(tabDropEvent(int,QDropEvent
*)));
223 m_tabBar
->blockSignals(true); // signals get unblocked after at least 2 tabs are open
225 QWidget
* centralWidget
= new QWidget(this);
226 m_centralWidgetLayout
= new QVBoxLayout(centralWidget
);
227 m_centralWidgetLayout
->setSpacing(0);
228 m_centralWidgetLayout
->setMargin(0);
229 m_centralWidgetLayout
->addWidget(m_tabBar
);
230 m_centralWidgetLayout
->addWidget(m_viewTab
[m_tabIndex
].splitter
, 1);
232 setCentralWidget(centralWidget
);
234 emit
urlChanged(homeUrl
);
236 setupGUI(Keys
| Save
| Create
| ToolBar
);
237 stateChanged("new_file");
239 QClipboard
* clipboard
= QApplication::clipboard();
240 connect(clipboard
, SIGNAL(dataChanged()),
241 this, SLOT(updatePasteAction()));
243 if (generalSettings
->splitView()) {
250 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
251 showFilterBarAction
->setChecked(generalSettings
->filterBar());
254 menuBar()->setVisible(false);
255 // Assure a proper default size if Dolphin runs the first time
259 const bool showMenu
= !menuBar()->isHidden();
260 QAction
* showMenuBarAction
= actionCollection()->action(KStandardAction::name(KStandardAction::ShowMenubar
));
261 showMenuBarAction
->setChecked(showMenu
); // workaround for bug #171080
263 createToolBarMenuButton();
267 DolphinMainWindow::~DolphinMainWindow()
271 void DolphinMainWindow::openDirectories(const QList
<KUrl
>& dirs
)
273 if (dirs
.isEmpty()) {
277 if (dirs
.count() == 1) {
278 m_activeViewContainer
->setUrl(dirs
.first());
282 const int oldOpenTabsCount
= m_viewTab
.count();
284 const bool hasSplitView
= GeneralSettings::splitView();
286 // Open each directory inside a new tab. If the "split view" option has been enabled,
287 // always show two directories within one tab.
288 QList
<KUrl
>::const_iterator it
= dirs
.begin();
289 while (it
!= dirs
.end()) {
293 if (hasSplitView
&& (it
!= dirs
.end())) {
294 const int tabIndex
= m_viewTab
.count() - 1;
295 m_viewTab
[tabIndex
].secondaryView
->setUrl(*it
);
300 // Remove the previously opened tabs
301 for (int i
= 0; i
< oldOpenTabsCount
; ++i
) {
306 void DolphinMainWindow::openFiles(const QList
<KUrl
>& files
)
308 if (files
.isEmpty()) {
312 // Get all distinct directories from 'files' and open a tab
313 // for each directory. If the "split view" option is enabled, two
314 // directories are shown inside one tab (see openDirectories()).
316 foreach (const KUrl
& url
, files
) {
317 const KUrl
dir(url
.directory());
318 if (!dirs
.contains(dir
)) {
323 openDirectories(dirs
);
325 // Select the files. Although the files can be split between several
326 // tabs, there is no need to split 'files' accordingly, as
327 // the DolphinView will just ignore invalid selections.
328 const int tabCount
= m_viewTab
.count();
329 for (int i
= 0; i
< tabCount
; ++i
) {
330 m_viewTab
[i
].primaryView
->view()->markUrlsAsSelected(files
);
331 m_viewTab
[i
].primaryView
->view()->markUrlAsCurrent(files
.at(0));
332 if (m_viewTab
[i
].secondaryView
) {
333 m_viewTab
[i
].secondaryView
->view()->markUrlsAsSelected(files
);
334 m_viewTab
[i
].secondaryView
->view()->markUrlAsCurrent(files
.at(0));
339 void DolphinMainWindow::showCommand(CommandType command
)
341 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
343 case KIO::FileUndoManager::Copy
:
344 statusBar
->setMessage(i18nc("@info:status", "Successfully copied."),
345 DolphinStatusBar::OperationCompleted
);
347 case KIO::FileUndoManager::Move
:
348 statusBar
->setMessage(i18nc("@info:status", "Successfully moved."),
349 DolphinStatusBar::OperationCompleted
);
351 case KIO::FileUndoManager::Link
:
352 statusBar
->setMessage(i18nc("@info:status", "Successfully linked."),
353 DolphinStatusBar::OperationCompleted
);
355 case KIO::FileUndoManager::Trash
:
356 statusBar
->setMessage(i18nc("@info:status", "Successfully moved to trash."),
357 DolphinStatusBar::OperationCompleted
);
359 case KIO::FileUndoManager::Rename
:
360 statusBar
->setMessage(i18nc("@info:status", "Successfully renamed."),
361 DolphinStatusBar::OperationCompleted
);
364 case KIO::FileUndoManager::Mkdir
:
365 statusBar
->setMessage(i18nc("@info:status", "Created folder."),
366 DolphinStatusBar::OperationCompleted
);
374 void DolphinMainWindow::pasteIntoFolder()
376 m_activeViewContainer
->view()->pasteIntoFolder();
379 void DolphinMainWindow::changeUrl(const KUrl
& url
)
381 if (!KProtocolManager::supportsListing(url
)) {
382 // The URL navigator only checks for validity, not
383 // if the URL can be listed. An error message is
384 // shown due to DolphinViewContainer::restoreView().
388 DolphinViewContainer
* view
= activeViewContainer();
394 setUrlAsCaption(url
);
395 if (m_viewTab
.count() > 1) {
396 m_tabBar
->setTabText(m_tabIndex
, squeezedText(tabName(m_activeViewContainer
->url())));
398 const QString iconName
= KMimeType::iconNameForUrl(url
);
399 m_tabBar
->setTabIcon(m_tabIndex
, KIcon(iconName
));
400 emit
urlChanged(url
);
404 void DolphinMainWindow::slotEditableStateChanged(bool editable
)
406 KToggleAction
* editableLocationAction
=
407 static_cast<KToggleAction
*>(actionCollection()->action("editable_location"));
408 editableLocationAction
->setChecked(editable
);
411 void DolphinMainWindow::slotSelectionChanged(const KFileItemList
& selection
)
415 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
);
416 int selectedUrlsCount
= m_viewTab
[m_tabIndex
].primaryView
->view()->selectedItemsCount();
417 if (m_viewTab
[m_tabIndex
].secondaryView
) {
418 selectedUrlsCount
+= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedItemsCount();
421 QAction
* compareFilesAction
= actionCollection()->action("compare_files");
422 if (selectedUrlsCount
== 2) {
423 compareFilesAction
->setEnabled(isKompareInstalled());
425 compareFilesAction
->setEnabled(false);
428 emit
selectionChanged(selection
);
431 void DolphinMainWindow::slotRequestItemInfo(const KFileItem
& item
)
433 emit
requestItemInfo(item
);
436 void DolphinMainWindow::updateHistory()
438 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
439 const int index
= urlNavigator
->historyIndex();
441 QAction
* backAction
= actionCollection()->action("go_back");
443 backAction
->setToolTip(i18nc("@info", "Go back"));
444 backAction
->setEnabled(index
< urlNavigator
->historySize() - 1);
447 QAction
* forwardAction
= actionCollection()->action("go_forward");
449 forwardAction
->setToolTip(i18nc("@info", "Go forward"));
450 forwardAction
->setEnabled(index
> 0);
454 void DolphinMainWindow::updateFilterBarAction(bool show
)
456 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
457 showFilterBarAction
->setChecked(show
);
460 void DolphinMainWindow::openNewMainWindow()
462 KRun::run("dolphin", KUrl::List(), this);
465 void DolphinMainWindow::openNewTab()
467 const bool isUrlEditable
= m_activeViewContainer
->urlNavigator()->isUrlEditable();
469 openNewTab(m_activeViewContainer
->url());
470 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
472 // The URL navigator of the new tab should have the same editable state
473 // as the current tab
474 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
475 navigator
->setUrlEditable(isUrlEditable
);
478 // If a new tab is opened and the URL is editable, assure that
479 // the user can edit the URL without manually setting the focus
480 navigator
->setFocus();
484 void DolphinMainWindow::openNewTab(const KUrl
& url
)
486 QWidget
* focusWidget
= QApplication::focusWidget();
488 if (m_viewTab
.count() == 1) {
489 // Only one view is open currently and hence no tab is shown at
490 // all. Before creating a tab for 'url', provide a tab for the current URL.
491 const KUrl currentUrl
= m_activeViewContainer
->url();
492 m_tabBar
->addTab(KIcon(KMimeType::iconNameForUrl(currentUrl
)),
493 squeezedText(tabName(currentUrl
)));
494 m_tabBar
->blockSignals(false);
497 m_tabBar
->addTab(KIcon(KMimeType::iconNameForUrl(url
)),
498 squeezedText(tabName(url
)));
501 viewTab
.splitter
= new QSplitter(this);
502 viewTab
.splitter
->setChildrenCollapsible(false);
503 viewTab
.primaryView
= createViewContainer(url
, viewTab
.splitter
);
504 viewTab
.primaryView
->setActive(false);
505 connectViewSignals(viewTab
.primaryView
);
507 m_viewTab
.append(viewTab
);
509 actionCollection()->action("close_tab")->setEnabled(true);
511 // provide a split view, if the startup settings are set this way
512 if (GeneralSettings::splitView()) {
513 const int tabIndex
= m_viewTab
.count() - 1;
514 createSecondaryView(tabIndex
);
515 m_viewTab
[tabIndex
].secondaryView
->setActive(true);
516 m_viewTab
[tabIndex
].isPrimaryViewActive
= false;
520 // The DolphinViewContainer grabbed the keyboard focus. As the tab is opened
521 // in background, assure that the previous focused widget gets the focus back.
522 focusWidget
->setFocus();
526 void DolphinMainWindow::activateNextTab()
528 if ((m_viewTab
.count() == 1) || (m_tabBar
->count() < 2)) {
532 const int tabIndex
= (m_tabBar
->currentIndex() + 1) % m_tabBar
->count();
533 m_tabBar
->setCurrentIndex(tabIndex
);
536 void DolphinMainWindow::activatePrevTab()
538 if ((m_viewTab
.count() == 1) || (m_tabBar
->count() < 2)) {
542 int tabIndex
= m_tabBar
->currentIndex() - 1;
543 if (tabIndex
== -1) {
544 tabIndex
= m_tabBar
->count() - 1;
546 m_tabBar
->setCurrentIndex(tabIndex
);
549 void DolphinMainWindow::openInNewTab()
551 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
552 if (list
.isEmpty()) {
553 openNewTab(m_activeViewContainer
->url());
554 } else if ((list
.count() == 1) && list
[0].isDir()) {
555 openNewTab(list
[0].url());
559 void DolphinMainWindow::openInNewWindow()
563 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
564 if (list
.isEmpty()) {
565 newWindowUrl
= m_activeViewContainer
->url();
566 } else if ((list
.count() == 1) && list
[0].isDir()) {
567 newWindowUrl
= list
[0].url();
570 if (!newWindowUrl
.isEmpty()) {
571 KRun::run("dolphin", KUrl::List() << newWindowUrl
, this);
575 void DolphinMainWindow::toggleActiveView()
577 if (!m_viewTab
[m_tabIndex
].secondaryView
) {
578 // only one view is available
582 Q_ASSERT(m_activeViewContainer
);
583 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
);
585 DolphinViewContainer
* left
= m_viewTab
[m_tabIndex
].primaryView
;
586 DolphinViewContainer
* right
= m_viewTab
[m_tabIndex
].secondaryView
;
587 setActiveViewContainer(m_activeViewContainer
== right
? left
: right
);
590 void DolphinMainWindow::showEvent(QShowEvent
* event
)
592 KXmlGuiWindow::showEvent(event
);
593 if (!event
->spontaneous()) {
594 m_activeViewContainer
->view()->setFocus();
598 void DolphinMainWindow::closeEvent(QCloseEvent
* event
)
600 // Find out if Dolphin is closed directly by the user or
601 // by the session manager because the session is closed
602 bool closedByUser
= true;
603 DolphinApplication
*application
= qobject_cast
<DolphinApplication
*>(qApp
);
604 if (application
&& application
->sessionSaving()) {
605 closedByUser
= false;
608 if (m_viewTab
.count() > 1 && GeneralSettings::confirmClosingMultipleTabs() && closedByUser
) {
609 // Ask the user if he really wants to quit and close all tabs.
610 // Open a confirmation dialog with 3 buttons:
611 // KDialog::Yes -> Quit
612 // KDialog::No -> Close only the current tab
613 // KDialog::Cancel -> do nothing
614 KDialog
*dialog
= new KDialog(this, Qt::Dialog
);
615 dialog
->setCaption(i18nc("@title:window", "Confirmation"));
616 dialog
->setButtons(KDialog::Yes
| KDialog::No
| KDialog::Cancel
);
617 dialog
->setModal(true);
618 dialog
->setButtonGuiItem(KDialog::Yes
, KStandardGuiItem::quit());
619 dialog
->setButtonGuiItem(KDialog::No
, KGuiItem(i18n("C&lose Current Tab"), KIcon("tab-close")));
620 dialog
->setButtonGuiItem(KDialog::Cancel
, KStandardGuiItem::cancel());
621 dialog
->setDefaultButton(KDialog::Yes
);
623 bool doNotAskAgainCheckboxResult
= false;
625 const int result
= KMessageBox::createKMessageBox(dialog
,
626 QMessageBox::Warning
,
627 i18n("You have multiple tabs open in this window, are you sure you want to quit?"),
629 i18n("Do not ask again"),
630 &doNotAskAgainCheckboxResult
,
631 KMessageBox::Notify
);
633 if (doNotAskAgainCheckboxResult
) {
634 GeneralSettings::setConfirmClosingMultipleTabs(false);
642 // Close only the current tab
650 GeneralSettings::setVersion(CurrentDolphinVersion
);
651 GeneralSettings::self()->writeConfig();
653 if (m_searchDockIsTemporaryVisible
) {
654 QDockWidget
* searchDock
= findChild
<QDockWidget
*>("searchDock");
658 m_searchDockIsTemporaryVisible
= false;
661 KXmlGuiWindow::closeEvent(event
);
664 void DolphinMainWindow::saveProperties(KConfigGroup
& group
)
666 const int tabCount
= m_viewTab
.count();
667 group
.writeEntry("Tab Count", tabCount
);
668 group
.writeEntry("Active Tab Index", m_tabBar
->currentIndex());
670 for (int i
= 0; i
< tabCount
; ++i
) {
671 const DolphinViewContainer
* cont
= m_viewTab
[i
].primaryView
;
672 group
.writeEntry(tabProperty("Primary URL", i
), cont
->url().url());
673 group
.writeEntry(tabProperty("Primary Editable", i
),
674 cont
->urlNavigator()->isUrlEditable());
676 cont
= m_viewTab
[i
].secondaryView
;
678 group
.writeEntry(tabProperty("Secondary URL", i
), cont
->url().url());
679 group
.writeEntry(tabProperty("Secondary Editable", i
),
680 cont
->urlNavigator()->isUrlEditable());
685 void DolphinMainWindow::readProperties(const KConfigGroup
& group
)
687 const int tabCount
= group
.readEntry("Tab Count", 1);
688 for (int i
= 0; i
< tabCount
; ++i
) {
689 DolphinViewContainer
* cont
= m_viewTab
[i
].primaryView
;
691 cont
->setUrl(group
.readEntry(tabProperty("Primary URL", i
)));
692 const bool editable
= group
.readEntry(tabProperty("Primary Editable", i
), false);
693 cont
->urlNavigator()->setUrlEditable(editable
);
695 cont
= m_viewTab
[i
].secondaryView
;
696 const QString secondaryUrl
= group
.readEntry(tabProperty("Secondary URL", i
));
697 if (!secondaryUrl
.isEmpty()) {
699 // a secondary view should be shown, but no one is available
700 // currently -> create a new view
702 cont
= m_viewTab
[i
].secondaryView
;
706 cont
->setUrl(secondaryUrl
);
707 const bool editable
= group
.readEntry(tabProperty("Secondary Editable", i
), false);
708 cont
->urlNavigator()->setUrlEditable(editable
);
710 // no secondary view should be shown, but the default setting shows
711 // one already -> close the view
715 // openNewTab() needs to be called only tabCount - 1 times
716 if (i
!= tabCount
- 1) {
721 const int index
= group
.readEntry("Active Tab Index", 0);
722 m_tabBar
->setCurrentIndex(index
);
725 void DolphinMainWindow::updateNewMenu()
727 m_newFileMenu
->setViewShowsHiddenFiles(activeViewContainer()->view()->hiddenFilesShown());
728 m_newFileMenu
->checkUpToDate();
729 m_newFileMenu
->setPopupFiles(activeViewContainer()->url());
732 void DolphinMainWindow::createDirectory()
734 m_newFileMenu
->setViewShowsHiddenFiles(activeViewContainer()->view()->hiddenFilesShown());
735 m_newFileMenu
->setPopupFiles(activeViewContainer()->url());
736 m_newFileMenu
->createDirectory();
739 void DolphinMainWindow::quit()
744 void DolphinMainWindow::showErrorMessage(const QString
& message
)
746 if (!message
.isEmpty()) {
747 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
748 statusBar
->setMessage(message
, DolphinStatusBar::Error
);
752 void DolphinMainWindow::slotUndoAvailable(bool available
)
754 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
756 undoAction
->setEnabled(available
);
760 void DolphinMainWindow::restoreClosedTab(QAction
* action
)
762 if (action
->data().toBool()) {
763 // clear all actions except the "Empty Recently Closed Tabs"
764 // action and the separator
765 QList
<QAction
*> actions
= m_recentTabsMenu
->menu()->actions();
766 const int count
= actions
.size();
767 for (int i
= 2; i
< count
; ++i
) {
768 m_recentTabsMenu
->menu()->removeAction(actions
.at(i
));
771 const ClosedTab closedTab
= action
->data().value
<ClosedTab
>();
772 openNewTab(closedTab
.primaryUrl
);
773 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
775 if (closedTab
.isSplit
) {
776 // create secondary view
778 m_viewTab
[m_tabIndex
].secondaryView
->setUrl(closedTab
.secondaryUrl
);
781 m_recentTabsMenu
->removeAction(action
);
784 if (m_recentTabsMenu
->menu()->actions().count() == 2) {
785 m_recentTabsMenu
->setEnabled(false);
789 void DolphinMainWindow::slotUndoTextChanged(const QString
& text
)
791 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
793 undoAction
->setText(text
);
797 void DolphinMainWindow::undo()
800 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
801 KIO::FileUndoManager::self()->undo();
804 void DolphinMainWindow::cut()
806 m_activeViewContainer
->view()->cutSelectedItems();
809 void DolphinMainWindow::copy()
811 m_activeViewContainer
->view()->copySelectedItems();
814 void DolphinMainWindow::paste()
816 m_activeViewContainer
->view()->paste();
819 void DolphinMainWindow::find()
821 m_activeViewContainer
->setSearchModeEnabled(true);
824 void DolphinMainWindow::slotSearchLocationChanged()
827 QDockWidget
* searchDock
= findChild
<QDockWidget
*>("searchDock");
832 SearchPanel
* searchPanel
= qobject_cast
<SearchPanel
*>(searchDock
->widget());
834 searchPanel
->setSearchLocation(SearchSettings::location() == QLatin1String("FromHere")
835 ? SearchPanel::FromCurrentDir
836 : SearchPanel::Everywhere
);
841 void DolphinMainWindow::updatePasteAction()
843 QAction
* pasteAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Paste
));
844 QPair
<bool, QString
> pasteInfo
= m_activeViewContainer
->view()->pasteInfo();
845 pasteAction
->setEnabled(pasteInfo
.first
);
846 pasteAction
->setText(pasteInfo
.second
);
849 void DolphinMainWindow::selectAll()
853 // if the URL navigator is editable and focused, select the whole
854 // URL instead of all items of the view
856 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
857 QLineEdit
* lineEdit
= urlNavigator
->editor()->lineEdit(); // krazy:exclude=qclasses
858 const bool selectUrl
= urlNavigator
->isUrlEditable() &&
859 lineEdit
->hasFocus();
861 lineEdit
->selectAll();
863 m_activeViewContainer
->view()->selectAll();
867 void DolphinMainWindow::invertSelection()
870 m_activeViewContainer
->view()->invertSelection();
873 void DolphinMainWindow::toggleSplitView()
875 if (!m_viewTab
[m_tabIndex
].secondaryView
) {
876 createSecondaryView(m_tabIndex
);
877 setActiveViewContainer(m_viewTab
[m_tabIndex
].secondaryView
);
878 } else if (m_activeViewContainer
== m_viewTab
[m_tabIndex
].secondaryView
) {
879 // remove secondary view
880 m_viewTab
[m_tabIndex
].secondaryView
->close();
881 m_viewTab
[m_tabIndex
].secondaryView
->deleteLater();
882 m_viewTab
[m_tabIndex
].secondaryView
= 0;
884 setActiveViewContainer(m_viewTab
[m_tabIndex
].primaryView
);
886 // The primary view is active and should be closed. Hence from a users point of view
887 // the content of the secondary view should be moved to the primary view.
888 // From an implementation point of view it is more efficient to close
889 // the primary view and exchange the internal pointers afterwards.
891 m_viewTab
[m_tabIndex
].primaryView
->close();
892 m_viewTab
[m_tabIndex
].primaryView
->deleteLater();
893 m_viewTab
[m_tabIndex
].primaryView
= m_viewTab
[m_tabIndex
].secondaryView
;
894 m_viewTab
[m_tabIndex
].secondaryView
= 0;
896 setActiveViewContainer(m_viewTab
[m_tabIndex
].primaryView
);
902 void DolphinMainWindow::reloadView()
905 m_activeViewContainer
->view()->reload();
908 void DolphinMainWindow::stopLoading()
910 m_activeViewContainer
->view()->stopLoading();
913 void DolphinMainWindow::enableStopAction()
915 actionCollection()->action("stop")->setEnabled(true);
918 void DolphinMainWindow::disableStopAction()
920 actionCollection()->action("stop")->setEnabled(false);
923 void DolphinMainWindow::showFilterBar()
925 m_activeViewContainer
->setFilterBarVisible(true);
928 void DolphinMainWindow::toggleEditLocation()
932 QAction
* action
= actionCollection()->action("editable_location");
933 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
934 urlNavigator
->setUrlEditable(action
->isChecked());
937 void DolphinMainWindow::replaceLocation()
939 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
940 navigator
->setUrlEditable(true);
941 navigator
->setFocus();
943 // select the whole text of the combo box editor
944 QLineEdit
* lineEdit
= navigator
->editor()->lineEdit(); // krazy:exclude=qclasses
945 lineEdit
->selectAll();
948 void DolphinMainWindow::togglePanelLockState()
950 const bool newLockState
= !GeneralSettings::lockPanels();
951 foreach (QObject
* child
, children()) {
952 DolphinDockWidget
* dock
= qobject_cast
<DolphinDockWidget
*>(child
);
954 dock
->setLocked(newLockState
);
958 GeneralSettings::setLockPanels(newLockState
);
961 void DolphinMainWindow::slotPlacesPanelVisibilityChanged(bool visible
)
963 const int tabCount
= m_viewTab
.count();
964 for (int i
= 0; i
< tabCount
; ++i
) {
965 ViewTab
& tab
= m_viewTab
[i
];
966 Q_ASSERT(tab
.primaryView
);
967 tab
.primaryView
->urlNavigator()->setPlacesSelectorVisible(!visible
);
968 if (tab
.secondaryView
) {
969 tab
.secondaryView
->urlNavigator()->setPlacesSelectorVisible(!visible
);
974 void DolphinMainWindow::goBack()
976 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
977 urlNavigator
->goBack();
979 if (urlNavigator
->locationState().isEmpty()) {
980 // An empty location state indicates a redirection URL,
981 // which must be skipped too
982 urlNavigator
->goBack();
986 void DolphinMainWindow::goForward()
988 m_activeViewContainer
->urlNavigator()->goForward();
991 void DolphinMainWindow::goUp()
993 m_activeViewContainer
->urlNavigator()->goUp();
996 void DolphinMainWindow::goHome()
998 m_activeViewContainer
->urlNavigator()->goHome();
1001 void DolphinMainWindow::goBack(Qt::MouseButtons buttons
)
1003 // The default case (left button pressed) is handled in goBack().
1004 if (buttons
== Qt::MidButton
) {
1005 KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigator();
1006 const int index
= urlNavigator
->historyIndex() + 1;
1007 openNewTab(urlNavigator
->locationUrl(index
));
1011 void DolphinMainWindow::goForward(Qt::MouseButtons buttons
)
1013 // The default case (left button pressed) is handled in goForward().
1014 if (buttons
== Qt::MidButton
) {
1015 KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigator();
1016 const int index
= urlNavigator
->historyIndex() - 1;
1017 openNewTab(urlNavigator
->locationUrl(index
));
1021 void DolphinMainWindow::goUp(Qt::MouseButtons buttons
)
1023 // The default case (left button pressed) is handled in goUp().
1024 if (buttons
== Qt::MidButton
) {
1025 openNewTab(activeViewContainer()->url().upUrl());
1029 void DolphinMainWindow::compareFiles()
1031 // The method is only invoked if exactly 2 files have
1032 // been selected. The selected files may be:
1033 // - both in the primary view
1034 // - both in the secondary view
1035 // - one in the primary view and the other in the secondary
1037 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
);
1042 KFileItemList items
= m_viewTab
[m_tabIndex
].primaryView
->view()->selectedItems();
1044 switch (items
.count()) {
1046 Q_ASSERT(m_viewTab
[m_tabIndex
].secondaryView
);
1047 items
= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedItems();
1048 Q_ASSERT(items
.count() == 2);
1049 urlA
= items
[0].url();
1050 urlB
= items
[1].url();
1055 urlA
= items
[0].url();
1056 Q_ASSERT(m_viewTab
[m_tabIndex
].secondaryView
);
1057 items
= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedItems();
1058 Q_ASSERT(items
.count() == 1);
1059 urlB
= items
[0].url();
1064 urlA
= items
[0].url();
1065 urlB
= items
[1].url();
1070 // may not happen: compareFiles may only get invoked if 2
1071 // files are selected
1076 QString
command("kompare -c \"");
1077 command
.append(urlA
.pathOrUrl());
1078 command
.append("\" \"");
1079 command
.append(urlB
.pathOrUrl());
1080 command
.append('\"');
1081 KRun::runCommand(command
, "Kompare", "kompare", this);
1084 void DolphinMainWindow::toggleShowMenuBar()
1086 const bool visible
= menuBar()->isVisible();
1087 menuBar()->setVisible(!visible
);
1089 createToolBarMenuButton();
1091 deleteToolBarMenuButton();
1095 void DolphinMainWindow::openTerminal()
1097 QString
dir(QDir::homePath());
1099 // If the given directory is not local, it can still be the URL of an
1100 // ioslave using UDS_LOCAL_PATH which to be converted first.
1101 KUrl url
= KIO::NetAccess::mostLocalUrl(m_activeViewContainer
->url(), this);
1103 //If the URL is local after the above conversion, set the directory.
1104 if (url
.isLocalFile()) {
1105 dir
= url
.toLocalFile();
1108 KToolInvocation::invokeTerminal(QString(), dir
);
1111 void DolphinMainWindow::editSettings()
1113 if (!m_settingsDialog
) {
1114 const KUrl url
= activeViewContainer()->url();
1115 DolphinSettingsDialog
* settingsDialog
= new DolphinSettingsDialog(url
, this);
1116 connect(settingsDialog
, SIGNAL(settingsChanged()), this, SLOT(refreshViews()));
1117 settingsDialog
->setAttribute(Qt::WA_DeleteOnClose
);
1118 settingsDialog
->show();
1119 m_settingsDialog
= settingsDialog
;
1121 m_settingsDialog
.data()->raise();
1125 void DolphinMainWindow::setActiveTab(int index
)
1127 Q_ASSERT(index
>= 0);
1128 Q_ASSERT(index
< m_viewTab
.count());
1129 if (index
== m_tabIndex
) {
1133 // hide current tab content
1134 ViewTab
& hiddenTab
= m_viewTab
[m_tabIndex
];
1135 hiddenTab
.isPrimaryViewActive
= hiddenTab
.primaryView
->isActive();
1136 hiddenTab
.primaryView
->setActive(false);
1137 if (hiddenTab
.secondaryView
) {
1138 hiddenTab
.secondaryView
->setActive(false);
1140 QSplitter
* splitter
= m_viewTab
[m_tabIndex
].splitter
;
1142 m_centralWidgetLayout
->removeWidget(splitter
);
1144 // show active tab content
1147 ViewTab
& viewTab
= m_viewTab
[index
];
1148 m_centralWidgetLayout
->addWidget(viewTab
.splitter
, 1);
1149 viewTab
.primaryView
->show();
1150 if (viewTab
.secondaryView
) {
1151 viewTab
.secondaryView
->show();
1153 viewTab
.splitter
->show();
1155 setActiveViewContainer(viewTab
.isPrimaryViewActive
? viewTab
.primaryView
:
1156 viewTab
.secondaryView
);
1159 void DolphinMainWindow::closeTab()
1161 closeTab(m_tabBar
->currentIndex());
1164 void DolphinMainWindow::closeTab(int index
)
1166 Q_ASSERT(index
>= 0);
1167 Q_ASSERT(index
< m_viewTab
.count());
1168 if (m_viewTab
.count() == 1) {
1169 // the last tab may never get closed
1173 if (index
== m_tabIndex
) {
1174 // The tab that should be closed is the active tab. Activate the
1175 // previous tab before closing the tab.
1176 m_tabBar
->setCurrentIndex((index
> 0) ? index
- 1 : 1);
1178 rememberClosedTab(index
);
1181 m_viewTab
[index
].primaryView
->deleteLater();
1182 if (m_viewTab
[index
].secondaryView
) {
1183 m_viewTab
[index
].secondaryView
->deleteLater();
1185 m_viewTab
[index
].splitter
->deleteLater();
1186 m_viewTab
.erase(m_viewTab
.begin() + index
);
1188 m_tabBar
->blockSignals(true);
1189 m_tabBar
->removeTab(index
);
1191 if (m_tabIndex
> index
) {
1193 Q_ASSERT(m_tabIndex
>= 0);
1196 // if only one tab is left, also remove the tab entry so that
1197 // closing the last tab is not possible
1198 if (m_viewTab
.count() == 1) {
1199 m_tabBar
->removeTab(0);
1200 actionCollection()->action("close_tab")->setEnabled(false);
1202 m_tabBar
->blockSignals(false);
1206 void DolphinMainWindow::openTabContextMenu(int index
, const QPoint
& pos
)
1210 QAction
* newTabAction
= menu
.addAction(KIcon("tab-new"), i18nc("@action:inmenu", "New Tab"));
1211 newTabAction
->setShortcut(actionCollection()->action("new_tab")->shortcut());
1213 QAction
* detachTabAction
= menu
.addAction(KIcon("tab-detach"), i18nc("@action:inmenu", "Detach Tab"));
1215 QAction
* closeOtherTabsAction
= menu
.addAction(KIcon("tab-close-other"), i18nc("@action:inmenu", "Close Other Tabs"));
1217 QAction
* closeTabAction
= menu
.addAction(KIcon("tab-close"), i18nc("@action:inmenu", "Close Tab"));
1218 closeTabAction
->setShortcut(actionCollection()->action("close_tab")->shortcut());
1219 QAction
* selectedAction
= menu
.exec(pos
);
1220 if (selectedAction
== newTabAction
) {
1221 const ViewTab
& tab
= m_viewTab
[index
];
1222 Q_ASSERT(tab
.primaryView
);
1223 const KUrl url
= tab
.secondaryView
&& tab
.secondaryView
->isActive() ?
1224 tab
.secondaryView
->url() : tab
.primaryView
->url();
1226 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
1227 } else if (selectedAction
== detachTabAction
) {
1228 const QString
separator(QLatin1Char(' '));
1229 QString command
= QLatin1String("dolphin");
1231 const ViewTab
& tab
= m_viewTab
[index
];
1232 Q_ASSERT(tab
.primaryView
);
1234 command
+= separator
+ tab
.primaryView
->url().url();
1235 if (tab
.secondaryView
) {
1236 command
+= separator
+ tab
.secondaryView
->url().url();
1237 command
+= separator
+ QLatin1String("-split");
1240 KRun::runCommand(command
, this);
1243 } else if (selectedAction
== closeOtherTabsAction
) {
1244 const int count
= m_tabBar
->count();
1245 for (int i
= 0; i
< index
; ++i
) {
1248 for (int i
= index
+ 1; i
< count
; ++i
) {
1251 } else if (selectedAction
== closeTabAction
) {
1256 void DolphinMainWindow::slotTabMoved(int from
, int to
)
1258 m_viewTab
.move(from
, to
);
1259 m_tabIndex
= m_tabBar
->currentIndex();
1262 void DolphinMainWindow::handlePlacesClick(const KUrl
& url
, Qt::MouseButtons buttons
)
1264 if (buttons
& Qt::MidButton
) {
1266 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
1272 void DolphinMainWindow::slotTestCanDecode(const QDragMoveEvent
* event
, bool& canDecode
)
1274 canDecode
= KUrl::List::canDecode(event
->mimeData());
1277 void DolphinMainWindow::handleUrl(const KUrl
& url
)
1279 delete m_lastHandleUrlStatJob
;
1280 m_lastHandleUrlStatJob
= 0;
1282 if (url
.isLocalFile() && QFileInfo(url
.toLocalFile()).isDir()) {
1283 activeViewContainer()->setUrl(url
);
1284 } else if (KProtocolManager::supportsListing(url
)) {
1285 // stat the URL to see if it is a dir or not
1286 m_lastHandleUrlStatJob
= KIO::stat(url
, KIO::HideProgressInfo
);
1287 connect(m_lastHandleUrlStatJob
, SIGNAL(result(KJob
*)),
1288 this, SLOT(slotHandleUrlStatFinished(KJob
*)));
1291 new KRun(url
, this);
1295 void DolphinMainWindow::slotHandleUrlStatFinished(KJob
* job
)
1297 m_lastHandleUrlStatJob
= 0;
1298 const KIO::UDSEntry entry
= static_cast<KIO::StatJob
*>(job
)->statResult();
1299 const KUrl url
= static_cast<KIO::StatJob
*>(job
)->url();
1300 if (entry
.isDir()) {
1301 activeViewContainer()->setUrl(url
);
1303 new KRun(url
, this);
1307 void DolphinMainWindow::tabDropEvent(int tab
, QDropEvent
* event
)
1309 const KUrl::List urls
= KUrl::List::fromMimeData(event
->mimeData());
1310 if (!urls
.isEmpty() && tab
!= -1) {
1311 const ViewTab
& viewTab
= m_viewTab
[tab
];
1312 const KUrl destPath
= viewTab
.isPrimaryViewActive
? viewTab
.primaryView
->url() : viewTab
.secondaryView
->url();
1314 //DragAndDropHelper::instance().dropUrls(KFileItem(), destPath, event, m_tabBar);
1318 void DolphinMainWindow::slotWriteStateChanged(bool isFolderWritable
)
1320 newFileMenu()->setEnabled(isFolderWritable
);
1323 void DolphinMainWindow::slotSearchModeChanged(bool enabled
)
1326 const DolphinSearchInformation
& searchInfo
= DolphinSearchInformation::instance();
1327 if (!searchInfo
.isIndexingEnabled()) {
1331 QDockWidget
* searchDock
= findChild
<QDockWidget
*>("searchDock");
1337 if (!searchDock
->isVisible()) {
1338 m_searchDockIsTemporaryVisible
= true;
1342 if (searchDock
->isVisible() && m_searchDockIsTemporaryVisible
) {
1345 m_searchDockIsTemporaryVisible
= false;
1348 SearchPanel
* searchPanel
= qobject_cast
<SearchPanel
*>(searchDock
->widget());
1354 SearchPanel::SearchLocation searchLocation
= SearchPanel::Everywhere
;
1355 const KUrl url
= m_activeViewContainer
->url();
1356 const bool isSearchUrl
= (url
.protocol() == QLatin1String("nepomuksearch"));
1357 if ((SearchSettings::location() == QLatin1String("FromHere") && !isSearchUrl
)) {
1358 searchLocation
= SearchPanel::FromCurrentDir
;
1360 searchPanel
->setSearchLocation(searchLocation
);
1362 searchPanel
->setSearchLocation(SearchPanel::Everywhere
);
1369 void DolphinMainWindow::openContextMenu(const QPoint
& pos
,
1370 const KFileItem
& item
,
1372 const QList
<QAction
*>& customActions
)
1374 QWeakPointer
<DolphinContextMenu
> contextMenu
= new DolphinContextMenu(this, pos
, item
, url
);
1375 contextMenu
.data()->setCustomActions(customActions
);
1376 const DolphinContextMenu::Command command
= contextMenu
.data()->open();
1379 case DolphinContextMenu::OpenParentFolderInNewWindow
: {
1380 KRun::run("dolphin", KUrl::List() << item
.url().upUrl(), this);
1384 case DolphinContextMenu::OpenParentFolderInNewTab
:
1385 openNewTab(item
.url().upUrl());
1388 case DolphinContextMenu::None
:
1393 delete contextMenu
.data();
1396 void DolphinMainWindow::updateToolBarMenu()
1398 KMenu
* menu
= qobject_cast
<KMenu
*>(sender());
1401 // All actions get cleared by KMenu::clear(). The sub-menus are deleted
1402 // by connecting to the aboutToHide() signal from the parent-menu.
1405 KActionCollection
* ac
= actionCollection();
1407 // Add "Edit" actions
1408 bool added
= addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::Undo
)), menu
) |
1409 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::Find
)), menu
) |
1410 addActionToMenu(ac
->action("select_all"), menu
) |
1411 addActionToMenu(ac
->action("invert_selection"), menu
);
1414 menu
->addSeparator();
1417 // Add "View" actions
1418 if (!GeneralSettings::showZoomSlider()) {
1419 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ZoomIn
)), menu
);
1420 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ZoomOut
)), menu
);
1421 menu
->addSeparator();
1424 added
= addActionToMenu(ac
->action("view_mode"), menu
) |
1425 addActionToMenu(ac
->action("sort"), menu
) |
1426 addActionToMenu(ac
->action("additional_info"), menu
) |
1427 addActionToMenu(ac
->action("show_preview"), menu
) |
1428 addActionToMenu(ac
->action("show_in_groups"), menu
) |
1429 addActionToMenu(ac
->action("show_hidden_files"), menu
);
1432 menu
->addSeparator();
1435 added
= addActionToMenu(ac
->action("split_view"), menu
) |
1436 addActionToMenu(ac
->action("reload"), menu
) |
1437 addActionToMenu(ac
->action("view_properties"), menu
);
1439 menu
->addSeparator();
1442 addActionToMenu(ac
->action("panels"), menu
);
1443 KMenu
* locationBarMenu
= new KMenu(i18nc("@action:inmenu", "Location Bar"), menu
);
1444 locationBarMenu
->addAction(ac
->action("editable_location"));
1445 locationBarMenu
->addAction(ac
->action("replace_location"));
1446 menu
->addMenu(locationBarMenu
);
1448 menu
->addSeparator();
1451 KMenu
* goMenu
= new KMenu(i18nc("@action:inmenu", "Go"), menu
);
1452 connect(menu
, SIGNAL(aboutToHide()), goMenu
, SLOT(deleteLater()));
1453 goMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Back
)));
1454 goMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Forward
)));
1455 goMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Up
)));
1456 goMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Home
)));
1457 goMenu
->addAction(ac
->action("closed_tabs"));
1458 menu
->addMenu(goMenu
);
1461 KMenu
* toolsMenu
= new KMenu(i18nc("@action:inmenu", "Tools"), menu
);
1462 connect(menu
, SIGNAL(aboutToHide()), toolsMenu
, SLOT(deleteLater()));
1463 toolsMenu
->addAction(ac
->action("show_filter_bar"));
1464 toolsMenu
->addAction(ac
->action("compare_files"));
1465 toolsMenu
->addAction(ac
->action("open_terminal"));
1466 toolsMenu
->addAction(ac
->action("change_remote_encoding"));
1467 menu
->addMenu(toolsMenu
);
1469 // Add "Settings" menu entries
1470 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::KeyBindings
)), menu
);
1471 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ConfigureToolbars
)), menu
);
1472 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::Preferences
)), menu
);
1475 KMenu
* helpMenu
= new KMenu(i18nc("@action:inmenu", "Help"), menu
);
1476 connect(menu
, SIGNAL(aboutToHide()), helpMenu
, SLOT(deleteLater()));
1477 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::HelpContents
)));
1478 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::WhatsThis
)));
1479 helpMenu
->addSeparator();
1480 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::ReportBug
)));
1481 helpMenu
->addSeparator();
1482 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::SwitchApplicationLanguage
)));
1483 helpMenu
->addSeparator();
1484 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::AboutApp
)));
1485 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::AboutKDE
)));
1486 menu
->addMenu(helpMenu
);
1488 menu
->addSeparator();
1489 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ShowMenubar
)), menu
);
1492 void DolphinMainWindow::updateToolBar()
1494 if (!menuBar()->isVisible()) {
1495 createToolBarMenuButton();
1499 void DolphinMainWindow::slotToolBarSpacerDeleted()
1501 m_toolBarSpacer
= 0;
1502 m_updateToolBarTimer
->start();
1505 void DolphinMainWindow::slotToolBarMenuButtonDeleted()
1507 m_openToolBarMenuButton
= 0;
1508 m_updateToolBarTimer
->start();
1511 void DolphinMainWindow::slotToolBarIconSizeChanged(const QSize
& iconSize
)
1513 if (m_openToolBarMenuButton
) {
1514 m_openToolBarMenuButton
->setIconSize(iconSize
);
1518 void DolphinMainWindow::setActiveViewContainer(DolphinViewContainer
* viewContainer
)
1520 Q_ASSERT(viewContainer
);
1521 Q_ASSERT((viewContainer
== m_viewTab
[m_tabIndex
].primaryView
) ||
1522 (viewContainer
== m_viewTab
[m_tabIndex
].secondaryView
));
1523 if (m_activeViewContainer
== viewContainer
) {
1527 m_activeViewContainer
->setActive(false);
1528 m_activeViewContainer
= viewContainer
;
1530 // Activating the view container might trigger a recursive setActiveViewContainer() call
1531 // inside DolphinMainWindow::toggleActiveView() when having a split view. Temporary
1532 // disconnect the activated() signal in this case:
1533 disconnect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1534 m_activeViewContainer
->setActive(true);
1535 connect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1537 m_actionHandler
->setCurrentView(viewContainer
->view());
1540 updateEditActions();
1541 updateViewActions();
1544 const KUrl url
= m_activeViewContainer
->url();
1545 setUrlAsCaption(url
);
1546 if (m_viewTab
.count() > 1) {
1547 m_tabBar
->setTabText(m_tabIndex
, tabName(url
));
1548 m_tabBar
->setTabIcon(m_tabIndex
, KIcon(KMimeType::iconNameForUrl(url
)));
1551 emit
urlChanged(url
);
1554 DolphinViewContainer
* DolphinMainWindow::createViewContainer(const KUrl
& url
, QWidget
* parent
)
1556 DolphinViewContainer
* container
= new DolphinViewContainer(url
, parent
);
1558 // The places-selector from the URL navigator should only be shown
1559 // if the places dock is invisible
1560 QDockWidget
* placesDock
= findChild
<QDockWidget
*>("placesDock");
1561 container
->urlNavigator()->setPlacesSelectorVisible(!placesDock
|| !placesDock
->isVisible());
1566 void DolphinMainWindow::setupActions()
1568 // setup 'File' menu
1569 m_newFileMenu
= new DolphinNewFileMenu(this);
1570 KMenu
* menu
= m_newFileMenu
->menu();
1571 menu
->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1572 menu
->setIcon(KIcon("document-new"));
1573 connect(menu
, SIGNAL(aboutToShow()),
1574 this, SLOT(updateNewMenu()));
1576 KAction
* newWindow
= actionCollection()->addAction("new_window");
1577 newWindow
->setIcon(KIcon("window-new"));
1578 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
1579 newWindow
->setShortcut(Qt::CTRL
| Qt::Key_N
);
1580 connect(newWindow
, SIGNAL(triggered()), this, SLOT(openNewMainWindow()));
1582 KAction
* newTab
= actionCollection()->addAction("new_tab");
1583 newTab
->setIcon(KIcon("tab-new"));
1584 newTab
->setText(i18nc("@action:inmenu File", "New Tab"));
1585 newTab
->setShortcut(KShortcut(Qt::CTRL
| Qt::Key_T
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_N
));
1586 connect(newTab
, SIGNAL(triggered()), this, SLOT(openNewTab()));
1588 KAction
* closeTab
= actionCollection()->addAction("close_tab");
1589 closeTab
->setIcon(KIcon("tab-close"));
1590 closeTab
->setText(i18nc("@action:inmenu File", "Close Tab"));
1591 closeTab
->setShortcut(Qt::CTRL
| Qt::Key_W
);
1592 closeTab
->setEnabled(false);
1593 connect(closeTab
, SIGNAL(triggered()), this, SLOT(closeTab()));
1595 KStandardAction::quit(this, SLOT(quit()), actionCollection());
1597 // setup 'Edit' menu
1598 KStandardAction::undo(this,
1600 actionCollection());
1602 // need to remove shift+del from cut action, else the shortcut for deletejob
1604 KAction
* cut
= KStandardAction::cut(this, SLOT(cut()), actionCollection());
1605 KShortcut cutShortcut
= cut
->shortcut();
1606 cutShortcut
.remove(Qt::SHIFT
| Qt::Key_Delete
, KShortcut::KeepEmpty
);
1607 cut
->setShortcut(cutShortcut
);
1608 KStandardAction::copy(this, SLOT(copy()), actionCollection());
1609 KAction
* paste
= KStandardAction::paste(this, SLOT(paste()), actionCollection());
1610 // The text of the paste-action is modified dynamically by Dolphin
1611 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1612 // due to the long text, the text "Paste" is used:
1613 paste
->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1615 KStandardAction::find(this, SLOT(find()), actionCollection());
1617 KAction
* selectAll
= actionCollection()->addAction("select_all");
1618 selectAll
->setText(i18nc("@action:inmenu Edit", "Select All"));
1619 selectAll
->setShortcut(Qt::CTRL
| Qt::Key_A
);
1620 connect(selectAll
, SIGNAL(triggered()), this, SLOT(selectAll()));
1622 KAction
* invertSelection
= actionCollection()->addAction("invert_selection");
1623 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1624 invertSelection
->setShortcut(Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
1625 connect(invertSelection
, SIGNAL(triggered()), this, SLOT(invertSelection()));
1627 // setup 'View' menu
1628 // (note that most of it is set up in DolphinViewActionHandler)
1630 KAction
* split
= actionCollection()->addAction("split_view");
1631 split
->setShortcut(Qt::Key_F3
);
1632 updateSplitAction();
1633 connect(split
, SIGNAL(triggered()), this, SLOT(toggleSplitView()));
1635 KAction
* reload
= actionCollection()->addAction("reload");
1636 reload
->setText(i18nc("@action:inmenu View", "Reload"));
1637 reload
->setShortcut(Qt::Key_F5
);
1638 reload
->setIcon(KIcon("view-refresh"));
1639 connect(reload
, SIGNAL(triggered()), this, SLOT(reloadView()));
1641 KAction
* stop
= actionCollection()->addAction("stop");
1642 stop
->setText(i18nc("@action:inmenu View", "Stop"));
1643 stop
->setToolTip(i18nc("@info", "Stop loading"));
1644 stop
->setIcon(KIcon("process-stop"));
1645 connect(stop
, SIGNAL(triggered()), this, SLOT(stopLoading()));
1647 KToggleAction
* editableLocation
= actionCollection()->add
<KToggleAction
>("editable_location");
1648 editableLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1649 editableLocation
->setShortcut(Qt::CTRL
| Qt::Key_L
);
1650 connect(editableLocation
, SIGNAL(triggered()), this, SLOT(toggleEditLocation()));
1652 KAction
* replaceLocation
= actionCollection()->addAction("replace_location");
1653 replaceLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1654 replaceLocation
->setShortcut(Qt::Key_F6
);
1655 connect(replaceLocation
, SIGNAL(triggered()), this, SLOT(replaceLocation()));
1658 KAction
* backAction
= KStandardAction::back(this, SLOT(goBack()), actionCollection());
1659 connect(backAction
, SIGNAL(triggered(Qt::MouseButtons
,Qt::KeyboardModifiers
)), this, SLOT(goBack(Qt::MouseButtons
)));
1660 KShortcut backShortcut
= backAction
->shortcut();
1661 backShortcut
.setAlternate(Qt::Key_Backspace
);
1662 backAction
->setShortcut(backShortcut
);
1664 m_recentTabsMenu
= new KActionMenu(i18n("Recently Closed Tabs"), this);
1665 m_recentTabsMenu
->setIcon(KIcon("edit-undo"));
1666 actionCollection()->addAction("closed_tabs", m_recentTabsMenu
);
1667 connect(m_recentTabsMenu
->menu(), SIGNAL(triggered(QAction
*)),
1668 this, SLOT(restoreClosedTab(QAction
*)));
1670 QAction
* action
= new QAction(i18n("Empty Recently Closed Tabs"), m_recentTabsMenu
);
1671 action
->setIcon(KIcon("edit-clear-list"));
1672 action
->setData(QVariant::fromValue(true));
1673 m_recentTabsMenu
->addAction(action
);
1674 m_recentTabsMenu
->addSeparator();
1675 m_recentTabsMenu
->setEnabled(false);
1677 KAction
* forwardAction
= KStandardAction::forward(this, SLOT(goForward()), actionCollection());
1678 connect(forwardAction
, SIGNAL(triggered(Qt::MouseButtons
,Qt::KeyboardModifiers
)), this, SLOT(goForward(Qt::MouseButtons
)));
1680 KAction
* upAction
= KStandardAction::up(this, SLOT(goUp()), actionCollection());
1681 connect(upAction
, SIGNAL(triggered(Qt::MouseButtons
,Qt::KeyboardModifiers
)), this, SLOT(goUp(Qt::MouseButtons
)));
1683 KStandardAction::home(this, SLOT(goHome()), actionCollection());
1685 // setup 'Tools' menu
1686 KAction
* showFilterBar
= actionCollection()->addAction("show_filter_bar");
1687 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Show Filter Bar"));
1688 showFilterBar
->setIcon(KIcon("view-filter"));
1689 showFilterBar
->setShortcut(Qt::CTRL
| Qt::Key_I
);
1690 connect(showFilterBar
, SIGNAL(triggered()), this, SLOT(showFilterBar()));
1692 KAction
* compareFiles
= actionCollection()->addAction("compare_files");
1693 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1694 compareFiles
->setIcon(KIcon("kompare"));
1695 compareFiles
->setEnabled(false);
1696 connect(compareFiles
, SIGNAL(triggered()), this, SLOT(compareFiles()));
1698 KAction
* openTerminal
= actionCollection()->addAction("open_terminal");
1699 openTerminal
->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
1700 openTerminal
->setIcon(KIcon("utilities-terminal"));
1701 openTerminal
->setShortcut(Qt::SHIFT
| Qt::Key_F4
);
1702 connect(openTerminal
, SIGNAL(triggered()), this, SLOT(openTerminal()));
1704 // setup 'Settings' menu
1705 KToggleAction
* showMenuBar
= KStandardAction::showMenubar(0, 0, actionCollection());
1706 connect(showMenuBar
, SIGNAL(triggered(bool)), // Fixes #286822
1707 this, SLOT(toggleShowMenuBar()), Qt::QueuedConnection
);
1708 KStandardAction::preferences(this, SLOT(editSettings()), actionCollection());
1710 // not in menu actions
1711 QList
<QKeySequence
> nextTabKeys
;
1712 nextTabKeys
.append(KStandardShortcut::tabNext().primary());
1713 nextTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::Key_Tab
));
1715 QList
<QKeySequence
> prevTabKeys
;
1716 prevTabKeys
.append(KStandardShortcut::tabPrev().primary());
1717 prevTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::SHIFT
| Qt::Key_Tab
));
1719 KAction
* activateNextTab
= actionCollection()->addAction("activate_next_tab");
1720 activateNextTab
->setText(i18nc("@action:inmenu", "Activate Next Tab"));
1721 connect(activateNextTab
, SIGNAL(triggered()), SLOT(activateNextTab()));
1722 activateNextTab
->setShortcuts(QApplication::isRightToLeft() ? prevTabKeys
: nextTabKeys
);
1724 KAction
* activatePrevTab
= actionCollection()->addAction("activate_prev_tab");
1725 activatePrevTab
->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
1726 connect(activatePrevTab
, SIGNAL(triggered()), SLOT(activatePrevTab()));
1727 activatePrevTab
->setShortcuts(QApplication::isRightToLeft() ? nextTabKeys
: prevTabKeys
);
1730 KAction
* openInNewTab
= actionCollection()->addAction("open_in_new_tab");
1731 openInNewTab
->setText(i18nc("@action:inmenu", "Open in New Tab"));
1732 openInNewTab
->setIcon(KIcon("tab-new"));
1733 connect(openInNewTab
, SIGNAL(triggered()), this, SLOT(openInNewTab()));
1735 KAction
* openInNewWindow
= actionCollection()->addAction("open_in_new_window");
1736 openInNewWindow
->setText(i18nc("@action:inmenu", "Open in New Window"));
1737 openInNewWindow
->setIcon(KIcon("window-new"));
1738 connect(openInNewWindow
, SIGNAL(triggered()), this, SLOT(openInNewWindow()));
1741 void DolphinMainWindow::setupDockWidgets()
1743 const bool lock
= GeneralSettings::lockPanels();
1745 KDualAction
* lockLayoutAction
= actionCollection()->add
<KDualAction
>("lock_panels");
1746 lockLayoutAction
->setActiveText(i18nc("@action:inmenu Panels", "Unlock Panels"));
1747 lockLayoutAction
->setActiveIcon(KIcon("object-unlocked"));
1748 lockLayoutAction
->setInactiveText(i18nc("@action:inmenu Panels", "Lock Panels"));
1749 lockLayoutAction
->setInactiveIcon(KIcon("object-locked"));
1750 lockLayoutAction
->setActive(lock
);
1751 connect(lockLayoutAction
, SIGNAL(triggered()), this, SLOT(togglePanelLockState()));
1753 // Setup "Information"
1754 DolphinDockWidget
* infoDock
= new DolphinDockWidget(i18nc("@title:window", "Information"));
1755 infoDock
->setLocked(lock
);
1756 infoDock
->setObjectName("infoDock");
1757 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1758 Panel
* infoPanel
= new InformationPanel(infoDock
);
1759 infoPanel
->setCustomContextMenuActions(QList
<QAction
*>() << lockLayoutAction
);
1760 connect(infoPanel
, SIGNAL(urlActivated(KUrl
)), this, SLOT(handleUrl(KUrl
)));
1761 infoDock
->setWidget(infoPanel
);
1763 QAction
* infoAction
= infoDock
->toggleViewAction();
1764 createPanelAction(KIcon("dialog-information"), Qt::Key_F11
, infoAction
, "show_information_panel");
1766 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
1767 connect(this, SIGNAL(urlChanged(KUrl
)),
1768 infoPanel
, SLOT(setUrl(KUrl
)));
1769 connect(this, SIGNAL(selectionChanged(KFileItemList
)),
1770 infoPanel
, SLOT(setSelection(KFileItemList
)));
1771 connect(this, SIGNAL(requestItemInfo(KFileItem
)),
1772 infoPanel
, SLOT(requestDelayedItemInfo(KFileItem
)));
1775 DolphinDockWidget
* foldersDock
= new DolphinDockWidget(i18nc("@title:window", "Folders"));
1776 foldersDock
->setLocked(lock
);
1777 foldersDock
->setObjectName("foldersDock");
1778 foldersDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1779 FoldersPanel
* foldersPanel
= new FoldersPanel(foldersDock
);
1780 foldersPanel
->setCustomContextMenuActions(QList
<QAction
*>() << lockLayoutAction
);
1781 foldersDock
->setWidget(foldersPanel
);
1783 QAction
* foldersAction
= foldersDock
->toggleViewAction();
1784 createPanelAction(KIcon("folder"), Qt::Key_F7
, foldersAction
, "show_folders_panel");
1786 addDockWidget(Qt::LeftDockWidgetArea
, foldersDock
);
1787 connect(this, SIGNAL(urlChanged(KUrl
)),
1788 foldersPanel
, SLOT(setUrl(KUrl
)));
1789 connect(foldersPanel
, SIGNAL(changeUrl(KUrl
,Qt::MouseButtons
)),
1790 this, SLOT(handlePlacesClick(KUrl
,Qt::MouseButtons
)));
1794 DolphinDockWidget
* terminalDock
= new DolphinDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
1795 terminalDock
->setLocked(lock
);
1796 terminalDock
->setObjectName("terminalDock");
1797 terminalDock
->setAllowedAreas(Qt::TopDockWidgetArea
| Qt::BottomDockWidgetArea
);
1798 Panel
* terminalPanel
= new TerminalPanel(terminalDock
);
1799 terminalPanel
->setCustomContextMenuActions(QList
<QAction
*>() << lockLayoutAction
);
1800 terminalDock
->setWidget(terminalPanel
);
1802 connect(terminalPanel
, SIGNAL(hideTerminalPanel()), terminalDock
, SLOT(hide()));
1803 connect(terminalDock
, SIGNAL(visibilityChanged(bool)),
1804 terminalPanel
, SLOT(dockVisibilityChanged()));
1806 QAction
* terminalAction
= terminalDock
->toggleViewAction();
1807 createPanelAction(KIcon("utilities-terminal"), Qt::Key_F4
, terminalAction
, "show_terminal_panel");
1809 addDockWidget(Qt::BottomDockWidgetArea
, terminalDock
);
1810 connect(this, SIGNAL(urlChanged(KUrl
)),
1811 terminalPanel
, SLOT(setUrl(KUrl
)));
1816 DolphinDockWidget
* searchDock
= new DolphinDockWidget(i18nc("@title:window", "Search"));
1817 searchDock
->setLocked(lock
);
1818 searchDock
->setObjectName("searchDock");
1819 searchDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1820 Panel
* searchPanel
= new SearchPanel(searchDock
);
1821 searchPanel
->setCustomContextMenuActions(QList
<QAction
*>() << lockLayoutAction
);
1822 connect(searchPanel
, SIGNAL(urlActivated(KUrl
)), this, SLOT(handleUrl(KUrl
)));
1823 searchDock
->setWidget(searchPanel
);
1825 QAction
* searchAction
= searchDock
->toggleViewAction();
1826 createPanelAction(KIcon("system-search"), Qt::Key_F12
, searchAction
, "show_search_panel");
1827 addDockWidget(Qt::RightDockWidgetArea
, searchDock
);
1828 connect(this, SIGNAL(urlChanged(KUrl
)),
1829 searchPanel
, SLOT(setUrl(KUrl
)));
1832 if (GeneralSettings::version() < 200) {
1834 foldersDock
->hide();
1836 terminalDock
->hide();
1844 DolphinDockWidget
* placesDock
= new DolphinDockWidget(i18nc("@title:window", "Places"));
1845 placesDock
->setLocked(lock
);
1846 placesDock
->setObjectName("placesDock");
1847 placesDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1849 PlacesPanel
* placesPanel
= new PlacesPanel(placesDock
);
1850 QAction
* separator
= new QAction(placesPanel
);
1851 separator
->setSeparator(true);
1852 QList
<QAction
*> placesActions
;
1853 placesActions
.append(separator
);
1854 placesActions
.append(lockLayoutAction
);
1855 placesPanel
->addActions(placesActions
);
1856 placesPanel
->setModel(DolphinPlacesModel::instance());
1857 placesPanel
->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff
);
1858 placesDock
->setWidget(placesPanel
);
1860 QAction
* placesAction
= placesDock
->toggleViewAction();
1861 createPanelAction(KIcon("bookmarks"), Qt::Key_F9
, placesAction
, "show_places_panel");
1863 addDockWidget(Qt::LeftDockWidgetArea
, placesDock
);
1864 connect(placesPanel
, SIGNAL(urlChanged(KUrl
,Qt::MouseButtons
)),
1865 this, SLOT(handlePlacesClick(KUrl
,Qt::MouseButtons
)));
1866 connect(this, SIGNAL(urlChanged(KUrl
)),
1867 placesPanel
, SLOT(setUrl(KUrl
)));
1868 connect(placesDock
, SIGNAL(visibilityChanged(bool)),
1869 this, SLOT(slotPlacesPanelVisibilityChanged(bool)));
1871 // Add actions into the "Panels" menu
1872 KActionMenu
* panelsMenu
= new KActionMenu(i18nc("@action:inmenu View", "Panels"), this);
1873 actionCollection()->addAction("panels", panelsMenu
);
1874 panelsMenu
->setDelayed(false);
1875 panelsMenu
->addAction(placesAction
);
1876 panelsMenu
->addAction(infoAction
);
1877 panelsMenu
->addAction(foldersAction
);
1879 panelsMenu
->addAction(terminalAction
);
1882 panelsMenu
->addAction(searchAction
);
1884 panelsMenu
->addSeparator();
1885 panelsMenu
->addAction(lockLayoutAction
);
1888 void DolphinMainWindow::updateEditActions()
1890 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
1891 if (list
.isEmpty()) {
1892 stateChanged("has_no_selection");
1894 stateChanged("has_selection");
1896 KActionCollection
* col
= actionCollection();
1897 QAction
* renameAction
= col
->action("rename");
1898 QAction
* moveToTrashAction
= col
->action("move_to_trash");
1899 QAction
* deleteAction
= col
->action("delete");
1900 QAction
* cutAction
= col
->action(KStandardAction::name(KStandardAction::Cut
));
1901 QAction
* deleteWithTrashShortcut
= col
->action("delete_shortcut"); // see DolphinViewActionHandler
1903 KFileItemListProperties
capabilities(list
);
1904 const bool enableMoveToTrash
= capabilities
.isLocal() && capabilities
.supportsMoving();
1906 renameAction
->setEnabled(capabilities
.supportsMoving());
1907 moveToTrashAction
->setEnabled(enableMoveToTrash
);
1908 deleteAction
->setEnabled(capabilities
.supportsDeleting());
1909 deleteWithTrashShortcut
->setEnabled(capabilities
.supportsDeleting() && !enableMoveToTrash
);
1910 cutAction
->setEnabled(capabilities
.supportsMoving());
1912 updatePasteAction();
1915 void DolphinMainWindow::updateViewActions()
1917 m_actionHandler
->updateViewActions();
1919 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
1920 showFilterBarAction
->setChecked(m_activeViewContainer
->isFilterBarVisible());
1922 updateSplitAction();
1924 QAction
* editableLocactionAction
= actionCollection()->action("editable_location");
1925 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
1926 editableLocactionAction
->setChecked(urlNavigator
->isUrlEditable());
1929 void DolphinMainWindow::updateGoActions()
1931 QAction
* goUpAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Up
));
1932 const KUrl currentUrl
= m_activeViewContainer
->url();
1933 goUpAction
->setEnabled(currentUrl
.upUrl() != currentUrl
);
1936 void DolphinMainWindow::createToolBarMenuButton()
1938 if (m_toolBarSpacer
&& m_openToolBarMenuButton
) {
1941 Q_ASSERT(!m_toolBarSpacer
);
1942 Q_ASSERT(!m_openToolBarMenuButton
);
1944 m_toolBarSpacer
= new QWidget(this);
1945 m_toolBarSpacer
->setSizePolicy(QSizePolicy::MinimumExpanding
, QSizePolicy::MinimumExpanding
);
1947 m_openToolBarMenuButton
= new QToolButton(this);
1948 m_openToolBarMenuButton
->setIcon(KIcon("configure"));
1949 m_openToolBarMenuButton
->setPopupMode(QToolButton::InstantPopup
);
1950 m_openToolBarMenuButton
->setToolTip(i18nc("@info:tooltip", "Configure and control Dolphin"));
1952 KMenu
* toolBarMenu
= new ToolBarMenu(m_openToolBarMenuButton
);
1953 connect(toolBarMenu
, SIGNAL(aboutToShow()), this, SLOT(updateToolBarMenu()));
1955 m_openToolBarMenuButton
->setMenu(toolBarMenu
);
1957 toolBar()->addWidget(m_toolBarSpacer
);
1958 toolBar()->addWidget(m_openToolBarMenuButton
);
1959 connect(toolBar(), SIGNAL(iconSizeChanged(QSize
)), this, SLOT(slotToolBarIconSizeChanged(QSize
)));
1961 // The added widgets are owned by the toolbar and may get deleted when e.g. the toolbar
1962 // gets edited. In this case we must add them again. The adding is done asynchronously by
1963 // m_updateToolBarTimer.
1964 connect(m_toolBarSpacer
, SIGNAL(destroyed()), this, SLOT(slotToolBarSpacerDeleted()));
1965 connect(m_openToolBarMenuButton
, SIGNAL(destroyed()), this, SLOT(slotToolBarMenuButtonDeleted()));
1966 m_updateToolBarTimer
= new QTimer(this);
1967 m_updateToolBarTimer
->setInterval(500);
1968 connect(m_updateToolBarTimer
, SIGNAL(timeout()), this, SLOT(updateToolBar()));
1971 void DolphinMainWindow::deleteToolBarMenuButton()
1973 delete m_toolBarSpacer
;
1974 m_toolBarSpacer
= 0;
1976 delete m_openToolBarMenuButton
;
1977 m_openToolBarMenuButton
= 0;
1979 delete m_updateToolBarTimer
;
1980 m_updateToolBarTimer
= 0;
1983 bool DolphinMainWindow::addActionToMenu(QAction
* action
, KMenu
* menu
)
1988 const KToolBar
* toolBarWidget
= toolBar();
1989 foreach (const QWidget
* widget
, action
->associatedWidgets()) {
1990 if (widget
== toolBarWidget
) {
1995 menu
->addAction(action
);
1999 void DolphinMainWindow::rememberClosedTab(int index
)
2001 KMenu
* tabsMenu
= m_recentTabsMenu
->menu();
2003 const QString primaryPath
= m_viewTab
[index
].primaryView
->url().path();
2004 const QString iconName
= KMimeType::iconNameForUrl(primaryPath
);
2006 QAction
* action
= new QAction(squeezedText(primaryPath
), tabsMenu
);
2008 ClosedTab closedTab
;
2009 closedTab
.primaryUrl
= m_viewTab
[index
].primaryView
->url();
2011 if (m_viewTab
[index
].secondaryView
) {
2012 closedTab
.secondaryUrl
= m_viewTab
[index
].secondaryView
->url();
2013 closedTab
.isSplit
= true;
2015 closedTab
.isSplit
= false;
2018 action
->setData(QVariant::fromValue(closedTab
));
2019 action
->setIcon(KIcon(iconName
));
2021 // add the closed tab menu entry after the separator and
2022 // "Empty Recently Closed Tabs" entry
2023 if (tabsMenu
->actions().size() == 2) {
2024 tabsMenu
->addAction(action
);
2026 tabsMenu
->insertAction(tabsMenu
->actions().at(2), action
);
2029 // assure that only up to 8 closed tabs are shown in the menu
2030 if (tabsMenu
->actions().size() > 8) {
2031 tabsMenu
->removeAction(tabsMenu
->actions().last());
2033 actionCollection()->action("closed_tabs")->setEnabled(true);
2034 KAcceleratorManager::manage(tabsMenu
);
2037 void DolphinMainWindow::refreshViews()
2039 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
);
2041 // remember the current active view, as because of
2042 // the refreshing the active view might change to
2043 // the secondary view
2044 DolphinViewContainer
* activeViewContainer
= m_activeViewContainer
;
2046 const int tabCount
= m_viewTab
.count();
2047 for (int i
= 0; i
< tabCount
; ++i
) {
2048 m_viewTab
[i
].primaryView
->refresh();
2049 if (m_viewTab
[i
].secondaryView
) {
2050 m_viewTab
[i
].secondaryView
->refresh();
2054 setActiveViewContainer(activeViewContainer
);
2056 if (GeneralSettings::modifiedStartupSettings()) {
2057 // The startup settings have been changed by the user (see bug #254947).
2058 // Synchronize the split-view setting with the active view:
2059 const bool splitView
= GeneralSettings::splitView();
2060 const ViewTab
& activeTab
= m_viewTab
[m_tabIndex
];
2061 const bool toggle
= ( splitView
&& !activeTab
.secondaryView
)
2062 || (!splitView
&& activeTab
.secondaryView
);
2069 void DolphinMainWindow::clearStatusBar()
2071 m_activeViewContainer
->statusBar()->clear();
2074 void DolphinMainWindow::connectViewSignals(DolphinViewContainer
* container
)
2076 connect(container
, SIGNAL(showFilterBarChanged(bool)),
2077 this, SLOT(updateFilterBarAction(bool)));
2078 connect(container
, SIGNAL(writeStateChanged(bool)),
2079 this, SLOT(slotWriteStateChanged(bool)));
2080 connect(container
, SIGNAL(searchModeChanged(bool)),
2081 this, SLOT(slotSearchModeChanged(bool)));
2083 const DolphinSearchBox
* searchBox
= container
->searchBox();
2084 connect(searchBox
, SIGNAL(searchLocationChanged(SearchLocation
)),
2085 this, SLOT(slotSearchLocationChanged()));
2087 DolphinView
* view
= container
->view();
2088 connect(view
, SIGNAL(selectionChanged(KFileItemList
)),
2089 this, SLOT(slotSelectionChanged(KFileItemList
)));
2090 connect(view
, SIGNAL(requestItemInfo(KFileItem
)),
2091 this, SLOT(slotRequestItemInfo(KFileItem
)));
2092 connect(view
, SIGNAL(activated()),
2093 this, SLOT(toggleActiveView()));
2094 connect(view
, SIGNAL(tabRequested(KUrl
)),
2095 this, SLOT(openNewTab(KUrl
)));
2096 connect(view
, SIGNAL(requestContextMenu(QPoint
,KFileItem
,KUrl
,QList
<QAction
*>)),
2097 this, SLOT(openContextMenu(QPoint
,KFileItem
,KUrl
,QList
<QAction
*>)));
2098 connect(view
, SIGNAL(startedPathLoading(KUrl
)),
2099 this, SLOT(enableStopAction()));
2100 connect(view
, SIGNAL(finishedPathLoading(KUrl
)),
2101 this, SLOT(disableStopAction()));
2103 const KUrlNavigator
* navigator
= container
->urlNavigator();
2104 connect(navigator
, SIGNAL(urlChanged(KUrl
)),
2105 this, SLOT(changeUrl(KUrl
)));
2106 connect(navigator
, SIGNAL(historyChanged()),
2107 this, SLOT(updateHistory()));
2108 connect(navigator
, SIGNAL(editableStateChanged(bool)),
2109 this, SLOT(slotEditableStateChanged(bool)));
2110 connect(navigator
, SIGNAL(tabRequested(KUrl
)),
2111 this, SLOT(openNewTab(KUrl
)));
2114 void DolphinMainWindow::updateSplitAction()
2116 QAction
* splitAction
= actionCollection()->action("split_view");
2117 if (m_viewTab
[m_tabIndex
].secondaryView
) {
2118 if (m_activeViewContainer
== m_viewTab
[m_tabIndex
].secondaryView
) {
2119 splitAction
->setText(i18nc("@action:intoolbar Close right view", "Close"));
2120 splitAction
->setToolTip(i18nc("@info", "Close right view"));
2121 splitAction
->setIcon(KIcon("view-right-close"));
2123 splitAction
->setText(i18nc("@action:intoolbar Close left view", "Close"));
2124 splitAction
->setToolTip(i18nc("@info", "Close left view"));
2125 splitAction
->setIcon(KIcon("view-left-close"));
2128 splitAction
->setText(i18nc("@action:intoolbar Split view", "Split"));
2129 splitAction
->setToolTip(i18nc("@info", "Split view"));
2130 splitAction
->setIcon(KIcon("view-right-new"));
2134 QString
DolphinMainWindow::tabName(const KUrl
& url
) const
2137 if (url
.equals(KUrl("file:///"))) {
2140 name
= url
.fileName();
2141 if (name
.isEmpty()) {
2142 name
= url
.protocol();
2144 // Make sure that a '&' inside the directory name is displayed correctly
2145 // and not misinterpreted as a keyboard shortcut in QTabBar::setTabText()
2146 name
.replace('&', "&&");
2152 bool DolphinMainWindow::isKompareInstalled() const
2154 static bool initialized
= false;
2155 static bool installed
= false;
2157 // TODO: maybe replace this approach later by using a menu
2158 // plugin like kdiff3plugin.cpp
2159 installed
= !KGlobal::dirs()->findExe("kompare").isEmpty();
2165 void DolphinMainWindow::createSecondaryView(int tabIndex
)
2167 QSplitter
* splitter
= m_viewTab
[tabIndex
].splitter
;
2168 const int newWidth
= (m_viewTab
[tabIndex
].primaryView
->width() - splitter
->handleWidth()) / 2;
2170 const DolphinView
* view
= m_viewTab
[tabIndex
].primaryView
->view();
2171 m_viewTab
[tabIndex
].secondaryView
= createViewContainer(view
->url(), 0);
2172 splitter
->addWidget(m_viewTab
[tabIndex
].secondaryView
);
2173 splitter
->setSizes(QList
<int>() << newWidth
<< newWidth
);
2174 connectViewSignals(m_viewTab
[tabIndex
].secondaryView
);
2175 m_viewTab
[tabIndex
].secondaryView
->setActive(false);
2176 m_viewTab
[tabIndex
].secondaryView
->show();
2179 QString
DolphinMainWindow::tabProperty(const QString
& property
, int tabIndex
) const
2181 return "Tab " + QString::number(tabIndex
) + ' ' + property
;
2184 void DolphinMainWindow::setUrlAsCaption(const KUrl
& url
)
2187 if (!url
.isLocalFile()) {
2188 caption
.append(url
.protocol() + " - ");
2189 if (url
.hasHost()) {
2190 caption
.append(url
.host() + " - ");
2194 const QString fileName
= url
.fileName().isEmpty() ? "/" : url
.fileName();
2195 caption
.append(fileName
);
2197 setCaption(caption
);
2200 QString
DolphinMainWindow::squeezedText(const QString
& text
) const
2202 const QFontMetrics fm
= fontMetrics();
2203 return fm
.elidedText(text
, Qt::ElideMiddle
, fm
.maxWidth() * 10);
2206 void DolphinMainWindow::createPanelAction(const KIcon
& icon
,
2207 const QKeySequence
& shortcut
,
2208 QAction
* dockAction
,
2209 const QString
& actionName
)
2211 KAction
* panelAction
= actionCollection()->addAction(actionName
);
2212 panelAction
->setText(dockAction
->text());
2213 panelAction
->setIcon(icon
);
2214 panelAction
->setShortcut(shortcut
);
2216 dockAction
->setIcon(icon
);
2217 dockAction
->setShortcut(shortcut
);
2218 connect(panelAction
, SIGNAL(triggered()), dockAction
, SLOT(trigger()));
2221 DolphinMainWindow::UndoUiInterface::UndoUiInterface() :
2222 KIO::FileUndoManager::UiInterface()
2226 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
2230 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
* job
)
2232 DolphinMainWindow
* mainWin
= qobject_cast
<DolphinMainWindow
*>(parentWidget());
2234 DolphinStatusBar
* statusBar
= mainWin
->activeViewContainer()->statusBar();
2235 statusBar
->setMessage(job
->errorString(), DolphinStatusBar::Error
);
2237 KIO::FileUndoManager::UiInterface::jobError(job
);
2241 ToolBarMenu::ToolBarMenu(QWidget
* parent
) :
2246 ToolBarMenu::~ToolBarMenu()
2250 void ToolBarMenu::showEvent(QShowEvent
* event
)
2252 KMenu::showEvent(event
);
2254 // Adjust the position of the menu to be shown within the
2255 // Dolphin window to reduce the cases that sub-menus might overlap
2256 // the right screen border.
2258 QWidget
* button
= parentWidget();
2259 if (layoutDirection() == Qt::RightToLeft
) {
2260 pos
= button
->mapToGlobal(QPoint(0, button
->height()));
2262 pos
= button
->mapToGlobal(QPoint(button
->width(), button
->height()));
2263 pos
.rx() -= width();
2266 // Assure that the menu is not shown outside the screen boundaries and
2267 // that it does not overlap with the parent button.
2268 const QRect screen
= QApplication::desktop()->screenGeometry(QCursor::pos());
2269 if (pos
.x() < screen
.x()) {
2270 pos
.rx() = screen
.x();
2271 } else if (pos
.x() + width() > screen
.x() + screen
.width()) {
2272 pos
.rx() = screen
.x() + screen
.width() - width();
2275 if (pos
.y() < screen
.y()) {
2276 pos
.ry() = screen
.y();
2277 } else if (pos
.y() + height() > screen
.y() + screen
.height()) {
2278 pos
.ry() = button
->mapToGlobal(QPoint(0, 0)).y() - height();
2284 #include "dolphinmainwindow.moc"