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