From f48b89ce4d61d16843361636ad9f155451fde98d Mon Sep 17 00:00:00 2001 From: Xavier Claessens Date: Wed, 3 Mar 2010 15:31:45 +0100 Subject: Move empathy_string_parser API to its own file --- libempathy-gtk/Makefile.am | 2 + libempathy-gtk/empathy-chat-text-view.c | 1 + libempathy-gtk/empathy-string-parser.c | 131 ++++++++++++++++++++++++++++++++ libempathy-gtk/empathy-string-parser.h | 74 ++++++++++++++++++ libempathy-gtk/empathy-theme-adium.c | 1 + libempathy-gtk/empathy-ui-utils.c | 104 ------------------------- libempathy-gtk/empathy-ui-utils.h | 45 ----------- 7 files changed, 209 insertions(+), 149 deletions(-) create mode 100644 libempathy-gtk/empathy-string-parser.c create mode 100644 libempathy-gtk/empathy-string-parser.h (limited to 'libempathy-gtk') diff --git a/libempathy-gtk/Makefile.am b/libempathy-gtk/Makefile.am index c9736ac43..6ec319e1c 100644 --- a/libempathy-gtk/Makefile.am +++ b/libempathy-gtk/Makefile.am @@ -65,6 +65,7 @@ libempathy_gtk_handwritten_source = \ empathy-sound.c \ empathy-spell.c \ empathy-status-preset-dialog.c \ + empathy-string-parser.c \ empathy-theme-boxes.c \ empathy-theme-irc.c \ empathy-theme-manager.c \ @@ -111,6 +112,7 @@ libempathy_gtk_headers = \ empathy-sound.h \ empathy-spell.h \ empathy-status-preset-dialog.h \ + empathy-string-parser.h \ empathy-theme-boxes.h \ empathy-theme-irc.h \ empathy-theme-manager.h \ diff --git a/libempathy-gtk/empathy-chat-text-view.c b/libempathy-gtk/empathy-chat-text-view.c index 07f8f6cb9..7f16ab9a3 100644 --- a/libempathy-gtk/empathy-chat-text-view.c +++ b/libempathy-gtk/empathy-chat-text-view.c @@ -42,6 +42,7 @@ #include "empathy-conf.h" #include "empathy-ui-utils.h" #include "empathy-smiley-manager.h" +#include "empathy-string-parser.h" #define DEBUG_FLAG EMPATHY_DEBUG_CHAT #include diff --git a/libempathy-gtk/empathy-string-parser.c b/libempathy-gtk/empathy-string-parser.c new file mode 100644 index 000000000..9d0163e8e --- /dev/null +++ b/libempathy-gtk/empathy-string-parser.c @@ -0,0 +1,131 @@ +/* + * Copyright (C) 2010 Collabora Ltd. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Authors: Xavier Claessens + */ + +#include + +#include + +#include "empathy-string-parser.h" +#include "empathy-smiley-manager.h" + +void +empathy_string_parser_substr (const gchar *text, + gssize len, + EmpathyStringParser *parsers, + gpointer user_data) +{ + if (parsers != NULL && parsers[0].match_func != NULL) { + parsers[0].match_func (text, len, + parsers[0].replace_func, parsers + 1, + user_data); + } +} + +void +empathy_string_match_link (const gchar *text, + gssize len, + EmpathyStringReplace replace_func, + EmpathyStringParser *sub_parsers, + gpointer user_data) +{ + GRegex *uri_regex; + GMatchInfo *match_info; + gboolean match; + gint last = 0; + + uri_regex = empathy_uri_regex_dup_singleton (); + match = g_regex_match_full (uri_regex, text, len, 0, 0, &match_info, NULL); + if (match) { + gint s = 0, e = 0; + + do { + g_match_info_fetch_pos (match_info, 0, &s, &e); + + if (s > last) { + /* Append the text between last link (or the + * start of the message) and this link */ + empathy_string_parser_substr (text + last, + s - last, + sub_parsers, + user_data); + } + + replace_func (text + s, e - s, NULL, user_data); + + last = e; + } while (g_match_info_next (match_info, NULL)); + } + + empathy_string_parser_substr (text + last, len - last, + sub_parsers, user_data); + + g_match_info_free (match_info); + g_regex_unref (uri_regex); +} + +void +empathy_string_match_smiley (const gchar *text, + gssize len, + EmpathyStringReplace replace_func, + EmpathyStringParser *sub_parsers, + gpointer user_data) +{ + guint last = 0; + EmpathySmileyManager *smiley_manager; + GSList *hits, *l; + + smiley_manager = empathy_smiley_manager_dup_singleton (); + hits = empathy_smiley_manager_parse_len (smiley_manager, text, len); + + for (l = hits; l; l = l->next) { + EmpathySmileyHit *hit = l->data; + + if (hit->start > last) { + /* Append the text between last smiley (or the + * start of the message) and this smiley */ + empathy_string_parser_substr (text + last, + hit->start - last, + sub_parsers, user_data); + } + + replace_func (text + hit->start, hit->end - hit->start, + hit, user_data); + + last = hit->end; + + empathy_smiley_hit_free (hit); + } + g_slist_free (hits); + g_object_unref (smiley_manager); + + empathy_string_parser_substr (text + last, len - last, + sub_parsers, user_data); +} + +void +empathy_string_match_all (const gchar *text, + gssize len, + EmpathyStringReplace replace_func, + EmpathyStringParser *sub_parsers, + gpointer user_data) +{ + replace_func (text, len, NULL, user_data); +} + diff --git a/libempathy-gtk/empathy-string-parser.h b/libempathy-gtk/empathy-string-parser.h new file mode 100644 index 000000000..696545b65 --- /dev/null +++ b/libempathy-gtk/empathy-string-parser.h @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2010 Collabora Ltd. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Authors: Xavier Claessens + */ + +#ifndef __EMPATHY_STRING_PARSER_H__ +#define __EMPATHY_STRING_PARSER_H__ + +#include + +G_BEGIN_DECLS + +typedef struct _EmpathyStringParser EmpathyStringParser; + +typedef void (*EmpathyStringReplace) (const gchar *text, + gssize len, + gpointer match_data, + gpointer user_data); +typedef void (*EmpathyStringMatch) (const gchar *text, + gssize len, + EmpathyStringReplace replace_func, + EmpathyStringParser *sub_parsers, + gpointer user_data); + +struct _EmpathyStringParser { + EmpathyStringMatch match_func; + EmpathyStringReplace replace_func; +}; + +void +empathy_string_parser_substr (const gchar *text, + gssize len, + EmpathyStringParser *parsers, + gpointer user_data); + +void +empathy_string_match_link (const gchar *text, + gssize len, + EmpathyStringReplace replace_func, + EmpathyStringParser *sub_parsers, + gpointer user_data); + +void +empathy_string_match_smiley (const gchar *text, + gssize len, + EmpathyStringReplace replace_func, + EmpathyStringParser *sub_parsers, + gpointer user_data); + +void +empathy_string_match_all (const gchar *text, + gssize len, + EmpathyStringReplace replace_func, + EmpathyStringParser *sub_parsers, + gpointer user_data); + +G_END_DECLS + +#endif /* __EMPATHY_STRING_PARSER_H__ */ diff --git a/libempathy-gtk/empathy-theme-adium.c b/libempathy-gtk/empathy-theme-adium.c index 5c67af857..ef7d3a73e 100644 --- a/libempathy-gtk/empathy-theme-adium.c +++ b/libempathy-gtk/empathy-theme-adium.c @@ -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 diff --git a/libempathy-gtk/empathy-ui-utils.c b/libempathy-gtk/empathy-ui-utils.c index dcba5fe23..a2865bc55 100644 --- a/libempathy-gtk/empathy-ui-utils.c +++ b/libempathy-gtk/empathy-ui-utils.c @@ -1726,107 +1726,3 @@ empathy_receive_file_with_file_chooser (EmpathyFTHandler *handler) gtk_widget_show (widget); } -void -empathy_string_parser_substr (const gchar *text, - gssize len, - EmpathyStringParser *parsers, - gpointer user_data) -{ - if (parsers != NULL && parsers[0].match_func != NULL) { - parsers[0].match_func (text, len, - parsers[0].replace_func, parsers + 1, - user_data); - } -} - -void -empathy_string_match_link (const gchar *text, - gssize len, - EmpathyStringReplace replace_func, - EmpathyStringParser *sub_parsers, - gpointer user_data) -{ - GRegex *uri_regex; - GMatchInfo *match_info; - gboolean match; - gint last = 0; - - uri_regex = empathy_uri_regex_dup_singleton (); - match = g_regex_match_full (uri_regex, text, len, 0, 0, &match_info, NULL); - if (match) { - gint s = 0, e = 0; - - do { - g_match_info_fetch_pos (match_info, 0, &s, &e); - - if (s > last) { - /* Append the text between last link (or the - * start of the message) and this link */ - empathy_string_parser_substr (text + last, - s - last, - sub_parsers, - user_data); - } - - replace_func (text + s, e - s, NULL, user_data); - - last = e; - } while (g_match_info_next (match_info, NULL)); - } - - empathy_string_parser_substr (text + last, len - last, - sub_parsers, user_data); - - g_match_info_free (match_info); - g_regex_unref (uri_regex); -} - -void -empathy_string_match_smiley (const gchar *text, - gssize len, - EmpathyStringReplace replace_func, - EmpathyStringParser *sub_parsers, - gpointer user_data) -{ - guint last = 0; - EmpathySmileyManager *smiley_manager; - GSList *hits, *l; - - smiley_manager = empathy_smiley_manager_dup_singleton (); - hits = empathy_smiley_manager_parse_len (smiley_manager, text, len); - - for (l = hits; l; l = l->next) { - EmpathySmileyHit *hit = l->data; - - if (hit->start > last) { - /* Append the text between last smiley (or the - * start of the message) and this smiley */ - empathy_string_parser_substr (text + last, - hit->start - last, - sub_parsers, user_data); - } - - replace_func (text + hit->start, hit->end - hit->start, - hit, user_data); - - last = hit->end; - - empathy_smiley_hit_free (hit); - } - g_slist_free (hits); - g_object_unref (smiley_manager); - - empathy_string_parser_substr (text + last, len - last, - sub_parsers, user_data); -} - -void -empathy_string_match_all (const gchar *text, - gssize len, - EmpathyStringReplace replace_func, - EmpathyStringParser *sub_parsers, - gpointer user_data) -{ - replace_func (text, len, NULL, user_data); -} - diff --git a/libempathy-gtk/empathy-ui-utils.h b/libempathy-gtk/empathy-ui-utils.h index 925ecc5cb..e03ec66f8 100644 --- a/libempathy-gtk/empathy-ui-utils.h +++ b/libempathy-gtk/empathy-ui-utils.h @@ -130,51 +130,6 @@ gchar * empathy_make_absolute_url (const gchar *url); gchar * empathy_make_absolute_url_len (const gchar *url, guint len); -/* String parser */ -typedef struct _EmpathyStringParser EmpathyStringParser; - -typedef void (*EmpathyStringReplace) (const gchar *text, - gssize len, - gpointer match_data, - gpointer user_data); -typedef void (*EmpathyStringMatch) (const gchar *text, - gssize len, - EmpathyStringReplace replace_func, - EmpathyStringParser *sub_parsers, - gpointer user_data); - -struct _EmpathyStringParser { - EmpathyStringMatch match_func; - EmpathyStringReplace replace_func; -}; - -void -empathy_string_parser_substr (const gchar *text, - gssize len, - EmpathyStringParser *parsers, - gpointer user_data); - -void -empathy_string_match_link (const gchar *text, - gssize len, - EmpathyStringReplace replace_func, - EmpathyStringParser *sub_parsers, - gpointer user_data); - -void -empathy_string_match_smiley (const gchar *text, - gssize len, - EmpathyStringReplace replace_func, - EmpathyStringParser *sub_parsers, - gpointer user_data); - -void -empathy_string_match_all (const gchar *text, - gssize len, - EmpathyStringReplace replace_func, - EmpathyStringParser *sub_parsers, - gpointer user_data); - G_END_DECLS #endif /* __EMPATHY_UI_UTILS_H__ */ -- cgit v1.2.3 From e99f234b1e90869d04a17e300662b4be8c353bfe Mon Sep 17 00:00:00 2001 From: Xavier Claessens Date: Wed, 3 Mar 2010 15:52:35 +0100 Subject: Move empathy_uri_regex_dup_singleton to be private inside empathy-string-parser.c Now that our code is correctly factored, that regex can be made private --- libempathy-gtk/empathy-string-parser.c | 25 ++++++++++++++++++++++++- libempathy-gtk/empathy-ui-utils.c | 23 ----------------------- libempathy-gtk/empathy-ui-utils.h | 1 - 3 files changed, 24 insertions(+), 25 deletions(-) (limited to 'libempathy-gtk') diff --git a/libempathy-gtk/empathy-string-parser.c b/libempathy-gtk/empathy-string-parser.c index 9d0163e8e..27421eb59 100644 --- a/libempathy-gtk/empathy-string-parser.c +++ b/libempathy-gtk/empathy-string-parser.c @@ -25,6 +25,29 @@ #include "empathy-string-parser.h" #include "empathy-smiley-manager.h" +#define SCHEMES "([a-zA-Z\\+]+)" +#define INVALID_CHARS "\\s\"'" +#define INVALID_CHARS_EXT INVALID_CHARS "\\[\\]<>(){},;:?" +#define BODY "([^"INVALID_CHARS"]+)" +#define BODY_END "([^"INVALID_CHARS"]*)[^"INVALID_CHARS_EXT".]" +#define BODY_STRICT "([^"INVALID_CHARS_EXT"]+)" +#define URI_REGEX "("SCHEMES"://"BODY_END")" \ + "|((www|ftp)\\."BODY_END")" \ + "|((mailto:)?"BODY_STRICT"@"BODY"\\."BODY_END")" + +static GRegex * +uri_regex_dup_singleton (void) +{ + static GRegex *uri_regex = NULL; + + /* We intentionally leak the regex so it's not recomputed */ + if (!uri_regex) { + uri_regex = g_regex_new (URI_REGEX, 0, 0, NULL); + } + + return g_regex_ref (uri_regex); +} + void empathy_string_parser_substr (const gchar *text, gssize len, @@ -50,7 +73,7 @@ empathy_string_match_link (const gchar *text, gboolean match; gint last = 0; - uri_regex = empathy_uri_regex_dup_singleton (); + uri_regex = uri_regex_dup_singleton (); match = g_regex_match_full (uri_regex, text, len, 0, 0, &match_info, NULL); if (match) { gint s = 0, e = 0; diff --git a/libempathy-gtk/empathy-ui-utils.c b/libempathy-gtk/empathy-ui-utils.c index a2865bc55..927b63eae 100644 --- a/libempathy-gtk/empathy-ui-utils.c +++ b/libempathy-gtk/empathy-ui-utils.c @@ -50,16 +50,6 @@ #include #include -#define SCHEMES "([a-zA-Z\\+]+)" -#define INVALID_CHARS "\\s\"'" -#define INVALID_CHARS_EXT INVALID_CHARS "\\[\\]<>(){},;:?" -#define BODY "([^"INVALID_CHARS"]+)" -#define BODY_END "([^"INVALID_CHARS"]*)[^"INVALID_CHARS_EXT".]" -#define BODY_STRICT "([^"INVALID_CHARS_EXT"]+)" -#define URI_REGEX "("SCHEMES"://"BODY_END")" \ - "|((www|ftp)\\."BODY_END")" \ - "|((mailto:)?"BODY_STRICT"@"BODY"\\."BODY_END")" - void empathy_gtk_init (void) { @@ -75,19 +65,6 @@ empathy_gtk_init (void) initialized = TRUE; } -GRegex * -empathy_uri_regex_dup_singleton (void) -{ - static GRegex *uri_regex = NULL; - - /* We intentionally leak the regex so it's not recomputed */ - if (!uri_regex) { - uri_regex = g_regex_new (URI_REGEX, 0, 0, NULL); - } - - return g_regex_ref (uri_regex); -} - static GtkBuilder * builder_get_file_valist (const gchar *filename, const gchar *first_object, diff --git a/libempathy-gtk/empathy-ui-utils.h b/libempathy-gtk/empathy-ui-utils.h index e03ec66f8..05033f30f 100644 --- a/libempathy-gtk/empathy-ui-utils.h +++ b/libempathy-gtk/empathy-ui-utils.h @@ -47,7 +47,6 @@ G_BEGIN_DECLS (y) < gdk_screen_height ()) void empathy_gtk_init (void); -GRegex * empathy_uri_regex_dup_singleton (void); /* Glade */ GtkBuilder * empathy_builder_get_file (const gchar *filename, -- cgit v1.2.3 From 4f990cd2192a39f0b6111fc9aad1848aaeda11c4 Mon Sep 17 00:00:00 2001 From: Xavier Claessens Date: Wed, 3 Mar 2010 15:33:35 +0100 Subject: Reorganize code in empathy-ui-utils.ch to group related code --- libempathy-gtk/empathy-ui-utils.c | 26 +++++++++++++------------- libempathy-gtk/empathy-ui-utils.h | 19 ++++++++++++------- 2 files changed, 25 insertions(+), 20 deletions(-) (limited to 'libempathy-gtk') diff --git a/libempathy-gtk/empathy-ui-utils.c b/libempathy-gtk/empathy-ui-utils.c index 927b63eae..8819cb53a 100644 --- a/libempathy-gtk/empathy-ui-utils.c +++ b/libempathy-gtk/empathy-ui-utils.c @@ -1531,19 +1531,6 @@ empathy_link_button_new (const gchar *url, return gtk_link_button_new_with_label (url, title); } -void -empathy_toggle_button_set_state_quietly (GtkWidget *widget, - GCallback callback, - gpointer user_data, - gboolean active) -{ - g_return_if_fail (GTK_IS_TOGGLE_BUTTON (widget)); - - g_signal_handlers_block_by_func (widget, callback, user_data); - g_object_set (widget, "active", active, NULL); - g_signal_handlers_unblock_by_func (widget, callback, user_data); -} - void empathy_send_file (EmpathyContact *contact, GFile *file) { @@ -1703,3 +1690,16 @@ empathy_receive_file_with_file_chooser (EmpathyFTHandler *handler) gtk_widget_show (widget); } +void +empathy_toggle_button_set_state_quietly (GtkWidget *widget, + GCallback callback, + gpointer user_data, + gboolean active) +{ + g_return_if_fail (GTK_IS_TOGGLE_BUTTON (widget)); + + g_signal_handlers_block_by_func (widget, callback, user_data); + g_object_set (widget, "active", active, NULL); + g_signal_handlers_unblock_by_func (widget, callback, user_data); +} + diff --git a/libempathy-gtk/empathy-ui-utils.h b/libempathy-gtk/empathy-ui-utils.h index 05033f30f..097976ad6 100644 --- a/libempathy-gtk/empathy-ui-utils.h +++ b/libempathy-gtk/empathy-ui-utils.h @@ -109,15 +109,18 @@ void empathy_window_present (GtkWindow *windo void empathy_window_iconify (GtkWindow *window, GtkStatusIcon *status_icon); GtkWindow * empathy_get_toplevel_window (GtkWidget *widget); + +/* URL */ +gchar * empathy_make_absolute_url (const gchar *url); + +gchar * empathy_make_absolute_url_len (const gchar *url, + guint len); void empathy_url_show (GtkWidget *parent, const char *url); -void empathy_toggle_button_set_state_quietly (GtkWidget *widget, - GCallback callback, - gpointer user_data, - gboolean active); GtkWidget * empathy_link_button_new (const gchar *url, const gchar *title); +/* File transfer */ void empathy_send_file (EmpathyContact *contact, GFile *file); void empathy_send_file_from_uri_list (EmpathyContact *contact, @@ -125,9 +128,11 @@ void empathy_send_file_from_uri_list (EmpathyContact *conta void empathy_send_file_with_file_chooser (EmpathyContact *contact); void empathy_receive_file_with_file_chooser (EmpathyFTHandler *handler); -gchar * empathy_make_absolute_url (const gchar *url); -gchar * empathy_make_absolute_url_len (const gchar *url, - guint len); +/* Misc */ +void empathy_toggle_button_set_state_quietly (GtkWidget *widget, + GCallback callback, + gpointer user_data, + gboolean active); G_END_DECLS -- cgit v1.2.3 From 3e4bea3436209cca9ce685fdbacec7fcc11f1388 Mon Sep 17 00:00:00 2001 From: Xavier Claessens Date: Wed, 3 Mar 2010 15:39:40 +0100 Subject: Make empathy_string_replace_link and empathy_string_replace_escaped public The code is moved from empathy-theme-adium.c --- libempathy-gtk/empathy-string-parser.c | 39 ++++++++++++++++++++++++++++ libempathy-gtk/empathy-string-parser.h | 13 ++++++++++ libempathy-gtk/empathy-theme-adium.c | 46 +++------------------------------- 3 files changed, 56 insertions(+), 42 deletions(-) (limited to 'libempathy-gtk') diff --git a/libempathy-gtk/empathy-string-parser.c b/libempathy-gtk/empathy-string-parser.c index 27421eb59..1240edd50 100644 --- a/libempathy-gtk/empathy-string-parser.c +++ b/libempathy-gtk/empathy-string-parser.c @@ -24,6 +24,7 @@ #include "empathy-string-parser.h" #include "empathy-smiley-manager.h" +#include "empathy-ui-utils.h" #define SCHEMES "([a-zA-Z\\+]+)" #define INVALID_CHARS "\\s\"'" @@ -152,3 +153,41 @@ empathy_string_match_all (const gchar *text, replace_func (text, len, NULL, user_data); } +void +empathy_string_replace_link (const gchar *text, + gssize len, + gpointer match_data, + gpointer user_data) +{ + GString *string = user_data; + gchar *real_url; + gchar *escaped; + + real_url = empathy_make_absolute_url_len (text, len); + + /* The thing we are making a link of may contain + * characters which need escaping */ + escaped = g_markup_escape_text (text, len); + + /* Append the link inside tag */ + g_string_append_printf (string, "%s", + real_url, escaped); + + g_free (real_url); + g_free (escaped); +} + +void +empathy_string_replace_escaped (const gchar *text, + gssize len, + gpointer match_data, + gpointer user_data) +{ + GString *string = user_data; + gchar *escaped; + + escaped = g_markup_escape_text (text, len); + g_string_append (string, escaped); + g_free (escaped); +} + diff --git a/libempathy-gtk/empathy-string-parser.h b/libempathy-gtk/empathy-string-parser.h index 696545b65..db646d60b 100644 --- a/libempathy-gtk/empathy-string-parser.h +++ b/libempathy-gtk/empathy-string-parser.h @@ -69,6 +69,19 @@ empathy_string_match_all (const gchar *text, EmpathyStringParser *sub_parsers, gpointer user_data); +/* Replace functions assume user_data is a GString */ +void +empathy_string_replace_link (const gchar *text, + gssize len, + gpointer match_data, + gpointer user_data); + +void +empathy_string_replace_escaped (const gchar *text, + gssize len, + gpointer match_data, + gpointer user_data); + G_END_DECLS #endif /* __EMPATHY_STRING_PARSER_H__ */ diff --git a/libempathy-gtk/empathy-theme-adium.c b/libempathy-gtk/empathy-theme-adium.c index ef7d3a73e..7736be270 100644 --- a/libempathy-gtk/empathy-theme-adium.c +++ b/libempathy-gtk/empathy-theme-adium.c @@ -221,30 +221,6 @@ theme_adium_match_newline (const gchar *text, sub_parsers, user_data); } -static void -theme_adium_replace_link (const gchar *text, - gssize len, - gpointer match_data, - gpointer user_data) -{ - GString *string = user_data; - gchar *real_url; - gchar *escaped; - - real_url = empathy_make_absolute_url_len (text, len); - - /* The thing we are making a link of may contain - * characters which need escaping */ - escaped = g_markup_escape_text (text, len); - - /* Append the link inside tag */ - g_string_append_printf (string, "%s", - real_url, escaped); - - g_free (real_url); - g_free (escaped); -} - static void theme_adium_replace_smiley (const gchar *text, gssize len, @@ -260,32 +236,18 @@ theme_adium_replace_smiley (const gchar *text, hit->path, (int)len, text, (int)len, text); } -static void -theme_adium_replace_escaped (const gchar *text, - gssize len, - gpointer match_data, - gpointer user_data) -{ - GString *string = user_data; - gchar *escaped; - - escaped = g_markup_escape_text (text, len); - g_string_append (string, escaped); - g_free (escaped); -} - 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, theme_adium_replace_escaped}, + {empathy_string_match_all, empathy_string_replace_escaped}, {NULL, NULL} }; static EmpathyStringParser string_parsers_with_smiley[] = { - {empathy_string_match_link, theme_adium_replace_link}, + {empathy_string_match_link, empathy_string_replace_link}, {empathy_string_match_smiley, theme_adium_replace_smiley}, {theme_adium_match_newline, NULL}, - {empathy_string_match_all, theme_adium_replace_escaped}, + {empathy_string_match_all, empathy_string_replace_escaped}, {NULL, NULL} }; -- cgit v1.2.3 From 2e9c6f70f0291f84b266915620930d97dec1a467 Mon Sep 17 00:00:00 2001 From: Xavier Claessens Date: Wed, 3 Mar 2010 15:48:07 +0100 Subject: New function empathy_add_link_markup() to be used with gtk_label_set_markup() --- libempathy-gtk/empathy-string-parser.c | 16 ++++++++++++++++ libempathy-gtk/empathy-string-parser.h | 3 +++ 2 files changed, 19 insertions(+) (limited to 'libempathy-gtk') diff --git a/libempathy-gtk/empathy-string-parser.c b/libempathy-gtk/empathy-string-parser.c index 1240edd50..1f9f5f2ab 100644 --- a/libempathy-gtk/empathy-string-parser.c +++ b/libempathy-gtk/empathy-string-parser.c @@ -191,3 +191,19 @@ empathy_string_replace_escaped (const gchar *text, g_free (escaped); } +gchar * +empathy_add_link_markup (const gchar *text) +{ + static EmpathyStringParser parsers[] = { + {empathy_string_match_link, empathy_string_replace_link}, + {empathy_string_match_all, empathy_string_replace_escaped}, + {NULL, NULL} + }; + GString *string; + + string = g_string_sized_new (strlen (text)); + empathy_string_parser_substr (text, -1, parsers, string); + + return g_string_free (string, FALSE); +} + diff --git a/libempathy-gtk/empathy-string-parser.h b/libempathy-gtk/empathy-string-parser.h index db646d60b..aec741add 100644 --- a/libempathy-gtk/empathy-string-parser.h +++ b/libempathy-gtk/empathy-string-parser.h @@ -82,6 +82,9 @@ empathy_string_replace_escaped (const gchar *text, gpointer match_data, gpointer user_data); +gchar * +empathy_add_link_markup (const gchar *text); + G_END_DECLS #endif /* __EMPATHY_STRING_PARSER_H__ */ -- cgit v1.2.3 From 00ab069a55f05f0203bf58f071fa7adc54b6e9ac Mon Sep 17 00:00:00 2001 From: Xavier Claessens Date: Wed, 3 Mar 2010 16:17:37 +0100 Subject: Make links clickable in presence message and topics Fixes bug #525576 --- libempathy-gtk/empathy-chat.c | 8 +++++++- libempathy-gtk/empathy-contact-widget.c | 18 ++++++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) (limited to 'libempathy-gtk') diff --git a/libempathy-gtk/empathy-chat.c b/libempathy-gtk/empathy-chat.c index bec1d7704..4db9e455c 100644 --- a/libempathy-gtk/empathy-chat.c +++ b/libempathy-gtk/empathy-chat.c @@ -56,6 +56,7 @@ #include "empathy-theme-manager.h" #include "empathy-smiley-manager.h" #include "empathy-ui-utils.h" +#include "empathy-string-parser.h" #define DEBUG_FLAG EMPATHY_DEBUG_CHAT #include @@ -1212,7 +1213,12 @@ chat_property_changed_cb (EmpathyTpChat *tp_chat, if (EMP_STR_EMPTY (priv->subject)) { gtk_widget_hide (priv->hbox_topic); } else { - gtk_label_set_text (GTK_LABEL (priv->label_topic), priv->subject); + gchar *markup_text; + + markup_text = empathy_add_link_markup (priv->subject); + gtk_label_set_markup (GTK_LABEL (priv->label_topic), markup_text); + g_free (markup_text); + gtk_widget_show (priv->hbox_topic); } if (priv->block_events_timeout_id == 0) { diff --git a/libempathy-gtk/empathy-contact-widget.c b/libempathy-gtk/empathy-contact-widget.c index 9cb493fbe..500a387f6 100644 --- a/libempathy-gtk/empathy-contact-widget.c +++ b/libempathy-gtk/empathy-contact-widget.c @@ -47,6 +47,7 @@ #include "empathy-avatar-chooser.h" #include "empathy-avatar-image.h" #include "empathy-ui-utils.h" +#include "empathy-string-parser.h" #include "empathy-kludge-label.h" #define DEBUG_FLAG EMPATHY_DEBUG_CONTACT @@ -948,8 +949,21 @@ contact_widget_name_notify_cb (EmpathyContactWidget *information) static void contact_widget_presence_notify_cb (EmpathyContactWidget *information) { - gtk_label_set_text (GTK_LABEL (information->label_status), - empathy_contact_get_status (information->contact)); + const gchar *status; + + status = empathy_contact_get_status (information->contact); + if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP)) + { + gchar *markup_text; + + markup_text = empathy_add_link_markup (status); + gtk_label_set_markup (GTK_LABEL (information->label_status), markup_text); + g_free (markup_text); + } + else { + gtk_label_set_text (GTK_LABEL (information->label_status), status); + } + gtk_image_set_from_icon_name (GTK_IMAGE (information->image_state), empathy_icon_name_for_contact (information->contact), GTK_ICON_SIZE_BUTTON); -- cgit v1.2.3 From 1c9ef08484efd1596c57e1da7a17d3eb790d304d Mon Sep 17 00:00:00 2001 From: Xavier Claessens Date: Wed, 3 Mar 2010 16:51:48 +0100 Subject: Remove unused function empathy_toggle_button_set_state_quietly --- libempathy-gtk/empathy-ui-utils.c | 13 ------------- libempathy-gtk/empathy-ui-utils.h | 6 ------ 2 files changed, 19 deletions(-) (limited to 'libempathy-gtk') diff --git a/libempathy-gtk/empathy-ui-utils.c b/libempathy-gtk/empathy-ui-utils.c index 8819cb53a..d6e9ffeef 100644 --- a/libempathy-gtk/empathy-ui-utils.c +++ b/libempathy-gtk/empathy-ui-utils.c @@ -1690,16 +1690,3 @@ empathy_receive_file_with_file_chooser (EmpathyFTHandler *handler) gtk_widget_show (widget); } -void -empathy_toggle_button_set_state_quietly (GtkWidget *widget, - GCallback callback, - gpointer user_data, - gboolean active) -{ - g_return_if_fail (GTK_IS_TOGGLE_BUTTON (widget)); - - g_signal_handlers_block_by_func (widget, callback, user_data); - g_object_set (widget, "active", active, NULL); - g_signal_handlers_unblock_by_func (widget, callback, user_data); -} - diff --git a/libempathy-gtk/empathy-ui-utils.h b/libempathy-gtk/empathy-ui-utils.h index 097976ad6..38732c7f9 100644 --- a/libempathy-gtk/empathy-ui-utils.h +++ b/libempathy-gtk/empathy-ui-utils.h @@ -128,12 +128,6 @@ void empathy_send_file_from_uri_list (EmpathyContact *conta void empathy_send_file_with_file_chooser (EmpathyContact *contact); void empathy_receive_file_with_file_chooser (EmpathyFTHandler *handler); -/* Misc */ -void empathy_toggle_button_set_state_quietly (GtkWidget *widget, - GCallback callback, - gpointer user_data, - gboolean active); - G_END_DECLS #endif /* __EMPATHY_UI_UTILS_H__ */ -- cgit v1.2.3 From 207c3bdd45e280beb019153ca6c844178f6e331a Mon Sep 17 00:00:00 2001 From: Xavier Claessens Date: Thu, 4 Mar 2010 16:24:00 +0100 Subject: Also make links clickable in tooltip It is not clickable, but still nice looking --- libempathy-gtk/empathy-contact-widget.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) (limited to 'libempathy-gtk') diff --git a/libempathy-gtk/empathy-contact-widget.c b/libempathy-gtk/empathy-contact-widget.c index 500a387f6..75f244698 100644 --- a/libempathy-gtk/empathy-contact-widget.c +++ b/libempathy-gtk/empathy-contact-widget.c @@ -950,19 +950,12 @@ static void contact_widget_presence_notify_cb (EmpathyContactWidget *information) { const gchar *status; + gchar *markup_text; status = empathy_contact_get_status (information->contact); - if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP)) - { - gchar *markup_text; - - markup_text = empathy_add_link_markup (status); - gtk_label_set_markup (GTK_LABEL (information->label_status), markup_text); - g_free (markup_text); - } - else { - gtk_label_set_text (GTK_LABEL (information->label_status), status); - } + markup_text = empathy_add_link_markup (status); + gtk_label_set_markup (GTK_LABEL (information->label_status), markup_text); + g_free (markup_text); gtk_image_set_from_icon_name (GTK_IMAGE (information->image_state), empathy_icon_name_for_contact (information->contact), -- cgit v1.2.3 From 7c9a7e0a126322fea64c7a4dfcd455400cafcbe8 Mon Sep 17 00:00:00 2001 From: Xavier Claessens Date: Thu, 4 Mar 2010 16:28:56 +0100 Subject: Add a comment explaining what does empathy_add_link_markup, and don't make parser list static --- libempathy-gtk/empathy-string-parser.c | 2 +- libempathy-gtk/empathy-string-parser.h | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) (limited to 'libempathy-gtk') diff --git a/libempathy-gtk/empathy-string-parser.c b/libempathy-gtk/empathy-string-parser.c index 1f9f5f2ab..fa56a2d42 100644 --- a/libempathy-gtk/empathy-string-parser.c +++ b/libempathy-gtk/empathy-string-parser.c @@ -194,7 +194,7 @@ empathy_string_replace_escaped (const gchar *text, gchar * empathy_add_link_markup (const gchar *text) { - static EmpathyStringParser parsers[] = { + EmpathyStringParser parsers[] = { {empathy_string_match_link, empathy_string_replace_link}, {empathy_string_match_all, empathy_string_replace_escaped}, {NULL, NULL} diff --git a/libempathy-gtk/empathy-string-parser.h b/libempathy-gtk/empathy-string-parser.h index aec741add..78a822652 100644 --- a/libempathy-gtk/empathy-string-parser.h +++ b/libempathy-gtk/empathy-string-parser.h @@ -82,6 +82,8 @@ empathy_string_replace_escaped (const gchar *text, gpointer match_data, gpointer user_data); +/* Returns a new string with html tag around links, and escape the rest. + * To be used with gtk_label_set_markup() for example */ gchar * empathy_add_link_markup (const gchar *text); -- cgit v1.2.3