]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinmainwindow.cpp
Add margins to the zoom menu entry
[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(qobject_cast<KToolBarPopupAction *>(ac->action(QStringLiteral("zoom")))->popupMenu());
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) {
1730 continue;
1731 }
1732 const auto viewPath = viewContainer->url().toLocalFile();
1733 if (viewPath.startsWith(mountPath + QLatin1String("/")) || viewPath == mountPath) {
1734 viewContainer->setUrl(QUrl::fromLocalFile(QDir::homePath()));
1735 }
1736 }
1737 disconnect(m_placesPanel, &PlacesPanel::storageTearDownSuccessful, nullptr, nullptr);
1738 }
1739
1740 void DolphinMainWindow::setupActions()
1741 {
1742 auto hamburgerMenuAction = KStandardAction::hamburgerMenu(nullptr, nullptr, actionCollection());
1743
1744 // setup 'File' menu
1745 m_newFileMenu = new DolphinNewFileMenu(nullptr, nullptr, this);
1746 actionCollection()->addAction(QStringLiteral("new_menu"), m_newFileMenu);
1747 QMenu *menu = m_newFileMenu->menu();
1748 menu->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1749 menu->setIcon(QIcon::fromTheme(QStringLiteral("list-add")));
1750 m_newFileMenu->setPopupMode(QToolButton::InstantPopup);
1751 connect(menu, &QMenu::aboutToShow, this, &DolphinMainWindow::updateNewMenu);
1752
1753 QAction *newWindow = KStandardAction::openNew(this, &DolphinMainWindow::openNewMainWindow, actionCollection());
1754 newWindow->setText(i18nc("@action:inmenu File", "New &Window"));
1755 newWindow->setToolTip(i18nc("@info", "Open a new Dolphin window"));
1756 newWindow->setWhatsThis(xi18nc("@info:whatsthis",
1757 "This opens a new "
1758 "window just like this one with the current location."
1759 "<nl/>You can drag and drop items between windows."));
1760 newWindow->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
1761
1762 QAction *newTab = actionCollection()->addAction(QStringLiteral("new_tab"));
1763 newTab->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1764 newTab->setText(i18nc("@action:inmenu File", "New Tab"));
1765 newTab->setWhatsThis(xi18nc("@info:whatsthis",
1766 "This opens a new "
1767 "<emphasis>Tab</emphasis> with the current location."
1768 "<nl/>Tabs allow you to quickly switch between multiple locations and views within this window. "
1769 "You can drag and drop items between tabs."));
1770 actionCollection()->setDefaultShortcut(newTab, Qt::CTRL | Qt::Key_T);
1771 connect(newTab, &QAction::triggered, this, &DolphinMainWindow::openNewActivatedTab);
1772
1773 QAction *addToPlaces = actionCollection()->addAction(QStringLiteral("add_to_places"));
1774 addToPlaces->setIcon(QIcon::fromTheme(QStringLiteral("bookmark-new")));
1775 addToPlaces->setText(i18nc("@action:inmenu Add current folder to places", "Add to Places"));
1776 addToPlaces->setWhatsThis(xi18nc("@info:whatsthis",
1777 "This adds the selected folder "
1778 "to the Places panel."));
1779 connect(addToPlaces, &QAction::triggered, this, &DolphinMainWindow::addToPlaces);
1780
1781 QAction *closeTab = KStandardAction::close(m_tabWidget, QOverload<>::of(&DolphinTabWidget::closeTab), actionCollection());
1782 closeTab->setText(i18nc("@action:inmenu File", "Close Tab"));
1783 closeTab->setToolTip(i18nc("@info", "Close Tab"));
1784 closeTab->setWhatsThis(i18nc("@info:whatsthis",
1785 "This closes the "
1786 "currently viewed tab. If no more tabs are left, this closes "
1787 "the whole window instead."));
1788
1789 QAction *quitAction = KStandardAction::quit(this, &DolphinMainWindow::quit, actionCollection());
1790 quitAction->setWhatsThis(i18nc("@info:whatsthis quit", "This closes this window."));
1791
1792 // setup 'Edit' menu
1793 KStandardAction::undo(this, &DolphinMainWindow::undo, actionCollection());
1794
1795 // i18n: This will be the last paragraph for the whatsthis for all three:
1796 // Cut, Copy and Paste
1797 const QString cutCopyPastePara = xi18nc("@info:whatsthis",
1798 "<para><emphasis>Cut, "
1799 "Copy</emphasis> and <emphasis>Paste</emphasis> work between many "
1800 "applications and are among the most used commands. That's why their "
1801 "<emphasis>keyboard shortcuts</emphasis> are prominently placed right "
1802 "next to each other on the keyboard: <shortcut>Ctrl+X</shortcut>, "
1803 "<shortcut>Ctrl+C</shortcut> and <shortcut>Ctrl+V</shortcut>.</para>");
1804 QAction *cutAction = KStandardAction::cut(this, &DolphinMainWindow::cut, actionCollection());
1805 m_actionTextHelper->registerTextWhenNothingIsSelected(cutAction, i18nc("@action", "Cut…"));
1806 cutAction->setWhatsThis(xi18nc("@info:whatsthis cut",
1807 "This copies the items "
1808 "in your current selection to the <emphasis>clipboard</emphasis>.<nl/>"
1809 "Use the <emphasis>Paste</emphasis> action afterwards to copy them from "
1810 "the clipboard to a new location. The items will be removed from their "
1811 "initial location.")
1812 + cutCopyPastePara);
1813 QAction *copyAction = KStandardAction::copy(this, &DolphinMainWindow::copy, actionCollection());
1814 m_actionTextHelper->registerTextWhenNothingIsSelected(copyAction, i18nc("@action", "Copy…"));
1815 copyAction->setWhatsThis(xi18nc("@info:whatsthis copy",
1816 "This copies the "
1817 "items in your current selection to the <emphasis>clipboard</emphasis>."
1818 "<nl/>Use the <emphasis>Paste</emphasis> action afterwards to copy them "
1819 "from the clipboard to a new location.")
1820 + cutCopyPastePara);
1821 QAction *paste = KStandardAction::paste(this, &DolphinMainWindow::paste, actionCollection());
1822 // The text of the paste-action is modified dynamically by Dolphin
1823 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1824 // due to the long text, the text "Paste" is used:
1825 paste->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1826 paste->setWhatsThis(xi18nc("@info:whatsthis paste",
1827 "This copies the items from "
1828 "your <emphasis>clipboard</emphasis> to the currently viewed folder.<nl/>"
1829 "If the items were added to the clipboard by the <emphasis>Cut</emphasis> "
1830 "action they are removed from their old location.")
1831 + cutCopyPastePara);
1832
1833 QAction *copyToOtherViewAction = actionCollection()->addAction(QStringLiteral("copy_to_inactive_split_view"));
1834 copyToOtherViewAction->setText(i18nc("@action:inmenu", "Copy to Other View"));
1835 m_actionTextHelper->registerTextWhenNothingIsSelected(copyToOtherViewAction, i18nc("@action:inmenu", "Copy to Other View…"));
1836 copyToOtherViewAction->setWhatsThis(xi18nc("@info:whatsthis Copy",
1837 "This copies the selected items from "
1838 "the view in focus to the other view. "
1839 "(Only available while in Split View mode.)"));
1840 copyToOtherViewAction->setIcon(QIcon::fromTheme(QStringLiteral("edit-copy")));
1841 copyToOtherViewAction->setIconText(i18nc("@action:inmenu Edit", "Copy to Other View"));
1842 actionCollection()->setDefaultShortcut(copyToOtherViewAction, Qt::SHIFT | Qt::Key_F5);
1843 connect(copyToOtherViewAction, &QAction::triggered, this, &DolphinMainWindow::copyToInactiveSplitView);
1844
1845 QAction *moveToOtherViewAction = actionCollection()->addAction(QStringLiteral("move_to_inactive_split_view"));
1846 moveToOtherViewAction->setText(i18nc("@action:inmenu", "Move to Other View"));
1847 m_actionTextHelper->registerTextWhenNothingIsSelected(moveToOtherViewAction, i18nc("@action:inmenu", "Move to Other View…"));
1848 moveToOtherViewAction->setWhatsThis(xi18nc("@info:whatsthis Move",
1849 "This moves the selected items from "
1850 "the view in focus to the other view. "
1851 "(Only available while in Split View mode.)"));
1852 moveToOtherViewAction->setIcon(QIcon::fromTheme(QStringLiteral("edit-cut")));
1853 moveToOtherViewAction->setIconText(i18nc("@action:inmenu Edit", "Move to Other View"));
1854 actionCollection()->setDefaultShortcut(moveToOtherViewAction, Qt::SHIFT | Qt::Key_F6);
1855 connect(moveToOtherViewAction, &QAction::triggered, this, &DolphinMainWindow::moveToInactiveSplitView);
1856
1857 QAction *showFilterBar = actionCollection()->addAction(QStringLiteral("show_filter_bar"));
1858 showFilterBar->setText(i18nc("@action:inmenu Tools", "Filter…"));
1859 showFilterBar->setToolTip(i18nc("@info:tooltip", "Show Filter Bar"));
1860 showFilterBar->setWhatsThis(xi18nc("@info:whatsthis",
1861 "This opens the "
1862 "<emphasis>Filter Bar</emphasis> at the bottom of the window.<nl/> "
1863 "There you can enter text to filter the files and folders currently displayed. "
1864 "Only those that contain the text in their name will be kept in view."));
1865 showFilterBar->setIcon(QIcon::fromTheme(QStringLiteral("view-filter")));
1866 actionCollection()->setDefaultShortcuts(showFilterBar, {Qt::CTRL | Qt::Key_I, Qt::Key_Slash});
1867 connect(showFilterBar, &QAction::triggered, this, &DolphinMainWindow::showFilterBar);
1868
1869 // toggle_filter acts as a copy of the main showFilterBar to be used mainly
1870 // in the toolbar, with no default shortcut attached, to avoid messing with
1871 // existing workflows (filter bar always open and Ctrl-I to focus)
1872 QAction *toggleFilter = actionCollection()->addAction(QStringLiteral("toggle_filter"));
1873 toggleFilter->setText(i18nc("@action:inmenu", "Toggle Filter Bar"));
1874 toggleFilter->setIconText(i18nc("@action:intoolbar", "Filter"));
1875 toggleFilter->setIcon(showFilterBar->icon());
1876 toggleFilter->setToolTip(showFilterBar->toolTip());
1877 toggleFilter->setWhatsThis(showFilterBar->whatsThis());
1878 toggleFilter->setCheckable(true);
1879 connect(toggleFilter, &QAction::triggered, this, &DolphinMainWindow::toggleFilterBar);
1880
1881 QAction *searchAction = KStandardAction::find(this, &DolphinMainWindow::find, actionCollection());
1882 searchAction->setText(i18n("Search…"));
1883 searchAction->setToolTip(i18nc("@info:tooltip", "Search for files and folders"));
1884 searchAction->setWhatsThis(xi18nc("@info:whatsthis find",
1885 "<para>This helps you "
1886 "find files and folders by opening a <emphasis>search bar</emphasis>. "
1887 "There you can enter search terms and specify settings to find the "
1888 "items you are looking for.</para>"));
1889
1890 // toggle_search acts as a copy of the main searchAction to be used mainly
1891 // in the toolbar, with no default shortcut attached, to avoid messing with
1892 // existing workflows (search bar always open and Ctrl-F to focus)
1893 QAction *toggleSearchAction = actionCollection()->addAction(QStringLiteral("toggle_search"));
1894 toggleSearchAction->setText(i18nc("@action:inmenu", "Toggle Search Bar"));
1895 toggleSearchAction->setIconText(i18nc("@action:intoolbar", "Search"));
1896 toggleSearchAction->setIcon(searchAction->icon());
1897 toggleSearchAction->setToolTip(searchAction->toolTip());
1898 toggleSearchAction->setWhatsThis(searchAction->whatsThis());
1899 toggleSearchAction->setCheckable(true);
1900 connect(toggleSearchAction, &QAction::triggered, this, [this](bool checked) {
1901 if (checked) {
1902 find();
1903 } else {
1904 m_activeViewContainer->setSearchBarVisible(false);
1905 }
1906 });
1907
1908 QAction *toggleSelectionModeAction = actionCollection()->addAction(QStringLiteral("toggle_selection_mode"));
1909 // i18n: This action toggles a selection mode.
1910 toggleSelectionModeAction->setText(i18nc("@action:inmenu", "Select Files and Folders"));
1911 // i18n: Opens a selection mode for selecting files/folders.
1912 // The text is kept so unspecific because it will be shown on the toolbar where space is at a premium.
1913 toggleSelectionModeAction->setIconText(i18nc("@action:intoolbar", "Select"));
1914 toggleSelectionModeAction->setWhatsThis(xi18nc(
1915 "@info:whatsthis",
1916 "<para>This application only knows which files or folders should be acted on if they are"
1917 " <emphasis>selected</emphasis> first. Press this to toggle a <emphasis>Selection Mode</emphasis> which makes selecting and deselecting as easy as "
1918 "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."
1919 "</para>"));
1920 toggleSelectionModeAction->setIcon(QIcon::fromTheme(QStringLiteral("quickwizard")));
1921 toggleSelectionModeAction->setCheckable(true);
1922 actionCollection()->setDefaultShortcut(toggleSelectionModeAction, Qt::Key_Space);
1923 connect(toggleSelectionModeAction, &QAction::triggered, this, &DolphinMainWindow::toggleSelectionMode);
1924
1925 // A special version of the toggleSelectionModeAction for the toolbar that also contains a menu
1926 // with the selectAllAction and invertSelectionAction.
1927 auto *toggleSelectionModeToolBarAction =
1928 new KToolBarPopupAction(toggleSelectionModeAction->icon(), toggleSelectionModeAction->iconText(), actionCollection());
1929 toggleSelectionModeToolBarAction->setToolTip(toggleSelectionModeAction->text());
1930 toggleSelectionModeToolBarAction->setWhatsThis(toggleSelectionModeAction->whatsThis());
1931 actionCollection()->addAction(QStringLiteral("toggle_selection_mode_tool_bar"), toggleSelectionModeToolBarAction);
1932 toggleSelectionModeToolBarAction->setCheckable(true);
1933 toggleSelectionModeToolBarAction->setPopupMode(KToolBarPopupAction::DelayedPopup);
1934 connect(toggleSelectionModeToolBarAction, &QAction::triggered, toggleSelectionModeAction, &QAction::trigger);
1935 connect(toggleSelectionModeAction, &QAction::toggled, toggleSelectionModeToolBarAction, &QAction::setChecked);
1936
1937 QAction *selectAllAction = KStandardAction::selectAll(this, &DolphinMainWindow::selectAll, actionCollection());
1938 selectAllAction->setWhatsThis(xi18nc("@info:whatsthis",
1939 "This selects all "
1940 "files and folders in the current location."));
1941
1942 QAction *invertSelection = actionCollection()->addAction(QStringLiteral("invert_selection"));
1943 invertSelection->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1944 invertSelection->setWhatsThis(xi18nc("@info:whatsthis invert",
1945 "This selects all "
1946 "items that you have currently <emphasis>not</emphasis> selected instead."));
1947 invertSelection->setIcon(QIcon::fromTheme(QStringLiteral("edit-select-invert")));
1948 actionCollection()->setDefaultShortcut(invertSelection, Qt::CTRL | Qt::SHIFT | Qt::Key_A);
1949 connect(invertSelection, &QAction::triggered, this, &DolphinMainWindow::invertSelection);
1950
1951 QMenu *toggleSelectionModeActionMenu = new QMenu(this);
1952 toggleSelectionModeActionMenu->addAction(selectAllAction);
1953 toggleSelectionModeActionMenu->addAction(invertSelection);
1954 toggleSelectionModeToolBarAction->setMenu(toggleSelectionModeActionMenu);
1955
1956 // setup 'View' menu
1957 // (note that most of it is set up in DolphinViewActionHandler)
1958
1959 Admin::WorkerIntegration::createActAsAdminAction(actionCollection(), this);
1960
1961 m_splitViewAction = actionCollection()->add<KActionMenu>(QStringLiteral("split_view"));
1962 m_splitViewMenuAction = actionCollection()->addAction(QStringLiteral("split_view_menu"));
1963
1964 m_splitViewAction->setWhatsThis(xi18nc("@info:whatsthis split",
1965 "<para>This presents "
1966 "a second view side-by-side with the current view, so you can see "
1967 "the contents of two folders at once and easily move items between "
1968 "them.</para><para>The view that is not \"in focus\" will be dimmed. "
1969 "</para>Click this button again to close one of the views."));
1970 m_splitViewMenuAction->setWhatsThis(m_splitViewAction->whatsThis());
1971
1972 // only set it for the menu version
1973 actionCollection()->setDefaultShortcut(m_splitViewMenuAction, Qt::Key_F3);
1974
1975 connect(m_splitViewAction, &QAction::triggered, this, &DolphinMainWindow::toggleSplitView);
1976 connect(m_splitViewMenuAction, &QAction::triggered, this, &DolphinMainWindow::toggleSplitView);
1977
1978 QAction *popoutSplit = actionCollection()->addAction(QStringLiteral("popout_split_view"));
1979 popoutSplit->setWhatsThis(xi18nc("@info:whatsthis",
1980 "If the view has been split, this will pop the view in focus "
1981 "out into a new window."));
1982 popoutSplit->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
1983 actionCollection()->setDefaultShortcut(popoutSplit, Qt::SHIFT | Qt::Key_F3);
1984 connect(popoutSplit, &QAction::triggered, this, &DolphinMainWindow::popoutSplitView);
1985
1986 QAction *stashSplit = actionCollection()->addAction(QStringLiteral("split_stash"));
1987 actionCollection()->setDefaultShortcut(stashSplit, Qt::CTRL | Qt::Key_S);
1988 stashSplit->setText(i18nc("@action:intoolbar Stash", "Stash"));
1989 stashSplit->setToolTip(i18nc("@info", "Opens the stash virtual directory in a split window"));
1990 stashSplit->setIcon(QIcon::fromTheme(QStringLiteral("folder-stash")));
1991 stashSplit->setCheckable(false);
1992 QDBusConnectionInterface *sessionInterface = QDBusConnection::sessionBus().interface();
1993 stashSplit->setVisible(sessionInterface && sessionInterface->isServiceRegistered(QStringLiteral("org.kde.kio.StashNotifier")));
1994 connect(stashSplit, &QAction::triggered, this, &DolphinMainWindow::toggleSplitStash);
1995
1996 QAction *redisplay = KStandardAction::redisplay(this, &DolphinMainWindow::reloadView, actionCollection());
1997 redisplay->setToolTip(i18nc("@info:tooltip", "Refresh view"));
1998 redisplay->setWhatsThis(xi18nc("@info:whatsthis refresh",
1999 "<para>This refreshes "
2000 "the folder view.</para>"
2001 "<para>If the contents of this folder have changed, refreshing will re-scan this folder "
2002 "and show you a newly-updated view of the files and folders contained here.</para>"
2003 "<para>If the view is split, this refreshes the one that is currently in focus.</para>"));
2004
2005 QAction *stop = actionCollection()->addAction(QStringLiteral("stop"));
2006 stop->setText(i18nc("@action:inmenu View", "Stop"));
2007 stop->setToolTip(i18nc("@info", "Stop loading"));
2008 stop->setWhatsThis(i18nc("@info", "This stops the loading of the contents of the current folder."));
2009 stop->setIcon(QIcon::fromTheme(QStringLiteral("process-stop")));
2010 connect(stop, &QAction::triggered, this, &DolphinMainWindow::stopLoading);
2011
2012 KToggleAction *editableLocation = actionCollection()->add<KToggleAction>(QStringLiteral("editable_location"));
2013 editableLocation->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
2014 editableLocation->setWhatsThis(xi18nc("@info:whatsthis",
2015 "This toggles the <emphasis>Location Bar</emphasis> to be "
2016 "editable so you can directly enter a location you want to go to.<nl/>"
2017 "You can also switch to editing by clicking to the right of the "
2018 "location and switch back by confirming the edited location."));
2019 actionCollection()->setDefaultShortcut(editableLocation, Qt::Key_F6);
2020 connect(editableLocation, &KToggleAction::triggered, this, &DolphinMainWindow::toggleEditLocation);
2021
2022 QAction *replaceLocation = actionCollection()->addAction(QStringLiteral("replace_location"));
2023 replaceLocation->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
2024 // i18n: "enter" is used both in the meaning of "writing" and "going to" a new location here.
2025 // Both meanings are useful but not necessary to understand the use of "Replace Location".
2026 // So you might want to be more verbose in your language to convey the meaning but it's up to you.
2027 replaceLocation->setWhatsThis(xi18nc("@info:whatsthis",
2028 "This switches to editing the location and selects it "
2029 "so you can quickly enter a different location."));
2030 actionCollection()->setDefaultShortcuts(replaceLocation, {Qt::CTRL | Qt::Key_L, Qt::ALT | Qt::Key_D});
2031 connect(replaceLocation, &QAction::triggered, this, &DolphinMainWindow::replaceLocation);
2032
2033 // setup 'Go' menu
2034 {
2035 QScopedPointer<QAction> backAction(KStandardAction::back(nullptr, nullptr, nullptr));
2036 m_backAction = new KToolBarPopupAction(backAction->icon(), backAction->text(), actionCollection());
2037 m_backAction->setObjectName(backAction->objectName());
2038 m_backAction->setShortcuts(backAction->shortcuts());
2039 }
2040 m_backAction->setPopupMode(KToolBarPopupAction::DelayedPopup);
2041 connect(m_backAction, &QAction::triggered, this, &DolphinMainWindow::goBack);
2042 connect(m_backAction->popupMenu(), &QMenu::aboutToShow, this, &DolphinMainWindow::slotAboutToShowBackPopupMenu);
2043 connect(m_backAction->popupMenu(), &QMenu::triggered, this, &DolphinMainWindow::slotGoBack);
2044 actionCollection()->addAction(m_backAction->objectName(), m_backAction);
2045
2046 auto backShortcuts = m_backAction->shortcuts();
2047 // Prepend this shortcut, to avoid being hidden by the two-slot UI (#371130)
2048 backShortcuts.prepend(QKeySequence(Qt::Key_Backspace));
2049 actionCollection()->setDefaultShortcuts(m_backAction, backShortcuts);
2050
2051 DolphinRecentTabsMenu *recentTabsMenu = new DolphinRecentTabsMenu(this);
2052 actionCollection()->addAction(QStringLiteral("closed_tabs"), recentTabsMenu);
2053 connect(m_tabWidget, &DolphinTabWidget::rememberClosedTab, recentTabsMenu, &DolphinRecentTabsMenu::rememberClosedTab);
2054 connect(recentTabsMenu, &DolphinRecentTabsMenu::restoreClosedTab, m_tabWidget, &DolphinTabWidget::restoreClosedTab);
2055 connect(recentTabsMenu, &DolphinRecentTabsMenu::closedTabsCountChanged, this, &DolphinMainWindow::closedTabsCountChanged);
2056
2057 QAction *undoCloseTab = actionCollection()->addAction(QStringLiteral("undo_close_tab"));
2058 undoCloseTab->setText(i18nc("@action:inmenu File", "Undo close tab"));
2059 undoCloseTab->setWhatsThis(i18nc("@info:whatsthis undo close tab", "This returns you to the previously closed tab."));
2060 actionCollection()->setDefaultShortcut(undoCloseTab, Qt::CTRL | Qt::SHIFT | Qt::Key_T);
2061 undoCloseTab->setIcon(QIcon::fromTheme(QStringLiteral("edit-undo")));
2062 undoCloseTab->setEnabled(false);
2063 connect(undoCloseTab, &QAction::triggered, recentTabsMenu, &DolphinRecentTabsMenu::undoCloseTab);
2064
2065 auto undoAction = actionCollection()->action(KStandardAction::name(KStandardAction::Undo));
2066 undoAction->setWhatsThis(xi18nc("@info:whatsthis",
2067 "This undoes "
2068 "the last change you made to files or folders.<nl/>"
2069 "Such changes include <interface>creating</interface>, <interface>renaming</interface> "
2070 "and <interface>moving</interface> them to a different location "
2071 "or to the <filename>Trash</filename>. <nl/>Any changes that cannot be undone "
2072 "will ask for your confirmation beforehand."));
2073 undoAction->setEnabled(false); // undo should be disabled by default
2074
2075 {
2076 QScopedPointer<QAction> forwardAction(KStandardAction::forward(nullptr, nullptr, nullptr));
2077 m_forwardAction = new KToolBarPopupAction(forwardAction->icon(), forwardAction->text(), actionCollection());
2078 m_forwardAction->setObjectName(forwardAction->objectName());
2079 m_forwardAction->setShortcuts(forwardAction->shortcuts());
2080 }
2081 m_forwardAction->setPopupMode(KToolBarPopupAction::DelayedPopup);
2082 connect(m_forwardAction, &QAction::triggered, this, &DolphinMainWindow::goForward);
2083 connect(m_forwardAction->popupMenu(), &QMenu::aboutToShow, this, &DolphinMainWindow::slotAboutToShowForwardPopupMenu);
2084 connect(m_forwardAction->popupMenu(), &QMenu::triggered, this, &DolphinMainWindow::slotGoForward);
2085 actionCollection()->addAction(m_forwardAction->objectName(), m_forwardAction);
2086 actionCollection()->setDefaultShortcuts(m_forwardAction, m_forwardAction->shortcuts());
2087
2088 // enable middle-click to open in a new tab
2089 auto *middleClickEventFilter = new MiddleClickActionEventFilter(this);
2090 connect(middleClickEventFilter, &MiddleClickActionEventFilter::actionMiddleClicked, this, &DolphinMainWindow::slotBackForwardActionMiddleClicked);
2091 m_backAction->popupMenu()->installEventFilter(middleClickEventFilter);
2092 m_forwardAction->popupMenu()->installEventFilter(middleClickEventFilter);
2093 KStandardAction::up(this, &DolphinMainWindow::goUp, actionCollection());
2094 QAction *homeAction = KStandardAction::home(this, &DolphinMainWindow::goHome, actionCollection());
2095 homeAction->setWhatsThis(xi18nc("@info:whatsthis",
2096 "Go to your "
2097 "<filename>Home</filename> folder.<nl/>Every user account "
2098 "has their own <filename>Home</filename> that contains their personal files, "
2099 "as well as hidden folders for their applications' data and configuration files."));
2100
2101 // setup 'Tools' menu
2102 QAction *compareFiles = actionCollection()->addAction(QStringLiteral("compare_files"));
2103 compareFiles->setText(i18nc("@action:inmenu Tools", "Compare Files"));
2104 compareFiles->setIcon(QIcon::fromTheme(QStringLiteral("kompare")));
2105 compareFiles->setEnabled(false);
2106 connect(compareFiles, &QAction::triggered, this, &DolphinMainWindow::compareFiles);
2107
2108 QAction *manageDiskSpaceUsage = actionCollection()->addAction(QStringLiteral("manage_disk_space"));
2109 manageDiskSpaceUsage->setText(i18nc("@action:inmenu Tools", "Manage Disk Space Usage"));
2110 manageDiskSpaceUsage->setIcon(QIcon::fromTheme(QStringLiteral("filelight")));
2111 m_diskSpaceUsageMenu = new DiskSpaceUsageMenu{this};
2112 manageDiskSpaceUsage->setMenu(m_diskSpaceUsageMenu);
2113
2114 QAction *openPreferredSearchTool = actionCollection()->addAction(QStringLiteral("open_preferred_search_tool"));
2115 openPreferredSearchTool->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool"));
2116 openPreferredSearchTool->setWhatsThis(xi18nc("@info:whatsthis",
2117 "<para>This opens a preferred search tool for the viewed location.</para>"
2118 "<para>Use <emphasis>More Search Tools</emphasis> menu to configure it.</para>"));
2119 openPreferredSearchTool->setIcon(QIcon::fromTheme(QStringLiteral("search")));
2120 actionCollection()->setDefaultShortcut(openPreferredSearchTool, Qt::CTRL | Qt::SHIFT | Qt::Key_F);
2121 connect(openPreferredSearchTool, &QAction::triggered, this, &DolphinMainWindow::openPreferredSearchTool);
2122
2123 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
2124 // Get icon of user default terminal emulator application
2125 const KConfigGroup group(KSharedConfig::openConfig(QStringLiteral("kdeglobals"), KConfig::SimpleConfig), QStringLiteral("General"));
2126 const QString terminalDesktopFilename = group.readEntry("TerminalService");
2127 // Use utilities-terminal icon from theme if readEntry() has failed
2128 const QString terminalIcon = terminalDesktopFilename.isEmpty() ? "utilities-terminal" : KDesktopFile(terminalDesktopFilename).readIcon();
2129
2130 QAction *openTerminal = actionCollection()->addAction(QStringLiteral("open_terminal"));
2131 openTerminal->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
2132 openTerminal->setWhatsThis(xi18nc("@info:whatsthis",
2133 "<para>This opens a <emphasis>terminal</emphasis> application for the viewed location.</para>"
2134 "<para>To learn more about terminals use the help features in the terminal application.</para>"));
2135 openTerminal->setIcon(QIcon::fromTheme(terminalIcon));
2136 actionCollection()->setDefaultShortcut(openTerminal, Qt::SHIFT | Qt::Key_F4);
2137 connect(openTerminal, &QAction::triggered, this, &DolphinMainWindow::openTerminal);
2138
2139 QAction *openTerminalHere = actionCollection()->addAction(QStringLiteral("open_terminal_here"));
2140 // i18n: "Here" refers to the location(s) of the currently selected item(s) or the currently viewed location if nothing is selected.
2141 openTerminalHere->setText(i18nc("@action:inmenu Tools", "Open Terminal Here"));
2142 openTerminalHere->setWhatsThis(xi18nc("@info:whatsthis",
2143 "<para>This opens <emphasis>terminal</emphasis> applications for the selected items' locations.</para>"
2144 "<para>To learn more about terminals use the help features in the terminal application.</para>"));
2145 openTerminalHere->setIcon(QIcon::fromTheme(terminalIcon));
2146 actionCollection()->setDefaultShortcut(openTerminalHere, Qt::SHIFT | Qt::ALT | Qt::Key_F4);
2147 connect(openTerminalHere, &QAction::triggered, this, &DolphinMainWindow::openTerminalHere);
2148 }
2149
2150 // setup 'Bookmarks' menu
2151 KActionMenu *bookmarkMenu = new KActionMenu(i18nc("@title:menu", "&Bookmarks"), this);
2152 bookmarkMenu->setIcon(QIcon::fromTheme(QStringLiteral("bookmarks")));
2153 // Make the toolbar button version work properly on click
2154 bookmarkMenu->setPopupMode(QToolButton::InstantPopup);
2155 m_bookmarkHandler = new DolphinBookmarkHandler(this, actionCollection(), bookmarkMenu->menu(), this);
2156 actionCollection()->addAction(QStringLiteral("bookmarks"), bookmarkMenu);
2157
2158 // setup 'Settings' menu
2159 KToggleAction *showMenuBar = KStandardAction::showMenubar(nullptr, nullptr, actionCollection());
2160 showMenuBar->setWhatsThis(xi18nc("@info:whatsthis",
2161 "<para>This switches between having a <emphasis>Menubar</emphasis> "
2162 "and having an <interface>%1</interface> button. Both "
2163 "contain mostly the same actions and configuration options.</para>"
2164 "<para>The Menubar takes up more space but allows for fast and organized access to all "
2165 "actions an application has to offer.</para><para>The %1 button "
2166 "is simpler and small which makes triggering advanced actions more time consuming.</para>",
2167 hamburgerMenuAction->text().replace('&', "")));
2168 connect(showMenuBar,
2169 &KToggleAction::triggered, // Fixes #286822
2170 this,
2171 &DolphinMainWindow::toggleShowMenuBar,
2172 Qt::QueuedConnection);
2173
2174 KStandardAction::keyBindings(this, &DolphinMainWindow::slotKeyBindings, actionCollection());
2175 KStandardAction::preferences(this, &DolphinMainWindow::editSettings, actionCollection());
2176
2177 // not in menu actions
2178 QList<QKeySequence> nextTabKeys = KStandardShortcut::tabNext();
2179 nextTabKeys.append(QKeySequence(Qt::CTRL | Qt::Key_Tab));
2180
2181 QList<QKeySequence> prevTabKeys = KStandardShortcut::tabPrev();
2182 prevTabKeys.append(QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_Tab));
2183
2184 for (int i = 0; i < MaxActivateTabShortcuts; ++i) {
2185 QAction *activateTab = actionCollection()->addAction(QStringLiteral("activate_tab_%1").arg(i));
2186 activateTab->setText(i18nc("@action:inmenu", "Go to Tab %1", i + 1));
2187 activateTab->setEnabled(false);
2188 connect(activateTab, &QAction::triggered, this, [this, i]() {
2189 m_tabWidget->activateTab(i);
2190 });
2191
2192 // only add default shortcuts for the first 9 tabs regardless of MaxActivateTabShortcuts
2193 if (i < 9) {
2194 actionCollection()->setDefaultShortcut(activateTab, QStringLiteral("Alt+%1").arg(i + 1));
2195 }
2196 }
2197
2198 QAction *activateLastTab = actionCollection()->addAction(QStringLiteral("activate_last_tab"));
2199 activateLastTab->setIconText(i18nc("@action:inmenu", "Last Tab"));
2200 activateLastTab->setText(i18nc("@action:inmenu", "Go to Last Tab"));
2201 activateLastTab->setEnabled(false);
2202 connect(activateLastTab, &QAction::triggered, m_tabWidget, &DolphinTabWidget::activateLastTab);
2203 actionCollection()->setDefaultShortcut(activateLastTab, Qt::ALT | Qt::Key_0);
2204
2205 QAction *activateNextTab = actionCollection()->addAction(QStringLiteral("activate_next_tab"));
2206 activateNextTab->setIconText(i18nc("@action:inmenu", "Next Tab"));
2207 activateNextTab->setText(i18nc("@action:inmenu", "Go to Next Tab"));
2208 activateNextTab->setEnabled(false);
2209 connect(activateNextTab, &QAction::triggered, m_tabWidget, &DolphinTabWidget::activateNextTab);
2210 actionCollection()->setDefaultShortcuts(activateNextTab, nextTabKeys);
2211
2212 QAction *activatePrevTab = actionCollection()->addAction(QStringLiteral("activate_prev_tab"));
2213 activatePrevTab->setIconText(i18nc("@action:inmenu", "Previous Tab"));
2214 activatePrevTab->setText(i18nc("@action:inmenu", "Go to Previous Tab"));
2215 activatePrevTab->setEnabled(false);
2216 connect(activatePrevTab, &QAction::triggered, m_tabWidget, &DolphinTabWidget::activatePrevTab);
2217 actionCollection()->setDefaultShortcuts(activatePrevTab, prevTabKeys);
2218
2219 // for context menu
2220 QAction *showTarget = actionCollection()->addAction(QStringLiteral("show_target"));
2221 showTarget->setText(i18nc("@action:inmenu", "Show Target"));
2222 showTarget->setIcon(QIcon::fromTheme(QStringLiteral("document-open-folder")));
2223 showTarget->setEnabled(false);
2224 connect(showTarget, &QAction::triggered, this, &DolphinMainWindow::showTarget);
2225
2226 QAction *openInNewTab = actionCollection()->addAction(QStringLiteral("open_in_new_tab"));
2227 openInNewTab->setText(i18nc("@action:inmenu", "Open in New Tab"));
2228 openInNewTab->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
2229 connect(openInNewTab, &QAction::triggered, this, &DolphinMainWindow::openInNewTab);
2230
2231 QAction *openInNewTabs = actionCollection()->addAction(QStringLiteral("open_in_new_tabs"));
2232 openInNewTabs->setText(i18nc("@action:inmenu", "Open in New Tabs"));
2233 openInNewTabs->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
2234 connect(openInNewTabs, &QAction::triggered, this, &DolphinMainWindow::openInNewTab);
2235
2236 QAction *openInNewWindow = actionCollection()->addAction(QStringLiteral("open_in_new_window"));
2237 openInNewWindow->setText(i18nc("@action:inmenu", "Open in New Window"));
2238 openInNewWindow->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
2239 connect(openInNewWindow, &QAction::triggered, this, &DolphinMainWindow::openInNewWindow);
2240
2241 QAction *openInSplitViewAction = actionCollection()->addAction(QStringLiteral("open_in_split_view"));
2242 openInSplitViewAction->setText(i18nc("@action:inmenu", "Open in Split View"));
2243 openInSplitViewAction->setIcon(QIcon::fromTheme(QStringLiteral("view-split-left-right")));
2244 connect(openInSplitViewAction, &QAction::triggered, this, [this]() {
2245 openInSplitView(QUrl());
2246 });
2247
2248 m_recentFiles = new KRecentFilesAction(this);
2249 }
2250
2251 void DolphinMainWindow::setupDockWidgets()
2252 {
2253 const bool lock = GeneralSettings::lockPanels();
2254
2255 DolphinPlacesModelSingleton::instance().placesModel()->setPanelsLocked(lock);
2256
2257 KDualAction *lockLayoutAction = actionCollection()->add<KDualAction>(QStringLiteral("lock_panels"));
2258 lockLayoutAction->setActiveText(i18nc("@action:inmenu Panels", "Unlock Panels"));
2259 lockLayoutAction->setActiveIcon(QIcon::fromTheme(QStringLiteral("object-unlocked")));
2260 lockLayoutAction->setInactiveText(i18nc("@action:inmenu Panels", "Lock Panels"));
2261 lockLayoutAction->setInactiveIcon(QIcon::fromTheme(QStringLiteral("object-locked")));
2262 lockLayoutAction->setWhatsThis(xi18nc("@info:whatsthis",
2263 "This "
2264 "switches between having panels <emphasis>locked</emphasis> or "
2265 "<emphasis>unlocked</emphasis>.<nl/>Unlocked panels can be "
2266 "dragged to the other side of the window and have a close "
2267 "button.<nl/>Locked panels are embedded more cleanly."));
2268 lockLayoutAction->setActive(lock);
2269 connect(lockLayoutAction, &KDualAction::triggered, this, &DolphinMainWindow::togglePanelLockState);
2270
2271 // Setup "Information"
2272 DolphinDockWidget *infoDock = new DolphinDockWidget(i18nc("@title:window", "Information"));
2273 infoDock->setLocked(lock);
2274 infoDock->setObjectName(QStringLiteral("infoDock"));
2275 infoDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
2276
2277 #if HAVE_BALOO
2278 InformationPanel *infoPanel = new InformationPanel(infoDock);
2279 infoPanel->setCustomContextMenuActions({lockLayoutAction});
2280 connect(infoPanel, &InformationPanel::urlActivated, this, &DolphinMainWindow::handleUrl);
2281 infoDock->setWidget(infoPanel);
2282
2283 createPanelAction(QIcon::fromTheme(QStringLiteral("documentinfo")), Qt::Key_F11, infoDock, QStringLiteral("show_information_panel"));
2284
2285 addDockWidget(Qt::RightDockWidgetArea, infoDock);
2286 connect(this, &DolphinMainWindow::urlChanged, infoPanel, &InformationPanel::setUrl);
2287 connect(this, &DolphinMainWindow::selectionChanged, infoPanel, &InformationPanel::setSelection);
2288 connect(this, &DolphinMainWindow::requestItemInfo, infoPanel, &InformationPanel::requestDelayedItemInfo);
2289 connect(this, &DolphinMainWindow::fileItemsChanged, infoPanel, &InformationPanel::slotFilesItemChanged);
2290 connect(this, &DolphinMainWindow::settingsChanged, infoPanel, &InformationPanel::readSettings);
2291 #endif
2292
2293 // i18n: This is the last paragraph for the "What's This"-texts of all four panels.
2294 const QString panelWhatsThis = xi18nc("@info:whatsthis",
2295 "<para>To show or "
2296 "hide panels like this go to <interface>Menu|Panels</interface> "
2297 "or <interface>View|Panels</interface>.</para>");
2298 #if HAVE_BALOO
2299 actionCollection()
2300 ->action(QStringLiteral("show_information_panel"))
2301 ->setWhatsThis(xi18nc("@info:whatsthis",
2302 "<para> This toggles the "
2303 "<emphasis>information</emphasis> panel at the right side of the "
2304 "window.</para><para>The panel provides in-depth information "
2305 "about the items your mouse is hovering over or about the selected "
2306 "items. Otherwise it informs you about the currently viewed folder.<nl/>"
2307 "For single items a preview of their contents is provided.</para>"));
2308 #endif
2309 infoDock->setWhatsThis(xi18nc("@info:whatsthis",
2310 "<para>This panel "
2311 "provides in-depth information about the items your mouse is "
2312 "hovering over or about the selected items. Otherwise it informs "
2313 "you about the currently viewed folder.<nl/>For single items a "
2314 "preview of their contents is provided.</para><para>You can configure "
2315 "which and how details are given here by right-clicking.</para>")
2316 + panelWhatsThis);
2317
2318 // Setup "Folders"
2319 DolphinDockWidget *foldersDock = new DolphinDockWidget(i18nc("@title:window", "Folders"));
2320 foldersDock->setLocked(lock);
2321 foldersDock->setObjectName(QStringLiteral("foldersDock"));
2322 foldersDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
2323 FoldersPanel *foldersPanel = new FoldersPanel(foldersDock);
2324 foldersPanel->setCustomContextMenuActions({lockLayoutAction});
2325 foldersDock->setWidget(foldersPanel);
2326
2327 createPanelAction(QIcon::fromTheme(QStringLiteral("folder")), Qt::Key_F7, foldersDock, QStringLiteral("show_folders_panel"));
2328
2329 addDockWidget(Qt::LeftDockWidgetArea, foldersDock);
2330 connect(this, &DolphinMainWindow::urlChanged, foldersPanel, &FoldersPanel::setUrl);
2331 connect(foldersPanel, &FoldersPanel::folderActivated, this, &DolphinMainWindow::changeUrl);
2332 connect(foldersPanel, &FoldersPanel::folderInNewTab, this, &DolphinMainWindow::openNewTab);
2333 connect(foldersPanel, &FoldersPanel::folderInNewActiveTab, this, &DolphinMainWindow::openNewTabAndActivate);
2334 connect(foldersPanel, &FoldersPanel::errorMessage, this, &DolphinMainWindow::showErrorMessage);
2335
2336 actionCollection()
2337 ->action(QStringLiteral("show_folders_panel"))
2338 ->setWhatsThis(xi18nc("@info:whatsthis",
2339 "This toggles the "
2340 "<emphasis>folders</emphasis> panel at the left side of the window."
2341 "<nl/><nl/>It shows the folders of the <emphasis>file system"
2342 "</emphasis> in a <emphasis>tree view</emphasis>."));
2343 foldersDock->setWhatsThis(xi18nc("@info:whatsthis",
2344 "<para>This panel "
2345 "shows the folders of the <emphasis>file system</emphasis> in a "
2346 "<emphasis>tree view</emphasis>.</para><para>Click a folder to go "
2347 "there. Click the arrow to the left of a folder to see its subfolders. "
2348 "This allows quick switching between any folders.</para>")
2349 + panelWhatsThis);
2350
2351 // Setup "Terminal"
2352 #if HAVE_TERMINAL
2353 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
2354 DolphinDockWidget *terminalDock = new DolphinDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
2355 terminalDock->setLocked(lock);
2356 terminalDock->setObjectName(QStringLiteral("terminalDock"));
2357 terminalDock->setContentsMargins(0, 0, 0, 0);
2358 m_terminalPanel = new TerminalPanel(terminalDock);
2359 m_terminalPanel->setCustomContextMenuActions({lockLayoutAction});
2360 terminalDock->setWidget(m_terminalPanel);
2361
2362 connect(m_terminalPanel, &TerminalPanel::hideTerminalPanel, terminalDock, &DolphinDockWidget::hide);
2363 connect(m_terminalPanel, &TerminalPanel::changeUrl, this, &DolphinMainWindow::slotTerminalDirectoryChanged);
2364 connect(terminalDock, &DolphinDockWidget::visibilityChanged, m_terminalPanel, &TerminalPanel::dockVisibilityChanged);
2365 connect(terminalDock, &DolphinDockWidget::visibilityChanged, this, &DolphinMainWindow::slotTerminalPanelVisibilityChanged);
2366
2367 createPanelAction(QIcon::fromTheme(QStringLiteral("dialog-scripts")), Qt::Key_F4, terminalDock, QStringLiteral("show_terminal_panel"));
2368
2369 addDockWidget(Qt::BottomDockWidgetArea, terminalDock);
2370 connect(this, &DolphinMainWindow::urlChanged, m_terminalPanel, &TerminalPanel::setUrl);
2371
2372 if (GeneralSettings::version() < 200) {
2373 terminalDock->hide();
2374 }
2375
2376 actionCollection()
2377 ->action(QStringLiteral("show_terminal_panel"))
2378 ->setWhatsThis(xi18nc("@info:whatsthis",
2379 "<para>This toggles the "
2380 "<emphasis>terminal</emphasis> panel at the bottom of the window."
2381 "<nl/>The location in the terminal will always match the folder "
2382 "view so you can navigate using either.</para><para>The terminal "
2383 "panel is not needed for basic computer usage but can be useful "
2384 "for advanced tasks. To learn more about terminals use the help features "
2385 "in a standalone terminal application like Konsole.</para>"));
2386 terminalDock->setWhatsThis(xi18nc("@info:whatsthis",
2387 "<para>This is "
2388 "the <emphasis>terminal</emphasis> panel. It behaves like a "
2389 "normal terminal but will match the location of the folder view "
2390 "so you can navigate using either.</para><para>The terminal panel "
2391 "is not needed for basic computer usage but can be useful for "
2392 "advanced tasks. To learn more about terminals use the help features in a "
2393 "standalone terminal application like Konsole.</para>")
2394 + panelWhatsThis);
2395
2396 QAction *focusTerminalPanel = actionCollection()->addAction(QStringLiteral("focus_terminal_panel"));
2397 focusTerminalPanel->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
2398 focusTerminalPanel->setToolTip(i18nc("@info:tooltip", "Move keyboard focus to and from the Terminal panel."));
2399 focusTerminalPanel->setIcon(QIcon::fromTheme(QStringLiteral("swap-panels")));
2400 actionCollection()->setDefaultShortcut(focusTerminalPanel, Qt::CTRL | Qt::SHIFT | Qt::Key_F4);
2401 connect(focusTerminalPanel, &QAction::triggered, this, &DolphinMainWindow::toggleTerminalPanelFocus);
2402 } // endif "shell_access" allowed
2403 #endif // HAVE_TERMINAL
2404
2405 if (GeneralSettings::version() < 200) {
2406 infoDock->hide();
2407 foldersDock->hide();
2408 }
2409
2410 // Setup "Places"
2411 DolphinDockWidget *placesDock = new DolphinDockWidget(i18nc("@title:window", "Places"));
2412 placesDock->setLocked(lock);
2413 placesDock->setObjectName(QStringLiteral("placesDock"));
2414 placesDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
2415
2416 m_placesPanel = new PlacesPanel(placesDock);
2417 m_placesPanel->setCustomContextMenuActions({lockLayoutAction});
2418 placesDock->setWidget(m_placesPanel);
2419
2420 createPanelAction(QIcon::fromTheme(QStringLiteral("compass")), Qt::Key_F9, placesDock, QStringLiteral("show_places_panel"));
2421
2422 addDockWidget(Qt::LeftDockWidgetArea, placesDock);
2423 connect(m_placesPanel, &PlacesPanel::placeActivated, this, &DolphinMainWindow::slotPlaceActivated);
2424 connect(m_placesPanel, &PlacesPanel::tabRequested, this, &DolphinMainWindow::openNewTab);
2425 connect(m_placesPanel, &PlacesPanel::activeTabRequested, this, &DolphinMainWindow::openNewTabAndActivate);
2426 connect(m_placesPanel, &PlacesPanel::newWindowRequested, this, [this](const QUrl &url) {
2427 Dolphin::openNewWindow({url}, this);
2428 });
2429 connect(m_placesPanel, &PlacesPanel::openInSplitViewRequested, this, &DolphinMainWindow::openInSplitView);
2430 connect(m_placesPanel, &PlacesPanel::errorMessage, this, &DolphinMainWindow::showErrorMessage);
2431 connect(this, &DolphinMainWindow::urlChanged, m_placesPanel, &PlacesPanel::setUrl);
2432 connect(placesDock, &DolphinDockWidget::visibilityChanged, &DolphinUrlNavigatorsController::slotPlacesPanelVisibilityChanged);
2433 connect(placesDock, &DolphinDockWidget::visibilityChanged, this, &DolphinMainWindow::slotPlacesPanelVisibilityChanged);
2434 connect(this, &DolphinMainWindow::settingsChanged, m_placesPanel, &PlacesPanel::readSettings);
2435 connect(m_placesPanel, &PlacesPanel::storageTearDownRequested, this, &DolphinMainWindow::slotStorageTearDownFromPlacesRequested);
2436 connect(m_placesPanel, &PlacesPanel::storageTearDownExternallyRequested, this, &DolphinMainWindow::slotStorageTearDownExternallyRequested);
2437 DolphinUrlNavigatorsController::slotPlacesPanelVisibilityChanged(m_placesPanel->isVisible());
2438
2439 auto actionShowAllPlaces = new QAction(QIcon::fromTheme(QStringLiteral("view-hidden")), i18nc("@item:inmenu", "Show Hidden Places"), this);
2440 actionShowAllPlaces->setCheckable(true);
2441 actionShowAllPlaces->setDisabled(true);
2442 actionShowAllPlaces->setWhatsThis(i18nc("@info:whatsthis",
2443 "This displays "
2444 "all places in the places panel that have been hidden. They will "
2445 "appear semi-transparent and allow you to uncheck their \"Hide\" property."));
2446
2447 connect(actionShowAllPlaces, &QAction::triggered, this, [this](bool checked) {
2448 m_placesPanel->setShowAll(checked);
2449 });
2450 connect(m_placesPanel, &PlacesPanel::allPlacesShownChanged, actionShowAllPlaces, &QAction::setChecked);
2451
2452 actionCollection()
2453 ->action(QStringLiteral("show_places_panel"))
2454 ->setWhatsThis(xi18nc("@info:whatsthis",
2455 "<para>This toggles the "
2456 "<emphasis>places</emphasis> panel at the left side of the window."
2457 "</para><para>It allows you to go to locations you have "
2458 "bookmarked and to access disk or media attached to the computer "
2459 "or to the network. It also contains sections to find recently "
2460 "saved files or files of a certain type.</para>"));
2461 placesDock->setWhatsThis(xi18nc("@info:whatsthis",
2462 "<para>This is the "
2463 "<emphasis>Places</emphasis> panel. It allows you to go to locations "
2464 "you have bookmarked and to access disk or media attached to the "
2465 "computer or to the network. It also contains sections to find "
2466 "recently saved files or files of a certain type.</para><para>"
2467 "Click on an entry to go there. Click with the right mouse button "
2468 "instead to open any entry in a new tab or new window.</para>"
2469 "<para>New entries can be added by dragging folders onto this panel. "
2470 "Right-click any section or entry to hide it. Right-click an empty "
2471 "space on this panel and select <interface>Show Hidden Places"
2472 "</interface> to display it again.</para>")
2473 + panelWhatsThis);
2474
2475 QAction *focusPlacesPanel = actionCollection()->addAction(QStringLiteral("focus_places_panel"));
2476 focusPlacesPanel->setText(i18nc("@action:inmenu View", "Focus Places Panel"));
2477 focusPlacesPanel->setToolTip(i18nc("@info:tooltip", "Move keyboard focus to and from the Places panel."));
2478 focusPlacesPanel->setIcon(QIcon::fromTheme(QStringLiteral("swap-panels")));
2479 actionCollection()->setDefaultShortcut(focusPlacesPanel, Qt::CTRL | Qt::Key_P);
2480 connect(focusPlacesPanel, &QAction::triggered, this, &DolphinMainWindow::togglePlacesPanelFocus);
2481
2482 // Add actions into the "Panels" menu
2483 KActionMenu *panelsMenu = new KActionMenu(i18nc("@action:inmenu View", "Show Panels"), this);
2484 actionCollection()->addAction(QStringLiteral("panels"), panelsMenu);
2485 panelsMenu->setIcon(QIcon::fromTheme(QStringLiteral("view-sidetree")));
2486 panelsMenu->setPopupMode(QToolButton::InstantPopup);
2487 const KActionCollection *ac = actionCollection();
2488 panelsMenu->addAction(ac->action(QStringLiteral("show_places_panel")));
2489 #if HAVE_BALOO
2490 panelsMenu->addAction(ac->action(QStringLiteral("show_information_panel")));
2491 #endif
2492 panelsMenu->addAction(ac->action(QStringLiteral("show_folders_panel")));
2493 panelsMenu->addAction(ac->action(QStringLiteral("show_terminal_panel")));
2494 panelsMenu->addSeparator();
2495 panelsMenu->addAction(lockLayoutAction);
2496 panelsMenu->addSeparator();
2497 panelsMenu->addAction(actionShowAllPlaces);
2498 panelsMenu->addAction(focusPlacesPanel);
2499 panelsMenu->addAction(ac->action(QStringLiteral("focus_terminal_panel")));
2500
2501 connect(panelsMenu->menu(), &QMenu::aboutToShow, this, [actionShowAllPlaces] {
2502 actionShowAllPlaces->setEnabled(DolphinPlacesModelSingleton::instance().placesModel()->hiddenCount());
2503 });
2504 }
2505
2506 void DolphinMainWindow::updateFileAndEditActions()
2507 {
2508 const KFileItemList list = m_activeViewContainer->view()->selectedItems();
2509 const KActionCollection *col = actionCollection();
2510 KFileItemListProperties capabilitiesSource(list);
2511
2512 QAction *renameAction = col->action(KStandardAction::name(KStandardAction::RenameFile));
2513 QAction *moveToTrashAction = col->action(KStandardAction::name(KStandardAction::MoveToTrash));
2514 QAction *deleteAction = col->action(KStandardAction::name(KStandardAction::DeleteFile));
2515 QAction *cutAction = col->action(KStandardAction::name(KStandardAction::Cut));
2516 QAction *duplicateAction = col->action(QStringLiteral("duplicate")); // see DolphinViewActionHandler
2517 QAction *addToPlacesAction = col->action(QStringLiteral("add_to_places"));
2518 QAction *copyToOtherViewAction = col->action(QStringLiteral("copy_to_inactive_split_view"));
2519 QAction *moveToOtherViewAction = col->action(QStringLiteral("move_to_inactive_split_view"));
2520 QAction *copyLocation = col->action(QStringLiteral("copy_location"));
2521
2522 if (list.isEmpty()) {
2523 stateChanged(QStringLiteral("has_no_selection"));
2524
2525 // All actions that need a selection to function can be enabled because they should trigger selection mode.
2526 renameAction->setEnabled(true);
2527 moveToTrashAction->setEnabled(true);
2528 deleteAction->setEnabled(true);
2529 cutAction->setEnabled(true);
2530 duplicateAction->setEnabled(true);
2531 addToPlacesAction->setEnabled(true);
2532 copyLocation->setEnabled(true);
2533 // Them triggering selection mode and not directly acting on selected items is signified by adding "…" to their text.
2534 m_actionTextHelper->textsWhenNothingIsSelectedEnabled(true);
2535
2536 } else {
2537 m_actionTextHelper->textsWhenNothingIsSelectedEnabled(false);
2538 stateChanged(QStringLiteral("has_selection"));
2539
2540 QAction *deleteWithTrashShortcut = col->action(QStringLiteral("delete_shortcut")); // see DolphinViewActionHandler
2541 QAction *showTarget = col->action(QStringLiteral("show_target"));
2542
2543 if (list.length() == 1 && list.first().isDir()) {
2544 addToPlacesAction->setEnabled(true);
2545 } else {
2546 addToPlacesAction->setEnabled(false);
2547 }
2548
2549 const bool enableMoveToTrash = capabilitiesSource.isLocal() && capabilitiesSource.supportsMoving();
2550
2551 renameAction->setEnabled(capabilitiesSource.supportsMoving());
2552 m_disabledActionNotifier->setDisabledReason(renameAction, i18nc("@info", "Cannot rename: You do not have permission to rename items in this folder."));
2553 deleteAction->setEnabled(capabilitiesSource.supportsDeleting());
2554 m_disabledActionNotifier->setDisabledReason(deleteAction,
2555 i18nc("@info", "Cannot delete: You do not have permission to remove items from this folder."));
2556 cutAction->setEnabled(capabilitiesSource.supportsMoving());
2557 m_disabledActionNotifier->setDisabledReason(cutAction, i18nc("@info", "Cannot cut: You do not have permission to move items from this folder."));
2558 copyLocation->setEnabled(list.length() == 1);
2559 showTarget->setEnabled(list.length() == 1 && list.at(0).isLink());
2560 duplicateAction->setEnabled(capabilitiesSource.supportsWriting());
2561 m_disabledActionNotifier->setDisabledReason(duplicateAction,
2562 i18nc("@info", "Cannot duplicate here: You do not have permission to create items in this folder."));
2563
2564 if (enableMoveToTrash) {
2565 moveToTrashAction->setEnabled(true);
2566 deleteWithTrashShortcut->setEnabled(false);
2567 m_disabledActionNotifier->clearDisabledReason(deleteWithTrashShortcut);
2568 } else {
2569 moveToTrashAction->setEnabled(false);
2570 deleteWithTrashShortcut->setEnabled(capabilitiesSource.supportsDeleting());
2571 m_disabledActionNotifier->setDisabledReason(deleteWithTrashShortcut,
2572 i18nc("@info", "Cannot delete: You do not have permission to remove items from this folder."));
2573 }
2574 }
2575
2576 if (!m_tabWidget->currentTabPage()->splitViewEnabled()) {
2577 // No need to set the disabled reason here, as it's obvious to the user that the reason is the split view being disabled.
2578 copyToOtherViewAction->setEnabled(false);
2579 m_disabledActionNotifier->clearDisabledReason(copyToOtherViewAction);
2580 moveToOtherViewAction->setEnabled(false);
2581 m_disabledActionNotifier->clearDisabledReason(moveToOtherViewAction);
2582 } else if (list.isEmpty()) {
2583 copyToOtherViewAction->setEnabled(false);
2584 m_disabledActionNotifier->setDisabledReason(copyToOtherViewAction, i18nc("@info", "Cannot copy to other view: No files selected."));
2585 moveToOtherViewAction->setEnabled(false);
2586 m_disabledActionNotifier->setDisabledReason(moveToOtherViewAction, i18nc("@info", "Cannot move to other view: No files selected."));
2587 } else {
2588 DolphinTabPage *tabPage = m_tabWidget->currentTabPage();
2589 KFileItem capabilitiesDestination;
2590
2591 if (tabPage->primaryViewActive()) {
2592 capabilitiesDestination = tabPage->secondaryViewContainer()->rootItem();
2593 } else {
2594 capabilitiesDestination = tabPage->primaryViewContainer()->rootItem();
2595 }
2596
2597 const auto destUrl = capabilitiesDestination.url();
2598 const bool allNotTargetOrigin = std::all_of(list.cbegin(), list.cend(), [destUrl](const KFileItem &item) {
2599 return item.url().adjusted(QUrl::RemoveFilename | QUrl::StripTrailingSlash) != destUrl;
2600 });
2601
2602 if (!allNotTargetOrigin) {
2603 copyToOtherViewAction->setEnabled(false);
2604 m_disabledActionNotifier->setDisabledReason(copyToOtherViewAction,
2605 i18nc("@info", "Cannot copy to other view: The other view already contains these items."));
2606 moveToOtherViewAction->setEnabled(false);
2607 m_disabledActionNotifier->setDisabledReason(moveToOtherViewAction,
2608 i18nc("@info", "Cannot move to other view: The other view already contains these items."));
2609 } else if (!capabilitiesDestination.isWritable()) {
2610 copyToOtherViewAction->setEnabled(false);
2611 m_disabledActionNotifier->setDisabledReason(
2612 copyToOtherViewAction,
2613 i18nc("@info", "Cannot copy to other view: You do not have permission to write into the destination folder."));
2614 moveToOtherViewAction->setEnabled(false);
2615 m_disabledActionNotifier->setDisabledReason(
2616 moveToOtherViewAction,
2617 i18nc("@info", "Cannot move to other view: You do not have permission to write into the destination folder."));
2618 } else {
2619 copyToOtherViewAction->setEnabled(true);
2620 moveToOtherViewAction->setEnabled(capabilitiesSource.supportsMoving());
2621 m_disabledActionNotifier->setDisabledReason(
2622 moveToOtherViewAction,
2623 i18nc("@info", "Cannot move to other view: You do not have permission to move items from this folder."));
2624 }
2625 }
2626 }
2627
2628 void DolphinMainWindow::updateViewActions()
2629 {
2630 m_actionHandler->updateViewActions();
2631
2632 QAction *toggleFilterBarAction = actionCollection()->action(QStringLiteral("toggle_filter"));
2633 toggleFilterBarAction->setChecked(m_activeViewContainer->isFilterBarVisible());
2634
2635 updateSplitActions();
2636 }
2637
2638 void DolphinMainWindow::updateGoActions()
2639 {
2640 QAction *goUpAction = actionCollection()->action(KStandardAction::name(KStandardAction::Up));
2641 const QUrl currentUrl = m_activeViewContainer->url();
2642 // I think this is one of the best places to firstly be confronted
2643 // with a file system and its hierarchy. Talking about the root
2644 // directory might seem too much here but it is the question that
2645 // naturally arises in this context.
2646 goUpAction->setWhatsThis(xi18nc("@info:whatsthis",
2647 "<para>Go to "
2648 "the folder that contains the currently viewed one.</para>"
2649 "<para>All files and folders are organized in a hierarchical "
2650 "<emphasis>file system</emphasis>. At the top of this hierarchy is "
2651 "a directory that contains all data connected to this computer"
2652 "—the <emphasis>root directory</emphasis>.</para>"));
2653 goUpAction->setEnabled(KIO::upUrl(currentUrl) != currentUrl);
2654 }
2655
2656 void DolphinMainWindow::refreshViews()
2657 {
2658 m_tabWidget->refreshViews();
2659
2660 if (GeneralSettings::modifiedStartupSettings()) {
2661 updateWindowTitle();
2662 }
2663
2664 updateSplitActions();
2665
2666 Q_EMIT settingsChanged();
2667 }
2668
2669 void DolphinMainWindow::clearStatusBar()
2670 {
2671 m_activeViewContainer->statusBar()->resetToDefaultText();
2672 }
2673
2674 void DolphinMainWindow::connectViewSignals(DolphinViewContainer *container)
2675 {
2676 connect(container, &DolphinViewContainer::showFilterBarChanged, this, &DolphinMainWindow::updateFilterBarAction);
2677 connect(container, &DolphinViewContainer::writeStateChanged, this, &DolphinMainWindow::slotWriteStateChanged);
2678 slotWriteStateChanged(container->view()->isFolderWritable());
2679 connect(container, &DolphinViewContainer::searchBarVisibilityChanged, this, &DolphinMainWindow::updateSearchAction);
2680 connect(container, &DolphinViewContainer::captionChanged, this, &DolphinMainWindow::updateWindowTitle);
2681 connect(container, &DolphinViewContainer::tabRequested, this, &DolphinMainWindow::openNewTab);
2682 connect(container, &DolphinViewContainer::activeTabRequested, this, &DolphinMainWindow::openNewTabAndActivate);
2683
2684 // Make the toggled state of the selection mode actions visually follow the selection mode state of the view.
2685 auto toggleSelectionModeAction = actionCollection()->action(QStringLiteral("toggle_selection_mode"));
2686 toggleSelectionModeAction->setChecked(m_activeViewContainer->isSelectionModeEnabled());
2687 connect(m_activeViewContainer, &DolphinViewContainer::selectionModeChanged, toggleSelectionModeAction, &QAction::setChecked);
2688
2689 const DolphinView *view = container->view();
2690 connect(view, &DolphinView::selectionChanged, this, &DolphinMainWindow::slotSelectionChanged);
2691 connect(view, &DolphinView::requestItemInfo, this, &DolphinMainWindow::requestItemInfo);
2692 connect(view, &DolphinView::fileItemsChanged, this, &DolphinMainWindow::fileItemsChanged);
2693 connect(view, &DolphinView::tabRequested, this, &DolphinMainWindow::openNewTab);
2694 connect(view, &DolphinView::activeTabRequested, this, &DolphinMainWindow::openNewTabAndActivate);
2695 connect(view, &DolphinView::windowRequested, this, &DolphinMainWindow::openNewWindow);
2696 connect(view, &DolphinView::requestContextMenu, this, &DolphinMainWindow::openContextMenu);
2697 connect(view, &DolphinView::directoryLoadingStarted, this, &DolphinMainWindow::enableStopAction);
2698 connect(view, &DolphinView::directoryLoadingCompleted, this, &DolphinMainWindow::disableStopAction);
2699 connect(view, &DolphinView::directoryLoadingCompleted, this, &DolphinMainWindow::slotDirectoryLoadingCompleted);
2700 connect(view, &DolphinView::goBackRequested, this, &DolphinMainWindow::goBack);
2701 connect(view, &DolphinView::goForwardRequested, this, &DolphinMainWindow::goForward);
2702 connect(view, &DolphinView::urlActivated, this, &DolphinMainWindow::handleUrl);
2703 connect(view, &DolphinView::goUpRequested, this, &DolphinMainWindow::goUp);
2704 connect(view, &DolphinView::doubleClickViewBackground, this, &DolphinMainWindow::slotDoubleClickViewBackground);
2705
2706 connect(container->urlNavigatorInternalWithHistory(), &KUrlNavigator::urlChanged, this, &DolphinMainWindow::changeUrl);
2707 connect(container->urlNavigatorInternalWithHistory(), &KUrlNavigator::historyChanged, this, &DolphinMainWindow::updateHistory);
2708
2709 auto navigators = static_cast<DolphinNavigatorsWidgetAction *>(actionCollection()->action(QStringLiteral("url_navigators")));
2710 const KUrlNavigator *navigator =
2711 m_tabWidget->currentTabPage()->primaryViewActive() ? navigators->primaryUrlNavigator() : navigators->secondaryUrlNavigator();
2712
2713 QAction *editableLocactionAction = actionCollection()->action(QStringLiteral("editable_location"));
2714 editableLocactionAction->setChecked(navigator->isUrlEditable());
2715 connect(navigator, &KUrlNavigator::editableStateChanged, this, &DolphinMainWindow::slotEditableStateChanged);
2716 connect(navigator, &KUrlNavigator::tabRequested, this, &DolphinMainWindow::openNewTab);
2717 connect(navigator, &KUrlNavigator::activeTabRequested, this, &DolphinMainWindow::openNewTabAndActivate);
2718 connect(navigator, &KUrlNavigator::newWindowRequested, this, &DolphinMainWindow::openNewWindow);
2719 }
2720
2721 void DolphinMainWindow::updateSplitActions()
2722 {
2723 QAction *popoutSplitAction = actionCollection()->action(QStringLiteral("popout_split_view"));
2724
2725 auto setActionPopupMode = [this](KActionMenu *action, QToolButton::ToolButtonPopupMode popupMode) {
2726 action->setPopupMode(popupMode);
2727 if (auto *buttonForAction = qobject_cast<QToolButton *>(toolBar()->widgetForAction(action))) {
2728 buttonForAction->setPopupMode(popupMode);
2729 }
2730 };
2731
2732 const DolphinTabPage *tabPage = m_tabWidget->currentTabPage();
2733 if (tabPage->splitViewEnabled()) {
2734 if (GeneralSettings::closeActiveSplitView() ? tabPage->primaryViewActive() : !tabPage->primaryViewActive()) {
2735 m_splitViewAction->setText(i18nc("@action:intoolbar Close left view", "Close"));
2736 m_splitViewAction->setToolTip(i18nc("@info", "Close left view"));
2737 m_splitViewAction->setIcon(QIcon::fromTheme(QStringLiteral("view-left-close")));
2738 m_splitViewMenuAction->setText(i18nc("@action:inmenu Close left view", "Close Left View"));
2739
2740 popoutSplitAction->setText(i18nc("@action:intoolbar Move left view to a new window", "Pop out Left View"));
2741 popoutSplitAction->setToolTip(i18nc("@info", "Move left view to a new window"));
2742 } else {
2743 m_splitViewAction->setText(i18nc("@action:intoolbar Close right view", "Close"));
2744 m_splitViewAction->setToolTip(i18nc("@info", "Close right view"));
2745 m_splitViewAction->setIcon(QIcon::fromTheme(QStringLiteral("view-right-close")));
2746 m_splitViewMenuAction->setText(i18nc("@action:inmenu Close left view", "Close Right View"));
2747
2748 popoutSplitAction->setText(i18nc("@action:intoolbar Move right view to a new window", "Pop out Right View"));
2749 popoutSplitAction->setToolTip(i18nc("@info", "Move right view to a new window"));
2750 }
2751 popoutSplitAction->setEnabled(true);
2752 if (!m_splitViewAction->menu()) {
2753 setActionPopupMode(m_splitViewAction, QToolButton::MenuButtonPopup);
2754 m_splitViewAction->setMenu(new QMenu);
2755 m_splitViewAction->addAction(popoutSplitAction);
2756 }
2757 } else {
2758 m_splitViewAction->setText(i18nc("@action:intoolbar Split view", "Split"));
2759 m_splitViewMenuAction->setText(m_splitViewAction->text());
2760 m_splitViewAction->setToolTip(i18nc("@info", "Split view"));
2761 m_splitViewAction->setIcon(QIcon::fromTheme(QStringLiteral("view-split-left-right")));
2762 popoutSplitAction->setText(i18nc("@action:intoolbar Move view in focus to a new window", "Pop out"));
2763 popoutSplitAction->setEnabled(false);
2764 if (m_splitViewAction->menu()) {
2765 m_splitViewAction->removeAction(popoutSplitAction);
2766 m_splitViewAction->menu()->deleteLater();
2767 m_splitViewAction->setMenu(nullptr);
2768 setActionPopupMode(m_splitViewAction, QToolButton::DelayedPopup);
2769 }
2770 }
2771
2772 // Update state from toolbar action
2773 m_splitViewMenuAction->setToolTip(m_splitViewAction->toolTip());
2774 m_splitViewMenuAction->setIcon(m_splitViewAction->icon());
2775 }
2776
2777 void DolphinMainWindow::updateAllowedToolbarAreas()
2778 {
2779 auto navigators = static_cast<DolphinNavigatorsWidgetAction *>(actionCollection()->action(QStringLiteral("url_navigators")));
2780 if (toolBar()->actions().contains(navigators)) {
2781 toolBar()->setAllowedAreas(Qt::TopToolBarArea | Qt::BottomToolBarArea);
2782 if (toolBarArea(toolBar()) == Qt::LeftToolBarArea || toolBarArea(toolBar()) == Qt::RightToolBarArea) {
2783 addToolBar(Qt::TopToolBarArea, toolBar());
2784 }
2785 } else {
2786 toolBar()->setAllowedAreas(Qt::AllToolBarAreas);
2787 }
2788 }
2789
2790 void DolphinMainWindow::updateNavigatorsBackground()
2791 {
2792 auto navigators = static_cast<DolphinNavigatorsWidgetAction *>(actionCollection()->action(QStringLiteral("url_navigators")));
2793 navigators->setBackgroundEnabled(navigators->isInToolbar());
2794 }
2795
2796 bool DolphinMainWindow::isKompareInstalled() const
2797 {
2798 static bool initialized = false;
2799 static bool installed = false;
2800 if (!initialized) {
2801 // TODO: maybe replace this approach later by using a menu
2802 // plugin like kdiff3plugin.cpp
2803 installed = !QStandardPaths::findExecutable(QStringLiteral("kompare")).isEmpty();
2804 initialized = true;
2805 }
2806 return installed;
2807 }
2808
2809 void DolphinMainWindow::createPanelAction(const QIcon &icon, const QKeySequence &shortcut, QDockWidget *dockWidget, const QString &actionName)
2810 {
2811 auto dockAction = dockWidget->toggleViewAction();
2812 dockAction->setIcon(icon);
2813 dockAction->setEnabled(true);
2814
2815 QAction *panelAction = actionCollection()->addAction(actionName, dockAction);
2816 actionCollection()->setDefaultShortcut(panelAction, shortcut);
2817 }
2818 // clang-format off
2819 void DolphinMainWindow::setupWhatsThis()
2820 {
2821 // main widgets
2822 menuBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2823 "<emphasis>Menubar</emphasis>. It provides access to commands and "
2824 "configuration options. Left-click on any of the menus on this "
2825 "bar to see its contents.</para><para>The Menubar can be hidden "
2826 "by unchecking <interface>Settings|Show Menubar</interface>. Then "
2827 "most of its contents become available through a <interface>Menu"
2828 "</interface> button on the <emphasis>Toolbar</emphasis>.</para>"));
2829 toolBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2830 "<emphasis>Toolbar</emphasis>. It allows quick access to "
2831 "frequently used actions.</para><para>It is highly customizable. "
2832 "All items you see in the <interface>Menu</interface> or "
2833 "in the <interface>Menubar</interface> can be placed on the "
2834 "Toolbar. Just right-click on it and select <interface>Configure "
2835 "Toolbars…</interface> or find this action within the <interface>"
2836 "menu</interface>."
2837 "</para><para>The location of the bar and the style of its "
2838 "buttons can also be changed in the right-click menu. Right-click "
2839 "a button if you want to show or hide its text.</para>"));
2840 m_tabWidget->setWhatsThis(xi18nc("@info:whatsthis main view",
2841 "<para>Here you can see the <emphasis>folders</emphasis> and "
2842 "<emphasis>files</emphasis> that are at the location described in "
2843 "the <interface>Location Bar</interface> above. This area is the "
2844 "central part of this application where you navigate to the files "
2845 "you want to use.</para><para>For an elaborate and general "
2846 "introduction to this application <link "
2847 "url='https://userbase.kde.org/Dolphin/File_Management#Introduction_to_Dolphin'>"
2848 "click here</link>. This will open an introductory article from "
2849 "the <emphasis>KDE UserBase Wiki</emphasis>.</para><para>For brief "
2850 "explanations of all the features of this <emphasis>view</emphasis> "
2851 "<link url='help:/dolphin/dolphin-view.html'>click here</link> "
2852 "instead. This will open a page from the <emphasis>Handbook"
2853 "</emphasis> that covers the basics.</para>"));
2854
2855 // Settings menu
2856 actionCollection()->action(KStandardAction::name(KStandardAction::KeyBindings))
2857 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window "
2858 "that lists the <emphasis>keyboard shortcuts</emphasis>.<nl/>"
2859 "There you can set up key combinations to trigger an action when "
2860 "they are pressed simultaneously. All commands in this application can "
2861 "be triggered this way.</para>"));
2862 actionCollection()->action(KStandardAction::name(KStandardAction::ConfigureToolbars))
2863 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window in which "
2864 "you can change which buttons appear on the <emphasis>Toolbar</emphasis>.</para>"
2865 "<para>All items you see in the <interface>Menu</interface> can also be placed on the Toolbar.</para>"));
2866 actionCollection()->action(KStandardAction::name(KStandardAction::Preferences))
2867 ->setWhatsThis(xi18nc("@info:whatsthis","This opens a window where you can "
2868 "change a multitude of settings for this application. For an explanation "
2869 "of the various settings go to the chapter <emphasis>Configuring Dolphin"
2870 "</emphasis> in <interface>Help|Dolphin Handbook</interface>."));
2871
2872 // Help menu
2873
2874 auto setStandardActionWhatsThis = [this](KStandardAction::StandardAction actionId,
2875 const QString &whatsThis) {
2876 // Check for the existence of an action since it can be restricted through the Kiosk system
2877 if (auto *action = actionCollection()->action(KStandardAction::name(actionId))) {
2878 action->setWhatsThis(whatsThis);
2879 }
2880 };
2881
2882 // i18n: If the external link isn't available in your language it might make
2883 // sense to state the external link's language in brackets to not
2884 // frustrate the user. If there are multiple languages that the user might
2885 // know with a reasonable chance you might want to have 2 external links.
2886 // The same might be true for any external link you translate.
2887 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>"));
2888 // (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 )
2889
2890 setStandardActionWhatsThis(KStandardAction::WhatsThis,
2891 xi18nc("@info:whatsthis whatsthis button",
2892 "<para>This is the button that invokes the help feature you are "
2893 "using right now! Click it, then click any component of this "
2894 "application to ask \"What's this?\" about it. The mouse cursor "
2895 "will change appearance if no help is available for a spot.</para>"
2896 "<para>There are two other ways to get help: "
2897 "The <link url='help:/dolphin/index.html'>Dolphin Handbook</link> and "
2898 "the <link url='https://userbase.kde.org/Dolphin/File_Management'>KDE "
2899 "UserBase Wiki</link>.</para><para>The \"What's this?\" help is "
2900 "missing in most other windows so don't get too used to this.</para>"));
2901
2902 setStandardActionWhatsThis(KStandardAction::ReportBug,
2903 xi18nc("@info:whatsthis","<para>This opens a "
2904 "window that will guide you through reporting errors or flaws "
2905 "in this application or in other KDE software.</para>"
2906 "<para>High-quality bug reports are much appreciated. To learn "
2907 "how to make your bug report as effective as possible "
2908 "<link url='https://community.kde.org/Get_Involved/Bug_Reporting'>"
2909 "click here</link>.</para>"));
2910
2911 setStandardActionWhatsThis(KStandardAction::Donate,
2912 xi18nc("@info:whatsthis", "<para>This opens a "
2913 "<emphasis>web page</emphasis> where you can donate to "
2914 "support the continued work on this application and many "
2915 "other projects by the <emphasis>KDE</emphasis> community.</para>"
2916 "<para>Donating is the easiest and fastest way to efficiently "
2917 "support KDE and its projects. KDE projects are available for "
2918 "free therefore your donation is needed to cover things that "
2919 "require money like servers, contributor meetings, etc.</para>"
2920 "<para><emphasis>KDE e.V.</emphasis> is the non-profit "
2921 "organization behind the KDE community.</para>"));
2922
2923 setStandardActionWhatsThis(KStandardAction::SwitchApplicationLanguage,
2924 xi18nc("@info:whatsthis",
2925 "With this you can change the language this application uses."
2926 "<nl/>You can even set secondary languages which will be used "
2927 "if texts are not available in your preferred language."));
2928
2929 setStandardActionWhatsThis(KStandardAction::AboutApp,
2930 xi18nc("@info:whatsthis","This opens a "
2931 "window that informs you about the version, license, "
2932 "used libraries and maintainers of this application."));
2933
2934 setStandardActionWhatsThis(KStandardAction::AboutKDE,
2935 xi18nc("@info:whatsthis","This opens a "
2936 "window with information about <emphasis>KDE</emphasis>. "
2937 "The KDE community are the people behind this free software."
2938 "<nl/>If you like using this application but don't know "
2939 "about KDE or want to see a cute dragon have a look!"));
2940 }
2941 // clang-format on
2942
2943 bool DolphinMainWindow::addHamburgerMenuToToolbar()
2944 {
2945 QDomDocument domDocument = KXMLGUIClient::domDocument();
2946 if (domDocument.isNull()) {
2947 return false;
2948 }
2949 QDomNode toolbar = domDocument.elementsByTagName(QStringLiteral("ToolBar")).at(0);
2950 if (toolbar.isNull()) {
2951 return false;
2952 }
2953
2954 QDomElement hamburgerMenuElement = domDocument.createElement(QStringLiteral("Action"));
2955 hamburgerMenuElement.setAttribute(QStringLiteral("name"), QStringLiteral("hamburger_menu"));
2956 toolbar.appendChild(hamburgerMenuElement);
2957
2958 KXMLGUIFactory::saveConfigFile(domDocument, xmlFile());
2959 reloadXML();
2960 createGUI();
2961 return true;
2962 // Make sure to also remove the <KXMLGUIFactory> and <QDomDocument> include
2963 // whenever this method is removed (maybe in the year ~2026).
2964 }
2965
2966 // Set a sane initial window size
2967 QSize DolphinMainWindow::sizeHint() const
2968 {
2969 return KXmlGuiWindow::sizeHint().expandedTo(QSize(760, 550));
2970 }
2971
2972 void DolphinMainWindow::saveNewToolbarConfig()
2973 {
2974 KXmlGuiWindow::saveNewToolbarConfig(); // Applies the new config. This has to be called first
2975 // because the rest of this method decides things
2976 // based on the new config.
2977 auto navigators = static_cast<DolphinNavigatorsWidgetAction *>(actionCollection()->action(QStringLiteral("url_navigators")));
2978 if (!toolBar()->actions().contains(navigators)) {
2979 m_tabWidget->currentTabPage()->insertNavigatorsWidget(navigators);
2980 }
2981 updateAllowedToolbarAreas();
2982 updateNavigatorsBackground();
2983 (static_cast<KHamburgerMenu *>(actionCollection()->action(KStandardAction::name(KStandardAction::HamburgerMenu))))->hideActionsOf(toolBar());
2984 }
2985
2986 void DolphinMainWindow::toggleTerminalPanelFocus()
2987 {
2988 if (!m_terminalPanel->isVisible()) {
2989 actionCollection()->action(QStringLiteral("show_terminal_panel"))->trigger(); // Also moves focus to the panel.
2990 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
2991 return;
2992 }
2993
2994 if (m_terminalPanel->terminalHasFocus()) {
2995 m_activeViewContainer->view()->setFocus(Qt::FocusReason::ShortcutFocusReason);
2996 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
2997 return;
2998 }
2999
3000 m_terminalPanel->setFocus(Qt::FocusReason::ShortcutFocusReason);
3001 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
3002 }
3003
3004 void DolphinMainWindow::togglePlacesPanelFocus()
3005 {
3006 if (!m_placesPanel->isVisible()) {
3007 actionCollection()->action(QStringLiteral("show_places_panel"))->trigger(); // Also moves focus to the panel.
3008 actionCollection()->action(QStringLiteral("focus_places_panel"))->setText(i18nc("@action:inmenu View", "Defocus Terminal Panel"));
3009 return;
3010 }
3011
3012 if (m_placesPanel->hasFocus()) {
3013 m_activeViewContainer->view()->setFocus(Qt::FocusReason::ShortcutFocusReason);
3014 actionCollection()->action(QStringLiteral("focus_places_panel"))->setText(i18nc("@action:inmenu View", "Focus Places Panel"));
3015 return;
3016 }
3017
3018 m_placesPanel->setFocus(Qt::FocusReason::ShortcutFocusReason);
3019 actionCollection()->action(QStringLiteral("focus_places_panel"))->setText(i18nc("@action:inmenu View", "Defocus Places Panel"));
3020 }
3021
3022 DolphinMainWindow::UndoUiInterface::UndoUiInterface()
3023 : KIO::FileUndoManager::UiInterface()
3024 {
3025 }
3026
3027 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
3028 {
3029 }
3030
3031 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job *job)
3032 {
3033 DolphinMainWindow *mainWin = qobject_cast<DolphinMainWindow *>(parentWidget());
3034 if (mainWin) {
3035 DolphinViewContainer *container = mainWin->activeViewContainer();
3036 container->showMessage(job->errorString(), KMessageWidget::Error);
3037 } else {
3038 KIO::FileUndoManager::UiInterface::jobError(job);
3039 }
3040 }
3041
3042 bool DolphinMainWindow::isUrlOpen(const QString &url)
3043 {
3044 return m_tabWidget->isUrlOpen(QUrl::fromUserInput(url));
3045 }
3046
3047 bool DolphinMainWindow::isItemVisibleInAnyView(const QString &urlOfItem)
3048 {
3049 return m_tabWidget->isItemVisibleInAnyView(QUrl::fromUserInput(urlOfItem));
3050 }
3051
3052 void DolphinMainWindow::slotDoubleClickViewBackground(Qt::MouseButton button)
3053 {
3054 if (button != Qt::MouseButton::LeftButton) {
3055 // only handle left mouse button for now
3056 return;
3057 }
3058
3059 GeneralSettings *settings = GeneralSettings::self();
3060 QString clickAction = settings->doubleClickViewAction();
3061
3062 DolphinView *view = activeViewContainer()->view();
3063 if (view == nullptr || clickAction == "none") {
3064 return;
3065 }
3066
3067 if (clickAction == customCommand) {
3068 // run custom command set by the user
3069 QString path = view->url().toLocalFile();
3070 QString clickCustomAction = settings->doubleClickViewCustomAction();
3071 clickCustomAction.replace("{path}", path.prepend('"').append('"'));
3072
3073 m_job = new KIO::CommandLauncherJob(clickCustomAction);
3074 m_job->setUiDelegate(new KDialogJobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, this));
3075 m_job->start();
3076
3077 } else {
3078 // get the action set by the user and trigger it
3079 const KActionCollection *actions = actionCollection();
3080 QAction *action = actions->action(clickAction);
3081 if (action == nullptr) {
3082 qCWarning(DolphinDebug) << QStringLiteral("Double-click view: action `%1` was not found").arg(clickAction);
3083 return;
3084 }
3085 action->trigger();
3086 }
3087 }
3088
3089 #include "moc_dolphinmainwindow.cpp"