Mercurial > pidgin.yaz
comparison pidgin/gtkimhtml.c @ 29789:89f0c974a6f9
Minor cleanup. Hopefully this code has a little less duplication and
is a little easier to follow.
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Thu, 18 Feb 2010 10:06:43 +0000 |
parents | f549ad844d54 |
children | f44718de8b06 fce3282c1813 |
comparison
equal
deleted
inserted
replaced
29788:e75d6a51a5c4 | 29789:89f0c974a6f9 |
---|---|
2129 | 2129 |
2130 *len = gtk_smiley_tree_lookup (tree, text); | 2130 *len = gtk_smiley_tree_lookup (tree, text); |
2131 return (*len > 0); | 2131 return (*len > 0); |
2132 } | 2132 } |
2133 | 2133 |
2134 static GtkIMHtmlSmiley *gtk_imhtml_smiley_get_from_tree(GtkSmileyTree *t, const gchar *text) | |
2135 { | |
2136 const gchar *x = text; | |
2137 gchar *pos; | |
2138 | |
2139 if (t == NULL) | |
2140 return NULL; | |
2141 | |
2142 while (*x) { | |
2143 if (!t->values) | |
2144 return NULL; | |
2145 | |
2146 pos = strchr(t->values->str, *x); | |
2147 if (!pos) | |
2148 return NULL; | |
2149 | |
2150 t = t->children[GPOINTER_TO_INT(pos) - GPOINTER_TO_INT(t->values->str)]; | |
2151 x++; | |
2152 } | |
2153 | |
2154 return t->image; | |
2155 } | |
2156 | |
2134 GtkIMHtmlSmiley * | 2157 GtkIMHtmlSmiley * |
2135 gtk_imhtml_smiley_get(GtkIMHtml *imhtml, | 2158 gtk_imhtml_smiley_get(GtkIMHtml *imhtml, const gchar *sml, const gchar *text) |
2136 const gchar *sml, | 2159 { |
2137 const gchar *text) | 2160 GtkIMHtmlSmiley *ret; |
2138 { | 2161 |
2139 GtkSmileyTree *t; | 2162 /* Look for custom smileys first */ |
2140 const gchar *x = text; | 2163 if (sml != NULL) { |
2141 if (sml == NULL) | 2164 ret = gtk_imhtml_smiley_get_from_tree(g_hash_table_lookup(imhtml->smiley_data, sml), text); |
2142 t = imhtml->default_smilies; | 2165 if (ret != NULL) |
2143 else | 2166 return ret; |
2144 t = g_hash_table_lookup(imhtml->smiley_data, sml); | 2167 } |
2145 | 2168 |
2146 | 2169 /* Fall back to check for default smileys */ |
2147 if (t == NULL) | 2170 return gtk_imhtml_smiley_get_from_tree(imhtml->default_smilies, text); |
2148 return sml ? gtk_imhtml_smiley_get(imhtml, NULL, text) : NULL; | |
2149 | |
2150 while (*x) { | |
2151 gchar *pos; | |
2152 | |
2153 if (!t->values) { | |
2154 return sml ? gtk_imhtml_smiley_get(imhtml, NULL, text) : NULL; | |
2155 } | |
2156 | |
2157 pos = strchr (t->values->str, *x); | |
2158 if (pos) { | |
2159 t = t->children [GPOINTER_TO_INT(pos) - GPOINTER_TO_INT(t->values->str)]; | |
2160 } else { | |
2161 return sml ? gtk_imhtml_smiley_get(imhtml, NULL, text) : NULL; | |
2162 } | |
2163 x++; | |
2164 } | |
2165 | |
2166 return t->image; | |
2167 } | 2171 } |
2168 | 2172 |
2169 static GdkPixbufAnimation * | 2173 static GdkPixbufAnimation * |
2170 gtk_smiley_get_image(GtkIMHtmlSmiley *smiley) | 2174 gtk_smiley_get_image(GtkIMHtmlSmiley *smiley) |
2171 { | 2175 { |
2172 if (!smiley->icon && smiley->file) { | 2176 if (!smiley->icon) { |
2173 smiley->icon = gdk_pixbuf_animation_new_from_file(smiley->file, NULL); | 2177 if (smiley->file) { |
2174 } else if (!smiley->icon && smiley->loader) { | 2178 smiley->icon = gdk_pixbuf_animation_new_from_file(smiley->file, NULL); |
2175 smiley->icon = gdk_pixbuf_loader_get_animation(smiley->loader); | 2179 } else if (smiley->loader) { |
2176 if (smiley->icon) | 2180 smiley->icon = gdk_pixbuf_loader_get_animation(smiley->loader); |
2177 g_object_ref(G_OBJECT(smiley->icon)); | 2181 if (smiley->icon) |
2182 g_object_ref(G_OBJECT(smiley->icon)); | |
2183 } | |
2178 } | 2184 } |
2179 | 2185 |
2180 return smiley->icon; | 2186 return smiley->icon; |
2181 } | 2187 } |
2182 | 2188 |