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