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