Merge lp:~rodrigo-moya/couchdb-glib/more-contact-fields into lp:couchdb-glib
- more-contact-fields
- Merge into trunk
Proposed by
Rodrigo Moya
Status: | Merged | ||||
---|---|---|---|---|---|
Approved by: | Rodrigo Moya | ||||
Approved revision: | 84 | ||||
Merge reported by: | Rodrigo Moya | ||||
Merged at revision: | not available | ||||
Proposed branch: | lp:~rodrigo-moya/couchdb-glib/more-contact-fields | ||||
Merge into: | lp:couchdb-glib | ||||
Diff against target: | None lines | ||||
To merge this branch: | bzr merge lp:~rodrigo-moya/couchdb-glib/more-contact-fields | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Joshua Blount (community) | Approve | ||
Review via email: mp+10524@code.launchpad.net |
Commit message
Description of the change
To post a comment you must log in.
Revision history for this message
Rodrigo Moya (rodrigo-moya) wrote : | # |
Revision history for this message
Joshua Blount (jblount) : | # |
review:
Approve
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-19 16:43:24 +0000 |
3 | +++ couchdb-glib/couchdb-document-contact.c 2009-08-21 12:20:32 +0000 |
4 | @@ -84,6 +84,44 @@ |
5 | } |
6 | |
7 | const char * |
8 | +couchdb_document_contact_get_nick_name (CouchDBDocument *document) |
9 | +{ |
10 | + g_return_val_if_fail (COUCHDB_IS_DOCUMENT (document), NULL); |
11 | + g_return_val_if_fail (couchdb_document_is_contact (document), NULL); |
12 | + |
13 | + return couchdb_document_get_string_field (document, "nick_name"); |
14 | +} |
15 | + |
16 | +void |
17 | +couchdb_document_contact_set_nick_name (CouchDBDocument *document, const char *nick_name) |
18 | +{ |
19 | + g_return_if_fail (COUCHDB_IS_DOCUMENT (document)); |
20 | + g_return_if_fail (couchdb_document_is_contact (document)); |
21 | + g_return_if_fail (nick_name != NULL); |
22 | + |
23 | + couchdb_document_set_string_field (document, "nick_name", nick_name); |
24 | +} |
25 | + |
26 | +const char * |
27 | +couchdb_document_contact_get_spouse_name (CouchDBDocument *document) |
28 | +{ |
29 | + g_return_val_if_fail (COUCHDB_IS_DOCUMENT (document), NULL); |
30 | + g_return_val_if_fail (couchdb_document_is_contact (document), NULL); |
31 | + |
32 | + return couchdb_document_get_string_field (document, "spouse_name"); |
33 | +} |
34 | + |
35 | +void |
36 | +couchdb_document_contact_set_spouse_name (CouchDBDocument *document, const char *spouse_name) |
37 | +{ |
38 | + g_return_if_fail (COUCHDB_IS_DOCUMENT (document)); |
39 | + g_return_if_fail (couchdb_document_is_contact (document)); |
40 | + g_return_if_fail (spouse_name != NULL); |
41 | + |
42 | + couchdb_document_set_string_field (document, "spouse_name", spouse_name); |
43 | +} |
44 | + |
45 | +const char * |
46 | couchdb_document_contact_get_birth_date (CouchDBDocument *document) |
47 | { |
48 | JsonObject *object; |
49 | @@ -104,6 +142,160 @@ |
50 | couchdb_document_set_string_field (document, "birth_date", birth_date); |
51 | } |
52 | |
53 | +const char * |
54 | +couchdb_document_contact_get_wedding_date (CouchDBDocument *document) |
55 | +{ |
56 | + JsonObject *object; |
57 | + |
58 | + g_return_val_if_fail (COUCHDB_IS_DOCUMENT (document), NULL); |
59 | + g_return_val_if_fail (couchdb_document_is_contact (document), NULL); |
60 | + |
61 | + return couchdb_document_get_string_field (document, "wedding_date"); |
62 | +} |
63 | + |
64 | +void |
65 | +couchdb_document_contact_set_wedding_date (CouchDBDocument *document, const char *wedding_date) |
66 | +{ |
67 | + g_return_if_fail (COUCHDB_IS_DOCUMENT (document)); |
68 | + g_return_if_fail (couchdb_document_is_contact (document)); |
69 | + g_return_if_fail (wedding_date != NULL); |
70 | + |
71 | + couchdb_document_set_string_field (document, "wedding_date", wedding_date); |
72 | +} |
73 | + |
74 | +const char * |
75 | +couchdb_document_contact_get_company (CouchDBDocument *document) |
76 | +{ |
77 | + g_return_val_if_fail (COUCHDB_IS_DOCUMENT (document), NULL); |
78 | + g_return_val_if_fail (couchdb_document_is_contact (document), NULL); |
79 | + |
80 | + return couchdb_document_get_string_field (document, "company"); |
81 | +} |
82 | + |
83 | +void |
84 | +couchdb_document_contact_set_company (CouchDBDocument *document, const char *company) |
85 | +{ |
86 | + g_return_if_fail (COUCHDB_IS_DOCUMENT (document)); |
87 | + g_return_if_fail (couchdb_document_is_contact (document)); |
88 | + g_return_if_fail (company != NULL); |
89 | + |
90 | + couchdb_document_set_string_field (document, "company", company); |
91 | +} |
92 | + |
93 | +const char * |
94 | +couchdb_document_contact_get_department (CouchDBDocument *document) |
95 | +{ |
96 | + g_return_val_if_fail (COUCHDB_IS_DOCUMENT (document), NULL); |
97 | + g_return_val_if_fail (couchdb_document_is_contact (document), NULL); |
98 | + |
99 | + return couchdb_document_get_string_field (document, "department"); |
100 | +} |
101 | + |
102 | +void |
103 | +couchdb_document_contact_set_department (CouchDBDocument *document, const char *department) |
104 | +{ |
105 | + g_return_if_fail (COUCHDB_IS_DOCUMENT (document)); |
106 | + g_return_if_fail (couchdb_document_is_contact (document)); |
107 | + g_return_if_fail (department != NULL); |
108 | + |
109 | + couchdb_document_set_string_field (document, "department", department); |
110 | +} |
111 | + |
112 | +const char * |
113 | +couchdb_document_contact_get_title (CouchDBDocument *document) |
114 | +{ |
115 | + g_return_val_if_fail (COUCHDB_IS_DOCUMENT (document), NULL); |
116 | + g_return_val_if_fail (couchdb_document_is_contact (document), NULL); |
117 | + |
118 | + return couchdb_document_get_string_field (document, "title"); |
119 | +} |
120 | + |
121 | +void |
122 | +couchdb_document_contact_set_title (CouchDBDocument *document, const char *title) |
123 | +{ |
124 | + g_return_if_fail (COUCHDB_IS_DOCUMENT (document)); |
125 | + g_return_if_fail (couchdb_document_is_contact (document)); |
126 | + g_return_if_fail (title != NULL); |
127 | + |
128 | + couchdb_document_set_string_field (document, "title", title); |
129 | +} |
130 | + |
131 | +const char * |
132 | +couchdb_document_contact_get_job_title (CouchDBDocument *document) |
133 | +{ |
134 | + g_return_val_if_fail (COUCHDB_IS_DOCUMENT (document), NULL); |
135 | + g_return_val_if_fail (couchdb_document_is_contact (document), NULL); |
136 | + |
137 | + return couchdb_document_get_string_field (document, "job_title"); |
138 | +} |
139 | + |
140 | +void |
141 | +couchdb_document_contact_set_job_title (CouchDBDocument *document, const char *job_title) |
142 | +{ |
143 | + g_return_if_fail (COUCHDB_IS_DOCUMENT (document)); |
144 | + g_return_if_fail (couchdb_document_is_contact (document)); |
145 | + g_return_if_fail (job_title != NULL); |
146 | + |
147 | + couchdb_document_set_string_field (document, "job_title", job_title); |
148 | +} |
149 | + |
150 | +const char * |
151 | +couchdb_document_contact_get_manager_name (CouchDBDocument *document) |
152 | +{ |
153 | + g_return_val_if_fail (COUCHDB_IS_DOCUMENT (document), NULL); |
154 | + g_return_val_if_fail (couchdb_document_is_contact (document), NULL); |
155 | + |
156 | + return couchdb_document_get_string_field (document, "manager_name"); |
157 | +} |
158 | + |
159 | +void |
160 | +couchdb_document_contact_set_manager_name (CouchDBDocument *document, const char *manager_name) |
161 | +{ |
162 | + g_return_if_fail (COUCHDB_IS_DOCUMENT (document)); |
163 | + g_return_if_fail (couchdb_document_is_contact (document)); |
164 | + g_return_if_fail (manager_name != NULL); |
165 | + |
166 | + couchdb_document_set_string_field (document, "manager_name", manager_name); |
167 | +} |
168 | + |
169 | +const char * |
170 | +couchdb_document_contact_get_assistant_name (CouchDBDocument *document) |
171 | +{ |
172 | + g_return_val_if_fail (COUCHDB_IS_DOCUMENT (document), NULL); |
173 | + g_return_val_if_fail (couchdb_document_is_contact (document), NULL); |
174 | + |
175 | + return couchdb_document_get_string_field (document, "assistant_name"); |
176 | +} |
177 | + |
178 | +void |
179 | +couchdb_document_contact_set_assistant_name (CouchDBDocument *document, const char *assistant_name) |
180 | +{ |
181 | + g_return_if_fail (COUCHDB_IS_DOCUMENT (document)); |
182 | + g_return_if_fail (couchdb_document_is_contact (document)); |
183 | + g_return_if_fail (assistant_name != NULL); |
184 | + |
185 | + couchdb_document_set_string_field (document, "assistant_name", assistant_name); |
186 | +} |
187 | + |
188 | +const char * |
189 | +couchdb_document_contact_get_office (CouchDBDocument *document) |
190 | +{ |
191 | + g_return_val_if_fail (COUCHDB_IS_DOCUMENT (document), NULL); |
192 | + g_return_val_if_fail (couchdb_document_is_contact (document), NULL); |
193 | + |
194 | + return couchdb_document_get_string_field (document, "office"); |
195 | +} |
196 | + |
197 | +void |
198 | +couchdb_document_contact_set_office (CouchDBDocument *document, const char *office) |
199 | +{ |
200 | + g_return_if_fail (COUCHDB_IS_DOCUMENT (document)); |
201 | + g_return_if_fail (couchdb_document_is_contact (document)); |
202 | + g_return_if_fail (office != NULL); |
203 | + |
204 | + couchdb_document_set_string_field (document, "office", office); |
205 | +} |
206 | + |
207 | static void |
208 | foreach_object_cb (JsonObject *object, |
209 | const char *member_name, |
210 | @@ -306,6 +498,25 @@ |
211 | /* FIXME: crashes if we _unref json_object_unref (addresses); */ |
212 | } |
213 | |
214 | +const char * |
215 | +couchdb_document_contact_get_notes (CouchDBDocument *document) |
216 | +{ |
217 | + g_return_val_if_fail (COUCHDB_IS_DOCUMENT (document), NULL); |
218 | + g_return_val_if_fail (couchdb_document_is_contact (document), NULL); |
219 | + |
220 | + return couchdb_document_get_string_field (document, "notes"); |
221 | +} |
222 | + |
223 | +void |
224 | +couchdb_document_contact_set_notes (CouchDBDocument *document, const char *notes) |
225 | +{ |
226 | + g_return_if_fail (COUCHDB_IS_DOCUMENT (document)); |
227 | + g_return_if_fail (couchdb_document_is_contact (document)); |
228 | + g_return_if_fail (notes != NULL); |
229 | + |
230 | + couchdb_document_set_string_field (document, "notes", notes); |
231 | +} |
232 | + |
233 | CouchDBStructField * |
234 | couchdb_document_contact_email_new (const char *uuid, const char *address, const char *description) |
235 | { |
236 | |
237 | === modified file 'couchdb-glib/couchdb-document-contact.h' |
238 | --- couchdb-glib/couchdb-document-contact.h 2009-08-19 16:43:24 +0000 |
239 | +++ couchdb-glib/couchdb-document-contact.h 2009-08-21 12:20:32 +0000 |
240 | @@ -37,8 +37,29 @@ |
241 | void couchdb_document_contact_set_first_name (CouchDBDocument *document, const char *first_name); |
242 | const char *couchdb_document_contact_get_last_name (CouchDBDocument *document); |
243 | void couchdb_document_contact_set_last_name (CouchDBDocument *document, const char *last_name); |
244 | +const char *couchdb_document_contact_get_nick_name (CouchDBDocument *document); |
245 | +void couchdb_document_contact_set_nick_name (CouchDBDocument *document, const char *nick_name); |
246 | +const char *couchdb_document_contact_get_spouse_name (CouchDBDocument *document); |
247 | +void couchdb_document_contact_set_spouse_name (CouchDBDocument *document, const char *spouse_name); |
248 | const char *couchdb_document_contact_get_birth_date (CouchDBDocument *document); |
249 | void couchdb_document_contact_set_birth_date (CouchDBDocument *document, const char *birth_date); |
250 | +const char *couchdb_document_contact_get_wedding_date (CouchDBDocument *document); |
251 | +void couchdb_document_contact_set_wedding_date (CouchDBDocument *document, const char *wedding_date); |
252 | + |
253 | +const char *couchdb_document_contact_get_company (CouchDBDocument *document); |
254 | +void couchdb_document_contact_set_company (CouchDBDocument *document, const char *company); |
255 | +const char *couchdb_document_contact_get_department (CouchDBDocument *document); |
256 | +void couchdb_document_contact_set_department (CouchDBDocument *document, const char *department); |
257 | +const char *couchdb_document_contact_get_title (CouchDBDocument *document); |
258 | +void couchdb_document_contact_set_title (CouchDBDocument *document, const char *title); |
259 | +const char *couchdb_document_contact_get_job_title (CouchDBDocument *document); |
260 | +void couchdb_document_contact_set_job_title (CouchDBDocument *document, const char *job_title); |
261 | +const char *couchdb_document_contact_get_manager_name (CouchDBDocument *document); |
262 | +void couchdb_document_contact_set_manager_name (CouchDBDocument *document, const char *manager_name); |
263 | +const char *couchdb_document_contact_get_assistant_name (CouchDBDocument *document); |
264 | +void couchdb_document_contact_set_assistant_name (CouchDBDocument *document, const char *assistant_name); |
265 | +const char *couchdb_document_contact_get_office (CouchDBDocument *document); |
266 | +void couchdb_document_contact_set_office (CouchDBDocument *document, const char *office); |
267 | |
268 | GSList *couchdb_document_contact_get_email_addresses (CouchDBDocument *document); |
269 | void couchdb_document_contact_set_email_addresses (CouchDBDocument *document, GSList *list); |
270 | @@ -49,6 +70,9 @@ |
271 | GSList *couchdb_document_contact_get_addresses (CouchDBDocument *document); |
272 | void couchdb_document_contact_set_addresses (CouchDBDocument *document, GSList *list); |
273 | |
274 | +const char *couchdb_document_contact_get_notes (CouchDBDocument *document); |
275 | +void couchdb_document_contact_set_notes (CouchDBDocument *document, const char *notes); |
276 | + |
277 | /* |
278 | * Utility functions to manipulate email addresses fields |
279 | */ |
280 | |
281 | === modified file 'couchdb-glib/couchdb-document.c' |
282 | --- couchdb-glib/couchdb-document.c 2009-08-19 16:43:24 +0000 |
283 | +++ couchdb-glib/couchdb-document.c 2009-08-21 12:20:32 +0000 |
284 | @@ -279,6 +279,9 @@ |
285 | g_return_val_if_fail (COUCHDB_IS_DOCUMENT (document), FALSE); |
286 | g_return_val_if_fail (field != NULL, FALSE); |
287 | |
288 | + if (!json_object_has_member (json_node_get_object (document->root_node), field)) |
289 | + return FALSE; |
290 | + |
291 | return json_object_get_boolean_member (json_node_get_object (document->root_node), |
292 | field); |
293 | } |
294 | @@ -300,6 +303,9 @@ |
295 | g_return_val_if_fail (COUCHDB_IS_DOCUMENT (document), -1); |
296 | g_return_val_if_fail (field != NULL, -1); |
297 | |
298 | + if (!json_object_has_member (json_node_get_object (document->root_node), field)) |
299 | + return 0; |
300 | + |
301 | return json_object_get_int_member (json_node_get_object (document->root_node), |
302 | field); |
303 | } |
304 | @@ -321,6 +327,8 @@ |
305 | g_return_val_if_fail (COUCHDB_IS_DOCUMENT (document), -1); |
306 | g_return_val_if_fail (field != NULL, -1); |
307 | |
308 | + if (!json_object_has_member (json_node_get_object (document->root_node), field)) |
309 | + return 0.0; |
310 | return json_object_get_double_member (json_node_get_object (document->root_node), |
311 | field); |
312 | } |
313 | @@ -342,6 +350,9 @@ |
314 | g_return_val_if_fail (COUCHDB_IS_DOCUMENT (document), NULL); |
315 | g_return_val_if_fail (field != NULL, NULL); |
316 | |
317 | + if (!json_object_has_member (json_node_get_object (document->root_node), field)) |
318 | + return NULL; |
319 | + |
320 | return json_object_get_string_member (json_node_get_object (document->root_node), |
321 | field); |
322 | } |
323 | @@ -368,6 +379,9 @@ |
324 | g_return_val_if_fail (COUCHDB_IS_DOCUMENT (document), NULL); |
325 | g_return_val_if_fail (field != NULL, NULL); |
326 | |
327 | + if (!json_object_has_member (json_node_get_object (document->root_node), field)) |
328 | + return NULL; |
329 | + |
330 | return couchdb_struct_field_new_from_json_object ( |
331 | json_object_ref (json_object_get_object_member (json_node_get_object (document->root_node), |
332 | field))); |
Add lots of new contact record fields
Check presence of fields in JSON objects before accessing them to avoid lots
of warnings