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