Commit 8520cc40 authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧

Use the right API to fetch 1 package

parent 15c1240f
......@@ -88,7 +88,44 @@ ResultsStream * SnapBackend::search(const AbstractResourcesBackend::Filters& fil
ResultsStream * SnapBackend::findResourceByPackageName(const QUrl& search)
{
return search.scheme() == QLatin1String("snap") ? populate(m_client.find(QSnapdClient::MatchName, search.host()), AbstractResource::Installed) : voidStream();
return search.scheme() == QLatin1String("snap") ? populate(m_client.listOne(search.host()), AbstractResource::None) : voidStream();
}
ResultsStream * SnapBackend::populate(QSnapdListOneRequest* job, AbstractResource::State state)
{
auto stream = new ResultsStream(QStringLiteral("Snap-populateOne"));
connect(job, &QSnapdFindRequest::complete, stream, [stream, this, state, job]() {
if (job->error()) {
qDebug() << "error:" << job->error() << job->errorString();
return;
}
QSet<SnapResource*> higher = kFilter<QSet<SnapResource*>>(m_resources, [state](AbstractResource* res){ return res->state()>=state; });
QSet<SnapResource*> resources;
QSharedPointer<QSnapdSnap> snap(job->snap());
const auto snapname = snap->name();
SnapResource* res = m_resources.value(snapname);
if (!res) {
res = new SnapResource(snap, state, this);
Q_ASSERT(res->packageName() == snapname);
resources += res;
} else {
res->setState(state);
higher.remove(res);
}
m_resources[res->packageName()] = res;
for(auto res: higher) {
res->setState(AbstractResource::None);
}
stream->resourcesFound({ret});
stream->finish();
});
job->runAsync();
return stream;
}
template <class T>
......
......@@ -59,6 +59,8 @@ private:
template <class T>
ResultsStream* populate(T* snaps, AbstractResource::State state);
ResultsStream* populate(QSnapdListOneRequest* snaps, AbstractResource::State state);
QHash<QString, SnapResource*> m_resources;
StandardBackendUpdater* m_updater;
SnapReviewsBackend* m_reviews;
......
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