[Xfce4-commits] <thunar:migration-to-gio> Add GIO >= 2.18 functions to thunar-gio-extensions.{c, h}.

Jannis Pohlmann jannis at xfce.org
Mon Aug 17 00:50:02 CEST 2009


Updating branch refs/heads/migration-to-gio
         to 6ae73a21b90d35dd024ea248997ba5760f704de2 (commit)
       from 179bced1e1dce8fb4de08462b15630ec6f9f3e40 (commit)

commit 6ae73a21b90d35dd024ea248997ba5760f704de2
Author: Jannis Pohlmann <jannis at xfce.org>
Date:   Mon Aug 17 00:46:29 2009 +0200

    Add GIO >= 2.18 functions to thunar-gio-extensions.{c,h}.
    
    This includes: g_file_monitor(), g_file_query_file_type() and
    g_file_make_directory_with_parents(). Needs testing.

 thunar/thunar-gio-extensions.c    |  113 +++++++++++++++++++++++++++++++++++++
 thunar/thunar-gio-extensions.h    |   73 ++++++++++++++----------
 thunar/thunar-io-scan-directory.c |    1 +
 thunar/thunar-transfer-job.c      |    1 +
 4 files changed, 158 insertions(+), 30 deletions(-)

diff --git a/thunar/thunar-gio-extensions.c b/thunar/thunar-gio-extensions.c
index b0309d7..a8bac83 100644
--- a/thunar/thunar-gio-extensions.c
+++ b/thunar/thunar-gio-extensions.c
@@ -476,3 +476,116 @@ g_mount_is_same_drive (GMount *mount,
 
   return same_drive;
 }
+
+
+
+#if !GLIB_CHECK_VERSION(2,18,0)
+GFileType *
+g_file_query_file_type (GFile              *file, 
+                        GFileQueryInfoFlags flags
+                        GCancellable       *cancellable)
+{
+  GFileInfo *info;
+  GFileType  file_type = G_FILE_TYPE_UNKNOWN;
+
+  _thunar_return_val_if_fail (G_IS_FILE (file), G_FILE_TYPE_UNKNOWN);
+
+  info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_TYPE, flags, 
+                            cancellable, NULL);
+  if (info != NULL)
+    {
+      file_type = g_file_info_get_file_type (info);
+      g_object_unref (info);
+    }
+
+  return file_type;
+}
+
+
+
+GFileMonitor *
+g_file_monitor (GFile            *file,
+	              GFileMonitorFlags flags,
+		            GCancellable     *cancellable,
+		            GError          **error)
+{
+  GFileType file_type;
+
+  _thunar_return_val_if_fail (G_IS_FILE (file), NULL);
+  _thunar_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
+  _thunar_return_val_if_fail (error == NULL || *error == NULL, NULL);
+
+  file_type = g_file_query_file_type (file, G_FILE_QUERY_INFO_NONE, cancelllable);
+
+  if (file_type == G_FILE_TYPE_DIRECTORY)
+    return g_file_monitor_directory (file, flags, cancellable, error);
+  else
+    return g_file_onitor_file (file, flags, cancellable, error);
+}
+
+
+
+/**
+ * Copied from http://git.gnome.org/cgit/glib/plain/gio/gfile.c
+ * Copyright (c) 2006-2007 Red Hat, Inc.
+ * Author: Alexander Larsson <alexl at redhat.com>
+ */
+gboolean
+g_file_make_directory_with_parents (GFile        *file,
+                                    GCancellable *cancellable,
+                                    GError      **error)
+{
+  gboolean result;
+  GFile *parent_file, *work_file;
+  GList *list = NULL, *l;
+  GError *my_error = NULL;
+
+  if (g_cancellable_set_error_if_cancelled (cancellable, error))
+    return FALSE;
+  
+  result = g_file_make_directory (file, cancellable, &my_error);
+  if (result || my_error->code != G_IO_ERROR_NOT_FOUND) 
+    {
+      if (my_error)
+        g_propagate_error (error, my_error);
+      return result;
+    }
+  
+  work_file = file;
+  
+  while (!result && my_error->code == G_IO_ERROR_NOT_FOUND) 
+    {
+      g_clear_error (&my_error);
+    
+      parent_file = g_file_get_parent (work_file);
+      if (parent_file == NULL)
+        break;
+      result = g_file_make_directory (parent_file, cancellable, &my_error);
+    
+      if (!result && my_error->code == G_IO_ERROR_NOT_FOUND)
+        list = g_list_prepend (list, parent_file);
+
+      work_file = parent_file;
+    }
+
+  for (l = list; result && l; l = l->next)
+    {
+      result = g_file_make_directory ((GFile *) l->data, cancellable, &my_error);
+    }
+  
+  /* Clean up */
+  while (list != NULL) 
+    {
+      g_object_unref ((GFile *) list->data);
+      list = g_list_remove (list, list->data);
+    }
+
+  if (!result) 
+    {
+      g_propagate_error (error, my_error);
+      return result;
+    }
+  
+  return g_file_make_directory (file, cancellable, error);
+}
+#endif /* !GLIB_CHECK_VERSION(2,18,0) */
diff --git a/thunar/thunar-gio-extensions.h b/thunar/thunar-gio-extensions.h
index f449548..6cc8fb0 100644
--- a/thunar/thunar-gio-extensions.h
+++ b/thunar/thunar-gio-extensions.h
@@ -24,25 +24,25 @@
 
 G_BEGIN_DECLS
 
