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