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);
764 auto future
= QtConcurrent::run([config
]() {
767 m_sessionSaveWatcher
->setFuture(future
);
771 void DolphinMainWindow::setSessionAutoSaveEnabled(bool enable
)
774 if (!m_sessionSaveTimer
) {
775 m_sessionSaveTimer
= new QTimer(this);
776 m_sessionSaveWatcher
= new QFutureWatcher
<void>(this);
777 m_sessionSaveTimer
->setSingleShot(true);
778 m_sessionSaveTimer
->setInterval(22000);
780 connect(m_sessionSaveTimer
, &QTimer::timeout
, this, &DolphinMainWindow::slotSaveSession
);
783 connect(m_tabWidget
, &DolphinTabWidget::urlChanged
, m_sessionSaveTimer
, qOverload
<>(&QTimer::start
), Qt::UniqueConnection
);
784 connect(m_tabWidget
, &DolphinTabWidget::tabCountChanged
, m_sessionSaveTimer
, qOverload
<>(&QTimer::start
), Qt::UniqueConnection
);
785 connect(m_tabWidget
, &DolphinTabWidget::activeViewChanged
, m_sessionSaveTimer
, qOverload
<>(&QTimer::start
), Qt::UniqueConnection
);
786 } else if (m_sessionSaveTimer
) {
787 m_sessionSaveTimer
->stop();
788 m_sessionSaveWatcher
->disconnect();
789 m_sessionSaveScheduled
= false;
791 m_sessionSaveWatcher
->waitForFinished();
793 m_sessionSaveTimer
->deleteLater();
794 m_sessionSaveWatcher
->deleteLater();
795 m_sessionSaveTimer
= nullptr;
796 m_sessionSaveWatcher
= nullptr;
800 void DolphinMainWindow::saveProperties(KConfigGroup
&group
)
802 m_tabWidget
->saveProperties(group
);
805 void DolphinMainWindow::readProperties(const KConfigGroup
&group
)
807 m_tabWidget
->readProperties(group
);
810 void DolphinMainWindow::updateNewMenu()
812 m_newFileMenu
->checkUpToDate();
813 m_newFileMenu
->setWorkingDirectory(activeViewContainer()->url());
816 void DolphinMainWindow::createDirectory()
818 // When creating directory, namejob is being run. In network folders,
819 // this job can take long time, so instead of starting multiple namejobs,
820 // just check if we are already running one. This prevents opening multiple
821 // dialogs. BUG:481401
822 if (!m_newFileMenu
->isCreateDirectoryRunning()) {
823 m_newFileMenu
->setWorkingDirectory(activeViewContainer()->url());
824 m_newFileMenu
->createDirectory();
828 void DolphinMainWindow::createFile()
830 // Use the same logic as in createDirectory()
831 if (!m_newFileMenu
->isCreateFileRunning()) {
832 m_newFileMenu
->setWorkingDirectory(activeViewContainer()->url());
833 m_newFileMenu
->createFile();
837 void DolphinMainWindow::quit()
842 void DolphinMainWindow::showErrorMessage(const QString
&message
)
844 m_activeViewContainer
->showMessage(message
, KMessageWidget::Error
);
847 void DolphinMainWindow::slotUndoAvailable(bool available
)
849 QAction
*undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
851 undoAction
->setEnabled(available
);
855 void DolphinMainWindow::slotUndoTextChanged(const QString
&text
)
857 QAction
*undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
859 undoAction
->setText(text
);
863 void DolphinMainWindow::undo()
866 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
867 KIO::FileUndoManager::self()->undo();
870 void DolphinMainWindow::cut()
872 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
873 m_activeViewContainer
->setSelectionModeEnabled(true, actionCollection(), SelectionMode::BottomBar::Contents::CutContents
);
875 m_activeViewContainer
->view()->cutSelectedItemsToClipboard();
876 m_activeViewContainer
->setSelectionModeEnabled(false);
880 void DolphinMainWindow::copy()
882 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
883 m_activeViewContainer
->setSelectionModeEnabled(true, actionCollection(), SelectionMode::BottomBar::Contents::CopyContents
);
885 m_activeViewContainer
->view()->copySelectedItemsToClipboard();
886 m_activeViewContainer
->setSelectionModeEnabled(false);
890 void DolphinMainWindow::paste()
892 m_activeViewContainer
->view()->paste();
895 void DolphinMainWindow::find()
897 m_activeViewContainer
->setSearchBarVisible(true);
898 m_activeViewContainer
->setFocusToSearchBar();
901 void DolphinMainWindow::updateSearchAction()
903 QAction
*toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
904 toggleSearchAction
->setChecked(m_activeViewContainer
->isSearchBarVisible());
907 void DolphinMainWindow::updatePasteAction()
909 QAction
*pasteAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Paste
));
910 QPair
<bool, QString
> pasteInfo
= m_activeViewContainer
->view()->pasteInfo();
911 pasteAction
->setEnabled(pasteInfo
.first
);
912 m_disabledActionNotifier
->setDisabledReason(pasteAction
,
913 m_activeViewContainer
->rootItem().isWritable()
914 ? i18nc("@info", "Cannot paste: The clipboard is empty.")
915 : i18nc("@info", "Cannot paste: You do not have permission to write into this folder."));
916 pasteAction
->setText(pasteInfo
.second
);
919 void DolphinMainWindow::slotDirectoryLoadingCompleted()
924 void DolphinMainWindow::slotToolBarActionMiddleClicked(QAction
*action
)
926 if (action
== actionCollection()->action(KStandardAction::name(KStandardAction::Back
))) {
928 } else if (action
== actionCollection()->action(KStandardAction::name(KStandardAction::Forward
))) {
930 } else if (action
== actionCollection()->action(QStringLiteral("go_up"))) {
932 } else if (action
== actionCollection()->action(QStringLiteral("go_home"))) {
937 QAction
*DolphinMainWindow::urlNavigatorHistoryAction(const KUrlNavigator
*urlNavigator
, int historyIndex
, QObject
*parent
)
939 const QUrl url
= urlNavigator
->locationUrl(historyIndex
);
943 if (isSearchUrl(url
)) {
944 text
= Search::DolphinQuery(url
, QUrl
{}).title();
945 } else if (urlNavigator
->showFullPath()) {
946 text
= url
.toDisplayString(QUrl::PreferLocalFile
);
948 const KFilePlacesModel
*placesModel
= DolphinPlacesModelSingleton::instance().placesModel();
950 const QModelIndex closestIdx
= placesModel
->closestItem(url
);
951 if (closestIdx
.isValid()) {
952 const QUrl placeUrl
= placesModel
->url(closestIdx
);
954 text
= placesModel
->text(closestIdx
);
956 QString pathInsidePlace
= url
.path().mid(placeUrl
.path().length());
958 if (!pathInsidePlace
.isEmpty() && !pathInsidePlace
.startsWith(QLatin1Char('/'))) {
959 pathInsidePlace
.prepend(QLatin1Char('/'));
962 if (pathInsidePlace
!= QLatin1Char('/')) {
963 text
.append(pathInsidePlace
);
968 QAction
*action
= new QAction(QIcon::fromTheme(KIO::iconNameForUrl(url
)), text
, parent
);
969 action
->setData(historyIndex
);
973 void DolphinMainWindow::slotAboutToShowBackPopupMenu()
975 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
977 QMenu
*menu
= m_backAction
->popupMenu();
979 for (int i
= urlNavigator
->historyIndex() + 1; i
< urlNavigator
->historySize() && entries
< MaxNumberOfNavigationentries
; ++i
, ++entries
) {
980 QAction
*action
= urlNavigatorHistoryAction(urlNavigator
, i
, menu
);
981 menu
->addAction(action
);
985 void DolphinMainWindow::slotGoBack(QAction
*action
)
987 int gotoIndex
= action
->data().value
<int>();
988 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
989 for (int i
= gotoIndex
- urlNavigator
->historyIndex(); i
> 0; --i
) {
994 void DolphinMainWindow::slotBackForwardActionMiddleClicked(QAction
*action
)
997 const KUrlNavigator
*urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
998 openNewTab(urlNavigator
->locationUrl(action
->data().value
<int>()));
1002 void DolphinMainWindow::slotAboutToShowForwardPopupMenu()
1004 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
1006 QMenu
*menu
= m_forwardAction
->popupMenu();
1008 for (int i
= urlNavigator
->historyIndex() - 1; i
>= 0 && entries
< MaxNumberOfNavigationentries
; --i
, ++entries
) {
1009 QAction
*action
= urlNavigatorHistoryAction(urlNavigator
, i
, menu
);
1010 menu
->addAction(action
);
1014 void DolphinMainWindow::slotGoForward(QAction
*action
)
1016 int gotoIndex
= action
->data().value
<int>();
1017 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
1018 for (int i
= urlNavigator
->historyIndex() - gotoIndex
; i
> 0; --i
) {
1023 void DolphinMainWindow::slotSetSelectionMode(bool enabled
, SelectionMode::BottomBar::Contents bottomBarContents
)
1025 m_activeViewContainer
->setSelectionModeEnabled(enabled
, actionCollection(), bottomBarContents
);
1028 void DolphinMainWindow::selectAll()
1032 // if the URL navigator is editable and focused, select the whole
1033 // URL instead of all items of the view
1035 KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigator();
1036 QLineEdit
*lineEdit
= urlNavigator
->editor()->lineEdit();
1037 const bool selectUrl
= urlNavigator
->isUrlEditable() && lineEdit
->hasFocus();
1039 lineEdit
->selectAll();
1041 m_activeViewContainer
->view()->selectAll();
1045 void DolphinMainWindow::invertSelection()
1048 m_activeViewContainer
->view()->invertSelection();
1051 void DolphinMainWindow::toggleSplitView()
1053 QUrl newSplitViewUrl
;
1054 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
1055 if (list
.count() == 1) {
1056 const KFileItem
&item
= list
.first();
1057 newSplitViewUrl
= DolphinView::openItemAsFolderUrl(item
);
1060 DolphinTabPage
*tabPage
= m_tabWidget
->currentTabPage();
1061 tabPage
->setSplitViewEnabled(!tabPage
->splitViewEnabled(), WithAnimation
, newSplitViewUrl
);
1062 m_tabWidget
->updateTabName(m_tabWidget
->indexOf(tabPage
));
1063 updateViewActions();
1066 void DolphinMainWindow::popoutSplitView()
1068 DolphinTabPage
*tabPage
= m_tabWidget
->currentTabPage();
1069 if (!tabPage
->splitViewEnabled())
1071 openNewWindow((GeneralSettings::closeActiveSplitView() ? tabPage
->activeViewContainer() : tabPage
->inactiveViewContainer())->url());
1072 tabPage
->setSplitViewEnabled(false, WithAnimation
);
1073 updateSplitActions();
1076 void DolphinMainWindow::toggleSplitStash()
1078 DolphinTabPage
*tabPage
= m_tabWidget
->currentTabPage();
1079 tabPage
->setSplitViewEnabled(false, WithAnimation
);
1080 tabPage
->setSplitViewEnabled(true, WithAnimation
, QUrl("stash:/"));
1083 void DolphinMainWindow::copyToInactiveSplitView()
1085 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
1086 m_activeViewContainer
->setSelectionModeEnabled(true, actionCollection(), SelectionMode::BottomBar::Contents::CopyToOtherViewContents
);
1088 m_tabWidget
->copyToInactiveSplitView();
1089 m_activeViewContainer
->setSelectionModeEnabled(false);
1093 void DolphinMainWindow::moveToInactiveSplitView()
1095 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
1096 m_activeViewContainer
->setSelectionModeEnabled(true, actionCollection(), SelectionMode::BottomBar::Contents::MoveToOtherViewContents
);
1098 m_tabWidget
->moveToInactiveSplitView();
1099 m_activeViewContainer
->setSelectionModeEnabled(false);
1103 void DolphinMainWindow::reloadView()
1106 m_activeViewContainer
->reload();
1107 m_activeViewContainer
->statusBar()->updateSpaceInfo();
1110 void DolphinMainWindow::stopLoading()
1112 m_activeViewContainer
->view()->stopLoading();
1115 void DolphinMainWindow::enableStopAction()
1117 actionCollection()->action(QStringLiteral("stop"))->setEnabled(true);
1120 void DolphinMainWindow::disableStopAction()
1122 actionCollection()->action(QStringLiteral("stop"))->setEnabled(false);
1125 void DolphinMainWindow::toggleSelectionMode()
1127 const bool checked
= !m_activeViewContainer
->isSelectionModeEnabled();
1129 m_activeViewContainer
->setSelectionModeEnabled(checked
, actionCollection(), SelectionMode::BottomBar::Contents::GeneralContents
);
1130 actionCollection()->action(QStringLiteral("toggle_selection_mode"))->setChecked(checked
);
1133 void DolphinMainWindow::showFilterBar()
1135 m_activeViewContainer
->setFilterBarVisible(true);
1138 void DolphinMainWindow::toggleFilterBar()
1140 const bool checked
= !m_activeViewContainer
->isFilterBarVisible();
1141 m_activeViewContainer
->setFilterBarVisible(checked
);
1143 QAction
*toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
1144 toggleFilterBarAction
->setChecked(checked
);
1147 void DolphinMainWindow::toggleEditLocation()
1151 QAction
*action
= actionCollection()->action(QStringLiteral("editable_location"));
1152 KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigator();
1153 urlNavigator
->setUrlEditable(action
->isChecked());
1156 void DolphinMainWindow::replaceLocation()
1158 KUrlNavigator
*navigator
= m_activeViewContainer
->urlNavigator();
1159 QLineEdit
*lineEdit
= navigator
->editor()->lineEdit();
1161 // If the text field currently has focus and everything is selected,
1162 // pressing the keyboard shortcut returns the whole thing to breadcrumb mode
1163 // and goes back to the view, just like how it was before this action was triggered the first time.
1164 if (navigator
->isUrlEditable() && lineEdit
->hasFocus() && lineEdit
->selectedText() == lineEdit
->text()) {
1165 navigator
->setUrlEditable(false);
1166 m_activeViewContainer
->view()->setFocus();
1168 navigator
->setUrlEditable(true);
1169 navigator
->setFocus();
1170 lineEdit
->selectAll();
1174 void DolphinMainWindow::togglePanelLockState()
1176 const bool newLockState
= !GeneralSettings::lockPanels();
1177 const auto childrenObjects
= children();
1178 for (QObject
*child
: childrenObjects
) {
1179 DolphinDockWidget
*dock
= qobject_cast
<DolphinDockWidget
*>(child
);
1181 dock
->setLocked(newLockState
);
1185 DolphinPlacesModelSingleton::instance().placesModel()->setPanelsLocked(newLockState
);
1187 GeneralSettings::setLockPanels(newLockState
);
1190 void DolphinMainWindow::slotTerminalPanelVisibilityChanged(bool visible
)
1192 if (!visible
&& m_activeViewContainer
) {
1193 m_activeViewContainer
->view()->setFocus();
1195 // Putting focus to the Terminal is not handled here but in TerminalPanel::showEvent().
1198 void DolphinMainWindow::slotPlacesPanelVisibilityChanged(bool visible
)
1200 if (!visible
&& m_activeViewContainer
) {
1201 m_activeViewContainer
->view()->setFocus();
1204 m_placesPanel
->setFocus();
1207 void DolphinMainWindow::goBack()
1209 DolphinUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
1210 urlNavigator
->goBack();
1212 if (urlNavigator
->locationState().isEmpty()) {
1213 // An empty location state indicates a redirection URL,
1214 // which must be skipped too
1215 urlNavigator
->goBack();
1219 void DolphinMainWindow::goForward()
1221 m_activeViewContainer
->urlNavigatorInternalWithHistory()->goForward();
1224 void DolphinMainWindow::goUp()
1226 m_activeViewContainer
->urlNavigatorInternalWithHistory()->goUp();
1229 void DolphinMainWindow::goHome()
1231 m_activeViewContainer
->urlNavigatorInternalWithHistory()->goHome();
1234 void DolphinMainWindow::goBackInNewTab()
1236 const KUrlNavigator
*urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
1237 const int index
= urlNavigator
->historyIndex() + 1;
1238 openNewTab(urlNavigator
->locationUrl(index
));
1241 void DolphinMainWindow::goForwardInNewTab()
1243 const KUrlNavigator
*urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
1244 const int index
= urlNavigator
->historyIndex() - 1;
1245 openNewTab(urlNavigator
->locationUrl(index
));
1248 void DolphinMainWindow::goUpInNewTab()
1250 const QUrl currentUrl
= activeViewContainer()->urlNavigator()->locationUrl();
1251 openNewTab(KIO::upUrl(currentUrl
));
1254 void DolphinMainWindow::goHomeInNewTab()
1256 openNewTab(Dolphin::homeUrl());
1259 void DolphinMainWindow::compareFiles()
1261 const KFileItemList items
= m_tabWidget
->currentTabPage()->selectedItems();
1262 if (items
.count() != 2) {
1263 // The action is disabled in this case, but it could have been triggered
1264 // via D-Bus, see https://bugs.kde.org/show_bug.cgi?id=325517
1268 QUrl urlA
= items
.at(0).url();
1269 QUrl urlB
= items
.at(1).url();
1271 QString
command(QStringLiteral("kompare -c \""));
1272 command
.append(urlA
.toDisplayString(QUrl::PreferLocalFile
));
1273 command
.append("\" \"");
1274 command
.append(urlB
.toDisplayString(QUrl::PreferLocalFile
));
1275 command
.append('\"');
1277 KIO::CommandLauncherJob
*job
= new KIO::CommandLauncherJob(command
, this);
1278 job
->setDesktopName(QStringLiteral("org.kde.kompare"));
1282 void DolphinMainWindow::toggleShowMenuBar()
1284 const bool visible
= menuBar()->isVisible();
1285 menuBar()->setVisible(!visible
);
1288 QPointer
<QAction
> DolphinMainWindow::preferredSearchTool()
1290 m_searchTools
.clear();
1292 KService::Ptr kfind
= KService::serviceByDesktopName(QStringLiteral("org.kde.kfind"));
1298 auto *action
= new QAction(QIcon::fromTheme(kfind
->icon()), kfind
->name(), this);
1300 connect(action
, &QAction::triggered
, this, [this, kfind
] {
1301 auto *job
= new KIO::ApplicationLauncherJob(kfind
);
1302 job
->setUrls({m_activeViewContainer
->url()});
1309 void DolphinMainWindow::updateOpenPreferredSearchToolAction()
1311 QAction
*openPreferredSearchTool
= actionCollection()->action(QStringLiteral("open_preferred_search_tool"));
1312 if (!openPreferredSearchTool
) {
1315 QPointer
<QAction
> tool
= preferredSearchTool();
1317 openPreferredSearchTool
->setVisible(true);
1318 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open %1", tool
->text()));
1319 // Only override with the app icon if it is the default, i.e. the user hasn't configured one manually
1320 // https://bugs.kde.org/show_bug.cgi?id=442815
1321 if (openPreferredSearchTool
->icon().name() == QLatin1String("search")) {
1322 openPreferredSearchTool
->setIcon(tool
->icon());
1325 openPreferredSearchTool
->setVisible(false);
1326 // still visible in Shortcuts configuration window
1327 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool"));
1328 openPreferredSearchTool
->setIcon(QIcon::fromTheme(QStringLiteral("search")));
1332 void DolphinMainWindow::openPreferredSearchTool()
1334 QPointer
<QAction
> tool
= preferredSearchTool();
1340 void DolphinMainWindow::openTerminal()
1342 openTerminalJob(m_activeViewContainer
->url());
1345 void DolphinMainWindow::openTerminalHere()
1347 QList
<QUrl
> urls
= {};
1349 const auto selectedItems
= m_activeViewContainer
->view()->selectedItems();
1350 for (const KFileItem
&item
: selectedItems
) {
1351 QUrl url
= item
.targetUrl();
1352 if (item
.isFile()) {
1353 url
.setPath(QFileInfo(url
.path()).absolutePath());
1355 if (!urls
.contains(url
)) {
1360 // No items are selected. Open a terminal window for the current location.
1361 if (urls
.count() == 0) {
1366 if (urls
.count() > 5) {
1367 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());
1368 const int answer
= KMessageBox::warningContinueCancel(
1372 KGuiItem(i18ncp("@action:button", "Open %1 Terminal", "Open %1 Terminals", urls
.count()), QStringLiteral("utilities-terminal")),
1373 KStandardGuiItem::cancel(),
1374 QStringLiteral("ConfirmOpenManyTerminals"));
1375 if (answer
!= KMessageBox::PrimaryAction
&& answer
!= KMessageBox::Continue
) {
1380 for (const QUrl
&url
: std::as_const(urls
)) {
1381 openTerminalJob(url
);
1385 void DolphinMainWindow::openTerminalJob(const QUrl
&url
)
1387 if (url
.isLocalFile()) {
1388 auto job
= new KTerminalLauncherJob(QString());
1389 job
->setWorkingDirectory(url
.toLocalFile());
1394 // Not a local file, with protocol Class ":local", try stat'ing
1395 if (KProtocolInfo::protocolClass(url
.scheme()) == QLatin1String(":local")) {
1396 KIO::StatJob
*job
= KIO::mostLocalUrl(url
);
1397 KJobWidgets::setWindow(job
, this);
1398 connect(job
, &KJob::result
, this, [job
]() {
1400 if (!job
->error()) {
1401 statUrl
= job
->mostLocalUrl();
1404 auto job
= new KTerminalLauncherJob(QString());
1405 job
->setWorkingDirectory(statUrl
.isLocalFile() ? statUrl
.toLocalFile() : QDir::homePath());
1412 // Nothing worked, just use $HOME
1413 auto job
= new KTerminalLauncherJob(QString());
1414 job
->setWorkingDirectory(QDir::homePath());
1418 void DolphinMainWindow::editSettings()
1420 if (!m_settingsDialog
) {
1421 DolphinViewContainer
*container
= activeViewContainer();
1422 container
->view()->writeSettings();
1424 const QUrl url
= container
->url();
1425 DolphinSettingsDialog
*settingsDialog
= new DolphinSettingsDialog(url
, this, actionCollection());
1426 connect(settingsDialog
, &DolphinSettingsDialog::settingsChanged
, this, &DolphinMainWindow::refreshViews
);
1427 connect(settingsDialog
, &DolphinSettingsDialog::settingsChanged
, &DolphinUrlNavigatorsController::slotReadSettings
);
1428 settingsDialog
->setAttribute(Qt::WA_DeleteOnClose
);
1429 settingsDialog
->show();
1430 m_settingsDialog
= settingsDialog
;
1432 m_settingsDialog
.data()->raise();
1436 void DolphinMainWindow::handleUrl(const QUrl
&url
)
1438 delete m_lastHandleUrlOpenJob
;
1439 m_lastHandleUrlOpenJob
= nullptr;
1441 if (url
.isLocalFile() && QFileInfo(url
.toLocalFile()).isDir()) {
1442 activeViewContainer()->setUrl(url
);
1444 m_lastHandleUrlOpenJob
= new KIO::OpenUrlJob(url
);
1445 m_lastHandleUrlOpenJob
->setUiDelegate(KIO::createDefaultJobUiDelegate(KJobUiDelegate::AutoHandlingEnabled
, this));
1446 m_lastHandleUrlOpenJob
->setShowOpenOrExecuteDialog(true);
1448 connect(m_lastHandleUrlOpenJob
, &KIO::OpenUrlJob::mimeTypeFound
, this, [this, url
](const QString
&mimetype
) {
1449 if (mimetype
== QLatin1String("inode/directory")) {
1450 // If it's a dir, we'll take it from here
1451 m_lastHandleUrlOpenJob
->kill();
1452 m_lastHandleUrlOpenJob
= nullptr;
1453 activeViewContainer()->setUrl(url
);
1457 connect(m_lastHandleUrlOpenJob
, &KIO::OpenUrlJob::result
, this, [this]() {
1458 m_lastHandleUrlOpenJob
= nullptr;
1461 m_lastHandleUrlOpenJob
->start();
1465 void DolphinMainWindow::slotWriteStateChanged(bool isFolderWritable
)
1467 // trash:/ is writable but we don't want to create new items in it.
1468 // TODO: remove the trash check once https://phabricator.kde.org/T8234 is implemented
1469 newFileMenu()->setEnabled(isFolderWritable
&& m_activeViewContainer
->url().scheme() != QLatin1String("trash"));
1470 // 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.
1471 QTimer::singleShot(0, this, [this]() {
1472 m_disabledActionNotifier
->setDisabledReason(actionCollection()->action(QStringLiteral("create_file")),
1473 i18nc("@info", "Cannot create new file: You do not have permission to create items in this folder."));
1474 m_disabledActionNotifier
->setDisabledReason(actionCollection()->action(QStringLiteral("create_dir")),
1475 i18nc("@info", "Cannot create new folder: You do not have permission to create items in this folder."));
1479 void DolphinMainWindow::openContextMenu(const QPoint
&pos
, const KFileItem
&item
, const KFileItemList
&selectedItems
, const QUrl
&url
)
1481 QPointer
<DolphinContextMenu
> contextMenu
= new DolphinContextMenu(this, item
, selectedItems
, url
, &m_fileItemActions
);
1482 contextMenu
->exec(pos
);
1484 // Delete the menu, unless it has been deleted in its own nested event loop already.
1486 contextMenu
->deleteLater();
1490 QMenu
*DolphinMainWindow::createPopupMenu()
1492 QMenu
*menu
= KXmlGuiWindow::createPopupMenu();
1494 menu
->addSeparator();
1495 menu
->addAction(actionCollection()->action(QStringLiteral("lock_panels")));
1500 void DolphinMainWindow::updateHamburgerMenu()
1502 KActionCollection
*ac
= actionCollection();
1503 auto hamburgerMenu
= static_cast<KHamburgerMenu
*>(ac
->action(KStandardAction::name(KStandardAction::HamburgerMenu
)));
1504 auto menu
= hamburgerMenu
->menu();
1506 menu
= new QMenu(this);
1507 hamburgerMenu
->setMenu(menu
);
1508 hamburgerMenu
->hideActionsOf(ac
->action(QStringLiteral("basic_actions"))->menu());
1509 hamburgerMenu
->hideActionsOf(ac
->action(QStringLiteral("zoom"))->menu());
1513 const QList
<QAction
*> toolbarActions
= toolBar()->actions();
1515 if (!toolBar()->isVisible()) {
1516 // If neither the menu bar nor the toolbar are visible, these actions should be available.
1517 menu
->addAction(ac
->action(KStandardAction::name(KStandardAction::ShowMenubar
)));
1518 menu
->addAction(toolBarMenuAction());
1519 menu
->addSeparator();
1522 // This group of actions (until the next separator) contains all the most basic actions
1523 // necessary to use Dolphin effectively.
1524 menu
->addAction(ac
->action(QStringLiteral("go_back")));
1525 menu
->addAction(ac
->action(QStringLiteral("go_forward")));
1527 menu
->addMenu(m_newFileMenu
->menu());
1528 if (!toolBar()->isVisible() || !toolbarActions
.contains(ac
->action(QStringLiteral("toggle_selection_mode_tool_bar")))) {
1529 menu
->addAction(ac
->action(QStringLiteral("toggle_selection_mode")));
1531 menu
->addAction(ac
->action(QStringLiteral("basic_actions")));
1532 menu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Undo
)));
1533 if (!toolBar()->isVisible()
1534 || (!toolbarActions
.contains(ac
->action(QStringLiteral("toggle_search")))
1535 && !toolbarActions
.contains(ac
->action(QStringLiteral("open_preferred_search_tool"))))) {
1536 menu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Find
)));
1537 // This way a search action will only be added if none of the three available
1538 // search actions is present on the toolbar.
1540 if (!toolBar()->isVisible() || !toolbarActions
.contains(ac
->action(QStringLiteral("toggle_filter")))) {
1541 menu
->addAction(ac
->action(QStringLiteral("show_filter_bar")));
1542 // This way a filter action will only be added if none of the two available
1543 // filter actions is present on the toolbar.
1545 menu
->addSeparator();
1547 // The second group of actions (up until the next separator) contains actions for opening
1548 // additional views to interact with the file system.
1549 menu
->addAction(ac
->action(QStringLiteral("file_new")));
1550 menu
->addAction(ac
->action(QStringLiteral("new_tab")));
1551 if (ac
->action(QStringLiteral("undo_close_tab"))->isEnabled()) {
1552 menu
->addAction(ac
->action(QStringLiteral("closed_tabs")));
1554 menu
->addAction(ac
->action(QStringLiteral("open_terminal")));
1555 menu
->addSeparator();
1557 // The third group contains actions to change what one sees in the view
1558 // and to change the more general UI.
1559 if (!toolBar()->isVisible()
1560 || (!toolbarActions
.contains(ac
->action(QStringLiteral("icons"))) && !toolbarActions
.contains(ac
->action(QStringLiteral("compact")))
1561 && !toolbarActions
.contains(ac
->action(QStringLiteral("details"))) && !toolbarActions
.contains(ac
->action(QStringLiteral("view_mode"))))) {
1562 menu
->addAction(ac
->action(QStringLiteral("view_mode")));
1564 menu
->addAction(ac
->action(QStringLiteral("show_hidden_files")));
1565 menu
->addAction(ac
->action(QStringLiteral("sort")));
1566 menu
->addAction(ac
->action(QStringLiteral("additional_info")));
1567 if (!GeneralSettings::showStatusBar() || !GeneralSettings::showZoomSlider()) {
1568 menu
->addAction(ac
->action(QStringLiteral("zoom")));
1570 menu
->addAction(ac
->action(QStringLiteral("panels")));
1572 // The "Configure" menu is not added to the actionCollection() because there is hardly
1573 // a good reason for users to put it on their toolbar.
1574 auto configureMenu
= menu
->addMenu(QIcon::fromTheme(QStringLiteral("configure")), i18nc("@action:inmenu menu for configure actions", "Configure"));
1575 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::SwitchApplicationLanguage
)));
1576 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::KeyBindings
)));
1577 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::ConfigureToolbars
)));
1578 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Preferences
)));
1579 hamburgerMenu
->hideActionsOf(configureMenu
);
1582 void DolphinMainWindow::slotPlaceActivated(const QUrl
&url
)
1584 DolphinViewContainer
*view
= activeViewContainer();
1586 if (view
->url() == url
) {
1587 view
->clearFilterBar(); // Fixes bug 259382.
1589 // We can end up here if the user clicked a device in the Places Panel
1590 // which had been unmounted earlier, see https://bugs.kde.org/show_bug.cgi?id=161385.
1593 m_activeViewContainer
->view()->setFocus(); // We always want the focus on the view after activating a place.
1595 view
->disableUrlNavigatorSelectionRequests();
1597 view
->enableUrlNavigatorSelectionRequests();
1601 void DolphinMainWindow::closedTabsCountChanged(unsigned int count
)
1603 actionCollection()->action(QStringLiteral("undo_close_tab"))->setEnabled(count
> 0);
1606 void DolphinMainWindow::activeViewChanged(DolphinViewContainer
*viewContainer
)
1608 DolphinViewContainer
*oldViewContainer
= m_activeViewContainer
;
1609 Q_ASSERT(viewContainer
);
1611 m_activeViewContainer
= viewContainer
;
1613 if (oldViewContainer
) {
1614 // Disconnect all signals between the old view container (container,
1615 // view and url navigator) and main window.
1616 oldViewContainer
->disconnect(this);
1617 oldViewContainer
->view()->disconnect(this);
1618 oldViewContainer
->urlNavigatorInternalWithHistory()->disconnect(this);
1619 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>(actionCollection()->action(QStringLiteral("url_navigators")));
1620 navigators
->primaryUrlNavigator()->disconnect(this);
1621 if (auto secondaryUrlNavigator
= navigators
->secondaryUrlNavigator()) {
1622 secondaryUrlNavigator
->disconnect(this);
1625 // except the requestItemInfo so that on hover the information panel can still be updated
1626 connect(oldViewContainer
->view(), &DolphinView::requestItemInfo
, this, &DolphinMainWindow::requestItemInfo
);
1628 // Disconnect other slots.
1629 disconnect(oldViewContainer
,
1630 &DolphinViewContainer::selectionModeChanged
,
1631 actionCollection()->action(QStringLiteral("toggle_selection_mode")),
1632 &QAction::setChecked
);
1635 connectViewSignals(viewContainer
);
1637 m_actionHandler
->setCurrentView(viewContainer
->view());
1640 updateFileAndEditActions();
1641 updatePasteAction();
1642 updateViewActions();
1644 updateSearchAction();
1646 const QUrl url
= viewContainer
->url();
1647 Q_EMIT
urlChanged(url
);
1650 void DolphinMainWindow::tabCountChanged(int count
)
1652 const bool enableTabActions
= (count
> 1);
1653 for (int i
= 0; i
< MaxActivateTabShortcuts
; ++i
) {
1654 actionCollection()->action(QStringLiteral("activate_tab_%1").arg(i
))->setEnabled(enableTabActions
);
1656 actionCollection()->action(QStringLiteral("activate_last_tab"))->setEnabled(enableTabActions
);
1657 actionCollection()->action(QStringLiteral("activate_next_tab"))->setEnabled(enableTabActions
);
1658 actionCollection()->action(QStringLiteral("activate_prev_tab"))->setEnabled(enableTabActions
);
1661 void DolphinMainWindow::updateWindowTitle()
1663 const QString newTitle
= m_activeViewContainer
->captionWindowTitle();
1664 if (windowTitle() != newTitle
) {
1665 setWindowTitle(newTitle
);
1669 void DolphinMainWindow::slotStorageTearDownFromPlacesRequested(const QString
&mountPath
)
1671 connect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, this, [this, mountPath
]() {
1672 setViewsToHomeIfMountPathOpen(mountPath
);
1675 if (m_terminalPanel
&& m_terminalPanel
->currentWorkingDirectoryIsChildOf(mountPath
)) {
1676 m_tearDownFromPlacesRequested
= true;
1677 m_terminalPanel
->goHome();
1678 // m_placesPanel->proceedWithTearDown() will be called in slotTerminalDirectoryChanged
1680 m_placesPanel
->proceedWithTearDown();
1684 void DolphinMainWindow::slotStorageTearDownExternallyRequested(const QString
&mountPath
)
1686 connect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, this, [this, mountPath
]() {
1687 setViewsToHomeIfMountPathOpen(mountPath
);
1690 if (m_terminalPanel
&& m_terminalPanel
->currentWorkingDirectoryIsChildOf(mountPath
)) {
1691 m_tearDownFromPlacesRequested
= false;
1692 m_terminalPanel
->goHome();
1696 void DolphinMainWindow::slotKeyBindings()
1698 KShortcutsDialog
dialog(KShortcutsEditor::AllActions
, KShortcutsEditor::LetterShortcutsAllowed
, this);
1699 dialog
.addCollection(actionCollection());
1700 if (m_terminalPanel
) {
1701 KActionCollection
*konsolePartActionCollection
= m_terminalPanel
->actionCollection();
1702 if (konsolePartActionCollection
) {
1703 dialog
.addCollection(konsolePartActionCollection
, QStringLiteral("KonsolePart"));
1709 void DolphinMainWindow::setViewsToHomeIfMountPathOpen(const QString
&mountPath
)
1711 const QVector
<DolphinViewContainer
*> theViewContainers
= viewContainers();
1712 for (DolphinViewContainer
*viewContainer
: theViewContainers
) {
1713 if (viewContainer
&& viewContainer
->url().toLocalFile().startsWith(mountPath
)) {
1714 viewContainer
->setUrl(QUrl::fromLocalFile(QDir::homePath()));
1717 disconnect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, nullptr, nullptr);
1720 void DolphinMainWindow::setupActions()
1722 auto hamburgerMenuAction
= KStandardAction::hamburgerMenu(nullptr, nullptr, actionCollection());
1724 // setup 'File' menu
1725 m_newFileMenu
= new DolphinNewFileMenu(nullptr, nullptr, this);
1726 actionCollection()->addAction(QStringLiteral("new_menu"), m_newFileMenu
);
1727 QMenu
*menu
= m_newFileMenu
->menu();
1728 menu
->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1729 menu
->setIcon(QIcon::fromTheme(QStringLiteral("list-add")));
1730 m_newFileMenu
->setPopupMode(QToolButton::InstantPopup
);
1731 connect(menu
, &QMenu::aboutToShow
, this, &DolphinMainWindow::updateNewMenu
);
1733 QAction
*newWindow
= KStandardAction::openNew(this, &DolphinMainWindow::openNewMainWindow
, actionCollection());
1734 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
1735 newWindow
->setToolTip(i18nc("@info", "Open a new Dolphin window"));
1736 newWindow
->setWhatsThis(xi18nc("@info:whatsthis",
1738 "window just like this one with the current location."
1739 "<nl/>You can drag and drop items between windows."));
1740 newWindow
->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
1742 QAction
*newTab
= actionCollection()->addAction(QStringLiteral("new_tab"));
1743 newTab
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1744 newTab
->setText(i18nc("@action:inmenu File", "New Tab"));
1745 newTab
->setWhatsThis(xi18nc("@info:whatsthis",
1747 "<emphasis>Tab</emphasis> with the current location."
1748 "<nl/>Tabs allow you to quickly switch between multiple locations and views within this window. "
1749 "You can drag and drop items between tabs."));
1750 actionCollection()->setDefaultShortcut(newTab
, Qt::CTRL
| Qt::Key_T
);
1751 connect(newTab
, &QAction::triggered
, this, &DolphinMainWindow::openNewActivatedTab
);
1753 QAction
*addToPlaces
= actionCollection()->addAction(QStringLiteral("add_to_places"));
1754 addToPlaces
->setIcon(QIcon::fromTheme(QStringLiteral("bookmark-new")));
1755 addToPlaces
->setText(i18nc("@action:inmenu Add current folder to places", "Add to Places"));
1756 addToPlaces
->setWhatsThis(xi18nc("@info:whatsthis",
1757 "This adds the selected folder "
1758 "to the Places panel."));
1759 connect(addToPlaces
, &QAction::triggered
, this, &DolphinMainWindow::addToPlaces
);
1761 QAction
*closeTab
= KStandardAction::close(m_tabWidget
, QOverload
<>::of(&DolphinTabWidget::closeTab
), actionCollection());
1762 closeTab
->setText(i18nc("@action:inmenu File", "Close Tab"));
1763 closeTab
->setToolTip(i18nc("@info", "Close Tab"));
1764 closeTab
->setWhatsThis(i18nc("@info:whatsthis",
1766 "currently viewed tab. If no more tabs are left, this closes "
1767 "the whole window instead."));
1769 QAction
*quitAction
= KStandardAction::quit(this, &DolphinMainWindow::quit
, actionCollection());
1770 quitAction
->setWhatsThis(i18nc("@info:whatsthis quit", "This closes this window."));
1772 // setup 'Edit' menu
1773 KStandardAction::undo(this, &DolphinMainWindow::undo
, actionCollection());
1775 // i18n: This will be the last paragraph for the whatsthis for all three:
1776 // Cut, Copy and Paste
1777 const QString cutCopyPastePara
= xi18nc("@info:whatsthis",
1778 "<para><emphasis>Cut, "
1779 "Copy</emphasis> and <emphasis>Paste</emphasis> work between many "
1780 "applications and are among the most used commands. That's why their "
1781 "<emphasis>keyboard shortcuts</emphasis> are prominently placed right "
1782 "next to each other on the keyboard: <shortcut>Ctrl+X</shortcut>, "
1783 "<shortcut>Ctrl+C</shortcut> and <shortcut>Ctrl+V</shortcut>.</para>");
1784 QAction
*cutAction
= KStandardAction::cut(this, &DolphinMainWindow::cut
, actionCollection());
1785 m_actionTextHelper
->registerTextWhenNothingIsSelected(cutAction
, i18nc("@action", "Cut…"));
1786 cutAction
->setWhatsThis(xi18nc("@info:whatsthis cut",
1787 "This copies the items "
1788 "in your current selection to the <emphasis>clipboard</emphasis>.<nl/>"
1789 "Use the <emphasis>Paste</emphasis> action afterwards to copy them from "
1790 "the clipboard to a new location. The items will be removed from their "
1791 "initial location.")
1792 + cutCopyPastePara
);
1793 QAction
*copyAction
= KStandardAction::copy(this, &DolphinMainWindow::copy
, actionCollection());
1794 m_actionTextHelper
->registerTextWhenNothingIsSelected(copyAction
, i18nc("@action", "Copy…"));
1795 copyAction
->setWhatsThis(xi18nc("@info:whatsthis copy",
1797 "items in your current selection to the <emphasis>clipboard</emphasis>."
1798 "<nl/>Use the <emphasis>Paste</emphasis> action afterwards to copy them "
1799 "from the clipboard to a new location.")
1800 + cutCopyPastePara
);
1801 QAction
*paste
= KStandardAction::paste(this, &DolphinMainWindow::paste
, actionCollection());
1802 // The text of the paste-action is modified dynamically by Dolphin
1803 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1804 // due to the long text, the text "Paste" is used:
1805 paste
->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1806 paste
->setWhatsThis(xi18nc("@info:whatsthis paste",
1807 "This copies the items from "
1808 "your <emphasis>clipboard</emphasis> to the currently viewed folder.<nl/>"
1809 "If the items were added to the clipboard by the <emphasis>Cut</emphasis> "
1810 "action they are removed from their old location.")
1811 + cutCopyPastePara
);
1813 QAction
*copyToOtherViewAction
= actionCollection()->addAction(QStringLiteral("copy_to_inactive_split_view"));
1814 copyToOtherViewAction
->setText(i18nc("@action:inmenu", "Copy to Other View"));
1815 m_actionTextHelper
->registerTextWhenNothingIsSelected(copyToOtherViewAction
, i18nc("@action:inmenu", "Copy to Other View…"));
1816 copyToOtherViewAction
->setWhatsThis(xi18nc("@info:whatsthis Copy",
1817 "This copies the selected items from "
1818 "the view in focus to the other view. "
1819 "(Only available while in Split View mode.)"));
1820 copyToOtherViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("edit-copy")));
1821 copyToOtherViewAction
->setIconText(i18nc("@action:inmenu Edit", "Copy to Other View"));
1822 actionCollection()->setDefaultShortcut(copyToOtherViewAction
, Qt::SHIFT
| Qt::Key_F5
);
1823 connect(copyToOtherViewAction
, &QAction::triggered
, this, &DolphinMainWindow::copyToInactiveSplitView
);
1825 QAction
*moveToOtherViewAction
= actionCollection()->addAction(QStringLiteral("move_to_inactive_split_view"));
1826 moveToOtherViewAction
->setText(i18nc("@action:inmenu", "Move to Other View"));
1827 m_actionTextHelper
->registerTextWhenNothingIsSelected(moveToOtherViewAction
, i18nc("@action:inmenu", "Move to Other View…"));
1828 moveToOtherViewAction
->setWhatsThis(xi18nc("@info:whatsthis Move",
1829 "This moves the selected items from "
1830 "the view in focus to the other view. "
1831 "(Only available while in Split View mode.)"));
1832 moveToOtherViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("edit-cut")));
1833 moveToOtherViewAction
->setIconText(i18nc("@action:inmenu Edit", "Move to Other View"));
1834 actionCollection()->setDefaultShortcut(moveToOtherViewAction
, Qt::SHIFT
| Qt::Key_F6
);
1835 connect(moveToOtherViewAction
, &QAction::triggered
, this, &DolphinMainWindow::moveToInactiveSplitView
);
1837 QAction
*showFilterBar
= actionCollection()->addAction(QStringLiteral("show_filter_bar"));
1838 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Filter…"));
1839 showFilterBar
->setToolTip(i18nc("@info:tooltip", "Show Filter Bar"));
1840 showFilterBar
->setWhatsThis(xi18nc("@info:whatsthis",
1842 "<emphasis>Filter Bar</emphasis> at the bottom of the window.<nl/> "
1843 "There you can enter text to filter the files and folders currently displayed. "
1844 "Only those that contain the text in their name will be kept in view."));
1845 showFilterBar
->setIcon(QIcon::fromTheme(QStringLiteral("view-filter")));
1846 actionCollection()->setDefaultShortcuts(showFilterBar
, {Qt::CTRL
| Qt::Key_I
, Qt::Key_Slash
});
1847 connect(showFilterBar
, &QAction::triggered
, this, &DolphinMainWindow::showFilterBar
);
1849 // toggle_filter acts as a copy of the main showFilterBar to be used mainly
1850 // in the toolbar, with no default shortcut attached, to avoid messing with
1851 // existing workflows (filter bar always open and Ctrl-I to focus)
1852 QAction
*toggleFilter
= actionCollection()->addAction(QStringLiteral("toggle_filter"));
1853 toggleFilter
->setText(i18nc("@action:inmenu", "Toggle Filter Bar"));
1854 toggleFilter
->setIconText(i18nc("@action:intoolbar", "Filter"));
1855 toggleFilter
->setIcon(showFilterBar
->icon());
1856 toggleFilter
->setToolTip(showFilterBar
->toolTip());
1857 toggleFilter
->setWhatsThis(showFilterBar
->whatsThis());
1858 toggleFilter
->setCheckable(true);
1859 connect(toggleFilter
, &QAction::triggered
, this, &DolphinMainWindow::toggleFilterBar
);
1861 QAction
*searchAction
= KStandardAction::find(this, &DolphinMainWindow::find
, actionCollection());
1862 searchAction
->setText(i18n("Search…"));
1863 searchAction
->setToolTip(i18nc("@info:tooltip", "Search for files and folders"));
1864 searchAction
->setWhatsThis(xi18nc("@info:whatsthis find",
1865 "<para>This helps you "
1866 "find files and folders by opening a <emphasis>search bar</emphasis>. "
1867 "There you can enter search terms and specify settings to find the "
1868 "items you are looking for.</para>"));
1870 // toggle_search acts as a copy of the main searchAction to be used mainly
1871 // in the toolbar, with no default shortcut attached, to avoid messing with
1872 // existing workflows (search bar always open and Ctrl-F to focus)
1873 QAction
*toggleSearchAction
= actionCollection()->addAction(QStringLiteral("toggle_search"));
1874 toggleSearchAction
->setText(i18nc("@action:inmenu", "Toggle Search Bar"));
1875 toggleSearchAction
->setIconText(i18nc("@action:intoolbar", "Search"));
1876 toggleSearchAction
->setIcon(searchAction
->icon());
1877 toggleSearchAction
->setToolTip(searchAction
->toolTip());
1878 toggleSearchAction
->setWhatsThis(searchAction
->whatsThis());
1879 toggleSearchAction
->setCheckable(true);
1880 connect(toggleSearchAction
, &QAction::triggered
, this, [this](bool checked
) {
1884 m_activeViewContainer
->setSearchBarVisible(false);
1888 QAction
*toggleSelectionModeAction
= actionCollection()->addAction(QStringLiteral("toggle_selection_mode"));
1889 // i18n: This action toggles a selection mode.
1890 toggleSelectionModeAction
->setText(i18nc("@action:inmenu", "Select Files and Folders"));
1891 // i18n: Opens a selection mode for selecting files/folders.
1892 // The text is kept so unspecific because it will be shown on the toolbar where space is at a premium.
1893 toggleSelectionModeAction
->setIconText(i18nc("@action:intoolbar", "Select"));
1894 toggleSelectionModeAction
->setWhatsThis(xi18nc(
1896 "<para>This application only knows which files or folders should be acted on if they are"
1897 " <emphasis>selected</emphasis> first. Press this to toggle a <emphasis>Selection Mode</emphasis> which makes selecting and deselecting as easy as "
1898 "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."
1900 toggleSelectionModeAction
->setIcon(QIcon::fromTheme(QStringLiteral("quickwizard")));
1901 toggleSelectionModeAction
->setCheckable(true);
1902 actionCollection()->setDefaultShortcut(toggleSelectionModeAction
, Qt::Key_Space
);
1903 connect(toggleSelectionModeAction
, &QAction::triggered
, this, &DolphinMainWindow::toggleSelectionMode
);
1905 // A special version of the toggleSelectionModeAction for the toolbar that also contains a menu
1906 // with the selectAllAction and invertSelectionAction.
1907 auto *toggleSelectionModeToolBarAction
=
1908 new KToolBarPopupAction(toggleSelectionModeAction
->icon(), toggleSelectionModeAction
->iconText(), actionCollection());
1909 toggleSelectionModeToolBarAction
->setToolTip(toggleSelectionModeAction
->text());
1910 toggleSelectionModeToolBarAction
->setWhatsThis(toggleSelectionModeAction
->whatsThis());
1911 actionCollection()->addAction(QStringLiteral("toggle_selection_mode_tool_bar"), toggleSelectionModeToolBarAction
);
1912 toggleSelectionModeToolBarAction
->setCheckable(true);
1913 toggleSelectionModeToolBarAction
->setPopupMode(KToolBarPopupAction::DelayedPopup
);
1914 connect(toggleSelectionModeToolBarAction
, &QAction::triggered
, toggleSelectionModeAction
, &QAction::trigger
);
1915 connect(toggleSelectionModeAction
, &QAction::toggled
, toggleSelectionModeToolBarAction
, &QAction::setChecked
);
1917 QAction
*selectAllAction
= KStandardAction::selectAll(this, &DolphinMainWindow::selectAll
, actionCollection());
1918 selectAllAction
->setWhatsThis(xi18nc("@info:whatsthis",
1920 "files and folders in the current location."));
1922 QAction
*invertSelection
= actionCollection()->addAction(QStringLiteral("invert_selection"));
1923 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1924 invertSelection
->setWhatsThis(xi18nc("@info:whatsthis invert",
1926 "items that you have currently <emphasis>not</emphasis> selected instead."));
1927 invertSelection
->setIcon(QIcon::fromTheme(QStringLiteral("edit-select-invert")));
1928 actionCollection()->setDefaultShortcut(invertSelection
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
1929 connect(invertSelection
, &QAction::triggered
, this, &DolphinMainWindow::invertSelection
);
1931 QMenu
*toggleSelectionModeActionMenu
= new QMenu(this);
1932 toggleSelectionModeActionMenu
->addAction(selectAllAction
);
1933 toggleSelectionModeActionMenu
->addAction(invertSelection
);
1934 toggleSelectionModeToolBarAction
->setMenu(toggleSelectionModeActionMenu
);
1936 // setup 'View' menu
1937 // (note that most of it is set up in DolphinViewActionHandler)
1939 Admin::WorkerIntegration::createActAsAdminAction(actionCollection(), this);
1941 m_splitViewAction
= actionCollection()->add
<KActionMenu
>(QStringLiteral("split_view"));
1942 m_splitViewMenuAction
= actionCollection()->addAction(QStringLiteral("split_view_menu"));
1944 m_splitViewAction
->setWhatsThis(xi18nc("@info:whatsthis split",
1945 "<para>This presents "
1946 "a second view side-by-side with the current view, so you can see "
1947 "the contents of two folders at once and easily move items between "
1948 "them.</para><para>The view that is not \"in focus\" will be dimmed. "
1949 "</para>Click this button again to close one of the views."));
1950 m_splitViewMenuAction
->setWhatsThis(m_splitViewAction
->whatsThis());
1952 // only set it for the menu version
1953 actionCollection()->setDefaultShortcut(m_splitViewMenuAction
, Qt::Key_F3
);
1955 connect(m_splitViewAction
, &QAction::triggered
, this, &DolphinMainWindow::toggleSplitView
);
1956 connect(m_splitViewMenuAction
, &QAction::triggered
, this, &DolphinMainWindow::toggleSplitView
);
1958 QAction
*popoutSplit
= actionCollection()->addAction(QStringLiteral("popout_split_view"));
1959 popoutSplit
->setWhatsThis(xi18nc("@info:whatsthis",
1960 "If the view has been split, this will pop the view in focus "
1961 "out into a new window."));
1962 popoutSplit
->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
1963 actionCollection()->setDefaultShortcut(popoutSplit
, Qt::SHIFT
| Qt::Key_F3
);
1964 connect(popoutSplit
, &QAction::triggered
, this, &DolphinMainWindow::popoutSplitView
);
1966 QAction
*stashSplit
= actionCollection()->addAction(QStringLiteral("split_stash"));
1967 actionCollection()->setDefaultShortcut(stashSplit
, Qt::CTRL
| Qt::Key_S
);
1968 stashSplit
->setText(i18nc("@action:intoolbar Stash", "Stash"));
1969 stashSplit
->setToolTip(i18nc("@info", "Opens the stash virtual directory in a split window"));
1970 stashSplit
->setIcon(QIcon::fromTheme(QStringLiteral("folder-stash")));
1971 stashSplit
->setCheckable(false);
1972 QDBusConnectionInterface
*sessionInterface
= QDBusConnection::sessionBus().interface();
1973 stashSplit
->setVisible(sessionInterface
&& sessionInterface
->isServiceRegistered(QStringLiteral("org.kde.kio.StashNotifier")));
1974 connect(stashSplit
, &QAction::triggered
, this, &DolphinMainWindow::toggleSplitStash
);
1976 QAction
*redisplay
= KStandardAction::redisplay(this, &DolphinMainWindow::reloadView
, actionCollection());
1977 redisplay
->setToolTip(i18nc("@info:tooltip", "Refresh view"));
1978 redisplay
->setWhatsThis(xi18nc("@info:whatsthis refresh",
1979 "<para>This refreshes "
1980 "the folder view.</para>"
1981 "<para>If the contents of this folder have changed, refreshing will re-scan this folder "
1982 "and show you a newly-updated view of the files and folders contained here.</para>"
1983 "<para>If the view is split, this refreshes the one that is currently in focus.</para>"));
1985 QAction
*stop
= actionCollection()->addAction(QStringLiteral("stop"));
1986 stop
->setText(i18nc("@action:inmenu View", "Stop"));
1987 stop
->setToolTip(i18nc("@info", "Stop loading"));
1988 stop
->setWhatsThis(i18nc("@info", "This stops the loading of the contents of the current folder."));
1989 stop
->setIcon(QIcon::fromTheme(QStringLiteral("process-stop")));
1990 connect(stop
, &QAction::triggered
, this, &DolphinMainWindow::stopLoading
);
1992 KToggleAction
*editableLocation
= actionCollection()->add
<KToggleAction
>(QStringLiteral("editable_location"));
1993 editableLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1994 editableLocation
->setWhatsThis(xi18nc("@info:whatsthis",
1995 "This toggles the <emphasis>Location Bar</emphasis> to be "
1996 "editable so you can directly enter a location you want to go to.<nl/>"
1997 "You can also switch to editing by clicking to the right of the "
1998 "location and switch back by confirming the edited location."));
1999 actionCollection()->setDefaultShortcut(editableLocation
, Qt::Key_F6
);
2000 connect(editableLocation
, &KToggleAction::triggered
, this, &DolphinMainWindow::toggleEditLocation
);
2002 QAction
*replaceLocation
= actionCollection()->addAction(QStringLiteral("replace_location"));
2003 replaceLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
2004 // i18n: "enter" is used both in the meaning of "writing" and "going to" a new location here.
2005 // Both meanings are useful but not necessary to understand the use of "Replace Location".
2006 // So you might want to be more verbose in your language to convey the meaning but it's up to you.
2007 replaceLocation
->setWhatsThis(xi18nc("@info:whatsthis",
2008 "This switches to editing the location and selects it "
2009 "so you can quickly enter a different location."));
2010 actionCollection()->setDefaultShortcuts(replaceLocation
, {Qt::CTRL
| Qt::Key_L
, Qt::ALT
| Qt::Key_D
});
2011 connect(replaceLocation
, &QAction::triggered
, this, &DolphinMainWindow::replaceLocation
);
2015 QScopedPointer
<QAction
> backAction(KStandardAction::back(nullptr, nullptr, nullptr));
2016 m_backAction
= new KToolBarPopupAction(backAction
->icon(), backAction
->text(), actionCollection());
2017 m_backAction
->setObjectName(backAction
->objectName());
2018 m_backAction
->setShortcuts(backAction
->shortcuts());
2020 m_backAction
->setPopupMode(KToolBarPopupAction::DelayedPopup
);
2021 connect(m_backAction
, &QAction::triggered
, this, &DolphinMainWindow::goBack
);
2022 connect(m_backAction
->popupMenu(), &QMenu::aboutToShow
, this, &DolphinMainWindow::slotAboutToShowBackPopupMenu
);
2023 connect(m_backAction
->popupMenu(), &QMenu::triggered
, this, &DolphinMainWindow::slotGoBack
);
2024 actionCollection()->addAction(m_backAction
->objectName(), m_backAction
);
2026 auto backShortcuts
= m_backAction
->shortcuts();
2027 // Prepend this shortcut, to avoid being hidden by the two-slot UI (#371130)
2028 backShortcuts
.prepend(QKeySequence(Qt::Key_Backspace
));
2029 actionCollection()->setDefaultShortcuts(m_backAction
, backShortcuts
);
2031 DolphinRecentTabsMenu
*recentTabsMenu
= new DolphinRecentTabsMenu(this);
2032 actionCollection()->addAction(QStringLiteral("closed_tabs"), recentTabsMenu
);
2033 connect(m_tabWidget
, &DolphinTabWidget::rememberClosedTab
, recentTabsMenu
, &DolphinRecentTabsMenu::rememberClosedTab
);
2034 connect(recentTabsMenu
, &DolphinRecentTabsMenu::restoreClosedTab
, m_tabWidget
, &DolphinTabWidget::restoreClosedTab
);
2035 connect(recentTabsMenu
, &DolphinRecentTabsMenu::closedTabsCountChanged
, this, &DolphinMainWindow::closedTabsCountChanged
);
2037 QAction
*undoCloseTab
= actionCollection()->addAction(QStringLiteral("undo_close_tab"));
2038 undoCloseTab
->setText(i18nc("@action:inmenu File", "Undo close tab"));
2039 undoCloseTab
->setWhatsThis(i18nc("@info:whatsthis undo close tab", "This returns you to the previously closed tab."));
2040 actionCollection()->setDefaultShortcut(undoCloseTab
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_T
);
2041 undoCloseTab
->setIcon(QIcon::fromTheme(QStringLiteral("edit-undo")));
2042 undoCloseTab
->setEnabled(false);
2043 connect(undoCloseTab
, &QAction::triggered
, recentTabsMenu
, &DolphinRecentTabsMenu::undoCloseTab
);
2045 auto undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
2046 undoAction
->setWhatsThis(xi18nc("@info:whatsthis",
2048 "the last change you made to files or folders.<nl/>"
2049 "Such changes include <interface>creating</interface>, <interface>renaming</interface> "
2050 "and <interface>moving</interface> them to a different location "
2051 "or to the <filename>Trash</filename>. <nl/>Any changes that cannot be undone "
2052 "will ask for your confirmation beforehand."));
2053 undoAction
->setEnabled(false); // undo should be disabled by default
2056 QScopedPointer
<QAction
> forwardAction(KStandardAction::forward(nullptr, nullptr, nullptr));
2057 m_forwardAction
= new KToolBarPopupAction(forwardAction
->icon(), forwardAction
->text(), actionCollection());
2058 m_forwardAction
->setObjectName(forwardAction
->objectName());
2059 m_forwardAction
->setShortcuts(forwardAction
->shortcuts());
2061 m_forwardAction
->setPopupMode(KToolBarPopupAction::DelayedPopup
);
2062 connect(m_forwardAction
, &QAction::triggered
, this, &DolphinMainWindow::goForward
);
2063 connect(m_forwardAction
->popupMenu(), &QMenu::aboutToShow
, this, &DolphinMainWindow::slotAboutToShowForwardPopupMenu
);
2064 connect(m_forwardAction
->popupMenu(), &QMenu::triggered
, this, &DolphinMainWindow::slotGoForward
);
2065 actionCollection()->addAction(m_forwardAction
->objectName(), m_forwardAction
);
2066 actionCollection()->setDefaultShortcuts(m_forwardAction
, m_forwardAction
->shortcuts());
2068 // enable middle-click to open in a new tab
2069 auto *middleClickEventFilter
= new MiddleClickActionEventFilter(this);
2070 connect(middleClickEventFilter
, &MiddleClickActionEventFilter::actionMiddleClicked
, this, &DolphinMainWindow::slotBackForwardActionMiddleClicked
);
2071 m_backAction
->popupMenu()->installEventFilter(middleClickEventFilter
);
2072 m_forwardAction
->popupMenu()->installEventFilter(middleClickEventFilter
);
2073 KStandardAction::up(this, &DolphinMainWindow::goUp
, actionCollection());
2074 QAction
*homeAction
= KStandardAction::home(this, &DolphinMainWindow::goHome
, actionCollection());
2075 homeAction
->setWhatsThis(xi18nc("@info:whatsthis",
2077 "<filename>Home</filename> folder.<nl/>Every user account "
2078 "has their own <filename>Home</filename> that contains their personal files, "
2079 "as well as hidden folders for their applications' data and configuration files."));
2081 // setup 'Tools' menu
2082 QAction
*compareFiles
= actionCollection()->addAction(QStringLiteral("compare_files"));
2083 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
2084 compareFiles
->setIcon(QIcon::fromTheme(QStringLiteral("kompare")));
2085 compareFiles
->setEnabled(false);
2086 connect(compareFiles
, &QAction::triggered
, this, &DolphinMainWindow::compareFiles
);
2088 QAction
*openPreferredSearchTool
= actionCollection()->addAction(QStringLiteral("open_preferred_search_tool"));
2089 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool"));
2090 openPreferredSearchTool
->setWhatsThis(xi18nc("@info:whatsthis",
2091 "<para>This opens a preferred search tool for the viewed location.</para>"
2092 "<para>Use <emphasis>More Search Tools</emphasis> menu to configure it.</para>"));
2093 openPreferredSearchTool
->setIcon(QIcon::fromTheme(QStringLiteral("search")));
2094 actionCollection()->setDefaultShortcut(openPreferredSearchTool
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_F
);
2095 connect(openPreferredSearchTool
, &QAction::triggered
, this, &DolphinMainWindow::openPreferredSearchTool
);
2097 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
2098 // Get icon of user default terminal emulator application
2099 const KConfigGroup
group(KSharedConfig::openConfig(QStringLiteral("kdeglobals"), KConfig::SimpleConfig
), QStringLiteral("General"));
2100 const QString terminalDesktopFilename
= group
.readEntry("TerminalService");
2101 // Use utilities-terminal icon from theme if readEntry() has failed
2102 const QString terminalIcon
= terminalDesktopFilename
.isEmpty() ? "utilities-terminal" : KDesktopFile(terminalDesktopFilename
).readIcon();
2104 QAction
*openTerminal
= actionCollection()->addAction(QStringLiteral("open_terminal"));
2105 openTerminal
->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
2106 openTerminal
->setWhatsThis(xi18nc("@info:whatsthis",
2107 "<para>This opens a <emphasis>terminal</emphasis> application for the viewed location.</para>"
2108 "<para>To learn more about terminals use the help features in the terminal application.</para>"));
2109 openTerminal
->setIcon(QIcon::fromTheme(terminalIcon
));
2110 actionCollection()->setDefaultShortcut(openTerminal
, Qt::SHIFT
| Qt::Key_F4
);
2111 connect(openTerminal
, &QAction::triggered
, this, &DolphinMainWindow::openTerminal
);
2113 QAction
*openTerminalHere
= actionCollection()->addAction(QStringLiteral("open_terminal_here"));
2114 // i18n: "Here" refers to the location(s) of the currently selected item(s) or the currently viewed location if nothing is selected.
2115 openTerminalHere
->setText(i18nc("@action:inmenu Tools", "Open Terminal Here"));
2116 openTerminalHere
->setWhatsThis(xi18nc("@info:whatsthis",
2117 "<para>This opens <emphasis>terminal</emphasis> applications for the selected items' locations.</para>"
2118 "<para>To learn more about terminals use the help features in the terminal application.</para>"));
2119 openTerminalHere
->setIcon(QIcon::fromTheme(terminalIcon
));
2120 actionCollection()->setDefaultShortcut(openTerminalHere
, Qt::SHIFT
| Qt::ALT
| Qt::Key_F4
);
2121 connect(openTerminalHere
, &QAction::triggered
, this, &DolphinMainWindow::openTerminalHere
);
2124 // setup 'Bookmarks' menu
2125 KActionMenu
*bookmarkMenu
= new KActionMenu(i18nc("@title:menu", "&Bookmarks"), this);
2126 bookmarkMenu
->setIcon(QIcon::fromTheme(QStringLiteral("bookmarks")));
2127 // Make the toolbar button version work properly on click
2128 bookmarkMenu
->setPopupMode(QToolButton::InstantPopup
);
2129 m_bookmarkHandler
= new DolphinBookmarkHandler(this, actionCollection(), bookmarkMenu
->menu(), this);
2130 actionCollection()->addAction(QStringLiteral("bookmarks"), bookmarkMenu
);
2132 // setup 'Settings' menu
2133 KToggleAction
*showMenuBar
= KStandardAction::showMenubar(nullptr, nullptr, actionCollection());
2134 showMenuBar
->setWhatsThis(xi18nc("@info:whatsthis",
2135 "<para>This switches between having a <emphasis>Menubar</emphasis> "
2136 "and having an <interface>%1</interface> button. Both "
2137 "contain mostly the same actions and configuration options.</para>"
2138 "<para>The Menubar takes up more space but allows for fast and organized access to all "
2139 "actions an application has to offer.</para><para>The %1 button "
2140 "is simpler and small which makes triggering advanced actions more time consuming.</para>",
2141 hamburgerMenuAction
->text().replace('&', "")));
2142 connect(showMenuBar
,
2143 &KToggleAction::triggered
, // Fixes #286822
2145 &DolphinMainWindow::toggleShowMenuBar
,
2146 Qt::QueuedConnection
);
2148 KStandardAction::keyBindings(this, &DolphinMainWindow::slotKeyBindings
, actionCollection());
2149 KStandardAction::preferences(this, &DolphinMainWindow::editSettings
, actionCollection());
2151 // not in menu actions
2152 QList
<QKeySequence
> nextTabKeys
= KStandardShortcut::tabNext();
2153 nextTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::Key_Tab
));
2155 QList
<QKeySequence
> prevTabKeys
= KStandardShortcut::tabPrev();
2156 prevTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::SHIFT
| Qt::Key_Tab
));
2158 for (int i
= 0; i
< MaxActivateTabShortcuts
; ++i
) {
2159 QAction
*activateTab
= actionCollection()->addAction(QStringLiteral("activate_tab_%1").arg(i
));
2160 activateTab
->setText(i18nc("@action:inmenu", "Go to Tab %1", i
+ 1));
2161 activateTab
->setEnabled(false);
2162 connect(activateTab
, &QAction::triggered
, this, [this, i
]() {
2163 m_tabWidget
->activateTab(i
);
2166 // only add default shortcuts for the first 9 tabs regardless of MaxActivateTabShortcuts
2168 actionCollection()->setDefaultShortcut(activateTab
, QStringLiteral("Alt+%1").arg(i
+ 1));
2172 QAction
*activateLastTab
= actionCollection()->addAction(QStringLiteral("activate_last_tab"));
2173 activateLastTab
->setIconText(i18nc("@action:inmenu", "Last Tab"));
2174 activateLastTab
->setText(i18nc("@action:inmenu", "Go to Last Tab"));
2175 activateLastTab
->setEnabled(false);
2176 connect(activateLastTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activateLastTab
);
2177 actionCollection()->setDefaultShortcut(activateLastTab
, Qt::ALT
| Qt::Key_0
);
2179 QAction
*activateNextTab
= actionCollection()->addAction(QStringLiteral("activate_next_tab"));
2180 activateNextTab
->setIconText(i18nc("@action:inmenu", "Next Tab"));
2181 activateNextTab
->setText(i18nc("@action:inmenu", "Go to Next Tab"));
2182 activateNextTab
->setEnabled(false);
2183 connect(activateNextTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activateNextTab
);
2184 actionCollection()->setDefaultShortcuts(activateNextTab
, nextTabKeys
);
2186 QAction
*activatePrevTab
= actionCollection()->addAction(QStringLiteral("activate_prev_tab"));
2187 activatePrevTab
->setIconText(i18nc("@action:inmenu", "Previous Tab"));
2188 activatePrevTab
->setText(i18nc("@action:inmenu", "Go to Previous Tab"));
2189 activatePrevTab
->setEnabled(false);
2190 connect(activatePrevTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activatePrevTab
);
2191 actionCollection()->setDefaultShortcuts(activatePrevTab
, prevTabKeys
);
2194 QAction
*showTarget
= actionCollection()->addAction(QStringLiteral("show_target"));
2195 showTarget
->setText(i18nc("@action:inmenu", "Show Target"));
2196 showTarget
->setIcon(QIcon::fromTheme(QStringLiteral("document-open-folder")));
2197 showTarget
->setEnabled(false);
2198 connect(showTarget
, &QAction::triggered
, this, &DolphinMainWindow::showTarget
);
2200 QAction
*openInNewTab
= actionCollection()->addAction(QStringLiteral("open_in_new_tab"));
2201 openInNewTab
->setText(i18nc("@action:inmenu", "Open in New Tab"));
2202 openInNewTab
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
2203 connect(openInNewTab
, &QAction::triggered
, this, &DolphinMainWindow::openInNewTab
);
2205 QAction
*openInNewTabs
= actionCollection()->addAction(QStringLiteral("open_in_new_tabs"));
2206 openInNewTabs
->setText(i18nc("@action:inmenu", "Open in New Tabs"));
2207 openInNewTabs
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
2208 connect(openInNewTabs
, &QAction::triggered
, this, &DolphinMainWindow::openInNewTab
);
2210 QAction
*openInNewWindow
= actionCollection()->addAction(QStringLiteral("open_in_new_window"));
2211 openInNewWindow
->setText(i18nc("@action:inmenu", "Open in New Window"));
2212 openInNewWindow
->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
2213 connect(openInNewWindow
, &QAction::triggered
, this, &DolphinMainWindow::openInNewWindow
);
2215 QAction
*openInSplitViewAction
= actionCollection()->addAction(QStringLiteral("open_in_split_view"));
2216 openInSplitViewAction
->setText(i18nc("@action:inmenu", "Open in Split View"));
2217 openInSplitViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-split-left-right")));
2218 connect(openInSplitViewAction
, &QAction::triggered
, this, [this]() {
2219 openInSplitView(QUrl());
2222 m_recentFiles
= new KRecentFilesAction(this);
2225 void DolphinMainWindow::setupDockWidgets()
2227 const bool lock
= GeneralSettings::lockPanels();
2229 DolphinPlacesModelSingleton::instance().placesModel()->setPanelsLocked(lock
);
2231 KDualAction
*lockLayoutAction
= actionCollection()->add
<KDualAction
>(QStringLiteral("lock_panels"));
2232 lockLayoutAction
->setActiveText(i18nc("@action:inmenu Panels", "Unlock Panels"));
2233 lockLayoutAction
->setActiveIcon(QIcon::fromTheme(QStringLiteral("object-unlocked")));
2234 lockLayoutAction
->setInactiveText(i18nc("@action:inmenu Panels", "Lock Panels"));
2235 lockLayoutAction
->setInactiveIcon(QIcon::fromTheme(QStringLiteral("object-locked")));
2236 lockLayoutAction
->setWhatsThis(xi18nc("@info:whatsthis",
2238 "switches between having panels <emphasis>locked</emphasis> or "
2239 "<emphasis>unlocked</emphasis>.<nl/>Unlocked panels can be "
2240 "dragged to the other side of the window and have a close "
2241 "button.<nl/>Locked panels are embedded more cleanly."));
2242 lockLayoutAction
->setActive(lock
);
2243 connect(lockLayoutAction
, &KDualAction::triggered
, this, &DolphinMainWindow::togglePanelLockState
);
2245 // Setup "Information"
2246 DolphinDockWidget
*infoDock
= new DolphinDockWidget(i18nc("@title:window", "Information"));
2247 infoDock
->setLocked(lock
);
2248 infoDock
->setObjectName(QStringLiteral("infoDock"));
2249 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
2252 InformationPanel
*infoPanel
= new InformationPanel(infoDock
);
2253 infoPanel
->setCustomContextMenuActions({lockLayoutAction
});
2254 connect(infoPanel
, &InformationPanel::urlActivated
, this, &DolphinMainWindow::handleUrl
);
2255 infoDock
->setWidget(infoPanel
);
2257 createPanelAction(QIcon::fromTheme(QStringLiteral("documentinfo")), Qt::Key_F11
, infoDock
, QStringLiteral("show_information_panel"));
2259 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
2260 connect(this, &DolphinMainWindow::urlChanged
, infoPanel
, &InformationPanel::setUrl
);
2261 connect(this, &DolphinMainWindow::selectionChanged
, infoPanel
, &InformationPanel::setSelection
);
2262 connect(this, &DolphinMainWindow::requestItemInfo
, infoPanel
, &InformationPanel::requestDelayedItemInfo
);
2263 connect(this, &DolphinMainWindow::fileItemsChanged
, infoPanel
, &InformationPanel::slotFilesItemChanged
);
2264 connect(this, &DolphinMainWindow::settingsChanged
, infoPanel
, &InformationPanel::readSettings
);
2267 // i18n: This is the last paragraph for the "What's This"-texts of all four panels.
2268 const QString panelWhatsThis
= xi18nc("@info:whatsthis",
2270 "hide panels like this go to <interface>Menu|Panels</interface> "
2271 "or <interface>View|Panels</interface>.</para>");
2274 ->action(QStringLiteral("show_information_panel"))
2275 ->setWhatsThis(xi18nc("@info:whatsthis",
2276 "<para> This toggles the "
2277 "<emphasis>information</emphasis> panel at the right side of the "
2278 "window.</para><para>The panel provides in-depth information "
2279 "about the items your mouse is hovering over or about the selected "
2280 "items. Otherwise it informs you about the currently viewed folder.<nl/>"
2281 "For single items a preview of their contents is provided.</para>"));
2283 infoDock
->setWhatsThis(xi18nc("@info:whatsthis",
2285 "provides in-depth information about the items your mouse is "
2286 "hovering over or about the selected items. Otherwise it informs "
2287 "you about the currently viewed folder.<nl/>For single items a "
2288 "preview of their contents is provided.</para><para>You can configure "
2289 "which and how details are given here by right-clicking.</para>")
2293 DolphinDockWidget
*foldersDock
= new DolphinDockWidget(i18nc("@title:window", "Folders"));
2294 foldersDock
->setLocked(lock
);
2295 foldersDock
->setObjectName(QStringLiteral("foldersDock"));
2296 foldersDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
2297 FoldersPanel
*foldersPanel
= new FoldersPanel(foldersDock
);
2298 foldersPanel
->setCustomContextMenuActions({lockLayoutAction
});
2299 foldersDock
->setWidget(foldersPanel
);
2301 createPanelAction(QIcon::fromTheme(QStringLiteral("folder")), Qt::Key_F7
, foldersDock
, QStringLiteral("show_folders_panel"));
2303 addDockWidget(Qt::LeftDockWidgetArea
, foldersDock
);
2304 connect(this, &DolphinMainWindow::urlChanged
, foldersPanel
, &FoldersPanel::setUrl
);
2305 connect(foldersPanel
, &FoldersPanel::folderActivated
, this, &DolphinMainWindow::changeUrl
);
2306 connect(foldersPanel
, &FoldersPanel::folderInNewTab
, this, &DolphinMainWindow::openNewTab
);
2307 connect(foldersPanel
, &FoldersPanel::folderInNewActiveTab
, this, &DolphinMainWindow::openNewTabAndActivate
);
2308 connect(foldersPanel
, &FoldersPanel::errorMessage
, this, &DolphinMainWindow::showErrorMessage
);
2311 ->action(QStringLiteral("show_folders_panel"))
2312 ->setWhatsThis(xi18nc("@info:whatsthis",
2314 "<emphasis>folders</emphasis> panel at the left side of the window."
2315 "<nl/><nl/>It shows the folders of the <emphasis>file system"
2316 "</emphasis> in a <emphasis>tree view</emphasis>."));
2317 foldersDock
->setWhatsThis(xi18nc("@info:whatsthis",
2319 "shows the folders of the <emphasis>file system</emphasis> in a "
2320 "<emphasis>tree view</emphasis>.</para><para>Click a folder to go "
2321 "there. Click the arrow to the left of a folder to see its subfolders. "
2322 "This allows quick switching between any folders.</para>")
2327 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
2328 DolphinDockWidget
*terminalDock
= new DolphinDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
2329 terminalDock
->setLocked(lock
);
2330 terminalDock
->setObjectName(QStringLiteral("terminalDock"));
2331 terminalDock
->setContentsMargins(0, 0, 0, 0);
2332 m_terminalPanel
= new TerminalPanel(terminalDock
);
2333 m_terminalPanel
->setCustomContextMenuActions({lockLayoutAction
});
2334 terminalDock
->setWidget(m_terminalPanel
);
2336 connect(m_terminalPanel
, &TerminalPanel::hideTerminalPanel
, terminalDock
, &DolphinDockWidget::hide
);
2337 connect(m_terminalPanel
, &TerminalPanel::changeUrl
, this, &DolphinMainWindow::slotTerminalDirectoryChanged
);
2338 connect(terminalDock
, &DolphinDockWidget::visibilityChanged
, m_terminalPanel
, &TerminalPanel::dockVisibilityChanged
);
2339 connect(terminalDock
, &DolphinDockWidget::visibilityChanged
, this, &DolphinMainWindow::slotTerminalPanelVisibilityChanged
);
2341 createPanelAction(QIcon::fromTheme(QStringLiteral("dialog-scripts")), Qt::Key_F4
, terminalDock
, QStringLiteral("show_terminal_panel"));
2343 addDockWidget(Qt::BottomDockWidgetArea
, terminalDock
);
2344 connect(this, &DolphinMainWindow::urlChanged
, m_terminalPanel
, &TerminalPanel::setUrl
);
2346 if (GeneralSettings::version() < 200) {
2347 terminalDock
->hide();
2351 ->action(QStringLiteral("show_terminal_panel"))
2352 ->setWhatsThis(xi18nc("@info:whatsthis",
2353 "<para>This toggles the "
2354 "<emphasis>terminal</emphasis> panel at the bottom of the window."
2355 "<nl/>The location in the terminal will always match the folder "
2356 "view so you can navigate using either.</para><para>The terminal "
2357 "panel is not needed for basic computer usage but can be useful "
2358 "for advanced tasks. To learn more about terminals use the help features "
2359 "in a standalone terminal application like Konsole.</para>"));
2360 terminalDock
->setWhatsThis(xi18nc("@info:whatsthis",
2362 "the <emphasis>terminal</emphasis> panel. It behaves like a "
2363 "normal terminal but will match the location of the folder view "
2364 "so you can navigate using either.</para><para>The terminal panel "
2365 "is not needed for basic computer usage but can be useful for "
2366 "advanced tasks. To learn more about terminals use the help features in a "
2367 "standalone terminal application like Konsole.</para>")
2370 QAction
*focusTerminalPanel
= actionCollection()->addAction(QStringLiteral("focus_terminal_panel"));
2371 focusTerminalPanel
->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
2372 focusTerminalPanel
->setToolTip(i18nc("@info:tooltip", "Move keyboard focus to and from the Terminal panel."));
2373 focusTerminalPanel
->setIcon(QIcon::fromTheme(QStringLiteral("swap-panels")));
2374 actionCollection()->setDefaultShortcut(focusTerminalPanel
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_F4
);
2375 connect(focusTerminalPanel
, &QAction::triggered
, this, &DolphinMainWindow::toggleTerminalPanelFocus
);
2376 } // endif "shell_access" allowed
2377 #endif // HAVE_TERMINAL
2379 if (GeneralSettings::version() < 200) {
2381 foldersDock
->hide();
2385 DolphinDockWidget
*placesDock
= new DolphinDockWidget(i18nc("@title:window", "Places"));
2386 placesDock
->setLocked(lock
);
2387 placesDock
->setObjectName(QStringLiteral("placesDock"));
2388 placesDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
2390 m_placesPanel
= new PlacesPanel(placesDock
);
2391 m_placesPanel
->setCustomContextMenuActions({lockLayoutAction
});
2392 placesDock
->setWidget(m_placesPanel
);
2394 createPanelAction(QIcon::fromTheme(QStringLiteral("compass")), Qt::Key_F9
, placesDock
, QStringLiteral("show_places_panel"));
2396 addDockWidget(Qt::LeftDockWidgetArea
, placesDock
);
2397 connect(m_placesPanel
, &PlacesPanel::placeActivated
, this, &DolphinMainWindow::slotPlaceActivated
);
2398 connect(m_placesPanel
, &PlacesPanel::tabRequested
, this, &DolphinMainWindow::openNewTab
);
2399 connect(m_placesPanel
, &PlacesPanel::activeTabRequested
, this, &DolphinMainWindow::openNewTabAndActivate
);
2400 connect(m_placesPanel
, &PlacesPanel::newWindowRequested
, this, [this](const QUrl
&url
) {
2401 Dolphin::openNewWindow({url
}, this);
2403 connect(m_placesPanel
, &PlacesPanel::openInSplitViewRequested
, this, &DolphinMainWindow::openInSplitView
);
2404 connect(m_placesPanel
, &PlacesPanel::errorMessage
, this, &DolphinMainWindow::showErrorMessage
);
2405 connect(this, &DolphinMainWindow::urlChanged
, m_placesPanel
, &PlacesPanel::setUrl
);
2406 connect(placesDock
, &DolphinDockWidget::visibilityChanged
, &DolphinUrlNavigatorsController::slotPlacesPanelVisibilityChanged
);
2407 connect(placesDock
, &DolphinDockWidget::visibilityChanged
, this, &DolphinMainWindow::slotPlacesPanelVisibilityChanged
);
2408 connect(this, &DolphinMainWindow::settingsChanged
, m_placesPanel
, &PlacesPanel::readSettings
);
2409 connect(m_placesPanel
, &PlacesPanel::storageTearDownRequested
, this, &DolphinMainWindow::slotStorageTearDownFromPlacesRequested
);
2410 connect(m_placesPanel
, &PlacesPanel::storageTearDownExternallyRequested
, this, &DolphinMainWindow::slotStorageTearDownExternallyRequested
);
2411 DolphinUrlNavigatorsController::slotPlacesPanelVisibilityChanged(m_placesPanel
->isVisible());
2413 auto actionShowAllPlaces
= new QAction(QIcon::fromTheme(QStringLiteral("view-hidden")), i18nc("@item:inmenu", "Show Hidden Places"), this);
2414 actionShowAllPlaces
->setCheckable(true);
2415 actionShowAllPlaces
->setDisabled(true);
2416 actionShowAllPlaces
->setWhatsThis(i18nc("@info:whatsthis",
2418 "all places in the places panel that have been hidden. They will "
2419 "appear semi-transparent and allow you to uncheck their \"Hide\" property."));
2421 connect(actionShowAllPlaces
, &QAction::triggered
, this, [this](bool checked
) {
2422 m_placesPanel
->setShowAll(checked
);
2424 connect(m_placesPanel
, &PlacesPanel::allPlacesShownChanged
, actionShowAllPlaces
, &QAction::setChecked
);
2427 ->action(QStringLiteral("show_places_panel"))
2428 ->setWhatsThis(xi18nc("@info:whatsthis",
2429 "<para>This toggles the "
2430 "<emphasis>places</emphasis> panel at the left side of the window."
2431 "</para><para>It allows you to go to locations you have "
2432 "bookmarked and to access disk or media attached to the computer "
2433 "or to the network. It also contains sections to find recently "
2434 "saved files or files of a certain type.</para>"));
2435 placesDock
->setWhatsThis(xi18nc("@info:whatsthis",
2436 "<para>This is the "
2437 "<emphasis>Places</emphasis> panel. It allows you to go to locations "
2438 "you have bookmarked and to access disk or media attached to the "
2439 "computer or to the network. It also contains sections to find "
2440 "recently saved files or files of a certain type.</para><para>"
2441 "Click on an entry to go there. Click with the right mouse button "
2442 "instead to open any entry in a new tab or new window.</para>"
2443 "<para>New entries can be added by dragging folders onto this panel. "
2444 "Right-click any section or entry to hide it. Right-click an empty "
2445 "space on this panel and select <interface>Show Hidden Places"
2446 "</interface> to display it again.</para>")
2449 QAction
*focusPlacesPanel
= actionCollection()->addAction(QStringLiteral("focus_places_panel"));
2450 focusPlacesPanel
->setText(i18nc("@action:inmenu View", "Focus Places Panel"));
2451 focusPlacesPanel
->setToolTip(i18nc("@info:tooltip", "Move keyboard focus to and from the Places panel."));
2452 focusPlacesPanel
->setIcon(QIcon::fromTheme(QStringLiteral("swap-panels")));
2453 actionCollection()->setDefaultShortcut(focusPlacesPanel
, Qt::CTRL
| Qt::Key_P
);
2454 connect(focusPlacesPanel
, &QAction::triggered
, this, &DolphinMainWindow::togglePlacesPanelFocus
);
2456 // Add actions into the "Panels" menu
2457 KActionMenu
*panelsMenu
= new KActionMenu(i18nc("@action:inmenu View", "Show Panels"), this);
2458 actionCollection()->addAction(QStringLiteral("panels"), panelsMenu
);
2459 panelsMenu
->setIcon(QIcon::fromTheme(QStringLiteral("view-sidetree")));
2460 panelsMenu
->setPopupMode(QToolButton::InstantPopup
);
2461 const KActionCollection
*ac
= actionCollection();
2462 panelsMenu
->addAction(ac
->action(QStringLiteral("show_places_panel")));
2464 panelsMenu
->addAction(ac
->action(QStringLiteral("show_information_panel")));
2466 panelsMenu
->addAction(ac
->action(QStringLiteral("show_folders_panel")));
2467 panelsMenu
->addAction(ac
->action(QStringLiteral("show_terminal_panel")));
2468 panelsMenu
->addSeparator();
2469 panelsMenu
->addAction(lockLayoutAction
);
2470 panelsMenu
->addSeparator();
2471 panelsMenu
->addAction(actionShowAllPlaces
);
2472 panelsMenu
->addAction(focusPlacesPanel
);
2473 panelsMenu
->addAction(ac
->action(QStringLiteral("focus_terminal_panel")));
2475 connect(panelsMenu
->menu(), &QMenu::aboutToShow
, this, [actionShowAllPlaces
] {
2476 actionShowAllPlaces
->setEnabled(DolphinPlacesModelSingleton::instance().placesModel()->hiddenCount());
2480 void DolphinMainWindow::updateFileAndEditActions()
2482 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
2483 const KActionCollection
*col
= actionCollection();
2484 KFileItemListProperties
capabilitiesSource(list
);
2486 QAction
*renameAction
= col
->action(KStandardAction::name(KStandardAction::RenameFile
));
2487 QAction
*moveToTrashAction
= col
->action(KStandardAction::name(KStandardAction::MoveToTrash
));
2488 QAction
*deleteAction
= col
->action(KStandardAction::name(KStandardAction::DeleteFile
));
2489 QAction
*cutAction
= col
->action(KStandardAction::name(KStandardAction::Cut
));
2490 QAction
*duplicateAction
= col
->action(QStringLiteral("duplicate")); // see DolphinViewActionHandler
2491 QAction
*addToPlacesAction
= col
->action(QStringLiteral("add_to_places"));
2492 QAction
*copyToOtherViewAction
= col
->action(QStringLiteral("copy_to_inactive_split_view"));
2493 QAction
*moveToOtherViewAction
= col
->action(QStringLiteral("move_to_inactive_split_view"));
2494 QAction
*copyLocation
= col
->action(QStringLiteral("copy_location"));
2496 if (list
.isEmpty()) {
2497 stateChanged(QStringLiteral("has_no_selection"));
2499 // All actions that need a selection to function can be enabled because they should trigger selection mode.
2500 renameAction
->setEnabled(true);
2501 moveToTrashAction
->setEnabled(true);
2502 deleteAction
->setEnabled(true);
2503 cutAction
->setEnabled(true);
2504 duplicateAction
->setEnabled(true);
2505 addToPlacesAction
->setEnabled(true);
2506 copyLocation
->setEnabled(true);
2507 // Them triggering selection mode and not directly acting on selected items is signified by adding "…" to their text.
2508 m_actionTextHelper
->textsWhenNothingIsSelectedEnabled(true);
2511 m_actionTextHelper
->textsWhenNothingIsSelectedEnabled(false);
2512 stateChanged(QStringLiteral("has_selection"));
2514 QAction
*deleteWithTrashShortcut
= col
->action(QStringLiteral("delete_shortcut")); // see DolphinViewActionHandler
2515 QAction
*showTarget
= col
->action(QStringLiteral("show_target"));
2517 if (list
.length() == 1 && list
.first().isDir()) {
2518 addToPlacesAction
->setEnabled(true);
2520 addToPlacesAction
->setEnabled(false);
2523 const bool enableMoveToTrash
= capabilitiesSource
.isLocal() && capabilitiesSource
.supportsMoving();
2525 renameAction
->setEnabled(capabilitiesSource
.supportsMoving());
2526 m_disabledActionNotifier
->setDisabledReason(renameAction
, i18nc("@info", "Cannot rename: You do not have permission to rename items in this folder."));
2527 deleteAction
->setEnabled(capabilitiesSource
.supportsDeleting());
2528 m_disabledActionNotifier
->setDisabledReason(deleteAction
,
2529 i18nc("@info", "Cannot delete: You do not have permission to remove items from this folder."));
2530 cutAction
->setEnabled(capabilitiesSource
.supportsMoving());
2531 m_disabledActionNotifier
->setDisabledReason(cutAction
, i18nc("@info", "Cannot cut: You do not have permission to move items from this folder."));
2532 copyLocation
->setEnabled(list
.length() == 1);
2533 showTarget
->setEnabled(list
.length() == 1 && list
.at(0).isLink());
2534 duplicateAction
->setEnabled(capabilitiesSource
.supportsWriting());
2535 m_disabledActionNotifier
->setDisabledReason(duplicateAction
,
2536 i18nc("@info", "Cannot duplicate here: You do not have permission to create items in this folder."));
2538 if (enableMoveToTrash
) {
2539 moveToTrashAction
->setEnabled(true);
2540 deleteWithTrashShortcut
->setEnabled(false);
2541 m_disabledActionNotifier
->clearDisabledReason(deleteWithTrashShortcut
);
2543 moveToTrashAction
->setEnabled(false);
2544 deleteWithTrashShortcut
->setEnabled(capabilitiesSource
.supportsDeleting());
2545 m_disabledActionNotifier
->setDisabledReason(deleteWithTrashShortcut
,
2546 i18nc("@info", "Cannot delete: You do not have permission to remove items from this folder."));
2550 if (!m_tabWidget
->currentTabPage()->splitViewEnabled()) {
2551 // No need to set the disabled reason here, as it's obvious to the user that the reason is the split view being disabled.
2552 copyToOtherViewAction
->setEnabled(false);
2553 m_disabledActionNotifier
->clearDisabledReason(copyToOtherViewAction
);
2554 moveToOtherViewAction
->setEnabled(false);
2555 m_disabledActionNotifier
->clearDisabledReason(moveToOtherViewAction
);
2556 } else if (list
.isEmpty()) {
2557 copyToOtherViewAction
->setEnabled(false);
2558 m_disabledActionNotifier
->setDisabledReason(copyToOtherViewAction
, i18nc("@info", "Cannot copy to other view: No files selected."));
2559 moveToOtherViewAction
->setEnabled(false);
2560 m_disabledActionNotifier
->setDisabledReason(moveToOtherViewAction
, i18nc("@info", "Cannot move to other view: No files selected."));
2562 DolphinTabPage
*tabPage
= m_tabWidget
->currentTabPage();
2563 KFileItem capabilitiesDestination
;
2565 if (tabPage
->primaryViewActive()) {
2566 capabilitiesDestination
= tabPage
->secondaryViewContainer()->rootItem();
2568 capabilitiesDestination
= tabPage
->primaryViewContainer()->rootItem();
2571 const auto destUrl
= capabilitiesDestination
.url();
2572 const bool allNotTargetOrigin
= std::all_of(list
.cbegin(), list
.cend(), [destUrl
](const KFileItem
&item
) {
2573 return item
.url().adjusted(QUrl::RemoveFilename
| QUrl::StripTrailingSlash
) != destUrl
;
2576 if (!allNotTargetOrigin
) {
2577 copyToOtherViewAction
->setEnabled(false);
2578 m_disabledActionNotifier
->setDisabledReason(copyToOtherViewAction
,
2579 i18nc("@info", "Cannot copy to other view: The other view already contains these items."));
2580 moveToOtherViewAction
->setEnabled(false);
2581 m_disabledActionNotifier
->setDisabledReason(moveToOtherViewAction
,
2582 i18nc("@info", "Cannot move to other view: The other view already contains these items."));
2583 } else if (!capabilitiesDestination
.isWritable()) {
2584 copyToOtherViewAction
->setEnabled(false);
2585 m_disabledActionNotifier
->setDisabledReason(
2586 copyToOtherViewAction
,
2587 i18nc("@info", "Cannot copy to other view: You do not have permission to write into the destination folder."));
2588 moveToOtherViewAction
->setEnabled(false);
2589 m_disabledActionNotifier
->setDisabledReason(
2590 moveToOtherViewAction
,
2591 i18nc("@info", "Cannot move to other view: You do not have permission to write into the destination folder."));
2593 copyToOtherViewAction
->setEnabled(true);
2594 moveToOtherViewAction
->setEnabled(capabilitiesSource
.supportsMoving());
2595 m_disabledActionNotifier
->setDisabledReason(
2596 moveToOtherViewAction
,
2597 i18nc("@info", "Cannot move to other view: You do not have permission to move items from this folder."));
2602 void DolphinMainWindow::updateViewActions()
2604 m_actionHandler
->updateViewActions();
2606 QAction
*toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
2607 toggleFilterBarAction
->setChecked(m_activeViewContainer
->isFilterBarVisible());
2609 updateSplitActions();
2612 void DolphinMainWindow::updateGoActions()
2614 QAction
*goUpAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Up
));
2615 const QUrl currentUrl
= m_activeViewContainer
->url();
2616 // I think this is one of the best places to firstly be confronted
2617 // with a file system and its hierarchy. Talking about the root
2618 // directory might seem too much here but it is the question that
2619 // naturally arises in this context.
2620 goUpAction
->setWhatsThis(xi18nc("@info:whatsthis",
2622 "the folder that contains the currently viewed one.</para>"
2623 "<para>All files and folders are organized in a hierarchical "
2624 "<emphasis>file system</emphasis>. At the top of this hierarchy is "
2625 "a directory that contains all data connected to this computer"
2626 "—the <emphasis>root directory</emphasis>.</para>"));
2627 goUpAction
->setEnabled(KIO::upUrl(currentUrl
) != currentUrl
);
2630 void DolphinMainWindow::refreshViews()
2632 m_tabWidget
->refreshViews();
2634 if (GeneralSettings::modifiedStartupSettings()) {
2635 updateWindowTitle();
2638 updateSplitActions();
2640 Q_EMIT
settingsChanged();
2643 void DolphinMainWindow::clearStatusBar()
2645 m_activeViewContainer
->statusBar()->resetToDefaultText();
2648 void DolphinMainWindow::connectViewSignals(DolphinViewContainer
*container
)
2650 connect(container
, &DolphinViewContainer::showFilterBarChanged
, this, &DolphinMainWindow::updateFilterBarAction
);
2651 connect(container
, &DolphinViewContainer::writeStateChanged
, this, &DolphinMainWindow::slotWriteStateChanged
);
2652 slotWriteStateChanged(container
->view()->isFolderWritable());
2653 connect(container
, &DolphinViewContainer::searchBarVisibilityChanged
, this, &DolphinMainWindow::updateSearchAction
);
2654 connect(container
, &DolphinViewContainer::captionChanged
, this, &DolphinMainWindow::updateWindowTitle
);
2655 connect(container
, &DolphinViewContainer::tabRequested
, this, &DolphinMainWindow::openNewTab
);
2656 connect(container
, &DolphinViewContainer::activeTabRequested
, this, &DolphinMainWindow::openNewTabAndActivate
);
2658 // Make the toggled state of the selection mode actions visually follow the selection mode state of the view.
2659 auto toggleSelectionModeAction
= actionCollection()->action(QStringLiteral("toggle_selection_mode"));
2660 toggleSelectionModeAction
->setChecked(m_activeViewContainer
->isSelectionModeEnabled());
2661 connect(m_activeViewContainer
, &DolphinViewContainer::selectionModeChanged
, toggleSelectionModeAction
, &QAction::setChecked
);
2663 const DolphinView
*view
= container
->view();
2664 connect(view
, &DolphinView::selectionChanged
, this, &DolphinMainWindow::slotSelectionChanged
);
2665 connect(view
, &DolphinView::requestItemInfo
, this, &DolphinMainWindow::requestItemInfo
);
2666 connect(view
, &DolphinView::fileItemsChanged
, this, &DolphinMainWindow::fileItemsChanged
);
2667 connect(view
, &DolphinView::tabRequested
, this, &DolphinMainWindow::openNewTab
);
2668 connect(view
, &DolphinView::activeTabRequested
, this, &DolphinMainWindow::openNewTabAndActivate
);
2669 connect(view
, &DolphinView::windowRequested
, this, &DolphinMainWindow::openNewWindow
);
2670 connect(view
, &DolphinView::requestContextMenu
, this, &DolphinMainWindow::openContextMenu
);
2671 connect(view
, &DolphinView::directoryLoadingStarted
, this, &DolphinMainWindow::enableStopAction
);
2672 connect(view
, &DolphinView::directoryLoadingCompleted
, this, &DolphinMainWindow::disableStopAction
);
2673 connect(view
, &DolphinView::directoryLoadingCompleted
, this, &DolphinMainWindow::slotDirectoryLoadingCompleted
);
2674 connect(view
, &DolphinView::goBackRequested
, this, &DolphinMainWindow::goBack
);
2675 connect(view
, &DolphinView::goForwardRequested
, this, &DolphinMainWindow::goForward
);
2676 connect(view
, &DolphinView::urlActivated
, this, &DolphinMainWindow::handleUrl
);
2677 connect(view
, &DolphinView::goUpRequested
, this, &DolphinMainWindow::goUp
);
2678 connect(view
, &DolphinView::doubleClickViewBackground
, this, &DolphinMainWindow::slotDoubleClickViewBackground
);
2680 connect(container
->urlNavigatorInternalWithHistory(), &KUrlNavigator::urlChanged
, this, &DolphinMainWindow::changeUrl
);
2681 connect(container
->urlNavigatorInternalWithHistory(), &KUrlNavigator::historyChanged
, this, &DolphinMainWindow::updateHistory
);
2683 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>(actionCollection()->action(QStringLiteral("url_navigators")));
2684 const KUrlNavigator
*navigator
=
2685 m_tabWidget
->currentTabPage()->primaryViewActive() ? navigators
->primaryUrlNavigator() : navigators
->secondaryUrlNavigator();
2687 QAction
*editableLocactionAction
= actionCollection()->action(QStringLiteral("editable_location"));
2688 editableLocactionAction
->setChecked(navigator
->isUrlEditable());
2689 connect(navigator
, &KUrlNavigator::editableStateChanged
, this, &DolphinMainWindow::slotEditableStateChanged
);
2690 connect(navigator
, &KUrlNavigator::tabRequested
, this, &DolphinMainWindow::openNewTab
);
2691 connect(navigator
, &KUrlNavigator::activeTabRequested
, this, &DolphinMainWindow::openNewTabAndActivate
);
2692 connect(navigator
, &KUrlNavigator::newWindowRequested
, this, &DolphinMainWindow::openNewWindow
);
2695 void DolphinMainWindow::updateSplitActions()
2697 QAction
*popoutSplitAction
= actionCollection()->action(QStringLiteral("popout_split_view"));
2699 auto setActionPopupMode
= [this](KActionMenu
*action
, QToolButton::ToolButtonPopupMode popupMode
) {
2700 action
->setPopupMode(popupMode
);
2701 if (auto *buttonForAction
= qobject_cast
<QToolButton
*>(toolBar()->widgetForAction(action
))) {
2702 buttonForAction
->setPopupMode(popupMode
);
2706 const DolphinTabPage
*tabPage
= m_tabWidget
->currentTabPage();
2707 if (tabPage
->splitViewEnabled()) {
2708 if (GeneralSettings::closeActiveSplitView() ? tabPage
->primaryViewActive() : !tabPage
->primaryViewActive()) {
2709 m_splitViewAction
->setText(i18nc("@action:intoolbar Close left view", "Close"));
2710 m_splitViewAction
->setToolTip(i18nc("@info", "Close left view"));
2711 m_splitViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-left-close")));
2712 m_splitViewMenuAction
->setText(i18nc("@action:inmenu Close left view", "Close Left View"));
2714 popoutSplitAction
->setText(i18nc("@action:intoolbar Move left view to a new window", "Pop out Left View"));
2715 popoutSplitAction
->setToolTip(i18nc("@info", "Move left view to a new window"));
2717 m_splitViewAction
->setText(i18nc("@action:intoolbar Close right view", "Close"));
2718 m_splitViewAction
->setToolTip(i18nc("@info", "Close right view"));
2719 m_splitViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-right-close")));
2720 m_splitViewMenuAction
->setText(i18nc("@action:inmenu Close left view", "Close Right View"));
2722 popoutSplitAction
->setText(i18nc("@action:intoolbar Move right view to a new window", "Pop out Right View"));
2723 popoutSplitAction
->setToolTip(i18nc("@info", "Move right view to a new window"));
2725 popoutSplitAction
->setEnabled(true);
2726 if (!m_splitViewAction
->menu()) {
2727 setActionPopupMode(m_splitViewAction
, QToolButton::MenuButtonPopup
);
2728 m_splitViewAction
->setMenu(new QMenu
);
2729 m_splitViewAction
->addAction(popoutSplitAction
);
2732 m_splitViewAction
->setText(i18nc("@action:intoolbar Split view", "Split"));
2733 m_splitViewMenuAction
->setText(m_splitViewAction
->text());
2734 m_splitViewAction
->setToolTip(i18nc("@info", "Split view"));
2735 m_splitViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-split-left-right")));
2736 popoutSplitAction
->setText(i18nc("@action:intoolbar Move view in focus to a new window", "Pop out"));
2737 popoutSplitAction
->setEnabled(false);
2738 if (m_splitViewAction
->menu()) {
2739 m_splitViewAction
->removeAction(popoutSplitAction
);
2740 m_splitViewAction
->menu()->deleteLater();
2741 m_splitViewAction
->setMenu(nullptr);
2742 setActionPopupMode(m_splitViewAction
, QToolButton::DelayedPopup
);
2746 // Update state from toolbar action
2747 m_splitViewMenuAction
->setToolTip(m_splitViewAction
->toolTip());
2748 m_splitViewMenuAction
->setIcon(m_splitViewAction
->icon());
2751 void DolphinMainWindow::updateAllowedToolbarAreas()
2753 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>(actionCollection()->action(QStringLiteral("url_navigators")));
2754 if (toolBar()->actions().contains(navigators
)) {
2755 toolBar()->setAllowedAreas(Qt::TopToolBarArea
| Qt::BottomToolBarArea
);
2756 if (toolBarArea(toolBar()) == Qt::LeftToolBarArea
|| toolBarArea(toolBar()) == Qt::RightToolBarArea
) {
2757 addToolBar(Qt::TopToolBarArea
, toolBar());
2760 toolBar()->setAllowedAreas(Qt::AllToolBarAreas
);
2764 void DolphinMainWindow::updateNavigatorsBackground()
2766 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>(actionCollection()->action(QStringLiteral("url_navigators")));
2767 navigators
->setBackgroundEnabled(navigators
->isInToolbar());
2770 bool DolphinMainWindow::isKompareInstalled() const
2772 static bool initialized
= false;
2773 static bool installed
= false;
2775 // TODO: maybe replace this approach later by using a menu
2776 // plugin like kdiff3plugin.cpp
2777 installed
= !QStandardPaths::findExecutable(QStringLiteral("kompare")).isEmpty();
2783 void DolphinMainWindow::createPanelAction(const QIcon
&icon
, const QKeySequence
&shortcut
, QDockWidget
*dockWidget
, const QString
&actionName
)
2785 auto dockAction
= dockWidget
->toggleViewAction();
2786 dockAction
->setIcon(icon
);
2787 dockAction
->setEnabled(true);
2789 QAction
*panelAction
= actionCollection()->addAction(actionName
, dockAction
);
2790 actionCollection()->setDefaultShortcut(panelAction
, shortcut
);
2793 void DolphinMainWindow::setupWhatsThis()
2796 menuBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2797 "<emphasis>Menubar</emphasis>. It provides access to commands and "
2798 "configuration options. Left-click on any of the menus on this "
2799 "bar to see its contents.</para><para>The Menubar can be hidden "
2800 "by unchecking <interface>Settings|Show Menubar</interface>. Then "
2801 "most of its contents become available through a <interface>Menu"
2802 "</interface> button on the <emphasis>Toolbar</emphasis>.</para>"));
2803 toolBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2804 "<emphasis>Toolbar</emphasis>. It allows quick access to "
2805 "frequently used actions.</para><para>It is highly customizable. "
2806 "All items you see in the <interface>Menu</interface> or "
2807 "in the <interface>Menubar</interface> can be placed on the "
2808 "Toolbar. Just right-click on it and select <interface>Configure "
2809 "Toolbars…</interface> or find this action within the <interface>"
2811 "</para><para>The location of the bar and the style of its "
2812 "buttons can also be changed in the right-click menu. Right-click "
2813 "a button if you want to show or hide its text.</para>"));
2814 m_tabWidget
->setWhatsThis(xi18nc("@info:whatsthis main view",
2815 "<para>Here you can see the <emphasis>folders</emphasis> and "
2816 "<emphasis>files</emphasis> that are at the location described in "
2817 "the <interface>Location Bar</interface> above. This area is the "
2818 "central part of this application where you navigate to the files "
2819 "you want to use.</para><para>For an elaborate and general "
2820 "introduction to this application <link "
2821 "url='https://userbase.kde.org/Dolphin/File_Management#Introduction_to_Dolphin'>"
2822 "click here</link>. This will open an introductory article from "
2823 "the <emphasis>KDE UserBase Wiki</emphasis>.</para><para>For brief "
2824 "explanations of all the features of this <emphasis>view</emphasis> "
2825 "<link url='help:/dolphin/dolphin-view.html'>click here</link> "
2826 "instead. This will open a page from the <emphasis>Handbook"
2827 "</emphasis> that covers the basics.</para>"));
2830 actionCollection()->action(KStandardAction::name(KStandardAction::KeyBindings
))
2831 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window "
2832 "that lists the <emphasis>keyboard shortcuts</emphasis>.<nl/>"
2833 "There you can set up key combinations to trigger an action when "
2834 "they are pressed simultaneously. All commands in this application can "
2835 "be triggered this way.</para>"));
2836 actionCollection()->action(KStandardAction::name(KStandardAction::ConfigureToolbars
))
2837 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window in which "
2838 "you can change which buttons appear on the <emphasis>Toolbar</emphasis>.</para>"
2839 "<para>All items you see in the <interface>Menu</interface> can also be placed on the Toolbar.</para>"));
2840 actionCollection()->action(KStandardAction::name(KStandardAction::Preferences
))
2841 ->setWhatsThis(xi18nc("@info:whatsthis","This opens a window where you can "
2842 "change a multitude of settings for this application. For an explanation "
2843 "of the various settings go to the chapter <emphasis>Configuring Dolphin"
2844 "</emphasis> in <interface>Help|Dolphin Handbook</interface>."));
2848 auto setStandardActionWhatsThis
= [this](KStandardAction::StandardAction actionId
,
2849 const QString
&whatsThis
) {
2850 // Check for the existence of an action since it can be restricted through the Kiosk system
2851 if (auto *action
= actionCollection()->action(KStandardAction::name(actionId
))) {
2852 action
->setWhatsThis(whatsThis
);
2856 // i18n: If the external link isn't available in your language it might make
2857 // sense to state the external link's language in brackets to not
2858 // frustrate the user. If there are multiple languages that the user might
2859 // know with a reasonable chance you might want to have 2 external links.
2860 // The same might be true for any external link you translate.
2861 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>"));
2862 // (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 )
2864 setStandardActionWhatsThis(KStandardAction::WhatsThis
,
2865 xi18nc("@info:whatsthis whatsthis button",
2866 "<para>This is the button that invokes the help feature you are "
2867 "using right now! Click it, then click any component of this "
2868 "application to ask \"What's this?\" about it. The mouse cursor "
2869 "will change appearance if no help is available for a spot.</para>"
2870 "<para>There are two other ways to get help: "
2871 "The <link url='help:/dolphin/index.html'>Dolphin Handbook</link> and "
2872 "the <link url='https://userbase.kde.org/Dolphin/File_Management'>KDE "
2873 "UserBase Wiki</link>.</para><para>The \"What's this?\" help is "
2874 "missing in most other windows so don't get too used to this.</para>"));
2876 setStandardActionWhatsThis(KStandardAction::ReportBug
,
2877 xi18nc("@info:whatsthis","<para>This opens a "
2878 "window that will guide you through reporting errors or flaws "
2879 "in this application or in other KDE software.</para>"
2880 "<para>High-quality bug reports are much appreciated. To learn "
2881 "how to make your bug report as effective as possible "
2882 "<link url='https://community.kde.org/Get_Involved/Bug_Reporting'>"
2883 "click here</link>.</para>"));
2885 setStandardActionWhatsThis(KStandardAction::Donate
,
2886 xi18nc("@info:whatsthis", "<para>This opens a "
2887 "<emphasis>web page</emphasis> where you can donate to "
2888 "support the continued work on this application and many "
2889 "other projects by the <emphasis>KDE</emphasis> community.</para>"
2890 "<para>Donating is the easiest and fastest way to efficiently "
2891 "support KDE and its projects. KDE projects are available for "
2892 "free therefore your donation is needed to cover things that "
2893 "require money like servers, contributor meetings, etc.</para>"
2894 "<para><emphasis>KDE e.V.</emphasis> is the non-profit "
2895 "organization behind the KDE community.</para>"));
2897 setStandardActionWhatsThis(KStandardAction::SwitchApplicationLanguage
,
2898 xi18nc("@info:whatsthis",
2899 "With this you can change the language this application uses."
2900 "<nl/>You can even set secondary languages which will be used "
2901 "if texts are not available in your preferred language."));
2903 setStandardActionWhatsThis(KStandardAction::AboutApp
,
2904 xi18nc("@info:whatsthis","This opens a "
2905 "window that informs you about the version, license, "
2906 "used libraries and maintainers of this application."));
2908 setStandardActionWhatsThis(KStandardAction::AboutKDE
,
2909 xi18nc("@info:whatsthis","This opens a "
2910 "window with information about <emphasis>KDE</emphasis>. "
2911 "The KDE community are the people behind this free software."
2912 "<nl/>If you like using this application but don't know "
2913 "about KDE or want to see a cute dragon have a look!"));
2917 bool DolphinMainWindow::addHamburgerMenuToToolbar()
2919 QDomDocument domDocument
= KXMLGUIClient::domDocument();
2920 if (domDocument
.isNull()) {
2923 QDomNode toolbar
= domDocument
.elementsByTagName(QStringLiteral("ToolBar")).at(0);
2924 if (toolbar
.isNull()) {
2928 QDomElement hamburgerMenuElement
= domDocument
.createElement(QStringLiteral("Action"));
2929 hamburgerMenuElement
.setAttribute(QStringLiteral("name"), QStringLiteral("hamburger_menu"));
2930 toolbar
.appendChild(hamburgerMenuElement
);
2932 KXMLGUIFactory::saveConfigFile(domDocument
, xmlFile());
2936 // Make sure to also remove the <KXMLGUIFactory> and <QDomDocument> include
2937 // whenever this method is removed (maybe in the year ~2026).
2940 // Set a sane initial window size
2941 QSize
DolphinMainWindow::sizeHint() const
2943 return KXmlGuiWindow::sizeHint().expandedTo(QSize(760, 550));
2946 void DolphinMainWindow::saveNewToolbarConfig()
2948 KXmlGuiWindow::saveNewToolbarConfig(); // Applies the new config. This has to be called first
2949 // because the rest of this method decides things
2950 // based on the new config.
2951 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>(actionCollection()->action(QStringLiteral("url_navigators")));
2952 if (!toolBar()->actions().contains(navigators
)) {
2953 m_tabWidget
->currentTabPage()->insertNavigatorsWidget(navigators
);
2955 updateAllowedToolbarAreas();
2956 updateNavigatorsBackground();
2957 (static_cast<KHamburgerMenu
*>(actionCollection()->action(KStandardAction::name(KStandardAction::HamburgerMenu
))))->hideActionsOf(toolBar());
2960 void DolphinMainWindow::toggleTerminalPanelFocus()
2962 if (!m_terminalPanel
->isVisible()) {
2963 actionCollection()->action(QStringLiteral("show_terminal_panel"))->trigger(); // Also moves focus to the panel.
2964 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
2968 if (m_terminalPanel
->terminalHasFocus()) {
2969 m_activeViewContainer
->view()->setFocus(Qt::FocusReason::ShortcutFocusReason
);
2970 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
2974 m_terminalPanel
->setFocus(Qt::FocusReason::ShortcutFocusReason
);
2975 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
2978 void DolphinMainWindow::togglePlacesPanelFocus()
2980 if (!m_placesPanel
->isVisible()) {
2981 actionCollection()->action(QStringLiteral("show_places_panel"))->trigger(); // Also moves focus to the panel.
2982 actionCollection()->action(QStringLiteral("focus_places_panel"))->setText(i18nc("@action:inmenu View", "Defocus Terminal Panel"));
2986 if (m_placesPanel
->hasFocus()) {
2987 m_activeViewContainer
->view()->setFocus(Qt::FocusReason::ShortcutFocusReason
);
2988 actionCollection()->action(QStringLiteral("focus_places_panel"))->setText(i18nc("@action:inmenu View", "Focus Places Panel"));
2992 m_placesPanel
->setFocus(Qt::FocusReason::ShortcutFocusReason
);
2993 actionCollection()->action(QStringLiteral("focus_places_panel"))->setText(i18nc("@action:inmenu View", "Defocus Places Panel"));
2996 DolphinMainWindow::UndoUiInterface::UndoUiInterface()
2997 : KIO::FileUndoManager::UiInterface()
3001 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
3005 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
*job
)
3007 DolphinMainWindow
*mainWin
= qobject_cast
<DolphinMainWindow
*>(parentWidget());
3009 DolphinViewContainer
*container
= mainWin
->activeViewContainer();
3010 container
->showMessage(job
->errorString(), KMessageWidget::Error
);
3012 KIO::FileUndoManager::UiInterface::jobError(job
);
3016 bool DolphinMainWindow::isUrlOpen(const QString
&url
)
3018 return m_tabWidget
->isUrlOpen(QUrl::fromUserInput(url
));
3021 bool DolphinMainWindow::isItemVisibleInAnyView(const QString
&urlOfItem
)
3023 return m_tabWidget
->isItemVisibleInAnyView(QUrl::fromUserInput(urlOfItem
));
3026 void DolphinMainWindow::slotDoubleClickViewBackground(Qt::MouseButton button
)
3028 if (button
!= Qt::MouseButton::LeftButton
) {
3029 // only handle left mouse button for now
3033 GeneralSettings
*settings
= GeneralSettings::self();
3034 QString clickAction
= settings
->doubleClickViewAction();
3036 DolphinView
*view
= activeViewContainer()->view();
3037 if (view
== nullptr || clickAction
== "none") {
3041 if (clickAction
== customCommand
) {
3042 // run custom command set by the user
3043 QString path
= view
->url().toLocalFile();
3044 QString clickCustomAction
= settings
->doubleClickViewCustomAction();
3045 clickCustomAction
.replace("{path}", path
.prepend('"').append('"'));
3047 m_job
= new KIO::CommandLauncherJob(clickCustomAction
);
3048 m_job
->setUiDelegate(new KDialogJobUiDelegate(KJobUiDelegate::AutoHandlingEnabled
, this));
3052 // get the action set by the user and trigger it
3053 const KActionCollection
*actions
= actionCollection();
3054 QAction
*action
= actions
->action(clickAction
);
3055 if (action
== nullptr) {
3056 qCWarning(DolphinDebug
) << QStringLiteral("Double-click view: action `%1` was not found").arg(clickAction
);
3063 #include "moc_dolphinmainwindow.cpp"