1 From 091f0e00bae058d384fbc9834a402192bbf192a6 Mon Sep 17 00:00:00 2001
2 From: Matthew Barnes <mbarnes@redhat.com>
3 Date: Sat, 29 Dec 2012 21:14:51 +0100
4 Subject: [PATCH] Adapt to Evolution-Data-Server API changes
6 Closes: https://bugzilla.gnome.org/show_bug.cgi?id=680927
9 cut-n-paste/e-contact-entry/e-contact-entry.c | 168 +++++++++++---------------
10 cut-n-paste/e-contact-entry/e-contact-entry.h | 8 +-
11 libgsm/phonemgr-utils.c | 2 +-
12 src/e-phone-entry.c | 38 +++---
13 5 files changed, 96 insertions(+), 122 deletions(-)
15 diff --git a/configure.in b/configure.in
16 index be5e729..73e7aec 100644
19 @@ -47,7 +47,7 @@ PKG_CHECK_MODULES(LIBGSM, glib-2.0 gobject-2.0 $GNOKII_REQS gthread-2.0 bluez $e
21 PKG_CHECK_MODULES(PHONEMGR, gtk+-3.0 >= 3.0 glib-2.0 >= 2.31.0
22 libcanberra-gtk3 gconf-2.0
23 - $GNOME_BLUETOOTH_REQS $evo_pc_file libedataserverui-3.0
24 + $GNOME_BLUETOOTH_REQS $evo_pc_file libedataserver-1.2 >= 3.6
25 gmodule-2.0 dbus-glib-1 gnome-icon-theme >= 2.19.1
28 diff --git a/cut-n-paste/e-contact-entry/e-contact-entry.c b/cut-n-paste/e-contact-entry/e-contact-entry.c
29 index dc8e2e3..bbd4e6a 100644
30 --- a/cut-n-paste/e-contact-entry/e-contact-entry.c
31 +++ b/cut-n-paste/e-contact-entry/e-contact-entry.c
35 * Copyright (C) 2004 Ross Burton <ross@burtonini.com
40 #include <glib/gi18n.h>
42 -#include <libedataserver/e-source.h>
43 -#include <libebook/e-book.h>
44 -#include <libebook/e-book-view.h>
45 -#include <libebook/e-contact.h>
47 #include "e-contact-entry.h"
48 #include "econtactentry-marshal.h"
50 @@ -59,7 +54,7 @@ static int signals[LAST_SIGNAL] = { 0 };
53 PROP_0, /* TODO: why? */
59 @@ -70,7 +65,7 @@ enum {
60 struct EContactEntryPriv {
61 GtkEntryCompletion *completion;
63 - ESourceList *source_list;
64 + ESourceRegistry *registry;
65 /* A list of EntryLookup structs we are searching */
66 GList *lookup_entries;
67 /* Number of characters to start searching at */
68 @@ -227,7 +222,7 @@ e_contact_entry_display_func (EContact *contact)
69 emails = e_contact_get (contact, E_CONTACT_EMAIL);
70 for (l = emails; l != NULL; l = l->next) {
71 item = g_new0 (EContactEntyItem, 1);
72 - item->identifier = item->identifier = g_strdup (l->data);
73 + item->identifier = g_strdup (l->data);
74 item->display_string = g_strdup_printf ("%s <%s>", (char*)e_contact_get_const (contact, E_CONTACT_NAME_OR_ORG), item->identifier);
76 items = g_list_prepend (items, item);
77 @@ -276,22 +271,13 @@ view_contacts_added_cb (EBook *book, GList *contacts, gpointer user_data)
80 photo = e_contact_get (contact, E_CONTACT_PHOTO);
81 -#ifndef HAVE_ECONTACTPHOTOTYPE
84 if (photo && photo->type == E_CONTACT_PHOTO_TYPE_INLINED) {
86 GdkPixbufLoader *loader;
88 loader = gdk_pixbuf_loader_new ();
90 -#ifndef HAVE_ECONTACTPHOTOTYPE
91 - if (gdk_pixbuf_loader_write (loader, (guchar *)photo->data,
92 - photo->length, NULL))
94 if (gdk_pixbuf_loader_write (loader, (guchar *)photo->data.inlined.data,
95 photo->data.inlined.length, NULL))
97 pixbuf = gdk_pixbuf_loader_get_pixbuf (loader);
100 @@ -339,16 +325,15 @@ view_contacts_added_cb (EBook *book, GList *contacts, gpointer user_data)
101 * The query on the EBookView has completed.
104 -view_completed_cb (EBookView *book_view, EBookViewStatus status, gpointer user_data)
105 +view_completed_cb (EBookView *book_view, EBookViewStatus status, const gchar *message, gpointer user_data)
108 g_return_if_fail (user_data != NULL);
109 - /* TODO: handle status != OK */
110 - g_return_if_fail (status == E_BOOK_ERROR_OK);
111 g_return_if_fail (book_view != NULL);
113 lookup = (EntryLookup*)user_data;
114 g_object_unref (lookup->bookview);
115 + lookup->bookview = NULL;
119 @@ -361,9 +346,9 @@ bookview_cb (EBook *book, EBookStatus status, EBookView *book_view, gpointer clo
120 /* TODO: handle status != OK */
121 g_return_if_fail (status == E_BOOK_ERROR_OK);
122 g_return_if_fail (closure != NULL);
125 lookup = (EntryLookup*)closure;
128 g_object_ref (book_view);
129 /* This shouldn't happen of course */
130 if (lookup->bookview) {
131 @@ -372,10 +357,10 @@ bookview_cb (EBook *book, EBookStatus status, EBookView *book_view, gpointer clo
133 lookup->bookview = book_view;
134 g_object_add_weak_pointer ((GObject*)book_view, (gpointer*)&lookup->bookview);
136 - g_signal_connect (book_view, "contacts_added", (GCallback)view_contacts_added_cb, lookup);
137 - g_signal_connect (book_view, "sequence_complete", (GCallback)view_completed_cb, lookup);
140 + g_signal_connect (book_view, "contacts-added", (GCallback)view_contacts_added_cb, lookup);
141 + g_signal_connect (book_view, "view_complete", (GCallback)view_completed_cb, lookup);
143 e_book_view_start (book_view);
146 @@ -396,9 +381,10 @@ entry_changed_cb (GtkEditable *editable, gpointer user_data)
147 if (lookup->bookview) {
148 e_book_view_stop (lookup->bookview);
149 g_object_unref (lookup->bookview);
150 + lookup->bookview = NULL;
155 gtk_list_store_clear (entry->priv->store);
157 query = create_query (entry, gtk_editable_get_chars (editable, 0, -1));
158 @@ -409,8 +395,8 @@ entry_changed_cb (GtkEditable *editable, gpointer user_data)
159 /* If the book isn't open yet, skip this source */
163 - if (e_book_async_get_book_view (lookup->book, query, NULL, 11, (EBookBookViewCallback)bookview_cb, lookup) != 0) {
165 + if (e_book_async_get_book_view (lookup->book, query, NULL, MAX_ENTRIES, (EBookBookViewCallback)bookview_cb, lookup) == FALSE) {
166 g_signal_emit (entry, signals[ERROR], 0, _("Cannot create searchable view."));
169 @@ -441,7 +427,7 @@ book_opened_cb (EBook *book, EBookStatus status, gpointer data)
175 g_signal_emit (lookup->entry, signals[STATE_CHANGE], 0, FALSE);
176 g_signal_emit (lookup->entry, signals[ERROR], 0, stringify_ebook_error (status));
178 @@ -458,11 +444,12 @@ book_opened_cb (EBook *book, EBookStatus status, gpointer data)
182 -e_contact_entry_set_source_list (EContactEntry *entry,
183 - ESourceList *source_list)
184 +e_contact_entry_set_registry (EContactEntry *entry,
185 + ESourceRegistry *registry)
187 + GList *list, *link;
188 + const gchar *extension_name;
189 GError *error = NULL;
192 g_return_if_fail (E_IS_CONTACT_ENTRY (entry));
194 @@ -471,58 +458,48 @@ e_contact_entry_set_source_list (EContactEntry *entry,
195 g_list_foreach (entry->priv->lookup_entries, (GFunc)lookup_entry_free, NULL);
196 g_list_free (entry->priv->lookup_entries);
198 - if (entry->priv->source_list) {
199 - g_object_unref (entry->priv->source_list);
200 + if (entry->priv->registry) {
201 + g_object_unref (entry->priv->registry);
204 /* If we have no new sources, disable and return here */
205 - if (source_list == NULL) {
206 + if (registry == NULL) {
207 g_signal_emit (entry, signals[STATE_CHANGE], 0, FALSE);
208 - entry->priv->source_list = NULL;
209 + entry->priv->registry = NULL;
210 entry->priv->lookup_entries = NULL;
214 - entry->priv->source_list = source_list;
215 - /* So that the list isn't going away underneath us */
216 - g_object_ref (entry->priv->source_list);
217 + entry->priv->registry = registry;
218 + /* So that the registry isn't going away underneath us */
219 + g_object_ref (entry->priv->registry);
221 - /* That gets us a list of ESourceGroup */
222 - list = e_source_list_peek_groups (source_list);
223 entry->priv->lookup_entries = NULL;
225 - for (l = list; l != NULL; l = l->next) {
226 - ESourceGroup *group = l->data;
227 - GSList *sources = NULL, *m;
228 - /* That should give us a list of ESource */
229 - sources = e_source_group_peek_sources (group);
230 - for (m = sources; m != NULL; m = m->next) {
231 - ESource *source = m->data;
232 - ESource *s = e_source_copy (source);
233 - EntryLookup *lookup;
235 + extension_name = E_SOURCE_EXTENSION_ADDRESS_BOOK;
236 + list = e_source_registry_list_sources (registry, extension_name);
238 - uri = g_strdup_printf("%s/%s", e_source_group_peek_base_uri (group), e_source_peek_relative_uri (source));
239 - e_source_set_absolute_uri (s, uri);
241 + for (link = list; link != NULL; link = g_list_next (link)) {
242 + ESource *source = E_SOURCE (link->data);
243 + EntryLookup *lookup;
245 - /* Now add those to the lookup entries list */
246 - lookup = g_new0 (EntryLookup, 1);
247 - lookup->entry = entry;
248 - lookup->status = E_BOOK_ERROR_OK;
249 - lookup->open = FALSE;
250 + /* Now add those to the lookup entries list */
251 + lookup = g_new0 (EntryLookup, 1);
252 + lookup->entry = entry;
253 + lookup->status = E_BOOK_ERROR_OK;
254 + lookup->open = FALSE;
256 - if ((lookup->book = e_book_new (s, &error)) == NULL) {
257 - /* TODO handle this better, fire the error signal I guess */
258 + if ((lookup->book = e_book_new (source, &error)) == NULL) {
259 + /* TODO handle this better, fire the error signal I guess */
261 g_warning ("%s", error->message);
262 - g_error_free (error);
265 - entry->priv->lookup_entries = g_list_append (entry->priv->lookup_entries, lookup);
266 - e_book_async_open(lookup->book, TRUE, (EBookCallback)book_opened_cb, lookup);
267 + g_error_free (error);
271 - g_object_unref (s);
274 + entry->priv->lookup_entries = g_list_append (entry->priv->lookup_entries, lookup);
275 + e_book_async_open(lookup->book, TRUE, (EBookCallback)book_opened_cb, lookup);
279 @@ -530,12 +507,12 @@ e_contact_entry_set_source_list (EContactEntry *entry,
280 g_signal_emit (entry, signals[STATE_CHANGE], 0, FALSE);
284 -e_contact_entry_get_source_list (EContactEntry *entry)
286 +e_contact_entry_get_registry (EContactEntry *entry)
288 g_return_val_if_fail (E_IS_CONTACT_ENTRY (entry), NULL);
290 - return entry->priv->source_list;
291 + return entry->priv->registry;
295 @@ -552,7 +529,7 @@ int
296 e_contact_entry_get_complete_length (EContactEntry *entry)
298 g_return_val_if_fail (E_IS_CONTACT_ENTRY (entry), 3); /* TODO: from paramspec? */
301 return entry->priv->lookup_length;
304 @@ -564,7 +541,7 @@ e_contact_entry_set_display_func (EContactEntry *entry, EContactEntryDisplayFunc
305 if (entry->priv->display_destroy) {
306 entry->priv->display_destroy (entry->priv->display_func);
310 entry->priv->display_func = func;
311 entry->priv->display_data = func_data;
312 entry->priv->display_destroy = destroy;
313 @@ -596,13 +573,13 @@ static void
314 e_contact_entry_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
316 EContactEntry *entry;
319 g_return_if_fail (E_IS_CONTACT_ENTRY (object));
320 entry = E_CONTACT_ENTRY (object);
323 switch (property_id) {
324 - case PROP_SOURCE_LIST:
325 - e_contact_entry_set_source_list (entry, g_value_get_object (value));
326 + case PROP_REGISTRY:
327 + e_contact_entry_set_registry (entry, g_value_get_object (value));
329 case PROP_COMPLETE_LENGTH:
330 e_contact_entry_set_complete_length (entry, g_value_get_int (value));
331 @@ -618,10 +595,10 @@ e_contact_entry_get_property (GObject *object, guint property_id, GValue *value,
332 EContactEntry *entry;
333 g_return_if_fail (E_IS_CONTACT_ENTRY (object));
334 entry = E_CONTACT_ENTRY (object);
337 switch (property_id) {
338 - case PROP_SOURCE_LIST:
339 - g_value_set_object (value, e_contact_entry_get_source_list (entry));
340 + case PROP_REGISTRY:
341 + g_value_set_object (value, e_contact_entry_get_registry (entry));
343 case PROP_COMPLETE_LENGTH:
344 g_value_set_int (value, e_contact_entry_get_complete_length (entry));
345 @@ -644,7 +621,7 @@ e_contact_entry_finalize (GObject *object)
346 g_list_free (entry->priv->lookup_entries);
347 g_object_unref (entry->priv->completion);
348 g_object_unref (entry->priv->store);
349 - g_object_unref (entry->priv->source_list);
350 + g_object_unref (entry->priv->registry);
352 if (entry->priv->display_destroy) {
353 entry->priv->display_destroy (entry->priv->display_func);
354 @@ -657,7 +634,7 @@ e_contact_entry_finalize (GObject *object)
356 reset_search_fields (EContactEntry *entry)
358 - EContactField fields[] = { E_CONTACT_FULL_NAME, E_CONTACT_EMAIL, E_CONTACT_NICKNAME, E_CONTACT_ORG, 0 };
359 + EContactField fields[] = { E_CONTACT_FULL_NAME, E_CONTACT_EMAIL, E_CONTACT_NICKNAME, 0 };
361 g_free (entry->priv->search_fields);
362 entry->priv->search_fields = g_new0 (EContactField, G_N_ELEMENTS (fields));
363 @@ -707,23 +684,23 @@ static void
364 e_contact_entry_class_init (EContactEntryClass *klass)
366 GObjectClass *object_class;
369 object_class = (GObjectClass *) klass;
373 object_class->set_property = e_contact_entry_set_property;
374 object_class->get_property = e_contact_entry_get_property;
375 object_class->finalize = e_contact_entry_finalize;
378 - g_object_class_install_property (object_class, PROP_SOURCE_LIST,
379 - g_param_spec_object ("source-list", "Source List", "The source list to search for contacts.",
380 - E_TYPE_SOURCE_LIST, G_PARAM_READWRITE));
382 + g_object_class_install_property (object_class, PROP_REGISTRY,
383 + g_param_spec_object ("registry", "Registry", "Data source registry.",
384 + E_TYPE_SOURCE_REGISTRY, G_PARAM_READWRITE));
386 g_object_class_install_property (object_class, PROP_COMPLETE_LENGTH,
387 g_param_spec_int ("complete-length", "Complete length", "Number of characters to start a search on.",
388 2, 99, 3, G_PARAM_READWRITE));
392 signals[CONTACT_SELECTED] = g_signal_new ("contact-selected",
393 G_TYPE_FROM_CLASS (object_class),
394 @@ -732,7 +709,7 @@ e_contact_entry_class_init (EContactEntryClass *klass)
396 econtactentry_marshal_VOID__OBJECT_STRING,
397 G_TYPE_NONE, 2, E_TYPE_CONTACT, G_TYPE_STRING);
400 signals[ERROR] = g_signal_new ("error",
401 G_TYPE_FROM_CLASS (object_class),
403 @@ -771,6 +748,7 @@ lookup_entry_free (EntryLookup *lookup)
404 if (lookup->bookview) {
405 g_warning("EBookView still around");
406 g_object_unref (lookup->bookview);
407 + lookup->bookview = NULL;
410 g_object_unref (lookup->book);
411 @@ -789,11 +767,11 @@ split_query_string (const gchar *str)
412 GArray *parts = g_array_sized_new (FALSE, FALSE, sizeof (char *), 2);
414 guint str_len = strlen (str), word_start = 0, i;
416 - attrs = g_new0 (PangoLogAttr, str_len + 1);
418 + attrs = g_new0 (PangoLogAttr, str_len + 1);
419 /* TODO: do we need to specify a particular language or is NULL ok? */
420 pango_get_log_attrs (str, -1, -1, NULL, attrs, str_len + 1);
423 for (i = 0; i < str_len + 1; i++) {
424 char *start_word, *end_word, *word;
425 if (attrs[i].is_word_end) {
426 diff --git a/cut-n-paste/e-contact-entry/e-contact-entry.h b/cut-n-paste/e-contact-entry/e-contact-entry.h
427 index bf6b39b..6fedef7 100644
428 --- a/cut-n-paste/e-contact-entry/e-contact-entry.h
429 +++ b/cut-n-paste/e-contact-entry/e-contact-entry.h
431 #ifndef CONTACT_ENTRY_H
432 #define CONTACT_ENTRY_H
434 -#include <libedataserver/e-source-group.h>
435 -#include <libedataserver/e-source-list.h>
436 -#include <libebook/e-contact.h>
438 +#include <libebook/libebook.h>
442 @@ -71,8 +69,8 @@ GType e_contact_entry_get_type (void);
444 GtkWidget *e_contact_entry_new (void);
446 -void e_contact_entry_set_source_list (EContactEntry *entry, ESourceList *list);
447 -ESourceList *e_contact_entry_get_source_list (EContactEntry *entry);
448 +void e_contact_entry_set_registry (EContactEntry *entry, ESourceRegistry *registry);
449 +ESourceRegistry *e_contact_entry_get_registry (EContactEntry *entry);
451 void e_contact_entry_set_complete_length(EContactEntry *entry, int length);
452 int e_contact_entry_get_complete_length(EContactEntry *entry);
453 diff --git a/libgsm/phonemgr-utils.c b/libgsm/phonemgr-utils.c
454 index 4e62e10..baef34f 100644
455 --- a/libgsm/phonemgr-utils.c
456 +++ b/libgsm/phonemgr-utils.c
459 #include <glib/gstdio.h>
460 #include <glib-object.h>
461 -#include <libebook/e-contact.h>
462 +#include <libebook/libebook.h>
465 #include <bluetooth/bluetooth.h>
466 diff --git a/src/e-phone-entry.c b/src/e-phone-entry.c
467 index 5d25622..5c10155 100644
468 --- a/src/e-phone-entry.c
469 +++ b/src/e-phone-entry.c
471 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
474 * Copyright (C) 2005 Bastien Nocera <hadess@hadess.net>
481 -#include <libedataserver/e-source-list.h>
482 -#include <libedataserverui/e-client-utils.h>
483 #include "e-phone-entry.h"
485 #define CONTACT_FORMAT "%s (%s)"
486 @@ -181,25 +179,25 @@ e_phone_entry_finalize (GObject *object)
490 -add_sources (EContactEntry *entry)
492 - ESourceList *source_list;
494 - if (e_client_utils_get_sources (&source_list,
495 - E_CLIENT_SOURCE_TYPE_CONTACTS,
497 - e_contact_entry_set_source_list (E_CONTACT_ENTRY (entry),
499 - g_object_unref (source_list);
504 e_phone_entry_init (EPhoneEntry *entry)
506 EContactField fields[] = { E_CONTACT_FULL_NAME, E_CONTACT_NICKNAME, E_CONTACT_ORG, E_CONTACT_PHONE_MOBILE, 0 };
507 + ESourceRegistry *registry;
508 + GError *error = NULL;
510 + /* XXX This call blocks while a D-Bus connection is made, possibly
511 + * requiring activation. Might be better to create the registry
512 + * in main(), pass it to ui_init(), and have e_phone_entry_new()
513 + * take it as an argument. Calling this from main() means if it
514 + * fails you can abort cleanly with a console error message. */
515 + registry = e_source_registry_new_sync (NULL, &error);
516 + if (registry == NULL) {
517 + g_error ("%s: %s", G_STRFUNC, error->message);
518 + g_assert_not_reached ();
520 + e_contact_entry_set_registry (E_CONTACT_ENTRY (entry), registry);
521 + g_object_unref (registry);
523 - add_sources (E_CONTACT_ENTRY (entry));
524 e_contact_entry_set_search_fields (E_CONTACT_ENTRY (entry), (const EContactField *)fields);
525 e_contact_entry_set_display_func (E_CONTACT_ENTRY (entry), test_display_func, NULL, NULL);
526 g_signal_connect (G_OBJECT (entry), "contact_selected",
527 @@ -212,9 +210,9 @@ static void
528 e_phone_entry_class_init (EPhoneEntryClass *klass)
530 GObjectClass *object_class;
533 object_class = (GObjectClass *) klass;
537 object_class->finalize = e_phone_entry_finalize;