~kklimonda/couchdb-glib/fix-critical

« back to all changes in this revision

Viewing changes to couchdb-glib/couchdb-document-contact.c

  • Committer: Rodrigo Moya
  • Date: 2010-07-07 11:44:30 UTC
  • Revision ID: git-v1:47e511231e6911c4ab3dd86b6ef893781e5222c3
Move DesktopcouchDocument* classes to couchdb-glib, so that they can be used in other CouchdbSession's

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
 
2
/*
 
3
 * Copyright (C) 2009 Canonical Services Ltd (www.canonical.com)
 
4
 *
 
5
 * Authors: Rodrigo Moya <rodrigo.moya@canonical.com>
 
6
 *
 
7
 * This library is free software; you can redistribute it and/or
 
8
 * modify it under the terms of version 2 of the GNU Lesser General Public
 
9
 * License as published by the Free Software Foundation.
 
10
 *
 
11
 * This program is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
14
 * General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU Lesser General Public
 
17
 * License along with this library; if not, write to the
 
18
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 
19
 * Boston, MA 02110-1301, USA.
 
20
 */
 
21
 
 
22
#include "couchdb-document-contact.h"
 
23
#include "utils.h"
 
24
 
 
25
G_DEFINE_TYPE(CouchdbDocumentContact, couchdb_document_contact, COUCHDB_TYPE_DOCUMENT)
 
26
 
 
27
static void
 
28
couchdb_document_contact_class_init (CouchdbDocumentContactClass *klass)
 
29
{
 
30
}
 
31
 
 
32
static void
 
33
couchdb_document_contact_init (CouchdbDocumentContact *document)
 
34
{
 
35
        couchdb_document_set_record_type (COUCHDB_DOCUMENT (document), COUCHDB_RECORD_TYPE_CONTACT);
 
36
}
 
37
 
 
38
/**
 
39
 * couchdb_document_contact_new:
 
40
 *
 
41
 * Create a new #CouchdbDocumentContact object.
 
42
 */
 
43
CouchdbDocumentContact *
 
44
couchdb_document_contact_new (void)
 
45
{
 
46
        return g_object_new (COUCHDB_TYPE_DOCUMENT_CONTACT, NULL);
 
47
}
 
48
 
 
49
const char *
 
50
couchdb_document_contact_get_title (CouchdbDocumentContact *document)
 
51
{
 
52
        g_return_val_if_fail (COUCHDB_IS_DOCUMENT_CONTACT (document), NULL);
 
53
        g_return_val_if_fail (couchdb_document_is_contact (COUCHDB_DOCUMENT (document)), NULL);
 
54
 
 
55
        return couchdb_document_get_string_field (COUCHDB_DOCUMENT (document), "title");
 
56
}
 
57
 
 
58
void
 
59
couchdb_document_contact_set_title (CouchdbDocumentContact *document, const char *title)
 
60
{
 
61
        g_return_if_fail (COUCHDB_IS_DOCUMENT_CONTACT (document));
 
62
        g_return_if_fail (couchdb_document_is_contact (COUCHDB_DOCUMENT (document)));
 
63
        g_return_if_fail (title != NULL);
 
64
 
 
65
        couchdb_document_set_string_field (COUCHDB_DOCUMENT (document), "title", title);
 
66
}
 
67
 
 
68
const char *
 
69
couchdb_document_contact_get_first_name (CouchdbDocumentContact *document)
 
70
{
 
71
        g_return_val_if_fail (COUCHDB_IS_DOCUMENT_CONTACT (document), NULL);
 
72
        g_return_val_if_fail (couchdb_document_is_contact (COUCHDB_DOCUMENT (document)), NULL);
 
73
 
 
74
        return couchdb_document_get_string_field (COUCHDB_DOCUMENT (document), "first_name");
 
75
}
 
76
 
 
77
void
 
78
couchdb_document_contact_set_first_name (CouchdbDocumentContact *document, const char *first_name)
 
79
{
 
80
        g_return_if_fail (COUCHDB_IS_DOCUMENT_CONTACT (document));
 
81
        g_return_if_fail (couchdb_document_is_contact (COUCHDB_DOCUMENT (document)));
 
82
        g_return_if_fail (first_name != NULL);
 
83
 
 
84
        couchdb_document_set_string_field (COUCHDB_DOCUMENT (document), "first_name", first_name);
 
85
}
 
86
 
 
87
const char *
 
88
couchdb_document_contact_get_middle_name (CouchdbDocumentContact *document)
 
89
{
 
90
        g_return_val_if_fail (COUCHDB_IS_DOCUMENT_CONTACT (document), NULL);
 
91
        g_return_val_if_fail (couchdb_document_is_contact (COUCHDB_DOCUMENT (document)), NULL);
 
92
 
 
93
        return couchdb_document_get_string_field (COUCHDB_DOCUMENT (document), "middle_name");
 
94
}
 
95
 
 
96
void
 
97
couchdb_document_contact_set_middle_name (CouchdbDocumentContact *document, const char *middle_name)
 
98
{
 
99
        g_return_if_fail (COUCHDB_IS_DOCUMENT_CONTACT (document));
 
100
        g_return_if_fail (couchdb_document_is_contact (COUCHDB_DOCUMENT (document)));
 
101
        g_return_if_fail (middle_name != NULL);
 
102
 
 
103
        couchdb_document_set_string_field (COUCHDB_DOCUMENT (document), "middle_name", middle_name);
 
104
}
 
105
 
 
106
const char *
 
107
couchdb_document_contact_get_last_name (CouchdbDocumentContact *document)
 
108
{
 
109
        g_return_val_if_fail (COUCHDB_IS_DOCUMENT_CONTACT (document), NULL);
 
110
        g_return_val_if_fail (couchdb_document_is_contact (COUCHDB_DOCUMENT (document)), NULL);
 
111
 
 
112
        return couchdb_document_get_string_field (COUCHDB_DOCUMENT (document), "last_name");
 
113
}
 
114
 
 
115
void
 
116
couchdb_document_contact_set_last_name (CouchdbDocumentContact *document, const char *last_name)
 
117
{
 
118
        g_return_if_fail (COUCHDB_IS_DOCUMENT_CONTACT (document));
 
119
        g_return_if_fail (couchdb_document_is_contact (COUCHDB_DOCUMENT (document)));
 
120
        g_return_if_fail (last_name != NULL);
 
121
 
 
122
        couchdb_document_set_string_field (COUCHDB_DOCUMENT (document), "last_name", last_name);
 
123
}
 
124
 
 
125
const char *
 
126
couchdb_document_contact_get_suffix (CouchdbDocumentContact *document)
 
