summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleix Pol <[email protected]>2018-05-31 03:44:53 +0200
committerAleix Pol <[email protected]>2018-05-31 03:46:08 +0200
commit6d63fd3581cb39be8ef4eccfb3b697751daaacc5 (patch)
treec26821ffcc9357a1b5ba50e0fcd4284c9f3fba00
parent898cddd9e8ccdd108778c45e0d3d4dd300d1acf3 (diff)
Fix dependency counting
Only do it for the transactions we need.
-rw-r--r--libdiscover/backends/PackageKitBackend/PackageKitBackend.cpp17
-rw-r--r--libdiscover/backends/PackageKitBackend/PackageKitBackend.h2
-rw-r--r--libdiscover/backends/PackageKitBackend/PackageKitResource.cpp31
-rw-r--r--libdiscover/backends/PackageKitBackend/PackageKitResource.h9
4 files changed, 36 insertions, 23 deletions
diff --git a/libdiscover/backends/PackageKitBackend/PackageKitBackend.cpp b/libdiscover/backends/PackageKitBackend/PackageKitBackend.cpp
index dfb7c41..c58430d 100644
--- a/libdiscover/backends/PackageKitBackend/PackageKitBackend.cpp
+++ b/libdiscover/backends/PackageKitBackend/PackageKitBackend.cpp
@@ -567,23 +567,6 @@ void PackageKitBackend::performDetailsFetch()
PackageKit::Transaction* transaction = PackageKit::Daemon::getDetails(ids);
connect(transaction, &PackageKit::Transaction::details, this, &PackageKitBackend::packageDetails);
connect(transaction, &PackageKit::Transaction::errorCode, this, &PackageKitBackend::transactionError);
-
- QSharedPointer<QMap<QString, int>> packageDependencies(new QMap<QString, int>);
- auto trans = PackageKit::Daemon::dependsOn(ids);
- connect(trans, &PackageKit::Transaction::package, this, [packageDependencies](PackageKit::Transaction::Info /*info*/, const QString &packageID, const QString &/*summary*/) {
- (*packageDependencies)[packageID] += 1;
- });
- connect(trans, &PackageKit::Transaction::finished, this, [this, packageDependencies](PackageKit::Transaction::Exit /*status*/) {
- auto pkgDeps = (*packageDependencies);
-
- for (auto it = pkgDeps.constBegin(), itEnd = pkgDeps.constEnd(); it != itEnd; ++it) {
- const auto resources = resourcesByPackageName(PackageKit::Daemon::packageName(it.key()));
- for(auto resource : resources) {
- auto pkres = qobject_cast<PackageKitResource*>(resource);
- pkres->setDependenciesCount(it.value());
- }
- }
- });
}
void PackageKitBackend::checkDaemonRunning()
diff --git a/libdiscover/backends/PackageKitBackend/PackageKitBackend.h b/libdiscover/backends/PackageKitBackend/PackageKitBackend.h
index f30041c..749703c 100644
--- a/libdiscover/backends/PackageKitBackend/PackageKitBackend.h
+++ b/libdiscover/backends/PackageKitBackend/PackageKitBackend.h
@@ -79,6 +79,7 @@ class DISCOVERCOMMON_EXPORT PackageKitBackend : public AbstractResourcesBackend
public Q_SLOTS:
void reloadPackageList();
void refreshDatabase();
+ void transactionError(PackageKit::Transaction::Error, const QString& message);
private Q_SLOTS:
void getPackagesFinished();
@@ -86,7 +87,6 @@ class DISCOVERCOMMON_EXPORT PackageKitBackend : public AbstractResourcesBackend
void addPackageArch(PackageKit::Transaction::Info info, const QString &packageId, const QString &summary);
void addPackageNotArch(PackageKit::Transaction::Info info, const QString &packageId, const QString &summary);
void packageDetails(const PackageKit::Details& details);
- void transactionError(PackageKit::Transaction::Error, const QString& message);
void addPackageToUpdate(PackageKit::Transaction::Info, const QString& pkgid, const QString& summary);
void getUpdatesFinished(PackageKit::Transaction::Exit,uint);
void getUpdatesDetailsFinished(PackageKit::Transaction::Exit,uint);
diff --git a/libdiscover/backends/PackageKitBackend/PackageKitResource.cpp b/libdiscover/backends/PackageKitBackend/PackageKitResource.cpp
index 9ad765e..ac48d3e 100644
--- a/libdiscover/backends/PackageKitBackend/PackageKitResource.cpp
+++ b/libdiscover/backends/PackageKitBackend/PackageKitResource.cpp
@@ -25,15 +25,17 @@
#include <KLocalizedString>
#include <PackageKit/Details>
#include <PackageKit/Daemon>
+#include <QJsonArray>
#include <QDebug>
PackageKitResource::PackageKitResource(QString packageName, QString summary, PackageKitBackend* parent)
: AbstractResource(parent)
, m_summary(std::move(summary))
, m_name(std::move(packageName))
- , m_dependenciesCount(0)
{
setObjectName(m_name);
+
+ connect(this, &PackageKitResource::dependenciesFound, this, [this](const QJsonObject& obj) { setDependenciesCount(obj.size()); });
}
QString PackageKitResource::name() const
@@ -176,7 +178,7 @@ void PackageKitResource::failedFetchingDetails(PackageKit::Transaction::Error, c
qWarning() << "error fetching details" << msg;
}
-void PackageKitResource::setDependenciesCount(uint deps)
+void PackageKitResource::setDependenciesCount(int deps)
{
if (deps != m_dependenciesCount) {
m_dependenciesCount = deps;
@@ -254,8 +256,31 @@ PackageKitBackend* PackageKitResource::backend() const
QString PackageKitResource::sizeDescription()
{
- if (m_dependenciesCount == 0)
+ if (m_dependenciesCount < 0) {
+ fetchDetails();
+ fetchDependencies();
+ }
+
+ if (m_dependenciesCount <= 0)
return AbstractResource::sizeDescription();
else
return i18np("%2 (plus %1 dependency)", "%2 (plus %1 dependencies)", m_dependenciesCount, AbstractResource::sizeDescription());
}
+
+void PackageKitResource::fetchDependencies()
+{
+ const auto id = availablePackageId();
+ if (id.isEmpty())
+ return;
+ m_dependenciesCount = 0;
+
+ QSharedPointer<QJsonObject> packageDependencies(new QJsonObject);
+ auto trans = PackageKit::Daemon::installPackage(id, PackageKit::Transaction::TransactionFlagSimulate);
+ connect(trans, &PackageKit::Transaction::errorCode, backend(), &PackageKitBackend::transactionError);
+ connect(trans, &PackageKit::Transaction::package, this, [packageDependencies](PackageKit::Transaction::Info info, const QString &packageID, const QString &summary) {
+ (*packageDependencies)[PackageKit::Daemon::packageName(packageID)] = summary ;
+ });
+ connect(trans, &PackageKit::Transaction::finished, this, [this, packageDependencies](PackageKit::Transaction::Exit status) {
+ Q_EMIT dependenciesFound(*packageDependencies);
+ });
+}
diff --git a/libdiscover/backends/PackageKitBackend/PackageKitResource.h b/libdiscover/backends/PackageKitBackend/PackageKitResource.h
index 24284c6..19a92f0 100644
--- a/libdiscover/backends/PackageKitBackend/PackageKitResource.h
+++ b/libdiscover/backends/PackageKitBackend/PackageKitResource.h
@@ -67,7 +67,10 @@ class PackageKitResource : public AbstractResource
bool canExecute() const override { return false; }
QString sizeDescription() override;
- void setDependenciesCount(uint count);
+ void setDependenciesCount(int count);
+
+ Q_SIGNALS:
+ void dependenciesFound(const QJsonObject& dependencies);
public Q_SLOTS:
void addPackageId(PackageKit::Transaction::Info info, const QString &packageId, bool arch);
@@ -90,6 +93,8 @@ class PackageKitResource : public AbstractResource
void failedFetchingDetails(PackageKit::Transaction::Error, const QString& msg);
private:
+ void fetchDependencies();
+ void setDependencies(const QStringList &deps);
/** fetches details individually, it's better if done in batch, like for updates */
void fetchDetails();
@@ -97,7 +102,7 @@ class PackageKitResource : public AbstractResource
const QString m_summary;
const QString m_name;
PackageKit::Details m_details;
- uint m_dependenciesCount;
+ int m_dependenciesCount = -1;
};
#endif // PACKAGEKITRESOURCE_H