]> err.no Git - eweouz/blobdiff - src/eweouz-dump-addressbook.c
Add copyright notices for .c files too
[eweouz] / src / eweouz-dump-addressbook.c
index 2f6dea982f514feb28008541076d3b35c4710b80..769b69921e21ceec8fe1c79220c412be634994f1 100644 (file)
@@ -1,5 +1,21 @@
-#include <libebook/e-book.h>
-#include <libedataserver/e-source-group.h>
+/* Copyright (c) 2008-2013 Tollef Fog Heen <tfheen@err.no>
+
+ eweouz is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License version 2 as
+ published by the Free Software Foundation.
+
+ eweouz is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301 USA.
+*/
+
+#include <libebook/libebook.h>
 #include <glib.h>
 #include <locale.h>
 
@@ -57,22 +73,20 @@ static GOptionEntry entries[] =
 
 int main(int argc, char **argv)
 {
-       EBook *book;
-       ESourceList *source_list;
-       ESourceGroup *group;
+       EBookClient *client;
+       ESourceRegistry *eds_source_registry = NULL;
+       GList *sources;
        ESource *source;
        GSList *groups;
        EBookQuery *query;
-       GList *contacts;
-       GSList *sources;
-       GSList *g, *s;
-       GList *c;
+       GSList *contacts;
+       GList *g, *s;
+       GSList *c;
        GError *error = NULL;
        GOptionContext *optioncontext;
 
        setlocale (LC_ALL, "");
 
-       g_type_init();
        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);
@@ -82,52 +96,43 @@ 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, E_SOURCE_EXTENSION_ADDRESS_BOOK);
+
        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;
-                       }
+       for (s = sources ; s; s = s->next) {
+               source = E_SOURCE(s->data);
+               client = E_BOOK_CLIENT(e_book_client_connect_sync(source, NULL, &error));
 
-                       e_book_open(book, TRUE, &error);
-
-
-                       if (error != NULL) {
-                         fprintf(stderr, "%s\n", error->message);
-                         return 1;
-                       }
+               if (error != NULL) {
+                       fprintf(stderr, "e_book_client_connect_sync: %s\n", error->message);
+                       g_error_free(error);
+                       error = NULL;
+                       continue;
+               }
 
-                       e_book_get_contacts(book, query, &contacts, &error);
-                       if (error != NULL) {
-                         fprintf(stderr, "%s\n", error->message);
-                         return 1;
-                       }
+               /* XXX: leaks the query, but we're short running so doesn't really matter */
+               e_book_client_get_contacts_sync(client, e_book_query_to_string(query), &contacts, NULL, &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);
-                       }
+               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);
+
 }