[gnome-control-center/wip/fmuellner/symbolic-search-icons: 3/3] model: Convert panel icons to symbolic variants if possible



commit d5de9d86c9f2608179c87fa95e6f8e0e326c6f7a
Author: Florian Müllner <fmuellner gnome org>
Date:   Tue Jul 24 17:13:42 2018 +0200

    model: Convert panel icons to symbolic variants if possible
    
    Panel icons should be consistent between the app and corresponding
    search results in GNOME Shell, but currently the former uses the
    symbolic variant while the latter uses the colored version.
    
    Address this by converting icons to their symbolic variants when
    building the model rather than later when consuming them.
    
    https://gitlab.gnome.org/GNOME/gnome-control-center/merge_requests/151

 shell/cc-shell-model.c | 21 ++++++++++++++++++++-
 shell/cc-window.c      | 30 +++---------------------------
 2 files changed, 23 insertions(+), 28 deletions(-)
---
diff --git a/shell/cc-shell-model.c b/shell/cc-shell-model.c
index 2e209a7d0..a84de3ee2 100644
--- a/shell/cc-shell-model.c
+++ b/shell/cc-shell-model.c
@@ -292,13 +292,31 @@ get_casefolded_keywords (GAppInfo *appinfo)
   return casefolded_keywords;
 }
 
+static GIcon *
+symbolicize_g_icon (GIcon *gicon)
+{
+  const gchar * const *names;
+  g_autofree gchar *new_name = NULL;
+
+  if (!G_IS_THEMED_ICON (gicon))
+    return g_object_ref (gicon);
+
+  names = g_themed_icon_get_names (G_THEMED_ICON (gicon));
+
+  if (g_str_has_suffix (names[0], "-symbolic"))
+    return g_object_ref (gicon);
+
+  new_name = g_strdup_printf ("%s-symbolic", names[0]);
+  return g_themed_icon_new_with_default_fallbacks (new_name);
+}
+
 void
 cc_shell_model_add_item (CcShellModel    *model,
                          CcPanelCategory  category,
                          GAppInfo        *appinfo,
                          const char      *id)
 {
-  GIcon       *icon = g_app_info_get_icon (appinfo);
+  g_autoptr(GIcon) icon = NULL;
   const gchar *name = g_app_info_get_name (appinfo);
   const gchar *comment = g_app_info_get_description (appinfo);
   char **keywords;
@@ -307,6 +325,7 @@ cc_shell_model_add_item (CcShellModel    *model,
   casefolded_name = cc_util_normalize_casefold_and_unaccent (name);
   casefolded_description = cc_util_normalize_casefold_and_unaccent (comment);
   keywords = get_casefolded_keywords (appinfo);
+  icon = symbolicize_g_icon (g_app_info_get_icon (appinfo));
 
   gtk_list_store_insert_with_values (GTK_LIST_STORE (model), NULL, 0,
                                      COL_NAME, name,
diff --git a/shell/cc-window.c b/shell/cc-window.c
index e83076dca..9e6f49b85 100644
--- a/shell/cc-window.c
+++ b/shell/cc-window.c
@@ -134,31 +134,6 @@ add_development_build_css (CcWindow *self)
                                              GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
 }
 
-static gchar *
-get_symbolic_icon_name_from_g_icon (GIcon *gicon)
-{
-  const gchar * const *names;
-  GtkIconTheme *icon_theme;
-  int i;
-
-  if (!G_IS_THEMED_ICON (gicon))
-    return NULL;
-
-  names = g_themed_icon_get_names (G_THEMED_ICON (gicon));
-  icon_theme = gtk_icon_theme_get_default ();
-
-  for (i = 0; names[i] != NULL; i++)
-    {
-      g_autofree gchar *name = NULL;
-      name = g_strdup_printf ("%s-symbolic", names[i]);
-
-      if (gtk_icon_theme_has_icon (icon_theme, name))
-        return g_steal_pointer (&name);
-    }
-
-  return NULL;
-}
-
 static void
 remove_all_custom_widgets (CcWindow *self)
 {
@@ -326,9 +301,9 @@ setup_model (CcWindow *shell)
       g_autofree gchar *name = NULL;
       g_autofree gchar *description = NULL;
       g_autofree gchar *id = NULL;
-      g_autofree gchar *icon_name = NULL;
       g_autofree GStrv keywords = NULL;
       CcPanelVisibility visibility;
+      const gchar *icon_name = NULL;
 
       gtk_tree_model_get (model, &iter,
                           COL_CATEGORY, &category,
@@ -340,7 +315,8 @@ setup_model (CcWindow *shell)
                           COL_VISIBILITY, &visibility,
                           -1);
 
-      icon_name = get_symbolic_icon_name_from_g_icon (icon);
+      if (G_IS_THEMED_ICON (icon))
+        icon_name = g_themed_icon_get_names (G_THEMED_ICON (icon))[0];
 
       cc_panel_list_add_panel (CC_PANEL_LIST (shell->panel_list),
                                category,


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