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