[evolution-data-server/account-mgmt: 17/26] Add an ESource extension for the contacts backend.



commit 33b4fd9f186b4a8198c397bb3a0c510f45d4830e
Author: Matthew Barnes <mbarnes redhat com>
Date:   Tue Nov 23 08:35:40 2010 -0500

    Add an ESource extension for the contacts backend.

 calendar/backends/contacts/Makefile.am             |    4 +-
 .../contacts/e-cal-backend-contacts-factory.c      |   84 +--
 .../backends/contacts/e-cal-backend-contacts.c     |  658 ++++++++------------
 calendar/backends/contacts/e-source-contacts.c     |  139 ++++
 calendar/backends/contacts/e-source-contacts.h     |   70 ++
 5 files changed, 523 insertions(+), 432 deletions(-)
---
diff --git a/calendar/backends/contacts/Makefile.am b/calendar/backends/contacts/Makefile.am
index f386ed7..3e96250 100644
--- a/calendar/backends/contacts/Makefile.am
+++ b/calendar/backends/contacts/Makefile.am
@@ -15,7 +15,9 @@ libecalbackendcontacts_la_SOURCES =		\
 	e-cal-backend-contacts-factory.c	\
 	e-cal-backend-contacts-factory.h	\
 	e-cal-backend-contacts.c		\
-	e-cal-backend-contacts.h
+	e-cal-backend-contacts.h		\
+	e-source-contacts.c			\
+	e-source-contacts.h
 
 libecalbackendcontacts_la_LIBADD =						\
 	$(top_builddir)/calendar/libecal/libecal-1.2.la				\
diff --git a/calendar/backends/contacts/e-cal-backend-contacts-factory.c b/calendar/backends/contacts/e-cal-backend-contacts-factory.c
index 6c75b53..9bbcef3 100644
--- a/calendar/backends/contacts/e-cal-backend-contacts-factory.c
+++ b/calendar/backends/contacts/e-cal-backend-contacts-factory.c
@@ -15,19 +15,18 @@
 
 #include "e-cal-backend-contacts-factory.h"
 #include "e-cal-backend-contacts.h"
+#include "e-source-contacts.h"
 
-typedef struct {
-	ECalBackendFactory            parent_object;
-} ECalBackendContactsFactory;
+typedef ECalBackendFactory ECalBackendContactsEventsFactory;
+typedef ECalBackendFactoryClass ECalBackendContactsEventsFactoryClass;
 
-typedef struct {
-	ECalBackendFactoryClass parent_class;
-} ECalBackendContactsFactoryClass;
+/* Forward Declarations */
+GType e_cal_backend_contacts_events_factory_get_type (void);
 
-static void
-e_cal_backend_contacts_factory_instance_init (ECalBackendContactsFactory *factory)
-{
-}
+G_DEFINE_DYNAMIC_TYPE (
+	ECalBackendContactsEventsFactory,
+	e_cal_backend_contacts_events_factory,
+	E_TYPE_CAL_BACKEND_FACTORY)
 
 static const gchar *
 _get_protocol (ECalBackendFactory *factory)
@@ -35,13 +34,14 @@ _get_protocol (ECalBackendFactory *factory)
 	return "contacts";
 }
 
-static ECalBackend*
-_events_new_backend (ECalBackendFactory *factory, ESource *source)
+static ECalBackend *
+_events_new_backend (ECalBackendFactory *factory,
+                     ESource *source)
 {
-	return g_object_new (e_cal_backend_contacts_get_type (),
-			     "source", source,
-			     "kind", ICAL_VEVENT_COMPONENT,
-			     NULL);
+	return g_object_new (
+		e_cal_backend_contacts_get_type (),
+		"kind", ICAL_VEVENT_COMPONENT,
+		"source", source, NULL);
 }
 
 static icalcomponent_kind
@@ -51,56 +51,42 @@ _events_get_kind (ECalBackendFactory *factory)
 }
 
 static void
-events_backend_factory_class_init (ECalBackendContactsFactoryClass *klass)
+e_cal_backend_contacts_events_factory_class_init (ECalBackendFactoryClass *class)
 {
-	E_CAL_BACKEND_FACTORY_CLASS (klass)->get_protocol = _get_protocol;
-	E_CAL_BACKEND_FACTORY_CLASS (klass)->get_kind     = _events_get_kind;
-	E_CAL_BACKEND_FACTORY_CLASS (klass)->new_backend  = _events_new_backend;
+	class->get_protocol = _get_protocol;
+	class->get_kind     = _events_get_kind;
+	class->new_backend  = _events_new_backend;
 }
 
-static GType
-events_backend_factory_get_type (GTypeModule *module)
+static void
+e_cal_backend_contacts_events_factory_class_finalize (ECalBackendFactoryClass *class)
 {
-	GType type;
-
-	GTypeInfo info = {
-		sizeof (ECalBackendContactsFactoryClass),
-		NULL, /* base_class_init */
-		NULL, /* base_class_finalize */
-		(GClassInitFunc)  events_backend_factory_class_init,
-		NULL, /* class_finalize */
-		NULL, /* class_data */
-		sizeof (ECalBackend),
-		0,    /* n_preallocs */
-		(GInstanceInitFunc) e_cal_backend_contacts_factory_instance_init
-	};
-
-	type = g_type_module_register_type (module,
-					    E_TYPE_CAL_BACKEND_FACTORY,
-					    "ECalBackendContactsEventsFactory",
-					    &info, 0);
-
-	return type;
 }
 
-
-
-static GType contacts_types[1];
+static void
+e_cal_backend_contacts_events_factory_init (ECalBackendFactory *factory)
+{
+}
 
 void
-eds_module_initialize (GTypeModule *module)
+eds_module_initialize (GTypeModule *type_module)
 {
-	contacts_types[0] = events_backend_factory_get_type (module);
+	e_source_contacts_type_register (type_module);
+	e_cal_backend_contacts_events_factory_register_type (type_module);
 }
 
 void
-eds_module_shutdown   (void)
+eds_module_shutdown (void)
 {
 }
 
 void
 eds_module_list_types (const GType **types, gint *num_types)
 {
+	static GType contacts_types[1];
+
+	contacts_types[0] = e_cal_backend_contacts_events_factory_get_type ();
+
 	*types = contacts_types;
-	*num_types = 1;
+	*num_types = G_N_ELEMENTS (contacts_types);
 }
diff --git a/calendar/backends/contacts/e-cal-backend-contacts.c b/calendar/backends/contacts/e-cal-backend-contacts.c
index fdad612..f122353 100644
--- a/calendar/backends/contacts/e-cal-backend-contacts.c
+++ b/calendar/backends/contacts/e-cal-backend-contacts.c
@@ -32,16 +32,17 @@
 
 #include <glib/gi18n-lib.h>
 #include <gconf/gconf-client.h>
-#include "libedataserver/e-xml-hash-utils.h"
-#include "libedataserver/e-flag.h"
+#include <libedataserver/e-xml-hash-utils.h>
+#include <libedataserver/e-source-registry.h>
+#include <libedataserver/e-flag.h>
 #include <libecal/e-cal-recur.h>
 #include <libecal/e-cal-util.h>
 #include <libedata-cal/e-cal-backend-util.h>
 #include <libedata-cal/e-cal-backend-sexp.h>
-
 #include <libebook/e-book.h>
+#include <libebook/e-source-address-book.h>
 
