2 * SPDX-FileCopyrightText: 2006 Peter Penz <peter.penz19@gmail.com>
3 * SPDX-FileCopyrightText: 2006 Stefan Monov <logixoul@gmail.com>
4 * SPDX-FileCopyrightText: 2006 Cvetoslav Ludmiloff <ludmiloff@gmail.com>
6 * SPDX-License-Identifier: GPL-2.0-or-later
9 #include "dolphinmainwindow.h"
11 #include "dolphinmainwindowadaptor.h"
13 #include "dolphinbookmarkhandler.h"
14 #include "dolphindockwidget.h"
15 #include "dolphincontextmenu.h"
16 #include "dolphinnavigatorswidgetaction.h"
17 #include "dolphinnewfilemenu.h"
18 #include "dolphinrecenttabsmenu.h"
19 #include "dolphinplacesmodelsingleton.h"
20 #include "dolphinurlnavigatorscontroller.h"
21 #include "dolphinviewcontainer.h"
22 #include "dolphintabpage.h"
23 #include "middleclickactioneventfilter.h"
24 #include "panels/folders/folderspanel.h"
25 #include "panels/places/placespanel.h"
26 #include "panels/terminal/terminalpanel.h"
27 #include "settings/dolphinsettingsdialog.h"
28 #include "statusbar/dolphinstatusbar.h"
29 #include "views/dolphinviewactionhandler.h"
30 #include "views/dolphinremoteencoding.h"
31 #include "views/draganddrophelper.h"
32 #include "views/viewproperties.h"
33 #include "views/dolphinnewfilemenuobserver.h"
34 #include "dolphin_generalsettings.h"
36 #include <KActionCollection>
37 #include <KActionMenu>
38 #include <KAuthorized>
41 #include <KDualAction>
42 #include <KFileItemListProperties>
44 #include <KIO/CommandLauncherJob>
45 #include <KIO/JobUiDelegate>
46 #include <KIO/OpenFileManagerWindowJob>
47 #include <KIO/OpenUrlJob>
48 #include <KJobWidgets>
49 #include <KLocalizedString>
50 #include <KMessageBox>
51 #include <KMoreToolsMenuFactory>
52 #include <KProtocolInfo>
53 #include <KProtocolManager>
55 #include <KShortcutsDialog>
56 #include <KStandardAction>
57 #include <KStartupInfo>
59 #include <KTerminalLauncherJob>
60 #include <KToggleAction>
62 #include <KToolBarPopupAction>
63 #include <KUrlComboBox>
64 #include <KUrlNavigator>
65 #include <KWindowSystem>
66 #include <KXMLGUIFactory>
68 #include <kio_version.h>
70 #include <QApplication>
72 #include <QCloseEvent>
73 #include <QDesktopServices>
75 #include <QDomDocument>
79 #include <QPushButton>
81 #include <QStandardPaths>
83 #include <QToolButton>
84 #include <QWhatsThisClickedEvent>
87 // Used for GeneralSettings::version() to determine whether
88 // an updated version of Dolphin is running, so as to migrate
89 // removed/renamed ...etc config entries; increment it in such
91 const int CurrentDolphinVersion
= 202;
92 // The maximum number of entries in the back/forward popup menu
93 const int MaxNumberOfNavigationentries
= 12;
94 // The maximum number of "Activate Tab" shortcuts
95 const int MaxActivateTabShortcuts
= 9;
98 DolphinMainWindow::DolphinMainWindow() :
99 KXmlGuiWindow(nullptr),
100 m_newFileMenu(nullptr),
102 m_tabWidget(nullptr),
103 m_activeViewContainer(nullptr),
104 m_actionHandler(nullptr),
105 m_remoteEncoding(nullptr),
107 m_bookmarkHandler(nullptr),
108 m_controlButton(nullptr),
109 m_updateToolBarTimer(nullptr),
110 m_lastHandleUrlOpenJob(nullptr),
111 m_terminalPanel(nullptr),
112 m_placesPanel(nullptr),
113 m_tearDownFromPlacesRequested(false),
114 m_backAction(nullptr),
115 m_forwardAction(nullptr)
117 Q_INIT_RESOURCE(dolphin
);
119 new MainWindowAdaptor(this);
122 setWindowFlags(Qt::WindowContextHelpButtonHint
);
124 setComponentName(QStringLiteral("dolphin"), QGuiApplication::applicationDisplayName());
125 setObjectName(QStringLiteral("Dolphin#"));
127 setStateConfigGroup("State");
129 connect(&DolphinNewFileMenuObserver::instance(), &DolphinNewFileMenuObserver::errorMessage
,
130 this, &DolphinMainWindow::showErrorMessage
);
132 KIO::FileUndoManager
* undoManager
= KIO::FileUndoManager::self();
133 undoManager
->setUiInterface(new UndoUiInterface());
135 connect(undoManager
, &KIO::FileUndoManager::undoAvailable
,
136 this, &DolphinMainWindow::slotUndoAvailable
);
137 connect(undoManager
, &KIO::FileUndoManager::undoTextChanged
,
138 this, &DolphinMainWindow::slotUndoTextChanged
);
139 connect(undoManager
, &KIO::FileUndoManager::jobRecordingStarted
,
140 this, &DolphinMainWindow::clearStatusBar
);
141 connect(undoManager
, &KIO::FileUndoManager::jobRecordingFinished
,
142 this, &DolphinMainWindow::showCommand
);
144 const bool firstRun
= (GeneralSettings::version() < 200);
146 GeneralSettings::setViewPropsTimestamp(QDateTime::currentDateTime());
149 setAcceptDrops(true);
151 auto *navigatorsWidgetAction
= new DolphinNavigatorsWidgetAction(this);
152 actionCollection()->addAction(QStringLiteral("url_navigators"), navigatorsWidgetAction
);
153 m_tabWidget
= new DolphinTabWidget(navigatorsWidgetAction
, this);
154 m_tabWidget
->setObjectName("tabWidget");
155 connect(m_tabWidget
, &DolphinTabWidget::activeViewChanged
,
156 this, &DolphinMainWindow::activeViewChanged
);
157 connect(m_tabWidget
, &DolphinTabWidget::tabCountChanged
,
158 this, &DolphinMainWindow::tabCountChanged
);
159 connect(m_tabWidget
, &DolphinTabWidget::currentUrlChanged
,
160 this, &DolphinMainWindow::updateWindowTitle
);
161 setCentralWidget(m_tabWidget
);
165 m_actionHandler
= new DolphinViewActionHandler(actionCollection(), this);
166 connect(m_actionHandler
, &DolphinViewActionHandler::actionBeingHandled
, this, &DolphinMainWindow::clearStatusBar
);
167 connect(m_actionHandler
, &DolphinViewActionHandler::createDirectoryTriggered
, this, &DolphinMainWindow::createDirectory
);
168 connect(m_actionHandler
, &DolphinViewActionHandler::setSelectionMode
, this, &DolphinMainWindow::slotSetSelectionMode
);
170 m_remoteEncoding
= new DolphinRemoteEncoding(this, m_actionHandler
);
171 connect(this, &DolphinMainWindow::urlChanged
,
172 m_remoteEncoding
, &DolphinRemoteEncoding::slotAboutToOpenUrl
);
176 setupGUI(Save
| Create
| ToolBar
);
177 stateChanged(QStringLiteral("new_file"));
179 QClipboard
* clipboard
= QApplication::clipboard();
180 connect(clipboard
, &QClipboard::dataChanged
,
181 this, &DolphinMainWindow::updatePasteAction
);
183 QAction
* toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
184 toggleFilterBarAction
->setChecked(GeneralSettings::filterBar());
187 menuBar()->setVisible(false);
190 const bool showMenu
= !menuBar()->isHidden();
191 QAction
* showMenuBarAction
= actionCollection()->action(KStandardAction::name(KStandardAction::ShowMenubar
));
192 showMenuBarAction
->setChecked(showMenu
); // workaround for bug #171080
194 auto hamburgerMenu
= static_cast<KHamburgerMenu
*>(actionCollection()->action(
195 KStandardAction::name(KStandardAction::HamburgerMenu
)));
196 hamburgerMenu
->setMenuBar(menuBar());
197 hamburgerMenu
->setShowMenuBarAction(showMenuBarAction
);
198 connect(hamburgerMenu
, &KHamburgerMenu::aboutToShowMenu
,
199 this, &DolphinMainWindow::updateHamburgerMenu
);
200 hamburgerMenu
->hideActionsOf(toolBar());
201 if (GeneralSettings::version() < 201 && !toolBar()->actions().contains(hamburgerMenu
)) {
202 addHamburgerMenuToToolbar();
205 updateAllowedToolbarAreas();
207 // enable middle-click on back/forward/up to open in a new tab
208 auto *middleClickEventFilter
= new MiddleClickActionEventFilter(this);
209 connect(middleClickEventFilter
, &MiddleClickActionEventFilter::actionMiddleClicked
, this, &DolphinMainWindow::slotToolBarActionMiddleClicked
);
210 toolBar()->installEventFilter(middleClickEventFilter
);
214 connect(KSycoca::self(), &KSycoca::databaseChanged
, this, &DolphinMainWindow::updateOpenPreferredSearchToolAction
);
216 QTimer::singleShot(0, this, &DolphinMainWindow::updateOpenPreferredSearchToolAction
);
218 m_fileItemActions
.setParentWidget(this);
219 connect(&m_fileItemActions
, &KFileItemActions::error
, this, [this](const QString
&errorMessage
) {
220 showErrorMessage(errorMessage
);
223 connect(GeneralSettings::self(), &GeneralSettings::splitViewChanged
,
224 this, &DolphinMainWindow::slotSplitViewChanged
);
227 DolphinMainWindow::~DolphinMainWindow()
229 // This fixes a crash on Wayland when closing the mainwindow while another dialog is open.
230 disconnect(QGuiApplication::clipboard(), &QClipboard::dataChanged
, this, &DolphinMainWindow::updatePasteAction
);
233 QVector
<DolphinViewContainer
*> DolphinMainWindow::viewContainers() const
235 QVector
<DolphinViewContainer
*> viewContainers
;
237 for (int i
= 0; i
< m_tabWidget
->count(); ++i
) {
238 DolphinTabPage
*tabPage
= m_tabWidget
->tabPageAt(i
);
240 viewContainers
<< tabPage
->primaryViewContainer();
241 if (tabPage
->splitViewEnabled()) {
242 viewContainers
<< tabPage
->secondaryViewContainer();
245 return viewContainers
;
248 void DolphinMainWindow::openDirectories(const QList
<QUrl
>& dirs
, bool splitView
)
250 m_tabWidget
->openDirectories(dirs
, splitView
);
253 void DolphinMainWindow::openDirectories(const QStringList
& dirs
, bool splitView
)
255 openDirectories(QUrl::fromStringList(dirs
), splitView
);
258 void DolphinMainWindow::openFiles(const QList
<QUrl
>& files
, bool splitView
)
260 m_tabWidget
->openFiles(files
, splitView
);
263 bool DolphinMainWindow::isFoldersPanelEnabled() const
265 return actionCollection()->action(QStringLiteral("show_folders_panel"))->isChecked();
268 bool DolphinMainWindow::isInformationPanelEnabled() const
271 return actionCollection()->action(QStringLiteral("show_information_panel"))->isChecked();
277 void DolphinMainWindow::openFiles(const QStringList
& files
, bool splitView
)
279 openFiles(QUrl::fromStringList(files
), splitView
);
282 void DolphinMainWindow::activateWindow()
284 window()->setAttribute(Qt::WA_NativeWindow
, true);
285 KStartupInfo::setNewStartupId(window()->windowHandle(), KStartupInfo::startupId());
286 KWindowSystem::activateWindow(window()->effectiveWinId());
289 bool DolphinMainWindow::isActiveWindow()
291 return window()->isActiveWindow();
294 void DolphinMainWindow::showCommand(CommandType command
)
296 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
298 case KIO::FileUndoManager::Copy
:
299 statusBar
->setText(i18nc("@info:status", "Successfully copied."));
301 case KIO::FileUndoManager::Move
:
302 statusBar
->setText(i18nc("@info:status", "Successfully moved."));
304 case KIO::FileUndoManager::Link
:
305 statusBar
->setText(i18nc("@info:status", "Successfully linked."));
307 case KIO::FileUndoManager::Trash
:
308 statusBar
->setText(i18nc("@info:status", "Successfully moved to trash."));
310 case KIO::FileUndoManager::Rename
:
311 statusBar
->setText(i18nc("@info:status", "Successfully renamed."));
314 case KIO::FileUndoManager::Mkdir
:
315 statusBar
->setText(i18nc("@info:status", "Created folder."));
323 void DolphinMainWindow::pasteIntoFolder()
325 m_activeViewContainer
->view()->pasteIntoFolder();
328 void DolphinMainWindow::changeUrl(const QUrl
&url
)
330 if (!KProtocolManager::supportsListing(url
)) {
331 // The URL navigator only checks for validity, not
332 // if the URL can be listed. An error message is
333 // shown due to DolphinViewContainer::restoreView().
337 m_activeViewContainer
->setUrl(url
);
338 updateFileAndEditActions();
343 Q_EMIT
urlChanged(url
);
346 void DolphinMainWindow::slotTerminalDirectoryChanged(const QUrl
& url
)
348 if (m_tearDownFromPlacesRequested
&& url
== QUrl::fromLocalFile(QDir::homePath())) {
349 m_placesPanel
->proceedWithTearDown();
350 m_tearDownFromPlacesRequested
= false;
353 m_activeViewContainer
->setAutoGrabFocus(false);
355 m_activeViewContainer
->setAutoGrabFocus(true);
358 void DolphinMainWindow::slotEditableStateChanged(bool editable
)
360 KToggleAction
* editableLocationAction
=
361 static_cast<KToggleAction
*>(actionCollection()->action(QStringLiteral("editable_location")));
362 editableLocationAction
->setChecked(editable
);
365 void DolphinMainWindow::slotSelectionChanged(const KFileItemList
& selection
)
367 updateFileAndEditActions();
369 const int selectedUrlsCount
= m_tabWidget
->currentTabPage()->selectedItemsCount();
371 QAction
* compareFilesAction
= actionCollection()->action(QStringLiteral("compare_files"));
372 if (selectedUrlsCount
== 2) {
373 compareFilesAction
->setEnabled(isKompareInstalled());
375 compareFilesAction
->setEnabled(false);
378 Q_EMIT
selectionChanged(selection
);
381 void DolphinMainWindow::updateHistory()
383 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
384 const int index
= urlNavigator
->historyIndex();
386 QAction
* backAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Back
));
388 backAction
->setToolTip(i18nc("@info", "Go back"));
389 backAction
->setWhatsThis(i18nc("@info:whatsthis go back", "Return to the previously viewed folder."));
390 backAction
->setEnabled(index
< urlNavigator
->historySize() - 1);
393 QAction
* forwardAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Forward
));
395 forwardAction
->setToolTip(i18nc("@info", "Go forward"));
396 forwardAction
->setWhatsThis(xi18nc("@info:whatsthis go forward",
397 "This undoes a <interface>Go|Back</interface> action."));
398 forwardAction
->setEnabled(index
> 0);
402 void DolphinMainWindow::updateFilterBarAction(bool show
)
404 QAction
* toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
405 toggleFilterBarAction
->setChecked(show
);
408 void DolphinMainWindow::openNewMainWindow()
410 Dolphin::openNewWindow({m_activeViewContainer
->url()}, this);
413 void DolphinMainWindow::openNewActivatedTab()
415 // keep browsers compatibility, new tab is always after last one
416 auto openNewTabAfterLastTabConfigured
= GeneralSettings::openNewTabAfterLastTab();
417 GeneralSettings::setOpenNewTabAfterLastTab(true);
418 m_tabWidget
->openNewActivatedTab();
419 GeneralSettings::setOpenNewTabAfterLastTab(openNewTabAfterLastTabConfigured
);
422 void DolphinMainWindow::addToPlaces()
427 // If nothing is selected, act on the current dir
428 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
429 url
= m_activeViewContainer
->url();
430 name
= m_activeViewContainer
->placesText();
432 const auto dirToAdd
= m_activeViewContainer
->view()->selectedItems().first();
433 url
= dirToAdd
.url();
434 name
= dirToAdd
.name();
438 if (m_activeViewContainer
->isSearchModeEnabled()) {
439 icon
= QStringLiteral("folder-saved-search-symbolic");
441 icon
= KIO::iconNameForUrl(url
);
443 DolphinPlacesModelSingleton::instance().placesModel()->addPlace(name
, url
, icon
);
447 void DolphinMainWindow::openNewTab(const QUrl
& url
)
449 m_tabWidget
->openNewTab(url
, QUrl());
452 void DolphinMainWindow::openNewTabAndActivate(const QUrl
&url
)
454 m_tabWidget
->openNewActivatedTab(url
, QUrl());
457 void DolphinMainWindow::openNewWindow(const QUrl
&url
)
459 Dolphin::openNewWindow({url
}, this);
462 void DolphinMainWindow::slotSplitViewChanged()
464 m_tabWidget
->currentTabPage()->setSplitViewEnabled(GeneralSettings::splitView(), WithAnimation
);
468 void DolphinMainWindow::openInNewTab()
470 const KFileItemList
& list
= m_activeViewContainer
->view()->selectedItems();
471 bool tabCreated
= false;
473 for (const KFileItem
& item
: list
) {
474 const QUrl
& url
= DolphinView::openItemAsFolderUrl(item
);
475 if (!url
.isEmpty()) {
481 // if no new tab has been created from the selection
482 // open the current directory in a new tab
484 openNewTab(m_activeViewContainer
->url());
488 void DolphinMainWindow::openInNewWindow()
492 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
493 if (list
.isEmpty()) {
494 newWindowUrl
= m_activeViewContainer
->url();
495 } else if (list
.count() == 1) {
496 const KFileItem
& item
= list
.first();
497 newWindowUrl
= DolphinView::openItemAsFolderUrl(item
);
500 if (!newWindowUrl
.isEmpty()) {
501 Dolphin::openNewWindow({newWindowUrl
}, this);
505 void DolphinMainWindow::showTarget()
507 const auto link
= m_activeViewContainer
->view()->selectedItems().at(0);
508 const auto linkLocationDir
= QFileInfo(link
.localPath()).absoluteDir();
509 auto linkDestination
= link
.linkDest();
510 if (QFileInfo(linkDestination
).isRelative()) {
511 linkDestination
= linkLocationDir
.filePath(linkDestination
);
513 if (QFileInfo::exists(linkDestination
)) {
514 KIO::highlightInFileManager({QUrl::fromLocalFile(linkDestination
).adjusted(QUrl::StripTrailingSlash
)});
516 m_activeViewContainer
->showMessage(xi18nc("@info", "Could not access <filename>%1</filename>.", linkDestination
),
517 DolphinViewContainer::Warning
);
521 void DolphinMainWindow::showEvent(QShowEvent
* event
)
523 KXmlGuiWindow::showEvent(event
);
525 if (!event
->spontaneous()) {
526 m_activeViewContainer
->view()->setFocus();
530 void DolphinMainWindow::closeEvent(QCloseEvent
* event
)
532 // Find out if Dolphin is closed directly by the user or
533 // by the session manager because the session is closed
534 bool closedByUser
= true;
535 if (qApp
->isSavingSession()) {
536 closedByUser
= false;
539 if (m_tabWidget
->count() > 1
540 && GeneralSettings::confirmClosingMultipleTabs()
541 && !GeneralSettings::rememberOpenedTabs()
543 // Ask the user if he really wants to quit and close all tabs.
544 // Open a confirmation dialog with 3 buttons:
545 // QDialogButtonBox::Yes -> Quit
546 // QDialogButtonBox::No -> Close only the current tab
547 // QDialogButtonBox::Cancel -> do nothing
548 QDialog
*dialog
= new QDialog(this, Qt::Dialog
);
549 dialog
->setWindowTitle(i18nc("@title:window", "Confirmation"));
550 dialog
->setModal(true);
551 QDialogButtonBox
* buttons
= new QDialogButtonBox(QDialogButtonBox::Yes
| QDialogButtonBox::No
| QDialogButtonBox::Cancel
);
552 KGuiItem::assign(buttons
->button(QDialogButtonBox::Yes
), KGuiItem(i18nc("@action:button 'Quit Dolphin' button", "&Quit %1", QGuiApplication::applicationDisplayName()), QIcon::fromTheme(QStringLiteral("application-exit"))));
553 KGuiItem::assign(buttons
->button(QDialogButtonBox::No
), KGuiItem(i18n("C&lose Current Tab"), QIcon::fromTheme(QStringLiteral("tab-close"))));
554 KGuiItem::assign(buttons
->button(QDialogButtonBox::Cancel
), KStandardGuiItem::cancel());
555 buttons
->button(QDialogButtonBox::Yes
)->setDefault(true);
557 bool doNotAskAgainCheckboxResult
= false;
559 const auto result
= KMessageBox::createKMessageBox(dialog
,
561 QMessageBox::Warning
,
562 i18n("You have multiple tabs open in this window, are you sure you want to quit?"),
564 i18n("Do not ask again"),
565 &doNotAskAgainCheckboxResult
,
566 KMessageBox::Notify
);
568 if (doNotAskAgainCheckboxResult
) {
569 GeneralSettings::setConfirmClosingMultipleTabs(false);
573 case QDialogButtonBox::Yes
:
576 case QDialogButtonBox::No
:
577 // Close only the current tab
578 m_tabWidget
->closeTab();
586 if (m_terminalPanel
&& m_terminalPanel
->hasProgramRunning() && GeneralSettings::confirmClosingTerminalRunningProgram() && closedByUser
) {
587 // Ask if the user really wants to quit Dolphin with a program that is still running in the Terminal panel
588 // Open a confirmation dialog with 3 buttons:
589 // QDialogButtonBox::Yes -> Quit
590 // QDialogButtonBox::No -> Show Terminal Panel
591 // QDialogButtonBox::Cancel -> do nothing
592 QDialog
*dialog
= new QDialog(this, Qt::Dialog
);
593 dialog
->setWindowTitle(i18nc("@title:window", "Confirmation"));
594 dialog
->setModal(true);
595 auto standardButtons
= QDialogButtonBox::Yes
| QDialogButtonBox::Cancel
;
596 if (!m_terminalPanel
->isVisible()) {
597 standardButtons
|= QDialogButtonBox::No
;
599 QDialogButtonBox
*buttons
= new QDialogButtonBox(standardButtons
);
600 KGuiItem::assign(buttons
->button(QDialogButtonBox::Yes
), KStandardGuiItem::quit());
601 if (!m_terminalPanel
->isVisible()) {
603 buttons
->button(QDialogButtonBox::No
),
604 KGuiItem(i18n("Show &Terminal Panel"), QIcon::fromTheme(QStringLiteral("dialog-scripts"))));
606 KGuiItem::assign(buttons
->button(QDialogButtonBox::Cancel
), KStandardGuiItem::cancel());
608 bool doNotAskAgainCheckboxResult
= false;
610 const auto result
= KMessageBox::createKMessageBox(
613 QMessageBox::Warning
,
614 i18n("The program '%1' is still running in the Terminal panel. Are you sure you want to quit?", m_terminalPanel
->runningProgramName()),
616 i18n("Do not ask again"),
617 &doNotAskAgainCheckboxResult
,
618 KMessageBox::Dangerous
);
620 if (doNotAskAgainCheckboxResult
) {
621 GeneralSettings::setConfirmClosingTerminalRunningProgram(false);
625 case QDialogButtonBox::Yes
:
628 case QDialogButtonBox::No
:
629 actionCollection()->action("show_terminal_panel")->trigger();
630 // Do not quit, ignore quit event
638 if (GeneralSettings::rememberOpenedTabs()) {
639 KConfigGui::setSessionConfig(QStringLiteral("dolphin"), QStringLiteral("dolphin"));
640 KConfig
*config
= KConfigGui::sessionConfig();
641 saveGlobalProperties(config
);
642 savePropertiesInternal(config
, 1);
646 GeneralSettings::setVersion(CurrentDolphinVersion
);
647 GeneralSettings::self()->save();
649 KXmlGuiWindow::closeEvent(event
);
652 void DolphinMainWindow::saveProperties(KConfigGroup
& group
)
654 m_tabWidget
->saveProperties(group
);
657 void DolphinMainWindow::readProperties(const KConfigGroup
& group
)
659 m_tabWidget
->readProperties(group
);
662 void DolphinMainWindow::updateNewMenu()
664 m_newFileMenu
->checkUpToDate();
665 #if KIO_VERSION >= QT_VERSION_CHECK(5, 97, 0)
666 m_newFileMenu
->setWorkingDirectory(activeViewContainer()->url());
668 m_newFileMenu
->setPopupFiles(QList
<QUrl
>() << activeViewContainer()->url());
672 void DolphinMainWindow::createDirectory()
674 #if KIO_VERSION >= QT_VERSION_CHECK(5, 97, 0)
675 m_newFileMenu
->setWorkingDirectory(activeViewContainer()->url());
677 m_newFileMenu
->setPopupFiles(QList
<QUrl
>() << activeViewContainer()->url());
679 m_newFileMenu
->createDirectory();
682 void DolphinMainWindow::quit()
687 void DolphinMainWindow::showErrorMessage(const QString
& message
)
689 m_activeViewContainer
->showMessage(message
, DolphinViewContainer::Error
);
692 void DolphinMainWindow::slotUndoAvailable(bool available
)
694 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
696 undoAction
->setEnabled(available
);
700 void DolphinMainWindow::slotUndoTextChanged(const QString
& text
)
702 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
704 undoAction
->setText(text
);
708 void DolphinMainWindow::undo()
711 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
712 KIO::FileUndoManager::self()->undo();
715 void DolphinMainWindow::cut()
717 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
718 m_activeViewContainer
->setSelectionModeEnabled(true, actionCollection(), SelectionModeBottomBar::Contents::CutContents
);
720 m_activeViewContainer
->view()->cutSelectedItemsToClipboard();
721 m_activeViewContainer
->setSelectionModeEnabled(false);
725 void DolphinMainWindow::copy()
727 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
728 m_activeViewContainer
->setSelectionModeEnabled(true, actionCollection(), SelectionModeBottomBar::Contents::CopyContents
);
730 m_activeViewContainer
->view()->copySelectedItemsToClipboard();
731 m_activeViewContainer
->setSelectionModeEnabled(false);
735 void DolphinMainWindow::paste()
737 m_activeViewContainer
->view()->paste();
740 void DolphinMainWindow::find()
742 m_activeViewContainer
->setSearchModeEnabled(true);
745 void DolphinMainWindow::updateSearchAction()
747 QAction
* toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
748 toggleSearchAction
->setChecked(m_activeViewContainer
->isSearchModeEnabled());
751 void DolphinMainWindow::updatePasteAction()
753 QAction
* pasteAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Paste
));
754 QPair
<bool, QString
> pasteInfo
= m_activeViewContainer
->view()->pasteInfo();
755 pasteAction
->setEnabled(pasteInfo
.first
);
756 pasteAction
->setText(pasteInfo
.second
);
759 void DolphinMainWindow::slotDirectoryLoadingCompleted()
764 void DolphinMainWindow::slotToolBarActionMiddleClicked(QAction
*action
)
766 if (action
== actionCollection()->action(KStandardAction::name(KStandardAction::Back
))) {
768 } else if (action
== actionCollection()->action(KStandardAction::name(KStandardAction::Forward
))) {
770 } else if (action
== actionCollection()->action(QStringLiteral("go_up"))) {
772 } else if (action
== actionCollection()->action(QStringLiteral("go_home"))) {
777 QAction
*DolphinMainWindow::urlNavigatorHistoryAction(const KUrlNavigator
*urlNavigator
, int historyIndex
, QObject
*parent
)
779 const QUrl url
= urlNavigator
->locationUrl(historyIndex
);
781 QString text
= url
.toDisplayString(QUrl::PreferLocalFile
);
783 if (!urlNavigator
->showFullPath()) {
784 const KFilePlacesModel
*placesModel
= DolphinPlacesModelSingleton::instance().placesModel();
786 const QModelIndex closestIdx
= placesModel
->closestItem(url
);
787 if (closestIdx
.isValid()) {
788 const QUrl placeUrl
= placesModel
->url(closestIdx
);
790 text
= placesModel
->text(closestIdx
);
792 QString pathInsidePlace
= url
.path().mid(placeUrl
.path().length());
794 if (!pathInsidePlace
.isEmpty() && !pathInsidePlace
.startsWith(QLatin1Char('/'))) {
795 pathInsidePlace
.prepend(QLatin1Char('/'));
798 if (pathInsidePlace
!= QLatin1Char('/')) {
799 text
.append(pathInsidePlace
);
804 QAction
*action
= new QAction(QIcon::fromTheme(KIO::iconNameForUrl(url
)), text
, parent
);
805 action
->setData(historyIndex
);
809 void DolphinMainWindow::slotAboutToShowBackPopupMenu()
811 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
813 m_backAction
->menu()->clear();
814 for (int i
= urlNavigator
->historyIndex() + 1; i
< urlNavigator
->historySize() && entries
< MaxNumberOfNavigationentries
; ++i
, ++entries
) {
815 QAction
*action
= urlNavigatorHistoryAction(urlNavigator
, i
, m_backAction
->menu());
817 m_backAction
->menu()->addAction(action
);
821 void DolphinMainWindow::slotGoBack(QAction
* action
)
823 int gotoIndex
= action
->data().value
<int>();
824 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
825 for (int i
= gotoIndex
- urlNavigator
->historyIndex(); i
> 0; --i
) {
830 void DolphinMainWindow::slotBackForwardActionMiddleClicked(QAction
* action
)
833 const KUrlNavigator
*urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
834 openNewTab(urlNavigator
->locationUrl(action
->data().value
<int>()));
838 void DolphinMainWindow::slotAboutToShowForwardPopupMenu()
840 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
842 m_forwardAction
->menu()->clear();
843 for (int i
= urlNavigator
->historyIndex() - 1; i
>= 0 && entries
< MaxNumberOfNavigationentries
; --i
, ++entries
) {
844 QAction
*action
= urlNavigatorHistoryAction(urlNavigator
, i
, m_forwardAction
->menu());
846 m_forwardAction
->menu()->addAction(action
);
850 void DolphinMainWindow::slotGoForward(QAction
* action
)
852 int gotoIndex
= action
->data().value
<int>();
853 const KUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
854 for (int i
= urlNavigator
->historyIndex() - gotoIndex
; i
> 0; --i
) {
859 void DolphinMainWindow::slotSetSelectionMode(bool enabled
, SelectionModeBottomBar::Contents bottomBarContents
)
861 m_activeViewContainer
->setSelectionModeEnabled(enabled
, actionCollection(), bottomBarContents
);
864 void DolphinMainWindow::selectAll()
868 // if the URL navigator is editable and focused, select the whole
869 // URL instead of all items of the view
871 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
872 QLineEdit
* lineEdit
= urlNavigator
->editor()->lineEdit();
873 const bool selectUrl
= urlNavigator
->isUrlEditable() &&
874 lineEdit
->hasFocus();
876 lineEdit
->selectAll();
878 m_activeViewContainer
->view()->selectAll();
882 void DolphinMainWindow::invertSelection()
885 m_activeViewContainer
->view()->invertSelection();
888 void DolphinMainWindow::toggleSplitView()
890 DolphinTabPage
* tabPage
= m_tabWidget
->currentTabPage();
891 tabPage
->setSplitViewEnabled(!tabPage
->splitViewEnabled(), WithAnimation
);
896 void DolphinMainWindow::toggleSplitStash()
898 DolphinTabPage
* tabPage
= m_tabWidget
->currentTabPage();
899 tabPage
->setSplitViewEnabled(false, WithAnimation
);
900 tabPage
->setSplitViewEnabled(true, WithAnimation
, QUrl("stash:/"));
903 void DolphinMainWindow::copyToInactiveSplitView()
905 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
906 m_activeViewContainer
->setSelectionModeEnabled(true, actionCollection(), SelectionModeBottomBar::Contents::CopyToOtherViewContents
);
908 m_tabWidget
->copyToInactiveSplitView();
909 m_activeViewContainer
->setSelectionModeEnabled(false);
913 void DolphinMainWindow::moveToInactiveSplitView()
915 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
916 m_activeViewContainer
->setSelectionModeEnabled(true, actionCollection(), SelectionModeBottomBar::Contents::MoveToOtherViewContents
);
918 m_tabWidget
->moveToInactiveSplitView();
919 m_activeViewContainer
->setSelectionModeEnabled(false);
923 void DolphinMainWindow::reloadView()
926 m_activeViewContainer
->reload();
927 m_activeViewContainer
->statusBar()->updateSpaceInfo();
930 void DolphinMainWindow::stopLoading()
932 m_activeViewContainer
->view()->stopLoading();
935 void DolphinMainWindow::enableStopAction()
937 actionCollection()->action(QStringLiteral("stop"))->setEnabled(true);
940 void DolphinMainWindow::disableStopAction()
942 actionCollection()->action(QStringLiteral("stop"))->setEnabled(false);
945 void DolphinMainWindow::toggleSelectionMode()
947 const bool checked
= !m_activeViewContainer
->isSelectionModeEnabled();
949 m_activeViewContainer
->setSelectionModeEnabled(checked
, actionCollection(), SelectionModeBottomBar::Contents::GeneralContents
);
950 actionCollection()->action(QStringLiteral("toggle_selection_mode"))->setChecked(checked
);
953 void DolphinMainWindow::showFilterBar()
955 m_activeViewContainer
->setFilterBarVisible(true);
958 void DolphinMainWindow::toggleFilterBar()
960 const bool checked
= !m_activeViewContainer
->isFilterBarVisible();
961 m_activeViewContainer
->setFilterBarVisible(checked
);
963 QAction
* toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
964 toggleFilterBarAction
->setChecked(checked
);
967 void DolphinMainWindow::toggleEditLocation()
971 QAction
* action
= actionCollection()->action(QStringLiteral("editable_location"));
972 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
973 urlNavigator
->setUrlEditable(action
->isChecked());
976 void DolphinMainWindow::replaceLocation()
978 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
979 QLineEdit
* lineEdit
= navigator
->editor()->lineEdit();
981 // If the text field currently has focus and everything is selected,
982 // pressing the keyboard shortcut returns the whole thing to breadcrumb mode
983 if (navigator
->isUrlEditable()
984 && lineEdit
->hasFocus()
985 && lineEdit
->selectedText() == lineEdit
->text() ) {
986 navigator
->setUrlEditable(false);
988 navigator
->setUrlEditable(true);
989 navigator
->setFocus();
990 lineEdit
->selectAll();
994 void DolphinMainWindow::togglePanelLockState()
996 const bool newLockState
= !GeneralSettings::lockPanels();
997 const auto childrenObjects
= children();
998 for (QObject
* child
: childrenObjects
) {
999 DolphinDockWidget
* dock
= qobject_cast
<DolphinDockWidget
*>(child
);
1001 dock
->setLocked(newLockState
);
1005 DolphinPlacesModelSingleton::instance().placesModel()->setPanelsLocked(newLockState
);
1007 GeneralSettings::setLockPanels(newLockState
);
1010 void DolphinMainWindow::slotTerminalPanelVisibilityChanged()
1012 if (m_terminalPanel
->isHiddenInVisibleWindow() && m_activeViewContainer
) {
1013 m_activeViewContainer
->view()->setFocus();
1017 void DolphinMainWindow::goBack()
1019 DolphinUrlNavigator
*urlNavigator
= m_activeViewContainer
->urlNavigatorInternalWithHistory();
1020 urlNavigator
->goBack();
1022 if (urlNavigator
->locationState().isEmpty()) {
1023 // An empty location state indicates a redirection URL,
1024 // which must be skipped too
1025 urlNavigator
->goBack();
1029 void DolphinMainWindow::goForward()
1031 m_activeViewContainer
->urlNavigatorInternalWithHistory()->goForward();
1034 void DolphinMainWindow::goUp()
1036 m_activeViewContainer
->urlNavigatorInternalWithHistory()->goUp();
1039 void DolphinMainWindow::goHome()
1041 m_activeViewContainer
->urlNavigatorInternalWithHistory()->goHome();
1044 void DolphinMainWindow::goBackInNewTab()
1046 const KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
1047 const int index
= urlNavigator
->historyIndex() + 1;
1048 openNewTab(urlNavigator
->locationUrl(index
));
1051 void DolphinMainWindow::goForwardInNewTab()
1053 const KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigatorInternalWithHistory();
1054 const int index
= urlNavigator
->historyIndex() - 1;
1055 openNewTab(urlNavigator
->locationUrl(index
));
1058 void DolphinMainWindow::goUpInNewTab()
1060 const QUrl currentUrl
= activeViewContainer()->urlNavigator()->locationUrl();
1061 openNewTab(KIO::upUrl(currentUrl
));
1064 void DolphinMainWindow::goHomeInNewTab()
1066 openNewTab(Dolphin::homeUrl());
1069 void DolphinMainWindow::compareFiles()
1071 const KFileItemList items
= m_tabWidget
->currentTabPage()->selectedItems();
1072 if (items
.count() != 2) {
1073 // The action is disabled in this case, but it could have been triggered
1074 // via D-Bus, see https://bugs.kde.org/show_bug.cgi?id=325517
1078 QUrl urlA
= items
.at(0).url();
1079 QUrl urlB
= items
.at(1).url();
1081 QString
command(QStringLiteral("kompare -c \""));
1082 command
.append(urlA
.toDisplayString(QUrl::PreferLocalFile
));
1083 command
.append("\" \"");
1084 command
.append(urlB
.toDisplayString(QUrl::PreferLocalFile
));
1085 command
.append('\"');
1087 KIO::CommandLauncherJob
*job
= new KIO::CommandLauncherJob(command
, this);
1088 job
->setDesktopName(QStringLiteral("org.kde.kompare"));
1092 void DolphinMainWindow::toggleShowMenuBar()
1094 const bool visible
= menuBar()->isVisible();
1095 menuBar()->setVisible(!visible
);
1098 QPointer
<QAction
> DolphinMainWindow::preferredSearchTool()
1100 m_searchTools
.clear();
1101 KMoreToolsMenuFactory("dolphin/search-tools").fillMenuFromGroupingNames(
1102 &m_searchTools
, { "files-find" }, m_activeViewContainer
->url()
1104 QList
<QAction
*> actions
= m_searchTools
.actions();
1105 if (actions
.isEmpty()) {
1108 QAction
* action
= actions
.first();
1109 if (action
->isSeparator()) {
1115 void DolphinMainWindow::updateOpenPreferredSearchToolAction()
1117 QAction
* openPreferredSearchTool
= actionCollection()->action(QStringLiteral("open_preferred_search_tool"));
1118 if (!openPreferredSearchTool
) {
1121 QPointer
<QAction
> tool
= preferredSearchTool();
1123 openPreferredSearchTool
->setVisible(true);
1124 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open %1", tool
->text()));
1125 // Only override with the app icon if it is the default, i.e. the user hasn't configured one manually
1126 // https://bugs.kde.org/show_bug.cgi?id=442815
1127 if (openPreferredSearchTool
->icon().name() == QLatin1String("search")) {
1128 openPreferredSearchTool
->setIcon(tool
->icon());
1131 openPreferredSearchTool
->setVisible(false);
1132 // still visible in Shortcuts configuration window
1133 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool"));
1134 openPreferredSearchTool
->setIcon(QIcon::fromTheme(QStringLiteral("search")));
1138 void DolphinMainWindow::openPreferredSearchTool()
1140 QPointer
<QAction
> tool
= preferredSearchTool();
1146 void DolphinMainWindow::openTerminal()
1148 openTerminalJob(m_activeViewContainer
->url());
1151 void DolphinMainWindow::openTerminalHere()
1153 QList
<QUrl
> urls
= {};
1155 for (const KFileItem
& item
: m_activeViewContainer
->view()->selectedItems()) {
1156 QUrl url
= item
.targetUrl();
1157 if (item
.isFile()) {
1158 url
.setPath(QFileInfo(url
.path()).absolutePath());
1160 if (!urls
.contains(url
)) {
1165 // No items are selected. Open a terminal window for the current location.
1166 if (urls
.count() == 0) {
1171 if (urls
.count() > 5) {
1172 QString question
= i18np("Are you sure you want to open 1 terminal window?",
1173 "Are you sure you want to open %1 terminal windows?", urls
.count());
1174 const int answer
= KMessageBox::warningYesNo(this, question
, {},
1175 KGuiItem(i18ncp("@action:button", "Open %1 Terminal", "Open %1 Terminals", urls
.count()),
1176 QStringLiteral("utilities-terminal")),
1177 KStandardGuiItem::cancel());
1178 if (answer
!= KMessageBox::Yes
) {
1183 for (const QUrl
& url
: urls
) {
1184 openTerminalJob(url
);
1188 void DolphinMainWindow::openTerminalJob(const QUrl
& url
)
1190 if (url
.isLocalFile()) {
1191 auto job
= new KTerminalLauncherJob(QString());
1192 job
->setWorkingDirectory(url
.toLocalFile());
1197 // Not a local file, with protocol Class ":local", try stat'ing
1198 if (KProtocolInfo::protocolClass(url
.scheme()) == QLatin1String(":local")) {
1199 KIO::StatJob
*job
= KIO::mostLocalUrl(url
);
1200 KJobWidgets::setWindow(job
, this);
1201 connect(job
, &KJob::result
, this, [job
]() {
1203 if (!job
->error()) {
1204 statUrl
= job
->mostLocalUrl();
1207 auto job
= new KTerminalLauncherJob(QString());
1208 job
->setWorkingDirectory(statUrl
.isLocalFile() ? statUrl
.toLocalFile() : QDir::homePath());
1215 // Nothing worked, just use $HOME
1216 auto job
= new KTerminalLauncherJob(QString());
1217 job
->setWorkingDirectory(QDir::homePath());
1221 void DolphinMainWindow::editSettings()
1223 if (!m_settingsDialog
) {
1224 DolphinViewContainer
* container
= activeViewContainer();
1225 container
->view()->writeSettings();
1227 const QUrl url
= container
->url();
1228 DolphinSettingsDialog
* settingsDialog
= new DolphinSettingsDialog(url
, this, actionCollection());
1229 connect(settingsDialog
, &DolphinSettingsDialog::settingsChanged
, this, &DolphinMainWindow::refreshViews
);
1230 connect(settingsDialog
, &DolphinSettingsDialog::settingsChanged
,
1231 &DolphinUrlNavigatorsController::slotReadSettings
);
1232 settingsDialog
->setAttribute(Qt::WA_DeleteOnClose
);
1233 settingsDialog
->show();
1234 m_settingsDialog
= settingsDialog
;
1236 m_settingsDialog
.data()->raise();
1240 void DolphinMainWindow::handleUrl(const QUrl
& url
)
1242 delete m_lastHandleUrlOpenJob
;
1243 m_lastHandleUrlOpenJob
= nullptr;
1245 if (url
.isLocalFile() && QFileInfo(url
.toLocalFile()).isDir()) {
1246 activeViewContainer()->setUrl(url
);
1248 m_lastHandleUrlOpenJob
= new KIO::OpenUrlJob(url
);
1249 m_lastHandleUrlOpenJob
->setUiDelegate(new KIO::JobUiDelegate(KJobUiDelegate::AutoHandlingEnabled
, this));
1250 m_lastHandleUrlOpenJob
->setShowOpenOrExecuteDialog(true);
1252 connect(m_lastHandleUrlOpenJob
, &KIO::OpenUrlJob::mimeTypeFound
, this,
1253 [this, url
](const QString
&mimetype
) {
1254 if (mimetype
== QLatin1String("inode/directory")) {
1255 // If it's a dir, we'll take it from here
1256 m_lastHandleUrlOpenJob
->kill();
1257 m_lastHandleUrlOpenJob
= nullptr;
1258 activeViewContainer()->setUrl(url
);
1262 connect(m_lastHandleUrlOpenJob
, &KIO::OpenUrlJob::result
, this, [this]() {
1263 m_lastHandleUrlOpenJob
= nullptr;
1266 m_lastHandleUrlOpenJob
->start();
1270 void DolphinMainWindow::slotWriteStateChanged(bool isFolderWritable
)
1272 // trash:/ is writable but we don't want to create new items in it.
1273 // TODO: remove the trash check once https://phabricator.kde.org/T8234 is implemented
1274 newFileMenu()->setEnabled(isFolderWritable
&& m_activeViewContainer
->url().scheme() != QLatin1String("trash"));
1277 void DolphinMainWindow::openContextMenu(const QPoint
& pos
,
1278 const KFileItem
& item
,
1279 const KFileItemList
&selectedItems
,
1282 QPointer
<DolphinContextMenu
> contextMenu
= new DolphinContextMenu(this, item
, selectedItems
, url
, &m_fileItemActions
);
1283 contextMenu
.data()->exec(pos
);
1285 // Delete the menu, unless it has been deleted in its own nested event loop already.
1287 contextMenu
->deleteLater();
1291 QMenu
*DolphinMainWindow::createPopupMenu()
1293 QMenu
*menu
= KXmlGuiWindow::createPopupMenu();
1295 menu
->addSeparator();
1296 menu
->addAction(actionCollection()->action(QStringLiteral("lock_panels")));
1301 void DolphinMainWindow::updateHamburgerMenu()
1303 KActionCollection
* ac
= actionCollection();
1304 auto hamburgerMenu
= static_cast<KHamburgerMenu
*>(
1305 ac
->action(KStandardAction::name(KStandardAction::HamburgerMenu
)));
1306 auto menu
= hamburgerMenu
->menu();
1308 menu
= new QMenu(this);
1309 hamburgerMenu
->setMenu(menu
);
1310 hamburgerMenu
->hideActionsOf(ac
->action(QStringLiteral("basic_actions"))->menu());
1311 hamburgerMenu
->hideActionsOf(ac
->action(QStringLiteral("zoom"))->menu());
1315 const QList
<QAction
*> toolbarActions
= toolBar()->actions();
1317 if (!toolBar()->isVisible()) {
1318 // If neither the menu bar nor the toolbar are visible, these actions should be available.
1319 menu
->addAction(ac
->action(KStandardAction::name(KStandardAction::ShowMenubar
)));
1320 menu
->addAction(toolBarMenuAction());
1321 menu
->addSeparator();
1324 // This group of actions (until the next separator) contains all the most basic actions
1325 // necessary to use Dolphin effectively.
1326 menu
->addAction(ac
->action(QStringLiteral("go_back")));
1327 menu
->addAction(ac
->action(QStringLiteral("go_forward")));
1329 menu
->addMenu(m_newFileMenu
->menu());
1330 if (!toolBar()->isVisible()
1331 || !toolbarActions
.contains(ac
->action(QStringLiteral("toggle_selection_mode_tool_bar")))
1333 menu
->addAction(ac
->action(QStringLiteral("toggle_selection_mode")));
1335 menu
->addAction(ac
->action(QStringLiteral("basic_actions")));
1336 menu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Undo
)));
1337 if (!toolBar()->isVisible()
1338 || (!toolbarActions
.contains(ac
->action(QStringLiteral("toggle_search")))
1339 && !toolbarActions
.contains(ac
->action(QStringLiteral("open_preferred_search_tool"))))
1341 menu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Find
)));
1342 // This way a search action will only be added if none of the three available
1343 // search actions is present on the toolbar.
1345 if (!toolBar()->isVisible()
1346 || !toolbarActions
.contains(ac
->action(QStringLiteral("toggle_filter")))
1348 menu
->addAction(ac
->action(QStringLiteral("show_filter_bar")));
1349 // This way a filter action will only be added if none of the two available
1350 // filter actions is present on the toolbar.
1352 menu
->addSeparator();
1354 // The second group of actions (up until the next separator) contains actions for opening
1355 // additional views to interact with the file system.
1356 menu
->addAction(ac
->action(QStringLiteral("file_new")));
1357 menu
->addAction(ac
->action(QStringLiteral("new_tab")));
1358 if (ac
->action(QStringLiteral("undo_close_tab"))->isEnabled()) {
1359 menu
->addAction(ac
->action(QStringLiteral("closed_tabs")));
1361 menu
->addAction(ac
->action(QStringLiteral("open_terminal")));
1362 menu
->addSeparator();
1364 // The third group contains actions to change what one sees in the view
1365 // and to change the more general UI.
1366 if (!toolBar()->isVisible()
1367 || (!toolbarActions
.contains(ac
->action(QStringLiteral("icons")))
1368 && !toolbarActions
.contains(ac
->action(QStringLiteral("compact")))
1369 && !toolbarActions
.contains(ac
->action(QStringLiteral("details")))
1370 && !toolbarActions
.contains(ac
->action(QStringLiteral("view_mode"))))
1372 menu
->addAction(ac
->action(QStringLiteral("view_mode")));
1374 menu
->addAction(ac
->action(QStringLiteral("show_hidden_files")));
1375 menu
->addAction(ac
->action(QStringLiteral("sort")));
1376 menu
->addAction(ac
->action(QStringLiteral("additional_info")));
1377 if (!GeneralSettings::showStatusBar() || !GeneralSettings::showZoomSlider()) {
1378 menu
->addAction(ac
->action(QStringLiteral("zoom")));
1380 menu
->addAction(ac
->action(QStringLiteral("panels")));
1382 // The "Configure" menu is not added to the actionCollection() because there is hardly
1383 // a good reason for users to put it on their toolbar.
1384 auto configureMenu
= menu
->addMenu(QIcon::fromTheme(QStringLiteral("configure")),
1385 i18nc("@action:inmenu menu for configure actions", "Configure"));
1386 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::SwitchApplicationLanguage
)));
1387 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::KeyBindings
)));
1388 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::ConfigureToolbars
)));
1389 configureMenu
->addAction(ac
->action(KStandardAction::name(KStandardAction::Preferences
)));
1390 hamburgerMenu
->hideActionsOf(configureMenu
);
1393 void DolphinMainWindow::slotPlaceActivated(const QUrl
& url
)
1395 DolphinViewContainer
* view
= activeViewContainer();
1397 if (view
->url() == url
) {
1398 // We can end up here if the user clicked a device in the Places Panel
1399 // which had been unmounted earlier, see https://bugs.kde.org/show_bug.cgi?id=161385.
1402 view
->disableUrlNavigatorSelectionRequests();
1404 view
->enableUrlNavigatorSelectionRequests();
1408 void DolphinMainWindow::closedTabsCountChanged(unsigned int count
)
1410 actionCollection()->action(QStringLiteral("undo_close_tab"))->setEnabled(count
> 0);
1413 void DolphinMainWindow::activeViewChanged(DolphinViewContainer
* viewContainer
)
1415 DolphinViewContainer
* oldViewContainer
= m_activeViewContainer
;
1416 Q_ASSERT(viewContainer
);
1418 m_activeViewContainer
= viewContainer
;
1420 if (oldViewContainer
) {
1421 const QAction
* toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
1422 toggleSearchAction
->disconnect(oldViewContainer
);
1424 // Disconnect all signals between the old view container (container,
1425 // view and url navigator) and main window.
1426 oldViewContainer
->disconnect(this);
1427 oldViewContainer
->view()->disconnect(this);
1428 oldViewContainer
->urlNavigatorInternalWithHistory()->disconnect(this);
1429 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>
1430 (actionCollection()->action(QStringLiteral("url_navigators")));
1431 navigators
->primaryUrlNavigator()->disconnect(this);
1432 if (auto secondaryUrlNavigator
= navigators
->secondaryUrlNavigator()) {
1433 secondaryUrlNavigator
->disconnect(this);
1436 // except the requestItemInfo so that on hover the information panel can still be updated
1437 connect(oldViewContainer
->view(), &DolphinView::requestItemInfo
,
1438 this, &DolphinMainWindow::requestItemInfo
);
1441 connectViewSignals(viewContainer
);
1443 m_actionHandler
->setCurrentView(viewContainer
->view());
1446 updateFileAndEditActions();
1447 updatePasteAction();
1448 updateViewActions();
1450 updateSearchAction();
1452 const QUrl url
= viewContainer
->url();
1453 Q_EMIT
urlChanged(url
);
1456 void DolphinMainWindow::tabCountChanged(int count
)
1458 const bool enableTabActions
= (count
> 1);
1459 for (int i
= 0; i
< MaxActivateTabShortcuts
; ++i
) {
1460 actionCollection()->action(QStringLiteral("activate_tab_%1").arg(i
))->setEnabled(enableTabActions
);
1462 actionCollection()->action(QStringLiteral("activate_last_tab"))->setEnabled(enableTabActions
);
1463 actionCollection()->action(QStringLiteral("activate_next_tab"))->setEnabled(enableTabActions
);
1464 actionCollection()->action(QStringLiteral("activate_prev_tab"))->setEnabled(enableTabActions
);
1467 void DolphinMainWindow::updateWindowTitle()
1469 const QString newTitle
= m_activeViewContainer
->captionWindowTitle();
1470 if (windowTitle() != newTitle
) {
1471 setWindowTitle(newTitle
);
1475 void DolphinMainWindow::slotStorageTearDownFromPlacesRequested(const QString
& mountPath
)
1477 connect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, this, [this, mountPath
]() {
1478 setViewsToHomeIfMountPathOpen(mountPath
);
1481 if (m_terminalPanel
&& m_terminalPanel
->currentWorkingDirectory().startsWith(mountPath
)) {
1482 m_tearDownFromPlacesRequested
= true;
1483 m_terminalPanel
->goHome();
1484 // m_placesPanel->proceedWithTearDown() will be called in slotTerminalDirectoryChanged
1486 m_placesPanel
->proceedWithTearDown();
1490 void DolphinMainWindow::slotStorageTearDownExternallyRequested(const QString
& mountPath
)
1492 connect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, this, [this, mountPath
]() {
1493 setViewsToHomeIfMountPathOpen(mountPath
);
1496 if (m_terminalPanel
&& m_terminalPanel
->currentWorkingDirectory().startsWith(mountPath
)) {
1497 m_tearDownFromPlacesRequested
= false;
1498 m_terminalPanel
->goHome();
1502 void DolphinMainWindow::slotKeyBindings()
1504 KShortcutsDialog
dialog(KShortcutsEditor::AllActions
, KShortcutsEditor::LetterShortcutsAllowed
, this);
1505 dialog
.addCollection(actionCollection());
1506 if (m_terminalPanel
) {
1507 KActionCollection
*konsolePartActionCollection
= m_terminalPanel
->actionCollection();
1508 if (konsolePartActionCollection
) {
1509 dialog
.addCollection(konsolePartActionCollection
, QStringLiteral("KonsolePart"));
1515 void DolphinMainWindow::setViewsToHomeIfMountPathOpen(const QString
& mountPath
)
1517 const QVector
<DolphinViewContainer
*> theViewContainers
= viewContainers();
1518 for (DolphinViewContainer
*viewContainer
: theViewContainers
) {
1519 if (viewContainer
&& viewContainer
->url().toLocalFile().startsWith(mountPath
)) {
1520 viewContainer
->setUrl(QUrl::fromLocalFile(QDir::homePath()));
1523 disconnect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, nullptr, nullptr);
1526 void DolphinMainWindow::setupActions()
1528 KStandardAction::hamburgerMenu(nullptr, nullptr, actionCollection());
1530 // setup 'File' menu
1531 m_newFileMenu
= new DolphinNewFileMenu(actionCollection(), this);
1532 QMenu
* menu
= m_newFileMenu
->menu();
1533 menu
->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1534 menu
->setIcon(QIcon::fromTheme(QStringLiteral("list-add")));
1535 m_newFileMenu
->setPopupMode(QToolButton::InstantPopup
);
1536 connect(menu
, &QMenu::aboutToShow
,
1537 this, &DolphinMainWindow::updateNewMenu
);
1539 QAction
* newWindow
= KStandardAction::openNew(this, &DolphinMainWindow::openNewMainWindow
, actionCollection());
1540 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
1541 newWindow
->setToolTip(i18nc("@info", "Open a new Dolphin window"));
1542 newWindow
->setWhatsThis(xi18nc("@info:whatsthis", "This opens a new "
1543 "window just like this one with the current location and view."
1544 "<nl/>You can drag and drop items between windows."));
1545 newWindow
->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
1547 QAction
* newTab
= actionCollection()->addAction(QStringLiteral("new_tab"));
1548 newTab
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1549 newTab
->setText(i18nc("@action:inmenu File", "New Tab"));
1550 newTab
->setWhatsThis(xi18nc("@info:whatsthis", "This opens a new "
1551 "<emphasis>Tab</emphasis> with the current location and view.<nl/>"
1552 "A tab is an additional view within this window. "
1553 "You can drag and drop items between tabs."));
1554 actionCollection()->setDefaultShortcuts(newTab
, {Qt::CTRL
| Qt::Key_T
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_N
});
1555 connect(newTab
, &QAction::triggered
, this, &DolphinMainWindow::openNewActivatedTab
);
1557 QAction
* addToPlaces
= actionCollection()->addAction(QStringLiteral("add_to_places"));
1558 addToPlaces
->setIcon(QIcon::fromTheme(QStringLiteral("bookmark-new")));
1559 addToPlaces
->setText(i18nc("@action:inmenu Add current folder to places", "Add to Places"));
1560 addToPlaces
->setWhatsThis(xi18nc("@info:whatsthis", "This adds the selected folder "
1561 "to the Places panel."));
1562 connect(addToPlaces
, &QAction::triggered
, this, &DolphinMainWindow::addToPlaces
);
1564 QAction
* closeTab
= KStandardAction::close(m_tabWidget
, QOverload
<>::of(&DolphinTabWidget::closeTab
), actionCollection());
1565 closeTab
->setText(i18nc("@action:inmenu File", "Close Tab"));
1566 closeTab
->setWhatsThis(i18nc("@info:whatsthis", "This closes the "
1567 "currently viewed tab. If no more tabs are left this window "
1568 "will close instead."));
1570 QAction
* quitAction
= KStandardAction::quit(this, &DolphinMainWindow::quit
, actionCollection());
1571 quitAction
->setWhatsThis(i18nc("@info:whatsthis quit", "This closes this window."));
1573 // setup 'Edit' menu
1574 KStandardAction::undo(this,
1575 &DolphinMainWindow::undo
,
1576 actionCollection());
1578 // i18n: This will be the last paragraph for the whatsthis for all three:
1579 // Cut, Copy and Paste
1580 const QString cutCopyPastePara
= xi18nc("@info:whatsthis", "<para><emphasis>Cut, "
1581 "Copy</emphasis> and <emphasis>Paste</emphasis> work between many "
1582 "applications and are among the most used commands. That's why their "
1583 "<emphasis>keyboard shortcuts</emphasis> are prominently placed right "
1584 "next to each other on the keyboard: <shortcut>Ctrl+X</shortcut>, "
1585 "<shortcut>Ctrl+C</shortcut> and <shortcut>Ctrl+V</shortcut>.</para>");
1586 QAction
* cutAction
= KStandardAction::cut(this, &DolphinMainWindow::cut
, actionCollection());
1587 cutAction
->setWhatsThis(xi18nc("@info:whatsthis cut", "This copies the items "
1588 "in your current selection to the <emphasis>clipboard</emphasis>.<nl/>"
1589 "Use the <emphasis>Paste</emphasis> action afterwards to copy them from "
1590 "the clipboard to a new location. The items will be removed from their "
1591 "initial location.") + cutCopyPastePara
);
1592 QAction
* copyAction
= KStandardAction::copy(this, &DolphinMainWindow::copy
, actionCollection());
1593 copyAction
->setWhatsThis(xi18nc("@info:whatsthis copy", "This copies the "
1594 "items in your current selection to the <emphasis>clipboard</emphasis>."
1595 "<nl/>Use the <emphasis>Paste</emphasis> action afterwards to copy them "
1596 "from the clipboard to a new location.") + cutCopyPastePara
);
1597 QAction
* paste
= KStandardAction::paste(this, &DolphinMainWindow::paste
, actionCollection());
1598 // The text of the paste-action is modified dynamically by Dolphin
1599 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1600 // due to the long text, the text "Paste" is used:
1601 paste
->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1602 paste
->setWhatsThis(xi18nc("@info:whatsthis paste", "This copies the items from "
1603 "your <emphasis>clipboard</emphasis> to the currently viewed folder.<nl/>"
1604 "If the items were added to the clipboard by the <emphasis>Cut</emphasis> "
1605 "action they are removed from their old location.") + cutCopyPastePara
);
1607 QAction
* copyToOtherViewAction
= actionCollection()->addAction(QStringLiteral("copy_to_inactive_split_view"));
1608 copyToOtherViewAction
->setText(i18nc("@action:inmenu", "Copy to Inactive Split View"));
1609 copyToOtherViewAction
->setWhatsThis(xi18nc("@info:whatsthis Copy", "This copies the selected items from "
1610 "the <emphasis>active</emphasis> view to the inactive split view."));
1611 copyToOtherViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("edit-copy")));
1612 copyToOtherViewAction
->setIconText(i18nc("@action:inmenu Edit", "Copy to Inactive Split View"));
1613 actionCollection()->setDefaultShortcut(copyToOtherViewAction
, Qt::SHIFT
| Qt::Key_F5
);
1614 connect(copyToOtherViewAction
, &QAction::triggered
, this, &DolphinMainWindow::copyToInactiveSplitView
);
1616 QAction
* moveToOtherViewAction
= actionCollection()->addAction(QStringLiteral("move_to_inactive_split_view"));
1617 moveToOtherViewAction
->setText(i18nc("@action:inmenu", "Move to Inactive Split View"));
1618 moveToOtherViewAction
->setWhatsThis(xi18nc("@info:whatsthis Move", "This moves the selected items from "
1619 "the <emphasis>active</emphasis> view to the inactive split view."));
1620 moveToOtherViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("edit-cut")));
1621 moveToOtherViewAction
->setIconText(i18nc("@action:inmenu Edit", "Move to Inactive Split View"));
1622 actionCollection()->setDefaultShortcut(moveToOtherViewAction
, Qt::SHIFT
| Qt::Key_F6
);
1623 connect(moveToOtherViewAction
, &QAction::triggered
, this, &DolphinMainWindow::moveToInactiveSplitView
);
1625 QAction
* showFilterBar
= actionCollection()->addAction(QStringLiteral("show_filter_bar"));
1626 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Filter..."));
1627 showFilterBar
->setToolTip(i18nc("@info:tooltip", "Show Filter Bar"));
1628 showFilterBar
->setWhatsThis(xi18nc("@info:whatsthis", "This opens the "
1629 "<emphasis>Filter Bar</emphasis> at the bottom of the window.<nl/> "
1630 "There you can enter a text to filter the files and folders currently displayed. "
1631 "Only those that contain the text in their name will be kept in view."));
1632 showFilterBar
->setIcon(QIcon::fromTheme(QStringLiteral("view-filter")));
1633 actionCollection()->setDefaultShortcuts(showFilterBar
, {Qt::CTRL
| Qt::Key_I
, Qt::Key_Slash
});
1634 connect(showFilterBar
, &QAction::triggered
, this, &DolphinMainWindow::showFilterBar
);
1636 // toggle_filter acts as a copy of the main showFilterBar to be used mainly
1637 // in the toolbar, with no default shortcut attached, to avoid messing with
1638 // existing workflows (filter bar always open and Ctrl-I to focus)
1639 QAction
*toggleFilter
= actionCollection()->addAction(QStringLiteral("toggle_filter"));
1640 toggleFilter
->setText(i18nc("@action:inmenu", "Toggle Filter Bar"));
1641 toggleFilter
->setIconText(i18nc("@action:intoolbar", "Filter"));
1642 toggleFilter
->setIcon(showFilterBar
->icon());
1643 toggleFilter
->setToolTip(showFilterBar
->toolTip());
1644 toggleFilter
->setWhatsThis(showFilterBar
->whatsThis());
1645 toggleFilter
->setCheckable(true);
1646 connect(toggleFilter
, &QAction::triggered
, this, &DolphinMainWindow::toggleFilterBar
);
1648 QAction
*searchAction
= KStandardAction::find(this, &DolphinMainWindow::find
, actionCollection());
1649 searchAction
->setText(i18n("Search..."));
1650 searchAction
->setToolTip(i18nc("@info:tooltip", "Search for files and folders"));
1651 searchAction
->setWhatsThis(xi18nc("@info:whatsthis find", "<para>This helps you "
1652 "find files and folders by opening a <emphasis>find bar</emphasis>. "
1653 "There you can enter search terms and specify settings to find the "
1654 "objects you are looking for.</para><para>Use this help again on "
1655 "the find bar so we can have a look at it while the settings are "
1656 "explained.</para>"));
1658 // toggle_search acts as a copy of the main searchAction to be used mainly
1659 // in the toolbar, with no default shortcut attached, to avoid messing with
1660 // existing workflows (search bar always open and Ctrl-F to focus)
1661 QAction
*toggleSearchAction
= actionCollection()->addAction(QStringLiteral("toggle_search"));
1662 toggleSearchAction
->setText(i18nc("@action:inmenu", "Toggle Search Bar"));
1663 toggleSearchAction
->setIconText(i18nc("@action:intoolbar", "Search"));
1664 toggleSearchAction
->setIcon(searchAction
->icon());
1665 toggleSearchAction
->setToolTip(searchAction
->toolTip());
1666 toggleSearchAction
->setWhatsThis(searchAction
->whatsThis());
1667 toggleSearchAction
->setCheckable(true);
1669 QAction
*toggleSelectionModeAction
= actionCollection()->addAction(QStringLiteral("toggle_selection_mode"));
1670 // i18n: This action toggles a selection mode.
1671 toggleSelectionModeAction
->setText(i18nc("@action:inmenu", "Select Files and Folders"));
1672 // i18n: Opens a selection mode for selecting files/folders and later selecting an action that acts on them.
1673 // So in a way "Select" here is used to mean both "Select files" and also "Select what to do" but mostly the first.
1674 // The text is kept so unspecific because it will be shown on the toolbar where space is at a premium.
1675 toggleSelectionModeAction
->setIconText(i18nc("@action:intoolbar", "Select"));
1676 toggleSelectionModeAction
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This application only knows which files or folders should be acted on if they are"
1677 " <emphasis>selected</emphasis> first. Press this to toggle a <emphasis>Selection Mode</emphasis> which makes selecting and deselecting as easy as "
1678 "pressing an item once.</para><para>While in this mode, a quick access bar at the bottom shows available actions for the currently selected items."
1680 toggleSelectionModeAction
->setIcon(QIcon::fromTheme(QStringLiteral("quickwizard")));
1681 toggleSelectionModeAction
->setCheckable(true);
1682 actionCollection()->setDefaultShortcut(toggleSelectionModeAction
, Qt::Key_Space
);
1683 connect(toggleSelectionModeAction
, &QAction::triggered
, this, &DolphinMainWindow::toggleSelectionMode
);
1685 // A special version of the toggleSelectionModeAction for the toolbar that also contains a menu
1686 // with the selectAllAction and invertSelectionAction.
1687 auto *toggleSelectionModeToolBarAction
= new KToolBarPopupAction(toggleSelectionModeAction
->icon(), toggleSelectionModeAction
->iconText(), actionCollection());
1688 toggleSelectionModeToolBarAction
->setToolTip(toggleSelectionModeAction
->text());
1689 toggleSelectionModeToolBarAction
->setWhatsThis(toggleSelectionModeAction
->whatsThis());
1690 actionCollection()->addAction(QStringLiteral("toggle_selection_mode_tool_bar"), toggleSelectionModeToolBarAction
);
1691 toggleSelectionModeToolBarAction
->setCheckable(true);
1692 toggleSelectionModeToolBarAction
->setPopupMode(QToolButton::DelayedPopup
);
1693 connect(toggleSelectionModeToolBarAction
, &QAction::triggered
, toggleSelectionModeAction
, &QAction::trigger
);
1694 connect(toggleSelectionModeAction
, &QAction::toggled
, toggleSelectionModeToolBarAction
, &QAction::setChecked
);
1696 QAction
* selectAllAction
= KStandardAction::selectAll(this, &DolphinMainWindow::selectAll
, actionCollection());
1697 selectAllAction
->setWhatsThis(xi18nc("@info:whatsthis", "This selects all "
1698 "files and folders in the current location."));
1700 QAction
* invertSelection
= actionCollection()->addAction(QStringLiteral("invert_selection"));
1701 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1702 invertSelection
->setWhatsThis(xi18nc("@info:whatsthis invert", "This selects all "
1703 "objects that you have currently <emphasis>not</emphasis> selected instead."));
1704 invertSelection
->setIcon(QIcon::fromTheme(QStringLiteral("edit-select-invert")));
1705 actionCollection()->setDefaultShortcut(invertSelection
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_A
);
1706 connect(invertSelection
, &QAction::triggered
, this, &DolphinMainWindow::invertSelection
);
1708 QMenu
*toggleSelectionModeActionMenu
= new QMenu(this);
1709 toggleSelectionModeActionMenu
->addAction(selectAllAction
);
1710 toggleSelectionModeActionMenu
->addAction(invertSelection
);
1711 toggleSelectionModeToolBarAction
->setMenu(toggleSelectionModeActionMenu
);
1713 // setup 'View' menu
1714 // (note that most of it is set up in DolphinViewActionHandler)
1716 QAction
* split
= actionCollection()->addAction(QStringLiteral("split_view"));
1717 split
->setWhatsThis(xi18nc("@info:whatsthis find", "<para>This splits "
1718 "the folder view below into two autonomous views.</para><para>This "
1719 "way you can see two locations at once and move items between them "
1720 "quickly.</para>Click this again afterwards to recombine the views."));
1721 actionCollection()->setDefaultShortcut(split
, Qt::Key_F3
);
1722 connect(split
, &QAction::triggered
, this, &DolphinMainWindow::toggleSplitView
);
1724 QAction
* stashSplit
= actionCollection()->addAction(QStringLiteral("split_stash"));
1725 actionCollection()->setDefaultShortcut(stashSplit
, Qt::CTRL
| Qt::Key_S
);
1726 stashSplit
->setText(i18nc("@action:intoolbar Stash", "Stash"));
1727 stashSplit
->setToolTip(i18nc("@info", "Opens the stash virtual directory in a split window"));
1728 stashSplit
->setIcon(QIcon::fromTheme(QStringLiteral("folder-stash")));
1729 stashSplit
->setCheckable(false);
1730 QDBusConnectionInterface
*sessionInterface
= QDBusConnection::sessionBus().interface();
1731 stashSplit
->setVisible(sessionInterface
&& sessionInterface
->isServiceRegistered(QStringLiteral("org.kde.kio.StashNotifier")));
1732 connect(stashSplit
, &QAction::triggered
, this, &DolphinMainWindow::toggleSplitStash
);
1734 KStandardAction::redisplay(this, &DolphinMainWindow::reloadView
, actionCollection());
1736 QAction
* stop
= actionCollection()->addAction(QStringLiteral("stop"));
1737 stop
->setText(i18nc("@action:inmenu View", "Stop"));
1738 stop
->setToolTip(i18nc("@info", "Stop loading"));
1739 stop
->setWhatsThis(i18nc("@info", "This stops the loading of the contents of the current folder."));
1740 stop
->setIcon(QIcon::fromTheme(QStringLiteral("process-stop")));
1741 connect(stop
, &QAction::triggered
, this, &DolphinMainWindow::stopLoading
);
1743 KToggleAction
* editableLocation
= actionCollection()->add
<KToggleAction
>(QStringLiteral("editable_location"));
1744 editableLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1745 editableLocation
->setWhatsThis(xi18nc("@info:whatsthis",
1746 "This toggles the <emphasis>Location Bar</emphasis> to be "
1747 "editable so you can directly enter a location you want to go to.<nl/>"
1748 "You can also switch to editing by clicking to the right of the "
1749 "location and switch back by confirming the edited location."));
1750 actionCollection()->setDefaultShortcut(editableLocation
, Qt::Key_F6
);
1751 connect(editableLocation
, &KToggleAction::triggered
, this, &DolphinMainWindow::toggleEditLocation
);
1753 QAction
* replaceLocation
= actionCollection()->addAction(QStringLiteral("replace_location"));
1754 replaceLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1755 // i18n: "enter" is used both in the meaning of "writing" and "going to" a new location here.
1756 // Both meanings are useful but not necessary to understand the use of "Replace Location".
1757 // So you might want to be more verbose in your language to convey the meaning but it's up to you.
1758 replaceLocation
->setWhatsThis(xi18nc("@info:whatsthis",
1759 "This switches to editing the location and selects it "
1760 "so you can quickly enter a different location."));
1761 actionCollection()->setDefaultShortcut(replaceLocation
, Qt::CTRL
| Qt::Key_L
);
1762 connect(replaceLocation
, &QAction::triggered
, this, &DolphinMainWindow::replaceLocation
);
1766 QScopedPointer
<QAction
> backAction(KStandardAction::back(nullptr, nullptr, nullptr));
1767 m_backAction
= new KToolBarPopupAction(backAction
->icon(), backAction
->text(), actionCollection());
1768 m_backAction
->setObjectName(backAction
->objectName());
1769 m_backAction
->setShortcuts(backAction
->shortcuts());
1771 m_backAction
->setPopupMode(QToolButton::DelayedPopup
);
1772 connect(m_backAction
, &QAction::triggered
, this, &DolphinMainWindow::goBack
);
1773 connect(m_backAction
->menu(), &QMenu::aboutToShow
, this, &DolphinMainWindow::slotAboutToShowBackPopupMenu
);
1774 connect(m_backAction
->menu(), &QMenu::triggered
, this, &DolphinMainWindow::slotGoBack
);
1775 actionCollection()->addAction(m_backAction
->objectName(), m_backAction
);
1777 auto backShortcuts
= m_backAction
->shortcuts();
1778 backShortcuts
.append(QKeySequence(Qt::Key_Backspace
));
1779 actionCollection()->setDefaultShortcuts(m_backAction
, backShortcuts
);
1781 DolphinRecentTabsMenu
* recentTabsMenu
= new DolphinRecentTabsMenu(this);
1782 actionCollection()->addAction(QStringLiteral("closed_tabs"), recentTabsMenu
);
1783 connect(m_tabWidget
, &DolphinTabWidget::rememberClosedTab
,
1784 recentTabsMenu
, &DolphinRecentTabsMenu::rememberClosedTab
);
1785 connect(recentTabsMenu
, &DolphinRecentTabsMenu::restoreClosedTab
,
1786 m_tabWidget
, &DolphinTabWidget::restoreClosedTab
);
1787 connect(recentTabsMenu
, &DolphinRecentTabsMenu::closedTabsCountChanged
,
1788 this, &DolphinMainWindow::closedTabsCountChanged
);
1790 QAction
* undoCloseTab
= actionCollection()->addAction(QStringLiteral("undo_close_tab"));
1791 undoCloseTab
->setText(i18nc("@action:inmenu File", "Undo close tab"));
1792 undoCloseTab
->setWhatsThis(i18nc("@info:whatsthis undo close tab",
1793 "This returns you to the previously closed tab."));
1794 actionCollection()->setDefaultShortcut(undoCloseTab
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_T
);
1795 undoCloseTab
->setIcon(QIcon::fromTheme(QStringLiteral("edit-undo")));
1796 undoCloseTab
->setEnabled(false);
1797 connect(undoCloseTab
, &QAction::triggered
, recentTabsMenu
, &DolphinRecentTabsMenu::undoCloseTab
);
1799 auto undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
1800 undoAction
->setWhatsThis(xi18nc("@info:whatsthis", "This undoes "
1801 "the last change you made to files or folders.<nl/>"
1802 "Such changes include <interface>creating, renaming</interface> "
1803 "and <interface>moving</interface> them to a different location "
1804 "or to the <filename>Trash</filename>. <nl/>Changes that can't "
1805 "be undone will ask for your confirmation."));
1806 undoAction
->setEnabled(false); // undo should be disabled by default
1809 QScopedPointer
<QAction
> forwardAction(KStandardAction::forward(nullptr, nullptr, nullptr));
1810 m_forwardAction
= new KToolBarPopupAction(forwardAction
->icon(), forwardAction
->text(), actionCollection());
1811 m_forwardAction
->setObjectName(forwardAction
->objectName());
1812 m_forwardAction
->setShortcuts(forwardAction
->shortcuts());
1814 m_forwardAction
->setPopupMode(QToolButton::DelayedPopup
);
1815 connect(m_forwardAction
, &QAction::triggered
, this, &DolphinMainWindow::goForward
);
1816 connect(m_forwardAction
->menu(), &QMenu::aboutToShow
, this, &DolphinMainWindow::slotAboutToShowForwardPopupMenu
);
1817 connect(m_forwardAction
->menu(), &QMenu::triggered
, this, &DolphinMainWindow::slotGoForward
);
1818 actionCollection()->addAction(m_forwardAction
->objectName(), m_forwardAction
);
1819 actionCollection()->setDefaultShortcuts(m_forwardAction
, m_forwardAction
->shortcuts());
1821 // enable middle-click to open in a new tab
1822 auto *middleClickEventFilter
= new MiddleClickActionEventFilter(this);
1823 connect(middleClickEventFilter
, &MiddleClickActionEventFilter::actionMiddleClicked
, this, &DolphinMainWindow::slotBackForwardActionMiddleClicked
);
1824 m_backAction
->menu()->installEventFilter(middleClickEventFilter
);
1825 m_forwardAction
->menu()->installEventFilter(middleClickEventFilter
);
1826 KStandardAction::up(this, &DolphinMainWindow::goUp
, actionCollection());
1827 QAction
* homeAction
= KStandardAction::home(this, &DolphinMainWindow::goHome
, actionCollection());
1828 homeAction
->setWhatsThis(xi18nc("@info:whatsthis", "Go to your "
1829 "<filename>Home</filename> folder.<nl/>Every user account "
1830 "has their own <filename>Home</filename> that contains their data "
1831 "including folders that contain personal application data."));
1833 // setup 'Tools' menu
1834 QAction
* compareFiles
= actionCollection()->addAction(QStringLiteral("compare_files"));
1835 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1836 compareFiles
->setIcon(QIcon::fromTheme(QStringLiteral("kompare")));
1837 compareFiles
->setEnabled(false);
1838 connect(compareFiles
, &QAction::triggered
, this, &DolphinMainWindow::compareFiles
);
1840 QAction
* openPreferredSearchTool
= actionCollection()->addAction(QStringLiteral("open_preferred_search_tool"));
1841 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool"));
1842 openPreferredSearchTool
->setWhatsThis(xi18nc("@info:whatsthis",
1843 "<para>This opens a preferred search tool for the viewed location.</para>"
1844 "<para>Use <emphasis>More Search Tools</emphasis> menu to configure it.</para>"));
1845 openPreferredSearchTool
->setIcon(QIcon::fromTheme(QStringLiteral("search")));
1846 actionCollection()->setDefaultShortcut(openPreferredSearchTool
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_F
);
1847 connect(openPreferredSearchTool
, &QAction::triggered
, this, &DolphinMainWindow::openPreferredSearchTool
);
1849 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
1850 QAction
* openTerminal
= actionCollection()->addAction(QStringLiteral("open_terminal"));
1851 openTerminal
->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
1852 openTerminal
->setWhatsThis(xi18nc("@info:whatsthis",
1853 "<para>This opens a <emphasis>terminal</emphasis> application for the viewed location.</para>"
1854 "<para>To learn more about terminals use the help in the terminal application.</para>"));
1855 openTerminal
->setIcon(QIcon::fromTheme(QStringLiteral("utilities-terminal")));
1856 actionCollection()->setDefaultShortcut(openTerminal
, Qt::SHIFT
| Qt::Key_F4
);
1857 connect(openTerminal
, &QAction::triggered
, this, &DolphinMainWindow::openTerminal
);
1859 QAction
* openTerminalHere
= actionCollection()->addAction(QStringLiteral("open_terminal_here"));
1860 // i18n: "Here" refers to the location(s) of the currently selected item(s) or the currently viewed location if nothing is selected.
1861 openTerminalHere
->setText(i18nc("@action:inmenu Tools", "Open Terminal Here"));
1862 openTerminalHere
->setWhatsThis(xi18nc("@info:whatsthis",
1863 "<para>This opens <emphasis>terminal</emphasis> applications for the selected items' locations.</para>"
1864 "<para>To learn more about terminals use the help in the terminal application.</para>"));
1865 openTerminalHere
->setIcon(QIcon::fromTheme(QStringLiteral("utilities-terminal")));
1866 actionCollection()->setDefaultShortcut(openTerminalHere
, Qt::SHIFT
| Qt::ALT
| Qt::Key_F4
);
1867 connect(openTerminalHere
, &QAction::triggered
, this, &DolphinMainWindow::openTerminalHere
);
1870 QAction
* focusTerminalPanel
= actionCollection()->addAction(QStringLiteral("focus_terminal_panel"));
1871 focusTerminalPanel
->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
1872 focusTerminalPanel
->setIcon(QIcon::fromTheme(QStringLiteral("swap-panels")));
1873 actionCollection()->setDefaultShortcut(focusTerminalPanel
, Qt::CTRL
| Qt::SHIFT
| Qt::Key_F4
);
1874 connect(focusTerminalPanel
, &QAction::triggered
, this, &DolphinMainWindow::focusTerminalPanel
);
1878 // setup 'Bookmarks' menu
1879 KActionMenu
*bookmarkMenu
= new KActionMenu(i18nc("@title:menu", "&Bookmarks"), this);
1880 bookmarkMenu
->setIcon(QIcon::fromTheme(QStringLiteral("bookmarks")));
1881 // Make the toolbar button version work properly on click
1882 bookmarkMenu
->setPopupMode(QToolButton::InstantPopup
);
1883 m_bookmarkHandler
= new DolphinBookmarkHandler(this, actionCollection(), bookmarkMenu
->menu(), this);
1884 actionCollection()->addAction(QStringLiteral("bookmarks"), bookmarkMenu
);
1886 // setup 'Settings' menu
1887 KToggleAction
* showMenuBar
= KStandardAction::showMenubar(nullptr, nullptr, actionCollection());
1888 showMenuBar
->setWhatsThis(xi18nc("@info:whatsthis",
1889 "This switches between having a <emphasis>Menubar</emphasis> "
1890 "and having a <interface>Control</interface> button. Both "
1891 "contain mostly the same commands and configuration options."));
1892 connect(showMenuBar
, &KToggleAction::triggered
, // Fixes #286822
1893 this, &DolphinMainWindow::toggleShowMenuBar
, Qt::QueuedConnection
);
1895 KToggleAction
* showStatusBar
= KStandardAction::showStatusbar(nullptr, nullptr, actionCollection());
1896 showStatusBar
->setChecked(GeneralSettings::showStatusBar());
1897 connect(GeneralSettings::self(), &GeneralSettings::showStatusBarChanged
, showStatusBar
, &KToggleAction::setChecked
);
1898 connect(showStatusBar
, &KToggleAction::triggered
, this, [this](bool checked
) {
1899 GeneralSettings::setShowStatusBar(checked
);
1903 KStandardAction::keyBindings(this, &DolphinMainWindow::slotKeyBindings
, actionCollection());
1904 KStandardAction::preferences(this, &DolphinMainWindow::editSettings
, actionCollection());
1906 // setup 'Help' menu for the m_controlButton. The other one is set up in the base class.
1907 m_helpMenu
= new KHelpMenu(nullptr);
1908 m_helpMenu
->menu()->installEventFilter(this);
1909 // remove duplicate shortcuts
1910 auto removeHelpActionShortcut
= [this](KHelpMenu::MenuId menuId
) {
1911 if (auto *action
= m_helpMenu
->action(menuId
)) {
1912 action
->setShortcut(QKeySequence());
1915 removeHelpActionShortcut(KHelpMenu::menuHelpContents
);
1916 removeHelpActionShortcut(KHelpMenu::menuWhatsThis
);
1918 // not in menu actions
1919 QList
<QKeySequence
> nextTabKeys
= KStandardShortcut::tabNext();
1920 nextTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::Key_Tab
));
1922 QList
<QKeySequence
> prevTabKeys
= KStandardShortcut::tabPrev();
1923 prevTabKeys
.append(QKeySequence(Qt::CTRL
| Qt::SHIFT
| Qt::Key_Tab
));
1925 for (int i
= 0; i
< MaxActivateTabShortcuts
; ++i
) {
1926 QAction
* activateTab
= actionCollection()->addAction(QStringLiteral("activate_tab_%1").arg(i
));
1927 activateTab
->setText(i18nc("@action:inmenu", "Activate Tab %1", i
+ 1));
1928 activateTab
->setEnabled(false);
1929 connect(activateTab
, &QAction::triggered
, this, [this, i
]() { m_tabWidget
->activateTab(i
); });
1931 // only add default shortcuts for the first 9 tabs regardless of MaxActivateTabShortcuts
1933 actionCollection()->setDefaultShortcut(activateTab
, QStringLiteral("Alt+%1").arg(i
+ 1));
1937 QAction
* activateLastTab
= actionCollection()->addAction(QStringLiteral("activate_last_tab"));
1938 activateLastTab
->setText(i18nc("@action:inmenu", "Activate Last Tab"));
1939 activateLastTab
->setEnabled(false);
1940 connect(activateLastTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activateLastTab
);
1941 actionCollection()->setDefaultShortcut(activateLastTab
, Qt::ALT
| Qt::Key_0
);
1943 QAction
* activateNextTab
= actionCollection()->addAction(QStringLiteral("activate_next_tab"));
1944 activateNextTab
->setIconText(i18nc("@action:inmenu", "Next Tab"));
1945 activateNextTab
->setText(i18nc("@action:inmenu", "Activate Next Tab"));
1946 activateNextTab
->setEnabled(false);
1947 connect(activateNextTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activateNextTab
);
1948 actionCollection()->setDefaultShortcuts(activateNextTab
, nextTabKeys
);
1950 QAction
* activatePrevTab
= actionCollection()->addAction(QStringLiteral("activate_prev_tab"));
1951 activatePrevTab
->setIconText(i18nc("@action:inmenu", "Previous Tab"));
1952 activatePrevTab
->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
1953 activatePrevTab
->setEnabled(false);
1954 connect(activatePrevTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activatePrevTab
);
1955 actionCollection()->setDefaultShortcuts(activatePrevTab
, prevTabKeys
);
1958 QAction
* showTarget
= actionCollection()->addAction(QStringLiteral("show_target"));
1959 showTarget
->setText(i18nc("@action:inmenu", "Show Target"));
1960 showTarget
->setIcon(QIcon::fromTheme(QStringLiteral("document-open-folder")));
1961 showTarget
->setEnabled(false);
1962 connect(showTarget
, &QAction::triggered
, this, &DolphinMainWindow::showTarget
);
1964 QAction
* openInNewTab
= actionCollection()->addAction(QStringLiteral("open_in_new_tab"));
1965 openInNewTab
->setText(i18nc("@action:inmenu", "Open in New Tab"));
1966 openInNewTab
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1967 connect(openInNewTab
, &QAction::triggered
, this, &DolphinMainWindow::openInNewTab
);
1969 QAction
* openInNewTabs
= actionCollection()->addAction(QStringLiteral("open_in_new_tabs"));
1970 openInNewTabs
->setText(i18nc("@action:inmenu", "Open in New Tabs"));
1971 openInNewTabs
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1972 connect(openInNewTabs
, &QAction::triggered
, this, &DolphinMainWindow::openInNewTab
);
1974 QAction
* openInNewWindow
= actionCollection()->addAction(QStringLiteral("open_in_new_window"));
1975 openInNewWindow
->setText(i18nc("@action:inmenu", "Open in New Window"));
1976 openInNewWindow
->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
1977 connect(openInNewWindow
, &QAction::triggered
, this, &DolphinMainWindow::openInNewWindow
);
1980 void DolphinMainWindow::setupDockWidgets()
1982 const bool lock
= GeneralSettings::lockPanels();
1984 DolphinPlacesModelSingleton::instance().placesModel()->setPanelsLocked(lock
);
1986 KDualAction
* lockLayoutAction
= actionCollection()->add
<KDualAction
>(QStringLiteral("lock_panels"));
1987 lockLayoutAction
->setActiveText(i18nc("@action:inmenu Panels", "Unlock Panels"));
1988 lockLayoutAction
->setActiveIcon(QIcon::fromTheme(QStringLiteral("object-unlocked")));
1989 lockLayoutAction
->setInactiveText(i18nc("@action:inmenu Panels", "Lock Panels"));
1990 lockLayoutAction
->setInactiveIcon(QIcon::fromTheme(QStringLiteral("object-locked")));
1991 lockLayoutAction
->setWhatsThis(xi18nc("@info:whatsthis", "This "
1992 "switches between having panels <emphasis>locked</emphasis> or "
1993 "<emphasis>unlocked</emphasis>.<nl/>Unlocked panels can be "
1994 "dragged to the other side of the window and have a close "
1995 "button.<nl/>Locked panels are embedded more cleanly."));
1996 lockLayoutAction
->setActive(lock
);
1997 connect(lockLayoutAction
, &KDualAction::triggered
, this, &DolphinMainWindow::togglePanelLockState
);
1999 // Setup "Information"
2000 DolphinDockWidget
* infoDock
= new DolphinDockWidget(i18nc("@title:window", "Information"));
2001 infoDock
->setLocked(lock
);
2002 infoDock
->setObjectName(QStringLiteral("infoDock"));
2003 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
2006 InformationPanel
* infoPanel
= new InformationPanel(infoDock
);
2007 infoPanel
->setCustomContextMenuActions({lockLayoutAction
});
2008 connect(infoPanel
, &InformationPanel::urlActivated
, this, &DolphinMainWindow::handleUrl
);
2009 infoDock
->setWidget(infoPanel
);
2011 QAction
* infoAction
= infoDock
->toggleViewAction();
2012 createPanelAction(QIcon::fromTheme(QStringLiteral("dialog-information")), Qt::Key_F11
, infoAction
, QStringLiteral("show_information_panel"));
2014 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
2015 connect(this, &DolphinMainWindow::urlChanged
,
2016 infoPanel
, &InformationPanel::setUrl
);
2017 connect(this, &DolphinMainWindow::selectionChanged
,
2018 infoPanel
, &InformationPanel::setSelection
);
2019 connect(this, &DolphinMainWindow::requestItemInfo
,
2020 infoPanel
, &InformationPanel::requestDelayedItemInfo
);
2021 connect(this, &DolphinMainWindow::fileItemsChanged
,
2022 infoPanel
, &InformationPanel::slotFilesItemChanged
);
2025 // i18n: This is the last paragraph for the "What's This"-texts of all four panels.
2026 const QString panelWhatsThis
= xi18nc("@info:whatsthis", "<para>To show or "
2027 "hide panels like this go to <interface>Control|Panels</interface> "
2028 "or <interface>View|Panels</interface>.</para>");
2030 actionCollection()->action(QStringLiteral("show_information_panel"))
2031 ->setWhatsThis(xi18nc("@info:whatsthis", "<para> This toggles the "
2032 "<emphasis>information</emphasis> panel at the right side of the "
2033 "window.</para><para>The panel provides in-depth information "
2034 "about the items your mouse is hovering over or about the selected "
2035 "items. Otherwise it informs you about the currently viewed folder.<nl/>"
2036 "For single items a preview of their contents is provided.</para>"));
2038 infoDock
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This panel "
2039 "provides in-depth information about the items your mouse is "
2040 "hovering over or about the selected items. Otherwise it informs "
2041 "you about the currently viewed folder.<nl/>For single items a "
2042 "preview of their contents is provided.</para><para>You can configure "
2043 "which and how details are given here by right-clicking.</para>") + panelWhatsThis
);
2046 DolphinDockWidget
* foldersDock
= new DolphinDockWidget(i18nc("@title:window", "Folders"));
2047 foldersDock
->setLocked(lock
);
2048 foldersDock
->setObjectName(QStringLiteral("foldersDock"));
2049 foldersDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
2050 FoldersPanel
* foldersPanel
= new FoldersPanel(foldersDock
);
2051 foldersPanel
->setCustomContextMenuActions({lockLayoutAction
});
2052 foldersDock
->setWidget(foldersPanel
);
2054 QAction
* foldersAction
= foldersDock
->toggleViewAction();
2055 createPanelAction(QIcon::fromTheme(QStringLiteral("folder")), Qt::Key_F7
, foldersAction
, QStringLiteral("show_folders_panel"));
2057 addDockWidget(Qt::LeftDockWidgetArea
, foldersDock
);
2058 connect(this, &DolphinMainWindow::urlChanged
,
2059 foldersPanel
, &FoldersPanel::setUrl
);
2060 connect(foldersPanel
, &FoldersPanel::folderActivated
,
2061 this, &DolphinMainWindow::changeUrl
);
2062 connect(foldersPanel
, &FoldersPanel::folderInNewTab
,
2063 this, &DolphinMainWindow::openNewTab
);
2064 connect(foldersPanel
, &FoldersPanel::folderInNewActiveTab
,
2065 this, &DolphinMainWindow::openNewTabAndActivate
);
2066 connect(foldersPanel
, &FoldersPanel::errorMessage
,
2067 this, &DolphinMainWindow::showErrorMessage
);
2069 actionCollection()->action(QStringLiteral("show_folders_panel"))
2070 ->setWhatsThis(xi18nc("@info:whatsthis", "This toggles the "
2071 "<emphasis>folders</emphasis> panel at the left side of the window."
2072 "<nl/><nl/>It shows the folders of the <emphasis>file system"
2073 "</emphasis> in a <emphasis>tree view</emphasis>."));
2074 foldersDock
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This panel "
2075 "shows the folders of the <emphasis>file system</emphasis> in a "
2076 "<emphasis>tree view</emphasis>.</para><para>Click a folder to go "
2077 "there. Click the arrow to the left of a folder to see its subfolders. "
2078 "This allows quick switching between any folders.</para>") + panelWhatsThis
);
2082 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
2083 DolphinDockWidget
* terminalDock
= new DolphinDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
2084 terminalDock
->setLocked(lock
);
2085 terminalDock
->setObjectName(QStringLiteral("terminalDock"));
2086 m_terminalPanel
= new TerminalPanel(terminalDock
);
2087 m_terminalPanel
->setCustomContextMenuActions({lockLayoutAction
});
2088 terminalDock
->setWidget(m_terminalPanel
);
2090 connect(m_terminalPanel
, &TerminalPanel::hideTerminalPanel
, terminalDock
, &DolphinDockWidget::hide
);
2091 connect(m_terminalPanel
, &TerminalPanel::changeUrl
, this, &DolphinMainWindow::slotTerminalDirectoryChanged
);
2092 connect(terminalDock
, &DolphinDockWidget::visibilityChanged
,
2093 m_terminalPanel
, &TerminalPanel::dockVisibilityChanged
);
2094 connect(terminalDock
, &DolphinDockWidget::visibilityChanged
,
2095 this, &DolphinMainWindow::slotTerminalPanelVisibilityChanged
);
2097 QAction
* terminalAction
= terminalDock
->toggleViewAction();
2098 createPanelAction(QIcon::fromTheme(QStringLiteral("dialog-scripts")), Qt::Key_F4
, terminalAction
, QStringLiteral("show_terminal_panel"));
2100 addDockWidget(Qt::BottomDockWidgetArea
, terminalDock
);
2101 connect(this, &DolphinMainWindow::urlChanged
,
2102 m_terminalPanel
, &TerminalPanel::setUrl
);
2104 if (GeneralSettings::version() < 200) {
2105 terminalDock
->hide();
2108 actionCollection()->action(QStringLiteral("show_terminal_panel"))
2109 ->setWhatsThis(xi18nc("@info:whatsthis", "<para>This toggles the "
2110 "<emphasis>terminal</emphasis> panel at the bottom of the window."
2111 "<nl/>The location in the terminal will always match the folder "
2112 "view so you can navigate using either.</para><para>The terminal "
2113 "panel is not needed for basic computer usage but can be useful "
2114 "for advanced tasks. To learn more about terminals use the help "
2115 "in a standalone terminal application like Konsole.</para>"));
2116 terminalDock
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is "
2117 "the <emphasis>terminal</emphasis> panel. It behaves like a "
2118 "normal terminal but will match the location of the folder view "
2119 "so you can navigate using either.</para><para>The terminal panel "
2120 "is not needed for basic computer usage but can be useful for "
2121 "advanced tasks. To learn more about terminals use the help in a "
2122 "standalone terminal application like Konsole.</para>") + panelWhatsThis
);
2126 if (GeneralSettings::version() < 200) {
2128 foldersDock
->hide();
2132 DolphinDockWidget
* placesDock
= new DolphinDockWidget(i18nc("@title:window", "Places"));
2133 placesDock
->setLocked(lock
);
2134 placesDock
->setObjectName(QStringLiteral("placesDock"));
2135 placesDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
2137 m_placesPanel
= new PlacesPanel(placesDock
);
2138 m_placesPanel
->setCustomContextMenuActions({lockLayoutAction
});
2139 placesDock
->setWidget(m_placesPanel
);
2141 QAction
*placesAction
= placesDock
->toggleViewAction();
2142 createPanelAction(QIcon::fromTheme(QStringLiteral("compass")), Qt::Key_F9
, placesAction
, QStringLiteral("show_places_panel"));
2144 addDockWidget(Qt::LeftDockWidgetArea
, placesDock
);
2145 connect(m_placesPanel
, &PlacesPanel::placeActivated
,
2146 this, &DolphinMainWindow::slotPlaceActivated
);
2147 connect(m_placesPanel
, &PlacesPanel::tabRequested
,
2148 this, &DolphinMainWindow::openNewTab
);
2149 connect(m_placesPanel
, &PlacesPanel::activeTabRequested
,
2150 this, &DolphinMainWindow::openNewTabAndActivate
);
2151 connect(m_placesPanel
, &PlacesPanel::newWindowRequested
, this, [this](const QUrl
&url
) {
2152 Dolphin::openNewWindow({url
}, this);
2154 connect(m_placesPanel
, &PlacesPanel::errorMessage
,
2155 this, &DolphinMainWindow::showErrorMessage
);
2156 connect(this, &DolphinMainWindow::urlChanged
,
2157 m_placesPanel
, &PlacesPanel::setUrl
);
2158 connect(placesDock
, &DolphinDockWidget::visibilityChanged
,
2159 &DolphinUrlNavigatorsController::slotPlacesPanelVisibilityChanged
);
2160 connect(this, &DolphinMainWindow::settingsChanged
,
2161 m_placesPanel
, &PlacesPanel::readSettings
);
2162 connect(m_placesPanel
, &PlacesPanel::storageTearDownRequested
,
2163 this, &DolphinMainWindow::slotStorageTearDownFromPlacesRequested
);
2164 connect(m_placesPanel
, &PlacesPanel::storageTearDownExternallyRequested
,
2165 this, &DolphinMainWindow::slotStorageTearDownExternallyRequested
);
2166 DolphinUrlNavigatorsController::slotPlacesPanelVisibilityChanged(m_placesPanel
->isVisible());
2168 auto actionShowAllPlaces
= new QAction(QIcon::fromTheme(QStringLiteral("view-hidden")), i18nc("@item:inmenu", "Show Hidden Places"), this);
2169 actionShowAllPlaces
->setCheckable(true);
2170 actionShowAllPlaces
->setDisabled(true);
2171 actionShowAllPlaces
->setWhatsThis(i18nc("@info:whatsthis", "This displays "
2172 "all places in the places panel that have been hidden. They will "
2173 "appear semi-transparent unless you uncheck their hide property."));
2175 connect(actionShowAllPlaces
, &QAction::triggered
, this, [actionShowAllPlaces
, this](bool checked
){
2176 m_placesPanel
->setShowAll(checked
);
2178 connect(m_placesPanel
, &PlacesPanel::allPlacesShownChanged
, actionShowAllPlaces
, &QAction::setChecked
);
2180 actionCollection()->action(QStringLiteral("show_places_panel"))
2181 ->setWhatsThis(xi18nc("@info:whatsthis", "<para>This toggles the "
2182 "<emphasis>places</emphasis> panel at the left side of the window."
2183 "</para><para>It allows you to go to locations you have "
2184 "bookmarked and to access disk or media attached to the computer "
2185 "or to the network. It also contains sections to find recently "
2186 "saved files or files of a certain type.</para>"));
2187 placesDock
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2188 "<emphasis>Places</emphasis> panel. It allows you to go to locations "
2189 "you have bookmarked and to access disk or media attached to the "
2190 "computer or to the network. It also contains sections to find "
2191 "recently saved files or files of a certain type.</para><para>"
2192 "Click on an entry to go there. Click with the right mouse button "
2193 "instead to open any entry in a new tab or new window.</para>"
2194 "<para>New entries can be added by dragging folders onto this panel. "
2195 "Right-click any section or entry to hide it. Right-click an empty "
2196 "space on this panel and select <interface>Show Hidden Places"
2197 "</interface> to display it again.</para>") + panelWhatsThis
);
2199 // Add actions into the "Panels" menu
2200 KActionMenu
* panelsMenu
= new KActionMenu(i18nc("@action:inmenu View", "Show Panels"), this);
2201 actionCollection()->addAction(QStringLiteral("panels"), panelsMenu
);
2202 panelsMenu
->setIcon(QIcon::fromTheme(QStringLiteral("view-sidetree")));
2203 panelsMenu
->setPopupMode(QToolButton::InstantPopup
);
2204 const KActionCollection
* ac
= actionCollection();
2205 panelsMenu
->addAction(ac
->action(QStringLiteral("show_places_panel")));
2207 panelsMenu
->addAction(ac
->action(QStringLiteral("show_information_panel")));
2209 panelsMenu
->addAction(ac
->action(QStringLiteral("show_folders_panel")));
2210 panelsMenu
->addAction(ac
->action(QStringLiteral("show_terminal_panel")));
2211 panelsMenu
->addSeparator();
2212 panelsMenu
->addAction(actionShowAllPlaces
);
2213 panelsMenu
->addAction(lockLayoutAction
);
2215 connect(panelsMenu
->menu(), &QMenu::aboutToShow
, this, [actionShowAllPlaces
, this]{
2216 actionShowAllPlaces
->setEnabled(DolphinPlacesModelSingleton::instance().placesModel()->hiddenCount());
2221 void DolphinMainWindow::updateFileAndEditActions()
2223 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
2224 const KActionCollection
* col
= actionCollection();
2225 KFileItemListProperties
capabilitiesSource(list
);
2227 QAction
* renameAction
= col
->action(KStandardAction::name(KStandardAction::RenameFile
));
2228 QAction
* moveToTrashAction
= col
->action(KStandardAction::name(KStandardAction::MoveToTrash
));
2229 QAction
* deleteAction
= col
->action(KStandardAction::name(KStandardAction::DeleteFile
));
2230 QAction
* cutAction
= col
->action(KStandardAction::name(KStandardAction::Cut
));
2231 QAction
* duplicateAction
= col
->action(QStringLiteral("duplicate")); // see DolphinViewActionHandler
2232 QAction
* addToPlacesAction
= col
->action(QStringLiteral("add_to_places"));
2233 QAction
* copyToOtherViewAction
= col
->action(QStringLiteral("copy_to_inactive_split_view"));
2234 QAction
* moveToOtherViewAction
= col
->action(QStringLiteral("move_to_inactive_split_view"));
2235 QAction
* copyLocation
= col
->action(QString("copy_location"));
2237 if (list
.isEmpty()) {
2238 stateChanged(QStringLiteral("has_no_selection"));
2240 // All actions that need a selection to function can be enabled because they should trigger selection mode.
2241 renameAction
->setEnabled(true);
2242 moveToTrashAction
->setEnabled(true);
2243 deleteAction
->setEnabled(true);
2244 cutAction
->setEnabled(true);
2245 duplicateAction
->setEnabled(true);
2246 addToPlacesAction
->setEnabled(true);
2247 copyLocation
->setEnabled(true);
2249 stateChanged(QStringLiteral("has_selection"));
2251 QAction
* deleteWithTrashShortcut
= col
->action(QStringLiteral("delete_shortcut")); // see DolphinViewActionHandler
2252 QAction
* showTarget
= col
->action(QStringLiteral("show_target"));
2254 if (list
.length() == 1 && list
.first().isDir()) {
2255 addToPlacesAction
->setEnabled(true);
2257 addToPlacesAction
->setEnabled(false);
2260 const bool enableMoveToTrash
= capabilitiesSource
.isLocal() && capabilitiesSource
.supportsMoving();
2262 renameAction
->setEnabled(capabilitiesSource
.supportsMoving());
2263 moveToTrashAction
->setEnabled(enableMoveToTrash
);
2264 deleteAction
->setEnabled(capabilitiesSource
.supportsDeleting());
2265 deleteWithTrashShortcut
->setEnabled(capabilitiesSource
.supportsDeleting() && !enableMoveToTrash
);
2266 cutAction
->setEnabled(capabilitiesSource
.supportsMoving());
2267 copyLocation
->setEnabled(list
.length() == 1);
2268 showTarget
->setEnabled(list
.length() == 1 && list
.at(0).isLink());
2269 duplicateAction
->setEnabled(capabilitiesSource
.supportsWriting());
2272 if (m_tabWidget
->currentTabPage()->splitViewEnabled()) {
2273 DolphinTabPage
* tabPage
= m_tabWidget
->currentTabPage();
2274 KFileItem capabilitiesDestination
;
2276 if (tabPage
->primaryViewActive()) {
2277 capabilitiesDestination
= tabPage
->secondaryViewContainer()->url();
2279 capabilitiesDestination
= tabPage
->primaryViewContainer()->url();
2282 copyToOtherViewAction
->setEnabled(capabilitiesDestination
.isWritable());
2283 moveToOtherViewAction
->setEnabled((list
.isEmpty() || capabilitiesSource
.supportsMoving()) && capabilitiesDestination
.isWritable());
2285 copyToOtherViewAction
->setEnabled(false);
2286 moveToOtherViewAction
->setEnabled(false);
2290 void DolphinMainWindow::updateViewActions()
2292 m_actionHandler
->updateViewActions();
2294 QAction
*toggleSelectionModeAction
= actionCollection()->action(QStringLiteral("toggle_selection_mode"));
2295 disconnect(nullptr, &DolphinViewContainer::selectionModeChanged
,
2296 toggleSelectionModeAction
, &QAction::setChecked
);
2297 toggleSelectionModeAction
->setChecked(m_activeViewContainer
->isSelectionModeEnabled());
2298 connect(m_activeViewContainer
, &DolphinViewContainer::selectionModeChanged
,
2299 toggleSelectionModeAction
, &QAction::setChecked
);
2301 QAction
* toggleFilterBarAction
= actionCollection()->action(QStringLiteral("toggle_filter"));
2302 toggleFilterBarAction
->setChecked(m_activeViewContainer
->isFilterBarVisible());
2304 updateSplitAction();
2307 void DolphinMainWindow::updateGoActions()
2309 QAction
* goUpAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Up
));
2310 const QUrl currentUrl
= m_activeViewContainer
->url();
2311 // I think this is one of the best places to firstly be confronted
2312 // with a file system and its hierarchy. Talking about the root
2313 // directory might seem too much here but it is the question that
2314 // naturally arises in this context.
2315 goUpAction
->setWhatsThis(xi18nc("@info:whatsthis", "<para>Go to "
2316 "the folder that contains the currently viewed one.</para>"
2317 "<para>All files and folders are organized in a hierarchical "
2318 "<emphasis>file system</emphasis>. At the top of this hierarchy is "
2319 "a directory that contains all data connected to this computer"
2320 "—the <emphasis>root directory</emphasis>.</para>"));
2321 goUpAction
->setEnabled(KIO::upUrl(currentUrl
) != currentUrl
);
2324 void DolphinMainWindow::refreshViews()
2326 m_tabWidget
->refreshViews();
2328 if (GeneralSettings::modifiedStartupSettings()) {
2329 updateWindowTitle();
2332 Q_EMIT
settingsChanged();
2335 void DolphinMainWindow::clearStatusBar()
2337 m_activeViewContainer
->statusBar()->resetToDefaultText();
2340 void DolphinMainWindow::connectViewSignals(DolphinViewContainer
* container
)
2342 connect(container
, &DolphinViewContainer::showFilterBarChanged
,
2343 this, &DolphinMainWindow::updateFilterBarAction
);
2344 connect(container
, &DolphinViewContainer::writeStateChanged
,
2345 this, &DolphinMainWindow::slotWriteStateChanged
);
2346 connect(container
, &DolphinViewContainer::searchModeEnabledChanged
,
2347 this, &DolphinMainWindow::updateSearchAction
);
2348 connect(container
, &DolphinViewContainer::captionChanged
,
2349 this, &DolphinMainWindow::updateWindowTitle
);
2350 connect(container
, &DolphinViewContainer::tabRequested
,
2351 this, &DolphinMainWindow::openNewTab
);
2352 connect(container
, &DolphinViewContainer::activeTabRequested
,
2353 this, &DolphinMainWindow::openNewTabAndActivate
);
2355 const QAction
* toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
2356 connect(toggleSearchAction
, &QAction::triggered
, container
, &DolphinViewContainer::setSearchModeEnabled
);
2358 const DolphinView
* view
= container
->view();
2359 connect(view
, &DolphinView::selectionChanged
,
2360 this, &DolphinMainWindow::slotSelectionChanged
);
2361 connect(view
, &DolphinView::requestItemInfo
,
2362 this, &DolphinMainWindow::requestItemInfo
);
2363 connect(view
, &DolphinView::fileItemsChanged
,
2364 this, &DolphinMainWindow::fileItemsChanged
);
2365 connect(view
, &DolphinView::tabRequested
,
2366 this, &DolphinMainWindow::openNewTab
);
2367 connect(view
, &DolphinView::activeTabRequested
,
2368 this, &DolphinMainWindow::openNewTabAndActivate
);
2369 connect(view
, &DolphinView::windowRequested
,
2370 this, &DolphinMainWindow::openNewWindow
);
2371 connect(view
, &DolphinView::requestContextMenu
,
2372 this, &DolphinMainWindow::openContextMenu
);
2373 connect(view
, &DolphinView::directoryLoadingStarted
,
2374 this, &DolphinMainWindow::enableStopAction
);
2375 connect(view
, &DolphinView::directoryLoadingCompleted
,
2376 this, &DolphinMainWindow::disableStopAction
);
2377 connect(view
, &DolphinView::directoryLoadingCompleted
,
2378 this, &DolphinMainWindow::slotDirectoryLoadingCompleted
);
2379 connect(view
, &DolphinView::goBackRequested
,
2380 this, &DolphinMainWindow::goBack
);
2381 connect(view
, &DolphinView::goForwardRequested
,
2382 this, &DolphinMainWindow::goForward
);
2383 connect(view
, &DolphinView::urlActivated
,
2384 this, &DolphinMainWindow::handleUrl
);
2385 connect(view
, &DolphinView::goUpRequested
,
2386 this, &DolphinMainWindow::goUp
);
2388 connect(container
->urlNavigatorInternalWithHistory(), &KUrlNavigator::urlChanged
,
2389 this, &DolphinMainWindow::changeUrl
);
2390 connect(container
->urlNavigatorInternalWithHistory(), &KUrlNavigator::historyChanged
,
2391 this, &DolphinMainWindow::updateHistory
);
2393 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>
2394 (actionCollection()->action(QStringLiteral("url_navigators")));
2395 const KUrlNavigator
*navigator
= m_tabWidget
->currentTabPage()->primaryViewActive() ?
2396 navigators
->primaryUrlNavigator() :
2397 navigators
->secondaryUrlNavigator();
2399 QAction
*editableLocactionAction
= actionCollection()->action(QStringLiteral("editable_location"));
2400 editableLocactionAction
->setChecked(navigator
->isUrlEditable());
2401 connect(navigator
, &KUrlNavigator::editableStateChanged
,
2402 this, &DolphinMainWindow::slotEditableStateChanged
);
2403 connect(navigator
, &KUrlNavigator::tabRequested
,
2404 this, &DolphinMainWindow::openNewTab
);
2405 connect(navigator
, &KUrlNavigator::activeTabRequested
,
2406 this, &DolphinMainWindow::openNewTabAndActivate
);
2407 connect(navigator
, &KUrlNavigator::newWindowRequested
,
2408 this, &DolphinMainWindow::openNewWindow
);
2412 void DolphinMainWindow::updateSplitAction()
2414 QAction
* splitAction
= actionCollection()->action(QStringLiteral("split_view"));
2415 const DolphinTabPage
* tabPage
= m_tabWidget
->currentTabPage();
2416 if (tabPage
->splitViewEnabled()) {
2417 if (GeneralSettings::closeActiveSplitView() ? tabPage
->primaryViewActive() : !tabPage
->primaryViewActive()) {
2418 splitAction
->setText(i18nc("@action:intoolbar Close left view", "Close"));
2419 splitAction
->setToolTip(i18nc("@info", "Close left view"));
2420 splitAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-left-close")));
2422 splitAction
->setText(i18nc("@action:intoolbar Close right view", "Close"));
2423 splitAction
->setToolTip(i18nc("@info", "Close right view"));
2424 splitAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-right-close")));
2427 splitAction
->setText(i18nc("@action:intoolbar Split view", "Split"));
2428 splitAction
->setToolTip(i18nc("@info", "Split view"));
2429 splitAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-right-new")));
2433 void DolphinMainWindow::updateAllowedToolbarAreas()
2435 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>
2436 (actionCollection()->action(QStringLiteral("url_navigators")));
2437 if (toolBar()->actions().contains(navigators
)) {
2438 toolBar()->setAllowedAreas(Qt::TopToolBarArea
| Qt::BottomToolBarArea
);
2439 if (toolBarArea(toolBar()) == Qt::LeftToolBarArea
||
2440 toolBarArea(toolBar()) == Qt::RightToolBarArea
) {
2441 addToolBar(Qt::TopToolBarArea
, toolBar());
2444 toolBar()->setAllowedAreas(Qt::AllToolBarAreas
);
2448 bool DolphinMainWindow::isKompareInstalled() const
2450 static bool initialized
= false;
2451 static bool installed
= false;
2453 // TODO: maybe replace this approach later by using a menu
2454 // plugin like kdiff3plugin.cpp
2455 installed
= !QStandardPaths::findExecutable(QStringLiteral("kompare")).isEmpty();
2461 void DolphinMainWindow::createPanelAction(const QIcon
& icon
,
2462 const QKeySequence
& shortcut
,
2463 QAction
* dockAction
,
2464 const QString
& actionName
)
2466 QAction
* panelAction
= actionCollection()->addAction(actionName
);
2467 panelAction
->setCheckable(true);
2468 panelAction
->setChecked(dockAction
->isChecked());
2469 panelAction
->setText(dockAction
->text());
2470 panelAction
->setIcon(icon
);
2471 dockAction
->setIcon(icon
);
2472 actionCollection()->setDefaultShortcut(panelAction
, shortcut
);
2474 connect(panelAction
, &QAction::triggered
, dockAction
, &QAction::trigger
);
2475 connect(dockAction
, &QAction::toggled
, panelAction
, &QAction::setChecked
);
2478 void DolphinMainWindow::setupWhatsThis()
2481 menuBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2482 "<emphasis>Menubar</emphasis>. It provides access to commands and "
2483 "configuration options. Left-click on any of the menus on this "
2484 "bar to see its contents.</para><para>The Menubar can be hidden "
2485 "by unchecking <interface>Settings|Show Menubar</interface>. Then "
2486 "most of its contents become available through a <interface>Control"
2487 "</interface> button on the <emphasis>Toolbar</emphasis>.</para>"));
2488 toolBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2489 "<emphasis>Toolbar</emphasis>. It allows quick access to "
2490 "frequently used actions.</para><para>It is highly customizable. "
2491 "All items you see in the <interface>Control</interface> menu or "
2492 "in the <interface>Menubar</interface> can be placed on the "
2493 "Toolbar. Just right-click on it and select <interface>Configure "
2494 "Toolbars…</interface> or find this action in the <interface>"
2495 "Control</interface> or <interface>Settings</interface> menu."
2496 "</para><para>The location of the bar and the style of its "
2497 "buttons can also be changed in the right-click menu. Right-click "
2498 "a button if you want to show or hide its text.</para>"));
2499 m_tabWidget
->setWhatsThis(xi18nc("@info:whatsthis main view",
2500 "<para>Here you can see the <emphasis>folders</emphasis> and "
2501 "<emphasis>files</emphasis> that are at the location described in "
2502 "the <interface>Location Bar</interface> above. This area is the "
2503 "central part of this application where you navigate to the files "
2504 "you want to use.</para><para>For an elaborate and general "
2505 "introduction to this application <link "
2506 "url='https://userbase.kde.org/Dolphin/File_Management#Introduction_to_Dolphin'>"
2507 "click here</link>. This will open an introductory article from "
2508 "the <emphasis>KDE UserBase Wiki</emphasis>.</para><para>For brief "
2509 "explanations of all the features of this <emphasis>view</emphasis> "
2510 "<link url='help:/dolphin/dolphin-view.html'>click here</link> "
2511 "instead. This will open a page from the <emphasis>Handbook"
2512 "</emphasis> that covers the basics.</para>"));
2515 actionCollection()->action(KStandardAction::name(KStandardAction::KeyBindings
))
2516 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window "
2517 "that lists the <emphasis>keyboard shortcuts</emphasis>.<nl/>"
2518 "There you can set up key combinations to trigger an action when "
2519 "they are pressed simultaneously. All commands in this application can "
2520 "be triggered this way.</para>"));
2521 actionCollection()->action(KStandardAction::name(KStandardAction::ConfigureToolbars
))
2522 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window in which "
2523 "you can change which buttons appear on the <emphasis>Toolbar</emphasis>.</para>"
2524 "<para>All items you see in the <interface>Control</interface> menu "
2525 "or in the <interface>Menubar</interface> can also be placed on the Toolbar.</para>"));
2526 actionCollection()->action(KStandardAction::name(KStandardAction::Preferences
))
2527 ->setWhatsThis(xi18nc("@info:whatsthis","This opens a window where you can "
2528 "change a multitude of settings for this application. For an explanation "
2529 "of the various settings go to the chapter <emphasis>Configuring Dolphin"
2530 "</emphasis> in <interface>Help|Dolphin Handbook</interface>."));
2533 // The whatsthis has to be set for the m_helpMenu and for the
2534 // StandardAction separately because both are used in different locations.
2535 // m_helpMenu is only used for createControlButton() button.
2537 auto setStandardActionWhatsThis
= [this](KStandardAction::StandardAction actionId
,
2538 const QString
&whatsThis
) {
2539 if (auto *action
= actionCollection()->action(KStandardAction::name(actionId
))) {
2540 action
->setWhatsThis(whatsThis
);
2543 auto setHelpActionWhatsThis
= [this](KHelpMenu::MenuId menuId
, const QString
&whatsThis
) {
2544 if (auto *action
= m_helpMenu
->action(menuId
)) {
2545 action
->setWhatsThis(whatsThis
);
2549 // Links do not work within the Menubar so texts without links are provided there.
2551 // i18n: If the external link isn't available in your language you should
2552 // probably state the external link language at least in brackets to not
2553 // frustrate the user. If there are multiple languages that the user might
2554 // know with a reasonable chance you might want to have 2 external links.
2555 // The same is in my opinion true for every external link you translate.
2556 const QString whatsThisHelpContents
= xi18nc("@info:whatsthis handbook",
2557 "<para>This opens the Handbook for this application. It provides "
2558 "explanations for every part of <emphasis>Dolphin</emphasis>.</para>");
2559 setStandardActionWhatsThis(KStandardAction::HelpContents
, whatsThisHelpContents
2560 + xi18nc("@info:whatsthis second half of handbook hb text without link",
2561 "<para>If you want more elaborate introductions to the "
2562 "different features of <emphasis>Dolphin</emphasis> "
2563 "go to the KDE UserBase Wiki.</para>"));
2564 setHelpActionWhatsThis(KHelpMenu::menuHelpContents
, whatsThisHelpContents
2565 + xi18nc("@info:whatsthis second half of handbook text with link",
2566 "<para>If you want more elaborate introductions to the "
2567 "different features of <emphasis>Dolphin</emphasis> "
2568 "<link url='https://userbase.kde.org/Dolphin/File_Management'>click here</link>. "
2569 "It will open the dedicated page in the KDE UserBase Wiki.</para>"));
2571 const QString whatsThisWhatsThis
= xi18nc("@info:whatsthis whatsthis button",
2572 "<para>This is the button that invokes the help feature you are "
2573 "using right now! Click it, then click any component of this "
2574 "application to ask \"What's this?\" about it. The mouse cursor "
2575 "will change appearance if no help is available for a spot.</para>");
2576 setStandardActionWhatsThis(KStandardAction::WhatsThis
, whatsThisWhatsThis
2577 + xi18nc("@info:whatsthis second half of whatsthis button text without link",
2578 "<para>There are two other ways to get help for this application: The "
2579 "<interface>Dolphin Handbook</interface> in the <interface>Help"
2580 "</interface> menu and the <emphasis>KDE UserBase Wiki</emphasis> "
2581 "article about <emphasis>File Management</emphasis> online."
2582 "</para><para>The \"What's this?\" help is "
2583 "missing in most other windows so don't get too used to this.</para>"));
2584 setHelpActionWhatsThis(KHelpMenu::menuWhatsThis
, whatsThisWhatsThis
2585 + xi18nc("@info:whatsthis second half of whatsthis button text with link",
2586 "<para>There are two other ways to get help: "
2587 "The <link url='help:/dolphin/index.html'>Dolphin Handbook</link> and "
2588 "the <link url='https://userbase.kde.org/Dolphin/File_Management'>KDE "
2589 "UserBase Wiki</link>.</para><para>The \"What's this?\" help is "
2590 "missing in most other windows so don't get too used to this.</para>"));
2592 const QString whatsThisReportBug
= xi18nc("@info:whatsthis","<para>This opens a "
2593 "window that will guide you through reporting errors or flaws "
2594 "in this application or in other KDE software.</para>");
2595 setStandardActionWhatsThis(KStandardAction::ReportBug
, whatsThisReportBug
);
2596 setHelpActionWhatsThis(KHelpMenu::menuReportBug
, whatsThisReportBug
2597 + xi18nc("@info:whatsthis second half of reportbug text with link",
2598 "<para>High-quality bug reports are much appreciated. To learn "
2599 "how to make your bug report as effective as possible "
2600 "<link url='https://community.kde.org/Get_Involved/Bug_Reporting'>"
2601 "click here</link>.</para>"));
2603 const QString whatsThisDonate
= xi18nc("@info:whatsthis","<para>This opens a "
2604 "<emphasis>web page</emphasis> where you can donate to "
2605 "support the continued work on this application and many "
2606 "other projects by the <emphasis>KDE</emphasis> community.</para>"
2607 "<para>Donating is the easiest and fastest way to efficiently "
2608 "support KDE and its projects. KDE projects are available for "
2609 "free therefore your donation is needed to cover things that "
2610 "require money like servers, contributor meetings, etc.</para>"
2611 "<para><emphasis>KDE e.V.</emphasis> is the non-profit "
2612 "organization behind the KDE community.</para>");
2613 setStandardActionWhatsThis(KStandardAction::Donate
, whatsThisDonate
);
2614 setHelpActionWhatsThis(KHelpMenu::menuDonate
, whatsThisDonate
);
2616 const QString whatsThisSwitchLanguage
= xi18nc("@info:whatsthis",
2617 "With this you can change the language this application uses."
2618 "<nl/>You can even set secondary languages which will be used "
2619 "if texts are not available in your preferred language.");
2620 setStandardActionWhatsThis(KStandardAction::SwitchApplicationLanguage
,
2621 whatsThisSwitchLanguage
);
2622 setHelpActionWhatsThis(KHelpMenu::menuSwitchLanguage
, whatsThisSwitchLanguage
);
2624 const QString whatsThisAboutApp
= xi18nc("@info:whatsthis","This opens a "
2625 "window that informs you about the version, license, "
2626 "used libraries and maintainers of this application.");
2627 setStandardActionWhatsThis(KStandardAction::AboutApp
, whatsThisAboutApp
);
2628 setHelpActionWhatsThis(KHelpMenu::menuAboutApp
, whatsThisAboutApp
);
2630 const QString whatsThisAboutKDE
= xi18nc("@info:whatsthis","This opens a "
2631 "window with information about <emphasis>KDE</emphasis>. "
2632 "The KDE community are the people behind this free software."
2633 "<nl/>If you like using this application but don't know "
2634 "about KDE or want to see a cute dragon have a look!");
2635 setStandardActionWhatsThis(KStandardAction::AboutKDE
, whatsThisAboutKDE
);
2636 setHelpActionWhatsThis(KHelpMenu::menuAboutKDE
, whatsThisAboutKDE
);
2639 bool DolphinMainWindow::addHamburgerMenuToToolbar()
2641 QDomDocument domDocument
= KXMLGUIClient::domDocument();
2642 if (domDocument
.isNull()) {
2645 QDomNode toolbar
= domDocument
.elementsByTagName(QStringLiteral("ToolBar")).at(0);
2646 if (toolbar
.isNull()) {
2650 QDomElement hamburgerMenuElement
= domDocument
.createElement(QStringLiteral("Action"));
2651 hamburgerMenuElement
.setAttribute(QStringLiteral("name"), QStringLiteral("hamburger_menu"));
2652 toolbar
.appendChild(hamburgerMenuElement
);
2654 KXMLGUIFactory::saveConfigFile(domDocument
, xmlFile());
2658 // Make sure to also remove the <KXMLGUIFactory> and <QDomDocument> include
2659 // whenever this method is removed (maybe in the year ~2026).
2662 bool DolphinMainWindow::event(QEvent
*event
)
2664 if (event
->type() == QEvent::WhatsThisClicked
) {
2666 QWhatsThisClickedEvent
* whatsThisEvent
= dynamic_cast<QWhatsThisClickedEvent
*>(event
);
2667 QDesktopServices::openUrl(QUrl(whatsThisEvent
->href()));
2670 return KXmlGuiWindow::event(event
);
2673 bool DolphinMainWindow::eventFilter(QObject
* obj
, QEvent
* event
)
2676 if (event
->type() == QEvent::WhatsThisClicked
) {
2678 QWhatsThisClickedEvent
* whatsThisEvent
= dynamic_cast<QWhatsThisClickedEvent
*>(event
);
2679 QDesktopServices::openUrl(QUrl(whatsThisEvent
->href()));
2685 // Set a sane initial window size
2686 QSize
DolphinMainWindow::sizeHint() const
2688 return KXmlGuiWindow::sizeHint().expandedTo(QSize(760, 550));
2691 void DolphinMainWindow::saveNewToolbarConfig()
2693 KXmlGuiWindow::saveNewToolbarConfig(); // Applies the new config. This has to be called first
2694 // because the rest of this method decides things
2695 // based on the new config.
2696 auto navigators
= static_cast<DolphinNavigatorsWidgetAction
*>
2697 (actionCollection()->action(QStringLiteral("url_navigators")));
2698 if (!toolBar()->actions().contains(navigators
)) {
2699 m_tabWidget
->currentTabPage()->insertNavigatorsWidget(navigators
);
2701 updateAllowedToolbarAreas();
2702 (static_cast<KHamburgerMenu
*>(actionCollection()->action(KStandardAction::name(
2703 KStandardAction::HamburgerMenu
))))->hideActionsOf(toolBar());
2706 void DolphinMainWindow::focusTerminalPanel()
2708 if (m_terminalPanel
->isVisible()) {
2709 if (m_terminalPanel
->terminalHasFocus()) {
2710 m_activeViewContainer
->view()->setFocus(Qt::FocusReason::ShortcutFocusReason
);
2711 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
2713 m_terminalPanel
->setFocus(Qt::FocusReason::ShortcutFocusReason
);
2714 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
2717 actionCollection()->action(QStringLiteral("show_terminal_panel"))->trigger();
2718 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
2722 DolphinMainWindow::UndoUiInterface::UndoUiInterface() :
2723 KIO::FileUndoManager::UiInterface()
2727 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
2731 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
* job
)
2733 DolphinMainWindow
* mainWin
= qobject_cast
<DolphinMainWindow
*>(parentWidget());
2735 DolphinViewContainer
* container
= mainWin
->activeViewContainer();
2736 container
->showMessage(job
->errorString(), DolphinViewContainer::Error
);
2738 KIO::FileUndoManager::UiInterface::jobError(job
);
2742 bool DolphinMainWindow::isUrlOpen(const QString
&url
)
2744 return m_tabWidget
->isUrlOpen(QUrl::fromUserInput(url
));
2747 bool DolphinMainWindow::isUrlOrParentOpen(const QString
&url
)
2749 return m_tabWidget
->isUrlOrParentOpen(QUrl::fromUserInput(url
));