Merge lp:~rodrigo-moya/evolution-couchdb/im-addresses into lp:evolution-couchdb

Proposed by Rodrigo Moya
Status: Merged
Approved by: Tim Cole
Approved revision: 69
Merge reported by: Rodrigo Moya
Merged at revision: not available
Proposed branch: lp:~rodrigo-moya/evolution-couchdb/im-addresses
Merge into: lp:evolution-couchdb
Diff against target: None lines
To merge this branch: bzr merge lp:~rodrigo-moya/evolution-couchdb/im-addresses
Reviewer Review Type Date Requested Status
Tim Cole (community) Approve
Chad Miller (community) Approve
Review via email: mp+12219@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Rodrigo Moya (rodrigo-moya) wrote :

Added support for IM addresses fields, and reworded CouchDB addressbook config dialog

Revision history for this message
Chad Miller (cmiller) wrote :

I admire your strcmp() explicit comparisons to integers, and uses of const. I dislike the space before parens in funcalls, though. Good enough.

review: Approve
Revision history for this message
Tim Cole (tcole) wrote :

Looks reasonable. I am also NOT a fan of spaces between the function name and argument list, though.

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-09-09 14:59:34 +0000
3+++ addressbook/e-book-backend-couchdb.c 2009-09-22 12:40:52 +0000
4@@ -300,6 +300,66 @@
5 couchdb_struct_field_unref (url);
6 }
7
8+ /* parse IM addresses */
9+ list = couchdb_document_contact_get_im_addresses (document);
10+ while (list != NULL) {
11+ const char *address_str, *description_str, *protocol_str, *uuid_str;
12+ EVCardAttribute *attr = NULL;
13+ CouchDBStructField *im = (CouchDBStructField *) list->data;
14+
15+ address_str = couchdb_document_contact_im_get_address (im);
16+ description_str = couchdb_document_contact_im_get_description (im);
17+ protocol_str = couchdb_document_contact_im_get_protocol (im);
18+ uuid_str = couchdb_struct_field_get_uuid (im);
19+
20+ if (protocol_str != NULL) {
21+ if (g_strcmp0 (protocol_str, COUCHDB_DOCUMENT_CONTACT_IM_PROTOCOL_AIM) == 0)
22+ attr = e_vcard_attribute_new (NULL, e_contact_vcard_attribute (E_CONTACT_IM_AIM));
23+ else if (g_strcmp0 (protocol_str, COUCHDB_DOCUMENT_CONTACT_IM_PROTOCOL_GADU_GADU) == 0)
24+ attr = e_vcard_attribute_new (NULL, e_contact_vcard_attribute (E_CONTACT_IM_GADUGADU));
25+ else if (g_strcmp0 (protocol_str, COUCHDB_DOCUMENT_CONTACT_IM_PROTOCOL_GROUPWISE) == 0)
26+ attr = e_vcard_attribute_new (NULL, e_contact_vcard_attribute (E_CONTACT_IM_GROUPWISE));
27+ else if (g_strcmp0 (protocol_str, COUCHDB_DOCUMENT_CONTACT_IM_PROTOCOL_ICQ) == 0)
28+ attr = e_vcard_attribute_new (NULL, e_contact_vcard_attribute (E_CONTACT_IM_ICQ));
29+ else if (g_strcmp0 (protocol_str, COUCHDB_DOCUMENT_CONTACT_IM_PROTOCOL_JABBER) == 0)
30+ attr = e_vcard_attribute_new (NULL, e_contact_vcard_attribute (E_CONTACT_IM_JABBER));
31+ else if (g_strcmp0 (protocol_str, COUCHDB_DOCUMENT_CONTACT_IM_PROTOCOL_MSN) == 0)
32+ attr = e_vcard_attribute_new (NULL, e_contact_vcard_attribute (E_CONTACT_IM_MSN));
33+ else if (g_strcmp0 (protocol_str, COUCHDB_DOCUMENT_CONTACT_IM_PROTOCOL_SKYPE) == 0)
34+ attr = e_vcard_attribute_new (NULL, e_contact_vcard_attribute (E_CONTACT_IM_SKYPE));
35+ else if (g_strcmp0 (protocol_str, COUCHDB_DOCUMENT_CONTACT_IM_PROTOCOL_YAHOO) == 0)
36+ attr = e_vcard_attribute_new (NULL, e_contact_vcard_attribute (E_CONTACT_IM_YAHOO));
37+
38+ if (attr != NULL) {
39+ if (description_str) {
40+ if (!g_ascii_strcasecmp (description_str, "home")) {
41+ e_vcard_attribute_add_param_with_value (attr,
42+ e_vcard_attribute_param_new (EVC_TYPE),
43+ "HOME");
44+ } else if (!g_ascii_strcasecmp (description_str, "work")) {
45+ e_vcard_attribute_add_param_with_value (attr,
46+ e_vcard_attribute_param_new (EVC_TYPE),
47+ "WORK");
48+ }
49+ }
50+
51+ if (uuid_str != NULL) {
52+ EVCardAttributeParam *param;
53+
54+ param = e_vcard_attribute_param_new (COUCHDB_UUID_PROP);
55+ e_vcard_attribute_add_param_with_value (attr, param, uuid_str);
56+ }
57+
58+ e_vcard_attribute_add_value (attr, address_str);
59+ e_vcard_add_attribute (E_VCARD (contact), attr);
60+ }
61+ }
62+
63+ /* remove addresses from list */
64+ list = g_slist_remove (list, im);
65+ couchdb_struct_field_unref (im);
66+ }
67+
68 /* birth date */
69 str = (char *) couchdb_document_contact_get_birth_date (document);
70 if (str) {
71@@ -407,7 +467,7 @@
72 GList *v;
73 EVCardAttributeParam *p = pl->data;
74
75- if (!g_strcmp0 (EVC_TYPE, e_vcard_attribute_param_get_name (p)) != 0) {
76+ if (g_strcmp0 (EVC_TYPE, e_vcard_attribute_param_get_name (p)) == 0) {
77 v = e_vcard_attribute_param_get_values (p);
78 while (v && v->data) {
79 if (g_ascii_strcasecmp ((const gchar *) v->data, "HOME") == 0)
80@@ -474,7 +534,7 @@
81 GList *v;
82 EVCardAttributeParam *p = pl->data;
83
84- if (!g_strcmp0 (COUCHDB_UUID_PROP, e_vcard_attribute_param_get_name (p)) != 0) {
85+ if (g_strcmp0 (COUCHDB_UUID_PROP, e_vcard_attribute_param_get_name (p)) == 0) {
86 v = e_vcard_attribute_param_get_values (p);
87 if (v && v->data)
88 uuid = (const gchar *) v->data;
89@@ -484,6 +544,44 @@
90 return couchdb_document_contact_url_new (uuid, address, description);
91 }
92
93+static CouchDBStructField *
94+contact_im_to_struct_field (EVCardAttribute *attr, const gchar *protocol)
95+{
96+ const gchar *address, *description = NULL, *uuid = NULL;
97+ GList *params, *pl;
98+
99+ address = e_vcard_attribute_get_value (attr);
100+ if (!address)
101+ return NULL;
102+
103+ params = e_vcard_attribute_get_params (attr);
104+ if (!params)
105+ return couchdb_document_contact_im_new (NULL, address, "other", protocol);
106+
107+ for (pl = params; pl != NULL; pl = pl->next) {
108+ GList *v;
109+ EVCardAttributeParam *p = pl->data;
110+
111+ if (g_strcmp0 (COUCHDB_UUID_PROP, e_vcard_attribute_param_get_name (p)) == 0) {
112+ v = e_vcard_attribute_param_get_values (p);
113+ if (v && v->data)
114+ uuid = (const gchar *) v->data;
115+ } else if (g_strcmp0 (EVC_TYPE, e_vcard_attribute_param_get_name (p)) == 0) {
116+ v = e_vcard_attribute_param_get_values (p);
117+ if (v && v->data) {
118+ if (g_strcmp0 ("HOME", (const gchar *) v->data) == 0)
119+ description = "home";
120+ else if (g_strcmp0 ("WORK", (const gchar *) v->data) == 0)
121+ description = "work";
122+ else
123+ description = "other";
124+ }
125+ }
126+ }
127+
128+ return couchdb_document_contact_im_new (uuid, address, description, protocol);
129+}
130+
131 static CouchDBDocument *
132 couch_document_from_contact (EBookBackendCouchDB *couchdb_backend, EContact *contact)
133 {
134@@ -639,6 +737,49 @@
135 g_slist_free (list);
136 }
137
138+ /* IM addresses */
139+ list = NULL;
140+ attr_list = e_vcard_get_attributes (E_VCARD (contact));
141+ for (al = attr_list; al != NULL; al = al->next) {
142+ CouchDBStructField *sf = NULL;
143+ EVCardAttribute *attr = (EVCardAttribute *) al->data;
144+
145+ if (g_strcmp0 (e_vcard_attribute_get_name (attr),
146+ e_contact_vcard_attribute (E_CONTACT_IM_AIM)) == 0)
147+ sf = contact_im_to_struct_field (attr, COUCHDB_DOCUMENT_CONTACT_IM_PROTOCOL_AIM);
148+ else if (g_strcmp0 (e_vcard_attribute_get_name (attr),
149+ e_contact_vcard_attribute (E_CONTACT_IM_GADUGADU)) == 0)
150+ sf = contact_im_to_struct_field (attr, COUCHDB_DOCUMENT_CONTACT_IM_PROTOCOL_GADU_GADU);
151+ else if (g_strcmp0 (e_vcard_attribute_get_name (attr),
152+ e_contact_vcard_attribute (E_CONTACT_IM_GROUPWISE)) == 0)
153+ sf = contact_im_to_struct_field (attr, COUCHDB_DOCUMENT_CONTACT_IM_PROTOCOL_GROUPWISE);
154+ else if (g_strcmp0 (e_vcard_attribute_get_name (attr),
155+ e_contact_vcard_attribute (E_CONTACT_IM_ICQ)) == 0)
156+ sf = contact_im_to_struct_field (attr, COUCHDB_DOCUMENT_CONTACT_IM_PROTOCOL_ICQ);
157+ else if (g_strcmp0 (e_vcard_attribute_get_name (attr),
158+ e_contact_vcard_attribute (E_CONTACT_IM_JABBER)) == 0)
159+ sf = contact_im_to_struct_field (attr, COUCHDB_DOCUMENT_CONTACT_IM_PROTOCOL_JABBER);
160+ else if (g_strcmp0 (e_vcard_attribute_get_name (attr),
161+ e_contact_vcard_attribute (E_CONTACT_IM_MSN)) == 0)
162+ sf = contact_im_to_struct_field (attr, COUCHDB_DOCUMENT_CONTACT_IM_PROTOCOL_MSN);
163+ else if (g_strcmp0 (e_vcard_attribute_get_name (attr),
164+ e_contact_vcard_attribute (E_CONTACT_IM_SKYPE)) == 0)
165+ sf = contact_im_to_struct_field (attr, COUCHDB_DOCUMENT_CONTACT_IM_PROTOCOL_SKYPE);
166+ else if (g_strcmp0 (e_vcard_attribute_get_name (attr),
167+ e_contact_vcard_attribute (E_CONTACT_IM_YAHOO)) == 0)
168+ sf = contact_im_to_struct_field (attr, COUCHDB_DOCUMENT_CONTACT_IM_PROTOCOL_YAHOO);
169+
170+ if (sf != NULL)
171+ list = g_slist_append (list, sf);
172+ }
173+
174+ if (list != NULL) {
175+ couchdb_document_contact_set_im_addresses (document, list);
176+
177+ g_slist_foreach (list, (GFunc) couchdb_struct_field_unref, NULL);
178+ g_slist_free (list);
179+ }
180+
181 /* birth date */
182 dt = (EContactDate *) e_contact_get_const (contact, E_CONTACT_BIRTH_DATE);
183 if (dt) {
184@@ -1208,6 +1349,16 @@
185 fields = g_list_append (fields, g_strdup (e_contact_field_name (E_CONTACT_ADDRESS_WORK)));
186 fields = g_list_append (fields, g_strdup (e_contact_field_name (E_CONTACT_ADDRESS_OTHER)));
187
188+ /* IM addresses */
189+ fields = g_list_append (fields, g_strdup (e_contact_field_name (E_CONTACT_IM_AIM)));
190+ fields = g_list_append (fields, g_strdup (e_contact_field_name (E_CONTACT_IM_GADUGADU)));
191+ fields = g_list_append (fields, g_strdup (e_contact_field_name (E_CONTACT_IM_GROUPWISE)));
192+ fields = g_list_append (fields, g_strdup (e_contact_field_name (E_CONTACT_IM_ICQ)));
193+ fields = g_list_append (fields, g_strdup (e_contact_field_name (E_CONTACT_IM_JABBER)));
194+ fields = g_list_append (fields, g_strdup (e_contact_field_name (E_CONTACT_IM_MSN)));
195+ fields = g_list_append (fields, g_strdup (e_contact_field_name (E_CONTACT_IM_SKYPE)));
196+ fields = g_list_append (fields, g_strdup (e_contact_field_name (E_CONTACT_IM_YAHOO)));
197+
198 e_data_book_respond_get_supported_fields (book, opid,
199 GNOME_Evolution_Addressbook_Success, fields);
200
201
202=== modified file 'plugins/couchdb-contacts-source.c'
203--- plugins/couchdb-contacts-source.c 2009-09-02 11:14:44 +0000
204+++ plugins/couchdb-contacts-source.c 2009-09-22 12:40:52 +0000
205@@ -239,19 +239,19 @@
206 table = gtk_table_new (3, 2, FALSE);
207 gtk_box_pack_start (GTK_BOX (ui->vbox), table, TRUE, TRUE, 0);
208
209- ui->user_db_button = gtk_radio_button_new_with_label (NULL, _("User local database"));
210+ ui->user_db_button = gtk_radio_button_new_with_label (NULL, _("Desktop CouchDB"));
211 gtk_table_attach (GTK_TABLE (table), ui->user_db_button, 0, 2, 0, 1,
212 GTK_EXPAND | GTK_FILL, GTK_FILL, 3, 3);
213
214 ui->system_db_button = gtk_radio_button_new_with_label (
215 gtk_radio_button_get_group (GTK_RADIO_BUTTON (ui->user_db_button)),
216- _("System wide database"));
217+ _("System-wide CouchDB"));
218 gtk_table_attach (GTK_TABLE (table), ui->system_db_button, 0, 2, 1, 2,
219 GTK_EXPAND | GTK_FILL, GTK_FILL, 3, 3);
220
221 ui->remote_db_button = gtk_radio_button_new_with_label (
222 gtk_radio_button_get_group (GTK_RADIO_BUTTON (ui->user_db_button)),
223- _("Remote database"));
224+ _("Remote CouchDB server"));
225 gtk_table_attach (GTK_TABLE (table), ui->remote_db_button, 0, 1, 2, 3,
226 GTK_EXPAND | GTK_FILL, GTK_FILL, 3, 3);
227 ui->remote_db_entry = gtk_entry_new ();

Subscribers

People subscribed via source and target branches