Commit 9d49c268 authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧

packagekit: Don't display packages that extend themselves

It's common to have appstream components for plugins that some
distributions will split into separate packages. This is useful but it
can easily clutter the UX.
Take Okular for example, it has an appstream component for every format
it supports. On some distributions, like ArchLinux, it will not be
possible to give them separate states as they all point to the same
package. In such case we'll just show the package that is being
extended.

CCBUG: 403118
parent b7ebd04e
......@@ -179,8 +179,8 @@ QStringList AppPackageKitResource::allPackageNames() const
QList<PackageState> AppPackageKitResource::addonsInformation()
{
return kTransform<QList<PackageState>>(
backend()->extendedBy(m_appdata.id()),
const auto res = kFilter<QVector<AppPackageKitResource*>>(backend()->extendedBy(m_appdata.id()), [this](AppPackageKitResource* r){ return r->allPackageNames() != allPackageNames(); });
return kTransform<QList<PackageState>>(res,
[](AppPackageKitResource* r) { return PackageState(r->appstreamId(), r->name(), r->comment(), r->isInstalled()); }
);
}
......
......@@ -419,13 +419,13 @@ ResultsStream* PackageKitBackend::search(const AbstractResourcesBackend::Filters
const auto ext = kTransform<QVector<AbstractResource*>>(m_packages.extendedBy[filter.extends], [](AppPackageKitResource* a){ return a; });
return new ResultsStream(QStringLiteral("PackageKitStream-extends"), ext);
} else if (filter.search.isEmpty()) {
return new ResultsStream(QStringLiteral("PackageKitStream-all"), kFilter<QVector<AbstractResource*>>(m_packages.packages, [](AbstractResource* res) { return res->type() != AbstractResource::Technical; }));
return new ResultsStream(QStringLiteral("PackageKitStream-all"), kFilter<QVector<AbstractResource*>>(m_packages.packages, [](AbstractResource* res) { return res->type() != AbstractResource::Technical && !qobject_cast<PackageKitResource*>(res)->extendsItself(); }));
} else {
const QList<AppStream::Component> components = m_appdata->search(filter.search);
const QStringList ids = kTransform<QStringList>(components, [](const AppStream::Component& comp) { return comp.id(); });
auto stream = new ResultsStream(QStringLiteral("PackageKitStream-search"));
if (!ids.isEmpty()) {
const auto resources = resourcesByPackageNames<QVector<AbstractResource*>>(ids);
const auto resources = kFilter<QVector<AbstractResource*>>(resourcesByPackageNames<QVector<AbstractResource*>>(ids), [](AbstractResource* res){ return !qobject_cast<PackageKitResource*>(res)->extendsItself(); });
QTimer::singleShot(0, this, [stream, resources] () {
Q_EMIT stream->resourcesFound(resources);
});
......
......@@ -90,6 +90,7 @@ class DISCOVERCOMMON_EXPORT PackageKitBackend : public AbstractResourcesBackend
void getUpdatesFinished(PackageKit::Transaction::Exit,uint);
private:
friend class PackageKitResource;
template <typename T>
T resourcesByPackageNames(const QStringList& names) const;
......
......@@ -334,3 +334,18 @@ void PackageKitResource::fetchDependencies()
Q_EMIT dependenciesFound(*packageDependencies);
});
}
bool PackageKitResource::extendsItself() const
{
const auto extendsResources = backend()->resourcesByPackageNames<QVector<AbstractResource*>>(extends());
if (extendsResources.isEmpty())
return false;
const auto ourPackageNames = allPackageNames();
for (auto r : extendsResources) {
PackageKitResource* pkres = qobject_cast<PackageKitResource*>(r);
if (pkres->allPackageNames() != ourPackageNames)
return false;
}
return true;
}
......@@ -78,6 +78,8 @@ class PackageKitResource : public AbstractResource
virtual QString changelog() const { return {}; }
bool extendsItself() const;
Q_SIGNALS:
void dependenciesFound(const QJsonObject& dependencies);
......
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