]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkicontheme.c
Display an error when we come to the root.
[~andy/gtk] / gtk / gtkicontheme.c
index 5cad504433225d1df7e150919433d09c08f94a51..92270bc459dfb13ad9eb8995174c250a73d80d95 100644 (file)
@@ -40,6 +40,7 @@
 #include "gtkiconcache.h"
 #include "gtkbuiltincache.h"
 #include "gtkintl.h"
+#include "gtkmain.h"
 #include "gtksettings.h"
 #include "gtkprivate.h"
 #include "gtkalias.h"
@@ -186,8 +187,6 @@ typedef struct
   GtkIconCache *cache;
 } IconThemeDirMtime;
 
-static void  gtk_icon_theme_class_init (GtkIconThemeClass    *klass);
-static void  gtk_icon_theme_init       (GtkIconTheme         *icon_theme);
 static void  gtk_icon_theme_finalize   (GObject              *object);
 static void  theme_dir_destroy         (IconThemeDir         *dir);
 
@@ -228,8 +227,6 @@ static BuiltinIcon *find_builtin_icon (const gchar *icon_name,
                                       gint        *min_difference_p,
                                       gboolean    *has_larger_p);
 
-static GObjectClass *parent_class = NULL;
-
 static guint signal_changed = 0;
 
 static GHashTable *icon_theme_builtin_icons;
@@ -238,32 +235,7 @@ static GHashTable *icon_theme_builtin_icons;
 GtkIconCache *_builtin_cache = NULL;
 static GList *builtin_dirs = NULL;
 
