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