[evolution-data-server/openismus-work] Added ESourceDirectAccess extension



commit 4e08a96eda37966aed0e2db007a69c0b58423ecd
Author: Tristan Van Berkom <tristanvb openismus com>
Date:   Mon Nov 12 17:22:12 2012 +0900

    Added ESourceDirectAccess extension
    
    The ESourceDirectAccess extension configures a backend for direct read
    access mode by exposing the install path of the backend and it's backend
    name.
    
    This patch additionally moves the extensions from libebook to libebook-contacts
    where it's visible from EDataBook.
    
    EDataBook apis & EBookClient modified to use the new extension in order
    to leverage the new extension instead of the hard coded variables.

 addressbook/libebook-contacts/Makefile.am          |   10 +-
 .../e-source-address-book-config.c                 |   14 +-
 .../e-source-address-book-config.h                 |    7 +-
 .../libebook-contacts/e-source-direct-access.c     |  278 ++++++++++++++++++++
 .../libebook-contacts/e-source-direct-access.h     |   98 +++++++
 addressbook/libebook-contacts/libebook-contacts.h  |    2 +
 addressbook/libebook/Makefile.am                   |    4 +-
 addressbook/libebook/e-book-client.c               |   12 +-
 addressbook/libebook/libebook.h                    |    1 -
 addressbook/libedata-book/e-data-book.c            |   42 ++-
 addressbook/libedata-book/e-data-book.h            |    2 +-
 11 files changed, 430 insertions(+), 40 deletions(-)
---
diff --git a/addressbook/libebook-contacts/Makefile.am b/addressbook/libebook-contacts/Makefile.am
index 275ffc0..debb059 100644
--- a/addressbook/libebook-contacts/Makefile.am
+++ b/addressbook/libebook-contacts/Makefile.am
@@ -40,7 +40,10 @@ libebook_contacts_1_2_la_SOURCES =				\
 	e-name-western-tables.h                         \
 	e-book-query.c					\
 	e-contact.c					\
-	e-vcard.c
+	e-vcard.c					\
+	e-source-address-book-config.c			\
+	e-source-direct-access.c
+
 
 libebook_contacts_1_2_la_LIBADD =					\
 	$(top_builddir)/camel/libcamel-1.2.la			\
@@ -62,7 +65,10 @@ libebookcontactsinclude_HEADERS =			\
 	e-address-western.h				\
 	e-name-western.h				\
 	e-contact.h					\
-	e-vcard.h
+	e-vcard.h					\
+	e-source-address-book-config.h			\
+	e-source-direct-access.h
+
 
 %-$(API_VERSION).pc: %.pc
 	 cp $< $@
diff --git a/addressbook/libebook/e-source-address-book-config.c b/addressbook/libebook-contacts/e-source-address-book-config.c
similarity index 98%
rename from addressbook/libebook/e-source-address-book-config.c
rename to addressbook/libebook-contacts/e-source-address-book-config.c
index 686549f..6f08677 100644
--- a/addressbook/libebook/e-source-address-book-config.c
+++ b/addressbook/libebook-contacts/e-source-address-book-config.c
@@ -23,7 +23,7 @@
 
 /**
  * SECTION: e-source-address-book-config
- * @include: libebook/libebook.h
+ * @include: libebook-contacts/libebook-contacts.h
  * @short_description: #ESource extension for an address book configuration
  *
  * The #ESourceAddressBookConfig extension adds configuration data to
@@ -32,7 +32,7 @@
  * Access the extension as follows:
  *
  * |[
- *   #include <libebook/libebook.h>
+ *   #include <libebook-contacts/libebook-contacts.h>
  *
  *   ESourceAddressBookConfig *extension;
  *
@@ -41,7 +41,7 @@
  **/
 
 #include "e-source-address-book-config.h"
