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