]> err.no Git - eweouz/commitdiff
Add initial write support
authorTollef Fog Heen <tfheen@err.no>
Tue, 16 Oct 2007 19:33:40 +0000 (21:33 +0200)
committerTollef Fog Heen <tfheen@err.no>
Tue, 16 Oct 2007 19:33:40 +0000 (21:33 +0200)
src/Makefile.am
src/write-addressbook.c [new file with mode: 0644]

index 6c778888661f91186e03fc16c854dd2b7294d7fc..8a7b03d94c2f23382994fcb0f30dc82ba3c9f544 100644 (file)
@@ -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 (file)
index 0000000..8241626
--- /dev/null
@@ -0,0 +1,74 @@
+#include <libebook/e-book.h>
+#include <libedataserver/e-source-group.h>
+#include <gconf/gconf.h>
+#include <glib.h>
+
+
+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);
+}