~noskcaj/ubuntu/trusty/ekiga/ftbfs

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2006-01-28 18:49:20 UTC
  • Revision ID: james.westby@ubuntu.com-20060128184920-v525ihmiv7id40xs
Tags: upstream-1.99.0
ImportĀ upstreamĀ versionĀ 1.99.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
/* GnomeMeeting -- A 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
 
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
18
 *
 
19
 *
 
20
 * GnomeMeting 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 OpenH323 and Pwlib, and distribute the combination, without
 
23
 * applying the requirements of the GNU GPL to the OpenH323 program, as long
 
24
 * as you do follow the requirements of the GNU GPL for all the rest of the
 
25
 * software thus combined.
 
26
 */
 
27
 
 
28
 
 
29
/*
 
30
 *                         gmcontacts-eds.c  -  description 
 
31
 *                         ---------------------------------
 
32
 *   begin                : Mon Apr 12 2004
 
33
 *   copyright            : (C) 2000-2006 by Damien Sandras
 
34
 *   description          : Functions to manage the GM Addressbook using EDS..
 
35
 *
 
36
 */
 
37
 
 
38
 
 
39
#include <string.h>
 
40
 
 
41
extern "C" {
 
42
 
 
43
#include <libebook/e-book.h>
 
44
 
 
45
}
 
46
 
 
47
 
 
48
#include "gmconf.h"
 
49
#include "gmcontacts.h"
 
50
 
 
51
#ifndef _GM_CONTACTS_H_INSIDE__
 
52
#define _GM_CONTACTS_H_INSIDE__
 
53
#include "gmcontacts-local.h"
 
54
#undef _GM_CONTACTS_H_INSIDE__
 
55
#endif
 
56
 
 
57
 
 
58
static ESourceGroup *
 
59
gnomemeeting_addressbook_get_local_source_group (ESourceList **source_list)
 
60
{
 
61
  ESourceGroup *result = NULL;
 
62
  
 
63
  GSList *source_groups = NULL;
 
64
  GSList *addressbooks = NULL;
 
65
  GSList *l = NULL;
 
66
  GSList *j = NULL;
 
67
 
 
68
  gchar *uri = NULL;
 
69
  
 
70
  /* Get the list of possible sources */
 
71
  if (e_book_get_addressbooks (source_list, NULL)) {
 
72
 
 
73
    source_groups = e_source_list_peek_groups (*source_list);
 
74
 
 
75
    l = source_groups;
 
76
    while (l) {
 
77
 
 
78
      addressbooks = e_source_group_peek_sources (E_SOURCE_GROUP (l->data));
 
79
    
 
80
      j = addressbooks;
 
81
      while (j) {
 
82
 
 
83
 
 
84
        uri = e_source_get_uri (E_SOURCE (j->data));
 
85
        if (g_str_has_prefix (uri, "file:"))
 
86
          result = E_SOURCE_GROUP (l->data);
 
87
        g_free (uri);
 
88
 
 
89
        j = g_slist_next (j);
 
90
      }
 
91
 
 
92
 
 
93
      l = g_slist_next (l);
 
94
    }
 
95
 
 
96
  }
 
97
  
 
98
  return result;
 
99
}
 
100
 
 
101
 
 
102
static EVCardAttributeParam *
 
103
gm_addressbook_get_contact_speeddial_param (EContact *contact)
 