127
{
 
128
        g_return_val_if_fail (COUCHDB_IS_DOCUMENT_CONTACT (document), NULL);
 
129
        g_return_val_if_fail (couchdb_document_is_contact (COUCHDB_DOCUMENT (document)), NULL);
 
130
 
 
131
        return couchdb_document_get_string_field (COUCHDB_DOCUMENT (document), "suffix");
 
132
}
 
133
 
 
134
void
 
135
couchdb_document_contact_set_suffix (CouchdbDocumentContact *document, const char *suffix)
 
136
{
 
137
        g_return_if_fail (COUCHDB_IS_DOCUMENT_CONTACT (document));
 
138
        g_return_if_fail (couchdb_document_is_contact (COUCHDB_DOCUMENT (document)));
 
139
        g_return_if_fail (suffix != NULL);
 
140
 
 
141
        couchdb_document_set_string_field (COUCHDB_DOCUMENT (document), "suffix", suffix);
 
142
}
 
143
 
 
144
const char *
 
145
couchdb_document_contact_get_nick_name (CouchdbDocumentContact *document)
 
146
{
 
147
        g_return_val_if_fail (COUCHDB_IS_DOCUMENT_CONTACT (document), NULL);
 
148
        g_return_val_if_fail (couchdb_document_is_contact (COUCHDB_DOCUMENT (document)), NULL);
 
149
 
 
150
        return couchdb_document_get_string_field (COUCHDB_DOCUMENT (document), "nick_name");
 
151
}
 
152
 
 
153
void
 
154
couchdb_document_contact_set_nick_name (CouchdbDocumentContact *document, const char *nick_name)
 
155
{
 
156
        g_return_if_fail (COUCHDB_IS_DOCUMENT_CONTACT (document));
 
157
        g_return_if_fail (couchdb_document_is_contact (COUCHDB_DOCUMENT (document)));
 
158
        g_return_if_fail (nick_name != NULL);
 
159
 
 
160
        couchdb_document_set_string_field (COUCHDB_DOCUMENT (document), "nick_name", nick_name);
 
161
}
 
162
 
 
163
const char *
 
164
couchdb_document_contact_get_spouse_name (CouchdbDocumentContact *document)
 
165
{
 
166
        g_return_val_if_fail (COUCHDB_IS_DOCUMENT_CONTACT (document), NULL);
 
167
        g_return_val_if_fail (couchdb_document_is_contact (COUCHDB_DOCUMENT (document)), NULL);
 
168
 
 
169
        return couchdb_document_get_string_field (COUCHDB_DOCUMENT (document), "spouse_name");
 
170
}
 
171
 
 
172
void
 
173
couchdb_document_contact_set_spouse_name (CouchdbDocumentContact *document, const char *spouse_name)
 
174
{
 
175
        g_return_if_fail (COUCHDB_IS_DOCUMENT_CONTACT (document));
 
176
        g_return_if_fail (couchdb_document_is_contact (COUCHDB_DOCUMENT (document)));
 
177
        g_return_if_fail (spouse_name != NULL);
 
178
 
 
179
        couchdb_document_set_string_field (COUCHDB_DOCUMENT (document), "spouse_name", spouse_name);
 
180
}
 
181
 
 
182
const char *
 
183
couchdb_document_contact_get_birth_date (CouchdbDocumentContact *document)
 
184
{
 
185
        JsonObject *object;
 
186
 
 
187
        g_return_val_if_fail (COUCHDB_IS_DOCUMENT_CONTACT (document), NULL);
 
188
        g_return_val_if_fail (couchdb_document_is_contact (COUCHDB_DOCUMENT (document)), NULL);
 
189
 
 
190
        return couchdb_document_get_string_field (COUCHDB_DOCUMENT (document), "birth_date");
 
191
}
 
192
 
 
193
void
 
194
couchdb_document_contact_set_birth_date (CouchdbDocumentContact *document, const char *birth_date)
 
195
{
 
196
        g_return_if_fail (COUCHDB_IS_DOCUMENT_CONTACT (document));
 
197
        g_return_if_fail (couchdb_document_is_contact (COUCHDB_DOCUMENT (document)));
 
198
        g_return_if_fail (birth_date != NULL);
 
199
 
 
200
        couchdb_document_set_string_field (COUCHDB_DOCUMENT (document), "birth_date", birth_date);
 
201
}
 
202
 
 
203
const char *
 
204
couchdb_document_contact_get_wedding_date (CouchdbDocumentContact *document)
 
205
{
 
206
        JsonObject *object;
 
207
 
 
208
        g_return_val_if_fail (COUCHDB_IS_DOCUMENT_CONTACT (document), NULL);
 
209
        g_return_val_if_fail (couchdb_document_is_contact (COUCHDB_DOCUMENT (document)), NULL);
 
210
 
 
211
        return couchdb_document_get_string_field (COUCHDB_DOCUMENT (document), "wedding_date");
 
212
}
 
213
 
 
214
void
 
215
couchdb_document_contact_set_wedding_date (CouchdbDocumentContact *document, const char *wedding_date)
 
216
{
 
217
        g_return_if_fail (COUCHDB_IS_DOCUMENT_CONTACT (document));
 
218
        g_return_if_fail (couchdb_document_is_contact (COUCHDB_DOCUMENT (document)));
 
219
        g_return_if_fail (wedding_date != NULL);
 
220
 
 
221
        couchdb_document_set_string_field (COUCHDB_DOCUMENT (document), "wedding_date", wedding_date);
 
222
}
 
223
 
 
224
const char *
 
225
couchdb_document_contact_get_company (CouchdbDocumentContact *document)
 
226
{
 
227
        g_return_val_if_fail (COUCHDB_IS_DOCUMENT_CONTACT (document), NULL);
 
228
        g_return_val_if_fail (couchdb_document_is_contact (COUCHDB_DOCUMENT (document)), NULL);
 
229
 
 
230
        return couchdb_document_get_string_field (COUCHDB_DOCUMENT (document), "company");
 
231
}
 
232
 
 
233
void
 
234
couchdb_document_contact_set_company (CouchdbDocumentContact *document, const char *company)
 
235
{
 
236
        g_return_if_fail (COUCHDB_IS_DOCUMENT_CONTACT (document));
 
237
        g_return_if_fail (couchdb_document_is_contact (COUCHDB_DOCUMENT (document)));
 
238
        g_return_if_fail (company != NULL);
 
239
 
 
240
        couchdb_document_set_string_field (COUCHDB_DOCUMENT (document), "company", company);
 
241
}
 
242
 
 
243
const char *
 
