/soc/2013/ankitkv/gobjectification: 5ef8e33e5bed: Refactored sam...

Ankit Vani a at nevitus.org
Mon Jun 24 03:04:40 EDT 2013


Changeset: 5ef8e33e5bed01a1518b0fc4cb0e639131703163
Author:	 Ankit Vani <a at nevitus.org>
Date:	 2013-06-24 12:34 +0530
Branch:	 soc.2013.gobjectification
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/5ef8e33e5bed

Description:

Refactored sametime and yahoo protocols to use the GObject conversation API

diffstat:

 libpurple/protocols/sametime/sametime.c  |   83 ++++++++++++-----------
 libpurple/protocols/yahoo/libyahoo.c     |   12 +-
 libpurple/protocols/yahoo/libymsg.c      |   56 ++++++++-------
 libpurple/protocols/yahoo/yahoo_doodle.c |    2 +-
 libpurple/protocols/yahoo/yahoochat.c    |  106 ++++++++++++++++--------------
 libpurple/protocols/yahoo/ycht.c         |   16 ++--
 6 files changed, 142 insertions(+), 133 deletions(-)

diffs (truncated from 831 to 300 lines):

diff --git a/libpurple/protocols/sametime/sametime.c b/libpurple/protocols/sametime/sametime.c
--- a/libpurple/protocols/sametime/sametime.c
+++ b/libpurple/protocols/sametime/sametime.c
@@ -295,7 +295,7 @@ static void convo_data_free(struct convo
 
 static void convo_features(struct mwConversation *conv);
 
-static PurpleConversation *convo_get_gconv(struct mwConversation *conv);
+static PurpleIMConversation *convo_get_im(struct mwConversation *conv);
 
 
 /* name and id */
@@ -1279,7 +1279,7 @@ static void conversation_created_cb(Purp
   if(pd->gc != gc)
     return; /* not ours */
 
-  if(purple_conversation_get_type(g_conv) != PURPLE_CONV_TYPE_IM)
+  if(PURPLE_IS_CHAT_CONVERSATION(g_conv))
     return; /* wrong type */
 
   who.user = (char *) purple_conversation_get_name(g_conv);
@@ -1835,15 +1835,15 @@ static void mw_session_announce(struct m
 				const char *text) {
   struct mwPurplePluginData *pd;
   PurpleAccount *acct;
-  PurpleConversation *conv;
+  PurpleIMConversation *im;
   PurpleBuddy *buddy;
   char *who = from->user_id;
   char *msg;
 
   pd = mwSession_getClientData(s);
   acct = purple_connection_get_account(pd->gc);
-  conv = purple_conversations_find_im_with_account(who, acct);
-  if(! conv) conv = purple_im_conversation_new(acct, who);
+  im = purple_conversations_find_im_with_account(who, acct);
+  if(! im) im = purple_im_conversation_new(acct, who);
 
   buddy = purple_find_buddy(acct, who);
   if(buddy) who = (char *) purple_buddy_get_contact_alias(buddy);
@@ -1851,7 +1851,8 @@ static void mw_session_announce(struct m
   who = g_strdup_printf(_("Announcement from %s"), who);
   msg = purple_markup_linkify(text);
 
-  purple_conversation_write(conv, who, msg ? msg : "", PURPLE_MESSAGE_RECV, time(NULL));
+  purple_conversation_write(PURPLE_CONVERSATION(im), who, msg ? msg : "",
+  		PURPLE_MESSAGE_RECV, time(NULL));
   g_free(who);
   g_free(msg);
 }
@@ -1978,7 +1979,7 @@ static void mw_conf_opened(struct mwConf
   struct mwSession *session;
   struct mwPurplePluginData *pd;
   PurpleConnection *gc;
-  PurpleConversation *g_conf;
+  PurpleChatConversation *g_conf;
 
   const char *n = mwConference_getName(conf);
   const char *t = mwConference_getTitle(conf);
@@ -1994,11 +1995,11 @@ static void mw_conf_opened(struct mwConf
   if(! t) t = "(no title)";
   g_conf = serv_got_joined_chat(gc, CONF_TO_ID(conf), t);
 
-  mwConference_setClientData(conf, PURPLE_CONV_CHAT(g_conf), NULL);
+  mwConference_setClientData(conf, g_conf, NULL);
 
   for(; members; members = members->next) {
     struct mwLoginInfo *peer = members->data;
-    purple_chat_conversation_add_user(PURPLE_CONV_CHAT(g_conf), peer->user_id,
+    purple_chat_conversation_add_user(g_conf, peer->user_id,
 			    NULL, PURPLE_CHAT_CONVERSATION_BUDDY_NONE, FALSE);
   }
 }
@@ -2408,7 +2409,7 @@ static void convo_data_new(struct mwConv
 }
 
 
-static PurpleConversation *convo_get_gconv(struct mwConversation *conv) {
+static PurpleIMConversation *convo_get_im(struct mwConversation *conv) {
   struct mwServiceIm *srvc;
   struct mwSession *session;
   struct mwPurplePluginData *pd;
@@ -2425,8 +2426,7 @@ static PurpleConversation *convo_get_gco
 
   idb = mwConversation_getTarget(conv);
 
-  return purple_conversations_find_with_account(PURPLE_CONV_TYPE_IM,
-					     idb->user, acct);
+  return purple_conversations_find_im_with_account(idb->user, acct);
 }
 
 
@@ -2460,7 +2460,7 @@ static void convo_queue(struct mwConvers
 
 /* Does what it takes to get an error displayed for a conversation */
 static void convo_error(struct mwConversation *conv, guint32 err) {
-  PurpleConversation *gconv;
+  PurpleIMConversation *im;
   char *tmp, *text;
   struct mwIdBlock *idb;
 
@@ -2469,13 +2469,15 @@ static void convo_error(struct mwConvers
   tmp = mwError(err);
   text = g_strconcat(_("Unable to send message: "), tmp, NULL);
 
-  gconv = convo_get_gconv(conv);
-  if(gconv && !purple_conversation_helper_present_error(idb->user, purple_conversation_get_account(gconv), text)) {
+  im = convo_get_im(conv);
+  if(im && !purple_conversation_helper_present_error(idb->user,
+  		purple_conversation_get_account(PURPLE_CONVERSATION(im)), text)) {
 
     g_free(text);
     text = g_strdup_printf(_("Unable to send message to %s:"),
 			   (idb->user)? idb->user: "(unknown)");
-    purple_notify_error(purple_account_get_connection(purple_conversation_get_account(gconv)),
+    purple_notify_error(purple_account_get_connection(
+    		purple_conversation_get_account(PURPLE_CONVERSATION(im))),
 		      NULL, text, tmp);
   }
 
@@ -2507,16 +2509,17 @@ static void convo_queue_send(struct mwCo
      inform the purple conversation that it's unsafe to offer any *cool*
      features. */
 static void convo_nofeatures(struct mwConversation *conv) {
-  PurpleConversation *gconv;
+  PurpleIMConversation *im;
   PurpleConnection *gc;
 
-  gconv = convo_get_gconv(conv);
-  if(! gconv) return;
-
-  gc = purple_conversation_get_connection(gconv);
+  im = convo_get_im(conv);
+  if(! im) return;
+
+  gc = purple_conversation_get_connection(PURPLE_CONVERSATION(im));
   if(! gc) return;
 
-  purple_conversation_set_features(gconv, purple_connection_get_flags(gc));
+  purple_conversation_set_features(PURPLE_CONVERSATION(im),
+  		purple_connection_get_flags(gc));
 }
 
 
@@ -2524,13 +2527,13 @@ static void convo_nofeatures(struct mwCo
     to inform the purple conversation of what features to offer the
     user */
 static void convo_features(struct mwConversation *conv) {
-  PurpleConversation *gconv;
+  PurpleIMConversation *im;
   PurpleConnectionFlags feat;
 
-  gconv = convo_get_gconv(conv);
-  if(! gconv) return;
-
-  feat = purple_conversation_get_features(gconv);
+  im = convo_get_im(conv);
+  if(! im) return;
+
+  feat = purple_conversation_get_features(PURPLE_CONVERSATION(im));
 
   if(mwConversation_isOpen(conv)) {
     if(mwConversation_supports(conv, mwImSend_HTML)) {
@@ -2546,7 +2549,7 @@ static void convo_features(struct mwConv
     }
 
     DEBUG_INFO("conversation features set to 0x%04x\n", feat);
-    purple_conversation_set_features(gconv, feat);
+    purple_conversation_set_features(PURPLE_CONVERSATION(im), feat);
 
   } else {
     convo_nofeatures(conv);
@@ -2574,7 +2577,7 @@ static void mw_conversation_opened(struc
   if(cd) {
     convo_queue_send(conv);
 
-    if(! convo_get_gconv(conv)) {
+    if(! convo_get_im(conv)) {
       mwConversation_free(conv);
       return;
     }
@@ -2965,7 +2968,7 @@ place_find_by_id(struct mwPurplePluginDa
   l = (GList *) mwServicePlace_getPlaces(srvc);
   for(; l; l = l->next) {
     struct mwPlace *p = l->data;
-    PurpleChatConversation *h = PURPLE_CONV_CHAT(mwPlace_getClientData(p));
+    PurpleChatConversation *h = mwPlace_getClientData(p);
 
     if(CHAT_TO_ID(h) == id) {
       place = p;
@@ -2982,7 +2985,7 @@ static void mw_place_opened(struct mwPla
   struct mwSession *session;
   struct mwPurplePluginData *pd;
   PurpleConnection *gc;
-  PurpleConversation *gconf;
+  PurpleChatConversation *gconf;
 
   GList *members, *l;
 
@@ -3006,7 +3009,7 @@ static void mw_place_opened(struct mwPla
 
   for(l = members; l; l = l->next) {
     struct mwIdBlock *idb = l->data;
-    purple_chat_conversation_add_user(PURPLE_CONV_CHAT(gconf), idb->user,
+    purple_chat_conversation_add_user(gconf, idb->user,
 			    NULL, PURPLE_CHAT_CONVERSATION_BUDDY_NONE, FALSE);
   }
   g_list_free(members);
@@ -3038,7 +3041,7 @@ static void mw_place_closed(struct mwPla
 
 static void mw_place_peerJoined(struct mwPlace *place,
 				const struct mwIdBlock *peer) {
-  PurpleConversation *gconf;
+  PurpleChatConversation *gconf;
 
   const char *n = mwPlace_getName(place);
 
@@ -3047,14 +3050,14 @@ static void mw_place_peerJoined(struct m
   gconf = mwPlace_getClientData(place);
   g_return_if_fail(gconf != NULL);
 
-  purple_chat_conversation_add_user(PURPLE_CONV_CHAT(gconf), peer->user,
+  purple_chat_conversation_add_user(gconf, peer->user,
 			  NULL, PURPLE_CHAT_CONVERSATION_BUDDY_NONE, TRUE);
 }
 
 
 static void mw_place_peerParted(struct mwPlace *place,
 				const struct mwIdBlock *peer) {
-  PurpleConversation *gconf;
+  PurpleChatConversation *gconf;
 
   const char *n = mwPlace_getName(place);
 
@@ -3063,7 +3066,7 @@ static void mw_place_peerParted(struct m
   gconf = mwPlace_getClientData(place);
   g_return_if_fail(gconf != NULL);
 
-  purple_chat_conversation_remove_user(PURPLE_CONV_CHAT(gconf), peer->user, NULL);
+  purple_chat_conversation_remove_user(gconf, peer->user, NULL);
 }
 
 
@@ -4274,14 +4277,14 @@ static void mw_prpl_set_idle(PurpleConne
 
 static void notify_im(PurpleConnection *gc, GList *row, void *user_data) {
   PurpleAccount *acct;
-  PurpleConversation *conv;
+  PurpleIMConversation *im;
   char *id;
 
   acct = purple_connection_get_account(gc);
   id = g_list_nth_data(row, 1);
-  conv = purple_conversations_find_im_with_account(id, acct);
-  if(! conv) conv = purple_im_conversation_new(acct, id);
-  purple_conversation_present(conv);
+  im = purple_conversations_find_im_with_account(id, acct);
+  if(! im) im = purple_im_conversation_new(acct, id);
+  purple_conversation_present(PURPLE_CONVERSATION(im));
 }
 
 
diff --git a/libpurple/protocols/yahoo/libyahoo.c b/libpurple/protocols/yahoo/libyahoo.c
--- a/libpurple/protocols/yahoo/libyahoo.c
+++ b/libpurple/protocols/yahoo/libyahoo.c
@@ -112,16 +112,16 @@ static gboolean yahoo_uri_handler(const 
 		if (sname) {
 			char *message = g_hash_table_lookup(params, "m");
 
-			PurpleConversation *conv = purple_conversations_find_with_account(
-				PURPLE_CONV_TYPE_IM, sname, acct);
-			if (conv == NULL)
-				conv = purple_im_conversation_new(acct, sname);
-			purple_conversation_present(conv);
+			PurpleIMConversation *im = purple_conversations_find_im_with_account(
+				sname, acct);
+			if (im == NULL)
+				im = purple_im_conversation_new(acct, sname);
+			purple_conversation_present(PURPLE_CONVERSATION(im));
 
 			if (message) {
 				/* Spaces are encoded as '+' */
 				g_strdelimit(message, "+", ' ');
-				purple_conversation_send_confirm(conv, message);
+				purple_conversation_send_confirm(PURPLE_CONVERSATION(im), message);
 			}
 		}
 		/* else
diff --git a/libpurple/protocols/yahoo/libymsg.c b/libpurple/protocols/yahoo/libymsg.c
--- a/libpurple/protocols/yahoo/libymsg.c
+++ b/libpurple/protocols/yahoo/libymsg.c
@@ -870,9 +870,9 @@ static void yahoo_process_notify(PurpleC
 				yahoo_update_status(gc, from, f);
 		}
 	} else if (!g_ascii_strncasecmp(msg, "WEBCAMINVITE", strlen("WEBCAMINVITE"))) {
-		PurpleConversation *conv = purple_conversations_find_im_with_account(from, account);
+		PurpleIMConversation *im = purple_conversations_find_im_with_account(from, account);
 		char *buf = g_strdup_printf(_("%s has sent you a webcam invite, which is not yet supported."), from);
-		purple_conversation_write(conv, NULL, buf, PURPLE_MESSAGE_SYSTEM|PURPLE_MESSAGE_NOTIFY, time(NULL));
+		purple_conversation_write(PURPLE_CONVERSATION(im), NULL, buf, PURPLE_MESSAGE_SYSTEM|PURPLE_MESSAGE_NOTIFY, time(NULL));



More information about the Commits mailing list