soc.2010.detachablepurple: 5b93e9d6: Updated purple_account_new() according t...

gillux at soc.pidgin.im gillux at soc.pidgin.im
Tue Jul 6 17:01:09 EDT 2010


----------------------------------------------------------------------
Revision: 5b93e9d69da2aecae7175e80450c7056e7bbd93f
Parent:   43db6309f1a932adcab522e09872c1eb8c64a3a8
Author:   gillux at soc.pidgin.im
Date:     07/06/10 15:37:03
Branch:   im.pidgin.soc.2010.detachablepurple
URL: http://d.pidgin.im/viewmtn/revision/info/5b93e9d69da2aecae7175e80450c7056e7bbd93f

Changelog: 

Updated purple_account_new() according to previous work. Now multiple accounts
can be remotely created, thanks to the PurpleConstructor.

Changes against parent 43db6309f1a932adcab522e09872c1eb8c64a3a8

  patched  libpurple/account.c
  patched  libpurple/dbus-purple.h

-------------- next part --------------
============================================================
--- libpurple/account.c	0e23f59ed035aa0a3499294c931c5e583510cc0f
+++ libpurple/account.c	22edcbba26240ede12d2badca13c669d0cb1db9d
@@ -51,6 +51,8 @@
 #  include "account-dbus.h"
 #  include "dbus-account-server.h"
 #  include "dbus-account-client.h"
+#  include "dbus-constructor.h"
+#  include "dbus-constructor-client.h"
 #endif
 
 struct _PurpleAccountPrivate
@@ -797,6 +799,19 @@ GType purple_account_get_gtype(void)
 	return type;
 }
 
+static char*
+build_dbus_path(const char *username, const char *protocol_id) {
+	char* id;
+	char* dbus_path;
+	guint account_dbus_id;
+
+	id = g_strjoin(" ", protocol_id, username, NULL);
+	account_dbus_id = g_str_hash(id);
+	g_free(id);
+	dbus_path = g_strdup_printf("%s/%u", DBUS_ACCOUNT_PATH, account_dbus_id);
+	return dbus_path;
+}
+
 PurpleAccount *
 purple_account_new(const char *username, const char *protocol_id)
 {
@@ -805,16 +820,43 @@ purple_account_new(const char *username,
 	PurplePluginProtocolInfo *prpl_info = NULL;
 	PurpleStatusType *status_type;
 	PurpleAccountPrivate *priv;
+#ifdef HAVE_DBUS
+	char* dbus_path;
+	DBusGProxy* dbus_proxy;
+	GError *error = NULL;
+#endif
 
 	g_return_val_if_fail(username != NULL, NULL);
 	g_return_val_if_fail(protocol_id != NULL, NULL);
 
 #ifdef HAVE_DBUS
-	if(purple_core_get_remote_mode())
-		return (PurpleAccount *)dbus_g_proxy_new_for_name(purple_dbus_get_g_connection(),
-														DBUS_PURPLE_SERVICE,
-														DBUS_ACCOUNT_PATH, 
-														DBUS_ACCOUNT_INTERFACE);
+	/**
+	 * If we are in remote mode we only create a dummy object which
+	 * contains a dbus_proxy in its PurpleObject parent class.
+	 */
+	if(purple_core_get_remote_mode()) {
+		/* First, remotely create a new account */
+		dbus_proxy = dbus_g_proxy_new_for_name(purple_dbus_get_g_connection(),
+											DBUS_PURPLE_SERVICE,
+											DBUS_CONSTRUCTOR_PATH,
+											DBUS_CONSTRUCTOR_INTERFACE);
+		if (!im_pidgin_purple_constructor_new_account(dbus_proxy, username,
+													protocol_id, &dbus_path,
+													&error)) {
+			purple_debug_error("dbus", "Failed to remotely call purple_account_new: %s\n",
+							error->message);
+			g_error_free(error);
+			return NULL;
+		}
+
+		/* Then, locally create a dummy account that will hold a proxy */
+		dbus_proxy = dbus_g_proxy_new_for_name(purple_dbus_get_g_connection(),
+											DBUS_PURPLE_SERVICE, dbus_path,
+											DBUS_ACCOUNT_INTERFACE);
+		account = g_object_new(PURPLE_TYPE_ACCOUNT, NULL);
+		purple_object_set_dbus_proxy(PURPLE_OBJECT(account), dbus_proxy);
+		return account;
+	}
 #endif
 
 	account = purple_accounts_find(username, protocol_id);
@@ -833,7 +875,9 @@ purple_account_new(const char *username,
 
 	PURPLE_DBUS_REGISTER_POINTER(account, PurpleAccount);
 
-	PURPLE_DBUS_REGISTER_OBJECT(DBUS_ACCOUNT_PATH, account);
+	dbus_path = build_dbus_path(username, protocol_id);
+	PURPLE_DBUS_REGISTER_OBJECT(dbus_path, account);
+	g_free(dbus_path);
 
 	prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(prpl);
 	if (prpl_info != NULL && prpl_info->status_types != NULL)
@@ -3099,6 +3143,10 @@ purple_accounts_init(void)
 			}
 			/* We should also care about request_ret */
 		}
+
+		dbus_g_connection_register_g_object(purple_dbus_get_g_connection(),
+										DBUS_CONSTRUCTOR_PATH,
+										G_OBJECT(purple_constructor_get_instance()));
 	}
 #endif
 }
============================================================
--- libpurple/dbus-purple.h	832adde929eaddf164a190f4027a12fc7b4a8d6c
+++ libpurple/dbus-purple.h	7bd285c8383aa7aedfa4f3ad9966d11b9db854d6
@@ -32,4 +32,7 @@
 #define DBUS_ACCOUNT_PATH	"/im/pidgin/purple/account"
 #define DBUS_ACCOUNT_INTERFACE    "im.pidgin.purple.account"
 
+#define DBUS_CONSTRUCTOR_PATH      "/im/pidgin/purple/constructor"
+#define DBUS_CONSTRUCTOR_INTERFACE "im.pidgin.purple.constructor"
+
 #endif /* _DBUS_PURPLE_H_ */


More information about the Commits mailing list