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