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