Commit 1a34987a authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧

Improve snap support

Connecting isn't necessary anymore
Only search when the query has something to search
parent 43076fa2
...@@ -46,15 +46,6 @@ SnapBackend::SnapBackend(QObject* parent) ...@@ -46,15 +46,6 @@ SnapBackend::SnapBackend(QObject* parent)
, m_updater(new StandardBackendUpdater(this)) , m_updater(new StandardBackendUpdater(this))
, m_reviews(new SnapReviewsBackend(this)) , m_reviews(new SnapReviewsBackend(this))
{ {
{
auto request = m_client.connect();
request->runSync();
m_valid = request->error() == QSnapdRequest::NoError;
if (!m_valid) {
qWarning() << "snap problem at initialize:" << request->errorString();
return;
}
}
connect(m_reviews, &SnapReviewsBackend::ratingsReady, this, &AbstractResourcesBackend::emitRatingsReady); connect(m_reviews, &SnapReviewsBackend::ratingsReady, this, &AbstractResourcesBackend::emitRatingsReady);
//make sure we populate the installed resources first //make sure we populate the installed resources first
...@@ -76,7 +67,7 @@ ResultsStream * SnapBackend::search(const AbstractResourcesBackend::Filters& fil ...@@ -76,7 +67,7 @@ ResultsStream * SnapBackend::search(const AbstractResourcesBackend::Filters& fil
return voidStream(); return voidStream();
} else if (filters.state >= AbstractResource::Installed) { } else if (filters.state >= AbstractResource::Installed) {
return populate(m_client.list(), AbstractResource::Installed); return populate(m_client.list(), AbstractResource::Installed);
} else { } else if (!filters.search.isEmpty()) {
return populate(m_client.find(QSnapdClient::FindFlag::None, filters.search), AbstractResource::None); return populate(m_client.find(QSnapdClient::FindFlag::None, filters.search), AbstractResource::None);
} }
return voidStream(); return voidStream();
...@@ -93,6 +84,7 @@ ResultsStream* SnapBackend::populate(T* job, AbstractResource::State state) ...@@ -93,6 +84,7 @@ ResultsStream* SnapBackend::populate(T* job, AbstractResource::State state)
auto stream = new ResultsStream(QStringLiteral("Snap-populate")); auto stream = new ResultsStream(QStringLiteral("Snap-populate"));
connect(job, &QSnapdFindRequest::complete, stream, [stream, this, state, job]() { connect(job, &QSnapdFindRequest::complete, stream, [stream, this, state, job]() {
static_assert(std::is_base_of<QSnapdRequest, T>::value, "we can only populate QSnapdRequest");
QSet<SnapResource*> higher = kFilter<QSet<SnapResource*>>(m_resources, [state](AbstractResource* res){ return res->state()>=state; }); QSet<SnapResource*> higher = kFilter<QSet<SnapResource*>>(m_resources, [state](AbstractResource* res){ return res->state()>=state; });
QVector<AbstractResource*> ret; QVector<AbstractResource*> ret;
......
...@@ -43,7 +43,7 @@ public: ...@@ -43,7 +43,7 @@ public:
int updatesCount() const override; int updatesCount() const override;
AbstractBackendUpdater* backendUpdater() const override; AbstractBackendUpdater* backendUpdater() const override;
AbstractReviewsBackend* reviewsBackend() const override; AbstractReviewsBackend* reviewsBackend() const override;
bool isValid() const override { return m_valid; } bool isValid() const override { return true; }
QList<QAction*> messageActions() const override { return {}; } QList<QAction*> messageActions() const override { return {}; }
Transaction* installApplication(AbstractResource* app) override; Transaction* installApplication(AbstractResource* app) override;
...@@ -64,7 +64,6 @@ private: ...@@ -64,7 +64,6 @@ private:
StandardBackendUpdater* m_updater; StandardBackendUpdater* m_updater;
SnapReviewsBackend* m_reviews; SnapReviewsBackend* m_reviews;
bool m_valid = true;
bool m_fetching = false; bool m_fetching = false;
QSnapdClient m_client; QSnapdClient m_client;
}; };
......
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