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

Proposed by Rodrigo Moya
Status: Merged
Approved by: Rodrigo Moya
Approved revision: 96
Merge reported by: Rodrigo Moya
Merged at revision: not available
Proposed branch: lp://qastaging/~rodrigo-moya/couchdb-glib/im-addresses
Merge into: lp://qastaging/couchdb-glib
Diff against target: None lines
To merge this branch: bzr merge lp://qastaging/~rodrigo-moya/couchdb-glib/im-addresses
Reviewer Review Type Date Requested Status
dobey (community) Needs Information
John O'Brien (community) Approve
Review via email: mp+12048@code.qastaging.launchpad.net
To post a comment you must log in.
Revision history for this message
Rodrigo Moya (rodrigo-moya) wrote :

Added API to manipulate IM addresses for contact records

95. By Rodrigo Moya

Print error messages before asserting

96. By Rodrigo Moya

Use 127.0.0.1 instead of localhost

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

I'm not sure what all the #defines are for, but it looks like some of them should have different strings than they do here. What are these for exactly and how are they used?

review: Needs Information
Revision history for this message
Rodrigo Moya (rodrigo-moya) wrote :

> I'm not sure what all the #defines are for, but it looks like some of them
> should have different strings than they do here. What are these for exactly
> and how are they used?

