/soc/2013/ankitkv/gobjectification: 1f0650e7b1b5: Refactored fin...

Ankit Vani a at nevitus.org
Sat Aug 31 19:11:30 EDT 2013


Changeset: 1f0650e7b1b5ad466c7e0debb2b83814cc587c41
Author:	 Ankit Vani <a at nevitus.org>
Date:	 2013-09-01 03:53 +0530
Branch:	 soc.2013.gobjectification.plugins
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/1f0650e7b1b5

Description:

Refactored finch and a bit of libpurple plugins to use the new protocol API

diffstat:

 finch/gntaccount.c                    |   6 +++---
 finch/gntblist.c                      |  22 ++++++++++------------
 finch/gntconv.c                       |  24 ++++++++++++------------
 finch/gntroomlist.c                   |   4 ++--
 libpurple/plugins/log_reader.c        |   6 +++---
 libpurple/plugins/perl/common/Prpl.xs |   7 ++-----
 6 files changed, 32 insertions(+), 37 deletions(-)

diffs (254 lines):

diff --git a/finch/gntaccount.c b/finch/gntaccount.c
--- a/finch/gntaccount.c
+++ b/finch/gntaccount.c
@@ -251,7 +251,7 @@ save_account_cb(AccountEditDialog *dialo
 		gnt_box_give_focus_to_child(GNT_BOX(accounts.window), accounts.tree);
 	}
 
