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