[Goodies-commits] r5490 - in thunar-shares-plugin/trunk: . libshares thunar-plugin

Daniel Morales danielm at xfce.org
Mon Sep 29 17:36:19 CEST 2008


Author: danielm
Date: 2008-09-29 15:36:18 +0000 (Mon, 29 Sep 2008)
New Revision: 5490

Modified:
   thunar-shares-plugin/trunk/ChangeLog
   thunar-shares-plugin/trunk/libshares/libshares-util.c
   thunar-shares-plugin/trunk/libshares/libshares-util.h
   thunar-shares-plugin/trunk/thunar-plugin/tsp-page.c
Log:
	* thunar-plugin/tsp-page.c: Let's use ThunarVFSMonitor functions,
	instead of thunarx_file_info_changed ().
	* libshares/libshares-util.[ch]: $
 

Modified: thunar-shares-plugin/trunk/ChangeLog
===================================================================
--- thunar-shares-plugin/trunk/ChangeLog	2008-09-29 07:47:23 UTC (rev 5489)
+++ thunar-shares-plugin/trunk/ChangeLog	2008-09-29 15:36:18 UTC (rev 5490)
@@ -1,6 +1,12 @@
-2008-09-22	Daniel Morales <daniel at daniel.com.uy>
+2008-09-29	Daniel Morales <daniel at daniel.com.uy>
 
 	* libshares/libshares-util.[ch]:
+	* thunar-plugin/tsp-page.c: Let's use ThunarVFSMonitor functions,
+	instead of thunarx_file_info_changed ().
+
+2008-09-24	Daniel Morales <daniel at daniel.com.uy>
+
+	* libshares/libshares-util.[ch]:
 	* thunar-plugin/tsp-provider.c: Add 'Unshare' menu provider to
 	the shared folders.
 

Modified: thunar-shares-plugin/trunk/libshares/libshares-util.c
===================================================================
--- thunar-shares-plugin/trunk/libshares/libshares-util.c	2008-09-29 07:47:23 UTC (rev 5489)
+++ thunar-shares-plugin/trunk/libshares/libshares-util.c	2008-09-29 15:36:18 UTC (rev 5490)
@@ -99,6 +99,12 @@
     }
   }
 
+  /* Notify changes */
+  if (ret)
+  {
+    tsp_monitor_feed (path);
+  }
+
   return ret;
 }
 
@@ -171,7 +177,8 @@
 
     /* Share it */
     ret = shares_modify_share (file_local, share_info, &err);
-    if (!ret){
+    if (!ret)
+    {
       tsp_show_error (NULL, err->message);
       g_error_free (err);
       shares_free_share_info (share_info);
@@ -179,6 +186,12 @@
     }
   }
 
+  /* Notify changes */
+  if (share_info)
+  {
+    tsp_monitor_feed (file_local);
+  }
+
   return share_info;
 }
 
@@ -246,6 +259,25 @@
   return retval;
 }
 
+/* Notify the file system about shareing changes */
+void
+tsp_monitor_feed (const gchar *uri)
+{
+  ThunarVfsMonitor *monitor;
+  ThunarVfsPath    *path;
+
+  path = thunar_vfs_path_new (uri, NULL);
+
+  if (G_LIKELY (path != NULL))
+  {
+    monitor = thunar_vfs_monitor_get_default ();
+    thunar_vfs_monitor_feed (monitor, THUNAR_VFS_MONITOR_EVENT_CHANGED, path);
+
+    g_object_unref (monitor);
+    thunar_vfs_path_unref (path);
+  }
+}
+
 /* Asks to the user if we can change the permissions of the folder */
 static gboolean
 tsp_ask_perms (gboolean  need_r,

Modified: thunar-shares-plugin/trunk/libshares/libshares-util.h
===================================================================
--- thunar-shares-plugin/trunk/libshares/libshares-util.h	2008-09-29 07:47:23 UTC (rev 5489)
+++ thunar-shares-plugin/trunk/libshares/libshares-util.h	2008-09-29 15:36:18 UTC (rev 5490)
@@ -39,6 +39,8 @@
 
 gboolean tsp_ask_user       (const char      *text);
 
+void     tsp_monitor_feed   (const gchar *uri);
+
 gboolean tsp_is_shareable   (ThunarxFileInfo *info);
 
 gboolean tsp_shares_unshare (const gchar     *path);

Modified: thunar-shares-plugin/trunk/thunar-plugin/tsp-page.c
===================================================================
--- thunar-shares-plugin/trunk/thunar-plugin/tsp-page.c	2008-09-29 07:47:23 UTC (rev 5489)
+++ thunar-shares-plugin/trunk/thunar-plugin/tsp-page.c	2008-09-29 15:36:18 UTC (rev 5490)
@@ -48,8 +48,12 @@
                                     guint            prop_id,
                                     const GValue    *value,
                                     GParamSpec      *pspec);