104
{
 
105
  EVCardAttributeParam *attr_param = NULL;
 
106
 
 
107
  const char *attr_param_name = NULL;
 
108
  
 
109
  GList *attr_list = NULL;
 
110
  GList *attr_list_iter = NULL;
 
111
  GList *attr_param_list = NULL;
 
112
  GList *attr_param_list_iter = NULL;
 
113
 
 
114
  attr_list = e_vcard_get_attributes (E_VCARD (contact));
 
115
 
 
116
  attr_list_iter = attr_list;
 
117
  while (attr_list_iter && !attr_param) {
 
118
 
 
119
    attr_param_list = 
 
120
      e_vcard_attribute_get_params ((EVCardAttribute *) attr_list_iter->data);
 
121
    attr_param_list_iter = attr_param_list;
 
122
    while (attr_param_list_iter && !attr_param) {
 
123
 
 
124
      attr_param_name = 
 
125
        e_vcard_attribute_param_get_name ((EVCardAttributeParam *) attr_param_list_iter->data);
 
126
      
 
127
      if (attr_param_name 
 
128
          && !strcmp (attr_param_name, "X-GNOMEMEETING-SPEEDDIAL")) {
 
129
 
 
130
        attr_param = (EVCardAttributeParam *) attr_param_list_iter->data;
 
131
      }
 
132
 
 
133
      attr_param_list_iter = g_list_next (attr_param_list_iter);
 
134
    }
 
135
 
 
136
 
 
137
    attr_list_iter = g_list_next (attr_list_iter);
 
138
  }
 
139
 
 
140
  
 
141
  return attr_param;
 
142
}
 
143
 
 
144
 
 
145
static const char *
 
146
gm_addressbook_get_contact_speeddial (EContact *contact)
 
147
{
 
148
  EVCardAttributeParam *attr_param = NULL;
 
149
 
 
150
  const char *speeddial = NULL;
 
151
  const char *attr_param_name = NULL;
 
152
  
 
153
  GList *x = NULL;
 
154
 
 
155
  GList *attr_list = NULL;
 
156
  GList *attr_list_iter = NULL;
 
157
  GList *attr_param_list = NULL;
 
158
  GList *attr_param_list_iter = NULL;
 
159
 
 
160
  attr_list = e_contact_get_attributes (E_CONTACT (contact),
 
161
                                        E_CONTACT_PHONE_TELEX);
 
162
  attr_list_iter = attr_list;
 
163
  while (attr_list_iter && !attr_param) {
 
164
 
 
165
    attr_param_list = 
 
166
      e_vcard_attribute_get_params ((EVCardAttribute *) attr_list_iter->data);
 
167
    attr_param_list_iter = attr_param_list;
 
168
    while (attr_param_list_iter && !attr_param) {
 
169
 
 
170
      attr_param_name = 
 
171
        e_vcard_attribute_param_get_name ((EVCardAttributeParam *) attr_param_list_iter->data);
 
172
      
 
173
      if (attr_param_name 
 
174
          && !strcmp (attr_param_name, "X-GNOMEMEETING-SPEEDDIAL")) {
 
175
 
 
176
        attr_param = (EVCardAttributeParam *) attr_param_list_iter->data;
 
177
      }
 
178
 
 
179
      attr_param_list_iter = g_list_next (attr_param_list_iter);
 
180
    }
 
181
 
 
182
 
 
183
    attr_list_iter = g_list_next (attr_list_iter);
 
184
  }
 
185
 
 
186
  if (attr_param) {
 
187
 
 
188
    x = e_vcard_attribute_param_get_values (attr_param);
 
189
    if (x && x->data)
 
190
      speeddial = g_strdup ((char *) x->data);
 
191
 
 
192
  }
 
193
  
 
194
  return speeddial;
 
195
}
 
196
 
 
197
 
 
198
GmContact *
 
199
gmcontact_new ()
 
200
{
 
201
  GmContact *contact = NULL;
 
202
  EContact *econtact = NULL;
 
203
 
 
204
  contact = g_new (GmContact, 1);
 
205
 
 
206
  econtact = e_contact_new ();
 
207
 
 
208
  contact->fullname = NULL;
 
209
  contact->categories = NULL;
 
210
  contact->url = NULL;
 
211
  contact->location = NULL;
 
212
  contact->speeddial = NULL;
 
213
  contact->comment = NULL;
 
214
  contact->software = NULL;
 
215
  contact->email = NULL;
 
216
  contact->state = 0;
 
217
  contact->video_capable = FALSE;
 
218
  contact->uid =  
 
219
    g_strdup ((const gchar *) e_contact_get_const (E_CONTACT (econtact), 
 
220
                                                   E_CONTACT_UID));
 
221
  g_object_unref (econtact);
 
222
 
 
223
  return contact;
 
224
}
 
