Commit bc71b687 authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧

Improve how progress is processed when installing one application

BUG: 391058
parent 09bf743a
......@@ -93,25 +93,33 @@ void PKTransaction::trigger(PackageKit::Transaction::TransactionFlags flags)
connect(m_trans.data(), &PackageKit::Transaction::mediaChangeRequired, this, &PKTransaction::mediaChange);
connect(m_trans.data(), &PackageKit::Transaction::requireRestart, this, &PKTransaction::requireRestart);
connect(m_trans.data(), &PackageKit::Transaction::repoSignatureRequired, this, &PKTransaction::repoSignatureRequired);
connect(m_trans.data(), &PackageKit::Transaction::itemProgress, this, &PKTransaction::progressChanged);
connect(m_trans.data(), &PackageKit::Transaction::percentageChanged, this, &PKTransaction::progressChanged);
connect(m_trans.data(), &PackageKit::Transaction::statusChanged, this, &PKTransaction::statusChanged);
connect(m_trans.data(), &PackageKit::Transaction::eulaRequired, this, &PKTransaction::eulaRequired);
connect(m_trans.data(), &PackageKit::Transaction::allowCancelChanged, this, &PKTransaction::cancellableChanged);
setCancellable(m_trans->allowCancel());
}
void PKTransaction::progressChanged(const QString &id, PackageKit::Transaction::Status status, uint percentage)
void PKTransaction::statusChanged()
{
PackageKitResource * res = qobject_cast<PackageKitResource*>(resource());
if (!res->allPackageNames().contains(PackageKit::Daemon::packageName(id)))
return;
setStatus(m_trans->status() == PackageKit::Transaction::StatusDownload ? Transaction::DownloadingStatus : Transaction::CommittingStatus);
progressChanged();
}
setProgress(percentage);
int percentageWithStatus(PackageKit::Transaction::Status status, uint percentage);
if (status == PackageKit::Transaction::StatusDownload)
setStatus(Transaction::DownloadingStatus);
else
setStatus(Transaction::CommittingStatus);
void PKTransaction::progressChanged()
{
auto percent = m_trans->percentage();
if (percent == 101) {
qWarning() << "percentage cannot be calculated";
percent = 50;
}
const auto processedPercentage = percentageWithStatus(m_trans->status(), qBound<int>(0, percent, 100));
if (processedPercentage >= 0)
setProgress(processedPercentage);
}
void PKTransaction::cancellableChanged()
......
......@@ -41,12 +41,13 @@ class PKTransaction : public Transaction
private:
void processProceedFunction();
void statusChanged();
void cleanup(PackageKit::Transaction::Exit, uint);
void errorFound(PackageKit::Transaction::Error err, const QString& error);
void mediaChange(PackageKit::Transaction::MediaType media, const QString& type, const QString& text);
void requireRestart(PackageKit::Transaction::Restart restart, const QString& p);
void progressChanged(const QString&, PackageKit::Transaction::Status, uint);
void progressChanged();
void eulaRequired(const QString &eulaID, const QString &packageID, const QString &vendor, const QString &licenseAgreement);
void cancellableChanged();
void packageResolved(PackageKit::Transaction::Info info, const QString& packageId);
......
......@@ -30,12 +30,14 @@
#include <KLocalizedString>
static int percentageWithStatus(PackageKit::Transaction::Status status, uint percentage)
int percentageWithStatus(PackageKit::Transaction::Status status, uint percentage)
{
const auto was = percentage;
if (status != PackageKit::Transaction::StatusUnknown) {
static const QMap<PackageKit::Transaction::Status, int> statuses = {
{ PackageKit::Transaction::Status::StatusDownload, 0 },
{ PackageKit::Transaction::Status::StatusInstall, 1},
{ PackageKit::Transaction::Status::StatusRemove, 1},
{ PackageKit::Transaction::Status::StatusUpdate, 1}
};
const auto idx = statuses.value(status, -1);
......@@ -45,7 +47,7 @@ static int percentageWithStatus(PackageKit::Transaction::Status status, uint per
}
percentage = (idx * 100 + percentage) / 2 /*the maximum in statuses*/;
}
qDebug() << "reporing progress with status:" << status << percentage;
qDebug() << "reporting progress with status:" << status << percentage << was;
return percentage;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment