]> err.no Git - eweouz/commitdiff
Update to newer API
authorTollef Fog Heen <tfheen@err.no>
Tue, 18 Sep 2012 09:15:26 +0000 (11:15 +0200)
committerTollef Fog Heen <tfheen@err.no>
Tue, 18 Sep 2012 09:15:26 +0000 (11:15 +0200)
src/eweouz-dump-addressbook.c
src/eweouz-write-addressbook.c

index 2f6dea982f514feb28008541076d3b35c4710b80..4072426dcaa1c8a2ff25b0f759d7e4cc02785107 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>
 
@@ -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);
+
 }
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);