2
/* GnomeMeeting -- A Video-Conferencing application
3
* Copyright (C) 2000-2006 Damien Sandras
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.
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.
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.
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.
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..
43
#include <libebook/e-book.h>
49
#include "gmcontacts.h"
51
#ifndef _GM_CONTACTS_H_INSIDE__
52
#define _GM_CONTACTS_H_INSIDE__
53
#include "gmcontacts-local.h"
54
#undef _GM_CONTACTS_H_INSIDE__
59
gnomemeeting_addressbook_get_local_source_group (ESourceList **source_list)
61
ESourceGroup *result = NULL;
63
GSList *source_groups = NULL;
64
GSList *addressbooks = NULL;
70
/* Get the list of possible sources */
71
if (e_book_get_addressbooks (source_list, NULL)) {
73
source_groups = e_source_list_peek_groups (*source_list);
78
addressbooks = e_source_group_peek_sources (E_SOURCE_GROUP (l->data));
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);
102
static EVCardAttributeParam *
103
gm_addressbook_get_contact_speeddial_param (EContact *contact)
105
EVCardAttributeParam *attr_param = NULL;
107
const char *attr_param_name = NULL;
109
GList *attr_list = NULL;
110
GList *attr_list_iter = NULL;
111
GList *attr_param_list = NULL;
112
GList *attr_param_list_iter = NULL;
114
attr_list = e_vcard_get_attributes (E_VCARD (contact));
116
attr_list_iter = attr_list;
117
while (attr_list_iter && !attr_param) {
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) {
125
e_vcard_attribute_param_get_name ((EVCardAttributeParam *) attr_param_list_iter->data);
128
&& !strcmp (attr_param_name, "X-GNOMEMEETING-SPEEDDIAL")) {
130
attr_param = (EVCardAttributeParam *) attr_param_list_iter->data;
133
attr_param_list_iter = g_list_next (attr_param_list_iter);
137
attr_list_iter = g_list_next (attr_list_iter);
146
gm_addressbook_get_contact_speeddial (EContact *contact)
148
EVCardAttributeParam *attr_param = NULL;
150
const char *speeddial = NULL;
151
const char *attr_param_name = NULL;
155
GList *attr_list = NULL;
156
GList *attr_list_iter = NULL;
157
GList *attr_param_list = NULL;
158
GList *attr_param_list_iter = NULL;
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) {
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) {
171
e_vcard_attribute_param_get_name ((EVCardAttributeParam *) attr_param_list_iter->data);
174
&& !strcmp (attr_param_name, "X-GNOMEMEETING-SPEEDDIAL")) {
176
attr_param = (EVCardAttributeParam *) attr_param_list_iter->data;
179
attr_param_list_iter = g_list_next (attr_param_list_iter);
183
attr_list_iter = g_list_next (attr_list_iter);
188
x = e_vcard_attribute_param_get_values (attr_param);
190
speeddial = g_strdup ((char *) x->data);
201
GmContact *contact = NULL;
202
EContact *econtact = NULL;
204
contact = g_new (GmContact, 1);
206
econtact = e_contact_new ();
208
contact->fullname = NULL;
209
contact->categories = NULL;
211
contact->location = NULL;
212
contact->speeddial = NULL;
213
contact->comment = NULL;
214
contact->software = NULL;
215
contact->email = NULL;
217
contact->video_capable = FALSE;
219
g_strdup ((const gchar *) e_contact_get_const (E_CONTACT (econtact),
221
g_object_unref (econtact);
228
gmcontact_delete (GmContact *contact)
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);
247
gm_addressbook_new ()
249
GmAddressbook *addressbook = NULL;
251
ESourceList *list = NULL;
252
ESourceGroup *source_group = NULL;
253
ESource *source = NULL;
255
addressbook = g_new (GmAddressbook, 1);
257
addressbook->name = NULL;
258
addressbook->url = NULL;
259
addressbook->aid = NULL;
260
addressbook->call_attribute = NULL;
262
source = e_source_new ("", "");
263
source_group = gnomemeeting_addressbook_get_local_source_group (&list);
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;
275
g_object_unref (source);
282
gm_addressbook_delete (GmAddressbook *addressbook)
287
g_free (addressbook->url);
288
g_free (addressbook->aid);
289
g_free (addressbook->name);
290
g_free (addressbook->call_attribute);
292
g_free (addressbook);
297
gnomemeeting_get_local_addressbooks ()
299
ESourceList *source_list = NULL;
301
GSList *sources = NULL;
302
GSList *groups = NULL;
303
GSList *addressbooks = NULL;
308
GmAddressbook *elmt = NULL;
313
if (e_book_get_addressbooks (&source_list, NULL)) {
315
sources = e_source_list_peek_groups (source_list);
320
groups = e_source_group_peek_sources (E_SOURCE_GROUP (l->data));
325
aid = (gchar *) e_source_peek_uid (E_SOURCE (j->data));
326
uri = (gchar *) e_source_get_uri (E_SOURCE (j->data));
328
if (g_str_has_prefix (uri, "file:")) {
330
elmt = gm_addressbook_new ();
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);
336
addressbooks = g_slist_append (addressbooks, (gpointer) elmt);
339
j = g_slist_next (j);
345
l = g_slist_next (l);
355
gnomemeeting_local_addressbook_get_contacts (GmAddressbook *addbook,
357
gboolean partial_match,
364
EBookQuery *query = NULL;
365
EBookQuery *queries [4];
367
GmContact *contact = NULL;
368
GmAddressbook *addressbook = NULL;
370
GSList *contacts = NULL;
371
GSList *addressbooks = NULL;
372
GSList *addressbooks_iter = NULL;
380
addressbooks = g_slist_append (addressbooks, (gpointer) addbook);
382
addressbooks = gnomemeeting_get_local_addressbooks ();
384
/* Build the filter */
385
if (fullname && strcmp (fullname, ""))
387
e_book_query_field_test (E_CONTACT_FULL_NAME,
389
E_BOOK_QUERY_CONTAINS
394
if (url && strcmp (url, ""))
396
e_book_query_field_test (E_CONTACT_VIDEO_URL,
398
E_BOOK_QUERY_CONTAINS
402
if (categorie && strcmp (categorie, ""))
404
e_book_query_field_test (E_CONTACT_CATEGORY_LIST,
406
E_BOOK_QUERY_CONTAINS
412
queries [cpt++] = e_book_query_field_exists (E_CONTACT_FULL_NAME);
414
query = e_book_query_or (cpt, queries, TRUE);
416
addressbooks_iter = addressbooks;
417
while (addressbooks_iter) {
419
addressbook = GM_ADDRESSBOOK (addressbooks_iter->data);
420
if ((ebook = e_book_new_from_uri (addressbook->url, NULL))) {
422
if (e_book_open (ebook, FALSE, NULL)) {
424
/* Get the contacts for that fitler */
425
if (e_book_get_contacts (ebook, query, &list, NULL)) {
430
contact = gmcontact_new ();
433
g_strdup ((const gchar *) e_contact_get_const (E_CONTACT (l->data),
436
g_strdup ((const gchar *) e_contact_get_const (E_CONTACT (l->data),
437
E_CONTACT_FULL_NAME));
439
g_strdup ((const gchar *) e_contact_get_const (E_CONTACT (l->data),
440
E_CONTACT_VIDEO_URL));
442
g_strdup ((const gchar *) e_contact_get_const (E_CONTACT (l->data),
444
contact->categories =
445
g_strdup ((const gchar *) e_contact_get_const (E_CONTACT (l->data),
446
E_CONTACT_CATEGORIES));
450
gm_addressbook_get_contact_speeddial (E_CONTACT (l->data));
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
457
&& ((contact->speeddial && strcmp (speeddial, "") &&
458
!strcmp (speeddial, contact->speeddial))
459
|| (!strcmp (speeddial, "*") && contact->speeddial
460
&& strcmp (contact->speeddial, "")))
462
contacts = g_slist_append (contacts, (gpointer) contact);
468
g_list_foreach (list, (GFunc) g_object_unref, NULL);
474
addressbooks_iter = g_slist_next (addressbooks_iter);
478
e_book_query_unref (query);
482
g_slist_foreach (addressbooks, (GFunc) gm_addressbook_delete, NULL);
483
g_slist_free (addressbooks);
487
/* No hidden contacts in a local address book */
488
nbr = g_slist_length (contacts);
495
gnomemeeting_local_addressbook_add (GmAddressbook *addressbook)
497
ESourceList *list = NULL;
498
ESource *source = NULL;
499
ESourceGroup *source_group = NULL;
501
g_return_val_if_fail (addressbook != NULL, FALSE);
503
source_group = gnomemeeting_addressbook_get_local_source_group (&list);
505
source = e_source_new ("", "");
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);
511
if (addressbook->aid) {
513
g_free (addressbook->aid);
515
addressbook->aid = g_strdup (e_source_peek_uid (E_SOURCE (source)));
516
addressbook->url = e_source_get_uri (source);
518
e_source_group_add_source (source_group, source, -1);
520
e_source_list_sync (list, NULL);
527
gnomemeeting_local_addressbook_delete (GmAddressbook *addressbook)
529
ESourceList *list = NULL;
530
ESourceGroup *source_group = NULL;
532
g_return_val_if_fail (addressbook != NULL, FALSE);
534
source_group = gnomemeeting_addressbook_get_local_source_group (&list);
536
if (addressbook->aid) {
538
if (e_source_group_remove_source_by_uid (source_group,
540
if (e_source_list_sync (list, NULL))
549
gnomemeeting_local_addressbook_modify (GmAddressbook *addressbook)
551
ESourceList *list = NULL;
552
ESourceGroup *source_group = NULL;
553
ESource *source = NULL;
555
g_return_val_if_fail (addressbook != NULL, FALSE);
557
source_group = gnomemeeting_addressbook_get_local_source_group (&list);
559
if (addressbook->aid) {
561
source = e_source_group_peek_source_by_uid (source_group, addressbook->aid);
563
if (addressbook->name && strcmp (addressbook->name, "")) {
565
e_source_set_name (source, addressbook->name);
567
if (e_source_list_sync (list, NULL))
577
gnomemeeting_local_addressbook_add_contact (GmAddressbook *addressbook,
580
GError *error = NULL;
583
EContact *contact = NULL;
584
EVCardAttribute *attr = NULL;
585
EVCardAttributeParam *param = NULL;
587
g_return_val_if_fail (ctact != NULL, FALSE);
588
g_return_val_if_fail (addressbook != NULL, FALSE);
590
if ((ebook = e_book_new_from_uri (addressbook->url, NULL))) {
592
if (e_book_open (ebook, FALSE, &error)) {
594
contact = e_contact_new ();
597
e_contact_set (contact, E_CONTACT_UID, ctact->uid);
599
e_contact_set (contact, E_CONTACT_FULL_NAME, ctact->fullname);
601
e_contact_set (contact, E_CONTACT_VIDEO_URL, ctact->url);
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) {
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);
615
if (e_book_add_contact (ebook, contact, NULL)) {
627
gnomemeeting_local_addressbook_delete_contact (GmAddressbook *addressbook,
634
g_return_val_if_fail (contact != NULL, FALSE);
635
g_return_val_if_fail (addressbook != NULL, FALSE);
638
if ((ebook = e_book_new_from_uri (addressbook->url, NULL))) {
640
if (e_book_open (ebook, FALSE, NULL)) {
644
l = g_list_append (l, (gpointer) contact->uid);
645
e_book_remove_contacts (ebook, l, NULL);
657
gnomemeeting_local_addressbook_modify_contact (GmAddressbook *addressbook,
662
EContact *contact = NULL;
663
EVCardAttribute *attr = NULL;
664
EVCardAttributeParam *param = NULL;
666
g_return_val_if_fail (ctact != NULL, FALSE);
667
g_return_val_if_fail (addressbook != NULL, FALSE);
670
if ((ebook = e_book_new_from_uri (addressbook->url, NULL))) {
672
if (e_book_open (ebook, FALSE, NULL)) {
676
e_book_get_contact (ebook, ctact->uid, &contact, NULL);
679
contact = e_contact_new ();
682
e_contact_set (contact, E_CONTACT_FULL_NAME, ctact->fullname);
684
e_contact_set (contact, E_CONTACT_VIDEO_URL, ctact->url);
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) {
691
param = gm_addressbook_get_contact_speeddial_param (contact);
695
e_vcard_attribute_param_remove_values (param);
696
e_vcard_attribute_param_add_value (param, ctact->speeddial);
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);
708
if (e_book_commit_contact (ebook, contact, NULL))
718
gnomemeeting_local_addressbook_is_editable (GmAddressbook *)
725
gnomemeeting_local_addressbook_init (gchar *group_name, gchar *source_name)
727
ESourceGroup *source_group = NULL;
728
ESourceGroup *on_this_computer = NULL;
729
ESourceList *source_list = NULL;
731
ESource *source = NULL;
733
gchar *source_dir = NULL;
735
g_return_if_fail (group_name != NULL && source_name != NULL);
738
gnomemeeting_addressbook_get_local_source_group (&source_list);
742
source_dir = g_strdup_printf ("file://%s/.evolution/addressbook/local",
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 ("", "");
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);
753
e_source_list_sync (source_list, NULL);
760
gnomemeeting_local_addressbook_has_fullname (GmAddressbook *)
767
gnomemeeting_local_addressbook_has_url (GmAddressbook *)
774
gnomemeeting_local_addressbook_has_speeddial (GmAddressbook *)
781
gnomemeeting_local_addressbook_has_categories (GmAddressbook *)
788
gnomemeeting_local_addressbook_has_location (GmAddressbook *)
795
gnomemeeting_local_addressbook_has_comment (GmAddressbook *)
802
gnomemeeting_local_addressbook_has_software (GmAddressbook *)
809
gnomemeeting_local_addressbook_has_email (GmAddressbook *)
815
gboolean gnomemeeting_local_addressbook_has_state (GmAddressbook *)