[Xfce4-commits] r26839 - in xfconf/trunk: tests/property-changed-signal xfconf

Brian Tarricone kelnos at xfce.org
Tue Apr 15 07:56:43 CEST 2008


Author: kelnos
Date: 2008-04-15 05:56:43 +0000 (Tue, 15 Apr 2008)
New Revision: 26839

Added:
   xfconf/trunk/tests/property-changed-signal/t-string-changed-signal-detailed.c
Modified:
   xfconf/trunk/tests/property-changed-signal/Makefile.am
   xfconf/trunk/tests/property-changed-signal/t-string-changed-signal.c
   xfconf/trunk/xfconf/xfconf-channel.c
Log:
make XfconfChannel::property-changed allow a prop name signal detail

this way you can get a signal for changes to all properties in a channel
by connecting to "property-changed", or just one property by connecting
to "property-changed::/property/name"


Modified: xfconf/trunk/tests/property-changed-signal/Makefile.am
===================================================================
--- xfconf/trunk/tests/property-changed-signal/Makefile.am	2008-04-15 05:41:01 UTC (rev 26838)
+++ xfconf/trunk/tests/property-changed-signal/Makefile.am	2008-04-15 05:56:43 UTC (rev 26839)
@@ -1,6 +1,8 @@
 check_PROGRAMS = \
-	t-string-changed-signal
+	t-string-changed-signal \
+	t-string-changed-signal-detailed
 
 t_string_changed_signal_SOURCES = t-string-changed-signal.c
+t_string_changed_signal_detailed_SOURCES = t-string-changed-signal-detailed.c
 
 include $(top_srcdir)/tests/Makefile.inc

Copied: xfconf/trunk/tests/property-changed-signal/t-string-changed-signal-detailed.c (from rev 26835, xfconf/trunk/tests/property-changed-signal/t-string-changed-signal.c)
===================================================================
--- xfconf/trunk/tests/property-changed-signal/t-string-changed-signal-detailed.c	                        (rev 0)
+++ xfconf/trunk/tests/property-changed-signal/t-string-changed-signal-detailed.c	2008-04-15 05:56:43 UTC (rev 26839)
@@ -0,0 +1,82 @@
+/*
+ *  xfconf
+ *
+ *  Copyright (c) 2008 Brian Tarricone <bjt23 at cornell.edu>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; version 2 of the License ONLY.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU Library General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include "tests-common.h"
+
+#include <string.h>
+
+typedef struct
+{
+    GMainLoop *mloop;
+    gboolean got_signal;
+} SignalTestData;
+
+static void
+test_signal_changed(XfconfChannel *channel,
+                    const gchar *property,
+                    gpointer user_data)
+{
+    SignalTestData *std = user_data;
+    if(!strcmp(property, test_string_property))
+        std->got_signal = TRUE;
+    else
+        std->got_signal = FALSE;
+    g_main_loop_quit(std->mloop);
+}
+
+static gboolean
+test_watchdog(gpointer data)
+{
+    SignalTestData *std = data;
+    g_main_loop_quit(std->mloop);
+    return FALSE;
+}
+
+int
+main(int argc,
+     char **argv)
+{
+    XfconfChannel *channel;
+    SignalTestData std = { NULL, FALSE };
+    gchar detailed_signal[512];
+    
+    std.mloop = g_main_loop_new(NULL, FALSE);
+
+    if(!xfconf_tests_start())
+        return 1;
+    
+    channel = xfconf_channel_new(TEST_CHANNEL_NAME);
+    g_snprintf(detailed_signal, sizeof(detailed_signal),
+               "property-changed::%s", test_string_property);
+    g_signal_connect(G_OBJECT(channel), detailed_signal,
+                     G_CALLBACK(test_signal_changed), &std);
+    
+    TEST_OPERATION(xfconf_channel_set_string(channel, test_string_property, test_string));
+    TEST_OPERATION(xfconf_channel_set_int(channel, test_int_property, test_int));
+    
+    g_timeout_add(2000, test_watchdog, &std);
+    g_main_loop_run(std.mloop);
+
+    g_main_loop_unref(std.mloop);
+    g_object_unref(G_OBJECT(channel));
+    
+    xfconf_tests_end();
+    
+    return std.got_signal ? 0 : 1;
+}

Modified: xfconf/trunk/tests/property-changed-signal/t-string-changed-signal.c
===================================================================
--- xfconf/trunk/tests/property-changed-signal/t-string-changed-signal.c	2008-04-15 05:41:01 UTC (rev 26838)
+++ xfconf/trunk/tests/property-changed-signal/t-string-changed-signal.c	2008-04-15 05:56:43 UTC (rev 26839)
@@ -1,7 +1,7 @@
 /*
  *  xfconf
  *
- *  Copyright (c) 2007 Brian Tarricone <bjt23 at cornell.edu>
+ *  Copyright (c) 2008 Brian Tarricone <bjt23 at cornell.edu>
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -19,6 +19,8 @@
 
 #include "tests-common.h"
 
+#include <string.h>
+
 typedef struct
 {
     GMainLoop *mloop;
@@ -31,7 +33,8 @@
                     gpointer user_data)
 {
     SignalTestData *std = user_data;
-    std->got_signal = TRUE;
+    if(!strcmp(property, test_string_property))
+        std->got_signal = TRUE;
     g_main_loop_quit(std->mloop);
 }
 

Modified: xfconf/trunk/xfconf/xfconf-channel.c
===================================================================
--- xfconf/trunk/xfconf/xfconf-channel.c	2008-04-15 05:41:01 UTC (rev 26838)
+++ xfconf/trunk/xfconf/xfconf-channel.c	2008-04-15 05:56:43 UTC (rev 26839)
@@ -131,7 +131,8 @@
      **/
     signals[SIG_PROPERTY_CHANGED] = g_signal_new("property-changed",
                                                  XFCONF_TYPE_CHANNEL,
-                                                 G_SIGNAL_RUN_LAST,
+                                                 G_SIGNAL_RUN_LAST
+                                                 | G_SIGNAL_DETAILED,
                                                  G_STRUCT_OFFSET(XfconfChannelClass,
                                                                  property_changed),
                                                  NULL,
@@ -231,8 +232,8 @@
     if(strcmp(channel_name, channel->channel_name))
         return;
 
-    g_signal_emit(G_OBJECT(channel), signals[SIG_PROPERTY_CHANGED], 0,
-                  property);
+    g_signal_emit(G_OBJECT(channel), signals[SIG_PROPERTY_CHANGED],
+                  g_quark_from_string(property), property);
 }
 
 



More information about the Xfce4-commits mailing list