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