/soc/2013/ankitkv/gobjectification: ab3f70aaaf17: Added GObject ...

Ankit Vani a at nevitus.org
Wed Jun 19 06:22:08 EDT 2013


Changeset: ab3f70aaaf17849291adfd05b438f4bca9ed9bda
Author:	 Ankit Vani <a at nevitus.org>
Date:	 2013-06-18 21:28 +0530
Branch:	 soc.2013.gobjectification
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/ab3f70aaaf17

Description:

Added GObject code to PurpleAccount. Changed PurpleAccountSetting to GValue.

diffstat:

 libpurple/account.c  |  914 ++++++++++++++++++++++++++++++++++++--------------
 libpurple/accounts.c |    7 +-
 2 files changed, 659 insertions(+), 262 deletions(-)

diffs (truncated from 1707 to 300 lines):

diff --git a/libpurple/account.c b/libpurple/account.c
--- a/libpurple/account.c
+++ b/libpurple/account.c
@@ -91,25 +91,6 @@ typedef struct
 	PurpleConnectionErrorInfo *current_error;	/**< Errors */
 } PurpleAccountPrivate;
 
-#if 0
-/* TODO Use GValue instead */
-typedef struct
-{
-	PurplePrefType type;
-
-	char *ui;
-
-	union
-	{
-		int integer;
-		char *string;
-		gboolean boolean;
-
-	} value;
-
-} PurpleAccountSetting;
-#endif
-
 typedef struct
 {
 	PurpleAccountRequestType type;
@@ -128,133 +109,42 @@ typedef struct
 	gpointer data;
 } PurpleCallbackBundle;
 
+static GObjectClass *parent_class = NULL;
+
+/* GObject Property enums */
+enum
+{
+	PROP_0,
+	PROP_USERNAME,
+	PROP_PASSWORD,
+	PROP_PRIVATE_ALIAS,
+	PROP_PUBLIC_ALIAS,
+	PROP_ENABLED,
+	PROP_CONNECTION,
+	PROP_PROTOCOL_ID,
+	PROP_USER_INFO,
+	PROP_BUDDY_ICON_PATH,
+	PROP_REMEMBER_PASSWORD,
+	PROP_CHECK_MAIL,
+	PROP_LAST
+};
+
+
 static void set_current_error(PurpleAccount *account,
 	PurpleConnectionErrorInfo *new_err);
 
 
-PurpleAccount *
-purple_account_new(const char *username, const char *protocol_id)
-{
-	PurpleAccount *account = NULL;
-	PurplePlugin *prpl = NULL;
-	PurplePluginProtocolInfo *prpl_info = NULL;
-	PurpleStatusType *status_type;
-
-	g_return_val_if_fail(username != NULL, NULL);
-	g_return_val_if_fail(protocol_id != NULL, NULL);
-
-	account = purple_accounts_find(username, protocol_id);
-
-	if (account != NULL)
-		return account;
-
-	account = g_new0(PurpleAccount, 1);
-	PURPLE_DBUS_REGISTER_POINTER(account, PurpleAccount);
-
-	purple_account_set_username(account, username);
-
-	purple_account_set_protocol_id(account, protocol_id);
-
-	account->settings = g_hash_table_new_full(g_str_hash, g_str_equal,
-											  g_free, delete_setting);
-	account->ui_settings = g_hash_table_new_full(g_str_hash, g_str_equal,
-				g_free, (GDestroyNotify)g_hash_table_destroy);
-	account->system_log = NULL;
-	/* 0 is not a valid privacy setting */
-	account->perm_deny = PURPLE_PRIVACY_ALLOW_ALL;
-
-	purple_signal_emit(purple_accounts_get_handle(), "account-created", account);
-
-	prpl = purple_find_prpl(protocol_id);
-
-	if (prpl == NULL)
-		return account;
-
-	prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(prpl);
-	if (prpl_info != NULL && prpl_info->status_types != NULL)
-		purple_account_set_status_types(account, prpl_info->status_types(account));
-
-	account->presence = purple_presence_new_for_account(account);
-
-	status_type = purple_account_get_status_type_with_primitive(account, PURPLE_STATUS_AVAILABLE);
-	if (status_type != NULL)
-		purple_presence_set_status_active(account->presence,
-										purple_status_type_get_id(status_type),
-										TRUE);
-	else
-		purple_presence_set_status_active(account->presence,
-										"offline",
-										TRUE);
-
-	return account;
-}
-
-void
-purple_account_destroy(PurpleAccount *account)
-{
-	GList *l;
-
-	g_return_if_fail(account != NULL);
-
-	purple_debug_info("account", "Destroying account %p\n", account);
-	purple_signal_emit(purple_accounts_get_handle(), "account-destroying", account);
-
-	for (l = purple_get_conversations(); l != NULL; l = l->next)
-	{
-		PurpleConversation *conv = (PurpleConversation *)l->data;
-
-		if (purple_conversation_get_account(conv) == account)
-			purple_conversation_set_account(conv, NULL);
-	}
-
-	g_free(account->username);
-	g_free(account->alias);
-	purple_str_wipe(account->password);
-	g_free(account->user_info);
-	g_free(account->buddy_icon_path);
-	g_free(account->protocol_id);
-
-	g_hash_table_destroy(account->settings);
-	g_hash_table_destroy(account->ui_settings);
-
-	if (account->proxy_info)
-		purple_proxy_info_destroy(account->proxy_info);
-
-	purple_account_set_status_types(account, NULL);
-
-	if (account->presence)
-		purple_presence_destroy(account->presence);
-
-	if(account->system_log)
-		purple_log_free(account->system_log);
-
-	while (account->deny) {
-		g_free(account->deny->data);
-		account->deny = g_slist_delete_link(account->deny, account->deny);
-	}
-
-	while (account->permit) {
-		g_free(account->permit->data);
-		account->permit = g_slist_delete_link(account->permit, account->permit);
-	}
-
-	PURPLE_DBUS_UNREGISTER_POINTER(account->current_error);
-	if (account->current_error) {
-		g_free(account->current_error->description);
-		g_free(account->current_error);
-	}
-
-	PURPLE_DBUS_UNREGISTER_POINTER(account);
-	g_free(account);
-}
-
 void
 purple_account_set_register_callback(PurpleAccount *account, PurpleAccountRegistrationCb cb, void *user_data)
 {
+	PurpleAccountPrivate *priv;
+
 	g_return_if_fail(account != NULL);
 
-	account->registration_cb = cb;
-	account->registration_cb_user_data = user_data;
+	priv = PURPLE_ACCOUNT_GET_PRIVATE(account);
+
+	priv->registration_cb = cb;
+	priv->registration_cb_user_data = user_data;
 }
 
 static void
