]> git.0d.be Git - empathy.git/blobdiff - libempathy-gtk/empathy-theme-adium.c
Updated Polish translation
[empathy.git] / libempathy-gtk / empathy-theme-adium.c
index e0aff10f42079c665ccdc4c517562802a8d812ec..7736be27070bb2e783fc545502aafaff94d0c0a4 100644 (file)
@@ -40,6 +40,7 @@
 #include "empathy-conf.h"
 #include "empathy-ui-utils.h"
 #include "empathy-plist.h"
+#include "empathy-string-parser.h"
 
 #define DEBUG_FLAG EMPATHY_DEBUG_CHAT
 #include <libempathy/empathy-debug.h>
@@ -192,12 +193,13 @@ theme_adium_open_address_cb (GtkMenuItem *menuitem,
 }
 
 static void
-theme_adium_match_newline (GString *string,
-                          const gchar *text,
+theme_adium_match_newline (const gchar *text,
                           gssize len,
                           EmpathyStringReplace replace_func,
-                          EmpathyStringParser *sub_parsers)
+                          EmpathyStringParser *sub_parsers,
+                          gpointer user_data)
 {
+       GString *string = user_data;
        gint i;
        gint prev = 0;
 
@@ -208,90 +210,68 @@ theme_adium_match_newline (GString *string,
        /* Replace \n by <br/> */
        for (i = 0; i < len && text[i] != '\0'; i++) {
                if (text[i] == '\n') {
-                       empathy_string_parser_substr (string, text + prev,
-                                                     i - prev, sub_parsers);
+                       empathy_string_parser_substr (text + prev,
+                                                     i - prev, sub_parsers,
+                                                     user_data);
                        g_string_append (string, "<br/>");
                        prev = i + 1;
                }
        }
-       empathy_string_parser_substr (string, text + prev, i - prev, sub_parsers);
+       empathy_string_parser_substr (text + prev, i - prev,
+                                     sub_parsers, user_data);
 }
 
 static void
-theme_adium_replace_link (GString *string,
-                         const gchar *text,
-                         gssize len,
-                         gpointer user_data)
-{
-       gchar *real_url;
-
-       /* Append the link inside <a href=""></a> tag */
-       real_url = empathy_make_absolute_url_len (text, len);
-
-       g_string_append_printf (string, "<a href=\"%s\">", real_url);
-       g_string_append_len (string, text, len);
-       g_string_append (string, "</a>");
-
-       g_free (real_url);
-}
-
-static gboolean use_smileys = FALSE;
-
-static void
-theme_adium_replace_smiley (GString *string,
-                           const gchar *text,
+theme_adium_replace_smiley (const gchar *text,
                            gssize len,
+                           gpointer match_data,
                            gpointer user_data)
 {
-       EmpathySmileyHit *hit = user_data;
-
-       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);
-       }
+       EmpathySmileyHit *hit = match_data;
+       GString *string = user_data;
+
+       /* Replace smiley by a <img/> tag */
+       g_string_append_printf (string,
+                               "<img src=\"%s\" alt=\"%.*s\" title=\"%.*s\"/>",
+                               hit->path, (int)len, text, (int)len, text);
 }
 
 static EmpathyStringParser string_parsers[] = {
-       {empathy_string_match_link, theme_adium_replace_link},
+       {empathy_string_match_link, empathy_string_replace_link},
+       {theme_adium_match_newline, NULL},
+       {empathy_string_match_all, empathy_string_replace_escaped},
+       {NULL, NULL}
+};
+
+static EmpathyStringParser string_parsers_with_smiley[] = {
+       {empathy_string_match_link, empathy_string_replace_link},
        {empathy_string_match_smiley, theme_adium_replace_smiley},
        {theme_adium_match_newline, NULL},
-       {empathy_string_match_escape, NULL},
+       {empathy_string_match_all, empathy_string_replace_escaped},
        {NULL, NULL}
 };
 
 static gchar *
 theme_adium_parse_body (const gchar *text)
 {
+       EmpathyStringParser *parsers;
        GString *string;
+       gboolean use_smileys;
 
-       /* Get use_smileys value now to avoid getting it for each match */
+       /* Check if we have to parse smileys */
        empathy_conf_get_bool (empathy_conf_get (),
                               EMPATHY_PREFS_CHAT_SHOW_SMILEYS,
                               &use_smileys);
-
-       /* We parse text in 4 steps: url, smiley, newline, escape.
-        * For each step, we detect the position of tokens in the text, and
-        * we give text between each token to the next level parser.
-        *
-        * For example the string "Hello :)\n www.test.com"
-        * 1) The url parser detects "www.test.com" and gives "Hello :)\n " to
-        *    the smiley parser, then insert the <a> tag for the link.
-        * 2) The smiley parser will detect ":)". It first gives "Hello "
-        *    to the newline parser, then insert the <img/> tag for the smiley,
-        *    and finally give "\n " to the newline parser.
-        * 3a) The newline parser gets "Hello " and escape it.
-        * 3b) The newline parser gets "\n " and replace to "<br/> ".
-        */
-
+       if (use_smileys)
+               parsers = string_parsers_with_smiley;
+       else
+               parsers = string_parsers;
+
+       /* Parse text and construct string with links and smileys replaced
+        * by html tags. Also escape text to make sure html code is
+        * displayed verbatim. */
        string = g_string_sized_new (strlen (text));
-       empathy_string_parser_substr (string, text, -1, string_parsers);
+       empathy_string_parser_substr (text, -1, parsers, string);
 
        return g_string_free (string, FALSE);
 }