244
couchdb_document_contact_get_department (CouchdbDocumentContact *document)
 
245
{
 
246
        g_return_val_if_fail (COUCHDB_IS_DOCUMENT_CONTACT (document), NULL);
 
247
        g_return_val_if_fail (couchdb_document_is_contact (COUCHDB_DOCUMENT (document)), NULL);
 
248
 
 
249
        return couchdb_document_get_string_field (COUCHDB_DOCUMENT (document), "department");
 
250
}
 
251
 
 
252
void
 
253
couchdb_document_contact_set_department (CouchdbDocumentContact *document, const char *department)
 
254
{
 
255
        g_return_if_fail (COUCHDB_IS_DOCUMENT_CONTACT (document));
 
256
        g_return_if_fail (couchdb_document_is_contact (COUCHDB_DOCUMENT (document)));
 
257
        g_return_if_fail (department != NULL);
 
258
 
 
259
        couchdb_document_set_string_field (COUCHDB_DOCUMENT (document), "department", department);
 
260
}
 
261
 
 
262
const char *
 
263
couchdb_document_contact_get_job_title (CouchdbDocumentContact *document)
 
264
{
 
265
        g_return_val_if_fail (COUCHDB_IS_DOCUMENT_CONTACT (document), NULL);
 
266
        g_return_val_if_fail (couchdb_document_is_contact (COUCHDB_DOCUMENT (document)), NULL);
 
267
 
 
268
        return couchdb_document_get_string_field (COUCHDB_DOCUMENT (document), "job_title");
 
269
}
 
270
 
 
271
void
 
272
couchdb_document_contact_set_job_title (CouchdbDocumentContact *document, const char *job_title)
 
273
{
 
274
        g_return_if_fail (COUCHDB_IS_DOCUMENT_CONTACT (document));
 
275
        g_return_if_fail (couchdb_document_is_contact (COUCHDB_DOCUMENT (document)));
 
276
        g_return_if_fail (job_title != NULL);
 
277
 
 
278
        couchdb_document_set_string_field (COUCHDB_DOCUMENT (document), "job_title", job_title);
 
279
}
 
280
 
 
281
const char *
 
282
couchdb_document_contact_get_manager_name (CouchdbDocumentContact *document)
 
283
{
 
284
        g_return_val_if_fail (COUCHDB_IS_DOCUMENT_CONTACT (document), NULL);
 
285
        g_return_val_if_fail (couchdb_document_is_contact (COUCHDB_DOCUMENT (document)), NULL);
 
286
 
 
287
        return couchdb_document_get_string_field (COUCHDB_DOCUMENT (document), "manager_name");
 
288
}
 
289
 
 
290
void
 
291
couchdb_document_contact_set_manager_name (CouchdbDocumentContact *document, const char *manager_name)
 
292
{
 
293
        g_return_if_fail (COUCHDB_IS_DOCUMENT_CONTACT (document));
 
294
        g_return_if_fail (couchdb_document_is_contact (COUCHDB_DOCUMENT (document)));
 
295
        g_return_if_fail (manager_name != NULL);
 
296
 
 
297
        couchdb_document_set_string_field (COUCHDB_DOCUMENT (document), "manager_name", manager_name);
 
298
}
 
299
 
 
300
const char *
 
301
couchdb_document_contact_get_assistant_name (CouchdbDocumentContact *document)
 
302
{
 
303
        g_return_val_if_fail (COUCHDB_IS_DOCUMENT_CONTACT (document), NULL);
 
304
        g_return_val_if_fail (couchdb_document_is_contact (COUCHDB_DOCUMENT (document)), NULL);
 
305
 
 
306
        return couchdb_document_get_string_field (COUCHDB_DOCUMENT (document), "assistant_name");
 
307
}
 
308
 
 
309
void
 
310
couchdb_document_contact_set_assistant_name (CouchdbDocumentContact *document, const char *assistant_name)
 
311
{
 
312
        g_return_if_fail (COUCHDB_IS_DOCUMENT_CONTACT (document));
 
313
        g_return_if_fail (couchdb_document_is_contact (COUCHDB_DOCUMENT (document)));
 
314
        g_return_if_fail (assistant_name != NULL);
 
315
 
 
316
        couchdb_document_set_string_field (COUCHDB_DOCUMENT (document), "assistant_name", assistant_name);
 
317
}
 
318
 
 
319
const char *
 
320
couchdb_document_contact_get_office (CouchdbDocumentContact *document)
 
321
{
 
322
        g_return_val_if_fail (COUCHDB_IS_DOCUMENT_CONTACT (document), NULL);
 
323
        g_return_val_if_fail (couchdb_document_is_contact (COUCHDB_DOCUMENT (document)), NULL);
 
324
 
 
325
        return couchdb_document_get_string_field (COUCHDB_DOCUMENT (document), "office");
 
326
}
 
327
 
 
328
void
 
329
couchdb_document_contact_set_office (CouchdbDocumentContact *document, const char *office)
 
330
{
 
331
        g_return_if_fail (COUCHDB_IS_DOCUMENT_CONTACT (document));
 
332
        g_return_if_fail (couchdb_document_is_contact (COUCHDB_DOCUMENT (document)));
 
333
        g_return_if_fail (office != NULL);
 
334
 
 
335
        couchdb_document_set_string_field (COUCHDB_DOCUMENT (document), "office", office);
 
336
}
 
337
 
 
338
static void
 
339
foreach_object_cb (JsonObject *object,
 
340
                  const char *member_name,
 
341
                  JsonNode *member_node,
 
342
                  gpointer user_data)
 
343
{
 
344
        GSList **list = (GSList **) user_data;
 
345
 
 
346
        if (json_node_get_node_type (member_node) == JSON_NODE_OBJECT) {
 
347
                CouchdbStructField *sf;
 
348
 
 
349
                sf = couchdb_struct_field_new_from_json_object (
 
350
                        json_object_ref (json_node_get_object (member_node)));
 
351
                couchdb_struct_field_set_uuid (sf, member_name);
 
352
                *list = g_slist_prepend (*list, sf);
 
353
        }
 
354
}
 
355
 
 
356
/**
 
357
 * couchdb_document_contact_get_email_addresses:
 
358
 * @document: A #CouchdbDocumentContact object representing a contact
 
359
 *
 
360
 * Retrieve a list of email addresses from the specified contact document.
 
361
 * Email addresses are returned in a GSList of #CouchdbStructField objects,
 
362
 * which can be manipulated with the couchdb_document_contact_email_* functions
 
363
 * and freed with:
 
364
 *     g_slist_foreach (list, (GFunc) couchdb_struct_field_unref, NULL);
 
365
 *     g_slist_free (list);
 
366
 *
 
367
 * Return value: a #GSList of #CouchdbStructField objects.
 
368
 */
 
