]> err.no Git - eweouz/commitdiff
Add search filtering
authorTollef Fog Heen <tfheen@err.no>
Tue, 16 Oct 2007 19:10:12 +0000 (21:10 +0200)
committerTollef Fog Heen <tfheen@err.no>
Tue, 16 Oct 2007 19:10:12 +0000 (21:10 +0200)
src/dump-addressbook.c

index 4f8e47de9711c26f106d04f56dedf14849ea0686..f30f5060d091dc972702eb23048ede00e51f477d 100644 (file)
@@ -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);
 }