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

Jannis Pohlmann jannis at xfce.org
Fri Apr 10 23:14:07 CEST 2009


Author: jannis
Date: 2009-04-10 21:14:07 +0000 (Fri, 10 Apr 2009)
New Revision: 29757

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-gio-extensions.c
   thunar/branches/migration-to-gio/thunar/thunar-gio-extensions.h
   thunar/branches/migration-to-gio/thunar/thunar-launcher.c
   thunar/branches/migration-to-gio/thunar/thunar-location-buttons.c
   thunar/branches/migration-to-gio/thunar/thunar-properties-dialog.c
   thunar/branches/migration-to-gio/thunar/thunar-shortcuts-view.c
   thunar/branches/migration-to-gio/thunar/thunar-standard-view.c
   thunar/branches/migration-to-gio/thunar/thunar-tree-model.c
   thunar/branches/migration-to-gio/thunar/thunar-tree-view.c
   thunar/branches/migration-to-gio/thunar/thunar-window.c
Log:
	* thunar/thunar-file.{c,h}: Use GFile in thunar_file_atexit_foreach().
	  When finalizing, creating or loading a ThunarFile, check whether the
	  GFileInfo is NULL before unref'ing it. Use the GFile member instead
	  of the ThunarVfsPath in thunar_file_rename(). Tweak
	  thunar_file_accepts_drop() so that it converts the ThunarVfsPath
	  elements of the path list into GFile objects for everything. This
	  will make the transition away from ThunarVfsPath easier later.
	  Rewrite thunar_file_is_trashed() so that it uses
	  g_file_is_trashed().
	* thunar/thunar-gio-extensions.{c,h}: Add new function
	  g_file_is_trashed() which checks whether a GFile resides in the
	  trash.
	* thunar/thunar-launcher.c, thunar/thunar-location-buttons.c,
	  thunar/thunar-properties-dialog.c, thunar/thunar-shortcuts-view.c,
	  thunar/thunar-standard-view.c, thunar/thunar-tree-model.c,
	  thunar/thunar-tree-view.c, thunar/thunar-window.c: Include
	  thunar-gio-extensions.h to compile with thunar_file_is_trashed().

Modified: thunar/branches/migration-to-gio/ChangeLog
===================================================================
--- thunar/branches/migration-to-gio/ChangeLog	2009-04-10 20:32:31 UTC (rev 29756)
+++ thunar/branches/migration-to-gio/ChangeLog	2009-04-10 21:14:07 UTC (rev 29757)
@@ -1,5 +1,25 @@
 2009-04-10	Jannis Pohlmann <jannis at xfce.org>
 
+	* thunar/thunar-file.{c,h}: Use GFile in thunar_file_atexit_foreach().
+	  When finalizing, creating or loading a ThunarFile, check whether the
+	  GFileInfo is NULL before unref'ing it. Use the GFile member instead
+	  of the ThunarVfsPath in thunar_file_rename(). Tweak
+	  thunar_file_accepts_drop() so that it converts the ThunarVfsPath
+	  elements of the path list into GFile objects for everything. This
+	  will make the transition away from ThunarVfsPath easier later.
+	  Rewrite thunar_file_is_trashed() so that it uses
+	  g_file_is_trashed().
+	* thunar/thunar-gio-extensions.{c,h}: Add new function
+	  g_file_is_trashed() which checks whether a GFile resides in the
+	  trash.
+	* thunar/thunar-launcher.c, thunar/thunar-location-buttons.c,
+	  thunar/thunar-properties-dialog.c, thunar/thunar-shortcuts-view.c,
+	  thunar/thunar-standard-view.c, thunar/thunar-tree-model.c,
+	  thunar/thunar-tree-view.c, thunar/thunar-window.c: Include
+	  thunar-gio-extensions.h to compile with thunar_file_is_trashed().
+	
+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 

Modified: thunar/branches/migration-to-gio/thunar/thunar-file.c
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-file.c	2009-04-10 20:32:31 UTC (rev 29756)
+++ thunar/branches/migration-to-gio/thunar/thunar-file.c	2009-04-10 21:14:07 UTC (rev 29757)
@@ -50,6 +50,7 @@
 #include <thunar/thunar-chooser-dialog.h>
 #include <thunar/thunar-file.h>
 #include <thunar/thunar-file-monitor.h>
