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

StandardUpdater: improve how progress is calculated generically

Account not just for finished transactions but also actual progress being
made.

This will affect flatpak and kns backends.
parent 03c0dbc7
......@@ -52,7 +52,6 @@ void DummyTransaction::iterateTransaction()
QTimer::singleShot(/*KRandom::random()%*/100, this, &DummyTransaction::iterateTransaction);
} else if (status() == DownloadingStatus) {
setStatus(CommittingStatus);
setProgress(0);
QTimer::singleShot(/*KRandom::random()%*/100, this, &DummyTransaction::iterateTransaction);
} else
#ifdef TEST_PROCEED
......
......@@ -26,6 +26,7 @@
#include <KLocalizedString>
#include <QDateTime>
#include "libdiscover_debug.h"
#include "utils.h"
#include <QTimer>
#include <QIcon>
......@@ -130,6 +131,8 @@ void StandardBackendUpdater::transactionProgressChanged()
{
Transaction* t = qobject_cast<Transaction*>(sender());
Q_EMIT resourceProgressed(t->resource(), t->progress(), toUpdateState(t));
refreshProgress();
}
void StandardBackendUpdater::transactionRemoved(Transaction* t)
......@@ -142,8 +145,7 @@ void StandardBackendUpdater::transactionRemoved(Transaction* t)
const bool found = fromOurBackend && m_pendingResources.remove(t->resource());
if(found && !m_settingUp) {
qreal p = 1-(qreal(m_pendingResources.size())/m_toUpgrade.size());
setProgress(100*p);
refreshProgress();
if(m_pendingResources.isEmpty()) {
cleanup();
}
......@@ -151,6 +153,16 @@ void StandardBackendUpdater::transactionRemoved(Transaction* t)
refreshUpdateable();
}
void StandardBackendUpdater::refreshProgress()
{
int allProgresses = (m_toUpgrade.size() - m_pendingResources.size()) * 100;
for (auto t: transactions()) {
allProgresses += t->progress();
}
setProgress(allProgresses / m_toUpgrade.size());
qDebug() << allProgresses << m_toUpgrade.size() << (m_toUpgrade.size() - m_pendingResources.size()) << progress();
}
void StandardBackendUpdater::refreshUpdateable()
{
if (m_backend->isFetching() || !m_backend->isValid()) {
......@@ -260,13 +272,18 @@ double StandardBackendUpdater::updateSize() const
return ret;
}
QVector<Transaction *> StandardBackendUpdater::transactions() const
{
const auto trans = TransactionModel::global()->transactions();
return kFilter<QVector<Transaction*>>(trans, [this](Transaction* t) { return t->property("updater").value<QObject*>() == this; });
}
quint64 StandardBackendUpdater::downloadSpeed() const
{
quint64 ret = 0;
const auto trans = TransactionModel::global()->transactions();
const auto trans = transactions();
for(Transaction* t: trans) {
if (t->property("updater").value<QObject*>() == this)
ret += t->downloadSpeed();
ret += t->downloadSpeed();
}
return ret;
......
......@@ -67,6 +67,8 @@ class DISCOVERCOMMON_EXPORT StandardBackendUpdater : public AbstractBackendUpdat
void refreshUpdateable();
void transactionAdded(Transaction* newTransaction);
void transactionProgressChanged();
void refreshProgress();
QVector<Transaction*> transactions() const;
QSet<AbstractResource*> m_toUpgrade;
QSet<AbstractResource*> m_upgradeable;
......
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