~ubuntu-branches/ubuntu/maverick/ekiga/maverick

« back to all changes in this revision

Viewing changes to lib/gmcontacts/gmcontacts-gmconf.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2008-12-07 10:30:45 UTC
  • mfrom: (1.2.3 experimental)
  • Revision ID: james.westby@ubuntu.com-20081207103045-iaurrjo4p7d1nngo
Tags: 3.0.1-1ubuntu1
* Merge to Debian experimental, to get Ekiga 3. (LP: #274085) Remaining
  Ubuntu changes:
  - Launchpad Integration: (Ubuntu specific)
    + debian/control.in: Add liblaunchpad-integration-dev build dependency.
    + Add ubuntu_lpi.patch: Call launchpad_integration_add_items() in main() and
      check for the launchpad-integration pkg-config module.
    + Add autoconf.patch: autoconf changes from above patch.
  - Add ubuntu_desktop-file-onlyshowin.patch: Show ekiga in Mobile, too.
    (Ubuntu specific).
  - debian/control.in: Add missing fdupes build dependency for identical
    GNOME help file symlinking. (Debian #505536)
* Drop 42_change_pixmaps.dpatch: Many of the old icons do not exist any
  more, some have been replaced, and keeping the remaining three would make
  them look very inconsistent.
* Convert our dpatches to quilt patches and rewrite them for new upstream
  version.
* Add migrate_2.0_settings.patch: Properly migrate settings from
  2.0. Taken from upstream SVN, thanks to Damien Sandras!

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
 
2
 
/* Ekiga -- A VoIP and Video-Conferencing application
3
 
 * Copyright (C) 2000-2006 Damien Sandras
4
 
 *
5
 
 * This program is free software; you can redistribute it and/or modify
6
 
 * it under the terms of the GNU General Public License as published by
7
 
 * the Free Software Foundation; either version 2 of the License, or
8
 
 * (at your option) any later version.
9
 
 *
10
 
 * This program is distributed in the hope that it will be useful,
11
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
 * GNU General Public License for more details.
14
 
 *
15
 
 * You should have received a copy of the GNU General Public License
16
 
 * along with this program; if not, write to the Free Software Foundation,
17
 
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
18
 
 *
19
 
 *
20
 
 * Ekiga is licensed under the GPL license and as a special exception,
21
 
 * you have permission to link or otherwise combine this program with the
22
 
 * programs OPAL, OpenH323 and PWLIB, and distribute the combination,
23
 
 * without applying the requirements of the GNU GPL to the OPAL, OpenH323
24
 
 * and PWLIB programs, as long as you do follow the requirements of the
25
 
 * GNU GPL for all the rest of the software thus combined.
26
 
 */
27
 
 
28
 
 
29
 
/*
30
 
 *                         gmcontacts-gmconf.cpp - description 
31
 
 *                         ---------------------------
32
 
 *   begin                : Mon Apr 19 2004
33
 
 *   copyright            : (C) 2004-2006 by Julien Puydt
34
 
 *                          (C) 2004-2006 by Damien Sandras
35
 
 *                          (C) 2006 by Kilian Krause
36
 
 *   description          : Implementation of an addressbook using gmconf
37
 
 *
38
 
 */
39
 
 
40
 
 
41
 
#include "../../config.h"
42
 
 
43
 
#include "gmconf.h"
44
 
#include "gmcontacts.h"
45
 
#ifndef _GM_CONTACTS_H_INSIDE__
46
 
#define _GM_CONTACTS_H_INSIDE__
47
 
#include "gmcontacts-local.h"
48
 
#include "gmcontacts-convert.h"
49
 
#undef _GM_CONTACTS_H_INSIDE__
50
 
#endif
51
 
#include <stdlib.h>
52
 
#include <string.h>
53
 
 
54
 
/*
55
 
 * The following is the implementation of the local addressbooks, when
56
 
 * gnomemeeting is compiled without evolution-data-server support: it uses
57
 
 * the configuration system (gmconf) to store the data.
58
 
 *
59
 
 * Everything is stored under CONTACTS_KEY, in the following form:
60
 
 * - an addressbook identifier is an integer starting at 1 ;
61
 
 * (stored as a string) ;
62
 
 * - the integer key CONTACTS_KEY "max_aid" stores the maximum addressbook
63
 
 * identifier (to know when to stop when searching the list of addressbooks:
64
 
 * there may be an empty slot in the middle after a removal, so looking for
65
 
 * empty slot isn't a good idea) ;
66
 
 * - the addressbook is stored in the CONTACTS_KEY (string of the aid)
67
 
 * namespace ;
68
 
 * - the addressbook features are directly stored in the namespace: for example
69
 
 * CONTACTS_KEY (string of the aid)"/name" stores the name of the
70
 
 * group ;
71
 
 * - a contact identifier is an integer starting at 1 (and has a meaning in the
72
 
 * addressbook only) ;
73
 
 * - a contact is stored as a vcard in the addressbook namespace:
74
 
 * CONTACTS_KEY (string of the aid) "/" (string of the uid) ;
75
 
 * - the integer key CONTACTS_KEY (string of the aid)"/max_uid" stores the
76
 
 * maximum contact identifier (for the same reasons as above).
77
 
 *
78
 
 * NB: starting the counts at 1 has the bonus that a 0 can mean "doesn't exist"
79
 
 */
80
 
 
81
 
#define CONTACTS_KEY "/apps/" PACKAGE_NAME "/contacts/"
82
 
 
83
 
 
84
 
/*
85
 
 * Declaration of the helper functions
86
 
 */
87
 
 
88
 
/* this function checks if str2 is a substring of str2
89
 
 */
90
 
static gboolean str_contains (const gchar *str1, const gchar *str2);
91
 
 
92
 
/* this function retrieves the contact with the given "coordinates"
93
 
 * from the configuration ; it wants and checks aid > 0 and uid > 0.
94
 
 */
95
 
static GmContact *get_contact (gint aid, 
96
 
                               gint uid);
97
 
 
98
 
 
99
 
/* this function stores the given contact in the configuration, at the
100
 
 * given "coordinates" ; it wants and checks aid > 0, and contact != NULL
101
 
 * with a valid (> 0) uid.
102
 
 */
103
 
static gboolean store_contact (GmContact *contact, 
104
 
                               gint aid); 
105
 
 
106
 
 
107
 
/* this function retrieves the addressbook with the given identifier
108
 
 * from the configuration ; it wants and checks aid > 0.
109
 
 */
110
 
static GmAddressbook *get_addressbook (gint aid);
111
 
 
112
 
 
113
 
/* this function stores the addressbook in the configuration, at the
114
 
 * given identifier ; it wants and checks addb != NULL with a valid aid.
115
 
 */
116
 
static gboolean store_addressbook (GmAddressbook *addb);
117
 
 
118
 
 
119
 
/* this function returns the first available addressbook identifier
120
 
 * (that can be max_aid+1 or the old identifier of a removed group)
121
 
 */
122
 
static gint get_available_aid ();
123
 
 
124
 
 
125
 
/* this function returns the first available contact identifier
126
 
 * available in the given group (again, that can be either max_uid+1 or
127
 
 * the old identifier of a removed contact) [it wants and checks aid > 0]
128
 
 */
129
 
static gint get_available_uid (gint aid);
130
 
 
131
 
 
132
 
/*
133
 
 * Implementation of the helper functions
134
 
 */
135
 
 
136
 
 
137
 
static
138
 
gboolean str_contains (const gchar *str1, const gchar *str2)
139
 
{
140
 
  return (g_strrstr (str1, str2) != NULL);
141
 
}
142
 
 
143
 
 
144
 
static GmContact *
145
 
get_contact (gint aid, 
146
 
             gint uid)
147
 
{
148
 
  gchar *vcard = NULL;
149
 
  gchar *key = NULL;
150
 
  GmContact *contact = NULL;
151
 
 
152
 
  g_return_val_if_fail (aid > 0, NULL);
153
 
  g_return_val_if_fail (uid > 0, NULL);
154
 
  
155
 
  key = g_strdup_printf (CONTACTS_KEY "%d/%d", aid, uid);
156
 
  vcard = gm_conf_get_string (key);
157
 
  g_free (key);
158
 
 
159
 
  if (vcard != NULL) {
160
 
    contact = vcard_to_gmcontact (vcard);
161
 
    contact->uid = g_strdup_printf ("%d", uid);
162
 
  }
163
 
 
164
 
  return contact;
165
 
}
166
 
 
167
 
 
168
 
static gboolean
169
 
store_contact (GmContact *contact, 
170
 
               gint aid)
171
 
{
172
 
  gchar *vcard = NULL;
173
 
  gchar *key = NULL;
174
 
  gint uid = 0;
175
 
  gint max_uid = 0;
176
 
 
177
 
  g_return_val_if_fail (contact != NULL, FALSE);
178
 
  g_return_val_if_fail (contact->uid != NULL, FALSE);
179
 
  g_return_val_if_fail (aid > 0, FALSE);
180
 
 
181
 
  uid = strtol (contact->uid, NULL, 10);
182
 
  g_return_val_if_fail (uid > 0, FALSE);
183
 
 
184
 
  vcard = gmcontact_to_vcard (contact);
185
 
  key = g_strdup_printf (CONTACTS_KEY "%d/%d", aid, uid);
186
 
  gm_conf_set_string (key, vcard);
187
 
  g_free (key);  
188
 
  g_free (vcard);
189
 
 
190
 
  key = g_strdup_printf (CONTACTS_KEY "%d/max_uid", aid);
191
 
  max_uid = gm_conf_get_int (key);
192
 
  if (uid > max_uid)
193
 
    gm_conf_set_int (key, uid);
194
 
  g_free (key);
195
 
 
196
 
  return TRUE;
197
 
}
198
 
 
199
 
 
200
 
static GmAddressbook *
201
 
get_addressbook (gint aid)
202
 
{
203
 
  GmAddressbook *addb = NULL;
204
 
  gchar *key = NULL;
205
 
  gchar *str = NULL;
206
 
 
207
 
  g_return_val_if_fail (aid > 0, NULL);
208
 
 
209
 
  addb = gm_addressbook_new ();
210
 
 
211
 
  addb->aid = g_strdup_printf ("%d", aid);
212
 
 
213
 
  key = g_strdup_printf (CONTACTS_KEY "%d/name", aid);
214
 
  str = gm_conf_get_string (key);
215
 
  if (str != NULL)
216
 
    addb->name = g_strdup (str);
217
 
  g_free (key);
218
 
 
219
 
  key = g_strdup_printf (CONTACTS_KEY "%d/url", aid);
220
 
  str = gm_conf_get_string (key);
221
 
  if (str != NULL)
222
 
    addb->url = g_strdup (str);
223
 
  g_free (key);
224
 
 
225
 
  key = g_strdup_printf (CONTACTS_KEY "%d/call_attribute", aid);
226
 
  str = gm_conf_get_string (key);
227
 
  if (str != NULL)
228
 
    addb->call_attribute = g_strdup (str);
229
 
  g_free (key);
230
 
 
231
 
  if (addb->name == NULL
232
 
      && addb->url == NULL 
233
 
      && addb->call_attribute == NULL) {
234
 
    gm_addressbook_delete (addb);
235
 
    addb = NULL;
236
 
  }
237
 
 
238
 
  return addb;
239
 
}
240
 
 
241
 
 
242
 
static gboolean
243
 
store_addressbook (GmAddressbook *addb)
244
 
{
245
 
  gchar *key = NULL;
246
 
  gint max_aid = 0;
247
 
  gint aid = 0;
248
 
 
249
 
  g_return_val_if_fail (addb != NULL, FALSE);
250
 
  g_return_val_if_fail (addb->aid != NULL, FALSE);
251
 
 
252
 
  aid = strtol (addb->aid, NULL, 10);
253
 
  
254
 
  g_return_val_if_fail (aid > 0, FALSE);
255
 
 
256
 
  key = g_strdup_printf (CONTACTS_KEY "%d/name", aid);
257
 
  if (addb->name != NULL)
258
 
    gm_conf_set_string (key, addb->name);
259
 
  else
260
 
    gm_conf_destroy (key);
261
 
  g_free (key);
262
 
 
263
 
  key = g_strdup_printf (CONTACTS_KEY "%d/url", aid);
264
 
  if (addb->url != NULL)
265
 
    gm_conf_set_string (key, addb->url);
266
 
  else
267
 
    gm_conf_destroy (key);
268
 
  g_free (key);
269
 
 
270
 
  key = g_strdup_printf (CONTACTS_KEY "%d/call_attribute", aid);
271
 
  if (addb->call_attribute != NULL)
272
 
    gm_conf_set_string (key, addb->call_attribute);
273
 
  else
274
 
    gm_conf_destroy (key);
275
 
  g_free (key);
276
 
 
277
 
  max_aid = gm_conf_get_int (CONTACTS_KEY "max_aid");
278
 
  if (aid > max_aid)
279
 
    gm_conf_set_int (CONTACTS_KEY "max_aid", aid);
280
 
 
281
 
  return TRUE;
282
 
}
283
 
 
284
 
 
285
 
static gint
286
 
get_available_aid ()
287
 
{
288
 
  gint aid = 1;
289
 
  gint max_aid = 1;
290
 
  GmAddressbook *addb = NULL;
291
 
 
292
 
  max_aid = gm_conf_get_int (CONTACTS_KEY "max_aid");
293
 
  
294
 
  for (aid = 1; aid < max_aid + 1; aid++) {
295
 
    addb = get_addressbook (aid);
296
 
    if (addb == NULL)
297
 
      break;
298
 
    gm_addressbook_delete (addb);
299
 
  }
300
 
  
301
 
  return aid;
302
 
}
303
 
 
304
 
 
305
 
static gint
306
 
get_available_uid (gint aid)
307
 
{
308
 
  gint uid = 1;
309
 
  gint max_uid = 1;
310
 
  gchar *key = NULL;
311
 
  GmContact *contact = NULL;
312
 
 
313
 
  g_return_val_if_fail (aid > 0, 1);
314
 
 
315
 
  key = g_strdup_printf (CONTACTS_KEY "%d/max_uid", aid);
316
 
  max_uid = gm_conf_get_int (key);
317
 
  g_free (key);
318
 
  
319
 
  for (uid = 1; uid < max_uid + 1; uid++) {
320
 
    contact = get_contact (aid, uid);
321
 
    if (contact == NULL)
322
 
      break;
323
 
    gmcontact_delete (contact);
324
 
  }
325
 
 
326
 
  return uid;
327
 
}
328
 
 
329
 
 
330
 
/*
331
 
 * Implementation of the public api
332
 
 */
333
 
 
334
 
 
335
 
GmContact *
336
 
gmcontact_new ()
337
 
{
338
 
  GmContact *contact = NULL;
339
 
 
340
 
  contact = g_new (GmContact, 1);
341
 
 
342
 
  contact->fullname = NULL;
343
 
  contact->categories = NULL;
344
 
  contact->url = NULL;
345
 
  contact->location = NULL;
346
 
  contact->speeddial = NULL;
347
 
  contact->comment = NULL;
348
 
  contact->software = NULL;
349
 
  contact->email = NULL;
350
 
  contact->state = CONTACT_AVAILABLE;
351
 
  contact->video_capable = FALSE;
352
 
  contact->uid = NULL; 
353
 
 
354
 
  return contact;
355
 
}
356
 
 
357
 
 
358
 
GmContact *
359
 
gmcontact_copy (GmContact *orig)
360
 
{
361
 
  GmContact *contact = NULL;
362
 
 
363
 
  contact = g_new (GmContact, 1);
364
 
 
365
 
  contact->fullname = g_strdup (orig->fullname);
366
 
  contact->categories = g_strdup (orig->categories);
367
 
  contact->url = g_strdup (orig->url);
368
 
  contact->location = g_strdup (orig->location);
369
 
  contact->speeddial = g_strdup (orig->speeddial);
370
 
  contact->comment = g_strdup (orig->comment);
371
 
  contact->software = g_strdup (orig->software);
372
 
  contact->email = g_strdup (orig->email);
373
 
  contact->state = orig->state;
374
 
  contact->video_capable = orig->video_capable;
375
 
  contact->uid = g_strdup (orig->uid); 
376
 
 
377
 
  return contact;
378
 
}
379
 
 
380
 
 
381
 
void
382
 
gmcontact_delete (GmContact *contact)
383
 
{
384
 
  if (!contact)
385
 
    return;
386
 
 
387
 
  g_free (contact->fullname);
388
 
  g_free (contact->url);
389
 
  g_free (contact->speeddial);
390
 
  g_free (contact->categories);
391
 
  g_free (contact->comment);
392
 
  g_free (contact->software);
393
 
  g_free (contact->email);
394
 
  g_free (contact->uid);
395
 
 
396
 
  g_free (contact);
397
 
}
398
 
 
399
 
 
400
 
GmAddressbook *
401
 
gm_addressbook_new ()
402
 
{
403
 
  GmAddressbook *addressbook = NULL;
404
 
 
405
 
  addressbook = g_new (GmAddressbook, 1);
406
 
  
407
 
  addressbook->name = NULL;
408
 
  addressbook->url = NULL;
409
 
  addressbook->aid = g_strdup_printf ("%010d", g_random_int());
410
 
  addressbook->call_attribute = NULL;
411
 
 
412
 
  return addressbook;
413
 
}
414
 
 
415
 
 
416
 
void 
417
 
gm_addressbook_delete (GmAddressbook *addressbook)
418
 
{
419
 
  if (!addressbook)
420
 
    return;
421
 
 
422
 
  g_free (addressbook->url);
423
 
  g_free (addressbook->aid);
424
 
  g_free (addressbook->name);
425
 
  g_free (addressbook->call_attribute);
426
 
 
427
 
  g_free (addressbook);  
428
 
}
429
 
 
430
 
 
431
 
GSList *
432
 
gnomemeeting_get_local_addressbooks ()
433
 
{
434
 
  gint i = 0;
435
 
  gint max_aid = 0;
436
 
  GmAddressbook *addb = NULL;
437
 
  GSList *result = NULL;
438
 
 
439
 
  max_aid = gm_conf_get_int (CONTACTS_KEY "max_aid");
440
 
 
441
 
  for (i = 1; i <= max_aid ; i++) {
442
 
    addb = get_addressbook (i);
443
 
    if (addb != NULL)
444
 
      result = g_slist_append (result, (gpointer)addb);
445
 
  }
446
 
 
447
 
  return result;
448
 
}
449
 
 
450
 
 
451
 
GSList *
452
 
gnomemeeting_local_addressbook_get_contacts (GmAddressbook *addb,
453
 
                                             int & nbr,
454
 
                                             gboolean partial_match,
455
 
                                             const gchar *fullname,
456
 
                                             const gchar *url,
457
 
                                             const gchar *categorie,
458
 
                                             const gchar *location,
459
 
                                             const gchar *speeddial)
460
 
{
461
 
  gchar *key = NULL;
462
 
  gint aid = 0;
463
 
  gint uid = 0;
464
 
  gint max_uid = 0;
465
 
  gint max_aid = 0;
466
 
  gboolean matching = TRUE;
467
 
  GmContact *contact = NULL;
468
 
  GSList *result = NULL;
469
 
  GmAddressbook *addb_loop = NULL;
470
 
 
471
 
  if (addb != NULL) {
472
 
    
473
 
    aid = strtol (addb->aid, NULL, 10);
474
 
 
475
 
    g_return_val_if_fail (aid > 0, NULL);
476
 
   
477
 
    key = g_strdup_printf (CONTACTS_KEY "%d/max_uid", aid);
478
 
    max_uid = gm_conf_get_int (key);
479
 
    g_free (key);
480
 
    
481
 
    for (uid = 1; uid <= max_uid ; uid++) {
482
 
      contact = get_contact (aid, uid);
483
 
      if (contact != NULL) {
484
 
        
485
 
        if (partial_match)
486
 
          matching = FALSE;
487
 
        else
488
 
          matching = TRUE;
489
 
 
490
 
        if (fullname) {
491
 
 
492
 
          if (str_contains (contact->fullname, fullname)) {
493
 
 
494
 
            if (partial_match)
495
 
              matching = TRUE;
496
 
          } else
497
 
            if (!partial_match)
498
 
              matching = FALSE;
499
 
        }
500
 
 
501
 
        if (url) {
502
 
 
503
 
          if (str_contains (contact->url, url)) {
504
 
 
505
 
            if (partial_match)
506
 
              matching = TRUE;
507
 
          } else
508
 
            if (!partial_match)
509
 
              matching = FALSE;
510
 
        }
511
 
 
512
 
        if (categorie) {
513
 
 
514
 
          if (str_contains (contact->categories, categorie)) {
515
 
 
516
 
            if (partial_match)
517
 
              matching = TRUE;
518
 
          } else
519
 
            if (!partial_match)
520
 
              matching = FALSE;
521
 
        }
522
 
 
523
 
        if (speeddial) {
524
 
    
525
 
          if (str_contains (contact->speeddial, speeddial)) {
526
 
 
527
 
            if (partial_match)
528
 
              matching = TRUE;
529
 
          } else
530
 
            if (!partial_match)
531
 
              matching = FALSE;
532
 
        }
533
 
 
534
 
        if (partial_match
535
 
            && fullname == NULL
536
 
            && url == NULL
537
 
            && categorie == NULL
538
 
            && speeddial == NULL)
539
 
          matching = TRUE; /* nothing was tested, so the contact is good */
540
 
 
541
 
        if (matching)
542
 
          result = g_slist_append (result, (gpointer)contact);
543
 
        else
544
 
          gmcontact_delete (contact);
545
 
      }
546
 
    }
547
 
  }
548
 
  else {
549
 
    max_aid = gm_conf_get_int (CONTACTS_KEY "max_aid");
550
 
    for (aid = 1; aid <= max_aid; aid++) {
551
 
      addb_loop = get_addressbook (aid);
552
 
      if (addb_loop != NULL)
553
 
        result = g_slist_concat (result, gnomemeeting_local_addressbook_get_contacts (addb_loop, nbr, partial_match, fullname, url, categorie, location, speeddial));
554
 
    }
555
 
  }
556
 
 
557
 
  nbr = g_slist_length (result);
558
 
 
559
 
  return result;
560
 
}
561
 
 
562
 
 
563
 
gboolean
564
 
gnomemeeting_local_addressbook_add (GmAddressbook *addb)
565
 
{
566
 
  gint aid = 0;
567
 
  
568
 
  g_return_val_if_fail (addb != NULL, FALSE);
569
 
 
570
 
  aid = get_available_aid ();
571
 
 
572
 
  if (addb->aid) {
573
 
 
574
 
    g_free (addb->aid);
575
 
  }
576
 
  addb->aid = g_strdup_printf ("%d", aid);
577
 
 
578
 
  return store_addressbook (addb);
579
 
}
580
 
 
581
 
 
582
 
gboolean
583
 
gnomemeeting_local_addressbook_delete (GmAddressbook *addb)
584
 
{
585
 
  gint aid = 0;
586
 
  gint max_aid = 0;
587
 
  gchar *namespc = NULL;
588
 
 
589
 
  g_return_val_if_fail (addb != NULL, FALSE);
590
 
 
591
 
  aid = strtol (addb->aid, NULL, 10);
592
 
 
593
 
  g_return_val_if_fail (aid > 0, FALSE);
594
 
 
595
 
  namespc = g_strdup_printf (CONTACTS_KEY "%d", aid);
596
 
  gm_conf_destroy (namespc);
597
 
  g_free (namespc);
598
 
 
599
 
  max_aid = gm_conf_get_int (CONTACTS_KEY "max_aid");
600
 
 
601
 
  if (max_aid == aid) {
602
 
    /* FIXME: bad! Need a proper loop to detect the last really
603
 
     * used aid (another helper function would be nice, I think)
604
 
     */
605
 
    gm_conf_set_int (CONTACTS_KEY "max_aid", aid - 1);
606
 
  }
607
 
 
608
 
  return TRUE;
609
 
}
610
 
 
611
 
 
612
 
gboolean
613
 
gnomemeeting_local_addressbook_modify (GmAddressbook *addb)
614
 
{
615
 
  g_return_val_if_fail (addb != NULL, FALSE);
616
 
 
617
 
  return store_addressbook (addb);
618
 
}
619
 
 
620
 
 
621
 
gboolean
622
 
gnomemeeting_local_addressbook_delete_contact (GmAddressbook *addb,
623
 
                                               GmContact *contact)
624
 
{
625
 
  gint aid = 0;
626
 
  gint uid = 0;
627
 
  gint max_uid = 0;
628
 
  gchar *namespc = NULL;
629
 
  gchar *key = NULL;
630
 
 
631
 
  g_return_val_if_fail (addb != NULL, FALSE);
632
 
  g_return_val_if_fail (contact != NULL, FALSE);
633
 
 
634
 
  aid = strtol (addb->aid, NULL, 10);
635
 
  g_return_val_if_fail (aid > 0, FALSE);
636
 
 
637
 
  uid = strtol (contact->uid, NULL, 10);
638
 
  g_return_val_if_fail (uid > 0, FALSE);
639
 
 
640
 
  namespc = g_strdup_printf (CONTACTS_KEY "%d/%d", aid, uid);
641
 
  gm_conf_destroy (namespc);
642
 
  g_free (namespc);
643
 
 
644
 
  key = g_strdup_printf (CONTACTS_KEY "%d/max_uid", aid);
645
 
  max_uid = gm_conf_get_int (key);
646
 
  g_free (key);
647
 
 
648
 
  if (max_uid == uid) {
649
 
    /* FIXME: bad! Need a proper loop to detect the last really
650
 
     * used uid (another helper function would be nice, I think)
651
 
     */
652
 
    key = g_strdup_printf (CONTACTS_KEY "%d/max_uid", aid);
653
 
    gm_conf_set_int (key, uid - 1);
654
 
    g_free (key);
655
 
  }
656
 
 
657
 
  return TRUE;
658
 
}
659
 
 
660
 
 
661
 
gboolean
662
 
gnomemeeting_local_addressbook_add_contact (GmAddressbook *addb,
663
 
                                            GmContact *contact)
664
 
{
665
 
  gint aid = 0;
666
 
  gint uid = 0;
667
 
 
668
 
  g_return_val_if_fail (addb != NULL, FALSE);
669
 
  g_return_val_if_fail (contact != NULL, FALSE);
670
 
 
671
 
  aid = strtol (addb->aid, NULL, 10);
672
 
  g_return_val_if_fail (aid > 0, FALSE);
673
 
 
674
 
  uid = get_available_uid (aid);
675
 
  contact->uid = g_strdup_printf ("%d", uid);
676
 
 
677
 
  return store_contact (contact, aid);
678
 
}
679
 
 
680
 
 
681
 
gboolean
682
 
gnomemeeting_local_addressbook_modify_contact (GmAddressbook *addb,
683
 
                                               GmContact *contact)
684
 
{
685
 
  gint aid = 0;
686
 
 
687
 
  g_return_val_if_fail (addb != NULL, FALSE);
688
 
  g_return_val_if_fail (contact != NULL, FALSE);
689
 
 
690
 
  aid = strtol (addb->aid, NULL, 10);
691
 
  g_return_val_if_fail (aid > 0, FALSE);
692
 
 
693
 
  return store_contact (contact, aid);
694
 
}
695
 
 
696
 
 
697
 
gboolean 
698
 
gnomemeeting_local_addressbook_is_editable (GmAddressbook *)
699
 
{
700
 
  return TRUE;
701
 
}
702
 
 
703
 
 
704
 
void
705
 
gnomemeeting_local_addressbook_init (gchar *group_name,
706
 
                                     gchar *source_name)
707
 
{
708
 
  GmAddressbook *addb = NULL;
709
 
  
710
 
  GSList *addressbooks = NULL;
711
 
  GSList *addressbooks_iter = NULL;
712
 
  gboolean found = false;
713
 
 
714
 
  addressbooks = gnomemeeting_get_local_addressbooks ();
715
 
  addressbooks_iter = addressbooks;
716
 
  while (addressbooks_iter && !found) {
717
 
 
718
 
    if (addressbooks_iter->data) {
719
 
 
720
 
      addb = GM_ADDRESSBOOK (addressbooks_iter->data);
721
 
      if (addb && addb->name && !strcmp (source_name, addb->name))
722
 
        found = true;
723
 
    }
724
 
    addressbooks_iter = g_slist_next (addressbooks_iter);
725
 
  }
726
 
  g_slist_foreach (addressbooks, (GFunc) gm_addressbook_delete, NULL);
727
 
  g_slist_free (addressbooks);
728
 
 
729
 
  if (found)
730
 
    return;
731
 
 
732
 
  addb = gm_addressbook_new ();
733
 
  addb->name = g_strdup (source_name);
734
 
  gnomemeeting_addressbook_add (addb);
735
 
  gm_addressbook_delete (addb);
736
 
}
737
 
 
738
 
 
739
 
gboolean 
740
 
gnomemeeting_local_addressbook_has_fullname (GmAddressbook *)
741
 
{
742
 
  return TRUE;
743
 
}
744
 
 
745
 
 
746
 
gboolean 
747
 
gnomemeeting_local_addressbook_has_url (GmAddressbook *)
748
 
{
749
 
  return TRUE;
750
 
}
751
 
 
752
 
 
753
 
gboolean 
754
 
gnomemeeting_local_addressbook_has_speeddial (GmAddressbook *)
755
 
{
756
 
  return TRUE;
757
 
}
758
 
 
759
 
 
760
 
gboolean 
761
 
gnomemeeting_local_addressbook_has_categories (GmAddressbook *)
762
 
{
763
 
  return TRUE;
764
 
}
765
 
 
766
 
 
767
 
gboolean 
768
 
gnomemeeting_local_addressbook_has_location (GmAddressbook *)
769
 
{
770
 
  return FALSE;
771
 
}
772
 
 
773
 
 
774
 
gboolean 
775
 
gnomemeeting_local_addressbook_has_comment (GmAddressbook *)
776
 
{
777
 
  return FALSE;
778
 
}
779
 
 
780
 
 
781
 
gboolean 
782
 
gnomemeeting_local_addressbook_has_software (GmAddressbook *)
783
 
{
784
 
  return FALSE;
785
 
}
786
 
 
787
 
 
788
 
gboolean 
789
 
gnomemeeting_local_addressbook_has_email (GmAddressbook *)
790
 
{
791
 
  return TRUE;
792
 
}
793
 
 
794
 
 
795
 
gboolean gnomemeeting_local_addressbook_has_state (GmAddressbook *)
796
 
{
797
 
  return FALSE;
798
 
}
799