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