Commit 0cc8edb1 authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧

Include the number of dependencies an application will have to install

Together with the size of the package itself.
To show the full size we'd have to resolve them separately and for now
I'm afraid it would collapse PackageKit in some implementations.

BUG: 364422
parent c236e27c
......@@ -31,6 +31,7 @@ PackageKitResource::PackageKitResource(QString packageName, QString summary, Pac
: AbstractResource(parent)
, m_summary(std::move(summary))
, m_name(std::move(packageName))
, m_dependenciesCount(0)
{
setObjectName(m_name);
}
......@@ -168,6 +169,18 @@ void PackageKitResource::fetchDetails()
m_details.insert(QStringLiteral("fetching"), true);//we add an entry so it's not re-fetched.
backend()->fetchDetails(pkgid);
auto trans = PackageKit::Daemon::installPackages({ pkgid }, PackageKit::Transaction::TransactionFlagSimulate);
connect(trans, &PackageKit::Transaction::package, this, [trans](PackageKit::Transaction::Info info, const QString &packageID, const QString &summary) {
trans->setProperty("dependencies", trans->property("dependencies").toUInt() + 1);
});
connect(trans, &PackageKit::Transaction::finished, this, [this, trans](PackageKit::Transaction::Exit status) {
auto deps = trans->property("dependencies").toUInt();
if (deps != m_dependenciesCount) {
m_dependenciesCount = deps;
Q_EMIT sizeChanged();
}
});
}
void PackageKitResource::failedFetchingDetails(PackageKit::Transaction::Error, const QString& msg)
......@@ -243,3 +256,10 @@ PackageKitBackend* PackageKitResource::backend() const
return qobject_cast<PackageKitBackend*>(parent());
}
QString PackageKitResource::sizeDescription()
{
if (m_dependenciesCount == 0)
return AbstractResource::sizeDescription();
else
return i18np("%2 (plus %1 dependency)", "%2 (plus %1 dependencies)", m_dependenciesCount, AbstractResource::sizeDescription());
}
......@@ -66,6 +66,8 @@ class PackageKitResource : public AbstractResource
void invokeApplication() const override {}
bool canExecute() const override { return false; }
QString sizeDescription() override;
public Q_SLOTS:
void addPackageId(PackageKit::Transaction::Info info, const QString &packageId, bool arch);
void setDetails(const PackageKit::Details& details);
......@@ -94,6 +96,7 @@ class PackageKitResource : public AbstractResource
const QString m_summary;
const QString m_name;
PackageKit::Details m_details;
uint m_dependenciesCount;
};
#endif // PACKAGEKITRESOURCE_H
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