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