]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkicontheme.c
Display an error when we come to the root.
[~andy/gtk] / gtk / gtkicontheme.c
index d487fd8847308797fbe5ff59b4449931c8777c23..92270bc459dfb13ad9eb8995174c250a73d80d95 100644 (file)
@@ -28,7 +28,6 @@
 #include <stdlib.h>
 #include <glib.h>
 #include <glib/gstdio.h>
-#include "gtkalias.h"
 
 #ifdef G_OS_WIN32
 #ifndef S_ISDIR
 #include "gtkicontheme.h"
 #include "gtkiconfactory.h"
 #include "gtkiconcache.h"
+#include "gtkbuiltincache.h"
 #include "gtkintl.h"
+#include "gtkmain.h"
 #include "gtksettings.h"
 #include "gtkprivate.h"
-
-
+#include "gtkalias.h"
 
 #define DEFAULT_THEME_NAME "hicolor"
 
@@ -68,21 +68,22 @@ typedef enum
 
 struct _GtkIconThemePrivate
 {
-  guint custom_theme : 1;
+  guint custom_theme        : 1;
   guint is_screen_singleton : 1;
   guint pixbuf_supports_svg : 1;
+  guint themes_valid        : 1;
+  guint check_reload        : 1;
   
   char *current_theme;
+  char *fallback_theme;
   char **search_path;
   int search_path_len;
 
-  gboolean themes_valid;
   /* A list of all the themes needed to look up icons.
    * In search order, without duplicates
    */
   GList *themes;
   GHashTable *unthemed_icons;
-  GList *unthemed_icons_caches;
   
   /* Note: The keys of this hashtable are owned by the
    * themedir and unthemed hashtables.
@@ -96,6 +97,8 @@ struct _GtkIconThemePrivate
   /* time when we last stat:ed for theme changes */
   long last_stat_time;
   GList *dir_mtimes;
+
+  gulong reset_styles_idle;
 };
 
 struct _GtkIconInfo
@@ -109,8 +112,6 @@ struct _GtkIconInfo
    */
   gchar *cp_filename;
 #endif
-  GdkPixbuf *builtin_pixbuf;
-
   /* Cache pixbuf (if there is any) */
   GdkPixbuf *cache_pixbuf;
 
@@ -143,11 +144,6 @@ typedef struct
   char *comment;
   char *example;
 
-  /* Icon caches, per theme directory, key is NULL if
-   * no cache exists for that directory
-   */
-  GHashTable *icon_caches;
-  
   /* In search order */
   GList *dirs;
 } IconTheme;
@@ -187,10 +183,10 @@ typedef struct
 {
   char *dir;
   time_t mtime; /* 0 == not existing or not a dir */
+
+  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);
 
@@ -211,10 +207,10 @@ static void         do_theme_change   (GtkIconTheme     *icon_theme);
 
 static void  blow_themes               (GtkIconTheme    *icon_themes);
 
-static void  icon_data_free            (GtkIconData          *icon_data);
-static void load_icon_data (IconThemeDir *dir,
-                           const char   *path,
-                           const char   *name);
+static void  icon_data_free            (GtkIconData     *icon_data);
+static void load_icon_data             (IconThemeDir    *dir,
+                                       const char      *path,
+                                       const char      *name);
 
 static IconSuffix theme_dir_get_icon_suffix (IconThemeDir *dir,
                                             const gchar  *icon_name,
@@ -227,41 +223,19 @@ static GtkIconInfo *icon_info_new_builtin     (BuiltinIcon *icon);
 static IconSuffix suffix_from_name (const char *name);
 
 static BuiltinIcon *find_builtin_icon (const gchar *icon_name,
-                                      gint         size,
+                                      gint        size,
                                       gint        *min_difference_p,
                                       gboolean    *has_larger_p);
 
-static GObjectClass *parent_class = NULL;
-
 static guint signal_changed = 0;
 
 static GHashTable *icon_theme_builtin_icons;
 
-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, "GtkIconTheme", &info, 0);
-    }
+/* also used in gtkiconfactory.c */
+GtkIconCache *_builtin_cache = NULL;
+static GList *builtin_dirs = NULL;
 
-  return type;
-}
+G_DEFINE_TYPE (GtkIconTheme, gtk_icon_theme, G_TYPE_OBJECT)
 
 /**
  * gtk_icon_theme_new:
@@ -291,7 +265,7 @@ gtk_icon_theme_new (void)
  * Return value: A unique #GtkIconTheme associated with
  *  the default screen. This icon theme is associated with
  *  the screen and can be used as long as the screen
- *  is open.
+ *  is open. Do not ref or unref it.
  *
  * Since: 2.4
  **/
@@ -317,7 +291,7 @@ gtk_icon_theme_get_default (void)
  * Return value: A unique #GtkIconTheme associated with
  *  the given screen. This icon theme is associated with
  *  the screen and can be used as long as the screen
- *  is open.
+ *  is open. Do not ref or unref it.
  *
  * Since: 2.4
  **/
@@ -340,7 +314,7 @@ gtk_icon_theme_get_for_screen (GdkScreen *screen)
       priv = icon_theme->priv;
       priv->is_screen_singleton = TRUE;
 
-      g_object_set_data (G_OBJECT (screen), "gtk-icon-theme", icon_theme);
+      g_object_set_data (G_OBJECT (screen), I_("gtk-icon-theme"), icon_theme);
     }
 
   return icon_theme;
@@ -351,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;
 
 /**
@@ -363,7 +335,7 @@ gtk_icon_theme_class_init (GtkIconThemeClass *klass)
  * that a change has occurred in the contents of the current
  * icon theme.
  **/
