[gnome-software] Add support for application key colors



commit 8d0dfa2625a15771ef4220fdc6d607664730e5bd
Author: Richard Hughes <richard hughsie com>
Date:   Tue Apr 5 19:27:57 2016 +0100

    Add support for application key colors
    
    These are important colors picked from the default icon that can be used for
    theming.

 src/gs-app-tile.c                  |    8 +-
 src/gs-app.c                       |   44 ++++++++
 src/gs-app.h                       |    6 +
 src/gs-cmd.c                       |    2 +
 src/gs-feature-tile.c              |    8 +-
 src/gs-plugin.h                    |    1 +
 src/gs-popular-tile.c              |    9 +-
 src/gs-self-test.c                 |   22 ++++
 src/gs-upgrade-banner.c            |    8 +-
 src/gs-utils.c                     |   26 +++++-
 src/gs-utils.h                     |    5 +-
 src/plugins/Makefile.am            |    6 +
 src/plugins/gs-plugin-key-colors.c |  195 ++++++++++++++++++++++++++++++++++++
 13 files changed, 315 insertions(+), 25 deletions(-)
---
diff --git a/src/gs-app-tile.c b/src/gs-app-tile.c
index 0366ca8..5aefdfc 100644
--- a/src/gs-app-tile.c
+++ b/src/gs-app-tile.c
@@ -127,7 +127,6 @@ void
 gs_app_tile_set_app (GsAppTile *tile, GsApp *app)
 {
        const GdkPixbuf *pixbuf;
-       const gchar *css;
        g_autofree gchar *text = NULL;
 
        g_return_if_fail (GS_IS_APP_TILE (tile));
@@ -154,10 +153,9 @@ gs_app_tile_set_app (GsAppTile *tile, GsApp *app)
                gs_image_set_from_pixbuf (GTK_IMAGE (tile->image), pixbuf);
        gtk_label_set_label (GTK_LABEL (tile->name), gs_app_get_name (app));
 
-       /* set custom css */
-       css = gs_app_get_metadata_item (app, "GnomeSoftware::AppTile-css");
-       if (css != NULL)
-               gs_utils_widget_set_custom_css (GTK_WIDGET (tile), css);
+       /* perhaps set custom css */
+       gs_utils_widget_set_custom_css (app, GTK_WIDGET (tile),
+                                       "GnomeSoftware::AppTile-css");
 
        /* some kinds have boring summaries */
        switch (gs_app_get_kind (app)) {
diff --git a/src/gs-app.c b/src/gs-app.c
index c5fb4b5..96499b8 100644
--- a/src/gs-app.c
+++ b/src/gs-app.c
@@ -71,6 +71,7 @@ struct _GsApp
        GError                  *last_error;
        GPtrArray               *screenshots;
        GPtrArray               *categories;
+       GPtrArray               *key_colors;
        GPtrArray               *keywords;
        GHashTable              *urls;
        gchar                   *license;
@@ -339,6 +340,13 @@ gs_app_to_string (GsApp *app)
                tmp = g_ptr_array_index (app->categories, i);
                gs_app_kv_lpad (str, "category", tmp);
        }
+       for (i = 0; i < app->key_colors->len; i++) {
+               GdkRGBA *color = g_ptr_array_index (app->key_colors, i);
+               g_autofree gchar *key = NULL;
+               key = g_strdup_printf ("key-color-%02i", i);
+               gs_app_kv_printf (str, key, "%.0f,%.0f,%.0f",
+                                 color->red, color->green, color->blue);
+       }
        if (app->keywords != NULL) {
                for (i = 0; i < app->keywords->len; i++) {
                        tmp = g_ptr_array_index (app->keywords, i);
@@ -2096,6 +2104,40 @@ gs_app_add_category (GsApp *app, const gchar *category)
 }
 
 /**
+ * gs_app_get_key_colors:
+ */
+GPtrArray *
+gs_app_get_key_colors (GsApp *app)
+{
+       g_return_val_if_fail (GS_IS_APP (app), NULL);
+       return app->key_colors;
+}
+
+/**
+ * gs_app_set_key_colors:
+ */
+void
+gs_app_set_key_colors (GsApp *app, GPtrArray *key_colors)
+{
+       g_return_if_fail (GS_IS_APP (app));
+       g_return_if_fail (key_colors != NULL);
+       if (app->key_colors != NULL)
+               g_ptr_array_unref (app->key_colors);
+       app->key_colors = g_ptr_array_ref (key_colors);
+}
+
+/**
+ * gs_app_add_key_color:
+ */
+void
+gs_app_add_key_color (GsApp *app, GdkRGBA *key_color)
+{
+       g_return_if_fail (GS_IS_APP (app));
+       g_return_if_fail (key_color != NULL);
+       g_ptr_array_add (app->key_colors, gdk_rgba_copy (key_color));
+}
+
+/**
  * gs_app_get_keywords:
  */
 GPtrArray *
@@ -2436,6 +2478,7 @@ gs_app_finalize (GObject *object)
        g_hash_table_unref (app->addons_hash);
        g_hash_table_unref (app->related_hash);
        g_ptr_array_unref (app->categories);
+       g_ptr_array_unref (app->key_colors);
        if (app->keywords != NULL)
                g_ptr_array_unref (app->keywords);
        if (app->last_error != NULL)
@@ -2559,6 +2602,7 @@ gs_app_init (GsApp *app)
        app->sources = g_ptr_array_new_with_free_func (g_free);
        app->source_ids = g_ptr_array_new_with_free_func (g_free);
        app->categories = g_ptr_array_new_with_free_func (g_free);
+       app->key_colors = g_ptr_array_new_with_free_func ((GDestroyNotify) gdk_rgba_free);
        app->addons = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
        app->related = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
        app->history = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
diff --git a/src/gs-app.h b/src/gs-app.h
index 86e750c..0e476d7 100644
--- a/src/gs-app.h
+++ b/src/gs-app.h
@@ -23,6 +23,7 @@
 #define __GS_APP_H
 
 #include <glib-object.h>
+#include <gdk/gdk.h>
 #include <gdk-pixbuf/gdk-pixbuf.h>
 #include <appstream-glib.h>
 
@@ -226,6 +227,11 @@ void                gs_app_set_install_date        (GsApp          *app,
 GPtrArray      *gs_app_get_categories          (GsApp          *app);
 void            gs_app_set_categories          (GsApp          *app,
                                                 GPtrArray      *categories);
+GPtrArray      *gs_app_get_key_colors          (GsApp          *app);
+void            gs_app_set_key_colors          (GsApp          *app,
+                                                GPtrArray      *key_colors);
+void            gs_app_add_key_color           (GsApp          *app,
+                                                GdkRGBA        *key_color);
 gboolean        gs_app_has_category            (GsApp          *app,
                                                 const gchar    *category);
 void            gs_app_add_category            (GsApp          *app,
diff --git a/src/gs-cmd.c b/src/gs-cmd.c
index 760aaae..54905f5 100644
--- a/src/gs-cmd.c
+++ b/src/gs-cmd.c
@@ -145,6 +145,8 @@ gs_cmd_refine_flag_from_string (const gchar *flag, GError **error)
                return GS_PLUGIN_REFINE_FLAGS_REQUIRE_REVIEWS;
        if (g_strcmp0 (flag, "review-ratings") == 0)
                return GS_PLUGIN_REFINE_FLAGS_REQUIRE_REVIEW_RATINGS;
+       if (g_strcmp0 (flag, "key-colors") == 0)
+               return GS_PLUGIN_REFINE_FLAGS_REQUIRE_KEY_COLORS;
        g_set_error (error,
                     GS_PLUGIN_ERROR,
                     GS_PLUGIN_ERROR_NOT_SUPPORTED,
diff --git a/src/gs-feature-tile.c b/src/gs-feature-tile.c
index 214562d..77a122c 100644
--- a/src/gs-feature-tile.c
+++ b/src/gs-feature-tile.c
@@ -91,7 +91,6 @@ app_state_changed (GsApp *app, GParamSpec *pspec, GsFeatureTile *tile)
 void
 gs_feature_tile_set_app (GsFeatureTile *tile, GsApp *app)
 {
-       const gchar *css;
        g_autoptr(GString) data = NULL;
 
        g_return_if_fail (GS_IS_FEATURE_TILE (tile));
@@ -113,10 +112,9 @@ gs_feature_tile_set_app (GsFeatureTile *tile, GsApp *app)
        gtk_label_set_label (GTK_LABEL (tile->title), gs_app_get_name (app));
        gtk_label_set_label (GTK_LABEL (tile->subtitle), gs_app_get_summary (app));
 
-       /* set custom css */
-       css = gs_app_get_metadata_item (app, "GnomeSoftware::FeatureTile-css");
-       if (css != NULL)
-               gs_utils_widget_set_custom_css (GTK_WIDGET (tile), css);
+       /* perhaps set custom css */
+       gs_utils_widget_set_custom_css (app, GTK_WIDGET (tile),
+                                       "GnomeSoftware::FeatureTile-css");
 }
 
 static void
diff --git a/src/gs-plugin.h b/src/gs-plugin.h
index 177bc6a..e48a9af 100644
--- a/src/gs-plugin.h
+++ b/src/gs-plugin.h
@@ -103,6 +103,7 @@ typedef enum {
        GS_PLUGIN_REFINE_FLAGS_REQUIRE_PROVENANCE       = 1 << 17,
        GS_PLUGIN_REFINE_FLAGS_REQUIRE_REVIEWS          = 1 << 18,
        GS_PLUGIN_REFINE_FLAGS_REQUIRE_REVIEW_RATINGS   = 1 << 19,
+       GS_PLUGIN_REFINE_FLAGS_REQUIRE_KEY_COLORS       = 1 << 20,
        /*< private >*/
        GS_PLUGIN_REFINE_FLAGS_LAST
 } GsPluginRefineFlags;
diff --git a/src/gs-popular-tile.c b/src/gs-popular-tile.c
index 6ca6fb1..2fcdb24 100644
--- a/src/gs-popular-tile.c
+++ b/src/gs-popular-tile.c
@@ -103,8 +103,6 @@ app_state_changed (GsApp *app, GParamSpec *pspec, GsPopularTile *tile)
 void
 gs_popular_tile_set_app (GsPopularTile *tile, GsApp *app)
 {
-       const gchar *css;
-
        g_return_if_fail (GS_IS_POPULAR_TILE (tile));
        g_return_if_fail (GS_IS_APP (app) || app == NULL);
 
@@ -128,10 +126,9 @@ gs_popular_tile_set_app (GsPopularTile *tile, GsApp *app)
                          G_CALLBACK (app_state_changed), tile);
        app_state_changed (tile->app, NULL, tile);
 
-       /* set custom css */
-       css = gs_app_get_metadata_item (app, "GnomeSoftware::PopularTile-css");
-       if (css != NULL)
-               gs_utils_widget_set_custom_css (GTK_WIDGET (tile), css);
+       /* perhaps set custom css */
+       gs_utils_widget_set_custom_css (app, GTK_WIDGET (tile),
+                                       "GnomeSoftware::PopularTile-css");
 
        gs_image_set_from_pixbuf (GTK_IMAGE (tile->image), gs_app_get_pixbuf (tile->app));
 
diff --git a/src/gs-self-test.c b/src/gs-self-test.c
index 4c561e8..1388cb5 100644
--- a/src/gs-self-test.c
+++ b/src/gs-self-test.c
@@ -245,6 +245,24 @@ gs_plugin_loader_refine_func (GsPluginLoader *plugin_loader)
 }
 
 static void
+gs_plugin_loader_key_colors_func (GsPluginLoader *plugin_loader)
+{
+       gboolean ret;
+       g_autoptr(GsApp) app = NULL;
+       g_autoptr(GError) error = NULL;
+
+       /* get the extra bits */
+       app = gs_app_new ("zeus.desktop");
+       ret = gs_plugin_loader_app_refine (plugin_loader, app,
+                                          GS_PLUGIN_REFINE_FLAGS_REQUIRE_KEY_COLORS,
+                                          NULL,
+                                          &error);
+       g_assert_no_error (error);
+       g_assert (ret);
+       g_assert_cmpint (gs_app_get_key_colors(app)->len, >=, 3);
+}
+
+static void
 gs_plugin_loader_updates_func (GsPluginLoader *plugin_loader)
 {
        GsApp *app;
@@ -516,6 +534,7 @@ main (int argc, char **argv)
                "hardcoded-blacklist",
                "icons",
                "menu-spec-refine",
+               "key-colors",
                "provenance",
                "packagekit-local",
                NULL
@@ -602,6 +621,9 @@ main (int argc, char **argv)
        g_assert (gs_plugin_loader_get_enabled (plugin_loader, "dummy"));
 
        /* plugin tests go here */
+       g_test_add_data_func ("/gnome-software/plugin-loader{key-colors}",
+                             plugin_loader,
+                             (GTestDataFunc) gs_plugin_loader_key_colors_func);
        g_test_add_data_func ("/gnome-software/plugin-loader{packagekit-local}",
                              plugin_loader,
                              (GTestDataFunc) gs_plugin_loader_packagekit_local_func);
diff --git a/src/gs-upgrade-banner.c b/src/gs-upgrade-banner.c
index 6ab29dd..5772352 100644
--- a/src/gs-upgrade-banner.c
+++ b/src/gs-upgrade-banner.c
@@ -208,7 +208,6 @@ void
 gs_upgrade_banner_set_app (GsUpgradeBanner *self, GsApp *app)
 {
        GsUpgradeBannerPrivate *priv = gs_upgrade_banner_get_instance_private (self);
-       const gchar *css;
 
        g_return_if_fail (GS_IS_UPGRADE_BANNER (self));
        g_return_if_fail (GS_IS_APP (app) || app == NULL);
@@ -227,10 +226,9 @@ gs_upgrade_banner_set_app (GsUpgradeBanner *self, GsApp *app)
        g_signal_connect (priv->app, "notify::progress",
                          G_CALLBACK (app_progress_changed), self);
 
-       /* set custom css */
-       css = gs_app_get_metadata_item (app, "GnomeSoftware::UpgradeBanner-css");
-       if (css != NULL)
-               gs_utils_widget_set_custom_css (priv->box_upgrades, css);
+       /* perhaps set custom css */
+       gs_utils_widget_set_custom_css (app, priv->box_upgrades,
+                                       "GnomeSoftware::UpgradeBanner-css");
 
        gs_upgrade_banner_refresh (self);
 }
diff --git a/src/gs-utils.c b/src/gs-utils.c
index 603c0f6..730afab 100644
--- a/src/gs-utils.c
+++ b/src/gs-utils.c
@@ -830,21 +830,43 @@ gs_utils_widget_css_parsing_error_cb (GtkCssProvider *provider,
  * gs_utils_widget_set_custom_css:
  **/
 void
-gs_utils_widget_set_custom_css (GtkWidget *widget, const gchar *css)
+gs_utils_widget_set_custom_css (GsApp *app, GtkWidget *widget, const gchar *metadata_css)
 {
+       GPtrArray *key_colors;
        GString *str = g_string_sized_new (1024);
+       GString *css_str = g_string_new ("");
        GtkStyleContext *context;
+       const gchar *css;
+       guint i;
        g_autofree gchar *class_name = NULL;
        g_autoptr(GtkCssProvider) provider = NULL;
 
+       g_return_if_fail (GS_IS_APP (app));
+
        /* invalid */
+       css = gs_app_get_metadata_item (app, metadata_css);
        if (css == NULL)
                return;
 
+       /* replace any key colors */
+       css_str = g_string_new (css);
+       key_colors = gs_app_get_key_colors (app);
+       for (i = 0; i < key_colors->len; i++) {
+               GdkRGBA *color = g_ptr_array_index (key_colors, 1);
+               g_autofree gchar *key = NULL;
+               g_autofree gchar *value = NULL;
+               key = g_strdup_printf ("@keycolor-%02i@", i);
+               value = g_strdup_printf ("rgb(%.0f,%.0f,%.0f)",
+                                        color->red,
+                                        color->green,
+                                        color->blue);
+               as_utils_string_replace (css_str, key, value);
+       }
+
        /* make into a proper CSS class */
        class_name = g_strdup_printf ("themed-widget_%p", widget);
        g_string_append_printf (str, ".%s {\n", class_name);
-       g_string_append_printf (str, "%s\n", css);
+       g_string_append_printf (str, "%s\n", css_str->str);
        g_string_append (str, "}");
 
        g_string_append_printf (str, ".%s:hover {\n", class_name);
diff --git a/src/gs-utils.h b/src/gs-utils.h
index 84745bf..e407bd0 100644
--- a/src/gs-utils.h
+++ b/src/gs-utils.h
@@ -69,8 +69,9 @@ const gchar   *gs_utils_get_content_rating    (void);
 #endif
 
 gboolean        gs_utils_is_current_desktop    (const gchar    *name);
-void            gs_utils_widget_set_custom_css (GtkWidget      *widget,
-                                                const gchar    *css);
+void            gs_utils_widget_set_custom_css (GsApp          *app,
+                                                GtkWidget      *widget,
+                                                const gchar    *metadata_css);
 
 G_END_DECLS
 
diff --git a/src/plugins/Makefile.am b/src/plugins/Makefile.am
index efb10b1..ea8d975 100644
--- a/src/plugins/Makefile.am
+++ b/src/plugins/Makefile.am
@@ -28,6 +28,7 @@ AM_CPPFLAGS =                                         \
 plugindir = $(libdir)/gs-plugins-${GS_PLUGIN_API_VERSION}
 plugin_LTLIBRARIES =                                   \
        libgs_plugin_appstream.la                       \
+       libgs_plugin_key-colors.la                      \
        libgs_plugin_dummy.la                           \
        libgs_plugin_dpkg.la                            \
        libgs_plugin_hardcoded-blacklist.la             \
@@ -99,6 +100,11 @@ libgs_plugin_dpkg_la_LIBADD = $(GS_PLUGIN_LIBS)
 libgs_plugin_dpkg_la_LDFLAGS = -module -avoid-version
 libgs_plugin_dpkg_la_CFLAGS = $(GS_PLUGIN_CFLAGS) $(WARN_CFLAGS)
 
+libgs_plugin_key_colors_la_SOURCES = gs-plugin-key-colors.c
+libgs_plugin_key_colors_la_LIBADD = $(GS_PLUGIN_LIBS)
+libgs_plugin_key_colors_la_LDFLAGS = -module -avoid-version
+libgs_plugin_key_colors_la_CFLAGS = $(GS_PLUGIN_CFLAGS) $(WARN_CFLAGS)
+
 if HAVE_SHELL_EXTENSIONS
 libgs_plugin_shell_extensions_la_SOURCES = gs-plugin-shell-extensions.c
 libgs_plugin_shell_extensions_la_LIBADD = $(GS_PLUGIN_LIBS) $(JSON_GLIB_LIBS)
diff --git a/src/plugins/gs-plugin-key-colors.c b/src/plugins/gs-plugin-key-colors.c
new file mode 100644
index 0000000..30f918c
--- /dev/null
+++ b/src/plugins/gs-plugin-key-colors.c
@@ -0,0 +1,195 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2016 Richard Hughes <richard hughsie com>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <config.h>
+
+#include <gs-plugin.h>
+
+/**
+ * gs_plugin_order_after:
+ */
+const gchar **
+gs_plugin_order_after (GsPlugin *plugin)
+{
+       static const gchar *deps[] = {
+               "icons",        /* need icon */
+               NULL };
+       return deps;
+}
+
+typedef struct {
+       guint8           R;
+       guint8           G;
+       guint8           B;
+} CdColorRGB8;
+
+/**
+ * cd_color_rgb8_to_uint32:
+ */
+static guint32
+cd_color_rgb8_to_uint32 (CdColorRGB8 *rgb)
+{
+       return (guint32) rgb->R |
+               (guint32) rgb->G << 8 |
+               (guint32) rgb->B << 16;
+}
+
+typedef struct {
+       GdkRGBA         color;
+       guint           cnt;
+} GsColorBin;
+
+/**
+ * gs_color_bin_sort_cb:
+ */
+static gint
+gs_color_bin_sort_cb (gconstpointer a, gconstpointer b)
+{
+       GsColorBin *s1 = (GsColorBin *) a;
+       GsColorBin *s2 = (GsColorBin *) b;
+       if (s1->cnt < s2->cnt)
+               return 1;
+       if (s1->cnt > s2->cnt)
+               return -1;
+       return 0;
+}
+
+/**
+ * gs_plugin_key_colors_set_for_pixbuf:
+ */
+static void
+gs_plugin_key_colors_set_for_pixbuf (GsApp *app, GdkPixbuf *pb, guint number)
+{
+       GList *l;
+       gint rowstride, n_channels;
+       gint x, y;
+       guchar *pixels, *p;
+       guint bin_size = 200;
+       guint i;
+       guint number_of_bins;
+       g_autoptr(AsImage) im = NULL;
+
+       /* go through each pixel */
+       n_channels = gdk_pixbuf_get_n_channels (pb);
+       rowstride = gdk_pixbuf_get_rowstride (pb);
+       pixels = gdk_pixbuf_get_pixels (pb);
+       for (bin_size = 250; bin_size > 0; bin_size -= 2) {
+               g_autoptr(GHashTable) hash = NULL;
+               hash = g_hash_table_new_full (g_direct_hash,  g_direct_equal,
+                                             NULL, g_free);
+               for (y = 0; y < gdk_pixbuf_get_height (pb); y++) {
+                       for (x = 0; x < gdk_pixbuf_get_width (pb); x++) {
+                               CdColorRGB8 tmp;
+                               GsColorBin *s;
+                               gpointer key;
+
+                               /* disregard any with alpha */
+                               p = pixels + y * rowstride + x * n_channels;
+                               if (p[3] != 255)
+                                       continue;
+
+                               /* find in cache */
+                               tmp.R = p[0] / bin_size;
+                               tmp.G = p[1] / bin_size;
+                               tmp.B = p[2] / bin_size;
+                               key = GUINT_TO_POINTER (cd_color_rgb8_to_uint32 (&tmp));
+                               s = g_hash_table_lookup (hash, key);
+                               if (s != NULL) {
+                                       s->color.red += p[0];
+                                       s->color.green += p[1];
+                                       s->color.blue += p[2];
+                                       s->cnt++;
+                                       continue;
+                               }
+
+                               /* add to hash table */
+                               s = g_new0 (GsColorBin, 1);
+                               s->color.red = p[0];
+                               s->color.green = p[1];
+                               s->color.blue = p[2];
+                               s->color.alpha = 1.0;
+                               s->cnt = 1;
+                               g_hash_table_insert (hash, key, s);
+                       }
+               }
+
+               number_of_bins = g_hash_table_size (hash);
+//             g_debug ("number of colors: %i", number_of_bins);
+               if (number_of_bins >= number) {
+                       g_autoptr(GList) values = NULL;
+
+                       /* order by most popular */
+                       values = g_hash_table_get_values (hash);
+                       values = g_list_sort (values, gs_color_bin_sort_cb);
+                       for (l = values; l != NULL; l = l->next) {
+                               GsColorBin *s = l->data;
+                               g_autofree GdkRGBA *color = g_new0 (GdkRGBA, 1);
+                               color->red = s->color.red / s->cnt;
+                               color->green = s->color.green / s->cnt;
+                               color->blue = s->color.blue / s->cnt;
+                               gs_app_add_key_color (app, color);
+                       }
+                       return;
+               }
+       }
+
+       /* the algorithm failed, so just return a monochrome ramp */
+       for (i = 0; i < 3; i++) {
+               g_autofree GdkRGBA *color = g_new0 (GdkRGBA, 1);
+               color->red = 255 * i / 3;
+               color->green = color->red;
+               color->blue = color->red;
+               color->alpha = 1.0f;
+               gs_app_add_key_color (app, color);
+       }
+}
+
+/**
+ * gs_plugin_refine_app:
+ */
+gboolean
+gs_plugin_refine_app (GsPlugin *plugin,
+                     GsApp *app,
+                     GsPluginRefineFlags flags,
+                     GCancellable *cancellable,
+                     GError **error)
+{
+       GdkPixbuf *pb;
+       g_autoptr(GdkPixbuf) pb_small = NULL;
+
+       /* add a rating */
+       if ((flags & GS_PLUGIN_REFINE_FLAGS_REQUIRE_KEY_COLORS) == 0)
+               return TRUE;
+
+       /* already set */
+       if (gs_app_get_key_colors(app)->len > 0)
+               return TRUE;
+
+       /* no pixbuf */
+       pb = gs_app_get_pixbuf (app);
+       if (pb == NULL)
+               return TRUE;
+
+       /* get a list of key colors */
+       pb_small = gdk_pixbuf_scale_simple (pb, 32, 32, GDK_INTERP_BILINEAR);
+       gs_plugin_key_colors_set_for_pixbuf (app, pb_small, 10);
+       return TRUE;
+}


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