]> err.no Git - eweouz/blob - src/dump-addressbook.c
Get rid of obsolete debug code
[eweouz] / src / dump-addressbook.c
1 #include <libebook/e-book.h>
2 #include <libedataserver/e-source-group.h>
3 #include <gconf/gconf.h>
4 #include <glib.h>
5
6 void dump_as_vcard(EContact *contact, int dump_all)
7 {
8         GList *attrs;
9         int i;
10
11         attrs = e_vcard_get_attributes(&contact->parent);
12         for (i = 0; i < g_list_length(attrs); i++) {
13                 EVCardAttribute *attr = (EVCardAttribute *) 
14                         g_list_nth_data(attrs, i);
15                 int j;
16                 char *attr_name = e_vcard_attribute_get_name(attr);
17
18                 if (!dump_all && 
19                     strcmp(attr_name, "TEL") != 0 &&
20                     strcmp(attr_name, "FN") != 0 &&
21                     strcmp(attr_name, "BDAY") != 0 &&
22                     strcmp(attr_name, "ORG") != 0 &&
23                     strcmp(attr_name, "TEL") != 0 &&
24                     strcmp(attr_name, "EMAIL") != 0 &&
25                     strcmp(attr_name, "NOTE") != 0 &&
26                     strcmp(attr_name, "NICKNAME") != 0
27                         ) {
28                         continue;
29                 }
30
31                 if (strcmp(attr_name, "N") == 0 ||
32                     strcmp(attr_name, "ADR") == 0) {
33                         continue;
34                 }
35
36                 if (e_vcard_attribute_is_single_valued(attr)) {
37                         char *av = e_vcard_attribute_get_value(attr);
38                         printf("%s: %s\n", 
39                                attr_name,
40                                av);
41                 } else {
42                         GList *vals = e_vcard_attribute_get_values(attr);
43
44                         for (j = 0; j < g_list_length(vals); j++) {
45                                 char *av = g_list_nth(vals, j);
46
47                                 printf("%s: %s\n", 
48                                        attr_name,
49                                        av);
50                         }
51                 }
52         }
53 }
54
55 int main(int argc, char **argv)
56 {
57         EBook *book;
58         ESourceList *source_list;
59         ESourceGroup *group;
60         ESource *source;
61         GSList *groups;
62         EBookQuery *query;
63         GList *contacts;
64         GSList *sources;
65         GSList *g, *s;
66         GList *c;
67         GError *error = NULL;
68
69         printf("%d\n", e_book_get_addressbooks(&source_list, &error));
70
71         if (error != NULL) {
72                 fprintf(stderr, "%s\n", error->message);
73         }
74
75         groups = e_source_list_peek_groups(source_list);
76         for (g = groups; g; g = g->next) {
77
78                 group = E_SOURCE_GROUP (g->data);
79                 sources = e_source_group_peek_sources(group);
80
81                 for (s = sources ; s; s = s->next) {
82                         source = E_SOURCE(s->data);
83                         book = e_book_new(source, &error);
84                         e_book_open(book, TRUE, &error);
85
86                         //      query = e_book_query_any_field_contains("");
87                         query = e_book_query_field_exists(E_CONTACT_FULL_NAME);
88                         e_book_get_contacts(book, query, &contacts, &error);
89
90                         for (c = contacts; c; c = c->next) {
91                                 dump_as_vcard(E_CONTACT(c->data), 1);
92                         }
93                 }
94         }
95 }