369
GSList *
 
370
couchdb_document_contact_get_email_addresses (CouchdbDocumentContact *document)
 
371
{
 
372
        GSList *list = NULL;
 
373
        JsonObject *addresses_json;
 
374
 
 
375
        g_return_val_if_fail (COUCHDB_IS_DOCUMENT_CONTACT (document), NULL);
 
376
        g_return_val_if_fail (couchdb_document_is_contact (COUCHDB_DOCUMENT (document)), NULL);
 
377
 
 
378
        addresses_json = json_object_get_object_member (
 
379
                couchdb_document_get_json_object (COUCHDB_DOCUMENT (document)), "email_addresses");;
 
380
        if (addresses_json) {
 
381
                json_object_foreach_member (addresses_json,
 
382
                                            (JsonObjectForeach) foreach_object_cb,
 
383
                                            &list);
 
384
        }
 
385
 
 
386
        return list;
 
387
}
 
388
 
 
389
void
 
390
couchdb_document_contact_set_email_addresses (CouchdbDocumentContact *document, GSList *list)
 
391
{
 
392
        GSList *l;
 
393
        JsonObject *addresses_json;
 
394
 
 
395
        g_return_if_fail (COUCHDB_IS_DOCUMENT_CONTACT (document));
 
396
 
 
397
        addresses_json = json_object_new ();
 
398
        for (l = list; l != NULL; l = l->next) {
 
399
                const gchar *address_str;
 
400
                CouchdbStructField *sf = (CouchdbStructField *) l->data;
 
401
 
 
402
                address_str = couchdb_document_contact_email_get_address (sf);
 
403
                if (address_str) {
 
404
                        JsonObject *this_address;
 
405
 
 
406
                        this_address = json_object_new ();
 
407
                        json_object_set_string_member (this_address, "address", address_str);
 
408
                        json_object_set_string_member (this_address, "description",
 
409
                                                       couchdb_document_contact_email_get_description (sf));
 
410
 
 
411
                        json_object_set_object_member (addresses_json,
 
412
                                                       couchdb_struct_field_get_uuid (sf),
 
413
                                                       this_address);
 
414
                }
 
415
        }
 
416
 
 
417
        json_object_set_object_member (couchdb_document_get_json_object (COUCHDB_DOCUMENT (document)),
 
418
                                       "email_addresses",
 
419
                                       addresses_json);
 
420
}
 
421
 
 
422
GSList *
 
423
couchdb_document_contact_get_phone_numbers (CouchdbDocumentContact *document)
 
424
{
 
425
        GSList *list = NULL;
 
426
        JsonObject *phone_numbers;
 
427
 
 
428
        g_return_val_if_fail (COUCHDB_IS_DOCUMENT_CONTACT (document), NULL);
 
429
        g_return_val_if_fail (couchdb_document_is_contact (COUCHDB_DOCUMENT (document)), NULL);
 
430
 
 
431
        phone_numbers = json_object_get_object_member (
 
432
                couchdb_document_get_json_object (COUCHDB_DOCUMENT (document)), "phone_numbers");
 
433
        if (phone_numbers) {
 
434
                json_object_foreach_member (phone_numbers,
 
435
                                            (JsonObjectForeach) foreach_object_cb,
 
436
                                            &list);
 
437
        }
 
438
 
 
439
        return list;
 
440
}
 
441
 
 
442
void
 
443
couchdb_document_contact_set_phone_numbers (CouchdbDocumentContact *document, GSList *list)
 
444
{
 
445
        GSList *l;
 
446
        JsonObject *phone_numbers;
 
447
 
 
448
        g_return_if_fail (COUCHDB_IS_DOCUMENT_CONTACT (document));
 
449
 
 
450
        phone_numbers = json_object_new ();
 
451
        for (l = list; l != NULL; l = l->next) {
 
452
                const gchar *number_str;
 
453
                CouchdbStructField *sf = (CouchdbStructField *) l->data;
 
454
 
 
455
                number_str = couchdb_document_contact_phone_get_number (sf);
 
456
                if (number_str) {
 
457
                        JsonObject *this_phone;
 
458
 
 
459
                        this_phone = json_object_new ();
 
460
                        json_object_set_string_member (this_phone, "number", number_str);
 
461
                        json_object_set_string_member (this_phone, "description",
 
462
                                                       couchdb_document_contact_phone_get_description (sf));
 
463
                        json_object_set_int_member (this_phone, "priority",
 
464
                                                    couchdb_document_contact_phone_get_priority (sf));
 
465
 
 
466
                        json_object_set_object_member (phone_numbers,
 
467
                                                       couchdb_struct_field_get_uuid (sf),
 
468
                                                       this_phone);
 
469
                }
 
470
        }
 
471
 
 
472
        json_object_set_object_member (couchdb_document_get_json_object (COUCHDB_DOCUMENT (document)),
 
473
                                       "phone_numbers", phone_numbers);
 
474
}
 
475
 
 
476
GSList *
 
477
couchdb_document_contact_get_addresses (CouchdbDocumentContact *document)
 
478
{
 
479
        GSList *list = NULL;
 
480
        JsonObject *addresses;
 
481
 
 
482
        g_return_val_if_fail (COUCHDB_IS_DOCUMENT_CONTACT (document), NULL);
 
483
        g_return_val_if_fail (couchdb_document_is_contact (COUCHDB_DOCUMENT (document)), NULL);
 
484
 
 
485
        addresses = json_object_get_object_member (
 
486
                couchdb_document_get_json_object (COUCHDB_DOCUMENT (document)), "addresses");
 
487
        if (addresses) {
 
488
                json_object_foreach_member (addresses,
 
489
                                            (JsonObjectForeach) foreach_object_cb,
 
490
                                            &list);
 
491
        }
 
492
 
 
493
        return list;
 
494
}
 
495
 
 
496
void
 
497
couchdb_document_contact_set_addresses (CouchdbDocumentContact *document, GSList *list)
 
