/soc/2013/ankitkv/gobjectification: d9079090f7fe: Updated gtkbli...

Ankit Vani a at nevitus.org
Fri Jun 28 13:45:07 EDT 2013


Changeset: d9079090f7fe222a920b17dc12d11ad8cd8e9b1e
Author:	 Ankit Vani <a at nevitus.org>
Date:	 2013-06-28 23:14 +0530
Branch:	 soc.2013.gobjectification
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/d9079090f7fe

Description:

Updated gtkblist and gtkconv to use the GObject conversation API

diffstat:

 pidgin/gtkblist.c |  109 +++----
 pidgin/gtkconv.c  |  667 ++++++++++++++++++++++++-----------------------------
 pidgin/gtkconv.h  |    2 +-
 3 files changed, 353 insertions(+), 425 deletions(-)

diffs (truncated from 2070 to 300 lines):

diff --git a/pidgin/gtkblist.c b/pidgin/gtkblist.c
--- a/pidgin/gtkblist.c
+++ b/pidgin/gtkblist.c
@@ -376,9 +376,8 @@ find_conversation_with_buddy(PurpleBuddy
 	PidginBlistNode *ui = purple_blist_node_get_ui_data(PURPLE_BLIST_NODE(buddy));
 	if (ui)
 		return ui->conv.conv;
-	return purple_conversations_find_with_account(PURPLE_CONV_TYPE_IM,
-									     purple_buddy_get_name(buddy),
-									     purple_buddy_get_account(buddy));
+	return PURPLE_CONVERSATION(purple_conversations_find_im_with_account(
+			purple_buddy_get_name(buddy), purple_buddy_get_account(buddy)));
 }
 
 static void gtk_blist_join_chat(PurpleChat *chat)
