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