[Xfce4-commits] r26841 - in xfconf/trunk: . docs/reference docs/reference/tmpl xfconf xfconf-gtk

Brian Tarricone kelnos at xfce.org
Tue Apr 15 10:09:38 CEST 2008


Author: kelnos
Date: 2008-04-15 08:09:38 +0000 (Tue, 15 Apr 2008)
New Revision: 26841

Added:
   xfconf/trunk/docs/reference/tmpl/xfconf-binding.sgml
   xfconf/trunk/xfconf/xfconf-binding.c
   xfconf/trunk/xfconf/xfconf-binding.h
Removed:
   xfconf/trunk/docs/reference/tmpl/xfconf-gtk.sgml
   xfconf/trunk/xfconf-gtk/Makefile.am
   xfconf/trunk/xfconf-gtk/libxfconf-gtk-0.pc.in
   xfconf/trunk/xfconf-gtk/xfconf-gtk.c
   xfconf/trunk/xfconf-gtk/xfconf-gtk.h
Modified:
   xfconf/trunk/Makefile.am
   xfconf/trunk/configure.ac.in
   xfconf/trunk/docs/reference/Makefile.am
   xfconf/trunk/docs/reference/xfconf-docs.sgml
   xfconf/trunk/docs/reference/xfconf-sections.txt
   xfconf/trunk/xfconf/Makefile.am
   xfconf/trunk/xfconf/xfconf.h
   xfconf/trunk/xfconf/xfconf.symbols
Log:
remove libxfconf-gtk and move binding functionality to libxfconf

binding functionality is not gobject-based (uses properties) and doesn't
require gtk at all


Modified: xfconf/trunk/Makefile.am
===================================================================
--- xfconf/trunk/Makefile.am	2008-04-15 06:24:31 UTC (rev 26840)
+++ xfconf/trunk/Makefile.am	2008-04-15 08:09:38 UTC (rev 26841)
@@ -4,7 +4,6 @@
 	xfconfd \
 	xfconf-query \
 	xfsettingsd \
-	xfconf-gtk \
 	po \
 	docs \
 	tests

Modified: xfconf/trunk/configure.ac.in
===================================================================
--- xfconf/trunk/configure.ac.in	2008-04-15 06:24:31 UTC (rev 26840)
+++ xfconf/trunk/configure.ac.in	2008-04-15 08:09:38 UTC (rev 26841)
@@ -196,8 +196,6 @@
 tests/property-changed-signal/Makefile
 xfconf/Makefile
 xfconf/libxfconf-0.pc
-xfconf-gtk/Makefile
-xfconf-gtk/libxfconf-gtk-0.pc
 xfconf-query/Makefile
 xfconfd/Makefile
 xfsettingsd/Makefile

