[gnome-software] Allow specifying the optional text-shadow for the featured applications



commit 363bdb57ea3df3360353d3d9f6ef92183088e64b
Author: Richard Hughes <richard hughsie com>
Date:   Tue Feb 4 10:25:28 2014 +0000

    Allow specifying the optional text-shadow for the featured applications

 src/gs-feature-tile.c                      |   74 +++++++++++++++------------
 src/plugins/gs-plugin-hardcoded-featured.c |   27 ++++++----
 2 files changed, 58 insertions(+), 43 deletions(-)
---
diff --git a/src/gs-feature-tile.c b/src/gs-feature-tile.c
index 38a723a..e7394b1 100644
--- a/src/gs-feature-tile.c
+++ b/src/gs-feature-tile.c
@@ -97,8 +97,12 @@ void
 gs_feature_tile_set_app (GsFeatureTile *tile, GsApp *app)
 {
        GsFeatureTilePrivate *priv;
-       const gchar *tmp;
-       gchar *data;
+       GString *data = NULL;
+       const gchar *background;
+       const gchar *stroke_color;
+       const gchar *text_color;
+       const gchar *text_shadow;
+       gchar *tmp;
 
        g_return_if_fail (GS_IS_FEATURE_TILE (tile));
        g_return_if_fail (GS_IS_APP (app) || app == NULL);
@@ -121,41 +125,45 @@ gs_feature_tile_set_app (GsFeatureTile *tile, GsApp *app)
        gtk_label_set_label (GTK_LABEL (priv->subtitle), gs_app_get_summary (app));
 
        /* check the app has the featured data */
-       tmp = gs_app_get_metadata_item (app, "Featured::text-color");
-       if (tmp == NULL) {
-               data = gs_app_to_string (app);
+       text_color = gs_app_get_metadata_item (app, "Featured::text-color");
+       if (text_color == NULL) {
+               tmp = gs_app_to_string (app);
                g_warning ("%s has no featured data: %s",
-                          gs_app_get_id (app), data);
+                          gs_app_get_id (app), tmp);
+               g_free (tmp);
                goto out;
        }
-
-       data = g_strdup_printf (
-               ".button.featured-tile {\n"
-               "  padding: 0;\n"
-               "  border-radius: 0;\n"
-               "  border-width: 1px;\n"
-               "  border-image: none;\n"
-               "  border-color: %s;\n"
-               "  color: %s;\n"
-               "  -GtkWidget-focus-padding: 0;\n"
-               "  outline-color: alpha(%s, 0.75);\n"
-               "  outline-style: dashed;\n"
-               "  outline-offset: 2px;\n"
-               "  background: %s;\n"
-               "}\n"
-               ".button.featured-tile:hover {\n"
-               "  background: linear-gradient(to bottom,\n"
-                "                              alpha(#fff,0.16),\n"
-               "                              alpha(#aaa,0.16)), %s;\n"
-               "}\n",
-               gs_app_get_metadata_item (app, "Featured::stroke-color"),
-               gs_app_get_metadata_item (app, "Featured::text-color"),
-               gs_app_get_metadata_item (app, "Featured::text-color"),
-               gs_app_get_metadata_item (app, "Featured::background"),
-               gs_app_get_metadata_item (app, "Featured::background"));
-       gtk_css_provider_load_from_data (priv->provider, data, -1, NULL);
+       background = gs_app_get_metadata_item (app, "Featured::background");
+       stroke_color = gs_app_get_metadata_item (app, "Featured::stroke-color");
+       text_shadow = gs_app_get_metadata_item (app, "Featured::text-shadow");
+
+       data = g_string_sized_new (1024);
+       g_string_append (data, ".button.featured-tile {\n");
+       g_string_append (data, "  padding: 0;\n");
+       g_string_append (data, "  border-radius: 0;\n");
+       g_string_append (data, "  border-width: 1px;\n");
+       g_string_append (data, "  border-image: none;\n");
+       g_string_append_printf (data, "  border-color: %s;\n", stroke_color);
+       if (text_shadow != NULL)
+               g_string_append_printf (data, "  text-shadow: %s;\n", text_shadow);
+       g_string_append_printf (data, "  color: %s;\n", text_color);
+       g_string_append (data, "  -GtkWidget-focus-padding: 0;\n");
+       g_string_append_printf (data, "  outline-color: alpha(%s, 0.75);\n", text_color);
+       g_string_append (data, "  outline-style: dashed;\n");
+       g_string_append (data, "  outline-offset: 2px;\n");
+       g_string_append_printf (data, "  background: %s;\n", background);
+       g_string_append (data, "}\n");
+       g_string_append (data, ".button.featured-tile:hover {\n");
+       g_string_append (data, "  background: linear-gradient(to bottom,\n");
+       g_string_append (data, "                              alpha(#fff,0.16),\n");
+       g_string_append_printf (data,
+                               "                              alpha(#aaa,0.16)), %s;\n",
+                               background);
+       g_string_append (data, "}\n");
+       gtk_css_provider_load_from_data (priv->provider, data->str, -1, NULL);
 out:
-       g_free (data);
+       if (data != NULL)
+               g_string_free (data, TRUE);
 }
 
 static void
diff --git a/src/plugins/gs-plugin-hardcoded-featured.c b/src/plugins/gs-plugin-hardcoded-featured.c
index b9b938b..bbf6cbc 100644
--- a/src/plugins/gs-plugin-hardcoded-featured.c
+++ b/src/plugins/gs-plugin-hardcoded-featured.c
@@ -44,37 +44,44 @@ gs_plugin_add_featured_app (GList **list,
        GsApp *app = NULL;
        gboolean ret = TRUE;
        gchar *background = NULL;
-       gchar *stroke = NULL;
-       gchar *text = NULL;
+       gchar *stroke_color = NULL;
+       gchar *text_color = NULL;
+       gchar *text_shadow = NULL;
 
        background = g_key_file_get_string (kf, id, "background", error);
        if (background == NULL) {
                ret = FALSE;
                goto out;
        }
-       stroke = g_key_file_get_string (kf, id, "stroke", error);
-       if (stroke == NULL) {
+       stroke_color = g_key_file_get_string (kf, id, "stroke", error);
+       if (stroke_color == NULL) {
                ret = FALSE;
                goto out;
        }
-       text = g_key_file_get_string (kf, id, "text", error);
-       if (text == NULL) {
+       text_color = g_key_file_get_string (kf, id, "text", error);
+       if (text_color == NULL) {
                ret = FALSE;
                goto out;
        }
 
+       /* optional */
+       text_shadow = g_key_file_get_string (kf, id, "text-shadow", NULL);
+
        /* add app */
        app = gs_app_new (id);
        gs_app_set_metadata (app, "Featured::background", background);
-       gs_app_set_metadata (app, "Featured::stroke-color", stroke);
-       gs_app_set_metadata (app, "Featured::text-color", text);
+       gs_app_set_metadata (app, "Featured::stroke-color", stroke_color);
+       gs_app_set_metadata (app, "Featured::text-color", text_color);
+       if (text_shadow != NULL)
+               gs_app_set_metadata (app, "Featured::text-shadow", text_shadow);
        gs_plugin_add_app (list, app);
 out:
        if (app != NULL)
                g_object_unref (app);
        g_free (background);
-       g_free (stroke);
-       g_free (text);
+       g_free (stroke_color);
+       g_free (text_color);
+       g_free (text_shadow);
        return ret;
 }
 


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