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 "dolphinmainwindowadaptor.h"
13 #include "dolphinbookmarkhandler.h"
14 #include "dolphindockwidget.h"
15 #include "dolphincontextmenu.h"
16 #include "dolphinnavigatorswidgetaction.h"
17 #include "dolphinnewfilemenu.h"
18 #include "dolphinrecenttabsmenu.h"
19 #include "dolphinplacesmodelsingleton.h"
20 #include "dolphinurlnavigatorscontroller.h"
21 #include "dolphinviewcontainer.h"
22 #include "dolphintabpage.h"
23 #include "middleclickactioneventfilter.h"
24 #include "panels/folders/folderspanel.h"
25 #include "panels/places/placespanel.h"
26 #include "panels/terminal/terminalpanel.h"
27 #include "settings/dolphinsettingsdialog.h"
28 #include "statusbar/dolphinstatusbar.h"
29 #include "views/dolphinviewactionhandler.h"
30 #include "views/dolphinremoteencoding.h"
31 #include "views/draganddrophelper.h"
32 #include "views/viewproperties.h"
33 #include "views/dolphinnewfilemenuobserver.h"
34 #include "dolphin_generalsettings.h"
36 #include <KActionCollection>
37 #include <KActionMenu>
38 #include <KAuthorized>
41 #include <KDualAction>
42 #include <KFileItemListProperties>
44 #include <KIO/CommandLauncherJob>
45 #include <KIO/JobUiDelegate>
46 #include <KIO/OpenFileManagerWindowJob>
47 #include <KIO/OpenUrlJob>
48 #include <KJobWidgets>
49 #include <KLocalizedString>
50 #include <KMessageBox>
51 #include <KMoreToolsMenuFactory>
52 #include <KProtocolInfo>
53 #include <KProtocolManager>
55 #include <KShortcutsDialog>
56 #include <KStandardAction>
57 #include <KStartupInfo>
59 #include <KTerminalLauncherJob>
60 #include <KToggleAction>
62 #include <KToolBarPopupAction>
63 #include <KUrlComboBox>
64 #include <KUrlNavigator>
65 #include <KWindowSystem>
66 #include <KXMLGUIFactory>
68 #include <kio_version.h>
70 #include <QApplication>
72 #include <QCloseEvent>
73 #include <QDesktopServices>
75 #include <QDomDocument>
79 #include <QPushButton>
81 #include <QStandardPaths>
83 #include <QToolButton>
84 #include <QWhatsThisClickedEvent>
89 // Used for GeneralSettings::version() to determine whether
90 // an updated version of Dolphin is running, so as to migrate
91 // removed/renamed ...etc config entries; increment it in such
93 const int CurrentDolphinVersion
= 202;
94 // The maximum number of entries in the back/forward popup menu
95 const int MaxNumberOfNavigationentries
= 12;
96 // The maximum number of "Activate Tab" shortcuts
97 const int MaxActivateTabShortcuts
= 9;
100 DolphinMainWindow::DolphinMainWindow() :
101 KXmlGuiWindow(nullptr),
102 m_newFileMenu(nullptr),
104 m_tabWidget(nullptr),
105 m_activeViewContainer(nullptr),
106 m_actionHandler(nullptr),
107 m_remoteEncoding(nullptr),
109 m_bookmarkHandler(nullptr),
110 m_controlButton(nullptr),
111 m_updateToolBarTimer(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)
119 Q_INIT_RESOURCE(dolphin
);
121 new MainWindowAdaptor(this);
124 setWindowFlags(Qt::WindowContextHelpButtonHint
);
126 setComponentName(QStringLiteral("dolphin"), QGuiApplication::applicationDisplayName());
127 setObjectName(QStringLiteral("Dolphin#"));
129 //setStateConfigGroup("State"); // TODO: Don't leave this as a comment.
131 connect(&DolphinNewFileMenuObserver::instance(), &DolphinNewFileMenuObserver::errorMessage
,
132 this, &DolphinMainWindow::showErrorMessage
);
134 KIO::FileUndoManager
* undoManager
= KIO::FileUndoManager::self();
135 undoManager
->setUiInterface(new UndoUiInterface());
137 connect(undoManager
, &KIO::FileUndoManager::undoAvailable
,
138 this, &DolphinMainWindow::slotUndoAvailable
);
139 connect(undoManager
, &KIO::FileUndoManager::undoTextChanged
,
140 this, &DolphinMainWindow::slotUndoTextChanged
);
141 connect(undoManager
, &KIO::FileUndoManager::jobRecordingStarted
,
142 this, &DolphinMainWindow::clearStatusBar
);
143 connect(undoManager
, &KIO::FileUndoManager::jobRecordingFinished
,
144 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
,
158 this, &DolphinMainWindow::activeViewChanged
);
159 connect(m_tabWidget
, &DolphinTabWidget::tabCountChanged
,
160 this, &DolphinMainWindow::tabCountChanged
);
161 connect(m_tabWidget
, &DolphinTabWidget::currentUrlChanged
,
162 this, &DolphinMainWindow::updateWindowTitle
);
163 setCentralWidget(m_tabWidget
);
167 m_actionHandler
= new DolphinViewActionHandler(actionCollection(), this);
168 connect(m_actionHandler
, &DolphinViewActionHandler::actionBeingHandled
, this, &DolphinMainWindow::clearStatusBar
);
169 connect(m_actionHandler
, &DolphinViewActionHandler::createDirectoryTriggered
, this, &DolphinMainWindow::createDirectory
);
170 connect(m_actionHandler
, &DolphinViewActionHandler::setSelectionMode
, this, &DolphinMainWindow::slotSetSelectionMode
);
172 m_remoteEncoding
= new DolphinRemoteEncoding(this, m_actionHandler
);
173 connect(this, &DolphinMainWindow::urlChanged
,
174 m_remoteEncoding
, &DolphinRemoteEncoding::slotAboutToOpenUrl
);
178 setupGUI(Save
| Create
| ToolBar
);
179 stateChanged(QStringLiteral("new_file"));
181 QClipboard
* clipboard
= QApplication::clipboard();
182 connect(clipboard
, &QClipboard::dataChanged
,
183 this, &DolphinMainWindow::updatePasteAction
);
185 QAction
* toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
186 toggleFilterBarAction
->setChecked(GeneralSettings::filterBar());
189 menuBar()->setVisible(false);
192 const bool showMenu
= !menuBar()->isHidden();
193 QAction
* showMenuBarAction
= actionCollection()->action(KStandardAction::name(KStandardAction::ShowMenubar
));
194 showMenuBarAction
->setChecked(showMenu
); // workaround for bug #171080
196 auto hamburgerMenu
= static_cast<KHamburgerMenu
*>(actionCollection()->action(
197 KStandardAction::name(KStandardAction::HamburgerMenu
)));
198 hamburgerMenu
->icon();
199 hamburgerMenu
->setMenuBar(menuBar());
200 hamburgerMenu
->setShowMenuBarAction(showMenuBarAction
);
201 connect(hamburgerMenu
, &KHamburgerMenu::aboutToShowMenu
,
202 this, &DolphinMainWindow::updateHamburgerMenu
);
203 hamburgerMenu
->hideActionsOf(toolBar());
204 if (GeneralSettings::version() < 201 && !toolBar()->actions().contains(hamburgerMenu
)) {
205 addHamburgerMenuToToolbar();
208 updateAllowedToolbarAreas();
210 // enable middle-click on back/forward/up to open in a new tab
211 auto *middleClickEventFilter
= new MiddleClickActionEventFilter(this);
212 connect(middleClickEventFilter
, &MiddleClickActionEventFilter::actionMiddleClicked
, this, &DolphinMainWindow::slotToolBarActionMiddleClicked
);
213 toolBar()->installEventFilter(middleClickEventFilter
);
217 connect(KSycoca::self(), &KSycoca::databaseChanged
, this, &DolphinMainWindow::updateOpenPreferredSearchToolAction
);
219 QTimer::singleShot(0, this, &DolphinMainWindow::updateOpenPreferredSearchToolAction
);
221 m_fileItemActions
.setParentWidget(this);
222 connect(&m_fileItemActions
, &KFileItemActions::error
, this, [this](const QString
&errorMessage
) {
223 showErrorMessage(errorMessage
);
226 connect(GeneralSettings::self(), &GeneralSettings::splitViewChanged
,
227 this, &DolphinMainWindow::slotSplitViewChanged
);
230 DolphinMainWindow::~DolphinMainWindow()
232 // This fixes a crash on Wayland when closing the mainwindow while another dialog is open.
233 disconnect(QGuiApplication::clipboard(), &QClipboard::dataChanged
, this, &DolphinMainWindow::updatePasteAction
);
236 QVector
<DolphinViewContainer
*> DolphinMainWindow::viewContainers() const
238 QVector
<DolphinViewContainer
*> viewContainers
;
240 for (int i
= 0; i
< m_tabWidget
->count(); ++i
) {
241 DolphinTabPage
*tabPage
= m_tabWidget
->tabPageAt(i
);
243 viewContainers
<< tabPage
->primaryViewContainer();
244 if (tabPage
->splitViewEnabled()) {
245 viewContainers
<< tabPage
->secondaryViewContainer();
248 return viewContainers
;
251 void DolphinMainWindow::openDirectories(const QList
<QUrl
>& dirs
, bool splitView
)
253 m_tabWidget
->openDirectories(dirs
, splitView
);
256 void DolphinMainWindow::openDirectories(const QStringList
& dirs
, bool splitView
)
258 openDirectories(QUrl::fromStringList(dirs
), splitView
);
261 void DolphinMainWindow::openFiles(const QList
<QUrl
>& files
, bool splitView
)
263 m_tabWidget
->openFiles(files
, splitView
);
266 bool DolphinMainWindow::isFoldersPanelEnabled() const
268 return actionCollection()->action(QStringLiteral("show_folders_panel"))->isChecked();
271 bool DolphinMainWindow::isInformationPanelEnabled() const
274 return actionCollection()->action(QStringLiteral("show_information_panel"))->isChecked();
280 void DolphinMainWindow::openFiles(const QStringList
& files
, bool splitView
)
282 openFiles(QUrl::fromStringList(files
), splitView
);
285 void DolphinMainWindow::activateWindow()
287 window()->setAttribute(Qt::WA_NativeWindow
, true);
288 KStartupInfo::setNewStartupId(window()->windowHandle(), KStartupInfo::startupId());
289 KWindowSystem::activateWindow(window()->effectiveWinId());
292 bool DolphinMainWindow::isActiveWindow()
294 return window()->isActiveWindow();
297 void DolphinMainWindow::showCommand(CommandType command
)
299 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
301 case KIO::FileUndoManager::Copy
:
302 statusBar
->setText(i18nc("@info:status", "Successfully copied."));
304 case KIO::FileUndoManager::Move
:
305 statusBar
->setText(i18nc("@info:status", "Successfully moved."));
307 case KIO::FileUndoManager::Link
:
308 statusBar
->setText(i18nc("@info:status", "Successfully linked."));
310 case KIO::FileUndoManager::Trash
:
311 statusBar
->setText(i18nc("@info:status", "Successfully moved to trash."));
313 case KIO::FileUndoManager::Rename
:
314 statusBar
->setText(i18nc("@info:status", "Successfully renamed."));
317 case KIO::FileUndoManager::Mkdir
:
318 statusBar
->setText(i18nc("@info:status", "Created folder."));
326 void DolphinMainWindow::pasteIntoFolder()
328 m_activeViewContainer
->view()->pasteIntoFolder();
331 void DolphinMainWindow::changeUrl(const QUrl
&url
)
333 if (!KProtocolManager::supportsListing(url
)) {
334 // The URL navigator only checks for validity, not
335 // if the URL can be listed. An error message is
336 // shown due to DolphinViewContainer::restoreView().
340 m_activeViewContainer
->setUrl(url
);
341 updateFileAndEditActions();
346 Q_EMIT
urlChanged(url
);
349 void DolphinMainWindow::slotTerminalDirectoryChanged(const QUrl
& url
)
351 if (m_tearDownFromPlacesRequested
&& url
== QUrl::fromLocalFile(QDir::homePath())) {
352 m_placesPanel
->proceedWithTearDown();
353 m_tearDownFromPlacesRequested
= false;
356 m_activeViewContainer
->setAutoGrabFocus(false);
358 m_activeViewContainer
->setAutoGrabFocus(true);
361 void DolphinMainWindow::slotEditableStateChanged(bool editable
)
363 KToggleAction
* editableLocationAction
=
364 static_cast<KToggleAction
*>(actionCollection()->action(QStringLiteral("editable_location")));
365 editableLocationAction
->setChecked(editable
);
368 void DolphinMainWindow::slotSelectionChanged(const KFileItemList
& selection
)
370 updateFileAndEditActions();
372 const int selectedUrlsCount
= m_tabWidget
->currentTabPage()->selectedItemsCount();
374 QAction
* compareFilesAction
= actionCollection()->action(QStringLiteral("compare_files"));
375 if (selectedUrlsCount
== 2) {
376 compareFilesAction
->setEnabled(isKompareInstalled());
378 compareFilesAction
->setEnabled(false);
381 Q_EMIT
selectionChanged(selection
);
384 void DolphinMainWindow::updateHistory()
386 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
387 const int index
= urlNavigator
->historyIndex();
389 QAction
* backAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Back
));
391 backAction
->setToolTip(i18nc("@info", "Go back"));
392 backAction
->setWhatsThis(i18nc("@info:whatsthis go back", "Return to the previously viewed folder."));
393 backAction
->setEnabled(index
< urlNavigator
->historySize() - 1);
396 QAction
* forwardAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Forward
));
398 forwardAction
->setToolTip(i18nc("@info", "Go forward"));
399 forwardAction
->setWhatsThis(xi18nc("@info:whatsthis go forward",
400 "This undoes a <interface>Go|Back</interface> action."));
401 forwardAction
->setEnabled(index
> 0);
405 void DolphinMainWindow::updateFilterBarAction(bool show
)
407 QAction
* toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
408 toggleFilterBarAction
->setChecked(show
);
411 void DolphinMainWindow::openNewMainWindow()
413 Dolphin::openNewWindow({m_activeViewContainer
->url()}, this);
416 void DolphinMainWindow::openNewActivatedTab()
418 // keep browsers compatibility, new tab is always after last one
419 auto openNewTabAfterLastTabConfigured
= GeneralSettings::openNewTabAfterLastTab();
420 GeneralSettings::setOpenNewTabAfterLastTab(true);
421 m_tabWidget
->openNewActivatedTab();
422 GeneralSettings::setOpenNewTabAfterLastTab(openNewTabAfterLastTabConfigured
);
425 void DolphinMainWindow::addToPlaces()
430 // If nothing is selected, act on the current dir
431 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
432 url
= m_activeViewContainer
->url();
433 name
= m_activeViewContainer
->placesText();
435 const auto dirToAdd
= m_activeViewContainer
->view()->selectedItems().first();
436 url
= dirToAdd
.url();
437 name
= dirToAdd
.name();
441 if (m_activeViewContainer
->isSearchModeEnabled()) {
442 icon
= QStringLiteral("folder-saved-search-symbolic");
444 icon
= KIO::iconNameForUrl(url
);
446 DolphinPlacesModelSingleton::instance().placesModel()->addPlace(name
, url
, icon
);
450 void DolphinMainWindow::openNewTab(const QUrl
& url
)
452 m_tabWidget
->openNewTab(url
, QUrl());
455 void DolphinMainWindow::openNewTabAndActivate(const QUrl
&url
)
457 m_tabWidget
->openNewActivatedTab(url
, QUrl());
460 void DolphinMainWindow::openNewWindow(const QUrl
&url
)
462 Dolphin::openNewWindow({url
}, this);
465 void DolphinMainWindow::slotSplitViewChanged()
467 m_tabWidget
->currentTabPage()->setSplitViewEnabled(GeneralSettings::splitView(), WithAnimation
);
471 void DolphinMainWindow::openInNewTab()
473 const KFileItemList
& list
= m_activeViewContainer
->view()->selectedItems();
474 bool tabCreated
= false;
476 for (const KFileItem
& item
: list
) {
477 const QUrl
& url
= DolphinView::openItemAsFolderUrl(item
);
478 if (!url
.isEmpty()) {
484 // if no new tab has been created from the selection
485 // open the current directory in a new tab
487 openNewTab(m_activeViewContainer
->url());
491 void DolphinMainWindow::openInNewWindow()
495 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
496 if (list
.isEmpty()) {
497 newWindowUrl
= m_activeViewContainer
->url();
498 } else if (list
.count() == 1) {
499 const KFileItem
& item
= list
.first();
500 newWindowUrl
= DolphinView::openItemAsFolderUrl(item
);
503 if (!newWindowUrl
.isEmpty()) {
504 Dolphin::openNewWindow({newWindowUrl
}, this);
508 void DolphinMainWindow::showTarget()
510 const auto link
= m_activeViewContainer
->view()->selectedItems().at(0);
511 const auto linkLocationDir
= QFileInfo(link
.localPath()).absoluteDir();
512 auto linkDestination
= link
.linkDest();
513 if (QFileInfo(linkDestination
).isRelative()) {
514 linkDestination
= linkLocationDir
.filePath(linkDestination
);
516 if (QFileInfo::exists(linkDestination
)) {
517 KIO::highlightInFileManager({QUrl::fromLocalFile(linkDestination
).adjusted(QUrl::StripTrailingSlash
)});
519 m_activeViewContainer
->showMessage(xi18nc("@info", "Could not access <filename>%1</filename>.", linkDestination
),
520 DolphinViewContainer::Warning
);
524 void DolphinMainWindow::showEvent(QShowEvent
* event
)
526 KXmlGuiWindow::showEvent(event
);
528 if (!event
->spontaneous()) {
529 m_activeViewContainer
->view()->setFocus();
533 void DolphinMainWindow::closeEvent(QCloseEvent
* event
)
535 // Find out if Dolphin is closed directly by the user or
536 // by the session manager because the session is closed
537 bool closedByUser
= true;
538 if (qApp
->isSavingSession()) {
539 closedByUser
= false;
542 if (m_tabWidget
->count() > 1
543 && GeneralSettings::confirmClosingMultipleTabs()
544 && !GeneralSettings::rememberOpenedTabs()
546 // Ask the user if he really wants to quit and close all tabs.
547 // Open a confirmation dialog with 3 buttons:
548 // QDialogButtonBox::Yes -> Quit
549 // QDialogButtonBox::No -> Close only the current tab
550 // QDialogButtonBox::Cancel -> do nothing
551 QDialog
*dialog
= new QDialog(this, Qt::Dialog
);
552 dialog
->setWindowTitle(i18nc("@title:window", "Confirmation"));
553 dialog
->setModal(true);
554 QDialogButtonBox
* buttons
= new QDialogButtonBox(QDialogButtonBox::Yes
| QDialogButtonBox::No
| QDialogButtonBox::Cancel
);
555 KGuiItem::assign(buttons
->button(QDialogButtonBox::Yes
), KGuiItem(i18nc("@action:button 'Quit Dolphin' button", "&Quit %1", QGuiApplication::applicationDisplayName()), QIcon::fromTheme(QStringLiteral("application-exit"))));
556 KGuiItem::assign(buttons
->button(QDialogButtonBox::No
), KGuiItem(i18n("C&lose Current Tab"), QIcon::fromTheme(QStringLiteral("tab-close"))));
557 KGuiItem::assign(buttons
->button(QDialogButtonBox::Cancel
), KStandardGuiItem::cancel());
558 buttons
->button(QDialogButtonBox::Yes
)->setDefault(true);
560 bool doNotAskAgainCheckboxResult
= false;
562 const auto result
= KMessageBox::createKMessageBox(dialog
,
564 QMessageBox::Warning
,
565 i18n("You have multiple tabs open in this window, are you sure you want to quit?"),
567 i18n("Do not ask again"),
568 &doNotAskAgainCheckboxResult
,
569 KMessageBox::Notify
);
571 if (doNotAskAgainCheckboxResult
) {
572 GeneralSettings::setConfirmClosingMultipleTabs(false);
576 case QDialogButtonBox::Yes
:
579 case QDialogButtonBox::No
:
580 // Close only the current tab
581 m_tabWidget
->closeTab();
589 if (m_terminalPanel
&& m_terminalPanel
->hasProgramRunning() && GeneralSettings::confirmClosingTerminalRunningProgram() && closedByUser
) {
590 // Ask if the user really wants to quit Dolphin with a program that is still running in the Terminal panel
591 // Open a confirmation dialog with 3 buttons:
592 // QDialogButtonBox::Yes -> Quit
593 // QDialogButtonBox::No -> Show Terminal Panel
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 auto standardButtons
= QDialogButtonBox::Yes
| QDialogButtonBox::Cancel
;
599 if (!m_terminalPanel
->isVisible()) {
600 standardButtons
|= QDialogButtonBox::No
;
602 QDialogButtonBox
*buttons
= new QDialogButtonBox(standardButtons
);
603 KGuiItem::assign(buttons
->button(QDialogButtonBox::Yes
), KStandardGuiItem::quit());
604 if (!m_terminalPanel
->isVisible()) {
606 buttons
->button(QDialogButtonBox::No
),
607 KGuiItem(i18n("Show &Terminal Panel"), QIcon::fromTheme(QStringLiteral("dialog-scripts"))));
609 KGuiItem::assign(buttons
->button(QDialogButtonBox::Cancel
), KStandardGuiItem::cancel());
611 bool doNotAskAgainCheckboxResult
= false;
613 const auto result
= KMessageBox::createKMessageBox(
616 QMessageBox::Warning
,
617 i18n("The program '%1' is still running in the Terminal panel. Are you sure you want to quit?", m_terminalPanel
->runningProgramName()),
619 i18n("Do not ask again"),
620 &doNotAskAgainCheckboxResult
,
621 KMessageBox::Dangerous
);
623 if (doNotAskAgainCheckboxResult
) {
624 GeneralSettings::setConfirmClosingTerminalRunningProgram(false);
628 case QDialogButtonBox::Yes
:
631 case QDialogButtonBox::No
:
632 actionCollection()->action("show_terminal_panel")->trigger();
633 // Do not quit, ignore quit event
641 if (GeneralSettings::rememberOpenedTabs()) {
642 KConfigGui::setSessionConfig(QStringLiteral("dolphin"), QStringLiteral("dolphin"));
643 KConfig
*config
= KConfigGui::sessionConfig();
644 saveGlobalProperties(config
);
645 savePropertiesInternal(config
, 1);
649 GeneralSettings::setVersion(CurrentDolphinVersion
);
650 GeneralSettings::self()->save();
652 KXmlGuiWindow::closeEvent(event
);
655 void DolphinMainWindow::saveProperties(KConfigGroup
& group
)
657 m_tabWidget
->saveProperties(group
);
660 void DolphinMainWindow::readProperties(const KConfigGroup
& group
)
662 m_tabWidget
->readProperties(group
);
665 void DolphinMainWindow::updateNewMenu()
667 m_newFileMenu
->checkUpToDate();
668 #if KIO_VERSION >= QT_VERSION_CHECK(5, 97, 0)
669 m_newFileMenu
->setWorkingDirectory(activeViewContainer()->url());
671 m_newFileMenu
->setPopupFiles(QList
<QUrl
>() << activeViewContainer()->url());
675 void DolphinMainWindow::createDirectory()
677 #if KIO_VERSION >= QT_VERSION_CHECK(5, 97, 0)
678 m_newFileMenu
->setWorkingDirectory(activeViewContainer()->url());
680 m_newFileMenu
->setPopupFiles(QList
<QUrl
>() << activeViewContainer()->url());
682 m_newFileMenu
->createDirectory();
685 void DolphinMainWindow::quit()
690 void DolphinMainWindow::showErrorMessage(const QString
& message
)
692 m_activeViewContainer
->showMessage(message
, DolphinViewContainer::Error
);
695 void DolphinMainWindow::slotUndoAvailable(bool available
)
697 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
699 undoAction
->setEnabled(available
);
703 void DolphinMainWindow::slotUndoTextChanged(const QString
& text
)
705 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
707 undoAction
->setText(text
);
711 void DolphinMainWindow::undo()
714 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
715 KIO::FileUndoManager::self()->undo();
718 void DolphinMainWindow::cut()
720 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
721 m_activeViewContainer
->setSelectionModeEnabled(true, actionCollection(), SelectionModeBottomBar::Contents::CutContents
);
723 m_activeViewContainer
->view()->cutSelectedItemsToClipboard();
724 m_activeViewContainer
->setSelectionModeEnabled(false);
728 void DolphinMainWindow::copy()
730 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
731 m_activeViewContainer
->setSelectionModeEnabled(true, actionCollection(), SelectionModeBottomBar::Contents::CopyContents
);
733 m_activeViewContainer
->view()->copySelectedItemsToClipboard();
734 m_activeViewContainer
->setSelectionModeEnabled(false);
738 void DolphinMainWindow::paste()
740 m_activeViewContainer
->view()->paste();
743 void DolphinMainWindow::find()
745 m_activeViewContainer
->setSearchModeEnabled(true);
748 void DolphinMainWindow::updateSearchAction()
750 QAction
* toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
751 toggleSearchAction
->setChecked(m_activeViewContainer
->isSearchModeEnabled());
754 void DolphinMainWindow::updatePasteAction()
756 QAction
* pasteAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Paste
));
757 QPair
<bool, QString
> pasteInfo
= m_activeViewContainer
->view()->pasteInfo();
758 pasteAction
->setEnabled(pasteInfo
.first
);
759 pasteAction
->setText(pasteInfo
.second
);
762 void DolphinMainWindow::slotDirectoryLoadingCompleted()
767 void DolphinMainWindow::slotToolBarActionMiddleClicked(QAction
*action
)
769 if (action
== actionCollection()->action(KStandardAction::name(KStandardAction::Back
))) {
771 } else if (action
== actionCollection()->action(KStandardAction::name(KStandardAction::Forward
))) {
773 } else if (action
== actionCollection()->action(QStringLiteral("go_up"))) {
775 } else if (action
== actionCollection()->action(QStringLiteral("go_home"))) {
780 QAction
*DolphinMainWindow::urlNavigatorHistoryAction(const KUrlNavigator
*urlNavigator
, int historyIndex
, QObject
*parent
)
782 const QUrl url
= urlNavigator
->locationUrl(historyIndex
);
784 QString text
= url
.toDisplayString(QUrl::PreferLocalFile
);
786 if (!urlNavigator
->showFullPath()) {
787 const KFilePlacesModel
*placesModel
= DolphinPlacesModelSingleton::instance().placesModel();
789 const QModelIndex closestIdx
= placesModel
->closestItem(url
);
790 if (closestIdx
.isValid()) {
791 const QUrl placeUrl
= placesModel
->url(closestIdx
);
793 text
= placesModel
->text(closestIdx
);
795 QString pathInsidePlace
= url
.path().mid(placeUrl
.path().length());
797 if (!pathInsidePlace
.isEmpty() && !pathInsidePlace
.startsWith(QLatin1Char('/'))) {
798 pathInsidePlace
.prepend(QLatin1Char('/'));
801 if (pathInsidePlace
!= QLatin1Char('/')) {
802 text
.append(pathInsidePlace
);
807 QAction
*action
= new QAction(QIcon::fromTheme(KIO::iconNameForUrl(url
)), text
, parent
);
808 action
->setData(historyIndex
);
812 void DolphinMainWindow::slotAboutToShowBackPopupMenu()
814 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
816 m_backAction
->menu()->clear();
817 for (int i
= urlNavigator
->historyIndex() + 1; i
< urlNavigator
->historySize() && entries
< MaxNumberOfNavigationentries
; ++i
, ++entries
) {
818 QAction
*action
= urlNavigatorHistoryAction(urlNavigator
, i
, m_backAction
->menu());
820 m_backAction
->menu()->addAction(action
);
824 void DolphinMainWindow::slotGoBack(QAction
* action
)
826 int gotoIndex
= action
->data().value
<int>();
827 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
828 for (int i
= gotoIndex
- urlNavigator
->historyIndex(); i
> 0; --i
) {
833 void DolphinMainWindow::slotBackForwardActionMiddleClicked(QAction
* action
)
836 const KUrlNavigator
*urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
837 openNewTab(urlNavigator
->locationUrl(action
->data().value
<int>()));
841 void DolphinMainWindow::slotAboutToShowForwardPopupMenu()
843 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
845 m_forwardAction
->menu()->clear();
846 for (int i
= urlNavigator
->historyIndex() - 1; i
>= 0 && entries
< MaxNumberOfNavigationentries
; --i
, ++entries
) {
847 QAction
*action
= urlNavigatorHistoryAction(urlNavigator
, i
, m_forwardAction
->menu());
849 m_forwardAction
->menu()->addAction(action
);
853 void DolphinMainWindow::slotGoForward(QAction
* action
)
855 int gotoIndex
= action
->data().value
<int>();
856 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
857 for (int i
= urlNavigator
->historyIndex() - gotoIndex
; i
> 0; --i
) {
862 void DolphinMainWindow::slotSetSelectionMode(bool enabled
, SelectionModeBottomBar::Contents bottomBarContents
)
864 m_activeViewContainer
->setSelectionModeEnabled(enabled
, actionCollection(), bottomBarContents
);
867 void DolphinMainWindow::selectAll()
871 // if the URL navigator is editable and focused, select the whole
872 // URL instead of all items of the view
874 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
875 QLineEdit
* lineEdit
= urlNavigator
->editor()->lineEdit();
876 const bool selectUrl
= urlNavigator
->isUrlEditable() &&
877 lineEdit
->hasFocus();
879 lineEdit
->selectAll();
881 m_activeViewContainer
->view()->selectAll();
885 void DolphinMainWindow::invertSelection()
888 m_activeViewContainer
->view()->invertSelection();
891 void DolphinMainWindow::toggleSplitView()
893 DolphinTabPage
* tabPage
= m_tabWidget
->currentTabPage();
894 tabPage
->setSplitViewEnabled(!tabPage
->splitViewEnabled(), WithAnimation
);
899 void DolphinMainWindow::toggleSplitStash()
901 DolphinTabPage
* tabPage
= m_tabWidget
->currentTabPage();
902 tabPage
->setSplitViewEnabled(false, WithAnimation
);
903 tabPage
->setSplitViewEnabled(true, WithAnimation
, QUrl("stash:/"));
906 void DolphinMainWindow::copyToInactiveSplitView()
908 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
909 m_activeViewContainer
->setSelectionModeEnabled(true, actionCollection(), SelectionModeBottomBar::Contents::CopyToOtherViewContents
);
911 m_tabWidget
->copyToInactiveSplitView();
912 m_activeViewContainer
->setSelectionModeEnabled(false);
916 void DolphinMainWindow::moveToInactiveSplitView()
918 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
919 m_activeViewContainer
->setSelectionModeEnabled(true, actionCollection(), SelectionModeBottomBar::Contents::MoveToOtherViewContents
);
921 m_tabWidget
->moveToInactiveSplitView();
922 m_activeViewContainer
->setSelectionModeEnabled(false);
926 void DolphinMainWindow::reloadView()
929 m_activeViewContainer
->reload();
930 m_activeViewContainer
->statusBar()->updateSpaceInfo();
933 void DolphinMainWindow::stopLoading()
935 m_activeViewContainer
->view()->stopLoading();
938 void DolphinMainWindow::enableStopAction()
940 actionCollection()->action(QStringLiteral("stop"))->setEnabled(true);
943 void DolphinMainWindow::disableStopAction()
945 actionCollection()->action(QStringLiteral("stop"))->setEnabled(false);
948 void DolphinMainWindow::toggleSelectionMode()
950 const bool checked
= !m_activeViewContainer
->isSelectionModeEnabled();
952 m_activeViewContainer
->setSelectionModeEnabled(checked
, actionCollection(), SelectionModeBottomBar::Contents::GeneralContents
);
953 actionCollection()->action(QStringLiteral("toggle_selection_mode"))->setChecked(checked
);
956 void DolphinMainWindow::showFilterBar()
958 m_activeViewContainer
->setFilterBarVisible(true);
961 void DolphinMainWindow::toggleFilterBar()
963 const bool checked
= !m_activeViewContainer
->isFilterBarVisible();
964 m_activeViewContainer
->setFilterBarVisible(checked
);
966 QAction
* toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
967 toggleFilterBarAction
->setChecked(checked
);
970 void DolphinMainWindow::toggleEditLocation()
974 QAction
* action
= actionCollection()->action(QStringLiteral("editable_location"));
975 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
976 urlNavigator
->setUrlEditable(action
->isChecked());
979 void DolphinMainWindow::replaceLocation()
981 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
982 QLineEdit
* lineEdit
= navigator
->editor()->lineEdit();
984 // If the text field currently has focus and everything is selected,
985 // pressing the keyboard shortcut returns the whole thing to breadcrumb mode
986 if (navigator
->isUrlEditable()
987 && lineEdit
->hasFocus()
988 && lineEdit
->selectedText() == lineEdit
->text() ) {
989 navigator
->setUrlEditable(false);
991 navigator
->setUrlEditable(true);
992 navigator
->setFocus();
993 lineEdit
->selectAll();
997 void DolphinMainWindow::togglePanelLockState()
999 const bool newLockState
= !GeneralSettings::lockPanels();
1000 const auto childrenObjects
= children();
1001 for (QObject
* child
: childrenObjects
) {
1002 DolphinDockWidget
* dock
= qobject_cast
<DolphinDockWidget
*>(child
);
1004 dock
->setLocked(newLockState
);
1008 DolphinPlacesModelSingleton::instance().placesModel()->setPanelsLocked(newLockState
);
1010 GeneralSettings::setLockPanels(newLockState
);
1013 void DolphinMainWindow::slotTerminalPanelVisibilityChanged()
1015 if (m_terminalPanel
->isHiddenInVisibleWindow() && m_activeViewContainer
) {
1016 m_activeViewContainer
->view()->setFocus();
1020 void DolphinMainWindow::goBack()
1022 DolphinUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
1023 urlNavigator
->goBack();
1025 if (urlNavigator
->locationState().isEmpty()) {
1026 // An empty location state indicates a redirection URL,
1027 // which must be skipped too
1028 urlNavigator
->goBack();
1032 void DolphinMainWindow::goForward()
1034 m_activeViewContainer
->urlNavigatorInternalWithHistory()->goForward();
1037 void DolphinMainWindow::goUp()
1039 m_activeViewContainer
->urlNavigatorInternalWithHistory()->goUp();
1042 void DolphinMainWindow::goHome()
1044 m_activeViewContainer
->urlNavigatorInternalWithHistory()->goHome();
1047 void DolphinMainWindow::goBackInNewTab()
1049 const KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
1050 const int index
= urlNavigator
->historyIndex() + 1;
1051 openNewTab(urlNavigator
->locationUrl(index
));
1054 void DolphinMainWindow::goForwardInNewTab()
1056 const KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
1057 const int index
= urlNavigator
->historyIndex() - 1;
1058 openNewTab(urlNavigator
->locationUrl(index
));
1061 void DolphinMainWindow::goUpInNewTab()
1063 const QUrl currentUrl
= activeViewContainer()->urlNavigator()->locationUrl();
1064 openNewTab(KIO::upUrl(currentUrl
));
1067 void DolphinMainWindow::goHomeInNewTab()
1069 openNewTab(Dolphin::homeUrl());
1072 void DolphinMainWindow::compareFiles()
1074 const KFileItemList items
= m_tabWidget
->currentTabPage()->selectedItems();
1075 if (items
.count() != 2) {
1076 // The action is disabled in this case, but it could have been triggered
1077 // via D-Bus, see https://bugs.kde.org/show_bug.cgi?id=325517
1081 QUrl urlA
= items
.at(0).url();
1082 QUrl urlB
= items
.at(1).url();
1084 QString
command(QStringLiteral("kompare -c \""));
1085 command
.append(urlA
.toDisplayString(QUrl::PreferLocalFile
));
1086 command
.append("\" \"");
1087 command
.append(urlB
.toDisplayString(QUrl::PreferLocalFile
));
1088 command
.append('\"');
1090 KIO::CommandLauncherJob
*job
= new KIO::CommandLauncherJob(command
, this);
1091 job
->setDesktopName(QStringLiteral("org.kde.kompare"));
1095 void DolphinMainWindow::toggleShowMenuBar()
1097 const bool visible
= menuBar()->isVisible();
1098 menuBar()->setVisible(!visible
);
1101 QPointer
<QAction
> DolphinMainWindow::preferredSearchTool()
1103 m_searchTools
.clear();
1104 KMoreToolsMenuFactory("dolphin/search-tools").fillMenuFromGroupingNames(
1105 &m_searchTools
, { "files-find" }, m_activeViewContainer
->url()
1107 QList
<QAction
*> actions
= m_searchTools
.actions();
1108 if (actions
.isEmpty()) {
1111 QAction
* action
= actions
.first();
1112 if (action
->isSeparator()) {
1118 void DolphinMainWindow::updateOpenPreferredSearchToolAction()
1120 QAction
* openPreferredSearchTool
= actionCollection()->action(QStringLiteral("open_preferred_search_tool"));
1121 if (!openPreferredSearchTool
) {
1124 QPointer
<QAction
> tool
= preferredSearchTool();
1126 openPreferredSearchTool
->setVisible(true);
1127 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open %1", tool
->text()));
1128 // Only override with the app icon if it is the default, i.e. the user hasn't configured one manually
1129 // https://bugs.kde.org/show_bug.cgi?id=442815
1130 if (openPreferredSearchTool
->icon().name() == QLatin1String("search")) {
1131 openPreferredSearchTool
->setIcon(tool
->icon());
1134 openPreferredSearchTool
->setVisible(false);
1135 // still visible in Shortcuts configuration window
1136 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool"));
1137 openPreferredSearchTool
->setIcon(QIcon::fromTheme(QStringLiteral("search")));
1141 void DolphinMainWindow::openPreferredSearchTool()
1143 QPointer
<QAction
> tool
= preferredSearchTool();
1149 void DolphinMainWindow::openTerminal()
1151 openTerminalJob(m_activeViewContainer
->url());
1154 void DolphinMainWindow::openTerminalHere()
1156 QList
<QUrl
> urls
= {};
1158 for (const KFileItem
& item
: m_activeViewContainer
->view()->selectedItems()) {
1159 QUrl url
= item
.targetUrl();
1160 if (item
.isFile()) {
1161 url
.setPath(QFileInfo(url
.path()).absolutePath());
1163 if (!urls
.contains(url
)) {
1168 // No items are selected. Open a terminal window for the current location.
1169 if (urls
.count() == 0) {
1174 if (urls
.count() > 5) {
1175 QString question
= i18np("Are you sure you want to open 1 terminal window?",
1176 "Are you sure you want to open %1 terminal windows?", urls
.count());
1177 const int answer
= KMessageBox::warningYesNo(this, question
, {},
1178 KGuiItem(i18ncp("@action:button", "Open %1 Terminal", "Open %1 Terminals", urls
.count()),
1179 QStringLiteral("utilities-terminal")),
1180 KStandardGuiItem::cancel());
1181 if (answer
!= KMessageBox::Yes
) {
1186 for (const QUrl
& url
: urls
) {
1187 openTerminalJob(url
);
1191 void DolphinMainWindow::openTerminalJob(const QUrl
& url
)
1193 if (url
.isLocalFile()) {
1194 auto job
= new KTerminalLauncherJob(QString());
1195 job
->setWorkingDirectory(url
.toLocalFile());
1200 // Not a local file, with protocol Class ":local", try stat'ing
1201 if (KProtocolInfo::protocolClass(url
.scheme()) == QLatin1String(":local")) {
1202 KIO::StatJob
*job
= KIO::mostLocalUrl(url
);
1203 KJobWidgets::setWindow(job
, this);
1204 connect(job
, &KJob::result
, this, [job
]() {
1206 if (!job
->error()) {
1207 statUrl
= job
->mostLocalUrl();
1210 auto job
= new KTerminalLauncherJob(QString());
1211 job
->setWorkingDirectory(statUrl
.isLocalFile() ? statUrl
.toLocalFile() : QDir::homePath());
1218 // Nothing worked, just use $HOME
1219 auto job
= new KTerminalLauncherJob(QString());
1220 job
->setWorkingDirectory(QDir::homePath());
1224 void DolphinMainWindow::editSettings()
1226 if (!m_settingsDialog
) {
1227 DolphinViewContainer
* container
= activeViewContainer();
1228 container
->view()->writeSettings();
1230 const QUrl url
= container
->url();
1231 DolphinSettingsDialog
* settingsDialog
= new DolphinSettingsDialog(url
, this, actionCollection());
1232 connect(settingsDialog
, &DolphinSettingsDialog::settingsChanged
, this, &DolphinMainWindow::refreshViews
);
1233 connect(settingsDialog
, &DolphinSettingsDialog::settingsChanged
,
1234 &DolphinUrlNavigatorsController::slotReadSettings
);
1235 settingsDialog
->setAttribute(Qt::WA_DeleteOnClose
);
1236 settingsDialog
->show();
1237 m_settingsDialog
= settingsDialog
;
1239 m_settingsDialog
.data()->raise();
1243 void DolphinMainWindow::handleUrl(const QUrl
& url
)
1245 delete m_lastHandleUrlOpenJob
;
1246 m_lastHandleUrlOpenJob
= nullptr;
1248 if (url
.isLocalFile() && QFileInfo(url
.toLocalFile()).isDir()) {
1249 activeViewContainer()->setUrl(url
);
1251 m_lastHandleUrlOpenJob
= new KIO::OpenUrlJob(url
);
1252 m_lastHandleUrlOpenJob
->setUiDelegate(new KIO::JobUiDelegate(KJobUiDelegate::AutoHandlingEnabled
, this));
1253 m_lastHandleUrlOpenJob
->setShowOpenOrExecuteDialog(true);
1255 connect(m_lastHandleUrlOpenJob
, &KIO::OpenUrlJob::mimeTypeFound
, this,
1256 [this, url
](const QString
&mimetype
) {
1257 if (mimetype
== QLatin1String("inode/directory")) {
1258 // If it's a dir, we'll take it from here
1259 m_lastHandleUrlOpenJob
->kill();
1260 m_lastHandleUrlOpenJob
= nullptr;
1261 activeViewContainer()->setUrl(url
);
1265 connect(m_lastHandleUrlOpenJob
, &KIO::OpenUrlJob::result
, this, [this]() {
1266 m_lastHandleUrlOpenJob
= nullptr;
1269 m_lastHandleUrlOpenJob
->start();
1273 void DolphinMainWindow::slotWriteStateChanged(bool isFolderWritable
)
1275 // trash:/ is writable but we don't want to create new items in it.
1276 // TODO: remove the trash check once https://phabricator.kde.org/T8234 is implemented
1277 newFileMenu()->setEnabled(isFolderWritable
&& m_activeViewContainer
->url().scheme() != QLatin1String("trash"));
1280 void DolphinMainWindow::openContextMenu(const QPoint
& pos
,
1281 const KFileItem
& item
,
1282 const KFileItemList
&selectedItems
,
1285 QPointer
<DolphinContextMenu
> contextMenu
= new DolphinContextMenu(this, item
, selectedItems
, url
, &m_fileItemActions
);
1286 contextMenu
.data()->exec(pos
);
1288 // Delete the menu, unless it has been deleted in its own nested event loop already.
1290 contextMenu
->deleteLater();
1294 QMenu
*DolphinMainWindow::createPopupMenu()
1296 QMenu
*menu
= KXmlGuiWindow::createPopupMenu();
1298 menu
->addSeparator();
1299 menu
->addAction(actionCollection()->action(QStringLiteral("lock_panels")));
1304 void DolphinMainWindow::updateHamburgerMenu()
1306 KActionCollection
* ac
= actionCollection();
1307 auto hamburgerMenu
= static_cast<KHamburgerMenu
*>(
1308 ac
->action(KStandardAction::name(KStandardAction::HamburgerMenu
)));
1309 auto menu
= hamburgerMenu
->menu();
1311 menu
= new QMenu(this);
1312 hamburgerMenu
->setMenu(menu
);
1313 hamburgerMenu
->hideActionsOf(ac
->action(QStringLiteral("basic_actions"))->menu());
1314 hamburgerMenu
->hideActionsOf(ac
->action(QStringLiteral("zoom"))->menu());
1318 const QList
<QAction
*> toolbarActions
= toolBar()->actions();
1320 if (!toolBar()->isVisible()) {
1321 // If neither the menu bar nor the toolbar are visible, these actions should be available.
1322 menu
->addAction(ac
->action(KStandardAction::name(KStandardAction::ShowMenubar
)));
1323 menu
->addAction(toolBarMenuAction());
1324 menu
->addSeparator();
1327 // This group of actions (until the next separator) contains all the most basic actions
1328 // necessary to use Dolphin effectively.
1329 menu
->addAction(ac
->action(QStringLiteral("go_back")));
1330 menu
->addAction(ac
->action(QStringLiteral("go_forward")));
1332 menu
->addMenu(m_newFileMenu
->menu());
1333 if (!toolBar()->isVisible()
1334 || !toolbarActions
.contains(ac
->action(QStringLiteral("toggle_selection_mode_with_popup")))
1336 menu
->addAction(ac
->action(QStringLiteral("toggle_selection_mode")));
1338 menu
->addAction(ac
->action(QStringLiteral("basic_actions")));
1339 menu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Undo
)));
1340 if (!toolBar()->isVisible()
1341 || (!toolbarActions
.contains(ac
->action(QStringLiteral("toggle_search")))
1342 && !toolbarActions
.contains(ac
->action(QStringLiteral("open_preferred_search_tool"))))
1344 menu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Find
)));
1345 // This way a search action will only be added if none of the three available
1346 // search actions is present on the toolbar.
1348 if (!toolBar()->isVisible()
1349 || !toolbarActions
.contains(ac
->action(QStringLiteral("toggle_filter")))
1351 menu
->addAction(ac
->action(QStringLiteral("show_filter_bar")));
1352 // This way a filter action will only be added if none of the two available
1353 // filter actions is present on the toolbar.
1355 menu
->addSeparator();
1357 // The second group of actions (up until the next separator) contains actions for opening
1358 // additional views to interact with the file system.
1359 menu
->addAction(ac
->action(QStringLiteral("file_new")));
1360 menu
->addAction(ac
->action(QStringLiteral("new_tab")));
1361 if (ac
->action(QStringLiteral("undo_close_tab"))->isEnabled()) {
1362 menu
->addAction(ac
->action(QStringLiteral("closed_tabs")));
1364 menu
->addAction(ac
->action(QStringLiteral("open_terminal")));
1365 menu
->addSeparator();
1367 // The third group contains actions to change what one sees in the view
1368 // and to change the more general UI.
1369 if (!toolBar()->isVisible()
1370 || (!toolbarActions
.contains(ac
->action(QStringLiteral("icons")))
1371 && !toolbarActions
.contains(ac
->action(QStringLiteral("compact")))
1372 && !toolbarActions
.contains(ac
->action(QStringLiteral("details")))
1373 && !toolbarActions
.contains(ac
->action(QStringLiteral("view_mode"))))
1375 menu
->addAction(ac
->action(QStringLiteral("view_mode")));
1377 menu
->addAction(ac
->action(QStringLiteral("show_hidden_files")));
1378 menu
->addAction(ac
->action(QStringLiteral("sort")));
1379 menu
->addAction(ac
->action(QStringLiteral("additional_info")));
1380 if (!GeneralSettings::showStatusBar() || !GeneralSettings::showZoomSlider()) {
1381 menu
->addAction(ac
->action(QStringLiteral("zoom")));
1383 menu
->addAction(ac
->action(QStringLiteral("panels")));
1385 // The "Configure" menu is not added to the actionCollection() because there is hardly
1386 // a good reason for users to put it on their toolbar.
1387 auto configureMenu
= menu
->addMenu(QIcon::fromTheme(QStringLiteral("configure")),
1388 i18nc("@action:inmenu menu for configure actions", "Configure"));
1389 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::SwitchApplicationLanguage
)));
1390 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::KeyBindings
)));
1391 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::ConfigureToolbars
)));
1392 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Preferences
)));
1393 hamburgerMenu
->hideActionsOf(configureMenu
);
1396 void DolphinMainWindow::slotPlaceActivated(const QUrl
& url
)
1398 DolphinViewContainer
* view
= activeViewContainer();
1400 if (view
->url() == url
) {
1401 // We can end up here if the user clicked a device in the Places Panel
1402 // which had been unmounted earlier, see https://bugs.kde.org/show_bug.cgi?id=161385.
1405 view
->disableUrlNavigatorSelectionRequests();
1407 view
->enableUrlNavigatorSelectionRequests();
1411 void DolphinMainWindow::closedTabsCountChanged(unsigned int count
)
1413 actionCollection()->action(QStringLiteral("undo_close_tab"))->setEnabled(count
> 0);
1416 void DolphinMainWindow::activeViewChanged(DolphinViewContainer
* viewContainer
)
1418 DolphinViewContainer
* oldViewContainer
= m_activeViewContainer
;
1419 Q_ASSERT(viewContainer
);
1421 m_activeViewContainer
= viewContainer
;
1423 if (oldViewContainer
) {
1424 const QAction
* toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
1425 toggleSearchAction
->disconnect(oldViewContainer
);
1427 // Disconnect all signals between the old view container (container,
1428 // view and url navigator) and main window.
1429 oldViewContainer
->disconnect(this);
1430 oldViewContainer
->view()->disconnect(this);
1431 oldViewContainer
->urlNavigatorInternalWithHistory()->disconnect(this);
1432 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>
1433 (actionCollection()->action(QStringLiteral("url_navigators")));
1434 navigators
->primaryUrlNavigator()->disconnect(this);
1435 if (auto secondaryUrlNavigator
= navigators
->secondaryUrlNavigator()) {
1436 secondaryUrlNavigator
->disconnect(this);
1439 // except the requestItemInfo so that on hover the information panel can still be updated
1440 connect(oldViewContainer
->view(), &DolphinView::requestItemInfo
,
1441 this, &DolphinMainWindow::requestItemInfo
);
1444 connectViewSignals(viewContainer
);
1446 m_actionHandler
->setCurrentView(viewContainer
->view());
1449 updateFileAndEditActions();
1450 updatePasteAction();
1451 updateViewActions();
1453 updateSearchAction();
1455 const QUrl url
= viewContainer
->url();
1456 Q_EMIT
urlChanged(url
);
1459 void DolphinMainWindow::tabCountChanged(int count
)
1461 const bool enableTabActions
= (count
> 1);
1462 for (int i
= 0; i
< MaxActivateTabShortcuts
; ++i
) {
1463 actionCollection()->action(QStringLiteral("activate_tab_%1").arg(i
))->setEnabled(enableTabActions
);
1465 actionCollection()->action(QStringLiteral("activate_last_tab"))->setEnabled(enableTabActions
);
1466 actionCollection()->action(QStringLiteral("activate_next_tab"))->setEnabled(enableTabActions
);
1467 actionCollection()->action(QStringLiteral("activate_prev_tab"))->setEnabled(enableTabActions
);
1470 void DolphinMainWindow::updateWindowTitle()
1472 const QString newTitle
= m_activeViewContainer
->captionWindowTitle();
1473 if (windowTitle() != newTitle
) {
1474 setWindowTitle(newTitle
);
1478 void DolphinMainWindow::slotStorageTearDownFromPlacesRequested(const QString
& mountPath
)
1480 connect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, this, [this, mountPath
]() {
1481 setViewsToHomeIfMountPathOpen(mountPath
);
1484 if (m_terminalPanel
&& m_terminalPanel
->currentWorkingDirectory().startsWith(mountPath
)) {
1485 m_tearDownFromPlacesRequested
= true;
1486 m_terminalPanel
->goHome();
1487 // m_placesPanel->proceedWithTearDown() will be called in slotTerminalDirectoryChanged
1489 m_placesPanel
->proceedWithTearDown();
1493 void DolphinMainWindow::slotStorageTearDownExternallyRequested(const QString
& mountPath
)
1495 connect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, this, [this, mountPath
]() {
1496 setViewsToHomeIfMountPathOpen(mountPath
);
1499 if (m_terminalPanel
&& m_terminalPanel
->currentWorkingDirectory().startsWith(mountPath
)) {
1500 m_tearDownFromPlacesRequested
= false;
1501 m_terminalPanel
->goHome();
1505 void DolphinMainWindow::slotKeyBindings()
1507 KShortcutsDialog
dialog(KShortcutsEditor::AllActions
, KShortcutsEditor::LetterShortcutsAllowed
, this);
1508 dialog
.addCollection(actionCollection());
1509 if (m_terminalPanel
) {
1510 KActionCollection
*konsolePartActionCollection
= m_terminalPanel
->actionCollection();
1511 if (konsolePartActionCollection
) {
1512 dialog
.addCollection(konsolePartActionCollection
, QStringLiteral("KonsolePart"));
1518 void DolphinMainWindow::setViewsToHomeIfMountPathOpen(const QString
& mountPath
)
1520 const QVector
<DolphinViewContainer
*> theViewContainers
= viewContainers();
1521 for (DolphinViewContainer
*viewContainer
: theViewContainers
) {
1522 if (viewContainer
&& viewContainer
->url().toLocalFile().startsWith(mountPath
)) {
1523 viewContainer
->setUrl(QUrl::fromLocalFile(QDir::homePath()));
1526 disconnect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, nullptr, nullptr);
1529 void DolphinMainWindow::setupActions()
1531 KStandardAction::hamburgerMenu(nullptr, nullptr, actionCollection());
1533 // setup 'File' menu
1534 m_newFileMenu
= new DolphinNewFileMenu(actionCollection(), this);
1535 QMenu
* menu
= m_newFileMenu
->menu();
1536 menu
->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1537 menu
->setIcon(QIcon::fromTheme(QStringLiteral("list-add")));
1538 m_newFileMenu
->setPopupMode(QToolButton::InstantPopup
);
1539 connect(menu
, &QMenu::aboutToShow
,
1540 this, &DolphinMainWindow::updateNewMenu
);
1542 QAction
* newWindow
= KStandardAction::openNew(this, &DolphinMainWindow::openNewMainWindow
, actionCollection());
1543 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
1544 newWindow
->setToolTip(i18nc("@info", "Open a new Dolphin window"));
1545 newWindow
->setWhatsThis(xi18nc("@info:whatsthis", "This opens a new "
1546 "window just like this one with the current location and view."
1547 "<nl/>You can drag and drop items between windows."));
1548 newWindow
->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
1550 QAction
* newTab
= actionCollection()->addAction(QStringLiteral("new_tab"));
1551 newTab
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1552 newTab
->setText(i18nc("@action:inmenu File", "New Tab"));
1553 newTab
->setWhatsThis(xi18nc("@info:whatsthis", "This opens a new "
1554 "<emphasis>Tab</emphasis> with the current location and view.<nl/>"
1555 "A tab is an additional view within this window. "
1556 "You can drag and drop items between tabs."));
1557 actionCollection()->setDefaultShortcuts(newTab
, {Qt::CTRL
| Qt::Key_T
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_N
});
1558 connect(newTab
, &QAction::triggered
, this, &DolphinMainWindow::openNewActivatedTab
);
1560 QAction
* addToPlaces
= actionCollection()->addAction(QStringLiteral("add_to_places"));
1561 addToPlaces
->setIcon(QIcon::fromTheme(QStringLiteral("bookmark-new")));
1562 addToPlaces
->setText(i18nc("@action:inmenu Add current folder to places", "Add to Places"));
1563 addToPlaces
->setWhatsThis(xi18nc("@info:whatsthis", "This adds the selected folder "
1564 "to the Places panel."));
1565 connect(addToPlaces
, &QAction::triggered
, this, &DolphinMainWindow::addToPlaces
);
1567 QAction
* closeTab
= KStandardAction::close(m_tabWidget
, QOverload
<>::of(&DolphinTabWidget::closeTab
), actionCollection());
1568 closeTab
->setText(i18nc("@action:inmenu File", "Close Tab"));
1569 closeTab
->setWhatsThis(i18nc("@info:whatsthis", "This closes the "
1570 "currently viewed tab. If no more tabs are left this window "
1571 "will close instead."));
1573 QAction
* quitAction
= KStandardAction::quit(this, &DolphinMainWindow::quit
, actionCollection());
1574 quitAction
->setWhatsThis(i18nc("@info:whatsthis quit", "This closes this window."));
1576 // setup 'Edit' menu
1577 KStandardAction::undo(this,
1578 &DolphinMainWindow::undo
,
1579 actionCollection());
1581 // i18n: This will be the last paragraph for the whatsthis for all three:
1582 // Cut, Copy and Paste
1583 const QString cutCopyPastePara
= xi18nc("@info:whatsthis", "<para><emphasis>Cut, "
1584 "Copy</emphasis> and <emphasis>Paste</emphasis> work between many "
1585 "applications and are among the most used commands. That's why their "
1586 "<emphasis>keyboard shortcuts</emphasis> are prominently placed right "
1587 "next to each other on the keyboard: <shortcut>Ctrl+X</shortcut>, "
1588 "<shortcut>Ctrl+C</shortcut> and <shortcut>Ctrl+V</shortcut>.</para>");
1589 QAction
* cutAction
= KStandardAction::cut(this, &DolphinMainWindow::cut
, actionCollection());
1590 cutAction
->setWhatsThis(xi18nc("@info:whatsthis cut", "This copies the items "
1591 "in your current selection to the <emphasis>clipboard</emphasis>.<nl/>"
1592 "Use the <emphasis>Paste</emphasis> action afterwards to copy them from "
1593 "the clipboard to a new location. The items will be removed from their "
1594 "initial location.") + cutCopyPastePara
);
1595 QAction
* copyAction
= KStandardAction::copy(this, &DolphinMainWindow::copy
, actionCollection());
1596 copyAction
->setWhatsThis(xi18nc("@info:whatsthis copy", "This copies the "
1597 "items in your current selection to the <emphasis>clipboard</emphasis>."
1598 "<nl/>Use the <emphasis>Paste</emphasis> action afterwards to copy them "
1599 "from the clipboard to a new location.") + cutCopyPastePara
);
1600 QAction
* paste
= KStandardAction::paste(this, &DolphinMainWindow::paste
, actionCollection());
1601 // The text of the paste-action is modified dynamically by Dolphin
1602 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1603 // due to the long text, the text "Paste" is used:
1604 paste
->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1605 paste
->setWhatsThis(xi18nc("@info:whatsthis paste", "This copies the items from "
1606 "your <emphasis>clipboard</emphasis> to the currently viewed folder.<nl/>"
1607 "If the items were added to the clipboard by the <emphasis>Cut</emphasis> "
1608 "action they are removed from their old location.") + cutCopyPastePara
);
1610 QAction
* copyToOtherViewAction
= actionCollection()->addAction(QStringLiteral("copy_to_inactive_split_view"));
1611 copyToOtherViewAction
->setText(i18nc("@action:inmenu", "Copy to Inactive Split View"));
1612 copyToOtherViewAction
->setWhatsThis(xi18nc("@info:whatsthis Copy", "This copies the selected items from "
1613 "the <emphasis>active</emphasis> view to the inactive split view."));
1614 copyToOtherViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("edit-copy")));
1615 copyToOtherViewAction
->setIconText(i18nc("@action:inmenu Edit", "Copy to Inactive Split View"));
1616 actionCollection()->setDefaultShortcut(copyToOtherViewAction
, Qt::SHIFT
| Qt::Key_F5
);
1617 connect(copyToOtherViewAction
, &QAction::triggered
, this, &DolphinMainWindow::copyToInactiveSplitView
);
1619 QAction
* moveToOtherViewAction
= actionCollection()->addAction(QStringLiteral("move_to_inactive_split_view"));
1620 moveToOtherViewAction
->setText(i18nc("@action:inmenu", "Move to Inactive Split View"));
1621 moveToOtherViewAction
->setWhatsThis(xi18nc("@info:whatsthis Move", "This moves the selected items from "
1622 "the <emphasis>active</emphasis> view to the inactive split view."));
1623 moveToOtherViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("edit-cut")));
1624 moveToOtherViewAction
->setIconText(i18nc("@action:inmenu Edit", "Move to Inactive Split View"));
1625 actionCollection()->setDefaultShortcut(moveToOtherViewAction
, Qt::SHIFT
| Qt::Key_F6
);
1626 connect(moveToOtherViewAction
, &QAction::triggered
, this, &DolphinMainWindow::moveToInactiveSplitView
);
1628 QAction
* showFilterBar
= actionCollection()->addAction(QStringLiteral("show_filter_bar"));
1629 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Filter..."));
1630 showFilterBar
->setToolTip(i18nc("@info:tooltip", "Show Filter Bar"));
1631 showFilterBar
->setWhatsThis(xi18nc("@info:whatsthis", "This opens the "
1632 "<emphasis>Filter Bar</emphasis> at the bottom of the window.<nl/> "
1633 "There you can enter a text to filter the files and folders currently displayed. "
1634 "Only those that contain the text in their name will be kept in view."));
1635 showFilterBar
->setIcon(QIcon::fromTheme(QStringLiteral("view-filter")));
1636 actionCollection()->setDefaultShortcuts(showFilterBar
, {Qt::CTRL
| Qt::Key_I
, Qt::Key_Slash
});
1637 connect(showFilterBar
, &QAction::triggered
, this, &DolphinMainWindow::showFilterBar
);
1639 // toggle_filter acts as a copy of the main showFilterBar to be used mainly
1640 // in the toolbar, with no default shortcut attached, to avoid messing with
1641 // existing workflows (filter bar always open and Ctrl-I to focus)
1642 QAction
*toggleFilter
= actionCollection()->addAction(QStringLiteral("toggle_filter"));
1643 toggleFilter
->setText(i18nc("@action:inmenu", "Toggle Filter Bar"));
1644 toggleFilter
->setIconText(i18nc("@action:intoolbar", "Filter"));
1645 toggleFilter
->setIcon(showFilterBar
->icon());
1646 toggleFilter
->setToolTip(showFilterBar
->toolTip());
1647 toggleFilter
->setWhatsThis(showFilterBar
->whatsThis());
1648 toggleFilter
->setCheckable(true);
1649 connect(toggleFilter
, &QAction::triggered
, this, &DolphinMainWindow::toggleFilterBar
);
1651 QAction
*searchAction
= KStandardAction::find(this, &DolphinMainWindow::find
, actionCollection());
1652 searchAction
->setText(i18n("Search..."));
1653 searchAction
->setToolTip(i18nc("@info:tooltip", "Search for files and folders"));
1654 searchAction
->setWhatsThis(xi18nc("@info:whatsthis find", "<para>This helps you "
1655 "find files and folders by opening a <emphasis>find bar</emphasis>. "
1656 "There you can enter search terms and specify settings to find the "
1657 "objects you are looking for.</para><para>Use this help again on "
1658 "the find bar so we can have a look at it while the settings are "
1659 "explained.</para>"));
1661 // toggle_search acts as a copy of the main searchAction to be used mainly
1662 // in the toolbar, with no default shortcut attached, to avoid messing with
1663 // existing workflows (search bar always open and Ctrl-F to focus)
1664 QAction
*toggleSearchAction
= actionCollection()->addAction(QStringLiteral("toggle_search"));
1665 toggleSearchAction
->setText(i18nc("@action:inmenu", "Toggle Search Bar"));
1666 toggleSearchAction
->setIconText(i18nc("@action:intoolbar", "Search"));
1667 toggleSearchAction
->setIcon(searchAction
->icon());
1668 toggleSearchAction
->setToolTip(searchAction
->toolTip());
1669 toggleSearchAction
->setWhatsThis(searchAction
->whatsThis());
1670 toggleSearchAction
->setCheckable(true);
1672 QAction
*toggleSelectionModeAction
= actionCollection()->addAction(QStringLiteral("toggle_selection_mode"));
1673 // i18n: This action toggles a selection mode.
1674 toggleSelectionModeAction
->setText(i18nc("@action:inmenu", "Select Files and Folders"));
1675 // i18n: Opens a selection mode for selecting files/folders and later selecting an action that acts on them.
1676 // So in a way "Select" here is used to mean both "Select files" and also "Select what to do" but mostly the first.
1677 // The text is kept so unspecific because it will be shown on the toolbar where space is at a premium.
1678 toggleSelectionModeAction
->setIconText(i18nc("@action:intoolbar", "Select"));
1679 toggleSelectionModeAction
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This application doesn't know which files or folders should be acted on, "
1680 "unless they are <emphasis>selected</emphasis> first. Press this to toggle the <emphasis>Selection Mode</emphasis> which makes selecting and deselecting as "
1681 "easy as pressing an item once.</para><para>While in this mode, a quick access bar at the bottom shows all the available actions for the current "
1682 "selection of items.</para>"));
1683 toggleSelectionModeAction
->setIcon(QIcon::fromTheme(QStringLiteral("quickwizard")));
1684 toggleSelectionModeAction
->setCheckable(true);
1685 actionCollection()->setDefaultShortcut(toggleSelectionModeAction
, Qt::Key_Space
);
1686 connect(toggleSelectionModeAction
, &QAction::triggered
, this, &DolphinMainWindow::toggleSelectionMode
);
1688 // A special version of the toggleSelectionModeAction for the toolbar that also contains a menu
1689 // with the selectAllAction and invertSelectionAction.
1690 auto *toggleSelectionModeToolBarAction
= new KToolBarPopupAction(toggleSelectionModeAction
->icon(), toggleSelectionModeAction
->iconText(), actionCollection());
1691 toggleSelectionModeToolBarAction
->setToolTip(toggleSelectionModeAction
->text());
1692 toggleSelectionModeToolBarAction
->setWhatsThis(toggleSelectionModeAction
->whatsThis());
1693 actionCollection()->addAction(QStringLiteral("toggle_selection_mode_with_popup"), toggleSelectionModeToolBarAction
);
1694 toggleSelectionModeToolBarAction
->setCheckable(true);
1695 toggleSelectionModeToolBarAction
->setPopupMode(QToolButton::DelayedPopup
);
1696 connect(toggleSelectionModeToolBarAction
, &QAction::triggered
, toggleSelectionModeAction
, &QAction::trigger
);
1697 connect(toggleSelectionModeAction
, &QAction::toggled
, toggleSelectionModeToolBarAction
, &QAction::setChecked
);
1699 QAction
* selectAllAction
= KStandardAction::selectAll(this, &DolphinMainWindow::selectAll
, actionCollection());
1700 selectAllAction
->setWhatsThis(xi18nc("@info:whatsthis", "This selects all "
1701 "files and folders in the current location."));
1703 QAction
* invertSelection
= actionCollection()->addAction(QStringLiteral("invert_selection"));
1704 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1705 invertSelection
->setWhatsThis(xi18nc("@info:whatsthis invert", "This selects all "
1706 "objects that you have currently <emphasis>not</emphasis> selected instead."));
1707 invertSelection
->setIcon(QIcon::fromTheme(QStringLiteral("edit-select-invert")));
1708 actionCollection()->setDefaultShortcut(invertSelection
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
1709 connect(invertSelection
, &QAction::triggered
, this, &DolphinMainWindow::invertSelection
);
1711 QMenu
*toggleSelectionModeActionMenu
= new QMenu(this);
1712 toggleSelectionModeActionMenu
->addAction(selectAllAction
);
1713 toggleSelectionModeActionMenu
->addAction(invertSelection
);
1714 toggleSelectionModeToolBarAction
->setMenu(toggleSelectionModeActionMenu
);
1716 // setup 'View' menu
1717 // (note that most of it is set up in DolphinViewActionHandler)
1719 QAction
* split
= actionCollection()->addAction(QStringLiteral("split_view"));
1720 split
->setWhatsThis(xi18nc("@info:whatsthis find", "<para>This splits "
1721 "the folder view below into two autonomous views.</para><para>This "
1722 "way you can see two locations at once and move items between them "
1723 "quickly.</para>Click this again afterwards to recombine the views."));
1724 actionCollection()->setDefaultShortcut(split
, Qt::Key_F3
);
1725 connect(split
, &QAction::triggered
, this, &DolphinMainWindow::toggleSplitView
);
1727 QAction
* stashSplit
= actionCollection()->addAction(QStringLiteral("split_stash"));
1728 actionCollection()->setDefaultShortcut(stashSplit
, Qt::CTRL
| Qt::Key_S
);
1729 stashSplit
->setText(i18nc("@action:intoolbar Stash", "Stash"));
1730 stashSplit
->setToolTip(i18nc("@info", "Opens the stash virtual directory in a split window"));
1731 stashSplit
->setIcon(QIcon::fromTheme(QStringLiteral("folder-stash")));
1732 stashSplit
->setCheckable(false);
1733 QDBusConnectionInterface
*sessionInterface
= QDBusConnection::sessionBus().interface();
1734 stashSplit
->setVisible(sessionInterface
&& sessionInterface
->isServiceRegistered(QStringLiteral("org.kde.kio.StashNotifier")));
1735 connect(stashSplit
, &QAction::triggered
, this, &DolphinMainWindow::toggleSplitStash
);
1737 KStandardAction::redisplay(this, &DolphinMainWindow::reloadView
, actionCollection());
1739 QAction
* stop
= actionCollection()->addAction(QStringLiteral("stop"));
1740 stop
->setText(i18nc("@action:inmenu View", "Stop"));
1741 stop
->setToolTip(i18nc("@info", "Stop loading"));
1742 stop
->setWhatsThis(i18nc("@info", "This stops the loading of the contents of the current folder."));
1743 stop
->setIcon(QIcon::fromTheme(QStringLiteral("process-stop")));
1744 connect(stop
, &QAction::triggered
, this, &DolphinMainWindow::stopLoading
);
1746 KToggleAction
* editableLocation
= actionCollection()->add
<KToggleAction
>(QStringLiteral("editable_location"));
1747 editableLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1748 editableLocation
->setWhatsThis(xi18nc("@info:whatsthis",
1749 "This toggles the <emphasis>Location Bar</emphasis> to be "
1750 "editable so you can directly enter a location you want to go to.<nl/>"
1751 "You can also switch to editing by clicking to the right of the "
1752 "location and switch back by confirming the edited location."));
1753 actionCollection()->setDefaultShortcut(editableLocation
, Qt::Key_F6
);
1754 connect(editableLocation
, &KToggleAction::triggered
, this, &DolphinMainWindow::toggleEditLocation
);
1756 QAction
* replaceLocation
= actionCollection()->addAction(QStringLiteral("replace_location"));
1757 replaceLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1758 // i18n: "enter" is used both in the meaning of "writing" and "going to" a new location here.
1759 // Both meanings are useful but not necessary to understand the use of "Replace Location".
1760 // So you might want to be more verbose in your language to convey the meaning but it's up to you.
1761 replaceLocation
->setWhatsThis(xi18nc("@info:whatsthis",
1762 "This switches to editing the location and selects it "
1763 "so you can quickly enter a different location."));
1764 actionCollection()->setDefaultShortcut(replaceLocation
, Qt::CTRL
| Qt::Key_L
);
1765 connect(replaceLocation
, &QAction::triggered
, this, &DolphinMainWindow::replaceLocation
);
1769 QScopedPointer
<QAction
> backAction(KStandardAction::back(nullptr, nullptr, nullptr));
1770 m_backAction
= new KToolBarPopupAction(backAction
->icon(), backAction
->text(), actionCollection());
1771 m_backAction
->setObjectName(backAction
->objectName());
1772 m_backAction
->setShortcuts(backAction
->shortcuts());
1774 m_backAction
->setPopupMode(QToolButton::DelayedPopup
);
1775 connect(m_backAction
, &QAction::triggered
, this, &DolphinMainWindow::goBack
);
1776 connect(m_backAction
->menu(), &QMenu::aboutToShow
, this, &DolphinMainWindow::slotAboutToShowBackPopupMenu
);
1777 connect(m_backAction
->menu(), &QMenu::triggered
, this, &DolphinMainWindow::slotGoBack
);
1778 actionCollection()->addAction(m_backAction
->objectName(), m_backAction
);
1780 auto backShortcuts
= m_backAction
->shortcuts();
1781 backShortcuts
.append(QKeySequence(Qt::Key_Backspace
));
1782 actionCollection()->setDefaultShortcuts(m_backAction
, backShortcuts
);
1784 DolphinRecentTabsMenu
* recentTabsMenu
= new DolphinRecentTabsMenu(this);
1785 actionCollection()->addAction(QStringLiteral("closed_tabs"), recentTabsMenu
);
1786 connect(m_tabWidget
, &DolphinTabWidget::rememberClosedTab
,
1787 recentTabsMenu
, &DolphinRecentTabsMenu::rememberClosedTab
);
1788 connect(recentTabsMenu
, &DolphinRecentTabsMenu::restoreClosedTab
,
1789 m_tabWidget
, &DolphinTabWidget::restoreClosedTab
);
1790 connect(recentTabsMenu
, &DolphinRecentTabsMenu::closedTabsCountChanged
,
1791 this, &DolphinMainWindow::closedTabsCountChanged
);
1793 QAction
* undoCloseTab
= actionCollection()->addAction(QStringLiteral("undo_close_tab"));
1794 undoCloseTab
->setText(i18nc("@action:inmenu File", "Undo close tab"));
1795 undoCloseTab
->setWhatsThis(i18nc("@info:whatsthis undo close tab",
1796 "This returns you to the previously closed tab."));
1797 actionCollection()->setDefaultShortcut(undoCloseTab
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_T
);
1798 undoCloseTab
->setIcon(QIcon::fromTheme(QStringLiteral("edit-undo")));
1799 undoCloseTab
->setEnabled(false);
1800 connect(undoCloseTab
, &QAction::triggered
, recentTabsMenu
, &DolphinRecentTabsMenu::undoCloseTab
);
1802 auto undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
1803 undoAction
->setWhatsThis(xi18nc("@info:whatsthis", "This undoes "
1804 "the last change you made to files or folders.<nl/>"
1805 "Such changes include <interface>creating, renaming</interface> "
1806 "and <interface>moving</interface> them to a different location "
1807 "or to the <filename>Trash</filename>. <nl/>Changes that can't "
1808 "be undone will ask for your confirmation."));
1809 undoAction
->setEnabled(false); // undo should be disabled by default
1812 QScopedPointer
<QAction
> forwardAction(KStandardAction::forward(nullptr, nullptr, nullptr));
1813 m_forwardAction
= new KToolBarPopupAction(forwardAction
->icon(), forwardAction
->text(), actionCollection());
1814 m_forwardAction
->setObjectName(forwardAction
->objectName());
1815 m_forwardAction
->setShortcuts(forwardAction
->shortcuts());
1817 m_forwardAction
->setPopupMode(QToolButton::DelayedPopup
);
1818 connect(m_forwardAction
, &QAction::triggered
, this, &DolphinMainWindow::goForward
);
1819 connect(m_forwardAction
->menu(), &QMenu::aboutToShow
, this, &DolphinMainWindow::slotAboutToShowForwardPopupMenu
);
1820 connect(m_forwardAction
->menu(), &QMenu::triggered
, this, &DolphinMainWindow::slotGoForward
);
1821 actionCollection()->addAction(m_forwardAction
->objectName(), m_forwardAction
);
1822 actionCollection()->setDefaultShortcuts(m_forwardAction
, m_forwardAction
->shortcuts());
1824 // enable middle-click to open in a new tab
1825 auto *middleClickEventFilter
= new MiddleClickActionEventFilter(this);
1826 connect(middleClickEventFilter
, &MiddleClickActionEventFilter::actionMiddleClicked
, this, &DolphinMainWindow::slotBackForwardActionMiddleClicked
);
1827 m_backAction
->menu()->installEventFilter(middleClickEventFilter
);
1828 m_forwardAction
->menu()->installEventFilter(middleClickEventFilter
);
1829 KStandardAction::up(this, &DolphinMainWindow::goUp
, actionCollection());
1830 QAction
* homeAction
= KStandardAction::home(this, &DolphinMainWindow::goHome
, actionCollection());
1831 homeAction
->setWhatsThis(xi18nc("@info:whatsthis", "Go to your "
1832 "<filename>Home</filename> folder.<nl/>Every user account "
1833 "has their own <filename>Home</filename> that contains their data "
1834 "including folders that contain personal application data."));
1836 // setup 'Tools' menu
1837 QAction
* compareFiles
= actionCollection()->addAction(QStringLiteral("compare_files"));
1838 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1839 compareFiles
->setIcon(QIcon::fromTheme(QStringLiteral("kompare")));
1840 compareFiles
->setEnabled(false);
1841 connect(compareFiles
, &QAction::triggered
, this, &DolphinMainWindow::compareFiles
);
1843 QAction
* openPreferredSearchTool
= actionCollection()->addAction(QStringLiteral("open_preferred_search_tool"));
1844 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool"));
1845 openPreferredSearchTool
->setWhatsThis(xi18nc("@info:whatsthis",
1846 "<para>This opens a preferred search tool for the viewed location.</para>"
1847 "<para>Use <emphasis>More Search Tools</emphasis> menu to configure it.</para>"));
1848 openPreferredSearchTool
->setIcon(QIcon::fromTheme(QStringLiteral("search")));
1849 actionCollection()->setDefaultShortcut(openPreferredSearchTool
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_F
);
1850 connect(openPreferredSearchTool
, &QAction::triggered
, this, &DolphinMainWindow::openPreferredSearchTool
);
1852 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
1853 QAction
* openTerminal
= actionCollection()->addAction(QStringLiteral("open_terminal"));
1854 openTerminal
->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
1855 openTerminal
->setWhatsThis(xi18nc("@info:whatsthis",
1856 "<para>This opens a <emphasis>terminal</emphasis> application for the viewed location.</para>"
1857 "<para>To learn more about terminals use the help in the terminal application.</para>"));
1858 openTerminal
->setIcon(QIcon::fromTheme(QStringLiteral("utilities-terminal")));
1859 actionCollection()->setDefaultShortcut(openTerminal
, Qt::SHIFT
| Qt::Key_F4
);
1860 connect(openTerminal
, &QAction::triggered
, this, &DolphinMainWindow::openTerminal
);
1862 QAction
* openTerminalHere
= actionCollection()->addAction(QStringLiteral("open_terminal_here"));
1863 // i18n: "Here" refers to the location(s) of the currently selected item(s) or the currently viewed location if nothing is selected.
1864 openTerminalHere
->setText(i18nc("@action:inmenu Tools", "Open Terminal Here"));
1865 openTerminalHere
->setWhatsThis(xi18nc("@info:whatsthis",
1866 "<para>This opens <emphasis>terminal</emphasis> applications for the selected items' locations.</para>"
1867 "<para>To learn more about terminals use the help in the terminal application.</para>"));
1868 openTerminalHere
->setIcon(QIcon::fromTheme(QStringLiteral("utilities-terminal")));
1869 actionCollection()->setDefaultShortcut(openTerminalHere
, Qt::SHIFT
| Qt::ALT
| Qt::Key_F4
);
1870 connect(openTerminalHere
, &QAction::triggered
, this, &DolphinMainWindow::openTerminalHere
);
1873 QAction
* focusTerminalPanel
= actionCollection()->addAction(QStringLiteral("focus_terminal_panel"));
1874 focusTerminalPanel
->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
1875 focusTerminalPanel
->setIcon(QIcon::fromTheme(QStringLiteral("swap-panels")));
1876 actionCollection()->setDefaultShortcut(focusTerminalPanel
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_F4
);
1877 connect(focusTerminalPanel
, &QAction::triggered
, this, &DolphinMainWindow::focusTerminalPanel
);
1881 // setup 'Bookmarks' menu
1882 KActionMenu
*bookmarkMenu
= new KActionMenu(i18nc("@title:menu", "&Bookmarks"), this);
1883 bookmarkMenu
->setIcon(QIcon::fromTheme(QStringLiteral("bookmarks")));
1884 // Make the toolbar button version work properly on click
1885 bookmarkMenu
->setPopupMode(QToolButton::InstantPopup
);
1886 m_bookmarkHandler
= new DolphinBookmarkHandler(this, actionCollection(), bookmarkMenu
->menu(), this);
1887 actionCollection()->addAction(QStringLiteral("bookmarks"), bookmarkMenu
);
1889 // setup 'Settings' menu
1890 KToggleAction
* showMenuBar
= KStandardAction::showMenubar(nullptr, nullptr, actionCollection());
1891 showMenuBar
->setWhatsThis(xi18nc("@info:whatsthis",
1892 "This switches between having a <emphasis>Menubar</emphasis> "
1893 "and having a <interface>Control</interface> button. Both "
1894 "contain mostly the same commands and configuration options."));
1895 connect(showMenuBar
, &KToggleAction::triggered
, // Fixes #286822
1896 this, &DolphinMainWindow::toggleShowMenuBar
, Qt::QueuedConnection
);
1898 KToggleAction
* showStatusBar
= KStandardAction::showStatusbar(nullptr, nullptr, actionCollection());
1899 showStatusBar
->setChecked(GeneralSettings::showStatusBar());
1900 connect(GeneralSettings::self(), &GeneralSettings::showStatusBarChanged
, showStatusBar
, &KToggleAction::setChecked
);
1901 connect(showStatusBar
, &KToggleAction::triggered
, this, [this](bool checked
) {
1902 GeneralSettings::setShowStatusBar(checked
);
1906 KStandardAction::keyBindings(this, &DolphinMainWindow::slotKeyBindings
, actionCollection());
1907 KStandardAction::preferences(this, &DolphinMainWindow::editSettings
, actionCollection());
1909 // setup 'Help' menu for the m_controlButton. The other one is set up in the base class.
1910 m_helpMenu
= new KHelpMenu(nullptr);
1911 m_helpMenu
->menu()->installEventFilter(this);
1912 // remove duplicate shortcuts
1913 auto removeHelpActionShortcut
= [this](KHelpMenu::MenuId menuId
) {
1914 if (auto *action
= m_helpMenu
->action(menuId
)) {
1915 action
->setShortcut(QKeySequence());
1918 removeHelpActionShortcut(KHelpMenu::menuHelpContents
);
1919 removeHelpActionShortcut(KHelpMenu::menuWhatsThis
);
1921 // not in menu actions
1922 QList
<QKeySequence
> nextTabKeys
= KStandardShortcut::tabNext();
1923 nextTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::Key_Tab
));
1925 QList
<QKeySequence
> prevTabKeys
= KStandardShortcut::tabPrev();
1926 prevTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::SHIFT
| Qt::Key_Tab
));
1928 for (int i
= 0; i
< MaxActivateTabShortcuts
; ++i
) {
1929 QAction
* activateTab
= actionCollection()->addAction(QStringLiteral("activate_tab_%1").arg(i
));
1930 activateTab
->setText(i18nc("@action:inmenu", "Activate Tab %1", i
+ 1));
1931 activateTab
->setEnabled(false);
1932 connect(activateTab
, &QAction::triggered
, this, [this, i
]() { m_tabWidget
->activateTab(i
); });
1934 // only add default shortcuts for the first 9 tabs regardless of MaxActivateTabShortcuts
1936 actionCollection()->setDefaultShortcut(activateTab
, QStringLiteral("Alt+%1").arg(i
+ 1));
1940 QAction
* activateLastTab
= actionCollection()->addAction(QStringLiteral("activate_last_tab"));
1941 activateLastTab
->setText(i18nc("@action:inmenu", "Activate Last Tab"));
1942 activateLastTab
->setEnabled(false);
1943 connect(activateLastTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activateLastTab
);
1944 actionCollection()->setDefaultShortcut(activateLastTab
, Qt::ALT
| Qt::Key_0
);
1946 QAction
* activateNextTab
= actionCollection()->addAction(QStringLiteral("activate_next_tab"));
1947 activateNextTab
->setIconText(i18nc("@action:inmenu", "Next Tab"));
1948 activateNextTab
->setText(i18nc("@action:inmenu", "Activate Next Tab"));
1949 activateNextTab
->setEnabled(false);
1950 connect(activateNextTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activateNextTab
);
1951 actionCollection()->setDefaultShortcuts(activateNextTab
, nextTabKeys
);
1953 QAction
* activatePrevTab
= actionCollection()->addAction(QStringLiteral("activate_prev_tab"));
1954 activatePrevTab
->setIconText(i18nc("@action:inmenu", "Previous Tab"));
1955 activatePrevTab
->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
1956 activatePrevTab
->setEnabled(false);
1957 connect(activatePrevTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activatePrevTab
);
1958 actionCollection()->setDefaultShortcuts(activatePrevTab
, prevTabKeys
);
1961 QAction
* showTarget
= actionCollection()->addAction(QStringLiteral("show_target"));
1962 showTarget
->setText(i18nc("@action:inmenu", "Show Target"));
1963 showTarget
->setIcon(QIcon::fromTheme(QStringLiteral("document-open-folder")));
1964 showTarget
->setEnabled(false);
1965 connect(showTarget
, &QAction::triggered
, this, &DolphinMainWindow::showTarget
);
1967 QAction
* openInNewTab
= actionCollection()->addAction(QStringLiteral("open_in_new_tab"));
1968 openInNewTab
->setText(i18nc("@action:inmenu", "Open in New Tab"));
1969 openInNewTab
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1970 connect(openInNewTab
, &QAction::triggered
, this, &DolphinMainWindow::openInNewTab
);
1972 QAction
* openInNewTabs
= actionCollection()->addAction(QStringLiteral("open_in_new_tabs"));
1973 openInNewTabs
->setText(i18nc("@action:inmenu", "Open in New Tabs"));
1974 openInNewTabs
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1975 connect(openInNewTabs
, &QAction::triggered
, this, &DolphinMainWindow::openInNewTab
);
1977 QAction
* openInNewWindow
= actionCollection()->addAction(QStringLiteral("open_in_new_window"));
1978 openInNewWindow
->setText(i18nc("@action:inmenu", "Open in New Window"));
1979 openInNewWindow
->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
1980 connect(openInNewWindow
, &QAction::triggered
, this, &DolphinMainWindow::openInNewWindow
);
1983 void DolphinMainWindow::setupDockWidgets()
1985 const bool lock
= GeneralSettings::lockPanels();
1987 DolphinPlacesModelSingleton::instance().placesModel()->setPanelsLocked(lock
);
1989 KDualAction
* lockLayoutAction
= actionCollection()->add
<KDualAction
>(QStringLiteral("lock_panels"));
1990 lockLayoutAction
->setActiveText(i18nc("@action:inmenu Panels", "Unlock Panels"));
1991 lockLayoutAction
->setActiveIcon(QIcon::fromTheme(QStringLiteral("object-unlocked")));
1992 lockLayoutAction
->setInactiveText(i18nc("@action:inmenu Panels", "Lock Panels"));
1993 lockLayoutAction
->setInactiveIcon(QIcon::fromTheme(QStringLiteral("object-locked")));
1994 lockLayoutAction
->setWhatsThis(xi18nc("@info:whatsthis", "This "
1995 "switches between having panels <emphasis>locked</emphasis> or "
1996 "<emphasis>unlocked</emphasis>.<nl/>Unlocked panels can be "
1997 "dragged to the other side of the window and have a close "
1998 "button.<nl/>Locked panels are embedded more cleanly."));
1999 lockLayoutAction
->setActive(lock
);
2000 connect(lockLayoutAction
, &KDualAction::triggered
, this, &DolphinMainWindow::togglePanelLockState
);
2002 // Setup "Information"
2003 DolphinDockWidget
* infoDock
= new DolphinDockWidget(i18nc("@title:window", "Information"));
2004 infoDock
->setLocked(lock
);
2005 infoDock
->setObjectName(QStringLiteral("infoDock"));
2006 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
2009 InformationPanel
* infoPanel
= new InformationPanel(infoDock
);
2010 infoPanel
->setCustomContextMenuActions({lockLayoutAction
});
2011 connect(infoPanel
, &InformationPanel::urlActivated
, this, &DolphinMainWindow::handleUrl
);
2012 infoDock
->setWidget(infoPanel
);
2014 QAction
* infoAction
= infoDock
->toggleViewAction();
2015 createPanelAction(QIcon::fromTheme(QStringLiteral("dialog-information")), Qt::Key_F11
, infoAction
, QStringLiteral("show_information_panel"));
2017 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
2018 connect(this, &DolphinMainWindow::urlChanged
,
2019 infoPanel
, &InformationPanel::setUrl
);
2020 connect(this, &DolphinMainWindow::selectionChanged
,
2021 infoPanel
, &InformationPanel::setSelection
);
2022 connect(this, &DolphinMainWindow::requestItemInfo
,
2023 infoPanel
, &InformationPanel::requestDelayedItemInfo
);
2024 connect(this, &DolphinMainWindow::fileItemsChanged
,
2025 infoPanel
, &InformationPanel::slotFilesItemChanged
);
2028 // i18n: This is the last paragraph for the "What's This"-texts of all four panels.
2029 const QString panelWhatsThis
= xi18nc("@info:whatsthis", "<para>To show or "
2030 "hide panels like this go to <interface>Control|Panels</interface> "
2031 "or <interface>View|Panels</interface>.</para>");
2033 actionCollection()->action(QStringLiteral("show_information_panel"))
2034 ->setWhatsThis(xi18nc("@info:whatsthis", "<para> This toggles the "
2035 "<emphasis>information</emphasis> panel at the right side of the "
2036 "window.</para><para>The panel provides in-depth information "
2037 "about the items your mouse is hovering over or about the selected "
2038 "items. Otherwise it informs you about the currently viewed folder.<nl/>"
2039 "For single items a preview of their contents is provided.</para>"));
2041 infoDock
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This panel "
2042 "provides in-depth information about the items your mouse is "
2043 "hovering over or about the selected items. Otherwise it informs "
2044 "you about the currently viewed folder.<nl/>For single items a "
2045 "preview of their contents is provided.</para><para>You can configure "
2046 "which and how details are given here by right-clicking.</para>") + panelWhatsThis
);
2049 DolphinDockWidget
* foldersDock
= new DolphinDockWidget(i18nc("@title:window", "Folders"));
2050 foldersDock
->setLocked(lock
);
2051 foldersDock
->setObjectName(QStringLiteral("foldersDock"));
2052 foldersDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
2053 FoldersPanel
* foldersPanel
= new FoldersPanel(foldersDock
);
2054 foldersPanel
->setCustomContextMenuActions({lockLayoutAction
});
2055 foldersDock
->setWidget(foldersPanel
);
2057 QAction
* foldersAction
= foldersDock
->toggleViewAction();
2058 createPanelAction(QIcon::fromTheme(QStringLiteral("folder")), Qt::Key_F7
, foldersAction
, QStringLiteral("show_folders_panel"));
2060 addDockWidget(Qt::LeftDockWidgetArea
, foldersDock
);
2061 connect(this, &DolphinMainWindow::urlChanged
,
2062 foldersPanel
, &FoldersPanel::setUrl
);
2063 connect(foldersPanel
, &FoldersPanel::folderActivated
,
2064 this, &DolphinMainWindow::changeUrl
);
2065 connect(foldersPanel
, &FoldersPanel::folderInNewTab
,
2066 this, &DolphinMainWindow::openNewTab
);
2067 connect(foldersPanel
, &FoldersPanel::folderInNewActiveTab
,
2068 this, &DolphinMainWindow::openNewTabAndActivate
);
2069 connect(foldersPanel
, &FoldersPanel::errorMessage
,
2070 this, &DolphinMainWindow::showErrorMessage
);
2072 actionCollection()->action(QStringLiteral("show_folders_panel"))
2073 ->setWhatsThis(xi18nc("@info:whatsthis", "This toggles the "
2074 "<emphasis>folders</emphasis> panel at the left side of the window."
2075 "<nl/><nl/>It shows the folders of the <emphasis>file system"
2076 "</emphasis> in a <emphasis>tree view</emphasis>."));
2077 foldersDock
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This panel "
2078 "shows the folders of the <emphasis>file system</emphasis> in a "
2079 "<emphasis>tree view</emphasis>.</para><para>Click a folder to go "
2080 "there. Click the arrow to the left of a folder to see its subfolders. "
2081 "This allows quick switching between any folders.</para>") + panelWhatsThis
);
2085 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
2086 DolphinDockWidget
* terminalDock
= new DolphinDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
2087 terminalDock
->setLocked(lock
);
2088 terminalDock
->setObjectName(QStringLiteral("terminalDock"));
2089 m_terminalPanel
= new TerminalPanel(terminalDock
);
2090 m_terminalPanel
->setCustomContextMenuActions({lockLayoutAction
});
2091 terminalDock
->setWidget(m_terminalPanel
);
2093 connect(m_terminalPanel
, &TerminalPanel::hideTerminalPanel
, terminalDock
, &DolphinDockWidget::hide
);
2094 connect(m_terminalPanel
, &TerminalPanel::changeUrl
, this, &DolphinMainWindow::slotTerminalDirectoryChanged
);
2095 connect(terminalDock
, &DolphinDockWidget::visibilityChanged
,
2096 m_terminalPanel
, &TerminalPanel::dockVisibilityChanged
);
2097 connect(terminalDock
, &DolphinDockWidget::visibilityChanged
,
2098 this, &DolphinMainWindow::slotTerminalPanelVisibilityChanged
);
2100 QAction
* terminalAction
= terminalDock
->toggleViewAction();
2101 createPanelAction(QIcon::fromTheme(QStringLiteral("dialog-scripts")), Qt::Key_F4
, terminalAction
, QStringLiteral("show_terminal_panel"));
2103 addDockWidget(Qt::BottomDockWidgetArea
, terminalDock
);
2104 connect(this, &DolphinMainWindow::urlChanged
,
2105 m_terminalPanel
, &TerminalPanel::setUrl
);
2107 if (GeneralSettings::version() < 200) {
2108 terminalDock
->hide();
2111 actionCollection()->action(QStringLiteral("show_terminal_panel"))
2112 ->setWhatsThis(xi18nc("@info:whatsthis", "<para>This toggles the "
2113 "<emphasis>terminal</emphasis> panel at the bottom of the window."
2114 "<nl/>The location in the terminal will always match the folder "
2115 "view so you can navigate using either.</para><para>The terminal "
2116 "panel is not needed for basic computer usage but can be useful "
2117 "for advanced tasks. To learn more about terminals use the help "
2118 "in a standalone terminal application like Konsole.</para>"));
2119 terminalDock
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is "
2120 "the <emphasis>terminal</emphasis> panel. It behaves like a "
2121 "normal terminal but will match the location of the folder view "
2122 "so you can navigate using either.</para><para>The terminal panel "
2123 "is not needed for basic computer usage but can be useful for "
2124 "advanced tasks. To learn more about terminals use the help in a "
2125 "standalone terminal application like Konsole.</para>") + panelWhatsThis
);
2129 if (GeneralSettings::version() < 200) {
2131 foldersDock
->hide();
2135 DolphinDockWidget
* placesDock
= new DolphinDockWidget(i18nc("@title:window", "Places"));
2136 placesDock
->setLocked(lock
);
2137 placesDock
->setObjectName(QStringLiteral("placesDock"));
2138 placesDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
2140 m_placesPanel
= new PlacesPanel(placesDock
);
2141 m_placesPanel
->setCustomContextMenuActions({lockLayoutAction
});
2142 placesDock
->setWidget(m_placesPanel
);
2144 QAction
*placesAction
= placesDock
->toggleViewAction();
2145 createPanelAction(QIcon::fromTheme(QStringLiteral("compass")), Qt::Key_F9
, placesAction
, QStringLiteral("show_places_panel"));
2147 addDockWidget(Qt::LeftDockWidgetArea
, placesDock
);
2148 connect(m_placesPanel
, &PlacesPanel::placeActivated
,
2149 this, &DolphinMainWindow::slotPlaceActivated
);
2150 connect(m_placesPanel
, &PlacesPanel::tabRequested
,
2151 this, &DolphinMainWindow::openNewTab
);
2152 connect(m_placesPanel
, &PlacesPanel::activeTabRequested
,
2153 this, &DolphinMainWindow::openNewTabAndActivate
);
2154 connect(m_placesPanel
, &PlacesPanel::newWindowRequested
, this, [this](const QUrl
&url
) {
2155 Dolphin::openNewWindow({url
}, this);
2157 connect(m_placesPanel
, &PlacesPanel::errorMessage
,
2158 this, &DolphinMainWindow::showErrorMessage
);
2159 connect(this, &DolphinMainWindow::urlChanged
,
2160 m_placesPanel
, &PlacesPanel::setUrl
);
2161 connect(placesDock
, &DolphinDockWidget::visibilityChanged
,
2162 &DolphinUrlNavigatorsController::slotPlacesPanelVisibilityChanged
);
2163 connect(this, &DolphinMainWindow::settingsChanged
,
2164 m_placesPanel
, &PlacesPanel::readSettings
);
2165 connect(m_placesPanel
, &PlacesPanel::storageTearDownRequested
,
2166 this, &DolphinMainWindow::slotStorageTearDownFromPlacesRequested
);
2167 connect(m_placesPanel
, &PlacesPanel::storageTearDownExternallyRequested
,
2168 this, &DolphinMainWindow::slotStorageTearDownExternallyRequested
);
2169 DolphinUrlNavigatorsController::slotPlacesPanelVisibilityChanged(m_placesPanel
->isVisible());
2171 auto actionShowAllPlaces
= new QAction(QIcon::fromTheme(QStringLiteral("view-hidden")), i18nc("@item:inmenu", "Show Hidden Places"), this);
2172 actionShowAllPlaces
->setCheckable(true);
2173 actionShowAllPlaces
->setDisabled(true);
2174 actionShowAllPlaces
->setWhatsThis(i18nc("@info:whatsthis", "This displays "
2175 "all places in the places panel that have been hidden. They will "
2176 "appear semi-transparent unless you uncheck their hide property."));
2178 connect(actionShowAllPlaces
, &QAction::triggered
, this, [actionShowAllPlaces
, this](bool checked
){
2179 m_placesPanel
->setShowAll(checked
);
2181 connect(m_placesPanel
, &PlacesPanel::allPlacesShownChanged
, actionShowAllPlaces
, &QAction::setChecked
);
2183 actionCollection()->action(QStringLiteral("show_places_panel"))
2184 ->setWhatsThis(xi18nc("@info:whatsthis", "<para>This toggles the "
2185 "<emphasis>places</emphasis> panel at the left side of the window."
2186 "</para><para>It allows you to go to locations you have "
2187 "bookmarked and to access disk or media attached to the computer "
2188 "or to the network. It also contains sections to find recently "
2189 "saved files or files of a certain type.</para>"));
2190 placesDock
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2191 "<emphasis>Places</emphasis> panel. It allows you to go to locations "
2192 "you have bookmarked and to access disk or media attached to the "
2193 "computer or to the network. It also contains sections to find "
2194 "recently saved files or files of a certain type.</para><para>"
2195 "Click on an entry to go there. Click with the right mouse button "
2196 "instead to open any entry in a new tab or new window.</para>"
2197 "<para>New entries can be added by dragging folders onto this panel. "
2198 "Right-click any section or entry to hide it. Right-click an empty "
2199 "space on this panel and select <interface>Show Hidden Places"
2200 "</interface> to display it again.</para>") + panelWhatsThis
);
2202 // Add actions into the "Panels" menu
2203 KActionMenu
* panelsMenu
= new KActionMenu(i18nc("@action:inmenu View", "Show Panels"), this);
2204 actionCollection()->addAction(QStringLiteral("panels"), panelsMenu
);
2205 panelsMenu
->setIcon(QIcon::fromTheme(QStringLiteral("view-sidetree")));
2206 panelsMenu
->setPopupMode(QToolButton::InstantPopup
);
2207 const KActionCollection
* ac
= actionCollection();
2208 panelsMenu
->addAction(ac
->action(QStringLiteral("show_places_panel")));
2210 panelsMenu
->addAction(ac
->action(QStringLiteral("show_information_panel")));
2212 panelsMenu
->addAction(ac
->action(QStringLiteral("show_folders_panel")));
2213 panelsMenu
->addAction(ac
->action(QStringLiteral("show_terminal_panel")));
2214 panelsMenu
->addSeparator();
2215 panelsMenu
->addAction(actionShowAllPlaces
);
2216 panelsMenu
->addAction(lockLayoutAction
);
2218 connect(panelsMenu
->menu(), &QMenu::aboutToShow
, this, [actionShowAllPlaces
, this]{
2219 actionShowAllPlaces
->setEnabled(DolphinPlacesModelSingleton::instance().placesModel()->hiddenCount());
2224 void DolphinMainWindow::updateFileAndEditActions()
2226 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
2227 const KActionCollection
* col
= actionCollection();
2228 KFileItemListProperties
capabilitiesSource(list
);
2230 QAction
* renameAction
= col
->action(KStandardAction::name(KStandardAction::RenameFile
));
2231 QAction
* moveToTrashAction
= col
->action(KStandardAction::name(KStandardAction::MoveToTrash
));
2232 QAction
* deleteAction
= col
->action(KStandardAction::name(KStandardAction::DeleteFile
));
2233 QAction
* cutAction
= col
->action(KStandardAction::name(KStandardAction::Cut
));
2234 QAction
* duplicateAction
= col
->action(QStringLiteral("duplicate")); // see DolphinViewActionHandler
2235 QAction
* addToPlacesAction
= col
->action(QStringLiteral("add_to_places"));
2236 QAction
* copyToOtherViewAction
= col
->action(QStringLiteral("copy_to_inactive_split_view"));
2237 QAction
* moveToOtherViewAction
= col
->action(QStringLiteral("move_to_inactive_split_view"));
2238 QAction
* copyLocation
= col
->action(QString("copy_location"));
2240 if (list
.isEmpty()) {
2241 stateChanged(QStringLiteral("has_no_selection"));
2243 // All actions that need a selection to function can be enabled because they should trigger selection mode.
2244 renameAction
->setEnabled(true);
2245 moveToTrashAction
->setEnabled(true);
2246 deleteAction
->setEnabled(true);
2247 cutAction
->setEnabled(true);
2248 duplicateAction
->setEnabled(true);
2249 addToPlacesAction
->setEnabled(true);
2250 copyLocation
->setEnabled(true);
2252 stateChanged(QStringLiteral("has_selection"));
2254 QAction
* deleteWithTrashShortcut
= col
->action(QStringLiteral("delete_shortcut")); // see DolphinViewActionHandler
2255 QAction
* showTarget
= col
->action(QStringLiteral("show_target"));
2257 if (list
.length() == 1 && list
.first().isDir()) {
2258 addToPlacesAction
->setEnabled(true);
2260 addToPlacesAction
->setEnabled(false);
2263 const bool enableMoveToTrash
= capabilitiesSource
.isLocal() && capabilitiesSource
.supportsMoving();
2265 renameAction
->setEnabled(capabilitiesSource
.supportsMoving());
2266 moveToTrashAction
->setEnabled(enableMoveToTrash
);
2267 deleteAction
->setEnabled(capabilitiesSource
.supportsDeleting());
2268 deleteWithTrashShortcut
->setEnabled(capabilitiesSource
.supportsDeleting() && !enableMoveToTrash
);
2269 cutAction
->setEnabled(capabilitiesSource
.supportsMoving());
2270 copyLocation
->setEnabled(list
.length() == 1);
2271 showTarget
->setEnabled(list
.length() == 1 && list
.at(0).isLink());
2272 duplicateAction
->setEnabled(capabilitiesSource
.supportsWriting());
2275 if (m_tabWidget
->currentTabPage()->splitViewEnabled()) {
2276 DolphinTabPage
* tabPage
= m_tabWidget
->currentTabPage();
2277 KFileItem capabilitiesDestination
;
2279 if (tabPage
->primaryViewActive()) {
2280 capabilitiesDestination
= tabPage
->secondaryViewContainer()->url();
2282 capabilitiesDestination
= tabPage
->primaryViewContainer()->url();
2285 copyToOtherViewAction
->setEnabled(capabilitiesDestination
.isWritable());
2286 moveToOtherViewAction
->setEnabled((list
.isEmpty() || capabilitiesSource
.supportsMoving()) && capabilitiesDestination
.isWritable());
2288 copyToOtherViewAction
->setEnabled(false);
2289 moveToOtherViewAction
->setEnabled(false);
2293 void DolphinMainWindow::updateViewActions()
2295 m_actionHandler
->updateViewActions();
2297 QAction
*toggleSelectionModeAction
= actionCollection()->action(QStringLiteral("toggle_selection_mode"));
2298 disconnect(nullptr, &DolphinViewContainer::selectionModeChanged
,
2299 toggleSelectionModeAction
, &QAction::setChecked
);
2300 toggleSelectionModeAction
->setChecked(m_activeViewContainer
->isSelectionModeEnabled());
2301 connect(m_activeViewContainer
, &DolphinViewContainer::selectionModeChanged
,
2302 toggleSelectionModeAction
, &QAction::setChecked
);
2304 QAction
* toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
2305 toggleFilterBarAction
->setChecked(m_activeViewContainer
->isFilterBarVisible());
2307 updateSplitAction();
2310 void DolphinMainWindow::updateGoActions()
2312 QAction
* goUpAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Up
));
2313 const QUrl currentUrl
= m_activeViewContainer
->url();
2314 // I think this is one of the best places to firstly be confronted
2315 // with a file system and its hierarchy. Talking about the root
2316 // directory might seem too much here but it is the question that
2317 // naturally arises in this context.
2318 goUpAction
->setWhatsThis(xi18nc("@info:whatsthis", "<para>Go to "
2319 "the folder that contains the currently viewed one.</para>"
2320 "<para>All files and folders are organized in a hierarchical "
2321 "<emphasis>file system</emphasis>. At the top of this hierarchy is "
2322 "a directory that contains all data connected to this computer"
2323 "—the <emphasis>root directory</emphasis>.</para>"));
2324 goUpAction
->setEnabled(KIO::upUrl(currentUrl
) != currentUrl
);
2327 void DolphinMainWindow::refreshViews()
2329 m_tabWidget
->refreshViews();
2331 if (GeneralSettings::modifiedStartupSettings()) {
2332 updateWindowTitle();
2335 Q_EMIT
settingsChanged();
2338 void DolphinMainWindow::clearStatusBar()
2340 m_activeViewContainer
->statusBar()->resetToDefaultText();
2343 void DolphinMainWindow::connectViewSignals(DolphinViewContainer
* container
)
2345 connect(container
, &DolphinViewContainer::showFilterBarChanged
,
2346 this, &DolphinMainWindow::updateFilterBarAction
);
2347 connect(container
, &DolphinViewContainer::writeStateChanged
,
2348 this, &DolphinMainWindow::slotWriteStateChanged
);
2349 connect(container
, &DolphinViewContainer::searchModeEnabledChanged
,
2350 this, &DolphinMainWindow::updateSearchAction
);
2351 connect(container
, &DolphinViewContainer::captionChanged
,
2352 this, &DolphinMainWindow::updateWindowTitle
);
2353 connect(container
, &DolphinViewContainer::tabRequested
,
2354 this, &DolphinMainWindow::openNewTab
);
2355 connect(container
, &DolphinViewContainer::activeTabRequested
,
2356 this, &DolphinMainWindow::openNewTabAndActivate
);
2358 const QAction
* toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
2359 connect(toggleSearchAction
, &QAction::triggered
, container
, &DolphinViewContainer::setSearchModeEnabled
);
2361 const DolphinView
* view
= container
->view();
2362 connect(view
, &DolphinView::selectionChanged
,
2363 this, &DolphinMainWindow::slotSelectionChanged
);
2364 connect(view
, &DolphinView::requestItemInfo
,
2365 this, &DolphinMainWindow::requestItemInfo
);
2366 connect(view
, &DolphinView::fileItemsChanged
,
2367 this, &DolphinMainWindow::fileItemsChanged
);
2368 connect(view
, &DolphinView::tabRequested
,
2369 this, &DolphinMainWindow::openNewTab
);
2370 connect(view
, &DolphinView::activeTabRequested
,
2371 this, &DolphinMainWindow::openNewTabAndActivate
);
2372 connect(view
, &DolphinView::windowRequested
,
2373 this, &DolphinMainWindow::openNewWindow
);
2374 connect(view
, &DolphinView::requestContextMenu
,
2375 this, &DolphinMainWindow::openContextMenu
);
2376 connect(view
, &DolphinView::directoryLoadingStarted
,
2377 this, &DolphinMainWindow::enableStopAction
);
2378 connect(view
, &DolphinView::directoryLoadingCompleted
,
2379 this, &DolphinMainWindow::disableStopAction
);
2380 connect(view
, &DolphinView::directoryLoadingCompleted
,
2381 this, &DolphinMainWindow::slotDirectoryLoadingCompleted
);
2382 connect(view
, &DolphinView::goBackRequested
,
2383 this, &DolphinMainWindow::goBack
);
2384 connect(view
, &DolphinView::goForwardRequested
,
2385 this, &DolphinMainWindow::goForward
);
2386 connect(view
, &DolphinView::urlActivated
,
2387 this, &DolphinMainWindow::handleUrl
);
2388 connect(view
, &DolphinView::goUpRequested
,
2389 this, &DolphinMainWindow::goUp
);
2391 connect(container
->urlNavigatorInternalWithHistory(), &KUrlNavigator::urlChanged
,
2392 this, &DolphinMainWindow::changeUrl
);
2393 connect(container
->urlNavigatorInternalWithHistory(), &KUrlNavigator::historyChanged
,
2394 this, &DolphinMainWindow::updateHistory
);
2396 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>
2397 (actionCollection()->action(QStringLiteral("url_navigators")));
2398 const KUrlNavigator
*navigator
= m_tabWidget
->currentTabPage()->primaryViewActive() ?
2399 navigators
->primaryUrlNavigator() :
2400 navigators
->secondaryUrlNavigator();
2402 QAction
*editableLocactionAction
= actionCollection()->action(QStringLiteral("editable_location"));
2403 editableLocactionAction
->setChecked(navigator
->isUrlEditable());
2404 connect(navigator
, &KUrlNavigator::editableStateChanged
,
2405 this, &DolphinMainWindow::slotEditableStateChanged
);
2406 connect(navigator
, &KUrlNavigator::tabRequested
,
2407 this, &DolphinMainWindow::openNewTab
);
2408 connect(navigator
, &KUrlNavigator::activeTabRequested
,
2409 this, &DolphinMainWindow::openNewTabAndActivate
);
2410 connect(navigator
, &KUrlNavigator::newWindowRequested
,
2411 this, &DolphinMainWindow::openNewWindow
);
2415 void DolphinMainWindow::updateSplitAction()
2417 QAction
* splitAction
= actionCollection()->action(QStringLiteral("split_view"));
2418 const DolphinTabPage
* tabPage
= m_tabWidget
->currentTabPage();
2419 if (tabPage
->splitViewEnabled()) {
2420 if (GeneralSettings::closeActiveSplitView() ? tabPage
->primaryViewActive() : !tabPage
->primaryViewActive()) {
2421 splitAction
->setText(i18nc("@action:intoolbar Close left view", "Close"));
2422 splitAction
->setToolTip(i18nc("@info", "Close left view"));
2423 splitAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-left-close")));
2425 splitAction
->setText(i18nc("@action:intoolbar Close right view", "Close"));
2426 splitAction
->setToolTip(i18nc("@info", "Close right view"));
2427 splitAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-right-close")));
2430 splitAction
->setText(i18nc("@action:intoolbar Split view", "Split"));
2431 splitAction
->setToolTip(i18nc("@info", "Split view"));
2432 splitAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-right-new")));
2436 void DolphinMainWindow::updateAllowedToolbarAreas()
2438 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>
2439 (actionCollection()->action(QStringLiteral("url_navigators")));
2440 if (toolBar()->actions().contains(navigators
)) {
2441 toolBar()->setAllowedAreas(Qt::TopToolBarArea
| Qt::BottomToolBarArea
);
2442 if (toolBarArea(toolBar()) == Qt::LeftToolBarArea
||
2443 toolBarArea(toolBar()) == Qt::RightToolBarArea
) {
2444 addToolBar(Qt::TopToolBarArea
, toolBar());
2447 toolBar()->setAllowedAreas(Qt::AllToolBarAreas
);
2451 bool DolphinMainWindow::isKompareInstalled() const
2453 static bool initialized
= false;
2454 static bool installed
= false;
2456 // TODO: maybe replace this approach later by using a menu
2457 // plugin like kdiff3plugin.cpp
2458 installed
= !QStandardPaths::findExecutable(QStringLiteral("kompare")).isEmpty();
2464 void DolphinMainWindow::createPanelAction(const QIcon
& icon
,
2465 const QKeySequence
& shortcut
,
2466 QAction
* dockAction
,
2467 const QString
& actionName
)
2469 QAction
* panelAction
= actionCollection()->addAction(actionName
);
2470 panelAction
->setCheckable(true);
2471 panelAction
->setChecked(dockAction
->isChecked());
2472 panelAction
->setText(dockAction
->text());
2473 panelAction
->setIcon(icon
);
2474 dockAction
->setIcon(icon
);
2475 actionCollection()->setDefaultShortcut(panelAction
, shortcut
);
2477 connect(panelAction
, &QAction::triggered
, dockAction
, &QAction::trigger
);
2478 connect(dockAction
, &QAction::toggled
, panelAction
, &QAction::setChecked
);
2481 void DolphinMainWindow::setupWhatsThis()
2484 menuBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2485 "<emphasis>Menubar</emphasis>. It provides access to commands and "
2486 "configuration options. Left-click on any of the menus on this "
2487 "bar to see its contents.</para><para>The Menubar can be hidden "
2488 "by unchecking <interface>Settings|Show Menubar</interface>. Then "
2489 "most of its contents become available through a <interface>Control"
2490 "</interface> button on the <emphasis>Toolbar</emphasis>.</para>"));
2491 toolBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2492 "<emphasis>Toolbar</emphasis>. It allows quick access to "
2493 "frequently used actions.</para><para>It is highly customizable. "
2494 "All items you see in the <interface>Control</interface> menu or "
2495 "in the <interface>Menubar</interface> can be placed on the "
2496 "Toolbar. Just right-click on it and select <interface>Configure "
2497 "Toolbars…</interface> or find this action in the <interface>"
2498 "Control</interface> or <interface>Settings</interface> menu."
2499 "</para><para>The location of the bar and the style of its "
2500 "buttons can also be changed in the right-click menu. Right-click "
2501 "a button if you want to show or hide its text.</para>"));
2502 m_tabWidget
->setWhatsThis(xi18nc("@info:whatsthis main view",
2503 "<para>Here you can see the <emphasis>folders</emphasis> and "
2504 "<emphasis>files</emphasis> that are at the location described in "
2505 "the <interface>Location Bar</interface> above. This area is the "
2506 "central part of this application where you navigate to the files "
2507 "you want to use.</para><para>For an elaborate and general "
2508 "introduction to this application <link "
2509 "url='https://userbase.kde.org/Dolphin/File_Management#Introduction_to_Dolphin'>"
2510 "click here</link>. This will open an introductory article from "
2511 "the <emphasis>KDE UserBase Wiki</emphasis>.</para><para>For brief "
2512 "explanations of all the features of this <emphasis>view</emphasis> "
2513 "<link url='help:/dolphin/dolphin-view.html'>click here</link> "
2514 "instead. This will open a page from the <emphasis>Handbook"
2515 "</emphasis> that covers the basics.</para>"));
2518 actionCollection()->action(KStandardAction::name(KStandardAction::KeyBindings
))
2519 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window "
2520 "that lists the <emphasis>keyboard shortcuts</emphasis>.<nl/>"
2521 "There you can set up key combinations to trigger an action when "
2522 "they are pressed simultaneously. All commands in this application can "
2523 "be triggered this way.</para>"));
2524 actionCollection()->action(KStandardAction::name(KStandardAction::ConfigureToolbars
))
2525 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window in which "
2526 "you can change which buttons appear on the <emphasis>Toolbar</emphasis>.</para>"
2527 "<para>All items you see in the <interface>Control</interface> menu "
2528 "or in the <interface>Menubar</interface> can also be placed on the Toolbar.</para>"));
2529 actionCollection()->action(KStandardAction::name(KStandardAction::Preferences
))
2530 ->setWhatsThis(xi18nc("@info:whatsthis","This opens a window where you can "
2531 "change a multitude of settings for this application. For an explanation "
2532 "of the various settings go to the chapter <emphasis>Configuring Dolphin"
2533 "</emphasis> in <interface>Help|Dolphin Handbook</interface>."));
2536 // The whatsthis has to be set for the m_helpMenu and for the
2537 // StandardAction separately because both are used in different locations.
2538 // m_helpMenu is only used for createControlButton() button.
2540 auto setStandardActionWhatsThis
= [this](KStandardAction::StandardAction actionId
,
2541 const QString
&whatsThis
) {
2542 if (auto *action
= actionCollection()->action(KStandardAction::name(actionId
))) {
2543 action
->setWhatsThis(whatsThis
);
2546 auto setHelpActionWhatsThis
= [this](KHelpMenu::MenuId menuId
, const QString
&whatsThis
) {
2547 if (auto *action
= m_helpMenu
->action(menuId
)) {
2548 action
->setWhatsThis(whatsThis
);
2552 // Links do not work within the Menubar so texts without links are provided there.
2554 // i18n: If the external link isn't available in your language you should
2555 // probably state the external link language at least in brackets to not
2556 // frustrate the user. If there are multiple languages that the user might
2557 // know with a reasonable chance you might want to have 2 external links.
2558 // The same is in my opinion true for every external link you translate.
2559 const QString whatsThisHelpContents
= xi18nc("@info:whatsthis handbook",
2560 "<para>This opens the Handbook for this application. It provides "
2561 "explanations for every part of <emphasis>Dolphin</emphasis>.</para>");
2562 setStandardActionWhatsThis(KStandardAction::HelpContents
, whatsThisHelpContents
2563 + xi18nc("@info:whatsthis second half of handbook hb text without link",
2564 "<para>If you want more elaborate introductions to the "
2565 "different features of <emphasis>Dolphin</emphasis> "
2566 "go to the KDE UserBase Wiki.</para>"));
2567 setHelpActionWhatsThis(KHelpMenu::menuHelpContents
, whatsThisHelpContents
2568 + xi18nc("@info:whatsthis second half of handbook text with link",
2569 "<para>If you want more elaborate introductions to the "
2570 "different features of <emphasis>Dolphin</emphasis> "
2571 "<link url='https://userbase.kde.org/Dolphin/File_Management'>click here</link>. "
2572 "It will open the dedicated page in the KDE UserBase Wiki.</para>"));
2574 const QString whatsThisWhatsThis
= xi18nc("@info:whatsthis whatsthis button",
2575 "<para>This is the button that invokes the help feature you are "
2576 "using right now! Click it, then click any component of this "
2577 "application to ask \"What's this?\" about it. The mouse cursor "
2578 "will change appearance if no help is available for a spot.</para>");
2579 setStandardActionWhatsThis(KStandardAction::WhatsThis
, whatsThisWhatsThis
2580 + xi18nc("@info:whatsthis second half of whatsthis button text without link",
2581 "<para>There are two other ways to get help for this application: The "
2582 "<interface>Dolphin Handbook</interface> in the <interface>Help"
2583 "</interface> menu and the <emphasis>KDE UserBase Wiki</emphasis> "
2584 "article about <emphasis>File Management</emphasis> online."
2585 "</para><para>The \"What's this?\" help is "
2586 "missing in most other windows so don't get too used to this.</para>"));
2587 setHelpActionWhatsThis(KHelpMenu::menuWhatsThis
, whatsThisWhatsThis
2588 + xi18nc("@info:whatsthis second half of whatsthis button text with link",
2589 "<para>There are two other ways to get help: "
2590 "The <link url='help:/dolphin/index.html'>Dolphin Handbook</link> and "
2591 "the <link url='https://userbase.kde.org/Dolphin/File_Management'>KDE "
2592 "UserBase Wiki</link>.</para><para>The \"What's this?\" help is "
2593 "missing in most other windows so don't get too used to this.</para>"));
2595 const QString whatsThisReportBug
= xi18nc("@info:whatsthis","<para>This opens a "
2596 "window that will guide you through reporting errors or flaws "
2597 "in this application or in other KDE software.</para>");
2598 setStandardActionWhatsThis(KStandardAction::ReportBug
, whatsThisReportBug
);
2599 setHelpActionWhatsThis(KHelpMenu::menuReportBug
, whatsThisReportBug
2600 + xi18nc("@info:whatsthis second half of reportbug text with link",
2601 "<para>High-quality bug reports are much appreciated. To learn "
2602 "how to make your bug report as effective as possible "
2603 "<link url='https://community.kde.org/Get_Involved/Bug_Reporting'>"
2604 "click here</link>.</para>"));
2606 const QString whatsThisDonate
= xi18nc("@info:whatsthis","<para>This opens a "
2607 "<emphasis>web page</emphasis> where you can donate to "
2608 "support the continued work on this application and many "
2609 "other projects by the <emphasis>KDE</emphasis> community.</para>"
2610 "<para>Donating is the easiest and fastest way to efficiently "
2611 "support KDE and its projects. KDE projects are available for "
2612 "free therefore your donation is needed to cover things that "
2613 "require money like servers, contributor meetings, etc.</para>"
2614 "<para><emphasis>KDE e.V.</emphasis> is the non-profit "
2615 "organization behind the KDE community.</para>");
2616 setStandardActionWhatsThis(KStandardAction::Donate
, whatsThisDonate
);
2617 setHelpActionWhatsThis(KHelpMenu::menuDonate
, whatsThisDonate
);
2619 const QString whatsThisSwitchLanguage
= xi18nc("@info:whatsthis",
2620 "With this you can change the language this application uses."
2621 "<nl/>You can even set secondary languages which will be used "
2622 "if texts are not available in your preferred language.");
2623 setStandardActionWhatsThis(KStandardAction::SwitchApplicationLanguage
,
2624 whatsThisSwitchLanguage
);
2625 setHelpActionWhatsThis(KHelpMenu::menuSwitchLanguage
, whatsThisSwitchLanguage
);
2627 const QString whatsThisAboutApp
= xi18nc("@info:whatsthis","This opens a "
2628 "window that informs you about the version, license, "
2629 "used libraries and maintainers of this application.");
2630 setStandardActionWhatsThis(KStandardAction::AboutApp
, whatsThisAboutApp
);
2631 setHelpActionWhatsThis(KHelpMenu::menuAboutApp
, whatsThisAboutApp
);
2633 const QString whatsThisAboutKDE
= xi18nc("@info:whatsthis","This opens a "
2634 "window with information about <emphasis>KDE</emphasis>. "
2635 "The KDE community are the people behind this free software."
2636 "<nl/>If you like using this application but don't know "
2637 "about KDE or want to see a cute dragon have a look!");
2638 setStandardActionWhatsThis(KStandardAction::AboutKDE
, whatsThisAboutKDE
);
2639 setHelpActionWhatsThis(KHelpMenu::menuAboutKDE
, whatsThisAboutKDE
);
2642 bool DolphinMainWindow::addHamburgerMenuToToolbar()
2644 QDomDocument domDocument
= KXMLGUIClient::domDocument();
2645 if (domDocument
.isNull()) {
2648 QDomNode toolbar
= domDocument
.elementsByTagName(QStringLiteral("ToolBar")).at(0);
2649 if (toolbar
.isNull()) {
2653 QDomElement hamburgerMenuElement
= domDocument
.createElement(QStringLiteral("Action"));
2654 hamburgerMenuElement
.setAttribute(QStringLiteral("name"), QStringLiteral("hamburger_menu"));
2655 toolbar
.appendChild(hamburgerMenuElement
);
2657 KXMLGUIFactory::saveConfigFile(domDocument
, xmlFile());
2661 // Make sure to also remove the <KXMLGUIFactory> and <QDomDocument> include
2662 // whenever this method is removed (maybe in the year ~2026).
2665 bool DolphinMainWindow::event(QEvent
*event
)
2667 if (event
->type() == QEvent::WhatsThisClicked
) {
2669 QWhatsThisClickedEvent
* whatsThisEvent
= dynamic_cast<QWhatsThisClickedEvent
*>(event
);
2670 QDesktopServices::openUrl(QUrl(whatsThisEvent
->href()));
2673 return KXmlGuiWindow::event(event
);
2676 bool DolphinMainWindow::eventFilter(QObject
* obj
, QEvent
* event
)
2679 if (event
->type() == QEvent::WhatsThisClicked
) {
2681 QWhatsThisClickedEvent
* whatsThisEvent
= dynamic_cast<QWhatsThisClickedEvent
*>(event
);
2682 QDesktopServices::openUrl(QUrl(whatsThisEvent
->href()));
2688 // Set a sane initial window size
2689 QSize
DolphinMainWindow::sizeHint() const
2691 return KXmlGuiWindow::sizeHint().expandedTo(QSize(760, 550));
2694 void DolphinMainWindow::saveNewToolbarConfig()
2696 KXmlGuiWindow::saveNewToolbarConfig(); // Applies the new config. This has to be called first
2697 // because the rest of this method decides things
2698 // based on the new config.
2699 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>
2700 (actionCollection()->action(QStringLiteral("url_navigators")));
2701 if (!toolBar()->actions().contains(navigators
)) {
2702 m_tabWidget
->currentTabPage()->insertNavigatorsWidget(navigators
);
2704 updateAllowedToolbarAreas();
2705 (static_cast<KHamburgerMenu
*>(actionCollection()->action(KStandardAction::name(
2706 KStandardAction::HamburgerMenu
))))->hideActionsOf(toolBar());
2709 void DolphinMainWindow::focusTerminalPanel()
2711 if (m_terminalPanel
->isVisible()) {
2712 if (m_terminalPanel
->terminalHasFocus()) {
2713 m_activeViewContainer
->view()->setFocus(Qt::FocusReason::ShortcutFocusReason
);
2714 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
2716 m_terminalPanel
->setFocus(Qt::FocusReason::ShortcutFocusReason
);
2717 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
2720 actionCollection()->action(QStringLiteral("show_terminal_panel"))->trigger();
2721 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
2725 DolphinMainWindow::UndoUiInterface::UndoUiInterface() :
2726 KIO::FileUndoManager::UiInterface()
2730 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
2734 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
* job
)
2736 DolphinMainWindow
* mainWin
= qobject_cast
<DolphinMainWindow
*>(parentWidget());
2738 DolphinViewContainer
* container
= mainWin
->activeViewContainer();
2739 container
->showMessage(job
->errorString(), DolphinViewContainer::Error
);
2741 KIO::FileUndoManager::UiInterface::jobError(job
);
2745 bool DolphinMainWindow::isUrlOpen(const QString
&url
)
2747 return m_tabWidget
->isUrlOpen(QUrl::fromUserInput(url
));
2750 bool DolphinMainWindow::isUrlOrParentOpen(const QString
&url
)
2752 return m_tabWidget
->isUrlOrParentOpen(QUrl::fromUserInput(url
));