-GFile    *g_file_new_for_home              (void);
-GFile    *g_file_new_for_root              (void);
-GFile    *g_file_new_for_trash             (void);
-GFile    *g_file_new_for_desktop           (void);
-GFile    *g_file_new_for_user_special_dir  (GUserDirectory      dir);
+GFile        *g_file_new_for_home                (void);
+GFile        *g_file_new_for_root                (void);
+GFile        *g_file_new_for_trash               (void);
+GFile        *g_file_new_for_desktop             (void);
+GFile        *g_file_new_for_user_special_dir    (GUserDirectory      dir);
 
-gboolean  g_file_is_root                   (GFile              *file);
-gboolean  g_file_is_trashed                (GFile              *file);
-gboolean  g_file_is_desktop                (GFile              *file);
+gboolean      g_file_is_root                     (GFile              *file);
+gboolean      g_file_is_trashed                  (GFile              *file);
+gboolean      g_file_is_desktop                  (GFile              *file);
 
-GKeyFile *g_file_query_key_file            (GFile              *file,
-                                            GCancellable       *cancellable,
-                                            GError            **error);
-gboolean  g_file_write_key_file            (GFile              *file,
-                                            GKeyFile           *key_file,
-                                            GCancellable       *cancellable,
-                                            GError            **error);
+GKeyFile     *g_file_query_key_file              (GFile              *file,
+                                                  GCancellable       *cancellable,
+                                                  GError            **error);
+gboolean      g_file_write_key_file              (GFile              *file,
+                                                  GKeyFile           *key_file,
+                                                  GCancellable       *cancellable,
+                                                  GError            **error);
 
-gchar    *g_file_get_location              (GFile              *file);
+gchar        *g_file_get_location                (GFile              *file);
 
 /**
  * G_TYPE_FILE_LIST:
@@ -52,23 +52,36 @@ gchar    *g_file_get_location              (GFile              *file);
  **/
 #define G_TYPE_FILE_LIST (g_file_list_get_type ())
 
-GType     g_file_list_get_type             (void);
+GType         g_file_list_get_type               (void);
 
-GList    *g_file_list_new_from_string      (const gchar        *string);
-gchar    *g_file_list_to_string            (GList              *list);
-GList    *g_file_list_append               (GList              *list,
-                                            GFile              *file);
-GList    *g_file_list_prepend              (GList              *list,
-                                            GFile              *file);
-GList    *g_file_list_copy                 (GList              *list);
-void      g_file_list_free                 (GList              *list);
+GList        *g_file_list_new_from_string        (const gchar        *string);
+gchar        *g_file_list_to_string              (GList              *list);
+GList        *g_file_list_append                 (GList              *list,
+                                                  GFile              *file);
+GList        *g_file_list_prepend                (GList              *list,
+                                                  GFile              *file);
+GList        *g_file_list_copy                   (GList              *list);
+void          g_file_list_free                   (GList              *list);
 
-gboolean  g_volume_is_removable            (GVolume            *volume);
-gboolean  g_volume_is_mounted              (GVolume            *volume);
-gboolean  g_volume_is_present              (GVolume            *volume);
+gboolean      g_volume_is_removable              (GVolume            *volume);
+gboolean      g_volume_is_mounted                (GVolume            *volume);
+gboolean      g_volume_is_present                (GVolume            *volume);
 
-gboolean  g_mount_is_same_drive            (GMount             *mount,
-                                            GMount             *other);
+gboolean      g_mount_is_same_drive              (GMount             *mount,
+                                                  GMount             *other);
+
+#if !GLIB_CHECK_VERSION(2,18,0)
+GFileType    *g_file_query_file_type             (GFile              *file,
+                                                  GFileQueryInfoFlags flags,
+                                                  GCancellable       *cancellable) G_GNUC_WARN_UNUSED_RESULT;
+GFileMonitor *g_file_monitor                     (GFile              *file,
+	                                                GFileMonitorFlags   flags,
+		                                              GCancellable       *cancellable,
+		                                              GError            **error) G_GNUC_WARN_UNUSED_RESULT;
+gboolean      g_file_make_directory_with_parents (GFile              *file,
+                                                  GCancellable       *cancellable,
+                                                  GError            **error);
+#endif /* !GLIB_CHECK_VERSION(2,18,0) */
 
 G_END_DECLS
 
diff --git a/thunar/thunar-io-scan-directory.c b/thunar/thunar-io-scan-directory.c
index ee72f20..9acdae1 100644
--- a/thunar/thunar-io-scan-directory.c
+++ b/thunar/thunar-io-scan-directory.c
@@ -26,6 +26,7 @@
 
 #include <exo/exo.h>
 
+#include <thunar/thunar-gio-extensions.h>
 #include <thunar/thunar-job.h>
 #include <thunar/thunar-private.h>
 
diff --git a/thunar/thunar-transfer-job.c b/thunar/thunar-transfer-job.c
index 8d46c1b..d793ad0 100644
--- a/thunar/thunar-transfer-job.c
+++ b/thunar/thunar-transfer-job.c
@@ -25,6 +25,7 @@
 
 #include <gio/gio.h>
 
+#include <thunar/thunar-gio-extensions.h>
 #include <thunar/thunar-io-scan-directory.h>
 #include <thunar/thunar-io-jobs-util.h>
 #include <thunar/thunar-job.h>



More information about the Xfce4-commits mailing list