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

Have backends provide the update size

BUG: 387698
parent 3d4b1b8b
......@@ -253,12 +253,7 @@ UpdateItem * UpdateModel::itemFromResource(AbstractResource* res)
QString UpdateModel::updateSize() const
{
double ret = 0;
foreach (UpdateItem* item, m_updateItems) {
if (item->checked() == Qt::Checked)
ret += item->size();
}
return KFormat().formatByteSize(ret);
return KFormat().formatByteSize(m_updates->updateSize());
}
QModelIndex UpdateModel::indexFromItem(UpdateItem* item) const
......
......@@ -376,3 +376,18 @@ void PackageKitUpdater::repoSignatureRequired(const QString& packageID, const QS
return PackageKit::Daemon::installSignature(type, keyId, packageID);
};
}
double PackageKitUpdater::updateSize() const
{
double ret = 0.;
QSet<QString> donePkgs;
for (AbstractResource * res : m_toUpgrade) {
PackageKitResource * app = qobject_cast<PackageKitResource*>(res);
QString pkgid = m_backend->upgradeablePackageId(app);
if (!donePkgs.contains(pkgid)) {
donePkgs.insert(pkgid);
ret += app->size();
}
}
return ret;
}
......@@ -46,6 +46,7 @@ class PackageKitUpdater : public AbstractBackendUpdater
bool isCancelable() const override;
bool isProgressing() const override;
void fetchChangelog() const override;
double updateSize() const override;
void proceed() override;
......
......@@ -118,6 +118,11 @@ class DISCOVERCOMMON_EXPORT AbstractBackendUpdater : public QObject
virtual void fetchChangelog() const;
/**
* @returns the size of all the packages set to update combined
*/
virtual double updateSize() const = 0;
public Q_SLOTS:
/**
* If \isCancelable is true during the transaction, this method has
......
......@@ -236,6 +236,15 @@ QDateTime ResourcesUpdatesModel::lastUpdate() const
return ret;
}
double ResourcesUpdatesModel::updateSize() const
{
double ret;
for(AbstractBackendUpdater* upd: m_updaters) {
ret += upd->updateSize();
}
return ret;
}
qint64 ResourcesUpdatesModel::secsToLastUpdate() const
{
return lastUpdate().secsTo(QDateTime::currentDateTime());
......
......@@ -51,6 +51,7 @@ class DISCOVERCOMMON_EXPORT ResourcesUpdatesModel : public QStandardItemModel
bool isProgressing() const;
QList<AbstractResource*> toUpdate() const;
QDateTime lastUpdate() const;
double updateSize() const;
void addResources(const QList<AbstractResource*>& resources);
void removeResources(const QList<AbstractResource*>& resources);
......
......@@ -206,3 +206,12 @@ bool StandardBackendUpdater::isProgressing() const
{
return m_settingUp || !m_pendingResources.isEmpty();
}
double StandardBackendUpdater::updateSize() const
{
double ret = 0.;
for(AbstractResource* res: m_toUpgrade) {
ret += res->size();
}
return ret;
}
......@@ -47,6 +47,7 @@ class DISCOVERCOMMON_EXPORT StandardBackendUpdater : public AbstractBackendUpdat
bool isCancelable() const override;
bool isProgressing() const override;
bool isMarked(AbstractResource* res) const override;
double updateSize() const override;
void setProgress(qreal p);
int updatesCount() const;
......
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