# HG changeset patch # User Jeffrey Connelly # Date 1182834989 0 # Node ID a014bcce5a5da5068710ece1be5a9a12831d09da # Parent 32b9b6af101016f4bbe6b9ca39de7076fc417024 Add (at least placeholder) functions to process p, f, c, b, and i markup tags into HTML on incoming messages. diff -r 32b9b6af1010 -r a014bcce5a5d libpurple/protocols/myspace/myspace.c --- a/libpurple/protocols/myspace/myspace.c Mon Jun 25 05:53:10 2007 +0000 +++ b/libpurple/protocols/myspace/myspace.c Tue Jun 26 05:16:29 2007 +0000 @@ -746,6 +746,115 @@ } } +/** Convert the msim markup (font) tag into HTML. */ +static void msim_markup_f_to_html(xmlnode *root, gchar **begin, gchar **end) +{ + const gchar *face, *height_str, *decor_str; + GString *gs_end, *gs_begin; + guint decor, height; + + face = xmlnode_get_attrib(root, "n"); + height_str = xmlnode_get_attrib(root, "h"); + decor_str = xmlnode_get_attrib(root, "s"); + + if (height_str) + height = atol(height_str); + else + height = 12; + + if (decor_str) + decor = atol(decor_str); + else + decor = 0; + + gs_begin = g_string_new(""); + g_string_printf(gs_begin, "", face, + msim_font_size_to_purple(msim_font_height_to_point(height))); + /* No support for font-size CSS? */ + /* g_string_printf(gs_begin, "", face, + msim_font_height_to_point(height)); */ + + gs_end = g_string_new(""); + + if (decor & 1) + { + g_string_append(gs_begin, ""); + g_string_prepend(gs_end, ""); + } + + if (decor & 2) + { + g_string_append(gs_begin, ""); + g_string_append(gs_end, ""); + } + + if (decor & 4) + { + g_string_append(gs_begin, ""); + g_string_append(gs_end, ""); + } + + + *begin = gs_begin->str; + *end = gs_end->str; +} + +/** Convert the msim markup

(paragraph) tag into HTML. */ +static void msim_markup_p_to_html(xmlnode *root, gchar **begin, gchar **end) +{ + /* Just pass through unchanged. + * + * Note: attributes currently aren't passed, if there are any. */ + *begin = g_strdup("

"); + *end = g_strdup("

"); +} + +/** Convert the msim markup tag (text color) into HTML. TODO: Test */ +static void msim_markup_c_to_html(xmlnode *root, gchar **begin, gchar **end) +{ + const gchar *color; + + color = xmlnode_get_attrib(root, "v"); + + /* TODO: parse rgb(255,0,0) into #FF0000, etc. + * And do something about rgba (alpha) and transparent. + */ + /* *begin = g_strdup_printf("", color); */ + *begin = g_strdup_printf("", color); + *end = g_strdup("

"); +} + +/** Convert the msim markup tag (background color) into HTML. TODO: Test */ +static void msim_markup_b_to_html(xmlnode *root, gchar **begin, gchar **end) +{ + const gchar *color; + + color = xmlnode_get_attrib(root, "v"); + + /* TODO: parse color same as msim_markup_c_to_html(). */ + *begin = g_strdup_printf("", color); + *end = g_strdup("

"); +} + +/** Convert the msim markup tag (emoticon image) into HTML. TODO: Test */ +static void msim_markup_i_to_html(xmlnode *root, gchar **begin, gchar **end) +{ + const gchar *name; + + name = xmlnode_get_attrib(root, "n"); + + /* TODO: Support these emoticons: + * + * bigsmile growl mad scared tongue devil happy messed sidefrown upset + * frazzled heart nerd sinister wink geek laugh oops smirk worried + * googles mohawk pirate straight kiss + */ + + *begin = g_strdup_printf("", name); + *end = g_strdup("

"); +} + + /** Convert an xmlnode of msim markup to an HTML string. * @return An HTML string. Caller frees. */ @@ -765,50 +874,15 @@ if (!strcmp(root->name, "f")) { - const gchar *face, *height_str, *decor_str; - GString *gs_end, *gs_begin; - guint decor, height; - - face = xmlnode_get_attrib(root, "n"); - height_str = xmlnode_get_attrib(root, "h"); - decor_str = xmlnode_get_attrib(root, "s"); - - if (height_str) - height = atol(height_str); - else - height = 12; - - if (decor_str) - decor = atol(decor_str); - else - decor = 0; - - gs_begin = g_string_new(""); - g_string_printf(gs_begin, "", face, - msim_font_size_to_purple(msim_font_height_to_point(height))); - gs_end = g_string_new(""); - - if (decor & 1) - { - g_string_append(gs_begin, ""); - g_string_prepend(gs_end, ""); - } - - if (decor & 2) - { - g_string_append(gs_begin, ""); - g_string_append(gs_end, ""); - } - - if (decor & 4) - { - g_string_append(gs_begin, ""); - g_string_append(gs_end, ""); - } - - - begin = gs_begin->str; - end = gs_end->str; + msim_markup_f_to_html(root, &begin, &end); + } else if (!strcmp(root->name, "p")) { + msim_markup_p_to_html(root, &begin, &end); + } else if (!strcmp(root->name, "c")) { + msim_markup_c_to_html(root, &begin, &end); + } else if (!strcmp(root->name, "b")) { + msim_markup_b_to_html(root, &begin, &end); + } else if (!strcmp(root->name, "i")) { + msim_markup_i_to_html(root, &begin, &end); } else { purple_debug_info("msim", "msim_markup_xmlnode_to_html: " "unknown tag name=%s, ignoring", root->name); @@ -861,10 +935,9 @@ return final; } -/** Convert MySpaceIM markup to GtkIMHtml markup. - * TODO +/** Convert MySpaceIM markup to Purple (HTML) markup. * - * @return GtkIMHtml markup string, must be g_free()'d. */ + * @return Purple markup string, must be g_free()'d. */ gchar * msim_markup_to_html(const gchar *raw) {