Merge lp:~rodrigo-moya/evolution-couchdb/support-url-fields into lp:evolution-couchdb

Proposed by Rodrigo Moya
Status: Merged
Approved by: Elliot Murphy
Approved revision: 61
Merge reported by: Rodrigo Moya
Merged at revision: not available
Proposed branch: lp:~rodrigo-moya/evolution-couchdb/support-url-fields
Merge into: lp:evolution-couchdb
Diff against target: None lines
To merge this branch: bzr merge lp:~rodrigo-moya/evolution-couchdb/support-url-fields
Reviewer Review Type Date Requested Status
John O'Brien (community) Approve
Elliot Murphy (community) Approve
Review via email: mp+10702@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Rodrigo Moya (rodrigo-moya) wrote :

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

Revision history for this message
Elliot Murphy (statik) :
review: Approve
Revision history for this message
John O'Brien (jdobrien) wrote :

This is some of the cleanest C code I have seen. very nice.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'addressbook/e-book-backend-couchdb.c'
2--- addressbook/e-book-backend-couchdb.c 2009-08-25 15:29:51 +0000
3+++ addressbook/e-book-backend-couchdb.c 2009-08-25 22:45:04 +0000
4@@ -220,9 +220,6 @@
5 e_vcard_attribute_param_new (EVC_TYPE),
6 EVC_X_COMPANY);
7 } else {
8- //e_vcard_attribute_add_param_with_value (attr,
9- // e_vcard_attribute_param_new (EVC_TYPE),
10- // "OTHER");
11 e_vcard_attribute_add_param_with_value (attr,
12 e_vcard_attribute_param_new (EVC_TYPE),
13 "VOICE");
14@@ -268,6 +265,40 @@
15 e_contact_address_free (contact_address);
16 }
17
18+ /* parse URLs */
19+ list = couchdb_document_contact_get_urls (document);
20+ while (list != NULL) {
21+ const char *description_str, *address_str, *uuid_str;
22+ EVCardAttribute *attr;
23+ CouchDBStructField *url = (CouchDBStructField *) list->data;
24+
25+ address_str = couchdb_document_contact_url_get_address (url);
26+ description_str = couchdb_document_contact_url_get_description (url);
27+ uuid_str = couchdb_struct_field_get_uuid (url);
28+
29+ if (description_str != NULL) {
30+ if (g_ascii_strcasecmp (description_str, "blog") == 0)
31+ attr = e_vcard_attribute_new (NULL, e_contact_vcard_attribute (E_CONTACT_BLOG_URL));
32+ else
33+ attr = e_vcard_attribute_new (NULL, e_contact_vcard_attribute (E_CONTACT_HOMEPAGE_URL));
34+ } else
35+ attr = e_vcard_attribute_new (NULL, e_contact_vcard_attribute (E_CONTACT_HOMEPAGE_URL));
36+
37+ if (uuid_str != NULL) {
38+ EVCardAttributeParam *param;
39+
40+ param = e_vcard_attribute_param_new (COUCHDB_UUID_PROP);
41+ e_vcard_attribute_add_param_with_value (attr, param, uuid_str);
42+ }
43+
44+ e_vcard_attribute_add_value (attr, address_str);
45+ e_vcard_add_attribute (E_VCARD (contact), attr);
46+
47+ /* remove urls from list */
48+ list = g_slist_remove (list, url);
49+ couchdb_struct_field_unref (url);
50+ }
51+
52 /* birth date */
53 str = (char *) couchdb_document_contact_get_birth_date (document);
54 if (str) {
55@@ -424,6 +455,34 @@
56 return sf;
57 }
58
59+static CouchDBStructField *
60+contact_url_to_struct_field (EVCardAttribute *attr, const gchar *description)
61+{
62+ const gchar *address, *uuid;
63+ GList *params, *pl;
64+
65+ address = e_vcard_attribute_get_value (attr);
66+ if (!address)
67+ return NULL;
68+
69+ params = e_vcard_attribute_get_params (attr);
70+ if (!params)
71+ return couchdb_document_contact_url_new (NULL, address, description);
72+
73+ for (pl = params; pl != NULL; pl = pl->next) {
74+ GList *v;
75+ EVCardAttributeParam *p = pl->data;
76+
77+ if (!g_strcmp0 (COUCHDB_UUID_PROP, e_vcard_attribute_param_get_name (p)) != 0) {
78+ v = e_vcard_attribute_param_get_values (p);
79+ if (v && v->data)
80+ uuid = (const gchar *) v->data;
81+ }
82+ }
83+
84+ return couchdb_document_contact_url_new (uuid, address, description);
85+}
86+
87 static CouchDBDocument *
88 couch_document_from_contact (EBookBackendCouchDB *couchdb_backend, EContact *contact)
89 {
90@@ -554,6 +613,31 @@
91 g_slist_free (list);
92 }
93
94+ /* URLS */
95+ list = NULL;
96+ attr_list = e_vcard_get_attributes (E_VCARD (contact));
97+ for (al = attr_list; al != NULL; al = al->next) {
98+ CouchDBStructField *sf = NULL;
99+ EVCardAttribute *attr = (EVCardAttribute *) al->data;
100+
101+ if (g_strcmp0 (e_vcard_attribute_get_name (attr),
102+ e_contact_vcard_attribute (E_CONTACT_HOMEPAGE_URL)) == 0)
103+ sf = contact_url_to_struct_field (attr, "home page");
104+ else if (g_strcmp0 (e_vcard_attribute_get_name (attr),
105+ e_contact_vcard_attribute (E_CONTACT_BLOG_URL)) == 0)
106+ sf = contact_url_to_struct_field (attr, "blog");
107+
108+ if (sf != NULL)
109+ list = g_slist_append (list, sf);
110+ }
111+
112+ if (list != NULL) {
113+ couchdb_document_contact_set_urls (document, list);
114+
115+ g_slist_foreach (list, (GFunc) couchdb_struct_field_unref, NULL);
116+ g_slist_free (list);
117+ }
118+
119 /* birth date */
120 dt = (EContactDate *) e_contact_get_const (contact, E_CONTACT_BIRTH_DATE);
121 if (dt) {
122@@ -990,6 +1074,10 @@
123 fields = g_list_append (fields, g_strdup (e_contact_field_name (E_CONTACT_ANNIVERSARY)));
124 fields = g_list_append (fields, g_strdup (e_contact_field_name (E_CONTACT_NOTE)));
125
126+ /* URLS */
127+ fields = g_list_append (fields, g_strdup (e_contact_field_name (E_CONTACT_HOMEPAGE_URL)));
128+ fields = g_list_append (fields, g_strdup (e_contact_field_name (E_CONTACT_BLOG_URL)));
129+
130 /* Company fields */
131 fields = g_list_append (fields, g_strdup (e_contact_field_name (E_CONTACT_ORG)));
132 fields = g_list_append (fields, g_strdup (e_contact_field_name (E_CONTACT_ORG_UNIT)));
133
134=== modified file 'plugins/couchdb-contacts-source.c'
135--- plugins/couchdb-contacts-source.c 2009-08-05 12:09:30 +0000
136+++ plugins/couchdb-contacts-source.c 2009-08-25 22:45:04 +0000
137@@ -272,6 +272,8 @@
138 e_source_get_property (ui->source, "couchdb_remote_server"));
139 } else {
140 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (ui->user_db_button), TRUE);
141+ if (!property)
142+ e_source_set_property (ui->source, "couchdb_instance", "system");
143 gtk_widget_set_sensitive (ui->remote_db_entry, FALSE);
144 }
145

Subscribers

People subscribed via source and target branches