498
{
 
499
        GSList *l;
 
500
        JsonObject *addresses;
 
501
 
 
502
        g_return_if_fail (COUCHDB_IS_DOCUMENT_CONTACT (document));
 
503
 
 
504
        addresses = json_object_new ();
 
505
        for (l = list; l != NULL; l = l->next) {
 
506
                const gchar *street_str;
 
507
                CouchdbStructField *sf = (CouchdbStructField *) l->data;
 
508
 
 
509
                street_str = couchdb_document_contact_address_get_street (sf);
 
510
                if (street_str) {
 
511
                        JsonObject *this_address;
 
512
 
 
513
                        this_address = json_object_new ();
 
514
 
 
515
                        json_object_set_string_member (this_address, "address1", street_str);
 
516
                        json_object_set_string_member (this_address, "address2",
 
517
                                                       couchdb_document_contact_address_get_ext_street (sf));
 
518
                        json_object_set_string_member (this_address, "city",
 
519
                                                       couchdb_document_contact_address_get_city (sf));
 
520
                        json_object_set_string_member (this_address, "state",
 
521
                                                       couchdb_document_contact_address_get_state (sf));
 
522
                        json_object_set_string_member (this_address, "country",
 
523
                                                       couchdb_document_contact_address_get_country (sf));
 
524
                        json_object_set_string_member (this_address, "postalcode",
 
525
                                                       couchdb_document_contact_address_get_postalcode (sf));
 
526
                        json_object_set_string_member (this_address, "pobox",
 
527
                                                       couchdb_document_contact_address_get_pobox (sf));
 
528
                        json_object_set_string_member (this_address, "description",
 
529
                                                       couchdb_document_contact_address_get_description (sf));
 
530
 
 
531
                        json_object_set_object_member (addresses,
 
532
                                                       couchdb_struct_field_get_uuid (sf),
 
533
                                                       this_address);
 
534
                }
 
535
        }
 
536
 
 
537
        json_object_set_object_member (couchdb_document_get_json_object (COUCHDB_DOCUMENT (document)),
 
538
                                       "addresses", addresses);
 
539
}
 
540
 
 
541
GSList *
 
542
couchdb_document_contact_get_im_addresses (CouchdbDocumentContact *document)
 
543
{
 
544
        GSList *list = NULL;
 
545
        JsonObject *im_addresses;
 
546
 
 
547
        g_return_val_if_fail (COUCHDB_IS_DOCUMENT_CONTACT (document), NULL);
 
548
        g_return_val_if_fail (couchdb_document_is_contact (COUCHDB_DOCUMENT (document)), NULL);
 
549
 
 
550
        im_addresses = json_object_get_object_member (
 
551
                couchdb_document_get_json_object (COUCHDB_DOCUMENT (document)), "im_addresses");
 
552
        if (im_addresses != NULL) {
 
553
                json_object_foreach_member (im_addresses,
 
554
                                            (JsonObjectForeach) foreach_object_cb,
 
555
                                            &list);
 
556
        }
 
557
 
 
558
        return list;
 
559
}
 
560
 
 
561
void
 
562
couchdb_document_contact_set_im_addresses (CouchdbDocumentContact *document, GSList *list)
 
563
{
 
564
        GSList *l;
 
565
        JsonObject *im_addresses_json;
 
566
 
 
567
        g_return_if_fail (COUCHDB_IS_DOCUMENT_CONTACT (document));
 
568
 
 
569
        im_addresses_json = json_object_new ();
 
570
        for (l = list; l != NULL; l = l->next) {
 
571
                const gchar *address_str;
 
572
                CouchdbStructField *sf = (CouchdbStructField *) l->data;
 
573
 
 
574
                address_str = couchdb_document_contact_im_get_address (sf);
 
575
                if (address_str != NULL) {
 
576
                        JsonObject *this_address;
 
577
 
 
578
                        this_address = json_object_new ();
 
579
                        json_object_set_string_member (this_address, "address", address_str);
 
580
                        json_object_set_string_member (this_address, "description",
 
581
                                                       couchdb_document_contact_im_get_description (sf));
 
582
                        json_object_set_string_member (this_address, "protocol",
 
583
                                                       couchdb_document_contact_im_get_protocol (sf));
 
584
 
 
585
                        json_object_set_object_member (im_addresses_json,
 
586
                                                       couchdb_struct_field_get_uuid (sf),
 
587
                                                       this_address);
 
588
                }
 
589
        }
 
590
 
 
591
        json_object_set_object_member (couchdb_document_get_json_object (COUCHDB_DOCUMENT (document)),
 
592
                                       "im_addresses", im_addresses_json);
 
593
}
 
594
 
 
595
GSList *
 
596
couchdb_document_contact_get_urls (CouchdbDocumentContact *document)
 
597
{
 
598
        GSList *list = NULL;
 
599
        JsonObject *urls;
 
600
 
 
601
        g_return_val_if_fail (COUCHDB_IS_DOCUMENT_CONTACT (document), NULL);
 
602
        g_return_val_if_fail (couchdb_document_is_contact (COUCHDB_DOCUMENT (document)), NULL);
 
603
 
 
604
        urls = json_object_get_object_member (
 
605
                couchdb_document_get_json_object (COUCHDB_DOCUMENT (document)), "urls");
 
606
        if (urls) {
 
607
                json_object_foreach_member (urls,
 
608
                                            (JsonObjectForeach) foreach_object_cb,
 
609
                                            &list);
 
610
        }
 
611
 
 
612
        return list;
 
613
}
 
614
 
 
615
void
 
616
couchdb_document_contact_set_urls (CouchdbDocumentContact *document, GSList *list)
 
617
{
 
618
        GSList *l;
 
619
        JsonObject *urls_json;
 
620
 
 
621
        g_return_if_fail (COUCHDB_IS_DOCUMENT_CONTACT (document));
 
622
 
 
623
        urls_json = json_object_new ();
 
624
        for (l = list; l != NULL; l = l->next) {
 
625
                const gchar *address_str;
 
626
                CouchdbStructField *sf = (CouchdbStructField *) l->data;
 
627
 
 
628
                address_str = couchdb_document_contact_url_get_address (sf);
 
629
                if (address_str) {
 
630
                        JsonObject *this_url;
 
631
 
 
632
                        this_url = json_object_new ();
 
633
                        json_object_set_string_member (this_url, "address", address_str);
 
634
                        json_object_set_string_member (this_url, "description",
 
635
                                                       couchdb_document_contact_url_get_description (sf));
 
636
 
 
637
                        json_object_set_object_member (urls_json,
 
638
                                                       couchdb_struct_field_get_uuid (sf),
 
639
                                                       this_url);
 
640
                }
 
641
        }
 
642
 
 
643
        json_object_set_object_member (couchdb_document_get_json_object (COUCHDB_DOCUMENT (document)),
 
644
                                       "urls", urls_json);
 
645
}
 
