[gtk/theme-redux] inspector: Use theme apis



commit e265d8fa73d1f6aa820fbde35998dfcdf83a6a36
Author: Matthias Clasen <mclasen redhat com>
Date:   Sun Apr 12 00:29:05 2020 -0400

    inspector: Use theme apis
    
    We can now use gtk_theme_get_available_themes instead
    of our own copy of that code.

 gtk/inspector/visual.c  | 80 +++++--------------------------------------------
 gtk/inspector/visual.ui |  1 -
 2 files changed, 7 insertions(+), 74 deletions(-)
---
diff --git a/gtk/inspector/visual.c b/gtk/inspector/visual.c
index debcc768bd..2389a6e7b6 100644
--- a/gtk/inspector/visual.c
+++ b/gtk/inspector/visual.c
@@ -42,6 +42,7 @@
 #include "gskrendererprivate.h"
 #include "gtknative.h"
 #include "gtkbinlayout.h"
+#include "gtktheme.h"
 
 #include "fallback-c89.c"
 
@@ -473,30 +474,6 @@ focus_activate (GtkSwitch          *sw,
   redraw_everything ();
 }
 
-static void
-fill_gtk (const gchar *path,
-          GHashTable  *t)
-{
-  const gchar *dir_entry;
-  GDir *dir = g_dir_open (path, 0, NULL);
-
-  if (!dir)
-    return;
-
-  while ((dir_entry = g_dir_read_name (dir)))
-    {
-      gchar *filename = g_build_filename (path, dir_entry, "gtk-4.0", "gtk.css", NULL);
-
-      if (g_file_test (filename, G_FILE_TEST_IS_REGULAR) &&
-          !g_hash_table_contains (t, dir_entry))
-        g_hash_table_add (t, g_strdup (dir_entry));
-
-      g_free (filename);
-    }
-
-  g_dir_close (dir);
-}
-
 static gchar*
 get_data_path (const gchar *subdir)
 {
@@ -514,57 +491,14 @@ get_data_path (const gchar *subdir)
 static void
 init_theme (GtkInspectorVisual *vis)
 {
-  GHashTable *t;
-  GHashTableIter iter;
-  gchar *theme, *path;
-  gchar **builtin_themes;
-  GList *list, *l;
-  guint i;
-  const gchar * const *dirs;
+  char **themes;
+  int i;
 
-  t = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
-  /* Builtin themes */
-  builtin_themes = g_resources_enumerate_children ("/org/gtk/libgtk/theme", 0, NULL);
-  for (i = 0; builtin_themes[i] != NULL; i++)
-    {
-      if (g_str_has_suffix (builtin_themes[i], "/"))
-        g_hash_table_add (t, g_strndup (builtin_themes[i], strlen (builtin_themes[i]) - 1));
-    }
-  g_strfreev (builtin_themes);
-
-  path = _gtk_get_theme_dir ();
-  fill_gtk (path, t);
-  g_free (path);
-
-  path = g_build_filename (g_get_user_data_dir (), "themes", NULL);
-  fill_gtk (path, t);
-  g_free (path);
-
-  path = g_build_filename (g_get_home_dir (), ".themes", NULL);
-  fill_gtk (path, t);
-  g_free (path);
-
-  dirs = g_get_system_data_dirs ();
-  for (i = 0; dirs[i]; i++)
-    {
-      path = g_build_filename (dirs[i], "themes", NULL);
-      fill_gtk (path, t);
-      g_free (path);
-    }
+  themes = gtk_theme_get_available_themes ();
+  for (i = 0; themes[i]; i++)
+    gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (vis->priv->theme_combo), themes[i], themes[i]);
 
-  list = NULL;
-  g_hash_table_iter_init (&iter, t);
-  while (g_hash_table_iter_next (&iter, (gpointer *)&theme, NULL))
-    list = g_list_insert_sorted (list, theme, (GCompareFunc)strcmp);
-
-  for (l = list; l; l = l->next)
-    {
-      theme = l->data;
-      gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (vis->priv->theme_combo), theme, theme);
-    }
-
-  g_list_free (list);
-  g_hash_table_destroy (t);
+  g_strfreev (themes);
 
   g_object_bind_property (gtk_settings_get_for_display (vis->priv->display),
                           "gtk-theme-name",
diff --git a/gtk/inspector/visual.ui b/gtk/inspector/visual.ui
index 10b4f4856e..8658f8e399 100644
--- a/gtk/inspector/visual.ui
+++ b/gtk/inspector/visual.ui
@@ -663,7 +663,6 @@
   <object class="GtkSizeGroup">
     <widgets>
       <widget name="theme_label"/>
-      <widget name="dark_label"/>
       <widget name="icon_label"/>
       <widget name="cursor_label"/>
       <widget name="cursor_size_label"/>


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