From: Tollef Fog Heen Date: Sat, 2 Aug 2008 06:30:17 +0000 (+0200) Subject: Add some semblance of write support X-Git-Tag: 0.1~9 X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9077feecf7a66781497bcccfbdff1681b89413c5;p=eweouz Add some semblance of write support --- diff --git a/src/write-addressbook.c b/src/write-addressbook.c index 8241626..8cd12a0 100644 --- a/src/write-addressbook.c +++ b/src/write-addressbook.c @@ -4,14 +4,35 @@ #include -static gchar **search_filter = NULL; +static gchar *id = NULL; +static gchar *full_name = NULL; +static gchar *nickname = NULL; +static gchar *company = NULL; +static gchar **phones = NULL; +static gchar **emails = NULL; static GOptionEntry entries[] = { - { G_OPTION_REMAINING, 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_STRING_ARRAY, &search_filter, NULL, NULL}, + { "id", 0, 0, G_OPTION_ARG_STRING, &id, "ID of element to modify", "ID" }, + { "full-name", 0, 0, G_OPTION_ARG_STRING, &full_name, "Full name of person", "full_name" }, + { "nickname", 0, 0, G_OPTION_ARG_STRING, &nickname, "Nickname of person", "nick" }, + { "company", 0, 0, G_OPTION_ARG_STRING, &company, "Company of person", "company" }, + { "phones", 0, 0, G_OPTION_ARG_STRING_ARRAY, &phones, "Phone numbers (all)", "phone" }, + { "emails", 0, 0, G_OPTION_ARG_STRING_ARRAY, &emails, "Email addresses (all)", "email" }, + { NULL } }; +/* +Addresses List of `bbdb-record-addresses' List of address vectors + Vectors `bbdb-record-set-addresses' +Net List of `bbdb-record-net' List of network +address Strings `bbdb-record-set-net' addresses +Notes String or `bbdb-record-raw-notes' String or Association + Alist `bbdb-record-set-raw-notes'list of note fields + (strings) +*/ + int main(int argc, char **argv) { EBook *book; @@ -41,16 +62,13 @@ int main(int argc, char **argv) fprintf(stderr, "%s\n", error->message); } - if (search_filter == NULL) { + if (id == 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); + char *qu = g_strdup_printf ("(is \"id\" \"%s\")", id); 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) { @@ -65,10 +83,20 @@ int main(int argc, char **argv) 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); + if (emails != NULL) { + gchar **head = emails; + GList *el = NULL; + while (*head != NULL) { + printf("appending %s\n", *head); + el = g_list_prepend(el, *head); + head++; + } + g_object_set(E_CONTACT(c->data), "email", el); + e_book_commit_contact(book, E_CONTACT(c->data), &error); + } } } } e_book_query_unref (query); + g_free(qu); }