Modified: xfconf/trunk/docs/reference/Makefile.am
===================================================================
--- xfconf/trunk/docs/reference/Makefile.am	2008-04-15 06:24:31 UTC (rev 26840)
+++ xfconf/trunk/docs/reference/Makefile.am	2008-04-15 08:09:38 UTC (rev 26841)
@@ -23,12 +23,10 @@
 # Used for dependencies
 HFILE_GLOB = \
 	$(top_srcdir)/xfconf/*.h \
-	$(top_srcdir)/xfconfd/*.h \
-	$(top_srcdir)/xfconf-gtk/*.h
+	$(top_srcdir)/xfconfd/*.h
 CFILE_GLOB = \
 	$(top_srcdir)/xfconf/*.c \
 	$(top_srcdir)/xfconfd/*.c \
-	$(top_srcdir)/xfconf-gtk/*.c \
 	$(top_srcdir)/common/xfconf-errors.c
 
 # Header files to ignore when scanning
@@ -64,7 +62,6 @@
 
 GTKDOC_LIBS = \
 	$(top_builddir)/xfconf/libxfconf-$(LIBXFCONF_VERSION_API).la \
-	$(top_builddir)/xfconf-gtk/libxfconf-gtk-$(LIBXFCONF_GTK_VERSION_API).la \
 	$(top_builddir)/xfconfd/xfconfd-xfconf-backend.o
 
 include $(top_srcdir)/gtk-doc.make

Added: xfconf/trunk/docs/reference/tmpl/xfconf-binding.sgml
===================================================================
--- xfconf/trunk/docs/reference/tmpl/xfconf-binding.sgml	                        (rev 0)
+++ xfconf/trunk/docs/reference/tmpl/xfconf-binding.sgml	2008-04-15 08:09:38 UTC (rev 26841)
@@ -0,0 +1,50 @@
+<!-- ##### SECTION Title ##### -->
+Xfconf-GObject Binding
+
+<!-- ##### SECTION Short_Description ##### -->
+Functions to bind Xfconf properties to GObject properties
+
+<!-- ##### SECTION Long_Description ##### -->
+<para>
+Often it may be useful to bind an Xfconf property to a GObject property.
+Settings dialogs often display the current value of an Xfconf property,
+and a user may edit the value to change the value in the Xfconf store.
+If the Xfconf property changes outside the settings dialog, the user will
+usually want to see the settings dialog automatically update to reflect
+the new value.
+
+With a single line of code, Xfconf's binding functionality can automate
+all this.
+</para>
+
+<!-- ##### SECTION See_Also ##### -->
+<para>
+
+</para>
+
+<!-- ##### SECTION Stability_Level ##### -->
+
+
+<!-- ##### FUNCTION xfconf_g_property_bind ##### -->
+<para>
+
+</para>
+
+ at channel: 
+ at xfconf_property: 
+ at xfconf_property_type: 
+ at object: 
+ at object_property: 
+
+
+<!-- ##### FUNCTION xfconf_g_property_unbind ##### -->
+<para>
+
+</para>
+
+ at channel: 
+ at xfconf_property: 
+ at object: 
+ at object_property: 
+
+

Deleted: xfconf/trunk/docs/reference/tmpl/xfconf-gtk.sgml

Modified: xfconf/trunk/docs/reference/xfconf-docs.sgml
===================================================================
--- xfconf/trunk/docs/reference/xfconf-docs.sgml	2008-04-15 06:24:31 UTC (rev 26840)
+++ xfconf/trunk/docs/reference/xfconf-docs.sgml	2008-04-15 08:09:38 UTC (rev 26841)
@@ -21,10 +21,6 @@
     <title>Xfconf Client Library</title>
     <xi:include href="xml/xfconf.xml"/>
     <xi:include href="xml/xfconf-channel.xml"/>
+    <xi:include href="xml/xfconf-binding.xml"/>
   </chapter>
-  
-  <chapter>
-    <title>Xfconf Gtk Convenience Library</title>
-    <xi:include href="xml/xfconf-gtk.xml"/>
-  </chapter>
 </book>

Modified: xfconf/trunk/docs/reference/xfconf-sections.txt
===================================================================
--- xfconf/trunk/docs/reference/xfconf-sections.txt	2008-04-15 06:24:31 UTC (rev 26840)
+++ xfconf/trunk/docs/reference/xfconf-sections.txt	2008-04-15 08:09:38 UTC (rev 26841)
@@ -85,7 +85,7 @@
 </SECTION>
 
 <SECTION>
-<FILE>xfconf-gtk</FILE>
-xfconf_gtk_editable_bind_property
-xfconf_gtk_widget_unbind
+<FILE>xfconf-binding</FILE>
+xfconf_g_property_bind
+xfconf_g_property_unbind
 </SECTION>

Modified: xfconf/trunk/xfconf/Makefile.am
===================================================================
--- xfconf/trunk/xfconf/Makefile.am	2008-04-15 06:24:31 UTC (rev 26840)
+++ xfconf/trunk/xfconf/Makefile.am	2008-04-15 08:09:38 UTC (rev 26841)
@@ -3,6 +3,7 @@
 
 libxfconfincludedir = $(includedir)/xfce4/xfconf-$(LIBXFCONF_VERSION_API)/xfconf
 libxfconfinclude_HEADERS = \
+	xfconf-binding.h \
 	xfconf-channel.h \
 	xfconf-errors.h \
 	xfconf-types.h \
@@ -10,6 +11,7 @@
 
 libxfconf_0_la_SOURCES = \
 	$(libxfconfinclude_HEADERS) \
+	xfconf-binding.c \
 	xfconf-channel.c \
 	xfconf-dbus-bindings.h \
 	xfconf-private.h \

Added: xfconf/trunk/xfconf/xfconf-binding.c
===================================================================
--- xfconf/trunk/xfconf/xfconf-binding.c	                        (rev 0)
+++ xfconf/trunk/xfconf/xfconf-binding.c	2008-04-15 08:09:38 UTC (rev 26841)
@@ -0,0 +1,302 @@
+/*
+ *  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 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+
+#include "xfconf-binding.h"
+
+
+typedef struct
+{
+    XfconfChannel *channel;
+    gchar *xfconf_property;
+    GType xfconf_property_type;
+
+    GObject *object;
+    gchar *object_property;
+    GType object_property_type;
+} XfconfGBinding;
+
+static void xfconf_g_binding_channel_destroyed(gpointer data,
+                                               GObject *where_the_object_was);
+static void xfconf_g_binding_object_destroyed(gpointer data,
+                                              GObject *where_the_object_was);
+static void xfconf_g_binding_channel_property_changed(XfconfChannel *channel,
+                                                      const gchar *property,
+                                                      gpointer user_data);
+static void xfconf_g_binding_object_property_changed(GObject *object,
+                                                     GParamSpec *pspec,
+                                                     gpointer user_data);
+
+static void
+xfconf_g_binding_free(XfconfGBinding *binding)
+{
+    if(G_UNLIKELY(!binding))
+        return;
+
+    if(binding->object) {
+        g_signal_handlers_disconnect_by_func(G_OBJECT(binding->object),
+                                            G_CALLBACK(xfconf_g_binding_object_property_changed),
+                                             binding);
+        g_object_weak_unref(G_OBJECT(binding->object),
+                            xfconf_g_binding_object_destroyed,
+                            binding);
+    }
+
+    if(binding->channel) {
+        g_signal_handlers_disconnect_by_func(G_OBJECT(binding->channel),
+                                             G_CALLBACK(xfconf_g_binding_channel_property_changed),
+                                             binding);
+        g_object_weak_unref(G_OBJECT(binding->channel),
+                            xfconf_g_binding_channel_destroyed,
+                            binding);
+    }
+
+    g_free(binding->xfconf_property);
+    g_free(binding->object_property);
+    g_free(binding);
+}
+
+static void
+xfconf_g_binding_channel_destroyed(gpointer data,
+                                   GObject *where_the_object_was)
+{
+    XfconfGBinding *binding = data;
+    binding->channel = NULL;
+    xfconf_g_binding_free(binding);
+}
+
+static void
+xfconf_g_binding_object_destroyed(gpointer data,
+                                  GObject *where_the_object_was)
+{
+    XfconfGBinding *binding = data;
+    binding->object = NULL;
+    xfconf_g_binding_free(binding);
+}
+
+static void
+xfconf_g_binding_channel_property_changed(XfconfChannel *channel,
+                                          const gchar *property,
+                                          gpointer user_data)
+{
+    XfconfGBinding *binding = user_data;
+    GValue src_val = { 0, }, dst_val = { 0, };
+
+    if(!xfconf_channel_get_property(channel, property, &src_val))
+        return;
+
+    g_value_init(&dst_val, binding->object_property_type);
+
+    if(g_value_transform(&src_val, &dst_val)) {
+        g_signal_handlers_block_by_func(binding->object,
+                                        G_CALLBACK(xfconf_g_binding_object_property_changed),
+                                        binding);
+        g_object_set_property(binding->object, binding->object_property,
+                              &dst_val);
+        g_signal_handlers_unblock_by_func(binding->object,
+                                          G_CALLBACK(xfconf_g_binding_object_property_changed),
+                                          binding);
+    }
+
+    g_value_unset(&src_val);
+    g_value_unset(&dst_val);
+}
+
+static void
+xfconf_g_binding_object_property_changed(GObject *object,
+                                         GParamSpec *pspec,
+                                         gpointer user_data)
+{
+    XfconfGBinding *binding = user_data;
+    GValue src_val = { 0, }, dst_val = { 0, };
+
+    /* this can do auto-conversion for us, but we can't easily tell if
+     * the conversion worked */
+    g_value_init(&src_val, G_PARAM_SPEC_VALUE_TYPE(pspec));
+    g_object_get_property(object, g_param_spec_get_name(pspec), &src_val);
+    
+    g_value_init(&dst_val, binding->xfconf_property_type);
+
+    if(g_value_transform(&src_val, &dst_val)) {
+        g_signal_handlers_block_by_func(G_OBJECT(binding->channel),
+                                        G_CALLBACK(xfconf_g_binding_channel_property_changed),
+                                        binding);
+        xfconf_channel_set_property(binding->channel,
+                                    binding->xfconf_property,
+                                    &dst_val);
+        g_signal_handlers_unblock_by_func(G_OBJECT(binding->channel),
+                                          G_CALLBACK(xfconf_g_binding_channel_property_changed),
+                                          binding);
+    }
+
+    g_value_unset(&src_val);
+    g_value_unset(&dst_val);
+}
+
+/**
+ * xfconf_g_property_bind:
+ * @channel: An #XfconfChannel.
+ * @xfconf_property: A property on @channel.
+ * @xfconf_property_type: The type of @xfconf_property.
+ * @object: A #GObject.
+ * @object_property: A valid property on @object.
+ *
+ * Binds an Xfconf property to a #GObject property.  If the property
+ * is changed via either the #GObject or Xfconf, the corresponding
+ * property will also be updated.
+ *
+ * Note that @xfconf_property_type is required since @xfconf_property
+ * may or may not already exist in the Xfconf store.  The type of
+ * @object_property will be determined automatically.  If the two
+ * types do not match, a conversion will be attempted.
+ **/
+void
+xfconf_g_property_bind(XfconfChannel *channel,
+                       const gchar *xfconf_property,
+                       GType xfconf_property_type,
+                       GObject *object,
+                       const gchar *object_property)
+{
+    XfconfGBinding *binding;
+    GParamSpec *pspec;
+    gchar buf[1024];
+    GList *bindings;
+
+    g_return_if_fail(XFCONF_IS_CHANNEL(channel)
+                     && xfconf_property && *xfconf_property
+                     && xfconf_property_type != G_TYPE_NONE
+                     && xfconf_property_type != G_TYPE_INVALID
+                     && G_IS_OBJECT(object)
+                     && object_property && *object_property);
+
+    pspec = g_object_class_find_property(G_OBJECT_GET_CLASS(object),
+                                         object_property);
+    if(!pspec) {
+        g_warning("Property \"%s\" is not valid for GObject type \"%s\"",
+                  object_property, G_OBJECT_TYPE_NAME(object));
+        return;
+    }
+
+    if(!g_value_type_transformable(xfconf_property_type,
+                                   G_PARAM_SPEC_VALUE_TYPE(pspec)))
+    {
+        g_warning("Converting from type \"%s\" to type \"%s\" is not supported",
+                  g_type_name(xfconf_property_type),
+                  g_type_name(G_PARAM_SPEC_VALUE_TYPE(pspec)));
+        return;
+    }
+
+    if(!g_value_type_transformable(G_PARAM_SPEC_VALUE_TYPE(pspec),
+                                   xfconf_property_type))
+    {
+        g_warning("Converting from type \"%s\" to type \"%s\" is not supported",
+                  g_type_name(G_PARAM_SPEC_VALUE_TYPE(pspec)),
+                  g_type_name(xfconf_property_type));
+        return;
+    }
+
+
+    binding = g_new0(XfconfGBinding, 1);
+    binding->channel = channel;
+    binding->xfconf_property = g_strdup(xfconf_property);
+    binding->xfconf_property_type = xfconf_property_type;
+    binding->object = object;
+    binding->object_property = g_strdup(object_property);
+    binding->object_property_type = G_PARAM_SPEC_VALUE_TYPE(pspec);
+
+    g_object_weak_ref(G_OBJECT(channel),
+                      xfconf_g_binding_channel_destroyed,
+                      binding);
+    g_object_weak_ref(G_OBJECT(object),
+                      xfconf_g_binding_object_destroyed,
+                      binding);
+    
+    g_snprintf(buf, sizeof(buf), "property-changed::%s", xfconf_property);
+    g_signal_connect(G_OBJECT(channel), buf,
+                     G_CALLBACK(xfconf_g_binding_channel_property_changed),
+                     binding);
+
+    g_snprintf(buf, sizeof(buf), "notify::%s", object_property);
+    g_signal_connect(G_OBJECT(object), buf,
+                     G_CALLBACK(xfconf_g_binding_object_property_changed),
+                     binding);
+
+    bindings = g_object_get_data(G_OBJECT(channel), "--xfconf-g-bindings");
+    if(bindings)
+        bindings = g_list_append(bindings, binding);
+    else {
+        bindings = g_list_append(bindings, binding);
+        g_object_set_data_full(G_OBJECT(channel), "--xfconf-g-bindings",
+                               bindings, (GDestroyNotify)g_list_free);
+    }
+
+    xfconf_g_binding_channel_property_changed(channel, xfconf_property,
+                                              binding);
+}
+
+/**
+ * xfconf_g_property_unbind:
+ * @channel: An #XfconfChannel.
+ * @xfconf_property: A bound property on @channel.
+ * @object: A #GObject.
+ * @object_property: A bound property on @object.
+ *
+ * Causes an Xfconf channel previously bound to a #GObject property
+ * (see xfconf_g_property_bind()) to no longer be bound.
+ **/
+void
+xfconf_g_property_unbind(XfconfChannel *channel,
+                         const gchar *xfconf_property,
+                         GObject *object,
+                         const gchar *object_property)
+{
+    GList *bindings = g_object_steal_data(G_OBJECT(channel),
+                                          "--xfconf-g-bindings");
+    GList *l;
+
+    for(l = bindings; l; l = l->next) {
+        XfconfGBinding *binding = l->data;
+
+        if(object == binding->object
+           && !strcmp(xfconf_property, binding->xfconf_property)
+           && !strcmp(object_property, binding->object_property))
+        {
+            bindings = g_list_delete_link(bindings, l);
+            xfconf_g_binding_free(binding);
+            break;
+        }
+    }
+
+    if(bindings) {
+        g_object_set_data_full(G_OBJECT(channel), "--xfconf-g-bindings",
+                               bindings, (GDestroyNotify)g_list_free);
+    }
+}
+
+
+
+#define __XFCONF_BINDING_C__
+#include "common/xfconf-aliasdef.c"

