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