X-Git-Url: http://git.maemo.org/git/?p=modest;a=blobdiff_plain;f=src%2Fwidgets%2Fmodest-recpt-editor.c;h=3e60a02b3853e67b211115457330d81329115f44;hp=e77a981eb7db4dd527f9fea9ad409317c020420a;hb=f8a806f78f538409b502f58f09f969186e908258;hpb=c82fe05ac5c60ec3b67d0dc59de20ffb40219695 diff --git a/src/widgets/modest-recpt-editor.c b/src/widgets/modest-recpt-editor.c index e77a981..3e60a02 100644 --- a/src/widgets/modest-recpt-editor.c +++ b/src/widgets/modest-recpt-editor.c @@ -328,7 +328,8 @@ modest_recpt_editor_instance_init (GTypeInstance *instance, gpointer g_class) gtk_container_add (GTK_CONTAINER (priv->abook_button), abook_icon); priv->text_view = gtk_text_view_new (); - + priv->recipients = NULL; + priv->scrolled_window = modest_scroll_text_new (GTK_TEXT_VIEW (priv->text_view), 5); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->scrolled_window), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); @@ -439,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, @@ -450,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); @@ -758,6 +810,14 @@ modest_recpt_editor_grab_focus (ModestRecptEditor *recpt_editor) static void modest_recpt_editor_finalize (GObject *object) { + ModestRecptEditorPrivate *priv; + priv = MODEST_RECPT_EDITOR_GET_PRIVATE (object); + + if (priv->recipients) { + g_free (priv->recipients); + priv->recipients = NULL; + } + (*parent_class->finalize) (object); return;