[evolution-data-server/openismus-work] EBookClient: Added e_book_client_new_direct()
- From: Tristan Van Berkom <tvb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server/openismus-work] EBookClient: Added e_book_client_new_direct()
- Date: Mon, 12 Nov 2012 08:52:46 +0000 (UTC)
commit bad9dd3298df7c3c1233e9c23cdcda1c8f6de17f
Author: Tristan Van Berkom <tristanvb openismus com>
Date: Mon Nov 12 16:38:59 2012 +0900
EBookClient: Added e_book_client_new_direct()
With direct access enabled, an EDataBook is created locally by
the client and used for read access directly instead of going over
the D-Bus.
This is a work in progress.
addressbook/libebook/Makefile.am | 2 +
addressbook/libebook/e-book-client.c | 107 ++++++++++++++++++++++++++++++++++
addressbook/libebook/e-book-client.h | 2 +
3 files changed, 111 insertions(+), 0 deletions(-)
---
diff --git a/addressbook/libebook/Makefile.am b/addressbook/libebook/Makefile.am
index 9efbf64..5177934 100644
--- a/addressbook/libebook/Makefile.am
+++ b/addressbook/libebook/Makefile.am
@@ -58,6 +58,8 @@ libebook_1_2_la_LIBADD = \
$(top_builddir)/addressbook/libegdbus/libegdbus-book.la \
$(top_builddir)/camel/libcamel-1.2.la \
$(top_builddir)/libedataserver/libedataserver-1.2.la \
+ $(top_builddir)/libebackend/libebackend-1.2.la \
+ $(top_builddir)/addressbook/libedata-book/libedata-book-1.2.la \
$(EVOLUTION_ADDRESSBOOK_LIBS) \
$(CAMEL_LIBS)
diff --git a/addressbook/libebook/e-book-client.c b/addressbook/libebook/e-book-client.c
index 634659a..609a7e7 100644
--- a/addressbook/libebook/e-book-client.c
+++ b/addressbook/libebook/e-book-client.c
@@ -29,6 +29,9 @@
#include <libedataserver/libedataserver.h>
#include <libedataserver/e-client-private.h>
+#include <libebackend/libebackend.h>
+#include <libedata-book/libedata-book.h>
+
#include "e-book-client.h"
#include "e-contact.h"
#include "e-name-western.h"
@@ -46,6 +49,10 @@ struct _EBookClientPrivate {
/* GDBus data */
GDBusProxy *gdbus_book;
guint gone_signal_id;
+
+ EModule *direct_module;
+ EDataBook *direct_book;
+ EBookBackend *direct_backend;
};
G_DEFINE_TYPE (EBookClient, e_book_client, E_TYPE_CLIENT)
@@ -354,6 +361,9 @@ gdbus_book_client_disconnect (EBookClient *client)
g_dbus_connection_signal_unsubscribe (connection, client->priv->gone_signal_id);
client->priv->gone_signal_id = 0;
+ if (client->priv->direct_book)
+ e_data_book_close_sync (client->priv->direct_book, NULL, NULL);
+
e_gdbus_book_call_close_sync (client->priv->gdbus_book, NULL, NULL);
g_object_unref (client->priv->gdbus_book);
client->priv->gdbus_book = NULL;
@@ -551,6 +561,62 @@ e_book_client_new (ESource *source,
return client;
}
+
+/**
+ * e_book_client_new:
+ * @source: An #ESource pointer
+ * @error: A #GError pointer
+ *
+ * Like e_book_client_new(), except creates the book client for
+ * direct read access to the underlying addressbook.
+ *
+ * Returns: a new but unopened #EBookClient.
+ *
+ * Since: 3.8
+ **/
+EBookClient *
+e_book_client_new_direct (ESourceRegistry *registry,
+ ESource *source,
+ GError **error)
+{
+ EBookClient *client;
+ GType factory_type;
+ GType backend_type;
+ GTypeClass *factory_class;
+ 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_module = e_module_new (backend_path);
+ g_type_module_use (G_TYPE_MODULE (client->priv->direct_module));
+
+ factory_type = g_type_from_name (backend_name);
+
+ factory_class = g_type_class_ref (factory_type);
+ backend_type = E_BOOK_BACKEND_FACTORY_CLASS (factory_class)->backend_type;
+
+ g_print ("Direct backend type name: %s\n", g_type_name (backend_type));
+
+ g_type_class_unref (factory_class);
+
+ client->priv->direct_backend =
+ g_object_new (backend_type,
+ "registry", registry,
+ "source", source, NULL);
+
+ client->priv->direct_book = e_data_book_new (client->priv->direct_backend);
+
+ return client;
+}
+
#define SELF_UID_PATH_ID "org.gnome.evolution-data-server.addressbook"
#define SELF_UID_KEY "self-contact-uid"
@@ -938,6 +1004,11 @@ book_client_open_sync (EClient *client,
return FALSE;
}
+ if (book_client->priv->direct_book &&
+ !e_data_book_open_sync (book_client->priv->direct_book,
+ only_if_exists, cancellable, error))
+ return FALSE;
+
return e_client_proxy_call_sync_boolean__void (client, only_if_exists, cancellable, error, e_gdbus_book_call_open_sync);
}
@@ -1803,6 +1874,12 @@ e_book_client_get_contact (EBookClient *client,
g_return_if_fail (uid != NULL);
+ if (client->priv->direct_book) {
+ e_data_book_get_contact (client->priv->direct_book,
+ uid, cancellable, callback, user_data);
+ return;
+ }
+
safe_uid = e_util_ensure_gdbus_string (uid, &gdbus_uid);
g_return_if_fail (safe_uid != NULL);
@@ -1840,6 +1917,9 @@ e_book_client_get_contact_finish (EBookClient *client,
g_return_val_if_fail (contact != NULL, FALSE);
+ if (client->priv->direct_book)
+ return e_data_book_get_contact_finish (client->priv->direct_book, result, contact, error);
+
res = e_client_proxy_call_finish_string (E_CLIENT (client), result, &vcard, error, e_book_client_get_contact);
if (vcard && res)
@@ -1883,6 +1963,9 @@ e_book_client_get_contact_sync (EBookClient *client,
g_return_val_if_fail (uid != NULL, FALSE);
g_return_val_if_fail (contact != NULL, FALSE);
+ if (client->priv->direct_book)
+ return e_data_book_get_contact_sync (client->priv->direct_book, uid, contact, cancellable, error);
+
if (!client->priv->gdbus_book) {
set_proxy_gone_error (error);
return FALSE;
@@ -1932,6 +2015,12 @@ e_book_client_get_contacts (EBookClient *client,
g_return_if_fail (sexp != NULL);
+ if (client->priv->direct_book) {
+ e_data_book_get_contacts (client->priv->direct_book,
+ sexp, cancellable, callback, user_data);
+ return;
+ }
+
e_client_proxy_call_string (
E_CLIENT (client), e_util_ensure_gdbus_string (sexp, &gdbus_sexp), cancellable, callback, user_data, e_book_client_get_contacts,
e_gdbus_book_call_get_contact_list,
@@ -1966,6 +2055,9 @@ e_book_client_get_contacts_finish (EBookClient *client,
g_return_val_if_fail (contacts != NULL, FALSE);
+ if (client->priv->direct_book)
+ return e_data_book_get_contacts_finish (client->priv->direct_book, result, contacts, error);
+
res = e_client_proxy_call_finish_strv (E_CLIENT (client), result, &vcards, error, e_book_client_get_contacts);
if (vcards && res) {
@@ -2020,6 +2112,9 @@ e_book_client_get_contacts_sync (EBookClient *client,
g_return_val_if_fail (sexp != NULL, FALSE);
g_return_val_if_fail (contacts != NULL, FALSE);
+ if (client->priv->direct_book)
+ return e_data_book_get_contacts_sync (client->priv->direct_book, sexp, contacts, cancellable, error);
+
if (!client->priv->gdbus_book) {
set_proxy_gone_error (error);
return FALSE;
@@ -2074,6 +2169,12 @@ e_book_client_get_contacts_uids (EBookClient *client,
g_return_if_fail (sexp != NULL);
+ if (client->priv->direct_book) {
+ e_data_book_get_contacts_uids (client->priv->direct_book,
+ sexp, cancellable, callback, user_data);
+ return;
+ }
+
e_client_proxy_call_string (
E_CLIENT (client), e_util_ensure_gdbus_string (sexp, &gdbus_sexp), cancellable, callback, user_data, e_book_client_get_contacts_uids,
e_gdbus_book_call_get_contact_list_uids,
@@ -2108,6 +2209,9 @@ e_book_client_get_contacts_uids_finish (EBookClient *client,
g_return_val_if_fail (contacts_uids != NULL, FALSE);
+ if (client->priv->direct_book)
+ return e_data_book_get_contacts_uids_finish (client->priv->direct_book, result, contacts_uids, error);
+
res = e_client_proxy_call_finish_strv (E_CLIENT (client), result, &uids, error, e_book_client_get_contacts_uids);
if (uids && res) {
@@ -2162,6 +2266,9 @@ e_book_client_get_contacts_uids_sync (EBookClient *client,
g_return_val_if_fail (sexp != NULL, FALSE);
g_return_val_if_fail (contacts_uids != NULL, FALSE);
+ if (client->priv->direct_book)
+ return e_data_book_get_contacts_uids_sync (client->priv->direct_book, sexp, contacts_uids, cancellable, error);
+
if (!client->priv->gdbus_book) {
set_proxy_gone_error (error);
return FALSE;
diff --git a/addressbook/libebook/e-book-client.h b/addressbook/libebook/e-book-client.h
index d0c3b79..6e8ba48 100644
--- a/addressbook/libebook/e-book-client.h
+++ b/addressbook/libebook/e-book-client.h
@@ -124,6 +124,8 @@ GType e_book_client_get_type (void);
/* Creating a new addressbook */
EBookClient * e_book_client_new (ESource *source, GError **error);
+EBookClient * e_book_client_new_direct (ESourceRegistry *registry, ESource *source, GError **error);
+
/* Identity */
gboolean e_book_client_get_self (ESourceRegistry *registry, EContact **contact, EBookClient **client, GError **error);
gboolean e_book_client_set_self (EBookClient *client, EContact *contact, GError **error);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]