[gnome-software: 3/25] gs-odrs-provider: Add new type for refine flags
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software: 3/25] gs-odrs-provider: Add new type for refine flags
- Date: Tue, 1 Mar 2022 12:28:12 +0000 (UTC)
commit 0f477e2d4f89ada81e431691a3fe09e088cac973
Author: Philip Withnall <pwithnall endlessos org>
Date: Wed Feb 23 14:01:09 2022 +0000
gs-odrs-provider: Add new type for refine flags
Rather than reusing the not-really-appropriate `GsPluginRefineFlags`,
which is not appropriate because it carries a lot of unrelated flags,
and has a duplicate flag for ratings.
This further decouples the `GsOdrsProvider` API from `GsPlugin`.
Signed-off-by: Philip Withnall <pwithnall endlessos org>
lib/gs-odrs-provider.c | 33 +++++++++++++++------------------
lib/gs-odrs-provider.h | 17 +++++++++++++++--
lib/gs-plugin-job-refine.c | 11 +++++++++--
3 files changed, 39 insertions(+), 22 deletions(-)
---
diff --git a/lib/gs-odrs-provider.c b/lib/gs-odrs-provider.c
index 147fd62d4..11fb86db1 100644
--- a/lib/gs-odrs-provider.c
+++ b/lib/gs-odrs-provider.c
@@ -820,11 +820,11 @@ gs_odrs_provider_fetch_for_app (GsOdrsProvider *self,
}
static gboolean
-refine_app (GsOdrsProvider *self,
- GsApp *app,
- GsPluginRefineFlags flags,
- GCancellable *cancellable,
- GError **error)
+refine_app (GsOdrsProvider *self,
+ GsApp *app,
+ GsOdrsProviderRefineFlags flags,
+ GCancellable *cancellable,
+ GError **error)
{
/* not valid */
if (gs_app_get_kind (app) == AS_COMPONENT_KIND_ADDON)
@@ -833,7 +833,7 @@ refine_app (GsOdrsProvider *self,
return TRUE;
/* add reviews if possible */
- if (flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_REVIEWS) {
+ if (flags & GS_ODRS_PROVIDER_REFINE_FLAGS_GET_REVIEWS) {
AsReview *review;
g_autoptr(GPtrArray) reviews = NULL;
@@ -868,8 +868,7 @@ refine_app (GsOdrsProvider *self,
}
/* add ratings if possible */
- if (flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_REVIEW_RATINGS ||
- flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_RATING) {
+ if (flags & GS_ODRS_PROVIDER_REFINE_FLAGS_GET_RATINGS) {
if (gs_app_get_review_ratings (app) != NULL)
return TRUE;
if (!gs_odrs_provider_refine_ratings (self, app, cancellable, error))
@@ -1386,19 +1385,17 @@ gs_odrs_provider_refresh_ratings_finish (GsOdrsProvider *self,
* specified in @flags.
*
* Returns: %TRUE on success, %FALSE otherwise
- * Since: 41
+ * Since: 42
*/
gboolean
-gs_odrs_provider_refine (GsOdrsProvider *self,
- GsAppList *list,
- GsPluginRefineFlags flags,
- GCancellable *cancellable,
- GError **error)
+gs_odrs_provider_refine (GsOdrsProvider *self,
+ GsAppList *list,
+ GsOdrsProviderRefineFlags flags,
+ GCancellable *cancellable,
+ GError **error)
{
- /* nothing to do here */
- if ((flags & (GS_PLUGIN_REFINE_FLAGS_REQUIRE_REVIEWS |
- GS_PLUGIN_REFINE_FLAGS_REQUIRE_REVIEW_RATINGS |
- GS_PLUGIN_REFINE_FLAGS_REQUIRE_RATING)) == 0)
+ if ((flags & (GS_ODRS_PROVIDER_REFINE_FLAGS_GET_RATINGS |
+ GS_ODRS_PROVIDER_REFINE_FLAGS_GET_REVIEWS)) == 0)
return TRUE;
for (guint i = 0; i < gs_app_list_length (list); i++) {
diff --git a/lib/gs-odrs-provider.h b/lib/gs-odrs-provider.h
index 2f045d2ed..6959cca4a 100644
--- a/lib/gs-odrs-provider.h
+++ b/lib/gs-odrs-provider.h
@@ -16,7 +16,6 @@
#include "gs-app-list.h"
#include "gs-download-utils.h"
-#include "gs-plugin-types.h"
G_BEGIN_DECLS
@@ -41,6 +40,20 @@ typedef enum {
#define GS_ODRS_PROVIDER_ERROR gs_odrs_provider_error_quark ()
GQuark gs_odrs_provider_error_quark (void);
+/**
+ * GsOdrsProviderRefineFlags:
+ * @GS_ODRS_PROVIDER_REFINE_FLAGS_GET_RATINGS: Get the numerical ratings for the app.
+ * @GS_ODRS_PROVIDER_REFINE_FLAGS_GET_REVIEWS: Get the written reviews for the app.
+ *
+ * The flags for refining apps to get their reviews or ratings.
+ *
+ * Since: 42
+ */
+typedef enum {
+ GS_ODRS_PROVIDER_REFINE_FLAGS_GET_RATINGS = (1 << 0),
+ GS_ODRS_PROVIDER_REFINE_FLAGS_GET_REVIEWS = (1 << 1),
+} GsOdrsProviderRefineFlags;
+
#define GS_TYPE_ODRS_PROVIDER (gs_odrs_provider_get_type ())
G_DECLARE_FINAL_TYPE (GsOdrsProvider, gs_odrs_provider, GS, ODRS_PROVIDER, GObject)
@@ -65,7 +78,7 @@ gboolean gs_odrs_provider_refresh_ratings_finish(GsOdrsProvider *self,
gboolean gs_odrs_provider_refine (GsOdrsProvider *self,
GsAppList *list,
- GsPluginRefineFlags flags,
+ GsOdrsProviderRefineFlags flags,
GCancellable *cancellable,
GError **error);
diff --git a/lib/gs-plugin-job-refine.c b/lib/gs-plugin-job-refine.c
index b7d097adb..4eba1f793 100644
--- a/lib/gs-plugin-job-refine.c
+++ b/lib/gs-plugin-job-refine.c
@@ -182,6 +182,7 @@ run_refine_filter (GsPluginJobRefine *self,
GError **error)
{
GsOdrsProvider *odrs_provider;
+ GsOdrsProviderRefineFlags odrs_refine_flags = 0;
GPtrArray *plugins; /* (element-type GsPlugin) */
/* run each plugin */
@@ -215,9 +216,15 @@ run_refine_filter (GsPluginJobRefine *self,
/* Add ODRS data if needed */
odrs_provider = gs_plugin_loader_get_odrs_provider (plugin_loader);
- if (odrs_provider != NULL) {
+ if (refine_flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_REVIEWS)
+ odrs_refine_flags |= GS_ODRS_PROVIDER_REFINE_FLAGS_GET_REVIEWS;
+ if (refine_flags & (GS_PLUGIN_REFINE_FLAGS_REQUIRE_REVIEW_RATINGS |
+ GS_PLUGIN_REFINE_FLAGS_REQUIRE_RATING))
+ odrs_refine_flags |= GS_ODRS_PROVIDER_REFINE_FLAGS_GET_RATINGS;
+
+ if (odrs_provider != NULL && odrs_refine_flags != 0) {
if (!gs_odrs_provider_refine (odrs_provider,
- list, refine_flags, cancellable, error))
+ list, odrs_refine_flags, cancellable, error))
return FALSE;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]