]> git.0d.be Git - empathy.git/commitdiff
Use new smiley parser in EmpathyChatTextView.
authorXavier Claessens <xclaesse@gmail.com>
Mon, 26 Oct 2009 11:59:09 +0000 (12:59 +0100)
committerXavier Claessens <xclaesse@gmail.com>
Tue, 24 Nov 2009 17:29:43 +0000 (18:29 +0100)
libempathy-gtk/empathy-chat-text-view.c
libempathy-gtk/empathy-smiley-manager.h

index de777f2fbd4ef2daf9ffc079761448b8745c977f..aa8676bfd6155f046e3d79d8ce69bd75be17d532 100644 (file)
@@ -1262,7 +1262,8 @@ chat_text_view_insert_text_with_emoticons (EmpathyChatTextView *view,
 {
        EmpathyChatTextViewPriv *priv = GET_PRIV (view);
        gboolean                 use_smileys = FALSE;
-       GSList                  *smileys, *l;
+       GSList                  *hits, *l;
+       gint                     last = 0;
 
        empathy_conf_get_bool (empathy_conf_get (),
                               EMPATHY_PREFS_CHAT_SHOW_SMILEYS,
@@ -1273,19 +1274,25 @@ chat_text_view_insert_text_with_emoticons (EmpathyChatTextView *view,
                return;
        }
 
-       smileys = empathy_smiley_manager_parse (priv->smiley_manager, str);
-       for (l = smileys; l; l = l->next) {
-               EmpathySmiley *smiley;
+       hits = empathy_smiley_manager_parse_len (priv->smiley_manager, str, -1);
+       for (l = hits; l; l = l->next) {
+               EmpathySmileyHit *hit = l->data;
 
-               smiley = l->data;
-               if (smiley->pixbuf) {
-                       gtk_text_buffer_insert_pixbuf (priv->buffer, iter, smiley->pixbuf);
-               } else {
-                       gtk_text_buffer_insert (priv->buffer, iter, smiley->str, -1);
+               if (hit->start > last) {
+                       /* Append the text between last smiley (or the
+                        * start of the message) and this smiley */
+                       gtk_text_buffer_insert (priv->buffer, iter, str + last,
+                                               hit->start - last);
                }
-               empathy_smiley_free (smiley);
+               gtk_text_buffer_insert_pixbuf (priv->buffer, iter, hit->pixbuf);
+
+               last = hit->end;
+
+               empathy_smiley_hit_free (hit);
        }
-       g_slist_free (smileys);
+       g_slist_free (hits);
+
+       gtk_text_buffer_insert (priv->buffer, iter, str + last, -1);
 }
 
 void
index 7d37c592a5b3e3e6a0471dec68e6fe1f4235cd38..9530fe85b2a888b2868f093644c2d898d7d06eca 100644 (file)
@@ -56,8 +56,8 @@ typedef struct {
 typedef struct {
        GdkPixbuf   *pixbuf;
        const gchar *path;
-       gint        start;
-       gint        end;
+       gint         start;
+       gint         end;
 } EmpathySmileyHit;
 
 typedef void (*EmpathySmileyMenuFunc) (EmpathySmileyManager *manager,