646
 
 
647
/**
 
648
 * couchdb_document_contact_get_categories:
 
649
 * @document: A #CouchdbDocumentContact object
 
650
 *
 
651
 * Get the list of categories (as a string) for this contact document.
 
652
 *
 
653
 * Return value: A comma separated list of categories as a string.
 
654
 */
 
655
const char *
 
656
couchdb_document_contact_get_categories (CouchdbDocumentContact *document)
 
657
{
 
658
        g_return_val_if_fail (COUCHDB_IS_DOCUMENT_CONTACT (document), NULL);
 
659
        g_return_val_if_fail (couchdb_document_is_contact (COUCHDB_DOCUMENT (document)), NULL);
 
660
 
 
661
        return couchdb_document_get_string_field (COUCHDB_DOCUMENT (document), "categories");
 
662
}
 
663
 
 
664
void
 
665
couchdb_document_contact_set_categories (CouchdbDocumentContact *document, const char *categories)
 
666
{
 
667
        g_return_if_fail (COUCHDB_IS_DOCUMENT_CONTACT (document));
 
668
        g_return_if_fail (couchdb_document_is_contact (COUCHDB_DOCUMENT (document)));
 
669
        g_return_if_fail (categories != NULL);
 
670
 
 
671
        couchdb_document_set_string_field (COUCHDB_DOCUMENT (document), "categories", categories);
 
672
}
 
673
 
 
674
const char *
 
675
couchdb_document_contact_get_notes (CouchdbDocumentContact *document)
 
676
{
 
677
        g_return_val_if_fail (COUCHDB_IS_DOCUMENT_CONTACT (document), NULL);
 
678
        g_return_val_if_fail (couchdb_document_is_contact (COUCHDB_DOCUMENT (document)), NULL);
 
679
 
 
680
        return couchdb_document_get_string_field (COUCHDB_DOCUMENT (document), "notes");
 
681
}
 
682
 
 
683
void
 
684
couchdb_document_contact_set_notes (CouchdbDocumentContact *document, const char *notes)
 
685
{
 
686
        g_return_if_fail (COUCHDB_IS_DOCUMENT_CONTACT (document));
 
687
        g_return_if_fail (couchdb_document_is_contact (COUCHDB_DOCUMENT (document)));
 
688
        g_return_if_fail (notes != NULL);
 
689
 
 
690
        couchdb_document_set_string_field (COUCHDB_DOCUMENT (document), "notes", notes);
 
691
}
 
692
 
 
693
CouchdbStructField *
 
694
couchdb_document_contact_email_new (const char *uuid, const char *address, const char *description)
 
695
{
 
696
        CouchdbStructField *sf;
 
697
 
 
698
        sf = couchdb_struct_field_new_from_json_object (json_object_new ());
 
699
        if (uuid != NULL)
 
700
                couchdb_struct_field_set_uuid (sf, uuid);
 
701
        else {
 
702
                char *new_uuid = generate_uuid ();
 
703
                couchdb_struct_field_set_uuid (sf, new_uuid);
 
704
                g_free (new_uuid);
 
705
        }
 
706
 
 
707
        if (address)
 
708
                couchdb_document_contact_email_set_address (sf, address);
 
709
        if (description)
 
710
                couchdb_document_contact_email_set_description (sf, description);
 
711
 
 
712
        return sf;
 
713
}
 
714
 
 
715
const char *
 
716
couchdb_document_contact_email_get_address (CouchdbStructField *sf)
 
717
{
 
718
        g_return_val_if_fail (sf != NULL, NULL);
 
719
 
 
720
        return couchdb_struct_field_get_string_field (sf, "address");
 
721
}
 
722
 
 
723
void
 
724
couchdb_document_contact_email_set_address (CouchdbStructField *sf, const char *email)
 
725
{
 
726
        g_return_if_fail (sf != NULL);
 
727
        g_return_if_fail (email != NULL);
 
728
 
 
729
        couchdb_struct_field_set_string_field (sf, "address", email);
 
730
}
 
731
 
 
732
const char *
 
733
couchdb_document_contact_email_get_description (CouchdbStructField *sf)
 
734
{
 
735
        g_return_val_if_fail (sf != NULL, NULL);
 
736
 
 
737
        return couchdb_struct_field_get_string_field (sf, "description");
 
738
}
 
739
 
 
740
void
 
741
couchdb_document_contact_email_set_description (CouchdbStructField *sf, const char *description)
 
742
{
 
743
        g_return_if_fail (sf != NULL);
 
744
 
 
745
        couchdb_struct_field_set_string_field (sf, "description", description);
 
746
}
 
747
 
 
748
CouchdbStructField *
 
749
couchdb_document_contact_phone_new (const char *uuid, const char *number, const char *description, gint priority)
 
750
{
 
751
        CouchdbStructField *sf;
 
752
 
 
753
        sf = couchdb_struct_field_new_from_json_object (json_object_new ());
 
754
        if (uuid != NULL)
 
755
                couchdb_struct_field_set_uuid (sf, uuid);
 
756
        else {
 
757
                char *new_uuid = generate_uuid ();
 
758
                couchdb_struct_field_set_uuid (sf, new_uuid);
 
759
                g_free (new_uuid);
 
760
        }
 
761
 
 
762
        if (number)
 
763
                couchdb_document_contact_phone_set_number (sf, number);
 
764
        if (description)
 
765
                couchdb_document_contact_phone_set_description (sf, description);
 
766
        couchdb_document_contact_phone_set_priority (sf, priority);
 
767
 
 
768
        return sf;
 
769
}
 
770
 
 
771
gint
 
772
couchdb_document_contact_phone_get_priority (CouchdbStructField *sf)
 
773
{
 
774
        g_return_val_if_fail (sf != NULL, 0);
 
775
 
 
776
        return couchdb_struct_field_get_int_field (sf, "priority");
 
777
}
 
778
 
 
779
void
 
780
couchdb_document_contact_phone_set_priority (CouchdbStructField *sf, gint priority)
 
781
{
 
782
        g_return_if_fail (sf != NULL);
 
783
 
 
784
        couchdb_struct_field_set_int_field (sf, "priority", priority);
 
785
}
 
786
 
 
787
const char *
 
788
couchdb_document_contact_phone_get_number (CouchdbStructField *sf)
 
789
{
 
790
        g_return_val_if_fail (sf != NULL, NULL);
 
791
 
 
792
        return couchdb_struct_field_get_string_field (sf, "number");
 
793
}
 
794
 
 
795
void
 
796
couchdb_document_contact_phone_set_number (CouchdbStructField *sf, const char *number)
 
797
{
 
798
        g_return_if_fail (sf != NULL);
 
799
        g_return_if_fail (number != NULL);
 
800
 
 
801
        couchdb_struct_field_set_string_field (sf, "number", number);
 
802
}
 
