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