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