comparison libpurple/protocols/myspace/myspace.c @ 17677:11988aee28f2

Add msim_color_to_purple() to convert msim markup color to a color for libpurple, and use this on the <c> tag to display incoming colored text as colored (tested).
author Jeffrey Connelly <jaconnel@calpoly.edu>
date Mon, 02 Jul 2007 04:51:09 +0000
parents e7612bd6835b
children 51f54868bbad
comparison
equal deleted inserted replaced
17676:e7612bd6835b 17677:11988aee28f2
805 805
806 *begin = gs_begin->str; 806 *begin = gs_begin->str;
807 *end = gs_end->str; 807 *end = gs_end->str;
808 } 808 }
809 809
810 /** Convert a msim markup color to a color suitable for libpurple.
811 *
812 * @param msim Either a color name, or an rgb(x,y,z) code.
813 *
814 * @return A new string, either a color name or #rrggbb code. Must g_free().
815 */
816 static char *msim_color_to_purple(const char *msim)
817 {
818 guint red, green, blue;
819
820 if (!msim)
821 return g_strdup("black");
822
823 if (sscanf(msim, "rgb(%d,%d,%d)", &red, &green, &blue) != 3)
824 {
825 /* Color name. */
826 return g_strdup(msim);
827 }
828 /* TODO: rgba (alpha). */
829
830 return g_strdup_printf("#%.2x%.2x%.2x", red, green, blue);
831 }
832
810 /** Convert the msim markup <p> (paragraph) tag into HTML. */ 833 /** Convert the msim markup <p> (paragraph) tag into HTML. */
811 static void msim_markup_p_to_html(xmlnode *root, gchar **begin, gchar **end) 834 static void msim_markup_p_to_html(xmlnode *root, gchar **begin, gchar **end)
812 { 835 {
813 /* Just pass through unchanged. 836 /* Just pass through unchanged.
814 * 837 *
819 842
820 /** Convert the msim markup <c> tag (text color) into HTML. TODO: Test */ 843 /** Convert the msim markup <c> tag (text color) into HTML. TODO: Test */
821 static void msim_markup_c_to_html(xmlnode *root, gchar **begin, gchar **end) 844 static void msim_markup_c_to_html(xmlnode *root, gchar **begin, gchar **end)
822 { 845 {
823 const gchar *color; 846 const gchar *color;
847 gchar *purple_color;
824 848
825 color = xmlnode_get_attrib(root, "v"); 849 color = xmlnode_get_attrib(root, "v");
826 if (!color) 850 if (!color)
827 { 851 {
828 purple_debug_info("msim", "msim_markup_c_to_html: <c> tag w/o v attr"); 852 purple_debug_info("msim", "msim_markup_c_to_html: <c> tag w/o v attr");
830 *end = g_strdup(""); 854 *end = g_strdup("");
831 /* TODO: log as unrecognized */ 855 /* TODO: log as unrecognized */
832 return; 856 return;
833 } 857 }
834 858
835 /* TODO: parse rgb(255,0,0) into #FF0000, etc. 859 purple_color = msim_color_to_purple(color);
836 * And do something about rgba (alpha) and transparent. 860
837 */ 861 *begin = g_strdup_printf("<font color='%s'>", purple_color);
838 *begin = g_strdup_printf("<font color='%s'>", color); 862
863 g_free(purple_color);
864
839 /* *begin = g_strdup_printf("<span style='color: %s'>", color); */ 865 /* *begin = g_strdup_printf("<span style='color: %s'>", color); */
840 *end = g_strdup("</font>"); 866 *end = g_strdup("</font>");
841 } 867 }
842 868
843 /** Convert the msim markup <b> tag (background color) into HTML. TODO: Test */ 869 /** Convert the msim markup <b> tag (background color) into HTML. TODO: Test */
844 static void msim_markup_b_to_html(xmlnode *root, gchar **begin, gchar **end) 870 static void msim_markup_b_to_html(xmlnode *root, gchar **begin, gchar **end)
845 { 871 {
846 const gchar *color; 872 const gchar *color;
873 gchar *purple_color;
847 874
848 color = xmlnode_get_attrib(root, "v"); 875 color = xmlnode_get_attrib(root, "v");
849 if (!color) 876 if (!color)
850 { 877 {
851 *begin = g_strdup(""); 878 *begin = g_strdup("");
853 purple_debug_info("msim", "msim_markup_b_to_html: <b> w/o v attr"); 880 purple_debug_info("msim", "msim_markup_b_to_html: <b> w/o v attr");
854 /* TODO: log as unrecognized. */ 881 /* TODO: log as unrecognized. */
855 return; 882 return;
856 } 883 }
857 884
858 /* TODO: parse color same as msim_markup_c_to_html(). */ 885 purple_color = msim_color_to_purple(color);
886
859 /* TODO: find out how to set background color. */ 887 /* TODO: find out how to set background color. */
860 *begin = g_strdup_printf("<span style='background-color: %s'>", color); 888 *begin = g_strdup_printf("<span style='background-color: %s'>",
889 purple_color);
890 g_free(purple_color);
891
861 *end = g_strdup("</p>"); 892 *end = g_strdup("</p>");
862 } 893 }
863 894
864 /** Convert the msim markup <i> tag (emoticon image) into HTML. TODO: Test */ 895 /** Convert the msim markup <i> tag (emoticon image) into HTML. TODO: Test */
865 static void msim_markup_i_to_html(xmlnode *root, gchar **begin, gchar **end) 896 static void msim_markup_i_to_html(xmlnode *root, gchar **begin, gchar **end)