[libgdata] Added methods to get the primary e-mail address (etc.) from a contact



commit ce0ac112bf3a370a2ffd727b8074fd41a54afa80
Author: Philip Withnall <philip tecnocode co uk>
Date:   Sun Apr 19 21:08:55 2009 +0100

    Added methods to get the primary e-mail address (etc.) from a contact
---
 gdata/gdata.symbols                              |    5 ++
 gdata/services/contacts/gdata-contacts-contact.c |   77 ++++++++++++++++++++++
 gdata/services/contacts/gdata-contacts-contact.h |    5 ++
 3 files changed, 87 insertions(+), 0 deletions(-)

diff --git a/gdata/gdata.symbols b/gdata/gdata.symbols
index a5b47d3..945ee80 100644
--- a/gdata/gdata.symbols
+++ b/gdata/gdata.symbols
@@ -264,14 +264,19 @@ gdata_contacts_contact_get_edited
 gdata_contacts_contact_set_edited
 gdata_contacts_contact_add_email_address
 gdata_contacts_contact_get_email_addresses
+gdata_contacts_contact_get_primary_email_address
 gdata_contacts_contact_add_im_address
 gdata_contacts_contact_get_im_addresses
+gdata_contacts_contact_get_primary_im_address
 gdata_contacts_contact_add_phone_number
 gdata_contacts_contact_get_phone_numbers
+gdata_contacts_contact_get_primary_phone_number
 gdata_contacts_contact_add_postal_address
 gdata_contacts_contact_get_postal_addresses
+gdata_contacts_contact_get_primary_postal_address
 gdata_contacts_contact_add_organization
 gdata_contacts_contact_get_organizations
+gdata_contacts_contact_get_primary_organization
 gdata_contacts_contact_get_extended_property
 gdata_contacts_contact_set_extended_property
 gdata_contacts_contact_add_group
diff --git a/gdata/services/contacts/gdata-contacts-contact.c b/gdata/services/contacts/gdata-contacts-contact.c
index a6a9f98..9b50be2 100644
--- a/gdata/services/contacts/gdata-contacts-contact.c
+++ b/gdata/services/contacts/gdata-contacts-contact.c
@@ -626,9 +626,26 @@ gdata_contacts_contact_get_email_addresses (GDataContactsContact *self)
 	return self->priv->email_addresses;
 }
 
+GDataGDEmailAddress *
+gdata_contacts_contact_get_primary_email_address (GDataContactsContact *self)
+{
+	GList *i;
+
+	g_return_val_if_fail (GDATA_IS_CONTACTS_CONTACT (self), NULL);
+
+	for (i = self->priv->email_addresses; i != NULL; i = i->next) {
+		if (((GDataGDEmailAddress*) i->data)->primary == TRUE)
+			return (GDataGDEmailAddress*) i->data;
+	}
+
+	return NULL;
+}
+
 void
 gdata_contacts_contact_add_im_address (GDataContactsContact *self, GDataGDIMAddress *im_address)
 {
+	/* TODO: Note that only one e-mail address can be the primary, but this isn't enforced.
+	 * Same for IM, etc. */
 	g_return_if_fail (GDATA_IS_CONTACTS_CONTACT (self));
 	g_return_if_fail (im_address != NULL);
 
@@ -642,6 +659,21 @@ gdata_contacts_contact_get_im_addresses (GDataContactsContact *self)
 	return self->priv->im_addresses;
 }
 
+GDataGDIMAddress *
+gdata_contacts_contact_get_primary_im_address (GDataContactsContact *self)
+{
+	GList *i;
+
+	g_return_val_if_fail (GDATA_IS_CONTACTS_CONTACT (self), NULL);
+
+	for (i = self->priv->im_addresses; i != NULL; i = i->next) {
+		if (((GDataGDIMAddress*) i->data)->primary == TRUE)
+			return (GDataGDIMAddress*) i->data;
+	}
+
+	return NULL;
+}
+
 void
 gdata_contacts_contact_add_phone_number (GDataContactsContact *self, GDataGDPhoneNumber *phone_number)
 {
@@ -658,6 +690,21 @@ gdata_contacts_contact_get_phone_numbers (GDataContactsContact *self)
 	return self->priv->phone_numbers;
 }
 