803
 
 
804
const char *
 
805
couchdb_document_contact_phone_get_description (CouchdbStructField *sf)
 
806
{
 
807
        g_return_val_if_fail (sf != NULL, NULL);
 
808
 
 
809
        return couchdb_struct_field_get_string_field (sf, "description");
 
810
}
 
811
 
 
812
void
 
813
couchdb_document_contact_phone_set_description (CouchdbStructField *sf, const char *description)
 
814
{
 
815
        g_return_if_fail (sf != NULL);
 
816
 
 
817
        couchdb_struct_field_set_string_field (sf, "description", description);
 
818
}
 
819
 
 
820
CouchdbStructField *
 
821
couchdb_document_contact_address_new (const char *uuid,
 
822
                                           const char *street,
 
823
                                           const char *ext_street,
 
824
                                           const char *city,
 
825
                                           const char *state,
 
826
                                           const char *country,
 
827
                                           const char *postalcode,
 
828
                                           const char *pobox,
 
829
                                           const char *description)
 
830
{
 
831
        CouchdbStructField *sf;
 
832
 
 
833
        sf = couchdb_struct_field_new_from_json_object (json_object_new ());
 
834
        if (uuid != NULL)
 
835
                couchdb_struct_field_set_uuid (sf, uuid);
 
836
        else {
 
837
                char *new_uuid = generate_uuid ();
 
838
                couchdb_struct_field_set_uuid (sf, new_uuid);
 
839
                g_free (new_uuid);
 
840
        }
 
841
 
 
842
        if (street)
 
843
                couchdb_document_contact_address_set_street (sf, street);
 
844
        if (ext_street)
 
845
                couchdb_document_contact_address_set_ext_street (sf, ext_street);
 
846
        if (city)
 
847
                couchdb_document_contact_address_set_city (sf, city);
 
848
        if (state)
 
849
                couchdb_document_contact_address_set_state (sf, state);
 
850
        if (country)
 
851
                couchdb_document_contact_address_set_country (sf, country);
 
852
        if (postalcode)
 
853
                couchdb_document_contact_address_set_postalcode (sf, postalcode);
 
854
        if (pobox)
 
855
                couchdb_document_contact_address_set_pobox (sf, pobox);
 
856
        if (description)
 
857
                couchdb_document_contact_address_set_description (sf, description);
 
858
 
 
859
        return sf;
 
860
}
 
861
 
 
862
const char *
 
863
couchdb_document_contact_address_get_street (CouchdbStructField *sf)
 
864
{
 
865
        g_return_val_if_fail (sf != NULL, NULL);
 
866
 
 
867
        if (couchdb_struct_field_has_field (sf, "address1"))
 
868
                return couchdb_struct_field_get_string_field (sf, "address1");
 
869
        else if (couchdb_struct_field_has_field (sf, "street"))
 
870
                return couchdb_struct_field_get_string_field (sf, "street");
 
871
 
 
872
        return NULL;
 
873
}
 
874
 
 
875
void
 
876
couchdb_document_contact_address_set_street (CouchdbStructField *sf, const char *street)
 
877
{
 
878
        g_return_if_fail (sf != NULL);
 
879
 
 
880
        couchdb_struct_field_set_string_field (sf, "address1", street);
 
881
}
 
882
 
 
883
const char *
 
884
couchdb_document_contact_address_get_ext_street (CouchdbStructField *sf)
 
885
{
 
886
        g_return_val_if_fail (sf != NULL, NULL);
 
887
 
 
888
        return couchdb_struct_field_get_string_field (sf, "address2");
 
889
}
 
890
 
 
891
void
 
892
couchdb_document_contact_address_set_ext_street (CouchdbStructField *sf, const char *ext_street)
 
893
{
 
894
        g_return_if_fail (sf != NULL);
 
895
 
 
896
        couchdb_struct_field_set_string_field (sf, "address2", ext_street);
 
897
}
 
898
 
 
899
const char *
 
900
couchdb_document_contact_address_get_city (CouchdbStructField *sf)
 
901
{
 
902
        g_return_val_if_fail (sf != NULL, NULL);
 
903
 
 
904
        return couchdb_struct_field_get_string_field (sf, "city");
 
905
}
 
906
 
 
907
void
 
908
couchdb_document_contact_address_set_city (CouchdbStructField *sf, const char *city)
 
909
{
 
910
        g_return_if_fail (sf != NULL);
 
911
 
 
912
        couchdb_struct_field_set_string_field (sf, "city", city);
 
913
}
 
914
 
 
915
const char *
 
916
couchdb_document_contact_address_get_state (CouchdbStructField *sf)
 
917
{
 
918
        g_return_val_if_fail (sf != NULL, NULL);
 
919
 
 
920
        return couchdb_struct_field_get_string_field (sf, "state");
 
921
}
 
922
 
 
923
void
 
924
couchdb_document_contact_address_set_state (CouchdbStructField *sf, const char *state)
 
925
{
 
926
        g_return_if_fail (sf != NULL);
 
927
 
 
928
        couchdb_struct_field_set_string_field (sf, "state", state);
 
929
}
 
930
 
 
931
const char *
 
932
couchdb_document_contact_address_get_country (CouchdbStructField *sf)
 
933
{
 
934
        g_return_val_if_fail (sf != NULL, NULL);
 
935
 
 
936
        return couchdb_struct_field_get_string_field (sf, "country");
 
937
}
 
938
 
 
939
void
 
940
couchdb_document_contact_address_set_country (CouchdbStructField *sf, const char *country)
 
941
{
 
942
        g_return_if_fail (sf != NULL);
 
943
 
 
944
        couchdb_struct_field_set_string_field (sf, "country", country);
 
945
}
 
946
 
 
947
const char *
 
948
couchdb_document_contact_address_get_postalcode (CouchdbStructField *sf)
 
949
{
 
950
        g_return_val_if_fail (sf != NULL, NULL);
 
951
 
 
952
        return couchdb_struct_field_get_string_field (sf, "postalcode");
 
953
}
 
954
 
 
955
void
 
956
couchdb_document_contact_address_set_postalcode (CouchdbStructField *sf, const char *postalcode)
 
957
{
 
958
        g_return_if_fail (sf != NULL);
 
959
 
 
960
        couchdb_struct_field_set_string_field (sf, "postalcode", postalcode);
 
961
}
 
962
 
 
963
const char *
 
964
couchdb_document_contact_address_get_pobox (CouchdbStructField *sf)
 
