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