From f8a806f78f538409b502f58f09f969186e908258 Mon Sep 17 00:00:00 2001 From: Jose Dapena Paz Date: Thu, 19 Jul 2007 17:20:10 +0000 Subject: [PATCH] * src/widgets/modest-recpt-editor.c: * Now we discard invalid chars (bullets and images) on pasting in recipient editor. This way, if we paste from the editor these symbols, they should be removed from text pasted in the recipient editor (fixes NB#62575). pmo-trunk-r2757 --- src/widgets/modest-recpt-editor.c | 51 +++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/src/widgets/modest-recpt-editor.c b/src/widgets/modest-recpt-editor.c index ddf648c..3e60a02 100644 --- a/src/widgets/modest-recpt-editor.c +++ b/src/widgets/modest-recpt-editor.c @@ -440,6 +440,50 @@ modest_recpt_editor_on_focus_in (GtkTextView *text_view, gtk_text_view_place_cursor_onscreen (GTK_TEXT_VIEW (priv->text_view)); } +static gboolean +is_valid_insert (const gchar *text, gint len) +{ + gunichar c; + gint i= 0; + const gchar *current; + if (text == NULL) + return TRUE; + current = text; + + while (((len == -1)||(i < len)) && (*text != '\0')) { + c = g_utf8_get_char (current); + if (c == 0x2022 || c == 0xfffc) + return FALSE; + current = g_utf8_next_char (current); + i = current - text; + } + return TRUE; +} + +static gchar * +create_valid_text (const gchar *text, gint len) +{ + gunichar c; + gint i= 0; + GString *str; + const gchar *current; + + if (text == NULL) + return NULL; + + str = g_string_new (""); + current = text; + + while (((len == -1)||(i < len)) && (*text != '\0')) { + c = g_utf8_get_char (current); + if (c != 0x2022 && c != 0xfffc) + str = g_string_append_unichar (str, c); + current = g_utf8_next_char (current); + i = current - text; + } + return g_string_free (str, FALSE); +} + static void modest_recpt_editor_on_insert_text (GtkTextBuffer *buffer, GtkTextIter *location, @@ -451,6 +495,13 @@ modest_recpt_editor_on_insert_text (GtkTextBuffer *buffer, gunichar prev_char; ModestRecptEditorPrivate *priv = MODEST_RECPT_EDITOR_GET_PRIVATE (editor); + if (!is_valid_insert (text, len)) { + gchar *new_text = create_valid_text (text, len); + g_signal_stop_emission_by_name (G_OBJECT (buffer), "insert-text"); + gtk_text_buffer_insert (buffer, location, new_text, -1); + g_free (new_text); + } + if (iter_has_recipient (location)) { gtk_text_buffer_get_end_iter (buffer, location); gtk_text_buffer_place_cursor (buffer, location); -- 1.7.9.5