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