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