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"
12 #include "config-terminal.h"
14 #include "dolphinbookmarkhandler.h"
15 #include "dolphindockwidget.h"
16 #include "dolphincontextmenu.h"
17 #include "dolphinnavigatorswidgetaction.h"
18 #include "dolphinnewfilemenu.h"
19 #include "dolphinrecenttabsmenu.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/placesitemmodel.h"
26 #include "panels/places/placespanel.h"
27 #include "panels/terminal/terminalpanel.h"
28 #include "settings/dolphinsettingsdialog.h"
29 #include "statusbar/dolphinstatusbar.h"
30 #include "views/dolphinviewactionhandler.h"
31 #include "views/dolphinremoteencoding.h"
32 #include "views/draganddrophelper.h"
33 #include "views/viewproperties.h"
34 #include "views/dolphinnewfilemenuobserver.h"
35 #include "dolphin_generalsettings.h"
37 #include <KActionCollection>
38 #include <KActionMenu>
39 #include <KAuthorized>
42 #include <KDualAction>
43 #include <KFileItemListProperties>
45 #include <KIO/CommandLauncherJob>
46 #include <KIO/JobUiDelegate>
47 #include <KIO/OpenFileManagerWindowJob>
48 #include <KIO/OpenUrlJob>
49 #include <KJobWidgets>
50 #include <KLocalizedString>
51 #include <KMessageBox>
52 #include <KNS3/KMoreToolsMenuFactory>
53 #include <KProtocolInfo>
54 #include <KProtocolManager>
56 #include <KStandardAction>
57 #include <KStartupInfo>
59 #include <KToggleAction>
61 #include <KToolBarPopupAction>
62 #include <KToolInvocation>
63 #include <KUrlComboBox>
64 #include <KUrlNavigator>
65 #include <KWindowSystem>
66 #include <KXMLGUIFactory>
68 #include <QApplication>
70 #include <QCloseEvent>
71 #include <QDesktopServices>
73 #include <QDomDocument>
77 #include <QPushButton>
79 #include <QStandardPaths>
81 #include <QToolButton>
82 #include <QWhatsThisClickedEvent>
85 // Used for GeneralSettings::version() to determine whether
86 // an updated version of Dolphin is running.
87 const int CurrentDolphinVersion
= 201;
88 // The maximum number of entries in the back/forward popup menu
89 const int MaxNumberOfNavigationentries
= 12;
90 // The maximum number of "Activate Tab" shortcuts
91 const int MaxActivateTabShortcuts
= 9;
94 DolphinMainWindow::DolphinMainWindow() :
95 KXmlGuiWindow(nullptr),
96 m_newFileMenu(nullptr),
99 m_activeViewContainer(nullptr),
100 m_actionHandler(nullptr),
101 m_remoteEncoding(nullptr),
103 m_bookmarkHandler(nullptr),
104 m_controlButton(nullptr),
105 m_updateToolBarTimer(nullptr),
106 m_lastHandleUrlOpenJob(nullptr),
107 m_terminalPanel(nullptr),
108 m_placesPanel(nullptr),
109 m_tearDownFromPlacesRequested(false),
110 m_backAction(nullptr),
111 m_forwardAction(nullptr)
113 Q_INIT_RESOURCE(dolphin
);
115 new MainWindowAdaptor(this);
118 setWindowFlags(Qt::WindowContextHelpButtonHint
);
120 setComponentName(QStringLiteral("dolphin"), QGuiApplication::applicationDisplayName());
121 setObjectName(QStringLiteral("Dolphin#"));
123 connect(&DolphinNewFileMenuObserver::instance(), &DolphinNewFileMenuObserver::errorMessage
,
124 this, &DolphinMainWindow::showErrorMessage
);
126 KIO::FileUndoManager
* undoManager
= KIO::FileUndoManager::self();
127 undoManager
->setUiInterface(new UndoUiInterface());
129 connect(undoManager
, QOverload
<bool>::of(&KIO::FileUndoManager::undoAvailable
),
130 this, &DolphinMainWindow::slotUndoAvailable
);
131 connect(undoManager
, &KIO::FileUndoManager::undoTextChanged
,
132 this, &DolphinMainWindow::slotUndoTextChanged
);
133 connect(undoManager
, &KIO::FileUndoManager::jobRecordingStarted
,
134 this, &DolphinMainWindow::clearStatusBar
);
135 connect(undoManager
, &KIO::FileUndoManager::jobRecordingFinished
,
136 this, &DolphinMainWindow::showCommand
);
138 const bool firstRun
= (GeneralSettings::version() < 200);
140 GeneralSettings::setViewPropsTimestamp(QDateTime::currentDateTime());
143 setAcceptDrops(true);
145 auto *navigatorsWidgetAction
= new DolphinNavigatorsWidgetAction(this);
146 actionCollection()->addAction(QStringLiteral("url_navigators"), navigatorsWidgetAction
);
147 m_tabWidget
= new DolphinTabWidget(navigatorsWidgetAction
, this);
148 m_tabWidget
->setObjectName("tabWidget");
149 connect(m_tabWidget
, &DolphinTabWidget::activeViewChanged
,
150 this, &DolphinMainWindow::activeViewChanged
);
151 connect(m_tabWidget
, &DolphinTabWidget::tabCountChanged
,
152 this, &DolphinMainWindow::tabCountChanged
);
153 connect(m_tabWidget
, &DolphinTabWidget::currentUrlChanged
,
154 this, &DolphinMainWindow::updateWindowTitle
);
155 setCentralWidget(m_tabWidget
);
159 m_actionHandler
= new DolphinViewActionHandler(actionCollection(), this);
160 connect(m_actionHandler
, &DolphinViewActionHandler::actionBeingHandled
, this, &DolphinMainWindow::clearStatusBar
);
161 connect(m_actionHandler
, &DolphinViewActionHandler::createDirectoryTriggered
, this, &DolphinMainWindow::createDirectory
);
163 m_remoteEncoding
= new DolphinRemoteEncoding(this, m_actionHandler
);
164 connect(this, &DolphinMainWindow::urlChanged
,
165 m_remoteEncoding
, &DolphinRemoteEncoding::slotAboutToOpenUrl
);
169 setupGUI(Keys
| Save
| Create
| ToolBar
);
170 stateChanged(QStringLiteral("new_file"));
172 QClipboard
* clipboard
= QApplication::clipboard();
173 connect(clipboard
, &QClipboard::dataChanged
,
174 this, &DolphinMainWindow::updatePasteAction
);
176 QAction
* toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
177 toggleFilterBarAction
->setChecked(GeneralSettings::filterBar());
180 menuBar()->setVisible(false);
181 // Assure a proper default size if Dolphin runs the first time
185 const bool showMenu
= !menuBar()->isHidden();
186 QAction
* showMenuBarAction
= actionCollection()->action(KStandardAction::name(KStandardAction::ShowMenubar
));
187 showMenuBarAction
->setChecked(showMenu
); // workaround for bug #171080
189 auto hamburgerMenu
= static_cast<KHamburgerMenu
*>(actionCollection()->action(
190 KStandardAction::name(KStandardAction::HamburgerMenu
)));
191 hamburgerMenu
->setMenuBar(menuBar());
192 hamburgerMenu
->setMenuBarAdvertised(false); // This line will soon be removed when the
193 // hamburger menu contents are re-arranged.
194 connect(hamburgerMenu
, &KHamburgerMenu::aboutToShowMenu
,
195 this, &DolphinMainWindow::updateHamburgerMenu
);
196 hamburgerMenu
->hideActionsOf(toolBar());
197 if (GeneralSettings::version() < 201 && !toolBar()->actions().contains(hamburgerMenu
)) {
198 addHamburgerMenuToToolbar();
201 updateAllowedToolbarAreas();
203 // enable middle-click on back/forward/up to open in a new tab
204 auto *middleClickEventFilter
= new MiddleClickActionEventFilter(this);
205 connect(middleClickEventFilter
, &MiddleClickActionEventFilter::actionMiddleClicked
, this, &DolphinMainWindow::slotToolBarActionMiddleClicked
);
206 toolBar()->installEventFilter(middleClickEventFilter
);
210 connect(KSycoca::self(), QOverload
<>::of(&KSycoca::databaseChanged
), this, &DolphinMainWindow::updateOpenPreferredSearchToolAction
);
212 QTimer::singleShot(0, this, &DolphinMainWindow::updateOpenPreferredSearchToolAction
);
215 DolphinMainWindow::~DolphinMainWindow()
219 QVector
<DolphinViewContainer
*> DolphinMainWindow::viewContainers() const
221 QVector
<DolphinViewContainer
*> viewContainers
;
223 for (int i
= 0; i
< m_tabWidget
->count(); ++i
) {
224 DolphinTabPage
*tabPage
= m_tabWidget
->tabPageAt(i
);
226 viewContainers
<< tabPage
->primaryViewContainer();
227 if (tabPage
->splitViewEnabled()) {
228 viewContainers
<< tabPage
->secondaryViewContainer();
231 return viewContainers
;
234 void DolphinMainWindow::setViewsWithInvalidPathsToHome()
236 const QVector
<DolphinViewContainer
*> theViewContainers
= viewContainers();
237 for (DolphinViewContainer
*viewContainer
: theViewContainers
) {
239 // Only consider local dirs, not remote locations and abstract protocols
240 if (viewContainer
->url().isLocalFile()) {
241 if (!QFileInfo::exists(viewContainer
->url().toLocalFile())) {
242 viewContainer
->setUrl(QUrl::fromLocalFile(QDir::homePath()));
248 void DolphinMainWindow::openDirectories(const QList
<QUrl
>& dirs
, bool splitView
)
250 m_tabWidget
->openDirectories(dirs
, splitView
);
253 void DolphinMainWindow::openDirectories(const QStringList
& dirs
, bool splitView
)
255 openDirectories(QUrl::fromStringList(dirs
), splitView
);
258 void DolphinMainWindow::openFiles(const QList
<QUrl
>& files
, bool splitView
)
260 m_tabWidget
->openFiles(files
, splitView
);
263 bool DolphinMainWindow::isFoldersPanelEnabled() const
265 return actionCollection()->action(QStringLiteral("show_folders_panel"))->isChecked();
268 bool DolphinMainWindow::isInformationPanelEnabled() const
271 return actionCollection()->action(QStringLiteral("show_information_panel"))->isChecked();
277 void DolphinMainWindow::openFiles(const QStringList
& files
, bool splitView
)
279 openFiles(QUrl::fromStringList(files
), splitView
);
282 void DolphinMainWindow::activateWindow()
284 window()->setAttribute(Qt::WA_NativeWindow
, true);
285 KStartupInfo::setNewStartupId(window()->windowHandle(), KStartupInfo::startupId());
286 KWindowSystem::activateWindow(window()->effectiveWinId());
289 void DolphinMainWindow::showCommand(CommandType command
)
291 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
293 case KIO::FileUndoManager::Copy
:
294 statusBar
->setText(i18nc("@info:status", "Successfully copied."));
296 case KIO::FileUndoManager::Move
:
297 statusBar
->setText(i18nc("@info:status", "Successfully moved."));
299 case KIO::FileUndoManager::Link
:
300 statusBar
->setText(i18nc("@info:status", "Successfully linked."));
302 case KIO::FileUndoManager::Trash
:
303 statusBar
->setText(i18nc("@info:status", "Successfully moved to trash."));
305 case KIO::FileUndoManager::Rename
:
306 statusBar
->setText(i18nc("@info:status", "Successfully renamed."));
309 case KIO::FileUndoManager::Mkdir
:
310 statusBar
->setText(i18nc("@info:status", "Created folder."));
318 void DolphinMainWindow::pasteIntoFolder()
320 m_activeViewContainer
->view()->pasteIntoFolder();
323 void DolphinMainWindow::changeUrl(const QUrl
&url
)
325 if (!KProtocolManager::supportsListing(url
)) {
326 // The URL navigator only checks for validity, not
327 // if the URL can be listed. An error message is
328 // shown due to DolphinViewContainer::restoreView().
332 m_activeViewContainer
->setUrl(url
);
333 updateFileAndEditActions();
338 Q_EMIT
urlChanged(url
);
341 void DolphinMainWindow::slotTerminalDirectoryChanged(const QUrl
& url
)
343 if (m_tearDownFromPlacesRequested
&& url
== QUrl::fromLocalFile(QDir::homePath())) {
344 m_placesPanel
->proceedWithTearDown();
345 m_tearDownFromPlacesRequested
= false;
348 m_activeViewContainer
->setAutoGrabFocus(false);
350 m_activeViewContainer
->setAutoGrabFocus(true);
353 void DolphinMainWindow::slotEditableStateChanged(bool editable
)
355 KToggleAction
* editableLocationAction
=
356 static_cast<KToggleAction
*>(actionCollection()->action(QStringLiteral("editable_location")));
357 editableLocationAction
->setChecked(editable
);
360 void DolphinMainWindow::slotSelectionChanged(const KFileItemList
& selection
)
362 updateFileAndEditActions();
364 const int selectedUrlsCount
= m_tabWidget
->currentTabPage()->selectedItemsCount();
366 QAction
* compareFilesAction
= actionCollection()->action(QStringLiteral("compare_files"));
367 if (selectedUrlsCount
== 2) {
368 compareFilesAction
->setEnabled(isKompareInstalled());
370 compareFilesAction
->setEnabled(false);
373 Q_EMIT
selectionChanged(selection
);
376 void DolphinMainWindow::updateHistory()
378 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
379 const int index
= urlNavigator
->historyIndex();
381 QAction
* backAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Back
));
383 backAction
->setToolTip(i18nc("@info", "Go back"));
384 backAction
->setWhatsThis(i18nc("@info:whatsthis go back", "Return to the previously viewed folder."));
385 backAction
->setEnabled(index
< urlNavigator
->historySize() - 1);
388 QAction
* forwardAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Forward
));
390 forwardAction
->setToolTip(i18nc("@info", "Go forward"));
391 forwardAction
->setWhatsThis(xi18nc("@info:whatsthis go forward",
392 "This undoes a <interface>Go|Back</interface> action."));
393 forwardAction
->setEnabled(index
> 0);
397 void DolphinMainWindow::updateFilterBarAction(bool show
)
399 QAction
* toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
400 toggleFilterBarAction
->setChecked(show
);
403 void DolphinMainWindow::openNewMainWindow()
405 Dolphin::openNewWindow({m_activeViewContainer
->url()}, this);
408 void DolphinMainWindow::openNewActivatedTab()
410 // keep browsers compatibility, new tab is always after last one
411 auto openNewTabAfterLastTabConfigured
= GeneralSettings::openNewTabAfterLastTab();
412 GeneralSettings::setOpenNewTabAfterLastTab(true);
413 m_tabWidget
->openNewActivatedTab();
414 GeneralSettings::setOpenNewTabAfterLastTab(openNewTabAfterLastTabConfigured
);
417 void DolphinMainWindow::addToPlaces()
422 // If nothing is selected, act on the current dir
423 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
424 url
= m_activeViewContainer
->url();
425 name
= m_activeViewContainer
->placesText();
427 const auto dirToAdd
= m_activeViewContainer
->view()->selectedItems().first();
428 url
= dirToAdd
.url();
429 name
= dirToAdd
.name();
432 PlacesItemModel model
;
434 if (m_activeViewContainer
->isSearchModeEnabled()) {
435 icon
= QStringLiteral("folder-saved-search-symbolic");
437 icon
= KIO::iconNameForUrl(url
);
439 model
.createPlacesItem(name
, url
, icon
);
443 void DolphinMainWindow::openNewTab(const QUrl
& url
)
445 m_tabWidget
->openNewTab(url
, QUrl());
448 void DolphinMainWindow::openInNewTab()
450 const KFileItemList
& list
= m_activeViewContainer
->view()->selectedItems();
451 bool tabCreated
= false;
453 for (const KFileItem
& item
: list
) {
454 const QUrl
& url
= DolphinView::openItemAsFolderUrl(item
);
455 if (!url
.isEmpty()) {
461 // if no new tab has been created from the selection
462 // open the current directory in a new tab
464 openNewTab(m_activeViewContainer
->url());
468 void DolphinMainWindow::openInNewWindow()
472 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
473 if (list
.isEmpty()) {
474 newWindowUrl
= m_activeViewContainer
->url();
475 } else if (list
.count() == 1) {
476 const KFileItem
& item
= list
.first();
477 newWindowUrl
= DolphinView::openItemAsFolderUrl(item
);
480 if (!newWindowUrl
.isEmpty()) {
481 Dolphin::openNewWindow({newWindowUrl
}, this);
485 void DolphinMainWindow::showTarget()
487 const auto link
= m_activeViewContainer
->view()->selectedItems().at(0);
488 const auto linkLocationDir
= QFileInfo(link
.localPath()).absoluteDir();
489 auto linkDestination
= link
.linkDest();
490 if (QFileInfo(linkDestination
).isRelative()) {
491 linkDestination
= linkLocationDir
.filePath(linkDestination
);
493 if (QFileInfo::exists(linkDestination
)) {
494 KIO::highlightInFileManager({QUrl::fromLocalFile(linkDestination
).adjusted(QUrl::StripTrailingSlash
)});
496 m_activeViewContainer
->showMessage(xi18nc("@info", "Could not access <filename>%1</filename>.", linkDestination
),
497 DolphinViewContainer::Warning
);
501 void DolphinMainWindow::showEvent(QShowEvent
* event
)
503 KXmlGuiWindow::showEvent(event
);
505 if (!event
->spontaneous()) {
506 m_activeViewContainer
->view()->setFocus();
510 void DolphinMainWindow::closeEvent(QCloseEvent
* event
)
512 // Find out if Dolphin is closed directly by the user or
513 // by the session manager because the session is closed
514 bool closedByUser
= true;
515 if (qApp
->isSavingSession()) {
516 closedByUser
= false;
519 if (m_tabWidget
->count() > 1
520 && GeneralSettings::confirmClosingMultipleTabs()
521 && !GeneralSettings::rememberOpenedTabs()
523 // Ask the user if he really wants to quit and close all tabs.
524 // Open a confirmation dialog with 3 buttons:
525 // QDialogButtonBox::Yes -> Quit
526 // QDialogButtonBox::No -> Close only the current tab
527 // QDialogButtonBox::Cancel -> do nothing
528 QDialog
*dialog
= new QDialog(this, Qt::Dialog
);
529 dialog
->setWindowTitle(i18nc("@title:window", "Confirmation"));
530 dialog
->setModal(true);
531 QDialogButtonBox
* buttons
= new QDialogButtonBox(QDialogButtonBox::Yes
| QDialogButtonBox::No
| QDialogButtonBox::Cancel
);
532 KGuiItem::assign(buttons
->button(QDialogButtonBox::Yes
), KGuiItem(i18nc("@action:button 'Quit Dolphin' button", "&Quit %1", QGuiApplication::applicationDisplayName()), QIcon::fromTheme(QStringLiteral("application-exit"))));
533 KGuiItem::assign(buttons
->button(QDialogButtonBox::No
), KGuiItem(i18n("C&lose Current Tab"), QIcon::fromTheme(QStringLiteral("tab-close"))));
534 KGuiItem::assign(buttons
->button(QDialogButtonBox::Cancel
), KStandardGuiItem::cancel());
535 buttons
->button(QDialogButtonBox::Yes
)->setDefault(true);
537 bool doNotAskAgainCheckboxResult
= false;
539 const auto result
= KMessageBox::createKMessageBox(dialog
,
541 QMessageBox::Warning
,
542 i18n("You have multiple tabs open in this window, are you sure you want to quit?"),
544 i18n("Do not ask again"),
545 &doNotAskAgainCheckboxResult
,
546 KMessageBox::Notify
);
548 if (doNotAskAgainCheckboxResult
) {
549 GeneralSettings::setConfirmClosingMultipleTabs(false);
553 case QDialogButtonBox::Yes
:
556 case QDialogButtonBox::No
:
557 // Close only the current tab
558 m_tabWidget
->closeTab();
566 if (m_terminalPanel
&& m_terminalPanel
->hasProgramRunning() && GeneralSettings::confirmClosingTerminalRunningProgram() && closedByUser
) {
567 // Ask if the user really wants to quit Dolphin with a program that is still running in the Terminal panel
568 // Open a confirmation dialog with 3 buttons:
569 // QDialogButtonBox::Yes -> Quit
570 // QDialogButtonBox::No -> Show Terminal Panel
571 // QDialogButtonBox::Cancel -> do nothing
572 QDialog
*dialog
= new QDialog(this, Qt::Dialog
);
573 dialog
->setWindowTitle(i18nc("@title:window", "Confirmation"));
574 dialog
->setModal(true);
575 auto standardButtons
= QDialogButtonBox::Yes
| QDialogButtonBox::Cancel
;
576 if (!m_terminalPanel
->isVisible()) {
577 standardButtons
|= QDialogButtonBox::No
;
579 QDialogButtonBox
*buttons
= new QDialogButtonBox(standardButtons
);
580 KGuiItem::assign(buttons
->button(QDialogButtonBox::Yes
), KStandardGuiItem::quit());
581 if (!m_terminalPanel
->isVisible()) {
583 buttons
->button(QDialogButtonBox::No
),
584 KGuiItem(i18n("Show &Terminal Panel"), QIcon::fromTheme(QStringLiteral("dialog-scripts"))));
586 KGuiItem::assign(buttons
->button(QDialogButtonBox::Cancel
), KStandardGuiItem::cancel());
588 bool doNotAskAgainCheckboxResult
= false;
590 const auto result
= KMessageBox::createKMessageBox(
593 QMessageBox::Warning
,
594 i18n("The program '%1' is still running in the Terminal panel. Are you sure you want to quit?", m_terminalPanel
->runningProgramName()),
596 i18n("Do not ask again"),
597 &doNotAskAgainCheckboxResult
,
598 KMessageBox::Dangerous
);
600 if (doNotAskAgainCheckboxResult
) {
601 GeneralSettings::setConfirmClosingTerminalRunningProgram(false);
605 case QDialogButtonBox::Yes
:
608 case QDialogButtonBox::No
:
609 actionCollection()->action("show_terminal_panel")->trigger();
610 // Do not quit, ignore quit event
618 if (GeneralSettings::rememberOpenedTabs()) {
619 KConfigGui::setSessionConfig(QStringLiteral("dolphin"), QStringLiteral("dolphin"));
620 KConfig
*config
= KConfigGui::sessionConfig();
621 saveGlobalProperties(config
);
622 savePropertiesInternal(config
, 1);
626 GeneralSettings::setVersion(CurrentDolphinVersion
);
627 GeneralSettings::self()->save();
629 KXmlGuiWindow::closeEvent(event
);
632 void DolphinMainWindow::saveProperties(KConfigGroup
& group
)
634 m_tabWidget
->saveProperties(group
);
637 void DolphinMainWindow::readProperties(const KConfigGroup
& group
)
639 m_tabWidget
->readProperties(group
);
642 void DolphinMainWindow::updateNewMenu()
644 m_newFileMenu
->setViewShowsHiddenFiles(activeViewContainer()->view()->hiddenFilesShown());
645 m_newFileMenu
->checkUpToDate();
646 m_newFileMenu
->setPopupFiles(QList
<QUrl
>() << activeViewContainer()->url());
649 void DolphinMainWindow::createDirectory()
651 m_newFileMenu
->setViewShowsHiddenFiles(activeViewContainer()->view()->hiddenFilesShown());
652 m_newFileMenu
->setPopupFiles(QList
<QUrl
>() << activeViewContainer()->url());
653 m_newFileMenu
->createDirectory();
656 void DolphinMainWindow::quit()
661 void DolphinMainWindow::showErrorMessage(const QString
& message
)
663 m_activeViewContainer
->showMessage(message
, DolphinViewContainer::Error
);
666 void DolphinMainWindow::slotUndoAvailable(bool available
)
668 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
670 undoAction
->setEnabled(available
);
674 void DolphinMainWindow::slotUndoTextChanged(const QString
& text
)
676 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
678 undoAction
->setText(text
);
682 void DolphinMainWindow::undo()
685 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
686 KIO::FileUndoManager::self()->undo();
689 void DolphinMainWindow::cut()
691 m_activeViewContainer
->view()->cutSelectedItemsToClipboard();
694 void DolphinMainWindow::copy()
696 m_activeViewContainer
->view()->copySelectedItemsToClipboard();
699 void DolphinMainWindow::paste()
701 m_activeViewContainer
->view()->paste();
704 void DolphinMainWindow::find()
706 m_activeViewContainer
->setSearchModeEnabled(true);
709 void DolphinMainWindow::updateSearchAction()
711 QAction
* toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
712 toggleSearchAction
->setChecked(m_activeViewContainer
->isSearchModeEnabled());
715 void DolphinMainWindow::updatePasteAction()
717 QAction
* pasteAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Paste
));
718 QPair
<bool, QString
> pasteInfo
= m_activeViewContainer
->view()->pasteInfo();
719 pasteAction
->setEnabled(pasteInfo
.first
);
720 pasteAction
->setText(pasteInfo
.second
);
723 void DolphinMainWindow::slotDirectoryLoadingCompleted()
728 void DolphinMainWindow::slotToolBarActionMiddleClicked(QAction
*action
)
730 if (action
== actionCollection()->action(KStandardAction::name(KStandardAction::Back
))) {
732 } else if (action
== actionCollection()->action(KStandardAction::name(KStandardAction::Forward
))) {
734 } else if (action
== actionCollection()->action(QStringLiteral("go_up"))) {
736 } else if (action
== actionCollection()->action(QStringLiteral("go_home"))) {
741 void DolphinMainWindow::slotAboutToShowBackPopupMenu()
743 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
745 m_backAction
->menu()->clear();
746 for (int i
= urlNavigator
->historyIndex() + 1; i
< urlNavigator
->historySize() && entries
< MaxNumberOfNavigationentries
; ++i
, ++entries
) {
747 QAction
* action
= new QAction(urlNavigator
->locationUrl(i
).toString(QUrl::PreferLocalFile
), m_backAction
->menu());
749 m_backAction
->menu()->addAction(action
);
753 void DolphinMainWindow::slotGoBack(QAction
* action
)
755 int gotoIndex
= action
->data().value
<int>();
756 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
757 for (int i
= gotoIndex
- urlNavigator
->historyIndex(); i
> 0; --i
) {
762 void DolphinMainWindow::slotBackForwardActionMiddleClicked(QAction
* action
)
765 const KUrlNavigator
*urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
766 openNewTab(urlNavigator
->locationUrl(action
->data().value
<int>()));
770 void DolphinMainWindow::slotAboutToShowForwardPopupMenu()
772 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
774 m_forwardAction
->menu()->clear();
775 for (int i
= urlNavigator
->historyIndex() - 1; i
>= 0 && entries
< MaxNumberOfNavigationentries
; --i
, ++entries
) {
776 QAction
* action
= new QAction(urlNavigator
->locationUrl(i
).toString(QUrl::PreferLocalFile
), m_forwardAction
->menu());
778 m_forwardAction
->menu()->addAction(action
);
782 void DolphinMainWindow::slotGoForward(QAction
* action
)
784 int gotoIndex
= action
->data().value
<int>();
785 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
786 for (int i
= urlNavigator
->historyIndex() - gotoIndex
; i
> 0; --i
) {
791 void DolphinMainWindow::selectAll()
795 // if the URL navigator is editable and focused, select the whole
796 // URL instead of all items of the view
798 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
799 QLineEdit
* lineEdit
= urlNavigator
->editor()->lineEdit();
800 const bool selectUrl
= urlNavigator
->isUrlEditable() &&
801 lineEdit
->hasFocus();
803 lineEdit
->selectAll();
805 m_activeViewContainer
->view()->selectAll();
809 void DolphinMainWindow::invertSelection()
812 m_activeViewContainer
->view()->invertSelection();
815 void DolphinMainWindow::toggleSplitView()
817 DolphinTabPage
* tabPage
= m_tabWidget
->currentTabPage();
818 tabPage
->setSplitViewEnabled(!tabPage
->splitViewEnabled(), WithAnimation
);
823 void DolphinMainWindow::toggleSplitStash()
825 DolphinTabPage
* tabPage
= m_tabWidget
->currentTabPage();
826 tabPage
->setSplitViewEnabled(false, WithAnimation
);
827 tabPage
->setSplitViewEnabled(true, WithAnimation
, QUrl("stash:/"));
830 void DolphinMainWindow::reloadView()
833 m_activeViewContainer
->reload();
834 m_activeViewContainer
->statusBar()->updateSpaceInfo();
837 void DolphinMainWindow::stopLoading()
839 m_activeViewContainer
->view()->stopLoading();
842 void DolphinMainWindow::enableStopAction()
844 actionCollection()->action(QStringLiteral("stop"))->setEnabled(true);
847 void DolphinMainWindow::disableStopAction()
849 actionCollection()->action(QStringLiteral("stop"))->setEnabled(false);
852 void DolphinMainWindow::showFilterBar()
854 m_activeViewContainer
->setFilterBarVisible(true);
857 void DolphinMainWindow::toggleFilterBar()
859 const bool checked
= !m_activeViewContainer
->isFilterBarVisible();
860 m_activeViewContainer
->setFilterBarVisible(checked
);
862 QAction
* toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
863 toggleFilterBarAction
->setChecked(checked
);
866 void DolphinMainWindow::toggleEditLocation()
870 QAction
* action
= actionCollection()->action(QStringLiteral("editable_location"));
871 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
872 urlNavigator
->setUrlEditable(action
->isChecked());
875 void DolphinMainWindow::replaceLocation()
877 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
878 QLineEdit
* lineEdit
= navigator
->editor()->lineEdit();
880 // If the text field currently has focus and everything is selected,
881 // pressing the keyboard shortcut returns the whole thing to breadcrumb mode
882 if (navigator
->isUrlEditable()
883 && lineEdit
->hasFocus()
884 && lineEdit
->selectedText() == lineEdit
->text() ) {
885 navigator
->setUrlEditable(false);
887 navigator
->setUrlEditable(true);
888 navigator
->setFocus();
889 lineEdit
->selectAll();
893 void DolphinMainWindow::togglePanelLockState()
895 const bool newLockState
= !GeneralSettings::lockPanels();
896 const auto childrenObjects
= children();
897 for (QObject
* child
: childrenObjects
) {
898 DolphinDockWidget
* dock
= qobject_cast
<DolphinDockWidget
*>(child
);
900 dock
->setLocked(newLockState
);
904 GeneralSettings::setLockPanels(newLockState
);
907 void DolphinMainWindow::slotTerminalPanelVisibilityChanged()
909 if (m_terminalPanel
->isHiddenInVisibleWindow() && m_activeViewContainer
) {
910 m_activeViewContainer
->view()->setFocus();
914 void DolphinMainWindow::goBack()
916 DolphinUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
917 urlNavigator
->goBack();
919 if (urlNavigator
->locationState().isEmpty()) {
920 // An empty location state indicates a redirection URL,
921 // which must be skipped too
922 urlNavigator
->goBack();
926 void DolphinMainWindow::goForward()
928 m_activeViewContainer
->urlNavigatorInternalWithHistory()->goForward();
931 void DolphinMainWindow::goUp()
933 m_activeViewContainer
->urlNavigatorInternalWithHistory()->goUp();
936 void DolphinMainWindow::goHome()
938 m_activeViewContainer
->urlNavigatorInternalWithHistory()->goHome();
941 void DolphinMainWindow::goBackInNewTab()
943 const KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
944 const int index
= urlNavigator
->historyIndex() + 1;
945 openNewTab(urlNavigator
->locationUrl(index
));
948 void DolphinMainWindow::goForwardInNewTab()
950 const KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
951 const int index
= urlNavigator
->historyIndex() - 1;
952 openNewTab(urlNavigator
->locationUrl(index
));
955 void DolphinMainWindow::goUpInNewTab()
957 const QUrl currentUrl
= activeViewContainer()->urlNavigator()->locationUrl();
958 openNewTab(KIO::upUrl(currentUrl
));
961 void DolphinMainWindow::goHomeInNewTab()
963 openNewTab(Dolphin::homeUrl());
966 void DolphinMainWindow::compareFiles()
968 const KFileItemList items
= m_tabWidget
->currentTabPage()->selectedItems();
969 if (items
.count() != 2) {
970 // The action is disabled in this case, but it could have been triggered
971 // via D-Bus, see https://bugs.kde.org/show_bug.cgi?id=325517
975 QUrl urlA
= items
.at(0).url();
976 QUrl urlB
= items
.at(1).url();
978 QString
command(QStringLiteral("kompare -c \""));
979 command
.append(urlA
.toDisplayString(QUrl::PreferLocalFile
));
980 command
.append("\" \"");
981 command
.append(urlB
.toDisplayString(QUrl::PreferLocalFile
));
982 command
.append('\"');
984 KIO::CommandLauncherJob
*job
= new KIO::CommandLauncherJob(command
, this);
985 job
->setDesktopName(QStringLiteral("org.kde.kompare"));
989 void DolphinMainWindow::toggleShowMenuBar()
991 const bool visible
= menuBar()->isVisible();
992 menuBar()->setVisible(!visible
);
995 QPointer
<QAction
> DolphinMainWindow::preferredSearchTool()
997 m_searchTools
.clear();
998 KMoreToolsMenuFactory("dolphin/search-tools").fillMenuFromGroupingNames(
999 &m_searchTools
, { "files-find" }, m_activeViewContainer
->url()
1001 QList
<QAction
*> actions
= m_searchTools
.actions();
1002 if (actions
.isEmpty()) {
1005 QAction
* action
= actions
.first();
1006 if (action
->isSeparator()) {
1012 void DolphinMainWindow::updateOpenPreferredSearchToolAction()
1014 QAction
* openPreferredSearchTool
= actionCollection()->action(QStringLiteral("open_preferred_search_tool"));
1015 if (!openPreferredSearchTool
) {
1018 QPointer
<QAction
> tool
= preferredSearchTool();
1020 openPreferredSearchTool
->setVisible(true);
1021 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open %1", tool
->text()));
1022 openPreferredSearchTool
->setIcon(tool
->icon());
1024 openPreferredSearchTool
->setVisible(false);
1025 // still visible in Shortcuts configuration window
1026 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool"));
1027 openPreferredSearchTool
->setIcon(QIcon::fromTheme(QStringLiteral("search")));
1031 void DolphinMainWindow::openPreferredSearchTool()
1033 QPointer
<QAction
> tool
= preferredSearchTool();
1039 void DolphinMainWindow::openTerminal()
1041 const QUrl url
= m_activeViewContainer
->url();
1043 if (url
.isLocalFile()) {
1044 KToolInvocation::invokeTerminal(QString(), {}, url
.toLocalFile());
1048 // Not a local file, with protocol Class ":local", try stat'ing
1049 if (KProtocolInfo::protocolClass(url
.scheme()) == QLatin1String(":local")) {
1050 KIO::StatJob
*job
= KIO::mostLocalUrl(url
);
1051 KJobWidgets::setWindow(job
, this);
1052 connect(job
, &KJob::result
, this, [job
]() {
1054 if (!job
->error()) {
1055 statUrl
= job
->mostLocalUrl();
1058 KToolInvocation::invokeTerminal(QString(), {}, statUrl
.isLocalFile() ? statUrl
.toLocalFile() : QDir::homePath());
1064 // Nothing worked, just use $HOME
1065 KToolInvocation::invokeTerminal(QString(), {}, QDir::homePath());
1068 void DolphinMainWindow::editSettings()
1070 if (!m_settingsDialog
) {
1071 DolphinViewContainer
* container
= activeViewContainer();
1072 container
->view()->writeSettings();
1074 const QUrl url
= container
->url();
1075 DolphinSettingsDialog
* settingsDialog
= new DolphinSettingsDialog(url
, this, actionCollection());
1076 connect(settingsDialog
, &DolphinSettingsDialog::settingsChanged
, this, &DolphinMainWindow::refreshViews
);
1077 connect(settingsDialog
, &DolphinSettingsDialog::settingsChanged
,
1078 &DolphinUrlNavigatorsController::slotReadSettings
);
1079 settingsDialog
->setAttribute(Qt::WA_DeleteOnClose
);
1080 settingsDialog
->show();
1081 m_settingsDialog
= settingsDialog
;
1083 m_settingsDialog
.data()->raise();
1087 void DolphinMainWindow::handleUrl(const QUrl
& url
)
1089 delete m_lastHandleUrlOpenJob
;
1090 m_lastHandleUrlOpenJob
= nullptr;
1092 if (url
.isLocalFile() && QFileInfo(url
.toLocalFile()).isDir()) {
1093 activeViewContainer()->setUrl(url
);
1095 m_lastHandleUrlOpenJob
= new KIO::OpenUrlJob(url
);
1096 m_lastHandleUrlOpenJob
->setUiDelegate(new KIO::JobUiDelegate(KJobUiDelegate::AutoHandlingEnabled
, this));
1097 m_lastHandleUrlOpenJob
->setShowOpenOrExecuteDialog(true);
1099 connect(m_lastHandleUrlOpenJob
, &KIO::OpenUrlJob::mimeTypeFound
, this,
1100 [this, url
](const QString
&mimetype
) {
1101 if (mimetype
== QLatin1String("inode/directory")) {
1102 // If it's a dir, we'll take it from here
1103 m_lastHandleUrlOpenJob
->kill();
1104 m_lastHandleUrlOpenJob
= nullptr;
1105 activeViewContainer()->setUrl(url
);
1109 connect(m_lastHandleUrlOpenJob
, &KIO::OpenUrlJob::result
, this, [this]() {
1110 m_lastHandleUrlOpenJob
= nullptr;
1113 m_lastHandleUrlOpenJob
->start();
1117 void DolphinMainWindow::slotWriteStateChanged(bool isFolderWritable
)
1119 // trash:/ is writable but we don't want to create new items in it.
1120 // TODO: remove the trash check once https://phabricator.kde.org/T8234 is implemented
1121 newFileMenu()->setEnabled(isFolderWritable
&& m_activeViewContainer
->url().scheme() != QLatin1String("trash"));
1124 void DolphinMainWindow::openContextMenu(const QPoint
& pos
,
1125 const KFileItem
& item
,
1127 const QList
<QAction
*>& customActions
)
1129 QPointer
<DolphinContextMenu
> contextMenu
= new DolphinContextMenu(this, pos
, item
, url
);
1130 contextMenu
.data()->setCustomActions(customActions
);
1131 const DolphinContextMenu::Command command
= contextMenu
.data()->open();
1134 case DolphinContextMenu::OpenParentFolder
:
1135 changeUrl(KIO::upUrl(item
.url()));
1136 m_activeViewContainer
->view()->markUrlsAsSelected({item
.url()});
1137 m_activeViewContainer
->view()->markUrlAsCurrent(item
.url());
1140 case DolphinContextMenu::OpenParentFolderInNewWindow
:
1141 Dolphin::openNewWindow({item
.url()}, this, Dolphin::OpenNewWindowFlag::Select
);
1144 case DolphinContextMenu::OpenParentFolderInNewTab
:
1145 openNewTab(KIO::upUrl(item
.url()));
1148 case DolphinContextMenu::None
:
1153 // Delete the menu, unless it has been deleted in its own nested event loop already.
1155 contextMenu
->deleteLater();
1159 void DolphinMainWindow::updateHamburgerMenu()
1161 KActionCollection
* ac
= actionCollection();
1162 auto hamburgerMenu
= static_cast<KHamburgerMenu
*>(
1163 ac
->action(KStandardAction::name(KStandardAction::HamburgerMenu
)));
1164 auto menu
= hamburgerMenu
->menu();
1166 menu
= new QMenu(this);
1167 hamburgerMenu
->setMenu(menu
);
1172 menu
->addMenu(m_newFileMenu
->menu());
1173 menu
->addAction(ac
->action(QStringLiteral("file_new")));
1174 menu
->addAction(ac
->action(QStringLiteral("new_tab")));
1175 menu
->addAction(ac
->action(QStringLiteral("closed_tabs")));
1177 menu
->addSeparator();
1179 // Add "Edit" actions
1180 menu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Undo
)));
1181 menu
->addAction(ac
->action(QString("copy_location")));
1182 menu
->addAction(ac
->action(QStringLiteral("copy_to_inactive_split_view")));
1183 menu
->addAction(ac
->action(QStringLiteral("move_to_inactive_split_view")));
1184 menu
->addAction(ac
->action(KStandardAction::name(KStandardAction::SelectAll
)));
1185 menu
->addAction(ac
->action(QStringLiteral("invert_selection")));
1187 menu
->addSeparator();
1189 // Add "View" actions
1190 if (!GeneralSettings::showZoomSlider()) {
1191 menu
->addAction(ac
->action(KStandardAction::name(KStandardAction::ZoomIn
)));
1192 menu
->addAction(ac
->action(QStringLiteral("view_zoom_reset")));
1193 menu
->addAction(ac
->action(KStandardAction::name(KStandardAction::ZoomOut
)));
1194 menu
->addSeparator();
1197 menu
->addAction(ac
->action(QStringLiteral("show_preview")));
1198 menu
->addAction(ac
->action(QStringLiteral("show_in_groups")));
1199 menu
->addAction(ac
->action(QStringLiteral("show_hidden_files")));
1200 menu
->addAction(ac
->action(QStringLiteral("additional_info")));
1201 menu
->addAction(ac
->action(QStringLiteral("view_properties")));
1203 menu
->addSeparator();
1205 // Add a curated assortment of items from the "Tools" menu
1206 menu
->addAction(ac
->action(QStringLiteral("show_filter_bar")));
1207 menu
->addAction(ac
->action(QStringLiteral("open_preferred_search_tool")));
1208 menu
->addAction(ac
->action(QStringLiteral("open_terminal")));
1210 menu
->addSeparator();
1212 // Add "Show Panels" menu
1213 menu
->addAction(ac
->action(QStringLiteral("panels")));
1215 // Add "Settings" menu entries
1216 menu
->addAction(ac
->action(KStandardAction::name(KStandardAction::KeyBindings
)));
1217 menu
->addAction(ac
->action(KStandardAction::name(KStandardAction::ConfigureToolbars
)));
1218 menu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Preferences
)));
1219 menu
->addAction(ac
->action(KStandardAction::name(KStandardAction::ShowMenubar
)));
1222 void DolphinMainWindow::slotPlaceActivated(const QUrl
& url
)
1224 DolphinViewContainer
* view
= activeViewContainer();
1226 if (view
->url() == url
) {
1227 // We can end up here if the user clicked a device in the Places Panel
1228 // which had been unmounted earlier, see https://bugs.kde.org/show_bug.cgi?id=161385.
1231 view
->disableUrlNavigatorSelectionRequests();
1233 view
->enableUrlNavigatorSelectionRequests();
1237 void DolphinMainWindow::closedTabsCountChanged(unsigned int count
)
1239 actionCollection()->action(QStringLiteral("undo_close_tab"))->setEnabled(count
> 0);
1242 void DolphinMainWindow::activeViewChanged(DolphinViewContainer
* viewContainer
)
1244 DolphinViewContainer
* oldViewContainer
= m_activeViewContainer
;
1245 Q_ASSERT(viewContainer
);
1247 m_activeViewContainer
= viewContainer
;
1249 if (oldViewContainer
) {
1250 const QAction
* toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
1251 toggleSearchAction
->disconnect(oldViewContainer
);
1253 // Disconnect all signals between the old view container (container,
1254 // view and url navigator) and main window.
1255 oldViewContainer
->disconnect(this);
1256 oldViewContainer
->view()->disconnect(this);
1257 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>
1258 (actionCollection()->action(QStringLiteral("url_navigators")));
1259 navigators
->primaryUrlNavigator()->disconnect(this);
1260 if (auto secondaryUrlNavigator
= navigators
->secondaryUrlNavigator()) {
1261 secondaryUrlNavigator
->disconnect(this);
1264 // except the requestItemInfo so that on hover the information panel can still be updated
1265 connect(oldViewContainer
->view(), &DolphinView::requestItemInfo
,
1266 this, &DolphinMainWindow::requestItemInfo
);
1269 connectViewSignals(viewContainer
);
1271 m_actionHandler
->setCurrentView(viewContainer
->view());
1274 updateFileAndEditActions();
1275 updatePasteAction();
1276 updateViewActions();
1278 updateSearchAction();
1280 const QUrl url
= viewContainer
->url();
1281 Q_EMIT
urlChanged(url
);
1284 void DolphinMainWindow::tabCountChanged(int count
)
1286 const bool enableTabActions
= (count
> 1);
1287 for (int i
= 0; i
< MaxActivateTabShortcuts
; ++i
) {
1288 actionCollection()->action(QStringLiteral("activate_tab_%1").arg(i
))->setEnabled(enableTabActions
);
1290 actionCollection()->action(QStringLiteral("activate_last_tab"))->setEnabled(enableTabActions
);
1291 actionCollection()->action(QStringLiteral("activate_next_tab"))->setEnabled(enableTabActions
);
1292 actionCollection()->action(QStringLiteral("activate_prev_tab"))->setEnabled(enableTabActions
);
1295 void DolphinMainWindow::updateWindowTitle()
1297 const QString newTitle
= m_activeViewContainer
->captionWindowTitle();
1298 if (windowTitle() != newTitle
) {
1299 setWindowTitle(newTitle
);
1303 void DolphinMainWindow::slotStorageTearDownFromPlacesRequested(const QString
& mountPath
)
1305 connect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, this, [this, mountPath
]() {
1306 setViewsToHomeIfMountPathOpen(mountPath
);
1309 if (m_terminalPanel
&& m_terminalPanel
->currentWorkingDirectory().startsWith(mountPath
)) {
1310 m_tearDownFromPlacesRequested
= true;
1311 m_terminalPanel
->goHome();
1312 // m_placesPanel->proceedWithTearDown() will be called in slotTerminalDirectoryChanged
1314 m_placesPanel
->proceedWithTearDown();
1318 void DolphinMainWindow::slotStorageTearDownExternallyRequested(const QString
& mountPath
)
1320 connect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, this, [this, mountPath
]() {
1321 setViewsToHomeIfMountPathOpen(mountPath
);
1324 if (m_terminalPanel
&& m_terminalPanel
->currentWorkingDirectory().startsWith(mountPath
)) {
1325 m_tearDownFromPlacesRequested
= false;
1326 m_terminalPanel
->goHome();
1330 void DolphinMainWindow::setViewsToHomeIfMountPathOpen(const QString
& mountPath
)
1332 const QVector
<DolphinViewContainer
*> theViewContainers
= viewContainers();
1333 for (DolphinViewContainer
*viewContainer
: theViewContainers
) {
1334 if (viewContainer
&& viewContainer
->url().toLocalFile().startsWith(mountPath
)) {
1335 viewContainer
->setUrl(QUrl::fromLocalFile(QDir::homePath()));
1338 disconnect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, nullptr, nullptr);
1341 void DolphinMainWindow::setupActions()
1343 KStandardAction::hamburgerMenu(nullptr, nullptr, actionCollection());
1345 // setup 'File' menu
1346 m_newFileMenu
= new DolphinNewFileMenu(actionCollection(), this);
1347 QMenu
* menu
= m_newFileMenu
->menu();
1348 menu
->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1349 menu
->setIcon(QIcon::fromTheme(QStringLiteral("document-new")));
1350 m_newFileMenu
->setDelayed(false);
1351 connect(menu
, &QMenu::aboutToShow
,
1352 this, &DolphinMainWindow::updateNewMenu
);
1354 QAction
* newWindow
= KStandardAction::openNew(this, &DolphinMainWindow::openNewMainWindow
, actionCollection());
1355 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
1356 newWindow
->setToolTip(i18nc("@info", "Open a new Dolphin window"));
1357 newWindow
->setWhatsThis(xi18nc("@info:whatsthis", "This opens a new "
1358 "window just like this one with the current location and view."
1359 "<nl/>You can drag and drop items between windows."));
1360 newWindow
->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
1362 QAction
* newTab
= actionCollection()->addAction(QStringLiteral("new_tab"));
1363 newTab
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1364 newTab
->setText(i18nc("@action:inmenu File", "New Tab"));
1365 newTab
->setWhatsThis(xi18nc("@info:whatsthis", "This opens a new "
1366 "<emphasis>Tab</emphasis> with the current location and view.<nl/>"
1367 "A tab is an additional view within this window. "
1368 "You can drag and drop items between tabs."));
1369 actionCollection()->setDefaultShortcuts(newTab
, {Qt::CTRL
| Qt::Key_T
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_N
});
1370 connect(newTab
, &QAction::triggered
, this, &DolphinMainWindow::openNewActivatedTab
);
1372 QAction
* addToPlaces
= actionCollection()->addAction(QStringLiteral("add_to_places"));
1373 addToPlaces
->setIcon(QIcon::fromTheme(QStringLiteral("bookmark-new")));
1374 addToPlaces
->setText(i18nc("@action:inmenu Add current folder to places", "Add to Places"));
1375 addToPlaces
->setWhatsThis(xi18nc("@info:whatsthis", "This adds the selected folder "
1376 "to the Places panel."));
1377 connect(addToPlaces
, &QAction::triggered
, this, &DolphinMainWindow::addToPlaces
);
1379 QAction
* closeTab
= KStandardAction::close(m_tabWidget
, QOverload
<>::of(&DolphinTabWidget::closeTab
), actionCollection());
1380 closeTab
->setText(i18nc("@action:inmenu File", "Close Tab"));
1381 closeTab
->setWhatsThis(i18nc("@info:whatsthis", "This closes the "
1382 "currently viewed tab. If no more tabs are left this window "
1383 "will close instead."));
1385 QAction
* quitAction
= KStandardAction::quit(this, &DolphinMainWindow::quit
, actionCollection());
1386 quitAction
->setWhatsThis(i18nc("@info:whatsthis quit", "This closes this window."));
1388 // setup 'Edit' menu
1389 KStandardAction::undo(this,
1390 &DolphinMainWindow::undo
,
1391 actionCollection());
1393 // i18n: This will be the last paragraph for the whatsthis for all three:
1394 // Cut, Copy and Paste
1395 const QString cutCopyPastePara
= xi18nc("@info:whatsthis", "<para><emphasis>Cut, "
1396 "Copy</emphasis> and <emphasis>Paste</emphasis> work between many "
1397 "applications and are among the most used commands. That's why their "
1398 "<emphasis>keyboard shortcuts</emphasis> are prominently placed right "
1399 "next to each other on the keyboard: <shortcut>Ctrl+X</shortcut>, "
1400 "<shortcut>Ctrl+C</shortcut> and <shortcut>Ctrl+V</shortcut>.</para>");
1401 QAction
* cutAction
= KStandardAction::cut(this, &DolphinMainWindow::cut
, actionCollection());
1402 cutAction
->setWhatsThis(xi18nc("@info:whatsthis cut", "This copies the items "
1403 "in your current selection to the <emphasis>clipboard</emphasis>.<nl/>"
1404 "Use the <emphasis>Paste</emphasis> action afterwards to copy them from "
1405 "the clipboard to a new location. The items will be removed from their "
1406 "initial location.") + cutCopyPastePara
);
1407 QAction
* copyAction
= KStandardAction::copy(this, &DolphinMainWindow::copy
, actionCollection());
1408 copyAction
->setWhatsThis(xi18nc("@info:whatsthis copy", "This copies the "
1409 "items in your current selection to the <emphasis>clipboard</emphasis>."
1410 "<nl/>Use the <emphasis>Paste</emphasis> action afterwards to copy them "
1411 "from the clipboard to a new location.") + cutCopyPastePara
);
1412 QAction
* paste
= KStandardAction::paste(this, &DolphinMainWindow::paste
, actionCollection());
1413 // The text of the paste-action is modified dynamically by Dolphin
1414 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1415 // due to the long text, the text "Paste" is used:
1416 paste
->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1417 paste
->setWhatsThis(xi18nc("@info:whatsthis paste", "This copies the items from "
1418 "your <emphasis>clipboard</emphasis> to the currently viewed folder.<nl/>"
1419 "If the items were added to the clipboard by the <emphasis>Cut</emphasis> "
1420 "action they are removed from their old location.") + cutCopyPastePara
);
1422 QAction
* copyToOtherViewAction
= actionCollection()->addAction(QStringLiteral("copy_to_inactive_split_view"));
1423 copyToOtherViewAction
->setText(i18nc("@action:inmenu", "Copy to Inactive Split View"));
1424 copyToOtherViewAction
->setWhatsThis(xi18nc("@info:whatsthis Copy", "This copies the selected items from "
1425 "the <emphasis>active</emphasis> view to the inactive split view."));
1426 copyToOtherViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("edit-copy")));
1427 copyToOtherViewAction
->setIconText(i18nc("@action:inmenu Edit", "Copy to Inactive Split View"));
1428 actionCollection()->setDefaultShortcut(copyToOtherViewAction
, Qt::SHIFT
| Qt::Key_F5
);
1429 connect(copyToOtherViewAction
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::copyToInactiveSplitView
);
1431 QAction
* moveToOtherViewAction
= actionCollection()->addAction(QStringLiteral("move_to_inactive_split_view"));
1432 moveToOtherViewAction
->setText(i18nc("@action:inmenu", "Move to Inactive Split View"));
1433 moveToOtherViewAction
->setWhatsThis(xi18nc("@info:whatsthis Move", "This moves the selected items from "
1434 "the <emphasis>active</emphasis> view to the inactive split view."));
1435 moveToOtherViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("edit-cut")));
1436 moveToOtherViewAction
->setIconText(i18nc("@action:inmenu Edit", "Move to Inactive Split View"));
1437 actionCollection()->setDefaultShortcut(moveToOtherViewAction
, Qt::SHIFT
| Qt::Key_F6
);
1438 connect(moveToOtherViewAction
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::moveToInactiveSplitView
);
1440 QAction
* showFilterBar
= actionCollection()->addAction(QStringLiteral("show_filter_bar"));
1441 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Filter..."));
1442 showFilterBar
->setToolTip(i18nc("@info:tooltip", "Toggle Filter Bar"));
1443 showFilterBar
->setWhatsThis(xi18nc("@info:whatsthis", "This opens the "
1444 "<emphasis>Filter Bar</emphasis> at the bottom of the window.<nl/> "
1445 "There you can enter a text to filter the files and folders currently displayed. "
1446 "Only those that contain the text in their name will be kept in view."));
1447 showFilterBar
->setIcon(QIcon::fromTheme(QStringLiteral("view-filter")));
1448 actionCollection()->setDefaultShortcuts(showFilterBar
, {Qt::CTRL
| Qt::Key_I
, Qt::Key_Slash
});
1449 connect(showFilterBar
, &QAction::triggered
, this, &DolphinMainWindow::showFilterBar
);
1451 // toggle_filter acts as a copy of the main showFilterBar to be used mainly
1452 // in the toolbar, with no default shortcut attached, to avoid messing with
1453 // existing workflows (filter bar always open and Ctrl-I to focus)
1454 QAction
*toggleFilter
= actionCollection()->addAction(QStringLiteral("toggle_filter"));
1455 toggleFilter
->setText(i18nc("@action:inmenu", "Toggle Filter Bar"));
1456 toggleFilter
->setIconText(i18nc("@action:intoolbar", "Filter"));
1457 toggleFilter
->setIcon(showFilterBar
->icon());
1458 toggleFilter
->setToolTip(showFilterBar
->toolTip());
1459 toggleFilter
->setWhatsThis(showFilterBar
->whatsThis());
1460 toggleFilter
->setCheckable(true);
1461 connect(toggleFilter
, &QAction::triggered
, this, &DolphinMainWindow::toggleFilterBar
);
1463 QAction
*searchAction
= KStandardAction::find(this, &DolphinMainWindow::find
, actionCollection());
1464 searchAction
->setText(i18n("Search..."));
1465 searchAction
->setToolTip(i18nc("@info:tooltip", "Search for files and folders"));
1466 searchAction
->setWhatsThis(xi18nc("@info:whatsthis find", "<para>This helps you "
1467 "find files and folders by opening a <emphasis>find bar</emphasis>. "
1468 "There you can enter search terms and specify settings to find the "
1469 "objects you are looking for.</para><para>Use this help again on "
1470 "the find bar so we can have a look at it while the settings are "
1471 "explained.</para>"));
1473 // toggle_search acts as a copy of the main searchAction to be used mainly
1474 // in the toolbar, with no default shortcut attached, to avoid messing with
1475 // existing workflows (search bar always open and Ctrl-F to focus)
1476 QAction
*toggleSearchAction
= actionCollection()->addAction(QStringLiteral("toggle_search"));
1477 toggleSearchAction
->setText(i18nc("@action:inmenu", "Toggle Search Bar"));
1478 toggleSearchAction
->setIconText(i18nc("@action:intoolbar", "Search"));
1479 toggleSearchAction
->setIcon(searchAction
->icon());
1480 toggleSearchAction
->setToolTip(searchAction
->toolTip());
1481 toggleSearchAction
->setWhatsThis(searchAction
->whatsThis());
1482 toggleSearchAction
->setCheckable(true);
1484 QAction
* selectAllAction
= KStandardAction::selectAll(this, &DolphinMainWindow::selectAll
, actionCollection());
1485 selectAllAction
->setWhatsThis(xi18nc("@info:whatsthis", "This selects all "
1486 "files and folders in the current location."));
1488 QAction
* invertSelection
= actionCollection()->addAction(QStringLiteral("invert_selection"));
1489 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1490 invertSelection
->setWhatsThis(xi18nc("@info:whatsthis invert", "This selects all "
1491 "objects that you have currently <emphasis>not</emphasis> selected instead."));
1492 invertSelection
->setIcon(QIcon::fromTheme(QStringLiteral("edit-select-invert")));
1493 actionCollection()->setDefaultShortcut(invertSelection
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
1494 connect(invertSelection
, &QAction::triggered
, this, &DolphinMainWindow::invertSelection
);
1496 // setup 'View' menu
1497 // (note that most of it is set up in DolphinViewActionHandler)
1499 QAction
* split
= actionCollection()->addAction(QStringLiteral("split_view"));
1500 split
->setWhatsThis(xi18nc("@info:whatsthis find", "<para>This splits "
1501 "the folder view below into two autonomous views.</para><para>This "
1502 "way you can see two locations at once and move items between them "
1503 "quickly.</para>Click this again afterwards to recombine the views."));
1504 actionCollection()->setDefaultShortcut(split
, Qt::Key_F3
);
1505 connect(split
, &QAction::triggered
, this, &DolphinMainWindow::toggleSplitView
);
1507 QAction
* stashSplit
= actionCollection()->addAction(QStringLiteral("split_stash"));
1508 actionCollection()->setDefaultShortcut(stashSplit
, Qt::CTRL
| Qt::Key_S
);
1509 stashSplit
->setText(i18nc("@action:intoolbar Stash", "Stash"));
1510 stashSplit
->setToolTip(i18nc("@info", "Opens the stash virtual directory in a split window"));
1511 stashSplit
->setIcon(QIcon::fromTheme(QStringLiteral("folder-stash")));
1512 stashSplit
->setCheckable(false);
1513 stashSplit
->setVisible(QDBusConnection::sessionBus().interface()->isServiceRegistered(QStringLiteral("org.kde.kio.StashNotifier")));
1514 connect(stashSplit
, &QAction::triggered
, this, &DolphinMainWindow::toggleSplitStash
);
1516 KStandardAction::redisplay(this, &DolphinMainWindow::reloadView
, actionCollection());
1518 QAction
* stop
= actionCollection()->addAction(QStringLiteral("stop"));
1519 stop
->setText(i18nc("@action:inmenu View", "Stop"));
1520 stop
->setToolTip(i18nc("@info", "Stop loading"));
1521 stop
->setWhatsThis(i18nc("@info", "This stops the loading of the contents of the current folder."));
1522 stop
->setIcon(QIcon::fromTheme(QStringLiteral("process-stop")));
1523 connect(stop
, &QAction::triggered
, this, &DolphinMainWindow::stopLoading
);
1525 KToggleAction
* editableLocation
= actionCollection()->add
<KToggleAction
>(QStringLiteral("editable_location"));
1526 editableLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1527 editableLocation
->setWhatsThis(xi18nc("@info:whatsthis",
1528 "This toggles the <emphasis>Location Bar</emphasis> to be "
1529 "editable so you can directly enter a location you want to go to.<nl/>"
1530 "You can also switch to editing by clicking to the right of the "
1531 "location and switch back by confirming the edited location."));
1532 actionCollection()->setDefaultShortcut(editableLocation
, Qt::Key_F6
);
1533 connect(editableLocation
, &KToggleAction::triggered
, this, &DolphinMainWindow::toggleEditLocation
);
1535 QAction
* replaceLocation
= actionCollection()->addAction(QStringLiteral("replace_location"));
1536 replaceLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1537 // i18n: "enter" is used both in the meaning of "writing" and "going to" a new location here.
1538 // Both meanings are useful but not necessary to understand the use of "Replace Location".
1539 // So you might want to be more verbose in your language to convey the meaning but it's up to you.
1540 replaceLocation
->setWhatsThis(xi18nc("@info:whatsthis",
1541 "This switches to editing the location and selects it "
1542 "so you can quickly enter a different location."));
1543 actionCollection()->setDefaultShortcut(replaceLocation
, Qt::CTRL
| Qt::Key_L
);
1544 connect(replaceLocation
, &QAction::triggered
, this, &DolphinMainWindow::replaceLocation
);
1548 QScopedPointer
<QAction
> backAction(KStandardAction::back(nullptr, nullptr, nullptr));
1549 m_backAction
= new KToolBarPopupAction(backAction
->icon(), backAction
->text(), actionCollection());
1550 m_backAction
->setObjectName(backAction
->objectName());
1551 m_backAction
->setShortcuts(backAction
->shortcuts());
1553 m_backAction
->setDelayed(true);
1554 m_backAction
->setStickyMenu(false);
1555 connect(m_backAction
, &QAction::triggered
, this, &DolphinMainWindow::goBack
);
1556 connect(m_backAction
->menu(), &QMenu::aboutToShow
, this, &DolphinMainWindow::slotAboutToShowBackPopupMenu
);
1557 connect(m_backAction
->menu(), &QMenu::triggered
, this, &DolphinMainWindow::slotGoBack
);
1558 actionCollection()->addAction(m_backAction
->objectName(), m_backAction
);
1560 auto backShortcuts
= m_backAction
->shortcuts();
1561 backShortcuts
.append(QKeySequence(Qt::Key_Backspace
));
1562 actionCollection()->setDefaultShortcuts(m_backAction
, backShortcuts
);
1564 DolphinRecentTabsMenu
* recentTabsMenu
= new DolphinRecentTabsMenu(this);
1565 actionCollection()->addAction(QStringLiteral("closed_tabs"), recentTabsMenu
);
1566 connect(m_tabWidget
, &DolphinTabWidget::rememberClosedTab
,
1567 recentTabsMenu
, &DolphinRecentTabsMenu::rememberClosedTab
);
1568 connect(recentTabsMenu
, &DolphinRecentTabsMenu::restoreClosedTab
,
1569 m_tabWidget
, &DolphinTabWidget::restoreClosedTab
);
1570 connect(recentTabsMenu
, &DolphinRecentTabsMenu::closedTabsCountChanged
,
1571 this, &DolphinMainWindow::closedTabsCountChanged
);
1573 QAction
* undoCloseTab
= actionCollection()->addAction(QStringLiteral("undo_close_tab"));
1574 undoCloseTab
->setText(i18nc("@action:inmenu File", "Undo close tab"));
1575 undoCloseTab
->setWhatsThis(i18nc("@info:whatsthis undo close tab",
1576 "This returns you to the previously closed tab."));
1577 actionCollection()->setDefaultShortcut(undoCloseTab
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_T
);
1578 undoCloseTab
->setIcon(QIcon::fromTheme(QStringLiteral("edit-undo")));
1579 undoCloseTab
->setEnabled(false);
1580 connect(undoCloseTab
, &QAction::triggered
, recentTabsMenu
, &DolphinRecentTabsMenu::undoCloseTab
);
1582 auto undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
1583 undoAction
->setWhatsThis(xi18nc("@info:whatsthis", "This undoes "
1584 "the last change you made to files or folders.<nl/>"
1585 "Such changes include <interface>creating, renaming</interface> "
1586 "and <interface>moving</interface> them to a different location "
1587 "or to the <filename>Trash</filename>. <nl/>Changes that can't "
1588 "be undone will ask for your confirmation."));
1589 undoAction
->setEnabled(false); // undo should be disabled by default
1592 QScopedPointer
<QAction
> forwardAction(KStandardAction::forward(nullptr, nullptr, nullptr));
1593 m_forwardAction
= new KToolBarPopupAction(forwardAction
->icon(), forwardAction
->text(), actionCollection());
1594 m_forwardAction
->setObjectName(forwardAction
->objectName());
1595 m_forwardAction
->setShortcuts(forwardAction
->shortcuts());
1597 m_forwardAction
->setDelayed(true);
1598 m_forwardAction
->setStickyMenu(false);
1599 connect(m_forwardAction
, &QAction::triggered
, this, &DolphinMainWindow::goForward
);
1600 connect(m_forwardAction
->menu(), &QMenu::aboutToShow
, this, &DolphinMainWindow::slotAboutToShowForwardPopupMenu
);
1601 connect(m_forwardAction
->menu(), &QMenu::triggered
, this, &DolphinMainWindow::slotGoForward
);
1602 actionCollection()->addAction(m_forwardAction
->objectName(), m_forwardAction
);
1603 actionCollection()->setDefaultShortcuts(m_forwardAction
, m_forwardAction
->shortcuts());
1605 // enable middle-click to open in a new tab
1606 auto *middleClickEventFilter
= new MiddleClickActionEventFilter(this);
1607 connect(middleClickEventFilter
, &MiddleClickActionEventFilter::actionMiddleClicked
, this, &DolphinMainWindow::slotBackForwardActionMiddleClicked
);
1608 m_backAction
->menu()->installEventFilter(middleClickEventFilter
);
1609 m_forwardAction
->menu()->installEventFilter(middleClickEventFilter
);
1610 KStandardAction::up(this, &DolphinMainWindow::goUp
, actionCollection());
1611 QAction
* homeAction
= KStandardAction::home(this, &DolphinMainWindow::goHome
, actionCollection());
1612 homeAction
->setWhatsThis(xi18nc("@info:whatsthis", "Go to your "
1613 "<filename>Home</filename> folder.<nl/>Every user account "
1614 "has their own <filename>Home</filename> that contains their data "
1615 "including folders that contain personal application data."));
1617 // setup 'Tools' menu
1618 QAction
* compareFiles
= actionCollection()->addAction(QStringLiteral("compare_files"));
1619 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1620 compareFiles
->setIcon(QIcon::fromTheme(QStringLiteral("kompare")));
1621 compareFiles
->setEnabled(false);
1622 connect(compareFiles
, &QAction::triggered
, this, &DolphinMainWindow::compareFiles
);
1624 QAction
* openPreferredSearchTool
= actionCollection()->addAction(QStringLiteral("open_preferred_search_tool"));
1625 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool"));
1626 openPreferredSearchTool
->setWhatsThis(xi18nc("@info:whatsthis",
1627 "<para>This opens a preferred search tool for the viewed location.</para>"
1628 "<para>Use <emphasis>More Search Tools</emphasis> menu to configure it.</para>"));
1629 openPreferredSearchTool
->setIcon(QIcon::fromTheme(QStringLiteral("search")));
1630 actionCollection()->setDefaultShortcut(openPreferredSearchTool
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_F
);
1631 connect(openPreferredSearchTool
, &QAction::triggered
, this, &DolphinMainWindow::openPreferredSearchTool
);
1633 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
1634 QAction
* openTerminal
= actionCollection()->addAction(QStringLiteral("open_terminal"));
1635 openTerminal
->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
1636 openTerminal
->setWhatsThis(xi18nc("@info:whatsthis",
1637 "<para>This opens a <emphasis>terminal</emphasis> application for the viewed location.</para>"
1638 "<para>To learn more about terminals use the help in the terminal application.</para>"));
1639 openTerminal
->setIcon(QIcon::fromTheme(QStringLiteral("utilities-terminal")));
1640 actionCollection()->setDefaultShortcut(openTerminal
, Qt::SHIFT
| Qt::Key_F4
);
1641 connect(openTerminal
, &QAction::triggered
, this, &DolphinMainWindow::openTerminal
);
1643 #ifdef HAVE_TERMINAL
1644 QAction
* focusTerminalPanel
= actionCollection()->addAction(QStringLiteral("focus_terminal_panel"));
1645 focusTerminalPanel
->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
1646 focusTerminalPanel
->setIcon(QIcon::fromTheme(QStringLiteral("swap-panels")));
1647 actionCollection()->setDefaultShortcut(focusTerminalPanel
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_F4
);
1648 connect(focusTerminalPanel
, &QAction::triggered
, this, &DolphinMainWindow::focusTerminalPanel
);
1652 // setup 'Bookmarks' menu
1653 KActionMenu
*bookmarkMenu
= new KActionMenu(i18nc("@title:menu", "&Bookmarks"), this);
1654 bookmarkMenu
->setIcon(QIcon::fromTheme(QStringLiteral("bookmarks")));
1655 // Make the toolbar button version work properly on click
1656 bookmarkMenu
->setDelayed(false);
1657 m_bookmarkHandler
= new DolphinBookmarkHandler(this, actionCollection(), bookmarkMenu
->menu(), this);
1658 actionCollection()->addAction(QStringLiteral("bookmarks"), bookmarkMenu
);
1660 // setup 'Settings' menu
1661 KToggleAction
* showMenuBar
= KStandardAction::showMenubar(nullptr, nullptr, actionCollection());
1662 showMenuBar
->setWhatsThis(xi18nc("@info:whatsthis",
1663 "This switches between having a <emphasis>Menubar</emphasis> "
1664 "and having a <interface>Control</interface> button. Both "
1665 "contain mostly the same commands and configuration options."));
1666 connect(showMenuBar
, &KToggleAction::triggered
, // Fixes #286822
1667 this, &DolphinMainWindow::toggleShowMenuBar
, Qt::QueuedConnection
);
1668 KStandardAction::preferences(this, &DolphinMainWindow::editSettings
, actionCollection());
1670 // setup 'Help' menu for the m_controlButton. The other one is set up in the base class.
1671 m_helpMenu
= new KHelpMenu(nullptr);
1672 m_helpMenu
->menu()->installEventFilter(this);
1673 // remove duplicate shortcuts
1674 m_helpMenu
->action(KHelpMenu::menuHelpContents
)->setShortcut(QKeySequence());
1675 m_helpMenu
->action(KHelpMenu::menuWhatsThis
)->setShortcut(QKeySequence());
1677 // not in menu actions
1678 QList
<QKeySequence
> nextTabKeys
= KStandardShortcut::tabNext();
1679 nextTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::Key_Tab
));
1681 QList
<QKeySequence
> prevTabKeys
= KStandardShortcut::tabPrev();
1682 prevTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::SHIFT
| Qt::Key_Tab
));
1684 for (int i
= 0; i
< MaxActivateTabShortcuts
; ++i
) {
1685 QAction
* activateTab
= actionCollection()->addAction(QStringLiteral("activate_tab_%1").arg(i
));
1686 activateTab
->setText(i18nc("@action:inmenu", "Activate Tab %1", i
+ 1));
1687 activateTab
->setEnabled(false);
1688 connect(activateTab
, &QAction::triggered
, this, [this, i
]() { m_tabWidget
->activateTab(i
); });
1690 // only add default shortcuts for the first 9 tabs regardless of MaxActivateTabShortcuts
1692 actionCollection()->setDefaultShortcut(activateTab
, QStringLiteral("Alt+%1").arg(i
+ 1));
1696 QAction
* activateLastTab
= actionCollection()->addAction(QStringLiteral("activate_last_tab"));
1697 activateLastTab
->setText(i18nc("@action:inmenu", "Activate Last Tab"));
1698 activateLastTab
->setEnabled(false);
1699 connect(activateLastTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activateLastTab
);
1700 actionCollection()->setDefaultShortcut(activateLastTab
, Qt::ALT
| Qt::Key_0
);
1702 QAction
* activateNextTab
= actionCollection()->addAction(QStringLiteral("activate_next_tab"));
1703 activateNextTab
->setIconText(i18nc("@action:inmenu", "Next Tab"));
1704 activateNextTab
->setText(i18nc("@action:inmenu", "Activate Next Tab"));
1705 activateNextTab
->setEnabled(false);
1706 connect(activateNextTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activateNextTab
);
1707 actionCollection()->setDefaultShortcuts(activateNextTab
, nextTabKeys
);
1709 QAction
* activatePrevTab
= actionCollection()->addAction(QStringLiteral("activate_prev_tab"));
1710 activatePrevTab
->setIconText(i18nc("@action:inmenu", "Previous Tab"));
1711 activatePrevTab
->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
1712 activatePrevTab
->setEnabled(false);
1713 connect(activatePrevTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activatePrevTab
);
1714 actionCollection()->setDefaultShortcuts(activatePrevTab
, prevTabKeys
);
1717 QAction
* showTarget
= actionCollection()->addAction(QStringLiteral("show_target"));
1718 showTarget
->setText(i18nc("@action:inmenu", "Show Target"));
1719 showTarget
->setIcon(QIcon::fromTheme(QStringLiteral("document-open-folder")));
1720 showTarget
->setEnabled(false);
1721 connect(showTarget
, &QAction::triggered
, this, &DolphinMainWindow::showTarget
);
1723 QAction
* openInNewTab
= actionCollection()->addAction(QStringLiteral("open_in_new_tab"));
1724 openInNewTab
->setText(i18nc("@action:inmenu", "Open in New Tab"));
1725 openInNewTab
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1726 connect(openInNewTab
, &QAction::triggered
, this, &DolphinMainWindow::openInNewTab
);
1728 QAction
* openInNewTabs
= actionCollection()->addAction(QStringLiteral("open_in_new_tabs"));
1729 openInNewTabs
->setText(i18nc("@action:inmenu", "Open in New Tabs"));
1730 openInNewTabs
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1731 connect(openInNewTabs
, &QAction::triggered
, this, &DolphinMainWindow::openInNewTab
);
1733 QAction
* openInNewWindow
= actionCollection()->addAction(QStringLiteral("open_in_new_window"));
1734 openInNewWindow
->setText(i18nc("@action:inmenu", "Open in New Window"));
1735 openInNewWindow
->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
1736 connect(openInNewWindow
, &QAction::triggered
, this, &DolphinMainWindow::openInNewWindow
);
1739 void DolphinMainWindow::setupDockWidgets()
1741 const bool lock
= GeneralSettings::lockPanels();
1743 KDualAction
* lockLayoutAction
= actionCollection()->add
<KDualAction
>(QStringLiteral("lock_panels"));
1744 lockLayoutAction
->setActiveText(i18nc("@action:inmenu Panels", "Unlock Panels"));
1745 lockLayoutAction
->setActiveIcon(QIcon::fromTheme(QStringLiteral("object-unlocked")));
1746 lockLayoutAction
->setInactiveText(i18nc("@action:inmenu Panels", "Lock Panels"));
1747 lockLayoutAction
->setInactiveIcon(QIcon::fromTheme(QStringLiteral("object-locked")));
1748 lockLayoutAction
->setWhatsThis(xi18nc("@info:whatsthis", "This "
1749 "switches between having panels <emphasis>locked</emphasis> or "
1750 "<emphasis>unlocked</emphasis>.<nl/>Unlocked panels can be "
1751 "dragged to the other side of the window and have a close "
1752 "button.<nl/>Locked panels are embedded more cleanly."));
1753 lockLayoutAction
->setActive(lock
);
1754 connect(lockLayoutAction
, &KDualAction::triggered
, this, &DolphinMainWindow::togglePanelLockState
);
1756 // Setup "Information"
1757 DolphinDockWidget
* infoDock
= new DolphinDockWidget(i18nc("@title:window", "Information"));
1758 infoDock
->setLocked(lock
);
1759 infoDock
->setObjectName(QStringLiteral("infoDock"));
1760 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1763 InformationPanel
* infoPanel
= new InformationPanel(infoDock
);
1764 infoPanel
->setCustomContextMenuActions({lockLayoutAction
});
1765 connect(infoPanel
, &InformationPanel::urlActivated
, this, &DolphinMainWindow::handleUrl
);
1766 infoDock
->setWidget(infoPanel
);
1768 QAction
* infoAction
= infoDock
->toggleViewAction();
1769 createPanelAction(QIcon::fromTheme(QStringLiteral("dialog-information")), Qt::Key_F11
, infoAction
, QStringLiteral("show_information_panel"));
1771 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
1772 connect(this, &DolphinMainWindow::urlChanged
,
1773 infoPanel
, &InformationPanel::setUrl
);
1774 connect(this, &DolphinMainWindow::selectionChanged
,
1775 infoPanel
, &InformationPanel::setSelection
);
1776 connect(this, &DolphinMainWindow::requestItemInfo
,
1777 infoPanel
, &InformationPanel::requestDelayedItemInfo
);
1778 connect(this, &DolphinMainWindow::fileItemsChanged
,
1779 infoPanel
, &InformationPanel::slotFilesItemChanged
);
1782 // i18n: This is the last paragraph for the "What's This"-texts of all four panels.
1783 const QString panelWhatsThis
= xi18nc("@info:whatsthis", "<para>To show or "
1784 "hide panels like this go to <interface>Control|Panels</interface> "
1785 "or <interface>View|Panels</interface>.</para>");
1787 actionCollection()->action(QStringLiteral("show_information_panel"))
1788 ->setWhatsThis(xi18nc("@info:whatsthis", "<para> This toggles the "
1789 "<emphasis>information</emphasis> panel at the right side of the "
1790 "window.</para><para>The panel provides in-depth information "
1791 "about the items your mouse is hovering over or about the selected "
1792 "items. Otherwise it informs you about the currently viewed folder.<nl/>"
1793 "For single items a preview of their contents is provided.</para>"));
1795 infoDock
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This panel "
1796 "provides in-depth information about the items your mouse is "
1797 "hovering over or about the selected items. Otherwise it informs "
1798 "you about the currently viewed folder.<nl/>For single items a "
1799 "preview of their contents is provided.</para><para>You can configure "
1800 "which and how details are given here by right-clicking.</para>") + panelWhatsThis
);
1803 DolphinDockWidget
* foldersDock
= new DolphinDockWidget(i18nc("@title:window", "Folders"));
1804 foldersDock
->setLocked(lock
);
1805 foldersDock
->setObjectName(QStringLiteral("foldersDock"));
1806 foldersDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1807 FoldersPanel
* foldersPanel
= new FoldersPanel(foldersDock
);
1808 foldersPanel
->setCustomContextMenuActions({lockLayoutAction
});
1809 foldersDock
->setWidget(foldersPanel
);
1811 QAction
* foldersAction
= foldersDock
->toggleViewAction();
1812 createPanelAction(QIcon::fromTheme(QStringLiteral("folder")), Qt::Key_F7
, foldersAction
, QStringLiteral("show_folders_panel"));
1814 addDockWidget(Qt::LeftDockWidgetArea
, foldersDock
);
1815 connect(this, &DolphinMainWindow::urlChanged
,
1816 foldersPanel
, &FoldersPanel::setUrl
);
1817 connect(foldersPanel
, &FoldersPanel::folderActivated
,
1818 this, &DolphinMainWindow::changeUrl
);
1819 connect(foldersPanel
, &FoldersPanel::folderMiddleClicked
,
1820 this, &DolphinMainWindow::openNewTab
);
1821 connect(foldersPanel
, &FoldersPanel::errorMessage
,
1822 this, &DolphinMainWindow::showErrorMessage
);
1824 actionCollection()->action(QStringLiteral("show_folders_panel"))
1825 ->setWhatsThis(xi18nc("@info:whatsthis", "This toggles the "
1826 "<emphasis>folders</emphasis> panel at the left side of the window."
1827 "<nl/><nl/>It shows the folders of the <emphasis>file system"
1828 "</emphasis> in a <emphasis>tree view</emphasis>."));
1829 foldersDock
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This panel "
1830 "shows the folders of the <emphasis>file system</emphasis> in a "
1831 "<emphasis>tree view</emphasis>.</para><para>Click a folder to go "
1832 "there. Click the arrow to the left of a folder to see its subfolders. "
1833 "This allows quick switching between any folders.</para>") + panelWhatsThis
);
1836 #ifdef HAVE_TERMINAL
1837 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
1838 DolphinDockWidget
* terminalDock
= new DolphinDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
1839 terminalDock
->setLocked(lock
);
1840 terminalDock
->setObjectName(QStringLiteral("terminalDock"));
1841 m_terminalPanel
= new TerminalPanel(terminalDock
);
1842 m_terminalPanel
->setCustomContextMenuActions({lockLayoutAction
});
1843 terminalDock
->setWidget(m_terminalPanel
);
1845 connect(m_terminalPanel
, &TerminalPanel::hideTerminalPanel
, terminalDock
, &DolphinDockWidget::hide
);
1846 connect(m_terminalPanel
, &TerminalPanel::changeUrl
, this, &DolphinMainWindow::slotTerminalDirectoryChanged
);
1847 connect(terminalDock
, &DolphinDockWidget::visibilityChanged
,
1848 m_terminalPanel
, &TerminalPanel::dockVisibilityChanged
);
1849 connect(terminalDock
, &DolphinDockWidget::visibilityChanged
,
1850 this, &DolphinMainWindow::slotTerminalPanelVisibilityChanged
);
1852 QAction
* terminalAction
= terminalDock
->toggleViewAction();
1853 createPanelAction(QIcon::fromTheme(QStringLiteral("dialog-scripts")), Qt::Key_F4
, terminalAction
, QStringLiteral("show_terminal_panel"));
1855 addDockWidget(Qt::BottomDockWidgetArea
, terminalDock
);
1856 connect(this, &DolphinMainWindow::urlChanged
,
1857 m_terminalPanel
, &TerminalPanel::setUrl
);
1859 if (GeneralSettings::version() < 200) {
1860 terminalDock
->hide();
1863 actionCollection()->action(QStringLiteral("show_terminal_panel"))
1864 ->setWhatsThis(xi18nc("@info:whatsthis", "<para>This toggles the "
1865 "<emphasis>terminal</emphasis> panel at the bottom of the window."
1866 "<nl/>The location in the terminal will always match the folder "
1867 "view so you can navigate using either.</para><para>The terminal "
1868 "panel is not needed for basic computer usage but can be useful "
1869 "for advanced tasks. To learn more about terminals use the help "
1870 "in a standalone terminal application like Konsole.</para>"));
1871 terminalDock
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is "
1872 "the <emphasis>terminal</emphasis> panel. It behaves like a "
1873 "normal terminal but will match the location of the folder view "
1874 "so you can navigate using either.</para><para>The terminal panel "
1875 "is not needed for basic computer usage but can be useful for "
1876 "advanced tasks. To learn more about terminals use the help in a "
1877 "standalone terminal application like Konsole.</para>") + panelWhatsThis
);
1881 if (GeneralSettings::version() < 200) {
1883 foldersDock
->hide();
1887 DolphinDockWidget
* placesDock
= new DolphinDockWidget(i18nc("@title:window", "Places"));
1888 placesDock
->setLocked(lock
);
1889 placesDock
->setObjectName(QStringLiteral("placesDock"));
1890 placesDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1892 m_placesPanel
= new PlacesPanel(placesDock
);
1893 m_placesPanel
->setCustomContextMenuActions({lockLayoutAction
});
1894 placesDock
->setWidget(m_placesPanel
);
1896 QAction
*placesAction
= placesDock
->toggleViewAction();
1897 createPanelAction(QIcon::fromTheme(QStringLiteral("compass")), Qt::Key_F9
, placesAction
, QStringLiteral("show_places_panel"));
1899 addDockWidget(Qt::LeftDockWidgetArea
, placesDock
);
1900 connect(m_placesPanel
, &PlacesPanel::placeActivated
,
1901 this, &DolphinMainWindow::slotPlaceActivated
);
1902 connect(m_placesPanel
, &PlacesPanel::placeMiddleClicked
,
1903 this, &DolphinMainWindow::openNewTab
);
1904 connect(m_placesPanel
, &PlacesPanel::errorMessage
,
1905 this, &DolphinMainWindow::showErrorMessage
);
1906 connect(this, &DolphinMainWindow::urlChanged
,
1907 m_placesPanel
, &PlacesPanel::setUrl
);
1908 connect(placesDock
, &DolphinDockWidget::visibilityChanged
,
1909 &DolphinUrlNavigatorsController::slotPlacesPanelVisibilityChanged
);
1910 connect(this, &DolphinMainWindow::settingsChanged
,
1911 m_placesPanel
, &PlacesPanel::readSettings
);
1912 connect(m_placesPanel
, &PlacesPanel::storageTearDownRequested
,
1913 this, &DolphinMainWindow::slotStorageTearDownFromPlacesRequested
);
1914 connect(m_placesPanel
, &PlacesPanel::storageTearDownExternallyRequested
,
1915 this, &DolphinMainWindow::slotStorageTearDownExternallyRequested
);
1916 DolphinUrlNavigatorsController::slotPlacesPanelVisibilityChanged(m_placesPanel
->isVisible());
1918 auto actionShowAllPlaces
= new QAction(QIcon::fromTheme(QStringLiteral("view-hidden")), i18nc("@item:inmenu", "Show Hidden Places"), this);
1919 actionShowAllPlaces
->setCheckable(true);
1920 actionShowAllPlaces
->setDisabled(true);
1921 actionShowAllPlaces
->setWhatsThis(i18nc("@info:whatsthis", "This displays "
1922 "all places in the places panel that have been hidden. They will "
1923 "appear semi-transparent unless you uncheck their hide property."));
1925 connect(actionShowAllPlaces
, &QAction::triggered
, this, [actionShowAllPlaces
, this](bool checked
){
1926 actionShowAllPlaces
->setIcon(QIcon::fromTheme(checked
? QStringLiteral("view-visible") : QStringLiteral("view-hidden")));
1927 m_placesPanel
->showHiddenEntries(checked
);
1930 connect(m_placesPanel
, &PlacesPanel::showHiddenEntriesChanged
, this, [actionShowAllPlaces
] (bool checked
){
1931 actionShowAllPlaces
->setChecked(checked
);
1932 actionShowAllPlaces
->setIcon(QIcon::fromTheme(checked
? QStringLiteral("view-visible") : QStringLiteral("view-hidden")));
1935 actionCollection()->action(QStringLiteral("show_places_panel"))
1936 ->setWhatsThis(xi18nc("@info:whatsthis", "<para>This toggles the "
1937 "<emphasis>places</emphasis> panel at the left side of the window."
1938 "</para><para>It allows you to go to locations you have "
1939 "bookmarked and to access disk or media attached to the computer "
1940 "or to the network. It also contains sections to find recently "
1941 "saved files or files of a certain type.</para>"));
1942 placesDock
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
1943 "<emphasis>Places</emphasis> panel. It allows you to go to locations "
1944 "you have bookmarked and to access disk or media attached to the "
1945 "computer or to the network. It also contains sections to find "
1946 "recently saved files or files of a certain type.</para><para>"
1947 "Click on an entry to go there. Click with the right mouse button "
1948 "instead to open any entry in a new tab or new window.</para>"
1949 "<para>New entries can be added by dragging folders onto this panel. "
1950 "Right-click any section or entry to hide it. Right-click an empty "
1951 "space on this panel and select <interface>Show Hidden Places"
1952 "</interface> to display it again.</para>") + panelWhatsThis
);
1954 // Add actions into the "Panels" menu
1955 KActionMenu
* panelsMenu
= new KActionMenu(i18nc("@action:inmenu View", "Show Panels"), this);
1956 actionCollection()->addAction(QStringLiteral("panels"), panelsMenu
);
1957 panelsMenu
->setIcon(QIcon::fromTheme(QStringLiteral("view-sidetree")));
1958 panelsMenu
->setDelayed(false);
1959 const KActionCollection
* ac
= actionCollection();
1960 panelsMenu
->addAction(ac
->action(QStringLiteral("show_places_panel")));
1962 panelsMenu
->addAction(ac
->action(QStringLiteral("show_information_panel")));
1964 panelsMenu
->addAction(ac
->action(QStringLiteral("show_folders_panel")));
1965 panelsMenu
->addAction(ac
->action(QStringLiteral("show_terminal_panel")));
1966 panelsMenu
->addSeparator();
1967 panelsMenu
->addAction(actionShowAllPlaces
);
1968 panelsMenu
->addAction(lockLayoutAction
);
1970 connect(panelsMenu
->menu(), &QMenu::aboutToShow
, this, [actionShowAllPlaces
, this]{
1971 actionShowAllPlaces
->setEnabled(m_placesPanel
->hiddenListCount());
1976 void DolphinMainWindow::updateFileAndEditActions()
1978 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
1979 const KActionCollection
* col
= actionCollection();
1980 KFileItemListProperties
capabilitiesSource(list
);
1982 QAction
* addToPlacesAction
= col
->action(QStringLiteral("add_to_places"));
1983 QAction
* copyToOtherViewAction
= col
->action(QStringLiteral("copy_to_inactive_split_view"));
1984 QAction
* moveToOtherViewAction
= col
->action(QStringLiteral("move_to_inactive_split_view"));
1985 QAction
* copyLocation
= col
->action(QString("copy_location"));
1987 if (list
.isEmpty()) {
1988 stateChanged(QStringLiteral("has_no_selection"));
1990 addToPlacesAction
->setEnabled(true);
1991 copyToOtherViewAction
->setEnabled(false);
1992 moveToOtherViewAction
->setEnabled(false);
1993 copyLocation
->setEnabled(false);
1995 stateChanged(QStringLiteral("has_selection"));
1997 QAction
* renameAction
= col
->action(KStandardAction::name(KStandardAction::RenameFile
));
1998 QAction
* moveToTrashAction
= col
->action(KStandardAction::name(KStandardAction::MoveToTrash
));
1999 QAction
* deleteAction
= col
->action(KStandardAction::name(KStandardAction::DeleteFile
));
2000 QAction
* cutAction
= col
->action(KStandardAction::name(KStandardAction::Cut
));
2001 QAction
* deleteWithTrashShortcut
= col
->action(QStringLiteral("delete_shortcut")); // see DolphinViewActionHandler
2002 QAction
* showTarget
= col
->action(QStringLiteral("show_target"));
2003 QAction
* duplicateAction
= col
->action(QStringLiteral("duplicate")); // see DolphinViewActionHandler
2005 if (list
.length() == 1 && list
.first().isDir()) {
2006 addToPlacesAction
->setEnabled(true);
2008 addToPlacesAction
->setEnabled(false);
2011 if (m_tabWidget
->currentTabPage()->splitViewEnabled()) {
2012 DolphinTabPage
* tabPage
= m_tabWidget
->currentTabPage();
2013 KFileItem capabilitiesDestination
;
2015 if (tabPage
->primaryViewActive()) {
2016 capabilitiesDestination
= tabPage
->secondaryViewContainer()->url();
2018 capabilitiesDestination
= tabPage
->primaryViewContainer()->url();
2021 copyToOtherViewAction
->setEnabled(capabilitiesDestination
.isWritable());
2022 moveToOtherViewAction
->setEnabled(capabilitiesSource
.supportsMoving() && capabilitiesDestination
.isWritable());
2024 copyToOtherViewAction
->setEnabled(false);
2025 moveToOtherViewAction
->setEnabled(false);
2028 const bool enableMoveToTrash
= capabilitiesSource
.isLocal() && capabilitiesSource
.supportsMoving();
2030 renameAction
->setEnabled(capabilitiesSource
.supportsMoving());
2031 moveToTrashAction
->setEnabled(enableMoveToTrash
);
2032 deleteAction
->setEnabled(capabilitiesSource
.supportsDeleting());
2033 deleteWithTrashShortcut
->setEnabled(capabilitiesSource
.supportsDeleting() && !enableMoveToTrash
);
2034 cutAction
->setEnabled(capabilitiesSource
.supportsMoving());
2035 copyLocation
->setEnabled(list
.length() == 1);
2036 showTarget
->setEnabled(list
.length() == 1 && list
.at(0).isLink());
2037 duplicateAction
->setEnabled(capabilitiesSource
.supportsWriting());
2041 void DolphinMainWindow::updateViewActions()
2043 m_actionHandler
->updateViewActions();
2045 QAction
* toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
2046 toggleFilterBarAction
->setChecked(m_activeViewContainer
->isFilterBarVisible());
2048 updateSplitAction();
2051 void DolphinMainWindow::updateGoActions()
2053 QAction
* goUpAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Up
));
2054 const QUrl currentUrl
= m_activeViewContainer
->url();
2055 // I think this is one of the best places to firstly be confronted
2056 // with a file system and its hierarchy. Talking about the root
2057 // directory might seem too much here but it is the question that
2058 // naturally arises in this context.
2059 goUpAction
->setWhatsThis(xi18nc("@info:whatsthis", "<para>Go to "
2060 "the folder that contains the currently viewed one.</para>"
2061 "<para>All files and folders are organized in a hierarchical "
2062 "<emphasis>file system</emphasis>. At the top of this hierarchy is "
2063 "a directory that contains all data connected to this computer"
2064 "—the <emphasis>root directory</emphasis>.</para>"));
2065 goUpAction
->setEnabled(KIO::upUrl(currentUrl
) != currentUrl
);
2068 void DolphinMainWindow::refreshViews()
2070 m_tabWidget
->refreshViews();
2072 if (GeneralSettings::modifiedStartupSettings()) {
2073 // The startup settings have been changed by the user (see bug #254947).
2074 // Synchronize the split-view setting with the active view:
2075 const bool splitView
= GeneralSettings::splitView();
2076 m_tabWidget
->currentTabPage()->setSplitViewEnabled(splitView
, WithAnimation
);
2077 updateSplitAction();
2078 updateWindowTitle();
2081 Q_EMIT
settingsChanged();
2084 void DolphinMainWindow::clearStatusBar()
2086 m_activeViewContainer
->statusBar()->resetToDefaultText();
2089 void DolphinMainWindow::connectViewSignals(DolphinViewContainer
* container
)
2091 connect(container
, &DolphinViewContainer::showFilterBarChanged
,
2092 this, &DolphinMainWindow::updateFilterBarAction
);
2093 connect(container
, &DolphinViewContainer::writeStateChanged
,
2094 this, &DolphinMainWindow::slotWriteStateChanged
);
2095 connect(container
, &DolphinViewContainer::searchModeEnabledChanged
,
2096 this, &DolphinMainWindow::updateSearchAction
);
2098 const QAction
* toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
2099 connect(toggleSearchAction
, &QAction::triggered
, container
, &DolphinViewContainer::setSearchModeEnabled
);
2101 const DolphinView
* view
= container
->view();
2102 connect(view
, &DolphinView::selectionChanged
,
2103 this, &DolphinMainWindow::slotSelectionChanged
);
2104 connect(view
, &DolphinView::requestItemInfo
,
2105 this, &DolphinMainWindow::requestItemInfo
);
2106 connect(view
, &DolphinView::fileItemsChanged
,
2107 this, &DolphinMainWindow::fileItemsChanged
);
2108 connect(view
, &DolphinView::tabRequested
,
2109 this, &DolphinMainWindow::openNewTab
);
2110 connect(view
, &DolphinView::requestContextMenu
,
2111 this, &DolphinMainWindow::openContextMenu
);
2112 connect(view
, &DolphinView::directoryLoadingStarted
,
2113 this, &DolphinMainWindow::enableStopAction
);
2114 connect(view
, &DolphinView::directoryLoadingCompleted
,
2115 this, &DolphinMainWindow::disableStopAction
);
2116 connect(view
, &DolphinView::directoryLoadingCompleted
,
2117 this, &DolphinMainWindow::slotDirectoryLoadingCompleted
);
2118 connect(view
, &DolphinView::goBackRequested
,
2119 this, &DolphinMainWindow::goBack
);
2120 connect(view
, &DolphinView::goForwardRequested
,
2121 this, &DolphinMainWindow::goForward
);
2122 connect(view
, &DolphinView::urlActivated
,
2123 this, &DolphinMainWindow::handleUrl
);
2124 connect(view
, &DolphinView::goUpRequested
,
2125 this, &DolphinMainWindow::goUp
);
2127 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>
2128 (actionCollection()->action(QStringLiteral("url_navigators")));
2130 const KUrlNavigator
*navigator
= m_tabWidget
->currentTabPage()->primaryViewActive() ?
2131 navigators
->primaryUrlNavigator() :
2132 navigators
->secondaryUrlNavigator();
2134 connect(navigator
, &KUrlNavigator::urlChanged
,
2135 this, &DolphinMainWindow::changeUrl
);
2136 QAction
*editableLocactionAction
= actionCollection()->action(QStringLiteral("editable_location"));
2137 editableLocactionAction
->setChecked(navigator
->isUrlEditable());
2138 connect(navigator
, &KUrlNavigator::editableStateChanged
,
2139 this, &DolphinMainWindow::slotEditableStateChanged
);
2140 connect(navigator
, &KUrlNavigator::tabRequested
,
2141 this, &DolphinMainWindow::openNewTab
);
2143 disconnect(m_updateHistoryConnection
);
2144 m_updateHistoryConnection
= connect(
2145 container
->urlNavigatorInternalWithHistory(), &KUrlNavigator::historyChanged
,
2146 this, &DolphinMainWindow::updateHistory
);
2149 void DolphinMainWindow::updateSplitAction()
2151 QAction
* splitAction
= actionCollection()->action(QStringLiteral("split_view"));
2152 const DolphinTabPage
* tabPage
= m_tabWidget
->currentTabPage();
2153 if (tabPage
->splitViewEnabled()) {
2154 if (GeneralSettings::closeActiveSplitView() ? tabPage
->primaryViewActive() : !tabPage
->primaryViewActive()) {
2155 splitAction
->setText(i18nc("@action:intoolbar Close left view", "Close"));
2156 splitAction
->setToolTip(i18nc("@info", "Close left view"));
2157 splitAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-left-close")));
2159 splitAction
->setText(i18nc("@action:intoolbar Close right view", "Close"));
2160 splitAction
->setToolTip(i18nc("@info", "Close right view"));
2161 splitAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-right-close")));
2164 splitAction
->setText(i18nc("@action:intoolbar Split view", "Split"));
2165 splitAction
->setToolTip(i18nc("@info", "Split view"));
2166 splitAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-right-new")));
2170 void DolphinMainWindow::updateAllowedToolbarAreas()
2172 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>
2173 (actionCollection()->action(QStringLiteral("url_navigators")));
2174 if (toolBar()->actions().contains(navigators
)) {
2175 toolBar()->setAllowedAreas(Qt::TopToolBarArea
| Qt::BottomToolBarArea
);
2176 if (toolBarArea(toolBar()) == Qt::LeftToolBarArea
||
2177 toolBarArea(toolBar()) == Qt::RightToolBarArea
) {
2178 addToolBar(Qt::TopToolBarArea
, toolBar());
2181 toolBar()->setAllowedAreas(Qt::AllToolBarAreas
);
2185 bool DolphinMainWindow::isKompareInstalled() const
2187 static bool initialized
= false;
2188 static bool installed
= false;
2190 // TODO: maybe replace this approach later by using a menu
2191 // plugin like kdiff3plugin.cpp
2192 installed
= !QStandardPaths::findExecutable(QStringLiteral("kompare")).isEmpty();
2198 void DolphinMainWindow::createPanelAction(const QIcon
& icon
,
2199 const QKeySequence
& shortcut
,
2200 QAction
* dockAction
,
2201 const QString
& actionName
)
2203 QAction
* panelAction
= actionCollection()->addAction(actionName
);
2204 panelAction
->setCheckable(true);
2205 panelAction
->setChecked(dockAction
->isChecked());
2206 panelAction
->setText(dockAction
->text());
2207 panelAction
->setIcon(icon
);
2208 actionCollection()->setDefaultShortcut(panelAction
, shortcut
);
2210 connect(panelAction
, &QAction::triggered
, dockAction
, &QAction::trigger
);
2211 connect(dockAction
, &QAction::toggled
, panelAction
, &QAction::setChecked
);
2214 void DolphinMainWindow::setupWhatsThis()
2217 menuBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2218 "<emphasis>Menubar</emphasis>. It provides access to commands and "
2219 "configuration options. Left-click on any of the menus on this "
2220 "bar to see its contents.</para><para>The Menubar can be hidden "
2221 "by unchecking <interface>Settings|Show Menubar</interface>. Then "
2222 "most of its contents become available through a <interface>Control"
2223 "</interface> button on the <emphasis>Toolbar</emphasis>.</para>"));
2224 toolBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2225 "<emphasis>Toolbar</emphasis>. It allows quick access to "
2226 "frequently used actions.</para><para>It is highly customizable. "
2227 "All items you see in the <interface>Control</interface> menu or "
2228 "in the <interface>Menubar</interface> can be placed on the "
2229 "Toolbar. Just right-click on it and select <interface>Configure "
2230 "Toolbars…</interface> or find this action in the <interface>"
2231 "Control</interface> or <interface>Settings</interface> menu."
2232 "</para><para>The location of the bar and the style of its "
2233 "buttons can also be changed in the right-click menu. Right-click "
2234 "a button if you want to show or hide its text.</para>"));
2235 m_tabWidget
->setWhatsThis(xi18nc("@info:whatsthis main view",
2236 "<para>Here you can see the <emphasis>folders</emphasis> and "
2237 "<emphasis>files</emphasis> that are at the location described in "
2238 "the <interface>Location Bar</interface> above. This area is the "
2239 "central part of this application where you navigate to the files "
2240 "you want to use.</para><para>For an elaborate and general "
2241 "introduction to this application <link "
2242 "url='https://userbase.kde.org/Dolphin/File_Management#Introduction_to_Dolphin'>"
2243 "click here</link>. This will open an introductory article from "
2244 "the <emphasis>KDE UserBase Wiki</emphasis>.</para><para>For brief "
2245 "explanations of all the features of this <emphasis>view</emphasis> "
2246 "<link url='help:/dolphin/dolphin-view.html'>click here</link> "
2247 "instead. This will open a page from the <emphasis>Handbook"
2248 "</emphasis> that covers the basics.</para>"));
2251 actionCollection()->action(KStandardAction::name(KStandardAction::KeyBindings
))
2252 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window "
2253 "that lists the <emphasis>keyboard shortcuts</emphasis>.<nl/>"
2254 "There you can set up key combinations to trigger an action when "
2255 "they are pressed simultaneously. All commands in this application can "
2256 "be triggered this way.</para>"));
2257 actionCollection()->action(KStandardAction::name(KStandardAction::ConfigureToolbars
))
2258 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window in which "
2259 "you can change which buttons appear on the <emphasis>Toolbar</emphasis>.</para>"
2260 "<para>All items you see in the <interface>Control</interface> menu "
2261 "or in the <interface>Menubar</interface> can also be placed on the Toolbar.</para>"));
2262 actionCollection()->action(KStandardAction::name(KStandardAction::Preferences
))
2263 ->setWhatsThis(xi18nc("@info:whatsthis","This opens a window where you can "
2264 "change a multitude of settings for this application. For an explanation "
2265 "of the various settings go to the chapter <emphasis>Configuring Dolphin"
2266 "</emphasis> in <interface>Help|Dolphin Handbook</interface>."));
2269 // The whatsthis has to be set for the m_helpMenu and for the
2270 // StandardAction separately because both are used in different locations.
2271 // m_helpMenu is only used for createControlButton() button.
2273 // Links do not work within the Menubar so texts without links are provided there.
2275 // i18n: If the external link isn't available in your language you should
2276 // probably state the external link language at least in brackets to not
2277 // frustrate the user. If there are multiple languages that the user might
2278 // know with a reasonable chance you might want to have 2 external links.
2279 // The same is in my opinion true for every external link you translate.
2280 const QString whatsThisHelpContents
= xi18nc("@info:whatsthis handbook",
2281 "<para>This opens the Handbook for this application. It provides "
2282 "explanations for every part of <emphasis>Dolphin</emphasis>.</para>");
2283 actionCollection()->action(KStandardAction::name(KStandardAction::HelpContents
))
2284 ->setWhatsThis(whatsThisHelpContents
2285 + xi18nc("@info:whatsthis second half of handbook hb text without link",
2286 "<para>If you want more elaborate introductions to the "
2287 "different features of <emphasis>Dolphin</emphasis> "
2288 "go to the KDE UserBase Wiki.</para>"));
2289 m_helpMenu
->action(KHelpMenu::menuHelpContents
)->setWhatsThis(whatsThisHelpContents
2290 + xi18nc("@info:whatsthis second half of handbook text with link",
2291 "<para>If you want more elaborate introductions to the "
2292 "different features of <emphasis>Dolphin</emphasis> "
2293 "<link url='https://userbase.kde.org/Dolphin/File_Management'>click here</link>. "
2294 "It will open the dedicated page in the KDE UserBase Wiki.</para>"));
2296 const QString whatsThisWhatsThis
= xi18nc("@info:whatsthis whatsthis button",
2297 "<para>This is the button that invokes the help feature you are "
2298 "using right now! Click it, then click any component of this "
2299 "application to ask \"What's this?\" about it. The mouse cursor "
2300 "will change appearance if no help is available for a spot.</para>");
2301 actionCollection()->action(KStandardAction::name(KStandardAction::WhatsThis
))
2302 ->setWhatsThis(whatsThisWhatsThis
2303 + xi18nc("@info:whatsthis second half of whatsthis button text without link",
2304 "<para>There are two other ways to get help for this application: The "
2305 "<interface>Dolphin Handbook</interface> in the <interface>Help"
2306 "</interface> menu and the <emphasis>KDE UserBase Wiki</emphasis> "
2307 "article about <emphasis>File Management</emphasis> online."
2308 "</para><para>The \"What's this?\" help is "
2309 "missing in most other windows so don't get too used to this.</para>"));
2310 m_helpMenu
->action(KHelpMenu::menuWhatsThis
)->setWhatsThis(whatsThisWhatsThis
2311 + xi18nc("@info:whatsthis second half of whatsthis button text with link",
2312 "<para>There are two other ways to get help: "
2313 "The <link url='help:/dolphin/index.html'>Dolphin Handbook</link> and "
2314 "the <link url='https://userbase.kde.org/Dolphin/File_Management'>KDE "
2315 "UserBase Wiki</link>.</para><para>The \"What's this?\" help is "
2316 "missing in most other windows so don't get too used to this.</para>"));
2318 const QString whatsThisReportBug
= xi18nc("@info:whatsthis","<para>This opens a "
2319 "window that will guide you through reporting errors or flaws "
2320 "in this application or in other KDE software.</para>");
2321 actionCollection()->action(KStandardAction::name(KStandardAction::ReportBug
))
2322 ->setWhatsThis(whatsThisReportBug
);
2323 m_helpMenu
->action(KHelpMenu::menuReportBug
)->setWhatsThis(whatsThisReportBug
2324 + xi18nc("@info:whatsthis second half of reportbug text with link",
2325 "<para>High-quality bug reports are much appreciated. To learn "
2326 "how to make your bug report as effective as possible "
2327 "<link url='https://community.kde.org/Get_Involved/Bug_Reporting'>"
2328 "click here</link>.</para>"));
2330 const QString whatsThisDonate
= xi18nc("@info:whatsthis","<para>This opens a "
2331 "<emphasis>web page</emphasis> where you can donate to "
2332 "support the continued work on this application and many "
2333 "other projects by the <emphasis>KDE</emphasis> community.</para>"
2334 "<para>Donating is the easiest and fastest way to efficiently "
2335 "support KDE and its projects. KDE projects are available for "
2336 "free therefore your donation is needed to cover things that "
2337 "require money like servers, contributor meetings, etc.</para>"
2338 "<para><emphasis>KDE e.V.</emphasis> is the non-profit "
2339 "organization behind the KDE community.</para>");
2340 actionCollection()->action(KStandardAction::name(KStandardAction::Donate
))
2341 ->setWhatsThis(whatsThisDonate
);
2342 m_helpMenu
->action(KHelpMenu::menuDonate
)->setWhatsThis(whatsThisDonate
);
2344 const QString whatsThisSwitchLanguage
= xi18nc("@info:whatsthis",
2345 "With this you can change the language this application uses."
2346 "<nl/>You can even set secondary languages which will be used "
2347 "if texts are not available in your preferred language.");
2348 actionCollection()->action(KStandardAction::name(KStandardAction::SwitchApplicationLanguage
))
2349 ->setWhatsThis(whatsThisSwitchLanguage
);
2350 m_helpMenu
->action(KHelpMenu::menuSwitchLanguage
)->setWhatsThis(whatsThisSwitchLanguage
);
2352 const QString whatsThisAboutApp
= xi18nc("@info:whatsthis","This opens a "
2353 "window that informs you about the version, license, "
2354 "used libraries and maintainers of this application.");
2355 actionCollection()->action(KStandardAction::name(KStandardAction::AboutApp
))
2356 ->setWhatsThis(whatsThisAboutApp
);
2357 m_helpMenu
->action(KHelpMenu::menuAboutApp
)->setWhatsThis(whatsThisAboutApp
);
2359 const QString whatsThisAboutKDE
= xi18nc("@info:whatsthis","This opens a "
2360 "window with information about <emphasis>KDE</emphasis>. "
2361 "The KDE community are the people behind this free software."
2362 "<nl/>If you like using this application but don't know "
2363 "about KDE or want to see a cute dragon have a look!");
2364 actionCollection()->action(KStandardAction::name(KStandardAction::AboutKDE
))
2365 ->setWhatsThis(whatsThisAboutKDE
);
2366 m_helpMenu
->action(KHelpMenu::menuAboutKDE
)->setWhatsThis(whatsThisAboutKDE
);
2369 bool DolphinMainWindow::addHamburgerMenuToToolbar()
2371 QDomDocument domDocument
= KXMLGUIClient::domDocument();
2372 if (domDocument
.isNull()) {
2375 QDomNode toolbar
= domDocument
.elementsByTagName(QStringLiteral("ToolBar")).at(0);
2376 if (toolbar
.isNull()) {
2380 QDomElement hamburgerMenuElement
= domDocument
.createElement(QStringLiteral("Action"));
2381 hamburgerMenuElement
.setAttribute(QStringLiteral("name"), QStringLiteral("hamburger_menu"));
2382 toolbar
.appendChild(hamburgerMenuElement
);
2384 KXMLGUIFactory::saveConfigFile(domDocument
, xmlFile());
2388 // Make sure to also remove the <KXMLGUIFactory> and <QDomDocument> include
2389 // whenever this method is removed (maybe in the year ~2026).
2392 bool DolphinMainWindow::event(QEvent
*event
)
2394 if (event
->type() == QEvent::WhatsThisClicked
) {
2396 QWhatsThisClickedEvent
* whatsThisEvent
= dynamic_cast<QWhatsThisClickedEvent
*>(event
);
2397 QDesktopServices::openUrl(QUrl(whatsThisEvent
->href()));
2400 return KXmlGuiWindow::event(event
);
2403 bool DolphinMainWindow::eventFilter(QObject
* obj
, QEvent
* event
)
2406 if (event
->type() == QEvent::WhatsThisClicked
) {
2408 QWhatsThisClickedEvent
* whatsThisEvent
= dynamic_cast<QWhatsThisClickedEvent
*>(event
);
2409 QDesktopServices::openUrl(QUrl(whatsThisEvent
->href()));
2415 void DolphinMainWindow::saveNewToolbarConfig()
2417 KXmlGuiWindow::saveNewToolbarConfig(); // Applies the new config. This has to be called first
2418 // because the rest of this method decides things
2419 // based on the new config.
2420 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>
2421 (actionCollection()->action(QStringLiteral("url_navigators")));
2422 if (!toolBar()->actions().contains(navigators
)) {
2423 m_tabWidget
->currentTabPage()->insertNavigatorsWidget(navigators
);
2425 updateAllowedToolbarAreas();
2426 (static_cast<KHamburgerMenu
*>(actionCollection()->action(KStandardAction::name(
2427 KStandardAction::HamburgerMenu
))))->hideActionsOf(toolBar());
2430 void DolphinMainWindow::focusTerminalPanel()
2432 if (m_terminalPanel
->isVisible()) {
2433 if (m_terminalPanel
->terminalHasFocus()) {
2434 m_activeViewContainer
->view()->setFocus(Qt::FocusReason::ShortcutFocusReason
);
2435 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
2437 m_terminalPanel
->setFocus(Qt::FocusReason::ShortcutFocusReason
);
2438 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
2441 actionCollection()->action(QStringLiteral("show_terminal_panel"))->trigger();
2442 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
2446 DolphinMainWindow::UndoUiInterface::UndoUiInterface() :
2447 KIO::FileUndoManager::UiInterface()
2451 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
2455 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
* job
)
2457 DolphinMainWindow
* mainWin
= qobject_cast
<DolphinMainWindow
*>(parentWidget());
2459 DolphinViewContainer
* container
= mainWin
->activeViewContainer();
2460 container
->showMessage(job
->errorString(), DolphinViewContainer::Error
);
2462 KIO::FileUndoManager::UiInterface::jobError(job
);
2466 bool DolphinMainWindow::isUrlOpen(const QString
& url
)
2468 return m_tabWidget
->isUrlOpen(QUrl::fromUserInput((url
)));