/soc/2013/ankitkv/gobjectification: b10d6297ffd5: Refactored fin...

Ankit Vani a at nevitus.org
Thu Jun 27 10:46:44 EDT 2013


Changeset: b10d6297ffd5694d3590166510eb8607932b3ff8
Author:	 Ankit Vani <a at nevitus.org>
Date:	 2013-06-27 20:16 +0530
Branch:	 soc.2013.gobjectification
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/b10d6297ffd5

Description:

Refactored finch to use the GObject conversation API

diffstat:

 finch/gntblist.c           |   35 ++++-----
 finch/gntconv.c            |  166 +++++++++++++++++---------------------------
 finch/gntmedia.c           |    6 +-
 finch/gntsound.c           |   43 +++++------
 finch/plugins/gntgf.c      |    9 +-
 finch/plugins/gnthistory.c |    6 +-
 finch/plugins/gnttinyurl.c |    2 +-
 7 files changed, 109 insertions(+), 158 deletions(-)

diffs (truncated from 724 to 300 lines):

diff --git a/finch/gntblist.c b/finch/gntblist.c
--- a/finch/gntblist.c
+++ b/finch/gntblist.c
@@ -707,7 +707,7 @@ join_chat(PurpleChat *chat)
 {
 	PurpleAccount *account = purple_chat_get_account(chat);
 	const char *name;
-	PurpleConversation *conv;
+	PurpleChatConversation *conv;
 	const char *alias;
 
 	/* This hack here is to work around the fact that there's no good way of
@@ -716,15 +716,14 @@ join_chat(PurpleChat *chat)
 	alias = chat->alias;
 	chat->alias = NULL;
 	name = purple_chat_get_name(chat);
-	conv = purple_conversations_find_with_account(
-			PURPLE_CONV_TYPE_CHAT, name, account);
+	conv = purple_conversations_find_chat_with_account(name, account);
 	chat->alias = (char *)alias;
 
-	if (!conv || purple_chat_conversation_has_left(PURPLE_CONV_CHAT(conv))) {
+	if (!conv || purple_chat_conversation_has_left(conv)) {
 		serv_join_chat(purple_account_get_connection(account),
 				purple_chat_get_components(chat));
 	} else if (conv) {
-		purple_conversation_present(conv);
+		purple_conversation_present(PURPLE_CONVERSATION(conv));
 	}
 }
 
@@ -1051,19 +1050,17 @@ selection_activate(GntWidget *widget, Fi
 	if (PURPLE_BLIST_NODE_IS_BUDDY(node))
 	{
 		PurpleBuddy *buddy = (PurpleBuddy *)node;
-		PurpleConversation *conv;
-		conv = purple_conversations_find_with_account(PURPLE_CONV_TYPE_IM,
-					purple_buddy_get_name(buddy),
+		PurpleIMConversation *im;
+		im = purple_conversations_find_im_with_account(purple_buddy_get_name(buddy),
 					purple_buddy_get_account(buddy));
-		if (!conv) {
-			conv =  purple_conversation_new(PURPLE_CONV_TYPE_IM,
-						purple_buddy_get_account(buddy),
+		if (!im) {
+			im =  purple_im_conversation_new(purple_buddy_get_account(buddy),
 						purple_buddy_get_name(buddy));
 		} else {
-			FinchConv *ggconv = FINCH_CONV(conv);
+			FinchConv *ggconv = FINCH_CONV(PURPLE_CONVERSATION(im));
 			gnt_window_present(ggconv->window);
 		}
-		finch_conversation_set_active(conv);
+		finch_conversation_set_active(PURPLE_CONVERSATION(im));
 	}
 	else if (PURPLE_BLIST_NODE_IS_CHAT(node))
 	{
@@ -2726,13 +2723,13 @@ send_im_select_cb(gpointer data, PurpleR
 {
 	PurpleAccount *account;
 	const char *username;
-	PurpleConversation *conv;
+	PurpleIMConversation *im;
 
 	account  = purple_request_fields_get_account(fields, "account");
 	username = purple_request_fields_get_string(fields,  "screenname");
 
-	conv = purple_im_conversation_new(account, username);
-	purple_conversation_present(conv);
+	im = purple_im_conversation_new(account, username);
+	purple_conversation_present(PURPLE_CONVERSATION(im));
 }
 
 static void
@@ -2779,7 +2776,7 @@ join_chat_select_cb(gpointer data, Purpl
 	PurpleConnection *gc;
 	PurpleChat *chat;
 	GHashTable *hash = NULL;
-	PurpleConversation *conv;
+	PurpleChatConversation *conv;
 
 	account = purple_request_fields_get_account(fields, "account");
 	name = purple_request_fields_get_string(fields,  "chat");
@@ -2793,9 +2790,9 @@ join_chat_select_cb(gpointer data, Purpl
 	 * a new conversation window will pop up when we finally join the chat. */
 	if (!(conv = purple_conversations_find_chat_with_account(name, account))) {
 		conv = purple_chat_conversation_new(account, name);
-		purple_chat_conversation_left(PURPLE_CONV_CHAT(conv));
+		purple_chat_conversation_leave(conv);
 	} else {
-		purple_conversation_present(conv);
+		purple_conversation_present(PURPLE_CONVERSATION(conv));
 	}
 
 	chat = purple_blist_find_chat(account, name);
diff --git a/finch/gntconv.c b/finch/gntconv.c
--- a/finch/gntconv.c
+++ b/finch/gntconv.c
@@ -94,17 +94,13 @@ get_conversation_blist_node(PurpleConver
 {
 	PurpleBlistNode *node = NULL;
 
-	switch (purple_conversation_get_type(conv)) {
-		case PURPLE_CONV_TYPE_IM:
-			node = (PurpleBlistNode*)find_buddy_for_conversation(conv);
-			node = node ? purple_blist_node_get_parent(node) : NULL;
-			break;
-		case PURPLE_CONV_TYPE_CHAT:
-			node = (PurpleBlistNode*)find_chat_for_conversation(conv);
-			break;
-		default:
-			break;
+	if (PURPLE_IS_IM_CONVERSATION(conv)) {
+		node = (PurpleBlistNode*)find_buddy_for_conversation(conv);
+		node = node ? purple_blist_node_get_parent(node) : NULL;
+	} else {
+		node = (PurpleBlistNode*)find_chat_for_conversation(conv);
 	}
+
 	return node;
 }
 
@@ -115,7 +111,7 @@ send_typing_notification(GntWidget *w, F
 	gboolean empty = (!text || !*text || (*text == '/'));
 	if (purple_prefs_get_bool("/finch/conversations/notify_typing")) {
 		PurpleConversation *conv = ggconv->active_conv;
-		PurpleIMConversation *im = PURPLE_CONV_IM(conv);
+		PurpleIMConversation *im = PURPLE_IM_CONVERSATION(conv);
 		if (!empty) {
 			gboolean send = (purple_im_conversation_get_send_typed_timeout(im) == 0);
 
@@ -172,7 +168,7 @@ entry_key_pressed(GntWidget *w, FinchCon
 						PURPLE_MESSAGE_NO_LOG, time(NULL));
 				break;
 			case PURPLE_CMD_STATUS_WRONG_TYPE:
-				if(purple_conversation_get_type(conv) == PURPLE_CONV_TYPE_IM)
+				if(PURPLE_IS_IM_CONVERSATION(conv))
 					purple_conversation_write(conv, "", _("That command only works in chats, not IMs."),
 							PURPLE_MESSAGE_NO_LOG, time(NULL));
 				else
@@ -194,18 +190,7 @@ entry_key_pressed(GntWidget *w, FinchCon
 	else
 	{
 		char *escape = purple_markup_escape_text((*text == '/' ? text + 1 : text), -1);
-		switch (purple_conversation_get_type(ggconv->active_conv))
-		{
-			case PURPLE_CONV_TYPE_IM:
-				purple_im_conversation_send_message(PURPLE_CONV_IM(ggconv->active_conv), escape, PURPLE_MESSAGE_SEND);
-				break;
-			case PURPLE_CONV_TYPE_CHAT:
-				purple_chat_conversation_send(PURPLE_CONV_CHAT(ggconv->active_conv), escape);
-				break;
-			default:
-				g_free(escape);
-				g_return_if_reached();
-		}
+		purple_conversation_send(ggconv->active_conv, escape);
 		g_free(escape);
 		purple_idle_touch();
 	}
@@ -221,7 +206,7 @@ closing_window(GntWidget *window, FinchC
 	while (list) {
 		PurpleConversation *conv = list->data;
 		list = list->next;
-		purple_conversation_destroy(conv);
+		g_object_unref(conv);
 	}
 }
 
@@ -241,12 +226,12 @@ save_position_cb(GntWidget *w, int x, in
 	purple_prefs_set_int(PREF_ROOT "/position/y", y);
 }
 
-static PurpleConversation *
-find_conv_with_contact(PurpleAccount *account, const char *name)
+static PurpleIMConversation *
+find_im_with_contact(PurpleAccount *account, const char *name)
 {
 	PurpleBlistNode *node;
 	PurpleBuddy *buddy = purple_find_buddy(account, name);
-	PurpleConversation *ret = NULL;
+	PurpleIMConversation *im = NULL;
 
 	if (!buddy)
 		return NULL;
@@ -255,11 +240,11 @@ find_conv_with_contact(PurpleAccount *ac
 				node; node = purple_blist_node_get_sibling_next(node)) {
 		if (node == (PurpleBlistNode*)buddy)
 			continue;
-		if ((ret = purple_conversations_find_with_account(PURPLE_CONV_TYPE_IM,
+		if ((im = purple_conversations_find_im_with_account(
 				purple_buddy_get_name((PurpleBuddy*)node), purple_buddy_get_account((PurpleBuddy*)node))) != NULL)
 			break;
 	}
-	return ret;
+	return im;
 }
 
 static char *
@@ -272,17 +257,17 @@ get_conversation_title(PurpleConversatio
 static void
 update_buddy_typing(PurpleAccount *account, const char *who, gpointer null)
 {
+	FinchConv *ggc;
+	PurpleIMConversation *im;
 	PurpleConversation *conv;
-	FinchConv *ggc;
-	PurpleIMConversation *im = NULL;
 	char *title, *str;
 
-	conv = purple_conversations_find_im_with_account(who, account);
+	im = purple_conversations_find_im_with_account(who, account);
 
-	if (!conv)
+	if (!im)
 		return;
 
-	im = PURPLE_CONV_IM(conv);
+	conv = PURPLE_CONVERSATION(im);
 	ggc = FINCH_CONV(conv);
 
 	if (purple_im_conversation_get_typing_state(im) == PURPLE_IM_CONVERSATION_TYPING) {
@@ -319,10 +304,10 @@ chat_left_cb(PurpleConversation *conv, g
 static void
 buddy_signed_on_off(PurpleBuddy *buddy, gpointer null)
 {
-	PurpleConversation *conv = find_conv_with_contact(purple_buddy_get_account(buddy), purple_buddy_get_name(buddy));
-	if (conv == NULL)
+	PurpleIMConversation *im = find_im_with_contact(purple_buddy_get_account(buddy), purple_buddy_get_name(buddy));
+	if (im == NULL)
 		return;
-	generate_send_to_menu(FINCH_CONV(conv));
+	generate_send_to_menu(FINCH_CONV(PURPLE_CONVERSATION(im)));
 }
 
 static void
@@ -331,10 +316,10 @@ account_signed_on_off(PurpleConnection *
 	GList *list = purple_conversations_get_ims();
 	while (list) {
 		PurpleConversation *conv = list->data;
-		PurpleConversation *cc = find_conv_with_contact(
+		PurpleIMConversation *cc = find_im_with_contact(
 				purple_conversation_get_account(conv), purple_conversation_get_name(conv));
 		if (cc)
-			generate_send_to_menu(FINCH_CONV(cc));
+			generate_send_to_menu(FINCH_CONV(PURPLE_CONVERSATION(cc)));
 		list = list->next;
 	}
 
@@ -377,7 +362,7 @@ account_signing_off(PurpleConnection *gc
 	 * them for rejoin on reconnect. */
 	while (list) {
 		PurpleConversation *conv = list->data;
-		if (!purple_chat_conversation_has_left(PURPLE_CONV_CHAT(conv)) &&
+		if (!purple_chat_conversation_has_left(PURPLE_CHAT_CONVERSATION(conv)) &&
 				purple_conversation_get_account(conv) == account) {
 			purple_conversation_set_data(conv, "want-to-rejoin", GINT_TO_POINTER(TRUE));
 			purple_conversation_write(conv, NULL, _("The account has disconnected and you are no "
@@ -518,8 +503,8 @@ send_to_cb(GntMenuItem *m, gpointer n)
 {
 	PurpleAccount *account = g_object_get_data(G_OBJECT(m), "purple_account");
 	gchar *buddy = g_object_get_data(G_OBJECT(m), "purple_buddy_name");
-	PurpleConversation *conv = purple_im_conversation_new(account, buddy);
-	finch_conversation_set_active(conv);
+	PurpleIMConversation *im = purple_im_conversation_new(account, buddy);
+	finch_conversation_set_active(PURPLE_CONVERSATION(im));
 }
 
 static void
@@ -536,12 +521,10 @@ view_log_cb(GntMenuItem *n, gpointer ggc
 	fc = ggc;
 	conv = fc->active_conv;
 
-	if (purple_conversation_get_type(conv) == PURPLE_CONV_TYPE_IM)
+	if (PURPLE_IS_IM_CONVERSATION(conv))
 		type = PURPLE_LOG_IM;
-	else if (purple_conversation_get_type(conv) == PURPLE_CONV_TYPE_CHAT)
+	else
 		type = PURPLE_LOG_CHAT;
-	else
-		return;
 
 	name = purple_conversation_get_name(conv);
 	account = purple_conversation_get_account(conv);
@@ -615,8 +598,8 @@ static void
 invite_cb(GntMenuItem *item, gpointer ggconv)
 {
 	FinchConv *fc = ggconv;
-	PurpleConversation *conv = fc->active_conv;
-	purple_chat_conversation_invite_user(PURPLE_CONV_CHAT(conv), NULL, NULL, TRUE);
+	PurpleChatConversation *chat = PURPLE_CHAT_CONVERSATION(fc->active_conv);
+	purple_chat_conversation_invite_user(chat, NULL, NULL, TRUE);
 }
 
 static void
@@ -650,7 +633,7 @@ gg_create_menu(FinchConv *ggc)
 	gnt_menu_add_item(GNT_MENU(sub), item);
 	gnt_menuitem_set_callback(item, toggle_timestamps_cb, ggc);
 
-	if (purple_conversation_get_type(ggc->active_conv) == PURPLE_CONV_TYPE_IM) {



More information about the Commits mailing list