-	if (protocol && protocol->register_user &&
+	if (protocol && PURPLE_PROTOCOL_IMPLEMENTS(protocol, register_user) &&
 			gnt_check_box_get_checked(GNT_CHECK_BOX(dialog->regserver))) {
 		purple_account_register(account);
 	} else if (dialog->account == NULL) {
@@ -484,7 +484,7 @@ add_protocol_options(AccountEditDialog *
 	/* Show the registration checkbox only in a new account dialog,
 	 * and when the selected prpl has the support for it. */
 	gnt_widget_set_visible(dialog->regserver, account == NULL &&
-			protocol->register_user != NULL);
+			PURPLE_PROTOCOL_IMPLEMENTS(protocol, register_user));
 }
 
 static void
@@ -572,7 +572,7 @@ edit_account_continue(PurpleAccount *acc
 	for (iter = list; iter; iter = iter->next)
 	{
 		gnt_combo_box_add_data(GNT_COMBO_BOX(combo), iter->data,
-				((PurpleProtocol*)iter->data)->name);
+				purple_protocol_get_name(PURPLE_PROTOCOL(iter->data)));
 	}
 
 	protocol = purple_protocols_find(purple_account_get_protocol_id(account));
diff --git a/finch/gntblist.c b/finch/gntblist.c
--- a/finch/gntblist.c
+++ b/finch/gntblist.c
@@ -743,8 +743,7 @@ add_chat_cb(void *data, PurpleRequestFie
 
 	gc = purple_account_get_connection(account);
 	protocol = purple_connection_get_protocol(gc);
-	if (protocol->chat_info_defaults != NULL)
-		hash = purple_protocol_iface_chat_info_defaults(protocol, gc, name);
+	hash = purple_protocol_iface_chat_info_defaults(protocol, gc, name);
 
 	chat = purple_chat_new(account, name, hash);
 
@@ -1064,7 +1063,7 @@ append_proto_menu(GntMenu *menu, PurpleC
 	GList *list;
 	PurpleProtocol *protocol = purple_connection_get_protocol(gc);
 
-	if(!protocol || !protocol->blist_node_menu)
+	if(!protocol || !PURPLE_PROTOCOL_IMPLEMENTS(protocol, blist_node_menu))
 		return;
 
 	for(list = purple_protocol_iface_blist_node_menu(protocol, node); list;
@@ -1126,7 +1125,7 @@ chat_components_edit(PurpleBlistNode *se
 	purple_request_fields_add_group(fields, group);
 
 	gc = purple_account_get_connection(purple_chat_get_account(chat));
-	parts = purple_connection_get_protocol(gc)->chat_info(gc);
+	parts = purple_protocol_iface_chat_info(purple_connection_get_protocol(gc), gc);
 
 	for (iter = parts; iter; iter = iter->next) {
 		pce = iter->data;
@@ -1278,7 +1277,7 @@ create_buddy_menu(GntMenu *menu, PurpleB
 	PurpleConnection *gc = purple_account_get_connection(purple_buddy_get_account(buddy));
 
 	protocol = purple_connection_get_protocol(gc);
-	if (protocol && protocol->get_info)
+	if (protocol && PURPLE_PROTOCOL_IMPLEMENTS(protocol, get_info))
 	{
 		add_custom_action(menu, _("Get Info"),
 				PURPLE_CALLBACK(finch_blist_get_buddy_info_cb), buddy);
@@ -1287,9 +1286,9 @@ create_buddy_menu(GntMenu *menu, PurpleB
 	add_custom_action(menu, _("Add Buddy Pounce"),
 			PURPLE_CALLBACK(finch_blist_pounce_node_cb), buddy);
 
-	if (protocol && protocol->send_file)
+	if (protocol && PURPLE_PROTOCOL_IMPLEMENTS(protocol, send_file))
 	{
-		if (!protocol->can_receive_file ||
+		if (!PURPLE_PROTOCOL_IMPLEMENTS(protocol, can_receive_file) ||
 			purple_protocol_iface_can_receive_file(protocol, gc, purple_buddy_get_name(buddy)))
 			add_custom_action(menu, _("Send File"),
 					PURPLE_CALLBACK(finch_blist_menu_send_file_cb), buddy);
@@ -1416,7 +1415,7 @@ static void showlog_cb(PurpleBlistNode *
 		type = PURPLE_LOG_CHAT;
 		account = purple_chat_get_account(c);
 		protocol = purple_protocols_find(purple_account_get_protocol_id(account));
-		if (protocol && protocol->get_chat_name) {
+		if (protocol) {
 			name = purple_protocol_iface_get_chat_name(protocol, purple_chat_get_components(c));
 		}
 	} else if (PURPLE_IS_CONTACT(node)) {
@@ -1738,7 +1737,7 @@ tooltip_for_buddy(PurpleBuddy *buddy, GS
 	g_free(tmp);
 
 	protocol = purple_protocols_find(purple_account_get_protocol_id(account));
-	if (protocol && protocol->tooltip_text) {
+	if (protocol) {
 		purple_protocol_iface_tooltip_text(protocol, buddy, user_info, full);
 	}
 
@@ -2613,7 +2612,7 @@ reconstruct_accounts_menu(void)
 			continue;
 		protocol = purple_connection_get_protocol(gc);
 
-		if (PURPLE_PROTOCOL_PLUGIN_HAS_FUNC(protocol, get_actions)) {
+		if (PURPLE_PROTOCOL_IMPLEMENTS(protocol, get_actions)) {
 			item = gnt_menuitem_new(purple_account_get_username(account));
 			gnt_menu_add_item(GNT_MENU(sub), item);
 			build_protocol_actions(item, protocol, gc);
@@ -2817,8 +2816,7 @@ join_chat_select_cb(gpointer data, Purpl
 	chat = purple_blist_find_chat(account, name);
 	if (chat == NULL) {
 		PurpleProtocol *protocol = purple_connection_get_protocol(gc);
-		if (protocol->chat_info_defaults != NULL)
-			hash = purple_protocol_iface_chat_info_defaults(protocol, gc, name);
+		hash = purple_protocol_iface_chat_info_defaults(protocol, gc, name);
 	} else {
 		hash = purple_chat_get_components(chat);
 	}
diff --git a/finch/gntconv.c b/finch/gntconv.c
--- a/finch/gntconv.c
+++ b/finch/gntconv.c
@@ -339,9 +339,9 @@ account_signed_on_off(PurpleConnection *
 
 			chat = find_chat_for_conversation(conv);
 			if (chat == NULL) {
-				PurpleProtocol *info = purple_connection_get_protocol(gc);
-				if (info->chat_info_defaults != NULL)
-					comps = info->chat_info_defaults(gc, purple_conversation_get_name(conv));
+				PurpleProtocol *protocol = purple_connection_get_protocol(gc);
+				comps = purple_protocol_iface_chat_info_defaults(protocol, gc,
+						purple_conversation_get_name(conv));
 			} else {
 				comps = purple_chat_get_components(chat);
 			}
@@ -636,10 +636,10 @@ gg_create_menu(FinchConv *ggc)
 	if (PURPLE_IS_IM_CONVERSATION(ggc->active_conv)) {
 		PurpleAccount *account = purple_conversation_get_account(ggc->active_conv);
 		PurpleConnection *gc = purple_account_get_connection(account);
-		PurpleProtocol *pinfo =
+		PurpleProtocol *protocol =
 			gc ? purple_connection_get_protocol(gc) : NULL;
 
-		if (pinfo && pinfo->get_info) {
+		if (protocol && PURPLE_PROTOCOL_IMPLEMENTS(protocol, get_info)) {
 			item = gnt_menuitem_new(_("Get Info"));
 			gnt_menu_add_item(GNT_MENU(sub), item);
 			gnt_menuitem_set_callback(item, get_info_cb, ggc);
@@ -649,9 +649,10 @@ gg_create_menu(FinchConv *ggc)
 		gnt_menu_add_item(GNT_MENU(sub), item);
 		gnt_menuitem_set_callback(item, add_pounce_cb, ggc);
 
-		if (pinfo && pinfo->send_file &&
-				(!pinfo->can_receive_file ||
-					pinfo->can_receive_file(gc, purple_conversation_get_name(ggc->active_conv)))) {
+		if (protocol && PURPLE_PROTOCOL_IMPLEMENTS(protocol, send_file) &&
+				(!PURPLE_PROTOCOL_IMPLEMENTS(protocol, can_receive_file) ||
+					purple_protocol_iface_can_receive_file(protocol, gc,
+					purple_conversation_get_name(ggc->active_conv)))) {
 			item = gnt_menuitem_new(_("Send File"));
 			gnt_menu_add_item(GNT_MENU(sub), item);
 			gnt_menuitem_set_callback(item, send_file_cb, ggc);
@@ -693,7 +694,7 @@ create_conv_from_userlist(GntWidget *wid
 	PurpleAccount *account = purple_conversation_get_account(fc->active_conv);
 	PurpleConnection *gc = purple_account_get_connection(account);
 	PurpleProtocol *protocol = NULL;
-	char *name, *realname;
+	char *name, *realname = NULL;
 
 	if (!gc) {
 		purple_conversation_write(fc->active_conv, NULL, _("You are not connected."),
@@ -704,11 +705,10 @@ create_conv_from_userlist(GntWidget *wid
 	name = gnt_tree_get_selection_data(GNT_TREE(widget));
 
 	protocol = purple_connection_get_protocol(gc);
-	if (protocol && PURPLE_PROTOCOL_PLUGIN_HAS_FUNC(protocol, get_cb_real_name))
+	if (protocol)
 		realname = purple_protocol_iface_get_cb_real_name(protocol, gc, purple_chat_conversation_get_id(
 				PURPLE_CHAT_CONVERSATION(fc->active_conv)), name);
-	else
-		realname = NULL;
+
 	purple_im_conversation_new(account, realname ? realname : name);
 	g_free(realname);
 }
diff --git a/finch/gntroomlist.c b/finch/gntroomlist.c
--- a/finch/gntroomlist.c
+++ b/finch/gntroomlist.c
@@ -120,7 +120,7 @@ static void fl_add_chat(GntWidget *butto
 
 	protocol = purple_connection_get_protocol(gc);
 
-	if(protocol != NULL && protocol->roomlist_room_serialize)
+	if(protocol != NULL && PURPLE_PROTOCOL_IMPLEMENTS(protocol, roomlist_room_serialize))
 		name = purple_protocol_iface_roomlist_room_serialize(protocol, room);
 	else
 		name = g_strdup(purple_roomlist_room_get_name(room));
@@ -242,7 +242,7 @@ reset_account_list(PurpleAccount *accoun
 
 		protocol = purple_connection_get_protocol(gc);
 		if (PURPLE_CONNECTION_IS_CONNECTED(gc) &&
-		        protocol->roomlist_get_list != NULL) {
+		        PURPLE_PROTOCOL_IMPLEMENTS(protocol, roomlist_get_list)) {
 			PurpleAccount *account = purple_connection_get_account(gc);
 			char *text = g_strdup_printf("%s (%s)",
 					purple_account_get_username(account),
diff --git a/libpurple/plugins/log_reader.c b/libpurple/plugins/log_reader.c
--- a/libpurple/plugins/log_reader.c
+++ b/libpurple/plugins/log_reader.c
@@ -87,7 +87,7 @@ static GList *adium_logger_list(PurpleLo
 		return NULL;
 
 	protocol = PURPLE_PLUGIN_PROTOCOL_INFO(plugin);
-	if (!protocol->list_icon)
+	if (!PURPLE_PROTOCOL_IMPLEMENTS(protocol, list_icon))
 		return NULL;
 
 	protocol_name = g_ascii_strup(purple_protocol_iface_list_icon(protocol, account, NULL), -1);
@@ -1231,7 +1231,7 @@ static GList *trillian_logger_list(Purpl
 		return NULL;
 
 	protocol = PURPLE_PLUGIN_PROTOCOL_INFO(plugin);
-	if (!protocol->list_icon)
+	if (!PURPLE_PROTOCOL_IMPLEMENTS(protocoL, list_icon))
 		return NULL;
 
 	protocol_name = g_ascii_strup(purple_protocol_iface_list_icon(protocol, account, NULL), -1);
@@ -1791,7 +1791,7 @@ static GList *qip_logger_list(PurpleLogT
 		return NULL;
 
 	protocol = PURPLE_PLUGIN_PROTOCOL_INFO(plugin);
-	if (!protocol->list_icon)
+	if (!PURPLE_PROTOCOL_IMPLEMENTS(protocol, list_icon))
 		return NULL;
 
 	username = g_strdup(purple_normalize(account, purple_account_get_username(account)));
diff --git a/libpurple/plugins/perl/common/Prpl.xs b/libpurple/plugins/perl/common/Prpl.xs
--- a/libpurple/plugins/perl/common/Prpl.xs
+++ b/libpurple/plugins/perl/common/Prpl.xs
@@ -65,12 +65,9 @@ CODE:
 	if (!gc)
 		RETVAL = 0;
 	else {
-		protocol = PURPLE_PLUGIN_PROTOCOL_INFO(purple_connection_get_protocol(gc));
-		if (protocol && protocol->send_raw != NULL) {
+		protocol = purple_connection_get_protocol(gc);
+		if (protocol)
 			RETVAL = purple_protocol_iface_send_raw(protocol, gc, str, strlen(str));
-		} else {
-			RETVAL = 0;
-		}
 	}
 OUTPUT:
 	RETVAL



More information about the Commits mailing list