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