diff options
Diffstat (limited to 'libempathy-gtk')
-rw-r--r-- | libempathy-gtk/empathy-log-window.c | 57 |
1 files changed, 50 insertions, 7 deletions
diff --git a/libempathy-gtk/empathy-log-window.c b/libempathy-gtk/empathy-log-window.c index 4d304c582..773cfafd6 100644 --- a/libempathy-gtk/empathy-log-window.c +++ b/libempathy-gtk/empathy-log-window.c @@ -804,7 +804,7 @@ log_window_append_chat_message (TplEvent *event, { GtkTreeStore *store = log_window->store_events; GtkTreeIter iter, parent; - gchar *pretty_date, *body; + gchar *pretty_date, *alias, *body, *msg; GDateTime *date; date = g_date_time_new_from_unix_utc ( @@ -814,21 +814,62 @@ log_window_append_chat_message (TplEvent *event, get_parent_iter_for_message (event, message, &parent); + msg = g_markup_escape_text (empathy_message_get_body (message), -1); + alias = g_markup_escape_text ( + tpl_entity_get_alias (tpl_event_get_sender (event)), -1); + + /* If the user is searching, highlight the matched text */ + if (!EMP_STR_EMPTY (log_window->last_find)) + { + gchar *str = g_regex_escape_string (log_window->last_find, -1); + gchar *replacement = g_markup_printf_escaped ( + "<span background=\"yellow\">%s</span>", + log_window->last_find); + GError *error = NULL; + GRegex *regex = g_regex_new (str, 0, 0, &error); + + if (regex == NULL) + { + DEBUG ("Could not create regex: %s", error->message); + g_error_free (error); + } + else + { + gchar *new_msg = g_regex_replace_literal (regex, + empathy_message_get_body (message), -1, 0, replacement, + 0, &error); + + if (new_msg != NULL) + { + /* We pass ownership of new_msg to msg, which is freed later */ + g_free (msg); + msg = new_msg; + } + else + { + DEBUG ("Error while performing string substitution: %s", + error->message); + g_error_free (error); + } + } + + g_free (str); + g_free (replacement); + + tp_clear_pointer (®ex, g_regex_unref); + } + if (tpl_text_event_get_message_type (TPL_TEXT_EVENT (event)) == TP_CHANNEL_TEXT_MESSAGE_TYPE_ACTION) { /* Translators: this is an emote: '* Danielle waves' */ - body = g_markup_printf_escaped (_("<i>* %s %s</i>"), - tpl_entity_get_alias (tpl_event_get_sender (event)), - empathy_message_get_body (message)); + body = g_strdup_printf (_("<i>* %s %s</i>"), alias, msg); } else { /* Translators: this is a message: 'Danielle: hello' * The string in bold is the sender's name */ - body = g_markup_printf_escaped (_("<b>%s:</b> %s"), - tpl_entity_get_alias (tpl_event_get_sender (event)), - empathy_message_get_body (message)); + body = g_strdup_printf (_("<b>%s:</b> %s"), alias, msg); } gtk_tree_store_append (store, &iter, &parent); @@ -842,7 +883,9 @@ log_window_append_chat_message (TplEvent *event, COL_EVENTS_EVENT, event, -1); + g_free (msg); g_free (body); + g_free (alias); g_free (pretty_date); g_date_time_unref (date); } |