-  signal_changed = g_signal_new ("changed",
+  signal_changed = g_signal_new (I_("changed"),
                                 G_TYPE_FROM_CLASS (klass),
                                 G_SIGNAL_RUN_LAST,
                                 G_STRUCT_OFFSET (GtkIconThemeClass, changed),
@@ -390,7 +362,7 @@ display_closed (GdkDisplay   *display,
 
   if (was_screen_singleton)
     {
-      g_object_set_data (G_OBJECT (screen), "gtk-icon-theme", NULL);
+      g_object_set_data (G_OBJECT (screen), I_("gtk-icon-theme"), NULL);
       priv->is_screen_singleton = FALSE;
     }
 
@@ -410,11 +382,15 @@ update_current_theme (GtkIconTheme *icon_theme)
   if (!priv->custom_theme)
     {
       gchar *theme = NULL;
+      gchar *fallback_theme = NULL;
+      gboolean changed = FALSE;
 
       if (priv->screen)
        {
          GtkSettings *settings = gtk_settings_get_for_screen (priv->screen);
-         g_object_get (settings, "gtk-icon-theme-name", &theme, NULL);
+         g_object_get (settings, 
+                       "gtk-icon-theme-name", &theme, 
+                       "gtk-fallback-icon-theme", &fallback_theme, NULL);
        }
 
       if (!theme)
@@ -425,10 +401,26 @@ update_current_theme (GtkIconTheme *icon_theme)
          g_free (priv->current_theme);
          priv->current_theme = theme;
 
-         do_theme_change (icon_theme);
+         changed = TRUE;
        }
       else
        g_free (theme);
+
+      if ((priv->fallback_theme && !fallback_theme) ||
+         (!priv->fallback_theme && fallback_theme) ||
+         (priv->fallback_theme && fallback_theme &&
+          strcmp (priv->fallback_theme, fallback_theme) != 0))
+       {
+         g_free (priv->fallback_theme);
+         priv->fallback_theme = fallback_theme;
+
+         changed = TRUE;
+       }
+      else
+       g_free (fallback_theme);
+
+      if (changed)
+       do_theme_change (icon_theme);
     }
 }
 
@@ -502,6 +494,8 @@ gtk_icon_theme_set_screen (GtkIconTheme *icon_theme,
                        G_CALLBACK (display_closed), icon_theme);
       g_signal_connect (settings, "notify::gtk-icon-theme-name",
                        G_CALLBACK (theme_changed), icon_theme);
+      g_signal_connect (settings, "notify::gtk-fallback-icon-theme-name",
+                       G_CALLBACK (theme_changed), icon_theme);
     }
 
   update_current_theme (icon_theme);
@@ -515,12 +509,12 @@ pixbuf_supports_svg (void)
 {
   GSList *formats = gdk_pixbuf_get_formats ();
   GSList *tmp_list;
-  static gboolean found_svg = FALSE;
-  static gboolean value_known = FALSE;
+  static gint found_svg = -1;
 
-  if (value_known)
+  if (found_svg != -1)
     return found_svg;
-  
+  found_svg = FALSE; 
   for (tmp_list = formats; tmp_list && !found_svg; tmp_list = tmp_list->next)
     {
       gchar **mime_types = gdk_pixbuf_format_get_mime_types (tmp_list->data);
@@ -536,7 +530,6 @@ pixbuf_supports_svg (void)
     }
 
   g_slist_free (formats);
-  value_known = TRUE;
   
   return found_svg;
 }
@@ -575,7 +568,6 @@ gtk_icon_theme_init (GtkIconTheme *icon_theme)
   priv->themes_valid = FALSE;
   priv->themes = NULL;
   priv->unthemed_icons = NULL;
-  priv->unthemed_icons_caches = NULL;
   
   priv->pixbuf_supports_svg = pixbuf_supports_svg ();
 }
@@ -583,35 +575,52 @@ gtk_icon_theme_init (GtkIconTheme *icon_theme)
 static void
 free_dir_mtime (IconThemeDirMtime *dir_mtime)
 {
+  if (dir_mtime->cache)
+    _gtk_icon_cache_unref (dir_mtime->cache);
+
   g_free (dir_mtime->dir);
-  g_free (dir_mtime);
+  g_slice_free (IconThemeDirMtime, dir_mtime);
+
 }
 
-static void
-do_theme_change (GtkIconTheme *icon_theme)
+static gboolean
+reset_styles_idle (gpointer user_data)
 {
-  GtkIconThemePrivate *priv = icon_theme->priv;
-  
-  GTK_NOTE (ICONTHEME, 
-           g_print ("change to icon theme \"%s\"\n", priv->current_theme));
-  blow_themes (icon_theme);
-  g_signal_emit (icon_theme, signal_changed, 0);
-  
+  GtkIconTheme *icon_theme;
+  GtkIconThemePrivate *priv;
+
+  GDK_THREADS_ENTER ();
+
+  icon_theme = GTK_ICON_THEME (user_data);
+  priv = icon_theme->priv;
+
   if (priv->screen && priv->is_screen_singleton)
     {
       GtkSettings *settings = gtk_settings_get_for_screen (priv->screen);
       gtk_rc_reset_styles (settings);
     }
+
+  priv->reset_styles_idle = 0;
+
+  GDK_THREADS_LEAVE ();
+
+  return FALSE;
 }
 
