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