- pixbuf = gdk_pixbuf_new_from_file (filename, NULL);
- if (pixbuf) {
- gint image_file_id;
- GdkPixbufFormat *pixbuf_format;
-
- image_file_id = g_open (filename, O_RDONLY, 0);
- pixbuf_format = gdk_pixbuf_get_file_info (filename, NULL, NULL);
- if ((image_file_id != -1)&&(pixbuf_format != NULL)) {
- TnyMimePart *image_part;
- TnyStream *image_stream;
- gchar **mime_types;
- gchar *mime_type;
- gchar *basename;
- gchar *content_id;
-
- mime_types = gdk_pixbuf_format_get_mime_types (pixbuf_format);
- if ((mime_types != NULL) && (mime_types[0] != NULL)) {
- mime_type = mime_types[0];
- } else {
- mime_type = "image/unknown";
- }
- image_part = tny_platform_factory_new_mime_part
- (modest_runtime_get_platform_factory ());
- image_stream = TNY_STREAM (tny_fs_stream_new (image_file_id));
-
- tny_mime_part_construct_from_stream (image_part, image_stream, mime_type);
- g_strfreev (mime_types);
-
- content_id = g_strdup_printf ("%d", priv->last_cid);
- tny_mime_part_set_content_id (image_part, content_id);
- g_free (content_id);
- priv->last_cid++;
-
- basename = g_path_get_basename (filename);
- tny_mime_part_set_filename (image_part, basename);
- g_free (basename);
-
+ uri = (const gchar *) uri_node->data;
+ result = gnome_vfs_open (&handle, uri, GNOME_VFS_OPEN_READ);
+ if (result == GNOME_VFS_OK) {
+ GdkPixbufLoader *loader;
+ GdkPixbuf *pixbuf;
+ GnomeVFSFileInfo info;
+ gchar *filename, *basename;
+ TnyMimePart *mime_part;
+ TnyStream *stream;
+ gchar *content_id;
+ const gchar *mime_type = NULL;
+
+ filename = g_filename_from_uri (uri, NULL, NULL);
+ 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);
+ gtk_text_buffer_set_modified (priv->text_buffer, TRUE);
+ g_free (filename);
+
+ loader = gdk_pixbuf_loader_new_with_mime_type (mime_type, NULL);
+ while (!tny_stream_is_eos (TNY_STREAM (stream))) {
+ char read_buffer[128];
+ gint readed;
+ readed = tny_stream_read (TNY_STREAM (stream), read_buffer, 128);
+ if (!gdk_pixbuf_loader_write (loader, read_buffer, readed, NULL))
+ break;
+ }
+ pixbuf = gdk_pixbuf_loader_get_pixbuf (loader);
+ g_object_ref (pixbuf);
+ gdk_pixbuf_loader_close (loader, NULL);
+ g_object_unref (loader);
+
+ if (gdk_pixbuf_get_width (pixbuf) > IMAGE_MAX_WIDTH) {
+ GdkPixbuf *new_pixbuf;
+ gint new_height;
+ new_height = (gdk_pixbuf_get_height (pixbuf) * IMAGE_MAX_WIDTH) /
+ gdk_pixbuf_get_width (pixbuf);
+ new_pixbuf = gdk_pixbuf_scale_simple (pixbuf, IMAGE_MAX_WIDTH, new_height, GDK_INTERP_BILINEAR);
+ g_object_unref (pixbuf);
+ pixbuf = new_pixbuf;
+ }
+
+ if (pixbuf != NULL) {