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