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