+GDataGDPhoneNumber *
+gdata_contacts_contact_get_primary_phone_number (GDataContactsContact *self)
+{
+	GList *i;
+
+	g_return_val_if_fail (GDATA_IS_CONTACTS_CONTACT (self), NULL);
+
+	for (i = self->priv->phone_numbers; i != NULL; i = i->next) {
+		if (((GDataGDPhoneNumber*) i->data)->primary == TRUE)
+			return (GDataGDPhoneNumber*) i->data;
+	}
+
+	return NULL;
+}
+
 void
 gdata_contacts_contact_add_postal_address (GDataContactsContact *self, GDataGDPostalAddress *postal_address)
 {
@@ -674,6 +721,21 @@ gdata_contacts_contact_get_postal_addresses (GDataContactsContact *self)
 	return self->priv->postal_addresses;
 }
 
+GDataGDPostalAddress *
+gdata_contacts_contact_get_primary_postal_address (GDataContactsContact *self)
+{
+	GList *i;
+
+	g_return_val_if_fail (GDATA_IS_CONTACTS_CONTACT (self), NULL);
+
+	for (i = self->priv->postal_addresses; i != NULL; i = i->next) {
+		if (((GDataGDPostalAddress*) i->data)->primary == TRUE)
+			return (GDataGDPostalAddress*) i->data;
+	}
+
+	return NULL;
+}
+
 void
 gdata_contacts_contact_add_organization (GDataContactsContact *self, GDataGDOrganization *organization)
 {
@@ -690,6 +752,21 @@ gdata_contacts_contact_get_organizations (GDataContactsContact *self)
 	return self->priv->organizations;
 }
 
+GDataGDOrganization *
+gdata_contacts_contact_get_primary_organization (GDataContactsContact *self)
+{
+	GList *i;
+
+	g_return_val_if_fail (GDATA_IS_CONTACTS_CONTACT (self), NULL);
+
+	for (i = self->priv->organizations; i != NULL; i = i->next) {
+		if (((GDataGDOrganization*) i->data)->primary == TRUE)
+			return (GDataGDOrganization*) i->data;
+	}
+
+	return NULL;
+}
+
 const gchar *
 gdata_contacts_contact_get_extended_property (GDataContactsContact *self, const gchar *name)
 {
diff --git a/gdata/services/contacts/gdata-contacts-contact.h b/gdata/services/contacts/gdata-contacts-contact.h
index 237c297..ee453e2 100644
--- a/gdata/services/contacts/gdata-contacts-contact.h
+++ b/gdata/services/contacts/gdata-contacts-contact.h
@@ -55,14 +55,19 @@ void gdata_contacts_contact_get_edited (GDataContactsContact *self, GTimeVal *ed
 void gdata_contacts_contact_set_edited (GDataContactsContact *self, GTimeVal *edited);
 void gdata_contacts_contact_add_email_address (GDataContactsContact *self, GDataGDEmailAddress *email_address);
 GList *gdata_contacts_contact_get_email_addresses (GDataContactsContact *self);
+GDataGDEmailAddress *gdata_contacts_contact_get_primary_email_address (GDataContactsContact *self);
 void gdata_contacts_contact_add_im_address (GDataContactsContact *self, GDataGDIMAddress *im_address);
 GList *gdata_contacts_contact_get_im_addresses (GDataContactsContact *self);
+GDataGDIMAddress *gdata_contacts_contact_get_primary_im_address (GDataContactsContact *self);
 void gdata_contacts_contact_add_phone_number (GDataContactsContact *self, GDataGDPhoneNumber *phone_number);
 GList *gdata_contacts_contact_get_phone_numbers (GDataContactsContact *self);
+GDataGDPhoneNumber *gdata_contacts_contact_get_primary_phone_number (GDataContactsContact *self);
 void gdata_contacts_contact_add_postal_address (GDataContactsContact *self, GDataGDPostalAddress *postal_address);
 GList *gdata_contacts_contact_get_postal_addresses (GDataContactsContact *self);
+GDataGDPostalAddress *gdata_contacts_contact_get_primary_postal_address (GDataContactsContact *self);
 void gdata_contacts_contact_add_organization (GDataContactsContact *self, GDataGDOrganization *organization);
 GList *gdata_contacts_contact_get_organizations (GDataContactsContact *self);
+GDataGDOrganization *gdata_contacts_contact_get_primary_organization (GDataContactsContact *self);
 const gchar *gdata_contacts_contact_get_extended_property (GDataContactsContact *self, const gchar *name);
 void gdata_contacts_contact_set_extended_property (GDataContactsContact *self, const gchar *name, const gchar *value);
 void gdata_contacts_contact_add_group (GDataContactsContact *self, const gchar *href);



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