From 8dbc060532c5e6a7aba698e067ff5587e0e7598d Mon Sep 17 00:00:00 2001 From: Tollef Fog Heen Date: Tue, 16 Oct 2007 21:10:12 +0200 Subject: [PATCH] Add search filtering --- src/dump-addressbook.c | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/src/dump-addressbook.c b/src/dump-addressbook.c index 4f8e47d..f30f506 100644 --- a/src/dump-addressbook.c +++ b/src/dump-addressbook.c @@ -13,7 +13,7 @@ void dump_as_vcard(EContact *contact, int dump_all) EVCardAttribute *attr = (EVCardAttribute *) g_list_nth_data(attrs, i); int j; - char *attr_name = e_vcard_attribute_get_name(attr); + const char *attr_name = e_vcard_attribute_get_name(attr); if (!dump_all && strcmp(attr_name, "TEL") != 0 && @@ -42,7 +42,7 @@ void dump_as_vcard(EContact *contact, int dump_all) GList *vals = e_vcard_attribute_get_values(attr); for (j = 0; j < g_list_length(vals); j++) { - char *av = g_list_nth(vals, j); + const char *av = (char*) g_list_nth(vals, j); printf("%s: %s\n", attr_name, @@ -52,6 +52,14 @@ void dump_as_vcard(EContact *contact, int dump_all) } } +static gchar **search_filter = NULL; + +static GOptionEntry entries[] = +{ + { G_OPTION_REMAINING, 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_STRING_ARRAY, &search_filter, NULL, NULL}, + { NULL } +}; + int main(int argc, char **argv) { EBook *book; @@ -65,13 +73,32 @@ int main(int argc, char **argv) GSList *g, *s; GList *c; GError *error = NULL; + GOptionContext *optioncontext; - printf("%d\n", e_book_get_addressbooks(&source_list, &error)); + optioncontext = g_option_context_new ("- whack address book"); + g_option_context_add_main_entries (optioncontext, entries, NULL); + g_option_context_parse (optioncontext, &argc, &argv, &error); if (error != NULL) { fprintf(stderr, "%s\n", error->message); } + e_book_get_addressbooks(&source_list, &error); + + if (error != NULL) { + fprintf(stderr, "%s\n", error->message); + } + + if (search_filter != NULL) { + char *qu = g_strdup_printf ("(or (contains \"email\" \"%s\") " + "(contains \"full_name\" \"%s\"))", + *search_filter, *search_filter); + query = e_book_query_from_string(qu); + g_free(qu); + } else { + query = e_book_query_field_exists(E_CONTACT_FULL_NAME); + } + groups = e_source_list_peek_groups(source_list); for (g = groups; g; g = g->next) { @@ -82,9 +109,6 @@ int main(int argc, char **argv) source = E_SOURCE(s->data); book = e_book_new(source, &error); e_book_open(book, TRUE, &error); - - // query = e_book_query_any_field_contains(""); - query = e_book_query_field_exists(E_CONTACT_FULL_NAME); e_book_get_contacts(book, query, &contacts, &error); for (c = contacts; c; c = c->next) { @@ -92,4 +116,5 @@ int main(int argc, char **argv) } } } + e_book_query_unref (query); } -- 2.39.5