2 * SPDX-FileCopyrightText: 2006 Peter Penz <peter.penz19@gmail.com>
3 * SPDX-FileCopyrightText: 2006 Stefan Monov <logixoul@gmail.com>
4 * SPDX-FileCopyrightText: 2006 Cvetoslav Ludmiloff <ludmiloff@gmail.com>
6 * SPDX-License-Identifier: GPL-2.0-or-later
9 #include "dolphinmainwindow.h"
11 #include "dolphin_generalsettings.h"
12 #include "dolphinbookmarkhandler.h"
13 #include "dolphincontextmenu.h"
14 #include "dolphindockwidget.h"
15 #include "dolphinmainwindowadaptor.h"
16 #include "dolphinnavigatorswidgetaction.h"
17 #include "dolphinnewfilemenu.h"
18 #include "dolphinplacesmodelsingleton.h"
19 #include "dolphinrecenttabsmenu.h"
20 #include "dolphintabpage.h"
21 #include "dolphinurlnavigatorscontroller.h"
22 #include "dolphinviewcontainer.h"
24 #include "middleclickactioneventfilter.h"
25 #include "panels/folders/folderspanel.h"
26 #include "panels/places/placespanel.h"
27 #include "panels/terminal/terminalpanel.h"
28 #include "selectionmode/actiontexthelper.h"
29 #include "settings/dolphinsettingsdialog.h"
30 #include "statusbar/dolphinstatusbar.h"
31 #include "views/dolphinnewfilemenuobserver.h"
32 #include "views/dolphinremoteencoding.h"
33 #include "views/dolphinviewactionhandler.h"
34 #include "views/draganddrophelper.h"
35 #include "views/viewproperties.h"
37 #include <KActionCollection>
38 #include <KActionMenu>
39 #include <KAuthorized>
42 #include <KDualAction>
43 #include <KFileItemListProperties>
44 #include <KIO/CommandLauncherJob>
45 #include <KIO/JobUiDelegateFactory>
46 #include <KIO/OpenFileManagerWindowJob>
47 #include <KIO/OpenUrlJob>
48 #include <KJobWidgets>
49 #include <KLocalizedString>
50 #include <KMessageBox>
51 #include <KProtocolInfo>
52 #include <KProtocolManager>
54 #include <KShortcutsDialog>
55 #include <KStandardAction>
57 #include <KTerminalLauncherJob>
58 #include <KToggleAction>
60 #include <KToolBarPopupAction>
61 #include <KUrlComboBox>
62 #include <KUrlNavigator>
63 #include <KWindowSystem>
64 #include <KXMLGUIFactory>
66 #include <kwidgetsaddons_version.h>
68 #include <QApplication>
70 #include <QCloseEvent>
71 #include <QDesktopServices>
73 #include <QDomDocument>
77 #include <QPushButton>
79 #include <QStandardPaths>
81 #include <QToolButton>
82 #include <QtConcurrentRun>
87 #include <KStartupInfo>
92 // Used for GeneralSettings::version() to determine whether
93 // an updated version of Dolphin is running, so as to migrate
94 // removed/renamed ...etc config entries; increment it in such
96 const int CurrentDolphinVersion
= 202;
97 // The maximum number of entries in the back/forward popup menu
98 const int MaxNumberOfNavigationentries
= 12;
99 // The maximum number of "Activate Tab" shortcuts
100 const int MaxActivateTabShortcuts
= 9;
103 DolphinMainWindow::DolphinMainWindow()
104 : KXmlGuiWindow(nullptr)
105 , m_newFileMenu(nullptr)
106 , m_tabWidget(nullptr)
107 , m_activeViewContainer(nullptr)
108 , m_actionHandler(nullptr)
109 , m_remoteEncoding(nullptr)
111 , m_bookmarkHandler(nullptr)
112 , m_lastHandleUrlOpenJob(nullptr)
113 , m_terminalPanel(nullptr)
114 , m_placesPanel(nullptr)
115 , m_tearDownFromPlacesRequested(false)
116 , m_backAction(nullptr)
117 , m_forwardAction(nullptr)
118 , m_sessionSaveTimer(nullptr)
119 , m_sessionSaveWatcher(nullptr)
120 , m_sessionSaveScheduled(false)
122 Q_INIT_RESOURCE(dolphin
);
124 new MainWindowAdaptor(this);
127 setWindowFlags(Qt::WindowContextHelpButtonHint
);
129 setComponentName(QStringLiteral("dolphin"), QGuiApplication::applicationDisplayName());
130 setObjectName(QStringLiteral("Dolphin#"));
132 setStateConfigGroup("State");
134 connect(&DolphinNewFileMenuObserver::instance(), &DolphinNewFileMenuObserver::errorMessage
, this, &DolphinMainWindow::showErrorMessage
);
136 KIO::FileUndoManager
*undoManager
= KIO::FileUndoManager::self();
137 undoManager
->setUiInterface(new UndoUiInterface());
139 connect(undoManager
, &KIO::FileUndoManager::undoAvailable
, this, &DolphinMainWindow::slotUndoAvailable
);
140 connect(undoManager
, &KIO::FileUndoManager::undoTextChanged
, this, &DolphinMainWindow::slotUndoTextChanged
);
141 connect(undoManager
, &KIO::FileUndoManager::jobRecordingStarted
, this, &DolphinMainWindow::clearStatusBar
);
142 connect(undoManager
, &KIO::FileUndoManager::jobRecordingFinished
, this, &DolphinMainWindow::showCommand
);
144 const bool firstRun
= (GeneralSettings::version() < 200);
146 GeneralSettings::setViewPropsTimestamp(QDateTime::currentDateTime());
149 setAcceptDrops(true);
151 auto *navigatorsWidgetAction
= new DolphinNavigatorsWidgetAction(this);
152 actionCollection()->addAction(QStringLiteral("url_navigators"), navigatorsWidgetAction
);
153 m_tabWidget
= new DolphinTabWidget(navigatorsWidgetAction
, this);
154 m_tabWidget
->setObjectName("tabWidget");
155 connect(m_tabWidget
, &DolphinTabWidget::activeViewChanged
, this, &DolphinMainWindow::activeViewChanged
);
156 connect(m_tabWidget
, &DolphinTabWidget::tabCountChanged
, this, &DolphinMainWindow::tabCountChanged
);
157 connect(m_tabWidget
, &DolphinTabWidget::currentUrlChanged
, this, &DolphinMainWindow::updateWindowTitle
);
158 setCentralWidget(m_tabWidget
);
160 m_actionTextHelper
= new SelectionMode::ActionTextHelper(this);
163 m_actionHandler
= new DolphinViewActionHandler(actionCollection(), m_actionTextHelper
, this);
164 connect(m_actionHandler
, &DolphinViewActionHandler::actionBeingHandled
, this, &DolphinMainWindow::clearStatusBar
);
165 connect(m_actionHandler
, &DolphinViewActionHandler::createDirectoryTriggered
, this, &DolphinMainWindow::createDirectory
);
166 connect(m_actionHandler
, &DolphinViewActionHandler::selectionModeChangeTriggered
, this, &DolphinMainWindow::slotSetSelectionMode
);
168 Q_CHECK_PTR(actionCollection()->action(QStringLiteral("create_dir")));
169 m_newFileMenu
->setNewFolderShortcutAction(actionCollection()->action(QStringLiteral("create_dir")));
171 m_remoteEncoding
= new DolphinRemoteEncoding(this, m_actionHandler
);
172 connect(this, &DolphinMainWindow::urlChanged
, m_remoteEncoding
, &DolphinRemoteEncoding::slotAboutToOpenUrl
);
176 setupGUI(Save
| Create
| ToolBar
);
177 stateChanged(QStringLiteral("new_file"));
179 QClipboard
*clipboard
= QApplication::clipboard();
180 connect(clipboard
, &QClipboard::dataChanged
, this, &DolphinMainWindow::updatePasteAction
);
182 QAction
*toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
183 toggleFilterBarAction
->setChecked(GeneralSettings::filterBar());
186 menuBar()->setVisible(false);
189 const bool showMenu
= !menuBar()->isHidden();
190 QAction
*showMenuBarAction
= actionCollection()->action(KStandardAction::name(KStandardAction::ShowMenubar
));
191 showMenuBarAction
->setChecked(showMenu
); // workaround for bug #171080
193 auto hamburgerMenu
= static_cast<KHamburgerMenu
*>(actionCollection()->action(KStandardAction::name(KStandardAction::HamburgerMenu
)));
194 hamburgerMenu
->setMenuBar(menuBar());
195 hamburgerMenu
->setShowMenuBarAction(showMenuBarAction
);
196 connect(hamburgerMenu
, &KHamburgerMenu::aboutToShowMenu
, this, &DolphinMainWindow::updateHamburgerMenu
);
197 hamburgerMenu
->hideActionsOf(toolBar());
198 if (GeneralSettings::version() < 201 && !toolBar()->actions().contains(hamburgerMenu
)) {
199 addHamburgerMenuToToolbar();
202 updateAllowedToolbarAreas();
204 // enable middle-click on back/forward/up to open in a new tab
205 auto *middleClickEventFilter
= new MiddleClickActionEventFilter(this);
206 connect(middleClickEventFilter
, &MiddleClickActionEventFilter::actionMiddleClicked
, this, &DolphinMainWindow::slotToolBarActionMiddleClicked
);
207 toolBar()->installEventFilter(middleClickEventFilter
);
211 connect(KSycoca::self(), &KSycoca::databaseChanged
, this, &DolphinMainWindow::updateOpenPreferredSearchToolAction
);
213 QTimer::singleShot(0, this, &DolphinMainWindow::updateOpenPreferredSearchToolAction
);
215 m_fileItemActions
.setParentWidget(this);
216 connect(&m_fileItemActions
, &KFileItemActions::error
, this, [this](const QString
&errorMessage
) {
217 showErrorMessage(errorMessage
);
220 connect(GeneralSettings::self(), &GeneralSettings::splitViewChanged
, this, &DolphinMainWindow::slotSplitViewChanged
);
223 DolphinMainWindow::~DolphinMainWindow()
225 // This fixes a crash on Wayland when closing the mainwindow while another dialog is open.
226 disconnect(QGuiApplication::clipboard(), &QClipboard::dataChanged
, this, &DolphinMainWindow::updatePasteAction
);
229 QVector
<DolphinViewContainer
*> DolphinMainWindow::viewContainers() const
231 QVector
<DolphinViewContainer
*> viewContainers
;
233 for (int i
= 0; i
< m_tabWidget
->count(); ++i
) {
234 DolphinTabPage
*tabPage
= m_tabWidget
->tabPageAt(i
);
236 viewContainers
<< tabPage
->primaryViewContainer();
237 if (tabPage
->splitViewEnabled()) {
238 viewContainers
<< tabPage
->secondaryViewContainer();
241 return viewContainers
;
244 void DolphinMainWindow::openDirectories(const QList
<QUrl
> &dirs
, bool splitView
)
246 m_tabWidget
->openDirectories(dirs
, splitView
);
249 void DolphinMainWindow::openDirectories(const QStringList
&dirs
, bool splitView
)
251 openDirectories(QUrl::fromStringList(dirs
), splitView
);
254 void DolphinMainWindow::openFiles(const QList
<QUrl
> &files
, bool splitView
)
256 m_tabWidget
->openFiles(files
, splitView
);
259 bool DolphinMainWindow::isFoldersPanelEnabled() const
261 return actionCollection()->action(QStringLiteral("show_folders_panel"))->isChecked();
264 bool DolphinMainWindow::isInformationPanelEnabled() const
267 return actionCollection()->action(QStringLiteral("show_information_panel"))->isChecked();
273 bool DolphinMainWindow::isSplitViewEnabledInCurrentTab() const
275 return m_tabWidget
->currentTabPage()->splitViewEnabled();
278 void DolphinMainWindow::openFiles(const QStringList
&files
, bool splitView
)
280 openFiles(QUrl::fromStringList(files
), splitView
);
283 void DolphinMainWindow::activateWindow(const QString
&activationToken
)
285 window()->setAttribute(Qt::WA_NativeWindow
, true);
287 if (KWindowSystem::isPlatformWayland()) {
288 KWindowSystem::setCurrentXdgActivationToken(activationToken
);
289 } else if (KWindowSystem::isPlatformX11()) {
291 KStartupInfo::setNewStartupId(window()->windowHandle(), activationToken
.toUtf8());
295 KWindowSystem::activateWindow(window()->windowHandle());
298 bool DolphinMainWindow::isActiveWindow()
300 return window()->isActiveWindow();
303 void DolphinMainWindow::showCommand(CommandType command
)
305 DolphinStatusBar
*statusBar
= m_activeViewContainer
->statusBar();
307 case KIO::FileUndoManager::Copy
:
308 statusBar
->setText(i18nc("@info:status", "Successfully copied."));
310 case KIO::FileUndoManager::Move
:
311 statusBar
->setText(i18nc("@info:status", "Successfully moved."));
313 case KIO::FileUndoManager::Link
:
314 statusBar
->setText(i18nc("@info:status", "Successfully linked."));
316 case KIO::FileUndoManager::Trash
:
317 statusBar
->setText(i18nc("@info:status", "Successfully moved to trash."));
319 case KIO::FileUndoManager::Rename
:
320 statusBar
->setText(i18nc("@info:status", "Successfully renamed."));
323 case KIO::FileUndoManager::Mkdir
:
324 statusBar
->setText(i18nc("@info:status", "Created folder."));
332 void DolphinMainWindow::pasteIntoFolder()
334 m_activeViewContainer
->view()->pasteIntoFolder();
337 void DolphinMainWindow::changeUrl(const QUrl
&url
)
339 if (!KProtocolManager::supportsListing(url
)) {
340 // The URL navigator only checks for validity, not
341 // if the URL can be listed. An error message is
342 // shown due to DolphinViewContainer::restoreView().
346 m_activeViewContainer
->setUrl(url
);
347 updateFileAndEditActions();
352 Q_EMIT
urlChanged(url
);
355 void DolphinMainWindow::slotTerminalDirectoryChanged(const QUrl
&url
)
357 if (m_tearDownFromPlacesRequested
&& url
== QUrl::fromLocalFile(QDir::homePath())) {
358 m_placesPanel
->proceedWithTearDown();
359 m_tearDownFromPlacesRequested
= false;
362 m_activeViewContainer
->setAutoGrabFocus(false);
364 m_activeViewContainer
->setAutoGrabFocus(true);
367 void DolphinMainWindow::slotEditableStateChanged(bool editable
)
369 KToggleAction
*editableLocationAction
= static_cast<KToggleAction
*>(actionCollection()->action(QStringLiteral("editable_location")));
370 editableLocationAction
->setChecked(editable
);
373 void DolphinMainWindow::slotSelectionChanged(const KFileItemList
&selection
)
375 updateFileAndEditActions();
377 const int selectedUrlsCount
= m_tabWidget
->currentTabPage()->selectedItemsCount();
379 QAction
*compareFilesAction
= actionCollection()->action(QStringLiteral("compare_files"));
380 if (selectedUrlsCount
== 2) {
381 compareFilesAction
->setEnabled(isKompareInstalled());
383 compareFilesAction
->setEnabled(false);
386 Q_EMIT
selectionChanged(selection
);
389 void DolphinMainWindow::updateHistory()
391 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
392 const int index
= urlNavigator
->historyIndex();
394 QAction
*backAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Back
));
396 backAction
->setToolTip(i18nc("@info", "Go back"));
397 backAction
->setWhatsThis(i18nc("@info:whatsthis go back", "Return to the previously viewed folder."));
398 backAction
->setEnabled(index
< urlNavigator
->historySize() - 1);
401 QAction
*forwardAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Forward
));
403 forwardAction
->setToolTip(i18nc("@info", "Go forward"));
404 forwardAction
->setWhatsThis(xi18nc("@info:whatsthis go forward", "This undoes a <interface>Go|Back</interface> action."));
405 forwardAction
->setEnabled(index
> 0);
409 void DolphinMainWindow::updateFilterBarAction(bool show
)
411 QAction
*toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
412 toggleFilterBarAction
->setChecked(show
);
415 void DolphinMainWindow::openNewMainWindow()
417 Dolphin::openNewWindow({m_activeViewContainer
->url()}, this);
420 void DolphinMainWindow::openNewActivatedTab()
422 // keep browsers compatibility, new tab is always after last one
423 auto openNewTabAfterLastTabConfigured
= GeneralSettings::openNewTabAfterLastTab();
424 GeneralSettings::setOpenNewTabAfterLastTab(true);
425 m_tabWidget
->openNewActivatedTab();
426 GeneralSettings::setOpenNewTabAfterLastTab(openNewTabAfterLastTabConfigured
);
429 void DolphinMainWindow::addToPlaces()
434 // If nothing is selected, act on the current dir
435 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
436 url
= m_activeViewContainer
->url();
437 name
= m_activeViewContainer
->placesText();
439 const auto dirToAdd
= m_activeViewContainer
->view()->selectedItems().first();
440 url
= dirToAdd
.url();
441 name
= dirToAdd
.name();
445 if (m_activeViewContainer
->isSearchModeEnabled()) {
446 icon
= QStringLiteral("folder-saved-search-symbolic");
448 icon
= KIO::iconNameForUrl(url
);
450 DolphinPlacesModelSingleton::instance().placesModel()->addPlace(name
, url
, icon
);
454 void DolphinMainWindow::openNewTab(const QUrl
&url
)
456 m_tabWidget
->openNewTab(url
, QUrl());
459 void DolphinMainWindow::openNewTabAndActivate(const QUrl
&url
)
461 m_tabWidget
->openNewActivatedTab(url
, QUrl());
464 void DolphinMainWindow::openNewWindow(const QUrl
&url
)
466 Dolphin::openNewWindow({url
}, this);
469 void DolphinMainWindow::slotSplitViewChanged()
471 m_tabWidget
->currentTabPage()->setSplitViewEnabled(GeneralSettings::splitView(), WithAnimation
);
472 updateSplitActions();
475 void DolphinMainWindow::openInNewTab()
477 const KFileItemList
&list
= m_activeViewContainer
->view()->selectedItems();
478 bool tabCreated
= false;
480 for (const KFileItem
&item
: list
) {
481 const QUrl
&url
= DolphinView::openItemAsFolderUrl(item
);
482 if (!url
.isEmpty()) {
488 // if no new tab has been created from the selection
489 // open the current directory in a new tab
491 openNewTab(m_activeViewContainer
->url());
495 void DolphinMainWindow::openInNewWindow()
499 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
500 if (list
.isEmpty()) {
501 newWindowUrl
= m_activeViewContainer
->url();
502 } else if (list
.count() == 1) {
503 const KFileItem
&item
= list
.first();
504 newWindowUrl
= DolphinView::openItemAsFolderUrl(item
);
507 if (!newWindowUrl
.isEmpty()) {
508 Dolphin::openNewWindow({newWindowUrl
}, this);
512 void DolphinMainWindow::openInSplitView(const QUrl
&url
)
514 QUrl newSplitViewUrl
= url
;
516 if (newSplitViewUrl
.isEmpty()) {
517 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
518 if (list
.count() == 1) {
519 const KFileItem
&item
= list
.first();
520 newSplitViewUrl
= DolphinView::openItemAsFolderUrl(item
);
524 if (newSplitViewUrl
.isEmpty()) {
528 DolphinTabPage
*tabPage
= m_tabWidget
->currentTabPage();
529 if (tabPage
->splitViewEnabled()) {
530 tabPage
->switchActiveView();
531 tabPage
->activeViewContainer()->setUrl(newSplitViewUrl
);
533 tabPage
->setSplitViewEnabled(true, WithAnimation
, newSplitViewUrl
);
538 void DolphinMainWindow::showTarget()
540 const KFileItem link
= m_activeViewContainer
->view()->selectedItems().at(0);
541 const QUrl destinationUrl
= link
.url().resolved(QUrl(link
.linkDest()));
543 auto job
= KIO::stat(destinationUrl
, KIO::StatJob::SourceSide
, KIO::StatNoDetails
);
545 connect(job
, &KJob::finished
, this, [this, destinationUrl
](KJob
*job
) {
546 KIO::StatJob
*statJob
= static_cast<KIO::StatJob
*>(job
);
548 if (statJob
->error()) {
549 m_activeViewContainer
->showMessage(job
->errorString(), DolphinViewContainer::Error
);
551 KIO::highlightInFileManager({destinationUrl
});
556 bool DolphinMainWindow::event(QEvent
*event
)
558 if (event
->type() == QEvent::ShortcutOverride
) {
559 const QKeyEvent
*keyEvent
= static_cast<QKeyEvent
*>(event
);
560 if (keyEvent
->key() == Qt::Key_Space
&& m_activeViewContainer
->view()->handleSpaceAsNormalKey()) {
566 return KXmlGuiWindow::event(event
);
569 void DolphinMainWindow::showEvent(QShowEvent
*event
)
571 KXmlGuiWindow::showEvent(event
);
573 if (!event
->spontaneous()) {
574 m_activeViewContainer
->view()->setFocus();
578 void DolphinMainWindow::closeEvent(QCloseEvent
*event
)
580 // Find out if Dolphin is closed directly by the user or
581 // by the session manager because the session is closed
582 bool closedByUser
= true;
583 if (qApp
->isSavingSession()) {
584 closedByUser
= false;
587 if (m_tabWidget
->count() > 1 && GeneralSettings::confirmClosingMultipleTabs() && !GeneralSettings::rememberOpenedTabs() && closedByUser
) {
588 // Ask the user if he really wants to quit and close all tabs.
589 // Open a confirmation dialog with 3 buttons:
590 // QDialogButtonBox::Yes -> Quit
591 // QDialogButtonBox::No -> Close only the current tab
592 // QDialogButtonBox::Cancel -> do nothing
593 QDialog
*dialog
= new QDialog(this, Qt::Dialog
);
594 dialog
->setWindowTitle(i18nc("@title:window", "Confirmation"));
595 dialog
->setModal(true);
596 QDialogButtonBox
*buttons
= new QDialogButtonBox(QDialogButtonBox::Yes
| QDialogButtonBox::No
| QDialogButtonBox::Cancel
);
597 KGuiItem::assign(buttons
->button(QDialogButtonBox::Yes
),
598 KGuiItem(i18nc("@action:button 'Quit Dolphin' button", "&Quit %1", QGuiApplication::applicationDisplayName()),
599 QIcon::fromTheme(QStringLiteral("application-exit"))));
600 KGuiItem::assign(buttons
->button(QDialogButtonBox::No
), KGuiItem(i18n("C&lose Current Tab"), QIcon::fromTheme(QStringLiteral("tab-close"))));
601 KGuiItem::assign(buttons
->button(QDialogButtonBox::Cancel
), KStandardGuiItem::cancel());
602 buttons
->button(QDialogButtonBox::Yes
)->setDefault(true);
604 bool doNotAskAgainCheckboxResult
= false;
606 const auto result
= KMessageBox::createKMessageBox(dialog
,
608 QMessageBox::Warning
,
609 i18n("You have multiple tabs open in this window, are you sure you want to quit?"),
611 i18n("Do not ask again"),
612 &doNotAskAgainCheckboxResult
,
613 KMessageBox::Notify
);
615 if (doNotAskAgainCheckboxResult
) {
616 GeneralSettings::setConfirmClosingMultipleTabs(false);
620 case QDialogButtonBox::Yes
:
623 case QDialogButtonBox::No
:
624 // Close only the current tab
625 m_tabWidget
->closeTab();
633 if (m_terminalPanel
&& m_terminalPanel
->hasProgramRunning() && GeneralSettings::confirmClosingTerminalRunningProgram() && closedByUser
) {
634 // Ask if the user really wants to quit Dolphin with a program that is still running in the Terminal panel
635 // Open a confirmation dialog with 3 buttons:
636 // QDialogButtonBox::Yes -> Quit
637 // QDialogButtonBox::No -> Show Terminal Panel
638 // QDialogButtonBox::Cancel -> do nothing
639 QDialog
*dialog
= new QDialog(this, Qt::Dialog
);
640 dialog
->setWindowTitle(i18nc("@title:window", "Confirmation"));
641 dialog
->setModal(true);
642 auto standardButtons
= QDialogButtonBox::Yes
| QDialogButtonBox::Cancel
;
643 if (!m_terminalPanel
->isVisible()) {
644 standardButtons
|= QDialogButtonBox::No
;
646 QDialogButtonBox
*buttons
= new QDialogButtonBox(standardButtons
);
647 KGuiItem::assign(buttons
->button(QDialogButtonBox::Yes
), KStandardGuiItem::quit());
648 if (!m_terminalPanel
->isVisible()) {
649 KGuiItem::assign(buttons
->button(QDialogButtonBox::No
), KGuiItem(i18n("Show &Terminal Panel"), QIcon::fromTheme(QStringLiteral("dialog-scripts"))));
651 KGuiItem::assign(buttons
->button(QDialogButtonBox::Cancel
), KStandardGuiItem::cancel());
653 bool doNotAskAgainCheckboxResult
= false;
655 const auto result
= KMessageBox::createKMessageBox(
658 QMessageBox::Warning
,
659 i18n("The program '%1' is still running in the Terminal panel. Are you sure you want to quit?", m_terminalPanel
->runningProgramName()),
661 i18n("Do not ask again"),
662 &doNotAskAgainCheckboxResult
,
663 KMessageBox::Notify
| KMessageBox::Dangerous
);
665 if (doNotAskAgainCheckboxResult
) {
666 GeneralSettings::setConfirmClosingTerminalRunningProgram(false);
670 case QDialogButtonBox::Yes
:
673 case QDialogButtonBox::No
:
674 actionCollection()->action("show_terminal_panel")->trigger();
675 // Do not quit, ignore quit event
683 if (m_sessionSaveTimer
&& (m_sessionSaveTimer
->isActive() || m_sessionSaveWatcher
->isRunning())) {
684 const bool sessionSaveTimerActive
= m_sessionSaveTimer
->isActive();
686 m_sessionSaveTimer
->stop();
687 m_sessionSaveWatcher
->disconnect();
688 m_sessionSaveWatcher
->waitForFinished();
690 if (sessionSaveTimerActive
|| m_sessionSaveScheduled
) {
695 GeneralSettings::setVersion(CurrentDolphinVersion
);
696 GeneralSettings::self()->save();
698 KXmlGuiWindow::closeEvent(event
);
701 void DolphinMainWindow::slotSaveSession()
703 m_sessionSaveScheduled
= false;
705 if (m_sessionSaveWatcher
->isRunning()) {
706 // The previous session is still being saved - schedule another save.
707 m_sessionSaveWatcher
->disconnect();
708 connect(m_sessionSaveWatcher
, &QFutureWatcher
<void>::finished
, this, &DolphinMainWindow::slotSaveSession
, Qt::SingleShotConnection
);
709 m_sessionSaveScheduled
= true;
710 } else if (!m_sessionSaveTimer
->isActive()) {
711 // No point in saving the session if the timer is running (since it will save the session again when it times out).
712 KConfigGui::setSessionConfig(QStringLiteral("dolphin"), QStringLiteral("dolphin"));
713 KConfig
*config
= KConfigGui::sessionConfig();
714 saveGlobalProperties(config
);
715 savePropertiesInternal(config
, 1);
717 auto future
= QtConcurrent::run([config
]() {
720 m_sessionSaveWatcher
->setFuture(future
);
724 void DolphinMainWindow::setSessionAutoSaveEnabled(bool enable
)
727 if (!m_sessionSaveTimer
) {
728 m_sessionSaveTimer
= new QTimer(this);
729 m_sessionSaveWatcher
= new QFutureWatcher
<void>(this);
730 m_sessionSaveTimer
->setSingleShot(true);
731 m_sessionSaveTimer
->setInterval(22000);
733 connect(m_sessionSaveTimer
, &QTimer::timeout
, this, &DolphinMainWindow::slotSaveSession
);
736 connect(m_tabWidget
, &DolphinTabWidget::urlChanged
, m_sessionSaveTimer
, qOverload
<>(&QTimer::start
), Qt::UniqueConnection
);
737 connect(m_tabWidget
, &DolphinTabWidget::tabCountChanged
, m_sessionSaveTimer
, qOverload
<>(&QTimer::start
), Qt::UniqueConnection
);
738 connect(m_tabWidget
, &DolphinTabWidget::activeViewChanged
, m_sessionSaveTimer
, qOverload
<>(&QTimer::start
), Qt::UniqueConnection
);
739 } else if (m_sessionSaveTimer
) {
740 m_sessionSaveTimer
->stop();
741 m_sessionSaveWatcher
->disconnect();
742 m_sessionSaveScheduled
= false;
744 m_sessionSaveWatcher
->waitForFinished();
746 m_sessionSaveTimer
->deleteLater();
747 m_sessionSaveWatcher
->deleteLater();
748 m_sessionSaveTimer
= nullptr;
749 m_sessionSaveWatcher
= nullptr;
753 void DolphinMainWindow::saveProperties(KConfigGroup
&group
)
755 m_tabWidget
->saveProperties(group
);
758 void DolphinMainWindow::readProperties(const KConfigGroup
&group
)
760 m_tabWidget
->readProperties(group
);
763 void DolphinMainWindow::updateNewMenu()
765 m_newFileMenu
->checkUpToDate();
766 m_newFileMenu
->setWorkingDirectory(activeViewContainer()->url());
769 void DolphinMainWindow::createDirectory()
771 m_newFileMenu
->setWorkingDirectory(activeViewContainer()->url());
772 m_newFileMenu
->createDirectory();
775 void DolphinMainWindow::quit()
780 void DolphinMainWindow::showErrorMessage(const QString
&message
)
782 m_activeViewContainer
->showMessage(message
, DolphinViewContainer::Error
);
785 void DolphinMainWindow::slotUndoAvailable(bool available
)
787 QAction
*undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
789 undoAction
->setEnabled(available
);
793 void DolphinMainWindow::slotUndoTextChanged(const QString
&text
)
795 QAction
*undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
797 undoAction
->setText(text
);
801 void DolphinMainWindow::undo()
804 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
805 KIO::FileUndoManager::self()->undo();
808 void DolphinMainWindow::cut()
810 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
811 m_activeViewContainer
->setSelectionModeEnabled(true, actionCollection(), SelectionMode::BottomBar::Contents::CutContents
);
813 m_activeViewContainer
->view()->cutSelectedItemsToClipboard();
814 m_activeViewContainer
->setSelectionModeEnabled(false);
818 void DolphinMainWindow::copy()
820 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
821 m_activeViewContainer
->setSelectionModeEnabled(true, actionCollection(), SelectionMode::BottomBar::Contents::CopyContents
);
823 m_activeViewContainer
->view()->copySelectedItemsToClipboard();
824 m_activeViewContainer
->setSelectionModeEnabled(false);
828 void DolphinMainWindow::paste()
830 m_activeViewContainer
->view()->paste();
833 void DolphinMainWindow::find()
835 m_activeViewContainer
->setSearchModeEnabled(true);
838 void DolphinMainWindow::updateSearchAction()
840 QAction
*toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
841 toggleSearchAction
->setChecked(m_activeViewContainer
->isSearchModeEnabled());
844 void DolphinMainWindow::updatePasteAction()
846 QAction
*pasteAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Paste
));
847 QPair
<bool, QString
> pasteInfo
= m_activeViewContainer
->view()->pasteInfo();
848 pasteAction
->setEnabled(pasteInfo
.first
);
849 pasteAction
->setText(pasteInfo
.second
);
852 void DolphinMainWindow::slotDirectoryLoadingCompleted()
857 void DolphinMainWindow::slotToolBarActionMiddleClicked(QAction
*action
)
859 if (action
== actionCollection()->action(KStandardAction::name(KStandardAction::Back
))) {
861 } else if (action
== actionCollection()->action(KStandardAction::name(KStandardAction::Forward
))) {
863 } else if (action
== actionCollection()->action(QStringLiteral("go_up"))) {
865 } else if (action
== actionCollection()->action(QStringLiteral("go_home"))) {
870 QAction
*DolphinMainWindow::urlNavigatorHistoryAction(const KUrlNavigator
*urlNavigator
, int historyIndex
, QObject
*parent
)
872 const QUrl url
= urlNavigator
->locationUrl(historyIndex
);
874 QString text
= url
.toDisplayString(QUrl::PreferLocalFile
);
876 if (!urlNavigator
->showFullPath()) {
877 const KFilePlacesModel
*placesModel
= DolphinPlacesModelSingleton::instance().placesModel();
879 const QModelIndex closestIdx
= placesModel
->closestItem(url
);
880 if (closestIdx
.isValid()) {
881 const QUrl placeUrl
= placesModel
->url(closestIdx
);
883 text
= placesModel
->text(closestIdx
);
885 QString pathInsidePlace
= url
.path().mid(placeUrl
.path().length());
887 if (!pathInsidePlace
.isEmpty() && !pathInsidePlace
.startsWith(QLatin1Char('/'))) {
888 pathInsidePlace
.prepend(QLatin1Char('/'));
891 if (pathInsidePlace
!= QLatin1Char('/')) {
892 text
.append(pathInsidePlace
);
897 QAction
*action
= new QAction(QIcon::fromTheme(KIO::iconNameForUrl(url
)), text
, parent
);
898 action
->setData(historyIndex
);
902 void DolphinMainWindow::slotAboutToShowBackPopupMenu()
904 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
906 QMenu
*menu
= m_backAction
->popupMenu();
908 for (int i
= urlNavigator
->historyIndex() + 1; i
< urlNavigator
->historySize() && entries
< MaxNumberOfNavigationentries
; ++i
, ++entries
) {
909 QAction
*action
= urlNavigatorHistoryAction(urlNavigator
, i
, menu
);
910 menu
->addAction(action
);
914 void DolphinMainWindow::slotGoBack(QAction
*action
)
916 int gotoIndex
= action
->data().value
<int>();
917 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
918 for (int i
= gotoIndex
- urlNavigator
->historyIndex(); i
> 0; --i
) {
923 void DolphinMainWindow::slotBackForwardActionMiddleClicked(QAction
*action
)
926 const KUrlNavigator
*urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
927 openNewTab(urlNavigator
->locationUrl(action
->data().value
<int>()));
931 void DolphinMainWindow::slotAboutToShowForwardPopupMenu()
933 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
935 QMenu
*menu
= m_forwardAction
->popupMenu();
936 for (int i
= urlNavigator
->historyIndex() - 1; i
>= 0 && entries
< MaxNumberOfNavigationentries
; --i
, ++entries
) {
937 QAction
*action
= urlNavigatorHistoryAction(urlNavigator
, i
, menu
);
938 menu
->addAction(action
);
942 void DolphinMainWindow::slotGoForward(QAction
*action
)
944 int gotoIndex
= action
->data().value
<int>();
945 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
946 for (int i
= urlNavigator
->historyIndex() - gotoIndex
; i
> 0; --i
) {
951 void DolphinMainWindow::slotSetSelectionMode(bool enabled
, SelectionMode::BottomBar::Contents bottomBarContents
)
953 m_activeViewContainer
->setSelectionModeEnabled(enabled
, actionCollection(), bottomBarContents
);
956 void DolphinMainWindow::selectAll()
960 // if the URL navigator is editable and focused, select the whole
961 // URL instead of all items of the view
963 KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigator();
964 QLineEdit
*lineEdit
= urlNavigator
->editor()->lineEdit();
965 const bool selectUrl
= urlNavigator
->isUrlEditable() && lineEdit
->hasFocus();
967 lineEdit
->selectAll();
969 m_activeViewContainer
->view()->selectAll();
973 void DolphinMainWindow::invertSelection()
976 m_activeViewContainer
->view()->invertSelection();
979 void DolphinMainWindow::toggleSplitView()
981 DolphinTabPage
*tabPage
= m_tabWidget
->currentTabPage();
982 tabPage
->setSplitViewEnabled(!tabPage
->splitViewEnabled(), WithAnimation
);
983 m_tabWidget
->updateTabName(m_tabWidget
->indexOf(tabPage
));
987 void DolphinMainWindow::popoutSplitView()
989 DolphinTabPage
*tabPage
= m_tabWidget
->currentTabPage();
990 if (!tabPage
->splitViewEnabled())
992 openNewWindow(tabPage
->activeViewContainer()->url());
993 tabPage
->setSplitViewEnabled(false, WithAnimation
);
994 updateSplitActions();
997 void DolphinMainWindow::toggleSplitStash()
999 DolphinTabPage
*tabPage
= m_tabWidget
->currentTabPage();
1000 tabPage
->setSplitViewEnabled(false, WithAnimation
);
1001 tabPage
->setSplitViewEnabled(true, WithAnimation
, QUrl("stash:/"));
1004 void DolphinMainWindow::copyToInactiveSplitView()
1006 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
1007 m_activeViewContainer
->setSelectionModeEnabled(true, actionCollection(), SelectionMode::BottomBar::Contents::CopyToOtherViewContents
);
1009 m_tabWidget
->copyToInactiveSplitView();
1010 m_activeViewContainer
->setSelectionModeEnabled(false);
1014 void DolphinMainWindow::moveToInactiveSplitView()
1016 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
1017 m_activeViewContainer
->setSelectionModeEnabled(true, actionCollection(), SelectionMode::BottomBar::Contents::MoveToOtherViewContents
);
1019 m_tabWidget
->moveToInactiveSplitView();
1020 m_activeViewContainer
->setSelectionModeEnabled(false);
1024 void DolphinMainWindow::reloadView()
1027 m_activeViewContainer
->reload();
1028 m_activeViewContainer
->statusBar()->updateSpaceInfo();
1031 void DolphinMainWindow::stopLoading()
1033 m_activeViewContainer
->view()->stopLoading();
1036 void DolphinMainWindow::enableStopAction()
1038 actionCollection()->action(QStringLiteral("stop"))->setEnabled(true);
1041 void DolphinMainWindow::disableStopAction()
1043 actionCollection()->action(QStringLiteral("stop"))->setEnabled(false);
1046 void DolphinMainWindow::toggleSelectionMode()
1048 const bool checked
= !m_activeViewContainer
->isSelectionModeEnabled();
1050 m_activeViewContainer
->setSelectionModeEnabled(checked
, actionCollection(), SelectionMode::BottomBar::Contents::GeneralContents
);
1051 actionCollection()->action(QStringLiteral("toggle_selection_mode"))->setChecked(checked
);
1054 void DolphinMainWindow::showFilterBar()
1056 m_activeViewContainer
->setFilterBarVisible(true);
1059 void DolphinMainWindow::toggleFilterBar()
1061 const bool checked
= !m_activeViewContainer
->isFilterBarVisible();
1062 m_activeViewContainer
->setFilterBarVisible(checked
);
1064 QAction
*toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
1065 toggleFilterBarAction
->setChecked(checked
);
1068 void DolphinMainWindow::toggleEditLocation()
1072 QAction
*action
= actionCollection()->action(QStringLiteral("editable_location"));
1073 KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigator();
1074 urlNavigator
->setUrlEditable(action
->isChecked());
1077 void DolphinMainWindow::replaceLocation()
1079 KUrlNavigator
*navigator
= m_activeViewContainer
->urlNavigator();
1080 QLineEdit
*lineEdit
= navigator
->editor()->lineEdit();
1082 // If the text field currently has focus and everything is selected,
1083 // pressing the keyboard shortcut returns the whole thing to breadcrumb mode
1084 if (navigator
->isUrlEditable() && lineEdit
->hasFocus() && lineEdit
->selectedText() == lineEdit
->text()) {
1085 navigator
->setUrlEditable(false);
1087 navigator
->setUrlEditable(true);
1088 navigator
->setFocus();
1089 lineEdit
->selectAll();
1093 void DolphinMainWindow::togglePanelLockState()
1095 const bool newLockState
= !GeneralSettings::lockPanels();
1096 const auto childrenObjects
= children();
1097 for (QObject
*child
: childrenObjects
) {
1098 DolphinDockWidget
*dock
= qobject_cast
<DolphinDockWidget
*>(child
);
1100 dock
->setLocked(newLockState
);
1104 DolphinPlacesModelSingleton::instance().placesModel()->setPanelsLocked(newLockState
);
1106 GeneralSettings::setLockPanels(newLockState
);
1109 void DolphinMainWindow::slotTerminalPanelVisibilityChanged()
1111 if (m_terminalPanel
->isHiddenInVisibleWindow() && m_activeViewContainer
) {
1112 m_activeViewContainer
->view()->setFocus();
1116 void DolphinMainWindow::goBack()
1118 DolphinUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
1119 urlNavigator
->goBack();
1121 if (urlNavigator
->locationState().isEmpty()) {
1122 // An empty location state indicates a redirection URL,
1123 // which must be skipped too
1124 urlNavigator
->goBack();
1128 void DolphinMainWindow::goForward()
1130 m_activeViewContainer
->urlNavigatorInternalWithHistory()->goForward();
1133 void DolphinMainWindow::goUp()
1135 m_activeViewContainer
->urlNavigatorInternalWithHistory()->goUp();
1138 void DolphinMainWindow::goHome()
1140 m_activeViewContainer
->urlNavigatorInternalWithHistory()->goHome();
1143 void DolphinMainWindow::goBackInNewTab()
1145 const KUrlNavigator
*urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
1146 const int index
= urlNavigator
->historyIndex() + 1;
1147 openNewTab(urlNavigator
->locationUrl(index
));
1150 void DolphinMainWindow::goForwardInNewTab()
1152 const KUrlNavigator
*urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
1153 const int index
= urlNavigator
->historyIndex() - 1;
1154 openNewTab(urlNavigator
->locationUrl(index
));
1157 void DolphinMainWindow::goUpInNewTab()
1159 const QUrl currentUrl
= activeViewContainer()->urlNavigator()->locationUrl();
1160 openNewTab(KIO::upUrl(currentUrl
));
1163 void DolphinMainWindow::goHomeInNewTab()
1165 openNewTab(Dolphin::homeUrl());
1168 void DolphinMainWindow::compareFiles()
1170 const KFileItemList items
= m_tabWidget
->currentTabPage()->selectedItems();
1171 if (items
.count() != 2) {
1172 // The action is disabled in this case, but it could have been triggered
1173 // via D-Bus, see https://bugs.kde.org/show_bug.cgi?id=325517
1177 QUrl urlA
= items
.at(0).url();
1178 QUrl urlB
= items
.at(1).url();
1180 QString
command(QStringLiteral("kompare -c \""));
1181 command
.append(urlA
.toDisplayString(QUrl::PreferLocalFile
));
1182 command
.append("\" \"");
1183 command
.append(urlB
.toDisplayString(QUrl::PreferLocalFile
));
1184 command
.append('\"');
1186 KIO::CommandLauncherJob
*job
= new KIO::CommandLauncherJob(command
, this);
1187 job
->setDesktopName(QStringLiteral("org.kde.kompare"));
1191 void DolphinMainWindow::toggleShowMenuBar()
1193 const bool visible
= menuBar()->isVisible();
1194 menuBar()->setVisible(!visible
);
1197 QPointer
<QAction
> DolphinMainWindow::preferredSearchTool()
1199 m_searchTools
.clear();
1201 KService::Ptr kfind
= KService::serviceByDesktopName(QStringLiteral("org.kde.kfind"));
1207 auto *action
= new QAction(QIcon::fromTheme(kfind
->icon()), kfind
->name(), this);
1209 connect(action
, &QAction::triggered
, this, [kfind
] {
1210 auto *job
= new KIO::ApplicationLauncherJob(kfind
);
1217 void DolphinMainWindow::updateOpenPreferredSearchToolAction()
1219 QAction
*openPreferredSearchTool
= actionCollection()->action(QStringLiteral("open_preferred_search_tool"));
1220 if (!openPreferredSearchTool
) {
1223 QPointer
<QAction
> tool
= preferredSearchTool();
1225 openPreferredSearchTool
->setVisible(true);
1226 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open %1", tool
->text()));
1227 // Only override with the app icon if it is the default, i.e. the user hasn't configured one manually
1228 // https://bugs.kde.org/show_bug.cgi?id=442815
1229 if (openPreferredSearchTool
->icon().name() == QLatin1String("search")) {
1230 openPreferredSearchTool
->setIcon(tool
->icon());
1233 openPreferredSearchTool
->setVisible(false);
1234 // still visible in Shortcuts configuration window
1235 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool"));
1236 openPreferredSearchTool
->setIcon(QIcon::fromTheme(QStringLiteral("search")));
1240 void DolphinMainWindow::openPreferredSearchTool()
1242 QPointer
<QAction
> tool
= preferredSearchTool();
1248 void DolphinMainWindow::openTerminal()
1250 openTerminalJob(m_activeViewContainer
->url());
1253 void DolphinMainWindow::openTerminalHere()
1255 QList
<QUrl
> urls
= {};
1257 const auto selectedItems
= m_activeViewContainer
->view()->selectedItems();
1258 for (const KFileItem
&item
: selectedItems
) {
1259 QUrl url
= item
.targetUrl();
1260 if (item
.isFile()) {
1261 url
.setPath(QFileInfo(url
.path()).absolutePath());
1263 if (!urls
.contains(url
)) {
1268 // No items are selected. Open a terminal window for the current location.
1269 if (urls
.count() == 0) {
1274 if (urls
.count() > 5) {
1275 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());
1276 const int answer
= KMessageBox::warningContinueCancel(
1280 KGuiItem(i18ncp("@action:button", "Open %1 Terminal", "Open %1 Terminals", urls
.count()), QStringLiteral("utilities-terminal")),
1281 KStandardGuiItem::cancel(),
1282 QStringLiteral("ConfirmOpenManyTerminals"));
1283 if (answer
!= KMessageBox::PrimaryAction
&& answer
!= KMessageBox::Continue
) {
1288 for (const QUrl
&url
: std::as_const(urls
)) {
1289 openTerminalJob(url
);
1293 void DolphinMainWindow::openTerminalJob(const QUrl
&url
)
1295 if (url
.isLocalFile()) {
1296 auto job
= new KTerminalLauncherJob(QString());
1297 job
->setWorkingDirectory(url
.toLocalFile());
1302 // Not a local file, with protocol Class ":local", try stat'ing
1303 if (KProtocolInfo::protocolClass(url
.scheme()) == QLatin1String(":local")) {
1304 KIO::StatJob
*job
= KIO::mostLocalUrl(url
);
1305 KJobWidgets::setWindow(job
, this);
1306 connect(job
, &KJob::result
, this, [job
]() {
1308 if (!job
->error()) {
1309 statUrl
= job
->mostLocalUrl();
1312 auto job
= new KTerminalLauncherJob(QString());
1313 job
->setWorkingDirectory(statUrl
.isLocalFile() ? statUrl
.toLocalFile() : QDir::homePath());
1320 // Nothing worked, just use $HOME
1321 auto job
= new KTerminalLauncherJob(QString());
1322 job
->setWorkingDirectory(QDir::homePath());
1326 void DolphinMainWindow::editSettings()
1328 if (!m_settingsDialog
) {
1329 DolphinViewContainer
*container
= activeViewContainer();
1330 container
->view()->writeSettings();
1332 const QUrl url
= container
->url();
1333 DolphinSettingsDialog
*settingsDialog
= new DolphinSettingsDialog(url
, this, actionCollection());
1334 connect(settingsDialog
, &DolphinSettingsDialog::settingsChanged
, this, &DolphinMainWindow::refreshViews
);
1335 connect(settingsDialog
, &DolphinSettingsDialog::settingsChanged
, &DolphinUrlNavigatorsController::slotReadSettings
);
1336 settingsDialog
->setAttribute(Qt::WA_DeleteOnClose
);
1337 settingsDialog
->show();
1338 m_settingsDialog
= settingsDialog
;
1340 m_settingsDialog
.data()->raise();
1344 void DolphinMainWindow::handleUrl(const QUrl
&url
)
1346 delete m_lastHandleUrlOpenJob
;
1347 m_lastHandleUrlOpenJob
= nullptr;
1349 if (url
.isLocalFile() && QFileInfo(url
.toLocalFile()).isDir()) {
1350 activeViewContainer()->setUrl(url
);
1352 m_lastHandleUrlOpenJob
= new KIO::OpenUrlJob(url
);
1353 m_lastHandleUrlOpenJob
->setUiDelegate(KIO::createDefaultJobUiDelegate(KJobUiDelegate::AutoHandlingEnabled
, this));
1354 m_lastHandleUrlOpenJob
->setShowOpenOrExecuteDialog(true);
1356 connect(m_lastHandleUrlOpenJob
, &KIO::OpenUrlJob::mimeTypeFound
, this, [this, url
](const QString
&mimetype
) {
1357 if (mimetype
== QLatin1String("inode/directory")) {
1358 // If it's a dir, we'll take it from here
1359 m_lastHandleUrlOpenJob
->kill();
1360 m_lastHandleUrlOpenJob
= nullptr;
1361 activeViewContainer()->setUrl(url
);
1365 connect(m_lastHandleUrlOpenJob
, &KIO::OpenUrlJob::result
, this, [this]() {
1366 m_lastHandleUrlOpenJob
= nullptr;
1369 m_lastHandleUrlOpenJob
->start();
1373 void DolphinMainWindow::slotWriteStateChanged(bool isFolderWritable
)
1375 // trash:/ is writable but we don't want to create new items in it.
1376 // TODO: remove the trash check once https://phabricator.kde.org/T8234 is implemented
1377 newFileMenu()->setEnabled(isFolderWritable
&& m_activeViewContainer
->url().scheme() != QLatin1String("trash"));
1380 void DolphinMainWindow::openContextMenu(const QPoint
&pos
, const KFileItem
&item
, const KFileItemList
&selectedItems
, const QUrl
&url
)
1382 QPointer
<DolphinContextMenu
> contextMenu
= new DolphinContextMenu(this, item
, selectedItems
, url
, &m_fileItemActions
);
1383 contextMenu
->exec(pos
);
1385 // Delete the menu, unless it has been deleted in its own nested event loop already.
1387 contextMenu
->deleteLater();
1391 QMenu
*DolphinMainWindow::createPopupMenu()
1393 QMenu
*menu
= KXmlGuiWindow::createPopupMenu();
1395 menu
->addSeparator();
1396 menu
->addAction(actionCollection()->action(QStringLiteral("lock_panels")));
1401 void DolphinMainWindow::updateHamburgerMenu()
1403 KActionCollection
*ac
= actionCollection();
1404 auto hamburgerMenu
= static_cast<KHamburgerMenu
*>(ac
->action(KStandardAction::name(KStandardAction::HamburgerMenu
)));
1405 auto menu
= hamburgerMenu
->menu();
1407 menu
= new QMenu(this);
1408 hamburgerMenu
->setMenu(menu
);
1409 hamburgerMenu
->hideActionsOf(ac
->action(QStringLiteral("basic_actions"))->menu());
1410 hamburgerMenu
->hideActionsOf(ac
->action(QStringLiteral("zoom"))->menu());
1414 const QList
<QAction
*> toolbarActions
= toolBar()->actions();
1416 if (!toolBar()->isVisible()) {
1417 // If neither the menu bar nor the toolbar are visible, these actions should be available.
1418 menu
->addAction(ac
->action(KStandardAction::name(KStandardAction::ShowMenubar
)));
1419 menu
->addAction(toolBarMenuAction());
1420 menu
->addSeparator();
1423 // This group of actions (until the next separator) contains all the most basic actions
1424 // necessary to use Dolphin effectively.
1425 menu
->addAction(ac
->action(QStringLiteral("go_back")));
1426 menu
->addAction(ac
->action(QStringLiteral("go_forward")));
1428 menu
->addMenu(m_newFileMenu
->menu());
1429 if (!toolBar()->isVisible() || !toolbarActions
.contains(ac
->action(QStringLiteral("toggle_selection_mode_tool_bar")))) {
1430 menu
->addAction(ac
->action(QStringLiteral("toggle_selection_mode")));
1432 menu
->addAction(ac
->action(QStringLiteral("basic_actions")));
1433 menu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Undo
)));
1434 if (!toolBar()->isVisible()
1435 || (!toolbarActions
.contains(ac
->action(QStringLiteral("toggle_search")))
1436 && !toolbarActions
.contains(ac
->action(QStringLiteral("open_preferred_search_tool"))))) {
1437 menu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Find
)));
1438 // This way a search action will only be added if none of the three available
1439 // search actions is present on the toolbar.
1441 if (!toolBar()->isVisible() || !toolbarActions
.contains(ac
->action(QStringLiteral("toggle_filter")))) {
1442 menu
->addAction(ac
->action(QStringLiteral("show_filter_bar")));
1443 // This way a filter action will only be added if none of the two available
1444 // filter actions is present on the toolbar.
1446 menu
->addSeparator();
1448 // The second group of actions (up until the next separator) contains actions for opening
1449 // additional views to interact with the file system.
1450 menu
->addAction(ac
->action(QStringLiteral("file_new")));
1451 menu
->addAction(ac
->action(QStringLiteral("new_tab")));
1452 if (ac
->action(QStringLiteral("undo_close_tab"))->isEnabled()) {
1453 menu
->addAction(ac
->action(QStringLiteral("closed_tabs")));
1455 menu
->addAction(ac
->action(QStringLiteral("open_terminal")));
1456 menu
->addSeparator();
1458 // The third group contains actions to change what one sees in the view
1459 // and to change the more general UI.
1460 if (!toolBar()->isVisible()
1461 || (!toolbarActions
.contains(ac
->action(QStringLiteral("icons"))) && !toolbarActions
.contains(ac
->action(QStringLiteral("compact")))
1462 && !toolbarActions
.contains(ac
->action(QStringLiteral("details"))) && !toolbarActions
.contains(ac
->action(QStringLiteral("view_mode"))))) {
1463 menu
->addAction(ac
->action(QStringLiteral("view_mode")));
1465 menu
->addAction(ac
->action(QStringLiteral("show_hidden_files")));
1466 menu
->addAction(ac
->action(QStringLiteral("sort")));
1467 menu
->addAction(ac
->action(QStringLiteral("additional_info")));
1468 if (!GeneralSettings::showStatusBar() || !GeneralSettings::showZoomSlider()) {
1469 menu
->addAction(ac
->action(QStringLiteral("zoom")));
1471 menu
->addAction(ac
->action(QStringLiteral("panels")));
1473 // The "Configure" menu is not added to the actionCollection() because there is hardly
1474 // a good reason for users to put it on their toolbar.
1475 auto configureMenu
= menu
->addMenu(QIcon::fromTheme(QStringLiteral("configure")), i18nc("@action:inmenu menu for configure actions", "Configure"));
1476 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::SwitchApplicationLanguage
)));
1477 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::KeyBindings
)));
1478 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::ConfigureToolbars
)));
1479 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Preferences
)));
1480 hamburgerMenu
->hideActionsOf(configureMenu
);
1483 void DolphinMainWindow::slotPlaceActivated(const QUrl
&url
)
1485 DolphinViewContainer
*view
= activeViewContainer();
1487 if (view
->url() == url
) {
1488 view
->clearFilterBar(); // Fixes bug 259382.
1490 // We can end up here if the user clicked a device in the Places Panel
1491 // which had been unmounted earlier, see https://bugs.kde.org/show_bug.cgi?id=161385.
1494 view
->disableUrlNavigatorSelectionRequests();
1496 view
->enableUrlNavigatorSelectionRequests();
1500 void DolphinMainWindow::closedTabsCountChanged(unsigned int count
)
1502 actionCollection()->action(QStringLiteral("undo_close_tab"))->setEnabled(count
> 0);
1505 void DolphinMainWindow::activeViewChanged(DolphinViewContainer
*viewContainer
)
1507 DolphinViewContainer
*oldViewContainer
= m_activeViewContainer
;
1508 Q_ASSERT(viewContainer
);
1510 m_activeViewContainer
= viewContainer
;
1512 if (oldViewContainer
) {
1513 const QAction
*toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
1514 toggleSearchAction
->disconnect(oldViewContainer
);
1516 // Disconnect all signals between the old view container (container,
1517 // view and url navigator) and main window.
1518 oldViewContainer
->disconnect(this);
1519 oldViewContainer
->view()->disconnect(this);
1520 oldViewContainer
->urlNavigatorInternalWithHistory()->disconnect(this);
1521 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>(actionCollection()->action(QStringLiteral("url_navigators")));
1522 navigators
->primaryUrlNavigator()->disconnect(this);
1523 if (auto secondaryUrlNavigator
= navigators
->secondaryUrlNavigator()) {
1524 secondaryUrlNavigator
->disconnect(this);
1527 // except the requestItemInfo so that on hover the information panel can still be updated
1528 connect(oldViewContainer
->view(), &DolphinView::requestItemInfo
, this, &DolphinMainWindow::requestItemInfo
);
1530 // Disconnect other slots.
1531 disconnect(oldViewContainer
,
1532 &DolphinViewContainer::selectionModeChanged
,
1533 actionCollection()->action(QStringLiteral("toggle_selection_mode")),
1534 &QAction::setChecked
);
1537 connectViewSignals(viewContainer
);
1539 m_actionHandler
->setCurrentView(viewContainer
->view());
1542 updateFileAndEditActions();
1543 updatePasteAction();
1544 updateViewActions();
1546 updateSearchAction();
1548 const QUrl url
= viewContainer
->url();
1549 Q_EMIT
urlChanged(url
);
1552 void DolphinMainWindow::tabCountChanged(int count
)
1554 const bool enableTabActions
= (count
> 1);
1555 for (int i
= 0; i
< MaxActivateTabShortcuts
; ++i
) {
1556 actionCollection()->action(QStringLiteral("activate_tab_%1").arg(i
))->setEnabled(enableTabActions
);
1558 actionCollection()->action(QStringLiteral("activate_last_tab"))->setEnabled(enableTabActions
);
1559 actionCollection()->action(QStringLiteral("activate_next_tab"))->setEnabled(enableTabActions
);
1560 actionCollection()->action(QStringLiteral("activate_prev_tab"))->setEnabled(enableTabActions
);
1563 void DolphinMainWindow::updateWindowTitle()
1565 const QString newTitle
= m_activeViewContainer
->captionWindowTitle();
1566 if (windowTitle() != newTitle
) {
1567 setWindowTitle(newTitle
);
1571 void DolphinMainWindow::slotStorageTearDownFromPlacesRequested(const QString
&mountPath
)
1573 connect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, this, [this, mountPath
]() {
1574 setViewsToHomeIfMountPathOpen(mountPath
);
1577 if (m_terminalPanel
&& m_terminalPanel
->currentWorkingDirectoryIsChildOf(mountPath
)) {
1578 m_tearDownFromPlacesRequested
= true;
1579 m_terminalPanel
->goHome();
1580 // m_placesPanel->proceedWithTearDown() will be called in slotTerminalDirectoryChanged
1582 m_placesPanel
->proceedWithTearDown();
1586 void DolphinMainWindow::slotStorageTearDownExternallyRequested(const QString
&mountPath
)
1588 connect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, this, [this, mountPath
]() {
1589 setViewsToHomeIfMountPathOpen(mountPath
);
1592 if (m_terminalPanel
&& m_terminalPanel
->currentWorkingDirectoryIsChildOf(mountPath
)) {
1593 m_tearDownFromPlacesRequested
= false;
1594 m_terminalPanel
->goHome();
1598 void DolphinMainWindow::slotKeyBindings()
1600 KShortcutsDialog
dialog(KShortcutsEditor::AllActions
, KShortcutsEditor::LetterShortcutsAllowed
, this);
1601 dialog
.addCollection(actionCollection());
1602 if (m_terminalPanel
) {
1603 KActionCollection
*konsolePartActionCollection
= m_terminalPanel
->actionCollection();
1604 if (konsolePartActionCollection
) {
1605 dialog
.addCollection(konsolePartActionCollection
, QStringLiteral("KonsolePart"));
1611 void DolphinMainWindow::setViewsToHomeIfMountPathOpen(const QString
&mountPath
)
1613 const QVector
<DolphinViewContainer
*> theViewContainers
= viewContainers();
1614 for (DolphinViewContainer
*viewContainer
: theViewContainers
) {
1615 if (viewContainer
&& viewContainer
->url().toLocalFile().startsWith(mountPath
)) {
1616 viewContainer
->setUrl(QUrl::fromLocalFile(QDir::homePath()));
1619 disconnect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, nullptr, nullptr);
1622 void DolphinMainWindow::setupActions()
1624 auto hamburgerMenuAction
= KStandardAction::hamburgerMenu(nullptr, nullptr, actionCollection());
1626 // setup 'File' menu
1627 m_newFileMenu
= new DolphinNewFileMenu(nullptr, this);
1628 actionCollection()->addAction(QStringLiteral("new_menu"), m_newFileMenu
);
1629 QMenu
*menu
= m_newFileMenu
->menu();
1630 menu
->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1631 menu
->setIcon(QIcon::fromTheme(QStringLiteral("list-add")));
1632 m_newFileMenu
->setPopupMode(QToolButton::InstantPopup
);
1633 connect(menu
, &QMenu::aboutToShow
, this, &DolphinMainWindow::updateNewMenu
);
1635 QAction
*newWindow
= KStandardAction::openNew(this, &DolphinMainWindow::openNewMainWindow
, actionCollection());
1636 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
1637 newWindow
->setToolTip(i18nc("@info", "Open a new Dolphin window"));
1638 newWindow
->setWhatsThis(xi18nc("@info:whatsthis",
1640 "window just like this one with the current location and view."
1641 "<nl/>You can drag and drop items between windows."));
1642 newWindow
->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
1644 QAction
*newTab
= actionCollection()->addAction(QStringLiteral("new_tab"));
1645 newTab
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1646 newTab
->setText(i18nc("@action:inmenu File", "New Tab"));
1647 newTab
->setWhatsThis(xi18nc("@info:whatsthis",
1649 "<emphasis>Tab</emphasis> with the current location and view.<nl/>"
1650 "A tab is an additional view within this window. "
1651 "You can drag and drop items between tabs."));
1652 actionCollection()->setDefaultShortcut(newTab
, Qt::CTRL
| Qt::Key_T
);
1653 connect(newTab
, &QAction::triggered
, this, &DolphinMainWindow::openNewActivatedTab
);
1655 QAction
*addToPlaces
= actionCollection()->addAction(QStringLiteral("add_to_places"));
1656 addToPlaces
->setIcon(QIcon::fromTheme(QStringLiteral("bookmark-new")));
1657 addToPlaces
->setText(i18nc("@action:inmenu Add current folder to places", "Add to Places"));
1658 addToPlaces
->setWhatsThis(xi18nc("@info:whatsthis",
1659 "This adds the selected folder "
1660 "to the Places panel."));
1661 connect(addToPlaces
, &QAction::triggered
, this, &DolphinMainWindow::addToPlaces
);
1663 QAction
*closeTab
= KStandardAction::close(m_tabWidget
, QOverload
<>::of(&DolphinTabWidget::closeTab
), actionCollection());
1664 closeTab
->setText(i18nc("@action:inmenu File", "Close Tab"));
1665 closeTab
->setWhatsThis(i18nc("@info:whatsthis",
1667 "currently viewed tab. If no more tabs are left this window "
1668 "will close instead."));
1670 QAction
*quitAction
= KStandardAction::quit(this, &DolphinMainWindow::quit
, actionCollection());
1671 quitAction
->setWhatsThis(i18nc("@info:whatsthis quit", "This closes this window."));
1673 // setup 'Edit' menu
1674 KStandardAction::undo(this, &DolphinMainWindow::undo
, actionCollection());
1676 // i18n: This will be the last paragraph for the whatsthis for all three:
1677 // Cut, Copy and Paste
1678 const QString cutCopyPastePara
= xi18nc("@info:whatsthis",
1679 "<para><emphasis>Cut, "
1680 "Copy</emphasis> and <emphasis>Paste</emphasis> work between many "
1681 "applications and are among the most used commands. That's why their "
1682 "<emphasis>keyboard shortcuts</emphasis> are prominently placed right "
1683 "next to each other on the keyboard: <shortcut>Ctrl+X</shortcut>, "
1684 "<shortcut>Ctrl+C</shortcut> and <shortcut>Ctrl+V</shortcut>.</para>");
1685 QAction
*cutAction
= KStandardAction::cut(this, &DolphinMainWindow::cut
, actionCollection());
1686 m_actionTextHelper
->registerTextWhenNothingIsSelected(cutAction
, i18nc("@action", "Cut…"));
1687 cutAction
->setWhatsThis(xi18nc("@info:whatsthis cut",
1688 "This copies the items "
1689 "in your current selection to the <emphasis>clipboard</emphasis>.<nl/>"
1690 "Use the <emphasis>Paste</emphasis> action afterwards to copy them from "
1691 "the clipboard to a new location. The items will be removed from their "
1692 "initial location.")
1693 + cutCopyPastePara
);
1694 QAction
*copyAction
= KStandardAction::copy(this, &DolphinMainWindow::copy
, actionCollection());
1695 m_actionTextHelper
->registerTextWhenNothingIsSelected(copyAction
, i18nc("@action", "Copy…"));
1696 copyAction
->setWhatsThis(xi18nc("@info:whatsthis copy",
1698 "items in your current selection to the <emphasis>clipboard</emphasis>."
1699 "<nl/>Use the <emphasis>Paste</emphasis> action afterwards to copy them "
1700 "from the clipboard to a new location.")
1701 + cutCopyPastePara
);
1702 QAction
*paste
= KStandardAction::paste(this, &DolphinMainWindow::paste
, actionCollection());
1703 // The text of the paste-action is modified dynamically by Dolphin
1704 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1705 // due to the long text, the text "Paste" is used:
1706 paste
->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1707 paste
->setWhatsThis(xi18nc("@info:whatsthis paste",
1708 "This copies the items from "
1709 "your <emphasis>clipboard</emphasis> to the currently viewed folder.<nl/>"
1710 "If the items were added to the clipboard by the <emphasis>Cut</emphasis> "
1711 "action they are removed from their old location.")
1712 + cutCopyPastePara
);
1714 QAction
*copyToOtherViewAction
= actionCollection()->addAction(QStringLiteral("copy_to_inactive_split_view"));
1715 copyToOtherViewAction
->setText(i18nc("@action:inmenu", "Copy to Other View"));
1716 m_actionTextHelper
->registerTextWhenNothingIsSelected(copyToOtherViewAction
, i18nc("@action:inmenu", "Copy to Other View…"));
1717 copyToOtherViewAction
->setWhatsThis(xi18nc("@info:whatsthis Copy",
1718 "This copies the selected items from "
1719 "the <emphasis>active</emphasis> view to the inactive split view."));
1720 copyToOtherViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("edit-copy")));
1721 copyToOtherViewAction
->setIconText(i18nc("@action:inmenu Edit", "Copy to Inactive Split View"));
1722 actionCollection()->setDefaultShortcut(copyToOtherViewAction
, Qt::SHIFT
| Qt::Key_F5
);
1723 connect(copyToOtherViewAction
, &QAction::triggered
, this, &DolphinMainWindow::copyToInactiveSplitView
);
1725 QAction
*moveToOtherViewAction
= actionCollection()->addAction(QStringLiteral("move_to_inactive_split_view"));
1726 moveToOtherViewAction
->setText(i18nc("@action:inmenu", "Move to Other View"));
1727 m_actionTextHelper
->registerTextWhenNothingIsSelected(moveToOtherViewAction
, i18nc("@action:inmenu", "Move to Other View…"));
1728 moveToOtherViewAction
->setWhatsThis(xi18nc("@info:whatsthis Move",
1729 "This moves the selected items from "
1730 "the <emphasis>active</emphasis> view to the inactive split view."));
1731 moveToOtherViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("edit-cut")));
1732 moveToOtherViewAction
->setIconText(i18nc("@action:inmenu Edit", "Move to Inactive Split View"));
1733 actionCollection()->setDefaultShortcut(moveToOtherViewAction
, Qt::SHIFT
| Qt::Key_F6
);
1734 connect(moveToOtherViewAction
, &QAction::triggered
, this, &DolphinMainWindow::moveToInactiveSplitView
);
1736 QAction
*showFilterBar
= actionCollection()->addAction(QStringLiteral("show_filter_bar"));
1737 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Filter…"));
1738 showFilterBar
->setToolTip(i18nc("@info:tooltip", "Show Filter Bar"));
1739 showFilterBar
->setWhatsThis(xi18nc("@info:whatsthis",
1741 "<emphasis>Filter Bar</emphasis> at the bottom of the window.<nl/> "
1742 "There you can enter a text to filter the files and folders currently displayed. "
1743 "Only those that contain the text in their name will be kept in view."));
1744 showFilterBar
->setIcon(QIcon::fromTheme(QStringLiteral("view-filter")));
1745 actionCollection()->setDefaultShortcuts(showFilterBar
, {Qt::CTRL
| Qt::Key_I
, Qt::Key_Slash
});
1746 connect(showFilterBar
, &QAction::triggered
, this, &DolphinMainWindow::showFilterBar
);
1748 // toggle_filter acts as a copy of the main showFilterBar to be used mainly
1749 // in the toolbar, with no default shortcut attached, to avoid messing with
1750 // existing workflows (filter bar always open and Ctrl-I to focus)
1751 QAction
*toggleFilter
= actionCollection()->addAction(QStringLiteral("toggle_filter"));
1752 toggleFilter
->setText(i18nc("@action:inmenu", "Toggle Filter Bar"));
1753 toggleFilter
->setIconText(i18nc("@action:intoolbar", "Filter"));
1754 toggleFilter
->setIcon(showFilterBar
->icon());
1755 toggleFilter
->setToolTip(showFilterBar
->toolTip());
1756 toggleFilter
->setWhatsThis(showFilterBar
->whatsThis());
1757 toggleFilter
->setCheckable(true);
1758 connect(toggleFilter
, &QAction::triggered
, this, &DolphinMainWindow::toggleFilterBar
);
1760 QAction
*searchAction
= KStandardAction::find(this, &DolphinMainWindow::find
, actionCollection());
1761 searchAction
->setText(i18n("Search…"));
1762 searchAction
->setToolTip(i18nc("@info:tooltip", "Search for files and folders"));
1763 searchAction
->setWhatsThis(xi18nc("@info:whatsthis find",
1764 "<para>This helps you "
1765 "find files and folders by opening a <emphasis>find bar</emphasis>. "
1766 "There you can enter search terms and specify settings to find the "
1767 "objects you are looking for.</para><para>Use this help again on "
1768 "the find bar so we can have a look at it while the settings are "
1769 "explained.</para>"));
1771 // toggle_search acts as a copy of the main searchAction to be used mainly
1772 // in the toolbar, with no default shortcut attached, to avoid messing with
1773 // existing workflows (search bar always open and Ctrl-F to focus)
1774 QAction
*toggleSearchAction
= actionCollection()->addAction(QStringLiteral("toggle_search"));
1775 toggleSearchAction
->setText(i18nc("@action:inmenu", "Toggle Search Bar"));
1776 toggleSearchAction
->setIconText(i18nc("@action:intoolbar", "Search"));
1777 toggleSearchAction
->setIcon(searchAction
->icon());
1778 toggleSearchAction
->setToolTip(searchAction
->toolTip());
1779 toggleSearchAction
->setWhatsThis(searchAction
->whatsThis());
1780 toggleSearchAction
->setCheckable(true);
1782 QAction
*toggleSelectionModeAction
= actionCollection()->addAction(QStringLiteral("toggle_selection_mode"));
1783 // i18n: This action toggles a selection mode.
1784 toggleSelectionModeAction
->setText(i18nc("@action:inmenu", "Select Files and Folders"));
1785 // i18n: Opens a selection mode for selecting files/folders.
1786 // The text is kept so unspecific because it will be shown on the toolbar where space is at a premium.
1787 toggleSelectionModeAction
->setIconText(i18nc("@action:intoolbar", "Select"));
1788 toggleSelectionModeAction
->setWhatsThis(xi18nc(
1790 "<para>This application only knows which files or folders should be acted on if they are"
1791 " <emphasis>selected</emphasis> first. Press this to toggle a <emphasis>Selection Mode</emphasis> which makes selecting and deselecting as easy as "
1792 "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."
1794 toggleSelectionModeAction
->setIcon(QIcon::fromTheme(QStringLiteral("quickwizard")));
1795 toggleSelectionModeAction
->setCheckable(true);
1796 actionCollection()->setDefaultShortcut(toggleSelectionModeAction
, Qt::Key_Space
);
1797 connect(toggleSelectionModeAction
, &QAction::triggered
, this, &DolphinMainWindow::toggleSelectionMode
);
1799 // A special version of the toggleSelectionModeAction for the toolbar that also contains a menu
1800 // with the selectAllAction and invertSelectionAction.
1801 auto *toggleSelectionModeToolBarAction
=
1802 new KToolBarPopupAction(toggleSelectionModeAction
->icon(), toggleSelectionModeAction
->iconText(), actionCollection());
1803 toggleSelectionModeToolBarAction
->setToolTip(toggleSelectionModeAction
->text());
1804 toggleSelectionModeToolBarAction
->setWhatsThis(toggleSelectionModeAction
->whatsThis());
1805 actionCollection()->addAction(QStringLiteral("toggle_selection_mode_tool_bar"), toggleSelectionModeToolBarAction
);
1806 toggleSelectionModeToolBarAction
->setCheckable(true);
1807 toggleSelectionModeToolBarAction
->setPopupMode(KToolBarPopupAction::DelayedPopup
);
1808 connect(toggleSelectionModeToolBarAction
, &QAction::triggered
, toggleSelectionModeAction
, &QAction::trigger
);
1809 connect(toggleSelectionModeAction
, &QAction::toggled
, toggleSelectionModeToolBarAction
, &QAction::setChecked
);
1811 QAction
*selectAllAction
= KStandardAction::selectAll(this, &DolphinMainWindow::selectAll
, actionCollection());
1812 selectAllAction
->setWhatsThis(xi18nc("@info:whatsthis",
1814 "files and folders in the current location."));
1816 QAction
*invertSelection
= actionCollection()->addAction(QStringLiteral("invert_selection"));
1817 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1818 invertSelection
->setWhatsThis(xi18nc("@info:whatsthis invert",
1820 "objects that you have currently <emphasis>not</emphasis> selected instead."));
1821 invertSelection
->setIcon(QIcon::fromTheme(QStringLiteral("edit-select-invert")));
1822 actionCollection()->setDefaultShortcut(invertSelection
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
1823 connect(invertSelection
, &QAction::triggered
, this, &DolphinMainWindow::invertSelection
);
1825 QMenu
*toggleSelectionModeActionMenu
= new QMenu(this);
1826 toggleSelectionModeActionMenu
->addAction(selectAllAction
);
1827 toggleSelectionModeActionMenu
->addAction(invertSelection
);
1828 toggleSelectionModeToolBarAction
->setMenu(toggleSelectionModeActionMenu
);
1830 // setup 'View' menu
1831 // (note that most of it is set up in DolphinViewActionHandler)
1833 QAction
*split
= actionCollection()->addAction(QStringLiteral("split_view"));
1834 split
->setWhatsThis(xi18nc("@info:whatsthis find",
1835 "<para>This splits "
1836 "the folder view below into two autonomous views.</para><para>This "
1837 "way you can see two locations at once and move items between them "
1838 "quickly.</para>Click this again afterwards to recombine the views."));
1839 actionCollection()->setDefaultShortcut(split
, Qt::Key_F3
);
1840 connect(split
, &QAction::triggered
, this, &DolphinMainWindow::toggleSplitView
);
1842 QAction
*popoutSplit
= actionCollection()->addAction(QStringLiteral("popout_split_view"));
1843 popoutSplit
->setWhatsThis(xi18nc("@info:whatsthis",
1844 "If the folder view has been split, this will pop the active folder "
1845 "view out into a new window."));
1846 popoutSplit
->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
1847 actionCollection()->setDefaultShortcut(popoutSplit
, Qt::SHIFT
| Qt::Key_F3
);
1848 connect(popoutSplit
, &QAction::triggered
, this, &DolphinMainWindow::popoutSplitView
);
1850 QAction
*stashSplit
= actionCollection()->addAction(QStringLiteral("split_stash"));
1851 actionCollection()->setDefaultShortcut(stashSplit
, Qt::CTRL
| Qt::Key_S
);
1852 stashSplit
->setText(i18nc("@action:intoolbar Stash", "Stash"));
1853 stashSplit
->setToolTip(i18nc("@info", "Opens the stash virtual directory in a split window"));
1854 stashSplit
->setIcon(QIcon::fromTheme(QStringLiteral("folder-stash")));
1855 stashSplit
->setCheckable(false);
1856 QDBusConnectionInterface
*sessionInterface
= QDBusConnection::sessionBus().interface();
1857 stashSplit
->setVisible(sessionInterface
&& sessionInterface
->isServiceRegistered(QStringLiteral("org.kde.kio.StashNotifier")));
1858 connect(stashSplit
, &QAction::triggered
, this, &DolphinMainWindow::toggleSplitStash
);
1860 QAction
*redisplay
= KStandardAction::redisplay(this, &DolphinMainWindow::reloadView
, actionCollection());
1861 redisplay
->setToolTip(i18nc("@info:tooltip", "Refresh view"));
1862 redisplay
->setWhatsThis(xi18nc("@info:whatsthis refresh",
1863 "<para>This refreshes "
1864 "the folder view.</para>"
1865 "<para>If the contents of this folder have changed, refreshing will re-scan this folder "
1866 "and show you a newly-updated view of the files and folders contained here.</para>"
1867 "<para>If the view is split, this refreshes the one that is currently in focus.</para>"));
1869 QAction
*stop
= actionCollection()->addAction(QStringLiteral("stop"));
1870 stop
->setText(i18nc("@action:inmenu View", "Stop"));
1871 stop
->setToolTip(i18nc("@info", "Stop loading"));
1872 stop
->setWhatsThis(i18nc("@info", "This stops the loading of the contents of the current folder."));
1873 stop
->setIcon(QIcon::fromTheme(QStringLiteral("process-stop")));
1874 connect(stop
, &QAction::triggered
, this, &DolphinMainWindow::stopLoading
);
1876 KToggleAction
*editableLocation
= actionCollection()->add
<KToggleAction
>(QStringLiteral("editable_location"));
1877 editableLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1878 editableLocation
->setWhatsThis(xi18nc("@info:whatsthis",
1879 "This toggles the <emphasis>Location Bar</emphasis> to be "
1880 "editable so you can directly enter a location you want to go to.<nl/>"
1881 "You can also switch to editing by clicking to the right of the "
1882 "location and switch back by confirming the edited location."));
1883 actionCollection()->setDefaultShortcut(editableLocation
, Qt::Key_F6
);
1884 connect(editableLocation
, &KToggleAction::triggered
, this, &DolphinMainWindow::toggleEditLocation
);
1886 QAction
*replaceLocation
= actionCollection()->addAction(QStringLiteral("replace_location"));
1887 replaceLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1888 // i18n: "enter" is used both in the meaning of "writing" and "going to" a new location here.
1889 // Both meanings are useful but not necessary to understand the use of "Replace Location".
1890 // So you might want to be more verbose in your language to convey the meaning but it's up to you.
1891 replaceLocation
->setWhatsThis(xi18nc("@info:whatsthis",
1892 "This switches to editing the location and selects it "
1893 "so you can quickly enter a different location."));
1894 actionCollection()->setDefaultShortcuts(replaceLocation
, {Qt::CTRL
| Qt::Key_L
, Qt::ALT
| Qt::Key_D
});
1895 connect(replaceLocation
, &QAction::triggered
, this, &DolphinMainWindow::replaceLocation
);
1899 QScopedPointer
<QAction
> backAction(KStandardAction::back(nullptr, nullptr, nullptr));
1900 m_backAction
= new KToolBarPopupAction(backAction
->icon(), backAction
->text(), actionCollection());
1901 m_backAction
->setObjectName(backAction
->objectName());
1902 m_backAction
->setShortcuts(backAction
->shortcuts());
1904 m_backAction
->setPopupMode(KToolBarPopupAction::DelayedPopup
);
1905 connect(m_backAction
, &QAction::triggered
, this, &DolphinMainWindow::goBack
);
1906 connect(m_backAction
->popupMenu(), &QMenu::aboutToShow
, this, &DolphinMainWindow::slotAboutToShowBackPopupMenu
);
1907 connect(m_backAction
->popupMenu(), &QMenu::triggered
, this, &DolphinMainWindow::slotGoBack
);
1908 actionCollection()->addAction(m_backAction
->objectName(), m_backAction
);
1910 auto backShortcuts
= m_backAction
->shortcuts();
1911 // Prepend this shortcut, to avoid being hidden by the two-slot UI (#371130)
1912 backShortcuts
.prepend(QKeySequence(Qt::Key_Backspace
));
1913 actionCollection()->setDefaultShortcuts(m_backAction
, backShortcuts
);
1915 DolphinRecentTabsMenu
*recentTabsMenu
= new DolphinRecentTabsMenu(this);
1916 actionCollection()->addAction(QStringLiteral("closed_tabs"), recentTabsMenu
);
1917 connect(m_tabWidget
, &DolphinTabWidget::rememberClosedTab
, recentTabsMenu
, &DolphinRecentTabsMenu::rememberClosedTab
);
1918 connect(recentTabsMenu
, &DolphinRecentTabsMenu::restoreClosedTab
, m_tabWidget
, &DolphinTabWidget::restoreClosedTab
);
1919 connect(recentTabsMenu
, &DolphinRecentTabsMenu::closedTabsCountChanged
, this, &DolphinMainWindow::closedTabsCountChanged
);
1921 QAction
*undoCloseTab
= actionCollection()->addAction(QStringLiteral("undo_close_tab"));
1922 undoCloseTab
->setText(i18nc("@action:inmenu File", "Undo close tab"));
1923 undoCloseTab
->setWhatsThis(i18nc("@info:whatsthis undo close tab", "This returns you to the previously closed tab."));
1924 actionCollection()->setDefaultShortcut(undoCloseTab
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_T
);
1925 undoCloseTab
->setIcon(QIcon::fromTheme(QStringLiteral("edit-undo")));
1926 undoCloseTab
->setEnabled(false);
1927 connect(undoCloseTab
, &QAction::triggered
, recentTabsMenu
, &DolphinRecentTabsMenu::undoCloseTab
);
1929 auto undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
1930 undoAction
->setWhatsThis(xi18nc("@info:whatsthis",
1932 "the last change you made to files or folders.<nl/>"
1933 "Such changes include <interface>creating, renaming</interface> "
1934 "and <interface>moving</interface> them to a different location "
1935 "or to the <filename>Trash</filename>. <nl/>Changes that can't "
1936 "be undone will ask for your confirmation."));
1937 undoAction
->setEnabled(false); // undo should be disabled by default
1940 QScopedPointer
<QAction
> forwardAction(KStandardAction::forward(nullptr, nullptr, nullptr));
1941 m_forwardAction
= new KToolBarPopupAction(forwardAction
->icon(), forwardAction
->text(), actionCollection());
1942 m_forwardAction
->setObjectName(forwardAction
->objectName());
1943 m_forwardAction
->setShortcuts(forwardAction
->shortcuts());
1945 m_forwardAction
->setPopupMode(KToolBarPopupAction::DelayedPopup
);
1946 connect(m_forwardAction
, &QAction::triggered
, this, &DolphinMainWindow::goForward
);
1947 connect(m_forwardAction
->popupMenu(), &QMenu::aboutToShow
, this, &DolphinMainWindow::slotAboutToShowForwardPopupMenu
);
1948 connect(m_forwardAction
->popupMenu(), &QMenu::triggered
, this, &DolphinMainWindow::slotGoForward
);
1949 actionCollection()->addAction(m_forwardAction
->objectName(), m_forwardAction
);
1950 actionCollection()->setDefaultShortcuts(m_forwardAction
, m_forwardAction
->shortcuts());
1952 // enable middle-click to open in a new tab
1953 auto *middleClickEventFilter
= new MiddleClickActionEventFilter(this);
1954 connect(middleClickEventFilter
, &MiddleClickActionEventFilter::actionMiddleClicked
, this, &DolphinMainWindow::slotBackForwardActionMiddleClicked
);
1955 m_backAction
->popupMenu()->installEventFilter(middleClickEventFilter
);
1956 m_forwardAction
->popupMenu()->installEventFilter(middleClickEventFilter
);
1957 KStandardAction::up(this, &DolphinMainWindow::goUp
, actionCollection());
1958 QAction
*homeAction
= KStandardAction::home(this, &DolphinMainWindow::goHome
, actionCollection());
1959 homeAction
->setWhatsThis(xi18nc("@info:whatsthis",
1961 "<filename>Home</filename> folder.<nl/>Every user account "
1962 "has their own <filename>Home</filename> that contains their data "
1963 "including folders that contain personal application data."));
1965 // setup 'Tools' menu
1966 QAction
*compareFiles
= actionCollection()->addAction(QStringLiteral("compare_files"));
1967 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1968 compareFiles
->setIcon(QIcon::fromTheme(QStringLiteral("kompare")));
1969 compareFiles
->setEnabled(false);
1970 connect(compareFiles
, &QAction::triggered
, this, &DolphinMainWindow::compareFiles
);
1972 QAction
*openPreferredSearchTool
= actionCollection()->addAction(QStringLiteral("open_preferred_search_tool"));
1973 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool"));
1974 openPreferredSearchTool
->setWhatsThis(xi18nc("@info:whatsthis",
1975 "<para>This opens a preferred search tool for the viewed location.</para>"
1976 "<para>Use <emphasis>More Search Tools</emphasis> menu to configure it.</para>"));
1977 openPreferredSearchTool
->setIcon(QIcon::fromTheme(QStringLiteral("search")));
1978 actionCollection()->setDefaultShortcut(openPreferredSearchTool
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_F
);
1979 connect(openPreferredSearchTool
, &QAction::triggered
, this, &DolphinMainWindow::openPreferredSearchTool
);
1981 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
1982 QAction
*openTerminal
= actionCollection()->addAction(QStringLiteral("open_terminal"));
1983 openTerminal
->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
1984 openTerminal
->setWhatsThis(xi18nc("@info:whatsthis",
1985 "<para>This opens a <emphasis>terminal</emphasis> application for the viewed location.</para>"
1986 "<para>To learn more about terminals use the help in the terminal application.</para>"));
1987 openTerminal
->setIcon(QIcon::fromTheme(QStringLiteral("utilities-terminal")));
1988 actionCollection()->setDefaultShortcut(openTerminal
, Qt::SHIFT
| Qt::Key_F4
);
1989 connect(openTerminal
, &QAction::triggered
, this, &DolphinMainWindow::openTerminal
);
1991 QAction
*openTerminalHere
= actionCollection()->addAction(QStringLiteral("open_terminal_here"));
1992 // i18n: "Here" refers to the location(s) of the currently selected item(s) or the currently viewed location if nothing is selected.
1993 openTerminalHere
->setText(i18nc("@action:inmenu Tools", "Open Terminal Here"));
1994 openTerminalHere
->setWhatsThis(xi18nc("@info:whatsthis",
1995 "<para>This opens <emphasis>terminal</emphasis> applications for the selected items' locations.</para>"
1996 "<para>To learn more about terminals use the help in the terminal application.</para>"));
1997 openTerminalHere
->setIcon(QIcon::fromTheme(QStringLiteral("utilities-terminal")));
1998 actionCollection()->setDefaultShortcut(openTerminalHere
, Qt::SHIFT
| Qt::ALT
| Qt::Key_F4
);
1999 connect(openTerminalHere
, &QAction::triggered
, this, &DolphinMainWindow::openTerminalHere
);
2002 QAction
*focusTerminalPanel
= actionCollection()->addAction(QStringLiteral("focus_terminal_panel"));
2003 focusTerminalPanel
->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
2004 focusTerminalPanel
->setIcon(QIcon::fromTheme(QStringLiteral("swap-panels")));
2005 actionCollection()->setDefaultShortcut(focusTerminalPanel
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_F4
);
2006 connect(focusTerminalPanel
, &QAction::triggered
, this, &DolphinMainWindow::focusTerminalPanel
);
2010 // setup 'Bookmarks' menu
2011 KActionMenu
*bookmarkMenu
= new KActionMenu(i18nc("@title:menu", "&Bookmarks"), this);
2012 bookmarkMenu
->setIcon(QIcon::fromTheme(QStringLiteral("bookmarks")));
2013 // Make the toolbar button version work properly on click
2014 bookmarkMenu
->setPopupMode(QToolButton::InstantPopup
);
2015 m_bookmarkHandler
= new DolphinBookmarkHandler(this, actionCollection(), bookmarkMenu
->menu(), this);
2016 actionCollection()->addAction(QStringLiteral("bookmarks"), bookmarkMenu
);
2018 // setup 'Settings' menu
2019 KToggleAction
*showMenuBar
= KStandardAction::showMenubar(nullptr, nullptr, actionCollection());
2020 showMenuBar
->setWhatsThis(xi18nc("@info:whatsthis",
2021 "<para>This switches between having a <emphasis>Menubar</emphasis> "
2022 "and having a <interface>%1</interface> button. Both "
2023 "contain mostly the same actions and configuration options.</para>"
2024 "<para>The Menubar takes up more space but allows for fast and organised access to all "
2025 "actions an application has to offer.</para><para>The <interface>%1</interface> button "
2026 "is simpler and small which makes triggering advanced actions more time consuming.</para>",
2027 hamburgerMenuAction
->text().replace('&', "")));
2028 connect(showMenuBar
,
2029 &KToggleAction::triggered
, // Fixes #286822
2031 &DolphinMainWindow::toggleShowMenuBar
,
2032 Qt::QueuedConnection
);
2034 KToggleAction
*showStatusBar
= KStandardAction::showStatusbar(nullptr, nullptr, actionCollection());
2035 showStatusBar
->setChecked(GeneralSettings::showStatusBar());
2036 connect(GeneralSettings::self(), &GeneralSettings::showStatusBarChanged
, showStatusBar
, &KToggleAction::setChecked
);
2037 connect(showStatusBar
, &KToggleAction::triggered
, this, [this](bool checked
) {
2038 GeneralSettings::setShowStatusBar(checked
);
2042 KStandardAction::keyBindings(this, &DolphinMainWindow::slotKeyBindings
, actionCollection());
2043 KStandardAction::preferences(this, &DolphinMainWindow::editSettings
, actionCollection());
2045 // not in menu actions
2046 QList
<QKeySequence
> nextTabKeys
= KStandardShortcut::tabNext();
2047 nextTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::Key_Tab
));
2049 QList
<QKeySequence
> prevTabKeys
= KStandardShortcut::tabPrev();
2050 prevTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::SHIFT
| Qt::Key_Tab
));
2052 for (int i
= 0; i
< MaxActivateTabShortcuts
; ++i
) {
2053 QAction
*activateTab
= actionCollection()->addAction(QStringLiteral("activate_tab_%1").arg(i
));
2054 activateTab
->setText(i18nc("@action:inmenu", "Activate Tab %1", i
+ 1));
2055 activateTab
->setEnabled(false);
2056 connect(activateTab
, &QAction::triggered
, this, [this, i
]() {
2057 m_tabWidget
->activateTab(i
);
2060 // only add default shortcuts for the first 9 tabs regardless of MaxActivateTabShortcuts
2062 actionCollection()->setDefaultShortcut(activateTab
, QStringLiteral("Alt+%1").arg(i
+ 1));
2066 QAction
*activateLastTab
= actionCollection()->addAction(QStringLiteral("activate_last_tab"));
2067 activateLastTab
->setText(i18nc("@action:inmenu", "Activate Last Tab"));
2068 activateLastTab
->setEnabled(false);
2069 connect(activateLastTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activateLastTab
);
2070 actionCollection()->setDefaultShortcut(activateLastTab
, Qt::ALT
| Qt::Key_0
);
2072 QAction
*activateNextTab
= actionCollection()->addAction(QStringLiteral("activate_next_tab"));
2073 activateNextTab
->setIconText(i18nc("@action:inmenu", "Next Tab"));
2074 activateNextTab
->setText(i18nc("@action:inmenu", "Activate Next Tab"));
2075 activateNextTab
->setEnabled(false);
2076 connect(activateNextTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activateNextTab
);
2077 actionCollection()->setDefaultShortcuts(activateNextTab
, nextTabKeys
);
2079 QAction
*activatePrevTab
= actionCollection()->addAction(QStringLiteral("activate_prev_tab"));
2080 activatePrevTab
->setIconText(i18nc("@action:inmenu", "Previous Tab"));
2081 activatePrevTab
->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
2082 activatePrevTab
->setEnabled(false);
2083 connect(activatePrevTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activatePrevTab
);
2084 actionCollection()->setDefaultShortcuts(activatePrevTab
, prevTabKeys
);
2087 QAction
*showTarget
= actionCollection()->addAction(QStringLiteral("show_target"));
2088 showTarget
->setText(i18nc("@action:inmenu", "Show Target"));
2089 showTarget
->setIcon(QIcon::fromTheme(QStringLiteral("document-open-folder")));
2090 showTarget
->setEnabled(false);
2091 connect(showTarget
, &QAction::triggered
, this, &DolphinMainWindow::showTarget
);
2093 QAction
*openInNewTab
= actionCollection()->addAction(QStringLiteral("open_in_new_tab"));
2094 openInNewTab
->setText(i18nc("@action:inmenu", "Open in New Tab"));
2095 openInNewTab
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
2096 connect(openInNewTab
, &QAction::triggered
, this, &DolphinMainWindow::openInNewTab
);
2098 QAction
*openInNewTabs
= actionCollection()->addAction(QStringLiteral("open_in_new_tabs"));
2099 openInNewTabs
->setText(i18nc("@action:inmenu", "Open in New Tabs"));
2100 openInNewTabs
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
2101 connect(openInNewTabs
, &QAction::triggered
, this, &DolphinMainWindow::openInNewTab
);
2103 QAction
*openInNewWindow
= actionCollection()->addAction(QStringLiteral("open_in_new_window"));
2104 openInNewWindow
->setText(i18nc("@action:inmenu", "Open in New Window"));
2105 openInNewWindow
->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
2106 connect(openInNewWindow
, &QAction::triggered
, this, &DolphinMainWindow::openInNewWindow
);
2108 QAction
*openInSplitViewAction
= actionCollection()->addAction(QStringLiteral("open_in_split_view"));
2109 openInSplitViewAction
->setText(i18nc("@action:inmenu", "Open in Split View"));
2110 openInSplitViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-right-new")));
2111 connect(openInSplitViewAction
, &QAction::triggered
, this, [this]() {
2112 openInSplitView(QUrl());
2116 void DolphinMainWindow::setupDockWidgets()
2118 const bool lock
= GeneralSettings::lockPanels();
2120 DolphinPlacesModelSingleton::instance().placesModel()->setPanelsLocked(lock
);
2122 KDualAction
*lockLayoutAction
= actionCollection()->add
<KDualAction
>(QStringLiteral("lock_panels"));
2123 lockLayoutAction
->setActiveText(i18nc("@action:inmenu Panels", "Unlock Panels"));
2124 lockLayoutAction
->setActiveIcon(QIcon::fromTheme(QStringLiteral("object-unlocked")));
2125 lockLayoutAction
->setInactiveText(i18nc("@action:inmenu Panels", "Lock Panels"));
2126 lockLayoutAction
->setInactiveIcon(QIcon::fromTheme(QStringLiteral("object-locked")));
2127 lockLayoutAction
->setWhatsThis(xi18nc("@info:whatsthis",
2129 "switches between having panels <emphasis>locked</emphasis> or "
2130 "<emphasis>unlocked</emphasis>.<nl/>Unlocked panels can be "
2131 "dragged to the other side of the window and have a close "
2132 "button.<nl/>Locked panels are embedded more cleanly."));
2133 lockLayoutAction
->setActive(lock
);
2134 connect(lockLayoutAction
, &KDualAction::triggered
, this, &DolphinMainWindow::togglePanelLockState
);
2136 // Setup "Information"
2137 DolphinDockWidget
*infoDock
= new DolphinDockWidget(i18nc("@title:window", "Information"));
2138 infoDock
->setLocked(lock
);
2139 infoDock
->setObjectName(QStringLiteral("infoDock"));
2140 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
2143 InformationPanel
*infoPanel
= new InformationPanel(infoDock
);
2144 infoPanel
->setCustomContextMenuActions({lockLayoutAction
});
2145 connect(infoPanel
, &InformationPanel::urlActivated
, this, &DolphinMainWindow::handleUrl
);
2146 infoDock
->setWidget(infoPanel
);
2148 createPanelAction(QIcon::fromTheme(QStringLiteral("dialog-information")), Qt::Key_F11
, infoDock
, QStringLiteral("show_information_panel"));
2150 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
2151 connect(this, &DolphinMainWindow::urlChanged
, infoPanel
, &InformationPanel::setUrl
);
2152 connect(this, &DolphinMainWindow::selectionChanged
, infoPanel
, &InformationPanel::setSelection
);
2153 connect(this, &DolphinMainWindow::requestItemInfo
, infoPanel
, &InformationPanel::requestDelayedItemInfo
);
2154 connect(this, &DolphinMainWindow::fileItemsChanged
, infoPanel
, &InformationPanel::slotFilesItemChanged
);
2157 // i18n: This is the last paragraph for the "What's This"-texts of all four panels.
2158 const QString panelWhatsThis
= xi18nc("@info:whatsthis",
2160 "hide panels like this go to <interface>Menu|Panels</interface> "
2161 "or <interface>View|Panels</interface>.</para>");
2164 ->action(QStringLiteral("show_information_panel"))
2165 ->setWhatsThis(xi18nc("@info:whatsthis",
2166 "<para> This toggles the "
2167 "<emphasis>information</emphasis> panel at the right side of the "
2168 "window.</para><para>The panel provides in-depth information "
2169 "about the items your mouse is hovering over or about the selected "
2170 "items. Otherwise it informs you about the currently viewed folder.<nl/>"
2171 "For single items a preview of their contents is provided.</para>"));
2173 infoDock
->setWhatsThis(xi18nc("@info:whatsthis",
2175 "provides in-depth information about the items your mouse is "
2176 "hovering over or about the selected items. Otherwise it informs "
2177 "you about the currently viewed folder.<nl/>For single items a "
2178 "preview of their contents is provided.</para><para>You can configure "
2179 "which and how details are given here by right-clicking.</para>")
2183 DolphinDockWidget
*foldersDock
= new DolphinDockWidget(i18nc("@title:window", "Folders"));
2184 foldersDock
->setLocked(lock
);
2185 foldersDock
->setObjectName(QStringLiteral("foldersDock"));
2186 foldersDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
2187 FoldersPanel
*foldersPanel
= new FoldersPanel(foldersDock
);
2188 foldersPanel
->setCustomContextMenuActions({lockLayoutAction
});
2189 foldersDock
->setWidget(foldersPanel
);
2191 createPanelAction(QIcon::fromTheme(QStringLiteral("folder")), Qt::Key_F7
, foldersDock
, QStringLiteral("show_folders_panel"));
2193 addDockWidget(Qt::LeftDockWidgetArea
, foldersDock
);
2194 connect(this, &DolphinMainWindow::urlChanged
, foldersPanel
, &FoldersPanel::setUrl
);
2195 connect(foldersPanel
, &FoldersPanel::folderActivated
, this, &DolphinMainWindow::changeUrl
);
2196 connect(foldersPanel
, &FoldersPanel::folderInNewTab
, this, &DolphinMainWindow::openNewTab
);
2197 connect(foldersPanel
, &FoldersPanel::folderInNewActiveTab
, this, &DolphinMainWindow::openNewTabAndActivate
);
2198 connect(foldersPanel
, &FoldersPanel::errorMessage
, this, &DolphinMainWindow::showErrorMessage
);
2201 ->action(QStringLiteral("show_folders_panel"))
2202 ->setWhatsThis(xi18nc("@info:whatsthis",
2204 "<emphasis>folders</emphasis> panel at the left side of the window."
2205 "<nl/><nl/>It shows the folders of the <emphasis>file system"
2206 "</emphasis> in a <emphasis>tree view</emphasis>."));
2207 foldersDock
->setWhatsThis(xi18nc("@info:whatsthis",
2209 "shows the folders of the <emphasis>file system</emphasis> in a "
2210 "<emphasis>tree view</emphasis>.</para><para>Click a folder to go "
2211 "there. Click the arrow to the left of a folder to see its subfolders. "
2212 "This allows quick switching between any folders.</para>")
2217 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
2218 DolphinDockWidget
*terminalDock
= new DolphinDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
2219 terminalDock
->setLocked(lock
);
2220 terminalDock
->setObjectName(QStringLiteral("terminalDock"));
2221 terminalDock
->setContentsMargins(0, 0, 0, 0);
2222 m_terminalPanel
= new TerminalPanel(terminalDock
);
2223 m_terminalPanel
->setCustomContextMenuActions({lockLayoutAction
});
2224 terminalDock
->setWidget(m_terminalPanel
);
2226 connect(m_terminalPanel
, &TerminalPanel::hideTerminalPanel
, terminalDock
, &DolphinDockWidget::hide
);
2227 connect(m_terminalPanel
, &TerminalPanel::changeUrl
, this, &DolphinMainWindow::slotTerminalDirectoryChanged
);
2228 connect(terminalDock
, &DolphinDockWidget::visibilityChanged
, m_terminalPanel
, &TerminalPanel::dockVisibilityChanged
);
2229 connect(terminalDock
, &DolphinDockWidget::visibilityChanged
, this, &DolphinMainWindow::slotTerminalPanelVisibilityChanged
);
2231 createPanelAction(QIcon::fromTheme(QStringLiteral("dialog-scripts")), Qt::Key_F4
, terminalDock
, QStringLiteral("show_terminal_panel"));
2233 addDockWidget(Qt::BottomDockWidgetArea
, terminalDock
);
2234 connect(this, &DolphinMainWindow::urlChanged
, m_terminalPanel
, &TerminalPanel::setUrl
);
2236 if (GeneralSettings::version() < 200) {
2237 terminalDock
->hide();
2241 ->action(QStringLiteral("show_terminal_panel"))
2242 ->setWhatsThis(xi18nc("@info:whatsthis",
2243 "<para>This toggles the "
2244 "<emphasis>terminal</emphasis> panel at the bottom of the window."
2245 "<nl/>The location in the terminal will always match the folder "
2246 "view so you can navigate using either.</para><para>The terminal "
2247 "panel is not needed for basic computer usage but can be useful "
2248 "for advanced tasks. To learn more about terminals use the help "
2249 "in a standalone terminal application like Konsole.</para>"));
2250 terminalDock
->setWhatsThis(xi18nc("@info:whatsthis",
2252 "the <emphasis>terminal</emphasis> panel. It behaves like a "
2253 "normal terminal but will match the location of the folder view "
2254 "so you can navigate using either.</para><para>The terminal panel "
2255 "is not needed for basic computer usage but can be useful for "
2256 "advanced tasks. To learn more about terminals use the help in a "
2257 "standalone terminal application like Konsole.</para>")
2262 if (GeneralSettings::version() < 200) {
2264 foldersDock
->hide();
2268 DolphinDockWidget
*placesDock
= new DolphinDockWidget(i18nc("@title:window", "Places"));
2269 placesDock
->setLocked(lock
);
2270 placesDock
->setObjectName(QStringLiteral("placesDock"));
2271 placesDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
2273 m_placesPanel
= new PlacesPanel(placesDock
);
2274 m_placesPanel
->setCustomContextMenuActions({lockLayoutAction
});
2275 placesDock
->setWidget(m_placesPanel
);
2277 createPanelAction(QIcon::fromTheme(QStringLiteral("compass")), Qt::Key_F9
, placesDock
, QStringLiteral("show_places_panel"));
2279 addDockWidget(Qt::LeftDockWidgetArea
, placesDock
);
2280 connect(m_placesPanel
, &PlacesPanel::placeActivated
, this, &DolphinMainWindow::slotPlaceActivated
);
2281 connect(m_placesPanel
, &PlacesPanel::tabRequested
, this, &DolphinMainWindow::openNewTab
);
2282 connect(m_placesPanel
, &PlacesPanel::activeTabRequested
, this, &DolphinMainWindow::openNewTabAndActivate
);
2283 connect(m_placesPanel
, &PlacesPanel::newWindowRequested
, this, [this](const QUrl
&url
) {
2284 Dolphin::openNewWindow({url
}, this);
2286 connect(m_placesPanel
, &PlacesPanel::openInSplitViewRequested
, this, &DolphinMainWindow::openInSplitView
);
2287 connect(m_placesPanel
, &PlacesPanel::errorMessage
, this, &DolphinMainWindow::showErrorMessage
);
2288 connect(this, &DolphinMainWindow::urlChanged
, m_placesPanel
, &PlacesPanel::setUrl
);
2289 connect(placesDock
, &DolphinDockWidget::visibilityChanged
, &DolphinUrlNavigatorsController::slotPlacesPanelVisibilityChanged
);
2290 connect(this, &DolphinMainWindow::settingsChanged
, m_placesPanel
, &PlacesPanel::readSettings
);
2291 connect(m_placesPanel
, &PlacesPanel::storageTearDownRequested
, this, &DolphinMainWindow::slotStorageTearDownFromPlacesRequested
);
2292 connect(m_placesPanel
, &PlacesPanel::storageTearDownExternallyRequested
, this, &DolphinMainWindow::slotStorageTearDownExternallyRequested
);
2293 DolphinUrlNavigatorsController::slotPlacesPanelVisibilityChanged(m_placesPanel
->isVisible());
2295 auto actionShowAllPlaces
= new QAction(QIcon::fromTheme(QStringLiteral("view-hidden")), i18nc("@item:inmenu", "Show Hidden Places"), this);
2296 actionShowAllPlaces
->setCheckable(true);
2297 actionShowAllPlaces
->setDisabled(true);
2298 actionShowAllPlaces
->setWhatsThis(i18nc("@info:whatsthis",
2300 "all places in the places panel that have been hidden. They will "
2301 "appear semi-transparent unless you uncheck their hide property."));
2303 connect(actionShowAllPlaces
, &QAction::triggered
, this, [this](bool checked
) {
2304 m_placesPanel
->setShowAll(checked
);
2306 connect(m_placesPanel
, &PlacesPanel::allPlacesShownChanged
, actionShowAllPlaces
, &QAction::setChecked
);
2309 ->action(QStringLiteral("show_places_panel"))
2310 ->setWhatsThis(xi18nc("@info:whatsthis",
2311 "<para>This toggles the "
2312 "<emphasis>places</emphasis> panel at the left side of the window."
2313 "</para><para>It allows you to go to locations you have "
2314 "bookmarked and to access disk or media attached to the computer "
2315 "or to the network. It also contains sections to find recently "
2316 "saved files or files of a certain type.</para>"));
2317 placesDock
->setWhatsThis(xi18nc("@info:whatsthis",
2318 "<para>This is the "
2319 "<emphasis>Places</emphasis> panel. It allows you to go to locations "
2320 "you have bookmarked and to access disk or media attached to the "
2321 "computer or to the network. It also contains sections to find "
2322 "recently saved files or files of a certain type.</para><para>"
2323 "Click on an entry to go there. Click with the right mouse button "
2324 "instead to open any entry in a new tab or new window.</para>"
2325 "<para>New entries can be added by dragging folders onto this panel. "
2326 "Right-click any section or entry to hide it. Right-click an empty "
2327 "space on this panel and select <interface>Show Hidden Places"
2328 "</interface> to display it again.</para>")
2331 // Add actions into the "Panels" menu
2332 KActionMenu
*panelsMenu
= new KActionMenu(i18nc("@action:inmenu View", "Show Panels"), this);
2333 actionCollection()->addAction(QStringLiteral("panels"), panelsMenu
);
2334 panelsMenu
->setIcon(QIcon::fromTheme(QStringLiteral("view-sidetree")));
2335 panelsMenu
->setPopupMode(QToolButton::InstantPopup
);
2336 const KActionCollection
*ac
= actionCollection();
2337 panelsMenu
->addAction(ac
->action(QStringLiteral("show_places_panel")));
2339 panelsMenu
->addAction(ac
->action(QStringLiteral("show_information_panel")));
2341 panelsMenu
->addAction(ac
->action(QStringLiteral("show_folders_panel")));
2342 panelsMenu
->addAction(ac
->action(QStringLiteral("show_terminal_panel")));
2343 panelsMenu
->addSeparator();
2344 panelsMenu
->addAction(actionShowAllPlaces
);
2345 panelsMenu
->addAction(lockLayoutAction
);
2347 connect(panelsMenu
->menu(), &QMenu::aboutToShow
, this, [actionShowAllPlaces
] {
2348 actionShowAllPlaces
->setEnabled(DolphinPlacesModelSingleton::instance().placesModel()->hiddenCount());
2352 void DolphinMainWindow::updateFileAndEditActions()
2354 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
2355 const KActionCollection
*col
= actionCollection();
2356 KFileItemListProperties
capabilitiesSource(list
);
2358 QAction
*renameAction
= col
->action(KStandardAction::name(KStandardAction::RenameFile
));
2359 QAction
*moveToTrashAction
= col
->action(KStandardAction::name(KStandardAction::MoveToTrash
));
2360 QAction
*deleteAction
= col
->action(KStandardAction::name(KStandardAction::DeleteFile
));
2361 QAction
*cutAction
= col
->action(KStandardAction::name(KStandardAction::Cut
));
2362 QAction
*duplicateAction
= col
->action(QStringLiteral("duplicate")); // see DolphinViewActionHandler
2363 QAction
*addToPlacesAction
= col
->action(QStringLiteral("add_to_places"));
2364 QAction
*copyToOtherViewAction
= col
->action(QStringLiteral("copy_to_inactive_split_view"));
2365 QAction
*moveToOtherViewAction
= col
->action(QStringLiteral("move_to_inactive_split_view"));
2366 QAction
*copyLocation
= col
->action(QString("copy_location"));
2368 if (list
.isEmpty()) {
2369 stateChanged(QStringLiteral("has_no_selection"));
2371 // All actions that need a selection to function can be enabled because they should trigger selection mode.
2372 renameAction
->setEnabled(true);
2373 moveToTrashAction
->setEnabled(true);
2374 deleteAction
->setEnabled(true);
2375 cutAction
->setEnabled(true);
2376 duplicateAction
->setEnabled(true);
2377 addToPlacesAction
->setEnabled(true);
2378 copyLocation
->setEnabled(true);
2379 // Them triggering selection mode and not directly acting on selected items is signified by adding "…" to their text.
2380 m_actionTextHelper
->textsWhenNothingIsSelectedEnabled(true);
2383 m_actionTextHelper
->textsWhenNothingIsSelectedEnabled(false);
2384 stateChanged(QStringLiteral("has_selection"));
2386 QAction
*deleteWithTrashShortcut
= col
->action(QStringLiteral("delete_shortcut")); // see DolphinViewActionHandler
2387 QAction
*showTarget
= col
->action(QStringLiteral("show_target"));
2389 if (list
.length() == 1 && list
.first().isDir()) {
2390 addToPlacesAction
->setEnabled(true);
2392 addToPlacesAction
->setEnabled(false);
2395 const bool enableMoveToTrash
= capabilitiesSource
.isLocal() && capabilitiesSource
.supportsMoving();
2397 renameAction
->setEnabled(capabilitiesSource
.supportsMoving());
2398 moveToTrashAction
->setEnabled(enableMoveToTrash
);
2399 deleteAction
->setEnabled(capabilitiesSource
.supportsDeleting());
2400 deleteWithTrashShortcut
->setEnabled(capabilitiesSource
.supportsDeleting() && !enableMoveToTrash
);
2401 cutAction
->setEnabled(capabilitiesSource
.supportsMoving());
2402 copyLocation
->setEnabled(list
.length() == 1);
2403 showTarget
->setEnabled(list
.length() == 1 && list
.at(0).isLink());
2404 duplicateAction
->setEnabled(capabilitiesSource
.supportsWriting());
2407 if (m_tabWidget
->currentTabPage()->splitViewEnabled() && !list
.isEmpty()) {
2408 DolphinTabPage
*tabPage
= m_tabWidget
->currentTabPage();
2409 KFileItem capabilitiesDestination
;
2411 if (tabPage
->primaryViewActive()) {
2412 capabilitiesDestination
= tabPage
->secondaryViewContainer()->rootItem();
2414 capabilitiesDestination
= tabPage
->primaryViewContainer()->rootItem();
2417 const auto destUrl
= capabilitiesDestination
.url();
2418 const bool allNotTargetOrigin
= std::all_of(list
.cbegin(), list
.cend(), [destUrl
](const KFileItem
&item
) {
2419 return item
.url().adjusted(QUrl::RemoveFilename
| QUrl::StripTrailingSlash
) != destUrl
;
2422 copyToOtherViewAction
->setEnabled(capabilitiesDestination
.isWritable() && allNotTargetOrigin
);
2423 moveToOtherViewAction
->setEnabled((list
.isEmpty() || capabilitiesSource
.supportsMoving()) && capabilitiesDestination
.isWritable()
2424 && allNotTargetOrigin
);
2426 copyToOtherViewAction
->setEnabled(false);
2427 moveToOtherViewAction
->setEnabled(false);
2431 void DolphinMainWindow::updateViewActions()
2433 m_actionHandler
->updateViewActions();
2435 QAction
*toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
2436 toggleFilterBarAction
->setChecked(m_activeViewContainer
->isFilterBarVisible());
2438 updateSplitActions();
2441 void DolphinMainWindow::updateGoActions()
2443 QAction
*goUpAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Up
));
2444 const QUrl currentUrl
= m_activeViewContainer
->url();
2445 // I think this is one of the best places to firstly be confronted
2446 // with a file system and its hierarchy. Talking about the root
2447 // directory might seem too much here but it is the question that
2448 // naturally arises in this context.
2449 goUpAction
->setWhatsThis(xi18nc("@info:whatsthis",
2451 "the folder that contains the currently viewed one.</para>"
2452 "<para>All files and folders are organized in a hierarchical "
2453 "<emphasis>file system</emphasis>. At the top of this hierarchy is "
2454 "a directory that contains all data connected to this computer"
2455 "—the <emphasis>root directory</emphasis>.</para>"));
2456 goUpAction
->setEnabled(KIO::upUrl(currentUrl
) != currentUrl
);
2459 void DolphinMainWindow::refreshViews()
2461 m_tabWidget
->refreshViews();
2463 if (GeneralSettings::modifiedStartupSettings()) {
2464 updateWindowTitle();
2467 updateSplitActions();
2469 Q_EMIT
settingsChanged();
2472 void DolphinMainWindow::clearStatusBar()
2474 m_activeViewContainer
->statusBar()->resetToDefaultText();
2477 void DolphinMainWindow::connectViewSignals(DolphinViewContainer
*container
)
2479 connect(container
, &DolphinViewContainer::showFilterBarChanged
, this, &DolphinMainWindow::updateFilterBarAction
);
2480 connect(container
, &DolphinViewContainer::writeStateChanged
, this, &DolphinMainWindow::slotWriteStateChanged
);
2481 slotWriteStateChanged(container
->view()->isFolderWritable());
2482 connect(container
, &DolphinViewContainer::searchModeEnabledChanged
, this, &DolphinMainWindow::updateSearchAction
);
2483 connect(container
, &DolphinViewContainer::captionChanged
, this, &DolphinMainWindow::updateWindowTitle
);
2484 connect(container
, &DolphinViewContainer::tabRequested
, this, &DolphinMainWindow::openNewTab
);
2485 connect(container
, &DolphinViewContainer::activeTabRequested
, this, &DolphinMainWindow::openNewTabAndActivate
);
2487 const QAction
*toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
2488 connect(toggleSearchAction
, &QAction::triggered
, container
, &DolphinViewContainer::setSearchModeEnabled
);
2490 // Make the toggled state of the selection mode actions visually follow the selection mode state of the view.
2491 auto toggleSelectionModeAction
= actionCollection()->action(QStringLiteral("toggle_selection_mode"));
2492 toggleSelectionModeAction
->setChecked(m_activeViewContainer
->isSelectionModeEnabled());
2493 connect(m_activeViewContainer
, &DolphinViewContainer::selectionModeChanged
, toggleSelectionModeAction
, &QAction::setChecked
);
2495 const DolphinView
*view
= container
->view();
2496 connect(view
, &DolphinView::selectionChanged
, this, &DolphinMainWindow::slotSelectionChanged
);
2497 connect(view
, &DolphinView::requestItemInfo
, this, &DolphinMainWindow::requestItemInfo
);
2498 connect(view
, &DolphinView::fileItemsChanged
, this, &DolphinMainWindow::fileItemsChanged
);
2499 connect(view
, &DolphinView::tabRequested
, this, &DolphinMainWindow::openNewTab
);
2500 connect(view
, &DolphinView::activeTabRequested
, this, &DolphinMainWindow::openNewTabAndActivate
);
2501 connect(view
, &DolphinView::windowRequested
, this, &DolphinMainWindow::openNewWindow
);
2502 connect(view
, &DolphinView::requestContextMenu
, this, &DolphinMainWindow::openContextMenu
);
2503 connect(view
, &DolphinView::directoryLoadingStarted
, this, &DolphinMainWindow::enableStopAction
);
2504 connect(view
, &DolphinView::directoryLoadingCompleted
, this, &DolphinMainWindow::disableStopAction
);
2505 connect(view
, &DolphinView::directoryLoadingCompleted
, this, &DolphinMainWindow::slotDirectoryLoadingCompleted
);
2506 connect(view
, &DolphinView::goBackRequested
, this, &DolphinMainWindow::goBack
);
2507 connect(view
, &DolphinView::goForwardRequested
, this, &DolphinMainWindow::goForward
);
2508 connect(view
, &DolphinView::urlActivated
, this, &DolphinMainWindow::handleUrl
);
2509 connect(view
, &DolphinView::goUpRequested
, this, &DolphinMainWindow::goUp
);
2511 connect(container
->urlNavigatorInternalWithHistory(), &KUrlNavigator::urlChanged
, this, &DolphinMainWindow::changeUrl
);
2512 connect(container
->urlNavigatorInternalWithHistory(), &KUrlNavigator::historyChanged
, this, &DolphinMainWindow::updateHistory
);
2514 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>(actionCollection()->action(QStringLiteral("url_navigators")));
2515 const KUrlNavigator
*navigator
=
2516 m_tabWidget
->currentTabPage()->primaryViewActive() ? navigators
->primaryUrlNavigator() : navigators
->secondaryUrlNavigator();
2518 QAction
*editableLocactionAction
= actionCollection()->action(QStringLiteral("editable_location"));
2519 editableLocactionAction
->setChecked(navigator
->isUrlEditable());
2520 connect(navigator
, &KUrlNavigator::editableStateChanged
, this, &DolphinMainWindow::slotEditableStateChanged
);
2521 connect(navigator
, &KUrlNavigator::tabRequested
, this, &DolphinMainWindow::openNewTab
);
2522 connect(navigator
, &KUrlNavigator::activeTabRequested
, this, &DolphinMainWindow::openNewTabAndActivate
);
2523 connect(navigator
, &KUrlNavigator::newWindowRequested
, this, &DolphinMainWindow::openNewWindow
);
2526 void DolphinMainWindow::updateSplitActions()
2528 QAction
*splitAction
= actionCollection()->action(QStringLiteral("split_view"));
2529 QAction
*popoutSplitAction
= actionCollection()->action(QStringLiteral("popout_split_view"));
2530 const DolphinTabPage
*tabPage
= m_tabWidget
->currentTabPage();
2531 if (tabPage
->splitViewEnabled()) {
2532 if (GeneralSettings::closeActiveSplitView() ? tabPage
->primaryViewActive() : !tabPage
->primaryViewActive()) {
2533 splitAction
->setText(i18nc("@action:intoolbar Close left view", "Close"));
2534 splitAction
->setToolTip(i18nc("@info", "Close left view"));
2535 splitAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-left-close")));
2536 popoutSplitAction
->setText(i18nc("@action:intoolbar Move left split view to a new window", "Pop out"));
2537 popoutSplitAction
->setToolTip(i18nc("@info", "Move left split view to a new window"));
2539 splitAction
->setText(i18nc("@action:intoolbar Close right view", "Close"));
2540 splitAction
->setToolTip(i18nc("@info", "Close right view"));
2541 splitAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-right-close")));
2542 popoutSplitAction
->setText(i18nc("@action:intoolbar Move right split view to a new window", "Pop out"));
2543 popoutSplitAction
->setToolTip(i18nc("@info", "Move right split view to a new window"));
2545 popoutSplitAction
->setVisible(true);
2547 splitAction
->setText(i18nc("@action:intoolbar Split view", "Split"));
2548 splitAction
->setToolTip(i18nc("@info", "Split view"));
2549 splitAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-right-new")));
2550 popoutSplitAction
->setVisible(false);
2554 void DolphinMainWindow::updateAllowedToolbarAreas()
2556 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>(actionCollection()->action(QStringLiteral("url_navigators")));
2557 if (toolBar()->actions().contains(navigators
)) {
2558 toolBar()->setAllowedAreas(Qt::TopToolBarArea
| Qt::BottomToolBarArea
);
2559 if (toolBarArea(toolBar()) == Qt::LeftToolBarArea
|| toolBarArea(toolBar()) == Qt::RightToolBarArea
) {
2560 addToolBar(Qt::TopToolBarArea
, toolBar());
2563 toolBar()->setAllowedAreas(Qt::AllToolBarAreas
);
2567 bool DolphinMainWindow::isKompareInstalled() const
2569 static bool initialized
= false;
2570 static bool installed
= false;
2572 // TODO: maybe replace this approach later by using a menu
2573 // plugin like kdiff3plugin.cpp
2574 installed
= !QStandardPaths::findExecutable(QStringLiteral("kompare")).isEmpty();
2580 void DolphinMainWindow::createPanelAction(const QIcon
&icon
, const QKeySequence
&shortcut
, QDockWidget
*dockWidget
, const QString
&actionName
)
2582 auto dockAction
= dockWidget
->toggleViewAction();
2583 dockAction
->setIcon(icon
);
2584 dockAction
->setEnabled(true);
2586 QAction
*panelAction
= actionCollection()->addAction(actionName
, dockAction
);
2587 actionCollection()->setDefaultShortcut(panelAction
, shortcut
);
2589 connect(panelAction
, &QAction::toggled
, dockWidget
, &QWidget::setVisible
);
2592 void DolphinMainWindow::setupWhatsThis()
2595 menuBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2596 "<emphasis>Menubar</emphasis>. It provides access to commands and "
2597 "configuration options. Left-click on any of the menus on this "
2598 "bar to see its contents.</para><para>The Menubar can be hidden "
2599 "by unchecking <interface>Settings|Show Menubar</interface>. Then "
2600 "most of its contents become available through a <interface>Menu"
2601 "</interface> button on the <emphasis>Toolbar</emphasis>.</para>"));
2602 toolBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2603 "<emphasis>Toolbar</emphasis>. It allows quick access to "
2604 "frequently used actions.</para><para>It is highly customizable. "
2605 "All items you see in the <interface>Menu</interface> or "
2606 "in the <interface>Menubar</interface> can be placed on the "
2607 "Toolbar. Just right-click on it and select <interface>Configure "
2608 "Toolbars…</interface> or find this action within the <interface>"
2610 "</para><para>The location of the bar and the style of its "
2611 "buttons can also be changed in the right-click menu. Right-click "
2612 "a button if you want to show or hide its text.</para>"));
2613 m_tabWidget
->setWhatsThis(xi18nc("@info:whatsthis main view",
2614 "<para>Here you can see the <emphasis>folders</emphasis> and "
2615 "<emphasis>files</emphasis> that are at the location described in "
2616 "the <interface>Location Bar</interface> above. This area is the "
2617 "central part of this application where you navigate to the files "
2618 "you want to use.</para><para>For an elaborate and general "
2619 "introduction to this application <link "
2620 "url='https://userbase.kde.org/Dolphin/File_Management#Introduction_to_Dolphin'>"
2621 "click here</link>. This will open an introductory article from "
2622 "the <emphasis>KDE UserBase Wiki</emphasis>.</para><para>For brief "
2623 "explanations of all the features of this <emphasis>view</emphasis> "
2624 "<link url='help:/dolphin/dolphin-view.html'>click here</link> "
2625 "instead. This will open a page from the <emphasis>Handbook"
2626 "</emphasis> that covers the basics.</para>"));
2629 actionCollection()->action(KStandardAction::name(KStandardAction::KeyBindings
))
2630 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window "
2631 "that lists the <emphasis>keyboard shortcuts</emphasis>.<nl/>"
2632 "There you can set up key combinations to trigger an action when "
2633 "they are pressed simultaneously. All commands in this application can "
2634 "be triggered this way.</para>"));
2635 actionCollection()->action(KStandardAction::name(KStandardAction::ConfigureToolbars
))
2636 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window in which "
2637 "you can change which buttons appear on the <emphasis>Toolbar</emphasis>.</para>"
2638 "<para>All items you see in the <interface>Menu</interface> can also be placed on the Toolbar.</para>"));
2639 actionCollection()->action(KStandardAction::name(KStandardAction::Preferences
))
2640 ->setWhatsThis(xi18nc("@info:whatsthis","This opens a window where you can "
2641 "change a multitude of settings for this application. For an explanation "
2642 "of the various settings go to the chapter <emphasis>Configuring Dolphin"
2643 "</emphasis> in <interface>Help|Dolphin Handbook</interface>."));
2647 auto setStandardActionWhatsThis
= [this](KStandardAction::StandardAction actionId
,
2648 const QString
&whatsThis
) {
2649 // Check for the existence of an action since it can be restricted through the Kiosk system
2650 if (auto *action
= actionCollection()->action(KStandardAction::name(actionId
))) {
2651 action
->setWhatsThis(whatsThis
);
2655 // i18n: If the external link isn't available in your language it might make
2656 // sense to state the external link's language in brackets to not
2657 // frustrate the user. If there are multiple languages that the user might
2658 // know with a reasonable chance you might want to have 2 external links.
2659 // The same might be true for any external link you translate.
2660 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>"));
2661 // (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 )
2663 setStandardActionWhatsThis(KStandardAction::WhatsThis
,
2664 xi18nc("@info:whatsthis whatsthis button",
2665 "<para>This is the button that invokes the help feature you are "
2666 "using right now! Click it, then click any component of this "
2667 "application to ask \"What's this?\" about it. The mouse cursor "
2668 "will change appearance if no help is available for a spot.</para>"
2669 "<para>There are two other ways to get help: "
2670 "The <link url='help:/dolphin/index.html'>Dolphin Handbook</link> and "
2671 "the <link url='https://userbase.kde.org/Dolphin/File_Management'>KDE "
2672 "UserBase Wiki</link>.</para><para>The \"What's this?\" help is "
2673 "missing in most other windows so don't get too used to this.</para>"));
2675 setStandardActionWhatsThis(KStandardAction::ReportBug
,
2676 xi18nc("@info:whatsthis","<para>This opens a "
2677 "window that will guide you through reporting errors or flaws "
2678 "in this application or in other KDE software.</para>"
2679 "<para>High-quality bug reports are much appreciated. To learn "
2680 "how to make your bug report as effective as possible "
2681 "<link url='https://community.kde.org/Get_Involved/Bug_Reporting'>"
2682 "click here</link>.</para>"));
2684 setStandardActionWhatsThis(KStandardAction::Donate
,
2685 xi18nc("@info:whatsthis", "<para>This opens a "
2686 "<emphasis>web page</emphasis> where you can donate to "
2687 "support the continued work on this application and many "
2688 "other projects by the <emphasis>KDE</emphasis> community.</para>"
2689 "<para>Donating is the easiest and fastest way to efficiently "
2690 "support KDE and its projects. KDE projects are available for "
2691 "free therefore your donation is needed to cover things that "
2692 "require money like servers, contributor meetings, etc.</para>"
2693 "<para><emphasis>KDE e.V.</emphasis> is the non-profit "
2694 "organization behind the KDE community.</para>"));
2696 setStandardActionWhatsThis(KStandardAction::SwitchApplicationLanguage
,
2697 xi18nc("@info:whatsthis",
2698 "With this you can change the language this application uses."
2699 "<nl/>You can even set secondary languages which will be used "
2700 "if texts are not available in your preferred language."));
2702 setStandardActionWhatsThis(KStandardAction::AboutApp
,
2703 xi18nc("@info:whatsthis","This opens a "
2704 "window that informs you about the version, license, "
2705 "used libraries and maintainers of this application."));
2707 setStandardActionWhatsThis(KStandardAction::AboutKDE
,
2708 xi18nc("@info:whatsthis","This opens a "
2709 "window with information about <emphasis>KDE</emphasis>. "
2710 "The KDE community are the people behind this free software."
2711 "<nl/>If you like using this application but don't know "
2712 "about KDE or want to see a cute dragon have a look!"));
2716 bool DolphinMainWindow::addHamburgerMenuToToolbar()
2718 QDomDocument domDocument
= KXMLGUIClient::domDocument();
2719 if (domDocument
.isNull()) {
2722 QDomNode toolbar
= domDocument
.elementsByTagName(QStringLiteral("ToolBar")).at(0);
2723 if (toolbar
.isNull()) {
2727 QDomElement hamburgerMenuElement
= domDocument
.createElement(QStringLiteral("Action"));
2728 hamburgerMenuElement
.setAttribute(QStringLiteral("name"), QStringLiteral("hamburger_menu"));
2729 toolbar
.appendChild(hamburgerMenuElement
);
2731 KXMLGUIFactory::saveConfigFile(domDocument
, xmlFile());
2735 // Make sure to also remove the <KXMLGUIFactory> and <QDomDocument> include
2736 // whenever this method is removed (maybe in the year ~2026).
2739 // Set a sane initial window size
2740 QSize
DolphinMainWindow::sizeHint() const
2742 return KXmlGuiWindow::sizeHint().expandedTo(QSize(760, 550));
2745 void DolphinMainWindow::saveNewToolbarConfig()
2747 KXmlGuiWindow::saveNewToolbarConfig(); // Applies the new config. This has to be called first
2748 // because the rest of this method decides things
2749 // based on the new config.
2750 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>(actionCollection()->action(QStringLiteral("url_navigators")));
2751 if (!toolBar()->actions().contains(navigators
)) {
2752 m_tabWidget
->currentTabPage()->insertNavigatorsWidget(navigators
);
2754 updateAllowedToolbarAreas();
2755 (static_cast<KHamburgerMenu
*>(actionCollection()->action(KStandardAction::name(KStandardAction::HamburgerMenu
))))->hideActionsOf(toolBar());
2758 void DolphinMainWindow::focusTerminalPanel()
2760 if (m_terminalPanel
->isVisible()) {
2761 if (m_terminalPanel
->terminalHasFocus()) {
2762 m_activeViewContainer
->view()->setFocus(Qt::FocusReason::ShortcutFocusReason
);
2763 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
2765 m_terminalPanel
->setFocus(Qt::FocusReason::ShortcutFocusReason
);
2766 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
2769 actionCollection()->action(QStringLiteral("show_terminal_panel"))->trigger();
2770 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
2774 DolphinMainWindow::UndoUiInterface::UndoUiInterface()
2775 : KIO::FileUndoManager::UiInterface()
2779 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
2783 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
*job
)
2785 DolphinMainWindow
*mainWin
= qobject_cast
<DolphinMainWindow
*>(parentWidget());
2787 DolphinViewContainer
*container
= mainWin
->activeViewContainer();
2788 container
->showMessage(job
->errorString(), DolphinViewContainer::Error
);
2790 KIO::FileUndoManager::UiInterface::jobError(job
);
2794 bool DolphinMainWindow::isUrlOpen(const QString
&url
)
2796 return m_tabWidget
->isUrlOpen(QUrl::fromUserInput(url
));
2799 bool DolphinMainWindow::isItemVisibleInAnyView(const QString
&urlOfItem
)
2801 return m_tabWidget
->isItemVisibleInAnyView(QUrl::fromUserInput(urlOfItem
));
2804 #include "moc_dolphinmainwindow.cpp"