[libgdata] [contacts] Add gdata_contacts_contact_set_name()



commit 4aa89019908b1c6c951ffa5695e6678b6f2c8b52
Author: Philip Withnall <philip tecnocode co uk>
Date:   Fri Mar 19 14:03:54 2010 +0000

    [contacts] Add gdata_contacts_contact_set_name()
    
    Make the #GDataContactsContact:name object writeable, instead of making
    people change the properties of the singleton GDataGDName.

 docs/reference/gdata-docs.xml                    |    4 ++
 docs/reference/gdata-sections.txt                |    1 +
 gdata/gdata.symbols                              |    1 +
 gdata/services/contacts/gdata-contacts-contact.c |   46 +++++++++++++++++++++-
 gdata/services/contacts/gdata-contacts-contact.h |    1 +
 gdata/tests/contacts.c                           |   24 ++++++++---
 6 files changed, 69 insertions(+), 8 deletions(-)
---
diff --git a/docs/reference/gdata-docs.xml b/docs/reference/gdata-docs.xml
index 6c4a917..91a09cb 100644
--- a/docs/reference/gdata-docs.xml
+++ b/docs/reference/gdata-docs.xml
@@ -158,5 +158,9 @@
 			<title>Index of new symbols in 0.6.0</title>
 			<xi:include href="xml/api-index-0.6.0.xml"><xi:fallback/></xi:include>
 		</index>
+		<index role="0.7.0">
+			<title>Index of new symbols in 0.7.0</title>
+			<xi:include href="xml/api-index-0.7.0.xml"><xi:fallback/></xi:include>
+		</index>
 	</part>
 </book>
diff --git a/docs/reference/gdata-sections.txt b/docs/reference/gdata-sections.txt
index 138021a..2c9810e 100644
--- a/docs/reference/gdata-sections.txt
+++ b/docs/reference/gdata-sections.txt
@@ -317,6 +317,7 @@ GDataContactsContact
 GDataContactsContactClass
 gdata_contacts_contact_new
 gdata_contacts_contact_get_name
+gdata_contacts_contact_set_name
 gdata_contacts_contact_get_email_addresses
 gdata_contacts_contact_get_primary_email_address
 gdata_contacts_contact_add_email_address
diff --git a/gdata/gdata.symbols b/gdata/gdata.symbols
index 893fec8..2d1a764 100644
--- a/gdata/gdata.symbols
+++ b/gdata/gdata.symbols
@@ -273,6 +273,7 @@ gdata_contacts_contact_get_type
 gdata_contacts_contact_new
 gdata_contacts_contact_get_edited
 gdata_contacts_contact_get_name
+gdata_contacts_contact_set_name
 gdata_contacts_contact_add_email_address
 gdata_contacts_contact_get_email_addresses
 gdata_contacts_contact_get_primary_email_address
diff --git a/gdata/services/contacts/gdata-contacts-contact.c b/gdata/services/contacts/gdata-contacts-contact.c
index 57b9c62..fe0b221 100644
--- a/gdata/services/contacts/gdata-contacts-contact.c
+++ b/gdata/services/contacts/gdata-contacts-contact.c
@@ -49,6 +49,7 @@
 static void gdata_contacts_contact_dispose (GObject *object);
 static void gdata_contacts_contact_finalize (GObject *object);
 static void gdata_contacts_contact_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec);
+static void gdata_contacts_contact_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec);
 static void get_xml (GDataParsable *parsable, GString *xml_string);
 static gboolean parse_xml (GDataParsable *parsable, xmlDoc *doc, xmlNode *node, gpointer user_data, GError **error);
 static void get_namespaces (GDataParsable *parsable, GHashTable *namespaces);
@@ -86,6 +87,7 @@ gdata_contacts_contact_class_init (GDataContactsContactClass *klass)
 	g_type_class_add_private (klass, sizeof (GDataContactsContactPrivate));
 
 	gobject_class->get_property = gdata_contacts_contact_get_property;
+	gobject_class->set_property = gdata_contacts_contact_set_property;
 	gobject_class->dispose = gdata_contacts_contact_dispose;
 	gobject_class->finalize = gdata_contacts_contact_finalize;
 
@@ -146,7 +148,7 @@ gdata_contacts_contact_class_init (GDataContactsContactClass *klass)
 				g_param_spec_object ("name",
 					"Name", "The contact's name in a structured representation.",
 					GDATA_TYPE_GD_NAME,
-					G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
+					G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
 }
 
 static void notify_full_name_cb (GObject *gobject, GParamSpec *pspec, GDataContactsContact *self);
@@ -244,6 +246,22 @@ gdata_contacts_contact_get_property (GObject *object, guint property_id, GValue
 	}
 }
 