Added: xfconf/trunk/xfconf/xfconf-binding.h
===================================================================
--- xfconf/trunk/xfconf/xfconf-binding.h	                        (rev 0)
+++ xfconf/trunk/xfconf/xfconf-binding.h	2008-04-15 08:09:38 UTC (rev 26841)
@@ -0,0 +1,45 @@
+/*
+ *  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 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef __XFCONF_BINDING_H__
+#define __XFCONF_BINDING_H__
+
+#if !defined(LIBXFCONF_COMPILATION) && !defined(XFCONF_IN_XFCONF_H)
+#error "Do not include xfconf-binding.h, as this file may change or disappear in the future.  Include <xfconf/xfconf.h> instead."
+#endif
+
+#include <glib-object.h>
+#include <xfconf/xfconf-channel.h>
+
+G_BEGIN_DECLS
+
+void xfconf_g_property_bind(XfconfChannel *channel,
+                            const gchar *xfconf_property,
+                            GType xfconf_property_type,
+                            GObject *object,
+                            const gchar *object_property);
+
+void xfconf_g_property_unbind(XfconfChannel *channel,
+                              const gchar *xfconf_property,
+                              GObject *object,
+                              const gchar *object_property);
+
+G_END_DECLS
+
+#endif  /* __XFCONF_BINDING_H__ */

