2 * SPDX-FileCopyrightText: 2006 Peter Penz <peter.penz19@gmail.com>
3 * SPDX-FileCopyrightText: 2006 Stefan Monov <logixoul@gmail.com>
4 * SPDX-FileCopyrightText: 2006 Cvetoslav Ludmiloff <ludmiloff@gmail.com>
6 * SPDX-License-Identifier: GPL-2.0-or-later
9 #include "dolphinmainwindow.h"
11 #include "dolphin_generalsettings.h"
12 #include "dolphinbookmarkhandler.h"
13 #include "dolphincontextmenu.h"
14 #include "dolphindockwidget.h"
15 #include "dolphinmainwindowadaptor.h"
16 #include "dolphinnavigatorswidgetaction.h"
17 #include "dolphinnewfilemenu.h"
18 #include "dolphinplacesmodelsingleton.h"
19 #include "dolphinrecenttabsmenu.h"
20 #include "dolphintabpage.h"
21 #include "dolphinurlnavigatorscontroller.h"
22 #include "dolphinviewcontainer.h"
24 #include "middleclickactioneventfilter.h"
25 #include "panels/folders/folderspanel.h"
26 #include "panels/places/placespanel.h"
27 #include "panels/terminal/terminalpanel.h"
28 #include "selectionmode/actiontexthelper.h"
29 #include "settings/dolphinsettingsdialog.h"
30 #include "statusbar/dolphinstatusbar.h"
31 #include "views/dolphinnewfilemenuobserver.h"
32 #include "views/dolphinremoteencoding.h"
33 #include "views/dolphinviewactionhandler.h"
34 #include "views/draganddrophelper.h"
35 #include "views/viewproperties.h"
37 #include <KActionCollection>
38 #include <KActionMenu>
39 #include <KAuthorized>
40 #include <KColorSchemeManager>
43 #include <KDualAction>
44 #include <KFileItemListProperties>
45 #include <KIO/CommandLauncherJob>
46 #include <KIO/JobUiDelegateFactory>
47 #include <KIO/OpenFileManagerWindowJob>
48 #include <KIO/OpenUrlJob>
49 #include <KJobWidgets>
50 #include <KLocalizedString>
51 #include <KMessageBox>
52 #include <KProtocolInfo>
53 #include <KProtocolManager>
55 #include <KShortcutsDialog>
56 #include <KStandardAction>
58 #include <KTerminalLauncherJob>
59 #include <KToggleAction>
61 #include <KToolBarPopupAction>
62 #include <KUrlComboBox>
63 #include <KUrlNavigator>
64 #include <KWindowSystem>
65 #include <KXMLGUIFactory>
67 #include <kwidgetsaddons_version.h>
69 #include <QApplication>
71 #include <QCloseEvent>
72 #include <QDesktopServices>
74 #include <QDomDocument>
78 #include <QPushButton>
80 #include <QStandardPaths>
82 #include <QToolButton>
83 #include <QtConcurrentRun>
88 #include <KStartupInfo>
93 // Used for GeneralSettings::version() to determine whether
94 // an updated version of Dolphin is running, so as to migrate
95 // removed/renamed ...etc config entries; increment it in such
97 const int CurrentDolphinVersion
= 202;
98 // The maximum number of entries in the back/forward popup menu
99 const int MaxNumberOfNavigationentries
= 12;
100 // The maximum number of "Go to Tab" shortcuts
101 const int MaxActivateTabShortcuts
= 9;
104 DolphinMainWindow::DolphinMainWindow()
105 : KXmlGuiWindow(nullptr)
106 , m_newFileMenu(nullptr)
107 , m_tabWidget(nullptr)
108 , m_activeViewContainer(nullptr)
109 , m_actionHandler(nullptr)
110 , m_remoteEncoding(nullptr)
112 , m_bookmarkHandler(nullptr)
113 , m_lastHandleUrlOpenJob(nullptr)
114 , m_terminalPanel(nullptr)
115 , m_placesPanel(nullptr)
116 , m_tearDownFromPlacesRequested(false)
117 , m_backAction(nullptr)
118 , m_forwardAction(nullptr)
119 , m_splitViewAction(nullptr)
120 , m_splitViewMenuAction(nullptr)
121 , m_sessionSaveTimer(nullptr)
122 , m_sessionSaveWatcher(nullptr)
123 , m_sessionSaveScheduled(false)
125 Q_INIT_RESOURCE(dolphin
);
127 new MainWindowAdaptor(this);
130 setWindowFlags(Qt::WindowContextHelpButtonHint
);
132 setComponentName(QStringLiteral("dolphin"), QGuiApplication::applicationDisplayName());
133 setObjectName(QStringLiteral("Dolphin#"));
135 setStateConfigGroup("State");
137 new KColorSchemeManager(this);
139 connect(&DolphinNewFileMenuObserver::instance(), &DolphinNewFileMenuObserver::errorMessage
, this, &DolphinMainWindow::showErrorMessage
);
141 KIO::FileUndoManager
*undoManager
= KIO::FileUndoManager::self();
142 undoManager
->setUiInterface(new UndoUiInterface());
144 connect(undoManager
, &KIO::FileUndoManager::undoAvailable
, this, &DolphinMainWindow::slotUndoAvailable
);
145 connect(undoManager
, &KIO::FileUndoManager::undoTextChanged
, this, &DolphinMainWindow::slotUndoTextChanged
);
146 connect(undoManager
, &KIO::FileUndoManager::jobRecordingStarted
, this, &DolphinMainWindow::clearStatusBar
);
147 connect(undoManager
, &KIO::FileUndoManager::jobRecordingFinished
, this, &DolphinMainWindow::showCommand
);
149 const bool firstRun
= (GeneralSettings::version() < 200);
151 GeneralSettings::setViewPropsTimestamp(QDateTime::currentDateTime());
154 setAcceptDrops(true);
156 auto *navigatorsWidgetAction
= new DolphinNavigatorsWidgetAction(this);
157 actionCollection()->addAction(QStringLiteral("url_navigators"), navigatorsWidgetAction
);
158 m_tabWidget
= new DolphinTabWidget(navigatorsWidgetAction
, this);
159 m_tabWidget
->setObjectName("tabWidget");
160 connect(m_tabWidget
, &DolphinTabWidget::activeViewChanged
, this, &DolphinMainWindow::activeViewChanged
);
161 connect(m_tabWidget
, &DolphinTabWidget::tabCountChanged
, this, &DolphinMainWindow::tabCountChanged
);
162 connect(m_tabWidget
, &DolphinTabWidget::currentUrlChanged
, this, &DolphinMainWindow::updateWindowTitle
);
163 setCentralWidget(m_tabWidget
);
165 m_actionTextHelper
= new SelectionMode::ActionTextHelper(this);
168 m_actionHandler
= new DolphinViewActionHandler(actionCollection(), m_actionTextHelper
, this);
169 connect(m_actionHandler
, &DolphinViewActionHandler::actionBeingHandled
, this, &DolphinMainWindow::clearStatusBar
);
170 connect(m_actionHandler
, &DolphinViewActionHandler::createDirectoryTriggered
, this, &DolphinMainWindow::createDirectory
);
171 connect(m_actionHandler
, &DolphinViewActionHandler::selectionModeChangeTriggered
, this, &DolphinMainWindow::slotSetSelectionMode
);
173 Q_CHECK_PTR(actionCollection()->action(QStringLiteral("create_dir")));
174 m_newFileMenu
->setNewFolderShortcutAction(actionCollection()->action(QStringLiteral("create_dir")));
176 m_remoteEncoding
= new DolphinRemoteEncoding(this, m_actionHandler
);
177 connect(this, &DolphinMainWindow::urlChanged
, m_remoteEncoding
, &DolphinRemoteEncoding::slotAboutToOpenUrl
);
181 setupGUI(Save
| Create
| ToolBar
);
182 stateChanged(QStringLiteral("new_file"));
184 QClipboard
*clipboard
= QApplication::clipboard();
185 connect(clipboard
, &QClipboard::dataChanged
, this, &DolphinMainWindow::updatePasteAction
);
187 QAction
*toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
188 toggleFilterBarAction
->setChecked(GeneralSettings::filterBar());
191 menuBar()->setVisible(false);
194 const bool showMenu
= !menuBar()->isHidden();
195 QAction
*showMenuBarAction
= actionCollection()->action(KStandardAction::name(KStandardAction::ShowMenubar
));
196 showMenuBarAction
->setChecked(showMenu
); // workaround for bug #171080
198 auto hamburgerMenu
= static_cast<KHamburgerMenu
*>(actionCollection()->action(KStandardAction::name(KStandardAction::HamburgerMenu
)));
199 hamburgerMenu
->setMenuBar(menuBar());
200 hamburgerMenu
->setShowMenuBarAction(showMenuBarAction
);
201 connect(hamburgerMenu
, &KHamburgerMenu::aboutToShowMenu
, this, &DolphinMainWindow::updateHamburgerMenu
);
202 hamburgerMenu
->hideActionsOf(toolBar());
203 if (GeneralSettings::version() < 201 && !toolBar()->actions().contains(hamburgerMenu
)) {
204 addHamburgerMenuToToolbar();
207 updateAllowedToolbarAreas();
209 // enable middle-click on back/forward/up to open in a new tab
210 auto *middleClickEventFilter
= new MiddleClickActionEventFilter(this);
211 connect(middleClickEventFilter
, &MiddleClickActionEventFilter::actionMiddleClicked
, this, &DolphinMainWindow::slotToolBarActionMiddleClicked
);
212 toolBar()->installEventFilter(middleClickEventFilter
);
216 connect(KSycoca::self(), &KSycoca::databaseChanged
, this, &DolphinMainWindow::updateOpenPreferredSearchToolAction
);
218 QTimer::singleShot(0, this, &DolphinMainWindow::updateOpenPreferredSearchToolAction
);
220 m_fileItemActions
.setParentWidget(this);
221 connect(&m_fileItemActions
, &KFileItemActions::error
, this, [this](const QString
&errorMessage
) {
222 showErrorMessage(errorMessage
);
225 connect(GeneralSettings::self(), &GeneralSettings::splitViewChanged
, this, &DolphinMainWindow::slotSplitViewChanged
);
228 DolphinMainWindow::~DolphinMainWindow()
230 // This fixes a crash on Wayland when closing the mainwindow while another dialog is open.
231 disconnect(QGuiApplication::clipboard(), &QClipboard::dataChanged
, this, &DolphinMainWindow::updatePasteAction
);
234 QVector
<DolphinViewContainer
*> DolphinMainWindow::viewContainers() const
236 QVector
<DolphinViewContainer
*> viewContainers
;
238 for (int i
= 0; i
< m_tabWidget
->count(); ++i
) {
239 DolphinTabPage
*tabPage
= m_tabWidget
->tabPageAt(i
);
241 viewContainers
<< tabPage
->primaryViewContainer();
242 if (tabPage
->splitViewEnabled()) {
243 viewContainers
<< tabPage
->secondaryViewContainer();
246 return viewContainers
;
249 void DolphinMainWindow::openDirectories(const QList
<QUrl
> &dirs
, bool splitView
)
251 m_tabWidget
->openDirectories(dirs
, splitView
);
254 void DolphinMainWindow::openDirectories(const QStringList
&dirs
, bool splitView
)
256 openDirectories(QUrl::fromStringList(dirs
), splitView
);
259 void DolphinMainWindow::openFiles(const QList
<QUrl
> &files
, bool splitView
)
261 m_tabWidget
->openFiles(files
, splitView
);
264 bool DolphinMainWindow::isFoldersPanelEnabled() const
266 return actionCollection()->action(QStringLiteral("show_folders_panel"))->isChecked();
269 bool DolphinMainWindow::isInformationPanelEnabled() const
272 return actionCollection()->action(QStringLiteral("show_information_panel"))->isChecked();
278 bool DolphinMainWindow::isSplitViewEnabledInCurrentTab() const
280 return m_tabWidget
->currentTabPage()->splitViewEnabled();
283 void DolphinMainWindow::openFiles(const QStringList
&files
, bool splitView
)
285 openFiles(QUrl::fromStringList(files
), splitView
);
288 void DolphinMainWindow::activateWindow(const QString
&activationToken
)
290 window()->setAttribute(Qt::WA_NativeWindow
, true);
292 if (KWindowSystem::isPlatformWayland()) {
293 KWindowSystem::setCurrentXdgActivationToken(activationToken
);
294 } else if (KWindowSystem::isPlatformX11()) {
296 KStartupInfo::setNewStartupId(window()->windowHandle(), activationToken
.toUtf8());
300 KWindowSystem::activateWindow(window()->windowHandle());
303 bool DolphinMainWindow::isActiveWindow()
305 return window()->isActiveWindow();
308 void DolphinMainWindow::showCommand(CommandType command
)
310 DolphinStatusBar
*statusBar
= m_activeViewContainer
->statusBar();
312 case KIO::FileUndoManager::Copy
:
313 statusBar
->setText(i18nc("@info:status", "Successfully copied."));
315 case KIO::FileUndoManager::Move
:
316 statusBar
->setText(i18nc("@info:status", "Successfully moved."));
318 case KIO::FileUndoManager::Link
:
319 statusBar
->setText(i18nc("@info:status", "Successfully linked."));
321 case KIO::FileUndoManager::Trash
:
322 statusBar
->setText(i18nc("@info:status", "Successfully moved to trash."));
324 case KIO::FileUndoManager::Rename
:
325 statusBar
->setText(i18nc("@info:status", "Successfully renamed."));
328 case KIO::FileUndoManager::Mkdir
:
329 statusBar
->setText(i18nc("@info:status", "Created folder."));
337 void DolphinMainWindow::pasteIntoFolder()
339 m_activeViewContainer
->view()->pasteIntoFolder();
342 void DolphinMainWindow::changeUrl(const QUrl
&url
)
344 if (!KProtocolManager::supportsListing(url
)) {
345 // The URL navigator only checks for validity, not
346 // if the URL can be listed. An error message is
347 // shown due to DolphinViewContainer::restoreView().
351 m_activeViewContainer
->setUrl(url
);
352 updateFileAndEditActions();
357 Q_EMIT
urlChanged(url
);
360 void DolphinMainWindow::slotTerminalDirectoryChanged(const QUrl
&url
)
362 if (m_tearDownFromPlacesRequested
&& url
== QUrl::fromLocalFile(QDir::homePath())) {
363 m_placesPanel
->proceedWithTearDown();
364 m_tearDownFromPlacesRequested
= false;
367 m_activeViewContainer
->setAutoGrabFocus(false);
369 m_activeViewContainer
->setAutoGrabFocus(true);
372 void DolphinMainWindow::slotEditableStateChanged(bool editable
)
374 KToggleAction
*editableLocationAction
= static_cast<KToggleAction
*>(actionCollection()->action(QStringLiteral("editable_location")));
375 editableLocationAction
->setChecked(editable
);
378 void DolphinMainWindow::slotSelectionChanged(const KFileItemList
&selection
)
380 updateFileAndEditActions();
382 const int selectedUrlsCount
= m_tabWidget
->currentTabPage()->selectedItemsCount();
384 QAction
*compareFilesAction
= actionCollection()->action(QStringLiteral("compare_files"));
385 if (selectedUrlsCount
== 2) {
386 compareFilesAction
->setEnabled(isKompareInstalled());
388 compareFilesAction
->setEnabled(false);
391 Q_EMIT
selectionChanged(selection
);
394 void DolphinMainWindow::updateHistory()
396 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
397 const int index
= urlNavigator
->historyIndex();
399 QAction
*backAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Back
));
401 backAction
->setToolTip(i18nc("@info", "Go back"));
402 backAction
->setWhatsThis(i18nc("@info:whatsthis go back", "Return to the previously viewed folder."));
403 backAction
->setEnabled(index
< urlNavigator
->historySize() - 1);
406 QAction
*forwardAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Forward
));
408 forwardAction
->setToolTip(i18nc("@info", "Go forward"));
409 forwardAction
->setWhatsThis(xi18nc("@info:whatsthis go forward", "This undoes a <interface>Go|Back</interface> action."));
410 forwardAction
->setEnabled(index
> 0);
414 void DolphinMainWindow::updateFilterBarAction(bool show
)
416 QAction
*toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
417 toggleFilterBarAction
->setChecked(show
);
420 void DolphinMainWindow::openNewMainWindow()
422 Dolphin::openNewWindow({m_activeViewContainer
->url()}, this);
425 void DolphinMainWindow::openNewActivatedTab()
427 // keep browsers compatibility, new tab is always after last one
428 auto openNewTabAfterLastTabConfigured
= GeneralSettings::openNewTabAfterLastTab();
429 GeneralSettings::setOpenNewTabAfterLastTab(true);
430 m_tabWidget
->openNewActivatedTab();
431 GeneralSettings::setOpenNewTabAfterLastTab(openNewTabAfterLastTabConfigured
);
434 void DolphinMainWindow::addToPlaces()
439 // If nothing is selected, act on the current dir
440 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
441 url
= m_activeViewContainer
->url();
442 name
= m_activeViewContainer
->placesText();
444 const auto dirToAdd
= m_activeViewContainer
->view()->selectedItems().first();
445 url
= dirToAdd
.url();
446 name
= dirToAdd
.name();
450 if (m_activeViewContainer
->isSearchModeEnabled()) {
451 icon
= QStringLiteral("folder-saved-search-symbolic");
453 icon
= KIO::iconNameForUrl(url
);
455 DolphinPlacesModelSingleton::instance().placesModel()->addPlace(name
, url
, icon
);
459 void DolphinMainWindow::openNewTab(const QUrl
&url
)
461 m_tabWidget
->openNewTab(url
, QUrl());
464 void DolphinMainWindow::openNewTabAndActivate(const QUrl
&url
)
466 m_tabWidget
->openNewActivatedTab(url
, QUrl());
469 void DolphinMainWindow::openNewWindow(const QUrl
&url
)
471 Dolphin::openNewWindow({url
}, this);
474 void DolphinMainWindow::slotSplitViewChanged()
476 m_tabWidget
->currentTabPage()->setSplitViewEnabled(GeneralSettings::splitView(), WithAnimation
);
477 updateSplitActions();
480 void DolphinMainWindow::openInNewTab()
482 const KFileItemList
&list
= m_activeViewContainer
->view()->selectedItems();
483 bool tabCreated
= false;
485 for (const KFileItem
&item
: list
) {
486 const QUrl
&url
= DolphinView::openItemAsFolderUrl(item
);
487 if (!url
.isEmpty()) {
493 // if no new tab has been created from the selection
494 // open the current directory in a new tab
496 openNewTab(m_activeViewContainer
->url());
500 void DolphinMainWindow::openInNewWindow()
504 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
505 if (list
.isEmpty()) {
506 newWindowUrl
= m_activeViewContainer
->url();
507 } else if (list
.count() == 1) {
508 const KFileItem
&item
= list
.first();
509 newWindowUrl
= DolphinView::openItemAsFolderUrl(item
);
512 if (!newWindowUrl
.isEmpty()) {
513 Dolphin::openNewWindow({newWindowUrl
}, this);
517 void DolphinMainWindow::openInSplitView(const QUrl
&url
)
519 QUrl newSplitViewUrl
= url
;
521 if (newSplitViewUrl
.isEmpty()) {
522 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
523 if (list
.count() == 1) {
524 const KFileItem
&item
= list
.first();
525 newSplitViewUrl
= DolphinView::openItemAsFolderUrl(item
);
529 if (newSplitViewUrl
.isEmpty()) {
533 DolphinTabPage
*tabPage
= m_tabWidget
->currentTabPage();
534 if (tabPage
->splitViewEnabled()) {
535 tabPage
->switchActiveView();
536 tabPage
->activeViewContainer()->setUrl(newSplitViewUrl
);
538 tabPage
->setSplitViewEnabled(true, WithAnimation
, newSplitViewUrl
);
543 void DolphinMainWindow::showTarget()
545 const KFileItem link
= m_activeViewContainer
->view()->selectedItems().at(0);
546 const QUrl destinationUrl
= link
.url().resolved(QUrl(link
.linkDest()));
548 auto job
= KIO::stat(destinationUrl
, KIO::StatJob::SourceSide
, KIO::StatNoDetails
);
550 connect(job
, &KJob::finished
, this, [this, destinationUrl
](KJob
*job
) {
551 KIO::StatJob
*statJob
= static_cast<KIO::StatJob
*>(job
);
553 if (statJob
->error()) {
554 m_activeViewContainer
->showMessage(job
->errorString(), DolphinViewContainer::Error
);
556 KIO::highlightInFileManager({destinationUrl
});
561 bool DolphinMainWindow::event(QEvent
*event
)
563 if (event
->type() == QEvent::ShortcutOverride
) {
564 const QKeyEvent
*keyEvent
= static_cast<QKeyEvent
*>(event
);
565 if (keyEvent
->key() == Qt::Key_Space
&& m_activeViewContainer
->view()->handleSpaceAsNormalKey()) {
571 return KXmlGuiWindow::event(event
);
574 void DolphinMainWindow::showEvent(QShowEvent
*event
)
576 KXmlGuiWindow::showEvent(event
);
578 if (!event
->spontaneous()) {
579 m_activeViewContainer
->view()->setFocus();
583 void DolphinMainWindow::closeEvent(QCloseEvent
*event
)
585 // Find out if Dolphin is closed directly by the user or
586 // by the session manager because the session is closed
587 bool closedByUser
= true;
588 if (qApp
->isSavingSession()) {
589 closedByUser
= false;
592 if (m_tabWidget
->count() > 1 && GeneralSettings::confirmClosingMultipleTabs() && !GeneralSettings::rememberOpenedTabs() && closedByUser
) {
593 // Ask the user if he really wants to quit and close all tabs.
594 // Open a confirmation dialog with 3 buttons:
595 // QDialogButtonBox::Yes -> Quit
596 // QDialogButtonBox::No -> Close only the current tab
597 // QDialogButtonBox::Cancel -> do nothing
598 QDialog
*dialog
= new QDialog(this, Qt::Dialog
);
599 dialog
->setWindowTitle(i18nc("@title:window", "Confirmation"));
600 dialog
->setModal(true);
601 QDialogButtonBox
*buttons
= new QDialogButtonBox(QDialogButtonBox::Yes
| QDialogButtonBox::No
| QDialogButtonBox::Cancel
);
602 KGuiItem::assign(buttons
->button(QDialogButtonBox::Yes
),
603 KGuiItem(i18nc("@action:button 'Quit Dolphin' button", "&Quit %1", QGuiApplication::applicationDisplayName()),
604 QIcon::fromTheme(QStringLiteral("application-exit"))));
605 KGuiItem::assign(buttons
->button(QDialogButtonBox::No
), KGuiItem(i18n("C&lose Current Tab"), QIcon::fromTheme(QStringLiteral("tab-close"))));
606 KGuiItem::assign(buttons
->button(QDialogButtonBox::Cancel
), KStandardGuiItem::cancel());
607 buttons
->button(QDialogButtonBox::Yes
)->setDefault(true);
609 bool doNotAskAgainCheckboxResult
= false;
611 const auto result
= KMessageBox::createKMessageBox(dialog
,
613 QMessageBox::Warning
,
614 i18n("You have multiple tabs open in this window, are you sure you want to quit?"),
616 i18n("Do not ask again"),
617 &doNotAskAgainCheckboxResult
,
618 KMessageBox::Notify
);
620 if (doNotAskAgainCheckboxResult
) {
621 GeneralSettings::setConfirmClosingMultipleTabs(false);
625 case QDialogButtonBox::Yes
:
628 case QDialogButtonBox::No
:
629 // Close only the current tab
630 m_tabWidget
->closeTab();
638 if (m_terminalPanel
&& m_terminalPanel
->hasProgramRunning() && GeneralSettings::confirmClosingTerminalRunningProgram() && closedByUser
) {
639 // Ask if the user really wants to quit Dolphin with a program that is still running in the Terminal panel
640 // Open a confirmation dialog with 3 buttons:
641 // QDialogButtonBox::Yes -> Quit
642 // QDialogButtonBox::No -> Show Terminal Panel
643 // QDialogButtonBox::Cancel -> do nothing
644 QDialog
*dialog
= new QDialog(this, Qt::Dialog
);
645 dialog
->setWindowTitle(i18nc("@title:window", "Confirmation"));
646 dialog
->setModal(true);
647 auto standardButtons
= QDialogButtonBox::Yes
| QDialogButtonBox::Cancel
;
648 if (!m_terminalPanel
->isVisible()) {
649 standardButtons
|= QDialogButtonBox::No
;
651 QDialogButtonBox
*buttons
= new QDialogButtonBox(standardButtons
);
652 KGuiItem::assign(buttons
->button(QDialogButtonBox::Yes
), KStandardGuiItem::quit());
653 if (!m_terminalPanel
->isVisible()) {
654 KGuiItem::assign(buttons
->button(QDialogButtonBox::No
), KGuiItem(i18n("Show &Terminal Panel"), QIcon::fromTheme(QStringLiteral("dialog-scripts"))));
656 KGuiItem::assign(buttons
->button(QDialogButtonBox::Cancel
), KStandardGuiItem::cancel());
658 bool doNotAskAgainCheckboxResult
= false;
660 const auto result
= KMessageBox::createKMessageBox(
663 QMessageBox::Warning
,
664 i18n("The program '%1' is still running in the Terminal panel. Are you sure you want to quit?", m_terminalPanel
->runningProgramName()),
666 i18n("Do not ask again"),
667 &doNotAskAgainCheckboxResult
,
668 KMessageBox::Notify
| KMessageBox::Dangerous
);
670 if (doNotAskAgainCheckboxResult
) {
671 GeneralSettings::setConfirmClosingTerminalRunningProgram(false);
675 case QDialogButtonBox::Yes
:
678 case QDialogButtonBox::No
:
679 actionCollection()->action("show_terminal_panel")->trigger();
680 // Do not quit, ignore quit event
688 if (m_sessionSaveTimer
&& (m_sessionSaveTimer
->isActive() || m_sessionSaveWatcher
->isRunning())) {
689 const bool sessionSaveTimerActive
= m_sessionSaveTimer
->isActive();
691 m_sessionSaveTimer
->stop();
692 m_sessionSaveWatcher
->disconnect();
693 m_sessionSaveWatcher
->waitForFinished();
695 if (sessionSaveTimerActive
|| m_sessionSaveScheduled
) {
700 GeneralSettings::setVersion(CurrentDolphinVersion
);
701 GeneralSettings::self()->save();
703 KXmlGuiWindow::closeEvent(event
);
706 void DolphinMainWindow::slotSaveSession()
708 m_sessionSaveScheduled
= false;
710 if (m_sessionSaveWatcher
->isRunning()) {
711 // The previous session is still being saved - schedule another save.
712 m_sessionSaveWatcher
->disconnect();
713 connect(m_sessionSaveWatcher
, &QFutureWatcher
<void>::finished
, this, &DolphinMainWindow::slotSaveSession
, Qt::SingleShotConnection
);
714 m_sessionSaveScheduled
= true;
715 } else if (!m_sessionSaveTimer
->isActive()) {
716 // No point in saving the session if the timer is running (since it will save the session again when it times out).
717 KConfigGui::setSessionConfig(QStringLiteral("dolphin"), QStringLiteral("dolphin"));
718 KConfig
*config
= KConfigGui::sessionConfig();
719 saveGlobalProperties(config
);
720 savePropertiesInternal(config
, 1);
722 auto future
= QtConcurrent::run([config
]() {
725 m_sessionSaveWatcher
->setFuture(future
);
729 void DolphinMainWindow::setSessionAutoSaveEnabled(bool enable
)
732 if (!m_sessionSaveTimer
) {
733 m_sessionSaveTimer
= new QTimer(this);
734 m_sessionSaveWatcher
= new QFutureWatcher
<void>(this);
735 m_sessionSaveTimer
->setSingleShot(true);
736 m_sessionSaveTimer
->setInterval(22000);
738 connect(m_sessionSaveTimer
, &QTimer::timeout
, this, &DolphinMainWindow::slotSaveSession
);
741 connect(m_tabWidget
, &DolphinTabWidget::urlChanged
, m_sessionSaveTimer
, qOverload
<>(&QTimer::start
), Qt::UniqueConnection
);
742 connect(m_tabWidget
, &DolphinTabWidget::tabCountChanged
, m_sessionSaveTimer
, qOverload
<>(&QTimer::start
), Qt::UniqueConnection
);
743 connect(m_tabWidget
, &DolphinTabWidget::activeViewChanged
, m_sessionSaveTimer
, qOverload
<>(&QTimer::start
), Qt::UniqueConnection
);
744 } else if (m_sessionSaveTimer
) {
745 m_sessionSaveTimer
->stop();
746 m_sessionSaveWatcher
->disconnect();
747 m_sessionSaveScheduled
= false;
749 m_sessionSaveWatcher
->waitForFinished();
751 m_sessionSaveTimer
->deleteLater();
752 m_sessionSaveWatcher
->deleteLater();
753 m_sessionSaveTimer
= nullptr;
754 m_sessionSaveWatcher
= nullptr;
758 void DolphinMainWindow::saveProperties(KConfigGroup
&group
)
760 m_tabWidget
->saveProperties(group
);
763 void DolphinMainWindow::readProperties(const KConfigGroup
&group
)
765 m_tabWidget
->readProperties(group
);
768 void DolphinMainWindow::updateNewMenu()
770 m_newFileMenu
->checkUpToDate();
771 m_newFileMenu
->setWorkingDirectory(activeViewContainer()->url());
774 void DolphinMainWindow::createDirectory()
776 m_newFileMenu
->setWorkingDirectory(activeViewContainer()->url());
777 m_newFileMenu
->createDirectory();
780 void DolphinMainWindow::quit()
785 void DolphinMainWindow::showErrorMessage(const QString
&message
)
787 m_activeViewContainer
->showMessage(message
, DolphinViewContainer::Error
);
790 void DolphinMainWindow::slotUndoAvailable(bool available
)
792 QAction
*undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
794 undoAction
->setEnabled(available
);
798 void DolphinMainWindow::slotUndoTextChanged(const QString
&text
)
800 QAction
*undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
802 undoAction
->setText(text
);
806 void DolphinMainWindow::undo()
809 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
810 KIO::FileUndoManager::self()->undo();
813 void DolphinMainWindow::cut()
815 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
816 m_activeViewContainer
->setSelectionModeEnabled(true, actionCollection(), SelectionMode::BottomBar::Contents::CutContents
);
818 m_activeViewContainer
->view()->cutSelectedItemsToClipboard();
819 m_activeViewContainer
->setSelectionModeEnabled(false);
823 void DolphinMainWindow::copy()
825 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
826 m_activeViewContainer
->setSelectionModeEnabled(true, actionCollection(), SelectionMode::BottomBar::Contents::CopyContents
);
828 m_activeViewContainer
->view()->copySelectedItemsToClipboard();
829 m_activeViewContainer
->setSelectionModeEnabled(false);
833 void DolphinMainWindow::paste()
835 m_activeViewContainer
->view()->paste();
838 void DolphinMainWindow::find()
840 m_activeViewContainer
->setSearchModeEnabled(true);
843 void DolphinMainWindow::updateSearchAction()
845 QAction
*toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
846 toggleSearchAction
->setChecked(m_activeViewContainer
->isSearchModeEnabled());
849 void DolphinMainWindow::updatePasteAction()
851 QAction
*pasteAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Paste
));
852 QPair
<bool, QString
> pasteInfo
= m_activeViewContainer
->view()->pasteInfo();
853 pasteAction
->setEnabled(pasteInfo
.first
);
854 pasteAction
->setText(pasteInfo
.second
);
857 void DolphinMainWindow::slotDirectoryLoadingCompleted()
862 void DolphinMainWindow::slotToolBarActionMiddleClicked(QAction
*action
)
864 if (action
== actionCollection()->action(KStandardAction::name(KStandardAction::Back
))) {
866 } else if (action
== actionCollection()->action(KStandardAction::name(KStandardAction::Forward
))) {
868 } else if (action
== actionCollection()->action(QStringLiteral("go_up"))) {
870 } else if (action
== actionCollection()->action(QStringLiteral("go_home"))) {
875 QAction
*DolphinMainWindow::urlNavigatorHistoryAction(const KUrlNavigator
*urlNavigator
, int historyIndex
, QObject
*parent
)
877 const QUrl url
= urlNavigator
->locationUrl(historyIndex
);
879 QString text
= url
.toDisplayString(QUrl::PreferLocalFile
);
881 if (!urlNavigator
->showFullPath()) {
882 const KFilePlacesModel
*placesModel
= DolphinPlacesModelSingleton::instance().placesModel();
884 const QModelIndex closestIdx
= placesModel
->closestItem(url
);
885 if (closestIdx
.isValid()) {
886 const QUrl placeUrl
= placesModel
->url(closestIdx
);
888 text
= placesModel
->text(closestIdx
);
890 QString pathInsidePlace
= url
.path().mid(placeUrl
.path().length());
892 if (!pathInsidePlace
.isEmpty() && !pathInsidePlace
.startsWith(QLatin1Char('/'))) {
893 pathInsidePlace
.prepend(QLatin1Char('/'));
896 if (pathInsidePlace
!= QLatin1Char('/')) {
897 text
.append(pathInsidePlace
);
902 QAction
*action
= new QAction(QIcon::fromTheme(KIO::iconNameForUrl(url
)), text
, parent
);
903 action
->setData(historyIndex
);
907 void DolphinMainWindow::slotAboutToShowBackPopupMenu()
909 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
911 QMenu
*menu
= m_backAction
->popupMenu();
913 for (int i
= urlNavigator
->historyIndex() + 1; i
< urlNavigator
->historySize() && entries
< MaxNumberOfNavigationentries
; ++i
, ++entries
) {
914 QAction
*action
= urlNavigatorHistoryAction(urlNavigator
, i
, menu
);
915 menu
->addAction(action
);
919 void DolphinMainWindow::slotGoBack(QAction
*action
)
921 int gotoIndex
= action
->data().value
<int>();
922 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
923 for (int i
= gotoIndex
- urlNavigator
->historyIndex(); i
> 0; --i
) {
928 void DolphinMainWindow::slotBackForwardActionMiddleClicked(QAction
*action
)
931 const KUrlNavigator
*urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
932 openNewTab(urlNavigator
->locationUrl(action
->data().value
<int>()));
936 void DolphinMainWindow::slotAboutToShowForwardPopupMenu()
938 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
940 QMenu
*menu
= m_forwardAction
->popupMenu();
941 for (int i
= urlNavigator
->historyIndex() - 1; i
>= 0 && entries
< MaxNumberOfNavigationentries
; --i
, ++entries
) {
942 QAction
*action
= urlNavigatorHistoryAction(urlNavigator
, i
, menu
);
943 menu
->addAction(action
);
947 void DolphinMainWindow::slotGoForward(QAction
*action
)
949 int gotoIndex
= action
->data().value
<int>();
950 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
951 for (int i
= urlNavigator
->historyIndex() - gotoIndex
; i
> 0; --i
) {
956 void DolphinMainWindow::slotSetSelectionMode(bool enabled
, SelectionMode::BottomBar::Contents bottomBarContents
)
958 m_activeViewContainer
->setSelectionModeEnabled(enabled
, actionCollection(), bottomBarContents
);
961 void DolphinMainWindow::selectAll()
965 // if the URL navigator is editable and focused, select the whole
966 // URL instead of all items of the view
968 KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigator();
969 QLineEdit
*lineEdit
= urlNavigator
->editor()->lineEdit();
970 const bool selectUrl
= urlNavigator
->isUrlEditable() && lineEdit
->hasFocus();
972 lineEdit
->selectAll();
974 m_activeViewContainer
->view()->selectAll();
978 void DolphinMainWindow::invertSelection()
981 m_activeViewContainer
->view()->invertSelection();
984 void DolphinMainWindow::toggleSplitView()
986 DolphinTabPage
*tabPage
= m_tabWidget
->currentTabPage();
987 tabPage
->setSplitViewEnabled(!tabPage
->splitViewEnabled(), WithAnimation
);
988 m_tabWidget
->updateTabName(m_tabWidget
->indexOf(tabPage
));
992 void DolphinMainWindow::popoutSplitView()
994 DolphinTabPage
*tabPage
= m_tabWidget
->currentTabPage();
995 if (!tabPage
->splitViewEnabled())
997 openNewWindow((GeneralSettings::closeActiveSplitView() ? tabPage
->activeViewContainer() : tabPage
->inactiveViewContainer())->url());
998 tabPage
->setSplitViewEnabled(false, WithAnimation
);
999 updateSplitActions();
1002 void DolphinMainWindow::toggleSplitStash()
1004 DolphinTabPage
*tabPage
= m_tabWidget
->currentTabPage();
1005 tabPage
->setSplitViewEnabled(false, WithAnimation
);
1006 tabPage
->setSplitViewEnabled(true, WithAnimation
, QUrl("stash:/"));
1009 void DolphinMainWindow::copyToInactiveSplitView()
1011 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
1012 m_activeViewContainer
->setSelectionModeEnabled(true, actionCollection(), SelectionMode::BottomBar::Contents::CopyToOtherViewContents
);
1014 m_tabWidget
->copyToInactiveSplitView();
1015 m_activeViewContainer
->setSelectionModeEnabled(false);
1019 void DolphinMainWindow::moveToInactiveSplitView()
1021 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
1022 m_activeViewContainer
->setSelectionModeEnabled(true, actionCollection(), SelectionMode::BottomBar::Contents::MoveToOtherViewContents
);
1024 m_tabWidget
->moveToInactiveSplitView();
1025 m_activeViewContainer
->setSelectionModeEnabled(false);
1029 void DolphinMainWindow::reloadView()
1032 m_activeViewContainer
->reload();
1033 m_activeViewContainer
->statusBar()->updateSpaceInfo();
1036 void DolphinMainWindow::stopLoading()
1038 m_activeViewContainer
->view()->stopLoading();
1041 void DolphinMainWindow::enableStopAction()
1043 actionCollection()->action(QStringLiteral("stop"))->setEnabled(true);
1046 void DolphinMainWindow::disableStopAction()
1048 actionCollection()->action(QStringLiteral("stop"))->setEnabled(false);
1051 void DolphinMainWindow::toggleSelectionMode()
1053 const bool checked
= !m_activeViewContainer
->isSelectionModeEnabled();
1055 m_activeViewContainer
->setSelectionModeEnabled(checked
, actionCollection(), SelectionMode::BottomBar::Contents::GeneralContents
);
1056 actionCollection()->action(QStringLiteral("toggle_selection_mode"))->setChecked(checked
);
1059 void DolphinMainWindow::showFilterBar()
1061 m_activeViewContainer
->setFilterBarVisible(true);
1064 void DolphinMainWindow::toggleFilterBar()
1066 const bool checked
= !m_activeViewContainer
->isFilterBarVisible();
1067 m_activeViewContainer
->setFilterBarVisible(checked
);
1069 QAction
*toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
1070 toggleFilterBarAction
->setChecked(checked
);
1073 void DolphinMainWindow::toggleEditLocation()
1077 QAction
*action
= actionCollection()->action(QStringLiteral("editable_location"));
1078 KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigator();
1079 urlNavigator
->setUrlEditable(action
->isChecked());
1082 void DolphinMainWindow::replaceLocation()
1084 KUrlNavigator
*navigator
= m_activeViewContainer
->urlNavigator();
1085 QLineEdit
*lineEdit
= navigator
->editor()->lineEdit();
1087 // If the text field currently has focus and everything is selected,
1088 // pressing the keyboard shortcut returns the whole thing to breadcrumb mode
1089 if (navigator
->isUrlEditable() && lineEdit
->hasFocus() && lineEdit
->selectedText() == lineEdit
->text()) {
1090 navigator
->setUrlEditable(false);
1092 navigator
->setUrlEditable(true);
1093 navigator
->setFocus();
1094 lineEdit
->selectAll();
1098 void DolphinMainWindow::togglePanelLockState()
1100 const bool newLockState
= !GeneralSettings::lockPanels();
1101 const auto childrenObjects
= children();
1102 for (QObject
*child
: childrenObjects
) {
1103 DolphinDockWidget
*dock
= qobject_cast
<DolphinDockWidget
*>(child
);
1105 dock
->setLocked(newLockState
);
1109 DolphinPlacesModelSingleton::instance().placesModel()->setPanelsLocked(newLockState
);
1111 GeneralSettings::setLockPanels(newLockState
);
1114 void DolphinMainWindow::slotTerminalPanelVisibilityChanged()
1116 if (m_terminalPanel
->isHiddenInVisibleWindow() && m_activeViewContainer
) {
1117 m_activeViewContainer
->view()->setFocus();
1121 void DolphinMainWindow::goBack()
1123 DolphinUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
1124 urlNavigator
->goBack();
1126 if (urlNavigator
->locationState().isEmpty()) {
1127 // An empty location state indicates a redirection URL,
1128 // which must be skipped too
1129 urlNavigator
->goBack();
1133 void DolphinMainWindow::goForward()
1135 m_activeViewContainer
->urlNavigatorInternalWithHistory()->goForward();
1138 void DolphinMainWindow::goUp()
1140 m_activeViewContainer
->urlNavigatorInternalWithHistory()->goUp();
1143 void DolphinMainWindow::goHome()
1145 m_activeViewContainer
->urlNavigatorInternalWithHistory()->goHome();
1148 void DolphinMainWindow::goBackInNewTab()
1150 const KUrlNavigator
*urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
1151 const int index
= urlNavigator
->historyIndex() + 1;
1152 openNewTab(urlNavigator
->locationUrl(index
));
1155 void DolphinMainWindow::goForwardInNewTab()
1157 const KUrlNavigator
*urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
1158 const int index
= urlNavigator
->historyIndex() - 1;
1159 openNewTab(urlNavigator
->locationUrl(index
));
1162 void DolphinMainWindow::goUpInNewTab()
1164 const QUrl currentUrl
= activeViewContainer()->urlNavigator()->locationUrl();
1165 openNewTab(KIO::upUrl(currentUrl
));
1168 void DolphinMainWindow::goHomeInNewTab()
1170 openNewTab(Dolphin::homeUrl());
1173 void DolphinMainWindow::compareFiles()
1175 const KFileItemList items
= m_tabWidget
->currentTabPage()->selectedItems();
1176 if (items
.count() != 2) {
1177 // The action is disabled in this case, but it could have been triggered
1178 // via D-Bus, see https://bugs.kde.org/show_bug.cgi?id=325517
1182 QUrl urlA
= items
.at(0).url();
1183 QUrl urlB
= items
.at(1).url();
1185 QString
command(QStringLiteral("kompare -c \""));
1186 command
.append(urlA
.toDisplayString(QUrl::PreferLocalFile
));
1187 command
.append("\" \"");
1188 command
.append(urlB
.toDisplayString(QUrl::PreferLocalFile
));
1189 command
.append('\"');
1191 KIO::CommandLauncherJob
*job
= new KIO::CommandLauncherJob(command
, this);
1192 job
->setDesktopName(QStringLiteral("org.kde.kompare"));
1196 void DolphinMainWindow::toggleShowMenuBar()
1198 const bool visible
= menuBar()->isVisible();
1199 menuBar()->setVisible(!visible
);
1202 QPointer
<QAction
> DolphinMainWindow::preferredSearchTool()
1204 m_searchTools
.clear();
1206 KService::Ptr kfind
= KService::serviceByDesktopName(QStringLiteral("org.kde.kfind"));
1212 auto *action
= new QAction(QIcon::fromTheme(kfind
->icon()), kfind
->name(), this);
1214 connect(action
, &QAction::triggered
, this, [this, kfind
] {
1215 auto *job
= new KIO::ApplicationLauncherJob(kfind
);
1216 job
->setUrls({m_activeViewContainer
->url()});
1223 void DolphinMainWindow::updateOpenPreferredSearchToolAction()
1225 QAction
*openPreferredSearchTool
= actionCollection()->action(QStringLiteral("open_preferred_search_tool"));
1226 if (!openPreferredSearchTool
) {
1229 QPointer
<QAction
> tool
= preferredSearchTool();
1231 openPreferredSearchTool
->setVisible(true);
1232 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open %1", tool
->text()));
1233 // Only override with the app icon if it is the default, i.e. the user hasn't configured one manually
1234 // https://bugs.kde.org/show_bug.cgi?id=442815
1235 if (openPreferredSearchTool
->icon().name() == QLatin1String("search")) {
1236 openPreferredSearchTool
->setIcon(tool
->icon());
1239 openPreferredSearchTool
->setVisible(false);
1240 // still visible in Shortcuts configuration window
1241 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool"));
1242 openPreferredSearchTool
->setIcon(QIcon::fromTheme(QStringLiteral("search")));
1246 void DolphinMainWindow::openPreferredSearchTool()
1248 QPointer
<QAction
> tool
= preferredSearchTool();
1254 void DolphinMainWindow::openTerminal()
1256 openTerminalJob(m_activeViewContainer
->url());
1259 void DolphinMainWindow::openTerminalHere()
1261 QList
<QUrl
> urls
= {};
1263 const auto selectedItems
= m_activeViewContainer
->view()->selectedItems();
1264 for (const KFileItem
&item
: selectedItems
) {
1265 QUrl url
= item
.targetUrl();
1266 if (item
.isFile()) {
1267 url
.setPath(QFileInfo(url
.path()).absolutePath());
1269 if (!urls
.contains(url
)) {
1274 // No items are selected. Open a terminal window for the current location.
1275 if (urls
.count() == 0) {
1280 if (urls
.count() > 5) {
1281 QString question
= i18np("Are you sure you want to open 1 terminal window?", "Are you sure you want to open %1 terminal windows?", urls
.count());
1282 const int answer
= KMessageBox::warningContinueCancel(
1286 KGuiItem(i18ncp("@action:button", "Open %1 Terminal", "Open %1 Terminals", urls
.count()), QStringLiteral("utilities-terminal")),
1287 KStandardGuiItem::cancel(),
1288 QStringLiteral("ConfirmOpenManyTerminals"));
1289 if (answer
!= KMessageBox::PrimaryAction
&& answer
!= KMessageBox::Continue
) {
1294 for (const QUrl
&url
: std::as_const(urls
)) {
1295 openTerminalJob(url
);
1299 void DolphinMainWindow::openTerminalJob(const QUrl
&url
)
1301 if (url
.isLocalFile()) {
1302 auto job
= new KTerminalLauncherJob(QString());
1303 job
->setWorkingDirectory(url
.toLocalFile());
1308 // Not a local file, with protocol Class ":local", try stat'ing
1309 if (KProtocolInfo::protocolClass(url
.scheme()) == QLatin1String(":local")) {
1310 KIO::StatJob
*job
= KIO::mostLocalUrl(url
);
1311 KJobWidgets::setWindow(job
, this);
1312 connect(job
, &KJob::result
, this, [job
]() {
1314 if (!job
->error()) {
1315 statUrl
= job
->mostLocalUrl();
1318 auto job
= new KTerminalLauncherJob(QString());
1319 job
->setWorkingDirectory(statUrl
.isLocalFile() ? statUrl
.toLocalFile() : QDir::homePath());
1326 // Nothing worked, just use $HOME
1327 auto job
= new KTerminalLauncherJob(QString());
1328 job
->setWorkingDirectory(QDir::homePath());
1332 void DolphinMainWindow::editSettings()
1334 if (!m_settingsDialog
) {
1335 DolphinViewContainer
*container
= activeViewContainer();
1336 container
->view()->writeSettings();
1338 const QUrl url
= container
->url();
1339 DolphinSettingsDialog
*settingsDialog
= new DolphinSettingsDialog(url
, this, actionCollection());
1340 connect(settingsDialog
, &DolphinSettingsDialog::settingsChanged
, this, &DolphinMainWindow::refreshViews
);
1341 connect(settingsDialog
, &DolphinSettingsDialog::settingsChanged
, &DolphinUrlNavigatorsController::slotReadSettings
);
1342 settingsDialog
->setAttribute(Qt::WA_DeleteOnClose
);
1343 settingsDialog
->show();
1344 m_settingsDialog
= settingsDialog
;
1346 m_settingsDialog
.data()->raise();
1350 void DolphinMainWindow::handleUrl(const QUrl
&url
)
1352 delete m_lastHandleUrlOpenJob
;
1353 m_lastHandleUrlOpenJob
= nullptr;
1355 if (url
.isLocalFile() && QFileInfo(url
.toLocalFile()).isDir()) {
1356 activeViewContainer()->setUrl(url
);
1358 m_lastHandleUrlOpenJob
= new KIO::OpenUrlJob(url
);
1359 m_lastHandleUrlOpenJob
->setUiDelegate(KIO::createDefaultJobUiDelegate(KJobUiDelegate::AutoHandlingEnabled
, this));
1360 m_lastHandleUrlOpenJob
->setShowOpenOrExecuteDialog(true);
1362 connect(m_lastHandleUrlOpenJob
, &KIO::OpenUrlJob::mimeTypeFound
, this, [this, url
](const QString
&mimetype
) {
1363 if (mimetype
== QLatin1String("inode/directory")) {
1364 // If it's a dir, we'll take it from here
1365 m_lastHandleUrlOpenJob
->kill();
1366 m_lastHandleUrlOpenJob
= nullptr;
1367 activeViewContainer()->setUrl(url
);
1371 connect(m_lastHandleUrlOpenJob
, &KIO::OpenUrlJob::result
, this, [this]() {
1372 m_lastHandleUrlOpenJob
= nullptr;
1375 m_lastHandleUrlOpenJob
->start();
1379 void DolphinMainWindow::slotWriteStateChanged(bool isFolderWritable
)
1381 // trash:/ is writable but we don't want to create new items in it.
1382 // TODO: remove the trash check once https://phabricator.kde.org/T8234 is implemented
1383 newFileMenu()->setEnabled(isFolderWritable
&& m_activeViewContainer
->url().scheme() != QLatin1String("trash"));
1386 void DolphinMainWindow::openContextMenu(const QPoint
&pos
, const KFileItem
&item
, const KFileItemList
&selectedItems
, const QUrl
&url
)
1388 QPointer
<DolphinContextMenu
> contextMenu
= new DolphinContextMenu(this, item
, selectedItems
, url
, &m_fileItemActions
);
1389 contextMenu
->exec(pos
);
1391 // Delete the menu, unless it has been deleted in its own nested event loop already.
1393 contextMenu
->deleteLater();
1397 QMenu
*DolphinMainWindow::createPopupMenu()
1399 QMenu
*menu
= KXmlGuiWindow::createPopupMenu();
1401 menu
->addSeparator();
1402 menu
->addAction(actionCollection()->action(QStringLiteral("lock_panels")));
1407 void DolphinMainWindow::updateHamburgerMenu()
1409 KActionCollection
*ac
= actionCollection();
1410 auto hamburgerMenu
= static_cast<KHamburgerMenu
*>(ac
->action(KStandardAction::name(KStandardAction::HamburgerMenu
)));
1411 auto menu
= hamburgerMenu
->menu();
1413 menu
= new QMenu(this);
1414 hamburgerMenu
->setMenu(menu
);
1415 hamburgerMenu
->hideActionsOf(ac
->action(QStringLiteral("basic_actions"))->menu());
1416 hamburgerMenu
->hideActionsOf(ac
->action(QStringLiteral("zoom"))->menu());
1420 const QList
<QAction
*> toolbarActions
= toolBar()->actions();
1422 if (!toolBar()->isVisible()) {
1423 // If neither the menu bar nor the toolbar are visible, these actions should be available.
1424 menu
->addAction(ac
->action(KStandardAction::name(KStandardAction::ShowMenubar
)));
1425 menu
->addAction(toolBarMenuAction());
1426 menu
->addSeparator();
1429 // This group of actions (until the next separator) contains all the most basic actions
1430 // necessary to use Dolphin effectively.
1431 menu
->addAction(ac
->action(QStringLiteral("go_back")));
1432 menu
->addAction(ac
->action(QStringLiteral("go_forward")));
1434 menu
->addMenu(m_newFileMenu
->menu());
1435 if (!toolBar()->isVisible() || !toolbarActions
.contains(ac
->action(QStringLiteral("toggle_selection_mode_tool_bar")))) {
1436 menu
->addAction(ac
->action(QStringLiteral("toggle_selection_mode")));
1438 menu
->addAction(ac
->action(QStringLiteral("basic_actions")));
1439 menu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Undo
)));
1440 if (!toolBar()->isVisible()
1441 || (!toolbarActions
.contains(ac
->action(QStringLiteral("toggle_search")))
1442 && !toolbarActions
.contains(ac
->action(QStringLiteral("open_preferred_search_tool"))))) {
1443 menu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Find
)));
1444 // This way a search action will only be added if none of the three available
1445 // search actions is present on the toolbar.
1447 if (!toolBar()->isVisible() || !toolbarActions
.contains(ac
->action(QStringLiteral("toggle_filter")))) {
1448 menu
->addAction(ac
->action(QStringLiteral("show_filter_bar")));
1449 // This way a filter action will only be added if none of the two available
1450 // filter actions is present on the toolbar.
1452 menu
->addSeparator();
1454 // The second group of actions (up until the next separator) contains actions for opening
1455 // additional views to interact with the file system.
1456 menu
->addAction(ac
->action(QStringLiteral("file_new")));
1457 menu
->addAction(ac
->action(QStringLiteral("new_tab")));
1458 if (ac
->action(QStringLiteral("undo_close_tab"))->isEnabled()) {
1459 menu
->addAction(ac
->action(QStringLiteral("closed_tabs")));
1461 menu
->addAction(ac
->action(QStringLiteral("open_terminal")));
1462 menu
->addSeparator();
1464 // The third group contains actions to change what one sees in the view
1465 // and to change the more general UI.
1466 if (!toolBar()->isVisible()
1467 || (!toolbarActions
.contains(ac
->action(QStringLiteral("icons"))) && !toolbarActions
.contains(ac
->action(QStringLiteral("compact")))
1468 && !toolbarActions
.contains(ac
->action(QStringLiteral("details"))) && !toolbarActions
.contains(ac
->action(QStringLiteral("view_mode"))))) {
1469 menu
->addAction(ac
->action(QStringLiteral("view_mode")));
1471 menu
->addAction(ac
->action(QStringLiteral("show_hidden_files")));
1472 menu
->addAction(ac
->action(QStringLiteral("sort")));
1473 menu
->addAction(ac
->action(QStringLiteral("additional_info")));
1474 if (!GeneralSettings::showStatusBar() || !GeneralSettings::showZoomSlider()) {
1475 menu
->addAction(ac
->action(QStringLiteral("zoom")));
1477 menu
->addAction(ac
->action(QStringLiteral("panels")));
1479 // The "Configure" menu is not added to the actionCollection() because there is hardly
1480 // a good reason for users to put it on their toolbar.
1481 auto configureMenu
= menu
->addMenu(QIcon::fromTheme(QStringLiteral("configure")), i18nc("@action:inmenu menu for configure actions", "Configure"));
1482 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::SwitchApplicationLanguage
)));
1483 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::KeyBindings
)));
1484 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::ConfigureToolbars
)));
1485 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Preferences
)));
1486 hamburgerMenu
->hideActionsOf(configureMenu
);
1489 void DolphinMainWindow::slotPlaceActivated(const QUrl
&url
)
1491 DolphinViewContainer
*view
= activeViewContainer();
1493 if (view
->url() == url
) {
1494 view
->clearFilterBar(); // Fixes bug 259382.
1496 // We can end up here if the user clicked a device in the Places Panel
1497 // which had been unmounted earlier, see https://bugs.kde.org/show_bug.cgi?id=161385.
1500 view
->disableUrlNavigatorSelectionRequests();
1502 view
->enableUrlNavigatorSelectionRequests();
1506 void DolphinMainWindow::closedTabsCountChanged(unsigned int count
)
1508 actionCollection()->action(QStringLiteral("undo_close_tab"))->setEnabled(count
> 0);
1511 void DolphinMainWindow::activeViewChanged(DolphinViewContainer
*viewContainer
)
1513 DolphinViewContainer
*oldViewContainer
= m_activeViewContainer
;
1514 Q_ASSERT(viewContainer
);
1516 m_activeViewContainer
= viewContainer
;
1518 if (oldViewContainer
) {
1519 const QAction
*toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
1520 toggleSearchAction
->disconnect(oldViewContainer
);
1522 // Disconnect all signals between the old view container (container,
1523 // view and url navigator) and main window.
1524 oldViewContainer
->disconnect(this);
1525 oldViewContainer
->view()->disconnect(this);
1526 oldViewContainer
->urlNavigatorInternalWithHistory()->disconnect(this);
1527 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>(actionCollection()->action(QStringLiteral("url_navigators")));
1528 navigators
->primaryUrlNavigator()->disconnect(this);
1529 if (auto secondaryUrlNavigator
= navigators
->secondaryUrlNavigator()) {
1530 secondaryUrlNavigator
->disconnect(this);
1533 // except the requestItemInfo so that on hover the information panel can still be updated
1534 connect(oldViewContainer
->view(), &DolphinView::requestItemInfo
, this, &DolphinMainWindow::requestItemInfo
);
1536 // Disconnect other slots.
1537 disconnect(oldViewContainer
,
1538 &DolphinViewContainer::selectionModeChanged
,
1539 actionCollection()->action(QStringLiteral("toggle_selection_mode")),
1540 &QAction::setChecked
);
1543 connectViewSignals(viewContainer
);
1545 m_actionHandler
->setCurrentView(viewContainer
->view());
1548 updateFileAndEditActions();
1549 updatePasteAction();
1550 updateViewActions();
1552 updateSearchAction();
1554 const QUrl url
= viewContainer
->url();
1555 Q_EMIT
urlChanged(url
);
1558 void DolphinMainWindow::tabCountChanged(int count
)
1560 const bool enableTabActions
= (count
> 1);
1561 for (int i
= 0; i
< MaxActivateTabShortcuts
; ++i
) {
1562 actionCollection()->action(QStringLiteral("activate_tab_%1").arg(i
))->setEnabled(enableTabActions
);
1564 actionCollection()->action(QStringLiteral("activate_last_tab"))->setEnabled(enableTabActions
);
1565 actionCollection()->action(QStringLiteral("activate_next_tab"))->setEnabled(enableTabActions
);
1566 actionCollection()->action(QStringLiteral("activate_prev_tab"))->setEnabled(enableTabActions
);
1569 void DolphinMainWindow::updateWindowTitle()
1571 const QString newTitle
= m_activeViewContainer
->captionWindowTitle();
1572 if (windowTitle() != newTitle
) {
1573 setWindowTitle(newTitle
);
1577 void DolphinMainWindow::slotStorageTearDownFromPlacesRequested(const QString
&mountPath
)
1579 connect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, this, [this, mountPath
]() {
1580 setViewsToHomeIfMountPathOpen(mountPath
);
1583 if (m_terminalPanel
&& m_terminalPanel
->currentWorkingDirectoryIsChildOf(mountPath
)) {
1584 m_tearDownFromPlacesRequested
= true;
1585 m_terminalPanel
->goHome();
1586 // m_placesPanel->proceedWithTearDown() will be called in slotTerminalDirectoryChanged
1588 m_placesPanel
->proceedWithTearDown();
1592 void DolphinMainWindow::slotStorageTearDownExternallyRequested(const QString
&mountPath
)
1594 connect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, this, [this, mountPath
]() {
1595 setViewsToHomeIfMountPathOpen(mountPath
);
1598 if (m_terminalPanel
&& m_terminalPanel
->currentWorkingDirectoryIsChildOf(mountPath
)) {
1599 m_tearDownFromPlacesRequested
= false;
1600 m_terminalPanel
->goHome();
1604 void DolphinMainWindow::slotKeyBindings()
1606 KShortcutsDialog
dialog(KShortcutsEditor::AllActions
, KShortcutsEditor::LetterShortcutsAllowed
, this);
1607 dialog
.addCollection(actionCollection());
1608 if (m_terminalPanel
) {
1609 KActionCollection
*konsolePartActionCollection
= m_terminalPanel
->actionCollection();
1610 if (konsolePartActionCollection
) {
1611 dialog
.addCollection(konsolePartActionCollection
, QStringLiteral("KonsolePart"));
1617 void DolphinMainWindow::setViewsToHomeIfMountPathOpen(const QString
&mountPath
)
1619 const QVector
<DolphinViewContainer
*> theViewContainers
= viewContainers();
1620 for (DolphinViewContainer
*viewContainer
: theViewContainers
) {
1621 if (viewContainer
&& viewContainer
->url().toLocalFile().startsWith(mountPath
)) {
1622 viewContainer
->setUrl(QUrl::fromLocalFile(QDir::homePath()));
1625 disconnect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, nullptr, nullptr);
1628 void DolphinMainWindow::setupActions()
1630 auto hamburgerMenuAction
= KStandardAction::hamburgerMenu(nullptr, nullptr, actionCollection());
1632 // setup 'File' menu
1633 m_newFileMenu
= new DolphinNewFileMenu(nullptr, this);
1634 actionCollection()->addAction(QStringLiteral("new_menu"), m_newFileMenu
);
1635 QMenu
*menu
= m_newFileMenu
->menu();
1636 menu
->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1637 menu
->setIcon(QIcon::fromTheme(QStringLiteral("list-add")));
1638 m_newFileMenu
->setPopupMode(QToolButton::InstantPopup
);
1639 connect(menu
, &QMenu::aboutToShow
, this, &DolphinMainWindow::updateNewMenu
);
1641 QAction
*newWindow
= KStandardAction::openNew(this, &DolphinMainWindow::openNewMainWindow
, actionCollection());
1642 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
1643 newWindow
->setToolTip(i18nc("@info", "Open a new Dolphin window"));
1644 newWindow
->setWhatsThis(xi18nc("@info:whatsthis",
1646 "window just like this one with the current location."
1647 "<nl/>You can drag and drop items between windows."));
1648 newWindow
->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
1650 QAction
*newTab
= actionCollection()->addAction(QStringLiteral("new_tab"));
1651 newTab
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1652 newTab
->setText(i18nc("@action:inmenu File", "New Tab"));
1653 newTab
->setWhatsThis(xi18nc("@info:whatsthis",
1655 "<emphasis>Tab</emphasis> with the current location."
1656 "<nl/>Tabs allow you to quickly switch between multiple locations and views within this window. "
1657 "You can drag and drop items between tabs."));
1658 actionCollection()->setDefaultShortcut(newTab
, Qt::CTRL
| Qt::Key_T
);
1659 connect(newTab
, &QAction::triggered
, this, &DolphinMainWindow::openNewActivatedTab
);
1661 QAction
*addToPlaces
= actionCollection()->addAction(QStringLiteral("add_to_places"));
1662 addToPlaces
->setIcon(QIcon::fromTheme(QStringLiteral("bookmark-new")));
1663 addToPlaces
->setText(i18nc("@action:inmenu Add current folder to places", "Add to Places"));
1664 addToPlaces
->setWhatsThis(xi18nc("@info:whatsthis",
1665 "This adds the selected folder "
1666 "to the Places panel."));
1667 connect(addToPlaces
, &QAction::triggered
, this, &DolphinMainWindow::addToPlaces
);
1669 QAction
*closeTab
= KStandardAction::close(m_tabWidget
, QOverload
<>::of(&DolphinTabWidget::closeTab
), actionCollection());
1670 closeTab
->setText(i18nc("@action:inmenu File", "Close Tab"));
1671 closeTab
->setToolTip(i18nc("@info", "Close Tab"));
1672 closeTab
->setWhatsThis(i18nc("@info:whatsthis",
1674 "currently viewed tab. If no more tabs are left, this closes "
1675 "the whole window instead."));
1677 QAction
*quitAction
= KStandardAction::quit(this, &DolphinMainWindow::quit
, actionCollection());
1678 quitAction
->setWhatsThis(i18nc("@info:whatsthis quit", "This closes this window."));
1680 // setup 'Edit' menu
1681 KStandardAction::undo(this, &DolphinMainWindow::undo
, actionCollection());
1683 // i18n: This will be the last paragraph for the whatsthis for all three:
1684 // Cut, Copy and Paste
1685 const QString cutCopyPastePara
= xi18nc("@info:whatsthis",
1686 "<para><emphasis>Cut, "
1687 "Copy</emphasis> and <emphasis>Paste</emphasis> work between many "
1688 "applications and are among the most used commands. That's why their "
1689 "<emphasis>keyboard shortcuts</emphasis> are prominently placed right "
1690 "next to each other on the keyboard: <shortcut>Ctrl+X</shortcut>, "
1691 "<shortcut>Ctrl+C</shortcut> and <shortcut>Ctrl+V</shortcut>.</para>");
1692 QAction
*cutAction
= KStandardAction::cut(this, &DolphinMainWindow::cut
, actionCollection());
1693 m_actionTextHelper
->registerTextWhenNothingIsSelected(cutAction
, i18nc("@action", "Cut…"));
1694 cutAction
->setWhatsThis(xi18nc("@info:whatsthis cut",
1695 "This copies the items "
1696 "in your current selection to the <emphasis>clipboard</emphasis>.<nl/>"
1697 "Use the <emphasis>Paste</emphasis> action afterwards to copy them from "
1698 "the clipboard to a new location. The items will be removed from their "
1699 "initial location.")
1700 + cutCopyPastePara
);
1701 QAction
*copyAction
= KStandardAction::copy(this, &DolphinMainWindow::copy
, actionCollection());
1702 m_actionTextHelper
->registerTextWhenNothingIsSelected(copyAction
, i18nc("@action", "Copy…"));
1703 copyAction
->setWhatsThis(xi18nc("@info:whatsthis copy",
1705 "items in your current selection to the <emphasis>clipboard</emphasis>."
1706 "<nl/>Use the <emphasis>Paste</emphasis> action afterwards to copy them "
1707 "from the clipboard to a new location.")
1708 + cutCopyPastePara
);
1709 QAction
*paste
= KStandardAction::paste(this, &DolphinMainWindow::paste
, actionCollection());
1710 // The text of the paste-action is modified dynamically by Dolphin
1711 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1712 // due to the long text, the text "Paste" is used:
1713 paste
->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1714 paste
->setWhatsThis(xi18nc("@info:whatsthis paste",
1715 "This copies the items from "
1716 "your <emphasis>clipboard</emphasis> to the currently viewed folder.<nl/>"
1717 "If the items were added to the clipboard by the <emphasis>Cut</emphasis> "
1718 "action they are removed from their old location.")
1719 + cutCopyPastePara
);
1721 QAction
*copyToOtherViewAction
= actionCollection()->addAction(QStringLiteral("copy_to_inactive_split_view"));
1722 copyToOtherViewAction
->setText(i18nc("@action:inmenu", "Copy to Other View"));
1723 m_actionTextHelper
->registerTextWhenNothingIsSelected(copyToOtherViewAction
, i18nc("@action:inmenu", "Copy to Other View…"));
1724 copyToOtherViewAction
->setWhatsThis(xi18nc("@info:whatsthis Copy",
1725 "This copies the selected items from "
1726 "the view in focus to the other view. "
1727 "(Only available while in Split View mode.)"));
1728 copyToOtherViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("edit-copy")));
1729 copyToOtherViewAction
->setIconText(i18nc("@action:inmenu Edit", "Copy to Other View"));
1730 actionCollection()->setDefaultShortcut(copyToOtherViewAction
, Qt::SHIFT
| Qt::Key_F5
);
1731 connect(copyToOtherViewAction
, &QAction::triggered
, this, &DolphinMainWindow::copyToInactiveSplitView
);
1733 QAction
*moveToOtherViewAction
= actionCollection()->addAction(QStringLiteral("move_to_inactive_split_view"));
1734 moveToOtherViewAction
->setText(i18nc("@action:inmenu", "Move to Other View"));
1735 m_actionTextHelper
->registerTextWhenNothingIsSelected(moveToOtherViewAction
, i18nc("@action:inmenu", "Move to Other View…"));
1736 moveToOtherViewAction
->setWhatsThis(xi18nc("@info:whatsthis Move",
1737 "This moves the selected items from "
1738 "the view in focus to the other view. "
1739 "(Only available while in Split View mode.)"));
1740 moveToOtherViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("edit-cut")));
1741 moveToOtherViewAction
->setIconText(i18nc("@action:inmenu Edit", "Move to Other View"));
1742 actionCollection()->setDefaultShortcut(moveToOtherViewAction
, Qt::SHIFT
| Qt::Key_F6
);
1743 connect(moveToOtherViewAction
, &QAction::triggered
, this, &DolphinMainWindow::moveToInactiveSplitView
);
1745 QAction
*showFilterBar
= actionCollection()->addAction(QStringLiteral("show_filter_bar"));
1746 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Filter…"));
1747 showFilterBar
->setToolTip(i18nc("@info:tooltip", "Show Filter Bar"));
1748 showFilterBar
->setWhatsThis(xi18nc("@info:whatsthis",
1750 "<emphasis>Filter Bar</emphasis> at the bottom of the window.<nl/> "
1751 "There you can enter text to filter the files and folders currently displayed. "
1752 "Only those that contain the text in their name will be kept in view."));
1753 showFilterBar
->setIcon(QIcon::fromTheme(QStringLiteral("view-filter")));
1754 actionCollection()->setDefaultShortcuts(showFilterBar
, {Qt::CTRL
| Qt::Key_I
, Qt::Key_Slash
});
1755 connect(showFilterBar
, &QAction::triggered
, this, &DolphinMainWindow::showFilterBar
);
1757 // toggle_filter acts as a copy of the main showFilterBar to be used mainly
1758 // in the toolbar, with no default shortcut attached, to avoid messing with
1759 // existing workflows (filter bar always open and Ctrl-I to focus)
1760 QAction
*toggleFilter
= actionCollection()->addAction(QStringLiteral("toggle_filter"));
1761 toggleFilter
->setText(i18nc("@action:inmenu", "Toggle Filter Bar"));
1762 toggleFilter
->setIconText(i18nc("@action:intoolbar", "Filter"));
1763 toggleFilter
->setIcon(showFilterBar
->icon());
1764 toggleFilter
->setToolTip(showFilterBar
->toolTip());
1765 toggleFilter
->setWhatsThis(showFilterBar
->whatsThis());
1766 toggleFilter
->setCheckable(true);
1767 connect(toggleFilter
, &QAction::triggered
, this, &DolphinMainWindow::toggleFilterBar
);
1769 QAction
*searchAction
= KStandardAction::find(this, &DolphinMainWindow::find
, actionCollection());
1770 searchAction
->setText(i18n("Search…"));
1771 searchAction
->setToolTip(i18nc("@info:tooltip", "Search for files and folders"));
1772 searchAction
->setWhatsThis(xi18nc("@info:whatsthis find",
1773 "<para>This helps you "
1774 "find files and folders by opening a <emphasis>search bar</emphasis>. "
1775 "There you can enter search terms and specify settings to find the "
1776 "items you are looking for.</para><para>Use this help again on "
1777 "the search bar so we can have a look at it while the settings are "
1778 "explained.</para>"));
1780 // toggle_search acts as a copy of the main searchAction to be used mainly
1781 // in the toolbar, with no default shortcut attached, to avoid messing with
1782 // existing workflows (search bar always open and Ctrl-F to focus)
1783 QAction
*toggleSearchAction
= actionCollection()->addAction(QStringLiteral("toggle_search"));
1784 toggleSearchAction
->setText(i18nc("@action:inmenu", "Toggle Search Bar"));
1785 toggleSearchAction
->setIconText(i18nc("@action:intoolbar", "Search"));
1786 toggleSearchAction
->setIcon(searchAction
->icon());
1787 toggleSearchAction
->setToolTip(searchAction
->toolTip());
1788 toggleSearchAction
->setWhatsThis(searchAction
->whatsThis());
1789 toggleSearchAction
->setCheckable(true);
1791 QAction
*toggleSelectionModeAction
= actionCollection()->addAction(QStringLiteral("toggle_selection_mode"));
1792 // i18n: This action toggles a selection mode.
1793 toggleSelectionModeAction
->setText(i18nc("@action:inmenu", "Select Files and Folders"));
1794 // i18n: Opens a selection mode for selecting files/folders.
1795 // The text is kept so unspecific because it will be shown on the toolbar where space is at a premium.
1796 toggleSelectionModeAction
->setIconText(i18nc("@action:intoolbar", "Select"));
1797 toggleSelectionModeAction
->setWhatsThis(xi18nc(
1799 "<para>This application only knows which files or folders should be acted on if they are"
1800 " <emphasis>selected</emphasis> first. Press this to toggle a <emphasis>Selection Mode</emphasis> which makes selecting and deselecting as easy as "
1801 "pressing an item once.</para><para>While in this mode, a quick access bar at the bottom shows available actions for the currently selected items."
1803 toggleSelectionModeAction
->setIcon(QIcon::fromTheme(QStringLiteral("quickwizard")));
1804 toggleSelectionModeAction
->setCheckable(true);
1805 actionCollection()->setDefaultShortcut(toggleSelectionModeAction
, Qt::Key_Space
);
1806 connect(toggleSelectionModeAction
, &QAction::triggered
, this, &DolphinMainWindow::toggleSelectionMode
);
1808 // A special version of the toggleSelectionModeAction for the toolbar that also contains a menu
1809 // with the selectAllAction and invertSelectionAction.
1810 auto *toggleSelectionModeToolBarAction
=
1811 new KToolBarPopupAction(toggleSelectionModeAction
->icon(), toggleSelectionModeAction
->iconText(), actionCollection());
1812 toggleSelectionModeToolBarAction
->setToolTip(toggleSelectionModeAction
->text());
1813 toggleSelectionModeToolBarAction
->setWhatsThis(toggleSelectionModeAction
->whatsThis());
1814 actionCollection()->addAction(QStringLiteral("toggle_selection_mode_tool_bar"), toggleSelectionModeToolBarAction
);
1815 toggleSelectionModeToolBarAction
->setCheckable(true);
1816 toggleSelectionModeToolBarAction
->setPopupMode(KToolBarPopupAction::DelayedPopup
);
1817 connect(toggleSelectionModeToolBarAction
, &QAction::triggered
, toggleSelectionModeAction
, &QAction::trigger
);
1818 connect(toggleSelectionModeAction
, &QAction::toggled
, toggleSelectionModeToolBarAction
, &QAction::setChecked
);
1820 QAction
*selectAllAction
= KStandardAction::selectAll(this, &DolphinMainWindow::selectAll
, actionCollection());
1821 selectAllAction
->setWhatsThis(xi18nc("@info:whatsthis",
1823 "files and folders in the current location."));
1825 QAction
*invertSelection
= actionCollection()->addAction(QStringLiteral("invert_selection"));
1826 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1827 invertSelection
->setWhatsThis(xi18nc("@info:whatsthis invert",
1829 "items that you have currently <emphasis>not</emphasis> selected instead."));
1830 invertSelection
->setIcon(QIcon::fromTheme(QStringLiteral("edit-select-invert")));
1831 actionCollection()->setDefaultShortcut(invertSelection
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
1832 connect(invertSelection
, &QAction::triggered
, this, &DolphinMainWindow::invertSelection
);
1834 QMenu
*toggleSelectionModeActionMenu
= new QMenu(this);
1835 toggleSelectionModeActionMenu
->addAction(selectAllAction
);
1836 toggleSelectionModeActionMenu
->addAction(invertSelection
);
1837 toggleSelectionModeToolBarAction
->setMenu(toggleSelectionModeActionMenu
);
1839 // setup 'View' menu
1840 // (note that most of it is set up in DolphinViewActionHandler)
1842 m_splitViewAction
= actionCollection()->add
<KActionMenu
>(QStringLiteral("split_view"));
1843 m_splitViewMenuAction
= actionCollection()->addAction(QStringLiteral("split_view_menu"));
1845 m_splitViewAction
->setWhatsThis(xi18nc("@info:whatsthis split",
1846 "<para>This presents "
1847 "a second view side-by-side with the current view, so you can see "
1848 "the contents of two folders at once and easily move items between "
1849 "them.</para><para>The view that is not \"in focus\" will be dimmed. "
1850 "</para>Click this button again to close one of the views."));
1851 m_splitViewMenuAction
->setWhatsThis(m_splitViewAction
->whatsThis());
1853 // only set it for the menu version
1854 actionCollection()->setDefaultShortcut(m_splitViewMenuAction
, Qt::Key_F3
);
1856 connect(m_splitViewAction
, &QAction::triggered
, this, &DolphinMainWindow::toggleSplitView
);
1857 connect(m_splitViewMenuAction
, &QAction::triggered
, this, &DolphinMainWindow::toggleSplitView
);
1859 QAction
*popoutSplit
= actionCollection()->addAction(QStringLiteral("popout_split_view"));
1860 popoutSplit
->setWhatsThis(xi18nc("@info:whatsthis",
1861 "If the view has been split, this will pop the view in focus "
1862 "out into a new window."));
1863 popoutSplit
->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
1864 actionCollection()->setDefaultShortcut(popoutSplit
, Qt::SHIFT
| Qt::Key_F3
);
1865 connect(popoutSplit
, &QAction::triggered
, this, &DolphinMainWindow::popoutSplitView
);
1867 QAction
*stashSplit
= actionCollection()->addAction(QStringLiteral("split_stash"));
1868 actionCollection()->setDefaultShortcut(stashSplit
, Qt::CTRL
| Qt::Key_S
);
1869 stashSplit
->setText(i18nc("@action:intoolbar Stash", "Stash"));
1870 stashSplit
->setToolTip(i18nc("@info", "Opens the stash virtual directory in a split window"));
1871 stashSplit
->setIcon(QIcon::fromTheme(QStringLiteral("folder-stash")));
1872 stashSplit
->setCheckable(false);
1873 QDBusConnectionInterface
*sessionInterface
= QDBusConnection::sessionBus().interface();
1874 stashSplit
->setVisible(sessionInterface
&& sessionInterface
->isServiceRegistered(QStringLiteral("org.kde.kio.StashNotifier")));
1875 connect(stashSplit
, &QAction::triggered
, this, &DolphinMainWindow::toggleSplitStash
);
1877 QAction
*redisplay
= KStandardAction::redisplay(this, &DolphinMainWindow::reloadView
, actionCollection());
1878 redisplay
->setToolTip(i18nc("@info:tooltip", "Refresh view"));
1879 redisplay
->setWhatsThis(xi18nc("@info:whatsthis refresh",
1880 "<para>This refreshes "
1881 "the folder view.</para>"
1882 "<para>If the contents of this folder have changed, refreshing will re-scan this folder "
1883 "and show you a newly-updated view of the files and folders contained here.</para>"
1884 "<para>If the view is split, this refreshes the one that is currently in focus.</para>"));
1886 QAction
*stop
= actionCollection()->addAction(QStringLiteral("stop"));
1887 stop
->setText(i18nc("@action:inmenu View", "Stop"));
1888 stop
->setToolTip(i18nc("@info", "Stop loading"));
1889 stop
->setWhatsThis(i18nc("@info", "This stops the loading of the contents of the current folder."));
1890 stop
->setIcon(QIcon::fromTheme(QStringLiteral("process-stop")));
1891 connect(stop
, &QAction::triggered
, this, &DolphinMainWindow::stopLoading
);
1893 KToggleAction
*editableLocation
= actionCollection()->add
<KToggleAction
>(QStringLiteral("editable_location"));
1894 editableLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1895 editableLocation
->setWhatsThis(xi18nc("@info:whatsthis",
1896 "This toggles the <emphasis>Location Bar</emphasis> to be "
1897 "editable so you can directly enter a location you want to go to.<nl/>"
1898 "You can also switch to editing by clicking to the right of the "
1899 "location and switch back by confirming the edited location."));
1900 actionCollection()->setDefaultShortcut(editableLocation
, Qt::Key_F6
);
1901 connect(editableLocation
, &KToggleAction::triggered
, this, &DolphinMainWindow::toggleEditLocation
);
1903 QAction
*replaceLocation
= actionCollection()->addAction(QStringLiteral("replace_location"));
1904 replaceLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1905 // i18n: "enter" is used both in the meaning of "writing" and "going to" a new location here.
1906 // Both meanings are useful but not necessary to understand the use of "Replace Location".
1907 // So you might want to be more verbose in your language to convey the meaning but it's up to you.
1908 replaceLocation
->setWhatsThis(xi18nc("@info:whatsthis",
1909 "This switches to editing the location and selects it "
1910 "so you can quickly enter a different location."));
1911 actionCollection()->setDefaultShortcuts(replaceLocation
, {Qt::CTRL
| Qt::Key_L
, Qt::ALT
| Qt::Key_D
});
1912 connect(replaceLocation
, &QAction::triggered
, this, &DolphinMainWindow::replaceLocation
);
1916 QScopedPointer
<QAction
> backAction(KStandardAction::back(nullptr, nullptr, nullptr));
1917 m_backAction
= new KToolBarPopupAction(backAction
->icon(), backAction
->text(), actionCollection());
1918 m_backAction
->setObjectName(backAction
->objectName());
1919 m_backAction
->setShortcuts(backAction
->shortcuts());
1921 m_backAction
->setPopupMode(KToolBarPopupAction::DelayedPopup
);
1922 connect(m_backAction
, &QAction::triggered
, this, &DolphinMainWindow::goBack
);
1923 connect(m_backAction
->popupMenu(), &QMenu::aboutToShow
, this, &DolphinMainWindow::slotAboutToShowBackPopupMenu
);
1924 connect(m_backAction
->popupMenu(), &QMenu::triggered
, this, &DolphinMainWindow::slotGoBack
);
1925 actionCollection()->addAction(m_backAction
->objectName(), m_backAction
);
1927 auto backShortcuts
= m_backAction
->shortcuts();
1928 // Prepend this shortcut, to avoid being hidden by the two-slot UI (#371130)
1929 backShortcuts
.prepend(QKeySequence(Qt::Key_Backspace
));
1930 actionCollection()->setDefaultShortcuts(m_backAction
, backShortcuts
);
1932 DolphinRecentTabsMenu
*recentTabsMenu
= new DolphinRecentTabsMenu(this);
1933 actionCollection()->addAction(QStringLiteral("closed_tabs"), recentTabsMenu
);
1934 connect(m_tabWidget
, &DolphinTabWidget::rememberClosedTab
, recentTabsMenu
, &DolphinRecentTabsMenu::rememberClosedTab
);
1935 connect(recentTabsMenu
, &DolphinRecentTabsMenu::restoreClosedTab
, m_tabWidget
, &DolphinTabWidget::restoreClosedTab
);
1936 connect(recentTabsMenu
, &DolphinRecentTabsMenu::closedTabsCountChanged
, this, &DolphinMainWindow::closedTabsCountChanged
);
1938 QAction
*undoCloseTab
= actionCollection()->addAction(QStringLiteral("undo_close_tab"));
1939 undoCloseTab
->setText(i18nc("@action:inmenu File", "Undo close tab"));
1940 undoCloseTab
->setWhatsThis(i18nc("@info:whatsthis undo close tab", "This returns you to the previously closed tab."));
1941 actionCollection()->setDefaultShortcut(undoCloseTab
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_T
);
1942 undoCloseTab
->setIcon(QIcon::fromTheme(QStringLiteral("edit-undo")));
1943 undoCloseTab
->setEnabled(false);
1944 connect(undoCloseTab
, &QAction::triggered
, recentTabsMenu
, &DolphinRecentTabsMenu::undoCloseTab
);
1946 auto undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
1947 undoAction
->setWhatsThis(xi18nc("@info:whatsthis",
1949 "the last change you made to files or folders.<nl/>"
1950 "Such changes include <interface>creating</interface>, <interface>renaming</interface> "
1951 "and <interface>moving</interface> them to a different location "
1952 "or to the <filename>Trash</filename>. <nl/>Any changes that cannot be undone "
1953 "will ask for your confirmation beforehand."));
1954 undoAction
->setEnabled(false); // undo should be disabled by default
1957 QScopedPointer
<QAction
> forwardAction(KStandardAction::forward(nullptr, nullptr, nullptr));
1958 m_forwardAction
= new KToolBarPopupAction(forwardAction
->icon(), forwardAction
->text(), actionCollection());
1959 m_forwardAction
->setObjectName(forwardAction
->objectName());
1960 m_forwardAction
->setShortcuts(forwardAction
->shortcuts());
1962 m_forwardAction
->setPopupMode(KToolBarPopupAction::DelayedPopup
);
1963 connect(m_forwardAction
, &QAction::triggered
, this, &DolphinMainWindow::goForward
);
1964 connect(m_forwardAction
->popupMenu(), &QMenu::aboutToShow
, this, &DolphinMainWindow::slotAboutToShowForwardPopupMenu
);
1965 connect(m_forwardAction
->popupMenu(), &QMenu::triggered
, this, &DolphinMainWindow::slotGoForward
);
1966 actionCollection()->addAction(m_forwardAction
->objectName(), m_forwardAction
);
1967 actionCollection()->setDefaultShortcuts(m_forwardAction
, m_forwardAction
->shortcuts());
1969 // enable middle-click to open in a new tab
1970 auto *middleClickEventFilter
= new MiddleClickActionEventFilter(this);
1971 connect(middleClickEventFilter
, &MiddleClickActionEventFilter::actionMiddleClicked
, this, &DolphinMainWindow::slotBackForwardActionMiddleClicked
);
1972 m_backAction
->popupMenu()->installEventFilter(middleClickEventFilter
);
1973 m_forwardAction
->popupMenu()->installEventFilter(middleClickEventFilter
);
1974 KStandardAction::up(this, &DolphinMainWindow::goUp
, actionCollection());
1975 QAction
*homeAction
= KStandardAction::home(this, &DolphinMainWindow::goHome
, actionCollection());
1976 homeAction
->setWhatsThis(xi18nc("@info:whatsthis",
1978 "<filename>Home</filename> folder.<nl/>Every user account "
1979 "has their own <filename>Home</filename> that contains their personal files, "
1980 "as well as hidden folders for their applications' data and configuration files."));
1982 // setup 'Tools' menu
1983 QAction
*compareFiles
= actionCollection()->addAction(QStringLiteral("compare_files"));
1984 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1985 compareFiles
->setIcon(QIcon::fromTheme(QStringLiteral("kompare")));
1986 compareFiles
->setEnabled(false);
1987 connect(compareFiles
, &QAction::triggered
, this, &DolphinMainWindow::compareFiles
);
1989 QAction
*openPreferredSearchTool
= actionCollection()->addAction(QStringLiteral("open_preferred_search_tool"));
1990 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool"));
1991 openPreferredSearchTool
->setWhatsThis(xi18nc("@info:whatsthis",
1992 "<para>This opens a preferred search tool for the viewed location.</para>"
1993 "<para>Use <emphasis>More Search Tools</emphasis> menu to configure it.</para>"));
1994 openPreferredSearchTool
->setIcon(QIcon::fromTheme(QStringLiteral("search")));
1995 actionCollection()->setDefaultShortcut(openPreferredSearchTool
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_F
);
1996 connect(openPreferredSearchTool
, &QAction::triggered
, this, &DolphinMainWindow::openPreferredSearchTool
);
1998 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
1999 QAction
*openTerminal
= actionCollection()->addAction(QStringLiteral("open_terminal"));
2000 openTerminal
->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
2001 openTerminal
->setWhatsThis(xi18nc("@info:whatsthis",
2002 "<para>This opens a <emphasis>terminal</emphasis> application for the viewed location.</para>"
2003 "<para>To learn more about terminals use the help features in the terminal application.</para>"));
2004 openTerminal
->setIcon(QIcon::fromTheme(QStringLiteral("utilities-terminal")));
2005 actionCollection()->setDefaultShortcut(openTerminal
, Qt::SHIFT
| Qt::Key_F4
);
2006 connect(openTerminal
, &QAction::triggered
, this, &DolphinMainWindow::openTerminal
);
2008 QAction
*openTerminalHere
= actionCollection()->addAction(QStringLiteral("open_terminal_here"));
2009 // i18n: "Here" refers to the location(s) of the currently selected item(s) or the currently viewed location if nothing is selected.
2010 openTerminalHere
->setText(i18nc("@action:inmenu Tools", "Open Terminal Here"));
2011 openTerminalHere
->setWhatsThis(xi18nc("@info:whatsthis",
2012 "<para>This opens <emphasis>terminal</emphasis> applications for the selected items' locations.</para>"
2013 "<para>To learn more about terminals use the help features in the terminal application.</para>"));
2014 openTerminalHere
->setIcon(QIcon::fromTheme(QStringLiteral("utilities-terminal")));
2015 actionCollection()->setDefaultShortcut(openTerminalHere
, Qt::SHIFT
| Qt::ALT
| Qt::Key_F4
);
2016 connect(openTerminalHere
, &QAction::triggered
, this, &DolphinMainWindow::openTerminalHere
);
2019 QAction
*focusTerminalPanel
= actionCollection()->addAction(QStringLiteral("focus_terminal_panel"));
2020 focusTerminalPanel
->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
2021 focusTerminalPanel
->setIcon(QIcon::fromTheme(QStringLiteral("swap-panels")));
2022 actionCollection()->setDefaultShortcut(focusTerminalPanel
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_F4
);
2023 connect(focusTerminalPanel
, &QAction::triggered
, this, &DolphinMainWindow::focusTerminalPanel
);
2027 // setup 'Bookmarks' menu
2028 KActionMenu
*bookmarkMenu
= new KActionMenu(i18nc("@title:menu", "&Bookmarks"), this);
2029 bookmarkMenu
->setIcon(QIcon::fromTheme(QStringLiteral("bookmarks")));
2030 // Make the toolbar button version work properly on click
2031 bookmarkMenu
->setPopupMode(QToolButton::InstantPopup
);
2032 m_bookmarkHandler
= new DolphinBookmarkHandler(this, actionCollection(), bookmarkMenu
->menu(), this);
2033 actionCollection()->addAction(QStringLiteral("bookmarks"), bookmarkMenu
);
2035 // setup 'Settings' menu
2036 KToggleAction
*showMenuBar
= KStandardAction::showMenubar(nullptr, nullptr, actionCollection());
2037 showMenuBar
->setWhatsThis(xi18nc("@info:whatsthis",
2038 "<para>This switches between having a <emphasis>Menubar</emphasis> "
2039 "and having an <interface>%1</interface> button. Both "
2040 "contain mostly the same actions and configuration options.</para>"
2041 "<para>The Menubar takes up more space but allows for fast and organized access to all "
2042 "actions an application has to offer.</para><para>The %1 button "
2043 "is simpler and small which makes triggering advanced actions more time consuming.</para>",
2044 hamburgerMenuAction
->text().replace('&', "")));
2045 connect(showMenuBar
,
2046 &KToggleAction::triggered
, // Fixes #286822
2048 &DolphinMainWindow::toggleShowMenuBar
,
2049 Qt::QueuedConnection
);
2051 KToggleAction
*showStatusBar
= KStandardAction::showStatusbar(nullptr, nullptr, actionCollection());
2052 showStatusBar
->setChecked(GeneralSettings::showStatusBar());
2053 connect(GeneralSettings::self(), &GeneralSettings::showStatusBarChanged
, showStatusBar
, &KToggleAction::setChecked
);
2054 connect(showStatusBar
, &KToggleAction::triggered
, this, [this](bool checked
) {
2055 GeneralSettings::setShowStatusBar(checked
);
2059 KStandardAction::keyBindings(this, &DolphinMainWindow::slotKeyBindings
, actionCollection());
2060 KStandardAction::preferences(this, &DolphinMainWindow::editSettings
, actionCollection());
2062 // not in menu actions
2063 QList
<QKeySequence
> nextTabKeys
= KStandardShortcut::tabNext();
2064 nextTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::Key_Tab
));
2066 QList
<QKeySequence
> prevTabKeys
= KStandardShortcut::tabPrev();
2067 prevTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::SHIFT
| Qt::Key_Tab
));
2069 for (int i
= 0; i
< MaxActivateTabShortcuts
; ++i
) {
2070 QAction
*activateTab
= actionCollection()->addAction(QStringLiteral("activate_tab_%1").arg(i
));
2071 activateTab
->setText(i18nc("@action:inmenu", "Go to Tab %1", i
+ 1));
2072 activateTab
->setEnabled(false);
2073 connect(activateTab
, &QAction::triggered
, this, [this, i
]() {
2074 m_tabWidget
->activateTab(i
);
2077 // only add default shortcuts for the first 9 tabs regardless of MaxActivateTabShortcuts
2079 actionCollection()->setDefaultShortcut(activateTab
, QStringLiteral("Alt+%1").arg(i
+ 1));
2083 QAction
*activateLastTab
= actionCollection()->addAction(QStringLiteral("activate_last_tab"));
2084 activateLastTab
->setIconText(i18nc("@action:inmenu", "Last Tab"));
2085 activateLastTab
->setText(i18nc("@action:inmenu", "Go to Last Tab"));
2086 activateLastTab
->setEnabled(false);
2087 connect(activateLastTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activateLastTab
);
2088 actionCollection()->setDefaultShortcut(activateLastTab
, Qt::ALT
| Qt::Key_0
);
2090 QAction
*activateNextTab
= actionCollection()->addAction(QStringLiteral("activate_next_tab"));
2091 activateNextTab
->setIconText(i18nc("@action:inmenu", "Next Tab"));
2092 activateNextTab
->setText(i18nc("@action:inmenu", "Go to Next Tab"));
2093 activateNextTab
->setEnabled(false);
2094 connect(activateNextTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activateNextTab
);
2095 actionCollection()->setDefaultShortcuts(activateNextTab
, nextTabKeys
);
2097 QAction
*activatePrevTab
= actionCollection()->addAction(QStringLiteral("activate_prev_tab"));
2098 activatePrevTab
->setIconText(i18nc("@action:inmenu", "Previous Tab"));
2099 activatePrevTab
->setText(i18nc("@action:inmenu", "Go to Previous Tab"));
2100 activatePrevTab
->setEnabled(false);
2101 connect(activatePrevTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activatePrevTab
);
2102 actionCollection()->setDefaultShortcuts(activatePrevTab
, prevTabKeys
);
2105 QAction
*showTarget
= actionCollection()->addAction(QStringLiteral("show_target"));
2106 showTarget
->setText(i18nc("@action:inmenu", "Show Target"));
2107 showTarget
->setIcon(QIcon::fromTheme(QStringLiteral("document-open-folder")));
2108 showTarget
->setEnabled(false);
2109 connect(showTarget
, &QAction::triggered
, this, &DolphinMainWindow::showTarget
);
2111 QAction
*openInNewTab
= actionCollection()->addAction(QStringLiteral("open_in_new_tab"));
2112 openInNewTab
->setText(i18nc("@action:inmenu", "Open in New Tab"));
2113 openInNewTab
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
2114 connect(openInNewTab
, &QAction::triggered
, this, &DolphinMainWindow::openInNewTab
);
2116 QAction
*openInNewTabs
= actionCollection()->addAction(QStringLiteral("open_in_new_tabs"));
2117 openInNewTabs
->setText(i18nc("@action:inmenu", "Open in New Tabs"));
2118 openInNewTabs
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
2119 connect(openInNewTabs
, &QAction::triggered
, this, &DolphinMainWindow::openInNewTab
);
2121 QAction
*openInNewWindow
= actionCollection()->addAction(QStringLiteral("open_in_new_window"));
2122 openInNewWindow
->setText(i18nc("@action:inmenu", "Open in New Window"));
2123 openInNewWindow
->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
2124 connect(openInNewWindow
, &QAction::triggered
, this, &DolphinMainWindow::openInNewWindow
);
2126 QAction
*openInSplitViewAction
= actionCollection()->addAction(QStringLiteral("open_in_split_view"));
2127 openInSplitViewAction
->setText(i18nc("@action:inmenu", "Open in Split View"));
2128 openInSplitViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-right-new")));
2129 connect(openInSplitViewAction
, &QAction::triggered
, this, [this]() {
2130 openInSplitView(QUrl());
2134 void DolphinMainWindow::setupDockWidgets()
2136 const bool lock
= GeneralSettings::lockPanels();
2138 DolphinPlacesModelSingleton::instance().placesModel()->setPanelsLocked(lock
);
2140 KDualAction
*lockLayoutAction
= actionCollection()->add
<KDualAction
>(QStringLiteral("lock_panels"));
2141 lockLayoutAction
->setActiveText(i18nc("@action:inmenu Panels", "Unlock Panels"));
2142 lockLayoutAction
->setActiveIcon(QIcon::fromTheme(QStringLiteral("object-unlocked")));
2143 lockLayoutAction
->setInactiveText(i18nc("@action:inmenu Panels", "Lock Panels"));
2144 lockLayoutAction
->setInactiveIcon(QIcon::fromTheme(QStringLiteral("object-locked")));
2145 lockLayoutAction
->setWhatsThis(xi18nc("@info:whatsthis",
2147 "switches between having panels <emphasis>locked</emphasis> or "
2148 "<emphasis>unlocked</emphasis>.<nl/>Unlocked panels can be "
2149 "dragged to the other side of the window and have a close "
2150 "button.<nl/>Locked panels are embedded more cleanly."));
2151 lockLayoutAction
->setActive(lock
);
2152 connect(lockLayoutAction
, &KDualAction::triggered
, this, &DolphinMainWindow::togglePanelLockState
);
2154 // Setup "Information"
2155 DolphinDockWidget
*infoDock
= new DolphinDockWidget(i18nc("@title:window", "Information"));
2156 infoDock
->setLocked(lock
);
2157 infoDock
->setObjectName(QStringLiteral("infoDock"));
2158 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
2161 InformationPanel
*infoPanel
= new InformationPanel(infoDock
);
2162 infoPanel
->setCustomContextMenuActions({lockLayoutAction
});
2163 connect(infoPanel
, &InformationPanel::urlActivated
, this, &DolphinMainWindow::handleUrl
);
2164 infoDock
->setWidget(infoPanel
);
2166 createPanelAction(QIcon::fromTheme(QStringLiteral("dialog-information")), Qt::Key_F11
, infoDock
, QStringLiteral("show_information_panel"));
2168 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
2169 connect(this, &DolphinMainWindow::urlChanged
, infoPanel
, &InformationPanel::setUrl
);
2170 connect(this, &DolphinMainWindow::selectionChanged
, infoPanel
, &InformationPanel::setSelection
);
2171 connect(this, &DolphinMainWindow::requestItemInfo
, infoPanel
, &InformationPanel::requestDelayedItemInfo
);
2172 connect(this, &DolphinMainWindow::fileItemsChanged
, infoPanel
, &InformationPanel::slotFilesItemChanged
);
2173 connect(this, &DolphinMainWindow::settingsChanged
, infoPanel
, &InformationPanel::readSettings
);
2176 // i18n: This is the last paragraph for the "What's This"-texts of all four panels.
2177 const QString panelWhatsThis
= xi18nc("@info:whatsthis",
2179 "hide panels like this go to <interface>Menu|Panels</interface> "
2180 "or <interface>View|Panels</interface>.</para>");
2183 ->action(QStringLiteral("show_information_panel"))
2184 ->setWhatsThis(xi18nc("@info:whatsthis",
2185 "<para> This toggles the "
2186 "<emphasis>information</emphasis> panel at the right side of the "
2187 "window.</para><para>The panel provides in-depth information "
2188 "about the items your mouse is hovering over or about the selected "
2189 "items. Otherwise it informs you about the currently viewed folder.<nl/>"
2190 "For single items a preview of their contents is provided.</para>"));
2192 infoDock
->setWhatsThis(xi18nc("@info:whatsthis",
2194 "provides in-depth information about the items your mouse is "
2195 "hovering over or about the selected items. Otherwise it informs "
2196 "you about the currently viewed folder.<nl/>For single items a "
2197 "preview of their contents is provided.</para><para>You can configure "
2198 "which and how details are given here by right-clicking.</para>")
2202 DolphinDockWidget
*foldersDock
= new DolphinDockWidget(i18nc("@title:window", "Folders"));
2203 foldersDock
->setLocked(lock
);
2204 foldersDock
->setObjectName(QStringLiteral("foldersDock"));
2205 foldersDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
2206 FoldersPanel
*foldersPanel
= new FoldersPanel(foldersDock
);
2207 foldersPanel
->setCustomContextMenuActions({lockLayoutAction
});
2208 foldersDock
->setWidget(foldersPanel
);
2210 createPanelAction(QIcon::fromTheme(QStringLiteral("folder")), Qt::Key_F7
, foldersDock
, QStringLiteral("show_folders_panel"));
2212 addDockWidget(Qt::LeftDockWidgetArea
, foldersDock
);
2213 connect(this, &DolphinMainWindow::urlChanged
, foldersPanel
, &FoldersPanel::setUrl
);
2214 connect(foldersPanel
, &FoldersPanel::folderActivated
, this, &DolphinMainWindow::changeUrl
);
2215 connect(foldersPanel
, &FoldersPanel::folderInNewTab
, this, &DolphinMainWindow::openNewTab
);
2216 connect(foldersPanel
, &FoldersPanel::folderInNewActiveTab
, this, &DolphinMainWindow::openNewTabAndActivate
);
2217 connect(foldersPanel
, &FoldersPanel::errorMessage
, this, &DolphinMainWindow::showErrorMessage
);
2220 ->action(QStringLiteral("show_folders_panel"))
2221 ->setWhatsThis(xi18nc("@info:whatsthis",
2223 "<emphasis>folders</emphasis> panel at the left side of the window."
2224 "<nl/><nl/>It shows the folders of the <emphasis>file system"
2225 "</emphasis> in a <emphasis>tree view</emphasis>."));
2226 foldersDock
->setWhatsThis(xi18nc("@info:whatsthis",
2228 "shows the folders of the <emphasis>file system</emphasis> in a "
2229 "<emphasis>tree view</emphasis>.</para><para>Click a folder to go "
2230 "there. Click the arrow to the left of a folder to see its subfolders. "
2231 "This allows quick switching between any folders.</para>")
2236 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
2237 DolphinDockWidget
*terminalDock
= new DolphinDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
2238 terminalDock
->setLocked(lock
);
2239 terminalDock
->setObjectName(QStringLiteral("terminalDock"));
2240 terminalDock
->setContentsMargins(0, 0, 0, 0);
2241 m_terminalPanel
= new TerminalPanel(terminalDock
);
2242 m_terminalPanel
->setCustomContextMenuActions({lockLayoutAction
});
2243 terminalDock
->setWidget(m_terminalPanel
);
2245 connect(m_terminalPanel
, &TerminalPanel::hideTerminalPanel
, terminalDock
, &DolphinDockWidget::hide
);
2246 connect(m_terminalPanel
, &TerminalPanel::changeUrl
, this, &DolphinMainWindow::slotTerminalDirectoryChanged
);
2247 connect(terminalDock
, &DolphinDockWidget::visibilityChanged
, m_terminalPanel
, &TerminalPanel::dockVisibilityChanged
);
2248 connect(terminalDock
, &DolphinDockWidget::visibilityChanged
, this, &DolphinMainWindow::slotTerminalPanelVisibilityChanged
);
2250 createPanelAction(QIcon::fromTheme(QStringLiteral("dialog-scripts")), Qt::Key_F4
, terminalDock
, QStringLiteral("show_terminal_panel"));
2252 addDockWidget(Qt::BottomDockWidgetArea
, terminalDock
);
2253 connect(this, &DolphinMainWindow::urlChanged
, m_terminalPanel
, &TerminalPanel::setUrl
);
2255 if (GeneralSettings::version() < 200) {
2256 terminalDock
->hide();
2260 ->action(QStringLiteral("show_terminal_panel"))
2261 ->setWhatsThis(xi18nc("@info:whatsthis",
2262 "<para>This toggles the "
2263 "<emphasis>terminal</emphasis> panel at the bottom of the window."
2264 "<nl/>The location in the terminal will always match the folder "
2265 "view so you can navigate using either.</para><para>The terminal "
2266 "panel is not needed for basic computer usage but can be useful "
2267 "for advanced tasks. To learn more about terminals use the help features "
2268 "in a standalone terminal application like Konsole.</para>"));
2269 terminalDock
->setWhatsThis(xi18nc("@info:whatsthis",
2271 "the <emphasis>terminal</emphasis> panel. It behaves like a "
2272 "normal terminal but will match the location of the folder view "
2273 "so you can navigate using either.</para><para>The terminal panel "
2274 "is not needed for basic computer usage but can be useful for "
2275 "advanced tasks. To learn more about terminals use the help features in a "
2276 "standalone terminal application like Konsole.</para>")
2281 if (GeneralSettings::version() < 200) {
2283 foldersDock
->hide();
2287 DolphinDockWidget
*placesDock
= new DolphinDockWidget(i18nc("@title:window", "Places"));
2288 placesDock
->setLocked(lock
);
2289 placesDock
->setObjectName(QStringLiteral("placesDock"));
2290 placesDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
2292 m_placesPanel
= new PlacesPanel(placesDock
);
2293 m_placesPanel
->setCustomContextMenuActions({lockLayoutAction
});
2294 placesDock
->setWidget(m_placesPanel
);
2296 createPanelAction(QIcon::fromTheme(QStringLiteral("compass")), Qt::Key_F9
, placesDock
, QStringLiteral("show_places_panel"));
2298 addDockWidget(Qt::LeftDockWidgetArea
, placesDock
);
2299 connect(m_placesPanel
, &PlacesPanel::placeActivated
, this, &DolphinMainWindow::slotPlaceActivated
);
2300 connect(m_placesPanel
, &PlacesPanel::tabRequested
, this, &DolphinMainWindow::openNewTab
);
2301 connect(m_placesPanel
, &PlacesPanel::activeTabRequested
, this, &DolphinMainWindow::openNewTabAndActivate
);
2302 connect(m_placesPanel
, &PlacesPanel::newWindowRequested
, this, [this](const QUrl
&url
) {
2303 Dolphin::openNewWindow({url
}, this);
2305 connect(m_placesPanel
, &PlacesPanel::openInSplitViewRequested
, this, &DolphinMainWindow::openInSplitView
);
2306 connect(m_placesPanel
, &PlacesPanel::errorMessage
, this, &DolphinMainWindow::showErrorMessage
);
2307 connect(this, &DolphinMainWindow::urlChanged
, m_placesPanel
, &PlacesPanel::setUrl
);
2308 connect(placesDock
, &DolphinDockWidget::visibilityChanged
, &DolphinUrlNavigatorsController::slotPlacesPanelVisibilityChanged
);
2309 connect(this, &DolphinMainWindow::settingsChanged
, m_placesPanel
, &PlacesPanel::readSettings
);
2310 connect(m_placesPanel
, &PlacesPanel::storageTearDownRequested
, this, &DolphinMainWindow::slotStorageTearDownFromPlacesRequested
);
2311 connect(m_placesPanel
, &PlacesPanel::storageTearDownExternallyRequested
, this, &DolphinMainWindow::slotStorageTearDownExternallyRequested
);
2312 DolphinUrlNavigatorsController::slotPlacesPanelVisibilityChanged(m_placesPanel
->isVisible());
2314 auto actionShowAllPlaces
= new QAction(QIcon::fromTheme(QStringLiteral("view-hidden")), i18nc("@item:inmenu", "Show Hidden Places"), this);
2315 actionShowAllPlaces
->setCheckable(true);
2316 actionShowAllPlaces
->setDisabled(true);
2317 actionShowAllPlaces
->setWhatsThis(i18nc("@info:whatsthis",
2319 "all places in the places panel that have been hidden. They will "
2320 "appear semi-transparent and allow you to uncheck their \"Hide\" property."));
2322 connect(actionShowAllPlaces
, &QAction::triggered
, this, [this](bool checked
) {
2323 m_placesPanel
->setShowAll(checked
);
2325 connect(m_placesPanel
, &PlacesPanel::allPlacesShownChanged
, actionShowAllPlaces
, &QAction::setChecked
);
2328 ->action(QStringLiteral("show_places_panel"))
2329 ->setWhatsThis(xi18nc("@info:whatsthis",
2330 "<para>This toggles the "
2331 "<emphasis>places</emphasis> panel at the left side of the window."
2332 "</para><para>It allows you to go to locations you have "
2333 "bookmarked and to access disk or media attached to the computer "
2334 "or to the network. It also contains sections to find recently "
2335 "saved files or files of a certain type.</para>"));
2336 placesDock
->setWhatsThis(xi18nc("@info:whatsthis",
2337 "<para>This is the "
2338 "<emphasis>Places</emphasis> panel. It allows you to go to locations "
2339 "you have bookmarked and to access disk or media attached to the "
2340 "computer or to the network. It also contains sections to find "
2341 "recently saved files or files of a certain type.</para><para>"
2342 "Click on an entry to go there. Click with the right mouse button "
2343 "instead to open any entry in a new tab or new window.</para>"
2344 "<para>New entries can be added by dragging folders onto this panel. "
2345 "Right-click any section or entry to hide it. Right-click an empty "
2346 "space on this panel and select <interface>Show Hidden Places"
2347 "</interface> to display it again.</para>")
2350 // Add actions into the "Panels" menu
2351 KActionMenu
*panelsMenu
= new KActionMenu(i18nc("@action:inmenu View", "Show Panels"), this);
2352 actionCollection()->addAction(QStringLiteral("panels"), panelsMenu
);
2353 panelsMenu
->setIcon(QIcon::fromTheme(QStringLiteral("view-sidetree")));
2354 panelsMenu
->setPopupMode(QToolButton::InstantPopup
);
2355 const KActionCollection
*ac
= actionCollection();
2356 panelsMenu
->addAction(ac
->action(QStringLiteral("show_places_panel")));
2358 panelsMenu
->addAction(ac
->action(QStringLiteral("show_information_panel")));
2360 panelsMenu
->addAction(ac
->action(QStringLiteral("show_folders_panel")));
2361 panelsMenu
->addAction(ac
->action(QStringLiteral("show_terminal_panel")));
2362 panelsMenu
->addSeparator();
2363 panelsMenu
->addAction(actionShowAllPlaces
);
2364 panelsMenu
->addAction(lockLayoutAction
);
2366 connect(panelsMenu
->menu(), &QMenu::aboutToShow
, this, [actionShowAllPlaces
] {
2367 actionShowAllPlaces
->setEnabled(DolphinPlacesModelSingleton::instance().placesModel()->hiddenCount());
2371 void DolphinMainWindow::updateFileAndEditActions()
2373 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
2374 const KActionCollection
*col
= actionCollection();
2375 KFileItemListProperties
capabilitiesSource(list
);
2377 QAction
*renameAction
= col
->action(KStandardAction::name(KStandardAction::RenameFile
));
2378 QAction
*moveToTrashAction
= col
->action(KStandardAction::name(KStandardAction::MoveToTrash
));
2379 QAction
*deleteAction
= col
->action(KStandardAction::name(KStandardAction::DeleteFile
));
2380 QAction
*cutAction
= col
->action(KStandardAction::name(KStandardAction::Cut
));
2381 QAction
*duplicateAction
= col
->action(QStringLiteral("duplicate")); // see DolphinViewActionHandler
2382 QAction
*addToPlacesAction
= col
->action(QStringLiteral("add_to_places"));
2383 QAction
*copyToOtherViewAction
= col
->action(QStringLiteral("copy_to_inactive_split_view"));
2384 QAction
*moveToOtherViewAction
= col
->action(QStringLiteral("move_to_inactive_split_view"));
2385 QAction
*copyLocation
= col
->action(QString("copy_location"));
2387 if (list
.isEmpty()) {
2388 stateChanged(QStringLiteral("has_no_selection"));
2390 // All actions that need a selection to function can be enabled because they should trigger selection mode.
2391 renameAction
->setEnabled(true);
2392 moveToTrashAction
->setEnabled(true);
2393 deleteAction
->setEnabled(true);
2394 cutAction
->setEnabled(true);
2395 duplicateAction
->setEnabled(true);
2396 addToPlacesAction
->setEnabled(true);
2397 copyLocation
->setEnabled(true);
2398 // Them triggering selection mode and not directly acting on selected items is signified by adding "…" to their text.
2399 m_actionTextHelper
->textsWhenNothingIsSelectedEnabled(true);
2402 m_actionTextHelper
->textsWhenNothingIsSelectedEnabled(false);
2403 stateChanged(QStringLiteral("has_selection"));
2405 QAction
*deleteWithTrashShortcut
= col
->action(QStringLiteral("delete_shortcut")); // see DolphinViewActionHandler
2406 QAction
*showTarget
= col
->action(QStringLiteral("show_target"));
2408 if (list
.length() == 1 && list
.first().isDir()) {
2409 addToPlacesAction
->setEnabled(true);
2411 addToPlacesAction
->setEnabled(false);
2414 const bool enableMoveToTrash
= capabilitiesSource
.isLocal() && capabilitiesSource
.supportsMoving();
2416 renameAction
->setEnabled(capabilitiesSource
.supportsMoving());
2417 moveToTrashAction
->setEnabled(enableMoveToTrash
);
2418 deleteAction
->setEnabled(capabilitiesSource
.supportsDeleting());
2419 deleteWithTrashShortcut
->setEnabled(capabilitiesSource
.supportsDeleting() && !enableMoveToTrash
);
2420 cutAction
->setEnabled(capabilitiesSource
.supportsMoving());
2421 copyLocation
->setEnabled(list
.length() == 1);
2422 showTarget
->setEnabled(list
.length() == 1 && list
.at(0).isLink());
2423 duplicateAction
->setEnabled(capabilitiesSource
.supportsWriting());
2426 if (m_tabWidget
->currentTabPage()->splitViewEnabled() && !list
.isEmpty()) {
2427 DolphinTabPage
*tabPage
= m_tabWidget
->currentTabPage();
2428 KFileItem capabilitiesDestination
;
2430 if (tabPage
->primaryViewActive()) {
2431 capabilitiesDestination
= tabPage
->secondaryViewContainer()->rootItem();
2433 capabilitiesDestination
= tabPage
->primaryViewContainer()->rootItem();
2436 const auto destUrl
= capabilitiesDestination
.url();
2437 const bool allNotTargetOrigin
= std::all_of(list
.cbegin(), list
.cend(), [destUrl
](const KFileItem
&item
) {
2438 return item
.url().adjusted(QUrl::RemoveFilename
| QUrl::StripTrailingSlash
) != destUrl
;
2441 copyToOtherViewAction
->setEnabled(capabilitiesDestination
.isWritable() && allNotTargetOrigin
);
2442 moveToOtherViewAction
->setEnabled((list
.isEmpty() || capabilitiesSource
.supportsMoving()) && capabilitiesDestination
.isWritable()
2443 && allNotTargetOrigin
);
2445 copyToOtherViewAction
->setEnabled(false);
2446 moveToOtherViewAction
->setEnabled(false);
2450 void DolphinMainWindow::updateViewActions()
2452 m_actionHandler
->updateViewActions();
2454 QAction
*toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
2455 toggleFilterBarAction
->setChecked(m_activeViewContainer
->isFilterBarVisible());
2457 updateSplitActions();
2460 void DolphinMainWindow::updateGoActions()
2462 QAction
*goUpAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Up
));
2463 const QUrl currentUrl
= m_activeViewContainer
->url();
2464 // I think this is one of the best places to firstly be confronted
2465 // with a file system and its hierarchy. Talking about the root
2466 // directory might seem too much here but it is the question that
2467 // naturally arises in this context.
2468 goUpAction
->setWhatsThis(xi18nc("@info:whatsthis",
2470 "the folder that contains the currently viewed one.</para>"
2471 "<para>All files and folders are organized in a hierarchical "
2472 "<emphasis>file system</emphasis>. At the top of this hierarchy is "
2473 "a directory that contains all data connected to this computer"
2474 "—the <emphasis>root directory</emphasis>.</para>"));
2475 goUpAction
->setEnabled(KIO::upUrl(currentUrl
) != currentUrl
);
2478 void DolphinMainWindow::refreshViews()
2480 m_tabWidget
->refreshViews();
2482 if (GeneralSettings::modifiedStartupSettings()) {
2483 updateWindowTitle();
2486 updateSplitActions();
2488 Q_EMIT
settingsChanged();
2491 void DolphinMainWindow::clearStatusBar()
2493 m_activeViewContainer
->statusBar()->resetToDefaultText();
2496 void DolphinMainWindow::connectViewSignals(DolphinViewContainer
*container
)
2498 connect(container
, &DolphinViewContainer::showFilterBarChanged
, this, &DolphinMainWindow::updateFilterBarAction
);
2499 connect(container
, &DolphinViewContainer::writeStateChanged
, this, &DolphinMainWindow::slotWriteStateChanged
);
2500 slotWriteStateChanged(container
->view()->isFolderWritable());
2501 connect(container
, &DolphinViewContainer::searchModeEnabledChanged
, this, &DolphinMainWindow::updateSearchAction
);
2502 connect(container
, &DolphinViewContainer::captionChanged
, this, &DolphinMainWindow::updateWindowTitle
);
2503 connect(container
, &DolphinViewContainer::tabRequested
, this, &DolphinMainWindow::openNewTab
);
2504 connect(container
, &DolphinViewContainer::activeTabRequested
, this, &DolphinMainWindow::openNewTabAndActivate
);
2506 const QAction
*toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
2507 connect(toggleSearchAction
, &QAction::triggered
, container
, &DolphinViewContainer::setSearchModeEnabled
);
2509 // Make the toggled state of the selection mode actions visually follow the selection mode state of the view.
2510 auto toggleSelectionModeAction
= actionCollection()->action(QStringLiteral("toggle_selection_mode"));
2511 toggleSelectionModeAction
->setChecked(m_activeViewContainer
->isSelectionModeEnabled());
2512 connect(m_activeViewContainer
, &DolphinViewContainer::selectionModeChanged
, toggleSelectionModeAction
, &QAction::setChecked
);
2514 const DolphinView
*view
= container
->view();
2515 connect(view
, &DolphinView::selectionChanged
, this, &DolphinMainWindow::slotSelectionChanged
);
2516 connect(view
, &DolphinView::requestItemInfo
, this, &DolphinMainWindow::requestItemInfo
);
2517 connect(view
, &DolphinView::fileItemsChanged
, this, &DolphinMainWindow::fileItemsChanged
);
2518 connect(view
, &DolphinView::tabRequested
, this, &DolphinMainWindow::openNewTab
);
2519 connect(view
, &DolphinView::activeTabRequested
, this, &DolphinMainWindow::openNewTabAndActivate
);
2520 connect(view
, &DolphinView::windowRequested
, this, &DolphinMainWindow::openNewWindow
);
2521 connect(view
, &DolphinView::requestContextMenu
, this, &DolphinMainWindow::openContextMenu
);
2522 connect(view
, &DolphinView::directoryLoadingStarted
, this, &DolphinMainWindow::enableStopAction
);
2523 connect(view
, &DolphinView::directoryLoadingCompleted
, this, &DolphinMainWindow::disableStopAction
);
2524 connect(view
, &DolphinView::directoryLoadingCompleted
, this, &DolphinMainWindow::slotDirectoryLoadingCompleted
);
2525 connect(view
, &DolphinView::goBackRequested
, this, &DolphinMainWindow::goBack
);
2526 connect(view
, &DolphinView::goForwardRequested
, this, &DolphinMainWindow::goForward
);
2527 connect(view
, &DolphinView::urlActivated
, this, &DolphinMainWindow::handleUrl
);
2528 connect(view
, &DolphinView::goUpRequested
, this, &DolphinMainWindow::goUp
);
2530 connect(container
->urlNavigatorInternalWithHistory(), &KUrlNavigator::urlChanged
, this, &DolphinMainWindow::changeUrl
);
2531 connect(container
->urlNavigatorInternalWithHistory(), &KUrlNavigator::historyChanged
, this, &DolphinMainWindow::updateHistory
);
2533 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>(actionCollection()->action(QStringLiteral("url_navigators")));
2534 const KUrlNavigator
*navigator
=
2535 m_tabWidget
->currentTabPage()->primaryViewActive() ? navigators
->primaryUrlNavigator() : navigators
->secondaryUrlNavigator();
2537 QAction
*editableLocactionAction
= actionCollection()->action(QStringLiteral("editable_location"));
2538 editableLocactionAction
->setChecked(navigator
->isUrlEditable());
2539 connect(navigator
, &KUrlNavigator::editableStateChanged
, this, &DolphinMainWindow::slotEditableStateChanged
);
2540 connect(navigator
, &KUrlNavigator::tabRequested
, this, &DolphinMainWindow::openNewTab
);
2541 connect(navigator
, &KUrlNavigator::activeTabRequested
, this, &DolphinMainWindow::openNewTabAndActivate
);
2542 connect(navigator
, &KUrlNavigator::newWindowRequested
, this, &DolphinMainWindow::openNewWindow
);
2545 void DolphinMainWindow::updateSplitActions()
2547 QAction
*popoutSplitAction
= actionCollection()->action(QStringLiteral("popout_split_view"));
2549 auto setActionPopupMode
= [this](KActionMenu
*action
, QToolButton::ToolButtonPopupMode popupMode
) {
2550 action
->setPopupMode(popupMode
);
2551 if (auto *buttonForAction
= qobject_cast
<QToolButton
*>(toolBar()->widgetForAction(action
))) {
2552 buttonForAction
->setPopupMode(popupMode
);
2556 const DolphinTabPage
*tabPage
= m_tabWidget
->currentTabPage();
2557 if (tabPage
->splitViewEnabled()) {
2558 if (GeneralSettings::closeActiveSplitView() ? tabPage
->primaryViewActive() : !tabPage
->primaryViewActive()) {
2559 m_splitViewAction
->setText(i18nc("@action:intoolbar Close left view", "Close"));
2560 m_splitViewAction
->setToolTip(i18nc("@info", "Close left view"));
2561 m_splitViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-left-close")));
2562 popoutSplitAction
->setText(i18nc("@action:intoolbar Move left view to a new window", "Pop out Left View"));
2563 popoutSplitAction
->setToolTip(i18nc("@info", "Move left view to a new window"));
2565 m_splitViewAction
->setText(i18nc("@action:intoolbar Close right view", "Close"));
2566 m_splitViewAction
->setToolTip(i18nc("@info", "Close right view"));
2567 m_splitViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-right-close")));
2568 popoutSplitAction
->setText(i18nc("@action:intoolbar Move right view to a new window", "Pop out Right View"));
2569 popoutSplitAction
->setToolTip(i18nc("@info", "Move right view to a new window"));
2571 popoutSplitAction
->setEnabled(true);
2572 if (!m_splitViewAction
->menu()) {
2573 setActionPopupMode(m_splitViewAction
, QToolButton::MenuButtonPopup
);
2574 m_splitViewAction
->setMenu(new QMenu
);
2575 m_splitViewAction
->addAction(popoutSplitAction
);
2578 m_splitViewAction
->setText(i18nc("@action:intoolbar Split view", "Split"));
2579 m_splitViewAction
->setToolTip(i18nc("@info", "Split view"));
2580 m_splitViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-right-new")));
2581 popoutSplitAction
->setText(i18nc("@action:intoolbar Move view in focus to a new window", "Pop out"));
2582 popoutSplitAction
->setEnabled(false);
2583 if (m_splitViewAction
->menu()) {
2584 m_splitViewAction
->removeAction(popoutSplitAction
);
2585 m_splitViewAction
->menu()->deleteLater();
2586 m_splitViewAction
->setMenu(nullptr);
2587 setActionPopupMode(m_splitViewAction
, QToolButton::DelayedPopup
);
2591 // Update state from toolbar action
2592 m_splitViewMenuAction
->setText(m_splitViewAction
->text());
2593 m_splitViewMenuAction
->setToolTip(m_splitViewAction
->toolTip());
2594 m_splitViewMenuAction
->setIcon(m_splitViewAction
->icon());
2597 void DolphinMainWindow::updateAllowedToolbarAreas()
2599 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>(actionCollection()->action(QStringLiteral("url_navigators")));
2600 if (toolBar()->actions().contains(navigators
)) {
2601 toolBar()->setAllowedAreas(Qt::TopToolBarArea
| Qt::BottomToolBarArea
);
2602 if (toolBarArea(toolBar()) == Qt::LeftToolBarArea
|| toolBarArea(toolBar()) == Qt::RightToolBarArea
) {
2603 addToolBar(Qt::TopToolBarArea
, toolBar());
2606 toolBar()->setAllowedAreas(Qt::AllToolBarAreas
);
2610 bool DolphinMainWindow::isKompareInstalled() const
2612 static bool initialized
= false;
2613 static bool installed
= false;
2615 // TODO: maybe replace this approach later by using a menu
2616 // plugin like kdiff3plugin.cpp
2617 installed
= !QStandardPaths::findExecutable(QStringLiteral("kompare")).isEmpty();
2623 void DolphinMainWindow::createPanelAction(const QIcon
&icon
, const QKeySequence
&shortcut
, QDockWidget
*dockWidget
, const QString
&actionName
)
2625 auto dockAction
= dockWidget
->toggleViewAction();
2626 dockAction
->setIcon(icon
);
2627 dockAction
->setEnabled(true);
2629 QAction
*panelAction
= actionCollection()->addAction(actionName
, dockAction
);
2630 actionCollection()->setDefaultShortcut(panelAction
, shortcut
);
2633 void DolphinMainWindow::setupWhatsThis()
2636 menuBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2637 "<emphasis>Menubar</emphasis>. It provides access to commands and "
2638 "configuration options. Left-click on any of the menus on this "
2639 "bar to see its contents.</para><para>The Menubar can be hidden "
2640 "by unchecking <interface>Settings|Show Menubar</interface>. Then "
2641 "most of its contents become available through a <interface>Menu"
2642 "</interface> button on the <emphasis>Toolbar</emphasis>.</para>"));
2643 toolBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2644 "<emphasis>Toolbar</emphasis>. It allows quick access to "
2645 "frequently used actions.</para><para>It is highly customizable. "
2646 "All items you see in the <interface>Menu</interface> or "
2647 "in the <interface>Menubar</interface> can be placed on the "
2648 "Toolbar. Just right-click on it and select <interface>Configure "
2649 "Toolbars…</interface> or find this action within the <interface>"
2651 "</para><para>The location of the bar and the style of its "
2652 "buttons can also be changed in the right-click menu. Right-click "
2653 "a button if you want to show or hide its text.</para>"));
2654 m_tabWidget
->setWhatsThis(xi18nc("@info:whatsthis main view",
2655 "<para>Here you can see the <emphasis>folders</emphasis> and "
2656 "<emphasis>files</emphasis> that are at the location described in "
2657 "the <interface>Location Bar</interface> above. This area is the "
2658 "central part of this application where you navigate to the files "
2659 "you want to use.</para><para>For an elaborate and general "
2660 "introduction to this application <link "
2661 "url='https://userbase.kde.org/Dolphin/File_Management#Introduction_to_Dolphin'>"
2662 "click here</link>. This will open an introductory article from "
2663 "the <emphasis>KDE UserBase Wiki</emphasis>.</para><para>For brief "
2664 "explanations of all the features of this <emphasis>view</emphasis> "
2665 "<link url='help:/dolphin/dolphin-view.html'>click here</link> "
2666 "instead. This will open a page from the <emphasis>Handbook"
2667 "</emphasis> that covers the basics.</para>"));
2670 actionCollection()->action(KStandardAction::name(KStandardAction::KeyBindings
))
2671 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window "
2672 "that lists the <emphasis>keyboard shortcuts</emphasis>.<nl/>"
2673 "There you can set up key combinations to trigger an action when "
2674 "they are pressed simultaneously. All commands in this application can "
2675 "be triggered this way.</para>"));
2676 actionCollection()->action(KStandardAction::name(KStandardAction::ConfigureToolbars
))
2677 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window in which "
2678 "you can change which buttons appear on the <emphasis>Toolbar</emphasis>.</para>"
2679 "<para>All items you see in the <interface>Menu</interface> can also be placed on the Toolbar.</para>"));
2680 actionCollection()->action(KStandardAction::name(KStandardAction::Preferences
))
2681 ->setWhatsThis(xi18nc("@info:whatsthis","This opens a window where you can "
2682 "change a multitude of settings for this application. For an explanation "
2683 "of the various settings go to the chapter <emphasis>Configuring Dolphin"
2684 "</emphasis> in <interface>Help|Dolphin Handbook</interface>."));
2688 auto setStandardActionWhatsThis
= [this](KStandardAction::StandardAction actionId
,
2689 const QString
&whatsThis
) {
2690 // Check for the existence of an action since it can be restricted through the Kiosk system
2691 if (auto *action
= actionCollection()->action(KStandardAction::name(actionId
))) {
2692 action
->setWhatsThis(whatsThis
);
2696 // i18n: If the external link isn't available in your language it might make
2697 // sense to state the external link's language in brackets to not
2698 // frustrate the user. If there are multiple languages that the user might
2699 // know with a reasonable chance you might want to have 2 external links.
2700 // The same might be true for any external link you translate.
2701 setStandardActionWhatsThis(KStandardAction::HelpContents
, xi18nc("@info:whatsthis handbook", "<para>This opens the Handbook for this application. It provides explanations for every part of <emphasis>Dolphin</emphasis>.</para><para>If you want more elaborate introductions to the different features of <emphasis>Dolphin</emphasis> <link url='https://userbase.kde.org/Dolphin/File_Management'>click here</link>. It will open the dedicated page in the KDE UserBase Wiki.</para>"));
2702 // (The i18n call should be completely in the line following the i18n: comment without any line breaks within the i18n call or the comment might not be correctly extracted. See: https://commits.kde.org/kxmlgui/a31135046e1b3335b5d7bbbe6aa9a883ce3284c1 )
2704 setStandardActionWhatsThis(KStandardAction::WhatsThis
,
2705 xi18nc("@info:whatsthis whatsthis button",
2706 "<para>This is the button that invokes the help feature you are "
2707 "using right now! Click it, then click any component of this "
2708 "application to ask \"What's this?\" about it. The mouse cursor "
2709 "will change appearance if no help is available for a spot.</para>"
2710 "<para>There are two other ways to get help: "
2711 "The <link url='help:/dolphin/index.html'>Dolphin Handbook</link> and "
2712 "the <link url='https://userbase.kde.org/Dolphin/File_Management'>KDE "
2713 "UserBase Wiki</link>.</para><para>The \"What's this?\" help is "
2714 "missing in most other windows so don't get too used to this.</para>"));
2716 setStandardActionWhatsThis(KStandardAction::ReportBug
,
2717 xi18nc("@info:whatsthis","<para>This opens a "
2718 "window that will guide you through reporting errors or flaws "
2719 "in this application or in other KDE software.</para>"
2720 "<para>High-quality bug reports are much appreciated. To learn "
2721 "how to make your bug report as effective as possible "
2722 "<link url='https://community.kde.org/Get_Involved/Bug_Reporting'>"
2723 "click here</link>.</para>"));
2725 setStandardActionWhatsThis(KStandardAction::Donate
,
2726 xi18nc("@info:whatsthis", "<para>This opens a "
2727 "<emphasis>web page</emphasis> where you can donate to "
2728 "support the continued work on this application and many "
2729 "other projects by the <emphasis>KDE</emphasis> community.</para>"
2730 "<para>Donating is the easiest and fastest way to efficiently "
2731 "support KDE and its projects. KDE projects are available for "
2732 "free therefore your donation is needed to cover things that "
2733 "require money like servers, contributor meetings, etc.</para>"
2734 "<para><emphasis>KDE e.V.</emphasis> is the non-profit "
2735 "organization behind the KDE community.</para>"));
2737 setStandardActionWhatsThis(KStandardAction::SwitchApplicationLanguage
,
2738 xi18nc("@info:whatsthis",
2739 "With this you can change the language this application uses."
2740 "<nl/>You can even set secondary languages which will be used "
2741 "if texts are not available in your preferred language."));
2743 setStandardActionWhatsThis(KStandardAction::AboutApp
,
2744 xi18nc("@info:whatsthis","This opens a "
2745 "window that informs you about the version, license, "
2746 "used libraries and maintainers of this application."));
2748 setStandardActionWhatsThis(KStandardAction::AboutKDE
,
2749 xi18nc("@info:whatsthis","This opens a "
2750 "window with information about <emphasis>KDE</emphasis>. "
2751 "The KDE community are the people behind this free software."
2752 "<nl/>If you like using this application but don't know "
2753 "about KDE or want to see a cute dragon have a look!"));
2757 bool DolphinMainWindow::addHamburgerMenuToToolbar()
2759 QDomDocument domDocument
= KXMLGUIClient::domDocument();
2760 if (domDocument
.isNull()) {
2763 QDomNode toolbar
= domDocument
.elementsByTagName(QStringLiteral("ToolBar")).at(0);
2764 if (toolbar
.isNull()) {
2768 QDomElement hamburgerMenuElement
= domDocument
.createElement(QStringLiteral("Action"));
2769 hamburgerMenuElement
.setAttribute(QStringLiteral("name"), QStringLiteral("hamburger_menu"));
2770 toolbar
.appendChild(hamburgerMenuElement
);
2772 KXMLGUIFactory::saveConfigFile(domDocument
, xmlFile());
2776 // Make sure to also remove the <KXMLGUIFactory> and <QDomDocument> include
2777 // whenever this method is removed (maybe in the year ~2026).
2780 // Set a sane initial window size
2781 QSize
DolphinMainWindow::sizeHint() const
2783 return KXmlGuiWindow::sizeHint().expandedTo(QSize(760, 550));
2786 void DolphinMainWindow::saveNewToolbarConfig()
2788 KXmlGuiWindow::saveNewToolbarConfig(); // Applies the new config. This has to be called first
2789 // because the rest of this method decides things
2790 // based on the new config.
2791 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>(actionCollection()->action(QStringLiteral("url_navigators")));
2792 if (!toolBar()->actions().contains(navigators
)) {
2793 m_tabWidget
->currentTabPage()->insertNavigatorsWidget(navigators
);
2795 updateAllowedToolbarAreas();
2796 (static_cast<KHamburgerMenu
*>(actionCollection()->action(KStandardAction::name(KStandardAction::HamburgerMenu
))))->hideActionsOf(toolBar());
2799 void DolphinMainWindow::focusTerminalPanel()
2801 if (m_terminalPanel
->isVisible()) {
2802 if (m_terminalPanel
->terminalHasFocus()) {
2803 m_activeViewContainer
->view()->setFocus(Qt::FocusReason::ShortcutFocusReason
);
2804 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
2806 m_terminalPanel
->setFocus(Qt::FocusReason::ShortcutFocusReason
);
2807 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
2810 actionCollection()->action(QStringLiteral("show_terminal_panel"))->trigger();
2811 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
2815 DolphinMainWindow::UndoUiInterface::UndoUiInterface()
2816 : KIO::FileUndoManager::UiInterface()
2820 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
2824 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
*job
)
2826 DolphinMainWindow
*mainWin
= qobject_cast
<DolphinMainWindow
*>(parentWidget());
2828 DolphinViewContainer
*container
= mainWin
->activeViewContainer();
2829 container
->showMessage(job
->errorString(), DolphinViewContainer::Error
);
2831 KIO::FileUndoManager::UiInterface::jobError(job
);
2835 bool DolphinMainWindow::isUrlOpen(const QString
&url
)
2837 return m_tabWidget
->isUrlOpen(QUrl::fromUserInput(url
));
2840 bool DolphinMainWindow::isItemVisibleInAnyView(const QString
&urlOfItem
)
2842 return m_tabWidget
->isItemVisibleInAnyView(QUrl::fromUserInput(urlOfItem
));
2845 #include "moc_dolphinmainwindow.cpp"