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