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