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