225
 
 
226
 
 
227
void
 
228
gmcontact_delete (GmContact *contact)
 
229
{
 
230
  if (!contact)
 
231
    return;
 
232
 
 
233
  g_free (contact->uid);
 
234
  g_free (contact->fullname);
 
235
  g_free (contact->url);
 
236
  g_free (contact->speeddial);
 
237
  g_free (contact->categories);
 
238
  g_free (contact->comment);
 
239
  g_free (contact->software);
 
240
  g_free (contact->email);
 
241
 
 
242
  g_free (contact);
 
243
}
 
244
 
 
245
 
 
246
GmAddressbook *
 
247
gm_addressbook_new ()
 
248
{
 
249
  GmAddressbook *addressbook = NULL;
 
250
 
 
251
  ESourceList *list = NULL;
 
252
  ESourceGroup *source_group = NULL;
 
253
  ESource *source = NULL;
 
254
 
 
255
  addressbook = g_new (GmAddressbook, 1);
 
256
  
 
257
  addressbook->name = NULL;
 
258
  addressbook->url = NULL; 
 
259
  addressbook->aid = NULL;
 
260
  addressbook->call_attribute = NULL;
 
261
 
 
262
  source = e_source_new ("", "");
 
263
  source_group = gnomemeeting_addressbook_get_local_source_group (&list);
 
264
 
 
265
  if (source_group) {
 
266
  
 
267
    e_source_set_relative_uri (source, e_source_peek_uid (source));
 
268
    e_source_set_group (source, source_group);
 
269
    addressbook->name = NULL;
 
270
    addressbook->url = e_source_get_uri (source); 
 
271
    addressbook->aid = g_strdup (e_source_peek_uid (source));
 
272
    addressbook->call_attribute = NULL;
 
273
  }
 
274
 
 
275
  g_object_unref (source);
 
276
 
 
277
  return addressbook;
 
278
}
 
279
 
 
280
 
 
281
void 
 
282
gm_addressbook_delete (GmAddressbook *addressbook)
 
283
{
 
284
  if (!addressbook)
 
285
    return;
 
286
 
 
287
  g_free (addressbook->url);
 
288
  g_free (addressbook->aid);
 
289
  g_free (addressbook->name);
 
290
  g_free (addressbook->call_attribute);
 
291
 
 
292
  g_free (addressbook);  
 
293
}
 
294
 
 
295
 
 
296
GSList *
 
297
gnomemeeting_get_local_addressbooks ()
 
298
{
 
299
  ESourceList *source_list = NULL;
 
300
 
 
301
  GSList *sources = NULL;
 
302
  GSList *groups = NULL;
 
303
  GSList *addressbooks = NULL;
 
304
 
 
305
  GSList *l = NULL;
 
306
  GSList *j = NULL;
 
307
 
 
308
  GmAddressbook *elmt = NULL;
 
309
 
 
310
  gchar *uri = NULL;
 
311
  gchar *aid = NULL;
 
312
 
 
313
  if (e_book_get_addressbooks (&source_list, NULL)) {
 
314
 
 
315
    sources = e_source_list_peek_groups (source_list);
 
316
    l = sources;
 
317
 
 
318
    while (l) {
 
319
 
 
320
      groups = e_source_group_peek_sources (E_SOURCE_GROUP (l->data));
 
321
 
 
322
      j = groups;
 
323
      while (j) {
 
324
 
 
325
        aid = (gchar *) e_source_peek_uid (E_SOURCE (j->data));
 
326
        uri = (gchar *) e_source_get_uri (E_SOURCE (j->data));
 
327
 
 
328
        if (g_str_has_prefix (uri, "file:")) {
 
329
 
 
330
          elmt = gm_addressbook_new ();
 
331
 
 
332
          elmt->name = g_strdup (e_source_peek_name (E_SOURCE (j->data)));
 
333
          elmt->aid = g_strdup (aid); 
 
334
          elmt->url = g_strdup (uri); 
 
335
 
 
336
          addressbooks = g_slist_append (addressbooks, (gpointer) elmt);
 
337
 
 
338
        }
 
339
        j = g_slist_next (j);
 
340
 
 
341
        g_free (uri);
 
342
        g_free (aid);
 
343
      }
 
344
 
 
345
      l = g_slist_next (l);
 
346
    }
 
347
 
 
348
  }
 
349
 
 
350
  return addressbooks;
 
351
}
 
