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