summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKristian Rietveld <kris@imendio.com>2006-04-30 19:38:11 +0000
committerKristian Rietveld <kristian@src.gnome.org>2006-04-30 19:38:11 +0000
commit65bdb7ca9a5003b0c519bc5980a40859367b8db2 (patch)
tree85fdd2896a9cb0136d4e2507a46e049ef035ca41
parentc0d773526052c9861546c26f47b03f2ac93898c8 (diff)
downloadgtk+-kris-async-branch.tar.gz
remove the caching code, (gtk_file_info_get_icon_name): new function,kris-async-branch
2006-04-30 Kristian Rietveld <kris@imendio.com> * gtk/gtkfilesystem.[ch] (gtk_file_info_render_icon): remove the caching code, (gtk_file_info_get_icon_name): new function, (gtk_file_system_volume_get_icon_name): new function, (gtk_file_system_volume_render_icon): refactor to use get_icon_name() and render the icon on the fly. * gtk/gtkfilesystemunix.c (gtk_file_system_unix_volume_render_icon), (gtk_file_system_unix_volume_get_icon_name): reflect updates in file system interface, (get_fallback_icon): remove, along with icon caching code. * gtk/gtk.symbols: updated.
-rw-r--r--ChangeLog16
-rw-r--r--ChangeLog.pre-2-1016
-rw-r--r--gtk/gtk.symbols2
-rw-r--r--gtk/gtkfilesystem.c141
-rw-r--r--gtk/gtkfilesystem.h8
-rw-r--r--gtk/gtkfilesystemunix.c118
6 files changed, 108 insertions, 193 deletions
diff --git a/ChangeLog b/ChangeLog
index b77532329b..4a724dad4e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,21 @@
2006-04-30 Kristian Rietveld <kris@imendio.com>
+ * gtk/gtkfilesystem.[ch] (gtk_file_info_render_icon): remove the
+ caching code,
+ (gtk_file_info_get_icon_name): new function,
+ (gtk_file_system_volume_get_icon_name): new function,
+ (gtk_file_system_volume_render_icon): refactor to use
+ get_icon_name() and render the icon on the fly.
+
+ * gtk/gtkfilesystemunix.c (gtk_file_system_unix_volume_render_icon),
+ (gtk_file_system_unix_volume_get_icon_name): reflect updates in
+ file system interface,
+ (get_fallback_icon): remove, along with icon caching code.
+
+ * gtk/gtk.symbols: updated.
+
+2006-04-30 Kristian Rietveld <kris@imendio.com>
+
* gtk/gtkfilesystemmodel.c (got_root_folder_cb), (ref_path_cb),
(get_children_get_folder_cb): don't leak the handle,
(got_root_folder_cb), (get_children_get_folder_cb): emit
diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10
index b77532329b..4a724dad4e 100644
--- a/ChangeLog.pre-2-10
+++ b/ChangeLog.pre-2-10
@@ -1,5 +1,21 @@
2006-04-30 Kristian Rietveld <kris@imendio.com>
+ * gtk/gtkfilesystem.[ch] (gtk_file_info_render_icon): remove the
+ caching code,
+ (gtk_file_info_get_icon_name): new function,
+ (gtk_file_system_volume_get_icon_name): new function,
+ (gtk_file_system_volume_render_icon): refactor to use
+ get_icon_name() and render the icon on the fly.
+
+ * gtk/gtkfilesystemunix.c (gtk_file_system_unix_volume_render_icon),
+ (gtk_file_system_unix_volume_get_icon_name): reflect updates in
+ file system interface,
+ (get_fallback_icon): remove, along with icon caching code.
+
+ * gtk/gtk.symbols: updated.
+
+2006-04-30 Kristian Rietveld <kris@imendio.com>
+
* gtk/gtkfilesystemmodel.c (got_root_folder_cb), (ref_path_cb),
(get_children_get_folder_cb): don't leak the handle,
(got_root_folder_cb), (get_children_get_folder_cb): emit
diff --git a/gtk/gtk.symbols b/gtk/gtk.symbols
index 242e1a6b9c..5710bbb0d3 100644
--- a/gtk/gtk.symbols
+++ b/gtk/gtk.symbols
@@ -1344,6 +1344,7 @@ gtk_file_info_copy
gtk_file_info_free
gtk_file_info_get_display_key
gtk_file_info_get_display_name
+gtk_file_info_get_icon_name
gtk_file_info_get_is_folder
gtk_file_info_get_is_hidden
gtk_file_info_get_mime_type
@@ -1385,6 +1386,7 @@ gtk_file_system_uri_to_path
gtk_file_system_volume_free
gtk_file_system_volume_get_base_path
gtk_file_system_volume_get_display_name
+gtk_file_system_volume_get_icon_name
gtk_file_system_volume_get_is_mounted
gtk_file_system_volume_mount
gtk_file_system_volume_render_icon
diff --git a/gtk/gtkfilesystem.c b/gtk/gtkfilesystem.c
index 85197c62dd..7580d255c5 100644
--- a/gtk/gtkfilesystem.c
+++ b/gtk/gtkfilesystem.c
@@ -271,81 +271,12 @@ gtk_file_info_set_icon_name (GtkFileInfo *info,
info->icon_name = g_strdup (icon_name);
}
-
-typedef struct
-{
- gint size;
- GdkPixbuf *pixbuf;
-} IconCacheElement;
-
-static void
-icon_cache_element_free (IconCacheElement *element)
-{
- if (element->pixbuf)
- g_object_unref (element->pixbuf);
- g_free (element);
-}
-
-static void
-icon_theme_changed (GtkIconTheme *icon_theme)
-{
- GHashTable *cache;
-
- /* Difference from the initial creation is that we don't
- * reconnect the signal
- */
- cache = g_hash_table_new_full (g_str_hash, g_str_equal,
- (GDestroyNotify)g_free,
- (GDestroyNotify)icon_cache_element_free);
- g_object_set_data_full (G_OBJECT (icon_theme), I_("gtk-file-icon-cache"),
- cache, (GDestroyNotify)g_hash_table_destroy);
-}
-
-static GdkPixbuf *
-get_cached_icon (GtkWidget *widget,
- const gchar *name,
- gint pixel_size)
+G_CONST_RETURN gchar *
+gtk_file_info_get_icon_name (const GtkFileInfo *info)
{
- GtkIconTheme *icon_theme;
- GHashTable *cache;
- IconCacheElement *element;
-
- icon_theme = gtk_icon_theme_get_for_screen (gtk_widget_get_screen (widget));
- cache = g_object_get_data (G_OBJECT (icon_theme), "gtk-file-icon-cache");
-
- if (!cache)
- {
- cache = g_hash_table_new_full (g_str_hash, g_str_equal,
- (GDestroyNotify)g_free,
- (GDestroyNotify)icon_cache_element_free);
-
- g_object_set_data_full (G_OBJECT (icon_theme), I_("gtk-file-icon-cache"),
- cache, (GDestroyNotify)g_hash_table_destroy);
- g_signal_connect (icon_theme, "changed",
- G_CALLBACK (icon_theme_changed), NULL);
- }
-
- element = g_hash_table_lookup (cache, name);
- if (!element)
- {
- element = g_new0 (IconCacheElement, 1);
- g_hash_table_insert (cache, g_strdup (name), element);
- }
-
- if (element->size != pixel_size)
- {
- if (element->pixbuf)
- g_object_unref (element->pixbuf);
- element->size = pixel_size;
-
- if (g_path_is_absolute (name))
- element->pixbuf = gdk_pixbuf_new_from_file_at_size (name, pixel_size, pixel_size, NULL);
- else
- element->pixbuf = gtk_icon_theme_load_icon (icon_theme, name,
- pixel_size, 0, NULL);
- }
-
- return element->pixbuf ? g_object_ref (element->pixbuf) : NULL;
+ g_return_val_if_fail (info != NULL, NULL);
+
+ return info->icon_name;
}
GdkPixbuf *
@@ -360,7 +291,21 @@ gtk_file_info_render_icon (const GtkFileInfo *info,
g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
if (info->icon_name)
- pixbuf = get_cached_icon (widget, info->icon_name, pixel_size);
+ {
+ if (g_path_is_absolute (info->icon_name))
+ pixbuf = gdk_pixbuf_new_from_file_at_size (info->icon_name,
+ pixel_size,
+ pixel_size,
+ NULL);
+ else
+ {
+ GtkIconTheme *icon_theme;
+
+ icon_theme = gtk_icon_theme_get_for_screen (gtk_widget_get_screen (widget));
+ pixbuf = gtk_icon_theme_load_icon (icon_theme, info->icon_name,
+ pixel_size, 0, NULL);
+ }
+ }
if (!pixbuf)
{
@@ -740,17 +685,53 @@ gtk_file_system_volume_render_icon (GtkFileSystem *file_system,
gint pixel_size,
GError **error)
{
+ gchar *icon_name;
+ GdkPixbuf *pixbuf;
+
g_return_val_if_fail (GTK_IS_FILE_SYSTEM (file_system), NULL);
g_return_val_if_fail (volume != NULL, NULL);
g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
g_return_val_if_fail (pixel_size > 0, NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
- return GTK_FILE_SYSTEM_GET_IFACE (file_system)->volume_render_icon (file_system,
- volume,
- widget,
- pixel_size,
- error);
+ icon_name = gtk_file_system_volume_get_icon_name (file_system, volume,
+ error);
+ if (!icon_name)
+ {
+ return NULL;
+ }
+
+ pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_for_screen (gtk_widget_get_screen (widget)),
+ icon_name, pixel_size, 0, NULL);
+ g_free (icon_name);
+
+ return pixbuf;
+}
+
+/**
+ * gtk_file_system_volume_get_icon_name:
+ * @file_system: a #GtkFileSystem
+ * @volume: a #GtkFileSystemVolume
+ * @error: location to store error, or %NULL
+ *
+ * Gets an icon name suitable for a #GtkFileSystemVolume.
+ *
+ * Return value: An icon name which can be used for rendering an icon for
+ * this volume, or %NULL if no icon name could be found. In the latter
+ * case, the @error value will be set as appropriate.
+ **/
+gchar *
+gtk_file_system_volume_get_icon_name (GtkFileSystem *file_system,
+ GtkFileSystemVolume *volume,
+ GError **error)
+{
+ g_return_val_if_fail (GTK_IS_FILE_SYSTEM (file_system), NULL);
+ g_return_val_if_fail (volume != NULL, NULL);
+ g_return_val_if_fail (error == NULL || *error == NULL, NULL);
+
+ return GTK_FILE_SYSTEM_GET_IFACE (file_system)->volume_get_icon_name (file_system,
+ volume,
+ error);
}
/**
diff --git a/gtk/gtkfilesystem.h b/gtk/gtkfilesystem.h
index 6145bc706e..57c458a028 100644
--- a/gtk/gtkfilesystem.h
+++ b/gtk/gtkfilesystem.h
@@ -109,6 +109,7 @@ void gtk_file_info_set_size (GtkFileInfo *in
void gtk_file_info_set_icon_name (GtkFileInfo *info,
const gchar *con_name);
+G_CONST_RETURN gchar *gtk_file_info_get_icon_name (const GtkFileInfo *info);
GdkPixbuf *gtk_file_info_render_icon (const GtkFileInfo *info,
GtkWidget *widget,
gint pixel_size,
@@ -214,10 +215,8 @@ struct _GtkFileSystemIface
gpointer data);
char * (*volume_get_display_name) (GtkFileSystem *file_system,
GtkFileSystemVolume *volume);
- GdkPixbuf * (*volume_render_icon) (GtkFileSystem *file_system,
+ gchar * (*volume_get_icon_name) (GtkFileSystem *file_system,
GtkFileSystemVolume *volume,
- GtkWidget *widget,
- gint pixel_size,
GError **error);
/* Path Manipulation
@@ -294,6 +293,9 @@ GdkPixbuf * gtk_file_system_volume_render_icon (GtkFileSystem
GtkWidget *widget,
gint pixel_size,
GError **error);
+gchar * gtk_file_system_volume_get_icon_name (GtkFileSystem *file_system,
+ GtkFileSystemVolume *volume,
+ GError **error);
gboolean gtk_file_system_get_parent (GtkFileSystem *file_system,
const GtkFilePath *path,
diff --git a/gtk/gtkfilesystemunix.c b/gtk/gtkfilesystemunix.c
index b222472a40..739c52f61c 100644
--- a/gtk/gtkfilesystemunix.c
+++ b/gtk/gtkfilesystemunix.c
@@ -172,10 +172,8 @@ static GtkFileSystemHandle *gtk_file_system_unix_volume_mount (GtkFileSystem
gpointer data);
static gchar * gtk_file_system_unix_volume_get_display_name (GtkFileSystem *file_system,
GtkFileSystemVolume *volume);
-static GdkPixbuf * gtk_file_system_unix_volume_render_icon (GtkFileSystem *file_system,
+static gchar * gtk_file_system_unix_volume_get_icon_name (GtkFileSystem *file_system,
GtkFileSystemVolume *volume,
- GtkWidget *widget,
- gint pixel_size,
GError **error);
static gboolean gtk_file_system_unix_get_parent (GtkFileSystem *file_system,
@@ -348,7 +346,7 @@ gtk_file_system_unix_iface_init (GtkFileSystemIface *iface)
iface->volume_get_is_mounted = gtk_file_system_unix_volume_get_is_mounted;
iface->volume_mount = gtk_file_system_unix_volume_mount;
iface->volume_get_display_name = gtk_file_system_unix_volume_get_display_name;
- iface->volume_render_icon = gtk_file_system_unix_volume_render_icon;
+ iface->volume_get_icon_name = gtk_file_system_unix_volume_get_icon_name;
iface->get_parent = gtk_file_system_unix_get_parent;
iface->make_path = gtk_file_system_unix_make_path;
iface->parse = gtk_file_system_unix_parse;
@@ -1136,75 +1134,6 @@ get_icon_type (const char *filename,
return get_icon_type_from_stat (&statbuf);
}
-typedef struct
-{
- gint size;
- GdkPixbuf *pixbuf;
-} IconCacheElement;
-
-static void
-icon_cache_element_free (IconCacheElement *element)
-{
- if (element->pixbuf)
- g_object_unref (element->pixbuf);
- g_free (element);
-}
-
-static void
-icon_theme_changed (GtkIconTheme *icon_theme)
-{
- GHashTable *cache;
-
- /* Difference from the initial creation is that we don't
- * reconnect the signal
- */
- cache = g_hash_table_new_full (g_str_hash, g_str_equal,
- (GDestroyNotify)g_free,
- (GDestroyNotify)icon_cache_element_free);
- g_object_set_data_full (G_OBJECT (icon_theme), I_("gtk-file-icon-cache"),
- cache, (GDestroyNotify)g_hash_table_destroy);
-}
-
-static GdkPixbuf *
-get_cached_icon (GtkWidget *widget,
- const gchar *name,
- gint pixel_size)
-{
- GtkIconTheme *icon_theme = gtk_icon_theme_get_for_screen (gtk_widget_get_screen (widget));
- GHashTable *cache = g_object_get_data (G_OBJECT (icon_theme), "gtk-file-icon-cache");
- IconCacheElement *element;
-
- if (!cache)
- {
- cache = g_hash_table_new_full (g_str_hash, g_str_equal,
- (GDestroyNotify)g_free,
- (GDestroyNotify)icon_cache_element_free);
-
- g_object_set_data_full (G_OBJECT (icon_theme), I_("gtk-file-icon-cache"),
- cache, (GDestroyNotify)g_hash_table_destroy);
- g_signal_connect (icon_theme, "changed",
- G_CALLBACK (icon_theme_changed), NULL);
- }
-
- element = g_hash_table_lookup (cache, name);
- if (!element)
- {
- element = g_new0 (IconCacheElement, 1);
- g_hash_table_insert (cache, g_strdup (name), element);
- }
-
- if (element->size != pixel_size)
- {
- if (element->pixbuf)
- g_object_unref (element->pixbuf);
- element->size = pixel_size;
- element->pixbuf = gtk_icon_theme_load_icon (icon_theme, name,
- pixel_size, 0, NULL);
- }
-
- return element->pixbuf ? g_object_ref (element->pixbuf) : NULL;
-}
-
/* Renders a fallback icon from the stock system */
static const gchar *
get_fallback_icon_name (IconType icon_type)
@@ -1233,44 +1162,13 @@ get_fallback_icon_name (IconType icon_type)
return stock_name;
}
-static GdkPixbuf *
-get_fallback_icon (GtkWidget *widget,
- IconType icon_type,
- GError **error)
-{
- const char *name;
- GdkPixbuf *pixbuf;
-
- name = get_fallback_icon_name (icon_type);
-
- pixbuf = gtk_widget_render_icon (widget, name, GTK_ICON_SIZE_SMALL_TOOLBAR, NULL);
- if (!pixbuf)
- g_set_error (error,
- GTK_FILE_SYSTEM_ERROR,
- GTK_FILE_SYSTEM_ERROR_FAILED,
- _("Could not get a stock icon for %s"),
- name);
-
- return pixbuf;
-}
-
-static GdkPixbuf *
-gtk_file_system_unix_volume_render_icon (GtkFileSystem *file_system,
- GtkFileSystemVolume *volume,
- GtkWidget *widget,
- gint pixel_size,
- GError **error)
+static gchar *
+gtk_file_system_unix_volume_get_icon_name (GtkFileSystem *file_system,
+ GtkFileSystemVolume *volume,
+ GError **error)
{
- GdkPixbuf *pixbuf;
-
- pixbuf = get_cached_icon (widget, "gnome-dev-harddisk", pixel_size);
- if (pixbuf)
- return pixbuf;
-
- pixbuf = get_fallback_icon (widget, ICON_BLOCK_DEVICE, error);
- g_assert (pixbuf != NULL);
-
- return pixbuf;
+ /* FIXME: maybe we just always want to return GTK_STOCK_HARDDISK here */
+ return g_strdup ("gnome-dev-harddisk");
}
static char *