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