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