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