summaryrefslogtreecommitdiff
path: root/thunar/thunar-file.c
diff options
context:
space:
mode:
authorBenedikt Meurer <benny@xfce.org>2005-06-05 11:31:09 +0000
committerBenedikt Meurer <benny@xfce.org>2005-06-05 11:31:09 +0000
commit639311c95bfc6bffc282890b44ac6cca5c7d596d (patch)
treed2995be52a02b72c35544ef4e6ecccde89941439 /thunar/thunar-file.c
parentfbb5452f0c186dcd9f0b19afff618828acd9ec94 (diff)
downloadthunar-639311c95bfc6bffc282890b44ac6cca5c7d596d.tar.gz
2005-06-05 Benedikt Meurer <benny@xfce.org>
* thunar/thunar-favourites-model.c(thunar_favourites_model_get_value): The display_name's of ThunarFile's can be considered static (as the name cannot change during the ThunarFile's life-time), so we don't need to take a copy here. * thunar/thunar-list-model.c(thunar_list_model_get_value): Same here, the ThunarFile's display_name is static. * thunar/thunar-file.c: Add the simple caching on the ThunarFile level. If a ThunarFile for the same ThunarVfsURI is requested multiple times, the same ThunarFile instance will be used, instead of allocating a new one. Future versions will extend this scheme using a smarter caching mechanism. * thunar/thunar-side-pane.{c,h}: Add implementation for the ThunarSidePane interface, which is to be implemented by all widgets that can be placed on the right side. The interface currently includes only the "current-directory" property, which is the most important communication mechanism. We'll need some way to pass in other per-window settings here (e.g. "show-hidden" and such). Hopefully somebody will pick up the preferences task soon. * thunar/thunar-favourites-model.{c,h}, thunar/thunar-favourites-view.{c,h}, thunar/thunar-favourites-pane.{c,h}: More work on the ThunarFavourites module. The ThunarFavouritesPane class implements the ThunarSidePane interface and acts as a bridge to the underlying ThunarFavouritesView. * thunar/thunar-window.c: Test the new ThunarFavouritesPane class. * thunar/Makefile.am: Add the new classes to the build framework. (Old svn revision: 16317)
Diffstat (limited to 'thunar/thunar-file.c')
-rw-r--r--thunar/thunar-file.c46
1 files changed, 32 insertions, 14 deletions
diff --git a/thunar/thunar-file.c b/thunar/thunar-file.c
index 4864bc05..2db7b853 100644
--- a/thunar/thunar-file.c
+++ b/thunar/thunar-file.c
@@ -54,6 +54,7 @@ static void thunar_file_get_property (GObject *object,
static GObjectClass *parent_class;
+static GHashTable *file_cache;
static guint file_signals[LAST_SIGNAL];
@@ -152,11 +153,14 @@ thunar_file_finalize (GObject *object)
g_object_unref (G_OBJECT (file->mime_info));
/* reset the vfs info (freeing the specific data) */
- //thunar_vfs_info_drop_from_cache (&file->info);
thunar_vfs_info_reset (&file->info);
g_free (file->display_name);
+ /* drop this ThunarFile from the cache */
+ if (G_LIKELY (file->info.uri != NULL))
+ g_hash_table_remove (file_cache, file->info.uri);
+
G_OBJECT_CLASS (parent_class)->finalize (object);
}
@@ -216,24 +220,38 @@ thunar_file_get_for_uri (ThunarVfsURI *uri,
g_return_val_if_fail (THUNAR_VFS_IS_URI (uri), NULL);
- /* allocate the new file object */
- file = g_object_new (THUNAR_TYPE_FILE, NULL);
- file->display_name = thunar_vfs_uri_get_display_name (uri);
+ /* allocate the ThunarFile cache on-demand */
+ if (G_UNLIKELY (file_cache == NULL))
+ file_cache = g_hash_table_new (thunar_vfs_uri_hash, thunar_vfs_uri_equal);
+
+ /* check if we have the corresponding file cached already */
+ file = g_hash_table_lookup (file_cache, uri);
+ if (file == NULL)
+ {
+ /* allocate the new file object */
+ file = g_object_new (THUNAR_TYPE_FILE, NULL);
+ file->display_name = thunar_vfs_uri_get_display_name (uri);
+
+ /* drop the floating reference */
+ g_object_ref (G_OBJECT (file));
+ gtk_object_sink (GTK_OBJECT (file));
- /* drop the floating reference */
- g_object_ref (G_OBJECT (file));
- gtk_object_sink (GTK_OBJECT (file));
+ /* query the file info */
+ if (!thunar_vfs_info_query (&file->info, uri, error))
+ {
+ g_object_unref (G_OBJECT (file));
+ return NULL;
+ }
- /* query the file info */
- if (!thunar_vfs_info_query (&file->info, uri, error))
+ /* insert the file into the cache */
+ g_hash_table_insert (file_cache, uri, file);
+ }
+ else
{
- g_object_unref (G_OBJECT (file));
- return NULL;
+ /* take another reference on the cached file */
+ g_object_ref (G_OBJECT (file));
}
- /* watch this file for changes */
- //thunar_vfs_info_add_to_cache (&file->info);
-
return file;
}