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