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