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