1
From 7c7d01ec54cdde2e6d782e398c7b2a9600867e80 Mon Sep 17 00:00:00 2001
2
From: Simon Fels <simon.fels@canonical.com>
3
Date: Fri, 11 Sep 2015 18:46:26 +0200
4
Subject: [PATCH 1/4] obexd: plugins: port ebook support to the latest EDS
6
Signed-off-by: Simon Fels <simon.fels@canonical.com>
8
obexd/plugins/phonebook-ebook.c | 132 ++++++++++++++++++----------------------
9
1 file changed, 60 insertions(+), 72 deletions(-)
11
diff --git a/obexd/plugins/phonebook-ebook.c b/obexd/plugins/phonebook-ebook.c
12
index c422585..d1e6159 100644
13
--- a/obexd/plugins/phonebook-ebook.c
14
+++ b/obexd/plugins/phonebook-ebook.c
21
-#include <libebook/e-book.h>
23
+#include <libebook/libebook.h>
25
#include "lib/bluetooth.h"
27
@@ -158,13 +158,17 @@ static char *evcard_to_string(EVCard *evcard, unsigned int format,
31
-static void ebookpull_cb(EBook *book, const GError *gerr, GList *contacts,
33
+static void ebookpull_cb(EBookClient *client, GAsyncResult *res,
36
struct query_context *data = user_data;
39
+ GSList *contacts = NULL;
40
+ GError *gerr = NULL;
41
unsigned int count, maxcount;
43
+ e_book_client_get_contacts_finish(client, res, &contacts, &gerr);
48
@@ -184,13 +188,13 @@ static void ebookpull_cb(EBook *book, const GError *gerr, GList *contacts,
50
maxcount = data->params->maxlistcount;
52
- data->count += g_list_length(contacts);
53
+ data->count += g_slist_length(contacts);
57
- l = g_list_nth(contacts, data->params->liststartoffset);
58
+ l = g_slist_nth(contacts, data->params->liststartoffset);
60
- for (count = 0; l && count + data->count < maxcount; l = g_list_next(l),
61
+ for (count = 0; l && count + data->count < maxcount; l = g_slist_next(l),
63
EContact *contact = E_CONTACT(l->data);
64
EVCard *evcard = E_VCARD(contact);
65
@@ -208,7 +212,7 @@ static void ebookpull_cb(EBook *book, const GError *gerr, GList *contacts,
69
- g_list_free_full(contacts, g_object_unref);
70
+ g_slist_free_full(contacts, g_object_unref);
73
if (data->queued_calls == 0) {
74
@@ -229,14 +233,18 @@ canceled:
75
free_query_context(data);
78
-static void ebook_entry_cb(EBook *book, const GError *gerr,
79
- EContact *contact, void *user_data)
80
+static void ebook_entry_cb(EBookClient *client, GAsyncResult *res,
83
struct query_context *data = user_data;
85
+ GError *gerr = NULL;
90
+ e_book_client_get_contact_finish(client, res, &contact, &gerr);
95
@@ -244,6 +252,7 @@ static void ebook_entry_cb(EBook *book, const GError *gerr,
98
error("E-Book query failed: %s", gerr->message);
103
@@ -367,81 +376,55 @@ canceled:
104
free_query_context(data);
107
-static GSList *traverse_sources(GSList *ebooks, GSList *sources,
108
- char **default_src) {
109
+static GSList *traverse_sources(GSList *ebooks, ESource *source)
113
- for (; sources != NULL; sources = g_slist_next(sources)) {
115
- ESource *source = E_SOURCE(sources->data);
116
- EBook *ebook = e_book_new(source, &gerr);
118
- if (ebook == NULL) {
119
- error("Can't create user's address book: %s",
121
- g_clear_error(&gerr);
125
- uri = e_source_get_uri(source);
126
- if (g_strcmp0(*default_src, uri) == 0) {
132
- if (e_book_open(ebook, FALSE, &gerr) == FALSE) {
133
- error("Can't open e-book address book: %s",
134
+ EClient *client = e_book_client_connect_sync(source, -1, NULL, &gerr);
135
+ if (client == NULL) {
136
+ error("Can't create user's address book: %s",
138
- g_object_unref(ebook);
139
- g_clear_error(&gerr);
143
- if (*default_src == NULL)
144
- *default_src = e_source_get_uri(source);
145
+ g_clear_error(&gerr);
149
- DBG("%s address book opened", e_source_peek_name(source));
150
+ DBG("%s address book opened", e_source_get_display_name(source));
152
- ebooks = g_slist_append(ebooks, ebook);
154
+ ebooks = g_slist_append(ebooks, client);
159
int phonebook_init(void)
166
static GSList *open_ebooks(void)
169
- ESourceList *src_list;
171
- char *default_src = NULL;
173
GSList *ebooks = NULL;
174
+ ESourceRegistry *registry;
176
- if (e_book_get_addressbooks(&src_list, &gerr) == FALSE) {
177
+ registry = e_source_registry_new_sync(NULL, &gerr);
179
error("Can't list user's address books: %s", gerr->message);
184
- list = e_source_list_peek_groups(src_list);
185
+ list = e_source_registry_list_sources(registry, E_SOURCE_EXTENSION_ADDRESS_BOOK);
186
while (list != NULL) {
187
- ESourceGroup *group = E_SOURCE_GROUP(list->data);
188
- GSList *sources = e_source_group_peek_sources(group);
189
+ ESource *source = E_SOURCE(list->data);
191
- ebooks = traverse_sources(ebooks, sources, &default_src);
192
+ ebooks = traverse_sources(ebooks, source);
197
- g_free(default_src);
198
- g_object_unref(src_list);
199
+ g_list_free_full(list, g_object_unref);
200
+ g_object_unref(registry);
204
@@ -579,14 +562,13 @@ int phonebook_pull_read(void *request)
207
for (l = data->ebooks; l != NULL; l = g_slist_next(l)) {
208
- EBook *ebook = l->data;
210
- if (e_book_is_opened(ebook) == FALSE)
212
+ EClient *client = l->data;
213
+ gchar *query = e_book_query_to_string(data->query);
215
- if (e_book_get_contacts_async(ebook, data->query,
216
- ebookpull_cb, data) == TRUE)
217
- data->queued_calls++;
218
+ e_book_client_get_contacts(E_BOOK_CLIENT(client), query,
219
+ NULL, (GAsyncReadyCallback) ebookpull_cb, data);
220
+ data->queued_calls++;
224
if (data->queued_calls == 0)
225
@@ -610,14 +592,11 @@ void *phonebook_get_entry(const char *folder, const char *id,
226
data->ebooks = open_ebooks();
228
for (l = data->ebooks; l != NULL; l = g_slist_next(l)) {
229
- EBook *ebook = l->data;
231
- if (e_book_is_opened(ebook) == FALSE)
233
+ EClient *client = l->data;
235
- if (e_book_get_contact_async(ebook, data->id,
236
- ebook_entry_cb, data) == TRUE)
237
- data->queued_calls++;
238
+ e_book_client_get_contact(E_BOOK_CLIENT(client), data->id,
239
+ NULL, (GAsyncReadyCallback) ebook_entry_cb, data);
240
+ data->queued_calls++;
244
@@ -630,12 +609,13 @@ void *phonebook_create_cache(const char *name, phonebook_entry_cb entry_cb,
245
phonebook_cache_ready_cb ready_cb, void *user_data, int *err)
247
struct query_context *data;
248
+ ESourceRegistry *registry;
256
EVCardAttribute *attrib;
257
char *uid, *tel, *cname;
259
@@ -648,6 +628,13 @@ void *phonebook_create_cache(const char *name, phonebook_entry_cb entry_cb,
263
+ registry = e_source_registry_new_sync(NULL, &gerr);
265
+ error("Can't access user's address books: %s", gerr->message);
266
+ g_error_free(gerr);
270
query = e_book_query_any_field_contains("");
272
data = g_new0(struct query_context, 1);
273
@@ -658,7 +645,7 @@ void *phonebook_create_cache(const char *name, phonebook_entry_cb entry_cb,
274
data->ebooks = open_ebooks();
277
- if (e_book_get_self(&me, &eb, &gerr) == FALSE) {
278
+ if (e_book_client_get_self(registry, &me, &eb, &gerr) == FALSE) {
282
@@ -688,6 +675,7 @@ void *phonebook_create_cache(const char *name, phonebook_entry_cb entry_cb,
286
+ g_object_unref(registry);
289
for (l = data->ebooks; l != NULL; l = g_slist_next(l)) {