[Goodies-commits] r7646 - in xfce4-clipman-plugin/trunk: . panel-plugin

Mike Massonnet mmassonnet at xfce.org
Wed Jul 1 08:54:10 CEST 2009


Author: mmassonnet
Date: 2009-07-01 06:54:10 +0000 (Wed, 01 Jul 2009)
New Revision: 7646

Modified:
   xfce4-clipman-plugin/trunk/ChangeLog
   xfce4-clipman-plugin/trunk/configure.ac.in
   xfce4-clipman-plugin/trunk/panel-plugin/Makefile.am
   xfce4-clipman-plugin/trunk/panel-plugin/actions.c
   xfce4-clipman-plugin/trunk/panel-plugin/main.c
   xfce4-clipman-plugin/trunk/panel-plugin/xfce4-clipman-settings.c
Log:
Use GIO to track changes over the actions xml file

Modified: xfce4-clipman-plugin/trunk/ChangeLog
===================================================================
--- xfce4-clipman-plugin/trunk/ChangeLog	2009-06-30 14:41:12 UTC (rev 7645)
+++ xfce4-clipman-plugin/trunk/ChangeLog	2009-07-01 06:54:10 UTC (rev 7646)
@@ -1,3 +1,11 @@
+2009-05-30	Mike Massonnet
+Use GIO to track changes over the actions xml file
+
+	- panel-plugin/actions.c:
+		Use a GFile and replace old functions g_file_set/get_contents
+		against g_file_replace/load_contents. Note: the function
+		g_file_replace_contents does not work with size = -1.
+
 2009-05-29	Mike Massonnet
 Move the settings dialog outside
 

Modified: xfce4-clipman-plugin/trunk/configure.ac.in
===================================================================
--- xfce4-clipman-plugin/trunk/configure.ac.in	2009-06-30 14:41:12 UTC (rev 7645)
+++ xfce4-clipman-plugin/trunk/configure.ac.in	2009-07-01 06:54:10 UTC (rev 7646)
@@ -56,10 +56,11 @@
 dnl ***********************************
 dnl *** Check for required packages ***
 dnl ***********************************
-XDT_CHECK_PACKAGE([GLIB], [glib-2.0], [2.14.0])
+XDT_CHECK_PACKAGE([GIO], [gio-2.0], [2.16.0])
+XDT_CHECK_PACKAGE([EXO], [exo-0.3], [0.3.0])
+XDT_CHECK_PACKAGE([GLIB], [glib-2.0], [2.16.0])
 XDT_CHECK_PACKAGE([GDKX], [gdk-x11-2.0], [2.10.0])
 XDT_CHECK_PACKAGE([GTK], [gtk+-2.0], [2.10.0])
-XDT_CHECK_PACKAGE([EXO], [exo-0.3], [0.3.0])
 XDT_CHECK_PACKAGE([LIBXFCE4UTIL], [libxfce4util-1.0], [4.4.0])
 XDT_CHECK_PACKAGE([LIBXFCEGUI4], [libxfcegui4-1.0], [4.4.0])
 XDT_CHECK_PACKAGE([LIBXFCE4PANEL], [libxfce4panel-1.0], [4.4.0])

Modified: xfce4-clipman-plugin/trunk/panel-plugin/Makefile.am
===================================================================
--- xfce4-clipman-plugin/trunk/panel-plugin/Makefile.am	2009-06-30 14:41:12 UTC (rev 7645)
+++ xfce4-clipman-plugin/trunk/panel-plugin/Makefile.am	2009-07-01 06:54:10 UTC (rev 7646)
@@ -55,16 +55,18 @@
 	$(NULL)
 
 xfce4_clipman_settings_CFLAGS =						\
+	@GIO_CFLAGS@							\
+	@EXO_CFLAGS@							\
 	@GTK_CFLAGS@							\
-	@EXO_CFLAGS@							\
 	@LIBXFCEGUI4_CFLAGS@						\
 	@XFCONF_CFLAGS@							\
 	@GLADE_CFLAGS@							\
 	$(NULL)
 
 xfce4_clipman_settings_LDADD =						\
+	@GIO_LIBS@							\
+	@EXO_LIBS@							\
 	@GTK_LIBS@							\
-	@EXO_LIBS@							\
 	@LIBXFCEGUI4_LIBS@						\
 	@XFCONF_LIBS@							\
 	@GLADE_LIBS@							\
@@ -85,10 +87,11 @@
 	$(NULL)
 
 xfce4_clipman_plugin_CFLAGS =						\
+	@GIO_CFLAGS@							\
+	@EXO_CFLAGS@							\
 	@LIBX11_CFLAGS@							\
 	@GDKX_CFLAGS@							\
 	@GTK_CFLAGS@							\
-	@EXO_CFLAGS@							\
 	@LIBXFCE4UTIL_CFLAGS@						\
 	@LIBXFCEGUI4_CFLAGS@						\
 	@LIBXFCE4PANEL_CFLAGS@						\
