[Goodies-commits] r3741 - in xfce4-notes-plugin/trunk: . panel-plugin

Mike Massonnet mmassonnet at xfce.org
Sun Dec 23 23:10:17 CET 2007


Author: mmassonnet
Date: 2007-12-23 22:10:17 +0000 (Sun, 23 Dec 2007)
New Revision: 3741

Modified:
   xfce4-notes-plugin/trunk/configure.in.in
   xfce4-notes-plugin/trunk/panel-plugin/Makefile.am
   xfce4-notes-plugin/trunk/panel-plugin/notes.c
   xfce4-notes-plugin/trunk/panel-plugin/notes.h
   xfce4-notes-plugin/trunk/panel-plugin/panel-plugin.c
Log:
	* configure.in.in, panel-plugin/Makefile.am, panel-plugin/notes.c,
	panel-plugin/notes.h, panel-plugin/panel-plugin.c: Add file system monitoring.


Modified: xfce4-notes-plugin/trunk/configure.in.in
===================================================================
--- xfce4-notes-plugin/trunk/configure.in.in	2007-12-23 22:09:26 UTC (rev 3740)
+++ xfce4-notes-plugin/trunk/configure.in.in	2007-12-23 22:10:17 UTC (rev 3741)
@@ -51,6 +51,28 @@
 XDT_CHECK_PACKAGE([LIBXFCE4UTIL], [libxfce4util-1.0], [4.3.90])
 XDT_CHECK_PACKAGE([LIBXFCE4PANEL], [libxfce4panel-1.0], [4.3.90])
 
