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