Gadu-Gadu: status refactoring - polishing soc.2012.gg
authorTomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
Fri, 17 Aug 2012 17:44:23 +0200
branchsoc.2012.gg
changeset26ba5e4e8c24 pushlog
parent 481258ec30de
child 09f740724036
Gadu-Gadu: status refactoring - polishing
libpurple/protocols/gg/gg.c
libpurple/protocols/gg/status.c
libpurple/protocols/gg/status.h
     1.1 --- a/libpurple/protocols/gg/gg.c
     1.2 +++ b/libpurple/protocols/gg/gg.c
     1.3 @@ -416,20 +416,13 @@
     1.4  	PurpleNotifyUserInfo *user_info;
     1.5  	PurpleBuddy *buddy;
     1.6  	char *val, *who;
     1.7 -	const gchar *status;
     1.8  
     1.9  	user_info = purple_notify_user_info_new();
    1.10  
    1.11  
    1.12  	val = ggp_search_get_result(req, 0, GG_PUBDIR50_STATUS);
    1.13 -	status = ggp_status_to_purplestatus(atoi(val));
    1.14 -	if (g_strcmp0(status, "freeforchat"))
    1.15 -		//TODO: move to status.h or push to libpurple
    1.16 -		status = _("Chatty");
    1.17 -	else
    1.18 -		status = purple_primitive_get_name_from_type(
    1.19 -			purple_primitive_get_type_from_id(status));
    1.20 -	purple_notify_user_info_add_pair_plaintext(user_info, _("Status"), status);
    1.21 +	purple_notify_user_info_add_pair_plaintext(user_info, _("Status"),
    1.22 +		ggp_status_get_name(ggp_status_to_purplestatus(atoi(val))));
    1.23  	g_free(val);
    1.24  
    1.25  	who = ggp_search_get_result(req, 0, GG_PUBDIR50_UIN);
    1.26 @@ -467,16 +460,16 @@
    1.27  	 * Include a status message, if exists and buddy is in the blist.
    1.28  	 */
    1.29  	buddy = purple_find_buddy(purple_connection_get_account(gc), who);
    1.30 -	if (NULL != buddy) {
    1.31 -		PurpleStatus *status;
    1.32 -		const char *msg;
    1.33 +	if (NULL != buddy)
    1.34 +	{
    1.35 +		gchar *msg;
    1.36  
    1.37 -		status = purple_presence_get_active_status(purple_buddy_get_presence(buddy));
    1.38 -		msg = purple_status_get_attr_string(status, "message");
    1.39 -
    1.40 -		if (msg != NULL) {
    1.41 -			purple_notify_user_info_add_pair_plaintext(user_info, _("Message"), msg);
    1.42 -		}
    1.43 +		ggp_status_from_purplestatus(purple_presence_get_active_status(
    1.44 +			purple_buddy_get_presence(buddy)), &msg);
    1.45 +		if (msg != NULL)
    1.46 +			purple_notify_user_info_add_pair_plaintext(user_info,
    1.47 +				_("Message"), msg);
    1.48 +		g_free(msg);
    1.49  	}
    1.50  
    1.51  	purple_notify_userinfo(gc, who, user_info, ggp_sr_close_cb, form);
    1.52 @@ -1163,14 +1156,15 @@
    1.53  {
    1.54  	PurpleStatus *status;
    1.55  	char *tmp;
    1.56 -	const char *msg, *name, *alias;
    1.57 +	const char *name, *alias;
    1.58 +	gchar *msg;
    1.59  
    1.60  	g_return_if_fail(b != NULL);
    1.61  
    1.62  	status = purple_presence_get_active_status(purple_buddy_get_presence(b));
    1.63 -	msg = purple_status_get_attr_string(status, "message");
    1.64  	name = purple_status_get_name(status);
    1.65  	alias = purple_buddy_get_alias(b);
    1.66 +	ggp_status_from_purplestatus(status, &msg);
    1.67  
    1.68  	purple_notify_user_info_add_pair_plaintext(user_info, _("Alias"), alias);
    1.69  
    1.70 @@ -1182,6 +1176,7 @@
    1.71  		} else {
    1.72  			purple_notify_user_info_add_pair_plaintext(user_info, _("Message"), msg);
    1.73  		}
    1.74 +		g_free(msg);
    1.75  	/* We don't want to duplicate 'Status: Offline'. */
    1.76  	} else if (PURPLE_BUDDY_IS_ONLINE(b)) {
    1.77  		purple_notify_user_info_add_pair_plaintext(user_info, _("Status"), name);
     2.1 --- a/libpurple/protocols/gg/status.c
     2.2 +++ b/libpurple/protocols/gg/status.c
     2.3 @@ -17,7 +17,6 @@
     2.4  ggp_status_get_ssdata(PurpleConnection *gc);
     2.5  
     2.6  static gchar * ggp_status_validate_description(const gchar* msg);
     2.7 -static int ggp_status_from_purplestatus(PurpleStatus *status, gchar **message);
     2.8  
     2.9  ////
    2.10  
    2.11 @@ -92,7 +91,7 @@
    2.12  	return types;
    2.13  }
    2.14  
    2.15 -static int ggp_status_from_purplestatus(PurpleStatus *status, gchar **message)
    2.16 +int ggp_status_from_purplestatus(PurpleStatus *status, gchar **message)
    2.17  {
    2.18  	const char *status_id = purple_status_get_id(status);
    2.19  	const char *status_message =
    2.20 @@ -163,6 +162,14 @@
    2.21  	}
    2.22  }
    2.23  
    2.24 +const gchar * ggp_status_get_name(const gchar *purple_status)
    2.25 +{
    2.26 +	if (g_strcmp0(purple_status, "freeforchat") == 0)
    2.27 +		return _("Chatty");
    2.28 +	return purple_primitive_get_name_from_type(
    2.29 +		purple_primitive_get_type_from_id(purple_status));
    2.30 +}
    2.31 +
    2.32  /*******************************************************************************
    2.33   * Own status.
    2.34   ******************************************************************************/
     3.1 --- a/libpurple/protocols/gg/status.h
     3.2 +++ b/libpurple/protocols/gg/status.h
     3.3 @@ -10,7 +10,9 @@
     3.4  void ggp_status_cleanup(PurpleConnection *gc);
     3.5  
     3.6  GList * ggp_status_types(PurpleAccount *account);
     3.7 +int ggp_status_from_purplestatus(PurpleStatus *status, gchar **message);
     3.8  const gchar * ggp_status_to_purplestatus(int status);
     3.9 +const gchar * ggp_status_get_name(const gchar *purple_status);
    3.10  
    3.11  // own status
    3.12