+dnl check for thunar_vfs
+m4_define([thunar_minimum_version], [0.8.0])
+AC_ARG_ENABLE([fs-monitor],
+              [AC_HELP_STRING([--disable-fs-monitor],
+                              [Don't use thunar-vfs to monitor the file system. (default=enabled)])],
+              [thunar_vfs=$enableval],
+              [thunar_vfs=yes])
+if test "x$thunar_vfs" = "xyes" ; then
+    XDT_CHECK_PACKAGE([THUNAR_VFS], [thunar-vfs-1],
+                      [thunar_minimum_version], [have_thunar_vfs=yes], [
+echo "*** Optional package thunar-vfs-1 was either not found on your system"
+echo "*** or is too old.  Please install or upgrade to at least version"
+echo "*** thunar_minimum_version, or adjust the PKG_CONFIG_PATH environment variable"
+echo "*** if you installed the new version of the package in a nonstandard"
+echo "*** prefix.  File system monitoring will be disabled."
+])
+
+    if test "x$have_thunar_vfs" = "xyes" ; then
+        AC_DEFINE([HAVE_THUNAR_VFS], [1], [Define if thunar-vfs is present.])
+    fi
+fi
+
 dnl Translations
 XDT_I18N([@LINGUAS@])
 

Modified: xfce4-notes-plugin/trunk/panel-plugin/Makefile.am
===================================================================
--- xfce4-notes-plugin/trunk/panel-plugin/Makefile.am	2007-12-23 22:09:26 UTC (rev 3740)
+++ xfce4-notes-plugin/trunk/panel-plugin/Makefile.am	2007-12-23 22:10:17 UTC (rev 3741)
@@ -1,37 +1,39 @@
 bin_PROGRAMS = xfce4-popup-notes
 
-xfce4_popup_notes_SOURCES =										\
-	xfce4-popup-notes.c											\
+xfce4_popup_notes_SOURCES =						\
+	xfce4-popup-notes.c						\
 	xfce4-popup-notes.h
 
-xfce4_popup_notes_CFLAGS =										\
-	$(LIBX11_CFLAGS)											\
-	$(GTK_CFLAGS)
+xfce4_popup_notes_CFLAGS =						\
+	@LIBX11_CFLAGS@							\
+	@GTK_CFLAGS@
 
-xfce4_popup_notes_LDADD =										\
-	$(LIBX11_LDFLAGS)											\
-	$(LIBX11_LIBS)												\
-	$(GTK_LIBS)
+xfce4_popup_notes_LDADD =						\
+	@LIBX11_LDFLAGS@						\
+	@LIBX11_LIBS@							\
+	@GTK_LIBS@
 
 plugindir = $(libexecdir)/xfce4/panel-plugins
 plugin_PROGRAMS = xfce4-notes-plugin
 
-xfce4_notes_plugin_SOURCES =									\
-	panel-plugin.c												\
-	notes.c														\
+xfce4_notes_plugin_SOURCES =						\
+	panel-plugin.c							\
+	notes.c								\
 	notes.h
 
-xfce4_notes_plugin_CFLAGS =										\
-	-I$(top_srcdir)												\
-	@LIBXFCE4PANEL_CFLAGS@										\
-	@LIBXFCE4UTIL_CFLAGS@										\
-	@LIBXFCEGUI4_CFLAGS@										\
+xfce4_notes_plugin_CFLAGS =						\
+	-I$(top_srcdir)							\
+	@LIBXFCE4PANEL_CFLAGS@						\
+	@LIBXFCE4UTIL_CFLAGS@						\
+	@LIBXFCEGUI4_CFLAGS@						\
+	@THUNAR_VFS_CFLAGS@						\
 	-DPACKAGE_LOCALE_DIR=\"$(localedir)\"
 
-xfce4_notes_plugin_LDADD =										\
-	@LIBXFCE4PANEL_LIBS@										\
-	@LIBXFCE4UTIL_LIBS@											\
-	@LIBXFCEGUI4_LIBS@
+xfce4_notes_plugin_LDADD =						\
+	@LIBXFCE4PANEL_LIBS@						\
+	@LIBXFCE4UTIL_LIBS@						\
+	@LIBXFCEGUI4_LIBS@						\
+	@THUNAR_VFS_LIBS@
 
 desktop_in_in_files = xfce4-notes-plugin.desktop.in.in
 desktop_in_files = $(desktop_in_in_files:.desktop.in.in=.desktop.in)
@@ -40,10 +42,10 @@
 desktop_DATA = $(desktop_in_files:.desktop.in=.desktop)
 @INTLTOOL_DESKTOP_RULE@
 
-EXTRA_DIST =													\
+EXTRA_DIST =								\
 	$(desktop_in_in_files)
 
-DISTCLEANFILES =												\
+DISTCLEANFILES =							\
 	$(desktop_DATA) $(desktop_in_files)
 
 # get full path into .desktop file

Modified: xfce4-notes-plugin/trunk/panel-plugin/notes.c
===================================================================
--- xfce4-notes-plugin/trunk/panel-plugin/notes.c	2007-12-23 22:09:26 UTC (rev 3740)
+++ xfce4-notes-plugin/trunk/panel-plugin/notes.c	2007-12-23 22:10:17 UTC (rev 3741)
@@ -36,6 +36,14 @@
 
 
 
+#ifdef HAVE_THUNAR_VFS
+static void             notes_window_fs_event           (ThunarVfsMonitor *monitor,
+                                                         ThunarVfsMonitorHandle *handle,
+                                                         ThunarVfsMonitorEvent event,
+                                                         ThunarVfsPath *handle_path,
+                                                         ThunarVfsPath *event_path,
+                                                         NotesWindow *notes_window);
+#endif
 static void             notes_window_menu_new           (NotesWindow *notes_window);
 
 static void             notes_window_menu_popup         (NotesWindow *notes_window);
@@ -106,10 +114,14 @@
                                                          GdkEventKey *event);
 
 
+
 /**
+ * NotesWindow
+ */
+/**
  * - Iterator to fetch all windows
- * - Window creation functions
- * - Load and save the data
+ * - Window creation/destroy functions
+ * - Load/save the data
  */
 const gchar *
 notes_window_read_name (NotesPlugin *notes_plugin)
@@ -328,6 +340,26 @@
                                                  notes_window,
                                                  (GCompareFunc)notes_window_strcasecmp);
 
+#ifdef HAVE_THUNAR_VFS
+  /* Monitor handle */
+  gchar *path = g_build_path (G_DIR_SEPARATOR_S,
+                              notes_plugin->notes_path,
+                              notes_window->name,
+                              NULL);
+  notes_window->thunar_vfs_path = thunar_vfs_path_new (path, NULL);
+  g_free (path);
+
+  if (G_LIKELY (NULL != notes_window->thunar_vfs_path))
+    {
+      DBG ("Monitor `%s'", thunar_vfs_path_get_name (notes_window->thunar_vfs_path));
+      notes_window->monitor_handle =
+        thunar_vfs_monitor_add_directory (notes_plugin->monitor,
+                                          notes_window->thunar_vfs_path,
+                                          (ThunarVfsMonitorCallback)notes_window_fs_event,
+                                          notes_window);
+    }
+#endif
+
   /* Signals */
   g_signal_connect_swapped (notes_window->window,
                             "window-state-event",
@@ -379,6 +411,60 @@
 }
 
 void
+notes_window_destroy (NotesWindow *notes_window)
+{
+  DBG ("Destroy window `%s' (%p)", notes_window->name, notes_window);
+
+  GtkWidget *dialog =
+    gtk_message_dialog_new (GTK_WINDOW (notes_window->window),
+                            GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT,
+                            GTK_MESSAGE_QUESTION,
+                            GTK_BUTTONS_YES_NO,
+                            _("Are you sure you want to delete this window?"));
+  gint result = gtk_dialog_run (GTK_DIALOG (dialog));
+  gtk_widget_destroy (dialog);
+  if (G_UNLIKELY (result != GTK_RESPONSE_YES))
+    return;
+
+  NotesPlugin *notes_plugin = notes_window->notes_plugin;
+
+  /* Drop configuration data */
+  XfceRc *rc = xfce_rc_simple_open (notes_window->notes_plugin->config_file, FALSE);
+  g_return_if_fail (G_LIKELY (rc != NULL));
+  xfce_rc_delete_group (rc, notes_window->name, FALSE);
+  xfce_rc_close (rc);
+
+  /* Destroy all NotesNote */
+  g_slist_foreach (notes_window->notes, (GFunc)notes_note_destroy, NULL);
+  g_slist_free (notes_window->notes);
+
+  /* Remove directory */
+  gchar *window_path = g_build_path (G_DIR_SEPARATOR_S,
+                                     notes_window->notes_plugin->notes_path,
+                                     notes_window->name,
+                                     NULL);
+  g_rmdir (window_path);
+  g_free (window_path);
+
+  /* Remove GSList entry */
+  notes_plugin->windows = g_slist_remove (notes_plugin->windows, notes_window);
+
+  /* Monitor handle */
+  thunar_vfs_monitor_remove (notes_window->notes_plugin->monitor,
+                             notes_window->monitor_handle);
+  thunar_vfs_path_unref (notes_window->thunar_vfs_path);
+
+  /* Free data */
+  g_free (notes_window->name);
+  gtk_widget_destroy (notes_window->window);
+  g_slice_free (NotesWindow, notes_window);
+
+  /* Init a new window if we get too low */
+  if (g_slist_length (notes_plugin->windows) == 0)
+    notes_window_new (notes_plugin);
+}
+
+void
 notes_window_load_data (NotesWindow *notes_window)
 {
   XfceRc               *rc;
@@ -524,54 +610,24 @@
   xfce_rc_close (rc);
 }
 
-void
-notes_window_destroy (NotesWindow *notes_window)
+#ifdef HAVE_THUNAR_VFS
+/**
+ * Fs event
+ */
+static void
+notes_window_fs_event (ThunarVfsMonitor *monitor,
+                       ThunarVfsMonitorHandle *handle,
+                       ThunarVfsMonitorEvent event,
+                       ThunarVfsPath *handle_path,
+                       ThunarVfsPath *event_path,
+                       NotesWindow *notes_window)
 {
-  DBG ("Destroy window `%s' (%p)", notes_window->name, notes_window);
-
-  GtkWidget *dialog =
-    gtk_message_dialog_new (GTK_WINDOW (notes_window->window),
-                            GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT,
-                            GTK_MESSAGE_QUESTION,
-                            GTK_BUTTONS_YES_NO,
-                            _("Are you sure you want to delete this window?"));
-  gint result = gtk_dialog_run (GTK_DIALOG (dialog));
-  gtk_widget_destroy (dialog);
-  if (G_UNLIKELY (result != GTK_RESPONSE_YES))
-    return;
-
-  NotesPlugin *notes_plugin = notes_window->notes_plugin;
-
-  /* Drop configuration data */
-  XfceRc *rc = xfce_rc_simple_open (notes_window->notes_plugin->config_file, FALSE);
-  g_return_if_fail (G_LIKELY (rc != NULL));
-  xfce_rc_delete_group (rc, notes_window->name, FALSE);
-  xfce_rc_close (rc);
-
-  /* Destroy all NotesNote */
-  g_slist_foreach (notes_window->notes, (GFunc)notes_note_destroy, NULL);
-  g_slist_free (notes_window->notes);
-
-  /* Remove directory */
-  gchar *window_path = g_build_path (G_DIR_SEPARATOR_S,
-                                     notes_window->notes_plugin->notes_path,
-                                     notes_window->name,
-                                     NULL);
-  g_rmdir (window_path);
-  g_free (window_path);
-
-  /* Remove GSList entry */
-  notes_plugin->windows = g_slist_remove (notes_plugin->windows, notes_window);
-
-  /* Free data */
-  g_free (notes_window->name);
-  gtk_widget_destroy (notes_window->window);
-  g_slice_free (NotesWindow, notes_window);
-
-  /* Init a new window if we get too low */
-  if (g_slist_length (notes_plugin->windows) == 0)
-    notes_window_new (notes_plugin);
+  TRACE ("event: `%d'\nhandle_path: `%s'\nevent_path: `%s'",
+         event,
+         thunar_vfs_path_get_name (handle_path),
+         thunar_vfs_path_get_name (event_path));
 }
+#endif
 
 /**
  * Window menu
@@ -1277,7 +1333,8 @@
 }
 
 /**
- * Functions to create/delete a note and return the current note
+ * - Get current note
+ * - Add/delete note
  */
 static inline NotesNote *
 notes_window_get_current_note (NotesWindow *notes_window)
@@ -1328,9 +1385,12 @@
 
 
 /**
+ * NotesNote
+ */
+/**
  * - Iterator to fetch all notes from a window
- * - Note creation functions
- * - Load and save the data
+ * - Note creation/destroy functions
+ * - Load/save the data
  */
 const gchar *
 notes_note_read_name (NotesWindow *notes_window)
@@ -1434,6 +1494,42 @@
 }
 
 void
