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