965
{
 
966
        g_return_val_if_fail (sf != NULL, NULL);
 
967
 
 
968
        return couchdb_struct_field_get_string_field (sf, "pobox");
 
969
}
 
970
 
 
971
void
 
972
couchdb_document_contact_address_set_pobox (CouchdbStructField *sf, const char *pobox)
 
973
{
 
974
        g_return_if_fail (sf != NULL);
 
975
 
 
976
        couchdb_struct_field_set_string_field (sf, "pobox", pobox);
 
977
}
 
978
 
 
979
const char *
 
980
couchdb_document_contact_address_get_description (CouchdbStructField *sf)
 
981
{
 
982
        g_return_val_if_fail (sf != NULL, NULL);
 
983
 
 
984
        return couchdb_struct_field_get_string_field (sf, "description");
 
985
}
 
986
 
 
987
void
 
988
couchdb_document_contact_address_set_description (CouchdbStructField *sf, const char *description)
 
989
{
 
990
        g_return_if_fail (sf != NULL);
 
991
 
 
992
        couchdb_struct_field_set_string_field (sf, "description", description);
 
993
}
 
994
 
 
995
CouchdbStructField *
 
996
couchdb_document_contact_im_new (const char *uuid,
 
997
                                 const char *address,
 
998
                                 const char *description,
 
999
                                 const char *protocol)
 
1000
{
 
1001
        CouchdbStructField *sf;
 
1002
 
 
1003
        sf = couchdb_struct_field_new_from_json_object (json_object_new ());
 
1004
        if (uuid != NULL)
 
1005
                couchdb_struct_field_set_uuid (sf, uuid);
 
1006
        else {
 
1007
                char *new_uuid = generate_uuid ();
 
1008
                couchdb_struct_field_set_uuid (sf, new_uuid);
 
1009
                g_free (new_uuid);
 
1010
        }
 
1011
 
 
1012
        if (address != NULL)
 
1013
                couchdb_document_contact_im_set_address (sf, address);
 
1014
        if (description != NULL)
 
1015
                couchdb_document_contact_im_set_description (sf, description);
 
1016
        if (protocol != NULL)
 
1017
                couchdb_document_contact_im_set_protocol (sf, protocol);
 
1018
 
 
1019
        return sf;
 
1020
}
 
1021
 
 
1022
const char *
 
1023
couchdb_document_contact_im_get_address (CouchdbStructField *sf)
 
1024
{
 
1025
        g_return_val_if_fail (sf != NULL, NULL);
 
1026
 
 
1027
        return couchdb_struct_field_get_string_field (sf, "address");
 
1028
}
 
1029
 
 
1030
void
 
1031
couchdb_document_contact_im_set_address (CouchdbStructField *sf, const char *address)
 
1032
{
 
1033
        g_return_if_fail (sf != NULL);
 
1034
        g_return_if_fail (address != NULL);
 
1035
 
 
1036
        couchdb_struct_field_set_string_field (sf, "address", address);
 
1037
}
 
1038
 
 
1039
const char *
 
1040
couchdb_document_contact_im_get_description (CouchdbStructField *sf)
 
1041
{
 
1042
        g_return_val_if_fail (sf != NULL, NULL);
 
1043
 
 
1044
        return couchdb_struct_field_get_string_field (sf, "description");
 
1045
}
 
1046
 
 
1047
void
 
1048
couchdb_document_contact_im_set_description (CouchdbStructField *sf, const char *description)
 
1049
{
 
1050
        g_return_if_fail (sf != NULL);
 
1051
        g_return_if_fail (description != NULL);
 
1052
 
 
1053
        couchdb_struct_field_set_string_field (sf, "description", description);
 
1054
}
 
1055
 
 
1056
const char *
 
1057
couchdb_document_contact_im_get_protocol (CouchdbStructField *sf)
 
1058
{
 
1059
        g_return_val_if_fail (sf != NULL, NULL);
 
1060
 
 
1061
        return couchdb_struct_field_get_string_field (sf, "protocol");
 
1062
}
 
1063
 
 
1064
void
 
1065
couchdb_document_contact_im_set_protocol (CouchdbStructField *sf, const char *protocol)
 
1066
{
 
1067
        g_return_if_fail (sf != NULL);
 
1068
        g_return_if_fail (protocol != NULL);
 
1069
 
 
1070
        couchdb_struct_field_set_string_field (sf, "protocol", protocol);
 
1071
}
 
1072
 
 
1073
CouchdbStructField *
 
1074
couchdb_document_contact_url_new (const char *uuid, const char *address, const char *description)
 
1075
{
 
1076
        CouchdbStructField *sf;
 
1077
 
 
1078
        sf = couchdb_struct_field_new_from_json_object (json_object_new ());
 
1079
        if (uuid != NULL)
 
1080
                couchdb_struct_field_set_uuid (sf, uuid);
 
1081
        else {
 
1082
                char *new_uuid = generate_uuid ();
 
1083
                couchdb_struct_field_set_uuid (sf, new_uuid);
 
1084
                g_free (new_uuid);
 
1085
        }
 
1086
 
 
1087
        if (address)
 
1088
                couchdb_document_contact_url_set_address (sf, address);
 
1089
        if (description)
 
1090
                couchdb_document_contact_url_set_description (sf, description);
 
1091
 
 
1092
        return sf;
 
1093
}
 
1094
 
 
1095
const char *
 
1096
couchdb_document_contact_url_get_address (CouchdbStructField *sf)
 
1097
{
 
1098
        g_return_val_if_fail (sf != NULL, NULL);
 
1099
 
 
1100
        return couchdb_struct_field_get_string_field (sf, "address");
 
1101
}
 
1102
 
 
1103
void
 
1104
couchdb_document_contact_url_set_address (CouchdbStructField *sf, const char *url)
 
1105
{
 
1106
        g_return_if_fail (sf != NULL);
 
1107
        g_return_if_fail (url != NULL);
 
1108
 
 
1109
        couchdb_struct_field_set_string_field (sf, "address", url);
 
1110
}
 
1111
 
 
1112
const char *
 
1113
couchdb_document_contact_url_get_description (CouchdbStructField *sf)
 
1114
{
 
1115
        g_return_val_if_fail (sf != NULL, NULL);
 
1116
 
 
1117
        return couchdb_struct_field_get_string_field (sf, "description");
 
1118
}
 
1119
 
 
1120
void
 
1121
couchdb_document_contact_url_set_description (CouchdbStructField *sf, const char *description)
 
1122
{
 
1123
        g_return_if_fail (sf != NULL);
 
1124
 
 
1125
        couchdb_struct_field_set_string_field (sf, "description", description);
 
1126
}