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