2 * SPDX-FileCopyrightText: 2006 Peter Penz <peter.penz19@gmail.com>
3 * SPDX-FileCopyrightText: 2006 Stefan Monov <logixoul@gmail.com>
4 * SPDX-FileCopyrightText: 2006 Cvetoslav Ludmiloff <ludmiloff@gmail.com>
6 * SPDX-License-Identifier: GPL-2.0-or-later
9 #include "dolphinmainwindow.h"
11 #include "dolphin_generalsettings.h"
12 #include "dolphinbookmarkhandler.h"
13 #include "dolphincontextmenu.h"
14 #include "dolphindockwidget.h"
15 #include "dolphinmainwindowadaptor.h"
16 #include "dolphinnavigatorswidgetaction.h"
17 #include "dolphinnewfilemenu.h"
18 #include "dolphinplacesmodelsingleton.h"
19 #include "dolphinrecenttabsmenu.h"
20 #include "dolphintabpage.h"
21 #include "dolphinurlnavigatorscontroller.h"
22 #include "dolphinviewcontainer.h"
24 #include "middleclickactioneventfilter.h"
25 #include "panels/folders/folderspanel.h"
26 #include "panels/places/placespanel.h"
27 #include "panels/terminal/terminalpanel.h"
28 #include "selectionmode/actiontexthelper.h"
29 #include "settings/dolphinsettingsdialog.h"
30 #include "statusbar/dolphinstatusbar.h"
31 #include "views/dolphinnewfilemenuobserver.h"
32 #include "views/dolphinremoteencoding.h"
33 #include "views/dolphinviewactionhandler.h"
34 #include "views/draganddrophelper.h"
35 #include "views/viewproperties.h"
37 #include <KActionCollection>
38 #include <KActionMenu>
39 #include <KAuthorized>
42 #include <KDualAction>
43 #include <KFileItemListProperties>
44 #include <KIO/CommandLauncherJob>
45 #include <KIO/JobUiDelegateFactory>
46 #include <KIO/OpenFileManagerWindowJob>
47 #include <KIO/OpenUrlJob>
48 #include <KJobWidgets>
49 #include <KLocalizedString>
50 #include <KMessageBox>
51 #include <KProtocolInfo>
52 #include <KProtocolManager>
54 #include <KShortcutsDialog>
55 #include <KStandardAction>
57 #include <KTerminalLauncherJob>
58 #include <KToggleAction>
60 #include <KToolBarPopupAction>
61 #include <KUrlComboBox>
62 #include <KUrlNavigator>
63 #include <KWindowSystem>
64 #include <KXMLGUIFactory>
66 #include <kwidgetsaddons_version.h>
68 #include <QApplication>
70 #include <QCloseEvent>
71 #include <QDesktopServices>
73 #include <QDomDocument>
77 #include <QPushButton>
79 #include <QStandardPaths>
81 #include <QToolButton>
82 #include <QtConcurrentRun>
87 #include <KStartupInfo>
92 // Used for GeneralSettings::version() to determine whether
93 // an updated version of Dolphin is running, so as to migrate
94 // removed/renamed ...etc config entries; increment it in such
96 const int CurrentDolphinVersion
= 202;
97 // The maximum number of entries in the back/forward popup menu
98 const int MaxNumberOfNavigationentries
= 12;
99 // The maximum number of "Activate Tab" shortcuts
100 const int MaxActivateTabShortcuts
= 9;
103 DolphinMainWindow::DolphinMainWindow()
104 : KXmlGuiWindow(nullptr)
105 , m_newFileMenu(nullptr)
106 , m_tabWidget(nullptr)
107 , m_activeViewContainer(nullptr)
108 , m_actionHandler(nullptr)
109 , m_remoteEncoding(nullptr)
111 , m_bookmarkHandler(nullptr)
112 , m_lastHandleUrlOpenJob(nullptr)
113 , m_terminalPanel(nullptr)
114 , m_placesPanel(nullptr)
115 , m_tearDownFromPlacesRequested(false)
116 , m_backAction(nullptr)
117 , m_forwardAction(nullptr)
118 , m_sessionSaveTimer(nullptr)
119 , m_sessionSaveWatcher(nullptr)
120 , m_sessionSaveScheduled(false)
121 , m_splitViewAction(nullptr)
122 , m_splitViewMenuAction(nullptr)
124 Q_INIT_RESOURCE(dolphin
);
126 new MainWindowAdaptor(this);
129 setWindowFlags(Qt::WindowContextHelpButtonHint
);
131 setComponentName(QStringLiteral("dolphin"), QGuiApplication::applicationDisplayName());
132 setObjectName(QStringLiteral("Dolphin#"));
134 setStateConfigGroup("State");
136 connect(&DolphinNewFileMenuObserver::instance(), &DolphinNewFileMenuObserver::errorMessage
, this, &DolphinMainWindow::showErrorMessage
);
138 KIO::FileUndoManager
*undoManager
= KIO::FileUndoManager::self();
139 undoManager
->setUiInterface(new UndoUiInterface());
141 connect(undoManager
, &KIO::FileUndoManager::undoAvailable
, this, &DolphinMainWindow::slotUndoAvailable
);
142 connect(undoManager
, &KIO::FileUndoManager::undoTextChanged
, this, &DolphinMainWindow::slotUndoTextChanged
);
143 connect(undoManager
, &KIO::FileUndoManager::jobRecordingStarted
, this, &DolphinMainWindow::clearStatusBar
);
144 connect(undoManager
, &KIO::FileUndoManager::jobRecordingFinished
, this, &DolphinMainWindow::showCommand
);
146 const bool firstRun
= (GeneralSettings::version() < 200);
148 GeneralSettings::setViewPropsTimestamp(QDateTime::currentDateTime());
151 setAcceptDrops(true);
153 auto *navigatorsWidgetAction
= new DolphinNavigatorsWidgetAction(this);
154 actionCollection()->addAction(QStringLiteral("url_navigators"), navigatorsWidgetAction
);
155 m_tabWidget
= new DolphinTabWidget(navigatorsWidgetAction
, this);
156 m_tabWidget
->setObjectName("tabWidget");
157 connect(m_tabWidget
, &DolphinTabWidget::activeViewChanged
, this, &DolphinMainWindow::activeViewChanged
);
158 connect(m_tabWidget
, &DolphinTabWidget::tabCountChanged
, this, &DolphinMainWindow::tabCountChanged
);
159 connect(m_tabWidget
, &DolphinTabWidget::currentUrlChanged
, this, &DolphinMainWindow::updateWindowTitle
);
160 setCentralWidget(m_tabWidget
);
162 m_actionTextHelper
= new SelectionMode::ActionTextHelper(this);
165 m_actionHandler
= new DolphinViewActionHandler(actionCollection(), m_actionTextHelper
, this);
166 connect(m_actionHandler
, &DolphinViewActionHandler::actionBeingHandled
, this, &DolphinMainWindow::clearStatusBar
);
167 connect(m_actionHandler
, &DolphinViewActionHandler::createDirectoryTriggered
, this, &DolphinMainWindow::createDirectory
);
168 connect(m_actionHandler
, &DolphinViewActionHandler::selectionModeChangeTriggered
, this, &DolphinMainWindow::slotSetSelectionMode
);
170 Q_CHECK_PTR(actionCollection()->action(QStringLiteral("create_dir")));
171 m_newFileMenu
->setNewFolderShortcutAction(actionCollection()->action(QStringLiteral("create_dir")));
173 m_remoteEncoding
= new DolphinRemoteEncoding(this, m_actionHandler
);
174 connect(this, &DolphinMainWindow::urlChanged
, m_remoteEncoding
, &DolphinRemoteEncoding::slotAboutToOpenUrl
);
178 setupGUI(Save
| Create
| ToolBar
);
179 stateChanged(QStringLiteral("new_file"));
181 QClipboard
*clipboard
= QApplication::clipboard();
182 connect(clipboard
, &QClipboard::dataChanged
, this, &DolphinMainWindow::updatePasteAction
);
184 QAction
*toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
185 toggleFilterBarAction
->setChecked(GeneralSettings::filterBar());
188 menuBar()->setVisible(false);
191 const bool showMenu
= !menuBar()->isHidden();
192 QAction
*showMenuBarAction
= actionCollection()->action(KStandardAction::name(KStandardAction::ShowMenubar
));
193 showMenuBarAction
->setChecked(showMenu
); // workaround for bug #171080
195 auto hamburgerMenu
= static_cast<KHamburgerMenu
*>(actionCollection()->action(KStandardAction::name(KStandardAction::HamburgerMenu
)));
196 hamburgerMenu
->setMenuBar(menuBar());
197 hamburgerMenu
->setShowMenuBarAction(showMenuBarAction
);
198 connect(hamburgerMenu
, &KHamburgerMenu::aboutToShowMenu
, this, &DolphinMainWindow::updateHamburgerMenu
);
199 hamburgerMenu
->hideActionsOf(toolBar());
200 if (GeneralSettings::version() < 201 && !toolBar()->actions().contains(hamburgerMenu
)) {
201 addHamburgerMenuToToolbar();
204 updateAllowedToolbarAreas();
206 // enable middle-click on back/forward/up to open in a new tab
207 auto *middleClickEventFilter
= new MiddleClickActionEventFilter(this);
208 connect(middleClickEventFilter
, &MiddleClickActionEventFilter::actionMiddleClicked
, this, &DolphinMainWindow::slotToolBarActionMiddleClicked
);
209 toolBar()->installEventFilter(middleClickEventFilter
);
213 connect(KSycoca::self(), &KSycoca::databaseChanged
, this, &DolphinMainWindow::updateOpenPreferredSearchToolAction
);
215 QTimer::singleShot(0, this, &DolphinMainWindow::updateOpenPreferredSearchToolAction
);
217 m_fileItemActions
.setParentWidget(this);
218 connect(&m_fileItemActions
, &KFileItemActions::error
, this, [this](const QString
&errorMessage
) {
219 showErrorMessage(errorMessage
);
222 connect(GeneralSettings::self(), &GeneralSettings::splitViewChanged
, this, &DolphinMainWindow::slotSplitViewChanged
);
225 DolphinMainWindow::~DolphinMainWindow()
227 // This fixes a crash on Wayland when closing the mainwindow while another dialog is open.
228 disconnect(QGuiApplication::clipboard(), &QClipboard::dataChanged
, this, &DolphinMainWindow::updatePasteAction
);
231 QVector
<DolphinViewContainer
*> DolphinMainWindow::viewContainers() const
233 QVector
<DolphinViewContainer
*> viewContainers
;
235 for (int i
= 0; i
< m_tabWidget
->count(); ++i
) {
236 DolphinTabPage
*tabPage
= m_tabWidget
->tabPageAt(i
);
238 viewContainers
<< tabPage
->primaryViewContainer();
239 if (tabPage
->splitViewEnabled()) {
240 viewContainers
<< tabPage
->secondaryViewContainer();
243 return viewContainers
;
246 void DolphinMainWindow::openDirectories(const QList
<QUrl
> &dirs
, bool splitView
)
248 m_tabWidget
->openDirectories(dirs
, splitView
);
251 void DolphinMainWindow::openDirectories(const QStringList
&dirs
, bool splitView
)
253 openDirectories(QUrl::fromStringList(dirs
), splitView
);
256 void DolphinMainWindow::openFiles(const QList
<QUrl
> &files
, bool splitView
)
258 m_tabWidget
->openFiles(files
, splitView
);
261 bool DolphinMainWindow::isFoldersPanelEnabled() const
263 return actionCollection()->action(QStringLiteral("show_folders_panel"))->isChecked();
266 bool DolphinMainWindow::isInformationPanelEnabled() const
269 return actionCollection()->action(QStringLiteral("show_information_panel"))->isChecked();
275 bool DolphinMainWindow::isSplitViewEnabledInCurrentTab() const
277 return m_tabWidget
->currentTabPage()->splitViewEnabled();
280 void DolphinMainWindow::openFiles(const QStringList
&files
, bool splitView
)
282 openFiles(QUrl::fromStringList(files
), splitView
);
285 void DolphinMainWindow::activateWindow(const QString
&activationToken
)
287 window()->setAttribute(Qt::WA_NativeWindow
, true);
289 if (KWindowSystem::isPlatformWayland()) {
290 KWindowSystem::setCurrentXdgActivationToken(activationToken
);
291 } else if (KWindowSystem::isPlatformX11()) {
293 KStartupInfo::setNewStartupId(window()->windowHandle(), activationToken
.toUtf8());
297 KWindowSystem::activateWindow(window()->windowHandle());
300 bool DolphinMainWindow::isActiveWindow()
302 return window()->isActiveWindow();
305 void DolphinMainWindow::showCommand(CommandType command
)
307 DolphinStatusBar
*statusBar
= m_activeViewContainer
->statusBar();
309 case KIO::FileUndoManager::Copy
:
310 statusBar
->setText(i18nc("@info:status", "Successfully copied."));
312 case KIO::FileUndoManager::Move
:
313 statusBar
->setText(i18nc("@info:status", "Successfully moved."));
315 case KIO::FileUndoManager::Link
:
316 statusBar
->setText(i18nc("@info:status", "Successfully linked."));
318 case KIO::FileUndoManager::Trash
:
319 statusBar
->setText(i18nc("@info:status", "Successfully moved to trash."));
321 case KIO::FileUndoManager::Rename
:
322 statusBar
->setText(i18nc("@info:status", "Successfully renamed."));
325 case KIO::FileUndoManager::Mkdir
:
326 statusBar
->setText(i18nc("@info:status", "Created folder."));
334 void DolphinMainWindow::pasteIntoFolder()
336 m_activeViewContainer
->view()->pasteIntoFolder();
339 void DolphinMainWindow::changeUrl(const QUrl
&url
)
341 if (!KProtocolManager::supportsListing(url
)) {
342 // The URL navigator only checks for validity, not
343 // if the URL can be listed. An error message is
344 // shown due to DolphinViewContainer::restoreView().
348 m_activeViewContainer
->setUrl(url
);
349 updateFileAndEditActions();
354 Q_EMIT
urlChanged(url
);
357 void DolphinMainWindow::slotTerminalDirectoryChanged(const QUrl
&url
)
359 if (m_tearDownFromPlacesRequested
&& url
== QUrl::fromLocalFile(QDir::homePath())) {
360 m_placesPanel
->proceedWithTearDown();
361 m_tearDownFromPlacesRequested
= false;
364 m_activeViewContainer
->setAutoGrabFocus(false);
366 m_activeViewContainer
->setAutoGrabFocus(true);
369 void DolphinMainWindow::slotEditableStateChanged(bool editable
)
371 KToggleAction
*editableLocationAction
= static_cast<KToggleAction
*>(actionCollection()->action(QStringLiteral("editable_location")));
372 editableLocationAction
->setChecked(editable
);
375 void DolphinMainWindow::slotSelectionChanged(const KFileItemList
&selection
)
377 updateFileAndEditActions();
379 const int selectedUrlsCount
= m_tabWidget
->currentTabPage()->selectedItemsCount();
381 QAction
*compareFilesAction
= actionCollection()->action(QStringLiteral("compare_files"));
382 if (selectedUrlsCount
== 2) {
383 compareFilesAction
->setEnabled(isKompareInstalled());
385 compareFilesAction
->setEnabled(false);
388 Q_EMIT
selectionChanged(selection
);
391 void DolphinMainWindow::updateHistory()
393 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
394 const int index
= urlNavigator
->historyIndex();
396 QAction
*backAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Back
));
398 backAction
->setToolTip(i18nc("@info", "Go back"));
399 backAction
->setWhatsThis(i18nc("@info:whatsthis go back", "Return to the previously viewed folder."));
400 backAction
->setEnabled(index
< urlNavigator
->historySize() - 1);
403 QAction
*forwardAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Forward
));
405 forwardAction
->setToolTip(i18nc("@info", "Go forward"));
406 forwardAction
->setWhatsThis(xi18nc("@info:whatsthis go forward", "This undoes a <interface>Go|Back</interface> action."));
407 forwardAction
->setEnabled(index
> 0);
411 void DolphinMainWindow::updateFilterBarAction(bool show
)
413 QAction
*toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
414 toggleFilterBarAction
->setChecked(show
);
417 void DolphinMainWindow::openNewMainWindow()
419 Dolphin::openNewWindow({m_activeViewContainer
->url()}, this);
422 void DolphinMainWindow::openNewActivatedTab()
424 // keep browsers compatibility, new tab is always after last one
425 auto openNewTabAfterLastTabConfigured
= GeneralSettings::openNewTabAfterLastTab();
426 GeneralSettings::setOpenNewTabAfterLastTab(true);
427 m_tabWidget
->openNewActivatedTab();
428 GeneralSettings::setOpenNewTabAfterLastTab(openNewTabAfterLastTabConfigured
);
431 void DolphinMainWindow::addToPlaces()
436 // If nothing is selected, act on the current dir
437 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
438 url
= m_activeViewContainer
->url();
439 name
= m_activeViewContainer
->placesText();
441 const auto dirToAdd
= m_activeViewContainer
->view()->selectedItems().first();
442 url
= dirToAdd
.url();
443 name
= dirToAdd
.name();
447 if (m_activeViewContainer
->isSearchModeEnabled()) {
448 icon
= QStringLiteral("folder-saved-search-symbolic");
450 icon
= KIO::iconNameForUrl(url
);
452 DolphinPlacesModelSingleton::instance().placesModel()->addPlace(name
, url
, icon
);
456 void DolphinMainWindow::openNewTab(const QUrl
&url
)
458 m_tabWidget
->openNewTab(url
, QUrl());
461 void DolphinMainWindow::openNewTabAndActivate(const QUrl
&url
)
463 m_tabWidget
->openNewActivatedTab(url
, QUrl());
466 void DolphinMainWindow::openNewWindow(const QUrl
&url
)
468 Dolphin::openNewWindow({url
}, this);
471 void DolphinMainWindow::slotSplitViewChanged()
473 m_tabWidget
->currentTabPage()->setSplitViewEnabled(GeneralSettings::splitView(), WithAnimation
);
474 updateSplitActions();
477 void DolphinMainWindow::openInNewTab()
479 const KFileItemList
&list
= m_activeViewContainer
->view()->selectedItems();
480 bool tabCreated
= false;
482 for (const KFileItem
&item
: list
) {
483 const QUrl
&url
= DolphinView::openItemAsFolderUrl(item
);
484 if (!url
.isEmpty()) {
490 // if no new tab has been created from the selection
491 // open the current directory in a new tab
493 openNewTab(m_activeViewContainer
->url());
497 void DolphinMainWindow::openInNewWindow()
501 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
502 if (list
.isEmpty()) {
503 newWindowUrl
= m_activeViewContainer
->url();
504 } else if (list
.count() == 1) {
505 const KFileItem
&item
= list
.first();
506 newWindowUrl
= DolphinView::openItemAsFolderUrl(item
);
509 if (!newWindowUrl
.isEmpty()) {
510 Dolphin::openNewWindow({newWindowUrl
}, this);
514 void DolphinMainWindow::openInSplitView(const QUrl
&url
)
516 QUrl newSplitViewUrl
= url
;
518 if (newSplitViewUrl
.isEmpty()) {
519 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
520 if (list
.count() == 1) {
521 const KFileItem
&item
= list
.first();
522 newSplitViewUrl
= DolphinView::openItemAsFolderUrl(item
);
526 if (newSplitViewUrl
.isEmpty()) {
530 DolphinTabPage
*tabPage
= m_tabWidget
->currentTabPage();
531 if (tabPage
->splitViewEnabled()) {
532 tabPage
->switchActiveView();
533 tabPage
->activeViewContainer()->setUrl(newSplitViewUrl
);
535 tabPage
->setSplitViewEnabled(true, WithAnimation
, newSplitViewUrl
);
540 void DolphinMainWindow::showTarget()
542 const KFileItem link
= m_activeViewContainer
->view()->selectedItems().at(0);
543 const QUrl destinationUrl
= link
.url().resolved(QUrl(link
.linkDest()));
545 auto job
= KIO::stat(destinationUrl
, KIO::StatJob::SourceSide
, KIO::StatNoDetails
);
547 connect(job
, &KJob::finished
, this, [this, destinationUrl
](KJob
*job
) {
548 KIO::StatJob
*statJob
= static_cast<KIO::StatJob
*>(job
);
550 if (statJob
->error()) {
551 m_activeViewContainer
->showMessage(job
->errorString(), DolphinViewContainer::Error
);
553 KIO::highlightInFileManager({destinationUrl
});
558 bool DolphinMainWindow::event(QEvent
*event
)
560 if (event
->type() == QEvent::ShortcutOverride
) {
561 const QKeyEvent
*keyEvent
= static_cast<QKeyEvent
*>(event
);
562 if (keyEvent
->key() == Qt::Key_Space
&& m_activeViewContainer
->view()->handleSpaceAsNormalKey()) {
568 return KXmlGuiWindow::event(event
);
571 void DolphinMainWindow::showEvent(QShowEvent
*event
)
573 KXmlGuiWindow::showEvent(event
);
575 if (!event
->spontaneous()) {
576 m_activeViewContainer
->view()->setFocus();
580 void DolphinMainWindow::closeEvent(QCloseEvent
*event
)
582 // Find out if Dolphin is closed directly by the user or
583 // by the session manager because the session is closed
584 bool closedByUser
= true;
585 if (qApp
->isSavingSession()) {
586 closedByUser
= false;
589 if (m_tabWidget
->count() > 1 && GeneralSettings::confirmClosingMultipleTabs() && !GeneralSettings::rememberOpenedTabs() && closedByUser
) {
590 // Ask the user if he really wants to quit and close all tabs.
591 // Open a confirmation dialog with 3 buttons:
592 // QDialogButtonBox::Yes -> Quit
593 // QDialogButtonBox::No -> Close only the current tab
594 // QDialogButtonBox::Cancel -> do nothing
595 QDialog
*dialog
= new QDialog(this, Qt::Dialog
);
596 dialog
->setWindowTitle(i18nc("@title:window", "Confirmation"));
597 dialog
->setModal(true);
598 QDialogButtonBox
*buttons
= new QDialogButtonBox(QDialogButtonBox::Yes
| QDialogButtonBox::No
| QDialogButtonBox::Cancel
);
599 KGuiItem::assign(buttons
->button(QDialogButtonBox::Yes
),
600 KGuiItem(i18nc("@action:button 'Quit Dolphin' button", "&Quit %1", QGuiApplication::applicationDisplayName()),
601 QIcon::fromTheme(QStringLiteral("application-exit"))));
602 KGuiItem::assign(buttons
->button(QDialogButtonBox::No
), KGuiItem(i18n("C&lose Current Tab"), QIcon::fromTheme(QStringLiteral("tab-close"))));
603 KGuiItem::assign(buttons
->button(QDialogButtonBox::Cancel
), KStandardGuiItem::cancel());
604 buttons
->button(QDialogButtonBox::Yes
)->setDefault(true);
606 bool doNotAskAgainCheckboxResult
= false;
608 const auto result
= KMessageBox::createKMessageBox(dialog
,
610 QMessageBox::Warning
,
611 i18n("You have multiple tabs open in this window, are you sure you want to quit?"),
613 i18n("Do not ask again"),
614 &doNotAskAgainCheckboxResult
,
615 KMessageBox::Notify
);
617 if (doNotAskAgainCheckboxResult
) {
618 GeneralSettings::setConfirmClosingMultipleTabs(false);
622 case QDialogButtonBox::Yes
:
625 case QDialogButtonBox::No
:
626 // Close only the current tab
627 m_tabWidget
->closeTab();
635 if (m_terminalPanel
&& m_terminalPanel
->hasProgramRunning() && GeneralSettings::confirmClosingTerminalRunningProgram() && closedByUser
) {
636 // Ask if the user really wants to quit Dolphin with a program that is still running in the Terminal panel
637 // Open a confirmation dialog with 3 buttons:
638 // QDialogButtonBox::Yes -> Quit
639 // QDialogButtonBox::No -> Show Terminal Panel
640 // QDialogButtonBox::Cancel -> do nothing
641 QDialog
*dialog
= new QDialog(this, Qt::Dialog
);
642 dialog
->setWindowTitle(i18nc("@title:window", "Confirmation"));
643 dialog
->setModal(true);
644 auto standardButtons
= QDialogButtonBox::Yes
| QDialogButtonBox::Cancel
;
645 if (!m_terminalPanel
->isVisible()) {
646 standardButtons
|= QDialogButtonBox::No
;
648 QDialogButtonBox
*buttons
= new QDialogButtonBox(standardButtons
);
649 KGuiItem::assign(buttons
->button(QDialogButtonBox::Yes
), KStandardGuiItem::quit());
650 if (!m_terminalPanel
->isVisible()) {
651 KGuiItem::assign(buttons
->button(QDialogButtonBox::No
), KGuiItem(i18n("Show &Terminal Panel"), QIcon::fromTheme(QStringLiteral("dialog-scripts"))));
653 KGuiItem::assign(buttons
->button(QDialogButtonBox::Cancel
), KStandardGuiItem::cancel());
655 bool doNotAskAgainCheckboxResult
= false;
657 const auto result
= KMessageBox::createKMessageBox(
660 QMessageBox::Warning
,
661 i18n("The program '%1' is still running in the Terminal panel. Are you sure you want to quit?", m_terminalPanel
->runningProgramName()),
663 i18n("Do not ask again"),
664 &doNotAskAgainCheckboxResult
,
665 KMessageBox::Notify
| KMessageBox::Dangerous
);
667 if (doNotAskAgainCheckboxResult
) {
668 GeneralSettings::setConfirmClosingTerminalRunningProgram(false);
672 case QDialogButtonBox::Yes
:
675 case QDialogButtonBox::No
:
676 actionCollection()->action("show_terminal_panel")->trigger();
677 // Do not quit, ignore quit event
685 if (m_sessionSaveTimer
&& (m_sessionSaveTimer
->isActive() || m_sessionSaveWatcher
->isRunning())) {
686 const bool sessionSaveTimerActive
= m_sessionSaveTimer
->isActive();
688 m_sessionSaveTimer
->stop();
689 m_sessionSaveWatcher
->disconnect();
690 m_sessionSaveWatcher
->waitForFinished();
692 if (sessionSaveTimerActive
|| m_sessionSaveScheduled
) {
697 GeneralSettings::setVersion(CurrentDolphinVersion
);
698 GeneralSettings::self()->save();
700 KXmlGuiWindow::closeEvent(event
);
703 void DolphinMainWindow::slotSaveSession()
705 m_sessionSaveScheduled
= false;
707 if (m_sessionSaveWatcher
->isRunning()) {
708 // The previous session is still being saved - schedule another save.
709 m_sessionSaveWatcher
->disconnect();
710 connect(m_sessionSaveWatcher
, &QFutureWatcher
<void>::finished
, this, &DolphinMainWindow::slotSaveSession
, Qt::SingleShotConnection
);
711 m_sessionSaveScheduled
= true;
712 } else if (!m_sessionSaveTimer
->isActive()) {
713 // No point in saving the session if the timer is running (since it will save the session again when it times out).
714 KConfigGui::setSessionConfig(QStringLiteral("dolphin"), QStringLiteral("dolphin"));
715 KConfig
*config
= KConfigGui::sessionConfig();
716 saveGlobalProperties(config
);
717 savePropertiesInternal(config
, 1);
719 auto future
= QtConcurrent::run([config
]() {
722 m_sessionSaveWatcher
->setFuture(future
);
726 void DolphinMainWindow::setSessionAutoSaveEnabled(bool enable
)
729 if (!m_sessionSaveTimer
) {
730 m_sessionSaveTimer
= new QTimer(this);
731 m_sessionSaveWatcher
= new QFutureWatcher
<void>(this);
732 m_sessionSaveTimer
->setSingleShot(true);
733 m_sessionSaveTimer
->setInterval(22000);
735 connect(m_sessionSaveTimer
, &QTimer::timeout
, this, &DolphinMainWindow::slotSaveSession
);
738 connect(m_tabWidget
, &DolphinTabWidget::urlChanged
, m_sessionSaveTimer
, qOverload
<>(&QTimer::start
), Qt::UniqueConnection
);
739 connect(m_tabWidget
, &DolphinTabWidget::tabCountChanged
, m_sessionSaveTimer
, qOverload
<>(&QTimer::start
), Qt::UniqueConnection
);
740 connect(m_tabWidget
, &DolphinTabWidget::activeViewChanged
, m_sessionSaveTimer
, qOverload
<>(&QTimer::start
), Qt::UniqueConnection
);
741 } else if (m_sessionSaveTimer
) {
742 m_sessionSaveTimer
->stop();
743 m_sessionSaveWatcher
->disconnect();
744 m_sessionSaveScheduled
= false;
746 m_sessionSaveWatcher
->waitForFinished();
748 m_sessionSaveTimer
->deleteLater();
749 m_sessionSaveWatcher
->deleteLater();
750 m_sessionSaveTimer
= nullptr;
751 m_sessionSaveWatcher
= nullptr;
755 void DolphinMainWindow::saveProperties(KConfigGroup
&group
)
757 m_tabWidget
->saveProperties(group
);
760 void DolphinMainWindow::readProperties(const KConfigGroup
&group
)
762 m_tabWidget
->readProperties(group
);
765 void DolphinMainWindow::updateNewMenu()
767 m_newFileMenu
->checkUpToDate();
768 m_newFileMenu
->setWorkingDirectory(activeViewContainer()->url());
771 void DolphinMainWindow::createDirectory()
773 m_newFileMenu
->setWorkingDirectory(activeViewContainer()->url());
774 m_newFileMenu
->createDirectory();
777 void DolphinMainWindow::quit()
782 void DolphinMainWindow::showErrorMessage(const QString
&message
)
784 m_activeViewContainer
->showMessage(message
, DolphinViewContainer::Error
);
787 void DolphinMainWindow::slotUndoAvailable(bool available
)
789 QAction
*undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
791 undoAction
->setEnabled(available
);
795 void DolphinMainWindow::slotUndoTextChanged(const QString
&text
)
797 QAction
*undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
799 undoAction
->setText(text
);
803 void DolphinMainWindow::undo()
806 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
807 KIO::FileUndoManager::self()->undo();
810 void DolphinMainWindow::cut()
812 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
813 m_activeViewContainer
->setSelectionModeEnabled(true, actionCollection(), SelectionMode::BottomBar::Contents::CutContents
);
815 m_activeViewContainer
->view()->cutSelectedItemsToClipboard();
816 m_activeViewContainer
->setSelectionModeEnabled(false);
820 void DolphinMainWindow::copy()
822 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
823 m_activeViewContainer
->setSelectionModeEnabled(true, actionCollection(), SelectionMode::BottomBar::Contents::CopyContents
);
825 m_activeViewContainer
->view()->copySelectedItemsToClipboard();
826 m_activeViewContainer
->setSelectionModeEnabled(false);
830 void DolphinMainWindow::paste()
832 m_activeViewContainer
->view()->paste();
835 void DolphinMainWindow::find()
837 m_activeViewContainer
->setSearchModeEnabled(true);
840 void DolphinMainWindow::updateSearchAction()
842 QAction
*toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
843 toggleSearchAction
->setChecked(m_activeViewContainer
->isSearchModeEnabled());
846 void DolphinMainWindow::updatePasteAction()
848 QAction
*pasteAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Paste
));
849 QPair
<bool, QString
> pasteInfo
= m_activeViewContainer
->view()->pasteInfo();
850 pasteAction
->setEnabled(pasteInfo
.first
);
851 pasteAction
->setText(pasteInfo
.second
);
854 void DolphinMainWindow::slotDirectoryLoadingCompleted()
859 void DolphinMainWindow::slotToolBarActionMiddleClicked(QAction
*action
)
861 if (action
== actionCollection()->action(KStandardAction::name(KStandardAction::Back
))) {
863 } else if (action
== actionCollection()->action(KStandardAction::name(KStandardAction::Forward
))) {
865 } else if (action
== actionCollection()->action(QStringLiteral("go_up"))) {
867 } else if (action
== actionCollection()->action(QStringLiteral("go_home"))) {
872 QAction
*DolphinMainWindow::urlNavigatorHistoryAction(const KUrlNavigator
*urlNavigator
, int historyIndex
, QObject
*parent
)
874 const QUrl url
= urlNavigator
->locationUrl(historyIndex
);
876 QString text
= url
.toDisplayString(QUrl::PreferLocalFile
);
878 if (!urlNavigator
->showFullPath()) {
879 const KFilePlacesModel
*placesModel
= DolphinPlacesModelSingleton::instance().placesModel();
881 const QModelIndex closestIdx
= placesModel
->closestItem(url
);
882 if (closestIdx
.isValid()) {
883 const QUrl placeUrl
= placesModel
->url(closestIdx
);
885 text
= placesModel
->text(closestIdx
);
887 QString pathInsidePlace
= url
.path().mid(placeUrl
.path().length());
889 if (!pathInsidePlace
.isEmpty() && !pathInsidePlace
.startsWith(QLatin1Char('/'))) {
890 pathInsidePlace
.prepend(QLatin1Char('/'));
893 if (pathInsidePlace
!= QLatin1Char('/')) {
894 text
.append(pathInsidePlace
);
899 QAction
*action
= new QAction(QIcon::fromTheme(KIO::iconNameForUrl(url
)), text
, parent
);
900 action
->setData(historyIndex
);
904 void DolphinMainWindow::slotAboutToShowBackPopupMenu()
906 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
908 QMenu
*menu
= m_backAction
->popupMenu();
910 for (int i
= urlNavigator
->historyIndex() + 1; i
< urlNavigator
->historySize() && entries
< MaxNumberOfNavigationentries
; ++i
, ++entries
) {
911 QAction
*action
= urlNavigatorHistoryAction(urlNavigator
, i
, menu
);
912 menu
->addAction(action
);
916 void DolphinMainWindow::slotGoBack(QAction
*action
)
918 int gotoIndex
= action
->data().value
<int>();
919 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
920 for (int i
= gotoIndex
- urlNavigator
->historyIndex(); i
> 0; --i
) {
925 void DolphinMainWindow::slotBackForwardActionMiddleClicked(QAction
*action
)
928 const KUrlNavigator
*urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
929 openNewTab(urlNavigator
->locationUrl(action
->data().value
<int>()));
933 void DolphinMainWindow::slotAboutToShowForwardPopupMenu()
935 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
937 QMenu
*menu
= m_forwardAction
->popupMenu();
938 for (int i
= urlNavigator
->historyIndex() - 1; i
>= 0 && entries
< MaxNumberOfNavigationentries
; --i
, ++entries
) {
939 QAction
*action
= urlNavigatorHistoryAction(urlNavigator
, i
, menu
);
940 menu
->addAction(action
);
944 void DolphinMainWindow::slotGoForward(QAction
*action
)
946 int gotoIndex
= action
->data().value
<int>();
947 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
948 for (int i
= urlNavigator
->historyIndex() - gotoIndex
; i
> 0; --i
) {
953 void DolphinMainWindow::slotSetSelectionMode(bool enabled
, SelectionMode::BottomBar::Contents bottomBarContents
)
955 m_activeViewContainer
->setSelectionModeEnabled(enabled
, actionCollection(), bottomBarContents
);
958 void DolphinMainWindow::selectAll()
962 // if the URL navigator is editable and focused, select the whole
963 // URL instead of all items of the view
965 KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigator();
966 QLineEdit
*lineEdit
= urlNavigator
->editor()->lineEdit();
967 const bool selectUrl
= urlNavigator
->isUrlEditable() && lineEdit
->hasFocus();
969 lineEdit
->selectAll();
971 m_activeViewContainer
->view()->selectAll();
975 void DolphinMainWindow::invertSelection()
978 m_activeViewContainer
->view()->invertSelection();
981 void DolphinMainWindow::toggleSplitView()
983 DolphinTabPage
*tabPage
= m_tabWidget
->currentTabPage();
984 tabPage
->setSplitViewEnabled(!tabPage
->splitViewEnabled(), WithAnimation
);
985 m_tabWidget
->updateTabName(m_tabWidget
->indexOf(tabPage
));
989 void DolphinMainWindow::popoutSplitView()
991 DolphinTabPage
*tabPage
= m_tabWidget
->currentTabPage();
992 if (!tabPage
->splitViewEnabled())
994 openNewWindow((GeneralSettings::closeActiveSplitView() ? tabPage
->activeViewContainer() : tabPage
->inactiveViewContainer())->url());
995 tabPage
->setSplitViewEnabled(false, WithAnimation
);
996 updateSplitActions();
999 void DolphinMainWindow::toggleSplitStash()
1001 DolphinTabPage
*tabPage
= m_tabWidget
->currentTabPage();
1002 tabPage
->setSplitViewEnabled(false, WithAnimation
);
1003 tabPage
->setSplitViewEnabled(true, WithAnimation
, QUrl("stash:/"));
1006 void DolphinMainWindow::copyToInactiveSplitView()
1008 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
1009 m_activeViewContainer
->setSelectionModeEnabled(true, actionCollection(), SelectionMode::BottomBar::Contents::CopyToOtherViewContents
);
1011 m_tabWidget
->copyToInactiveSplitView();
1012 m_activeViewContainer
->setSelectionModeEnabled(false);
1016 void DolphinMainWindow::moveToInactiveSplitView()
1018 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
1019 m_activeViewContainer
->setSelectionModeEnabled(true, actionCollection(), SelectionMode::BottomBar::Contents::MoveToOtherViewContents
);
1021 m_tabWidget
->moveToInactiveSplitView();
1022 m_activeViewContainer
->setSelectionModeEnabled(false);
1026 void DolphinMainWindow::reloadView()
1029 m_activeViewContainer
->reload();
1030 m_activeViewContainer
->statusBar()->updateSpaceInfo();
1033 void DolphinMainWindow::stopLoading()
1035 m_activeViewContainer
->view()->stopLoading();
1038 void DolphinMainWindow::enableStopAction()
1040 actionCollection()->action(QStringLiteral("stop"))->setEnabled(true);
1043 void DolphinMainWindow::disableStopAction()
1045 actionCollection()->action(QStringLiteral("stop"))->setEnabled(false);
1048 void DolphinMainWindow::toggleSelectionMode()
1050 const bool checked
= !m_activeViewContainer
->isSelectionModeEnabled();
1052 m_activeViewContainer
->setSelectionModeEnabled(checked
, actionCollection(), SelectionMode::BottomBar::Contents::GeneralContents
);
1053 actionCollection()->action(QStringLiteral("toggle_selection_mode"))->setChecked(checked
);
1056 void DolphinMainWindow::showFilterBar()
1058 m_activeViewContainer
->setFilterBarVisible(true);
1061 void DolphinMainWindow::toggleFilterBar()
1063 const bool checked
= !m_activeViewContainer
->isFilterBarVisible();
1064 m_activeViewContainer
->setFilterBarVisible(checked
);
1066 QAction
*toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
1067 toggleFilterBarAction
->setChecked(checked
);
1070 void DolphinMainWindow::toggleEditLocation()
1074 QAction
*action
= actionCollection()->action(QStringLiteral("editable_location"));
1075 KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigator();
1076 urlNavigator
->setUrlEditable(action
->isChecked());
1079 void DolphinMainWindow::replaceLocation()
1081 KUrlNavigator
*navigator
= m_activeViewContainer
->urlNavigator();
1082 QLineEdit
*lineEdit
= navigator
->editor()->lineEdit();
1084 // If the text field currently has focus and everything is selected,
1085 // pressing the keyboard shortcut returns the whole thing to breadcrumb mode
1086 if (navigator
->isUrlEditable() && lineEdit
->hasFocus() && lineEdit
->selectedText() == lineEdit
->text()) {
1087 navigator
->setUrlEditable(false);
1089 navigator
->setUrlEditable(true);
1090 navigator
->setFocus();
1091 lineEdit
->selectAll();
1095 void DolphinMainWindow::togglePanelLockState()
1097 const bool newLockState
= !GeneralSettings::lockPanels();
1098 const auto childrenObjects
= children();
1099 for (QObject
*child
: childrenObjects
) {
1100 DolphinDockWidget
*dock
= qobject_cast
<DolphinDockWidget
*>(child
);
1102 dock
->setLocked(newLockState
);
1106 DolphinPlacesModelSingleton::instance().placesModel()->setPanelsLocked(newLockState
);
1108 GeneralSettings::setLockPanels(newLockState
);
1111 void DolphinMainWindow::slotTerminalPanelVisibilityChanged()
1113 if (m_terminalPanel
->isHiddenInVisibleWindow() && m_activeViewContainer
) {
1114 m_activeViewContainer
->view()->setFocus();
1118 void DolphinMainWindow::goBack()
1120 DolphinUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
1121 urlNavigator
->goBack();
1123 if (urlNavigator
->locationState().isEmpty()) {
1124 // An empty location state indicates a redirection URL,
1125 // which must be skipped too
1126 urlNavigator
->goBack();
1130 void DolphinMainWindow::goForward()
1132 m_activeViewContainer
->urlNavigatorInternalWithHistory()->goForward();
1135 void DolphinMainWindow::goUp()
1137 m_activeViewContainer
->urlNavigatorInternalWithHistory()->goUp();
1140 void DolphinMainWindow::goHome()
1142 m_activeViewContainer
->urlNavigatorInternalWithHistory()->goHome();
1145 void DolphinMainWindow::goBackInNewTab()
1147 const KUrlNavigator
*urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
1148 const int index
= urlNavigator
->historyIndex() + 1;
1149 openNewTab(urlNavigator
->locationUrl(index
));
1152 void DolphinMainWindow::goForwardInNewTab()
1154 const KUrlNavigator
*urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
1155 const int index
= urlNavigator
->historyIndex() - 1;
1156 openNewTab(urlNavigator
->locationUrl(index
));
1159 void DolphinMainWindow::goUpInNewTab()
1161 const QUrl currentUrl
= activeViewContainer()->urlNavigator()->locationUrl();
1162 openNewTab(KIO::upUrl(currentUrl
));
1165 void DolphinMainWindow::goHomeInNewTab()
1167 openNewTab(Dolphin::homeUrl());
1170 void DolphinMainWindow::compareFiles()
1172 const KFileItemList items
= m_tabWidget
->currentTabPage()->selectedItems();
1173 if (items
.count() != 2) {
1174 // The action is disabled in this case, but it could have been triggered
1175 // via D-Bus, see https://bugs.kde.org/show_bug.cgi?id=325517
1179 QUrl urlA
= items
.at(0).url();
1180 QUrl urlB
= items
.at(1).url();
1182 QString
command(QStringLiteral("kompare -c \""));
1183 command
.append(urlA
.toDisplayString(QUrl::PreferLocalFile
));
1184 command
.append("\" \"");
1185 command
.append(urlB
.toDisplayString(QUrl::PreferLocalFile
));
1186 command
.append('\"');
1188 KIO::CommandLauncherJob
*job
= new KIO::CommandLauncherJob(command
, this);
1189 job
->setDesktopName(QStringLiteral("org.kde.kompare"));
1193 void DolphinMainWindow::toggleShowMenuBar()
1195 const bool visible
= menuBar()->isVisible();
1196 menuBar()->setVisible(!visible
);
1199 QPointer
<QAction
> DolphinMainWindow::preferredSearchTool()
1201 m_searchTools
.clear();
1203 KService::Ptr kfind
= KService::serviceByDesktopName(QStringLiteral("org.kde.kfind"));
1209 auto *action
= new QAction(QIcon::fromTheme(kfind
->icon()), kfind
->name(), this);
1211 connect(action
, &QAction::triggered
, this, [kfind
] {
1212 auto *job
= new KIO::ApplicationLauncherJob(kfind
);
1219 void DolphinMainWindow::updateOpenPreferredSearchToolAction()
1221 QAction
*openPreferredSearchTool
= actionCollection()->action(QStringLiteral("open_preferred_search_tool"));
1222 if (!openPreferredSearchTool
) {
1225 QPointer
<QAction
> tool
= preferredSearchTool();
1227 openPreferredSearchTool
->setVisible(true);
1228 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open %1", tool
->text()));
1229 // Only override with the app icon if it is the default, i.e. the user hasn't configured one manually
1230 // https://bugs.kde.org/show_bug.cgi?id=442815
1231 if (openPreferredSearchTool
->icon().name() == QLatin1String("search")) {
1232 openPreferredSearchTool
->setIcon(tool
->icon());
1235 openPreferredSearchTool
->setVisible(false);
1236 // still visible in Shortcuts configuration window
1237 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool"));
1238 openPreferredSearchTool
->setIcon(QIcon::fromTheme(QStringLiteral("search")));
1242 void DolphinMainWindow::openPreferredSearchTool()
1244 QPointer
<QAction
> tool
= preferredSearchTool();
1250 void DolphinMainWindow::openTerminal()
1252 openTerminalJob(m_activeViewContainer
->url());
1255 void DolphinMainWindow::openTerminalHere()
1257 QList
<QUrl
> urls
= {};
1259 const auto selectedItems
= m_activeViewContainer
->view()->selectedItems();
1260 for (const KFileItem
&item
: selectedItems
) {
1261 QUrl url
= item
.targetUrl();
1262 if (item
.isFile()) {
1263 url
.setPath(QFileInfo(url
.path()).absolutePath());
1265 if (!urls
.contains(url
)) {
1270 // No items are selected. Open a terminal window for the current location.
1271 if (urls
.count() == 0) {
1276 if (urls
.count() > 5) {
1277 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());
1278 const int answer
= KMessageBox::warningContinueCancel(
1282 KGuiItem(i18ncp("@action:button", "Open %1 Terminal", "Open %1 Terminals", urls
.count()), QStringLiteral("utilities-terminal")),
1283 KStandardGuiItem::cancel(),
1284 QStringLiteral("ConfirmOpenManyTerminals"));
1285 if (answer
!= KMessageBox::PrimaryAction
&& answer
!= KMessageBox::Continue
) {
1290 for (const QUrl
&url
: std::as_const(urls
)) {
1291 openTerminalJob(url
);
1295 void DolphinMainWindow::openTerminalJob(const QUrl
&url
)
1297 if (url
.isLocalFile()) {
1298 auto job
= new KTerminalLauncherJob(QString());
1299 job
->setWorkingDirectory(url
.toLocalFile());
1304 // Not a local file, with protocol Class ":local", try stat'ing
1305 if (KProtocolInfo::protocolClass(url
.scheme()) == QLatin1String(":local")) {
1306 KIO::StatJob
*job
= KIO::mostLocalUrl(url
);
1307 KJobWidgets::setWindow(job
, this);
1308 connect(job
, &KJob::result
, this, [job
]() {
1310 if (!job
->error()) {
1311 statUrl
= job
->mostLocalUrl();
1314 auto job
= new KTerminalLauncherJob(QString());
1315 job
->setWorkingDirectory(statUrl
.isLocalFile() ? statUrl
.toLocalFile() : QDir::homePath());
1322 // Nothing worked, just use $HOME
1323 auto job
= new KTerminalLauncherJob(QString());
1324 job
->setWorkingDirectory(QDir::homePath());
1328 void DolphinMainWindow::editSettings()
1330 if (!m_settingsDialog
) {
1331 DolphinViewContainer
*container
= activeViewContainer();
1332 container
->view()->writeSettings();
1334 const QUrl url
= container
->url();
1335 DolphinSettingsDialog
*settingsDialog
= new DolphinSettingsDialog(url
, this, actionCollection());
1336 connect(settingsDialog
, &DolphinSettingsDialog::settingsChanged
, this, &DolphinMainWindow::refreshViews
);
1337 connect(settingsDialog
, &DolphinSettingsDialog::settingsChanged
, &DolphinUrlNavigatorsController::slotReadSettings
);
1338 settingsDialog
->setAttribute(Qt::WA_DeleteOnClose
);
1339 settingsDialog
->show();
1340 m_settingsDialog
= settingsDialog
;
1342 m_settingsDialog
.data()->raise();
1346 void DolphinMainWindow::handleUrl(const QUrl
&url
)
1348 delete m_lastHandleUrlOpenJob
;
1349 m_lastHandleUrlOpenJob
= nullptr;
1351 if (url
.isLocalFile() && QFileInfo(url
.toLocalFile()).isDir()) {
1352 activeViewContainer()->setUrl(url
);
1354 m_lastHandleUrlOpenJob
= new KIO::OpenUrlJob(url
);
1355 m_lastHandleUrlOpenJob
->setUiDelegate(KIO::createDefaultJobUiDelegate(KJobUiDelegate::AutoHandlingEnabled
, this));
1356 m_lastHandleUrlOpenJob
->setShowOpenOrExecuteDialog(true);
1358 connect(m_lastHandleUrlOpenJob
, &KIO::OpenUrlJob::mimeTypeFound
, this, [this, url
](const QString
&mimetype
) {
1359 if (mimetype
== QLatin1String("inode/directory")) {
1360 // If it's a dir, we'll take it from here
1361 m_lastHandleUrlOpenJob
->kill();
1362 m_lastHandleUrlOpenJob
= nullptr;
1363 activeViewContainer()->setUrl(url
);
1367 connect(m_lastHandleUrlOpenJob
, &KIO::OpenUrlJob::result
, this, [this]() {
1368 m_lastHandleUrlOpenJob
= nullptr;
1371 m_lastHandleUrlOpenJob
->start();
1375 void DolphinMainWindow::slotWriteStateChanged(bool isFolderWritable
)
1377 // trash:/ is writable but we don't want to create new items in it.
1378 // TODO: remove the trash check once https://phabricator.kde.org/T8234 is implemented
1379 newFileMenu()->setEnabled(isFolderWritable
&& m_activeViewContainer
->url().scheme() != QLatin1String("trash"));
1382 void DolphinMainWindow::openContextMenu(const QPoint
&pos
, const KFileItem
&item
, const KFileItemList
&selectedItems
, const QUrl
&url
)
1384 QPointer
<DolphinContextMenu
> contextMenu
= new DolphinContextMenu(this, item
, selectedItems
, url
, &m_fileItemActions
);
1385 contextMenu
->exec(pos
);
1387 // Delete the menu, unless it has been deleted in its own nested event loop already.
1389 contextMenu
->deleteLater();
1393 QMenu
*DolphinMainWindow::createPopupMenu()
1395 QMenu
*menu
= KXmlGuiWindow::createPopupMenu();
1397 menu
->addSeparator();
1398 menu
->addAction(actionCollection()->action(QStringLiteral("lock_panels")));
1403 void DolphinMainWindow::updateHamburgerMenu()
1405 KActionCollection
*ac
= actionCollection();
1406 auto hamburgerMenu
= static_cast<KHamburgerMenu
*>(ac
->action(KStandardAction::name(KStandardAction::HamburgerMenu
)));
1407 auto menu
= hamburgerMenu
->menu();
1409 menu
= new QMenu(this);
1410 hamburgerMenu
->setMenu(menu
);
1411 hamburgerMenu
->hideActionsOf(ac
->action(QStringLiteral("basic_actions"))->menu());
1412 hamburgerMenu
->hideActionsOf(ac
->action(QStringLiteral("zoom"))->menu());
1416 const QList
<QAction
*> toolbarActions
= toolBar()->actions();
1418 if (!toolBar()->isVisible()) {
1419 // If neither the menu bar nor the toolbar are visible, these actions should be available.
1420 menu
->addAction(ac
->action(KStandardAction::name(KStandardAction::ShowMenubar
)));
1421 menu
->addAction(toolBarMenuAction());
1422 menu
->addSeparator();
1425 // This group of actions (until the next separator) contains all the most basic actions
1426 // necessary to use Dolphin effectively.
1427 menu
->addAction(ac
->action(QStringLiteral("go_back")));
1428 menu
->addAction(ac
->action(QStringLiteral("go_forward")));
1430 menu
->addMenu(m_newFileMenu
->menu());
1431 if (!toolBar()->isVisible() || !toolbarActions
.contains(ac
->action(QStringLiteral("toggle_selection_mode_tool_bar")))) {
1432 menu
->addAction(ac
->action(QStringLiteral("toggle_selection_mode")));
1434 menu
->addAction(ac
->action(QStringLiteral("basic_actions")));
1435 menu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Undo
)));
1436 if (!toolBar()->isVisible()
1437 || (!toolbarActions
.contains(ac
->action(QStringLiteral("toggle_search")))
1438 && !toolbarActions
.contains(ac
->action(QStringLiteral("open_preferred_search_tool"))))) {
1439 menu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Find
)));
1440 // This way a search action will only be added if none of the three available
1441 // search actions is present on the toolbar.
1443 if (!toolBar()->isVisible() || !toolbarActions
.contains(ac
->action(QStringLiteral("toggle_filter")))) {
1444 menu
->addAction(ac
->action(QStringLiteral("show_filter_bar")));
1445 // This way a filter action will only be added if none of the two available
1446 // filter actions is present on the toolbar.
1448 menu
->addSeparator();
1450 // The second group of actions (up until the next separator) contains actions for opening
1451 // additional views to interact with the file system.
1452 menu
->addAction(ac
->action(QStringLiteral("file_new")));
1453 menu
->addAction(ac
->action(QStringLiteral("new_tab")));
1454 if (ac
->action(QStringLiteral("undo_close_tab"))->isEnabled()) {
1455 menu
->addAction(ac
->action(QStringLiteral("closed_tabs")));
1457 menu
->addAction(ac
->action(QStringLiteral("open_terminal")));
1458 menu
->addSeparator();
1460 // The third group contains actions to change what one sees in the view
1461 // and to change the more general UI.
1462 if (!toolBar()->isVisible()
1463 || (!toolbarActions
.contains(ac
->action(QStringLiteral("icons"))) && !toolbarActions
.contains(ac
->action(QStringLiteral("compact")))
1464 && !toolbarActions
.contains(ac
->action(QStringLiteral("details"))) && !toolbarActions
.contains(ac
->action(QStringLiteral("view_mode"))))) {
1465 menu
->addAction(ac
->action(QStringLiteral("view_mode")));
1467 menu
->addAction(ac
->action(QStringLiteral("show_hidden_files")));
1468 menu
->addAction(ac
->action(QStringLiteral("sort")));
1469 menu
->addAction(ac
->action(QStringLiteral("additional_info")));
1470 if (!GeneralSettings::showStatusBar() || !GeneralSettings::showZoomSlider()) {
1471 menu
->addAction(ac
->action(QStringLiteral("zoom")));
1473 menu
->addAction(ac
->action(QStringLiteral("panels")));
1475 // The "Configure" menu is not added to the actionCollection() because there is hardly
1476 // a good reason for users to put it on their toolbar.
1477 auto configureMenu
= menu
->addMenu(QIcon::fromTheme(QStringLiteral("configure")), i18nc("@action:inmenu menu for configure actions", "Configure"));
1478 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::SwitchApplicationLanguage
)));
1479 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::KeyBindings
)));
1480 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::ConfigureToolbars
)));
1481 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Preferences
)));
1482 hamburgerMenu
->hideActionsOf(configureMenu
);
1485 void DolphinMainWindow::slotPlaceActivated(const QUrl
&url
)
1487 DolphinViewContainer
*view
= activeViewContainer();
1489 if (view
->url() == url
) {
1490 view
->clearFilterBar(); // Fixes bug 259382.
1492 // We can end up here if the user clicked a device in the Places Panel
1493 // which had been unmounted earlier, see https://bugs.kde.org/show_bug.cgi?id=161385.
1496 view
->disableUrlNavigatorSelectionRequests();
1498 view
->enableUrlNavigatorSelectionRequests();
1502 void DolphinMainWindow::closedTabsCountChanged(unsigned int count
)
1504 actionCollection()->action(QStringLiteral("undo_close_tab"))->setEnabled(count
> 0);
1507 void DolphinMainWindow::activeViewChanged(DolphinViewContainer
*viewContainer
)
1509 DolphinViewContainer
*oldViewContainer
= m_activeViewContainer
;
1510 Q_ASSERT(viewContainer
);
1512 m_activeViewContainer
= viewContainer
;
1514 if (oldViewContainer
) {
1515 const QAction
*toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
1516 toggleSearchAction
->disconnect(oldViewContainer
);
1518 // Disconnect all signals between the old view container (container,
1519 // view and url navigator) and main window.
1520 oldViewContainer
->disconnect(this);
1521 oldViewContainer
->view()->disconnect(this);
1522 oldViewContainer
->urlNavigatorInternalWithHistory()->disconnect(this);
1523 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>(actionCollection()->action(QStringLiteral("url_navigators")));
1524 navigators
->primaryUrlNavigator()->disconnect(this);
1525 if (auto secondaryUrlNavigator
= navigators
->secondaryUrlNavigator()) {
1526 secondaryUrlNavigator
->disconnect(this);
1529 // except the requestItemInfo so that on hover the information panel can still be updated
1530 connect(oldViewContainer
->view(), &DolphinView::requestItemInfo
, this, &DolphinMainWindow::requestItemInfo
);
1532 // Disconnect other slots.
1533 disconnect(oldViewContainer
,
1534 &DolphinViewContainer::selectionModeChanged
,
1535 actionCollection()->action(QStringLiteral("toggle_selection_mode")),
1536 &QAction::setChecked
);
1539 connectViewSignals(viewContainer
);
1541 m_actionHandler
->setCurrentView(viewContainer
->view());
1544 updateFileAndEditActions();
1545 updatePasteAction();
1546 updateViewActions();
1548 updateSearchAction();
1550 const QUrl url
= viewContainer
->url();
1551 Q_EMIT
urlChanged(url
);
1554 void DolphinMainWindow::tabCountChanged(int count
)
1556 const bool enableTabActions
= (count
> 1);
1557 for (int i
= 0; i
< MaxActivateTabShortcuts
; ++i
) {
1558 actionCollection()->action(QStringLiteral("activate_tab_%1").arg(i
))->setEnabled(enableTabActions
);
1560 actionCollection()->action(QStringLiteral("activate_last_tab"))->setEnabled(enableTabActions
);
1561 actionCollection()->action(QStringLiteral("activate_next_tab"))->setEnabled(enableTabActions
);
1562 actionCollection()->action(QStringLiteral("activate_prev_tab"))->setEnabled(enableTabActions
);
1565 void DolphinMainWindow::updateWindowTitle()
1567 const QString newTitle
= m_activeViewContainer
->captionWindowTitle();
1568 if (windowTitle() != newTitle
) {
1569 setWindowTitle(newTitle
);
1573 void DolphinMainWindow::slotStorageTearDownFromPlacesRequested(const QString
&mountPath
)
1575 connect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, this, [this, mountPath
]() {
1576 setViewsToHomeIfMountPathOpen(mountPath
);
1579 if (m_terminalPanel
&& m_terminalPanel
->currentWorkingDirectoryIsChildOf(mountPath
)) {
1580 m_tearDownFromPlacesRequested
= true;
1581 m_terminalPanel
->goHome();
1582 // m_placesPanel->proceedWithTearDown() will be called in slotTerminalDirectoryChanged
1584 m_placesPanel
->proceedWithTearDown();
1588 void DolphinMainWindow::slotStorageTearDownExternallyRequested(const QString
&mountPath
)
1590 connect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, this, [this, mountPath
]() {
1591 setViewsToHomeIfMountPathOpen(mountPath
);
1594 if (m_terminalPanel
&& m_terminalPanel
->currentWorkingDirectoryIsChildOf(mountPath
)) {
1595 m_tearDownFromPlacesRequested
= false;
1596 m_terminalPanel
->goHome();
1600 void DolphinMainWindow::slotKeyBindings()
1602 KShortcutsDialog
dialog(KShortcutsEditor::AllActions
, KShortcutsEditor::LetterShortcutsAllowed
, this);
1603 dialog
.addCollection(actionCollection());
1604 if (m_terminalPanel
) {
1605 KActionCollection
*konsolePartActionCollection
= m_terminalPanel
->actionCollection();
1606 if (konsolePartActionCollection
) {
1607 dialog
.addCollection(konsolePartActionCollection
, QStringLiteral("KonsolePart"));
1613 void DolphinMainWindow::setViewsToHomeIfMountPathOpen(const QString
&mountPath
)
1615 const QVector
<DolphinViewContainer
*> theViewContainers
= viewContainers();
1616 for (DolphinViewContainer
*viewContainer
: theViewContainers
) {
1617 if (viewContainer
&& viewContainer
->url().toLocalFile().startsWith(mountPath
)) {
1618 viewContainer
->setUrl(QUrl::fromLocalFile(QDir::homePath()));
1621 disconnect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, nullptr, nullptr);
1624 void DolphinMainWindow::setupActions()
1626 auto hamburgerMenuAction
= KStandardAction::hamburgerMenu(nullptr, nullptr, actionCollection());
1628 // setup 'File' menu
1629 m_newFileMenu
= new DolphinNewFileMenu(nullptr, this);
1630 actionCollection()->addAction(QStringLiteral("new_menu"), m_newFileMenu
);
1631 QMenu
*menu
= m_newFileMenu
->menu();
1632 menu
->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1633 menu
->setIcon(QIcon::fromTheme(QStringLiteral("list-add")));
1634 m_newFileMenu
->setPopupMode(QToolButton::InstantPopup
);
1635 connect(menu
, &QMenu::aboutToShow
, this, &DolphinMainWindow::updateNewMenu
);
1637 QAction
*newWindow
= KStandardAction::openNew(this, &DolphinMainWindow::openNewMainWindow
, actionCollection());
1638 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
1639 newWindow
->setToolTip(i18nc("@info", "Open a new Dolphin window"));
1640 newWindow
->setWhatsThis(xi18nc("@info:whatsthis",
1642 "window just like this one with the current location and view."
1643 "<nl/>You can drag and drop items between windows."));
1644 newWindow
->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
1646 QAction
*newTab
= actionCollection()->addAction(QStringLiteral("new_tab"));
1647 newTab
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1648 newTab
->setText(i18nc("@action:inmenu File", "New Tab"));
1649 newTab
->setWhatsThis(xi18nc("@info:whatsthis",
1651 "<emphasis>Tab</emphasis> with the current location and view.<nl/>"
1652 "A tab is an additional view within this window. "
1653 "You can drag and drop items between tabs."));
1654 actionCollection()->setDefaultShortcut(newTab
, Qt::CTRL
| Qt::Key_T
);
1655 connect(newTab
, &QAction::triggered
, this, &DolphinMainWindow::openNewActivatedTab
);
1657 QAction
*addToPlaces
= actionCollection()->addAction(QStringLiteral("add_to_places"));
1658 addToPlaces
->setIcon(QIcon::fromTheme(QStringLiteral("bookmark-new")));
1659 addToPlaces
->setText(i18nc("@action:inmenu Add current folder to places", "Add to Places"));
1660 addToPlaces
->setWhatsThis(xi18nc("@info:whatsthis",
1661 "This adds the selected folder "
1662 "to the Places panel."));
1663 connect(addToPlaces
, &QAction::triggered
, this, &DolphinMainWindow::addToPlaces
);
1665 QAction
*closeTab
= KStandardAction::close(m_tabWidget
, QOverload
<>::of(&DolphinTabWidget::closeTab
), actionCollection());
1666 closeTab
->setText(i18nc("@action:inmenu File", "Close Tab"));
1667 closeTab
->setWhatsThis(i18nc("@info:whatsthis",
1669 "currently viewed tab. If no more tabs are left this window "
1670 "will close instead."));
1672 QAction
*quitAction
= KStandardAction::quit(this, &DolphinMainWindow::quit
, actionCollection());
1673 quitAction
->setWhatsThis(i18nc("@info:whatsthis quit", "This closes this window."));
1675 // setup 'Edit' menu
1676 KStandardAction::undo(this, &DolphinMainWindow::undo
, actionCollection());
1678 // i18n: This will be the last paragraph for the whatsthis for all three:
1679 // Cut, Copy and Paste
1680 const QString cutCopyPastePara
= xi18nc("@info:whatsthis",
1681 "<para><emphasis>Cut, "
1682 "Copy</emphasis> and <emphasis>Paste</emphasis> work between many "
1683 "applications and are among the most used commands. That's why their "
1684 "<emphasis>keyboard shortcuts</emphasis> are prominently placed right "
1685 "next to each other on the keyboard: <shortcut>Ctrl+X</shortcut>, "
1686 "<shortcut>Ctrl+C</shortcut> and <shortcut>Ctrl+V</shortcut>.</para>");
1687 QAction
*cutAction
= KStandardAction::cut(this, &DolphinMainWindow::cut
, actionCollection());
1688 m_actionTextHelper
->registerTextWhenNothingIsSelected(cutAction
, i18nc("@action", "Cut…"));
1689 cutAction
->setWhatsThis(xi18nc("@info:whatsthis cut",
1690 "This copies the items "
1691 "in your current selection to the <emphasis>clipboard</emphasis>.<nl/>"
1692 "Use the <emphasis>Paste</emphasis> action afterwards to copy them from "
1693 "the clipboard to a new location. The items will be removed from their "
1694 "initial location.")
1695 + cutCopyPastePara
);
1696 QAction
*copyAction
= KStandardAction::copy(this, &DolphinMainWindow::copy
, actionCollection());
1697 m_actionTextHelper
->registerTextWhenNothingIsSelected(copyAction
, i18nc("@action", "Copy…"));
1698 copyAction
->setWhatsThis(xi18nc("@info:whatsthis copy",
1700 "items in your current selection to the <emphasis>clipboard</emphasis>."
1701 "<nl/>Use the <emphasis>Paste</emphasis> action afterwards to copy them "
1702 "from the clipboard to a new location.")
1703 + cutCopyPastePara
);
1704 QAction
*paste
= KStandardAction::paste(this, &DolphinMainWindow::paste
, actionCollection());
1705 // The text of the paste-action is modified dynamically by Dolphin
1706 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1707 // due to the long text, the text "Paste" is used:
1708 paste
->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1709 paste
->setWhatsThis(xi18nc("@info:whatsthis paste",
1710 "This copies the items from "
1711 "your <emphasis>clipboard</emphasis> to the currently viewed folder.<nl/>"
1712 "If the items were added to the clipboard by the <emphasis>Cut</emphasis> "
1713 "action they are removed from their old location.")
1714 + cutCopyPastePara
);
1716 QAction
*copyToOtherViewAction
= actionCollection()->addAction(QStringLiteral("copy_to_inactive_split_view"));
1717 copyToOtherViewAction
->setText(i18nc("@action:inmenu", "Copy to Other View"));
1718 m_actionTextHelper
->registerTextWhenNothingIsSelected(copyToOtherViewAction
, i18nc("@action:inmenu", "Copy to Other View…"));
1719 copyToOtherViewAction
->setWhatsThis(xi18nc("@info:whatsthis Copy",
1720 "This copies the selected items from "
1721 "the <emphasis>active</emphasis> view to the inactive split view."));
1722 copyToOtherViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("edit-copy")));
1723 copyToOtherViewAction
->setIconText(i18nc("@action:inmenu Edit", "Copy to Inactive Split View"));
1724 actionCollection()->setDefaultShortcut(copyToOtherViewAction
, Qt::SHIFT
| Qt::Key_F5
);
1725 connect(copyToOtherViewAction
, &QAction::triggered
, this, &DolphinMainWindow::copyToInactiveSplitView
);
1727 QAction
*moveToOtherViewAction
= actionCollection()->addAction(QStringLiteral("move_to_inactive_split_view"));
1728 moveToOtherViewAction
->setText(i18nc("@action:inmenu", "Move to Other View"));
1729 m_actionTextHelper
->registerTextWhenNothingIsSelected(moveToOtherViewAction
, i18nc("@action:inmenu", "Move to Other View…"));
1730 moveToOtherViewAction
->setWhatsThis(xi18nc("@info:whatsthis Move",
1731 "This moves the selected items from "
1732 "the <emphasis>active</emphasis> view to the inactive split view."));
1733 moveToOtherViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("edit-cut")));
1734 moveToOtherViewAction
->setIconText(i18nc("@action:inmenu Edit", "Move to Inactive Split View"));
1735 actionCollection()->setDefaultShortcut(moveToOtherViewAction
, Qt::SHIFT
| Qt::Key_F6
);
1736 connect(moveToOtherViewAction
, &QAction::triggered
, this, &DolphinMainWindow::moveToInactiveSplitView
);
1738 QAction
*showFilterBar
= actionCollection()->addAction(QStringLiteral("show_filter_bar"));
1739 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Filter…"));
1740 showFilterBar
->setToolTip(i18nc("@info:tooltip", "Show Filter Bar"));
1741 showFilterBar
->setWhatsThis(xi18nc("@info:whatsthis",
1743 "<emphasis>Filter Bar</emphasis> at the bottom of the window.<nl/> "
1744 "There you can enter a text to filter the files and folders currently displayed. "
1745 "Only those that contain the text in their name will be kept in view."));
1746 showFilterBar
->setIcon(QIcon::fromTheme(QStringLiteral("view-filter")));
1747 actionCollection()->setDefaultShortcuts(showFilterBar
, {Qt::CTRL
| Qt::Key_I
, Qt::Key_Slash
});
1748 connect(showFilterBar
, &QAction::triggered
, this, &DolphinMainWindow::showFilterBar
);
1750 // toggle_filter acts as a copy of the main showFilterBar to be used mainly
1751 // in the toolbar, with no default shortcut attached, to avoid messing with
1752 // existing workflows (filter bar always open and Ctrl-I to focus)
1753 QAction
*toggleFilter
= actionCollection()->addAction(QStringLiteral("toggle_filter"));
1754 toggleFilter
->setText(i18nc("@action:inmenu", "Toggle Filter Bar"));
1755 toggleFilter
->setIconText(i18nc("@action:intoolbar", "Filter"));
1756 toggleFilter
->setIcon(showFilterBar
->icon());
1757 toggleFilter
->setToolTip(showFilterBar
->toolTip());
1758 toggleFilter
->setWhatsThis(showFilterBar
->whatsThis());
1759 toggleFilter
->setCheckable(true);
1760 connect(toggleFilter
, &QAction::triggered
, this, &DolphinMainWindow::toggleFilterBar
);
1762 QAction
*searchAction
= KStandardAction::find(this, &DolphinMainWindow::find
, actionCollection());
1763 searchAction
->setText(i18n("Search…"));
1764 searchAction
->setToolTip(i18nc("@info:tooltip", "Search for files and folders"));
1765 searchAction
->setWhatsThis(xi18nc("@info:whatsthis find",
1766 "<para>This helps you "
1767 "find files and folders by opening a <emphasis>find bar</emphasis>. "
1768 "There you can enter search terms and specify settings to find the "
1769 "objects you are looking for.</para><para>Use this help again on "
1770 "the find bar so we can have a look at it while the settings are "
1771 "explained.</para>"));
1773 // toggle_search acts as a copy of the main searchAction to be used mainly
1774 // in the toolbar, with no default shortcut attached, to avoid messing with
1775 // existing workflows (search bar always open and Ctrl-F to focus)
1776 QAction
*toggleSearchAction
= actionCollection()->addAction(QStringLiteral("toggle_search"));
1777 toggleSearchAction
->setText(i18nc("@action:inmenu", "Toggle Search Bar"));
1778 toggleSearchAction
->setIconText(i18nc("@action:intoolbar", "Search"));
1779 toggleSearchAction
->setIcon(searchAction
->icon());
1780 toggleSearchAction
->setToolTip(searchAction
->toolTip());
1781 toggleSearchAction
->setWhatsThis(searchAction
->whatsThis());
1782 toggleSearchAction
->setCheckable(true);
1784 QAction
*toggleSelectionModeAction
= actionCollection()->addAction(QStringLiteral("toggle_selection_mode"));
1785 // i18n: This action toggles a selection mode.
1786 toggleSelectionModeAction
->setText(i18nc("@action:inmenu", "Select Files and Folders"));
1787 // i18n: Opens a selection mode for selecting files/folders.
1788 // The text is kept so unspecific because it will be shown on the toolbar where space is at a premium.
1789 toggleSelectionModeAction
->setIconText(i18nc("@action:intoolbar", "Select"));
1790 toggleSelectionModeAction
->setWhatsThis(xi18nc(
1792 "<para>This application only knows which files or folders should be acted on if they are"
1793 " <emphasis>selected</emphasis> first. Press this to toggle a <emphasis>Selection Mode</emphasis> which makes selecting and deselecting as easy as "
1794 "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."
1796 toggleSelectionModeAction
->setIcon(QIcon::fromTheme(QStringLiteral("quickwizard")));
1797 toggleSelectionModeAction
->setCheckable(true);
1798 actionCollection()->setDefaultShortcut(toggleSelectionModeAction
, Qt::Key_Space
);
1799 connect(toggleSelectionModeAction
, &QAction::triggered
, this, &DolphinMainWindow::toggleSelectionMode
);
1801 // A special version of the toggleSelectionModeAction for the toolbar that also contains a menu
1802 // with the selectAllAction and invertSelectionAction.
1803 auto *toggleSelectionModeToolBarAction
=
1804 new KToolBarPopupAction(toggleSelectionModeAction
->icon(), toggleSelectionModeAction
->iconText(), actionCollection());
1805 toggleSelectionModeToolBarAction
->setToolTip(toggleSelectionModeAction
->text());
1806 toggleSelectionModeToolBarAction
->setWhatsThis(toggleSelectionModeAction
->whatsThis());
1807 actionCollection()->addAction(QStringLiteral("toggle_selection_mode_tool_bar"), toggleSelectionModeToolBarAction
);
1808 toggleSelectionModeToolBarAction
->setCheckable(true);
1809 toggleSelectionModeToolBarAction
->setPopupMode(KToolBarPopupAction::DelayedPopup
);
1810 connect(toggleSelectionModeToolBarAction
, &QAction::triggered
, toggleSelectionModeAction
, &QAction::trigger
);
1811 connect(toggleSelectionModeAction
, &QAction::toggled
, toggleSelectionModeToolBarAction
, &QAction::setChecked
);
1813 QAction
*selectAllAction
= KStandardAction::selectAll(this, &DolphinMainWindow::selectAll
, actionCollection());
1814 selectAllAction
->setWhatsThis(xi18nc("@info:whatsthis",
1816 "files and folders in the current location."));
1818 QAction
*invertSelection
= actionCollection()->addAction(QStringLiteral("invert_selection"));
1819 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1820 invertSelection
->setWhatsThis(xi18nc("@info:whatsthis invert",
1822 "objects that you have currently <emphasis>not</emphasis> selected instead."));
1823 invertSelection
->setIcon(QIcon::fromTheme(QStringLiteral("edit-select-invert")));
1824 actionCollection()->setDefaultShortcut(invertSelection
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
1825 connect(invertSelection
, &QAction::triggered
, this, &DolphinMainWindow::invertSelection
);
1827 QMenu
*toggleSelectionModeActionMenu
= new QMenu(this);
1828 toggleSelectionModeActionMenu
->addAction(selectAllAction
);
1829 toggleSelectionModeActionMenu
->addAction(invertSelection
);
1830 toggleSelectionModeToolBarAction
->setMenu(toggleSelectionModeActionMenu
);
1832 // setup 'View' menu
1833 // (note that most of it is set up in DolphinViewActionHandler)
1835 m_splitViewAction
= actionCollection()->add
<KActionMenu
>(QStringLiteral("split_view"));
1836 m_splitViewMenuAction
= actionCollection()->addAction(QStringLiteral("split_view_menu"));
1838 m_splitViewAction
->setWhatsThis(xi18nc("@info:whatsthis find",
1839 "<para>This splits "
1840 "the folder view below into two autonomous views.</para><para>This "
1841 "way you can see two locations at once and move items between them "
1842 "quickly.</para>Click this again afterwards to recombine the views."));
1843 m_splitViewMenuAction
->setWhatsThis(m_splitViewAction
->whatsThis());
1845 // only set it for the menu version
1846 actionCollection()->setDefaultShortcut(m_splitViewMenuAction
, Qt::Key_F3
);
1848 connect(m_splitViewAction
, &QAction::triggered
, this, &DolphinMainWindow::toggleSplitView
);
1849 connect(m_splitViewMenuAction
, &QAction::triggered
, this, &DolphinMainWindow::toggleSplitView
);
1851 QAction
*popoutSplit
= actionCollection()->addAction(QStringLiteral("popout_split_view"));
1852 popoutSplit
->setWhatsThis(xi18nc("@info:whatsthis",
1853 "If the folder view has been split, this will pop the active folder "
1854 "view out into a new window."));
1855 popoutSplit
->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
1856 actionCollection()->setDefaultShortcut(popoutSplit
, Qt::SHIFT
| Qt::Key_F3
);
1857 connect(popoutSplit
, &QAction::triggered
, this, &DolphinMainWindow::popoutSplitView
);
1859 QAction
*stashSplit
= actionCollection()->addAction(QStringLiteral("split_stash"));
1860 actionCollection()->setDefaultShortcut(stashSplit
, Qt::CTRL
| Qt::Key_S
);
1861 stashSplit
->setText(i18nc("@action:intoolbar Stash", "Stash"));
1862 stashSplit
->setToolTip(i18nc("@info", "Opens the stash virtual directory in a split window"));
1863 stashSplit
->setIcon(QIcon::fromTheme(QStringLiteral("folder-stash")));
1864 stashSplit
->setCheckable(false);
1865 QDBusConnectionInterface
*sessionInterface
= QDBusConnection::sessionBus().interface();
1866 stashSplit
->setVisible(sessionInterface
&& sessionInterface
->isServiceRegistered(QStringLiteral("org.kde.kio.StashNotifier")));
1867 connect(stashSplit
, &QAction::triggered
, this, &DolphinMainWindow::toggleSplitStash
);
1869 QAction
*redisplay
= KStandardAction::redisplay(this, &DolphinMainWindow::reloadView
, actionCollection());
1870 redisplay
->setToolTip(i18nc("@info:tooltip", "Refresh view"));
1871 redisplay
->setWhatsThis(xi18nc("@info:whatsthis refresh",
1872 "<para>This refreshes "
1873 "the folder view.</para>"
1874 "<para>If the contents of this folder have changed, refreshing will re-scan this folder "
1875 "and show you a newly-updated view of the files and folders contained here.</para>"
1876 "<para>If the view is split, this refreshes the one that is currently in focus.</para>"));
1878 QAction
*stop
= actionCollection()->addAction(QStringLiteral("stop"));
1879 stop
->setText(i18nc("@action:inmenu View", "Stop"));
1880 stop
->setToolTip(i18nc("@info", "Stop loading"));
1881 stop
->setWhatsThis(i18nc("@info", "This stops the loading of the contents of the current folder."));
1882 stop
->setIcon(QIcon::fromTheme(QStringLiteral("process-stop")));
1883 connect(stop
, &QAction::triggered
, this, &DolphinMainWindow::stopLoading
);
1885 KToggleAction
*editableLocation
= actionCollection()->add
<KToggleAction
>(QStringLiteral("editable_location"));
1886 editableLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1887 editableLocation
->setWhatsThis(xi18nc("@info:whatsthis",
1888 "This toggles the <emphasis>Location Bar</emphasis> to be "
1889 "editable so you can directly enter a location you want to go to.<nl/>"
1890 "You can also switch to editing by clicking to the right of the "
1891 "location and switch back by confirming the edited location."));
1892 actionCollection()->setDefaultShortcut(editableLocation
, Qt::Key_F6
);
1893 connect(editableLocation
, &KToggleAction::triggered
, this, &DolphinMainWindow::toggleEditLocation
);
1895 QAction
*replaceLocation
= actionCollection()->addAction(QStringLiteral("replace_location"));
1896 replaceLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1897 // i18n: "enter" is used both in the meaning of "writing" and "going to" a new location here.
1898 // Both meanings are useful but not necessary to understand the use of "Replace Location".
1899 // So you might want to be more verbose in your language to convey the meaning but it's up to you.
1900 replaceLocation
->setWhatsThis(xi18nc("@info:whatsthis",
1901 "This switches to editing the location and selects it "
1902 "so you can quickly enter a different location."));
1903 actionCollection()->setDefaultShortcuts(replaceLocation
, {Qt::CTRL
| Qt::Key_L
, Qt::ALT
| Qt::Key_D
});
1904 connect(replaceLocation
, &QAction::triggered
, this, &DolphinMainWindow::replaceLocation
);
1908 QScopedPointer
<QAction
> backAction(KStandardAction::back(nullptr, nullptr, nullptr));
1909 m_backAction
= new KToolBarPopupAction(backAction
->icon(), backAction
->text(), actionCollection());
1910 m_backAction
->setObjectName(backAction
->objectName());
1911 m_backAction
->setShortcuts(backAction
->shortcuts());
1913 m_backAction
->setPopupMode(KToolBarPopupAction::DelayedPopup
);
1914 connect(m_backAction
, &QAction::triggered
, this, &DolphinMainWindow::goBack
);
1915 connect(m_backAction
->popupMenu(), &QMenu::aboutToShow
, this, &DolphinMainWindow::slotAboutToShowBackPopupMenu
);
1916 connect(m_backAction
->popupMenu(), &QMenu::triggered
, this, &DolphinMainWindow::slotGoBack
);
1917 actionCollection()->addAction(m_backAction
->objectName(), m_backAction
);
1919 auto backShortcuts
= m_backAction
->shortcuts();
1920 // Prepend this shortcut, to avoid being hidden by the two-slot UI (#371130)
1921 backShortcuts
.prepend(QKeySequence(Qt::Key_Backspace
));
1922 actionCollection()->setDefaultShortcuts(m_backAction
, backShortcuts
);
1924 DolphinRecentTabsMenu
*recentTabsMenu
= new DolphinRecentTabsMenu(this);
1925 actionCollection()->addAction(QStringLiteral("closed_tabs"), recentTabsMenu
);
1926 connect(m_tabWidget
, &DolphinTabWidget::rememberClosedTab
, recentTabsMenu
, &DolphinRecentTabsMenu::rememberClosedTab
);
1927 connect(recentTabsMenu
, &DolphinRecentTabsMenu::restoreClosedTab
, m_tabWidget
, &DolphinTabWidget::restoreClosedTab
);
1928 connect(recentTabsMenu
, &DolphinRecentTabsMenu::closedTabsCountChanged
, this, &DolphinMainWindow::closedTabsCountChanged
);
1930 QAction
*undoCloseTab
= actionCollection()->addAction(QStringLiteral("undo_close_tab"));
1931 undoCloseTab
->setText(i18nc("@action:inmenu File", "Undo close tab"));
1932 undoCloseTab
->setWhatsThis(i18nc("@info:whatsthis undo close tab", "This returns you to the previously closed tab."));
1933 actionCollection()->setDefaultShortcut(undoCloseTab
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_T
);
1934 undoCloseTab
->setIcon(QIcon::fromTheme(QStringLiteral("edit-undo")));
1935 undoCloseTab
->setEnabled(false);
1936 connect(undoCloseTab
, &QAction::triggered
, recentTabsMenu
, &DolphinRecentTabsMenu::undoCloseTab
);
1938 auto undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
1939 undoAction
->setWhatsThis(xi18nc("@info:whatsthis",
1941 "the last change you made to files or folders.<nl/>"
1942 "Such changes include <interface>creating, renaming</interface> "
1943 "and <interface>moving</interface> them to a different location "
1944 "or to the <filename>Trash</filename>. <nl/>Changes that can't "
1945 "be undone will ask for your confirmation."));
1946 undoAction
->setEnabled(false); // undo should be disabled by default
1949 QScopedPointer
<QAction
> forwardAction(KStandardAction::forward(nullptr, nullptr, nullptr));
1950 m_forwardAction
= new KToolBarPopupAction(forwardAction
->icon(), forwardAction
->text(), actionCollection());
1951 m_forwardAction
->setObjectName(forwardAction
->objectName());
1952 m_forwardAction
->setShortcuts(forwardAction
->shortcuts());
1954 m_forwardAction
->setPopupMode(KToolBarPopupAction::DelayedPopup
);
1955 connect(m_forwardAction
, &QAction::triggered
, this, &DolphinMainWindow::goForward
);
1956 connect(m_forwardAction
->popupMenu(), &QMenu::aboutToShow
, this, &DolphinMainWindow::slotAboutToShowForwardPopupMenu
);
1957 connect(m_forwardAction
->popupMenu(), &QMenu::triggered
, this, &DolphinMainWindow::slotGoForward
);
1958 actionCollection()->addAction(m_forwardAction
->objectName(), m_forwardAction
);
1959 actionCollection()->setDefaultShortcuts(m_forwardAction
, m_forwardAction
->shortcuts());
1961 // enable middle-click to open in a new tab
1962 auto *middleClickEventFilter
= new MiddleClickActionEventFilter(this);
1963 connect(middleClickEventFilter
, &MiddleClickActionEventFilter::actionMiddleClicked
, this, &DolphinMainWindow::slotBackForwardActionMiddleClicked
);
1964 m_backAction
->popupMenu()->installEventFilter(middleClickEventFilter
);
1965 m_forwardAction
->popupMenu()->installEventFilter(middleClickEventFilter
);
1966 KStandardAction::up(this, &DolphinMainWindow::goUp
, actionCollection());
1967 QAction
*homeAction
= KStandardAction::home(this, &DolphinMainWindow::goHome
, actionCollection());
1968 homeAction
->setWhatsThis(xi18nc("@info:whatsthis",
1970 "<filename>Home</filename> folder.<nl/>Every user account "
1971 "has their own <filename>Home</filename> that contains their data "
1972 "including folders that contain personal application data."));
1974 // setup 'Tools' menu
1975 QAction
*compareFiles
= actionCollection()->addAction(QStringLiteral("compare_files"));
1976 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1977 compareFiles
->setIcon(QIcon::fromTheme(QStringLiteral("kompare")));
1978 compareFiles
->setEnabled(false);
1979 connect(compareFiles
, &QAction::triggered
, this, &DolphinMainWindow::compareFiles
);
1981 QAction
*openPreferredSearchTool
= actionCollection()->addAction(QStringLiteral("open_preferred_search_tool"));
1982 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool"));
1983 openPreferredSearchTool
->setWhatsThis(xi18nc("@info:whatsthis",
1984 "<para>This opens a preferred search tool for the viewed location.</para>"
1985 "<para>Use <emphasis>More Search Tools</emphasis> menu to configure it.</para>"));
1986 openPreferredSearchTool
->setIcon(QIcon::fromTheme(QStringLiteral("search")));
1987 actionCollection()->setDefaultShortcut(openPreferredSearchTool
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_F
);
1988 connect(openPreferredSearchTool
, &QAction::triggered
, this, &DolphinMainWindow::openPreferredSearchTool
);
1990 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
1991 QAction
*openTerminal
= actionCollection()->addAction(QStringLiteral("open_terminal"));
1992 openTerminal
->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
1993 openTerminal
->setWhatsThis(xi18nc("@info:whatsthis",
1994 "<para>This opens a <emphasis>terminal</emphasis> application for the viewed location.</para>"
1995 "<para>To learn more about terminals use the help in the terminal application.</para>"));
1996 openTerminal
->setIcon(QIcon::fromTheme(QStringLiteral("utilities-terminal")));
1997 actionCollection()->setDefaultShortcut(openTerminal
, Qt::SHIFT
| Qt::Key_F4
);
1998 connect(openTerminal
, &QAction::triggered
, this, &DolphinMainWindow::openTerminal
);
2000 QAction
*openTerminalHere
= actionCollection()->addAction(QStringLiteral("open_terminal_here"));
2001 // i18n: "Here" refers to the location(s) of the currently selected item(s) or the currently viewed location if nothing is selected.
2002 openTerminalHere
->setText(i18nc("@action:inmenu Tools", "Open Terminal Here"));
2003 openTerminalHere
->setWhatsThis(xi18nc("@info:whatsthis",
2004 "<para>This opens <emphasis>terminal</emphasis> applications for the selected items' locations.</para>"
2005 "<para>To learn more about terminals use the help in the terminal application.</para>"));
2006 openTerminalHere
->setIcon(QIcon::fromTheme(QStringLiteral("utilities-terminal")));
2007 actionCollection()->setDefaultShortcut(openTerminalHere
, Qt::SHIFT
| Qt::ALT
| Qt::Key_F4
);
2008 connect(openTerminalHere
, &QAction::triggered
, this, &DolphinMainWindow::openTerminalHere
);
2011 QAction
*focusTerminalPanel
= actionCollection()->addAction(QStringLiteral("focus_terminal_panel"));
2012 focusTerminalPanel
->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
2013 focusTerminalPanel
->setIcon(QIcon::fromTheme(QStringLiteral("swap-panels")));
2014 actionCollection()->setDefaultShortcut(focusTerminalPanel
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_F4
);
2015 connect(focusTerminalPanel
, &QAction::triggered
, this, &DolphinMainWindow::focusTerminalPanel
);
2019 // setup 'Bookmarks' menu
2020 KActionMenu
*bookmarkMenu
= new KActionMenu(i18nc("@title:menu", "&Bookmarks"), this);
2021 bookmarkMenu
->setIcon(QIcon::fromTheme(QStringLiteral("bookmarks")));
2022 // Make the toolbar button version work properly on click
2023 bookmarkMenu
->setPopupMode(QToolButton::InstantPopup
);
2024 m_bookmarkHandler
= new DolphinBookmarkHandler(this, actionCollection(), bookmarkMenu
->menu(), this);
2025 actionCollection()->addAction(QStringLiteral("bookmarks"), bookmarkMenu
);
2027 // setup 'Settings' menu
2028 KToggleAction
*showMenuBar
= KStandardAction::showMenubar(nullptr, nullptr, actionCollection());
2029 showMenuBar
->setWhatsThis(xi18nc("@info:whatsthis",
2030 "<para>This switches between having a <emphasis>Menubar</emphasis> "
2031 "and having a <interface>%1</interface> button. Both "
2032 "contain mostly the same actions and configuration options.</para>"
2033 "<para>The Menubar takes up more space but allows for fast and organised access to all "
2034 "actions an application has to offer.</para><para>The <interface>%1</interface> button "
2035 "is simpler and small which makes triggering advanced actions more time consuming.</para>",
2036 hamburgerMenuAction
->text().replace('&', "")));
2037 connect(showMenuBar
,
2038 &KToggleAction::triggered
, // Fixes #286822
2040 &DolphinMainWindow::toggleShowMenuBar
,
2041 Qt::QueuedConnection
);
2043 KToggleAction
*showStatusBar
= KStandardAction::showStatusbar(nullptr, nullptr, actionCollection());
2044 showStatusBar
->setChecked(GeneralSettings::showStatusBar());
2045 connect(GeneralSettings::self(), &GeneralSettings::showStatusBarChanged
, showStatusBar
, &KToggleAction::setChecked
);
2046 connect(showStatusBar
, &KToggleAction::triggered
, this, [this](bool checked
) {
2047 GeneralSettings::setShowStatusBar(checked
);
2051 KStandardAction::keyBindings(this, &DolphinMainWindow::slotKeyBindings
, actionCollection());
2052 KStandardAction::preferences(this, &DolphinMainWindow::editSettings
, actionCollection());
2054 // not in menu actions
2055 QList
<QKeySequence
> nextTabKeys
= KStandardShortcut::tabNext();
2056 nextTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::Key_Tab
));
2058 QList
<QKeySequence
> prevTabKeys
= KStandardShortcut::tabPrev();
2059 prevTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::SHIFT
| Qt::Key_Tab
));
2061 for (int i
= 0; i
< MaxActivateTabShortcuts
; ++i
) {
2062 QAction
*activateTab
= actionCollection()->addAction(QStringLiteral("activate_tab_%1").arg(i
));
2063 activateTab
->setText(i18nc("@action:inmenu", "Activate Tab %1", i
+ 1));
2064 activateTab
->setEnabled(false);
2065 connect(activateTab
, &QAction::triggered
, this, [this, i
]() {
2066 m_tabWidget
->activateTab(i
);
2069 // only add default shortcuts for the first 9 tabs regardless of MaxActivateTabShortcuts
2071 actionCollection()->setDefaultShortcut(activateTab
, QStringLiteral("Alt+%1").arg(i
+ 1));
2075 QAction
*activateLastTab
= actionCollection()->addAction(QStringLiteral("activate_last_tab"));
2076 activateLastTab
->setText(i18nc("@action:inmenu", "Activate Last Tab"));
2077 activateLastTab
->setEnabled(false);
2078 connect(activateLastTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activateLastTab
);
2079 actionCollection()->setDefaultShortcut(activateLastTab
, Qt::ALT
| Qt::Key_0
);
2081 QAction
*activateNextTab
= actionCollection()->addAction(QStringLiteral("activate_next_tab"));
2082 activateNextTab
->setIconText(i18nc("@action:inmenu", "Next Tab"));
2083 activateNextTab
->setText(i18nc("@action:inmenu", "Activate Next Tab"));
2084 activateNextTab
->setEnabled(false);
2085 connect(activateNextTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activateNextTab
);
2086 actionCollection()->setDefaultShortcuts(activateNextTab
, nextTabKeys
);
2088 QAction
*activatePrevTab
= actionCollection()->addAction(QStringLiteral("activate_prev_tab"));
2089 activatePrevTab
->setIconText(i18nc("@action:inmenu", "Previous Tab"));
2090 activatePrevTab
->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
2091 activatePrevTab
->setEnabled(false);
2092 connect(activatePrevTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activatePrevTab
);
2093 actionCollection()->setDefaultShortcuts(activatePrevTab
, prevTabKeys
);
2096 QAction
*showTarget
= actionCollection()->addAction(QStringLiteral("show_target"));
2097 showTarget
->setText(i18nc("@action:inmenu", "Show Target"));
2098 showTarget
->setIcon(QIcon::fromTheme(QStringLiteral("document-open-folder")));
2099 showTarget
->setEnabled(false);
2100 connect(showTarget
, &QAction::triggered
, this, &DolphinMainWindow::showTarget
);
2102 QAction
*openInNewTab
= actionCollection()->addAction(QStringLiteral("open_in_new_tab"));
2103 openInNewTab
->setText(i18nc("@action:inmenu", "Open in New Tab"));
2104 openInNewTab
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
2105 connect(openInNewTab
, &QAction::triggered
, this, &DolphinMainWindow::openInNewTab
);
2107 QAction
*openInNewTabs
= actionCollection()->addAction(QStringLiteral("open_in_new_tabs"));
2108 openInNewTabs
->setText(i18nc("@action:inmenu", "Open in New Tabs"));
2109 openInNewTabs
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
2110 connect(openInNewTabs
, &QAction::triggered
, this, &DolphinMainWindow::openInNewTab
);
2112 QAction
*openInNewWindow
= actionCollection()->addAction(QStringLiteral("open_in_new_window"));
2113 openInNewWindow
->setText(i18nc("@action:inmenu", "Open in New Window"));
2114 openInNewWindow
->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
2115 connect(openInNewWindow
, &QAction::triggered
, this, &DolphinMainWindow::openInNewWindow
);
2117 QAction
*openInSplitViewAction
= actionCollection()->addAction(QStringLiteral("open_in_split_view"));
2118 openInSplitViewAction
->setText(i18nc("@action:inmenu", "Open in Split View"));
2119 openInSplitViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-right-new")));
2120 connect(openInSplitViewAction
, &QAction::triggered
, this, [this]() {
2121 openInSplitView(QUrl());
2125 void DolphinMainWindow::setupDockWidgets()
2127 const bool lock
= GeneralSettings::lockPanels();
2129 DolphinPlacesModelSingleton::instance().placesModel()->setPanelsLocked(lock
);
2131 KDualAction
*lockLayoutAction
= actionCollection()->add
<KDualAction
>(QStringLiteral("lock_panels"));
2132 lockLayoutAction
->setActiveText(i18nc("@action:inmenu Panels", "Unlock Panels"));
2133 lockLayoutAction
->setActiveIcon(QIcon::fromTheme(QStringLiteral("object-unlocked")));
2134 lockLayoutAction
->setInactiveText(i18nc("@action:inmenu Panels", "Lock Panels"));
2135 lockLayoutAction
->setInactiveIcon(QIcon::fromTheme(QStringLiteral("object-locked")));
2136 lockLayoutAction
->setWhatsThis(xi18nc("@info:whatsthis",
2138 "switches between having panels <emphasis>locked</emphasis> or "
2139 "<emphasis>unlocked</emphasis>.<nl/>Unlocked panels can be "
2140 "dragged to the other side of the window and have a close "
2141 "button.<nl/>Locked panels are embedded more cleanly."));
2142 lockLayoutAction
->setActive(lock
);
2143 connect(lockLayoutAction
, &KDualAction::triggered
, this, &DolphinMainWindow::togglePanelLockState
);
2145 // Setup "Information"
2146 DolphinDockWidget
*infoDock
= new DolphinDockWidget(i18nc("@title:window", "Information"));
2147 infoDock
->setLocked(lock
);
2148 infoDock
->setObjectName(QStringLiteral("infoDock"));
2149 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
2152 InformationPanel
*infoPanel
= new InformationPanel(infoDock
);
2153 infoPanel
->setCustomContextMenuActions({lockLayoutAction
});
2154 connect(infoPanel
, &InformationPanel::urlActivated
, this, &DolphinMainWindow::handleUrl
);
2155 infoDock
->setWidget(infoPanel
);
2157 createPanelAction(QIcon::fromTheme(QStringLiteral("dialog-information")), Qt::Key_F11
, infoDock
, QStringLiteral("show_information_panel"));
2159 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
2160 connect(this, &DolphinMainWindow::urlChanged
, infoPanel
, &InformationPanel::setUrl
);
2161 connect(this, &DolphinMainWindow::selectionChanged
, infoPanel
, &InformationPanel::setSelection
);
2162 connect(this, &DolphinMainWindow::requestItemInfo
, infoPanel
, &InformationPanel::requestDelayedItemInfo
);
2163 connect(this, &DolphinMainWindow::fileItemsChanged
, infoPanel
, &InformationPanel::slotFilesItemChanged
);
2166 // i18n: This is the last paragraph for the "What's This"-texts of all four panels.
2167 const QString panelWhatsThis
= xi18nc("@info:whatsthis",
2169 "hide panels like this go to <interface>Menu|Panels</interface> "
2170 "or <interface>View|Panels</interface>.</para>");
2173 ->action(QStringLiteral("show_information_panel"))
2174 ->setWhatsThis(xi18nc("@info:whatsthis",
2175 "<para> This toggles the "
2176 "<emphasis>information</emphasis> panel at the right side of the "
2177 "window.</para><para>The panel provides in-depth information "
2178 "about the items your mouse is hovering over or about the selected "
2179 "items. Otherwise it informs you about the currently viewed folder.<nl/>"
2180 "For single items a preview of their contents is provided.</para>"));
2182 infoDock
->setWhatsThis(xi18nc("@info:whatsthis",
2184 "provides in-depth information about the items your mouse is "
2185 "hovering over or about the selected items. Otherwise it informs "
2186 "you about the currently viewed folder.<nl/>For single items a "
2187 "preview of their contents is provided.</para><para>You can configure "
2188 "which and how details are given here by right-clicking.</para>")
2192 DolphinDockWidget
*foldersDock
= new DolphinDockWidget(i18nc("@title:window", "Folders"));
2193 foldersDock
->setLocked(lock
);
2194 foldersDock
->setObjectName(QStringLiteral("foldersDock"));
2195 foldersDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
2196 FoldersPanel
*foldersPanel
= new FoldersPanel(foldersDock
);
2197 foldersPanel
->setCustomContextMenuActions({lockLayoutAction
});
2198 foldersDock
->setWidget(foldersPanel
);
2200 createPanelAction(QIcon::fromTheme(QStringLiteral("folder")), Qt::Key_F7
, foldersDock
, QStringLiteral("show_folders_panel"));
2202 addDockWidget(Qt::LeftDockWidgetArea
, foldersDock
);
2203 connect(this, &DolphinMainWindow::urlChanged
, foldersPanel
, &FoldersPanel::setUrl
);
2204 connect(foldersPanel
, &FoldersPanel::folderActivated
, this, &DolphinMainWindow::changeUrl
);
2205 connect(foldersPanel
, &FoldersPanel::folderInNewTab
, this, &DolphinMainWindow::openNewTab
);
2206 connect(foldersPanel
, &FoldersPanel::folderInNewActiveTab
, this, &DolphinMainWindow::openNewTabAndActivate
);
2207 connect(foldersPanel
, &FoldersPanel::errorMessage
, this, &DolphinMainWindow::showErrorMessage
);
2210 ->action(QStringLiteral("show_folders_panel"))
2211 ->setWhatsThis(xi18nc("@info:whatsthis",
2213 "<emphasis>folders</emphasis> panel at the left side of the window."
2214 "<nl/><nl/>It shows the folders of the <emphasis>file system"
2215 "</emphasis> in a <emphasis>tree view</emphasis>."));
2216 foldersDock
->setWhatsThis(xi18nc("@info:whatsthis",
2218 "shows the folders of the <emphasis>file system</emphasis> in a "
2219 "<emphasis>tree view</emphasis>.</para><para>Click a folder to go "
2220 "there. Click the arrow to the left of a folder to see its subfolders. "
2221 "This allows quick switching between any folders.</para>")
2226 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
2227 DolphinDockWidget
*terminalDock
= new DolphinDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
2228 terminalDock
->setLocked(lock
);
2229 terminalDock
->setObjectName(QStringLiteral("terminalDock"));
2230 terminalDock
->setContentsMargins(0, 0, 0, 0);
2231 m_terminalPanel
= new TerminalPanel(terminalDock
);
2232 m_terminalPanel
->setCustomContextMenuActions({lockLayoutAction
});
2233 terminalDock
->setWidget(m_terminalPanel
);
2235 connect(m_terminalPanel
, &TerminalPanel::hideTerminalPanel
, terminalDock
, &DolphinDockWidget::hide
);
2236 connect(m_terminalPanel
, &TerminalPanel::changeUrl
, this, &DolphinMainWindow::slotTerminalDirectoryChanged
);
2237 connect(terminalDock
, &DolphinDockWidget::visibilityChanged
, m_terminalPanel
, &TerminalPanel::dockVisibilityChanged
);
2238 connect(terminalDock
, &DolphinDockWidget::visibilityChanged
, this, &DolphinMainWindow::slotTerminalPanelVisibilityChanged
);
2240 createPanelAction(QIcon::fromTheme(QStringLiteral("dialog-scripts")), Qt::Key_F4
, terminalDock
, QStringLiteral("show_terminal_panel"));
2242 addDockWidget(Qt::BottomDockWidgetArea
, terminalDock
);
2243 connect(this, &DolphinMainWindow::urlChanged
, m_terminalPanel
, &TerminalPanel::setUrl
);
2245 if (GeneralSettings::version() < 200) {
2246 terminalDock
->hide();
2250 ->action(QStringLiteral("show_terminal_panel"))
2251 ->setWhatsThis(xi18nc("@info:whatsthis",
2252 "<para>This toggles the "
2253 "<emphasis>terminal</emphasis> panel at the bottom of the window."
2254 "<nl/>The location in the terminal will always match the folder "
2255 "view so you can navigate using either.</para><para>The terminal "
2256 "panel is not needed for basic computer usage but can be useful "
2257 "for advanced tasks. To learn more about terminals use the help "
2258 "in a standalone terminal application like Konsole.</para>"));
2259 terminalDock
->setWhatsThis(xi18nc("@info:whatsthis",
2261 "the <emphasis>terminal</emphasis> panel. It behaves like a "
2262 "normal terminal but will match the location of the folder view "
2263 "so you can navigate using either.</para><para>The terminal panel "
2264 "is not needed for basic computer usage but can be useful for "
2265 "advanced tasks. To learn more about terminals use the help in a "
2266 "standalone terminal application like Konsole.</para>")
2271 if (GeneralSettings::version() < 200) {
2273 foldersDock
->hide();
2277 DolphinDockWidget
*placesDock
= new DolphinDockWidget(i18nc("@title:window", "Places"));
2278 placesDock
->setLocked(lock
);
2279 placesDock
->setObjectName(QStringLiteral("placesDock"));
2280 placesDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
2282 m_placesPanel
= new PlacesPanel(placesDock
);
2283 m_placesPanel
->setCustomContextMenuActions({lockLayoutAction
});
2284 placesDock
->setWidget(m_placesPanel
);
2286 createPanelAction(QIcon::fromTheme(QStringLiteral("compass")), Qt::Key_F9
, placesDock
, QStringLiteral("show_places_panel"));
2288 addDockWidget(Qt::LeftDockWidgetArea
, placesDock
);
2289 connect(m_placesPanel
, &PlacesPanel::placeActivated
, this, &DolphinMainWindow::slotPlaceActivated
);
2290 connect(m_placesPanel
, &PlacesPanel::tabRequested
, this, &DolphinMainWindow::openNewTab
);
2291 connect(m_placesPanel
, &PlacesPanel::activeTabRequested
, this, &DolphinMainWindow::openNewTabAndActivate
);
2292 connect(m_placesPanel
, &PlacesPanel::newWindowRequested
, this, [this](const QUrl
&url
) {
2293 Dolphin::openNewWindow({url
}, this);
2295 connect(m_placesPanel
, &PlacesPanel::openInSplitViewRequested
, this, &DolphinMainWindow::openInSplitView
);
2296 connect(m_placesPanel
, &PlacesPanel::errorMessage
, this, &DolphinMainWindow::showErrorMessage
);
2297 connect(this, &DolphinMainWindow::urlChanged
, m_placesPanel
, &PlacesPanel::setUrl
);
2298 connect(placesDock
, &DolphinDockWidget::visibilityChanged
, &DolphinUrlNavigatorsController::slotPlacesPanelVisibilityChanged
);
2299 connect(this, &DolphinMainWindow::settingsChanged
, m_placesPanel
, &PlacesPanel::readSettings
);
2300 connect(m_placesPanel
, &PlacesPanel::storageTearDownRequested
, this, &DolphinMainWindow::slotStorageTearDownFromPlacesRequested
);
2301 connect(m_placesPanel
, &PlacesPanel::storageTearDownExternallyRequested
, this, &DolphinMainWindow::slotStorageTearDownExternallyRequested
);
2302 DolphinUrlNavigatorsController::slotPlacesPanelVisibilityChanged(m_placesPanel
->isVisible());
2304 auto actionShowAllPlaces
= new QAction(QIcon::fromTheme(QStringLiteral("view-hidden")), i18nc("@item:inmenu", "Show Hidden Places"), this);
2305 actionShowAllPlaces
->setCheckable(true);
2306 actionShowAllPlaces
->setDisabled(true);
2307 actionShowAllPlaces
->setWhatsThis(i18nc("@info:whatsthis",
2309 "all places in the places panel that have been hidden. They will "
2310 "appear semi-transparent unless you uncheck their hide property."));
2312 connect(actionShowAllPlaces
, &QAction::triggered
, this, [this](bool checked
) {
2313 m_placesPanel
->setShowAll(checked
);
2315 connect(m_placesPanel
, &PlacesPanel::allPlacesShownChanged
, actionShowAllPlaces
, &QAction::setChecked
);
2318 ->action(QStringLiteral("show_places_panel"))
2319 ->setWhatsThis(xi18nc("@info:whatsthis",
2320 "<para>This toggles the "
2321 "<emphasis>places</emphasis> panel at the left side of the window."
2322 "</para><para>It allows you to go to locations you have "
2323 "bookmarked and to access disk or media attached to the computer "
2324 "or to the network. It also contains sections to find recently "
2325 "saved files or files of a certain type.</para>"));
2326 placesDock
->setWhatsThis(xi18nc("@info:whatsthis",
2327 "<para>This is the "
2328 "<emphasis>Places</emphasis> panel. It allows you to go to locations "
2329 "you have bookmarked and to access disk or media attached to the "
2330 "computer or to the network. It also contains sections to find "
2331 "recently saved files or files of a certain type.</para><para>"
2332 "Click on an entry to go there. Click with the right mouse button "
2333 "instead to open any entry in a new tab or new window.</para>"
2334 "<para>New entries can be added by dragging folders onto this panel. "
2335 "Right-click any section or entry to hide it. Right-click an empty "
2336 "space on this panel and select <interface>Show Hidden Places"
2337 "</interface> to display it again.</para>")
2340 // Add actions into the "Panels" menu
2341 KActionMenu
*panelsMenu
= new KActionMenu(i18nc("@action:inmenu View", "Show Panels"), this);
2342 actionCollection()->addAction(QStringLiteral("panels"), panelsMenu
);
2343 panelsMenu
->setIcon(QIcon::fromTheme(QStringLiteral("view-sidetree")));
2344 panelsMenu
->setPopupMode(QToolButton::InstantPopup
);
2345 const KActionCollection
*ac
= actionCollection();
2346 panelsMenu
->addAction(ac
->action(QStringLiteral("show_places_panel")));
2348 panelsMenu
->addAction(ac
->action(QStringLiteral("show_information_panel")));
2350 panelsMenu
->addAction(ac
->action(QStringLiteral("show_folders_panel")));
2351 panelsMenu
->addAction(ac
->action(QStringLiteral("show_terminal_panel")));
2352 panelsMenu
->addSeparator();
2353 panelsMenu
->addAction(actionShowAllPlaces
);
2354 panelsMenu
->addAction(lockLayoutAction
);
2356 connect(panelsMenu
->menu(), &QMenu::aboutToShow
, this, [actionShowAllPlaces
] {
2357 actionShowAllPlaces
->setEnabled(DolphinPlacesModelSingleton::instance().placesModel()->hiddenCount());
2361 void DolphinMainWindow::updateFileAndEditActions()
2363 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
2364 const KActionCollection
*col
= actionCollection();
2365 KFileItemListProperties
capabilitiesSource(list
);
2367 QAction
*renameAction
= col
->action(KStandardAction::name(KStandardAction::RenameFile
));
2368 QAction
*moveToTrashAction
= col
->action(KStandardAction::name(KStandardAction::MoveToTrash
));
2369 QAction
*deleteAction
= col
->action(KStandardAction::name(KStandardAction::DeleteFile
));
2370 QAction
*cutAction
= col
->action(KStandardAction::name(KStandardAction::Cut
));
2371 QAction
*duplicateAction
= col
->action(QStringLiteral("duplicate")); // see DolphinViewActionHandler
2372 QAction
*addToPlacesAction
= col
->action(QStringLiteral("add_to_places"));
2373 QAction
*copyToOtherViewAction
= col
->action(QStringLiteral("copy_to_inactive_split_view"));
2374 QAction
*moveToOtherViewAction
= col
->action(QStringLiteral("move_to_inactive_split_view"));
2375 QAction
*copyLocation
= col
->action(QString("copy_location"));
2377 if (list
.isEmpty()) {
2378 stateChanged(QStringLiteral("has_no_selection"));
2380 // All actions that need a selection to function can be enabled because they should trigger selection mode.
2381 renameAction
->setEnabled(true);
2382 moveToTrashAction
->setEnabled(true);
2383 deleteAction
->setEnabled(true);
2384 cutAction
->setEnabled(true);
2385 duplicateAction
->setEnabled(true);
2386 addToPlacesAction
->setEnabled(true);
2387 copyLocation
->setEnabled(true);
2388 // Them triggering selection mode and not directly acting on selected items is signified by adding "…" to their text.
2389 m_actionTextHelper
->textsWhenNothingIsSelectedEnabled(true);
2392 m_actionTextHelper
->textsWhenNothingIsSelectedEnabled(false);
2393 stateChanged(QStringLiteral("has_selection"));
2395 QAction
*deleteWithTrashShortcut
= col
->action(QStringLiteral("delete_shortcut")); // see DolphinViewActionHandler
2396 QAction
*showTarget
= col
->action(QStringLiteral("show_target"));
2398 if (list
.length() == 1 && list
.first().isDir()) {
2399 addToPlacesAction
->setEnabled(true);
2401 addToPlacesAction
->setEnabled(false);
2404 const bool enableMoveToTrash
= capabilitiesSource
.isLocal() && capabilitiesSource
.supportsMoving();
2406 renameAction
->setEnabled(capabilitiesSource
.supportsMoving());
2407 moveToTrashAction
->setEnabled(enableMoveToTrash
);
2408 deleteAction
->setEnabled(capabilitiesSource
.supportsDeleting());
2409 deleteWithTrashShortcut
->setEnabled(capabilitiesSource
.supportsDeleting() && !enableMoveToTrash
);
2410 cutAction
->setEnabled(capabilitiesSource
.supportsMoving());
2411 copyLocation
->setEnabled(list
.length() == 1);
2412 showTarget
->setEnabled(list
.length() == 1 && list
.at(0).isLink());
2413 duplicateAction
->setEnabled(capabilitiesSource
.supportsWriting());
2416 if (m_tabWidget
->currentTabPage()->splitViewEnabled() && !list
.isEmpty()) {
2417 DolphinTabPage
*tabPage
= m_tabWidget
->currentTabPage();
2418 KFileItem capabilitiesDestination
;
2420 if (tabPage
->primaryViewActive()) {
2421 capabilitiesDestination
= tabPage
->secondaryViewContainer()->rootItem();
2423 capabilitiesDestination
= tabPage
->primaryViewContainer()->rootItem();
2426 const auto destUrl
= capabilitiesDestination
.url();
2427 const bool allNotTargetOrigin
= std::all_of(list
.cbegin(), list
.cend(), [destUrl
](const KFileItem
&item
) {
2428 return item
.url().adjusted(QUrl::RemoveFilename
| QUrl::StripTrailingSlash
) != destUrl
;
2431 copyToOtherViewAction
->setEnabled(capabilitiesDestination
.isWritable() && allNotTargetOrigin
);
2432 moveToOtherViewAction
->setEnabled((list
.isEmpty() || capabilitiesSource
.supportsMoving()) && capabilitiesDestination
.isWritable()
2433 && allNotTargetOrigin
);
2435 copyToOtherViewAction
->setEnabled(false);
2436 moveToOtherViewAction
->setEnabled(false);
2440 void DolphinMainWindow::updateViewActions()
2442 m_actionHandler
->updateViewActions();
2444 QAction
*toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
2445 toggleFilterBarAction
->setChecked(m_activeViewContainer
->isFilterBarVisible());
2447 updateSplitActions();
2450 void DolphinMainWindow::updateGoActions()
2452 QAction
*goUpAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Up
));
2453 const QUrl currentUrl
= m_activeViewContainer
->url();
2454 // I think this is one of the best places to firstly be confronted
2455 // with a file system and its hierarchy. Talking about the root
2456 // directory might seem too much here but it is the question that
2457 // naturally arises in this context.
2458 goUpAction
->setWhatsThis(xi18nc("@info:whatsthis",
2460 "the folder that contains the currently viewed one.</para>"
2461 "<para>All files and folders are organized in a hierarchical "
2462 "<emphasis>file system</emphasis>. At the top of this hierarchy is "
2463 "a directory that contains all data connected to this computer"
2464 "—the <emphasis>root directory</emphasis>.</para>"));
2465 goUpAction
->setEnabled(KIO::upUrl(currentUrl
) != currentUrl
);
2468 void DolphinMainWindow::refreshViews()
2470 m_tabWidget
->refreshViews();
2472 if (GeneralSettings::modifiedStartupSettings()) {
2473 updateWindowTitle();
2476 updateSplitActions();
2478 Q_EMIT
settingsChanged();
2481 void DolphinMainWindow::clearStatusBar()
2483 m_activeViewContainer
->statusBar()->resetToDefaultText();
2486 void DolphinMainWindow::connectViewSignals(DolphinViewContainer
*container
)
2488 connect(container
, &DolphinViewContainer::showFilterBarChanged
, this, &DolphinMainWindow::updateFilterBarAction
);
2489 connect(container
, &DolphinViewContainer::writeStateChanged
, this, &DolphinMainWindow::slotWriteStateChanged
);
2490 slotWriteStateChanged(container
->view()->isFolderWritable());
2491 connect(container
, &DolphinViewContainer::searchModeEnabledChanged
, this, &DolphinMainWindow::updateSearchAction
);
2492 connect(container
, &DolphinViewContainer::captionChanged
, this, &DolphinMainWindow::updateWindowTitle
);
2493 connect(container
, &DolphinViewContainer::tabRequested
, this, &DolphinMainWindow::openNewTab
);
2494 connect(container
, &DolphinViewContainer::activeTabRequested
, this, &DolphinMainWindow::openNewTabAndActivate
);
2496 const QAction
*toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
2497 connect(toggleSearchAction
, &QAction::triggered
, container
, &DolphinViewContainer::setSearchModeEnabled
);
2499 // Make the toggled state of the selection mode actions visually follow the selection mode state of the view.
2500 auto toggleSelectionModeAction
= actionCollection()->action(QStringLiteral("toggle_selection_mode"));
2501 toggleSelectionModeAction
->setChecked(m_activeViewContainer
->isSelectionModeEnabled());
2502 connect(m_activeViewContainer
, &DolphinViewContainer::selectionModeChanged
, toggleSelectionModeAction
, &QAction::setChecked
);
2504 const DolphinView
*view
= container
->view();
2505 connect(view
, &DolphinView::selectionChanged
, this, &DolphinMainWindow::slotSelectionChanged
);
2506 connect(view
, &DolphinView::requestItemInfo
, this, &DolphinMainWindow::requestItemInfo
);
2507 connect(view
, &DolphinView::fileItemsChanged
, this, &DolphinMainWindow::fileItemsChanged
);
2508 connect(view
, &DolphinView::tabRequested
, this, &DolphinMainWindow::openNewTab
);
2509 connect(view
, &DolphinView::activeTabRequested
, this, &DolphinMainWindow::openNewTabAndActivate
);
2510 connect(view
, &DolphinView::windowRequested
, this, &DolphinMainWindow::openNewWindow
);
2511 connect(view
, &DolphinView::requestContextMenu
, this, &DolphinMainWindow::openContextMenu
);
2512 connect(view
, &DolphinView::directoryLoadingStarted
, this, &DolphinMainWindow::enableStopAction
);
2513 connect(view
, &DolphinView::directoryLoadingCompleted
, this, &DolphinMainWindow::disableStopAction
);
2514 connect(view
, &DolphinView::directoryLoadingCompleted
, this, &DolphinMainWindow::slotDirectoryLoadingCompleted
);
2515 connect(view
, &DolphinView::goBackRequested
, this, &DolphinMainWindow::goBack
);
2516 connect(view
, &DolphinView::goForwardRequested
, this, &DolphinMainWindow::goForward
);
2517 connect(view
, &DolphinView::urlActivated
, this, &DolphinMainWindow::handleUrl
);
2518 connect(view
, &DolphinView::goUpRequested
, this, &DolphinMainWindow::goUp
);
2520 connect(container
->urlNavigatorInternalWithHistory(), &KUrlNavigator::urlChanged
, this, &DolphinMainWindow::changeUrl
);
2521 connect(container
->urlNavigatorInternalWithHistory(), &KUrlNavigator::historyChanged
, this, &DolphinMainWindow::updateHistory
);
2523 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>(actionCollection()->action(QStringLiteral("url_navigators")));
2524 const KUrlNavigator
*navigator
=
2525 m_tabWidget
->currentTabPage()->primaryViewActive() ? navigators
->primaryUrlNavigator() : navigators
->secondaryUrlNavigator();
2527 QAction
*editableLocactionAction
= actionCollection()->action(QStringLiteral("editable_location"));
2528 editableLocactionAction
->setChecked(navigator
->isUrlEditable());
2529 connect(navigator
, &KUrlNavigator::editableStateChanged
, this, &DolphinMainWindow::slotEditableStateChanged
);
2530 connect(navigator
, &KUrlNavigator::tabRequested
, this, &DolphinMainWindow::openNewTab
);
2531 connect(navigator
, &KUrlNavigator::activeTabRequested
, this, &DolphinMainWindow::openNewTabAndActivate
);
2532 connect(navigator
, &KUrlNavigator::newWindowRequested
, this, &DolphinMainWindow::openNewWindow
);
2535 void DolphinMainWindow::updateSplitActions()
2537 QAction
*popoutSplitAction
= actionCollection()->action(QStringLiteral("popout_split_view"));
2539 auto setActionPopupMode
= [this](KActionMenu
*action
, QToolButton::ToolButtonPopupMode popupMode
) {
2540 action
->setPopupMode(popupMode
);
2541 if (auto *buttonForAction
= qobject_cast
<QToolButton
*>(toolBar()->widgetForAction(action
))) {
2542 buttonForAction
->setPopupMode(popupMode
);
2546 const DolphinTabPage
*tabPage
= m_tabWidget
->currentTabPage();
2547 if (tabPage
->splitViewEnabled()) {
2548 if (GeneralSettings::closeActiveSplitView() ? tabPage
->primaryViewActive() : !tabPage
->primaryViewActive()) {
2549 m_splitViewAction
->setText(i18nc("@action:intoolbar Close left view", "Close"));
2550 m_splitViewAction
->setToolTip(i18nc("@info", "Close left view"));
2551 m_splitViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-left-close")));
2552 popoutSplitAction
->setText(i18nc("@action:intoolbar Move left split view to a new window", "Pop out"));
2553 popoutSplitAction
->setToolTip(i18nc("@info", "Move left split view to a new window"));
2555 m_splitViewAction
->setText(i18nc("@action:intoolbar Close right view", "Close"));
2556 m_splitViewAction
->setToolTip(i18nc("@info", "Close right view"));
2557 m_splitViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-right-close")));
2558 popoutSplitAction
->setText(i18nc("@action:intoolbar Move right split view to a new window", "Pop out"));
2559 popoutSplitAction
->setToolTip(i18nc("@info", "Move right split view to a new window"));
2561 popoutSplitAction
->setEnabled(true);
2562 if (!m_splitViewAction
->menu()) {
2563 setActionPopupMode(m_splitViewAction
, QToolButton::MenuButtonPopup
);
2564 m_splitViewAction
->setMenu(new QMenu
);
2565 m_splitViewAction
->addAction(popoutSplitAction
);
2568 m_splitViewAction
->setText(i18nc("@action:intoolbar Split view", "Split"));
2569 m_splitViewAction
->setToolTip(i18nc("@info", "Split view"));
2570 m_splitViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-right-new")));
2571 popoutSplitAction
->setText(i18nc("@action:intoolbar Move active split view to a new window", "Pop out"));
2572 popoutSplitAction
->setEnabled(false);
2573 if (m_splitViewAction
->menu()) {
2574 m_splitViewAction
->removeAction(popoutSplitAction
);
2575 m_splitViewAction
->menu()->deleteLater();
2576 m_splitViewAction
->setMenu(nullptr);
2577 setActionPopupMode(m_splitViewAction
, QToolButton::DelayedPopup
);
2581 // Update state from toolbar action
2582 m_splitViewMenuAction
->setText(m_splitViewAction
->text());
2583 m_splitViewMenuAction
->setToolTip(m_splitViewAction
->toolTip());
2584 m_splitViewMenuAction
->setIcon(m_splitViewAction
->icon());
2587 void DolphinMainWindow::updateAllowedToolbarAreas()
2589 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>(actionCollection()->action(QStringLiteral("url_navigators")));
2590 if (toolBar()->actions().contains(navigators
)) {
2591 toolBar()->setAllowedAreas(Qt::TopToolBarArea
| Qt::BottomToolBarArea
);
2592 if (toolBarArea(toolBar()) == Qt::LeftToolBarArea
|| toolBarArea(toolBar()) == Qt::RightToolBarArea
) {
2593 addToolBar(Qt::TopToolBarArea
, toolBar());
2596 toolBar()->setAllowedAreas(Qt::AllToolBarAreas
);
2600 bool DolphinMainWindow::isKompareInstalled() const
2602 static bool initialized
= false;
2603 static bool installed
= false;
2605 // TODO: maybe replace this approach later by using a menu
2606 // plugin like kdiff3plugin.cpp
2607 installed
= !QStandardPaths::findExecutable(QStringLiteral("kompare")).isEmpty();
2613 void DolphinMainWindow::createPanelAction(const QIcon
&icon
, const QKeySequence
&shortcut
, QDockWidget
*dockWidget
, const QString
&actionName
)
2615 auto dockAction
= dockWidget
->toggleViewAction();
2616 dockAction
->setIcon(icon
);
2617 dockAction
->setEnabled(true);
2619 QAction
*panelAction
= actionCollection()->addAction(actionName
, dockAction
);
2620 actionCollection()->setDefaultShortcut(panelAction
, shortcut
);
2622 connect(panelAction
, &QAction::toggled
, dockWidget
, &QWidget::setVisible
);
2625 void DolphinMainWindow::setupWhatsThis()
2628 menuBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2629 "<emphasis>Menubar</emphasis>. It provides access to commands and "
2630 "configuration options. Left-click on any of the menus on this "
2631 "bar to see its contents.</para><para>The Menubar can be hidden "
2632 "by unchecking <interface>Settings|Show Menubar</interface>. Then "
2633 "most of its contents become available through a <interface>Menu"
2634 "</interface> button on the <emphasis>Toolbar</emphasis>.</para>"));
2635 toolBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2636 "<emphasis>Toolbar</emphasis>. It allows quick access to "
2637 "frequently used actions.</para><para>It is highly customizable. "
2638 "All items you see in the <interface>Menu</interface> or "
2639 "in the <interface>Menubar</interface> can be placed on the "
2640 "Toolbar. Just right-click on it and select <interface>Configure "
2641 "Toolbars…</interface> or find this action within the <interface>"
2643 "</para><para>The location of the bar and the style of its "
2644 "buttons can also be changed in the right-click menu. Right-click "
2645 "a button if you want to show or hide its text.</para>"));
2646 m_tabWidget
->setWhatsThis(xi18nc("@info:whatsthis main view",
2647 "<para>Here you can see the <emphasis>folders</emphasis> and "
2648 "<emphasis>files</emphasis> that are at the location described in "
2649 "the <interface>Location Bar</interface> above. This area is the "
2650 "central part of this application where you navigate to the files "
2651 "you want to use.</para><para>For an elaborate and general "
2652 "introduction to this application <link "
2653 "url='https://userbase.kde.org/Dolphin/File_Management#Introduction_to_Dolphin'>"
2654 "click here</link>. This will open an introductory article from "
2655 "the <emphasis>KDE UserBase Wiki</emphasis>.</para><para>For brief "
2656 "explanations of all the features of this <emphasis>view</emphasis> "
2657 "<link url='help:/dolphin/dolphin-view.html'>click here</link> "
2658 "instead. This will open a page from the <emphasis>Handbook"
2659 "</emphasis> that covers the basics.</para>"));
2662 actionCollection()->action(KStandardAction::name(KStandardAction::KeyBindings
))
2663 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window "
2664 "that lists the <emphasis>keyboard shortcuts</emphasis>.<nl/>"
2665 "There you can set up key combinations to trigger an action when "
2666 "they are pressed simultaneously. All commands in this application can "
2667 "be triggered this way.</para>"));
2668 actionCollection()->action(KStandardAction::name(KStandardAction::ConfigureToolbars
))
2669 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window in which "
2670 "you can change which buttons appear on the <emphasis>Toolbar</emphasis>.</para>"
2671 "<para>All items you see in the <interface>Menu</interface> can also be placed on the Toolbar.</para>"));
2672 actionCollection()->action(KStandardAction::name(KStandardAction::Preferences
))
2673 ->setWhatsThis(xi18nc("@info:whatsthis","This opens a window where you can "
2674 "change a multitude of settings for this application. For an explanation "
2675 "of the various settings go to the chapter <emphasis>Configuring Dolphin"
2676 "</emphasis> in <interface>Help|Dolphin Handbook</interface>."));
2680 auto setStandardActionWhatsThis
= [this](KStandardAction::StandardAction actionId
,
2681 const QString
&whatsThis
) {
2682 // Check for the existence of an action since it can be restricted through the Kiosk system
2683 if (auto *action
= actionCollection()->action(KStandardAction::name(actionId
))) {
2684 action
->setWhatsThis(whatsThis
);
2688 // i18n: If the external link isn't available in your language it might make
2689 // sense to state the external link's language in brackets to not
2690 // frustrate the user. If there are multiple languages that the user might
2691 // know with a reasonable chance you might want to have 2 external links.
2692 // The same might be true for any external link you translate.
2693 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>"));
2694 // (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 )
2696 setStandardActionWhatsThis(KStandardAction::WhatsThis
,
2697 xi18nc("@info:whatsthis whatsthis button",
2698 "<para>This is the button that invokes the help feature you are "
2699 "using right now! Click it, then click any component of this "
2700 "application to ask \"What's this?\" about it. The mouse cursor "
2701 "will change appearance if no help is available for a spot.</para>"
2702 "<para>There are two other ways to get help: "
2703 "The <link url='help:/dolphin/index.html'>Dolphin Handbook</link> and "
2704 "the <link url='https://userbase.kde.org/Dolphin/File_Management'>KDE "
2705 "UserBase Wiki</link>.</para><para>The \"What's this?\" help is "
2706 "missing in most other windows so don't get too used to this.</para>"));
2708 setStandardActionWhatsThis(KStandardAction::ReportBug
,
2709 xi18nc("@info:whatsthis","<para>This opens a "
2710 "window that will guide you through reporting errors or flaws "
2711 "in this application or in other KDE software.</para>"
2712 "<para>High-quality bug reports are much appreciated. To learn "
2713 "how to make your bug report as effective as possible "
2714 "<link url='https://community.kde.org/Get_Involved/Bug_Reporting'>"
2715 "click here</link>.</para>"));
2717 setStandardActionWhatsThis(KStandardAction::Donate
,
2718 xi18nc("@info:whatsthis", "<para>This opens a "
2719 "<emphasis>web page</emphasis> where you can donate to "
2720 "support the continued work on this application and many "
2721 "other projects by the <emphasis>KDE</emphasis> community.</para>"
2722 "<para>Donating is the easiest and fastest way to efficiently "
2723 "support KDE and its projects. KDE projects are available for "
2724 "free therefore your donation is needed to cover things that "
2725 "require money like servers, contributor meetings, etc.</para>"
2726 "<para><emphasis>KDE e.V.</emphasis> is the non-profit "
2727 "organization behind the KDE community.</para>"));
2729 setStandardActionWhatsThis(KStandardAction::SwitchApplicationLanguage
,
2730 xi18nc("@info:whatsthis",
2731 "With this you can change the language this application uses."
2732 "<nl/>You can even set secondary languages which will be used "
2733 "if texts are not available in your preferred language."));
2735 setStandardActionWhatsThis(KStandardAction::AboutApp
,
2736 xi18nc("@info:whatsthis","This opens a "
2737 "window that informs you about the version, license, "
2738 "used libraries and maintainers of this application."));
2740 setStandardActionWhatsThis(KStandardAction::AboutKDE
,
2741 xi18nc("@info:whatsthis","This opens a "
2742 "window with information about <emphasis>KDE</emphasis>. "
2743 "The KDE community are the people behind this free software."
2744 "<nl/>If you like using this application but don't know "
2745 "about KDE or want to see a cute dragon have a look!"));
2749 bool DolphinMainWindow::addHamburgerMenuToToolbar()
2751 QDomDocument domDocument
= KXMLGUIClient::domDocument();
2752 if (domDocument
.isNull()) {
2755 QDomNode toolbar
= domDocument
.elementsByTagName(QStringLiteral("ToolBar")).at(0);
2756 if (toolbar
.isNull()) {
2760 QDomElement hamburgerMenuElement
= domDocument
.createElement(QStringLiteral("Action"));
2761 hamburgerMenuElement
.setAttribute(QStringLiteral("name"), QStringLiteral("hamburger_menu"));
2762 toolbar
.appendChild(hamburgerMenuElement
);
2764 KXMLGUIFactory::saveConfigFile(domDocument
, xmlFile());
2768 // Make sure to also remove the <KXMLGUIFactory> and <QDomDocument> include
2769 // whenever this method is removed (maybe in the year ~2026).
2772 // Set a sane initial window size
2773 QSize
DolphinMainWindow::sizeHint() const
2775 return KXmlGuiWindow::sizeHint().expandedTo(QSize(760, 550));
2778 void DolphinMainWindow::saveNewToolbarConfig()
2780 KXmlGuiWindow::saveNewToolbarConfig(); // Applies the new config. This has to be called first
2781 // because the rest of this method decides things
2782 // based on the new config.
2783 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>(actionCollection()->action(QStringLiteral("url_navigators")));
2784 if (!toolBar()->actions().contains(navigators
)) {
2785 m_tabWidget
->currentTabPage()->insertNavigatorsWidget(navigators
);
2787 updateAllowedToolbarAreas();
2788 (static_cast<KHamburgerMenu
*>(actionCollection()->action(KStandardAction::name(KStandardAction::HamburgerMenu
))))->hideActionsOf(toolBar());
2791 void DolphinMainWindow::focusTerminalPanel()
2793 if (m_terminalPanel
->isVisible()) {
2794 if (m_terminalPanel
->terminalHasFocus()) {
2795 m_activeViewContainer
->view()->setFocus(Qt::FocusReason::ShortcutFocusReason
);
2796 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
2798 m_terminalPanel
->setFocus(Qt::FocusReason::ShortcutFocusReason
);
2799 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
2802 actionCollection()->action(QStringLiteral("show_terminal_panel"))->trigger();
2803 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
2807 DolphinMainWindow::UndoUiInterface::UndoUiInterface()
2808 : KIO::FileUndoManager::UiInterface()
2812 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
2816 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
*job
)
2818 DolphinMainWindow
*mainWin
= qobject_cast
<DolphinMainWindow
*>(parentWidget());
2820 DolphinViewContainer
*container
= mainWin
->activeViewContainer();
2821 container
->showMessage(job
->errorString(), DolphinViewContainer::Error
);
2823 KIO::FileUndoManager::UiInterface::jobError(job
);
2827 bool DolphinMainWindow::isUrlOpen(const QString
&url
)
2829 return m_tabWidget
->isUrlOpen(QUrl::fromUserInput(url
));
2832 bool DolphinMainWindow::isItemVisibleInAnyView(const QString
&urlOfItem
)
2834 return m_tabWidget
->isItemVisibleInAnyView(QUrl::fromUserInput(urlOfItem
));
2837 #include "moc_dolphinmainwindow.cpp"