+notes_note_destroy (NotesNote *notes_note)
+{
+  DBG ("Destroy note `%s' (%p)", notes_note->name, notes_note);
+
+  gint                  id;
+  gchar                *note_path;
+  NotesWindow          *notes_window = notes_note->notes_window;
+
+  /* Make sure we kill the timeout */
+  if (notes_note->timeout != 0)
+    g_source_remove (notes_note->timeout);
+
+  /* Remove notebook page */
+  id = gtk_notebook_get_current_page (GTK_NOTEBOOK (notes_window->notebook));
+  gtk_notebook_remove_page (GTK_NOTEBOOK (notes_window->notebook), id);
+  gtk_notebook_set_show_tabs (GTK_NOTEBOOK (notes_window->notebook),
+                              ((g_slist_length (notes_window->notes) - 1) > 1));
+
+  /* Remove file */
+  note_path = g_build_path (G_DIR_SEPARATOR_S,
+                            notes_window->notes_plugin->notes_path,
+                            notes_window->name,
+                            notes_note->name,
+                            NULL);
+  g_unlink (note_path);
+  g_free (note_path);
+
+  /* Remove GSList entry */
+  notes_window->notes = g_slist_remove (notes_window->notes, notes_note);
+
+  /* Free data */
+  g_free (notes_note->name);
+  g_slice_free (NotesNote, notes_note);
+}
+
+void
 notes_note_load_data (NotesNote *notes_note,
                       GtkTextBuffer *buffer)
 {
@@ -1518,42 +1614,6 @@
   return FALSE;
 }
 
