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 "admin/workerintegration.h"
12 #include "dolphin_generalsettings.h"
13 #include "dolphinbookmarkhandler.h"
14 #include "dolphincontextmenu.h"
15 #include "dolphindockwidget.h"
16 #include "dolphinmainwindowadaptor.h"
17 #include "dolphinnavigatorswidgetaction.h"
18 #include "dolphinnewfilemenu.h"
19 #include "dolphinplacesmodelsingleton.h"
20 #include "dolphinrecenttabsmenu.h"
21 #include "dolphintabpage.h"
22 #include "dolphinurlnavigatorscontroller.h"
23 #include "dolphinviewcontainer.h"
25 #include "middleclickactioneventfilter.h"
26 #include "panels/folders/folderspanel.h"
27 #include "panels/places/placespanel.h"
28 #include "panels/terminal/terminalpanel.h"
29 #include "search/dolphinquery.h"
30 #include "selectionmode/actiontexthelper.h"
31 #include "settings/dolphinsettingsdialog.h"
32 #include "statusbar/diskspaceusagemenu.h"
33 #include "statusbar/dolphinstatusbar.h"
34 #include "views/dolphinnewfilemenuobserver.h"
35 #include "views/dolphinremoteencoding.h"
36 #include "views/dolphinviewactionhandler.h"
37 #include "views/draganddrophelper.h"
38 #include "views/viewproperties.h"
40 #include <KActionCollection>
41 #include <KActionMenu>
42 #include <KAuthorized>
43 #include <KColorSchemeManager>
46 #include <KDesktopFile>
47 #include <KDialogJobUiDelegate>
48 #include <KDualAction>
49 #include <KFileItemListProperties>
50 #include <KIO/CommandLauncherJob>
51 #include <KIO/JobUiDelegateFactory>
52 #include <KIO/OpenFileManagerWindowJob>
53 #include <KIO/OpenUrlJob>
54 #include <KJobWidgets>
55 #include <KLocalizedString>
56 #include <KMessageBox>
57 #include <KProtocolInfo>
58 #include <KProtocolManager>
59 #include <KRecentFilesAction>
60 #include <KRuntimePlatform>
62 #include <KShortcutsDialog>
63 #include <KStandardAction>
65 #include <KTerminalLauncherJob>
66 #include <KToggleAction>
68 #include <KToolBarPopupAction>
69 #include <KUrlComboBox>
70 #include <KUrlNavigator>
71 #include <KWindowSystem>
72 #include <KXMLGUIFactory>
74 #include <kwidgetsaddons_version.h>
76 #include <QApplication>
78 #include <QCloseEvent>
79 #include <QDesktopServices>
81 #include <QDomDocument>
85 #include <QPushButton>
87 #include <QStandardPaths>
89 #include <QToolButton>
90 #include <QtConcurrentRun>
91 #include <dolphindebug.h>
96 #include <KStartupInfo>
101 // Used for GeneralSettings::version() to determine whether
102 // an updated version of Dolphin is running, so as to migrate
103 // removed/renamed ...etc config entries; increment it in such
105 const int CurrentDolphinVersion
= 202;
106 // The maximum number of entries in the back/forward popup menu
107 const int MaxNumberOfNavigationentries
= 12;
108 // The maximum number of "Go to Tab" shortcuts
109 const int MaxActivateTabShortcuts
= 9;
112 DolphinMainWindow::DolphinMainWindow()
113 : KXmlGuiWindow(nullptr)
114 , m_newFileMenu(nullptr)
115 , m_tabWidget(nullptr)
116 , m_activeViewContainer(nullptr)
117 , m_actionHandler(nullptr)
118 , m_remoteEncoding(nullptr)
120 , m_bookmarkHandler(nullptr)
121 , m_disabledActionNotifier(nullptr)
122 , m_lastHandleUrlOpenJob(nullptr)
123 , m_terminalPanel(nullptr)
124 , m_placesPanel(nullptr)
125 , m_tearDownFromPlacesRequested(false)
126 , m_backAction(nullptr)
127 , m_forwardAction(nullptr)
128 , m_splitViewAction(nullptr)
129 , m_splitViewMenuAction(nullptr)
130 , m_diskSpaceUsageMenu(nullptr)
131 , m_sessionSaveTimer(nullptr)
132 , m_sessionSaveWatcher(nullptr)
133 , m_sessionSaveScheduled(false)
135 Q_INIT_RESOURCE(dolphin
);
137 new MainWindowAdaptor(this);
140 setWindowFlags(Qt::WindowContextHelpButtonHint
);
142 setComponentName(QStringLiteral("dolphin"), QGuiApplication::applicationDisplayName());
143 setObjectName(QStringLiteral("Dolphin#"));
145 setStateConfigGroup("State");
147 #if defined(Q_OS_WIN) || defined(Q_OS_MACOS)
148 new KColorSchemeManager(this); // Sets a sensible color scheme which fixes unreadable icons and text on Windows.
151 connect(&DolphinNewFileMenuObserver::instance(), &DolphinNewFileMenuObserver::errorMessage
, this, &DolphinMainWindow::showErrorMessage
);
153 KIO::FileUndoManager
*undoManager
= KIO::FileUndoManager::self();
154 undoManager
->setUiInterface(new UndoUiInterface());
156 connect(undoManager
, &KIO::FileUndoManager::undoAvailable
, this, &DolphinMainWindow::slotUndoAvailable
);
157 connect(undoManager
, &KIO::FileUndoManager::undoTextChanged
, this, &DolphinMainWindow::slotUndoTextChanged
);
158 connect(undoManager
, &KIO::FileUndoManager::jobRecordingStarted
, this, &DolphinMainWindow::clearStatusBar
);
159 connect(undoManager
, &KIO::FileUndoManager::jobRecordingFinished
, this, &DolphinMainWindow::showCommand
);
161 const bool firstRun
= (GeneralSettings::version() < 200);
163 GeneralSettings::setViewPropsTimestamp(QDateTime::currentDateTime());
166 setAcceptDrops(true);
168 auto *navigatorsWidgetAction
= new DolphinNavigatorsWidgetAction(this);
169 actionCollection()->addAction(QStringLiteral("url_navigators"), navigatorsWidgetAction
);
170 m_tabWidget
= new DolphinTabWidget(navigatorsWidgetAction
, this);
171 m_tabWidget
->setObjectName("tabWidget");
172 connect(m_tabWidget
, &DolphinTabWidget::activeViewChanged
, this, &DolphinMainWindow::activeViewChanged
);
173 connect(m_tabWidget
, &DolphinTabWidget::tabCountChanged
, this, &DolphinMainWindow::tabCountChanged
);
174 connect(m_tabWidget
, &DolphinTabWidget::currentUrlChanged
, this, &DolphinMainWindow::updateWindowTitle
);
175 setCentralWidget(m_tabWidget
);
177 m_actionTextHelper
= new SelectionMode::ActionTextHelper(this);
180 m_actionHandler
= new DolphinViewActionHandler(actionCollection(), m_actionTextHelper
, this);
181 connect(m_actionHandler
, &DolphinViewActionHandler::actionBeingHandled
, this, &DolphinMainWindow::clearStatusBar
);
182 connect(m_actionHandler
, &DolphinViewActionHandler::createDirectoryTriggered
, this, &DolphinMainWindow::createDirectory
);
183 connect(m_actionHandler
, &DolphinViewActionHandler::createFileTriggered
, this, &DolphinMainWindow::createFile
);
184 connect(m_actionHandler
, &DolphinViewActionHandler::selectionModeChangeTriggered
, this, &DolphinMainWindow::slotSetSelectionMode
);
186 QAction
*newDirAction
= actionCollection()->action(QStringLiteral("create_dir"));
187 Q_CHECK_PTR(newDirAction
);
188 m_newFileMenu
->setNewFolderShortcutAction(newDirAction
);
190 QAction
*newFileAction
= actionCollection()->action(QStringLiteral("create_file"));
191 Q_CHECK_PTR(newFileAction
);
192 m_newFileMenu
->setNewFileShortcutAction(newFileAction
);
194 m_remoteEncoding
= new DolphinRemoteEncoding(this, m_actionHandler
);
195 connect(this, &DolphinMainWindow::urlChanged
, m_remoteEncoding
, &DolphinRemoteEncoding::slotAboutToOpenUrl
);
197 m_disabledActionNotifier
= new DisabledActionNotifier(this);
198 connect(m_disabledActionNotifier
, &DisabledActionNotifier::disabledActionTriggered
, this, [this](const QAction
*, QString reason
) {
199 m_activeViewContainer
->showMessage(reason
, KMessageWidget::Warning
);
204 const bool usePhoneUi
{KRuntimePlatform::runtimePlatform().contains(QLatin1String("phone"))};
205 setupGUI(Save
| Create
| ToolBar
, usePhoneUi
? QStringLiteral("dolphinuiforphones.rc") : QString() /* load the default dolphinui.rc file */);
206 stateChanged(QStringLiteral("new_file"));
208 QClipboard
*clipboard
= QApplication::clipboard();
209 connect(clipboard
, &QClipboard::dataChanged
, this, &DolphinMainWindow::updatePasteAction
);
211 QAction
*toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
212 toggleFilterBarAction
->setChecked(GeneralSettings::filterBar());
215 menuBar()->setVisible(false);
218 Q_ASSERT(qobject_cast
<QDockWidget
*>(m_placesPanel
->parent()));
219 m_placesPanel
->parentWidget()->hide();
220 auto settings
= GeneralSettings::self();
221 settings
->setShowZoomSlider(false); // Zooming can be done with pinch gestures instead and we are short on horizontal space.
222 settings
->setRenameInline(false); // This works around inline renaming currently not working well with virtual keyboards.
223 settings
->save(); // Otherwise the RenameInline setting is not picked up for the first time Dolphin is used.
227 const bool showMenu
= !menuBar()->isHidden();
228 QAction
*showMenuBarAction
= actionCollection()->action(KStandardAction::name(KStandardAction::ShowMenubar
));
229 showMenuBarAction
->setChecked(showMenu
); // workaround for bug #171080
231 auto hamburgerMenu
= static_cast<KHamburgerMenu
*>(actionCollection()->action(KStandardAction::name(KStandardAction::HamburgerMenu
)));
232 hamburgerMenu
->setMenuBar(menuBar());
233 hamburgerMenu
->setShowMenuBarAction(showMenuBarAction
);
234 connect(hamburgerMenu
, &KHamburgerMenu::aboutToShowMenu
, this, &DolphinMainWindow::updateHamburgerMenu
);
235 hamburgerMenu
->hideActionsOf(toolBar());
236 if (GeneralSettings::version() < 201 && !toolBar()->actions().contains(hamburgerMenu
)) {
237 addHamburgerMenuToToolbar();
240 updateAllowedToolbarAreas();
241 updateNavigatorsBackground();
243 // enable middle-click on back/forward/up to open in a new tab
244 auto *middleClickEventFilter
= new MiddleClickActionEventFilter(this);
245 connect(middleClickEventFilter
, &MiddleClickActionEventFilter::actionMiddleClicked
, this, &DolphinMainWindow::slotToolBarActionMiddleClicked
);
246 toolBar()->installEventFilter(middleClickEventFilter
);
250 connect(KSycoca::self(), &KSycoca::databaseChanged
, this, &DolphinMainWindow::updateOpenPreferredSearchToolAction
);
252 QTimer::singleShot(0, this, &DolphinMainWindow::updateOpenPreferredSearchToolAction
);
254 m_fileItemActions
.setParentWidget(this);
255 connect(&m_fileItemActions
, &KFileItemActions::error
, this, [this](const QString
&errorMessage
) {
256 showErrorMessage(errorMessage
);
259 connect(GeneralSettings::self(), &GeneralSettings::splitViewChanged
, this, &DolphinMainWindow::slotSplitViewChanged
);
262 DolphinMainWindow::~DolphinMainWindow()
264 // This fixes a crash on Wayland when closing the mainwindow while another dialog is open.
265 disconnect(QGuiApplication::clipboard(), &QClipboard::dataChanged
, this, &DolphinMainWindow::updatePasteAction
);
267 // This fixes a crash in dolphinmainwindowtest where the connection below fires even though the KMainWindow destructor of this object is already running.
268 Q_CHECK_PTR(qobject_cast
<DolphinDockWidget
*>(m_placesPanel
->parent()));
269 disconnect(static_cast<DolphinDockWidget
*>(m_placesPanel
->parent()),
270 &DolphinDockWidget::visibilityChanged
,
272 &DolphinMainWindow::slotPlacesPanelVisibilityChanged
);
275 QVector
<DolphinViewContainer
*> DolphinMainWindow::viewContainers() const
277 QVector
<DolphinViewContainer
*> viewContainers
;
279 for (int i
= 0; i
< m_tabWidget
->count(); ++i
) {
280 DolphinTabPage
*tabPage
= m_tabWidget
->tabPageAt(i
);
282 viewContainers
<< tabPage
->primaryViewContainer();
283 if (tabPage
->splitViewEnabled()) {
284 viewContainers
<< tabPage
->secondaryViewContainer();
287 return viewContainers
;
290 void DolphinMainWindow::openDirectories(const QList
<QUrl
> &dirs
, bool splitView
)
292 m_tabWidget
->openDirectories(dirs
, splitView
);
295 void DolphinMainWindow::openDirectories(const QStringList
&dirs
, bool splitView
)
297 openDirectories(QUrl::fromStringList(dirs
), splitView
);
300 void DolphinMainWindow::openFiles(const QList
<QUrl
> &files
, bool splitView
)
302 m_tabWidget
->openFiles(files
, splitView
);
305 bool DolphinMainWindow::isFoldersPanelEnabled() const
307 return actionCollection()->action(QStringLiteral("show_folders_panel"))->isChecked();
310 bool DolphinMainWindow::isInformationPanelEnabled() const
313 return actionCollection()->action(QStringLiteral("show_information_panel"))->isChecked();
319 bool DolphinMainWindow::isSplitViewEnabledInCurrentTab() const
321 return m_tabWidget
->currentTabPage()->splitViewEnabled();
324 void DolphinMainWindow::openFiles(const QStringList
&files
, bool splitView
)
326 openFiles(QUrl::fromStringList(files
), splitView
);
329 void DolphinMainWindow::activateWindow(const QString
&activationToken
)
331 window()->setAttribute(Qt::WA_NativeWindow
, true);
333 if (KWindowSystem::isPlatformWayland()) {
334 KWindowSystem::setCurrentXdgActivationToken(activationToken
);
335 } else if (KWindowSystem::isPlatformX11()) {
337 KStartupInfo::setNewStartupId(window()->windowHandle(), activationToken
.toUtf8());
341 KWindowSystem::activateWindow(window()->windowHandle());
344 bool DolphinMainWindow::isActiveWindow()
346 return window()->isActiveWindow();
349 void DolphinMainWindow::showCommand(CommandType command
)
351 DolphinStatusBar
*statusBar
= m_activeViewContainer
->statusBar();
353 case KIO::FileUndoManager::Copy
:
354 statusBar
->setText(i18nc("@info:status", "Successfully copied."));
356 case KIO::FileUndoManager::Move
:
357 statusBar
->setText(i18nc("@info:status", "Successfully moved."));
359 case KIO::FileUndoManager::Link
:
360 statusBar
->setText(i18nc("@info:status", "Successfully linked."));
362 case KIO::FileUndoManager::Trash
:
363 statusBar
->setText(i18nc("@info:status", "Successfully moved to trash."));
365 case KIO::FileUndoManager::Rename
:
366 statusBar
->setText(i18nc("@info:status", "Successfully renamed."));
369 case KIO::FileUndoManager::Mkdir
:
370 statusBar
->setText(i18nc("@info:status", "Created folder."));
378 void DolphinMainWindow::pasteIntoFolder()
380 m_activeViewContainer
->view()->pasteIntoFolder();
383 void DolphinMainWindow::changeUrl(const QUrl
&url
)
385 if (!KProtocolManager::supportsListing(url
)) {
386 // The URL navigator only checks for validity, not
387 // if the URL can be listed. An error message is
388 // shown due to DolphinViewContainer::restoreView().
392 m_activeViewContainer
->setUrl(url
);
393 updateFileAndEditActions();
397 m_diskSpaceUsageMenu
->setUrl(url
);
399 // will signal used urls to activities manager, too
400 m_recentFiles
->addUrl(url
, QString(), "inode/directory");
402 Q_EMIT
urlChanged(url
);
405 void DolphinMainWindow::slotTerminalDirectoryChanged(const QUrl
&url
)
407 if (m_tearDownFromPlacesRequested
&& url
== QUrl::fromLocalFile(QDir::homePath())) {
408 m_placesPanel
->proceedWithTearDown();
409 m_tearDownFromPlacesRequested
= false;
412 m_activeViewContainer
->setGrabFocusOnUrlChange(false);
414 m_activeViewContainer
->setGrabFocusOnUrlChange(true);
417 void DolphinMainWindow::slotEditableStateChanged(bool editable
)
419 KToggleAction
*editableLocationAction
= static_cast<KToggleAction
*>(actionCollection()->action(QStringLiteral("editable_location")));
420 editableLocationAction
->setChecked(editable
);
423 void DolphinMainWindow::slotSelectionChanged(const KFileItemList
&selection
)
425 updateFileAndEditActions();
427 const int selectedUrlsCount
= m_tabWidget
->currentTabPage()->selectedItemsCount();
429 QAction
*compareFilesAction
= actionCollection()->action(QStringLiteral("compare_files"));
430 if (selectedUrlsCount
== 2) {
431 compareFilesAction
->setEnabled(isKompareInstalled());
433 compareFilesAction
->setEnabled(false);
436 Q_EMIT
selectionChanged(selection
);
439 void DolphinMainWindow::updateHistory()
441 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
442 const int index
= urlNavigator
->historyIndex();
444 QAction
*backAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Back
));
446 backAction
->setToolTip(i18nc("@info", "Go back"));
447 backAction
->setWhatsThis(i18nc("@info:whatsthis go back", "Return to the previously viewed folder."));
448 backAction
->setEnabled(index
< urlNavigator
->historySize() - 1);
451 QAction
*forwardAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Forward
));
453 forwardAction
->setToolTip(i18nc("@info", "Go forward"));
454 forwardAction
->setWhatsThis(xi18nc("@info:whatsthis go forward", "This undoes a <interface>Go|Back</interface> action."));
455 forwardAction
->setEnabled(index
> 0);
459 void DolphinMainWindow::updateFilterBarAction(bool show
)
461 QAction
*toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
462 toggleFilterBarAction
->setChecked(show
);
465 void DolphinMainWindow::openNewMainWindow()
467 Dolphin::openNewWindow({m_activeViewContainer
->url()}, this);
470 void DolphinMainWindow::openNewActivatedTab()
472 // keep browsers compatibility, new tab is always after last one
473 auto openNewTabAfterLastTabConfigured
= GeneralSettings::openNewTabAfterLastTab();
474 GeneralSettings::setOpenNewTabAfterLastTab(true);
475 m_tabWidget
->openNewActivatedTab();
476 GeneralSettings::setOpenNewTabAfterLastTab(openNewTabAfterLastTabConfigured
);
479 void DolphinMainWindow::addToPlaces()
484 // If nothing is selected, act on the current dir
485 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
486 url
= m_activeViewContainer
->url();
487 name
= m_activeViewContainer
->placesText();
489 const auto dirToAdd
= m_activeViewContainer
->view()->selectedItems().first();
490 url
= dirToAdd
.url();
491 name
= dirToAdd
.name();
495 if (isSearchUrl(url
)) {
496 icon
= QStringLiteral("folder-saved-search-symbolic");
498 icon
= KIO::iconNameForUrl(url
);
500 DolphinPlacesModelSingleton::instance().placesModel()->addPlace(name
, url
, icon
);
504 DolphinTabPage
*DolphinMainWindow::openNewTab(const QUrl
&url
)
506 return m_tabWidget
->openNewTab(url
, QUrl());
509 void DolphinMainWindow::openNewTabAndActivate(const QUrl
&url
)
511 m_tabWidget
->openNewActivatedTab(url
, QUrl());
514 void DolphinMainWindow::openNewWindow(const QUrl
&url
)
516 Dolphin::openNewWindow({url
}, this);
519 void DolphinMainWindow::slotSplitViewChanged()
521 m_tabWidget
->currentTabPage()->setSplitViewEnabled(GeneralSettings::splitView(), WithAnimation
);
522 updateSplitActions();
525 void DolphinMainWindow::openInNewTab()
527 const KFileItemList
&list
= m_activeViewContainer
->view()->selectedItems();
528 bool tabCreated
= false;
530 for (const KFileItem
&item
: list
) {
531 const QUrl
&url
= DolphinView::openItemAsFolderUrl(item
);
532 if (!url
.isEmpty()) {
538 // if no new tab has been created from the selection
539 // open the current directory in a new tab
541 openNewTab(m_activeViewContainer
->url());
545 void DolphinMainWindow::openInNewWindow()
549 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
550 if (list
.isEmpty()) {
551 newWindowUrl
= m_activeViewContainer
->url();
552 } else if (list
.count() == 1) {
553 const KFileItem
&item
= list
.first();
554 newWindowUrl
= DolphinView::openItemAsFolderUrl(item
);
557 if (!newWindowUrl
.isEmpty()) {
558 Dolphin::openNewWindow({newWindowUrl
}, this);
562 void DolphinMainWindow::openInSplitView(const QUrl
&url
)
564 QUrl newSplitViewUrl
= url
;
566 if (newSplitViewUrl
.isEmpty()) {
567 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
568 if (list
.count() == 1) {
569 const KFileItem
&item
= list
.first();
570 newSplitViewUrl
= DolphinView::openItemAsFolderUrl(item
);
574 if (newSplitViewUrl
.isEmpty()) {
578 DolphinTabPage
*tabPage
= m_tabWidget
->currentTabPage();
579 if (tabPage
->splitViewEnabled()) {
580 tabPage
->switchActiveView();
581 tabPage
->activeViewContainer()->setUrl(newSplitViewUrl
);
583 tabPage
->setSplitViewEnabled(true, WithAnimation
, newSplitViewUrl
);
588 void DolphinMainWindow::showTarget()
590 const KFileItem link
= m_activeViewContainer
->view()->selectedItems().at(0);
591 const QUrl destinationUrl
= link
.url().resolved(QUrl(link
.linkDest()));
593 auto job
= KIO::stat(destinationUrl
, KIO::StatJob::SourceSide
, KIO::StatNoDetails
);
595 connect(job
, &KJob::finished
, this, [this, destinationUrl
](KJob
*job
) {
596 KIO::StatJob
*statJob
= static_cast<KIO::StatJob
*>(job
);
598 if (statJob
->error()) {
599 m_activeViewContainer
->showMessage(job
->errorString(), KMessageWidget::Error
);
601 KIO::highlightInFileManager({destinationUrl
});
606 bool DolphinMainWindow::event(QEvent
*event
)
608 if (event
->type() == QEvent::ShortcutOverride
) {
609 const QKeyEvent
*keyEvent
= static_cast<QKeyEvent
*>(event
);
610 if (keyEvent
->key() == Qt::Key_Space
&& m_activeViewContainer
->view()->handleSpaceAsNormalKey()) {
616 return KXmlGuiWindow::event(event
);
619 void DolphinMainWindow::showEvent(QShowEvent
*event
)
621 KXmlGuiWindow::showEvent(event
);
623 if (!event
->spontaneous() && m_activeViewContainer
) {
624 m_activeViewContainer
->view()->setFocus();
628 void DolphinMainWindow::closeEvent(QCloseEvent
*event
)
630 // Find out if Dolphin is closed directly by the user or
631 // by the session manager because the session is closed
632 bool closedByUser
= true;
633 if (qApp
->isSavingSession()) {
634 closedByUser
= false;
637 if (m_tabWidget
->count() > 1 && GeneralSettings::confirmClosingMultipleTabs() && !GeneralSettings::rememberOpenedTabs() && closedByUser
) {
638 // Ask the user if he really wants to quit and close all tabs.
639 // Open a confirmation dialog with 3 buttons:
640 // QDialogButtonBox::Yes -> Quit
641 // QDialogButtonBox::No -> Close only the current tab
642 // QDialogButtonBox::Cancel -> do nothing
643 QDialog
*dialog
= new QDialog(this, Qt::Dialog
);
644 dialog
->setWindowTitle(i18nc("@title:window", "Confirmation"));
645 dialog
->setModal(true);
646 QDialogButtonBox
*buttons
= new QDialogButtonBox(QDialogButtonBox::Yes
| QDialogButtonBox::No
| QDialogButtonBox::Cancel
);
647 KGuiItem::assign(buttons
->button(QDialogButtonBox::Yes
),
648 KGuiItem(i18nc("@action:button 'Quit Dolphin' button", "&Quit %1", QGuiApplication::applicationDisplayName()),
649 QIcon::fromTheme(QStringLiteral("application-exit"))));
650 KGuiItem::assign(buttons
->button(QDialogButtonBox::No
), KGuiItem(i18n("C&lose Current Tab"), QIcon::fromTheme(QStringLiteral("tab-close"))));
651 KGuiItem::assign(buttons
->button(QDialogButtonBox::Cancel
), KStandardGuiItem::cancel());
652 buttons
->button(QDialogButtonBox::Yes
)->setDefault(true);
654 bool doNotAskAgainCheckboxResult
= false;
656 const auto result
= KMessageBox::createKMessageBox(dialog
,
658 QMessageBox::Warning
,
659 i18n("You have multiple tabs open in this window, are you sure you want to quit?"),
661 i18n("Do not ask again"),
662 &doNotAskAgainCheckboxResult
,
663 KMessageBox::Notify
);
665 if (doNotAskAgainCheckboxResult
) {
666 GeneralSettings::setConfirmClosingMultipleTabs(false);
670 case QDialogButtonBox::Yes
:
673 case QDialogButtonBox::No
:
674 // Close only the current tab
675 m_tabWidget
->closeTab();
683 if (m_terminalPanel
&& m_terminalPanel
->hasProgramRunning() && GeneralSettings::confirmClosingTerminalRunningProgram() && closedByUser
) {
684 // Ask if the user really wants to quit Dolphin with a program that is still running in the Terminal panel
685 // Open a confirmation dialog with 3 buttons:
686 // QDialogButtonBox::Yes -> Quit
687 // QDialogButtonBox::No -> Show Terminal Panel
688 // QDialogButtonBox::Cancel -> do nothing
689 QDialog
*dialog
= new QDialog(this, Qt::Dialog
);
690 dialog
->setWindowTitle(i18nc("@title:window", "Confirmation"));
691 dialog
->setModal(true);
692 auto standardButtons
= QDialogButtonBox::Yes
| QDialogButtonBox::Cancel
;
693 if (!m_terminalPanel
->isVisible()) {
694 standardButtons
|= QDialogButtonBox::No
;
696 QDialogButtonBox
*buttons
= new QDialogButtonBox(standardButtons
);
697 KGuiItem::assign(buttons
->button(QDialogButtonBox::Yes
), KStandardGuiItem::quit());
698 if (!m_terminalPanel
->isVisible()) {
699 KGuiItem::assign(buttons
->button(QDialogButtonBox::No
), KGuiItem(i18n("Show &Terminal Panel"), QIcon::fromTheme(QStringLiteral("dialog-scripts"))));
701 KGuiItem::assign(buttons
->button(QDialogButtonBox::Cancel
), KStandardGuiItem::cancel());
703 bool doNotAskAgainCheckboxResult
= false;
705 const auto result
= KMessageBox::createKMessageBox(
708 QMessageBox::Warning
,
709 i18n("The program '%1' is still running in the Terminal panel. Are you sure you want to quit?", m_terminalPanel
->runningProgramName()),
711 i18n("Do not ask again"),
712 &doNotAskAgainCheckboxResult
,
713 KMessageBox::Notify
| KMessageBox::Dangerous
);
715 if (doNotAskAgainCheckboxResult
) {
716 GeneralSettings::setConfirmClosingTerminalRunningProgram(false);
720 case QDialogButtonBox::Yes
:
723 case QDialogButtonBox::No
:
724 actionCollection()->action("show_terminal_panel")->trigger();
725 // Do not quit, ignore quit event
733 if (m_sessionSaveTimer
&& (m_sessionSaveTimer
->isActive() || m_sessionSaveWatcher
->isRunning())) {
734 const bool sessionSaveTimerActive
= m_sessionSaveTimer
->isActive();
736 m_sessionSaveTimer
->stop();
737 m_sessionSaveWatcher
->disconnect();
738 m_sessionSaveWatcher
->waitForFinished();
740 if (sessionSaveTimerActive
|| m_sessionSaveScheduled
) {
745 GeneralSettings::setVersion(CurrentDolphinVersion
);
746 GeneralSettings::self()->save();
748 KXmlGuiWindow::closeEvent(event
);
751 void DolphinMainWindow::slotSaveSession()
753 m_sessionSaveScheduled
= false;
755 if (m_sessionSaveWatcher
->isRunning()) {
756 // The previous session is still being saved - schedule another save.
757 m_sessionSaveWatcher
->disconnect();
758 connect(m_sessionSaveWatcher
, &QFutureWatcher
<void>::finished
, this, &DolphinMainWindow::slotSaveSession
, Qt::SingleShotConnection
);
759 m_sessionSaveScheduled
= true;
760 } else if (!m_sessionSaveTimer
->isActive()) {
761 // No point in saving the session if the timer is running (since it will save the session again when it times out).
762 KConfigGui::setSessionConfig(QStringLiteral("dolphin"), QStringLiteral("dolphin"));
763 KConfig
*config
= KConfigGui::sessionConfig();
764 saveGlobalProperties(config
);
765 savePropertiesInternal(config
, 1);
766 KConfigGroup group
= config
->group(QStringLiteral("Number"));
767 group
.writeEntry("NumberOfWindows", 1); // Makes session restore aware that there is a window to restore.
769 auto future
= QtConcurrent::run([config
]() {
772 m_sessionSaveWatcher
->setFuture(future
);
776 void DolphinMainWindow::setSessionAutoSaveEnabled(bool enable
)
779 if (!m_sessionSaveTimer
) {
780 m_sessionSaveTimer
= new QTimer(this);
781 m_sessionSaveWatcher
= new QFutureWatcher
<void>(this);
782 m_sessionSaveTimer
->setSingleShot(true);
783 m_sessionSaveTimer
->setInterval(22000);
785 connect(m_sessionSaveTimer
, &QTimer::timeout
, this, &DolphinMainWindow::slotSaveSession
);
788 connect(m_tabWidget
, &DolphinTabWidget::urlChanged
, m_sessionSaveTimer
, qOverload
<>(&QTimer::start
), Qt::UniqueConnection
);
789 connect(m_tabWidget
, &DolphinTabWidget::tabCountChanged
, m_sessionSaveTimer
, qOverload
<>(&QTimer::start
), Qt::UniqueConnection
);
790 connect(m_tabWidget
, &DolphinTabWidget::activeViewChanged
, m_sessionSaveTimer
, qOverload
<>(&QTimer::start
), Qt::UniqueConnection
);
791 } else if (m_sessionSaveTimer
) {
792 m_sessionSaveTimer
->stop();
793 m_sessionSaveWatcher
->disconnect();
794 m_sessionSaveScheduled
= false;
796 m_sessionSaveWatcher
->waitForFinished();
798 m_sessionSaveTimer
->deleteLater();
799 m_sessionSaveWatcher
->deleteLater();
800 m_sessionSaveTimer
= nullptr;
801 m_sessionSaveWatcher
= nullptr;
805 void DolphinMainWindow::saveProperties(KConfigGroup
&group
)
807 m_tabWidget
->saveProperties(group
);
810 void DolphinMainWindow::readProperties(const KConfigGroup
&group
)
812 m_tabWidget
->readProperties(group
);
815 void DolphinMainWindow::updateNewMenu()
817 m_newFileMenu
->checkUpToDate();
818 m_newFileMenu
->setWorkingDirectory(activeViewContainer()->url());
821 void DolphinMainWindow::createDirectory()
823 // When creating directory, namejob is being run. In network folders,
824 // this job can take long time, so instead of starting multiple namejobs,
825 // just check if we are already running one. This prevents opening multiple
826 // dialogs. BUG:481401
827 if (!m_newFileMenu
->isCreateDirectoryRunning()) {
828 m_newFileMenu
->setWorkingDirectory(activeViewContainer()->url());
829 m_newFileMenu
->createDirectory();
833 void DolphinMainWindow::createFile()
835 // Use the same logic as in createDirectory()
836 if (!m_newFileMenu
->isCreateFileRunning()) {
837 m_newFileMenu
->setWorkingDirectory(activeViewContainer()->url());
838 m_newFileMenu
->createFile();
842 void DolphinMainWindow::quit()
847 void DolphinMainWindow::showErrorMessage(const QString
&message
)
849 m_activeViewContainer
->showMessage(message
, KMessageWidget::Error
);
852 void DolphinMainWindow::slotUndoAvailable(bool available
)
854 QAction
*undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
856 undoAction
->setEnabled(available
);
860 void DolphinMainWindow::slotUndoTextChanged(const QString
&text
)
862 QAction
*undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
864 undoAction
->setText(text
);
868 void DolphinMainWindow::undo()
871 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
872 KIO::FileUndoManager::self()->undo();
875 void DolphinMainWindow::cut()
877 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
878 m_activeViewContainer
->setSelectionModeEnabled(true, actionCollection(), SelectionMode::BottomBar::Contents::CutContents
);
880 m_activeViewContainer
->view()->cutSelectedItemsToClipboard();
881 m_activeViewContainer
->setSelectionModeEnabled(false);
885 void DolphinMainWindow::copy()
887 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
888 m_activeViewContainer
->setSelectionModeEnabled(true, actionCollection(), SelectionMode::BottomBar::Contents::CopyContents
);
890 m_activeViewContainer
->view()->copySelectedItemsToClipboard();
891 m_activeViewContainer
->setSelectionModeEnabled(false);
895 void DolphinMainWindow::paste()
897 m_activeViewContainer
->view()->paste();
900 void DolphinMainWindow::find()
902 m_activeViewContainer
->setSearchBarVisible(true);
903 m_activeViewContainer
->setFocusToSearchBar();
906 void DolphinMainWindow::updateSearchAction()
908 QAction
*toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
909 toggleSearchAction
->setChecked(m_activeViewContainer
->isSearchBarVisible());
912 void DolphinMainWindow::updatePasteAction()
914 QAction
*pasteAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Paste
));
915 QPair
<bool, QString
> pasteInfo
= m_activeViewContainer
->view()->pasteInfo();
916 pasteAction
->setEnabled(pasteInfo
.first
);
917 m_disabledActionNotifier
->setDisabledReason(pasteAction
,
918 m_activeViewContainer
->rootItem().isWritable()
919 ? i18nc("@info", "Cannot paste: The clipboard is empty.")
920 : i18nc("@info", "Cannot paste: You do not have permission to write into this folder."));
921 pasteAction
->setText(pasteInfo
.second
);
924 void DolphinMainWindow::slotDirectoryLoadingCompleted()
929 void DolphinMainWindow::slotToolBarActionMiddleClicked(QAction
*action
)
931 if (action
== actionCollection()->action(KStandardAction::name(KStandardAction::Back
))) {
933 } else if (action
== actionCollection()->action(KStandardAction::name(KStandardAction::Forward
))) {
935 } else if (action
== actionCollection()->action(QStringLiteral("go_up"))) {
937 } else if (action
== actionCollection()->action(QStringLiteral("go_home"))) {
942 QAction
*DolphinMainWindow::urlNavigatorHistoryAction(const KUrlNavigator
*urlNavigator
, int historyIndex
, QObject
*parent
)
944 const QUrl url
= urlNavigator
->locationUrl(historyIndex
);
948 if (isSearchUrl(url
)) {
949 text
= Search::DolphinQuery(url
, QUrl
{}).title();
950 } else if (urlNavigator
->showFullPath()) {
951 text
= url
.toDisplayString(QUrl::PreferLocalFile
);
953 const KFilePlacesModel
*placesModel
= DolphinPlacesModelSingleton::instance().placesModel();
955 const QModelIndex closestIdx
= placesModel
->closestItem(url
);
956 if (closestIdx
.isValid()) {
957 const QUrl placeUrl
= placesModel
->url(closestIdx
);
959 text
= placesModel
->text(closestIdx
);
961 QString pathInsidePlace
= url
.path().mid(placeUrl
.path().length());
963 if (!pathInsidePlace
.isEmpty() && !pathInsidePlace
.startsWith(QLatin1Char('/'))) {
964 pathInsidePlace
.prepend(QLatin1Char('/'));
967 if (pathInsidePlace
!= QLatin1Char('/')) {
968 text
.append(pathInsidePlace
);
973 QAction
*action
= new QAction(QIcon::fromTheme(KIO::iconNameForUrl(url
)), text
, parent
);
974 action
->setData(historyIndex
);
978 void DolphinMainWindow::slotAboutToShowBackPopupMenu()
980 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
982 QMenu
*menu
= m_backAction
->popupMenu();
984 for (int i
= urlNavigator
->historyIndex() + 1; i
< urlNavigator
->historySize() && entries
< MaxNumberOfNavigationentries
; ++i
, ++entries
) {
985 QAction
*action
= urlNavigatorHistoryAction(urlNavigator
, i
, menu
);
986 menu
->addAction(action
);
990 void DolphinMainWindow::slotGoBack(QAction
*action
)
992 int gotoIndex
= action
->data().value
<int>();
993 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
994 for (int i
= gotoIndex
- urlNavigator
->historyIndex(); i
> 0; --i
) {
999 void DolphinMainWindow::slotBackForwardActionMiddleClicked(QAction
*action
)
1002 const KUrlNavigator
*urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
1003 openNewTab(urlNavigator
->locationUrl(action
->data().value
<int>()));
1007 void DolphinMainWindow::slotAboutToShowForwardPopupMenu()
1009 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
1011 QMenu
*menu
= m_forwardAction
->popupMenu();
1013 for (int i
= urlNavigator
->historyIndex() - 1; i
>= 0 && entries
< MaxNumberOfNavigationentries
; --i
, ++entries
) {
1014 QAction
*action
= urlNavigatorHistoryAction(urlNavigator
, i
, menu
);
1015 menu
->addAction(action
);
1019 void DolphinMainWindow::slotGoForward(QAction
*action
)
1021 int gotoIndex
= action
->data().value
<int>();
1022 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
1023 for (int i
= urlNavigator
->historyIndex() - gotoIndex
; i
> 0; --i
) {
1028 void DolphinMainWindow::slotSetSelectionMode(bool enabled
, SelectionMode::BottomBar::Contents bottomBarContents
)
1030 m_activeViewContainer
->setSelectionModeEnabled(enabled
, actionCollection(), bottomBarContents
);
1033 void DolphinMainWindow::selectAll()
1037 // if the URL navigator is editable and focused, select the whole
1038 // URL instead of all items of the view
1040 KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigator();
1041 QLineEdit
*lineEdit
= urlNavigator
->editor()->lineEdit();
1042 const bool selectUrl
= urlNavigator
->isUrlEditable() && lineEdit
->hasFocus();
1044 lineEdit
->selectAll();
1046 m_activeViewContainer
->view()->selectAll();
1050 void DolphinMainWindow::invertSelection()
1053 m_activeViewContainer
->view()->invertSelection();
1056 void DolphinMainWindow::toggleSplitView()
1058 QUrl newSplitViewUrl
;
1059 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
1060 if (list
.count() == 1) {
1061 const KFileItem
&item
= list
.first();
1062 newSplitViewUrl
= DolphinView::openItemAsFolderUrl(item
);
1065 DolphinTabPage
*tabPage
= m_tabWidget
->currentTabPage();
1066 tabPage
->setSplitViewEnabled(!tabPage
->splitViewEnabled(), WithAnimation
, newSplitViewUrl
);
1067 m_tabWidget
->updateTabName(m_tabWidget
->indexOf(tabPage
));
1068 updateViewActions();
1071 void DolphinMainWindow::popoutSplitView()
1073 DolphinTabPage
*tabPage
= m_tabWidget
->currentTabPage();
1074 if (!tabPage
->splitViewEnabled())
1076 openNewWindow((GeneralSettings::closeActiveSplitView() ? tabPage
->activeViewContainer() : tabPage
->inactiveViewContainer())->url());
1077 tabPage
->setSplitViewEnabled(false, WithAnimation
);
1078 updateSplitActions();
1081 void DolphinMainWindow::toggleSplitStash()
1083 DolphinTabPage
*tabPage
= m_tabWidget
->currentTabPage();
1084 tabPage
->setSplitViewEnabled(false, WithAnimation
);
1085 tabPage
->setSplitViewEnabled(true, WithAnimation
, QUrl("stash:/"));
1088 void DolphinMainWindow::copyToInactiveSplitView()
1090 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
1091 m_activeViewContainer
->setSelectionModeEnabled(true, actionCollection(), SelectionMode::BottomBar::Contents::CopyToOtherViewContents
);
1093 m_tabWidget
->copyToInactiveSplitView();
1094 m_activeViewContainer
->setSelectionModeEnabled(false);
1098 void DolphinMainWindow::moveToInactiveSplitView()
1100 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
1101 m_activeViewContainer
->setSelectionModeEnabled(true, actionCollection(), SelectionMode::BottomBar::Contents::MoveToOtherViewContents
);
1103 m_tabWidget
->moveToInactiveSplitView();
1104 m_activeViewContainer
->setSelectionModeEnabled(false);
1108 void DolphinMainWindow::reloadView()
1111 m_activeViewContainer
->reload();
1112 m_activeViewContainer
->statusBar()->updateSpaceInfo();
1115 void DolphinMainWindow::stopLoading()
1117 m_activeViewContainer
->view()->stopLoading();
1120 void DolphinMainWindow::enableStopAction()
1122 actionCollection()->action(QStringLiteral("stop"))->setEnabled(true);
1125 void DolphinMainWindow::disableStopAction()
1127 actionCollection()->action(QStringLiteral("stop"))->setEnabled(false);
1130 void DolphinMainWindow::toggleSelectionMode()
1132 const bool checked
= !m_activeViewContainer
->isSelectionModeEnabled();
1134 m_activeViewContainer
->setSelectionModeEnabled(checked
, actionCollection(), SelectionMode::BottomBar::Contents::GeneralContents
);
1135 actionCollection()->action(QStringLiteral("toggle_selection_mode"))->setChecked(checked
);
1138 void DolphinMainWindow::showFilterBar()
1140 m_activeViewContainer
->setFilterBarVisible(true);
1143 void DolphinMainWindow::toggleFilterBar()
1145 const bool checked
= !m_activeViewContainer
->isFilterBarVisible();
1146 m_activeViewContainer
->setFilterBarVisible(checked
);
1148 QAction
*toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
1149 toggleFilterBarAction
->setChecked(checked
);
1152 void DolphinMainWindow::toggleEditLocation()
1156 QAction
*action
= actionCollection()->action(QStringLiteral("editable_location"));
1157 KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigator();
1158 urlNavigator
->setUrlEditable(action
->isChecked());
1161 void DolphinMainWindow::replaceLocation()
1163 KUrlNavigator
*navigator
= m_activeViewContainer
->urlNavigator();
1164 QLineEdit
*lineEdit
= navigator
->editor()->lineEdit();
1166 // If the text field currently has focus and everything is selected,
1167 // pressing the keyboard shortcut returns the whole thing to breadcrumb mode
1168 // and goes back to the view, just like how it was before this action was triggered the first time.
1169 if (navigator
->isUrlEditable() && lineEdit
->hasFocus() && lineEdit
->selectedText() == lineEdit
->text()) {
1170 navigator
->setUrlEditable(false);
1171 m_activeViewContainer
->view()->setFocus();
1173 navigator
->setUrlEditable(true);
1174 navigator
->setFocus();
1175 lineEdit
->selectAll();
1179 void DolphinMainWindow::togglePanelLockState()
1181 const bool newLockState
= !GeneralSettings::lockPanels();
1182 const auto childrenObjects
= children();
1183 for (QObject
*child
: childrenObjects
) {
1184 DolphinDockWidget
*dock
= qobject_cast
<DolphinDockWidget
*>(child
);
1186 dock
->setLocked(newLockState
);
1190 DolphinPlacesModelSingleton::instance().placesModel()->setPanelsLocked(newLockState
);
1192 GeneralSettings::setLockPanels(newLockState
);
1195 void DolphinMainWindow::slotTerminalPanelVisibilityChanged(bool visible
)
1197 if (!visible
&& m_activeViewContainer
) {
1198 m_activeViewContainer
->view()->setFocus();
1200 // Putting focus to the Terminal is not handled here but in TerminalPanel::showEvent().
1203 void DolphinMainWindow::slotPlacesPanelVisibilityChanged(bool visible
)
1205 if (!visible
&& m_activeViewContainer
) {
1206 m_activeViewContainer
->view()->setFocus();
1209 m_placesPanel
->setFocus();
1212 void DolphinMainWindow::goBack()
1214 DolphinUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
1215 urlNavigator
->goBack();
1217 if (urlNavigator
->locationState().isEmpty()) {
1218 // An empty location state indicates a redirection URL,
1219 // which must be skipped too
1220 urlNavigator
->goBack();
1224 void DolphinMainWindow::goForward()
1226 m_activeViewContainer
->urlNavigatorInternalWithHistory()->goForward();
1229 void DolphinMainWindow::goUp()
1231 m_activeViewContainer
->urlNavigatorInternalWithHistory()->goUp();
1234 void DolphinMainWindow::goHome()
1236 m_activeViewContainer
->urlNavigatorInternalWithHistory()->goHome();
1239 void DolphinMainWindow::goBackInNewTab()
1241 const KUrlNavigator
*urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
1242 const int index
= urlNavigator
->historyIndex() + 1;
1243 openNewTab(urlNavigator
->locationUrl(index
));
1246 void DolphinMainWindow::goForwardInNewTab()
1248 const KUrlNavigator
*urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
1249 const int index
= urlNavigator
->historyIndex() - 1;
1250 openNewTab(urlNavigator
->locationUrl(index
));
1253 void DolphinMainWindow::goUpInNewTab()
1255 const QUrl currentUrl
= activeViewContainer()->urlNavigator()->locationUrl();
1256 openNewTab(KIO::upUrl(currentUrl
));
1259 void DolphinMainWindow::goHomeInNewTab()
1261 openNewTab(Dolphin::homeUrl());
1264 void DolphinMainWindow::compareFiles()
1266 const KFileItemList items
= m_tabWidget
->currentTabPage()->selectedItems();
1267 if (items
.count() != 2) {
1268 // The action is disabled in this case, but it could have been triggered
1269 // via D-Bus, see https://bugs.kde.org/show_bug.cgi?id=325517
1273 QUrl urlA
= items
.at(0).url();
1274 QUrl urlB
= items
.at(1).url();
1276 QString
command(QStringLiteral("kompare -c \""));
1277 command
.append(urlA
.toDisplayString(QUrl::PreferLocalFile
));
1278 command
.append("\" \"");
1279 command
.append(urlB
.toDisplayString(QUrl::PreferLocalFile
));
1280 command
.append('\"');
1282 KIO::CommandLauncherJob
*job
= new KIO::CommandLauncherJob(command
, this);
1283 job
->setDesktopName(QStringLiteral("org.kde.kompare"));
1287 void DolphinMainWindow::toggleShowMenuBar()
1289 const bool visible
= menuBar()->isVisible();
1290 menuBar()->setVisible(!visible
);
1293 QPointer
<QAction
> DolphinMainWindow::preferredSearchTool()
1295 m_searchTools
.clear();
1297 KService::Ptr kfind
= KService::serviceByDesktopName(QStringLiteral("org.kde.kfind"));
1303 auto *action
= new QAction(QIcon::fromTheme(kfind
->icon()), kfind
->name(), this);
1305 connect(action
, &QAction::triggered
, this, [this, kfind
] {
1306 auto *job
= new KIO::ApplicationLauncherJob(kfind
);
1307 job
->setUrls({m_activeViewContainer
->url()});
1314 void DolphinMainWindow::updateOpenPreferredSearchToolAction()
1316 QAction
*openPreferredSearchTool
= actionCollection()->action(QStringLiteral("open_preferred_search_tool"));
1317 if (!openPreferredSearchTool
) {
1320 QPointer
<QAction
> tool
= preferredSearchTool();
1322 openPreferredSearchTool
->setVisible(true);
1323 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open %1", tool
->text()));
1324 // Only override with the app icon if it is the default, i.e. the user hasn't configured one manually
1325 // https://bugs.kde.org/show_bug.cgi?id=442815
1326 if (openPreferredSearchTool
->icon().name() == QLatin1String("search")) {
1327 openPreferredSearchTool
->setIcon(tool
->icon());
1330 openPreferredSearchTool
->setVisible(false);
1331 // still visible in Shortcuts configuration window
1332 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool"));
1333 openPreferredSearchTool
->setIcon(QIcon::fromTheme(QStringLiteral("search")));
1337 void DolphinMainWindow::openPreferredSearchTool()
1339 QPointer
<QAction
> tool
= preferredSearchTool();
1345 void DolphinMainWindow::openTerminal()
1347 openTerminalJob(m_activeViewContainer
->url());
1350 void DolphinMainWindow::openTerminalHere()
1352 QList
<QUrl
> urls
= {};
1354 const auto selectedItems
= m_activeViewContainer
->view()->selectedItems();
1355 for (const KFileItem
&item
: selectedItems
) {
1356 QUrl url
= item
.targetUrl();
1357 if (item
.isFile()) {
1358 url
.setPath(QFileInfo(url
.path()).absolutePath());
1360 if (!urls
.contains(url
)) {
1365 // No items are selected. Open a terminal window for the current location.
1366 if (urls
.count() == 0) {
1371 if (urls
.count() > 5) {
1372 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());
1373 const int answer
= KMessageBox::warningContinueCancel(
1377 KGuiItem(i18ncp("@action:button", "Open %1 Terminal", "Open %1 Terminals", urls
.count()), QStringLiteral("utilities-terminal")),
1378 KStandardGuiItem::cancel(),
1379 QStringLiteral("ConfirmOpenManyTerminals"));
1380 if (answer
!= KMessageBox::PrimaryAction
&& answer
!= KMessageBox::Continue
) {
1385 for (const QUrl
&url
: std::as_const(urls
)) {
1386 openTerminalJob(url
);
1390 void DolphinMainWindow::openTerminalJob(const QUrl
&url
)
1392 if (url
.isLocalFile()) {
1393 auto job
= new KTerminalLauncherJob(QString());
1394 job
->setWorkingDirectory(url
.toLocalFile());
1399 // Not a local file, with protocol Class ":local", try stat'ing
1400 if (KProtocolInfo::protocolClass(url
.scheme()) == QLatin1String(":local")) {
1401 KIO::StatJob
*job
= KIO::mostLocalUrl(url
);
1402 KJobWidgets::setWindow(job
, this);
1403 connect(job
, &KJob::result
, this, [job
]() {
1405 if (!job
->error()) {
1406 statUrl
= job
->mostLocalUrl();
1409 auto job
= new KTerminalLauncherJob(QString());
1410 job
->setWorkingDirectory(statUrl
.isLocalFile() ? statUrl
.toLocalFile() : QDir::homePath());
1417 // Nothing worked, just use $HOME
1418 auto job
= new KTerminalLauncherJob(QString());
1419 job
->setWorkingDirectory(QDir::homePath());
1423 void DolphinMainWindow::editSettings()
1425 if (!m_settingsDialog
) {
1426 DolphinViewContainer
*container
= activeViewContainer();
1427 container
->view()->writeSettings();
1429 const QUrl url
= container
->url();
1430 DolphinSettingsDialog
*settingsDialog
= new DolphinSettingsDialog(url
, this, actionCollection());
1431 connect(settingsDialog
, &DolphinSettingsDialog::settingsChanged
, this, &DolphinMainWindow::refreshViews
);
1432 connect(settingsDialog
, &DolphinSettingsDialog::settingsChanged
, &DolphinUrlNavigatorsController::slotReadSettings
);
1433 settingsDialog
->setAttribute(Qt::WA_DeleteOnClose
);
1434 settingsDialog
->show();
1435 m_settingsDialog
= settingsDialog
;
1437 m_settingsDialog
.data()->raise();
1441 void DolphinMainWindow::handleUrl(const QUrl
&url
)
1443 delete m_lastHandleUrlOpenJob
;
1444 m_lastHandleUrlOpenJob
= nullptr;
1446 if (url
.isLocalFile() && QFileInfo(url
.toLocalFile()).isDir()) {
1447 activeViewContainer()->setUrl(url
);
1449 m_lastHandleUrlOpenJob
= new KIO::OpenUrlJob(url
);
1450 m_lastHandleUrlOpenJob
->setUiDelegate(KIO::createDefaultJobUiDelegate(KJobUiDelegate::AutoHandlingEnabled
, this));
1451 m_lastHandleUrlOpenJob
->setShowOpenOrExecuteDialog(true);
1453 connect(m_lastHandleUrlOpenJob
, &KIO::OpenUrlJob::mimeTypeFound
, this, [this, url
](const QString
&mimetype
) {
1454 if (mimetype
== QLatin1String("inode/directory")) {
1455 // If it's a dir, we'll take it from here
1456 m_lastHandleUrlOpenJob
->kill();
1457 m_lastHandleUrlOpenJob
= nullptr;
1458 activeViewContainer()->setUrl(url
);
1462 connect(m_lastHandleUrlOpenJob
, &KIO::OpenUrlJob::result
, this, [this]() {
1463 m_lastHandleUrlOpenJob
= nullptr;
1466 m_lastHandleUrlOpenJob
->start();
1470 void DolphinMainWindow::slotWriteStateChanged(bool isFolderWritable
)
1472 // trash:/ is writable but we don't want to create new items in it.
1473 // TODO: remove the trash check once https://phabricator.kde.org/T8234 is implemented
1474 newFileMenu()->setEnabled(isFolderWritable
&& m_activeViewContainer
->url().scheme() != QLatin1String("trash"));
1475 // 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.
1476 QTimer::singleShot(0, this, [this]() {
1477 m_disabledActionNotifier
->setDisabledReason(actionCollection()->action(QStringLiteral("create_file")),
1478 i18nc("@info", "Cannot create new file: You do not have permission to create items in this folder."));
1479 m_disabledActionNotifier
->setDisabledReason(actionCollection()->action(QStringLiteral("create_dir")),
1480 i18nc("@info", "Cannot create new folder: You do not have permission to create items in this folder."));
1484 void DolphinMainWindow::openContextMenu(const QPoint
&pos
, const KFileItem
&item
, const KFileItemList
&selectedItems
, const QUrl
&url
)
1486 QPointer
<DolphinContextMenu
> contextMenu
= new DolphinContextMenu(this, item
, selectedItems
, url
, &m_fileItemActions
);
1487 contextMenu
->exec(pos
);
1489 // Delete the menu, unless it has been deleted in its own nested event loop already.
1491 contextMenu
->deleteLater();
1495 QMenu
*DolphinMainWindow::createPopupMenu()
1497 QMenu
*menu
= KXmlGuiWindow::createPopupMenu();
1499 menu
->addSeparator();
1500 menu
->addAction(actionCollection()->action(QStringLiteral("lock_panels")));
1505 void DolphinMainWindow::updateHamburgerMenu()
1507 KActionCollection
*ac
= actionCollection();
1508 auto hamburgerMenu
= static_cast<KHamburgerMenu
*>(ac
->action(KStandardAction::name(KStandardAction::HamburgerMenu
)));
1509 auto menu
= hamburgerMenu
->menu();
1511 menu
= new QMenu(this);
1512 hamburgerMenu
->setMenu(menu
);
1513 hamburgerMenu
->hideActionsOf(ac
->action(QStringLiteral("basic_actions"))->menu());
1514 hamburgerMenu
->hideActionsOf(qobject_cast
<KToolBarPopupAction
*>(ac
->action(QStringLiteral("zoom")))->popupMenu());
1518 const QList
<QAction
*> toolbarActions
= toolBar()->actions();
1520 if (!toolBar()->isVisible()) {
1521 // If neither the menu bar nor the toolbar are visible, these actions should be available.
1522 menu
->addAction(ac
->action(KStandardAction::name(KStandardAction::ShowMenubar
)));
1523 menu
->addAction(toolBarMenuAction());
1524 menu
->addSeparator();
1527 // This group of actions (until the next separator) contains all the most basic actions
1528 // necessary to use Dolphin effectively.
1529 menu
->addAction(ac
->action(QStringLiteral("go_back")));
1530 menu
->addAction(ac
->action(QStringLiteral("go_forward")));
1532 menu
->addMenu(m_newFileMenu
->menu());
1533 if (!toolBar()->isVisible() || !toolbarActions
.contains(ac
->action(QStringLiteral("toggle_selection_mode_tool_bar")))) {
1534 menu
->addAction(ac
->action(QStringLiteral("toggle_selection_mode")));
1536 menu
->addAction(ac
->action(QStringLiteral("basic_actions")));
1537 menu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Undo
)));
1538 if (!toolBar()->isVisible()
1539 || (!toolbarActions
.contains(ac
->action(QStringLiteral("toggle_search")))
1540 && !toolbarActions
.contains(ac
->action(QStringLiteral("open_preferred_search_tool"))))) {
1541 menu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Find
)));
1542 // This way a search action will only be added if none of the three available
1543 // search actions is present on the toolbar.
1545 if (!toolBar()->isVisible() || !toolbarActions
.contains(ac
->action(QStringLiteral("toggle_filter")))) {
1546 menu
->addAction(ac
->action(QStringLiteral("show_filter_bar")));
1547 // This way a filter action will only be added if none of the two available
1548 // filter actions is present on the toolbar.
1550 menu
->addSeparator();
1552 // The second group of actions (up until the next separator) contains actions for opening
1553 // additional views to interact with the file system.
1554 menu
->addAction(ac
->action(QStringLiteral("file_new")));
1555 menu
->addAction(ac
->action(QStringLiteral("new_tab")));
1556 if (ac
->action(QStringLiteral("undo_close_tab"))->isEnabled()) {
1557 menu
->addAction(ac
->action(QStringLiteral("closed_tabs")));
1559 menu
->addAction(ac
->action(QStringLiteral("open_terminal")));
1560 menu
->addSeparator();
1562 // The third group contains actions to change what one sees in the view
1563 // and to change the more general UI.
1564 if (!toolBar()->isVisible()
1565 || ((!toolbarActions
.contains(ac
->action(QStringLiteral("icons"))) && !toolbarActions
.contains(ac
->action(QStringLiteral("compact")))
1566 && !toolbarActions
.contains(ac
->action(QStringLiteral("details"))) && !toolbarActions
.contains(ac
->action(QStringLiteral("view_mode"))))
1567 && !toolbarActions
.contains(ac
->action(QStringLiteral("view_settings"))))) {
1568 menu
->addAction(ac
->action(QStringLiteral("view_mode")));
1570 if (!toolBar()->isVisible() || !toolbarActions
.contains(ac
->action(QStringLiteral("view_settings")))) {
1571 menu
->addAction(ac
->action(QStringLiteral("show_hidden_files")));
1572 menu
->addAction(ac
->action(QStringLiteral("sort")));
1573 menu
->addAction(ac
->action(QStringLiteral("additional_info")));
1574 if (!GeneralSettings::showStatusBar() || !GeneralSettings::showZoomSlider()) {
1575 menu
->addAction(ac
->action(QStringLiteral("zoom")));
1578 menu
->addAction(ac
->action(QStringLiteral("panels")));
1580 // The "Configure" menu is not added to the actionCollection() because there is hardly
1581 // a good reason for users to put it on their toolbar.
1582 auto configureMenu
= menu
->addMenu(QIcon::fromTheme(QStringLiteral("configure")), i18nc("@action:inmenu menu for configure actions", "Configure"));
1583 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::SwitchApplicationLanguage
)));
1584 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::KeyBindings
)));
1585 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::ConfigureToolbars
)));
1586 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Preferences
)));
1587 hamburgerMenu
->hideActionsOf(configureMenu
);
1590 void DolphinMainWindow::slotPlaceActivated(const QUrl
&url
)
1592 DolphinViewContainer
*view
= activeViewContainer();
1594 if (view
->url() == url
) {
1595 view
->clearFilterBar(); // Fixes bug 259382.
1597 // We can end up here if the user clicked a device in the Places Panel
1598 // which had been unmounted earlier, see https://bugs.kde.org/show_bug.cgi?id=161385.
1601 m_activeViewContainer
->view()->setFocus(); // We always want the focus on the view after activating a place.
1603 view
->disableUrlNavigatorSelectionRequests();
1605 view
->enableUrlNavigatorSelectionRequests();
1609 void DolphinMainWindow::closedTabsCountChanged(unsigned int count
)
1611 actionCollection()->action(QStringLiteral("undo_close_tab"))->setEnabled(count
> 0);
1614 void DolphinMainWindow::activeViewChanged(DolphinViewContainer
*viewContainer
)
1616 DolphinViewContainer
*oldViewContainer
= m_activeViewContainer
;
1617 Q_ASSERT(viewContainer
);
1619 m_activeViewContainer
= viewContainer
;
1621 if (oldViewContainer
) {
1622 // Disconnect all signals between the old view container (container,
1623 // view and url navigator) and main window.
1624 oldViewContainer
->disconnect(this);
1625 oldViewContainer
->view()->disconnect(this);
1626 oldViewContainer
->urlNavigatorInternalWithHistory()->disconnect(this);
1627 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>(actionCollection()->action(QStringLiteral("url_navigators")));
1628 navigators
->primaryUrlNavigator()->disconnect(this);
1629 if (auto secondaryUrlNavigator
= navigators
->secondaryUrlNavigator()) {
1630 secondaryUrlNavigator
->disconnect(this);
1632 oldViewContainer
->disconnect(m_diskSpaceUsageMenu
);
1634 // except the requestItemInfo so that on hover the information panel can still be updated
1635 connect(oldViewContainer
->view(), &DolphinView::requestItemInfo
, this, &DolphinMainWindow::requestItemInfo
);
1637 // Disconnect other slots.
1638 disconnect(oldViewContainer
,
1639 &DolphinViewContainer::selectionModeChanged
,
1640 actionCollection()->action(QStringLiteral("toggle_selection_mode")),
1641 &QAction::setChecked
);
1644 connectViewSignals(viewContainer
);
1646 m_actionHandler
->setCurrentView(viewContainer
->view());
1649 updateFileAndEditActions();
1650 updatePasteAction();
1651 updateViewActions();
1653 updateSearchAction();
1654 connect(m_diskSpaceUsageMenu
,
1655 &DiskSpaceUsageMenu::showMessage
,
1657 [viewContainer
](const QString
&message
, KMessageWidget::MessageType messageType
) {
1658 viewContainer
->showMessage(message
, messageType
);
1660 connect(m_diskSpaceUsageMenu
, &DiskSpaceUsageMenu::showInstallationProgress
, viewContainer
, &DolphinViewContainer::showProgress
);
1662 const QUrl url
= viewContainer
->url();
1663 Q_EMIT
urlChanged(url
);
1664 Q_EMIT
selectionChanged(m_activeViewContainer
->view()->selectedItems());
1667 void DolphinMainWindow::tabCountChanged(int count
)
1669 const bool enableTabActions
= (count
> 1);
1670 for (int i
= 0; i
< MaxActivateTabShortcuts
; ++i
) {
1671 actionCollection()->action(QStringLiteral("activate_tab_%1").arg(i
))->setEnabled(enableTabActions
);
1673 actionCollection()->action(QStringLiteral("activate_last_tab"))->setEnabled(enableTabActions
);
1674 actionCollection()->action(QStringLiteral("activate_next_tab"))->setEnabled(enableTabActions
);
1675 actionCollection()->action(QStringLiteral("activate_prev_tab"))->setEnabled(enableTabActions
);
1678 void DolphinMainWindow::updateWindowTitle()
1680 const QString newTitle
= m_activeViewContainer
->captionWindowTitle();
1681 if (windowTitle() != newTitle
) {
1682 setWindowTitle(newTitle
);
1686 void DolphinMainWindow::slotStorageTearDownFromPlacesRequested(const QString
&mountPath
)
1688 connect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, this, [this, mountPath
]() {
1689 setViewsToHomeIfMountPathOpen(mountPath
);
1692 if (m_terminalPanel
&& m_terminalPanel
->currentWorkingDirectoryIsChildOf(mountPath
)) {
1693 m_tearDownFromPlacesRequested
= true;
1694 m_terminalPanel
->goHome();
1695 // m_placesPanel->proceedWithTearDown() will be called in slotTerminalDirectoryChanged
1697 m_placesPanel
->proceedWithTearDown();
1701 void DolphinMainWindow::slotStorageTearDownExternallyRequested(const QString
&mountPath
)
1703 connect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, this, [this, mountPath
]() {
1704 setViewsToHomeIfMountPathOpen(mountPath
);
1707 if (m_terminalPanel
&& m_terminalPanel
->currentWorkingDirectoryIsChildOf(mountPath
)) {
1708 m_tearDownFromPlacesRequested
= false;
1709 m_terminalPanel
->goHome();
1713 void DolphinMainWindow::slotKeyBindings()
1715 KShortcutsDialog
dialog(KShortcutsEditor::AllActions
, KShortcutsEditor::LetterShortcutsAllowed
, this);
1716 dialog
.addCollection(actionCollection());
1717 if (m_terminalPanel
) {
1718 KActionCollection
*konsolePartActionCollection
= m_terminalPanel
->actionCollection();
1719 if (konsolePartActionCollection
) {
1720 dialog
.addCollection(konsolePartActionCollection
, QStringLiteral("KonsolePart"));
1726 void DolphinMainWindow::setViewsToHomeIfMountPathOpen(const QString
&mountPath
)
1728 const QVector
<DolphinViewContainer
*> theViewContainers
= viewContainers();
1729 for (DolphinViewContainer
*viewContainer
: theViewContainers
) {
1730 if (!viewContainer
) {
1733 const auto viewPath
= viewContainer
->url().toLocalFile();
1734 if (viewPath
.startsWith(mountPath
+ QLatin1String("/")) || viewPath
== mountPath
) {
1735 viewContainer
->setUrl(QUrl::fromLocalFile(QDir::homePath()));
1738 disconnect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, nullptr, nullptr);
1741 void DolphinMainWindow::setupActions()
1743 auto hamburgerMenuAction
= KStandardAction::hamburgerMenu(nullptr, nullptr, actionCollection());
1745 // setup 'File' menu
1746 m_newFileMenu
= new DolphinNewFileMenu(nullptr, nullptr, this);
1747 actionCollection()->addAction(QStringLiteral("new_menu"), m_newFileMenu
);
1748 QMenu
*menu
= m_newFileMenu
->menu();
1749 menu
->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1750 menu
->setIcon(QIcon::fromTheme(QStringLiteral("list-add")));
1751 m_newFileMenu
->setPopupMode(QToolButton::InstantPopup
);
1752 connect(menu
, &QMenu::aboutToShow
, this, &DolphinMainWindow::updateNewMenu
);
1754 QAction
*newWindow
= KStandardAction::openNew(this, &DolphinMainWindow::openNewMainWindow
, actionCollection());
1755 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
1756 newWindow
->setToolTip(i18nc("@info", "Open a new Dolphin window"));
1757 newWindow
->setWhatsThis(xi18nc("@info:whatsthis",
1759 "window just like this one with the current location."
1760 "<nl/>You can drag and drop items between windows."));
1761 newWindow
->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
1763 QAction
*newTab
= actionCollection()->addAction(QStringLiteral("new_tab"));
1764 newTab
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1765 newTab
->setText(i18nc("@action:inmenu File", "New Tab"));
1766 newTab
->setWhatsThis(xi18nc("@info:whatsthis",
1768 "<emphasis>Tab</emphasis> with the current location."
1769 "<nl/>Tabs allow you to quickly switch between multiple locations and views within this window. "
1770 "You can drag and drop items between tabs."));
1771 actionCollection()->setDefaultShortcut(newTab
, Qt::CTRL
| Qt::Key_T
);
1772 connect(newTab
, &QAction::triggered
, this, &DolphinMainWindow::openNewActivatedTab
);
1774 QAction
*addToPlaces
= actionCollection()->addAction(QStringLiteral("add_to_places"));
1775 addToPlaces
->setIcon(QIcon::fromTheme(QStringLiteral("bookmark-new")));
1776 addToPlaces
->setText(i18nc("@action:inmenu Add current folder to places", "Add to Places"));
1777 addToPlaces
->setWhatsThis(xi18nc("@info:whatsthis",
1778 "This adds the selected folder "
1779 "to the Places panel."));
1780 connect(addToPlaces
, &QAction::triggered
, this, &DolphinMainWindow::addToPlaces
);
1782 QAction
*closeTab
= KStandardAction::close(m_tabWidget
, QOverload
<>::of(&DolphinTabWidget::closeTab
), actionCollection());
1783 closeTab
->setText(i18nc("@action:inmenu File", "Close Tab"));
1784 closeTab
->setToolTip(i18nc("@info", "Close Tab"));
1785 closeTab
->setWhatsThis(i18nc("@info:whatsthis",
1787 "currently viewed tab. If no more tabs are left, this closes "
1788 "the whole window instead."));
1790 QAction
*quitAction
= KStandardAction::quit(this, &DolphinMainWindow::quit
, actionCollection());
1791 quitAction
->setWhatsThis(i18nc("@info:whatsthis quit", "This closes this window."));
1793 // setup 'Edit' menu
1794 KStandardAction::undo(this, &DolphinMainWindow::undo
, actionCollection());
1796 // i18n: This will be the last paragraph for the whatsthis for all three:
1797 // Cut, Copy and Paste
1798 const QString cutCopyPastePara
= xi18nc("@info:whatsthis",
1799 "<para><emphasis>Cut, "
1800 "Copy</emphasis> and <emphasis>Paste</emphasis> work between many "
1801 "applications and are among the most used commands. That's why their "
1802 "<emphasis>keyboard shortcuts</emphasis> are prominently placed right "
1803 "next to each other on the keyboard: <shortcut>Ctrl+X</shortcut>, "
1804 "<shortcut>Ctrl+C</shortcut> and <shortcut>Ctrl+V</shortcut>.</para>");
1805 QAction
*cutAction
= KStandardAction::cut(this, &DolphinMainWindow::cut
, actionCollection());
1806 m_actionTextHelper
->registerTextWhenNothingIsSelected(cutAction
, i18nc("@action", "Cut…"));
1807 cutAction
->setWhatsThis(xi18nc("@info:whatsthis cut",
1808 "This copies the items "
1809 "in your current selection to the <emphasis>clipboard</emphasis>.<nl/>"
1810 "Use the <emphasis>Paste</emphasis> action afterwards to copy them from "
1811 "the clipboard to a new location. The items will be removed from their "
1812 "initial location.")
1813 + cutCopyPastePara
);
1814 QAction
*copyAction
= KStandardAction::copy(this, &DolphinMainWindow::copy
, actionCollection());
1815 m_actionTextHelper
->registerTextWhenNothingIsSelected(copyAction
, i18nc("@action", "Copy…"));
1816 copyAction
->setWhatsThis(xi18nc("@info:whatsthis copy",
1818 "items in your current selection to the <emphasis>clipboard</emphasis>."
1819 "<nl/>Use the <emphasis>Paste</emphasis> action afterwards to copy them "
1820 "from the clipboard to a new location.")
1821 + cutCopyPastePara
);
1822 QAction
*paste
= KStandardAction::paste(this, &DolphinMainWindow::paste
, actionCollection());
1823 // The text of the paste-action is modified dynamically by Dolphin
1824 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1825 // due to the long text, the text "Paste" is used:
1826 paste
->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1827 paste
->setWhatsThis(xi18nc("@info:whatsthis paste",
1828 "This copies the items from "
1829 "your <emphasis>clipboard</emphasis> to the currently viewed folder.<nl/>"
1830 "If the items were added to the clipboard by the <emphasis>Cut</emphasis> "
1831 "action they are removed from their old location.")
1832 + cutCopyPastePara
);
1834 QAction
*copyToOtherViewAction
= actionCollection()->addAction(QStringLiteral("copy_to_inactive_split_view"));
1835 copyToOtherViewAction
->setText(i18nc("@action:inmenu", "Copy to Other View"));
1836 m_actionTextHelper
->registerTextWhenNothingIsSelected(copyToOtherViewAction
, i18nc("@action:inmenu", "Copy to Other View…"));
1837 copyToOtherViewAction
->setWhatsThis(xi18nc("@info:whatsthis Copy",
1838 "This copies the selected items from "
1839 "the view in focus to the other view. "
1840 "(Only available while in Split View mode.)"));
1841 copyToOtherViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("edit-copy")));
1842 copyToOtherViewAction
->setIconText(i18nc("@action:inmenu Edit", "Copy to Other View"));
1843 actionCollection()->setDefaultShortcut(copyToOtherViewAction
, Qt::SHIFT
| Qt::Key_F5
);
1844 connect(copyToOtherViewAction
, &QAction::triggered
, this, &DolphinMainWindow::copyToInactiveSplitView
);
1846 QAction
*moveToOtherViewAction
= actionCollection()->addAction(QStringLiteral("move_to_inactive_split_view"));
1847 moveToOtherViewAction
->setText(i18nc("@action:inmenu", "Move to Other View"));
1848 m_actionTextHelper
->registerTextWhenNothingIsSelected(moveToOtherViewAction
, i18nc("@action:inmenu", "Move to Other View…"));
1849 moveToOtherViewAction
->setWhatsThis(xi18nc("@info:whatsthis Move",
1850 "This moves the selected items from "
1851 "the view in focus to the other view. "
1852 "(Only available while in Split View mode.)"));
1853 moveToOtherViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("edit-cut")));
1854 moveToOtherViewAction
->setIconText(i18nc("@action:inmenu Edit", "Move to Other View"));
1855 actionCollection()->setDefaultShortcut(moveToOtherViewAction
, Qt::SHIFT
| Qt::Key_F6
);
1856 connect(moveToOtherViewAction
, &QAction::triggered
, this, &DolphinMainWindow::moveToInactiveSplitView
);
1858 QAction
*showFilterBar
= actionCollection()->addAction(QStringLiteral("show_filter_bar"));
1859 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Filter…"));
1860 showFilterBar
->setToolTip(i18nc("@info:tooltip", "Show Filter Bar"));
1861 showFilterBar
->setWhatsThis(xi18nc("@info:whatsthis",
1863 "<emphasis>Filter Bar</emphasis> at the bottom of the window.<nl/> "
1864 "There you can enter text to filter the files and folders currently displayed. "
1865 "Only those that contain the text in their name will be kept in view."));
1866 showFilterBar
->setIcon(QIcon::fromTheme(QStringLiteral("view-filter")));
1867 actionCollection()->setDefaultShortcuts(showFilterBar
, {Qt::CTRL
| Qt::Key_I
, Qt::Key_Slash
});
1868 connect(showFilterBar
, &QAction::triggered
, this, &DolphinMainWindow::showFilterBar
);
1870 // toggle_filter acts as a copy of the main showFilterBar to be used mainly
1871 // in the toolbar, with no default shortcut attached, to avoid messing with
1872 // existing workflows (filter bar always open and Ctrl-I to focus)
1873 QAction
*toggleFilter
= actionCollection()->addAction(QStringLiteral("toggle_filter"));
1874 toggleFilter
->setText(i18nc("@action:inmenu", "Toggle Filter Bar"));
1875 toggleFilter
->setIconText(i18nc("@action:intoolbar", "Filter"));
1876 toggleFilter
->setIcon(showFilterBar
->icon());
1877 toggleFilter
->setToolTip(showFilterBar
->toolTip());
1878 toggleFilter
->setWhatsThis(showFilterBar
->whatsThis());
1879 toggleFilter
->setCheckable(true);
1880 connect(toggleFilter
, &QAction::triggered
, this, &DolphinMainWindow::toggleFilterBar
);
1882 QAction
*searchAction
= KStandardAction::find(this, &DolphinMainWindow::find
, actionCollection());
1883 searchAction
->setText(i18n("Search…"));
1884 searchAction
->setToolTip(i18nc("@info:tooltip", "Search for files and folders"));
1885 searchAction
->setWhatsThis(xi18nc("@info:whatsthis find",
1886 "<para>This helps you "
1887 "find files and folders by opening a <emphasis>search bar</emphasis>. "
1888 "There you can enter search terms and specify settings to find the "
1889 "items you are looking for.</para>"));
1891 // toggle_search acts as a copy of the main searchAction to be used mainly
1892 // in the toolbar, with no default shortcut attached, to avoid messing with
1893 // existing workflows (search bar always open and Ctrl-F to focus)
1894 QAction
*toggleSearchAction
= actionCollection()->addAction(QStringLiteral("toggle_search"));
1895 toggleSearchAction
->setText(i18nc("@action:inmenu", "Toggle Search Bar"));
1896 toggleSearchAction
->setIconText(i18nc("@action:intoolbar", "Search"));
1897 toggleSearchAction
->setIcon(searchAction
->icon());
1898 toggleSearchAction
->setToolTip(searchAction
->toolTip());
1899 toggleSearchAction
->setWhatsThis(searchAction
->whatsThis());
1900 toggleSearchAction
->setCheckable(true);
1901 connect(toggleSearchAction
, &QAction::triggered
, this, [this](bool checked
) {
1905 m_activeViewContainer
->setSearchBarVisible(false);
1909 QAction
*toggleSelectionModeAction
= actionCollection()->addAction(QStringLiteral("toggle_selection_mode"));
1910 // i18n: This action toggles a selection mode.
1911 toggleSelectionModeAction
->setText(i18nc("@action:inmenu", "Select Files and Folders"));
1912 // i18n: Opens a selection mode for selecting files/folders.
1913 // The text is kept so unspecific because it will be shown on the toolbar where space is at a premium.
1914 toggleSelectionModeAction
->setIconText(i18nc("@action:intoolbar", "Select"));
1915 toggleSelectionModeAction
->setWhatsThis(xi18nc(
1917 "<para>This application only knows which files or folders should be acted on if they are"
1918 " <emphasis>selected</emphasis> first. Press this to toggle a <emphasis>Selection Mode</emphasis> which makes selecting and deselecting as easy as "
1919 "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."
1921 toggleSelectionModeAction
->setIcon(QIcon::fromTheme(QStringLiteral("quickwizard")));
1922 toggleSelectionModeAction
->setCheckable(true);
1923 actionCollection()->setDefaultShortcut(toggleSelectionModeAction
, Qt::Key_Space
);
1924 connect(toggleSelectionModeAction
, &QAction::triggered
, this, &DolphinMainWindow::toggleSelectionMode
);
1926 // A special version of the toggleSelectionModeAction for the toolbar that also contains a menu
1927 // with the selectAllAction and invertSelectionAction.
1928 auto *toggleSelectionModeToolBarAction
=
1929 new KToolBarPopupAction(toggleSelectionModeAction
->icon(), toggleSelectionModeAction
->iconText(), actionCollection());
1930 toggleSelectionModeToolBarAction
->setToolTip(toggleSelectionModeAction
->text());
1931 toggleSelectionModeToolBarAction
->setWhatsThis(toggleSelectionModeAction
->whatsThis());
1932 actionCollection()->addAction(QStringLiteral("toggle_selection_mode_tool_bar"), toggleSelectionModeToolBarAction
);
1933 toggleSelectionModeToolBarAction
->setCheckable(true);
1934 toggleSelectionModeToolBarAction
->setPopupMode(KToolBarPopupAction::DelayedPopup
);
1935 connect(toggleSelectionModeToolBarAction
, &QAction::triggered
, toggleSelectionModeAction
, &QAction::trigger
);
1936 connect(toggleSelectionModeAction
, &QAction::toggled
, toggleSelectionModeToolBarAction
, &QAction::setChecked
);
1938 QAction
*selectAllAction
= KStandardAction::selectAll(this, &DolphinMainWindow::selectAll
, actionCollection());
1939 selectAllAction
->setWhatsThis(xi18nc("@info:whatsthis",
1941 "files and folders in the current location."));
1943 QAction
*invertSelection
= actionCollection()->addAction(QStringLiteral("invert_selection"));
1944 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1945 invertSelection
->setWhatsThis(xi18nc("@info:whatsthis invert",
1947 "items that you have currently <emphasis>not</emphasis> selected instead."));
1948 invertSelection
->setIcon(QIcon::fromTheme(QStringLiteral("edit-select-invert")));
1949 actionCollection()->setDefaultShortcut(invertSelection
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
1950 connect(invertSelection
, &QAction::triggered
, this, &DolphinMainWindow::invertSelection
);
1952 QMenu
*toggleSelectionModeActionMenu
= new QMenu(this);
1953 toggleSelectionModeActionMenu
->addAction(selectAllAction
);
1954 toggleSelectionModeActionMenu
->addAction(invertSelection
);
1955 toggleSelectionModeToolBarAction
->setMenu(toggleSelectionModeActionMenu
);
1957 // setup 'View' menu
1958 // (note that most of it is set up in DolphinViewActionHandler)
1960 Admin::WorkerIntegration::createActAsAdminAction(actionCollection(), this);
1962 m_splitViewAction
= actionCollection()->add
<KActionMenu
>(QStringLiteral("split_view"));
1963 m_splitViewMenuAction
= actionCollection()->addAction(QStringLiteral("split_view_menu"));
1965 m_splitViewAction
->setWhatsThis(xi18nc("@info:whatsthis split",
1966 "<para>This presents "
1967 "a second view side-by-side with the current view, so you can see "
1968 "the contents of two folders at once and easily move items between "
1969 "them.</para><para>The view that is not \"in focus\" will be dimmed. "
1970 "</para>Click this button again to close one of the views."));
1971 m_splitViewMenuAction
->setWhatsThis(m_splitViewAction
->whatsThis());
1973 // only set it for the menu version
1974 actionCollection()->setDefaultShortcut(m_splitViewMenuAction
, Qt::Key_F3
);
1976 connect(m_splitViewAction
, &QAction::triggered
, this, &DolphinMainWindow::toggleSplitView
);
1977 connect(m_splitViewMenuAction
, &QAction::triggered
, this, &DolphinMainWindow::toggleSplitView
);
1979 QAction
*popoutSplit
= actionCollection()->addAction(QStringLiteral("popout_split_view"));
1980 popoutSplit
->setWhatsThis(xi18nc("@info:whatsthis",
1981 "If the view has been split, this will pop the view in focus "
1982 "out into a new window."));
1983 popoutSplit
->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
1984 actionCollection()->setDefaultShortcut(popoutSplit
, Qt::SHIFT
| Qt::Key_F3
);
1985 connect(popoutSplit
, &QAction::triggered
, this, &DolphinMainWindow::popoutSplitView
);
1987 QAction
*stashSplit
= actionCollection()->addAction(QStringLiteral("split_stash"));
1988 actionCollection()->setDefaultShortcut(stashSplit
, Qt::CTRL
| Qt::Key_S
);
1989 stashSplit
->setText(i18nc("@action:intoolbar Stash", "Stash"));
1990 stashSplit
->setToolTip(i18nc("@info", "Opens the stash virtual directory in a split window"));
1991 stashSplit
->setIcon(QIcon::fromTheme(QStringLiteral("folder-stash")));
1992 stashSplit
->setCheckable(false);
1993 QDBusConnectionInterface
*sessionInterface
= QDBusConnection::sessionBus().interface();
1994 stashSplit
->setVisible(sessionInterface
&& sessionInterface
->isServiceRegistered(QStringLiteral("org.kde.kio.StashNotifier")));
1995 connect(stashSplit
, &QAction::triggered
, this, &DolphinMainWindow::toggleSplitStash
);
1997 QAction
*redisplay
= KStandardAction::redisplay(this, &DolphinMainWindow::reloadView
, actionCollection());
1998 redisplay
->setToolTip(i18nc("@info:tooltip", "Refresh view"));
1999 redisplay
->setWhatsThis(xi18nc("@info:whatsthis refresh",
2000 "<para>This refreshes "
2001 "the folder view.</para>"
2002 "<para>If the contents of this folder have changed, refreshing will re-scan this folder "
2003 "and show you a newly-updated view of the files and folders contained here.</para>"
2004 "<para>If the view is split, this refreshes the one that is currently in focus.</para>"));
2006 QAction
*stop
= actionCollection()->addAction(QStringLiteral("stop"));
2007 stop
->setText(i18nc("@action:inmenu View", "Stop"));
2008 stop
->setToolTip(i18nc("@info", "Stop loading"));
2009 stop
->setWhatsThis(i18nc("@info", "This stops the loading of the contents of the current folder."));
2010 stop
->setIcon(QIcon::fromTheme(QStringLiteral("process-stop")));
2011 connect(stop
, &QAction::triggered
, this, &DolphinMainWindow::stopLoading
);
2013 KToggleAction
*editableLocation
= actionCollection()->add
<KToggleAction
>(QStringLiteral("editable_location"));
2014 editableLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
2015 editableLocation
->setWhatsThis(xi18nc("@info:whatsthis",
2016 "This toggles the <emphasis>Location Bar</emphasis> to be "
2017 "editable so you can directly enter a location you want to go to.<nl/>"
2018 "You can also switch to editing by clicking to the right of the "
2019 "location and switch back by confirming the edited location."));
2020 actionCollection()->setDefaultShortcut(editableLocation
, Qt::Key_F6
);
2021 connect(editableLocation
, &KToggleAction::triggered
, this, &DolphinMainWindow::toggleEditLocation
);
2023 QAction
*replaceLocation
= actionCollection()->addAction(QStringLiteral("replace_location"));
2024 replaceLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
2025 // i18n: "enter" is used both in the meaning of "writing" and "going to" a new location here.
2026 // Both meanings are useful but not necessary to understand the use of "Replace Location".
2027 // So you might want to be more verbose in your language to convey the meaning but it's up to you.
2028 replaceLocation
->setWhatsThis(xi18nc("@info:whatsthis",
2029 "This switches to editing the location and selects it "
2030 "so you can quickly enter a different location."));
2031 actionCollection()->setDefaultShortcuts(replaceLocation
, {Qt::CTRL
| Qt::Key_L
, Qt::ALT
| Qt::Key_D
});
2032 connect(replaceLocation
, &QAction::triggered
, this, &DolphinMainWindow::replaceLocation
);
2036 QScopedPointer
<QAction
> backAction(KStandardAction::back(nullptr, nullptr, nullptr));
2037 m_backAction
= new KToolBarPopupAction(backAction
->icon(), backAction
->text(), actionCollection());
2038 m_backAction
->setObjectName(backAction
->objectName());
2039 m_backAction
->setShortcuts(backAction
->shortcuts());
2041 m_backAction
->setPopupMode(KToolBarPopupAction::DelayedPopup
);
2042 connect(m_backAction
, &QAction::triggered
, this, &DolphinMainWindow::goBack
);
2043 connect(m_backAction
->popupMenu(), &QMenu::aboutToShow
, this, &DolphinMainWindow::slotAboutToShowBackPopupMenu
);
2044 connect(m_backAction
->popupMenu(), &QMenu::triggered
, this, &DolphinMainWindow::slotGoBack
);
2045 actionCollection()->addAction(m_backAction
->objectName(), m_backAction
);
2047 auto backShortcuts
= m_backAction
->shortcuts();
2048 // Prepend this shortcut, to avoid being hidden by the two-slot UI (#371130)
2049 backShortcuts
.prepend(QKeySequence(Qt::Key_Backspace
));
2050 actionCollection()->setDefaultShortcuts(m_backAction
, backShortcuts
);
2052 DolphinRecentTabsMenu
*recentTabsMenu
= new DolphinRecentTabsMenu(this);
2053 actionCollection()->addAction(QStringLiteral("closed_tabs"), recentTabsMenu
);
2054 connect(m_tabWidget
, &DolphinTabWidget::rememberClosedTab
, recentTabsMenu
, &DolphinRecentTabsMenu::rememberClosedTab
);
2055 connect(recentTabsMenu
, &DolphinRecentTabsMenu::restoreClosedTab
, m_tabWidget
, &DolphinTabWidget::restoreClosedTab
);
2056 connect(recentTabsMenu
, &DolphinRecentTabsMenu::closedTabsCountChanged
, this, &DolphinMainWindow::closedTabsCountChanged
);
2058 QAction
*undoCloseTab
= actionCollection()->addAction(QStringLiteral("undo_close_tab"));
2059 undoCloseTab
->setText(i18nc("@action:inmenu File", "Undo close tab"));
2060 undoCloseTab
->setWhatsThis(i18nc("@info:whatsthis undo close tab", "This returns you to the previously closed tab."));
2061 actionCollection()->setDefaultShortcut(undoCloseTab
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_T
);
2062 undoCloseTab
->setIcon(QIcon::fromTheme(QStringLiteral("edit-undo")));
2063 undoCloseTab
->setEnabled(false);
2064 connect(undoCloseTab
, &QAction::triggered
, recentTabsMenu
, &DolphinRecentTabsMenu::undoCloseTab
);
2066 auto undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
2067 undoAction
->setWhatsThis(xi18nc("@info:whatsthis",
2069 "the last change you made to files or folders.<nl/>"
2070 "Such changes include <interface>creating</interface>, <interface>renaming</interface> "
2071 "and <interface>moving</interface> them to a different location "
2072 "or to the <filename>Trash</filename>. <nl/>Any changes that cannot be undone "
2073 "will ask for your confirmation beforehand."));
2074 undoAction
->setEnabled(false); // undo should be disabled by default
2077 QScopedPointer
<QAction
> forwardAction(KStandardAction::forward(nullptr, nullptr, nullptr));
2078 m_forwardAction
= new KToolBarPopupAction(forwardAction
->icon(), forwardAction
->text(), actionCollection());
2079 m_forwardAction
->setObjectName(forwardAction
->objectName());
2080 m_forwardAction
->setShortcuts(forwardAction
->shortcuts());
2082 m_forwardAction
->setPopupMode(KToolBarPopupAction::DelayedPopup
);
2083 connect(m_forwardAction
, &QAction::triggered
, this, &DolphinMainWindow::goForward
);
2084 connect(m_forwardAction
->popupMenu(), &QMenu::aboutToShow
, this, &DolphinMainWindow::slotAboutToShowForwardPopupMenu
);
2085 connect(m_forwardAction
->popupMenu(), &QMenu::triggered
, this, &DolphinMainWindow::slotGoForward
);
2086 actionCollection()->addAction(m_forwardAction
->objectName(), m_forwardAction
);
2087 actionCollection()->setDefaultShortcuts(m_forwardAction
, m_forwardAction
->shortcuts());
2089 // enable middle-click to open in a new tab
2090 auto *middleClickEventFilter
= new MiddleClickActionEventFilter(this);
2091 connect(middleClickEventFilter
, &MiddleClickActionEventFilter::actionMiddleClicked
, this, &DolphinMainWindow::slotBackForwardActionMiddleClicked
);
2092 m_backAction
->popupMenu()->installEventFilter(middleClickEventFilter
);
2093 m_forwardAction
->popupMenu()->installEventFilter(middleClickEventFilter
);
2094 KStandardAction::up(this, &DolphinMainWindow::goUp
, actionCollection());
2095 QAction
*homeAction
= KStandardAction::home(this, &DolphinMainWindow::goHome
, actionCollection());
2096 homeAction
->setWhatsThis(xi18nc("@info:whatsthis",
2098 "<filename>Home</filename> folder.<nl/>Every user account "
2099 "has their own <filename>Home</filename> that contains their personal files, "
2100 "as well as hidden folders for their applications' data and configuration files."));
2102 // setup 'Tools' menu
2103 QAction
*compareFiles
= actionCollection()->addAction(QStringLiteral("compare_files"));
2104 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
2105 compareFiles
->setIcon(QIcon::fromTheme(QStringLiteral("kompare")));
2106 compareFiles
->setEnabled(false);
2107 connect(compareFiles
, &QAction::triggered
, this, &DolphinMainWindow::compareFiles
);
2109 QAction
*manageDiskSpaceUsage
= actionCollection()->addAction(QStringLiteral("manage_disk_space"));
2110 manageDiskSpaceUsage
->setText(i18nc("@action:inmenu Tools", "Manage Disk Space Usage"));
2111 manageDiskSpaceUsage
->setIcon(QIcon::fromTheme(QStringLiteral("filelight")));
2112 m_diskSpaceUsageMenu
= new DiskSpaceUsageMenu
{this};
2113 manageDiskSpaceUsage
->setMenu(m_diskSpaceUsageMenu
);
2115 QAction
*openPreferredSearchTool
= actionCollection()->addAction(QStringLiteral("open_preferred_search_tool"));
2116 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool"));
2117 openPreferredSearchTool
->setWhatsThis(xi18nc("@info:whatsthis",
2118 "<para>This opens a preferred search tool for the viewed location.</para>"
2119 "<para>Use <emphasis>More Search Tools</emphasis> menu to configure it.</para>"));
2120 openPreferredSearchTool
->setIcon(QIcon::fromTheme(QStringLiteral("search")));
2121 actionCollection()->setDefaultShortcut(openPreferredSearchTool
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_F
);
2122 connect(openPreferredSearchTool
, &QAction::triggered
, this, &DolphinMainWindow::openPreferredSearchTool
);
2124 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
2125 // Get icon of user default terminal emulator application
2126 const KConfigGroup
group(KSharedConfig::openConfig(QStringLiteral("kdeglobals"), KConfig::SimpleConfig
), QStringLiteral("General"));
2127 const QString terminalDesktopFilename
= group
.readEntry("TerminalService");
2128 // Use utilities-terminal icon from theme if readEntry() has failed
2129 const QString terminalIcon
= terminalDesktopFilename
.isEmpty() ? "utilities-terminal" : KDesktopFile(terminalDesktopFilename
).readIcon();
2131 QAction
*openTerminal
= actionCollection()->addAction(QStringLiteral("open_terminal"));
2132 openTerminal
->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
2133 openTerminal
->setWhatsThis(xi18nc("@info:whatsthis",
2134 "<para>This opens a <emphasis>terminal</emphasis> application for the viewed location.</para>"
2135 "<para>To learn more about terminals use the help features in the terminal application.</para>"));
2136 openTerminal
->setIcon(QIcon::fromTheme(terminalIcon
));
2137 actionCollection()->setDefaultShortcut(openTerminal
, Qt::SHIFT
| Qt::Key_F4
);
2138 connect(openTerminal
, &QAction::triggered
, this, &DolphinMainWindow::openTerminal
);
2140 QAction
*openTerminalHere
= actionCollection()->addAction(QStringLiteral("open_terminal_here"));
2141 // i18n: "Here" refers to the location(s) of the currently selected item(s) or the currently viewed location if nothing is selected.
2142 openTerminalHere
->setText(i18nc("@action:inmenu Tools", "Open Terminal Here"));
2143 openTerminalHere
->setWhatsThis(xi18nc("@info:whatsthis",
2144 "<para>This opens <emphasis>terminal</emphasis> applications for the selected items' locations.</para>"
2145 "<para>To learn more about terminals use the help features in the terminal application.</para>"));
2146 openTerminalHere
->setIcon(QIcon::fromTheme(terminalIcon
));
2147 actionCollection()->setDefaultShortcut(openTerminalHere
, Qt::SHIFT
| Qt::ALT
| Qt::Key_F4
);
2148 connect(openTerminalHere
, &QAction::triggered
, this, &DolphinMainWindow::openTerminalHere
);
2151 // setup 'Bookmarks' menu
2152 KActionMenu
*bookmarkMenu
= new KActionMenu(i18nc("@title:menu", "&Bookmarks"), this);
2153 bookmarkMenu
->setIcon(QIcon::fromTheme(QStringLiteral("bookmarks")));
2154 // Make the toolbar button version work properly on click
2155 bookmarkMenu
->setPopupMode(QToolButton::InstantPopup
);
2156 m_bookmarkHandler
= new DolphinBookmarkHandler(this, actionCollection(), bookmarkMenu
->menu(), this);
2157 actionCollection()->addAction(QStringLiteral("bookmarks"), bookmarkMenu
);
2159 // setup 'Settings' menu
2160 KToggleAction
*showMenuBar
= KStandardAction::showMenubar(nullptr, nullptr, actionCollection());
2161 showMenuBar
->setWhatsThis(xi18nc("@info:whatsthis",
2162 "<para>This switches between having a <emphasis>Menubar</emphasis> "
2163 "and having an <interface>%1</interface> button. Both "
2164 "contain mostly the same actions and configuration options.</para>"
2165 "<para>The Menubar takes up more space but allows for fast and organized access to all "
2166 "actions an application has to offer.</para><para>The %1 button "
2167 "is simpler and small which makes triggering advanced actions more time consuming.</para>",
2168 hamburgerMenuAction
->text().replace('&', "")));
2169 connect(showMenuBar
,
2170 &KToggleAction::triggered
, // Fixes #286822
2172 &DolphinMainWindow::toggleShowMenuBar
,
2173 Qt::QueuedConnection
);
2175 KStandardAction::keyBindings(this, &DolphinMainWindow::slotKeyBindings
, actionCollection());
2176 KStandardAction::preferences(this, &DolphinMainWindow::editSettings
, actionCollection());
2178 // not in menu actions
2179 QList
<QKeySequence
> nextTabKeys
= KStandardShortcut::tabNext();
2180 nextTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::Key_Tab
));
2182 QList
<QKeySequence
> prevTabKeys
= KStandardShortcut::tabPrev();
2183 prevTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::SHIFT
| Qt::Key_Tab
));
2185 for (int i
= 0; i
< MaxActivateTabShortcuts
; ++i
) {
2186 QAction
*activateTab
= actionCollection()->addAction(QStringLiteral("activate_tab_%1").arg(i
));
2187 activateTab
->setText(i18nc("@action:inmenu", "Go to Tab %1", i
+ 1));
2188 activateTab
->setEnabled(false);
2189 connect(activateTab
, &QAction::triggered
, this, [this, i
]() {
2190 m_tabWidget
->activateTab(i
);
2193 // only add default shortcuts for the first 9 tabs regardless of MaxActivateTabShortcuts
2195 actionCollection()->setDefaultShortcut(activateTab
, QStringLiteral("Alt+%1").arg(i
+ 1));
2199 QAction
*activateLastTab
= actionCollection()->addAction(QStringLiteral("activate_last_tab"));
2200 activateLastTab
->setIconText(i18nc("@action:inmenu", "Last Tab"));
2201 activateLastTab
->setText(i18nc("@action:inmenu", "Go to Last Tab"));
2202 activateLastTab
->setEnabled(false);
2203 connect(activateLastTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activateLastTab
);
2204 actionCollection()->setDefaultShortcut(activateLastTab
, Qt::ALT
| Qt::Key_0
);
2206 QAction
*activateNextTab
= actionCollection()->addAction(QStringLiteral("activate_next_tab"));
2207 activateNextTab
->setIconText(i18nc("@action:inmenu", "Next Tab"));
2208 activateNextTab
->setText(i18nc("@action:inmenu", "Go to Next Tab"));
2209 activateNextTab
->setEnabled(false);
2210 connect(activateNextTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activateNextTab
);
2211 actionCollection()->setDefaultShortcuts(activateNextTab
, nextTabKeys
);
2213 QAction
*activatePrevTab
= actionCollection()->addAction(QStringLiteral("activate_prev_tab"));
2214 activatePrevTab
->setIconText(i18nc("@action:inmenu", "Previous Tab"));
2215 activatePrevTab
->setText(i18nc("@action:inmenu", "Go to Previous Tab"));
2216 activatePrevTab
->setEnabled(false);
2217 connect(activatePrevTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activatePrevTab
);
2218 actionCollection()->setDefaultShortcuts(activatePrevTab
, prevTabKeys
);
2221 QAction
*showTarget
= actionCollection()->addAction(QStringLiteral("show_target"));
2222 showTarget
->setText(i18nc("@action:inmenu", "Show Target"));
2223 showTarget
->setIcon(QIcon::fromTheme(QStringLiteral("document-open-folder")));
2224 showTarget
->setEnabled(false);
2225 connect(showTarget
, &QAction::triggered
, this, &DolphinMainWindow::showTarget
);
2227 QAction
*openInNewTab
= actionCollection()->addAction(QStringLiteral("open_in_new_tab"));
2228 openInNewTab
->setText(i18nc("@action:inmenu", "Open in New Tab"));
2229 openInNewTab
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
2230 connect(openInNewTab
, &QAction::triggered
, this, &DolphinMainWindow::openInNewTab
);
2232 QAction
*openInNewTabs
= actionCollection()->addAction(QStringLiteral("open_in_new_tabs"));
2233 openInNewTabs
->setText(i18nc("@action:inmenu", "Open in New Tabs"));
2234 openInNewTabs
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
2235 connect(openInNewTabs
, &QAction::triggered
, this, &DolphinMainWindow::openInNewTab
);
2237 QAction
*openInNewWindow
= actionCollection()->addAction(QStringLiteral("open_in_new_window"));
2238 openInNewWindow
->setText(i18nc("@action:inmenu", "Open in New Window"));
2239 openInNewWindow
->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
2240 connect(openInNewWindow
, &QAction::triggered
, this, &DolphinMainWindow::openInNewWindow
);
2242 QAction
*openInSplitViewAction
= actionCollection()->addAction(QStringLiteral("open_in_split_view"));
2243 openInSplitViewAction
->setText(i18nc("@action:inmenu", "Open in Split View"));
2244 openInSplitViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-split-left-right")));
2245 connect(openInSplitViewAction
, &QAction::triggered
, this, [this]() {
2246 openInSplitView(QUrl());
2249 m_recentFiles
= new KRecentFilesAction(this);
2252 void DolphinMainWindow::setupDockWidgets()
2254 const bool lock
= GeneralSettings::lockPanels();
2256 DolphinPlacesModelSingleton::instance().placesModel()->setPanelsLocked(lock
);
2258 KDualAction
*lockLayoutAction
= actionCollection()->add
<KDualAction
>(QStringLiteral("lock_panels"));
2259 lockLayoutAction
->setActiveText(i18nc("@action:inmenu Panels", "Unlock Panels"));
2260 lockLayoutAction
->setActiveIcon(QIcon::fromTheme(QStringLiteral("object-unlocked")));
2261 lockLayoutAction
->setInactiveText(i18nc("@action:inmenu Panels", "Lock Panels"));
2262 lockLayoutAction
->setInactiveIcon(QIcon::fromTheme(QStringLiteral("object-locked")));
2263 lockLayoutAction
->setWhatsThis(xi18nc("@info:whatsthis",
2265 "switches between having panels <emphasis>locked</emphasis> or "
2266 "<emphasis>unlocked</emphasis>.<nl/>Unlocked panels can be "
2267 "dragged to the other side of the window and have a close "
2268 "button.<nl/>Locked panels are embedded more cleanly."));
2269 lockLayoutAction
->setActive(lock
);
2270 connect(lockLayoutAction
, &KDualAction::triggered
, this, &DolphinMainWindow::togglePanelLockState
);
2272 // Setup "Information"
2273 DolphinDockWidget
*infoDock
= new DolphinDockWidget(i18nc("@title:window", "Information"));
2274 infoDock
->setLocked(lock
);
2275 infoDock
->setObjectName(QStringLiteral("infoDock"));
2276 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
2279 InformationPanel
*infoPanel
= new InformationPanel(infoDock
);
2280 infoPanel
->setCustomContextMenuActions({lockLayoutAction
});
2281 connect(infoPanel
, &InformationPanel::urlActivated
, this, &DolphinMainWindow::handleUrl
);
2282 infoDock
->setWidget(infoPanel
);
2284 createPanelAction(QIcon::fromTheme(QStringLiteral("documentinfo")), Qt::Key_F11
, infoDock
, QStringLiteral("show_information_panel"));
2286 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
2287 connect(this, &DolphinMainWindow::urlChanged
, infoPanel
, &InformationPanel::setUrl
);
2288 connect(this, &DolphinMainWindow::selectionChanged
, infoPanel
, &InformationPanel::setSelection
);
2289 connect(this, &DolphinMainWindow::requestItemInfo
, infoPanel
, &InformationPanel::requestDelayedItemInfo
);
2290 connect(this, &DolphinMainWindow::fileItemsChanged
, infoPanel
, &InformationPanel::slotFilesItemChanged
);
2291 connect(this, &DolphinMainWindow::settingsChanged
, infoPanel
, &InformationPanel::readSettings
);
2294 // i18n: This is the last paragraph for the "What's This"-texts of all four panels.
2295 const QString panelWhatsThis
= xi18nc("@info:whatsthis",
2297 "hide panels like this go to <interface>Menu|Panels</interface> "
2298 "or <interface>View|Panels</interface>.</para>");
2301 ->action(QStringLiteral("show_information_panel"))
2302 ->setWhatsThis(xi18nc("@info:whatsthis",
2303 "<para> This toggles the "
2304 "<emphasis>information</emphasis> panel at the right side of the "
2305 "window.</para><para>The panel provides in-depth information "
2306 "about the items your mouse is hovering over or about the selected "
2307 "items. Otherwise it informs you about the currently viewed folder.<nl/>"
2308 "For single items a preview of their contents is provided.</para>"));
2310 infoDock
->setWhatsThis(xi18nc("@info:whatsthis",
2312 "provides in-depth information about the items your mouse is "
2313 "hovering over or about the selected items. Otherwise it informs "
2314 "you about the currently viewed folder.<nl/>For single items a "
2315 "preview of their contents is provided.</para><para>You can configure "
2316 "which and how details are given here by right-clicking.</para>")
2320 DolphinDockWidget
*foldersDock
= new DolphinDockWidget(i18nc("@title:window", "Folders"));
2321 foldersDock
->setLocked(lock
);
2322 foldersDock
->setObjectName(QStringLiteral("foldersDock"));
2323 foldersDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
2324 FoldersPanel
*foldersPanel
= new FoldersPanel(foldersDock
);
2325 foldersPanel
->setCustomContextMenuActions({lockLayoutAction
});
2326 foldersDock
->setWidget(foldersPanel
);
2328 createPanelAction(QIcon::fromTheme(QStringLiteral("folder")), Qt::Key_F7
, foldersDock
, QStringLiteral("show_folders_panel"));
2330 addDockWidget(Qt::LeftDockWidgetArea
, foldersDock
);
2331 connect(this, &DolphinMainWindow::urlChanged
, foldersPanel
, &FoldersPanel::setUrl
);
2332 connect(foldersPanel
, &FoldersPanel::folderActivated
, this, &DolphinMainWindow::changeUrl
);
2333 connect(foldersPanel
, &FoldersPanel::folderInNewTab
, this, &DolphinMainWindow::openNewTab
);
2334 connect(foldersPanel
, &FoldersPanel::folderInNewActiveTab
, this, &DolphinMainWindow::openNewTabAndActivate
);
2335 connect(foldersPanel
, &FoldersPanel::errorMessage
, this, &DolphinMainWindow::showErrorMessage
);
2338 ->action(QStringLiteral("show_folders_panel"))
2339 ->setWhatsThis(xi18nc("@info:whatsthis",
2341 "<emphasis>folders</emphasis> panel at the left side of the window."
2342 "<nl/><nl/>It shows the folders of the <emphasis>file system"
2343 "</emphasis> in a <emphasis>tree view</emphasis>."));
2344 foldersDock
->setWhatsThis(xi18nc("@info:whatsthis",
2346 "shows the folders of the <emphasis>file system</emphasis> in a "
2347 "<emphasis>tree view</emphasis>.</para><para>Click a folder to go "
2348 "there. Click the arrow to the left of a folder to see its subfolders. "
2349 "This allows quick switching between any folders.</para>")
2354 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
2355 DolphinDockWidget
*terminalDock
= new DolphinDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
2356 terminalDock
->setLocked(lock
);
2357 terminalDock
->setObjectName(QStringLiteral("terminalDock"));
2358 terminalDock
->setContentsMargins(0, 0, 0, 0);
2359 m_terminalPanel
= new TerminalPanel(terminalDock
);
2360 m_terminalPanel
->setCustomContextMenuActions({lockLayoutAction
});
2361 terminalDock
->setWidget(m_terminalPanel
);
2363 connect(m_terminalPanel
, &TerminalPanel::hideTerminalPanel
, terminalDock
, &DolphinDockWidget::hide
);
2364 connect(m_terminalPanel
, &TerminalPanel::changeUrl
, this, &DolphinMainWindow::slotTerminalDirectoryChanged
);
2365 connect(terminalDock
, &DolphinDockWidget::visibilityChanged
, m_terminalPanel
, &TerminalPanel::dockVisibilityChanged
);
2366 connect(terminalDock
, &DolphinDockWidget::visibilityChanged
, this, &DolphinMainWindow::slotTerminalPanelVisibilityChanged
);
2368 createPanelAction(QIcon::fromTheme(QStringLiteral("dialog-scripts")), Qt::Key_F4
, terminalDock
, QStringLiteral("show_terminal_panel"));
2370 addDockWidget(Qt::BottomDockWidgetArea
, terminalDock
);
2371 connect(this, &DolphinMainWindow::urlChanged
, m_terminalPanel
, &TerminalPanel::setUrl
);
2373 if (GeneralSettings::version() < 200) {
2374 terminalDock
->hide();
2378 ->action(QStringLiteral("show_terminal_panel"))
2379 ->setWhatsThis(xi18nc("@info:whatsthis",
2380 "<para>This toggles the "
2381 "<emphasis>terminal</emphasis> panel at the bottom of the window."
2382 "<nl/>The location in the terminal will always match the folder "
2383 "view so you can navigate using either.</para><para>The terminal "
2384 "panel is not needed for basic computer usage but can be useful "
2385 "for advanced tasks. To learn more about terminals use the help features "
2386 "in a standalone terminal application like Konsole.</para>"));
2387 terminalDock
->setWhatsThis(xi18nc("@info:whatsthis",
2389 "the <emphasis>terminal</emphasis> panel. It behaves like a "
2390 "normal terminal but will match the location of the folder view "
2391 "so you can navigate using either.</para><para>The terminal panel "
2392 "is not needed for basic computer usage but can be useful for "
2393 "advanced tasks. To learn more about terminals use the help features in a "
2394 "standalone terminal application like Konsole.</para>")
2397 QAction
*focusTerminalPanel
= actionCollection()->addAction(QStringLiteral("focus_terminal_panel"));
2398 focusTerminalPanel
->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
2399 focusTerminalPanel
->setToolTip(i18nc("@info:tooltip", "Move keyboard focus to and from the Terminal panel."));
2400 focusTerminalPanel
->setIcon(QIcon::fromTheme(QStringLiteral("swap-panels")));
2401 actionCollection()->setDefaultShortcut(focusTerminalPanel
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_F4
);
2402 connect(focusTerminalPanel
, &QAction::triggered
, this, &DolphinMainWindow::toggleTerminalPanelFocus
);
2403 } // endif "shell_access" allowed
2404 #endif // HAVE_TERMINAL
2406 if (GeneralSettings::version() < 200) {
2408 foldersDock
->hide();
2412 DolphinDockWidget
*placesDock
= new DolphinDockWidget(i18nc("@title:window", "Places"));
2413 placesDock
->setLocked(lock
);
2414 placesDock
->setObjectName(QStringLiteral("placesDock"));
2415 placesDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
2417 m_placesPanel
= new PlacesPanel(placesDock
);
2418 m_placesPanel
->setCustomContextMenuActions({lockLayoutAction
});
2419 placesDock
->setWidget(m_placesPanel
);
2421 createPanelAction(QIcon::fromTheme(QStringLiteral("compass")), Qt::Key_F9
, placesDock
, QStringLiteral("show_places_panel"));
2423 addDockWidget(Qt::LeftDockWidgetArea
, placesDock
);
2424 connect(m_placesPanel
, &PlacesPanel::placeActivated
, this, &DolphinMainWindow::slotPlaceActivated
);
2425 connect(m_placesPanel
, &PlacesPanel::tabRequested
, this, &DolphinMainWindow::openNewTab
);
2426 connect(m_placesPanel
, &PlacesPanel::activeTabRequested
, this, &DolphinMainWindow::openNewTabAndActivate
);
2427 connect(m_placesPanel
, &PlacesPanel::newWindowRequested
, this, [this](const QUrl
&url
) {
2428 Dolphin::openNewWindow({url
}, this);
2430 connect(m_placesPanel
, &PlacesPanel::openInSplitViewRequested
, this, &DolphinMainWindow::openInSplitView
);
2431 connect(m_placesPanel
, &PlacesPanel::errorMessage
, this, &DolphinMainWindow::showErrorMessage
);
2432 connect(this, &DolphinMainWindow::urlChanged
, m_placesPanel
, &PlacesPanel::setUrl
);
2433 connect(placesDock
, &DolphinDockWidget::visibilityChanged
, &DolphinUrlNavigatorsController::slotPlacesPanelVisibilityChanged
);
2434 connect(placesDock
, &DolphinDockWidget::visibilityChanged
, this, &DolphinMainWindow::slotPlacesPanelVisibilityChanged
);
2435 connect(this, &DolphinMainWindow::settingsChanged
, m_placesPanel
, &PlacesPanel::readSettings
);
2436 connect(m_placesPanel
, &PlacesPanel::storageTearDownRequested
, this, &DolphinMainWindow::slotStorageTearDownFromPlacesRequested
);
2437 connect(m_placesPanel
, &PlacesPanel::storageTearDownExternallyRequested
, this, &DolphinMainWindow::slotStorageTearDownExternallyRequested
);
2438 DolphinUrlNavigatorsController::slotPlacesPanelVisibilityChanged(m_placesPanel
->isVisible());
2440 auto actionShowAllPlaces
= new QAction(QIcon::fromTheme(QStringLiteral("view-hidden")), i18nc("@item:inmenu", "Show Hidden Places"), this);
2441 actionShowAllPlaces
->setCheckable(true);
2442 actionShowAllPlaces
->setDisabled(true);
2443 actionShowAllPlaces
->setWhatsThis(i18nc("@info:whatsthis",
2445 "all places in the places panel that have been hidden. They will "
2446 "appear semi-transparent and allow you to uncheck their \"Hide\" property."));
2448 connect(actionShowAllPlaces
, &QAction::triggered
, this, [this](bool checked
) {
2449 m_placesPanel
->setShowAll(checked
);
2451 connect(m_placesPanel
, &PlacesPanel::allPlacesShownChanged
, actionShowAllPlaces
, &QAction::setChecked
);
2454 ->action(QStringLiteral("show_places_panel"))
2455 ->setWhatsThis(xi18nc("@info:whatsthis",
2456 "<para>This toggles the "
2457 "<emphasis>places</emphasis> panel at the left side of the window."
2458 "</para><para>It allows you to go to locations you have "
2459 "bookmarked and to access disk or media attached to the computer "
2460 "or to the network. It also contains sections to find recently "
2461 "saved files or files of a certain type.</para>"));
2462 placesDock
->setWhatsThis(xi18nc("@info:whatsthis",
2463 "<para>This is the "
2464 "<emphasis>Places</emphasis> panel. It allows you to go to locations "
2465 "you have bookmarked and to access disk or media attached to the "
2466 "computer or to the network. It also contains sections to find "
2467 "recently saved files or files of a certain type.</para><para>"
2468 "Click on an entry to go there. Click with the right mouse button "
2469 "instead to open any entry in a new tab or new window.</para>"
2470 "<para>New entries can be added by dragging folders onto this panel. "
2471 "Right-click any section or entry to hide it. Right-click an empty "
2472 "space on this panel and select <interface>Show Hidden Places"
2473 "</interface> to display it again.</para>")
2476 QAction
*focusPlacesPanel
= actionCollection()->addAction(QStringLiteral("focus_places_panel"));
2477 focusPlacesPanel
->setText(i18nc("@action:inmenu View", "Focus Places Panel"));
2478 focusPlacesPanel
->setToolTip(i18nc("@info:tooltip", "Move keyboard focus to and from the Places panel."));
2479 focusPlacesPanel
->setIcon(QIcon::fromTheme(QStringLiteral("swap-panels")));
2480 actionCollection()->setDefaultShortcut(focusPlacesPanel
, Qt::CTRL
| Qt::Key_P
);
2481 connect(focusPlacesPanel
, &QAction::triggered
, this, &DolphinMainWindow::togglePlacesPanelFocus
);
2483 // Add actions into the "Panels" menu
2484 KActionMenu
*panelsMenu
= new KActionMenu(i18nc("@action:inmenu View", "Show Panels"), this);
2485 actionCollection()->addAction(QStringLiteral("panels"), panelsMenu
);
2486 panelsMenu
->setIcon(QIcon::fromTheme(QStringLiteral("view-sidetree")));
2487 panelsMenu
->setPopupMode(QToolButton::InstantPopup
);
2488 const KActionCollection
*ac
= actionCollection();
2489 panelsMenu
->addAction(ac
->action(QStringLiteral("show_places_panel")));
2491 panelsMenu
->addAction(ac
->action(QStringLiteral("show_information_panel")));
2493 panelsMenu
->addAction(ac
->action(QStringLiteral("show_folders_panel")));
2494 panelsMenu
->addAction(ac
->action(QStringLiteral("show_terminal_panel")));
2495 panelsMenu
->addSeparator();
2496 panelsMenu
->addAction(lockLayoutAction
);
2497 panelsMenu
->addSeparator();
2498 panelsMenu
->addAction(actionShowAllPlaces
);
2499 panelsMenu
->addAction(focusPlacesPanel
);
2500 panelsMenu
->addAction(ac
->action(QStringLiteral("focus_terminal_panel")));
2502 connect(panelsMenu
->menu(), &QMenu::aboutToShow
, this, [actionShowAllPlaces
] {
2503 actionShowAllPlaces
->setEnabled(DolphinPlacesModelSingleton::instance().placesModel()->hiddenCount());
2507 void DolphinMainWindow::updateFileAndEditActions()
2509 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
2510 const KActionCollection
*col
= actionCollection();
2511 KFileItemListProperties
capabilitiesSource(list
);
2513 QAction
*renameAction
= col
->action(KStandardAction::name(KStandardAction::RenameFile
));
2514 QAction
*moveToTrashAction
= col
->action(KStandardAction::name(KStandardAction::MoveToTrash
));
2515 QAction
*deleteAction
= col
->action(KStandardAction::name(KStandardAction::DeleteFile
));
2516 QAction
*cutAction
= col
->action(KStandardAction::name(KStandardAction::Cut
));
2517 QAction
*duplicateAction
= col
->action(QStringLiteral("duplicate")); // see DolphinViewActionHandler
2518 QAction
*addToPlacesAction
= col
->action(QStringLiteral("add_to_places"));
2519 QAction
*copyToOtherViewAction
= col
->action(QStringLiteral("copy_to_inactive_split_view"));
2520 QAction
*moveToOtherViewAction
= col
->action(QStringLiteral("move_to_inactive_split_view"));
2521 QAction
*copyLocation
= col
->action(QStringLiteral("copy_location"));
2523 if (list
.isEmpty()) {
2524 stateChanged(QStringLiteral("has_no_selection"));
2526 // All actions that need a selection to function can be enabled because they should trigger selection mode.
2527 renameAction
->setEnabled(true);
2528 moveToTrashAction
->setEnabled(true);
2529 deleteAction
->setEnabled(true);
2530 cutAction
->setEnabled(true);
2531 duplicateAction
->setEnabled(true);
2532 addToPlacesAction
->setEnabled(true);
2533 copyLocation
->setEnabled(true);
2534 // Them triggering selection mode and not directly acting on selected items is signified by adding "…" to their text.
2535 m_actionTextHelper
->textsWhenNothingIsSelectedEnabled(true);
2538 m_actionTextHelper
->textsWhenNothingIsSelectedEnabled(false);
2539 stateChanged(QStringLiteral("has_selection"));
2541 QAction
*deleteWithTrashShortcut
= col
->action(QStringLiteral("delete_shortcut")); // see DolphinViewActionHandler
2542 QAction
*showTarget
= col
->action(QStringLiteral("show_target"));
2544 if (list
.length() == 1 && list
.first().isDir()) {
2545 addToPlacesAction
->setEnabled(true);
2547 addToPlacesAction
->setEnabled(false);
2550 const bool enableMoveToTrash
= capabilitiesSource
.isLocal() && capabilitiesSource
.supportsMoving();
2552 renameAction
->setEnabled(capabilitiesSource
.supportsMoving());
2553 m_disabledActionNotifier
->setDisabledReason(renameAction
, i18nc("@info", "Cannot rename: You do not have permission to rename items in this folder."));
2554 deleteAction
->setEnabled(capabilitiesSource
.supportsDeleting());
2555 m_disabledActionNotifier
->setDisabledReason(deleteAction
,
2556 i18nc("@info", "Cannot delete: You do not have permission to remove items from this folder."));
2557 cutAction
->setEnabled(capabilitiesSource
.supportsMoving());
2558 m_disabledActionNotifier
->setDisabledReason(cutAction
, i18nc("@info", "Cannot cut: You do not have permission to move items from this folder."));
2559 copyLocation
->setEnabled(list
.length() == 1);
2560 showTarget
->setEnabled(list
.length() == 1 && list
.at(0).isLink());
2561 duplicateAction
->setEnabled(capabilitiesSource
.supportsWriting());
2562 m_disabledActionNotifier
->setDisabledReason(duplicateAction
,
2563 i18nc("@info", "Cannot duplicate here: You do not have permission to create items in this folder."));
2565 if (enableMoveToTrash
) {
2566 moveToTrashAction
->setEnabled(true);
2567 deleteWithTrashShortcut
->setEnabled(false);
2568 m_disabledActionNotifier
->clearDisabledReason(deleteWithTrashShortcut
);
2570 moveToTrashAction
->setEnabled(false);
2571 deleteWithTrashShortcut
->setEnabled(capabilitiesSource
.supportsDeleting());
2572 m_disabledActionNotifier
->setDisabledReason(deleteWithTrashShortcut
,
2573 i18nc("@info", "Cannot delete: You do not have permission to remove items from this folder."));
2577 if (!m_tabWidget
->currentTabPage()->splitViewEnabled()) {
2578 // No need to set the disabled reason here, as it's obvious to the user that the reason is the split view being disabled.
2579 copyToOtherViewAction
->setEnabled(false);
2580 m_disabledActionNotifier
->clearDisabledReason(copyToOtherViewAction
);
2581 moveToOtherViewAction
->setEnabled(false);
2582 m_disabledActionNotifier
->clearDisabledReason(moveToOtherViewAction
);
2583 } else if (list
.isEmpty()) {
2584 copyToOtherViewAction
->setEnabled(false);
2585 m_disabledActionNotifier
->setDisabledReason(copyToOtherViewAction
, i18nc("@info", "Cannot copy to other view: No files selected."));
2586 moveToOtherViewAction
->setEnabled(false);
2587 m_disabledActionNotifier
->setDisabledReason(moveToOtherViewAction
, i18nc("@info", "Cannot move to other view: No files selected."));
2589 DolphinTabPage
*tabPage
= m_tabWidget
->currentTabPage();
2590 KFileItem capabilitiesDestination
;
2592 if (tabPage
->primaryViewActive()) {
2593 capabilitiesDestination
= tabPage
->secondaryViewContainer()->rootItem();
2595 capabilitiesDestination
= tabPage
->primaryViewContainer()->rootItem();
2598 const auto destUrl
= capabilitiesDestination
.url();
2599 const bool allNotTargetOrigin
= std::all_of(list
.cbegin(), list
.cend(), [destUrl
](const KFileItem
&item
) {
2600 return item
.url().adjusted(QUrl::RemoveFilename
| QUrl::StripTrailingSlash
) != destUrl
;
2603 if (!allNotTargetOrigin
) {
2604 copyToOtherViewAction
->setEnabled(false);
2605 m_disabledActionNotifier
->setDisabledReason(copyToOtherViewAction
,
2606 i18nc("@info", "Cannot copy to other view: The other view already contains these items."));
2607 moveToOtherViewAction
->setEnabled(false);
2608 m_disabledActionNotifier
->setDisabledReason(moveToOtherViewAction
,
2609 i18nc("@info", "Cannot move to other view: The other view already contains these items."));
2610 } else if (!capabilitiesDestination
.isWritable()) {
2611 copyToOtherViewAction
->setEnabled(false);
2612 m_disabledActionNotifier
->setDisabledReason(
2613 copyToOtherViewAction
,
2614 i18nc("@info", "Cannot copy to other view: You do not have permission to write into the destination folder."));
2615 moveToOtherViewAction
->setEnabled(false);
2616 m_disabledActionNotifier
->setDisabledReason(
2617 moveToOtherViewAction
,
2618 i18nc("@info", "Cannot move to other view: You do not have permission to write into the destination folder."));
2620 copyToOtherViewAction
->setEnabled(true);
2621 moveToOtherViewAction
->setEnabled(capabilitiesSource
.supportsMoving());
2622 m_disabledActionNotifier
->setDisabledReason(
2623 moveToOtherViewAction
,
2624 i18nc("@info", "Cannot move to other view: You do not have permission to move items from this folder."));
2629 void DolphinMainWindow::updateViewActions()
2631 m_actionHandler
->updateViewActions();
2633 QAction
*toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
2634 toggleFilterBarAction
->setChecked(m_activeViewContainer
->isFilterBarVisible());
2636 updateSplitActions();
2639 void DolphinMainWindow::updateGoActions()
2641 QAction
*goUpAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Up
));
2642 const QUrl currentUrl
= m_activeViewContainer
->url();
2643 // I think this is one of the best places to firstly be confronted
2644 // with a file system and its hierarchy. Talking about the root
2645 // directory might seem too much here but it is the question that
2646 // naturally arises in this context.
2647 goUpAction
->setWhatsThis(xi18nc("@info:whatsthis",
2649 "the folder that contains the currently viewed one.</para>"
2650 "<para>All files and folders are organized in a hierarchical "
2651 "<emphasis>file system</emphasis>. At the top of this hierarchy is "
2652 "a directory that contains all data connected to this computer"
2653 "—the <emphasis>root directory</emphasis>.</para>"));
2654 goUpAction
->setEnabled(KIO::upUrl(currentUrl
) != currentUrl
);
2657 void DolphinMainWindow::refreshViews()
2659 m_tabWidget
->refreshViews();
2661 if (GeneralSettings::modifiedStartupSettings()) {
2662 updateWindowTitle();
2665 updateSplitActions();
2667 Q_EMIT
settingsChanged();
2670 void DolphinMainWindow::clearStatusBar()
2672 m_activeViewContainer
->statusBar()->resetToDefaultText();
2675 void DolphinMainWindow::connectViewSignals(DolphinViewContainer
*container
)
2677 connect(container
, &DolphinViewContainer::showFilterBarChanged
, this, &DolphinMainWindow::updateFilterBarAction
);
2678 connect(container
, &DolphinViewContainer::writeStateChanged
, this, &DolphinMainWindow::slotWriteStateChanged
);
2679 slotWriteStateChanged(container
->view()->isFolderWritable());
2680 connect(container
, &DolphinViewContainer::searchBarVisibilityChanged
, this, &DolphinMainWindow::updateSearchAction
);
2681 connect(container
, &DolphinViewContainer::captionChanged
, this, &DolphinMainWindow::updateWindowTitle
);
2682 connect(container
, &DolphinViewContainer::tabRequested
, this, &DolphinMainWindow::openNewTab
);
2683 connect(container
, &DolphinViewContainer::activeTabRequested
, this, &DolphinMainWindow::openNewTabAndActivate
);
2685 // Make the toggled state of the selection mode actions visually follow the selection mode state of the view.
2686 auto toggleSelectionModeAction
= actionCollection()->action(QStringLiteral("toggle_selection_mode"));
2687 toggleSelectionModeAction
->setChecked(m_activeViewContainer
->isSelectionModeEnabled());
2688 connect(m_activeViewContainer
, &DolphinViewContainer::selectionModeChanged
, toggleSelectionModeAction
, &QAction::setChecked
);
2690 const DolphinView
*view
= container
->view();
2691 connect(view
, &DolphinView::selectionChanged
, this, &DolphinMainWindow::slotSelectionChanged
);
2692 connect(view
, &DolphinView::requestItemInfo
, this, &DolphinMainWindow::requestItemInfo
);
2693 connect(view
, &DolphinView::fileItemsChanged
, this, &DolphinMainWindow::fileItemsChanged
);
2694 connect(view
, &DolphinView::tabRequested
, this, &DolphinMainWindow::openNewTab
);
2695 connect(view
, &DolphinView::activeTabRequested
, this, &DolphinMainWindow::openNewTabAndActivate
);
2696 connect(view
, &DolphinView::windowRequested
, this, &DolphinMainWindow::openNewWindow
);
2697 connect(view
, &DolphinView::requestContextMenu
, this, &DolphinMainWindow::openContextMenu
);
2698 connect(view
, &DolphinView::directoryLoadingStarted
, this, &DolphinMainWindow::enableStopAction
);
2699 connect(view
, &DolphinView::directoryLoadingCompleted
, this, &DolphinMainWindow::disableStopAction
);
2700 connect(view
, &DolphinView::directoryLoadingCompleted
, this, &DolphinMainWindow::slotDirectoryLoadingCompleted
);
2701 connect(view
, &DolphinView::goBackRequested
, this, &DolphinMainWindow::goBack
);
2702 connect(view
, &DolphinView::goForwardRequested
, this, &DolphinMainWindow::goForward
);
2703 connect(view
, &DolphinView::urlActivated
, this, &DolphinMainWindow::handleUrl
);
2704 connect(view
, &DolphinView::goUpRequested
, this, &DolphinMainWindow::goUp
);
2705 connect(view
, &DolphinView::doubleClickViewBackground
, this, &DolphinMainWindow::slotDoubleClickViewBackground
);
2707 connect(container
->urlNavigatorInternalWithHistory(), &KUrlNavigator::urlChanged
, this, &DolphinMainWindow::changeUrl
);
2708 connect(container
->urlNavigatorInternalWithHistory(), &KUrlNavigator::historyChanged
, this, &DolphinMainWindow::updateHistory
);
2710 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>(actionCollection()->action(QStringLiteral("url_navigators")));
2711 const KUrlNavigator
*navigator
=
2712 m_tabWidget
->currentTabPage()->primaryViewActive() ? navigators
->primaryUrlNavigator() : navigators
->secondaryUrlNavigator();
2714 QAction
*editableLocactionAction
= actionCollection()->action(QStringLiteral("editable_location"));
2715 editableLocactionAction
->setChecked(navigator
->isUrlEditable());
2716 connect(navigator
, &KUrlNavigator::editableStateChanged
, this, &DolphinMainWindow::slotEditableStateChanged
);
2717 connect(navigator
, &KUrlNavigator::tabRequested
, this, &DolphinMainWindow::openNewTab
);
2718 connect(navigator
, &KUrlNavigator::activeTabRequested
, this, &DolphinMainWindow::openNewTabAndActivate
);
2719 connect(navigator
, &KUrlNavigator::newWindowRequested
, this, &DolphinMainWindow::openNewWindow
);
2722 void DolphinMainWindow::updateSplitActions()
2724 QAction
*popoutSplitAction
= actionCollection()->action(QStringLiteral("popout_split_view"));
2726 auto setActionPopupMode
= [this](KActionMenu
*action
, QToolButton::ToolButtonPopupMode popupMode
) {
2727 action
->setPopupMode(popupMode
);
2728 if (auto *buttonForAction
= qobject_cast
<QToolButton
*>(toolBar()->widgetForAction(action
))) {
2729 buttonForAction
->setPopupMode(popupMode
);
2733 const DolphinTabPage
*tabPage
= m_tabWidget
->currentTabPage();
2734 if (tabPage
->splitViewEnabled()) {
2735 if (GeneralSettings::closeActiveSplitView() ? tabPage
->primaryViewActive() : !tabPage
->primaryViewActive()) {
2736 m_splitViewAction
->setText(i18nc("@action:intoolbar Close left view", "Close"));
2737 m_splitViewAction
->setToolTip(i18nc("@info", "Close left view"));
2738 m_splitViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-left-close")));
2739 m_splitViewMenuAction
->setText(i18nc("@action:inmenu Close left view", "Close Left View"));
2741 popoutSplitAction
->setText(i18nc("@action:intoolbar Move left view to a new window", "Pop out Left View"));
2742 popoutSplitAction
->setToolTip(i18nc("@info", "Move left view to a new window"));
2744 m_splitViewAction
->setText(i18nc("@action:intoolbar Close right view", "Close"));
2745 m_splitViewAction
->setToolTip(i18nc("@info", "Close right view"));
2746 m_splitViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-right-close")));
2747 m_splitViewMenuAction
->setText(i18nc("@action:inmenu Close left view", "Close Right View"));
2749 popoutSplitAction
->setText(i18nc("@action:intoolbar Move right view to a new window", "Pop out Right View"));
2750 popoutSplitAction
->setToolTip(i18nc("@info", "Move right view to a new window"));
2752 popoutSplitAction
->setEnabled(true);
2753 if (!m_splitViewAction
->menu()) {
2754 setActionPopupMode(m_splitViewAction
, QToolButton::MenuButtonPopup
);
2755 m_splitViewAction
->setMenu(new QMenu
);
2756 m_splitViewAction
->addAction(popoutSplitAction
);
2759 m_splitViewAction
->setText(i18nc("@action:intoolbar Split view", "Split"));
2760 m_splitViewMenuAction
->setText(m_splitViewAction
->text());
2761 m_splitViewAction
->setToolTip(i18nc("@info", "Split view"));
2762 m_splitViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-split-left-right")));
2763 popoutSplitAction
->setText(i18nc("@action:intoolbar Move view in focus to a new window", "Pop out"));
2764 popoutSplitAction
->setEnabled(false);
2765 if (m_splitViewAction
->menu()) {
2766 m_splitViewAction
->removeAction(popoutSplitAction
);
2767 m_splitViewAction
->menu()->deleteLater();
2768 m_splitViewAction
->setMenu(nullptr);
2769 setActionPopupMode(m_splitViewAction
, QToolButton::DelayedPopup
);
2773 // Update state from toolbar action
2774 m_splitViewMenuAction
->setToolTip(m_splitViewAction
->toolTip());
2775 m_splitViewMenuAction
->setIcon(m_splitViewAction
->icon());
2778 void DolphinMainWindow::updateAllowedToolbarAreas()
2780 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>(actionCollection()->action(QStringLiteral("url_navigators")));
2781 if (toolBar()->actions().contains(navigators
)) {
2782 toolBar()->setAllowedAreas(Qt::TopToolBarArea
| Qt::BottomToolBarArea
);
2783 if (toolBarArea(toolBar()) == Qt::LeftToolBarArea
|| toolBarArea(toolBar()) == Qt::RightToolBarArea
) {
2784 addToolBar(Qt::TopToolBarArea
, toolBar());
2787 toolBar()->setAllowedAreas(Qt::AllToolBarAreas
);
2791 void DolphinMainWindow::updateNavigatorsBackground()
2793 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>(actionCollection()->action(QStringLiteral("url_navigators")));
2794 navigators
->setBackgroundEnabled(navigators
->isInToolbar());
2797 bool DolphinMainWindow::isKompareInstalled() const
2799 static bool initialized
= false;
2800 static bool installed
= false;
2802 // TODO: maybe replace this approach later by using a menu
2803 // plugin like kdiff3plugin.cpp
2804 installed
= !QStandardPaths::findExecutable(QStringLiteral("kompare")).isEmpty();
2810 void DolphinMainWindow::createPanelAction(const QIcon
&icon
, const QKeySequence
&shortcut
, QDockWidget
*dockWidget
, const QString
&actionName
)
2812 auto dockAction
= dockWidget
->toggleViewAction();
2813 dockAction
->setIcon(icon
);
2814 dockAction
->setEnabled(true);
2816 QAction
*panelAction
= actionCollection()->addAction(actionName
, dockAction
);
2817 actionCollection()->setDefaultShortcut(panelAction
, shortcut
);
2820 void DolphinMainWindow::setupWhatsThis()
2823 menuBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2824 "<emphasis>Menubar</emphasis>. It provides access to commands and "
2825 "configuration options. Left-click on any of the menus on this "
2826 "bar to see its contents.</para><para>The Menubar can be hidden "
2827 "by unchecking <interface>Settings|Show Menubar</interface>. Then "
2828 "most of its contents become available through a <interface>Menu"
2829 "</interface> button on the <emphasis>Toolbar</emphasis>.</para>"));
2830 toolBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2831 "<emphasis>Toolbar</emphasis>. It allows quick access to "
2832 "frequently used actions.</para><para>It is highly customizable. "
2833 "All items you see in the <interface>Menu</interface> or "
2834 "in the <interface>Menubar</interface> can be placed on the "
2835 "Toolbar. Just right-click on it and select <interface>Configure "
2836 "Toolbars…</interface> or find this action within the <interface>"
2838 "</para><para>The location of the bar and the style of its "
2839 "buttons can also be changed in the right-click menu. Right-click "
2840 "a button if you want to show or hide its text.</para>"));
2841 m_tabWidget
->setWhatsThis(xi18nc("@info:whatsthis main view",
2842 "<para>Here you can see the <emphasis>folders</emphasis> and "
2843 "<emphasis>files</emphasis> that are at the location described in "
2844 "the <interface>Location Bar</interface> above. This area is the "
2845 "central part of this application where you navigate to the files "
2846 "you want to use.</para><para>For an elaborate and general "
2847 "introduction to this application <link "
2848 "url='https://userbase.kde.org/Dolphin/File_Management#Introduction_to_Dolphin'>"
2849 "click here</link>. This will open an introductory article from "
2850 "the <emphasis>KDE UserBase Wiki</emphasis>.</para><para>For brief "
2851 "explanations of all the features of this <emphasis>view</emphasis> "
2852 "<link url='help:/dolphin/dolphin-view.html'>click here</link> "
2853 "instead. This will open a page from the <emphasis>Handbook"
2854 "</emphasis> that covers the basics.</para>"));
2857 actionCollection()->action(KStandardAction::name(KStandardAction::KeyBindings
))
2858 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window "
2859 "that lists the <emphasis>keyboard shortcuts</emphasis>.<nl/>"
2860 "There you can set up key combinations to trigger an action when "
2861 "they are pressed simultaneously. All commands in this application can "
2862 "be triggered this way.</para>"));
2863 actionCollection()->action(KStandardAction::name(KStandardAction::ConfigureToolbars
))
2864 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window in which "
2865 "you can change which buttons appear on the <emphasis>Toolbar</emphasis>.</para>"
2866 "<para>All items you see in the <interface>Menu</interface> can also be placed on the Toolbar.</para>"));
2867 actionCollection()->action(KStandardAction::name(KStandardAction::Preferences
))
2868 ->setWhatsThis(xi18nc("@info:whatsthis","This opens a window where you can "
2869 "change a multitude of settings for this application. For an explanation "
2870 "of the various settings go to the chapter <emphasis>Configuring Dolphin"
2871 "</emphasis> in <interface>Help|Dolphin Handbook</interface>."));
2875 auto setStandardActionWhatsThis
= [this](KStandardAction::StandardAction actionId
,
2876 const QString
&whatsThis
) {
2877 // Check for the existence of an action since it can be restricted through the Kiosk system
2878 if (auto *action
= actionCollection()->action(KStandardAction::name(actionId
))) {
2879 action
->setWhatsThis(whatsThis
);
2883 // i18n: If the external link isn't available in your language it might make
2884 // sense to state the external link's language in brackets to not
2885 // frustrate the user. If there are multiple languages that the user might
2886 // know with a reasonable chance you might want to have 2 external links.
2887 // The same might be true for any external link you translate.
2888 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>"));
2889 // (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 )
2891 setStandardActionWhatsThis(KStandardAction::WhatsThis
,
2892 xi18nc("@info:whatsthis whatsthis button",
2893 "<para>This is the button that invokes the help feature you are "
2894 "using right now! Click it, then click any component of this "
2895 "application to ask \"What's this?\" about it. The mouse cursor "
2896 "will change appearance if no help is available for a spot.</para>"
2897 "<para>There are two other ways to get help: "
2898 "The <link url='help:/dolphin/index.html'>Dolphin Handbook</link> and "
2899 "the <link url='https://userbase.kde.org/Dolphin/File_Management'>KDE "
2900 "UserBase Wiki</link>.</para><para>The \"What's this?\" help is "
2901 "missing in most other windows so don't get too used to this.</para>"));
2903 setStandardActionWhatsThis(KStandardAction::ReportBug
,
2904 xi18nc("@info:whatsthis","<para>This opens a "
2905 "window that will guide you through reporting errors or flaws "
2906 "in this application or in other KDE software.</para>"
2907 "<para>High-quality bug reports are much appreciated. To learn "
2908 "how to make your bug report as effective as possible "
2909 "<link url='https://community.kde.org/Get_Involved/Bug_Reporting'>"
2910 "click here</link>.</para>"));
2912 setStandardActionWhatsThis(KStandardAction::Donate
,
2913 xi18nc("@info:whatsthis", "<para>This opens a "
2914 "<emphasis>web page</emphasis> where you can donate to "
2915 "support the continued work on this application and many "
2916 "other projects by the <emphasis>KDE</emphasis> community.</para>"
2917 "<para>Donating is the easiest and fastest way to efficiently "
2918 "support KDE and its projects. KDE projects are available for "
2919 "free therefore your donation is needed to cover things that "
2920 "require money like servers, contributor meetings, etc.</para>"
2921 "<para><emphasis>KDE e.V.</emphasis> is the non-profit "
2922 "organization behind the KDE community.</para>"));
2924 setStandardActionWhatsThis(KStandardAction::SwitchApplicationLanguage
,
2925 xi18nc("@info:whatsthis",
2926 "With this you can change the language this application uses."
2927 "<nl/>You can even set secondary languages which will be used "
2928 "if texts are not available in your preferred language."));
2930 setStandardActionWhatsThis(KStandardAction::AboutApp
,
2931 xi18nc("@info:whatsthis","This opens a "
2932 "window that informs you about the version, license, "
2933 "used libraries and maintainers of this application."));
2935 setStandardActionWhatsThis(KStandardAction::AboutKDE
,
2936 xi18nc("@info:whatsthis","This opens a "
2937 "window with information about <emphasis>KDE</emphasis>. "
2938 "The KDE community are the people behind this free software."
2939 "<nl/>If you like using this application but don't know "
2940 "about KDE or want to see a cute dragon have a look!"));
2944 bool DolphinMainWindow::addHamburgerMenuToToolbar()
2946 QDomDocument domDocument
= KXMLGUIClient::domDocument();
2947 if (domDocument
.isNull()) {
2950 QDomNode toolbar
= domDocument
.elementsByTagName(QStringLiteral("ToolBar")).at(0);
2951 if (toolbar
.isNull()) {
2955 QDomElement hamburgerMenuElement
= domDocument
.createElement(QStringLiteral("Action"));
2956 hamburgerMenuElement
.setAttribute(QStringLiteral("name"), QStringLiteral("hamburger_menu"));
2957 toolbar
.appendChild(hamburgerMenuElement
);
2959 KXMLGUIFactory::saveConfigFile(domDocument
, xmlFile());
2963 // Make sure to also remove the <KXMLGUIFactory> and <QDomDocument> include
2964 // whenever this method is removed (maybe in the year ~2026).
2967 // Set a sane initial window size
2968 QSize
DolphinMainWindow::sizeHint() const
2970 return KXmlGuiWindow::sizeHint().expandedTo(QSize(760, 550));
2973 void DolphinMainWindow::saveNewToolbarConfig()
2975 KXmlGuiWindow::saveNewToolbarConfig(); // Applies the new config. This has to be called first
2976 // because the rest of this method decides things
2977 // based on the new config.
2978 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>(actionCollection()->action(QStringLiteral("url_navigators")));
2979 if (!toolBar()->actions().contains(navigators
)) {
2980 m_tabWidget
->currentTabPage()->insertNavigatorsWidget(navigators
);
2982 updateAllowedToolbarAreas();
2983 updateNavigatorsBackground();
2984 (static_cast<KHamburgerMenu
*>(actionCollection()->action(KStandardAction::name(KStandardAction::HamburgerMenu
))))->hideActionsOf(toolBar());
2987 void DolphinMainWindow::toggleTerminalPanelFocus()
2989 if (!m_terminalPanel
->isVisible()) {
2990 actionCollection()->action(QStringLiteral("show_terminal_panel"))->trigger(); // Also moves focus to the panel.
2991 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
2995 if (m_terminalPanel
->terminalHasFocus()) {
2996 m_activeViewContainer
->view()->setFocus(Qt::FocusReason::ShortcutFocusReason
);
2997 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
3001 m_terminalPanel
->setFocus(Qt::FocusReason::ShortcutFocusReason
);
3002 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
3005 void DolphinMainWindow::togglePlacesPanelFocus()
3007 if (!m_placesPanel
->isVisible()) {
3008 actionCollection()->action(QStringLiteral("show_places_panel"))->trigger(); // Also moves focus to the panel.
3009 actionCollection()->action(QStringLiteral("focus_places_panel"))->setText(i18nc("@action:inmenu View", "Defocus Terminal Panel"));
3013 if (m_placesPanel
->hasFocus()) {
3014 m_activeViewContainer
->view()->setFocus(Qt::FocusReason::ShortcutFocusReason
);
3015 actionCollection()->action(QStringLiteral("focus_places_panel"))->setText(i18nc("@action:inmenu View", "Focus Places Panel"));
3019 m_placesPanel
->setFocus(Qt::FocusReason::ShortcutFocusReason
);
3020 actionCollection()->action(QStringLiteral("focus_places_panel"))->setText(i18nc("@action:inmenu View", "Defocus Places Panel"));
3023 DolphinMainWindow::UndoUiInterface::UndoUiInterface()
3024 : KIO::FileUndoManager::UiInterface()
3028 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
3032 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
*job
)
3034 DolphinMainWindow
*mainWin
= qobject_cast
<DolphinMainWindow
*>(parentWidget());
3036 DolphinViewContainer
*container
= mainWin
->activeViewContainer();
3037 container
->showMessage(job
->errorString(), KMessageWidget::Error
);
3039 KIO::FileUndoManager::UiInterface::jobError(job
);
3043 bool DolphinMainWindow::isUrlOpen(const QString
&url
)
3045 return m_tabWidget
->isUrlOpen(QUrl::fromUserInput(url
));
3048 bool DolphinMainWindow::isItemVisibleInAnyView(const QString
&urlOfItem
)
3050 return m_tabWidget
->isItemVisibleInAnyView(QUrl::fromUserInput(urlOfItem
));
3053 void DolphinMainWindow::slotDoubleClickViewBackground(Qt::MouseButton button
)
3055 if (button
!= Qt::MouseButton::LeftButton
) {
3056 // only handle left mouse button for now
3060 GeneralSettings
*settings
= GeneralSettings::self();
3061 QString clickAction
= settings
->doubleClickViewAction();
3063 DolphinView
*view
= activeViewContainer()->view();
3064 if (view
== nullptr || clickAction
== "none") {
3068 if (clickAction
== customCommand
) {
3069 // run custom command set by the user
3070 QString path
= view
->url().toLocalFile();
3071 QString clickCustomAction
= settings
->doubleClickViewCustomAction();
3072 clickCustomAction
.replace("{path}", path
.prepend('"').append('"'));
3074 m_job
= new KIO::CommandLauncherJob(clickCustomAction
);
3075 m_job
->setUiDelegate(new KDialogJobUiDelegate(KJobUiDelegate::AutoHandlingEnabled
, this));
3079 // get the action set by the user and trigger it
3080 const KActionCollection
*actions
= actionCollection();
3081 QAction
*action
= actions
->action(clickAction
);
3082 if (action
== nullptr) {
3083 qCWarning(DolphinDebug
) << QStringLiteral("Double-click view: action `%1` was not found").arg(clickAction
);
3090 #include "moc_dolphinmainwindow.cpp"