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