~ubuntu-branches/ubuntu/precise/evolution-data-server/precise

« back to all changes in this revision

Viewing changes to tests/libebook/test-ebook-async.c

  • Committer: Bazaar Package Importer
  • Author(s): Mathieu Trudel-Lapierre, Ken VanDine, Mathieu Trudel-Lapierre
  • Date: 2011-06-23 17:40:41 UTC
  • mfrom: (1.1.88 upstream)
  • Revision ID: james.westby@ubuntu.com-20110623174041-4wd9jvs07wfinyet
Tags: 3.1.2-0ubuntu1
* New upstream version
  - bgo 589495 - Search folder by Size (KB) counts bytes, not KB (LP: #385859)
  - bgo 649757 - Filtering on a source account always succeeded (LP: #781391)
  - bgo 418954 - Add a separate entry combo for port numbers (LP: #160304)

[ Ken VanDine ]
* debian/libebook1.2-dev.install
  - Include EBook-1.2.gir
* debian/control
  - Added gir1.2-ebook-1.2 binary

[ Mathieu Trudel-Lapierre ]
* debian/control: drop libegroupwise1.2-13, libegroupwise-dev, they are now
  an independent module.
* debian/libegroupwise1.2-13.install,
  debian/libegroupwise1.2-dev.install,
  debian/lintian/libegroupwise1.2-13: dropped, see above.
* debian/control, debian/libe*.install, debian/lintian/libe*: rename and
  update files where needed to follow upstream soname changes.
* debian/control: bump evolution-data-server's Depends to libcamel-1.2-26.
* debian/rules: update to use makeshlibs with the new libcamel soname.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
 
2
 
 
3
#include <stdlib.h>
 
4
#include <libebook/e-book.h>
 
5
 
 
6
static GMainLoop *loop;
 
7
 
 
8
static void
 
9
print_email (EContact *contact)
 
10
{
 
11
        const gchar *file_as = e_contact_get_const (contact, E_CONTACT_FILE_AS);
 
12
        const gchar *name_or_org = e_contact_get_const (contact, E_CONTACT_NAME_OR_ORG);
 
13
        GList *emails, *e;
 
14
 
 
15
        printf ("Contact: %s\n", file_as);
 
16
        printf ("Name or org: %s\n", name_or_org);
 
17
        printf ("Email addresses:\n");
 
18
        emails = e_contact_get (contact, E_CONTACT_EMAIL);
 
19
        for (e = emails; e; e = e->next) {
 
20
                printf ("\t%s\n",  (gchar *)e->data);
 
21
        }
 
22
        g_list_foreach (emails, (GFunc) g_free, NULL);
 
23
        g_list_free (emails);
 
24
 
 
25
        printf ("\n");
 
26
}
 
27
 
 
28
static void
 
29
print_all_emails_cb (EBook *book, const GError *error, GList *contacts, gpointer closure)
 
30
{
 
31
        GList *c;
 
32
 
 
33
        if (!error) {
 
34
                for (c = contacts; c; c = c->next) {
 
35
                        EContact *contact = E_CONTACT (c->data);
 
36
 
 
37
                        print_email (contact);
 
38
                }
 
39
        } else {
 
40
                g_warning ("%s: Got error %d (%s)", G_STRFUNC, error->code, error->message);
 
41
        }
 
42
 
 
43
        g_main_loop_quit (loop);
 
44
}
 
45
 
 
46
static void
 
47
print_all_emails (EBook *book)
 
48
{
 
49
        EBookQuery *query;
 
50
 
 
51
        query = e_book_query_field_exists (E_CONTACT_FULL_NAME);
 
52
 
 
53
        e_book_get_contacts_async (book, query, print_all_emails_cb, NULL);
 
54
 
 
55
        e_book_query_unref (query);
 
56
}
 
57
 
 
58
static void
 
59
print_email_cb (EBook *book, const GError *error, EContact *contact, gpointer closure)
 
60
{
 
61
        if (!error)
 
62
                print_email (contact);
 
63
        else
 
64
                g_warning ("%s: Got error %d (%s)", G_STRFUNC, error->code, error->message);
 
65
 
 
66
        printf ("printing all contacts\n");
 
67
        print_all_emails (book);
 
68
}
 
69
 
 
70
static void
 
71
print_one_email (EBook *book)
 
72
{
 
73
        e_book_get_contact_async (book, "pas-id-0002023", print_email_cb, NULL);
 
74
}
 
75
 
 
76
static void
 
77
book_loaded_cb (EBook *book, const GError *error, gpointer data)
 
78
{
 
79
        if (error) {
 
80
                g_warning ("%s: Got error %d (%s)", G_STRFUNC, error->code, error->message);
 
81
                return;
 
82
        }
 
83
 
 
84
        printf ("printing one contact\n");
 
85
        print_one_email (book);
 
86
}
 
87
 
 
88
gint
 
89
main (gint argc, gchar **argv)
 
90
{
 
91
        EBook *book;
 
92
 
 
93
        g_type_init ();
 
94
        loop = g_main_loop_new (NULL, TRUE);
 
95
 
 
96
        /*
 
97
        ** the actual ebook foo
 
98
        */
 
99
 
 
100
        book = e_book_new_system_addressbook (NULL);
 
101
 
 
102
        printf ("loading addressbook\n");
 
103
        e_book_open_async (book, FALSE, book_loaded_cb, book);
 
104
 
 
105
        g_main_loop_run (loop);
 
106
 
 
107
        return 0;
 
108
}