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