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