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