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