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