@@ -421,6 +401,28 @@ theme_adium_append_html (EmpathyThemeAdium *theme,
        g_free (script);
 }
 
+static void
+theme_adium_append_event_escaped (EmpathyChatView *view,
+                                 const gchar     *escaped)
+{
+       EmpathyThemeAdium     *theme = EMPATHY_THEME_ADIUM (view);
+       EmpathyThemeAdiumPriv *priv = GET_PRIV (theme);
+
+       if (priv->data->status_html) {
+               theme_adium_append_html (theme, "appendMessage",
+                                        priv->data->status_html,
+                                        priv->data->status_len,
+                                        escaped, NULL, NULL, NULL, NULL,
+                                        "event", empathy_time_get_current ());
+       }
+
+       /* There is no last contact */
+       if (priv->last_contact) {
+               g_object_unref (priv->last_contact);
+               priv->last_contact = NULL;
+       }
+}
+
 static void
 theme_adium_append_message (EmpathyChatView *view,
                            EmpathyMessage  *msg)
@@ -468,7 +470,8 @@ theme_adium_append_message (EmpathyChatView *view,
                gchar *str;
 
                str = g_strdup_printf ("%s %s", name, body_escaped);
-               empathy_chat_view_append_event (view, str);
+               theme_adium_append_event_escaped (view, str);
+
                g_free (str);
                g_free (body_escaped);
                return;
@@ -615,26 +618,11 @@ static void
 theme_adium_append_event (EmpathyChatView *view,
                          const gchar     *str)
 {
-       EmpathyThemeAdium     *theme = EMPATHY_THEME_ADIUM (view);
-       EmpathyThemeAdiumPriv *priv = GET_PRIV (theme);
+       gchar *str_escaped;
 
-       if (priv->data->status_html) {
-               gchar *str_escaped;
-
-               str_escaped = g_markup_escape_text (str, -1);
-               theme_adium_append_html (theme, "appendMessage",
-                                        priv->data->status_html,
-                                        priv->data->status_len,
-                                        str_escaped, NULL, NULL, NULL, NULL,
-                                        "event", empathy_time_get_current ());
-               g_free (str_escaped);
-       }
-
-       /* There is no last contact */
-       if (priv->last_contact) {
-               g_object_unref (priv->last_contact);
-               priv->last_contact = NULL;
-       }
+       str_escaped = g_markup_escape_text (str, -1);
+       theme_adium_append_event_escaped (view, str_escaped);
+       g_free (str_escaped);
 }
 
 static void
@@ -681,26 +669,31 @@ theme_adium_clear (EmpathyChatView *view)
 static gboolean
 theme_adium_find_previous (EmpathyChatView *view,
                           const gchar     *search_criteria,
-                          gboolean         new_search)
+                          gboolean         new_search,
+                          gboolean         match_case)
 {
+       /* FIXME: Doesn't respect new_search */
        return webkit_web_view_search_text (WEBKIT_WEB_VIEW (view),
-                                           search_criteria, FALSE,
+                                           search_criteria, match_case,
                                            FALSE, TRUE);
 }
 
 static gboolean
 theme_adium_find_next (EmpathyChatView *view,
                       const gchar     *search_criteria,
-                      gboolean         new_search)
+                      gboolean         new_search,
+                      gboolean         match_case)
 {
+       /* FIXME: Doesn't respect new_search */
        return webkit_web_view_search_text (WEBKIT_WEB_VIEW (view),
-                                           search_criteria, FALSE,
+                                           search_criteria, match_case,
                                            TRUE, TRUE);
 }
 
 static void
 theme_adium_find_abilities (EmpathyChatView *view,
                            const gchar    *search_criteria,
+                            gboolean        match_case,
                            gboolean       *can_do_previous,
                            gboolean       *can_do_next)
 {
@@ -714,11 +707,12 @@ theme_adium_find_abilities (EmpathyChatView *view,
 
 static void
 theme_adium_highlight (EmpathyChatView *view,
-                      const gchar     *text)
+                      const gchar     *text,
+                      gboolean         match_case)
 {
        webkit_web_view_unmark_text_matches (WEBKIT_WEB_VIEW (view));
        webkit_web_view_mark_text_matches (WEBKIT_WEB_VIEW (view),
-                                          text, FALSE, 0);
+                                          text, match_case, 0);
        webkit_web_view_set_highlight_text_matches (WEBKIT_WEB_VIEW (view),
                                                    TRUE);
 }
@@ -811,6 +805,8 @@ theme_adium_context_menu_for_event (EmpathyThemeAdium *theme, GdkEventButton *ev
        gtk_widget_show_all (menu);
        gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
                        event->button, event->time);
+       g_object_ref_sink (menu);
+       g_object_unref (menu);
 }
 
 static gboolean