@@ -405,8 +404,8 @@ static void gtk_blist_join_chat(PurpleCh
 	else
 		name = purple_chat_get_name(chat);
 
-	conv = purple_conversations_find_chat_with_account(name,
-	                                             account);
+	conv = PURPLE_CONVERSATION(purple_conversations_find_chat_with_account(name,
+			account));
 
 	if (conv != NULL) {
 		pidgin_conv_attach_to_conversation(conv);
@@ -3836,7 +3835,7 @@ static char *pidgin_get_tooltip_text(Pur
 		GList *cur;
 		struct proto_chat_entry *pce;
 		char *name, *value;
-		PurpleConversation *conv;
+		PurpleChatConversation *conv;
 		PidginBlistNode *bnode = purple_blist_node_get_ui_data(node);
 
 		chat = (PurpleChat *)node;
@@ -3852,7 +3851,7 @@ static char *pidgin_get_tooltip_text(Pur
 		}
 
 		if (bnode && bnode->conv.conv) {
-			conv = bnode->conv.conv;
+			conv = PURPLE_CHAT_CONVERSATION(bnode->conv.conv);
 		} else {
 			char *chat_name;
 			if (prpl_info && prpl_info->get_chat_name)
@@ -3865,12 +3864,12 @@ static char *pidgin_get_tooltip_text(Pur
 			g_free(chat_name);
 		}
 
-		if (conv && !purple_chat_conversation_has_left(PURPLE_CONV_CHAT(conv))) {
+		if (conv && !purple_chat_conversation_has_left(conv)) {
 			g_string_append_printf(str, _("\n<b>Occupants:</b> %d"),
-					g_list_length(purple_chat_conversation_get_users(PURPLE_CONV_CHAT(conv))));
+					g_list_length(purple_chat_conversation_get_users(conv)));
 
 			if (prpl_info && (prpl_info->options & OPT_PROTO_CHAT_TOPIC)) {
-				const char *chattopic = purple_chat_conversation_get_topic(PURPLE_CONV_CHAT(conv));
+				const char *chattopic = purple_chat_conversation_get_topic(conv);
 				char *topic = chattopic ? g_markup_escape_text(chattopic, -1) : NULL;
 				g_string_append_printf(str, _("\n<b>Topic:</b> %s"), topic ? topic : _("(no topic set)"));
 				g_free(topic);
@@ -4842,8 +4841,7 @@ written_msg_update_ui_cb(PurpleAccount *
 			!(flag & (PURPLE_MESSAGE_SEND | PURPLE_MESSAGE_RECV)))
 		return;
 	ui->conv.flags |= PIDGIN_BLIST_NODE_HAS_PENDING_MESSAGE;
-	if (purple_conversation_get_type(conv) == PURPLE_CONV_TYPE_CHAT
-			&& (flag & PURPLE_MESSAGE_NICK))
+	if (PURPLE_IS_CHAT_CONVERSATION(conv) && (flag & PURPLE_MESSAGE_NICK))
 		ui->conv.flags |= PIDGIN_BLIST_CHAT_HAS_PENDING_MESSAGE_WITH_NICK;
 
 	ui->conv.last_message = time(NULL);    /* XXX: for lack of better data */
@@ -4866,50 +4864,41 @@ conversation_created_cb(PurpleConversati
 {
 	PurpleAccount *account = purple_conversation_get_account(conv);
 
-	switch (purple_conversation_get_type(conv)) {
-		case PURPLE_CONV_TYPE_IM:
-			{
-				GSList *buddies = purple_find_buddies(account, purple_conversation_get_name(conv));
-				while (buddies) {
-					PurpleBlistNode *buddy = buddies->data;
-					struct _pidgin_blist_node *ui = purple_blist_node_get_ui_data(buddy);
-					buddies = g_slist_delete_link(buddies, buddies);
-					if (!ui)
-						continue;
-					ui->conv.conv = conv;
-					ui->conv.flags = 0;
-					ui->conv.last_message = 0;
-					purple_signal_connect(purple_conversations_get_handle(), "deleting-conversation",
-							ui, PURPLE_CALLBACK(conversation_deleted_update_ui_cb), ui);
-					purple_signal_connect(purple_conversations_get_handle(), "wrote-im-msg",
-							ui, PURPLE_CALLBACK(written_msg_update_ui_cb), buddy);
-					purple_signal_connect(pidgin_conversations_get_handle(), "conversation-displayed",
-							ui, PURPLE_CALLBACK(displayed_msg_update_ui_cb), buddy);
-				}
-			}
-			break;
-		case PURPLE_CONV_TYPE_CHAT:
-			{
-				PurpleChat *chat = purple_blist_find_chat(account, purple_conversation_get_name(conv));
-				struct _pidgin_blist_node *ui;
-				if (!chat)
-					break;
-				ui = purple_blist_node_get_ui_data(&(chat->node));
-				if (!ui)
-					break;
-				ui->conv.conv = conv;
-				ui->conv.flags = 0;
-				ui->conv.last_message = 0;
-				purple_signal_connect(purple_conversations_get_handle(), "deleting-conversation",
-						ui, PURPLE_CALLBACK(conversation_deleted_update_ui_cb), ui);
-				purple_signal_connect(purple_conversations_get_handle(), "wrote-chat-msg",
-						ui, PURPLE_CALLBACK(written_msg_update_ui_cb), chat);
-				purple_signal_connect(pidgin_conversations_get_handle(), "conversation-displayed",
-						ui, PURPLE_CALLBACK(displayed_msg_update_ui_cb), chat);
-			}
-			break;
-		default:
-			break;
+	if (PURPLE_IS_IM_CONVERSATION(conv)) {
+		GSList *buddies = purple_find_buddies(account, purple_conversation_get_name(conv));
+		while (buddies) {
+			PurpleBlistNode *buddy = buddies->data;
+			struct _pidgin_blist_node *ui = purple_blist_node_get_ui_data(buddy);
+			buddies = g_slist_delete_link(buddies, buddies);
+			if (!ui)
+				continue;
+			ui->conv.conv = conv;
+			ui->conv.flags = 0;
+			ui->conv.last_message = 0;
+			purple_signal_connect(purple_conversations_get_handle(), "deleting-conversation",
+					ui, PURPLE_CALLBACK(conversation_deleted_update_ui_cb), ui);
+			purple_signal_connect(purple_conversations_get_handle(), "wrote-im-msg",
+					ui, PURPLE_CALLBACK(written_msg_update_ui_cb), buddy);
+			purple_signal_connect(pidgin_conversations_get_handle(), "conversation-displayed",
+					ui, PURPLE_CALLBACK(displayed_msg_update_ui_cb), buddy);
+		}
+	} else {
+		PurpleChat *chat = purple_blist_find_chat(account, purple_conversation_get_name(conv));
+		struct _pidgin_blist_node *ui;
+		if (!chat)
+			return;
+		ui = purple_blist_node_get_ui_data(&(chat->node));
+		if (!ui)
+			return;
+		ui->conv.conv = conv;
+		ui->conv.flags = 0;
+		ui->conv.last_message = 0;
+		purple_signal_connect(purple_conversations_get_handle(), "deleting-conversation",
+				ui, PURPLE_CALLBACK(conversation_deleted_update_ui_cb), ui);
+		purple_signal_connect(purple_conversations_get_handle(), "wrote-chat-msg",
+				ui, PURPLE_CALLBACK(written_msg_update_ui_cb), chat);
+		purple_signal_connect(pidgin_conversations_get_handle(), "conversation-displayed",
+				ui, PURPLE_CALLBACK(displayed_msg_update_ui_cb), chat);
 	}
 }
 
@@ -7233,7 +7222,7 @@ add_buddy_cb(GtkWidget *w, int resp, Pid
 	PurpleAccount *account;
 	PurpleGroup *g;
 	PurpleBuddy *b;
-	PurpleConversation *c;
+	PurpleIMConversation *im;
 	PurpleBuddyIcon *icon;
 
 	if (resp == GTK_RESPONSE_OK)
@@ -7292,9 +7281,9 @@ add_buddy_cb(GtkWidget *w, int resp, Pid
 		 * Or something.  --Mark
 		 */
 
-		c = purple_conversations_find_im_with_account(who, data->rq_data.account);
-		if (c != NULL) {
-			icon = purple_im_conversation_get_icon(PURPLE_CONV_IM(c));
+		im = purple_conversations_find_im_with_account(who, data->rq_data.account);
+		if (im != NULL) {
+			icon = purple_im_conversation_get_icon(im);
 			if (icon != NULL)
 				purple_buddy_icon_update(icon);
 		}
diff --git a/pidgin/gtkconv.c b/pidgin/gtkconv.c
--- a/pidgin/gtkconv.c
+++ b/pidgin/gtkconv.c
@@ -171,7 +171,7 @@ typedef struct {
 	GtkWidget *entry;
 	GtkWidget *message;
 
-	PurpleConversation *conv;
+	PurpleChatConversation *chat;
 
 } InviteBuddyInfo;
 
@@ -201,7 +201,7 @@ static gboolean infopane_entry_activate(
 static void got_typing_keypress(PidginConversation *gtkconv, gboolean first);
 #endif
 static void gray_stuff_out(PidginConversation *gtkconv);
-static void add_chat_buddy_common(PurpleConversation *conv, PurpleChatConversationBuddy *cb, const char *old_name);
+static void add_chat_buddy_common(PurpleChatConversation *chat, PurpleChatConversationBuddy *cb, const char *old_name);
 static gboolean tab_complete(PurpleConversation *conv);
 static void pidgin_conv_updated(PurpleConversation *conv, PurpleConversationUpdateType type);
 static void conv_set_unseen(PurpleConversation *gtkconv, PidginUnseenState state);
@@ -211,7 +211,7 @@ static void update_typing_message(Pidgin
 gboolean pidgin_conv_has_focus(PurpleConversation *conv);
 static GArray* generate_nick_colors(guint numcolors, GdkColor background);
 static gboolean color_is_visible(GdkColor foreground, GdkColor background, int color_contrast, int brightness_contrast);
-static GtkTextTag *get_buddy_tag(PurpleConversation *conv, const char *who, PurpleMessageFlags flag, gboolean create);
+static GtkTextTag *get_buddy_tag(PurpleChatConversation *chat, const char *who, PurpleMessageFlags flag, gboolean create);
 static void pidgin_conv_update_fields(PurpleConversation *conv, PidginConvFields fields);
 static void focus_out_from_menubar(GtkWidget *wid, PidginWindow *win);
 static void pidgin_conv_tab_pack(PidginWindow *win, PidginConversation *gtkconv);
@@ -248,17 +248,13 @@ get_conversation_blist_node(PurpleConver
 	PurpleAccount *account = purple_conversation_get_account(conv);
 	PurpleBlistNode *node = NULL;
 
-	switch (purple_conversation_get_type(conv)) {
-		case PURPLE_CONV_TYPE_IM:
-			node = PURPLE_BLIST_NODE(purple_find_buddy(account, purple_conversation_get_name(conv)));
-			node = node ? node->parent : NULL;
-			break;
-		case PURPLE_CONV_TYPE_CHAT:
-			node = PURPLE_BLIST_NODE(purple_blist_find_chat(account, purple_conversation_get_name(conv)));
-			break;
-		default:
-			break;
-	}
+	if (PURPLE_IS_IM_CONVERSATION(conv)) {
+		node = PURPLE_BLIST_NODE(purple_find_buddy(account, purple_conversation_get_name(conv)));
+		node = node ? node->parent : NULL;
+	} else {
+		node = PURPLE_BLIST_NODE(purple_blist_find_chat(account, purple_conversation_get_name(conv)));
+	}
+
 	return node;
 }
 
@@ -271,7 +267,7 @@ close_this_sucker(gpointer data)
 {
 	PidginConversation *gtkconv = data;
 	GList *list = g_list_copy(gtkconv->convs);
-	g_list_foreach(list, (GFunc)purple_conversation_destroy, NULL);
+	g_list_foreach(list, (GFunc)g_object_unref, NULL);
 	g_list_free(list);
 	return FALSE;
 }
@@ -288,27 +284,18 @@ close_conv_cb(GtkButton *button, PidginC
 	PurpleAccount *account = purple_conversation_get_account(conv);
 	const char *name = purple_conversation_get_name(conv);
 
-	switch (purple_conversation_get_type(conv)) {
-		case PURPLE_CONV_TYPE_IM:
-		{
-			if (purple_prefs_get_bool(PIDGIN_PREFS_ROOT "/conversations/im/close_immediately"))
-				close_this_sucker(gtkconv);
-			else
-				hide_conv(gtkconv, TRUE);
-			break;
-		}
-		case PURPLE_CONV_TYPE_CHAT:
-		{
-			PurpleChat *chat = purple_blist_find_chat(account, name);
-			if (!chat ||
-					!purple_blist_node_get_bool(&chat->node, "gtk-persistent"))
-				close_this_sucker(gtkconv);
-			else
-				hide_conv(gtkconv, FALSE);
-			break;
-		}
-		default:
-			;
+	if (PURPLE_IS_IM_CONVERSATION(conv)) {
+		if (purple_prefs_get_bool(PIDGIN_PREFS_ROOT "/conversations/im/close_immediately"))
+			close_this_sucker(gtkconv);
+		else
+			hide_conv(gtkconv, TRUE);
+	} else {
+		PurpleChat *chat = purple_blist_find_chat(account, name);
+		if (!chat ||
+				!purple_blist_node_get_bool(&chat->node, "gtk-persistent"))
+			close_this_sucker(gtkconv);
+		else
+			hide_conv(gtkconv, FALSE);
 	}
 
 	return TRUE;
@@ -362,10 +349,7 @@ static PurpleCmdRet
 say_command_cb(PurpleConversation *conv,
               const char *cmd, char **args, char **error, void *data)
 {
-	if (purple_conversation_get_type(conv) == PURPLE_CONV_TYPE_IM)
-		purple_im_conversation_send(PURPLE_CONV_IM(conv), args[0]);
-	else if (purple_conversation_get_type(conv) == PURPLE_CONV_TYPE_CHAT)
-		purple_chat_conversation_send(PURPLE_CONV_CHAT(conv), args[0]);
+	purple_conversation_send(conv, args[0]);
 
 	return PURPLE_CMD_RET_OK;
 }
@@ -377,11 +361,7 @@ me_command_cb(PurpleConversation *conv,
 	char *tmp;
 
 	tmp = g_strdup_printf("/me %s", args[0]);
-
-	if (purple_conversation_get_type(conv) == PURPLE_CONV_TYPE_IM)



More information about the Commits mailing list