352
 
 
353
 
 
354
GSList *
 
355
gnomemeeting_local_addressbook_get_contacts (GmAddressbook *addbook,
 
356
                                             int & nbr,
 
357
                                             gboolean partial_match,
 
358
                                             gchar *fullname,
 
359
                                             gchar *url,
 
360
                                             gchar *categorie,
 
361
                                             gchar *speeddial)
 
362
{
 
363
  EBook *ebook = NULL;
 
364
  EBookQuery *query = NULL;
 
365
  EBookQuery *queries [4];
 
366
  
 
367
  GmContact *contact = NULL;
 
368
  GmAddressbook *addressbook = NULL;
 
369
 
 
370
  GSList *contacts = NULL;
 
371
  GSList *addressbooks = NULL;
 
372
  GSList *addressbooks_iter = NULL;
 
373
  
 
374
  GList *list = NULL;
 
375
  GList *l = NULL;
 
376
 
 
377
  gint cpt = 0;
 
378
  
 
379
  if (addbook) 
 
380
    addressbooks = g_slist_append (addressbooks, (gpointer) addbook);
 
381
  else
 
382
    addressbooks = gnomemeeting_get_local_addressbooks ();
 
383
 
 
384
  /* Build the filter */ 
 
385
  if (fullname && strcmp (fullname, "")) 
 
386
    queries [cpt++] = 
 
387
      e_book_query_field_test (E_CONTACT_FULL_NAME,
 
388
                               partial_match?
 
389
                               E_BOOK_QUERY_CONTAINS
 
390
                               :
 
391
                               E_BOOK_QUERY_IS,
 
392
                               fullname);
 
393
 
 
394
  if (url && strcmp (url, "")) 
 
395
    queries [cpt++] = 
 
396
      e_book_query_field_test (E_CONTACT_VIDEO_URL,
 
397
                               partial_match?
 
398
                               E_BOOK_QUERY_CONTAINS
 
399
                               :
 
400
                               E_BOOK_QUERY_IS,
 
401
                               url);
 
402
  if (categorie && strcmp (categorie, ""))
 
403
    queries [cpt++] = 
 
404
      e_book_query_field_test (E_CONTACT_CATEGORY_LIST,
 
405
                               partial_match?
 
406
                               E_BOOK_QUERY_CONTAINS
 
407
                               :
 
408
                               E_BOOK_QUERY_IS,
 
409
                               categorie);
 
410
 
 
411
  if (cpt == 0)
 
412
    queries [cpt++] = e_book_query_field_exists (E_CONTACT_FULL_NAME);
 
413
 
 
414
  query = e_book_query_or (cpt, queries, TRUE);
 
415
 
 
416
  addressbooks_iter = addressbooks;
 
417
  while (addressbooks_iter) {
 
418
 
 
419
    addressbook = GM_ADDRESSBOOK (addressbooks_iter->data);
 
420
    if ((ebook = e_book_new_from_uri (addressbook->url, NULL))) {
 
421
 
 
422
      if (e_book_open (ebook, FALSE, NULL)) {
 
423
        
 
424
        /* Get the contacts for that fitler */
 
425
        if (e_book_get_contacts (ebook, query, &list, NULL)) {
 
426
 
 
427
          l = list;
 
428
          while (l) {
 
429
 
 
430
            contact = gmcontact_new ();
 
431
 
 
432
            contact->uid =  
 
433
              g_strdup ((const gchar *) e_contact_get_const (E_CONTACT (l->data), 
 
434
                                                             E_CONTACT_UID));
 
435
            contact->fullname =  
 
436
              g_strdup ((const gchar *) e_contact_get_const (E_CONTACT (l->data), 
 
437
                                                             E_CONTACT_FULL_NAME));
 
438
            contact->url =  
 
439
              g_strdup ((const gchar *) e_contact_get_const (E_CONTACT (l->data), 
 
440
                                                             E_CONTACT_VIDEO_URL));
 
441
            contact->email =  
 
442
              g_strdup ((const gchar *) e_contact_get_const (E_CONTACT (l->data), 
 
443
                                                             E_CONTACT_EMAIL_1));
 
444
            contact->categories =  
 
445
              g_strdup ((const gchar *) e_contact_get_const (E_CONTACT (l->data), 
 
446
                                                             E_CONTACT_CATEGORIES));      
 
447
 
 
448
            contact->speeddial = 
 
449
              (gchar *) 
 
450
              gm_addressbook_get_contact_speeddial (E_CONTACT (l->data));
 
451
 
 
452
 
 
453
            /* If it is a search on a speed dial, then we only add
 
454
             * the contact to the list if it has the correct speed dial
 
455
             */
 
456
            if ((speeddial 
 
457
                 && ((contact->speeddial && strcmp (speeddial, "") && 
 
458
                      !strcmp (speeddial, contact->speeddial)) 
 
459
                     || (!strcmp (speeddial, "*") && contact->speeddial
 
460
                         && strcmp (contact->speeddial, "")))
 
461
                 || !speeddial))
 
462
              contacts = g_slist_append (contacts, (gpointer) contact);
 
463
 
 
464
            l = g_list_next (l);
 
465
          }
 
466
 
 
467
 
 
468
          g_list_foreach (list, (GFunc) g_object_unref, NULL);
 
469
          g_list_free (list);
 
470
        }
 
471
      }
 
472
    }
 
473
    
 
474
    addressbooks_iter = g_slist_next (addressbooks_iter);
 
475
  }
 
476
  
 
477
  
 
478
  e_book_query_unref (query);
 
479
 
 
480
  if (!addbook) {
 
481
    
 
482
    g_slist_foreach (addressbooks, (GFunc) gm_addressbook_delete, NULL);
 
483
    g_slist_free (addressbooks);
 
484
  }
 
485
  
 
486
 
 
487
  /* No hidden contacts in a local address book */
 
488
  nbr = g_slist_length (contacts);
 
489
  
 
490
  return contacts;
 
491
}
 
