X-Git-Url: http://git.maemo.org/git/?p=modest;a=blobdiff_plain;f=src%2Fwidgets%2Fmodest-recpt-editor.c;h=1f96cd28f1b2a639dcabcbf6abdf3dc4108171ea;hp=3e60a02b3853e67b211115457330d81329115f44;hb=40a8f5cbe03bd040fe3403dbfa6806df4fb6bc8a;hpb=f8a806f78f538409b502f58f09f969186e908258 diff --git a/src/widgets/modest-recpt-editor.c b/src/widgets/modest-recpt-editor.c index 3e60a02..1f96cd2 100644 --- a/src/widgets/modest-recpt-editor.c +++ b/src/widgets/modest-recpt-editor.c @@ -100,6 +100,8 @@ static GtkTextTag *prev_iter_has_recipient (GtkTextIter *iter); /* static GtkTextTag *next_iter_has_recipient (GtkTextIter *iter); */ static void select_tag_of_iter (GtkTextIter *iter, GtkTextTag *tag); static gboolean quote_opened (GtkTextIter *iter); +static gboolean is_valid_insert (const gchar *text, gint len); +static gchar *create_valid_text (const gchar *text, gint len); /** * modest_recpt_editor_new: @@ -122,14 +124,17 @@ modest_recpt_editor_set_recipients (ModestRecptEditor *recpt_editor, const gchar { ModestRecptEditorPrivate *priv; GtkTextBuffer *buffer = NULL; + gchar *valid_recipients = NULL; g_return_if_fail (MODEST_IS_RECPT_EDITOR (recpt_editor)); priv = MODEST_RECPT_EDITOR_GET_PRIVATE (recpt_editor); buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (priv->text_view)); + valid_recipients = create_valid_text (recipients, -1); g_signal_handlers_block_by_func (buffer, modest_recpt_editor_on_insert_text, recpt_editor); - gtk_text_buffer_set_text (buffer, recipients, -1); + gtk_text_buffer_set_text (buffer, valid_recipients, -1); + g_free (valid_recipients); if (GTK_WIDGET_REALIZED (recpt_editor)) gtk_widget_queue_resize (GTK_WIDGET (recpt_editor)); g_signal_handlers_unblock_by_func (buffer, modest_recpt_editor_on_insert_text, recpt_editor); @@ -330,7 +335,7 @@ modest_recpt_editor_instance_init (GTypeInstance *instance, gpointer g_class) priv->text_view = gtk_text_view_new (); priv->recipients = NULL; - priv->scrolled_window = modest_scroll_text_new (GTK_TEXT_VIEW (priv->text_view), 5); + priv->scrolled_window = modest_scroll_text_new (GTK_TEXT_VIEW (priv->text_view), 1024); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->scrolled_window), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (priv->scrolled_window), GTK_SHADOW_IN); @@ -444,16 +449,35 @@ static gboolean is_valid_insert (const gchar *text, gint len) { gunichar c; + gunichar next_c; gint i= 0; - const gchar *current; + gboolean quoted = FALSE; + const gchar *current, *next_current; if (text == NULL) return TRUE; current = text; - while (((len == -1)||(i < len)) && (*text != '\0')) { + while (((len == -1)||(i < len)) && (*current != '\0')) { c = g_utf8_get_char (current); - if (c == 0x2022 || c == 0xfffc) + next_current = g_utf8_next_char (current); + if (next_current && *next_current != '\0') + next_c = g_utf8_get_char (g_utf8_next_char (current)); + else + next_c = 0; + if (!quoted && ((c == g_utf8_get_char(",") || c == g_utf8_get_char (";")))) { + if ((next_c != 0) && (next_c != g_utf8_get_char ("\n"))) + return FALSE; + else { + current = g_utf8_next_char (next_current); + continue; + } + } + if (c == 0x2022 || c == 0xfffc || + c == g_utf8_get_char ("\n") || + c == g_utf8_get_char ("\t")) return FALSE; + if (c == g_utf8_get_char ("\"")) + quoted = !quoted; current = g_utf8_next_char (current); i = current - text; } @@ -464,9 +488,11 @@ static gchar * create_valid_text (const gchar *text, gint len) { gunichar c; + gunichar next_c; gint i= 0; GString *str; - const gchar *current; + gboolean quoted = FALSE; + const gchar *current, *next_current; if (text == NULL) return NULL; @@ -474,10 +500,23 @@ create_valid_text (const gchar *text, gint len) str = g_string_new (""); current = text; - while (((len == -1)||(i < len)) && (*text != '\0')) { + while (((len == -1)||(i < len)) && (*current != '\0')) { c = g_utf8_get_char (current); - if (c != 0x2022 && c != 0xfffc) + next_current = g_utf8_next_char (current); + if (next_current && *next_current != '\0') + next_c = g_utf8_get_char (g_utf8_next_char (current)); + else + next_c = 0; + if (c != 0x2022 && c != 0xfffc && + c != g_utf8_get_char ("\n") && + c != g_utf8_get_char ("\t")) str = g_string_append_unichar (str, c); + if (!quoted && ((c == g_utf8_get_char(",") || c == g_utf8_get_char (";")))) { + if ((next_c != 0) && (next_c != g_utf8_get_char ("\n"))) + str = g_string_append_c (str, '\n'); + } + if (c == g_utf8_get_char ("\"")) + quoted = !quoted; current = g_utf8_next_char (current); i = current - text; } @@ -500,6 +539,7 @@ modest_recpt_editor_on_insert_text (GtkTextBuffer *buffer, g_signal_stop_emission_by_name (G_OBJECT (buffer), "insert-text"); gtk_text_buffer_insert (buffer, location, new_text, -1); g_free (new_text); + return; } if (iter_has_recipient (location)) {