@@ -96,10 +99,11 @@
 	$(NULL)
 
 xfce4_clipman_plugin_LDADD =						\
+	@GIO_LIBS@							\
+	@EXO_LIBS@							\
 	@LIBX11_LIBS@							\
 	@GDKX_LIBS@							\
 	@GTK_LIBS@							\
-	@EXO_LIBS@							\
 	@LIBXFCE4UTIL_LIBS@						\
 	@LIBXFCEGUI4_LIBS@						\
 	@LIBXFCE4PANEL_LIBS@						\

Modified: xfce4-clipman-plugin/trunk/panel-plugin/actions.c
===================================================================
--- xfce4-clipman-plugin/trunk/panel-plugin/actions.c	2009-06-30 14:41:12 UTC (rev 7645)
+++ xfce4-clipman-plugin/trunk/panel-plugin/actions.c	2009-07-01 06:54:10 UTC (rev 7646)
@@ -30,6 +30,11 @@
 #include <locale.h>
 #endif
 
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+
+#include <gio/gio.h>
 #include <exo/exo.h>
 #include <gtk/gtk.h>
 #include <libxfce4util/libxfce4util.h>
@@ -49,6 +54,8 @@
 
 struct _ClipmanActionsPrivate
 {
+  GFile                *file;
+  GFileMonitor         *file_monitor;
   GSList               *entries;
   GtkWidget            *menu;
 };
@@ -82,6 +89,11 @@
 
 static void             cb_entry_activated                  (GtkMenuItem *mi,
                                                              gpointer user_data);
+static void             cb_file_changed                     (ClipmanActions *actions,
+                                                             GFile *file,
+                                                             GFile *other_file,
+                                                             GFileMonitorEvent event_type);
+static gboolean         timeout_file_changed                (ClipmanActions *actions);
 
 /*
  * XML Parser declarations
@@ -344,6 +356,29 @@
   g_free (real_command);
 }
 
+static void
+cb_file_changed (ClipmanActions *actions,
+                 GFile *file,
+                 GFile *other_file,
+                 GFileMonitorEvent event_type)
+{
+  static guint timeout = 0;
+  if (event_type == G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT)
+    {
+      if (timeout > 0)
+        g_source_remove (timeout);
+      timeout = g_timeout_add_seconds (1, (GSourceFunc)timeout_file_changed, actions);
+    }
+}
+
+static gboolean
+timeout_file_changed (ClipmanActions *actions)
+{
+  _clipman_actions_free_list (actions);
+  clipman_actions_load (actions);
+  return FALSE;
+}
+
 /*
  * Misc functions
  */
@@ -355,6 +390,7 @@
   for (l = actions->priv->entries; l != NULL; l = l->next)
     __clipman_actions_entry_free (l->data);
   g_slist_free (actions->priv->entries);
+  actions->priv->entries = NULL;
 }
 
 static gint
@@ -702,40 +738,38 @@
 {
   gchar *filename;
   gchar *data;
-  gsize size;
+  gssize size;
   gboolean load;
   GMarkupParseContext *context;
   EntryParser *parser;
 
-  filename = g_strdup_printf ("%s/xfce4/panel/xfce4-clipman-actions.xml", g_get_user_config_dir ());
-  load = g_file_get_contents (filename, &data, &size, NULL);
+  load = g_file_load_contents (actions->priv->file, NULL, &data, &size, NULL, NULL);
 
   if (!load)
     {
-      g_free (filename);
       filename = g_strdup (SYSCONFDIR"/xdg/xfce4/panel/xfce4-clipman-actions.xml");
       load = g_file_get_contents (filename, &data, &size, NULL);
+      g_free (filename);
     }
 
   if (!load)
-    g_warning ("Unable to load actions from an XML file");
-
-  DBG ("Load actions from file %s", filename);
-
-  if (load)
     {
-      parser = g_slice_new0 (EntryParser);
-      parser->actions = actions;
-      parser->locale = setlocale (LC_MESSAGES, NULL);
-      context = g_markup_parse_context_new (&markup_parser, 0, parser, NULL);
-      g_markup_parse_context_parse (context, data, (gssize)size, NULL);
-      if (!g_markup_parse_context_end_parse (context, NULL))
-        g_warning ("Error parsing the XML file");
-      g_markup_parse_context_free (context);
-      g_slice_free (EntryParser, parser);
+      g_warning ("Unable to load actions from an XML file");
+      return;
     }
 
-  g_free (filename);
+  DBG ("Load actions from file");
+
+  parser = g_slice_new0 (EntryParser);
+  parser->actions = actions;
+  parser->locale = setlocale (LC_MESSAGES, NULL);
+  context = g_markup_parse_context_new (&markup_parser, 0, parser, NULL);
+  g_markup_parse_context_parse (context, data, size, NULL);
+  if (!g_markup_parse_context_end_parse (context, NULL))
+    g_warning ("Error parsing the XML file");
+  g_markup_parse_context_free (context);
+  g_slice_free (EntryParser, parser);
+
   g_free (data);
 }
 
