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