X-Git-Url: http://git.maemo.org/git/?p=modest;a=blobdiff_plain;f=src%2Fmaemo%2Fmodest-msg-edit-window.c;h=3fd0e734de5d4ae01f5547c37d8794fa717b5183;hp=d438ddf6b2bfc0023ccafaebcec52abaabfc6445;hb=099f1b1684400f3394ea4f9a0190c5961316be01;hpb=20f40360ad626eb860e7d106e5dcfd43a59d21d4 diff --git a/src/maemo/modest-msg-edit-window.c b/src/maemo/modest-msg-edit-window.c index d438ddf..3fd0e73 100644 --- a/src/maemo/modest-msg-edit-window.c +++ b/src/maemo/modest-msg-edit-window.c @@ -179,6 +179,8 @@ static void text_buffer_mark_set (GtkTextBuffer *buffer, void vadj_changed (GtkAdjustment *adj, ModestMsgEditWindow *window); +static ModestPair *find_transport_from_message_sender (ModestPairList *transports, + TnyMsg *msg); @@ -243,6 +245,7 @@ struct _ModestMsgEditWindowPrivate { ModestPairList *from_field_protos; GtkWidget *from_field; + const gchar *original_account_name; GtkWidget *to_field; GtkWidget *cc_field; @@ -272,6 +275,7 @@ struct _ModestMsgEditWindowPrivate { GtkWidget *scroll; guint scroll_drag_timeout_id; + gdouble last_upper; gint last_cid; TnyList *attachments; @@ -437,6 +441,7 @@ modest_msg_edit_window_init (ModestMsgEditWindow *obj) priv->sent = FALSE; priv->scroll_drag_timeout_id = 0; + priv->last_upper = 0.0; modest_window_mgr_register_help_id (modest_runtime_get_window_mgr(), GTK_WINDOW(obj),"applications_email_editor"); @@ -490,6 +495,41 @@ get_transports (void) return transports; } +/** + * Search an (account, address) ModestPairList for a pair whose + * address matches the one in the From: header of a TnyMsg + * + * @result: A ModestPair * with a matching address, or NULL if none found + */ +static ModestPair * +find_transport_from_message_sender (ModestPairList *transports, TnyMsg *msg) +{ + g_return_val_if_fail (transports, NULL); + g_return_val_if_fail (msg, NULL); + + ModestPair *account_pair = NULL; + TnyHeader *header = tny_msg_get_header (msg); + + if (header != NULL && tny_header_get_from (header)) { + char *from_addr = modest_text_utils_get_email_address (tny_header_get_from (header)); + GSList *iter; + for (iter = transports; iter && !account_pair; iter = iter->next) { + ModestPair *pair = (ModestPair *) iter->data; + char *account_addr = modest_text_utils_get_email_address ((char *) pair->second); + if (account_addr && !strcasecmp(from_addr, account_addr)) { + account_pair = pair; + } + g_free (account_addr); + } + g_free (from_addr); + } + + if (header) + g_object_unref (header); + + return account_pair; +} + static void window_focus (GtkWindow *window, GtkWidget *widget, gpointer userdata) @@ -526,6 +566,9 @@ correct_scroll_without_drag_check (ModestMsgEditWindow *w) priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE(w); + if (!gtk_widget_is_focus (priv->msg_body)) + return; + insert = gtk_text_buffer_get_insert (priv->text_buffer); gtk_text_buffer_get_iter_at_mark (priv->text_buffer, &iter, insert); @@ -601,7 +644,14 @@ text_buffer_mark_set (GtkTextBuffer *buffer, void vadj_changed (GtkAdjustment *adj, ModestMsgEditWindow *window) { - correct_scroll (window); + ModestMsgEditWindowPrivate *priv; + + priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window); + + if (priv->last_upper != adj->upper) { + priv->last_upper = adj->upper; + correct_scroll (window); + } } static void @@ -996,6 +1046,7 @@ replace_with_images (ModestMsgEditWindow *self, TnyList *attachments) } g_object_unref (part); } + g_object_unref (iter); } static void @@ -1073,6 +1124,7 @@ update_last_cid (ModestMsgEditWindow *self, TnyList *attachments) } g_object_unref (part); } + g_object_unref (iter); } static void @@ -1433,10 +1485,15 @@ modest_msg_edit_window_new (TnyMsg *msg, const gchar *account_name, gboolean pre modest_window_set_active_account (MODEST_WINDOW(obj), account_name); - account_pair = modest_pair_list_find_by_first_as_string (priv->from_field_protos, account_name); + account_pair = find_transport_from_message_sender (priv->from_field_protos, msg); + if (account_pair == NULL) { + account_pair = modest_pair_list_find_by_first_as_string (priv->from_field_protos, account_name); + } if (account_pair != NULL) modest_combo_box_set_active_id (MODEST_COMBO_BOX (priv->from_field), account_pair->first); + priv->original_account_name = account_pair ? (const gchar *) account_pair->first : NULL; + parent_priv->ui_dimming_manager = modest_ui_dimming_manager_new (); menu_rules_group = modest_dimming_rules_group_new (MODEST_DIMMING_RULES_MENU, FALSE); toolbar_rules_group = modest_dimming_rules_group_new (MODEST_DIMMING_RULES_TOOLBAR, TRUE); @@ -1472,6 +1529,7 @@ modest_msg_edit_window_new (TnyMsg *msg, const gchar *account_name, gboolean pre g_object_unref (toolbar_rules_group); g_object_unref (clipboard_rules_group); gtk_widget_show_all (GTK_WIDGET (obj)); + modest_msg_edit_window_clipboard_owner_change (NULL, NULL, MODEST_MSG_EDIT_WINDOW (obj)); set_msg (MODEST_MSG_EDIT_WINDOW (obj), msg, preserve_is_rich); @@ -1616,6 +1674,7 @@ modest_msg_edit_window_get_msg_data (ModestMsgEditWindow *edit_window) g_object_unref (part); tny_iterator_next (att_iter); } + g_object_unref (att_iter); data->priority_flags = priv->priority_flags; @@ -2091,7 +2150,7 @@ modest_msg_edit_window_insert_image (ModestMsgEditWindow *window) result = gnome_vfs_open (&handle, uri, GNOME_VFS_OPEN_READ); if (result == GNOME_VFS_OK) { GdkPixbuf *pixbuf; - GnomeVFSFileInfo info; + GnomeVFSFileInfo *info; gchar *filename, *basename, *escaped_filename; TnyMimePart *mime_part; gchar *content_id; @@ -2105,11 +2164,12 @@ modest_msg_edit_window_insert_image (ModestMsgEditWindow *window) filename = gnome_vfs_unescape_string_for_display (escaped_filename); g_free (escaped_filename); gnome_vfs_uri_unref (vfs_uri); + info = gnome_vfs_file_info_new (); - if (gnome_vfs_get_file_info (uri, &info, GNOME_VFS_FILE_INFO_GET_MIME_TYPE + if (gnome_vfs_get_file_info (uri, info, GNOME_VFS_FILE_INFO_GET_MIME_TYPE | GNOME_VFS_FILE_INFO_FORCE_SLOW_MIME_TYPE) == GNOME_VFS_OK) - mime_type = gnome_vfs_file_info_get_mime_type (&info); + mime_type = gnome_vfs_file_info_get_mime_type (info); mime_part = tny_platform_factory_new_mime_part (modest_runtime_get_platform_factory ()); @@ -2140,6 +2200,7 @@ modest_msg_edit_window_insert_image (ModestMsgEditWindow *window) gtk_text_buffer_set_modified (priv->text_buffer, TRUE); g_free (filename); g_object_unref (mime_part); + gnome_vfs_file_info_unref (info); } } @@ -2182,14 +2243,16 @@ modest_msg_edit_window_attach_file_one ( ModestMsgEditWindow *window, const gchar *uri) { + GnomeVFSHandle *handle = NULL; + ModestMsgEditWindowPrivate *priv; + GnomeVFSResult result; + g_return_if_fail (window); g_return_if_fail (uri); - ModestMsgEditWindowPrivate *priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window); - + priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window); - GnomeVFSHandle *handle = NULL; - GnomeVFSResult result = gnome_vfs_open (&handle, uri, GNOME_VFS_OPEN_READ); + result = gnome_vfs_open (&handle, uri, GNOME_VFS_OPEN_READ); if (result == GNOME_VFS_OK) { TnyMimePart *mime_part; TnyStream *stream; @@ -2198,7 +2261,7 @@ modest_msg_edit_window_attach_file_one ( gchar *escaped_filename; gchar *filename; gchar *content_id; - GnomeVFSFileInfo info; + GnomeVFSFileInfo *info; GnomeVFSURI *vfs_uri; vfs_uri = gnome_vfs_uri_new (uri); @@ -2208,12 +2271,14 @@ modest_msg_edit_window_attach_file_one ( filename = gnome_vfs_unescape_string_for_display (escaped_filename); g_free (escaped_filename); gnome_vfs_uri_unref (vfs_uri); + + info = gnome_vfs_file_info_new (); if (gnome_vfs_get_file_info (uri, - &info, + info, GNOME_VFS_FILE_INFO_GET_MIME_TYPE) == GNOME_VFS_OK) - mime_type = gnome_vfs_file_info_get_mime_type (&info); + mime_type = gnome_vfs_file_info_get_mime_type (info); mime_part = tny_platform_factory_new_mime_part (modest_runtime_get_platform_factory ()); stream = TNY_STREAM (tny_vfs_stream_new (handle)); @@ -2234,12 +2299,13 @@ modest_msg_edit_window_attach_file_one ( tny_list_prepend (priv->attachments, (GObject *) mime_part); modest_attachments_view_add_attachment (MODEST_ATTACHMENTS_VIEW (priv->attachments_view), mime_part, - info.size == 0, info.size); + info->size == 0, info->size); gtk_widget_set_no_show_all (priv->attachments_caption, FALSE); gtk_widget_show_all (priv->attachments_caption); gtk_text_buffer_set_modified (priv->text_buffer, TRUE); g_free (filename); g_object_unref (mime_part); + gnome_vfs_file_info_unref (info); } } @@ -2319,6 +2385,7 @@ modest_msg_edit_window_remove_attachments (ModestMsgEditWindow *window, gtk_text_buffer_set_modified (priv->text_buffer, TRUE); g_object_unref (mime_part); } + g_object_unref (iter); } g_object_unref (att_list); @@ -2946,6 +3013,7 @@ gboolean modest_msg_edit_window_is_modified (ModestMsgEditWindow *editor) { ModestMsgEditWindowPrivate *priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (editor); + const char *account_name; GtkTextBuffer *buffer; buffer = modest_recpt_editor_get_buffer (MODEST_RECPT_EDITOR(priv->to_field)); @@ -2959,6 +3027,10 @@ modest_msg_edit_window_is_modified (ModestMsgEditWindow *editor) return TRUE; if (gtk_text_buffer_get_modified (priv->text_buffer)) return TRUE; + account_name = modest_combo_box_get_active_id (MODEST_COMBO_BOX (priv->from_field)); + if (!priv->original_account_name || strcmp(account_name, priv->original_account_name)) { + return TRUE; + } return FALSE; }