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