492
 
 
493
 
 
494
gboolean 
 
495
gnomemeeting_local_addressbook_add (GmAddressbook *addressbook)
 
496
{
 
497
  ESourceList *list = NULL;
 
498
  ESource *source = NULL;
 
499
  ESourceGroup *source_group = NULL;
 
500
 
 
501
  g_return_val_if_fail (addressbook != NULL, FALSE);
 
502
 
 
503
  source_group = gnomemeeting_addressbook_get_local_source_group (&list);
 
504
  
 
505
  source = e_source_new ("", "");
 
506
 
 
507
  e_source_set_name (source, addressbook->name);
 
508
  e_source_set_relative_uri (source, e_source_peek_uid (source));
 
509
  e_source_set_group (source, source_group);
 
510
 
 
511
  if (addressbook->aid) {
 
512
    
 
513
    g_free (addressbook->aid);
 
514
  }
 
515
  addressbook->aid = g_strdup (e_source_peek_uid (E_SOURCE (source)));
 
516
  addressbook->url = e_source_get_uri (source);
 
517
 
 
518
  e_source_group_add_source (source_group, source, -1); 
 
519
 
 
520
  e_source_list_sync (list, NULL);
 
521
 
 
522
  return TRUE;
 
523
}
 
524
 
 
525
 
 
526
gboolean 
 
