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