gint
main (gint argc,
      gchar **argv)
{
#if 0  /* ACCOUNT_MGMT */
	EBook *book;
	gboolean status;
	EBookQuery *query;
	EBookView *view = NULL;
	EBookView *new_view;
	gint i;

	g_type_init ();

	/*
	** the actual ebook foo
	*/

	printf ("loading addressbook\n");
	book = e_book_new_system_addressbook (NULL);
	if (!book) {
		printf ("failed to create ebook\n");
		exit (0);
	}

	status = e_book_open (book, FALSE, NULL);
	if (status == FALSE) {
		printf ("failed to open local addressbook\n");
		exit (0);
	}

	query = e_book_query_any_field_contains ("");

	for (i = 0; i < 500; i++) {
		status = e_book_get_book_view (book, query, NULL, -1, &new_view, NULL);

		g_signal_connect (new_view, "contacts_added", G_CALLBACK (contacts_added), NULL);
		g_signal_connect (new_view, "contacts_removed", G_CALLBACK (contacts_removed), NULL);
		g_signal_connect (new_view, "view_complete", G_CALLBACK (view_complete), NULL);

		e_book_view_start (new_view);

		if (view) {
			e_book_view_stop (view);
			g_object_unref (view);
		}

		view = new_view;
	}

	e_book_view_stop (view);
	g_object_unref (view);

	e_book_query_unref (query);
	g_object_unref (book);
#endif /* ACCOUNT_MGMT */

	return 0;
}
static void
view_complete (EBookView *book_view, EBookViewStatus status, const gchar *error_msg)
{
	e_book_view_stop (book_view);
	g_object_unref (book_view);
	g_main_loop_quit (loop);
}
static void add_gnome_addressbook(GList **address_list)
{
  ESourceRegistry * registry = NULL;
  GError *error = NULL;
  GList *a;

  registry = e_source_registry_new_sync (NULL, &error);

  if (!registry || error) {
    debug_print("Error: Failed to get access to source registry: %s\n", error->message);
    g_error_free(error);
    return;
  }

  // create book accessor if necessary
  if(!eds_books) {
    GList *list_sources = e_source_registry_list_sources (registry, E_SOURCE_EXTENSION_ADDRESS_BOOK);
    for (a = list_sources; a; a = a->next) {
      ESource *source = E_SOURCE (a->data);
      if (e_source_get_enabled(source)) {
        EBook *eds_book = e_book_new(source, &error);

        if(!eds_book) {
          g_list_free_full(list_sources, g_object_unref);
          debug_print("Error: Could not get eds addressbook: %s\n", error->message);
          g_error_free(error);
          return;
        }
        eds_books = g_list_append (eds_books, eds_book);
      }
    }
    g_list_free_full(list_sources, g_object_unref);
  }

  for (a = eds_books; a; a = a->next) {
    EBook *eds_book = a->data;
    EBookQuery *query;
    EBookView *view;

    // open book if necessary
    if(!e_book_is_opened(eds_book) && !e_book_open(eds_book, TRUE, &error)) {
      debug_print("Error: Could not open eds addressbook: %s\n", error->message);
      g_error_free(error);
      return;
    }

    // query book
    query = e_book_query_field_exists(E_CONTACT_EMAIL);
    if(!e_book_get_book_view(eds_book, query, NULL, 0, &view, &error)) {
      debug_print("Error: Could not get eds addressbook view: %s\n", error->message);
      g_error_free(error);
    }
    e_book_query_unref(query);

    g_signal_connect(G_OBJECT(view), "contacts-added", G_CALLBACK(eds_contacts_added_cb), address_list);
    g_signal_connect(G_OBJECT(view), "sequence-complete", G_CALLBACK(eds_sequence_complete_cb), NULL);

    eds_waiting = TRUE;
    e_book_view_start(view);

    while(eds_waiting)
      gtk_main_iteration();

    e_book_view_stop(view);
    g_object_unref(view);
  }

}