build test-ebook-async
authorChris Toshok <toshok@ximian.com>
Sun, 8 Feb 2004 20:56:45 +0000 (20:56 +0000)
committerChris Toshok <toshok@src.gnome.org>
Sun, 8 Feb 2004 20:56:45 +0000 (20:56 +0000)
2004-02-08  Chris Toshok  <toshok@ximian.com>

* tests/ebook/Makefile.am (noinst_PROGRAMS): build
test-ebook-async

* tests/ebook/test-ebook-async.c: async version of test-ebook.c

* tests/ebook/test-ebook.c (main): remove the call to
bonobo_main_quit here - we don't need it.

addressbook/ChangeLog
addressbook/tests/ebook/Makefile.am
addressbook/tests/ebook/test-ebook-async.c [new file with mode: 0644]
addressbook/tests/ebook/test-ebook.c

index cb97299..832bcba 100644 (file)
@@ -1,5 +1,15 @@
 2004-02-08  Chris Toshok  <toshok@ximian.com>
 
+       * tests/ebook/Makefile.am (noinst_PROGRAMS): build
+       test-ebook-async
+
+       * tests/ebook/test-ebook-async.c: async version of test-ebook.c
+
+       * tests/ebook/test-ebook.c (main): remove the call to
+       bonobo_main_quit here - we don't need it.
+
+2004-02-08  Chris Toshok  <toshok@ximian.com>
+
        * libebook/e-book-async.c (main_thread_get_response): lock the
        idle mutex around this function, reset it to -1, and return FALSE.
        (push_response): abstract out all the g_async_queue_push stuff
index d85ea4d..cf88675 100644 (file)
@@ -6,10 +6,11 @@ TEST_LIBS=                                            \
        $(top_builddir)/addressbook/libebook/libebook.la\
        $(EVOLUTION_ADDRESSBOOK_LIBS)
 
-noinst_PROGRAMS= test-changes test-categories test-date test-ebook test-ebook-view test-photo test-self test-string test-undefinedfield test-untyped-phones
+noinst_PROGRAMS= test-changes test-categories test-date test-ebook test-ebook-async test-ebook-view test-photo test-self test-string test-undefinedfield test-untyped-phones
 
 test_date_LDADD=$(TEST_LIBS)
 test_ebook_LDADD=$(TEST_LIBS)
+test_ebook_async_LDADD=$(TEST_LIBS)
 test_ebook_view_LDADD=$(TEST_LIBS)
 test_changes_LDADD=$(TEST_LIBS)
 test_categories_LDADD=$(TEST_LIBS)
diff --git a/addressbook/tests/ebook/test-ebook-async.c b/addressbook/tests/ebook/test-ebook-async.c
new file mode 100644 (file)
index 0000000..2a7a0e4
--- /dev/null
@@ -0,0 +1,105 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+#include <libgnome/gnome-init.h>
+#include <bonobo/bonobo-main.h>
+#include <stdlib.h>
+#include <libebook/e-book-async.h>
+
+static void
+print_email (EContact *contact)
+{
+       char *file_as = e_contact_get_const (contact, E_CONTACT_FILE_AS);
+       char *name_or_org = e_contact_get_const (contact, E_CONTACT_NAME_OR_ORG);
+       GList *emails, *e;
+
+       printf ("Contact: %s\n", file_as);
+       printf ("Name or org: %s\n", name_or_org);
+       printf ("Email addresses:\n");
+       emails = e_contact_get (contact, E_CONTACT_EMAIL);
+       for (e = emails; e; e = e->next) {
+               printf ("\t%s\n",  (char*)e->data);
+       }
+       g_list_foreach (emails, (GFunc)g_free, NULL);
+       g_list_free (emails);
+
+       printf ("\n");
+}
+
+static void
+print_all_emails_cb (EBook *book, EBookStatus status, GList *contacts, gpointer closure)
+{
+       GList *c;
+
+       if (status == E_BOOK_ERROR_OK) {
+               for (c = contacts; c; c = c->next) {
+                       EContact *contact = E_CONTACT (c->data);
+
+                       print_email (contact);
+               }
+       }
+
+       bonobo_main_quit ();
+}
+
+static void
+print_all_emails (EBook *book)
+{
+       EBookQuery *query;
+
+       query = e_book_query_field_exists (E_CONTACT_FULL_NAME);
+
+       e_book_async_get_contacts (book, query, print_all_emails_cb, NULL);
+
+       e_book_query_unref (query);
+}
+
+static void
+print_email_cb (EBook *book, EBookStatus status, EContact *contact, gpointer closure)
+{
+       if (status == E_BOOK_ERROR_OK)
+               print_email (contact);
+
+       printf ("printing all contacts\n");
+       print_all_emails (book);
+}
+
+static void
+print_one_email (EBook *book)
+{
+       e_book_async_get_contact (book, "pas-id-0002023", print_email_cb, NULL);
+}
+
+static void
+book_loaded_cb (EBook *book, EBookStatus status, gpointer data)
+{
+       if (status != E_BOOK_ERROR_OK)
+               return;
+
+       printf ("printing one contact\n");
+       print_one_email (book);
+}
+
+int
+main (int argc, char **argv)
+{
+       EBook *book;
+       gboolean status;
+
+       gnome_program_init("test-ebook", "0.0", LIBGNOME_MODULE, argc, argv, NULL);
+
+       if (bonobo_init (&argc, argv) == FALSE)
+               g_error ("Could not initialize Bonobo");
+
+       /*
+       ** the actual ebook foo
+       */
+
+       book = e_book_new ();
+
+       printf ("loading addressbook\n");
+       e_book_async_load_local_addressbook (book, book_loaded_cb, book);
+
+       bonobo_main();
+
+       return 0;
+}
index 020fd79..df5f2e7 100644 (file)
@@ -102,7 +102,5 @@ main (int argc, char **argv)
 
        g_object_unref (book);
 
-       bonobo_main_quit();
-
        return 0;
 }