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