[libgdata] [core] Ensure GDataEntry:title follows GDataAccessRule:role



commit 3bd5972905a0af089f44aa13a148a1e997426724
Author: Philip Withnall <philip tecnocode co uk>
Date:   Tue Jul 13 09:07:09 2010 +0100

    [core] Ensure GDataEntry:title follows GDataAccessRule:role

 gdata/gdata-access-rule.c |   28 ++++++++++++++++++++++++----
 gdata/tests/general.c     |    6 ++++++
 2 files changed, 30 insertions(+), 4 deletions(-)
---
diff --git a/gdata/gdata-access-rule.c b/gdata/gdata-access-rule.c
index 386cf3b..f415002 100644
--- a/gdata/gdata-access-rule.c
+++ b/gdata/gdata-access-rule.c
@@ -141,10 +141,34 @@ gdata_access_rule_class_init (GDataAccessRuleClass *klass)
 	                                                     G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
 }
 
+static void notify_role_cb (GDataAccessRule *self, GParamSpec *pspec, gpointer user_data);
+
+static void
+notify_title_cb (GDataAccessRule *self, GParamSpec *pspec, gpointer user_data)
+{
+	/* Update GDataAccessRule:role */
+	g_signal_handlers_block_by_func (self, notify_role_cb, self);
+	gdata_access_rule_set_role (self, gdata_entry_get_title (GDATA_ENTRY (self)));
+	g_signal_handlers_unblock_by_func (self, notify_role_cb, self);
+}
+
+static void
+notify_role_cb (GDataAccessRule *self, GParamSpec *pspec, gpointer user_data)
+{
+	/* Update GDataEntry:title */
+	g_signal_handlers_block_by_func (self, notify_title_cb, self);
+	gdata_entry_set_title (GDATA_ENTRY (self), gdata_access_rule_get_role (self));
+	g_signal_handlers_unblock_by_func (self, notify_title_cb, self);
+}
+
 static void
 gdata_access_rule_init (GDataAccessRule *self)
 {
 	self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, GDATA_TYPE_ACCESS_RULE, GDataAccessRulePrivate);
+
+	/* Listen to change notifications for the entry's title, since it's linked to GDataAccessRule:role */
+	g_signal_connect (self, "notify::title", (GCallback) notify_title_cb, self);
+	g_signal_connect (self, "notify::role", (GCallback) notify_role_cb, self);
 }
 
 static void
@@ -259,10 +283,6 @@ get_xml (GDataParsable *parsable, GString *xml_string)
 {
 	GDataAccessRulePrivate *priv = GDATA_ACCESS_RULE (parsable)->priv;
 
-	/* So it's valid Atom, set the title if one doesn't already exist */
-	if (gdata_entry_get_title (GDATA_ENTRY (parsable)) == NULL)
-		gdata_entry_set_title (GDATA_ENTRY (parsable), priv->role);
-
 	/* Chain up to the parent class */
 	GDATA_PARSABLE_CLASS (gdata_access_rule_parent_class)->get_xml (parsable, xml_string);
 
diff --git a/gdata/tests/general.c b/gdata/tests/general.c
index e9e09e9..e3a3e35 100644
--- a/gdata/tests/general.c
+++ b/gdata/tests/general.c
@@ -801,6 +801,12 @@ test_access_rule_get_xml (void)
 	g_free (scope_type3);
 	g_free (scope_value3);
 
+	/* Test that the GDataAccessRule:role and GDataEntry:title properties are linked */
+	gdata_entry_set_title (rule, "Another role");
+	g_assert_cmpstr (gdata_access_rule_get_role (rule), ==, "Another role");
+	gdata_access_rule_set_role (rule, GDATA_ACCESS_ROLE_NONE);
+	g_assert_cmpstr (gdata_entry_get_title (GDATA_ENTRY (rule)), ==, "none");
+
 	g_object_unref (rule);
 	g_object_unref (rule2);
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]