* src/widgets/modest-recpt-editor.c:
[modest] / src / widgets / modest-recpt-editor.c
index 375cefd..3e60a02 100644 (file)
@@ -324,12 +324,15 @@ modest_recpt_editor_instance_init (GTypeInstance *instance, gpointer g_class)
        gtk_button_set_focus_on_click (GTK_BUTTON (priv->abook_button), FALSE);
        GTK_WIDGET_UNSET_FLAGS (priv->abook_button, GTK_CAN_FOCUS);
        gtk_button_set_alignment (GTK_BUTTON (priv->abook_button), 1.0, 1.0);
-       abook_icon = gtk_image_new_from_icon_name ("qgn_list_gene_contacts", GTK_ICON_SIZE_BUTTON);
+       abook_icon = gtk_image_new_from_icon_name ("qgn_list_addressbook", GTK_ICON_SIZE_BUTTON);
        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);
+       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);
 /*     gtk_container_add (GTK_CONTAINER (priv->scrolled_window), priv->text_view); */
 
@@ -437,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,
@@ -448,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);
@@ -756,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;