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