/soc/2013/ankitkv/gobjectification: 9cdc9e6eecce: Refactored mxi...

Ankit Vani a at nevitus.org
Sun Jun 23 15:22:00 EDT 2013


Changeset: 9cdc9e6eecce12034f008be2e173c19dd3ecb0a9
Author:	 Ankit Vani <a at nevitus.org>
Date:	 2013-06-24 00:51 +0530
Branch:	 soc.2013.gobjectification
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/9cdc9e6eecce

Description:

Refactored mxit and myspace protocols to use the GObject conversation API

diffstat:

 libpurple/protocols/mxit/formcmds.c   |   8 +++---
 libpurple/protocols/mxit/multimx.c    |  46 +++++++++++++++++-----------------
 libpurple/protocols/mxit/mxit.c       |   2 +-
 libpurple/protocols/myspace/myspace.c |  22 ++++++++--------
 4 files changed, 39 insertions(+), 39 deletions(-)

diffs (256 lines):

diff --git a/libpurple/protocols/mxit/formcmds.c b/libpurple/protocols/mxit/formcmds.c
--- a/libpurple/protocols/mxit/formcmds.c
+++ b/libpurple/protocols/mxit/formcmds.c
@@ -228,11 +228,11 @@ static GHashTable* command_tokenize(char
  */
 static void command_clear(struct MXitSession* session, const char* from, GHashTable* hash)
 {
-	PurpleConversation *conv;
+	PurpleIMConversation *im;
 	char* clearmsgscreen;
 
-	conv = purple_conversations_find_im_with_account(from, session->acc);
-	if (conv == NULL) {
+	im = purple_conversations_find_im_with_account(from, session->acc);
+	if (im == NULL) {
 		purple_debug_error(MXIT_PLUGIN_ID, _( "Conversation with '%s' not found\n" ), from);
 		return;
 	}
@@ -240,7 +240,7 @@ static void command_clear(struct MXitSes
 	clearmsgscreen = g_hash_table_lookup(hash, "clearmsgscreen");
 	if ( (clearmsgscreen) && (strcmp(clearmsgscreen, "true") == 0) ) {
 		/* this is a command to clear the chat screen */
-		purple_conversation_clear_message_history(conv);
+		purple_conversation_clear_message_history(PURPLE_CONVERSATION(im));
 	}
 }
 
diff --git a/libpurple/protocols/mxit/multimx.c b/libpurple/protocols/mxit/multimx.c
--- a/libpurple/protocols/mxit/multimx.c
+++ b/libpurple/protocols/mxit/multimx.c
@@ -179,11 +179,11 @@ static void room_remove(struct MXitSessi
  *  @param convo		The Conversation object
  *  @param nickname		The nickname of the user who joined the room
  */
-static void member_added(PurpleConversation* convo, const char* nickname)
+static void member_added(PurpleChatConversation* chat, const char* nickname)
 {
 	purple_debug_info(MXIT_PLUGIN_ID, "member_added: '%s'\n", nickname);
 
-	purple_chat_conversation_add_user(PURPLE_CONV_CHAT(convo), nickname, NULL, PURPLE_CHAT_CONVERSATION_BUDDY_NONE, TRUE);
+	purple_chat_conversation_add_user(chat, nickname, NULL, PURPLE_CHAT_CONVERSATION_BUDDY_NONE, TRUE);
 }
 
 
@@ -193,11 +193,11 @@ static void member_added(PurpleConversat
  *  @param convo		The Conversation object
  *  @param nickname		The nickname of the user who left the room
  */
-static void member_removed(PurpleConversation* convo, const char* nickname)
+static void member_removed(PurpleChatConversation* chat, const char* nickname)
 {
 	purple_debug_info(MXIT_PLUGIN_ID, "member_removed: '%s'\n", nickname);
 
-	purple_chat_conversation_remove_user(PURPLE_CONV_CHAT(convo), nickname, NULL);
+	purple_chat_conversation_remove_user(chat, nickname, NULL);
 }
 
 
@@ -207,11 +207,11 @@ static void member_removed(PurpleConvers
  *  @param convo		The Conversation object
  *  @param nickname		The nickname of the user who was kicked
  */
-static void member_kicked(PurpleConversation* convo, const char* nickname)
+static void member_kicked(PurpleChatConversation* chat, const char* nickname)
 {
 	purple_debug_info(MXIT_PLUGIN_ID, "member_kicked: '%s'\n", nickname);
 
-	purple_chat_conversation_remove_user(PURPLE_CONV_CHAT(convo), nickname, _("was kicked"));
+	purple_chat_conversation_remove_user(chat, nickname, _("was kicked"));
 }
 
 
@@ -222,12 +222,12 @@ static void member_kicked(PurpleConversa
  *  @param session		The MXit session object
  *  @param multimx		The MultiMX room object
  */
-static void you_kicked(PurpleConversation* convo, struct MXitSession* session, struct multimx* multimx)
+static void you_kicked(PurpleChatConversation* chat, struct MXitSession* session, struct multimx* multimx)
 {
 	purple_debug_info(MXIT_PLUGIN_ID, "you_kicked\n");
 
-	purple_chat_conversation_write_message(PURPLE_CONV_CHAT(convo), "MXit", _("You have been kicked from this MultiMX."), PURPLE_MESSAGE_SYSTEM, time(NULL));
-	purple_chat_conversation_clear_users(PURPLE_CONV_CHAT(convo));
+	purple_conversation_write_message(PURPLE_CONVERSATION(chat), "MXit", _("You have been kicked from this MultiMX."), PURPLE_MESSAGE_SYSTEM, time(NULL));
+	purple_chat_conversation_clear_users(chat);
 	serv_got_chat_left(session->con, multimx->chatid);
 }
 
@@ -238,7 +238,7 @@ static void you_kicked(PurpleConversatio
  *  @param convo		The Conversation object
  *  @param data			The nicknames of the users in the room (separated by \n)
  */
-static void member_update(PurpleConversation* convo, char* data)
+static void member_update(PurpleChatConversation* chat, char* data)
 {
 	gchar** userlist;
 	int i = 0;
@@ -246,14 +246,14 @@ static void member_update(PurpleConversa
 	purple_debug_info(MXIT_PLUGIN_ID, "member_update: '%s'\n", data);
 
 	/* Clear list */
-	purple_chat_conversation_clear_users(PURPLE_CONV_CHAT(convo));
+	purple_chat_conversation_clear_users(chat);
 
 	/* Add each member */
 	data = g_strstrip(data);				/* string leading & trailing whitespace */
 	userlist = g_strsplit(data, "\n", 0);	/* tokenize string */
 	while (userlist[i] != NULL) {
 		purple_debug_info(MXIT_PLUGIN_ID, "member_update - adding: '%s'\n", userlist[i]);
-		purple_chat_conversation_add_user(PURPLE_CONV_CHAT(convo), userlist[i], NULL, PURPLE_CHAT_CONVERSATION_BUDDY_NONE, FALSE);
+		purple_chat_conversation_add_user(chat, userlist[i], NULL, PURPLE_CHAT_CONVERSATION_BUDDY_NONE, FALSE);
 		i++;
 	}
 	g_strfreev(userlist);
@@ -377,8 +377,8 @@ void multimx_message_received(struct RXM
 		/* Must be a service message */
 		char* ofs;
 
-		PurpleConversation* convo = purple_conversations_find_chat_with_account(multimx->roomname, mx->session->acc);
-		if (convo == NULL) {
+		PurpleChatConversation* chat = purple_conversations_find_chat_with_account(multimx->roomname, mx->session->acc);
+		if (chat == NULL) {
 			purple_debug_error(MXIT_PLUGIN_ID, "Conversation '%s' not found\n", multimx->roomname);
 			return;
 		}
@@ -387,28 +387,28 @@ void multimx_message_received(struct RXM
 		if ((ofs = strstr(msg, " has joined")) != NULL) {
 			/* Somebody has joined */
 			*ofs = '\0';
-			member_added(convo, msg);
+			member_added(chat, msg);
 			mx->processed = TRUE;
 		}
 		else if ((ofs = strstr(msg, " has left")) != NULL) {
 			/* Somebody has left */
 			*ofs = '\0';
-			member_removed(convo, msg);
+			member_removed(chat, msg);
 			mx->processed = TRUE;
 		}
 		else if ((ofs = strstr(msg, " has been kicked")) != NULL) {
 			/* Somebody has been kicked */
 			*ofs = '\0';
-			member_kicked(convo, msg);
+			member_kicked(chat, msg);
 			mx->processed = TRUE;
 		}
 		else if (strcmp(msg, "You have been kicked.") == 0) {
 			/* You have been kicked */
-			you_kicked(convo, mx->session, multimx);
+			you_kicked(chat, mx->session, multimx);
 			mx->processed = TRUE;
 		}
 		else if (g_str_has_prefix(msg, "The following users are in this MultiMx:") == TRUE) {
-			member_update(convo, msg + strlen("The following users are in this MultiMx:") + 1);
+			member_update(chat, msg + strlen("The following users are in this MultiMx:") + 1);
 			mx->processed = TRUE;
 		}
 		else {
@@ -544,7 +544,7 @@ void mxit_chat_invite(PurpleConnection *
 	struct MXitSession* session = purple_connection_get_protocol_data(gc);
 	struct multimx* multimx = NULL;
 	PurpleBuddy* buddy;
-	PurpleConversation *convo;
+	PurpleChatConversation *chat;
 	char* tmp;
 
 	purple_debug_info(MXIT_PLUGIN_ID, "Groupchat invite to '%s'\n", username);
@@ -566,15 +566,15 @@ void mxit_chat_invite(PurpleConnection *
 		return;
 	}
 
-	convo = purple_conversations_find_chat_with_account(multimx->roomname, session->acc);
-	if (convo == NULL) {
+	chat = purple_conversations_find_chat_with_account(multimx->roomname, session->acc);
+	if (chat == NULL) {
 		purple_debug_error(MXIT_PLUGIN_ID, "Conversation '%s' not found\n", multimx->roomname);
 		return;
 	}
 
 	/* Display system message in chat window */
 	tmp = g_strdup_printf("%s: %s", _("You have invited"), purple_buddy_get_alias(buddy));
-	purple_chat_conversation_write_message(PURPLE_CONV_CHAT(convo), "MXit", tmp, PURPLE_MESSAGE_SYSTEM, time(NULL));
+	purple_conversation_write_message(PURPLE_CONVERSATION(chat), "MXit", tmp, PURPLE_MESSAGE_SYSTEM, time(NULL));
 	g_free(tmp);
 }
 
diff --git a/libpurple/protocols/mxit/mxit.c b/libpurple/protocols/mxit/mxit.c
--- a/libpurple/protocols/mxit/mxit.c
+++ b/libpurple/protocols/mxit/mxit.c
@@ -180,7 +180,7 @@ static void mxit_cb_chat_created( Purple
 		/* not our conversation */
 		return;
 	}
-	else if ( purple_conversation_get_type( conv ) != PURPLE_CONV_TYPE_IM ) {
+	else if ( PURPLE_IS_CHAT_CONVERSATION( conv ) ) {
 		/* wrong type of conversation */
 		return;
 	}
diff --git a/libpurple/protocols/myspace/myspace.c b/libpurple/protocols/myspace/myspace.c
--- a/libpurple/protocols/myspace/myspace.c
+++ b/libpurple/protocols/myspace/myspace.c
@@ -1488,7 +1488,7 @@ msim_incoming_im(MsimSession *session, M
 	gchar *msg_msim_markup, *msg_purple_markup;
 	gchar *userid;
 	time_t time_received;
-	PurpleConversation *conv;
+	PurpleIMConversation *im;
 
 	/* I know this isn't really a string... but we need it to be one for
 	 * purple_conversations_find_with_account(). */
@@ -1502,11 +1502,11 @@ msim_incoming_im(MsimSession *session, M
 		return FALSE;
 	}
 
-	/* See if a conversation with their UID already exists...*/
-	conv = purple_conversations_find_im_with_account(userid, session->account);
-	if (conv) {
-		/* Since the conversation exists... We need to normalize it */
-		purple_conversation_set_name(conv, username);
+	/* See if an IM with their UID already exists...*/
+	im = purple_conversations_find_im_with_account(userid, session->account);
+	if (im) {
+		/* Since the IM exists... We need to normalize it */
+		purple_conversation_set_name(PURPLE_CONVERSATION(im), username);
 	}
 
 	msg_msim_markup = msim_msg_get_string(msg, "msg");
@@ -3480,7 +3480,7 @@ msim_uri_handler_addContact_cb(MsimSessi
 static void
 msim_uri_handler_sendIM_cb(MsimSession *session, MsimMessage *userinfo, gpointer data)
 {
-	PurpleConversation *conv;
+	PurpleIMConversation *im;
 	MsimMessage *body;
 	gchar *username;
 
@@ -3498,14 +3498,14 @@ msim_uri_handler_sendIM_cb(MsimSession *
 	}
 
 
-	conv = purple_conversations_find_im_with_account(username, session->account);
-	if (!conv)  {
+	im = purple_conversations_find_im_with_account(username, session->account);
+	if (!im)  {
 		purple_debug_info("msim_uri_handler", "creating new conversation for %s\n", username);
-		conv = purple_im_conversation_new(session->account, username);
+		im = purple_im_conversation_new(session->account, username);
 	}
 
 	/* Just open the window so the user can send an IM. */
-	purple_conversation_present(conv);
+	purple_conversation_present(PURPLE_CONVERSATION(im));
 
 	g_free(username);
 }



More information about the Commits mailing list