[couchdb-glib] Port to gdbus



commit b26d199c52588ccdebdb0415aebb0e22b58d081b
Author: Rodrigo Moya <rodrigo gnome-db org>
Date:   Thu Mar 31 18:08:58 2011 +0200

    Port to gdbus

 NEWS                                     |    2 +-
 configure.ac                             |    2 +-
 desktopcouch-glib/desktopcouch-session.c |  149 ++++++++++++++++--------------
 3 files changed, 82 insertions(+), 71 deletions(-)
---
diff --git a/NEWS b/NEWS
index e6ce350..c91c858 100644
--- a/NEWS
+++ b/NEWS
@@ -1,5 +1,5 @@
 ==============
-Version 0.7.0
+Version 0.7.1
 ==============
 - Include missing documentation (Rodrigo Moya)
 - Fix retrieval of documents (Rodrigo Moya)
diff --git a/configure.ac b/configure.ac
index fb10ea1..8fdb308 100644
--- a/configure.ac
+++ b/configure.ac
@@ -48,7 +48,7 @@ AC_SUBST(COUCHDB_GLIB_CFLAGS)
 AC_SUBST(COUCHDB_GLIB_LIBS)
 
 dnl Needed modules for Desktopcouch
-PKG_CHECK_MODULES(DESKTOPCOUCH_GLIB, gnome-keyring-1 dbus-glib-1)
+PKG_CHECK_MODULES(DESKTOPCOUCH_GLIB, gnome-keyring-1 gio-2.0)
 AC_SUBST(DESKTOPCOUCH_GLIB_CFLAGS)
 AC_SUBST(DESKTOPCOUCH_GLIB_LIBS)
 
diff --git a/desktopcouch-glib/desktopcouch-session.c b/desktopcouch-glib/desktopcouch-session.c
index 12bcaf5..9777bca 100644
--- a/desktopcouch-glib/desktopcouch-session.c
+++ b/desktopcouch-glib/desktopcouch-session.c
@@ -19,7 +19,7 @@
  * Boston, MA 02110-1301, USA.
  */
 
-#include <dbus/dbus-glib.h>
+#include <gio/gio.h>
 #include <gnome-keyring.h>
 #include "utils.h"
 #include "desktopcouch-session.h"
