/soc/2013/ankitkv/gobjectification: b2c73469c1be: GObjectified t...

Ankit Vani a at nevitus.org
Thu Jul 11 19:32:54 EDT 2013


Changeset: b2c73469c1bee0198956e7ba47d0d3331147ce82
Author:	 Ankit Vani <a at nevitus.org>
Date:	 2013-07-12 05:02 +0530
Branch:	 soc.2013.gobjectification
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/b2c73469c1be

Description:

GObjectified the PurpleConnection source

diffstat:

 libpurple/account.c    |   11 +-
 libpurple/connection.c |  660 +++++++++++++++++++++++++++++++++---------------
 libpurple/connection.h |    9 +-
 3 files changed, 463 insertions(+), 217 deletions(-)

diffs (truncated from 773 to 300 lines):

diff --git a/libpurple/account.c b/libpurple/account.c
--- a/libpurple/account.c
+++ b/libpurple/account.c
@@ -2808,8 +2808,7 @@ purple_account_set_property(GObject *obj
 					g_value_get_boolean(value));
 			break;
 		case PROP_CONNECTION:
-#warning TODO: change get_pointer to get_object when PurpleConnection is a GObject
-			purple_account_set_connection(account, g_value_get_pointer(value));
+			purple_account_set_connection(account, g_value_get_object(value));
 			break;
 		case PROP_PROTOCOL_ID:
 			purple_account_set_protocol_id(account, g_value_get_string(value));
@@ -2853,8 +2852,7 @@ purple_account_get_property(GObject *obj
 					purple_core_get_ui()));
 			break;
 		case PROP_CONNECTION:
-#warning TODO: change set_pointer to set_object when PurpleConnection is a GObject
-			g_value_set_pointer(value, purple_account_get_connection(account));
+			g_value_set_object(value, purple_account_get_connection(account));
 			break;
 		case PROP_PROTOCOL_ID:
 			g_value_set_string(value, purple_account_get_protocol_id(account));
@@ -3070,10 +3068,9 @@ purple_account_class_init(PurpleAccountC
 				G_PARAM_READWRITE)
 			);
 
-#warning TODO: change spec_pointer to spec_object when PurpleConnection is a GObject
 	g_object_class_install_property(obj_class, PROP_CONNECTION,
-			g_param_spec_pointer(PROP_CONNECTION_S, _("Connection"),
-				_("The PurpleConnection object for the account."),
+			g_param_spec_object(PROP_CONNECTION_S, _("Connection"),
+				_("The connection for the account."), PURPLE_TYPE_CONNECTION,
 				G_PARAM_READWRITE)
 			);
 
diff --git a/libpurple/connection.c b/libpurple/connection.c
--- a/libpurple/connection.c
+++ b/libpurple/connection.c
@@ -31,6 +31,7 @@
 #include "connection.h"
 #include "dbus-maybe.h"
 #include "debug.h"
+#include "enums.h"
 #include "http.h"
 #include "log.h"
 #include "notify.h"
@@ -84,12 +85,30 @@ struct _PurpleConnectionPrivate
 	                                prpl to avoid sending unneeded keepalives */
 };
 
+/* GObject property enums */
+enum
+{
+	PROP_0,
+	PROP_PRPL,
+	PROP_FLAGS,
+	PROP_STATE,
+	PROP_ACCOUNT,
+	PROP_PASSWORD,
+	PROP_DISPLAY_NAME,
+	PROP_LAST
+};
+
+static GObjectClass *parent_class;
+
 static GList *connections = NULL;
 static GList *connections_connecting = NULL;
 static PurpleConnectionUiOps *connection_ui_ops = NULL;
 
 static int connections_handle;
 
+/**************************************************************************
+ * Connection API
+ **************************************************************************/
 static gboolean
 send_keepalive(gpointer data)
 {
@@ -135,215 +154,6 @@ update_keepalive(PurpleConnection *gc, g
 	}
 }
 