-
-GType
-gtk_icon_theme_get_type (void)
-{
-  static GType type = 0;
-
-  if (type == 0)
-    {
-      static const GTypeInfo info =
-       {
-         sizeof (GtkIconThemeClass),
-         NULL,           /* base_init */
-         NULL,           /* base_finalize */
-         (GClassInitFunc) gtk_icon_theme_class_init,
-         NULL,           /* class_finalize */
-         NULL,           /* class_data */
-         sizeof (GtkIconTheme),
-         0,              /* n_preallocs */
-         (GInstanceInitFunc) gtk_icon_theme_init,
-       };
-
-      type = g_type_register_static (G_TYPE_OBJECT, I_("GtkIconTheme"), &info, 0);
-    }
-
-  return type;
-}
+G_DEFINE_TYPE (GtkIconTheme, gtk_icon_theme, G_TYPE_OBJECT)
 
 /**
  * gtk_icon_theme_new:
@@ -353,8 +325,6 @@ gtk_icon_theme_class_init (GtkIconThemeClass *klass)
 {
   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
 
-  parent_class = g_type_class_peek_parent (klass);
-
   gobject_class->finalize = gtk_icon_theme_finalize;
 
 /**
@@ -609,7 +579,7 @@ free_dir_mtime (IconThemeDirMtime *dir_mtime)
     _gtk_icon_cache_unref (dir_mtime->cache);
 
   g_free (dir_mtime->dir);
-  g_free (dir_mtime);
+  g_slice_free (IconThemeDirMtime, dir_mtime);
 
 }
 
@@ -649,7 +619,8 @@ do_theme_change (GtkIconTheme *icon_theme)
 
   if (!priv->reset_styles_idle)
     priv->reset_styles_idle = 
-      g_idle_add (reset_styles_idle, icon_theme);
+      g_idle_add_full (GTK_PRIORITY_RESIZE - 2, 
+                      reset_styles_idle, icon_theme, NULL);
 }
 
 static void
@@ -694,7 +665,7 @@ gtk_icon_theme_finalize (GObject *object)
   g_free (priv->current_theme);
   priv->current_theme = NULL;
 
-  for (i=0; i < priv->search_path_len; i++)
+  for (i = 0; i < priv->search_path_len; i++)
     g_free (priv->search_path[i]);
 
   g_free (priv->search_path);
@@ -702,7 +673,7 @@ gtk_icon_theme_finalize (GObject *object)
 
   blow_themes (icon_theme);
 
-  G_OBJECT_CLASS (parent_class)->finalize (object);  
+  G_OBJECT_CLASS (gtk_icon_theme_parent_class)->finalize (object);  
 }
 
 /**
@@ -746,6 +717,7 @@ gtk_icon_theme_set_search_path (GtkIconTheme *icon_theme,
 
   priv->search_path = g_new (gchar *, n_elements);
   priv->search_path_len = n_elements;
+
   for (i = 0; i < priv->search_path_len; i++)
     priv->search_path[i] = g_strdup (path[i]);
 
@@ -811,6 +783,7 @@ gtk_icon_theme_append_search_path (GtkIconTheme *icon_theme,
   priv = icon_theme->priv;
   
   priv->search_path_len++;
+
   priv->search_path = g_renew (gchar *, priv->search_path, priv->search_path_len);
   priv->search_path[priv->search_path_len-1] = g_strdup (path);
 
@@ -923,7 +896,7 @@ insert_theme (GtkIconTheme *icon_theme, const char *theme_name)
       path = g_build_filename (priv->search_path[i],
                               theme_name,
                               NULL);
-      dir_mtime = g_new (IconThemeDirMtime, 1);
+      dir_mtime = g_slice_new (IconThemeDirMtime);
       dir_mtime->cache = NULL;
       dir_mtime->dir = path;
       if (g_stat (path, &stat_buf) == 0 && S_ISDIR (stat_buf.st_mode))
@@ -1026,15 +999,27 @@ free_unthemed_icon (UnthemedIcon *unthemed_icon)
   g_slice_free (UnthemedIcon, unthemed_icon);
 }
 
+static char *
+strip_suffix (const char *filename)
+{
+  const char *dot;
+
+  dot = strrchr (filename, '.');
+
+  if (dot == NULL)
+    return g_strdup (filename);
+
+  return g_strndup (filename, dot - filename);
+}
+
 static void
 load_themes (GtkIconTheme *icon_theme)
 {
   GtkIconThemePrivate *priv;
   GDir *gdir;
   int base;
-  char *dir, *base_name, *dot;
+  char *dir;
   const char *file;
-  char *abs_file;
   UnthemedIcon *unthemed_icon;
   IconSuffix old_suffix, new_suffix;
   GTimeVal tv;
@@ -1061,7 +1046,7 @@ load_themes (GtkIconTheme *icon_theme)
     {
       dir = icon_theme->priv->search_path[base];
 
-      dir_mtime = g_new (IconThemeDirMtime, 1);
+      dir_mtime = g_slice_new (IconThemeDirMtime);
       dir_mtime->cache = _gtk_icon_cache_new_for_path (dir);
       dir_mtime->dir = g_strdup (dir);
       if (g_stat (dir, &stat_buf) == 0 && S_ISDIR (stat_buf.st_mode))
@@ -1085,14 +1070,12 @@ load_themes (GtkIconTheme *icon_theme)
          
          if (new_suffix != ICON_SUFFIX_NONE)
            {
+             char *abs_file;
+             char *base_name;
+
              abs_file = g_build_filename (dir, file, NULL);
-             
-             base_name = g_strdup (file);
-             
-             dot = strrchr (base_name, '.');
-             if (dot)
-               *dot = 0;
-             
+             base_name = strip_suffix (file);
+
              if ((unthemed_icon = g_hash_table_lookup (priv->unthemed_icons,
                                                        base_name)))
                {
@@ -1148,13 +1131,19 @@ load_themes (GtkIconTheme *icon_theme)
   priv->last_stat_time = tv.tv_sec;
 }
 
-static void
+void
 _gtk_icon_theme_ensure_builtin_cache (void)
 {
   static gboolean initialized = FALSE;
   IconThemeDir *dir;
-  gint sizes[5] = { 16, 20, 24, 32, 48 };
-  gint n_sizes = G_N_ELEMENTS (sizes);
+  static IconThemeDir dirs[5] = 
+    {
+      { ICON_THEME_DIR_THRESHOLD, 0, 16, 16, 16, 2, NULL, "16", NULL, NULL, NULL },
+      { ICON_THEME_DIR_THRESHOLD, 0, 20, 20, 20, 2, NULL, "20", NULL, NULL, NULL },
+      { ICON_THEME_DIR_THRESHOLD, 0, 24, 24, 24, 2, NULL, "24", NULL, NULL, NULL },
+      { ICON_THEME_DIR_THRESHOLD, 0, 32, 32, 32, 2, NULL, "32", NULL, NULL, NULL },
+      { ICON_THEME_DIR_THRESHOLD, 0, 48, 48, 48, 2, NULL, "48", NULL, NULL, NULL }
+    };
   gint i;
 
   if (!initialized)
@@ -1163,18 +1152,9 @@ _gtk_icon_theme_ensure_builtin_cache (void)
 
       _builtin_cache = _gtk_icon_cache_new ((gchar *)builtin_icons);
 
-      for (i = 0; i < n_sizes; i++)
+      for (i = 0; i < G_N_ELEMENTS (dirs); i++)
        {
-         dir = g_new (IconThemeDir, 1);
-         dir->type = ICON_THEME_DIR_THRESHOLD;
-         dir->context = 0;
-         dir->size = sizes[i];
-         dir->min_size = sizes[i];
-         dir->max_size = sizes[i];
-         dir->threshold = 2;
-         dir->dir = NULL;
-         dir->icon_data = NULL;
-         dir->subdir = g_strdup_printf ("%d", sizes[i]);
+         dir = &(dirs[i]);
          dir->cache = _gtk_icon_cache_ref (_builtin_cache);
 
          builtin_dirs = g_list_append (builtin_dirs, dir);
@@ -2078,7 +2058,6 @@ load_icon_data (IconThemeDir *dir, const char *path, const char *name)
   char *base_name;
   char **split;
   gsize length;
-  char *dot;
   char *str;
   char *split_point;
   int i;
@@ -2098,9 +2077,7 @@ load_icon_data (IconThemeDir *dir, const char *path, const char *name)
     }
   else
     {
-      base_name = g_strdup (name);
-      dot = strrchr (base_name, '.');
-      *dot = 0;
+      base_name = strip_suffix (name);
       
       data = g_slice_new0 (GtkIconData);
       g_hash_table_replace (dir->icon_data, base_name, data);
@@ -2161,9 +2138,6 @@ scan_directory (GtkIconThemePrivate *icon_theme,
 {
   GDir *gdir;
   const char *name;
-  char *base_name, *dot;
-  char *path;
-  IconSuffix suffix, hash_suffix;
 
   GTK_NOTE (ICONTHEME, 
            g_print ("scanning directory %s\n", full_dir));
@@ -2177,6 +2151,10 @@ scan_directory (GtkIconThemePrivate *icon_theme,
 
   while ((name = g_dir_read_name (gdir)))
     {
+      char *path;
+      char *base_name;
+      IconSuffix suffix, hash_suffix;
+
       if (g_str_has_suffix (name, ".icon"))
        {
          if (dir->icon_data == NULL)
@@ -2195,11 +2173,9 @@ scan_directory (GtkIconThemePrivate *icon_theme,
       suffix = suffix_from_name (name);
       if (suffix == ICON_SUFFIX_NONE)
        continue;
-      
-      base_name = g_strdup (name);
-      dot = strrchr (base_name, '.');
-      *dot = 0;
-      
+
+      base_name = strip_suffix (name);
+
       hash_suffix = GPOINTER_TO_INT (g_hash_table_lookup (dir->icons, base_name));
       g_hash_table_replace (dir->icons, base_name, GUINT_TO_POINTER (hash_suffix| suffix));
       g_hash_table_insert (icon_theme->all_icons, base_name, NULL);