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