527
gnomemeeting_local_addressbook_delete (GmAddressbook *addressbook)
 
528
{
 
529
  ESourceList *list = NULL;
 
530
  ESourceGroup *source_group = NULL;
 
531
 
 
532
  g_return_val_if_fail (addressbook != NULL, FALSE);
 
533
 
 
534
  source_group = gnomemeeting_addressbook_get_local_source_group (&list);
 
535
 
 
536
  if (addressbook->aid) {
 
537
    
 
538
    if (e_source_group_remove_source_by_uid (source_group, 
 
539
                                             addressbook->aid)) 
 
540
      if (e_source_list_sync (list, NULL))
 
541
        return TRUE;
 
542
  }
 
543
  
 
544
  return FALSE;
 
545
}
 
546
 
 
547
 
 
548
gboolean
 
549
gnomemeeting_local_addressbook_modify (GmAddressbook *addressbook)
 
550
{
 
551
  ESourceList *list = NULL;
 
552
  ESourceGroup *source_group = NULL;
 
553
  ESource *source = NULL;
 
554
 
 
555
  g_return_val_if_fail (addressbook != NULL, FALSE);
 
556
 
 
557
  source_group = gnomemeeting_addressbook_get_local_source_group (&list);
 
558
 
 
559
  if (addressbook->aid) {
 
560
    
 
561
    source = e_source_group_peek_source_by_uid (source_group, addressbook->aid);
 
562
 
 
563
    if (addressbook->name && strcmp (addressbook->name, "")) {
 
564
      
 
565
      e_source_set_name (source, addressbook->name);
 
566
 
 
567
      if (e_source_list_sync (list, NULL))
 
568
        return TRUE;
 
569
    }
 
570
  }
 
571
  
 
572
  return FALSE;
 
573
}
 
574
 
 
575
 
 
576
gboolean
 
577
gnomemeeting_local_addressbook_add_contact (GmAddressbook *addressbook,
 
578
                                            GmContact *ctact)
 
579
{
 
580
  GError *error = NULL;
 
581
  EBook *ebook = NULL;
 
582
 
 
583
  EContact *contact = NULL;
 
584
  EVCardAttribute *attr = NULL;
 
585
  EVCardAttributeParam *param = NULL;
 
586
 
 
587
  g_return_val_if_fail (ctact != NULL, FALSE);
 
588
  g_return_val_if_fail (addressbook != NULL, FALSE);
 
589
 
 
590
  if ((ebook = e_book_new_from_uri (addressbook->url, NULL))) {
 
591
 
 
592
    if (e_book_open (ebook, FALSE, &error)) {
 
593
 
 
594
      contact = e_contact_new ();
 
595
 
 
596
      if (ctact->uid)
 
597
        e_contact_set (contact, E_CONTACT_UID, ctact->uid);
 
598
      if (ctact->fullname)
 
599
        e_contact_set (contact, E_CONTACT_FULL_NAME, ctact->fullname);
 
600
      if (ctact->url)
 
601
        e_contact_set (contact, E_CONTACT_VIDEO_URL, ctact->url);
 
602
      if (ctact->email)
 
603
        e_contact_set (contact, E_CONTACT_EMAIL_1, ctact->email);
 
604
      if (ctact->categories)
 
605
        e_contact_set (contact, E_CONTACT_CATEGORIES, ctact->categories);
 
606
      if (ctact->speeddial) {
 
607
 
 
608
        attr = e_vcard_attribute_new (NULL, "TEL");
 
609
        param = e_vcard_attribute_param_new ("X-GNOMEMEETING-SPEEDDIAL");
 
610
        e_vcard_attribute_add_param_with_value (attr, 
 
611
                                                param, ctact->speeddial);
 
612
        e_vcard_add_attribute (E_VCARD (contact), attr);
 
613
      }
 
614
 
 
615
      if (e_book_add_contact (ebook, contact, NULL)) {
 
616
 
 
617
        return TRUE;
 
618
      }
 
619
    }
 
620
  }
 
621
 
 
622
  return FALSE;
 
623
}
 