-void
-notes_note_destroy (NotesNote *notes_note)
-{
-  DBG ("Destroy note `%s' (%p)", notes_note->name, notes_note);
-
-  gint                  id;
-  gchar                *note_path;
-  NotesWindow          *notes_window = notes_note->notes_window;
-
-  /* Make sure we kill the timeout */
-  if (notes_note->timeout != 0)
-    g_source_remove (notes_note->timeout);
-
-  /* Remove notebook page */
-  id = gtk_notebook_get_current_page (GTK_NOTEBOOK (notes_window->notebook));
-  gtk_notebook_remove_page (GTK_NOTEBOOK (notes_window->notebook), id);
-  gtk_notebook_set_show_tabs (GTK_NOTEBOOK (notes_window->notebook),
-                              ((g_slist_length (notes_window->notes) - 1) > 1));
-
-  /* Remove file */
-  note_path = g_build_path (G_DIR_SEPARATOR_S,
-                            notes_window->notes_plugin->notes_path,
-                            notes_window->name,
-                            notes_note->name,
-                            NULL);
-  g_unlink (note_path);
-  g_free (note_path);
-
-  /* Remove GSList entry */
-  notes_window->notes = g_slist_remove (notes_window->notes, notes_note);
-
-  /* Free data */
-  g_free (notes_note->name);
-  g_slice_free (NotesNote, notes_note);
-}
-
 /**
  * Function to set the font
  */

