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