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