-void
-_purple_connection_new(PurpleAccount *account, gboolean regist, const char *password)
-{
-	PurpleConnection *gc;
-	PurpleConnectionPrivate *priv;
-	PurplePlugin *prpl;
-	PurplePluginProtocolInfo *prpl_info;
-
-	g_return_if_fail(account != NULL);
-
-	if (!purple_account_is_disconnected(account))
-		return;
-
-	prpl = purple_find_prpl(purple_account_get_protocol_id(account));
-
-	if (prpl != NULL)
-		prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(prpl);
-	else {
-		gchar *message;
-
-		message = g_strdup_printf(_("Missing protocol plugin for %s"),
-			purple_account_get_username(account));
-		purple_notify_error(NULL, regist ? _("Registration Error") :
-						  _("Connection Error"), message, NULL);
-		g_free(message);
-		return;
-	}
-
-	if (regist)
-	{
-		if (prpl_info->register_user == NULL)
-			return;
-	}
-	else
-	{
-		if (((password == NULL) || (*password == '\0')) &&
-			!(prpl_info->options & OPT_PROTO_NO_PASSWORD) &&
-			!(prpl_info->options & OPT_PROTO_PASSWORD_OPTIONAL))
-		{
-			purple_debug_error("connection", "Cannot connect to account %s without "
-							 "a password.\n", purple_account_get_username(account));
-			return;
-		}
-	}
-
-	gc = g_object_new(PURPLE_TYPE_CONNECTION, NULL);
-	PURPLE_DBUS_REGISTER_POINTER(gc, PurpleConnection);
-
-	priv = PURPLE_CONNECTION_GET_PRIVATE(gc);
-
-	priv->prpl = prpl;
-	if ((password != NULL) && (*password != '\0'))
-		priv->password = g_strdup(password);
-	purple_connection_set_account(gc, account);
-	purple_connection_set_state(gc, PURPLE_CONNECTION_CONNECTING);
-	connections = g_list_append(connections, gc);
-	purple_account_set_connection(account, gc);
-
-	purple_signal_emit(purple_connections_get_handle(), "signing-on", gc);
-
-	if (regist)
-	{
-		purple_debug_info("connection", "Registering.  gc = %p\n", gc);
-
-		/* set this so we don't auto-reconnect after registering */
-		priv->wants_to_die = TRUE;
-
-		prpl_info->register_user(account);
-	}
-	else
-	{
-		purple_debug_info("connection", "Connecting. gc = %p\n", gc);
-
-		purple_signal_emit(purple_accounts_get_handle(), "account-connecting", account);
-		prpl_info->login(account);
-	}
-}
-
-void
-_purple_connection_new_unregister(PurpleAccount *account, const char *password, PurpleAccountUnregistrationCb cb, void *user_data)
-{
-	/* Lots of copy/pasted code to avoid API changes. You might want to integrate that into the previous function when posssible. */
-	PurpleConnection *gc;
-	PurpleConnectionPrivate *priv;
-	PurplePlugin *prpl;
-	PurplePluginProtocolInfo *prpl_info;
-
-	g_return_if_fail(account != NULL);
-
-	prpl = purple_find_prpl(purple_account_get_protocol_id(account));
-
-	if (prpl != NULL)
-		prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(prpl);
-	else {
-		gchar *message;
-
-		message = g_strdup_printf(_("Missing protocol plugin for %s"),
-								  purple_account_get_username(account));
-		purple_notify_error(NULL, _("Unregistration Error"), message, NULL);
-		g_free(message);
-		return;
-	}
-
-	if (!purple_account_is_disconnected(account)) {
-		prpl_info->unregister_user(account, cb, user_data);
-		return;
-	}
-
-	if (((password == NULL) || (*password == '\0')) &&
-		!(prpl_info->options & OPT_PROTO_NO_PASSWORD) &&
-		!(prpl_info->options & OPT_PROTO_PASSWORD_OPTIONAL))
-	{
-		purple_debug_error("connection", "Cannot connect to account %s without "
-						   "a password.\n", purple_account_get_username(account));
-		return;
-	}
-
-	gc = g_object_new(PURPLE_TYPE_CONNECTION, NULL);
-	PURPLE_DBUS_REGISTER_POINTER(gc, PurpleConnection);
-
-	priv = PURPLE_CONNECTION_GET_PRIVATE(gc);
-
-	priv->prpl = prpl;
-	if ((password != NULL) && (*password != '\0'))
-		priv->password = g_strdup(password);
-	purple_connection_set_account(gc, account);
-	purple_connection_set_state(gc, PURPLE_CONNECTION_CONNECTING);
-	connections = g_list_append(connections, gc);
-	purple_account_set_connection(account, gc);
-
-	purple_signal_emit(purple_connections_get_handle(), "signing-on", gc);
-
-	purple_debug_info("connection", "Unregistering.  gc = %p\n", gc);
-
-	prpl_info->unregister_user(account, cb, user_data);
-}
-
-void
-_purple_connection_destroy(PurpleConnection *gc)
-{
-	PurpleAccount *account;
-	GSList *buddies;
-	PurplePluginProtocolInfo *prpl_info = NULL;
-	gboolean remove = FALSE;
-	PurpleConnectionPrivate *priv = PURPLE_CONNECTION_GET_PRIVATE(gc);
-
-	g_return_if_fail(priv != NULL);
-
-	account = purple_connection_get_account(gc);
-
-	purple_debug_info("connection", "Disconnecting connection %p\n", gc);
-
-	if (purple_connection_get_state(gc) != PURPLE_CONNECTION_CONNECTING)
-		remove = TRUE;
-
-	purple_signal_emit(purple_connections_get_handle(), "signing-off", gc);
-
-	while (priv->buddy_chats)
-	{
-		PurpleChatConversation *b = priv->buddy_chats->data;
-
-		priv->buddy_chats = g_slist_remove(priv->buddy_chats, b);
-		purple_chat_conversation_leave(b);
-	}
-
-	update_keepalive(gc, FALSE);
-
-	purple_http_conn_cancel_all(gc);
-	purple_proxy_connect_cancel_with_handle(gc);
-
-	prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(priv->prpl);
-	if (prpl_info->close)
-		(prpl_info->close)(gc);
-
-	/* Clear out the proto data that was freed in the prpl close method*/
-	buddies = purple_blist_find_buddies(account, NULL);
-	while (buddies != NULL) {
-		PurpleBuddy *buddy = buddies->data;
-		purple_buddy_set_protocol_data(buddy, NULL);
-		buddies = g_slist_delete_link(buddies, buddies);
-	}
-
-	connections = g_list_remove(connections, gc);
-
-	purple_connection_set_state(gc, PURPLE_CONNECTION_DISCONNECTED);
-
-	if (remove)
-		purple_blist_remove_account(account);
-
-	purple_signal_emit(purple_connections_get_handle(), "signed-off", gc);
-
-	purple_account_request_close_with_account(account);
-	purple_request_close_with_handle(gc);
-	purple_notify_close_with_handle(gc);
-
-	purple_debug_info("connection", "Destroying connection %p\n", gc);
-
-	purple_account_set_connection(account, NULL);
-
-	purple_str_wipe(priv->password);
-	g_free(priv->display_name);
-
-	if (priv->disconnect_timeout > 0)
-		purple_timeout_remove(priv->disconnect_timeout);
-
-	PURPLE_DBUS_UNREGISTER_POINTER(gc);
-	g_free(gc);
-}
-
 /*
  * d:)->-<
  *
@@ -531,6 +341,16 @@ purple_connection_get_password(const Pur
 	return priv->password;
 }
 
+GSList *
+purple_connection_get_active_chats(const PurpleConnection *gc)



More information about the Commits mailing list