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/dolphinstatusbar.h"
33 #include "views/dolphinnewfilemenuobserver.h"
34 #include "views/dolphinremoteencoding.h"
35 #include "views/dolphinviewactionhandler.h"
36 #include "views/draganddrophelper.h"
37 #include "views/viewproperties.h"
39 #include <KActionCollection>
40 #include <KActionMenu>
41 #include <KAuthorized>
42 #include <KColorSchemeManager>
45 #include <KDesktopFile>
46 #include <KDialogJobUiDelegate>
47 #include <KDualAction>
48 #include <KFileItemListProperties>
49 #include <KIO/CommandLauncherJob>
50 #include <KIO/JobUiDelegateFactory>
51 #include <KIO/OpenFileManagerWindowJob>
52 #include <KIO/OpenUrlJob>
53 #include <KJobWidgets>
54 #include <KLocalizedString>
55 #include <KMessageBox>
56 #include <KProtocolInfo>
57 #include <KProtocolManager>
58 #include <KRecentFilesAction>
59 #include <KRuntimePlatform>
61 #include <KShortcutsDialog>
62 #include <KStandardAction>
64 #include <KTerminalLauncherJob>
65 #include <KToggleAction>
67 #include <KToolBarPopupAction>
68 #include <KUrlComboBox>
69 #include <KUrlNavigator>
70 #include <KWindowSystem>
71 #include <KXMLGUIFactory>
73 #include <kwidgetsaddons_version.h>
75 #include <QApplication>
77 #include <QCloseEvent>
78 #include <QDesktopServices>
80 #include <QDomDocument>
84 #include <QPushButton>
86 #include <QStandardPaths>
88 #include <QToolButton>
89 #include <QtConcurrentRun>
90 #include <dolphindebug.h>
95 #include <KStartupInfo>
100 // Used for GeneralSettings::version() to determine whether
101 // an updated version of Dolphin is running, so as to migrate
102 // removed/renamed ...etc config entries; increment it in such
104 const int CurrentDolphinVersion
= 202;
105 // The maximum number of entries in the back/forward popup menu
106 const int MaxNumberOfNavigationentries
= 12;
107 // The maximum number of "Go to Tab" shortcuts
108 const int MaxActivateTabShortcuts
= 9;
111 DolphinMainWindow::DolphinMainWindow()
112 : KXmlGuiWindow(nullptr)
113 , m_newFileMenu(nullptr)
114 , m_tabWidget(nullptr)
115 , m_activeViewContainer(nullptr)
116 , m_actionHandler(nullptr)
117 , m_remoteEncoding(nullptr)
119 , m_bookmarkHandler(nullptr)
120 , m_disabledActionNotifier(nullptr)
121 , m_lastHandleUrlOpenJob(nullptr)
122 , m_terminalPanel(nullptr)
123 , m_placesPanel(nullptr)
124 , m_tearDownFromPlacesRequested(false)
125 , m_backAction(nullptr)
126 , m_forwardAction(nullptr)
127 , m_splitViewAction(nullptr)
128 , m_splitViewMenuAction(nullptr)
129 , m_sessionSaveTimer(nullptr)
130 , m_sessionSaveWatcher(nullptr)
131 , m_sessionSaveScheduled(false)
133 Q_INIT_RESOURCE(dolphin
);
135 new MainWindowAdaptor(this);
138 setWindowFlags(Qt::WindowContextHelpButtonHint
);
140 setComponentName(QStringLiteral("dolphin"), QGuiApplication::applicationDisplayName());
141 setObjectName(QStringLiteral("Dolphin#"));
143 setStateConfigGroup("State");
145 #if defined(Q_OS_WIN) || defined(Q_OS_MACOS)
146 new KColorSchemeManager(this); // Sets a sensible color scheme which fixes unreadable icons and text on Windows.
149 connect(&DolphinNewFileMenuObserver::instance(), &DolphinNewFileMenuObserver::errorMessage
, this, &DolphinMainWindow::showErrorMessage
);
151 KIO::FileUndoManager
*undoManager
= KIO::FileUndoManager::self();
152 undoManager
->setUiInterface(new UndoUiInterface());
154 connect(undoManager
, &KIO::FileUndoManager::undoAvailable
, this, &DolphinMainWindow::slotUndoAvailable
);
155 connect(undoManager
, &KIO::FileUndoManager::undoTextChanged
, this, &DolphinMainWindow::slotUndoTextChanged
);
156 connect(undoManager
, &KIO::FileUndoManager::jobRecordingStarted
, this, &DolphinMainWindow::clearStatusBar
);
157 connect(undoManager
, &KIO::FileUndoManager::jobRecordingFinished
, this, &DolphinMainWindow::showCommand
);
159 const bool firstRun
= (GeneralSettings::version() < 200);
161 GeneralSettings::setViewPropsTimestamp(QDateTime::currentDateTime());
164 setAcceptDrops(true);
166 auto *navigatorsWidgetAction
= new DolphinNavigatorsWidgetAction(this);
167 actionCollection()->addAction(QStringLiteral("url_navigators"), navigatorsWidgetAction
);
168 m_tabWidget
= new DolphinTabWidget(navigatorsWidgetAction
, this);
169 m_tabWidget
->setObjectName("tabWidget");
170 connect(m_tabWidget
, &DolphinTabWidget::activeViewChanged
, this, &DolphinMainWindow::activeViewChanged
);
171 connect(m_tabWidget
, &DolphinTabWidget::tabCountChanged
, this, &DolphinMainWindow::tabCountChanged
);
172 connect(m_tabWidget
, &DolphinTabWidget::currentUrlChanged
, this, &DolphinMainWindow::updateWindowTitle
);
173 setCentralWidget(m_tabWidget
);
175 m_actionTextHelper
= new SelectionMode::ActionTextHelper(this);
178 m_actionHandler
= new DolphinViewActionHandler(actionCollection(), m_actionTextHelper
, this);
179 connect(m_actionHandler
, &DolphinViewActionHandler::actionBeingHandled
, this, &DolphinMainWindow::clearStatusBar
);
180 connect(m_actionHandler
, &DolphinViewActionHandler::createDirectoryTriggered
, this, &DolphinMainWindow::createDirectory
);
181 connect(m_actionHandler
, &DolphinViewActionHandler::createFileTriggered
, this, &DolphinMainWindow::createFile
);
182 connect(m_actionHandler
, &DolphinViewActionHandler::selectionModeChangeTriggered
, this, &DolphinMainWindow::slotSetSelectionMode
);
184 QAction
*newDirAction
= actionCollection()->action(QStringLiteral("create_dir"));
185 Q_CHECK_PTR(newDirAction
);
186 m_newFileMenu
->setNewFolderShortcutAction(newDirAction
);
188 QAction
*newFileAction
= actionCollection()->action(QStringLiteral("create_file"));
189 Q_CHECK_PTR(newFileAction
);
190 m_newFileMenu
->setNewFileShortcutAction(newFileAction
);
192 m_remoteEncoding
= new DolphinRemoteEncoding(this, m_actionHandler
);
193 connect(this, &DolphinMainWindow::urlChanged
, m_remoteEncoding
, &DolphinRemoteEncoding::slotAboutToOpenUrl
);
195 m_disabledActionNotifier
= new DisabledActionNotifier(this);
196 connect(m_disabledActionNotifier
, &DisabledActionNotifier::disabledActionTriggered
, this, [this](const QAction
*, QString reason
) {
197 m_activeViewContainer
->showMessage(reason
, KMessageWidget::Warning
);
202 const bool usePhoneUi
{KRuntimePlatform::runtimePlatform().contains(QLatin1String("phone"))};
203 setupGUI(Save
| Create
| ToolBar
, usePhoneUi
? QStringLiteral("dolphinuiforphones.rc") : QString() /* load the default dolphinui.rc file */);
204 stateChanged(QStringLiteral("new_file"));
206 QClipboard
*clipboard
= QApplication::clipboard();
207 connect(clipboard
, &QClipboard::dataChanged
, this, &DolphinMainWindow::updatePasteAction
);
209 QAction
*toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
210 toggleFilterBarAction
->setChecked(GeneralSettings::filterBar());
213 menuBar()->setVisible(false);
216 Q_ASSERT(qobject_cast
<QDockWidget
*>(m_placesPanel
->parent()));
217 m_placesPanel
->parentWidget()->hide();
218 auto settings
= GeneralSettings::self();
219 settings
->setShowZoomSlider(false); // Zooming can be done with pinch gestures instead and we are short on horizontal space.
220 settings
->setRenameInline(false); // This works around inline renaming currently not working well with virtual keyboards.
221 settings
->save(); // Otherwise the RenameInline setting is not picked up for the first time Dolphin is used.
225 const bool showMenu
= !menuBar()->isHidden();
226 QAction
*showMenuBarAction
= actionCollection()->action(KStandardAction::name(KStandardAction::ShowMenubar
));
227 showMenuBarAction
->setChecked(showMenu
); // workaround for bug #171080
229 auto hamburgerMenu
= static_cast<KHamburgerMenu
*>(actionCollection()->action(KStandardAction::name(KStandardAction::HamburgerMenu
)));
230 hamburgerMenu
->setMenuBar(menuBar());
231 hamburgerMenu
->setShowMenuBarAction(showMenuBarAction
);
232 connect(hamburgerMenu
, &KHamburgerMenu::aboutToShowMenu
, this, &DolphinMainWindow::updateHamburgerMenu
);
233 hamburgerMenu
->hideActionsOf(toolBar());
234 if (GeneralSettings::version() < 201 && !toolBar()->actions().contains(hamburgerMenu
)) {
235 addHamburgerMenuToToolbar();
238 updateAllowedToolbarAreas();
239 updateNavigatorsBackground();
241 // enable middle-click on back/forward/up to open in a new tab
242 auto *middleClickEventFilter
= new MiddleClickActionEventFilter(this);
243 connect(middleClickEventFilter
, &MiddleClickActionEventFilter::actionMiddleClicked
, this, &DolphinMainWindow::slotToolBarActionMiddleClicked
);
244 toolBar()->installEventFilter(middleClickEventFilter
);
248 connect(KSycoca::self(), &KSycoca::databaseChanged
, this, &DolphinMainWindow::updateOpenPreferredSearchToolAction
);
250 QTimer::singleShot(0, this, &DolphinMainWindow::updateOpenPreferredSearchToolAction
);
252 m_fileItemActions
.setParentWidget(this);
253 connect(&m_fileItemActions
, &KFileItemActions::error
, this, [this](const QString
&errorMessage
) {
254 showErrorMessage(errorMessage
);
257 connect(GeneralSettings::self(), &GeneralSettings::splitViewChanged
, this, &DolphinMainWindow::slotSplitViewChanged
);
260 DolphinMainWindow::~DolphinMainWindow()
262 // This fixes a crash on Wayland when closing the mainwindow while another dialog is open.
263 disconnect(QGuiApplication::clipboard(), &QClipboard::dataChanged
, this, &DolphinMainWindow::updatePasteAction
);
265 // This fixes a crash in dolphinmainwindowtest where the connection below fires even though the KMainWindow destructor of this object is already running.
266 Q_CHECK_PTR(qobject_cast
<DolphinDockWidget
*>(m_placesPanel
->parent()));
267 disconnect(static_cast<DolphinDockWidget
*>(m_placesPanel
->parent()),
268 &DolphinDockWidget::visibilityChanged
,
270 &DolphinMainWindow::slotPlacesPanelVisibilityChanged
);
273 QVector
<DolphinViewContainer
*> DolphinMainWindow::viewContainers() const
275 QVector
<DolphinViewContainer
*> viewContainers
;
277 for (int i
= 0; i
< m_tabWidget
->count(); ++i
) {
278 DolphinTabPage
*tabPage
= m_tabWidget
->tabPageAt(i
);
280 viewContainers
<< tabPage
->primaryViewContainer();
281 if (tabPage
->splitViewEnabled()) {
282 viewContainers
<< tabPage
->secondaryViewContainer();
285 return viewContainers
;
288 void DolphinMainWindow::openDirectories(const QList
<QUrl
> &dirs
, bool splitView
)
290 m_tabWidget
->openDirectories(dirs
, splitView
);
293 void DolphinMainWindow::openDirectories(const QStringList
&dirs
, bool splitView
)
295 openDirectories(QUrl::fromStringList(dirs
), splitView
);
298 void DolphinMainWindow::openFiles(const QList
<QUrl
> &files
, bool splitView
)
300 m_tabWidget
->openFiles(files
, splitView
);
303 bool DolphinMainWindow::isFoldersPanelEnabled() const
305 return actionCollection()->action(QStringLiteral("show_folders_panel"))->isChecked();
308 bool DolphinMainWindow::isInformationPanelEnabled() const
311 return actionCollection()->action(QStringLiteral("show_information_panel"))->isChecked();
317 bool DolphinMainWindow::isSplitViewEnabledInCurrentTab() const
319 return m_tabWidget
->currentTabPage()->splitViewEnabled();
322 void DolphinMainWindow::openFiles(const QStringList
&files
, bool splitView
)
324 openFiles(QUrl::fromStringList(files
), splitView
);
327 void DolphinMainWindow::activateWindow(const QString
&activationToken
)
329 window()->setAttribute(Qt::WA_NativeWindow
, true);
331 if (KWindowSystem::isPlatformWayland()) {
332 KWindowSystem::setCurrentXdgActivationToken(activationToken
);
333 } else if (KWindowSystem::isPlatformX11()) {
335 KStartupInfo::setNewStartupId(window()->windowHandle(), activationToken
.toUtf8());
339 KWindowSystem::activateWindow(window()->windowHandle());
342 bool DolphinMainWindow::isActiveWindow()
344 return window()->isActiveWindow();
347 void DolphinMainWindow::showCommand(CommandType command
)
349 DolphinStatusBar
*statusBar
= m_activeViewContainer
->statusBar();
351 case KIO::FileUndoManager::Copy
:
352 statusBar
->setText(i18nc("@info:status", "Successfully copied."));
354 case KIO::FileUndoManager::Move
:
355 statusBar
->setText(i18nc("@info:status", "Successfully moved."));
357 case KIO::FileUndoManager::Link
:
358 statusBar
->setText(i18nc("@info:status", "Successfully linked."));
360 case KIO::FileUndoManager::Trash
:
361 statusBar
->setText(i18nc("@info:status", "Successfully moved to trash."));
363 case KIO::FileUndoManager::Rename
:
364 statusBar
->setText(i18nc("@info:status", "Successfully renamed."));
367 case KIO::FileUndoManager::Mkdir
:
368 statusBar
->setText(i18nc("@info:status", "Created folder."));
376 void DolphinMainWindow::pasteIntoFolder()
378 m_activeViewContainer
->view()->pasteIntoFolder();
381 void DolphinMainWindow::changeUrl(const QUrl
&url
)
383 if (!KProtocolManager::supportsListing(url
)) {
384 // The URL navigator only checks for validity, not
385 // if the URL can be listed. An error message is
386 // shown due to DolphinViewContainer::restoreView().
390 m_activeViewContainer
->setUrl(url
);
391 updateFileAndEditActions();
396 // will signal used urls to activities manager, too
397 m_recentFiles
->addUrl(url
, QString(), "inode/directory");
399 Q_EMIT
urlChanged(url
);
402 void DolphinMainWindow::slotTerminalDirectoryChanged(const QUrl
&url
)
404 if (m_tearDownFromPlacesRequested
&& url
== QUrl::fromLocalFile(QDir::homePath())) {
405 m_placesPanel
->proceedWithTearDown();
406 m_tearDownFromPlacesRequested
= false;
409 m_activeViewContainer
->setGrabFocusOnUrlChange(false);
411 m_activeViewContainer
->setGrabFocusOnUrlChange(true);
414 void DolphinMainWindow::slotEditableStateChanged(bool editable
)
416 KToggleAction
*editableLocationAction
= static_cast<KToggleAction
*>(actionCollection()->action(QStringLiteral("editable_location")));
417 editableLocationAction
->setChecked(editable
);
420 void DolphinMainWindow::slotSelectionChanged(const KFileItemList
&selection
)
422 updateFileAndEditActions();
424 const int selectedUrlsCount
= m_tabWidget
->currentTabPage()->selectedItemsCount();
426 QAction
*compareFilesAction
= actionCollection()->action(QStringLiteral("compare_files"));
427 if (selectedUrlsCount
== 2) {
428 compareFilesAction
->setEnabled(isKompareInstalled());
430 compareFilesAction
->setEnabled(false);
433 Q_EMIT
selectionChanged(selection
);
436 void DolphinMainWindow::updateHistory()
438 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
439 const int index
= urlNavigator
->historyIndex();
441 QAction
*backAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Back
));
443 backAction
->setToolTip(i18nc("@info", "Go back"));
444 backAction
->setWhatsThis(i18nc("@info:whatsthis go back", "Return to the previously viewed folder."));
445 backAction
->setEnabled(index
< urlNavigator
->historySize() - 1);
448 QAction
*forwardAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Forward
));
450 forwardAction
->setToolTip(i18nc("@info", "Go forward"));
451 forwardAction
->setWhatsThis(xi18nc("@info:whatsthis go forward", "This undoes a <interface>Go|Back</interface> action."));
452 forwardAction
->setEnabled(index
> 0);
456 void DolphinMainWindow::updateFilterBarAction(bool show
)
458 QAction
*toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
459 toggleFilterBarAction
->setChecked(show
);
462 void DolphinMainWindow::openNewMainWindow()
464 Dolphin::openNewWindow({m_activeViewContainer
->url()}, this);
467 void DolphinMainWindow::openNewActivatedTab()
469 // keep browsers compatibility, new tab is always after last one
470 auto openNewTabAfterLastTabConfigured
= GeneralSettings::openNewTabAfterLastTab();
471 GeneralSettings::setOpenNewTabAfterLastTab(true);
472 m_tabWidget
->openNewActivatedTab();
473 GeneralSettings::setOpenNewTabAfterLastTab(openNewTabAfterLastTabConfigured
);
476 void DolphinMainWindow::addToPlaces()
481 // If nothing is selected, act on the current dir
482 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
483 url
= m_activeViewContainer
->url();
484 name
= m_activeViewContainer
->placesText();
486 const auto dirToAdd
= m_activeViewContainer
->view()->selectedItems().first();
487 url
= dirToAdd
.url();
488 name
= dirToAdd
.name();
492 if (isSearchUrl(url
)) {
493 icon
= QStringLiteral("folder-saved-search-symbolic");
495 icon
= KIO::iconNameForUrl(url
);
497 DolphinPlacesModelSingleton::instance().placesModel()->addPlace(name
, url
, icon
);
501 DolphinTabPage
*DolphinMainWindow::openNewTab(const QUrl
&url
)
503 return m_tabWidget
->openNewTab(url
, QUrl());
506 void DolphinMainWindow::openNewTabAndActivate(const QUrl
&url
)
508 m_tabWidget
->openNewActivatedTab(url
, QUrl());
511 void DolphinMainWindow::openNewWindow(const QUrl
&url
)
513 Dolphin::openNewWindow({url
}, this);
516 void DolphinMainWindow::slotSplitViewChanged()
518 m_tabWidget
->currentTabPage()->setSplitViewEnabled(GeneralSettings::splitView(), WithAnimation
);
519 updateSplitActions();
522 void DolphinMainWindow::openInNewTab()
524 const KFileItemList
&list
= m_activeViewContainer
->view()->selectedItems();
525 bool tabCreated
= false;
527 for (const KFileItem
&item
: list
) {
528 const QUrl
&url
= DolphinView::openItemAsFolderUrl(item
);
529 if (!url
.isEmpty()) {
535 // if no new tab has been created from the selection
536 // open the current directory in a new tab
538 openNewTab(m_activeViewContainer
->url());
542 void DolphinMainWindow::openInNewWindow()
546 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
547 if (list
.isEmpty()) {
548 newWindowUrl
= m_activeViewContainer
->url();
549 } else if (list
.count() == 1) {
550 const KFileItem
&item
= list
.first();
551 newWindowUrl
= DolphinView::openItemAsFolderUrl(item
);
554 if (!newWindowUrl
.isEmpty()) {
555 Dolphin::openNewWindow({newWindowUrl
}, this);
559 void DolphinMainWindow::openInSplitView(const QUrl
&url
)
561 QUrl newSplitViewUrl
= url
;
563 if (newSplitViewUrl
.isEmpty()) {
564 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
565 if (list
.count() == 1) {
566 const KFileItem
&item
= list
.first();
567 newSplitViewUrl
= DolphinView::openItemAsFolderUrl(item
);
571 if (newSplitViewUrl
.isEmpty()) {
575 DolphinTabPage
*tabPage
= m_tabWidget
->currentTabPage();
576 if (tabPage
->splitViewEnabled()) {
577 tabPage
->switchActiveView();
578 tabPage
->activeViewContainer()->setUrl(newSplitViewUrl
);
580 tabPage
->setSplitViewEnabled(true, WithAnimation
, newSplitViewUrl
);
585 void DolphinMainWindow::showTarget()
587 const KFileItem link
= m_activeViewContainer
->view()->selectedItems().at(0);
588 const QUrl destinationUrl
= link
.url().resolved(QUrl(link
.linkDest()));
590 auto job
= KIO::stat(destinationUrl
, KIO::StatJob::SourceSide
, KIO::StatNoDetails
);
592 connect(job
, &KJob::finished
, this, [this, destinationUrl
](KJob
*job
) {
593 KIO::StatJob
*statJob
= static_cast<KIO::StatJob
*>(job
);
595 if (statJob
->error()) {
596 m_activeViewContainer
->showMessage(job
->errorString(), KMessageWidget::Error
);
598 KIO::highlightInFileManager({destinationUrl
});
603 bool DolphinMainWindow::event(QEvent
*event
)
605 if (event
->type() == QEvent::ShortcutOverride
) {
606 const QKeyEvent
*keyEvent
= static_cast<QKeyEvent
*>(event
);
607 if (keyEvent
->key() == Qt::Key_Space
&& m_activeViewContainer
->view()->handleSpaceAsNormalKey()) {
613 return KXmlGuiWindow::event(event
);
616 void DolphinMainWindow::showEvent(QShowEvent
*event
)
618 KXmlGuiWindow::showEvent(event
);
620 if (!event
->spontaneous() && m_activeViewContainer
) {
621 m_activeViewContainer
->view()->setFocus();
625 void DolphinMainWindow::closeEvent(QCloseEvent
*event
)
627 // Find out if Dolphin is closed directly by the user or
628 // by the session manager because the session is closed
629 bool closedByUser
= true;
630 if (qApp
->isSavingSession()) {
631 closedByUser
= false;
634 if (m_tabWidget
->count() > 1 && GeneralSettings::confirmClosingMultipleTabs() && !GeneralSettings::rememberOpenedTabs() && closedByUser
) {
635 // Ask the user if he really wants to quit and close all tabs.
636 // Open a confirmation dialog with 3 buttons:
637 // QDialogButtonBox::Yes -> Quit
638 // QDialogButtonBox::No -> Close only the current tab
639 // QDialogButtonBox::Cancel -> do nothing
640 QDialog
*dialog
= new QDialog(this, Qt::Dialog
);
641 dialog
->setWindowTitle(i18nc("@title:window", "Confirmation"));
642 dialog
->setModal(true);
643 QDialogButtonBox
*buttons
= new QDialogButtonBox(QDialogButtonBox::Yes
| QDialogButtonBox::No
| QDialogButtonBox::Cancel
);
644 KGuiItem::assign(buttons
->button(QDialogButtonBox::Yes
),
645 KGuiItem(i18nc("@action:button 'Quit Dolphin' button", "&Quit %1", QGuiApplication::applicationDisplayName()),
646 QIcon::fromTheme(QStringLiteral("application-exit"))));
647 KGuiItem::assign(buttons
->button(QDialogButtonBox::No
), KGuiItem(i18n("C&lose Current Tab"), QIcon::fromTheme(QStringLiteral("tab-close"))));
648 KGuiItem::assign(buttons
->button(QDialogButtonBox::Cancel
), KStandardGuiItem::cancel());
649 buttons
->button(QDialogButtonBox::Yes
)->setDefault(true);
651 bool doNotAskAgainCheckboxResult
= false;
653 const auto result
= KMessageBox::createKMessageBox(dialog
,
655 QMessageBox::Warning
,
656 i18n("You have multiple tabs open in this window, are you sure you want to quit?"),
658 i18n("Do not ask again"),
659 &doNotAskAgainCheckboxResult
,
660 KMessageBox::Notify
);
662 if (doNotAskAgainCheckboxResult
) {
663 GeneralSettings::setConfirmClosingMultipleTabs(false);
667 case QDialogButtonBox::Yes
:
670 case QDialogButtonBox::No
:
671 // Close only the current tab
672 m_tabWidget
->closeTab();
680 if (m_terminalPanel
&& m_terminalPanel
->hasProgramRunning() && GeneralSettings::confirmClosingTerminalRunningProgram() && closedByUser
) {
681 // Ask if the user really wants to quit Dolphin with a program that is still running in the Terminal panel
682 // Open a confirmation dialog with 3 buttons:
683 // QDialogButtonBox::Yes -> Quit
684 // QDialogButtonBox::No -> Show Terminal Panel
685 // QDialogButtonBox::Cancel -> do nothing
686 QDialog
*dialog
= new QDialog(this, Qt::Dialog
);
687 dialog
->setWindowTitle(i18nc("@title:window", "Confirmation"));
688 dialog
->setModal(true);
689 auto standardButtons
= QDialogButtonBox::Yes
| QDialogButtonBox::Cancel
;
690 if (!m_terminalPanel
->isVisible()) {
691 standardButtons
|= QDialogButtonBox::No
;
693 QDialogButtonBox
*buttons
= new QDialogButtonBox(standardButtons
);
694 KGuiItem::assign(buttons
->button(QDialogButtonBox::Yes
), KStandardGuiItem::quit());
695 if (!m_terminalPanel
->isVisible()) {
696 KGuiItem::assign(buttons
->button(QDialogButtonBox::No
), KGuiItem(i18n("Show &Terminal Panel"), QIcon::fromTheme(QStringLiteral("dialog-scripts"))));
698 KGuiItem::assign(buttons
->button(QDialogButtonBox::Cancel
), KStandardGuiItem::cancel());
700 bool doNotAskAgainCheckboxResult
= false;
702 const auto result
= KMessageBox::createKMessageBox(
705 QMessageBox::Warning
,
706 i18n("The program '%1' is still running in the Terminal panel. Are you sure you want to quit?", m_terminalPanel
->runningProgramName()),
708 i18n("Do not ask again"),
709 &doNotAskAgainCheckboxResult
,
710 KMessageBox::Notify
| KMessageBox::Dangerous
);
712 if (doNotAskAgainCheckboxResult
) {
713 GeneralSettings::setConfirmClosingTerminalRunningProgram(false);
717 case QDialogButtonBox::Yes
:
720 case QDialogButtonBox::No
:
721 actionCollection()->action("show_terminal_panel")->trigger();
722 // Do not quit, ignore quit event
730 if (m_sessionSaveTimer
&& (m_sessionSaveTimer
->isActive() || m_sessionSaveWatcher
->isRunning())) {
731 const bool sessionSaveTimerActive
= m_sessionSaveTimer
->isActive();
733 m_sessionSaveTimer
->stop();
734 m_sessionSaveWatcher
->disconnect();
735 m_sessionSaveWatcher
->waitForFinished();
737 if (sessionSaveTimerActive
|| m_sessionSaveScheduled
) {
742 GeneralSettings::setVersion(CurrentDolphinVersion
);
743 GeneralSettings::self()->save();
745 KXmlGuiWindow::closeEvent(event
);
748 void DolphinMainWindow::slotSaveSession()
750 m_sessionSaveScheduled
= false;
752 if (m_sessionSaveWatcher
->isRunning()) {
753 // The previous session is still being saved - schedule another save.
754 m_sessionSaveWatcher
->disconnect();
755 connect(m_sessionSaveWatcher
, &QFutureWatcher
<void>::finished
, this, &DolphinMainWindow::slotSaveSession
, Qt::SingleShotConnection
);
756 m_sessionSaveScheduled
= true;
757 } else if (!m_sessionSaveTimer
->isActive()) {
758 // No point in saving the session if the timer is running (since it will save the session again when it times out).
759 KConfigGui::setSessionConfig(QStringLiteral("dolphin"), QStringLiteral("dolphin"));
760 KConfig
*config
= KConfigGui::sessionConfig();
761 saveGlobalProperties(config
);
762 savePropertiesInternal(config
, 1);
763 KConfigGroup group
= config
->group(QStringLiteral("Number"));
764 group
.writeEntry("NumberOfWindows", 1); // Makes session restore aware that there is a window to restore.
766 auto future
= QtConcurrent::run([config
]() {
769 m_sessionSaveWatcher
->setFuture(future
);
773 void DolphinMainWindow::setSessionAutoSaveEnabled(bool enable
)
776 if (!m_sessionSaveTimer
) {
777 m_sessionSaveTimer
= new QTimer(this);
778 m_sessionSaveWatcher
= new QFutureWatcher
<void>(this);
779 m_sessionSaveTimer
->setSingleShot(true);
780 m_sessionSaveTimer
->setInterval(22000);
782 connect(m_sessionSaveTimer
, &QTimer::timeout
, this, &DolphinMainWindow::slotSaveSession
);
785 connect(m_tabWidget
, &DolphinTabWidget::urlChanged
, m_sessionSaveTimer
, qOverload
<>(&QTimer::start
), Qt::UniqueConnection
);
786 connect(m_tabWidget
, &DolphinTabWidget::tabCountChanged
, m_sessionSaveTimer
, qOverload
<>(&QTimer::start
), Qt::UniqueConnection
);
787 connect(m_tabWidget
, &DolphinTabWidget::activeViewChanged
, m_sessionSaveTimer
, qOverload
<>(&QTimer::start
), Qt::UniqueConnection
);
788 } else if (m_sessionSaveTimer
) {
789 m_sessionSaveTimer
->stop();
790 m_sessionSaveWatcher
->disconnect();
791 m_sessionSaveScheduled
= false;
793 m_sessionSaveWatcher
->waitForFinished();
795 m_sessionSaveTimer
->deleteLater();
796 m_sessionSaveWatcher
->deleteLater();
797 m_sessionSaveTimer
= nullptr;
798 m_sessionSaveWatcher
= nullptr;
802 void DolphinMainWindow::saveProperties(KConfigGroup
&group
)
804 m_tabWidget
->saveProperties(group
);
807 void DolphinMainWindow::readProperties(const KConfigGroup
&group
)
809 m_tabWidget
->readProperties(group
);
812 void DolphinMainWindow::updateNewMenu()
814 m_newFileMenu
->checkUpToDate();
815 m_newFileMenu
->setWorkingDirectory(activeViewContainer()->url());
818 void DolphinMainWindow::createDirectory()
820 // When creating directory, namejob is being run. In network folders,
821 // this job can take long time, so instead of starting multiple namejobs,
822 // just check if we are already running one. This prevents opening multiple
823 // dialogs. BUG:481401
824 if (!m_newFileMenu
->isCreateDirectoryRunning()) {
825 m_newFileMenu
->setWorkingDirectory(activeViewContainer()->url());
826 m_newFileMenu
->createDirectory();
830 void DolphinMainWindow::createFile()
832 // Use the same logic as in createDirectory()
833 if (!m_newFileMenu
->isCreateFileRunning()) {
834 m_newFileMenu
->setWorkingDirectory(activeViewContainer()->url());
835 m_newFileMenu
->createFile();
839 void DolphinMainWindow::quit()
844 void DolphinMainWindow::showErrorMessage(const QString
&message
)
846 m_activeViewContainer
->showMessage(message
, KMessageWidget::Error
);
849 void DolphinMainWindow::slotUndoAvailable(bool available
)
851 QAction
*undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
853 undoAction
->setEnabled(available
);
857 void DolphinMainWindow::slotUndoTextChanged(const QString
&text
)
859 QAction
*undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
861 undoAction
->setText(text
);
865 void DolphinMainWindow::undo()
868 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
869 KIO::FileUndoManager::self()->undo();
872 void DolphinMainWindow::cut()
874 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
875 m_activeViewContainer
->setSelectionModeEnabled(true, actionCollection(), SelectionMode::BottomBar::Contents::CutContents
);
877 m_activeViewContainer
->view()->cutSelectedItemsToClipboard();
878 m_activeViewContainer
->setSelectionModeEnabled(false);
882 void DolphinMainWindow::copy()
884 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
885 m_activeViewContainer
->setSelectionModeEnabled(true, actionCollection(), SelectionMode::BottomBar::Contents::CopyContents
);
887 m_activeViewContainer
->view()->copySelectedItemsToClipboard();
888 m_activeViewContainer
->setSelectionModeEnabled(false);
892 void DolphinMainWindow::paste()
894 m_activeViewContainer
->view()->paste();
897 void DolphinMainWindow::find()
899 m_activeViewContainer
->setSearchBarVisible(true);
900 m_activeViewContainer
->setFocusToSearchBar();
903 void DolphinMainWindow::updateSearchAction()
905 QAction
*toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
906 toggleSearchAction
->setChecked(m_activeViewContainer
->isSearchBarVisible());
909 void DolphinMainWindow::updatePasteAction()
911 QAction
*pasteAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Paste
));
912 QPair
<bool, QString
> pasteInfo
= m_activeViewContainer
->view()->pasteInfo();
913 pasteAction
->setEnabled(pasteInfo
.first
);
914 m_disabledActionNotifier
->setDisabledReason(pasteAction
,
915 m_activeViewContainer
->rootItem().isWritable()
916 ? i18nc("@info", "Cannot paste: The clipboard is empty.")
917 : i18nc("@info", "Cannot paste: You do not have permission to write into this folder."));
918 pasteAction
->setText(pasteInfo
.second
);
921 void DolphinMainWindow::slotDirectoryLoadingCompleted()
926 void DolphinMainWindow::slotToolBarActionMiddleClicked(QAction
*action
)
928 if (action
== actionCollection()->action(KStandardAction::name(KStandardAction::Back
))) {
930 } else if (action
== actionCollection()->action(KStandardAction::name(KStandardAction::Forward
))) {
932 } else if (action
== actionCollection()->action(QStringLiteral("go_up"))) {
934 } else if (action
== actionCollection()->action(QStringLiteral("go_home"))) {
939 QAction
*DolphinMainWindow::urlNavigatorHistoryAction(const KUrlNavigator
*urlNavigator
, int historyIndex
, QObject
*parent
)
941 const QUrl url
= urlNavigator
->locationUrl(historyIndex
);
945 if (isSearchUrl(url
)) {
946 text
= Search::DolphinQuery(url
, QUrl
{}).title();
947 } else if (urlNavigator
->showFullPath()) {
948 text
= url
.toDisplayString(QUrl::PreferLocalFile
);
950 const KFilePlacesModel
*placesModel
= DolphinPlacesModelSingleton::instance().placesModel();
952 const QModelIndex closestIdx
= placesModel
->closestItem(url
);
953 if (closestIdx
.isValid()) {
954 const QUrl placeUrl
= placesModel
->url(closestIdx
);
956 text
= placesModel
->text(closestIdx
);
958 QString pathInsidePlace
= url
.path().mid(placeUrl
.path().length());
960 if (!pathInsidePlace
.isEmpty() && !pathInsidePlace
.startsWith(QLatin1Char('/'))) {
961 pathInsidePlace
.prepend(QLatin1Char('/'));
964 if (pathInsidePlace
!= QLatin1Char('/')) {
965 text
.append(pathInsidePlace
);
970 QAction
*action
= new QAction(QIcon::fromTheme(KIO::iconNameForUrl(url
)), text
, parent
);
971 action
->setData(historyIndex
);
975 void DolphinMainWindow::slotAboutToShowBackPopupMenu()
977 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
979 QMenu
*menu
= m_backAction
->popupMenu();
981 for (int i
= urlNavigator
->historyIndex() + 1; i
< urlNavigator
->historySize() && entries
< MaxNumberOfNavigationentries
; ++i
, ++entries
) {
982 QAction
*action
= urlNavigatorHistoryAction(urlNavigator
, i
, menu
);
983 menu
->addAction(action
);
987 void DolphinMainWindow::slotGoBack(QAction
*action
)
989 int gotoIndex
= action
->data().value
<int>();
990 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
991 for (int i
= gotoIndex
- urlNavigator
->historyIndex(); i
> 0; --i
) {
996 void DolphinMainWindow::slotBackForwardActionMiddleClicked(QAction
*action
)
999 const KUrlNavigator
*urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
1000 openNewTab(urlNavigator
->locationUrl(action
->data().value
<int>()));
1004 void DolphinMainWindow::slotAboutToShowForwardPopupMenu()
1006 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
1008 QMenu
*menu
= m_forwardAction
->popupMenu();
1010 for (int i
= urlNavigator
->historyIndex() - 1; i
>= 0 && entries
< MaxNumberOfNavigationentries
; --i
, ++entries
) {
1011 QAction
*action
= urlNavigatorHistoryAction(urlNavigator
, i
, menu
);
1012 menu
->addAction(action
);
1016 void DolphinMainWindow::slotGoForward(QAction
*action
)
1018 int gotoIndex
= action
->data().value
<int>();
1019 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
1020 for (int i
= urlNavigator
->historyIndex() - gotoIndex
; i
> 0; --i
) {
1025 void DolphinMainWindow::slotSetSelectionMode(bool enabled
, SelectionMode::BottomBar::Contents bottomBarContents
)
1027 m_activeViewContainer
->setSelectionModeEnabled(enabled
, actionCollection(), bottomBarContents
);
1030 void DolphinMainWindow::selectAll()
1034 // if the URL navigator is editable and focused, select the whole
1035 // URL instead of all items of the view
1037 KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigator();
1038 QLineEdit
*lineEdit
= urlNavigator
->editor()->lineEdit();
1039 const bool selectUrl
= urlNavigator
->isUrlEditable() && lineEdit
->hasFocus();
1041 lineEdit
->selectAll();
1043 m_activeViewContainer
->view()->selectAll();
1047 void DolphinMainWindow::invertSelection()
1050 m_activeViewContainer
->view()->invertSelection();
1053 void DolphinMainWindow::toggleSplitView()
1055 QUrl newSplitViewUrl
;
1056 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
1057 if (list
.count() == 1) {
1058 const KFileItem
&item
= list
.first();
1059 newSplitViewUrl
= DolphinView::openItemAsFolderUrl(item
);
1062 DolphinTabPage
*tabPage
= m_tabWidget
->currentTabPage();
1063 tabPage
->setSplitViewEnabled(!tabPage
->splitViewEnabled(), WithAnimation
, newSplitViewUrl
);
1064 m_tabWidget
->updateTabName(m_tabWidget
->indexOf(tabPage
));
1065 updateViewActions();
1068 void DolphinMainWindow::popoutSplitView()
1070 DolphinTabPage
*tabPage
= m_tabWidget
->currentTabPage();
1071 if (!tabPage
->splitViewEnabled())
1073 openNewWindow((GeneralSettings::closeActiveSplitView() ? tabPage
->activeViewContainer() : tabPage
->inactiveViewContainer())->url());
1074 tabPage
->setSplitViewEnabled(false, WithAnimation
);
1075 updateSplitActions();
1078 void DolphinMainWindow::toggleSplitStash()
1080 DolphinTabPage
*tabPage
= m_tabWidget
->currentTabPage();
1081 tabPage
->setSplitViewEnabled(false, WithAnimation
);
1082 tabPage
->setSplitViewEnabled(true, WithAnimation
, QUrl("stash:/"));
1085 void DolphinMainWindow::copyToInactiveSplitView()
1087 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
1088 m_activeViewContainer
->setSelectionModeEnabled(true, actionCollection(), SelectionMode::BottomBar::Contents::CopyToOtherViewContents
);
1090 m_tabWidget
->copyToInactiveSplitView();
1091 m_activeViewContainer
->setSelectionModeEnabled(false);
1095 void DolphinMainWindow::moveToInactiveSplitView()
1097 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
1098 m_activeViewContainer
->setSelectionModeEnabled(true, actionCollection(), SelectionMode::BottomBar::Contents::MoveToOtherViewContents
);
1100 m_tabWidget
->moveToInactiveSplitView();
1101 m_activeViewContainer
->setSelectionModeEnabled(false);
1105 void DolphinMainWindow::reloadView()
1108 m_activeViewContainer
->reload();
1109 m_activeViewContainer
->statusBar()->updateSpaceInfo();
1112 void DolphinMainWindow::stopLoading()
1114 m_activeViewContainer
->view()->stopLoading();
1117 void DolphinMainWindow::enableStopAction()
1119 actionCollection()->action(QStringLiteral("stop"))->setEnabled(true);
1122 void DolphinMainWindow::disableStopAction()
1124 actionCollection()->action(QStringLiteral("stop"))->setEnabled(false);
1127 void DolphinMainWindow::toggleSelectionMode()
1129 const bool checked
= !m_activeViewContainer
->isSelectionModeEnabled();
1131 m_activeViewContainer
->setSelectionModeEnabled(checked
, actionCollection(), SelectionMode::BottomBar::Contents::GeneralContents
);
1132 actionCollection()->action(QStringLiteral("toggle_selection_mode"))->setChecked(checked
);
1135 void DolphinMainWindow::showFilterBar()
1137 m_activeViewContainer
->setFilterBarVisible(true);
1140 void DolphinMainWindow::toggleFilterBar()
1142 const bool checked
= !m_activeViewContainer
->isFilterBarVisible();
1143 m_activeViewContainer
->setFilterBarVisible(checked
);
1145 QAction
*toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
1146 toggleFilterBarAction
->setChecked(checked
);
1149 void DolphinMainWindow::toggleEditLocation()
1153 QAction
*action
= actionCollection()->action(QStringLiteral("editable_location"));
1154 KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigator();
1155 urlNavigator
->setUrlEditable(action
->isChecked());
1158 void DolphinMainWindow::replaceLocation()
1160 KUrlNavigator
*navigator
= m_activeViewContainer
->urlNavigator();
1161 QLineEdit
*lineEdit
= navigator
->editor()->lineEdit();
1163 // If the text field currently has focus and everything is selected,
1164 // pressing the keyboard shortcut returns the whole thing to breadcrumb mode
1165 // and goes back to the view, just like how it was before this action was triggered the first time.
1166 if (navigator
->isUrlEditable() && lineEdit
->hasFocus() && lineEdit
->selectedText() == lineEdit
->text()) {
1167 navigator
->setUrlEditable(false);
1168 m_activeViewContainer
->view()->setFocus();
1170 navigator
->setUrlEditable(true);
1171 navigator
->setFocus();
1172 lineEdit
->selectAll();
1176 void DolphinMainWindow::togglePanelLockState()
1178 const bool newLockState
= !GeneralSettings::lockPanels();
1179 const auto childrenObjects
= children();
1180 for (QObject
*child
: childrenObjects
) {
1181 DolphinDockWidget
*dock
= qobject_cast
<DolphinDockWidget
*>(child
);
1183 dock
->setLocked(newLockState
);
1187 DolphinPlacesModelSingleton::instance().placesModel()->setPanelsLocked(newLockState
);
1189 GeneralSettings::setLockPanels(newLockState
);
1192 void DolphinMainWindow::slotTerminalPanelVisibilityChanged(bool visible
)
1194 if (!visible
&& m_activeViewContainer
) {
1195 m_activeViewContainer
->view()->setFocus();
1197 // Putting focus to the Terminal is not handled here but in TerminalPanel::showEvent().
1200 void DolphinMainWindow::slotPlacesPanelVisibilityChanged(bool visible
)
1202 if (!visible
&& m_activeViewContainer
) {
1203 m_activeViewContainer
->view()->setFocus();
1206 m_placesPanel
->setFocus();
1209 void DolphinMainWindow::goBack()
1211 DolphinUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
1212 urlNavigator
->goBack();
1214 if (urlNavigator
->locationState().isEmpty()) {
1215 // An empty location state indicates a redirection URL,
1216 // which must be skipped too
1217 urlNavigator
->goBack();
1221 void DolphinMainWindow::goForward()
1223 m_activeViewContainer
->urlNavigatorInternalWithHistory()->goForward();
1226 void DolphinMainWindow::goUp()
1228 m_activeViewContainer
->urlNavigatorInternalWithHistory()->goUp();
1231 void DolphinMainWindow::goHome()
1233 m_activeViewContainer
->urlNavigatorInternalWithHistory()->goHome();
1236 void DolphinMainWindow::goBackInNewTab()
1238 const KUrlNavigator
*urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
1239 const int index
= urlNavigator
->historyIndex() + 1;
1240 openNewTab(urlNavigator
->locationUrl(index
));
1243 void DolphinMainWindow::goForwardInNewTab()
1245 const KUrlNavigator
*urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
1246 const int index
= urlNavigator
->historyIndex() - 1;
1247 openNewTab(urlNavigator
->locationUrl(index
));
1250 void DolphinMainWindow::goUpInNewTab()
1252 const QUrl currentUrl
= activeViewContainer()->urlNavigator()->locationUrl();
1253 openNewTab(KIO::upUrl(currentUrl
));
1256 void DolphinMainWindow::goHomeInNewTab()
1258 openNewTab(Dolphin::homeUrl());
1261 void DolphinMainWindow::compareFiles()
1263 const KFileItemList items
= m_tabWidget
->currentTabPage()->selectedItems();
1264 if (items
.count() != 2) {
1265 // The action is disabled in this case, but it could have been triggered
1266 // via D-Bus, see https://bugs.kde.org/show_bug.cgi?id=325517
1270 QUrl urlA
= items
.at(0).url();
1271 QUrl urlB
= items
.at(1).url();
1273 QString
command(QStringLiteral("kompare -c \""));
1274 command
.append(urlA
.toDisplayString(QUrl::PreferLocalFile
));
1275 command
.append("\" \"");
1276 command
.append(urlB
.toDisplayString(QUrl::PreferLocalFile
));
1277 command
.append('\"');
1279 KIO::CommandLauncherJob
*job
= new KIO::CommandLauncherJob(command
, this);
1280 job
->setDesktopName(QStringLiteral("org.kde.kompare"));
1284 void DolphinMainWindow::toggleShowMenuBar()
1286 const bool visible
= menuBar()->isVisible();
1287 menuBar()->setVisible(!visible
);
1290 QPointer
<QAction
> DolphinMainWindow::preferredSearchTool()
1292 m_searchTools
.clear();
1294 KService::Ptr kfind
= KService::serviceByDesktopName(QStringLiteral("org.kde.kfind"));
1300 auto *action
= new QAction(QIcon::fromTheme(kfind
->icon()), kfind
->name(), this);
1302 connect(action
, &QAction::triggered
, this, [this, kfind
] {
1303 auto *job
= new KIO::ApplicationLauncherJob(kfind
);
1304 job
->setUrls({m_activeViewContainer
->url()});
1311 void DolphinMainWindow::updateOpenPreferredSearchToolAction()
1313 QAction
*openPreferredSearchTool
= actionCollection()->action(QStringLiteral("open_preferred_search_tool"));
1314 if (!openPreferredSearchTool
) {
1317 QPointer
<QAction
> tool
= preferredSearchTool();
1319 openPreferredSearchTool
->setVisible(true);
1320 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open %1", tool
->text()));
1321 // Only override with the app icon if it is the default, i.e. the user hasn't configured one manually
1322 // https://bugs.kde.org/show_bug.cgi?id=442815
1323 if (openPreferredSearchTool
->icon().name() == QLatin1String("search")) {
1324 openPreferredSearchTool
->setIcon(tool
->icon());
1327 openPreferredSearchTool
->setVisible(false);
1328 // still visible in Shortcuts configuration window
1329 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool"));
1330 openPreferredSearchTool
->setIcon(QIcon::fromTheme(QStringLiteral("search")));
1334 void DolphinMainWindow::openPreferredSearchTool()
1336 QPointer
<QAction
> tool
= preferredSearchTool();
1342 void DolphinMainWindow::openTerminal()
1344 openTerminalJob(m_activeViewContainer
->url());
1347 void DolphinMainWindow::openTerminalHere()
1349 QList
<QUrl
> urls
= {};
1351 const auto selectedItems
= m_activeViewContainer
->view()->selectedItems();
1352 for (const KFileItem
&item
: selectedItems
) {
1353 QUrl url
= item
.targetUrl();
1354 if (item
.isFile()) {
1355 url
.setPath(QFileInfo(url
.path()).absolutePath());
1357 if (!urls
.contains(url
)) {
1362 // No items are selected. Open a terminal window for the current location.
1363 if (urls
.count() == 0) {
1368 if (urls
.count() > 5) {
1369 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());
1370 const int answer
= KMessageBox::warningContinueCancel(
1374 KGuiItem(i18ncp("@action:button", "Open %1 Terminal", "Open %1 Terminals", urls
.count()), QStringLiteral("utilities-terminal")),
1375 KStandardGuiItem::cancel(),
1376 QStringLiteral("ConfirmOpenManyTerminals"));
1377 if (answer
!= KMessageBox::PrimaryAction
&& answer
!= KMessageBox::Continue
) {
1382 for (const QUrl
&url
: std::as_const(urls
)) {
1383 openTerminalJob(url
);
1387 void DolphinMainWindow::openTerminalJob(const QUrl
&url
)
1389 if (url
.isLocalFile()) {
1390 auto job
= new KTerminalLauncherJob(QString());
1391 job
->setWorkingDirectory(url
.toLocalFile());
1396 // Not a local file, with protocol Class ":local", try stat'ing
1397 if (KProtocolInfo::protocolClass(url
.scheme()) == QLatin1String(":local")) {
1398 KIO::StatJob
*job
= KIO::mostLocalUrl(url
);
1399 KJobWidgets::setWindow(job
, this);
1400 connect(job
, &KJob::result
, this, [job
]() {
1402 if (!job
->error()) {
1403 statUrl
= job
->mostLocalUrl();
1406 auto job
= new KTerminalLauncherJob(QString());
1407 job
->setWorkingDirectory(statUrl
.isLocalFile() ? statUrl
.toLocalFile() : QDir::homePath());
1414 // Nothing worked, just use $HOME
1415 auto job
= new KTerminalLauncherJob(QString());
1416 job
->setWorkingDirectory(QDir::homePath());
1420 void DolphinMainWindow::editSettings()
1422 if (!m_settingsDialog
) {
1423 DolphinViewContainer
*container
= activeViewContainer();
1424 container
->view()->writeSettings();
1426 const QUrl url
= container
->url();
1427 DolphinSettingsDialog
*settingsDialog
= new DolphinSettingsDialog(url
, this, actionCollection());
1428 connect(settingsDialog
, &DolphinSettingsDialog::settingsChanged
, this, &DolphinMainWindow::refreshViews
);
1429 connect(settingsDialog
, &DolphinSettingsDialog::settingsChanged
, &DolphinUrlNavigatorsController::slotReadSettings
);
1430 settingsDialog
->setAttribute(Qt::WA_DeleteOnClose
);
1431 settingsDialog
->show();
1432 m_settingsDialog
= settingsDialog
;
1434 m_settingsDialog
.data()->raise();
1438 void DolphinMainWindow::handleUrl(const QUrl
&url
)
1440 delete m_lastHandleUrlOpenJob
;
1441 m_lastHandleUrlOpenJob
= nullptr;
1443 if (url
.isLocalFile() && QFileInfo(url
.toLocalFile()).isDir()) {
1444 activeViewContainer()->setUrl(url
);
1446 m_lastHandleUrlOpenJob
= new KIO::OpenUrlJob(url
);
1447 m_lastHandleUrlOpenJob
->setUiDelegate(KIO::createDefaultJobUiDelegate(KJobUiDelegate::AutoHandlingEnabled
, this));
1448 m_lastHandleUrlOpenJob
->setShowOpenOrExecuteDialog(true);
1450 connect(m_lastHandleUrlOpenJob
, &KIO::OpenUrlJob::mimeTypeFound
, this, [this, url
](const QString
&mimetype
) {
1451 if (mimetype
== QLatin1String("inode/directory")) {
1452 // If it's a dir, we'll take it from here
1453 m_lastHandleUrlOpenJob
->kill();
1454 m_lastHandleUrlOpenJob
= nullptr;
1455 activeViewContainer()->setUrl(url
);
1459 connect(m_lastHandleUrlOpenJob
, &KIO::OpenUrlJob::result
, this, [this]() {
1460 m_lastHandleUrlOpenJob
= nullptr;
1463 m_lastHandleUrlOpenJob
->start();
1467 void DolphinMainWindow::slotWriteStateChanged(bool isFolderWritable
)
1469 // trash:/ is writable but we don't want to create new items in it.
1470 // TODO: remove the trash check once https://phabricator.kde.org/T8234 is implemented
1471 newFileMenu()->setEnabled(isFolderWritable
&& m_activeViewContainer
->url().scheme() != QLatin1String("trash"));
1472 // 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.
1473 QTimer::singleShot(0, this, [this]() {
1474 m_disabledActionNotifier
->setDisabledReason(actionCollection()->action(QStringLiteral("create_file")),
1475 i18nc("@info", "Cannot create new file: You do not have permission to create items in this folder."));
1476 m_disabledActionNotifier
->setDisabledReason(actionCollection()->action(QStringLiteral("create_dir")),
1477 i18nc("@info", "Cannot create new folder: You do not have permission to create items in this folder."));
1481 void DolphinMainWindow::openContextMenu(const QPoint
&pos
, const KFileItem
&item
, const KFileItemList
&selectedItems
, const QUrl
&url
)
1483 QPointer
<DolphinContextMenu
> contextMenu
= new DolphinContextMenu(this, item
, selectedItems
, url
, &m_fileItemActions
);
1484 contextMenu
->exec(pos
);
1486 // Delete the menu, unless it has been deleted in its own nested event loop already.
1488 contextMenu
->deleteLater();
1492 QMenu
*DolphinMainWindow::createPopupMenu()
1494 QMenu
*menu
= KXmlGuiWindow::createPopupMenu();
1496 menu
->addSeparator();
1497 menu
->addAction(actionCollection()->action(QStringLiteral("lock_panels")));
1502 void DolphinMainWindow::updateHamburgerMenu()
1504 KActionCollection
*ac
= actionCollection();
1505 auto hamburgerMenu
= static_cast<KHamburgerMenu
*>(ac
->action(KStandardAction::name(KStandardAction::HamburgerMenu
)));
1506 auto menu
= hamburgerMenu
->menu();
1508 menu
= new QMenu(this);
1509 hamburgerMenu
->setMenu(menu
);
1510 hamburgerMenu
->hideActionsOf(ac
->action(QStringLiteral("basic_actions"))->menu());
1511 hamburgerMenu
->hideActionsOf(ac
->action(QStringLiteral("zoom"))->menu());
1515 const QList
<QAction
*> toolbarActions
= toolBar()->actions();
1517 if (!toolBar()->isVisible()) {
1518 // If neither the menu bar nor the toolbar are visible, these actions should be available.
1519 menu
->addAction(ac
->action(KStandardAction::name(KStandardAction::ShowMenubar
)));
1520 menu
->addAction(toolBarMenuAction());
1521 menu
->addSeparator();
1524 // This group of actions (until the next separator) contains all the most basic actions
1525 // necessary to use Dolphin effectively.
1526 menu
->addAction(ac
->action(QStringLiteral("go_back")));
1527 menu
->addAction(ac
->action(QStringLiteral("go_forward")));
1529 menu
->addMenu(m_newFileMenu
->menu());
1530 if (!toolBar()->isVisible() || !toolbarActions
.contains(ac
->action(QStringLiteral("toggle_selection_mode_tool_bar")))) {
1531 menu
->addAction(ac
->action(QStringLiteral("toggle_selection_mode")));
1533 menu
->addAction(ac
->action(QStringLiteral("basic_actions")));
1534 menu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Undo
)));
1535 if (!toolBar()->isVisible()
1536 || (!toolbarActions
.contains(ac
->action(QStringLiteral("toggle_search")))
1537 && !toolbarActions
.contains(ac
->action(QStringLiteral("open_preferred_search_tool"))))) {
1538 menu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Find
)));
1539 // This way a search action will only be added if none of the three available
1540 // search actions is present on the toolbar.
1542 if (!toolBar()->isVisible() || !toolbarActions
.contains(ac
->action(QStringLiteral("toggle_filter")))) {
1543 menu
->addAction(ac
->action(QStringLiteral("show_filter_bar")));
1544 // This way a filter action will only be added if none of the two available
1545 // filter actions is present on the toolbar.
1547 menu
->addSeparator();
1549 // The second group of actions (up until the next separator) contains actions for opening
1550 // additional views to interact with the file system.
1551 menu
->addAction(ac
->action(QStringLiteral("file_new")));
1552 menu
->addAction(ac
->action(QStringLiteral("new_tab")));
1553 if (ac
->action(QStringLiteral("undo_close_tab"))->isEnabled()) {
1554 menu
->addAction(ac
->action(QStringLiteral("closed_tabs")));
1556 menu
->addAction(ac
->action(QStringLiteral("open_terminal")));
1557 menu
->addSeparator();
1559 // The third group contains actions to change what one sees in the view
1560 // and to change the more general UI.
1561 if (!toolBar()->isVisible()
1562 || (!toolbarActions
.contains(ac
->action(QStringLiteral("icons"))) && !toolbarActions
.contains(ac
->action(QStringLiteral("compact")))
1563 && !toolbarActions
.contains(ac
->action(QStringLiteral("details"))) && !toolbarActions
.contains(ac
->action(QStringLiteral("view_mode"))))
1564 && !toolbarActions
.contains(ac
->action(QStringLiteral("view_settings")))) {
1565 menu
->addAction(ac
->action(QStringLiteral("view_mode")));
1567 if (!toolBar()->isVisible() || !toolbarActions
.contains(ac
->action(QStringLiteral("view_settings")))) {
1568 menu
->addAction(ac
->action(QStringLiteral("show_hidden_files")));
1569 menu
->addAction(ac
->action(QStringLiteral("sort")));
1570 menu
->addAction(ac
->action(QStringLiteral("additional_info")));
1571 if (!GeneralSettings::showStatusBar() || !GeneralSettings::showZoomSlider()) {
1572 menu
->addAction(ac
->action(QStringLiteral("zoom")));
1575 menu
->addAction(ac
->action(QStringLiteral("panels")));
1577 // The "Configure" menu is not added to the actionCollection() because there is hardly
1578 // a good reason for users to put it on their toolbar.
1579 auto configureMenu
= menu
->addMenu(QIcon::fromTheme(QStringLiteral("configure")), i18nc("@action:inmenu menu for configure actions", "Configure"));
1580 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::SwitchApplicationLanguage
)));
1581 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::KeyBindings
)));
1582 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::ConfigureToolbars
)));
1583 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Preferences
)));
1584 hamburgerMenu
->hideActionsOf(configureMenu
);
1587 void DolphinMainWindow::slotPlaceActivated(const QUrl
&url
)
1589 DolphinViewContainer
*view
= activeViewContainer();
1591 if (view
->url() == url
) {
1592 view
->clearFilterBar(); // Fixes bug 259382.
1594 // We can end up here if the user clicked a device in the Places Panel
1595 // which had been unmounted earlier, see https://bugs.kde.org/show_bug.cgi?id=161385.
1598 m_activeViewContainer
->view()->setFocus(); // We always want the focus on the view after activating a place.
1600 view
->disableUrlNavigatorSelectionRequests();
1602 view
->enableUrlNavigatorSelectionRequests();
1606 void DolphinMainWindow::closedTabsCountChanged(unsigned int count
)
1608 actionCollection()->action(QStringLiteral("undo_close_tab"))->setEnabled(count
> 0);
1611 void DolphinMainWindow::activeViewChanged(DolphinViewContainer
*viewContainer
)
1613 DolphinViewContainer
*oldViewContainer
= m_activeViewContainer
;
1614 Q_ASSERT(viewContainer
);
1616 m_activeViewContainer
= viewContainer
;
1618 if (oldViewContainer
) {
1619 // Disconnect all signals between the old view container (container,
1620 // view and url navigator) and main window.
1621 oldViewContainer
->disconnect(this);
1622 oldViewContainer
->view()->disconnect(this);
1623 oldViewContainer
->urlNavigatorInternalWithHistory()->disconnect(this);
1624 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>(actionCollection()->action(QStringLiteral("url_navigators")));
1625 navigators
->primaryUrlNavigator()->disconnect(this);
1626 if (auto secondaryUrlNavigator
= navigators
->secondaryUrlNavigator()) {
1627 secondaryUrlNavigator
->disconnect(this);
1630 // except the requestItemInfo so that on hover the information panel can still be updated
1631 connect(oldViewContainer
->view(), &DolphinView::requestItemInfo
, this, &DolphinMainWindow::requestItemInfo
);
1633 // Disconnect other slots.
1634 disconnect(oldViewContainer
,
1635 &DolphinViewContainer::selectionModeChanged
,
1636 actionCollection()->action(QStringLiteral("toggle_selection_mode")),
1637 &QAction::setChecked
);
1640 connectViewSignals(viewContainer
);
1642 m_actionHandler
->setCurrentView(viewContainer
->view());
1645 updateFileAndEditActions();
1646 updatePasteAction();
1647 updateViewActions();
1649 updateSearchAction();
1651 const QUrl url
= viewContainer
->url();
1652 Q_EMIT
urlChanged(url
);
1655 void DolphinMainWindow::tabCountChanged(int count
)
1657 const bool enableTabActions
= (count
> 1);
1658 for (int i
= 0; i
< MaxActivateTabShortcuts
; ++i
) {
1659 actionCollection()->action(QStringLiteral("activate_tab_%1").arg(i
))->setEnabled(enableTabActions
);
1661 actionCollection()->action(QStringLiteral("activate_last_tab"))->setEnabled(enableTabActions
);
1662 actionCollection()->action(QStringLiteral("activate_next_tab"))->setEnabled(enableTabActions
);
1663 actionCollection()->action(QStringLiteral("activate_prev_tab"))->setEnabled(enableTabActions
);
1666 void DolphinMainWindow::updateWindowTitle()
1668 const QString newTitle
= m_activeViewContainer
->captionWindowTitle();
1669 if (windowTitle() != newTitle
) {
1670 setWindowTitle(newTitle
);
1674 void DolphinMainWindow::slotStorageTearDownFromPlacesRequested(const QString
&mountPath
)
1676 connect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, this, [this, mountPath
]() {
1677 setViewsToHomeIfMountPathOpen(mountPath
);
1680 if (m_terminalPanel
&& m_terminalPanel
->currentWorkingDirectoryIsChildOf(mountPath
)) {
1681 m_tearDownFromPlacesRequested
= true;
1682 m_terminalPanel
->goHome();
1683 // m_placesPanel->proceedWithTearDown() will be called in slotTerminalDirectoryChanged
1685 m_placesPanel
->proceedWithTearDown();
1689 void DolphinMainWindow::slotStorageTearDownExternallyRequested(const QString
&mountPath
)
1691 connect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, this, [this, mountPath
]() {
1692 setViewsToHomeIfMountPathOpen(mountPath
);
1695 if (m_terminalPanel
&& m_terminalPanel
->currentWorkingDirectoryIsChildOf(mountPath
)) {
1696 m_tearDownFromPlacesRequested
= false;
1697 m_terminalPanel
->goHome();
1701 void DolphinMainWindow::slotKeyBindings()
1703 KShortcutsDialog
dialog(KShortcutsEditor::AllActions
, KShortcutsEditor::LetterShortcutsAllowed
, this);
1704 dialog
.addCollection(actionCollection());
1705 if (m_terminalPanel
) {
1706 KActionCollection
*konsolePartActionCollection
= m_terminalPanel
->actionCollection();
1707 if (konsolePartActionCollection
) {
1708 dialog
.addCollection(konsolePartActionCollection
, QStringLiteral("KonsolePart"));
1714 void DolphinMainWindow::setViewsToHomeIfMountPathOpen(const QString
&mountPath
)
1716 const QVector
<DolphinViewContainer
*> theViewContainers
= viewContainers();
1717 for (DolphinViewContainer
*viewContainer
: theViewContainers
) {
1718 if (viewContainer
&& viewContainer
->url().toLocalFile().startsWith(mountPath
)) {
1719 viewContainer
->setUrl(QUrl::fromLocalFile(QDir::homePath()));
1722 disconnect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, nullptr, nullptr);
1725 void DolphinMainWindow::setupActions()
1727 auto hamburgerMenuAction
= KStandardAction::hamburgerMenu(nullptr, nullptr, actionCollection());
1729 // setup 'File' menu
1730 m_newFileMenu
= new DolphinNewFileMenu(nullptr, nullptr, this);
1731 actionCollection()->addAction(QStringLiteral("new_menu"), m_newFileMenu
);
1732 QMenu
*menu
= m_newFileMenu
->menu();
1733 menu
->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1734 menu
->setIcon(QIcon::fromTheme(QStringLiteral("list-add")));
1735 m_newFileMenu
->setPopupMode(QToolButton::InstantPopup
);
1736 connect(menu
, &QMenu::aboutToShow
, this, &DolphinMainWindow::updateNewMenu
);
1738 QAction
*newWindow
= KStandardAction::openNew(this, &DolphinMainWindow::openNewMainWindow
, actionCollection());
1739 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
1740 newWindow
->setToolTip(i18nc("@info", "Open a new Dolphin window"));
1741 newWindow
->setWhatsThis(xi18nc("@info:whatsthis",
1743 "window just like this one with the current location."
1744 "<nl/>You can drag and drop items between windows."));
1745 newWindow
->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
1747 QAction
*newTab
= actionCollection()->addAction(QStringLiteral("new_tab"));
1748 newTab
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1749 newTab
->setText(i18nc("@action:inmenu File", "New Tab"));
1750 newTab
->setWhatsThis(xi18nc("@info:whatsthis",
1752 "<emphasis>Tab</emphasis> with the current location."
1753 "<nl/>Tabs allow you to quickly switch between multiple locations and views within this window. "
1754 "You can drag and drop items between tabs."));
1755 actionCollection()->setDefaultShortcut(newTab
, Qt::CTRL
| Qt::Key_T
);
1756 connect(newTab
, &QAction::triggered
, this, &DolphinMainWindow::openNewActivatedTab
);
1758 QAction
*addToPlaces
= actionCollection()->addAction(QStringLiteral("add_to_places"));
1759 addToPlaces
->setIcon(QIcon::fromTheme(QStringLiteral("bookmark-new")));
1760 addToPlaces
->setText(i18nc("@action:inmenu Add current folder to places", "Add to Places"));
1761 addToPlaces
->setWhatsThis(xi18nc("@info:whatsthis",
1762 "This adds the selected folder "
1763 "to the Places panel."));
1764 connect(addToPlaces
, &QAction::triggered
, this, &DolphinMainWindow::addToPlaces
);
1766 QAction
*closeTab
= KStandardAction::close(m_tabWidget
, QOverload
<>::of(&DolphinTabWidget::closeTab
), actionCollection());
1767 closeTab
->setText(i18nc("@action:inmenu File", "Close Tab"));
1768 closeTab
->setToolTip(i18nc("@info", "Close Tab"));
1769 closeTab
->setWhatsThis(i18nc("@info:whatsthis",
1771 "currently viewed tab. If no more tabs are left, this closes "
1772 "the whole window instead."));
1774 QAction
*quitAction
= KStandardAction::quit(this, &DolphinMainWindow::quit
, actionCollection());
1775 quitAction
->setWhatsThis(i18nc("@info:whatsthis quit", "This closes this window."));
1777 // setup 'Edit' menu
1778 KStandardAction::undo(this, &DolphinMainWindow::undo
, actionCollection());
1780 // i18n: This will be the last paragraph for the whatsthis for all three:
1781 // Cut, Copy and Paste
1782 const QString cutCopyPastePara
= xi18nc("@info:whatsthis",
1783 "<para><emphasis>Cut, "
1784 "Copy</emphasis> and <emphasis>Paste</emphasis> work between many "
1785 "applications and are among the most used commands. That's why their "
1786 "<emphasis>keyboard shortcuts</emphasis> are prominently placed right "
1787 "next to each other on the keyboard: <shortcut>Ctrl+X</shortcut>, "
1788 "<shortcut>Ctrl+C</shortcut> and <shortcut>Ctrl+V</shortcut>.</para>");
1789 QAction
*cutAction
= KStandardAction::cut(this, &DolphinMainWindow::cut
, actionCollection());
1790 m_actionTextHelper
->registerTextWhenNothingIsSelected(cutAction
, i18nc("@action", "Cut…"));
1791 cutAction
->setWhatsThis(xi18nc("@info:whatsthis cut",
1792 "This copies the items "
1793 "in your current selection to the <emphasis>clipboard</emphasis>.<nl/>"
1794 "Use the <emphasis>Paste</emphasis> action afterwards to copy them from "
1795 "the clipboard to a new location. The items will be removed from their "
1796 "initial location.")
1797 + cutCopyPastePara
);
1798 QAction
*copyAction
= KStandardAction::copy(this, &DolphinMainWindow::copy
, actionCollection());
1799 m_actionTextHelper
->registerTextWhenNothingIsSelected(copyAction
, i18nc("@action", "Copy…"));
1800 copyAction
->setWhatsThis(xi18nc("@info:whatsthis copy",
1802 "items in your current selection to the <emphasis>clipboard</emphasis>."
1803 "<nl/>Use the <emphasis>Paste</emphasis> action afterwards to copy them "
1804 "from the clipboard to a new location.")
1805 + cutCopyPastePara
);
1806 QAction
*paste
= KStandardAction::paste(this, &DolphinMainWindow::paste
, actionCollection());
1807 // The text of the paste-action is modified dynamically by Dolphin
1808 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1809 // due to the long text, the text "Paste" is used:
1810 paste
->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1811 paste
->setWhatsThis(xi18nc("@info:whatsthis paste",
1812 "This copies the items from "
1813 "your <emphasis>clipboard</emphasis> to the currently viewed folder.<nl/>"
1814 "If the items were added to the clipboard by the <emphasis>Cut</emphasis> "
1815 "action they are removed from their old location.")
1816 + cutCopyPastePara
);
1818 QAction
*copyToOtherViewAction
= actionCollection()->addAction(QStringLiteral("copy_to_inactive_split_view"));
1819 copyToOtherViewAction
->setText(i18nc("@action:inmenu", "Copy to Other View"));
1820 m_actionTextHelper
->registerTextWhenNothingIsSelected(copyToOtherViewAction
, i18nc("@action:inmenu", "Copy to Other View…"));
1821 copyToOtherViewAction
->setWhatsThis(xi18nc("@info:whatsthis Copy",
1822 "This copies the selected items from "
1823 "the view in focus to the other view. "
1824 "(Only available while in Split View mode.)"));
1825 copyToOtherViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("edit-copy")));
1826 copyToOtherViewAction
->setIconText(i18nc("@action:inmenu Edit", "Copy to Other View"));
1827 actionCollection()->setDefaultShortcut(copyToOtherViewAction
, Qt::SHIFT
| Qt::Key_F5
);
1828 connect(copyToOtherViewAction
, &QAction::triggered
, this, &DolphinMainWindow::copyToInactiveSplitView
);
1830 QAction
*moveToOtherViewAction
= actionCollection()->addAction(QStringLiteral("move_to_inactive_split_view"));
1831 moveToOtherViewAction
->setText(i18nc("@action:inmenu", "Move to Other View"));
1832 m_actionTextHelper
->registerTextWhenNothingIsSelected(moveToOtherViewAction
, i18nc("@action:inmenu", "Move to Other View…"));
1833 moveToOtherViewAction
->setWhatsThis(xi18nc("@info:whatsthis Move",
1834 "This moves the selected items from "
1835 "the view in focus to the other view. "
1836 "(Only available while in Split View mode.)"));
1837 moveToOtherViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("edit-cut")));
1838 moveToOtherViewAction
->setIconText(i18nc("@action:inmenu Edit", "Move to Other View"));
1839 actionCollection()->setDefaultShortcut(moveToOtherViewAction
, Qt::SHIFT
| Qt::Key_F6
);
1840 connect(moveToOtherViewAction
, &QAction::triggered
, this, &DolphinMainWindow::moveToInactiveSplitView
);
1842 QAction
*showFilterBar
= actionCollection()->addAction(QStringLiteral("show_filter_bar"));
1843 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Filter…"));
1844 showFilterBar
->setToolTip(i18nc("@info:tooltip", "Show Filter Bar"));
1845 showFilterBar
->setWhatsThis(xi18nc("@info:whatsthis",
1847 "<emphasis>Filter Bar</emphasis> at the bottom of the window.<nl/> "
1848 "There you can enter text to filter the files and folders currently displayed. "
1849 "Only those that contain the text in their name will be kept in view."));
1850 showFilterBar
->setIcon(QIcon::fromTheme(QStringLiteral("view-filter")));
1851 actionCollection()->setDefaultShortcuts(showFilterBar
, {Qt::CTRL
| Qt::Key_I
, Qt::Key_Slash
});
1852 connect(showFilterBar
, &QAction::triggered
, this, &DolphinMainWindow::showFilterBar
);
1854 // toggle_filter acts as a copy of the main showFilterBar to be used mainly
1855 // in the toolbar, with no default shortcut attached, to avoid messing with
1856 // existing workflows (filter bar always open and Ctrl-I to focus)
1857 QAction
*toggleFilter
= actionCollection()->addAction(QStringLiteral("toggle_filter"));
1858 toggleFilter
->setText(i18nc("@action:inmenu", "Toggle Filter Bar"));
1859 toggleFilter
->setIconText(i18nc("@action:intoolbar", "Filter"));
1860 toggleFilter
->setIcon(showFilterBar
->icon());
1861 toggleFilter
->setToolTip(showFilterBar
->toolTip());
1862 toggleFilter
->setWhatsThis(showFilterBar
->whatsThis());
1863 toggleFilter
->setCheckable(true);
1864 connect(toggleFilter
, &QAction::triggered
, this, &DolphinMainWindow::toggleFilterBar
);
1866 QAction
*searchAction
= KStandardAction::find(this, &DolphinMainWindow::find
, actionCollection());
1867 searchAction
->setText(i18n("Search…"));
1868 searchAction
->setToolTip(i18nc("@info:tooltip", "Search for files and folders"));
1869 searchAction
->setWhatsThis(xi18nc("@info:whatsthis find",
1870 "<para>This helps you "
1871 "find files and folders by opening a <emphasis>search bar</emphasis>. "
1872 "There you can enter search terms and specify settings to find the "
1873 "items you are looking for.</para>"));
1875 // toggle_search acts as a copy of the main searchAction to be used mainly
1876 // in the toolbar, with no default shortcut attached, to avoid messing with
1877 // existing workflows (search bar always open and Ctrl-F to focus)
1878 QAction
*toggleSearchAction
= actionCollection()->addAction(QStringLiteral("toggle_search"));
1879 toggleSearchAction
->setText(i18nc("@action:inmenu", "Toggle Search Bar"));
1880 toggleSearchAction
->setIconText(i18nc("@action:intoolbar", "Search"));
1881 toggleSearchAction
->setIcon(searchAction
->icon());
1882 toggleSearchAction
->setToolTip(searchAction
->toolTip());
1883 toggleSearchAction
->setWhatsThis(searchAction
->whatsThis());
1884 toggleSearchAction
->setCheckable(true);
1885 connect(toggleSearchAction
, &QAction::triggered
, this, [this](bool checked
) {
1889 m_activeViewContainer
->setSearchBarVisible(false);
1893 QAction
*toggleSelectionModeAction
= actionCollection()->addAction(QStringLiteral("toggle_selection_mode"));
1894 // i18n: This action toggles a selection mode.
1895 toggleSelectionModeAction
->setText(i18nc("@action:inmenu", "Select Files and Folders"));
1896 // i18n: Opens a selection mode for selecting files/folders.
1897 // The text is kept so unspecific because it will be shown on the toolbar where space is at a premium.
1898 toggleSelectionModeAction
->setIconText(i18nc("@action:intoolbar", "Select"));
1899 toggleSelectionModeAction
->setWhatsThis(xi18nc(
1901 "<para>This application only knows which files or folders should be acted on if they are"
1902 " <emphasis>selected</emphasis> first. Press this to toggle a <emphasis>Selection Mode</emphasis> which makes selecting and deselecting as easy as "
1903 "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."
1905 toggleSelectionModeAction
->setIcon(QIcon::fromTheme(QStringLiteral("quickwizard")));
1906 toggleSelectionModeAction
->setCheckable(true);
1907 actionCollection()->setDefaultShortcut(toggleSelectionModeAction
, Qt::Key_Space
);
1908 connect(toggleSelectionModeAction
, &QAction::triggered
, this, &DolphinMainWindow::toggleSelectionMode
);
1910 // A special version of the toggleSelectionModeAction for the toolbar that also contains a menu
1911 // with the selectAllAction and invertSelectionAction.
1912 auto *toggleSelectionModeToolBarAction
=
1913 new KToolBarPopupAction(toggleSelectionModeAction
->icon(), toggleSelectionModeAction
->iconText(), actionCollection());
1914 toggleSelectionModeToolBarAction
->setToolTip(toggleSelectionModeAction
->text());
1915 toggleSelectionModeToolBarAction
->setWhatsThis(toggleSelectionModeAction
->whatsThis());
1916 actionCollection()->addAction(QStringLiteral("toggle_selection_mode_tool_bar"), toggleSelectionModeToolBarAction
);
1917 toggleSelectionModeToolBarAction
->setCheckable(true);
1918 toggleSelectionModeToolBarAction
->setPopupMode(KToolBarPopupAction::DelayedPopup
);
1919 connect(toggleSelectionModeToolBarAction
, &QAction::triggered
, toggleSelectionModeAction
, &QAction::trigger
);
1920 connect(toggleSelectionModeAction
, &QAction::toggled
, toggleSelectionModeToolBarAction
, &QAction::setChecked
);
1922 QAction
*selectAllAction
= KStandardAction::selectAll(this, &DolphinMainWindow::selectAll
, actionCollection());
1923 selectAllAction
->setWhatsThis(xi18nc("@info:whatsthis",
1925 "files and folders in the current location."));
1927 QAction
*invertSelection
= actionCollection()->addAction(QStringLiteral("invert_selection"));
1928 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1929 invertSelection
->setWhatsThis(xi18nc("@info:whatsthis invert",
1931 "items that you have currently <emphasis>not</emphasis> selected instead."));
1932 invertSelection
->setIcon(QIcon::fromTheme(QStringLiteral("edit-select-invert")));
1933 actionCollection()->setDefaultShortcut(invertSelection
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
1934 connect(invertSelection
, &QAction::triggered
, this, &DolphinMainWindow::invertSelection
);
1936 QMenu
*toggleSelectionModeActionMenu
= new QMenu(this);
1937 toggleSelectionModeActionMenu
->addAction(selectAllAction
);
1938 toggleSelectionModeActionMenu
->addAction(invertSelection
);
1939 toggleSelectionModeToolBarAction
->setMenu(toggleSelectionModeActionMenu
);
1941 // setup 'View' menu
1942 // (note that most of it is set up in DolphinViewActionHandler)
1944 Admin::WorkerIntegration::createActAsAdminAction(actionCollection(), this);
1946 m_splitViewAction
= actionCollection()->add
<KActionMenu
>(QStringLiteral("split_view"));
1947 m_splitViewMenuAction
= actionCollection()->addAction(QStringLiteral("split_view_menu"));
1949 m_splitViewAction
->setWhatsThis(xi18nc("@info:whatsthis split",
1950 "<para>This presents "
1951 "a second view side-by-side with the current view, so you can see "
1952 "the contents of two folders at once and easily move items between "
1953 "them.</para><para>The view that is not \"in focus\" will be dimmed. "
1954 "</para>Click this button again to close one of the views."));
1955 m_splitViewMenuAction
->setWhatsThis(m_splitViewAction
->whatsThis());
1957 // only set it for the menu version
1958 actionCollection()->setDefaultShortcut(m_splitViewMenuAction
, Qt::Key_F3
);
1960 connect(m_splitViewAction
, &QAction::triggered
, this, &DolphinMainWindow::toggleSplitView
);
1961 connect(m_splitViewMenuAction
, &QAction::triggered
, this, &DolphinMainWindow::toggleSplitView
);
1963 QAction
*popoutSplit
= actionCollection()->addAction(QStringLiteral("popout_split_view"));
1964 popoutSplit
->setWhatsThis(xi18nc("@info:whatsthis",
1965 "If the view has been split, this will pop the view in focus "
1966 "out into a new window."));
1967 popoutSplit
->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
1968 actionCollection()->setDefaultShortcut(popoutSplit
, Qt::SHIFT
| Qt::Key_F3
);
1969 connect(popoutSplit
, &QAction::triggered
, this, &DolphinMainWindow::popoutSplitView
);
1971 QAction
*stashSplit
= actionCollection()->addAction(QStringLiteral("split_stash"));
1972 actionCollection()->setDefaultShortcut(stashSplit
, Qt::CTRL
| Qt::Key_S
);
1973 stashSplit
->setText(i18nc("@action:intoolbar Stash", "Stash"));
1974 stashSplit
->setToolTip(i18nc("@info", "Opens the stash virtual directory in a split window"));
1975 stashSplit
->setIcon(QIcon::fromTheme(QStringLiteral("folder-stash")));
1976 stashSplit
->setCheckable(false);
1977 QDBusConnectionInterface
*sessionInterface
= QDBusConnection::sessionBus().interface();
1978 stashSplit
->setVisible(sessionInterface
&& sessionInterface
->isServiceRegistered(QStringLiteral("org.kde.kio.StashNotifier")));
1979 connect(stashSplit
, &QAction::triggered
, this, &DolphinMainWindow::toggleSplitStash
);
1981 QAction
*redisplay
= KStandardAction::redisplay(this, &DolphinMainWindow::reloadView
, actionCollection());
1982 redisplay
->setToolTip(i18nc("@info:tooltip", "Refresh view"));
1983 redisplay
->setWhatsThis(xi18nc("@info:whatsthis refresh",
1984 "<para>This refreshes "
1985 "the folder view.</para>"
1986 "<para>If the contents of this folder have changed, refreshing will re-scan this folder "
1987 "and show you a newly-updated view of the files and folders contained here.</para>"
1988 "<para>If the view is split, this refreshes the one that is currently in focus.</para>"));
1990 QAction
*stop
= actionCollection()->addAction(QStringLiteral("stop"));
1991 stop
->setText(i18nc("@action:inmenu View", "Stop"));
1992 stop
->setToolTip(i18nc("@info", "Stop loading"));
1993 stop
->setWhatsThis(i18nc("@info", "This stops the loading of the contents of the current folder."));
1994 stop
->setIcon(QIcon::fromTheme(QStringLiteral("process-stop")));
1995 connect(stop
, &QAction::triggered
, this, &DolphinMainWindow::stopLoading
);
1997 KToggleAction
*editableLocation
= actionCollection()->add
<KToggleAction
>(QStringLiteral("editable_location"));
1998 editableLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1999 editableLocation
->setWhatsThis(xi18nc("@info:whatsthis",
2000 "This toggles the <emphasis>Location Bar</emphasis> to be "
2001 "editable so you can directly enter a location you want to go to.<nl/>"
2002 "You can also switch to editing by clicking to the right of the "
2003 "location and switch back by confirming the edited location."));
2004 actionCollection()->setDefaultShortcut(editableLocation
, Qt::Key_F6
);
2005 connect(editableLocation
, &KToggleAction::triggered
, this, &DolphinMainWindow::toggleEditLocation
);
2007 QAction
*replaceLocation
= actionCollection()->addAction(QStringLiteral("replace_location"));
2008 replaceLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
2009 // i18n: "enter" is used both in the meaning of "writing" and "going to" a new location here.
2010 // Both meanings are useful but not necessary to understand the use of "Replace Location".
2011 // So you might want to be more verbose in your language to convey the meaning but it's up to you.
2012 replaceLocation
->setWhatsThis(xi18nc("@info:whatsthis",
2013 "This switches to editing the location and selects it "
2014 "so you can quickly enter a different location."));
2015 actionCollection()->setDefaultShortcuts(replaceLocation
, {Qt::CTRL
| Qt::Key_L
, Qt::ALT
| Qt::Key_D
});
2016 connect(replaceLocation
, &QAction::triggered
, this, &DolphinMainWindow::replaceLocation
);
2020 QScopedPointer
<QAction
> backAction(KStandardAction::back(nullptr, nullptr, nullptr));
2021 m_backAction
= new KToolBarPopupAction(backAction
->icon(), backAction
->text(), actionCollection());
2022 m_backAction
->setObjectName(backAction
->objectName());
2023 m_backAction
->setShortcuts(backAction
->shortcuts());
2025 m_backAction
->setPopupMode(KToolBarPopupAction::DelayedPopup
);
2026 connect(m_backAction
, &QAction::triggered
, this, &DolphinMainWindow::goBack
);
2027 connect(m_backAction
->popupMenu(), &QMenu::aboutToShow
, this, &DolphinMainWindow::slotAboutToShowBackPopupMenu
);
2028 connect(m_backAction
->popupMenu(), &QMenu::triggered
, this, &DolphinMainWindow::slotGoBack
);
2029 actionCollection()->addAction(m_backAction
->objectName(), m_backAction
);
2031 auto backShortcuts
= m_backAction
->shortcuts();
2032 // Prepend this shortcut, to avoid being hidden by the two-slot UI (#371130)
2033 backShortcuts
.prepend(QKeySequence(Qt::Key_Backspace
));
2034 actionCollection()->setDefaultShortcuts(m_backAction
, backShortcuts
);
2036 DolphinRecentTabsMenu
*recentTabsMenu
= new DolphinRecentTabsMenu(this);
2037 actionCollection()->addAction(QStringLiteral("closed_tabs"), recentTabsMenu
);
2038 connect(m_tabWidget
, &DolphinTabWidget::rememberClosedTab
, recentTabsMenu
, &DolphinRecentTabsMenu::rememberClosedTab
);
2039 connect(recentTabsMenu
, &DolphinRecentTabsMenu::restoreClosedTab
, m_tabWidget
, &DolphinTabWidget::restoreClosedTab
);
2040 connect(recentTabsMenu
, &DolphinRecentTabsMenu::closedTabsCountChanged
, this, &DolphinMainWindow::closedTabsCountChanged
);
2042 QAction
*undoCloseTab
= actionCollection()->addAction(QStringLiteral("undo_close_tab"));
2043 undoCloseTab
->setText(i18nc("@action:inmenu File", "Undo close tab"));
2044 undoCloseTab
->setWhatsThis(i18nc("@info:whatsthis undo close tab", "This returns you to the previously closed tab."));
2045 actionCollection()->setDefaultShortcut(undoCloseTab
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_T
);
2046 undoCloseTab
->setIcon(QIcon::fromTheme(QStringLiteral("edit-undo")));
2047 undoCloseTab
->setEnabled(false);
2048 connect(undoCloseTab
, &QAction::triggered
, recentTabsMenu
, &DolphinRecentTabsMenu::undoCloseTab
);
2050 auto undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
2051 undoAction
->setWhatsThis(xi18nc("@info:whatsthis",
2053 "the last change you made to files or folders.<nl/>"
2054 "Such changes include <interface>creating</interface>, <interface>renaming</interface> "
2055 "and <interface>moving</interface> them to a different location "
2056 "or to the <filename>Trash</filename>. <nl/>Any changes that cannot be undone "
2057 "will ask for your confirmation beforehand."));
2058 undoAction
->setEnabled(false); // undo should be disabled by default
2061 QScopedPointer
<QAction
> forwardAction(KStandardAction::forward(nullptr, nullptr, nullptr));
2062 m_forwardAction
= new KToolBarPopupAction(forwardAction
->icon(), forwardAction
->text(), actionCollection());
2063 m_forwardAction
->setObjectName(forwardAction
->objectName());
2064 m_forwardAction
->setShortcuts(forwardAction
->shortcuts());
2066 m_forwardAction
->setPopupMode(KToolBarPopupAction::DelayedPopup
);
2067 connect(m_forwardAction
, &QAction::triggered
, this, &DolphinMainWindow::goForward
);
2068 connect(m_forwardAction
->popupMenu(), &QMenu::aboutToShow
, this, &DolphinMainWindow::slotAboutToShowForwardPopupMenu
);
2069 connect(m_forwardAction
->popupMenu(), &QMenu::triggered
, this, &DolphinMainWindow::slotGoForward
);
2070 actionCollection()->addAction(m_forwardAction
->objectName(), m_forwardAction
);
2071 actionCollection()->setDefaultShortcuts(m_forwardAction
, m_forwardAction
->shortcuts());
2073 // enable middle-click to open in a new tab
2074 auto *middleClickEventFilter
= new MiddleClickActionEventFilter(this);
2075 connect(middleClickEventFilter
, &MiddleClickActionEventFilter::actionMiddleClicked
, this, &DolphinMainWindow::slotBackForwardActionMiddleClicked
);
2076 m_backAction
->popupMenu()->installEventFilter(middleClickEventFilter
);
2077 m_forwardAction
->popupMenu()->installEventFilter(middleClickEventFilter
);
2078 KStandardAction::up(this, &DolphinMainWindow::goUp
, actionCollection());
2079 QAction
*homeAction
= KStandardAction::home(this, &DolphinMainWindow::goHome
, actionCollection());
2080 homeAction
->setWhatsThis(xi18nc("@info:whatsthis",
2082 "<filename>Home</filename> folder.<nl/>Every user account "
2083 "has their own <filename>Home</filename> that contains their personal files, "
2084 "as well as hidden folders for their applications' data and configuration files."));
2086 // setup 'Tools' menu
2087 QAction
*compareFiles
= actionCollection()->addAction(QStringLiteral("compare_files"));
2088 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
2089 compareFiles
->setIcon(QIcon::fromTheme(QStringLiteral("kompare")));
2090 compareFiles
->setEnabled(false);
2091 connect(compareFiles
, &QAction::triggered
, this, &DolphinMainWindow::compareFiles
);
2093 QAction
*openPreferredSearchTool
= actionCollection()->addAction(QStringLiteral("open_preferred_search_tool"));
2094 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool"));
2095 openPreferredSearchTool
->setWhatsThis(xi18nc("@info:whatsthis",
2096 "<para>This opens a preferred search tool for the viewed location.</para>"
2097 "<para>Use <emphasis>More Search Tools</emphasis> menu to configure it.</para>"));
2098 openPreferredSearchTool
->setIcon(QIcon::fromTheme(QStringLiteral("search")));
2099 actionCollection()->setDefaultShortcut(openPreferredSearchTool
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_F
);
2100 connect(openPreferredSearchTool
, &QAction::triggered
, this, &DolphinMainWindow::openPreferredSearchTool
);
2102 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
2103 // Get icon of user default terminal emulator application
2104 const KConfigGroup
group(KSharedConfig::openConfig(QStringLiteral("kdeglobals"), KConfig::SimpleConfig
), QStringLiteral("General"));
2105 const QString terminalDesktopFilename
= group
.readEntry("TerminalService");
2106 // Use utilities-terminal icon from theme if readEntry() has failed
2107 const QString terminalIcon
= terminalDesktopFilename
.isEmpty() ? "utilities-terminal" : KDesktopFile(terminalDesktopFilename
).readIcon();
2109 QAction
*openTerminal
= actionCollection()->addAction(QStringLiteral("open_terminal"));
2110 openTerminal
->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
2111 openTerminal
->setWhatsThis(xi18nc("@info:whatsthis",
2112 "<para>This opens a <emphasis>terminal</emphasis> application for the viewed location.</para>"
2113 "<para>To learn more about terminals use the help features in the terminal application.</para>"));
2114 openTerminal
->setIcon(QIcon::fromTheme(terminalIcon
));
2115 actionCollection()->setDefaultShortcut(openTerminal
, Qt::SHIFT
| Qt::Key_F4
);
2116 connect(openTerminal
, &QAction::triggered
, this, &DolphinMainWindow::openTerminal
);
2118 QAction
*openTerminalHere
= actionCollection()->addAction(QStringLiteral("open_terminal_here"));
2119 // i18n: "Here" refers to the location(s) of the currently selected item(s) or the currently viewed location if nothing is selected.
2120 openTerminalHere
->setText(i18nc("@action:inmenu Tools", "Open Terminal Here"));
2121 openTerminalHere
->setWhatsThis(xi18nc("@info:whatsthis",
2122 "<para>This opens <emphasis>terminal</emphasis> applications for the selected items' locations.</para>"
2123 "<para>To learn more about terminals use the help features in the terminal application.</para>"));
2124 openTerminalHere
->setIcon(QIcon::fromTheme(terminalIcon
));
2125 actionCollection()->setDefaultShortcut(openTerminalHere
, Qt::SHIFT
| Qt::ALT
| Qt::Key_F4
);
2126 connect(openTerminalHere
, &QAction::triggered
, this, &DolphinMainWindow::openTerminalHere
);
2129 // setup 'Bookmarks' menu
2130 KActionMenu
*bookmarkMenu
= new KActionMenu(i18nc("@title:menu", "&Bookmarks"), this);
2131 bookmarkMenu
->setIcon(QIcon::fromTheme(QStringLiteral("bookmarks")));
2132 // Make the toolbar button version work properly on click
2133 bookmarkMenu
->setPopupMode(QToolButton::InstantPopup
);
2134 m_bookmarkHandler
= new DolphinBookmarkHandler(this, actionCollection(), bookmarkMenu
->menu(), this);
2135 actionCollection()->addAction(QStringLiteral("bookmarks"), bookmarkMenu
);
2137 // setup 'Settings' menu
2138 KToggleAction
*showMenuBar
= KStandardAction::showMenubar(nullptr, nullptr, actionCollection());
2139 showMenuBar
->setWhatsThis(xi18nc("@info:whatsthis",
2140 "<para>This switches between having a <emphasis>Menubar</emphasis> "
2141 "and having an <interface>%1</interface> button. Both "
2142 "contain mostly the same actions and configuration options.</para>"
2143 "<para>The Menubar takes up more space but allows for fast and organized access to all "
2144 "actions an application has to offer.</para><para>The %1 button "
2145 "is simpler and small which makes triggering advanced actions more time consuming.</para>",
2146 hamburgerMenuAction
->text().replace('&', "")));
2147 connect(showMenuBar
,
2148 &KToggleAction::triggered
, // Fixes #286822
2150 &DolphinMainWindow::toggleShowMenuBar
,
2151 Qt::QueuedConnection
);
2153 KStandardAction::keyBindings(this, &DolphinMainWindow::slotKeyBindings
, actionCollection());
2154 KStandardAction::preferences(this, &DolphinMainWindow::editSettings
, actionCollection());
2156 // not in menu actions
2157 QList
<QKeySequence
> nextTabKeys
= KStandardShortcut::tabNext();
2158 nextTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::Key_Tab
));
2160 QList
<QKeySequence
> prevTabKeys
= KStandardShortcut::tabPrev();
2161 prevTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::SHIFT
| Qt::Key_Tab
));
2163 for (int i
= 0; i
< MaxActivateTabShortcuts
; ++i
) {
2164 QAction
*activateTab
= actionCollection()->addAction(QStringLiteral("activate_tab_%1").arg(i
));
2165 activateTab
->setText(i18nc("@action:inmenu", "Go to Tab %1", i
+ 1));
2166 activateTab
->setEnabled(false);
2167 connect(activateTab
, &QAction::triggered
, this, [this, i
]() {
2168 m_tabWidget
->activateTab(i
);
2171 // only add default shortcuts for the first 9 tabs regardless of MaxActivateTabShortcuts
2173 actionCollection()->setDefaultShortcut(activateTab
, QStringLiteral("Alt+%1").arg(i
+ 1));
2177 QAction
*activateLastTab
= actionCollection()->addAction(QStringLiteral("activate_last_tab"));
2178 activateLastTab
->setIconText(i18nc("@action:inmenu", "Last Tab"));
2179 activateLastTab
->setText(i18nc("@action:inmenu", "Go to Last Tab"));
2180 activateLastTab
->setEnabled(false);
2181 connect(activateLastTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activateLastTab
);
2182 actionCollection()->setDefaultShortcut(activateLastTab
, Qt::ALT
| Qt::Key_0
);
2184 QAction
*activateNextTab
= actionCollection()->addAction(QStringLiteral("activate_next_tab"));
2185 activateNextTab
->setIconText(i18nc("@action:inmenu", "Next Tab"));
2186 activateNextTab
->setText(i18nc("@action:inmenu", "Go to Next Tab"));
2187 activateNextTab
->setEnabled(false);
2188 connect(activateNextTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activateNextTab
);
2189 actionCollection()->setDefaultShortcuts(activateNextTab
, nextTabKeys
);
2191 QAction
*activatePrevTab
= actionCollection()->addAction(QStringLiteral("activate_prev_tab"));
2192 activatePrevTab
->setIconText(i18nc("@action:inmenu", "Previous Tab"));
2193 activatePrevTab
->setText(i18nc("@action:inmenu", "Go to Previous Tab"));
2194 activatePrevTab
->setEnabled(false);
2195 connect(activatePrevTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activatePrevTab
);
2196 actionCollection()->setDefaultShortcuts(activatePrevTab
, prevTabKeys
);
2199 QAction
*showTarget
= actionCollection()->addAction(QStringLiteral("show_target"));
2200 showTarget
->setText(i18nc("@action:inmenu", "Show Target"));
2201 showTarget
->setIcon(QIcon::fromTheme(QStringLiteral("document-open-folder")));
2202 showTarget
->setEnabled(false);
2203 connect(showTarget
, &QAction::triggered
, this, &DolphinMainWindow::showTarget
);
2205 QAction
*openInNewTab
= actionCollection()->addAction(QStringLiteral("open_in_new_tab"));
2206 openInNewTab
->setText(i18nc("@action:inmenu", "Open in New Tab"));
2207 openInNewTab
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
2208 connect(openInNewTab
, &QAction::triggered
, this, &DolphinMainWindow::openInNewTab
);
2210 QAction
*openInNewTabs
= actionCollection()->addAction(QStringLiteral("open_in_new_tabs"));
2211 openInNewTabs
->setText(i18nc("@action:inmenu", "Open in New Tabs"));
2212 openInNewTabs
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
2213 connect(openInNewTabs
, &QAction::triggered
, this, &DolphinMainWindow::openInNewTab
);
2215 QAction
*openInNewWindow
= actionCollection()->addAction(QStringLiteral("open_in_new_window"));
2216 openInNewWindow
->setText(i18nc("@action:inmenu", "Open in New Window"));
2217 openInNewWindow
->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
2218 connect(openInNewWindow
, &QAction::triggered
, this, &DolphinMainWindow::openInNewWindow
);
2220 QAction
*openInSplitViewAction
= actionCollection()->addAction(QStringLiteral("open_in_split_view"));
2221 openInSplitViewAction
->setText(i18nc("@action:inmenu", "Open in Split View"));
2222 openInSplitViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-split-left-right")));
2223 connect(openInSplitViewAction
, &QAction::triggered
, this, [this]() {
2224 openInSplitView(QUrl());
2227 m_recentFiles
= new KRecentFilesAction(this);
2230 void DolphinMainWindow::setupDockWidgets()
2232 const bool lock
= GeneralSettings::lockPanels();
2234 DolphinPlacesModelSingleton::instance().placesModel()->setPanelsLocked(lock
);
2236 KDualAction
*lockLayoutAction
= actionCollection()->add
<KDualAction
>(QStringLiteral("lock_panels"));
2237 lockLayoutAction
->setActiveText(i18nc("@action:inmenu Panels", "Unlock Panels"));
2238 lockLayoutAction
->setActiveIcon(QIcon::fromTheme(QStringLiteral("object-unlocked")));
2239 lockLayoutAction
->setInactiveText(i18nc("@action:inmenu Panels", "Lock Panels"));
2240 lockLayoutAction
->setInactiveIcon(QIcon::fromTheme(QStringLiteral("object-locked")));
2241 lockLayoutAction
->setWhatsThis(xi18nc("@info:whatsthis",
2243 "switches between having panels <emphasis>locked</emphasis> or "
2244 "<emphasis>unlocked</emphasis>.<nl/>Unlocked panels can be "
2245 "dragged to the other side of the window and have a close "
2246 "button.<nl/>Locked panels are embedded more cleanly."));
2247 lockLayoutAction
->setActive(lock
);
2248 connect(lockLayoutAction
, &KDualAction::triggered
, this, &DolphinMainWindow::togglePanelLockState
);
2250 // Setup "Information"
2251 DolphinDockWidget
*infoDock
= new DolphinDockWidget(i18nc("@title:window", "Information"));
2252 infoDock
->setLocked(lock
);
2253 infoDock
->setObjectName(QStringLiteral("infoDock"));
2254 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
2257 InformationPanel
*infoPanel
= new InformationPanel(infoDock
);
2258 infoPanel
->setCustomContextMenuActions({lockLayoutAction
});
2259 connect(infoPanel
, &InformationPanel::urlActivated
, this, &DolphinMainWindow::handleUrl
);
2260 infoDock
->setWidget(infoPanel
);
2262 createPanelAction(QIcon::fromTheme(QStringLiteral("documentinfo")), Qt::Key_F11
, infoDock
, QStringLiteral("show_information_panel"));
2264 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
2265 connect(this, &DolphinMainWindow::urlChanged
, infoPanel
, &InformationPanel::setUrl
);
2266 connect(this, &DolphinMainWindow::selectionChanged
, infoPanel
, &InformationPanel::setSelection
);
2267 connect(this, &DolphinMainWindow::requestItemInfo
, infoPanel
, &InformationPanel::requestDelayedItemInfo
);
2268 connect(this, &DolphinMainWindow::fileItemsChanged
, infoPanel
, &InformationPanel::slotFilesItemChanged
);
2269 connect(this, &DolphinMainWindow::settingsChanged
, infoPanel
, &InformationPanel::readSettings
);
2272 // i18n: This is the last paragraph for the "What's This"-texts of all four panels.
2273 const QString panelWhatsThis
= xi18nc("@info:whatsthis",
2275 "hide panels like this go to <interface>Menu|Panels</interface> "
2276 "or <interface>View|Panels</interface>.</para>");
2279 ->action(QStringLiteral("show_information_panel"))
2280 ->setWhatsThis(xi18nc("@info:whatsthis",
2281 "<para> This toggles the "
2282 "<emphasis>information</emphasis> panel at the right side of the "
2283 "window.</para><para>The panel provides in-depth information "
2284 "about the items your mouse is hovering over or about the selected "
2285 "items. Otherwise it informs you about the currently viewed folder.<nl/>"
2286 "For single items a preview of their contents is provided.</para>"));
2288 infoDock
->setWhatsThis(xi18nc("@info:whatsthis",
2290 "provides in-depth information about the items your mouse is "
2291 "hovering over or about the selected items. Otherwise it informs "
2292 "you about the currently viewed folder.<nl/>For single items a "
2293 "preview of their contents is provided.</para><para>You can configure "
2294 "which and how details are given here by right-clicking.</para>")
2298 DolphinDockWidget
*foldersDock
= new DolphinDockWidget(i18nc("@title:window", "Folders"));
2299 foldersDock
->setLocked(lock
);
2300 foldersDock
->setObjectName(QStringLiteral("foldersDock"));
2301 foldersDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
2302 FoldersPanel
*foldersPanel
= new FoldersPanel(foldersDock
);
2303 foldersPanel
->setCustomContextMenuActions({lockLayoutAction
});
2304 foldersDock
->setWidget(foldersPanel
);
2306 createPanelAction(QIcon::fromTheme(QStringLiteral("folder")), Qt::Key_F7
, foldersDock
, QStringLiteral("show_folders_panel"));
2308 addDockWidget(Qt::LeftDockWidgetArea
, foldersDock
);
2309 connect(this, &DolphinMainWindow::urlChanged
, foldersPanel
, &FoldersPanel::setUrl
);
2310 connect(foldersPanel
, &FoldersPanel::folderActivated
, this, &DolphinMainWindow::changeUrl
);
2311 connect(foldersPanel
, &FoldersPanel::folderInNewTab
, this, &DolphinMainWindow::openNewTab
);
2312 connect(foldersPanel
, &FoldersPanel::folderInNewActiveTab
, this, &DolphinMainWindow::openNewTabAndActivate
);
2313 connect(foldersPanel
, &FoldersPanel::errorMessage
, this, &DolphinMainWindow::showErrorMessage
);
2316 ->action(QStringLiteral("show_folders_panel"))
2317 ->setWhatsThis(xi18nc("@info:whatsthis",
2319 "<emphasis>folders</emphasis> panel at the left side of the window."
2320 "<nl/><nl/>It shows the folders of the <emphasis>file system"
2321 "</emphasis> in a <emphasis>tree view</emphasis>."));
2322 foldersDock
->setWhatsThis(xi18nc("@info:whatsthis",
2324 "shows the folders of the <emphasis>file system</emphasis> in a "
2325 "<emphasis>tree view</emphasis>.</para><para>Click a folder to go "
2326 "there. Click the arrow to the left of a folder to see its subfolders. "
2327 "This allows quick switching between any folders.</para>")
2332 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
2333 DolphinDockWidget
*terminalDock
= new DolphinDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
2334 terminalDock
->setLocked(lock
);
2335 terminalDock
->setObjectName(QStringLiteral("terminalDock"));
2336 terminalDock
->setContentsMargins(0, 0, 0, 0);
2337 m_terminalPanel
= new TerminalPanel(terminalDock
);
2338 m_terminalPanel
->setCustomContextMenuActions({lockLayoutAction
});
2339 terminalDock
->setWidget(m_terminalPanel
);
2341 connect(m_terminalPanel
, &TerminalPanel::hideTerminalPanel
, terminalDock
, &DolphinDockWidget::hide
);
2342 connect(m_terminalPanel
, &TerminalPanel::changeUrl
, this, &DolphinMainWindow::slotTerminalDirectoryChanged
);
2343 connect(terminalDock
, &DolphinDockWidget::visibilityChanged
, m_terminalPanel
, &TerminalPanel::dockVisibilityChanged
);
2344 connect(terminalDock
, &DolphinDockWidget::visibilityChanged
, this, &DolphinMainWindow::slotTerminalPanelVisibilityChanged
);
2346 createPanelAction(QIcon::fromTheme(QStringLiteral("dialog-scripts")), Qt::Key_F4
, terminalDock
, QStringLiteral("show_terminal_panel"));
2348 addDockWidget(Qt::BottomDockWidgetArea
, terminalDock
);
2349 connect(this, &DolphinMainWindow::urlChanged
, m_terminalPanel
, &TerminalPanel::setUrl
);
2351 if (GeneralSettings::version() < 200) {
2352 terminalDock
->hide();
2356 ->action(QStringLiteral("show_terminal_panel"))
2357 ->setWhatsThis(xi18nc("@info:whatsthis",
2358 "<para>This toggles the "
2359 "<emphasis>terminal</emphasis> panel at the bottom of the window."
2360 "<nl/>The location in the terminal will always match the folder "
2361 "view so you can navigate using either.</para><para>The terminal "
2362 "panel is not needed for basic computer usage but can be useful "
2363 "for advanced tasks. To learn more about terminals use the help features "
2364 "in a standalone terminal application like Konsole.</para>"));
2365 terminalDock
->setWhatsThis(xi18nc("@info:whatsthis",
2367 "the <emphasis>terminal</emphasis> panel. It behaves like a "
2368 "normal terminal but will match the location of the folder view "
2369 "so you can navigate using either.</para><para>The terminal panel "
2370 "is not needed for basic computer usage but can be useful for "
2371 "advanced tasks. To learn more about terminals use the help features in a "
2372 "standalone terminal application like Konsole.</para>")
2375 QAction
*focusTerminalPanel
= actionCollection()->addAction(QStringLiteral("focus_terminal_panel"));
2376 focusTerminalPanel
->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
2377 focusTerminalPanel
->setToolTip(i18nc("@info:tooltip", "Move keyboard focus to and from the Terminal panel."));
2378 focusTerminalPanel
->setIcon(QIcon::fromTheme(QStringLiteral("swap-panels")));
2379 actionCollection()->setDefaultShortcut(focusTerminalPanel
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_F4
);
2380 connect(focusTerminalPanel
, &QAction::triggered
, this, &DolphinMainWindow::toggleTerminalPanelFocus
);
2381 } // endif "shell_access" allowed
2382 #endif // HAVE_TERMINAL
2384 if (GeneralSettings::version() < 200) {
2386 foldersDock
->hide();
2390 DolphinDockWidget
*placesDock
= new DolphinDockWidget(i18nc("@title:window", "Places"));
2391 placesDock
->setLocked(lock
);
2392 placesDock
->setObjectName(QStringLiteral("placesDock"));
2393 placesDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
2395 m_placesPanel
= new PlacesPanel(placesDock
);
2396 m_placesPanel
->setCustomContextMenuActions({lockLayoutAction
});
2397 placesDock
->setWidget(m_placesPanel
);
2399 createPanelAction(QIcon::fromTheme(QStringLiteral("compass")), Qt::Key_F9
, placesDock
, QStringLiteral("show_places_panel"));
2401 addDockWidget(Qt::LeftDockWidgetArea
, placesDock
);
2402 connect(m_placesPanel
, &PlacesPanel::placeActivated
, this, &DolphinMainWindow::slotPlaceActivated
);
2403 connect(m_placesPanel
, &PlacesPanel::tabRequested
, this, &DolphinMainWindow::openNewTab
);
2404 connect(m_placesPanel
, &PlacesPanel::activeTabRequested
, this, &DolphinMainWindow::openNewTabAndActivate
);
2405 connect(m_placesPanel
, &PlacesPanel::newWindowRequested
, this, [this](const QUrl
&url
) {
2406 Dolphin::openNewWindow({url
}, this);
2408 connect(m_placesPanel
, &PlacesPanel::openInSplitViewRequested
, this, &DolphinMainWindow::openInSplitView
);
2409 connect(m_placesPanel
, &PlacesPanel::errorMessage
, this, &DolphinMainWindow::showErrorMessage
);
2410 connect(this, &DolphinMainWindow::urlChanged
, m_placesPanel
, &PlacesPanel::setUrl
);
2411 connect(placesDock
, &DolphinDockWidget::visibilityChanged
, &DolphinUrlNavigatorsController::slotPlacesPanelVisibilityChanged
);
2412 connect(placesDock
, &DolphinDockWidget::visibilityChanged
, this, &DolphinMainWindow::slotPlacesPanelVisibilityChanged
);
2413 connect(this, &DolphinMainWindow::settingsChanged
, m_placesPanel
, &PlacesPanel::readSettings
);
2414 connect(m_placesPanel
, &PlacesPanel::storageTearDownRequested
, this, &DolphinMainWindow::slotStorageTearDownFromPlacesRequested
);
2415 connect(m_placesPanel
, &PlacesPanel::storageTearDownExternallyRequested
, this, &DolphinMainWindow::slotStorageTearDownExternallyRequested
);
2416 DolphinUrlNavigatorsController::slotPlacesPanelVisibilityChanged(m_placesPanel
->isVisible());
2418 auto actionShowAllPlaces
= new QAction(QIcon::fromTheme(QStringLiteral("view-hidden")), i18nc("@item:inmenu", "Show Hidden Places"), this);
2419 actionShowAllPlaces
->setCheckable(true);
2420 actionShowAllPlaces
->setDisabled(true);
2421 actionShowAllPlaces
->setWhatsThis(i18nc("@info:whatsthis",
2423 "all places in the places panel that have been hidden. They will "
2424 "appear semi-transparent and allow you to uncheck their \"Hide\" property."));
2426 connect(actionShowAllPlaces
, &QAction::triggered
, this, [this](bool checked
) {
2427 m_placesPanel
->setShowAll(checked
);
2429 connect(m_placesPanel
, &PlacesPanel::allPlacesShownChanged
, actionShowAllPlaces
, &QAction::setChecked
);
2432 ->action(QStringLiteral("show_places_panel"))
2433 ->setWhatsThis(xi18nc("@info:whatsthis",
2434 "<para>This toggles the "
2435 "<emphasis>places</emphasis> panel at the left side of the window."
2436 "</para><para>It allows you to go to locations you have "
2437 "bookmarked and to access disk or media attached to the computer "
2438 "or to the network. It also contains sections to find recently "
2439 "saved files or files of a certain type.</para>"));
2440 placesDock
->setWhatsThis(xi18nc("@info:whatsthis",
2441 "<para>This is the "
2442 "<emphasis>Places</emphasis> panel. It allows you to go to locations "
2443 "you have bookmarked and to access disk or media attached to the "
2444 "computer or to the network. It also contains sections to find "
2445 "recently saved files or files of a certain type.</para><para>"
2446 "Click on an entry to go there. Click with the right mouse button "
2447 "instead to open any entry in a new tab or new window.</para>"
2448 "<para>New entries can be added by dragging folders onto this panel. "
2449 "Right-click any section or entry to hide it. Right-click an empty "
2450 "space on this panel and select <interface>Show Hidden Places"
2451 "</interface> to display it again.</para>")
2454 QAction
*focusPlacesPanel
= actionCollection()->addAction(QStringLiteral("focus_places_panel"));
2455 focusPlacesPanel
->setText(i18nc("@action:inmenu View", "Focus Places Panel"));
2456 focusPlacesPanel
->setToolTip(i18nc("@info:tooltip", "Move keyboard focus to and from the Places panel."));
2457 focusPlacesPanel
->setIcon(QIcon::fromTheme(QStringLiteral("swap-panels")));
2458 actionCollection()->setDefaultShortcut(focusPlacesPanel
, Qt::CTRL
| Qt::Key_P
);
2459 connect(focusPlacesPanel
, &QAction::triggered
, this, &DolphinMainWindow::togglePlacesPanelFocus
);
2461 // Add actions into the "Panels" menu
2462 KActionMenu
*panelsMenu
= new KActionMenu(i18nc("@action:inmenu View", "Show Panels"), this);
2463 actionCollection()->addAction(QStringLiteral("panels"), panelsMenu
);
2464 panelsMenu
->setIcon(QIcon::fromTheme(QStringLiteral("view-sidetree")));
2465 panelsMenu
->setPopupMode(QToolButton::InstantPopup
);
2466 const KActionCollection
*ac
= actionCollection();
2467 panelsMenu
->addAction(ac
->action(QStringLiteral("show_places_panel")));
2469 panelsMenu
->addAction(ac
->action(QStringLiteral("show_information_panel")));
2471 panelsMenu
->addAction(ac
->action(QStringLiteral("show_folders_panel")));
2472 panelsMenu
->addAction(ac
->action(QStringLiteral("show_terminal_panel")));
2473 panelsMenu
->addSeparator();
2474 panelsMenu
->addAction(lockLayoutAction
);
2475 panelsMenu
->addSeparator();
2476 panelsMenu
->addAction(actionShowAllPlaces
);
2477 panelsMenu
->addAction(focusPlacesPanel
);
2478 panelsMenu
->addAction(ac
->action(QStringLiteral("focus_terminal_panel")));
2480 connect(panelsMenu
->menu(), &QMenu::aboutToShow
, this, [actionShowAllPlaces
] {
2481 actionShowAllPlaces
->setEnabled(DolphinPlacesModelSingleton::instance().placesModel()->hiddenCount());
2485 void DolphinMainWindow::updateFileAndEditActions()
2487 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
2488 const KActionCollection
*col
= actionCollection();
2489 KFileItemListProperties
capabilitiesSource(list
);
2491 QAction
*renameAction
= col
->action(KStandardAction::name(KStandardAction::RenameFile
));
2492 QAction
*moveToTrashAction
= col
->action(KStandardAction::name(KStandardAction::MoveToTrash
));
2493 QAction
*deleteAction
= col
->action(KStandardAction::name(KStandardAction::DeleteFile
));
2494 QAction
*cutAction
= col
->action(KStandardAction::name(KStandardAction::Cut
));
2495 QAction
*duplicateAction
= col
->action(QStringLiteral("duplicate")); // see DolphinViewActionHandler
2496 QAction
*addToPlacesAction
= col
->action(QStringLiteral("add_to_places"));
2497 QAction
*copyToOtherViewAction
= col
->action(QStringLiteral("copy_to_inactive_split_view"));
2498 QAction
*moveToOtherViewAction
= col
->action(QStringLiteral("move_to_inactive_split_view"));
2499 QAction
*copyLocation
= col
->action(QStringLiteral("copy_location"));
2501 if (list
.isEmpty()) {
2502 stateChanged(QStringLiteral("has_no_selection"));
2504 // All actions that need a selection to function can be enabled because they should trigger selection mode.
2505 renameAction
->setEnabled(true);
2506 moveToTrashAction
->setEnabled(true);
2507 deleteAction
->setEnabled(true);
2508 cutAction
->setEnabled(true);
2509 duplicateAction
->setEnabled(true);
2510 addToPlacesAction
->setEnabled(true);
2511 copyLocation
->setEnabled(true);
2512 // Them triggering selection mode and not directly acting on selected items is signified by adding "…" to their text.
2513 m_actionTextHelper
->textsWhenNothingIsSelectedEnabled(true);
2516 m_actionTextHelper
->textsWhenNothingIsSelectedEnabled(false);
2517 stateChanged(QStringLiteral("has_selection"));
2519 QAction
*deleteWithTrashShortcut
= col
->action(QStringLiteral("delete_shortcut")); // see DolphinViewActionHandler
2520 QAction
*showTarget
= col
->action(QStringLiteral("show_target"));
2522 if (list
.length() == 1 && list
.first().isDir()) {
2523 addToPlacesAction
->setEnabled(true);
2525 addToPlacesAction
->setEnabled(false);
2528 const bool enableMoveToTrash
= capabilitiesSource
.isLocal() && capabilitiesSource
.supportsMoving();
2530 renameAction
->setEnabled(capabilitiesSource
.supportsMoving());
2531 m_disabledActionNotifier
->setDisabledReason(renameAction
, i18nc("@info", "Cannot rename: You do not have permission to rename items in this folder."));
2532 deleteAction
->setEnabled(capabilitiesSource
.supportsDeleting());
2533 m_disabledActionNotifier
->setDisabledReason(deleteAction
,
2534 i18nc("@info", "Cannot delete: You do not have permission to remove items from this folder."));
2535 cutAction
->setEnabled(capabilitiesSource
.supportsMoving());
2536 m_disabledActionNotifier
->setDisabledReason(cutAction
, i18nc("@info", "Cannot cut: You do not have permission to move items from this folder."));
2537 copyLocation
->setEnabled(list
.length() == 1);
2538 showTarget
->setEnabled(list
.length() == 1 && list
.at(0).isLink());
2539 duplicateAction
->setEnabled(capabilitiesSource
.supportsWriting());
2540 m_disabledActionNotifier
->setDisabledReason(duplicateAction
,
2541 i18nc("@info", "Cannot duplicate here: You do not have permission to create items in this folder."));
2543 if (enableMoveToTrash
) {
2544 moveToTrashAction
->setEnabled(true);
2545 deleteWithTrashShortcut
->setEnabled(false);
2546 m_disabledActionNotifier
->clearDisabledReason(deleteWithTrashShortcut
);
2548 moveToTrashAction
->setEnabled(false);
2549 deleteWithTrashShortcut
->setEnabled(capabilitiesSource
.supportsDeleting());
2550 m_disabledActionNotifier
->setDisabledReason(deleteWithTrashShortcut
,
2551 i18nc("@info", "Cannot delete: You do not have permission to remove items from this folder."));
2555 if (!m_tabWidget
->currentTabPage()->splitViewEnabled()) {
2556 // No need to set the disabled reason here, as it's obvious to the user that the reason is the split view being disabled.
2557 copyToOtherViewAction
->setEnabled(false);
2558 m_disabledActionNotifier
->clearDisabledReason(copyToOtherViewAction
);
2559 moveToOtherViewAction
->setEnabled(false);
2560 m_disabledActionNotifier
->clearDisabledReason(moveToOtherViewAction
);
2561 } else if (list
.isEmpty()) {
2562 copyToOtherViewAction
->setEnabled(false);
2563 m_disabledActionNotifier
->setDisabledReason(copyToOtherViewAction
, i18nc("@info", "Cannot copy to other view: No files selected."));
2564 moveToOtherViewAction
->setEnabled(false);
2565 m_disabledActionNotifier
->setDisabledReason(moveToOtherViewAction
, i18nc("@info", "Cannot move to other view: No files selected."));
2567 DolphinTabPage
*tabPage
= m_tabWidget
->currentTabPage();
2568 KFileItem capabilitiesDestination
;
2570 if (tabPage
->primaryViewActive()) {
2571 capabilitiesDestination
= tabPage
->secondaryViewContainer()->rootItem();
2573 capabilitiesDestination
= tabPage
->primaryViewContainer()->rootItem();
2576 const auto destUrl
= capabilitiesDestination
.url();
2577 const bool allNotTargetOrigin
= std::all_of(list
.cbegin(), list
.cend(), [destUrl
](const KFileItem
&item
) {
2578 return item
.url().adjusted(QUrl::RemoveFilename
| QUrl::StripTrailingSlash
) != destUrl
;
2581 if (!allNotTargetOrigin
) {
2582 copyToOtherViewAction
->setEnabled(false);
2583 m_disabledActionNotifier
->setDisabledReason(copyToOtherViewAction
,
2584 i18nc("@info", "Cannot copy to other view: The other view already contains these items."));
2585 moveToOtherViewAction
->setEnabled(false);
2586 m_disabledActionNotifier
->setDisabledReason(moveToOtherViewAction
,
2587 i18nc("@info", "Cannot move to other view: The other view already contains these items."));
2588 } else if (!capabilitiesDestination
.isWritable()) {
2589 copyToOtherViewAction
->setEnabled(false);
2590 m_disabledActionNotifier
->setDisabledReason(
2591 copyToOtherViewAction
,
2592 i18nc("@info", "Cannot copy to other view: You do not have permission to write into the destination folder."));
2593 moveToOtherViewAction
->setEnabled(false);
2594 m_disabledActionNotifier
->setDisabledReason(
2595 moveToOtherViewAction
,
2596 i18nc("@info", "Cannot move to other view: You do not have permission to write into the destination folder."));
2598 copyToOtherViewAction
->setEnabled(true);
2599 moveToOtherViewAction
->setEnabled(capabilitiesSource
.supportsMoving());
2600 m_disabledActionNotifier
->setDisabledReason(
2601 moveToOtherViewAction
,
2602 i18nc("@info", "Cannot move to other view: You do not have permission to move items from this folder."));
2607 void DolphinMainWindow::updateViewActions()
2609 m_actionHandler
->updateViewActions();
2611 QAction
*toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
2612 toggleFilterBarAction
->setChecked(m_activeViewContainer
->isFilterBarVisible());
2614 updateSplitActions();
2617 void DolphinMainWindow::updateGoActions()
2619 QAction
*goUpAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Up
));
2620 const QUrl currentUrl
= m_activeViewContainer
->url();
2621 // I think this is one of the best places to firstly be confronted
2622 // with a file system and its hierarchy. Talking about the root
2623 // directory might seem too much here but it is the question that
2624 // naturally arises in this context.
2625 goUpAction
->setWhatsThis(xi18nc("@info:whatsthis",
2627 "the folder that contains the currently viewed one.</para>"
2628 "<para>All files and folders are organized in a hierarchical "
2629 "<emphasis>file system</emphasis>. At the top of this hierarchy is "
2630 "a directory that contains all data connected to this computer"
2631 "—the <emphasis>root directory</emphasis>.</para>"));
2632 goUpAction
->setEnabled(KIO::upUrl(currentUrl
) != currentUrl
);
2635 void DolphinMainWindow::refreshViews()
2637 m_tabWidget
->refreshViews();
2639 if (GeneralSettings::modifiedStartupSettings()) {
2640 updateWindowTitle();
2643 updateSplitActions();
2645 Q_EMIT
settingsChanged();
2648 void DolphinMainWindow::clearStatusBar()
2650 m_activeViewContainer
->statusBar()->resetToDefaultText();
2653 void DolphinMainWindow::connectViewSignals(DolphinViewContainer
*container
)
2655 connect(container
, &DolphinViewContainer::showFilterBarChanged
, this, &DolphinMainWindow::updateFilterBarAction
);
2656 connect(container
, &DolphinViewContainer::writeStateChanged
, this, &DolphinMainWindow::slotWriteStateChanged
);
2657 slotWriteStateChanged(container
->view()->isFolderWritable());
2658 connect(container
, &DolphinViewContainer::searchBarVisibilityChanged
, this, &DolphinMainWindow::updateSearchAction
);
2659 connect(container
, &DolphinViewContainer::captionChanged
, this, &DolphinMainWindow::updateWindowTitle
);
2660 connect(container
, &DolphinViewContainer::tabRequested
, this, &DolphinMainWindow::openNewTab
);
2661 connect(container
, &DolphinViewContainer::activeTabRequested
, this, &DolphinMainWindow::openNewTabAndActivate
);
2663 // Make the toggled state of the selection mode actions visually follow the selection mode state of the view.
2664 auto toggleSelectionModeAction
= actionCollection()->action(QStringLiteral("toggle_selection_mode"));
2665 toggleSelectionModeAction
->setChecked(m_activeViewContainer
->isSelectionModeEnabled());
2666 connect(m_activeViewContainer
, &DolphinViewContainer::selectionModeChanged
, toggleSelectionModeAction
, &QAction::setChecked
);
2668 const DolphinView
*view
= container
->view();
2669 connect(view
, &DolphinView::selectionChanged
, this, &DolphinMainWindow::slotSelectionChanged
);
2670 connect(view
, &DolphinView::requestItemInfo
, this, &DolphinMainWindow::requestItemInfo
);
2671 connect(view
, &DolphinView::fileItemsChanged
, this, &DolphinMainWindow::fileItemsChanged
);
2672 connect(view
, &DolphinView::tabRequested
, this, &DolphinMainWindow::openNewTab
);
2673 connect(view
, &DolphinView::activeTabRequested
, this, &DolphinMainWindow::openNewTabAndActivate
);
2674 connect(view
, &DolphinView::windowRequested
, this, &DolphinMainWindow::openNewWindow
);
2675 connect(view
, &DolphinView::requestContextMenu
, this, &DolphinMainWindow::openContextMenu
);
2676 connect(view
, &DolphinView::directoryLoadingStarted
, this, &DolphinMainWindow::enableStopAction
);
2677 connect(view
, &DolphinView::directoryLoadingCompleted
, this, &DolphinMainWindow::disableStopAction
);
2678 connect(view
, &DolphinView::directoryLoadingCompleted
, this, &DolphinMainWindow::slotDirectoryLoadingCompleted
);
2679 connect(view
, &DolphinView::goBackRequested
, this, &DolphinMainWindow::goBack
);
2680 connect(view
, &DolphinView::goForwardRequested
, this, &DolphinMainWindow::goForward
);
2681 connect(view
, &DolphinView::urlActivated
, this, &DolphinMainWindow::handleUrl
);
2682 connect(view
, &DolphinView::goUpRequested
, this, &DolphinMainWindow::goUp
);
2683 connect(view
, &DolphinView::doubleClickViewBackground
, this, &DolphinMainWindow::slotDoubleClickViewBackground
);
2685 connect(container
->urlNavigatorInternalWithHistory(), &KUrlNavigator::urlChanged
, this, &DolphinMainWindow::changeUrl
);
2686 connect(container
->urlNavigatorInternalWithHistory(), &KUrlNavigator::historyChanged
, this, &DolphinMainWindow::updateHistory
);
2688 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>(actionCollection()->action(QStringLiteral("url_navigators")));
2689 const KUrlNavigator
*navigator
=
2690 m_tabWidget
->currentTabPage()->primaryViewActive() ? navigators
->primaryUrlNavigator() : navigators
->secondaryUrlNavigator();
2692 QAction
*editableLocactionAction
= actionCollection()->action(QStringLiteral("editable_location"));
2693 editableLocactionAction
->setChecked(navigator
->isUrlEditable());
2694 connect(navigator
, &KUrlNavigator::editableStateChanged
, this, &DolphinMainWindow::slotEditableStateChanged
);
2695 connect(navigator
, &KUrlNavigator::tabRequested
, this, &DolphinMainWindow::openNewTab
);
2696 connect(navigator
, &KUrlNavigator::activeTabRequested
, this, &DolphinMainWindow::openNewTabAndActivate
);
2697 connect(navigator
, &KUrlNavigator::newWindowRequested
, this, &DolphinMainWindow::openNewWindow
);
2700 void DolphinMainWindow::updateSplitActions()
2702 QAction
*popoutSplitAction
= actionCollection()->action(QStringLiteral("popout_split_view"));
2704 auto setActionPopupMode
= [this](KActionMenu
*action
, QToolButton::ToolButtonPopupMode popupMode
) {
2705 action
->setPopupMode(popupMode
);
2706 if (auto *buttonForAction
= qobject_cast
<QToolButton
*>(toolBar()->widgetForAction(action
))) {
2707 buttonForAction
->setPopupMode(popupMode
);
2711 const DolphinTabPage
*tabPage
= m_tabWidget
->currentTabPage();
2712 if (tabPage
->splitViewEnabled()) {
2713 if (GeneralSettings::closeActiveSplitView() ? tabPage
->primaryViewActive() : !tabPage
->primaryViewActive()) {
2714 m_splitViewAction
->setText(i18nc("@action:intoolbar Close left view", "Close"));
2715 m_splitViewAction
->setToolTip(i18nc("@info", "Close left view"));
2716 m_splitViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-left-close")));
2717 m_splitViewMenuAction
->setText(i18nc("@action:inmenu Close left view", "Close Left View"));
2719 popoutSplitAction
->setText(i18nc("@action:intoolbar Move left view to a new window", "Pop out Left View"));
2720 popoutSplitAction
->setToolTip(i18nc("@info", "Move left view to a new window"));
2722 m_splitViewAction
->setText(i18nc("@action:intoolbar Close right view", "Close"));
2723 m_splitViewAction
->setToolTip(i18nc("@info", "Close right view"));
2724 m_splitViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-right-close")));
2725 m_splitViewMenuAction
->setText(i18nc("@action:inmenu Close left view", "Close Right View"));
2727 popoutSplitAction
->setText(i18nc("@action:intoolbar Move right view to a new window", "Pop out Right View"));
2728 popoutSplitAction
->setToolTip(i18nc("@info", "Move right view to a new window"));
2730 popoutSplitAction
->setEnabled(true);
2731 if (!m_splitViewAction
->menu()) {
2732 setActionPopupMode(m_splitViewAction
, QToolButton::MenuButtonPopup
);
2733 m_splitViewAction
->setMenu(new QMenu
);
2734 m_splitViewAction
->addAction(popoutSplitAction
);
2737 m_splitViewAction
->setText(i18nc("@action:intoolbar Split view", "Split"));
2738 m_splitViewMenuAction
->setText(m_splitViewAction
->text());
2739 m_splitViewAction
->setToolTip(i18nc("@info", "Split view"));
2740 m_splitViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-split-left-right")));
2741 popoutSplitAction
->setText(i18nc("@action:intoolbar Move view in focus to a new window", "Pop out"));
2742 popoutSplitAction
->setEnabled(false);
2743 if (m_splitViewAction
->menu()) {
2744 m_splitViewAction
->removeAction(popoutSplitAction
);
2745 m_splitViewAction
->menu()->deleteLater();
2746 m_splitViewAction
->setMenu(nullptr);
2747 setActionPopupMode(m_splitViewAction
, QToolButton::DelayedPopup
);
2751 // Update state from toolbar action
2752 m_splitViewMenuAction
->setToolTip(m_splitViewAction
->toolTip());
2753 m_splitViewMenuAction
->setIcon(m_splitViewAction
->icon());
2756 void DolphinMainWindow::updateAllowedToolbarAreas()
2758 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>(actionCollection()->action(QStringLiteral("url_navigators")));
2759 if (toolBar()->actions().contains(navigators
)) {
2760 toolBar()->setAllowedAreas(Qt::TopToolBarArea
| Qt::BottomToolBarArea
);
2761 if (toolBarArea(toolBar()) == Qt::LeftToolBarArea
|| toolBarArea(toolBar()) == Qt::RightToolBarArea
) {
2762 addToolBar(Qt::TopToolBarArea
, toolBar());
2765 toolBar()->setAllowedAreas(Qt::AllToolBarAreas
);
2769 void DolphinMainWindow::updateNavigatorsBackground()
2771 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>(actionCollection()->action(QStringLiteral("url_navigators")));
2772 navigators
->setBackgroundEnabled(navigators
->isInToolbar());
2775 bool DolphinMainWindow::isKompareInstalled() const
2777 static bool initialized
= false;
2778 static bool installed
= false;
2780 // TODO: maybe replace this approach later by using a menu
2781 // plugin like kdiff3plugin.cpp
2782 installed
= !QStandardPaths::findExecutable(QStringLiteral("kompare")).isEmpty();
2788 void DolphinMainWindow::createPanelAction(const QIcon
&icon
, const QKeySequence
&shortcut
, QDockWidget
*dockWidget
, const QString
&actionName
)
2790 auto dockAction
= dockWidget
->toggleViewAction();
2791 dockAction
->setIcon(icon
);
2792 dockAction
->setEnabled(true);
2794 QAction
*panelAction
= actionCollection()->addAction(actionName
, dockAction
);
2795 actionCollection()->setDefaultShortcut(panelAction
, shortcut
);
2798 void DolphinMainWindow::setupWhatsThis()
2801 menuBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2802 "<emphasis>Menubar</emphasis>. It provides access to commands and "
2803 "configuration options. Left-click on any of the menus on this "
2804 "bar to see its contents.</para><para>The Menubar can be hidden "
2805 "by unchecking <interface>Settings|Show Menubar</interface>. Then "
2806 "most of its contents become available through a <interface>Menu"
2807 "</interface> button on the <emphasis>Toolbar</emphasis>.</para>"));
2808 toolBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2809 "<emphasis>Toolbar</emphasis>. It allows quick access to "
2810 "frequently used actions.</para><para>It is highly customizable. "
2811 "All items you see in the <interface>Menu</interface> or "
2812 "in the <interface>Menubar</interface> can be placed on the "
2813 "Toolbar. Just right-click on it and select <interface>Configure "
2814 "Toolbars…</interface> or find this action within the <interface>"
2816 "</para><para>The location of the bar and the style of its "
2817 "buttons can also be changed in the right-click menu. Right-click "
2818 "a button if you want to show or hide its text.</para>"));
2819 m_tabWidget
->setWhatsThis(xi18nc("@info:whatsthis main view",
2820 "<para>Here you can see the <emphasis>folders</emphasis> and "
2821 "<emphasis>files</emphasis> that are at the location described in "
2822 "the <interface>Location Bar</interface> above. This area is the "
2823 "central part of this application where you navigate to the files "
2824 "you want to use.</para><para>For an elaborate and general "
2825 "introduction to this application <link "
2826 "url='https://userbase.kde.org/Dolphin/File_Management#Introduction_to_Dolphin'>"
2827 "click here</link>. This will open an introductory article from "
2828 "the <emphasis>KDE UserBase Wiki</emphasis>.</para><para>For brief "
2829 "explanations of all the features of this <emphasis>view</emphasis> "
2830 "<link url='help:/dolphin/dolphin-view.html'>click here</link> "
2831 "instead. This will open a page from the <emphasis>Handbook"
2832 "</emphasis> that covers the basics.</para>"));
2835 actionCollection()->action(KStandardAction::name(KStandardAction::KeyBindings
))
2836 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window "
2837 "that lists the <emphasis>keyboard shortcuts</emphasis>.<nl/>"
2838 "There you can set up key combinations to trigger an action when "
2839 "they are pressed simultaneously. All commands in this application can "
2840 "be triggered this way.</para>"));
2841 actionCollection()->action(KStandardAction::name(KStandardAction::ConfigureToolbars
))
2842 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window in which "
2843 "you can change which buttons appear on the <emphasis>Toolbar</emphasis>.</para>"
2844 "<para>All items you see in the <interface>Menu</interface> can also be placed on the Toolbar.</para>"));
2845 actionCollection()->action(KStandardAction::name(KStandardAction::Preferences
))
2846 ->setWhatsThis(xi18nc("@info:whatsthis","This opens a window where you can "
2847 "change a multitude of settings for this application. For an explanation "
2848 "of the various settings go to the chapter <emphasis>Configuring Dolphin"
2849 "</emphasis> in <interface>Help|Dolphin Handbook</interface>."));
2853 auto setStandardActionWhatsThis
= [this](KStandardAction::StandardAction actionId
,
2854 const QString
&whatsThis
) {
2855 // Check for the existence of an action since it can be restricted through the Kiosk system
2856 if (auto *action
= actionCollection()->action(KStandardAction::name(actionId
))) {
2857 action
->setWhatsThis(whatsThis
);
2861 // i18n: If the external link isn't available in your language it might make
2862 // sense to state the external link's language in brackets to not
2863 // frustrate the user. If there are multiple languages that the user might
2864 // know with a reasonable chance you might want to have 2 external links.
2865 // The same might be true for any external link you translate.
2866 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>"));
2867 // (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 )
2869 setStandardActionWhatsThis(KStandardAction::WhatsThis
,
2870 xi18nc("@info:whatsthis whatsthis button",
2871 "<para>This is the button that invokes the help feature you are "
2872 "using right now! Click it, then click any component of this "
2873 "application to ask \"What's this?\" about it. The mouse cursor "
2874 "will change appearance if no help is available for a spot.</para>"
2875 "<para>There are two other ways to get help: "
2876 "The <link url='help:/dolphin/index.html'>Dolphin Handbook</link> and "
2877 "the <link url='https://userbase.kde.org/Dolphin/File_Management'>KDE "
2878 "UserBase Wiki</link>.</para><para>The \"What's this?\" help is "
2879 "missing in most other windows so don't get too used to this.</para>"));
2881 setStandardActionWhatsThis(KStandardAction::ReportBug
,
2882 xi18nc("@info:whatsthis","<para>This opens a "
2883 "window that will guide you through reporting errors or flaws "
2884 "in this application or in other KDE software.</para>"
2885 "<para>High-quality bug reports are much appreciated. To learn "
2886 "how to make your bug report as effective as possible "
2887 "<link url='https://community.kde.org/Get_Involved/Bug_Reporting'>"
2888 "click here</link>.</para>"));
2890 setStandardActionWhatsThis(KStandardAction::Donate
,
2891 xi18nc("@info:whatsthis", "<para>This opens a "
2892 "<emphasis>web page</emphasis> where you can donate to "
2893 "support the continued work on this application and many "
2894 "other projects by the <emphasis>KDE</emphasis> community.</para>"
2895 "<para>Donating is the easiest and fastest way to efficiently "
2896 "support KDE and its projects. KDE projects are available for "
2897 "free therefore your donation is needed to cover things that "
2898 "require money like servers, contributor meetings, etc.</para>"
2899 "<para><emphasis>KDE e.V.</emphasis> is the non-profit "
2900 "organization behind the KDE community.</para>"));
2902 setStandardActionWhatsThis(KStandardAction::SwitchApplicationLanguage
,
2903 xi18nc("@info:whatsthis",
2904 "With this you can change the language this application uses."
2905 "<nl/>You can even set secondary languages which will be used "
2906 "if texts are not available in your preferred language."));
2908 setStandardActionWhatsThis(KStandardAction::AboutApp
,
2909 xi18nc("@info:whatsthis","This opens a "
2910 "window that informs you about the version, license, "
2911 "used libraries and maintainers of this application."));
2913 setStandardActionWhatsThis(KStandardAction::AboutKDE
,
2914 xi18nc("@info:whatsthis","This opens a "
2915 "window with information about <emphasis>KDE</emphasis>. "
2916 "The KDE community are the people behind this free software."
2917 "<nl/>If you like using this application but don't know "
2918 "about KDE or want to see a cute dragon have a look!"));
2922 bool DolphinMainWindow::addHamburgerMenuToToolbar()
2924 QDomDocument domDocument
= KXMLGUIClient::domDocument();
2925 if (domDocument
.isNull()) {
2928 QDomNode toolbar
= domDocument
.elementsByTagName(QStringLiteral("ToolBar")).at(0);
2929 if (toolbar
.isNull()) {
2933 QDomElement hamburgerMenuElement
= domDocument
.createElement(QStringLiteral("Action"));
2934 hamburgerMenuElement
.setAttribute(QStringLiteral("name"), QStringLiteral("hamburger_menu"));
2935 toolbar
.appendChild(hamburgerMenuElement
);
2937 KXMLGUIFactory::saveConfigFile(domDocument
, xmlFile());
2941 // Make sure to also remove the <KXMLGUIFactory> and <QDomDocument> include
2942 // whenever this method is removed (maybe in the year ~2026).
2945 // Set a sane initial window size
2946 QSize
DolphinMainWindow::sizeHint() const
2948 return KXmlGuiWindow::sizeHint().expandedTo(QSize(760, 550));
2951 void DolphinMainWindow::saveNewToolbarConfig()
2953 KXmlGuiWindow::saveNewToolbarConfig(); // Applies the new config. This has to be called first
2954 // because the rest of this method decides things
2955 // based on the new config.
2956 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>(actionCollection()->action(QStringLiteral("url_navigators")));
2957 if (!toolBar()->actions().contains(navigators
)) {
2958 m_tabWidget
->currentTabPage()->insertNavigatorsWidget(navigators
);
2960 updateAllowedToolbarAreas();
2961 updateNavigatorsBackground();
2962 (static_cast<KHamburgerMenu
*>(actionCollection()->action(KStandardAction::name(KStandardAction::HamburgerMenu
))))->hideActionsOf(toolBar());
2965 void DolphinMainWindow::toggleTerminalPanelFocus()
2967 if (!m_terminalPanel
->isVisible()) {
2968 actionCollection()->action(QStringLiteral("show_terminal_panel"))->trigger(); // Also moves focus to the panel.
2969 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
2973 if (m_terminalPanel
->terminalHasFocus()) {
2974 m_activeViewContainer
->view()->setFocus(Qt::FocusReason::ShortcutFocusReason
);
2975 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
2979 m_terminalPanel
->setFocus(Qt::FocusReason::ShortcutFocusReason
);
2980 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
2983 void DolphinMainWindow::togglePlacesPanelFocus()
2985 if (!m_placesPanel
->isVisible()) {
2986 actionCollection()->action(QStringLiteral("show_places_panel"))->trigger(); // Also moves focus to the panel.
2987 actionCollection()->action(QStringLiteral("focus_places_panel"))->setText(i18nc("@action:inmenu View", "Defocus Terminal Panel"));
2991 if (m_placesPanel
->hasFocus()) {
2992 m_activeViewContainer
->view()->setFocus(Qt::FocusReason::ShortcutFocusReason
);
2993 actionCollection()->action(QStringLiteral("focus_places_panel"))->setText(i18nc("@action:inmenu View", "Focus Places Panel"));
2997 m_placesPanel
->setFocus(Qt::FocusReason::ShortcutFocusReason
);
2998 actionCollection()->action(QStringLiteral("focus_places_panel"))->setText(i18nc("@action:inmenu View", "Defocus Places Panel"));
3001 DolphinMainWindow::UndoUiInterface::UndoUiInterface()
3002 : KIO::FileUndoManager::UiInterface()
3006 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
3010 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
*job
)
3012 DolphinMainWindow
*mainWin
= qobject_cast
<DolphinMainWindow
*>(parentWidget());
3014 DolphinViewContainer
*container
= mainWin
->activeViewContainer();
3015 container
->showMessage(job
->errorString(), KMessageWidget::Error
);
3017 KIO::FileUndoManager::UiInterface::jobError(job
);
3021 bool DolphinMainWindow::isUrlOpen(const QString
&url
)
3023 return m_tabWidget
->isUrlOpen(QUrl::fromUserInput(url
));
3026 bool DolphinMainWindow::isItemVisibleInAnyView(const QString
&urlOfItem
)
3028 return m_tabWidget
->isItemVisibleInAnyView(QUrl::fromUserInput(urlOfItem
));
3031 void DolphinMainWindow::slotDoubleClickViewBackground(Qt::MouseButton button
)
3033 if (button
!= Qt::MouseButton::LeftButton
) {
3034 // only handle left mouse button for now
3038 GeneralSettings
*settings
= GeneralSettings::self();
3039 QString clickAction
= settings
->doubleClickViewAction();
3041 DolphinView
*view
= activeViewContainer()->view();
3042 if (view
== nullptr || clickAction
== "none") {
3046 if (clickAction
== customCommand
) {
3047 // run custom command set by the user
3048 QString path
= view
->url().toLocalFile();
3049 QString clickCustomAction
= settings
->doubleClickViewCustomAction();
3050 clickCustomAction
.replace("{path}", path
.prepend('"').append('"'));
3052 m_job
= new KIO::CommandLauncherJob(clickCustomAction
);
3053 m_job
->setUiDelegate(new KDialogJobUiDelegate(KJobUiDelegate::AutoHandlingEnabled
, this));
3057 // get the action set by the user and trigger it
3058 const KActionCollection
*actions
= actionCollection();
3059 QAction
*action
= actions
->action(clickAction
);
3060 if (action
== nullptr) {
3061 qCWarning(DolphinDebug
) << QStringLiteral("Double-click view: action `%1` was not found").arg(clickAction
);
3068 #include "moc_dolphinmainwindow.cpp"