1 /* Copyright (c) 2008-2013 Tollef Fog Heen <tfheen@err.no>
3 eweouz is free software; you can redistribute it and/or modify it
4 under the terms of the GNU General Public License version 2 as
5 published by the Free Software Foundation.
7 eweouz is distributed in the hope that it will be useful, but
8 WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 General Public License for more details.
12 You should have received a copy of the GNU General Public License
13 along with this program; if not, write to the Free Software
14 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 #include <libebook/libebook.h>
22 void dump_as_vcard(EContact *contact, int dump_all)
27 printf("BEGIN:VCARD\n");
28 attrs = e_vcard_get_attributes(&contact->parent);
29 for (i = 0; i < g_list_length(attrs); i++) {
30 EVCardAttribute *attr = (EVCardAttribute *)
31 g_list_nth_data(attrs, i);
33 const char *attr_name = e_vcard_attribute_get_name(attr);
36 strcmp(attr_name, "TEL") != 0 &&
37 strcmp(attr_name, "FN") != 0 &&
38 strcmp(attr_name, "BDAY") != 0 &&
39 strcmp(attr_name, "ORG") != 0 &&
40 strcmp(attr_name, "TEL") != 0 &&
41 strcmp(attr_name, "EMAIL") != 0 &&
42 strcmp(attr_name, "NOTE") != 0 &&
43 strcmp(attr_name, "NICKNAME") != 0
48 if (e_vcard_attribute_is_single_valued(attr)) {
49 char *av = e_vcard_attribute_get_value(attr);
54 GList *vals = e_vcard_attribute_get_values(attr);
56 for (j = 0; j < g_list_length(vals); j++) {
57 const char *av = *(char**) g_list_nth(vals, j);
59 printf("%s: %s\n", attr_name, av);
63 printf("END:VCARD\n");
66 static gchar **search_filter = NULL;
68 static GOptionEntry entries[] =
70 { G_OPTION_REMAINING, 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_STRING_ARRAY, &search_filter, NULL, NULL},
74 int main(int argc, char **argv)
77 ESourceRegistry *eds_source_registry = NULL;
86 GOptionContext *optioncontext;
88 setlocale (LC_ALL, "");
90 optioncontext = g_option_context_new ("- whack address book");
91 g_option_context_add_main_entries (optioncontext, entries, NULL);
92 g_option_context_parse (optioncontext, &argc, &argv, &error);
95 fprintf(stderr, "%s\n", error->message);
99 eds_source_registry = e_source_registry_new_sync (NULL, &error);
101 fprintf(stderr, "%s\n", error->message);
105 sources = e_source_registry_list_sources (eds_source_registry, E_SOURCE_EXTENSION_ADDRESS_BOOK);
107 if (search_filter != NULL) {
108 query = e_book_query_any_field_contains(*search_filter);
110 query = e_book_query_field_exists(E_CONTACT_FULL_NAME);
113 for (s = sources ; s; s = s->next) {
114 source = E_SOURCE(s->data);
115 client = E_BOOK_CLIENT(e_book_client_connect_sync(source, NULL, &error));
118 fprintf(stderr, "e_book_client_connect_sync: %s\n", error->message);
124 /* XXX: leaks the query, but we're short running so doesn't really matter */
125 e_book_client_get_contacts_sync(client, e_book_query_to_string(query), &contacts, NULL, &error);
127 fprintf(stderr, "%s\n", error->message);
131 for (c = contacts; c; c = c->next) {
132 dump_as_vcard(E_CONTACT(c->data), 1);
135 e_book_query_unref(query);
136 g_list_free_full(sources, g_object_unref);