624
 
 
625
 
 
626
gboolean 
 
627
gnomemeeting_local_addressbook_delete_contact (GmAddressbook *addressbook,
 
628
                                               GmContact *contact)
 
629
{
 
630
  GList *l = NULL;
 
631
 
 
632
  EBook *ebook = NULL;
 
633
 
 
634
  g_return_val_if_fail (contact != NULL, FALSE);
 
635
  g_return_val_if_fail (addressbook != NULL, FALSE);
 
636
 
 
637
 
 
638
  if ((ebook = e_book_new_from_uri (addressbook->url, NULL))) {
 
639
 
 
640
    if (e_book_open (ebook, FALSE, NULL)) {
 
641
 
 
642
      if (contact->uid) {
 
643
 
 
644
        l = g_list_append (l, (gpointer) contact->uid);
 
645
        e_book_remove_contacts (ebook, l, NULL);
 
646
        g_list_free (l);
 
647
      }
 
648
    }
 
649
  }
 
650
 
 
651
 
 
652
  return TRUE;
 
653
};
 
654
 
 
655
 
 
656
gboolean
 
657
gnomemeeting_local_addressbook_modify_contact (GmAddressbook *addressbook,
 
658
                                               GmContact *ctact)
 
659
{
 
660
  EBook *ebook = NULL;
 
661
 
 
662
  EContact *contact = NULL;
 
663
  EVCardAttribute *attr = NULL;
 
664
  EVCardAttributeParam *param = NULL;
 
665
 
 
666
  g_return_val_if_fail (ctact != NULL, FALSE);
 
667
  g_return_val_if_fail (addressbook != NULL, FALSE);
 
668
 
 
669
 
 
670
  if ((ebook = e_book_new_from_uri (addressbook->url, NULL))) {
 
671
 
 
672
      if (e_book_open (ebook, FALSE, NULL)) {
 
673
 
 
674
 
 
675
        if (ctact->uid) 
 
676
          e_book_get_contact (ebook, ctact->uid, &contact, NULL);
 
677
 
 
678
        if (!contact)
 
679
          contact = e_contact_new ();
 
680
        
 
681
        if (ctact->fullname)
 
682
          e_contact_set (contact, E_CONTACT_FULL_NAME, ctact->fullname);
 
683
        if (ctact->url)
 
684
          e_contact_set (contact, E_CONTACT_VIDEO_URL, ctact->url);
 
685
        if (ctact->email)
 
686
          e_contact_set (contact, E_CONTACT_EMAIL_1, ctact->email);
 
687
        if (ctact->categories)
 
688
          e_contact_set (contact, E_CONTACT_CATEGORIES, ctact->categories);
 
689
        if (ctact->speeddial) {
 
690
 
 
691
          param = gm_addressbook_get_contact_speeddial_param (contact);
 
692
 
 
693
          if (param) {
 
694
 
 
695
            e_vcard_attribute_param_remove_values (param);
 
696
            e_vcard_attribute_param_add_value (param, ctact->speeddial);
 
697
          }
 
698
          else {
 
699
 
 
700
            attr = e_vcard_attribute_new (NULL, "TEL");
 
701
            param = e_vcard_attribute_param_new ("X-GNOMEMEETING-SPEEDDIAL");
 
702
            e_vcard_attribute_add_param_with_value (attr, 
 
703
                                                    param, ctact->speeddial);
 
704
            e_vcard_add_attribute (E_VCARD (contact), attr);
 
705
          }
 
706
        }
 
707
 
 
708
        if (e_book_commit_contact (ebook, contact, NULL))
 
709
          return TRUE;
 
710
      }
 
711
  }
 
712
  
 
713
  return FALSE;
 
714
}
 
