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

Improve progress bar in some cases

Updates consist on first downloading then installing. This patch will make
sure the progress doesn't jump back to 0 when it finishes downloading and
starts updating.

CCBUG: 383473
parent 1bc15046
......@@ -27,6 +27,21 @@
#include <KLocalizedString>
static int percentageWithStatus(PackageKit::Transaction::Status status, uint percentage)
{
if (status != PackageKit::Transaction::StatusUnknown) {
static QVector<PackageKit::Transaction::Status> statuses = {PackageKit::Transaction::Status::StatusDownload, PackageKit::Transaction::Status::StatusUpdate};
const auto idx = statuses.indexOf(status);
if (idx < 0) {
qDebug() << "Status not present" << status << percentage;
return -1;
}
percentage = (idx * 100 + percentage) / statuses.count();
}
qDebug() << "reporing progress:" << status << percentage;
return percentage;
}
PackageKitUpdater::PackageKitUpdater(PackageKitBackend * parent)
: AbstractBackendUpdater(parent),
m_transaction(nullptr),
......@@ -157,8 +172,9 @@ void PackageKitUpdater::cancellableChanged()
void PackageKitUpdater::percentageChanged()
{
if (m_percentage != m_transaction->percentage()) {
m_percentage = m_transaction->percentage();
const auto actualPercentage = percentageWithStatus(m_transaction->status(), m_transaction->percentage());
if (actualPercentage >= 0 && m_percentage != actualPercentage) {
m_percentage = actualPercentage;
emit progressChanged(m_percentage);
}
}
......@@ -282,12 +298,16 @@ void PackageKitUpdater::lastUpdateTimeReceived(QDBusPendingCallWatcher* w)
w->deleteLater();
}
void PackageKitUpdater::itemProgress(const QString& itemID, PackageKit::Transaction::Status /*status*/, uint percentage)
void PackageKitUpdater::itemProgress(const QString& itemID, PackageKit::Transaction::Status status, uint percentage)
{
auto res = packagesForPackageId({itemID});
const auto actualPercentage = percentageWithStatus(status, percentage);
if (actualPercentage<0)
return;
foreach(auto r, res) {
Q_EMIT resourceProgressed(r, percentage);
Q_EMIT resourceProgressed(r, actualPercentage);
}
}
......
......@@ -84,7 +84,7 @@ class PackageKitUpdater : public AbstractBackendUpdater
bool m_isCancelable;
bool m_isProgressing;
PackageKit::Transaction::Status m_status;
uint m_percentage;
int m_percentage;
QDateTime m_lastUpdate;
QStringList m_packagesRemoved;
QVector<QString> m_requiredEula;
......
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