Gadu-Gadu: status refactoring - polishing soc.2012.gg

Fri, 17 Aug 2012 17:44:23 +0200

author
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
date
Fri, 17 Aug 2012 17:44:23 +0200
branch
soc.2012.gg
changeset 33342
26ba5e4e8c24
parent 33341
481258ec30de
child 33343
09f740724036

Gadu-Gadu: status refactoring - polishing

libpurple/protocols/gg/gg.c file | annotate | diff | comparison | revisions
libpurple/protocols/gg/status.c file | annotate | diff | comparison | revisions
libpurple/protocols/gg/status.h file | annotate | diff | comparison | revisions
--- a/libpurple/protocols/gg/gg.c	Fri Aug 17 17:22:23 2012 +0200
+++ b/libpurple/protocols/gg/gg.c	Fri Aug 17 17:44:23 2012 +0200
@@ -416,20 +416,13 @@
 	PurpleNotifyUserInfo *user_info;
 	PurpleBuddy *buddy;
 	char *val, *who;
-	const gchar *status;
 
 	user_info = purple_notify_user_info_new();
 
 
 	val = ggp_search_get_result(req, 0, GG_PUBDIR50_STATUS);
-	status = ggp_status_to_purplestatus(atoi(val));
-	if (g_strcmp0(status, "freeforchat"))
-		//TODO: move to status.h or push to libpurple
-		status = _("Chatty");
-	else
-		status = purple_primitive_get_name_from_type(
-			purple_primitive_get_type_from_id(status));
-	purple_notify_user_info_add_pair_plaintext(user_info, _("Status"), status);
+	purple_notify_user_info_add_pair_plaintext(user_info, _("Status"),
+		ggp_status_get_name(ggp_status_to_purplestatus(atoi(val))));
 	g_free(val);
 
 	who = ggp_search_get_result(req, 0, GG_PUBDIR50_UIN);
@@ -467,16 +460,16 @@
 	 * Include a status message, if exists and buddy is in the blist.
 	 */
 	buddy = purple_find_buddy(purple_connection_get_account(gc), who);
-	if (NULL != buddy) {
-		PurpleStatus *status;
-		const char *msg;
+	if (NULL != buddy)
+	{
+		gchar *msg;
 
-		status = purple_presence_get_active_status(purple_buddy_get_presence(buddy));
-		msg = purple_status_get_attr_string(status, "message");
-
-		if (msg != NULL) {
-			purple_notify_user_info_add_pair_plaintext(user_info, _("Message"), msg);
-		}
+		ggp_status_from_purplestatus(purple_presence_get_active_status(
+			purple_buddy_get_presence(buddy)), &msg);
+		if (msg != NULL)
+			purple_notify_user_info_add_pair_plaintext(user_info,
+				_("Message"), msg);
+		g_free(msg);
 	}
 
 	purple_notify_userinfo(gc, who, user_info, ggp_sr_close_cb, form);
@@ -1163,14 +1156,15 @@
 {
 	PurpleStatus *status;
 	char *tmp;
-	const char *msg, *name, *alias;
+	const char *name, *alias;
+	gchar *msg;
 
 	g_return_if_fail(b != NULL);
 
 	status = purple_presence_get_active_status(purple_buddy_get_presence(b));
-	msg = purple_status_get_attr_string(status, "message");
 	name = purple_status_get_name(status);
 	alias = purple_buddy_get_alias(b);
+	ggp_status_from_purplestatus(status, &msg);
 
 	purple_notify_user_info_add_pair_plaintext(user_info, _("Alias"), alias);
 
@@ -1182,6 +1176,7 @@
 		} else {
 			purple_notify_user_info_add_pair_plaintext(user_info, _("Message"), msg);
 		}
+		g_free(msg);
 	/* We don't want to duplicate 'Status: Offline'. */
 	} else if (PURPLE_BUDDY_IS_ONLINE(b)) {
 		purple_notify_user_info_add_pair_plaintext(user_info, _("Status"), name);
--- a/libpurple/protocols/gg/status.c	Fri Aug 17 17:22:23 2012 +0200
+++ b/libpurple/protocols/gg/status.c	Fri Aug 17 17:44:23 2012 +0200
@@ -17,7 +17,6 @@
 ggp_status_get_ssdata(PurpleConnection *gc);
 
 static gchar * ggp_status_validate_description(const gchar* msg);
-static int ggp_status_from_purplestatus(PurpleStatus *status, gchar **message);
 
 ////
 
@@ -92,7 +91,7 @@
 	return types;
 }
 
-static int ggp_status_from_purplestatus(PurpleStatus *status, gchar **message)
+int ggp_status_from_purplestatus(PurpleStatus *status, gchar **message)
 {
 	const char *status_id = purple_status_get_id(status);
 	const char *status_message =
@@ -163,6 +162,14 @@
 	}
 }
 
+const gchar * ggp_status_get_name(const gchar *purple_status)
+{
+	if (g_strcmp0(purple_status, "freeforchat") == 0)
+		return _("Chatty");
+	return purple_primitive_get_name_from_type(
+		purple_primitive_get_type_from_id(purple_status));
+}
+
 /*******************************************************************************
  * Own status.
  ******************************************************************************/
--- a/libpurple/protocols/gg/status.h	Fri Aug 17 17:22:23 2012 +0200
+++ b/libpurple/protocols/gg/status.h	Fri Aug 17 17:44:23 2012 +0200
@@ -10,7 +10,9 @@
 void ggp_status_cleanup(PurpleConnection *gc);
 
 GList * ggp_status_types(PurpleAccount *account);
+int ggp_status_from_purplestatus(PurpleStatus *status, gchar **message);
 const gchar * ggp_status_to_purplestatus(int status);
+const gchar * ggp_status_get_name(const gchar *purple_status);
 
 // own status
 

mercurial