Modified: xfce4-notes-plugin/trunk/panel-plugin/notes.h
===================================================================
--- xfce4-notes-plugin/trunk/panel-plugin/notes.h	2007-12-23 22:09:26 UTC (rev 3740)
+++ xfce4-notes-plugin/trunk/panel-plugin/notes.h	2007-12-23 22:10:17 UTC (rev 3741)
@@ -24,6 +24,9 @@
 #include <libxfce4panel/xfce-panel-plugin.h>
 #include <libxfce4panel/xfce-panel-convenience.h>
 #include <libxfcegui4/libxfcegui4.h>
+#ifdef HAVE_THUNAR_VFS
+#include <thunar-vfs/thunar-vfs.h>
+#endif
 
 typedef struct _NotesPlugin     NotesPlugin;
 struct _NotesPlugin
@@ -41,6 +44,12 @@
   GtkWidget            *icon_rev;
 
   GtkTooltips          *tooltips;
+
+#ifdef HAVE_THUNAR_VFS
+  ThunarVfsMonitor     *monitor;
+  ThunarVfsPath        *thunar_vfs_path;
+  ThunarVfsMonitorHandle *monitor_handle;
+#endif
 };
 
 typedef enum
@@ -84,6 +93,11 @@
   GtkWidget            *statusbar;
 
   GtkAccelGroup        *accel_group;
+
+#ifdef HAVE_THUNAR_VFS
+  ThunarVfsPath        *thunar_vfs_path;
+  ThunarVfsMonitorHandle *monitor_handle;
+#endif
 };
 
 typedef struct _NotesNote       NotesNote;

Modified: xfce4-notes-plugin/trunk/panel-plugin/panel-plugin.c
===================================================================
--- xfce4-notes-plugin/trunk/panel-plugin/panel-plugin.c	2007-12-23 22:09:26 UTC (rev 3740)
+++ xfce4-notes-plugin/trunk/panel-plugin/panel-plugin.c	2007-12-23 22:10:17 UTC (rev 3741)
@@ -47,6 +47,14 @@
 
 static void             notes_plugin_destroy_timeout    (NotesPlugin *notes_plugin);
 