-#include "libedataserver/e-source-list.h"
+#include "e-source-contacts.h"
 
 #define EDC_ERROR(_code) e_data_cal_create_error (_code, NULL)
 
@@ -58,19 +59,16 @@ typedef enum
 
 /* Private part of the ECalBackendContacts structure */
 struct _ECalBackendContactsPrivate {
-        ESourceList  *addressbook_sources;
 
-        GHashTable   *addressbooks;       /* UID -> BookRecord */
-        gboolean      addressbook_loaded;
+	GHashTable   *addressbooks;       /* UID -> BookRecord */
+	gboolean      addressbook_loaded;
 
-        EBookView    *book_view;
-        GHashTable   *tracked_contacts;   /* UID -> ContactRecord */
+	EBookView    *book_view;
+	GHashTable   *tracked_contacts;   /* UID -> ContactRecord */
 
 	GHashTable *zones;
 	icaltimezone *default_zone;
 
-	EFlag   *init_done_flag; /* is set, when the init thread gone */
-
 	/* properties related to track alarm settings for this backend */
 	GConfClient *conf_client;
 	guint notifyid1;
@@ -84,15 +82,15 @@ struct _ECalBackendContactsPrivate {
 
 typedef struct _BookRecord {
 	ECalBackendContacts *cbc;
-        EBook     *book;
-        EBookView *book_view;
+	EBook     *book;
+	EBookView *book_view;
 } BookRecord;
 
 typedef struct _ContactRecord {
-        ECalBackendContacts *cbc;
-	EBook               *book; /* where it comes from */
-        EContact            *contact;
-        ECalComponent       *comp_birthday, *comp_anniversary;
+	ECalBackendContacts *cbc;
+	EBook	       *book; /* where it comes from */
+	EContact	    *contact;
+	ECalComponent       *comp_birthday, *comp_anniversary;
 } ContactRecord;
 
 #define d(x)
@@ -113,56 +111,57 @@ static void setup_alarm (ECalBackendContacts *cbc, ECalComponent *comp);
 static BookRecord *
 book_record_new (ECalBackendContacts *cbc, ESource *source)
 {
-        EBook      *book;
-        GList      *fields = NULL;
-        EBookQuery *query;
-        EBookView  *book_view;
-        BookRecord *br;
+	EBook      *book;
+	GList      *fields = NULL;
+	EBookQuery *query;
+	EBookView  *book_view;
+	BookRecord *br;
 	GError     *error = NULL;
 
 	book = e_book_new (source, &error);
-        if (!book || !e_book_open (book, TRUE, &error) || error) {
-		g_warning ("%s: Failed to open book '%s': %s", G_STRFUNC, e_source_peek_name (source), error ? error->message : "Unknown error");
+	if (!book || !e_book_open (book, TRUE, &error) || error) {
 		if (book)
 			g_object_unref (book);
-		if (error)
+		if (error) {
+			g_warning ("%s: Failed to open book, error: %s", G_STRFUNC, error->message);
 			g_error_free (error);
+		}
 		return NULL;
 	}
 
-        /* Create book view */
-        fields = g_list_append (fields, (gchar *)e_contact_field_name (E_CONTACT_FILE_AS));
-        fields = g_list_append (fields, (gchar *)e_contact_field_name (E_CONTACT_BIRTH_DATE));
-        fields = g_list_append (fields, (gchar *)e_contact_field_name (E_CONTACT_ANNIVERSARY));
-        query = e_book_query_any_field_contains ("");
+	/* Create book view */
+	fields = g_list_append (fields, (gchar *)e_contact_field_name (E_CONTACT_FILE_AS));
+	fields = g_list_append (fields, (gchar *)e_contact_field_name (E_CONTACT_BIRTH_DATE));
+	fields = g_list_append (fields, (gchar *)e_contact_field_name (E_CONTACT_ANNIVERSARY));
+	query = e_book_query_any_field_contains ("");
 
-        if (!e_book_get_book_view (book, query, fields, -1, &book_view, &error)) {
-		g_warning ("%s: Failed to get book view on '%s': %s", G_STRFUNC, e_source_peek_name (source), error ? error->message : "Unknown error");
+	if (!e_book_get_book_view (book, query, fields, -1, &book_view, NULL)) {
+		g_warning ("%s: Failed to get book view on '%s': %s", G_STRFUNC, e_source_get_display_name (source), error ? error->message : "Unknown error");
 
-                e_book_query_unref (query);
-                g_object_unref (book);
-                g_list_free (fields);
+		e_book_query_unref (query);
+		g_object_unref (book);
+		g_list_free (fields);
 
 		if (error)
 			g_error_free (error);
 
-                return NULL;
-        }
-        e_book_query_unref (query);
+		return NULL;
+	}
+	e_book_query_unref (query);
 	g_list_free (fields);
 
-        g_signal_connect (book_view, "contacts_added", G_CALLBACK (contacts_added_cb), cbc);
-        g_signal_connect (book_view, "contacts_removed", G_CALLBACK (contacts_removed_cb), cbc);
-        g_signal_connect (book_view, "contacts_changed", G_CALLBACK (contacts_changed_cb), cbc);
+	g_signal_connect (book_view, "contacts_added", G_CALLBACK (contacts_added_cb), cbc);
+	g_signal_connect (book_view, "contacts_removed", G_CALLBACK (contacts_removed_cb), cbc);
+	g_signal_connect (book_view, "contacts_changed", G_CALLBACK (contacts_changed_cb), cbc);
 
-        e_book_view_start (book_view);
+	e_book_view_start (book_view);
 
-        br = g_new (BookRecord, 1);
+	br = g_new (BookRecord, 1);
 	br->cbc = cbc;
-        br->book = book;
-        br->book_view = book_view;
+	br->book = book;
+	br->book_view = book_view;
 
-        return br;
+	return br;
 }
 
 static gboolean
@@ -177,28 +176,28 @@ remove_by_book (gpointer key, gpointer value, gpointer user_data)
 static void
 book_record_free (BookRecord *br)
 {
-        if (!br)
-                return;
+	if (!br)
+		return;
 
 	g_hash_table_foreach_remove (br->cbc->priv->tracked_contacts, remove_by_book, br->book);
-        g_object_unref (br->book_view);
-        g_object_unref (br->book);
+	g_object_unref (br->book_view);
+	g_object_unref (br->book);
 
-        g_free (br);
+	g_free (br);
 }
 
 /* ContactRecord methods */
 static ContactRecord *
 contact_record_new (ECalBackendContacts *cbc, EBook *book, EContact *contact)
 {
-        ContactRecord *cr = g_new0 (ContactRecord, 1);
+	ContactRecord *cr = g_new0 (ContactRecord, 1);
 	gchar *comp_str;
 
-        cr->cbc = cbc;
+	cr->cbc = cbc;
 	cr->book = book;
-        cr->contact = contact;
-        cr->comp_birthday = create_birthday (cbc, contact);
-        cr->comp_anniversary = create_anniversary (cbc, contact);
+	cr->contact = contact;
+	cr->comp_birthday = create_birthday (cbc, contact);
+	cr->comp_anniversary = create_anniversary (cbc, contact);
 
 	if (cr->comp_birthday) {
 		comp_str = e_cal_component_get_as_string (cr->comp_birthday);
@@ -215,18 +214,18 @@ contact_record_new (ECalBackendContacts *cbc, EBook *book, EContact *contact)
 		g_free (comp_str);
 	}
 
-        g_object_ref (G_OBJECT (contact));
+	g_object_ref (G_OBJECT (contact));
 
-        return cr;
+	return cr;
 }
 
 static void
 contact_record_free (ContactRecord *cr)
 {
-        gchar *comp_str;
+	gchar *comp_str;
 	ECalComponentId *id;
 
-        g_object_unref (G_OBJECT (cr->contact));
+	g_object_unref (G_OBJECT (cr->contact));
 
 	/* Remove the birthday event */
 	if (cr->comp_birthday) {
@@ -251,173 +250,90 @@ contact_record_free (ContactRecord *cr)
 		g_object_unref (G_OBJECT (cr->comp_anniversary));
 	}
 
-        g_free (cr);
+	g_free (cr);
 }
 
 /* ContactRecordCB methods */
 typedef struct _ContactRecordCB {
-        ECalBackendContacts *cbc;
-        ECalBackendSExp     *sexp;
-        GList               *result;
+	ECalBackendContacts *cbc;
+	ECalBackendSExp *sexp;
+	GList *result;
 } ContactRecordCB;
 
 static ContactRecordCB *
 contact_record_cb_new (ECalBackendContacts *cbc, ECalBackendSExp *sexp)
 {
-        ContactRecordCB *cb_data = g_new (ContactRecordCB, 1);
+	ContactRecordCB *cb_data = g_new (ContactRecordCB, 1);
 
-        cb_data->cbc = cbc;
-        cb_data->sexp = sexp;
-        cb_data->result = NULL;
+	cb_data->cbc = cbc;
+	cb_data->sexp = sexp;
+	cb_data->result = NULL;
 
-        return cb_data;
+	return cb_data;
 }
 
 static void
 contact_record_cb_free (ContactRecordCB *cb_data)
 {
-        g_list_foreach (cb_data->result, (GFunc) g_free, NULL);
-        g_list_free (cb_data->result);
+	g_list_foreach (cb_data->result, (GFunc) g_free, NULL);
+	g_list_free (cb_data->result);
 
-        g_free (cb_data);
+	g_free (cb_data);
 }
 
 static void
 contact_record_cb (gpointer key, gpointer value, gpointer user_data)
 {
-        ContactRecordCB *cb_data = user_data;
-        ContactRecord   *record = value;
-
-        if (record->comp_birthday && e_cal_backend_sexp_match_comp (cb_data->sexp, record->comp_birthday, E_CAL_BACKEND (cb_data->cbc))) {
-                gchar * comp_str = e_cal_component_get_as_string (record->comp_birthday);
-                cb_data->result = g_list_append (cb_data->result, comp_str);
-        }
-
-        if (record->comp_anniversary && e_cal_backend_sexp_match_comp (cb_data->sexp, record->comp_anniversary, E_CAL_BACKEND (cb_data->cbc))) {
-                gchar * comp_str = e_cal_component_get_as_string (record->comp_anniversary);
-                cb_data->result = g_list_append (cb_data->result, comp_str);
-        }
-}
-
-static gboolean
-is_source_usable (ESource *source, ESourceGroup *group)
-{
-	const gchar *base_uri;
-	const gchar *prop;
-
-        base_uri = e_source_group_peek_base_uri (group);
-        if (!base_uri)
-                return FALSE;
-
-	prop = e_source_get_property (source, "use-in-contacts-calendar");
-
-	/* the later check is for backward compatibility */
-	return (prop && g_str_equal (prop, "1")) || (!prop && g_str_has_prefix (base_uri, "file://")) || (!prop && g_str_has_prefix (base_uri, "local:"));
-}
-
-/* SourceList callbacks */
-static void
-add_source (ECalBackendContacts *cbc, ESource *source)
-{
-        BookRecord *br = book_record_new (cbc, source);
-        const gchar *uid = e_source_peek_uid (source);
-
-	if (!br)
-		return;
-
-        g_hash_table_insert (cbc->priv->addressbooks, g_strdup (uid), br);
-}
-
-static void
-source_added_cb (ESourceGroup *group, ESource *source, gpointer user_data)
-{
-        ECalBackendContacts *cbc = E_CAL_BACKEND_CONTACTS (user_data);
-
-        g_return_if_fail (cbc);
+	ContactRecordCB *cb_data = user_data;
+	ContactRecord   *record = value;
 
-	if (is_source_usable (source, group))
-		add_source (cbc, source);
-}
-
-static void
-source_removed_cb (ESourceGroup *group, ESource *source, gpointer user_data)
-{
-        ECalBackendContacts *cbc = E_CAL_BACKEND_CONTACTS (user_data);
-        const gchar          *uid = e_source_peek_uid (source);
-
-        g_return_if_fail (cbc);
+	if (record->comp_birthday && e_cal_backend_sexp_match_comp (cb_data->sexp, record->comp_birthday, E_CAL_BACKEND (cb_data->cbc))) {
+		gchar * comp_str = e_cal_component_get_as_string (record->comp_birthday);
+		cb_data->result = g_list_append (cb_data->result, comp_str);
+	}
 
-        g_hash_table_remove (cbc->priv->addressbooks, uid);
+	if (record->comp_anniversary && e_cal_backend_sexp_match_comp (cb_data->sexp, record->comp_anniversary, E_CAL_BACKEND (cb_data->cbc))) {
+		gchar * comp_str = e_cal_component_get_as_string (record->comp_anniversary);
+		cb_data->result = g_list_append (cb_data->result, comp_str);
+	}
 }
 
 static void
-source_list_changed_cb (ESourceList *source_list, gpointer user_data)
+source_added_cb (ESourceRegistry *registry,
+                 ESource *source,
+                 ECalBackendContacts *cbc)
 {
-        ECalBackendContacts *cbc = E_CAL_BACKEND_CONTACTS (user_data);
-        GSList *g, *s;
+	ESourceContacts *extension;
+	const gchar *extension_name;
+	BookRecord *br;
+	const gchar *uid;
 
-        g_return_if_fail (cbc);
+	extension_name = E_SOURCE_EXTENSION_CONTACTS_BACKEND;
+	extension = e_source_get_extension (source, extension_name);
 
-	for (g = e_source_list_peek_groups (source_list); g; g = g->next) {
-		ESourceGroup *group = E_SOURCE_GROUP (g->data);
-
-		if (!group)
-			continue;
-
-		for (s = e_source_group_peek_sources (group); s; s = s->next) {
-			ESource *source = E_SOURCE (s->data);
-			const gchar *uid;
-
-			if (!source)
-				continue;
-
-			uid = e_source_peek_uid (source);
-			if (!uid)
-				continue;
-
-			if (is_source_usable (source, group)) {
-				if (!g_hash_table_lookup (cbc->priv->addressbooks, uid))
-					source_added_cb (group, source, cbc);
-			} else if (g_hash_table_lookup (cbc->priv->addressbooks, uid)) {
-				source_removed_cb (group, source, cbc);
-			}
-		}
-	}
-}
+	if (extension == NULL)
+		return;
 
-static void
-source_group_added_cb (ESourceList *source_list, ESourceGroup *group, gpointer user_data)
-{
-        ECalBackendContacts *cbc = E_CAL_BACKEND_CONTACTS (user_data);
-        GSList *i;
+	if (!e_source_contacts_get_include_me (extension))
+		return;
 
-        g_return_if_fail (cbc);
+	uid = e_source_get_uid (source);
+	br = book_record_new (cbc, source);
 
-	for (i = e_source_group_peek_sources (group); i; i = i->next) {
-		ESource *source = E_SOURCE (i->data);
-		source_added_cb (group, source, cbc);
-	}
+	if (br == NULL)
+		return;
 
-	/* Watch for future changes */
-	g_signal_connect (group, "source_added", G_CALLBACK (source_added_cb), cbc);
-	g_signal_connect (group, "source_removed", G_CALLBACK (source_removed_cb), cbc);
+	g_hash_table_insert (cbc->priv->addressbooks, g_strdup (uid), br);
 }
 
 static void
-source_group_removed_cb (ESourceList *source_list, ESourceGroup *group, gpointer user_data)
+source_removed_cb (ESourceRegistry *registry,
+                   ESource *source,
+                   ECalBackendContacts *cbc)
 {
-        ECalBackendContacts *cbc = E_CAL_BACKEND_CONTACTS (user_data);
-        GSList *i = NULL;
-
-        g_return_if_fail (cbc);
+	const gchar *uid = e_source_get_uid (source);
 
-        /* Unload all address books from this group */
-        for (i = e_source_group_peek_sources (group); i; i = i->next) {
-                ESource *source = E_SOURCE (i->data);
-                const gchar *uid = e_source_peek_uid (source);
-
-                g_hash_table_remove (cbc->priv->addressbooks, uid);
-        }
+	g_hash_table_remove (cbc->priv->addressbooks, uid);
 }
 
 /************************************************************************************/
@@ -425,70 +341,70 @@ source_group_removed_cb (ESourceList *source_list, ESourceGroup *group, gpointer
 static void
 contacts_changed_cb (EBookView *book_view, const GList *contacts, gpointer user_data)
 {
-        ECalBackendContacts *cbc = E_CAL_BACKEND_CONTACTS (user_data);
+	ECalBackendContacts *cbc = E_CAL_BACKEND_CONTACTS (user_data);
 	EBook *book = e_book_view_get_book (book_view);
-        const GList *i;
+	const GList *i;
 
-        for (i = contacts; i; i = i->next) {
-                EContact *contact = E_CONTACT (i->data);
-                const gchar *uid = e_contact_get_const (contact, E_CONTACT_UID);
-                EContactDate *birthday, *anniversary;
+	for (i = contacts; i; i = i->next) {
+		EContact *contact = E_CONTACT (i->data);
+		const gchar *uid = e_contact_get_const (contact, E_CONTACT_UID);
+		EContactDate *birthday, *anniversary;
 
-                /* Because this is a change of contact, then always remove old tracked data
+		/* Because this is a change of contact, then always remove old tracked data
 		   and if possible, add with (possibly) new values.
 		*/
 		g_hash_table_remove (cbc->priv->tracked_contacts, (gchar *)uid);
 
-                birthday = e_contact_get (contact, E_CONTACT_BIRTH_DATE);
-                anniversary = e_contact_get (contact, E_CONTACT_ANNIVERSARY);
+		birthday = e_contact_get (contact, E_CONTACT_BIRTH_DATE);
+		anniversary = e_contact_get (contact, E_CONTACT_ANNIVERSARY);
 
-                if (birthday || anniversary) {
-                        ContactRecord *cr = contact_record_new (cbc, book, contact);
-                        g_hash_table_insert (cbc->priv->tracked_contacts, g_strdup (uid), cr);
-                }
+		if (birthday || anniversary) {
+			ContactRecord *cr = contact_record_new (cbc, book, contact);
+			g_hash_table_insert (cbc->priv->tracked_contacts, g_strdup (uid), cr);
+		}
 
-                e_contact_date_free (birthday);
-                e_contact_date_free (anniversary);
-        }
+		e_contact_date_free (birthday);
+		e_contact_date_free (anniversary);
+	}
 }
 
 static void
 contacts_added_cb (EBookView *book_view, const GList *contacts, gpointer user_data)
 {
-        ECalBackendContacts *cbc = E_CAL_BACKEND_CONTACTS (user_data);
+	ECalBackendContacts *cbc = E_CAL_BACKEND_CONTACTS (user_data);
 	EBook *book = e_book_view_get_book (book_view);
-        const GList *i;
+	const GList *i;
 
-        /* See if any new contacts have BIRTHDAY or ANNIVERSARY fields */
-        for (i = contacts; i; i = i->next)
-        {
-                EContact *contact = E_CONTACT (i->data);
-                EContactDate *birthday, *anniversary;
+	/* See if any new contacts have BIRTHDAY or ANNIVERSARY fields */
+	for (i = contacts; i; i = i->next)
+	{
+		EContact *contact = E_CONTACT (i->data);
+		EContactDate *birthday, *anniversary;
 
-                birthday = e_contact_get (contact, E_CONTACT_BIRTH_DATE);
-                anniversary = e_contact_get (contact, E_CONTACT_ANNIVERSARY);
+		birthday = e_contact_get (contact, E_CONTACT_BIRTH_DATE);
+		anniversary = e_contact_get (contact, E_CONTACT_ANNIVERSARY);
 
-                if (birthday || anniversary) {
-                        ContactRecord *cr = contact_record_new (cbc, book, contact);
-                        const gchar    *uid = e_contact_get_const (contact, E_CONTACT_UID);
+		if (birthday || anniversary) {
+			ContactRecord *cr = contact_record_new (cbc, book, contact);
+			const gchar    *uid = e_contact_get_const (contact, E_CONTACT_UID);
 
-                        g_hash_table_insert (cbc->priv->tracked_contacts, g_strdup (uid), cr);
-                }
+			g_hash_table_insert (cbc->priv->tracked_contacts, g_strdup (uid), cr);
+		}
 
-                e_contact_date_free (birthday);
-                e_contact_date_free (anniversary);
-        }
+		e_contact_date_free (birthday);
+		e_contact_date_free (anniversary);
+	}
 }
 
 static void
 contacts_removed_cb (EBookView *book_view, const GList *contact_ids, gpointer user_data)
 {
-        ECalBackendContacts *cbc = E_CAL_BACKEND_CONTACTS (user_data);
-        const GList *i;
+	ECalBackendContacts *cbc = E_CAL_BACKEND_CONTACTS (user_data);
+	const GList *i;
 
-        /* Stop tracking these */
-        for (i = contact_ids; i; i = i->next)
-                g_hash_table_remove (cbc->priv->tracked_contacts, i->data);
+	/* Stop tracking these */
+	for (i = contact_ids; i; i = i->next)
+		g_hash_table_remove (cbc->priv->tracked_contacts, i->data);
 }
 
 /************************************************************************************/
@@ -534,16 +450,16 @@ static void
 update_alarm_cb (gpointer key, gpointer value, gpointer user_data)
 {
 	ECalBackendContacts *cbc = user_data;
-        ContactRecord   *record = value;
+	ContactRecord   *record = value;
 
 	g_return_if_fail (cbc != NULL);
 	g_return_if_fail (record != NULL);
 
-        if (record->comp_birthday)
+	if (record->comp_birthday)
 		manage_comp_alarm_update (cbc, record->comp_birthday);
 
-        if (record->comp_anniversary)
-                manage_comp_alarm_update (cbc, record->comp_anniversary);
+	if (record->comp_anniversary)
+		manage_comp_alarm_update (cbc, record->comp_anniversary);
 }
 
 static gboolean
@@ -669,34 +585,34 @@ setup_alarm (ECalBackendContacts *cbc, ECalComponent *comp)
 static ECalComponent *
 create_component (ECalBackendContacts *cbc, const gchar *uid, EContactDate *cdate, const gchar *summary)
 {
-        ECalComponent             *cal_comp;
-	ECalComponentText          comp_summary;
-        icalcomponent             *ical_comp;
-        struct icaltimetype        itt;
-        ECalComponentDateTime      dt;
+	ECalComponent	     *cal_comp;
+	ECalComponentText	  comp_summary;
+	icalcomponent	     *ical_comp;
+	struct icaltimetype	itt;
+	ECalComponentDateTime      dt;
 	struct icalrecurrencetype  r;
-        GSList recur_list;
+	GSList recur_list;
 
-        g_return_val_if_fail (E_IS_CAL_BACKEND_CONTACTS (cbc), NULL);
+	g_return_val_if_fail (E_IS_CAL_BACKEND_CONTACTS (cbc), NULL);
 
-        if (!cdate)
-                return NULL;
+	if (!cdate)
+		return NULL;
 
-        ical_comp = icalcomponent_new (ICAL_VEVENT_COMPONENT);
+	ical_comp = icalcomponent_new (ICAL_VEVENT_COMPONENT);
 
-        /* Create the event object */
-        cal_comp = e_cal_component_new ();
+	/* Create the event object */
+	cal_comp = e_cal_component_new ();
 	e_cal_component_set_icalcomponent (cal_comp, ical_comp);
 
 	/* Set uid */
 	d(g_message ("Creating UID: %s", uid));
 	e_cal_component_set_uid (cal_comp, uid);
 
-        /* Set all-day event's date from contact data */
-        itt = cdate_to_icaltime (cdate);
-        dt.value = &itt;
-        dt.tzid = NULL;
-        e_cal_component_set_dtstart (cal_comp, &dt);
+	/* Set all-day event's date from contact data */
+	itt = cdate_to_icaltime (cdate);
+	dt.value = &itt;
+	dt.tzid = NULL;
+	e_cal_component_set_dtstart (cal_comp, &dt);
 
 	itt = cdate_to_icaltime (cdate);
 	icaltime_adjust (&itt, 1, 0, 0, 0);
@@ -705,18 +621,18 @@ create_component (ECalBackendContacts *cbc, const gchar *uid, EContactDate *cdat
 	/* We have to add 1 day to DTEND, as it is not inclusive. */
 	e_cal_component_set_dtend (cal_comp, &dt);
 
-        /* Create yearly recurrence */
-        icalrecurrencetype_clear (&r);
-        r.freq = ICAL_YEARLY_RECURRENCE;
+	/* Create yearly recurrence */
+	icalrecurrencetype_clear (&r);
+	r.freq = ICAL_YEARLY_RECURRENCE;
 	r.interval = 1;
-        recur_list.data = &r;
-        recur_list.next = NULL;
-        e_cal_component_set_rrule_list (cal_comp, &recur_list);
+	recur_list.data = &r;
+	recur_list.next = NULL;
+	e_cal_component_set_rrule_list (cal_comp, &recur_list);
 
-        /* Create summary */
-        comp_summary.value = summary;
-        comp_summary.altrep = NULL;
-        e_cal_component_set_summary (cal_comp, &comp_summary);
+	/* Create summary */
+	comp_summary.value = summary;
+	comp_summary.altrep = NULL;
+	e_cal_component_set_summary (cal_comp, &comp_summary);
 
 	/* Set category and visibility */
 	if (g_str_has_suffix (uid, ANNIVERSARY_UID_EXT))
@@ -732,58 +648,58 @@ create_component (ECalBackendContacts *cbc, const gchar *uid, EContactDate *cdat
 	/* setup alarms if required */
 	setup_alarm (cbc, cal_comp);
 
-        /* Don't forget to call commit()! */
+	/* Don't forget to call commit()! */
 	e_cal_component_commit_sequence (cal_comp);
 
-        return cal_comp;
+	return cal_comp;
 }
 
 static ECalComponent *
 create_birthday (ECalBackendContacts *cbc, EContact *contact)
 {
-        EContactDate  *cdate;
-        ECalComponent *cal_comp;
-	gchar          *summary;
-        const gchar    *name;
-        gchar *uid;
+	EContactDate  *cdate;
+	ECalComponent *cal_comp;
+	gchar	  *summary;
+	const gchar    *name;
+	gchar *uid;
 
-        cdate = e_contact_get (contact, E_CONTACT_BIRTH_DATE);
-        name = e_contact_get_const (contact, E_CONTACT_FILE_AS);
+	cdate = e_contact_get (contact, E_CONTACT_BIRTH_DATE);
+	name = e_contact_get_const (contact, E_CONTACT_FILE_AS);
 
 	uid = g_strdup_printf ("%s%s", (gchar *) e_contact_get_const (contact, E_CONTACT_UID), BIRTHDAY_UID_EXT);
-        summary = g_strdup_printf (_("Birthday: %s"), name);
+	summary = g_strdup_printf (_("Birthday: %s"), name);
 
-        cal_comp = create_component (cbc, uid, cdate, summary);
+	cal_comp = create_component (cbc, uid, cdate, summary);
 
-        e_contact_date_free (cdate);
-        g_free (uid);
-        g_free (summary);
+	e_contact_date_free (cdate);
+	g_free (uid);
+	g_free (summary);
 
-        return cal_comp;
+	return cal_comp;
 }
 
 static ECalComponent *
 create_anniversary (ECalBackendContacts *cbc, EContact *contact)
 {
-        EContactDate  *cdate;
-        ECalComponent *cal_comp;
-	gchar          *summary;
-        const gchar    *name;
-        gchar *uid;
+	EContactDate  *cdate;
+	ECalComponent *cal_comp;
+	gchar	  *summary;
+	const gchar    *name;
+	gchar *uid;
 
-        cdate = e_contact_get (contact, E_CONTACT_ANNIVERSARY);
-        name = e_contact_get_const (contact, E_CONTACT_FILE_AS);
+	cdate = e_contact_get (contact, E_CONTACT_ANNIVERSARY);
+	name = e_contact_get_const (contact, E_CONTACT_FILE_AS);
 
 	uid = g_strdup_printf ("%s%s", (gchar *) e_contact_get_const (contact, E_CONTACT_UID), ANNIVERSARY_UID_EXT);
-        summary = g_strdup_printf (_("Anniversary: %s"), name);
+	summary = g_strdup_printf (_("Anniversary: %s"), name);
 
-        cal_comp = create_component (cbc, uid, cdate, summary);
+	cal_comp = create_component (cbc, uid, cdate, summary);
 
-        e_contact_date_free (cdate);
-        g_free (uid);
-        g_free (summary);
+	e_contact_date_free (cdate);
+	g_free (uid);
+	g_free (summary);
 
-        return cal_comp;
+	return cal_comp;
 }
 
 /************************************************************************************/
@@ -825,11 +741,14 @@ e_cal_backend_contacts_get_static_capabilities (ECalBackendSync *backend, EDataC
 	*capabilities = NULL;
 }
 
-static void
-e_cal_backend_contacts_remove (ECalBackendSync *backend, EDataCal *cal, GError **perror)
+static gboolean
+e_cal_backend_contacts_remove (ECalBackend *backend,
+                               GError **error)
 {
 	/* WRITE ME */
-	g_propagate_error (perror, EDC_ERROR (PermissionDenied));
+	g_propagate_error (error, EDC_ERROR (PermissionDenied));
+
+	return FALSE;
 }
 
 static void
@@ -844,8 +763,8 @@ e_cal_backend_contacts_get_object (ECalBackendSync *backend, EDataCal *cal,
 				   const gchar *uid, const gchar *rid,
 				   gchar **object, GError **perror)
 {
-        ECalBackendContacts *cbc = E_CAL_BACKEND_CONTACTS (backend);
-        ECalBackendContactsPrivate *priv = cbc->priv;
+	ECalBackendContacts *cbc = E_CAL_BACKEND_CONTACTS (backend);
+	ECalBackendContactsPrivate *priv = cbc->priv;
 	ContactRecord *record;
 	gchar *real_uid;
 
@@ -869,19 +788,19 @@ e_cal_backend_contacts_get_object (ECalBackendSync *backend, EDataCal *cal,
 		return;
 	}
 
-        if (record->comp_birthday && g_str_has_suffix (uid, BIRTHDAY_UID_EXT)) {
-                *object = e_cal_component_get_as_string (record->comp_birthday);
+	if (record->comp_birthday && g_str_has_suffix (uid, BIRTHDAY_UID_EXT)) {
+		*object = e_cal_component_get_as_string (record->comp_birthday);
 
 		d(g_message ("Return birthday: %s", *object));
 		return;
 	}
 
-        if (record->comp_anniversary && g_str_has_suffix (uid, ANNIVERSARY_UID_EXT)) {
-                *object = e_cal_component_get_as_string (record->comp_anniversary);
+	if (record->comp_anniversary && g_str_has_suffix (uid, ANNIVERSARY_UID_EXT)) {
+		*object = e_cal_component_get_as_string (record->comp_anniversary);
 
 		d(g_message ("Return anniversary: %s", *object));
 		return;
-        }
+	}
 
 	d(g_message ("Returning nothing for uid: %s", uid));
 
@@ -976,46 +895,18 @@ e_cal_backend_contacts_is_read_only (ECalBackendSync *backend, EDataCal *cal,
 	*read_only = TRUE;
 }
 
-static gpointer
-init_sources_cb (ECalBackendContacts *cbc)
-{
-        ECalBackendContactsPrivate *priv;
-        GSList *i;
-
-	g_return_val_if_fail (cbc != NULL, NULL);
-
-	priv = cbc->priv;
-
-	/* Create address books for existing sources */
-        for (i = e_source_list_peek_groups (priv->addressbook_sources); i; i = i->next) {
-                ESourceGroup *source_group = E_SOURCE_GROUP (i->data);
-
-                source_group_added_cb (priv->addressbook_sources, source_group, cbc);
-        }
-
-        /* Listen for source list changes */
-        g_signal_connect (priv->addressbook_sources, "changed", G_CALLBACK (source_list_changed_cb), cbc);
-        g_signal_connect (priv->addressbook_sources, "group_added", G_CALLBACK (source_group_added_cb), cbc);
-        g_signal_connect (priv->addressbook_sources, "group_removed", G_CALLBACK (source_group_removed_cb), cbc);
-
-	e_flag_set (priv->init_done_flag);
-
-	return NULL;
-}
-
 static void
 e_cal_backend_contacts_open (ECalBackendSync *backend, EDataCal *cal,
 			     gboolean only_if_exists,
 			     const gchar *username, const gchar *password, GError **perror)
 {
-        ECalBackendContacts *cbc = E_CAL_BACKEND_CONTACTS (backend);
-        ECalBackendContactsPrivate *priv = cbc->priv;
-	GError *error = NULL;
+	ECalBackendContacts *cbc = E_CAL_BACKEND_CONTACTS (backend);
+	ECalBackendContactsPrivate *priv = cbc->priv;
 
-        if (priv->addressbook_loaded)
-                return;
+	if (priv->addressbook_loaded)
+		return;
 
-        if (priv->default_zone && priv->default_zone != icaltimezone_get_utc_timezone ()) {
+	if (priv->default_zone && priv->default_zone != icaltimezone_get_utc_timezone ()) {
 		icalcomponent *icalcomp = icaltimezone_get_component (priv->default_zone);
 		icaltimezone *zone = icaltimezone_new ();
 
@@ -1024,27 +915,16 @@ e_cal_backend_contacts_open (ECalBackendSync *backend, EDataCal *cal,
 		g_hash_table_insert (priv->zones, g_strdup (icaltimezone_get_tzid (zone)), zone);
 	}
 
-	/* initialize addressbook sources in new thread to make this function quick as much as possible */
-	if (!g_thread_create ((GThreadFunc)init_sources_cb, cbc, FALSE, &error)) {
-		e_flag_set (priv->init_done_flag);
-		g_warning ("%s: Cannot create thread to initialize sources! (%s)", G_STRFUNC, error ? error->message : "Unknown error");
-		if (error)
-			g_error_free (error);
-
-		g_propagate_error (perror, EDC_ERROR (OtherError));
-		return;
-	}
-
-        priv->addressbook_loaded = TRUE;
+	priv->addressbook_loaded = TRUE;
 }
 
 static gboolean
 e_cal_backend_contacts_is_loaded (ECalBackend *backend)
 {
-        ECalBackendContacts *cbc = E_CAL_BACKEND_CONTACTS (backend);
-        ECalBackendContactsPrivate *priv = cbc->priv;
+	ECalBackendContacts *cbc = E_CAL_BACKEND_CONTACTS (backend);
+	ECalBackendContactsPrivate *priv = cbc->priv;
 
-        return priv->addressbook_loaded;
+	return priv->addressbook_loaded;
 }
 
 /* Add_timezone handler for the file backend */
@@ -1121,10 +1001,10 @@ static void
 e_cal_backend_contacts_get_object_list (ECalBackendSync *backend, EDataCal *cal,
 					const gchar *sexp_string, GList **objects, GError **perror)
 {
-        ECalBackendContacts *cbc = E_CAL_BACKEND_CONTACTS (backend);
-        ECalBackendContactsPrivate *priv = cbc->priv;
-        ECalBackendSExp *sexp = e_cal_backend_sexp_new (sexp_string);
-        ContactRecordCB *cb_data;
+	ECalBackendContacts *cbc = E_CAL_BACKEND_CONTACTS (backend);
+	ECalBackendContactsPrivate *priv = cbc->priv;
+	ECalBackendSExp *sexp = e_cal_backend_sexp_new (sexp_string);
+	ContactRecordCB *cb_data;
 
 	if (!sexp) {
 		g_propagate_error (perror, EDC_ERROR (InvalidQuery));
@@ -1132,7 +1012,7 @@ e_cal_backend_contacts_get_object_list (ECalBackendSync *backend, EDataCal *cal,
 	}
 
 	cb_data = contact_record_cb_new (cbc, sexp);
-        g_hash_table_foreach (priv->tracked_contacts, contact_record_cb, cb_data);
+	g_hash_table_foreach (priv->tracked_contacts, contact_record_cb, cb_data);
 	*objects = cb_data->result;
 
 	/* Don't call cb_data_free as that would destroy the results
@@ -1143,12 +1023,12 @@ e_cal_backend_contacts_get_object_list (ECalBackendSync *backend, EDataCal *cal,
 static void
 e_cal_backend_contacts_start_query (ECalBackend *backend, EDataCalView *query)
 {
-        ECalBackendContacts *cbc = E_CAL_BACKEND_CONTACTS (backend);
-        ECalBackendContactsPrivate *priv = cbc->priv;
-        ECalBackendSExp *sexp;
-        ContactRecordCB *cb_data;
+	ECalBackendContacts *cbc = E_CAL_BACKEND_CONTACTS (backend);
+	ECalBackendContactsPrivate *priv = cbc->priv;
+	ECalBackendSExp *sexp;
+	ContactRecordCB *cb_data;
 
-        sexp = e_data_cal_view_get_object_sexp (query);
+	sexp = e_data_cal_view_get_object_sexp (query);
 	if (!sexp) {
 		GError *error = EDC_ERROR (InvalidQuery);
 		e_data_cal_view_notify_done (query, error);
@@ -1156,12 +1036,12 @@ e_cal_backend_contacts_start_query (ECalBackend *backend, EDataCalView *query)
 		return;
 	}
 
-        cb_data = contact_record_cb_new (cbc, sexp);
+	cb_data = contact_record_cb_new (cbc, sexp);
 
-        g_hash_table_foreach (priv->tracked_contacts, contact_record_cb, cb_data);
-        e_data_cal_view_notify_objects_added (query, cb_data->result);
+	g_hash_table_foreach (priv->tracked_contacts, contact_record_cb, cb_data);
+	e_data_cal_view_notify_objects_added (query, cb_data->result);
 
-        contact_record_cb_free (cb_data);
+	contact_record_cb_free (cb_data);
 
 	e_data_cal_view_notify_done (query, NULL /* Success */);
 }
@@ -1169,7 +1049,7 @@ e_cal_backend_contacts_start_query (ECalBackend *backend, EDataCalView *query)
 static icaltimezone *
 e_cal_backend_contacts_internal_get_default_timezone (ECalBackend *backend)
 {
-        ECalBackendContacts *cbc = E_CAL_BACKEND_CONTACTS (backend);
+	ECalBackendContacts *cbc = E_CAL_BACKEND_CONTACTS (backend);
 
 	return cbc->priv->default_zone;
 }
@@ -1177,9 +1057,9 @@ e_cal_backend_contacts_internal_get_default_timezone (ECalBackend *backend)
 static icaltimezone *
 e_cal_backend_contacts_internal_get_timezone (ECalBackend *backend, const gchar *tzid)
 {
-        ECalBackendContacts *cbc = E_CAL_BACKEND_CONTACTS (backend);
+	ECalBackendContacts *cbc = E_CAL_BACKEND_CONTACTS (backend);
 
-        return cbc->priv->default_zone;
+	return cbc->priv->default_zone;
 }
 
 /***********************************************************************************
@@ -1204,12 +1084,6 @@ e_cal_backend_contacts_finalize (GObject *object)
 	cbc = E_CAL_BACKEND_CONTACTS (object);
 	priv = cbc->priv;
 
-	if (priv->init_done_flag) {
-		e_flag_wait (priv->init_done_flag);
-		e_flag_free (priv->init_done_flag);
-		priv->init_done_flag = NULL;
-	}
-
 	if (priv->update_alarms_id) {
 		g_source_remove (priv->update_alarms_id);
 		priv->update_alarms_id = 0;
@@ -1220,10 +1094,9 @@ e_cal_backend_contacts_finalize (GObject *object)
 	}
 
 	priv->default_zone = NULL;
-	g_object_unref (priv->addressbook_sources);
 	g_hash_table_destroy (priv->addressbooks);
-        g_hash_table_destroy (priv->tracked_contacts);
-        g_hash_table_destroy (priv->zones);
+	g_hash_table_destroy (priv->tracked_contacts);
+	g_hash_table_destroy (priv->zones);
 	if (priv->notifyid1)
 		gconf_client_notify_remove (priv->conf_client, priv->notifyid1);
 	if (priv->notifyid2)
@@ -1245,19 +1118,19 @@ static void
 e_cal_backend_contacts_init (ECalBackendContacts *cbc)
 {
 	ECalBackendContactsPrivate *priv;
+	ESourceRegistry *registry;
+	GList *sources, *iter;
+	const gchar *extension_name;
 
 	priv = g_new0 (ECalBackendContactsPrivate, 1);
 
-	e_book_get_addressbooks (&priv->addressbook_sources, NULL);
-
-        priv->addressbooks = g_hash_table_new_full (g_str_hash, g_str_equal,
-                                                    g_free, (GDestroyNotify) book_record_free);
-        priv->tracked_contacts = g_hash_table_new_full (g_str_hash, g_str_equal,
-                                                        g_free, (GDestroyNotify)contact_record_free);
+	priv->addressbooks = g_hash_table_new_full (g_str_hash, g_str_equal,
+						    g_free, (GDestroyNotify) book_record_free);
+	priv->tracked_contacts = g_hash_table_new_full (g_str_hash, g_str_equal,
+							g_free, (GDestroyNotify)contact_record_free);
 
 	priv->zones = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, free_zone);
 	priv->default_zone = icaltimezone_get_utc_timezone ();
-	priv->init_done_flag = e_flag_new ();
 	priv->conf_client = gconf_client_get_default ();
 	priv->notifyid1 = 0;
 	priv->notifyid2 = 0;
@@ -1270,18 +1143,35 @@ e_cal_backend_contacts_init (ECalBackendContacts *cbc)
 	cbc->priv = priv;
 
 	e_cal_backend_sync_set_lock (E_CAL_BACKEND_SYNC (cbc), TRUE);
+
+	/* Query all address book sources from the registry. */
+
+	registry = e_source_registry_get_default ();
+	extension_name = E_SOURCE_EXTENSION_ADDRESS_BOOK;
+	sources = e_source_registry_list_sources (registry, extension_name);
+	for (iter = sources; iter != NULL; iter = g_list_next (iter))
+		source_added_cb (registry, E_SOURCE (iter->data), cbc);
+	g_list_free (sources);
+
+	g_signal_connect (
+		registry, "source-added",
+		G_CALLBACK (source_added_cb), cbc);
+
+	g_signal_connect (
+		registry, "source-removed",
+		G_CALLBACK (source_removed_cb), cbc);
 }
 
 static void
 e_cal_backend_contacts_create_object (ECalBackendSync *backend, EDataCal *cal, gchar **calobj, gchar **uid, GError **perror)
 {
-        ECalBackendContacts *cbcontacts;
-        ECalBackendContactsPrivate *priv;
+	ECalBackendContacts *cbcontacts;
+	ECalBackendContactsPrivate *priv;
 
-        cbcontacts = E_CAL_BACKEND_CONTACTS (backend);
-        priv = cbcontacts->priv;
+	cbcontacts = E_CAL_BACKEND_CONTACTS (backend);
+	priv = cbcontacts->priv;
 
-        g_propagate_error (perror, EDC_ERROR (PermissionDenied));
+	g_propagate_error (perror, EDC_ERROR (PermissionDenied));
 }
 
 /* Class initialization function for the contacts backend */
@@ -1306,7 +1196,6 @@ e_cal_backend_contacts_class_init (ECalBackendContactsClass *class)
 	sync_class->get_ldap_attribute_sync = e_cal_backend_contacts_get_ldap_attribute;
 	sync_class->get_static_capabilities_sync = e_cal_backend_contacts_get_static_capabilities;
 	sync_class->open_sync = e_cal_backend_contacts_open;
-	sync_class->remove_sync = e_cal_backend_contacts_remove;
 	sync_class->create_object_sync = e_cal_backend_contacts_create_object;
 	sync_class->discard_alarm_sync = e_cal_backend_contacts_discard_alarm;
 	sync_class->receive_objects_sync = e_cal_backend_contacts_receive_objects;
@@ -1318,11 +1207,16 @@ e_cal_backend_contacts_class_init (ECalBackendContactsClass *class)
 	sync_class->set_default_zone_sync = e_cal_backend_contacts_set_default_zone;
 	sync_class->get_freebusy_sync = e_cal_backend_contacts_get_free_busy;
 	sync_class->get_changes_sync = e_cal_backend_contacts_get_changes;
+
 	backend_class->is_loaded = e_cal_backend_contacts_is_loaded;
+	backend_class->remove = e_cal_backend_contacts_remove;
 	backend_class->start_query = e_cal_backend_contacts_start_query;
 	backend_class->get_mode = e_cal_backend_contacts_get_mode;
 	backend_class->set_mode = e_cal_backend_contacts_set_mode;
 
 	backend_class->internal_get_default_timezone = e_cal_backend_contacts_internal_get_default_timezone;
 	backend_class->internal_get_timezone = e_cal_backend_contacts_internal_get_timezone;
+
+	/* Register our ESource extension. */
+	E_TYPE_SOURCE_CONTACTS;
 }
diff --git a/calendar/backends/contacts/e-source-contacts.c b/calendar/backends/contacts/e-source-contacts.c
new file mode 100644
index 0000000..d6deb8c
--- /dev/null
+++ b/calendar/backends/contacts/e-source-contacts.c
@@ -0,0 +1,139 @@
+/*
+ * e-source-contacts.c
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with the program; if not, see <webcal://www.gnu.org/licenses/>
+ *
+ */
+
+#include "e-source-contacts.h"
+
+#define E_SOURCE_CONTACTS_GET_PRIVATE(obj) \
+	(G_TYPE_INSTANCE_GET_PRIVATE \
+	((obj), E_TYPE_SOURCE_CONTACTS, ESourceContactsPrivate))
+
+struct _ESourceContactsPrivate {
+	gboolean include_me;
+};
+
+enum {
+	PROP_0,
+	PROP_INCLUDE_ME
+};
+
+G_DEFINE_DYNAMIC_TYPE (
+	ESourceContacts,
+	e_source_contacts,
+	E_TYPE_SOURCE_EXTENSION)
+
+static void
+source_contacts_set_property (GObject *object,
+                              guint property_id,
+                              const GValue *value,
+                              GParamSpec *pspec)
+{
+	switch (property_id) {
+		case PROP_INCLUDE_ME:
+			e_source_contacts_set_include_me (
+				E_SOURCE_CONTACTS (object),
+				g_value_get_boolean (value));
+			return;
+	}
+
+	G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+}
+
+static void
+source_contacts_get_property (GObject *object,
+                              guint property_id,
+                              GValue *value,
+                              GParamSpec *pspec)
+{
+	switch (property_id) {
+		case PROP_INCLUDE_ME:
+			g_value_set_boolean (
+				value,
+				e_source_contacts_get_include_me (
+				E_SOURCE_CONTACTS (object)));
+			return;
+	}
+
+	G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+}
+
+static void
+e_source_contacts_class_init (ESourceContactsClass *class)
+{
+	GObjectClass *object_class;
+	ESourceExtensionClass *extension_class;
+
+	g_type_class_add_private (class, sizeof (ESourceContactsPrivate));
+
+	object_class = G_OBJECT_CLASS (class);
+	object_class->set_property = source_contacts_set_property;
+	object_class->get_property = source_contacts_get_property;
+
+	extension_class = E_SOURCE_EXTENSION_CLASS (class);
+	extension_class->name = E_SOURCE_EXTENSION_CONTACTS_BACKEND;
+
+	g_object_class_install_property (
+		object_class,
+		PROP_INCLUDE_ME,
+		g_param_spec_boolean (
+			"include-me",
+			"Include Me",
+			"Include this address book in the contacts calendar",
+			FALSE,
+			G_PARAM_READWRITE |
+			G_PARAM_CONSTRUCT |
+			E_SOURCE_PARAM_SETTING));
+}
+
+static void
+e_source_contacts_class_finalize (ESourceContactsClass *class)
+{
+}
+
+static void
+e_source_contacts_init (ESourceContacts *extension)
+{
+	extension->priv = E_SOURCE_CONTACTS_GET_PRIVATE (extension);
+}
+
+void
+e_source_contacts_type_register (GTypeModule *type_module)
+{
+	/* XXX G_DEFINE_DYNAMIC_TYPE declares a static type registration
+	 *     function, so we have to wrap it with a public function in
+	 *     order to register types from a separate compilation unit. */
+	e_source_contacts_register_type (type_module);
+}
+
+gboolean
+e_source_contacts_get_include_me (ESourceContacts *extension)
+{
+	g_return_val_if_fail (E_IS_SOURCE_CONTACTS (extension), FALSE);
+
+	return extension->priv->include_me;
+}
+
+void
+e_source_contacts_set_include_me (ESourceContacts *extension,
+                                  gboolean include_me)
+{
+	g_return_if_fail (E_IS_SOURCE_CONTACTS (extension));
+
+	extension->priv->include_me = include_me;
+
+	g_object_notify (G_OBJECT (extension), "include-me");
+}
diff --git a/calendar/backends/contacts/e-source-contacts.h b/calendar/backends/contacts/e-source-contacts.h
new file mode 100644
index 0000000..95d9b83
--- /dev/null
+++ b/calendar/backends/contacts/e-source-contacts.h
@@ -0,0 +1,70 @@
+/*
+ * e-source-contacts.h
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with the program; if not, see <webcal://www.gnu.org/licenses/>
+ *
+ */
+
+#ifndef E_SOURCE_CONTACTS_H
+#define E_SOURCE_CONTACTS_H
+
+#include <libedataserver/e-source-extension.h>
+
+/* Standard GObject macros */
+#define E_TYPE_SOURCE_CONTACTS \
+	(e_source_contacts_get_type ())
+#define E_SOURCE_CONTACTS(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), E_TYPE_SOURCE_CONTACTS, ESourceContacts))
+#define E_SOURCE_CONTACTS_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), E_TYPE_SOURCE_CONTACTS, ESourceContactsClass))
+#define E_IS_SOURCE_CONTACTS(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), E_TYPE_SOURCE_CONTACTS))
+#define E_IS_SOURCE_CONTACTS_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), E_TYPE_SOURCE_CONTACTS))
+#define E_SOURCE_CONTACTS_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), E_TYPE_SOURCE_CONTACTS, ESourceContactsClass))
+
+#define E_SOURCE_EXTENSION_CONTACTS_BACKEND "Contacts Backend"
+
+G_BEGIN_DECLS
+
+typedef struct _ESourceContacts ESourceContacts;
+typedef struct _ESourceContactsClass ESourceContactsClass;
+typedef struct _ESourceContactsPrivate ESourceContactsPrivate;
+
+struct _ESourceContacts {
+	ESourceExtension parent;
+	ESourceContactsPrivate *priv;
+};
+
+struct _ESourceContactsClass {
+	ESourceExtensionClass parent_class;
+};
+
+GType		e_source_contacts_get_type	(void);
+void		e_source_contacts_type_register	(GTypeModule *type_module);
+gboolean	e_source_contacts_get_include_me
+						(ESourceContacts *extension);
+void		e_source_contacts_set_include_me
+						(ESourceContacts *extension,
+						 gboolean include_me);
+
+G_END_DECLS
+
+#endif /* E_SOURCE_CONTACTS_H */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]