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