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 "dolphinapplication.h"
25 #include "dolphindockwidget.h"
26 #include "dolphincontextmenu.h"
27 #include "dolphinnewfilemenu.h"
28 #include "dolphinviewcontainer.h"
29 #include "panels/folders/folderspanel.h"
30 #include "panels/places/placespanel.h"
31 #include "panels/information/informationpanel.h"
32 #include "settings/dolphinsettingsdialog.h"
33 #include "statusbar/dolphinstatusbar.h"
34 #include "views/dolphinview.h"
35 #include "views/dolphinviewactionhandler.h"
36 #include "views/dolphinremoteencoding.h"
37 #include "views/draganddrophelper.h"
38 #include "views/viewproperties.h"
39 #include "views/dolphinnewfilemenuobserver.h"
42 #include "panels/terminal/terminalpanel.h"
45 #include "dolphin_generalsettings.h"
47 #include <KAcceleratorManager>
49 #include <KActionCollection>
50 #include <KActionMenu>
52 #include <KDesktopFile>
53 #include <kdeversion.h>
54 #include <kdualaction.h>
55 #include <KFileDialog>
60 #include <KIconLoader>
61 #include <KIO/NetAccess>
62 #include <KIO/JobUiDelegate>
63 #include <KInputDialog>
65 #include <KProtocolManager>
68 #include <KMessageBox>
69 #include <KFileItemListProperties>
70 #include <konqmimedata.h>
71 #include <KProtocolInfo>
74 #include <KStandardDirs>
75 #include <kstatusbar.h>
76 #include <KStandardAction>
78 #include <KToggleAction>
79 #include <KUrlNavigator>
81 #include <KUrlComboBox>
82 #include <KToolInvocation>
84 #include <QDesktopWidget>
85 #include <QDBusMessage>
88 #include <QToolButton>
92 // Used for GeneralSettings::version() to determine whether
93 // an updated version of Dolphin is running.
94 const int CurrentDolphinVersion
= 200;
98 * Remembers the tab configuration if a tab has been closed.
99 * Each closed tab can be restored by the menu
100 * "Go -> Recently Closed Tabs".
108 Q_DECLARE_METATYPE(ClosedTab
)
110 DolphinMainWindow::DolphinMainWindow() :
114 m_activeViewContainer(0),
115 m_centralWidgetLayout(0),
122 m_updateToolBarTimer(0),
123 m_lastHandleUrlStatJob(0)
125 setObjectName("Dolphin#");
127 m_viewTab
.append(ViewTab());
128 ViewTab
& viewTab
= m_viewTab
[m_tabIndex
];
129 viewTab
.wasActive
= true; // The first opened tab is automatically active
131 connect(&DolphinNewFileMenuObserver::instance(), SIGNAL(errorMessage(QString
)),
132 this, SLOT(showErrorMessage(QString
)));
134 KIO::FileUndoManager
* undoManager
= KIO::FileUndoManager::self();
135 undoManager
->setUiInterface(new UndoUiInterface());
137 connect(undoManager
, SIGNAL(undoAvailable(bool)),
138 this, SLOT(slotUndoAvailable(bool)));
139 connect(undoManager
, SIGNAL(undoTextChanged(QString
)),
140 this, SLOT(slotUndoTextChanged(QString
)));
141 connect(undoManager
, SIGNAL(jobRecordingStarted(CommandType
)),
142 this, SLOT(clearStatusBar()));
143 connect(undoManager
, SIGNAL(jobRecordingFinished(CommandType
)),
144 this, SLOT(showCommand(CommandType
)));
146 GeneralSettings
* generalSettings
= GeneralSettings::self();
147 const bool firstRun
= (generalSettings
->version() < 200);
149 generalSettings
->setViewPropsTimestamp(QDateTime::currentDateTime());
152 setAcceptDrops(true);
154 viewTab
.splitter
= new QSplitter(this);
155 viewTab
.splitter
->setChildrenCollapsible(false);
159 const KUrl
homeUrl(generalSettings
->homeUrl());
160 setUrlAsCaption(homeUrl
);
161 m_actionHandler
= new DolphinViewActionHandler(actionCollection(), this);
162 connect(m_actionHandler
, SIGNAL(actionBeingHandled()), SLOT(clearStatusBar()));
163 connect(m_actionHandler
, SIGNAL(createDirectory()), SLOT(createDirectory()));
165 viewTab
.primaryView
= createViewContainer(homeUrl
, viewTab
.splitter
);
167 m_activeViewContainer
= viewTab
.primaryView
;
168 connectViewSignals(m_activeViewContainer
);
169 DolphinView
* view
= m_activeViewContainer
->view();
170 m_activeViewContainer
->show();
171 m_actionHandler
->setCurrentView(view
);
173 m_remoteEncoding
= new DolphinRemoteEncoding(this, m_actionHandler
);
174 connect(this, SIGNAL(urlChanged(KUrl
)),
175 m_remoteEncoding
, SLOT(slotAboutToOpenUrl()));
177 m_tabBar
= new KTabBar(this);
178 m_tabBar
->setMovable(true);
179 m_tabBar
->setTabsClosable(true);
180 connect(m_tabBar
, SIGNAL(currentChanged(int)),
181 this, SLOT(setActiveTab(int)));
182 connect(m_tabBar
, SIGNAL(tabCloseRequested(int)),
183 this, SLOT(closeTab(int)));
184 connect(m_tabBar
, SIGNAL(contextMenu(int,QPoint
)),
185 this, SLOT(openTabContextMenu(int,QPoint
)));
186 connect(m_tabBar
, SIGNAL(newTabRequest()),
187 this, SLOT(openNewTab()));
188 connect(m_tabBar
, SIGNAL(testCanDecode(const QDragMoveEvent
*,bool&)),
189 this, SLOT(slotTestCanDecode(const QDragMoveEvent
*,bool&)));
190 connect(m_tabBar
, SIGNAL(mouseMiddleClick(int)),
191 this, SLOT(closeTab(int)));
192 connect(m_tabBar
, SIGNAL(tabMoved(int,int)),
193 this, SLOT(slotTabMoved(int,int)));
194 connect(m_tabBar
, SIGNAL(receivedDropEvent(int,QDropEvent
*)),
195 this, SLOT(tabDropEvent(int,QDropEvent
*)));
197 m_tabBar
->blockSignals(true); // signals get unblocked after at least 2 tabs are open
199 QWidget
* centralWidget
= new QWidget(this);
200 m_centralWidgetLayout
= new QVBoxLayout(centralWidget
);
201 m_centralWidgetLayout
->setSpacing(0);
202 m_centralWidgetLayout
->setMargin(0);
203 m_centralWidgetLayout
->addWidget(m_tabBar
);
204 m_centralWidgetLayout
->addWidget(viewTab
.splitter
, 1);
206 setCentralWidget(centralWidget
);
208 emit
urlChanged(homeUrl
);
210 setupGUI(Keys
| Save
| Create
| ToolBar
);
211 stateChanged("new_file");
213 QClipboard
* clipboard
= QApplication::clipboard();
214 connect(clipboard
, SIGNAL(dataChanged()),
215 this, SLOT(updatePasteAction()));
217 if (generalSettings
->splitView()) {
224 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
225 showFilterBarAction
->setChecked(generalSettings
->filterBar());
228 menuBar()->setVisible(false);
229 // Assure a proper default size if Dolphin runs the first time
233 const bool showMenu
= !menuBar()->isHidden();
234 QAction
* showMenuBarAction
= actionCollection()->action(KStandardAction::name(KStandardAction::ShowMenubar
));
235 showMenuBarAction
->setChecked(showMenu
); // workaround for bug #171080
237 createControlButton();
241 DolphinMainWindow::~DolphinMainWindow()
245 void DolphinMainWindow::openDirectories(const QList
<KUrl
>& dirs
)
247 if (dirs
.isEmpty()) {
251 // dirs could contain URLs that actually point to archives or other files.
252 // Replace them by URLs we can open where possible and filter the rest out.
253 QList
<KUrl
> urlsToOpen
;
254 foreach (const KUrl
& rawUrl
, dirs
) {
255 const KFileItem
& item
= KFileItem(KFileItem::Unknown
, KFileItem::Unknown
, rawUrl
);
256 item
.determineMimeType();
257 const KUrl
& url
= DolphinView::openItemAsFolderUrl(item
);
258 if (!url
.isEmpty()) {
259 urlsToOpen
.append(url
);
263 if (urlsToOpen
.count() == 1) {
264 m_activeViewContainer
->setUrl(urlsToOpen
.first());
268 const int oldOpenTabsCount
= m_viewTab
.count();
270 const bool hasSplitView
= GeneralSettings::splitView();
272 // Open each directory inside a new tab. If the "split view" option has been enabled,
273 // always show two directories within one tab.
274 QList
<KUrl
>::const_iterator it
= urlsToOpen
.constBegin();
275 while (it
!= urlsToOpen
.constEnd()) {
279 if (hasSplitView
&& (it
!= urlsToOpen
.constEnd())) {
280 const int tabIndex
= m_viewTab
.count() - 1;
281 m_viewTab
[tabIndex
].secondaryView
->setUrl(*it
);
286 // Remove the previously opened tabs
287 for (int i
= 0; i
< oldOpenTabsCount
; ++i
) {
292 void DolphinMainWindow::openFiles(const QList
<KUrl
>& files
)
294 if (files
.isEmpty()) {
298 // Get all distinct directories from 'files' and open a tab
299 // for each directory. If the "split view" option is enabled, two
300 // directories are shown inside one tab (see openDirectories()).
302 foreach (const KUrl
& url
, files
) {
303 const KUrl
dir(url
.directory());
304 if (!dirs
.contains(dir
)) {
309 openDirectories(dirs
);
311 // Select the files. Although the files can be split between several
312 // tabs, there is no need to split 'files' accordingly, as
313 // the DolphinView will just ignore invalid selections.
314 const int tabCount
= m_viewTab
.count();
315 for (int i
= 0; i
< tabCount
; ++i
) {
316 m_viewTab
[i
].primaryView
->view()->markUrlsAsSelected(files
);
317 m_viewTab
[i
].primaryView
->view()->markUrlAsCurrent(files
.at(0));
318 if (m_viewTab
[i
].secondaryView
) {
319 m_viewTab
[i
].secondaryView
->view()->markUrlsAsSelected(files
);
320 m_viewTab
[i
].secondaryView
->view()->markUrlAsCurrent(files
.at(0));
325 void DolphinMainWindow::showCommand(CommandType command
)
327 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
329 case KIO::FileUndoManager::Copy
:
330 statusBar
->setText(i18nc("@info:status", "Successfully copied."));
332 case KIO::FileUndoManager::Move
:
333 statusBar
->setText(i18nc("@info:status", "Successfully moved."));
335 case KIO::FileUndoManager::Link
:
336 statusBar
->setText(i18nc("@info:status", "Successfully linked."));
338 case KIO::FileUndoManager::Trash
:
339 statusBar
->setText(i18nc("@info:status", "Successfully moved to trash."));
341 case KIO::FileUndoManager::Rename
:
342 statusBar
->setText(i18nc("@info:status", "Successfully renamed."));
345 case KIO::FileUndoManager::Mkdir
:
346 statusBar
->setText(i18nc("@info:status", "Created folder."));
354 void DolphinMainWindow::pasteIntoFolder()
356 m_activeViewContainer
->view()->pasteIntoFolder();
359 void DolphinMainWindow::changeUrl(const KUrl
& url
)
361 if (!KProtocolManager::supportsListing(url
)) {
362 // The URL navigator only checks for validity, not
363 // if the URL can be listed. An error message is
364 // shown due to DolphinViewContainer::restoreView().
368 DolphinViewContainer
* view
= activeViewContainer();
374 setUrlAsCaption(url
);
375 if (m_viewTab
.count() > 1) {
376 m_tabBar
->setTabText(m_tabIndex
, squeezedText(tabName(m_activeViewContainer
->url())));
378 const QString iconName
= KMimeType::iconNameForUrl(url
);
379 m_tabBar
->setTabIcon(m_tabIndex
, KIcon(iconName
));
380 emit
urlChanged(url
);
384 void DolphinMainWindow::slotTerminalDirectoryChanged(const KUrl
& url
)
386 m_activeViewContainer
->setAutoGrabFocus(false);
388 m_activeViewContainer
->setAutoGrabFocus(true);
391 void DolphinMainWindow::slotEditableStateChanged(bool editable
)
393 KToggleAction
* editableLocationAction
=
394 static_cast<KToggleAction
*>(actionCollection()->action("editable_location"));
395 editableLocationAction
->setChecked(editable
);
398 void DolphinMainWindow::slotSelectionChanged(const KFileItemList
& selection
)
402 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
);
403 int selectedUrlsCount
= m_viewTab
[m_tabIndex
].primaryView
->view()->selectedItemsCount();
404 if (m_viewTab
[m_tabIndex
].secondaryView
) {
405 selectedUrlsCount
+= m_viewTab
[m_tabIndex
].secondaryView
->view()->selectedItemsCount();
408 QAction
* compareFilesAction
= actionCollection()->action("compare_files");
409 if (selectedUrlsCount
== 2) {
410 compareFilesAction
->setEnabled(isKompareInstalled());
412 compareFilesAction
->setEnabled(false);
415 emit
selectionChanged(selection
);
418 void DolphinMainWindow::slotRequestItemInfo(const KFileItem
& item
)
420 emit
requestItemInfo(item
);
423 void DolphinMainWindow::updateHistory()
425 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
426 const int index
= urlNavigator
->historyIndex();
428 QAction
* backAction
= actionCollection()->action("go_back");
430 backAction
->setToolTip(i18nc("@info", "Go back"));
431 backAction
->setEnabled(index
< urlNavigator
->historySize() - 1);
434 QAction
* forwardAction
= actionCollection()->action("go_forward");
436 forwardAction
->setToolTip(i18nc("@info", "Go forward"));
437 forwardAction
->setEnabled(index
> 0);
441 void DolphinMainWindow::updateFilterBarAction(bool show
)
443 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
444 showFilterBarAction
->setChecked(show
);
447 void DolphinMainWindow::openNewMainWindow()
449 KRun::run("dolphin %u", KUrl::List(), this);
452 void DolphinMainWindow::openNewTab()
454 const bool isUrlEditable
= m_activeViewContainer
->urlNavigator()->isUrlEditable();
456 openNewTab(m_activeViewContainer
->url());
457 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
459 // The URL navigator of the new tab should have the same editable state
460 // as the current tab
461 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
462 navigator
->setUrlEditable(isUrlEditable
);
465 // If a new tab is opened and the URL is editable, assure that
466 // the user can edit the URL without manually setting the focus
467 navigator
->setFocus();
471 void DolphinMainWindow::openNewTab(const KUrl
& url
)
473 QWidget
* focusWidget
= QApplication::focusWidget();
475 if (m_viewTab
.count() == 1) {
476 // Only one view is open currently and hence no tab is shown at
477 // all. Before creating a tab for 'url', provide a tab for the current URL.
478 const KUrl currentUrl
= m_activeViewContainer
->url();
479 m_tabBar
->addTab(KIcon(KMimeType::iconNameForUrl(currentUrl
)),
480 squeezedText(tabName(currentUrl
)));
481 m_tabBar
->blockSignals(false);
484 m_tabBar
->addTab(KIcon(KMimeType::iconNameForUrl(url
)),
485 squeezedText(tabName(url
)));
488 viewTab
.splitter
= new QSplitter(this);
489 viewTab
.splitter
->setChildrenCollapsible(false);
490 viewTab
.primaryView
= createViewContainer(url
, viewTab
.splitter
);
491 viewTab
.primaryView
->setActive(false);
492 connectViewSignals(viewTab
.primaryView
);
494 m_viewTab
.append(viewTab
);
496 actionCollection()->action("close_tab")->setEnabled(true);
498 // Provide a split view, if the startup settings are set this way
499 if (GeneralSettings::splitView()) {
500 const int newTabIndex
= m_viewTab
.count() - 1;
501 createSecondaryView(newTabIndex
);
502 m_viewTab
[newTabIndex
].secondaryView
->setActive(true);
503 m_viewTab
[newTabIndex
].isPrimaryViewActive
= false;
507 // The DolphinViewContainer grabbed the keyboard focus. As the tab is opened
508 // in background, assure that the previous focused widget gets the focus back.
509 focusWidget
->setFocus();
513 void DolphinMainWindow::openNewActivatedTab(const KUrl
& url
)
516 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
519 void DolphinMainWindow::activateNextTab()
521 if (m_viewTab
.count() >= 2) {
522 const int tabIndex
= (m_tabBar
->currentIndex() + 1) % m_tabBar
->count();
523 m_tabBar
->setCurrentIndex(tabIndex
);
527 void DolphinMainWindow::activatePrevTab()
529 if (m_viewTab
.count() >= 2) {
530 int tabIndex
= m_tabBar
->currentIndex() - 1;
531 if (tabIndex
== -1) {
532 tabIndex
= m_tabBar
->count() - 1;
534 m_tabBar
->setCurrentIndex(tabIndex
);
538 void DolphinMainWindow::openInNewTab()
540 const KFileItemList
& list
= m_activeViewContainer
->view()->selectedItems();
541 if (list
.isEmpty()) {
542 openNewTab(m_activeViewContainer
->url());
544 foreach (const KFileItem
& item
, list
) {
545 const KUrl
& url
= DolphinView::openItemAsFolderUrl(item
);
546 if (!url
.isEmpty()) {
553 void DolphinMainWindow::openInNewWindow()
557 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
558 if (list
.isEmpty()) {
559 newWindowUrl
= m_activeViewContainer
->url();
560 } else if (list
.count() == 1) {
561 const KFileItem
& item
= list
.first();
562 newWindowUrl
= DolphinView::openItemAsFolderUrl(item
);
565 if (!newWindowUrl
.isEmpty()) {
566 KRun::run("dolphin %u", KUrl::List() << newWindowUrl
, this);
570 void DolphinMainWindow::toggleActiveView()
572 if (!m_viewTab
[m_tabIndex
].secondaryView
) {
573 // only one view is available
577 Q_ASSERT(m_activeViewContainer
);
578 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
);
580 DolphinViewContainer
* left
= m_viewTab
[m_tabIndex
].primaryView
;
581 DolphinViewContainer
* right
= m_viewTab
[m_tabIndex
].secondaryView
;
582 setActiveViewContainer(m_activeViewContainer
== right
? left
: right
);
585 void DolphinMainWindow::showEvent(QShowEvent
* event
)
587 KXmlGuiWindow::showEvent(event
);
588 if (!event
->spontaneous()) {
589 m_activeViewContainer
->view()->setFocus();
593 void DolphinMainWindow::closeEvent(QCloseEvent
* event
)
595 // Find out if Dolphin is closed directly by the user or
596 // by the session manager because the session is closed
597 bool closedByUser
= true;
598 DolphinApplication
*application
= qobject_cast
<DolphinApplication
*>(qApp
);
599 if (application
&& application
->sessionSaving()) {
600 closedByUser
= false;
603 if (m_viewTab
.count() > 1 && GeneralSettings::confirmClosingMultipleTabs() && closedByUser
) {
604 // Ask the user if he really wants to quit and close all tabs.
605 // Open a confirmation dialog with 3 buttons:
606 // KDialog::Yes -> Quit
607 // KDialog::No -> Close only the current tab
608 // KDialog::Cancel -> do nothing
609 KDialog
*dialog
= new KDialog(this, Qt::Dialog
);
610 dialog
->setCaption(i18nc("@title:window", "Confirmation"));
611 dialog
->setButtons(KDialog::Yes
| KDialog::No
| KDialog::Cancel
);
612 dialog
->setModal(true);
613 dialog
->setButtonGuiItem(KDialog::Yes
, KStandardGuiItem::quit());
614 dialog
->setButtonGuiItem(KDialog::No
, KGuiItem(i18n("C&lose Current Tab"), KIcon("tab-close")));
615 dialog
->setButtonGuiItem(KDialog::Cancel
, KStandardGuiItem::cancel());
616 dialog
->setDefaultButton(KDialog::Yes
);
618 bool doNotAskAgainCheckboxResult
= false;
620 const int result
= KMessageBox::createKMessageBox(dialog
,
621 QMessageBox::Warning
,
622 i18n("You have multiple tabs open in this window, are you sure you want to quit?"),
624 i18n("Do not ask again"),
625 &doNotAskAgainCheckboxResult
,
626 KMessageBox::Notify
);
628 if (doNotAskAgainCheckboxResult
) {
629 GeneralSettings::setConfirmClosingMultipleTabs(false);
637 // Close only the current tab
645 GeneralSettings::setVersion(CurrentDolphinVersion
);
646 GeneralSettings::self()->writeConfig();
648 KXmlGuiWindow::closeEvent(event
);
651 void DolphinMainWindow::saveProperties(KConfigGroup
& group
)
653 const int tabCount
= m_viewTab
.count();
654 group
.writeEntry("Tab Count", tabCount
);
655 group
.writeEntry("Active Tab Index", m_tabBar
->currentIndex());
657 for (int i
= 0; i
< tabCount
; ++i
) {
658 const DolphinViewContainer
* cont
= m_viewTab
[i
].primaryView
;
659 group
.writeEntry(tabProperty("Primary URL", i
), cont
->url().url());
660 group
.writeEntry(tabProperty("Primary Editable", i
),
661 cont
->urlNavigator()->isUrlEditable());
663 cont
= m_viewTab
[i
].secondaryView
;
665 group
.writeEntry(tabProperty("Secondary URL", i
), cont
->url().url());
666 group
.writeEntry(tabProperty("Secondary Editable", i
),
667 cont
->urlNavigator()->isUrlEditable());
672 void DolphinMainWindow::readProperties(const KConfigGroup
& group
)
674 const int tabCount
= group
.readEntry("Tab Count", 1);
675 for (int i
= 0; i
< tabCount
; ++i
) {
676 DolphinViewContainer
* cont
= m_viewTab
[i
].primaryView
;
678 cont
->setUrl(group
.readEntry(tabProperty("Primary URL", i
)));
679 const bool editable
= group
.readEntry(tabProperty("Primary Editable", i
), false);
680 cont
->urlNavigator()->setUrlEditable(editable
);
682 cont
= m_viewTab
[i
].secondaryView
;
683 const QString secondaryUrl
= group
.readEntry(tabProperty("Secondary URL", i
));
684 if (!secondaryUrl
.isEmpty()) {
686 // a secondary view should be shown, but no one is available
687 // currently -> create a new view
689 cont
= m_viewTab
[i
].secondaryView
;
693 cont
->setUrl(secondaryUrl
);
694 const bool editable
= group
.readEntry(tabProperty("Secondary Editable", i
), false);
695 cont
->urlNavigator()->setUrlEditable(editable
);
697 // no secondary view should be shown, but the default setting shows
698 // one already -> close the view
702 // openNewTab() needs to be called only tabCount - 1 times
703 if (i
!= tabCount
- 1) {
708 const int index
= group
.readEntry("Active Tab Index", 0);
709 m_tabBar
->setCurrentIndex(index
);
712 void DolphinMainWindow::updateNewMenu()
714 m_newFileMenu
->setViewShowsHiddenFiles(activeViewContainer()->view()->hiddenFilesShown());
715 m_newFileMenu
->checkUpToDate();
716 m_newFileMenu
->setPopupFiles(activeViewContainer()->url());
719 void DolphinMainWindow::createDirectory()
721 m_newFileMenu
->setViewShowsHiddenFiles(activeViewContainer()->view()->hiddenFilesShown());
722 m_newFileMenu
->setPopupFiles(activeViewContainer()->url());
723 m_newFileMenu
->createDirectory();
726 void DolphinMainWindow::quit()
731 void DolphinMainWindow::showErrorMessage(const QString
& message
)
733 m_activeViewContainer
->showMessage(message
, DolphinViewContainer::Error
);
736 void DolphinMainWindow::slotUndoAvailable(bool available
)
738 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
740 undoAction
->setEnabled(available
);
744 void DolphinMainWindow::restoreClosedTab(QAction
* action
)
746 if (action
->data().toBool()) {
747 // clear all actions except the "Empty Recently Closed Tabs"
748 // action and the separator
749 QList
<QAction
*> actions
= m_recentTabsMenu
->menu()->actions();
750 const int count
= actions
.size();
751 for (int i
= 2; i
< count
; ++i
) {
752 m_recentTabsMenu
->menu()->removeAction(actions
.at(i
));
755 const ClosedTab closedTab
= action
->data().value
<ClosedTab
>();
756 openNewTab(closedTab
.primaryUrl
);
757 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
759 if (closedTab
.isSplit
) {
760 // create secondary view
762 m_viewTab
[m_tabIndex
].secondaryView
->setUrl(closedTab
.secondaryUrl
);
765 m_recentTabsMenu
->removeAction(action
);
768 if (m_recentTabsMenu
->menu()->actions().count() == 2) {
769 m_recentTabsMenu
->setEnabled(false);
773 void DolphinMainWindow::slotUndoTextChanged(const QString
& text
)
775 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
777 undoAction
->setText(text
);
781 void DolphinMainWindow::undo()
784 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
785 KIO::FileUndoManager::self()->undo();
788 void DolphinMainWindow::cut()
790 m_activeViewContainer
->view()->cutSelectedItems();
793 void DolphinMainWindow::copy()
795 m_activeViewContainer
->view()->copySelectedItems();
798 void DolphinMainWindow::paste()
800 m_activeViewContainer
->view()->paste();
803 void DolphinMainWindow::find()
805 m_activeViewContainer
->setSearchModeEnabled(true);
808 void DolphinMainWindow::updatePasteAction()
810 QAction
* pasteAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Paste
));
811 QPair
<bool, QString
> pasteInfo
= m_activeViewContainer
->view()->pasteInfo();
812 pasteAction
->setEnabled(pasteInfo
.first
);
813 pasteAction
->setText(pasteInfo
.second
);
816 void DolphinMainWindow::selectAll()
820 // if the URL navigator is editable and focused, select the whole
821 // URL instead of all items of the view
823 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
824 QLineEdit
* lineEdit
= urlNavigator
->editor()->lineEdit(); // krazy:exclude=qclasses
825 const bool selectUrl
= urlNavigator
->isUrlEditable() &&
826 lineEdit
->hasFocus();
828 lineEdit
->selectAll();
830 m_activeViewContainer
->view()->selectAll();
834 void DolphinMainWindow::invertSelection()
837 m_activeViewContainer
->view()->invertSelection();
840 void DolphinMainWindow::toggleSplitView()
842 if (!m_viewTab
[m_tabIndex
].secondaryView
) {
843 createSecondaryView(m_tabIndex
);
844 setActiveViewContainer(m_viewTab
[m_tabIndex
].secondaryView
);
845 } else if (m_activeViewContainer
== m_viewTab
[m_tabIndex
].secondaryView
) {
846 // remove secondary view
847 m_viewTab
[m_tabIndex
].secondaryView
->close();
848 m_viewTab
[m_tabIndex
].secondaryView
->deleteLater();
849 m_viewTab
[m_tabIndex
].secondaryView
= 0;
851 setActiveViewContainer(m_viewTab
[m_tabIndex
].primaryView
);
853 // The primary view is active and should be closed. Hence from a users point of view
854 // the content of the secondary view should be moved to the primary view.
855 // From an implementation point of view it is more efficient to close
856 // the primary view and exchange the internal pointers afterwards.
858 m_viewTab
[m_tabIndex
].primaryView
->close();
859 m_viewTab
[m_tabIndex
].primaryView
->deleteLater();
860 m_viewTab
[m_tabIndex
].primaryView
= m_viewTab
[m_tabIndex
].secondaryView
;
861 m_viewTab
[m_tabIndex
].secondaryView
= 0;
863 setActiveViewContainer(m_viewTab
[m_tabIndex
].primaryView
);
869 void DolphinMainWindow::reloadView()
872 m_activeViewContainer
->view()->reload();
875 void DolphinMainWindow::stopLoading()
877 m_activeViewContainer
->view()->stopLoading();
880 void DolphinMainWindow::enableStopAction()
882 actionCollection()->action("stop")->setEnabled(true);
885 void DolphinMainWindow::disableStopAction()
887 actionCollection()->action("stop")->setEnabled(false);
890 void DolphinMainWindow::showFilterBar()
892 m_activeViewContainer
->setFilterBarVisible(true);
895 void DolphinMainWindow::toggleEditLocation()
899 QAction
* action
= actionCollection()->action("editable_location");
900 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
901 urlNavigator
->setUrlEditable(action
->isChecked());
904 void DolphinMainWindow::replaceLocation()
906 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
907 navigator
->setUrlEditable(true);
908 navigator
->setFocus();
910 // select the whole text of the combo box editor
911 QLineEdit
* lineEdit
= navigator
->editor()->lineEdit(); // krazy:exclude=qclasses
912 lineEdit
->selectAll();
915 void DolphinMainWindow::togglePanelLockState()
917 const bool newLockState
= !GeneralSettings::lockPanels();
918 foreach (QObject
* child
, children()) {
919 DolphinDockWidget
* dock
= qobject_cast
<DolphinDockWidget
*>(child
);
921 dock
->setLocked(newLockState
);
925 GeneralSettings::setLockPanels(newLockState
);
928 void DolphinMainWindow::slotPlacesPanelVisibilityChanged(bool visible
)
930 const int tabCount
= m_viewTab
.count();
931 for (int i
= 0; i
< tabCount
; ++i
) {
932 ViewTab
& tab
= m_viewTab
[i
];
933 Q_ASSERT(tab
.primaryView
);
934 tab
.primaryView
->urlNavigator()->setPlacesSelectorVisible(!visible
);
935 if (tab
.secondaryView
) {
936 tab
.secondaryView
->urlNavigator()->setPlacesSelectorVisible(!visible
);
941 void DolphinMainWindow::goBack()
943 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
944 urlNavigator
->goBack();
946 if (urlNavigator
->locationState().isEmpty()) {
947 // An empty location state indicates a redirection URL,
948 // which must be skipped too
949 urlNavigator
->goBack();
953 void DolphinMainWindow::goForward()
955 m_activeViewContainer
->urlNavigator()->goForward();
958 void DolphinMainWindow::goUp()
960 m_activeViewContainer
->urlNavigator()->goUp();
963 void DolphinMainWindow::goHome()
965 m_activeViewContainer
->urlNavigator()->goHome();
968 void DolphinMainWindow::goBack(Qt::MouseButtons buttons
)
970 // The default case (left button pressed) is handled in goBack().
971 if (buttons
== Qt::MidButton
) {
972 KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigator();
973 const int index
= urlNavigator
->historyIndex() + 1;
974 openNewTab(urlNavigator
->locationUrl(index
));
978 void DolphinMainWindow::goForward(Qt::MouseButtons buttons
)
980 // The default case (left button pressed) is handled in goForward().
981 if (buttons
== Qt::MidButton
) {
982 KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigator();
983 const int index
= urlNavigator
->historyIndex() - 1;
984 openNewTab(urlNavigator
->locationUrl(index
));
988 void DolphinMainWindow::goUp(Qt::MouseButtons buttons
)
990 // The default case (left button pressed) is handled in goUp().
991 if (buttons
== Qt::MidButton
) {
992 openNewTab(activeViewContainer()->url().upUrl());
996 void DolphinMainWindow::goHome(Qt::MouseButtons buttons
)
998 // The default case (left button pressed) is handled in goHome().
999 if (buttons
== Qt::MidButton
) {
1000 openNewTab(GeneralSettings::self()->homeUrl());
1004 void DolphinMainWindow::compareFiles()
1006 const DolphinViewContainer
* primaryViewContainer
= m_viewTab
[m_tabIndex
].primaryView
;
1007 Q_ASSERT(primaryViewContainer
);
1008 KFileItemList items
= primaryViewContainer
->view()->selectedItems();
1010 const DolphinViewContainer
* secondaryViewContainer
= m_viewTab
[m_tabIndex
].secondaryView
;
1011 if (secondaryViewContainer
) {
1012 items
.append(secondaryViewContainer
->view()->selectedItems());
1015 if (items
.count() != 2) {
1016 // The action is disabled in this case, but it could have been triggered
1017 // via D-Bus, see https://bugs.kde.org/show_bug.cgi?id=325517
1021 KUrl urlA
= items
.at(0).url();
1022 KUrl urlB
= items
.at(1).url();
1024 QString
command("kompare -c \"");
1025 command
.append(urlA
.pathOrUrl());
1026 command
.append("\" \"");
1027 command
.append(urlB
.pathOrUrl());
1028 command
.append('\"');
1029 KRun::runCommand(command
, "Kompare", "kompare", this);
1032 void DolphinMainWindow::toggleShowMenuBar()
1034 const bool visible
= menuBar()->isVisible();
1035 menuBar()->setVisible(!visible
);
1037 createControlButton();
1039 deleteControlButton();
1043 void DolphinMainWindow::openTerminal()
1045 QString
dir(QDir::homePath());
1047 // If the given directory is not local, it can still be the URL of an
1048 // ioslave using UDS_LOCAL_PATH which to be converted first.
1049 KUrl url
= KIO::NetAccess::mostLocalUrl(m_activeViewContainer
->url(), this);
1051 //If the URL is local after the above conversion, set the directory.
1052 if (url
.isLocalFile()) {
1053 dir
= url
.toLocalFile();
1056 KToolInvocation::invokeTerminal(QString(), dir
);
1059 void DolphinMainWindow::editSettings()
1061 if (!m_settingsDialog
) {
1062 DolphinViewContainer
* container
= activeViewContainer();
1063 container
->view()->writeSettings();
1065 const KUrl url
= container
->url();
1066 DolphinSettingsDialog
* settingsDialog
= new DolphinSettingsDialog(url
, this);
1067 connect(settingsDialog
, SIGNAL(settingsChanged()), this, SLOT(refreshViews()));
1068 settingsDialog
->setAttribute(Qt::WA_DeleteOnClose
);
1069 settingsDialog
->show();
1070 m_settingsDialog
= settingsDialog
;
1072 m_settingsDialog
.data()->raise();
1076 void DolphinMainWindow::setActiveTab(int index
)
1078 Q_ASSERT(index
>= 0);
1079 Q_ASSERT(index
< m_viewTab
.count());
1080 if (index
== m_tabIndex
) {
1084 // hide current tab content
1085 ViewTab
& hiddenTab
= m_viewTab
[m_tabIndex
];
1086 hiddenTab
.isPrimaryViewActive
= hiddenTab
.primaryView
->isActive();
1087 hiddenTab
.primaryView
->setActive(false);
1088 if (hiddenTab
.secondaryView
) {
1089 hiddenTab
.secondaryView
->setActive(false);
1091 QSplitter
* splitter
= m_viewTab
[m_tabIndex
].splitter
;
1093 m_centralWidgetLayout
->removeWidget(splitter
);
1095 // show active tab content
1098 ViewTab
& viewTab
= m_viewTab
[index
];
1099 m_centralWidgetLayout
->addWidget(viewTab
.splitter
, 1);
1100 viewTab
.primaryView
->show();
1101 if (viewTab
.secondaryView
) {
1102 viewTab
.secondaryView
->show();
1104 viewTab
.splitter
->show();
1106 if (!viewTab
.wasActive
) {
1107 viewTab
.wasActive
= true;
1109 // If the tab has not been activated yet the size of the KItemListView is
1110 // undefined and results in an unwanted animation. To prevent this a
1111 // reloading of the directory gets triggered.
1112 viewTab
.primaryView
->view()->reload();
1113 if (viewTab
.secondaryView
) {
1114 viewTab
.secondaryView
->view()->reload();
1118 setActiveViewContainer(viewTab
.isPrimaryViewActive
? viewTab
.primaryView
:
1119 viewTab
.secondaryView
);
1122 void DolphinMainWindow::closeTab()
1124 closeTab(m_tabBar
->currentIndex());
1127 void DolphinMainWindow::closeTab(int index
)
1129 Q_ASSERT(index
>= 0);
1130 Q_ASSERT(index
< m_viewTab
.count());
1131 if (m_viewTab
.count() == 1) {
1132 // the last tab may never get closed
1136 if (index
== m_tabIndex
) {
1137 // The tab that should be closed is the active tab. Activate the
1138 // previous tab before closing the tab.
1139 m_tabBar
->setCurrentIndex((index
> 0) ? index
- 1 : 1);
1141 rememberClosedTab(index
);
1144 m_viewTab
[index
].primaryView
->deleteLater();
1145 if (m_viewTab
[index
].secondaryView
) {
1146 m_viewTab
[index
].secondaryView
->deleteLater();
1148 m_viewTab
[index
].splitter
->deleteLater();
1149 m_viewTab
.erase(m_viewTab
.begin() + index
);
1151 m_tabBar
->blockSignals(true);
1152 m_tabBar
->removeTab(index
);
1154 if (m_tabIndex
> index
) {
1156 Q_ASSERT(m_tabIndex
>= 0);
1159 // if only one tab is left, also remove the tab entry so that
1160 // closing the last tab is not possible
1161 if (m_viewTab
.count() == 1) {
1162 m_tabBar
->removeTab(0);
1163 actionCollection()->action("close_tab")->setEnabled(false);
1165 m_tabBar
->blockSignals(false);
1169 void DolphinMainWindow::openTabContextMenu(int index
, const QPoint
& pos
)
1173 QAction
* newTabAction
= menu
.addAction(KIcon("tab-new"), i18nc("@action:inmenu", "New Tab"));
1174 newTabAction
->setShortcut(actionCollection()->action("new_tab")->shortcut());
1176 QAction
* detachTabAction
= menu
.addAction(KIcon("tab-detach"), i18nc("@action:inmenu", "Detach Tab"));
1178 QAction
* closeOtherTabsAction
= menu
.addAction(KIcon("tab-close-other"), i18nc("@action:inmenu", "Close Other Tabs"));
1180 QAction
* closeTabAction
= menu
.addAction(KIcon("tab-close"), i18nc("@action:inmenu", "Close Tab"));
1181 closeTabAction
->setShortcut(actionCollection()->action("close_tab")->shortcut());
1182 QAction
* selectedAction
= menu
.exec(pos
);
1183 if (selectedAction
== newTabAction
) {
1184 const ViewTab
& tab
= m_viewTab
[index
];
1185 Q_ASSERT(tab
.primaryView
);
1186 const KUrl url
= tab
.secondaryView
&& tab
.secondaryView
->isActive() ?
1187 tab
.secondaryView
->url() : tab
.primaryView
->url();
1189 m_tabBar
->setCurrentIndex(m_viewTab
.count() - 1);
1190 } else if (selectedAction
== detachTabAction
) {
1191 const QString
separator(QLatin1Char(' '));
1192 QString command
= QLatin1String("dolphin");
1194 const ViewTab
& tab
= m_viewTab
[index
];
1195 Q_ASSERT(tab
.primaryView
);
1197 command
+= separator
+ tab
.primaryView
->url().url();
1198 if (tab
.secondaryView
) {
1199 command
+= separator
+ tab
.secondaryView
->url().url();
1200 command
+= separator
+ QLatin1String("-split");
1203 KRun::runCommand(command
, this);
1206 } else if (selectedAction
== closeOtherTabsAction
) {
1207 const int count
= m_tabBar
->count();
1208 for (int i
= 0; i
< index
; ++i
) {
1211 for (int i
= index
+ 1; i
< count
; ++i
) {
1214 } else if (selectedAction
== closeTabAction
) {
1219 void DolphinMainWindow::slotTabMoved(int from
, int to
)
1221 m_viewTab
.move(from
, to
);
1222 m_tabIndex
= m_tabBar
->currentIndex();
1225 void DolphinMainWindow::slotTestCanDecode(const QDragMoveEvent
* event
, bool& canDecode
)
1227 canDecode
= KUrl::List::canDecode(event
->mimeData());
1230 void DolphinMainWindow::handleUrl(const KUrl
& url
)
1232 delete m_lastHandleUrlStatJob
;
1233 m_lastHandleUrlStatJob
= 0;
1235 if (url
.isLocalFile() && QFileInfo(url
.toLocalFile()).isDir()) {
1236 activeViewContainer()->setUrl(url
);
1237 } else if (KProtocolManager::supportsListing(url
)) {
1238 // stat the URL to see if it is a dir or not
1239 m_lastHandleUrlStatJob
= KIO::stat(url
, KIO::HideProgressInfo
);
1240 if (m_lastHandleUrlStatJob
->ui()) {
1241 m_lastHandleUrlStatJob
->ui()->setWindow(this);
1243 connect(m_lastHandleUrlStatJob
, SIGNAL(result(KJob
*)),
1244 this, SLOT(slotHandleUrlStatFinished(KJob
*)));
1247 new KRun(url
, this); // Automatically deletes itself after being finished
1251 void DolphinMainWindow::slotHandleUrlStatFinished(KJob
* job
)
1253 m_lastHandleUrlStatJob
= 0;
1254 const KIO::UDSEntry entry
= static_cast<KIO::StatJob
*>(job
)->statResult();
1255 const KUrl url
= static_cast<KIO::StatJob
*>(job
)->url();
1256 if (entry
.isDir()) {
1257 activeViewContainer()->setUrl(url
);
1259 new KRun(url
, this); // Automatically deletes itself after being finished
1263 void DolphinMainWindow::tabDropEvent(int tab
, QDropEvent
* event
)
1265 const KUrl::List urls
= KUrl::List::fromMimeData(event
->mimeData());
1266 if (!urls
.isEmpty() && tab
!= -1) {
1267 const ViewTab
& viewTab
= m_viewTab
[tab
];
1268 const DolphinView
* view
= viewTab
.isPrimaryViewActive
? viewTab
.primaryView
->view()
1269 : viewTab
.secondaryView
->view();
1271 DragAndDropHelper::dropUrls(view
->rootItem(), view
->url(), event
, error
);
1272 if (!error
.isEmpty()) {
1273 activeViewContainer()->showMessage(error
, DolphinViewContainer::Error
);
1278 void DolphinMainWindow::slotWriteStateChanged(bool isFolderWritable
)
1280 newFileMenu()->setEnabled(isFolderWritable
);
1283 void DolphinMainWindow::openContextMenu(const QPoint
& pos
,
1284 const KFileItem
& item
,
1286 const QList
<QAction
*>& customActions
)
1288 QWeakPointer
<DolphinContextMenu
> contextMenu
= new DolphinContextMenu(this, pos
, item
, url
);
1289 contextMenu
.data()->setCustomActions(customActions
);
1290 const DolphinContextMenu::Command command
= contextMenu
.data()->open();
1293 case DolphinContextMenu::OpenParentFolderInNewWindow
: {
1294 KRun::run("dolphin %u", KUrl::List() << item
.url().upUrl(), this);
1298 case DolphinContextMenu::OpenParentFolderInNewTab
:
1299 openNewTab(item
.url().upUrl());
1302 case DolphinContextMenu::None
:
1307 delete contextMenu
.data();
1310 void DolphinMainWindow::updateControlMenu()
1312 KMenu
* menu
= qobject_cast
<KMenu
*>(sender());
1315 // All actions get cleared by KMenu::clear(). The sub-menus are deleted
1316 // by connecting to the aboutToHide() signal from the parent-menu.
1319 KActionCollection
* ac
= actionCollection();
1321 // Add "Edit" actions
1322 bool added
= addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::Undo
)), menu
) |
1323 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::Find
)), menu
) |
1324 addActionToMenu(ac
->action("select_all"), menu
) |
1325 addActionToMenu(ac
->action("invert_selection"), menu
);
1328 menu
->addSeparator();
1331 // Add "View" actions
1332 if (!GeneralSettings::showZoomSlider()) {
1333 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ZoomIn
)), menu
);
1334 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ZoomOut
)), menu
);
1335 menu
->addSeparator();
1338 added
= addActionToMenu(ac
->action("view_mode"), menu
) |
1339 addActionToMenu(ac
->action("sort"), menu
) |
1340 addActionToMenu(ac
->action("additional_info"), menu
) |
1341 addActionToMenu(ac
->action("show_preview"), menu
) |
1342 addActionToMenu(ac
->action("show_in_groups"), menu
) |
1343 addActionToMenu(ac
->action("show_hidden_files"), menu
);
1346 menu
->addSeparator();
1349 added
= addActionToMenu(ac
->action("split_view"), menu
) |
1350 addActionToMenu(ac
->action("reload"), menu
) |
1351 addActionToMenu(ac
->action("view_properties"), menu
);
1353 menu
->addSeparator();
1356 addActionToMenu(ac
->action("panels"), menu
);
1357 KMenu
* locationBarMenu
= new KMenu(i18nc("@action:inmenu", "Location Bar"), menu
);
1358 locationBarMenu
->addAction(ac
->action("editable_location"));
1359 locationBarMenu
->addAction(ac
->action("replace_location"));
1360 menu
->addMenu(locationBarMenu
);
1362 menu
->addSeparator();
1365 KMenu
* goMenu
= new KMenu(i18nc("@action:inmenu", "Go"), menu
);
1366 connect(menu
, SIGNAL(aboutToHide()), goMenu
, SLOT(deleteLater()));
1367 goMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Back
)));
1368 goMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Forward
)));
1369 goMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Up
)));
1370 goMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Home
)));
1371 goMenu
->addAction(ac
->action("closed_tabs"));
1372 menu
->addMenu(goMenu
);
1375 KMenu
* toolsMenu
= new KMenu(i18nc("@action:inmenu", "Tools"), menu
);
1376 connect(menu
, SIGNAL(aboutToHide()), toolsMenu
, SLOT(deleteLater()));
1377 toolsMenu
->addAction(ac
->action("show_filter_bar"));
1378 toolsMenu
->addAction(ac
->action("compare_files"));
1379 toolsMenu
->addAction(ac
->action("open_terminal"));
1380 toolsMenu
->addAction(ac
->action("change_remote_encoding"));
1381 menu
->addMenu(toolsMenu
);
1383 // Add "Settings" menu entries
1384 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::KeyBindings
)), menu
);
1385 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ConfigureToolbars
)), menu
);
1386 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::Preferences
)), menu
);
1389 KMenu
* helpMenu
= new KMenu(i18nc("@action:inmenu", "Help"), menu
);
1390 connect(menu
, SIGNAL(aboutToHide()), helpMenu
, SLOT(deleteLater()));
1391 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::HelpContents
)));
1392 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::WhatsThis
)));
1393 helpMenu
->addSeparator();
1394 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::ReportBug
)));
1395 helpMenu
->addSeparator();
1396 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::SwitchApplicationLanguage
)));
1397 helpMenu
->addSeparator();
1398 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::AboutApp
)));
1399 helpMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::AboutKDE
)));
1400 menu
->addMenu(helpMenu
);
1402 menu
->addSeparator();
1403 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ShowMenubar
)), menu
);
1406 void DolphinMainWindow::updateToolBar()
1408 if (!menuBar()->isVisible()) {
1409 createControlButton();
1413 void DolphinMainWindow::slotControlButtonDeleted()
1415 m_controlButton
= 0;
1416 m_updateToolBarTimer
->start();
1419 void DolphinMainWindow::slotPanelErrorMessage(const QString
& error
)
1421 activeViewContainer()->showMessage(error
, DolphinViewContainer::Error
);
1424 void DolphinMainWindow::slotPlaceActivated(const KUrl
& url
)
1426 DolphinViewContainer
* view
= activeViewContainer();
1428 if (view
->url() == url
) {
1429 // We can end up here if the user clicked a device in the Places Panel
1430 // which had been unmounted earlier, see https://bugs.kde.org/show_bug.cgi?id=161385.
1437 void DolphinMainWindow::setActiveViewContainer(DolphinViewContainer
* viewContainer
)
1439 Q_ASSERT(viewContainer
);
1440 Q_ASSERT((viewContainer
== m_viewTab
[m_tabIndex
].primaryView
) ||
1441 (viewContainer
== m_viewTab
[m_tabIndex
].secondaryView
));
1442 if (m_activeViewContainer
== viewContainer
) {
1446 m_activeViewContainer
->setActive(false);
1447 m_activeViewContainer
= viewContainer
;
1449 // Activating the view container might trigger a recursive setActiveViewContainer() call
1450 // inside DolphinMainWindow::toggleActiveView() when having a split view. Temporary
1451 // disconnect the activated() signal in this case:
1452 disconnect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1453 m_activeViewContainer
->setActive(true);
1454 connect(m_activeViewContainer
->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
1456 m_actionHandler
->setCurrentView(viewContainer
->view());
1459 updateEditActions();
1460 updateViewActions();
1463 const KUrl url
= m_activeViewContainer
->url();
1464 setUrlAsCaption(url
);
1465 if (m_viewTab
.count() > 1) {
1466 m_tabBar
->setTabText(m_tabIndex
, tabName(url
));
1467 m_tabBar
->setTabIcon(m_tabIndex
, KIcon(KMimeType::iconNameForUrl(url
)));
1470 emit
urlChanged(url
);
1473 DolphinViewContainer
* DolphinMainWindow::createViewContainer(const KUrl
& url
, QWidget
* parent
)
1475 DolphinViewContainer
* container
= new DolphinViewContainer(url
, parent
);
1477 // The places-selector from the URL navigator should only be shown
1478 // if the places dock is invisible
1479 QDockWidget
* placesDock
= findChild
<QDockWidget
*>("placesDock");
1480 container
->urlNavigator()->setPlacesSelectorVisible(!placesDock
|| !placesDock
->isVisible());
1485 void DolphinMainWindow::setupActions()
1487 // setup 'File' menu
1488 m_newFileMenu
= new DolphinNewFileMenu(actionCollection(), this);
1489 KMenu
* menu
= m_newFileMenu
->menu();
1490 menu
->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1491 menu
->setIcon(KIcon("document-new"));
1492 m_newFileMenu
->setDelayed(false);
1493 connect(menu
, SIGNAL(aboutToShow()),
1494 this, SLOT(updateNewMenu()));
1496 KAction
* newWindow
= actionCollection()->addAction("new_window");
1497 newWindow
->setIcon(KIcon("window-new"));
1498 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
1499 newWindow
->setShortcut(Qt::CTRL
| Qt::Key_N
);
1500 connect(newWindow
, SIGNAL(triggered()), this, SLOT(openNewMainWindow()));
1502 KAction
* newTab
= actionCollection()->addAction("new_tab");
1503 newTab
->setIcon(KIcon("tab-new"));
1504 newTab
->setText(i18nc("@action:inmenu File", "New Tab"));
1505 newTab
->setShortcut(KShortcut(Qt::CTRL
| Qt::Key_T
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_N
));
1506 connect(newTab
, SIGNAL(triggered()), this, SLOT(openNewTab()));
1508 KAction
* closeTab
= actionCollection()->addAction("close_tab");
1509 closeTab
->setIcon(KIcon("tab-close"));
1510 closeTab
->setText(i18nc("@action:inmenu File", "Close Tab"));
1511 closeTab
->setShortcut(Qt::CTRL
| Qt::Key_W
);
1512 closeTab
->setEnabled(false);
1513 connect(closeTab
, SIGNAL(triggered()), this, SLOT(closeTab()));
1515 KStandardAction::quit(this, SLOT(quit()), actionCollection());
1517 // setup 'Edit' menu
1518 KStandardAction::undo(this,
1520 actionCollection());
1522 // need to remove shift+del from cut action, else the shortcut for deletejob
1524 KAction
* cut
= KStandardAction::cut(this, SLOT(cut()), actionCollection());
1525 KShortcut cutShortcut
= cut
->shortcut();
1526 cutShortcut
.remove(Qt::SHIFT
| Qt::Key_Delete
, KShortcut::KeepEmpty
);
1527 cut
->setShortcut(cutShortcut
);
1528 KStandardAction::copy(this, SLOT(copy()), actionCollection());
1529 KAction
* paste
= KStandardAction::paste(this, SLOT(paste()), actionCollection());
1530 // The text of the paste-action is modified dynamically by Dolphin
1531 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1532 // due to the long text, the text "Paste" is used:
1533 paste
->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1535 KStandardAction::find(this, SLOT(find()), actionCollection());
1537 KAction
* selectAll
= actionCollection()->addAction("select_all");
1538 selectAll
->setText(i18nc("@action:inmenu Edit", "Select All"));
1539 selectAll
->setShortcut(Qt::CTRL
| Qt::Key_A
);
1540 connect(selectAll
, SIGNAL(triggered()), this, SLOT(selectAll()));
1542 KAction
* invertSelection
= actionCollection()->addAction("invert_selection");
1543 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1544 invertSelection
->setShortcut(Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
1545 connect(invertSelection
, SIGNAL(triggered()), this, SLOT(invertSelection()));
1547 // setup 'View' menu
1548 // (note that most of it is set up in DolphinViewActionHandler)
1550 KAction
* split
= actionCollection()->addAction("split_view");
1551 split
->setShortcut(Qt::Key_F3
);
1552 updateSplitAction();
1553 connect(split
, SIGNAL(triggered()), this, SLOT(toggleSplitView()));
1555 KAction
* reload
= actionCollection()->addAction("reload");
1556 reload
->setText(i18nc("@action:inmenu View", "Reload"));
1557 reload
->setShortcut(Qt::Key_F5
);
1558 reload
->setIcon(KIcon("view-refresh"));
1559 connect(reload
, SIGNAL(triggered()), this, SLOT(reloadView()));
1561 KAction
* stop
= actionCollection()->addAction("stop");
1562 stop
->setText(i18nc("@action:inmenu View", "Stop"));
1563 stop
->setToolTip(i18nc("@info", "Stop loading"));
1564 stop
->setIcon(KIcon("process-stop"));
1565 connect(stop
, SIGNAL(triggered()), this, SLOT(stopLoading()));
1567 KToggleAction
* editableLocation
= actionCollection()->add
<KToggleAction
>("editable_location");
1568 editableLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1569 editableLocation
->setShortcut(Qt::Key_F6
);
1570 connect(editableLocation
, SIGNAL(triggered()), this, SLOT(toggleEditLocation()));
1572 KAction
* replaceLocation
= actionCollection()->addAction("replace_location");
1573 replaceLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1574 replaceLocation
->setShortcut(Qt::CTRL
| Qt::Key_L
);
1575 connect(replaceLocation
, SIGNAL(triggered()), this, SLOT(replaceLocation()));
1578 KAction
* backAction
= KStandardAction::back(this, SLOT(goBack()), actionCollection());
1579 connect(backAction
, SIGNAL(triggered(Qt::MouseButtons
,Qt::KeyboardModifiers
)), this, SLOT(goBack(Qt::MouseButtons
)));
1580 KShortcut backShortcut
= backAction
->shortcut();
1581 backShortcut
.setAlternate(Qt::Key_Backspace
);
1582 backAction
->setShortcut(backShortcut
);
1584 m_recentTabsMenu
= new KActionMenu(i18n("Recently Closed Tabs"), this);
1585 m_recentTabsMenu
->setIcon(KIcon("edit-undo"));
1586 m_recentTabsMenu
->setDelayed(false);
1587 actionCollection()->addAction("closed_tabs", m_recentTabsMenu
);
1588 connect(m_recentTabsMenu
->menu(), SIGNAL(triggered(QAction
*)),
1589 this, SLOT(restoreClosedTab(QAction
*)));
1591 QAction
* action
= new QAction(i18n("Empty Recently Closed Tabs"), m_recentTabsMenu
);
1592 action
->setIcon(KIcon("edit-clear-list"));
1593 action
->setData(QVariant::fromValue(true));
1594 m_recentTabsMenu
->addAction(action
);
1595 m_recentTabsMenu
->addSeparator();
1596 m_recentTabsMenu
->setEnabled(false);
1598 KAction
* forwardAction
= KStandardAction::forward(this, SLOT(goForward()), actionCollection());
1599 connect(forwardAction
, SIGNAL(triggered(Qt::MouseButtons
,Qt::KeyboardModifiers
)), this, SLOT(goForward(Qt::MouseButtons
)));
1601 KAction
* upAction
= KStandardAction::up(this, SLOT(goUp()), actionCollection());
1602 connect(upAction
, SIGNAL(triggered(Qt::MouseButtons
,Qt::KeyboardModifiers
)), this, SLOT(goUp(Qt::MouseButtons
)));
1604 KAction
* homeAction
= KStandardAction::home(this, SLOT(goHome()), actionCollection());
1605 connect(homeAction
, SIGNAL(triggered(Qt::MouseButtons
,Qt::KeyboardModifiers
)), this, SLOT(goHome(Qt::MouseButtons
)));
1607 // setup 'Tools' menu
1608 KAction
* showFilterBar
= actionCollection()->addAction("show_filter_bar");
1609 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Show Filter Bar"));
1610 showFilterBar
->setIcon(KIcon("view-filter"));
1611 showFilterBar
->setShortcut(Qt::CTRL
| Qt::Key_I
);
1612 connect(showFilterBar
, SIGNAL(triggered()), this, SLOT(showFilterBar()));
1614 KAction
* compareFiles
= actionCollection()->addAction("compare_files");
1615 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1616 compareFiles
->setIcon(KIcon("kompare"));
1617 compareFiles
->setEnabled(false);
1618 connect(compareFiles
, SIGNAL(triggered()), this, SLOT(compareFiles()));
1620 KAction
* openTerminal
= actionCollection()->addAction("open_terminal");
1621 openTerminal
->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
1622 openTerminal
->setIcon(KIcon("utilities-terminal"));
1623 openTerminal
->setShortcut(Qt::SHIFT
| Qt::Key_F4
);
1624 connect(openTerminal
, SIGNAL(triggered()), this, SLOT(openTerminal()));
1626 // setup 'Settings' menu
1627 KToggleAction
* showMenuBar
= KStandardAction::showMenubar(0, 0, actionCollection());
1628 connect(showMenuBar
, SIGNAL(triggered(bool)), // Fixes #286822
1629 this, SLOT(toggleShowMenuBar()), Qt::QueuedConnection
);
1630 KStandardAction::preferences(this, SLOT(editSettings()), actionCollection());
1632 // not in menu actions
1633 QList
<QKeySequence
> nextTabKeys
;
1634 nextTabKeys
.append(KStandardShortcut::tabNext().primary());
1635 nextTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::Key_Tab
));
1637 QList
<QKeySequence
> prevTabKeys
;
1638 prevTabKeys
.append(KStandardShortcut::tabPrev().primary());
1639 prevTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::SHIFT
| Qt::Key_Tab
));
1641 KAction
* activateNextTab
= actionCollection()->addAction("activate_next_tab");
1642 activateNextTab
->setText(i18nc("@action:inmenu", "Activate Next Tab"));
1643 connect(activateNextTab
, SIGNAL(triggered()), SLOT(activateNextTab()));
1644 activateNextTab
->setShortcuts(QApplication::isRightToLeft() ? prevTabKeys
: nextTabKeys
);
1646 KAction
* activatePrevTab
= actionCollection()->addAction("activate_prev_tab");
1647 activatePrevTab
->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
1648 connect(activatePrevTab
, SIGNAL(triggered()), SLOT(activatePrevTab()));
1649 activatePrevTab
->setShortcuts(QApplication::isRightToLeft() ? nextTabKeys
: prevTabKeys
);
1652 KAction
* openInNewTab
= actionCollection()->addAction("open_in_new_tab");
1653 openInNewTab
->setText(i18nc("@action:inmenu", "Open in New Tab"));
1654 openInNewTab
->setIcon(KIcon("tab-new"));
1655 connect(openInNewTab
, SIGNAL(triggered()), this, SLOT(openInNewTab()));
1657 KAction
* openInNewTabs
= actionCollection()->addAction("open_in_new_tabs");
1658 openInNewTabs
->setText(i18nc("@action:inmenu", "Open in New Tabs"));
1659 openInNewTabs
->setIcon(KIcon("tab-new"));
1660 connect(openInNewTabs
, SIGNAL(triggered()), this, SLOT(openInNewTab()));
1662 KAction
* openInNewWindow
= actionCollection()->addAction("open_in_new_window");
1663 openInNewWindow
->setText(i18nc("@action:inmenu", "Open in New Window"));
1664 openInNewWindow
->setIcon(KIcon("window-new"));
1665 connect(openInNewWindow
, SIGNAL(triggered()), this, SLOT(openInNewWindow()));
1668 void DolphinMainWindow::setupDockWidgets()
1670 const bool lock
= GeneralSettings::lockPanels();
1672 KDualAction
* lockLayoutAction
= actionCollection()->add
<KDualAction
>("lock_panels");
1673 lockLayoutAction
->setActiveText(i18nc("@action:inmenu Panels", "Unlock Panels"));
1674 lockLayoutAction
->setActiveIcon(KIcon("object-unlocked"));
1675 lockLayoutAction
->setInactiveText(i18nc("@action:inmenu Panels", "Lock Panels"));
1676 lockLayoutAction
->setInactiveIcon(KIcon("object-locked"));
1677 lockLayoutAction
->setActive(lock
);
1678 connect(lockLayoutAction
, SIGNAL(triggered()), this, SLOT(togglePanelLockState()));
1680 // Setup "Information"
1681 DolphinDockWidget
* infoDock
= new DolphinDockWidget(i18nc("@title:window", "Information"));
1682 infoDock
->setLocked(lock
);
1683 infoDock
->setObjectName("infoDock");
1684 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1685 Panel
* infoPanel
= new InformationPanel(infoDock
);
1686 infoPanel
->setCustomContextMenuActions(QList
<QAction
*>() << lockLayoutAction
);
1687 connect(infoPanel
, SIGNAL(urlActivated(KUrl
)), this, SLOT(handleUrl(KUrl
)));
1688 infoDock
->setWidget(infoPanel
);
1690 QAction
* infoAction
= infoDock
->toggleViewAction();
1691 createPanelAction(KIcon("dialog-information"), Qt::Key_F11
, infoAction
, "show_information_panel");
1693 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
1694 connect(this, SIGNAL(urlChanged(KUrl
)),
1695 infoPanel
, SLOT(setUrl(KUrl
)));
1696 connect(this, SIGNAL(selectionChanged(KFileItemList
)),
1697 infoPanel
, SLOT(setSelection(KFileItemList
)));
1698 connect(this, SIGNAL(requestItemInfo(KFileItem
)),
1699 infoPanel
, SLOT(requestDelayedItemInfo(KFileItem
)));
1702 DolphinDockWidget
* foldersDock
= new DolphinDockWidget(i18nc("@title:window", "Folders"));
1703 foldersDock
->setLocked(lock
);
1704 foldersDock
->setObjectName("foldersDock");
1705 foldersDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1706 FoldersPanel
* foldersPanel
= new FoldersPanel(foldersDock
);
1707 foldersPanel
->setCustomContextMenuActions(QList
<QAction
*>() << lockLayoutAction
);
1708 foldersDock
->setWidget(foldersPanel
);
1710 QAction
* foldersAction
= foldersDock
->toggleViewAction();
1711 createPanelAction(KIcon("folder"), Qt::Key_F7
, foldersAction
, "show_folders_panel");
1713 addDockWidget(Qt::LeftDockWidgetArea
, foldersDock
);
1714 connect(this, SIGNAL(urlChanged(KUrl
)),
1715 foldersPanel
, SLOT(setUrl(KUrl
)));
1716 connect(foldersPanel
, SIGNAL(folderActivated(KUrl
)),
1717 this, SLOT(changeUrl(KUrl
)));
1718 connect(foldersPanel
, SIGNAL(folderMiddleClicked(KUrl
)),
1719 this, SLOT(openNewTab(KUrl
)));
1720 connect(foldersPanel
, SIGNAL(errorMessage(QString
)),
1721 this, SLOT(slotPanelErrorMessage(QString
)));
1725 DolphinDockWidget
* terminalDock
= new DolphinDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
1726 terminalDock
->setLocked(lock
);
1727 terminalDock
->setObjectName("terminalDock");
1728 terminalDock
->setAllowedAreas(Qt::TopDockWidgetArea
| Qt::BottomDockWidgetArea
);
1729 Panel
* terminalPanel
= new TerminalPanel(terminalDock
);
1730 terminalPanel
->setCustomContextMenuActions(QList
<QAction
*>() << lockLayoutAction
);
1731 terminalDock
->setWidget(terminalPanel
);
1733 connect(terminalPanel
, SIGNAL(hideTerminalPanel()), terminalDock
, SLOT(hide()));
1734 connect(terminalPanel
, SIGNAL(changeUrl(KUrl
)), this, SLOT(slotTerminalDirectoryChanged(KUrl
)));
1735 connect(terminalDock
, SIGNAL(visibilityChanged(bool)),
1736 terminalPanel
, SLOT(dockVisibilityChanged()));
1738 QAction
* terminalAction
= terminalDock
->toggleViewAction();
1739 createPanelAction(KIcon("utilities-terminal"), Qt::Key_F4
, terminalAction
, "show_terminal_panel");
1741 addDockWidget(Qt::BottomDockWidgetArea
, terminalDock
);
1742 connect(this, SIGNAL(urlChanged(KUrl
)),
1743 terminalPanel
, SLOT(setUrl(KUrl
)));
1746 if (GeneralSettings::version() < 200) {
1748 foldersDock
->hide();
1750 terminalDock
->hide();
1755 DolphinDockWidget
* placesDock
= new DolphinDockWidget(i18nc("@title:window", "Places"));
1756 placesDock
->setLocked(lock
);
1757 placesDock
->setObjectName("placesDock");
1758 placesDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1760 PlacesPanel
* placesPanel
= new PlacesPanel(placesDock
);
1761 placesPanel
->setCustomContextMenuActions(QList
<QAction
*>() << lockLayoutAction
);
1762 placesDock
->setWidget(placesPanel
);
1764 QAction
* placesAction
= placesDock
->toggleViewAction();
1765 createPanelAction(KIcon("bookmarks"), Qt::Key_F9
, placesAction
, "show_places_panel");
1767 addDockWidget(Qt::LeftDockWidgetArea
, placesDock
);
1768 connect(placesPanel
, SIGNAL(placeActivated(KUrl
)),
1769 this, SLOT(slotPlaceActivated(KUrl
)));
1770 connect(placesPanel
, SIGNAL(placeMiddleClicked(KUrl
)),
1771 this, SLOT(openNewTab(KUrl
)));
1772 connect(placesPanel
, SIGNAL(errorMessage(QString
)),
1773 this, SLOT(slotPanelErrorMessage(QString
)));
1774 connect(this, SIGNAL(urlChanged(KUrl
)),
1775 placesPanel
, SLOT(setUrl(KUrl
)));
1776 connect(placesDock
, SIGNAL(visibilityChanged(bool)),
1777 this, SLOT(slotPlacesPanelVisibilityChanged(bool)));
1778 connect(this, SIGNAL(settingsChanged()),
1779 placesPanel
, SLOT(readSettings()));
1781 // Add actions into the "Panels" menu
1782 KActionMenu
* panelsMenu
= new KActionMenu(i18nc("@action:inmenu View", "Panels"), this);
1783 actionCollection()->addAction("panels", panelsMenu
);
1784 panelsMenu
->setDelayed(false);
1785 const KActionCollection
* ac
= actionCollection();
1786 panelsMenu
->addAction(ac
->action("show_places_panel"));
1787 panelsMenu
->addAction(ac
->action("show_information_panel"));
1788 panelsMenu
->addAction(ac
->action("show_folders_panel"));
1790 panelsMenu
->addAction(ac
->action("show_terminal_panel"));
1792 panelsMenu
->addSeparator();
1793 panelsMenu
->addAction(lockLayoutAction
);
1796 void DolphinMainWindow::updateEditActions()
1798 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
1799 if (list
.isEmpty()) {
1800 stateChanged("has_no_selection");
1802 stateChanged("has_selection");
1804 KActionCollection
* col
= actionCollection();
1805 QAction
* renameAction
= col
->action("rename");
1806 QAction
* moveToTrashAction
= col
->action("move_to_trash");
1807 QAction
* deleteAction
= col
->action("delete");
1808 QAction
* cutAction
= col
->action(KStandardAction::name(KStandardAction::Cut
));
1809 QAction
* deleteWithTrashShortcut
= col
->action("delete_shortcut"); // see DolphinViewActionHandler
1811 KFileItemListProperties
capabilities(list
);
1812 const bool enableMoveToTrash
= capabilities
.isLocal() && capabilities
.supportsMoving();
1814 renameAction
->setEnabled(capabilities
.supportsMoving());
1815 moveToTrashAction
->setEnabled(enableMoveToTrash
);
1816 deleteAction
->setEnabled(capabilities
.supportsDeleting());
1817 deleteWithTrashShortcut
->setEnabled(capabilities
.supportsDeleting() && !enableMoveToTrash
);
1818 cutAction
->setEnabled(capabilities
.supportsMoving());
1820 updatePasteAction();
1823 void DolphinMainWindow::updateViewActions()
1825 m_actionHandler
->updateViewActions();
1827 QAction
* showFilterBarAction
= actionCollection()->action("show_filter_bar");
1828 showFilterBarAction
->setChecked(m_activeViewContainer
->isFilterBarVisible());
1830 updateSplitAction();
1832 QAction
* editableLocactionAction
= actionCollection()->action("editable_location");
1833 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
1834 editableLocactionAction
->setChecked(urlNavigator
->isUrlEditable());
1837 void DolphinMainWindow::updateGoActions()
1839 QAction
* goUpAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Up
));
1840 const KUrl currentUrl
= m_activeViewContainer
->url();
1841 goUpAction
->setEnabled(currentUrl
.upUrl() != currentUrl
);
1844 void DolphinMainWindow::createControlButton()
1846 if (m_controlButton
) {
1849 Q_ASSERT(!m_controlButton
);
1851 m_controlButton
= new QToolButton(this);
1852 m_controlButton
->setIcon(KIcon("applications-system"));
1853 m_controlButton
->setText(i18nc("@action", "Control"));
1854 m_controlButton
->setPopupMode(QToolButton::InstantPopup
);
1855 m_controlButton
->setToolButtonStyle(toolBar()->toolButtonStyle());
1857 KMenu
* controlMenu
= new KMenu(m_controlButton
);
1858 connect(controlMenu
, SIGNAL(aboutToShow()), this, SLOT(updateControlMenu()));
1860 m_controlButton
->setMenu(controlMenu
);
1862 toolBar()->addWidget(m_controlButton
);
1863 connect(toolBar(), SIGNAL(iconSizeChanged(QSize
)),
1864 m_controlButton
, SLOT(setIconSize(QSize
)));
1865 connect(toolBar(), SIGNAL(toolButtonStyleChanged(Qt::ToolButtonStyle
)),
1866 m_controlButton
, SLOT(setToolButtonStyle(Qt::ToolButtonStyle
)));
1868 // The added widgets are owned by the toolbar and may get deleted when e.g. the toolbar
1869 // gets edited. In this case we must add them again. The adding is done asynchronously by
1870 // m_updateToolBarTimer.
1871 connect(m_controlButton
, SIGNAL(destroyed()), this, SLOT(slotControlButtonDeleted()));
1872 m_updateToolBarTimer
= new QTimer(this);
1873 m_updateToolBarTimer
->setInterval(500);
1874 connect(m_updateToolBarTimer
, SIGNAL(timeout()), this, SLOT(updateToolBar()));
1877 void DolphinMainWindow::deleteControlButton()
1879 delete m_controlButton
;
1880 m_controlButton
= 0;
1882 delete m_updateToolBarTimer
;
1883 m_updateToolBarTimer
= 0;
1886 bool DolphinMainWindow::addActionToMenu(QAction
* action
, KMenu
* menu
)
1891 const KToolBar
* toolBarWidget
= toolBar();
1892 foreach (const QWidget
* widget
, action
->associatedWidgets()) {
1893 if (widget
== toolBarWidget
) {
1898 menu
->addAction(action
);
1902 void DolphinMainWindow::rememberClosedTab(int index
)
1904 KMenu
* tabsMenu
= m_recentTabsMenu
->menu();
1906 const QString primaryPath
= m_viewTab
[index
].primaryView
->url().path();
1907 const QString iconName
= KMimeType::iconNameForUrl(primaryPath
);
1909 QAction
* action
= new QAction(squeezedText(primaryPath
), tabsMenu
);
1911 ClosedTab closedTab
;
1912 closedTab
.primaryUrl
= m_viewTab
[index
].primaryView
->url();
1914 if (m_viewTab
[index
].secondaryView
) {
1915 closedTab
.secondaryUrl
= m_viewTab
[index
].secondaryView
->url();
1916 closedTab
.isSplit
= true;
1918 closedTab
.isSplit
= false;
1921 action
->setData(QVariant::fromValue(closedTab
));
1922 action
->setIcon(KIcon(iconName
));
1924 // add the closed tab menu entry after the separator and
1925 // "Empty Recently Closed Tabs" entry
1926 if (tabsMenu
->actions().size() == 2) {
1927 tabsMenu
->addAction(action
);
1929 tabsMenu
->insertAction(tabsMenu
->actions().at(2), action
);
1932 // assure that only up to 8 closed tabs are shown in the menu
1933 if (tabsMenu
->actions().size() > 8) {
1934 tabsMenu
->removeAction(tabsMenu
->actions().last());
1936 actionCollection()->action("closed_tabs")->setEnabled(true);
1937 KAcceleratorManager::manage(tabsMenu
);
1940 void DolphinMainWindow::refreshViews()
1942 Q_ASSERT(m_viewTab
[m_tabIndex
].primaryView
);
1944 // remember the current active view, as because of
1945 // the refreshing the active view might change to
1946 // the secondary view
1947 DolphinViewContainer
* activeViewContainer
= m_activeViewContainer
;
1949 const int tabCount
= m_viewTab
.count();
1950 for (int i
= 0; i
< tabCount
; ++i
) {
1951 m_viewTab
[i
].primaryView
->readSettings();
1952 if (m_viewTab
[i
].secondaryView
) {
1953 m_viewTab
[i
].secondaryView
->readSettings();
1957 setActiveViewContainer(activeViewContainer
);
1959 if (GeneralSettings::modifiedStartupSettings()) {
1960 // The startup settings have been changed by the user (see bug #254947).
1961 // Synchronize the split-view setting with the active view:
1962 const bool splitView
= GeneralSettings::splitView();
1963 const ViewTab
& activeTab
= m_viewTab
[m_tabIndex
];
1964 const bool toggle
= ( splitView
&& !activeTab
.secondaryView
)
1965 || (!splitView
&& activeTab
.secondaryView
);
1971 emit
settingsChanged();
1974 void DolphinMainWindow::clearStatusBar()
1976 m_activeViewContainer
->statusBar()->resetToDefaultText();
1979 void DolphinMainWindow::connectViewSignals(DolphinViewContainer
* container
)
1981 connect(container
, SIGNAL(showFilterBarChanged(bool)),
1982 this, SLOT(updateFilterBarAction(bool)));
1983 connect(container
, SIGNAL(writeStateChanged(bool)),
1984 this, SLOT(slotWriteStateChanged(bool)));
1986 DolphinView
* view
= container
->view();
1987 connect(view
, SIGNAL(selectionChanged(KFileItemList
)),
1988 this, SLOT(slotSelectionChanged(KFileItemList
)));
1989 connect(view
, SIGNAL(requestItemInfo(KFileItem
)),
1990 this, SLOT(slotRequestItemInfo(KFileItem
)));
1991 connect(view
, SIGNAL(activated()),
1992 this, SLOT(toggleActiveView()));
1993 connect(view
, SIGNAL(tabRequested(KUrl
)),
1994 this, SLOT(openNewTab(KUrl
)));
1995 connect(view
, SIGNAL(requestContextMenu(QPoint
,KFileItem
,KUrl
,QList
<QAction
*>)),
1996 this, SLOT(openContextMenu(QPoint
,KFileItem
,KUrl
,QList
<QAction
*>)));
1997 connect(view
, SIGNAL(directoryLoadingStarted()),
1998 this, SLOT(enableStopAction()));
1999 connect(view
, SIGNAL(directoryLoadingCompleted()),
2000 this, SLOT(disableStopAction()));
2001 connect(view
, SIGNAL(goBackRequested()),
2002 this, SLOT(goBack()));
2003 connect(view
, SIGNAL(goForwardRequested()),
2004 this, SLOT(goForward()));
2006 const KUrlNavigator
* navigator
= container
->urlNavigator();
2007 connect(navigator
, SIGNAL(urlChanged(KUrl
)),
2008 this, SLOT(changeUrl(KUrl
)));
2009 connect(navigator
, SIGNAL(historyChanged()),
2010 this, SLOT(updateHistory()));
2011 connect(navigator
, SIGNAL(editableStateChanged(bool)),
2012 this, SLOT(slotEditableStateChanged(bool)));
2013 connect(navigator
, SIGNAL(tabRequested(KUrl
)),
2014 this, SLOT(openNewTab(KUrl
)));
2017 void DolphinMainWindow::updateSplitAction()
2019 QAction
* splitAction
= actionCollection()->action("split_view");
2020 if (m_viewTab
[m_tabIndex
].secondaryView
) {
2021 if (m_activeViewContainer
== m_viewTab
[m_tabIndex
].secondaryView
) {
2022 splitAction
->setText(i18nc("@action:intoolbar Close right view", "Close"));
2023 splitAction
->setToolTip(i18nc("@info", "Close right view"));
2024 splitAction
->setIcon(KIcon("view-right-close"));
2026 splitAction
->setText(i18nc("@action:intoolbar Close left view", "Close"));
2027 splitAction
->setToolTip(i18nc("@info", "Close left view"));
2028 splitAction
->setIcon(KIcon("view-left-close"));
2031 splitAction
->setText(i18nc("@action:intoolbar Split view", "Split"));
2032 splitAction
->setToolTip(i18nc("@info", "Split view"));
2033 splitAction
->setIcon(KIcon("view-right-new"));
2037 QString
DolphinMainWindow::tabName(const KUrl
& url
) const
2040 if (url
.equals(KUrl("file:///"))) {
2043 name
= url
.fileName();
2044 if (name
.isEmpty()) {
2045 name
= url
.protocol();
2047 // Make sure that a '&' inside the directory name is displayed correctly
2048 // and not misinterpreted as a keyboard shortcut in QTabBar::setTabText()
2049 name
.replace('&', "&&");
2055 bool DolphinMainWindow::isKompareInstalled() const
2057 static bool initialized
= false;
2058 static bool installed
= false;
2060 // TODO: maybe replace this approach later by using a menu
2061 // plugin like kdiff3plugin.cpp
2062 installed
= !KGlobal::dirs()->findExe("kompare").isEmpty();
2068 void DolphinMainWindow::createSecondaryView(int tabIndex
)
2070 ViewTab
& viewTab
= m_viewTab
[tabIndex
];
2072 QSplitter
* splitter
= viewTab
.splitter
;
2073 const int newWidth
= (viewTab
.primaryView
->width() - splitter
->handleWidth()) / 2;
2075 const DolphinView
* view
= viewTab
.primaryView
->view();
2076 // The final parent of the new view container will be set by adding it
2077 // to the splitter. However, we must make sure that the DolphinMainWindow
2078 // is a parent of the view container already when it is constructed
2079 // because this enables the container's KFileItemModel to assign its
2080 // dir lister to the right main window. The dir lister can then cache
2081 // authentication data.
2082 viewTab
.secondaryView
= createViewContainer(view
->url(), this);
2083 splitter
->addWidget(viewTab
.secondaryView
);
2084 splitter
->setSizes(QList
<int>() << newWidth
<< newWidth
);
2086 connectViewSignals(viewTab
.secondaryView
);
2087 viewTab
.secondaryView
->setActive(false);
2088 viewTab
.secondaryView
->resize(newWidth
, viewTab
.primaryView
->height());
2089 viewTab
.secondaryView
->show();
2092 QString
DolphinMainWindow::tabProperty(const QString
& property
, int tabIndex
) const
2094 return "Tab " + QString::number(tabIndex
) + ' ' + property
;
2097 void DolphinMainWindow::setUrlAsCaption(const KUrl
& url
)
2100 if (!url
.isLocalFile()) {
2101 caption
.append(url
.protocol() + " - ");
2102 if (url
.hasHost()) {
2103 caption
.append(url
.host() + " - ");
2107 const QString fileName
= url
.fileName().isEmpty() ? "/" : url
.fileName();
2108 caption
.append(fileName
);
2110 setCaption(caption
);
2113 QString
DolphinMainWindow::squeezedText(const QString
& text
) const
2115 const QFontMetrics fm
= fontMetrics();
2116 return fm
.elidedText(text
, Qt::ElideMiddle
, fm
.maxWidth() * 10);
2119 void DolphinMainWindow::createPanelAction(const KIcon
& icon
,
2120 const QKeySequence
& shortcut
,
2121 QAction
* dockAction
,
2122 const QString
& actionName
)
2124 KAction
* panelAction
= actionCollection()->addAction(actionName
);
2125 panelAction
->setCheckable(true);
2126 panelAction
->setChecked(dockAction
->isChecked());
2127 panelAction
->setText(dockAction
->text());
2128 panelAction
->setIcon(icon
);
2129 panelAction
->setShortcut(shortcut
);
2131 connect(panelAction
, SIGNAL(triggered()), dockAction
, SLOT(trigger()));
2132 connect(dockAction
, SIGNAL(toggled(bool)), panelAction
, SLOT(setChecked(bool)));
2135 DolphinMainWindow::UndoUiInterface::UndoUiInterface() :
2136 KIO::FileUndoManager::UiInterface()
2140 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
2144 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
* job
)
2146 DolphinMainWindow
* mainWin
= qobject_cast
<DolphinMainWindow
*>(parentWidget());
2148 DolphinViewContainer
* container
= mainWin
->activeViewContainer();
2149 container
->showMessage(job
->errorString(), DolphinViewContainer::Error
);
2151 KIO::FileUndoManager::UiInterface::jobError(job
);
2155 #include "dolphinmainwindow.moc"