[gimp] app: allow GUI config property for icon style preference.



commit 8cfe2df866ef439e3d06a0724b392179364faf42
Author: Jehan <jehan girinstud io>
Date:   Fri Jun 8 03:29:47 2018 +0200

    app: allow GUI config property for icon style preference.
    
    A single icon theme can contain both regular and symbolic icons. Let's
    give possibility to switch from one style to the other within GIMP
    Preferences.
    
    This won't work very well in all cases yet, especially if an icon theme
    only has symbolic icons (and no regular ones) because of inconsistencies
    in glib which are being fixed (patches which I submitted and which were
    merged in glib on 2018-08-17).
    So this will work as expected when we will bump our glib requirement to
    whatever is the next release.

 app/config/gimpguiconfig.c       | 14 ++++++++++++++
 app/config/gimpguiconfig.h       |  1 +
 app/config/gimprc-blurbs.h       |  4 ++--
 app/dialogs/preferences-dialog.c |  4 ++++
 app/gui/themes.c                 | 32 +++++++++++++++++++++++++++++---
 5 files changed, 50 insertions(+), 5 deletions(-)
---
diff --git a/app/config/gimpguiconfig.c b/app/config/gimpguiconfig.c
index f7319145fe..57c5bc11f7 100644
--- a/app/config/gimpguiconfig.c
+++ b/app/config/gimpguiconfig.c
@@ -71,6 +71,7 @@ enum
   PROP_PREFER_DARK_THEME,
   PROP_ICON_THEME_PATH,
   PROP_ICON_THEME,
+  PROP_PREFER_SYMBOLIC_ICONS,
   PROP_USE_HELP,
   PROP_SHOW_HELP_BUTTON,
   PROP_HELP_LOCALES,
@@ -309,6 +310,13 @@ gimp_gui_config_class_init (GimpGuiConfigClass *klass)
                            GIMP_CONFIG_DEFAULT_ICON_THEME,
                            GIMP_PARAM_STATIC_STRINGS);
 
