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