+static void
+gdata_contacts_contact_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
+{
+	GDataContactsContact *self = GDATA_CONTACTS_CONTACT (object);
+
+	switch (property_id) {
+		case PROP_NAME:
+			gdata_contacts_contact_set_name (self, g_value_get_object (value));
+			break;
+		default:
+			/* We don't have any other property... */
+			G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+			break;
+	}
+}
+
 /**
  * gdata_contacts_contact_new:
  * @id: the contact's ID, or %NULL
@@ -503,6 +521,32 @@ gdata_contacts_contact_get_name (GDataContactsContact *self)
 }
 
 /**
+ * gdata_contacts_contact_set_name:
+ * @self: a #GDataContactsContact
+ * @name: the new #GDataGDName
+ *
+ * Sets the #GDataContactsContact:name property to @name, and increments its reference count.
+ *
+ * @name must not be %NULL, though all its properties may be %NULL.
+ *
+ * Since: 0.7.0
+ **/
+void
+gdata_contacts_contact_set_name (GDataContactsContact *self, GDataGDName *name)
+{
+	g_return_if_fail (GDATA_IS_CONTACTS_CONTACT (self));
+	g_return_if_fail (GDATA_IS_GD_NAME (name));
+
+	if (self->priv->name != NULL)
+		g_object_unref (self->priv->name);
+	self->priv->name = g_object_ref (name);
+	g_object_notify (G_OBJECT (self), "name");
+
+	/* Notify the change in #GDataGDName:full-name explicitly, so that our #GDataEntry:title gets updated */
+	notify_full_name_cb (G_OBJECT (name), NULL, self);
+}
+
+/**
  * gdata_contacts_contact_add_email_address:
  * @self: a #GDataContactsContact
  * @email_address: a #GDataGDEmailAddress to add
diff --git a/gdata/services/contacts/gdata-contacts-contact.h b/gdata/services/contacts/gdata-contacts-contact.h
index 8230c23..2beb5d4 100644
--- a/gdata/services/contacts/gdata-contacts-contact.h
+++ b/gdata/services/contacts/gdata-contacts-contact.h
@@ -70,6 +70,7 @@ void gdata_contacts_contact_get_edited (GDataContactsContact *self, GTimeVal *ed
 gboolean gdata_contacts_contact_is_deleted (GDataContactsContact *self);
 
 GDataGDName *gdata_contacts_contact_get_name (GDataContactsContact *self);
+void gdata_contacts_contact_set_name (GDataContactsContact *self, GDataGDName *name);
 
 void gdata_contacts_contact_add_email_address (GDataContactsContact *self, GDataGDEmailAddress *email_address);
 GList *gdata_contacts_contact_get_email_addresses (GDataContactsContact *self);
diff --git a/gdata/tests/contacts.c b/gdata/tests/contacts.c
index e30427c..0529983 100644
--- a/gdata/tests/contacts.c
+++ b/gdata/tests/contacts.c
@@ -156,6 +156,12 @@ test_insert_simple (gconstpointer service)
 	gdata_gd_name_set_full_name (name, "Lizzie Bennet");
 	g_assert_cmpstr (gdata_entry_get_title (GDATA_ENTRY (contact)), ==, "Lizzie Bennet");
 
+	name2 = gdata_gd_name_new ("John", "Smith");
+	gdata_gd_name_set_full_name (name2, "John Smith");
+	gdata_contacts_contact_set_name (contact, name2);
+	g_object_unref (name2);
+	g_assert_cmpstr (gdata_entry_get_title (GDATA_ENTRY (contact)), ==, "John Smith");
+
 	gdata_entry_set_content (GDATA_ENTRY (contact), "Notes");
 	/* TODO: Have it add this category automatically? Same for GDataCalendarEvent */
 	category = gdata_category_new ("http://schemas.google.com/contact/2008#contact";, "http://schemas.google.com/g/2005#kind";, NULL);
@@ -192,7 +198,7 @@ test_insert_simple (gconstpointer service)
 	              "edited", &edited,
 	              "deleted", &deleted,
 	              "has-photo", &has_photo,
-	              "name", &name2,
+	              "name", &name,
 	              NULL);
 
 	g_assert_cmpint (edited->tv_sec, ==, creation_time.tv_sec);
@@ -207,13 +213,17 @@ test_insert_simple (gconstpointer service)
 	xml = gdata_parsable_get_xml (GDATA_PARSABLE (contact));
 	g_assert_cmpstr (xml, ==,
 			 "<entry xmlns='http://www.w3.org/2005/Atom' "
-			 	"xmlns:gd='http://schemas.google.com/g/2005' "
-			 	"xmlns:app='http://www.w3.org/2007/app' "
-			 	"xmlns:gContact='http://schemas.google.com/contact/2008'>"
-			 	"<title type='text'>Lizzie Bennet</title>"
-			 	"<content type='text'>Notes</content>"
+				"xmlns:gd='http://schemas.google.com/g/2005' "
+				"xmlns:app='http://www.w3.org/2007/app' "
+				"xmlns:gContact='http://schemas.google.com/contact/2008'>"
+				"<title type='text'>John Smith</title>"
+				"<content type='text'>Notes</content>"
 				"<category term='http://schemas.google.com/contact/2008#contact' scheme='http://schemas.google.com/g/2005#kind'/>"
-				"<gd:name><gd:fullName>Lizzie Bennet</gd:fullName></gd:name>"
+				"<gd:name>"
+					"<gd:givenName>John</gd:givenName>"
+					"<gd:familyName>Smith</gd:familyName>"
+					"<gd:fullName>John Smith</gd:fullName>"
+				"</gd:name>"
 				"<gd:email address='liz gmail com' rel='http://schemas.google.com/g/2005#work' primary='false'/>"
 				"<gd:email address='liz example org' rel='http://schemas.google.com/g/2005#home' primary='false'/>"
 				"<gd:im address='liz gmail com' protocol='http://schemas.google.com/g/2005#GOOGLE_TALK' "



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