+  GIMP_CONFIG_PROP_BOOLEAN (object_class, PROP_PREFER_SYMBOLIC_ICONS,
+                            "prefer-symbolic-icons",
+                            "Prefer symbolic icons",
+                            PREFER_SYMBOLIC_ICONS_BLURB,
+                            TRUE,
+                            GIMP_PARAM_STATIC_STRINGS);
+
   GIMP_CONFIG_PROP_BOOLEAN (object_class, PROP_USE_HELP,
                             "use-help",
                             "Use help",
@@ -612,6 +620,9 @@ gimp_gui_config_set_property (GObject      *object,
       g_free (gui_config->icon_theme);
       gui_config->icon_theme = g_value_dup_string (value);
       break;
+    case PROP_PREFER_SYMBOLIC_ICONS:
+      gui_config->prefer_symbolic_icons = g_value_get_boolean (value);
+      break;
     case PROP_USE_HELP:
       gui_config->use_help = g_value_get_boolean (value);
       break;
@@ -768,6 +779,9 @@ gimp_gui_config_get_property (GObject    *object,
     case PROP_ICON_THEME:
       g_value_set_string (value, gui_config->icon_theme);
       break;
+    case PROP_PREFER_SYMBOLIC_ICONS:
+      g_value_set_boolean (value, gui_config->prefer_symbolic_icons);
+      break;
     case PROP_USE_HELP:
       g_value_set_boolean (value, gui_config->use_help);
       break;
diff --git a/app/config/gimpguiconfig.h b/app/config/gimpguiconfig.h
index 97edead829..d3e94de0ee 100644
--- a/app/config/gimpguiconfig.h
+++ b/app/config/gimpguiconfig.h
@@ -66,6 +66,7 @@ struct _GimpGuiConfig
   gboolean             prefer_dark_theme;
   gchar               *icon_theme_path;
   gchar               *icon_theme;
+  gboolean             prefer_symbolic_icons;
   gboolean             use_help;
   gboolean             show_help_button;
   gchar               *help_locales;
diff --git a/app/config/gimprc-blurbs.h b/app/config/gimprc-blurbs.h
index 05eb4f6888..0e100f6cb1 100644
--- a/app/config/gimprc-blurbs.h
+++ b/app/config/gimprc-blurbs.h
@@ -470,8 +470,8 @@ _("Sets the folder for temporary storage. Files will appear here " \
 #define ICON_THEME_BLURB \
 "The name of the icon theme to use."
 
-#define ICON_SIZE_BLURB \
-"The size of the icons to use."
+#define PREFER_SYMBOLIC_ICONS_BLURB \
+"When enabled, symbolic icons will be prefered if available."
 
 #define ICON_THEME_PATH_BLURB \
 "Sets the icon theme search path."
diff --git a/app/dialogs/preferences-dialog.c b/app/dialogs/preferences-dialog.c
index d0e5a8546d..f5928a10f2 100644
--- a/app/dialogs/preferences-dialog.c
+++ b/app/dialogs/preferences-dialog.c
@@ -2028,6 +2028,10 @@ prefs_dialog_new (Gimp       *gimp,
     g_signal_connect (sel, "changed",
                       G_CALLBACK (prefs_icon_theme_select_callback),
                       gimp);
+
+    prefs_check_button_add (object, "prefer-symbolic-icons",
+                            _("Use symbolic icons if available"),
+                            GTK_BOX (vbox2));
   }
 
   /*************************/
diff --git a/app/gui/themes.c b/app/gui/themes.c
index 8c2ec44e26..73fb832d36 100644
--- a/app/gui/themes.c
+++ b/app/gui/themes.c
@@ -93,6 +93,9 @@ themes_init (Gimp *gimp)
   g_signal_connect (config, "notify::prefer-dark-theme",
                     G_CALLBACK (themes_theme_change_notify),
                     gimp);
+  g_signal_connect (config, "notify::prefer-symbolic-icons",
+                    G_CALLBACK (themes_theme_change_notify),
+                    gimp);
 
   themes_theme_change_notify (config, NULL, gimp);
 }
@@ -327,7 +330,9 @@ themes_theme_change_notify (GimpGuiConfig *config,
 {
   GFile    *theme_css;
   GError   *error = NULL;
+  gchar    *css;
   gboolean  prefer_dark_theme;
+  gboolean  prefer_symbolic_icons;
 
   g_object_get (config, "prefer-dark-theme", &prefer_dark_theme, NULL);
   g_object_set (gtk_settings_get_for_screen (gdk_screen_get_default ()),
@@ -342,10 +347,31 @@ themes_theme_change_notify (GimpGuiConfig *config,
     g_print ("Parsing '%s'\n",
              gimp_file_get_utf8_name (theme_css));
 
-  if (! gtk_css_provider_load_from_file (GTK_CSS_PROVIDER (themes_style_provider),
-                                         theme_css, &error))
+  g_object_get (config, "prefer-symbolic-icons", &prefer_symbolic_icons, NULL);
+  if (g_file_load_contents (theme_css, NULL, &css, NULL, NULL, &error))
+    {
+      gchar *css2;
+
+      if (prefer_symbolic_icons)
+        css2 = g_strdup_printf ("%s\n%s", css,
+                                "* { -gtk-icon-style: symbolic; } ");
+      else
+        css2 = g_strdup_printf ("%s\n%s", css,
+                                "* { -gtk-icon-style: regular; } ");
+      if (! gtk_css_provider_load_from_data (GTK_CSS_PROVIDER (themes_style_provider),
+                                             css2, -1, &error))
+        {
+          g_printerr ("%s: error parsing %s: %s\n", G_STRFUNC,
+                      gimp_file_get_utf8_name (theme_css), error->message);
+          g_clear_error (&error);
+        }
+
+      g_free (css2);
+      g_free (css);
+    }
+  else
     {
-      g_printerr ("%s: error parsing %s: %s\n", G_STRFUNC,
+      g_printerr ("%s: error loading %s: %s\n", G_STRFUNC,
                   gimp_file_get_utf8_name (theme_css), error->message);
       g_clear_error (&error);
     }


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