]> err.no Git - eweouz/blobdiff - src/eweouz-write-addressbook.c
Update to newer API
[eweouz] / src / eweouz-write-addressbook.c
index c3da2617d51f998e2dd668f166d6afc57d6e5b4f..21870b70e56bf623ccded25cc237bb8d1e3f9709 100644 (file)
@@ -1,5 +1,4 @@
-#include <libebook/e-book.h>
-#include <libedataserver/e-source-group.h>
+#include <libebook/libebook.h>
 #include <glib.h>
 #include <locale.h>
 
@@ -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);