]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinmainwindow.cpp
DolphinMainWindow: autosave session
[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 updateSplitAction();
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::toggleSplitStash()
988 {
989 DolphinTabPage *tabPage = m_tabWidget->currentTabPage();
990 tabPage->setSplitViewEnabled(false, WithAnimation);
991 tabPage->setSplitViewEnabled(true, WithAnimation, QUrl("stash:/"));
992 }
993
994 void DolphinMainWindow::copyToInactiveSplitView()
995 {
996 if (m_activeViewContainer->view()->selectedItems().isEmpty()) {
997 m_activeViewContainer->setSelectionModeEnabled(true, actionCollection(), SelectionMode::BottomBar::Contents::CopyToOtherViewContents);
998 } else {
999 m_tabWidget->copyToInactiveSplitView();
1000 m_activeViewContainer->setSelectionModeEnabled(false);
1001 }
1002 }
1003
1004 void DolphinMainWindow::moveToInactiveSplitView()
1005 {
1006 if (m_activeViewContainer->view()->selectedItems().isEmpty()) {
1007 m_activeViewContainer->setSelectionModeEnabled(true, actionCollection(), SelectionMode::BottomBar::Contents::MoveToOtherViewContents);
1008 } else {
1009 m_tabWidget->moveToInactiveSplitView();
1010 m_activeViewContainer->setSelectionModeEnabled(false);
1011 }
1012 }
1013
1014 void DolphinMainWindow::reloadView()
1015 {
1016 clearStatusBar();
1017 m_activeViewContainer->reload();
1018 m_activeViewContainer->statusBar()->updateSpaceInfo();
1019 }
1020
1021 void DolphinMainWindow::stopLoading()
1022 {
1023 m_activeViewContainer->view()->stopLoading();
1024 }
1025
1026 void DolphinMainWindow::enableStopAction()
1027 {
1028 actionCollection()->action(QStringLiteral("stop"))->setEnabled(true);
1029 }
1030
1031 void DolphinMainWindow::disableStopAction()
1032 {
1033 actionCollection()->action(QStringLiteral("stop"))->setEnabled(false);
1034 }
1035
1036 void DolphinMainWindow::toggleSelectionMode()
1037 {
1038 const bool checked = !m_activeViewContainer->isSelectionModeEnabled();
1039
1040 m_activeViewContainer->setSelectionModeEnabled(checked, actionCollection(), SelectionMode::BottomBar::Contents::GeneralContents);
1041 actionCollection()->action(QStringLiteral("toggle_selection_mode"))->setChecked(checked);
1042 }
1043
1044 void DolphinMainWindow::showFilterBar()
1045 {
1046 m_activeViewContainer->setFilterBarVisible(true);
1047 }
1048
1049 void DolphinMainWindow::toggleFilterBar()
1050 {
1051 const bool checked = !m_activeViewContainer->isFilterBarVisible();
1052 m_activeViewContainer->setFilterBarVisible(checked);
1053
1054 QAction *toggleFilterBarAction = actionCollection()->action(QStringLiteral("toggle_filter"));
1055 toggleFilterBarAction->setChecked(checked);
1056 }
1057
1058 void DolphinMainWindow::toggleEditLocation()
1059 {
1060 clearStatusBar();
1061
1062 QAction *action = actionCollection()->action(QStringLiteral("editable_location"));
1063 KUrlNavigator *urlNavigator = m_activeViewContainer->urlNavigator();
1064 urlNavigator->setUrlEditable(action->isChecked());
1065 }
1066
1067 void DolphinMainWindow::replaceLocation()
1068 {
1069 KUrlNavigator *navigator = m_activeViewContainer->urlNavigator();
1070 QLineEdit *lineEdit = navigator->editor()->lineEdit();
1071
1072 // If the text field currently has focus and everything is selected,
1073 // pressing the keyboard shortcut returns the whole thing to breadcrumb mode
1074 if (navigator->isUrlEditable() && lineEdit->hasFocus() && lineEdit->selectedText() == lineEdit->text()) {
1075 navigator->setUrlEditable(false);
1076 } else {
1077 navigator->setUrlEditable(true);
1078 navigator->setFocus();
1079 lineEdit->selectAll();
1080 }
1081 }
1082
1083 void DolphinMainWindow::togglePanelLockState()
1084 {
1085 const bool newLockState = !GeneralSettings::lockPanels();
1086 const auto childrenObjects = children();
1087 for (QObject *child : childrenObjects) {
1088 DolphinDockWidget *dock = qobject_cast<DolphinDockWidget *>(child);
1089 if (dock) {
1090 dock->setLocked(newLockState);
1091 }
1092 }
1093
1094 DolphinPlacesModelSingleton::instance().placesModel()->setPanelsLocked(newLockState);
1095
1096 GeneralSettings::setLockPanels(newLockState);
1097 }
1098
1099 void DolphinMainWindow::slotTerminalPanelVisibilityChanged()
1100 {
1101 if (m_terminalPanel->isHiddenInVisibleWindow() && m_activeViewContainer) {
1102 m_activeViewContainer->view()->setFocus();
1103 }
1104 }
1105
1106 void DolphinMainWindow::goBack()
1107 {
1108 DolphinUrlNavigator *urlNavigator = m_activeViewContainer->urlNavigatorInternalWithHistory();
1109 urlNavigator->goBack();
1110
1111 if (urlNavigator->locationState().isEmpty()) {
1112 // An empty location state indicates a redirection URL,
1113 // which must be skipped too
1114 urlNavigator->goBack();
1115 }
1116 }
1117
1118 void DolphinMainWindow::goForward()
1119 {
1120 m_activeViewContainer->urlNavigatorInternalWithHistory()->goForward();
1121 }
1122
1123 void DolphinMainWindow::goUp()
1124 {
1125 m_activeViewContainer->urlNavigatorInternalWithHistory()->goUp();
1126 }
1127
1128 void DolphinMainWindow::goHome()
1129 {
1130 m_activeViewContainer->urlNavigatorInternalWithHistory()->goHome();
1131 }
1132
1133 void DolphinMainWindow::goBackInNewTab()
1134 {
1135 const KUrlNavigator *urlNavigator = activeViewContainer()->urlNavigatorInternalWithHistory();
1136 const int index = urlNavigator->historyIndex() + 1;
1137 openNewTab(urlNavigator->locationUrl(index));
1138 }
1139
1140 void DolphinMainWindow::goForwardInNewTab()
1141 {
1142 const KUrlNavigator *urlNavigator = activeViewContainer()->urlNavigatorInternalWithHistory();
1143 const int index = urlNavigator->historyIndex() - 1;
1144 openNewTab(urlNavigator->locationUrl(index));
1145 }
1146
1147 void DolphinMainWindow::goUpInNewTab()
1148 {
1149 const QUrl currentUrl = activeViewContainer()->urlNavigator()->locationUrl();
1150 openNewTab(KIO::upUrl(currentUrl));
1151 }
1152
1153 void DolphinMainWindow::goHomeInNewTab()
1154 {
1155 openNewTab(Dolphin::homeUrl());
1156 }
1157
1158 void DolphinMainWindow::compareFiles()
1159 {
1160 const KFileItemList items = m_tabWidget->currentTabPage()->selectedItems();
1161 if (items.count() != 2) {
1162 // The action is disabled in this case, but it could have been triggered
1163 // via D-Bus, see https://bugs.kde.org/show_bug.cgi?id=325517
1164 return;
1165 }
1166
1167 QUrl urlA = items.at(0).url();
1168 QUrl urlB = items.at(1).url();
1169
1170 QString command(QStringLiteral("kompare -c \""));
1171 command.append(urlA.toDisplayString(QUrl::PreferLocalFile));
1172 command.append("\" \"");
1173 command.append(urlB.toDisplayString(QUrl::PreferLocalFile));
1174 command.append('\"');
1175
1176 KIO::CommandLauncherJob *job = new KIO::CommandLauncherJob(command, this);
1177 job->setDesktopName(QStringLiteral("org.kde.kompare"));
1178 job->start();
1179 }
1180
1181 void DolphinMainWindow::toggleShowMenuBar()
1182 {
1183 const bool visible = menuBar()->isVisible();
1184 menuBar()->setVisible(!visible);
1185 }
1186
1187 QPointer<QAction> DolphinMainWindow::preferredSearchTool()
1188 {
1189 m_searchTools.clear();
1190
1191 KService::Ptr kfind = KService::serviceByDesktopName(QStringLiteral("org.kde.kfind"));
1192
1193 if (!kfind) {
1194 return nullptr;
1195 }
1196
1197 auto *action = new QAction(QIcon::fromTheme(kfind->icon()), kfind->name(), this);
1198
1199 connect(action, &QAction::triggered, this, [kfind] {
1200 auto *job = new KIO::ApplicationLauncherJob(kfind);
1201 job->start();
1202 });
1203
1204 return action;
1205 }
1206
1207 void DolphinMainWindow::updateOpenPreferredSearchToolAction()
1208 {
1209 QAction *openPreferredSearchTool = actionCollection()->action(QStringLiteral("open_preferred_search_tool"));
1210 if (!openPreferredSearchTool) {
1211 return;
1212 }
1213 QPointer<QAction> tool = preferredSearchTool();
1214 if (tool) {
1215 openPreferredSearchTool->setVisible(true);
1216 openPreferredSearchTool->setText(i18nc("@action:inmenu Tools", "Open %1", tool->text()));
1217 // Only override with the app icon if it is the default, i.e. the user hasn't configured one manually
1218 // https://bugs.kde.org/show_bug.cgi?id=442815
1219 if (openPreferredSearchTool->icon().name() == QLatin1String("search")) {
1220 openPreferredSearchTool->setIcon(tool->icon());
1221 }
1222 } else {
1223 openPreferredSearchTool->setVisible(false);
1224 // still visible in Shortcuts configuration window
1225 openPreferredSearchTool->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool"));
1226 openPreferredSearchTool->setIcon(QIcon::fromTheme(QStringLiteral("search")));
1227 }
1228 }
1229
1230 void DolphinMainWindow::openPreferredSearchTool()
1231 {
1232 QPointer<QAction> tool = preferredSearchTool();
1233 if (tool) {
1234 tool->trigger();
1235 }
1236 }
1237
1238 void DolphinMainWindow::openTerminal()
1239 {
1240 openTerminalJob(m_activeViewContainer->url());
1241 }
1242
1243 void DolphinMainWindow::openTerminalHere()
1244 {
1245 QList<QUrl> urls = {};
1246
1247 const auto selectedItems = m_activeViewContainer->view()->selectedItems();
1248 for (const KFileItem &item : selectedItems) {
1249 QUrl url = item.targetUrl();
1250 if (item.isFile()) {
1251 url.setPath(QFileInfo(url.path()).absolutePath());
1252 }
1253 if (!urls.contains(url)) {
1254 urls << url;
1255 }
1256 }
1257
1258 // No items are selected. Open a terminal window for the current location.
1259 if (urls.count() == 0) {
1260 openTerminal();
1261 return;
1262 }
1263
1264 if (urls.count() > 5) {
1265 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());
1266 const int answer = KMessageBox::warningContinueCancel(
1267 this,
1268 question,
1269 {},
1270 KGuiItem(i18ncp("@action:button", "Open %1 Terminal", "Open %1 Terminals", urls.count()), QStringLiteral("utilities-terminal")),
1271 KStandardGuiItem::cancel(),
1272 QStringLiteral("ConfirmOpenManyTerminals"));
1273 if (answer != KMessageBox::PrimaryAction && answer != KMessageBox::Continue) {
1274 return;
1275 }
1276 }
1277
1278 for (const QUrl &url : std::as_const(urls)) {
1279 openTerminalJob(url);
1280 }
1281 }
1282
1283 void DolphinMainWindow::openTerminalJob(const QUrl &url)
1284 {
1285 if (url.isLocalFile()) {
1286 auto job = new KTerminalLauncherJob(QString());
1287 job->setWorkingDirectory(url.toLocalFile());
1288 job->start();
1289 return;
1290 }
1291
1292 // Not a local file, with protocol Class ":local", try stat'ing
1293 if (KProtocolInfo::protocolClass(url.scheme()) == QLatin1String(":local")) {
1294 KIO::StatJob *job = KIO::mostLocalUrl(url);
1295 KJobWidgets::setWindow(job, this);
1296 connect(job, &KJob::result, this, [job]() {
1297 QUrl statUrl;
1298 if (!job->error()) {
1299 statUrl = job->mostLocalUrl();
1300 }
1301
1302 auto job = new KTerminalLauncherJob(QString());
1303 job->setWorkingDirectory(statUrl.isLocalFile() ? statUrl.toLocalFile() : QDir::homePath());
1304 job->start();
1305 });
1306
1307 return;
1308 }
1309
1310 // Nothing worked, just use $HOME
1311 auto job = new KTerminalLauncherJob(QString());
1312 job->setWorkingDirectory(QDir::homePath());
1313 job->start();
1314 }
1315
1316 void DolphinMainWindow::editSettings()
1317 {
1318 if (!m_settingsDialog) {
1319 DolphinViewContainer *container = activeViewContainer();
1320 container->view()->writeSettings();
1321
1322 const QUrl url = container->url();
1323 DolphinSettingsDialog *settingsDialog = new DolphinSettingsDialog(url, this, actionCollection());
1324 connect(settingsDialog, &DolphinSettingsDialog::settingsChanged, this, &DolphinMainWindow::refreshViews);
1325 connect(settingsDialog, &DolphinSettingsDialog::settingsChanged, &DolphinUrlNavigatorsController::slotReadSettings);
1326 settingsDialog->setAttribute(Qt::WA_DeleteOnClose);
1327 settingsDialog->show();
1328 m_settingsDialog = settingsDialog;
1329 } else {
1330 m_settingsDialog.data()->raise();
1331 }
1332 }
1333
1334 void DolphinMainWindow::handleUrl(const QUrl &url)
1335 {
1336 delete m_lastHandleUrlOpenJob;
1337 m_lastHandleUrlOpenJob = nullptr;
1338
1339 if (url.isLocalFile() && QFileInfo(url.toLocalFile()).isDir()) {
1340 activeViewContainer()->setUrl(url);
1341 } else {
1342 m_lastHandleUrlOpenJob = new KIO::OpenUrlJob(url);
1343 m_lastHandleUrlOpenJob->setUiDelegate(KIO::createDefaultJobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, this));
1344 m_lastHandleUrlOpenJob->setShowOpenOrExecuteDialog(true);
1345
1346 connect(m_lastHandleUrlOpenJob, &KIO::OpenUrlJob::mimeTypeFound, this, [this, url](const QString &mimetype) {
1347 if (mimetype == QLatin1String("inode/directory")) {
1348 // If it's a dir, we'll take it from here
1349 m_lastHandleUrlOpenJob->kill();
1350 m_lastHandleUrlOpenJob = nullptr;
1351 activeViewContainer()->setUrl(url);
1352 }
1353 });
1354
1355 connect(m_lastHandleUrlOpenJob, &KIO::OpenUrlJob::result, this, [this]() {
1356 m_lastHandleUrlOpenJob = nullptr;
1357 });
1358
1359 m_lastHandleUrlOpenJob->start();
1360 }
1361 }
1362
1363 void DolphinMainWindow::slotWriteStateChanged(bool isFolderWritable)
1364 {
1365 // trash:/ is writable but we don't want to create new items in it.
1366 // TODO: remove the trash check once https://phabricator.kde.org/T8234 is implemented
1367 newFileMenu()->setEnabled(isFolderWritable && m_activeViewContainer->url().scheme() != QLatin1String("trash"));
1368 }
1369
1370 void DolphinMainWindow::openContextMenu(const QPoint &pos, const KFileItem &item, const KFileItemList &selectedItems, const QUrl &url)
1371 {
1372 QPointer<DolphinContextMenu> contextMenu = new DolphinContextMenu(this, item, selectedItems, url, &m_fileItemActions);
1373 contextMenu->exec(pos);
1374
1375 // Delete the menu, unless it has been deleted in its own nested event loop already.
1376 if (contextMenu) {
1377 contextMenu->deleteLater();
1378 }
1379 }
1380
1381 QMenu *DolphinMainWindow::createPopupMenu()
1382 {
1383 QMenu *menu = KXmlGuiWindow::createPopupMenu();
1384
1385 menu->addSeparator();
1386 menu->addAction(actionCollection()->action(QStringLiteral("lock_panels")));
1387
1388 return menu;
1389 }
1390
1391 void DolphinMainWindow::updateHamburgerMenu()
1392 {
1393 KActionCollection *ac = actionCollection();
1394 auto hamburgerMenu = static_cast<KHamburgerMenu *>(ac->action(KStandardAction::name(KStandardAction::HamburgerMenu)));
1395 auto menu = hamburgerMenu->menu();
1396 if (!menu) {
1397 menu = new QMenu(this);
1398 hamburgerMenu->setMenu(menu);
1399 hamburgerMenu->hideActionsOf(ac->action(QStringLiteral("basic_actions"))->menu());
1400 hamburgerMenu->hideActionsOf(ac->action(QStringLiteral("zoom"))->menu());
1401 } else {
1402 menu->clear();
1403 }
1404 const QList<QAction *> toolbarActions = toolBar()->actions();
1405
1406 if (!toolBar()->isVisible()) {
1407 // If neither the menu bar nor the toolbar are visible, these actions should be available.
1408 menu->addAction(ac->action(KStandardAction::name(KStandardAction::ShowMenubar)));
1409 menu->addAction(toolBarMenuAction());
1410 menu->addSeparator();
1411 }
1412
1413 // This group of actions (until the next separator) contains all the most basic actions
1414 // necessary to use Dolphin effectively.
1415 menu->addAction(ac->action(QStringLiteral("go_back")));
1416 menu->addAction(ac->action(QStringLiteral("go_forward")));
1417
1418 menu->addMenu(m_newFileMenu->menu());
1419 if (!toolBar()->isVisible() || !toolbarActions.contains(ac->action(QStringLiteral("toggle_selection_mode_tool_bar")))) {
1420 menu->addAction(ac->action(QStringLiteral("toggle_selection_mode")));
1421 }
1422 menu->addAction(ac->action(QStringLiteral("basic_actions")));
1423 menu->addAction(ac->action(KStandardAction::name(KStandardAction::Undo)));
1424 if (!toolBar()->isVisible()
1425 || (!toolbarActions.contains(ac->action(QStringLiteral("toggle_search")))
1426 && !toolbarActions.contains(ac->action(QStringLiteral("open_preferred_search_tool"))))) {
1427 menu->addAction(ac->action(KStandardAction::name(KStandardAction::Find)));
1428 // This way a search action will only be added if none of the three available
1429 // search actions is present on the toolbar.
1430 }
1431 if (!toolBar()->isVisible() || !toolbarActions.contains(ac->action(QStringLiteral("toggle_filter")))) {
1432 menu->addAction(ac->action(QStringLiteral("show_filter_bar")));
1433 // This way a filter action will only be added if none of the two available
1434 // filter actions is present on the toolbar.
1435 }
1436 menu->addSeparator();
1437
1438 // The second group of actions (up until the next separator) contains actions for opening
1439 // additional views to interact with the file system.
1440 menu->addAction(ac->action(QStringLiteral("file_new")));
1441 menu->addAction(ac->action(QStringLiteral("new_tab")));
1442 if (ac->action(QStringLiteral("undo_close_tab"))->isEnabled()) {
1443 menu->addAction(ac->action(QStringLiteral("closed_tabs")));
1444 }
1445 menu->addAction(ac->action(QStringLiteral("open_terminal")));
1446 menu->addSeparator();
1447
1448 // The third group contains actions to change what one sees in the view
1449 // and to change the more general UI.
1450 if (!toolBar()->isVisible()
1451 || (!toolbarActions.contains(ac->action(QStringLiteral("icons"))) && !toolbarActions.contains(ac->action(QStringLiteral("compact")))
1452 && !toolbarActions.contains(ac->action(QStringLiteral("details"))) && !toolbarActions.contains(ac->action(QStringLiteral("view_mode"))))) {
1453 menu->addAction(ac->action(QStringLiteral("view_mode")));
1454 }
1455 menu->addAction(ac->action(QStringLiteral("show_hidden_files")));
1456 menu->addAction(ac->action(QStringLiteral("sort")));
1457 menu->addAction(ac->action(QStringLiteral("additional_info")));
1458 if (!GeneralSettings::showStatusBar() || !GeneralSettings::showZoomSlider()) {
1459 menu->addAction(ac->action(QStringLiteral("zoom")));
1460 }
1461 menu->addAction(ac->action(QStringLiteral("panels")));
1462
1463 // The "Configure" menu is not added to the actionCollection() because there is hardly
1464 // a good reason for users to put it on their toolbar.
1465 auto configureMenu = menu->addMenu(QIcon::fromTheme(QStringLiteral("configure")), i18nc("@action:inmenu menu for configure actions", "Configure"));
1466 configureMenu->addAction(ac->action(KStandardAction::name(KStandardAction::SwitchApplicationLanguage)));
1467 configureMenu->addAction(ac->action(KStandardAction::name(KStandardAction::KeyBindings)));
1468 configureMenu->addAction(ac->action(KStandardAction::name(KStandardAction::ConfigureToolbars)));
1469 configureMenu->addAction(ac->action(KStandardAction::name(KStandardAction::Preferences)));
1470 hamburgerMenu->hideActionsOf(configureMenu);
1471 }
1472
1473 void DolphinMainWindow::slotPlaceActivated(const QUrl &url)
1474 {
1475 DolphinViewContainer *view = activeViewContainer();
1476
1477 if (view->url() == url) {
1478 view->clearFilterBar(); // Fixes bug 259382.
1479
1480 // We can end up here if the user clicked a device in the Places Panel
1481 // which had been unmounted earlier, see https://bugs.kde.org/show_bug.cgi?id=161385.
1482 reloadView();
1483 } else {
1484 view->disableUrlNavigatorSelectionRequests();
1485 changeUrl(url);
1486 view->enableUrlNavigatorSelectionRequests();
1487 }
1488 }
1489
1490 void DolphinMainWindow::closedTabsCountChanged(unsigned int count)
1491 {
1492 actionCollection()->action(QStringLiteral("undo_close_tab"))->setEnabled(count > 0);
1493 }
1494
1495 void DolphinMainWindow::activeViewChanged(DolphinViewContainer *viewContainer)
1496 {
1497 DolphinViewContainer *oldViewContainer = m_activeViewContainer;
1498 Q_ASSERT(viewContainer);
1499
1500 m_activeViewContainer = viewContainer;
1501
1502 if (oldViewContainer) {
1503 const QAction *toggleSearchAction = actionCollection()->action(QStringLiteral("toggle_search"));
1504 toggleSearchAction->disconnect(oldViewContainer);
1505
1506 // Disconnect all signals between the old view container (container,
1507 // view and url navigator) and main window.
1508 oldViewContainer->disconnect(this);
1509 oldViewContainer->view()->disconnect(this);
1510 oldViewContainer->urlNavigatorInternalWithHistory()->disconnect(this);
1511 auto navigators = static_cast<DolphinNavigatorsWidgetAction *>(actionCollection()->action(QStringLiteral("url_navigators")));
1512 navigators->primaryUrlNavigator()->disconnect(this);
1513 if (auto secondaryUrlNavigator = navigators->secondaryUrlNavigator()) {
1514 secondaryUrlNavigator->disconnect(this);
1515 }
1516
1517 // except the requestItemInfo so that on hover the information panel can still be updated
1518 connect(oldViewContainer->view(), &DolphinView::requestItemInfo, this, &DolphinMainWindow::requestItemInfo);
1519
1520 // Disconnect other slots.
1521 disconnect(oldViewContainer,
1522 &DolphinViewContainer::selectionModeChanged,
1523 actionCollection()->action(QStringLiteral("toggle_selection_mode")),
1524 &QAction::setChecked);
1525 }
1526
1527 connectViewSignals(viewContainer);
1528
1529 m_actionHandler->setCurrentView(viewContainer->view());
1530
1531 updateHistory();
1532 updateFileAndEditActions();
1533 updatePasteAction();
1534 updateViewActions();
1535 updateGoActions();
1536 updateSearchAction();
1537
1538 const QUrl url = viewContainer->url();
1539 Q_EMIT urlChanged(url);
1540 }
1541
1542 void DolphinMainWindow::tabCountChanged(int count)
1543 {
1544 const bool enableTabActions = (count > 1);
1545 for (int i = 0; i < MaxActivateTabShortcuts; ++i) {
1546 actionCollection()->action(QStringLiteral("activate_tab_%1").arg(i))->setEnabled(enableTabActions);
1547 }
1548 actionCollection()->action(QStringLiteral("activate_last_tab"))->setEnabled(enableTabActions);
1549 actionCollection()->action(QStringLiteral("activate_next_tab"))->setEnabled(enableTabActions);
1550 actionCollection()->action(QStringLiteral("activate_prev_tab"))->setEnabled(enableTabActions);
1551 }
1552
1553 void DolphinMainWindow::updateWindowTitle()
1554 {
1555 const QString newTitle = m_activeViewContainer->captionWindowTitle();
1556 if (windowTitle() != newTitle) {
1557 setWindowTitle(newTitle);
1558 }
1559 }
1560
1561 void DolphinMainWindow::slotStorageTearDownFromPlacesRequested(const QString &mountPath)
1562 {
1563 connect(m_placesPanel, &PlacesPanel::storageTearDownSuccessful, this, [this, mountPath]() {
1564 setViewsToHomeIfMountPathOpen(mountPath);
1565 });
1566
1567 if (m_terminalPanel && m_terminalPanel->currentWorkingDirectoryIsChildOf(mountPath)) {
1568 m_tearDownFromPlacesRequested = true;
1569 m_terminalPanel->goHome();
1570 // m_placesPanel->proceedWithTearDown() will be called in slotTerminalDirectoryChanged
1571 } else {
1572 m_placesPanel->proceedWithTearDown();
1573 }
1574 }
1575
1576 void DolphinMainWindow::slotStorageTearDownExternallyRequested(const QString &mountPath)
1577 {
1578 connect(m_placesPanel, &PlacesPanel::storageTearDownSuccessful, this, [this, mountPath]() {
1579 setViewsToHomeIfMountPathOpen(mountPath);
1580 });
1581
1582 if (m_terminalPanel && m_terminalPanel->currentWorkingDirectoryIsChildOf(mountPath)) {
1583 m_tearDownFromPlacesRequested = false;
1584 m_terminalPanel->goHome();
1585 }
1586 }
1587
1588 void DolphinMainWindow::slotKeyBindings()
1589 {
1590 KShortcutsDialog dialog(KShortcutsEditor::AllActions, KShortcutsEditor::LetterShortcutsAllowed, this);
1591 dialog.addCollection(actionCollection());
1592 if (m_terminalPanel) {
1593 KActionCollection *konsolePartActionCollection = m_terminalPanel->actionCollection();
1594 if (konsolePartActionCollection) {
1595 dialog.addCollection(konsolePartActionCollection, QStringLiteral("KonsolePart"));
1596 }
1597 }
1598 dialog.configure();
1599 }
1600
1601 void DolphinMainWindow::setViewsToHomeIfMountPathOpen(const QString &mountPath)
1602 {
1603 const QVector<DolphinViewContainer *> theViewContainers = viewContainers();
1604 for (DolphinViewContainer *viewContainer : theViewContainers) {
1605 if (viewContainer && viewContainer->url().toLocalFile().startsWith(mountPath)) {
1606 viewContainer->setUrl(QUrl::fromLocalFile(QDir::homePath()));
1607 }
1608 }
1609 disconnect(m_placesPanel, &PlacesPanel::storageTearDownSuccessful, nullptr, nullptr);
1610 }
1611
1612 void DolphinMainWindow::setupActions()
1613 {
1614 auto hamburgerMenuAction = KStandardAction::hamburgerMenu(nullptr, nullptr, actionCollection());
1615
1616 // setup 'File' menu
1617 m_newFileMenu = new DolphinNewFileMenu(nullptr, this);
1618 actionCollection()->addAction(QStringLiteral("new_menu"), m_newFileMenu);
1619 QMenu *menu = m_newFileMenu->menu();
1620 menu->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1621 menu->setIcon(QIcon::fromTheme(QStringLiteral("list-add")));
1622 m_newFileMenu->setPopupMode(QToolButton::InstantPopup);
1623 connect(menu, &QMenu::aboutToShow, this, &DolphinMainWindow::updateNewMenu);
1624
1625 QAction *newWindow = KStandardAction::openNew(this, &DolphinMainWindow::openNewMainWindow, actionCollection());
1626 newWindow->setText(i18nc("@action:inmenu File", "New &Window"));
1627 newWindow->setToolTip(i18nc("@info", "Open a new Dolphin window"));
1628 newWindow->setWhatsThis(xi18nc("@info:whatsthis",
1629 "This opens a new "
1630 "window just like this one with the current location and view."
1631 "<nl/>You can drag and drop items between windows."));
1632 newWindow->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
1633
1634 QAction *newTab = actionCollection()->addAction(QStringLiteral("new_tab"));
1635 newTab->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1636 newTab->setText(i18nc("@action:inmenu File", "New Tab"));
1637 newTab->setWhatsThis(xi18nc("@info:whatsthis",
1638 "This opens a new "
1639 "<emphasis>Tab</emphasis> with the current location and view.<nl/>"
1640 "A tab is an additional view within this window. "
1641 "You can drag and drop items between tabs."));
1642 actionCollection()->setDefaultShortcut(newTab, Qt::CTRL | Qt::Key_T);
1643 connect(newTab, &QAction::triggered, this, &DolphinMainWindow::openNewActivatedTab);
1644
1645 QAction *addToPlaces = actionCollection()->addAction(QStringLiteral("add_to_places"));
1646 addToPlaces->setIcon(QIcon::fromTheme(QStringLiteral("bookmark-new")));
1647 addToPlaces->setText(i18nc("@action:inmenu Add current folder to places", "Add to Places"));
1648 addToPlaces->setWhatsThis(xi18nc("@info:whatsthis",
1649 "This adds the selected folder "
1650 "to the Places panel."));
1651 connect(addToPlaces, &QAction::triggered, this, &DolphinMainWindow::addToPlaces);
1652
1653 QAction *closeTab = KStandardAction::close(m_tabWidget, QOverload<>::of(&DolphinTabWidget::closeTab), actionCollection());
1654 closeTab->setText(i18nc("@action:inmenu File", "Close Tab"));
1655 closeTab->setWhatsThis(i18nc("@info:whatsthis",
1656 "This closes the "
1657 "currently viewed tab. If no more tabs are left this window "
1658 "will close instead."));
1659
1660 QAction *quitAction = KStandardAction::quit(this, &DolphinMainWindow::quit, actionCollection());
1661 quitAction->setWhatsThis(i18nc("@info:whatsthis quit", "This closes this window."));
1662
1663 // setup 'Edit' menu
1664 KStandardAction::undo(this, &DolphinMainWindow::undo, actionCollection());
1665
1666 // i18n: This will be the last paragraph for the whatsthis for all three:
1667 // Cut, Copy and Paste
1668 const QString cutCopyPastePara = xi18nc("@info:whatsthis",
1669 "<para><emphasis>Cut, "
1670 "Copy</emphasis> and <emphasis>Paste</emphasis> work between many "
1671 "applications and are among the most used commands. That's why their "
1672 "<emphasis>keyboard shortcuts</emphasis> are prominently placed right "
1673 "next to each other on the keyboard: <shortcut>Ctrl+X</shortcut>, "
1674 "<shortcut>Ctrl+C</shortcut> and <shortcut>Ctrl+V</shortcut>.</para>");
1675 QAction *cutAction = KStandardAction::cut(this, &DolphinMainWindow::cut, actionCollection());
1676 m_actionTextHelper->registerTextWhenNothingIsSelected(cutAction, i18nc("@action", "Cut…"));
1677 cutAction->setWhatsThis(xi18nc("@info:whatsthis cut",
1678 "This copies the items "
1679 "in your current selection to the <emphasis>clipboard</emphasis>.<nl/>"
1680 "Use the <emphasis>Paste</emphasis> action afterwards to copy them from "
1681 "the clipboard to a new location. The items will be removed from their "
1682 "initial location.")
1683 + cutCopyPastePara);
1684 QAction *copyAction = KStandardAction::copy(this, &DolphinMainWindow::copy, actionCollection());
1685 m_actionTextHelper->registerTextWhenNothingIsSelected(copyAction, i18nc("@action", "Copy…"));
1686 copyAction->setWhatsThis(xi18nc("@info:whatsthis copy",
1687 "This copies the "
1688 "items in your current selection to the <emphasis>clipboard</emphasis>."
1689 "<nl/>Use the <emphasis>Paste</emphasis> action afterwards to copy them "
1690 "from the clipboard to a new location.")
1691 + cutCopyPastePara);
1692 QAction *paste = KStandardAction::paste(this, &DolphinMainWindow::paste, actionCollection());
1693 // The text of the paste-action is modified dynamically by Dolphin
1694 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1695 // due to the long text, the text "Paste" is used:
1696 paste->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1697 paste->setWhatsThis(xi18nc("@info:whatsthis paste",
1698 "This copies the items from "
1699 "your <emphasis>clipboard</emphasis> to the currently viewed folder.<nl/>"
1700 "If the items were added to the clipboard by the <emphasis>Cut</emphasis> "
1701 "action they are removed from their old location.")
1702 + cutCopyPastePara);
1703
1704 QAction *copyToOtherViewAction = actionCollection()->addAction(QStringLiteral("copy_to_inactive_split_view"));
1705 copyToOtherViewAction->setText(i18nc("@action:inmenu", "Copy to Other View"));
1706 m_actionTextHelper->registerTextWhenNothingIsSelected(copyToOtherViewAction, i18nc("@action:inmenu", "Copy to Other View…"));
1707 copyToOtherViewAction->setWhatsThis(xi18nc("@info:whatsthis Copy",
1708 "This copies the selected items from "
1709 "the <emphasis>active</emphasis> view to the inactive split view."));
1710 copyToOtherViewAction->setIcon(QIcon::fromTheme(QStringLiteral("edit-copy")));
1711 copyToOtherViewAction->setIconText(i18nc("@action:inmenu Edit", "Copy to Inactive Split View"));
1712 actionCollection()->setDefaultShortcut(copyToOtherViewAction, Qt::SHIFT | Qt::Key_F5);
1713 connect(copyToOtherViewAction, &QAction::triggered, this, &DolphinMainWindow::copyToInactiveSplitView);
1714
1715 QAction *moveToOtherViewAction = actionCollection()->addAction(QStringLiteral("move_to_inactive_split_view"));
1716 moveToOtherViewAction->setText(i18nc("@action:inmenu", "Move to Other View"));
1717 m_actionTextHelper->registerTextWhenNothingIsSelected(moveToOtherViewAction, i18nc("@action:inmenu", "Move to Other View…"));
1718 moveToOtherViewAction->setWhatsThis(xi18nc("@info:whatsthis Move",
1719 "This moves the selected items from "
1720 "the <emphasis>active</emphasis> view to the inactive split view."));
1721 moveToOtherViewAction->setIcon(QIcon::fromTheme(QStringLiteral("edit-cut")));
1722 moveToOtherViewAction->setIconText(i18nc("@action:inmenu Edit", "Move to Inactive Split View"));
1723 actionCollection()->setDefaultShortcut(moveToOtherViewAction, Qt::SHIFT | Qt::Key_F6);
1724 connect(moveToOtherViewAction, &QAction::triggered, this, &DolphinMainWindow::moveToInactiveSplitView);
1725
1726 QAction *showFilterBar = actionCollection()->addAction(QStringLiteral("show_filter_bar"));
1727 showFilterBar->setText(i18nc("@action:inmenu Tools", "Filter…"));
1728 showFilterBar->setToolTip(i18nc("@info:tooltip", "Show Filter Bar"));
1729 showFilterBar->setWhatsThis(xi18nc("@info:whatsthis",
1730 "This opens the "
1731 "<emphasis>Filter Bar</emphasis> at the bottom of the window.<nl/> "
1732 "There you can enter a text to filter the files and folders currently displayed. "
1733 "Only those that contain the text in their name will be kept in view."));
1734 showFilterBar->setIcon(QIcon::fromTheme(QStringLiteral("view-filter")));
1735 actionCollection()->setDefaultShortcuts(showFilterBar, {Qt::CTRL | Qt::Key_I, Qt::Key_Slash});
1736 connect(showFilterBar, &QAction::triggered, this, &DolphinMainWindow::showFilterBar);
1737
1738 // toggle_filter acts as a copy of the main showFilterBar to be used mainly
1739 // in the toolbar, with no default shortcut attached, to avoid messing with
1740 // existing workflows (filter bar always open and Ctrl-I to focus)
1741 QAction *toggleFilter = actionCollection()->addAction(QStringLiteral("toggle_filter"));
1742 toggleFilter->setText(i18nc("@action:inmenu", "Toggle Filter Bar"));
1743 toggleFilter->setIconText(i18nc("@action:intoolbar", "Filter"));
1744 toggleFilter->setIcon(showFilterBar->icon());
1745 toggleFilter->setToolTip(showFilterBar->toolTip());
1746 toggleFilter->setWhatsThis(showFilterBar->whatsThis());
1747 toggleFilter->setCheckable(true);
1748 connect(toggleFilter, &QAction::triggered, this, &DolphinMainWindow::toggleFilterBar);
1749
1750 QAction *searchAction = KStandardAction::find(this, &DolphinMainWindow::find, actionCollection());
1751 searchAction->setText(i18n("Search…"));
1752 searchAction->setToolTip(i18nc("@info:tooltip", "Search for files and folders"));
1753 searchAction->setWhatsThis(xi18nc("@info:whatsthis find",
1754 "<para>This helps you "
1755 "find files and folders by opening a <emphasis>find bar</emphasis>. "
1756 "There you can enter search terms and specify settings to find the "
1757 "objects you are looking for.</para><para>Use this help again on "
1758 "the find bar so we can have a look at it while the settings are "
1759 "explained.</para>"));
1760
1761 // toggle_search acts as a copy of the main searchAction to be used mainly
1762 // in the toolbar, with no default shortcut attached, to avoid messing with
1763 // existing workflows (search bar always open and Ctrl-F to focus)
1764 QAction *toggleSearchAction = actionCollection()->addAction(QStringLiteral("toggle_search"));
1765 toggleSearchAction->setText(i18nc("@action:inmenu", "Toggle Search Bar"));
1766 toggleSearchAction->setIconText(i18nc("@action:intoolbar", "Search"));
1767 toggleSearchAction->setIcon(searchAction->icon());
1768 toggleSearchAction->setToolTip(searchAction->toolTip());
1769 toggleSearchAction->setWhatsThis(searchAction->whatsThis());
1770 toggleSearchAction->setCheckable(true);
1771
1772 QAction *toggleSelectionModeAction = actionCollection()->addAction(QStringLiteral("toggle_selection_mode"));
1773 // i18n: This action toggles a selection mode.
1774 toggleSelectionModeAction->setText(i18nc("@action:inmenu", "Select Files and Folders"));
1775 // i18n: Opens a selection mode for selecting files/folders.
1776 // The text is kept so unspecific because it will be shown on the toolbar where space is at a premium.
1777 toggleSelectionModeAction->setIconText(i18nc("@action:intoolbar", "Select"));
1778 toggleSelectionModeAction->setWhatsThis(xi18nc(
1779 "@info:whatsthis",
1780 "<para>This application only knows which files or folders should be acted on if they are"
1781 " <emphasis>selected</emphasis> first. Press this to toggle a <emphasis>Selection Mode</emphasis> which makes selecting and deselecting as easy as "
1782 "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."
1783 "</para>"));
1784 toggleSelectionModeAction->setIcon(QIcon::fromTheme(QStringLiteral("quickwizard")));
1785 toggleSelectionModeAction->setCheckable(true);
1786 actionCollection()->setDefaultShortcut(toggleSelectionModeAction, Qt::Key_Space);
1787 connect(toggleSelectionModeAction, &QAction::triggered, this, &DolphinMainWindow::toggleSelectionMode);
1788
1789 // A special version of the toggleSelectionModeAction for the toolbar that also contains a menu
1790 // with the selectAllAction and invertSelectionAction.
1791 auto *toggleSelectionModeToolBarAction =
1792 new KToolBarPopupAction(toggleSelectionModeAction->icon(), toggleSelectionModeAction->iconText(), actionCollection());
1793 toggleSelectionModeToolBarAction->setToolTip(toggleSelectionModeAction->text());
1794 toggleSelectionModeToolBarAction->setWhatsThis(toggleSelectionModeAction->whatsThis());
1795 actionCollection()->addAction(QStringLiteral("toggle_selection_mode_tool_bar"), toggleSelectionModeToolBarAction);
1796 toggleSelectionModeToolBarAction->setCheckable(true);
1797 toggleSelectionModeToolBarAction->setPopupMode(KToolBarPopupAction::DelayedPopup);
1798 connect(toggleSelectionModeToolBarAction, &QAction::triggered, toggleSelectionModeAction, &QAction::trigger);
1799 connect(toggleSelectionModeAction, &QAction::toggled, toggleSelectionModeToolBarAction, &QAction::setChecked);
1800
1801 QAction *selectAllAction = KStandardAction::selectAll(this, &DolphinMainWindow::selectAll, actionCollection());
1802 selectAllAction->setWhatsThis(xi18nc("@info:whatsthis",
1803 "This selects all "
1804 "files and folders in the current location."));
1805
1806 QAction *invertSelection = actionCollection()->addAction(QStringLiteral("invert_selection"));
1807 invertSelection->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1808 invertSelection->setWhatsThis(xi18nc("@info:whatsthis invert",
1809 "This selects all "
1810 "objects that you have currently <emphasis>not</emphasis> selected instead."));
1811 invertSelection->setIcon(QIcon::fromTheme(QStringLiteral("edit-select-invert")));
1812 actionCollection()->setDefaultShortcut(invertSelection, Qt::CTRL | Qt::SHIFT | Qt::Key_A);
1813 connect(invertSelection, &QAction::triggered, this, &DolphinMainWindow::invertSelection);
1814
1815 QMenu *toggleSelectionModeActionMenu = new QMenu(this);
1816 toggleSelectionModeActionMenu->addAction(selectAllAction);
1817 toggleSelectionModeActionMenu->addAction(invertSelection);
1818 toggleSelectionModeToolBarAction->setMenu(toggleSelectionModeActionMenu);
1819
1820 // setup 'View' menu
1821 // (note that most of it is set up in DolphinViewActionHandler)
1822
1823 QAction *split = actionCollection()->addAction(QStringLiteral("split_view"));
1824 split->setWhatsThis(xi18nc("@info:whatsthis find",
1825 "<para>This splits "
1826 "the folder view below into two autonomous views.</para><para>This "
1827 "way you can see two locations at once and move items between them "
1828 "quickly.</para>Click this again afterwards to recombine the views."));
1829 actionCollection()->setDefaultShortcut(split, Qt::Key_F3);
1830 connect(split, &QAction::triggered, this, &DolphinMainWindow::toggleSplitView);
1831
1832 QAction *stashSplit = actionCollection()->addAction(QStringLiteral("split_stash"));
1833 actionCollection()->setDefaultShortcut(stashSplit, Qt::CTRL | Qt::Key_S);
1834 stashSplit->setText(i18nc("@action:intoolbar Stash", "Stash"));
1835 stashSplit->setToolTip(i18nc("@info", "Opens the stash virtual directory in a split window"));
1836 stashSplit->setIcon(QIcon::fromTheme(QStringLiteral("folder-stash")));
1837 stashSplit->setCheckable(false);
1838 QDBusConnectionInterface *sessionInterface = QDBusConnection::sessionBus().interface();
1839 stashSplit->setVisible(sessionInterface && sessionInterface->isServiceRegistered(QStringLiteral("org.kde.kio.StashNotifier")));
1840 connect(stashSplit, &QAction::triggered, this, &DolphinMainWindow::toggleSplitStash);
1841
1842 QAction *redisplay = KStandardAction::redisplay(this, &DolphinMainWindow::reloadView, actionCollection());
1843 redisplay->setToolTip(i18nc("@info:tooltip", "Refresh view"));
1844 redisplay->setWhatsThis(xi18nc("@info:whatsthis refresh",
1845 "<para>This refreshes "
1846 "the folder view.</para>"
1847 "<para>If the contents of this folder have changed, refreshing will re-scan this folder "
1848 "and show you a newly-updated view of the files and folders contained here.</para>"
1849 "<para>If the view is split, this refreshes the one that is currently in focus.</para>"));
1850
1851 QAction *stop = actionCollection()->addAction(QStringLiteral("stop"));
1852 stop->setText(i18nc("@action:inmenu View", "Stop"));
1853 stop->setToolTip(i18nc("@info", "Stop loading"));
1854 stop->setWhatsThis(i18nc("@info", "This stops the loading of the contents of the current folder."));
1855 stop->setIcon(QIcon::fromTheme(QStringLiteral("process-stop")));
1856 connect(stop, &QAction::triggered, this, &DolphinMainWindow::stopLoading);
1857
1858 KToggleAction *editableLocation = actionCollection()->add<KToggleAction>(QStringLiteral("editable_location"));
1859 editableLocation->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1860 editableLocation->setWhatsThis(xi18nc("@info:whatsthis",
1861 "This toggles the <emphasis>Location Bar</emphasis> to be "
1862 "editable so you can directly enter a location you want to go to.<nl/>"
1863 "You can also switch to editing by clicking to the right of the "
1864 "location and switch back by confirming the edited location."));
1865 actionCollection()->setDefaultShortcut(editableLocation, Qt::Key_F6);
1866 connect(editableLocation, &KToggleAction::triggered, this, &DolphinMainWindow::toggleEditLocation);
1867
1868 QAction *replaceLocation = actionCollection()->addAction(QStringLiteral("replace_location"));
1869 replaceLocation->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1870 // i18n: "enter" is used both in the meaning of "writing" and "going to" a new location here.
1871 // Both meanings are useful but not necessary to understand the use of "Replace Location".
1872 // So you might want to be more verbose in your language to convey the meaning but it's up to you.
1873 replaceLocation->setWhatsThis(xi18nc("@info:whatsthis",
1874 "This switches to editing the location and selects it "
1875 "so you can quickly enter a different location."));
1876 actionCollection()->setDefaultShortcuts(replaceLocation, {Qt::CTRL | Qt::Key_L, Qt::ALT | Qt::Key_D});
1877 connect(replaceLocation, &QAction::triggered, this, &DolphinMainWindow::replaceLocation);
1878
1879 // setup 'Go' menu
1880 {
1881 QScopedPointer<QAction> backAction(KStandardAction::back(nullptr, nullptr, nullptr));
1882 m_backAction = new KToolBarPopupAction(backAction->icon(), backAction->text(), actionCollection());
1883 m_backAction->setObjectName(backAction->objectName());
1884 m_backAction->setShortcuts(backAction->shortcuts());
1885 }
1886 m_backAction->setPopupMode(KToolBarPopupAction::DelayedPopup);
1887 connect(m_backAction, &QAction::triggered, this, &DolphinMainWindow::goBack);
1888 connect(m_backAction->popupMenu(), &QMenu::aboutToShow, this, &DolphinMainWindow::slotAboutToShowBackPopupMenu);
1889 connect(m_backAction->popupMenu(), &QMenu::triggered, this, &DolphinMainWindow::slotGoBack);
1890 actionCollection()->addAction(m_backAction->objectName(), m_backAction);
1891
1892 auto backShortcuts = m_backAction->shortcuts();
1893 // Prepend this shortcut, to avoid being hidden by the two-slot UI (#371130)
1894 backShortcuts.prepend(QKeySequence(Qt::Key_Backspace));
1895 actionCollection()->setDefaultShortcuts(m_backAction, backShortcuts);
1896
1897 DolphinRecentTabsMenu *recentTabsMenu = new DolphinRecentTabsMenu(this);
1898 actionCollection()->addAction(QStringLiteral("closed_tabs"), recentTabsMenu);
1899 connect(m_tabWidget, &DolphinTabWidget::rememberClosedTab, recentTabsMenu, &DolphinRecentTabsMenu::rememberClosedTab);
1900 connect(recentTabsMenu, &DolphinRecentTabsMenu::restoreClosedTab, m_tabWidget, &DolphinTabWidget::restoreClosedTab);
1901 connect(recentTabsMenu, &DolphinRecentTabsMenu::closedTabsCountChanged, this, &DolphinMainWindow::closedTabsCountChanged);
1902
1903 QAction *undoCloseTab = actionCollection()->addAction(QStringLiteral("undo_close_tab"));
1904 undoCloseTab->setText(i18nc("@action:inmenu File", "Undo close tab"));
1905 undoCloseTab->setWhatsThis(i18nc("@info:whatsthis undo close tab", "This returns you to the previously closed tab."));
1906 actionCollection()->setDefaultShortcut(undoCloseTab, Qt::CTRL | Qt::SHIFT | Qt::Key_T);
1907 undoCloseTab->setIcon(QIcon::fromTheme(QStringLiteral("edit-undo")));
1908 undoCloseTab->setEnabled(false);
1909 connect(undoCloseTab, &QAction::triggered, recentTabsMenu, &DolphinRecentTabsMenu::undoCloseTab);
1910
1911 auto undoAction = actionCollection()->action(KStandardAction::name(KStandardAction::Undo));
1912 undoAction->setWhatsThis(xi18nc("@info:whatsthis",
1913 "This undoes "
1914 "the last change you made to files or folders.<nl/>"
1915 "Such changes include <interface>creating, renaming</interface> "
1916 "and <interface>moving</interface> them to a different location "
1917 "or to the <filename>Trash</filename>. <nl/>Changes that can't "
1918 "be undone will ask for your confirmation."));
1919 undoAction->setEnabled(false); // undo should be disabled by default
1920
1921 {
1922 QScopedPointer<QAction> forwardAction(KStandardAction::forward(nullptr, nullptr, nullptr));
1923 m_forwardAction = new KToolBarPopupAction(forwardAction->icon(), forwardAction->text(), actionCollection());
1924 m_forwardAction->setObjectName(forwardAction->objectName());
1925 m_forwardAction->setShortcuts(forwardAction->shortcuts());
1926 }
1927 m_forwardAction->setPopupMode(KToolBarPopupAction::DelayedPopup);
1928 connect(m_forwardAction, &QAction::triggered, this, &DolphinMainWindow::goForward);
1929 connect(m_forwardAction->popupMenu(), &QMenu::aboutToShow, this, &DolphinMainWindow::slotAboutToShowForwardPopupMenu);
1930 connect(m_forwardAction->popupMenu(), &QMenu::triggered, this, &DolphinMainWindow::slotGoForward);
1931 actionCollection()->addAction(m_forwardAction->objectName(), m_forwardAction);
1932 actionCollection()->setDefaultShortcuts(m_forwardAction, m_forwardAction->shortcuts());
1933
1934 // enable middle-click to open in a new tab
1935 auto *middleClickEventFilter = new MiddleClickActionEventFilter(this);
1936 connect(middleClickEventFilter, &MiddleClickActionEventFilter::actionMiddleClicked, this, &DolphinMainWindow::slotBackForwardActionMiddleClicked);
1937 m_backAction->popupMenu()->installEventFilter(middleClickEventFilter);
1938 m_forwardAction->popupMenu()->installEventFilter(middleClickEventFilter);
1939 KStandardAction::up(this, &DolphinMainWindow::goUp, actionCollection());
1940 QAction *homeAction = KStandardAction::home(this, &DolphinMainWindow::goHome, actionCollection());
1941 homeAction->setWhatsThis(xi18nc("@info:whatsthis",
1942 "Go to your "
1943 "<filename>Home</filename> folder.<nl/>Every user account "
1944 "has their own <filename>Home</filename> that contains their data "
1945 "including folders that contain personal application data."));
1946
1947 // setup 'Tools' menu
1948 QAction *compareFiles = actionCollection()->addAction(QStringLiteral("compare_files"));
1949 compareFiles->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1950 compareFiles->setIcon(QIcon::fromTheme(QStringLiteral("kompare")));
1951 compareFiles->setEnabled(false);
1952 connect(compareFiles, &QAction::triggered, this, &DolphinMainWindow::compareFiles);
1953
1954 QAction *openPreferredSearchTool = actionCollection()->addAction(QStringLiteral("open_preferred_search_tool"));
1955 openPreferredSearchTool->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool"));
1956 openPreferredSearchTool->setWhatsThis(xi18nc("@info:whatsthis",
1957 "<para>This opens a preferred search tool for the viewed location.</para>"
1958 "<para>Use <emphasis>More Search Tools</emphasis> menu to configure it.</para>"));
1959 openPreferredSearchTool->setIcon(QIcon::fromTheme(QStringLiteral("search")));
1960 actionCollection()->setDefaultShortcut(openPreferredSearchTool, Qt::CTRL | Qt::SHIFT | Qt::Key_F);
1961 connect(openPreferredSearchTool, &QAction::triggered, this, &DolphinMainWindow::openPreferredSearchTool);
1962
1963 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
1964 QAction *openTerminal = actionCollection()->addAction(QStringLiteral("open_terminal"));
1965 openTerminal->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
1966 openTerminal->setWhatsThis(xi18nc("@info:whatsthis",
1967 "<para>This opens a <emphasis>terminal</emphasis> application for the viewed location.</para>"
1968 "<para>To learn more about terminals use the help in the terminal application.</para>"));
1969 openTerminal->setIcon(QIcon::fromTheme(QStringLiteral("utilities-terminal")));
1970 actionCollection()->setDefaultShortcut(openTerminal, Qt::SHIFT | Qt::Key_F4);
1971 connect(openTerminal, &QAction::triggered, this, &DolphinMainWindow::openTerminal);
1972
1973 QAction *openTerminalHere = actionCollection()->addAction(QStringLiteral("open_terminal_here"));
1974 // i18n: "Here" refers to the location(s) of the currently selected item(s) or the currently viewed location if nothing is selected.
1975 openTerminalHere->setText(i18nc("@action:inmenu Tools", "Open Terminal Here"));
1976 openTerminalHere->setWhatsThis(xi18nc("@info:whatsthis",
1977 "<para>This opens <emphasis>terminal</emphasis> applications for the selected items' locations.</para>"
1978 "<para>To learn more about terminals use the help in the terminal application.</para>"));
1979 openTerminalHere->setIcon(QIcon::fromTheme(QStringLiteral("utilities-terminal")));
1980 actionCollection()->setDefaultShortcut(openTerminalHere, Qt::SHIFT | Qt::ALT | Qt::Key_F4);
1981 connect(openTerminalHere, &QAction::triggered, this, &DolphinMainWindow::openTerminalHere);
1982
1983 #if HAVE_TERMINAL
1984 QAction *focusTerminalPanel = actionCollection()->addAction(QStringLiteral("focus_terminal_panel"));
1985 focusTerminalPanel->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
1986 focusTerminalPanel->setIcon(QIcon::fromTheme(QStringLiteral("swap-panels")));
1987 actionCollection()->setDefaultShortcut(focusTerminalPanel, Qt::CTRL | Qt::SHIFT | Qt::Key_F4);
1988 connect(focusTerminalPanel, &QAction::triggered, this, &DolphinMainWindow::focusTerminalPanel);
1989 #endif
1990 }
1991
1992 // setup 'Bookmarks' menu
1993 KActionMenu *bookmarkMenu = new KActionMenu(i18nc("@title:menu", "&Bookmarks"), this);
1994 bookmarkMenu->setIcon(QIcon::fromTheme(QStringLiteral("bookmarks")));
1995 // Make the toolbar button version work properly on click
1996 bookmarkMenu->setPopupMode(QToolButton::InstantPopup);
1997 m_bookmarkHandler = new DolphinBookmarkHandler(this, actionCollection(), bookmarkMenu->menu(), this);
1998 actionCollection()->addAction(QStringLiteral("bookmarks"), bookmarkMenu);
1999
2000 // setup 'Settings' menu
2001 KToggleAction *showMenuBar = KStandardAction::showMenubar(nullptr, nullptr, actionCollection());
2002 showMenuBar->setWhatsThis(xi18nc("@info:whatsthis",
2003 "<para>This switches between having a <emphasis>Menubar</emphasis> "
2004 "and having a <interface>%1</interface> button. Both "
2005 "contain mostly the same actions and configuration options.</para>"
2006 "<para>The Menubar takes up more space but allows for fast and organised access to all "
2007 "actions an application has to offer.</para><para>The <interface>%1</interface> button "
2008 "is simpler and small which makes triggering advanced actions more time consuming.</para>",
2009 hamburgerMenuAction->text().replace('&', "")));
2010 connect(showMenuBar,
2011 &KToggleAction::triggered, // Fixes #286822
2012 this,
2013 &DolphinMainWindow::toggleShowMenuBar,
2014 Qt::QueuedConnection);
2015
2016 KToggleAction *showStatusBar = KStandardAction::showStatusbar(nullptr, nullptr, actionCollection());
2017 showStatusBar->setChecked(GeneralSettings::showStatusBar());
2018 connect(GeneralSettings::self(), &GeneralSettings::showStatusBarChanged, showStatusBar, &KToggleAction::setChecked);
2019 connect(showStatusBar, &KToggleAction::triggered, this, [this](bool checked) {
2020 GeneralSettings::setShowStatusBar(checked);
2021 refreshViews();
2022 });
2023
2024 KStandardAction::keyBindings(this, &DolphinMainWindow::slotKeyBindings, actionCollection());
2025 KStandardAction::preferences(this, &DolphinMainWindow::editSettings, actionCollection());
2026
2027 // not in menu actions
2028 QList<QKeySequence> nextTabKeys = KStandardShortcut::tabNext();
2029 nextTabKeys.append(QKeySequence(Qt::CTRL | Qt::Key_Tab));
2030
2031 QList<QKeySequence> prevTabKeys = KStandardShortcut::tabPrev();
2032 prevTabKeys.append(QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_Tab));
2033
2034 for (int i = 0; i < MaxActivateTabShortcuts; ++i) {
2035 QAction *activateTab = actionCollection()->addAction(QStringLiteral("activate_tab_%1").arg(i));
2036 activateTab->setText(i18nc("@action:inmenu", "Activate Tab %1", i + 1));
2037 activateTab->setEnabled(false);
2038 connect(activateTab, &QAction::triggered, this, [this, i]() {
2039 m_tabWidget->activateTab(i);
2040 });
2041
2042 // only add default shortcuts for the first 9 tabs regardless of MaxActivateTabShortcuts
2043 if (i < 9) {
2044 actionCollection()->setDefaultShortcut(activateTab, QStringLiteral("Alt+%1").arg(i + 1));
2045 }
2046 }
2047
2048 QAction *activateLastTab = actionCollection()->addAction(QStringLiteral("activate_last_tab"));
2049 activateLastTab->setText(i18nc("@action:inmenu", "Activate Last Tab"));
2050 activateLastTab->setEnabled(false);
2051 connect(activateLastTab, &QAction::triggered, m_tabWidget, &DolphinTabWidget::activateLastTab);
2052 actionCollection()->setDefaultShortcut(activateLastTab, Qt::ALT | Qt::Key_0);
2053
2054 QAction *activateNextTab = actionCollection()->addAction(QStringLiteral("activate_next_tab"));
2055 activateNextTab->setIconText(i18nc("@action:inmenu", "Next Tab"));
2056 activateNextTab->setText(i18nc("@action:inmenu", "Activate Next Tab"));
2057 activateNextTab->setEnabled(false);
2058 connect(activateNextTab, &QAction::triggered, m_tabWidget, &DolphinTabWidget::activateNextTab);
2059 actionCollection()->setDefaultShortcuts(activateNextTab, nextTabKeys);
2060
2061 QAction *activatePrevTab = actionCollection()->addAction(QStringLiteral("activate_prev_tab"));
2062 activatePrevTab->setIconText(i18nc("@action:inmenu", "Previous Tab"));
2063 activatePrevTab->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
2064 activatePrevTab->setEnabled(false);
2065 connect(activatePrevTab, &QAction::triggered, m_tabWidget, &DolphinTabWidget::activatePrevTab);
2066 actionCollection()->setDefaultShortcuts(activatePrevTab, prevTabKeys);
2067
2068 // for context menu
2069 QAction *showTarget = actionCollection()->addAction(QStringLiteral("show_target"));
2070 showTarget->setText(i18nc("@action:inmenu", "Show Target"));
2071 showTarget->setIcon(QIcon::fromTheme(QStringLiteral("document-open-folder")));
2072 showTarget->setEnabled(false);
2073 connect(showTarget, &QAction::triggered, this, &DolphinMainWindow::showTarget);
2074
2075 QAction *openInNewTab = actionCollection()->addAction(QStringLiteral("open_in_new_tab"));
2076 openInNewTab->setText(i18nc("@action:inmenu", "Open in New Tab"));
2077 openInNewTab->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
2078 connect(openInNewTab, &QAction::triggered, this, &DolphinMainWindow::openInNewTab);
2079
2080 QAction *openInNewTabs = actionCollection()->addAction(QStringLiteral("open_in_new_tabs"));
2081 openInNewTabs->setText(i18nc("@action:inmenu", "Open in New Tabs"));
2082 openInNewTabs->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
2083 connect(openInNewTabs, &QAction::triggered, this, &DolphinMainWindow::openInNewTab);
2084
2085 QAction *openInNewWindow = actionCollection()->addAction(QStringLiteral("open_in_new_window"));
2086 openInNewWindow->setText(i18nc("@action:inmenu", "Open in New Window"));
2087 openInNewWindow->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
2088 connect(openInNewWindow, &QAction::triggered, this, &DolphinMainWindow::openInNewWindow);
2089
2090 QAction *openInSplitViewAction = actionCollection()->addAction(QStringLiteral("open_in_split_view"));
2091 openInSplitViewAction->setText(i18nc("@action:inmenu", "Open in Split View"));
2092 openInSplitViewAction->setIcon(QIcon::fromTheme(QStringLiteral("view-right-new")));
2093 connect(openInSplitViewAction, &QAction::triggered, this, [this]() {
2094 openInSplitView(QUrl());
2095 });
2096 }
2097
2098 void DolphinMainWindow::setupDockWidgets()
2099 {
2100 const bool lock = GeneralSettings::lockPanels();
2101
2102 DolphinPlacesModelSingleton::instance().placesModel()->setPanelsLocked(lock);
2103
2104 KDualAction *lockLayoutAction = actionCollection()->add<KDualAction>(QStringLiteral("lock_panels"));
2105 lockLayoutAction->setActiveText(i18nc("@action:inmenu Panels", "Unlock Panels"));
2106 lockLayoutAction->setActiveIcon(QIcon::fromTheme(QStringLiteral("object-unlocked")));
2107 lockLayoutAction->setInactiveText(i18nc("@action:inmenu Panels", "Lock Panels"));
2108 lockLayoutAction->setInactiveIcon(QIcon::fromTheme(QStringLiteral("object-locked")));
2109 lockLayoutAction->setWhatsThis(xi18nc("@info:whatsthis",
2110 "This "
2111 "switches between having panels <emphasis>locked</emphasis> or "
2112 "<emphasis>unlocked</emphasis>.<nl/>Unlocked panels can be "
2113 "dragged to the other side of the window and have a close "
2114 "button.<nl/>Locked panels are embedded more cleanly."));
2115 lockLayoutAction->setActive(lock);
2116 connect(lockLayoutAction, &KDualAction::triggered, this, &DolphinMainWindow::togglePanelLockState);
2117
2118 // Setup "Information"
2119 DolphinDockWidget *infoDock = new DolphinDockWidget(i18nc("@title:window", "Information"));
2120 infoDock->setLocked(lock);
2121 infoDock->setObjectName(QStringLiteral("infoDock"));
2122 infoDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
2123
2124 #if HAVE_BALOO
2125 InformationPanel *infoPanel = new InformationPanel(infoDock);
2126 infoPanel->setCustomContextMenuActions({lockLayoutAction});
2127 connect(infoPanel, &InformationPanel::urlActivated, this, &DolphinMainWindow::handleUrl);
2128 infoDock->setWidget(infoPanel);
2129
2130 createPanelAction(QIcon::fromTheme(QStringLiteral("dialog-information")), Qt::Key_F11, infoDock, QStringLiteral("show_information_panel"));
2131
2132 addDockWidget(Qt::RightDockWidgetArea, infoDock);
2133 connect(this, &DolphinMainWindow::urlChanged, infoPanel, &InformationPanel::setUrl);
2134 connect(this, &DolphinMainWindow::selectionChanged, infoPanel, &InformationPanel::setSelection);
2135 connect(this, &DolphinMainWindow::requestItemInfo, infoPanel, &InformationPanel::requestDelayedItemInfo);
2136 connect(this, &DolphinMainWindow::fileItemsChanged, infoPanel, &InformationPanel::slotFilesItemChanged);
2137 #endif
2138
2139 // i18n: This is the last paragraph for the "What's This"-texts of all four panels.
2140 const QString panelWhatsThis = xi18nc("@info:whatsthis",
2141 "<para>To show or "
2142 "hide panels like this go to <interface>Menu|Panels</interface> "
2143 "or <interface>View|Panels</interface>.</para>");
2144 #if HAVE_BALOO
2145 actionCollection()
2146 ->action(QStringLiteral("show_information_panel"))
2147 ->setWhatsThis(xi18nc("@info:whatsthis",
2148 "<para> This toggles the "
2149 "<emphasis>information</emphasis> panel at the right side of the "
2150 "window.</para><para>The panel provides in-depth information "
2151 "about the items your mouse is hovering over or about the selected "
2152 "items. Otherwise it informs you about the currently viewed folder.<nl/>"
2153 "For single items a preview of their contents is provided.</para>"));
2154 #endif
2155 infoDock->setWhatsThis(xi18nc("@info:whatsthis",
2156 "<para>This panel "
2157 "provides in-depth information about the items your mouse is "
2158 "hovering over or about the selected items. Otherwise it informs "
2159 "you about the currently viewed folder.<nl/>For single items a "
2160 "preview of their contents is provided.</para><para>You can configure "
2161 "which and how details are given here by right-clicking.</para>")
2162 + panelWhatsThis);
2163
2164 // Setup "Folders"
2165 DolphinDockWidget *foldersDock = new DolphinDockWidget(i18nc("@title:window", "Folders"));
2166 foldersDock->setLocked(lock);
2167 foldersDock->setObjectName(QStringLiteral("foldersDock"));
2168 foldersDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
2169 FoldersPanel *foldersPanel = new FoldersPanel(foldersDock);
2170 foldersPanel->setCustomContextMenuActions({lockLayoutAction});
2171 foldersDock->setWidget(foldersPanel);
2172
2173 createPanelAction(QIcon::fromTheme(QStringLiteral("folder")), Qt::Key_F7, foldersDock, QStringLiteral("show_folders_panel"));
2174
2175 addDockWidget(Qt::LeftDockWidgetArea, foldersDock);
2176 connect(this, &DolphinMainWindow::urlChanged, foldersPanel, &FoldersPanel::setUrl);
2177 connect(foldersPanel, &FoldersPanel::folderActivated, this, &DolphinMainWindow::changeUrl);
2178 connect(foldersPanel, &FoldersPanel::folderInNewTab, this, &DolphinMainWindow::openNewTab);
2179 connect(foldersPanel, &FoldersPanel::folderInNewActiveTab, this, &DolphinMainWindow::openNewTabAndActivate);
2180 connect(foldersPanel, &FoldersPanel::errorMessage, this, &DolphinMainWindow::showErrorMessage);
2181
2182 actionCollection()
2183 ->action(QStringLiteral("show_folders_panel"))
2184 ->setWhatsThis(xi18nc("@info:whatsthis",
2185 "This toggles the "
2186 "<emphasis>folders</emphasis> panel at the left side of the window."
2187 "<nl/><nl/>It shows the folders of the <emphasis>file system"
2188 "</emphasis> in a <emphasis>tree view</emphasis>."));
2189 foldersDock->setWhatsThis(xi18nc("@info:whatsthis",
2190 "<para>This panel "
2191 "shows the folders of the <emphasis>file system</emphasis> in a "
2192 "<emphasis>tree view</emphasis>.</para><para>Click a folder to go "
2193 "there. Click the arrow to the left of a folder to see its subfolders. "
2194 "This allows quick switching between any folders.</para>")
2195 + panelWhatsThis);
2196
2197 // Setup "Terminal"
2198 #if HAVE_TERMINAL
2199 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
2200 DolphinDockWidget *terminalDock = new DolphinDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
2201 terminalDock->setLocked(lock);
2202 terminalDock->setObjectName(QStringLiteral("terminalDock"));
2203 terminalDock->setContentsMargins(0, 0, 0, 0);
2204 m_terminalPanel = new TerminalPanel(terminalDock);
2205 m_terminalPanel->setCustomContextMenuActions({lockLayoutAction});
2206 terminalDock->setWidget(m_terminalPanel);
2207
2208 connect(m_terminalPanel, &TerminalPanel::hideTerminalPanel, terminalDock, &DolphinDockWidget::hide);
2209 connect(m_terminalPanel, &TerminalPanel::changeUrl, this, &DolphinMainWindow::slotTerminalDirectoryChanged);
2210 connect(terminalDock, &DolphinDockWidget::visibilityChanged, m_terminalPanel, &TerminalPanel::dockVisibilityChanged);
2211 connect(terminalDock, &DolphinDockWidget::visibilityChanged, this, &DolphinMainWindow::slotTerminalPanelVisibilityChanged);
2212
2213 createPanelAction(QIcon::fromTheme(QStringLiteral("dialog-scripts")), Qt::Key_F4, terminalDock, QStringLiteral("show_terminal_panel"));
2214
2215 addDockWidget(Qt::BottomDockWidgetArea, terminalDock);
2216 connect(this, &DolphinMainWindow::urlChanged, m_terminalPanel, &TerminalPanel::setUrl);
2217
2218 if (GeneralSettings::version() < 200) {
2219 terminalDock->hide();
2220 }
2221
2222 actionCollection()
2223 ->action(QStringLiteral("show_terminal_panel"))
2224 ->setWhatsThis(xi18nc("@info:whatsthis",
2225 "<para>This toggles the "
2226 "<emphasis>terminal</emphasis> panel at the bottom of the window."
2227 "<nl/>The location in the terminal will always match the folder "
2228 "view so you can navigate using either.</para><para>The terminal "
2229 "panel is not needed for basic computer usage but can be useful "
2230 "for advanced tasks. To learn more about terminals use the help "
2231 "in a standalone terminal application like Konsole.</para>"));
2232 terminalDock->setWhatsThis(xi18nc("@info:whatsthis",
2233 "<para>This is "
2234 "the <emphasis>terminal</emphasis> panel. It behaves like a "
2235 "normal terminal but will match the location of the folder view "
2236 "so you can navigate using either.</para><para>The terminal panel "
2237 "is not needed for basic computer usage but can be useful for "
2238 "advanced tasks. To learn more about terminals use the help in a "
2239 "standalone terminal application like Konsole.</para>")
2240 + panelWhatsThis);
2241 }
2242 #endif
2243
2244 if (GeneralSettings::version() < 200) {
2245 infoDock->hide();
2246 foldersDock->hide();
2247 }
2248
2249 // Setup "Places"
2250 DolphinDockWidget *placesDock = new DolphinDockWidget(i18nc("@title:window", "Places"));
2251 placesDock->setLocked(lock);
2252 placesDock->setObjectName(QStringLiteral("placesDock"));
2253 placesDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
2254
2255 m_placesPanel = new PlacesPanel(placesDock);
2256 m_placesPanel->setCustomContextMenuActions({lockLayoutAction});
2257 placesDock->setWidget(m_placesPanel);
2258
2259 createPanelAction(QIcon::fromTheme(QStringLiteral("compass")), Qt::Key_F9, placesDock, QStringLiteral("show_places_panel"));
2260
2261 addDockWidget(Qt::LeftDockWidgetArea, placesDock);
2262 connect(m_placesPanel, &PlacesPanel::placeActivated, this, &DolphinMainWindow::slotPlaceActivated);
2263 connect(m_placesPanel, &PlacesPanel::tabRequested, this, &DolphinMainWindow::openNewTab);
2264 connect(m_placesPanel, &PlacesPanel::activeTabRequested, this, &DolphinMainWindow::openNewTabAndActivate);
2265 connect(m_placesPanel, &PlacesPanel::newWindowRequested, this, [this](const QUrl &url) {
2266 Dolphin::openNewWindow({url}, this);
2267 });
2268 connect(m_placesPanel, &PlacesPanel::openInSplitViewRequested, this, &DolphinMainWindow::openInSplitView);
2269 connect(m_placesPanel, &PlacesPanel::errorMessage, this, &DolphinMainWindow::showErrorMessage);
2270 connect(this, &DolphinMainWindow::urlChanged, m_placesPanel, &PlacesPanel::setUrl);
2271 connect(placesDock, &DolphinDockWidget::visibilityChanged, &DolphinUrlNavigatorsController::slotPlacesPanelVisibilityChanged);
2272 connect(this, &DolphinMainWindow::settingsChanged, m_placesPanel, &PlacesPanel::readSettings);
2273 connect(m_placesPanel, &PlacesPanel::storageTearDownRequested, this, &DolphinMainWindow::slotStorageTearDownFromPlacesRequested);
2274 connect(m_placesPanel, &PlacesPanel::storageTearDownExternallyRequested, this, &DolphinMainWindow::slotStorageTearDownExternallyRequested);
2275 DolphinUrlNavigatorsController::slotPlacesPanelVisibilityChanged(m_placesPanel->isVisible());
2276
2277 auto actionShowAllPlaces = new QAction(QIcon::fromTheme(QStringLiteral("view-hidden")), i18nc("@item:inmenu", "Show Hidden Places"), this);
2278 actionShowAllPlaces->setCheckable(true);
2279 actionShowAllPlaces->setDisabled(true);
2280 actionShowAllPlaces->setWhatsThis(i18nc("@info:whatsthis",
2281 "This displays "
2282 "all places in the places panel that have been hidden. They will "
2283 "appear semi-transparent unless you uncheck their hide property."));
2284
2285 connect(actionShowAllPlaces, &QAction::triggered, this, [this](bool checked) {
2286 m_placesPanel->setShowAll(checked);
2287 });
2288 connect(m_placesPanel, &PlacesPanel::allPlacesShownChanged, actionShowAllPlaces, &QAction::setChecked);
2289
2290 actionCollection()
2291 ->action(QStringLiteral("show_places_panel"))
2292 ->setWhatsThis(xi18nc("@info:whatsthis",
2293 "<para>This toggles the "
2294 "<emphasis>places</emphasis> panel at the left side of the window."
2295 "</para><para>It allows you to go to locations you have "
2296 "bookmarked and to access disk or media attached to the computer "
2297 "or to the network. It also contains sections to find recently "
2298 "saved files or files of a certain type.</para>"));
2299 placesDock->setWhatsThis(xi18nc("@info:whatsthis",
2300 "<para>This is the "
2301 "<emphasis>Places</emphasis> panel. It allows you to go to locations "
2302 "you have bookmarked and to access disk or media attached to the "
2303 "computer or to the network. It also contains sections to find "
2304 "recently saved files or files of a certain type.</para><para>"
2305 "Click on an entry to go there. Click with the right mouse button "
2306 "instead to open any entry in a new tab or new window.</para>"
2307 "<para>New entries can be added by dragging folders onto this panel. "
2308 "Right-click any section or entry to hide it. Right-click an empty "
2309 "space on this panel and select <interface>Show Hidden Places"
2310 "</interface> to display it again.</para>")
2311 + panelWhatsThis);
2312
2313 // Add actions into the "Panels" menu
2314 KActionMenu *panelsMenu = new KActionMenu(i18nc("@action:inmenu View", "Show Panels"), this);
2315 actionCollection()->addAction(QStringLiteral("panels"), panelsMenu);
2316 panelsMenu->setIcon(QIcon::fromTheme(QStringLiteral("view-sidetree")));
2317 panelsMenu->setPopupMode(QToolButton::InstantPopup);
2318 const KActionCollection *ac = actionCollection();
2319 panelsMenu->addAction(ac->action(QStringLiteral("show_places_panel")));
2320 #if HAVE_BALOO
2321 panelsMenu->addAction(ac->action(QStringLiteral("show_information_panel")));
2322 #endif
2323 panelsMenu->addAction(ac->action(QStringLiteral("show_folders_panel")));
2324 panelsMenu->addAction(ac->action(QStringLiteral("show_terminal_panel")));
2325 panelsMenu->addSeparator();
2326 panelsMenu->addAction(actionShowAllPlaces);
2327 panelsMenu->addAction(lockLayoutAction);
2328
2329 connect(panelsMenu->menu(), &QMenu::aboutToShow, this, [actionShowAllPlaces] {
2330 actionShowAllPlaces->setEnabled(DolphinPlacesModelSingleton::instance().placesModel()->hiddenCount());
2331 });
2332 }
2333
2334 void DolphinMainWindow::updateFileAndEditActions()
2335 {
2336 const KFileItemList list = m_activeViewContainer->view()->selectedItems();
2337 const KActionCollection *col = actionCollection();
2338 KFileItemListProperties capabilitiesSource(list);
2339
2340 QAction *renameAction = col->action(KStandardAction::name(KStandardAction::RenameFile));
2341 QAction *moveToTrashAction = col->action(KStandardAction::name(KStandardAction::MoveToTrash));
2342 QAction *deleteAction = col->action(KStandardAction::name(KStandardAction::DeleteFile));
2343 QAction *cutAction = col->action(KStandardAction::name(KStandardAction::Cut));
2344 QAction *duplicateAction = col->action(QStringLiteral("duplicate")); // see DolphinViewActionHandler
2345 QAction *addToPlacesAction = col->action(QStringLiteral("add_to_places"));
2346 QAction *copyToOtherViewAction = col->action(QStringLiteral("copy_to_inactive_split_view"));
2347 QAction *moveToOtherViewAction = col->action(QStringLiteral("move_to_inactive_split_view"));
2348 QAction *copyLocation = col->action(QString("copy_location"));
2349
2350 if (list.isEmpty()) {
2351 stateChanged(QStringLiteral("has_no_selection"));
2352
2353 // All actions that need a selection to function can be enabled because they should trigger selection mode.
2354 renameAction->setEnabled(true);
2355 moveToTrashAction->setEnabled(true);
2356 deleteAction->setEnabled(true);
2357 cutAction->setEnabled(true);
2358 duplicateAction->setEnabled(true);
2359 addToPlacesAction->setEnabled(true);
2360 copyLocation->setEnabled(true);
2361 // Them triggering selection mode and not directly acting on selected items is signified by adding "…" to their text.
2362 m_actionTextHelper->textsWhenNothingIsSelectedEnabled(true);
2363
2364 } else {
2365 m_actionTextHelper->textsWhenNothingIsSelectedEnabled(false);
2366 stateChanged(QStringLiteral("has_selection"));
2367
2368 QAction *deleteWithTrashShortcut = col->action(QStringLiteral("delete_shortcut")); // see DolphinViewActionHandler
2369 QAction *showTarget = col->action(QStringLiteral("show_target"));
2370
2371 if (list.length() == 1 && list.first().isDir()) {
2372 addToPlacesAction->setEnabled(true);
2373 } else {
2374 addToPlacesAction->setEnabled(false);
2375 }
2376
2377 const bool enableMoveToTrash = capabilitiesSource.isLocal() && capabilitiesSource.supportsMoving();
2378
2379 renameAction->setEnabled(capabilitiesSource.supportsMoving());
2380 moveToTrashAction->setEnabled(enableMoveToTrash);
2381 deleteAction->setEnabled(capabilitiesSource.supportsDeleting());
2382 deleteWithTrashShortcut->setEnabled(capabilitiesSource.supportsDeleting() && !enableMoveToTrash);
2383 cutAction->setEnabled(capabilitiesSource.supportsMoving());
2384 copyLocation->setEnabled(list.length() == 1);
2385 showTarget->setEnabled(list.length() == 1 && list.at(0).isLink());
2386 duplicateAction->setEnabled(capabilitiesSource.supportsWriting());
2387 }
2388
2389 if (m_tabWidget->currentTabPage()->splitViewEnabled() && !list.isEmpty()) {
2390 DolphinTabPage *tabPage = m_tabWidget->currentTabPage();
2391 KFileItem capabilitiesDestination;
2392
2393 if (tabPage->primaryViewActive()) {
2394 capabilitiesDestination = tabPage->secondaryViewContainer()->rootItem();
2395 } else {
2396 capabilitiesDestination = tabPage->primaryViewContainer()->rootItem();
2397 }
2398
2399 const auto destUrl = capabilitiesDestination.url();
2400 const bool allNotTargetOrigin = std::all_of(list.cbegin(), list.cend(), [destUrl](const KFileItem &item) {
2401 return item.url().adjusted(QUrl::RemoveFilename | QUrl::StripTrailingSlash) != destUrl;
2402 });
2403
2404 copyToOtherViewAction->setEnabled(capabilitiesDestination.isWritable() && allNotTargetOrigin);
2405 moveToOtherViewAction->setEnabled((list.isEmpty() || capabilitiesSource.supportsMoving()) && capabilitiesDestination.isWritable()
2406 && allNotTargetOrigin);
2407 } else {
2408 copyToOtherViewAction->setEnabled(false);
2409 moveToOtherViewAction->setEnabled(false);
2410 }
2411 }
2412
2413 void DolphinMainWindow::updateViewActions()
2414 {
2415 m_actionHandler->updateViewActions();
2416
2417 QAction *toggleFilterBarAction = actionCollection()->action(QStringLiteral("toggle_filter"));
2418 toggleFilterBarAction->setChecked(m_activeViewContainer->isFilterBarVisible());
2419
2420 updateSplitAction();
2421 }
2422
2423 void DolphinMainWindow::updateGoActions()
2424 {
2425 QAction *goUpAction = actionCollection()->action(KStandardAction::name(KStandardAction::Up));
2426 const QUrl currentUrl = m_activeViewContainer->url();
2427 // I think this is one of the best places to firstly be confronted
2428 // with a file system and its hierarchy. Talking about the root
2429 // directory might seem too much here but it is the question that
2430 // naturally arises in this context.
2431 goUpAction->setWhatsThis(xi18nc("@info:whatsthis",
2432 "<para>Go to "
2433 "the folder that contains the currently viewed one.</para>"
2434 "<para>All files and folders are organized in a hierarchical "
2435 "<emphasis>file system</emphasis>. At the top of this hierarchy is "
2436 "a directory that contains all data connected to this computer"
2437 "—the <emphasis>root directory</emphasis>.</para>"));
2438 goUpAction->setEnabled(KIO::upUrl(currentUrl) != currentUrl);
2439 }
2440
2441 void DolphinMainWindow::refreshViews()
2442 {
2443 m_tabWidget->refreshViews();
2444
2445 if (GeneralSettings::modifiedStartupSettings()) {
2446 updateWindowTitle();
2447 }
2448
2449 updateSplitAction();
2450
2451 Q_EMIT settingsChanged();
2452 }
2453
2454 void DolphinMainWindow::clearStatusBar()
2455 {
2456 m_activeViewContainer->statusBar()->resetToDefaultText();
2457 }
2458
2459 void DolphinMainWindow::connectViewSignals(DolphinViewContainer *container)
2460 {
2461 connect(container, &DolphinViewContainer::showFilterBarChanged, this, &DolphinMainWindow::updateFilterBarAction);
2462 connect(container, &DolphinViewContainer::writeStateChanged, this, &DolphinMainWindow::slotWriteStateChanged);
2463 slotWriteStateChanged(container->view()->isFolderWritable());
2464 connect(container, &DolphinViewContainer::searchModeEnabledChanged, this, &DolphinMainWindow::updateSearchAction);
2465 connect(container, &DolphinViewContainer::captionChanged, this, &DolphinMainWindow::updateWindowTitle);
2466 connect(container, &DolphinViewContainer::tabRequested, this, &DolphinMainWindow::openNewTab);
2467 connect(container, &DolphinViewContainer::activeTabRequested, this, &DolphinMainWindow::openNewTabAndActivate);
2468
2469 const QAction *toggleSearchAction = actionCollection()->action(QStringLiteral("toggle_search"));
2470 connect(toggleSearchAction, &QAction::triggered, container, &DolphinViewContainer::setSearchModeEnabled);
2471
2472 // Make the toggled state of the selection mode actions visually follow the selection mode state of the view.
2473 auto toggleSelectionModeAction = actionCollection()->action(QStringLiteral("toggle_selection_mode"));
2474 toggleSelectionModeAction->setChecked(m_activeViewContainer->isSelectionModeEnabled());
2475 connect(m_activeViewContainer, &DolphinViewContainer::selectionModeChanged, toggleSelectionModeAction, &QAction::setChecked);
2476
2477 const DolphinView *view = container->view();
2478 connect(view, &DolphinView::selectionChanged, this, &DolphinMainWindow::slotSelectionChanged);
2479 connect(view, &DolphinView::requestItemInfo, this, &DolphinMainWindow::requestItemInfo);
2480 connect(view, &DolphinView::fileItemsChanged, this, &DolphinMainWindow::fileItemsChanged);
2481 connect(view, &DolphinView::tabRequested, this, &DolphinMainWindow::openNewTab);
2482 connect(view, &DolphinView::activeTabRequested, this, &DolphinMainWindow::openNewTabAndActivate);
2483 connect(view, &DolphinView::windowRequested, this, &DolphinMainWindow::openNewWindow);
2484 connect(view, &DolphinView::requestContextMenu, this, &DolphinMainWindow::openContextMenu);
2485 connect(view, &DolphinView::directoryLoadingStarted, this, &DolphinMainWindow::enableStopAction);
2486 connect(view, &DolphinView::directoryLoadingCompleted, this, &DolphinMainWindow::disableStopAction);
2487 connect(view, &DolphinView::directoryLoadingCompleted, this, &DolphinMainWindow::slotDirectoryLoadingCompleted);
2488 connect(view, &DolphinView::goBackRequested, this, &DolphinMainWindow::goBack);
2489 connect(view, &DolphinView::goForwardRequested, this, &DolphinMainWindow::goForward);
2490 connect(view, &DolphinView::urlActivated, this, &DolphinMainWindow::handleUrl);
2491 connect(view, &DolphinView::goUpRequested, this, &DolphinMainWindow::goUp);
2492
2493 connect(container->urlNavigatorInternalWithHistory(), &KUrlNavigator::urlChanged, this, &DolphinMainWindow::changeUrl);
2494 connect(container->urlNavigatorInternalWithHistory(), &KUrlNavigator::historyChanged, this, &DolphinMainWindow::updateHistory);
2495
2496 auto navigators = static_cast<DolphinNavigatorsWidgetAction *>(actionCollection()->action(QStringLiteral("url_navigators")));
2497 const KUrlNavigator *navigator =
2498 m_tabWidget->currentTabPage()->primaryViewActive() ? navigators->primaryUrlNavigator() : navigators->secondaryUrlNavigator();
2499
2500 QAction *editableLocactionAction = actionCollection()->action(QStringLiteral("editable_location"));
2501 editableLocactionAction->setChecked(navigator->isUrlEditable());
2502 connect(navigator, &KUrlNavigator::editableStateChanged, this, &DolphinMainWindow::slotEditableStateChanged);
2503 connect(navigator, &KUrlNavigator::tabRequested, this, &DolphinMainWindow::openNewTab);
2504 connect(navigator, &KUrlNavigator::activeTabRequested, this, &DolphinMainWindow::openNewTabAndActivate);
2505 connect(navigator, &KUrlNavigator::newWindowRequested, this, &DolphinMainWindow::openNewWindow);
2506 }
2507
2508 void DolphinMainWindow::updateSplitAction()
2509 {
2510 QAction *splitAction = actionCollection()->action(QStringLiteral("split_view"));
2511 const DolphinTabPage *tabPage = m_tabWidget->currentTabPage();
2512 if (tabPage->splitViewEnabled()) {
2513 if (GeneralSettings::closeActiveSplitView() ? tabPage->primaryViewActive() : !tabPage->primaryViewActive()) {
2514 splitAction->setText(i18nc("@action:intoolbar Close left view", "Close"));
2515 splitAction->setToolTip(i18nc("@info", "Close left view"));
2516 splitAction->setIcon(QIcon::fromTheme(QStringLiteral("view-left-close")));
2517 } else {
2518 splitAction->setText(i18nc("@action:intoolbar Close right view", "Close"));
2519 splitAction->setToolTip(i18nc("@info", "Close right view"));
2520 splitAction->setIcon(QIcon::fromTheme(QStringLiteral("view-right-close")));
2521 }
2522 } else {
2523 splitAction->setText(i18nc("@action:intoolbar Split view", "Split"));
2524 splitAction->setToolTip(i18nc("@info", "Split view"));
2525 splitAction->setIcon(QIcon::fromTheme(QStringLiteral("view-right-new")));
2526 }
2527 }
2528
2529 void DolphinMainWindow::updateAllowedToolbarAreas()
2530 {
2531 auto navigators = static_cast<DolphinNavigatorsWidgetAction *>(actionCollection()->action(QStringLiteral("url_navigators")));
2532 if (toolBar()->actions().contains(navigators)) {
2533 toolBar()->setAllowedAreas(Qt::TopToolBarArea | Qt::BottomToolBarArea);
2534 if (toolBarArea(toolBar()) == Qt::LeftToolBarArea || toolBarArea(toolBar()) == Qt::RightToolBarArea) {
2535 addToolBar(Qt::TopToolBarArea, toolBar());
2536 }
2537 } else {
2538 toolBar()->setAllowedAreas(Qt::AllToolBarAreas);
2539 }
2540 }
2541
2542 bool DolphinMainWindow::isKompareInstalled() const
2543 {
2544 static bool initialized = false;
2545 static bool installed = false;
2546 if (!initialized) {
2547 // TODO: maybe replace this approach later by using a menu
2548 // plugin like kdiff3plugin.cpp
2549 installed = !QStandardPaths::findExecutable(QStringLiteral("kompare")).isEmpty();
2550 initialized = true;
2551 }
2552 return installed;
2553 }
2554
2555 void DolphinMainWindow::createPanelAction(const QIcon &icon, const QKeySequence &shortcut, QDockWidget *dockWidget, const QString &actionName)
2556 {
2557 auto dockAction = dockWidget->toggleViewAction();
2558 dockAction->setIcon(icon);
2559 dockAction->setEnabled(true);
2560
2561 QAction *panelAction = actionCollection()->addAction(actionName, dockAction);
2562 actionCollection()->setDefaultShortcut(panelAction, shortcut);
2563
2564 connect(panelAction, &QAction::toggled, dockWidget, &QWidget::setVisible);
2565 }
2566 // clang-format off
2567 void DolphinMainWindow::setupWhatsThis()
2568 {
2569 // main widgets
2570 menuBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2571 "<emphasis>Menubar</emphasis>. It provides access to commands and "
2572 "configuration options. Left-click on any of the menus on this "
2573 "bar to see its contents.</para><para>The Menubar can be hidden "
2574 "by unchecking <interface>Settings|Show Menubar</interface>. Then "
2575 "most of its contents become available through a <interface>Menu"
2576 "</interface> button on the <emphasis>Toolbar</emphasis>.</para>"));
2577 toolBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2578 "<emphasis>Toolbar</emphasis>. It allows quick access to "
2579 "frequently used actions.</para><para>It is highly customizable. "
2580 "All items you see in the <interface>Menu</interface> or "
2581 "in the <interface>Menubar</interface> can be placed on the "
2582 "Toolbar. Just right-click on it and select <interface>Configure "
2583 "Toolbars…</interface> or find this action within the <interface>"
2584 "menu</interface>."
2585 "</para><para>The location of the bar and the style of its "
2586 "buttons can also be changed in the right-click menu. Right-click "
2587 "a button if you want to show or hide its text.</para>"));
2588 m_tabWidget->setWhatsThis(xi18nc("@info:whatsthis main view",
2589 "<para>Here you can see the <emphasis>folders</emphasis> and "
2590 "<emphasis>files</emphasis> that are at the location described in "
2591 "the <interface>Location Bar</interface> above. This area is the "
2592 "central part of this application where you navigate to the files "
2593 "you want to use.</para><para>For an elaborate and general "
2594 "introduction to this application <link "
2595 "url='https://userbase.kde.org/Dolphin/File_Management#Introduction_to_Dolphin'>"
2596 "click here</link>. This will open an introductory article from "
2597 "the <emphasis>KDE UserBase Wiki</emphasis>.</para><para>For brief "
2598 "explanations of all the features of this <emphasis>view</emphasis> "
2599 "<link url='help:/dolphin/dolphin-view.html'>click here</link> "
2600 "instead. This will open a page from the <emphasis>Handbook"
2601 "</emphasis> that covers the basics.</para>"));
2602
2603 // Settings menu
2604 actionCollection()->action(KStandardAction::name(KStandardAction::KeyBindings))
2605 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window "
2606 "that lists the <emphasis>keyboard shortcuts</emphasis>.<nl/>"
2607 "There you can set up key combinations to trigger an action when "
2608 "they are pressed simultaneously. All commands in this application can "
2609 "be triggered this way.</para>"));
2610 actionCollection()->action(KStandardAction::name(KStandardAction::ConfigureToolbars))
2611 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window in which "
2612 "you can change which buttons appear on the <emphasis>Toolbar</emphasis>.</para>"
2613 "<para>All items you see in the <interface>Menu</interface> can also be placed on the Toolbar.</para>"));
2614 actionCollection()->action(KStandardAction::name(KStandardAction::Preferences))
2615 ->setWhatsThis(xi18nc("@info:whatsthis","This opens a window where you can "
2616 "change a multitude of settings for this application. For an explanation "
2617 "of the various settings go to the chapter <emphasis>Configuring Dolphin"
2618 "</emphasis> in <interface>Help|Dolphin Handbook</interface>."));
2619
2620 // Help menu
2621
2622 auto setStandardActionWhatsThis = [this](KStandardAction::StandardAction actionId,
2623 const QString &whatsThis) {
2624 // Check for the existence of an action since it can be restricted through the Kiosk system
2625 if (auto *action = actionCollection()->action(KStandardAction::name(actionId))) {
2626 action->setWhatsThis(whatsThis);
2627 }
2628 };
2629
2630 // i18n: If the external link isn't available in your language it might make
2631 // sense to state the external link's language in brackets to not
2632 // frustrate the user. If there are multiple languages that the user might
2633 // know with a reasonable chance you might want to have 2 external links.
2634 // The same might be true for any external link you translate.
2635 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>"));
2636 // (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 )
2637
2638 setStandardActionWhatsThis(KStandardAction::WhatsThis,
2639 xi18nc("@info:whatsthis whatsthis button",
2640 "<para>This is the button that invokes the help feature you are "
2641 "using right now! Click it, then click any component of this "
2642 "application to ask \"What's this?\" about it. The mouse cursor "
2643 "will change appearance if no help is available for a spot.</para>"
2644 "<para>There are two other ways to get help: "
2645 "The <link url='help:/dolphin/index.html'>Dolphin Handbook</link> and "
2646 "the <link url='https://userbase.kde.org/Dolphin/File_Management'>KDE "
2647 "UserBase Wiki</link>.</para><para>The \"What's this?\" help is "
2648 "missing in most other windows so don't get too used to this.</para>"));
2649
2650 setStandardActionWhatsThis(KStandardAction::ReportBug,
2651 xi18nc("@info:whatsthis","<para>This opens a "
2652 "window that will guide you through reporting errors or flaws "
2653 "in this application or in other KDE software.</para>"
2654 "<para>High-quality bug reports are much appreciated. To learn "
2655 "how to make your bug report as effective as possible "
2656 "<link url='https://community.kde.org/Get_Involved/Bug_Reporting'>"
2657 "click here</link>.</para>"));
2658
2659 setStandardActionWhatsThis(KStandardAction::Donate,
2660 xi18nc("@info:whatsthis", "<para>This opens a "
2661 "<emphasis>web page</emphasis> where you can donate to "
2662 "support the continued work on this application and many "
2663 "other projects by the <emphasis>KDE</emphasis> community.</para>"
2664 "<para>Donating is the easiest and fastest way to efficiently "
2665 "support KDE and its projects. KDE projects are available for "
2666 "free therefore your donation is needed to cover things that "
2667 "require money like servers, contributor meetings, etc.</para>"
2668 "<para><emphasis>KDE e.V.</emphasis> is the non-profit "
2669 "organization behind the KDE community.</para>"));
2670
2671 setStandardActionWhatsThis(KStandardAction::SwitchApplicationLanguage,
2672 xi18nc("@info:whatsthis",
2673 "With this you can change the language this application uses."
2674 "<nl/>You can even set secondary languages which will be used "
2675 "if texts are not available in your preferred language."));
2676
2677 setStandardActionWhatsThis(KStandardAction::AboutApp,
2678 xi18nc("@info:whatsthis","This opens a "
2679 "window that informs you about the version, license, "
2680 "used libraries and maintainers of this application."));
2681
2682 setStandardActionWhatsThis(KStandardAction::AboutKDE,
2683 xi18nc("@info:whatsthis","This opens a "
2684 "window with information about <emphasis>KDE</emphasis>. "
2685 "The KDE community are the people behind this free software."
2686 "<nl/>If you like using this application but don't know "
2687 "about KDE or want to see a cute dragon have a look!"));
2688 }
2689 // clang-format on
2690
2691 bool DolphinMainWindow::addHamburgerMenuToToolbar()
2692 {
2693 QDomDocument domDocument = KXMLGUIClient::domDocument();
2694 if (domDocument.isNull()) {
2695 return false;
2696 }
2697 QDomNode toolbar = domDocument.elementsByTagName(QStringLiteral("ToolBar")).at(0);
2698 if (toolbar.isNull()) {
2699 return false;
2700 }
2701
2702 QDomElement hamburgerMenuElement = domDocument.createElement(QStringLiteral("Action"));
2703 hamburgerMenuElement.setAttribute(QStringLiteral("name"), QStringLiteral("hamburger_menu"));
2704 toolbar.appendChild(hamburgerMenuElement);
2705
2706 KXMLGUIFactory::saveConfigFile(domDocument, xmlFile());
2707 reloadXML();
2708 createGUI();
2709 return true;
2710 // Make sure to also remove the <KXMLGUIFactory> and <QDomDocument> include
2711 // whenever this method is removed (maybe in the year ~2026).
2712 }
2713
2714 // Set a sane initial window size
2715 QSize DolphinMainWindow::sizeHint() const
2716 {
2717 return KXmlGuiWindow::sizeHint().expandedTo(QSize(760, 550));
2718 }
2719
2720 void DolphinMainWindow::saveNewToolbarConfig()
2721 {
2722 KXmlGuiWindow::saveNewToolbarConfig(); // Applies the new config. This has to be called first
2723 // because the rest of this method decides things
2724 // based on the new config.
2725 auto navigators = static_cast<DolphinNavigatorsWidgetAction *>(actionCollection()->action(QStringLiteral("url_navigators")));
2726 if (!toolBar()->actions().contains(navigators)) {
2727 m_tabWidget->currentTabPage()->insertNavigatorsWidget(navigators);
2728 }
2729 updateAllowedToolbarAreas();
2730 (static_cast<KHamburgerMenu *>(actionCollection()->action(KStandardAction::name(KStandardAction::HamburgerMenu))))->hideActionsOf(toolBar());
2731 }
2732
2733 void DolphinMainWindow::focusTerminalPanel()
2734 {
2735 if (m_terminalPanel->isVisible()) {
2736 if (m_terminalPanel->terminalHasFocus()) {
2737 m_activeViewContainer->view()->setFocus(Qt::FocusReason::ShortcutFocusReason);
2738 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
2739 } else {
2740 m_terminalPanel->setFocus(Qt::FocusReason::ShortcutFocusReason);
2741 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
2742 }
2743 } else {
2744 actionCollection()->action(QStringLiteral("show_terminal_panel"))->trigger();
2745 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
2746 }
2747 }
2748
2749 DolphinMainWindow::UndoUiInterface::UndoUiInterface()
2750 : KIO::FileUndoManager::UiInterface()
2751 {
2752 }
2753
2754 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
2755 {
2756 }
2757
2758 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job *job)
2759 {
2760 DolphinMainWindow *mainWin = qobject_cast<DolphinMainWindow *>(parentWidget());
2761 if (mainWin) {
2762 DolphinViewContainer *container = mainWin->activeViewContainer();
2763 container->showMessage(job->errorString(), DolphinViewContainer::Error);
2764 } else {
2765 KIO::FileUndoManager::UiInterface::jobError(job);
2766 }
2767 }
2768
2769 bool DolphinMainWindow::isUrlOpen(const QString &url)
2770 {
2771 return m_tabWidget->isUrlOpen(QUrl::fromUserInput(url));
2772 }
2773
2774 bool DolphinMainWindow::isItemVisibleInAnyView(const QString &urlOfItem)
2775 {
2776 return m_tabWidget->isItemVisibleInAnyView(QUrl::fromUserInput(urlOfItem));
2777 }
2778
2779 #include "moc_dolphinmainwindow.cpp"