From ed0b6d5e6d2dc0e2d2124ec9f32067dbbc51d9aa Mon Sep 17 00:00:00 2001
From: Benedikt Meurer <benny@xfce.org>
Date: Tue, 30 Aug 2005 21:39:59 +0000
Subject: [PATCH] 2005-08-30	Benedikt Meurer <benny@xfce.org>

	* thunar/thunar-favourites-model.c: Drop the icon caching from the
	  favourites model as it causes trouble with icon theme changing and
	  is unnecessary since the ThunarIconFactory already performs quite
	  well at caching icons.
	* thunar/thunar-location-buttons.c: Reload the icons for the location
	  buttons when the active icon/gtk theme is changed.




(Old svn revision: 17200)
---
 ChangeLog                        |  9 +++++
 thunar/thunar-favourites-model.c | 68 +++++++++++---------------------
 thunar/thunar-location-buttons.c | 34 ++++++++++++++++
 3 files changed, 67 insertions(+), 44 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 3e2f79114..4dea705b3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2005-08-30	Benedikt Meurer <benny@xfce.org>
+
+	* thunar/thunar-favourites-model.c: Drop the icon caching from the
+	  favourites model as it causes trouble with icon theme changing and
+	  is unnecessary since the ThunarIconFactory already performs quite
+	  well at caching icons.
+	* thunar/thunar-location-buttons.c: Reload the icons for the location
+	  buttons when the active icon/gtk theme is changed.
+
 2005-08-30	Benedikt Meurer <benny@xfce.org>
 
 	* thunar/thunar-local-file.c(thunar_local_folder_infos_ready): Do not
diff --git a/thunar/thunar-favourites-model.c b/thunar/thunar-favourites-model.c
index a69eda430..ddf3890aa 100644
--- a/thunar/thunar-favourites-model.c
+++ b/thunar/thunar-favourites-model.c
@@ -129,7 +129,6 @@ struct _ThunarFavouritesModel
   guint                   stamp;
   GList                  *favourites;
   GList                  *hidden_volumes;
-  ThunarIconFactory      *icon_factory;
   ThunarVfsVolumeManager *volume_manager;
 
   ThunarVfsMonitor       *monitor;
@@ -143,9 +142,6 @@ struct _ThunarFavourite
   gchar              *name;
   ThunarFile         *file;
   ThunarVfsVolume    *volume;
-
-  /* cached icon */
-  GdkPixbuf          *icon;
 };
 
 
@@ -213,7 +209,6 @@ thunar_favourites_model_init (ThunarFavouritesModel *model)
   gchar           *bookmarks_path;
 
   model->stamp = g_random_int ();
-  model->icon_factory = thunar_icon_factory_get_for_icon_theme (gtk_icon_theme_get_default ());
   model->volume_manager = thunar_vfs_volume_manager_get_default ();
 
   /* will be used to append the favourites to the list */
