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