+#include <thunar/thunar-gio-extensions.h>
 #include <thunar/thunar-gobject-extensions.h>
 #include <thunar/thunar-private.h>
 #include <thunar/thunar-util.h>
@@ -180,11 +181,11 @@
                             gpointer value,
                             gpointer user_data)
 {
-  gchar *s;
+  gchar *uri;
 
-  s = thunar_vfs_path_dup_string (key);
-  g_print ("--> %s (%u)\n", s, G_OBJECT (value)->ref_count);
-  g_free (s);
+  uri = g_file_get_uri (key);
+  g_print ("--> %s (%u)\n", uri, G_OBJECT (value)->ref_count);
+  g_free (uri);
 }
 
 static void
@@ -312,7 +313,8 @@
     g_object_unref (G_OBJECT (metafile));
 
   /* release GIO data */
-  g_object_unref (file->ginfo);
+  if (file->ginfo != NULL)
+    g_object_unref (file->ginfo);
   g_object_unref (file->gfile);
 
   /* release the file info */
@@ -630,13 +632,15 @@
         {
           thunar_vfs_info_unref (file->info);
 
+          file->info = thunar_vfs_info_ref (info);
+
           g_object_unref (file->gfile);
-          g_object_unref (file->ginfo);
+          if (file->ginfo != NULL)
+            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);
@@ -786,7 +790,10 @@
   _thunar_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), FALSE);
 
   if (file->ginfo != NULL)
-    g_object_unref (file->ginfo);
+    {
+      g_object_unref (file->ginfo);
+      file->ginfo = NULL;
+    }
 
   file->ginfo = g_file_query_info (file->gfile,
                                    THUNAR_FILE_G_FILE_INFO_NAMESPACE ","
@@ -966,16 +973,16 @@
                     const gchar *name,
                     GError     **error)
 {
-  ThunarVfsPath *previous_path;
-  gboolean       succeed;
-  gint           watch_count;;
+  GFile   *previous_file;
+  gboolean succeed;
+  gint     watch_count;;
 
   _thunar_return_val_if_fail (THUNAR_IS_FILE (file), FALSE);
   _thunar_return_val_if_fail (g_utf8_validate (name, -1, NULL), FALSE);
   _thunar_return_val_if_fail (error == NULL || *error == NULL, FALSE);
 
-  /* remember the previous path */
-  previous_path = thunar_vfs_path_ref (file->info->path);
+  /* remember the previous file */
+  previous_file = g_object_ref (file->gfile);
   
   /* try to rename the file */
   succeed = thunar_vfs_info_rename (file->info, name, error);
@@ -999,10 +1006,10 @@
         }
 
       /* drop the previous entry from the cache */
-      g_hash_table_remove (file_cache, previous_path);
+      g_hash_table_remove (file_cache, previous_file);
 
       /* insert the new entry */
-      g_hash_table_insert (file_cache, thunar_vfs_path_ref (file->info->path), file);
+      g_hash_table_insert (file_cache, g_object_ref (file->gfile), file);
 
       /* tell the associated folder that the file was renamed */
       thunarx_file_info_renamed (THUNARX_FILE_INFO (file));
@@ -1011,8 +1018,8 @@
       thunar_file_changed (file);
     }
 
-  /* drop the reference on the previous path */
-  thunar_vfs_path_unref (previous_path);
+  /* drop the reference on the previous file */
+  g_object_unref (previous_file);
 
   return succeed;
 }
