pidgin: 159777d1: This should fix tooltips for buddies wit...
evands at pidgin.im
evands at pidgin.im
Mon Jun 2 07:35:48 EDT 2008
-----------------------------------------------------------------
Revision: 159777d1bbf9084c7e0f9e562bb47e7ab3638da7
Ancestor: ec0b14c175374622580c2edd88b9d8675add3a0c
Author: evands at pidgin.im
Date: 2008-06-02T11:31:20
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/159777d1bbf9084c7e0f9e562bb47e7ab3638da7
Modified files:
libpurple/protocols/oscar/oscar.c
ChangeLog:
This should fix tooltips for buddies with away messages which have embedded
BODY tags. As was done before my recent changes, we now strip and then
re-escape the away message HTML to remove formatting and other tags for
display in tooltips.
-------------- next part --------------
============================================================
--- libpurple/protocols/oscar/oscar.c 2e85b168e6453032f76c510bf6746d3c00116f41
+++ libpurple/protocols/oscar/oscar.c cf81aca1a128dc9defe7fcbd074503df44ce7a37
@@ -772,13 +772,25 @@ oscar_user_info_convert_and_add(PurpleAc
}
}
-static void oscar_user_info_append_status(PurpleConnection *gc, PurpleNotifyUserInfo *user_info, PurpleBuddy *b, aim_userinfo_t *userinfo)
+/**
+ * @brief Append the status information to a user_info struct
+ *
+ * The returned information is HTML-ready, appropriately escaped, as all information in a user_info struct should be HTML.
+ *
+ * @param gc The PurpleConnection
+ * @param user_info A PurpleNotifyUserInfo object to which status information will be added
+ * @param b The PurpleBuddy whose status is desired. This or the aim_userinfo_t (or both) must be passed to oscar_user_info_append_status().
+ * @param userinfo The aim_userinfo_t of the buddy whose status is desired. This or the PurpleBuddy (or both) must be passed to oscar_user_info_append_status().
+ * @param strip_html_tags If strip_html_tags is TRUE, tags embedded in the status message will be stripped, returning a non-formatted string. The string will still be HTML escaped.
+ */
+static void oscar_user_info_append_status(PurpleConnection *gc, PurpleNotifyUserInfo *user_info, PurpleBuddy *b, aim_userinfo_t *userinfo, gboolean strip_html_tags)
{
PurpleAccount *account = purple_connection_get_account(gc);
OscarData *od;
PurplePresence *presence = NULL;
PurpleStatus *status = NULL;
gchar *message = NULL, *itmsurl = NULL, *tmp;
+ gboolean is_away;
od = gc->proto_data;
@@ -803,25 +815,16 @@ static void oscar_user_info_append_statu
if ((userinfo->flags & AIM_FLAG_AWAY)) {
/* Away message? */
if ((userinfo->flags & AIM_FLAG_AWAY) && (userinfo->away_len > 0) && (userinfo->away != NULL) && (userinfo->away_encoding != NULL)) {
- gchar *away_utf8;
-
tmp = oscar_encoding_extract(userinfo->away_encoding);
- away_utf8 = oscar_encoding_to_utf8(account, tmp, userinfo->away,
+ message = oscar_encoding_to_utf8(account, tmp, userinfo->away,
userinfo->away_len);
g_free(tmp);
- if (away_utf8 != NULL) {
- message = purple_str_sub_away_formatters(away_utf8, purple_account_get_username(account));
- g_free(away_utf8);
}
- }
} else {
/* Available message? */
if ((userinfo->status != NULL) && userinfo->status[0] != '\0') {
- tmp = oscar_encoding_to_utf8(account, userinfo->status_encoding,
+ message = oscar_encoding_to_utf8(account, userinfo->status_encoding,
userinfo->status, userinfo->status_len);
- /* Available messages are plain text */
- message = g_markup_escape_text(tmp, -1);
- g_free(tmp);
}
#if defined (_WIN32) || defined (__APPLE__)
if (userinfo->itmsurl && (userinfo->itmsurl[0] != '\0'))
@@ -831,6 +834,23 @@ static void oscar_user_info_append_statu
}
}
+ is_away = ((status && !purple_status_is_available(status)) ||
+ (userinfo && (userinfo->flags & AIM_FLAG_AWAY)));
+
+ if (strip_html_tags) {
+ /* Away messges are HTML, but available messages were originally plain text.
+ * We therefore need to strip away messages but not available messages if we're asked to remove HTML tags.
+ */
+ if (is_away) {
+ gchar *tmp2;
+ tmp = purple_markup_strip_html(message);
+ g_free(message);
+ tmp2 = g_markup_escape_text(tmp, -1);
+ g_free(tmp);
+ message = tmp2;
+ }
+
+ } else {
if (itmsurl) {
tmp = g_strdup_printf("<a href=\"%s\">%s</a>",
itmsurl, message);
@@ -838,7 +858,14 @@ static void oscar_user_info_append_statu
g_free(message);
message = tmp;
}
+ }
+ if (is_away) {
+ tmp = purple_str_sub_away_formatters(message, purple_account_get_username(account));
+ g_free(message);
+ message = tmp;
+ }
+
if (b) {
if (purple_presence_is_online(presence)) {
if (aim_snvalid_icq(b->name) || !message || !(*message)) {
@@ -3024,7 +3051,7 @@ static int purple_parse_userinfo(OscarDa
user_info = purple_notify_user_info_new();
- oscar_user_info_append_status(gc, user_info, NULL, userinfo);
+ oscar_user_info_append_status(gc, user_info, /* PurpleBuddy */ NULL, userinfo, /* strip_html_tags */ FALSE);
if (userinfo->present & AIM_USERINFO_PRESENT_IDLE) {
tmp = purple_str_seconds_to_string(userinfo->idletime*60);
@@ -3840,7 +3867,7 @@ static int purple_icqinfo(OscarData *od,
}
if (buddy != NULL)
- oscar_user_info_append_status(gc, user_info, buddy, NULL);
+ oscar_user_info_append_status(gc, user_info, buddy, /* aim_userinfo_t */ NULL, /* strip_html_tags */ FALSE);
oscar_user_info_convert_and_add(account, user_info, _("Additional Information"), info->info);
purple_notify_user_info_add_section_break(user_info);
@@ -5670,7 +5697,7 @@ void oscar_tooltip_text(PurpleBuddy *b,
od = gc->proto_data;
userinfo = aim_locate_finduserinfo(od, b->name);
- oscar_user_info_append_status(gc, user_info, b, userinfo);
+ oscar_user_info_append_status(gc, user_info, b, userinfo, /* strip_html_tags */ TRUE);
if (full)
oscar_user_info_append_extra_info(gc, user_info, b, userinfo);
More information about the Commits
mailing list