[gnome-software] Prepare for application IDs with prefixes



commit f5a83399649c65dfb62955d9b1a36bcdea04c561
Author: Richard Hughes <richard hughsie com>
Date:   Wed Feb 17 11:38:03 2016 +0000

    Prepare for application IDs with prefixes
    
    This is required to properly support different providers of per-user and per-system apps.

 src/gs-app.c                            |   14 ++++++++++++++
 src/gs-app.h                            |    1 +
 src/plugins/gs-plugin-xdg-app-reviews.c |   18 +++++++++---------
 3 files changed, 24 insertions(+), 9 deletions(-)
---
diff --git a/src/gs-app.c b/src/gs-app.c
index ae82e66..22026a4 100644
--- a/src/gs-app.c
+++ b/src/gs-app.c
@@ -380,6 +380,20 @@ gs_app_get_id (GsApp *app)
 }
 
 /**
+ * gs_app_get_id_no_prefix:
+ **/
+const gchar *
+gs_app_get_id_no_prefix (GsApp *app)
+{
+       gchar *tmp;
+       g_return_val_if_fail (GS_IS_APP (app), NULL);
+       tmp = g_strrstr (app->id, ":");
+       if (tmp != NULL)
+               return tmp + 1;
+       return app->id;
+}
+
+/**
  * gs_app_set_id:
  */
 void
diff --git a/src/gs-app.h b/src/gs-app.h
index e5e514b..97d9c9f 100644
--- a/src/gs-app.h
+++ b/src/gs-app.h
@@ -99,6 +99,7 @@ void           gs_app_subsume                 (GsApp          *app,
 const gchar    *gs_app_get_id                  (GsApp          *app);
 void            gs_app_set_id                  (GsApp          *app,
                                                 const gchar    *id);
+const gchar    *gs_app_get_id_no_prefix        (GsApp          *app);
 GsAppKind       gs_app_get_kind                (GsApp          *app);
 void            gs_app_set_kind                (GsApp          *app,
                                                 GsAppKind       kind);
diff --git a/src/plugins/gs-plugin-xdg-app-reviews.c b/src/plugins/gs-plugin-xdg-app-reviews.c
index 8b7eaad..568492c 100644
--- a/src/plugins/gs-plugin-xdg-app-reviews.c
+++ b/src/plugins/gs-plugin-xdg-app-reviews.c
@@ -433,14 +433,14 @@ xdg_app_review_get_ratings (GsPlugin *plugin, GsApp *app, GError **error)
        cachedir = gs_utils_get_cachedir ("ratings", error);
        if (cachedir == NULL)
                return NULL;
-       cachefn = g_strdup_printf ("%s/%s.json", cachedir, gs_app_get_id (app));
+       cachefn = g_strdup_printf ("%s/%s.json", cachedir, gs_app_get_id_no_prefix (app));
        cachefn_file = g_file_new_for_path (cachefn);
        if (gs_utils_get_file_age (cachefn_file) < XDG_APP_REVIEW_CACHE_AGE_MAX) {
                g_autofree gchar *json_data = NULL;
                if (!g_file_get_contents (cachefn, &json_data, NULL, error))
                        return NULL;
                g_debug ("got ratings data for %s from %s",
-                        gs_app_get_id (app), cachefn);
+                        gs_app_get_id_no_prefix (app), cachefn);
                return xdg_app_review_parse_ratings (json_data, -1, error);
        }
 
@@ -448,7 +448,7 @@ xdg_app_review_get_ratings (GsPlugin *plugin, GsApp *app, GError **error)
         * review the application ourselves */
        uri = g_strdup_printf ("%s/ratings/%s",
                               plugin->priv->review_server,
-                              gs_app_get_id (app));
+                              gs_app_get_id_no_prefix (app));
        msg = soup_message_new (SOUP_METHOD_GET, uri);
        status_code = soup_session_send_message (plugin->soup_session, msg);
        if (status_code != SOUP_STATUS_OK) {
@@ -539,14 +539,14 @@ xdg_app_review_fetch_for_app (GsPlugin *plugin, GsApp *app, GError **error)
        cachedir = gs_utils_get_cachedir ("reviews", error);
        if (cachedir == NULL)
                return NULL;
-       cachefn = g_strdup_printf ("%s/%s.json", cachedir, gs_app_get_id (app));
+       cachefn = g_strdup_printf ("%s/%s.json", cachedir, gs_app_get_id_no_prefix (app));
        cachefn_file = g_file_new_for_path (cachefn);
        if (gs_utils_get_file_age (cachefn_file) < XDG_APP_REVIEW_CACHE_AGE_MAX) {
                g_autofree gchar *json_data = NULL;
                if (!g_file_get_contents (cachefn, &json_data, NULL, error))
                        return NULL;
                g_debug ("got review data for %s from %s",
-                        gs_app_get_id (app), cachefn);
+                        gs_app_get_id_no_prefix (app), cachefn);
                return xdg_app_review_parse_reviews (json_data, -1, error);
        }
 
@@ -561,7 +561,7 @@ xdg_app_review_fetch_for_app (GsPlugin *plugin, GsApp *app, GError **error)
        json_builder_set_member_name (builder, "user_hash");
        json_builder_add_string_value (builder, plugin->priv->user_hash);
        json_builder_set_member_name (builder, "app_id");
-       json_builder_add_string_value (builder, gs_app_get_id (app));
+       json_builder_add_string_value (builder, gs_app_get_id_no_prefix (app));
        json_builder_set_member_name (builder, "locale");
        json_builder_add_string_value (builder, plugin->locale);
        json_builder_set_member_name (builder, "distro");
@@ -682,7 +682,7 @@ gs_plugin_refine (GsPlugin *plugin,
                        app = GS_APP (l->data);
                        if (gs_app_get_reviews(app)->len > 0)
                                continue;
-                       if (gs_app_get_id (app) == NULL)
+                       if (gs_app_get_id_no_prefix (app) == NULL)
                                continue;
                        if (gs_app_get_id_kind (app) == AS_ID_KIND_ADDON)
                                continue;
@@ -702,7 +702,7 @@ gs_plugin_refine (GsPlugin *plugin,
                        app = GS_APP (l->data);
                        if (gs_app_get_review_ratings(app) != NULL)
                                continue;
-                       if (gs_app_get_id (app) == NULL)
+                       if (gs_app_get_id_no_prefix (app) == NULL)
                                continue;
                        if (gs_app_get_id_kind (app) == AS_ID_KIND_ADDON)
                                continue;
@@ -773,7 +773,7 @@ gs_plugin_review_submit (GsPlugin *plugin,
 
        /* save as we don't re-request the review from the server */
        gs_review_set_reviewer (review, g_get_real_name ());
-       gs_review_add_metadata (review, "app_id", gs_app_get_id (app));
+       gs_review_add_metadata (review, "app_id", gs_app_get_id_no_prefix (app));
        gs_review_add_metadata (review, "user_skey",
                                gs_app_get_metadata_item (app, "XdgAppReviews::user_skey"));
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]