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