@@ -224,9 +219,11 @@ thunar_favourites_model_init (ThunarFavouritesModel *model)
   file = thunar_file_get_for_uri (uri, NULL);
   if (G_LIKELY (file != NULL))
     {
-      favourite = g_new0 (ThunarFavourite, 1);
+      favourite = g_new (ThunarFavourite, 1);
       favourite->type = THUNAR_FAVOURITE_SYSTEM_DEFINED;
       favourite->file = file;
+      favourite->name = NULL;
+      favourite->volume = NULL;
 
       /* append the favourite to the list */
       thunar_favourites_model_add_favourite (model, favourite, path);
@@ -239,9 +236,11 @@ thunar_favourites_model_init (ThunarFavouritesModel *model)
   file = thunar_file_get_for_uri (uri, NULL);
   if (G_LIKELY (file != NULL))
     {
-      favourite = g_new0 (ThunarFavourite, 1);
+      favourite = g_new (ThunarFavourite, 1);
       favourite->type = THUNAR_FAVOURITE_SYSTEM_DEFINED;
       favourite->file = file;
+      favourite->name = NULL;
+      favourite->volume = NULL;
 
       /* append the favourite to the list */
       thunar_favourites_model_add_favourite (model, favourite, path);
@@ -254,9 +253,11 @@ thunar_favourites_model_init (ThunarFavouritesModel *model)
   file = thunar_file_get_for_uri (uri, NULL);
   if (G_LIKELY (file != NULL))
     {
-      favourite = g_new0 (ThunarFavourite, 1);
+      favourite = g_new (ThunarFavourite, 1);
       favourite->type = THUNAR_FAVOURITE_SYSTEM_DEFINED;
       favourite->file = file;
+      favourite->name = NULL;
+      favourite->volume = NULL;
 
       /* append the favourite to the list */
       thunar_favourites_model_add_favourite (model, favourite, path);
@@ -284,9 +285,10 @@ thunar_favourites_model_init (ThunarFavouritesModel *model)
               if (G_LIKELY (file != NULL))
                 {
                   /* generate the favourite */
-                  favourite = g_new0 (ThunarFavourite, 1);
+                  favourite = g_new (ThunarFavourite, 1);
                   favourite->type = THUNAR_FAVOURITE_REMOVABLE_MEDIA;
                   favourite->file = file;
+                  favourite->name = NULL;
                   favourite->volume = volume;
 
                   /* link the favourite to the list */
@@ -347,9 +349,6 @@ thunar_favourites_model_finalize (GObject *object)
   thunar_vfs_monitor_remove (model->monitor, model->handle);
   g_object_unref (G_OBJECT (model->monitor));
 
-  /* unlink from the icon factory */
-  g_object_unref (G_OBJECT (model->icon_factory));
-
   /* unlink from the volume manager */
   g_object_unref (G_OBJECT (model->volume_manager));
 
@@ -451,9 +450,11 @@ thunar_favourites_model_get_value (GtkTreeModel *tree_model,
                                    GValue       *value)
 {
   ThunarFavouritesModel *model = THUNAR_FAVOURITES_MODEL (tree_model);
+  ThunarIconFactory     *icon_factory;
   ThunarFavourite       *favourite;
   GtkIconTheme          *icon_theme;
   const gchar           *icon_name;
+  GdkPixbuf             *icon;
 
   g_return_if_fail (THUNAR_IS_FAVOURITES_MODEL (model));
   g_return_if_fail (iter->stamp == model->stamp);
@@ -477,20 +478,18 @@ thunar_favourites_model_get_value (GtkTreeModel *tree_model,
 
     case THUNAR_FAVOURITES_MODEL_COLUMN_ICON:
       g_value_init (value, GDK_TYPE_PIXBUF);
-      if (G_UNLIKELY (favourite->icon == NULL))
+      icon_factory = thunar_icon_factory_get_default ();
+      icon_theme = thunar_icon_factory_get_icon_theme (icon_factory);
+      if (G_UNLIKELY (favourite->volume != NULL))
         {
-          if (G_UNLIKELY (favourite->volume != NULL))
-            {
-              icon_theme = thunar_icon_factory_get_icon_theme (model->icon_factory);
-              icon_name = thunar_vfs_volume_lookup_icon_name (favourite->volume, icon_theme);
-              favourite->icon = thunar_icon_factory_load_icon (model->icon_factory, icon_name, 32, NULL, TRUE);
-            }
-          else if (G_LIKELY (favourite->file != NULL))
-            {
-              favourite->icon = thunar_file_load_icon (favourite->file, model->icon_factory, 32);
-            }
+          icon_name = thunar_vfs_volume_lookup_icon_name (favourite->volume, icon_theme);
+          icon = thunar_icon_factory_load_icon (icon_factory, icon_name, 32, NULL, TRUE);
+        }
+      else if (G_LIKELY (favourite->file != NULL))
+        {
+          icon = thunar_file_load_icon (favourite->file, icon_factory, 32);
         }
-      g_value_set_object (value, favourite->icon);
+      g_value_take_object (value, icon);
       break;
 
     case THUNAR_FAVOURITES_MODEL_COLUMN_MUTABLE:
@@ -737,7 +736,6 @@ thunar_favourites_model_load (ThunarFavouritesModel *model)
           favourite->type = THUNAR_FAVOURITE_USER_DEFINED;
           favourite->file = file;
           favourite->volume = NULL;
-          favourite->icon = NULL;
           favourite->name = (*name != '\0') ? g_strdup (name) : NULL;
 
           /* append the favourite to the list */
@@ -897,13 +895,6 @@ thunar_favourites_model_file_changed (ThunarFile            *file,
       favourite = THUNAR_FAVOURITE (lp->data);
       if (favourite->file == file)
         {
-          /* drop the cached icon */
-          if (G_LIKELY (favourite->icon != NULL))
-            {
-              g_object_unref (G_OBJECT (favourite->icon));
-              favourite->icon = NULL;
-            }
-
           iter.stamp = model->stamp;
           iter.user_data = lp;
 
@@ -1000,8 +991,8 @@ thunar_favourites_model_volume_changed (ThunarVfsVolume       *volume,
               favourite = g_new (ThunarFavourite, 1);
               favourite->type = THUNAR_FAVOURITE_REMOVABLE_MEDIA;
               favourite->file = file;
+              favourite->name = NULL;
               favourite->volume = volume;
-              favourite->icon = NULL;
 
               /* the volume is present now, so we have to display it */
               path = gtk_tree_path_new_from_indices (index, -1);
@@ -1042,13 +1033,6 @@ thunar_favourites_model_volume_changed (ThunarVfsVolume       *volume,
         }
       else
         {
-          /* drop the cached icon */
-          if (G_LIKELY (favourite->icon != NULL))
-            {
-              g_object_unref (G_OBJECT (favourite->icon));
-              favourite->icon = NULL;
-            }
-
           /* tell the view that the volume has changed in some way */
           iter.stamp = model->stamp;
           iter.user_data = lp;
@@ -1086,10 +1070,6 @@ thunar_favourite_free (ThunarFavourite       *favourite,
       g_object_unref (G_OBJECT (favourite->volume));
     }
 
-  /* drop any cached icon */
-  if (G_LIKELY (favourite->icon != NULL))
-    g_object_unref (G_OBJECT (favourite->icon));
-
   g_free (favourite->name);
   g_free (favourite);
 }
diff --git a/thunar/thunar-location-buttons.c b/thunar/thunar-location-buttons.c
index c796e8a85..24e31bbbd 100644
--- a/thunar/thunar-location-buttons.c
+++ b/thunar/thunar-location-buttons.c
@@ -71,6 +71,8 @@ static void        thunar_location_buttons_size_allocate          (GtkWidget
                                                                    GtkAllocation              *allocation);
 static void        thunar_location_buttons_state_changed          (GtkWidget                  *widget,
                                                                    GtkStateType                previous_state);
+static void        thunar_location_buttons_style_set              (GtkWidget                  *widget,
+                                                                   GtkStyle                   *previous_style);
 static void        thunar_location_buttons_grab_notify            (GtkWidget                  *widget,
                                                                    gboolean                    was_grabbed);
 static void        thunar_location_buttons_add                    (GtkContainer               *container,
@@ -189,6 +191,7 @@ thunar_location_buttons_class_init (ThunarLocationButtonsClass *klass)
   gtkwidget_class->size_request = thunar_location_buttons_size_request;
   gtkwidget_class->size_allocate = thunar_location_buttons_size_allocate;
   gtkwidget_class->state_changed = thunar_location_buttons_state_changed;
+  gtkwidget_class->style_set = thunar_location_buttons_style_set;
   gtkwidget_class->grab_notify = thunar_location_buttons_grab_notify;
 
   gtkcontainer_class = GTK_CONTAINER_CLASS (klass);
@@ -652,6 +655,37 @@ thunar_location_buttons_state_changed (GtkWidget   *widget,
 
 
 
+static void
+thunar_location_buttons_style_set (GtkWidget *widget,
+                                   GtkStyle  *previous_style)
+{
+  ThunarLocationButtons *buttons = THUNAR_LOCATION_BUTTONS (widget);
+  ThunarFile            *file;
+  GdkPixbuf             *icon;
+  GList                 *children;
+  GList                 *lp;
+  gint                   size;
+
+  /* lookup the icon size for buttons */
+  gtk_icon_size_lookup (GTK_ICON_SIZE_BUTTON, &size, &size);
+
+  /* update the icons for every button */
+  for (lp = buttons->list; lp != NULL; lp = lp->next)
+    {
+      file = g_object_get_qdata (G_OBJECT (lp->data), thunar_file_quark);
+      children = gtk_container_get_children (GTK_CONTAINER (GTK_BIN (lp->data)->child));
+      icon = thunar_file_load_icon (file, thunar_icon_factory_get_default (), size);
+      gtk_drag_source_set_icon_pixbuf (GTK_WIDGET (lp->data), icon);
+      gtk_image_set_from_pixbuf (GTK_IMAGE (children->data), icon);
+      g_object_unref (G_OBJECT (icon));
+      g_list_free (children);
+    }
+
+  (*GTK_WIDGET_CLASS (thunar_location_buttons_parent_class)->style_set) (widget, previous_style);
+}
+
+
+
 static void
 thunar_location_buttons_grab_notify (GtkWidget *widget,
                                      gboolean   was_grabbed)
-- 
GitLab