@@ -1043,13 +1050,14 @@
                           GdkDragContext *context,
                           GdkDragAction  *suggested_action_return)
 {
-  ThunarVfsPath *parent_path;
-  ThunarVfsPath *path;
-  GdkDragAction  suggested_action;
-  GdkDragAction  actions;
-  ThunarFile    *ofile;
-  GList         *lp;
-  guint          n;
+  GdkDragAction suggested_action;
+  GdkDragAction actions;
+  ThunarFile   *ofile;
+  GFile        *parent_file;
+  GFile        *gfile;
+  GList        *lp;
+  gchar        *uri;
+  guint         n;
 
   _thunar_return_val_if_fail (THUNAR_IS_FILE (file), 0);
   _thunar_return_val_if_fail (GDK_IS_DRAG_CONTEXT (context), 0);
@@ -1067,11 +1075,8 @@
       /* determine the possible actions */
       actions = context->actions & (GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK | GDK_ACTION_ASK);
 
-      /* determine the path of the file */
-      path = thunar_file_get_path (file);
-
       /* cannot create symbolic links in the trash or copy to the trash */
-      if (thunar_vfs_path_get_scheme (path) == THUNAR_VFS_PATH_SCHEME_TRASH)
+      if (thunar_file_is_trashed (file))
         actions &= ~(GDK_ACTION_COPY | GDK_ACTION_LINK);
 
       /* check up to 100 of the paths (just in case somebody tries to
@@ -1079,23 +1084,35 @@
        */
       for (lp = path_list, n = 0; lp != NULL && n < 100; lp = lp->next, ++n)
         {
+          uri = thunar_vfs_path_dup_uri (lp->data);
+          gfile = g_file_new_for_uri (uri);
+          g_free (uri);
+
           /* we cannot drop a file on itself */
-          if (G_UNLIKELY (thunar_vfs_path_equal (path, lp->data)))
-            return 0;
+          if (G_UNLIKELY (g_file_equal (file->gfile, gfile)))
+            {
+              g_object_unref (gfile);
+              return 0;
+            }
 
           /* check whether source and destination are the same */
-          parent_path = thunar_vfs_path_get_parent (lp->data);
-          if (G_LIKELY (parent_path != NULL))
+          parent_file = g_file_get_parent (gfile);
+          if (G_LIKELY (parent_file != NULL))
             {
-              if (thunar_vfs_path_equal (path, parent_path))
-                return 0;
+              if (g_file_equal (file->gfile, parent_file))
+                {
+                  g_object_unref (parent_file);
+                  return 0;
+                }
+              else
+                g_object_unref (parent_file);
             }
 
           /* check if both source and target is in the trash */
-          if (G_UNLIKELY (thunar_vfs_path_get_scheme (lp->data) == THUNAR_VFS_PATH_SCHEME_TRASH
-                       && thunar_vfs_path_get_scheme (path) == THUNAR_VFS_PATH_SCHEME_TRASH))
+          if (G_UNLIKELY (g_file_is_trashed (gfile) && thunar_file_is_trashed (file)))
             {
               /* copy/move/link within the trash not possible */
+              g_object_unref (gfile);
               return 0;
             }
         }
@@ -1111,22 +1128,35 @@
           /* check for up to 100 files, for the reason state above */
           for (lp = path_list, n = 0; lp != NULL && n < 100; lp = lp->next, ++n)
             {
+              uri = thunar_vfs_path_dup_uri (lp->data);
+              gfile = g_file_new_for_uri (uri);
+              g_free (uri);
+
               /* dropping from the trash always suggests move */
-              if (G_UNLIKELY (thunar_vfs_path_get_scheme (lp->data) == THUNAR_VFS_PATH_SCHEME_TRASH))
-                break;
+              if (G_UNLIKELY (g_file_is_trashed (gfile)))
+                {
+                  g_object_unref (gfile);
+                  break;
+                }
 
               /* determine the cached version of the source file */
-              ofile = thunar_file_cache_lookup_path (lp->data);
+              ofile = thunar_file_cache_lookup (gfile);
 
               /* 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.
                */
-              if (ofile == NULL || (ofile->info->device != file->info->device) || (ofile->info->uid != effective_user_id))
+              if (ofile == NULL 
+                  || (ofile->info->device != file->info->device) 
+                  || (ofile->info->uid != effective_user_id))
                 {
+                  g_object_unref (gfile);
+
                   /* default to copy and get outa here */
                   suggested_action = GDK_ACTION_COPY;
                   break;
                 }
+
+              g_object_unref (gfile);
             }
         }
     }