-static void 
-free_cache (gpointer data, 
-           gpointer user_data)
+static void
+do_theme_change (GtkIconTheme *icon_theme)
 {
-  GtkIconCache *cache = (GtkIconCache *)data;
+  GtkIconThemePrivate *priv = icon_theme->priv;
+  
+  GTK_NOTE (ICONTHEME, 
+           g_print ("change to icon theme \"%s\"\n", priv->current_theme));
+  blow_themes (icon_theme);
+  g_signal_emit (icon_theme, signal_changed, 0);
 
-  if (cache)
-    _gtk_icon_cache_unref (cache);
+  if (!priv->reset_styles_idle)
+    priv->reset_styles_idle = 
+      g_idle_add_full (GTK_PRIORITY_RESIZE - 2, 
+                      reset_styles_idle, icon_theme, NULL);
 }
 
 static void
@@ -627,13 +636,9 @@ blow_themes (GtkIconTheme *icon_theme)
       g_list_foreach (priv->dir_mtimes, (GFunc)free_dir_mtime, NULL);
       g_list_free (priv->dir_mtimes);
       g_hash_table_destroy (priv->unthemed_icons);
-      if (priv->unthemed_icons_caches)
-       g_list_foreach (priv->unthemed_icons_caches, free_cache, NULL);
-      g_list_free (priv->unthemed_icons_caches);
     }
   priv->themes = NULL;
   priv->unthemed_icons = NULL;
-  priv->unthemed_icons_caches = NULL;
   priv->dir_mtimes = NULL;
   priv->all_icons = NULL;
   priv->themes_valid = FALSE;
@@ -649,12 +654,18 @@ gtk_icon_theme_finalize (GObject *object)
   icon_theme = GTK_ICON_THEME (object);
   priv = icon_theme->priv;
 
+  if (priv->reset_styles_idle)
+    {
+      g_source_remove (priv->reset_styles_idle);
+      priv->reset_styles_idle = 0;
+    }
+
   unset_screen (icon_theme);
 
   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);
