From 242b1b73a67fdb2a74af0250d142d8d0b0c0fd50 Mon Sep 17 00:00:00 2001 From: Felix Ernst Date: Thu, 13 Jun 2024 17:38:52 +0200 Subject: [PATCH] Show installation progress in the status bar This commit reuses the progress reporting of the status bar for the Filelight installation progress. --- src/statusbar/dolphinstatusbar.cpp | 6 ++++++ src/statusbar/statusbarspaceinfo.cpp | 19 ++++++++++--------- src/statusbar/statusbarspaceinfo.h | 2 ++ 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/statusbar/dolphinstatusbar.cpp b/src/statusbar/dolphinstatusbar.cpp index cb8c422456..c8369febcf 100644 --- a/src/statusbar/dolphinstatusbar.cpp +++ b/src/statusbar/dolphinstatusbar.cpp @@ -71,6 +71,12 @@ DolphinStatusBar::DolphinStatusBar(QWidget *parent) // Initialize space information m_spaceInfo = new StatusBarSpaceInfo(contentsContainer); connect(m_spaceInfo, &StatusBarSpaceInfo::showMessage, this, &DolphinStatusBar::showMessage); + connect(m_spaceInfo, + &StatusBarSpaceInfo::showInstallationProgress, + this, + [this](const QString ¤tlyRunningTaskTitle, int installationProgressPercent) { + showProgress(currentlyRunningTaskTitle, installationProgressPercent, CancelLoading::Disallowed); + }); // Initialize progress information m_stopButton = new QToolButton(contentsContainer); diff --git a/src/statusbar/statusbarspaceinfo.cpp b/src/statusbar/statusbarspaceinfo.cpp index 1febd4caf4..e464b9d9f5 100644 --- a/src/statusbar/statusbarspaceinfo.cpp +++ b/src/statusbar/statusbarspaceinfo.cpp @@ -153,8 +153,8 @@ void StatusBarSpaceInfo::updateMenu() vLayout->addSpacing(Dolphin::VERTICAL_SPACER_HEIGHT); - const QString installFilelightButtonDefaultText{i18nc("@action:button", "Install Filelight…")}; - auto installFilelightButton = new QPushButton(QIcon::fromTheme(QStringLiteral("filelight")), installFilelightButtonDefaultText, containerWidget); + auto installFilelightButton = + new QPushButton(QIcon::fromTheme(QStringLiteral("filelight")), i18nc("@action:button", "Install Filelight…"), containerWidget); installFilelightButton->setMinimumWidth(std::max(installFilelightButton->sizeHint().width(), installFilelightTitle->sizeHint().width())); auto buttonLayout = new QHBoxLayout{containerWidget}; buttonLayout->addWidget(installFilelightButton, 0, Qt::AlignHCenter); @@ -166,7 +166,7 @@ void StatusBarSpaceInfo::updateMenu() containerWidget->setFocusProxy(installFilelightButton); installFilelightButton->setAccessibleDescription(installFilelightBody->text()); - connect(installFilelightButton, &QAbstractButton::clicked, this, [this, installFilelightButton, installFilelightButtonDefaultText] { + connect(installFilelightButton, &QAbstractButton::clicked, this, [this] { #ifdef Q_OS_WIN QDesktopServices::openUrl(QUrl("https://apps.kde.org/filelight")); #else @@ -177,8 +177,8 @@ void StatusBarSpaceInfo::updateMenu() return KService::serviceByDesktopName(QStringLiteral("org.kde.filelight")); }, this); - connect(packageInstaller, &KJob::result, this, [this, installFilelightButton, installFilelightButtonDefaultText](KJob *job) { - installFilelightButton->setText(installFilelightButtonDefaultText); + connect(packageInstaller, &KJob::result, this, [this](KJob *job) { + Q_EMIT showInstallationProgress(QString(), 100); // Hides the progress information in the status bar. if (job->error()) { Q_EMIT showMessage(job->errorString(), KMessageWidget::Error); } else { @@ -190,11 +190,12 @@ void StatusBarSpaceInfo::updateMenu() } } }); - connect(packageInstaller, &KJob::percentChanged, installFilelightButton, [installFilelightButton](KJob */* job */, long unsigned int percent) { - if (percent > 100) { - return; // For some reason it instantly reports 101% completion for me when it starts. + const auto installationTaskText{i18nc("@info:status", "Installing Filelight…")}; + Q_EMIT showInstallationProgress(installationTaskText, -1); + connect(packageInstaller, &KJob::percentChanged, this, [this, installationTaskText](KJob */* job */, long unsigned int percent) { + if (percent < 100) { // Ignore some weird reported values. + Q_EMIT showInstallationProgress(installationTaskText, percent); } - installFilelightButton->setText(i18nc("@action:button which also shows progress %1 in percent", "Install Filelight… (%1%)", percent)); }); packageInstaller->start(); #endif diff --git a/src/statusbar/statusbarspaceinfo.h b/src/statusbar/statusbarspaceinfo.h index 02e4e02b13..e78a839349 100644 --- a/src/statusbar/statusbarspaceinfo.h +++ b/src/statusbar/statusbarspaceinfo.h @@ -49,6 +49,8 @@ Q_SIGNALS: */ void showMessage(const QString &message, KMessageWidget::MessageType messageType); + void showInstallationProgress(const QString ¤tlyRunningTaskTitle, int installationProgressPercent); + protected: void showEvent(QShowEvent *event) override; void hideEvent(QHideEvent *event) override;