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
);
1666 void DolphinMainWindow::tabCountChanged(int count
)
1668 const bool enableTabActions
= (count
> 1);
1669 for (int i
= 0; i
< MaxActivateTabShortcuts
; ++i
) {
1670 actionCollection()->action(QStringLiteral("activate_tab_%1").arg(i
))->setEnabled(enableTabActions
);
1672 actionCollection()->action(QStringLiteral("activate_last_tab"))->setEnabled(enableTabActions
);
1673 actionCollection()->action(QStringLiteral("activate_next_tab"))->setEnabled(enableTabActions
);
1674 actionCollection()->action(QStringLiteral("activate_prev_tab"))->setEnabled(enableTabActions
);
1677 void DolphinMainWindow::updateWindowTitle()
1679 const QString newTitle
= m_activeViewContainer
->captionWindowTitle();
1680 if (windowTitle() != newTitle
) {
1681 setWindowTitle(newTitle
);
1685 void DolphinMainWindow::slotStorageTearDownFromPlacesRequested(const QString
&mountPath
)
1687 connect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, this, [this, mountPath
]() {
1688 setViewsToHomeIfMountPathOpen(mountPath
);
1691 if (m_terminalPanel
&& m_terminalPanel
->currentWorkingDirectoryIsChildOf(mountPath
)) {
1692 m_tearDownFromPlacesRequested
= true;
1693 m_terminalPanel
->goHome();
1694 // m_placesPanel->proceedWithTearDown() will be called in slotTerminalDirectoryChanged
1696 m_placesPanel
->proceedWithTearDown();
1700 void DolphinMainWindow::slotStorageTearDownExternallyRequested(const QString
&mountPath
)
1702 connect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, this, [this, mountPath
]() {
1703 setViewsToHomeIfMountPathOpen(mountPath
);
1706 if (m_terminalPanel
&& m_terminalPanel
->currentWorkingDirectoryIsChildOf(mountPath
)) {
1707 m_tearDownFromPlacesRequested
= false;
1708 m_terminalPanel
->goHome();
1712 void DolphinMainWindow::slotKeyBindings()
1714 KShortcutsDialog
dialog(KShortcutsEditor::AllActions
, KShortcutsEditor::LetterShortcutsAllowed
, this);
1715 dialog
.addCollection(actionCollection());
1716 if (m_terminalPanel
) {
1717 KActionCollection
*konsolePartActionCollection
= m_terminalPanel
->actionCollection();
1718 if (konsolePartActionCollection
) {
1719 dialog
.addCollection(konsolePartActionCollection
, QStringLiteral("KonsolePart"));
1725 void DolphinMainWindow::setViewsToHomeIfMountPathOpen(const QString
&mountPath
)
1727 const QVector
<DolphinViewContainer
*> theViewContainers
= viewContainers();
1728 for (DolphinViewContainer
*viewContainer
: theViewContainers
) {
1729 if (!viewContainer
) {
1732 const auto viewPath
= viewContainer
->url().toLocalFile();
1733 if (viewPath
.startsWith(mountPath
+ QLatin1String("/")) || viewPath
== mountPath
) {
1734 viewContainer
->setUrl(QUrl::fromLocalFile(QDir::homePath()));
1737 disconnect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, nullptr, nullptr);
1740 void DolphinMainWindow::setupActions()
1742 auto hamburgerMenuAction
= KStandardAction::hamburgerMenu(nullptr, nullptr, actionCollection());
1744 // setup 'File' menu
1745 m_newFileMenu
= new DolphinNewFileMenu(nullptr, nullptr, this);
1746 actionCollection()->addAction(QStringLiteral("new_menu"), m_newFileMenu
);
1747 QMenu
*menu
= m_newFileMenu
->menu();
1748 menu
->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1749 menu
->setIcon(QIcon::fromTheme(QStringLiteral("list-add")));
1750 m_newFileMenu
->setPopupMode(QToolButton::InstantPopup
);
1751 connect(menu
, &QMenu::aboutToShow
, this, &DolphinMainWindow::updateNewMenu
);
1753 QAction
*newWindow
= KStandardAction::openNew(this, &DolphinMainWindow::openNewMainWindow
, actionCollection());
1754 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
1755 newWindow
->setToolTip(i18nc("@info", "Open a new Dolphin window"));
1756 newWindow
->setWhatsThis(xi18nc("@info:whatsthis",
1758 "window just like this one with the current location."
1759 "<nl/>You can drag and drop items between windows."));
1760 newWindow
->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
1762 QAction
*newTab
= actionCollection()->addAction(QStringLiteral("new_tab"));
1763 newTab
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1764 newTab
->setText(i18nc("@action:inmenu File", "New Tab"));
1765 newTab
->setWhatsThis(xi18nc("@info:whatsthis",
1767 "<emphasis>Tab</emphasis> with the current location."
1768 "<nl/>Tabs allow you to quickly switch between multiple locations and views within this window. "
1769 "You can drag and drop items between tabs."));
1770 actionCollection()->setDefaultShortcut(newTab
, Qt::CTRL
| Qt::Key_T
);
1771 connect(newTab
, &QAction::triggered
, this, &DolphinMainWindow::openNewActivatedTab
);
1773 QAction
*addToPlaces
= actionCollection()->addAction(QStringLiteral("add_to_places"));
1774 addToPlaces
->setIcon(QIcon::fromTheme(QStringLiteral("bookmark-new")));
1775 addToPlaces
->setText(i18nc("@action:inmenu Add current folder to places", "Add to Places"));
1776 addToPlaces
->setWhatsThis(xi18nc("@info:whatsthis",
1777 "This adds the selected folder "
1778 "to the Places panel."));
1779 connect(addToPlaces
, &QAction::triggered
, this, &DolphinMainWindow::addToPlaces
);
1781 QAction
*closeTab
= KStandardAction::close(m_tabWidget
, QOverload
<>::of(&DolphinTabWidget::closeTab
), actionCollection());
1782 closeTab
->setText(i18nc("@action:inmenu File", "Close Tab"));
1783 closeTab
->setToolTip(i18nc("@info", "Close Tab"));
1784 closeTab
->setWhatsThis(i18nc("@info:whatsthis",
1786 "currently viewed tab. If no more tabs are left, this closes "
1787 "the whole window instead."));
1789 QAction
*quitAction
= KStandardAction::quit(this, &DolphinMainWindow::quit
, actionCollection());
1790 quitAction
->setWhatsThis(i18nc("@info:whatsthis quit", "This closes this window."));
1792 // setup 'Edit' menu
1793 KStandardAction::undo(this, &DolphinMainWindow::undo
, actionCollection());
1795 // i18n: This will be the last paragraph for the whatsthis for all three:
1796 // Cut, Copy and Paste
1797 const QString cutCopyPastePara
= xi18nc("@info:whatsthis",
1798 "<para><emphasis>Cut, "
1799 "Copy</emphasis> and <emphasis>Paste</emphasis> work between many "
1800 "applications and are among the most used commands. That's why their "
1801 "<emphasis>keyboard shortcuts</emphasis> are prominently placed right "
1802 "next to each other on the keyboard: <shortcut>Ctrl+X</shortcut>, "
1803 "<shortcut>Ctrl+C</shortcut> and <shortcut>Ctrl+V</shortcut>.</para>");
1804 QAction
*cutAction
= KStandardAction::cut(this, &DolphinMainWindow::cut
, actionCollection());
1805 m_actionTextHelper
->registerTextWhenNothingIsSelected(cutAction
, i18nc("@action", "Cut…"));
1806 cutAction
->setWhatsThis(xi18nc("@info:whatsthis cut",
1807 "This copies the items "
1808 "in your current selection to the <emphasis>clipboard</emphasis>.<nl/>"
1809 "Use the <emphasis>Paste</emphasis> action afterwards to copy them from "
1810 "the clipboard to a new location. The items will be removed from their "
1811 "initial location.")
1812 + cutCopyPastePara
);
1813 QAction
*copyAction
= KStandardAction::copy(this, &DolphinMainWindow::copy
, actionCollection());
1814 m_actionTextHelper
->registerTextWhenNothingIsSelected(copyAction
, i18nc("@action", "Copy…"));
1815 copyAction
->setWhatsThis(xi18nc("@info:whatsthis copy",
1817 "items in your current selection to the <emphasis>clipboard</emphasis>."
1818 "<nl/>Use the <emphasis>Paste</emphasis> action afterwards to copy them "
1819 "from the clipboard to a new location.")
1820 + cutCopyPastePara
);
1821 QAction
*paste
= KStandardAction::paste(this, &DolphinMainWindow::paste
, actionCollection());
1822 // The text of the paste-action is modified dynamically by Dolphin
1823 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1824 // due to the long text, the text "Paste" is used:
1825 paste
->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1826 paste
->setWhatsThis(xi18nc("@info:whatsthis paste",
1827 "This copies the items from "
1828 "your <emphasis>clipboard</emphasis> to the currently viewed folder.<nl/>"
1829 "If the items were added to the clipboard by the <emphasis>Cut</emphasis> "
1830 "action they are removed from their old location.")
1831 + cutCopyPastePara
);
1833 QAction
*copyToOtherViewAction
= actionCollection()->addAction(QStringLiteral("copy_to_inactive_split_view"));
1834 copyToOtherViewAction
->setText(i18nc("@action:inmenu", "Copy to Other View"));
1835 m_actionTextHelper
->registerTextWhenNothingIsSelected(copyToOtherViewAction
, i18nc("@action:inmenu", "Copy to Other View…"));
1836 copyToOtherViewAction
->setWhatsThis(xi18nc("@info:whatsthis Copy",
1837 "This copies the selected items from "
1838 "the view in focus to the other view. "
1839 "(Only available while in Split View mode.)"));
1840 copyToOtherViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("edit-copy")));
1841 copyToOtherViewAction
->setIconText(i18nc("@action:inmenu Edit", "Copy to Other View"));
1842 actionCollection()->setDefaultShortcut(copyToOtherViewAction
, Qt::SHIFT
| Qt::Key_F5
);
1843 connect(copyToOtherViewAction
, &QAction::triggered
, this, &DolphinMainWindow::copyToInactiveSplitView
);
1845 QAction
*moveToOtherViewAction
= actionCollection()->addAction(QStringLiteral("move_to_inactive_split_view"));
1846 moveToOtherViewAction
->setText(i18nc("@action:inmenu", "Move to Other View"));
1847 m_actionTextHelper
->registerTextWhenNothingIsSelected(moveToOtherViewAction
, i18nc("@action:inmenu", "Move to Other View…"));
1848 moveToOtherViewAction
->setWhatsThis(xi18nc("@info:whatsthis Move",
1849 "This moves the selected items from "
1850 "the view in focus to the other view. "
1851 "(Only available while in Split View mode.)"));
1852 moveToOtherViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("edit-cut")));
1853 moveToOtherViewAction
->setIconText(i18nc("@action:inmenu Edit", "Move to Other View"));
1854 actionCollection()->setDefaultShortcut(moveToOtherViewAction
, Qt::SHIFT
| Qt::Key_F6
);
1855 connect(moveToOtherViewAction
, &QAction::triggered
, this, &DolphinMainWindow::moveToInactiveSplitView
);
1857 QAction
*showFilterBar
= actionCollection()->addAction(QStringLiteral("show_filter_bar"));
1858 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Filter…"));
1859 showFilterBar
->setToolTip(i18nc("@info:tooltip", "Show Filter Bar"));
1860 showFilterBar
->setWhatsThis(xi18nc("@info:whatsthis",
1862 "<emphasis>Filter Bar</emphasis> at the bottom of the window.<nl/> "
1863 "There you can enter text to filter the files and folders currently displayed. "
1864 "Only those that contain the text in their name will be kept in view."));
1865 showFilterBar
->setIcon(QIcon::fromTheme(QStringLiteral("view-filter")));
1866 actionCollection()->setDefaultShortcuts(showFilterBar
, {Qt::CTRL
| Qt::Key_I
, Qt::Key_Slash
});
1867 connect(showFilterBar
, &QAction::triggered
, this, &DolphinMainWindow::showFilterBar
);
1869 // toggle_filter acts as a copy of the main showFilterBar to be used mainly
1870 // in the toolbar, with no default shortcut attached, to avoid messing with
1871 // existing workflows (filter bar always open and Ctrl-I to focus)
1872 QAction
*toggleFilter
= actionCollection()->addAction(QStringLiteral("toggle_filter"));
1873 toggleFilter
->setText(i18nc("@action:inmenu", "Toggle Filter Bar"));
1874 toggleFilter
->setIconText(i18nc("@action:intoolbar", "Filter"));
1875 toggleFilter
->setIcon(showFilterBar
->icon());
1876 toggleFilter
->setToolTip(showFilterBar
->toolTip());
1877 toggleFilter
->setWhatsThis(showFilterBar
->whatsThis());
1878 toggleFilter
->setCheckable(true);
1879 connect(toggleFilter
, &QAction::triggered
, this, &DolphinMainWindow::toggleFilterBar
);
1881 QAction
*searchAction
= KStandardAction::find(this, &DolphinMainWindow::find
, actionCollection());
1882 searchAction
->setText(i18n("Search…"));
1883 searchAction
->setToolTip(i18nc("@info:tooltip", "Search for files and folders"));
1884 searchAction
->setWhatsThis(xi18nc("@info:whatsthis find",
1885 "<para>This helps you "
1886 "find files and folders by opening a <emphasis>search bar</emphasis>. "
1887 "There you can enter search terms and specify settings to find the "
1888 "items you are looking for.</para>"));
1890 // toggle_search acts as a copy of the main searchAction to be used mainly
1891 // in the toolbar, with no default shortcut attached, to avoid messing with
1892 // existing workflows (search bar always open and Ctrl-F to focus)
1893 QAction
*toggleSearchAction
= actionCollection()->addAction(QStringLiteral("toggle_search"));
1894 toggleSearchAction
->setText(i18nc("@action:inmenu", "Toggle Search Bar"));
1895 toggleSearchAction
->setIconText(i18nc("@action:intoolbar", "Search"));
1896 toggleSearchAction
->setIcon(searchAction
->icon());
1897 toggleSearchAction
->setToolTip(searchAction
->toolTip());
1898 toggleSearchAction
->setWhatsThis(searchAction
->whatsThis());
1899 toggleSearchAction
->setCheckable(true);
1900 connect(toggleSearchAction
, &QAction::triggered
, this, [this](bool checked
) {
1904 m_activeViewContainer
->setSearchBarVisible(false);
1908 QAction
*toggleSelectionModeAction
= actionCollection()->addAction(QStringLiteral("toggle_selection_mode"));
1909 // i18n: This action toggles a selection mode.
1910 toggleSelectionModeAction
->setText(i18nc("@action:inmenu", "Select Files and Folders"));
1911 // i18n: Opens a selection mode for selecting files/folders.
1912 // The text is kept so unspecific because it will be shown on the toolbar where space is at a premium.
1913 toggleSelectionModeAction
->setIconText(i18nc("@action:intoolbar", "Select"));
1914 toggleSelectionModeAction
->setWhatsThis(xi18nc(
1916 "<para>This application only knows which files or folders should be acted on if they are"
1917 " <emphasis>selected</emphasis> first. Press this to toggle a <emphasis>Selection Mode</emphasis> which makes selecting and deselecting as easy as "
1918 "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."
1920 toggleSelectionModeAction
->setIcon(QIcon::fromTheme(QStringLiteral("quickwizard")));
1921 toggleSelectionModeAction
->setCheckable(true);
1922 actionCollection()->setDefaultShortcut(toggleSelectionModeAction
, Qt::Key_Space
);
1923 connect(toggleSelectionModeAction
, &QAction::triggered
, this, &DolphinMainWindow::toggleSelectionMode
);
1925 // A special version of the toggleSelectionModeAction for the toolbar that also contains a menu
1926 // with the selectAllAction and invertSelectionAction.
1927 auto *toggleSelectionModeToolBarAction
=
1928 new KToolBarPopupAction(toggleSelectionModeAction
->icon(), toggleSelectionModeAction
->iconText(), actionCollection());
1929 toggleSelectionModeToolBarAction
->setToolTip(toggleSelectionModeAction
->text());
1930 toggleSelectionModeToolBarAction
->setWhatsThis(toggleSelectionModeAction
->whatsThis());
1931 actionCollection()->addAction(QStringLiteral("toggle_selection_mode_tool_bar"), toggleSelectionModeToolBarAction
);
1932 toggleSelectionModeToolBarAction
->setCheckable(true);
1933 toggleSelectionModeToolBarAction
->setPopupMode(KToolBarPopupAction::DelayedPopup
);
1934 connect(toggleSelectionModeToolBarAction
, &QAction::triggered
, toggleSelectionModeAction
, &QAction::trigger
);
1935 connect(toggleSelectionModeAction
, &QAction::toggled
, toggleSelectionModeToolBarAction
, &QAction::setChecked
);
1937 QAction
*selectAllAction
= KStandardAction::selectAll(this, &DolphinMainWindow::selectAll
, actionCollection());
1938 selectAllAction
->setWhatsThis(xi18nc("@info:whatsthis",
1940 "files and folders in the current location."));
1942 QAction
*invertSelection
= actionCollection()->addAction(QStringLiteral("invert_selection"));
1943 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1944 invertSelection
->setWhatsThis(xi18nc("@info:whatsthis invert",
1946 "items that you have currently <emphasis>not</emphasis> selected instead."));
1947 invertSelection
->setIcon(QIcon::fromTheme(QStringLiteral("edit-select-invert")));
1948 actionCollection()->setDefaultShortcut(invertSelection
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
1949 connect(invertSelection
, &QAction::triggered
, this, &DolphinMainWindow::invertSelection
);
1951 QMenu
*toggleSelectionModeActionMenu
= new QMenu(this);
1952 toggleSelectionModeActionMenu
->addAction(selectAllAction
);
1953 toggleSelectionModeActionMenu
->addAction(invertSelection
);
1954 toggleSelectionModeToolBarAction
->setMenu(toggleSelectionModeActionMenu
);
1956 // setup 'View' menu
1957 // (note that most of it is set up in DolphinViewActionHandler)
1959 Admin::WorkerIntegration::createActAsAdminAction(actionCollection(), this);
1961 m_splitViewAction
= actionCollection()->add
<KActionMenu
>(QStringLiteral("split_view"));
1962 m_splitViewMenuAction
= actionCollection()->addAction(QStringLiteral("split_view_menu"));
1964 m_splitViewAction
->setWhatsThis(xi18nc("@info:whatsthis split",
1965 "<para>This presents "
1966 "a second view side-by-side with the current view, so you can see "
1967 "the contents of two folders at once and easily move items between "
1968 "them.</para><para>The view that is not \"in focus\" will be dimmed. "
1969 "</para>Click this button again to close one of the views."));
1970 m_splitViewMenuAction
->setWhatsThis(m_splitViewAction
->whatsThis());
1972 // only set it for the menu version
1973 actionCollection()->setDefaultShortcut(m_splitViewMenuAction
, Qt::Key_F3
);
1975 connect(m_splitViewAction
, &QAction::triggered
, this, &DolphinMainWindow::toggleSplitView
);
1976 connect(m_splitViewMenuAction
, &QAction::triggered
, this, &DolphinMainWindow::toggleSplitView
);
1978 QAction
*popoutSplit
= actionCollection()->addAction(QStringLiteral("popout_split_view"));
1979 popoutSplit
->setWhatsThis(xi18nc("@info:whatsthis",
1980 "If the view has been split, this will pop the view in focus "
1981 "out into a new window."));
1982 popoutSplit
->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
1983 actionCollection()->setDefaultShortcut(popoutSplit
, Qt::SHIFT
| Qt::Key_F3
);
1984 connect(popoutSplit
, &QAction::triggered
, this, &DolphinMainWindow::popoutSplitView
);
1986 QAction
*stashSplit
= actionCollection()->addAction(QStringLiteral("split_stash"));
1987 actionCollection()->setDefaultShortcut(stashSplit
, Qt::CTRL
| Qt::Key_S
);
1988 stashSplit
->setText(i18nc("@action:intoolbar Stash", "Stash"));
1989 stashSplit
->setToolTip(i18nc("@info", "Opens the stash virtual directory in a split window"));
1990 stashSplit
->setIcon(QIcon::fromTheme(QStringLiteral("folder-stash")));
1991 stashSplit
->setCheckable(false);
1992 QDBusConnectionInterface
*sessionInterface
= QDBusConnection::sessionBus().interface();
1993 stashSplit
->setVisible(sessionInterface
&& sessionInterface
->isServiceRegistered(QStringLiteral("org.kde.kio.StashNotifier")));
1994 connect(stashSplit
, &QAction::triggered
, this, &DolphinMainWindow::toggleSplitStash
);
1996 QAction
*redisplay
= KStandardAction::redisplay(this, &DolphinMainWindow::reloadView
, actionCollection());
1997 redisplay
->setToolTip(i18nc("@info:tooltip", "Refresh view"));
1998 redisplay
->setWhatsThis(xi18nc("@info:whatsthis refresh",
1999 "<para>This refreshes "
2000 "the folder view.</para>"
2001 "<para>If the contents of this folder have changed, refreshing will re-scan this folder "
2002 "and show you a newly-updated view of the files and folders contained here.</para>"
2003 "<para>If the view is split, this refreshes the one that is currently in focus.</para>"));
2005 QAction
*stop
= actionCollection()->addAction(QStringLiteral("stop"));
2006 stop
->setText(i18nc("@action:inmenu View", "Stop"));
2007 stop
->setToolTip(i18nc("@info", "Stop loading"));
2008 stop
->setWhatsThis(i18nc("@info", "This stops the loading of the contents of the current folder."));
2009 stop
->setIcon(QIcon::fromTheme(QStringLiteral("process-stop")));
2010 connect(stop
, &QAction::triggered
, this, &DolphinMainWindow::stopLoading
);
2012 KToggleAction
*editableLocation
= actionCollection()->add
<KToggleAction
>(QStringLiteral("editable_location"));
2013 editableLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
2014 editableLocation
->setWhatsThis(xi18nc("@info:whatsthis",
2015 "This toggles the <emphasis>Location Bar</emphasis> to be "
2016 "editable so you can directly enter a location you want to go to.<nl/>"
2017 "You can also switch to editing by clicking to the right of the "
2018 "location and switch back by confirming the edited location."));
2019 actionCollection()->setDefaultShortcut(editableLocation
, Qt::Key_F6
);
2020 connect(editableLocation
, &KToggleAction::triggered
, this, &DolphinMainWindow::toggleEditLocation
);
2022 QAction
*replaceLocation
= actionCollection()->addAction(QStringLiteral("replace_location"));
2023 replaceLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
2024 // i18n: "enter" is used both in the meaning of "writing" and "going to" a new location here.
2025 // Both meanings are useful but not necessary to understand the use of "Replace Location".
2026 // So you might want to be more verbose in your language to convey the meaning but it's up to you.
2027 replaceLocation
->setWhatsThis(xi18nc("@info:whatsthis",
2028 "This switches to editing the location and selects it "
2029 "so you can quickly enter a different location."));
2030 actionCollection()->setDefaultShortcuts(replaceLocation
, {Qt::CTRL
| Qt::Key_L
, Qt::ALT
| Qt::Key_D
});
2031 connect(replaceLocation
, &QAction::triggered
, this, &DolphinMainWindow::replaceLocation
);
2035 QScopedPointer
<QAction
> backAction(KStandardAction::back(nullptr, nullptr, nullptr));
2036 m_backAction
= new KToolBarPopupAction(backAction
->icon(), backAction
->text(), actionCollection());
2037 m_backAction
->setObjectName(backAction
->objectName());
2038 m_backAction
->setShortcuts(backAction
->shortcuts());
2040 m_backAction
->setPopupMode(KToolBarPopupAction::DelayedPopup
);
2041 connect(m_backAction
, &QAction::triggered
, this, &DolphinMainWindow::goBack
);
2042 connect(m_backAction
->popupMenu(), &QMenu::aboutToShow
, this, &DolphinMainWindow::slotAboutToShowBackPopupMenu
);
2043 connect(m_backAction
->popupMenu(), &QMenu::triggered
, this, &DolphinMainWindow::slotGoBack
);
2044 actionCollection()->addAction(m_backAction
->objectName(), m_backAction
);
2046 auto backShortcuts
= m_backAction
->shortcuts();
2047 // Prepend this shortcut, to avoid being hidden by the two-slot UI (#371130)
2048 backShortcuts
.prepend(QKeySequence(Qt::Key_Backspace
));
2049 actionCollection()->setDefaultShortcuts(m_backAction
, backShortcuts
);
2051 DolphinRecentTabsMenu
*recentTabsMenu
= new DolphinRecentTabsMenu(this);
2052 actionCollection()->addAction(QStringLiteral("closed_tabs"), recentTabsMenu
);
2053 connect(m_tabWidget
, &DolphinTabWidget::rememberClosedTab
, recentTabsMenu
, &DolphinRecentTabsMenu::rememberClosedTab
);
2054 connect(recentTabsMenu
, &DolphinRecentTabsMenu::restoreClosedTab
, m_tabWidget
, &DolphinTabWidget::restoreClosedTab
);
2055 connect(recentTabsMenu
, &DolphinRecentTabsMenu::closedTabsCountChanged
, this, &DolphinMainWindow::closedTabsCountChanged
);
2057 QAction
*undoCloseTab
= actionCollection()->addAction(QStringLiteral("undo_close_tab"));
2058 undoCloseTab
->setText(i18nc("@action:inmenu File", "Undo close tab"));
2059 undoCloseTab
->setWhatsThis(i18nc("@info:whatsthis undo close tab", "This returns you to the previously closed tab."));
2060 actionCollection()->setDefaultShortcut(undoCloseTab
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_T
);
2061 undoCloseTab
->setIcon(QIcon::fromTheme(QStringLiteral("edit-undo")));
2062 undoCloseTab
->setEnabled(false);
2063 connect(undoCloseTab
, &QAction::triggered
, recentTabsMenu
, &DolphinRecentTabsMenu::undoCloseTab
);
2065 auto undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
2066 undoAction
->setWhatsThis(xi18nc("@info:whatsthis",
2068 "the last change you made to files or folders.<nl/>"
2069 "Such changes include <interface>creating</interface>, <interface>renaming</interface> "
2070 "and <interface>moving</interface> them to a different location "
2071 "or to the <filename>Trash</filename>. <nl/>Any changes that cannot be undone "
2072 "will ask for your confirmation beforehand."));
2073 undoAction
->setEnabled(false); // undo should be disabled by default
2076 QScopedPointer
<QAction
> forwardAction(KStandardAction::forward(nullptr, nullptr, nullptr));
2077 m_forwardAction
= new KToolBarPopupAction(forwardAction
->icon(), forwardAction
->text(), actionCollection());
2078 m_forwardAction
->setObjectName(forwardAction
->objectName());
2079 m_forwardAction
->setShortcuts(forwardAction
->shortcuts());
2081 m_forwardAction
->setPopupMode(KToolBarPopupAction::DelayedPopup
);
2082 connect(m_forwardAction
, &QAction::triggered
, this, &DolphinMainWindow::goForward
);
2083 connect(m_forwardAction
->popupMenu(), &QMenu::aboutToShow
, this, &DolphinMainWindow::slotAboutToShowForwardPopupMenu
);
2084 connect(m_forwardAction
->popupMenu(), &QMenu::triggered
, this, &DolphinMainWindow::slotGoForward
);
2085 actionCollection()->addAction(m_forwardAction
->objectName(), m_forwardAction
);
2086 actionCollection()->setDefaultShortcuts(m_forwardAction
, m_forwardAction
->shortcuts());
2088 // enable middle-click to open in a new tab
2089 auto *middleClickEventFilter
= new MiddleClickActionEventFilter(this);
2090 connect(middleClickEventFilter
, &MiddleClickActionEventFilter::actionMiddleClicked
, this, &DolphinMainWindow::slotBackForwardActionMiddleClicked
);
2091 m_backAction
->popupMenu()->installEventFilter(middleClickEventFilter
);
2092 m_forwardAction
->popupMenu()->installEventFilter(middleClickEventFilter
);
2093 KStandardAction::up(this, &DolphinMainWindow::goUp
, actionCollection());
2094 QAction
*homeAction
= KStandardAction::home(this, &DolphinMainWindow::goHome
, actionCollection());
2095 homeAction
->setWhatsThis(xi18nc("@info:whatsthis",
2097 "<filename>Home</filename> folder.<nl/>Every user account "
2098 "has their own <filename>Home</filename> that contains their personal files, "
2099 "as well as hidden folders for their applications' data and configuration files."));
2101 // setup 'Tools' menu
2102 QAction
*compareFiles
= actionCollection()->addAction(QStringLiteral("compare_files"));
2103 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
2104 compareFiles
->setIcon(QIcon::fromTheme(QStringLiteral("kompare")));
2105 compareFiles
->setEnabled(false);
2106 connect(compareFiles
, &QAction::triggered
, this, &DolphinMainWindow::compareFiles
);
2108 QAction
*manageDiskSpaceUsage
= actionCollection()->addAction(QStringLiteral("manage_disk_space"));
2109 manageDiskSpaceUsage
->setText(i18nc("@action:inmenu Tools", "Manage Disk Space Usage"));
2110 manageDiskSpaceUsage
->setIcon(QIcon::fromTheme(QStringLiteral("filelight")));
2111 m_diskSpaceUsageMenu
= new DiskSpaceUsageMenu
{this};
2112 manageDiskSpaceUsage
->setMenu(m_diskSpaceUsageMenu
);
2114 QAction
*openPreferredSearchTool
= actionCollection()->addAction(QStringLiteral("open_preferred_search_tool"));
2115 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool"));
2116 openPreferredSearchTool
->setWhatsThis(xi18nc("@info:whatsthis",
2117 "<para>This opens a preferred search tool for the viewed location.</para>"
2118 "<para>Use <emphasis>More Search Tools</emphasis> menu to configure it.</para>"));
2119 openPreferredSearchTool
->setIcon(QIcon::fromTheme(QStringLiteral("search")));
2120 actionCollection()->setDefaultShortcut(openPreferredSearchTool
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_F
);
2121 connect(openPreferredSearchTool
, &QAction::triggered
, this, &DolphinMainWindow::openPreferredSearchTool
);
2123 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
2124 // Get icon of user default terminal emulator application
2125 const KConfigGroup
group(KSharedConfig::openConfig(QStringLiteral("kdeglobals"), KConfig::SimpleConfig
), QStringLiteral("General"));
2126 const QString terminalDesktopFilename
= group
.readEntry("TerminalService");
2127 // Use utilities-terminal icon from theme if readEntry() has failed
2128 const QString terminalIcon
= terminalDesktopFilename
.isEmpty() ? "utilities-terminal" : KDesktopFile(terminalDesktopFilename
).readIcon();
2130 QAction
*openTerminal
= actionCollection()->addAction(QStringLiteral("open_terminal"));
2131 openTerminal
->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
2132 openTerminal
->setWhatsThis(xi18nc("@info:whatsthis",
2133 "<para>This opens a <emphasis>terminal</emphasis> application for the viewed location.</para>"
2134 "<para>To learn more about terminals use the help features in the terminal application.</para>"));
2135 openTerminal
->setIcon(QIcon::fromTheme(terminalIcon
));
2136 actionCollection()->setDefaultShortcut(openTerminal
, Qt::SHIFT
| Qt::Key_F4
);
2137 connect(openTerminal
, &QAction::triggered
, this, &DolphinMainWindow::openTerminal
);
2139 QAction
*openTerminalHere
= actionCollection()->addAction(QStringLiteral("open_terminal_here"));
2140 // i18n: "Here" refers to the location(s) of the currently selected item(s) or the currently viewed location if nothing is selected.
2141 openTerminalHere
->setText(i18nc("@action:inmenu Tools", "Open Terminal Here"));
2142 openTerminalHere
->setWhatsThis(xi18nc("@info:whatsthis",
2143 "<para>This opens <emphasis>terminal</emphasis> applications for the selected items' locations.</para>"
2144 "<para>To learn more about terminals use the help features in the terminal application.</para>"));
2145 openTerminalHere
->setIcon(QIcon::fromTheme(terminalIcon
));
2146 actionCollection()->setDefaultShortcut(openTerminalHere
, Qt::SHIFT
| Qt::ALT
| Qt::Key_F4
);
2147 connect(openTerminalHere
, &QAction::triggered
, this, &DolphinMainWindow::openTerminalHere
);
2150 // setup 'Bookmarks' menu
2151 KActionMenu
*bookmarkMenu
= new KActionMenu(i18nc("@title:menu", "&Bookmarks"), this);
2152 bookmarkMenu
->setIcon(QIcon::fromTheme(QStringLiteral("bookmarks")));
2153 // Make the toolbar button version work properly on click
2154 bookmarkMenu
->setPopupMode(QToolButton::InstantPopup
);
2155 m_bookmarkHandler
= new DolphinBookmarkHandler(this, actionCollection(), bookmarkMenu
->menu(), this);
2156 actionCollection()->addAction(QStringLiteral("bookmarks"), bookmarkMenu
);
2158 // setup 'Settings' menu
2159 KToggleAction
*showMenuBar
= KStandardAction::showMenubar(nullptr, nullptr, actionCollection());
2160 showMenuBar
->setWhatsThis(xi18nc("@info:whatsthis",
2161 "<para>This switches between having a <emphasis>Menubar</emphasis> "
2162 "and having an <interface>%1</interface> button. Both "
2163 "contain mostly the same actions and configuration options.</para>"
2164 "<para>The Menubar takes up more space but allows for fast and organized access to all "
2165 "actions an application has to offer.</para><para>The %1 button "
2166 "is simpler and small which makes triggering advanced actions more time consuming.</para>",
2167 hamburgerMenuAction
->text().replace('&', "")));
2168 connect(showMenuBar
,
2169 &KToggleAction::triggered
, // Fixes #286822
2171 &DolphinMainWindow::toggleShowMenuBar
,
2172 Qt::QueuedConnection
);
2174 KStandardAction::keyBindings(this, &DolphinMainWindow::slotKeyBindings
, actionCollection());
2175 KStandardAction::preferences(this, &DolphinMainWindow::editSettings
, actionCollection());
2177 // not in menu actions
2178 QList
<QKeySequence
> nextTabKeys
= KStandardShortcut::tabNext();
2179 nextTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::Key_Tab
));
2181 QList
<QKeySequence
> prevTabKeys
= KStandardShortcut::tabPrev();
2182 prevTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::SHIFT
| Qt::Key_Tab
));
2184 for (int i
= 0; i
< MaxActivateTabShortcuts
; ++i
) {
2185 QAction
*activateTab
= actionCollection()->addAction(QStringLiteral("activate_tab_%1").arg(i
));
2186 activateTab
->setText(i18nc("@action:inmenu", "Go to Tab %1", i
+ 1));
2187 activateTab
->setEnabled(false);
2188 connect(activateTab
, &QAction::triggered
, this, [this, i
]() {
2189 m_tabWidget
->activateTab(i
);
2192 // only add default shortcuts for the first 9 tabs regardless of MaxActivateTabShortcuts
2194 actionCollection()->setDefaultShortcut(activateTab
, QStringLiteral("Alt+%1").arg(i
+ 1));
2198 QAction
*activateLastTab
= actionCollection()->addAction(QStringLiteral("activate_last_tab"));
2199 activateLastTab
->setIconText(i18nc("@action:inmenu", "Last Tab"));
2200 activateLastTab
->setText(i18nc("@action:inmenu", "Go to Last Tab"));
2201 activateLastTab
->setEnabled(false);
2202 connect(activateLastTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activateLastTab
);
2203 actionCollection()->setDefaultShortcut(activateLastTab
, Qt::ALT
| Qt::Key_0
);
2205 QAction
*activateNextTab
= actionCollection()->addAction(QStringLiteral("activate_next_tab"));
2206 activateNextTab
->setIconText(i18nc("@action:inmenu", "Next Tab"));
2207 activateNextTab
->setText(i18nc("@action:inmenu", "Go to Next Tab"));
2208 activateNextTab
->setEnabled(false);
2209 connect(activateNextTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activateNextTab
);
2210 actionCollection()->setDefaultShortcuts(activateNextTab
, nextTabKeys
);
2212 QAction
*activatePrevTab
= actionCollection()->addAction(QStringLiteral("activate_prev_tab"));
2213 activatePrevTab
->setIconText(i18nc("@action:inmenu", "Previous Tab"));
2214 activatePrevTab
->setText(i18nc("@action:inmenu", "Go to Previous Tab"));
2215 activatePrevTab
->setEnabled(false);
2216 connect(activatePrevTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activatePrevTab
);
2217 actionCollection()->setDefaultShortcuts(activatePrevTab
, prevTabKeys
);
2220 QAction
*showTarget
= actionCollection()->addAction(QStringLiteral("show_target"));
2221 showTarget
->setText(i18nc("@action:inmenu", "Show Target"));
2222 showTarget
->setIcon(QIcon::fromTheme(QStringLiteral("document-open-folder")));
2223 showTarget
->setEnabled(false);
2224 connect(showTarget
, &QAction::triggered
, this, &DolphinMainWindow::showTarget
);
2226 QAction
*openInNewTab
= actionCollection()->addAction(QStringLiteral("open_in_new_tab"));
2227 openInNewTab
->setText(i18nc("@action:inmenu", "Open in New Tab"));
2228 openInNewTab
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
2229 connect(openInNewTab
, &QAction::triggered
, this, &DolphinMainWindow::openInNewTab
);
2231 QAction
*openInNewTabs
= actionCollection()->addAction(QStringLiteral("open_in_new_tabs"));
2232 openInNewTabs
->setText(i18nc("@action:inmenu", "Open in New Tabs"));
2233 openInNewTabs
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
2234 connect(openInNewTabs
, &QAction::triggered
, this, &DolphinMainWindow::openInNewTab
);
2236 QAction
*openInNewWindow
= actionCollection()->addAction(QStringLiteral("open_in_new_window"));
2237 openInNewWindow
->setText(i18nc("@action:inmenu", "Open in New Window"));
2238 openInNewWindow
->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
2239 connect(openInNewWindow
, &QAction::triggered
, this, &DolphinMainWindow::openInNewWindow
);
2241 QAction
*openInSplitViewAction
= actionCollection()->addAction(QStringLiteral("open_in_split_view"));
2242 openInSplitViewAction
->setText(i18nc("@action:inmenu", "Open in Split View"));
2243 openInSplitViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-split-left-right")));
2244 connect(openInSplitViewAction
, &QAction::triggered
, this, [this]() {
2245 openInSplitView(QUrl());
2248 m_recentFiles
= new KRecentFilesAction(this);
2251 void DolphinMainWindow::setupDockWidgets()
2253 const bool lock
= GeneralSettings::lockPanels();
2255 DolphinPlacesModelSingleton::instance().placesModel()->setPanelsLocked(lock
);
2257 KDualAction
*lockLayoutAction
= actionCollection()->add
<KDualAction
>(QStringLiteral("lock_panels"));
2258 lockLayoutAction
->setActiveText(i18nc("@action:inmenu Panels", "Unlock Panels"));
2259 lockLayoutAction
->setActiveIcon(QIcon::fromTheme(QStringLiteral("object-unlocked")));
2260 lockLayoutAction
->setInactiveText(i18nc("@action:inmenu Panels", "Lock Panels"));
2261 lockLayoutAction
->setInactiveIcon(QIcon::fromTheme(QStringLiteral("object-locked")));
2262 lockLayoutAction
->setWhatsThis(xi18nc("@info:whatsthis",
2264 "switches between having panels <emphasis>locked</emphasis> or "
2265 "<emphasis>unlocked</emphasis>.<nl/>Unlocked panels can be "
2266 "dragged to the other side of the window and have a close "
2267 "button.<nl/>Locked panels are embedded more cleanly."));
2268 lockLayoutAction
->setActive(lock
);
2269 connect(lockLayoutAction
, &KDualAction::triggered
, this, &DolphinMainWindow::togglePanelLockState
);
2271 // Setup "Information"
2272 DolphinDockWidget
*infoDock
= new DolphinDockWidget(i18nc("@title:window", "Information"));
2273 infoDock
->setLocked(lock
);
2274 infoDock
->setObjectName(QStringLiteral("infoDock"));
2275 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
2278 InformationPanel
*infoPanel
= new InformationPanel(infoDock
);
2279 infoPanel
->setCustomContextMenuActions({lockLayoutAction
});
2280 connect(infoPanel
, &InformationPanel::urlActivated
, this, &DolphinMainWindow::handleUrl
);
2281 infoDock
->setWidget(infoPanel
);
2283 createPanelAction(QIcon::fromTheme(QStringLiteral("documentinfo")), Qt::Key_F11
, infoDock
, QStringLiteral("show_information_panel"));
2285 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
2286 connect(this, &DolphinMainWindow::urlChanged
, infoPanel
, &InformationPanel::setUrl
);
2287 connect(this, &DolphinMainWindow::selectionChanged
, infoPanel
, &InformationPanel::setSelection
);
2288 connect(this, &DolphinMainWindow::requestItemInfo
, infoPanel
, &InformationPanel::requestDelayedItemInfo
);
2289 connect(this, &DolphinMainWindow::fileItemsChanged
, infoPanel
, &InformationPanel::slotFilesItemChanged
);
2290 connect(this, &DolphinMainWindow::settingsChanged
, infoPanel
, &InformationPanel::readSettings
);
2293 // i18n: This is the last paragraph for the "What's This"-texts of all four panels.
2294 const QString panelWhatsThis
= xi18nc("@info:whatsthis",
2296 "hide panels like this go to <interface>Menu|Panels</interface> "
2297 "or <interface>View|Panels</interface>.</para>");
2300 ->action(QStringLiteral("show_information_panel"))
2301 ->setWhatsThis(xi18nc("@info:whatsthis",
2302 "<para> This toggles the "
2303 "<emphasis>information</emphasis> panel at the right side of the "
2304 "window.</para><para>The panel provides in-depth information "
2305 "about the items your mouse is hovering over or about the selected "
2306 "items. Otherwise it informs you about the currently viewed folder.<nl/>"
2307 "For single items a preview of their contents is provided.</para>"));
2309 infoDock
->setWhatsThis(xi18nc("@info:whatsthis",
2311 "provides in-depth information about the items your mouse is "
2312 "hovering over or about the selected items. Otherwise it informs "
2313 "you about the currently viewed folder.<nl/>For single items a "
2314 "preview of their contents is provided.</para><para>You can configure "
2315 "which and how details are given here by right-clicking.</para>")
2319 DolphinDockWidget
*foldersDock
= new DolphinDockWidget(i18nc("@title:window", "Folders"));
2320 foldersDock
->setLocked(lock
);
2321 foldersDock
->setObjectName(QStringLiteral("foldersDock"));
2322 foldersDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
2323 FoldersPanel
*foldersPanel
= new FoldersPanel(foldersDock
);
2324 foldersPanel
->setCustomContextMenuActions({lockLayoutAction
});
2325 foldersDock
->setWidget(foldersPanel
);
2327 createPanelAction(QIcon::fromTheme(QStringLiteral("folder")), Qt::Key_F7
, foldersDock
, QStringLiteral("show_folders_panel"));
2329 addDockWidget(Qt::LeftDockWidgetArea
, foldersDock
);
2330 connect(this, &DolphinMainWindow::urlChanged
, foldersPanel
, &FoldersPanel::setUrl
);
2331 connect(foldersPanel
, &FoldersPanel::folderActivated
, this, &DolphinMainWindow::changeUrl
);
2332 connect(foldersPanel
, &FoldersPanel::folderInNewTab
, this, &DolphinMainWindow::openNewTab
);
2333 connect(foldersPanel
, &FoldersPanel::folderInNewActiveTab
, this, &DolphinMainWindow::openNewTabAndActivate
);
2334 connect(foldersPanel
, &FoldersPanel::errorMessage
, this, &DolphinMainWindow::showErrorMessage
);
2337 ->action(QStringLiteral("show_folders_panel"))
2338 ->setWhatsThis(xi18nc("@info:whatsthis",
2340 "<emphasis>folders</emphasis> panel at the left side of the window."
2341 "<nl/><nl/>It shows the folders of the <emphasis>file system"
2342 "</emphasis> in a <emphasis>tree view</emphasis>."));
2343 foldersDock
->setWhatsThis(xi18nc("@info:whatsthis",
2345 "shows the folders of the <emphasis>file system</emphasis> in a "
2346 "<emphasis>tree view</emphasis>.</para><para>Click a folder to go "
2347 "there. Click the arrow to the left of a folder to see its subfolders. "
2348 "This allows quick switching between any folders.</para>")
2353 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
2354 DolphinDockWidget
*terminalDock
= new DolphinDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
2355 terminalDock
->setLocked(lock
);
2356 terminalDock
->setObjectName(QStringLiteral("terminalDock"));
2357 terminalDock
->setContentsMargins(0, 0, 0, 0);
2358 m_terminalPanel
= new TerminalPanel(terminalDock
);
2359 m_terminalPanel
->setCustomContextMenuActions({lockLayoutAction
});
2360 terminalDock
->setWidget(m_terminalPanel
);
2362 connect(m_terminalPanel
, &TerminalPanel::hideTerminalPanel
, terminalDock
, &DolphinDockWidget::hide
);
2363 connect(m_terminalPanel
, &TerminalPanel::changeUrl
, this, &DolphinMainWindow::slotTerminalDirectoryChanged
);
2364 connect(terminalDock
, &DolphinDockWidget::visibilityChanged
, m_terminalPanel
, &TerminalPanel::dockVisibilityChanged
);
2365 connect(terminalDock
, &DolphinDockWidget::visibilityChanged
, this, &DolphinMainWindow::slotTerminalPanelVisibilityChanged
);
2367 createPanelAction(QIcon::fromTheme(QStringLiteral("dialog-scripts")), Qt::Key_F4
, terminalDock
, QStringLiteral("show_terminal_panel"));
2369 addDockWidget(Qt::BottomDockWidgetArea
, terminalDock
);
2370 connect(this, &DolphinMainWindow::urlChanged
, m_terminalPanel
, &TerminalPanel::setUrl
);
2372 if (GeneralSettings::version() < 200) {
2373 terminalDock
->hide();
2377 ->action(QStringLiteral("show_terminal_panel"))
2378 ->setWhatsThis(xi18nc("@info:whatsthis",
2379 "<para>This toggles the "
2380 "<emphasis>terminal</emphasis> panel at the bottom of the window."
2381 "<nl/>The location in the terminal will always match the folder "
2382 "view so you can navigate using either.</para><para>The terminal "
2383 "panel is not needed for basic computer usage but can be useful "
2384 "for advanced tasks. To learn more about terminals use the help features "
2385 "in a standalone terminal application like Konsole.</para>"));
2386 terminalDock
->setWhatsThis(xi18nc("@info:whatsthis",
2388 "the <emphasis>terminal</emphasis> panel. It behaves like a "
2389 "normal terminal but will match the location of the folder view "
2390 "so you can navigate using either.</para><para>The terminal panel "
2391 "is not needed for basic computer usage but can be useful for "
2392 "advanced tasks. To learn more about terminals use the help features in a "
2393 "standalone terminal application like Konsole.</para>")
2396 QAction
*focusTerminalPanel
= actionCollection()->addAction(QStringLiteral("focus_terminal_panel"));
2397 focusTerminalPanel
->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
2398 focusTerminalPanel
->setToolTip(i18nc("@info:tooltip", "Move keyboard focus to and from the Terminal panel."));
2399 focusTerminalPanel
->setIcon(QIcon::fromTheme(QStringLiteral("swap-panels")));
2400 actionCollection()->setDefaultShortcut(focusTerminalPanel
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_F4
);
2401 connect(focusTerminalPanel
, &QAction::triggered
, this, &DolphinMainWindow::toggleTerminalPanelFocus
);
2402 } // endif "shell_access" allowed
2403 #endif // HAVE_TERMINAL
2405 if (GeneralSettings::version() < 200) {
2407 foldersDock
->hide();
2411 DolphinDockWidget
*placesDock
= new DolphinDockWidget(i18nc("@title:window", "Places"));
2412 placesDock
->setLocked(lock
);
2413 placesDock
->setObjectName(QStringLiteral("placesDock"));
2414 placesDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
2416 m_placesPanel
= new PlacesPanel(placesDock
);
2417 m_placesPanel
->setCustomContextMenuActions({lockLayoutAction
});
2418 placesDock
->setWidget(m_placesPanel
);
2420 createPanelAction(QIcon::fromTheme(QStringLiteral("compass")), Qt::Key_F9
, placesDock
, QStringLiteral("show_places_panel"));
2422 addDockWidget(Qt::LeftDockWidgetArea
, placesDock
);
2423 connect(m_placesPanel
, &PlacesPanel::placeActivated
, this, &DolphinMainWindow::slotPlaceActivated
);
2424 connect(m_placesPanel
, &PlacesPanel::tabRequested
, this, &DolphinMainWindow::openNewTab
);
2425 connect(m_placesPanel
, &PlacesPanel::activeTabRequested
, this, &DolphinMainWindow::openNewTabAndActivate
);
2426 connect(m_placesPanel
, &PlacesPanel::newWindowRequested
, this, [this](const QUrl
&url
) {
2427 Dolphin::openNewWindow({url
}, this);
2429 connect(m_placesPanel
, &PlacesPanel::openInSplitViewRequested
, this, &DolphinMainWindow::openInSplitView
);
2430 connect(m_placesPanel
, &PlacesPanel::errorMessage
, this, &DolphinMainWindow::showErrorMessage
);
2431 connect(this, &DolphinMainWindow::urlChanged
, m_placesPanel
, &PlacesPanel::setUrl
);
2432 connect(placesDock
, &DolphinDockWidget::visibilityChanged
, &DolphinUrlNavigatorsController::slotPlacesPanelVisibilityChanged
);
2433 connect(placesDock
, &DolphinDockWidget::visibilityChanged
, this, &DolphinMainWindow::slotPlacesPanelVisibilityChanged
);
2434 connect(this, &DolphinMainWindow::settingsChanged
, m_placesPanel
, &PlacesPanel::readSettings
);
2435 connect(m_placesPanel
, &PlacesPanel::storageTearDownRequested
, this, &DolphinMainWindow::slotStorageTearDownFromPlacesRequested
);
2436 connect(m_placesPanel
, &PlacesPanel::storageTearDownExternallyRequested
, this, &DolphinMainWindow::slotStorageTearDownExternallyRequested
);
2437 DolphinUrlNavigatorsController::slotPlacesPanelVisibilityChanged(m_placesPanel
->isVisible());
2439 auto actionShowAllPlaces
= new QAction(QIcon::fromTheme(QStringLiteral("view-hidden")), i18nc("@item:inmenu", "Show Hidden Places"), this);
2440 actionShowAllPlaces
->setCheckable(true);
2441 actionShowAllPlaces
->setDisabled(true);
2442 actionShowAllPlaces
->setWhatsThis(i18nc("@info:whatsthis",
2444 "all places in the places panel that have been hidden. They will "
2445 "appear semi-transparent and allow you to uncheck their \"Hide\" property."));
2447 connect(actionShowAllPlaces
, &QAction::triggered
, this, [this](bool checked
) {
2448 m_placesPanel
->setShowAll(checked
);
2450 connect(m_placesPanel
, &PlacesPanel::allPlacesShownChanged
, actionShowAllPlaces
, &QAction::setChecked
);
2453 ->action(QStringLiteral("show_places_panel"))
2454 ->setWhatsThis(xi18nc("@info:whatsthis",
2455 "<para>This toggles the "
2456 "<emphasis>places</emphasis> panel at the left side of the window."
2457 "</para><para>It allows you to go to locations you have "
2458 "bookmarked and to access disk or media attached to the computer "
2459 "or to the network. It also contains sections to find recently "
2460 "saved files or files of a certain type.</para>"));
2461 placesDock
->setWhatsThis(xi18nc("@info:whatsthis",
2462 "<para>This is the "
2463 "<emphasis>Places</emphasis> panel. It allows you to go to locations "
2464 "you have bookmarked and to access disk or media attached to the "
2465 "computer or to the network. It also contains sections to find "
2466 "recently saved files or files of a certain type.</para><para>"
2467 "Click on an entry to go there. Click with the right mouse button "
2468 "instead to open any entry in a new tab or new window.</para>"
2469 "<para>New entries can be added by dragging folders onto this panel. "
2470 "Right-click any section or entry to hide it. Right-click an empty "
2471 "space on this panel and select <interface>Show Hidden Places"
2472 "</interface> to display it again.</para>")
2475 QAction
*focusPlacesPanel
= actionCollection()->addAction(QStringLiteral("focus_places_panel"));
2476 focusPlacesPanel
->setText(i18nc("@action:inmenu View", "Focus Places Panel"));
2477 focusPlacesPanel
->setToolTip(i18nc("@info:tooltip", "Move keyboard focus to and from the Places panel."));
2478 focusPlacesPanel
->setIcon(QIcon::fromTheme(QStringLiteral("swap-panels")));
2479 actionCollection()->setDefaultShortcut(focusPlacesPanel
, Qt::CTRL
| Qt::Key_P
);
2480 connect(focusPlacesPanel
, &QAction::triggered
, this, &DolphinMainWindow::togglePlacesPanelFocus
);
2482 // Add actions into the "Panels" menu
2483 KActionMenu
*panelsMenu
= new KActionMenu(i18nc("@action:inmenu View", "Show Panels"), this);
2484 actionCollection()->addAction(QStringLiteral("panels"), panelsMenu
);
2485 panelsMenu
->setIcon(QIcon::fromTheme(QStringLiteral("view-sidetree")));
2486 panelsMenu
->setPopupMode(QToolButton::InstantPopup
);
2487 const KActionCollection
*ac
= actionCollection();
2488 panelsMenu
->addAction(ac
->action(QStringLiteral("show_places_panel")));
2490 panelsMenu
->addAction(ac
->action(QStringLiteral("show_information_panel")));
2492 panelsMenu
->addAction(ac
->action(QStringLiteral("show_folders_panel")));
2493 panelsMenu
->addAction(ac
->action(QStringLiteral("show_terminal_panel")));
2494 panelsMenu
->addSeparator();
2495 panelsMenu
->addAction(lockLayoutAction
);
2496 panelsMenu
->addSeparator();
2497 panelsMenu
->addAction(actionShowAllPlaces
);
2498 panelsMenu
->addAction(focusPlacesPanel
);
2499 panelsMenu
->addAction(ac
->action(QStringLiteral("focus_terminal_panel")));
2501 connect(panelsMenu
->menu(), &QMenu::aboutToShow
, this, [actionShowAllPlaces
] {
2502 actionShowAllPlaces
->setEnabled(DolphinPlacesModelSingleton::instance().placesModel()->hiddenCount());
2506 void DolphinMainWindow::updateFileAndEditActions()
2508 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
2509 const KActionCollection
*col
= actionCollection();
2510 KFileItemListProperties
capabilitiesSource(list
);
2512 QAction
*renameAction
= col
->action(KStandardAction::name(KStandardAction::RenameFile
));
2513 QAction
*moveToTrashAction
= col
->action(KStandardAction::name(KStandardAction::MoveToTrash
));
2514 QAction
*deleteAction
= col
->action(KStandardAction::name(KStandardAction::DeleteFile
));
2515 QAction
*cutAction
= col
->action(KStandardAction::name(KStandardAction::Cut
));
2516 QAction
*duplicateAction
= col
->action(QStringLiteral("duplicate")); // see DolphinViewActionHandler
2517 QAction
*addToPlacesAction
= col
->action(QStringLiteral("add_to_places"));
2518 QAction
*copyToOtherViewAction
= col
->action(QStringLiteral("copy_to_inactive_split_view"));
2519 QAction
*moveToOtherViewAction
= col
->action(QStringLiteral("move_to_inactive_split_view"));
2520 QAction
*copyLocation
= col
->action(QStringLiteral("copy_location"));
2522 if (list
.isEmpty()) {
2523 stateChanged(QStringLiteral("has_no_selection"));
2525 // All actions that need a selection to function can be enabled because they should trigger selection mode.
2526 renameAction
->setEnabled(true);
2527 moveToTrashAction
->setEnabled(true);
2528 deleteAction
->setEnabled(true);
2529 cutAction
->setEnabled(true);
2530 duplicateAction
->setEnabled(true);
2531 addToPlacesAction
->setEnabled(true);
2532 copyLocation
->setEnabled(true);
2533 // Them triggering selection mode and not directly acting on selected items is signified by adding "…" to their text.
2534 m_actionTextHelper
->textsWhenNothingIsSelectedEnabled(true);
2537 m_actionTextHelper
->textsWhenNothingIsSelectedEnabled(false);
2538 stateChanged(QStringLiteral("has_selection"));
2540 QAction
*deleteWithTrashShortcut
= col
->action(QStringLiteral("delete_shortcut")); // see DolphinViewActionHandler
2541 QAction
*showTarget
= col
->action(QStringLiteral("show_target"));
2543 if (list
.length() == 1 && list
.first().isDir()) {
2544 addToPlacesAction
->setEnabled(true);
2546 addToPlacesAction
->setEnabled(false);
2549 const bool enableMoveToTrash
= capabilitiesSource
.isLocal() && capabilitiesSource
.supportsMoving();
2551 renameAction
->setEnabled(capabilitiesSource
.supportsMoving());
2552 m_disabledActionNotifier
->setDisabledReason(renameAction
, i18nc("@info", "Cannot rename: You do not have permission to rename items in this folder."));
2553 deleteAction
->setEnabled(capabilitiesSource
.supportsDeleting());
2554 m_disabledActionNotifier
->setDisabledReason(deleteAction
,
2555 i18nc("@info", "Cannot delete: You do not have permission to remove items from this folder."));
2556 cutAction
->setEnabled(capabilitiesSource
.supportsMoving());
2557 m_disabledActionNotifier
->setDisabledReason(cutAction
, i18nc("@info", "Cannot cut: You do not have permission to move items from this folder."));
2558 copyLocation
->setEnabled(list
.length() == 1);
2559 showTarget
->setEnabled(list
.length() == 1 && list
.at(0).isLink());
2560 duplicateAction
->setEnabled(capabilitiesSource
.supportsWriting());
2561 m_disabledActionNotifier
->setDisabledReason(duplicateAction
,
2562 i18nc("@info", "Cannot duplicate here: You do not have permission to create items in this folder."));
2564 if (enableMoveToTrash
) {
2565 moveToTrashAction
->setEnabled(true);
2566 deleteWithTrashShortcut
->setEnabled(false);
2567 m_disabledActionNotifier
->clearDisabledReason(deleteWithTrashShortcut
);
2569 moveToTrashAction
->setEnabled(false);
2570 deleteWithTrashShortcut
->setEnabled(capabilitiesSource
.supportsDeleting());
2571 m_disabledActionNotifier
->setDisabledReason(deleteWithTrashShortcut
,
2572 i18nc("@info", "Cannot delete: You do not have permission to remove items from this folder."));
2576 if (!m_tabWidget
->currentTabPage()->splitViewEnabled()) {
2577 // No need to set the disabled reason here, as it's obvious to the user that the reason is the split view being disabled.
2578 copyToOtherViewAction
->setEnabled(false);
2579 m_disabledActionNotifier
->clearDisabledReason(copyToOtherViewAction
);
2580 moveToOtherViewAction
->setEnabled(false);
2581 m_disabledActionNotifier
->clearDisabledReason(moveToOtherViewAction
);
2582 } else if (list
.isEmpty()) {
2583 copyToOtherViewAction
->setEnabled(false);
2584 m_disabledActionNotifier
->setDisabledReason(copyToOtherViewAction
, i18nc("@info", "Cannot copy to other view: No files selected."));
2585 moveToOtherViewAction
->setEnabled(false);
2586 m_disabledActionNotifier
->setDisabledReason(moveToOtherViewAction
, i18nc("@info", "Cannot move to other view: No files selected."));
2588 DolphinTabPage
*tabPage
= m_tabWidget
->currentTabPage();
2589 KFileItem capabilitiesDestination
;
2591 if (tabPage
->primaryViewActive()) {
2592 capabilitiesDestination
= tabPage
->secondaryViewContainer()->rootItem();
2594 capabilitiesDestination
= tabPage
->primaryViewContainer()->rootItem();
2597 const auto destUrl
= capabilitiesDestination
.url();
2598 const bool allNotTargetOrigin
= std::all_of(list
.cbegin(), list
.cend(), [destUrl
](const KFileItem
&item
) {
2599 return item
.url().adjusted(QUrl::RemoveFilename
| QUrl::StripTrailingSlash
) != destUrl
;
2602 if (!allNotTargetOrigin
) {
2603 copyToOtherViewAction
->setEnabled(false);
2604 m_disabledActionNotifier
->setDisabledReason(copyToOtherViewAction
,
2605 i18nc("@info", "Cannot copy to other view: The other view already contains these items."));
2606 moveToOtherViewAction
->setEnabled(false);
2607 m_disabledActionNotifier
->setDisabledReason(moveToOtherViewAction
,
2608 i18nc("@info", "Cannot move to other view: The other view already contains these items."));
2609 } else if (!capabilitiesDestination
.isWritable()) {
2610 copyToOtherViewAction
->setEnabled(false);
2611 m_disabledActionNotifier
->setDisabledReason(
2612 copyToOtherViewAction
,
2613 i18nc("@info", "Cannot copy to other view: You do not have permission to write into the destination folder."));
2614 moveToOtherViewAction
->setEnabled(false);
2615 m_disabledActionNotifier
->setDisabledReason(
2616 moveToOtherViewAction
,
2617 i18nc("@info", "Cannot move to other view: You do not have permission to write into the destination folder."));
2619 copyToOtherViewAction
->setEnabled(true);
2620 moveToOtherViewAction
->setEnabled(capabilitiesSource
.supportsMoving());
2621 m_disabledActionNotifier
->setDisabledReason(
2622 moveToOtherViewAction
,
2623 i18nc("@info", "Cannot move to other view: You do not have permission to move items from this folder."));
2628 void DolphinMainWindow::updateViewActions()
2630 m_actionHandler
->updateViewActions();
2632 QAction
*toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
2633 toggleFilterBarAction
->setChecked(m_activeViewContainer
->isFilterBarVisible());
2635 updateSplitActions();
2638 void DolphinMainWindow::updateGoActions()
2640 QAction
*goUpAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Up
));
2641 const QUrl currentUrl
= m_activeViewContainer
->url();
2642 // I think this is one of the best places to firstly be confronted
2643 // with a file system and its hierarchy. Talking about the root
2644 // directory might seem too much here but it is the question that
2645 // naturally arises in this context.
2646 goUpAction
->setWhatsThis(xi18nc("@info:whatsthis",
2648 "the folder that contains the currently viewed one.</para>"
2649 "<para>All files and folders are organized in a hierarchical "
2650 "<emphasis>file system</emphasis>. At the top of this hierarchy is "
2651 "a directory that contains all data connected to this computer"
2652 "—the <emphasis>root directory</emphasis>.</para>"));
2653 goUpAction
->setEnabled(KIO::upUrl(currentUrl
) != currentUrl
);
2656 void DolphinMainWindow::refreshViews()
2658 m_tabWidget
->refreshViews();
2660 if (GeneralSettings::modifiedStartupSettings()) {
2661 updateWindowTitle();
2664 updateSplitActions();
2666 Q_EMIT
settingsChanged();
2669 void DolphinMainWindow::clearStatusBar()
2671 m_activeViewContainer
->statusBar()->resetToDefaultText();
2674 void DolphinMainWindow::connectViewSignals(DolphinViewContainer
*container
)
2676 connect(container
, &DolphinViewContainer::showFilterBarChanged
, this, &DolphinMainWindow::updateFilterBarAction
);
2677 connect(container
, &DolphinViewContainer::writeStateChanged
, this, &DolphinMainWindow::slotWriteStateChanged
);
2678 slotWriteStateChanged(container
->view()->isFolderWritable());
2679 connect(container
, &DolphinViewContainer::searchBarVisibilityChanged
, this, &DolphinMainWindow::updateSearchAction
);
2680 connect(container
, &DolphinViewContainer::captionChanged
, this, &DolphinMainWindow::updateWindowTitle
);
2681 connect(container
, &DolphinViewContainer::tabRequested
, this, &DolphinMainWindow::openNewTab
);
2682 connect(container
, &DolphinViewContainer::activeTabRequested
, this, &DolphinMainWindow::openNewTabAndActivate
);
2684 // Make the toggled state of the selection mode actions visually follow the selection mode state of the view.
2685 auto toggleSelectionModeAction
= actionCollection()->action(QStringLiteral("toggle_selection_mode"));
2686 toggleSelectionModeAction
->setChecked(m_activeViewContainer
->isSelectionModeEnabled());
2687 connect(m_activeViewContainer
, &DolphinViewContainer::selectionModeChanged
, toggleSelectionModeAction
, &QAction::setChecked
);
2689 const DolphinView
*view
= container
->view();
2690 connect(view
, &DolphinView::selectionChanged
, this, &DolphinMainWindow::slotSelectionChanged
);
2691 connect(view
, &DolphinView::requestItemInfo
, this, &DolphinMainWindow::requestItemInfo
);
2692 connect(view
, &DolphinView::fileItemsChanged
, this, &DolphinMainWindow::fileItemsChanged
);
2693 connect(view
, &DolphinView::tabRequested
, this, &DolphinMainWindow::openNewTab
);
2694 connect(view
, &DolphinView::activeTabRequested
, this, &DolphinMainWindow::openNewTabAndActivate
);
2695 connect(view
, &DolphinView::windowRequested
, this, &DolphinMainWindow::openNewWindow
);
2696 connect(view
, &DolphinView::requestContextMenu
, this, &DolphinMainWindow::openContextMenu
);
2697 connect(view
, &DolphinView::directoryLoadingStarted
, this, &DolphinMainWindow::enableStopAction
);
2698 connect(view
, &DolphinView::directoryLoadingCompleted
, this, &DolphinMainWindow::disableStopAction
);
2699 connect(view
, &DolphinView::directoryLoadingCompleted
, this, &DolphinMainWindow::slotDirectoryLoadingCompleted
);
2700 connect(view
, &DolphinView::goBackRequested
, this, &DolphinMainWindow::goBack
);
2701 connect(view
, &DolphinView::goForwardRequested
, this, &DolphinMainWindow::goForward
);
2702 connect(view
, &DolphinView::urlActivated
, this, &DolphinMainWindow::handleUrl
);
2703 connect(view
, &DolphinView::goUpRequested
, this, &DolphinMainWindow::goUp
);
2704 connect(view
, &DolphinView::doubleClickViewBackground
, this, &DolphinMainWindow::slotDoubleClickViewBackground
);
2706 connect(container
->urlNavigatorInternalWithHistory(), &KUrlNavigator::urlChanged
, this, &DolphinMainWindow::changeUrl
);
2707 connect(container
->urlNavigatorInternalWithHistory(), &KUrlNavigator::historyChanged
, this, &DolphinMainWindow::updateHistory
);
2709 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>(actionCollection()->action(QStringLiteral("url_navigators")));
2710 const KUrlNavigator
*navigator
=
2711 m_tabWidget
->currentTabPage()->primaryViewActive() ? navigators
->primaryUrlNavigator() : navigators
->secondaryUrlNavigator();
2713 QAction
*editableLocactionAction
= actionCollection()->action(QStringLiteral("editable_location"));
2714 editableLocactionAction
->setChecked(navigator
->isUrlEditable());
2715 connect(navigator
, &KUrlNavigator::editableStateChanged
, this, &DolphinMainWindow::slotEditableStateChanged
);
2716 connect(navigator
, &KUrlNavigator::tabRequested
, this, &DolphinMainWindow::openNewTab
);
2717 connect(navigator
, &KUrlNavigator::activeTabRequested
, this, &DolphinMainWindow::openNewTabAndActivate
);
2718 connect(navigator
, &KUrlNavigator::newWindowRequested
, this, &DolphinMainWindow::openNewWindow
);
2721 void DolphinMainWindow::updateSplitActions()
2723 QAction
*popoutSplitAction
= actionCollection()->action(QStringLiteral("popout_split_view"));
2725 auto setActionPopupMode
= [this](KActionMenu
*action
, QToolButton::ToolButtonPopupMode popupMode
) {
2726 action
->setPopupMode(popupMode
);
2727 if (auto *buttonForAction
= qobject_cast
<QToolButton
*>(toolBar()->widgetForAction(action
))) {
2728 buttonForAction
->setPopupMode(popupMode
);
2732 const DolphinTabPage
*tabPage
= m_tabWidget
->currentTabPage();
2733 if (tabPage
->splitViewEnabled()) {
2734 if (GeneralSettings::closeActiveSplitView() ? tabPage
->primaryViewActive() : !tabPage
->primaryViewActive()) {
2735 m_splitViewAction
->setText(i18nc("@action:intoolbar Close left view", "Close"));
2736 m_splitViewAction
->setToolTip(i18nc("@info", "Close left view"));
2737 m_splitViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-left-close")));
2738 m_splitViewMenuAction
->setText(i18nc("@action:inmenu Close left view", "Close Left View"));
2740 popoutSplitAction
->setText(i18nc("@action:intoolbar Move left view to a new window", "Pop out Left View"));
2741 popoutSplitAction
->setToolTip(i18nc("@info", "Move left view to a new window"));
2743 m_splitViewAction
->setText(i18nc("@action:intoolbar Close right view", "Close"));
2744 m_splitViewAction
->setToolTip(i18nc("@info", "Close right view"));
2745 m_splitViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-right-close")));
2746 m_splitViewMenuAction
->setText(i18nc("@action:inmenu Close left view", "Close Right View"));
2748 popoutSplitAction
->setText(i18nc("@action:intoolbar Move right view to a new window", "Pop out Right View"));
2749 popoutSplitAction
->setToolTip(i18nc("@info", "Move right view to a new window"));
2751 popoutSplitAction
->setEnabled(true);
2752 if (!m_splitViewAction
->menu()) {
2753 setActionPopupMode(m_splitViewAction
, QToolButton::MenuButtonPopup
);
2754 m_splitViewAction
->setMenu(new QMenu
);
2755 m_splitViewAction
->addAction(popoutSplitAction
);
2758 m_splitViewAction
->setText(i18nc("@action:intoolbar Split view", "Split"));
2759 m_splitViewMenuAction
->setText(m_splitViewAction
->text());
2760 m_splitViewAction
->setToolTip(i18nc("@info", "Split view"));
2761 m_splitViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-split-left-right")));
2762 popoutSplitAction
->setText(i18nc("@action:intoolbar Move view in focus to a new window", "Pop out"));
2763 popoutSplitAction
->setEnabled(false);
2764 if (m_splitViewAction
->menu()) {
2765 m_splitViewAction
->removeAction(popoutSplitAction
);
2766 m_splitViewAction
->menu()->deleteLater();
2767 m_splitViewAction
->setMenu(nullptr);
2768 setActionPopupMode(m_splitViewAction
, QToolButton::DelayedPopup
);
2772 // Update state from toolbar action
2773 m_splitViewMenuAction
->setToolTip(m_splitViewAction
->toolTip());
2774 m_splitViewMenuAction
->setIcon(m_splitViewAction
->icon());
2777 void DolphinMainWindow::updateAllowedToolbarAreas()
2779 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>(actionCollection()->action(QStringLiteral("url_navigators")));
2780 if (toolBar()->actions().contains(navigators
)) {
2781 toolBar()->setAllowedAreas(Qt::TopToolBarArea
| Qt::BottomToolBarArea
);
2782 if (toolBarArea(toolBar()) == Qt::LeftToolBarArea
|| toolBarArea(toolBar()) == Qt::RightToolBarArea
) {
2783 addToolBar(Qt::TopToolBarArea
, toolBar());
2786 toolBar()->setAllowedAreas(Qt::AllToolBarAreas
);
2790 void DolphinMainWindow::updateNavigatorsBackground()
2792 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>(actionCollection()->action(QStringLiteral("url_navigators")));
2793 navigators
->setBackgroundEnabled(navigators
->isInToolbar());
2796 bool DolphinMainWindow::isKompareInstalled() const
2798 static bool initialized
= false;
2799 static bool installed
= false;
2801 // TODO: maybe replace this approach later by using a menu
2802 // plugin like kdiff3plugin.cpp
2803 installed
= !QStandardPaths::findExecutable(QStringLiteral("kompare")).isEmpty();
2809 void DolphinMainWindow::createPanelAction(const QIcon
&icon
, const QKeySequence
&shortcut
, QDockWidget
*dockWidget
, const QString
&actionName
)
2811 auto dockAction
= dockWidget
->toggleViewAction();
2812 dockAction
->setIcon(icon
);
2813 dockAction
->setEnabled(true);
2815 QAction
*panelAction
= actionCollection()->addAction(actionName
, dockAction
);
2816 actionCollection()->setDefaultShortcut(panelAction
, shortcut
);
2819 void DolphinMainWindow::setupWhatsThis()
2822 menuBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2823 "<emphasis>Menubar</emphasis>. It provides access to commands and "
2824 "configuration options. Left-click on any of the menus on this "
2825 "bar to see its contents.</para><para>The Menubar can be hidden "
2826 "by unchecking <interface>Settings|Show Menubar</interface>. Then "
2827 "most of its contents become available through a <interface>Menu"
2828 "</interface> button on the <emphasis>Toolbar</emphasis>.</para>"));
2829 toolBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2830 "<emphasis>Toolbar</emphasis>. It allows quick access to "
2831 "frequently used actions.</para><para>It is highly customizable. "
2832 "All items you see in the <interface>Menu</interface> or "
2833 "in the <interface>Menubar</interface> can be placed on the "
2834 "Toolbar. Just right-click on it and select <interface>Configure "
2835 "Toolbars…</interface> or find this action within the <interface>"
2837 "</para><para>The location of the bar and the style of its "
2838 "buttons can also be changed in the right-click menu. Right-click "
2839 "a button if you want to show or hide its text.</para>"));
2840 m_tabWidget
->setWhatsThis(xi18nc("@info:whatsthis main view",
2841 "<para>Here you can see the <emphasis>folders</emphasis> and "
2842 "<emphasis>files</emphasis> that are at the location described in "
2843 "the <interface>Location Bar</interface> above. This area is the "
2844 "central part of this application where you navigate to the files "
2845 "you want to use.</para><para>For an elaborate and general "
2846 "introduction to this application <link "
2847 "url='https://userbase.kde.org/Dolphin/File_Management#Introduction_to_Dolphin'>"
2848 "click here</link>. This will open an introductory article from "
2849 "the <emphasis>KDE UserBase Wiki</emphasis>.</para><para>For brief "
2850 "explanations of all the features of this <emphasis>view</emphasis> "
2851 "<link url='help:/dolphin/dolphin-view.html'>click here</link> "
2852 "instead. This will open a page from the <emphasis>Handbook"
2853 "</emphasis> that covers the basics.</para>"));
2856 actionCollection()->action(KStandardAction::name(KStandardAction::KeyBindings
))
2857 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window "
2858 "that lists the <emphasis>keyboard shortcuts</emphasis>.<nl/>"
2859 "There you can set up key combinations to trigger an action when "
2860 "they are pressed simultaneously. All commands in this application can "
2861 "be triggered this way.</para>"));
2862 actionCollection()->action(KStandardAction::name(KStandardAction::ConfigureToolbars
))
2863 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window in which "
2864 "you can change which buttons appear on the <emphasis>Toolbar</emphasis>.</para>"
2865 "<para>All items you see in the <interface>Menu</interface> can also be placed on the Toolbar.</para>"));
2866 actionCollection()->action(KStandardAction::name(KStandardAction::Preferences
))
2867 ->setWhatsThis(xi18nc("@info:whatsthis","This opens a window where you can "
2868 "change a multitude of settings for this application. For an explanation "
2869 "of the various settings go to the chapter <emphasis>Configuring Dolphin"
2870 "</emphasis> in <interface>Help|Dolphin Handbook</interface>."));
2874 auto setStandardActionWhatsThis
= [this](KStandardAction::StandardAction actionId
,
2875 const QString
&whatsThis
) {
2876 // Check for the existence of an action since it can be restricted through the Kiosk system
2877 if (auto *action
= actionCollection()->action(KStandardAction::name(actionId
))) {
2878 action
->setWhatsThis(whatsThis
);
2882 // i18n: If the external link isn't available in your language it might make
2883 // sense to state the external link's language in brackets to not
2884 // frustrate the user. If there are multiple languages that the user might
2885 // know with a reasonable chance you might want to have 2 external links.
2886 // The same might be true for any external link you translate.
2887 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>"));
2888 // (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 )
2890 setStandardActionWhatsThis(KStandardAction::WhatsThis
,
2891 xi18nc("@info:whatsthis whatsthis button",
2892 "<para>This is the button that invokes the help feature you are "
2893 "using right now! Click it, then click any component of this "
2894 "application to ask \"What's this?\" about it. The mouse cursor "
2895 "will change appearance if no help is available for a spot.</para>"
2896 "<para>There are two other ways to get help: "
2897 "The <link url='help:/dolphin/index.html'>Dolphin Handbook</link> and "
2898 "the <link url='https://userbase.kde.org/Dolphin/File_Management'>KDE "
2899 "UserBase Wiki</link>.</para><para>The \"What's this?\" help is "
2900 "missing in most other windows so don't get too used to this.</para>"));
2902 setStandardActionWhatsThis(KStandardAction::ReportBug
,
2903 xi18nc("@info:whatsthis","<para>This opens a "
2904 "window that will guide you through reporting errors or flaws "
2905 "in this application or in other KDE software.</para>"
2906 "<para>High-quality bug reports are much appreciated. To learn "
2907 "how to make your bug report as effective as possible "
2908 "<link url='https://community.kde.org/Get_Involved/Bug_Reporting'>"
2909 "click here</link>.</para>"));
2911 setStandardActionWhatsThis(KStandardAction::Donate
,
2912 xi18nc("@info:whatsthis", "<para>This opens a "
2913 "<emphasis>web page</emphasis> where you can donate to "
2914 "support the continued work on this application and many "
2915 "other projects by the <emphasis>KDE</emphasis> community.</para>"
2916 "<para>Donating is the easiest and fastest way to efficiently "
2917 "support KDE and its projects. KDE projects are available for "
2918 "free therefore your donation is needed to cover things that "
2919 "require money like servers, contributor meetings, etc.</para>"
2920 "<para><emphasis>KDE e.V.</emphasis> is the non-profit "
2921 "organization behind the KDE community.</para>"));
2923 setStandardActionWhatsThis(KStandardAction::SwitchApplicationLanguage
,
2924 xi18nc("@info:whatsthis",
2925 "With this you can change the language this application uses."
2926 "<nl/>You can even set secondary languages which will be used "
2927 "if texts are not available in your preferred language."));
2929 setStandardActionWhatsThis(KStandardAction::AboutApp
,
2930 xi18nc("@info:whatsthis","This opens a "
2931 "window that informs you about the version, license, "
2932 "used libraries and maintainers of this application."));
2934 setStandardActionWhatsThis(KStandardAction::AboutKDE
,
2935 xi18nc("@info:whatsthis","This opens a "
2936 "window with information about <emphasis>KDE</emphasis>. "
2937 "The KDE community are the people behind this free software."
2938 "<nl/>If you like using this application but don't know "
2939 "about KDE or want to see a cute dragon have a look!"));
2943 bool DolphinMainWindow::addHamburgerMenuToToolbar()
2945 QDomDocument domDocument
= KXMLGUIClient::domDocument();
2946 if (domDocument
.isNull()) {
2949 QDomNode toolbar
= domDocument
.elementsByTagName(QStringLiteral("ToolBar")).at(0);
2950 if (toolbar
.isNull()) {
2954 QDomElement hamburgerMenuElement
= domDocument
.createElement(QStringLiteral("Action"));
2955 hamburgerMenuElement
.setAttribute(QStringLiteral("name"), QStringLiteral("hamburger_menu"));
2956 toolbar
.appendChild(hamburgerMenuElement
);
2958 KXMLGUIFactory::saveConfigFile(domDocument
, xmlFile());
2962 // Make sure to also remove the <KXMLGUIFactory> and <QDomDocument> include
2963 // whenever this method is removed (maybe in the year ~2026).
2966 // Set a sane initial window size
2967 QSize
DolphinMainWindow::sizeHint() const
2969 return KXmlGuiWindow::sizeHint().expandedTo(QSize(760, 550));
2972 void DolphinMainWindow::saveNewToolbarConfig()
2974 KXmlGuiWindow::saveNewToolbarConfig(); // Applies the new config. This has to be called first
2975 // because the rest of this method decides things
2976 // based on the new config.
2977 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>(actionCollection()->action(QStringLiteral("url_navigators")));
2978 if (!toolBar()->actions().contains(navigators
)) {
2979 m_tabWidget
->currentTabPage()->insertNavigatorsWidget(navigators
);
2981 updateAllowedToolbarAreas();
2982 updateNavigatorsBackground();
2983 (static_cast<KHamburgerMenu
*>(actionCollection()->action(KStandardAction::name(KStandardAction::HamburgerMenu
))))->hideActionsOf(toolBar());
2986 void DolphinMainWindow::toggleTerminalPanelFocus()
2988 if (!m_terminalPanel
->isVisible()) {
2989 actionCollection()->action(QStringLiteral("show_terminal_panel"))->trigger(); // Also moves focus to the panel.
2990 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
2994 if (m_terminalPanel
->terminalHasFocus()) {
2995 m_activeViewContainer
->view()->setFocus(Qt::FocusReason::ShortcutFocusReason
);
2996 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
3000 m_terminalPanel
->setFocus(Qt::FocusReason::ShortcutFocusReason
);
3001 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
3004 void DolphinMainWindow::togglePlacesPanelFocus()
3006 if (!m_placesPanel
->isVisible()) {
3007 actionCollection()->action(QStringLiteral("show_places_panel"))->trigger(); // Also moves focus to the panel.
3008 actionCollection()->action(QStringLiteral("focus_places_panel"))->setText(i18nc("@action:inmenu View", "Defocus Terminal Panel"));
3012 if (m_placesPanel
->hasFocus()) {
3013 m_activeViewContainer
->view()->setFocus(Qt::FocusReason::ShortcutFocusReason
);
3014 actionCollection()->action(QStringLiteral("focus_places_panel"))->setText(i18nc("@action:inmenu View", "Focus Places Panel"));
3018 m_placesPanel
->setFocus(Qt::FocusReason::ShortcutFocusReason
);
3019 actionCollection()->action(QStringLiteral("focus_places_panel"))->setText(i18nc("@action:inmenu View", "Defocus Places Panel"));
3022 DolphinMainWindow::UndoUiInterface::UndoUiInterface()
3023 : KIO::FileUndoManager::UiInterface()
3027 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
3031 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
*job
)
3033 DolphinMainWindow
*mainWin
= qobject_cast
<DolphinMainWindow
*>(parentWidget());
3035 DolphinViewContainer
*container
= mainWin
->activeViewContainer();
3036 container
->showMessage(job
->errorString(), KMessageWidget::Error
);
3038 KIO::FileUndoManager::UiInterface::jobError(job
);
3042 bool DolphinMainWindow::isUrlOpen(const QString
&url
)
3044 return m_tabWidget
->isUrlOpen(QUrl::fromUserInput(url
));
3047 bool DolphinMainWindow::isItemVisibleInAnyView(const QString
&urlOfItem
)
3049 return m_tabWidget
->isItemVisibleInAnyView(QUrl::fromUserInput(urlOfItem
));
3052 void DolphinMainWindow::slotDoubleClickViewBackground(Qt::MouseButton button
)
3054 if (button
!= Qt::MouseButton::LeftButton
) {
3055 // only handle left mouse button for now
3059 GeneralSettings
*settings
= GeneralSettings::self();
3060 QString clickAction
= settings
->doubleClickViewAction();
3062 DolphinView
*view
= activeViewContainer()->view();
3063 if (view
== nullptr || clickAction
== "none") {
3067 if (clickAction
== customCommand
) {
3068 // run custom command set by the user
3069 QString path
= view
->url().toLocalFile();
3070 QString clickCustomAction
= settings
->doubleClickViewCustomAction();
3071 clickCustomAction
.replace("{path}", path
.prepend('"').append('"'));
3073 m_job
= new KIO::CommandLauncherJob(clickCustomAction
);
3074 m_job
->setUiDelegate(new KDialogJobUiDelegate(KJobUiDelegate::AutoHandlingEnabled
, this));
3078 // get the action set by the user and trigger it
3079 const KActionCollection
*actions
= actionCollection();
3080 QAction
*action
= actions
->action(clickAction
);
3081 if (action
== nullptr) {
3082 qCWarning(DolphinDebug
) << QStringLiteral("Double-click view: action `%1` was not found").arg(clickAction
);
3089 #include "moc_dolphinmainwindow.cpp"