[evolution-data-server/treitter-client-gdbus] Port the e-book 'getContactList' method to gdbus



commit 1eeae5965c29b90fa732c2b6a0ba0c7f3fb6bee2
Author: Travis Reitter <treitter gmail com>
Date:   Fri Dec 4 17:22:53 2009 -0800

    Port the e-book 'getContactList' method to gdbus

 addressbook/libebook/e-book.c                     |    9 ++-
 addressbook/libebook/e-data-book-gdbus-bindings.h |   89 +++++++++++++++++++++
 2 files changed, 95 insertions(+), 3 deletions(-)
---
diff --git a/addressbook/libebook/e-book.c b/addressbook/libebook/e-book.c
index 256657f..fb1db0c 100644
--- a/addressbook/libebook/e-book.c
+++ b/addressbook/libebook/e-book.c
@@ -1383,7 +1383,7 @@ e_book_get_contacts (EBook       *book,
 
 	sexp = e_book_query_to_string (query);
 	LOCK_CONN ();
-	org_gnome_evolution_dataserver_addressbook_Book_get_contact_list (book->priv->proxy, sexp, &list, &err);
+	e_data_book_gdbus_get_contact_list_sync (book->priv->gdbus_proxy, sexp, &list, &err);
 	UNLOCK_CONN ();
 	g_free (sexp);
 	if (!err) {
@@ -1401,7 +1401,10 @@ e_book_get_contacts (EBook       *book,
 }
 
 static void
-get_contacts_reply(DBusGProxy *proxy, gchar **vcards, GError *error, gpointer user_data)
+get_contacts_reply (GDBusProxy  *proxy,
+		    gchar      **vcards,
+		    GError      *error,
+		    gpointer     user_data)
 {
 	AsyncData *data = user_data;
 	GList *list = NULL;
@@ -1454,7 +1457,7 @@ e_book_async_get_contacts (EBook             *book,
 	data->closure = closure;
 
 	LOCK_CONN ();
-	org_gnome_evolution_dataserver_addressbook_Book_get_contact_list_async (book->priv->proxy, sexp, get_contacts_reply, data);
+	e_data_book_gdbus_get_contact_list (book->priv->gdbus_proxy, sexp, get_contacts_reply, data);
 	UNLOCK_CONN ();
 	g_free (sexp);
 	return 0;
diff --git a/addressbook/libebook/e-data-book-gdbus-bindings.h b/addressbook/libebook/e-data-book-gdbus-bindings.h
index 1b1a885..f097fd3 100644
--- a/addressbook/libebook/e-data-book-gdbus-bindings.h
+++ b/addressbook/libebook/e-data-book-gdbus-bindings.h
@@ -243,6 +243,95 @@ e_data_book_gdbus_get_contact (GDBusProxy                          *proxy,
 }
 
 static gboolean
+get_contact_list_demarshal_retvals (GVariant *retvals, char ***OUT_vcards)
+{
+        gboolean success = TRUE;
+
+        if (retvals) {
+		GVariant *vcards_variant;
+                char **vcards = NULL;
+		gint length;
+
+		/* retvals contains a (as) with length 1; de-shell the
+		 * array of strings from the tuple */
+		vcards_variant = g_variant_get_child_value (retvals, 0);
+                vcards = g_variant_dup_strv (vcards_variant, &length);
+
+                if (vcards) {
+                        *OUT_vcards = vcards;
+                } else {
+                        success = FALSE;
+                }
+
+                g_variant_unref (retvals);
+        } else {
+                success = FALSE;
+        }
+
+        return success;
+}
+
+static gboolean
+e_data_book_gdbus_get_contact_list_sync (GDBusProxy   *proxy,
+					 const char   *IN_query,
+					 char       ***OUT_vcards,
+					 GError      **error)
+
+{
+	GVariant *parameters;
+	GVariant *retvals;
+
+	parameters = g_variant_new ("(s)", IN_query);
+	retvals = g_dbus_proxy_invoke_method_sync (proxy, "getContactList", parameters, -1, NULL, error);
+
+	return get_contact_list_demarshal_retvals (retvals, OUT_vcards);
+}
+
+typedef void (*e_data_book_gdbus_get_contact_list_reply) (GDBusProxy  *proxy,
+							  char       **OUT_vcards,
+							  GError      *error,
+							  gpointer     user_data);
+
+static void
+get_contact_list_cb (GDBusProxy   *proxy,
+		     GAsyncResult *result,
+		     gpointer      user_data)
+{
+        Closure *closure = user_data;
+        GVariant *retvals;
+        GError *error = NULL;
+        char **OUT_vcards = NULL;
+
+        retvals = g_dbus_proxy_invoke_method_finish (proxy, result, &error);
+	if (retvals) {
+		if (!get_contact_list_demarshal_retvals (retvals, &OUT_vcards)) {
+			error = g_error_new (E_BOOK_ERROR, E_BOOK_ERROR_CORBA_EXCEPTION, "demarshalling results for Book method 'getContactList'");
+		}
+	}
+
+	(*(e_data_book_gdbus_get_contact_list_reply) closure->cb) (proxy, OUT_vcards, error, closure->user_data);
+	closure_free (closure);
+}
+
+static void
+e_data_book_gdbus_get_contact_list (GDBusProxy                               *proxy,
+				    const char                               *IN_query,
+				    e_data_book_gdbus_get_contact_list_reply  callback,
+				    gpointer                                  user_data)
+{
+        GVariant *parameters;
+        Closure *closure;
+
+        parameters = g_variant_new ("(s)", IN_query);
+
+        closure = g_slice_new (Closure);
+        closure->cb = G_CALLBACK (callback);
+        closure->user_data = user_data;
+
+        g_dbus_proxy_invoke_method (proxy, "getContactList", parameters, -1, NULL, (GAsyncReadyCallback) get_contact_list_cb, closure);
+}
+
+static gboolean
 add_contact_demarshal_retvals (GVariant *retvals, char **OUT_uid)
 {
         gboolean success = TRUE;



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