/soc/2013/ankitkv/gobjectification: 3c3bed0fd13c: Refactored gg ...

Ankit Vani a at nevitus.org
Sun Jun 23 09:07:00 EDT 2013


Changeset: 3c3bed0fd13c56d8d7c3560882f398b6f58f6690
Author:	 Ankit Vani <a at nevitus.org>
Date:	 2013-06-23 18:34 +0530
Branch:	 soc.2013.gobjectification
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/3c3bed0fd13c

Description:

Refactored gg and irc protocols to use the GObject-based PurpleConversation

diffstat:

 libpurple/protocols/gg/confer.c      |    4 +-
 libpurple/protocols/gg/gg.c          |   10 +--
 libpurple/protocols/gg/image.c       |    3 +-
 libpurple/protocols/gg/pubdir-prpl.c |    2 +-
 libpurple/protocols/irc/cmds.c       |   17 ++---
 libpurple/protocols/irc/msgs.c       |  103 +++++++++++++++-------------------
 6 files changed, 60 insertions(+), 79 deletions(-)

diffs (truncated from 487 to 300 lines):

diff --git a/libpurple/protocols/gg/confer.c b/libpurple/protocols/gg/confer.c
--- a/libpurple/protocols/gg/confer.c
+++ b/libpurple/protocols/gg/confer.c
@@ -59,7 +59,7 @@ void ggp_confer_participants_add_uin(Pur
 
 			str_uin = g_strdup_printf("%lu", (unsigned long int)uin);
 			conv = ggp_confer_find_by_name(gc, chat_name);
-			purple_chat_conversation_add_user(PURPLE_CONV_CHAT(conv), str_uin, NULL,
+			purple_chat_conversation_add_user(PURPLE_CHAT_CONVERSATION(conv), str_uin, NULL,
 						PURPLE_CHAT_CONVERSATION_BUDDY_NONE, TRUE);
 
 			g_free(str_uin);
@@ -97,7 +97,7 @@ void ggp_confer_participants_add(PurpleC
 
 			str_uin = g_strdup_printf("%lu", (unsigned long int)recipients[i]);
 			conv = ggp_confer_find_by_name(gc, chat_name);
-			purple_chat_conversation_add_user(PURPLE_CONV_CHAT(conv),
+			purple_chat_conversation_add_user(PURPLE_CHAT_CONVERSATION(conv),
 						str_uin, NULL,
 						PURPLE_CHAT_CONVERSATION_BUDDY_NONE, TRUE);
 			g_free(str_uin);
diff --git a/libpurple/protocols/gg/gg.c b/libpurple/protocols/gg/gg.c
--- a/libpurple/protocols/gg/gg.c
+++ b/libpurple/protocols/gg/gg.c
@@ -417,8 +417,7 @@ void ggp_recv_message_handler(PurpleConn
 		PurpleAccount *account = purple_connection_get_account(gc);
 		PurpleConversation *conv;
 		const gchar *who = ggp_uin_to_str(ev->sender); // not really sender
-		conv = purple_conversations_find_with_account(
-			PURPLE_CONV_TYPE_IM, who, account);
+		conv = purple_conversations_find_im_with_account(who, account);
 		if (conv == NULL)
 			conv = purple_im_conversation_new(account, who);
 		purple_conversation_write(conv, purple_account_get_username(account), msg, PURPLE_MESSAGE_SEND, mtime);
@@ -444,7 +443,7 @@ void ggp_recv_message_handler(PurpleConn
 						    ev->recipients_count);
 		}
 		conv = ggp_confer_find_by_name(gc, chat_name);
-		chat_id = purple_chat_conversation_get_id(PURPLE_CONV_CHAT(conv));
+		chat_id = purple_chat_conversation_get_id(PURPLE_CHAT_CONVERSATION(conv));
 
 		serv_got_chat_in(gc, chat_id,
 			ggp_buddylist_get_buddy_name(gc, ev->sender),
@@ -1085,8 +1084,7 @@ static int ggp_send_im(PurpleConnection 
 			else if (prepare_result == GGP_IMAGE_PREPARE_TOO_BIG)
 			{
 				PurpleConversation *conv =
-					purple_conversations_find_with_account(
-						PURPLE_CONV_TYPE_IM, who,
+					purple_conversations_find_im_with_account(who,
 						purple_connection_get_account(gc));
 				purple_conversation_write(conv, "",
 					_("Image is too large, please try "
@@ -1215,7 +1213,7 @@ static void ggp_join_chat(PurpleConnecti
 
 	ggp_confer_add_new(gc, chat_name);
 	conv = serv_got_joined_chat(gc, info->chats_count, chat_name);
-	purple_chat_conversation_add_user(PURPLE_CONV_CHAT(conv),
+	purple_chat_conversation_add_user(PURPLE_CHAT_CONVERSATION(conv),
 				purple_account_get_username(account), NULL,
 				PURPLE_CHAT_CONVERSATION_BUDDY_NONE, TRUE);
 }
diff --git a/libpurple/protocols/gg/image.c b/libpurple/protocols/gg/image.c
--- a/libpurple/protocols/gg/image.c
+++ b/libpurple/protocols/gg/image.c
@@ -290,8 +290,7 @@ void ggp_image_send(PurpleConnection *gc
 		purple_imgstore_get_size(image));
 	purple_imgstore_unref(image);
 	
-	conv = purple_conversations_find_with_account(
-		PURPLE_CONV_TYPE_IM, pending_image->conv_name,
+	conv = purple_conversations_find_im_with_account(pending_image->conv_name, 
 		purple_connection_get_account(gc));
 	if (conv != NULL)
 		purple_conversation_write(conv, "", _("Image delivered."),
diff --git a/libpurple/protocols/gg/pubdir-prpl.c b/libpurple/protocols/gg/pubdir-prpl.c
--- a/libpurple/protocols/gg/pubdir-prpl.c
+++ b/libpurple/protocols/gg/pubdir-prpl.c
@@ -793,7 +793,7 @@ static void ggp_pubdir_search_results_ad
 static void ggp_pubdir_search_results_im(PurpleConnection *gc, GList *row,
 	gpointer _form)
 {
-	purple_conversation_present(purple_conversation_new(PURPLE_CONV_TYPE_IM,
+	purple_conversation_present(purple_im_conversation_new(
 		purple_connection_get_account(gc), g_list_nth_data(row, 0)));
 }
 
diff --git a/libpurple/protocols/irc/cmds.c b/libpurple/protocols/irc/cmds.c
--- a/libpurple/protocols/irc/cmds.c
+++ b/libpurple/protocols/irc/cmds.c
@@ -41,10 +41,7 @@ int irc_cmd_default(struct irc_conn *irc
 		return 1;
 
 	buf = g_strdup_printf(_("Unknown command: %s"), cmd);
-	if (purple_conversation_get_type(convo) == PURPLE_CONV_TYPE_IM)
-		purple_im_conversation_write_message(PURPLE_CONV_IM(convo), "", buf, PURPLE_MESSAGE_SYSTEM|PURPLE_MESSAGE_NO_LOG, time(NULL));
-	else
-		purple_chat_conversation_write_message(PURPLE_CONV_CHAT(convo), "", buf, PURPLE_MESSAGE_SYSTEM|PURPLE_MESSAGE_NO_LOG, time(NULL));
+	purple_conversation_write_message(convo, "", buf, PURPLE_MESSAGE_SYSTEM|PURPLE_MESSAGE_NO_LOG, time(NULL));
 	g_free(buf);
 
 	return 1;
@@ -139,12 +136,12 @@ int irc_cmd_ctcp_action(struct irc_conn 
 		g_free(escaped);
 		if (action[strlen(action) - 1] == '\n')
 			action[strlen(action) - 1] = '\0';
-		if (purple_conversation_get_type(convo) == PURPLE_CONV_TYPE_CHAT)
-			serv_got_chat_in(gc, purple_chat_conversation_get_id(PURPLE_CONV_CHAT(convo)),
+		if (PURPLE_IS_CHAT_CONVERSATION(convo))
+			serv_got_chat_in(gc, purple_chat_conversation_get_id(PURPLE_CHAT_CONVERSATION(convo)),
 			                 purple_connection_get_display_name(gc),
 			                 PURPLE_MESSAGE_SEND, action, time(NULL));
 		else
-			purple_im_conversation_write_message(PURPLE_CONV_IM(convo), purple_connection_get_display_name(gc),
+			purple_conversation_write_message(convo, purple_connection_get_display_name(gc),
 			                     action, PURPLE_MESSAGE_SEND, time(NULL));
 		g_free(action);
 	}
@@ -458,7 +455,7 @@ int irc_cmd_query(struct irc_conn *irc, 
 	if (args[1]) {
 		gc = purple_account_get_connection(irc->account);
 		irc_cmd_privmsg(irc, cmd, target, args);
-		purple_im_conversation_write_message(PURPLE_CONV_IM(convo), purple_connection_get_display_name(gc),
+		purple_conversation_write_message(convo, purple_connection_get_display_name(gc),
 			      args[1], PURPLE_MESSAGE_SEND, time(NULL));
 	}
 
@@ -527,7 +524,7 @@ int irc_cmd_topic(struct irc_conn *irc, 
 		return 0;
 
 	if (!args[0]) {
-		topic = purple_chat_conversation_get_topic (PURPLE_CONV_CHAT(convo));
+		topic = purple_chat_conversation_get_topic (PURPLE_CHAT_CONVERSATION(convo));
 
 		if (topic) {
 			char *tmp, *tmp2;
@@ -538,7 +535,7 @@ int irc_cmd_topic(struct irc_conn *irc, 
 			g_free(tmp2);
 		} else
 			buf = g_strdup(_("No topic is set"));
-		purple_chat_conversation_write_message(PURPLE_CONV_CHAT(convo), target, buf, PURPLE_MESSAGE_SYSTEM|PURPLE_MESSAGE_NO_LOG, time(NULL));
+		purple_conversation_write_message(convo, target, buf, PURPLE_MESSAGE_SYSTEM|PURPLE_MESSAGE_NO_LOG, time(NULL));
 		g_free(buf);
 
 		return 0;
diff --git a/libpurple/protocols/irc/msgs.c b/libpurple/protocols/irc/msgs.c
--- a/libpurple/protocols/irc/msgs.c
+++ b/libpurple/protocols/irc/msgs.c
@@ -76,8 +76,8 @@ static void irc_chat_remove_buddy(Purple
 	message = g_strdup_printf("quit: %s", stripped);
 	g_free(stripped);
 
-	if (purple_chat_conversation_find_user(PURPLE_CONV_CHAT(convo), data[0]))
-		purple_chat_conversation_remove_user(PURPLE_CONV_CHAT(convo), data[0], message);
+	if (purple_chat_conversation_find_user(PURPLE_CHAT_CONVERSATION(convo), data[0]))
+		purple_chat_conversation_remove_user(PURPLE_CHAT_CONVERSATION(convo), data[0], message);
 
 	g_free(message);
 }
@@ -161,9 +161,7 @@ void irc_msg_default(struct irc_conn *ir
 	g_free(tmp);
 
 	/* Check for an existing conversation */
-	convo = purple_conversations_find_with_account(PURPLE_CONV_TYPE_ANY,
-						      convname,
-						      irc->account);
+	convo = purple_conversations_find_with_account(convname, irc->account);
 	g_free(convname);
 
 	if (convo == NULL) {
@@ -272,8 +270,7 @@ void irc_msg_ban(struct irc_conn *irc, c
 	if (!args || !args[0] || !args[1])
 		return;
 
-	convo = purple_conversations_find_with_account(PURPLE_CONV_TYPE_CHAT,
-						      args[1], irc->account);
+	convo = purple_conversations_find_chat_with_account(args[1], irc->account);
 
 	if (!strcmp(name, "367")) {
 		char *msg = NULL;
@@ -292,7 +289,7 @@ void irc_msg_ban(struct irc_conn *irc, c
 			msg = g_strdup_printf(_("Ban on %s"), args[2]);
 		}
 		if (convo) {
-			purple_chat_conversation_write_message(PURPLE_CONV_CHAT(convo), "", msg,
+			purple_conversation_write_message(convo, "", msg,
 			                       PURPLE_MESSAGE_SYSTEM|PURPLE_MESSAGE_NO_LOG,
 			                       time(NULL));
 		} else {
@@ -303,7 +300,7 @@ void irc_msg_ban(struct irc_conn *irc, c
 		if (!convo)
 			return;
 		/* End of ban list */
-		purple_chat_conversation_write_message(PURPLE_CONV_CHAT(convo), "",
+		purple_conversation_write_message(convo, "",
 		                       _("End of ban list"),
 		                       PURPLE_MESSAGE_SYSTEM|PURPLE_MESSAGE_NO_LOG,
 		                       time(NULL));
@@ -338,7 +335,7 @@ void irc_msg_banfull(struct irc_conn *ir
 	nick = g_markup_escape_text(args[2], -1);
 	buf = g_strdup_printf(_("Cannot ban %s: banlist is full"), nick);
 	g_free(nick);
-	purple_chat_conversation_write_message(PURPLE_CONV_CHAT(convo), "", buf,
+	purple_conversation_write_message(convo, "", buf,
 			     PURPLE_MESSAGE_SYSTEM|PURPLE_MESSAGE_NO_LOG,
 			     time(NULL));
 	g_free(buf);
@@ -358,7 +355,7 @@ void irc_msg_chanmode(struct irc_conn *i
 
 	escaped = (args[3] != NULL) ? g_markup_escape_text(args[3], -1) : NULL;
 	buf = g_strdup_printf("mode for %s: %s %s", args[1], args[2], escaped ? escaped : "");
-	purple_chat_conversation_write_message(PURPLE_CONV_CHAT(convo), "", buf, PURPLE_MESSAGE_SYSTEM, time(NULL));
+	purple_conversation_write_message(convo, "", buf, PURPLE_MESSAGE_SYSTEM, time(NULL));
 	g_free(escaped);
 	g_free(buf);
 
@@ -498,13 +495,13 @@ void irc_msg_who(struct irc_conn *irc, c
 			return;
 		}
 
-		cb = purple_chat_conversation_cb_find(PURPLE_CONV_CHAT(conv), args[5]);
+		cb = purple_chat_conversation_find_buddy(PURPLE_CHAT_CONVERSATION(conv), args[5]);
 		if (!cb) {
 			purple_debug(PURPLE_DEBUG_ERROR, "irc", "Got a WHO response for %s who isn't a buddy.\n", args[5]);
 			return;
 		}
 
-		chat = PURPLE_CONV_CHAT(conv);
+		chat = PURPLE_CHAT_CONVERSATION(conv);
 		
 		userhost = g_strdup_printf("%s@%s", args[2], args[3]);
 
@@ -524,7 +521,7 @@ void irc_msg_who(struct irc_conn *irc, c
 		keys = g_list_prepend(keys, "realname");
 		values = g_list_prepend(values, realname);
 		
-		purple_chat_conversation_cb_set_attributes(chat, cb, keys, values);
+		purple_chat_conversation_buddy_set_attributes(chat, cb, keys, values);
 		
 		g_list_free(keys);
 		g_list_free(values);
@@ -532,16 +529,16 @@ void irc_msg_who(struct irc_conn *irc, c
 		g_free(userhost);
 		g_free(realname);
 		
-		flags = purple_chat_conversation_cb_get_flags(cb);
+		flags = purple_chat_conversation_buddy_get_flags(cb);
 
 		/* FIXME: I'm not sure this is really a good idea, now
 		 * that we no longer do periodic WHO.  It seems to me
 		 * like it's more likely to be confusing than not.
 		 * Comments? */
 		if (args[6][0] == 'G' && !(flags & PURPLE_CHAT_CONVERSATION_BUDDY_AWAY)) {
-			purple_chat_conversation_user_set_flags(chat, purple_chat_conversation_cb_get_name(cb), flags | PURPLE_CHAT_CONVERSATION_BUDDY_AWAY);
+			purple_chat_conversation_user_set_flags(chat, purple_chat_conversation_buddy_get_name(cb), flags | PURPLE_CHAT_CONVERSATION_BUDDY_AWAY);
 		} else if(args[6][0] == 'H' && (flags & PURPLE_CHAT_CONVERSATION_BUDDY_AWAY)) {
-			purple_chat_conversation_user_set_flags(chat, purple_chat_conversation_cb_get_name(cb), flags & ~PURPLE_CHAT_CONVERSATION_BUDDY_AWAY);
+			purple_chat_conversation_user_set_flags(chat, purple_chat_conversation_buddy_get_name(cb), flags & ~PURPLE_CHAT_CONVERSATION_BUDDY_AWAY);
 		}
 	}
 }
@@ -614,28 +611,28 @@ void irc_msg_topic(struct irc_conn *irc,
 	tmp2 = purple_markup_linkify(tmp);
 	g_free(tmp);
 	if (!strcmp(name, "topic")) {
-		const char *current_topic = purple_chat_conversation_get_topic(PURPLE_CONV_CHAT(convo));
+		const char *current_topic = purple_chat_conversation_get_topic(PURPLE_CHAT_CONVERSATION(convo));
 		if (!(current_topic != NULL && strcmp(tmp2, current_topic) == 0))
 		{
 			char *nick_esc;
 			nick = irc_mask_nick(from);
 			nick_esc = g_markup_escape_text(nick, -1);
-			purple_chat_conversation_set_topic(PURPLE_CONV_CHAT(convo), nick, topic);
+			purple_chat_conversation_set_topic(PURPLE_CHAT_CONVERSATION(convo), nick, topic);
 			if (*tmp2)
 				msg = g_strdup_printf(_("%s has changed the topic to: %s"), nick_esc, tmp2);
 			else
 				msg = g_strdup_printf(_("%s has cleared the topic."), nick_esc);
 			g_free(nick_esc);
 			g_free(nick);
-			purple_chat_conversation_write_message(PURPLE_CONV_CHAT(convo), from, msg, PURPLE_MESSAGE_SYSTEM, time(NULL));
+			purple_conversation_write_message(convo, from, msg, PURPLE_MESSAGE_SYSTEM, time(NULL));
 			g_free(msg);
 		}
 	} else {
 		char *chan_esc = g_markup_escape_text(chan, -1);
 		msg = g_strdup_printf(_("The topic for %s is: %s"), chan_esc, tmp2);
 		g_free(chan_esc);
-		purple_chat_conversation_set_topic(PURPLE_CONV_CHAT(convo), NULL, topic);
-		purple_chat_conversation_write_message(PURPLE_CONV_CHAT(convo), "", msg, PURPLE_MESSAGE_SYSTEM, time(NULL));
+		purple_chat_conversation_set_topic(PURPLE_CHAT_CONVERSATION(convo), NULL, topic);
+		purple_conversation_write_message(convo, "", msg, PURPLE_MESSAGE_SYSTEM, time(NULL));
 		g_free(msg);
 	}
 	g_free(tmp2);
@@ -668,7 +665,7 @@ void irc_msg_topicinfo(struct irc_conn *
 	timestamp = g_strdup(purple_time_format(tm));
 	datestamp = g_strdup(purple_date_format_short(tm));
 	msg = g_strdup_printf(_("Topic for %s set by %s at %s on %s"), args[1], args[2], timestamp, datestamp);
-	purple_chat_conversation_write_message(PURPLE_CONV_CHAT(convo), "", msg, PURPLE_MESSAGE_SYSTEM | PURPLE_MESSAGE_NO_LINKIFY, time(NULL));



More information about the Commits mailing list