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 <KDialogJobUiDelegate>
44 #include <KDualAction>
45 #include <KFileItemListProperties>
46 #include <KIO/CommandLauncherJob>
47 #include <KIO/JobUiDelegateFactory>
48 #include <KIO/OpenFileManagerWindowJob>
49 #include <KIO/OpenUrlJob>
50 #include <KJobWidgets>
51 #include <KLocalizedString>
52 #include <KMessageBox>
53 #include <KProtocolInfo>
54 #include <KProtocolManager>
56 #include <KShortcutsDialog>
57 #include <KStandardAction>
59 #include <KTerminalLauncherJob>
60 #include <KToggleAction>
62 #include <KToolBarPopupAction>
63 #include <KUrlComboBox>
64 #include <KUrlNavigator>
65 #include <KWindowSystem>
66 #include <KXMLGUIFactory>
68 #include <kwidgetsaddons_version.h>
70 #include <QApplication>
72 #include <QCloseEvent>
73 #include <QDesktopServices>
75 #include <QDomDocument>
79 #include <QPushButton>
81 #include <QStandardPaths>
83 #include <QToolButton>
84 #include <QtConcurrentRun>
85 #include <dolphindebug.h>
90 #include <KStartupInfo>
95 // Used for GeneralSettings::version() to determine whether
96 // an updated version of Dolphin is running, so as to migrate
97 // removed/renamed ...etc config entries; increment it in such
99 const int CurrentDolphinVersion
= 202;
100 // The maximum number of entries in the back/forward popup menu
101 const int MaxNumberOfNavigationentries
= 12;
102 // The maximum number of "Go to Tab" shortcuts
103 const int MaxActivateTabShortcuts
= 9;
106 DolphinMainWindow::DolphinMainWindow()
107 : KXmlGuiWindow(nullptr)
108 , m_newFileMenu(nullptr)
109 , m_tabWidget(nullptr)
110 , m_activeViewContainer(nullptr)
111 , m_actionHandler(nullptr)
112 , m_remoteEncoding(nullptr)
114 , m_bookmarkHandler(nullptr)
115 , m_disabledActionNotifier(nullptr)
116 , m_lastHandleUrlOpenJob(nullptr)
117 , m_terminalPanel(nullptr)
118 , m_placesPanel(nullptr)
119 , m_tearDownFromPlacesRequested(false)
120 , m_backAction(nullptr)
121 , m_forwardAction(nullptr)
122 , m_splitViewAction(nullptr)
123 , m_splitViewMenuAction(nullptr)
124 , m_sessionSaveTimer(nullptr)
125 , m_sessionSaveWatcher(nullptr)
126 , m_sessionSaveScheduled(false)
128 Q_INIT_RESOURCE(dolphin
);
130 new MainWindowAdaptor(this);
133 setWindowFlags(Qt::WindowContextHelpButtonHint
);
135 setComponentName(QStringLiteral("dolphin"), QGuiApplication::applicationDisplayName());
136 setObjectName(QStringLiteral("Dolphin#"));
138 setStateConfigGroup("State");
140 #if defined(Q_OS_WIN) || defined(Q_OS_MACOS)
141 new KColorSchemeManager(this); // Sets a sensible color scheme which fixes unreadable icons and text on Windows.
144 connect(&DolphinNewFileMenuObserver::instance(), &DolphinNewFileMenuObserver::errorMessage
, this, &DolphinMainWindow::showErrorMessage
);
146 KIO::FileUndoManager
*undoManager
= KIO::FileUndoManager::self();
147 undoManager
->setUiInterface(new UndoUiInterface());
149 connect(undoManager
, &KIO::FileUndoManager::undoAvailable
, this, &DolphinMainWindow::slotUndoAvailable
);
150 connect(undoManager
, &KIO::FileUndoManager::undoTextChanged
, this, &DolphinMainWindow::slotUndoTextChanged
);
151 connect(undoManager
, &KIO::FileUndoManager::jobRecordingStarted
, this, &DolphinMainWindow::clearStatusBar
);
152 connect(undoManager
, &KIO::FileUndoManager::jobRecordingFinished
, this, &DolphinMainWindow::showCommand
);
154 const bool firstRun
= (GeneralSettings::version() < 200);
156 GeneralSettings::setViewPropsTimestamp(QDateTime::currentDateTime());
159 setAcceptDrops(true);
161 auto *navigatorsWidgetAction
= new DolphinNavigatorsWidgetAction(this);
162 actionCollection()->addAction(QStringLiteral("url_navigators"), navigatorsWidgetAction
);
163 m_tabWidget
= new DolphinTabWidget(navigatorsWidgetAction
, this);
164 m_tabWidget
->setObjectName("tabWidget");
165 connect(m_tabWidget
, &DolphinTabWidget::activeViewChanged
, this, &DolphinMainWindow::activeViewChanged
);
166 connect(m_tabWidget
, &DolphinTabWidget::tabCountChanged
, this, &DolphinMainWindow::tabCountChanged
);
167 connect(m_tabWidget
, &DolphinTabWidget::currentUrlChanged
, this, &DolphinMainWindow::updateWindowTitle
);
168 setCentralWidget(m_tabWidget
);
170 m_actionTextHelper
= new SelectionMode::ActionTextHelper(this);
173 m_actionHandler
= new DolphinViewActionHandler(actionCollection(), m_actionTextHelper
, this);
174 connect(m_actionHandler
, &DolphinViewActionHandler::actionBeingHandled
, this, &DolphinMainWindow::clearStatusBar
);
175 connect(m_actionHandler
, &DolphinViewActionHandler::createDirectoryTriggered
, this, &DolphinMainWindow::createDirectory
);
176 connect(m_actionHandler
, &DolphinViewActionHandler::selectionModeChangeTriggered
, this, &DolphinMainWindow::slotSetSelectionMode
);
178 Q_CHECK_PTR(actionCollection()->action(QStringLiteral("create_dir")));
179 m_newFileMenu
->setNewFolderShortcutAction(actionCollection()->action(QStringLiteral("create_dir")));
181 m_remoteEncoding
= new DolphinRemoteEncoding(this, m_actionHandler
);
182 connect(this, &DolphinMainWindow::urlChanged
, m_remoteEncoding
, &DolphinRemoteEncoding::slotAboutToOpenUrl
);
184 m_disabledActionNotifier
= new DisabledActionNotifier(this);
185 connect(m_disabledActionNotifier
, &DisabledActionNotifier::disabledActionTriggered
, this, [this](const QAction
*, QString reason
) {
186 m_activeViewContainer
->showMessage(reason
, DolphinViewContainer::Warning
);
191 setupGUI(Save
| Create
| ToolBar
);
192 stateChanged(QStringLiteral("new_file"));
194 QClipboard
*clipboard
= QApplication::clipboard();
195 connect(clipboard
, &QClipboard::dataChanged
, this, &DolphinMainWindow::updatePasteAction
);
197 QAction
*toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
198 toggleFilterBarAction
->setChecked(GeneralSettings::filterBar());
201 menuBar()->setVisible(false);
204 const bool showMenu
= !menuBar()->isHidden();
205 QAction
*showMenuBarAction
= actionCollection()->action(KStandardAction::name(KStandardAction::ShowMenubar
));
206 showMenuBarAction
->setChecked(showMenu
); // workaround for bug #171080
208 auto hamburgerMenu
= static_cast<KHamburgerMenu
*>(actionCollection()->action(KStandardAction::name(KStandardAction::HamburgerMenu
)));
209 hamburgerMenu
->setMenuBar(menuBar());
210 hamburgerMenu
->setShowMenuBarAction(showMenuBarAction
);
211 connect(hamburgerMenu
, &KHamburgerMenu::aboutToShowMenu
, this, &DolphinMainWindow::updateHamburgerMenu
);
212 hamburgerMenu
->hideActionsOf(toolBar());
213 if (GeneralSettings::version() < 201 && !toolBar()->actions().contains(hamburgerMenu
)) {
214 addHamburgerMenuToToolbar();
217 updateAllowedToolbarAreas();
219 // enable middle-click on back/forward/up to open in a new tab
220 auto *middleClickEventFilter
= new MiddleClickActionEventFilter(this);
221 connect(middleClickEventFilter
, &MiddleClickActionEventFilter::actionMiddleClicked
, this, &DolphinMainWindow::slotToolBarActionMiddleClicked
);
222 toolBar()->installEventFilter(middleClickEventFilter
);
226 connect(KSycoca::self(), &KSycoca::databaseChanged
, this, &DolphinMainWindow::updateOpenPreferredSearchToolAction
);
228 QTimer::singleShot(0, this, &DolphinMainWindow::updateOpenPreferredSearchToolAction
);
230 m_fileItemActions
.setParentWidget(this);
231 connect(&m_fileItemActions
, &KFileItemActions::error
, this, [this](const QString
&errorMessage
) {
232 showErrorMessage(errorMessage
);
235 connect(GeneralSettings::self(), &GeneralSettings::splitViewChanged
, this, &DolphinMainWindow::slotSplitViewChanged
);
238 DolphinMainWindow::~DolphinMainWindow()
240 // This fixes a crash on Wayland when closing the mainwindow while another dialog is open.
241 disconnect(QGuiApplication::clipboard(), &QClipboard::dataChanged
, this, &DolphinMainWindow::updatePasteAction
);
244 QVector
<DolphinViewContainer
*> DolphinMainWindow::viewContainers() const
246 QVector
<DolphinViewContainer
*> viewContainers
;
248 for (int i
= 0; i
< m_tabWidget
->count(); ++i
) {
249 DolphinTabPage
*tabPage
= m_tabWidget
->tabPageAt(i
);
251 viewContainers
<< tabPage
->primaryViewContainer();
252 if (tabPage
->splitViewEnabled()) {
253 viewContainers
<< tabPage
->secondaryViewContainer();
256 return viewContainers
;
259 void DolphinMainWindow::openDirectories(const QList
<QUrl
> &dirs
, bool splitView
)
261 m_tabWidget
->openDirectories(dirs
, splitView
);
264 void DolphinMainWindow::openDirectories(const QStringList
&dirs
, bool splitView
)
266 openDirectories(QUrl::fromStringList(dirs
), splitView
);
269 void DolphinMainWindow::openFiles(const QList
<QUrl
> &files
, bool splitView
)
271 m_tabWidget
->openFiles(files
, splitView
);
274 bool DolphinMainWindow::isFoldersPanelEnabled() const
276 return actionCollection()->action(QStringLiteral("show_folders_panel"))->isChecked();
279 bool DolphinMainWindow::isInformationPanelEnabled() const
282 return actionCollection()->action(QStringLiteral("show_information_panel"))->isChecked();
288 bool DolphinMainWindow::isSplitViewEnabledInCurrentTab() const
290 return m_tabWidget
->currentTabPage()->splitViewEnabled();
293 void DolphinMainWindow::openFiles(const QStringList
&files
, bool splitView
)
295 openFiles(QUrl::fromStringList(files
), splitView
);
298 void DolphinMainWindow::activateWindow(const QString
&activationToken
)
300 window()->setAttribute(Qt::WA_NativeWindow
, true);
302 if (KWindowSystem::isPlatformWayland()) {
303 KWindowSystem::setCurrentXdgActivationToken(activationToken
);
304 } else if (KWindowSystem::isPlatformX11()) {
306 KStartupInfo::setNewStartupId(window()->windowHandle(), activationToken
.toUtf8());
310 KWindowSystem::activateWindow(window()->windowHandle());
313 bool DolphinMainWindow::isActiveWindow()
315 return window()->isActiveWindow();
318 void DolphinMainWindow::showCommand(CommandType command
)
320 DolphinStatusBar
*statusBar
= m_activeViewContainer
->statusBar();
322 case KIO::FileUndoManager::Copy
:
323 statusBar
->setText(i18nc("@info:status", "Successfully copied."));
325 case KIO::FileUndoManager::Move
:
326 statusBar
->setText(i18nc("@info:status", "Successfully moved."));
328 case KIO::FileUndoManager::Link
:
329 statusBar
->setText(i18nc("@info:status", "Successfully linked."));
331 case KIO::FileUndoManager::Trash
:
332 statusBar
->setText(i18nc("@info:status", "Successfully moved to trash."));
334 case KIO::FileUndoManager::Rename
:
335 statusBar
->setText(i18nc("@info:status", "Successfully renamed."));
338 case KIO::FileUndoManager::Mkdir
:
339 statusBar
->setText(i18nc("@info:status", "Created folder."));
347 void DolphinMainWindow::pasteIntoFolder()
349 m_activeViewContainer
->view()->pasteIntoFolder();
352 void DolphinMainWindow::changeUrl(const QUrl
&url
)
354 if (!KProtocolManager::supportsListing(url
)) {
355 // The URL navigator only checks for validity, not
356 // if the URL can be listed. An error message is
357 // shown due to DolphinViewContainer::restoreView().
361 m_activeViewContainer
->setUrl(url
);
362 updateFileAndEditActions();
367 Q_EMIT
urlChanged(url
);
370 void DolphinMainWindow::slotTerminalDirectoryChanged(const QUrl
&url
)
372 if (m_tearDownFromPlacesRequested
&& url
== QUrl::fromLocalFile(QDir::homePath())) {
373 m_placesPanel
->proceedWithTearDown();
374 m_tearDownFromPlacesRequested
= false;
377 m_activeViewContainer
->setAutoGrabFocus(false);
379 m_activeViewContainer
->setAutoGrabFocus(true);
382 void DolphinMainWindow::slotEditableStateChanged(bool editable
)
384 KToggleAction
*editableLocationAction
= static_cast<KToggleAction
*>(actionCollection()->action(QStringLiteral("editable_location")));
385 editableLocationAction
->setChecked(editable
);
388 void DolphinMainWindow::slotSelectionChanged(const KFileItemList
&selection
)
390 updateFileAndEditActions();
392 const int selectedUrlsCount
= m_tabWidget
->currentTabPage()->selectedItemsCount();
394 QAction
*compareFilesAction
= actionCollection()->action(QStringLiteral("compare_files"));
395 if (selectedUrlsCount
== 2) {
396 compareFilesAction
->setEnabled(isKompareInstalled());
398 compareFilesAction
->setEnabled(false);
401 Q_EMIT
selectionChanged(selection
);
404 void DolphinMainWindow::updateHistory()
406 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
407 const int index
= urlNavigator
->historyIndex();
409 QAction
*backAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Back
));
411 backAction
->setToolTip(i18nc("@info", "Go back"));
412 backAction
->setWhatsThis(i18nc("@info:whatsthis go back", "Return to the previously viewed folder."));
413 backAction
->setEnabled(index
< urlNavigator
->historySize() - 1);
416 QAction
*forwardAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Forward
));
418 forwardAction
->setToolTip(i18nc("@info", "Go forward"));
419 forwardAction
->setWhatsThis(xi18nc("@info:whatsthis go forward", "This undoes a <interface>Go|Back</interface> action."));
420 forwardAction
->setEnabled(index
> 0);
424 void DolphinMainWindow::updateFilterBarAction(bool show
)
426 QAction
*toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
427 toggleFilterBarAction
->setChecked(show
);
430 void DolphinMainWindow::openNewMainWindow()
432 Dolphin::openNewWindow({m_activeViewContainer
->url()}, this);
435 void DolphinMainWindow::openNewActivatedTab()
437 // keep browsers compatibility, new tab is always after last one
438 auto openNewTabAfterLastTabConfigured
= GeneralSettings::openNewTabAfterLastTab();
439 GeneralSettings::setOpenNewTabAfterLastTab(true);
440 m_tabWidget
->openNewActivatedTab();
441 GeneralSettings::setOpenNewTabAfterLastTab(openNewTabAfterLastTabConfigured
);
444 void DolphinMainWindow::addToPlaces()
449 // If nothing is selected, act on the current dir
450 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
451 url
= m_activeViewContainer
->url();
452 name
= m_activeViewContainer
->placesText();
454 const auto dirToAdd
= m_activeViewContainer
->view()->selectedItems().first();
455 url
= dirToAdd
.url();
456 name
= dirToAdd
.name();
460 if (m_activeViewContainer
->isSearchModeEnabled()) {
461 icon
= QStringLiteral("folder-saved-search-symbolic");
463 icon
= KIO::iconNameForUrl(url
);
465 DolphinPlacesModelSingleton::instance().placesModel()->addPlace(name
, url
, icon
);
469 void DolphinMainWindow::openNewTab(const QUrl
&url
)
471 m_tabWidget
->openNewTab(url
, QUrl());
474 void DolphinMainWindow::openNewTabAndActivate(const QUrl
&url
)
476 m_tabWidget
->openNewActivatedTab(url
, QUrl());
479 void DolphinMainWindow::openNewWindow(const QUrl
&url
)
481 Dolphin::openNewWindow({url
}, this);
484 void DolphinMainWindow::slotSplitViewChanged()
486 m_tabWidget
->currentTabPage()->setSplitViewEnabled(GeneralSettings::splitView(), WithAnimation
);
487 updateSplitActions();
490 void DolphinMainWindow::openInNewTab()
492 const KFileItemList
&list
= m_activeViewContainer
->view()->selectedItems();
493 bool tabCreated
= false;
495 for (const KFileItem
&item
: list
) {
496 const QUrl
&url
= DolphinView::openItemAsFolderUrl(item
);
497 if (!url
.isEmpty()) {
503 // if no new tab has been created from the selection
504 // open the current directory in a new tab
506 openNewTab(m_activeViewContainer
->url());
510 void DolphinMainWindow::openInNewWindow()
514 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
515 if (list
.isEmpty()) {
516 newWindowUrl
= m_activeViewContainer
->url();
517 } else if (list
.count() == 1) {
518 const KFileItem
&item
= list
.first();
519 newWindowUrl
= DolphinView::openItemAsFolderUrl(item
);
522 if (!newWindowUrl
.isEmpty()) {
523 Dolphin::openNewWindow({newWindowUrl
}, this);
527 void DolphinMainWindow::openInSplitView(const QUrl
&url
)
529 QUrl newSplitViewUrl
= url
;
531 if (newSplitViewUrl
.isEmpty()) {
532 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
533 if (list
.count() == 1) {
534 const KFileItem
&item
= list
.first();
535 newSplitViewUrl
= DolphinView::openItemAsFolderUrl(item
);
539 if (newSplitViewUrl
.isEmpty()) {
543 DolphinTabPage
*tabPage
= m_tabWidget
->currentTabPage();
544 if (tabPage
->splitViewEnabled()) {
545 tabPage
->switchActiveView();
546 tabPage
->activeViewContainer()->setUrl(newSplitViewUrl
);
548 tabPage
->setSplitViewEnabled(true, WithAnimation
, newSplitViewUrl
);
553 void DolphinMainWindow::showTarget()
555 const KFileItem link
= m_activeViewContainer
->view()->selectedItems().at(0);
556 const QUrl destinationUrl
= link
.url().resolved(QUrl(link
.linkDest()));
558 auto job
= KIO::stat(destinationUrl
, KIO::StatJob::SourceSide
, KIO::StatNoDetails
);
560 connect(job
, &KJob::finished
, this, [this, destinationUrl
](KJob
*job
) {
561 KIO::StatJob
*statJob
= static_cast<KIO::StatJob
*>(job
);
563 if (statJob
->error()) {
564 m_activeViewContainer
->showMessage(job
->errorString(), DolphinViewContainer::Error
);
566 KIO::highlightInFileManager({destinationUrl
});
571 bool DolphinMainWindow::event(QEvent
*event
)
573 if (event
->type() == QEvent::ShortcutOverride
) {
574 const QKeyEvent
*keyEvent
= static_cast<QKeyEvent
*>(event
);
575 if (keyEvent
->key() == Qt::Key_Space
&& m_activeViewContainer
->view()->handleSpaceAsNormalKey()) {
581 return KXmlGuiWindow::event(event
);
584 void DolphinMainWindow::showEvent(QShowEvent
*event
)
586 KXmlGuiWindow::showEvent(event
);
588 if (!event
->spontaneous()) {
589 m_activeViewContainer
->view()->setFocus();
593 void DolphinMainWindow::closeEvent(QCloseEvent
*event
)
595 // Find out if Dolphin is closed directly by the user or
596 // by the session manager because the session is closed
597 bool closedByUser
= true;
598 if (qApp
->isSavingSession()) {
599 closedByUser
= false;
602 if (m_tabWidget
->count() > 1 && GeneralSettings::confirmClosingMultipleTabs() && !GeneralSettings::rememberOpenedTabs() && closedByUser
) {
603 // Ask the user if he really wants to quit and close all tabs.
604 // Open a confirmation dialog with 3 buttons:
605 // QDialogButtonBox::Yes -> Quit
606 // QDialogButtonBox::No -> Close only the current tab
607 // QDialogButtonBox::Cancel -> do nothing
608 QDialog
*dialog
= new QDialog(this, Qt::Dialog
);
609 dialog
->setWindowTitle(i18nc("@title:window", "Confirmation"));
610 dialog
->setModal(true);
611 QDialogButtonBox
*buttons
= new QDialogButtonBox(QDialogButtonBox::Yes
| QDialogButtonBox::No
| QDialogButtonBox::Cancel
);
612 KGuiItem::assign(buttons
->button(QDialogButtonBox::Yes
),
613 KGuiItem(i18nc("@action:button 'Quit Dolphin' button", "&Quit %1", QGuiApplication::applicationDisplayName()),
614 QIcon::fromTheme(QStringLiteral("application-exit"))));
615 KGuiItem::assign(buttons
->button(QDialogButtonBox::No
), KGuiItem(i18n("C&lose Current Tab"), QIcon::fromTheme(QStringLiteral("tab-close"))));
616 KGuiItem::assign(buttons
->button(QDialogButtonBox::Cancel
), KStandardGuiItem::cancel());
617 buttons
->button(QDialogButtonBox::Yes
)->setDefault(true);
619 bool doNotAskAgainCheckboxResult
= false;
621 const auto result
= KMessageBox::createKMessageBox(dialog
,
623 QMessageBox::Warning
,
624 i18n("You have multiple tabs open in this window, are you sure you want to quit?"),
626 i18n("Do not ask again"),
627 &doNotAskAgainCheckboxResult
,
628 KMessageBox::Notify
);
630 if (doNotAskAgainCheckboxResult
) {
631 GeneralSettings::setConfirmClosingMultipleTabs(false);
635 case QDialogButtonBox::Yes
:
638 case QDialogButtonBox::No
:
639 // Close only the current tab
640 m_tabWidget
->closeTab();
648 if (m_terminalPanel
&& m_terminalPanel
->hasProgramRunning() && GeneralSettings::confirmClosingTerminalRunningProgram() && closedByUser
) {
649 // Ask if the user really wants to quit Dolphin with a program that is still running in the Terminal panel
650 // Open a confirmation dialog with 3 buttons:
651 // QDialogButtonBox::Yes -> Quit
652 // QDialogButtonBox::No -> Show Terminal Panel
653 // QDialogButtonBox::Cancel -> do nothing
654 QDialog
*dialog
= new QDialog(this, Qt::Dialog
);
655 dialog
->setWindowTitle(i18nc("@title:window", "Confirmation"));
656 dialog
->setModal(true);
657 auto standardButtons
= QDialogButtonBox::Yes
| QDialogButtonBox::Cancel
;
658 if (!m_terminalPanel
->isVisible()) {
659 standardButtons
|= QDialogButtonBox::No
;
661 QDialogButtonBox
*buttons
= new QDialogButtonBox(standardButtons
);
662 KGuiItem::assign(buttons
->button(QDialogButtonBox::Yes
), KStandardGuiItem::quit());
663 if (!m_terminalPanel
->isVisible()) {
664 KGuiItem::assign(buttons
->button(QDialogButtonBox::No
), KGuiItem(i18n("Show &Terminal Panel"), QIcon::fromTheme(QStringLiteral("dialog-scripts"))));
666 KGuiItem::assign(buttons
->button(QDialogButtonBox::Cancel
), KStandardGuiItem::cancel());
668 bool doNotAskAgainCheckboxResult
= false;
670 const auto result
= KMessageBox::createKMessageBox(
673 QMessageBox::Warning
,
674 i18n("The program '%1' is still running in the Terminal panel. Are you sure you want to quit?", m_terminalPanel
->runningProgramName()),
676 i18n("Do not ask again"),
677 &doNotAskAgainCheckboxResult
,
678 KMessageBox::Notify
| KMessageBox::Dangerous
);
680 if (doNotAskAgainCheckboxResult
) {
681 GeneralSettings::setConfirmClosingTerminalRunningProgram(false);
685 case QDialogButtonBox::Yes
:
688 case QDialogButtonBox::No
:
689 actionCollection()->action("show_terminal_panel")->trigger();
690 // Do not quit, ignore quit event
698 if (m_sessionSaveTimer
&& (m_sessionSaveTimer
->isActive() || m_sessionSaveWatcher
->isRunning())) {
699 const bool sessionSaveTimerActive
= m_sessionSaveTimer
->isActive();
701 m_sessionSaveTimer
->stop();
702 m_sessionSaveWatcher
->disconnect();
703 m_sessionSaveWatcher
->waitForFinished();
705 if (sessionSaveTimerActive
|| m_sessionSaveScheduled
) {
710 GeneralSettings::setVersion(CurrentDolphinVersion
);
711 GeneralSettings::self()->save();
713 KXmlGuiWindow::closeEvent(event
);
716 void DolphinMainWindow::slotSaveSession()
718 m_sessionSaveScheduled
= false;
720 if (m_sessionSaveWatcher
->isRunning()) {
721 // The previous session is still being saved - schedule another save.
722 m_sessionSaveWatcher
->disconnect();
723 connect(m_sessionSaveWatcher
, &QFutureWatcher
<void>::finished
, this, &DolphinMainWindow::slotSaveSession
, Qt::SingleShotConnection
);
724 m_sessionSaveScheduled
= true;
725 } else if (!m_sessionSaveTimer
->isActive()) {
726 // No point in saving the session if the timer is running (since it will save the session again when it times out).
727 KConfigGui::setSessionConfig(QStringLiteral("dolphin"), QStringLiteral("dolphin"));
728 KConfig
*config
= KConfigGui::sessionConfig();
729 saveGlobalProperties(config
);
730 savePropertiesInternal(config
, 1);
732 auto future
= QtConcurrent::run([config
]() {
735 m_sessionSaveWatcher
->setFuture(future
);
739 void DolphinMainWindow::setSessionAutoSaveEnabled(bool enable
)
742 if (!m_sessionSaveTimer
) {
743 m_sessionSaveTimer
= new QTimer(this);
744 m_sessionSaveWatcher
= new QFutureWatcher
<void>(this);
745 m_sessionSaveTimer
->setSingleShot(true);
746 m_sessionSaveTimer
->setInterval(22000);
748 connect(m_sessionSaveTimer
, &QTimer::timeout
, this, &DolphinMainWindow::slotSaveSession
);
751 connect(m_tabWidget
, &DolphinTabWidget::urlChanged
, m_sessionSaveTimer
, qOverload
<>(&QTimer::start
), Qt::UniqueConnection
);
752 connect(m_tabWidget
, &DolphinTabWidget::tabCountChanged
, m_sessionSaveTimer
, qOverload
<>(&QTimer::start
), Qt::UniqueConnection
);
753 connect(m_tabWidget
, &DolphinTabWidget::activeViewChanged
, m_sessionSaveTimer
, qOverload
<>(&QTimer::start
), Qt::UniqueConnection
);
754 } else if (m_sessionSaveTimer
) {
755 m_sessionSaveTimer
->stop();
756 m_sessionSaveWatcher
->disconnect();
757 m_sessionSaveScheduled
= false;
759 m_sessionSaveWatcher
->waitForFinished();
761 m_sessionSaveTimer
->deleteLater();
762 m_sessionSaveWatcher
->deleteLater();
763 m_sessionSaveTimer
= nullptr;
764 m_sessionSaveWatcher
= nullptr;
768 void DolphinMainWindow::saveProperties(KConfigGroup
&group
)
770 m_tabWidget
->saveProperties(group
);
773 void DolphinMainWindow::readProperties(const KConfigGroup
&group
)
775 m_tabWidget
->readProperties(group
);
778 void DolphinMainWindow::updateNewMenu()
780 m_newFileMenu
->checkUpToDate();
781 m_newFileMenu
->setWorkingDirectory(activeViewContainer()->url());
784 void DolphinMainWindow::createDirectory()
786 m_newFileMenu
->setWorkingDirectory(activeViewContainer()->url());
787 m_newFileMenu
->createDirectory();
790 void DolphinMainWindow::quit()
795 void DolphinMainWindow::showErrorMessage(const QString
&message
)
797 m_activeViewContainer
->showMessage(message
, DolphinViewContainer::Error
);
800 void DolphinMainWindow::slotUndoAvailable(bool available
)
802 QAction
*undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
804 undoAction
->setEnabled(available
);
808 void DolphinMainWindow::slotUndoTextChanged(const QString
&text
)
810 QAction
*undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
812 undoAction
->setText(text
);
816 void DolphinMainWindow::undo()
819 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
820 KIO::FileUndoManager::self()->undo();
823 void DolphinMainWindow::cut()
825 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
826 m_activeViewContainer
->setSelectionModeEnabled(true, actionCollection(), SelectionMode::BottomBar::Contents::CutContents
);
828 m_activeViewContainer
->view()->cutSelectedItemsToClipboard();
829 m_activeViewContainer
->setSelectionModeEnabled(false);
833 void DolphinMainWindow::copy()
835 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
836 m_activeViewContainer
->setSelectionModeEnabled(true, actionCollection(), SelectionMode::BottomBar::Contents::CopyContents
);
838 m_activeViewContainer
->view()->copySelectedItemsToClipboard();
839 m_activeViewContainer
->setSelectionModeEnabled(false);
843 void DolphinMainWindow::paste()
845 m_activeViewContainer
->view()->paste();
848 void DolphinMainWindow::find()
850 m_activeViewContainer
->setSearchModeEnabled(true);
853 void DolphinMainWindow::updateSearchAction()
855 QAction
*toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
856 toggleSearchAction
->setChecked(m_activeViewContainer
->isSearchModeEnabled());
859 void DolphinMainWindow::updatePasteAction()
861 QAction
*pasteAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Paste
));
862 QPair
<bool, QString
> pasteInfo
= m_activeViewContainer
->view()->pasteInfo();
863 pasteAction
->setEnabled(pasteInfo
.first
);
864 m_disabledActionNotifier
->setDisabledReason(pasteAction
,
865 m_activeViewContainer
->rootItem().isWritable()
866 ? i18nc("@info", "Cannot paste: The clipboard is empty.")
867 : i18nc("@info", "Cannot paste: You do not have permission to write into this folder."));
868 pasteAction
->setText(pasteInfo
.second
);
871 void DolphinMainWindow::slotDirectoryLoadingCompleted()
876 void DolphinMainWindow::slotToolBarActionMiddleClicked(QAction
*action
)
878 if (action
== actionCollection()->action(KStandardAction::name(KStandardAction::Back
))) {
880 } else if (action
== actionCollection()->action(KStandardAction::name(KStandardAction::Forward
))) {
882 } else if (action
== actionCollection()->action(QStringLiteral("go_up"))) {
884 } else if (action
== actionCollection()->action(QStringLiteral("go_home"))) {
889 QAction
*DolphinMainWindow::urlNavigatorHistoryAction(const KUrlNavigator
*urlNavigator
, int historyIndex
, QObject
*parent
)
891 const QUrl url
= urlNavigator
->locationUrl(historyIndex
);
893 QString text
= url
.toDisplayString(QUrl::PreferLocalFile
);
895 if (!urlNavigator
->showFullPath()) {
896 const KFilePlacesModel
*placesModel
= DolphinPlacesModelSingleton::instance().placesModel();
898 const QModelIndex closestIdx
= placesModel
->closestItem(url
);
899 if (closestIdx
.isValid()) {
900 const QUrl placeUrl
= placesModel
->url(closestIdx
);
902 text
= placesModel
->text(closestIdx
);
904 QString pathInsidePlace
= url
.path().mid(placeUrl
.path().length());
906 if (!pathInsidePlace
.isEmpty() && !pathInsidePlace
.startsWith(QLatin1Char('/'))) {
907 pathInsidePlace
.prepend(QLatin1Char('/'));
910 if (pathInsidePlace
!= QLatin1Char('/')) {
911 text
.append(pathInsidePlace
);
916 QAction
*action
= new QAction(QIcon::fromTheme(KIO::iconNameForUrl(url
)), text
, parent
);
917 action
->setData(historyIndex
);
921 void DolphinMainWindow::slotAboutToShowBackPopupMenu()
923 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
925 QMenu
*menu
= m_backAction
->popupMenu();
927 for (int i
= urlNavigator
->historyIndex() + 1; i
< urlNavigator
->historySize() && entries
< MaxNumberOfNavigationentries
; ++i
, ++entries
) {
928 QAction
*action
= urlNavigatorHistoryAction(urlNavigator
, i
, menu
);
929 menu
->addAction(action
);
933 void DolphinMainWindow::slotGoBack(QAction
*action
)
935 int gotoIndex
= action
->data().value
<int>();
936 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
937 for (int i
= gotoIndex
- urlNavigator
->historyIndex(); i
> 0; --i
) {
942 void DolphinMainWindow::slotBackForwardActionMiddleClicked(QAction
*action
)
945 const KUrlNavigator
*urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
946 openNewTab(urlNavigator
->locationUrl(action
->data().value
<int>()));
950 void DolphinMainWindow::slotAboutToShowForwardPopupMenu()
952 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
954 QMenu
*menu
= m_forwardAction
->popupMenu();
955 for (int i
= urlNavigator
->historyIndex() - 1; i
>= 0 && entries
< MaxNumberOfNavigationentries
; --i
, ++entries
) {
956 QAction
*action
= urlNavigatorHistoryAction(urlNavigator
, i
, menu
);
957 menu
->addAction(action
);
961 void DolphinMainWindow::slotGoForward(QAction
*action
)
963 int gotoIndex
= action
->data().value
<int>();
964 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
965 for (int i
= urlNavigator
->historyIndex() - gotoIndex
; i
> 0; --i
) {
970 void DolphinMainWindow::slotSetSelectionMode(bool enabled
, SelectionMode::BottomBar::Contents bottomBarContents
)
972 m_activeViewContainer
->setSelectionModeEnabled(enabled
, actionCollection(), bottomBarContents
);
975 void DolphinMainWindow::selectAll()
979 // if the URL navigator is editable and focused, select the whole
980 // URL instead of all items of the view
982 KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigator();
983 QLineEdit
*lineEdit
= urlNavigator
->editor()->lineEdit();
984 const bool selectUrl
= urlNavigator
->isUrlEditable() && lineEdit
->hasFocus();
986 lineEdit
->selectAll();
988 m_activeViewContainer
->view()->selectAll();
992 void DolphinMainWindow::invertSelection()
995 m_activeViewContainer
->view()->invertSelection();
998 void DolphinMainWindow::toggleSplitView()
1000 DolphinTabPage
*tabPage
= m_tabWidget
->currentTabPage();
1001 tabPage
->setSplitViewEnabled(!tabPage
->splitViewEnabled(), WithAnimation
);
1002 m_tabWidget
->updateTabName(m_tabWidget
->indexOf(tabPage
));
1003 updateViewActions();
1006 void DolphinMainWindow::popoutSplitView()
1008 DolphinTabPage
*tabPage
= m_tabWidget
->currentTabPage();
1009 if (!tabPage
->splitViewEnabled())
1011 openNewWindow((GeneralSettings::closeActiveSplitView() ? tabPage
->activeViewContainer() : tabPage
->inactiveViewContainer())->url());
1012 tabPage
->setSplitViewEnabled(false, WithAnimation
);
1013 updateSplitActions();
1016 void DolphinMainWindow::toggleSplitStash()
1018 DolphinTabPage
*tabPage
= m_tabWidget
->currentTabPage();
1019 tabPage
->setSplitViewEnabled(false, WithAnimation
);
1020 tabPage
->setSplitViewEnabled(true, WithAnimation
, QUrl("stash:/"));
1023 void DolphinMainWindow::copyToInactiveSplitView()
1025 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
1026 m_activeViewContainer
->setSelectionModeEnabled(true, actionCollection(), SelectionMode::BottomBar::Contents::CopyToOtherViewContents
);
1028 m_tabWidget
->copyToInactiveSplitView();
1029 m_activeViewContainer
->setSelectionModeEnabled(false);
1033 void DolphinMainWindow::moveToInactiveSplitView()
1035 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
1036 m_activeViewContainer
->setSelectionModeEnabled(true, actionCollection(), SelectionMode::BottomBar::Contents::MoveToOtherViewContents
);
1038 m_tabWidget
->moveToInactiveSplitView();
1039 m_activeViewContainer
->setSelectionModeEnabled(false);
1043 void DolphinMainWindow::reloadView()
1046 m_activeViewContainer
->reload();
1047 m_activeViewContainer
->statusBar()->updateSpaceInfo();
1050 void DolphinMainWindow::stopLoading()
1052 m_activeViewContainer
->view()->stopLoading();
1055 void DolphinMainWindow::enableStopAction()
1057 actionCollection()->action(QStringLiteral("stop"))->setEnabled(true);
1060 void DolphinMainWindow::disableStopAction()
1062 actionCollection()->action(QStringLiteral("stop"))->setEnabled(false);
1065 void DolphinMainWindow::toggleSelectionMode()
1067 const bool checked
= !m_activeViewContainer
->isSelectionModeEnabled();
1069 m_activeViewContainer
->setSelectionModeEnabled(checked
, actionCollection(), SelectionMode::BottomBar::Contents::GeneralContents
);
1070 actionCollection()->action(QStringLiteral("toggle_selection_mode"))->setChecked(checked
);
1073 void DolphinMainWindow::showFilterBar()
1075 m_activeViewContainer
->setFilterBarVisible(true);
1078 void DolphinMainWindow::toggleFilterBar()
1080 const bool checked
= !m_activeViewContainer
->isFilterBarVisible();
1081 m_activeViewContainer
->setFilterBarVisible(checked
);
1083 QAction
*toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
1084 toggleFilterBarAction
->setChecked(checked
);
1087 void DolphinMainWindow::toggleEditLocation()
1091 QAction
*action
= actionCollection()->action(QStringLiteral("editable_location"));
1092 KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigator();
1093 urlNavigator
->setUrlEditable(action
->isChecked());
1096 void DolphinMainWindow::replaceLocation()
1098 KUrlNavigator
*navigator
= m_activeViewContainer
->urlNavigator();
1099 QLineEdit
*lineEdit
= navigator
->editor()->lineEdit();
1101 // If the text field currently has focus and everything is selected,
1102 // pressing the keyboard shortcut returns the whole thing to breadcrumb mode
1103 if (navigator
->isUrlEditable() && lineEdit
->hasFocus() && lineEdit
->selectedText() == lineEdit
->text()) {
1104 navigator
->setUrlEditable(false);
1106 navigator
->setUrlEditable(true);
1107 navigator
->setFocus();
1108 lineEdit
->selectAll();
1112 void DolphinMainWindow::togglePanelLockState()
1114 const bool newLockState
= !GeneralSettings::lockPanels();
1115 const auto childrenObjects
= children();
1116 for (QObject
*child
: childrenObjects
) {
1117 DolphinDockWidget
*dock
= qobject_cast
<DolphinDockWidget
*>(child
);
1119 dock
->setLocked(newLockState
);
1123 DolphinPlacesModelSingleton::instance().placesModel()->setPanelsLocked(newLockState
);
1125 GeneralSettings::setLockPanels(newLockState
);
1128 void DolphinMainWindow::slotTerminalPanelVisibilityChanged()
1130 if (m_terminalPanel
->isHiddenInVisibleWindow() && m_activeViewContainer
) {
1131 m_activeViewContainer
->view()->setFocus();
1135 void DolphinMainWindow::goBack()
1137 DolphinUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
1138 urlNavigator
->goBack();
1140 if (urlNavigator
->locationState().isEmpty()) {
1141 // An empty location state indicates a redirection URL,
1142 // which must be skipped too
1143 urlNavigator
->goBack();
1147 void DolphinMainWindow::goForward()
1149 m_activeViewContainer
->urlNavigatorInternalWithHistory()->goForward();
1152 void DolphinMainWindow::goUp()
1154 m_activeViewContainer
->urlNavigatorInternalWithHistory()->goUp();
1157 void DolphinMainWindow::goHome()
1159 m_activeViewContainer
->urlNavigatorInternalWithHistory()->goHome();
1162 void DolphinMainWindow::goBackInNewTab()
1164 const KUrlNavigator
*urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
1165 const int index
= urlNavigator
->historyIndex() + 1;
1166 openNewTab(urlNavigator
->locationUrl(index
));
1169 void DolphinMainWindow::goForwardInNewTab()
1171 const KUrlNavigator
*urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
1172 const int index
= urlNavigator
->historyIndex() - 1;
1173 openNewTab(urlNavigator
->locationUrl(index
));
1176 void DolphinMainWindow::goUpInNewTab()
1178 const QUrl currentUrl
= activeViewContainer()->urlNavigator()->locationUrl();
1179 openNewTab(KIO::upUrl(currentUrl
));
1182 void DolphinMainWindow::goHomeInNewTab()
1184 openNewTab(Dolphin::homeUrl());
1187 void DolphinMainWindow::compareFiles()
1189 const KFileItemList items
= m_tabWidget
->currentTabPage()->selectedItems();
1190 if (items
.count() != 2) {
1191 // The action is disabled in this case, but it could have been triggered
1192 // via D-Bus, see https://bugs.kde.org/show_bug.cgi?id=325517
1196 QUrl urlA
= items
.at(0).url();
1197 QUrl urlB
= items
.at(1).url();
1199 QString
command(QStringLiteral("kompare -c \""));
1200 command
.append(urlA
.toDisplayString(QUrl::PreferLocalFile
));
1201 command
.append("\" \"");
1202 command
.append(urlB
.toDisplayString(QUrl::PreferLocalFile
));
1203 command
.append('\"');
1205 KIO::CommandLauncherJob
*job
= new KIO::CommandLauncherJob(command
, this);
1206 job
->setDesktopName(QStringLiteral("org.kde.kompare"));
1210 void DolphinMainWindow::toggleShowMenuBar()
1212 const bool visible
= menuBar()->isVisible();
1213 menuBar()->setVisible(!visible
);
1216 QPointer
<QAction
> DolphinMainWindow::preferredSearchTool()
1218 m_searchTools
.clear();
1220 KService::Ptr kfind
= KService::serviceByDesktopName(QStringLiteral("org.kde.kfind"));
1226 auto *action
= new QAction(QIcon::fromTheme(kfind
->icon()), kfind
->name(), this);
1228 connect(action
, &QAction::triggered
, this, [this, kfind
] {
1229 auto *job
= new KIO::ApplicationLauncherJob(kfind
);
1230 job
->setUrls({m_activeViewContainer
->url()});
1237 void DolphinMainWindow::updateOpenPreferredSearchToolAction()
1239 QAction
*openPreferredSearchTool
= actionCollection()->action(QStringLiteral("open_preferred_search_tool"));
1240 if (!openPreferredSearchTool
) {
1243 QPointer
<QAction
> tool
= preferredSearchTool();
1245 openPreferredSearchTool
->setVisible(true);
1246 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open %1", tool
->text()));
1247 // Only override with the app icon if it is the default, i.e. the user hasn't configured one manually
1248 // https://bugs.kde.org/show_bug.cgi?id=442815
1249 if (openPreferredSearchTool
->icon().name() == QLatin1String("search")) {
1250 openPreferredSearchTool
->setIcon(tool
->icon());
1253 openPreferredSearchTool
->setVisible(false);
1254 // still visible in Shortcuts configuration window
1255 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool"));
1256 openPreferredSearchTool
->setIcon(QIcon::fromTheme(QStringLiteral("search")));
1260 void DolphinMainWindow::openPreferredSearchTool()
1262 QPointer
<QAction
> tool
= preferredSearchTool();
1268 void DolphinMainWindow::openTerminal()
1270 openTerminalJob(m_activeViewContainer
->url());
1273 void DolphinMainWindow::openTerminalHere()
1275 QList
<QUrl
> urls
= {};
1277 const auto selectedItems
= m_activeViewContainer
->view()->selectedItems();
1278 for (const KFileItem
&item
: selectedItems
) {
1279 QUrl url
= item
.targetUrl();
1280 if (item
.isFile()) {
1281 url
.setPath(QFileInfo(url
.path()).absolutePath());
1283 if (!urls
.contains(url
)) {
1288 // No items are selected. Open a terminal window for the current location.
1289 if (urls
.count() == 0) {
1294 if (urls
.count() > 5) {
1295 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());
1296 const int answer
= KMessageBox::warningContinueCancel(
1300 KGuiItem(i18ncp("@action:button", "Open %1 Terminal", "Open %1 Terminals", urls
.count()), QStringLiteral("utilities-terminal")),
1301 KStandardGuiItem::cancel(),
1302 QStringLiteral("ConfirmOpenManyTerminals"));
1303 if (answer
!= KMessageBox::PrimaryAction
&& answer
!= KMessageBox::Continue
) {
1308 for (const QUrl
&url
: std::as_const(urls
)) {
1309 openTerminalJob(url
);
1313 void DolphinMainWindow::openTerminalJob(const QUrl
&url
)
1315 if (url
.isLocalFile()) {
1316 auto job
= new KTerminalLauncherJob(QString());
1317 job
->setWorkingDirectory(url
.toLocalFile());
1322 // Not a local file, with protocol Class ":local", try stat'ing
1323 if (KProtocolInfo::protocolClass(url
.scheme()) == QLatin1String(":local")) {
1324 KIO::StatJob
*job
= KIO::mostLocalUrl(url
);
1325 KJobWidgets::setWindow(job
, this);
1326 connect(job
, &KJob::result
, this, [job
]() {
1328 if (!job
->error()) {
1329 statUrl
= job
->mostLocalUrl();
1332 auto job
= new KTerminalLauncherJob(QString());
1333 job
->setWorkingDirectory(statUrl
.isLocalFile() ? statUrl
.toLocalFile() : QDir::homePath());
1340 // Nothing worked, just use $HOME
1341 auto job
= new KTerminalLauncherJob(QString());
1342 job
->setWorkingDirectory(QDir::homePath());
1346 void DolphinMainWindow::editSettings()
1348 if (!m_settingsDialog
) {
1349 DolphinViewContainer
*container
= activeViewContainer();
1350 container
->view()->writeSettings();
1352 const QUrl url
= container
->url();
1353 DolphinSettingsDialog
*settingsDialog
= new DolphinSettingsDialog(url
, this, actionCollection());
1354 connect(settingsDialog
, &DolphinSettingsDialog::settingsChanged
, this, &DolphinMainWindow::refreshViews
);
1355 connect(settingsDialog
, &DolphinSettingsDialog::settingsChanged
, &DolphinUrlNavigatorsController::slotReadSettings
);
1356 settingsDialog
->setAttribute(Qt::WA_DeleteOnClose
);
1357 settingsDialog
->show();
1358 m_settingsDialog
= settingsDialog
;
1360 m_settingsDialog
.data()->raise();
1364 void DolphinMainWindow::handleUrl(const QUrl
&url
)
1366 delete m_lastHandleUrlOpenJob
;
1367 m_lastHandleUrlOpenJob
= nullptr;
1369 if (url
.isLocalFile() && QFileInfo(url
.toLocalFile()).isDir()) {
1370 activeViewContainer()->setUrl(url
);
1372 m_lastHandleUrlOpenJob
= new KIO::OpenUrlJob(url
);
1373 m_lastHandleUrlOpenJob
->setUiDelegate(KIO::createDefaultJobUiDelegate(KJobUiDelegate::AutoHandlingEnabled
, this));
1374 m_lastHandleUrlOpenJob
->setShowOpenOrExecuteDialog(true);
1376 connect(m_lastHandleUrlOpenJob
, &KIO::OpenUrlJob::mimeTypeFound
, this, [this, url
](const QString
&mimetype
) {
1377 if (mimetype
== QLatin1String("inode/directory")) {
1378 // If it's a dir, we'll take it from here
1379 m_lastHandleUrlOpenJob
->kill();
1380 m_lastHandleUrlOpenJob
= nullptr;
1381 activeViewContainer()->setUrl(url
);
1385 connect(m_lastHandleUrlOpenJob
, &KIO::OpenUrlJob::result
, this, [this]() {
1386 m_lastHandleUrlOpenJob
= nullptr;
1389 m_lastHandleUrlOpenJob
->start();
1393 void DolphinMainWindow::slotWriteStateChanged(bool isFolderWritable
)
1395 // trash:/ is writable but we don't want to create new items in it.
1396 // TODO: remove the trash check once https://phabricator.kde.org/T8234 is implemented
1397 newFileMenu()->setEnabled(isFolderWritable
&& m_activeViewContainer
->url().scheme() != QLatin1String("trash"));
1398 // When the menu is disabled, actions in it are disabled later in the event loop, and we need to set the disabled reason after that.
1399 QTimer::singleShot(0, this, [this]() {
1400 m_disabledActionNotifier
->setDisabledReason(actionCollection()->action(QStringLiteral("create_dir")),
1401 i18nc("@info", "Cannot create new folder: You do not have permission to create items in this folder."));
1405 void DolphinMainWindow::openContextMenu(const QPoint
&pos
, const KFileItem
&item
, const KFileItemList
&selectedItems
, const QUrl
&url
)
1407 QPointer
<DolphinContextMenu
> contextMenu
= new DolphinContextMenu(this, item
, selectedItems
, url
, &m_fileItemActions
);
1408 contextMenu
->exec(pos
);
1410 // Delete the menu, unless it has been deleted in its own nested event loop already.
1412 contextMenu
->deleteLater();
1416 QMenu
*DolphinMainWindow::createPopupMenu()
1418 QMenu
*menu
= KXmlGuiWindow::createPopupMenu();
1420 menu
->addSeparator();
1421 menu
->addAction(actionCollection()->action(QStringLiteral("lock_panels")));
1426 void DolphinMainWindow::updateHamburgerMenu()
1428 KActionCollection
*ac
= actionCollection();
1429 auto hamburgerMenu
= static_cast<KHamburgerMenu
*>(ac
->action(KStandardAction::name(KStandardAction::HamburgerMenu
)));
1430 auto menu
= hamburgerMenu
->menu();
1432 menu
= new QMenu(this);
1433 hamburgerMenu
->setMenu(menu
);
1434 hamburgerMenu
->hideActionsOf(ac
->action(QStringLiteral("basic_actions"))->menu());
1435 hamburgerMenu
->hideActionsOf(ac
->action(QStringLiteral("zoom"))->menu());
1439 const QList
<QAction
*> toolbarActions
= toolBar()->actions();
1441 if (!toolBar()->isVisible()) {
1442 // If neither the menu bar nor the toolbar are visible, these actions should be available.
1443 menu
->addAction(ac
->action(KStandardAction::name(KStandardAction::ShowMenubar
)));
1444 menu
->addAction(toolBarMenuAction());
1445 menu
->addSeparator();
1448 // This group of actions (until the next separator) contains all the most basic actions
1449 // necessary to use Dolphin effectively.
1450 menu
->addAction(ac
->action(QStringLiteral("go_back")));
1451 menu
->addAction(ac
->action(QStringLiteral("go_forward")));
1453 menu
->addMenu(m_newFileMenu
->menu());
1454 if (!toolBar()->isVisible() || !toolbarActions
.contains(ac
->action(QStringLiteral("toggle_selection_mode_tool_bar")))) {
1455 menu
->addAction(ac
->action(QStringLiteral("toggle_selection_mode")));
1457 menu
->addAction(ac
->action(QStringLiteral("basic_actions")));
1458 menu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Undo
)));
1459 if (!toolBar()->isVisible()
1460 || (!toolbarActions
.contains(ac
->action(QStringLiteral("toggle_search")))
1461 && !toolbarActions
.contains(ac
->action(QStringLiteral("open_preferred_search_tool"))))) {
1462 menu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Find
)));
1463 // This way a search action will only be added if none of the three available
1464 // search actions is present on the toolbar.
1466 if (!toolBar()->isVisible() || !toolbarActions
.contains(ac
->action(QStringLiteral("toggle_filter")))) {
1467 menu
->addAction(ac
->action(QStringLiteral("show_filter_bar")));
1468 // This way a filter action will only be added if none of the two available
1469 // filter actions is present on the toolbar.
1471 menu
->addSeparator();
1473 // The second group of actions (up until the next separator) contains actions for opening
1474 // additional views to interact with the file system.
1475 menu
->addAction(ac
->action(QStringLiteral("file_new")));
1476 menu
->addAction(ac
->action(QStringLiteral("new_tab")));
1477 if (ac
->action(QStringLiteral("undo_close_tab"))->isEnabled()) {
1478 menu
->addAction(ac
->action(QStringLiteral("closed_tabs")));
1480 menu
->addAction(ac
->action(QStringLiteral("open_terminal")));
1481 menu
->addSeparator();
1483 // The third group contains actions to change what one sees in the view
1484 // and to change the more general UI.
1485 if (!toolBar()->isVisible()
1486 || (!toolbarActions
.contains(ac
->action(QStringLiteral("icons"))) && !toolbarActions
.contains(ac
->action(QStringLiteral("compact")))
1487 && !toolbarActions
.contains(ac
->action(QStringLiteral("details"))) && !toolbarActions
.contains(ac
->action(QStringLiteral("view_mode"))))) {
1488 menu
->addAction(ac
->action(QStringLiteral("view_mode")));
1490 menu
->addAction(ac
->action(QStringLiteral("show_hidden_files")));
1491 menu
->addAction(ac
->action(QStringLiteral("sort")));
1492 menu
->addAction(ac
->action(QStringLiteral("additional_info")));
1493 if (!GeneralSettings::showStatusBar() || !GeneralSettings::showZoomSlider()) {
1494 menu
->addAction(ac
->action(QStringLiteral("zoom")));
1496 menu
->addAction(ac
->action(QStringLiteral("panels")));
1498 // The "Configure" menu is not added to the actionCollection() because there is hardly
1499 // a good reason for users to put it on their toolbar.
1500 auto configureMenu
= menu
->addMenu(QIcon::fromTheme(QStringLiteral("configure")), i18nc("@action:inmenu menu for configure actions", "Configure"));
1501 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::SwitchApplicationLanguage
)));
1502 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::KeyBindings
)));
1503 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::ConfigureToolbars
)));
1504 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Preferences
)));
1505 hamburgerMenu
->hideActionsOf(configureMenu
);
1508 void DolphinMainWindow::slotPlaceActivated(const QUrl
&url
)
1510 DolphinViewContainer
*view
= activeViewContainer();
1512 if (view
->url() == url
) {
1513 view
->clearFilterBar(); // Fixes bug 259382.
1515 // We can end up here if the user clicked a device in the Places Panel
1516 // which had been unmounted earlier, see https://bugs.kde.org/show_bug.cgi?id=161385.
1519 view
->disableUrlNavigatorSelectionRequests();
1521 view
->enableUrlNavigatorSelectionRequests();
1525 void DolphinMainWindow::closedTabsCountChanged(unsigned int count
)
1527 actionCollection()->action(QStringLiteral("undo_close_tab"))->setEnabled(count
> 0);
1530 void DolphinMainWindow::activeViewChanged(DolphinViewContainer
*viewContainer
)
1532 DolphinViewContainer
*oldViewContainer
= m_activeViewContainer
;
1533 Q_ASSERT(viewContainer
);
1535 m_activeViewContainer
= viewContainer
;
1537 if (oldViewContainer
) {
1538 const QAction
*toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
1539 toggleSearchAction
->disconnect(oldViewContainer
);
1541 // Disconnect all signals between the old view container (container,
1542 // view and url navigator) and main window.
1543 oldViewContainer
->disconnect(this);
1544 oldViewContainer
->view()->disconnect(this);
1545 oldViewContainer
->urlNavigatorInternalWithHistory()->disconnect(this);
1546 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>(actionCollection()->action(QStringLiteral("url_navigators")));
1547 navigators
->primaryUrlNavigator()->disconnect(this);
1548 if (auto secondaryUrlNavigator
= navigators
->secondaryUrlNavigator()) {
1549 secondaryUrlNavigator
->disconnect(this);
1552 // except the requestItemInfo so that on hover the information panel can still be updated
1553 connect(oldViewContainer
->view(), &DolphinView::requestItemInfo
, this, &DolphinMainWindow::requestItemInfo
);
1555 // Disconnect other slots.
1556 disconnect(oldViewContainer
,
1557 &DolphinViewContainer::selectionModeChanged
,
1558 actionCollection()->action(QStringLiteral("toggle_selection_mode")),
1559 &QAction::setChecked
);
1562 connectViewSignals(viewContainer
);
1564 m_actionHandler
->setCurrentView(viewContainer
->view());
1567 updateFileAndEditActions();
1568 updatePasteAction();
1569 updateViewActions();
1571 updateSearchAction();
1573 const QUrl url
= viewContainer
->url();
1574 Q_EMIT
urlChanged(url
);
1577 void DolphinMainWindow::tabCountChanged(int count
)
1579 const bool enableTabActions
= (count
> 1);
1580 for (int i
= 0; i
< MaxActivateTabShortcuts
; ++i
) {
1581 actionCollection()->action(QStringLiteral("activate_tab_%1").arg(i
))->setEnabled(enableTabActions
);
1583 actionCollection()->action(QStringLiteral("activate_last_tab"))->setEnabled(enableTabActions
);
1584 actionCollection()->action(QStringLiteral("activate_next_tab"))->setEnabled(enableTabActions
);
1585 actionCollection()->action(QStringLiteral("activate_prev_tab"))->setEnabled(enableTabActions
);
1588 void DolphinMainWindow::updateWindowTitle()
1590 const QString newTitle
= m_activeViewContainer
->captionWindowTitle();
1591 if (windowTitle() != newTitle
) {
1592 setWindowTitle(newTitle
);
1596 void DolphinMainWindow::slotStorageTearDownFromPlacesRequested(const QString
&mountPath
)
1598 connect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, this, [this, mountPath
]() {
1599 setViewsToHomeIfMountPathOpen(mountPath
);
1602 if (m_terminalPanel
&& m_terminalPanel
->currentWorkingDirectoryIsChildOf(mountPath
)) {
1603 m_tearDownFromPlacesRequested
= true;
1604 m_terminalPanel
->goHome();
1605 // m_placesPanel->proceedWithTearDown() will be called in slotTerminalDirectoryChanged
1607 m_placesPanel
->proceedWithTearDown();
1611 void DolphinMainWindow::slotStorageTearDownExternallyRequested(const QString
&mountPath
)
1613 connect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, this, [this, mountPath
]() {
1614 setViewsToHomeIfMountPathOpen(mountPath
);
1617 if (m_terminalPanel
&& m_terminalPanel
->currentWorkingDirectoryIsChildOf(mountPath
)) {
1618 m_tearDownFromPlacesRequested
= false;
1619 m_terminalPanel
->goHome();
1623 void DolphinMainWindow::slotKeyBindings()
1625 KShortcutsDialog
dialog(KShortcutsEditor::AllActions
, KShortcutsEditor::LetterShortcutsAllowed
, this);
1626 dialog
.addCollection(actionCollection());
1627 if (m_terminalPanel
) {
1628 KActionCollection
*konsolePartActionCollection
= m_terminalPanel
->actionCollection();
1629 if (konsolePartActionCollection
) {
1630 dialog
.addCollection(konsolePartActionCollection
, QStringLiteral("KonsolePart"));
1636 void DolphinMainWindow::setViewsToHomeIfMountPathOpen(const QString
&mountPath
)
1638 const QVector
<DolphinViewContainer
*> theViewContainers
= viewContainers();
1639 for (DolphinViewContainer
*viewContainer
: theViewContainers
) {
1640 if (viewContainer
&& viewContainer
->url().toLocalFile().startsWith(mountPath
)) {
1641 viewContainer
->setUrl(QUrl::fromLocalFile(QDir::homePath()));
1644 disconnect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, nullptr, nullptr);
1647 void DolphinMainWindow::setupActions()
1649 auto hamburgerMenuAction
= KStandardAction::hamburgerMenu(nullptr, nullptr, actionCollection());
1651 // setup 'File' menu
1652 m_newFileMenu
= new DolphinNewFileMenu(nullptr, this);
1653 actionCollection()->addAction(QStringLiteral("new_menu"), m_newFileMenu
);
1654 QMenu
*menu
= m_newFileMenu
->menu();
1655 menu
->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1656 menu
->setIcon(QIcon::fromTheme(QStringLiteral("list-add")));
1657 m_newFileMenu
->setPopupMode(QToolButton::InstantPopup
);
1658 connect(menu
, &QMenu::aboutToShow
, this, &DolphinMainWindow::updateNewMenu
);
1660 QAction
*newWindow
= KStandardAction::openNew(this, &DolphinMainWindow::openNewMainWindow
, actionCollection());
1661 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
1662 newWindow
->setToolTip(i18nc("@info", "Open a new Dolphin window"));
1663 newWindow
->setWhatsThis(xi18nc("@info:whatsthis",
1665 "window just like this one with the current location."
1666 "<nl/>You can drag and drop items between windows."));
1667 newWindow
->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
1669 QAction
*newTab
= actionCollection()->addAction(QStringLiteral("new_tab"));
1670 newTab
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1671 newTab
->setText(i18nc("@action:inmenu File", "New Tab"));
1672 newTab
->setWhatsThis(xi18nc("@info:whatsthis",
1674 "<emphasis>Tab</emphasis> with the current location."
1675 "<nl/>Tabs allow you to quickly switch between multiple locations and views within this window. "
1676 "You can drag and drop items between tabs."));
1677 actionCollection()->setDefaultShortcut(newTab
, Qt::CTRL
| Qt::Key_T
);
1678 connect(newTab
, &QAction::triggered
, this, &DolphinMainWindow::openNewActivatedTab
);
1680 QAction
*addToPlaces
= actionCollection()->addAction(QStringLiteral("add_to_places"));
1681 addToPlaces
->setIcon(QIcon::fromTheme(QStringLiteral("bookmark-new")));
1682 addToPlaces
->setText(i18nc("@action:inmenu Add current folder to places", "Add to Places"));
1683 addToPlaces
->setWhatsThis(xi18nc("@info:whatsthis",
1684 "This adds the selected folder "
1685 "to the Places panel."));
1686 connect(addToPlaces
, &QAction::triggered
, this, &DolphinMainWindow::addToPlaces
);
1688 QAction
*closeTab
= KStandardAction::close(m_tabWidget
, QOverload
<>::of(&DolphinTabWidget::closeTab
), actionCollection());
1689 closeTab
->setText(i18nc("@action:inmenu File", "Close Tab"));
1690 closeTab
->setToolTip(i18nc("@info", "Close Tab"));
1691 closeTab
->setWhatsThis(i18nc("@info:whatsthis",
1693 "currently viewed tab. If no more tabs are left, this closes "
1694 "the whole window instead."));
1696 QAction
*quitAction
= KStandardAction::quit(this, &DolphinMainWindow::quit
, actionCollection());
1697 quitAction
->setWhatsThis(i18nc("@info:whatsthis quit", "This closes this window."));
1699 // setup 'Edit' menu
1700 KStandardAction::undo(this, &DolphinMainWindow::undo
, actionCollection());
1702 // i18n: This will be the last paragraph for the whatsthis for all three:
1703 // Cut, Copy and Paste
1704 const QString cutCopyPastePara
= xi18nc("@info:whatsthis",
1705 "<para><emphasis>Cut, "
1706 "Copy</emphasis> and <emphasis>Paste</emphasis> work between many "
1707 "applications and are among the most used commands. That's why their "
1708 "<emphasis>keyboard shortcuts</emphasis> are prominently placed right "
1709 "next to each other on the keyboard: <shortcut>Ctrl+X</shortcut>, "
1710 "<shortcut>Ctrl+C</shortcut> and <shortcut>Ctrl+V</shortcut>.</para>");
1711 QAction
*cutAction
= KStandardAction::cut(this, &DolphinMainWindow::cut
, actionCollection());
1712 m_actionTextHelper
->registerTextWhenNothingIsSelected(cutAction
, i18nc("@action", "Cut…"));
1713 cutAction
->setWhatsThis(xi18nc("@info:whatsthis cut",
1714 "This copies the items "
1715 "in your current selection to the <emphasis>clipboard</emphasis>.<nl/>"
1716 "Use the <emphasis>Paste</emphasis> action afterwards to copy them from "
1717 "the clipboard to a new location. The items will be removed from their "
1718 "initial location.")
1719 + cutCopyPastePara
);
1720 QAction
*copyAction
= KStandardAction::copy(this, &DolphinMainWindow::copy
, actionCollection());
1721 m_actionTextHelper
->registerTextWhenNothingIsSelected(copyAction
, i18nc("@action", "Copy…"));
1722 copyAction
->setWhatsThis(xi18nc("@info:whatsthis copy",
1724 "items in your current selection to the <emphasis>clipboard</emphasis>."
1725 "<nl/>Use the <emphasis>Paste</emphasis> action afterwards to copy them "
1726 "from the clipboard to a new location.")
1727 + cutCopyPastePara
);
1728 QAction
*paste
= KStandardAction::paste(this, &DolphinMainWindow::paste
, actionCollection());
1729 // The text of the paste-action is modified dynamically by Dolphin
1730 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1731 // due to the long text, the text "Paste" is used:
1732 paste
->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1733 paste
->setWhatsThis(xi18nc("@info:whatsthis paste",
1734 "This copies the items from "
1735 "your <emphasis>clipboard</emphasis> to the currently viewed folder.<nl/>"
1736 "If the items were added to the clipboard by the <emphasis>Cut</emphasis> "
1737 "action they are removed from their old location.")
1738 + cutCopyPastePara
);
1740 QAction
*copyToOtherViewAction
= actionCollection()->addAction(QStringLiteral("copy_to_inactive_split_view"));
1741 copyToOtherViewAction
->setText(i18nc("@action:inmenu", "Copy to Other View"));
1742 m_actionTextHelper
->registerTextWhenNothingIsSelected(copyToOtherViewAction
, i18nc("@action:inmenu", "Copy to Other View…"));
1743 copyToOtherViewAction
->setWhatsThis(xi18nc("@info:whatsthis Copy",
1744 "This copies the selected items from "
1745 "the view in focus to the other view. "
1746 "(Only available while in Split View mode.)"));
1747 copyToOtherViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("edit-copy")));
1748 copyToOtherViewAction
->setIconText(i18nc("@action:inmenu Edit", "Copy to Other View"));
1749 actionCollection()->setDefaultShortcut(copyToOtherViewAction
, Qt::SHIFT
| Qt::Key_F5
);
1750 connect(copyToOtherViewAction
, &QAction::triggered
, this, &DolphinMainWindow::copyToInactiveSplitView
);
1752 QAction
*moveToOtherViewAction
= actionCollection()->addAction(QStringLiteral("move_to_inactive_split_view"));
1753 moveToOtherViewAction
->setText(i18nc("@action:inmenu", "Move to Other View"));
1754 m_actionTextHelper
->registerTextWhenNothingIsSelected(moveToOtherViewAction
, i18nc("@action:inmenu", "Move to Other View…"));
1755 moveToOtherViewAction
->setWhatsThis(xi18nc("@info:whatsthis Move",
1756 "This moves the selected items from "
1757 "the view in focus to the other view. "
1758 "(Only available while in Split View mode.)"));
1759 moveToOtherViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("edit-cut")));
1760 moveToOtherViewAction
->setIconText(i18nc("@action:inmenu Edit", "Move to Other View"));
1761 actionCollection()->setDefaultShortcut(moveToOtherViewAction
, Qt::SHIFT
| Qt::Key_F6
);
1762 connect(moveToOtherViewAction
, &QAction::triggered
, this, &DolphinMainWindow::moveToInactiveSplitView
);
1764 QAction
*showFilterBar
= actionCollection()->addAction(QStringLiteral("show_filter_bar"));
1765 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Filter…"));
1766 showFilterBar
->setToolTip(i18nc("@info:tooltip", "Show Filter Bar"));
1767 showFilterBar
->setWhatsThis(xi18nc("@info:whatsthis",
1769 "<emphasis>Filter Bar</emphasis> at the bottom of the window.<nl/> "
1770 "There you can enter text to filter the files and folders currently displayed. "
1771 "Only those that contain the text in their name will be kept in view."));
1772 showFilterBar
->setIcon(QIcon::fromTheme(QStringLiteral("view-filter")));
1773 actionCollection()->setDefaultShortcuts(showFilterBar
, {Qt::CTRL
| Qt::Key_I
, Qt::Key_Slash
});
1774 connect(showFilterBar
, &QAction::triggered
, this, &DolphinMainWindow::showFilterBar
);
1776 // toggle_filter acts as a copy of the main showFilterBar to be used mainly
1777 // in the toolbar, with no default shortcut attached, to avoid messing with
1778 // existing workflows (filter bar always open and Ctrl-I to focus)
1779 QAction
*toggleFilter
= actionCollection()->addAction(QStringLiteral("toggle_filter"));
1780 toggleFilter
->setText(i18nc("@action:inmenu", "Toggle Filter Bar"));
1781 toggleFilter
->setIconText(i18nc("@action:intoolbar", "Filter"));
1782 toggleFilter
->setIcon(showFilterBar
->icon());
1783 toggleFilter
->setToolTip(showFilterBar
->toolTip());
1784 toggleFilter
->setWhatsThis(showFilterBar
->whatsThis());
1785 toggleFilter
->setCheckable(true);
1786 connect(toggleFilter
, &QAction::triggered
, this, &DolphinMainWindow::toggleFilterBar
);
1788 QAction
*searchAction
= KStandardAction::find(this, &DolphinMainWindow::find
, actionCollection());
1789 searchAction
->setText(i18n("Search…"));
1790 searchAction
->setToolTip(i18nc("@info:tooltip", "Search for files and folders"));
1791 searchAction
->setWhatsThis(xi18nc("@info:whatsthis find",
1792 "<para>This helps you "
1793 "find files and folders by opening a <emphasis>search bar</emphasis>. "
1794 "There you can enter search terms and specify settings to find the "
1795 "items you are looking for.</para><para>Use this help again on "
1796 "the search bar so we can have a look at it while the settings are "
1797 "explained.</para>"));
1799 // toggle_search acts as a copy of the main searchAction to be used mainly
1800 // in the toolbar, with no default shortcut attached, to avoid messing with
1801 // existing workflows (search bar always open and Ctrl-F to focus)
1802 QAction
*toggleSearchAction
= actionCollection()->addAction(QStringLiteral("toggle_search"));
1803 toggleSearchAction
->setText(i18nc("@action:inmenu", "Toggle Search Bar"));
1804 toggleSearchAction
->setIconText(i18nc("@action:intoolbar", "Search"));
1805 toggleSearchAction
->setIcon(searchAction
->icon());
1806 toggleSearchAction
->setToolTip(searchAction
->toolTip());
1807 toggleSearchAction
->setWhatsThis(searchAction
->whatsThis());
1808 toggleSearchAction
->setCheckable(true);
1810 QAction
*toggleSelectionModeAction
= actionCollection()->addAction(QStringLiteral("toggle_selection_mode"));
1811 // i18n: This action toggles a selection mode.
1812 toggleSelectionModeAction
->setText(i18nc("@action:inmenu", "Select Files and Folders"));
1813 // i18n: Opens a selection mode for selecting files/folders.
1814 // The text is kept so unspecific because it will be shown on the toolbar where space is at a premium.
1815 toggleSelectionModeAction
->setIconText(i18nc("@action:intoolbar", "Select"));
1816 toggleSelectionModeAction
->setWhatsThis(xi18nc(
1818 "<para>This application only knows which files or folders should be acted on if they are"
1819 " <emphasis>selected</emphasis> first. Press this to toggle a <emphasis>Selection Mode</emphasis> which makes selecting and deselecting as easy as "
1820 "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."
1822 toggleSelectionModeAction
->setIcon(QIcon::fromTheme(QStringLiteral("quickwizard")));
1823 toggleSelectionModeAction
->setCheckable(true);
1824 actionCollection()->setDefaultShortcut(toggleSelectionModeAction
, Qt::Key_Space
);
1825 connect(toggleSelectionModeAction
, &QAction::triggered
, this, &DolphinMainWindow::toggleSelectionMode
);
1827 // A special version of the toggleSelectionModeAction for the toolbar that also contains a menu
1828 // with the selectAllAction and invertSelectionAction.
1829 auto *toggleSelectionModeToolBarAction
=
1830 new KToolBarPopupAction(toggleSelectionModeAction
->icon(), toggleSelectionModeAction
->iconText(), actionCollection());
1831 toggleSelectionModeToolBarAction
->setToolTip(toggleSelectionModeAction
->text());
1832 toggleSelectionModeToolBarAction
->setWhatsThis(toggleSelectionModeAction
->whatsThis());
1833 actionCollection()->addAction(QStringLiteral("toggle_selection_mode_tool_bar"), toggleSelectionModeToolBarAction
);
1834 toggleSelectionModeToolBarAction
->setCheckable(true);
1835 toggleSelectionModeToolBarAction
->setPopupMode(KToolBarPopupAction::DelayedPopup
);
1836 connect(toggleSelectionModeToolBarAction
, &QAction::triggered
, toggleSelectionModeAction
, &QAction::trigger
);
1837 connect(toggleSelectionModeAction
, &QAction::toggled
, toggleSelectionModeToolBarAction
, &QAction::setChecked
);
1839 QAction
*selectAllAction
= KStandardAction::selectAll(this, &DolphinMainWindow::selectAll
, actionCollection());
1840 selectAllAction
->setWhatsThis(xi18nc("@info:whatsthis",
1842 "files and folders in the current location."));
1844 QAction
*invertSelection
= actionCollection()->addAction(QStringLiteral("invert_selection"));
1845 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1846 invertSelection
->setWhatsThis(xi18nc("@info:whatsthis invert",
1848 "items that you have currently <emphasis>not</emphasis> selected instead."));
1849 invertSelection
->setIcon(QIcon::fromTheme(QStringLiteral("edit-select-invert")));
1850 actionCollection()->setDefaultShortcut(invertSelection
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
1851 connect(invertSelection
, &QAction::triggered
, this, &DolphinMainWindow::invertSelection
);
1853 QMenu
*toggleSelectionModeActionMenu
= new QMenu(this);
1854 toggleSelectionModeActionMenu
->addAction(selectAllAction
);
1855 toggleSelectionModeActionMenu
->addAction(invertSelection
);
1856 toggleSelectionModeToolBarAction
->setMenu(toggleSelectionModeActionMenu
);
1858 // setup 'View' menu
1859 // (note that most of it is set up in DolphinViewActionHandler)
1861 m_splitViewAction
= actionCollection()->add
<KActionMenu
>(QStringLiteral("split_view"));
1862 m_splitViewMenuAction
= actionCollection()->addAction(QStringLiteral("split_view_menu"));
1864 m_splitViewAction
->setWhatsThis(xi18nc("@info:whatsthis split",
1865 "<para>This presents "
1866 "a second view side-by-side with the current view, so you can see "
1867 "the contents of two folders at once and easily move items between "
1868 "them.</para><para>The view that is not \"in focus\" will be dimmed. "
1869 "</para>Click this button again to close one of the views."));
1870 m_splitViewMenuAction
->setWhatsThis(m_splitViewAction
->whatsThis());
1872 // only set it for the menu version
1873 actionCollection()->setDefaultShortcut(m_splitViewMenuAction
, Qt::Key_F3
);
1875 connect(m_splitViewAction
, &QAction::triggered
, this, &DolphinMainWindow::toggleSplitView
);
1876 connect(m_splitViewMenuAction
, &QAction::triggered
, this, &DolphinMainWindow::toggleSplitView
);
1878 QAction
*popoutSplit
= actionCollection()->addAction(QStringLiteral("popout_split_view"));
1879 popoutSplit
->setWhatsThis(xi18nc("@info:whatsthis",
1880 "If the view has been split, this will pop the view in focus "
1881 "out into a new window."));
1882 popoutSplit
->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
1883 actionCollection()->setDefaultShortcut(popoutSplit
, Qt::SHIFT
| Qt::Key_F3
);
1884 connect(popoutSplit
, &QAction::triggered
, this, &DolphinMainWindow::popoutSplitView
);
1886 QAction
*stashSplit
= actionCollection()->addAction(QStringLiteral("split_stash"));
1887 actionCollection()->setDefaultShortcut(stashSplit
, Qt::CTRL
| Qt::Key_S
);
1888 stashSplit
->setText(i18nc("@action:intoolbar Stash", "Stash"));
1889 stashSplit
->setToolTip(i18nc("@info", "Opens the stash virtual directory in a split window"));
1890 stashSplit
->setIcon(QIcon::fromTheme(QStringLiteral("folder-stash")));
1891 stashSplit
->setCheckable(false);
1892 QDBusConnectionInterface
*sessionInterface
= QDBusConnection::sessionBus().interface();
1893 stashSplit
->setVisible(sessionInterface
&& sessionInterface
->isServiceRegistered(QStringLiteral("org.kde.kio.StashNotifier")));
1894 connect(stashSplit
, &QAction::triggered
, this, &DolphinMainWindow::toggleSplitStash
);
1896 QAction
*redisplay
= KStandardAction::redisplay(this, &DolphinMainWindow::reloadView
, actionCollection());
1897 redisplay
->setToolTip(i18nc("@info:tooltip", "Refresh view"));
1898 redisplay
->setWhatsThis(xi18nc("@info:whatsthis refresh",
1899 "<para>This refreshes "
1900 "the folder view.</para>"
1901 "<para>If the contents of this folder have changed, refreshing will re-scan this folder "
1902 "and show you a newly-updated view of the files and folders contained here.</para>"
1903 "<para>If the view is split, this refreshes the one that is currently in focus.</para>"));
1905 QAction
*stop
= actionCollection()->addAction(QStringLiteral("stop"));
1906 stop
->setText(i18nc("@action:inmenu View", "Stop"));
1907 stop
->setToolTip(i18nc("@info", "Stop loading"));
1908 stop
->setWhatsThis(i18nc("@info", "This stops the loading of the contents of the current folder."));
1909 stop
->setIcon(QIcon::fromTheme(QStringLiteral("process-stop")));
1910 connect(stop
, &QAction::triggered
, this, &DolphinMainWindow::stopLoading
);
1912 KToggleAction
*editableLocation
= actionCollection()->add
<KToggleAction
>(QStringLiteral("editable_location"));
1913 editableLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1914 editableLocation
->setWhatsThis(xi18nc("@info:whatsthis",
1915 "This toggles the <emphasis>Location Bar</emphasis> to be "
1916 "editable so you can directly enter a location you want to go to.<nl/>"
1917 "You can also switch to editing by clicking to the right of the "
1918 "location and switch back by confirming the edited location."));
1919 actionCollection()->setDefaultShortcut(editableLocation
, Qt::Key_F6
);
1920 connect(editableLocation
, &KToggleAction::triggered
, this, &DolphinMainWindow::toggleEditLocation
);
1922 QAction
*replaceLocation
= actionCollection()->addAction(QStringLiteral("replace_location"));
1923 replaceLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1924 // i18n: "enter" is used both in the meaning of "writing" and "going to" a new location here.
1925 // Both meanings are useful but not necessary to understand the use of "Replace Location".
1926 // So you might want to be more verbose in your language to convey the meaning but it's up to you.
1927 replaceLocation
->setWhatsThis(xi18nc("@info:whatsthis",
1928 "This switches to editing the location and selects it "
1929 "so you can quickly enter a different location."));
1930 actionCollection()->setDefaultShortcuts(replaceLocation
, {Qt::CTRL
| Qt::Key_L
, Qt::ALT
| Qt::Key_D
});
1931 connect(replaceLocation
, &QAction::triggered
, this, &DolphinMainWindow::replaceLocation
);
1935 QScopedPointer
<QAction
> backAction(KStandardAction::back(nullptr, nullptr, nullptr));
1936 m_backAction
= new KToolBarPopupAction(backAction
->icon(), backAction
->text(), actionCollection());
1937 m_backAction
->setObjectName(backAction
->objectName());
1938 m_backAction
->setShortcuts(backAction
->shortcuts());
1940 m_backAction
->setPopupMode(KToolBarPopupAction::DelayedPopup
);
1941 connect(m_backAction
, &QAction::triggered
, this, &DolphinMainWindow::goBack
);
1942 connect(m_backAction
->popupMenu(), &QMenu::aboutToShow
, this, &DolphinMainWindow::slotAboutToShowBackPopupMenu
);
1943 connect(m_backAction
->popupMenu(), &QMenu::triggered
, this, &DolphinMainWindow::slotGoBack
);
1944 actionCollection()->addAction(m_backAction
->objectName(), m_backAction
);
1946 auto backShortcuts
= m_backAction
->shortcuts();
1947 // Prepend this shortcut, to avoid being hidden by the two-slot UI (#371130)
1948 backShortcuts
.prepend(QKeySequence(Qt::Key_Backspace
));
1949 actionCollection()->setDefaultShortcuts(m_backAction
, backShortcuts
);
1951 DolphinRecentTabsMenu
*recentTabsMenu
= new DolphinRecentTabsMenu(this);
1952 actionCollection()->addAction(QStringLiteral("closed_tabs"), recentTabsMenu
);
1953 connect(m_tabWidget
, &DolphinTabWidget::rememberClosedTab
, recentTabsMenu
, &DolphinRecentTabsMenu::rememberClosedTab
);
1954 connect(recentTabsMenu
, &DolphinRecentTabsMenu::restoreClosedTab
, m_tabWidget
, &DolphinTabWidget::restoreClosedTab
);
1955 connect(recentTabsMenu
, &DolphinRecentTabsMenu::closedTabsCountChanged
, this, &DolphinMainWindow::closedTabsCountChanged
);
1957 QAction
*undoCloseTab
= actionCollection()->addAction(QStringLiteral("undo_close_tab"));
1958 undoCloseTab
->setText(i18nc("@action:inmenu File", "Undo close tab"));
1959 undoCloseTab
->setWhatsThis(i18nc("@info:whatsthis undo close tab", "This returns you to the previously closed tab."));
1960 actionCollection()->setDefaultShortcut(undoCloseTab
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_T
);
1961 undoCloseTab
->setIcon(QIcon::fromTheme(QStringLiteral("edit-undo")));
1962 undoCloseTab
->setEnabled(false);
1963 connect(undoCloseTab
, &QAction::triggered
, recentTabsMenu
, &DolphinRecentTabsMenu::undoCloseTab
);
1965 auto undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
1966 undoAction
->setWhatsThis(xi18nc("@info:whatsthis",
1968 "the last change you made to files or folders.<nl/>"
1969 "Such changes include <interface>creating</interface>, <interface>renaming</interface> "
1970 "and <interface>moving</interface> them to a different location "
1971 "or to the <filename>Trash</filename>. <nl/>Any changes that cannot be undone "
1972 "will ask for your confirmation beforehand."));
1973 undoAction
->setEnabled(false); // undo should be disabled by default
1976 QScopedPointer
<QAction
> forwardAction(KStandardAction::forward(nullptr, nullptr, nullptr));
1977 m_forwardAction
= new KToolBarPopupAction(forwardAction
->icon(), forwardAction
->text(), actionCollection());
1978 m_forwardAction
->setObjectName(forwardAction
->objectName());
1979 m_forwardAction
->setShortcuts(forwardAction
->shortcuts());
1981 m_forwardAction
->setPopupMode(KToolBarPopupAction::DelayedPopup
);
1982 connect(m_forwardAction
, &QAction::triggered
, this, &DolphinMainWindow::goForward
);
1983 connect(m_forwardAction
->popupMenu(), &QMenu::aboutToShow
, this, &DolphinMainWindow::slotAboutToShowForwardPopupMenu
);
1984 connect(m_forwardAction
->popupMenu(), &QMenu::triggered
, this, &DolphinMainWindow::slotGoForward
);
1985 actionCollection()->addAction(m_forwardAction
->objectName(), m_forwardAction
);
1986 actionCollection()->setDefaultShortcuts(m_forwardAction
, m_forwardAction
->shortcuts());
1988 // enable middle-click to open in a new tab
1989 auto *middleClickEventFilter
= new MiddleClickActionEventFilter(this);
1990 connect(middleClickEventFilter
, &MiddleClickActionEventFilter::actionMiddleClicked
, this, &DolphinMainWindow::slotBackForwardActionMiddleClicked
);
1991 m_backAction
->popupMenu()->installEventFilter(middleClickEventFilter
);
1992 m_forwardAction
->popupMenu()->installEventFilter(middleClickEventFilter
);
1993 KStandardAction::up(this, &DolphinMainWindow::goUp
, actionCollection());
1994 QAction
*homeAction
= KStandardAction::home(this, &DolphinMainWindow::goHome
, actionCollection());
1995 homeAction
->setWhatsThis(xi18nc("@info:whatsthis",
1997 "<filename>Home</filename> folder.<nl/>Every user account "
1998 "has their own <filename>Home</filename> that contains their personal files, "
1999 "as well as hidden folders for their applications' data and configuration files."));
2001 // setup 'Tools' menu
2002 QAction
*compareFiles
= actionCollection()->addAction(QStringLiteral("compare_files"));
2003 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
2004 compareFiles
->setIcon(QIcon::fromTheme(QStringLiteral("kompare")));
2005 compareFiles
->setEnabled(false);
2006 connect(compareFiles
, &QAction::triggered
, this, &DolphinMainWindow::compareFiles
);
2008 QAction
*openPreferredSearchTool
= actionCollection()->addAction(QStringLiteral("open_preferred_search_tool"));
2009 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool"));
2010 openPreferredSearchTool
->setWhatsThis(xi18nc("@info:whatsthis",
2011 "<para>This opens a preferred search tool for the viewed location.</para>"
2012 "<para>Use <emphasis>More Search Tools</emphasis> menu to configure it.</para>"));
2013 openPreferredSearchTool
->setIcon(QIcon::fromTheme(QStringLiteral("search")));
2014 actionCollection()->setDefaultShortcut(openPreferredSearchTool
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_F
);
2015 connect(openPreferredSearchTool
, &QAction::triggered
, this, &DolphinMainWindow::openPreferredSearchTool
);
2017 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
2018 QAction
*openTerminal
= actionCollection()->addAction(QStringLiteral("open_terminal"));
2019 openTerminal
->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
2020 openTerminal
->setWhatsThis(xi18nc("@info:whatsthis",
2021 "<para>This opens a <emphasis>terminal</emphasis> application for the viewed location.</para>"
2022 "<para>To learn more about terminals use the help features in the terminal application.</para>"));
2023 openTerminal
->setIcon(QIcon::fromTheme(QStringLiteral("utilities-terminal")));
2024 actionCollection()->setDefaultShortcut(openTerminal
, Qt::SHIFT
| Qt::Key_F4
);
2025 connect(openTerminal
, &QAction::triggered
, this, &DolphinMainWindow::openTerminal
);
2027 QAction
*openTerminalHere
= actionCollection()->addAction(QStringLiteral("open_terminal_here"));
2028 // i18n: "Here" refers to the location(s) of the currently selected item(s) or the currently viewed location if nothing is selected.
2029 openTerminalHere
->setText(i18nc("@action:inmenu Tools", "Open Terminal Here"));
2030 openTerminalHere
->setWhatsThis(xi18nc("@info:whatsthis",
2031 "<para>This opens <emphasis>terminal</emphasis> applications for the selected items' locations.</para>"
2032 "<para>To learn more about terminals use the help features in the terminal application.</para>"));
2033 openTerminalHere
->setIcon(QIcon::fromTheme(QStringLiteral("utilities-terminal")));
2034 actionCollection()->setDefaultShortcut(openTerminalHere
, Qt::SHIFT
| Qt::ALT
| Qt::Key_F4
);
2035 connect(openTerminalHere
, &QAction::triggered
, this, &DolphinMainWindow::openTerminalHere
);
2038 QAction
*focusTerminalPanel
= actionCollection()->addAction(QStringLiteral("focus_terminal_panel"));
2039 focusTerminalPanel
->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
2040 focusTerminalPanel
->setIcon(QIcon::fromTheme(QStringLiteral("swap-panels")));
2041 actionCollection()->setDefaultShortcut(focusTerminalPanel
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_F4
);
2042 connect(focusTerminalPanel
, &QAction::triggered
, this, &DolphinMainWindow::focusTerminalPanel
);
2046 // setup 'Bookmarks' menu
2047 KActionMenu
*bookmarkMenu
= new KActionMenu(i18nc("@title:menu", "&Bookmarks"), this);
2048 bookmarkMenu
->setIcon(QIcon::fromTheme(QStringLiteral("bookmarks")));
2049 // Make the toolbar button version work properly on click
2050 bookmarkMenu
->setPopupMode(QToolButton::InstantPopup
);
2051 m_bookmarkHandler
= new DolphinBookmarkHandler(this, actionCollection(), bookmarkMenu
->menu(), this);
2052 actionCollection()->addAction(QStringLiteral("bookmarks"), bookmarkMenu
);
2054 // setup 'Settings' menu
2055 KToggleAction
*showMenuBar
= KStandardAction::showMenubar(nullptr, nullptr, actionCollection());
2056 showMenuBar
->setWhatsThis(xi18nc("@info:whatsthis",
2057 "<para>This switches between having a <emphasis>Menubar</emphasis> "
2058 "and having an <interface>%1</interface> button. Both "
2059 "contain mostly the same actions and configuration options.</para>"
2060 "<para>The Menubar takes up more space but allows for fast and organized access to all "
2061 "actions an application has to offer.</para><para>The %1 button "
2062 "is simpler and small which makes triggering advanced actions more time consuming.</para>",
2063 hamburgerMenuAction
->text().replace('&', "")));
2064 connect(showMenuBar
,
2065 &KToggleAction::triggered
, // Fixes #286822
2067 &DolphinMainWindow::toggleShowMenuBar
,
2068 Qt::QueuedConnection
);
2070 KToggleAction
*showStatusBar
= KStandardAction::showStatusbar(nullptr, nullptr, actionCollection());
2071 showStatusBar
->setChecked(GeneralSettings::showStatusBar());
2072 connect(GeneralSettings::self(), &GeneralSettings::showStatusBarChanged
, showStatusBar
, &KToggleAction::setChecked
);
2073 connect(showStatusBar
, &KToggleAction::triggered
, this, [this](bool checked
) {
2074 GeneralSettings::setShowStatusBar(checked
);
2078 KStandardAction::keyBindings(this, &DolphinMainWindow::slotKeyBindings
, actionCollection());
2079 KStandardAction::preferences(this, &DolphinMainWindow::editSettings
, actionCollection());
2081 // not in menu actions
2082 QList
<QKeySequence
> nextTabKeys
= KStandardShortcut::tabNext();
2083 nextTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::Key_Tab
));
2085 QList
<QKeySequence
> prevTabKeys
= KStandardShortcut::tabPrev();
2086 prevTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::SHIFT
| Qt::Key_Tab
));
2088 for (int i
= 0; i
< MaxActivateTabShortcuts
; ++i
) {
2089 QAction
*activateTab
= actionCollection()->addAction(QStringLiteral("activate_tab_%1").arg(i
));
2090 activateTab
->setText(i18nc("@action:inmenu", "Go to Tab %1", i
+ 1));
2091 activateTab
->setEnabled(false);
2092 connect(activateTab
, &QAction::triggered
, this, [this, i
]() {
2093 m_tabWidget
->activateTab(i
);
2096 // only add default shortcuts for the first 9 tabs regardless of MaxActivateTabShortcuts
2098 actionCollection()->setDefaultShortcut(activateTab
, QStringLiteral("Alt+%1").arg(i
+ 1));
2102 QAction
*activateLastTab
= actionCollection()->addAction(QStringLiteral("activate_last_tab"));
2103 activateLastTab
->setIconText(i18nc("@action:inmenu", "Last Tab"));
2104 activateLastTab
->setText(i18nc("@action:inmenu", "Go to Last Tab"));
2105 activateLastTab
->setEnabled(false);
2106 connect(activateLastTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activateLastTab
);
2107 actionCollection()->setDefaultShortcut(activateLastTab
, Qt::ALT
| Qt::Key_0
);
2109 QAction
*activateNextTab
= actionCollection()->addAction(QStringLiteral("activate_next_tab"));
2110 activateNextTab
->setIconText(i18nc("@action:inmenu", "Next Tab"));
2111 activateNextTab
->setText(i18nc("@action:inmenu", "Go to Next Tab"));
2112 activateNextTab
->setEnabled(false);
2113 connect(activateNextTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activateNextTab
);
2114 actionCollection()->setDefaultShortcuts(activateNextTab
, nextTabKeys
);
2116 QAction
*activatePrevTab
= actionCollection()->addAction(QStringLiteral("activate_prev_tab"));
2117 activatePrevTab
->setIconText(i18nc("@action:inmenu", "Previous Tab"));
2118 activatePrevTab
->setText(i18nc("@action:inmenu", "Go to Previous Tab"));
2119 activatePrevTab
->setEnabled(false);
2120 connect(activatePrevTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activatePrevTab
);
2121 actionCollection()->setDefaultShortcuts(activatePrevTab
, prevTabKeys
);
2124 QAction
*showTarget
= actionCollection()->addAction(QStringLiteral("show_target"));
2125 showTarget
->setText(i18nc("@action:inmenu", "Show Target"));
2126 showTarget
->setIcon(QIcon::fromTheme(QStringLiteral("document-open-folder")));
2127 showTarget
->setEnabled(false);
2128 connect(showTarget
, &QAction::triggered
, this, &DolphinMainWindow::showTarget
);
2130 QAction
*openInNewTab
= actionCollection()->addAction(QStringLiteral("open_in_new_tab"));
2131 openInNewTab
->setText(i18nc("@action:inmenu", "Open in New Tab"));
2132 openInNewTab
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
2133 connect(openInNewTab
, &QAction::triggered
, this, &DolphinMainWindow::openInNewTab
);
2135 QAction
*openInNewTabs
= actionCollection()->addAction(QStringLiteral("open_in_new_tabs"));
2136 openInNewTabs
->setText(i18nc("@action:inmenu", "Open in New Tabs"));
2137 openInNewTabs
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
2138 connect(openInNewTabs
, &QAction::triggered
, this, &DolphinMainWindow::openInNewTab
);
2140 QAction
*openInNewWindow
= actionCollection()->addAction(QStringLiteral("open_in_new_window"));
2141 openInNewWindow
->setText(i18nc("@action:inmenu", "Open in New Window"));
2142 openInNewWindow
->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
2143 connect(openInNewWindow
, &QAction::triggered
, this, &DolphinMainWindow::openInNewWindow
);
2145 QAction
*openInSplitViewAction
= actionCollection()->addAction(QStringLiteral("open_in_split_view"));
2146 openInSplitViewAction
->setText(i18nc("@action:inmenu", "Open in Split View"));
2147 openInSplitViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-right-new")));
2148 connect(openInSplitViewAction
, &QAction::triggered
, this, [this]() {
2149 openInSplitView(QUrl());
2153 void DolphinMainWindow::setupDockWidgets()
2155 const bool lock
= GeneralSettings::lockPanels();
2157 DolphinPlacesModelSingleton::instance().placesModel()->setPanelsLocked(lock
);
2159 KDualAction
*lockLayoutAction
= actionCollection()->add
<KDualAction
>(QStringLiteral("lock_panels"));
2160 lockLayoutAction
->setActiveText(i18nc("@action:inmenu Panels", "Unlock Panels"));
2161 lockLayoutAction
->setActiveIcon(QIcon::fromTheme(QStringLiteral("object-unlocked")));
2162 lockLayoutAction
->setInactiveText(i18nc("@action:inmenu Panels", "Lock Panels"));
2163 lockLayoutAction
->setInactiveIcon(QIcon::fromTheme(QStringLiteral("object-locked")));
2164 lockLayoutAction
->setWhatsThis(xi18nc("@info:whatsthis",
2166 "switches between having panels <emphasis>locked</emphasis> or "
2167 "<emphasis>unlocked</emphasis>.<nl/>Unlocked panels can be "
2168 "dragged to the other side of the window and have a close "
2169 "button.<nl/>Locked panels are embedded more cleanly."));
2170 lockLayoutAction
->setActive(lock
);
2171 connect(lockLayoutAction
, &KDualAction::triggered
, this, &DolphinMainWindow::togglePanelLockState
);
2173 // Setup "Information"
2174 DolphinDockWidget
*infoDock
= new DolphinDockWidget(i18nc("@title:window", "Information"));
2175 infoDock
->setLocked(lock
);
2176 infoDock
->setObjectName(QStringLiteral("infoDock"));
2177 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
2180 InformationPanel
*infoPanel
= new InformationPanel(infoDock
);
2181 infoPanel
->setCustomContextMenuActions({lockLayoutAction
});
2182 connect(infoPanel
, &InformationPanel::urlActivated
, this, &DolphinMainWindow::handleUrl
);
2183 infoDock
->setWidget(infoPanel
);
2185 createPanelAction(QIcon::fromTheme(QStringLiteral("dialog-information")), Qt::Key_F11
, infoDock
, QStringLiteral("show_information_panel"));
2187 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
2188 connect(this, &DolphinMainWindow::urlChanged
, infoPanel
, &InformationPanel::setUrl
);
2189 connect(this, &DolphinMainWindow::selectionChanged
, infoPanel
, &InformationPanel::setSelection
);
2190 connect(this, &DolphinMainWindow::requestItemInfo
, infoPanel
, &InformationPanel::requestDelayedItemInfo
);
2191 connect(this, &DolphinMainWindow::fileItemsChanged
, infoPanel
, &InformationPanel::slotFilesItemChanged
);
2192 connect(this, &DolphinMainWindow::settingsChanged
, infoPanel
, &InformationPanel::readSettings
);
2195 // i18n: This is the last paragraph for the "What's This"-texts of all four panels.
2196 const QString panelWhatsThis
= xi18nc("@info:whatsthis",
2198 "hide panels like this go to <interface>Menu|Panels</interface> "
2199 "or <interface>View|Panels</interface>.</para>");
2202 ->action(QStringLiteral("show_information_panel"))
2203 ->setWhatsThis(xi18nc("@info:whatsthis",
2204 "<para> This toggles the "
2205 "<emphasis>information</emphasis> panel at the right side of the "
2206 "window.</para><para>The panel provides in-depth information "
2207 "about the items your mouse is hovering over or about the selected "
2208 "items. Otherwise it informs you about the currently viewed folder.<nl/>"
2209 "For single items a preview of their contents is provided.</para>"));
2211 infoDock
->setWhatsThis(xi18nc("@info:whatsthis",
2213 "provides in-depth information about the items your mouse is "
2214 "hovering over or about the selected items. Otherwise it informs "
2215 "you about the currently viewed folder.<nl/>For single items a "
2216 "preview of their contents is provided.</para><para>You can configure "
2217 "which and how details are given here by right-clicking.</para>")
2221 DolphinDockWidget
*foldersDock
= new DolphinDockWidget(i18nc("@title:window", "Folders"));
2222 foldersDock
->setLocked(lock
);
2223 foldersDock
->setObjectName(QStringLiteral("foldersDock"));
2224 foldersDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
2225 FoldersPanel
*foldersPanel
= new FoldersPanel(foldersDock
);
2226 foldersPanel
->setCustomContextMenuActions({lockLayoutAction
});
2227 foldersDock
->setWidget(foldersPanel
);
2229 createPanelAction(QIcon::fromTheme(QStringLiteral("folder")), Qt::Key_F7
, foldersDock
, QStringLiteral("show_folders_panel"));
2231 addDockWidget(Qt::LeftDockWidgetArea
, foldersDock
);
2232 connect(this, &DolphinMainWindow::urlChanged
, foldersPanel
, &FoldersPanel::setUrl
);
2233 connect(foldersPanel
, &FoldersPanel::folderActivated
, this, &DolphinMainWindow::changeUrl
);
2234 connect(foldersPanel
, &FoldersPanel::folderInNewTab
, this, &DolphinMainWindow::openNewTab
);
2235 connect(foldersPanel
, &FoldersPanel::folderInNewActiveTab
, this, &DolphinMainWindow::openNewTabAndActivate
);
2236 connect(foldersPanel
, &FoldersPanel::errorMessage
, this, &DolphinMainWindow::showErrorMessage
);
2239 ->action(QStringLiteral("show_folders_panel"))
2240 ->setWhatsThis(xi18nc("@info:whatsthis",
2242 "<emphasis>folders</emphasis> panel at the left side of the window."
2243 "<nl/><nl/>It shows the folders of the <emphasis>file system"
2244 "</emphasis> in a <emphasis>tree view</emphasis>."));
2245 foldersDock
->setWhatsThis(xi18nc("@info:whatsthis",
2247 "shows the folders of the <emphasis>file system</emphasis> in a "
2248 "<emphasis>tree view</emphasis>.</para><para>Click a folder to go "
2249 "there. Click the arrow to the left of a folder to see its subfolders. "
2250 "This allows quick switching between any folders.</para>")
2255 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
2256 DolphinDockWidget
*terminalDock
= new DolphinDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
2257 terminalDock
->setLocked(lock
);
2258 terminalDock
->setObjectName(QStringLiteral("terminalDock"));
2259 terminalDock
->setContentsMargins(0, 0, 0, 0);
2260 m_terminalPanel
= new TerminalPanel(terminalDock
);
2261 m_terminalPanel
->setCustomContextMenuActions({lockLayoutAction
});
2262 terminalDock
->setWidget(m_terminalPanel
);
2264 connect(m_terminalPanel
, &TerminalPanel::hideTerminalPanel
, terminalDock
, &DolphinDockWidget::hide
);
2265 connect(m_terminalPanel
, &TerminalPanel::changeUrl
, this, &DolphinMainWindow::slotTerminalDirectoryChanged
);
2266 connect(terminalDock
, &DolphinDockWidget::visibilityChanged
, m_terminalPanel
, &TerminalPanel::dockVisibilityChanged
);
2267 connect(terminalDock
, &DolphinDockWidget::visibilityChanged
, this, &DolphinMainWindow::slotTerminalPanelVisibilityChanged
);
2269 createPanelAction(QIcon::fromTheme(QStringLiteral("dialog-scripts")), Qt::Key_F4
, terminalDock
, QStringLiteral("show_terminal_panel"));
2271 addDockWidget(Qt::BottomDockWidgetArea
, terminalDock
);
2272 connect(this, &DolphinMainWindow::urlChanged
, m_terminalPanel
, &TerminalPanel::setUrl
);
2274 if (GeneralSettings::version() < 200) {
2275 terminalDock
->hide();
2279 ->action(QStringLiteral("show_terminal_panel"))
2280 ->setWhatsThis(xi18nc("@info:whatsthis",
2281 "<para>This toggles the "
2282 "<emphasis>terminal</emphasis> panel at the bottom of the window."
2283 "<nl/>The location in the terminal will always match the folder "
2284 "view so you can navigate using either.</para><para>The terminal "
2285 "panel is not needed for basic computer usage but can be useful "
2286 "for advanced tasks. To learn more about terminals use the help features "
2287 "in a standalone terminal application like Konsole.</para>"));
2288 terminalDock
->setWhatsThis(xi18nc("@info:whatsthis",
2290 "the <emphasis>terminal</emphasis> panel. It behaves like a "
2291 "normal terminal but will match the location of the folder view "
2292 "so you can navigate using either.</para><para>The terminal panel "
2293 "is not needed for basic computer usage but can be useful for "
2294 "advanced tasks. To learn more about terminals use the help features in a "
2295 "standalone terminal application like Konsole.</para>")
2300 if (GeneralSettings::version() < 200) {
2302 foldersDock
->hide();
2306 DolphinDockWidget
*placesDock
= new DolphinDockWidget(i18nc("@title:window", "Places"));
2307 placesDock
->setLocked(lock
);
2308 placesDock
->setObjectName(QStringLiteral("placesDock"));
2309 placesDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
2311 m_placesPanel
= new PlacesPanel(placesDock
);
2312 m_placesPanel
->setCustomContextMenuActions({lockLayoutAction
});
2313 placesDock
->setWidget(m_placesPanel
);
2315 createPanelAction(QIcon::fromTheme(QStringLiteral("compass")), Qt::Key_F9
, placesDock
, QStringLiteral("show_places_panel"));
2317 addDockWidget(Qt::LeftDockWidgetArea
, placesDock
);
2318 connect(m_placesPanel
, &PlacesPanel::placeActivated
, this, &DolphinMainWindow::slotPlaceActivated
);
2319 connect(m_placesPanel
, &PlacesPanel::tabRequested
, this, &DolphinMainWindow::openNewTab
);
2320 connect(m_placesPanel
, &PlacesPanel::activeTabRequested
, this, &DolphinMainWindow::openNewTabAndActivate
);
2321 connect(m_placesPanel
, &PlacesPanel::newWindowRequested
, this, [this](const QUrl
&url
) {
2322 Dolphin::openNewWindow({url
}, this);
2324 connect(m_placesPanel
, &PlacesPanel::openInSplitViewRequested
, this, &DolphinMainWindow::openInSplitView
);
2325 connect(m_placesPanel
, &PlacesPanel::errorMessage
, this, &DolphinMainWindow::showErrorMessage
);
2326 connect(this, &DolphinMainWindow::urlChanged
, m_placesPanel
, &PlacesPanel::setUrl
);
2327 connect(placesDock
, &DolphinDockWidget::visibilityChanged
, &DolphinUrlNavigatorsController::slotPlacesPanelVisibilityChanged
);
2328 connect(this, &DolphinMainWindow::settingsChanged
, m_placesPanel
, &PlacesPanel::readSettings
);
2329 connect(m_placesPanel
, &PlacesPanel::storageTearDownRequested
, this, &DolphinMainWindow::slotStorageTearDownFromPlacesRequested
);
2330 connect(m_placesPanel
, &PlacesPanel::storageTearDownExternallyRequested
, this, &DolphinMainWindow::slotStorageTearDownExternallyRequested
);
2331 DolphinUrlNavigatorsController::slotPlacesPanelVisibilityChanged(m_placesPanel
->isVisible());
2333 auto actionShowAllPlaces
= new QAction(QIcon::fromTheme(QStringLiteral("view-hidden")), i18nc("@item:inmenu", "Show Hidden Places"), this);
2334 actionShowAllPlaces
->setCheckable(true);
2335 actionShowAllPlaces
->setDisabled(true);
2336 actionShowAllPlaces
->setWhatsThis(i18nc("@info:whatsthis",
2338 "all places in the places panel that have been hidden. They will "
2339 "appear semi-transparent and allow you to uncheck their \"Hide\" property."));
2341 connect(actionShowAllPlaces
, &QAction::triggered
, this, [this](bool checked
) {
2342 m_placesPanel
->setShowAll(checked
);
2344 connect(m_placesPanel
, &PlacesPanel::allPlacesShownChanged
, actionShowAllPlaces
, &QAction::setChecked
);
2347 ->action(QStringLiteral("show_places_panel"))
2348 ->setWhatsThis(xi18nc("@info:whatsthis",
2349 "<para>This toggles the "
2350 "<emphasis>places</emphasis> panel at the left side of the window."
2351 "</para><para>It allows you to go to locations you have "
2352 "bookmarked and to access disk or media attached to the computer "
2353 "or to the network. It also contains sections to find recently "
2354 "saved files or files of a certain type.</para>"));
2355 placesDock
->setWhatsThis(xi18nc("@info:whatsthis",
2356 "<para>This is the "
2357 "<emphasis>Places</emphasis> panel. It allows you to go to locations "
2358 "you have bookmarked and to access disk or media attached to the "
2359 "computer or to the network. It also contains sections to find "
2360 "recently saved files or files of a certain type.</para><para>"
2361 "Click on an entry to go there. Click with the right mouse button "
2362 "instead to open any entry in a new tab or new window.</para>"
2363 "<para>New entries can be added by dragging folders onto this panel. "
2364 "Right-click any section or entry to hide it. Right-click an empty "
2365 "space on this panel and select <interface>Show Hidden Places"
2366 "</interface> to display it again.</para>")
2369 // Add actions into the "Panels" menu
2370 KActionMenu
*panelsMenu
= new KActionMenu(i18nc("@action:inmenu View", "Show Panels"), this);
2371 actionCollection()->addAction(QStringLiteral("panels"), panelsMenu
);
2372 panelsMenu
->setIcon(QIcon::fromTheme(QStringLiteral("view-sidetree")));
2373 panelsMenu
->setPopupMode(QToolButton::InstantPopup
);
2374 const KActionCollection
*ac
= actionCollection();
2375 panelsMenu
->addAction(ac
->action(QStringLiteral("show_places_panel")));
2377 panelsMenu
->addAction(ac
->action(QStringLiteral("show_information_panel")));
2379 panelsMenu
->addAction(ac
->action(QStringLiteral("show_folders_panel")));
2380 panelsMenu
->addAction(ac
->action(QStringLiteral("show_terminal_panel")));
2381 panelsMenu
->addSeparator();
2382 panelsMenu
->addAction(actionShowAllPlaces
);
2383 panelsMenu
->addAction(lockLayoutAction
);
2385 connect(panelsMenu
->menu(), &QMenu::aboutToShow
, this, [actionShowAllPlaces
] {
2386 actionShowAllPlaces
->setEnabled(DolphinPlacesModelSingleton::instance().placesModel()->hiddenCount());
2390 void DolphinMainWindow::updateFileAndEditActions()
2392 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
2393 const KActionCollection
*col
= actionCollection();
2394 KFileItemListProperties
capabilitiesSource(list
);
2396 QAction
*renameAction
= col
->action(KStandardAction::name(KStandardAction::RenameFile
));
2397 QAction
*moveToTrashAction
= col
->action(KStandardAction::name(KStandardAction::MoveToTrash
));
2398 QAction
*deleteAction
= col
->action(KStandardAction::name(KStandardAction::DeleteFile
));
2399 QAction
*cutAction
= col
->action(KStandardAction::name(KStandardAction::Cut
));
2400 QAction
*duplicateAction
= col
->action(QStringLiteral("duplicate")); // see DolphinViewActionHandler
2401 QAction
*addToPlacesAction
= col
->action(QStringLiteral("add_to_places"));
2402 QAction
*copyToOtherViewAction
= col
->action(QStringLiteral("copy_to_inactive_split_view"));
2403 QAction
*moveToOtherViewAction
= col
->action(QStringLiteral("move_to_inactive_split_view"));
2404 QAction
*copyLocation
= col
->action(QString("copy_location"));
2406 if (list
.isEmpty()) {
2407 stateChanged(QStringLiteral("has_no_selection"));
2409 // All actions that need a selection to function can be enabled because they should trigger selection mode.
2410 renameAction
->setEnabled(true);
2411 moveToTrashAction
->setEnabled(true);
2412 deleteAction
->setEnabled(true);
2413 cutAction
->setEnabled(true);
2414 duplicateAction
->setEnabled(true);
2415 addToPlacesAction
->setEnabled(true);
2416 copyLocation
->setEnabled(true);
2417 // Them triggering selection mode and not directly acting on selected items is signified by adding "…" to their text.
2418 m_actionTextHelper
->textsWhenNothingIsSelectedEnabled(true);
2421 m_actionTextHelper
->textsWhenNothingIsSelectedEnabled(false);
2422 stateChanged(QStringLiteral("has_selection"));
2424 QAction
*deleteWithTrashShortcut
= col
->action(QStringLiteral("delete_shortcut")); // see DolphinViewActionHandler
2425 QAction
*showTarget
= col
->action(QStringLiteral("show_target"));
2427 if (list
.length() == 1 && list
.first().isDir()) {
2428 addToPlacesAction
->setEnabled(true);
2430 addToPlacesAction
->setEnabled(false);
2433 const bool enableMoveToTrash
= capabilitiesSource
.isLocal() && capabilitiesSource
.supportsMoving();
2435 renameAction
->setEnabled(capabilitiesSource
.supportsMoving());
2436 m_disabledActionNotifier
->setDisabledReason(renameAction
, i18nc("@info", "Cannot rename: You do not have permission to rename items in this folder."));
2437 deleteAction
->setEnabled(capabilitiesSource
.supportsDeleting());
2438 m_disabledActionNotifier
->setDisabledReason(deleteAction
,
2439 i18nc("@info", "Cannot delete: You do not have permission to remove items from this folder."));
2440 cutAction
->setEnabled(capabilitiesSource
.supportsMoving());
2441 m_disabledActionNotifier
->setDisabledReason(cutAction
, i18nc("@info", "Cannot cut: You do not have permission to move items from this folder."));
2442 copyLocation
->setEnabled(list
.length() == 1);
2443 showTarget
->setEnabled(list
.length() == 1 && list
.at(0).isLink());
2444 duplicateAction
->setEnabled(capabilitiesSource
.supportsWriting());
2445 m_disabledActionNotifier
->setDisabledReason(duplicateAction
,
2446 i18nc("@info", "Cannot duplicate here: You do not have permission to create items in this folder."));
2448 if (enableMoveToTrash
) {
2449 moveToTrashAction
->setEnabled(true);
2450 deleteWithTrashShortcut
->setEnabled(false);
2451 m_disabledActionNotifier
->clearDisabledReason(deleteWithTrashShortcut
);
2453 moveToTrashAction
->setEnabled(false);
2454 deleteWithTrashShortcut
->setEnabled(capabilitiesSource
.supportsDeleting());
2455 m_disabledActionNotifier
->setDisabledReason(deleteWithTrashShortcut
,
2456 i18nc("@info", "Cannot delete: You do not have permission to remove items from this folder."));
2460 if (!m_tabWidget
->currentTabPage()->splitViewEnabled()) {
2461 // No need to set the disabled reason here, as it's obvious to the user that the reason is the split view being disabled.
2462 copyToOtherViewAction
->setEnabled(false);
2463 m_disabledActionNotifier
->clearDisabledReason(copyToOtherViewAction
);
2464 moveToOtherViewAction
->setEnabled(false);
2465 m_disabledActionNotifier
->clearDisabledReason(moveToOtherViewAction
);
2466 } else if (list
.isEmpty()) {
2467 copyToOtherViewAction
->setEnabled(false);
2468 m_disabledActionNotifier
->setDisabledReason(copyToOtherViewAction
, i18nc("@info", "Cannot copy to other view: No files selected."));
2469 moveToOtherViewAction
->setEnabled(false);
2470 m_disabledActionNotifier
->setDisabledReason(moveToOtherViewAction
, i18nc("@info", "Cannot move to other view: No files selected."));
2472 DolphinTabPage
*tabPage
= m_tabWidget
->currentTabPage();
2473 KFileItem capabilitiesDestination
;
2475 if (tabPage
->primaryViewActive()) {
2476 capabilitiesDestination
= tabPage
->secondaryViewContainer()->rootItem();
2478 capabilitiesDestination
= tabPage
->primaryViewContainer()->rootItem();
2481 const auto destUrl
= capabilitiesDestination
.url();
2482 const bool allNotTargetOrigin
= std::all_of(list
.cbegin(), list
.cend(), [destUrl
](const KFileItem
&item
) {
2483 return item
.url().adjusted(QUrl::RemoveFilename
| QUrl::StripTrailingSlash
) != destUrl
;
2486 if (!allNotTargetOrigin
) {
2487 copyToOtherViewAction
->setEnabled(false);
2488 m_disabledActionNotifier
->setDisabledReason(copyToOtherViewAction
,
2489 i18nc("@info", "Cannot copy to other view: The other view already contains these items."));
2490 moveToOtherViewAction
->setEnabled(false);
2491 m_disabledActionNotifier
->setDisabledReason(moveToOtherViewAction
,
2492 i18nc("@info", "Cannot move to other view: The other view already contains these items."));
2493 } else if (!capabilitiesDestination
.isWritable()) {
2494 copyToOtherViewAction
->setEnabled(false);
2495 m_disabledActionNotifier
->setDisabledReason(
2496 copyToOtherViewAction
,
2497 i18nc("@info", "Cannot copy to other view: You do not have permission to write into the destination folder."));
2498 moveToOtherViewAction
->setEnabled(false);
2499 m_disabledActionNotifier
->setDisabledReason(
2500 moveToOtherViewAction
,
2501 i18nc("@info", "Cannot move to other view: You do not have permission to write into the destination folder."));
2503 copyToOtherViewAction
->setEnabled(true);
2504 moveToOtherViewAction
->setEnabled(capabilitiesSource
.supportsMoving());
2505 m_disabledActionNotifier
->setDisabledReason(
2506 moveToOtherViewAction
,
2507 i18nc("@info", "Cannot move to other view: You do not have permission to move items from this folder."));
2512 void DolphinMainWindow::updateViewActions()
2514 m_actionHandler
->updateViewActions();
2516 QAction
*toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
2517 toggleFilterBarAction
->setChecked(m_activeViewContainer
->isFilterBarVisible());
2519 updateSplitActions();
2522 void DolphinMainWindow::updateGoActions()
2524 QAction
*goUpAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Up
));
2525 const QUrl currentUrl
= m_activeViewContainer
->url();
2526 // I think this is one of the best places to firstly be confronted
2527 // with a file system and its hierarchy. Talking about the root
2528 // directory might seem too much here but it is the question that
2529 // naturally arises in this context.
2530 goUpAction
->setWhatsThis(xi18nc("@info:whatsthis",
2532 "the folder that contains the currently viewed one.</para>"
2533 "<para>All files and folders are organized in a hierarchical "
2534 "<emphasis>file system</emphasis>. At the top of this hierarchy is "
2535 "a directory that contains all data connected to this computer"
2536 "—the <emphasis>root directory</emphasis>.</para>"));
2537 goUpAction
->setEnabled(KIO::upUrl(currentUrl
) != currentUrl
);
2540 void DolphinMainWindow::refreshViews()
2542 m_tabWidget
->refreshViews();
2544 if (GeneralSettings::modifiedStartupSettings()) {
2545 updateWindowTitle();
2548 updateSplitActions();
2550 Q_EMIT
settingsChanged();
2553 void DolphinMainWindow::clearStatusBar()
2555 m_activeViewContainer
->statusBar()->resetToDefaultText();
2558 void DolphinMainWindow::connectViewSignals(DolphinViewContainer
*container
)
2560 connect(container
, &DolphinViewContainer::showFilterBarChanged
, this, &DolphinMainWindow::updateFilterBarAction
);
2561 connect(container
, &DolphinViewContainer::writeStateChanged
, this, &DolphinMainWindow::slotWriteStateChanged
);
2562 slotWriteStateChanged(container
->view()->isFolderWritable());
2563 connect(container
, &DolphinViewContainer::searchModeEnabledChanged
, this, &DolphinMainWindow::updateSearchAction
);
2564 connect(container
, &DolphinViewContainer::captionChanged
, this, &DolphinMainWindow::updateWindowTitle
);
2565 connect(container
, &DolphinViewContainer::tabRequested
, this, &DolphinMainWindow::openNewTab
);
2566 connect(container
, &DolphinViewContainer::activeTabRequested
, this, &DolphinMainWindow::openNewTabAndActivate
);
2568 const QAction
*toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
2569 connect(toggleSearchAction
, &QAction::triggered
, container
, &DolphinViewContainer::setSearchModeEnabled
);
2571 // Make the toggled state of the selection mode actions visually follow the selection mode state of the view.
2572 auto toggleSelectionModeAction
= actionCollection()->action(QStringLiteral("toggle_selection_mode"));
2573 toggleSelectionModeAction
->setChecked(m_activeViewContainer
->isSelectionModeEnabled());
2574 connect(m_activeViewContainer
, &DolphinViewContainer::selectionModeChanged
, toggleSelectionModeAction
, &QAction::setChecked
);
2576 const DolphinView
*view
= container
->view();
2577 connect(view
, &DolphinView::selectionChanged
, this, &DolphinMainWindow::slotSelectionChanged
);
2578 connect(view
, &DolphinView::requestItemInfo
, this, &DolphinMainWindow::requestItemInfo
);
2579 connect(view
, &DolphinView::fileItemsChanged
, this, &DolphinMainWindow::fileItemsChanged
);
2580 connect(view
, &DolphinView::tabRequested
, this, &DolphinMainWindow::openNewTab
);
2581 connect(view
, &DolphinView::activeTabRequested
, this, &DolphinMainWindow::openNewTabAndActivate
);
2582 connect(view
, &DolphinView::windowRequested
, this, &DolphinMainWindow::openNewWindow
);
2583 connect(view
, &DolphinView::requestContextMenu
, this, &DolphinMainWindow::openContextMenu
);
2584 connect(view
, &DolphinView::directoryLoadingStarted
, this, &DolphinMainWindow::enableStopAction
);
2585 connect(view
, &DolphinView::directoryLoadingCompleted
, this, &DolphinMainWindow::disableStopAction
);
2586 connect(view
, &DolphinView::directoryLoadingCompleted
, this, &DolphinMainWindow::slotDirectoryLoadingCompleted
);
2587 connect(view
, &DolphinView::goBackRequested
, this, &DolphinMainWindow::goBack
);
2588 connect(view
, &DolphinView::goForwardRequested
, this, &DolphinMainWindow::goForward
);
2589 connect(view
, &DolphinView::urlActivated
, this, &DolphinMainWindow::handleUrl
);
2590 connect(view
, &DolphinView::goUpRequested
, this, &DolphinMainWindow::goUp
);
2591 connect(view
, &DolphinView::doubleClickViewBackground
, this, &DolphinMainWindow::slotDoubleClickViewBackground
);
2593 connect(container
->urlNavigatorInternalWithHistory(), &KUrlNavigator::urlChanged
, this, &DolphinMainWindow::changeUrl
);
2594 connect(container
->urlNavigatorInternalWithHistory(), &KUrlNavigator::historyChanged
, this, &DolphinMainWindow::updateHistory
);
2596 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>(actionCollection()->action(QStringLiteral("url_navigators")));
2597 const KUrlNavigator
*navigator
=
2598 m_tabWidget
->currentTabPage()->primaryViewActive() ? navigators
->primaryUrlNavigator() : navigators
->secondaryUrlNavigator();
2600 QAction
*editableLocactionAction
= actionCollection()->action(QStringLiteral("editable_location"));
2601 editableLocactionAction
->setChecked(navigator
->isUrlEditable());
2602 connect(navigator
, &KUrlNavigator::editableStateChanged
, this, &DolphinMainWindow::slotEditableStateChanged
);
2603 connect(navigator
, &KUrlNavigator::tabRequested
, this, &DolphinMainWindow::openNewTab
);
2604 connect(navigator
, &KUrlNavigator::activeTabRequested
, this, &DolphinMainWindow::openNewTabAndActivate
);
2605 connect(navigator
, &KUrlNavigator::newWindowRequested
, this, &DolphinMainWindow::openNewWindow
);
2608 void DolphinMainWindow::updateSplitActions()
2610 QAction
*popoutSplitAction
= actionCollection()->action(QStringLiteral("popout_split_view"));
2612 auto setActionPopupMode
= [this](KActionMenu
*action
, QToolButton::ToolButtonPopupMode popupMode
) {
2613 action
->setPopupMode(popupMode
);
2614 if (auto *buttonForAction
= qobject_cast
<QToolButton
*>(toolBar()->widgetForAction(action
))) {
2615 buttonForAction
->setPopupMode(popupMode
);
2619 const DolphinTabPage
*tabPage
= m_tabWidget
->currentTabPage();
2620 if (tabPage
->splitViewEnabled()) {
2621 if (GeneralSettings::closeActiveSplitView() ? tabPage
->primaryViewActive() : !tabPage
->primaryViewActive()) {
2622 m_splitViewAction
->setText(i18nc("@action:intoolbar Close left view", "Close"));
2623 m_splitViewAction
->setToolTip(i18nc("@info", "Close left view"));
2624 m_splitViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-left-close")));
2625 popoutSplitAction
->setText(i18nc("@action:intoolbar Move left view to a new window", "Pop out Left View"));
2626 popoutSplitAction
->setToolTip(i18nc("@info", "Move left view to a new window"));
2628 m_splitViewAction
->setText(i18nc("@action:intoolbar Close right view", "Close"));
2629 m_splitViewAction
->setToolTip(i18nc("@info", "Close right view"));
2630 m_splitViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-right-close")));
2631 popoutSplitAction
->setText(i18nc("@action:intoolbar Move right view to a new window", "Pop out Right View"));
2632 popoutSplitAction
->setToolTip(i18nc("@info", "Move right view to a new window"));
2634 popoutSplitAction
->setEnabled(true);
2635 if (!m_splitViewAction
->menu()) {
2636 setActionPopupMode(m_splitViewAction
, QToolButton::MenuButtonPopup
);
2637 m_splitViewAction
->setMenu(new QMenu
);
2638 m_splitViewAction
->addAction(popoutSplitAction
);
2641 m_splitViewAction
->setText(i18nc("@action:intoolbar Split view", "Split"));
2642 m_splitViewAction
->setToolTip(i18nc("@info", "Split view"));
2643 m_splitViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-right-new")));
2644 popoutSplitAction
->setText(i18nc("@action:intoolbar Move view in focus to a new window", "Pop out"));
2645 popoutSplitAction
->setEnabled(false);
2646 if (m_splitViewAction
->menu()) {
2647 m_splitViewAction
->removeAction(popoutSplitAction
);
2648 m_splitViewAction
->menu()->deleteLater();
2649 m_splitViewAction
->setMenu(nullptr);
2650 setActionPopupMode(m_splitViewAction
, QToolButton::DelayedPopup
);
2654 // Update state from toolbar action
2655 m_splitViewMenuAction
->setText(m_splitViewAction
->text());
2656 m_splitViewMenuAction
->setToolTip(m_splitViewAction
->toolTip());
2657 m_splitViewMenuAction
->setIcon(m_splitViewAction
->icon());
2660 void DolphinMainWindow::updateAllowedToolbarAreas()
2662 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>(actionCollection()->action(QStringLiteral("url_navigators")));
2663 if (toolBar()->actions().contains(navigators
)) {
2664 toolBar()->setAllowedAreas(Qt::TopToolBarArea
| Qt::BottomToolBarArea
);
2665 if (toolBarArea(toolBar()) == Qt::LeftToolBarArea
|| toolBarArea(toolBar()) == Qt::RightToolBarArea
) {
2666 addToolBar(Qt::TopToolBarArea
, toolBar());
2669 toolBar()->setAllowedAreas(Qt::AllToolBarAreas
);
2673 bool DolphinMainWindow::isKompareInstalled() const
2675 static bool initialized
= false;
2676 static bool installed
= false;
2678 // TODO: maybe replace this approach later by using a menu
2679 // plugin like kdiff3plugin.cpp
2680 installed
= !QStandardPaths::findExecutable(QStringLiteral("kompare")).isEmpty();
2686 void DolphinMainWindow::createPanelAction(const QIcon
&icon
, const QKeySequence
&shortcut
, QDockWidget
*dockWidget
, const QString
&actionName
)
2688 auto dockAction
= dockWidget
->toggleViewAction();
2689 dockAction
->setIcon(icon
);
2690 dockAction
->setEnabled(true);
2692 QAction
*panelAction
= actionCollection()->addAction(actionName
, dockAction
);
2693 actionCollection()->setDefaultShortcut(panelAction
, shortcut
);
2696 void DolphinMainWindow::setupWhatsThis()
2699 menuBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2700 "<emphasis>Menubar</emphasis>. It provides access to commands and "
2701 "configuration options. Left-click on any of the menus on this "
2702 "bar to see its contents.</para><para>The Menubar can be hidden "
2703 "by unchecking <interface>Settings|Show Menubar</interface>. Then "
2704 "most of its contents become available through a <interface>Menu"
2705 "</interface> button on the <emphasis>Toolbar</emphasis>.</para>"));
2706 toolBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2707 "<emphasis>Toolbar</emphasis>. It allows quick access to "
2708 "frequently used actions.</para><para>It is highly customizable. "
2709 "All items you see in the <interface>Menu</interface> or "
2710 "in the <interface>Menubar</interface> can be placed on the "
2711 "Toolbar. Just right-click on it and select <interface>Configure "
2712 "Toolbars…</interface> or find this action within the <interface>"
2714 "</para><para>The location of the bar and the style of its "
2715 "buttons can also be changed in the right-click menu. Right-click "
2716 "a button if you want to show or hide its text.</para>"));
2717 m_tabWidget
->setWhatsThis(xi18nc("@info:whatsthis main view",
2718 "<para>Here you can see the <emphasis>folders</emphasis> and "
2719 "<emphasis>files</emphasis> that are at the location described in "
2720 "the <interface>Location Bar</interface> above. This area is the "
2721 "central part of this application where you navigate to the files "
2722 "you want to use.</para><para>For an elaborate and general "
2723 "introduction to this application <link "
2724 "url='https://userbase.kde.org/Dolphin/File_Management#Introduction_to_Dolphin'>"
2725 "click here</link>. This will open an introductory article from "
2726 "the <emphasis>KDE UserBase Wiki</emphasis>.</para><para>For brief "
2727 "explanations of all the features of this <emphasis>view</emphasis> "
2728 "<link url='help:/dolphin/dolphin-view.html'>click here</link> "
2729 "instead. This will open a page from the <emphasis>Handbook"
2730 "</emphasis> that covers the basics.</para>"));
2733 actionCollection()->action(KStandardAction::name(KStandardAction::KeyBindings
))
2734 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window "
2735 "that lists the <emphasis>keyboard shortcuts</emphasis>.<nl/>"
2736 "There you can set up key combinations to trigger an action when "
2737 "they are pressed simultaneously. All commands in this application can "
2738 "be triggered this way.</para>"));
2739 actionCollection()->action(KStandardAction::name(KStandardAction::ConfigureToolbars
))
2740 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window in which "
2741 "you can change which buttons appear on the <emphasis>Toolbar</emphasis>.</para>"
2742 "<para>All items you see in the <interface>Menu</interface> can also be placed on the Toolbar.</para>"));
2743 actionCollection()->action(KStandardAction::name(KStandardAction::Preferences
))
2744 ->setWhatsThis(xi18nc("@info:whatsthis","This opens a window where you can "
2745 "change a multitude of settings for this application. For an explanation "
2746 "of the various settings go to the chapter <emphasis>Configuring Dolphin"
2747 "</emphasis> in <interface>Help|Dolphin Handbook</interface>."));
2751 auto setStandardActionWhatsThis
= [this](KStandardAction::StandardAction actionId
,
2752 const QString
&whatsThis
) {
2753 // Check for the existence of an action since it can be restricted through the Kiosk system
2754 if (auto *action
= actionCollection()->action(KStandardAction::name(actionId
))) {
2755 action
->setWhatsThis(whatsThis
);
2759 // i18n: If the external link isn't available in your language it might make
2760 // sense to state the external link's language in brackets to not
2761 // frustrate the user. If there are multiple languages that the user might
2762 // know with a reasonable chance you might want to have 2 external links.
2763 // The same might be true for any external link you translate.
2764 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>"));
2765 // (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 )
2767 setStandardActionWhatsThis(KStandardAction::WhatsThis
,
2768 xi18nc("@info:whatsthis whatsthis button",
2769 "<para>This is the button that invokes the help feature you are "
2770 "using right now! Click it, then click any component of this "
2771 "application to ask \"What's this?\" about it. The mouse cursor "
2772 "will change appearance if no help is available for a spot.</para>"
2773 "<para>There are two other ways to get help: "
2774 "The <link url='help:/dolphin/index.html'>Dolphin Handbook</link> and "
2775 "the <link url='https://userbase.kde.org/Dolphin/File_Management'>KDE "
2776 "UserBase Wiki</link>.</para><para>The \"What's this?\" help is "
2777 "missing in most other windows so don't get too used to this.</para>"));
2779 setStandardActionWhatsThis(KStandardAction::ReportBug
,
2780 xi18nc("@info:whatsthis","<para>This opens a "
2781 "window that will guide you through reporting errors or flaws "
2782 "in this application or in other KDE software.</para>"
2783 "<para>High-quality bug reports are much appreciated. To learn "
2784 "how to make your bug report as effective as possible "
2785 "<link url='https://community.kde.org/Get_Involved/Bug_Reporting'>"
2786 "click here</link>.</para>"));
2788 setStandardActionWhatsThis(KStandardAction::Donate
,
2789 xi18nc("@info:whatsthis", "<para>This opens a "
2790 "<emphasis>web page</emphasis> where you can donate to "
2791 "support the continued work on this application and many "
2792 "other projects by the <emphasis>KDE</emphasis> community.</para>"
2793 "<para>Donating is the easiest and fastest way to efficiently "
2794 "support KDE and its projects. KDE projects are available for "
2795 "free therefore your donation is needed to cover things that "
2796 "require money like servers, contributor meetings, etc.</para>"
2797 "<para><emphasis>KDE e.V.</emphasis> is the non-profit "
2798 "organization behind the KDE community.</para>"));
2800 setStandardActionWhatsThis(KStandardAction::SwitchApplicationLanguage
,
2801 xi18nc("@info:whatsthis",
2802 "With this you can change the language this application uses."
2803 "<nl/>You can even set secondary languages which will be used "
2804 "if texts are not available in your preferred language."));
2806 setStandardActionWhatsThis(KStandardAction::AboutApp
,
2807 xi18nc("@info:whatsthis","This opens a "
2808 "window that informs you about the version, license, "
2809 "used libraries and maintainers of this application."));
2811 setStandardActionWhatsThis(KStandardAction::AboutKDE
,
2812 xi18nc("@info:whatsthis","This opens a "
2813 "window with information about <emphasis>KDE</emphasis>. "
2814 "The KDE community are the people behind this free software."
2815 "<nl/>If you like using this application but don't know "
2816 "about KDE or want to see a cute dragon have a look!"));
2820 bool DolphinMainWindow::addHamburgerMenuToToolbar()
2822 QDomDocument domDocument
= KXMLGUIClient::domDocument();
2823 if (domDocument
.isNull()) {
2826 QDomNode toolbar
= domDocument
.elementsByTagName(QStringLiteral("ToolBar")).at(0);
2827 if (toolbar
.isNull()) {
2831 QDomElement hamburgerMenuElement
= domDocument
.createElement(QStringLiteral("Action"));
2832 hamburgerMenuElement
.setAttribute(QStringLiteral("name"), QStringLiteral("hamburger_menu"));
2833 toolbar
.appendChild(hamburgerMenuElement
);
2835 KXMLGUIFactory::saveConfigFile(domDocument
, xmlFile());
2839 // Make sure to also remove the <KXMLGUIFactory> and <QDomDocument> include
2840 // whenever this method is removed (maybe in the year ~2026).
2843 // Set a sane initial window size
2844 QSize
DolphinMainWindow::sizeHint() const
2846 return KXmlGuiWindow::sizeHint().expandedTo(QSize(760, 550));
2849 void DolphinMainWindow::saveNewToolbarConfig()
2851 KXmlGuiWindow::saveNewToolbarConfig(); // Applies the new config. This has to be called first
2852 // because the rest of this method decides things
2853 // based on the new config.
2854 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>(actionCollection()->action(QStringLiteral("url_navigators")));
2855 if (!toolBar()->actions().contains(navigators
)) {
2856 m_tabWidget
->currentTabPage()->insertNavigatorsWidget(navigators
);
2858 updateAllowedToolbarAreas();
2859 (static_cast<KHamburgerMenu
*>(actionCollection()->action(KStandardAction::name(KStandardAction::HamburgerMenu
))))->hideActionsOf(toolBar());
2862 void DolphinMainWindow::focusTerminalPanel()
2864 if (m_terminalPanel
->isVisible()) {
2865 if (m_terminalPanel
->terminalHasFocus()) {
2866 m_activeViewContainer
->view()->setFocus(Qt::FocusReason::ShortcutFocusReason
);
2867 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
2869 m_terminalPanel
->setFocus(Qt::FocusReason::ShortcutFocusReason
);
2870 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
2873 actionCollection()->action(QStringLiteral("show_terminal_panel"))->trigger();
2874 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
2878 DolphinMainWindow::UndoUiInterface::UndoUiInterface()
2879 : KIO::FileUndoManager::UiInterface()
2883 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
2887 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
*job
)
2889 DolphinMainWindow
*mainWin
= qobject_cast
<DolphinMainWindow
*>(parentWidget());
2891 DolphinViewContainer
*container
= mainWin
->activeViewContainer();
2892 container
->showMessage(job
->errorString(), DolphinViewContainer::Error
);
2894 KIO::FileUndoManager::UiInterface::jobError(job
);
2898 bool DolphinMainWindow::isUrlOpen(const QString
&url
)
2900 return m_tabWidget
->isUrlOpen(QUrl::fromUserInput(url
));
2903 bool DolphinMainWindow::isItemVisibleInAnyView(const QString
&urlOfItem
)
2905 return m_tabWidget
->isItemVisibleInAnyView(QUrl::fromUserInput(urlOfItem
));
2908 void DolphinMainWindow::slotDoubleClickViewBackground(Qt::MouseButton button
)
2910 Q_UNUSED(button
) // might be of use later
2912 GeneralSettings
*settings
= GeneralSettings::self();
2913 QString clickAction
= settings
->doubleClickViewAction();
2915 DolphinView
*view
= activeViewContainer()->view();
2916 if (view
== nullptr || clickAction
== "none") {
2920 if (clickAction
== customCommand
) {
2921 // run custom command set by the user
2922 QString path
= view
->url().toLocalFile();
2923 QString clickCustomAction
= settings
->doubleClickViewCustomAction();
2924 clickCustomAction
.replace("{path}", path
.prepend('"').append('"'));
2926 m_job
= new KIO::CommandLauncherJob(clickCustomAction
);
2927 m_job
->setUiDelegate(new KDialogJobUiDelegate(KJobUiDelegate::AutoHandlingEnabled
, this));
2931 // get the action set by the user and trigger it
2932 const KActionCollection
*actions
= actionCollection();
2933 QAction
*action
= actions
->action(clickAction
);
2934 if (action
== nullptr) {
2935 qCWarning(DolphinDebug
) << QStringLiteral("Double-click view: action `%1` was not found").arg(clickAction
);
2942 #include "moc_dolphinmainwindow.cpp"