@@ -58,15 +58,19 @@ DesktopcouchSession *
 desktopcouch_session_new (void)
 {
 	char *uri = NULL;
-	DBusGConnection *bus;
-	DBusGProxy *proxy;
-	gint port;
+	GDBusConnection *bus;
+	GDBusProxy *proxy;
+	GVariant *out;
 	GError *error;
 	gboolean success;
+	GnomeKeyringAttributeList *attrs;
+	GnomeKeyringResult result;
+	GList *items_found;
+	gint port;
 
 	/* Get the desktopcouch port via the org.desktopcouch.CouchDB interface */
 	error = NULL;
-	bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
+	bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
 	if (error) {
 		g_warning ("Couldn't get session bus: %s", error->message);
 		g_error_free (error);
@@ -74,80 +78,87 @@ desktopcouch_session_new (void)
 		return NULL;
 	}
 
-	proxy = dbus_g_proxy_new_for_name (bus,
-					   "org.desktopcouch.CouchDB",
-					   "/",
-					   "org.desktopcouch.CouchDB");
+	proxy = g_dbus_proxy_new_sync (bus, 0, NULL,
+				       "org.desktopcouch.CouchDB",
+				       "/",
+				       "org.desktopcouch.CouchDB",
+				       NULL,
+				       &error);
+	if (error) {
+		g_warning ("Couldn't get proxy object: %s", error->message);
+		g_error_free (error);
+
+		return NULL;
+	}
 
 	error = NULL;
-	success = dbus_g_proxy_call (proxy, "getPort", &error,
-				     G_TYPE_INVALID,
-				     G_TYPE_INT, &port, G_TYPE_INVALID);
+	out = g_dbus_proxy_call_sync (proxy, "getPort", NULL, 0, -1, NULL, &error);
 
 	/* Free memory */
 	g_object_unref (G_OBJECT (proxy));
-	dbus_g_connection_unref (bus);
-
-	if (success) {
-		GnomeKeyringAttributeList *attrs;
-		GnomeKeyringResult result;
-		GList *items_found;
-
-		uri = g_strdup_printf ("http://127.0.0.1:%d";, port);
-
-		/* Get OAuth tokens from GnomeKeyring */
-		attrs = gnome_keyring_attribute_list_new ();
-		gnome_keyring_attribute_list_append_string (attrs, "desktopcouch", "oauth");
-
-		result = gnome_keyring_find_items_sync (GNOME_KEYRING_ITEM_GENERIC_SECRET,
-							attrs, &items_found);
-		if (result == GNOME_KEYRING_RESULT_OK && items_found != NULL) {
-			gchar **items;
-			char *oauth_c_key = NULL, *oauth_c_secret = NULL, *oauth_t_key = NULL, *oauth_t_secret = NULL;
-			DesktopcouchSession *dc;
-			CouchdbCredentials *credentials;
-			GnomeKeyringFound *first_item = (GnomeKeyringFound *) items_found->data;
-
-			items = g_strsplit (first_item->secret, ":", 4);
-			if (items) {
-				oauth_c_key = g_strdup (items[0]);
-				oauth_c_secret = g_strdup (items[1]);
-				oauth_t_key = g_strdup (items[2]);
-				oauth_t_secret = g_strdup (items[3]);
-				g_strfreev (items);
-			}
-
-			gnome_keyring_found_list_free (items_found);
-
-			/* Enable OAuth on this connection */
-			dc = DESKTOPCOUCH_SESSION (g_object_new (DESKTOPCOUCH_TYPE_SESSION, "uri", uri, NULL));
-
-			credentials = couchdb_credentials_new_with_oauth (oauth_c_key,
-									  oauth_c_secret,
-									  oauth_t_key,
-									  oauth_t_secret);
-			couchdb_session_enable_authentication (COUCHDB_SESSION (dc), credentials);
-
-			/* Free memory */
-			g_free (oauth_c_key);
-			g_free (oauth_c_secret);
-			g_free (oauth_t_key);
-			g_free (oauth_t_secret);
-			g_free (uri);
-			g_object_unref (G_OBJECT (credentials));
-
-			return dc;
-		} else {
-			g_warning ("Could not get OAuth tokens from keyring: %s",
-				   gnome_keyring_result_to_message (result));
+	g_object_unref (bus);
+
+	if (error) {
+		g_warning ("Couldn't get desktopcouch port: %s", error->message);
+		g_error_free (error);
+
+		return NULL;
+	}
+
+	g_variant_get_child (out, 0, "i", &port);
+	uri = g_strdup_printf ("http://127.0.0.1:%d";, port);
+
+	/* Get OAuth tokens from GnomeKeyring */
+	attrs = gnome_keyring_attribute_list_new ();
+	gnome_keyring_attribute_list_append_string (attrs, "desktopcouch", "oauth");
+
+	result = gnome_keyring_find_items_sync (GNOME_KEYRING_ITEM_GENERIC_SECRET,
+						attrs, &items_found);
+	if (result == GNOME_KEYRING_RESULT_OK && items_found != NULL) {
+		gchar **items;
+		char *oauth_c_key = NULL, *oauth_c_secret = NULL, *oauth_t_key = NULL, *oauth_t_secret = NULL;
+		DesktopcouchSession *dc;
+		CouchdbCredentials *credentials;
+		GnomeKeyringFound *first_item = (GnomeKeyringFound *) items_found->data;
+
+		items = g_strsplit (first_item->secret, ":", 4);
+		if (items) {
+			oauth_c_key = g_strdup (items[0]);
+			oauth_c_secret = g_strdup (items[1]);
+			oauth_t_key = g_strdup (items[2]);
+			oauth_t_secret = g_strdup (items[3]);
+			g_strfreev (items);
 		}
 
+		gnome_keyring_found_list_free (items_found);
+
+		/* Enable OAuth on this connection */
+		dc = DESKTOPCOUCH_SESSION (g_object_new (DESKTOPCOUCH_TYPE_SESSION, "uri", uri, NULL));
+
+		credentials = couchdb_credentials_new_with_oauth (oauth_c_key,
+								  oauth_c_secret,
+								  oauth_t_key,
+								  oauth_t_secret);
+		couchdb_session_enable_authentication (COUCHDB_SESSION (dc), credentials);
+
 		/* Free memory */
-		gnome_keyring_attribute_list_free (attrs);
+		g_free (oauth_c_key);
+		g_free (oauth_c_secret);
+		g_free (oauth_t_key);
+		g_free (oauth_t_secret);
+		g_free (uri);
+		g_object_unref (G_OBJECT (credentials));
+		g_variant_unref (out);
+
+		return dc;
 	} else {
-		g_warning ("Couldn't get port for desktopcouch: %s", error->message);
-		g_error_free (error);
+		g_warning ("Could not get OAuth tokens from keyring: %s",
+			   gnome_keyring_result_to_message (result));
 	}
 
+	/* Free memory */
+	gnome_keyring_attribute_list_free (attrs);
+	g_variant_unref (out);
+
 	return NULL;
 }



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