@@ -294,10 +184,14 @@ purple_account_unregister_got_password_c
 void
 purple_account_register_completed(PurpleAccount *account, gboolean succeeded)
 {
+	PurpleAccountPrivate *priv;
+
 	g_return_if_fail(account != NULL);
 
-	if (account->registration_cb)
-		(account->registration_cb)(account, succeeded, account->registration_cb_user_data);
+	priv = PURPLE_ACCOUNT_GET_PRIVATE(account);
+
+	if (priv->registration_cb)
+		(priv->registration_cb)(account, succeeded, priv->registration_cb_user_data);
 }
 
 void
@@ -410,6 +304,7 @@ purple_account_connect(PurpleAccount *ac
 	PurplePlugin *prpl;
 	const char *username;
 	PurplePluginProtocolInfo *prpl_info;
+	PurpleAccountPrivate *priv;
 
 	g_return_if_fail(account != NULL);
 
@@ -432,12 +327,14 @@ purple_account_connect(PurpleAccount *ac
 		return;
 	}
 
+	priv = PURPLE_ACCOUNT_GET_PRIVATE(account);
+
 	purple_debug_info("account", "Connecting to account %s.\n", username);
 
 	prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(prpl);
-	if (account->password != NULL) {
+	if (priv->password != NULL) {
 		purple_account_connect_got_password_cb(account,
-			account->password, NULL, prpl_info);
+			priv->password, NULL, prpl_info);
 	} else {
 		purple_keyring_get_password(account,
 			purple_account_connect_got_password_cb, prpl_info);
@@ -448,30 +345,36 @@ void
 purple_account_disconnect(PurpleAccount *account)
 {
 	PurpleConnection *gc;
+	PurpleAccountPrivate *priv;
 	const char *username;
 
 	g_return_if_fail(account != NULL);
 	g_return_if_fail(!purple_account_is_disconnected(account));
 
+	priv = PURPLE_ACCOUNT_GET_PRIVATE(account);
+
 	username = purple_account_get_username(account);
 	purple_debug_info("account", "Disconnecting account %s (%p)\n",
 	                  username ? username : "(null)", account);
 
-	account->disconnecting = TRUE;
+	priv->disconnecting = TRUE;
 
 	gc = purple_account_get_connection(account);
 	_purple_connection_destroy(gc);
 	purple_account_set_connection(account, NULL);
 
-	account->disconnecting = FALSE;
+	priv->disconnecting = FALSE;
 }
 
 gboolean
 purple_account_is_disconnecting(const PurpleAccount *account)
 {
+	PurpleAccountPrivate *priv;
+
 	g_return_val_if_fail(account != NULL, TRUE);
-	
-	return account->disconnecting;
+
+	priv = PURPLE_ACCOUNT_GET_PRIVATE(account);
+	return priv->disconnecting;
 }
 
 void
@@ -803,11 +706,14 @@ void
 purple_account_set_username(PurpleAccount *account, const char *username)
 {
 	PurpleBlistUiOps *blist_ops;
+	PurpleAccountPrivate *priv;
 
 	g_return_if_fail(account != NULL);
 
-	g_free(account->username);
-	account->username = g_strdup(username);
+	priv = PURPLE_ACCOUNT_GET_PRIVATE(account);
+
+	g_free(priv->username);
+	priv->username = g_strdup(username);
 
 	schedule_accounts_save();
 
@@ -822,10 +728,14 @@ void
 purple_account_set_password(PurpleAccount *account, const gchar *password,
 	PurpleKeyringSaveCallback cb, gpointer data)
 {
+	PurpleAccountPrivate *priv;
+
 	g_return_if_fail(account != NULL);
 
-	purple_str_wipe(account->password);
-	account->password = g_strdup(password);



More information about the Commits mailing list