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