1 #include <libebook/libebook.h>
5 void dump_as_vcard(EContact *contact, int dump_all)
10 printf("BEGIN:VCARD\n");
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);
16 const char *attr_name = e_vcard_attribute_get_name(attr);
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
31 if (e_vcard_attribute_is_single_valued(attr)) {
32 char *av = e_vcard_attribute_get_value(attr);
37 GList *vals = e_vcard_attribute_get_values(attr);
39 for (j = 0; j < g_list_length(vals); j++) {
40 const char *av = *(char**) g_list_nth(vals, j);
42 printf("%s: %s\n", attr_name, av);
46 printf("END:VCARD\n");
49 static gchar **search_filter = NULL;
51 static GOptionEntry entries[] =
53 { G_OPTION_REMAINING, 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_STRING_ARRAY, &search_filter, NULL, NULL},
57 int main(int argc, char **argv)
60 ESourceRegistry *eds_source_registry = NULL;
69 GOptionContext *optioncontext;
71 setlocale (LC_ALL, "");
73 optioncontext = g_option_context_new ("- whack address book");
74 g_option_context_add_main_entries (optioncontext, entries, NULL);
75 g_option_context_parse (optioncontext, &argc, &argv, &error);
78 fprintf(stderr, "%s\n", error->message);
82 eds_source_registry = e_source_registry_new_sync (NULL, &error);
84 fprintf(stderr, "%s\n", error->message);
88 sources = e_source_registry_list_sources (eds_source_registry, E_SOURCE_EXTENSION_ADDRESS_BOOK);
90 if (search_filter != NULL) {
91 query = e_book_query_any_field_contains(*search_filter);
93 query = e_book_query_field_exists(E_CONTACT_FULL_NAME);
96 for (s = sources ; s; s = s->next) {
97 source = E_SOURCE(s->data);
98 client = E_BOOK_CLIENT(e_book_client_connect_sync(source, NULL, &error));
101 fprintf(stderr, "e_book_client_connect_sync: %s\n", error->message);
107 /* XXX: leaks the query, but we're short running so doesn't really matter */
108 e_book_client_get_contacts_sync(client, e_book_query_to_string(query), &contacts, NULL, &error);
110 fprintf(stderr, "%s\n", error->message);
114 for (c = contacts; c; c = c->next) {
115 dump_as_vcard(E_CONTACT(c->data), 1);
118 e_book_query_unref(query);
119 g_list_free_full(sources, g_object_unref);