Commit e610cd18 authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧

snap & packagekit: Refresh ratings when they arrive

As we already did for Flatpak.

BUG: 407471
parent 91d728a2
......@@ -37,7 +37,7 @@ QSharedPointer<OdrsReviewsBackend> AppStreamIntegration::reviews()
if (m_reviews) {
ret = m_reviews;
} else {
ret = QSharedPointer<OdrsReviewsBackend>(new OdrsReviewsBackend(nullptr));
ret = QSharedPointer<OdrsReviewsBackend>(new OdrsReviewsBackend());
m_reviews = ret;
}
return ret;
......
......@@ -48,8 +48,8 @@
// #define APIURL "http://127.0.0.1:5000/1.0/reviews/api"
#define APIURL "https://odrs.gnome.org/1.0/reviews/api"
OdrsReviewsBackend::OdrsReviewsBackend(AbstractResourcesBackend *parent)
: AbstractReviewsBackend(parent)
OdrsReviewsBackend::OdrsReviewsBackend()
: AbstractReviewsBackend(nullptr)
, m_isFetching(false)
, m_nam(new QNetworkAccessManager(this))
{
......@@ -346,3 +346,13 @@ bool OdrsReviewsBackend::isResourceSupported(AbstractResource* res) const
{
return !res->appstreamId().isEmpty();
}
void OdrsReviewsBackend::emitRatingFetched(AbstractResourcesBackend* b, const QList<AbstractResource *>& resources) const
{
b->emitRatingsReady();
foreach(AbstractResource* res, resources) {
if (m_ratings.contains(res->appstreamId())) {
Q_EMIT res->ratingFetched();
}
}
}
......@@ -35,7 +35,7 @@ class DISCOVERCOMMON_EXPORT OdrsReviewsBackend : public AbstractReviewsBackend
{
Q_OBJECT
public:
explicit OdrsReviewsBackend(AbstractResourcesBackend *parent = nullptr);
explicit OdrsReviewsBackend();
QString userName() const override;
void login() override {}
......@@ -50,8 +50,8 @@ public:
void submitReview(AbstractResource *, const QString &summary, const QString &description, const QString &rating) override;
void flagReview(Review *, const QString &, const QString &) override {}
void submitUsefulness(Review *review, bool useful) override;
QStringList appstreamIds() const { return m_ratings.keys(); }
bool isResourceSupported(AbstractResource * res) const override;
void emitRatingFetched(AbstractResourcesBackend* backend, const QList<AbstractResource*>& res) const;
private Q_SLOTS:
void ratingsFetched(KJob *job);
......
......@@ -25,6 +25,7 @@
#include "FlatpakSourcesBackend.h"
#include "FlatpakJobTransaction.h"
#include <utils.h>
#include <resources/StandardBackendUpdater.h>
#include <resources/SourcesModel.h>
#include <Transaction/Transaction.h>
......@@ -107,7 +108,9 @@ FlatpakBackend::FlatpakBackend(QObject* parent)
SourcesModel::global()->addSourcesBackend(m_sources);
}
connect(m_reviews.data(), &OdrsReviewsBackend::ratingsReady, this, &FlatpakBackend::announceRatingsReady);
connect(m_reviews.data(), &OdrsReviewsBackend::ratingsReady, this, [this] {
m_reviews->emitRatingFetched(this, kTransform<QList<AbstractResource*>>(m_resources.values(), [] (AbstractResource* r) { return r; }));
});
/* Override the umask to 022 to make it possible to share files between
* the plasma-discover process and flatpak system helper process.
......@@ -133,18 +136,6 @@ bool FlatpakBackend::isValid() const
return m_sources && !m_installations.isEmpty();
}
void FlatpakBackend::announceRatingsReady()
{
emitRatingsReady();
const auto ids = m_reviews->appstreamIds().toSet();
foreach(AbstractResource* res, m_resources) {
if (ids.contains(res->appstreamId())) {
Q_EMIT res->ratingFetched();
}
}
}
class FlatpakFetchRemoteResourceJob : public QNetworkAccessManager
{
Q_OBJECT
......@@ -209,8 +200,8 @@ Q_SIGNALS:
void jobFinished(bool success, FlatpakResource *resource);
private:
FlatpakBackend *m_backend;
QUrl m_url;
FlatpakBackend *const m_backend;
const QUrl m_url;
};
FlatpakRemote * FlatpakBackend::getFlatpakRemoteByUrl(const QString &url, FlatpakInstallation *installation) const
......
......@@ -94,7 +94,9 @@ PackageKitBackend::PackageKitBackend(QObject* parent)
connect(PackageKit::Daemon::global(), &PackageKit::Daemon::restartScheduled, m_updater, &PackageKitUpdater::enableNeedsReboot);
connect(PackageKit::Daemon::global(), &PackageKit::Daemon::updatesChanged, this, &PackageKitBackend::fetchUpdates);
connect(PackageKit::Daemon::global(), &PackageKit::Daemon::isRunningChanged, this, &PackageKitBackend::checkDaemonRunning);
connect(m_reviews.data(), &OdrsReviewsBackend::ratingsReady, this, &AbstractResourcesBackend::emitRatingsReady);
connect(m_reviews.data(), &OdrsReviewsBackend::ratingsReady, this, [this] {
m_reviews->emitRatingFetched(this, kTransform<QList<AbstractResource*>>(m_packages.packages.values(), [] (AbstractResource* r) { return r; }));
});
auto proxyWatch = new QFileSystemWatcher(this);
proxyWatch->addPath(QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + QLatin1String("/kioslaverc"));
......
......@@ -68,9 +68,11 @@ private:
SnapBackend::SnapBackend(QObject* parent)
: AbstractResourcesBackend(parent)
, m_updater(new StandardBackendUpdater(this))
, m_reviews(new OdrsReviewsBackend(this))
, m_reviews(new OdrsReviewsBackend()) //TODO: use AppStreamIntegration
{
connect(m_reviews, &OdrsReviewsBackend::ratingsReady, this, &AbstractResourcesBackend::emitRatingsReady);
connect(m_reviews.data(), &OdrsReviewsBackend::ratingsReady, this, [this] {
m_reviews->emitRatingFetched(this, kTransform<QList<AbstractResource*>>(m_resources.values(), [] (AbstractResource* r) { return r; }));
});
//make sure we populate the installed resources first
refreshStates();
......@@ -78,6 +80,8 @@ SnapBackend::SnapBackend(QObject* parent)
SourcesModel::global()->addSourcesBackend(new SnapSourcesBackend(this));
}
SnapBackend::~SnapBackend() = default;
int SnapBackend::updatesCount() const
{
return m_updater->updatesCount();
......@@ -181,7 +185,7 @@ AbstractBackendUpdater* SnapBackend::backendUpdater() const
AbstractReviewsBackend* SnapBackend::reviewsBackend() const
{
return m_reviews;
return m_reviews.data();
}
Transaction* SnapBackend::installApplication(AbstractResource* app, const AddonList& addons)
......
......@@ -24,6 +24,7 @@
#include <resources/AbstractResource.h>
#include <resources/AbstractResourcesBackend.h>
#include <QVariantList>
#include <QScopedPointer>
#include <Snapd/Client>
#include <functional>
......@@ -36,6 +37,7 @@ class SnapBackend : public AbstractResourcesBackend
Q_OBJECT
public:
explicit SnapBackend(QObject* parent = nullptr);
~SnapBackend() override;
ResultsStream * search(const AbstractResourcesBackend::Filters & search) override;
ResultsStream * findResourceByPackageName(const QUrl& search);
......@@ -66,7 +68,7 @@ private:
QHash<QString, SnapResource*> m_resources;
StandardBackendUpdater* m_updater;
OdrsReviewsBackend* m_reviews;
QScopedPointer<OdrsReviewsBackend> m_reviews;
bool m_valid = true;
bool m_fetching = false;
......
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