aboutsummaryrefslogtreecommitdiffstats
path: root/libempathy-gtk/empathy-log-window.c
diff options
context:
space:
mode:
authorEmilio Pozuelo Monfort <emilio.pozuelo@collabora.co.uk>2011-06-21 00:38:32 +0800
committerEmilio Pozuelo Monfort <emilio.pozuelo@collabora.co.uk>2011-06-21 19:39:27 +0800
commit5faa536ed6fc6ce21421900d4ddea64c61f5182a (patch)
treec70aefb6e1856243965419e2a80bedc21b911373 /libempathy-gtk/empathy-log-window.c
parent04ab5d6190a94bcf5db98ff8f857fd20d61ef332 (diff)
downloadgsoc2013-empathy-5faa536ed6fc6ce21421900d4ddea64c61f5182a.tar
gsoc2013-empathy-5faa536ed6fc6ce21421900d4ddea64c61f5182a.tar.gz
gsoc2013-empathy-5faa536ed6fc6ce21421900d4ddea64c61f5182a.tar.bz2
gsoc2013-empathy-5faa536ed6fc6ce21421900d4ddea64c61f5182a.tar.lz
gsoc2013-empathy-5faa536ed6fc6ce21421900d4ddea64c61f5182a.tar.xz
gsoc2013-empathy-5faa536ed6fc6ce21421900d4ddea64c61f5182a.tar.zst
gsoc2013-empathy-5faa536ed6fc6ce21421900d4ddea64c61f5182a.zip
LogWindow: highlight the searched text
https://bugzilla.gnome.org/show_bug.cgi?id=652522
Diffstat (limited to 'libempathy-gtk/empathy-log-window.c')
-rw-r--r--libempathy-gtk/empathy-log-window.c57
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 (&regex, 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);
}