[evolution-data-server/account-mgmt: 13/37] Adapt libedata-book to the new ESource API.
- From: Matthew Barnes <mbarnes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server/account-mgmt: 13/37] Adapt libedata-book to the new ESource API.
- Date: Sat, 1 Oct 2011 15:47:22 +0000 (UTC)
commit 7197f2bc348dc34db79527755dd5a1fb542b276f
Author: Matthew Barnes <mbarnes redhat com>
Date: Fri Nov 12 16:48:26 2010 -0500
Adapt libedata-book to the new ESource API.
addressbook/libedata-book/e-book-backend-factory.c | 6 ++-
addressbook/libedata-book/e-book-backend.c | 10 +--
addressbook/libedata-book/e-data-book-factory.c | 65 +++++++++-----------
3 files changed, 37 insertions(+), 44 deletions(-)
---
diff --git a/addressbook/libedata-book/e-book-backend-factory.c b/addressbook/libedata-book/e-book-backend-factory.c
index a2e1341..8beda14 100644
--- a/addressbook/libedata-book/e-book-backend-factory.c
+++ b/addressbook/libedata-book/e-book-backend-factory.c
@@ -34,6 +34,7 @@ book_backend_factory_get_hash_key (EBackendFactory *factory)
static EBackend *
book_backend_factory_new_backend (EBackendFactory *factory,
+ ESourceRegistry *registry,
ESource *source)
{
EBookBackendFactoryClass *class;
@@ -42,7 +43,10 @@ book_backend_factory_new_backend (EBackendFactory *factory,
g_return_val_if_fail (g_type_is_a (
class->backend_type, E_TYPE_BOOK_BACKEND), NULL);
- return g_object_new (class->backend_type, "source", source, NULL);
+ return g_object_new (
+ class->backend_type,
+ "registry", registry,
+ "source", source, NULL);
}
static void
diff --git a/addressbook/libedata-book/e-book-backend.c b/addressbook/libedata-book/e-book-backend.c
index cb68604..f482a97 100644
--- a/addressbook/libedata-book/e-book-backend.c
+++ b/addressbook/libedata-book/e-book-backend.c
@@ -44,21 +44,19 @@ book_backend_set_default_cache_dir (EBookBackend *backend)
{
ESource *source;
const gchar *user_cache_dir;
- gchar *mangled_uri;
+ const gchar *uid;
gchar *filename;
user_cache_dir = e_get_user_cache_dir ();
source = e_backend_get_source (E_BACKEND (backend));
- /* Mangle the URI to not contain invalid characters. */
- mangled_uri = g_strdelimit (e_source_get_uri (source), ":/", '_');
+ uid = e_source_get_uid (source);
+ g_return_if_fail (uid != NULL);
filename = g_build_filename (
- user_cache_dir, "addressbook", mangled_uri, NULL);
+ user_cache_dir, "addressbook", uid, NULL);
e_book_backend_set_cache_dir (backend, filename);
g_free (filename);
-
- g_free (mangled_uri);
}
static void
diff --git a/addressbook/libedata-book/e-data-book-factory.c b/addressbook/libedata-book/e-data-book-factory.c
index 966b4b1..e83065b 100644
--- a/addressbook/libedata-book/e-data-book-factory.c
+++ b/addressbook/libedata-book/e-data-book-factory.c
@@ -35,6 +35,8 @@
#define GOA_KEY "goa-account-id"
#endif
+#include <libebook/e-source-address-book.h>
+
#include "e-book-backend.h"
#include "e-book-backend-factory.h"
#include "e-data-book.h"
@@ -84,24 +86,18 @@ e_data_book_factory_extract_proto_from_uri (const gchar *uri)
static EBackend *
e_data_book_factory_get_backend (EDataBookFactory *factory,
- ESource *source,
- const gchar *uri)
+ ESource *source)
{
- EBackend *backend;
- gchar *hash_key;
-
- hash_key = e_data_book_factory_extract_proto_from_uri (uri);
- if (hash_key == NULL) {
- g_warning ("Cannot extract protocol from URI %s", uri);
- return NULL;
- }
+ const gchar *hash_key;
- backend = e_data_factory_get_backend (
- E_DATA_FACTORY (factory), hash_key, source);
+ /* For address books the hash key is simply the backend name.
+ * (cf. calendar hash keys, which are slightly more complex) */
- g_free (hash_key);
+ hash_key = e_source_get_backend_name (source);
+ g_return_val_if_fail (hash_key != NULL, NULL);
- return backend;
+ return e_data_factory_get_backend (
+ E_DATA_FACTORY (factory), hash_key, source);
}
static gchar *
@@ -160,16 +156,17 @@ book_freed_cb (EDataBookFactory *factory,
static gboolean
impl_BookFactory_get_book (EGdbusBookFactory *object,
GDBusMethodInvocation *invocation,
- const gchar *in_source,
+ const gchar *uid,
EDataBookFactory *factory)
{
EDataBook *book;
EBackend *backend;
EDataBookFactoryPrivate *priv = factory->priv;
GDBusConnection *connection;
+ ESourceRegistry *registry;
ESource *source;
gchar *path;
- gchar *uri;
+ const gchar *backend_name;
const gchar *sender;
GList *list;
GError *error = NULL;
@@ -177,51 +174,47 @@ impl_BookFactory_get_book (EGdbusBookFactory *object,
sender = g_dbus_method_invocation_get_sender (invocation);
connection = g_dbus_method_invocation_get_connection (invocation);
- if (in_source == NULL || in_source[0] == '\0') {
- error = g_error_new (
+ if (uid == NULL || *uid == '\0') {
+ error = g_error_new_literal (
E_DATA_BOOK_ERROR,
E_DATA_BOOK_STATUS_NO_SUCH_BOOK,
- _("Empty URI"));
+ _("Missing source UID"));
g_dbus_method_invocation_return_gerror (invocation, error);
g_error_free (error);
return TRUE;
}
- source = e_source_new_from_standalone_xml (in_source);
- if (!source) {
+ registry = e_data_factory_get_registry (E_DATA_FACTORY (factory));
+ source = e_source_registry_lookup_by_uid (registry, uid);
+
+ if (source == NULL) {
error = g_error_new (
E_DATA_BOOK_ERROR,
E_DATA_BOOK_STATUS_NO_SUCH_BOOK,
- _("Invalid source"));
+ _("No such source for UID '%s'"), uid);
g_dbus_method_invocation_return_gerror (invocation, error);
g_error_free (error);
return TRUE;
}
- uri = e_source_get_uri (source);
-
- if (uri == NULL || *uri == '\0') {
- g_object_unref (source);
- g_free (uri);
+ backend_name = e_source_get_backend_name (source);
+ if (backend_name == NULL || *backend_name == '\0') {
error = g_error_new (
E_DATA_BOOK_ERROR,
E_DATA_BOOK_STATUS_NO_SUCH_BOOK,
- _("Empty URI"));
+ _("No backend specified in source UID '%s'"), uid);
g_dbus_method_invocation_return_gerror (invocation, error);
g_error_free (error);
return TRUE;
}
- backend = e_data_book_factory_get_backend (factory, source, uri);
+ backend = e_data_book_factory_get_backend (factory, source);
if (backend == NULL) {
- g_free (uri);
- g_object_unref (source);
-
error = g_error_new (
E_DATA_BOOK_ERROR,
E_DATA_BOOK_STATUS_NO_SUCH_BOOK,
@@ -232,8 +225,6 @@ impl_BookFactory_get_book (EGdbusBookFactory *object,
return TRUE;
}
- g_mutex_lock (priv->books_lock);
-
e_dbus_server_hold (E_DBUS_SERVER (factory));
#ifdef HAVE_GOA
@@ -275,9 +266,6 @@ impl_BookFactory_get_book (EGdbusBookFactory *object,
g_mutex_unlock (priv->books_lock);
- g_object_unref (source);
- g_free (uri);
-
e_gdbus_book_factory_complete_get_book (
object, invocation, path, error);
@@ -429,6 +417,9 @@ e_data_book_factory_class_init (EDataBookFactoryClass *class)
dbus_server_class->module_directory = BACKENDDIR;
dbus_server_class->bus_acquired = data_book_factory_bus_acquired;
dbus_server_class->bus_name_lost = data_book_factory_bus_name_lost;
+
+ /* Register ESource extensions we'll need. */
+ E_TYPE_SOURCE_ADDRESS_BOOK;
}
#ifdef HAVE_GOA
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]