-#include "e-book-enumtypes.h"
+#include "e-book-contacts-enumtypes.h"
 
 #define E_SOURCE_ABC_GET_PRIVATE(obj)			\
 	(G_TYPE_INSTANCE_GET_PRIVATE			\
@@ -155,8 +155,7 @@ source_address_book_config_set_property (GObject *object,
 	switch (property_id) {
 	case PROP_SUMMARY_FIELDS:
 	case PROP_INDEXED_FIELDS:
-		source_address_book_config_set_litteral_fields
-			(extension, g_value_get_string (value), property_id);
+		source_address_book_config_set_litteral_fields (extension, g_value_get_string (value), property_id);
 		return;
 	case PROP_REVISION_GUARDS:
 		e_source_address_book_config_set_revision_guards_enabled (extension, g_value_get_boolean (value));
@@ -178,9 +177,8 @@ source_address_book_config_get_property (GObject *object,
 	case PROP_SUMMARY_FIELDS:
 	case PROP_INDEXED_FIELDS:
 		g_value_take_string (value,
-				     source_address_book_config_dup_litteral_fields
-				     (extension, property_id));
-			return;
+				     source_address_book_config_dup_litteral_fields (extension, property_id));
+		return;
 	case PROP_REVISION_GUARDS:
 		g_value_set_boolean (value, e_source_address_book_config_get_revision_guards_enabled (extension));
 		return;
diff --git a/addressbook/libebook/e-source-address-book-config.h b/addressbook/libebook-contacts/e-source-address-book-config.h
similarity index 94%
rename from addressbook/libebook/e-source-address-book-config.h
rename to addressbook/libebook-contacts/e-source-address-book-config.h
index 16cfa3c..ac72564 100644
--- a/addressbook/libebook/e-source-address-book-config.h
+++ b/addressbook/libebook-contacts/e-source-address-book-config.h
@@ -21,16 +21,15 @@
  * Authors: Tristan Van Berkom <tristanvb openismus com>
  */
 
-#if !defined (__LIBEBOOK_H_INSIDE__) && !defined (LIBEBOOK_COMPILATION)
-#error "Only <libebook/libebook.h> should be included directly."
+#if !defined (__LIBEBOOK_CONTACTS_H_INSIDE__) && !defined (LIBEBOOK_CONTACTS_COMPILATION)
+#error "Only <libebook-contacts/libebook-contacts.h> should be included directly."
 #endif
 
 #ifndef E_SOURCE_ADDRESS_BOOK_CONFIG_H
 #define E_SOURCE_ADDRESS_BOOK_CONFIG_H
 
 #include <libedataserver/libedataserver.h>
-#include <libebook-contacts/libebook-contacts.h>
-#include <libebook/e-book-types.h>
+#include <libebook-contacts/e-book-contacts-types.h>
 
 /* Standard GObject macros */
 #define E_TYPE_SOURCE_ADDRESS_BOOK_CONFIG \
diff --git a/addressbook/libebook-contacts/e-source-direct-access.c b/addressbook/libebook-contacts/e-source-direct-access.c
new file mode 100644
index 0000000..a95ad84
--- /dev/null
+++ b/addressbook/libebook-contacts/e-source-direct-access.c
@@ -0,0 +1,278 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/* e-source-address-book-config.c - Address Book Configuration.
+ *
+ * Copyright (C) 2012 Openismus GmbH
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU Lesser General Public
+ * License as published by the Free Software Foundation.
+ *
+ * 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
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ * Authors: Tristan Van Berkom <tristanvb openismus com>
+ */
+
+/**
+ * SECTION: e-source-direct-access
+ * @include: libebook-contacts/libebook-contacts.h
+ * @short_description: #ESource extension for direct access to the address book
+ *
+ * The #ESourceDirectAccess extension is used to advertize direct access parameters
+ * to be used in direct read access mode.
+ *
+ * Access the extension as follows:
+ *
+ * |[
+ *   #include <libebook-contacts/libebook-contacts.h>
+ *
+ *   ESourceDirectAccess *extension;
+ *
+ *   extension = e_source_get_extension (source, E_SOURCE_EXTENSION_DIRECT_ACCESS);
+ * ]|
+ **/
+
+#include "e-source-direct-access.h"
+
+#define E_SOURCE_DIRECT_ACCESS_GET_PRIVATE(obj)		\
+	(G_TYPE_INSTANCE_GET_PRIVATE			\
+	 ((obj), E_TYPE_SOURCE_DIRECT_ACCESS,		\
+	  ESourceDirectAccessPrivate))
+
+struct _ESourceDirectAccessPrivate {
+	GMutex *property_lock;
+	gchar  *backend_path;
+	gchar  *backend_name;
+};
+
+enum {
+	PROP_0,
+	PROP_BACKEND_PATH,
+	PROP_BACKEND_NAME
+};
+
+G_DEFINE_TYPE (
+	ESourceDirectAccess,
+	e_source_direct_access,
+	E_TYPE_SOURCE_EXTENSION)
+
+
+static void
+source_direct_access_finalize (GObject *object)
+{
+	ESourceDirectAccess        *source;
+	ESourceDirectAccessPrivate *priv;
+
+	source = E_SOURCE_DIRECT_ACCESS (object);
+	priv   = source->priv;
+
+	g_mutex_free (priv->property_lock);
+	g_free (priv->backend_path);
+	g_free (priv->backend_name);
+
+	G_OBJECT_CLASS (e_source_direct_access_parent_class)->finalize (object);
+}
+
+static void
+source_direct_access_set_property (GObject *object,
+				   guint property_id,
+				   const GValue *value,
+				   GParamSpec *pspec)
+{
+	ESourceDirectAccess *extension = E_SOURCE_DIRECT_ACCESS (object);
+
+	switch (property_id) {
+	case PROP_BACKEND_PATH:
+		e_source_direct_access_set_backend_path (extension, g_value_get_string (value));
+		return;
+	case PROP_BACKEND_NAME:
+		e_source_direct_access_set_backend_name (extension, g_value_get_string (value));
+		return;
+	}
+
+	G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+}
+
+static void
+source_direct_access_get_property (GObject *object,
+					 guint property_id,
+					 GValue *value,
+					 GParamSpec *pspec)
+{
+	ESourceDirectAccess *extension = E_SOURCE_DIRECT_ACCESS (object);
+
+	switch (property_id) {
+	case PROP_BACKEND_PATH:
+		g_value_take_string (value,
+				     e_source_direct_access_dup_backend_path (extension));
+		return;
+	case PROP_BACKEND_NAME:
+		g_value_take_string (value,
+				     e_source_direct_access_dup_backend_name (extension));
+		return;
+	}
+
+	G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+}
+
+static void
+e_source_direct_access_class_init (ESourceDirectAccessClass *class)
+{
+	GObjectClass          *object_class;
+	ESourceExtensionClass *extension_class;
+
+	extension_class       = E_SOURCE_EXTENSION_CLASS (class);
+	extension_class->name = E_SOURCE_EXTENSION_DIRECT_ACCESS;
+
+	object_class               = G_OBJECT_CLASS (class);
+	object_class->finalize     = source_direct_access_finalize;
+	object_class->get_property = source_direct_access_get_property;
+	object_class->set_property = source_direct_access_set_property;
+
+	g_object_class_install_property (
+		object_class,
+		PROP_BACKEND_PATH,
+		g_param_spec_string (
+			"backend-path",
+			"Backend Path",
+			"The full path to the backend module to load for direct access",
+			NULL,
+			G_PARAM_READWRITE |
+			G_PARAM_CONSTRUCT |
+			G_PARAM_STATIC_STRINGS |
+			E_SOURCE_PARAM_SETTING));
+
+	g_object_class_install_property (
+		object_class,
+		PROP_BACKEND_NAME,
+		g_param_spec_string (
+			"backend-name",
+			"Backend Name",
+			"The type name of the EBookBackendFactory to use to load the backend in direct access mode",
+			NULL,
+			G_PARAM_READWRITE |
+			G_PARAM_CONSTRUCT |
+			G_PARAM_STATIC_STRINGS |
+			E_SOURCE_PARAM_SETTING));
+
+	g_type_class_add_private (class, sizeof (ESourceDirectAccessPrivate));
+}
+
+static void
+e_source_direct_access_init (ESourceDirectAccess *extension)
+{
+	extension->priv = E_SOURCE_DIRECT_ACCESS_GET_PRIVATE (extension);
+	extension->priv->property_lock = g_mutex_new ();
+}
+
+
+/**
+ * e_source_direct_access_dup_backend_path:
+ * @extension: An #ESourceDirectAccess
+ *
+ * Fetches the path to load the #EBookBackend from directly for direct
+ * access to the addressbook.
+ *
+ * Returns: (transfer full): The backend path
+ *
+ * Since: 3.8
+ */
+gchar *
+e_source_direct_access_dup_backend_path (ESourceDirectAccess *extension)
+{
+	gchar *duplicate = NULL;
+
+	g_mutex_lock (extension->priv->property_lock);
+
+	duplicate = g_strdup (extension->priv->backend_path);
+
+	g_mutex_unlock (extension->priv->property_lock);
+
+	return duplicate;
+}
+
+/**
+ * e_source_direct_access_set_backend_path:
+ * @extension: An #ESourceDirectAccess
+ * @backend_path: The full path to the backend module
+ *
+ * Sets the path where to find the backend path for direct access
+ */
+void
+e_source_direct_access_set_backend_path (ESourceDirectAccess *extension,
+					 const gchar         *backend_path)
+{
+	g_mutex_lock (extension->priv->property_lock);
+
+	if (g_strcmp0 (extension->priv->backend_path, backend_path) == 0) {
+		g_mutex_unlock (extension->priv->property_lock);
+		return;
+	}
+
+	g_free (extension->priv->backend_path);
+	extension->priv->backend_path = e_util_strdup_strip (backend_path);
+
+	g_mutex_unlock (extension->priv->property_lock);
+
+	g_object_notify (G_OBJECT (extension), "backend-path");
+}
+
+/**
+ * e_source_direct_access_dup_backend_name:
+ * @extension: An #ESourceDirectAccess
+ *
+ * Fetches the name of the #EBookBackendFactory to use to create
+ * backends in direct access mode.
+ *
+ * Returns: (transfer full): The backend factory type name
+ *
+ * Since: 3.8
+ */
+gchar *
+e_source_direct_access_dup_backend_name (ESourceDirectAccess *extension)
+{
+	gchar *duplicate = NULL;
+
+	g_mutex_lock (extension->priv->property_lock);
+
+	duplicate = g_strdup (extension->priv->backend_name);
+
+	g_mutex_unlock (extension->priv->property_lock);
+
+	return duplicate;
+}
+
+/**
+ * e_source_direct_access_set_backend_name:
+ * @extension: An #ESourceDirectAccess
+ * @backend_path: The name of the #EBookBackendFactory to use in direct access mode
+ *
+ * Sets the name of the #EBookBackendFactory found in the directly loaded
+ * backend to use in direct access mode.
+ */
+void
+e_source_direct_access_set_backend_name (ESourceDirectAccess *extension,
+					 const gchar         *backend_name)
+{
+	g_mutex_lock (extension->priv->property_lock);
+
+	if (g_strcmp0 (extension->priv->backend_name, backend_name) == 0) {
+		g_mutex_unlock (extension->priv->property_lock);
+		return;
+	}
+
+	g_free (extension->priv->backend_name);
+	extension->priv->backend_name = e_util_strdup_strip (backend_name);
+
+	g_mutex_unlock (extension->priv->property_lock);
+
+	g_object_notify (G_OBJECT (extension), "backend-name");
+}
diff --git a/addressbook/libebook-contacts/e-source-direct-access.h b/addressbook/libebook-contacts/e-source-direct-access.h
new file mode 100644
index 0000000..21a5f84
--- /dev/null
+++ b/addressbook/libebook-contacts/e-source-direct-access.h
@@ -0,0 +1,98 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/* e-source-direct-access.h - Directly Accessible Extension.
+ *
+ * Copyright (C) 2012 Openismus GmbH
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU Lesser General Public
+ * License as published by the Free Software Foundation.
+ *
+ * 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
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ * Authors: Tristan Van Berkom <tristanvb openismus com>
+ */
+
+#if !defined (__LIBEBOOK_CONTACTS_H_INSIDE__) && !defined (LIBEBOOK_CONTACTS_COMPILATION)
+#error "Only <libebook-contacts/libebook-contacts.h> should be included directly."
+#endif
+
+#ifndef E_SOURCE_DIRECT_ACCESS_H
+#define E_SOURCE_DIRECT_ACCESS_H
+
+#include <libedataserver/libedataserver.h>
+
+/* Standard GObject macros */
+#define E_TYPE_SOURCE_DIRECT_ACCESS \
+	(e_source_direct_access_get_type ())
+#define E_SOURCE_DIRECT_ACCESS(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), E_TYPE_SOURCE_DIRECT_ACCESS, ESourceDirectAccess))
+#define E_SOURCE_DIRECT_ACCESS_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), E_TYPE_SOURCE_DIRECT_ACCESS, ESourceDirectAccessClass))
+#define E_IS_SOURCE_DIRECT_ACCESS(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), E_TYPE_SOURCE_DIRECT_ACCESS))
+#define E_IS_SOURCE_DIRECT_ACCESS_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), E_TYPE_SOURCE_DIRECT_ACCESS))
+#define E_SOURCE_DIRECT_ACCESS_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), E_TYPE_SOURCE_DIRECT_ACCESS, ESourceDirectAccessClass))
+
+/**
+ * E_SOURCE_EXTENSION_DIRECT_ACCESS:
+ *
+ * Pass this extension name to e_source_get_extension() to access
+ * #ESourceDirectAccess.  This is also used as a group name in key files.
+ *
+ * Since: 3.8
+ **/
+#define E_SOURCE_EXTENSION_DIRECT_ACCESS "Direct Access"
+
+G_BEGIN_DECLS
+
+typedef struct _ESourceDirectAccess ESourceDirectAccess;
+typedef struct _ESourceDirectAccessClass ESourceDirectAccessClass;
+typedef struct _ESourceDirectAccessPrivate ESourceDirectAccessPrivate;
+
+/**
+ * ESourceDirectAccess:
+ *
+ * Contains only private data that should be read and manipulated using the
+ * functions below.
+ *
+ * Since: 3.6
+ **/
+struct _ESourceDirectAccess {
+	ESourceBackend parent;
+	ESourceDirectAccessPrivate *priv;
+};
+
+struct _ESourceDirectAccessClass {
+	ESourceBackendClass parent_class;
+};
+
+GType           e_source_direct_access_get_type            (void) G_GNUC_CONST;
+
+gchar          *e_source_direct_access_dup_backend_path    (ESourceDirectAccess  *extension);
+void            e_source_direct_access_set_backend_path    (ESourceDirectAccess  *extension,
+							    const gchar          *backend_path);
+
+gchar          *e_source_direct_access_dup_backend_name    (ESourceDirectAccess  *extension);
+void            e_source_direct_access_set_backend_name    (ESourceDirectAccess  *extension,
+							    const gchar          *backend_name);
+
+
+G_END_DECLS
+
+#endif /* E_SOURCE_DIRECT_ACCESS_H */
diff --git a/addressbook/libebook-contacts/libebook-contacts.h b/addressbook/libebook-contacts/libebook-contacts.h
index b6fc89d..d713b83 100644
--- a/addressbook/libebook-contacts/libebook-contacts.h
+++ b/addressbook/libebook-contacts/libebook-contacts.h
@@ -30,6 +30,8 @@
 #include <libebook-contacts/e-contact.h>
 #include <libebook-contacts/e-vcard.h>
 #include <libebook-contacts/e-book-contacts-enumtypes.h>
+#include <libebook-contacts/e-source-address-book-config.h>
+#include <libebook-contacts/e-source-direct-access.h>
 
 #undef __LIBEBOOK_CONTACTS_H_INSIDE__
 
diff --git a/addressbook/libebook/Makefile.am b/addressbook/libebook/Makefile.am
index 0a2b93c..22d21c7 100644
--- a/addressbook/libebook/Makefile.am
+++ b/addressbook/libebook/Makefile.am
@@ -45,7 +45,6 @@ libebook_1_2_la_SOURCES =				\
 	e-book-view.c					\
 	e-book.c					\
 	e-destination.c					\
-	e-source-address-book-config.c			\
 	e-error.h
 
 libebook_1_2_la_LIBADD =					\
@@ -74,8 +73,7 @@ libebookinclude_HEADERS =				\
 	e-book-view.h					\
 	e-book-types.h					\
 	e-book.h					\
-	e-destination.h					\
-	e-source-address-book-config.h
+	e-destination.h
 
 %-$(API_VERSION).pc: %.pc
 	 cp $< $@
diff --git a/addressbook/libebook/e-book-client.c b/addressbook/libebook/e-book-client.c
index 9b19ffb..feda4ac 100644
--- a/addressbook/libebook/e-book-client.c
+++ b/addressbook/libebook/e-book-client.c
@@ -576,21 +576,15 @@ e_book_client_new_direct (ESourceRegistry *registry,
 			  GError         **error)
 {
   EBookClient *client;
-  const gchar *backend_path;
-  const gchar *backend_name;
 
   client = e_book_client_new (source, error);
 
   if (!client)
 	  return NULL;
 
-  /* Load the module for the given backend, need the path to the module and the name of the backend factory type */
-  backend_path = "/opt/devel/lib64/evolution-data-server/addressbook-backends/libebookbackendfile.so";
-  backend_name = "EBookBackendFileFactory";
-
-  client->priv->direct_book = 
-	  e_data_book_new_direct (registry, source,
-				  backend_path, backend_name);
+  client->priv->direct_book = e_data_book_new_direct (registry, source);
+  if (!client->priv->direct_book)
+    g_warning ("Direct access to address book is not available");
 
   return client;
 }
diff --git a/addressbook/libebook/libebook.h b/addressbook/libebook/libebook.h
index bfc6127..ae1ad0e 100644
--- a/addressbook/libebook/libebook.h
+++ b/addressbook/libebook/libebook.h
@@ -31,7 +31,6 @@
 #include <libebook/e-book-view.h>
 #include <libebook/e-book.h>
 #include <libebook/e-destination.h>
-#include <libebook/e-source-address-book-config.h>
 
 #undef __LIBEBOOK_H_INSIDE__
 
diff --git a/addressbook/libedata-book/e-data-book.c b/addressbook/libedata-book/e-data-book.c
index 6ffbfc6..91e784e 100644
--- a/addressbook/libedata-book/e-data-book.c
+++ b/addressbook/libedata-book/e-data-book.c
@@ -40,6 +40,12 @@
 	(G_TYPE_INSTANCE_GET_PRIVATE \
 	((obj), E_TYPE_DATA_BOOK, EDataBookPrivate))
 
+/* This forces the GType to be registered in a way that
+ * avoids a "statement with no effect" compiler warning.
+ * FIXME Use g_type_ensure() once we require GLib 2.34. */
+#define REGISTER_TYPE(type) \
+	(g_type_class_unref (g_type_class_ref (type)))
+
 struct _EDataBookPrivate
 {
 	EGdbusBook *gdbus_object;
@@ -1712,37 +1718,46 @@ e_data_book_new (EBookBackend *backend)
 
 EDataBook *
 e_data_book_new_direct (ESourceRegistry *registry,
-			ESource         *source,
-			const gchar     *backend_path,
-			const gchar     *backend_factory_name)
+			ESource         *source)
 {
-	EDataBook    *book;
+	EDataBook    *book = NULL;
 	EModule      *module;
 	EBookBackend *backend;
 	GType         backend_type;
 	GType         factory_type;
 	GTypeClass   *factory_class;
+	gchar        *backend_path;
+	gchar        *backend_name;
+	ESourceDirectAccess *direct;
 
 	g_return_val_if_fail (E_IS_SOURCE_REGISTRY (registry), NULL);
 	g_return_val_if_fail (E_IS_SOURCE (source), NULL);
-	g_return_val_if_fail (backend_path && backend_path[0], NULL);
-	g_return_val_if_fail (backend_factory_name && backend_factory_name[0], NULL);
+
+	REGISTER_TYPE (E_TYPE_SOURCE_DIRECT_ACCESS);
+	direct = e_source_get_extension (source, E_SOURCE_EXTENSION_DIRECT_ACCESS);
+	backend_path = e_source_direct_access_dup_backend_path (direct);
+	backend_name = e_source_direct_access_dup_backend_name (direct);
+
+	if (!backend_path || !backend_name) {
+		g_warning ("ESource is not configured for direct access");
+		goto new_direct_finish;
+	}
 
 	module = load_module (backend_path);
 	if (!module)
-		return NULL;
+		goto new_direct_finish;
 
 	if (!g_type_module_use (G_TYPE_MODULE (module))) {
 		g_warning ("Failed to load EModule at path: %s", backend_path);
-		return NULL;
+		goto new_direct_finish;
 	}
 
-	factory_type = g_type_from_name (backend_factory_name);
+	factory_type = g_type_from_name (backend_name);
 	if (factory_type == 0) {
 		g_warning ("Failed to get backend factory '%s' from EModule at path: %s",
-			   backend_factory_name, backend_path);
+			   backend_name, backend_path);
 		g_type_module_unuse (G_TYPE_MODULE (module));
-		return NULL;
+		goto new_direct_finish;
 	}
 
 	factory_class = g_type_class_ref (factory_type);
@@ -1753,10 +1768,13 @@ e_data_book_new_direct (ESourceRegistry *registry,
 				"registry", registry,
 				"source", source, NULL);
 
-
 	book = e_data_book_new (backend);
 	book->priv->direct_module = module;
 
+ new_direct_finish:
+	g_free (backend_path);
+	g_free (backend_name);
+
 	return book;
 }
 
diff --git a/addressbook/libedata-book/e-data-book.h b/addressbook/libedata-book/e-data-book.h
index 9961785..613a7eb 100644
--- a/addressbook/libedata-book/e-data-book.h
+++ b/addressbook/libedata-book/e-data-book.h
@@ -129,7 +129,7 @@ const gchar *e_data_book_status_to_string (EDataBookStatus status);
 
 GType		e_data_book_get_type				(void);
 EDataBook *	e_data_book_new					(struct _EBookBackend *backend);
-EDataBook *	e_data_book_new_direct				(ESourceRegistry *registry, ESource *source, const gchar *backend_path, const gchar *backend_factory_name);
+EDataBook *	e_data_book_new_direct				(ESourceRegistry *registry, ESource *source);
 struct _EBookBackend *
 		e_data_book_get_backend				(EDataBook *book);
 



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