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