]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinmainwindow.cpp
KFileItemListWidget: wrong selection when renamed file ends with a dot
[dolphin.git] / src / dolphinmainwindow.cpp
1 /*
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>
5 *
6 * SPDX-License-Identifier: GPL-2.0-or-later
7 */
8
9 #include "dolphinmainwindow.h"
10
11 #include "admin/workerintegration.h"
12 #include "dolphin_generalsettings.h"
13 #include "dolphinbookmarkhandler.h"
14 #include "dolphincontextmenu.h"
15 #include "dolphindockwidget.h"
16 #include "dolphinmainwindowadaptor.h"
17 #include "dolphinnavigatorswidgetaction.h"
18 #include "dolphinnewfilemenu.h"
19 #include "dolphinplacesmodelsingleton.h"
20 #include "dolphinrecenttabsmenu.h"
21 #include "dolphintabpage.h"
22 #include "dolphinurlnavigatorscontroller.h"
23 #include "dolphinviewcontainer.h"
24 #include "global.h"
25 #include "middleclickactioneventfilter.h"
26 #include "panels/folders/folderspanel.h"
27 #include "panels/places/placespanel.h"
28 #include "panels/terminal/terminalpanel.h"
29 #include "selectionmode/actiontexthelper.h"
30 #include "settings/dolphinsettingsdialog.h"
31 #include "statusbar/dolphinstatusbar.h"
32 #include "views/dolphinnewfilemenuobserver.h"
33 #include "views/dolphinremoteencoding.h"
34 #include "views/dolphinviewactionhandler.h"
35 #include "views/draganddrophelper.h"
36 #include "views/viewproperties.h"
37
38 #include <KActionCollection>
39 #include <KActionMenu>
40 #include <KAuthorized>
41 #include <KColorSchemeManager>
42 #include <KConfig>
43 #include <KConfigGui>
44 #include <KDesktopFile>
45 #include <KDialogJobUiDelegate>
46 #include <KDualAction>
47 #include <KFileItemListProperties>
48 #include <KIO/CommandLauncherJob>
49 #include <KIO/JobUiDelegateFactory>
50 #include <KIO/OpenFileManagerWindowJob>
51 #include <KIO/OpenUrlJob>
52 #include <KJobWidgets>
53 #include <KLocalizedString>
54 #include <KMessageBox>
55 #include <KProtocolInfo>
56 #include <KProtocolManager>
57 #include <KRecentFilesAction>
58 #include <KRuntimePlatform>
59 #include <KShell>
60 #include <KShortcutsDialog>
61 #include <KStandardAction>
62 #include <KSycoca>
63 #include <KTerminalLauncherJob>
64 #include <KToggleAction>
65 #include <KToolBar>
66 #include <KToolBarPopupAction>
67 #include <KUrlComboBox>
68 #include <KUrlNavigator>
69 #include <KWindowSystem>
70 #include <KXMLGUIFactory>
71
72 #include <kwidgetsaddons_version.h>
73
74 #include <QApplication>
75 #include <QClipboard>
76 #include <QCloseEvent>
77 #include <QDesktopServices>
78 #include <QDialog>
79 #include <QDomDocument>
80 #include <QFileInfo>
81 #include <QLineEdit>
82 #include <QMenuBar>
83 #include <QPushButton>
84 #include <QShowEvent>
85 #include <QStandardPaths>
86 #include <QTimer>
87 #include <QToolButton>
88 #include <QtConcurrentRun>
89 #include <dolphindebug.h>
90
91 #include <algorithm>
92
93 #if HAVE_X11
94 #include <KStartupInfo>
95 #endif
96
97 namespace
98 {
99 // Used for GeneralSettings::version() to determine whether
100 // an updated version of Dolphin is running, so as to migrate
101 // removed/renamed ...etc config entries; increment it in such
102 // cases
103 const int CurrentDolphinVersion = 202;
104 // The maximum number of entries in the back/forward popup menu
105 const int MaxNumberOfNavigationentries = 12;
106 // The maximum number of "Go to Tab" shortcuts
107 const int MaxActivateTabShortcuts = 9;
108 }
109
110 DolphinMainWindow::DolphinMainWindow()
111 : KXmlGuiWindow(nullptr)
112 , m_newFileMenu(nullptr)
113 , m_tabWidget(nullptr)
114 , m_activeViewContainer(nullptr)
115 , m_actionHandler(nullptr)
116 , m_remoteEncoding(nullptr)
117 , m_settingsDialog()
118 , m_bookmarkHandler(nullptr)
119 , m_disabledActionNotifier(nullptr)
120 , m_lastHandleUrlOpenJob(nullptr)
121 , m_terminalPanel(nullptr)
122 , m_placesPanel(nullptr)
123 , m_tearDownFromPlacesRequested(false)
124 , m_backAction(nullptr)
125 , m_forwardAction(nullptr)
126 , m_splitViewAction(nullptr)
127 , m_splitViewMenuAction(nullptr)
128 , m_sessionSaveTimer(nullptr)
129 , m_sessionSaveWatcher(nullptr)
130 , m_sessionSaveScheduled(false)
131 {
132 Q_INIT_RESOURCE(dolphin);
133
134 new MainWindowAdaptor(this);
135
136 #ifndef Q_OS_WIN
137 setWindowFlags(Qt::WindowContextHelpButtonHint);
138 #endif
139 setComponentName(QStringLiteral("dolphin"), QGuiApplication::applicationDisplayName());
140 setObjectName(QStringLiteral("Dolphin#"));
141
142 setStateConfigGroup("State");
143
144 #if defined(Q_OS_WIN) || defined(Q_OS_MACOS)
145 new KColorSchemeManager(this); // Sets a sensible color scheme which fixes unreadable icons and text on Windows.
146 #endif
147
148 connect(&DolphinNewFileMenuObserver::instance(), &DolphinNewFileMenuObserver::errorMessage, this, &DolphinMainWindow::showErrorMessage);
149
150 KIO::FileUndoManager *undoManager = KIO::FileUndoManager::self();
151 undoManager->setUiInterface(new UndoUiInterface());
152
153 connect(undoManager, &KIO::FileUndoManager::undoAvailable, this, &DolphinMainWindow::slotUndoAvailable);
154 connect(undoManager, &KIO::FileUndoManager::undoTextChanged, this, &DolphinMainWindow::slotUndoTextChanged);
155 connect(undoManager, &KIO::FileUndoManager::jobRecordingStarted, this, &DolphinMainWindow::clearStatusBar);
156 connect(undoManager, &KIO::FileUndoManager::jobRecordingFinished, this, &DolphinMainWindow::showCommand);
157
158 const bool firstRun = (GeneralSettings::version() < 200);
159 if (firstRun) {
160 GeneralSettings::setViewPropsTimestamp(QDateTime::currentDateTime());
161 }
162
163 setAcceptDrops(true);
164
165 auto *navigatorsWidgetAction = new DolphinNavigatorsWidgetAction(this);
166 actionCollection()->addAction(QStringLiteral("url_navigators"), navigatorsWidgetAction);
167 m_tabWidget = new DolphinTabWidget(navigatorsWidgetAction, this);
168 m_tabWidget->setObjectName("tabWidget");
169 connect(m_tabWidget, &DolphinTabWidget::activeViewChanged, this, &DolphinMainWindow::activeViewChanged);
170 connect(m_tabWidget, &DolphinTabWidget::tabCountChanged, this, &DolphinMainWindow::tabCountChanged);
171 connect(m_tabWidget, &DolphinTabWidget::currentUrlChanged, this, &DolphinMainWindow::updateWindowTitle);
172 setCentralWidget(m_tabWidget);
173
174 m_actionTextHelper = new SelectionMode::ActionTextHelper(this);
175 setupActions();
176
177 m_actionHandler = new DolphinViewActionHandler(actionCollection(), m_actionTextHelper, this);
178 connect(m_actionHandler, &DolphinViewActionHandler::actionBeingHandled, this, &DolphinMainWindow::clearStatusBar);
179 connect(m_actionHandler, &DolphinViewActionHandler::createDirectoryTriggered, this, &DolphinMainWindow::createDirectory);
180 connect(m_actionHandler, &DolphinViewActionHandler::createFileTriggered, this, &DolphinMainWindow::createFile);
181 connect(m_actionHandler, &DolphinViewActionHandler::selectionModeChangeTriggered, this, &DolphinMainWindow::slotSetSelectionMode);
182
183 QAction *newDirAction = actionCollection()->action(QStringLiteral("create_dir"));
184 Q_CHECK_PTR(newDirAction);
185 m_newFileMenu->setNewFolderShortcutAction(newDirAction);
186
187 QAction *newFileAction = actionCollection()->action(QStringLiteral("create_file"));
188 Q_CHECK_PTR(newFileAction);
189 m_newFileMenu->setNewFileShortcutAction(newFileAction);
190
191 m_remoteEncoding = new DolphinRemoteEncoding(this, m_actionHandler);
192 connect(this, &DolphinMainWindow::urlChanged, m_remoteEncoding, &DolphinRemoteEncoding::slotAboutToOpenUrl);
193
194 m_disabledActionNotifier = new DisabledActionNotifier(this);
195 connect(m_disabledActionNotifier, &DisabledActionNotifier::disabledActionTriggered, this, [this](const QAction *, QString reason) {
196 m_activeViewContainer->showMessage(reason, KMessageWidget::Warning);
197 });
198
199 setupDockWidgets();
200
201 const bool usePhoneUi{KRuntimePlatform::runtimePlatform().contains(QLatin1String("phone"))};
202 setupGUI(Save | Create | ToolBar, usePhoneUi ? QStringLiteral("dolphinuiforphones.rc") : QString() /* load the default dolphinui.rc file */);
203 stateChanged(QStringLiteral("new_file"));
204
205 QClipboard *clipboard = QApplication::clipboard();
206 connect(clipboard, &QClipboard::dataChanged, this, &DolphinMainWindow::updatePasteAction);
207
208 QAction *toggleFilterBarAction = actionCollection()->action(QStringLiteral("toggle_filter"));
209 toggleFilterBarAction->setChecked(GeneralSettings::filterBar());
210
211 if (firstRun) {
212 menuBar()->setVisible(false);
213
214 if (usePhoneUi) {
215 Q_ASSERT(qobject_cast<QDockWidget *>(m_placesPanel->parent()));
216 m_placesPanel->parentWidget()->hide();
217 auto settings = GeneralSettings::self();
218 settings->setShowZoomSlider(false); // Zooming can be done with pinch gestures instead and we are short on horizontal space.
219 settings->setRenameInline(false); // This works around inline renaming currently not working well with virtual keyboards.
220 settings->save(); // Otherwise the RenameInline setting is not picked up for the first time Dolphin is used.
221 }
222 }
223
224 const bool showMenu = !menuBar()->isHidden();
225 QAction *showMenuBarAction = actionCollection()->action(KStandardAction::name(KStandardAction::ShowMenubar));
226 showMenuBarAction->setChecked(showMenu); // workaround for bug #171080
227
228 auto hamburgerMenu = static_cast<KHamburgerMenu *>(actionCollection()->action(KStandardAction::name(KStandardAction::HamburgerMenu)));
229 hamburgerMenu->setMenuBar(menuBar());
230 hamburgerMenu->setShowMenuBarAction(showMenuBarAction);
231 connect(hamburgerMenu, &KHamburgerMenu::aboutToShowMenu, this, &DolphinMainWindow::updateHamburgerMenu);
232 hamburgerMenu->hideActionsOf(toolBar());
233 if (GeneralSettings::version() < 201 && !toolBar()->actions().contains(hamburgerMenu)) {
234 addHamburgerMenuToToolbar();
235 }
236
237 updateAllowedToolbarAreas();
238
239 // enable middle-click on back/forward/up to open in a new tab
240 auto *middleClickEventFilter = new MiddleClickActionEventFilter(this);
241 connect(middleClickEventFilter, &MiddleClickActionEventFilter::actionMiddleClicked, this, &DolphinMainWindow::slotToolBarActionMiddleClicked);
242 toolBar()->installEventFilter(middleClickEventFilter);
243
244 setupWhatsThis();
245
246 connect(KSycoca::self(), &KSycoca::databaseChanged, this, &DolphinMainWindow::updateOpenPreferredSearchToolAction);
247
248 QTimer::singleShot(0, this, &DolphinMainWindow::updateOpenPreferredSearchToolAction);
249
250 m_fileItemActions.setParentWidget(this);
251 connect(&m_fileItemActions, &KFileItemActions::error, this, [this](const QString &errorMessage) {
252 showErrorMessage(errorMessage);
253 });
254
255 connect(GeneralSettings::self(), &GeneralSettings::splitViewChanged, this, &DolphinMainWindow::slotSplitViewChanged);
256 }
257
258 DolphinMainWindow::~DolphinMainWindow()
259 {
260 // This fixes a crash on Wayland when closing the mainwindow while another dialog is open.
261 disconnect(QGuiApplication::clipboard(), &QClipboard::dataChanged, this, &DolphinMainWindow::updatePasteAction);
262
263 // This fixes a crash in dolphinmainwindowtest where the connection below fires even though the KMainWindow destructor of this object is already running.
264 Q_CHECK_PTR(qobject_cast<DolphinDockWidget *>(m_placesPanel->parent()));
265 disconnect(static_cast<DolphinDockWidget *>(m_placesPanel->parent()),
266 &DolphinDockWidget::visibilityChanged,
267 this,
268 &DolphinMainWindow::slotPlacesPanelVisibilityChanged);
269 }
270
271 QVector<DolphinViewContainer *> DolphinMainWindow::viewContainers() const
272 {
273 QVector<DolphinViewContainer *> viewContainers;
274
275 for (int i = 0; i < m_tabWidget->count(); ++i) {
276 DolphinTabPage *tabPage = m_tabWidget->tabPageAt(i);
277
278 viewContainers << tabPage->primaryViewContainer();
279 if (tabPage->splitViewEnabled()) {
280 viewContainers << tabPage->secondaryViewContainer();
281 }
282 }
283 return viewContainers;
284 }
285
286 void DolphinMainWindow::openDirectories(const QList<QUrl> &dirs, bool splitView)
287 {
288 m_tabWidget->openDirectories(dirs, splitView);
289 }
290
291 void DolphinMainWindow::openDirectories(const QStringList &dirs, bool splitView)
292 {
293 openDirectories(QUrl::fromStringList(dirs), splitView);
294 }
295
296 void DolphinMainWindow::openFiles(const QList<QUrl> &files, bool splitView)
297 {
298 m_tabWidget->openFiles(files, splitView);
299 }
300
301 bool DolphinMainWindow::isFoldersPanelEnabled() const
302 {
303 return actionCollection()->action(QStringLiteral("show_folders_panel"))->isChecked();
304 }
305
306 bool DolphinMainWindow::isInformationPanelEnabled() const
307 {
308 #if HAVE_BALOO
309 return actionCollection()->action(QStringLiteral("show_information_panel"))->isChecked();
310 #else
311 return false;
312 #endif
313 }
314
315 bool DolphinMainWindow::isSplitViewEnabledInCurrentTab() const
316 {
317 return m_tabWidget->currentTabPage()->splitViewEnabled();
318 }
319
320 void DolphinMainWindow::openFiles(const QStringList &files, bool splitView)
321 {
322 openFiles(QUrl::fromStringList(files), splitView);
323 }
324
325 void DolphinMainWindow::activateWindow(const QString &activationToken)
326 {
327 window()->setAttribute(Qt::WA_NativeWindow, true);
328
329 if (KWindowSystem::isPlatformWayland()) {
330 KWindowSystem::setCurrentXdgActivationToken(activationToken);
331 } else if (KWindowSystem::isPlatformX11()) {
332 #if HAVE_X11
333 KStartupInfo::setNewStartupId(window()->windowHandle(), activationToken.toUtf8());
334 #endif
335 }
336
337 KWindowSystem::activateWindow(window()->windowHandle());
338 }
339
340 bool DolphinMainWindow::isActiveWindow()
341 {
342 return window()->isActiveWindow();
343 }
344
345 void DolphinMainWindow::showCommand(CommandType command)
346 {
347 DolphinStatusBar *statusBar = m_activeViewContainer->statusBar();
348 switch (command) {
349 case KIO::FileUndoManager::Copy:
350 statusBar->setText(i18nc("@info:status", "Successfully copied."));
351 break;
352 case KIO::FileUndoManager::Move:
353 statusBar->setText(i18nc("@info:status", "Successfully moved."));
354 break;
355 case KIO::FileUndoManager::Link:
356 statusBar->setText(i18nc("@info:status", "Successfully linked."));
357 break;
358 case KIO::FileUndoManager::Trash:
359 statusBar->setText(i18nc("@info:status", "Successfully moved to trash."));
360 break;
361 case KIO::FileUndoManager::Rename:
362 statusBar->setText(i18nc("@info:status", "Successfully renamed."));
363 break;
364
365 case KIO::FileUndoManager::Mkdir:
366 statusBar->setText(i18nc("@info:status", "Created folder."));
367 break;
368
369 default:
370 break;
371 }
372 }
373
374 void DolphinMainWindow::pasteIntoFolder()
375 {
376 m_activeViewContainer->view()->pasteIntoFolder();
377 }
378
379 void DolphinMainWindow::changeUrl(const QUrl &url)
380 {
381 if (!KProtocolManager::supportsListing(url)) {
382 // The URL navigator only checks for validity, not
383 // if the URL can be listed. An error message is
384 // shown due to DolphinViewContainer::restoreView().
385 return;
386 }
387
388 m_activeViewContainer->setUrl(url);
389 updateFileAndEditActions();
390 updatePasteAction();
391 updateViewActions();
392 updateGoActions();
393
394 // will signal used urls to activities manager, too
395 m_recentFiles->addUrl(url, QString(), "inode/directory");
396
397 Q_EMIT urlChanged(url);
398 }
399
400 void DolphinMainWindow::slotTerminalDirectoryChanged(const QUrl &url)
401 {
402 if (m_tearDownFromPlacesRequested && url == QUrl::fromLocalFile(QDir::homePath())) {
403 m_placesPanel->proceedWithTearDown();
404 m_tearDownFromPlacesRequested = false;
405 }
406
407 m_activeViewContainer->setAutoGrabFocus(false);
408 changeUrl(url);
409 m_activeViewContainer->setAutoGrabFocus(true);
410 }
411
412 void DolphinMainWindow::slotEditableStateChanged(bool editable)
413 {
414 KToggleAction *editableLocationAction = static_cast<KToggleAction *>(actionCollection()->action(QStringLiteral("editable_location")));
415 editableLocationAction->setChecked(editable);
416 }
417
418 void DolphinMainWindow::slotSelectionChanged(const KFileItemList &selection)
419 {
420 updateFileAndEditActions();
421
422 const int selectedUrlsCount = m_tabWidget->currentTabPage()->selectedItemsCount();
423
424 QAction *compareFilesAction = actionCollection()->action(QStringLiteral("compare_files"));
425 if (selectedUrlsCount == 2) {
426 compareFilesAction->setEnabled(isKompareInstalled());
427 } else {
428 compareFilesAction->setEnabled(false);
429 }
430
431 Q_EMIT selectionChanged(selection);
432 }
433
434 void DolphinMainWindow::updateHistory()
435 {
436 const KUrlNavigator *urlNavigator = m_activeViewContainer->urlNavigatorInternalWithHistory();
437 const int index = urlNavigator->historyIndex();
438
439 QAction *backAction = actionCollection()->action(KStandardAction::name(KStandardAction::Back));
440 if (backAction) {
441 backAction->setToolTip(i18nc("@info", "Go back"));
442 backAction->setWhatsThis(i18nc("@info:whatsthis go back", "Return to the previously viewed folder."));
443 backAction->setEnabled(index < urlNavigator->historySize() - 1);
444 }
445
446 QAction *forwardAction = actionCollection()->action(KStandardAction::name(KStandardAction::Forward));
447 if (forwardAction) {
448 forwardAction->setToolTip(i18nc("@info", "Go forward"));
449 forwardAction->setWhatsThis(xi18nc("@info:whatsthis go forward", "This undoes a <interface>Go|Back</interface> action."));
450 forwardAction->setEnabled(index > 0);
451 }
452 }
453
454 void DolphinMainWindow::updateFilterBarAction(bool show)
455 {
456 QAction *toggleFilterBarAction = actionCollection()->action(QStringLiteral("toggle_filter"));
457 toggleFilterBarAction->setChecked(show);
458 }
459
460 void DolphinMainWindow::openNewMainWindow()
461 {
462 Dolphin::openNewWindow({m_activeViewContainer->url()}, this);
463 }
464
465 void DolphinMainWindow::openNewActivatedTab()
466 {
467 // keep browsers compatibility, new tab is always after last one
468 auto openNewTabAfterLastTabConfigured = GeneralSettings::openNewTabAfterLastTab();
469 GeneralSettings::setOpenNewTabAfterLastTab(true);
470 m_tabWidget->openNewActivatedTab();
471 GeneralSettings::setOpenNewTabAfterLastTab(openNewTabAfterLastTabConfigured);
472 }
473
474 void DolphinMainWindow::addToPlaces()
475 {
476 QUrl url;
477 QString name;
478
479 // If nothing is selected, act on the current dir
480 if (m_activeViewContainer->view()->selectedItems().isEmpty()) {
481 url = m_activeViewContainer->url();
482 name = m_activeViewContainer->placesText();
483 } else {
484 const auto dirToAdd = m_activeViewContainer->view()->selectedItems().first();
485 url = dirToAdd.url();
486 name = dirToAdd.name();
487 }
488 if (url.isValid()) {
489 QString icon;
490 if (m_activeViewContainer->isSearchModeEnabled()) {
491 icon = QStringLiteral("folder-saved-search-symbolic");
492 } else {
493 icon = KIO::iconNameForUrl(url);
494 }
495 DolphinPlacesModelSingleton::instance().placesModel()->addPlace(name, url, icon);
496 }
497 }
498
499 DolphinTabPage *DolphinMainWindow::openNewTab(const QUrl &url)
500 {
501 return m_tabWidget->openNewTab(url, QUrl());
502 }
503
504 void DolphinMainWindow::openNewTabAndActivate(const QUrl &url)
505 {
506 m_tabWidget->openNewActivatedTab(url, QUrl());
507 }
508
509 void DolphinMainWindow::openNewWindow(const QUrl &url)
510 {
511 Dolphin::openNewWindow({url}, this);
512 }
513
514 void DolphinMainWindow::slotSplitViewChanged()
515 {
516 m_tabWidget->currentTabPage()->setSplitViewEnabled(GeneralSettings::splitView(), WithAnimation);
517 updateSplitActions();
518 }
519
520 void DolphinMainWindow::openInNewTab()
521 {
522 const KFileItemList &list = m_activeViewContainer->view()->selectedItems();
523 bool tabCreated = false;
524
525 for (const KFileItem &item : list) {
526 const QUrl &url = DolphinView::openItemAsFolderUrl(item);
527 if (!url.isEmpty()) {
528 openNewTab(url);
529 tabCreated = true;
530 }
531 }
532
533 // if no new tab has been created from the selection
534 // open the current directory in a new tab
535 if (!tabCreated) {
536 openNewTab(m_activeViewContainer->url());
537 }
538 }
539
540 void DolphinMainWindow::openInNewWindow()
541 {
542 QUrl newWindowUrl;
543
544 const KFileItemList list = m_activeViewContainer->view()->selectedItems();
545 if (list.isEmpty()) {
546 newWindowUrl = m_activeViewContainer->url();
547 } else if (list.count() == 1) {
548 const KFileItem &item = list.first();
549 newWindowUrl = DolphinView::openItemAsFolderUrl(item);
550 }
551
552 if (!newWindowUrl.isEmpty()) {
553 Dolphin::openNewWindow({newWindowUrl}, this);
554 }
555 }
556
557 void DolphinMainWindow::openInSplitView(const QUrl &url)
558 {
559 QUrl newSplitViewUrl = url;
560
561 if (newSplitViewUrl.isEmpty()) {
562 const KFileItemList list = m_activeViewContainer->view()->selectedItems();
563 if (list.count() == 1) {
564 const KFileItem &item = list.first();
565 newSplitViewUrl = DolphinView::openItemAsFolderUrl(item);
566 }
567 }
568
569 if (newSplitViewUrl.isEmpty()) {
570 return;
571 }
572
573 DolphinTabPage *tabPage = m_tabWidget->currentTabPage();
574 if (tabPage->splitViewEnabled()) {
575 tabPage->switchActiveView();
576 tabPage->activeViewContainer()->setUrl(newSplitViewUrl);
577 } else {
578 tabPage->setSplitViewEnabled(true, WithAnimation, newSplitViewUrl);
579 updateViewActions();
580 }
581 }
582
583 void DolphinMainWindow::showTarget()
584 {
585 const KFileItem link = m_activeViewContainer->view()->selectedItems().at(0);
586 const QUrl destinationUrl = link.url().resolved(QUrl(link.linkDest()));
587
588 auto job = KIO::stat(destinationUrl, KIO::StatJob::SourceSide, KIO::StatNoDetails);
589
590 connect(job, &KJob::finished, this, [this, destinationUrl](KJob *job) {
591 KIO::StatJob *statJob = static_cast<KIO::StatJob *>(job);
592
593 if (statJob->error()) {
594 m_activeViewContainer->showMessage(job->errorString(), KMessageWidget::Error);
595 } else {
596 KIO::highlightInFileManager({destinationUrl});
597 }
598 });
599 }
600
601 bool DolphinMainWindow::event(QEvent *event)
602 {
603 if (event->type() == QEvent::ShortcutOverride) {
604 const QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
605 if (keyEvent->key() == Qt::Key_Space && m_activeViewContainer->view()->handleSpaceAsNormalKey()) {
606 event->accept();
607 return true;
608 }
609 }
610
611 return KXmlGuiWindow::event(event);
612 }
613
614 void DolphinMainWindow::showEvent(QShowEvent *event)
615 {
616 KXmlGuiWindow::showEvent(event);
617
618 if (!event->spontaneous() && m_activeViewContainer) {
619 m_activeViewContainer->view()->setFocus();
620 }
621 }
622
623 void DolphinMainWindow::closeEvent(QCloseEvent *event)
624 {
625 // Find out if Dolphin is closed directly by the user or
626 // by the session manager because the session is closed
627 bool closedByUser = true;
628 if (qApp->isSavingSession()) {
629 closedByUser = false;
630 }
631
632 if (m_tabWidget->count() > 1 && GeneralSettings::confirmClosingMultipleTabs() && !GeneralSettings::rememberOpenedTabs() && closedByUser) {
633 // Ask the user if he really wants to quit and close all tabs.
634 // Open a confirmation dialog with 3 buttons:
635 // QDialogButtonBox::Yes -> Quit
636 // QDialogButtonBox::No -> Close only the current tab
637 // QDialogButtonBox::Cancel -> do nothing
638 QDialog *dialog = new QDialog(this, Qt::Dialog);
639 dialog->setWindowTitle(i18nc("@title:window", "Confirmation"));
640 dialog->setModal(true);
641 QDialogButtonBox *buttons = new QDialogButtonBox(QDialogButtonBox::Yes | QDialogButtonBox::No | QDialogButtonBox::Cancel);
642 KGuiItem::assign(buttons->button(QDialogButtonBox::Yes),
643 KGuiItem(i18nc("@action:button 'Quit Dolphin' button", "&Quit %1", QGuiApplication::applicationDisplayName()),
644 QIcon::fromTheme(QStringLiteral("application-exit"))));
645 KGuiItem::assign(buttons->button(QDialogButtonBox::No), KGuiItem(i18n("C&lose Current Tab"), QIcon::fromTheme(QStringLiteral("tab-close"))));
646 KGuiItem::assign(buttons->button(QDialogButtonBox::Cancel), KStandardGuiItem::cancel());
647 buttons->button(QDialogButtonBox::Yes)->setDefault(true);
648
649 bool doNotAskAgainCheckboxResult = false;
650
651 const auto result = KMessageBox::createKMessageBox(dialog,
652 buttons,
653 QMessageBox::Warning,
654 i18n("You have multiple tabs open in this window, are you sure you want to quit?"),
655 QStringList(),
656 i18n("Do not ask again"),
657 &doNotAskAgainCheckboxResult,
658 KMessageBox::Notify);
659
660 if (doNotAskAgainCheckboxResult) {
661 GeneralSettings::setConfirmClosingMultipleTabs(false);
662 }
663
664 switch (result) {
665 case QDialogButtonBox::Yes:
666 // Quit
667 break;
668 case QDialogButtonBox::No:
669 // Close only the current tab
670 m_tabWidget->closeTab();
671 Q_FALLTHROUGH();
672 default:
673 event->ignore();
674 return;
675 }
676 }
677
678 if (m_terminalPanel && m_terminalPanel->hasProgramRunning() && GeneralSettings::confirmClosingTerminalRunningProgram() && closedByUser) {
679 // Ask if the user really wants to quit Dolphin with a program that is still running in the Terminal panel
680 // Open a confirmation dialog with 3 buttons:
681 // QDialogButtonBox::Yes -> Quit
682 // QDialogButtonBox::No -> Show Terminal Panel
683 // QDialogButtonBox::Cancel -> do nothing
684 QDialog *dialog = new QDialog(this, Qt::Dialog);
685 dialog->setWindowTitle(i18nc("@title:window", "Confirmation"));
686 dialog->setModal(true);
687 auto standardButtons = QDialogButtonBox::Yes | QDialogButtonBox::Cancel;
688 if (!m_terminalPanel->isVisible()) {
689 standardButtons |= QDialogButtonBox::No;
690 }
691 QDialogButtonBox *buttons = new QDialogButtonBox(standardButtons);
692 KGuiItem::assign(buttons->button(QDialogButtonBox::Yes), KStandardGuiItem::quit());
693 if (!m_terminalPanel->isVisible()) {
694 KGuiItem::assign(buttons->button(QDialogButtonBox::No), KGuiItem(i18n("Show &Terminal Panel"), QIcon::fromTheme(QStringLiteral("dialog-scripts"))));
695 }
696 KGuiItem::assign(buttons->button(QDialogButtonBox::Cancel), KStandardGuiItem::cancel());
697
698 bool doNotAskAgainCheckboxResult = false;
699
700 const auto result = KMessageBox::createKMessageBox(
701 dialog,
702 buttons,
703 QMessageBox::Warning,
704 i18n("The program '%1' is still running in the Terminal panel. Are you sure you want to quit?", m_terminalPanel->runningProgramName()),
705 QStringList(),
706 i18n("Do not ask again"),
707 &doNotAskAgainCheckboxResult,
708 KMessageBox::Notify | KMessageBox::Dangerous);
709
710 if (doNotAskAgainCheckboxResult) {
711 GeneralSettings::setConfirmClosingTerminalRunningProgram(false);
712 }
713
714 switch (result) {
715 case QDialogButtonBox::Yes:
716 // Quit
717 break;
718 case QDialogButtonBox::No:
719 actionCollection()->action("show_terminal_panel")->trigger();
720 // Do not quit, ignore quit event
721 Q_FALLTHROUGH();
722 default:
723 event->ignore();
724 return;
725 }
726 }
727
728 if (m_sessionSaveTimer && (m_sessionSaveTimer->isActive() || m_sessionSaveWatcher->isRunning())) {
729 const bool sessionSaveTimerActive = m_sessionSaveTimer->isActive();
730
731 m_sessionSaveTimer->stop();
732 m_sessionSaveWatcher->disconnect();
733 m_sessionSaveWatcher->waitForFinished();
734
735 if (sessionSaveTimerActive || m_sessionSaveScheduled) {
736 slotSaveSession();
737 }
738 }
739
740 GeneralSettings::setVersion(CurrentDolphinVersion);
741 GeneralSettings::self()->save();
742
743 KXmlGuiWindow::closeEvent(event);
744 }
745
746 void DolphinMainWindow::slotSaveSession()
747 {
748 m_sessionSaveScheduled = false;
749
750 if (m_sessionSaveWatcher->isRunning()) {
751 // The previous session is still being saved - schedule another save.
752 m_sessionSaveWatcher->disconnect();
753 connect(m_sessionSaveWatcher, &QFutureWatcher<void>::finished, this, &DolphinMainWindow::slotSaveSession, Qt::SingleShotConnection);
754 m_sessionSaveScheduled = true;
755 } else if (!m_sessionSaveTimer->isActive()) {
756 // No point in saving the session if the timer is running (since it will save the session again when it times out).
757 KConfigGui::setSessionConfig(QStringLiteral("dolphin"), QStringLiteral("dolphin"));
758 KConfig *config = KConfigGui::sessionConfig();
759 saveGlobalProperties(config);
760 savePropertiesInternal(config, 1);
761
762 auto future = QtConcurrent::run([config]() {
763 config->sync();
764 });
765 m_sessionSaveWatcher->setFuture(future);
766 }
767 }
768
769 void DolphinMainWindow::setSessionAutoSaveEnabled(bool enable)
770 {
771 if (enable) {
772 if (!m_sessionSaveTimer) {
773 m_sessionSaveTimer = new QTimer(this);
774 m_sessionSaveWatcher = new QFutureWatcher<void>(this);
775 m_sessionSaveTimer->setSingleShot(true);
776 m_sessionSaveTimer->setInterval(22000);
777
778 connect(m_sessionSaveTimer, &QTimer::timeout, this, &DolphinMainWindow::slotSaveSession);
779 }
780
781 connect(m_tabWidget, &DolphinTabWidget::urlChanged, m_sessionSaveTimer, qOverload<>(&QTimer::start), Qt::UniqueConnection);
782 connect(m_tabWidget, &DolphinTabWidget::tabCountChanged, m_sessionSaveTimer, qOverload<>(&QTimer::start), Qt::UniqueConnection);
783 connect(m_tabWidget, &DolphinTabWidget::activeViewChanged, m_sessionSaveTimer, qOverload<>(&QTimer::start), Qt::UniqueConnection);
784 } else if (m_sessionSaveTimer) {
785 m_sessionSaveTimer->stop();
786 m_sessionSaveWatcher->disconnect();
787 m_sessionSaveScheduled = false;
788
789 m_sessionSaveWatcher->waitForFinished();
790
791 m_sessionSaveTimer->deleteLater();
792 m_sessionSaveWatcher->deleteLater();
793 m_sessionSaveTimer = nullptr;
794 m_sessionSaveWatcher = nullptr;
795 }
796 }
797
798 void DolphinMainWindow::saveProperties(KConfigGroup &group)
799 {
800 m_tabWidget->saveProperties(group);
801 }
802
803 void DolphinMainWindow::readProperties(const KConfigGroup &group)
804 {
805 m_tabWidget->readProperties(group);
806 }
807
808 void DolphinMainWindow::updateNewMenu()
809 {
810 m_newFileMenu->checkUpToDate();
811 m_newFileMenu->setWorkingDirectory(activeViewContainer()->url());
812 }
813
814 void DolphinMainWindow::createDirectory()
815 {
816 // When creating directory, namejob is being run. In network folders,
817 // this job can take long time, so instead of starting multiple namejobs,
818 // just check if we are already running one. This prevents opening multiple
819 // dialogs. BUG:481401
820 if (!m_newFileMenu->isCreateDirectoryRunning()) {
821 m_newFileMenu->setWorkingDirectory(activeViewContainer()->url());
822 m_newFileMenu->createDirectory();
823 }
824 }
825
826 void DolphinMainWindow::createFile()
827 {
828 // Use the same logic as in createDirectory()
829 if (!m_newFileMenu->isCreateFileRunning()) {
830 m_newFileMenu->setWorkingDirectory(activeViewContainer()->url());
831 m_newFileMenu->createFile();
832 }
833 }
834
835 void DolphinMainWindow::quit()
836 {
837 close();
838 }
839
840 void DolphinMainWindow::showErrorMessage(const QString &message)
841 {
842 m_activeViewContainer->showMessage(message, KMessageWidget::Error);
843 }
844
845 void DolphinMainWindow::slotUndoAvailable(bool available)
846 {
847 QAction *undoAction = actionCollection()->action(KStandardAction::name(KStandardAction::Undo));
848 if (undoAction) {
849 undoAction->setEnabled(available);
850 }
851 }
852
853 void DolphinMainWindow::slotUndoTextChanged(const QString &text)
854 {
855 QAction *undoAction = actionCollection()->action(KStandardAction::name(KStandardAction::Undo));
856 if (undoAction) {
857 undoAction->setText(text);
858 }
859 }
860
861 void DolphinMainWindow::undo()
862 {
863 clearStatusBar();
864 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
865 KIO::FileUndoManager::self()->undo();
866 }
867
868 void DolphinMainWindow::cut()
869 {
870 if (m_activeViewContainer->view()->selectedItems().isEmpty()) {
871 m_activeViewContainer->setSelectionModeEnabled(true, actionCollection(), SelectionMode::BottomBar::Contents::CutContents);
872 } else {
873 m_activeViewContainer->view()->cutSelectedItemsToClipboard();
874 m_activeViewContainer->setSelectionModeEnabled(false);
875 }
876 }
877
878 void DolphinMainWindow::copy()
879 {
880 if (m_activeViewContainer->view()->selectedItems().isEmpty()) {
881 m_activeViewContainer->setSelectionModeEnabled(true, actionCollection(), SelectionMode::BottomBar::Contents::CopyContents);
882 } else {
883 m_activeViewContainer->view()->copySelectedItemsToClipboard();
884 m_activeViewContainer->setSelectionModeEnabled(false);
885 }
886 }
887
888 void DolphinMainWindow::paste()
889 {
890 m_activeViewContainer->view()->paste();
891 }
892
893 void DolphinMainWindow::find()
894 {
895 m_activeViewContainer->setSearchModeEnabled(true);
896 }
897
898 void DolphinMainWindow::updateSearchAction()
899 {
900 QAction *toggleSearchAction = actionCollection()->action(QStringLiteral("toggle_search"));
901 toggleSearchAction->setChecked(m_activeViewContainer->isSearchModeEnabled());
902 }
903
904 void DolphinMainWindow::updatePasteAction()
905 {
906 QAction *pasteAction = actionCollection()->action(KStandardAction::name(KStandardAction::Paste));
907 QPair<bool, QString> pasteInfo = m_activeViewContainer->view()->pasteInfo();
908 pasteAction->setEnabled(pasteInfo.first);
909 m_disabledActionNotifier->setDisabledReason(pasteAction,
910 m_activeViewContainer->rootItem().isWritable()
911 ? i18nc("@info", "Cannot paste: The clipboard is empty.")
912 : i18nc("@info", "Cannot paste: You do not have permission to write into this folder."));
913 pasteAction->setText(pasteInfo.second);
914 }
915
916 void DolphinMainWindow::slotDirectoryLoadingCompleted()
917 {
918 updatePasteAction();
919 }
920
921 void DolphinMainWindow::slotToolBarActionMiddleClicked(QAction *action)
922 {
923 if (action == actionCollection()->action(KStandardAction::name(KStandardAction::Back))) {
924 goBackInNewTab();
925 } else if (action == actionCollection()->action(KStandardAction::name(KStandardAction::Forward))) {
926 goForwardInNewTab();
927 } else if (action == actionCollection()->action(QStringLiteral("go_up"))) {
928 goUpInNewTab();
929 } else if (action == actionCollection()->action(QStringLiteral("go_home"))) {
930 goHomeInNewTab();
931 }
932 }
933
934 QAction *DolphinMainWindow::urlNavigatorHistoryAction(const KUrlNavigator *urlNavigator, int historyIndex, QObject *parent)
935 {
936 const QUrl url = urlNavigator->locationUrl(historyIndex);
937
938 QString text = url.toDisplayString(QUrl::PreferLocalFile);
939
940 if (!urlNavigator->showFullPath()) {
941 const KFilePlacesModel *placesModel = DolphinPlacesModelSingleton::instance().placesModel();
942
943 const QModelIndex closestIdx = placesModel->closestItem(url);
944 if (closestIdx.isValid()) {
945 const QUrl placeUrl = placesModel->url(closestIdx);
946
947 text = placesModel->text(closestIdx);
948
949 QString pathInsidePlace = url.path().mid(placeUrl.path().length());
950
951 if (!pathInsidePlace.isEmpty() && !pathInsidePlace.startsWith(QLatin1Char('/'))) {
952 pathInsidePlace.prepend(QLatin1Char('/'));
953 }
954
955 if (pathInsidePlace != QLatin1Char('/')) {
956 text.append(pathInsidePlace);
957 }
958 }
959 }
960
961 QAction *action = new QAction(QIcon::fromTheme(KIO::iconNameForUrl(url)), text, parent);
962 action->setData(historyIndex);
963 return action;
964 }
965
966 void DolphinMainWindow::slotAboutToShowBackPopupMenu()
967 {
968 const KUrlNavigator *urlNavigator = m_activeViewContainer->urlNavigatorInternalWithHistory();
969 int entries = 0;
970 QMenu *menu = m_backAction->popupMenu();
971 menu->clear();
972 for (int i = urlNavigator->historyIndex() + 1; i < urlNavigator->historySize() && entries < MaxNumberOfNavigationentries; ++i, ++entries) {
973 QAction *action = urlNavigatorHistoryAction(urlNavigator, i, menu);
974 menu->addAction(action);
975 }
976 }
977
978 void DolphinMainWindow::slotGoBack(QAction *action)
979 {
980 int gotoIndex = action->data().value<int>();
981 const KUrlNavigator *urlNavigator = m_activeViewContainer->urlNavigatorInternalWithHistory();
982 for (int i = gotoIndex - urlNavigator->historyIndex(); i > 0; --i) {
983 goBack();
984 }
985 }
986
987 void DolphinMainWindow::slotBackForwardActionMiddleClicked(QAction *action)
988 {
989 if (action) {
990 const KUrlNavigator *urlNavigator = activeViewContainer()->urlNavigatorInternalWithHistory();
991 openNewTab(urlNavigator->locationUrl(action->data().value<int>()));
992 }
993 }
994
995 void DolphinMainWindow::slotAboutToShowForwardPopupMenu()
996 {
997 const KUrlNavigator *urlNavigator = m_activeViewContainer->urlNavigatorInternalWithHistory();
998 int entries = 0;
999 QMenu *menu = m_forwardAction->popupMenu();
1000 menu->clear();
1001 for (int i = urlNavigator->historyIndex() - 1; i >= 0 && entries < MaxNumberOfNavigationentries; --i, ++entries) {
1002 QAction *action = urlNavigatorHistoryAction(urlNavigator, i, menu);
1003 menu->addAction(action);
1004 }
1005 }
1006
1007 void DolphinMainWindow::slotGoForward(QAction *action)
1008 {
1009 int gotoIndex = action->data().value<int>();
1010 const KUrlNavigator *urlNavigator = m_activeViewContainer->urlNavigatorInternalWithHistory();
1011 for (int i = urlNavigator->historyIndex() - gotoIndex; i > 0; --i) {
1012 goForward();
1013 }
1014 }
1015
1016 void DolphinMainWindow::slotSetSelectionMode(bool enabled, SelectionMode::BottomBar::Contents bottomBarContents)
1017 {
1018 m_activeViewContainer->setSelectionModeEnabled(enabled, actionCollection(), bottomBarContents);
1019 }
1020
1021 void DolphinMainWindow::selectAll()
1022 {
1023 clearStatusBar();
1024
1025 // if the URL navigator is editable and focused, select the whole
1026 // URL instead of all items of the view
1027
1028 KUrlNavigator *urlNavigator = m_activeViewContainer->urlNavigator();
1029 QLineEdit *lineEdit = urlNavigator->editor()->lineEdit();
1030 const bool selectUrl = urlNavigator->isUrlEditable() && lineEdit->hasFocus();
1031 if (selectUrl) {
1032 lineEdit->selectAll();
1033 } else {
1034 m_activeViewContainer->view()->selectAll();
1035 }
1036 }
1037
1038 void DolphinMainWindow::invertSelection()
1039 {
1040 clearStatusBar();
1041 m_activeViewContainer->view()->invertSelection();
1042 }
1043
1044 void DolphinMainWindow::toggleSplitView()
1045 {
1046 QUrl newSplitViewUrl;
1047 const KFileItemList list = m_activeViewContainer->view()->selectedItems();
1048 if (list.count() == 1) {
1049 const KFileItem &item = list.first();
1050 newSplitViewUrl = DolphinView::openItemAsFolderUrl(item);
1051 }
1052
1053 DolphinTabPage *tabPage = m_tabWidget->currentTabPage();
1054 tabPage->setSplitViewEnabled(!tabPage->splitViewEnabled(), WithAnimation, newSplitViewUrl);
1055 m_tabWidget->updateTabName(m_tabWidget->indexOf(tabPage));
1056 updateViewActions();
1057 }
1058
1059 void DolphinMainWindow::popoutSplitView()
1060 {
1061 DolphinTabPage *tabPage = m_tabWidget->currentTabPage();
1062 if (!tabPage->splitViewEnabled())
1063 return;
1064 openNewWindow((GeneralSettings::closeActiveSplitView() ? tabPage->activeViewContainer() : tabPage->inactiveViewContainer())->url());
1065 tabPage->setSplitViewEnabled(false, WithAnimation);
1066 updateSplitActions();
1067 }
1068
1069 void DolphinMainWindow::toggleSplitStash()
1070 {
1071 DolphinTabPage *tabPage = m_tabWidget->currentTabPage();
1072 tabPage->setSplitViewEnabled(false, WithAnimation);
1073 tabPage->setSplitViewEnabled(true, WithAnimation, QUrl("stash:/"));
1074 }
1075
1076 void DolphinMainWindow::copyToInactiveSplitView()
1077 {
1078 if (m_activeViewContainer->view()->selectedItems().isEmpty()) {
1079 m_activeViewContainer->setSelectionModeEnabled(true, actionCollection(), SelectionMode::BottomBar::Contents::CopyToOtherViewContents);
1080 } else {
1081 m_tabWidget->copyToInactiveSplitView();
1082 m_activeViewContainer->setSelectionModeEnabled(false);
1083 }
1084 }
1085
1086 void DolphinMainWindow::moveToInactiveSplitView()
1087 {
1088 if (m_activeViewContainer->view()->selectedItems().isEmpty()) {
1089 m_activeViewContainer->setSelectionModeEnabled(true, actionCollection(), SelectionMode::BottomBar::Contents::MoveToOtherViewContents);
1090 } else {
1091 m_tabWidget->moveToInactiveSplitView();
1092 m_activeViewContainer->setSelectionModeEnabled(false);
1093 }
1094 }
1095
1096 void DolphinMainWindow::reloadView()
1097 {
1098 clearStatusBar();
1099 m_activeViewContainer->reload();
1100 m_activeViewContainer->statusBar()->updateSpaceInfo();
1101 }
1102
1103 void DolphinMainWindow::stopLoading()
1104 {
1105 m_activeViewContainer->view()->stopLoading();
1106 }
1107
1108 void DolphinMainWindow::enableStopAction()
1109 {
1110 actionCollection()->action(QStringLiteral("stop"))->setEnabled(true);
1111 }
1112
1113 void DolphinMainWindow::disableStopAction()
1114 {
1115 actionCollection()->action(QStringLiteral("stop"))->setEnabled(false);
1116 }
1117
1118 void DolphinMainWindow::toggleSelectionMode()
1119 {
1120 const bool checked = !m_activeViewContainer->isSelectionModeEnabled();
1121
1122 m_activeViewContainer->setSelectionModeEnabled(checked, actionCollection(), SelectionMode::BottomBar::Contents::GeneralContents);
1123 actionCollection()->action(QStringLiteral("toggle_selection_mode"))->setChecked(checked);
1124 }
1125
1126 void DolphinMainWindow::showFilterBar()
1127 {
1128 m_activeViewContainer->setFilterBarVisible(true);
1129 }
1130
1131 void DolphinMainWindow::toggleFilterBar()
1132 {
1133 const bool checked = !m_activeViewContainer->isFilterBarVisible();
1134 m_activeViewContainer->setFilterBarVisible(checked);
1135
1136 QAction *toggleFilterBarAction = actionCollection()->action(QStringLiteral("toggle_filter"));
1137 toggleFilterBarAction->setChecked(checked);
1138 }
1139
1140 void DolphinMainWindow::toggleEditLocation()
1141 {
1142 clearStatusBar();
1143
1144 QAction *action = actionCollection()->action(QStringLiteral("editable_location"));
1145 KUrlNavigator *urlNavigator = m_activeViewContainer->urlNavigator();
1146 urlNavigator->setUrlEditable(action->isChecked());
1147 }
1148
1149 void DolphinMainWindow::replaceLocation()
1150 {
1151 KUrlNavigator *navigator = m_activeViewContainer->urlNavigator();
1152 QLineEdit *lineEdit = navigator->editor()->lineEdit();
1153
1154 // If the text field currently has focus and everything is selected,
1155 // pressing the keyboard shortcut returns the whole thing to breadcrumb mode
1156 // and goes back to the view, just like how it was before this action was triggered the first time.
1157 if (navigator->isUrlEditable() && lineEdit->hasFocus() && lineEdit->selectedText() == lineEdit->text()) {
1158 navigator->setUrlEditable(false);
1159 m_activeViewContainer->view()->setFocus();
1160 } else {
1161 navigator->setUrlEditable(true);
1162 navigator->setFocus();
1163 lineEdit->selectAll();
1164 }
1165 }
1166
1167 void DolphinMainWindow::togglePanelLockState()
1168 {
1169 const bool newLockState = !GeneralSettings::lockPanels();
1170 const auto childrenObjects = children();
1171 for (QObject *child : childrenObjects) {
1172 DolphinDockWidget *dock = qobject_cast<DolphinDockWidget *>(child);
1173 if (dock) {
1174 dock->setLocked(newLockState);
1175 }
1176 }
1177
1178 DolphinPlacesModelSingleton::instance().placesModel()->setPanelsLocked(newLockState);
1179
1180 GeneralSettings::setLockPanels(newLockState);
1181 }
1182
1183 void DolphinMainWindow::slotTerminalPanelVisibilityChanged(bool visible)
1184 {
1185 if (!visible && m_activeViewContainer) {
1186 m_activeViewContainer->view()->setFocus();
1187 }
1188 // Putting focus to the Terminal is not handled here but in TerminalPanel::showEvent().
1189 }
1190
1191 void DolphinMainWindow::slotPlacesPanelVisibilityChanged(bool visible)
1192 {
1193 if (!visible && m_activeViewContainer) {
1194 m_activeViewContainer->view()->setFocus();
1195 return;
1196 }
1197 m_placesPanel->setFocus();
1198 }
1199
1200 void DolphinMainWindow::goBack()
1201 {
1202 DolphinUrlNavigator *urlNavigator = m_activeViewContainer->urlNavigatorInternalWithHistory();
1203 urlNavigator->goBack();
1204
1205 if (urlNavigator->locationState().isEmpty()) {
1206 // An empty location state indicates a redirection URL,
1207 // which must be skipped too
1208 urlNavigator->goBack();
1209 }
1210 }
1211
1212 void DolphinMainWindow::goForward()
1213 {
1214 m_activeViewContainer->urlNavigatorInternalWithHistory()->goForward();
1215 }
1216
1217 void DolphinMainWindow::goUp()
1218 {
1219 m_activeViewContainer->urlNavigatorInternalWithHistory()->goUp();
1220 }
1221
1222 void DolphinMainWindow::goHome()
1223 {
1224 m_activeViewContainer->urlNavigatorInternalWithHistory()->goHome();
1225 }
1226
1227 void DolphinMainWindow::goBackInNewTab()
1228 {
1229 const KUrlNavigator *urlNavigator = activeViewContainer()->urlNavigatorInternalWithHistory();
1230 const int index = urlNavigator->historyIndex() + 1;
1231 openNewTab(urlNavigator->locationUrl(index));
1232 }
1233
1234 void DolphinMainWindow::goForwardInNewTab()
1235 {
1236 const KUrlNavigator *urlNavigator = activeViewContainer()->urlNavigatorInternalWithHistory();
1237 const int index = urlNavigator->historyIndex() - 1;
1238 openNewTab(urlNavigator->locationUrl(index));
1239 }
1240
1241 void DolphinMainWindow::goUpInNewTab()
1242 {
1243 const QUrl currentUrl = activeViewContainer()->urlNavigator()->locationUrl();
1244 openNewTab(KIO::upUrl(currentUrl));
1245 }
1246
1247 void DolphinMainWindow::goHomeInNewTab()
1248 {
1249 openNewTab(Dolphin::homeUrl());
1250 }
1251
1252 void DolphinMainWindow::compareFiles()
1253 {
1254 const KFileItemList items = m_tabWidget->currentTabPage()->selectedItems();
1255 if (items.count() != 2) {
1256 // The action is disabled in this case, but it could have been triggered
1257 // via D-Bus, see https://bugs.kde.org/show_bug.cgi?id=325517
1258 return;
1259 }
1260
1261 QUrl urlA = items.at(0).url();
1262 QUrl urlB = items.at(1).url();
1263
1264 QString command(QStringLiteral("kompare -c \""));
1265 command.append(urlA.toDisplayString(QUrl::PreferLocalFile));
1266 command.append("\" \"");
1267 command.append(urlB.toDisplayString(QUrl::PreferLocalFile));
1268 command.append('\"');
1269
1270 KIO::CommandLauncherJob *job = new KIO::CommandLauncherJob(command, this);
1271 job->setDesktopName(QStringLiteral("org.kde.kompare"));
1272 job->start();
1273 }
1274
1275 void DolphinMainWindow::toggleShowMenuBar()
1276 {
1277 const bool visible = menuBar()->isVisible();
1278 menuBar()->setVisible(!visible);
1279 }
1280
1281 QPointer<QAction> DolphinMainWindow::preferredSearchTool()
1282 {
1283 m_searchTools.clear();
1284
1285 KService::Ptr kfind = KService::serviceByDesktopName(QStringLiteral("org.kde.kfind"));
1286
1287 if (!kfind) {
1288 return nullptr;
1289 }
1290
1291 auto *action = new QAction(QIcon::fromTheme(kfind->icon()), kfind->name(), this);
1292
1293 connect(action, &QAction::triggered, this, [this, kfind] {
1294 auto *job = new KIO::ApplicationLauncherJob(kfind);
1295 job->setUrls({m_activeViewContainer->url()});
1296 job->start();
1297 });
1298
1299 return action;
1300 }
1301
1302 void DolphinMainWindow::updateOpenPreferredSearchToolAction()
1303 {
1304 QAction *openPreferredSearchTool = actionCollection()->action(QStringLiteral("open_preferred_search_tool"));
1305 if (!openPreferredSearchTool) {
1306 return;
1307 }
1308 QPointer<QAction> tool = preferredSearchTool();
1309 if (tool) {
1310 openPreferredSearchTool->setVisible(true);
1311 openPreferredSearchTool->setText(i18nc("@action:inmenu Tools", "Open %1", tool->text()));
1312 // Only override with the app icon if it is the default, i.e. the user hasn't configured one manually
1313 // https://bugs.kde.org/show_bug.cgi?id=442815
1314 if (openPreferredSearchTool->icon().name() == QLatin1String("search")) {
1315 openPreferredSearchTool->setIcon(tool->icon());
1316 }
1317 } else {
1318 openPreferredSearchTool->setVisible(false);
1319 // still visible in Shortcuts configuration window
1320 openPreferredSearchTool->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool"));
1321 openPreferredSearchTool->setIcon(QIcon::fromTheme(QStringLiteral("search")));
1322 }
1323 }
1324
1325 void DolphinMainWindow::openPreferredSearchTool()
1326 {
1327 QPointer<QAction> tool = preferredSearchTool();
1328 if (tool) {
1329 tool->trigger();
1330 }
1331 }
1332
1333 void DolphinMainWindow::openTerminal()
1334 {
1335 openTerminalJob(m_activeViewContainer->url());
1336 }
1337
1338 void DolphinMainWindow::openTerminalHere()
1339 {
1340 QList<QUrl> urls = {};
1341
1342 const auto selectedItems = m_activeViewContainer->view()->selectedItems();
1343 for (const KFileItem &item : selectedItems) {
1344 QUrl url = item.targetUrl();
1345 if (item.isFile()) {
1346 url.setPath(QFileInfo(url.path()).absolutePath());
1347 }
1348 if (!urls.contains(url)) {
1349 urls << url;
1350 }
1351 }
1352
1353 // No items are selected. Open a terminal window for the current location.
1354 if (urls.count() == 0) {
1355 openTerminal();
1356 return;
1357 }
1358
1359 if (urls.count() > 5) {
1360 QString question = i18np("Are you sure you want to open 1 terminal window?", "Are you sure you want to open %1 terminal windows?", urls.count());
1361 const int answer = KMessageBox::warningContinueCancel(
1362 this,
1363 question,
1364 {},
1365 KGuiItem(i18ncp("@action:button", "Open %1 Terminal", "Open %1 Terminals", urls.count()), QStringLiteral("utilities-terminal")),
1366 KStandardGuiItem::cancel(),
1367 QStringLiteral("ConfirmOpenManyTerminals"));
1368 if (answer != KMessageBox::PrimaryAction && answer != KMessageBox::Continue) {
1369 return;
1370 }
1371 }
1372
1373 for (const QUrl &url : std::as_const(urls)) {
1374 openTerminalJob(url);
1375 }
1376 }
1377
1378 void DolphinMainWindow::openTerminalJob(const QUrl &url)
1379 {
1380 if (url.isLocalFile()) {
1381 auto job = new KTerminalLauncherJob(QString());
1382 job->setWorkingDirectory(url.toLocalFile());
1383 job->start();
1384 return;
1385 }
1386
1387 // Not a local file, with protocol Class ":local", try stat'ing
1388 if (KProtocolInfo::protocolClass(url.scheme()) == QLatin1String(":local")) {
1389 KIO::StatJob *job = KIO::mostLocalUrl(url);
1390 KJobWidgets::setWindow(job, this);
1391 connect(job, &KJob::result, this, [job]() {
1392 QUrl statUrl;
1393 if (!job->error()) {
1394 statUrl = job->mostLocalUrl();
1395 }
1396
1397 auto job = new KTerminalLauncherJob(QString());
1398 job->setWorkingDirectory(statUrl.isLocalFile() ? statUrl.toLocalFile() : QDir::homePath());
1399 job->start();
1400 });
1401
1402 return;
1403 }
1404
1405 // Nothing worked, just use $HOME
1406 auto job = new KTerminalLauncherJob(QString());
1407 job->setWorkingDirectory(QDir::homePath());
1408 job->start();
1409 }
1410
1411 void DolphinMainWindow::editSettings()
1412 {
1413 if (!m_settingsDialog) {
1414 DolphinViewContainer *container = activeViewContainer();
1415 container->view()->writeSettings();
1416
1417 const QUrl url = container->url();
1418 DolphinSettingsDialog *settingsDialog = new DolphinSettingsDialog(url, this, actionCollection());
1419 connect(settingsDialog, &DolphinSettingsDialog::settingsChanged, this, &DolphinMainWindow::refreshViews);
1420 connect(settingsDialog, &DolphinSettingsDialog::settingsChanged, &DolphinUrlNavigatorsController::slotReadSettings);
1421 settingsDialog->setAttribute(Qt::WA_DeleteOnClose);
1422 settingsDialog->show();
1423 m_settingsDialog = settingsDialog;
1424 } else {
1425 m_settingsDialog.data()->raise();
1426 }
1427 }
1428
1429 void DolphinMainWindow::handleUrl(const QUrl &url)
1430 {
1431 delete m_lastHandleUrlOpenJob;
1432 m_lastHandleUrlOpenJob = nullptr;
1433
1434 if (url.isLocalFile() && QFileInfo(url.toLocalFile()).isDir()) {
1435 activeViewContainer()->setUrl(url);
1436 } else {
1437 m_lastHandleUrlOpenJob = new KIO::OpenUrlJob(url);
1438 m_lastHandleUrlOpenJob->setUiDelegate(KIO::createDefaultJobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, this));
1439 m_lastHandleUrlOpenJob->setShowOpenOrExecuteDialog(true);
1440
1441 connect(m_lastHandleUrlOpenJob, &KIO::OpenUrlJob::mimeTypeFound, this, [this, url](const QString &mimetype) {
1442 if (mimetype == QLatin1String("inode/directory")) {
1443 // If it's a dir, we'll take it from here
1444 m_lastHandleUrlOpenJob->kill();
1445 m_lastHandleUrlOpenJob = nullptr;
1446 activeViewContainer()->setUrl(url);
1447 }
1448 });
1449
1450 connect(m_lastHandleUrlOpenJob, &KIO::OpenUrlJob::result, this, [this]() {
1451 m_lastHandleUrlOpenJob = nullptr;
1452 });
1453
1454 m_lastHandleUrlOpenJob->start();
1455 }
1456 }
1457
1458 void DolphinMainWindow::slotWriteStateChanged(bool isFolderWritable)
1459 {
1460 // trash:/ is writable but we don't want to create new items in it.
1461 // TODO: remove the trash check once https://phabricator.kde.org/T8234 is implemented
1462 newFileMenu()->setEnabled(isFolderWritable && m_activeViewContainer->url().scheme() != QLatin1String("trash"));
1463 // When the menu is disabled, actions in it are disabled later in the event loop, and we need to set the disabled reason after that.
1464 QTimer::singleShot(0, this, [this]() {
1465 m_disabledActionNotifier->setDisabledReason(actionCollection()->action(QStringLiteral("create_file")),
1466 i18nc("@info", "Cannot create new file: You do not have permission to create items in this folder."));
1467 m_disabledActionNotifier->setDisabledReason(actionCollection()->action(QStringLiteral("create_dir")),
1468 i18nc("@info", "Cannot create new folder: You do not have permission to create items in this folder."));
1469 });
1470 }
1471
1472 void DolphinMainWindow::openContextMenu(const QPoint &pos, const KFileItem &item, const KFileItemList &selectedItems, const QUrl &url)
1473 {
1474 QPointer<DolphinContextMenu> contextMenu = new DolphinContextMenu(this, item, selectedItems, url, &m_fileItemActions);
1475 contextMenu->exec(pos);
1476
1477 // Delete the menu, unless it has been deleted in its own nested event loop already.
1478 if (contextMenu) {
1479 contextMenu->deleteLater();
1480 }
1481 }
1482
1483 QMenu *DolphinMainWindow::createPopupMenu()
1484 {
1485 QMenu *menu = KXmlGuiWindow::createPopupMenu();
1486
1487 menu->addSeparator();
1488 menu->addAction(actionCollection()->action(QStringLiteral("lock_panels")));
1489
1490 return menu;
1491 }
1492
1493 void DolphinMainWindow::updateHamburgerMenu()
1494 {
1495 KActionCollection *ac = actionCollection();
1496 auto hamburgerMenu = static_cast<KHamburgerMenu *>(ac->action(KStandardAction::name(KStandardAction::HamburgerMenu)));
1497 auto menu = hamburgerMenu->menu();
1498 if (!menu) {
1499 menu = new QMenu(this);
1500 hamburgerMenu->setMenu(menu);
1501 hamburgerMenu->hideActionsOf(ac->action(QStringLiteral("basic_actions"))->menu());
1502 hamburgerMenu->hideActionsOf(ac->action(QStringLiteral("zoom"))->menu());
1503 } else {
1504 menu->clear();
1505 }
1506 const QList<QAction *> toolbarActions = toolBar()->actions();
1507
1508 if (!toolBar()->isVisible()) {
1509 // If neither the menu bar nor the toolbar are visible, these actions should be available.
1510 menu->addAction(ac->action(KStandardAction::name(KStandardAction::ShowMenubar)));
1511 menu->addAction(toolBarMenuAction());
1512 menu->addSeparator();
1513 }
1514
1515 // This group of actions (until the next separator) contains all the most basic actions
1516 // necessary to use Dolphin effectively.
1517 menu->addAction(ac->action(QStringLiteral("go_back")));
1518 menu->addAction(ac->action(QStringLiteral("go_forward")));
1519
1520 menu->addMenu(m_newFileMenu->menu());
1521 if (!toolBar()->isVisible() || !toolbarActions.contains(ac->action(QStringLiteral("toggle_selection_mode_tool_bar")))) {
1522 menu->addAction(ac->action(QStringLiteral("toggle_selection_mode")));
1523 }
1524 menu->addAction(ac->action(QStringLiteral("basic_actions")));
1525 menu->addAction(ac->action(KStandardAction::name(KStandardAction::Undo)));
1526 if (!toolBar()->isVisible()
1527 || (!toolbarActions.contains(ac->action(QStringLiteral("toggle_search")))
1528 && !toolbarActions.contains(ac->action(QStringLiteral("open_preferred_search_tool"))))) {
1529 menu->addAction(ac->action(KStandardAction::name(KStandardAction::Find)));
1530 // This way a search action will only be added if none of the three available
1531 // search actions is present on the toolbar.
1532 }
1533 if (!toolBar()->isVisible() || !toolbarActions.contains(ac->action(QStringLiteral("toggle_filter")))) {
1534 menu->addAction(ac->action(QStringLiteral("show_filter_bar")));
1535 // This way a filter action will only be added if none of the two available
1536 // filter actions is present on the toolbar.
1537 }
1538 menu->addSeparator();
1539
1540 // The second group of actions (up until the next separator) contains actions for opening
1541 // additional views to interact with the file system.
1542 menu->addAction(ac->action(QStringLiteral("file_new")));
1543 menu->addAction(ac->action(QStringLiteral("new_tab")));
1544 if (ac->action(QStringLiteral("undo_close_tab"))->isEnabled()) {
1545 menu->addAction(ac->action(QStringLiteral("closed_tabs")));
1546 }
1547 menu->addAction(ac->action(QStringLiteral("open_terminal")));
1548 menu->addSeparator();
1549
1550 // The third group contains actions to change what one sees in the view
1551 // and to change the more general UI.
1552 if (!toolBar()->isVisible()
1553 || (!toolbarActions.contains(ac->action(QStringLiteral("icons"))) && !toolbarActions.contains(ac->action(QStringLiteral("compact")))
1554 && !toolbarActions.contains(ac->action(QStringLiteral("details"))) && !toolbarActions.contains(ac->action(QStringLiteral("view_mode"))))) {
1555 menu->addAction(ac->action(QStringLiteral("view_mode")));
1556 }
1557 menu->addAction(ac->action(QStringLiteral("show_hidden_files")));
1558 menu->addAction(ac->action(QStringLiteral("sort")));
1559 menu->addAction(ac->action(QStringLiteral("additional_info")));
1560 if (!GeneralSettings::showStatusBar() || !GeneralSettings::showZoomSlider()) {
1561 menu->addAction(ac->action(QStringLiteral("zoom")));
1562 }
1563 menu->addAction(ac->action(QStringLiteral("panels")));
1564
1565 // The "Configure" menu is not added to the actionCollection() because there is hardly
1566 // a good reason for users to put it on their toolbar.
1567 auto configureMenu = menu->addMenu(QIcon::fromTheme(QStringLiteral("configure")), i18nc("@action:inmenu menu for configure actions", "Configure"));
1568 configureMenu->addAction(ac->action(KStandardAction::name(KStandardAction::SwitchApplicationLanguage)));
1569 configureMenu->addAction(ac->action(KStandardAction::name(KStandardAction::KeyBindings)));
1570 configureMenu->addAction(ac->action(KStandardAction::name(KStandardAction::ConfigureToolbars)));
1571 configureMenu->addAction(ac->action(KStandardAction::name(KStandardAction::Preferences)));
1572 hamburgerMenu->hideActionsOf(configureMenu);
1573 }
1574
1575 void DolphinMainWindow::slotPlaceActivated(const QUrl &url)
1576 {
1577 DolphinViewContainer *view = activeViewContainer();
1578
1579 if (view->url() == url) {
1580 view->clearFilterBar(); // Fixes bug 259382.
1581
1582 // We can end up here if the user clicked a device in the Places Panel
1583 // which had been unmounted earlier, see https://bugs.kde.org/show_bug.cgi?id=161385.
1584 reloadView();
1585
1586 m_activeViewContainer->view()->setFocus(); // We always want the focus on the view after activating a place.
1587 } else {
1588 view->disableUrlNavigatorSelectionRequests();
1589 changeUrl(url);
1590 view->enableUrlNavigatorSelectionRequests();
1591 }
1592 }
1593
1594 void DolphinMainWindow::closedTabsCountChanged(unsigned int count)
1595 {
1596 actionCollection()->action(QStringLiteral("undo_close_tab"))->setEnabled(count > 0);
1597 }
1598
1599 void DolphinMainWindow::activeViewChanged(DolphinViewContainer *viewContainer)
1600 {
1601 DolphinViewContainer *oldViewContainer = m_activeViewContainer;
1602 Q_ASSERT(viewContainer);
1603
1604 m_activeViewContainer = viewContainer;
1605
1606 if (oldViewContainer) {
1607 const QAction *toggleSearchAction = actionCollection()->action(QStringLiteral("toggle_search"));
1608 toggleSearchAction->disconnect(oldViewContainer);
1609
1610 // Disconnect all signals between the old view container (container,
1611 // view and url navigator) and main window.
1612 oldViewContainer->disconnect(this);
1613 oldViewContainer->view()->disconnect(this);
1614 oldViewContainer->urlNavigatorInternalWithHistory()->disconnect(this);
1615 auto navigators = static_cast<DolphinNavigatorsWidgetAction *>(actionCollection()->action(QStringLiteral("url_navigators")));
1616 navigators->primaryUrlNavigator()->disconnect(this);
1617 if (auto secondaryUrlNavigator = navigators->secondaryUrlNavigator()) {
1618 secondaryUrlNavigator->disconnect(this);
1619 }
1620
1621 // except the requestItemInfo so that on hover the information panel can still be updated
1622 connect(oldViewContainer->view(), &DolphinView::requestItemInfo, this, &DolphinMainWindow::requestItemInfo);
1623
1624 // Disconnect other slots.
1625 disconnect(oldViewContainer,
1626 &DolphinViewContainer::selectionModeChanged,
1627 actionCollection()->action(QStringLiteral("toggle_selection_mode")),
1628 &QAction::setChecked);
1629 }
1630
1631 connectViewSignals(viewContainer);
1632
1633 m_actionHandler->setCurrentView(viewContainer->view());
1634
1635 updateHistory();
1636 updateFileAndEditActions();
1637 updatePasteAction();
1638 updateViewActions();
1639 updateGoActions();
1640 updateSearchAction();
1641
1642 const QUrl url = viewContainer->url();
1643 Q_EMIT urlChanged(url);
1644 }
1645
1646 void DolphinMainWindow::tabCountChanged(int count)
1647 {
1648 const bool enableTabActions = (count > 1);
1649 for (int i = 0; i < MaxActivateTabShortcuts; ++i) {
1650 actionCollection()->action(QStringLiteral("activate_tab_%1").arg(i))->setEnabled(enableTabActions);
1651 }
1652 actionCollection()->action(QStringLiteral("activate_last_tab"))->setEnabled(enableTabActions);
1653 actionCollection()->action(QStringLiteral("activate_next_tab"))->setEnabled(enableTabActions);
1654 actionCollection()->action(QStringLiteral("activate_prev_tab"))->setEnabled(enableTabActions);
1655 }
1656
1657 void DolphinMainWindow::updateWindowTitle()
1658 {
1659 const QString newTitle = m_activeViewContainer->captionWindowTitle();
1660 if (windowTitle() != newTitle) {
1661 setWindowTitle(newTitle);
1662 }
1663 }
1664
1665 void DolphinMainWindow::slotStorageTearDownFromPlacesRequested(const QString &mountPath)
1666 {
1667 connect(m_placesPanel, &PlacesPanel::storageTearDownSuccessful, this, [this, mountPath]() {
1668 setViewsToHomeIfMountPathOpen(mountPath);
1669 });
1670
1671 if (m_terminalPanel && m_terminalPanel->currentWorkingDirectoryIsChildOf(mountPath)) {
1672 m_tearDownFromPlacesRequested = true;
1673 m_terminalPanel->goHome();
1674 // m_placesPanel->proceedWithTearDown() will be called in slotTerminalDirectoryChanged
1675 } else {
1676 m_placesPanel->proceedWithTearDown();
1677 }
1678 }
1679
1680 void DolphinMainWindow::slotStorageTearDownExternallyRequested(const QString &mountPath)
1681 {
1682 connect(m_placesPanel, &PlacesPanel::storageTearDownSuccessful, this, [this, mountPath]() {
1683 setViewsToHomeIfMountPathOpen(mountPath);
1684 });
1685
1686 if (m_terminalPanel && m_terminalPanel->currentWorkingDirectoryIsChildOf(mountPath)) {
1687 m_tearDownFromPlacesRequested = false;
1688 m_terminalPanel->goHome();
1689 }
1690 }
1691
1692 void DolphinMainWindow::slotKeyBindings()
1693 {
1694 KShortcutsDialog dialog(KShortcutsEditor::AllActions, KShortcutsEditor::LetterShortcutsAllowed, this);
1695 dialog.addCollection(actionCollection());
1696 if (m_terminalPanel) {
1697 KActionCollection *konsolePartActionCollection = m_terminalPanel->actionCollection();
1698 if (konsolePartActionCollection) {
1699 dialog.addCollection(konsolePartActionCollection, QStringLiteral("KonsolePart"));
1700 }
1701 }
1702 dialog.configure();
1703 }
1704
1705 void DolphinMainWindow::setViewsToHomeIfMountPathOpen(const QString &mountPath)
1706 {
1707 const QVector<DolphinViewContainer *> theViewContainers = viewContainers();
1708 for (DolphinViewContainer *viewContainer : theViewContainers) {
1709 if (viewContainer && viewContainer->url().toLocalFile().startsWith(mountPath)) {
1710 viewContainer->setUrl(QUrl::fromLocalFile(QDir::homePath()));
1711 }
1712 }
1713 disconnect(m_placesPanel, &PlacesPanel::storageTearDownSuccessful, nullptr, nullptr);
1714 }
1715
1716 void DolphinMainWindow::setupActions()
1717 {
1718 auto hamburgerMenuAction = KStandardAction::hamburgerMenu(nullptr, nullptr, actionCollection());
1719
1720 // setup 'File' menu
1721 m_newFileMenu = new DolphinNewFileMenu(nullptr, nullptr, this);
1722 actionCollection()->addAction(QStringLiteral("new_menu"), m_newFileMenu);
1723 QMenu *menu = m_newFileMenu->menu();
1724 menu->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1725 menu->setIcon(QIcon::fromTheme(QStringLiteral("list-add")));
1726 m_newFileMenu->setPopupMode(QToolButton::InstantPopup);
1727 connect(menu, &QMenu::aboutToShow, this, &DolphinMainWindow::updateNewMenu);
1728
1729 QAction *newWindow = KStandardAction::openNew(this, &DolphinMainWindow::openNewMainWindow, actionCollection());
1730 newWindow->setText(i18nc("@action:inmenu File", "New &Window"));
1731 newWindow->setToolTip(i18nc("@info", "Open a new Dolphin window"));
1732 newWindow->setWhatsThis(xi18nc("@info:whatsthis",
1733 "This opens a new "
1734 "window just like this one with the current location."
1735 "<nl/>You can drag and drop items between windows."));
1736 newWindow->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
1737
1738 QAction *newTab = actionCollection()->addAction(QStringLiteral("new_tab"));
1739 newTab->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1740 newTab->setText(i18nc("@action:inmenu File", "New Tab"));
1741 newTab->setWhatsThis(xi18nc("@info:whatsthis",
1742 "This opens a new "
1743 "<emphasis>Tab</emphasis> with the current location."
1744 "<nl/>Tabs allow you to quickly switch between multiple locations and views within this window. "
1745 "You can drag and drop items between tabs."));
1746 actionCollection()->setDefaultShortcut(newTab, Qt::CTRL | Qt::Key_T);
1747 connect(newTab, &QAction::triggered, this, &DolphinMainWindow::openNewActivatedTab);
1748
1749 QAction *addToPlaces = actionCollection()->addAction(QStringLiteral("add_to_places"));
1750 addToPlaces->setIcon(QIcon::fromTheme(QStringLiteral("bookmark-new")));
1751 addToPlaces->setText(i18nc("@action:inmenu Add current folder to places", "Add to Places"));
1752 addToPlaces->setWhatsThis(xi18nc("@info:whatsthis",
1753 "This adds the selected folder "
1754 "to the Places panel."));
1755 connect(addToPlaces, &QAction::triggered, this, &DolphinMainWindow::addToPlaces);
1756
1757 QAction *closeTab = KStandardAction::close(m_tabWidget, QOverload<>::of(&DolphinTabWidget::closeTab), actionCollection());
1758 closeTab->setText(i18nc("@action:inmenu File", "Close Tab"));
1759 closeTab->setToolTip(i18nc("@info", "Close Tab"));
1760 closeTab->setWhatsThis(i18nc("@info:whatsthis",
1761 "This closes the "
1762 "currently viewed tab. If no more tabs are left, this closes "
1763 "the whole window instead."));
1764
1765 QAction *quitAction = KStandardAction::quit(this, &DolphinMainWindow::quit, actionCollection());
1766 quitAction->setWhatsThis(i18nc("@info:whatsthis quit", "This closes this window."));
1767
1768 // setup 'Edit' menu
1769 KStandardAction::undo(this, &DolphinMainWindow::undo, actionCollection());
1770
1771 // i18n: This will be the last paragraph for the whatsthis for all three:
1772 // Cut, Copy and Paste
1773 const QString cutCopyPastePara = xi18nc("@info:whatsthis",
1774 "<para><emphasis>Cut, "
1775 "Copy</emphasis> and <emphasis>Paste</emphasis> work between many "
1776 "applications and are among the most used commands. That's why their "
1777 "<emphasis>keyboard shortcuts</emphasis> are prominently placed right "
1778 "next to each other on the keyboard: <shortcut>Ctrl+X</shortcut>, "
1779 "<shortcut>Ctrl+C</shortcut> and <shortcut>Ctrl+V</shortcut>.</para>");
1780 QAction *cutAction = KStandardAction::cut(this, &DolphinMainWindow::cut, actionCollection());
1781 m_actionTextHelper->registerTextWhenNothingIsSelected(cutAction, i18nc("@action", "Cut…"));
1782 cutAction->setWhatsThis(xi18nc("@info:whatsthis cut",
1783 "This copies the items "
1784 "in your current selection to the <emphasis>clipboard</emphasis>.<nl/>"
1785 "Use the <emphasis>Paste</emphasis> action afterwards to copy them from "
1786 "the clipboard to a new location. The items will be removed from their "
1787 "initial location.")
1788 + cutCopyPastePara);
1789 QAction *copyAction = KStandardAction::copy(this, &DolphinMainWindow::copy, actionCollection());
1790 m_actionTextHelper->registerTextWhenNothingIsSelected(copyAction, i18nc("@action", "Copy…"));
1791 copyAction->setWhatsThis(xi18nc("@info:whatsthis copy",
1792 "This copies the "
1793 "items in your current selection to the <emphasis>clipboard</emphasis>."
1794 "<nl/>Use the <emphasis>Paste</emphasis> action afterwards to copy them "
1795 "from the clipboard to a new location.")
1796 + cutCopyPastePara);
1797 QAction *paste = KStandardAction::paste(this, &DolphinMainWindow::paste, actionCollection());
1798 // The text of the paste-action is modified dynamically by Dolphin
1799 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1800 // due to the long text, the text "Paste" is used:
1801 paste->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1802 paste->setWhatsThis(xi18nc("@info:whatsthis paste",
1803 "This copies the items from "
1804 "your <emphasis>clipboard</emphasis> to the currently viewed folder.<nl/>"
1805 "If the items were added to the clipboard by the <emphasis>Cut</emphasis> "
1806 "action they are removed from their old location.")
1807 + cutCopyPastePara);
1808
1809 QAction *copyToOtherViewAction = actionCollection()->addAction(QStringLiteral("copy_to_inactive_split_view"));
1810 copyToOtherViewAction->setText(i18nc("@action:inmenu", "Copy to Other View"));
1811 m_actionTextHelper->registerTextWhenNothingIsSelected(copyToOtherViewAction, i18nc("@action:inmenu", "Copy to Other View…"));
1812 copyToOtherViewAction->setWhatsThis(xi18nc("@info:whatsthis Copy",
1813 "This copies the selected items from "
1814 "the view in focus to the other view. "
1815 "(Only available while in Split View mode.)"));
1816 copyToOtherViewAction->setIcon(QIcon::fromTheme(QStringLiteral("edit-copy")));
1817 copyToOtherViewAction->setIconText(i18nc("@action:inmenu Edit", "Copy to Other View"));
1818 actionCollection()->setDefaultShortcut(copyToOtherViewAction, Qt::SHIFT | Qt::Key_F5);
1819 connect(copyToOtherViewAction, &QAction::triggered, this, &DolphinMainWindow::copyToInactiveSplitView);
1820
1821 QAction *moveToOtherViewAction = actionCollection()->addAction(QStringLiteral("move_to_inactive_split_view"));
1822 moveToOtherViewAction->setText(i18nc("@action:inmenu", "Move to Other View"));
1823 m_actionTextHelper->registerTextWhenNothingIsSelected(moveToOtherViewAction, i18nc("@action:inmenu", "Move to Other View…"));
1824 moveToOtherViewAction->setWhatsThis(xi18nc("@info:whatsthis Move",
1825 "This moves the selected items from "
1826 "the view in focus to the other view. "
1827 "(Only available while in Split View mode.)"));
1828 moveToOtherViewAction->setIcon(QIcon::fromTheme(QStringLiteral("edit-cut")));
1829 moveToOtherViewAction->setIconText(i18nc("@action:inmenu Edit", "Move to Other View"));
1830 actionCollection()->setDefaultShortcut(moveToOtherViewAction, Qt::SHIFT | Qt::Key_F6);
1831 connect(moveToOtherViewAction, &QAction::triggered, this, &DolphinMainWindow::moveToInactiveSplitView);
1832
1833 QAction *showFilterBar = actionCollection()->addAction(QStringLiteral("show_filter_bar"));
1834 showFilterBar->setText(i18nc("@action:inmenu Tools", "Filter…"));
1835 showFilterBar->setToolTip(i18nc("@info:tooltip", "Show Filter Bar"));
1836 showFilterBar->setWhatsThis(xi18nc("@info:whatsthis",
1837 "This opens the "
1838 "<emphasis>Filter Bar</emphasis> at the bottom of the window.<nl/> "
1839 "There you can enter text to filter the files and folders currently displayed. "
1840 "Only those that contain the text in their name will be kept in view."));
1841 showFilterBar->setIcon(QIcon::fromTheme(QStringLiteral("view-filter")));
1842 actionCollection()->setDefaultShortcuts(showFilterBar, {Qt::CTRL | Qt::Key_I, Qt::Key_Slash});
1843 connect(showFilterBar, &QAction::triggered, this, &DolphinMainWindow::showFilterBar);
1844
1845 // toggle_filter acts as a copy of the main showFilterBar to be used mainly
1846 // in the toolbar, with no default shortcut attached, to avoid messing with
1847 // existing workflows (filter bar always open and Ctrl-I to focus)
1848 QAction *toggleFilter = actionCollection()->addAction(QStringLiteral("toggle_filter"));
1849 toggleFilter->setText(i18nc("@action:inmenu", "Toggle Filter Bar"));
1850 toggleFilter->setIconText(i18nc("@action:intoolbar", "Filter"));
1851 toggleFilter->setIcon(showFilterBar->icon());
1852 toggleFilter->setToolTip(showFilterBar->toolTip());
1853 toggleFilter->setWhatsThis(showFilterBar->whatsThis());
1854 toggleFilter->setCheckable(true);
1855 connect(toggleFilter, &QAction::triggered, this, &DolphinMainWindow::toggleFilterBar);
1856
1857 QAction *searchAction = KStandardAction::find(this, &DolphinMainWindow::find, actionCollection());
1858 searchAction->setText(i18n("Search…"));
1859 searchAction->setToolTip(i18nc("@info:tooltip", "Search for files and folders"));
1860 searchAction->setWhatsThis(xi18nc("@info:whatsthis find",
1861 "<para>This helps you "
1862 "find files and folders by opening a <emphasis>search bar</emphasis>. "
1863 "There you can enter search terms and specify settings to find the "
1864 "items you are looking for.</para><para>Use this help again on "
1865 "the search bar so we can have a look at it while the settings are "
1866 "explained.</para>"));
1867
1868 // toggle_search acts as a copy of the main searchAction to be used mainly
1869 // in the toolbar, with no default shortcut attached, to avoid messing with
1870 // existing workflows (search bar always open and Ctrl-F to focus)
1871 QAction *toggleSearchAction = actionCollection()->addAction(QStringLiteral("toggle_search"));
1872 toggleSearchAction->setText(i18nc("@action:inmenu", "Toggle Search Bar"));
1873 toggleSearchAction->setIconText(i18nc("@action:intoolbar", "Search"));
1874 toggleSearchAction->setIcon(searchAction->icon());
1875 toggleSearchAction->setToolTip(searchAction->toolTip());
1876 toggleSearchAction->setWhatsThis(searchAction->whatsThis());
1877 toggleSearchAction->setCheckable(true);
1878
1879 QAction *toggleSelectionModeAction = actionCollection()->addAction(QStringLiteral("toggle_selection_mode"));
1880 // i18n: This action toggles a selection mode.
1881 toggleSelectionModeAction->setText(i18nc("@action:inmenu", "Select Files and Folders"));
1882 // i18n: Opens a selection mode for selecting files/folders.
1883 // The text is kept so unspecific because it will be shown on the toolbar where space is at a premium.
1884 toggleSelectionModeAction->setIconText(i18nc("@action:intoolbar", "Select"));
1885 toggleSelectionModeAction->setWhatsThis(xi18nc(
1886 "@info:whatsthis",
1887 "<para>This application only knows which files or folders should be acted on if they are"
1888 " <emphasis>selected</emphasis> first. Press this to toggle a <emphasis>Selection Mode</emphasis> which makes selecting and deselecting as easy as "
1889 "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."
1890 "</para>"));
1891 toggleSelectionModeAction->setIcon(QIcon::fromTheme(QStringLiteral("quickwizard")));
1892 toggleSelectionModeAction->setCheckable(true);
1893 actionCollection()->setDefaultShortcut(toggleSelectionModeAction, Qt::Key_Space);
1894 connect(toggleSelectionModeAction, &QAction::triggered, this, &DolphinMainWindow::toggleSelectionMode);
1895
1896 // A special version of the toggleSelectionModeAction for the toolbar that also contains a menu
1897 // with the selectAllAction and invertSelectionAction.
1898 auto *toggleSelectionModeToolBarAction =
1899 new KToolBarPopupAction(toggleSelectionModeAction->icon(), toggleSelectionModeAction->iconText(), actionCollection());
1900 toggleSelectionModeToolBarAction->setToolTip(toggleSelectionModeAction->text());
1901 toggleSelectionModeToolBarAction->setWhatsThis(toggleSelectionModeAction->whatsThis());
1902 actionCollection()->addAction(QStringLiteral("toggle_selection_mode_tool_bar"), toggleSelectionModeToolBarAction);
1903 toggleSelectionModeToolBarAction->setCheckable(true);
1904 toggleSelectionModeToolBarAction->setPopupMode(KToolBarPopupAction::DelayedPopup);
1905 connect(toggleSelectionModeToolBarAction, &QAction::triggered, toggleSelectionModeAction, &QAction::trigger);
1906 connect(toggleSelectionModeAction, &QAction::toggled, toggleSelectionModeToolBarAction, &QAction::setChecked);
1907
1908 QAction *selectAllAction = KStandardAction::selectAll(this, &DolphinMainWindow::selectAll, actionCollection());
1909 selectAllAction->setWhatsThis(xi18nc("@info:whatsthis",
1910 "This selects all "
1911 "files and folders in the current location."));
1912
1913 QAction *invertSelection = actionCollection()->addAction(QStringLiteral("invert_selection"));
1914 invertSelection->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1915 invertSelection->setWhatsThis(xi18nc("@info:whatsthis invert",
1916 "This selects all "
1917 "items that you have currently <emphasis>not</emphasis> selected instead."));
1918 invertSelection->setIcon(QIcon::fromTheme(QStringLiteral("edit-select-invert")));
1919 actionCollection()->setDefaultShortcut(invertSelection, Qt::CTRL | Qt::SHIFT | Qt::Key_A);
1920 connect(invertSelection, &QAction::triggered, this, &DolphinMainWindow::invertSelection);
1921
1922 QMenu *toggleSelectionModeActionMenu = new QMenu(this);
1923 toggleSelectionModeActionMenu->addAction(selectAllAction);
1924 toggleSelectionModeActionMenu->addAction(invertSelection);
1925 toggleSelectionModeToolBarAction->setMenu(toggleSelectionModeActionMenu);
1926
1927 // setup 'View' menu
1928 // (note that most of it is set up in DolphinViewActionHandler)
1929
1930 Admin::WorkerIntegration::createActAsAdminAction(actionCollection(), this);
1931
1932 m_splitViewAction = actionCollection()->add<KActionMenu>(QStringLiteral("split_view"));
1933 m_splitViewMenuAction = actionCollection()->addAction(QStringLiteral("split_view_menu"));
1934
1935 m_splitViewAction->setWhatsThis(xi18nc("@info:whatsthis split",
1936 "<para>This presents "
1937 "a second view side-by-side with the current view, so you can see "
1938 "the contents of two folders at once and easily move items between "
1939 "them.</para><para>The view that is not \"in focus\" will be dimmed. "
1940 "</para>Click this button again to close one of the views."));
1941 m_splitViewMenuAction->setWhatsThis(m_splitViewAction->whatsThis());
1942
1943 // only set it for the menu version
1944 actionCollection()->setDefaultShortcut(m_splitViewMenuAction, Qt::Key_F3);
1945
1946 connect(m_splitViewAction, &QAction::triggered, this, &DolphinMainWindow::toggleSplitView);
1947 connect(m_splitViewMenuAction, &QAction::triggered, this, &DolphinMainWindow::toggleSplitView);
1948
1949 QAction *popoutSplit = actionCollection()->addAction(QStringLiteral("popout_split_view"));
1950 popoutSplit->setWhatsThis(xi18nc("@info:whatsthis",
1951 "If the view has been split, this will pop the view in focus "
1952 "out into a new window."));
1953 popoutSplit->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
1954 actionCollection()->setDefaultShortcut(popoutSplit, Qt::SHIFT | Qt::Key_F3);
1955 connect(popoutSplit, &QAction::triggered, this, &DolphinMainWindow::popoutSplitView);
1956
1957 QAction *stashSplit = actionCollection()->addAction(QStringLiteral("split_stash"));
1958 actionCollection()->setDefaultShortcut(stashSplit, Qt::CTRL | Qt::Key_S);
1959 stashSplit->setText(i18nc("@action:intoolbar Stash", "Stash"));
1960 stashSplit->setToolTip(i18nc("@info", "Opens the stash virtual directory in a split window"));
1961 stashSplit->setIcon(QIcon::fromTheme(QStringLiteral("folder-stash")));
1962 stashSplit->setCheckable(false);
1963 QDBusConnectionInterface *sessionInterface = QDBusConnection::sessionBus().interface();
1964 stashSplit->setVisible(sessionInterface && sessionInterface->isServiceRegistered(QStringLiteral("org.kde.kio.StashNotifier")));
1965 connect(stashSplit, &QAction::triggered, this, &DolphinMainWindow::toggleSplitStash);
1966
1967 QAction *redisplay = KStandardAction::redisplay(this, &DolphinMainWindow::reloadView, actionCollection());
1968 redisplay->setToolTip(i18nc("@info:tooltip", "Refresh view"));
1969 redisplay->setWhatsThis(xi18nc("@info:whatsthis refresh",
1970 "<para>This refreshes "
1971 "the folder view.</para>"
1972 "<para>If the contents of this folder have changed, refreshing will re-scan this folder "
1973 "and show you a newly-updated view of the files and folders contained here.</para>"
1974 "<para>If the view is split, this refreshes the one that is currently in focus.</para>"));
1975
1976 QAction *stop = actionCollection()->addAction(QStringLiteral("stop"));
1977 stop->setText(i18nc("@action:inmenu View", "Stop"));
1978 stop->setToolTip(i18nc("@info", "Stop loading"));
1979 stop->setWhatsThis(i18nc("@info", "This stops the loading of the contents of the current folder."));
1980 stop->setIcon(QIcon::fromTheme(QStringLiteral("process-stop")));
1981 connect(stop, &QAction::triggered, this, &DolphinMainWindow::stopLoading);
1982
1983 KToggleAction *editableLocation = actionCollection()->add<KToggleAction>(QStringLiteral("editable_location"));
1984 editableLocation->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1985 editableLocation->setWhatsThis(xi18nc("@info:whatsthis",
1986 "This toggles the <emphasis>Location Bar</emphasis> to be "
1987 "editable so you can directly enter a location you want to go to.<nl/>"
1988 "You can also switch to editing by clicking to the right of the "
1989 "location and switch back by confirming the edited location."));
1990 actionCollection()->setDefaultShortcut(editableLocation, Qt::Key_F6);
1991 connect(editableLocation, &KToggleAction::triggered, this, &DolphinMainWindow::toggleEditLocation);
1992
1993 QAction *replaceLocation = actionCollection()->addAction(QStringLiteral("replace_location"));
1994 replaceLocation->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1995 // i18n: "enter" is used both in the meaning of "writing" and "going to" a new location here.
1996 // Both meanings are useful but not necessary to understand the use of "Replace Location".
1997 // So you might want to be more verbose in your language to convey the meaning but it's up to you.
1998 replaceLocation->setWhatsThis(xi18nc("@info:whatsthis",
1999 "This switches to editing the location and selects it "
2000 "so you can quickly enter a different location."));
2001 actionCollection()->setDefaultShortcuts(replaceLocation, {Qt::CTRL | Qt::Key_L, Qt::ALT | Qt::Key_D});
2002 connect(replaceLocation, &QAction::triggered, this, &DolphinMainWindow::replaceLocation);
2003
2004 // setup 'Go' menu
2005 {
2006 QScopedPointer<QAction> backAction(KStandardAction::back(nullptr, nullptr, nullptr));
2007 m_backAction = new KToolBarPopupAction(backAction->icon(), backAction->text(), actionCollection());
2008 m_backAction->setObjectName(backAction->objectName());
2009 m_backAction->setShortcuts(backAction->shortcuts());
2010 }
2011 m_backAction->setPopupMode(KToolBarPopupAction::DelayedPopup);
2012 connect(m_backAction, &QAction::triggered, this, &DolphinMainWindow::goBack);
2013 connect(m_backAction->popupMenu(), &QMenu::aboutToShow, this, &DolphinMainWindow::slotAboutToShowBackPopupMenu);
2014 connect(m_backAction->popupMenu(), &QMenu::triggered, this, &DolphinMainWindow::slotGoBack);
2015 actionCollection()->addAction(m_backAction->objectName(), m_backAction);
2016
2017 auto backShortcuts = m_backAction->shortcuts();
2018 // Prepend this shortcut, to avoid being hidden by the two-slot UI (#371130)
2019 backShortcuts.prepend(QKeySequence(Qt::Key_Backspace));
2020 actionCollection()->setDefaultShortcuts(m_backAction, backShortcuts);
2021
2022 DolphinRecentTabsMenu *recentTabsMenu = new DolphinRecentTabsMenu(this);
2023 actionCollection()->addAction(QStringLiteral("closed_tabs"), recentTabsMenu);
2024 connect(m_tabWidget, &DolphinTabWidget::rememberClosedTab, recentTabsMenu, &DolphinRecentTabsMenu::rememberClosedTab);
2025 connect(recentTabsMenu, &DolphinRecentTabsMenu::restoreClosedTab, m_tabWidget, &DolphinTabWidget::restoreClosedTab);
2026 connect(recentTabsMenu, &DolphinRecentTabsMenu::closedTabsCountChanged, this, &DolphinMainWindow::closedTabsCountChanged);
2027
2028 QAction *undoCloseTab = actionCollection()->addAction(QStringLiteral("undo_close_tab"));
2029 undoCloseTab->setText(i18nc("@action:inmenu File", "Undo close tab"));
2030 undoCloseTab->setWhatsThis(i18nc("@info:whatsthis undo close tab", "This returns you to the previously closed tab."));
2031 actionCollection()->setDefaultShortcut(undoCloseTab, Qt::CTRL | Qt::SHIFT | Qt::Key_T);
2032 undoCloseTab->setIcon(QIcon::fromTheme(QStringLiteral("edit-undo")));
2033 undoCloseTab->setEnabled(false);
2034 connect(undoCloseTab, &QAction::triggered, recentTabsMenu, &DolphinRecentTabsMenu::undoCloseTab);
2035
2036 auto undoAction = actionCollection()->action(KStandardAction::name(KStandardAction::Undo));
2037 undoAction->setWhatsThis(xi18nc("@info:whatsthis",
2038 "This undoes "
2039 "the last change you made to files or folders.<nl/>"
2040 "Such changes include <interface>creating</interface>, <interface>renaming</interface> "
2041 "and <interface>moving</interface> them to a different location "
2042 "or to the <filename>Trash</filename>. <nl/>Any changes that cannot be undone "
2043 "will ask for your confirmation beforehand."));
2044 undoAction->setEnabled(false); // undo should be disabled by default
2045
2046 {
2047 QScopedPointer<QAction> forwardAction(KStandardAction::forward(nullptr, nullptr, nullptr));
2048 m_forwardAction = new KToolBarPopupAction(forwardAction->icon(), forwardAction->text(), actionCollection());
2049 m_forwardAction->setObjectName(forwardAction->objectName());
2050 m_forwardAction->setShortcuts(forwardAction->shortcuts());
2051 }
2052 m_forwardAction->setPopupMode(KToolBarPopupAction::DelayedPopup);
2053 connect(m_forwardAction, &QAction::triggered, this, &DolphinMainWindow::goForward);
2054 connect(m_forwardAction->popupMenu(), &QMenu::aboutToShow, this, &DolphinMainWindow::slotAboutToShowForwardPopupMenu);
2055 connect(m_forwardAction->popupMenu(), &QMenu::triggered, this, &DolphinMainWindow::slotGoForward);
2056 actionCollection()->addAction(m_forwardAction->objectName(), m_forwardAction);
2057 actionCollection()->setDefaultShortcuts(m_forwardAction, m_forwardAction->shortcuts());
2058
2059 // enable middle-click to open in a new tab
2060 auto *middleClickEventFilter = new MiddleClickActionEventFilter(this);
2061 connect(middleClickEventFilter, &MiddleClickActionEventFilter::actionMiddleClicked, this, &DolphinMainWindow::slotBackForwardActionMiddleClicked);
2062 m_backAction->popupMenu()->installEventFilter(middleClickEventFilter);
2063 m_forwardAction->popupMenu()->installEventFilter(middleClickEventFilter);
2064 KStandardAction::up(this, &DolphinMainWindow::goUp, actionCollection());
2065 QAction *homeAction = KStandardAction::home(this, &DolphinMainWindow::goHome, actionCollection());
2066 homeAction->setWhatsThis(xi18nc("@info:whatsthis",
2067 "Go to your "
2068 "<filename>Home</filename> folder.<nl/>Every user account "
2069 "has their own <filename>Home</filename> that contains their personal files, "
2070 "as well as hidden folders for their applications' data and configuration files."));
2071
2072 // setup 'Tools' menu
2073 QAction *compareFiles = actionCollection()->addAction(QStringLiteral("compare_files"));
2074 compareFiles->setText(i18nc("@action:inmenu Tools", "Compare Files"));
2075 compareFiles->setIcon(QIcon::fromTheme(QStringLiteral("kompare")));
2076 compareFiles->setEnabled(false);
2077 connect(compareFiles, &QAction::triggered, this, &DolphinMainWindow::compareFiles);
2078
2079 QAction *openPreferredSearchTool = actionCollection()->addAction(QStringLiteral("open_preferred_search_tool"));
2080 openPreferredSearchTool->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool"));
2081 openPreferredSearchTool->setWhatsThis(xi18nc("@info:whatsthis",
2082 "<para>This opens a preferred search tool for the viewed location.</para>"
2083 "<para>Use <emphasis>More Search Tools</emphasis> menu to configure it.</para>"));
2084 openPreferredSearchTool->setIcon(QIcon::fromTheme(QStringLiteral("search")));
2085 actionCollection()->setDefaultShortcut(openPreferredSearchTool, Qt::CTRL | Qt::SHIFT | Qt::Key_F);
2086 connect(openPreferredSearchTool, &QAction::triggered, this, &DolphinMainWindow::openPreferredSearchTool);
2087
2088 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
2089 // Get icon of user default terminal emulator application
2090 const KConfigGroup group(KSharedConfig::openConfig(QStringLiteral("kdeglobals"), KConfig::SimpleConfig), QStringLiteral("General"));
2091 const QString terminalDesktopFilename = group.readEntry("TerminalService");
2092 // Use utilities-terminal icon from theme if readEntry() has failed
2093 const QString terminalIcon = terminalDesktopFilename.isEmpty() ? "utilities-terminal" : KDesktopFile(terminalDesktopFilename).readIcon();
2094
2095 QAction *openTerminal = actionCollection()->addAction(QStringLiteral("open_terminal"));
2096 openTerminal->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
2097 openTerminal->setWhatsThis(xi18nc("@info:whatsthis",
2098 "<para>This opens a <emphasis>terminal</emphasis> application for the viewed location.</para>"
2099 "<para>To learn more about terminals use the help features in the terminal application.</para>"));
2100 openTerminal->setIcon(QIcon::fromTheme(terminalIcon));
2101 actionCollection()->setDefaultShortcut(openTerminal, Qt::SHIFT | Qt::Key_F4);
2102 connect(openTerminal, &QAction::triggered, this, &DolphinMainWindow::openTerminal);
2103
2104 QAction *openTerminalHere = actionCollection()->addAction(QStringLiteral("open_terminal_here"));
2105 // i18n: "Here" refers to the location(s) of the currently selected item(s) or the currently viewed location if nothing is selected.
2106 openTerminalHere->setText(i18nc("@action:inmenu Tools", "Open Terminal Here"));
2107 openTerminalHere->setWhatsThis(xi18nc("@info:whatsthis",
2108 "<para>This opens <emphasis>terminal</emphasis> applications for the selected items' locations.</para>"
2109 "<para>To learn more about terminals use the help features in the terminal application.</para>"));
2110 openTerminalHere->setIcon(QIcon::fromTheme(terminalIcon));
2111 actionCollection()->setDefaultShortcut(openTerminalHere, Qt::SHIFT | Qt::ALT | Qt::Key_F4);
2112 connect(openTerminalHere, &QAction::triggered, this, &DolphinMainWindow::openTerminalHere);
2113 }
2114
2115 // setup 'Bookmarks' menu
2116 KActionMenu *bookmarkMenu = new KActionMenu(i18nc("@title:menu", "&Bookmarks"), this);
2117 bookmarkMenu->setIcon(QIcon::fromTheme(QStringLiteral("bookmarks")));
2118 // Make the toolbar button version work properly on click
2119 bookmarkMenu->setPopupMode(QToolButton::InstantPopup);
2120 m_bookmarkHandler = new DolphinBookmarkHandler(this, actionCollection(), bookmarkMenu->menu(), this);
2121 actionCollection()->addAction(QStringLiteral("bookmarks"), bookmarkMenu);
2122
2123 // setup 'Settings' menu
2124 KToggleAction *showMenuBar = KStandardAction::showMenubar(nullptr, nullptr, actionCollection());
2125 showMenuBar->setWhatsThis(xi18nc("@info:whatsthis",
2126 "<para>This switches between having a <emphasis>Menubar</emphasis> "
2127 "and having an <interface>%1</interface> button. Both "
2128 "contain mostly the same actions and configuration options.</para>"
2129 "<para>The Menubar takes up more space but allows for fast and organized access to all "
2130 "actions an application has to offer.</para><para>The %1 button "
2131 "is simpler and small which makes triggering advanced actions more time consuming.</para>",
2132 hamburgerMenuAction->text().replace('&', "")));
2133 connect(showMenuBar,
2134 &KToggleAction::triggered, // Fixes #286822
2135 this,
2136 &DolphinMainWindow::toggleShowMenuBar,
2137 Qt::QueuedConnection);
2138
2139 KStandardAction::keyBindings(this, &DolphinMainWindow::slotKeyBindings, actionCollection());
2140 KStandardAction::preferences(this, &DolphinMainWindow::editSettings, actionCollection());
2141
2142 // not in menu actions
2143 QList<QKeySequence> nextTabKeys = KStandardShortcut::tabNext();
2144 nextTabKeys.append(QKeySequence(Qt::CTRL | Qt::Key_Tab));
2145
2146 QList<QKeySequence> prevTabKeys = KStandardShortcut::tabPrev();
2147 prevTabKeys.append(QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_Tab));
2148
2149 for (int i = 0; i < MaxActivateTabShortcuts; ++i) {
2150 QAction *activateTab = actionCollection()->addAction(QStringLiteral("activate_tab_%1").arg(i));
2151 activateTab->setText(i18nc("@action:inmenu", "Go to Tab %1", i + 1));
2152 activateTab->setEnabled(false);
2153 connect(activateTab, &QAction::triggered, this, [this, i]() {
2154 m_tabWidget->activateTab(i);
2155 });
2156
2157 // only add default shortcuts for the first 9 tabs regardless of MaxActivateTabShortcuts
2158 if (i < 9) {
2159 actionCollection()->setDefaultShortcut(activateTab, QStringLiteral("Alt+%1").arg(i + 1));
2160 }
2161 }
2162
2163 QAction *activateLastTab = actionCollection()->addAction(QStringLiteral("activate_last_tab"));
2164 activateLastTab->setIconText(i18nc("@action:inmenu", "Last Tab"));
2165 activateLastTab->setText(i18nc("@action:inmenu", "Go to Last Tab"));
2166 activateLastTab->setEnabled(false);
2167 connect(activateLastTab, &QAction::triggered, m_tabWidget, &DolphinTabWidget::activateLastTab);
2168 actionCollection()->setDefaultShortcut(activateLastTab, Qt::ALT | Qt::Key_0);
2169
2170 QAction *activateNextTab = actionCollection()->addAction(QStringLiteral("activate_next_tab"));
2171 activateNextTab->setIconText(i18nc("@action:inmenu", "Next Tab"));
2172 activateNextTab->setText(i18nc("@action:inmenu", "Go to Next Tab"));
2173 activateNextTab->setEnabled(false);
2174 connect(activateNextTab, &QAction::triggered, m_tabWidget, &DolphinTabWidget::activateNextTab);
2175 actionCollection()->setDefaultShortcuts(activateNextTab, nextTabKeys);
2176
2177 QAction *activatePrevTab = actionCollection()->addAction(QStringLiteral("activate_prev_tab"));
2178 activatePrevTab->setIconText(i18nc("@action:inmenu", "Previous Tab"));
2179 activatePrevTab->setText(i18nc("@action:inmenu", "Go to Previous Tab"));
2180 activatePrevTab->setEnabled(false);
2181 connect(activatePrevTab, &QAction::triggered, m_tabWidget, &DolphinTabWidget::activatePrevTab);
2182 actionCollection()->setDefaultShortcuts(activatePrevTab, prevTabKeys);
2183
2184 // for context menu
2185 QAction *showTarget = actionCollection()->addAction(QStringLiteral("show_target"));
2186 showTarget->setText(i18nc("@action:inmenu", "Show Target"));
2187 showTarget->setIcon(QIcon::fromTheme(QStringLiteral("document-open-folder")));
2188 showTarget->setEnabled(false);
2189 connect(showTarget, &QAction::triggered, this, &DolphinMainWindow::showTarget);
2190
2191 QAction *openInNewTab = actionCollection()->addAction(QStringLiteral("open_in_new_tab"));
2192 openInNewTab->setText(i18nc("@action:inmenu", "Open in New Tab"));
2193 openInNewTab->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
2194 connect(openInNewTab, &QAction::triggered, this, &DolphinMainWindow::openInNewTab);
2195
2196 QAction *openInNewTabs = actionCollection()->addAction(QStringLiteral("open_in_new_tabs"));
2197 openInNewTabs->setText(i18nc("@action:inmenu", "Open in New Tabs"));
2198 openInNewTabs->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
2199 connect(openInNewTabs, &QAction::triggered, this, &DolphinMainWindow::openInNewTab);
2200
2201 QAction *openInNewWindow = actionCollection()->addAction(QStringLiteral("open_in_new_window"));
2202 openInNewWindow->setText(i18nc("@action:inmenu", "Open in New Window"));
2203 openInNewWindow->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
2204 connect(openInNewWindow, &QAction::triggered, this, &DolphinMainWindow::openInNewWindow);
2205
2206 QAction *openInSplitViewAction = actionCollection()->addAction(QStringLiteral("open_in_split_view"));
2207 openInSplitViewAction->setText(i18nc("@action:inmenu", "Open in Split View"));
2208 openInSplitViewAction->setIcon(QIcon::fromTheme(QStringLiteral("view-split-left-right")));
2209 connect(openInSplitViewAction, &QAction::triggered, this, [this]() {
2210 openInSplitView(QUrl());
2211 });
2212
2213 m_recentFiles = new KRecentFilesAction(this);
2214 }
2215
2216 void DolphinMainWindow::setupDockWidgets()
2217 {
2218 const bool lock = GeneralSettings::lockPanels();
2219
2220 DolphinPlacesModelSingleton::instance().placesModel()->setPanelsLocked(lock);
2221
2222 KDualAction *lockLayoutAction = actionCollection()->add<KDualAction>(QStringLiteral("lock_panels"));
2223 lockLayoutAction->setActiveText(i18nc("@action:inmenu Panels", "Unlock Panels"));
2224 lockLayoutAction->setActiveIcon(QIcon::fromTheme(QStringLiteral("object-unlocked")));
2225 lockLayoutAction->setInactiveText(i18nc("@action:inmenu Panels", "Lock Panels"));
2226 lockLayoutAction->setInactiveIcon(QIcon::fromTheme(QStringLiteral("object-locked")));
2227 lockLayoutAction->setWhatsThis(xi18nc("@info:whatsthis",
2228 "This "
2229 "switches between having panels <emphasis>locked</emphasis> or "
2230 "<emphasis>unlocked</emphasis>.<nl/>Unlocked panels can be "
2231 "dragged to the other side of the window and have a close "
2232 "button.<nl/>Locked panels are embedded more cleanly."));
2233 lockLayoutAction->setActive(lock);
2234 connect(lockLayoutAction, &KDualAction::triggered, this, &DolphinMainWindow::togglePanelLockState);
2235
2236 // Setup "Information"
2237 DolphinDockWidget *infoDock = new DolphinDockWidget(i18nc("@title:window", "Information"));
2238 infoDock->setLocked(lock);
2239 infoDock->setObjectName(QStringLiteral("infoDock"));
2240 infoDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
2241
2242 #if HAVE_BALOO
2243 InformationPanel *infoPanel = new InformationPanel(infoDock);
2244 infoPanel->setCustomContextMenuActions({lockLayoutAction});
2245 connect(infoPanel, &InformationPanel::urlActivated, this, &DolphinMainWindow::handleUrl);
2246 infoDock->setWidget(infoPanel);
2247
2248 createPanelAction(QIcon::fromTheme(QStringLiteral("documentinfo")), Qt::Key_F11, infoDock, QStringLiteral("show_information_panel"));
2249
2250 addDockWidget(Qt::RightDockWidgetArea, infoDock);
2251 connect(this, &DolphinMainWindow::urlChanged, infoPanel, &InformationPanel::setUrl);
2252 connect(this, &DolphinMainWindow::selectionChanged, infoPanel, &InformationPanel::setSelection);
2253 connect(this, &DolphinMainWindow::requestItemInfo, infoPanel, &InformationPanel::requestDelayedItemInfo);
2254 connect(this, &DolphinMainWindow::fileItemsChanged, infoPanel, &InformationPanel::slotFilesItemChanged);
2255 connect(this, &DolphinMainWindow::settingsChanged, infoPanel, &InformationPanel::readSettings);
2256 #endif
2257
2258 // i18n: This is the last paragraph for the "What's This"-texts of all four panels.
2259 const QString panelWhatsThis = xi18nc("@info:whatsthis",
2260 "<para>To show or "
2261 "hide panels like this go to <interface>Menu|Panels</interface> "
2262 "or <interface>View|Panels</interface>.</para>");
2263 #if HAVE_BALOO
2264 actionCollection()
2265 ->action(QStringLiteral("show_information_panel"))
2266 ->setWhatsThis(xi18nc("@info:whatsthis",
2267 "<para> This toggles the "
2268 "<emphasis>information</emphasis> panel at the right side of the "
2269 "window.</para><para>The panel provides in-depth information "
2270 "about the items your mouse is hovering over or about the selected "
2271 "items. Otherwise it informs you about the currently viewed folder.<nl/>"
2272 "For single items a preview of their contents is provided.</para>"));
2273 #endif
2274 infoDock->setWhatsThis(xi18nc("@info:whatsthis",
2275 "<para>This panel "
2276 "provides in-depth information about the items your mouse is "
2277 "hovering over or about the selected items. Otherwise it informs "
2278 "you about the currently viewed folder.<nl/>For single items a "
2279 "preview of their contents is provided.</para><para>You can configure "
2280 "which and how details are given here by right-clicking.</para>")
2281 + panelWhatsThis);
2282
2283 // Setup "Folders"
2284 DolphinDockWidget *foldersDock = new DolphinDockWidget(i18nc("@title:window", "Folders"));
2285 foldersDock->setLocked(lock);
2286 foldersDock->setObjectName(QStringLiteral("foldersDock"));
2287 foldersDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
2288 FoldersPanel *foldersPanel = new FoldersPanel(foldersDock);
2289 foldersPanel->setCustomContextMenuActions({lockLayoutAction});
2290 foldersDock->setWidget(foldersPanel);
2291
2292 createPanelAction(QIcon::fromTheme(QStringLiteral("folder")), Qt::Key_F7, foldersDock, QStringLiteral("show_folders_panel"));
2293
2294 addDockWidget(Qt::LeftDockWidgetArea, foldersDock);
2295 connect(this, &DolphinMainWindow::urlChanged, foldersPanel, &FoldersPanel::setUrl);
2296 connect(foldersPanel, &FoldersPanel::folderActivated, this, &DolphinMainWindow::changeUrl);
2297 connect(foldersPanel, &FoldersPanel::folderInNewTab, this, &DolphinMainWindow::openNewTab);
2298 connect(foldersPanel, &FoldersPanel::folderInNewActiveTab, this, &DolphinMainWindow::openNewTabAndActivate);
2299 connect(foldersPanel, &FoldersPanel::errorMessage, this, &DolphinMainWindow::showErrorMessage);
2300
2301 actionCollection()
2302 ->action(QStringLiteral("show_folders_panel"))
2303 ->setWhatsThis(xi18nc("@info:whatsthis",
2304 "This toggles the "
2305 "<emphasis>folders</emphasis> panel at the left side of the window."
2306 "<nl/><nl/>It shows the folders of the <emphasis>file system"
2307 "</emphasis> in a <emphasis>tree view</emphasis>."));
2308 foldersDock->setWhatsThis(xi18nc("@info:whatsthis",
2309 "<para>This panel "
2310 "shows the folders of the <emphasis>file system</emphasis> in a "
2311 "<emphasis>tree view</emphasis>.</para><para>Click a folder to go "
2312 "there. Click the arrow to the left of a folder to see its subfolders. "
2313 "This allows quick switching between any folders.</para>")
2314 + panelWhatsThis);
2315
2316 // Setup "Terminal"
2317 #if HAVE_TERMINAL
2318 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
2319 DolphinDockWidget *terminalDock = new DolphinDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
2320 terminalDock->setLocked(lock);
2321 terminalDock->setObjectName(QStringLiteral("terminalDock"));
2322 terminalDock->setContentsMargins(0, 0, 0, 0);
2323 m_terminalPanel = new TerminalPanel(terminalDock);
2324 m_terminalPanel->setCustomContextMenuActions({lockLayoutAction});
2325 terminalDock->setWidget(m_terminalPanel);
2326
2327 connect(m_terminalPanel, &TerminalPanel::hideTerminalPanel, terminalDock, &DolphinDockWidget::hide);
2328 connect(m_terminalPanel, &TerminalPanel::changeUrl, this, &DolphinMainWindow::slotTerminalDirectoryChanged);
2329 connect(terminalDock, &DolphinDockWidget::visibilityChanged, m_terminalPanel, &TerminalPanel::dockVisibilityChanged);
2330 connect(terminalDock, &DolphinDockWidget::visibilityChanged, this, &DolphinMainWindow::slotTerminalPanelVisibilityChanged);
2331
2332 createPanelAction(QIcon::fromTheme(QStringLiteral("dialog-scripts")), Qt::Key_F4, terminalDock, QStringLiteral("show_terminal_panel"));
2333
2334 addDockWidget(Qt::BottomDockWidgetArea, terminalDock);
2335 connect(this, &DolphinMainWindow::urlChanged, m_terminalPanel, &TerminalPanel::setUrl);
2336
2337 if (GeneralSettings::version() < 200) {
2338 terminalDock->hide();
2339 }
2340
2341 actionCollection()
2342 ->action(QStringLiteral("show_terminal_panel"))
2343 ->setWhatsThis(xi18nc("@info:whatsthis",
2344 "<para>This toggles the "
2345 "<emphasis>terminal</emphasis> panel at the bottom of the window."
2346 "<nl/>The location in the terminal will always match the folder "
2347 "view so you can navigate using either.</para><para>The terminal "
2348 "panel is not needed for basic computer usage but can be useful "
2349 "for advanced tasks. To learn more about terminals use the help features "
2350 "in a standalone terminal application like Konsole.</para>"));
2351 terminalDock->setWhatsThis(xi18nc("@info:whatsthis",
2352 "<para>This is "
2353 "the <emphasis>terminal</emphasis> panel. It behaves like a "
2354 "normal terminal but will match the location of the folder view "
2355 "so you can navigate using either.</para><para>The terminal panel "
2356 "is not needed for basic computer usage but can be useful for "
2357 "advanced tasks. To learn more about terminals use the help features in a "
2358 "standalone terminal application like Konsole.</para>")
2359 + panelWhatsThis);
2360
2361 QAction *focusTerminalPanel = actionCollection()->addAction(QStringLiteral("focus_terminal_panel"));
2362 focusTerminalPanel->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
2363 focusTerminalPanel->setToolTip(i18nc("@info:tooltip", "Move keyboard focus to and from the Terminal panel."));
2364 focusTerminalPanel->setIcon(QIcon::fromTheme(QStringLiteral("swap-panels")));
2365 actionCollection()->setDefaultShortcut(focusTerminalPanel, Qt::CTRL | Qt::SHIFT | Qt::Key_F4);
2366 connect(focusTerminalPanel, &QAction::triggered, this, &DolphinMainWindow::toggleTerminalPanelFocus);
2367 } // endif "shell_access" allowed
2368 #endif // HAVE_TERMINAL
2369
2370 if (GeneralSettings::version() < 200) {
2371 infoDock->hide();
2372 foldersDock->hide();
2373 }
2374
2375 // Setup "Places"
2376 DolphinDockWidget *placesDock = new DolphinDockWidget(i18nc("@title:window", "Places"));
2377 placesDock->setLocked(lock);
2378 placesDock->setObjectName(QStringLiteral("placesDock"));
2379 placesDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
2380
2381 m_placesPanel = new PlacesPanel(placesDock);
2382 m_placesPanel->setCustomContextMenuActions({lockLayoutAction});
2383 placesDock->setWidget(m_placesPanel);
2384
2385 createPanelAction(QIcon::fromTheme(QStringLiteral("compass")), Qt::Key_F9, placesDock, QStringLiteral("show_places_panel"));
2386
2387 addDockWidget(Qt::LeftDockWidgetArea, placesDock);
2388 connect(m_placesPanel, &PlacesPanel::placeActivated, this, &DolphinMainWindow::slotPlaceActivated);
2389 connect(m_placesPanel, &PlacesPanel::tabRequested, this, &DolphinMainWindow::openNewTab);
2390 connect(m_placesPanel, &PlacesPanel::activeTabRequested, this, &DolphinMainWindow::openNewTabAndActivate);
2391 connect(m_placesPanel, &PlacesPanel::newWindowRequested, this, [this](const QUrl &url) {
2392 Dolphin::openNewWindow({url}, this);
2393 });
2394 connect(m_placesPanel, &PlacesPanel::openInSplitViewRequested, this, &DolphinMainWindow::openInSplitView);
2395 connect(m_placesPanel, &PlacesPanel::errorMessage, this, &DolphinMainWindow::showErrorMessage);
2396 connect(this, &DolphinMainWindow::urlChanged, m_placesPanel, &PlacesPanel::setUrl);
2397 connect(placesDock, &DolphinDockWidget::visibilityChanged, &DolphinUrlNavigatorsController::slotPlacesPanelVisibilityChanged);
2398 connect(placesDock, &DolphinDockWidget::visibilityChanged, this, &DolphinMainWindow::slotPlacesPanelVisibilityChanged);
2399 connect(this, &DolphinMainWindow::settingsChanged, m_placesPanel, &PlacesPanel::readSettings);
2400 connect(m_placesPanel, &PlacesPanel::storageTearDownRequested, this, &DolphinMainWindow::slotStorageTearDownFromPlacesRequested);
2401 connect(m_placesPanel, &PlacesPanel::storageTearDownExternallyRequested, this, &DolphinMainWindow::slotStorageTearDownExternallyRequested);
2402 DolphinUrlNavigatorsController::slotPlacesPanelVisibilityChanged(m_placesPanel->isVisible());
2403
2404 auto actionShowAllPlaces = new QAction(QIcon::fromTheme(QStringLiteral("view-hidden")), i18nc("@item:inmenu", "Show Hidden Places"), this);
2405 actionShowAllPlaces->setCheckable(true);
2406 actionShowAllPlaces->setDisabled(true);
2407 actionShowAllPlaces->setWhatsThis(i18nc("@info:whatsthis",
2408 "This displays "
2409 "all places in the places panel that have been hidden. They will "
2410 "appear semi-transparent and allow you to uncheck their \"Hide\" property."));
2411
2412 connect(actionShowAllPlaces, &QAction::triggered, this, [this](bool checked) {
2413 m_placesPanel->setShowAll(checked);
2414 });
2415 connect(m_placesPanel, &PlacesPanel::allPlacesShownChanged, actionShowAllPlaces, &QAction::setChecked);
2416
2417 actionCollection()
2418 ->action(QStringLiteral("show_places_panel"))
2419 ->setWhatsThis(xi18nc("@info:whatsthis",
2420 "<para>This toggles the "
2421 "<emphasis>places</emphasis> panel at the left side of the window."
2422 "</para><para>It allows you to go to locations you have "
2423 "bookmarked and to access disk or media attached to the computer "
2424 "or to the network. It also contains sections to find recently "
2425 "saved files or files of a certain type.</para>"));
2426 placesDock->setWhatsThis(xi18nc("@info:whatsthis",
2427 "<para>This is the "
2428 "<emphasis>Places</emphasis> panel. It allows you to go to locations "
2429 "you have bookmarked and to access disk or media attached to the "
2430 "computer or to the network. It also contains sections to find "
2431 "recently saved files or files of a certain type.</para><para>"
2432 "Click on an entry to go there. Click with the right mouse button "
2433 "instead to open any entry in a new tab or new window.</para>"
2434 "<para>New entries can be added by dragging folders onto this panel. "
2435 "Right-click any section or entry to hide it. Right-click an empty "
2436 "space on this panel and select <interface>Show Hidden Places"
2437 "</interface> to display it again.</para>")
2438 + panelWhatsThis);
2439
2440 QAction *focusPlacesPanel = actionCollection()->addAction(QStringLiteral("focus_places_panel"));
2441 focusPlacesPanel->setText(i18nc("@action:inmenu View", "Focus Places Panel"));
2442 focusPlacesPanel->setToolTip(i18nc("@info:tooltip", "Move keyboard focus to and from the Places panel."));
2443 focusPlacesPanel->setIcon(QIcon::fromTheme(QStringLiteral("swap-panels")));
2444 actionCollection()->setDefaultShortcut(focusPlacesPanel, Qt::CTRL | Qt::Key_P);
2445 connect(focusPlacesPanel, &QAction::triggered, this, &DolphinMainWindow::togglePlacesPanelFocus);
2446
2447 // Add actions into the "Panels" menu
2448 KActionMenu *panelsMenu = new KActionMenu(i18nc("@action:inmenu View", "Show Panels"), this);
2449 actionCollection()->addAction(QStringLiteral("panels"), panelsMenu);
2450 panelsMenu->setIcon(QIcon::fromTheme(QStringLiteral("view-sidetree")));
2451 panelsMenu->setPopupMode(QToolButton::InstantPopup);
2452 const KActionCollection *ac = actionCollection();
2453 panelsMenu->addAction(ac->action(QStringLiteral("show_places_panel")));
2454 #if HAVE_BALOO
2455 panelsMenu->addAction(ac->action(QStringLiteral("show_information_panel")));
2456 #endif
2457 panelsMenu->addAction(ac->action(QStringLiteral("show_folders_panel")));
2458 panelsMenu->addAction(ac->action(QStringLiteral("show_terminal_panel")));
2459 panelsMenu->addSeparator();
2460 panelsMenu->addAction(lockLayoutAction);
2461 panelsMenu->addSeparator();
2462 panelsMenu->addAction(actionShowAllPlaces);
2463 panelsMenu->addAction(focusPlacesPanel);
2464 panelsMenu->addAction(ac->action(QStringLiteral("focus_terminal_panel")));
2465
2466 connect(panelsMenu->menu(), &QMenu::aboutToShow, this, [actionShowAllPlaces] {
2467 actionShowAllPlaces->setEnabled(DolphinPlacesModelSingleton::instance().placesModel()->hiddenCount());
2468 });
2469 }
2470
2471 void DolphinMainWindow::updateFileAndEditActions()
2472 {
2473 const KFileItemList list = m_activeViewContainer->view()->selectedItems();
2474 const KActionCollection *col = actionCollection();
2475 KFileItemListProperties capabilitiesSource(list);
2476
2477 QAction *renameAction = col->action(KStandardAction::name(KStandardAction::RenameFile));
2478 QAction *moveToTrashAction = col->action(KStandardAction::name(KStandardAction::MoveToTrash));
2479 QAction *deleteAction = col->action(KStandardAction::name(KStandardAction::DeleteFile));
2480 QAction *cutAction = col->action(KStandardAction::name(KStandardAction::Cut));
2481 QAction *duplicateAction = col->action(QStringLiteral("duplicate")); // see DolphinViewActionHandler
2482 QAction *addToPlacesAction = col->action(QStringLiteral("add_to_places"));
2483 QAction *copyToOtherViewAction = col->action(QStringLiteral("copy_to_inactive_split_view"));
2484 QAction *moveToOtherViewAction = col->action(QStringLiteral("move_to_inactive_split_view"));
2485 QAction *copyLocation = col->action(QStringLiteral("copy_location"));
2486
2487 if (list.isEmpty()) {
2488 stateChanged(QStringLiteral("has_no_selection"));
2489
2490 // All actions that need a selection to function can be enabled because they should trigger selection mode.
2491 renameAction->setEnabled(true);
2492 moveToTrashAction->setEnabled(true);
2493 deleteAction->setEnabled(true);
2494 cutAction->setEnabled(true);
2495 duplicateAction->setEnabled(true);
2496 addToPlacesAction->setEnabled(true);
2497 copyLocation->setEnabled(true);
2498 // Them triggering selection mode and not directly acting on selected items is signified by adding "…" to their text.
2499 m_actionTextHelper->textsWhenNothingIsSelectedEnabled(true);
2500
2501 } else {
2502 m_actionTextHelper->textsWhenNothingIsSelectedEnabled(false);
2503 stateChanged(QStringLiteral("has_selection"));
2504
2505 QAction *deleteWithTrashShortcut = col->action(QStringLiteral("delete_shortcut")); // see DolphinViewActionHandler
2506 QAction *showTarget = col->action(QStringLiteral("show_target"));
2507
2508 if (list.length() == 1 && list.first().isDir()) {
2509 addToPlacesAction->setEnabled(true);
2510 } else {
2511 addToPlacesAction->setEnabled(false);
2512 }
2513
2514 const bool enableMoveToTrash = capabilitiesSource.isLocal() && capabilitiesSource.supportsMoving();
2515
2516 renameAction->setEnabled(capabilitiesSource.supportsMoving());
2517 m_disabledActionNotifier->setDisabledReason(renameAction, i18nc("@info", "Cannot rename: You do not have permission to rename items in this folder."));
2518 deleteAction->setEnabled(capabilitiesSource.supportsDeleting());
2519 m_disabledActionNotifier->setDisabledReason(deleteAction,
2520 i18nc("@info", "Cannot delete: You do not have permission to remove items from this folder."));
2521 cutAction->setEnabled(capabilitiesSource.supportsMoving());
2522 m_disabledActionNotifier->setDisabledReason(cutAction, i18nc("@info", "Cannot cut: You do not have permission to move items from this folder."));
2523 copyLocation->setEnabled(list.length() == 1);
2524 showTarget->setEnabled(list.length() == 1 && list.at(0).isLink());
2525 duplicateAction->setEnabled(capabilitiesSource.supportsWriting());
2526 m_disabledActionNotifier->setDisabledReason(duplicateAction,
2527 i18nc("@info", "Cannot duplicate here: You do not have permission to create items in this folder."));
2528
2529 if (enableMoveToTrash) {
2530 moveToTrashAction->setEnabled(true);
2531 deleteWithTrashShortcut->setEnabled(false);
2532 m_disabledActionNotifier->clearDisabledReason(deleteWithTrashShortcut);
2533 } else {
2534 moveToTrashAction->setEnabled(false);
2535 deleteWithTrashShortcut->setEnabled(capabilitiesSource.supportsDeleting());
2536 m_disabledActionNotifier->setDisabledReason(deleteWithTrashShortcut,
2537 i18nc("@info", "Cannot delete: You do not have permission to remove items from this folder."));
2538 }
2539 }
2540
2541 if (!m_tabWidget->currentTabPage()->splitViewEnabled()) {
2542 // No need to set the disabled reason here, as it's obvious to the user that the reason is the split view being disabled.
2543 copyToOtherViewAction->setEnabled(false);
2544 m_disabledActionNotifier->clearDisabledReason(copyToOtherViewAction);
2545 moveToOtherViewAction->setEnabled(false);
2546 m_disabledActionNotifier->clearDisabledReason(moveToOtherViewAction);
2547 } else if (list.isEmpty()) {
2548 copyToOtherViewAction->setEnabled(false);
2549 m_disabledActionNotifier->setDisabledReason(copyToOtherViewAction, i18nc("@info", "Cannot copy to other view: No files selected."));
2550 moveToOtherViewAction->setEnabled(false);
2551 m_disabledActionNotifier->setDisabledReason(moveToOtherViewAction, i18nc("@info", "Cannot move to other view: No files selected."));
2552 } else {
2553 DolphinTabPage *tabPage = m_tabWidget->currentTabPage();
2554 KFileItem capabilitiesDestination;
2555
2556 if (tabPage->primaryViewActive()) {
2557 capabilitiesDestination = tabPage->secondaryViewContainer()->rootItem();
2558 } else {
2559 capabilitiesDestination = tabPage->primaryViewContainer()->rootItem();
2560 }
2561
2562 const auto destUrl = capabilitiesDestination.url();
2563 const bool allNotTargetOrigin = std::all_of(list.cbegin(), list.cend(), [destUrl](const KFileItem &item) {
2564 return item.url().adjusted(QUrl::RemoveFilename | QUrl::StripTrailingSlash) != destUrl;
2565 });
2566
2567 if (!allNotTargetOrigin) {
2568 copyToOtherViewAction->setEnabled(false);
2569 m_disabledActionNotifier->setDisabledReason(copyToOtherViewAction,
2570 i18nc("@info", "Cannot copy to other view: The other view already contains these items."));
2571 moveToOtherViewAction->setEnabled(false);
2572 m_disabledActionNotifier->setDisabledReason(moveToOtherViewAction,
2573 i18nc("@info", "Cannot move to other view: The other view already contains these items."));
2574 } else if (!capabilitiesDestination.isWritable()) {
2575 copyToOtherViewAction->setEnabled(false);
2576 m_disabledActionNotifier->setDisabledReason(
2577 copyToOtherViewAction,
2578 i18nc("@info", "Cannot copy to other view: You do not have permission to write into the destination folder."));
2579 moveToOtherViewAction->setEnabled(false);
2580 m_disabledActionNotifier->setDisabledReason(
2581 moveToOtherViewAction,
2582 i18nc("@info", "Cannot move to other view: You do not have permission to write into the destination folder."));
2583 } else {
2584 copyToOtherViewAction->setEnabled(true);
2585 moveToOtherViewAction->setEnabled(capabilitiesSource.supportsMoving());
2586 m_disabledActionNotifier->setDisabledReason(
2587 moveToOtherViewAction,
2588 i18nc("@info", "Cannot move to other view: You do not have permission to move items from this folder."));
2589 }
2590 }
2591 }
2592
2593 void DolphinMainWindow::updateViewActions()
2594 {
2595 m_actionHandler->updateViewActions();
2596
2597 QAction *toggleFilterBarAction = actionCollection()->action(QStringLiteral("toggle_filter"));
2598 toggleFilterBarAction->setChecked(m_activeViewContainer->isFilterBarVisible());
2599
2600 updateSplitActions();
2601 }
2602
2603 void DolphinMainWindow::updateGoActions()
2604 {
2605 QAction *goUpAction = actionCollection()->action(KStandardAction::name(KStandardAction::Up));
2606 const QUrl currentUrl = m_activeViewContainer->url();
2607 // I think this is one of the best places to firstly be confronted
2608 // with a file system and its hierarchy. Talking about the root
2609 // directory might seem too much here but it is the question that
2610 // naturally arises in this context.
2611 goUpAction->setWhatsThis(xi18nc("@info:whatsthis",
2612 "<para>Go to "
2613 "the folder that contains the currently viewed one.</para>"
2614 "<para>All files and folders are organized in a hierarchical "
2615 "<emphasis>file system</emphasis>. At the top of this hierarchy is "
2616 "a directory that contains all data connected to this computer"
2617 "—the <emphasis>root directory</emphasis>.</para>"));
2618 goUpAction->setEnabled(KIO::upUrl(currentUrl) != currentUrl);
2619 }
2620
2621 void DolphinMainWindow::refreshViews()
2622 {
2623 m_tabWidget->refreshViews();
2624
2625 if (GeneralSettings::modifiedStartupSettings()) {
2626 updateWindowTitle();
2627 }
2628
2629 updateSplitActions();
2630
2631 Q_EMIT settingsChanged();
2632 }
2633
2634 void DolphinMainWindow::clearStatusBar()
2635 {
2636 m_activeViewContainer->statusBar()->resetToDefaultText();
2637 }
2638
2639 void DolphinMainWindow::connectViewSignals(DolphinViewContainer *container)
2640 {
2641 connect(container, &DolphinViewContainer::showFilterBarChanged, this, &DolphinMainWindow::updateFilterBarAction);
2642 connect(container, &DolphinViewContainer::writeStateChanged, this, &DolphinMainWindow::slotWriteStateChanged);
2643 slotWriteStateChanged(container->view()->isFolderWritable());
2644 connect(container, &DolphinViewContainer::searchModeEnabledChanged, this, &DolphinMainWindow::updateSearchAction);
2645 connect(container, &DolphinViewContainer::captionChanged, this, &DolphinMainWindow::updateWindowTitle);
2646 connect(container, &DolphinViewContainer::tabRequested, this, &DolphinMainWindow::openNewTab);
2647 connect(container, &DolphinViewContainer::activeTabRequested, this, &DolphinMainWindow::openNewTabAndActivate);
2648
2649 const QAction *toggleSearchAction = actionCollection()->action(QStringLiteral("toggle_search"));
2650 connect(toggleSearchAction, &QAction::triggered, container, &DolphinViewContainer::setSearchModeEnabled);
2651
2652 // Make the toggled state of the selection mode actions visually follow the selection mode state of the view.
2653 auto toggleSelectionModeAction = actionCollection()->action(QStringLiteral("toggle_selection_mode"));
2654 toggleSelectionModeAction->setChecked(m_activeViewContainer->isSelectionModeEnabled());
2655 connect(m_activeViewContainer, &DolphinViewContainer::selectionModeChanged, toggleSelectionModeAction, &QAction::setChecked);
2656
2657 const DolphinView *view = container->view();
2658 connect(view, &DolphinView::selectionChanged, this, &DolphinMainWindow::slotSelectionChanged);
2659 connect(view, &DolphinView::requestItemInfo, this, &DolphinMainWindow::requestItemInfo);
2660 connect(view, &DolphinView::fileItemsChanged, this, &DolphinMainWindow::fileItemsChanged);
2661 connect(view, &DolphinView::tabRequested, this, &DolphinMainWindow::openNewTab);
2662 connect(view, &DolphinView::activeTabRequested, this, &DolphinMainWindow::openNewTabAndActivate);
2663 connect(view, &DolphinView::windowRequested, this, &DolphinMainWindow::openNewWindow);
2664 connect(view, &DolphinView::requestContextMenu, this, &DolphinMainWindow::openContextMenu);
2665 connect(view, &DolphinView::directoryLoadingStarted, this, &DolphinMainWindow::enableStopAction);
2666 connect(view, &DolphinView::directoryLoadingCompleted, this, &DolphinMainWindow::disableStopAction);
2667 connect(view, &DolphinView::directoryLoadingCompleted, this, &DolphinMainWindow::slotDirectoryLoadingCompleted);
2668 connect(view, &DolphinView::goBackRequested, this, &DolphinMainWindow::goBack);
2669 connect(view, &DolphinView::goForwardRequested, this, &DolphinMainWindow::goForward);
2670 connect(view, &DolphinView::urlActivated, this, &DolphinMainWindow::handleUrl);
2671 connect(view, &DolphinView::goUpRequested, this, &DolphinMainWindow::goUp);
2672 connect(view, &DolphinView::doubleClickViewBackground, this, &DolphinMainWindow::slotDoubleClickViewBackground);
2673
2674 connect(container->urlNavigatorInternalWithHistory(), &KUrlNavigator::urlChanged, this, &DolphinMainWindow::changeUrl);
2675 connect(container->urlNavigatorInternalWithHistory(), &KUrlNavigator::historyChanged, this, &DolphinMainWindow::updateHistory);
2676
2677 auto navigators = static_cast<DolphinNavigatorsWidgetAction *>(actionCollection()->action(QStringLiteral("url_navigators")));
2678 const KUrlNavigator *navigator =
2679 m_tabWidget->currentTabPage()->primaryViewActive() ? navigators->primaryUrlNavigator() : navigators->secondaryUrlNavigator();
2680
2681 QAction *editableLocactionAction = actionCollection()->action(QStringLiteral("editable_location"));
2682 editableLocactionAction->setChecked(navigator->isUrlEditable());
2683 connect(navigator, &KUrlNavigator::editableStateChanged, this, &DolphinMainWindow::slotEditableStateChanged);
2684 connect(navigator, &KUrlNavigator::tabRequested, this, &DolphinMainWindow::openNewTab);
2685 connect(navigator, &KUrlNavigator::activeTabRequested, this, &DolphinMainWindow::openNewTabAndActivate);
2686 connect(navigator, &KUrlNavigator::newWindowRequested, this, &DolphinMainWindow::openNewWindow);
2687 }
2688
2689 void DolphinMainWindow::updateSplitActions()
2690 {
2691 QAction *popoutSplitAction = actionCollection()->action(QStringLiteral("popout_split_view"));
2692
2693 auto setActionPopupMode = [this](KActionMenu *action, QToolButton::ToolButtonPopupMode popupMode) {
2694 action->setPopupMode(popupMode);
2695 if (auto *buttonForAction = qobject_cast<QToolButton *>(toolBar()->widgetForAction(action))) {
2696 buttonForAction->setPopupMode(popupMode);
2697 }
2698 };
2699
2700 const DolphinTabPage *tabPage = m_tabWidget->currentTabPage();
2701 if (tabPage->splitViewEnabled()) {
2702 if (GeneralSettings::closeActiveSplitView() ? tabPage->primaryViewActive() : !tabPage->primaryViewActive()) {
2703 m_splitViewAction->setText(i18nc("@action:intoolbar Close left view", "Close"));
2704 m_splitViewAction->setToolTip(i18nc("@info", "Close left view"));
2705 m_splitViewAction->setIcon(QIcon::fromTheme(QStringLiteral("view-left-close")));
2706 m_splitViewMenuAction->setText(i18nc("@action:inmenu Close left view", "Close Left View"));
2707
2708 popoutSplitAction->setText(i18nc("@action:intoolbar Move left view to a new window", "Pop out Left View"));
2709 popoutSplitAction->setToolTip(i18nc("@info", "Move left view to a new window"));
2710 } else {
2711 m_splitViewAction->setText(i18nc("@action:intoolbar Close right view", "Close"));
2712 m_splitViewAction->setToolTip(i18nc("@info", "Close right view"));
2713 m_splitViewAction->setIcon(QIcon::fromTheme(QStringLiteral("view-right-close")));
2714 m_splitViewMenuAction->setText(i18nc("@action:inmenu Close left view", "Close Right View"));
2715
2716 popoutSplitAction->setText(i18nc("@action:intoolbar Move right view to a new window", "Pop out Right View"));
2717 popoutSplitAction->setToolTip(i18nc("@info", "Move right view to a new window"));
2718 }
2719 popoutSplitAction->setEnabled(true);
2720 if (!m_splitViewAction->menu()) {
2721 setActionPopupMode(m_splitViewAction, QToolButton::MenuButtonPopup);
2722 m_splitViewAction->setMenu(new QMenu);
2723 m_splitViewAction->addAction(popoutSplitAction);
2724 }
2725 } else {
2726 m_splitViewAction->setText(i18nc("@action:intoolbar Split view", "Split"));
2727 m_splitViewMenuAction->setText(m_splitViewAction->text());
2728 m_splitViewAction->setToolTip(i18nc("@info", "Split view"));
2729 m_splitViewAction->setIcon(QIcon::fromTheme(QStringLiteral("view-split-left-right")));
2730 popoutSplitAction->setText(i18nc("@action:intoolbar Move view in focus to a new window", "Pop out"));
2731 popoutSplitAction->setEnabled(false);
2732 if (m_splitViewAction->menu()) {
2733 m_splitViewAction->removeAction(popoutSplitAction);
2734 m_splitViewAction->menu()->deleteLater();
2735 m_splitViewAction->setMenu(nullptr);
2736 setActionPopupMode(m_splitViewAction, QToolButton::DelayedPopup);
2737 }
2738 }
2739
2740 // Update state from toolbar action
2741 m_splitViewMenuAction->setToolTip(m_splitViewAction->toolTip());
2742 m_splitViewMenuAction->setIcon(m_splitViewAction->icon());
2743 }
2744
2745 void DolphinMainWindow::updateAllowedToolbarAreas()
2746 {
2747 auto navigators = static_cast<DolphinNavigatorsWidgetAction *>(actionCollection()->action(QStringLiteral("url_navigators")));
2748 if (toolBar()->actions().contains(navigators)) {
2749 toolBar()->setAllowedAreas(Qt::TopToolBarArea | Qt::BottomToolBarArea);
2750 if (toolBarArea(toolBar()) == Qt::LeftToolBarArea || toolBarArea(toolBar()) == Qt::RightToolBarArea) {
2751 addToolBar(Qt::TopToolBarArea, toolBar());
2752 }
2753 } else {
2754 toolBar()->setAllowedAreas(Qt::AllToolBarAreas);
2755 }
2756 }
2757
2758 bool DolphinMainWindow::isKompareInstalled() const
2759 {
2760 static bool initialized = false;
2761 static bool installed = false;
2762 if (!initialized) {
2763 // TODO: maybe replace this approach later by using a menu
2764 // plugin like kdiff3plugin.cpp
2765 installed = !QStandardPaths::findExecutable(QStringLiteral("kompare")).isEmpty();
2766 initialized = true;
2767 }
2768 return installed;
2769 }
2770
2771 void DolphinMainWindow::createPanelAction(const QIcon &icon, const QKeySequence &shortcut, QDockWidget *dockWidget, const QString &actionName)
2772 {
2773 auto dockAction = dockWidget->toggleViewAction();
2774 dockAction->setIcon(icon);
2775 dockAction->setEnabled(true);
2776
2777 QAction *panelAction = actionCollection()->addAction(actionName, dockAction);
2778 actionCollection()->setDefaultShortcut(panelAction, shortcut);
2779 }
2780 // clang-format off
2781 void DolphinMainWindow::setupWhatsThis()
2782 {
2783 // main widgets
2784 menuBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2785 "<emphasis>Menubar</emphasis>. It provides access to commands and "
2786 "configuration options. Left-click on any of the menus on this "
2787 "bar to see its contents.</para><para>The Menubar can be hidden "
2788 "by unchecking <interface>Settings|Show Menubar</interface>. Then "
2789 "most of its contents become available through a <interface>Menu"
2790 "</interface> button on the <emphasis>Toolbar</emphasis>.</para>"));
2791 toolBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2792 "<emphasis>Toolbar</emphasis>. It allows quick access to "
2793 "frequently used actions.</para><para>It is highly customizable. "
2794 "All items you see in the <interface>Menu</interface> or "
2795 "in the <interface>Menubar</interface> can be placed on the "
2796 "Toolbar. Just right-click on it and select <interface>Configure "
2797 "Toolbars…</interface> or find this action within the <interface>"
2798 "menu</interface>."
2799 "</para><para>The location of the bar and the style of its "
2800 "buttons can also be changed in the right-click menu. Right-click "
2801 "a button if you want to show or hide its text.</para>"));
2802 m_tabWidget->setWhatsThis(xi18nc("@info:whatsthis main view",
2803 "<para>Here you can see the <emphasis>folders</emphasis> and "
2804 "<emphasis>files</emphasis> that are at the location described in "
2805 "the <interface>Location Bar</interface> above. This area is the "
2806 "central part of this application where you navigate to the files "
2807 "you want to use.</para><para>For an elaborate and general "
2808 "introduction to this application <link "
2809 "url='https://userbase.kde.org/Dolphin/File_Management#Introduction_to_Dolphin'>"
2810 "click here</link>. This will open an introductory article from "
2811 "the <emphasis>KDE UserBase Wiki</emphasis>.</para><para>For brief "
2812 "explanations of all the features of this <emphasis>view</emphasis> "
2813 "<link url='help:/dolphin/dolphin-view.html'>click here</link> "
2814 "instead. This will open a page from the <emphasis>Handbook"
2815 "</emphasis> that covers the basics.</para>"));
2816
2817 // Settings menu
2818 actionCollection()->action(KStandardAction::name(KStandardAction::KeyBindings))
2819 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window "
2820 "that lists the <emphasis>keyboard shortcuts</emphasis>.<nl/>"
2821 "There you can set up key combinations to trigger an action when "
2822 "they are pressed simultaneously. All commands in this application can "
2823 "be triggered this way.</para>"));
2824 actionCollection()->action(KStandardAction::name(KStandardAction::ConfigureToolbars))
2825 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window in which "
2826 "you can change which buttons appear on the <emphasis>Toolbar</emphasis>.</para>"
2827 "<para>All items you see in the <interface>Menu</interface> can also be placed on the Toolbar.</para>"));
2828 actionCollection()->action(KStandardAction::name(KStandardAction::Preferences))
2829 ->setWhatsThis(xi18nc("@info:whatsthis","This opens a window where you can "
2830 "change a multitude of settings for this application. For an explanation "
2831 "of the various settings go to the chapter <emphasis>Configuring Dolphin"
2832 "</emphasis> in <interface>Help|Dolphin Handbook</interface>."));
2833
2834 // Help menu
2835
2836 auto setStandardActionWhatsThis = [this](KStandardAction::StandardAction actionId,
2837 const QString &whatsThis) {
2838 // Check for the existence of an action since it can be restricted through the Kiosk system
2839 if (auto *action = actionCollection()->action(KStandardAction::name(actionId))) {
2840 action->setWhatsThis(whatsThis);
2841 }
2842 };
2843
2844 // i18n: If the external link isn't available in your language it might make
2845 // sense to state the external link's language in brackets to not
2846 // frustrate the user. If there are multiple languages that the user might
2847 // know with a reasonable chance you might want to have 2 external links.
2848 // The same might be true for any external link you translate.
2849 setStandardActionWhatsThis(KStandardAction::HelpContents, xi18nc("@info:whatsthis handbook", "<para>This opens the Handbook for this application. It provides explanations for every part of <emphasis>Dolphin</emphasis>.</para><para>If you want more elaborate introductions to the different features of <emphasis>Dolphin</emphasis> <link url='https://userbase.kde.org/Dolphin/File_Management'>click here</link>. It will open the dedicated page in the KDE UserBase Wiki.</para>"));
2850 // (The i18n call should be completely in the line following the i18n: comment without any line breaks within the i18n call or the comment might not be correctly extracted. See: https://commits.kde.org/kxmlgui/a31135046e1b3335b5d7bbbe6aa9a883ce3284c1 )
2851
2852 setStandardActionWhatsThis(KStandardAction::WhatsThis,
2853 xi18nc("@info:whatsthis whatsthis button",
2854 "<para>This is the button that invokes the help feature you are "
2855 "using right now! Click it, then click any component of this "
2856 "application to ask \"What's this?\" about it. The mouse cursor "
2857 "will change appearance if no help is available for a spot.</para>"
2858 "<para>There are two other ways to get help: "
2859 "The <link url='help:/dolphin/index.html'>Dolphin Handbook</link> and "
2860 "the <link url='https://userbase.kde.org/Dolphin/File_Management'>KDE "
2861 "UserBase Wiki</link>.</para><para>The \"What's this?\" help is "
2862 "missing in most other windows so don't get too used to this.</para>"));
2863
2864 setStandardActionWhatsThis(KStandardAction::ReportBug,
2865 xi18nc("@info:whatsthis","<para>This opens a "
2866 "window that will guide you through reporting errors or flaws "
2867 "in this application or in other KDE software.</para>"
2868 "<para>High-quality bug reports are much appreciated. To learn "
2869 "how to make your bug report as effective as possible "
2870 "<link url='https://community.kde.org/Get_Involved/Bug_Reporting'>"
2871 "click here</link>.</para>"));
2872
2873 setStandardActionWhatsThis(KStandardAction::Donate,
2874 xi18nc("@info:whatsthis", "<para>This opens a "
2875 "<emphasis>web page</emphasis> where you can donate to "
2876 "support the continued work on this application and many "
2877 "other projects by the <emphasis>KDE</emphasis> community.</para>"
2878 "<para>Donating is the easiest and fastest way to efficiently "
2879 "support KDE and its projects. KDE projects are available for "
2880 "free therefore your donation is needed to cover things that "
2881 "require money like servers, contributor meetings, etc.</para>"
2882 "<para><emphasis>KDE e.V.</emphasis> is the non-profit "
2883 "organization behind the KDE community.</para>"));
2884
2885 setStandardActionWhatsThis(KStandardAction::SwitchApplicationLanguage,
2886 xi18nc("@info:whatsthis",
2887 "With this you can change the language this application uses."
2888 "<nl/>You can even set secondary languages which will be used "
2889 "if texts are not available in your preferred language."));
2890
2891 setStandardActionWhatsThis(KStandardAction::AboutApp,
2892 xi18nc("@info:whatsthis","This opens a "
2893 "window that informs you about the version, license, "
2894 "used libraries and maintainers of this application."));
2895
2896 setStandardActionWhatsThis(KStandardAction::AboutKDE,
2897 xi18nc("@info:whatsthis","This opens a "
2898 "window with information about <emphasis>KDE</emphasis>. "
2899 "The KDE community are the people behind this free software."
2900 "<nl/>If you like using this application but don't know "
2901 "about KDE or want to see a cute dragon have a look!"));
2902 }
2903 // clang-format on
2904
2905 bool DolphinMainWindow::addHamburgerMenuToToolbar()
2906 {
2907 QDomDocument domDocument = KXMLGUIClient::domDocument();
2908 if (domDocument.isNull()) {
2909 return false;
2910 }
2911 QDomNode toolbar = domDocument.elementsByTagName(QStringLiteral("ToolBar")).at(0);
2912 if (toolbar.isNull()) {
2913 return false;
2914 }
2915
2916 QDomElement hamburgerMenuElement = domDocument.createElement(QStringLiteral("Action"));
2917 hamburgerMenuElement.setAttribute(QStringLiteral("name"), QStringLiteral("hamburger_menu"));
2918 toolbar.appendChild(hamburgerMenuElement);
2919
2920 KXMLGUIFactory::saveConfigFile(domDocument, xmlFile());
2921 reloadXML();
2922 createGUI();
2923 return true;
2924 // Make sure to also remove the <KXMLGUIFactory> and <QDomDocument> include
2925 // whenever this method is removed (maybe in the year ~2026).
2926 }
2927
2928 // Set a sane initial window size
2929 QSize DolphinMainWindow::sizeHint() const
2930 {
2931 return KXmlGuiWindow::sizeHint().expandedTo(QSize(760, 550));
2932 }
2933
2934 void DolphinMainWindow::saveNewToolbarConfig()
2935 {
2936 KXmlGuiWindow::saveNewToolbarConfig(); // Applies the new config. This has to be called first
2937 // because the rest of this method decides things
2938 // based on the new config.
2939 auto navigators = static_cast<DolphinNavigatorsWidgetAction *>(actionCollection()->action(QStringLiteral("url_navigators")));
2940 if (!toolBar()->actions().contains(navigators)) {
2941 m_tabWidget->currentTabPage()->insertNavigatorsWidget(navigators);
2942 }
2943 updateAllowedToolbarAreas();
2944 (static_cast<KHamburgerMenu *>(actionCollection()->action(KStandardAction::name(KStandardAction::HamburgerMenu))))->hideActionsOf(toolBar());
2945 }
2946
2947 void DolphinMainWindow::toggleTerminalPanelFocus()
2948 {
2949 if (!m_terminalPanel->isVisible()) {
2950 actionCollection()->action(QStringLiteral("show_terminal_panel"))->trigger(); // Also moves focus to the panel.
2951 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
2952 return;
2953 }
2954
2955 if (m_terminalPanel->terminalHasFocus()) {
2956 m_activeViewContainer->view()->setFocus(Qt::FocusReason::ShortcutFocusReason);
2957 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
2958 return;
2959 }
2960
2961 m_terminalPanel->setFocus(Qt::FocusReason::ShortcutFocusReason);
2962 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
2963 }
2964
2965 void DolphinMainWindow::togglePlacesPanelFocus()
2966 {
2967 if (!m_placesPanel->isVisible()) {
2968 actionCollection()->action(QStringLiteral("show_places_panel"))->trigger(); // Also moves focus to the panel.
2969 actionCollection()->action(QStringLiteral("focus_places_panel"))->setText(i18nc("@action:inmenu View", "Defocus Terminal Panel"));
2970 return;
2971 }
2972
2973 if (m_placesPanel->hasFocus()) {
2974 m_activeViewContainer->view()->setFocus(Qt::FocusReason::ShortcutFocusReason);
2975 actionCollection()->action(QStringLiteral("focus_places_panel"))->setText(i18nc("@action:inmenu View", "Focus Places Panel"));
2976 return;
2977 }
2978
2979 m_placesPanel->setFocus(Qt::FocusReason::ShortcutFocusReason);
2980 actionCollection()->action(QStringLiteral("focus_places_panel"))->setText(i18nc("@action:inmenu View", "Defocus Places Panel"));
2981 }
2982
2983 DolphinMainWindow::UndoUiInterface::UndoUiInterface()
2984 : KIO::FileUndoManager::UiInterface()
2985 {
2986 }
2987
2988 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
2989 {
2990 }
2991
2992 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job *job)
2993 {
2994 DolphinMainWindow *mainWin = qobject_cast<DolphinMainWindow *>(parentWidget());
2995 if (mainWin) {
2996 DolphinViewContainer *container = mainWin->activeViewContainer();
2997 container->showMessage(job->errorString(), KMessageWidget::Error);
2998 } else {
2999 KIO::FileUndoManager::UiInterface::jobError(job);
3000 }
3001 }
3002
3003 bool DolphinMainWindow::isUrlOpen(const QString &url)
3004 {
3005 return m_tabWidget->isUrlOpen(QUrl::fromUserInput(url));
3006 }
3007
3008 bool DolphinMainWindow::isItemVisibleInAnyView(const QString &urlOfItem)
3009 {
3010 return m_tabWidget->isItemVisibleInAnyView(QUrl::fromUserInput(urlOfItem));
3011 }
3012
3013 void DolphinMainWindow::slotDoubleClickViewBackground(Qt::MouseButton button)
3014 {
3015 if (button != Qt::MouseButton::LeftButton) {
3016 // only handle left mouse button for now
3017 return;
3018 }
3019
3020 GeneralSettings *settings = GeneralSettings::self();
3021 QString clickAction = settings->doubleClickViewAction();
3022
3023 DolphinView *view = activeViewContainer()->view();
3024 if (view == nullptr || clickAction == "none") {
3025 return;
3026 }
3027
3028 if (clickAction == customCommand) {
3029 // run custom command set by the user
3030 QString path = view->url().toLocalFile();
3031 QString clickCustomAction = settings->doubleClickViewCustomAction();
3032 clickCustomAction.replace("{path}", path.prepend('"').append('"'));
3033
3034 m_job = new KIO::CommandLauncherJob(clickCustomAction);
3035 m_job->setUiDelegate(new KDialogJobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, this));
3036 m_job->start();
3037
3038 } else {
3039 // get the action set by the user and trigger it
3040 const KActionCollection *actions = actionCollection();
3041 QAction *action = actions->action(clickAction);
3042 if (action == nullptr) {
3043 qCWarning(DolphinDebug) << QStringLiteral("Double-click view: action `%1` was not found").arg(clickAction);
3044 return;
3045 }
3046 action->trigger();
3047 }
3048 }
3049
3050 #include "moc_dolphinmainwindow.cpp"