[evolution-couchdb] Support URL fields of contact records



commit 04853c99e048e205cde3223de2dc82eda7c9a003
Author: Rodrigo Moya <rodrigo gnome-db org>
Date:   Wed Aug 26 11:20:17 2009 +0200

    Support URL fields of contact records
    Set the couchdb_instance on the config dialog when defaulting to per-user
    CouchDB instance

 addressbook/e-book-backend-couchdb.c |   94 ++++++++++++++++++++++++++++++++-
 plugins/couchdb-contacts-source.c    |    2 +
 2 files changed, 93 insertions(+), 3 deletions(-)
---
diff --git a/addressbook/e-book-backend-couchdb.c b/addressbook/e-book-backend-couchdb.c
index 5816dd5..23fcce7 100644
--- a/addressbook/e-book-backend-couchdb.c
+++ b/addressbook/e-book-backend-couchdb.c
@@ -220,9 +220,6 @@ vcard_from_couch_document (CouchDBDocument *document)
 									e_vcard_attribute_param_new (EVC_TYPE),
 									EVC_X_COMPANY);
 			} else {
-				//e_vcard_attribute_add_param_with_value (attr,
-				//					e_vcard_attribute_param_new (EVC_TYPE),
-				//					"OTHER");
 				e_vcard_attribute_add_param_with_value (attr,
 									e_vcard_attribute_param_new (EVC_TYPE),
 									"VOICE");
@@ -268,6 +265,40 @@ vcard_from_couch_document (CouchDBDocument *document)
 		e_contact_address_free (contact_address);
 	}
 
+	/* parse URLs */
+	list = couchdb_document_contact_get_urls (document);
+	while (list != NULL) {
+		const char *description_str, *address_str, *uuid_str;
+		EVCardAttribute *attr;
+		CouchDBStructField *url = (CouchDBStructField *) list->data;
+
+		address_str = couchdb_document_contact_url_get_address (url);
+		description_str = couchdb_document_contact_url_get_description (url);
+		uuid_str = couchdb_struct_field_get_uuid (url);
+
+		if (description_str != NULL) {
+			if (g_ascii_strcasecmp (description_str, "blog") == 0)
+				attr = e_vcard_attribute_new (NULL, e_contact_vcard_attribute (E_CONTACT_BLOG_URL));
+			else
+				attr = e_vcard_attribute_new (NULL, e_contact_vcard_attribute (E_CONTACT_HOMEPAGE_URL));
+		} else
+			attr = e_vcard_attribute_new (NULL, e_contact_vcard_attribute (E_CONTACT_HOMEPAGE_URL));
+
+		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 urls from list */
+		list = g_slist_remove (list, url);
+		couchdb_struct_field_unref (url);
+	}
+
 	/* birth date */
 	str = (char *) couchdb_document_contact_get_birth_date (document);
 	if (str) {
@@ -424,6 +455,34 @@ contact_phone_to_struct_field (EVCardAttribute *attr)
 	return sf;
 }
 
+static CouchDBStructField *
+contact_url_to_struct_field (EVCardAttribute *attr, const gchar *description)
+{
+	const gchar *address, *uuid;
+	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_url_new (NULL, address, description);
+
+	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;
+		}
+	}
+
+	return couchdb_document_contact_url_new (uuid, address, description);
+}
+
 static CouchDBDocument *
 couch_document_from_contact (EBookBackendCouchDB *couchdb_backend, EContact *contact)
 {
@@ -554,6 +613,31 @@ couch_document_from_contact (EBookBackendCouchDB *couchdb_backend, EContact *con
 		g_slist_free (list);
 	}
 
+	/* URLS */
+	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_HOMEPAGE_URL)) == 0)
+			sf = contact_url_to_struct_field (attr, "home page");
+		else if (g_strcmp0 (e_vcard_attribute_get_name (attr),
+				    e_contact_vcard_attribute (E_CONTACT_BLOG_URL)) == 0)
+			sf = contact_url_to_struct_field (attr, "blog");
+
+		if (sf != NULL)
+			list = g_slist_append (list, sf);
+	}
+
+	if (list != NULL) {
+		couchdb_document_contact_set_urls (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) {
@@ -990,6 +1074,10 @@ e_book_backend_couchdb_get_supported_fields (EBookBackend *backend,
 	fields = g_list_append (fields, g_strdup (e_contact_field_name (E_CONTACT_ANNIVERSARY)));
 	fields = g_list_append (fields, g_strdup (e_contact_field_name (E_CONTACT_NOTE)));
 
+	/* URLS */
+	fields = g_list_append (fields, g_strdup (e_contact_field_name (E_CONTACT_HOMEPAGE_URL)));
+	fields = g_list_append (fields, g_strdup (e_contact_field_name (E_CONTACT_BLOG_URL)));
+
 	/* Company fields */
 	fields = g_list_append (fields, g_strdup (e_contact_field_name (E_CONTACT_ORG)));
 	fields = g_list_append (fields, g_strdup (e_contact_field_name (E_CONTACT_ORG_UNIT)));
diff --git a/plugins/couchdb-contacts-source.c b/plugins/couchdb-contacts-source.c
index 83344b0..35e5eff 100644
--- a/plugins/couchdb-contacts-source.c
+++ b/plugins/couchdb-contacts-source.c
@@ -272,6 +272,8 @@ plugin_couchdb_contacts (EPlugin *epl, EConfigHookItemFactoryData *data)
 				    e_source_get_property (ui->source, "couchdb_remote_server"));
 	} else {
 		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (ui->user_db_button), TRUE);
+		if (!property)
+			e_source_set_property (ui->source, "couchdb_instance", "system");
 		gtk_widget_set_sensitive (ui->remote_db_entry, FALSE);
 	}
 



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