[evolution-couchdb] Support IM addresses fields
- From: Rodrigo Moya <rodrigo src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [evolution-couchdb] Support IM addresses fields
- Date: Tue, 22 Sep 2009 22:52:42 +0000 (UTC)
commit 29205523a6723cd64159712468aa64d8c04aadf4
Author: Rodrigo Moya <rodrigo gnome-db org>
Date: Wed Sep 23 00:52:09 2009 +0200
Support IM addresses fields
addressbook/e-book-backend-couchdb.c | 155 +++++++++++++++++++++++++++++++++-
1 files changed, 153 insertions(+), 2 deletions(-)
---
diff --git a/addressbook/e-book-backend-couchdb.c b/addressbook/e-book-backend-couchdb.c
index 0c2d56e..f767395 100644
--- a/addressbook/e-book-backend-couchdb.c
+++ b/addressbook/e-book-backend-couchdb.c
@@ -300,6 +300,66 @@ vcard_from_couch_document (CouchDBDocument *document)
couchdb_struct_field_unref (url);
}
+ /* parse IM addresses */
+ list = couchdb_document_contact_get_im_addresses (document);
+ while (list != NULL) {
+ const char *address_str, *description_str, *protocol_str, *uuid_str;
+ EVCardAttribute *attr = NULL;
+ CouchDBStructField *im = (CouchDBStructField *) list->data;
+
+ address_str = couchdb_document_contact_im_get_address (im);
+ description_str = couchdb_document_contact_im_get_description (im);
+ protocol_str = couchdb_document_contact_im_get_protocol (im);
+ uuid_str = couchdb_struct_field_get_uuid (im);
+
+ if (protocol_str != NULL) {
+ if (g_strcmp0 (protocol_str, COUCHDB_DOCUMENT_CONTACT_IM_PROTOCOL_AIM) == 0)
+ attr = e_vcard_attribute_new (NULL, e_contact_vcard_attribute (E_CONTACT_IM_AIM));
+ else if (g_strcmp0 (protocol_str, COUCHDB_DOCUMENT_CONTACT_IM_PROTOCOL_GADU_GADU) == 0)
+ attr = e_vcard_attribute_new (NULL, e_contact_vcard_attribute (E_CONTACT_IM_GADUGADU));
+ else if (g_strcmp0 (protocol_str, COUCHDB_DOCUMENT_CONTACT_IM_PROTOCOL_GROUPWISE) == 0)
+ attr = e_vcard_attribute_new (NULL, e_contact_vcard_attribute (E_CONTACT_IM_GROUPWISE));
+ else if (g_strcmp0 (protocol_str, COUCHDB_DOCUMENT_CONTACT_IM_PROTOCOL_ICQ) == 0)
+ attr = e_vcard_attribute_new (NULL, e_contact_vcard_attribute (E_CONTACT_IM_ICQ));
+ else if (g_strcmp0 (protocol_str, COUCHDB_DOCUMENT_CONTACT_IM_PROTOCOL_JABBER) == 0)
+ attr = e_vcard_attribute_new (NULL, e_contact_vcard_attribute (E_CONTACT_IM_JABBER));
+ else if (g_strcmp0 (protocol_str, COUCHDB_DOCUMENT_CONTACT_IM_PROTOCOL_MSN) == 0)
+ attr = e_vcard_attribute_new (NULL, e_contact_vcard_attribute (E_CONTACT_IM_MSN));
+ else if (g_strcmp0 (protocol_str, COUCHDB_DOCUMENT_CONTACT_IM_PROTOCOL_SKYPE) == 0)
+ attr = e_vcard_attribute_new (NULL, e_contact_vcard_attribute (E_CONTACT_IM_SKYPE));
+ else if (g_strcmp0 (protocol_str, COUCHDB_DOCUMENT_CONTACT_IM_PROTOCOL_YAHOO) == 0)
+ attr = e_vcard_attribute_new (NULL, e_contact_vcard_attribute (E_CONTACT_IM_YAHOO));
+
+ if (attr != NULL) {
+ if (description_str) {
+ if (!g_ascii_strcasecmp (description_str, "home")) {
+ e_vcard_attribute_add_param_with_value (attr,
+ e_vcard_attribute_param_new (EVC_TYPE),
+ "HOME");
+ } else if (!g_ascii_strcasecmp (description_str, "work")) {
+ e_vcard_attribute_add_param_with_value (attr,
+ e_vcard_attribute_param_new (EVC_TYPE),
+ "WORK");
+ }
+ }
+
+ if (uuid_str != NULL) {
+ EVCardAttributeParam *param;
+
+ param = e_vcard_attribute_param_new (COUCHDB_UUID_PROP);
+ e_vcard_attribute_add_param_with_value (attr, param, uuid_str);
+ }
+
+ e_vcard_attribute_add_value (attr, address_str);
+ e_vcard_add_attribute (E_VCARD (contact), attr);
+ }
+ }
+
+ /* remove addresses from list */
+ list = g_slist_remove (list, im);
+ couchdb_struct_field_unref (im);
+ }
+
/* birth date */
str = (char *) couchdb_document_contact_get_birth_date (document);
if (str) {
@@ -407,7 +467,7 @@ contact_phone_to_struct_field (EVCardAttribute *attr)
GList *v;
EVCardAttributeParam *p = pl->data;
- if (!g_strcmp0 (EVC_TYPE, e_vcard_attribute_param_get_name (p)) != 0) {
+ if (g_strcmp0 (EVC_TYPE, e_vcard_attribute_param_get_name (p)) == 0) {
v = e_vcard_attribute_param_get_values (p);
while (v && v->data) {
if (g_ascii_strcasecmp ((const gchar *) v->data, "HOME") == 0)
@@ -474,7 +534,7 @@ contact_url_to_struct_field (EVCardAttribute *attr, const gchar *description)
GList *v;
EVCardAttributeParam *p = pl->data;
- if (!g_strcmp0 (COUCHDB_UUID_PROP, e_vcard_attribute_param_get_name (p)) != 0) {
+ if (g_strcmp0 (COUCHDB_UUID_PROP, e_vcard_attribute_param_get_name (p)) == 0) {
v = e_vcard_attribute_param_get_values (p);
if (v && v->data)
uuid = (const gchar *) v->data;
@@ -484,6 +544,44 @@ contact_url_to_struct_field (EVCardAttribute *attr, const gchar *description)
return couchdb_document_contact_url_new (uuid, address, description);
}
+static CouchDBStructField *
+contact_im_to_struct_field (EVCardAttribute *attr, const gchar *protocol)
+{
+ const gchar *address, *description = NULL, *uuid = NULL;
+ GList *params, *pl;
+
+ address = e_vcard_attribute_get_value (attr);
+ if (!address)
+ return NULL;
+
+ params = e_vcard_attribute_get_params (attr);
+ if (!params)
+ return couchdb_document_contact_im_new (NULL, address, "other", protocol);
+
+ for (pl = params; pl != NULL; pl = pl->next) {
+ GList *v;
+ EVCardAttributeParam *p = pl->data;
+
+ if (g_strcmp0 (COUCHDB_UUID_PROP, e_vcard_attribute_param_get_name (p)) == 0) {
+ v = e_vcard_attribute_param_get_values (p);
+ if (v && v->data)
+ uuid = (const gchar *) v->data;
+ } else if (g_strcmp0 (EVC_TYPE, e_vcard_attribute_param_get_name (p)) == 0) {
+ v = e_vcard_attribute_param_get_values (p);
+ if (v && v->data) {
+ if (g_strcmp0 ("HOME", (const gchar *) v->data) == 0)
+ description = "home";
+ else if (g_strcmp0 ("WORK", (const gchar *) v->data) == 0)
+ description = "work";
+ else
+ description = "other";
+ }
+ }
+ }
+
+ return couchdb_document_contact_im_new (uuid, address, description, protocol);
+}
+
static CouchDBDocument *
couch_document_from_contact (EBookBackendCouchDB *couchdb_backend, EContact *contact)
{
@@ -639,6 +737,49 @@ couch_document_from_contact (EBookBackendCouchDB *couchdb_backend, EContact *con
g_slist_free (list);
}
+ /* IM addresses */
+ list = NULL;
+ attr_list = e_vcard_get_attributes (E_VCARD (contact));
+ for (al = attr_list; al != NULL; al = al->next) {
+ CouchDBStructField *sf = NULL;
+ EVCardAttribute *attr = (EVCardAttribute *) al->data;
+
+ if (g_strcmp0 (e_vcard_attribute_get_name (attr),
+ e_contact_vcard_attribute (E_CONTACT_IM_AIM)) == 0)
+ sf = contact_im_to_struct_field (attr, COUCHDB_DOCUMENT_CONTACT_IM_PROTOCOL_AIM);
+ else if (g_strcmp0 (e_vcard_attribute_get_name (attr),
+ e_contact_vcard_attribute (E_CONTACT_IM_GADUGADU)) == 0)
+ sf = contact_im_to_struct_field (attr, COUCHDB_DOCUMENT_CONTACT_IM_PROTOCOL_GADU_GADU);
+ else if (g_strcmp0 (e_vcard_attribute_get_name (attr),
+ e_contact_vcard_attribute (E_CONTACT_IM_GROUPWISE)) == 0)
+ sf = contact_im_to_struct_field (attr, COUCHDB_DOCUMENT_CONTACT_IM_PROTOCOL_GROUPWISE);
+ else if (g_strcmp0 (e_vcard_attribute_get_name (attr),
+ e_contact_vcard_attribute (E_CONTACT_IM_ICQ)) == 0)
+ sf = contact_im_to_struct_field (attr, COUCHDB_DOCUMENT_CONTACT_IM_PROTOCOL_ICQ);
+ else if (g_strcmp0 (e_vcard_attribute_get_name (attr),
+ e_contact_vcard_attribute (E_CONTACT_IM_JABBER)) == 0)
+ sf = contact_im_to_struct_field (attr, COUCHDB_DOCUMENT_CONTACT_IM_PROTOCOL_JABBER);
+ else if (g_strcmp0 (e_vcard_attribute_get_name (attr),
+ e_contact_vcard_attribute (E_CONTACT_IM_MSN)) == 0)
+ sf = contact_im_to_struct_field (attr, COUCHDB_DOCUMENT_CONTACT_IM_PROTOCOL_MSN);
+ else if (g_strcmp0 (e_vcard_attribute_get_name (attr),
+ e_contact_vcard_attribute (E_CONTACT_IM_SKYPE)) == 0)
+ sf = contact_im_to_struct_field (attr, COUCHDB_DOCUMENT_CONTACT_IM_PROTOCOL_SKYPE);
+ else if (g_strcmp0 (e_vcard_attribute_get_name (attr),
+ e_contact_vcard_attribute (E_CONTACT_IM_YAHOO)) == 0)
+ sf = contact_im_to_struct_field (attr, COUCHDB_DOCUMENT_CONTACT_IM_PROTOCOL_YAHOO);
+
+ if (sf != NULL)
+ list = g_slist_append (list, sf);
+ }
+
+ if (list != NULL) {
+ couchdb_document_contact_set_im_addresses (document, list);
+
+ g_slist_foreach (list, (GFunc) couchdb_struct_field_unref, NULL);
+ g_slist_free (list);
+ }
+
/* birth date */
dt = (EContactDate *) e_contact_get_const (contact, E_CONTACT_BIRTH_DATE);
if (dt) {
@@ -1208,6 +1349,16 @@ e_book_backend_couchdb_get_supported_fields (EBookBackend *backend,
fields = g_list_append (fields, g_strdup (e_contact_field_name (E_CONTACT_ADDRESS_WORK)));
fields = g_list_append (fields, g_strdup (e_contact_field_name (E_CONTACT_ADDRESS_OTHER)));
+ /* IM addresses */
+ fields = g_list_append (fields, g_strdup (e_contact_field_name (E_CONTACT_IM_AIM)));
+ fields = g_list_append (fields, g_strdup (e_contact_field_name (E_CONTACT_IM_GADUGADU)));
+ fields = g_list_append (fields, g_strdup (e_contact_field_name (E_CONTACT_IM_GROUPWISE)));
+ fields = g_list_append (fields, g_strdup (e_contact_field_name (E_CONTACT_IM_ICQ)));
+ fields = g_list_append (fields, g_strdup (e_contact_field_name (E_CONTACT_IM_JABBER)));
+ fields = g_list_append (fields, g_strdup (e_contact_field_name (E_CONTACT_IM_MSN)));
+ fields = g_list_append (fields, g_strdup (e_contact_field_name (E_CONTACT_IM_SKYPE)));
+ fields = g_list_append (fields, g_strdup (e_contact_field_name (E_CONTACT_IM_YAHOO)));
+
e_data_book_respond_get_supported_fields (book, opid,
GNOME_Evolution_Addressbook_Success, fields);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]