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