From: Tollef Fog Heen Date: Tue, 18 Sep 2012 09:15:26 +0000 (+0200) Subject: Update to newer API X-Git-Tag: 0.8~13 X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=33fd687f1f7fec5b3140ca2f7edbde47ea4afa31;p=eweouz Update to newer API --- diff --git a/src/eweouz-dump-addressbook.c b/src/eweouz-dump-addressbook.c index 2f6dea9..4072426 100644 --- a/src/eweouz-dump-addressbook.c +++ b/src/eweouz-dump-addressbook.c @@ -1,5 +1,4 @@ -#include -#include +#include #include #include @@ -58,14 +57,13 @@ static GOptionEntry entries[] = int main(int argc, char **argv) { EBook *book; - ESourceList *source_list; - ESourceGroup *group; + ESourceRegistry *eds_source_registry = NULL; + GList *sources; ESource *source; GSList *groups; EBookQuery *query; GList *contacts; - GSList *sources; - GSList *g, *s; + GList *g, *s; GList *c; GError *error = NULL; GOptionContext *optioncontext; @@ -82,52 +80,48 @@ int main(int argc, char **argv) return 1; } - e_book_get_addressbooks(&source_list, &error); - + eds_source_registry = e_source_registry_new_sync (NULL, &error); if (error != NULL) { fprintf(stderr, "%s\n", error->message); return 1; } + sources = e_source_registry_list_sources (eds_source_registry, NULL); + if (search_filter != NULL) { query = e_book_query_any_field_contains(*search_filter); } 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) { - - 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); - - if (error != NULL) { - fprintf(stderr, "%s\n", error->message); - return 1; - } - - e_book_open(book, TRUE, &error); + for (s = sources ; s; s = s->next) { + source = E_SOURCE(s->data); + book = e_book_new(source, &error); + if (error != NULL) { + fprintf(stderr, "%s\n", error->message); + return 1; + } - if (error != NULL) { - fprintf(stderr, "%s\n", error->message); - return 1; - } + e_book_open(book, TRUE, &error); - e_book_get_contacts(book, query, &contacts, &error); - if (error != NULL) { - fprintf(stderr, "%s\n", error->message); - return 1; - } - for (c = contacts; c; c = c->next) { - dump_as_vcard(E_CONTACT(c->data), 1); - } + if (error != NULL) { + fprintf(stderr, "%s\n", error->message); + return 1; + } + + e_book_get_contacts(book, query, &contacts, &error); + if (error != NULL) { + fprintf(stderr, "%s\n", error->message); + return 1; + } + + for (c = contacts; c; c = c->next) { + dump_as_vcard(E_CONTACT(c->data), 1); } } - e_book_query_unref (query); + e_book_query_unref(query); + g_list_free_full(sources, g_object_unref); + } diff --git a/src/eweouz-write-addressbook.c b/src/eweouz-write-addressbook.c index c3da261..21870b7 100644 --- a/src/eweouz-write-addressbook.c +++ b/src/eweouz-write-addressbook.c @@ -1,5 +1,4 @@ -#include -#include +#include #include #include @@ -35,14 +34,13 @@ Notes String or `bbdb-record-raw-notes' String or Association int main(int argc, char **argv) { EBook *book; - ESourceList *source_list; - ESourceGroup *group; + ESourceRegistry *eds_source_registry = NULL; + EBookClient *ebc; ESource *source; - GSList *groups; EBookQuery *query; GList *contacts; - GSList *sources; - GSList *g, *s; + GList *sources; + GList *g, *s; GList *c; GError *error = NULL; GOptionContext *optioncontext; @@ -60,11 +58,10 @@ int main(int argc, char **argv) exit(1); } - e_book_get_addressbooks(&source_list, &error); - + eds_source_registry = e_source_registry_new_sync (NULL, &error); if (error != NULL) { fprintf(stderr, "%s\n", error->message); - exit(1); + return 1; } if (id == NULL) { @@ -109,20 +106,25 @@ int main(int argc, char **argv) g_object_set(c, "email", el, NULL); } } + source = e_source_registry_ref_default_address_book(eds_source_registry); - book = e_book_new_system_addressbook (&error); + if (! source) { + return 1; + } + + ebc = e_book_client_new(source, &error); if (error != NULL) { fprintf(stderr, "%s\n", error->message); return 1; } - e_book_open (book, TRUE, &error); + e_client_open_sync(E_CLIENT(ebc), TRUE, NULL, &error); if (error != NULL) { fprintf(stderr, "%s\n", error->message); return 1; } - e_book_add_contact (book, c, &error); + e_book_client_add_contact_sync(ebc, c, NULL, NULL, &error); if (error != NULL) { fprintf(stderr, "%s\n", error->message); return 1; @@ -130,46 +132,41 @@ int main(int argc, char **argv) } else { char *qu = g_strdup_printf ("(is \"id\" \"%s\")", id); query = e_book_query_from_string(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) { - if (full_name) - g_object_set(E_CONTACT(c->data), "full-name", full_name, NULL); - - if (nickname) - g_object_set(E_CONTACT(c->data), "nickname", nickname, NULL); - - if (emails != NULL) { - gchar **head = emails; - GList *el = NULL; - - if (*head[0] == '\0') { - printf("removing all emails\n"); - head++; - } else { - g_object_get(E_CONTACT(c->data), "email", &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, NULL); + + sources = e_source_registry_list_sources (eds_source_registry, NULL); + + 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) { + if (full_name) + g_object_set(E_CONTACT(c->data), "full-name", full_name, NULL); + + if (nickname) + g_object_set(E_CONTACT(c->data), "nickname", nickname, NULL); + + if (emails != NULL) { + gchar **head = emails; + GList *el = NULL; + + if (*head[0] == '\0') { + printf("removing all emails\n"); + head++; + } else { + g_object_get(E_CONTACT(c->data), "email", &el, NULL); + } + + while (*head != NULL) { + printf("appending %s\n", *head); + el = g_list_prepend(el, *head); + head++; } - e_book_commit_contact(book, E_CONTACT(c->data), &error); + g_object_set(E_CONTACT(c->data), "email", el, NULL); } + e_book_commit_contact(book, E_CONTACT(c->data), &error); } } e_book_query_unref (query);