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