X-Git-Url: http://git.maemo.org/git/?p=modest;a=blobdiff_plain;f=src%2Fhildon2%2Fmodest-msg-edit-window.c;h=14538699428b995630c00f5e8954f3d8f5809860;hp=6898f64bbbcaa4f7a9ce9ce1e48127400d8c8882;hb=882c7684fc9fe0b7e011b78da855a59f941a90f1;hpb=c96b53b53e89a1389910501fafbd609a1eb0a020 diff --git a/src/hildon2/modest-msg-edit-window.c b/src/hildon2/modest-msg-edit-window.c index 6898f64..1453869 100644 --- a/src/hildon2/modest-msg-edit-window.c +++ b/src/hildon2/modest-msg-edit-window.c @@ -92,6 +92,8 @@ #define IMAGE_MAX_WIDTH 560 #define DEFAULT_FONT_SCALE 1.5 #define ATTACHMENT_BUTTON_WIDTH 118 +#define MAX_FROM_VALUE 36 +#define MAX_BODY_LENGTH 4096 static gboolean is_wp_text_buffer_started = FALSE; @@ -110,6 +112,11 @@ static void text_buffer_apply_tag (GtkTextBuffer *buffer, GtkTextTag *tag, GtkTextIter *start, GtkTextIter *end, gpointer userdata); static void text_buffer_delete_images_by_id (GtkTextBuffer *buffer, const gchar * image_id); +static void body_insert_text (GtkTextBuffer *buffer, + GtkTextIter *location, + gchar *text, + gint len, + ModestMsgEditWindow *window); static void subject_field_changed (GtkEditable *editable, ModestMsgEditWindow *window); static void subject_field_insert_text (GtkEditable *editable, gchar *new_text, @@ -180,6 +187,8 @@ static void font_face_clicked (GtkToolButton *button, static void update_signature (ModestMsgEditWindow *self, const gchar *old_account, const gchar *new_account); +static GtkWidget *_create_addressbook_box (GtkSizeGroup *title_size_group, GtkSizeGroup *value_size_group, + const gchar *label, GtkWidget *control); static void DEBUG_BUFFER (WPTextBuffer *buffer) { #ifdef DEBUG @@ -258,7 +267,7 @@ struct _ModestMsgEditWindowPrivate { GtkWidget *attachments_view; GtkWidget *priority_icon; GtkWidget *subject_box; - GtkWidget *add_attachment_button; + GtkWidget *send_button; GtkWidget *cc_caption; GtkWidget *bcc_caption; @@ -712,6 +721,8 @@ connect_signals (ModestMsgEditWindow *obj) G_CALLBACK (text_buffer_can_redo), obj); g_signal_connect (G_OBJECT (priv->text_buffer), "changed", G_CALLBACK (body_changed), obj); + g_signal_connect (G_OBJECT (priv->text_buffer), "insert-text", + G_CALLBACK (body_insert_text), obj); g_signal_connect (G_OBJECT (priv->text_buffer), "modified-changed", G_CALLBACK (body_changed), obj); g_signal_connect (G_OBJECT (priv->text_buffer), "end-user-action", @@ -727,8 +738,6 @@ connect_signals (ModestMsgEditWindow *obj) g_signal_connect_swapped (G_OBJECT (priv->bcc_field), "open-addressbook", G_CALLBACK (modest_msg_edit_window_open_addressbook), obj); - g_signal_connect (G_OBJECT (priv->add_attachment_button), "clicked", - G_CALLBACK (modest_msg_edit_window_add_attachment_clicked), obj); g_signal_connect (G_OBJECT (priv->from_field), "value-changed", G_CALLBACK (from_field_changed), obj); @@ -778,7 +787,6 @@ init_window (ModestMsgEditWindow *obj) { GtkWidget *to_caption, *subject_caption; GtkWidget *main_vbox; - GtkWidget *add_attachment_align; ModestMsgEditWindowPrivate *priv; GtkActionGroup *action_group; ModestWindowPrivate *parent_priv; @@ -787,12 +795,13 @@ init_window (ModestMsgEditWindow *obj) GtkSizeGroup *title_size_group; GtkSizeGroup *value_size_group; - GtkWidget *attachment_icon; GtkWidget *window_box; GtkWidget *window_align; #if (GTK_MINOR_VERSION >= 10) GdkAtom deserialize_type; #endif + GtkWidget *from_send_hbox; + GtkWidget *send_icon; priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE(obj); parent_priv = MODEST_WINDOW_GET_PRIVATE (obj); @@ -858,12 +867,19 @@ init_window (ModestMsgEditWindow *obj) priv->from_field = modest_selector_picker_new (MODEST_EDITABLE_SIZE, HILDON_BUTTON_ARRANGEMENT_HORIZONTAL, NULL, g_str_equal); - modest_maemo_utils_set_hbutton_layout (title_size_group, value_size_group, + modest_selector_picker_set_value_max_chars (MODEST_SELECTOR_PICKER (priv->from_field), MAX_FROM_VALUE); + modest_maemo_utils_set_hbutton_layout (title_size_group, NULL, _("mail_va_from"), priv->from_field); + hildon_button_set_alignment (HILDON_BUTTON (priv->from_field), 0.0, 0.5, 1.0, 1.0); + hildon_button_set_title_alignment (HILDON_BUTTON (priv->from_field), 0.0, 0.5); + hildon_button_set_value_alignment (HILDON_BUTTON (priv->from_field), 1.0, 0.5); priv->to_field = modest_recpt_editor_new (); priv->cc_field = modest_recpt_editor_new (); priv->bcc_field = modest_recpt_editor_new (); + modest_recpt_editor_set_show_abook_button (MODEST_RECPT_EDITOR (priv->to_field), FALSE); + modest_recpt_editor_set_show_abook_button (MODEST_RECPT_EDITOR (priv->cc_field), FALSE); + modest_recpt_editor_set_show_abook_button (MODEST_RECPT_EDITOR (priv->bcc_field), FALSE); priv->subject_box = gtk_hbox_new (FALSE, MODEST_MARGIN_NONE); priv->priority_icon = gtk_image_new (); gtk_box_pack_start (GTK_BOX (priv->subject_box), priv->priority_icon, FALSE, FALSE, 0); @@ -873,34 +889,21 @@ init_window (ModestMsgEditWindow *obj) hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->subject_field), HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_AUTOCAP); gtk_box_pack_start (GTK_BOX (priv->subject_box), priv->subject_field, TRUE, TRUE, 0); - priv->add_attachment_button = hildon_button_new (MODEST_EDITABLE_SIZE, HILDON_BUTTON_ARRANGEMENT_VERTICAL); - gtk_widget_set_size_request (priv->add_attachment_button, ATTACHMENT_BUTTON_WIDTH, -1); - GTK_WIDGET_UNSET_FLAGS (GTK_WIDGET (priv->add_attachment_button), GTK_CAN_FOCUS); - gtk_button_set_focus_on_click (GTK_BUTTON (priv->add_attachment_button), FALSE); - attachment_icon = gtk_image_new_from_icon_name (MODEST_HEADER_ICON_ATTACH, HILDON_ICON_SIZE_FINGER); - hildon_button_set_image (HILDON_BUTTON (priv->add_attachment_button), attachment_icon); - add_attachment_align = gtk_alignment_new (0.0, 0.0, 1.0, 1.0); - gtk_alignment_set_padding (GTK_ALIGNMENT (add_attachment_align), 0, 0, MODEST_MARGIN_DEFAULT, 0); - gtk_container_add (GTK_CONTAINER (add_attachment_align), priv->add_attachment_button); - gtk_box_pack_start (GTK_BOX (priv->subject_box), add_attachment_align, FALSE, FALSE, 0); priv->attachments_view = modest_attachments_view_new (NULL); modest_attachments_view_set_style (MODEST_ATTACHMENTS_VIEW (priv->attachments_view), MODEST_ATTACHMENTS_VIEW_STYLE_NO_FOCUS); priv->header_box = gtk_vbox_new (FALSE, 0); - to_caption = modest_maemo_utils_create_captioned_with_size_type + to_caption = _create_addressbook_box (title_size_group, value_size_group, - _("mail_va_to"), FALSE, priv->to_field, - HILDON_SIZE_AUTO_HEIGHT | HILDON_SIZE_AUTO_WIDTH); - priv->cc_caption = modest_maemo_utils_create_captioned_with_size_type + _("mail_va_to"), priv->to_field); + priv->cc_caption = _create_addressbook_box (title_size_group, value_size_group, - _("mail_va_cc"), FALSE, priv->cc_field, - HILDON_SIZE_AUTO_HEIGHT | HILDON_SIZE_AUTO_WIDTH); - priv->bcc_caption = modest_maemo_utils_create_captioned_with_size_type + _("mail_va_cc"), priv->cc_field); + priv->bcc_caption = _create_addressbook_box (title_size_group, value_size_group, - _("mail_va_hotfix1"), FALSE, priv->bcc_field, - HILDON_SIZE_AUTO_HEIGHT | HILDON_SIZE_AUTO_WIDTH); + _("mail_va_hotfix1"), priv->bcc_field); subject_caption = modest_maemo_utils_create_captioned (title_size_group, value_size_group, _("mail_va_subject"), FALSE, priv->subject_box); priv->attachments_caption = modest_maemo_utils_create_captioned_with_size_type (title_size_group, value_size_group, @@ -909,13 +912,19 @@ init_window (ModestMsgEditWindow *obj) priv->attachments_view, HILDON_SIZE_AUTO_WIDTH | HILDON_SIZE_AUTO_HEIGHT); - /* modest_recpt_editor_set_field_size_group (MODEST_RECPT_EDITOR (priv->to_field), value_size_group); */ - /* modest_recpt_editor_set_field_size_group (MODEST_RECPT_EDITOR (priv->cc_field), value_size_group); */ - /* modest_recpt_editor_set_field_size_group (MODEST_RECPT_EDITOR (priv->bcc_field), value_size_group); */ + priv->send_button = hildon_gtk_button_new (HILDON_SIZE_FINGER_HEIGHT); + send_icon = gtk_image_new_from_icon_name (MODEST_TOOLBAR_ICON_MAIL_SEND, HILDON_ICON_SIZE_FINGER); + gtk_container_add (GTK_CONTAINER (priv->send_button), send_icon); + gtk_widget_set_size_request (GTK_WIDGET (priv->send_button), 118, -1); + g_object_unref (title_size_group); g_object_unref (value_size_group); - gtk_box_pack_start (GTK_BOX (priv->header_box), priv->from_field, FALSE, FALSE, 0); + from_send_hbox = gtk_hbox_new (FALSE, 0); + gtk_box_pack_start (GTK_BOX (from_send_hbox), priv->from_field, TRUE, TRUE, 0); + gtk_box_pack_start (GTK_BOX (from_send_hbox), priv->send_button, FALSE, FALSE, 0); + + gtk_box_pack_start (GTK_BOX (priv->header_box), from_send_hbox, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (priv->header_box), to_caption, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (priv->header_box), priv->cc_caption, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (priv->header_box), priv->bcc_caption, FALSE, FALSE, 0); @@ -947,6 +956,8 @@ init_window (ModestMsgEditWindow *obj) /* g_signal_connect (G_OBJECT (obj), "key_pressed", G_CALLBACK (on_key_pressed), NULL) */ priv->pannable = hildon_pannable_area_new (); + + g_object_set (G_OBJECT (priv->pannable), "hscrollbar-policy", GTK_POLICY_NEVER, NULL); main_vbox = gtk_vbox_new (FALSE, DEFAULT_MAIN_VBOX_SPACING); window_align = gtk_alignment_new (0.0, 0.0, 1.0, 1.0); @@ -1632,6 +1643,9 @@ modest_msg_edit_window_new (TnyMsg *msg, const gchar *account_name, const gchar modest_dimming_rules_group_add_widget_rule (toolbar_rules_group, priv->font_face_toolitem, G_CALLBACK (modest_ui_dimming_rules_on_set_style), MODEST_WINDOW (obj)); + modest_dimming_rules_group_add_widget_rule (toolbar_rules_group, priv->send_button, + G_CALLBACK (modest_ui_dimming_rules_on_send), + MODEST_WINDOW (obj)); /* Insert dimming rules group for this window */ modest_ui_dimming_manager_insert_rules_group (parent_priv->ui_dimming_manager, toolbar_rules_group); modest_ui_dimming_manager_insert_rules_group (parent_priv->ui_dimming_manager, clipboard_rules_group); @@ -1880,16 +1894,20 @@ modest_msg_edit_window_set_format (ModestMsgEditWindow *self, ModestMsgEditFormat format) { ModestMsgEditWindowPrivate *priv; + ModestWindowPrivate *parent_priv; g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (self)); priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (self); + parent_priv = MODEST_WINDOW_GET_PRIVATE (self); switch (format) { case MODEST_MSG_EDIT_FORMAT_HTML: wp_text_buffer_enable_rich_text (WP_TEXT_BUFFER (priv->text_buffer), TRUE); + if (parent_priv->toolbar) gtk_widget_show (parent_priv->toolbar); break; case MODEST_MSG_EDIT_FORMAT_TEXT: wp_text_buffer_enable_rich_text (WP_TEXT_BUFFER (priv->text_buffer), FALSE); + if (parent_priv->toolbar) gtk_widget_hide (parent_priv->toolbar); break; default: g_return_if_reached (); @@ -2775,6 +2793,7 @@ font_face_clicked (GtkToolButton *button, selector = hildon_touch_selector_new (); renderer = gtk_cell_renderer_text_new (); + g_object_set (G_OBJECT (renderer), "alignment", PANGO_ALIGN_CENTER, "xalign", 0.5, NULL); hildon_touch_selector_append_column (HILDON_TOUCH_SELECTOR (selector), priv->faces_model, renderer, "family", 0, "text", 0, NULL); hildon_touch_selector_set_active (HILDON_TOUCH_SELECTOR (selector), 0, priv->current_face_index); @@ -2916,17 +2935,27 @@ modest_msg_edit_window_show_toolbar (ModestWindow *self, gboolean show_toolbar) { ModestWindowPrivate *parent_priv; + ModestMsgEditWindowPrivate *priv; g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (self)); + priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (self); parent_priv = MODEST_WINDOW_GET_PRIVATE(self); /* We can not just use the code of modest_msg_edit_window_setup_toolbar because it has a mixture of both initialization and creation code. */ - if (show_toolbar) - gtk_widget_show (GTK_WIDGET (parent_priv->toolbar)); - else + if (show_toolbar) { + gint current_format; + current_format = wp_text_buffer_is_rich_text (WP_TEXT_BUFFER (priv->text_buffer)) + ? MODEST_FILE_FORMAT_FORMATTED_TEXT : MODEST_FILE_FORMAT_PLAIN_TEXT; + if (current_format == MODEST_FILE_FORMAT_PLAIN_TEXT) { + gtk_widget_hide (GTK_WIDGET (parent_priv->toolbar)); + } else { + gtk_widget_show (GTK_WIDGET (parent_priv->toolbar)); + } + } else { gtk_widget_hide (GTK_WIDGET (parent_priv->toolbar)); + } } void @@ -2991,6 +3020,12 @@ modest_msg_edit_window_set_file_format (ModestMsgEditWindow *window, current_format = wp_text_buffer_is_rich_text (WP_TEXT_BUFFER (priv->text_buffer)) ? MODEST_FILE_FORMAT_FORMATTED_TEXT : MODEST_FILE_FORMAT_PLAIN_TEXT; + gtk_widget_set_no_show_all (GTK_WIDGET (parent_priv->toolbar), TRUE); + + if (file_format == MODEST_FILE_FORMAT_PLAIN_TEXT) { + if (parent_priv->toolbar) gtk_widget_hide (parent_priv->toolbar); + } + if (current_format != file_format) { switch (file_format) { case MODEST_FILE_FORMAT_FORMATTED_TEXT: @@ -3006,6 +3041,7 @@ modest_msg_edit_window_set_file_format (ModestMsgEditWindow *window, gtk_widget_destroy (dialog); if (response == GTK_RESPONSE_OK) { wp_text_buffer_enable_rich_text (WP_TEXT_BUFFER (priv->text_buffer), FALSE); + if (parent_priv->toolbar) gtk_widget_hide (parent_priv->toolbar); } else { GtkToggleAction *action = GTK_TOGGLE_ACTION (gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/FormatMenu/FileFormatFormattedTextMenu")); modest_utils_toggle_action_set_active_block_notify (action, TRUE); @@ -3489,6 +3525,43 @@ update_window_title (ModestMsgEditWindow *window) } + +static void +body_insert_text (GtkTextBuffer *buffer, + GtkTextIter *location, + gchar *text, + gint len, + ModestMsgEditWindow *window) +{ + GtkTextIter end_iter; + gint offset; + + gtk_text_buffer_get_end_iter (GTK_TEXT_BUFFER (buffer), &end_iter); + + offset = gtk_text_iter_get_offset (&end_iter); + + if (offset + len > MAX_BODY_LENGTH) { + g_signal_stop_emission_by_name (G_OBJECT (buffer), "insert-text"); + if (offset < MAX_BODY_LENGTH) + { + gchar *result; + + /* Prevent endless recursion */ + result = g_strndup (text, MAX_BODY_LENGTH - offset); + 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) 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")); + } +} + static void subject_field_changed (GtkEditable *editable, ModestMsgEditWindow *window) @@ -3499,7 +3572,6 @@ subject_field_changed (GtkEditable *editable, modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (window)); modest_ui_actions_check_menu_dimming_rules (MODEST_WINDOW (window)); } - static void subject_field_insert_text (GtkEditable *editable, gchar *new_text, @@ -4179,6 +4251,9 @@ setup_menu (ModestMsgEditWindow *self) NULL); g_signal_connect (G_OBJECT (priv->cc_button), "toggled", G_CALLBACK (on_cc_button_toggled), (gpointer) self); + gtk_button_set_alignment (GTK_BUTTON (priv->cc_button), 0.5, 0.5); + gtk_button_set_alignment (GTK_BUTTON (priv->cc_button), 0.5, 0.5); + priv->bcc_button = hildon_check_button_new (0); gtk_button_set_label (GTK_BUTTON (priv->bcc_button), _("mcen_me_editor_showbcc")); hildon_check_button_set_active (HILDON_CHECK_BUTTON (priv->bcc_button), @@ -4187,10 +4262,15 @@ setup_menu (ModestMsgEditWindow *self) NULL); g_signal_connect (G_OBJECT (priv->bcc_button), "toggled", G_CALLBACK (on_bcc_button_toggled), (gpointer) self); + gtk_button_set_alignment (GTK_BUTTON (priv->bcc_button), 0.5, 0.5); + gtk_button_set_alignment (GTK_BUTTON (priv->bcc_button), 0.5, 0.5); 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, + 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, APP_MENU_CALLBACK (modest_ui_actions_on_remove_attachments), MODEST_DIMMING_CALLBACK (modest_ui_dimming_rules_on_editor_remove_attachment)); @@ -4202,3 +4282,42 @@ setup_menu (ModestMsgEditWindow *self) NULL); } +static void +emit_open_addressbook (GtkButton *button, + ModestRecptEditor *editor) +{ + g_signal_emit_by_name (G_OBJECT (editor), "open-addressbook"); +} + +static GtkWidget * +_create_addressbook_box (GtkSizeGroup *title_size_group, GtkSizeGroup *value_size_group, + const gchar *label, GtkWidget *control) +{ + GtkWidget *abook_button; + GtkWidget *align; + GtkWidget *box; + GtkWidget *label_widget; + + box = gtk_hbox_new (FALSE, 0); + + align = gtk_alignment_new (0.0, 0.0, 1.0, 1.0); + gtk_alignment_set_padding (GTK_ALIGNMENT (align), 0, 0, 0, MODEST_MARGIN_DEFAULT); + + abook_button = hildon_gtk_button_new (HILDON_SIZE_FINGER_HEIGHT); + label_widget = gtk_label_new (label); + gtk_misc_set_alignment (GTK_MISC (label_widget), 0.0, 0.5); + gtk_container_add (GTK_CONTAINER (abook_button), label_widget); + + gtk_container_add (GTK_CONTAINER (align), abook_button); + gtk_box_pack_start (GTK_BOX (box), align, FALSE, FALSE, 0); + gtk_box_pack_start (GTK_BOX (box), control, TRUE, TRUE, 0); + if (title_size_group) + gtk_size_group_add_widget (title_size_group, label_widget); + if (value_size_group) + gtk_size_group_add_widget (value_size_group, control); + + g_signal_connect (G_OBJECT (abook_button), "clicked", + G_CALLBACK (emit_open_addressbook), control); + + return box; +}