[Xfce4-commits] r29766 - in thunar/branches/migration-to-gio: . thunar

Jannis Pohlmann jannis at xfce.org
Sat Apr 11 21:10:12 CEST 2009


Author: jannis
Date: 2009-04-11 19:10:11 +0000 (Sat, 11 Apr 2009)
New Revision: 29766

Modified:
   thunar/branches/migration-to-gio/ChangeLog
   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-window.c
Log:
	* thunar/thunar-file.{c,h}: Add new function thunar_file_get(GFile*).
	  Internally this still uses thunar_file_load() and can thus block the
	  UI. For the sake of a smoother transition, asynchronous loading will
	  be implemented at a later stage.
	* thunar/thunar-window.c: Re-implement thunar_window_open_home() based
	  on thunar_file_get().

Modified: thunar/branches/migration-to-gio/ChangeLog
===================================================================
--- thunar/branches/migration-to-gio/ChangeLog	2009-04-11 18:51:09 UTC (rev 29765)
+++ thunar/branches/migration-to-gio/ChangeLog	2009-04-11 19:10:11 UTC (rev 29766)
@@ -1,5 +1,14 @@
 2009-04-11	Jannis Pohlmann <jannis at xfce.org>
 
+	* thunar/thunar-file.{c,h}: Add new function thunar_file_get(GFile*).
+	  Internally this still uses thunar_file_load() and can thus block the
+	  UI. For the sake of a smoother transition, asynchronous loading will
+	  be implemented at a later stage.
+	* thunar/thunar-window.c: Re-implement thunar_window_open_home() based
+	  on thunar_file_get(). 
+
+2009-04-11	Jannis Pohlmann <jannis at xfce.org>
+
 	* thunar/thunar-file.c: Tweak thunar_file_is_desktop() a little bit.
 	* thunar/thunar-window.c: Re-implement
 	  thunar_window_setup_user_dir_menu_entries() based on GFile. Remove

Modified: thunar/branches/migration-to-gio/thunar/thunar-file.c
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-file.c	2009-04-11 18:51:09 UTC (rev 29765)
+++ thunar/branches/migration-to-gio/thunar/thunar-file.c	2009-04-11 19:10:11 UTC (rev 29766)
@@ -564,6 +564,68 @@
 
 
 /**
+ * thunar_file_get:
+ * @file  : a #GFile.
+ * @error : return location for errors.
+ *
+ * Looks up the #ThunarFile referred to by @file.
+ *
+ * The caller is responsible to call g_object_unref()
+ * when done with the returned object.
+ *
+ * Return value: the #ThunarFile for @file or %NULL on errors.
+ **/
+ThunarFile*
+thunar_file_get (GFile   *gfile,
+                 GError **error)
+{
+  ThunarVfsInfo *info;
+  ThunarVfsPath *path;
+  ThunarFile    *file;
+  gchar         *uri;
+
+  _thunar_return_val_if_fail (G_IS_FILE (gfile), NULL);
+
+  /* check if we already have a cached version of that file */
+  file = thunar_file_cache_lookup (gfile);
+  if (G_UNLIKELY (file != NULL))
+    {
+      /* take a reference for the caller */
+      g_object_ref (G_OBJECT (file));
+    }
+  else
+    {
+      uri = g_file_get_uri (file->gfile);
+      path = thunar_vfs_path_new (uri, error);
+      g_free (uri);
+
+      if (G_UNLIKELY (path == NULL))
+        return NULL;
+
+      info = thunar_vfs_info_new_for_path (path, error);
+      thunar_vfs_path_unref (path);
+
+      if (G_UNLIKELY (info == NULL))
+        return NULL;
+
+      /* allocate a new object */
+      file = g_object_new (THUNAR_TYPE_FILE, NULL);
+      file->gfile = g_object_ref (gfile);
+      file->ginfo = NULL;
+      file->info = info;
+
+      thunar_file_load (file, NULL, error);
+
+      /* insert the file into the cache */
+      g_hash_table_insert (file_cache, g_object_ref (file->gfile), file);
+    }
+
+  return file;
+}
+
+
+
+/**
  * thunar_file_get_for_info:
  * @info : a #ThunarVfsInfo.
  *
@@ -624,6 +686,7 @@
 
       file->gfile = g_object_ref (gfile);
       file->ginfo = NULL;
+
       thunar_file_load (file, NULL, NULL);
 
       /* insert the file into the cache */

Modified: thunar/branches/migration-to-gio/thunar/thunar-file.h
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-file.h	2009-04-11 18:51:09 UTC (rev 29765)
+++ thunar/branches/migration-to-gio/thunar/thunar-file.h	2009-04-11 19:10:11 UTC (rev 29766)
@@ -143,6 +143,8 @@
 
 GType             thunar_file_get_type             (void) G_GNUC_CONST;
 
+ThunarFile       *thunar_file_get                  (GFile                  *file,
+                                                    GError                **error);
 ThunarFile       *thunar_file_get_for_info         (ThunarVfsInfo          *info);
 ThunarFile       *thunar_file_get_for_path         (ThunarVfsPath          *path,
                                                     GError                **error);

Modified: thunar/branches/migration-to-gio/thunar/thunar-window.c
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-window.c	2009-04-11 18:51:09 UTC (rev 29765)
+++ thunar/branches/migration-to-gio/thunar/thunar-window.c	2009-04-11 19:10:11 UTC (rev 29766)
@@ -1863,7 +1863,7 @@
 thunar_window_action_open_home (GtkAction    *action,
                                 ThunarWindow *window)
 {
-  ThunarVfsPath *home_path;
+  GFile         *home;
   ThunarFile    *home_file;
   GError        *error = NULL;
 
@@ -1871,10 +1871,10 @@
   _thunar_return_if_fail (THUNAR_IS_WINDOW (window));
 
   /* determine the path to the home directory */
-  home_path = thunar_vfs_path_get_for_home ();
+  home = g_file_new_for_home ();
 
   /* determine the file for the home directory */
-  home_file = thunar_file_get_for_path (home_path, &error);
+  home_file = thunar_file_get (home, &error);
   if (G_UNLIKELY (home_file == NULL))
     {
       /* display an error to the user */
@@ -1889,7 +1889,7 @@
     }
 
   /* release our reference on the home path */
-  thunar_vfs_path_unref (home_path);
+  g_object_unref (home);
 }
 
 gboolean




More information about the Xfce4-commits mailing list