From 6d629f3862eea022d1d3307899c21d254851fb8a Mon Sep 17 00:00:00 2001 From: Tollef Fog Heen Date: Tue, 16 Oct 2007 21:33:40 +0200 Subject: [PATCH] Add initial write support --- src/Makefile.am | 2 +- src/write-addressbook.c | 74 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 src/write-addressbook.c diff --git a/src/Makefile.am b/src/Makefile.am index 6c77888..8a7b03d 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,5 +1,5 @@ -bin_PROGRAMS = dump-addressbook +bin_PROGRAMS = dump-addressbook write-addressbook AM_CFLAGS = $(EDS_ADDRESS_CFLAGS) AM_LDFLAGS = $(EDS_ADDRESS_LIBS) diff --git a/src/write-addressbook.c b/src/write-addressbook.c new file mode 100644 index 0000000..8241626 --- /dev/null +++ b/src/write-addressbook.c @@ -0,0 +1,74 @@ +#include +#include +#include +#include + + +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; + ESourceList *source_list; + ESourceGroup *group; + ESource *source; + GSList *groups; + EBookQuery *query; + GList *contacts; + GSList *sources; + GSList *g, *s; + GList *c; + GError *error = NULL; + GOptionContext *optioncontext; + + 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) { + fprintf(stderr, "You must provide a filter\n"); + exit(1); + } + + 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); + + groups = e_source_list_peek_groups(source_list); + for (g = groups; g; g = g->next) { + + group = E_SOURCE_GROUP (g->data); + sources = e_source_group_peek_sources(group); + + for (s = sources ; s; s = s->next) { + source = E_SOURCE(s->data); + book = e_book_new(source, &error); + e_book_open(book, TRUE, &error); + e_book_get_contacts(book, query, &contacts, &error); + + for (c = contacts; c; c = c->next) { + g_object_set(E_CONTACT(c->data), "fburl", "http://etsted.blah/123"); + e_book_commit_contact(book, E_CONTACT(c->data), &error); + } + } + } + e_book_query_unref (query); +} -- 2.39.5