They are the valid values (some of them, apps can use whatever they want) for the descriptions of email addresses, phone numbers, etc

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'couchdb-glib/couchdb-document-contact.c'
2--- couchdb-glib/couchdb-document-contact.c 2009-08-25 16:06:36 +0000
3+++ couchdb-glib/couchdb-document-contact.c 2009-09-18 12:12:05 +0000
4@@ -372,12 +372,10 @@
5 json_object_set_object_member (addresses_json,
6 couchdb_struct_field_get_uuid (sf),
7 this_address);
8- /* FIXME: crashes if we _unref json_object_unref (this_address); */
9 }
10 }
11
12 json_object_set_object_member (json_node_get_object (document->root_node), "email_addresses", addresses_json);
13- /* FIXME: crashes if we _unref json_object_unref (addresses_json); */
14 }
15
16 GSList *
17@@ -427,12 +425,10 @@
18 json_object_set_object_member (phone_numbers,
19 couchdb_struct_field_get_uuid (sf),
20 this_phone);
21- /* FIXME: crashes if we _unref json_object_unref (this_phone); */
22 }
23 }
24
25 json_object_set_object_member (json_node_get_object (document->root_node), "phone_numbers", phone_numbers);
26- /* FIXME: crashes if we _unref json_object_unref (phone_numbers); */
27 }
28
29 GSList *
30@@ -490,12 +486,64 @@
31 json_object_set_object_member (addresses,
32 couchdb_struct_field_get_uuid (sf),
33 this_address);
34- /* FIXME: crashes if we _unref json_object_unref (this_address); */
35 }
36 }
37
38 json_object_set_object_member (json_node_get_object (document->root_node), "addresses", addresses);
39- /* FIXME: crashes if we _unref json_object_unref (addresses); */
40+}
41+
42+GSList *
43+couchdb_document_contact_get_im_addresses (CouchDBDocument *document)
44+{
45+ GSList *list = NULL;
46+ JsonObject *im_addresses;
47+
48+ g_return_val_if_fail (COUCHDB_IS_DOCUMENT (document), NULL);
49+ g_return_val_if_fail (couchdb_document_is_contact (document), NULL);
50+
51+ im_addresses = json_object_get_object_member (
52+ json_node_get_object (document->root_node), "im_addresses");
53+ if (im_addresses != NULL) {
54+ json_object_foreach_member (im_addresses,
55+ (JsonObjectForeach) foreach_object_cb,
56+ &list);
57+ }
58+
59+ return list;
60+}
61+
62+void
63+couchdb_document_contact_set_im_addresses (CouchDBDocument *document, GSList *list)
64+{
65+ GSList *l;
66+ JsonObject *im_addresses_json;
67+
68+ g_return_if_fail (COUCHDB_IS_DOCUMENT (document));
69+ g_return_if_fail (couchdb_document_is_contact (document));
70+
71+ im_addresses_json = json_object_new ();
72+ for (l = list; l != NULL; l = l->next) {
73+ const gchar *address_str;
74+ CouchDBStructField *sf = (CouchDBStructField *) l->data;
75+
76+ address_str = couchdb_document_contact_im_get_address (sf);
77+ if (address_str != NULL) {
78+ JsonObject *this_address;
79+
80+ this_address = json_object_new ();
81+ json_object_set_string_member (this_address, "address", address_str);
82+ json_object_set_string_member (this_address, "description",
83+ couchdb_document_contact_im_get_description (sf));
84+ json_object_set_string_member (this_address, "protocol",
85+ couchdb_document_contact_im_get_protocol (sf));
86+
87+ json_object_set_object_member (im_addresses_json,
88+ couchdb_struct_field_get_uuid (sf),
89+ this_address);
90+ }
91+ }
92+
93+ json_object_set_object_member (json_node_get_object (document->root_node), "im_addresses", im_addresses_json);
94 }
95
96 GSList *
97@@ -543,12 +591,10 @@
98 json_object_set_object_member (urls_json,
99 couchdb_struct_field_get_uuid (sf),
100 this_url);
101- /* FIXME: crashes if we _unref json_object_unref (this_url); */
102 }
103 }
104
105 json_object_set_object_member (json_node_get_object (document->root_node), "urls", urls_json);
106- /* FIXME: crashes if we _unref json_object_unref (urls_json); */
107 }
108
109 const char *
110@@ -849,6 +895,84 @@
111 }
112
113 CouchDBStructField *
114+couchdb_document_contact_im_new (const char *uuid,
115+ const char *address,
116+ const char *description,
117+ const char *protocol)
118+{
119+ CouchDBStructField *sf;
120+
121+ sf = couchdb_struct_field_new_from_json_object (json_object_new ());
122+ if (uuid != NULL)
123+ couchdb_struct_field_set_uuid (sf, uuid);
124+ else {
125+ char *new_uuid = generate_uuid ();
126+ couchdb_struct_field_set_uuid (sf, new_uuid);
127+ g_free (new_uuid);
128+ }
129+
130+ if (address != NULL)
131+ couchdb_document_contact_im_set_address (sf, address);
132+ if (description != NULL)
133+ couchdb_document_contact_im_set_description (sf, description);
134+ if (protocol != NULL)
135+ couchdb_document_contact_im_set_protocol (sf, protocol);
136+
137+ return sf;
138+}
139+
140+const char *
141+couchdb_document_contact_im_get_address (CouchDBStructField *sf)
142+{
143+ g_return_val_if_fail (sf != NULL, NULL);
144+
145+ return couchdb_struct_field_get_string_field (sf, "address");
146+}
147+
148+void
149+couchdb_document_contact_im_set_address (CouchDBStructField *sf, const char *address)
150+{
151+ g_return_if_fail (sf != NULL);
152+ g_return_if_fail (address != NULL);
153+
154+ couchdb_struct_field_set_string_field (sf, "address", address);
155+}
156+
157+const char *
158+couchdb_document_contact_im_get_description (CouchDBStructField *sf)
159+{
160+ g_return_val_if_fail (sf != NULL, NULL);
161+
162+ return couchdb_struct_field_get_string_field (sf, "description");
163+}
164+
165+void
166+couchdb_document_contact_im_set_description (CouchDBStructField *sf, const char *description)
167+{
168+ g_return_if_fail (sf != NULL);
169+ g_return_if_fail (description != NULL);
170+
171+ couchdb_struct_field_set_string_field (sf, "address", description);
172+}
173+
174+const char *
175+couchdb_document_contact_im_get_protocol (CouchDBStructField *sf)
176+{
177+ g_return_val_if_fail (sf != NULL, NULL);
178+
179+ return couchdb_struct_field_get_string_field (sf, "protocol");
180+}
181+
182+void
183+couchdb_document_contact_im_set_protocol (CouchDBStructField *sf, const char *protocol)
184+{
185+ g_return_if_fail (sf != NULL);
186+ g_return_if_fail (protocol != NULL);
187+
188+ couchdb_struct_field_set_string_field (sf, "protocol", protocol);
189+}
190+
191+CouchDBStructField *
192 couchdb_document_contact_url_new (const char *uuid, const char *address, const char *description)
193 {
194 CouchDBStructField *sf;
195
196=== modified file 'couchdb-glib/couchdb-document-contact.h'
197--- couchdb-glib/couchdb-document-contact.h 2009-08-25 16:06:36 +0000
198+++ couchdb-glib/couchdb-document-contact.h 2009-09-18 12:12:05 +0000
199@@ -70,6 +70,9 @@
200 GSList *couchdb_document_contact_get_addresses (CouchDBDocument *document);
201 void couchdb_document_contact_set_addresses (CouchDBDocument *document, GSList *list);
202
203+GSList *couchdb_document_contact_get_im_addresses (CouchDBDocument *document);
204+void couchdb_document_contact_set_im_addresses (CouchDBDocument *document, GSList *list);
205+
206 GSList *couchdb_document_contact_get_urls (CouchDBDocument *document);
207 void couchdb_document_contact_set_urls (CouchDBDocument *document, GSList *list);
208
209@@ -83,6 +86,11 @@
210 CouchDBStructField *couchdb_document_contact_email_new (const char *uuid, const char *address, const char *description);
211 const char *couchdb_document_contact_email_get_address (CouchDBStructField *sf);
212 void couchdb_document_contact_email_set_address (CouchDBStructField *sf, const char *email);
213+
214+#define COUCHDB_DOCUMENT_CONTACT_EMAIL_DESCRIPTION_HOME "home"
215+#define COUCHDB_DOCUMENT_CONTACT_EMAIL_DESCRIPTION_OTHER "other"
216+#define COUCHDB_DOCUMENT_CONTACT_EMAIL_DESCRIPTION_WORK "work"
217+
218 const char *couchdb_document_contact_email_get_description (CouchDBStructField *sf);
219 void couchdb_document_contact_email_set_description (CouchDBStructField *sf, const char *description);
220
221@@ -95,6 +103,23 @@
222 void couchdb_document_contact_phone_set_priority (CouchDBStructField *sf, gint priority);
223 const char *couchdb_document_contact_phone_get_number (CouchDBStructField *sf);
224 void couchdb_document_contact_phone_set_number (CouchDBStructField *sf, const char *number);
225+
226+#define COUCHDB_DOCUMENT_CONTACT_PHONE_DESCRIPTION_ASSISTANT "assistant"
227+#define COUCHDB_DOCUMENT_CONTACT_PHONE_DESCRIPTION_CALLBACK "callback"
228+#define COUCHDB_DOCUMENT_CONTACT_PHONE_DESCRIPTION_CAR "car"
229+#define COUCHDB_DOCUMENT_CONTACT_PHONE_DESCRIPTION_COMPANY "company"
230+#define COUCHDB_DOCUMENT_CONTACT_PHONE_DESCRIPTION_HOME "home"
231+#define COUCHDB_DOCUMENT_CONTACT_PHONE_DESCRIPTION_HOME_FAX "home fax"
232+#define COUCHDB_DOCUMENT_CONTACT_PHONE_DESCRIPTION_MOBILE "mobile"
233+#define COUCHDB_DOCUMENT_CONTACT_PHONE_DESCRIPTION_OTHER "other"
234+#define COUCHDB_DOCUMENT_CONTACT_PHONE_DESCRIPTION_OTHER_FAX "other fax"
235+#define COUCHDB_DOCUMENT_CONTACT_PHONE_DESCRIPTION_PAGER "pager"
236+#define COUCHDB_DOCUMENT_CONTACT_PHONE_DESCRIPTION_PRIMARY "primary"
237+#define COUCHDB_DOCUMENT_CONTACT_PHONE_DESCRIPTION_RADIO "radio"
238+#define COUCHDB_DOCUMENT_CONTACT_PHONE_DESCRIPTION_TELEX "telex"
239+#define COUCHDB_DOCUMENT_CONTACT_PHONE_DESCRIPTION_WORK "work"
240+#define COUCHDB_DOCUMENT_CONTACT_PHONE_DESCRIPTION_WORK_FAX "work fax"
241+
242 const char *couchdb_document_contact_phone_get_description (CouchDBStructField *sf);
243 void couchdb_document_contact_phone_set_description (CouchDBStructField *sf, const char *description);
244
245@@ -121,15 +146,49 @@
246 void couchdb_document_contact_address_set_postalcode (CouchDBStructField *sf, const char *postalcode);
247 const char *couchdb_document_contact_address_get_pobox (CouchDBStructField *sf);
248 void couchdb_document_contact_address_set_pobox (CouchDBStructField *sf, const char *pobox);
249+
250+#define COUCHDB_DOCUMENT_CONTACT_ADDRESS_DESCRIPTION_HOME "home"
251+#define COUCHDB_DOCUMENT_CONTACT_ADDRESS_DESCRIPTION_OTHER "other"
252+#define COUCHDB_DOCUMENT_CONTACT_ADDRESS_DESCRIPTION_WORK "work"
253+
254 const char *couchdb_document_contact_address_get_description (CouchDBStructField *sf);
255 void couchdb_document_contact_address_set_description (CouchDBStructField *sf, const char *description);
256
257 /*
258+ * Utility functions to manipulate IM addresses
259+ */
260+CouchDBStructField *couchdb_document_contact_im_new (const char *uuid,
261+ const char *address,
262+ const char *description,
263+ const char *protocol);
264+const char *couchdb_document_contact_im_get_address (CouchDBStructField *sf);
265+void couchdb_document_contact_im_set_address (CouchDBStructField *sf, const char *address);
266+const char *couchdb_document_contact_im_get_description (CouchDBStructField *sf);
267+void couchdb_document_contact_im_set_description (CouchDBStructField *sf, const char *description);
268+
269+#define COUCHDB_DOCUMENT_CONTACT_IM_PROTOCOL_AIM "aim"
270+#define COUCHDB_DOCUMENT_CONTACT_IM_PROTOCOL_GADU_GADU "gadu-gadu"
271+#define COUCHDB_DOCUMENT_CONTACT_IM_PROTOCOL_GROUPWISE "groupwise"
272+#define COUCHDB_DOCUMENT_CONTACT_IM_PROTOCOL_ICQ "icq"
273+#define COUCHDB_DOCUMENT_CONTACT_IM_PROTOCOL_IRC "irc"
274+#define COUCHDB_DOCUMENT_CONTACT_IM_PROTOCOL_JABBER "jabber"
275+#define COUCHDB_DOCUMENT_CONTACT_IM_PROTOCOL_MSN "msn"
276+#define COUCHDB_DOCUMENT_CONTACT_IM_PROTOCOL_SKYPE "skype"
277+#define COUCHDB_DOCUMENT_CONTACT_IM_PROTOCOL_YAHOO "yahoo"
278+
279+const char *couchdb_document_contact_im_get_protocol (CouchDBStructField *sf);
280+void couchdb_document_contact_im_set_protocol (CouchDBStructField *sf, const char *protocol);
281+
282+/*
283 * Utility functions to manipulate URLs
284 */
285 CouchDBStructField *couchdb_document_contact_url_new (const char *uuid, const char *address, const char *description);
286 const char *couchdb_document_contact_url_get_address (CouchDBStructField *sf);
287 void couchdb_document_contact_url_set_address (CouchDBStructField *sf, const char *address);
288+
289+#define COUCHDB_DOCUMENT_CONTACT_URL_DESCRIPTION_BLOG "blog"
290+#define COUCHDB_DOCUMENT_CONTACT_URL_DESCRIPTION_HOMEPAGE "home page"
291+
292 const char *couchdb_document_contact_url_get_description (CouchDBStructField *sf);
293 void couchdb_document_contact_url_set_description (CouchDBStructField *sf, const char *description);
294 #endif

Subscribers

People subscribed via source and target branches