715
 
 
716
 
 
717
gboolean 
 
718
gnomemeeting_local_addressbook_is_editable (GmAddressbook *)
 
719
{
 
720
  return TRUE;
 
721
}
 
722
 
 
723
 
 
724
void
 
725
gnomemeeting_local_addressbook_init (gchar *group_name, gchar *source_name)
 
726
{
 
727
  ESourceGroup *source_group = NULL;
 
728
  ESourceGroup *on_this_computer = NULL;
 
729
  ESourceList *source_list = NULL;
 
730
  
 
731
  ESource *source = NULL;
 
732
 
 
733
  gchar *source_dir = NULL;
 
734
 
 
735
  g_return_if_fail (group_name != NULL && source_name != NULL);
 
736
  
 
737
  source_group =
 
738
    gnomemeeting_addressbook_get_local_source_group (&source_list);
 
739
 
 
740
  if (!source_group) {
 
741
    
 
742
    source_dir = g_strdup_printf ("file://%s/.evolution/addressbook/local", 
 
743
                                  g_get_home_dir ());
 
744
    on_this_computer = e_source_group_new (group_name, source_dir);
 
745
    e_source_list_add_group (source_list, on_this_computer, -1);
 
746
    source = e_source_new ("", "");
 
747
 
 
748
    e_source_set_name (source, source_name);
 
749
    e_source_set_relative_uri (source, "system");
 
750
    e_source_set_group (source, on_this_computer);
 
751
    e_source_group_add_source (on_this_computer, source, -1); 
 
752
 
 
753
    e_source_list_sync (source_list, NULL);
 
754
    g_free (source_dir);
 
755
  }
 
756
}
 
757
 
 
758
 
 
759
gboolean 
 
760
gnomemeeting_local_addressbook_has_fullname (GmAddressbook *)
 
761
{
 
762
  return TRUE;
 
763
}
 
764
 
 
765
 
 
766
gboolean 
 
767
gnomemeeting_local_addressbook_has_url (GmAddressbook *)
 
768
{
 
769
  return TRUE;
 
770
}
 
771
 
 
772
 
 
773
gboolean 
 
774
gnomemeeting_local_addressbook_has_speeddial (GmAddressbook *)
 
775
{
 
776
  return TRUE;
 
777
}
 
778
 
 
779
 
 
780
gboolean 
 
781
gnomemeeting_local_addressbook_has_categories (GmAddressbook *)
 
782
{
 
783
  return TRUE;
 
784
}
 
785
 
 
786
 
 
787
gboolean 
 
788
gnomemeeting_local_addressbook_has_location (GmAddressbook *)
 
789
{
 
790
  return FALSE;
 
791
}
 
792
 
 
793
 
 
794
gboolean 
 
795
gnomemeeting_local_addressbook_has_comment (GmAddressbook *)
 
796
{
 
797
  return FALSE;
 
798
}
 
799
 
 
800
 
 
801
gboolean 
 
802
gnomemeeting_local_addressbook_has_software (GmAddressbook *)
 
803
{
 
804
  return FALSE;
 
805
}
 
806
 
 
807
 
 
808
gboolean 
 
809
gnomemeeting_local_addressbook_has_email (GmAddressbook *)
 
810
{
 
811
  return TRUE;
 
812
}
 
813
 
 
814
 
 
815
gboolean gnomemeeting_local_addressbook_has_state (GmAddressbook *)
 
816
{
 
817
  return FALSE;
 
818
}
 
819