Modified: thunar/branches/migration-to-gio/thunar/thunar-file.h
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-file.h	2009-04-10 20:32:31 UTC (rev 29756)
+++ thunar/branches/migration-to-gio/thunar/thunar-file.h	2009-04-10 21:14:07 UTC (rev 29757)
@@ -374,13 +374,13 @@
  * thunar_file_is_trashed:
  * @file : a #ThunarFile instance.
  *
- * Returns %TRUE if @file is a local file with the
- * %THUNAR_VFS_PATH_SCHEME_TRASH scheme.
+ * Returns %TRUE if @file is a local file that resides in 
+ * the trash bin.
  *
  * Return value: %TRUE if @file is in the trash, or
  *               the trash folder itself.
  **/
-#define thunar_file_is_trashed(file) (thunar_vfs_path_get_scheme (thunar_file_get_path ((file))) == THUNAR_VFS_PATH_SCHEME_TRASH)
+#define thunar_file_is_trashed(file) (g_file_is_trashed (THUNAR_FILE (file)->gfile))
 
 /**
  * thunar_file_is_ancestor:

Modified: thunar/branches/migration-to-gio/thunar/thunar-gio-extensions.c
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-gio-extensions.c	2009-04-10 20:32:31 UTC (rev 29756)
+++ thunar/branches/migration-to-gio/thunar/thunar-gio-extensions.c	2009-04-10 21:14:07 UTC (rev 29757)
@@ -26,6 +26,7 @@
 #include <libxfce4util/libxfce4util.h>
 
 #include <thunar/thunar-gio-extensions.h>
+#include <thunar/thunar-private.h>
 
 
 
@@ -69,6 +70,15 @@
 
 
 
+gboolean 
+g_file_is_trashed (GFile *file)
+{
+  _thunar_return_val_if_fail (G_IS_FILE (file), FALSE);
+  return g_file_has_uri_scheme (file, "trash");
+}
+
+
+
 /**
  * g_file_list_new_from_string:
  * @string : a string representation of an URI list.

Modified: thunar/branches/migration-to-gio/thunar/thunar-gio-extensions.h
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-gio-extensions.h	2009-04-10 20:32:31 UTC (rev 29756)
+++ thunar/branches/migration-to-gio/thunar/thunar-gio-extensions.h	2009-04-10 21:14:07 UTC (rev 29757)
@@ -29,6 +29,7 @@
 GFile   *g_file_new_for_trash        (void);
 
 gboolean g_file_is_root              (GFile       *file);
+gboolean g_file_is_trashed           (GFile       *file);
 
 GList   *g_file_list_new_from_string (const gchar *string);
 gchar   *g_file_list_to_string       (GList       *list);

Modified: thunar/branches/migration-to-gio/thunar/thunar-launcher.c
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-launcher.c	2009-04-10 20:32:31 UTC (rev 29756)
+++ thunar/branches/migration-to-gio/thunar/thunar-launcher.c	2009-04-10 21:14:07 UTC (rev 29757)
@@ -31,6 +31,7 @@
 #include <thunar/thunar-application.h>
 #include <thunar/thunar-chooser-dialog.h>
 #include <thunar/thunar-dialogs.h>
+#include <thunar/thunar-gio-extensions.h>
 #include <thunar/thunar-gobject-extensions.h>
 #include <thunar/thunar-gtk-extensions.h>
 #include <thunar/thunar-launcher.h>

Modified: thunar/branches/migration-to-gio/thunar/thunar-location-buttons.c
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-location-buttons.c	2009-04-10 20:32:31 UTC (rev 29756)
+++ thunar/branches/migration-to-gio/thunar/thunar-location-buttons.c	2009-04-10 21:14:07 UTC (rev 29757)
@@ -27,6 +27,7 @@
 #include <thunar/thunar-application.h>
 #include <thunar/thunar-clipboard-manager.h>
 #include <thunar/thunar-create-dialog.h>
+#include <thunar/thunar-gio-extensions.h>
 #include <thunar/thunar-gobject-extensions.h>
 #include <thunar/thunar-gtk-extensions.h>
 #include <thunar/thunar-location-button.h>

Modified: thunar/branches/migration-to-gio/thunar/thunar-properties-dialog.c
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-properties-dialog.c	2009-04-10 20:32:31 UTC (rev 29756)
+++ thunar/branches/migration-to-gio/thunar/thunar-properties-dialog.c	2009-04-10 21:14:07 UTC (rev 29757)
@@ -34,6 +34,7 @@
 #include <thunar/thunar-chooser-button.h>
 #include <thunar/thunar-dialogs.h>
 #include <thunar/thunar-emblem-chooser.h>
+#include <thunar/thunar-gio-extensions.h>
 #include <thunar/thunar-gobject-extensions.h>
 #include <thunar/thunar-gtk-extensions.h>
 #include <thunar/thunar-icon-factory.h>

Modified: thunar/branches/migration-to-gio/thunar/thunar-shortcuts-view.c
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-shortcuts-view.c	2009-04-10 20:32:31 UTC (rev 29756)
+++ thunar/branches/migration-to-gio/thunar/thunar-shortcuts-view.c	2009-04-10 21:14:07 UTC (rev 29757)
@@ -34,6 +34,7 @@
 #include <thunar/thunar-application.h>
 #include <thunar/thunar-dialogs.h>
 #include <thunar/thunar-dnd.h>
+#include <thunar/thunar-gio-extensions.h>
 #include <thunar/thunar-gtk-extensions.h>
 #include <thunar/thunar-preferences.h>
 #include <thunar/thunar-private.h>

Modified: thunar/branches/migration-to-gio/thunar/thunar-standard-view.c
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-standard-view.c	2009-04-10 20:32:31 UTC (rev 29756)
+++ thunar/branches/migration-to-gio/thunar/thunar-standard-view.c	2009-04-10 21:14:07 UTC (rev 29757)
@@ -35,6 +35,7 @@
 #include <thunar/thunar-dialogs.h>
 #include <thunar/thunar-dnd.h>
 #include <thunar/thunar-enum-types.h>
+#include <thunar/thunar-gio-extensions.h>
 #include <thunar/thunar-gobject-extensions.h>
 #include <thunar/thunar-gtk-extensions.h>
 #include <thunar/thunar-icon-renderer.h>

Modified: thunar/branches/migration-to-gio/thunar/thunar-tree-model.c
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-tree-model.c	2009-04-10 20:32:31 UTC (rev 29756)
+++ thunar/branches/migration-to-gio/thunar/thunar-tree-model.c	2009-04-10 21:14:07 UTC (rev 29757)
@@ -30,6 +30,7 @@
 
 #include <thunar/thunar-file-monitor.h>
 #include <thunar/thunar-folder.h>
+#include <thunar/thunar-gio-extensions.h>
 #include <thunar/thunar-pango-extensions.h>
 #include <thunar/thunar-preferences.h>
 #include <thunar/thunar-private.h>

Modified: thunar/branches/migration-to-gio/thunar/thunar-tree-view.c
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-tree-view.c	2009-04-10 20:32:31 UTC (rev 29756)
+++ thunar/branches/migration-to-gio/thunar/thunar-tree-view.c	2009-04-10 21:14:07 UTC (rev 29757)
@@ -28,6 +28,7 @@
 #include <thunar/thunar-create-dialog.h>
 #include <thunar/thunar-dialogs.h>
 #include <thunar/thunar-dnd.h>
+#include <thunar/thunar-gio-extensions.h>
 #include <thunar/thunar-gtk-extensions.h>
 #include <thunar/thunar-marshal.h>
 #include <thunar/thunar-preferences.h>

Modified: thunar/branches/migration-to-gio/thunar/thunar-window.c
===================================================================
--- thunar/branches/migration-to-gio/thunar/thunar-window.c	2009-04-10 20:32:31 UTC (rev 29756)
+++ thunar/branches/migration-to-gio/thunar/thunar-window.c	2009-04-10 21:14:07 UTC (rev 29757)
@@ -36,6 +36,7 @@
 #include <thunar/thunar-details-view.h>
 #include <thunar/thunar-dialogs.h>
 #include <thunar/thunar-shortcuts-pane.h>
+#include <thunar/thunar-gio-extensions.h>
 #include <thunar/thunar-gobject-extensions.h>
 #include <thunar/thunar-gtk-extensions.h>
 #include <thunar/thunar-history.h>




More information about the Xfce4-commits mailing list