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