+#ifdef HAVE_THUNAR_VFS
+static void             notes_plugin_fs_event           (ThunarVfsMonitor *monitor,
+                                                         ThunarVfsMonitorHandle *handle,
+                                                         ThunarVfsMonitorEvent event,
+                                                         ThunarVfsPath *handle_path,
+                                                         ThunarVfsPath *event_path,
+                                                         NotesPlugin *notes_plugin);
+#endif
 static gboolean         notes_plugin_button_pressed     (NotesPlugin *notes_plugin,
                                                          GdkEventButton *event);
 static gboolean         notes_plugin_button_released    (NotesPlugin *notes_plugin,
@@ -90,8 +98,22 @@
 {
   NotesPlugin *notes_plugin = g_slice_new0 (NotesPlugin);
   notes_plugin->panel_plugin = panel_plugin;
+
+  notes_plugin->notes_path =
+    xfce_resource_save_location (XFCE_RESOURCE_DATA,
+                                 "notes/",
+                                 TRUE);
+  g_return_val_if_fail (G_LIKELY (notes_plugin->notes_path != NULL), NULL);
+
+  notes_plugin->config_file =
+    xfce_panel_plugin_save_location (notes_plugin->panel_plugin,
+                                     TRUE);
+  g_return_val_if_fail (G_LIKELY (notes_plugin->config_file != NULL), NULL);
+
+  DBG ("\nLook up file: %s\nNotes path: %s", notes_plugin->config_file,
+                                           notes_plugin->notes_path);
+
   notes_plugin->windows = NULL;
-
   notes_plugin->btn_panel = xfce_create_panel_toggle_button ();
   notes_plugin->icon_panel = gtk_image_new ();
   notes_plugin->tooltips = gtk_tooltips_new ();
@@ -122,6 +144,21 @@
                             G_CALLBACK (notes_plugin_button_released),
                             notes_plugin);
 
+#ifdef HAVE_THUNAR_VFS
+  thunar_vfs_init ();
+  notes_plugin->monitor = thunar_vfs_monitor_get_default ();
+  notes_plugin->thunar_vfs_path = thunar_vfs_path_new (notes_plugin->notes_path, NULL);
+  if (G_LIKELY (NULL != notes_plugin->thunar_vfs_path))
+    {
+	  DBG ("Monitor `%s'", thunar_vfs_path_get_name (notes_plugin->thunar_vfs_path));
+      notes_plugin->monitor_handle =
+        thunar_vfs_monitor_add_directory (notes_plugin->monitor,
+                                          notes_plugin->thunar_vfs_path,
+                                          (ThunarVfsMonitorCallback)notes_plugin_fs_event,
+                                          notes_plugin);
+    }
+#endif
+
   xfce_panel_plugin_add_action_widget (panel_plugin, notes_plugin->btn_panel);
   notes_plugin_set_selection (notes_plugin);
   gtk_widget_show_all (notes_plugin->btn_panel);
@@ -151,20 +188,6 @@
   NotesWindow          *notes_window;
   const gchar          *window_name;
 
-  notes_plugin->notes_path =
-    xfce_resource_save_location (XFCE_RESOURCE_DATA,
-                                 "notes/",
-                                 TRUE);
-  g_return_if_fail (G_LIKELY (notes_plugin->notes_path != NULL));
-
-  notes_plugin->config_file =
-    xfce_panel_plugin_save_location (notes_plugin->panel_plugin,
-                                     TRUE);
-  g_return_if_fail (G_LIKELY (notes_plugin->config_file != NULL));
-
-  DBG ("\nLook up file: %s\nNotes path: %s", notes_plugin->config_file,
-                                           notes_plugin->notes_path);
-
   /**
    * Make sure we have at least one window if window_name is NULL.  After that
    * an inital window is created and it must not be read again.
@@ -201,6 +224,8 @@
 notes_plugin_free (NotesPlugin *notes_plugin)
 {
   notes_plugin_save_data_all (notes_plugin);
+  g_object_unref (notes_plugin->monitor);
+  thunar_vfs_shutdown ();
   gtk_main_quit ();
 }
 
@@ -210,6 +235,22 @@
   notes_plugin->timeout = 0;
 }
 
+#ifdef HAVE_THUNAR_VFS
+static void
+notes_plugin_fs_event (ThunarVfsMonitor *monitor,
+                       ThunarVfsMonitorHandle *handle,
+                       ThunarVfsMonitorEvent event,
+                       ThunarVfsPath *handle_path,
+                       ThunarVfsPath *event_path,
+                       NotesPlugin *notes_plugin)
+{
+  TRACE ("event: `%d'\nhandle_path: `%s'\nevent_path: `%s'",
+         event,
+         thunar_vfs_path_get_name (handle_path),
+         thunar_vfs_path_get_name (event_path));
+}
+#endif
+
 static gboolean
 notes_plugin_button_pressed (NotesPlugin *notes_plugin,
                              GdkEventButton *event)




More information about the Goodies-commits mailing list