aboutsummaryrefslogtreecommitdiffstats
path: root/libempathy-gtk/empathy-theme-adium.c
diff options
context:
space:
mode:
authorXavier Claessens <xclaesse@gmail.com>2009-11-24 21:29:45 +0800
committerXavier Claessens <xclaesse@gmail.com>2009-11-25 01:29:45 +0800
commitce6f2983d99033c0144a622295ae72ec567e2582 (patch)
tree1c839e8bb6444a2b1f0aad5d19215aa284ea8eb7 /libempathy-gtk/empathy-theme-adium.c
parent7731e5f2031462707a4e774d6ebe38d32641a6e5 (diff)
downloadgsoc2013-empathy-ce6f2983d99033c0144a622295ae72ec567e2582.tar
gsoc2013-empathy-ce6f2983d99033c0144a622295ae72ec567e2582.tar.gz
gsoc2013-empathy-ce6f2983d99033c0144a622295ae72ec567e2582.tar.bz2
gsoc2013-empathy-ce6f2983d99033c0144a622295ae72ec567e2582.tar.lz
gsoc2013-empathy-ce6f2983d99033c0144a622295ae72ec567e2582.tar.xz
gsoc2013-empathy-ce6f2983d99033c0144a622295ae72ec567e2582.tar.zst
gsoc2013-empathy-ce6f2983d99033c0144a622295ae72ec567e2582.zip
Make possible to define different replace function for parsers
Diffstat (limited to 'libempathy-gtk/empathy-theme-adium.c')
-rw-r--r--libempathy-gtk/empathy-theme-adium.c92
1 files changed, 43 insertions, 49 deletions
diff --git a/libempathy-gtk/empathy-theme-adium.c b/libempathy-gtk/empathy-theme-adium.c
index 78a218ad6..e0aff10f4 100644
--- a/libempathy-gtk/empathy-theme-adium.c
+++ b/libempathy-gtk/empathy-theme-adium.c
@@ -192,10 +192,11 @@ theme_adium_open_address_cb (GtkMenuItem *menuitem,
}
static void
-theme_adium_parser_newline (GString *string,
- const gchar *text,
- gssize len,
- gpointer user_data)
+theme_adium_match_newline (GString *string,
+ const gchar *text,
+ gssize len,
+ EmpathyStringReplace replace_func,
+ EmpathyStringParser *sub_parsers)
{
gint i;
gint prev = 0;
@@ -208,69 +209,61 @@ theme_adium_parser_newline (GString *string,
for (i = 0; i < len && text[i] != '\0'; i++) {
if (text[i] == '\n') {
empathy_string_parser_substr (string, text + prev,
- i - prev, user_data);
+ i - prev, sub_parsers);
g_string_append (string, "<br/>");
prev = i + 1;
}
}
- empathy_string_parser_substr (string, text + prev, i - prev, user_data);
+ empathy_string_parser_substr (string, text + prev, i - prev, sub_parsers);
}
-static gboolean use_smileys = FALSE;
-
static void
-theme_adium_parser_smiley (GString *string,
- const gchar *text,
- gssize len,
- gpointer user_data)
+theme_adium_replace_link (GString *string,
+ const gchar *text,
+ gssize len,
+ gpointer user_data)
{
- guint last = 0;
+ gchar *real_url;
- if (use_smileys) {
- EmpathySmileyManager *smiley_manager;
- GSList *hits, *l;
-
- smiley_manager = empathy_smiley_manager_dup_singleton ();
- hits = empathy_smiley_manager_parse_len (smiley_manager, text, len);
+ /* Append the link inside <a href=""></a> tag */
+ real_url = empathy_make_absolute_url_len (text, len);
- for (l = hits; l; l = l->next) {
- EmpathySmileyHit *hit = l->data;
+ g_string_append_printf (string, "<a href=\"%s\">", real_url);
+ g_string_append_len (string, text, len);
+ g_string_append (string, "</a>");
- if (hit->start > last) {
- /* Append the text between last smiley (or the
- * start of the message) and this smiley */
- empathy_string_parser_substr (string, text + last,
- hit->start - last,
- user_data);
- }
+ g_free (real_url);
+}
- /* Replace smileys by a <img/> tag */
- g_string_append (string, "<abbr title=\"");
- g_string_append_len (string, text + hit->start,
- hit->end - hit->start);
- g_string_append_printf (string, "\"><img src=\"%s\" alt=\"",
- hit->path);
- g_string_append_len (string, text + hit->start,
- hit->end - hit->start);
- g_string_append (string, "\"/></abbr>");
+static gboolean use_smileys = FALSE;
- last = hit->end;
+static void
+theme_adium_replace_smiley (GString *string,
+ const gchar *text,
+ gssize len,
+ gpointer user_data)
+{
+ EmpathySmileyHit *hit = user_data;
- empathy_smiley_hit_free (hit);
- }
- g_slist_free (hits);
- g_object_unref (smiley_manager);
+ if (use_smileys) {
+ /* Replace smileys by a <img/> tag */
+ g_string_append (string, "<abbr title=\"");
+ g_string_append_len (string, text, len);
+ g_string_append_printf (string, "\"><img src=\"%s\" alt=\"",
+ hit->path);
+ g_string_append_len (string, text, len);
+ g_string_append (string, "\"/></abbr>");
+ } else {
+ g_string_append_len (string, text, len);
}
-
- empathy_string_parser_substr (string, text + last, len - last, user_data);
}
static EmpathyStringParser string_parsers[] = {
- empathy_string_parser_link,
- theme_adium_parser_smiley,
- theme_adium_parser_newline,
- empathy_string_parser_escape,
- NULL,
+ {empathy_string_match_link, theme_adium_replace_link},
+ {empathy_string_match_smiley, theme_adium_replace_smiley},
+ {theme_adium_match_newline, NULL},
+ {empathy_string_match_escape, NULL},
+ {NULL, NULL}
};
static gchar *
@@ -278,6 +271,7 @@ theme_adium_parse_body (const gchar *text)
{
GString *string;
+ /* Get use_smileys value now to avoid getting it for each match */
empathy_conf_get_bool (empathy_conf_get (),
EMPATHY_PREFS_CHAT_SHOW_SMILEYS,
&use_smileys);