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