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)
121 , m_splitViewAction(nullptr)
123 Q_INIT_RESOURCE(dolphin
);
125 new MainWindowAdaptor(this);
128 setWindowFlags(Qt::WindowContextHelpButtonHint
);
130 setComponentName(QStringLiteral("dolphin"), QGuiApplication::applicationDisplayName());
131 setObjectName(QStringLiteral("Dolphin#"));
133 setStateConfigGroup("State");
135 connect(&DolphinNewFileMenuObserver::instance(), &DolphinNewFileMenuObserver::errorMessage
, this, &DolphinMainWindow::showErrorMessage
);
137 KIO::FileUndoManager
*undoManager
= KIO::FileUndoManager::self();
138 undoManager
->setUiInterface(new UndoUiInterface());
140 connect(undoManager
, &KIO::FileUndoManager::undoAvailable
, this, &DolphinMainWindow::slotUndoAvailable
);
141 connect(undoManager
, &KIO::FileUndoManager::undoTextChanged
, this, &DolphinMainWindow::slotUndoTextChanged
);
142 connect(undoManager
, &KIO::FileUndoManager::jobRecordingStarted
, this, &DolphinMainWindow::clearStatusBar
);
143 connect(undoManager
, &KIO::FileUndoManager::jobRecordingFinished
, this, &DolphinMainWindow::showCommand
);
145 const bool firstRun
= (GeneralSettings::version() < 200);
147 GeneralSettings::setViewPropsTimestamp(QDateTime::currentDateTime());
150 setAcceptDrops(true);
152 auto *navigatorsWidgetAction
= new DolphinNavigatorsWidgetAction(this);
153 actionCollection()->addAction(QStringLiteral("url_navigators"), navigatorsWidgetAction
);
154 m_tabWidget
= new DolphinTabWidget(navigatorsWidgetAction
, this);
155 m_tabWidget
->setObjectName("tabWidget");
156 connect(m_tabWidget
, &DolphinTabWidget::activeViewChanged
, this, &DolphinMainWindow::activeViewChanged
);
157 connect(m_tabWidget
, &DolphinTabWidget::tabCountChanged
, this, &DolphinMainWindow::tabCountChanged
);
158 connect(m_tabWidget
, &DolphinTabWidget::currentUrlChanged
, this, &DolphinMainWindow::updateWindowTitle
);
159 setCentralWidget(m_tabWidget
);
161 m_actionTextHelper
= new SelectionMode::ActionTextHelper(this);
164 m_actionHandler
= new DolphinViewActionHandler(actionCollection(), m_actionTextHelper
, this);
165 connect(m_actionHandler
, &DolphinViewActionHandler::actionBeingHandled
, this, &DolphinMainWindow::clearStatusBar
);
166 connect(m_actionHandler
, &DolphinViewActionHandler::createDirectoryTriggered
, this, &DolphinMainWindow::createDirectory
);
167 connect(m_actionHandler
, &DolphinViewActionHandler::selectionModeChangeTriggered
, this, &DolphinMainWindow::slotSetSelectionMode
);
169 Q_CHECK_PTR(actionCollection()->action(QStringLiteral("create_dir")));
170 m_newFileMenu
->setNewFolderShortcutAction(actionCollection()->action(QStringLiteral("create_dir")));
172 m_remoteEncoding
= new DolphinRemoteEncoding(this, m_actionHandler
);
173 connect(this, &DolphinMainWindow::urlChanged
, m_remoteEncoding
, &DolphinRemoteEncoding::slotAboutToOpenUrl
);
177 setupGUI(Save
| Create
| ToolBar
);
178 stateChanged(QStringLiteral("new_file"));
180 QClipboard
*clipboard
= QApplication::clipboard();
181 connect(clipboard
, &QClipboard::dataChanged
, this, &DolphinMainWindow::updatePasteAction
);
183 QAction
*toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
184 toggleFilterBarAction
->setChecked(GeneralSettings::filterBar());
187 menuBar()->setVisible(false);
190 const bool showMenu
= !menuBar()->isHidden();
191 QAction
*showMenuBarAction
= actionCollection()->action(KStandardAction::name(KStandardAction::ShowMenubar
));
192 showMenuBarAction
->setChecked(showMenu
); // workaround for bug #171080
194 auto hamburgerMenu
= static_cast<KHamburgerMenu
*>(actionCollection()->action(KStandardAction::name(KStandardAction::HamburgerMenu
)));
195 hamburgerMenu
->setMenuBar(menuBar());
196 hamburgerMenu
->setShowMenuBarAction(showMenuBarAction
);
197 connect(hamburgerMenu
, &KHamburgerMenu::aboutToShowMenu
, this, &DolphinMainWindow::updateHamburgerMenu
);
198 hamburgerMenu
->hideActionsOf(toolBar());
199 if (GeneralSettings::version() < 201 && !toolBar()->actions().contains(hamburgerMenu
)) {
200 addHamburgerMenuToToolbar();
203 updateAllowedToolbarAreas();
205 // enable middle-click on back/forward/up to open in a new tab
206 auto *middleClickEventFilter
= new MiddleClickActionEventFilter(this);
207 connect(middleClickEventFilter
, &MiddleClickActionEventFilter::actionMiddleClicked
, this, &DolphinMainWindow::slotToolBarActionMiddleClicked
);
208 toolBar()->installEventFilter(middleClickEventFilter
);
212 connect(KSycoca::self(), &KSycoca::databaseChanged
, this, &DolphinMainWindow::updateOpenPreferredSearchToolAction
);
214 QTimer::singleShot(0, this, &DolphinMainWindow::updateOpenPreferredSearchToolAction
);
216 m_fileItemActions
.setParentWidget(this);
217 connect(&m_fileItemActions
, &KFileItemActions::error
, this, [this](const QString
&errorMessage
) {
218 showErrorMessage(errorMessage
);
221 connect(GeneralSettings::self(), &GeneralSettings::splitViewChanged
, this, &DolphinMainWindow::slotSplitViewChanged
);
224 DolphinMainWindow::~DolphinMainWindow()
226 // This fixes a crash on Wayland when closing the mainwindow while another dialog is open.
227 disconnect(QGuiApplication::clipboard(), &QClipboard::dataChanged
, this, &DolphinMainWindow::updatePasteAction
);
230 QVector
<DolphinViewContainer
*> DolphinMainWindow::viewContainers() const
232 QVector
<DolphinViewContainer
*> viewContainers
;
234 for (int i
= 0; i
< m_tabWidget
->count(); ++i
) {
235 DolphinTabPage
*tabPage
= m_tabWidget
->tabPageAt(i
);
237 viewContainers
<< tabPage
->primaryViewContainer();
238 if (tabPage
->splitViewEnabled()) {
239 viewContainers
<< tabPage
->secondaryViewContainer();
242 return viewContainers
;
245 void DolphinMainWindow::openDirectories(const QList
<QUrl
> &dirs
, bool splitView
)
247 m_tabWidget
->openDirectories(dirs
, splitView
);
250 void DolphinMainWindow::openDirectories(const QStringList
&dirs
, bool splitView
)
252 openDirectories(QUrl::fromStringList(dirs
), splitView
);
255 void DolphinMainWindow::openFiles(const QList
<QUrl
> &files
, bool splitView
)
257 m_tabWidget
->openFiles(files
, splitView
);
260 bool DolphinMainWindow::isFoldersPanelEnabled() const
262 return actionCollection()->action(QStringLiteral("show_folders_panel"))->isChecked();
265 bool DolphinMainWindow::isInformationPanelEnabled() const
268 return actionCollection()->action(QStringLiteral("show_information_panel"))->isChecked();
274 bool DolphinMainWindow::isSplitViewEnabledInCurrentTab() const
276 return m_tabWidget
->currentTabPage()->splitViewEnabled();
279 void DolphinMainWindow::openFiles(const QStringList
&files
, bool splitView
)
281 openFiles(QUrl::fromStringList(files
), splitView
);
284 void DolphinMainWindow::activateWindow(const QString
&activationToken
)
286 window()->setAttribute(Qt::WA_NativeWindow
, true);
288 if (KWindowSystem::isPlatformWayland()) {
289 KWindowSystem::setCurrentXdgActivationToken(activationToken
);
290 } else if (KWindowSystem::isPlatformX11()) {
292 KStartupInfo::setNewStartupId(window()->windowHandle(), activationToken
.toUtf8());
296 KWindowSystem::activateWindow(window()->windowHandle());
299 bool DolphinMainWindow::isActiveWindow()
301 return window()->isActiveWindow();
304 void DolphinMainWindow::showCommand(CommandType command
)
306 DolphinStatusBar
*statusBar
= m_activeViewContainer
->statusBar();
308 case KIO::FileUndoManager::Copy
:
309 statusBar
->setText(i18nc("@info:status", "Successfully copied."));
311 case KIO::FileUndoManager::Move
:
312 statusBar
->setText(i18nc("@info:status", "Successfully moved."));
314 case KIO::FileUndoManager::Link
:
315 statusBar
->setText(i18nc("@info:status", "Successfully linked."));
317 case KIO::FileUndoManager::Trash
:
318 statusBar
->setText(i18nc("@info:status", "Successfully moved to trash."));
320 case KIO::FileUndoManager::Rename
:
321 statusBar
->setText(i18nc("@info:status", "Successfully renamed."));
324 case KIO::FileUndoManager::Mkdir
:
325 statusBar
->setText(i18nc("@info:status", "Created folder."));
333 void DolphinMainWindow::pasteIntoFolder()
335 m_activeViewContainer
->view()->pasteIntoFolder();
338 void DolphinMainWindow::changeUrl(const QUrl
&url
)
340 if (!KProtocolManager::supportsListing(url
)) {
341 // The URL navigator only checks for validity, not
342 // if the URL can be listed. An error message is
343 // shown due to DolphinViewContainer::restoreView().
347 m_activeViewContainer
->setUrl(url
);
348 updateFileAndEditActions();
353 Q_EMIT
urlChanged(url
);
356 void DolphinMainWindow::slotTerminalDirectoryChanged(const QUrl
&url
)
358 if (m_tearDownFromPlacesRequested
&& url
== QUrl::fromLocalFile(QDir::homePath())) {
359 m_placesPanel
->proceedWithTearDown();
360 m_tearDownFromPlacesRequested
= false;
363 m_activeViewContainer
->setAutoGrabFocus(false);
365 m_activeViewContainer
->setAutoGrabFocus(true);
368 void DolphinMainWindow::slotEditableStateChanged(bool editable
)
370 KToggleAction
*editableLocationAction
= static_cast<KToggleAction
*>(actionCollection()->action(QStringLiteral("editable_location")));
371 editableLocationAction
->setChecked(editable
);
374 void DolphinMainWindow::slotSelectionChanged(const KFileItemList
&selection
)
376 updateFileAndEditActions();
378 const int selectedUrlsCount
= m_tabWidget
->currentTabPage()->selectedItemsCount();
380 QAction
*compareFilesAction
= actionCollection()->action(QStringLiteral("compare_files"));
381 if (selectedUrlsCount
== 2) {
382 compareFilesAction
->setEnabled(isKompareInstalled());
384 compareFilesAction
->setEnabled(false);
387 Q_EMIT
selectionChanged(selection
);
390 void DolphinMainWindow::updateHistory()
392 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
393 const int index
= urlNavigator
->historyIndex();
395 QAction
*backAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Back
));
397 backAction
->setToolTip(i18nc("@info", "Go back"));
398 backAction
->setWhatsThis(i18nc("@info:whatsthis go back", "Return to the previously viewed folder."));
399 backAction
->setEnabled(index
< urlNavigator
->historySize() - 1);
402 QAction
*forwardAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Forward
));
404 forwardAction
->setToolTip(i18nc("@info", "Go forward"));
405 forwardAction
->setWhatsThis(xi18nc("@info:whatsthis go forward", "This undoes a <interface>Go|Back</interface> action."));
406 forwardAction
->setEnabled(index
> 0);
410 void DolphinMainWindow::updateFilterBarAction(bool show
)
412 QAction
*toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
413 toggleFilterBarAction
->setChecked(show
);
416 void DolphinMainWindow::openNewMainWindow()
418 Dolphin::openNewWindow({m_activeViewContainer
->url()}, this);
421 void DolphinMainWindow::openNewActivatedTab()
423 // keep browsers compatibility, new tab is always after last one
424 auto openNewTabAfterLastTabConfigured
= GeneralSettings::openNewTabAfterLastTab();
425 GeneralSettings::setOpenNewTabAfterLastTab(true);
426 m_tabWidget
->openNewActivatedTab();
427 GeneralSettings::setOpenNewTabAfterLastTab(openNewTabAfterLastTabConfigured
);
430 void DolphinMainWindow::addToPlaces()
435 // If nothing is selected, act on the current dir
436 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
437 url
= m_activeViewContainer
->url();
438 name
= m_activeViewContainer
->placesText();
440 const auto dirToAdd
= m_activeViewContainer
->view()->selectedItems().first();
441 url
= dirToAdd
.url();
442 name
= dirToAdd
.name();
446 if (m_activeViewContainer
->isSearchModeEnabled()) {
447 icon
= QStringLiteral("folder-saved-search-symbolic");
449 icon
= KIO::iconNameForUrl(url
);
451 DolphinPlacesModelSingleton::instance().placesModel()->addPlace(name
, url
, icon
);
455 void DolphinMainWindow::openNewTab(const QUrl
&url
)
457 m_tabWidget
->openNewTab(url
, QUrl());
460 void DolphinMainWindow::openNewTabAndActivate(const QUrl
&url
)
462 m_tabWidget
->openNewActivatedTab(url
, QUrl());
465 void DolphinMainWindow::openNewWindow(const QUrl
&url
)
467 Dolphin::openNewWindow({url
}, this);
470 void DolphinMainWindow::slotSplitViewChanged()
472 m_tabWidget
->currentTabPage()->setSplitViewEnabled(GeneralSettings::splitView(), WithAnimation
);
473 updateSplitActions();
476 void DolphinMainWindow::openInNewTab()
478 const KFileItemList
&list
= m_activeViewContainer
->view()->selectedItems();
479 bool tabCreated
= false;
481 for (const KFileItem
&item
: list
) {
482 const QUrl
&url
= DolphinView::openItemAsFolderUrl(item
);
483 if (!url
.isEmpty()) {
489 // if no new tab has been created from the selection
490 // open the current directory in a new tab
492 openNewTab(m_activeViewContainer
->url());
496 void DolphinMainWindow::openInNewWindow()
500 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
501 if (list
.isEmpty()) {
502 newWindowUrl
= m_activeViewContainer
->url();
503 } else if (list
.count() == 1) {
504 const KFileItem
&item
= list
.first();
505 newWindowUrl
= DolphinView::openItemAsFolderUrl(item
);
508 if (!newWindowUrl
.isEmpty()) {
509 Dolphin::openNewWindow({newWindowUrl
}, this);
513 void DolphinMainWindow::openInSplitView(const QUrl
&url
)
515 QUrl newSplitViewUrl
= url
;
517 if (newSplitViewUrl
.isEmpty()) {
518 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
519 if (list
.count() == 1) {
520 const KFileItem
&item
= list
.first();
521 newSplitViewUrl
= DolphinView::openItemAsFolderUrl(item
);
525 if (newSplitViewUrl
.isEmpty()) {
529 DolphinTabPage
*tabPage
= m_tabWidget
->currentTabPage();
530 if (tabPage
->splitViewEnabled()) {
531 tabPage
->switchActiveView();
532 tabPage
->activeViewContainer()->setUrl(newSplitViewUrl
);
534 tabPage
->setSplitViewEnabled(true, WithAnimation
, newSplitViewUrl
);
539 void DolphinMainWindow::showTarget()
541 const KFileItem link
= m_activeViewContainer
->view()->selectedItems().at(0);
542 const QUrl destinationUrl
= link
.url().resolved(QUrl(link
.linkDest()));
544 auto job
= KIO::stat(destinationUrl
, KIO::StatJob::SourceSide
, KIO::StatNoDetails
);
546 connect(job
, &KJob::finished
, this, [this, destinationUrl
](KJob
*job
) {
547 KIO::StatJob
*statJob
= static_cast<KIO::StatJob
*>(job
);
549 if (statJob
->error()) {
550 m_activeViewContainer
->showMessage(job
->errorString(), DolphinViewContainer::Error
);
552 KIO::highlightInFileManager({destinationUrl
});
557 bool DolphinMainWindow::event(QEvent
*event
)
559 if (event
->type() == QEvent::ShortcutOverride
) {
560 const QKeyEvent
*keyEvent
= static_cast<QKeyEvent
*>(event
);
561 if (keyEvent
->key() == Qt::Key_Space
&& m_activeViewContainer
->view()->handleSpaceAsNormalKey()) {
567 return KXmlGuiWindow::event(event
);
570 void DolphinMainWindow::showEvent(QShowEvent
*event
)
572 KXmlGuiWindow::showEvent(event
);
574 if (!event
->spontaneous()) {
575 m_activeViewContainer
->view()->setFocus();
579 void DolphinMainWindow::closeEvent(QCloseEvent
*event
)
581 // Find out if Dolphin is closed directly by the user or
582 // by the session manager because the session is closed
583 bool closedByUser
= true;
584 if (qApp
->isSavingSession()) {
585 closedByUser
= false;
588 if (m_tabWidget
->count() > 1 && GeneralSettings::confirmClosingMultipleTabs() && !GeneralSettings::rememberOpenedTabs() && closedByUser
) {
589 // Ask the user if he really wants to quit and close all tabs.
590 // Open a confirmation dialog with 3 buttons:
591 // QDialogButtonBox::Yes -> Quit
592 // QDialogButtonBox::No -> Close only the current tab
593 // QDialogButtonBox::Cancel -> do nothing
594 QDialog
*dialog
= new QDialog(this, Qt::Dialog
);
595 dialog
->setWindowTitle(i18nc("@title:window", "Confirmation"));
596 dialog
->setModal(true);
597 QDialogButtonBox
*buttons
= new QDialogButtonBox(QDialogButtonBox::Yes
| QDialogButtonBox::No
| QDialogButtonBox::Cancel
);
598 KGuiItem::assign(buttons
->button(QDialogButtonBox::Yes
),
599 KGuiItem(i18nc("@action:button 'Quit Dolphin' button", "&Quit %1", QGuiApplication::applicationDisplayName()),
600 QIcon::fromTheme(QStringLiteral("application-exit"))));
601 KGuiItem::assign(buttons
->button(QDialogButtonBox::No
), KGuiItem(i18n("C&lose Current Tab"), QIcon::fromTheme(QStringLiteral("tab-close"))));
602 KGuiItem::assign(buttons
->button(QDialogButtonBox::Cancel
), KStandardGuiItem::cancel());
603 buttons
->button(QDialogButtonBox::Yes
)->setDefault(true);
605 bool doNotAskAgainCheckboxResult
= false;
607 const auto result
= KMessageBox::createKMessageBox(dialog
,
609 QMessageBox::Warning
,
610 i18n("You have multiple tabs open in this window, are you sure you want to quit?"),
612 i18n("Do not ask again"),
613 &doNotAskAgainCheckboxResult
,
614 KMessageBox::Notify
);
616 if (doNotAskAgainCheckboxResult
) {
617 GeneralSettings::setConfirmClosingMultipleTabs(false);
621 case QDialogButtonBox::Yes
:
624 case QDialogButtonBox::No
:
625 // Close only the current tab
626 m_tabWidget
->closeTab();
634 if (m_terminalPanel
&& m_terminalPanel
->hasProgramRunning() && GeneralSettings::confirmClosingTerminalRunningProgram() && closedByUser
) {
635 // Ask if the user really wants to quit Dolphin with a program that is still running in the Terminal panel
636 // Open a confirmation dialog with 3 buttons:
637 // QDialogButtonBox::Yes -> Quit
638 // QDialogButtonBox::No -> Show Terminal Panel
639 // QDialogButtonBox::Cancel -> do nothing
640 QDialog
*dialog
= new QDialog(this, Qt::Dialog
);
641 dialog
->setWindowTitle(i18nc("@title:window", "Confirmation"));
642 dialog
->setModal(true);
643 auto standardButtons
= QDialogButtonBox::Yes
| QDialogButtonBox::Cancel
;
644 if (!m_terminalPanel
->isVisible()) {
645 standardButtons
|= QDialogButtonBox::No
;
647 QDialogButtonBox
*buttons
= new QDialogButtonBox(standardButtons
);
648 KGuiItem::assign(buttons
->button(QDialogButtonBox::Yes
), KStandardGuiItem::quit());
649 if (!m_terminalPanel
->isVisible()) {
650 KGuiItem::assign(buttons
->button(QDialogButtonBox::No
), KGuiItem(i18n("Show &Terminal Panel"), QIcon::fromTheme(QStringLiteral("dialog-scripts"))));
652 KGuiItem::assign(buttons
->button(QDialogButtonBox::Cancel
), KStandardGuiItem::cancel());
654 bool doNotAskAgainCheckboxResult
= false;
656 const auto result
= KMessageBox::createKMessageBox(
659 QMessageBox::Warning
,
660 i18n("The program '%1' is still running in the Terminal panel. Are you sure you want to quit?", m_terminalPanel
->runningProgramName()),
662 i18n("Do not ask again"),
663 &doNotAskAgainCheckboxResult
,
664 KMessageBox::Notify
| KMessageBox::Dangerous
);
666 if (doNotAskAgainCheckboxResult
) {
667 GeneralSettings::setConfirmClosingTerminalRunningProgram(false);
671 case QDialogButtonBox::Yes
:
674 case QDialogButtonBox::No
:
675 actionCollection()->action("show_terminal_panel")->trigger();
676 // Do not quit, ignore quit event
684 if (m_sessionSaveTimer
&& (m_sessionSaveTimer
->isActive() || m_sessionSaveWatcher
->isRunning())) {
685 const bool sessionSaveTimerActive
= m_sessionSaveTimer
->isActive();
687 m_sessionSaveTimer
->stop();
688 m_sessionSaveWatcher
->disconnect();
689 m_sessionSaveWatcher
->waitForFinished();
691 if (sessionSaveTimerActive
|| m_sessionSaveScheduled
) {
696 GeneralSettings::setVersion(CurrentDolphinVersion
);
697 GeneralSettings::self()->save();
699 KXmlGuiWindow::closeEvent(event
);
702 void DolphinMainWindow::slotSaveSession()
704 m_sessionSaveScheduled
= false;
706 if (m_sessionSaveWatcher
->isRunning()) {
707 // The previous session is still being saved - schedule another save.
708 m_sessionSaveWatcher
->disconnect();
709 connect(m_sessionSaveWatcher
, &QFutureWatcher
<void>::finished
, this, &DolphinMainWindow::slotSaveSession
, Qt::SingleShotConnection
);
710 m_sessionSaveScheduled
= true;
711 } else if (!m_sessionSaveTimer
->isActive()) {
712 // No point in saving the session if the timer is running (since it will save the session again when it times out).
713 KConfigGui::setSessionConfig(QStringLiteral("dolphin"), QStringLiteral("dolphin"));
714 KConfig
*config
= KConfigGui::sessionConfig();
715 saveGlobalProperties(config
);
716 savePropertiesInternal(config
, 1);
718 auto future
= QtConcurrent::run([config
]() {
721 m_sessionSaveWatcher
->setFuture(future
);
725 void DolphinMainWindow::setSessionAutoSaveEnabled(bool enable
)
728 if (!m_sessionSaveTimer
) {
729 m_sessionSaveTimer
= new QTimer(this);
730 m_sessionSaveWatcher
= new QFutureWatcher
<void>(this);
731 m_sessionSaveTimer
->setSingleShot(true);
732 m_sessionSaveTimer
->setInterval(22000);
734 connect(m_sessionSaveTimer
, &QTimer::timeout
, this, &DolphinMainWindow::slotSaveSession
);
737 connect(m_tabWidget
, &DolphinTabWidget::urlChanged
, m_sessionSaveTimer
, qOverload
<>(&QTimer::start
), Qt::UniqueConnection
);
738 connect(m_tabWidget
, &DolphinTabWidget::tabCountChanged
, m_sessionSaveTimer
, qOverload
<>(&QTimer::start
), Qt::UniqueConnection
);
739 connect(m_tabWidget
, &DolphinTabWidget::activeViewChanged
, m_sessionSaveTimer
, qOverload
<>(&QTimer::start
), Qt::UniqueConnection
);
740 } else if (m_sessionSaveTimer
) {
741 m_sessionSaveTimer
->stop();
742 m_sessionSaveWatcher
->disconnect();
743 m_sessionSaveScheduled
= false;
745 m_sessionSaveWatcher
->waitForFinished();
747 m_sessionSaveTimer
->deleteLater();
748 m_sessionSaveWatcher
->deleteLater();
749 m_sessionSaveTimer
= nullptr;
750 m_sessionSaveWatcher
= nullptr;
754 void DolphinMainWindow::saveProperties(KConfigGroup
&group
)
756 m_tabWidget
->saveProperties(group
);
759 void DolphinMainWindow::readProperties(const KConfigGroup
&group
)
761 m_tabWidget
->readProperties(group
);
764 void DolphinMainWindow::updateNewMenu()
766 m_newFileMenu
->checkUpToDate();
767 m_newFileMenu
->setWorkingDirectory(activeViewContainer()->url());
770 void DolphinMainWindow::createDirectory()
772 m_newFileMenu
->setWorkingDirectory(activeViewContainer()->url());
773 m_newFileMenu
->createDirectory();
776 void DolphinMainWindow::quit()
781 void DolphinMainWindow::showErrorMessage(const QString
&message
)
783 m_activeViewContainer
->showMessage(message
, DolphinViewContainer::Error
);
786 void DolphinMainWindow::slotUndoAvailable(bool available
)
788 QAction
*undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
790 undoAction
->setEnabled(available
);
794 void DolphinMainWindow::slotUndoTextChanged(const QString
&text
)
796 QAction
*undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
798 undoAction
->setText(text
);
802 void DolphinMainWindow::undo()
805 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
806 KIO::FileUndoManager::self()->undo();
809 void DolphinMainWindow::cut()
811 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
812 m_activeViewContainer
->setSelectionModeEnabled(true, actionCollection(), SelectionMode::BottomBar::Contents::CutContents
);
814 m_activeViewContainer
->view()->cutSelectedItemsToClipboard();
815 m_activeViewContainer
->setSelectionModeEnabled(false);
819 void DolphinMainWindow::copy()
821 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
822 m_activeViewContainer
->setSelectionModeEnabled(true, actionCollection(), SelectionMode::BottomBar::Contents::CopyContents
);
824 m_activeViewContainer
->view()->copySelectedItemsToClipboard();
825 m_activeViewContainer
->setSelectionModeEnabled(false);
829 void DolphinMainWindow::paste()
831 m_activeViewContainer
->view()->paste();
834 void DolphinMainWindow::find()
836 m_activeViewContainer
->setSearchModeEnabled(true);
839 void DolphinMainWindow::updateSearchAction()
841 QAction
*toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
842 toggleSearchAction
->setChecked(m_activeViewContainer
->isSearchModeEnabled());
845 void DolphinMainWindow::updatePasteAction()
847 QAction
*pasteAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Paste
));
848 QPair
<bool, QString
> pasteInfo
= m_activeViewContainer
->view()->pasteInfo();
849 pasteAction
->setEnabled(pasteInfo
.first
);
850 pasteAction
->setText(pasteInfo
.second
);
853 void DolphinMainWindow::slotDirectoryLoadingCompleted()
858 void DolphinMainWindow::slotToolBarActionMiddleClicked(QAction
*action
)
860 if (action
== actionCollection()->action(KStandardAction::name(KStandardAction::Back
))) {
862 } else if (action
== actionCollection()->action(KStandardAction::name(KStandardAction::Forward
))) {
864 } else if (action
== actionCollection()->action(QStringLiteral("go_up"))) {
866 } else if (action
== actionCollection()->action(QStringLiteral("go_home"))) {
871 QAction
*DolphinMainWindow::urlNavigatorHistoryAction(const KUrlNavigator
*urlNavigator
, int historyIndex
, QObject
*parent
)
873 const QUrl url
= urlNavigator
->locationUrl(historyIndex
);
875 QString text
= url
.toDisplayString(QUrl::PreferLocalFile
);
877 if (!urlNavigator
->showFullPath()) {
878 const KFilePlacesModel
*placesModel
= DolphinPlacesModelSingleton::instance().placesModel();
880 const QModelIndex closestIdx
= placesModel
->closestItem(url
);
881 if (closestIdx
.isValid()) {
882 const QUrl placeUrl
= placesModel
->url(closestIdx
);
884 text
= placesModel
->text(closestIdx
);
886 QString pathInsidePlace
= url
.path().mid(placeUrl
.path().length());
888 if (!pathInsidePlace
.isEmpty() && !pathInsidePlace
.startsWith(QLatin1Char('/'))) {
889 pathInsidePlace
.prepend(QLatin1Char('/'));
892 if (pathInsidePlace
!= QLatin1Char('/')) {
893 text
.append(pathInsidePlace
);
898 QAction
*action
= new QAction(QIcon::fromTheme(KIO::iconNameForUrl(url
)), text
, parent
);
899 action
->setData(historyIndex
);
903 void DolphinMainWindow::slotAboutToShowBackPopupMenu()
905 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
907 QMenu
*menu
= m_backAction
->popupMenu();
909 for (int i
= urlNavigator
->historyIndex() + 1; i
< urlNavigator
->historySize() && entries
< MaxNumberOfNavigationentries
; ++i
, ++entries
) {
910 QAction
*action
= urlNavigatorHistoryAction(urlNavigator
, i
, menu
);
911 menu
->addAction(action
);
915 void DolphinMainWindow::slotGoBack(QAction
*action
)
917 int gotoIndex
= action
->data().value
<int>();
918 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
919 for (int i
= gotoIndex
- urlNavigator
->historyIndex(); i
> 0; --i
) {
924 void DolphinMainWindow::slotBackForwardActionMiddleClicked(QAction
*action
)
927 const KUrlNavigator
*urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
928 openNewTab(urlNavigator
->locationUrl(action
->data().value
<int>()));
932 void DolphinMainWindow::slotAboutToShowForwardPopupMenu()
934 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
936 QMenu
*menu
= m_forwardAction
->popupMenu();
937 for (int i
= urlNavigator
->historyIndex() - 1; i
>= 0 && entries
< MaxNumberOfNavigationentries
; --i
, ++entries
) {
938 QAction
*action
= urlNavigatorHistoryAction(urlNavigator
, i
, menu
);
939 menu
->addAction(action
);
943 void DolphinMainWindow::slotGoForward(QAction
*action
)
945 int gotoIndex
= action
->data().value
<int>();
946 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
947 for (int i
= urlNavigator
->historyIndex() - gotoIndex
; i
> 0; --i
) {
952 void DolphinMainWindow::slotSetSelectionMode(bool enabled
, SelectionMode::BottomBar::Contents bottomBarContents
)
954 m_activeViewContainer
->setSelectionModeEnabled(enabled
, actionCollection(), bottomBarContents
);
957 void DolphinMainWindow::selectAll()
961 // if the URL navigator is editable and focused, select the whole
962 // URL instead of all items of the view
964 KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigator();
965 QLineEdit
*lineEdit
= urlNavigator
->editor()->lineEdit();
966 const bool selectUrl
= urlNavigator
->isUrlEditable() && lineEdit
->hasFocus();
968 lineEdit
->selectAll();
970 m_activeViewContainer
->view()->selectAll();
974 void DolphinMainWindow::invertSelection()
977 m_activeViewContainer
->view()->invertSelection();
980 void DolphinMainWindow::toggleSplitView()
982 DolphinTabPage
*tabPage
= m_tabWidget
->currentTabPage();
983 tabPage
->setSplitViewEnabled(!tabPage
->splitViewEnabled(), WithAnimation
);
984 m_tabWidget
->updateTabName(m_tabWidget
->indexOf(tabPage
));
988 void DolphinMainWindow::popoutSplitView()
990 DolphinTabPage
*tabPage
= m_tabWidget
->currentTabPage();
991 if (!tabPage
->splitViewEnabled())
993 openNewWindow((GeneralSettings::closeActiveSplitView() ? tabPage
->activeViewContainer() : tabPage
->inactiveViewContainer())->url());
994 tabPage
->setSplitViewEnabled(false, WithAnimation
);
995 updateSplitActions();
998 void DolphinMainWindow::toggleSplitStash()
1000 DolphinTabPage
*tabPage
= m_tabWidget
->currentTabPage();
1001 tabPage
->setSplitViewEnabled(false, WithAnimation
);
1002 tabPage
->setSplitViewEnabled(true, WithAnimation
, QUrl("stash:/"));
1005 void DolphinMainWindow::copyToInactiveSplitView()
1007 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
1008 m_activeViewContainer
->setSelectionModeEnabled(true, actionCollection(), SelectionMode::BottomBar::Contents::CopyToOtherViewContents
);
1010 m_tabWidget
->copyToInactiveSplitView();
1011 m_activeViewContainer
->setSelectionModeEnabled(false);
1015 void DolphinMainWindow::moveToInactiveSplitView()
1017 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
1018 m_activeViewContainer
->setSelectionModeEnabled(true, actionCollection(), SelectionMode::BottomBar::Contents::MoveToOtherViewContents
);
1020 m_tabWidget
->moveToInactiveSplitView();
1021 m_activeViewContainer
->setSelectionModeEnabled(false);
1025 void DolphinMainWindow::reloadView()
1028 m_activeViewContainer
->reload();
1029 m_activeViewContainer
->statusBar()->updateSpaceInfo();
1032 void DolphinMainWindow::stopLoading()
1034 m_activeViewContainer
->view()->stopLoading();
1037 void DolphinMainWindow::enableStopAction()
1039 actionCollection()->action(QStringLiteral("stop"))->setEnabled(true);
1042 void DolphinMainWindow::disableStopAction()
1044 actionCollection()->action(QStringLiteral("stop"))->setEnabled(false);
1047 void DolphinMainWindow::toggleSelectionMode()
1049 const bool checked
= !m_activeViewContainer
->isSelectionModeEnabled();
1051 m_activeViewContainer
->setSelectionModeEnabled(checked
, actionCollection(), SelectionMode::BottomBar::Contents::GeneralContents
);
1052 actionCollection()->action(QStringLiteral("toggle_selection_mode"))->setChecked(checked
);
1055 void DolphinMainWindow::showFilterBar()
1057 m_activeViewContainer
->setFilterBarVisible(true);
1060 void DolphinMainWindow::toggleFilterBar()
1062 const bool checked
= !m_activeViewContainer
->isFilterBarVisible();
1063 m_activeViewContainer
->setFilterBarVisible(checked
);
1065 QAction
*toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
1066 toggleFilterBarAction
->setChecked(checked
);
1069 void DolphinMainWindow::toggleEditLocation()
1073 QAction
*action
= actionCollection()->action(QStringLiteral("editable_location"));
1074 KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigator();
1075 urlNavigator
->setUrlEditable(action
->isChecked());
1078 void DolphinMainWindow::replaceLocation()
1080 KUrlNavigator
*navigator
= m_activeViewContainer
->urlNavigator();
1081 QLineEdit
*lineEdit
= navigator
->editor()->lineEdit();
1083 // If the text field currently has focus and everything is selected,
1084 // pressing the keyboard shortcut returns the whole thing to breadcrumb mode
1085 if (navigator
->isUrlEditable() && lineEdit
->hasFocus() && lineEdit
->selectedText() == lineEdit
->text()) {
1086 navigator
->setUrlEditable(false);
1088 navigator
->setUrlEditable(true);
1089 navigator
->setFocus();
1090 lineEdit
->selectAll();
1094 void DolphinMainWindow::togglePanelLockState()
1096 const bool newLockState
= !GeneralSettings::lockPanels();
1097 const auto childrenObjects
= children();
1098 for (QObject
*child
: childrenObjects
) {
1099 DolphinDockWidget
*dock
= qobject_cast
<DolphinDockWidget
*>(child
);
1101 dock
->setLocked(newLockState
);
1105 DolphinPlacesModelSingleton::instance().placesModel()->setPanelsLocked(newLockState
);
1107 GeneralSettings::setLockPanels(newLockState
);
1110 void DolphinMainWindow::slotTerminalPanelVisibilityChanged()
1112 if (m_terminalPanel
->isHiddenInVisibleWindow() && m_activeViewContainer
) {
1113 m_activeViewContainer
->view()->setFocus();
1117 void DolphinMainWindow::goBack()
1119 DolphinUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
1120 urlNavigator
->goBack();
1122 if (urlNavigator
->locationState().isEmpty()) {
1123 // An empty location state indicates a redirection URL,
1124 // which must be skipped too
1125 urlNavigator
->goBack();
1129 void DolphinMainWindow::goForward()
1131 m_activeViewContainer
->urlNavigatorInternalWithHistory()->goForward();
1134 void DolphinMainWindow::goUp()
1136 m_activeViewContainer
->urlNavigatorInternalWithHistory()->goUp();
1139 void DolphinMainWindow::goHome()
1141 m_activeViewContainer
->urlNavigatorInternalWithHistory()->goHome();
1144 void DolphinMainWindow::goBackInNewTab()
1146 const KUrlNavigator
*urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
1147 const int index
= urlNavigator
->historyIndex() + 1;
1148 openNewTab(urlNavigator
->locationUrl(index
));
1151 void DolphinMainWindow::goForwardInNewTab()
1153 const KUrlNavigator
*urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
1154 const int index
= urlNavigator
->historyIndex() - 1;
1155 openNewTab(urlNavigator
->locationUrl(index
));
1158 void DolphinMainWindow::goUpInNewTab()
1160 const QUrl currentUrl
= activeViewContainer()->urlNavigator()->locationUrl();
1161 openNewTab(KIO::upUrl(currentUrl
));
1164 void DolphinMainWindow::goHomeInNewTab()
1166 openNewTab(Dolphin::homeUrl());
1169 void DolphinMainWindow::compareFiles()
1171 const KFileItemList items
= m_tabWidget
->currentTabPage()->selectedItems();
1172 if (items
.count() != 2) {
1173 // The action is disabled in this case, but it could have been triggered
1174 // via D-Bus, see https://bugs.kde.org/show_bug.cgi?id=325517
1178 QUrl urlA
= items
.at(0).url();
1179 QUrl urlB
= items
.at(1).url();
1181 QString
command(QStringLiteral("kompare -c \""));
1182 command
.append(urlA
.toDisplayString(QUrl::PreferLocalFile
));
1183 command
.append("\" \"");
1184 command
.append(urlB
.toDisplayString(QUrl::PreferLocalFile
));
1185 command
.append('\"');
1187 KIO::CommandLauncherJob
*job
= new KIO::CommandLauncherJob(command
, this);
1188 job
->setDesktopName(QStringLiteral("org.kde.kompare"));
1192 void DolphinMainWindow::toggleShowMenuBar()
1194 const bool visible
= menuBar()->isVisible();
1195 menuBar()->setVisible(!visible
);
1198 QPointer
<QAction
> DolphinMainWindow::preferredSearchTool()
1200 m_searchTools
.clear();
1202 KService::Ptr kfind
= KService::serviceByDesktopName(QStringLiteral("org.kde.kfind"));
1208 auto *action
= new QAction(QIcon::fromTheme(kfind
->icon()), kfind
->name(), this);
1210 connect(action
, &QAction::triggered
, this, [kfind
] {
1211 auto *job
= new KIO::ApplicationLauncherJob(kfind
);
1218 void DolphinMainWindow::updateOpenPreferredSearchToolAction()
1220 QAction
*openPreferredSearchTool
= actionCollection()->action(QStringLiteral("open_preferred_search_tool"));
1221 if (!openPreferredSearchTool
) {
1224 QPointer
<QAction
> tool
= preferredSearchTool();
1226 openPreferredSearchTool
->setVisible(true);
1227 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open %1", tool
->text()));
1228 // Only override with the app icon if it is the default, i.e. the user hasn't configured one manually
1229 // https://bugs.kde.org/show_bug.cgi?id=442815
1230 if (openPreferredSearchTool
->icon().name() == QLatin1String("search")) {
1231 openPreferredSearchTool
->setIcon(tool
->icon());
1234 openPreferredSearchTool
->setVisible(false);
1235 // still visible in Shortcuts configuration window
1236 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool"));
1237 openPreferredSearchTool
->setIcon(QIcon::fromTheme(QStringLiteral("search")));
1241 void DolphinMainWindow::openPreferredSearchTool()
1243 QPointer
<QAction
> tool
= preferredSearchTool();
1249 void DolphinMainWindow::openTerminal()
1251 openTerminalJob(m_activeViewContainer
->url());
1254 void DolphinMainWindow::openTerminalHere()
1256 QList
<QUrl
> urls
= {};
1258 const auto selectedItems
= m_activeViewContainer
->view()->selectedItems();
1259 for (const KFileItem
&item
: selectedItems
) {
1260 QUrl url
= item
.targetUrl();
1261 if (item
.isFile()) {
1262 url
.setPath(QFileInfo(url
.path()).absolutePath());
1264 if (!urls
.contains(url
)) {
1269 // No items are selected. Open a terminal window for the current location.
1270 if (urls
.count() == 0) {
1275 if (urls
.count() > 5) {
1276 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());
1277 const int answer
= KMessageBox::warningContinueCancel(
1281 KGuiItem(i18ncp("@action:button", "Open %1 Terminal", "Open %1 Terminals", urls
.count()), QStringLiteral("utilities-terminal")),
1282 KStandardGuiItem::cancel(),
1283 QStringLiteral("ConfirmOpenManyTerminals"));
1284 if (answer
!= KMessageBox::PrimaryAction
&& answer
!= KMessageBox::Continue
) {
1289 for (const QUrl
&url
: std::as_const(urls
)) {
1290 openTerminalJob(url
);
1294 void DolphinMainWindow::openTerminalJob(const QUrl
&url
)
1296 if (url
.isLocalFile()) {
1297 auto job
= new KTerminalLauncherJob(QString());
1298 job
->setWorkingDirectory(url
.toLocalFile());
1303 // Not a local file, with protocol Class ":local", try stat'ing
1304 if (KProtocolInfo::protocolClass(url
.scheme()) == QLatin1String(":local")) {
1305 KIO::StatJob
*job
= KIO::mostLocalUrl(url
);
1306 KJobWidgets::setWindow(job
, this);
1307 connect(job
, &KJob::result
, this, [job
]() {
1309 if (!job
->error()) {
1310 statUrl
= job
->mostLocalUrl();
1313 auto job
= new KTerminalLauncherJob(QString());
1314 job
->setWorkingDirectory(statUrl
.isLocalFile() ? statUrl
.toLocalFile() : QDir::homePath());
1321 // Nothing worked, just use $HOME
1322 auto job
= new KTerminalLauncherJob(QString());
1323 job
->setWorkingDirectory(QDir::homePath());
1327 void DolphinMainWindow::editSettings()
1329 if (!m_settingsDialog
) {
1330 DolphinViewContainer
*container
= activeViewContainer();
1331 container
->view()->writeSettings();
1333 const QUrl url
= container
->url();
1334 DolphinSettingsDialog
*settingsDialog
= new DolphinSettingsDialog(url
, this, actionCollection());
1335 connect(settingsDialog
, &DolphinSettingsDialog::settingsChanged
, this, &DolphinMainWindow::refreshViews
);
1336 connect(settingsDialog
, &DolphinSettingsDialog::settingsChanged
, &DolphinUrlNavigatorsController::slotReadSettings
);
1337 settingsDialog
->setAttribute(Qt::WA_DeleteOnClose
);
1338 settingsDialog
->show();
1339 m_settingsDialog
= settingsDialog
;
1341 m_settingsDialog
.data()->raise();
1345 void DolphinMainWindow::handleUrl(const QUrl
&url
)
1347 delete m_lastHandleUrlOpenJob
;
1348 m_lastHandleUrlOpenJob
= nullptr;
1350 if (url
.isLocalFile() && QFileInfo(url
.toLocalFile()).isDir()) {
1351 activeViewContainer()->setUrl(url
);
1353 m_lastHandleUrlOpenJob
= new KIO::OpenUrlJob(url
);
1354 m_lastHandleUrlOpenJob
->setUiDelegate(KIO::createDefaultJobUiDelegate(KJobUiDelegate::AutoHandlingEnabled
, this));
1355 m_lastHandleUrlOpenJob
->setShowOpenOrExecuteDialog(true);
1357 connect(m_lastHandleUrlOpenJob
, &KIO::OpenUrlJob::mimeTypeFound
, this, [this, url
](const QString
&mimetype
) {
1358 if (mimetype
== QLatin1String("inode/directory")) {
1359 // If it's a dir, we'll take it from here
1360 m_lastHandleUrlOpenJob
->kill();
1361 m_lastHandleUrlOpenJob
= nullptr;
1362 activeViewContainer()->setUrl(url
);
1366 connect(m_lastHandleUrlOpenJob
, &KIO::OpenUrlJob::result
, this, [this]() {
1367 m_lastHandleUrlOpenJob
= nullptr;
1370 m_lastHandleUrlOpenJob
->start();
1374 void DolphinMainWindow::slotWriteStateChanged(bool isFolderWritable
)
1376 // trash:/ is writable but we don't want to create new items in it.
1377 // TODO: remove the trash check once https://phabricator.kde.org/T8234 is implemented
1378 newFileMenu()->setEnabled(isFolderWritable
&& m_activeViewContainer
->url().scheme() != QLatin1String("trash"));
1381 void DolphinMainWindow::openContextMenu(const QPoint
&pos
, const KFileItem
&item
, const KFileItemList
&selectedItems
, const QUrl
&url
)
1383 QPointer
<DolphinContextMenu
> contextMenu
= new DolphinContextMenu(this, item
, selectedItems
, url
, &m_fileItemActions
);
1384 contextMenu
->exec(pos
);
1386 // Delete the menu, unless it has been deleted in its own nested event loop already.
1388 contextMenu
->deleteLater();
1392 QMenu
*DolphinMainWindow::createPopupMenu()
1394 QMenu
*menu
= KXmlGuiWindow::createPopupMenu();
1396 menu
->addSeparator();
1397 menu
->addAction(actionCollection()->action(QStringLiteral("lock_panels")));
1402 void DolphinMainWindow::updateHamburgerMenu()
1404 KActionCollection
*ac
= actionCollection();
1405 auto hamburgerMenu
= static_cast<KHamburgerMenu
*>(ac
->action(KStandardAction::name(KStandardAction::HamburgerMenu
)));
1406 auto menu
= hamburgerMenu
->menu();
1408 menu
= new QMenu(this);
1409 hamburgerMenu
->setMenu(menu
);
1410 hamburgerMenu
->hideActionsOf(ac
->action(QStringLiteral("basic_actions"))->menu());
1411 hamburgerMenu
->hideActionsOf(ac
->action(QStringLiteral("zoom"))->menu());
1415 const QList
<QAction
*> toolbarActions
= toolBar()->actions();
1417 if (!toolBar()->isVisible()) {
1418 // If neither the menu bar nor the toolbar are visible, these actions should be available.
1419 menu
->addAction(ac
->action(KStandardAction::name(KStandardAction::ShowMenubar
)));
1420 menu
->addAction(toolBarMenuAction());
1421 menu
->addSeparator();
1424 // This group of actions (until the next separator) contains all the most basic actions
1425 // necessary to use Dolphin effectively.
1426 menu
->addAction(ac
->action(QStringLiteral("go_back")));
1427 menu
->addAction(ac
->action(QStringLiteral("go_forward")));
1429 menu
->addMenu(m_newFileMenu
->menu());
1430 if (!toolBar()->isVisible() || !toolbarActions
.contains(ac
->action(QStringLiteral("toggle_selection_mode_tool_bar")))) {
1431 menu
->addAction(ac
->action(QStringLiteral("toggle_selection_mode")));
1433 menu
->addAction(ac
->action(QStringLiteral("basic_actions")));
1434 menu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Undo
)));
1435 if (!toolBar()->isVisible()
1436 || (!toolbarActions
.contains(ac
->action(QStringLiteral("toggle_search")))
1437 && !toolbarActions
.contains(ac
->action(QStringLiteral("open_preferred_search_tool"))))) {
1438 menu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Find
)));
1439 // This way a search action will only be added if none of the three available
1440 // search actions is present on the toolbar.
1442 if (!toolBar()->isVisible() || !toolbarActions
.contains(ac
->action(QStringLiteral("toggle_filter")))) {
1443 menu
->addAction(ac
->action(QStringLiteral("show_filter_bar")));
1444 // This way a filter action will only be added if none of the two available
1445 // filter actions is present on the toolbar.
1447 menu
->addSeparator();
1449 // The second group of actions (up until the next separator) contains actions for opening
1450 // additional views to interact with the file system.
1451 menu
->addAction(ac
->action(QStringLiteral("file_new")));
1452 menu
->addAction(ac
->action(QStringLiteral("new_tab")));
1453 if (ac
->action(QStringLiteral("undo_close_tab"))->isEnabled()) {
1454 menu
->addAction(ac
->action(QStringLiteral("closed_tabs")));
1456 menu
->addAction(ac
->action(QStringLiteral("open_terminal")));
1457 menu
->addSeparator();
1459 // The third group contains actions to change what one sees in the view
1460 // and to change the more general UI.
1461 if (!toolBar()->isVisible()
1462 || (!toolbarActions
.contains(ac
->action(QStringLiteral("icons"))) && !toolbarActions
.contains(ac
->action(QStringLiteral("compact")))
1463 && !toolbarActions
.contains(ac
->action(QStringLiteral("details"))) && !toolbarActions
.contains(ac
->action(QStringLiteral("view_mode"))))) {
1464 menu
->addAction(ac
->action(QStringLiteral("view_mode")));
1466 menu
->addAction(ac
->action(QStringLiteral("show_hidden_files")));
1467 menu
->addAction(ac
->action(QStringLiteral("sort")));
1468 menu
->addAction(ac
->action(QStringLiteral("additional_info")));
1469 if (!GeneralSettings::showStatusBar() || !GeneralSettings::showZoomSlider()) {
1470 menu
->addAction(ac
->action(QStringLiteral("zoom")));
1472 menu
->addAction(ac
->action(QStringLiteral("panels")));
1474 // The "Configure" menu is not added to the actionCollection() because there is hardly
1475 // a good reason for users to put it on their toolbar.
1476 auto configureMenu
= menu
->addMenu(QIcon::fromTheme(QStringLiteral("configure")), i18nc("@action:inmenu menu for configure actions", "Configure"));
1477 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::SwitchApplicationLanguage
)));
1478 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::KeyBindings
)));
1479 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::ConfigureToolbars
)));
1480 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Preferences
)));
1481 hamburgerMenu
->hideActionsOf(configureMenu
);
1484 void DolphinMainWindow::slotPlaceActivated(const QUrl
&url
)
1486 DolphinViewContainer
*view
= activeViewContainer();
1488 if (view
->url() == url
) {
1489 view
->clearFilterBar(); // Fixes bug 259382.
1491 // We can end up here if the user clicked a device in the Places Panel
1492 // which had been unmounted earlier, see https://bugs.kde.org/show_bug.cgi?id=161385.
1495 view
->disableUrlNavigatorSelectionRequests();
1497 view
->enableUrlNavigatorSelectionRequests();
1501 void DolphinMainWindow::closedTabsCountChanged(unsigned int count
)
1503 actionCollection()->action(QStringLiteral("undo_close_tab"))->setEnabled(count
> 0);
1506 void DolphinMainWindow::activeViewChanged(DolphinViewContainer
*viewContainer
)
1508 DolphinViewContainer
*oldViewContainer
= m_activeViewContainer
;
1509 Q_ASSERT(viewContainer
);
1511 m_activeViewContainer
= viewContainer
;
1513 if (oldViewContainer
) {
1514 const QAction
*toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
1515 toggleSearchAction
->disconnect(oldViewContainer
);
1517 // Disconnect all signals between the old view container (container,
1518 // view and url navigator) and main window.
1519 oldViewContainer
->disconnect(this);
1520 oldViewContainer
->view()->disconnect(this);
1521 oldViewContainer
->urlNavigatorInternalWithHistory()->disconnect(this);
1522 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>(actionCollection()->action(QStringLiteral("url_navigators")));
1523 navigators
->primaryUrlNavigator()->disconnect(this);
1524 if (auto secondaryUrlNavigator
= navigators
->secondaryUrlNavigator()) {
1525 secondaryUrlNavigator
->disconnect(this);
1528 // except the requestItemInfo so that on hover the information panel can still be updated
1529 connect(oldViewContainer
->view(), &DolphinView::requestItemInfo
, this, &DolphinMainWindow::requestItemInfo
);
1531 // Disconnect other slots.
1532 disconnect(oldViewContainer
,
1533 &DolphinViewContainer::selectionModeChanged
,
1534 actionCollection()->action(QStringLiteral("toggle_selection_mode")),
1535 &QAction::setChecked
);
1538 connectViewSignals(viewContainer
);
1540 m_actionHandler
->setCurrentView(viewContainer
->view());
1543 updateFileAndEditActions();
1544 updatePasteAction();
1545 updateViewActions();
1547 updateSearchAction();
1549 const QUrl url
= viewContainer
->url();
1550 Q_EMIT
urlChanged(url
);
1553 void DolphinMainWindow::tabCountChanged(int count
)
1555 const bool enableTabActions
= (count
> 1);
1556 for (int i
= 0; i
< MaxActivateTabShortcuts
; ++i
) {
1557 actionCollection()->action(QStringLiteral("activate_tab_%1").arg(i
))->setEnabled(enableTabActions
);
1559 actionCollection()->action(QStringLiteral("activate_last_tab"))->setEnabled(enableTabActions
);
1560 actionCollection()->action(QStringLiteral("activate_next_tab"))->setEnabled(enableTabActions
);
1561 actionCollection()->action(QStringLiteral("activate_prev_tab"))->setEnabled(enableTabActions
);
1564 void DolphinMainWindow::updateWindowTitle()
1566 const QString newTitle
= m_activeViewContainer
->captionWindowTitle();
1567 if (windowTitle() != newTitle
) {
1568 setWindowTitle(newTitle
);
1572 void DolphinMainWindow::slotStorageTearDownFromPlacesRequested(const QString
&mountPath
)
1574 connect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, this, [this, mountPath
]() {
1575 setViewsToHomeIfMountPathOpen(mountPath
);
1578 if (m_terminalPanel
&& m_terminalPanel
->currentWorkingDirectoryIsChildOf(mountPath
)) {
1579 m_tearDownFromPlacesRequested
= true;
1580 m_terminalPanel
->goHome();
1581 // m_placesPanel->proceedWithTearDown() will be called in slotTerminalDirectoryChanged
1583 m_placesPanel
->proceedWithTearDown();
1587 void DolphinMainWindow::slotStorageTearDownExternallyRequested(const QString
&mountPath
)
1589 connect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, this, [this, mountPath
]() {
1590 setViewsToHomeIfMountPathOpen(mountPath
);
1593 if (m_terminalPanel
&& m_terminalPanel
->currentWorkingDirectoryIsChildOf(mountPath
)) {
1594 m_tearDownFromPlacesRequested
= false;
1595 m_terminalPanel
->goHome();
1599 void DolphinMainWindow::slotKeyBindings()
1601 KShortcutsDialog
dialog(KShortcutsEditor::AllActions
, KShortcutsEditor::LetterShortcutsAllowed
, this);
1602 dialog
.addCollection(actionCollection());
1603 if (m_terminalPanel
) {
1604 KActionCollection
*konsolePartActionCollection
= m_terminalPanel
->actionCollection();
1605 if (konsolePartActionCollection
) {
1606 dialog
.addCollection(konsolePartActionCollection
, QStringLiteral("KonsolePart"));
1612 void DolphinMainWindow::setViewsToHomeIfMountPathOpen(const QString
&mountPath
)
1614 const QVector
<DolphinViewContainer
*> theViewContainers
= viewContainers();
1615 for (DolphinViewContainer
*viewContainer
: theViewContainers
) {
1616 if (viewContainer
&& viewContainer
->url().toLocalFile().startsWith(mountPath
)) {
1617 viewContainer
->setUrl(QUrl::fromLocalFile(QDir::homePath()));
1620 disconnect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, nullptr, nullptr);
1623 void DolphinMainWindow::setupActions()
1625 auto hamburgerMenuAction
= KStandardAction::hamburgerMenu(nullptr, nullptr, actionCollection());
1627 // setup 'File' menu
1628 m_newFileMenu
= new DolphinNewFileMenu(nullptr, this);
1629 actionCollection()->addAction(QStringLiteral("new_menu"), m_newFileMenu
);
1630 QMenu
*menu
= m_newFileMenu
->menu();
1631 menu
->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1632 menu
->setIcon(QIcon::fromTheme(QStringLiteral("list-add")));
1633 m_newFileMenu
->setPopupMode(QToolButton::InstantPopup
);
1634 connect(menu
, &QMenu::aboutToShow
, this, &DolphinMainWindow::updateNewMenu
);
1636 QAction
*newWindow
= KStandardAction::openNew(this, &DolphinMainWindow::openNewMainWindow
, actionCollection());
1637 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
1638 newWindow
->setToolTip(i18nc("@info", "Open a new Dolphin window"));
1639 newWindow
->setWhatsThis(xi18nc("@info:whatsthis",
1641 "window just like this one with the current location and view."
1642 "<nl/>You can drag and drop items between windows."));
1643 newWindow
->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
1645 QAction
*newTab
= actionCollection()->addAction(QStringLiteral("new_tab"));
1646 newTab
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1647 newTab
->setText(i18nc("@action:inmenu File", "New Tab"));
1648 newTab
->setWhatsThis(xi18nc("@info:whatsthis",
1650 "<emphasis>Tab</emphasis> with the current location and view.<nl/>"
1651 "A tab is an additional view within this window. "
1652 "You can drag and drop items between tabs."));
1653 actionCollection()->setDefaultShortcut(newTab
, Qt::CTRL
| Qt::Key_T
);
1654 connect(newTab
, &QAction::triggered
, this, &DolphinMainWindow::openNewActivatedTab
);
1656 QAction
*addToPlaces
= actionCollection()->addAction(QStringLiteral("add_to_places"));
1657 addToPlaces
->setIcon(QIcon::fromTheme(QStringLiteral("bookmark-new")));
1658 addToPlaces
->setText(i18nc("@action:inmenu Add current folder to places", "Add to Places"));
1659 addToPlaces
->setWhatsThis(xi18nc("@info:whatsthis",
1660 "This adds the selected folder "
1661 "to the Places panel."));
1662 connect(addToPlaces
, &QAction::triggered
, this, &DolphinMainWindow::addToPlaces
);
1664 QAction
*closeTab
= KStandardAction::close(m_tabWidget
, QOverload
<>::of(&DolphinTabWidget::closeTab
), actionCollection());
1665 closeTab
->setText(i18nc("@action:inmenu File", "Close Tab"));
1666 closeTab
->setWhatsThis(i18nc("@info:whatsthis",
1668 "currently viewed tab. If no more tabs are left this window "
1669 "will close instead."));
1671 QAction
*quitAction
= KStandardAction::quit(this, &DolphinMainWindow::quit
, actionCollection());
1672 quitAction
->setWhatsThis(i18nc("@info:whatsthis quit", "This closes this window."));
1674 // setup 'Edit' menu
1675 KStandardAction::undo(this, &DolphinMainWindow::undo
, actionCollection());
1677 // i18n: This will be the last paragraph for the whatsthis for all three:
1678 // Cut, Copy and Paste
1679 const QString cutCopyPastePara
= xi18nc("@info:whatsthis",
1680 "<para><emphasis>Cut, "
1681 "Copy</emphasis> and <emphasis>Paste</emphasis> work between many "
1682 "applications and are among the most used commands. That's why their "
1683 "<emphasis>keyboard shortcuts</emphasis> are prominently placed right "
1684 "next to each other on the keyboard: <shortcut>Ctrl+X</shortcut>, "
1685 "<shortcut>Ctrl+C</shortcut> and <shortcut>Ctrl+V</shortcut>.</para>");
1686 QAction
*cutAction
= KStandardAction::cut(this, &DolphinMainWindow::cut
, actionCollection());
1687 m_actionTextHelper
->registerTextWhenNothingIsSelected(cutAction
, i18nc("@action", "Cut…"));
1688 cutAction
->setWhatsThis(xi18nc("@info:whatsthis cut",
1689 "This copies the items "
1690 "in your current selection to the <emphasis>clipboard</emphasis>.<nl/>"
1691 "Use the <emphasis>Paste</emphasis> action afterwards to copy them from "
1692 "the clipboard to a new location. The items will be removed from their "
1693 "initial location.")
1694 + cutCopyPastePara
);
1695 QAction
*copyAction
= KStandardAction::copy(this, &DolphinMainWindow::copy
, actionCollection());
1696 m_actionTextHelper
->registerTextWhenNothingIsSelected(copyAction
, i18nc("@action", "Copy…"));
1697 copyAction
->setWhatsThis(xi18nc("@info:whatsthis copy",
1699 "items in your current selection to the <emphasis>clipboard</emphasis>."
1700 "<nl/>Use the <emphasis>Paste</emphasis> action afterwards to copy them "
1701 "from the clipboard to a new location.")
1702 + cutCopyPastePara
);
1703 QAction
*paste
= KStandardAction::paste(this, &DolphinMainWindow::paste
, actionCollection());
1704 // The text of the paste-action is modified dynamically by Dolphin
1705 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1706 // due to the long text, the text "Paste" is used:
1707 paste
->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1708 paste
->setWhatsThis(xi18nc("@info:whatsthis paste",
1709 "This copies the items from "
1710 "your <emphasis>clipboard</emphasis> to the currently viewed folder.<nl/>"
1711 "If the items were added to the clipboard by the <emphasis>Cut</emphasis> "
1712 "action they are removed from their old location.")
1713 + cutCopyPastePara
);
1715 QAction
*copyToOtherViewAction
= actionCollection()->addAction(QStringLiteral("copy_to_inactive_split_view"));
1716 copyToOtherViewAction
->setText(i18nc("@action:inmenu", "Copy to Other View"));
1717 m_actionTextHelper
->registerTextWhenNothingIsSelected(copyToOtherViewAction
, i18nc("@action:inmenu", "Copy to Other View…"));
1718 copyToOtherViewAction
->setWhatsThis(xi18nc("@info:whatsthis Copy",
1719 "This copies the selected items from "
1720 "the <emphasis>active</emphasis> view to the inactive split view."));
1721 copyToOtherViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("edit-copy")));
1722 copyToOtherViewAction
->setIconText(i18nc("@action:inmenu Edit", "Copy to Inactive Split View"));
1723 actionCollection()->setDefaultShortcut(copyToOtherViewAction
, Qt::SHIFT
| Qt::Key_F5
);
1724 connect(copyToOtherViewAction
, &QAction::triggered
, this, &DolphinMainWindow::copyToInactiveSplitView
);
1726 QAction
*moveToOtherViewAction
= actionCollection()->addAction(QStringLiteral("move_to_inactive_split_view"));
1727 moveToOtherViewAction
->setText(i18nc("@action:inmenu", "Move to Other View"));
1728 m_actionTextHelper
->registerTextWhenNothingIsSelected(moveToOtherViewAction
, i18nc("@action:inmenu", "Move to Other View…"));
1729 moveToOtherViewAction
->setWhatsThis(xi18nc("@info:whatsthis Move",
1730 "This moves the selected items from "
1731 "the <emphasis>active</emphasis> view to the inactive split view."));
1732 moveToOtherViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("edit-cut")));
1733 moveToOtherViewAction
->setIconText(i18nc("@action:inmenu Edit", "Move to Inactive Split View"));
1734 actionCollection()->setDefaultShortcut(moveToOtherViewAction
, Qt::SHIFT
| Qt::Key_F6
);
1735 connect(moveToOtherViewAction
, &QAction::triggered
, this, &DolphinMainWindow::moveToInactiveSplitView
);
1737 QAction
*showFilterBar
= actionCollection()->addAction(QStringLiteral("show_filter_bar"));
1738 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Filter…"));
1739 showFilterBar
->setToolTip(i18nc("@info:tooltip", "Show Filter Bar"));
1740 showFilterBar
->setWhatsThis(xi18nc("@info:whatsthis",
1742 "<emphasis>Filter Bar</emphasis> at the bottom of the window.<nl/> "
1743 "There you can enter a text to filter the files and folders currently displayed. "
1744 "Only those that contain the text in their name will be kept in view."));
1745 showFilterBar
->setIcon(QIcon::fromTheme(QStringLiteral("view-filter")));
1746 actionCollection()->setDefaultShortcuts(showFilterBar
, {Qt::CTRL
| Qt::Key_I
, Qt::Key_Slash
});
1747 connect(showFilterBar
, &QAction::triggered
, this, &DolphinMainWindow::showFilterBar
);
1749 // toggle_filter acts as a copy of the main showFilterBar to be used mainly
1750 // in the toolbar, with no default shortcut attached, to avoid messing with
1751 // existing workflows (filter bar always open and Ctrl-I to focus)
1752 QAction
*toggleFilter
= actionCollection()->addAction(QStringLiteral("toggle_filter"));
1753 toggleFilter
->setText(i18nc("@action:inmenu", "Toggle Filter Bar"));
1754 toggleFilter
->setIconText(i18nc("@action:intoolbar", "Filter"));
1755 toggleFilter
->setIcon(showFilterBar
->icon());
1756 toggleFilter
->setToolTip(showFilterBar
->toolTip());
1757 toggleFilter
->setWhatsThis(showFilterBar
->whatsThis());
1758 toggleFilter
->setCheckable(true);
1759 connect(toggleFilter
, &QAction::triggered
, this, &DolphinMainWindow::toggleFilterBar
);
1761 QAction
*searchAction
= KStandardAction::find(this, &DolphinMainWindow::find
, actionCollection());
1762 searchAction
->setText(i18n("Search…"));
1763 searchAction
->setToolTip(i18nc("@info:tooltip", "Search for files and folders"));
1764 searchAction
->setWhatsThis(xi18nc("@info:whatsthis find",
1765 "<para>This helps you "
1766 "find files and folders by opening a <emphasis>find bar</emphasis>. "
1767 "There you can enter search terms and specify settings to find the "
1768 "objects you are looking for.</para><para>Use this help again on "
1769 "the find bar so we can have a look at it while the settings are "
1770 "explained.</para>"));
1772 // toggle_search acts as a copy of the main searchAction to be used mainly
1773 // in the toolbar, with no default shortcut attached, to avoid messing with
1774 // existing workflows (search bar always open and Ctrl-F to focus)
1775 QAction
*toggleSearchAction
= actionCollection()->addAction(QStringLiteral("toggle_search"));
1776 toggleSearchAction
->setText(i18nc("@action:inmenu", "Toggle Search Bar"));
1777 toggleSearchAction
->setIconText(i18nc("@action:intoolbar", "Search"));
1778 toggleSearchAction
->setIcon(searchAction
->icon());
1779 toggleSearchAction
->setToolTip(searchAction
->toolTip());
1780 toggleSearchAction
->setWhatsThis(searchAction
->whatsThis());
1781 toggleSearchAction
->setCheckable(true);
1783 QAction
*toggleSelectionModeAction
= actionCollection()->addAction(QStringLiteral("toggle_selection_mode"));
1784 // i18n: This action toggles a selection mode.
1785 toggleSelectionModeAction
->setText(i18nc("@action:inmenu", "Select Files and Folders"));
1786 // i18n: Opens a selection mode for selecting files/folders.
1787 // The text is kept so unspecific because it will be shown on the toolbar where space is at a premium.
1788 toggleSelectionModeAction
->setIconText(i18nc("@action:intoolbar", "Select"));
1789 toggleSelectionModeAction
->setWhatsThis(xi18nc(
1791 "<para>This application only knows which files or folders should be acted on if they are"
1792 " <emphasis>selected</emphasis> first. Press this to toggle a <emphasis>Selection Mode</emphasis> which makes selecting and deselecting as easy as "
1793 "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."
1795 toggleSelectionModeAction
->setIcon(QIcon::fromTheme(QStringLiteral("quickwizard")));
1796 toggleSelectionModeAction
->setCheckable(true);
1797 actionCollection()->setDefaultShortcut(toggleSelectionModeAction
, Qt::Key_Space
);
1798 connect(toggleSelectionModeAction
, &QAction::triggered
, this, &DolphinMainWindow::toggleSelectionMode
);
1800 // A special version of the toggleSelectionModeAction for the toolbar that also contains a menu
1801 // with the selectAllAction and invertSelectionAction.
1802 auto *toggleSelectionModeToolBarAction
=
1803 new KToolBarPopupAction(toggleSelectionModeAction
->icon(), toggleSelectionModeAction
->iconText(), actionCollection());
1804 toggleSelectionModeToolBarAction
->setToolTip(toggleSelectionModeAction
->text());
1805 toggleSelectionModeToolBarAction
->setWhatsThis(toggleSelectionModeAction
->whatsThis());
1806 actionCollection()->addAction(QStringLiteral("toggle_selection_mode_tool_bar"), toggleSelectionModeToolBarAction
);
1807 toggleSelectionModeToolBarAction
->setCheckable(true);
1808 toggleSelectionModeToolBarAction
->setPopupMode(KToolBarPopupAction::DelayedPopup
);
1809 connect(toggleSelectionModeToolBarAction
, &QAction::triggered
, toggleSelectionModeAction
, &QAction::trigger
);
1810 connect(toggleSelectionModeAction
, &QAction::toggled
, toggleSelectionModeToolBarAction
, &QAction::setChecked
);
1812 QAction
*selectAllAction
= KStandardAction::selectAll(this, &DolphinMainWindow::selectAll
, actionCollection());
1813 selectAllAction
->setWhatsThis(xi18nc("@info:whatsthis",
1815 "files and folders in the current location."));
1817 QAction
*invertSelection
= actionCollection()->addAction(QStringLiteral("invert_selection"));
1818 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1819 invertSelection
->setWhatsThis(xi18nc("@info:whatsthis invert",
1821 "objects that you have currently <emphasis>not</emphasis> selected instead."));
1822 invertSelection
->setIcon(QIcon::fromTheme(QStringLiteral("edit-select-invert")));
1823 actionCollection()->setDefaultShortcut(invertSelection
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
1824 connect(invertSelection
, &QAction::triggered
, this, &DolphinMainWindow::invertSelection
);
1826 QMenu
*toggleSelectionModeActionMenu
= new QMenu(this);
1827 toggleSelectionModeActionMenu
->addAction(selectAllAction
);
1828 toggleSelectionModeActionMenu
->addAction(invertSelection
);
1829 toggleSelectionModeToolBarAction
->setMenu(toggleSelectionModeActionMenu
);
1831 // setup 'View' menu
1832 // (note that most of it is set up in DolphinViewActionHandler)
1834 m_splitViewAction
= actionCollection()->add
<KActionMenu
>(QStringLiteral("split_view"));
1835 m_splitViewAction
->setWhatsThis(xi18nc("@info:whatsthis find",
1836 "<para>This splits "
1837 "the folder view below into two autonomous views.</para><para>This "
1838 "way you can see two locations at once and move items between them "
1839 "quickly.</para>Click this again afterwards to recombine the views."));
1840 m_splitViewAction
->setPopupMode(QToolButton::MenuButtonPopup
);
1841 actionCollection()->setDefaultShortcut(m_splitViewAction
, Qt::Key_F3
);
1842 connect(m_splitViewAction
, &QAction::triggered
, this, &DolphinMainWindow::toggleSplitView
);
1844 QAction
*popoutSplit
= actionCollection()->addAction(QStringLiteral("popout_split_view"));
1845 popoutSplit
->setWhatsThis(xi18nc("@info:whatsthis",
1846 "If the folder view has been split, this will pop the active folder "
1847 "view out into a new window."));
1848 popoutSplit
->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
1849 actionCollection()->setDefaultShortcut(popoutSplit
, Qt::SHIFT
| Qt::Key_F3
);
1850 m_splitViewAction
->addAction(popoutSplit
);
1851 connect(popoutSplit
, &QAction::triggered
, this, &DolphinMainWindow::popoutSplitView
);
1853 QAction
*stashSplit
= actionCollection()->addAction(QStringLiteral("split_stash"));
1854 actionCollection()->setDefaultShortcut(stashSplit
, Qt::CTRL
| Qt::Key_S
);
1855 stashSplit
->setText(i18nc("@action:intoolbar Stash", "Stash"));
1856 stashSplit
->setToolTip(i18nc("@info", "Opens the stash virtual directory in a split window"));
1857 stashSplit
->setIcon(QIcon::fromTheme(QStringLiteral("folder-stash")));
1858 stashSplit
->setCheckable(false);
1859 QDBusConnectionInterface
*sessionInterface
= QDBusConnection::sessionBus().interface();
1860 stashSplit
->setVisible(sessionInterface
&& sessionInterface
->isServiceRegistered(QStringLiteral("org.kde.kio.StashNotifier")));
1861 connect(stashSplit
, &QAction::triggered
, this, &DolphinMainWindow::toggleSplitStash
);
1863 QAction
*redisplay
= KStandardAction::redisplay(this, &DolphinMainWindow::reloadView
, actionCollection());
1864 redisplay
->setToolTip(i18nc("@info:tooltip", "Refresh view"));
1865 redisplay
->setWhatsThis(xi18nc("@info:whatsthis refresh",
1866 "<para>This refreshes "
1867 "the folder view.</para>"
1868 "<para>If the contents of this folder have changed, refreshing will re-scan this folder "
1869 "and show you a newly-updated view of the files and folders contained here.</para>"
1870 "<para>If the view is split, this refreshes the one that is currently in focus.</para>"));
1872 QAction
*stop
= actionCollection()->addAction(QStringLiteral("stop"));
1873 stop
->setText(i18nc("@action:inmenu View", "Stop"));
1874 stop
->setToolTip(i18nc("@info", "Stop loading"));
1875 stop
->setWhatsThis(i18nc("@info", "This stops the loading of the contents of the current folder."));
1876 stop
->setIcon(QIcon::fromTheme(QStringLiteral("process-stop")));
1877 connect(stop
, &QAction::triggered
, this, &DolphinMainWindow::stopLoading
);
1879 KToggleAction
*editableLocation
= actionCollection()->add
<KToggleAction
>(QStringLiteral("editable_location"));
1880 editableLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1881 editableLocation
->setWhatsThis(xi18nc("@info:whatsthis",
1882 "This toggles the <emphasis>Location Bar</emphasis> to be "
1883 "editable so you can directly enter a location you want to go to.<nl/>"
1884 "You can also switch to editing by clicking to the right of the "
1885 "location and switch back by confirming the edited location."));
1886 actionCollection()->setDefaultShortcut(editableLocation
, Qt::Key_F6
);
1887 connect(editableLocation
, &KToggleAction::triggered
, this, &DolphinMainWindow::toggleEditLocation
);
1889 QAction
*replaceLocation
= actionCollection()->addAction(QStringLiteral("replace_location"));
1890 replaceLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1891 // i18n: "enter" is used both in the meaning of "writing" and "going to" a new location here.
1892 // Both meanings are useful but not necessary to understand the use of "Replace Location".
1893 // So you might want to be more verbose in your language to convey the meaning but it's up to you.
1894 replaceLocation
->setWhatsThis(xi18nc("@info:whatsthis",
1895 "This switches to editing the location and selects it "
1896 "so you can quickly enter a different location."));
1897 actionCollection()->setDefaultShortcuts(replaceLocation
, {Qt::CTRL
| Qt::Key_L
, Qt::ALT
| Qt::Key_D
});
1898 connect(replaceLocation
, &QAction::triggered
, this, &DolphinMainWindow::replaceLocation
);
1902 QScopedPointer
<QAction
> backAction(KStandardAction::back(nullptr, nullptr, nullptr));
1903 m_backAction
= new KToolBarPopupAction(backAction
->icon(), backAction
->text(), actionCollection());
1904 m_backAction
->setObjectName(backAction
->objectName());
1905 m_backAction
->setShortcuts(backAction
->shortcuts());
1907 m_backAction
->setPopupMode(KToolBarPopupAction::DelayedPopup
);
1908 connect(m_backAction
, &QAction::triggered
, this, &DolphinMainWindow::goBack
);
1909 connect(m_backAction
->popupMenu(), &QMenu::aboutToShow
, this, &DolphinMainWindow::slotAboutToShowBackPopupMenu
);
1910 connect(m_backAction
->popupMenu(), &QMenu::triggered
, this, &DolphinMainWindow::slotGoBack
);
1911 actionCollection()->addAction(m_backAction
->objectName(), m_backAction
);
1913 auto backShortcuts
= m_backAction
->shortcuts();
1914 // Prepend this shortcut, to avoid being hidden by the two-slot UI (#371130)
1915 backShortcuts
.prepend(QKeySequence(Qt::Key_Backspace
));
1916 actionCollection()->setDefaultShortcuts(m_backAction
, backShortcuts
);
1918 DolphinRecentTabsMenu
*recentTabsMenu
= new DolphinRecentTabsMenu(this);
1919 actionCollection()->addAction(QStringLiteral("closed_tabs"), recentTabsMenu
);
1920 connect(m_tabWidget
, &DolphinTabWidget::rememberClosedTab
, recentTabsMenu
, &DolphinRecentTabsMenu::rememberClosedTab
);
1921 connect(recentTabsMenu
, &DolphinRecentTabsMenu::restoreClosedTab
, m_tabWidget
, &DolphinTabWidget::restoreClosedTab
);
1922 connect(recentTabsMenu
, &DolphinRecentTabsMenu::closedTabsCountChanged
, this, &DolphinMainWindow::closedTabsCountChanged
);
1924 QAction
*undoCloseTab
= actionCollection()->addAction(QStringLiteral("undo_close_tab"));
1925 undoCloseTab
->setText(i18nc("@action:inmenu File", "Undo close tab"));
1926 undoCloseTab
->setWhatsThis(i18nc("@info:whatsthis undo close tab", "This returns you to the previously closed tab."));
1927 actionCollection()->setDefaultShortcut(undoCloseTab
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_T
);
1928 undoCloseTab
->setIcon(QIcon::fromTheme(QStringLiteral("edit-undo")));
1929 undoCloseTab
->setEnabled(false);
1930 connect(undoCloseTab
, &QAction::triggered
, recentTabsMenu
, &DolphinRecentTabsMenu::undoCloseTab
);
1932 auto undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
1933 undoAction
->setWhatsThis(xi18nc("@info:whatsthis",
1935 "the last change you made to files or folders.<nl/>"
1936 "Such changes include <interface>creating, renaming</interface> "
1937 "and <interface>moving</interface> them to a different location "
1938 "or to the <filename>Trash</filename>. <nl/>Changes that can't "
1939 "be undone will ask for your confirmation."));
1940 undoAction
->setEnabled(false); // undo should be disabled by default
1943 QScopedPointer
<QAction
> forwardAction(KStandardAction::forward(nullptr, nullptr, nullptr));
1944 m_forwardAction
= new KToolBarPopupAction(forwardAction
->icon(), forwardAction
->text(), actionCollection());
1945 m_forwardAction
->setObjectName(forwardAction
->objectName());
1946 m_forwardAction
->setShortcuts(forwardAction
->shortcuts());
1948 m_forwardAction
->setPopupMode(KToolBarPopupAction::DelayedPopup
);
1949 connect(m_forwardAction
, &QAction::triggered
, this, &DolphinMainWindow::goForward
);
1950 connect(m_forwardAction
->popupMenu(), &QMenu::aboutToShow
, this, &DolphinMainWindow::slotAboutToShowForwardPopupMenu
);
1951 connect(m_forwardAction
->popupMenu(), &QMenu::triggered
, this, &DolphinMainWindow::slotGoForward
);
1952 actionCollection()->addAction(m_forwardAction
->objectName(), m_forwardAction
);
1953 actionCollection()->setDefaultShortcuts(m_forwardAction
, m_forwardAction
->shortcuts());
1955 // enable middle-click to open in a new tab
1956 auto *middleClickEventFilter
= new MiddleClickActionEventFilter(this);
1957 connect(middleClickEventFilter
, &MiddleClickActionEventFilter::actionMiddleClicked
, this, &DolphinMainWindow::slotBackForwardActionMiddleClicked
);
1958 m_backAction
->popupMenu()->installEventFilter(middleClickEventFilter
);
1959 m_forwardAction
->popupMenu()->installEventFilter(middleClickEventFilter
);
1960 KStandardAction::up(this, &DolphinMainWindow::goUp
, actionCollection());
1961 QAction
*homeAction
= KStandardAction::home(this, &DolphinMainWindow::goHome
, actionCollection());
1962 homeAction
->setWhatsThis(xi18nc("@info:whatsthis",
1964 "<filename>Home</filename> folder.<nl/>Every user account "
1965 "has their own <filename>Home</filename> that contains their data "
1966 "including folders that contain personal application data."));
1968 // setup 'Tools' menu
1969 QAction
*compareFiles
= actionCollection()->addAction(QStringLiteral("compare_files"));
1970 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1971 compareFiles
->setIcon(QIcon::fromTheme(QStringLiteral("kompare")));
1972 compareFiles
->setEnabled(false);
1973 connect(compareFiles
, &QAction::triggered
, this, &DolphinMainWindow::compareFiles
);
1975 QAction
*openPreferredSearchTool
= actionCollection()->addAction(QStringLiteral("open_preferred_search_tool"));
1976 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool"));
1977 openPreferredSearchTool
->setWhatsThis(xi18nc("@info:whatsthis",
1978 "<para>This opens a preferred search tool for the viewed location.</para>"
1979 "<para>Use <emphasis>More Search Tools</emphasis> menu to configure it.</para>"));
1980 openPreferredSearchTool
->setIcon(QIcon::fromTheme(QStringLiteral("search")));
1981 actionCollection()->setDefaultShortcut(openPreferredSearchTool
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_F
);
1982 connect(openPreferredSearchTool
, &QAction::triggered
, this, &DolphinMainWindow::openPreferredSearchTool
);
1984 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
1985 QAction
*openTerminal
= actionCollection()->addAction(QStringLiteral("open_terminal"));
1986 openTerminal
->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
1987 openTerminal
->setWhatsThis(xi18nc("@info:whatsthis",
1988 "<para>This opens a <emphasis>terminal</emphasis> application for the viewed location.</para>"
1989 "<para>To learn more about terminals use the help in the terminal application.</para>"));
1990 openTerminal
->setIcon(QIcon::fromTheme(QStringLiteral("utilities-terminal")));
1991 actionCollection()->setDefaultShortcut(openTerminal
, Qt::SHIFT
| Qt::Key_F4
);
1992 connect(openTerminal
, &QAction::triggered
, this, &DolphinMainWindow::openTerminal
);
1994 QAction
*openTerminalHere
= actionCollection()->addAction(QStringLiteral("open_terminal_here"));
1995 // i18n: "Here" refers to the location(s) of the currently selected item(s) or the currently viewed location if nothing is selected.
1996 openTerminalHere
->setText(i18nc("@action:inmenu Tools", "Open Terminal Here"));
1997 openTerminalHere
->setWhatsThis(xi18nc("@info:whatsthis",
1998 "<para>This opens <emphasis>terminal</emphasis> applications for the selected items' locations.</para>"
1999 "<para>To learn more about terminals use the help in the terminal application.</para>"));
2000 openTerminalHere
->setIcon(QIcon::fromTheme(QStringLiteral("utilities-terminal")));
2001 actionCollection()->setDefaultShortcut(openTerminalHere
, Qt::SHIFT
| Qt::ALT
| Qt::Key_F4
);
2002 connect(openTerminalHere
, &QAction::triggered
, this, &DolphinMainWindow::openTerminalHere
);
2005 QAction
*focusTerminalPanel
= actionCollection()->addAction(QStringLiteral("focus_terminal_panel"));
2006 focusTerminalPanel
->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
2007 focusTerminalPanel
->setIcon(QIcon::fromTheme(QStringLiteral("swap-panels")));
2008 actionCollection()->setDefaultShortcut(focusTerminalPanel
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_F4
);
2009 connect(focusTerminalPanel
, &QAction::triggered
, this, &DolphinMainWindow::focusTerminalPanel
);
2013 // setup 'Bookmarks' menu
2014 KActionMenu
*bookmarkMenu
= new KActionMenu(i18nc("@title:menu", "&Bookmarks"), this);
2015 bookmarkMenu
->setIcon(QIcon::fromTheme(QStringLiteral("bookmarks")));
2016 // Make the toolbar button version work properly on click
2017 bookmarkMenu
->setPopupMode(QToolButton::InstantPopup
);
2018 m_bookmarkHandler
= new DolphinBookmarkHandler(this, actionCollection(), bookmarkMenu
->menu(), this);
2019 actionCollection()->addAction(QStringLiteral("bookmarks"), bookmarkMenu
);
2021 // setup 'Settings' menu
2022 KToggleAction
*showMenuBar
= KStandardAction::showMenubar(nullptr, nullptr, actionCollection());
2023 showMenuBar
->setWhatsThis(xi18nc("@info:whatsthis",
2024 "<para>This switches between having a <emphasis>Menubar</emphasis> "
2025 "and having a <interface>%1</interface> button. Both "
2026 "contain mostly the same actions and configuration options.</para>"
2027 "<para>The Menubar takes up more space but allows for fast and organised access to all "
2028 "actions an application has to offer.</para><para>The <interface>%1</interface> button "
2029 "is simpler and small which makes triggering advanced actions more time consuming.</para>",
2030 hamburgerMenuAction
->text().replace('&', "")));
2031 connect(showMenuBar
,
2032 &KToggleAction::triggered
, // Fixes #286822
2034 &DolphinMainWindow::toggleShowMenuBar
,
2035 Qt::QueuedConnection
);
2037 KToggleAction
*showStatusBar
= KStandardAction::showStatusbar(nullptr, nullptr, actionCollection());
2038 showStatusBar
->setChecked(GeneralSettings::showStatusBar());
2039 connect(GeneralSettings::self(), &GeneralSettings::showStatusBarChanged
, showStatusBar
, &KToggleAction::setChecked
);
2040 connect(showStatusBar
, &KToggleAction::triggered
, this, [this](bool checked
) {
2041 GeneralSettings::setShowStatusBar(checked
);
2045 KStandardAction::keyBindings(this, &DolphinMainWindow::slotKeyBindings
, actionCollection());
2046 KStandardAction::preferences(this, &DolphinMainWindow::editSettings
, actionCollection());
2048 // not in menu actions
2049 QList
<QKeySequence
> nextTabKeys
= KStandardShortcut::tabNext();
2050 nextTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::Key_Tab
));
2052 QList
<QKeySequence
> prevTabKeys
= KStandardShortcut::tabPrev();
2053 prevTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::SHIFT
| Qt::Key_Tab
));
2055 for (int i
= 0; i
< MaxActivateTabShortcuts
; ++i
) {
2056 QAction
*activateTab
= actionCollection()->addAction(QStringLiteral("activate_tab_%1").arg(i
));
2057 activateTab
->setText(i18nc("@action:inmenu", "Activate Tab %1", i
+ 1));
2058 activateTab
->setEnabled(false);
2059 connect(activateTab
, &QAction::triggered
, this, [this, i
]() {
2060 m_tabWidget
->activateTab(i
);
2063 // only add default shortcuts for the first 9 tabs regardless of MaxActivateTabShortcuts
2065 actionCollection()->setDefaultShortcut(activateTab
, QStringLiteral("Alt+%1").arg(i
+ 1));
2069 QAction
*activateLastTab
= actionCollection()->addAction(QStringLiteral("activate_last_tab"));
2070 activateLastTab
->setText(i18nc("@action:inmenu", "Activate Last Tab"));
2071 activateLastTab
->setEnabled(false);
2072 connect(activateLastTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activateLastTab
);
2073 actionCollection()->setDefaultShortcut(activateLastTab
, Qt::ALT
| Qt::Key_0
);
2075 QAction
*activateNextTab
= actionCollection()->addAction(QStringLiteral("activate_next_tab"));
2076 activateNextTab
->setIconText(i18nc("@action:inmenu", "Next Tab"));
2077 activateNextTab
->setText(i18nc("@action:inmenu", "Activate Next Tab"));
2078 activateNextTab
->setEnabled(false);
2079 connect(activateNextTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activateNextTab
);
2080 actionCollection()->setDefaultShortcuts(activateNextTab
, nextTabKeys
);
2082 QAction
*activatePrevTab
= actionCollection()->addAction(QStringLiteral("activate_prev_tab"));
2083 activatePrevTab
->setIconText(i18nc("@action:inmenu", "Previous Tab"));
2084 activatePrevTab
->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
2085 activatePrevTab
->setEnabled(false);
2086 connect(activatePrevTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activatePrevTab
);
2087 actionCollection()->setDefaultShortcuts(activatePrevTab
, prevTabKeys
);
2090 QAction
*showTarget
= actionCollection()->addAction(QStringLiteral("show_target"));
2091 showTarget
->setText(i18nc("@action:inmenu", "Show Target"));
2092 showTarget
->setIcon(QIcon::fromTheme(QStringLiteral("document-open-folder")));
2093 showTarget
->setEnabled(false);
2094 connect(showTarget
, &QAction::triggered
, this, &DolphinMainWindow::showTarget
);
2096 QAction
*openInNewTab
= actionCollection()->addAction(QStringLiteral("open_in_new_tab"));
2097 openInNewTab
->setText(i18nc("@action:inmenu", "Open in New Tab"));
2098 openInNewTab
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
2099 connect(openInNewTab
, &QAction::triggered
, this, &DolphinMainWindow::openInNewTab
);
2101 QAction
*openInNewTabs
= actionCollection()->addAction(QStringLiteral("open_in_new_tabs"));
2102 openInNewTabs
->setText(i18nc("@action:inmenu", "Open in New Tabs"));
2103 openInNewTabs
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
2104 connect(openInNewTabs
, &QAction::triggered
, this, &DolphinMainWindow::openInNewTab
);
2106 QAction
*openInNewWindow
= actionCollection()->addAction(QStringLiteral("open_in_new_window"));
2107 openInNewWindow
->setText(i18nc("@action:inmenu", "Open in New Window"));
2108 openInNewWindow
->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
2109 connect(openInNewWindow
, &QAction::triggered
, this, &DolphinMainWindow::openInNewWindow
);
2111 QAction
*openInSplitViewAction
= actionCollection()->addAction(QStringLiteral("open_in_split_view"));
2112 openInSplitViewAction
->setText(i18nc("@action:inmenu", "Open in Split View"));
2113 openInSplitViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-right-new")));
2114 connect(openInSplitViewAction
, &QAction::triggered
, this, [this]() {
2115 openInSplitView(QUrl());
2119 void DolphinMainWindow::setupDockWidgets()
2121 const bool lock
= GeneralSettings::lockPanels();
2123 DolphinPlacesModelSingleton::instance().placesModel()->setPanelsLocked(lock
);
2125 KDualAction
*lockLayoutAction
= actionCollection()->add
<KDualAction
>(QStringLiteral("lock_panels"));
2126 lockLayoutAction
->setActiveText(i18nc("@action:inmenu Panels", "Unlock Panels"));
2127 lockLayoutAction
->setActiveIcon(QIcon::fromTheme(QStringLiteral("object-unlocked")));
2128 lockLayoutAction
->setInactiveText(i18nc("@action:inmenu Panels", "Lock Panels"));
2129 lockLayoutAction
->setInactiveIcon(QIcon::fromTheme(QStringLiteral("object-locked")));
2130 lockLayoutAction
->setWhatsThis(xi18nc("@info:whatsthis",
2132 "switches between having panels <emphasis>locked</emphasis> or "
2133 "<emphasis>unlocked</emphasis>.<nl/>Unlocked panels can be "
2134 "dragged to the other side of the window and have a close "
2135 "button.<nl/>Locked panels are embedded more cleanly."));
2136 lockLayoutAction
->setActive(lock
);
2137 connect(lockLayoutAction
, &KDualAction::triggered
, this, &DolphinMainWindow::togglePanelLockState
);
2139 // Setup "Information"
2140 DolphinDockWidget
*infoDock
= new DolphinDockWidget(i18nc("@title:window", "Information"));
2141 infoDock
->setLocked(lock
);
2142 infoDock
->setObjectName(QStringLiteral("infoDock"));
2143 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
2146 InformationPanel
*infoPanel
= new InformationPanel(infoDock
);
2147 infoPanel
->setCustomContextMenuActions({lockLayoutAction
});
2148 connect(infoPanel
, &InformationPanel::urlActivated
, this, &DolphinMainWindow::handleUrl
);
2149 infoDock
->setWidget(infoPanel
);
2151 createPanelAction(QIcon::fromTheme(QStringLiteral("dialog-information")), Qt::Key_F11
, infoDock
, QStringLiteral("show_information_panel"));
2153 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
2154 connect(this, &DolphinMainWindow::urlChanged
, infoPanel
, &InformationPanel::setUrl
);
2155 connect(this, &DolphinMainWindow::selectionChanged
, infoPanel
, &InformationPanel::setSelection
);
2156 connect(this, &DolphinMainWindow::requestItemInfo
, infoPanel
, &InformationPanel::requestDelayedItemInfo
);
2157 connect(this, &DolphinMainWindow::fileItemsChanged
, infoPanel
, &InformationPanel::slotFilesItemChanged
);
2160 // i18n: This is the last paragraph for the "What's This"-texts of all four panels.
2161 const QString panelWhatsThis
= xi18nc("@info:whatsthis",
2163 "hide panels like this go to <interface>Menu|Panels</interface> "
2164 "or <interface>View|Panels</interface>.</para>");
2167 ->action(QStringLiteral("show_information_panel"))
2168 ->setWhatsThis(xi18nc("@info:whatsthis",
2169 "<para> This toggles the "
2170 "<emphasis>information</emphasis> panel at the right side of the "
2171 "window.</para><para>The panel provides in-depth information "
2172 "about the items your mouse is hovering over or about the selected "
2173 "items. Otherwise it informs you about the currently viewed folder.<nl/>"
2174 "For single items a preview of their contents is provided.</para>"));
2176 infoDock
->setWhatsThis(xi18nc("@info:whatsthis",
2178 "provides in-depth information about the items your mouse is "
2179 "hovering over or about the selected items. Otherwise it informs "
2180 "you about the currently viewed folder.<nl/>For single items a "
2181 "preview of their contents is provided.</para><para>You can configure "
2182 "which and how details are given here by right-clicking.</para>")
2186 DolphinDockWidget
*foldersDock
= new DolphinDockWidget(i18nc("@title:window", "Folders"));
2187 foldersDock
->setLocked(lock
);
2188 foldersDock
->setObjectName(QStringLiteral("foldersDock"));
2189 foldersDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
2190 FoldersPanel
*foldersPanel
= new FoldersPanel(foldersDock
);
2191 foldersPanel
->setCustomContextMenuActions({lockLayoutAction
});
2192 foldersDock
->setWidget(foldersPanel
);
2194 createPanelAction(QIcon::fromTheme(QStringLiteral("folder")), Qt::Key_F7
, foldersDock
, QStringLiteral("show_folders_panel"));
2196 addDockWidget(Qt::LeftDockWidgetArea
, foldersDock
);
2197 connect(this, &DolphinMainWindow::urlChanged
, foldersPanel
, &FoldersPanel::setUrl
);
2198 connect(foldersPanel
, &FoldersPanel::folderActivated
, this, &DolphinMainWindow::changeUrl
);
2199 connect(foldersPanel
, &FoldersPanel::folderInNewTab
, this, &DolphinMainWindow::openNewTab
);
2200 connect(foldersPanel
, &FoldersPanel::folderInNewActiveTab
, this, &DolphinMainWindow::openNewTabAndActivate
);
2201 connect(foldersPanel
, &FoldersPanel::errorMessage
, this, &DolphinMainWindow::showErrorMessage
);
2204 ->action(QStringLiteral("show_folders_panel"))
2205 ->setWhatsThis(xi18nc("@info:whatsthis",
2207 "<emphasis>folders</emphasis> panel at the left side of the window."
2208 "<nl/><nl/>It shows the folders of the <emphasis>file system"
2209 "</emphasis> in a <emphasis>tree view</emphasis>."));
2210 foldersDock
->setWhatsThis(xi18nc("@info:whatsthis",
2212 "shows the folders of the <emphasis>file system</emphasis> in a "
2213 "<emphasis>tree view</emphasis>.</para><para>Click a folder to go "
2214 "there. Click the arrow to the left of a folder to see its subfolders. "
2215 "This allows quick switching between any folders.</para>")
2220 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
2221 DolphinDockWidget
*terminalDock
= new DolphinDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
2222 terminalDock
->setLocked(lock
);
2223 terminalDock
->setObjectName(QStringLiteral("terminalDock"));
2224 terminalDock
->setContentsMargins(0, 0, 0, 0);
2225 m_terminalPanel
= new TerminalPanel(terminalDock
);
2226 m_terminalPanel
->setCustomContextMenuActions({lockLayoutAction
});
2227 terminalDock
->setWidget(m_terminalPanel
);
2229 connect(m_terminalPanel
, &TerminalPanel::hideTerminalPanel
, terminalDock
, &DolphinDockWidget::hide
);
2230 connect(m_terminalPanel
, &TerminalPanel::changeUrl
, this, &DolphinMainWindow::slotTerminalDirectoryChanged
);
2231 connect(terminalDock
, &DolphinDockWidget::visibilityChanged
, m_terminalPanel
, &TerminalPanel::dockVisibilityChanged
);
2232 connect(terminalDock
, &DolphinDockWidget::visibilityChanged
, this, &DolphinMainWindow::slotTerminalPanelVisibilityChanged
);
2234 createPanelAction(QIcon::fromTheme(QStringLiteral("dialog-scripts")), Qt::Key_F4
, terminalDock
, QStringLiteral("show_terminal_panel"));
2236 addDockWidget(Qt::BottomDockWidgetArea
, terminalDock
);
2237 connect(this, &DolphinMainWindow::urlChanged
, m_terminalPanel
, &TerminalPanel::setUrl
);
2239 if (GeneralSettings::version() < 200) {
2240 terminalDock
->hide();
2244 ->action(QStringLiteral("show_terminal_panel"))
2245 ->setWhatsThis(xi18nc("@info:whatsthis",
2246 "<para>This toggles the "
2247 "<emphasis>terminal</emphasis> panel at the bottom of the window."
2248 "<nl/>The location in the terminal will always match the folder "
2249 "view so you can navigate using either.</para><para>The terminal "
2250 "panel is not needed for basic computer usage but can be useful "
2251 "for advanced tasks. To learn more about terminals use the help "
2252 "in a standalone terminal application like Konsole.</para>"));
2253 terminalDock
->setWhatsThis(xi18nc("@info:whatsthis",
2255 "the <emphasis>terminal</emphasis> panel. It behaves like a "
2256 "normal terminal but will match the location of the folder view "
2257 "so you can navigate using either.</para><para>The terminal panel "
2258 "is not needed for basic computer usage but can be useful for "
2259 "advanced tasks. To learn more about terminals use the help in a "
2260 "standalone terminal application like Konsole.</para>")
2265 if (GeneralSettings::version() < 200) {
2267 foldersDock
->hide();
2271 DolphinDockWidget
*placesDock
= new DolphinDockWidget(i18nc("@title:window", "Places"));
2272 placesDock
->setLocked(lock
);
2273 placesDock
->setObjectName(QStringLiteral("placesDock"));
2274 placesDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
2276 m_placesPanel
= new PlacesPanel(placesDock
);
2277 m_placesPanel
->setCustomContextMenuActions({lockLayoutAction
});
2278 placesDock
->setWidget(m_placesPanel
);
2280 createPanelAction(QIcon::fromTheme(QStringLiteral("compass")), Qt::Key_F9
, placesDock
, QStringLiteral("show_places_panel"));
2282 addDockWidget(Qt::LeftDockWidgetArea
, placesDock
);
2283 connect(m_placesPanel
, &PlacesPanel::placeActivated
, this, &DolphinMainWindow::slotPlaceActivated
);
2284 connect(m_placesPanel
, &PlacesPanel::tabRequested
, this, &DolphinMainWindow::openNewTab
);
2285 connect(m_placesPanel
, &PlacesPanel::activeTabRequested
, this, &DolphinMainWindow::openNewTabAndActivate
);
2286 connect(m_placesPanel
, &PlacesPanel::newWindowRequested
, this, [this](const QUrl
&url
) {
2287 Dolphin::openNewWindow({url
}, this);
2289 connect(m_placesPanel
, &PlacesPanel::openInSplitViewRequested
, this, &DolphinMainWindow::openInSplitView
);
2290 connect(m_placesPanel
, &PlacesPanel::errorMessage
, this, &DolphinMainWindow::showErrorMessage
);
2291 connect(this, &DolphinMainWindow::urlChanged
, m_placesPanel
, &PlacesPanel::setUrl
);
2292 connect(placesDock
, &DolphinDockWidget::visibilityChanged
, &DolphinUrlNavigatorsController::slotPlacesPanelVisibilityChanged
);
2293 connect(this, &DolphinMainWindow::settingsChanged
, m_placesPanel
, &PlacesPanel::readSettings
);
2294 connect(m_placesPanel
, &PlacesPanel::storageTearDownRequested
, this, &DolphinMainWindow::slotStorageTearDownFromPlacesRequested
);
2295 connect(m_placesPanel
, &PlacesPanel::storageTearDownExternallyRequested
, this, &DolphinMainWindow::slotStorageTearDownExternallyRequested
);
2296 DolphinUrlNavigatorsController::slotPlacesPanelVisibilityChanged(m_placesPanel
->isVisible());
2298 auto actionShowAllPlaces
= new QAction(QIcon::fromTheme(QStringLiteral("view-hidden")), i18nc("@item:inmenu", "Show Hidden Places"), this);
2299 actionShowAllPlaces
->setCheckable(true);
2300 actionShowAllPlaces
->setDisabled(true);
2301 actionShowAllPlaces
->setWhatsThis(i18nc("@info:whatsthis",
2303 "all places in the places panel that have been hidden. They will "
2304 "appear semi-transparent unless you uncheck their hide property."));
2306 connect(actionShowAllPlaces
, &QAction::triggered
, this, [this](bool checked
) {
2307 m_placesPanel
->setShowAll(checked
);
2309 connect(m_placesPanel
, &PlacesPanel::allPlacesShownChanged
, actionShowAllPlaces
, &QAction::setChecked
);
2312 ->action(QStringLiteral("show_places_panel"))
2313 ->setWhatsThis(xi18nc("@info:whatsthis",
2314 "<para>This toggles the "
2315 "<emphasis>places</emphasis> panel at the left side of the window."
2316 "</para><para>It allows you to go to locations you have "
2317 "bookmarked and to access disk or media attached to the computer "
2318 "or to the network. It also contains sections to find recently "
2319 "saved files or files of a certain type.</para>"));
2320 placesDock
->setWhatsThis(xi18nc("@info:whatsthis",
2321 "<para>This is the "
2322 "<emphasis>Places</emphasis> panel. It allows you to go to locations "
2323 "you have bookmarked and to access disk or media attached to the "
2324 "computer or to the network. It also contains sections to find "
2325 "recently saved files or files of a certain type.</para><para>"
2326 "Click on an entry to go there. Click with the right mouse button "
2327 "instead to open any entry in a new tab or new window.</para>"
2328 "<para>New entries can be added by dragging folders onto this panel. "
2329 "Right-click any section or entry to hide it. Right-click an empty "
2330 "space on this panel and select <interface>Show Hidden Places"
2331 "</interface> to display it again.</para>")
2334 // Add actions into the "Panels" menu
2335 KActionMenu
*panelsMenu
= new KActionMenu(i18nc("@action:inmenu View", "Show Panels"), this);
2336 actionCollection()->addAction(QStringLiteral("panels"), panelsMenu
);
2337 panelsMenu
->setIcon(QIcon::fromTheme(QStringLiteral("view-sidetree")));
2338 panelsMenu
->setPopupMode(QToolButton::InstantPopup
);
2339 const KActionCollection
*ac
= actionCollection();
2340 panelsMenu
->addAction(ac
->action(QStringLiteral("show_places_panel")));
2342 panelsMenu
->addAction(ac
->action(QStringLiteral("show_information_panel")));
2344 panelsMenu
->addAction(ac
->action(QStringLiteral("show_folders_panel")));
2345 panelsMenu
->addAction(ac
->action(QStringLiteral("show_terminal_panel")));
2346 panelsMenu
->addSeparator();
2347 panelsMenu
->addAction(actionShowAllPlaces
);
2348 panelsMenu
->addAction(lockLayoutAction
);
2350 connect(panelsMenu
->menu(), &QMenu::aboutToShow
, this, [actionShowAllPlaces
] {
2351 actionShowAllPlaces
->setEnabled(DolphinPlacesModelSingleton::instance().placesModel()->hiddenCount());
2355 void DolphinMainWindow::updateFileAndEditActions()
2357 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
2358 const KActionCollection
*col
= actionCollection();
2359 KFileItemListProperties
capabilitiesSource(list
);
2361 QAction
*renameAction
= col
->action(KStandardAction::name(KStandardAction::RenameFile
));
2362 QAction
*moveToTrashAction
= col
->action(KStandardAction::name(KStandardAction::MoveToTrash
));
2363 QAction
*deleteAction
= col
->action(KStandardAction::name(KStandardAction::DeleteFile
));
2364 QAction
*cutAction
= col
->action(KStandardAction::name(KStandardAction::Cut
));
2365 QAction
*duplicateAction
= col
->action(QStringLiteral("duplicate")); // see DolphinViewActionHandler
2366 QAction
*addToPlacesAction
= col
->action(QStringLiteral("add_to_places"));
2367 QAction
*copyToOtherViewAction
= col
->action(QStringLiteral("copy_to_inactive_split_view"));
2368 QAction
*moveToOtherViewAction
= col
->action(QStringLiteral("move_to_inactive_split_view"));
2369 QAction
*copyLocation
= col
->action(QString("copy_location"));
2371 if (list
.isEmpty()) {
2372 stateChanged(QStringLiteral("has_no_selection"));
2374 // All actions that need a selection to function can be enabled because they should trigger selection mode.
2375 renameAction
->setEnabled(true);
2376 moveToTrashAction
->setEnabled(true);
2377 deleteAction
->setEnabled(true);
2378 cutAction
->setEnabled(true);
2379 duplicateAction
->setEnabled(true);
2380 addToPlacesAction
->setEnabled(true);
2381 copyLocation
->setEnabled(true);
2382 // Them triggering selection mode and not directly acting on selected items is signified by adding "…" to their text.
2383 m_actionTextHelper
->textsWhenNothingIsSelectedEnabled(true);
2386 m_actionTextHelper
->textsWhenNothingIsSelectedEnabled(false);
2387 stateChanged(QStringLiteral("has_selection"));
2389 QAction
*deleteWithTrashShortcut
= col
->action(QStringLiteral("delete_shortcut")); // see DolphinViewActionHandler
2390 QAction
*showTarget
= col
->action(QStringLiteral("show_target"));
2392 if (list
.length() == 1 && list
.first().isDir()) {
2393 addToPlacesAction
->setEnabled(true);
2395 addToPlacesAction
->setEnabled(false);
2398 const bool enableMoveToTrash
= capabilitiesSource
.isLocal() && capabilitiesSource
.supportsMoving();
2400 renameAction
->setEnabled(capabilitiesSource
.supportsMoving());
2401 moveToTrashAction
->setEnabled(enableMoveToTrash
);
2402 deleteAction
->setEnabled(capabilitiesSource
.supportsDeleting());
2403 deleteWithTrashShortcut
->setEnabled(capabilitiesSource
.supportsDeleting() && !enableMoveToTrash
);
2404 cutAction
->setEnabled(capabilitiesSource
.supportsMoving());
2405 copyLocation
->setEnabled(list
.length() == 1);
2406 showTarget
->setEnabled(list
.length() == 1 && list
.at(0).isLink());
2407 duplicateAction
->setEnabled(capabilitiesSource
.supportsWriting());
2410 if (m_tabWidget
->currentTabPage()->splitViewEnabled() && !list
.isEmpty()) {
2411 DolphinTabPage
*tabPage
= m_tabWidget
->currentTabPage();
2412 KFileItem capabilitiesDestination
;
2414 if (tabPage
->primaryViewActive()) {
2415 capabilitiesDestination
= tabPage
->secondaryViewContainer()->rootItem();
2417 capabilitiesDestination
= tabPage
->primaryViewContainer()->rootItem();
2420 const auto destUrl
= capabilitiesDestination
.url();
2421 const bool allNotTargetOrigin
= std::all_of(list
.cbegin(), list
.cend(), [destUrl
](const KFileItem
&item
) {
2422 return item
.url().adjusted(QUrl::RemoveFilename
| QUrl::StripTrailingSlash
) != destUrl
;
2425 copyToOtherViewAction
->setEnabled(capabilitiesDestination
.isWritable() && allNotTargetOrigin
);
2426 moveToOtherViewAction
->setEnabled((list
.isEmpty() || capabilitiesSource
.supportsMoving()) && capabilitiesDestination
.isWritable()
2427 && allNotTargetOrigin
);
2429 copyToOtherViewAction
->setEnabled(false);
2430 moveToOtherViewAction
->setEnabled(false);
2434 void DolphinMainWindow::updateViewActions()
2436 m_actionHandler
->updateViewActions();
2438 QAction
*toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
2439 toggleFilterBarAction
->setChecked(m_activeViewContainer
->isFilterBarVisible());
2441 updateSplitActions();
2444 void DolphinMainWindow::updateGoActions()
2446 QAction
*goUpAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Up
));
2447 const QUrl currentUrl
= m_activeViewContainer
->url();
2448 // I think this is one of the best places to firstly be confronted
2449 // with a file system and its hierarchy. Talking about the root
2450 // directory might seem too much here but it is the question that
2451 // naturally arises in this context.
2452 goUpAction
->setWhatsThis(xi18nc("@info:whatsthis",
2454 "the folder that contains the currently viewed one.</para>"
2455 "<para>All files and folders are organized in a hierarchical "
2456 "<emphasis>file system</emphasis>. At the top of this hierarchy is "
2457 "a directory that contains all data connected to this computer"
2458 "—the <emphasis>root directory</emphasis>.</para>"));
2459 goUpAction
->setEnabled(KIO::upUrl(currentUrl
) != currentUrl
);
2462 void DolphinMainWindow::refreshViews()
2464 m_tabWidget
->refreshViews();
2466 if (GeneralSettings::modifiedStartupSettings()) {
2467 updateWindowTitle();
2470 updateSplitActions();
2472 Q_EMIT
settingsChanged();
2475 void DolphinMainWindow::clearStatusBar()
2477 m_activeViewContainer
->statusBar()->resetToDefaultText();
2480 void DolphinMainWindow::connectViewSignals(DolphinViewContainer
*container
)
2482 connect(container
, &DolphinViewContainer::showFilterBarChanged
, this, &DolphinMainWindow::updateFilterBarAction
);
2483 connect(container
, &DolphinViewContainer::writeStateChanged
, this, &DolphinMainWindow::slotWriteStateChanged
);
2484 slotWriteStateChanged(container
->view()->isFolderWritable());
2485 connect(container
, &DolphinViewContainer::searchModeEnabledChanged
, this, &DolphinMainWindow::updateSearchAction
);
2486 connect(container
, &DolphinViewContainer::captionChanged
, this, &DolphinMainWindow::updateWindowTitle
);
2487 connect(container
, &DolphinViewContainer::tabRequested
, this, &DolphinMainWindow::openNewTab
);
2488 connect(container
, &DolphinViewContainer::activeTabRequested
, this, &DolphinMainWindow::openNewTabAndActivate
);
2490 const QAction
*toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
2491 connect(toggleSearchAction
, &QAction::triggered
, container
, &DolphinViewContainer::setSearchModeEnabled
);
2493 // Make the toggled state of the selection mode actions visually follow the selection mode state of the view.
2494 auto toggleSelectionModeAction
= actionCollection()->action(QStringLiteral("toggle_selection_mode"));
2495 toggleSelectionModeAction
->setChecked(m_activeViewContainer
->isSelectionModeEnabled());
2496 connect(m_activeViewContainer
, &DolphinViewContainer::selectionModeChanged
, toggleSelectionModeAction
, &QAction::setChecked
);
2498 const DolphinView
*view
= container
->view();
2499 connect(view
, &DolphinView::selectionChanged
, this, &DolphinMainWindow::slotSelectionChanged
);
2500 connect(view
, &DolphinView::requestItemInfo
, this, &DolphinMainWindow::requestItemInfo
);
2501 connect(view
, &DolphinView::fileItemsChanged
, this, &DolphinMainWindow::fileItemsChanged
);
2502 connect(view
, &DolphinView::tabRequested
, this, &DolphinMainWindow::openNewTab
);
2503 connect(view
, &DolphinView::activeTabRequested
, this, &DolphinMainWindow::openNewTabAndActivate
);
2504 connect(view
, &DolphinView::windowRequested
, this, &DolphinMainWindow::openNewWindow
);
2505 connect(view
, &DolphinView::requestContextMenu
, this, &DolphinMainWindow::openContextMenu
);
2506 connect(view
, &DolphinView::directoryLoadingStarted
, this, &DolphinMainWindow::enableStopAction
);
2507 connect(view
, &DolphinView::directoryLoadingCompleted
, this, &DolphinMainWindow::disableStopAction
);
2508 connect(view
, &DolphinView::directoryLoadingCompleted
, this, &DolphinMainWindow::slotDirectoryLoadingCompleted
);
2509 connect(view
, &DolphinView::goBackRequested
, this, &DolphinMainWindow::goBack
);
2510 connect(view
, &DolphinView::goForwardRequested
, this, &DolphinMainWindow::goForward
);
2511 connect(view
, &DolphinView::urlActivated
, this, &DolphinMainWindow::handleUrl
);
2512 connect(view
, &DolphinView::goUpRequested
, this, &DolphinMainWindow::goUp
);
2514 connect(container
->urlNavigatorInternalWithHistory(), &KUrlNavigator::urlChanged
, this, &DolphinMainWindow::changeUrl
);
2515 connect(container
->urlNavigatorInternalWithHistory(), &KUrlNavigator::historyChanged
, this, &DolphinMainWindow::updateHistory
);
2517 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>(actionCollection()->action(QStringLiteral("url_navigators")));
2518 const KUrlNavigator
*navigator
=
2519 m_tabWidget
->currentTabPage()->primaryViewActive() ? navigators
->primaryUrlNavigator() : navigators
->secondaryUrlNavigator();
2521 QAction
*editableLocactionAction
= actionCollection()->action(QStringLiteral("editable_location"));
2522 editableLocactionAction
->setChecked(navigator
->isUrlEditable());
2523 connect(navigator
, &KUrlNavigator::editableStateChanged
, this, &DolphinMainWindow::slotEditableStateChanged
);
2524 connect(navigator
, &KUrlNavigator::tabRequested
, this, &DolphinMainWindow::openNewTab
);
2525 connect(navigator
, &KUrlNavigator::activeTabRequested
, this, &DolphinMainWindow::openNewTabAndActivate
);
2526 connect(navigator
, &KUrlNavigator::newWindowRequested
, this, &DolphinMainWindow::openNewWindow
);
2529 void DolphinMainWindow::updateSplitActions()
2531 QAction
*popoutSplitAction
= actionCollection()->action(QStringLiteral("popout_split_view"));
2532 const DolphinTabPage
*tabPage
= m_tabWidget
->currentTabPage();
2533 if (tabPage
->splitViewEnabled()) {
2534 if (GeneralSettings::closeActiveSplitView() ? tabPage
->primaryViewActive() : !tabPage
->primaryViewActive()) {
2535 m_splitViewAction
->setText(i18nc("@action:intoolbar Close left view", "Close"));
2536 m_splitViewAction
->setToolTip(i18nc("@info", "Close left view"));
2537 m_splitViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-left-close")));
2538 popoutSplitAction
->setText(i18nc("@action:intoolbar Move left split view to a new window", "Pop out"));
2539 popoutSplitAction
->setToolTip(i18nc("@info", "Move left split view to a new window"));
2541 m_splitViewAction
->setText(i18nc("@action:intoolbar Close right view", "Close"));
2542 m_splitViewAction
->setToolTip(i18nc("@info", "Close right view"));
2543 m_splitViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-right-close")));
2544 popoutSplitAction
->setText(i18nc("@action:intoolbar Move right split view to a new window", "Pop out"));
2545 popoutSplitAction
->setToolTip(i18nc("@info", "Move right split view to a new window"));
2547 popoutSplitAction
->setEnabled(true);
2549 m_splitViewAction
->setText(i18nc("@action:intoolbar Split view", "Split"));
2550 m_splitViewAction
->setToolTip(i18nc("@info", "Split view"));
2551 m_splitViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-right-new")));
2552 popoutSplitAction
->setText(i18nc("@action:intoolbar Move active split view to a new window", "Pop out"));
2553 popoutSplitAction
->setEnabled(false);
2557 void DolphinMainWindow::updateAllowedToolbarAreas()
2559 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>(actionCollection()->action(QStringLiteral("url_navigators")));
2560 if (toolBar()->actions().contains(navigators
)) {
2561 toolBar()->setAllowedAreas(Qt::TopToolBarArea
| Qt::BottomToolBarArea
);
2562 if (toolBarArea(toolBar()) == Qt::LeftToolBarArea
|| toolBarArea(toolBar()) == Qt::RightToolBarArea
) {
2563 addToolBar(Qt::TopToolBarArea
, toolBar());
2566 toolBar()->setAllowedAreas(Qt::AllToolBarAreas
);
2570 bool DolphinMainWindow::isKompareInstalled() const
2572 static bool initialized
= false;
2573 static bool installed
= false;
2575 // TODO: maybe replace this approach later by using a menu
2576 // plugin like kdiff3plugin.cpp
2577 installed
= !QStandardPaths::findExecutable(QStringLiteral("kompare")).isEmpty();
2583 void DolphinMainWindow::createPanelAction(const QIcon
&icon
, const QKeySequence
&shortcut
, QDockWidget
*dockWidget
, const QString
&actionName
)
2585 auto dockAction
= dockWidget
->toggleViewAction();
2586 dockAction
->setIcon(icon
);
2587 dockAction
->setEnabled(true);
2589 QAction
*panelAction
= actionCollection()->addAction(actionName
, dockAction
);
2590 actionCollection()->setDefaultShortcut(panelAction
, shortcut
);
2592 connect(panelAction
, &QAction::toggled
, dockWidget
, &QWidget::setVisible
);
2595 void DolphinMainWindow::setupWhatsThis()
2598 menuBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2599 "<emphasis>Menubar</emphasis>. It provides access to commands and "
2600 "configuration options. Left-click on any of the menus on this "
2601 "bar to see its contents.</para><para>The Menubar can be hidden "
2602 "by unchecking <interface>Settings|Show Menubar</interface>. Then "
2603 "most of its contents become available through a <interface>Menu"
2604 "</interface> button on the <emphasis>Toolbar</emphasis>.</para>"));
2605 toolBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2606 "<emphasis>Toolbar</emphasis>. It allows quick access to "
2607 "frequently used actions.</para><para>It is highly customizable. "
2608 "All items you see in the <interface>Menu</interface> or "
2609 "in the <interface>Menubar</interface> can be placed on the "
2610 "Toolbar. Just right-click on it and select <interface>Configure "
2611 "Toolbars…</interface> or find this action within the <interface>"
2613 "</para><para>The location of the bar and the style of its "
2614 "buttons can also be changed in the right-click menu. Right-click "
2615 "a button if you want to show or hide its text.</para>"));
2616 m_tabWidget
->setWhatsThis(xi18nc("@info:whatsthis main view",
2617 "<para>Here you can see the <emphasis>folders</emphasis> and "
2618 "<emphasis>files</emphasis> that are at the location described in "
2619 "the <interface>Location Bar</interface> above. This area is the "
2620 "central part of this application where you navigate to the files "
2621 "you want to use.</para><para>For an elaborate and general "
2622 "introduction to this application <link "
2623 "url='https://userbase.kde.org/Dolphin/File_Management#Introduction_to_Dolphin'>"
2624 "click here</link>. This will open an introductory article from "
2625 "the <emphasis>KDE UserBase Wiki</emphasis>.</para><para>For brief "
2626 "explanations of all the features of this <emphasis>view</emphasis> "
2627 "<link url='help:/dolphin/dolphin-view.html'>click here</link> "
2628 "instead. This will open a page from the <emphasis>Handbook"
2629 "</emphasis> that covers the basics.</para>"));
2632 actionCollection()->action(KStandardAction::name(KStandardAction::KeyBindings
))
2633 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window "
2634 "that lists the <emphasis>keyboard shortcuts</emphasis>.<nl/>"
2635 "There you can set up key combinations to trigger an action when "
2636 "they are pressed simultaneously. All commands in this application can "
2637 "be triggered this way.</para>"));
2638 actionCollection()->action(KStandardAction::name(KStandardAction::ConfigureToolbars
))
2639 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window in which "
2640 "you can change which buttons appear on the <emphasis>Toolbar</emphasis>.</para>"
2641 "<para>All items you see in the <interface>Menu</interface> can also be placed on the Toolbar.</para>"));
2642 actionCollection()->action(KStandardAction::name(KStandardAction::Preferences
))
2643 ->setWhatsThis(xi18nc("@info:whatsthis","This opens a window where you can "
2644 "change a multitude of settings for this application. For an explanation "
2645 "of the various settings go to the chapter <emphasis>Configuring Dolphin"
2646 "</emphasis> in <interface>Help|Dolphin Handbook</interface>."));
2650 auto setStandardActionWhatsThis
= [this](KStandardAction::StandardAction actionId
,
2651 const QString
&whatsThis
) {
2652 // Check for the existence of an action since it can be restricted through the Kiosk system
2653 if (auto *action
= actionCollection()->action(KStandardAction::name(actionId
))) {
2654 action
->setWhatsThis(whatsThis
);
2658 // i18n: If the external link isn't available in your language it might make
2659 // sense to state the external link's language in brackets to not
2660 // frustrate the user. If there are multiple languages that the user might
2661 // know with a reasonable chance you might want to have 2 external links.
2662 // The same might be true for any external link you translate.
2663 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>"));
2664 // (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 )
2666 setStandardActionWhatsThis(KStandardAction::WhatsThis
,
2667 xi18nc("@info:whatsthis whatsthis button",
2668 "<para>This is the button that invokes the help feature you are "
2669 "using right now! Click it, then click any component of this "
2670 "application to ask \"What's this?\" about it. The mouse cursor "
2671 "will change appearance if no help is available for a spot.</para>"
2672 "<para>There are two other ways to get help: "
2673 "The <link url='help:/dolphin/index.html'>Dolphin Handbook</link> and "
2674 "the <link url='https://userbase.kde.org/Dolphin/File_Management'>KDE "
2675 "UserBase Wiki</link>.</para><para>The \"What's this?\" help is "
2676 "missing in most other windows so don't get too used to this.</para>"));
2678 setStandardActionWhatsThis(KStandardAction::ReportBug
,
2679 xi18nc("@info:whatsthis","<para>This opens a "
2680 "window that will guide you through reporting errors or flaws "
2681 "in this application or in other KDE software.</para>"
2682 "<para>High-quality bug reports are much appreciated. To learn "
2683 "how to make your bug report as effective as possible "
2684 "<link url='https://community.kde.org/Get_Involved/Bug_Reporting'>"
2685 "click here</link>.</para>"));
2687 setStandardActionWhatsThis(KStandardAction::Donate
,
2688 xi18nc("@info:whatsthis", "<para>This opens a "
2689 "<emphasis>web page</emphasis> where you can donate to "
2690 "support the continued work on this application and many "
2691 "other projects by the <emphasis>KDE</emphasis> community.</para>"
2692 "<para>Donating is the easiest and fastest way to efficiently "
2693 "support KDE and its projects. KDE projects are available for "
2694 "free therefore your donation is needed to cover things that "
2695 "require money like servers, contributor meetings, etc.</para>"
2696 "<para><emphasis>KDE e.V.</emphasis> is the non-profit "
2697 "organization behind the KDE community.</para>"));
2699 setStandardActionWhatsThis(KStandardAction::SwitchApplicationLanguage
,
2700 xi18nc("@info:whatsthis",
2701 "With this you can change the language this application uses."
2702 "<nl/>You can even set secondary languages which will be used "
2703 "if texts are not available in your preferred language."));
2705 setStandardActionWhatsThis(KStandardAction::AboutApp
,
2706 xi18nc("@info:whatsthis","This opens a "
2707 "window that informs you about the version, license, "
2708 "used libraries and maintainers of this application."));
2710 setStandardActionWhatsThis(KStandardAction::AboutKDE
,
2711 xi18nc("@info:whatsthis","This opens a "
2712 "window with information about <emphasis>KDE</emphasis>. "
2713 "The KDE community are the people behind this free software."
2714 "<nl/>If you like using this application but don't know "
2715 "about KDE or want to see a cute dragon have a look!"));
2719 bool DolphinMainWindow::addHamburgerMenuToToolbar()
2721 QDomDocument domDocument
= KXMLGUIClient::domDocument();
2722 if (domDocument
.isNull()) {
2725 QDomNode toolbar
= domDocument
.elementsByTagName(QStringLiteral("ToolBar")).at(0);
2726 if (toolbar
.isNull()) {
2730 QDomElement hamburgerMenuElement
= domDocument
.createElement(QStringLiteral("Action"));
2731 hamburgerMenuElement
.setAttribute(QStringLiteral("name"), QStringLiteral("hamburger_menu"));
2732 toolbar
.appendChild(hamburgerMenuElement
);
2734 KXMLGUIFactory::saveConfigFile(domDocument
, xmlFile());
2738 // Make sure to also remove the <KXMLGUIFactory> and <QDomDocument> include
2739 // whenever this method is removed (maybe in the year ~2026).
2742 // Set a sane initial window size
2743 QSize
DolphinMainWindow::sizeHint() const
2745 return KXmlGuiWindow::sizeHint().expandedTo(QSize(760, 550));
2748 void DolphinMainWindow::saveNewToolbarConfig()
2750 KXmlGuiWindow::saveNewToolbarConfig(); // Applies the new config. This has to be called first
2751 // because the rest of this method decides things
2752 // based on the new config.
2753 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>(actionCollection()->action(QStringLiteral("url_navigators")));
2754 if (!toolBar()->actions().contains(navigators
)) {
2755 m_tabWidget
->currentTabPage()->insertNavigatorsWidget(navigators
);
2757 updateAllowedToolbarAreas();
2758 (static_cast<KHamburgerMenu
*>(actionCollection()->action(KStandardAction::name(KStandardAction::HamburgerMenu
))))->hideActionsOf(toolBar());
2761 void DolphinMainWindow::focusTerminalPanel()
2763 if (m_terminalPanel
->isVisible()) {
2764 if (m_terminalPanel
->terminalHasFocus()) {
2765 m_activeViewContainer
->view()->setFocus(Qt::FocusReason::ShortcutFocusReason
);
2766 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
2768 m_terminalPanel
->setFocus(Qt::FocusReason::ShortcutFocusReason
);
2769 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
2772 actionCollection()->action(QStringLiteral("show_terminal_panel"))->trigger();
2773 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
2777 DolphinMainWindow::UndoUiInterface::UndoUiInterface()
2778 : KIO::FileUndoManager::UiInterface()
2782 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
2786 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
*job
)
2788 DolphinMainWindow
*mainWin
= qobject_cast
<DolphinMainWindow
*>(parentWidget());
2790 DolphinViewContainer
*container
= mainWin
->activeViewContainer();
2791 container
->showMessage(job
->errorString(), DolphinViewContainer::Error
);
2793 KIO::FileUndoManager::UiInterface::jobError(job
);
2797 bool DolphinMainWindow::isUrlOpen(const QString
&url
)
2799 return m_tabWidget
->isUrlOpen(QUrl::fromUserInput(url
));
2802 bool DolphinMainWindow::isItemVisibleInAnyView(const QString
&urlOfItem
)
2804 return m_tabWidget
->isItemVisibleInAnyView(QUrl::fromUserInput(urlOfItem
));
2807 #include "moc_dolphinmainwindow.cpp"