[gnome-software/1610-not-possible-to-use-neutral-colour-banner-backgrounds: 1/2] gs-app: Introduce gs_app_get_user_key_colors()




commit ee4f7c783280e916ab30b19a4bba4fd62c1daf60
Author: Milan Crha <mcrha redhat com>
Date:   Thu Mar 3 13:38:29 2022 +0100

    gs-app: Introduce gs_app_get_user_key_colors()
    
    That tracks whether the app's key colors had been provided by the user.
    If not, it had been calculated from the app's icon.

 lib/gs-app.c | 28 ++++++++++++++++++++++++++++
 lib/gs-app.h |  1 +
 2 files changed, 29 insertions(+)
---
diff --git a/lib/gs-app.c b/lib/gs-app.c
index 3e605a209..6a30d0aef 100644
--- a/lib/gs-app.c
+++ b/lib/gs-app.c
@@ -78,6 +78,7 @@ typedef struct
        GPtrArray               *screenshots;
        GPtrArray               *categories;
        GArray                  *key_colors;  /* (nullable) (element-type GdkRGBA) */
+       gboolean                 user_key_colors;
        GHashTable              *urls;  /* (element-type AsUrlKind utf8) (owned) (nullable) */
        GHashTable              *launchables;
        gchar                   *url_missing;
@@ -708,6 +709,8 @@ gs_app_to_string_append (GsApp *app, GString *str)
                tmp = g_ptr_array_index (priv->categories, i);
                gs_app_kv_lpad (str, "category", tmp);
        }
+       if (priv->user_key_colors)
+               gs_app_kv_lpad (str, "user-key-colors", "yes");
        for (i = 0; priv->key_colors != NULL && i < priv->key_colors->len; i++) {
                GdkRGBA *color = &g_array_index (priv->key_colors, GdkRGBA, i);
                g_autofree gchar *key = NULL;
@@ -4299,6 +4302,7 @@ calculate_key_colors (GsApp *app)
        /* Lazily create the array */
        if (priv->key_colors == NULL)
                priv->key_colors = g_array_new (FALSE, FALSE, sizeof (GdkRGBA));
+       priv->user_key_colors = FALSE;
 
        /* Look for an override first. Parse and use it if possible. This is
         * typically specified in the appdata for an app as:
@@ -4335,6 +4339,8 @@ calculate_key_colors (GsApp *app)
                                g_array_append_val (priv->key_colors, rgba);
                        }
 
+                       priv->user_key_colors = TRUE;
+
                        return;
                } else {
                        g_warning ("Invalid value for GnomeSoftware::key-colors for %s: %s",
@@ -4471,6 +4477,7 @@ gs_app_set_key_colors (GsApp *app, GArray *key_colors)
        g_return_if_fail (GS_IS_APP (app));
        g_return_if_fail (key_colors != NULL);
        locker = g_mutex_locker_new (&priv->mutex);
+       priv->user_key_colors = FALSE;
        if (_g_set_array (&priv->key_colors, key_colors))
                gs_app_queue_notify (app, obj_props[PROP_KEY_COLORS]);
 }
@@ -4495,10 +4502,31 @@ gs_app_add_key_color (GsApp *app, GdkRGBA *key_color)
        if (priv->key_colors == NULL)
                priv->key_colors = g_array_new (FALSE, FALSE, sizeof (GdkRGBA));
 
+       priv->user_key_colors = FALSE;
        g_array_append_val (priv->key_colors, *key_color);
        gs_app_queue_notify (app, obj_props[PROP_KEY_COLORS]);
 }
 
+/**
+ * gs_app_get_user_key_colors:
+ * @app: a #GsApp
+ *
+ * Returns whether the key colors provided by gs_app_get_key_colors()
+ * are set by the user (using `GnomeSoftware::key-colors`). %FALSE
+ * means the colors have been calculated from the @app icon.
+ *
+ * Returns: whether the key colors have been provided by the user.
+ *
+ * Since: 42
+ **/
+gboolean
+gs_app_get_user_key_colors (GsApp *app)
+{
+       GsAppPrivate *priv = gs_app_get_instance_private (app);
+       g_return_val_if_fail (GS_IS_APP (app), FALSE);
+       return priv->user_key_colors;
+}
+
 /**
  * gs_app_add_kudo:
  * @app: a #GsApp
diff --git a/lib/gs-app.h b/lib/gs-app.h
index 91701f903..325dfd86d 100644
--- a/lib/gs-app.h
+++ b/lib/gs-app.h
@@ -446,6 +446,7 @@ void                 gs_app_set_key_colors          (GsApp          *app,
                                                 GArray         *key_colors);
 void            gs_app_add_key_color           (GsApp          *app,
                                                 GdkRGBA        *key_color);
+gboolean       gs_app_get_user_key_colors      (GsApp          *app);
 void            gs_app_set_is_update_downloaded (GsApp         *app,
                                                  gboolean       is_update_downloaded);
 gboolean        gs_app_get_is_update_downloaded (GsApp         *app);


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