Modified: xfconf/trunk/xfconf/xfconf.h
===================================================================
--- xfconf/trunk/xfconf/xfconf.h	2008-04-15 06:24:31 UTC (rev 26840)
+++ xfconf/trunk/xfconf/xfconf.h	2008-04-15 08:09:38 UTC (rev 26841)
@@ -25,9 +25,12 @@
 #define XFCONF_IN_XFCONF_H
 
 #include <xfconf/xfconf-channel.h>
+#include <xfconf/xfconf-binding.h>
 #include <xfconf/xfconf-errors.h>
 #include <xfconf/xfconf-types.h>
 
+#undef XFCONF_IN_XFCONF_H
+
 G_BEGIN_DECLS
 
 gboolean xfconf_init(GError **error);

Modified: xfconf/trunk/xfconf/xfconf.symbols
===================================================================
--- xfconf/trunk/xfconf/xfconf.symbols	2008-04-15 06:24:31 UTC (rev 26840)
+++ xfconf/trunk/xfconf/xfconf.symbols	2008-04-15 08:09:38 UTC (rev 26841)
@@ -90,3 +90,11 @@
 xfconf_channel_set_structv
 #endif
 #endif
+
+/* xfconf-binding.h */
+#if IN_HEADER(__XFCONF_BINDING_H__)
+#if IN_SOURCE(__XFCONF_BINDING_C__)
+xfconf_g_object_bind
+xfconf_g_object_unbind
+#endif
+#endif

Deleted: xfconf/trunk/xfconf-gtk/Makefile.am

Deleted: xfconf/trunk/xfconf-gtk/libxfconf-gtk-0.pc.in

Deleted: xfconf/trunk/xfconf-gtk/xfconf-gtk.c

Deleted: xfconf/trunk/xfconf-gtk/xfconf-gtk.h



More information about the Xfce4-commits mailing list