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