@@ -662,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);  
 }
 
 /**
@@ -706,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]);
 
@@ -771,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);
 
@@ -883,7 +896,8 @@ 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))
        dir_mtime->mtime = stat_buf.st_mtime;
@@ -917,19 +931,20 @@ insert_theme (GtkIconTheme *icon_theme, const char *theme_name)
       g_free (path);
     }
 
+  if (theme_file || strcmp (theme_name, DEFAULT_THEME_NAME) == 0)
+    {
+      theme = g_new0 (IconTheme, 1);
+      theme->name = g_strdup (theme_name);
+      priv->themes = g_list_prepend (priv->themes, theme);
+    }
+
   if (theme_file == NULL)
     return;
-  
-  theme = g_new (IconTheme, 1);
+
   theme->display_name = 
     g_key_file_get_locale_string (theme_file, "Icon Theme", "Name", NULL, NULL);
   if (!theme->display_name)
-    {
-      g_warning ("Theme file for %s has no name\n", theme_name);
-      g_free (theme);
-      g_key_file_free (theme_file);
-      return;
-    }
+    g_warning ("Theme file for %s has no name\n", theme_name);
 
   dirs = g_key_file_get_string_list (theme_file, "Icon Theme", "Directories", NULL, NULL);
   if (!dirs)
@@ -941,7 +956,6 @@ insert_theme (GtkIconTheme *icon_theme, const char *theme_name)
       return;
     }
   
-  theme->name = g_strdup (theme_name);
   theme->comment = 
     g_key_file_get_locale_string (theme_file, 
                                  "Icon Theme", "Comment",
@@ -951,17 +965,13 @@ insert_theme (GtkIconTheme *icon_theme, const char *theme_name)
                           "Icon Theme", "Example",
                           NULL);
 
-  theme->icon_caches = NULL;
   theme->dirs = NULL;
   for (i = 0; dirs[i] != NULL; i++)
     theme_subdir_load (icon_theme, theme, theme_file, dirs[i]);
-  
+
   g_strfreev (dirs);
-  
-  theme->dirs = g_list_reverse (theme->dirs);
 
-  /* Prepend the finished theme */
-  priv->themes = g_list_prepend (priv->themes, theme);
+  theme->dirs = g_list_reverse (theme->dirs);
 
   themes = g_key_file_get_string_list (theme_file,
                                       "Icon Theme",
@@ -986,7 +996,20 @@ free_unthemed_icon (UnthemedIcon *unthemed_icon)
     g_free (unthemed_icon->svg_filename);
   if (unthemed_icon->no_svg_filename)
     g_free (unthemed_icon->no_svg_filename);
-  g_free (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
@@ -995,20 +1018,23 @@ 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;
+  IconThemeDirMtime *dir_mtime;
+  struct stat stat_buf;
   
   priv = icon_theme->priv;
 
   priv->all_icons = g_hash_table_new (g_str_hash, g_str_equal);
   
   insert_theme (icon_theme, priv->current_theme);
-  
-  /* Always look in the "default" icon theme */
+
+  /* Always look in the "default" icon theme, and in a fallback theme */
+  if (priv->fallback_theme)
+    insert_theme (icon_theme, priv->fallback_theme);
   insert_theme (icon_theme, DEFAULT_THEME_NAME);
   priv->themes = g_list_reverse (priv->themes);
 
@@ -1018,36 +1044,37 @@ load_themes (GtkIconTheme *icon_theme)
 
   for (base = 0; base < icon_theme->priv->search_path_len; base++)
     {
-      GtkIconCache *cache;
       dir = icon_theme->priv->search_path[base];
 
-      cache = _gtk_icon_cache_new_for_path (dir);
-
-      if (cache != NULL)
-       {
-         priv->unthemed_icons_caches = g_list_prepend (priv->unthemed_icons_caches, cache);
+      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))
+       dir_mtime->mtime = stat_buf.st_mtime;
+      else
+       dir_mtime->mtime = 0;
+      
+      priv->dir_mtimes = g_list_append (priv->dir_mtimes, dir_mtime);
+      
+      if (dir_mtime->cache != NULL)
+       continue;
 
-         continue;
-       }
-          
       gdir = g_dir_open (dir, 0, NULL);
 
       if (gdir == NULL)
        continue;
-      
+
       while ((file = g_dir_read_name (gdir)))
        {
          new_suffix = suffix_from_name (file);
-
+         
          if (new_suffix != ICON_SUFFIX_NONE)
            {
-             abs_file = g_build_filename (dir, file, NULL);
+             char *abs_file;
+             char *base_name;
 
-             base_name = g_strdup (file);
-                 
-             dot = strrchr (base_name, '.');
-             if (dot)
-               *dot = 0;
+             abs_file = g_build_filename (dir, file, NULL);
+             base_name = strip_suffix (file);
 
              if ((unthemed_icon = g_hash_table_lookup (priv->unthemed_icons,
                                                        base_name)))
@@ -1080,7 +1107,7 @@ load_themes (GtkIconTheme *icon_theme)
                }
              else
                {
-                 unthemed_icon = g_new0 (UnthemedIcon, 1);
+                 unthemed_icon = g_slice_new0 (UnthemedIcon);
                  
                  if (new_suffix == ICON_SUFFIX_SVG)
                    unthemed_icon->svg_filename = abs_file;
@@ -1104,12 +1131,46 @@ load_themes (GtkIconTheme *icon_theme)
   priv->last_stat_time = tv.tv_sec;
 }
 
+void
+_gtk_icon_theme_ensure_builtin_cache (void)
+{
+  static gboolean initialized = FALSE;
+  IconThemeDir *dir;
+  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)
+    {
+      initialized = TRUE;
+
+      _builtin_cache = _gtk_icon_cache_new ((gchar *)builtin_icons);
+
+      for (i = 0; i < G_N_ELEMENTS (dirs); i++)
+       {
+         dir = &(dirs[i]);
+         dir->cache = _gtk_icon_cache_ref (_builtin_cache);
+
+         builtin_dirs = g_list_append (builtin_dirs, dir);
+       }
+    }
+}
+
 static void
 ensure_valid_themes (GtkIconTheme *icon_theme)
 {
   GtkIconThemePrivate *priv = icon_theme->priv;
   GTimeVal tv;
-  
+  gboolean was_valid = priv->themes_valid;
+
+  _gtk_icon_theme_ensure_builtin_cache ();
+
   if (priv->themes_valid)
     {
       g_get_current_time (&tv);
@@ -1119,7 +1180,26 @@ ensure_valid_themes (GtkIconTheme *icon_theme)
     }
   
   if (!priv->themes_valid)
-    load_themes (icon_theme);
+    {
+      load_themes (icon_theme);
+      
+      if (!priv->check_reload && was_valid && priv->screen)
+       {         
+         static GdkAtom atom_iconthemes = GDK_NONE;
+         GdkEvent *event = gdk_event_new (GDK_CLIENT_EVENT);
+         int i;
+
+         if (!atom_iconthemes)
+           atom_iconthemes = gdk_atom_intern_static_string ("_GTK_LOAD_ICONTHEMES");
+
+         for (i = 0; i < 5; i++)
+           event->client.data.l[i] = 0;
+         event->client.data_format = 32;
+         event->client.message_type = atom_iconthemes;
+
+         gdk_screen_broadcast_client_message (priv->screen, event);
+       }
+    }
 }
 
 /**
@@ -1153,7 +1233,6 @@ gtk_icon_theme_lookup_icon (GtkIconTheme       *icon_theme,
   UnthemedIcon *unthemed_icon;
   gboolean allow_svg;
   gboolean use_builtin;
-  gboolean found_default;
 
   g_return_val_if_fail (GTK_IS_ICON_THEME (icon_theme), NULL);
   g_return_val_if_fail (icon_name != NULL, NULL);
@@ -1162,6 +1241,8 @@ gtk_icon_theme_lookup_icon (GtkIconTheme       *icon_theme,
 
   priv = icon_theme->priv;
 
+  GTK_NOTE (ICONTHEME, 
+           g_print ("gtk_icon_theme_lookup_icon %s\n", icon_name));
   if (flags & GTK_ICON_LOOKUP_NO_SVG)
     allow_svg = FALSE;
   else if (flags & GTK_ICON_LOOKUP_FORCE_SVG)
@@ -1173,32 +1254,15 @@ gtk_icon_theme_lookup_icon (GtkIconTheme       *icon_theme,
 
   ensure_valid_themes (icon_theme);
 
-  found_default = FALSE;
-  l = priv->themes;
-  while (l != NULL)
+  for (l = priv->themes; l; l = l->next)
     {
       IconTheme *theme = l->data;
       
-      if (strcmp (theme->name, DEFAULT_THEME_NAME) == 0)
-       found_default = TRUE;
-      
       icon_info = theme_lookup_icon (theme, icon_name, size, allow_svg, use_builtin);
       if (icon_info)
        goto out;
-      
-      l = l->next;
     }
 
-  if (!found_default)
-    {
-      BuiltinIcon *builtin = find_builtin_icon (icon_name, size, NULL, NULL);
-      if (builtin)
-       {
-         icon_info = icon_info_new_builtin (builtin);
-         goto out;
-       }
-    }
-  
   unthemed_icon = g_hash_table_lookup (priv->unthemed_icons, icon_name);
   if (unthemed_icon)
     {
@@ -1251,7 +1315,7 @@ gtk_icon_theme_lookup_icon (GtkIconTheme       *icon_theme,
                           "was not found either, perhaps you need to install it.\n"
                           "You can get a copy from:\n"
                           "\t%s"),
-                        icon_name, DEFAULT_THEME_NAME, "http://freedesktop.org/Software/icon-theme/releases");
+                        icon_name, DEFAULT_THEME_NAME, "http://icon-theme.freedesktop.org/releases");
            }
        }
     }
@@ -1263,11 +1327,7 @@ gtk_icon_theme_lookup_icon (GtkIconTheme       *icon_theme,
 GQuark
 gtk_icon_theme_error_quark (void)
 {
-  static GQuark q = 0;
-  if (q == 0)
-    q = g_quark_from_static_string ("gtk-icon-theme-error-quark");
-
-  return q;
+  return g_quark_from_static_string ("gtk-icon-theme-error-quark");
 }
 
 /**
@@ -1283,6 +1343,14 @@ gtk_icon_theme_error_quark (void)
  * and renders it into a pixbuf. This is a convenience function;
  * if more details about the icon are needed, use
  * gtk_icon_theme_lookup_icon() followed by gtk_icon_info_load_icon().
+ *
+ * Note that you probably want to listen for icon theme changes and
+ * update the icon. This is usually done by connecting to the 
+ * GtkWidget::style-set signal. If for some reason you do not want to
+ * update the icon when the icon theme changes, you should consider
+ * using gdk_pixbuf_copy() to make a private copy of the pixbuf
+ * returned by this function. Otherwise GTK+ may need to keep the old 
+ * icon theme loaded, which would be a waste of memory.
  * 
  * Return value: the rendered icon; this may be a newly created icon
  *  or a new reference to an internal icon, so you must not modify
@@ -1322,27 +1390,6 @@ gtk_icon_theme_load_icon (GtkIconTheme         *icon_theme,
   return pixbuf;
 }
 
-typedef struct 
-{
-  const gchar *icon_name;
-  gboolean found;
-} CacheSearch;
-
-static void
-cache_has_icon (gpointer  key,
-               gpointer  value,
-               gpointer  user_data)
-{
-  GtkIconCache *cache = (GtkIconCache *)value;
-  CacheSearch *search = (CacheSearch *)user_data;
-
-  if (!cache || search->found)
-    return;
-
-  if (_gtk_icon_cache_has_icon (cache, search->icon_name))
-    search->found = TRUE;  
-}
-
 /**
  * gtk_icon_theme_has_icon:
  * @icon_theme: a #GtkIconTheme
@@ -1362,7 +1409,6 @@ gtk_icon_theme_has_icon (GtkIconTheme *icon_theme,
 {
   GtkIconThemePrivate *priv;
   GList *l;
-  CacheSearch search;
 
   g_return_val_if_fail (GTK_IS_ICON_THEME (icon_theme), FALSE);
   
@@ -1370,24 +1416,12 @@ gtk_icon_theme_has_icon (GtkIconTheme *icon_theme,
   
   ensure_valid_themes (icon_theme);
 
-  search.icon_name = icon_name;
-  search.found = FALSE;
-
-  for (l = priv->themes; l; l = l->next)
-    {
-      IconTheme *theme = (IconTheme *)l->data;
-
-      g_hash_table_foreach (theme->icon_caches, cache_has_icon, &search);
-
-      if (search.found)
-       return TRUE;
-    }
-
-  for (l = priv->unthemed_icons_caches; l; l = l->next)
+  for (l = priv->dir_mtimes; l; l = l->next)
     {
-      GtkIconCache *cache = (GtkIconCache *)l->data;
-
-      if (_gtk_icon_cache_has_icon (cache, icon_name))
+      IconThemeDirMtime *dir_mtime = l->data;
+      GtkIconCache *cache = dir_mtime->cache;
+      
+      if (cache && _gtk_icon_cache_has_icon (cache, icon_name))
        return TRUE;
     }
 
@@ -1395,6 +1429,10 @@ gtk_icon_theme_has_icon (GtkIconTheme *icon_theme,
                                    icon_name, NULL, NULL))
     return TRUE;
 
+  if (_builtin_cache &&
+      _gtk_icon_cache_has_icon (_builtin_cache, icon_name))
+    return TRUE;
+
   if (icon_theme_builtin_icons &&
       g_hash_table_lookup_extended (icon_theme_builtin_icons,
                                    icon_name, NULL, NULL))
@@ -1435,11 +1473,10 @@ gint *
 gtk_icon_theme_get_icon_sizes (GtkIconTheme *icon_theme,
                               const char   *icon_name)
 {
-  GList *l, *d;
+  GList *l, *d, *icons;
   GHashTable *sizes;
   gint *result, *r;
-  guint suffix;
-  
+  guint suffix;  
   GtkIconThemePrivate *priv;
 
   g_return_val_if_fail (GTK_IS_ICON_THEME (icon_theme), NULL);
@@ -1468,6 +1505,33 @@ gtk_icon_theme_get_icon_sizes (GtkIconTheme *icon_theme,
        }
     }
 
+  for (d = builtin_dirs; d; d = d->next)
+    {
+      IconThemeDir *dir = d->data;
+      
+      suffix = theme_dir_get_icon_suffix (dir, icon_name, NULL);         
+      if (suffix != ICON_SUFFIX_NONE)
+       {
+         if (suffix == ICON_SUFFIX_SVG)
+           g_hash_table_insert (sizes, GINT_TO_POINTER (-1), NULL);
+         else
+           g_hash_table_insert (sizes, GINT_TO_POINTER (dir->size), NULL);
+       }
+    }
+
+  if (icon_theme_builtin_icons)
+    {
+      icons = g_hash_table_lookup (icon_theme_builtin_icons, icon_name);
+      
+      while (icons)
+        {
+         BuiltinIcon *icon = icons->data;
+       
+         g_hash_table_insert (sizes, GINT_TO_POINTER (icon->size), NULL);
+          icons = icons->next;
+        }      
+    }
+
   r = result = g_new0 (gint, g_hash_table_size (sizes) + 1);
 
   g_hash_table_foreach (sizes, add_size, &r);
@@ -1505,8 +1569,8 @@ add_key_to_list (gpointer  key,
  * Lists the icons in the current icon theme. Only a subset
  * of the icons can be listed by providing a context string.
  * The set of values for the context string is system dependent,
- * but will typically include such values as 'apps' and
- * 'mimetypes'.
+ * but will typically include such values as "Applications" and
+ * "MimeTypes".
  * 
  * Return value: a #GList list holding the names of all the
  *  icons in the theme. You must first free each element
@@ -1666,9 +1730,6 @@ theme_destroy (IconTheme *theme)
   g_list_foreach (theme->dirs, (GFunc)theme_dir_destroy, NULL);
   g_list_free (theme->dirs);
   
-  if (theme->icon_caches)
-    g_hash_table_destroy (theme->icon_caches);
-
   g_free (theme);
 }
 
@@ -1791,7 +1852,10 @@ theme_dir_get_icon_suffix (IconThemeDir *dir,
       suffix = suffix & ~HAS_ICON_FILE;
     }
   else
-      suffix = GPOINTER_TO_UINT (g_hash_table_lookup (dir->icons, icon_name));
+    suffix = GPOINTER_TO_UINT (g_hash_table_lookup (dir->icons, icon_name));
+
+  GTK_NOTE (ICONTHEME, 
+           g_print ("get_icon_suffix%s %d\n", dir->cache ? " (cached)" : "", suffix));
 
   return suffix;
 }
@@ -1803,7 +1867,7 @@ theme_lookup_icon (IconTheme          *theme,
                   gboolean            allow_svg,
                   gboolean            use_builtin)
 {
-  GList *l;
+  GList *dirs, *l;
   IconThemeDir *dir, *min_dir;
   char *file;
   int min_difference, difference;
@@ -1820,19 +1884,26 @@ theme_lookup_icon (IconTheme          *theme,
    */
   if (strcmp (theme->name, DEFAULT_THEME_NAME) == 0 && use_builtin)
     {
-      closest_builtin = find_builtin_icon (icon_name, size,
+      closest_builtin = find_builtin_icon (icon_name, 
+                                          size,
                                           &min_difference,
                                           &has_larger);
 
       if (min_difference == 0)
        return icon_info_new_builtin (closest_builtin);
+
+      dirs = builtin_dirs;
     }
+  else
+    dirs = theme->dirs;
 
-  l = theme->dirs;
+  l = dirs;
   while (l != NULL)
     {
       dir = l->data;
 
+      GTK_NOTE (ICONTHEME, 
+               g_print ("theme_lookup_icon dir %s\n", dir->dir));
       suffix = theme_dir_get_icon_suffix (dir, icon_name, NULL);
       if (best_suffix (suffix, allow_svg) != ICON_SUFFIX_NONE)
        {
@@ -1867,6 +1938,12 @@ theme_lookup_icon (IconTheme          *theme,
        }
 
       l = l->next;
+
+      if (l == NULL && dirs == builtin_dirs)
+       {
+         dirs = theme->dirs;
+         l = dirs;
+       }
     }
 
   if (closest_builtin)
@@ -1875,7 +1952,7 @@ theme_lookup_icon (IconTheme          *theme,
   if (min_dir)
     {
       GtkIconInfo *icon_info = icon_info_new ();
-      gboolean has_icon_file;
+      gboolean has_icon_file = FALSE;
       
       suffix = theme_dir_get_icon_suffix (min_dir, icon_name, &has_icon_file);
       suffix = best_suffix (suffix, allow_svg);
@@ -1891,11 +1968,21 @@ theme_lookup_icon (IconTheme          *theme,
       
       if (min_dir->icon_data != NULL)
        icon_info->data = g_hash_table_lookup (min_dir->icon_data, icon_name);
-      else if (min_dir->cache != NULL)
-       icon_info->data = _gtk_icon_cache_get_icon_data (min_dir->cache, icon_name, min_dir->subdir);
 
-      if (icon_info->data == NULL &&
-         min_dir->cache && has_icon_file)
+      if (icon_info->data == NULL && min_dir->cache != NULL)
+       {
+         icon_info->data = _gtk_icon_cache_get_icon_data (min_dir->cache, icon_name, min_dir->subdir);
+         if (icon_info->data)
+           {
+             if (min_dir->icon_data == NULL)
+               min_dir->icon_data = g_hash_table_new_full (g_str_hash, g_str_equal,
+                                                           g_free, (GDestroyNotify)icon_data_free);
+
+             g_hash_table_replace (min_dir->icon_data, g_strdup (icon_name), icon_info->data);
+           }
+       }
+
+      if (icon_info->data == NULL && has_icon_file)
        {
          gchar *icon_file_name, *icon_file_path;
 
@@ -1904,7 +1991,7 @@ theme_lookup_icon (IconTheme          *theme,
 
          if (g_file_test (icon_file_path, G_FILE_TEST_IS_REGULAR))
            {
-             if (min_dir->icon_data == NULL)
+             if (min_dir->icon_data == NULL)   
                min_dir->icon_data = g_hash_table_new_full (g_str_hash, g_str_equal,
                                                            g_free, (GDestroyNotify)icon_data_free);
              load_icon_data (min_dir, icon_file_path, icon_file_name);
@@ -1932,8 +2019,9 @@ theme_lookup_icon (IconTheme          *theme,
 }
 
 static void
-theme_list_icons (IconTheme *theme, GHashTable *icons,
-                 GQuark context)
+theme_list_icons (IconTheme  *theme, 
+                 GHashTable *icons,
+                 GQuark      context)
 {
   GList *l = theme->dirs;
   IconThemeDir *dir;
@@ -1970,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;
@@ -1985,15 +2072,14 @@ load_icon_data (IconThemeDir *dir, const char *path, const char *name)
   if (error)
     {
       g_error_free (error);
+      g_key_file_free (icon_file);      
       return;
     }
   else
     {
-      base_name = g_strdup (name);
-      dot = strrchr (base_name, '.');
-      *dot = 0;
+      base_name = strip_suffix (name);
       
-      data = g_new0 (GtkIconData, 1);
+      data = g_slice_new0 (GtkIconData);
       g_hash_table_replace (dir->icon_data, base_name, data);
       
       ivalues = g_key_file_get_integer_list (icon_file, 
@@ -2019,7 +2105,7 @@ load_icon_data (IconThemeDir *dir, const char *path, const char *name)
          split = g_strsplit (str, "|", -1);
          
          data->n_attach_points = g_strv_length (split);
-         data->attach_points = g_malloc (sizeof (GdkPoint) * data->n_attach_points);
+         data->attach_points = g_new (GdkPoint, data->n_attach_points);
 
          i = 0;
          while (split[i] != NULL && i < data->n_attach_points)
@@ -2052,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));
@@ -2068,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)
@@ -2086,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);
@@ -2117,7 +2202,6 @@ theme_subdir_load (GtkIconTheme *icon_theme,
   int threshold;
   char *full_dir;
   GError *error = NULL;
-  GtkIconCache *cache;
   IconThemeDirMtime *dir_mtime;
 
   size = g_key_file_get_integer (theme_file, subdir, "Size", &error);
@@ -2188,21 +2272,14 @@ theme_subdir_load (GtkIconTheme *icon_theme,
        full_dir = g_build_filename (dir_mtime->dir, subdir, NULL);
 
       /* First, see if we have a cache for the directory */
-      if (!theme->icon_caches)
-       theme->icon_caches = g_hash_table_new_full (g_str_hash, g_str_equal,
-                                                   g_free, (GDestroyNotify)free_cache);
-                                                  
-      if (!g_hash_table_lookup_extended (theme->icon_caches, dir_mtime->dir, 
-                                        NULL, (gpointer)&cache))
-       {
-         /* This will return NULL if the cache doesn't exist or is outdated */
-         cache = _gtk_icon_cache_new_for_path (dir_mtime->dir);
-
-         g_hash_table_insert (theme->icon_caches, g_strdup (dir_mtime->dir), cache);
-       }
-
-      if (cache != NULL || g_file_test (full_dir, G_FILE_TEST_IS_DIR))
+      if (dir_mtime->cache != NULL || g_file_test (full_dir, G_FILE_TEST_IS_DIR))
        {
+         if (dir_mtime->cache == NULL)
+           {
+             /* This will return NULL if the cache doesn't exist or is outdated */
+             dir_mtime->cache = _gtk_icon_cache_new_for_path (dir_mtime->dir);
+           }
+         
          dir = g_new (IconThemeDir, 1);
          dir->type = type;
          dir->context = context;
@@ -2213,8 +2290,8 @@ theme_subdir_load (GtkIconTheme *icon_theme,
          dir->dir = full_dir;
          dir->icon_data = NULL;
          dir->subdir = g_strdup (subdir);
-         if (cache != NULL)
-           dir->cache = _gtk_icon_cache_ref (cache);
+         if (dir_mtime->cache != NULL)
+           dir->cache = _gtk_icon_cache_ref (dir_mtime->cache);
          else
            {
              dir->cache = NULL;
@@ -2233,7 +2310,7 @@ icon_data_free (GtkIconData *icon_data)
 {
   g_free (icon_data->attach_points);
   g_free (icon_data->display_name);
-  g_free (icon_data);
+  g_slice_free (GtkIconData, icon_data);
 }
 
 /*
@@ -2245,17 +2322,18 @@ gtk_icon_info_get_type (void)
   static GType our_type = 0;
   
   if (our_type == 0)
-    our_type = g_boxed_type_register_static ("GtkIconInfo",
+    our_type = g_boxed_type_register_static (I_("GtkIconInfo"),
                                             (GBoxedCopyFunc) gtk_icon_info_copy,
                                             (GBoxedFreeFunc) gtk_icon_info_free);
 
+
   return our_type;
 }
 
 static GtkIconInfo *
 icon_info_new (void)
 {
-  GtkIconInfo *icon_info = g_new0 (GtkIconInfo, 1);
+  GtkIconInfo *icon_info = g_slice_new0 (GtkIconInfo);
 
   icon_info->scale = -1.;
 
@@ -2267,7 +2345,7 @@ icon_info_new_builtin (BuiltinIcon *icon)
 {
   GtkIconInfo *icon_info = icon_info_new ();
 
-  icon_info->builtin_pixbuf = g_object_ref (icon->pixbuf);
+  icon_info->cache_pixbuf = g_object_ref (icon->pixbuf);
   icon_info->dir_type = ICON_THEME_DIR_THRESHOLD;
   icon_info->dir_size = icon->size;
   icon_info->threshold = 2;
@@ -2292,9 +2370,9 @@ gtk_icon_info_copy (GtkIconInfo *icon_info)
   
   g_return_val_if_fail (icon_info != NULL, NULL);
 
-  copy = g_memdup (icon_info, sizeof (GtkIconInfo));
-  if (copy->builtin_pixbuf)
-    g_object_ref (copy->builtin_pixbuf);
+  copy = memcpy (g_slice_new (GtkIconInfo), icon_info, sizeof (GtkIconInfo));
+  if (copy->cache_pixbuf)
+    g_object_ref (copy->cache_pixbuf);
   if (copy->pixbuf)
     g_object_ref (copy->pixbuf);
   if (copy->load_error)
@@ -2328,14 +2406,12 @@ gtk_icon_info_free (GtkIconInfo *icon_info)
   if (icon_info->cp_filename)
     g_free (icon_info->cp_filename);
 #endif
-  if (icon_info->builtin_pixbuf)
-    g_object_unref (icon_info->builtin_pixbuf);
   if (icon_info->pixbuf)
     g_object_unref (icon_info->pixbuf);
   if (icon_info->cache_pixbuf)
     g_object_unref (icon_info->cache_pixbuf);
-  
-  g_free (icon_info);
+
+  g_slice_free (GtkIconInfo, icon_info);
 }
 
 /**
@@ -2410,7 +2486,10 @@ gtk_icon_info_get_builtin_pixbuf (GtkIconInfo *icon_info)
 {
   g_return_val_if_fail (icon_info != NULL, NULL);
 
-  return icon_info->builtin_pixbuf;
+  if (icon_info->filename)
+    return NULL;
+  
+  return icon_info->cache_pixbuf;
 }
 
 static GdkPixbuf *
@@ -2427,7 +2506,10 @@ load_svg_at_size (const gchar *filename,
                            &contents, &length, error))
     goto bail;
   
-  loader = gdk_pixbuf_loader_new ();
+  loader = gdk_pixbuf_loader_new_with_type ("svg", error);
+  if (loader == NULL)
+    goto bail;
+
   gdk_pixbuf_loader_set_size (loader, size, size);
   
   if (!gdk_pixbuf_loader_write (loader, contents, length, error))
@@ -2517,9 +2599,7 @@ icon_info_ensure_scale_and_pixbuf (GtkIconInfo *icon_info,
   /* At this point, we need to actually get the icon; either from the
    * builting image or by loading the file
    */
-  if (icon_info->builtin_pixbuf)
-    source_pixbuf = g_object_ref (icon_info->builtin_pixbuf);
-  else if (icon_info->cache_pixbuf)
+  if (icon_info->cache_pixbuf)
     source_pixbuf = g_object_ref (icon_info->cache_pixbuf);
   else
     {
@@ -2572,7 +2652,7 @@ icon_info_ensure_scale_and_pixbuf (GtkIconInfo *icon_info,
 /**
  * gtk_icon_info_load_icon:
  * @icon_info: a #GtkIconInfo structure from gtk_icon_theme_lookup_icon()
- * @error: 
+ * @error: location to store error information on failure, or %NULL.
  * 
  * Renders an icon previously looked up in an icon theme using
  * gtk_icon_theme_lookup_icon(); the size will be based on the size
@@ -2789,7 +2869,7 @@ gtk_icon_info_get_attach_points (GtkIconInfo *icon_info,
  * Since: 2.4
  **/
 G_CONST_RETURN gchar *
-gtk_icon_info_get_display_name  (GtkIconInfo *icon_info)
+gtk_icon_info_get_display_name (GtkIconInfo *icon_info)
 {
   g_return_val_if_fail (icon_info != NULL, NULL);
 
@@ -2877,8 +2957,6 @@ find_builtin_icon (const gchar *icon_name,
   gboolean has_larger = FALSE;
   BuiltinIcon *min_icon = NULL;
   
-  _gtk_icon_factory_ensure_default_icons ();
-  
   if (!icon_theme_builtin_icons)
     return NULL;
 
@@ -2935,6 +3013,29 @@ find_builtin_icon (const gchar *icon_name,
   return min_icon;
 }
 
+void
+_gtk_icon_theme_check_reload (GdkDisplay *display)
+{
+  gint n_screens, i;
+  GdkScreen *screen;
+  GtkIconTheme *icon_theme;
+
+  n_screens = gdk_display_get_n_screens (display);
+  
+  for (i = 0; i < n_screens; i++)
+    {
+      screen = gdk_display_get_screen (display, i);
+
+      icon_theme = g_object_get_data (G_OBJECT (screen), "gtk-icon-theme");
+      if (icon_theme)
+       {
+         icon_theme->priv->check_reload = TRUE;
+         ensure_valid_themes (icon_theme);
+         icon_theme->priv->check_reload = FALSE;
+       }
+    }
+}
+
 #ifdef G_OS_WIN32
 
 /* DLL ABI stability backward compatibility versions */
@@ -3025,3 +3126,6 @@ gtk_icon_info_get_filename (GtkIconInfo *icon_info)
 }
 
 #endif
+
+#define __GTK_ICON_THEME_C__
+#include "gtkaliasdef.c"