aboutsummaryrefslogtreecommitdiffstats
path: root/composer/e-msg-composer-attachment-bar.c
diff options
context:
space:
mode:
Diffstat (limited to 'composer/e-msg-composer-attachment-bar.c')
-rw-r--r--composer/e-msg-composer-attachment-bar.c183
1 files changed, 181 insertions, 2 deletions
diff --git a/composer/e-msg-composer-attachment-bar.c b/composer/e-msg-composer-attachment-bar.c
index dde51106ec..7f15137e6a 100644
--- a/composer/e-msg-composer-attachment-bar.c
+++ b/composer/e-msg-composer-attachment-bar.c
@@ -52,6 +52,7 @@
#include "e-util/e-gui-utils.h"
#include "e-util/e-icon-factory.h"
#include "e-util/e-error.h"
+#include "e-util/e-mktemp.h"
#include "mail/em-popup.h"
#define ICON_WIDTH 64
@@ -70,6 +71,7 @@ struct _EMsgComposerAttachmentBarPrivate {
GList *attachments;
guint num_attachments;
+ gchar *path;
};
@@ -223,10 +225,20 @@ update (EMsgComposerAttachmentBar *bar)
EMsgComposerAttachment *attachment;
CamelContentType *content_type;
char *size_string, *label;
- GdkPixbuf *pixbuf;
+ GdkPixbuf *pixbuf=NULL;
const char *desc;
attachment = p->data;
+
+ if (!attachment->is_available_local) {
+ /* stock_attach would be better, but its fugly scaled up */
+ pixbuf = e_icon_factory_get_icon("stock_unknown", E_ICON_SIZE_DIALOG);
+ if (pixbuf) {
+ attachment->index = gnome_icon_list_append_pixbuf (icon_list, pixbuf, NULL, "");
+ g_object_unref(pixbuf);
+ }
+ continue;
+ }
content_type = camel_mime_part_get_content_type (attachment->body);
/* Get the image out of the attachment
and create a thumbnail for it */
@@ -326,6 +338,27 @@ update (EMsgComposerAttachmentBar *bar)
}
static void
+update_remote_file (EMsgComposerAttachmentBar *bar, EMsgComposerAttachment *attachment, char *msg)
+{
+ EMsgComposerAttachmentBarPrivate *priv;
+ GnomeIconList *icon_list;
+ GnomeIconTextItem *item;
+
+ priv = bar->priv;
+ icon_list = GNOME_ICON_LIST (bar);
+
+ gnome_icon_list_freeze (icon_list);
+
+ item = gnome_icon_list_get_icon_text_item (icon_list, attachment->index);
+ if (!item->is_text_allocated)
+ g_free (item->text);
+
+ gnome_icon_text_item_configure (item, item->x, item->y, item->width, item->fontname, msg, item->is_editable, TRUE);
+
+ gnome_icon_list_thaw (icon_list);
+}
+
+static void
remove_selected (EMsgComposerAttachmentBar *bar)
{
GnomeIconList *icon_list;
@@ -540,6 +573,9 @@ destroy (GtkObject *object)
if (bar->priv->attach)
gtk_widget_destroy(bar->priv->attach);
+ if (bar->priv->path)
+ g_free (bar->priv->path);
+
g_free (bar->priv);
bar->priv = NULL;
}
@@ -637,6 +673,7 @@ init (EMsgComposerAttachmentBar *bar)
priv->attach = NULL;
priv->attachments = NULL;
priv->num_attachments = 0;
+ priv->path = NULL;
bar->priv = priv;
}
@@ -815,7 +852,8 @@ e_msg_composer_attachment_bar_to_multipart (EMsgComposerAttachmentBar *bar,
EMsgComposerAttachment *attachment;
attachment = E_MSG_COMPOSER_ATTACHMENT (p->data);
- attach_to_multipart (multipart, attachment, default_charset);
+ if (attachment->is_available_local)
+ attach_to_multipart (multipart, attachment, default_charset);
}
}
@@ -842,6 +880,147 @@ e_msg_composer_attachment_bar_attach (EMsgComposerAttachmentBar *bar,
add_from_file (bar, file_name, "attachment");
}
+typedef struct DownloadInfo {
+ EMsgComposerAttachment *attachment;
+ EMsgComposerAttachmentBar *bar;
+ gchar *file_name;
+}DownloadInfo;
+
+static int
+async_progress_update_cb (GnomeVFSAsyncHandle *handle,
+ GnomeVFSXferProgressInfo *info,
+ DownloadInfo *download_info)
+{
+ int percent=0;
+ switch (info->status) {
+ case GNOME_VFS_XFER_PROGRESS_STATUS_OK:
+ {
+ gchar *base_path = g_path_get_basename(download_info->attachment->file_name);
+ if (info->file_size) {
+ percent = info->bytes_copied*100/info->file_size;
+ update_remote_file (download_info->bar,
+ download_info->attachment,
+ g_strdup_printf("%s (%d\%)", base_path, percent));
+ } else {
+ update_remote_file (download_info->bar,
+ download_info->attachment,
+ g_strdup_printf("%s (%d\%)", base_path, percent));
+ }
+ g_free (base_path);
+
+ if (info->phase == GNOME_VFS_XFER_PHASE_COMPLETED) {
+ CamelException ex;
+
+ download_info->attachment->is_available_local = TRUE;
+ download_info->attachment->handle = NULL;
+ camel_exception_init (&ex);
+ e_msg_composer_attachment_build_remote_file (download_info->file_name, download_info->attachment, "attachment", &ex);
+ update(download_info->bar);
+ g_free (download_info->file_name);
+ g_free (download_info);
+ }
+ return TRUE;
+ break;
+ }
+ case GNOME_VFS_XFER_PROGRESS_STATUS_VFSERROR:
+ gnome_vfs_async_cancel (handle);
+ g_free (download_info->file_name);
+ g_free (download_info);
+ return FALSE;
+ break;
+
+ default:
+ break;
+ }
+
+ return TRUE;
+}
+
+static void
+download_to_local_path (GnomeVFSURI *source_uri, GnomeVFSURI *target_uri, DownloadInfo *download_info)
+
+{
+ GnomeVFSResult result;
+ GList *source_uri_list = NULL;
+ GList *target_uri_list = NULL;
+
+ source_uri_list = g_list_prepend (source_uri_list, source_uri);
+ target_uri_list = g_list_prepend (target_uri_list, target_uri);
+
+ /* Callback info */
+ result = gnome_vfs_async_xfer (&download_info->attachment->handle, /* handle_return */
+ source_uri_list, /* source_uri_list */
+ target_uri_list, /* target_uri_list */
+ GNOME_VFS_XFER_DEFAULT, /* xfer_options */
+ GNOME_VFS_XFER_ERROR_MODE_ABORT, /* error_mode */
+ GNOME_VFS_XFER_OVERWRITE_MODE_REPLACE, /* overwrite_mode */
+ GNOME_VFS_PRIORITY_DEFAULT, /* priority */
+ async_progress_update_cb, /* progress_update_callback */
+ download_info, /* update_callback_data */
+ NULL, /* progress_sync_callback */
+ NULL); /* sync_callback_data */
+}
+
+
+int
+e_msg_composer_attachment_bar_get_download_count (EMsgComposerAttachmentBar *bar)
+{
+ EMsgComposerAttachmentBarPrivate *priv;
+ GList *p;
+ int count=0;
+
+ priv = bar->priv;
+
+ for (p = priv->attachments; p != NULL; p = p->next) {
+ EMsgComposerAttachment *attachment;
+
+ attachment = p->data;
+ if (!attachment->is_available_local)
+ count++;
+ }
+
+ return count;
+}
+
+void
+e_msg_composer_attachment_bar_attach_remote_file (EMsgComposerAttachmentBar *bar,
+ const gchar *url)
+{
+ EMsgComposerAttachment *attachment;
+ CamelException ex;
+ gchar *tmpfile;
+ gchar *base;
+
+ if (!bar->priv->path)
+ bar->priv->path = e_mkdtemp("attach-XXXXXX");
+ base = g_path_get_basename (url);
+
+ g_return_if_fail (E_IS_MSG_COMPOSER_ATTACHMENT_BAR (bar));
+ tmpfile = g_build_filename (bar->priv->path, base, NULL);
+
+ g_free (base);
+
+ camel_exception_init (&ex);
+ attachment = e_msg_composer_attachment_new_remote_file (tmpfile, "attachment", &ex);
+ if (attachment) {
+ DownloadInfo *download_info;
+ download_info = g_new (DownloadInfo, 1);
+ download_info->attachment = attachment;
+ download_info->bar =bar;
+ download_info->file_name = g_strdup (tmpfile);
+ add_common (bar, attachment);
+ download_to_local_path (gnome_vfs_uri_new(url), gnome_vfs_uri_new(tmpfile), download_info);
+
+ } else {
+ e_error_run((GtkWindow *)gtk_widget_get_toplevel((GtkWidget *)bar), "mail-composer:no-attach",
+ attachment->file_name, camel_exception_get_description(&ex), NULL);
+ camel_exception_clear (&ex);
+ }
+
+ g_free (tmpfile);
+
+}
+
void
e_msg_composer_attachment_bar_attach_mime_part (EMsgComposerAttachmentBar *bar,
CamelMimePart *part)