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