summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleix Pol <[email protected]>2016-10-26 00:54:45 +0200
committerAleix Pol <[email protected]>2016-10-26 00:54:45 +0200
commitd26f73cf28f80f3403e062cf127c43e9a2f3f93b (patch)
tree2cb5b0147028e09ff1bc0e9748557d2d8091efb6
parent9ebddba7ad5db564cec6a98806265e90cacc85f2 (diff)
Adapt to new backends API
-rw-r--r--libdiscover/backends/SnapBackend/SnapBackend.cpp29
-rw-r--r--libdiscover/backends/SnapBackend/SnapBackend.h8
2 files changed, 17 insertions, 20 deletions
diff --git a/libdiscover/backends/SnapBackend/SnapBackend.cpp b/libdiscover/backends/SnapBackend/SnapBackend.cpp
index 2e5792d..d0ade40 100644
--- a/libdiscover/backends/SnapBackend/SnapBackend.cpp
+++ b/libdiscover/backends/SnapBackend/SnapBackend.cpp
@@ -49,32 +49,29 @@ SnapBackend::SnapBackend(QObject* parent)
populate(m_socket.snaps(), AbstractResource::Installed);
}
-QVector<AbstractResource*> SnapBackend::allResources() const
-{
- QVector<AbstractResource*> ret;
- ret.reserve(m_resources.size());
- foreach(AbstractResource* res, m_resources) {
- ret += res;
- }
- return ret;
-}
-
int SnapBackend::updatesCount() const
{
return m_updater->updatesCount();
}
-AbstractResource* SnapBackend::resourceByPackageName(const QString& name) const
+ResultsStream * SnapBackend::search(const AbstractResourcesBackend::Filters& filters)
{
- return m_resources.value(name);
+ if (filters.state >= AbstractResource::Installed) {
+ return new ResultsStream(QStringLiteral("Snap-installed"), containerValues<QVector<AbstractResource*>>(m_resources.values()));
+ } else {
+ auto res = populate(m_socket.find(filters.search), AbstractResource::None);
+ return new ResultsStream(QStringLiteral("Snap-find"), res);
+ }
+ return new ResultsStream(QStringLiteral("Snap-void"), {});
}
-QList<AbstractResource*> SnapBackend::searchPackageName(const QString& name)
+ResultsStream * SnapBackend::findResourceByPackageName(const QString& search)
{
- return populate(m_socket.find(name), AbstractResource::None);
+ auto pkg = m_resources.value(search);
+ return new ResultsStream(QStringLiteral("SnapPkg"), pkg ? QVector<AbstractResource*>{pkg} : QVector<AbstractResource*>{});
}
-QList<AbstractResource*> SnapBackend::populate(SnapJob* job, AbstractResource::State state)
+QVector<AbstractResource*> SnapBackend::populate(SnapJob* job, AbstractResource::State state)
{
if (!job->exec()) {
qWarning() << "job failed" << job;
@@ -83,7 +80,7 @@ QList<AbstractResource*> SnapBackend::populate(SnapJob* job, AbstractResource::S
const auto snaps = job->result().toArray();
- QList<AbstractResource*> ret;
+ QVector<AbstractResource*> ret;
QSet<SnapResource*> resources;
for(const auto& snap: snaps) {
const auto snapObj = snap.toObject();
diff --git a/libdiscover/backends/SnapBackend/SnapBackend.h b/libdiscover/backends/SnapBackend/SnapBackend.h
index 1a6b963..68b5f47 100644
--- a/libdiscover/backends/SnapBackend/SnapBackend.h
+++ b/libdiscover/backends/SnapBackend/SnapBackend.h
@@ -36,12 +36,12 @@ Q_OBJECT
public:
explicit SnapBackend(QObject* parent = nullptr);
- AbstractResource* resourceByPackageName(const QString& name) const override;
+ ResultsStream * search(const AbstractResourcesBackend::Filters & search) override;
+ ResultsStream * findResourceByPackageName(const QString & search) override;
+
int updatesCount() const override;
AbstractBackendUpdater* backendUpdater() const override;
AbstractReviewsBackend* reviewsBackend() const override;
- QList<AbstractResource*> searchPackageName(const QString& searchText) override;
- QVector<AbstractResource*> allResources() const override;
bool isValid() const override { return true; } // No external file dependencies that could cause runtime errors
QList<QAction*> messageActions() const override { return {}; }
@@ -53,7 +53,7 @@ public:
private:
void setFetching(bool fetching);
- QList<AbstractResource*> populate(SnapJob* snaps, AbstractResource::State state);
+ QVector<AbstractResource*> populate(SnapJob* snaps, AbstractResource::State state);
QHash<QString, SnapResource*> m_resources;
StandardBackendUpdater* m_updater;