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 <kio_version.h>
70 #include <QApplication>
72 #include <QCloseEvent>
73 #include <QDesktopServices>
75 #include <QDomDocument>
79 #include <QPushButton>
81 #include <QStandardPaths>
83 #include <QToolButton>
84 #include <QWhatsThisClickedEvent>
87 // Used for GeneralSettings::version() to determine whether
88 // an updated version of Dolphin is running.
89 const int CurrentDolphinVersion
= 201;
90 // The maximum number of entries in the back/forward popup menu
91 const int MaxNumberOfNavigationentries
= 12;
92 // The maximum number of "Activate Tab" shortcuts
93 const int MaxActivateTabShortcuts
= 9;
96 DolphinMainWindow::DolphinMainWindow() :
97 KXmlGuiWindow(nullptr),
98 m_newFileMenu(nullptr),
100 m_tabWidget(nullptr),
101 m_activeViewContainer(nullptr),
102 m_actionHandler(nullptr),
103 m_remoteEncoding(nullptr),
105 m_bookmarkHandler(nullptr),
106 m_controlButton(nullptr),
107 m_updateToolBarTimer(nullptr),
108 m_lastHandleUrlOpenJob(nullptr),
109 m_terminalPanel(nullptr),
110 m_placesPanel(nullptr),
111 m_tearDownFromPlacesRequested(false),
112 m_backAction(nullptr),
113 m_forwardAction(nullptr)
115 Q_INIT_RESOURCE(dolphin
);
117 new MainWindowAdaptor(this);
120 setWindowFlags(Qt::WindowContextHelpButtonHint
);
122 setComponentName(QStringLiteral("dolphin"), QGuiApplication::applicationDisplayName());
123 setObjectName(QStringLiteral("Dolphin#"));
125 connect(&DolphinNewFileMenuObserver::instance(), &DolphinNewFileMenuObserver::errorMessage
,
126 this, &DolphinMainWindow::showErrorMessage
);
128 KIO::FileUndoManager
* undoManager
= KIO::FileUndoManager::self();
129 undoManager
->setUiInterface(new UndoUiInterface());
131 connect(undoManager
, QOverload
<bool>::of(&KIO::FileUndoManager::undoAvailable
),
132 this, &DolphinMainWindow::slotUndoAvailable
);
133 connect(undoManager
, &KIO::FileUndoManager::undoTextChanged
,
134 this, &DolphinMainWindow::slotUndoTextChanged
);
135 connect(undoManager
, &KIO::FileUndoManager::jobRecordingStarted
,
136 this, &DolphinMainWindow::clearStatusBar
);
137 connect(undoManager
, &KIO::FileUndoManager::jobRecordingFinished
,
138 this, &DolphinMainWindow::showCommand
);
140 const bool firstRun
= (GeneralSettings::version() < 200);
142 GeneralSettings::setViewPropsTimestamp(QDateTime::currentDateTime());
145 setAcceptDrops(true);
147 auto *navigatorsWidgetAction
= new DolphinNavigatorsWidgetAction(this);
148 actionCollection()->addAction(QStringLiteral("url_navigators"), navigatorsWidgetAction
);
149 m_tabWidget
= new DolphinTabWidget(navigatorsWidgetAction
, this);
150 m_tabWidget
->setObjectName("tabWidget");
151 connect(m_tabWidget
, &DolphinTabWidget::activeViewChanged
,
152 this, &DolphinMainWindow::activeViewChanged
);
153 connect(m_tabWidget
, &DolphinTabWidget::tabCountChanged
,
154 this, &DolphinMainWindow::tabCountChanged
);
155 connect(m_tabWidget
, &DolphinTabWidget::currentUrlChanged
,
156 this, &DolphinMainWindow::updateWindowTitle
);
157 setCentralWidget(m_tabWidget
);
161 m_actionHandler
= new DolphinViewActionHandler(actionCollection(), this);
162 connect(m_actionHandler
, &DolphinViewActionHandler::actionBeingHandled
, this, &DolphinMainWindow::clearStatusBar
);
163 connect(m_actionHandler
, &DolphinViewActionHandler::createDirectoryTriggered
, this, &DolphinMainWindow::createDirectory
);
165 m_remoteEncoding
= new DolphinRemoteEncoding(this, m_actionHandler
);
166 connect(this, &DolphinMainWindow::urlChanged
,
167 m_remoteEncoding
, &DolphinRemoteEncoding::slotAboutToOpenUrl
);
171 setupGUI(Keys
| Save
| Create
| ToolBar
);
172 stateChanged(QStringLiteral("new_file"));
174 QClipboard
* clipboard
= QApplication::clipboard();
175 connect(clipboard
, &QClipboard::dataChanged
,
176 this, &DolphinMainWindow::updatePasteAction
);
178 QAction
* toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
179 toggleFilterBarAction
->setChecked(GeneralSettings::filterBar());
182 menuBar()->setVisible(false);
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
->setShowMenuBarAction(showMenuBarAction
);
193 connect(hamburgerMenu
, &KHamburgerMenu::aboutToShowMenu
,
194 this, &DolphinMainWindow::updateHamburgerMenu
);
195 hamburgerMenu
->hideActionsOf(toolBar());
196 if (GeneralSettings::version() < 201 && !toolBar()->actions().contains(hamburgerMenu
)) {
197 addHamburgerMenuToToolbar();
200 updateAllowedToolbarAreas();
202 // enable middle-click on back/forward/up to open in a new tab
203 auto *middleClickEventFilter
= new MiddleClickActionEventFilter(this);
204 connect(middleClickEventFilter
, &MiddleClickActionEventFilter::actionMiddleClicked
, this, &DolphinMainWindow::slotToolBarActionMiddleClicked
);
205 toolBar()->installEventFilter(middleClickEventFilter
);
209 connect(KSycoca::self(), QOverload
<>::of(&KSycoca::databaseChanged
), this, &DolphinMainWindow::updateOpenPreferredSearchToolAction
);
211 QTimer::singleShot(0, this, &DolphinMainWindow::updateOpenPreferredSearchToolAction
);
213 m_fileItemActions
.setParentWidget(this);
214 connect(&m_fileItemActions
, &KFileItemActions::error
, this, [this](const QString
&errorMessage
) {
215 showErrorMessage(errorMessage
);
219 DolphinMainWindow::~DolphinMainWindow()
221 // This fixes a crash on Wayland when closing the mainwindow while another dialog is open.
222 disconnect(QGuiApplication::clipboard(), &QClipboard::dataChanged
, this, &DolphinMainWindow::updatePasteAction
);
225 QVector
<DolphinViewContainer
*> DolphinMainWindow::viewContainers() const
227 QVector
<DolphinViewContainer
*> viewContainers
;
229 for (int i
= 0; i
< m_tabWidget
->count(); ++i
) {
230 DolphinTabPage
*tabPage
= m_tabWidget
->tabPageAt(i
);
232 viewContainers
<< tabPage
->primaryViewContainer();
233 if (tabPage
->splitViewEnabled()) {
234 viewContainers
<< tabPage
->secondaryViewContainer();
237 return viewContainers
;
240 void DolphinMainWindow::openDirectories(const QList
<QUrl
>& dirs
, bool splitView
)
242 m_tabWidget
->openDirectories(dirs
, splitView
);
245 void DolphinMainWindow::openDirectories(const QStringList
& dirs
, bool splitView
)
247 openDirectories(QUrl::fromStringList(dirs
), splitView
);
250 void DolphinMainWindow::openFiles(const QList
<QUrl
>& files
, bool splitView
)
252 m_tabWidget
->openFiles(files
, splitView
);
255 bool DolphinMainWindow::isFoldersPanelEnabled() const
257 return actionCollection()->action(QStringLiteral("show_folders_panel"))->isChecked();
260 bool DolphinMainWindow::isInformationPanelEnabled() const
263 return actionCollection()->action(QStringLiteral("show_information_panel"))->isChecked();
269 void DolphinMainWindow::openFiles(const QStringList
& files
, bool splitView
)
271 openFiles(QUrl::fromStringList(files
), splitView
);
274 void DolphinMainWindow::activateWindow()
276 window()->setAttribute(Qt::WA_NativeWindow
, true);
277 KStartupInfo::setNewStartupId(window()->windowHandle(), KStartupInfo::startupId());
278 KWindowSystem::activateWindow(window()->effectiveWinId());
281 void DolphinMainWindow::showCommand(CommandType command
)
283 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
285 case KIO::FileUndoManager::Copy
:
286 statusBar
->setText(i18nc("@info:status", "Successfully copied."));
288 case KIO::FileUndoManager::Move
:
289 statusBar
->setText(i18nc("@info:status", "Successfully moved."));
291 case KIO::FileUndoManager::Link
:
292 statusBar
->setText(i18nc("@info:status", "Successfully linked."));
294 case KIO::FileUndoManager::Trash
:
295 statusBar
->setText(i18nc("@info:status", "Successfully moved to trash."));
297 case KIO::FileUndoManager::Rename
:
298 statusBar
->setText(i18nc("@info:status", "Successfully renamed."));
301 case KIO::FileUndoManager::Mkdir
:
302 statusBar
->setText(i18nc("@info:status", "Created folder."));
310 void DolphinMainWindow::pasteIntoFolder()
312 m_activeViewContainer
->view()->pasteIntoFolder();
315 void DolphinMainWindow::changeUrl(const QUrl
&url
)
317 if (!KProtocolManager::supportsListing(url
)) {
318 // The URL navigator only checks for validity, not
319 // if the URL can be listed. An error message is
320 // shown due to DolphinViewContainer::restoreView().
324 m_activeViewContainer
->setUrl(url
);
325 updateFileAndEditActions();
330 Q_EMIT
urlChanged(url
);
333 void DolphinMainWindow::slotTerminalDirectoryChanged(const QUrl
& url
)
335 if (m_tearDownFromPlacesRequested
&& url
== QUrl::fromLocalFile(QDir::homePath())) {
336 m_placesPanel
->proceedWithTearDown();
337 m_tearDownFromPlacesRequested
= false;
340 m_activeViewContainer
->setAutoGrabFocus(false);
342 m_activeViewContainer
->setAutoGrabFocus(true);
345 void DolphinMainWindow::slotEditableStateChanged(bool editable
)
347 KToggleAction
* editableLocationAction
=
348 static_cast<KToggleAction
*>(actionCollection()->action(QStringLiteral("editable_location")));
349 editableLocationAction
->setChecked(editable
);
352 void DolphinMainWindow::slotSelectionChanged(const KFileItemList
& selection
)
354 updateFileAndEditActions();
356 const int selectedUrlsCount
= m_tabWidget
->currentTabPage()->selectedItemsCount();
358 QAction
* compareFilesAction
= actionCollection()->action(QStringLiteral("compare_files"));
359 if (selectedUrlsCount
== 2) {
360 compareFilesAction
->setEnabled(isKompareInstalled());
362 compareFilesAction
->setEnabled(false);
365 Q_EMIT
selectionChanged(selection
);
368 void DolphinMainWindow::updateHistory()
370 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
371 const int index
= urlNavigator
->historyIndex();
373 QAction
* backAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Back
));
375 backAction
->setToolTip(i18nc("@info", "Go back"));
376 backAction
->setWhatsThis(i18nc("@info:whatsthis go back", "Return to the previously viewed folder."));
377 backAction
->setEnabled(index
< urlNavigator
->historySize() - 1);
380 QAction
* forwardAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Forward
));
382 forwardAction
->setToolTip(i18nc("@info", "Go forward"));
383 forwardAction
->setWhatsThis(xi18nc("@info:whatsthis go forward",
384 "This undoes a <interface>Go|Back</interface> action."));
385 forwardAction
->setEnabled(index
> 0);
389 void DolphinMainWindow::updateFilterBarAction(bool show
)
391 QAction
* toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
392 toggleFilterBarAction
->setChecked(show
);
395 void DolphinMainWindow::openNewMainWindow()
397 Dolphin::openNewWindow({m_activeViewContainer
->url()}, this);
400 void DolphinMainWindow::openNewActivatedTab()
402 // keep browsers compatibility, new tab is always after last one
403 auto openNewTabAfterLastTabConfigured
= GeneralSettings::openNewTabAfterLastTab();
404 GeneralSettings::setOpenNewTabAfterLastTab(true);
405 m_tabWidget
->openNewActivatedTab();
406 GeneralSettings::setOpenNewTabAfterLastTab(openNewTabAfterLastTabConfigured
);
409 void DolphinMainWindow::addToPlaces()
414 // If nothing is selected, act on the current dir
415 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
416 url
= m_activeViewContainer
->url();
417 name
= m_activeViewContainer
->placesText();
419 const auto dirToAdd
= m_activeViewContainer
->view()->selectedItems().first();
420 url
= dirToAdd
.url();
421 name
= dirToAdd
.name();
424 PlacesItemModel model
;
426 if (m_activeViewContainer
->isSearchModeEnabled()) {
427 icon
= QStringLiteral("folder-saved-search-symbolic");
429 icon
= KIO::iconNameForUrl(url
);
431 model
.createPlacesItem(name
, url
, icon
);
435 void DolphinMainWindow::openNewTab(const QUrl
& url
)
437 m_tabWidget
->openNewTab(url
, QUrl());
440 void DolphinMainWindow::openInNewTab()
442 const KFileItemList
& list
= m_activeViewContainer
->view()->selectedItems();
443 bool tabCreated
= false;
445 for (const KFileItem
& item
: list
) {
446 const QUrl
& url
= DolphinView::openItemAsFolderUrl(item
);
447 if (!url
.isEmpty()) {
453 // if no new tab has been created from the selection
454 // open the current directory in a new tab
456 openNewTab(m_activeViewContainer
->url());
460 void DolphinMainWindow::openInNewWindow()
464 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
465 if (list
.isEmpty()) {
466 newWindowUrl
= m_activeViewContainer
->url();
467 } else if (list
.count() == 1) {
468 const KFileItem
& item
= list
.first();
469 newWindowUrl
= DolphinView::openItemAsFolderUrl(item
);
472 if (!newWindowUrl
.isEmpty()) {
473 Dolphin::openNewWindow({newWindowUrl
}, this);
477 void DolphinMainWindow::showTarget()
479 const auto link
= m_activeViewContainer
->view()->selectedItems().at(0);
480 const auto linkLocationDir
= QFileInfo(link
.localPath()).absoluteDir();
481 auto linkDestination
= link
.linkDest();
482 if (QFileInfo(linkDestination
).isRelative()) {
483 linkDestination
= linkLocationDir
.filePath(linkDestination
);
485 if (QFileInfo::exists(linkDestination
)) {
486 KIO::highlightInFileManager({QUrl::fromLocalFile(linkDestination
).adjusted(QUrl::StripTrailingSlash
)});
488 m_activeViewContainer
->showMessage(xi18nc("@info", "Could not access <filename>%1</filename>.", linkDestination
),
489 DolphinViewContainer::Warning
);
493 void DolphinMainWindow::showEvent(QShowEvent
* event
)
495 KXmlGuiWindow::showEvent(event
);
497 if (!event
->spontaneous()) {
498 m_activeViewContainer
->view()->setFocus();
502 void DolphinMainWindow::closeEvent(QCloseEvent
* event
)
504 // Find out if Dolphin is closed directly by the user or
505 // by the session manager because the session is closed
506 bool closedByUser
= true;
507 if (qApp
->isSavingSession()) {
508 closedByUser
= false;
511 if (m_tabWidget
->count() > 1
512 && GeneralSettings::confirmClosingMultipleTabs()
513 && !GeneralSettings::rememberOpenedTabs()
515 // Ask the user if he really wants to quit and close all tabs.
516 // Open a confirmation dialog with 3 buttons:
517 // QDialogButtonBox::Yes -> Quit
518 // QDialogButtonBox::No -> Close only the current tab
519 // QDialogButtonBox::Cancel -> do nothing
520 QDialog
*dialog
= new QDialog(this, Qt::Dialog
);
521 dialog
->setWindowTitle(i18nc("@title:window", "Confirmation"));
522 dialog
->setModal(true);
523 QDialogButtonBox
* buttons
= new QDialogButtonBox(QDialogButtonBox::Yes
| QDialogButtonBox::No
| QDialogButtonBox::Cancel
);
524 KGuiItem::assign(buttons
->button(QDialogButtonBox::Yes
), KGuiItem(i18nc("@action:button 'Quit Dolphin' button", "&Quit %1", QGuiApplication::applicationDisplayName()), QIcon::fromTheme(QStringLiteral("application-exit"))));
525 KGuiItem::assign(buttons
->button(QDialogButtonBox::No
), KGuiItem(i18n("C&lose Current Tab"), QIcon::fromTheme(QStringLiteral("tab-close"))));
526 KGuiItem::assign(buttons
->button(QDialogButtonBox::Cancel
), KStandardGuiItem::cancel());
527 buttons
->button(QDialogButtonBox::Yes
)->setDefault(true);
529 bool doNotAskAgainCheckboxResult
= false;
531 const auto result
= KMessageBox::createKMessageBox(dialog
,
533 QMessageBox::Warning
,
534 i18n("You have multiple tabs open in this window, are you sure you want to quit?"),
536 i18n("Do not ask again"),
537 &doNotAskAgainCheckboxResult
,
538 KMessageBox::Notify
);
540 if (doNotAskAgainCheckboxResult
) {
541 GeneralSettings::setConfirmClosingMultipleTabs(false);
545 case QDialogButtonBox::Yes
:
548 case QDialogButtonBox::No
:
549 // Close only the current tab
550 m_tabWidget
->closeTab();
558 if (m_terminalPanel
&& m_terminalPanel
->hasProgramRunning() && GeneralSettings::confirmClosingTerminalRunningProgram() && closedByUser
) {
559 // Ask if the user really wants to quit Dolphin with a program that is still running in the Terminal panel
560 // Open a confirmation dialog with 3 buttons:
561 // QDialogButtonBox::Yes -> Quit
562 // QDialogButtonBox::No -> Show Terminal Panel
563 // QDialogButtonBox::Cancel -> do nothing
564 QDialog
*dialog
= new QDialog(this, Qt::Dialog
);
565 dialog
->setWindowTitle(i18nc("@title:window", "Confirmation"));
566 dialog
->setModal(true);
567 auto standardButtons
= QDialogButtonBox::Yes
| QDialogButtonBox::Cancel
;
568 if (!m_terminalPanel
->isVisible()) {
569 standardButtons
|= QDialogButtonBox::No
;
571 QDialogButtonBox
*buttons
= new QDialogButtonBox(standardButtons
);
572 KGuiItem::assign(buttons
->button(QDialogButtonBox::Yes
), KStandardGuiItem::quit());
573 if (!m_terminalPanel
->isVisible()) {
575 buttons
->button(QDialogButtonBox::No
),
576 KGuiItem(i18n("Show &Terminal Panel"), QIcon::fromTheme(QStringLiteral("dialog-scripts"))));
578 KGuiItem::assign(buttons
->button(QDialogButtonBox::Cancel
), KStandardGuiItem::cancel());
580 bool doNotAskAgainCheckboxResult
= false;
582 const auto result
= KMessageBox::createKMessageBox(
585 QMessageBox::Warning
,
586 i18n("The program '%1' is still running in the Terminal panel. Are you sure you want to quit?", m_terminalPanel
->runningProgramName()),
588 i18n("Do not ask again"),
589 &doNotAskAgainCheckboxResult
,
590 KMessageBox::Dangerous
);
592 if (doNotAskAgainCheckboxResult
) {
593 GeneralSettings::setConfirmClosingTerminalRunningProgram(false);
597 case QDialogButtonBox::Yes
:
600 case QDialogButtonBox::No
:
601 actionCollection()->action("show_terminal_panel")->trigger();
602 // Do not quit, ignore quit event
610 if (GeneralSettings::rememberOpenedTabs()) {
611 KConfigGui::setSessionConfig(QStringLiteral("dolphin"), QStringLiteral("dolphin"));
612 KConfig
*config
= KConfigGui::sessionConfig();
613 saveGlobalProperties(config
);
614 savePropertiesInternal(config
, 1);
618 GeneralSettings::setVersion(CurrentDolphinVersion
);
619 GeneralSettings::self()->save();
621 KXmlGuiWindow::closeEvent(event
);
624 void DolphinMainWindow::saveProperties(KConfigGroup
& group
)
626 m_tabWidget
->saveProperties(group
);
629 void DolphinMainWindow::readProperties(const KConfigGroup
& group
)
631 m_tabWidget
->readProperties(group
);
634 void DolphinMainWindow::updateNewMenu()
636 m_newFileMenu
->setViewShowsHiddenFiles(activeViewContainer()->view()->hiddenFilesShown());
637 m_newFileMenu
->checkUpToDate();
638 m_newFileMenu
->setPopupFiles(QList
<QUrl
>() << activeViewContainer()->url());
641 void DolphinMainWindow::createDirectory()
643 m_newFileMenu
->setViewShowsHiddenFiles(activeViewContainer()->view()->hiddenFilesShown());
644 m_newFileMenu
->setPopupFiles(QList
<QUrl
>() << activeViewContainer()->url());
645 m_newFileMenu
->createDirectory();
648 void DolphinMainWindow::quit()
653 void DolphinMainWindow::showErrorMessage(const QString
& message
)
655 m_activeViewContainer
->showMessage(message
, DolphinViewContainer::Error
);
658 void DolphinMainWindow::slotUndoAvailable(bool available
)
660 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
662 undoAction
->setEnabled(available
);
666 void DolphinMainWindow::slotUndoTextChanged(const QString
& text
)
668 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
670 undoAction
->setText(text
);
674 void DolphinMainWindow::undo()
677 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
678 KIO::FileUndoManager::self()->undo();
681 void DolphinMainWindow::cut()
683 m_activeViewContainer
->view()->cutSelectedItemsToClipboard();
686 void DolphinMainWindow::copy()
688 m_activeViewContainer
->view()->copySelectedItemsToClipboard();
691 void DolphinMainWindow::paste()
693 m_activeViewContainer
->view()->paste();
696 void DolphinMainWindow::find()
698 m_activeViewContainer
->setSearchModeEnabled(true);
701 void DolphinMainWindow::updateSearchAction()
703 QAction
* toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
704 toggleSearchAction
->setChecked(m_activeViewContainer
->isSearchModeEnabled());
707 void DolphinMainWindow::updatePasteAction()
709 QAction
* pasteAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Paste
));
710 QPair
<bool, QString
> pasteInfo
= m_activeViewContainer
->view()->pasteInfo();
711 pasteAction
->setEnabled(pasteInfo
.first
);
712 pasteAction
->setText(pasteInfo
.second
);
715 void DolphinMainWindow::slotDirectoryLoadingCompleted()
720 void DolphinMainWindow::slotToolBarActionMiddleClicked(QAction
*action
)
722 if (action
== actionCollection()->action(KStandardAction::name(KStandardAction::Back
))) {
724 } else if (action
== actionCollection()->action(KStandardAction::name(KStandardAction::Forward
))) {
726 } else if (action
== actionCollection()->action(QStringLiteral("go_up"))) {
728 } else if (action
== actionCollection()->action(QStringLiteral("go_home"))) {
733 void DolphinMainWindow::slotAboutToShowBackPopupMenu()
735 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
737 m_backAction
->menu()->clear();
738 for (int i
= urlNavigator
->historyIndex() + 1; i
< urlNavigator
->historySize() && entries
< MaxNumberOfNavigationentries
; ++i
, ++entries
) {
739 QAction
* action
= new QAction(urlNavigator
->locationUrl(i
).toString(QUrl::PreferLocalFile
), m_backAction
->menu());
741 m_backAction
->menu()->addAction(action
);
745 void DolphinMainWindow::slotGoBack(QAction
* action
)
747 int gotoIndex
= action
->data().value
<int>();
748 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
749 for (int i
= gotoIndex
- urlNavigator
->historyIndex(); i
> 0; --i
) {
754 void DolphinMainWindow::slotBackForwardActionMiddleClicked(QAction
* action
)
757 const KUrlNavigator
*urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
758 openNewTab(urlNavigator
->locationUrl(action
->data().value
<int>()));
762 void DolphinMainWindow::slotAboutToShowForwardPopupMenu()
764 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
766 m_forwardAction
->menu()->clear();
767 for (int i
= urlNavigator
->historyIndex() - 1; i
>= 0 && entries
< MaxNumberOfNavigationentries
; --i
, ++entries
) {
768 QAction
* action
= new QAction(urlNavigator
->locationUrl(i
).toString(QUrl::PreferLocalFile
), m_forwardAction
->menu());
770 m_forwardAction
->menu()->addAction(action
);
774 void DolphinMainWindow::slotGoForward(QAction
* action
)
776 int gotoIndex
= action
->data().value
<int>();
777 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
778 for (int i
= urlNavigator
->historyIndex() - gotoIndex
; i
> 0; --i
) {
783 void DolphinMainWindow::selectAll()
787 // if the URL navigator is editable and focused, select the whole
788 // URL instead of all items of the view
790 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
791 QLineEdit
* lineEdit
= urlNavigator
->editor()->lineEdit();
792 const bool selectUrl
= urlNavigator
->isUrlEditable() &&
793 lineEdit
->hasFocus();
795 lineEdit
->selectAll();
797 m_activeViewContainer
->view()->selectAll();
801 void DolphinMainWindow::invertSelection()
804 m_activeViewContainer
->view()->invertSelection();
807 void DolphinMainWindow::toggleSplitView()
809 DolphinTabPage
* tabPage
= m_tabWidget
->currentTabPage();
810 tabPage
->setSplitViewEnabled(!tabPage
->splitViewEnabled(), WithAnimation
);
815 void DolphinMainWindow::toggleSplitStash()
817 DolphinTabPage
* tabPage
= m_tabWidget
->currentTabPage();
818 tabPage
->setSplitViewEnabled(false, WithAnimation
);
819 tabPage
->setSplitViewEnabled(true, WithAnimation
, QUrl("stash:/"));
822 void DolphinMainWindow::reloadView()
825 m_activeViewContainer
->reload();
826 m_activeViewContainer
->statusBar()->updateSpaceInfo();
829 void DolphinMainWindow::stopLoading()
831 m_activeViewContainer
->view()->stopLoading();
834 void DolphinMainWindow::enableStopAction()
836 actionCollection()->action(QStringLiteral("stop"))->setEnabled(true);
839 void DolphinMainWindow::disableStopAction()
841 actionCollection()->action(QStringLiteral("stop"))->setEnabled(false);
844 void DolphinMainWindow::showFilterBar()
846 m_activeViewContainer
->setFilterBarVisible(true);
849 void DolphinMainWindow::toggleFilterBar()
851 const bool checked
= !m_activeViewContainer
->isFilterBarVisible();
852 m_activeViewContainer
->setFilterBarVisible(checked
);
854 QAction
* toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
855 toggleFilterBarAction
->setChecked(checked
);
858 void DolphinMainWindow::toggleEditLocation()
862 QAction
* action
= actionCollection()->action(QStringLiteral("editable_location"));
863 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
864 urlNavigator
->setUrlEditable(action
->isChecked());
867 void DolphinMainWindow::replaceLocation()
869 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
870 QLineEdit
* lineEdit
= navigator
->editor()->lineEdit();
872 // If the text field currently has focus and everything is selected,
873 // pressing the keyboard shortcut returns the whole thing to breadcrumb mode
874 if (navigator
->isUrlEditable()
875 && lineEdit
->hasFocus()
876 && lineEdit
->selectedText() == lineEdit
->text() ) {
877 navigator
->setUrlEditable(false);
879 navigator
->setUrlEditable(true);
880 navigator
->setFocus();
881 lineEdit
->selectAll();
885 void DolphinMainWindow::togglePanelLockState()
887 const bool newLockState
= !GeneralSettings::lockPanels();
888 const auto childrenObjects
= children();
889 for (QObject
* child
: childrenObjects
) {
890 DolphinDockWidget
* dock
= qobject_cast
<DolphinDockWidget
*>(child
);
892 dock
->setLocked(newLockState
);
896 GeneralSettings::setLockPanels(newLockState
);
899 void DolphinMainWindow::slotTerminalPanelVisibilityChanged()
901 if (m_terminalPanel
->isHiddenInVisibleWindow() && m_activeViewContainer
) {
902 m_activeViewContainer
->view()->setFocus();
906 void DolphinMainWindow::goBack()
908 DolphinUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
909 urlNavigator
->goBack();
911 if (urlNavigator
->locationState().isEmpty()) {
912 // An empty location state indicates a redirection URL,
913 // which must be skipped too
914 urlNavigator
->goBack();
918 void DolphinMainWindow::goForward()
920 m_activeViewContainer
->urlNavigatorInternalWithHistory()->goForward();
923 void DolphinMainWindow::goUp()
925 m_activeViewContainer
->urlNavigatorInternalWithHistory()->goUp();
928 void DolphinMainWindow::goHome()
930 m_activeViewContainer
->urlNavigatorInternalWithHistory()->goHome();
933 void DolphinMainWindow::goBackInNewTab()
935 const KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
936 const int index
= urlNavigator
->historyIndex() + 1;
937 openNewTab(urlNavigator
->locationUrl(index
));
940 void DolphinMainWindow::goForwardInNewTab()
942 const KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
943 const int index
= urlNavigator
->historyIndex() - 1;
944 openNewTab(urlNavigator
->locationUrl(index
));
947 void DolphinMainWindow::goUpInNewTab()
949 const QUrl currentUrl
= activeViewContainer()->urlNavigator()->locationUrl();
950 openNewTab(KIO::upUrl(currentUrl
));
953 void DolphinMainWindow::goHomeInNewTab()
955 openNewTab(Dolphin::homeUrl());
958 void DolphinMainWindow::compareFiles()
960 const KFileItemList items
= m_tabWidget
->currentTabPage()->selectedItems();
961 if (items
.count() != 2) {
962 // The action is disabled in this case, but it could have been triggered
963 // via D-Bus, see https://bugs.kde.org/show_bug.cgi?id=325517
967 QUrl urlA
= items
.at(0).url();
968 QUrl urlB
= items
.at(1).url();
970 QString
command(QStringLiteral("kompare -c \""));
971 command
.append(urlA
.toDisplayString(QUrl::PreferLocalFile
));
972 command
.append("\" \"");
973 command
.append(urlB
.toDisplayString(QUrl::PreferLocalFile
));
974 command
.append('\"');
976 KIO::CommandLauncherJob
*job
= new KIO::CommandLauncherJob(command
, this);
977 job
->setDesktopName(QStringLiteral("org.kde.kompare"));
981 void DolphinMainWindow::toggleShowMenuBar()
983 const bool visible
= menuBar()->isVisible();
984 menuBar()->setVisible(!visible
);
987 QPointer
<QAction
> DolphinMainWindow::preferredSearchTool()
989 m_searchTools
.clear();
990 KMoreToolsMenuFactory("dolphin/search-tools").fillMenuFromGroupingNames(
991 &m_searchTools
, { "files-find" }, m_activeViewContainer
->url()
993 QList
<QAction
*> actions
= m_searchTools
.actions();
994 if (actions
.isEmpty()) {
997 QAction
* action
= actions
.first();
998 if (action
->isSeparator()) {
1004 void DolphinMainWindow::updateOpenPreferredSearchToolAction()
1006 QAction
* openPreferredSearchTool
= actionCollection()->action(QStringLiteral("open_preferred_search_tool"));
1007 if (!openPreferredSearchTool
) {
1010 QPointer
<QAction
> tool
= preferredSearchTool();
1012 openPreferredSearchTool
->setVisible(true);
1013 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open %1", tool
->text()));
1014 openPreferredSearchTool
->setIcon(tool
->icon());
1016 openPreferredSearchTool
->setVisible(false);
1017 // still visible in Shortcuts configuration window
1018 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool"));
1019 openPreferredSearchTool
->setIcon(QIcon::fromTheme(QStringLiteral("search")));
1023 void DolphinMainWindow::openPreferredSearchTool()
1025 QPointer
<QAction
> tool
= preferredSearchTool();
1031 void DolphinMainWindow::openTerminal()
1033 const QUrl url
= m_activeViewContainer
->url();
1035 if (url
.isLocalFile()) {
1036 KToolInvocation::invokeTerminal(QString(), {}, url
.toLocalFile());
1040 // Not a local file, with protocol Class ":local", try stat'ing
1041 if (KProtocolInfo::protocolClass(url
.scheme()) == QLatin1String(":local")) {
1042 KIO::StatJob
*job
= KIO::mostLocalUrl(url
);
1043 KJobWidgets::setWindow(job
, this);
1044 connect(job
, &KJob::result
, this, [job
]() {
1046 if (!job
->error()) {
1047 statUrl
= job
->mostLocalUrl();
1050 KToolInvocation::invokeTerminal(QString(), {}, statUrl
.isLocalFile() ? statUrl
.toLocalFile() : QDir::homePath());
1056 // Nothing worked, just use $HOME
1057 KToolInvocation::invokeTerminal(QString(), {}, QDir::homePath());
1060 void DolphinMainWindow::editSettings()
1062 if (!m_settingsDialog
) {
1063 DolphinViewContainer
* container
= activeViewContainer();
1064 container
->view()->writeSettings();
1066 const QUrl url
= container
->url();
1067 DolphinSettingsDialog
* settingsDialog
= new DolphinSettingsDialog(url
, this, actionCollection());
1068 connect(settingsDialog
, &DolphinSettingsDialog::settingsChanged
, this, &DolphinMainWindow::refreshViews
);
1069 connect(settingsDialog
, &DolphinSettingsDialog::settingsChanged
,
1070 &DolphinUrlNavigatorsController::slotReadSettings
);
1071 settingsDialog
->setAttribute(Qt::WA_DeleteOnClose
);
1072 settingsDialog
->show();
1073 m_settingsDialog
= settingsDialog
;
1075 m_settingsDialog
.data()->raise();
1079 void DolphinMainWindow::handleUrl(const QUrl
& url
)
1081 delete m_lastHandleUrlOpenJob
;
1082 m_lastHandleUrlOpenJob
= nullptr;
1084 if (url
.isLocalFile() && QFileInfo(url
.toLocalFile()).isDir()) {
1085 activeViewContainer()->setUrl(url
);
1087 m_lastHandleUrlOpenJob
= new KIO::OpenUrlJob(url
);
1088 m_lastHandleUrlOpenJob
->setUiDelegate(new KIO::JobUiDelegate(KJobUiDelegate::AutoHandlingEnabled
, this));
1089 m_lastHandleUrlOpenJob
->setShowOpenOrExecuteDialog(true);
1091 connect(m_lastHandleUrlOpenJob
, &KIO::OpenUrlJob::mimeTypeFound
, this,
1092 [this, url
](const QString
&mimetype
) {
1093 if (mimetype
== QLatin1String("inode/directory")) {
1094 // If it's a dir, we'll take it from here
1095 m_lastHandleUrlOpenJob
->kill();
1096 m_lastHandleUrlOpenJob
= nullptr;
1097 activeViewContainer()->setUrl(url
);
1101 connect(m_lastHandleUrlOpenJob
, &KIO::OpenUrlJob::result
, this, [this]() {
1102 m_lastHandleUrlOpenJob
= nullptr;
1105 m_lastHandleUrlOpenJob
->start();
1109 void DolphinMainWindow::slotWriteStateChanged(bool isFolderWritable
)
1111 // trash:/ is writable but we don't want to create new items in it.
1112 // TODO: remove the trash check once https://phabricator.kde.org/T8234 is implemented
1113 newFileMenu()->setEnabled(isFolderWritable
&& m_activeViewContainer
->url().scheme() != QLatin1String("trash"));
1116 void DolphinMainWindow::openContextMenu(const QPoint
& pos
,
1117 const KFileItem
& item
,
1119 const QList
<QAction
*>& customActions
)
1121 QPointer
<DolphinContextMenu
> contextMenu
= new DolphinContextMenu(this, pos
, item
, url
, &m_fileItemActions
);
1122 contextMenu
.data()->setCustomActions(customActions
);
1123 const DolphinContextMenu::Command command
= contextMenu
.data()->open();
1126 case DolphinContextMenu::OpenParentFolder
:
1127 changeUrl(KIO::upUrl(item
.url()));
1128 m_activeViewContainer
->view()->markUrlsAsSelected({item
.url()});
1129 m_activeViewContainer
->view()->markUrlAsCurrent(item
.url());
1132 case DolphinContextMenu::OpenParentFolderInNewWindow
:
1133 Dolphin::openNewWindow({item
.url()}, this, Dolphin::OpenNewWindowFlag::Select
);
1136 case DolphinContextMenu::OpenParentFolderInNewTab
:
1137 openNewTab(KIO::upUrl(item
.url()));
1140 case DolphinContextMenu::None
:
1145 // Delete the menu, unless it has been deleted in its own nested event loop already.
1147 contextMenu
->deleteLater();
1151 void DolphinMainWindow::updateHamburgerMenu()
1153 KActionCollection
* ac
= actionCollection();
1154 auto hamburgerMenu
= static_cast<KHamburgerMenu
*>(
1155 ac
->action(KStandardAction::name(KStandardAction::HamburgerMenu
)));
1156 auto menu
= hamburgerMenu
->menu();
1158 menu
= new QMenu(this);
1159 hamburgerMenu
->setMenu(menu
);
1160 hamburgerMenu
->hideActionsOf(ac
->action(QStringLiteral("basic_actions"))->menu());
1161 hamburgerMenu
->hideActionsOf(ac
->action(QStringLiteral("zoom"))->menu());
1165 const QList
<QAction
*> toolbarActions
= toolBar()->actions();
1167 if (!toolBar()->isVisible()) {
1168 // If neither the menu bar nor the toolbar are visible, these actions should be available.
1169 menu
->addAction(ac
->action(KStandardAction::name(KStandardAction::ShowMenubar
)));
1170 menu
->addAction(toolBarMenuAction());
1171 menu
->addSeparator();
1174 // This group of actions (until the next separator) contains all the most basic actions
1175 // necessary to use Dolphin effectively.
1176 menu
->addAction(ac
->action(QStringLiteral("go_back")));
1177 menu
->addAction(ac
->action(QStringLiteral("go_forward")));
1179 menu
->addMenu(m_newFileMenu
->menu());
1180 menu
->addAction(ac
->action(QStringLiteral("basic_actions")));
1181 menu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Undo
)));
1182 if (!toolBar()->isVisible()
1183 || (!toolbarActions
.contains(ac
->action(QStringLiteral("toggle_search")))
1184 && !toolbarActions
.contains(ac
->action(QStringLiteral("open_preferred_search_tool"))))
1186 menu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Find
)));
1187 // This way a search action will only be added if none of the three available
1188 // search actions is present on the toolbar.
1190 if (!toolBar()->isVisible()
1191 || !toolbarActions
.contains(ac
->action(QStringLiteral("toggle_filter")))
1193 menu
->addAction(ac
->action(QStringLiteral("show_filter_bar")));
1194 // This way a filter action will only be added if none of the two available
1195 // filter actions is present on the toolbar.
1197 menu
->addSeparator();
1199 // The second group of actions (up until the next separator) contains actions for opening
1200 // additional views to interact with the file system.
1201 menu
->addAction(ac
->action(QStringLiteral("file_new")));
1202 menu
->addAction(ac
->action(QStringLiteral("new_tab")));
1203 if (ac
->action(QStringLiteral("undo_close_tab"))->isEnabled()) {
1204 menu
->addAction(ac
->action(QStringLiteral("closed_tabs")));
1206 menu
->addAction(ac
->action(QStringLiteral("open_terminal")));
1207 menu
->addSeparator();
1209 // The third group contains actions to change what one sees in the view
1210 // and to change the more general UI.
1211 if (!toolBar()->isVisible()
1212 || (!toolbarActions
.contains(ac
->action(QStringLiteral("icons")))
1213 && !toolbarActions
.contains(ac
->action(QStringLiteral("compact")))
1214 && !toolbarActions
.contains(ac
->action(QStringLiteral("details")))
1215 && !toolbarActions
.contains(ac
->action(QStringLiteral("view_mode"))))
1217 menu
->addAction(ac
->action(QStringLiteral("view_mode")));
1219 menu
->addAction(ac
->action(QStringLiteral("show_hidden_files")));
1220 menu
->addAction(ac
->action(QStringLiteral("sort")));
1221 menu
->addAction(ac
->action(QStringLiteral("additional_info")));
1222 if (!GeneralSettings::showStatusBar() || !GeneralSettings::showZoomSlider()) {
1223 menu
->addAction(ac
->action(QStringLiteral("zoom")));
1225 menu
->addAction(ac
->action(QStringLiteral("panels")));
1227 // The "Configure" menu is not added to the actionCollection() because there is hardly
1228 // a good reason for users to put it on their toolbar.
1229 auto configureMenu
= menu
->addMenu(QIcon::fromTheme(QStringLiteral("configure")),
1230 i18nc("@action:inmenu menu for configure actions", "Configure"));
1231 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::SwitchApplicationLanguage
)));
1232 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::KeyBindings
)));
1233 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::ConfigureToolbars
)));
1234 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Preferences
)));
1235 hamburgerMenu
->hideActionsOf(configureMenu
);
1238 void DolphinMainWindow::slotPlaceActivated(const QUrl
& url
)
1240 DolphinViewContainer
* view
= activeViewContainer();
1242 if (view
->url() == url
) {
1243 // We can end up here if the user clicked a device in the Places Panel
1244 // which had been unmounted earlier, see https://bugs.kde.org/show_bug.cgi?id=161385.
1247 view
->disableUrlNavigatorSelectionRequests();
1249 view
->enableUrlNavigatorSelectionRequests();
1253 void DolphinMainWindow::closedTabsCountChanged(unsigned int count
)
1255 actionCollection()->action(QStringLiteral("undo_close_tab"))->setEnabled(count
> 0);
1258 void DolphinMainWindow::activeViewChanged(DolphinViewContainer
* viewContainer
)
1260 DolphinViewContainer
* oldViewContainer
= m_activeViewContainer
;
1261 Q_ASSERT(viewContainer
);
1263 m_activeViewContainer
= viewContainer
;
1265 if (oldViewContainer
) {
1266 const QAction
* toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
1267 toggleSearchAction
->disconnect(oldViewContainer
);
1269 // Disconnect all signals between the old view container (container,
1270 // view and url navigator) and main window.
1271 oldViewContainer
->disconnect(this);
1272 oldViewContainer
->view()->disconnect(this);
1273 oldViewContainer
->urlNavigatorInternalWithHistory()->disconnect(this);
1274 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>
1275 (actionCollection()->action(QStringLiteral("url_navigators")));
1276 navigators
->primaryUrlNavigator()->disconnect(this);
1277 if (auto secondaryUrlNavigator
= navigators
->secondaryUrlNavigator()) {
1278 secondaryUrlNavigator
->disconnect(this);
1281 // except the requestItemInfo so that on hover the information panel can still be updated
1282 connect(oldViewContainer
->view(), &DolphinView::requestItemInfo
,
1283 this, &DolphinMainWindow::requestItemInfo
);
1286 connectViewSignals(viewContainer
);
1288 m_actionHandler
->setCurrentView(viewContainer
->view());
1291 updateFileAndEditActions();
1292 updatePasteAction();
1293 updateViewActions();
1295 updateSearchAction();
1297 const QUrl url
= viewContainer
->url();
1298 Q_EMIT
urlChanged(url
);
1301 void DolphinMainWindow::tabCountChanged(int count
)
1303 const bool enableTabActions
= (count
> 1);
1304 for (int i
= 0; i
< MaxActivateTabShortcuts
; ++i
) {
1305 actionCollection()->action(QStringLiteral("activate_tab_%1").arg(i
))->setEnabled(enableTabActions
);
1307 actionCollection()->action(QStringLiteral("activate_last_tab"))->setEnabled(enableTabActions
);
1308 actionCollection()->action(QStringLiteral("activate_next_tab"))->setEnabled(enableTabActions
);
1309 actionCollection()->action(QStringLiteral("activate_prev_tab"))->setEnabled(enableTabActions
);
1312 void DolphinMainWindow::updateWindowTitle()
1314 const QString newTitle
= m_activeViewContainer
->captionWindowTitle();
1315 if (windowTitle() != newTitle
) {
1316 setWindowTitle(newTitle
);
1320 void DolphinMainWindow::slotStorageTearDownFromPlacesRequested(const QString
& mountPath
)
1322 connect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, this, [this, mountPath
]() {
1323 setViewsToHomeIfMountPathOpen(mountPath
);
1326 if (m_terminalPanel
&& m_terminalPanel
->currentWorkingDirectory().startsWith(mountPath
)) {
1327 m_tearDownFromPlacesRequested
= true;
1328 m_terminalPanel
->goHome();
1329 // m_placesPanel->proceedWithTearDown() will be called in slotTerminalDirectoryChanged
1331 m_placesPanel
->proceedWithTearDown();
1335 void DolphinMainWindow::slotStorageTearDownExternallyRequested(const QString
& mountPath
)
1337 connect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, this, [this, mountPath
]() {
1338 setViewsToHomeIfMountPathOpen(mountPath
);
1341 if (m_terminalPanel
&& m_terminalPanel
->currentWorkingDirectory().startsWith(mountPath
)) {
1342 m_tearDownFromPlacesRequested
= false;
1343 m_terminalPanel
->goHome();
1347 void DolphinMainWindow::setViewsToHomeIfMountPathOpen(const QString
& mountPath
)
1349 const QVector
<DolphinViewContainer
*> theViewContainers
= viewContainers();
1350 for (DolphinViewContainer
*viewContainer
: theViewContainers
) {
1351 if (viewContainer
&& viewContainer
->url().toLocalFile().startsWith(mountPath
)) {
1352 viewContainer
->setUrl(QUrl::fromLocalFile(QDir::homePath()));
1355 disconnect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, nullptr, nullptr);
1358 void DolphinMainWindow::setupActions()
1360 KStandardAction::hamburgerMenu(nullptr, nullptr, actionCollection());
1362 // setup 'File' menu
1363 m_newFileMenu
= new DolphinNewFileMenu(actionCollection(), this);
1364 QMenu
* menu
= m_newFileMenu
->menu();
1365 menu
->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1366 menu
->setIcon(QIcon::fromTheme(QStringLiteral("list-add")));
1367 m_newFileMenu
->setPopupMode(QToolButton::InstantPopup
);
1368 connect(menu
, &QMenu::aboutToShow
,
1369 this, &DolphinMainWindow::updateNewMenu
);
1371 QAction
* newWindow
= KStandardAction::openNew(this, &DolphinMainWindow::openNewMainWindow
, actionCollection());
1372 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
1373 newWindow
->setToolTip(i18nc("@info", "Open a new Dolphin window"));
1374 newWindow
->setWhatsThis(xi18nc("@info:whatsthis", "This opens a new "
1375 "window just like this one with the current location and view."
1376 "<nl/>You can drag and drop items between windows."));
1377 newWindow
->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
1379 QAction
* newTab
= actionCollection()->addAction(QStringLiteral("new_tab"));
1380 newTab
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1381 newTab
->setText(i18nc("@action:inmenu File", "New Tab"));
1382 newTab
->setWhatsThis(xi18nc("@info:whatsthis", "This opens a new "
1383 "<emphasis>Tab</emphasis> with the current location and view.<nl/>"
1384 "A tab is an additional view within this window. "
1385 "You can drag and drop items between tabs."));
1386 actionCollection()->setDefaultShortcuts(newTab
, {Qt::CTRL
| Qt::Key_T
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_N
});
1387 connect(newTab
, &QAction::triggered
, this, &DolphinMainWindow::openNewActivatedTab
);
1389 QAction
* addToPlaces
= actionCollection()->addAction(QStringLiteral("add_to_places"));
1390 addToPlaces
->setIcon(QIcon::fromTheme(QStringLiteral("bookmark-new")));
1391 addToPlaces
->setText(i18nc("@action:inmenu Add current folder to places", "Add to Places"));
1392 addToPlaces
->setWhatsThis(xi18nc("@info:whatsthis", "This adds the selected folder "
1393 "to the Places panel."));
1394 connect(addToPlaces
, &QAction::triggered
, this, &DolphinMainWindow::addToPlaces
);
1396 QAction
* closeTab
= KStandardAction::close(m_tabWidget
, QOverload
<>::of(&DolphinTabWidget::closeTab
), actionCollection());
1397 closeTab
->setText(i18nc("@action:inmenu File", "Close Tab"));
1398 closeTab
->setWhatsThis(i18nc("@info:whatsthis", "This closes the "
1399 "currently viewed tab. If no more tabs are left this window "
1400 "will close instead."));
1402 QAction
* quitAction
= KStandardAction::quit(this, &DolphinMainWindow::quit
, actionCollection());
1403 quitAction
->setWhatsThis(i18nc("@info:whatsthis quit", "This closes this window."));
1405 // setup 'Edit' menu
1406 KStandardAction::undo(this,
1407 &DolphinMainWindow::undo
,
1408 actionCollection());
1410 // i18n: This will be the last paragraph for the whatsthis for all three:
1411 // Cut, Copy and Paste
1412 const QString cutCopyPastePara
= xi18nc("@info:whatsthis", "<para><emphasis>Cut, "
1413 "Copy</emphasis> and <emphasis>Paste</emphasis> work between many "
1414 "applications and are among the most used commands. That's why their "
1415 "<emphasis>keyboard shortcuts</emphasis> are prominently placed right "
1416 "next to each other on the keyboard: <shortcut>Ctrl+X</shortcut>, "
1417 "<shortcut>Ctrl+C</shortcut> and <shortcut>Ctrl+V</shortcut>.</para>");
1418 QAction
* cutAction
= KStandardAction::cut(this, &DolphinMainWindow::cut
, actionCollection());
1419 cutAction
->setWhatsThis(xi18nc("@info:whatsthis cut", "This copies the items "
1420 "in your current selection to the <emphasis>clipboard</emphasis>.<nl/>"
1421 "Use the <emphasis>Paste</emphasis> action afterwards to copy them from "
1422 "the clipboard to a new location. The items will be removed from their "
1423 "initial location.") + cutCopyPastePara
);
1424 QAction
* copyAction
= KStandardAction::copy(this, &DolphinMainWindow::copy
, actionCollection());
1425 copyAction
->setWhatsThis(xi18nc("@info:whatsthis copy", "This copies the "
1426 "items in your current selection to the <emphasis>clipboard</emphasis>."
1427 "<nl/>Use the <emphasis>Paste</emphasis> action afterwards to copy them "
1428 "from the clipboard to a new location.") + cutCopyPastePara
);
1429 QAction
* paste
= KStandardAction::paste(this, &DolphinMainWindow::paste
, actionCollection());
1430 // The text of the paste-action is modified dynamically by Dolphin
1431 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1432 // due to the long text, the text "Paste" is used:
1433 paste
->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1434 paste
->setWhatsThis(xi18nc("@info:whatsthis paste", "This copies the items from "
1435 "your <emphasis>clipboard</emphasis> to the currently viewed folder.<nl/>"
1436 "If the items were added to the clipboard by the <emphasis>Cut</emphasis> "
1437 "action they are removed from their old location.") + cutCopyPastePara
);
1439 QAction
* copyToOtherViewAction
= actionCollection()->addAction(QStringLiteral("copy_to_inactive_split_view"));
1440 copyToOtherViewAction
->setText(i18nc("@action:inmenu", "Copy to Inactive Split View"));
1441 copyToOtherViewAction
->setWhatsThis(xi18nc("@info:whatsthis Copy", "This copies the selected items from "
1442 "the <emphasis>active</emphasis> view to the inactive split view."));
1443 copyToOtherViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("edit-copy")));
1444 copyToOtherViewAction
->setIconText(i18nc("@action:inmenu Edit", "Copy to Inactive Split View"));
1445 actionCollection()->setDefaultShortcut(copyToOtherViewAction
, Qt::SHIFT
| Qt::Key_F5
);
1446 connect(copyToOtherViewAction
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::copyToInactiveSplitView
);
1448 QAction
* moveToOtherViewAction
= actionCollection()->addAction(QStringLiteral("move_to_inactive_split_view"));
1449 moveToOtherViewAction
->setText(i18nc("@action:inmenu", "Move to Inactive Split View"));
1450 moveToOtherViewAction
->setWhatsThis(xi18nc("@info:whatsthis Move", "This moves the selected items from "
1451 "the <emphasis>active</emphasis> view to the inactive split view."));
1452 moveToOtherViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("edit-cut")));
1453 moveToOtherViewAction
->setIconText(i18nc("@action:inmenu Edit", "Move to Inactive Split View"));
1454 actionCollection()->setDefaultShortcut(moveToOtherViewAction
, Qt::SHIFT
| Qt::Key_F6
);
1455 connect(moveToOtherViewAction
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::moveToInactiveSplitView
);
1457 QAction
* showFilterBar
= actionCollection()->addAction(QStringLiteral("show_filter_bar"));
1458 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Filter..."));
1459 showFilterBar
->setToolTip(i18nc("@info:tooltip", "Toggle Filter Bar"));
1460 showFilterBar
->setWhatsThis(xi18nc("@info:whatsthis", "This opens the "
1461 "<emphasis>Filter Bar</emphasis> at the bottom of the window.<nl/> "
1462 "There you can enter a text to filter the files and folders currently displayed. "
1463 "Only those that contain the text in their name will be kept in view."));
1464 showFilterBar
->setIcon(QIcon::fromTheme(QStringLiteral("view-filter")));
1465 actionCollection()->setDefaultShortcuts(showFilterBar
, {Qt::CTRL
| Qt::Key_I
, Qt::Key_Slash
});
1466 connect(showFilterBar
, &QAction::triggered
, this, &DolphinMainWindow::showFilterBar
);
1468 // toggle_filter acts as a copy of the main showFilterBar to be used mainly
1469 // in the toolbar, with no default shortcut attached, to avoid messing with
1470 // existing workflows (filter bar always open and Ctrl-I to focus)
1471 QAction
*toggleFilter
= actionCollection()->addAction(QStringLiteral("toggle_filter"));
1472 toggleFilter
->setText(i18nc("@action:inmenu", "Toggle Filter Bar"));
1473 toggleFilter
->setIconText(i18nc("@action:intoolbar", "Filter"));
1474 toggleFilter
->setIcon(showFilterBar
->icon());
1475 toggleFilter
->setToolTip(showFilterBar
->toolTip());
1476 toggleFilter
->setWhatsThis(showFilterBar
->whatsThis());
1477 toggleFilter
->setCheckable(true);
1478 connect(toggleFilter
, &QAction::triggered
, this, &DolphinMainWindow::toggleFilterBar
);
1480 QAction
*searchAction
= KStandardAction::find(this, &DolphinMainWindow::find
, actionCollection());
1481 searchAction
->setText(i18n("Search..."));
1482 searchAction
->setToolTip(i18nc("@info:tooltip", "Search for files and folders"));
1483 searchAction
->setWhatsThis(xi18nc("@info:whatsthis find", "<para>This helps you "
1484 "find files and folders by opening a <emphasis>find bar</emphasis>. "
1485 "There you can enter search terms and specify settings to find the "
1486 "objects you are looking for.</para><para>Use this help again on "
1487 "the find bar so we can have a look at it while the settings are "
1488 "explained.</para>"));
1490 // toggle_search acts as a copy of the main searchAction to be used mainly
1491 // in the toolbar, with no default shortcut attached, to avoid messing with
1492 // existing workflows (search bar always open and Ctrl-F to focus)
1493 QAction
*toggleSearchAction
= actionCollection()->addAction(QStringLiteral("toggle_search"));
1494 toggleSearchAction
->setText(i18nc("@action:inmenu", "Toggle Search Bar"));
1495 toggleSearchAction
->setIconText(i18nc("@action:intoolbar", "Search"));
1496 toggleSearchAction
->setIcon(searchAction
->icon());
1497 toggleSearchAction
->setToolTip(searchAction
->toolTip());
1498 toggleSearchAction
->setWhatsThis(searchAction
->whatsThis());
1499 toggleSearchAction
->setCheckable(true);
1501 QAction
* selectAllAction
= KStandardAction::selectAll(this, &DolphinMainWindow::selectAll
, actionCollection());
1502 selectAllAction
->setWhatsThis(xi18nc("@info:whatsthis", "This selects all "
1503 "files and folders in the current location."));
1505 QAction
* invertSelection
= actionCollection()->addAction(QStringLiteral("invert_selection"));
1506 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1507 invertSelection
->setWhatsThis(xi18nc("@info:whatsthis invert", "This selects all "
1508 "objects that you have currently <emphasis>not</emphasis> selected instead."));
1509 invertSelection
->setIcon(QIcon::fromTheme(QStringLiteral("edit-select-invert")));
1510 actionCollection()->setDefaultShortcut(invertSelection
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
1511 connect(invertSelection
, &QAction::triggered
, this, &DolphinMainWindow::invertSelection
);
1513 // setup 'View' menu
1514 // (note that most of it is set up in DolphinViewActionHandler)
1516 QAction
* split
= actionCollection()->addAction(QStringLiteral("split_view"));
1517 split
->setWhatsThis(xi18nc("@info:whatsthis find", "<para>This splits "
1518 "the folder view below into two autonomous views.</para><para>This "
1519 "way you can see two locations at once and move items between them "
1520 "quickly.</para>Click this again afterwards to recombine the views."));
1521 actionCollection()->setDefaultShortcut(split
, Qt::Key_F3
);
1522 connect(split
, &QAction::triggered
, this, &DolphinMainWindow::toggleSplitView
);
1524 QAction
* stashSplit
= actionCollection()->addAction(QStringLiteral("split_stash"));
1525 actionCollection()->setDefaultShortcut(stashSplit
, Qt::CTRL
| Qt::Key_S
);
1526 stashSplit
->setText(i18nc("@action:intoolbar Stash", "Stash"));
1527 stashSplit
->setToolTip(i18nc("@info", "Opens the stash virtual directory in a split window"));
1528 stashSplit
->setIcon(QIcon::fromTheme(QStringLiteral("folder-stash")));
1529 stashSplit
->setCheckable(false);
1530 QDBusConnectionInterface
*sessionInterface
= QDBusConnection::sessionBus().interface();
1531 stashSplit
->setVisible(sessionInterface
&& sessionInterface
->isServiceRegistered(QStringLiteral("org.kde.kio.StashNotifier")));
1532 connect(stashSplit
, &QAction::triggered
, this, &DolphinMainWindow::toggleSplitStash
);
1534 KStandardAction::redisplay(this, &DolphinMainWindow::reloadView
, actionCollection());
1536 QAction
* stop
= actionCollection()->addAction(QStringLiteral("stop"));
1537 stop
->setText(i18nc("@action:inmenu View", "Stop"));
1538 stop
->setToolTip(i18nc("@info", "Stop loading"));
1539 stop
->setWhatsThis(i18nc("@info", "This stops the loading of the contents of the current folder."));
1540 stop
->setIcon(QIcon::fromTheme(QStringLiteral("process-stop")));
1541 connect(stop
, &QAction::triggered
, this, &DolphinMainWindow::stopLoading
);
1543 KToggleAction
* editableLocation
= actionCollection()->add
<KToggleAction
>(QStringLiteral("editable_location"));
1544 editableLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1545 editableLocation
->setWhatsThis(xi18nc("@info:whatsthis",
1546 "This toggles the <emphasis>Location Bar</emphasis> to be "
1547 "editable so you can directly enter a location you want to go to.<nl/>"
1548 "You can also switch to editing by clicking to the right of the "
1549 "location and switch back by confirming the edited location."));
1550 actionCollection()->setDefaultShortcut(editableLocation
, Qt::Key_F6
);
1551 connect(editableLocation
, &KToggleAction::triggered
, this, &DolphinMainWindow::toggleEditLocation
);
1553 QAction
* replaceLocation
= actionCollection()->addAction(QStringLiteral("replace_location"));
1554 replaceLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1555 // i18n: "enter" is used both in the meaning of "writing" and "going to" a new location here.
1556 // Both meanings are useful but not necessary to understand the use of "Replace Location".
1557 // So you might want to be more verbose in your language to convey the meaning but it's up to you.
1558 replaceLocation
->setWhatsThis(xi18nc("@info:whatsthis",
1559 "This switches to editing the location and selects it "
1560 "so you can quickly enter a different location."));
1561 actionCollection()->setDefaultShortcut(replaceLocation
, Qt::CTRL
| Qt::Key_L
);
1562 connect(replaceLocation
, &QAction::triggered
, this, &DolphinMainWindow::replaceLocation
);
1566 QScopedPointer
<QAction
> backAction(KStandardAction::back(nullptr, nullptr, nullptr));
1567 m_backAction
= new KToolBarPopupAction(backAction
->icon(), backAction
->text(), actionCollection());
1568 m_backAction
->setObjectName(backAction
->objectName());
1569 m_backAction
->setShortcuts(backAction
->shortcuts());
1571 m_backAction
->setPopupMode(QToolButton::DelayedPopup
);
1572 connect(m_backAction
, &QAction::triggered
, this, &DolphinMainWindow::goBack
);
1573 connect(m_backAction
->menu(), &QMenu::aboutToShow
, this, &DolphinMainWindow::slotAboutToShowBackPopupMenu
);
1574 connect(m_backAction
->menu(), &QMenu::triggered
, this, &DolphinMainWindow::slotGoBack
);
1575 actionCollection()->addAction(m_backAction
->objectName(), m_backAction
);
1577 auto backShortcuts
= m_backAction
->shortcuts();
1578 backShortcuts
.append(QKeySequence(Qt::Key_Backspace
));
1579 actionCollection()->setDefaultShortcuts(m_backAction
, backShortcuts
);
1581 DolphinRecentTabsMenu
* recentTabsMenu
= new DolphinRecentTabsMenu(this);
1582 actionCollection()->addAction(QStringLiteral("closed_tabs"), recentTabsMenu
);
1583 connect(m_tabWidget
, &DolphinTabWidget::rememberClosedTab
,
1584 recentTabsMenu
, &DolphinRecentTabsMenu::rememberClosedTab
);
1585 connect(recentTabsMenu
, &DolphinRecentTabsMenu::restoreClosedTab
,
1586 m_tabWidget
, &DolphinTabWidget::restoreClosedTab
);
1587 connect(recentTabsMenu
, &DolphinRecentTabsMenu::closedTabsCountChanged
,
1588 this, &DolphinMainWindow::closedTabsCountChanged
);
1590 QAction
* undoCloseTab
= actionCollection()->addAction(QStringLiteral("undo_close_tab"));
1591 undoCloseTab
->setText(i18nc("@action:inmenu File", "Undo close tab"));
1592 undoCloseTab
->setWhatsThis(i18nc("@info:whatsthis undo close tab",
1593 "This returns you to the previously closed tab."));
1594 actionCollection()->setDefaultShortcut(undoCloseTab
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_T
);
1595 undoCloseTab
->setIcon(QIcon::fromTheme(QStringLiteral("edit-undo")));
1596 undoCloseTab
->setEnabled(false);
1597 connect(undoCloseTab
, &QAction::triggered
, recentTabsMenu
, &DolphinRecentTabsMenu::undoCloseTab
);
1599 auto undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
1600 undoAction
->setWhatsThis(xi18nc("@info:whatsthis", "This undoes "
1601 "the last change you made to files or folders.<nl/>"
1602 "Such changes include <interface>creating, renaming</interface> "
1603 "and <interface>moving</interface> them to a different location "
1604 "or to the <filename>Trash</filename>. <nl/>Changes that can't "
1605 "be undone will ask for your confirmation."));
1606 undoAction
->setEnabled(false); // undo should be disabled by default
1609 QScopedPointer
<QAction
> forwardAction(KStandardAction::forward(nullptr, nullptr, nullptr));
1610 m_forwardAction
= new KToolBarPopupAction(forwardAction
->icon(), forwardAction
->text(), actionCollection());
1611 m_forwardAction
->setObjectName(forwardAction
->objectName());
1612 m_forwardAction
->setShortcuts(forwardAction
->shortcuts());
1614 m_forwardAction
->setPopupMode(QToolButton::DelayedPopup
);
1615 connect(m_forwardAction
, &QAction::triggered
, this, &DolphinMainWindow::goForward
);
1616 connect(m_forwardAction
->menu(), &QMenu::aboutToShow
, this, &DolphinMainWindow::slotAboutToShowForwardPopupMenu
);
1617 connect(m_forwardAction
->menu(), &QMenu::triggered
, this, &DolphinMainWindow::slotGoForward
);
1618 actionCollection()->addAction(m_forwardAction
->objectName(), m_forwardAction
);
1619 actionCollection()->setDefaultShortcuts(m_forwardAction
, m_forwardAction
->shortcuts());
1621 // enable middle-click to open in a new tab
1622 auto *middleClickEventFilter
= new MiddleClickActionEventFilter(this);
1623 connect(middleClickEventFilter
, &MiddleClickActionEventFilter::actionMiddleClicked
, this, &DolphinMainWindow::slotBackForwardActionMiddleClicked
);
1624 m_backAction
->menu()->installEventFilter(middleClickEventFilter
);
1625 m_forwardAction
->menu()->installEventFilter(middleClickEventFilter
);
1626 KStandardAction::up(this, &DolphinMainWindow::goUp
, actionCollection());
1627 QAction
* homeAction
= KStandardAction::home(this, &DolphinMainWindow::goHome
, actionCollection());
1628 homeAction
->setWhatsThis(xi18nc("@info:whatsthis", "Go to your "
1629 "<filename>Home</filename> folder.<nl/>Every user account "
1630 "has their own <filename>Home</filename> that contains their data "
1631 "including folders that contain personal application data."));
1633 // setup 'Tools' menu
1634 QAction
* compareFiles
= actionCollection()->addAction(QStringLiteral("compare_files"));
1635 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1636 compareFiles
->setIcon(QIcon::fromTheme(QStringLiteral("kompare")));
1637 compareFiles
->setEnabled(false);
1638 connect(compareFiles
, &QAction::triggered
, this, &DolphinMainWindow::compareFiles
);
1640 QAction
* openPreferredSearchTool
= actionCollection()->addAction(QStringLiteral("open_preferred_search_tool"));
1641 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool"));
1642 openPreferredSearchTool
->setWhatsThis(xi18nc("@info:whatsthis",
1643 "<para>This opens a preferred search tool for the viewed location.</para>"
1644 "<para>Use <emphasis>More Search Tools</emphasis> menu to configure it.</para>"));
1645 openPreferredSearchTool
->setIcon(QIcon::fromTheme(QStringLiteral("search")));
1646 actionCollection()->setDefaultShortcut(openPreferredSearchTool
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_F
);
1647 connect(openPreferredSearchTool
, &QAction::triggered
, this, &DolphinMainWindow::openPreferredSearchTool
);
1649 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
1650 QAction
* openTerminal
= actionCollection()->addAction(QStringLiteral("open_terminal"));
1651 openTerminal
->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
1652 openTerminal
->setWhatsThis(xi18nc("@info:whatsthis",
1653 "<para>This opens a <emphasis>terminal</emphasis> application for the viewed location.</para>"
1654 "<para>To learn more about terminals use the help in the terminal application.</para>"));
1655 openTerminal
->setIcon(QIcon::fromTheme(QStringLiteral("utilities-terminal")));
1656 actionCollection()->setDefaultShortcut(openTerminal
, Qt::SHIFT
| Qt::Key_F4
);
1657 connect(openTerminal
, &QAction::triggered
, this, &DolphinMainWindow::openTerminal
);
1659 #ifdef HAVE_TERMINAL
1660 QAction
* focusTerminalPanel
= actionCollection()->addAction(QStringLiteral("focus_terminal_panel"));
1661 focusTerminalPanel
->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
1662 focusTerminalPanel
->setIcon(QIcon::fromTheme(QStringLiteral("swap-panels")));
1663 actionCollection()->setDefaultShortcut(focusTerminalPanel
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_F4
);
1664 connect(focusTerminalPanel
, &QAction::triggered
, this, &DolphinMainWindow::focusTerminalPanel
);
1668 // setup 'Bookmarks' menu
1669 KActionMenu
*bookmarkMenu
= new KActionMenu(i18nc("@title:menu", "&Bookmarks"), this);
1670 bookmarkMenu
->setIcon(QIcon::fromTheme(QStringLiteral("bookmarks")));
1671 // Make the toolbar button version work properly on click
1672 bookmarkMenu
->setPopupMode(QToolButton::InstantPopup
);
1673 m_bookmarkHandler
= new DolphinBookmarkHandler(this, actionCollection(), bookmarkMenu
->menu(), this);
1674 actionCollection()->addAction(QStringLiteral("bookmarks"), bookmarkMenu
);
1676 // setup 'Settings' menu
1677 KToggleAction
* showMenuBar
= KStandardAction::showMenubar(nullptr, nullptr, actionCollection());
1678 showMenuBar
->setWhatsThis(xi18nc("@info:whatsthis",
1679 "This switches between having a <emphasis>Menubar</emphasis> "
1680 "and having a <interface>Control</interface> button. Both "
1681 "contain mostly the same commands and configuration options."));
1682 connect(showMenuBar
, &KToggleAction::triggered
, // Fixes #286822
1683 this, &DolphinMainWindow::toggleShowMenuBar
, Qt::QueuedConnection
);
1684 KStandardAction::preferences(this, &DolphinMainWindow::editSettings
, actionCollection());
1686 // setup 'Help' menu for the m_controlButton. The other one is set up in the base class.
1687 m_helpMenu
= new KHelpMenu(nullptr);
1688 m_helpMenu
->menu()->installEventFilter(this);
1689 // remove duplicate shortcuts
1690 auto removeHelpActionShortcut
= [this](KHelpMenu::MenuId menuId
) {
1691 if (auto *action
= m_helpMenu
->action(menuId
)) {
1692 action
->setShortcut(QKeySequence());
1695 removeHelpActionShortcut(KHelpMenu::menuHelpContents
);
1696 removeHelpActionShortcut(KHelpMenu::menuWhatsThis
);
1698 // not in menu actions
1699 QList
<QKeySequence
> nextTabKeys
= KStandardShortcut::tabNext();
1700 nextTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::Key_Tab
));
1702 QList
<QKeySequence
> prevTabKeys
= KStandardShortcut::tabPrev();
1703 prevTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::SHIFT
| Qt::Key_Tab
));
1705 for (int i
= 0; i
< MaxActivateTabShortcuts
; ++i
) {
1706 QAction
* activateTab
= actionCollection()->addAction(QStringLiteral("activate_tab_%1").arg(i
));
1707 activateTab
->setText(i18nc("@action:inmenu", "Activate Tab %1", i
+ 1));
1708 activateTab
->setEnabled(false);
1709 connect(activateTab
, &QAction::triggered
, this, [this, i
]() { m_tabWidget
->activateTab(i
); });
1711 // only add default shortcuts for the first 9 tabs regardless of MaxActivateTabShortcuts
1713 actionCollection()->setDefaultShortcut(activateTab
, QStringLiteral("Alt+%1").arg(i
+ 1));
1717 QAction
* activateLastTab
= actionCollection()->addAction(QStringLiteral("activate_last_tab"));
1718 activateLastTab
->setText(i18nc("@action:inmenu", "Activate Last Tab"));
1719 activateLastTab
->setEnabled(false);
1720 connect(activateLastTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activateLastTab
);
1721 actionCollection()->setDefaultShortcut(activateLastTab
, Qt::ALT
| Qt::Key_0
);
1723 QAction
* activateNextTab
= actionCollection()->addAction(QStringLiteral("activate_next_tab"));
1724 activateNextTab
->setIconText(i18nc("@action:inmenu", "Next Tab"));
1725 activateNextTab
->setText(i18nc("@action:inmenu", "Activate Next Tab"));
1726 activateNextTab
->setEnabled(false);
1727 connect(activateNextTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activateNextTab
);
1728 actionCollection()->setDefaultShortcuts(activateNextTab
, nextTabKeys
);
1730 QAction
* activatePrevTab
= actionCollection()->addAction(QStringLiteral("activate_prev_tab"));
1731 activatePrevTab
->setIconText(i18nc("@action:inmenu", "Previous Tab"));
1732 activatePrevTab
->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
1733 activatePrevTab
->setEnabled(false);
1734 connect(activatePrevTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activatePrevTab
);
1735 actionCollection()->setDefaultShortcuts(activatePrevTab
, prevTabKeys
);
1738 QAction
* showTarget
= actionCollection()->addAction(QStringLiteral("show_target"));
1739 showTarget
->setText(i18nc("@action:inmenu", "Show Target"));
1740 showTarget
->setIcon(QIcon::fromTheme(QStringLiteral("document-open-folder")));
1741 showTarget
->setEnabled(false);
1742 connect(showTarget
, &QAction::triggered
, this, &DolphinMainWindow::showTarget
);
1744 QAction
* openInNewTab
= actionCollection()->addAction(QStringLiteral("open_in_new_tab"));
1745 openInNewTab
->setText(i18nc("@action:inmenu", "Open in New Tab"));
1746 openInNewTab
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1747 connect(openInNewTab
, &QAction::triggered
, this, &DolphinMainWindow::openInNewTab
);
1749 QAction
* openInNewTabs
= actionCollection()->addAction(QStringLiteral("open_in_new_tabs"));
1750 openInNewTabs
->setText(i18nc("@action:inmenu", "Open in New Tabs"));
1751 openInNewTabs
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1752 connect(openInNewTabs
, &QAction::triggered
, this, &DolphinMainWindow::openInNewTab
);
1754 QAction
* openInNewWindow
= actionCollection()->addAction(QStringLiteral("open_in_new_window"));
1755 openInNewWindow
->setText(i18nc("@action:inmenu", "Open in New Window"));
1756 openInNewWindow
->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
1757 connect(openInNewWindow
, &QAction::triggered
, this, &DolphinMainWindow::openInNewWindow
);
1760 void DolphinMainWindow::setupDockWidgets()
1762 const bool lock
= GeneralSettings::lockPanels();
1764 KDualAction
* lockLayoutAction
= actionCollection()->add
<KDualAction
>(QStringLiteral("lock_panels"));
1765 lockLayoutAction
->setActiveText(i18nc("@action:inmenu Panels", "Unlock Panels"));
1766 lockLayoutAction
->setActiveIcon(QIcon::fromTheme(QStringLiteral("object-unlocked")));
1767 lockLayoutAction
->setInactiveText(i18nc("@action:inmenu Panels", "Lock Panels"));
1768 lockLayoutAction
->setInactiveIcon(QIcon::fromTheme(QStringLiteral("object-locked")));
1769 lockLayoutAction
->setWhatsThis(xi18nc("@info:whatsthis", "This "
1770 "switches between having panels <emphasis>locked</emphasis> or "
1771 "<emphasis>unlocked</emphasis>.<nl/>Unlocked panels can be "
1772 "dragged to the other side of the window and have a close "
1773 "button.<nl/>Locked panels are embedded more cleanly."));
1774 lockLayoutAction
->setActive(lock
);
1775 connect(lockLayoutAction
, &KDualAction::triggered
, this, &DolphinMainWindow::togglePanelLockState
);
1777 // Setup "Information"
1778 DolphinDockWidget
* infoDock
= new DolphinDockWidget(i18nc("@title:window", "Information"));
1779 infoDock
->setLocked(lock
);
1780 infoDock
->setObjectName(QStringLiteral("infoDock"));
1781 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1784 InformationPanel
* infoPanel
= new InformationPanel(infoDock
);
1785 infoPanel
->setCustomContextMenuActions({lockLayoutAction
});
1786 connect(infoPanel
, &InformationPanel::urlActivated
, this, &DolphinMainWindow::handleUrl
);
1787 infoDock
->setWidget(infoPanel
);
1789 QAction
* infoAction
= infoDock
->toggleViewAction();
1790 createPanelAction(QIcon::fromTheme(QStringLiteral("dialog-information")), Qt::Key_F11
, infoAction
, QStringLiteral("show_information_panel"));
1792 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
1793 connect(this, &DolphinMainWindow::urlChanged
,
1794 infoPanel
, &InformationPanel::setUrl
);
1795 connect(this, &DolphinMainWindow::selectionChanged
,
1796 infoPanel
, &InformationPanel::setSelection
);
1797 connect(this, &DolphinMainWindow::requestItemInfo
,
1798 infoPanel
, &InformationPanel::requestDelayedItemInfo
);
1799 connect(this, &DolphinMainWindow::fileItemsChanged
,
1800 infoPanel
, &InformationPanel::slotFilesItemChanged
);
1803 // i18n: This is the last paragraph for the "What's This"-texts of all four panels.
1804 const QString panelWhatsThis
= xi18nc("@info:whatsthis", "<para>To show or "
1805 "hide panels like this go to <interface>Control|Panels</interface> "
1806 "or <interface>View|Panels</interface>.</para>");
1808 actionCollection()->action(QStringLiteral("show_information_panel"))
1809 ->setWhatsThis(xi18nc("@info:whatsthis", "<para> This toggles the "
1810 "<emphasis>information</emphasis> panel at the right side of the "
1811 "window.</para><para>The panel provides in-depth information "
1812 "about the items your mouse is hovering over or about the selected "
1813 "items. Otherwise it informs you about the currently viewed folder.<nl/>"
1814 "For single items a preview of their contents is provided.</para>"));
1816 infoDock
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This panel "
1817 "provides in-depth information about the items your mouse is "
1818 "hovering over or about the selected items. Otherwise it informs "
1819 "you about the currently viewed folder.<nl/>For single items a "
1820 "preview of their contents is provided.</para><para>You can configure "
1821 "which and how details are given here by right-clicking.</para>") + panelWhatsThis
);
1824 DolphinDockWidget
* foldersDock
= new DolphinDockWidget(i18nc("@title:window", "Folders"));
1825 foldersDock
->setLocked(lock
);
1826 foldersDock
->setObjectName(QStringLiteral("foldersDock"));
1827 foldersDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1828 FoldersPanel
* foldersPanel
= new FoldersPanel(foldersDock
);
1829 foldersPanel
->setCustomContextMenuActions({lockLayoutAction
});
1830 foldersDock
->setWidget(foldersPanel
);
1832 QAction
* foldersAction
= foldersDock
->toggleViewAction();
1833 createPanelAction(QIcon::fromTheme(QStringLiteral("folder")), Qt::Key_F7
, foldersAction
, QStringLiteral("show_folders_panel"));
1835 addDockWidget(Qt::LeftDockWidgetArea
, foldersDock
);
1836 connect(this, &DolphinMainWindow::urlChanged
,
1837 foldersPanel
, &FoldersPanel::setUrl
);
1838 connect(foldersPanel
, &FoldersPanel::folderActivated
,
1839 this, &DolphinMainWindow::changeUrl
);
1840 connect(foldersPanel
, &FoldersPanel::folderMiddleClicked
,
1841 this, &DolphinMainWindow::openNewTab
);
1842 connect(foldersPanel
, &FoldersPanel::errorMessage
,
1843 this, &DolphinMainWindow::showErrorMessage
);
1845 actionCollection()->action(QStringLiteral("show_folders_panel"))
1846 ->setWhatsThis(xi18nc("@info:whatsthis", "This toggles the "
1847 "<emphasis>folders</emphasis> panel at the left side of the window."
1848 "<nl/><nl/>It shows the folders of the <emphasis>file system"
1849 "</emphasis> in a <emphasis>tree view</emphasis>."));
1850 foldersDock
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This panel "
1851 "shows the folders of the <emphasis>file system</emphasis> in a "
1852 "<emphasis>tree view</emphasis>.</para><para>Click a folder to go "
1853 "there. Click the arrow to the left of a folder to see its subfolders. "
1854 "This allows quick switching between any folders.</para>") + panelWhatsThis
);
1857 #ifdef HAVE_TERMINAL
1858 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
1859 DolphinDockWidget
* terminalDock
= new DolphinDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
1860 terminalDock
->setLocked(lock
);
1861 terminalDock
->setObjectName(QStringLiteral("terminalDock"));
1862 m_terminalPanel
= new TerminalPanel(terminalDock
);
1863 m_terminalPanel
->setCustomContextMenuActions({lockLayoutAction
});
1864 terminalDock
->setWidget(m_terminalPanel
);
1866 connect(m_terminalPanel
, &TerminalPanel::hideTerminalPanel
, terminalDock
, &DolphinDockWidget::hide
);
1867 connect(m_terminalPanel
, &TerminalPanel::changeUrl
, this, &DolphinMainWindow::slotTerminalDirectoryChanged
);
1868 connect(terminalDock
, &DolphinDockWidget::visibilityChanged
,
1869 m_terminalPanel
, &TerminalPanel::dockVisibilityChanged
);
1870 connect(terminalDock
, &DolphinDockWidget::visibilityChanged
,
1871 this, &DolphinMainWindow::slotTerminalPanelVisibilityChanged
);
1873 QAction
* terminalAction
= terminalDock
->toggleViewAction();
1874 createPanelAction(QIcon::fromTheme(QStringLiteral("dialog-scripts")), Qt::Key_F4
, terminalAction
, QStringLiteral("show_terminal_panel"));
1876 addDockWidget(Qt::BottomDockWidgetArea
, terminalDock
);
1877 connect(this, &DolphinMainWindow::urlChanged
,
1878 m_terminalPanel
, &TerminalPanel::setUrl
);
1880 if (GeneralSettings::version() < 200) {
1881 terminalDock
->hide();
1884 actionCollection()->action(QStringLiteral("show_terminal_panel"))
1885 ->setWhatsThis(xi18nc("@info:whatsthis", "<para>This toggles the "
1886 "<emphasis>terminal</emphasis> panel at the bottom of the window."
1887 "<nl/>The location in the terminal will always match the folder "
1888 "view so you can navigate using either.</para><para>The terminal "
1889 "panel is not needed for basic computer usage but can be useful "
1890 "for advanced tasks. To learn more about terminals use the help "
1891 "in a standalone terminal application like Konsole.</para>"));
1892 terminalDock
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is "
1893 "the <emphasis>terminal</emphasis> panel. It behaves like a "
1894 "normal terminal but will match the location of the folder view "
1895 "so you can navigate using either.</para><para>The terminal panel "
1896 "is not needed for basic computer usage but can be useful for "
1897 "advanced tasks. To learn more about terminals use the help in a "
1898 "standalone terminal application like Konsole.</para>") + panelWhatsThis
);
1902 if (GeneralSettings::version() < 200) {
1904 foldersDock
->hide();
1908 DolphinDockWidget
* placesDock
= new DolphinDockWidget(i18nc("@title:window", "Places"));
1909 placesDock
->setLocked(lock
);
1910 placesDock
->setObjectName(QStringLiteral("placesDock"));
1911 placesDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1913 m_placesPanel
= new PlacesPanel(placesDock
);
1914 m_placesPanel
->setCustomContextMenuActions({lockLayoutAction
});
1915 placesDock
->setWidget(m_placesPanel
);
1917 QAction
*placesAction
= placesDock
->toggleViewAction();
1918 createPanelAction(QIcon::fromTheme(QStringLiteral("compass")), Qt::Key_F9
, placesAction
, QStringLiteral("show_places_panel"));
1920 addDockWidget(Qt::LeftDockWidgetArea
, placesDock
);
1921 connect(m_placesPanel
, &PlacesPanel::placeActivated
,
1922 this, &DolphinMainWindow::slotPlaceActivated
);
1923 connect(m_placesPanel
, &PlacesPanel::placeMiddleClicked
,
1924 this, &DolphinMainWindow::openNewTab
);
1925 connect(m_placesPanel
, &PlacesPanel::errorMessage
,
1926 this, &DolphinMainWindow::showErrorMessage
);
1927 connect(this, &DolphinMainWindow::urlChanged
,
1928 m_placesPanel
, &PlacesPanel::setUrl
);
1929 connect(placesDock
, &DolphinDockWidget::visibilityChanged
,
1930 &DolphinUrlNavigatorsController::slotPlacesPanelVisibilityChanged
);
1931 connect(this, &DolphinMainWindow::settingsChanged
,
1932 m_placesPanel
, &PlacesPanel::readSettings
);
1933 connect(m_placesPanel
, &PlacesPanel::storageTearDownRequested
,
1934 this, &DolphinMainWindow::slotStorageTearDownFromPlacesRequested
);
1935 connect(m_placesPanel
, &PlacesPanel::storageTearDownExternallyRequested
,
1936 this, &DolphinMainWindow::slotStorageTearDownExternallyRequested
);
1937 DolphinUrlNavigatorsController::slotPlacesPanelVisibilityChanged(m_placesPanel
->isVisible());
1939 auto actionShowAllPlaces
= new QAction(QIcon::fromTheme(QStringLiteral("view-hidden")), i18nc("@item:inmenu", "Show Hidden Places"), this);
1940 actionShowAllPlaces
->setCheckable(true);
1941 actionShowAllPlaces
->setDisabled(true);
1942 actionShowAllPlaces
->setWhatsThis(i18nc("@info:whatsthis", "This displays "
1943 "all places in the places panel that have been hidden. They will "
1944 "appear semi-transparent unless you uncheck their hide property."));
1946 connect(actionShowAllPlaces
, &QAction::triggered
, this, [actionShowAllPlaces
, this](bool checked
){
1947 actionShowAllPlaces
->setIcon(QIcon::fromTheme(checked
? QStringLiteral("view-visible") : QStringLiteral("view-hidden")));
1948 m_placesPanel
->showHiddenEntries(checked
);
1951 connect(m_placesPanel
, &PlacesPanel::showHiddenEntriesChanged
, this, [actionShowAllPlaces
] (bool checked
){
1952 actionShowAllPlaces
->setChecked(checked
);
1953 actionShowAllPlaces
->setIcon(QIcon::fromTheme(checked
? QStringLiteral("view-visible") : QStringLiteral("view-hidden")));
1956 actionCollection()->action(QStringLiteral("show_places_panel"))
1957 ->setWhatsThis(xi18nc("@info:whatsthis", "<para>This toggles the "
1958 "<emphasis>places</emphasis> panel at the left side of the window."
1959 "</para><para>It allows you to go to locations you have "
1960 "bookmarked and to access disk or media attached to the computer "
1961 "or to the network. It also contains sections to find recently "
1962 "saved files or files of a certain type.</para>"));
1963 placesDock
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
1964 "<emphasis>Places</emphasis> panel. It allows you to go to locations "
1965 "you have bookmarked and to access disk or media attached to the "
1966 "computer or to the network. It also contains sections to find "
1967 "recently saved files or files of a certain type.</para><para>"
1968 "Click on an entry to go there. Click with the right mouse button "
1969 "instead to open any entry in a new tab or new window.</para>"
1970 "<para>New entries can be added by dragging folders onto this panel. "
1971 "Right-click any section or entry to hide it. Right-click an empty "
1972 "space on this panel and select <interface>Show Hidden Places"
1973 "</interface> to display it again.</para>") + panelWhatsThis
);
1975 // Add actions into the "Panels" menu
1976 KActionMenu
* panelsMenu
= new KActionMenu(i18nc("@action:inmenu View", "Show Panels"), this);
1977 actionCollection()->addAction(QStringLiteral("panels"), panelsMenu
);
1978 panelsMenu
->setIcon(QIcon::fromTheme(QStringLiteral("view-sidetree")));
1979 panelsMenu
->setPopupMode(QToolButton::InstantPopup
);
1980 const KActionCollection
* ac
= actionCollection();
1981 panelsMenu
->addAction(ac
->action(QStringLiteral("show_places_panel")));
1983 panelsMenu
->addAction(ac
->action(QStringLiteral("show_information_panel")));
1985 panelsMenu
->addAction(ac
->action(QStringLiteral("show_folders_panel")));
1986 panelsMenu
->addAction(ac
->action(QStringLiteral("show_terminal_panel")));
1987 panelsMenu
->addSeparator();
1988 panelsMenu
->addAction(actionShowAllPlaces
);
1989 panelsMenu
->addAction(lockLayoutAction
);
1991 connect(panelsMenu
->menu(), &QMenu::aboutToShow
, this, [actionShowAllPlaces
, this]{
1992 actionShowAllPlaces
->setEnabled(m_placesPanel
->hiddenListCount());
1997 void DolphinMainWindow::updateFileAndEditActions()
1999 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
2000 const KActionCollection
* col
= actionCollection();
2001 KFileItemListProperties
capabilitiesSource(list
);
2003 QAction
* addToPlacesAction
= col
->action(QStringLiteral("add_to_places"));
2004 QAction
* copyToOtherViewAction
= col
->action(QStringLiteral("copy_to_inactive_split_view"));
2005 QAction
* moveToOtherViewAction
= col
->action(QStringLiteral("move_to_inactive_split_view"));
2006 QAction
* copyLocation
= col
->action(QString("copy_location"));
2008 if (list
.isEmpty()) {
2009 stateChanged(QStringLiteral("has_no_selection"));
2011 addToPlacesAction
->setEnabled(true);
2012 copyToOtherViewAction
->setEnabled(false);
2013 moveToOtherViewAction
->setEnabled(false);
2014 copyLocation
->setEnabled(false);
2016 stateChanged(QStringLiteral("has_selection"));
2018 QAction
* renameAction
= col
->action(KStandardAction::name(KStandardAction::RenameFile
));
2019 QAction
* moveToTrashAction
= col
->action(KStandardAction::name(KStandardAction::MoveToTrash
));
2020 QAction
* deleteAction
= col
->action(KStandardAction::name(KStandardAction::DeleteFile
));
2021 QAction
* cutAction
= col
->action(KStandardAction::name(KStandardAction::Cut
));
2022 QAction
* deleteWithTrashShortcut
= col
->action(QStringLiteral("delete_shortcut")); // see DolphinViewActionHandler
2023 QAction
* showTarget
= col
->action(QStringLiteral("show_target"));
2024 QAction
* duplicateAction
= col
->action(QStringLiteral("duplicate")); // see DolphinViewActionHandler
2026 if (list
.length() == 1 && list
.first().isDir()) {
2027 addToPlacesAction
->setEnabled(true);
2029 addToPlacesAction
->setEnabled(false);
2032 if (m_tabWidget
->currentTabPage()->splitViewEnabled()) {
2033 DolphinTabPage
* tabPage
= m_tabWidget
->currentTabPage();
2034 KFileItem capabilitiesDestination
;
2036 if (tabPage
->primaryViewActive()) {
2037 capabilitiesDestination
= tabPage
->secondaryViewContainer()->url();
2039 capabilitiesDestination
= tabPage
->primaryViewContainer()->url();
2042 copyToOtherViewAction
->setEnabled(capabilitiesDestination
.isWritable());
2043 moveToOtherViewAction
->setEnabled(capabilitiesSource
.supportsMoving() && capabilitiesDestination
.isWritable());
2045 copyToOtherViewAction
->setEnabled(false);
2046 moveToOtherViewAction
->setEnabled(false);
2049 const bool enableMoveToTrash
= capabilitiesSource
.isLocal() && capabilitiesSource
.supportsMoving();
2051 renameAction
->setEnabled(capabilitiesSource
.supportsMoving());
2052 moveToTrashAction
->setEnabled(enableMoveToTrash
);
2053 deleteAction
->setEnabled(capabilitiesSource
.supportsDeleting());
2054 deleteWithTrashShortcut
->setEnabled(capabilitiesSource
.supportsDeleting() && !enableMoveToTrash
);
2055 cutAction
->setEnabled(capabilitiesSource
.supportsMoving());
2056 copyLocation
->setEnabled(list
.length() == 1);
2057 showTarget
->setEnabled(list
.length() == 1 && list
.at(0).isLink());
2058 duplicateAction
->setEnabled(capabilitiesSource
.supportsWriting());
2062 void DolphinMainWindow::updateViewActions()
2064 m_actionHandler
->updateViewActions();
2066 QAction
* toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
2067 toggleFilterBarAction
->setChecked(m_activeViewContainer
->isFilterBarVisible());
2069 updateSplitAction();
2072 void DolphinMainWindow::updateGoActions()
2074 QAction
* goUpAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Up
));
2075 const QUrl currentUrl
= m_activeViewContainer
->url();
2076 // I think this is one of the best places to firstly be confronted
2077 // with a file system and its hierarchy. Talking about the root
2078 // directory might seem too much here but it is the question that
2079 // naturally arises in this context.
2080 goUpAction
->setWhatsThis(xi18nc("@info:whatsthis", "<para>Go to "
2081 "the folder that contains the currently viewed one.</para>"
2082 "<para>All files and folders are organized in a hierarchical "
2083 "<emphasis>file system</emphasis>. At the top of this hierarchy is "
2084 "a directory that contains all data connected to this computer"
2085 "—the <emphasis>root directory</emphasis>.</para>"));
2086 goUpAction
->setEnabled(KIO::upUrl(currentUrl
) != currentUrl
);
2089 void DolphinMainWindow::refreshViews()
2091 m_tabWidget
->refreshViews();
2093 if (GeneralSettings::modifiedStartupSettings()) {
2094 // The startup settings have been changed by the user (see bug #254947).
2095 // Synchronize the split-view setting with the active view:
2096 const bool splitView
= GeneralSettings::splitView();
2097 m_tabWidget
->currentTabPage()->setSplitViewEnabled(splitView
, WithAnimation
);
2098 updateSplitAction();
2099 updateWindowTitle();
2102 Q_EMIT
settingsChanged();
2105 void DolphinMainWindow::clearStatusBar()
2107 m_activeViewContainer
->statusBar()->resetToDefaultText();
2110 void DolphinMainWindow::connectViewSignals(DolphinViewContainer
* container
)
2112 connect(container
, &DolphinViewContainer::showFilterBarChanged
,
2113 this, &DolphinMainWindow::updateFilterBarAction
);
2114 connect(container
, &DolphinViewContainer::writeStateChanged
,
2115 this, &DolphinMainWindow::slotWriteStateChanged
);
2116 connect(container
, &DolphinViewContainer::searchModeEnabledChanged
,
2117 this, &DolphinMainWindow::updateSearchAction
);
2119 const QAction
* toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
2120 connect(toggleSearchAction
, &QAction::triggered
, container
, &DolphinViewContainer::setSearchModeEnabled
);
2122 const DolphinView
* view
= container
->view();
2123 connect(view
, &DolphinView::selectionChanged
,
2124 this, &DolphinMainWindow::slotSelectionChanged
);
2125 connect(view
, &DolphinView::requestItemInfo
,
2126 this, &DolphinMainWindow::requestItemInfo
);
2127 connect(view
, &DolphinView::fileItemsChanged
,
2128 this, &DolphinMainWindow::fileItemsChanged
);
2129 connect(view
, &DolphinView::tabRequested
,
2130 this, &DolphinMainWindow::openNewTab
);
2131 connect(view
, &DolphinView::requestContextMenu
,
2132 this, &DolphinMainWindow::openContextMenu
);
2133 connect(view
, &DolphinView::directoryLoadingStarted
,
2134 this, &DolphinMainWindow::enableStopAction
);
2135 connect(view
, &DolphinView::directoryLoadingCompleted
,
2136 this, &DolphinMainWindow::disableStopAction
);
2137 connect(view
, &DolphinView::directoryLoadingCompleted
,
2138 this, &DolphinMainWindow::slotDirectoryLoadingCompleted
);
2139 connect(view
, &DolphinView::goBackRequested
,
2140 this, &DolphinMainWindow::goBack
);
2141 connect(view
, &DolphinView::goForwardRequested
,
2142 this, &DolphinMainWindow::goForward
);
2143 connect(view
, &DolphinView::urlActivated
,
2144 this, &DolphinMainWindow::handleUrl
);
2145 connect(view
, &DolphinView::goUpRequested
,
2146 this, &DolphinMainWindow::goUp
);
2148 connect(container
->urlNavigatorInternalWithHistory(), &KUrlNavigator::urlChanged
,
2149 this, &DolphinMainWindow::changeUrl
);
2150 connect(container
->urlNavigatorInternalWithHistory(), &KUrlNavigator::historyChanged
,
2151 this, &DolphinMainWindow::updateHistory
);
2153 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>
2154 (actionCollection()->action(QStringLiteral("url_navigators")));
2155 const KUrlNavigator
*navigator
= m_tabWidget
->currentTabPage()->primaryViewActive() ?
2156 navigators
->primaryUrlNavigator() :
2157 navigators
->secondaryUrlNavigator();
2159 QAction
*editableLocactionAction
= actionCollection()->action(QStringLiteral("editable_location"));
2160 editableLocactionAction
->setChecked(navigator
->isUrlEditable());
2161 connect(navigator
, &KUrlNavigator::editableStateChanged
,
2162 this, &DolphinMainWindow::slotEditableStateChanged
);
2163 connect(navigator
, &KUrlNavigator::tabRequested
,
2164 this, &DolphinMainWindow::openNewTab
);
2168 void DolphinMainWindow::updateSplitAction()
2170 QAction
* splitAction
= actionCollection()->action(QStringLiteral("split_view"));
2171 const DolphinTabPage
* tabPage
= m_tabWidget
->currentTabPage();
2172 if (tabPage
->splitViewEnabled()) {
2173 if (GeneralSettings::closeActiveSplitView() ? tabPage
->primaryViewActive() : !tabPage
->primaryViewActive()) {
2174 splitAction
->setText(i18nc("@action:intoolbar Close left view", "Close"));
2175 splitAction
->setToolTip(i18nc("@info", "Close left view"));
2176 splitAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-left-close")));
2178 splitAction
->setText(i18nc("@action:intoolbar Close right view", "Close"));
2179 splitAction
->setToolTip(i18nc("@info", "Close right view"));
2180 splitAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-right-close")));
2183 splitAction
->setText(i18nc("@action:intoolbar Split view", "Split"));
2184 splitAction
->setToolTip(i18nc("@info", "Split view"));
2185 splitAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-right-new")));
2189 void DolphinMainWindow::updateAllowedToolbarAreas()
2191 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>
2192 (actionCollection()->action(QStringLiteral("url_navigators")));
2193 if (toolBar()->actions().contains(navigators
)) {
2194 toolBar()->setAllowedAreas(Qt::TopToolBarArea
| Qt::BottomToolBarArea
);
2195 if (toolBarArea(toolBar()) == Qt::LeftToolBarArea
||
2196 toolBarArea(toolBar()) == Qt::RightToolBarArea
) {
2197 addToolBar(Qt::TopToolBarArea
, toolBar());
2200 toolBar()->setAllowedAreas(Qt::AllToolBarAreas
);
2204 bool DolphinMainWindow::isKompareInstalled() const
2206 static bool initialized
= false;
2207 static bool installed
= false;
2209 // TODO: maybe replace this approach later by using a menu
2210 // plugin like kdiff3plugin.cpp
2211 installed
= !QStandardPaths::findExecutable(QStringLiteral("kompare")).isEmpty();
2217 void DolphinMainWindow::createPanelAction(const QIcon
& icon
,
2218 const QKeySequence
& shortcut
,
2219 QAction
* dockAction
,
2220 const QString
& actionName
)
2222 QAction
* panelAction
= actionCollection()->addAction(actionName
);
2223 panelAction
->setCheckable(true);
2224 panelAction
->setChecked(dockAction
->isChecked());
2225 panelAction
->setText(dockAction
->text());
2226 panelAction
->setIcon(icon
);
2227 actionCollection()->setDefaultShortcut(panelAction
, shortcut
);
2229 connect(panelAction
, &QAction::triggered
, dockAction
, &QAction::trigger
);
2230 connect(dockAction
, &QAction::toggled
, panelAction
, &QAction::setChecked
);
2233 void DolphinMainWindow::setupWhatsThis()
2236 menuBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2237 "<emphasis>Menubar</emphasis>. It provides access to commands and "
2238 "configuration options. Left-click on any of the menus on this "
2239 "bar to see its contents.</para><para>The Menubar can be hidden "
2240 "by unchecking <interface>Settings|Show Menubar</interface>. Then "
2241 "most of its contents become available through a <interface>Control"
2242 "</interface> button on the <emphasis>Toolbar</emphasis>.</para>"));
2243 toolBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2244 "<emphasis>Toolbar</emphasis>. It allows quick access to "
2245 "frequently used actions.</para><para>It is highly customizable. "
2246 "All items you see in the <interface>Control</interface> menu or "
2247 "in the <interface>Menubar</interface> can be placed on the "
2248 "Toolbar. Just right-click on it and select <interface>Configure "
2249 "Toolbars…</interface> or find this action in the <interface>"
2250 "Control</interface> or <interface>Settings</interface> menu."
2251 "</para><para>The location of the bar and the style of its "
2252 "buttons can also be changed in the right-click menu. Right-click "
2253 "a button if you want to show or hide its text.</para>"));
2254 m_tabWidget
->setWhatsThis(xi18nc("@info:whatsthis main view",
2255 "<para>Here you can see the <emphasis>folders</emphasis> and "
2256 "<emphasis>files</emphasis> that are at the location described in "
2257 "the <interface>Location Bar</interface> above. This area is the "
2258 "central part of this application where you navigate to the files "
2259 "you want to use.</para><para>For an elaborate and general "
2260 "introduction to this application <link "
2261 "url='https://userbase.kde.org/Dolphin/File_Management#Introduction_to_Dolphin'>"
2262 "click here</link>. This will open an introductory article from "
2263 "the <emphasis>KDE UserBase Wiki</emphasis>.</para><para>For brief "
2264 "explanations of all the features of this <emphasis>view</emphasis> "
2265 "<link url='help:/dolphin/dolphin-view.html'>click here</link> "
2266 "instead. This will open a page from the <emphasis>Handbook"
2267 "</emphasis> that covers the basics.</para>"));
2270 actionCollection()->action(KStandardAction::name(KStandardAction::KeyBindings
))
2271 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window "
2272 "that lists the <emphasis>keyboard shortcuts</emphasis>.<nl/>"
2273 "There you can set up key combinations to trigger an action when "
2274 "they are pressed simultaneously. All commands in this application can "
2275 "be triggered this way.</para>"));
2276 actionCollection()->action(KStandardAction::name(KStandardAction::ConfigureToolbars
))
2277 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window in which "
2278 "you can change which buttons appear on the <emphasis>Toolbar</emphasis>.</para>"
2279 "<para>All items you see in the <interface>Control</interface> menu "
2280 "or in the <interface>Menubar</interface> can also be placed on the Toolbar.</para>"));
2281 actionCollection()->action(KStandardAction::name(KStandardAction::Preferences
))
2282 ->setWhatsThis(xi18nc("@info:whatsthis","This opens a window where you can "
2283 "change a multitude of settings for this application. For an explanation "
2284 "of the various settings go to the chapter <emphasis>Configuring Dolphin"
2285 "</emphasis> in <interface>Help|Dolphin Handbook</interface>."));
2288 // The whatsthis has to be set for the m_helpMenu and for the
2289 // StandardAction separately because both are used in different locations.
2290 // m_helpMenu is only used for createControlButton() button.
2292 auto setStandardActionWhatsThis
= [this](KStandardAction::StandardAction actionId
,
2293 const QString
&whatsThis
) {
2294 if (auto *action
= actionCollection()->action(KStandardAction::name(actionId
))) {
2295 action
->setWhatsThis(whatsThis
);
2298 auto setHelpActionWhatsThis
= [this](KHelpMenu::MenuId menuId
, const QString
&whatsThis
) {
2299 if (auto *action
= m_helpMenu
->action(menuId
)) {
2300 action
->setWhatsThis(whatsThis
);
2304 // Links do not work within the Menubar so texts without links are provided there.
2306 // i18n: If the external link isn't available in your language you should
2307 // probably state the external link language at least in brackets to not
2308 // frustrate the user. If there are multiple languages that the user might
2309 // know with a reasonable chance you might want to have 2 external links.
2310 // The same is in my opinion true for every external link you translate.
2311 const QString whatsThisHelpContents
= xi18nc("@info:whatsthis handbook",
2312 "<para>This opens the Handbook for this application. It provides "
2313 "explanations for every part of <emphasis>Dolphin</emphasis>.</para>");
2314 setStandardActionWhatsThis(KStandardAction::HelpContents
, whatsThisHelpContents
2315 + xi18nc("@info:whatsthis second half of handbook hb text without link",
2316 "<para>If you want more elaborate introductions to the "
2317 "different features of <emphasis>Dolphin</emphasis> "
2318 "go to the KDE UserBase Wiki.</para>"));
2319 setHelpActionWhatsThis(KHelpMenu::menuHelpContents
, whatsThisHelpContents
2320 + xi18nc("@info:whatsthis second half of handbook text with link",
2321 "<para>If you want more elaborate introductions to the "
2322 "different features of <emphasis>Dolphin</emphasis> "
2323 "<link url='https://userbase.kde.org/Dolphin/File_Management'>click here</link>. "
2324 "It will open the dedicated page in the KDE UserBase Wiki.</para>"));
2326 const QString whatsThisWhatsThis
= xi18nc("@info:whatsthis whatsthis button",
2327 "<para>This is the button that invokes the help feature you are "
2328 "using right now! Click it, then click any component of this "
2329 "application to ask \"What's this?\" about it. The mouse cursor "
2330 "will change appearance if no help is available for a spot.</para>");
2331 setStandardActionWhatsThis(KStandardAction::WhatsThis
, whatsThisWhatsThis
2332 + xi18nc("@info:whatsthis second half of whatsthis button text without link",
2333 "<para>There are two other ways to get help for this application: The "
2334 "<interface>Dolphin Handbook</interface> in the <interface>Help"
2335 "</interface> menu and the <emphasis>KDE UserBase Wiki</emphasis> "
2336 "article about <emphasis>File Management</emphasis> online."
2337 "</para><para>The \"What's this?\" help is "
2338 "missing in most other windows so don't get too used to this.</para>"));
2339 setHelpActionWhatsThis(KHelpMenu::menuWhatsThis
, whatsThisWhatsThis
2340 + xi18nc("@info:whatsthis second half of whatsthis button text with link",
2341 "<para>There are two other ways to get help: "
2342 "The <link url='help:/dolphin/index.html'>Dolphin Handbook</link> and "
2343 "the <link url='https://userbase.kde.org/Dolphin/File_Management'>KDE "
2344 "UserBase Wiki</link>.</para><para>The \"What's this?\" help is "
2345 "missing in most other windows so don't get too used to this.</para>"));
2347 const QString whatsThisReportBug
= xi18nc("@info:whatsthis","<para>This opens a "
2348 "window that will guide you through reporting errors or flaws "
2349 "in this application or in other KDE software.</para>");
2350 setStandardActionWhatsThis(KStandardAction::ReportBug
, whatsThisReportBug
);
2351 setHelpActionWhatsThis(KHelpMenu::menuReportBug
, whatsThisReportBug
2352 + xi18nc("@info:whatsthis second half of reportbug text with link",
2353 "<para>High-quality bug reports are much appreciated. To learn "
2354 "how to make your bug report as effective as possible "
2355 "<link url='https://community.kde.org/Get_Involved/Bug_Reporting'>"
2356 "click here</link>.</para>"));
2358 const QString whatsThisDonate
= xi18nc("@info:whatsthis","<para>This opens a "
2359 "<emphasis>web page</emphasis> where you can donate to "
2360 "support the continued work on this application and many "
2361 "other projects by the <emphasis>KDE</emphasis> community.</para>"
2362 "<para>Donating is the easiest and fastest way to efficiently "
2363 "support KDE and its projects. KDE projects are available for "
2364 "free therefore your donation is needed to cover things that "
2365 "require money like servers, contributor meetings, etc.</para>"
2366 "<para><emphasis>KDE e.V.</emphasis> is the non-profit "
2367 "organization behind the KDE community.</para>");
2368 setStandardActionWhatsThis(KStandardAction::Donate
, whatsThisDonate
);
2369 setHelpActionWhatsThis(KHelpMenu::menuDonate
, whatsThisDonate
);
2371 const QString whatsThisSwitchLanguage
= xi18nc("@info:whatsthis",
2372 "With this you can change the language this application uses."
2373 "<nl/>You can even set secondary languages which will be used "
2374 "if texts are not available in your preferred language.");
2375 setStandardActionWhatsThis(KStandardAction::SwitchApplicationLanguage
,
2376 whatsThisSwitchLanguage
);
2377 setHelpActionWhatsThis(KHelpMenu::menuSwitchLanguage
, whatsThisSwitchLanguage
);
2379 const QString whatsThisAboutApp
= xi18nc("@info:whatsthis","This opens a "
2380 "window that informs you about the version, license, "
2381 "used libraries and maintainers of this application.");
2382 setStandardActionWhatsThis(KStandardAction::AboutApp
, whatsThisAboutApp
);
2383 setHelpActionWhatsThis(KHelpMenu::menuAboutApp
, whatsThisAboutApp
);
2385 const QString whatsThisAboutKDE
= xi18nc("@info:whatsthis","This opens a "
2386 "window with information about <emphasis>KDE</emphasis>. "
2387 "The KDE community are the people behind this free software."
2388 "<nl/>If you like using this application but don't know "
2389 "about KDE or want to see a cute dragon have a look!");
2390 setStandardActionWhatsThis(KStandardAction::AboutKDE
, whatsThisAboutKDE
);
2391 setHelpActionWhatsThis(KHelpMenu::menuAboutKDE
, whatsThisAboutKDE
);
2394 bool DolphinMainWindow::addHamburgerMenuToToolbar()
2396 QDomDocument domDocument
= KXMLGUIClient::domDocument();
2397 if (domDocument
.isNull()) {
2400 QDomNode toolbar
= domDocument
.elementsByTagName(QStringLiteral("ToolBar")).at(0);
2401 if (toolbar
.isNull()) {
2405 QDomElement hamburgerMenuElement
= domDocument
.createElement(QStringLiteral("Action"));
2406 hamburgerMenuElement
.setAttribute(QStringLiteral("name"), QStringLiteral("hamburger_menu"));
2407 toolbar
.appendChild(hamburgerMenuElement
);
2409 KXMLGUIFactory::saveConfigFile(domDocument
, xmlFile());
2413 // Make sure to also remove the <KXMLGUIFactory> and <QDomDocument> include
2414 // whenever this method is removed (maybe in the year ~2026).
2417 bool DolphinMainWindow::event(QEvent
*event
)
2419 if (event
->type() == QEvent::WhatsThisClicked
) {
2421 QWhatsThisClickedEvent
* whatsThisEvent
= dynamic_cast<QWhatsThisClickedEvent
*>(event
);
2422 QDesktopServices::openUrl(QUrl(whatsThisEvent
->href()));
2425 return KXmlGuiWindow::event(event
);
2428 bool DolphinMainWindow::eventFilter(QObject
* obj
, QEvent
* event
)
2431 if (event
->type() == QEvent::WhatsThisClicked
) {
2433 QWhatsThisClickedEvent
* whatsThisEvent
= dynamic_cast<QWhatsThisClickedEvent
*>(event
);
2434 QDesktopServices::openUrl(QUrl(whatsThisEvent
->href()));
2440 // Set a sane initial window size
2441 QSize
DolphinMainWindow::sizeHint() const
2443 return KXmlGuiWindow::sizeHint().expandedTo(QSize(760, 550));
2446 void DolphinMainWindow::saveNewToolbarConfig()
2448 KXmlGuiWindow::saveNewToolbarConfig(); // Applies the new config. This has to be called first
2449 // because the rest of this method decides things
2450 // based on the new config.
2451 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>
2452 (actionCollection()->action(QStringLiteral("url_navigators")));
2453 if (!toolBar()->actions().contains(navigators
)) {
2454 m_tabWidget
->currentTabPage()->insertNavigatorsWidget(navigators
);
2456 updateAllowedToolbarAreas();
2457 (static_cast<KHamburgerMenu
*>(actionCollection()->action(KStandardAction::name(
2458 KStandardAction::HamburgerMenu
))))->hideActionsOf(toolBar());
2461 void DolphinMainWindow::focusTerminalPanel()
2463 if (m_terminalPanel
->isVisible()) {
2464 if (m_terminalPanel
->terminalHasFocus()) {
2465 m_activeViewContainer
->view()->setFocus(Qt::FocusReason::ShortcutFocusReason
);
2466 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
2468 m_terminalPanel
->setFocus(Qt::FocusReason::ShortcutFocusReason
);
2469 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
2472 actionCollection()->action(QStringLiteral("show_terminal_panel"))->trigger();
2473 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
2477 DolphinMainWindow::UndoUiInterface::UndoUiInterface() :
2478 KIO::FileUndoManager::UiInterface()
2482 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
2486 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
* job
)
2488 DolphinMainWindow
* mainWin
= qobject_cast
<DolphinMainWindow
*>(parentWidget());
2490 DolphinViewContainer
* container
= mainWin
->activeViewContainer();
2491 container
->showMessage(job
->errorString(), DolphinViewContainer::Error
);
2493 KIO::FileUndoManager::UiInterface::jobError(job
);
2497 bool DolphinMainWindow::isUrlOpen(const QString
& url
)
2499 return m_tabWidget
->isUrlOpen(QUrl::fromUserInput((url
)));