-static void tsp_page_file_changed  (ThunarxFileInfo *file,
-                                    TspPage         *tsp_page);
+static void tsp_page_file_changed  (ThunarVfsMonitor       *monitor,
+                                    ThunarVfsMonitorHandle *handle,
+                                    ThunarVfsMonitorEvent   event,
+                                    ThunarVfsPath          *handle_path,
+                                    ThunarVfsPath          *event_path,
+                                    gpointer                user_data);
 static void tsp_page_share_toggled (GtkToggleButton *togglebutton,
                                     TspPage         *tsp_page);
 static void tsp_page_write_toggled (GtkToggleButton *togglebutton,
@@ -80,6 +84,8 @@
   ThunarxPropertyPage __parent__;
   ThunarxFileInfo    *file;
 
+  ThunarVfsMonitorHandle *handle;
+
   GtkWidget          *cb_share_folder;
   GtkWidget          *entry_share_name;
   GtkWidget          *cb_share_write;
@@ -303,6 +309,10 @@
 tsp_page_set_file (TspPage         *tsp_page,
                    ThunarxFileInfo *file)
 {
+  ThunarVfsMonitor *monitor;
+  ThunarVfsPath    *path;
+  gchar            *uri;
+
   g_return_if_fail (TSP_IS_PAGE (tsp_page));
   g_return_if_fail (file == NULL || THUNARX_IS_FILE_INFO (file));
 
@@ -310,9 +320,16 @@
     return;
   }
 
-  if (tsp_page->file != NULL)
+  monitor = thunar_vfs_monitor_get_default ();
+
+  if (G_LIKELY (tsp_page->handle != NULL))
   {
-    g_signal_handlers_disconnect_by_func (tsp_page->file, tsp_page_file_changed, tsp_page);
+    thunar_vfs_monitor_remove (monitor, tsp_page->handle);
+    tsp_page->handle = NULL;
+  }
+
+  if (G_LIKELY (tsp_page->file != NULL))
+  {
     g_object_unref (G_OBJECT (tsp_page->file));
   }
 
@@ -321,23 +338,46 @@
   if (file != NULL)
   {
     g_object_ref (tsp_page->file);
-    tsp_page_file_changed (file, tsp_page);
-    g_signal_connect (file, "changed", G_CALLBACK (tsp_page_file_changed), tsp_page);
+    tsp_page_file_changed (NULL, NULL, THUNAR_VFS_MONITOR_EVENT_CHANGED, NULL, NULL, tsp_page);
+    
+    /* Let's monitor file changes */
+    uri = thunarx_file_info_get_uri (tsp_page->file);
+    path = thunar_vfs_path_new (uri, NULL);
+
+    if (G_LIKELY (path != NULL))
+    {
+      tsp_page->handle = thunar_vfs_monitor_add_file (monitor, path, tsp_page_file_changed, tsp_page);
+      thunar_vfs_path_unref (path);
+    }
+
+    g_free (uri);
   }
 
+  g_object_unref (monitor);
   g_object_notify (G_OBJECT (tsp_page), "file");
 }
 
 /* File changed */
 static void
-tsp_page_file_changed (ThunarxFileInfo *file,
-                       TspPage         *tsp_page)
+tsp_page_file_changed (ThunarVfsMonitor       *monitor,
+                       ThunarVfsMonitorHandle *handle,
+                       ThunarVfsMonitorEvent   event,
+                       ThunarVfsPath          *handle_path,
+                       ThunarVfsPath          *event_path,
+                       gpointer                user_data)
 {
   ShareInfo   *share_info;
   gboolean     result;
+  TspPage     *tsp_page;
   GError      *error = NULL;
   gchar       *uri, *file_local;
 
+  if (G_LIKELY (event != THUNAR_VFS_MONITOR_EVENT_CHANGED)){
+    return;
+  }
+
+  tsp_page = TSP_PAGE (user_data);
+
   /* Load share info */
   uri = thunarx_file_info_get_uri (tsp_page->file);
   file_local = g_filename_from_uri (uri, NULL, NULL);
@@ -472,17 +512,12 @@
     {
       tsp_update_default (tsp_page, share_info);
       shares_free_share_info (share_info);
-
-      /* Notify other pages of the changes made */
-      thunarx_file_info_changed (tsp_page->file);
     }
   } else {
     /* Un-share the folder */
-    if (tsp_shares_unshare (local_file)){
+    if (tsp_shares_unshare (local_file))
+    {
       tsp_update_default (tsp_page, NULL);
-
-      /* Notify other pages of the changes made */
-      thunarx_file_info_changed (tsp_page->file);
     }
   }
 




More information about the Goodies-commits mailing list