[gnome-software] Set the content rating if available



commit a197de02c2b8a5c277c49e09ae7101a6f4f2b0f9
Author: Richard Hughes <richard hughsie com>
Date:   Tue Sep 20 21:02:38 2016 +0100

    Set the content rating if available

 src/gs-app.c               |   45 ++++++++++++++++++++++++++++++++++++++++++++
 src/gs-app.h               |    3 ++
 src/plugins/gs-appstream.c |   10 +++++++++
 3 files changed, 58 insertions(+), 0 deletions(-)
---
diff --git a/src/gs-app.c b/src/gs-app.c
index 30b01e1..12b89a5 100644
--- a/src/gs-app.c
+++ b/src/gs-app.c
@@ -118,6 +118,7 @@ struct _GsApp
        gboolean                 license_is_free;
        GsApp                   *runtime;
        GFile                   *local_file;
+       AsContentRating         *content_rating;
        GdkPixbuf               *pixbuf;
 };
 
@@ -372,6 +373,15 @@ gs_app_to_string (GsApp *app)
                g_autofree gchar *fn = g_file_get_path (app->local_file);
                gs_app_kv_lpad (str, "local-filename", fn);
        }
+       if (app->content_rating != NULL) {
+               guint age = as_content_rating_get_minimum_age (app->content_rating);
+               if (age != G_MAXUINT) {
+                       g_autofree gchar *value = g_strdup_printf ("%u", age);
+                       gs_app_kv_lpad (str, "content-age", value);
+               }
+               gs_app_kv_lpad (str, "content-rating",
+                               as_content_rating_get_kind (app->content_rating));
+       }
        tmp = g_hash_table_lookup (app->urls, as_url_kind_to_string (AS_URL_KIND_HOMEPAGE));
        if (tmp != NULL)
                gs_app_kv_lpad (str, "url{homepage}", tmp);
@@ -1379,6 +1389,39 @@ gs_app_set_local_file (GsApp *app, GFile *local_file)
 }
 
 /**
+ * gs_app_get_content_rating:
+ * @app: a #GsApp
+ *
+ * Gets the content rating for this application.
+ *
+ * Returns: (transfer none): a #AsContentRating, or %NULL
+ *
+ * Since: 3.24
+ **/
+AsContentRating *
+gs_app_get_content_rating (GsApp *app)
+{
+       g_return_val_if_fail (GS_IS_APP (app), NULL);
+       return app->content_rating;
+}
+
+/**
+ * gs_app_set_content_rating:
+ * @app: a #GsApp
+ * @content_rating: a #AsContentRating, or %NULL
+ *
+ * Sets the content rating for this application.
+ *
+ * Since: 3.24
+ **/
+void
+gs_app_set_content_rating (GsApp *app, AsContentRating *content_rating)
+{
+       g_return_if_fail (GS_IS_APP (app));
+       g_set_object (&app->content_rating, content_rating);
+}
+
+/**
  * gs_app_get_runtime:
  * @app: a #GsApp
  *
@@ -3356,6 +3399,8 @@ gs_app_finalize (GObject *object)
                g_ptr_array_unref (app->keywords);
        if (app->local_file != NULL)
                g_object_unref (app->local_file);
+       if (app->content_rating != NULL)
+               g_object_unref (app->content_rating);
        if (app->pixbuf != NULL)
                g_object_unref (app->pixbuf);
 
diff --git a/src/gs-app.h b/src/gs-app.h
index d7bc7ef..6b89e6f 100644
--- a/src/gs-app.h
+++ b/src/gs-app.h
@@ -206,6 +206,9 @@ void                 gs_app_add_icon                (GsApp          *app,
 GFile          *gs_app_get_local_file          (GsApp          *app);
 void            gs_app_set_local_file          (GsApp          *app,
                                                 GFile          *local_file);
+AsContentRating        *gs_app_get_content_rating      (GsApp          *app);
+void            gs_app_set_content_rating      (GsApp          *app,
+                                                AsContentRating *content_rating);
 GsApp          *gs_app_get_runtime             (GsApp          *app);
 void            gs_app_set_runtime             (GsApp          *app,
                                                 GsApp          *runtime);
diff --git a/src/plugins/gs-appstream.c b/src/plugins/gs-appstream.c
index 9d6043a..cc51d9b 100644
--- a/src/plugins/gs-appstream.c
+++ b/src/plugins/gs-appstream.c
@@ -576,6 +576,16 @@ gs_appstream_refine_app (GsPlugin *plugin,
            gs_app_get_branch (app) == NULL)
                gs_app_set_branch (app, as_app_get_branch (item));
 
+       /* set content rating */
+       array = as_app_get_content_ratings (item);
+       for (i = 0; i < array->len; i++) {
+               AsContentRating *cr = g_ptr_array_index (array, i);
+               if (g_strcmp0 (as_content_rating_get_kind (cr), "oars-1.0") == 0) {
+                       gs_app_set_content_rating (app, cr);
+                       break;
+               }
+       }
+
        /* bundle-kind */
        if (gs_app_get_bundle_kind (app) == AS_BUNDLE_KIND_UNKNOWN)
                gs_app_set_bundle_kind (app, gs_appstream_get_bundle_kind (item));


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