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