[Xfce4-commits] r29228 - in thunar/branches/port-to-gio: . thunar

Jannis Pohlmann jannis at xfce.org
Wed Jan 14 00:12:47 CET 2009


Author: jannis
Date: 2009-01-13 23:12:46 +0000 (Tue, 13 Jan 2009)
New Revision: 29228

Modified:
   thunar/branches/port-to-gio/ChangeLog
   thunar/branches/port-to-gio/configure.in.in
   thunar/branches/port-to-gio/thunar/Makefile.am
   thunar/branches/port-to-gio/thunar/thunar-file.c
   thunar/branches/port-to-gio/thunar/thunar-file.h
Log:
	* configure.in.in, thunar/Makefile.am: Add optional dependency on
	  gio-unix-2.0.
	* thunar/thunar-file.{c,h}: Add gio/gio.h include. Implement
	  thunar_file_monitor() and thunar_file_watch() with GIO. Improve
	  thunar_file_is_executable() by trying to intrepret the file as a
	  desktop entry and check if it has an Exec or Link key (depending on
	  the Type value). Remove thunar_file_watch_free() and the GQuark for
	  the monitor handle.

Modified: thunar/branches/port-to-gio/ChangeLog
===================================================================
--- thunar/branches/port-to-gio/ChangeLog	2009-01-13 12:25:58 UTC (rev 29227)
+++ thunar/branches/port-to-gio/ChangeLog	2009-01-13 23:12:46 UTC (rev 29228)
@@ -1,3 +1,14 @@
+2009-01-14	Jannis Pohlmann <jannis at xfce.org>
+
+	* configure.in.in, thunar/Makefile.am: Add optional dependency on 
+	  gio-unix-2.0.
+	* thunar/thunar-file.{c,h}: Add gio/gio.h include. Implement
+	  thunar_file_monitor() and thunar_file_watch() with GIO. Improve
+	  thunar_file_is_executable() by trying to intrepret the file as a
+	  desktop entry and check if it has an Exec or Link key (depending on
+	  the Type value). Remove thunar_file_watch_free() and the GQuark for 
+	  the monitor handle. 
+
 2009-01-12	Stephan Arts <stephan at xfce.org>
 	
 	* === Release 0.9.93 ===

Modified: thunar/branches/port-to-gio/configure.in.in
===================================================================
--- thunar/branches/port-to-gio/configure.in.in	2009-01-13 12:25:58 UTC (rev 29227)
+++ thunar/branches/port-to-gio/configure.in.in	2009-01-13 23:12:46 UTC (rev 29228)
@@ -201,6 +201,14 @@
                            [0.4], [startup-notification],
                            [startup notification library])
 
+dnl ***************************************************
+dnl *** Optional support for UNIX specific GIO APIs ***
+dnl ***************************************************
+XDT_CHECK_OPTIONAL_PACKAGE([GIO_UNIX],
+                           [gio-unix-2.0],
+                           [2.16.0], [gio-unix],
+                           [UNIX specific GIO APIs])
+
 dnl ******************************
 dnl *** Check for FreeType 2.x ***
 dnl ******************************
@@ -508,6 +516,11 @@
 else
 echo "* Startup Notification:      no"
 fi
+if test x"$GIO_UNIX_FOUND" = x"yes"; then
+echo "* UNIX specific GIO APIs:    yes"
+else
+echo "* UNIX specific GIO APIs:    no"
+fi
 echo "* Volume Manager:            $ac_bm_thunar_vfs_volume_impl"
 echo "* Debug Support:             $enable_debug"
 echo

Modified: thunar/branches/port-to-gio/thunar/Makefile.am
===================================================================
--- thunar/branches/port-to-gio/thunar/Makefile.am	2009-01-13 12:25:58 UTC (rev 29227)
+++ thunar/branches/port-to-gio/thunar/Makefile.am	2009-01-13 23:12:46 UTC (rev 29228)
@@ -199,6 +199,7 @@
 	$(GTHREAD_CFLAGS)						\
 	$(GLIB_CFLAGS)							\
 	$(GIO_CFLAGS)							\
+	$(GIO_UNIX_CFLAGS)						\
 	$(LIBSM_CFLAGS)							\
 	$(PLATFORM_CFLAGS)
 
@@ -215,6 +216,7 @@
 	$(GTHREAD_LIBS)							\
 	$(GLIB_LIBS)							\
 	$(GIO_LIBS)							\
+	$(GIO_UNIX_LIBS)						\
 	$(LIBSM_LIBS)
 
 Thunar_DEPENDENCIES =							\

Modified: thunar/branches/port-to-gio/thunar/thunar-file.c
===================================================================
--- thunar/branches/port-to-gio/thunar/thunar-file.c	2009-01-13 12:25:58 UTC (rev 29227)
+++ thunar/branches/port-to-gio/thunar/thunar-file.c	2009-01-13 23:12:46 UTC (rev 29228)
@@ -45,6 +45,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>
@@ -104,25 +106,21 @@
                                                                 ThunarFileMode          grp_permissions,
                                                                 ThunarFileMode          oth_permissions);
 static ThunarMetafile    *thunar_file_get_metafile             (ThunarFile             *file);
