X-Git-Url: http://git.maemo.org/git/?a=blobdiff_plain;f=src%2Fhildon2%2Fmodest-msg-edit-window.c;h=f85ac90e91468d63abffd18e945f651627ded922;hb=fa7034a06147384557e5386c1c3941e7d6caa7f4;hp=368a1d671a061ee176c2b5ae7aadb49ecde12327;hpb=890cdf6655a56ebb2a860c01bedbe15a59e7d9dd;p=modest diff --git a/src/hildon2/modest-msg-edit-window.c b/src/hildon2/modest-msg-edit-window.c index 368a1d6..f85ac90 100644 --- a/src/hildon2/modest-msg-edit-window.c +++ b/src/hildon2/modest-msg-edit-window.c @@ -189,11 +189,12 @@ static void update_signature (ModestMsgEditWindow *self, const gchar *new_account); static GtkWidget *_create_addressbook_box (GtkSizeGroup *title_size_group, GtkSizeGroup *value_size_group, const gchar *label, GtkWidget *control); +static void max_chars_banner_unref (ModestMsgEditWindow *self, GObject *old_ref); static void DEBUG_BUFFER (WPTextBuffer *buffer) { #ifdef DEBUG GtkTextIter iter; - g_message ("BEGIN BUFFER OF SIZE %d", gtk_text_buffer_get_char_count (GTK_TEXT_BUFFER (buffer))); + g_debug ("BEGIN BUFFER OF SIZE %d", gtk_text_buffer_get_char_count (GTK_TEXT_BUFFER (buffer))); gtk_text_buffer_get_start_iter (GTK_TEXT_BUFFER (buffer), &iter); while (!gtk_text_iter_is_end (&iter)) { @@ -220,11 +221,11 @@ static void DEBUG_BUFFER (WPTextBuffer *buffer) g_string_append (output, " "); } output = g_string_append (output, "]\n"); - g_message ("%s", output->str); + g_debug ("%s", output->str); g_string_free (output, TRUE); gtk_text_iter_forward_to_tag_toggle (&iter, NULL); } - g_message ("END BUFFER"); + g_debug ("END BUFFER"); #endif } @@ -322,6 +323,8 @@ struct _ModestMsgEditWindowPrivate { GtkWidget *app_menu; GtkWidget *cc_button; GtkWidget *bcc_button; + + GtkWidget *max_chars_banner; }; #define MODEST_MSG_EDIT_WINDOW_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \ @@ -445,6 +448,7 @@ modest_msg_edit_window_init (ModestMsgEditWindow *obj) priv->references = NULL; priv->in_reply_to = NULL; + priv->max_chars_banner = NULL; if (!is_wp_text_buffer_started) { is_wp_text_buffer_started = TRUE; @@ -1018,7 +1022,12 @@ static void modest_msg_edit_window_finalize (GObject *obj) { ModestMsgEditWindowPrivate *priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (obj); - + + if (priv->max_chars_banner) { + g_object_weak_unref (G_OBJECT (priv->max_chars_banner), (GWeakNotify) max_chars_banner_unref, obj); + priv->max_chars_banner = FALSE; + } + /* Sanity check: shouldn't be needed, the window mgr should call this function before */ modest_msg_edit_window_disconnect_signals (MODEST_WINDOW (obj)); @@ -2469,7 +2478,7 @@ on_attach_file_response (GtkDialog *dialog, modest_msg_edit_window_attach_file_one (window, uri, allowed_size); if (total_size > allowed_size) { - g_warning ("%s: total size: %u", + g_debug ("%s: total size: %u", __FUNCTION__, (unsigned int)total_size); break; } @@ -2579,7 +2588,7 @@ modest_msg_edit_window_attach_file_one (ModestMsgEditWindow *window, return 0; } } else - g_warning ("%s: could not get attachment size", __FUNCTION__); + g_debug ("%s: could not get attachment size", __FUNCTION__); stream = create_stream_for_uri (uri); @@ -2897,7 +2906,7 @@ modest_msg_edit_window_open_addressbook (ModestMsgEditWindow *window, priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window); if (editor == NULL) { - GtkWidget *view_focus; + GtkWidget *view_focus, *parent; view_focus = gtk_window_get_focus (GTK_WINDOW (window)); /* This code should be kept in sync with ModestRecptEditor. The @@ -2906,20 +2915,12 @@ modest_msg_edit_window_open_addressbook (ModestMsgEditWindow *window, hbox recpt editor inherits from, we'll need to go up in the hierarchy to know if the text view is part of the recpt editor or if it's a different text entry */ - - if (gtk_widget_get_parent (view_focus)) { - GtkWidget *first_parent; - - first_parent = gtk_widget_get_parent (view_focus); - if (gtk_widget_get_parent (first_parent) && - MODEST_IS_RECPT_EDITOR (gtk_widget_get_parent (first_parent))) { - editor = MODEST_RECPT_EDITOR (gtk_widget_get_parent (first_parent)); - } - } + parent = gtk_widget_get_parent (view_focus); + if (parent && MODEST_IS_RECPT_EDITOR (parent)) + editor = MODEST_RECPT_EDITOR (parent); if (editor == NULL) editor = MODEST_RECPT_EDITOR (priv->to_field); - } modest_address_book_select_addresses (editor, GTK_WINDOW (window)); @@ -3542,30 +3543,40 @@ body_insert_text (GtkTextBuffer *buffer, { GtkTextIter end_iter; gint offset; + glong utf8_len; + + ModestMsgEditWindowPrivate *priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window); gtk_text_buffer_get_end_iter (GTK_TEXT_BUFFER (buffer), &end_iter); offset = gtk_text_iter_get_offset (&end_iter); + utf8_len = g_utf8_strlen (text, len); - if (offset + len > MAX_BODY_LENGTH) { + if (offset + utf8_len > MAX_BODY_LENGTH) { g_signal_stop_emission_by_name (G_OBJECT (buffer), "insert-text"); if (offset < MAX_BODY_LENGTH) { gchar *result; + gchar *utf8_end; + + utf8_end = g_utf8_offset_to_pointer (text, MAX_BODY_LENGTH - offset); /* Prevent endless recursion */ - result = g_strndup (text, MAX_BODY_LENGTH - offset); + result = g_strndup (text, utf8_end - text); g_signal_handlers_block_by_func (G_OBJECT (buffer), G_CALLBACK (body_insert_text), window); g_signal_emit_by_name (G_OBJECT (buffer), "insert-text", location, - (gpointer) result, (gpointer) MAX_BODY_LENGTH - offset, + (gpointer) result, (gpointer) (utf8_end - text), (gpointer) window); g_signal_handlers_unblock_by_func (G_OBJECT (buffer), G_CALLBACK (body_insert_text), window); } } - if (offset + len > MAX_BODY_LENGTH) { - hildon_banner_show_information (GTK_WIDGET (window), NULL, - _CS("ckdg_ib_maximum_characters_reached")); + if (offset + utf8_len > MAX_BODY_LENGTH) { + if (priv->max_chars_banner == NULL) { + priv->max_chars_banner = hildon_banner_show_information (GTK_WIDGET (window), NULL, + _CS("ckdg_ib_maximum_characters_reached")); + g_object_weak_ref (G_OBJECT (priv->max_chars_banner), (GWeakNotify) max_chars_banner_unref, window); + } } } @@ -3690,7 +3701,7 @@ gtk_text_iter_forward_search_insensitive (const GtkTextIter *iter, result = TRUE; if (!gtk_text_iter_forward_search (iter, found_text, GTK_TEXT_SEARCH_VISIBLE_ONLY|GTK_TEXT_SEARCH_TEXT_ONLY, match_start, match_end, NULL)) { - g_warning ("Matched string with collate, but not matched in model"); + g_debug ("Matched string with collate, but not matched in model"); } g_free (found_text); } @@ -4278,7 +4289,7 @@ setup_menu (ModestMsgEditWindow *self) modest_hildon2_window_add_to_menu (MODEST_HILDON2_WINDOW (self), _("mcen_me_editor_attach_inlineimage"), NULL, APP_MENU_CALLBACK (modest_ui_actions_on_insert_image), MODEST_DIMMING_CALLBACK (modest_ui_dimming_rules_on_set_style)); - modest_hildon2_window_add_to_menu (MODEST_HILDON2_WINDOW (self), _("TODO: add attachment"), NULL, + modest_hildon2_window_add_to_menu (MODEST_HILDON2_WINDOW (self), _("mcen_me_editor_add_attachment"), NULL, APP_MENU_CALLBACK (modest_msg_edit_window_add_attachment_clicked), NULL); modest_hildon2_window_add_to_menu (MODEST_HILDON2_WINDOW (self), _("mcen_me_inbox_remove_attachments"), NULL, @@ -4310,7 +4321,7 @@ _create_addressbook_box (GtkSizeGroup *title_size_group, GtkSizeGroup *value_siz box = gtk_hbox_new (FALSE, 0); - align = gtk_alignment_new (0.0, 0.0, 1.0, 1.0); + align = gtk_alignment_new (0.0, 0.0, 1.0, 0.0); gtk_alignment_set_padding (GTK_ALIGNMENT (align), 0, 0, 0, MODEST_MARGIN_DEFAULT); abook_button = hildon_gtk_button_new (HILDON_SIZE_FINGER_HEIGHT); @@ -4332,3 +4343,14 @@ _create_addressbook_box (GtkSizeGroup *title_size_group, GtkSizeGroup *value_siz return box; } + +static void +max_chars_banner_unref (ModestMsgEditWindow *self, GObject *old_ref) +{ + ModestMsgEditWindowPrivate *priv = NULL; + + g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW(self)); + + priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (self); + priv->max_chars_banner = NULL; +}