@@ -748,7 +782,6 @@
 clipman_actions_save (ClipmanActions *actions)
 {
   ClipmanActionsEntry *entry;
-  gchar *filename;
   gchar *data;
   GString *output;
   gchar *tmp;
@@ -804,13 +837,12 @@
   g_string_append (output, "</actions>");
 
   /* And now write output to the xml file */
-  filename = g_strdup_printf ("%s/xfce4/panel/xfce4-clipman-actions.xml", g_get_user_config_dir ());
-  DBG ("Save actions to file %s", filename);
+  DBG ("Save actions to file");
   data = g_string_free (output, FALSE);
-  if (!g_file_set_contents (filename, data, -1, NULL))
-    g_warning ("Unable to write the actions to the XML file %s", filename);
+  if (!g_file_replace_contents (actions->priv->file, data, strlen (data), NULL, FALSE,
+                                G_FILE_CREATE_NONE, NULL, NULL, NULL))
+    g_warning ("Unable to write the actions to the XML file");
 
-  g_free (filename);
   g_free (data);
 }
 
@@ -854,9 +886,21 @@
 static void
 clipman_actions_init (ClipmanActions *actions)
 {
+  gchar *filename;
+
   actions->priv = GET_PRIVATE (actions);
 
+  /* Actions file */
+  filename = g_strdup_printf ("%s/xfce4/panel/xfce4-clipman-actions.xml", g_get_user_config_dir ());
+  actions->priv->file = g_file_new_for_path (filename);
+  g_free (filename);
+
+  /* Load initial actions */
   clipman_actions_load (actions);
+
+  /* Listen on xml file changes */
+  actions->priv->file_monitor = g_file_monitor_file (actions->priv->file, G_FILE_MONITOR_NONE, NULL, NULL);
+  g_signal_connect_swapped (actions->priv->file_monitor, "changed", G_CALLBACK (cb_file_changed), actions);
 }
 
 static void
@@ -864,5 +908,7 @@
 {
   ClipmanActions *actions = CLIPMAN_ACTIONS (object);
   _clipman_actions_free_list (actions);
+  g_object_unref (actions->priv->file_monitor);
+  g_object_unref (actions->priv->file);
 }
 

Modified: xfce4-clipman-plugin/trunk/panel-plugin/main.c
===================================================================
--- xfce4-clipman-plugin/trunk/panel-plugin/main.c	2009-06-30 14:41:12 UTC (rev 7645)
+++ xfce4-clipman-plugin/trunk/panel-plugin/main.c	2009-07-01 06:54:10 UTC (rev 7646)
@@ -647,7 +647,7 @@
                          "logo-icon-name", "xfce4-clipman-plugin",
                          "comments", _("Clipboard Manager for Xfce"),
                          "version", PACKAGE_VERSION,
-                         "copyright", "Copyright © 2008-2009 Mike Massonnet",
+                         "copyright", "Copyright © 2003-2009 The Xfce development team",
                          "license", license,
                          "website", "http://goodies.xfce.org/projects/panel-plugins/xfce4-clipman-plugin",
                          "website-label", "goodies.xfce.org",

Modified: xfce4-clipman-plugin/trunk/panel-plugin/xfce4-clipman-settings.c
===================================================================
--- xfce4-clipman-plugin/trunk/panel-plugin/xfce4-clipman-settings.c	2009-06-30 14:41:12 UTC (rev 7645)
+++ xfce4-clipman-plugin/trunk/panel-plugin/xfce4-clipman-settings.c	2009-07-01 06:54:10 UTC (rev 7646)
@@ -73,11 +73,8 @@
   /* GladeXML */
   gxml = glade_xml_new_from_buffer (settings_dialog_glade, settings_dialog_glade_length, NULL, NULL);
 
-  /* Settings dialog */
+  /* Dialogs */
   dialog = glade_xml_get_widget (gxml, "settings-dialog");
-
-  /* Action dialog */
-  actions = clipman_actions_get ();
   action_dialog = glade_xml_get_widget (gxml, "action-dialog");
 
   /* General settings */
@@ -423,7 +420,7 @@
 
 
 
-/* Entry Dialog */
+/* Actions Entry */
 static void
 setup_commands_treeview (GtkTreeView *treeview)
 {
@@ -633,7 +630,10 @@
   xfconf_init (NULL);
   gtk_init (&argc, &argv);
   xfconf_channel = xfconf_channel_new_with_property_base ("xfce4-panel", "/plugins/clipman");
+  actions = clipman_actions_get ();
   prop_dialog_run ();
+  g_object_unref (xfconf_channel);
+  g_object_unref (actions);
   xfconf_shutdown ();
   return 0;
 }




More information about the Goodies-commits mailing list