-static void               thunar_file_monitor                  (ThunarVfsMonitor       *monitor,
-                                                                ThunarVfsMonitorHandle *handle,
-                                                                ThunarVfsMonitorEvent   event,
-                                                                ThunarVfsPath          *handle_path,
-                                                                ThunarVfsPath          *event_path,
-                                                                gpointer                user_data);
-static void               thunar_file_watch_free               (gpointer                data);
+static void               thunar_file_monitor                  (GFileMonitor           *monitor,
+                                                                GFile                  *gfile,
+                                                                GFile                  *other_gfile,
+                                                                GFileMonitorEvent       event_type,
+                                                                ThunarFile             *file);
 
 
 
 static ThunarUserManager *user_manager;
-static ThunarVfsMonitor  *monitor;
 static guint32            effective_user_id;
 static ThunarMetafile    *metafile;
 static GObjectClass      *thunar_file_parent_class;
 static GHashTable        *file_cache;
 static GQuark             thunar_file_thumb_path_quark;
 static GQuark             thunar_file_watch_count_quark;
-static GQuark             thunar_file_watch_handle_quark;
 static GQuark             thunar_file_emblem_names_quark;
 static guint              file_signals[LAST_SIGNAL];
 
@@ -213,7 +211,6 @@
   /* pre-allocate the required quarks */
   thunar_file_thumb_path_quark = g_quark_from_static_string ("thunar-file-thumb-path");
   thunar_file_watch_count_quark = g_quark_from_static_string ("thunar-file-watch-count");
-  thunar_file_watch_handle_quark = g_quark_from_static_string ("thunar-file-watch-handle");
   thunar_file_emblem_names_quark = g_quark_from_static_string ("thunar-file-emblem-names");
 
   /* determine the parent class */
@@ -520,46 +517,48 @@
 
 
 static void
-thunar_file_monitor (ThunarVfsMonitor       *monitor,
-                     ThunarVfsMonitorHandle *handle,
-                     ThunarVfsMonitorEvent   event,
-                     ThunarVfsPath          *handle_path,
-                     ThunarVfsPath          *event_path,
-                     gpointer                user_data)
+thunar_file_monitor_update (GFile             *path,
+                            GFileMonitorEvent  event_type)
 {
-  ThunarFile *file = THUNAR_FILE (user_data);
+  ThunarFile *file;
 
-  _thunar_return_if_fail (THUNAR_VFS_IS_MONITOR (monitor));
-  _thunar_return_if_fail (THUNAR_IS_FILE (file));
-  _thunar_return_if_fail (thunar_vfs_path_equal (file->info->path, event_path));
+  _thunar_return_if_fail (G_IS_FILE (path));
 
-  /* just to be sure... */
-  if (G_UNLIKELY (!thunar_vfs_path_equal (handle_path, event_path)))
-    return;
-
-  switch (event)
+  file = thunar_file_cache_lookup (path);
+  if (G_LIKELY (file != NULL))
     {
-    case THUNAR_VFS_MONITOR_EVENT_CHANGED:
-    case THUNAR_VFS_MONITOR_EVENT_CREATED:
-      thunar_file_reload (file);
-      break;
+      switch (event_type)
+        {
+        case G_FILE_MONITOR_EVENT_CREATED:
+        case G_FILE_MONITOR_EVENT_CHANGED:
+        case G_FILE_MONITOR_EVENT_ATTRIBUTE_CHANGED:
+          thunar_file_reload (file);    
+          break;
+          
+        case G_FILE_MONITOR_EVENT_DELETED:
+          thunar_file_destroy (file);
+          break;
 
-    case THUNAR_VFS_MONITOR_EVENT_DELETED:
-      thunar_file_destroy (file);
-      break;
+        default:
+          break;
+        }
     }
 }
 
 
 
 static void
-thunar_file_watch_free (gpointer data)
+thunar_file_monitor (GFileMonitor      *monitor,
+                     GFile             *path,
+                     GFile             *other_path,
+                     GFileMonitorEvent  event_type,
+                     ThunarFile        *file)
 {
-  /* remove the watch from the VFS monitor */
-  thunar_vfs_monitor_remove (monitor, data);
+  if (G_LIKELY (G_IS_FILE (path)))
+    thunar_file_monitor_update (path, event_type);
 
-  /* release our reference on the VFS monitor */
-  g_object_unref (G_OBJECT (monitor));
+  if (G_UNLIKELY (G_IS_FILE (other_path)))
+    thunar_file_monitor_update (other_path, event_type);
 }
 
 
