[Xfce4-commits] r29756 - in thunar/branches/migration-to-gio: . thunar
Jannis Pohlmann
jannis at xfce.org
Fri Apr 10 22:32:32 CEST 2009
Author: jannis
Date: 2009-04-10 20:32:31 +0000 (Fri, 10 Apr 2009)
New Revision: 29756
Modified:
thunar/branches/migration-to-gio/ChangeLog
thunar/branches/migration-to-gio/thunar/thunar-dnd.c
thunar/branches/migration-to-gio/thunar/thunar-file.c
thunar/branches/migration-to-gio/thunar/thunar-file.h
thunar/branches/migration-to-gio/thunar/thunar-standard-view.c
thunar/branches/migration-to-gio/thunar/thunar-tree-view.c
thunar/branches/migration-to-gio/thunar/thunar-window.c
Log:
* thunar/thunar-dnd.c, thunar/thunar-standard-view.c,
thunar/thunar-tree-view.c, thunar/thunar-window.c: Use
thunar_file_cache_lookup_path() instead of
thunar_file_cache_lookup().
* thunar/thunar-file.{c,h}: Add new function thunar_file_load() for
loading the GFileInfo of a ThunarFile synchronously. Use it in
thunar_file_get_for_info() to load GIO data for a ThunarFile in
addition to ThunarVFS information. Use GFile for the keys of the
file cache and change the function signature of
thunar_file_cache_lookup(). Add thunar_file_cache_lookup_path() for
a smoother transition.
Modified: thunar/branches/migration-to-gio/ChangeLog
===================================================================
--- thunar/branches/migration-to-gio/ChangeLog 2009-04-10 19:42:52 UTC (rev 29755)
+++ thunar/branches/migration-to-gio/ChangeLog 2009-04-10 20:32:31 UTC (rev 29756)
@@ -1,5 +1,19 @@
2009-04-10 Jannis Pohlmann <jannis at xfce.org>
+ * thunar/thunar-dnd.c, thunar/thunar-standard-view.c,
+ thunar/thunar-tree-view.c, thunar/thunar-window.c: Use
+ thunar_file_cache_lookup_path() instead of
+ thunar_file_cache_lookup().
+ * thunar/thunar-file.{c,h}: Add new function thunar_file_load() for
+ loading the GFileInfo of a ThunarFile synchronously. Use it in
+ thunar_file_get_for_info() to load GIO data for a ThunarFile in
+ addition to ThunarVFS information. Use GFile for the keys of the
+ file cache and change the function signature of
+ thunar_file_cache_lookup(). Add thunar_file_cache_lookup_path() for
+ a smoother transition.
+
+2009-04-10 Jannis Pohlmann <jannis at xfce.org>
+
* thunar/thunar-gio-extensions.c: Remove unused variable in
g_file_list_new_from_string().
Modified: thunar/branches/migration-to-gio/thunar/thunar-dnd.c
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-dnd.c 2009-04-10 19:42:52 UTC (rev 29755)
+++ thunar/branches/migration-to-gio/thunar/thunar-dnd.c 2009-04-10 20:32:31 UTC (rev 29756)
@@ -124,7 +124,7 @@
for (lp = path_list; lp != NULL; lp = lp->next)
{
/* try to resolve this path */
- file = thunar_file_cache_lookup (lp->data);
+ file = thunar_file_cache_lookup_path (lp->data);
if (G_LIKELY (file != NULL))
file_list = g_list_prepend (file_list, file);
else
Modified: thunar/branches/migration-to-gio/thunar/thunar-file.c
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-file.c 2009-04-10 19:42:52 UTC (rev 29755)
+++ thunar/branches/migration-to-gio/thunar/thunar-file.c 2009-04-10 20:32:31 UTC (rev 29756)
@@ -44,6 +44,8 @@
#include <unistd.h>
#endif
+#include <gio/gio.h>
+
#include <thunar/thunar-application.h>
#include <thunar/thunar-chooser-dialog.h>
#include <thunar/thunar-file.h>
@@ -54,6 +56,18 @@
+/* File attribute namespaces being used */
+#define THUNAR_FILE_G_FILE_INFO_NAMESPACE \
+ "standard::*," \
+ "unix::*," \
+ "access::*," \
+ "time::*"
+
+#define THUNAR_FILE_G_FILE_INFO_FILESYSTEM_NAMESPACE \
+ "filesystem::*"
+
+
+
/* Additional flags associated with a ThunarFile */
#define THUNAR_FILE_IN_DESTRUCTION 0x04
#define THUNAR_FILE_OWNS_METAFILE_REFERENCE 0x08
@@ -291,12 +305,16 @@
#endif
/* drop the entry from the cache */
- g_hash_table_remove (file_cache, file->info->path);
+ g_hash_table_remove (file_cache, file->gfile);
/* drop a reference on the metadata if we own one */
if ((file->flags & THUNAR_FILE_OWNS_METAFILE_REFERENCE) != 0)
g_object_unref (G_OBJECT (metafile));
+ /* release GIO data */
+ g_object_unref (file->ginfo);
+ g_object_unref (file->gfile);
+
/* release the file info */
thunar_vfs_info_unref (file->info);
@@ -591,11 +609,17 @@
thunar_file_get_for_info (ThunarVfsInfo *info)
{
ThunarFile *file;
+ GFile *gfile;
+ gchar *uri;
_thunar_return_val_if_fail (info != NULL, NULL);
+ uri = thunar_vfs_path_dup_uri (info->path);
+ gfile = g_file_new_for_uri (uri);
+ g_free (uri);
+
/* check if we already have a cached version of that file */
- file = thunar_file_cache_lookup (info->path);
+ file = thunar_file_cache_lookup (gfile);
if (G_UNLIKELY (file != NULL))
{
/* take a reference for the caller */
@@ -605,7 +629,16 @@
if (!thunar_vfs_info_matches (file->info, info))
{
thunar_vfs_info_unref (file->info);
+
+ g_object_unref (file->gfile);
+ g_object_unref (file->ginfo);
+
file->info = thunar_vfs_info_ref (info);
+
+ file->gfile = g_object_ref (gfile);
+ file->ginfo = NULL;
+ thunar_file_load (file, NULL, NULL);
+
thunar_file_changed (file);
}
}
@@ -615,10 +648,16 @@
file = g_object_new (THUNAR_TYPE_FILE, NULL);
file->info = thunar_vfs_info_ref (info);
+ file->gfile = g_object_ref (gfile);
+ file->ginfo = NULL;
+ thunar_file_load (file, NULL, NULL);
+
/* insert the file into the cache */
- g_hash_table_insert (file_cache, thunar_vfs_path_ref (info->path), file);
+ g_hash_table_insert (file_cache, g_object_ref (file->gfile), file);
}
+ g_object_unref (gfile);
+
return file;
}
@@ -646,11 +685,19 @@
{
ThunarVfsInfo *info;
ThunarFile *file;
+ GFile *gfile;
+ gchar *uri;
_thunar_return_val_if_fail (error == NULL || *error == NULL, NULL);
+ uri = thunar_vfs_path_dup_uri (path);
+ gfile = g_file_new_for_uri (uri);
+ g_free (uri);
+
/* see if we have the corresponding file cached already */
- file = thunar_file_cache_lookup (path);
+ file = thunar_file_cache_lookup (gfile);
+ g_object_unref (gfile);
+
if (file == NULL)
{
/* determine the file info */
@@ -716,6 +763,42 @@
/**
+ * thunar_file_load:
+ * @file : a #ThunarFile.
+ * @cancellable : a #GCancellable.
+ * @error : return location for errors or %NULL.
+ *
+ * Loads all information about the file. As this is a possibly
+ * blocking call, it can be cancelled using @cancellable.
+ *
+ * If loading the file fails or the operation is cancelled,
+ * @error will be set.
+ *
+ * Return value: %TRUE on success, %FALSE on error or interruption.
+ **/
+gboolean
+thunar_file_load (ThunarFile *file,
+ GCancellable *cancellable,
+ GError **error)
+{
+ _thunar_return_val_if_fail (THUNAR_IS_FILE (file), FALSE);
+ _thunar_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+ _thunar_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), FALSE);
+
+ if (file->ginfo != NULL)
+ g_object_unref (file->ginfo);
+
+ file->ginfo = g_file_query_info (file->gfile,
+ THUNAR_FILE_G_FILE_INFO_NAMESPACE ","
+ THUNAR_FILE_G_FILE_INFO_FILESYSTEM_NAMESPACE,
+ G_FILE_QUERY_INFO_NONE,
+ cancellable,
+ error);
+
+ return (file->ginfo != NULL);
+}
+
+/**
* thunar_file_get_parent:
* @file : a #ThunarFile instance.
* @error : return location for errors.
@@ -1033,7 +1116,7 @@
break;
/* determine the cached version of the source file */
- ofile = thunar_file_cache_lookup (lp->data);
+ ofile = thunar_file_cache_lookup_path (lp->data);
/* we have only move if we know the source and both the source and the target
* are on the same disk, and the source file is owned by the current user.
@@ -2054,6 +2137,41 @@
/**
* thunar_file_cache_lookup:
+ * @file : a #GFile.
+ *
+ * Looks up the #ThunarFile for @file in the internal file
+ * cache and returns the file present for @file in the
+ * cache or %NULL if no #ThunarFile is cached for @file.
+ *
+ * Note that no reference is taken for the caller.
+ *
+ * This method should not be used but in very rare cases.
+ * Consider using thunar_file_get() instead.
+ *
+ * Return value: the #ThunarFile for @file in the internal
+ * cache, or %NULL.
+ **/
+ThunarFile *
+thunar_file_cache_lookup (const GFile *file)
+{
+ _thunar_return_val_if_fail (G_IS_FILE (file), NULL);
+
+ /* allocate the ThunarFile cache on-demand */
+ if (G_UNLIKELY (file_cache == NULL))
+ {
+ file_cache = g_hash_table_new_full (g_file_hash,
+ (GEqualFunc) g_file_equal,
+ (GDestroyNotify) g_object_unref,
+ NULL);
+ }
+
+ return g_hash_table_lookup (file_cache, file);
+}
+
+
+
+/**
+ * thunar_file_cache_lookup_path:
* @path : a #ThunarVfsPath.
*
* Looks up the #ThunarFile for @path in the internal file
@@ -2063,19 +2181,36 @@
* Note that no reference is taken for the caller.
*
* This method should not be used but in very rare cases.
- * Consider using thunar_file_get_for_path() instead.
+ * Consider using thunar_file_get() instead.
*
* Return value: the #ThunarFile for @path in the internal
* cache, or %NULL.
**/
-ThunarFile*
-thunar_file_cache_lookup (const ThunarVfsPath *path)
+ThunarFile *
+thunar_file_cache_lookup_path (const ThunarVfsPath *path)
{
+ ThunarFile *file;
+ GFile *gfile;
+ gchar *uri;
+
+ _thunar_return_val_if_fail (path != NULL, NULL);
+
+ uri = thunar_vfs_path_dup_uri (path);
+ gfile = g_file_new_for_uri (uri);
+ g_free (uri);
+
/* allocate the ThunarFile cache on-demand */
if (G_UNLIKELY (file_cache == NULL))
- file_cache = g_hash_table_new_full (thunar_vfs_path_hash, thunar_vfs_path_equal, (GDestroyNotify) thunar_vfs_path_unref, NULL);
+ {
+ file_cache = g_hash_table_new_full (g_file_hash,
+ (GEqualFunc) g_file_equal,
+ (GDestroyNotify) g_object_unref,
+ NULL);
+ }
- return g_hash_table_lookup (file_cache, path);
+ file = g_hash_table_lookup (file_cache, gfile);
+ g_object_unref (gfile);
+ return file;
}
Modified: thunar/branches/migration-to-gio/thunar/thunar-file.h
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-file.h 2009-04-10 19:42:52 UTC (rev 29755)
+++ thunar/branches/migration-to-gio/thunar/thunar-file.h 2009-04-10 20:32:31 UTC (rev 29756)
@@ -109,7 +109,9 @@
/*< private >*/
ThunarVfsInfo *info;
- guint flags;
+ GFileInfo *ginfo;
+ GFile *gfile;
+ guint flags;
};
GType thunar_file_get_type (void) G_GNUC_CONST;
@@ -120,6 +122,10 @@
ThunarFile *thunar_file_get_for_uri (const gchar *uri,
GError **error);
+gboolean thunar_file_load (ThunarFile *file,
+ GCancellable *cancellable,
+ GError **error);
+
ThunarFile *thunar_file_get_parent (const ThunarFile *file,
GError **error);
@@ -198,7 +204,8 @@
gboolean case_sensitive);
-ThunarFile *thunar_file_cache_lookup (const ThunarVfsPath *path);
+ThunarFile *thunar_file_cache_lookup (const GFile *file);
+ThunarFile *thunar_file_cache_lookup_path (const ThunarVfsPath *path);
GList *thunar_file_list_get_applications (GList *file_list);
Modified: thunar/branches/migration-to-gio/thunar/thunar-standard-view.c
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-standard-view.c 2009-04-10 19:42:52 UTC (rev 29755)
+++ thunar/branches/migration-to-gio/thunar/thunar-standard-view.c 2009-04-10 20:32:31 UTC (rev 29756)
@@ -2321,7 +2321,7 @@
/* determine the files for the paths */
for (lp = path_list; lp != NULL; lp = lp->next)
{
- file = thunar_file_cache_lookup (lp->data);
+ file = thunar_file_cache_lookup_path (lp->data);
if (G_LIKELY (file != NULL))
file_list = g_list_prepend (file_list, file);
}
Modified: thunar/branches/migration-to-gio/thunar/thunar-tree-view.c
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-tree-view.c 2009-04-10 19:42:52 UTC (rev 29755)
+++ thunar/branches/migration-to-gio/thunar/thunar-tree-view.c 2009-04-10 20:32:31 UTC (rev 29756)
@@ -1909,7 +1909,7 @@
return;
/* determine the file for the first path */
- file = thunar_file_cache_lookup (path_list->data);
+ file = thunar_file_cache_lookup_path (path_list->data);
if (G_LIKELY (file != NULL && thunar_file_is_directory (file)))
{
/* change to the newly created folder */
Modified: thunar/branches/migration-to-gio/thunar/thunar-window.c
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-window.c 2009-04-10 19:42:52 UTC (rev 29755)
+++ thunar/branches/migration-to-gio/thunar/thunar-window.c 2009-04-10 20:32:31 UTC (rev 29756)
@@ -2424,7 +2424,7 @@
return;
/* check if a ThunarFile is known for the mount point */
- file = thunar_file_cache_lookup (path);
+ file = thunar_file_cache_lookup_path (path);
if (G_UNLIKELY (file == NULL))
return;
More information about the Xfce4-commits
mailing list