X-Git-Url: http://git.maemo.org/git/?p=modest;a=blobdiff_plain;f=src%2Fhildon2%2Fmodest-msg-edit-window.c;h=6898f64bbbcaa4f7a9ce9ce1e48127400d8c8882;hp=a9609c77bae56e3a98118be6bb0eedd65d08d2b0;hb=c96b53b53e89a1389910501fafbd609a1eb0a020;hpb=aa66a0a365ffa002ed34419c7988f116fcd35f0c diff --git a/src/hildon2/modest-msg-edit-window.c b/src/hildon2/modest-msg-edit-window.c index a9609c7..6898f64 100644 --- a/src/hildon2/modest-msg-edit-window.c +++ b/src/hildon2/modest-msg-edit-window.c @@ -36,6 +36,7 @@ #include #include #include +#include #include @@ -61,9 +62,11 @@ #include "modest-address-book.h" #include "modest-text-utils.h" #include -#include +#include #include #include +#include +#include #include "modest-msg-edit-window-ui-dimming.h" #include "modest-hildon-includes.h" @@ -115,10 +118,6 @@ static void subject_field_insert_text (GtkEditable *editable, ModestMsgEditWindow *window); static void modest_msg_edit_window_color_button_change (ModestMsgEditWindow *window, gpointer userdata); -static void modest_msg_edit_window_size_change (GtkCheckMenuItem *menu_item, - gpointer userdata); -static void modest_msg_edit_window_font_change (GtkCheckMenuItem *menu_item, - gpointer userdata); static void modest_msg_edit_window_setup_toolbar (ModestMsgEditWindow *window); static void modest_msg_edit_window_open_addressbook (ModestMsgEditWindow *window, @@ -174,6 +173,13 @@ static void setup_menu (ModestMsgEditWindow *self); static void from_field_changed (HildonPickerButton *button, ModestMsgEditWindow *self); +static void font_size_clicked (GtkToolButton *button, + ModestMsgEditWindow *window); +static void font_face_clicked (GtkToolButton *button, + ModestMsgEditWindow *window); +static void update_signature (ModestMsgEditWindow *self, + const gchar *old_account, + const gchar *new_account); static void DEBUG_BUFFER (WPTextBuffer *buffer) { #ifdef DEBUG @@ -233,13 +239,17 @@ enum { typedef struct _ModestMsgEditWindowPrivate ModestMsgEditWindowPrivate; struct _ModestMsgEditWindowPrivate { GtkWidget *msg_body; - GtkWidget *frame; GtkWidget *header_box; ModestPairList *from_field_protos; GtkWidget *from_field; gchar *last_from_account; gchar *original_account_name; + + gchar *references; + gchar *in_reply_to; + + gchar *original_mailbox; GtkWidget *to_field; GtkWidget *cc_field; @@ -247,6 +257,7 @@ struct _ModestMsgEditWindowPrivate { GtkWidget *subject_field; GtkWidget *attachments_view; GtkWidget *priority_icon; + GtkWidget *subject_box; GtkWidget *add_attachment_button; GtkWidget *cc_caption; @@ -261,8 +272,11 @@ struct _ModestMsgEditWindowPrivate { GtkWidget *font_color_button; GtkWidget *font_color_toolitem; GSList *font_items_group; + GtkTreeModel *faces_model; + gint current_face_index; GtkWidget *font_tool_button_label; - GSList *size_items_group; + GtkTreeModel *sizes_model; + gint current_size_index; GtkWidget *size_tool_button_label; GtkWidget *find_toolbar; @@ -347,19 +361,10 @@ static void restore_settings (ModestMsgEditWindow *self) { ModestConf *conf = NULL; - GtkAction *action; - ModestWindowPrivate *parent_priv = MODEST_WINDOW_GET_PRIVATE (self); conf = modest_runtime_get_conf (); /* Dim at start clipboard actions */ - action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/EditMenu/CutMenu"); - gtk_action_set_sensitive (action, FALSE); - action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/EditMenu/CopyMenu"); - gtk_action_set_sensitive (action, FALSE); - action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/AttachmentsMenu/RemoveAttachmentsMenu"); - gtk_action_set_sensitive (action, FALSE); - modest_widget_memory_restore (conf, G_OBJECT(self), MODEST_CONF_EDIT_WINDOW_KEY); } @@ -389,7 +394,6 @@ modest_msg_edit_window_init (ModestMsgEditWindow *obj) priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE(obj); priv->msg_body = NULL; - priv->frame = NULL; priv->from_field = NULL; priv->to_field = NULL; priv->cc_field = NULL; @@ -430,6 +434,9 @@ modest_msg_edit_window_init (ModestMsgEditWindow *obj) priv->font_dialog = NULL; priv->app_menu = NULL; + priv->references = NULL; + priv->in_reply_to = NULL; + if (!is_wp_text_buffer_started) { is_wp_text_buffer_started = TRUE; wp_text_buffer_library_init (); @@ -441,6 +448,45 @@ modest_msg_edit_window_init (ModestMsgEditWindow *obj) HILDON_WINDOW(obj)); } +static gchar * +multimailbox_get_default_mailbox (const gchar *account_name) +{ + gchar *transport_account; + gchar *result = NULL; + + transport_account = modest_account_mgr_get_server_account_name (modest_runtime_get_account_mgr (), + account_name, + TNY_ACCOUNT_TYPE_TRANSPORT); + if (transport_account) { + gchar *proto; + ModestProtocolRegistry *registry; + + registry = modest_runtime_get_protocol_registry (); + + proto = modest_account_mgr_get_string (modest_runtime_get_account_mgr (), transport_account, + MODEST_ACCOUNT_PROTO, TRUE); + if (proto != NULL) { + ModestProtocol *protocol = + modest_protocol_registry_get_protocol_by_name (registry, + MODEST_PROTOCOL_REGISTRY_TRANSPORT_PROTOCOLS, + proto); + if (MODEST_ACCOUNT_PROTOCOL (protocol)) { + ModestPairList *pair_list; + + pair_list = modest_account_protocol_get_from_list (MODEST_ACCOUNT_PROTOCOL (protocol), + account_name); + if (pair_list) { + ModestPair *pair = (ModestPair *) pair_list->data; + result = g_strdup ((const gchar *) pair->first); + modest_pair_list_free (pair_list); + } + } + + } + } + + return result; +} /** * @result: A ModestPairList, which must be freed with modest_pair_list_free(). @@ -457,17 +503,41 @@ get_transports (void) GSList *cursor = accounts; while (cursor) { gchar *account_name = cursor->data; - gchar *from_string = NULL; if (account_name) { - from_string = modest_account_mgr_get_from_string (account_mgr, - account_name); - } - - if (from_string && account_name) { - gchar *name = account_name; - ModestPair *pair = modest_pair_new ((gpointer) name, - (gpointer) from_string , TRUE); - transports = g_slist_prepend (transports, pair); + + gchar *transport_account; + gboolean multi_mailbox = FALSE; + ModestProtocol *protocol = NULL; + + if (modest_account_mgr_account_is_multimailbox (account_mgr, account_name, &protocol)) { + + transport_account = modest_account_mgr_get_server_account_name + (modest_runtime_get_account_mgr (), + account_name, + TNY_ACCOUNT_TYPE_TRANSPORT); + if (protocol && MODEST_IS_ACCOUNT_PROTOCOL (protocol)) { + ModestPairList *pair_list; + pair_list = modest_account_protocol_get_from_list (MODEST_ACCOUNT_PROTOCOL (protocol), + account_name); + if (pair_list) { + transports = g_slist_concat (transports, pair_list); + multi_mailbox = TRUE; + } + } + } + + if (!multi_mailbox) { + gchar *from_string = NULL; + + from_string = modest_account_mgr_get_from_string (account_mgr, + account_name, NULL); + if (from_string && account_name) { + gchar *name = account_name; + ModestPair *pair = modest_pair_new ((gpointer) name, + (gpointer) from_string , TRUE); + transports = g_slist_prepend (transports, pair); + } + } } cursor = cursor->next; @@ -490,6 +560,10 @@ scroll_drag_timeout (gpointer userdata) ModestMsgEditWindow *win = (ModestMsgEditWindow *) userdata; ModestMsgEditWindowPrivate *priv; + /* It could happen that the window was already closed */ + if (!GTK_WIDGET_VISIBLE (win)) + return FALSE; + priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE(win); correct_scroll_without_drag_check (win, TRUE); @@ -506,21 +580,28 @@ correct_scroll_without_drag_check_idle (gpointer userdata) ModestMsgEditWindowPrivate *priv; GtkTextIter iter; GdkRectangle rectangle; - gdouble new_value; - gint offset; + gint offset_min, offset_max; GtkTextMark *insert; + GtkAdjustment *vadj; + + /* It could happen that the window was already closed */ + if (!GTK_WIDGET_VISIBLE (w)) + return FALSE; priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE(w); - + insert = gtk_text_buffer_get_insert (priv->text_buffer); gtk_text_buffer_get_iter_at_mark (priv->text_buffer, &iter, insert); gtk_text_view_get_iter_location (GTK_TEXT_VIEW (priv->msg_body), &iter, &rectangle); - offset = priv->msg_body->allocation.y; + offset_min = priv->msg_body->allocation.y + rectangle.y; + offset_max = offset_min + rectangle.height; - new_value = (offset + rectangle.y); + vadj = hildon_pannable_area_get_vadjustment (HILDON_PANNABLE_AREA (priv->pannable)); + offset_min = MAX (offset_min - 48, 0); + offset_max = MIN (offset_max + 48, vadj->upper); - hildon_pannable_area_jump_to (HILDON_PANNABLE_AREA (priv->pannable), -1, new_value); + gtk_adjustment_clamp_page (vadj, (gdouble) offset_min, (gdouble) offset_max); priv->correct_scroll_idle = 0; return FALSE; @@ -540,8 +621,10 @@ correct_scroll_without_drag_check (ModestMsgEditWindow *w, gboolean only_if_focu return; } - priv->correct_scroll_idle = g_idle_add ((GSourceFunc) correct_scroll_without_drag_check_idle, - (gpointer) w); + priv->correct_scroll_idle = g_idle_add_full (G_PRIORITY_DEFAULT_IDLE, + (GSourceFunc) correct_scroll_without_drag_check_idle, + g_object_ref (w), + g_object_unref); } static void @@ -552,8 +635,11 @@ correct_scroll (ModestMsgEditWindow *w) priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE(w); if (gtk_grab_get_current () == priv->msg_body) { if (priv->scroll_drag_timeout_id == 0) { - priv->scroll_drag_timeout_id = g_timeout_add (500, (GSourceFunc) scroll_drag_timeout, - (gpointer) w); + priv->scroll_drag_timeout_id = g_timeout_add_full (G_PRIORITY_DEFAULT, + 500, + (GSourceFunc) scroll_drag_timeout, + g_object_ref (w), + g_object_unref); } return; } @@ -692,6 +778,7 @@ init_window (ModestMsgEditWindow *obj) { GtkWidget *to_caption, *subject_caption; GtkWidget *main_vbox; + GtkWidget *add_attachment_align; ModestMsgEditWindowPrivate *priv; GtkActionGroup *action_group; ModestWindowPrivate *parent_priv; @@ -700,9 +787,9 @@ init_window (ModestMsgEditWindow *obj) GtkSizeGroup *title_size_group; GtkSizeGroup *value_size_group; - GtkWidget *subject_box; GtkWidget *attachment_icon; GtkWidget *window_box; + GtkWidget *window_align; #if (GTK_MINOR_VERSION >= 10) GdkAtom deserialize_type; #endif @@ -777,23 +864,28 @@ init_window (ModestMsgEditWindow *obj) priv->to_field = modest_recpt_editor_new (); priv->cc_field = modest_recpt_editor_new (); priv->bcc_field = modest_recpt_editor_new (); - subject_box = gtk_hbox_new (FALSE, 0); + priv->subject_box = gtk_hbox_new (FALSE, MODEST_MARGIN_NONE); priv->priority_icon = gtk_image_new (); - gtk_box_pack_start (GTK_BOX (subject_box), priv->priority_icon, FALSE, FALSE, 0); + gtk_box_pack_start (GTK_BOX (priv->subject_box), priv->priority_icon, FALSE, FALSE, 0); priv->subject_field = hildon_entry_new (MODEST_EDITABLE_SIZE); gtk_entry_set_max_length (GTK_ENTRY (priv->subject_field) ,SUBJECT_MAX_LENGTH); g_object_set (G_OBJECT (priv->subject_field), "truncate-multiline", TRUE, NULL); 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 (subject_box), priv->subject_field, TRUE, TRUE, 0); + 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); - gtk_box_pack_start (GTK_BOX (subject_box), priv->add_attachment_button, FALSE, FALSE, 0); + 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); @@ -810,7 +902,7 @@ init_window (ModestMsgEditWindow *obj) _("mail_va_hotfix1"), FALSE, priv->bcc_field, HILDON_SIZE_AUTO_HEIGHT | HILDON_SIZE_AUTO_WIDTH); subject_caption = modest_maemo_utils_create_captioned (title_size_group, value_size_group, - _("mail_va_subject"), FALSE, subject_box); + _("mail_va_subject"), FALSE, priv->subject_box); priv->attachments_caption = modest_maemo_utils_create_captioned_with_size_type (title_size_group, value_size_group, _("mail_va_attachment"), FALSE, @@ -833,7 +925,7 @@ init_window (ModestMsgEditWindow *obj) init_wp_text_view_style (); - priv->msg_body = wp_text_view_new (); + priv->msg_body = modest_wp_text_view_new (); gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (priv->msg_body), GTK_WRAP_WORD_CHAR); @@ -857,14 +949,14 @@ init_window (ModestMsgEditWindow *obj) priv->pannable = hildon_pannable_area_new (); main_vbox = gtk_vbox_new (FALSE, DEFAULT_MAIN_VBOX_SPACING); + window_align = gtk_alignment_new (0.0, 0.0, 1.0, 1.0); + gtk_alignment_set_padding (GTK_ALIGNMENT (window_align), 0, 0, MODEST_MARGIN_DOUBLE, MODEST_MARGIN_DEFAULT); gtk_box_pack_start (GTK_BOX(main_vbox), priv->header_box, FALSE, FALSE, 0); - priv->frame = gtk_frame_new (NULL); - gtk_box_pack_start (GTK_BOX(main_vbox), priv->frame, TRUE, TRUE, 0); + gtk_box_pack_start (GTK_BOX(main_vbox), priv->msg_body, TRUE, TRUE, 0); + gtk_container_add (GTK_CONTAINER (window_align), main_vbox); - hildon_pannable_area_add_with_viewport (HILDON_PANNABLE_AREA (priv->pannable), main_vbox); - gtk_container_set_focus_vadjustment (GTK_CONTAINER (main_vbox), - hildon_pannable_area_get_vadjustment (HILDON_PANNABLE_AREA (priv->pannable))); + hildon_pannable_area_add_with_viewport (HILDON_PANNABLE_AREA (priv->pannable), window_align); gtk_widget_show_all (GTK_WIDGET(priv->pannable)); window_box = gtk_vbox_new (FALSE, 0); @@ -872,8 +964,6 @@ init_window (ModestMsgEditWindow *obj) gtk_box_pack_start (GTK_BOX (window_box), priv->pannable, TRUE, TRUE, 0); - gtk_container_add (GTK_CONTAINER (priv->frame), priv->msg_body); - /* Set window icon */ window_icon = modest_platform_get_icon (MODEST_APP_MSG_EDIT_ICON, MODEST_ICON_SIZE_BIG); if (window_icon) { @@ -955,10 +1045,14 @@ modest_msg_edit_window_finalize (GObject *obj) } if (priv->original_account_name) g_free (priv->original_account_name); + if (priv->original_mailbox) + g_free (priv->original_mailbox); g_free (priv->msg_uid); g_free (priv->last_search); - g_slist_free (priv->font_items_group); - g_slist_free (priv->size_items_group); + g_free (priv->references); + g_free (priv->in_reply_to); + g_object_unref (priv->faces_model); + g_object_unref (priv->sizes_model); g_object_unref (priv->attachments); g_object_unref (priv->images); @@ -968,13 +1062,38 @@ modest_msg_edit_window_finalize (GObject *obj) G_OBJECT_CLASS(parent_class)->finalize (obj); } +static void +pixbuf_size_prepared (GdkPixbufLoader *loader, + gint width, + gint height, + ModestMsgEditWindow *self) +{ + gint new_height, new_width; + gboolean set_size; + + new_height = height; + new_width = width; + set_size = FALSE; + + if (width > IMAGE_MAX_WIDTH) { + new_height = height * IMAGE_MAX_WIDTH / width; + new_width = IMAGE_MAX_WIDTH; + } + + gdk_pixbuf_loader_set_size (loader, new_width, new_height); +} + static GdkPixbuf * -pixbuf_from_stream (TnyStream *stream, const gchar *mime_type, guint64 *stream_size) +pixbuf_from_stream (TnyStream *stream, + const gchar *mime_type, + guint64 *stream_size, + ModestMsgEditWindow *self) { GdkPixbufLoader *loader; GdkPixbuf *pixbuf; guint64 size; - + GError *error = NULL; + size = 0; loader = gdk_pixbuf_loader_new_with_mime_type (mime_type, NULL); @@ -984,25 +1103,32 @@ pixbuf_from_stream (TnyStream *stream, const gchar *mime_type, guint64 *stream_s *stream_size = 0; return NULL; } + g_signal_connect (G_OBJECT (loader), "size-prepared", G_CALLBACK (pixbuf_size_prepared), self); + + hildon_gtk_window_set_progress_indicator (GTK_WINDOW (self), TRUE); tny_stream_reset (TNY_STREAM (stream)); while (!tny_stream_is_eos (TNY_STREAM (stream))) { - GError *error = NULL; unsigned char read_buffer[128]; gint readed; readed = tny_stream_read (TNY_STREAM (stream), (char *) read_buffer, 128); size += readed; if (!gdk_pixbuf_loader_write (loader, read_buffer, readed, &error)) { - if (error) - g_error_free (error); break; } + /* Allow some UI responsiveness */ + while (gtk_events_pending ()) + gtk_main_iteration (); } + hildon_gtk_window_set_progress_indicator (GTK_WINDOW (self), FALSE); + + gdk_pixbuf_loader_close (loader, &error); + if (error) + g_error_free (error); pixbuf = gdk_pixbuf_loader_get_pixbuf (loader); if (pixbuf) g_object_ref (pixbuf); - gdk_pixbuf_loader_close (loader, NULL); g_object_unref (loader); if (!pixbuf) @@ -1032,6 +1158,7 @@ replace_with_images (ModestMsgEditWindow *self, TnyList *attachments) priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (self); + g_object_ref (self); for (iter = tny_list_create_iterator (attachments); !tny_iterator_is_done (iter); tny_iterator_next (iter)) { @@ -1041,7 +1168,7 @@ replace_with_images (ModestMsgEditWindow *self, TnyList *attachments) if ((cid != NULL)&&(mime_type != NULL)) { guint64 stream_size; TnyStream *stream = tny_mime_part_get_decoded_stream (part); - GdkPixbuf *pixbuf = pixbuf_from_stream (stream, mime_type, &stream_size); + GdkPixbuf *pixbuf = pixbuf_from_stream (stream, mime_type, &stream_size, self); g_object_unref (stream); @@ -1056,6 +1183,7 @@ replace_with_images (ModestMsgEditWindow *self, TnyList *attachments) g_object_unref (part); } g_object_unref (iter); + g_object_unref (self); } static void @@ -1066,7 +1194,7 @@ get_related_images (ModestMsgEditWindow *self, TnyMsg *msg) ModestMsgEditWindowPrivate *priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (self); content_type = tny_mime_part_get_content_type (TNY_MIME_PART (msg)); - + if (content_type && !g_strcasecmp (content_type, "multipart/related")) { parent = g_object_ref (msg); } else if (content_type && !g_strcasecmp (content_type, "multipart/mixed")) { @@ -1161,6 +1289,8 @@ set_msg (ModestMsgEditWindow *self, TnyMsg *msg, gboolean preserve_is_rich) cc = tny_header_dup_cc (header); bcc = tny_header_dup_bcc (header); subject = tny_header_dup_subject (header); + + modest_tny_msg_get_references (TNY_MSG (msg), NULL, &(priv->references), &(priv->in_reply_to)); priority_flags = tny_header_get_priority (header); if (to) @@ -1281,45 +1411,6 @@ set_msg (ModestMsgEditWindow *self, TnyMsg *msg, gboolean preserve_is_rich) g_free (bcc); } -static void -menu_tool_button_clicked_popup (GtkMenuToolButton *item, - gpointer data) -{ - GList *item_children, *node; - GtkWidget *bin_child; - - bin_child = gtk_bin_get_child (GTK_BIN(item)); - - item_children = gtk_container_get_children (GTK_CONTAINER (bin_child)); - - for (node = item_children; node != NULL; node = g_list_next (node)) { - if (GTK_IS_TOGGLE_BUTTON (node->data)) { - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (node->data), TRUE); - } - } - g_list_free (item_children); -} - -static void -menu_tool_button_dont_expand (GtkMenuToolButton *item) -{ - GtkWidget *box; - GList *item_children, *node; - - box = gtk_bin_get_child (GTK_BIN (item)); - gtk_box_set_homogeneous (GTK_BOX (box), TRUE); - item_children = gtk_container_get_children (GTK_CONTAINER (box)); - - for (node = item_children; node != NULL; node = g_list_next (node)) { - gtk_box_set_child_packing (GTK_BOX (box), GTK_WIDGET (node->data), TRUE, TRUE, 0, GTK_PACK_START); - if (GTK_IS_TOGGLE_BUTTON (node->data)) - gtk_button_set_alignment (GTK_BUTTON (node->data), 0.0, 0.5); - else if (GTK_IS_BUTTON (node->data)) - gtk_button_set_alignment (GTK_BUTTON (node->data), 1.0, 0.5); - } - g_list_free (item_children); -} - static void modest_msg_edit_window_setup_toolbar (ModestMsgEditWindow *window) @@ -1334,9 +1425,9 @@ modest_msg_edit_window_setup_toolbar (ModestMsgEditWindow *window) gint font_index; GtkWidget *sizes_menu; GtkWidget *fonts_menu; - GSList *radio_group = NULL; - GSList *node = NULL; gchar *markup; + GtkWidget *arrow; + GtkWidget *hbox; /* Toolbar */ parent_priv->toolbar = gtk_ui_manager_get_widget (parent_priv->ui_manager, "/ToolBar"); @@ -1367,89 +1458,78 @@ modest_msg_edit_window_setup_toolbar (ModestMsgEditWindow *window) placeholder = gtk_ui_manager_get_widget (parent_priv->ui_manager, "/ToolBar/FontAttributes"); insert_index = gtk_toolbar_get_item_index(GTK_TOOLBAR (parent_priv->toolbar), GTK_TOOL_ITEM(placeholder)); /* font_size */ - tool_item = GTK_WIDGET (gtk_menu_tool_button_new (NULL, NULL)); + tool_item = GTK_WIDGET (gtk_tool_button_new (NULL, NULL)); priv->size_tool_button_label = gtk_label_new (NULL); snprintf(size_text, sizeof(size_text), "%d", wp_font_size[DEFAULT_FONT_SIZE]); markup = g_strconcat ("", - size_text,"", NULL); + size_text, "", NULL); gtk_label_set_markup (GTK_LABEL (priv->size_tool_button_label), markup); + gtk_misc_set_alignment (GTK_MISC (priv->size_tool_button_label), 1.0, 0.5); g_free (markup); hildon_helper_set_logical_font (priv->size_tool_button_label, "LargeSystemFont"); - gtk_tool_button_set_label_widget (GTK_TOOL_BUTTON (tool_item), priv->size_tool_button_label); + hbox = gtk_hbox_new (MODEST_MARGIN_DEFAULT, FALSE); + gtk_box_pack_start (GTK_BOX (hbox), priv->size_tool_button_label, TRUE, TRUE, 0); + arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE); + gtk_misc_set_alignment (GTK_MISC (arrow), 0.0, 0.5); + gtk_box_pack_start (GTK_BOX (hbox), arrow, TRUE, TRUE, 0); + gtk_widget_set_sensitive (arrow, FALSE); + gtk_tool_button_set_label_widget (GTK_TOOL_BUTTON (tool_item), hbox); sizes_menu = gtk_menu_new (); - priv->size_items_group = NULL; - radio_group = NULL; + priv->sizes_model = GTK_TREE_MODEL (gtk_list_store_new (1, G_TYPE_STRING)); for (size_index = 0; size_index < WP_FONT_SIZE_COUNT; size_index++) { - GtkWidget *size_menu_item; + GtkTreeIter iter; snprintf(size_text, sizeof(size_text), "%d", wp_font_size[size_index]); - size_menu_item = gtk_radio_menu_item_new_with_label (radio_group, size_text); - radio_group = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (size_menu_item)); - gtk_menu_shell_append (GTK_MENU_SHELL (sizes_menu), size_menu_item); - gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (size_menu_item), (wp_font_size[size_index] == 12)); - gtk_widget_show (size_menu_item); + gtk_list_store_append (GTK_LIST_STORE (priv->sizes_model), &iter); - priv->size_items_group = g_slist_prepend (priv->size_items_group, size_menu_item); - - } + gtk_list_store_set (GTK_LIST_STORE (priv->sizes_model), &iter, + 0, size_text, + -1); - for (node = radio_group; node != NULL; node = g_slist_next (node)) { - GtkWidget *item = (GtkWidget *) node->data; - g_signal_connect (G_OBJECT (item), "toggled", G_CALLBACK (modest_msg_edit_window_size_change), - window); + if (wp_font_size[size_index] == 12) + priv->current_size_index = size_index; + } - priv->size_items_group = g_slist_reverse (priv->size_items_group); - gtk_menu_tool_button_set_menu (GTK_MENU_TOOL_BUTTON (tool_item), sizes_menu); - g_signal_connect (G_OBJECT (tool_item), "clicked", G_CALLBACK (menu_tool_button_clicked_popup), NULL); + g_signal_connect (G_OBJECT (tool_item), "clicked", G_CALLBACK (font_size_clicked), window); gtk_toolbar_insert (GTK_TOOLBAR (parent_priv->toolbar), GTK_TOOL_ITEM (tool_item), insert_index); - gtk_tool_item_set_expand (GTK_TOOL_ITEM (tool_item), FALSE); - gtk_tool_item_set_homogeneous (GTK_TOOL_ITEM (tool_item), FALSE); - menu_tool_button_dont_expand (GTK_MENU_TOOL_BUTTON (tool_item)); + gtk_tool_item_set_expand (GTK_TOOL_ITEM (tool_item), TRUE); + gtk_tool_item_set_homogeneous (GTK_TOOL_ITEM (tool_item), TRUE); priv->font_size_toolitem = tool_item; /* font face */ - tool_item = GTK_WIDGET (gtk_menu_tool_button_new (NULL, NULL)); + tool_item = GTK_WIDGET (gtk_tool_button_new (NULL, NULL)); priv->font_tool_button_label = gtk_label_new (NULL); markup = g_strconcat ("Tt", NULL); gtk_label_set_markup (GTK_LABEL (priv->font_tool_button_label), markup); + gtk_misc_set_alignment (GTK_MISC (priv->font_tool_button_label), 1.0, 0.5); g_free(markup); hildon_helper_set_logical_font (priv->font_tool_button_label, "LargeSystemFont"); - gtk_tool_button_set_label_widget (GTK_TOOL_BUTTON (tool_item), priv->font_tool_button_label); + hbox = gtk_hbox_new (MODEST_MARGIN_DEFAULT, FALSE); + gtk_box_pack_start (GTK_BOX (hbox), priv->font_tool_button_label, TRUE, TRUE, 0); + arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE); + gtk_misc_set_alignment (GTK_MISC (arrow), 0.0, 0.5); + gtk_box_pack_start (GTK_BOX (hbox), arrow, TRUE, TRUE, 0); + gtk_widget_set_sensitive (arrow, FALSE); + gtk_tool_button_set_label_widget (GTK_TOOL_BUTTON (tool_item), hbox); fonts_menu = gtk_menu_new (); - priv->font_items_group = NULL; - radio_group = NULL; + priv->faces_model = GTK_TREE_MODEL (gtk_list_store_new (1, G_TYPE_STRING)); for (font_index = 0; font_index < wp_get_font_count (); font_index++) { - GtkWidget *font_menu_item; - GtkWidget *child_label; - - font_menu_item = gtk_radio_menu_item_new_with_label (radio_group, ""); - child_label = gtk_bin_get_child (GTK_BIN (font_menu_item)); - markup = g_strconcat ("", - wp_get_font_name (font_index), "", NULL); - gtk_label_set_markup (GTK_LABEL (child_label), markup); - g_free (markup); - - radio_group = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (font_menu_item)); - gtk_menu_shell_append (GTK_MENU_SHELL (fonts_menu), font_menu_item); - gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (font_menu_item), (font_index == DEFAULT_FONT)); - gtk_widget_show (font_menu_item); + GtkTreeIter iter; - priv->font_items_group = g_slist_prepend (priv->font_items_group, font_menu_item); - - } - for (node = radio_group; node != NULL; node = g_slist_next (node)) { - GtkWidget *item = (GtkWidget *) node->data; - g_signal_connect (G_OBJECT (item), "toggled", G_CALLBACK (modest_msg_edit_window_font_change), - window); + gtk_list_store_append (GTK_LIST_STORE (priv->faces_model), &iter); + + gtk_list_store_set (GTK_LIST_STORE (priv->faces_model), &iter, + 0, wp_get_font_name (font_index), + -1); + + if (font_index == DEFAULT_FONT) + priv->current_face_index = font_index; } - priv->font_items_group = g_slist_reverse (priv->font_items_group); - gtk_menu_tool_button_set_menu (GTK_MENU_TOOL_BUTTON (tool_item), fonts_menu); - g_signal_connect (G_OBJECT (tool_item), "clicked", G_CALLBACK (menu_tool_button_clicked_popup), NULL); + g_signal_connect (G_OBJECT (tool_item), "clicked", G_CALLBACK (font_face_clicked), window); gtk_toolbar_insert (GTK_TOOLBAR (parent_priv->toolbar), GTK_TOOL_ITEM (tool_item), insert_index); - gtk_tool_item_set_expand (GTK_TOOL_ITEM (tool_item), FALSE); - gtk_tool_item_set_homogeneous (GTK_TOOL_ITEM (tool_item), FALSE); - menu_tool_button_dont_expand (GTK_MENU_TOOL_BUTTON (tool_item)); + gtk_tool_item_set_expand (GTK_TOOL_ITEM (tool_item), TRUE); + gtk_tool_item_set_homogeneous (GTK_TOOL_ITEM (tool_item), TRUE); priv->font_face_toolitem = tool_item; /* Set expand and homogeneous for remaining items */ @@ -1477,7 +1557,7 @@ modest_msg_edit_window_setup_toolbar (ModestMsgEditWindow *window) ModestWindow* -modest_msg_edit_window_new (TnyMsg *msg, const gchar *account_name, gboolean preserve_is_rich) +modest_msg_edit_window_new (TnyMsg *msg, const gchar *account_name, const gchar *mailbox, gboolean preserve_is_rich) { GObject *obj; ModestWindowPrivate *parent_priv; @@ -1498,9 +1578,26 @@ modest_msg_edit_window_new (TnyMsg *msg, const gchar *account_name, gboolean pre /* Menubar. Update the state of some toggles */ priv->from_field_protos = get_transports (); + priv->original_mailbox = NULL; modest_selector_picker_set_pair_list (MODEST_SELECTOR_PICKER (priv->from_field), priv->from_field_protos); modest_selector_picker_set_active_id (MODEST_SELECTOR_PICKER (priv->from_field), (gpointer) account_name); priv->last_from_account = modest_selector_picker_get_active_id (MODEST_SELECTOR_PICKER (priv->from_field)); + if (mailbox && modest_pair_list_find_by_first_as_string (priv->from_field_protos, mailbox)) { + modest_selector_picker_set_active_id (MODEST_SELECTOR_PICKER (priv->from_field), (gpointer) mailbox); + priv->original_mailbox = g_strdup (mailbox); + } else if (modest_account_mgr_account_is_multimailbox (modest_runtime_get_account_mgr (), account_name, NULL)) { + /* We set the first mailbox as the active mailbox */ + priv->original_mailbox = multimailbox_get_default_mailbox (account_name); + if (priv->original_mailbox != NULL) + modest_selector_picker_set_active_id (MODEST_SELECTOR_PICKER (priv->from_field), + (gpointer) priv->original_mailbox); + else + modest_selector_picker_set_active_id (MODEST_SELECTOR_PICKER (priv->from_field), + (gpointer) account_name); + } else { + modest_selector_picker_set_active_id (MODEST_SELECTOR_PICKER (priv->from_field), (gpointer) account_name); + } + priv->last_from_account = modest_selector_picker_get_active_id (MODEST_SELECTOR_PICKER (priv->from_field)); hildon_button_set_title (HILDON_BUTTON (priv->from_field), _("mail_va_from")); hildon_button_set_value (HILDON_BUTTON (priv->from_field), @@ -1515,6 +1612,7 @@ modest_msg_edit_window_new (TnyMsg *msg, const gchar *account_name, gboolean pre restore_settings (MODEST_MSG_EDIT_WINDOW(obj)); modest_window_set_active_account (MODEST_WINDOW(obj), account_name); + modest_window_set_active_mailbox (MODEST_WINDOW(obj), priv->original_mailbox); priv->original_account_name = (account_name) ? g_strdup (account_name) : NULL; @@ -1544,6 +1642,8 @@ modest_msg_edit_window_new (TnyMsg *msg, const gchar *account_name, gboolean pre /* Checks the dimming rules */ g_object_unref (toolbar_rules_group); g_object_unref (clipboard_rules_group); + gtk_widget_hide (priv->priority_icon); + gtk_widget_queue_resize (priv->subject_box); set_msg (MODEST_MSG_EDIT_WINDOW (obj), msg, preserve_is_rich); text_buffer_refresh_attributes (WP_TEXT_BUFFER (priv->text_buffer), MODEST_MSG_EDIT_WINDOW (obj)); @@ -1607,24 +1707,26 @@ modest_msg_edit_window_get_msg_data (ModestMsgEditWindow *edit_window) const gchar *account_name; ModestMsgEditWindowPrivate *priv; TnyIterator *att_iter; + const gchar *picker_active_id; g_return_val_if_fail (MODEST_IS_MSG_EDIT_WINDOW (edit_window), NULL); priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (edit_window); - - account_name = modest_selector_picker_get_active_id (MODEST_SELECTOR_PICKER (priv->from_field)); - g_return_val_if_fail (account_name, NULL); + picker_active_id = modest_selector_picker_get_active_id (MODEST_SELECTOR_PICKER (priv->from_field)); + g_return_val_if_fail (picker_active_id, NULL); + account_name = modest_utils_get_account_name_from_recipient (picker_active_id, NULL); /* don't free these (except from) */ data = g_slice_new0 (MsgData); - data->from = modest_account_mgr_get_from_string (modest_runtime_get_account_mgr(), - account_name); + data->from = g_strdup ((gchar *) modest_selector_picker_get_active_display_name (MODEST_SELECTOR_PICKER (priv->from_field))); data->account_name = g_strdup (account_name); data->to = g_strdup (modest_recpt_editor_get_recipients (MODEST_RECPT_EDITOR (priv->to_field))); data->cc = g_strdup (modest_recpt_editor_get_recipients (MODEST_RECPT_EDITOR (priv->cc_field))); data->bcc = g_strdup (modest_recpt_editor_get_recipients (MODEST_RECPT_EDITOR (priv->bcc_field))); data->subject = g_strdup (gtk_entry_get_text (GTK_ENTRY (priv->subject_field))); + data->references = g_strdup (priv->references); + data->in_reply_to = g_strdup (priv->in_reply_to); if (priv->draft_msg) { data->draft_msg = g_object_ref (priv->draft_msg); } else if (priv->outbox_msg) { @@ -1724,6 +1826,8 @@ modest_msg_edit_window_free_msg_data (ModestMsgEditWindow *edit_window, g_free (data->plain_body); g_free (data->html_body); g_free (data->account_name); + g_free (data->references); + g_free (data->in_reply_to); if (data->draft_msg != NULL) { g_object_unref (data->draft_msg); @@ -1797,9 +1901,11 @@ modest_msg_edit_window_get_format_state (ModestMsgEditWindow *self) { ModestMsgEditFormatState *format_state = NULL; ModestMsgEditWindowPrivate *priv; - WPTextBufferFormat *buffer_format = g_new0 (WPTextBufferFormat, 1); + WPTextBufferFormat *buffer_format; g_return_val_if_fail (MODEST_IS_MSG_EDIT_WINDOW (self), NULL); + + buffer_format = g_new0 (WPTextBufferFormat, 1); priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (self); wp_text_buffer_get_attributes (WP_TEXT_BUFFER (priv->text_buffer), buffer_format, TRUE); @@ -1823,11 +1929,15 @@ modest_msg_edit_window_set_format_state (ModestMsgEditWindow *self, const ModestMsgEditFormatState *format_state) { ModestMsgEditWindowPrivate *priv; - WPTextBufferFormat *buffer_format = g_new0 (WPTextBufferFormat, 1); - WPTextBufferFormat *current_format = g_new0 (WPTextBufferFormat, 1); + WPTextBufferFormat *buffer_format; + WPTextBufferFormat *current_format; + g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (self)); g_return_if_fail (format_state != NULL); + buffer_format = g_new0 (WPTextBufferFormat, 1); + current_format = g_new0 (WPTextBufferFormat, 1); + priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (self); gtk_widget_grab_focus (priv->msg_body); buffer_format->bold = (format_state->bold != FALSE); @@ -1912,8 +2022,6 @@ text_buffer_refresh_attributes (WPTextBuffer *buffer, ModestMsgEditWindow *windo GtkAction *action; ModestWindowPrivate *parent_priv; ModestMsgEditWindowPrivate *priv; - GtkWidget *new_size_menuitem; - GtkWidget *new_font_menuitem; parent_priv = MODEST_WINDOW_GET_PRIVATE (window); priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window); @@ -1966,42 +2074,45 @@ text_buffer_refresh_attributes (WPTextBuffer *buffer, ModestMsgEditWindow *windo G_CALLBACK (modest_msg_edit_window_color_button_change), window); - new_size_menuitem = GTK_WIDGET ((g_slist_nth (priv->size_items_group, - buffer_format->font_size))->data); - if (!gtk_check_menu_item_get_active (GTK_CHECK_MENU_ITEM (new_size_menuitem))) { - GtkWidget *label; - gchar *markup; + if (priv->current_size_index != buffer_format->font_size) { + GtkTreeIter iter; + GtkTreePath *path; - label = gtk_bin_get_child (GTK_BIN (new_size_menuitem)); - markup = g_strconcat ("", gtk_label_get_text (GTK_LABEL (label)), "", NULL); - gtk_label_set_markup (GTK_LABEL (priv->size_tool_button_label), markup); - g_free (markup); - g_signal_handlers_block_by_func (G_OBJECT (new_size_menuitem), - G_CALLBACK (modest_msg_edit_window_size_change), - window); - gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (new_size_menuitem), TRUE); - g_signal_handlers_unblock_by_func (G_OBJECT (new_size_menuitem), - G_CALLBACK (modest_msg_edit_window_size_change), - window); - } - - new_font_menuitem = GTK_WIDGET ((g_slist_nth (priv->font_items_group, - buffer_format->font))->data); - if (!gtk_check_menu_item_get_active (GTK_CHECK_MENU_ITEM (new_font_menuitem))) { - GtkWidget *label; - gchar *markup; + path = gtk_tree_path_new_from_indices (buffer_format->font_size, -1); + if (gtk_tree_model_get_iter (priv->sizes_model, &iter, path)) { + gchar *size_text; + gchar *markup; + + priv->current_size_index = buffer_format->font_size; + + gtk_tree_model_get (priv->sizes_model, &iter, 0, &size_text, -1); + markup = g_strconcat ("", + size_text, "", NULL); + + gtk_label_set_markup (GTK_LABEL (priv->size_tool_button_label), markup); + g_free (markup); + g_free (size_text); + } + gtk_tree_path_free (path); + } + + if (priv->current_face_index != buffer_format->font) { + GtkTreeIter iter; + GtkTreePath *path; + + path = gtk_tree_path_new_from_indices (buffer_format->font, -1); + if (gtk_tree_model_get_iter (priv->faces_model, &iter, path)) { + gchar *face_name; + gchar *markup; + + priv->current_face_index = buffer_format->font; + gtk_tree_model_get (priv->faces_model, &iter, 0, &face_name, -1); + markup = g_strconcat ("Tt", NULL); + gtk_label_set_markup (GTK_LABEL (priv->font_tool_button_label), markup); + g_free (face_name); + g_free (markup); + } - label = gtk_bin_get_child (GTK_BIN (new_font_menuitem)); - markup = g_strconcat ("Tt", NULL); - gtk_label_set_markup (GTK_LABEL (priv->font_tool_button_label), markup); - g_free (markup); - g_signal_handlers_block_by_func (G_OBJECT (new_font_menuitem), - G_CALLBACK (modest_msg_edit_window_font_change), - window); - gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (new_font_menuitem), TRUE); - g_signal_handlers_unblock_by_func (G_OBJECT (new_font_menuitem), - G_CALLBACK (modest_msg_edit_window_font_change), - window); } g_free (buffer_format); @@ -2155,9 +2266,9 @@ modest_msg_edit_window_insert_image (ModestMsgEditWindow *window) gint response = 0; GSList *uris = NULL; GSList *uri_node = NULL; - + priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window); - + dialog = hildon_file_chooser_dialog_new (GTK_WINDOW (window), GTK_FILE_CHOOSER_ACTION_OPEN); gtk_window_set_title (GTK_WINDOW (dialog), _("mcen_ia_select_inline_image_title")); gtk_file_chooser_set_select_multiple (GTK_FILE_CHOOSER (dialog), TRUE); @@ -2170,13 +2281,32 @@ modest_msg_edit_window_insert_image (ModestMsgEditWindow *window) response = gtk_dialog_run (GTK_DIALOG (dialog)); switch (response) { case GTK_RESPONSE_OK: + { + gchar *current_folder; uris = gtk_file_chooser_get_uris (GTK_FILE_CHOOSER (dialog)); - break; + current_folder = gtk_file_chooser_get_current_folder_uri (GTK_FILE_CHOOSER (dialog)); + if (current_folder && current_folder != '\0') { + GError *err = NULL; + modest_conf_set_string (modest_runtime_get_conf (), MODEST_CONF_LATEST_INSERT_IMAGE_PATH, + current_folder, &err); + if (err != NULL) { + g_debug ("Error storing latest used folder: %s", err->message); + g_error_free (err); + } + } + g_free (current_folder); + } + break; default: break; } gtk_widget_destroy (dialog); + g_object_ref (window); + /* The operation could take some time so allow the dialog to be closed */ + while (gtk_events_pending ()) + gtk_main_iteration (); + for (uri_node = uris; uri_node != NULL; uri_node = g_slist_next (uri_node)) { const gchar *uri; GnomeVFSHandle *handle = NULL; @@ -2219,7 +2349,7 @@ modest_msg_edit_window_insert_image (ModestMsgEditWindow *window) modest_platform_information_banner (NULL, NULL, _FM("sfil_ib_opening_not_allowed")); - + g_free (filename); g_object_unref (mime_part); gnome_vfs_file_info_unref (info); continue; @@ -2236,27 +2366,31 @@ modest_msg_edit_window_insert_image (ModestMsgEditWindow *window) tny_mime_part_set_filename (mime_part, basename); g_free (basename); - pixbuf = pixbuf_from_stream (stream, mime_type, &stream_size); + pixbuf = pixbuf_from_stream (stream, mime_type, &stream_size, window); if (pixbuf != NULL) { priv->images_size += stream_size; priv->images_count ++; insert_mark = gtk_text_buffer_get_insert (GTK_TEXT_BUFFER (priv->text_buffer)); gtk_text_buffer_get_iter_at_mark (GTK_TEXT_BUFFER (priv->text_buffer), &position, insert_mark); - wp_text_buffer_insert_image (WP_TEXT_BUFFER (priv->text_buffer), &position, g_strdup (tny_mime_part_get_content_id (mime_part)), pixbuf); + wp_text_buffer_insert_image (WP_TEXT_BUFFER (priv->text_buffer), &position, + tny_mime_part_get_content_id (mime_part), pixbuf); g_object_unref (pixbuf); - } - tny_list_prepend (priv->images, (GObject *) mime_part); - gtk_text_buffer_set_modified (priv->text_buffer, TRUE); + tny_list_prepend (priv->images, (GObject *) mime_part); + gtk_text_buffer_set_modified (priv->text_buffer, TRUE); + } else { + modest_platform_information_banner (NULL, NULL, + _("mail_ib_file_operation_failed")); + } + g_free (filename); g_object_unref (mime_part); gnome_vfs_file_info_unref (info); } } - - + g_object_unref (window); } static void @@ -2274,8 +2408,23 @@ on_attach_file_response (GtkDialog *dialog, switch (arg1) { case GTK_RESPONSE_OK: + { + gchar *current_folder; + uris = gtk_file_chooser_get_uris (GTK_FILE_CHOOSER (dialog)); - break; + current_folder = gtk_file_chooser_get_current_folder_uri (GTK_FILE_CHOOSER (dialog)); + if (current_folder && current_folder != '\0') { + GError *err = NULL; + modest_conf_set_string (modest_runtime_get_conf (), MODEST_CONF_LATEST_ATTACH_FILE_PATH, + current_folder, &err); + if (err != NULL) { + g_debug ("Error storing latest used folder: %s", err->message); + g_error_free (err); + } + } + g_free (current_folder); + } + break; default: break; } @@ -2314,6 +2463,7 @@ modest_msg_edit_window_offer_attach_file (ModestMsgEditWindow *window) { GtkWidget *dialog = NULL; ModestMsgEditWindowPrivate *priv; + gchar *conf_folder; g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW(window)); @@ -2325,6 +2475,18 @@ modest_msg_edit_window_offer_attach_file (ModestMsgEditWindow *window) dialog = hildon_file_chooser_dialog_new (GTK_WINDOW (window), GTK_FILE_CHOOSER_ACTION_OPEN); gtk_window_set_title (GTK_WINDOW (dialog), _("mcen_ti_select_attachment_title")); + conf_folder = modest_conf_get_string (modest_runtime_get_conf (), MODEST_CONF_LATEST_ATTACH_FILE_PATH, NULL); + if (conf_folder && conf_folder[0] != '\0') { + gtk_file_chooser_set_current_folder_uri (GTK_FILE_CHOOSER (dialog), conf_folder); + } else { + gchar *docs_folder; + /* Set the default folder to images folder */ + docs_folder = g_build_filename (g_getenv (MODEST_MAEMO_UTILS_MYDOCS_ENV), + ".documents", NULL); + gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), docs_folder); + g_free (docs_folder); + } + g_free (conf_folder); gtk_file_chooser_set_select_multiple (GTK_FILE_CHOOSER (dialog), TRUE); modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), GTK_WINDOW (dialog), GTK_WINDOW (window)); @@ -2390,6 +2552,7 @@ modest_msg_edit_window_attach_file_one (ModestMsgEditWindow *window, if (size > allowed_size) { modest_platform_information_banner (NULL, NULL, _FM("sfil_ib_opening_not_allowed")); + g_free (filename); return 0; } } else @@ -2402,6 +2565,7 @@ modest_msg_edit_window_attach_file_one (ModestMsgEditWindow *window, modest_platform_information_banner (NULL, NULL, _FM("sfil_ib_opening_not_allowed")); g_object_unref (mime_part); + g_free (filename); gnome_vfs_file_info_unref (info); return 0; } @@ -2445,7 +2609,7 @@ modest_msg_edit_window_remove_attachments (ModestMsgEditWindow *window, if (att_list == NULL) { att_list = modest_attachments_view_get_attachments (MODEST_ATTACHMENTS_VIEW (priv->attachments_view)); - if (!modest_maemo_utils_select_attachments (GTK_WINDOW (window), att_list)) { + if (!modest_maemo_utils_select_attachments (GTK_WINDOW (window), att_list, TRUE)) { g_object_unref (att_list); return; } @@ -2547,74 +2711,109 @@ modest_msg_edit_window_color_button_change (ModestMsgEditWindow *window, } static void -modest_msg_edit_window_size_change (GtkCheckMenuItem *menu_item, - gpointer userdata) +font_size_clicked (GtkToolButton *button, + ModestMsgEditWindow *window) { ModestMsgEditWindowPrivate *priv; - gint new_size_index; - ModestMsgEditWindow *window; - GtkWidget *label; + GtkWidget *selector, *dialog; - window = MODEST_MSG_EDIT_WINDOW (userdata); priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window); - gtk_widget_grab_focus (GTK_WIDGET (priv->msg_body)); - if (gtk_check_menu_item_get_active (menu_item)) { + selector = hildon_touch_selector_new (); + hildon_touch_selector_append_text_column (HILDON_TOUCH_SELECTOR (selector), priv->sizes_model, TRUE); + hildon_touch_selector_set_active (HILDON_TOUCH_SELECTOR (selector), 0, priv->current_size_index); + + dialog = hildon_picker_dialog_new (GTK_WINDOW (window)); + hildon_picker_dialog_set_selector (HILDON_PICKER_DIALOG (dialog), HILDON_TOUCH_SELECTOR (selector)); + gtk_window_set_title (GTK_WINDOW (dialog), _("mcen_ti_font_size")); + + if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK) { + gint new_index; + gchar *size_text; gchar *markup; WPTextBufferFormat format; + new_index = hildon_touch_selector_get_active (HILDON_TOUCH_SELECTOR (selector), 0); + memset (&format, 0, sizeof (format)); wp_text_buffer_get_attributes (WP_TEXT_BUFFER (priv->text_buffer), &format, FALSE); - label = gtk_bin_get_child (GTK_BIN (menu_item)); - - new_size_index = atoi (gtk_label_get_text (GTK_LABEL (label))); format.cs.font_size = TRUE; format.cs.text_position = TRUE; format.cs.font = TRUE; - format.font_size = wp_get_font_size_index (new_size_index, DEFAULT_FONT_SIZE); + format.font_size = new_index; /* wp_text_buffer_set_format (WP_TEXT_BUFFER (priv->text_buffer), &format); */ if (!wp_text_buffer_set_attribute (WP_TEXT_BUFFER (priv->text_buffer), WPT_FONT_SIZE, - GINT_TO_POINTER (wp_get_font_size_index (new_size_index, 12)))) + GINT_TO_POINTER (new_index))) wp_text_view_reset_and_show_im (WP_TEXT_VIEW (priv->msg_body)); text_buffer_refresh_attributes (WP_TEXT_BUFFER (priv->text_buffer), MODEST_MSG_EDIT_WINDOW (window)); - markup = g_strconcat ("", gtk_label_get_text (GTK_LABEL (label)), "", NULL); + size_text = hildon_touch_selector_get_current_text (HILDON_TOUCH_SELECTOR (selector)); + markup = g_strconcat ("", + size_text, "", NULL); + g_free (size_text); gtk_label_set_markup (GTK_LABEL (priv->size_tool_button_label), markup); g_free (markup); + } + gtk_widget_destroy (dialog); + + gtk_widget_grab_focus (GTK_WIDGET (priv->msg_body)); + } static void -modest_msg_edit_window_font_change (GtkCheckMenuItem *menu_item, - gpointer userdata) +font_face_clicked (GtkToolButton *button, + ModestMsgEditWindow *window) { ModestMsgEditWindowPrivate *priv; - gint new_font_index; - ModestMsgEditWindow *window; - GtkWidget *label; + GtkWidget *selector, *dialog; + GtkCellRenderer *renderer; - window = MODEST_MSG_EDIT_WINDOW (userdata); priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window); - gtk_widget_grab_focus (GTK_WIDGET (priv->msg_body)); - if (gtk_check_menu_item_get_active (menu_item)) { - gchar *markup; + selector = hildon_touch_selector_new (); + renderer = gtk_cell_renderer_text_new (); + 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); - label = gtk_bin_get_child (GTK_BIN (menu_item)); - - new_font_index = wp_get_font_index (gtk_label_get_text (GTK_LABEL (label)), DEFAULT_FONT); + dialog = hildon_picker_dialog_new (GTK_WINDOW (window)); + hildon_picker_dialog_set_selector (HILDON_PICKER_DIALOG (dialog), HILDON_TOUCH_SELECTOR (selector)); + gtk_window_set_title (GTK_WINDOW (dialog), _("mcen_ti_font_face")); + + if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK) { + gint new_font_index; + GtkTreePath *path; + GtkTreeIter iter; + + new_font_index = hildon_touch_selector_get_active (HILDON_TOUCH_SELECTOR (selector), 0); + path = gtk_tree_path_new_from_indices (new_font_index, -1); + if (gtk_tree_model_get_iter (priv->faces_model, &iter, path)) { + gchar *face_name; + gchar *markup; + + gtk_tree_model_get (priv->faces_model, &iter, 0, &face_name, -1); + + if (!wp_text_buffer_set_attribute (WP_TEXT_BUFFER (priv->text_buffer), WPT_FONT, + GINT_TO_POINTER(new_font_index))) + wp_text_view_reset_and_show_im (WP_TEXT_VIEW (priv->msg_body)); + + markup = g_strconcat ("Tt", NULL); + gtk_label_set_markup (GTK_LABEL (priv->font_tool_button_label), markup); + + text_buffer_refresh_attributes (WP_TEXT_BUFFER (priv->text_buffer), MODEST_MSG_EDIT_WINDOW (window)); + g_free (face_name); + g_free (markup); + } + gtk_tree_path_free (path); - if (!wp_text_buffer_set_attribute (WP_TEXT_BUFFER (priv->text_buffer), WPT_FONT, - GINT_TO_POINTER(new_font_index))) - wp_text_view_reset_and_show_im (WP_TEXT_VIEW (priv->msg_body)); - - text_buffer_refresh_attributes (WP_TEXT_BUFFER (priv->text_buffer), MODEST_MSG_EDIT_WINDOW (window)); - markup = g_strconcat ("Tt", NULL); - gtk_label_set_markup (GTK_LABEL (priv->font_tool_button_label), markup); - g_free (markup); } + gtk_widget_destroy (dialog); + + gtk_widget_grab_focus (GTK_WIDGET (priv->msg_body)); + } void @@ -2751,7 +2950,7 @@ modest_msg_edit_window_set_priority_flags (ModestMsgEditWindow *window, case TNY_HEADER_FLAG_HIGH_PRIORITY: gtk_image_set_from_icon_name (GTK_IMAGE (priv->priority_icon), MODEST_HEADER_ICON_HIGH, - HILDON_ICON_SIZE_XSMALL); + HILDON_ICON_SIZE_SMALL); gtk_widget_show (priv->priority_icon); priority_action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/ToolsMenu/MessagePriorityMenu/MessagePriorityHighMenu"); @@ -2759,7 +2958,7 @@ modest_msg_edit_window_set_priority_flags (ModestMsgEditWindow *window, case TNY_HEADER_FLAG_LOW_PRIORITY: gtk_image_set_from_icon_name (GTK_IMAGE (priv->priority_icon), MODEST_HEADER_ICON_LOW, - HILDON_ICON_SIZE_XSMALL); + HILDON_ICON_SIZE_SMALL); gtk_widget_show (priv->priority_icon); priority_action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/ToolsMenu/MessagePriorityMenu/MessagePriorityLowMenu"); @@ -2773,6 +2972,7 @@ modest_msg_edit_window_set_priority_flags (ModestMsgEditWindow *window, gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (priority_action), TRUE); gtk_text_buffer_set_modified (priv->text_buffer, TRUE); } + gtk_widget_queue_resize (priv->subject_box); } void @@ -3133,8 +3333,12 @@ modest_msg_edit_window_is_modified (ModestMsgEditWindow *editor) return TRUE; if (gtk_text_buffer_get_modified (priv->text_buffer)) return TRUE; + account_name = modest_selector_picker_get_active_id (MODEST_SELECTOR_PICKER (priv->from_field)); - if (!priv->original_account_name || strcmp(account_name, priv->original_account_name)) { + if (priv->original_mailbox) { + if (!account_name || strcmp (account_name, priv->original_mailbox)) + return TRUE; + } else if (!priv->original_account_name || strcmp(account_name, priv->original_account_name)) { return TRUE; } @@ -3210,6 +3414,8 @@ modest_msg_edit_window_clipboard_owner_change (GtkClipboard *clipboard, ModestMsgEditWindowPrivate *priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window); GtkClipboard *selection_clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD); gchar *text = NULL; + + /* It could happen that the window was already closed */ if (!GTK_WIDGET_VISIBLE (window)) return; @@ -3221,9 +3427,8 @@ modest_msg_edit_window_clipboard_owner_change (GtkClipboard *clipboard, } priv->clipboard_text = text; - if (GTK_WIDGET_VISIBLE (window)) { - modest_window_check_dimming_rules_group (MODEST_WINDOW (window), MODEST_DIMMING_RULES_CLIPBOARD); - } + modest_window_check_dimming_rules_group (MODEST_WINDOW (window), MODEST_DIMMING_RULES_CLIPBOARD); + g_object_unref (window); } @@ -3248,7 +3453,10 @@ modest_msg_edit_window_clipboard_owner_handle_change_in_idle (ModestMsgEditWindo { ModestMsgEditWindowPrivate *priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window); if (priv->clipboard_owner_idle == 0) { - priv->clipboard_owner_idle = g_idle_add (clipboard_owner_change_idle, window); + priv->clipboard_owner_idle = g_idle_add_full (G_PRIORITY_DEFAULT_IDLE, + clipboard_owner_change_idle, + g_object_ref (window), + g_object_unref); } } @@ -3259,6 +3467,7 @@ subject_field_move_cursor (GtkEntry *entry, gboolean a2, gpointer window) { + /* It could happen that the window was already closed */ if (!GTK_WIDGET_VISIBLE (window)) return; @@ -3400,8 +3609,10 @@ gtk_text_iter_forward_search_insensitive (const GtkTextIter *iter, if (!g_utf8_collate (range_subtext, str_casefold)) { gchar *found_text = g_strndup (range_text + offset, str_chars_n); result = TRUE; - gtk_text_iter_forward_search (iter, found_text, GTK_TEXT_SEARCH_VISIBLE_ONLY|GTK_TEXT_SEARCH_TEXT_ONLY, - match_start, match_end, NULL); + 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_free (found_text); } g_free (range_subtext); @@ -3515,7 +3726,6 @@ modest_msg_edit_window_set_draft (ModestMsgEditWindow *window, g_return_if_fail ((draft == NULL)||(TNY_IS_MSG (draft))); priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window); - ModestWindowMgr *mgr = modest_runtime_get_window_mgr (); if (priv->draft_msg != NULL) { g_object_unref (priv->draft_msg); @@ -3529,12 +3739,6 @@ modest_msg_edit_window_set_draft (ModestMsgEditWindow *window, priv->msg_uid = NULL; } priv->msg_uid = modest_tny_folder_get_header_unique_id (header); - if (GTK_WIDGET_REALIZED (window)) { - if (!modest_window_mgr_register_window (mgr, MODEST_WINDOW (window), NULL)) { - gtk_widget_destroy (GTK_WIDGET (window)); - return; - } - } } priv->draft_msg = draft; @@ -3644,9 +3848,9 @@ on_account_removed (TnyAccountStore *account_store, } } -static void -from_field_changed (HildonPickerButton *button, - ModestMsgEditWindow *self) +static void update_signature (ModestMsgEditWindow *self, + const gchar *old_account, + const gchar *new_account) { ModestMsgEditWindowPrivate *priv; gboolean has_old_signature, has_new_signature; @@ -3658,30 +3862,54 @@ from_field_changed (HildonPickerButton *button, priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (self); + gtk_text_buffer_begin_user_action (priv->text_buffer); + gtk_text_buffer_get_start_iter (priv->text_buffer, &iter); mgr = modest_runtime_get_account_mgr (); - signature = modest_account_mgr_get_signature (mgr, priv->last_from_account, &has_old_signature); - if (has_old_signature) { - full_signature = g_strconcat ("\n--\n", signature, NULL); - if (gtk_text_iter_forward_search (&iter, full_signature, 0, &match_start, &match_end, NULL)) { - gtk_text_buffer_delete (priv->text_buffer, &match_start, &match_end); - iter = match_start; - } else if (gtk_text_iter_forward_search (&iter, _("mcen_ia_editor_original_message"), 0, - &match_start, &match_end, NULL)) { - iter = match_start; + + + if (old_account) { + signature = modest_account_mgr_get_signature_from_recipient (mgr, old_account, &has_old_signature); + if (has_old_signature) { + full_signature = g_strconcat ("\n--\n", signature, NULL); + if (gtk_text_iter_forward_search (&iter, full_signature, 0, &match_start, &match_end, NULL)) { + gtk_text_buffer_delete (priv->text_buffer, &match_start, &match_end); + iter = match_start; + } else if (gtk_text_iter_forward_search (&iter, _("mcen_ia_editor_original_message"), 0, + &match_start, &match_end, NULL)) { + iter = match_start; + } + g_free (full_signature); } - g_free (full_signature); + g_free (signature); } - g_free (signature); priv->last_from_account = modest_selector_picker_get_active_id (MODEST_SELECTOR_PICKER (priv->from_field)); - signature = modest_account_mgr_get_signature (mgr, priv->last_from_account, &has_new_signature); + signature = modest_account_mgr_get_signature_from_recipient (mgr, new_account, &has_new_signature); if (has_new_signature) { full_signature = g_strconcat ("\n--\n", signature, NULL); gtk_text_buffer_insert (priv->text_buffer, &iter, full_signature, -1); g_free (full_signature); } g_free (signature); + gtk_text_buffer_end_user_action (priv->text_buffer); +} + +static void +from_field_changed (HildonPickerButton *button, + ModestMsgEditWindow *self) +{ + ModestMsgEditWindowPrivate *priv; + gchar *old_account, *new_account; + + priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (self); + + old_account = priv->last_from_account; + priv->last_from_account = modest_selector_picker_get_active_id (MODEST_SELECTOR_PICKER (priv->from_field)); + new_account = priv->last_from_account; + + update_signature (self, old_account, new_account); + } typedef struct _MessageSettingsHelper { @@ -3765,6 +3993,7 @@ static void modest_msg_edit_window_show_msg_settings_dialog (ModestMsgEditWindow *window) { GtkWidget *dialog; + GtkWidget *align; GtkWidget *vbox; GtkWidget *priority_hbox; GtkWidget *high_toggle, *medium_toggle, *low_toggle; @@ -3779,6 +4008,7 @@ modest_msg_edit_window_show_msg_settings_dialog (ModestMsgEditWindow *window) priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window); helper.window = window; helper.priority_group = NULL; + helper.format_group = NULL; title_sizegroup = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL); value_sizegroup = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL); @@ -3787,7 +4017,11 @@ modest_msg_edit_window_show_msg_settings_dialog (ModestMsgEditWindow *window) GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, _HL("wdgt_bd_done"), GTK_RESPONSE_ACCEPT, NULL); vbox = gtk_vbox_new (FALSE, 0); - gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), vbox); + align = gtk_alignment_new (0.0, 0.0, 1.0, 1.0); + gtk_alignment_set_padding (GTK_ALIGNMENT (align), 0, MODEST_MARGIN_DOUBLE, MODEST_MARGIN_DOUBLE, 0); + gtk_container_add (GTK_CONTAINER (align), vbox); + gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), align); + gtk_widget_show (align); gtk_widget_show (vbox); /* Priority toggles */