@@ -1820,15 +1819,61 @@
  *
  * Determines whether the owner of the current process is allowed
  * to execute the @file (or enter the directory refered to by
- * @file).
+ * @file). On UNIX it also returns %TRUE if @file refers to a 
+ * desktop entry.
  *
  * Return value: %TRUE if @file can be executed.
  **/
 gboolean
 thunar_file_is_executable (const ThunarFile *file)
 {
+  GKeyFile *key_file;
+  gchar    *path;
+  gchar    *type;
+  gboolean  executable = FALSE;
+
   _thunar_return_val_if_fail (THUNAR_IS_FILE (file), FALSE);
-  return g_file_info_get_attribute_boolean (file->ginfo, G_FILE_ATTRIBUTE_ACCESS_CAN_EXECUTE);
+   
+  /* Return true if the execute bit is set */
+  if (g_file_info_get_attribute_boolean (file->ginfo, G_FILE_ATTRIBUTE_ACCESS_CAN_EXECUTE))
+    return TRUE;
+
+  /* Determine the absolute path to the file */
+  path = g_file_get_path (file->gfile);
+  if (G_LIKELY (path != NULL))
+    {
+      /* Create a key file and try to load it from the file */
+      key_file = g_key_file_new ();
+      if (G_UNLIKELY (g_key_file_load_from_file (key_file, path, G_KEY_FILE_NONE, NULL)))
+        {
+          /* Try to read the "Type" value of the [Desktop Entry] group */
+          type = g_key_file_get_value (key_file, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_TYPE, NULL);
+          if (G_LIKELY (type != NULL))
+            {
+              if (g_str_equal (type, "Application") && 
+                  g_key_file_has_key (key_file, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_EXEC, NULL))
+                {
+                  /* Normal desktop entries with Exec keys are assumed to be executable */
+                  executable = TRUE;
+                }
+              else if (g_str_equal (type, "Link") &&
+                       g_key_file_has_key (key_file, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_URL, NULL))
+                {
+                  /* Desktop entries for URLs with an URL specified are assumed to be executable */
+                  executable = TRUE;
+                }
+
+              g_free (type);
+            }
+
+          g_key_file_free (key_file);
+        }
+
+      g_free (path);
+    }
+  
+
+  return executable;
 }
 
 
@@ -2106,8 +2151,7 @@
 void
 thunar_file_watch (ThunarFile *file)
 {
-  ThunarVfsMonitorHandle *handle;
-  gint                    watch_count;
+  gint watch_count;
 
   _thunar_return_if_fail (THUNAR_IS_FILE (file));
   _thunar_return_if_fail (THUNAR_FILE_GET_WATCH_COUNT (file) >= 0);
@@ -2116,20 +2160,15 @@
 
   if (++watch_count == 1)
     {
-      /* take a reference on the VFS monitor for this instance */
-      if (G_LIKELY (monitor == NULL))
+      /* create a file or directory monitor */
+      file->monitor = g_file_monitor_file (file->gfile, G_FILE_MONITOR_NONE, NULL, NULL);
+
+      /* if monitoring is supported watch for file changes */
+      if (G_LIKELY (file->monitor != NULL))
         {
-          monitor = thunar_vfs_monitor_get_default ();
-          g_object_add_weak_pointer (G_OBJECT (monitor), (gpointer) &monitor);
+          g_object_add_weak_pointer (G_OBJECT (file->monitor), (gpointer) &file->monitor);
+          g_signal_connect (file->monitor, "changed", G_CALLBACK (thunar_file_monitor), file);
         }
-      else
-        {
-          g_object_ref (G_OBJECT (monitor));
-        }
-
-      /* add us to the file monitor */
-      handle = thunar_vfs_monitor_add_file (monitor, file->info->path, thunar_file_monitor, file);
-      g_object_set_qdata_full (G_OBJECT (file), thunar_file_watch_handle_quark, handle, thunar_file_watch_free);
     }
 
   THUNAR_FILE_SET_WATCH_COUNT (file, watch_count);
@@ -2156,8 +2195,14 @@
 
   if (--watch_count == 0)
     {
-      /* just unset the watch handle */
-      g_object_set_qdata (G_OBJECT (file), thunar_file_watch_handle_quark, NULL);
+      if (G_LIKELY (file->monitor != NULL))
+        {
+          /* cancel monitoring */
+          g_file_monitor_cancel (file->monitor);
+
+          /* destroy the file monitor */
+          g_object_unref (file->monitor);
+        }
     }
 
   THUNAR_FILE_SET_WATCH_COUNT (file, watch_count);

Modified: thunar/branches/port-to-gio/thunar/thunar-file.h
===================================================================
--- thunar/branches/port-to-gio/thunar/thunar-file.h	2009-01-13 12:25:58 UTC (rev 29227)
+++ thunar/branches/port-to-gio/thunar/thunar-file.h	2009-01-13 23:12:46 UTC (rev 29228)
@@ -155,6 +155,7 @@
 
   GFile         *gfile;
   GFileInfo     *ginfo;
+  GFileMonitor  *monitor;
 };
 
 GType             thunar_file_get_type             (void) G_GNUC_CONST;




More information about the Xfce4-commits mailing list