X-Git-Url: http://git.maemo.org/git/?a=blobdiff_plain;ds=sidebyside;f=src%2Fmaemo%2Fmodest-msg-edit-window.c;h=3a13607f64fb3eb9bf582ae4f3291ec3818f4103;hb=be6ccffc543395f60cd1e8551d0df6f8f037a8d5;hp=4405abead57a4e320601b5889deadd1e23a7c0c1;hpb=af98a92476ea30f9cf8fe033a59065b2b27d5ff3;p=modest diff --git a/src/maemo/modest-msg-edit-window.c b/src/maemo/modest-msg-edit-window.c index 4405abe..3a13607 100644 --- a/src/maemo/modest-msg-edit-window.c +++ b/src/maemo/modest-msg-edit-window.c @@ -34,6 +34,7 @@ #include #include #include +#include #include @@ -1424,7 +1425,7 @@ modest_msg_edit_window_attach_file (ModestMsgEditWindow *window) ModestMsgEditWindowPrivate *priv; GtkWidget *dialog = NULL; gint response = 0; - gchar *filename = NULL; + gchar *uri = NULL, *filename = NULL; priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window); @@ -1433,6 +1434,7 @@ modest_msg_edit_window_attach_file (ModestMsgEditWindow *window) response = gtk_dialog_run (GTK_DIALOG (dialog)); switch (response) { case GTK_RESPONSE_OK: + uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (dialog)); filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog)); break; default: @@ -1440,6 +1442,57 @@ modest_msg_edit_window_attach_file (ModestMsgEditWindow *window) } gtk_widget_destroy (dialog); + if (uri) { + + GnomeVFSHandle *handle = NULL; + GnomeVFSResult result; + + result = gnome_vfs_open (&handle, uri, GNOME_VFS_OPEN_READ); + if (result == GNOME_VFS_OK) { + TnyMimePart *mime_part; + TnyStream *stream; + const gchar *mime_type = NULL; + gchar *basename; + gchar *content_id; + GnomeVFSFileInfo info; + + if (gnome_vfs_get_file_info_from_handle (handle, &info, GNOME_VFS_FILE_INFO_GET_MIME_TYPE) == GNOME_VFS_OK) + 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)); + + tny_mime_part_construct_from_stream (mime_part, stream, mime_type); + + content_id = g_strdup_printf ("%d", priv->last_cid); + tny_mime_part_set_content_id (mime_part, content_id); + g_free (content_id); + priv->last_cid++; + + basename = g_path_get_basename (filename); + tny_mime_part_set_filename (mime_part, basename); + g_free (basename); + + priv->attachments = g_list_prepend (priv->attachments, mime_part); + modest_attachments_view_add_attachment (MODEST_ATTACHMENTS_VIEW (priv->attachments_view), + mime_part); + gtk_widget_set_no_show_all (priv->attachments_caption, FALSE); + gtk_widget_show_all (priv->attachments_caption); + } + g_free (filename); + } +} + +void +modest_msg_edit_window_attach_file_noninteractive ( + ModestMsgEditWindow *window, + gchar *filename) +{ + + ModestMsgEditWindowPrivate *priv; + + priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window); + if (filename) { gint file_id; @@ -2156,6 +2209,7 @@ text_buffer_delete_images_by_id (GtkTextBuffer *buffer, const gchar * image_id) } } } + gtk_text_iter_forward_char (&iter); } }