1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
#include <stdlib.h>
#include <libebook/e-book-client.h>
#include <libebook/e-book-query.h>
#include "client-test-utils.h"
static void
print_all_uids_cb (GObject *source_object,
GAsyncResult *result,
gpointer user_data)
{
EBookClient *book_client;
GSList *uids = NULL, *u;
GError *error = NULL;
book_client = E_BOOK_CLIENT (source_object);
g_return_if_fail (book_client != NULL);
if (!e_book_client_get_contacts_uids_finish (book_client, result, &uids, &error)) {
report_error ("get contacts uids finish", &error);
stop_main_loop (1);
return;
}
for (u = uids; u; u = u->next) {
const gchar *uid = u->data;
g_print (" uid:'%s'\n", uid);
}
g_slist_foreach (uids, (GFunc) g_free, NULL);
g_slist_free (uids);
stop_main_loop (0);
}
static void
print_all_emails_cb (GObject *source_object,
GAsyncResult *result,
gpointer user_data)
{
EBookClient *book_client;
EBookQuery *query;
gchar *sexp;
GSList *contacts = NULL, *c;
GError *error = NULL;
book_client = E_BOOK_CLIENT (source_object);
g_return_if_fail (book_client != NULL);
if (!e_book_client_get_contacts_finish (book_client, result, &contacts, &error)) {
report_error ("get contacts finish", &error);
stop_main_loop (1);
return;
}
for (c = contacts; c; c = c->next) {
EContact *contact = E_CONTACT (c->data);
print_email (contact);
}
g_slist_foreach (contacts, (GFunc) g_object_unref, NULL);
g_slist_free (contacts);
query = e_book_query_field_exists (E_CONTACT_FULL_NAME);
sexp = e_book_query_to_string (query);
e_book_query_unref (query);
e_book_client_get_contacts_uids (book_client, sexp, NULL, print_all_uids_cb, NULL);
g_free (sexp);
}
static void
print_all_emails (EBookClient *book_client)
{
EBookQuery *query;
gchar *sexp;
query = e_book_query_field_exists (E_CONTACT_FULL_NAME);
sexp = e_book_query_to_string (query);
e_book_query_unref (query);
e_book_client_get_contacts (book_client, sexp, NULL, print_all_emails_cb, NULL);
g_free (sexp);
}
static void
print_email_cb (GObject *source_object,
GAsyncResult *result,
gpointer user_data)
{
EBookClient *book_client;
EContact *contact = NULL;
GError *error = NULL;
book_client = E_BOOK_CLIENT (source_object);
g_return_if_fail (book_client != NULL);
if (!e_book_client_get_contact_finish (book_client, result, &contact, &error)) {
report_error ("get contact finish", &error);
} else {
print_email (contact);
g_object_unref (contact);
}
printf ("printing all contacts\n");
print_all_emails (book_client);
}
static void
print_one_email (EBookClient *book_client)
{
e_book_client_get_contact (book_client, "pas-id-0002023", NULL, print_email_cb, NULL);
}
static void
client_loaded_cb (GObject *source_object,
GAsyncResult *result,
gpointer user_data)
{
EBookClient *book_client;
GError *error = NULL;
book_client = E_BOOK_CLIENT (source_object);
g_return_if_fail (book_client != NULL);
if (!e_client_open_finish (E_CLIENT (book_client), result, &error)) {
report_error ("client open finish", &error);
stop_main_loop (1);
return;
}
printf ("printing one contact\n");
print_one_email (book_client);
}
gint
main (gint argc,
gchar **argv)
{
EBookClient *book_client;
GError *error = NULL;
main_initialize ();
book_client = e_book_client_new_system (&error);
if (error) {
report_error ("create system addressbook", &error);
return 1;
}
printf ("loading addressbook\n");
e_client_open (E_CLIENT (book_client), FALSE, NULL, client_loaded_cb, NULL);
start_main_loop (NULL, NULL);
g_object_unref (book_client);
return get_main_loop_stop_result ();
}
|