/soc/2013/ankitkv/gobjectification: 3d99b9c0bf90: Refactored acc...

Ankit Vani a at nevitus.org
Thu Aug 29 15:57:32 EDT 2013


Changeset: 3d99b9c0bf9082aef2ce8fb4076e89264a3c6387
Author:	 Ankit Vani <a at nevitus.org>
Date:	 2013-08-30 01:27 +0530
Branch:	 soc.2013.gobjectification.plugins
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/3d99b9c0bf90

Description:

Refactored account, blist, buddyicon, connection, conversation, presence to use the new protocol API

diffstat:

 libpurple/account.c           |  30 +++++++++++++++---------------
 libpurple/blistnodetypes.c    |   6 +++---
 libpurple/buddyicon.c         |   2 +-
 libpurple/buddylist.c         |   2 +-
 libpurple/connection.c        |  26 +++++++-------------------
 libpurple/conversationtypes.c |   3 +--
 libpurple/presence.c          |   2 +-
 libpurple/protocol.h          |   1 +
 8 files changed, 30 insertions(+), 42 deletions(-)

diffs (267 lines):

diff --git a/libpurple/account.c b/libpurple/account.c
--- a/libpurple/account.c
+++ b/libpurple/account.c
@@ -1023,7 +1023,7 @@ purple_account_set_public_alias(PurpleAc
 	gc = purple_account_get_connection(account);
 	protocol = purple_connection_get_protocol_info(gc);
 
-	if (PURPLE_PROTOCOL_PLUGIN_HAS_FUNC(protocol, set_public_alias))
+	if (PURPLE_PROTOCOL_GET_INTERFACE(protocol)->set_public_alias)
 		purple_protocol_iface_set_public_alias(protocol, gc, alias, success_cb, failure_cb);
 	else if (failure_cb) {
 		struct public_alias_closure *closure =
@@ -1061,7 +1061,7 @@ purple_account_get_public_alias(PurpleAc
 	gc = purple_account_get_connection(account);
 	protocol = purple_connection_get_protocol_info(gc);
 
-	if (PURPLE_PROTOCOL_PLUGIN_HAS_FUNC(protocol, get_public_alias))
+	if (PURPLE_PROTOCOL_GET_INTERFACE(protocol)->get_public_alias)
 		purple_protocol_iface_get_public_alias(protocol, gc, success_cb, failure_cb);
 	else if (failure_cb) {
 		struct public_alias_closure *closure =
@@ -1426,7 +1426,8 @@ purple_account_get_protocol_name(const P
 
 	p = purple_find_protocol_info(purple_account_get_protocol_id(account));
 
-	return ((p && p->name) ? _(p->name) : _("Unknown"));
+	return (p && purple_protocol_get_name(p) ?
+	        _(purple_protocol_get_name(p)) : _("Unknown"));
 }
 
 PurpleConnection *
@@ -2219,10 +2220,9 @@ purple_account_add_buddy(PurpleAccount *
 	if (gc != NULL)
 		protocol = purple_connection_get_protocol_info(gc);
 
-	if (protocol != NULL) {
-		if (PURPLE_PROTOCOL_PLUGIN_HAS_FUNC(protocol, add_buddy))
-			purple_protocol_iface_add_buddy(protocol, gc, buddy, purple_buddy_get_group(buddy), message);
-	}
+	if (protocol != NULL)
+		purple_protocol_iface_add_buddy(protocol, gc, buddy,
+				purple_buddy_get_group(buddy), message);
 }
 
 void
@@ -2243,9 +2243,9 @@ purple_account_add_buddies(PurpleAccount
 			groups = g_list_append(groups, purple_buddy_get_group(buddy));
 		}
 
-		if (PURPLE_PROTOCOL_PLUGIN_HAS_FUNC(protocol, add_buddies))
+		if (PURPLE_PROTOCOL_GET_INTERFACE(protocol)->add_buddies)
 			purple_protocol_iface_add_buddies(protocol, gc, buddies, groups, message);
-		else if (PURPLE_PROTOCOL_PLUGIN_HAS_FUNC(protocol, add_buddy)) {
+		else if (PURPLE_PROTOCOL_GET_INTERFACE(protocol)->add_buddy) {
 			GList *curb = buddies, *curg = groups;
 
 			while ((curb != NULL) && (curg != NULL)) {
@@ -2269,7 +2269,7 @@ purple_account_remove_buddy(PurpleAccoun
 	if (gc != NULL)
 		protocol = purple_connection_get_protocol_info(gc);
 
-	if (protocol && protocol->remove_buddy)
+	if (protocol)
 		purple_protocol_iface_remove_buddy(protocol, gc, buddy, group);
 }
 
@@ -2283,7 +2283,7 @@ purple_account_remove_buddies(PurpleAcco
 		protocol = purple_connection_get_protocol_info(gc);
 
 	if (protocol) {
-		if (protocol->remove_buddies)
+		if (PURPLE_PROTOCOL_GET_INTERFACE(protocol)->remove_buddies)
 			purple_protocol_iface_remove_buddies(protocol, gc, buddies, groups);
 		else {
 			GList *curb = buddies;
@@ -2306,7 +2306,7 @@ purple_account_remove_group(PurpleAccoun
 	if (gc != NULL)
 		protocol = purple_connection_get_protocol_info(gc);
 
-	if (protocol && protocol->remove_group)
+	if (protocol)
 		purple_protocol_iface_remove_group(protocol, gc, group);
 }
 
@@ -2322,7 +2322,7 @@ purple_account_change_password(PurpleAcc
 	if (gc != NULL)
 		protocol = purple_connection_get_protocol_info(gc);
 
-	if (protocol && protocol->change_passwd)
+	if (protocol)
 		purple_protocol_iface_change_passwd(protocol, gc, orig_pw, new_pw);
 }
 
@@ -2340,7 +2340,7 @@ gboolean purple_account_supports_offline
 
 	protocol = purple_connection_get_protocol_info(gc);
 
-	if (!protocol || !protocol->offline_message)
+	if (!protocol)
 		return FALSE;
 	return purple_protocol_iface_offline_message(protocol, buddy);
 }
@@ -2889,7 +2889,7 @@ purple_account_constructed(GObject *obje
 		return;
 	}
 
-	if (protocol->status_types != NULL)
+	if (PURPLE_PROTOCOL_GET_INTERFACE(protocol)->status_types != NULL)
 		purple_account_set_status_types(account,
 				purple_protocol_iface_status_types(protocol, account));
 
diff --git a/libpurple/blistnodetypes.c b/libpurple/blistnodetypes.c
--- a/libpurple/blistnodetypes.c
+++ b/libpurple/blistnodetypes.c
@@ -635,7 +635,7 @@ purple_buddy_dispose(GObject *object)
 	 * can free proto_data
 	 */
 	protocol = purple_find_protocol_info(purple_account_get_protocol_id(priv->account));
-	if (protocol && protocol->buddy_free)
+	if (protocol)
 		purple_protocol_iface_buddy_free(protocol, buddy);
 
 	/* Delete the node */
@@ -1122,7 +1122,7 @@ const char *purple_chat_get_name_only(Pu
 
 	protocol = purple_find_protocol_info(purple_account_get_protocol_id(priv->account));
 
-	if (protocol->chat_info) {
+	if (PURPLE_PROTOCOL_GET_INTERFACE(protocol)->chat_info) {
 		PurpleProtocolChatEntry *pce;
 		GList *parts = purple_protocol_iface_chat_info(protocol, purple_account_get_connection(priv->account));
 		pce = parts->data;
@@ -1534,7 +1534,7 @@ void purple_group_set_name(PurpleGroup *
 					buddies = g_list_append(buddies, (PurpleBlistNode *)buddy);
 			}
 
-			if(protocol->rename_group) {
+			if(PURPLE_PROTOCOL_GET_INTERFACE(protocol)->rename_group) {
 				purple_protocol_iface_rename_group(protocol, gc, old_name, source, buddies);
 			} else {
 				GList *cur, *groups = NULL;
diff --git a/libpurple/buddyicon.c b/libpurple/buddyicon.c
--- a/libpurple/buddyicon.c
+++ b/libpurple/buddyicon.c
@@ -750,7 +750,7 @@ purple_buddy_icons_set_account_icon(Purp
 		gc = purple_account_get_connection(account);
 		protocol = purple_connection_get_protocol_info(gc);
 
-		if (protocol && protocol->set_buddy_icon)
+		if (protocol)
 			purple_protocol_iface_set_buddy_icon(protocol, gc, img);
 	}
 
diff --git a/libpurple/buddylist.c b/libpurple/buddylist.c
--- a/libpurple/buddylist.c
+++ b/libpurple/buddylist.c
@@ -1636,7 +1636,7 @@ purple_blist_find_chat(PurpleAccount *ac
 
 	protocol = purple_find_protocol_info(purple_account_get_protocol_id(account));
 
-	if (protocol->find_blist_chat != NULL)
+	if (PURPLE_PROTOCOL_GET_INTERFACE(protocol)->find_blist_chat != NULL)
 		return purple_protocol_iface_find_blist_chat(protocol, account, name);
 
 	normname = g_strdup(purple_normalize(account, name));
diff --git a/libpurple/connection.c b/libpurple/connection.c
--- a/libpurple/connection.c
+++ b/libpurple/connection.c
@@ -120,8 +120,7 @@ send_keepalive(gpointer data)
 	if ((time(NULL) - priv->last_received) < KEEPALIVE_INTERVAL)
 		return TRUE;
 
-	if (priv->protocol->keepalive)
-		priv->purple_protocol_iface_keepalive(protocol, gc);
+	purple_protocol_iface_keepalive(priv->protocol, gc);
 
 	return TRUE;
 }
@@ -133,7 +132,7 @@ update_keepalive(PurpleConnection *gc, g
 
 	g_return_if_fail(priv != NULL);
 
-	if (!priv->protocol->keepalive)
+	if (!PURPLE_PROTOCOL_GET_INTERFACE(priv->protocol)->keepalive)
 		return;
 
 	if (on && !priv->keepalive)
@@ -559,21 +558,11 @@ void purple_connection_update_last_recei
 gsize
 purple_connection_get_max_message_size(PurpleConnection *gc)
 {
-	PurplePlugin *prpl;
-	PurplePluginProtocolInfo *prpl_info;
+	PurpleConnectionPrivate *priv = PURPLE_CONNECTION_GET_PRIVATE(gc);
 
-	g_return_val_if_fail(gc != NULL, 0);
+	g_return_val_if_fail(priv != NULL, 0);
 
-	prpl = purple_connection_get_prpl(gc);
-	g_return_val_if_fail(prpl != NULL, 0);
-
-	prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(prpl);
-	g_return_val_if_fail(prpl_info != NULL, 0);
-
-	if (!PURPLE_PROTOCOL_PLUGIN_HAS_FUNC(prpl_info, get_max_message_size))
-		return 0;
-
-	return prpl_info->get_max_message_size(gc);
+	return purple_protocol_iface_get_max_message_size(priv->protocol, gc);
 }
 
 /**************************************************************************
@@ -752,8 +741,7 @@ purple_connection_dispose(GObject *objec
 	purple_http_conn_cancel_all(gc);
 	purple_proxy_connect_cancel_with_handle(gc);
 
-	if (priv->protocol->close)
-		priv->purple_protocol_iface_close(protocol, gc);
+	purple_protocol_iface_close(priv->protocol, gc);
 
 	/* Clear out the proto data that was freed in the prpl close method*/
 	buddies = purple_blist_find_buddies(account, NULL);
@@ -909,7 +897,7 @@ void
 
 	if (regist)
 	{
-		if (protocol->register_user == NULL)
+		if (PURPLE_PROTOCOL_GET_INTERFACE(protocol)->register_user == NULL)
 			return;
 	}
 	else
diff --git a/libpurple/conversationtypes.c b/libpurple/conversationtypes.c
--- a/libpurple/conversationtypes.c
+++ b/libpurple/conversationtypes.c
@@ -465,8 +465,7 @@ purple_im_conversation_dispose(GObject *
 		if (purple_prefs_get_bool("/purple/conversations/im/send_typing"))
 			serv_send_typing(gc, name, PURPLE_IM_NOT_TYPING);
 
-		if (gc && protocol->convo_closed != NULL)
-			purple_protocol_iface_convo_closed(protocol, gc, name);
+		purple_protocol_iface_convo_closed(protocol, gc, name);
 	}
 
 	purple_im_conversation_stop_typing_timeout(im);
diff --git a/libpurple/presence.c b/libpurple/presence.c
--- a/libpurple/presence.c
+++ b/libpurple/presence.c
@@ -587,7 +587,7 @@ purple_account_presence_update_idle(Purp
 	if(PURPLE_CONNECTION_IS_CONNECTED(gc))
 		protocol = purple_connection_get_protocol_info(gc);
 
-	if (protocol && protocol->set_idle)
+	if (protocol)
 		purple_protocol_iface_set_idle(protocol, gc, (idle ? (current_time - idle_time) : 0));
 }
 
diff --git a/libpurple/protocol.h b/libpurple/protocol.h
--- a/libpurple/protocol.h
+++ b/libpurple/protocol.h
@@ -51,6 +51,7 @@ typedef struct _PurpleProtocolInterface 
 #include "ft.h"
 #include "imgstore.h"
 #include "media.h"
+#include "notify.h"
 #include "roomlist.h"
 #include "status.h"
 #include "whiteboard.h"



More information about the Commits mailing list