aboutsummaryrefslogtreecommitdiffstats
path: root/calendar/gui/dialogs/cal-attachment.c
diff options
context:
space:
mode:
Diffstat (limited to 'calendar/gui/dialogs/cal-attachment.c')
-rw-r--r--calendar/gui/dialogs/cal-attachment.c222
1 files changed, 190 insertions, 32 deletions
diff --git a/calendar/gui/dialogs/cal-attachment.c b/calendar/gui/dialogs/cal-attachment.c
index 2f36aaf887..f9ecb9f329 100644
--- a/calendar/gui/dialogs/cal-attachment.c
+++ b/calendar/gui/dialogs/cal-attachment.c
@@ -71,9 +71,18 @@ finalise(GObject *object)
attachment = CAL_ATTACHMENT (object);
- camel_object_unref (attachment->body);
- if (attachment->pixbuf_cache != NULL)
- g_object_unref (attachment->pixbuf_cache);
+ if (attachment->is_available_local) {
+ camel_object_unref (attachment->body);
+ if (attachment->pixbuf_cache != NULL)
+ g_object_unref (attachment->pixbuf_cache);
+ } else {
+ if (attachment->handle)
+ gnome_vfs_async_cancel(attachment->handle);
+ if (attachment->file_name)
+ g_free (attachment->file_name);
+ if (attachment->description)
+ g_free (attachment->description);
+ }
G_OBJECT_CLASS (parent_class)->finalize (object);
}
@@ -116,6 +125,10 @@ init (CalAttachment *cal_attachment)
cal_attachment->body = NULL;
cal_attachment->size = 0;
cal_attachment->pixbuf_cache = NULL;
+ cal_attachment->index = -1;
+ cal_attachment->file_name = NULL;
+ cal_attachment->description = NULL;
+ cal_attachment->disposition = FALSE;
}
GType
@@ -259,10 +272,122 @@ cal_attachment_new (const char *file_name,
new->body = part;
new->size = statbuf.st_size;
new->guessed_type = TRUE;
+ new->handle = NULL;
+ new->is_available_local = TRUE;
return new;
}
+CalAttachment *
+cal_attachment_new_remote_file (const char *file_name,
+ const char *disposition,
+ CamelException *ex)
+{
+ CalAttachment *new;
+
+ g_return_val_if_fail (file_name != NULL, NULL);
+
+ new = g_object_new (E_TYPE_CAL_ATTACHMENT, NULL);
+ new->editor_gui = NULL;
+ new->body = NULL;
+ new->size = 0;
+ new->guessed_type = FALSE;
+ new->handle = NULL;
+ new->is_available_local = FALSE;
+ new->file_name = g_path_get_basename(file_name);
+
+ return new;
+}
+
+void
+cal_attachment_build_remote_file (const char *file_name,
+ CalAttachment *attachment,
+ const char *disposition,
+ CamelException *ex)
+{
+ CamelMimePart *part;
+ CamelDataWrapper *wrapper;
+ CamelStream *stream;
+ struct stat statbuf;
+ char *mime_type;
+ char *filename;
+
+ g_return_if_fail (file_name != NULL);
+
+ if (stat (file_name, &statbuf) < 0) {
+ camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
+ _("Cannot attach file %s: %s"),
+ file_name, g_strerror (errno));
+ return;
+ }
+
+ /* return if it's not a regular file */
+ if (!S_ISREG (statbuf.st_mode)) {
+ camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
+ _("Cannot attach file %s: not a regular file"),
+ file_name);
+ return;
+ }
+
+ stream = camel_stream_fs_new_with_name (file_name, O_RDONLY, 0);
+ if (!stream) {
+ camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
+ _("Cannot attach file %s: %s"),
+ file_name, g_strerror (errno));
+ return;
+ }
+
+ mime_type = cal_attachment_guess_mime_type (file_name);
+ if (mime_type) {
+ if (!g_ascii_strcasecmp (mime_type, "message/rfc822")) {
+ wrapper = (CamelDataWrapper *) camel_mime_message_new ();
+ } else {
+ wrapper = camel_data_wrapper_new ();
+ }
+
+ camel_data_wrapper_construct_from_stream (wrapper, stream);
+ camel_data_wrapper_set_mime_type (wrapper, mime_type);
+ g_free (mime_type);
+ } else {
+ wrapper = camel_data_wrapper_new ();
+ camel_data_wrapper_construct_from_stream (wrapper, stream);
+ camel_data_wrapper_set_mime_type (wrapper, "application/octet-stream");
+ }
+
+ camel_object_unref (stream);
+
+ part = camel_mime_part_new ();
+ camel_medium_set_content_object (CAMEL_MEDIUM (part), wrapper);
+ camel_object_unref (wrapper);
+
+ if (attachment->disposition)
+ camel_mime_part_set_disposition (part, "inline");
+ else
+ camel_mime_part_set_disposition (part, "attachment");
+
+ if (!attachment->file_name)
+ filename = g_path_get_basename (file_name);
+ else
+ filename = g_path_get_basename (attachment->file_name);
+
+ camel_mime_part_set_filename (part, filename);
+ g_free (filename);
+
+ if (attachment->description) {
+ camel_mime_part_set_description (part, attachment->description);
+ g_free (attachment->description);
+ attachment->description = NULL;
+ }
+
+ attachment->editor_gui = NULL;
+ attachment->body = part;
+ attachment->size = statbuf.st_size;
+ attachment->guessed_type = TRUE;
+ if (attachment->file_name) {
+ g_free (attachment->file_name);
+ attachment->file_name = NULL;
+ }
+}
/**
* cal_attachment_new_from_mime_part:
@@ -380,27 +505,44 @@ ok_cb (GtkWidget *widget, gpointer data)
attachment = dialog_data->attachment;
str = gtk_entry_get_text (dialog_data->file_name_entry);
- camel_mime_part_set_filename (attachment->body, str);
+ if (attachment->is_available_local) {
+ camel_mime_part_set_filename (attachment->body, str);
+ } else {
+ if (attachment->file_name)
+ g_free (attachment->file_name);
+ attachment->file_name = g_strdup (str);
+ }
str = gtk_entry_get_text (dialog_data->description_entry);
- camel_mime_part_set_description (attachment->body, str);
+ if (attachment->is_available_local) {
+ camel_mime_part_set_description (attachment->body, str);
+ } else {
+ if (attachment->description)
+ g_free (attachment->description);
+ attachment->description = g_strdup (str);
+ }
str = gtk_entry_get_text (dialog_data->mime_type_entry);
- camel_mime_part_set_content_type (attachment->body, str);
-
- camel_data_wrapper_set_mime_type(camel_medium_get_content_object(CAMEL_MEDIUM (attachment->body)), str);
-
- switch (gtk_toggle_button_get_active (dialog_data->disposition_checkbox)) {
- case 0:
- camel_mime_part_set_disposition (attachment->body, "attachment");
- break;
- case 1:
- camel_mime_part_set_disposition (attachment->body, "inline");
- break;
- default:
- /* Hmmmm? */
- break;
+ if (attachment->is_available_local) {
+ camel_mime_part_set_content_type (attachment->body, str);
+ camel_data_wrapper_set_mime_type(camel_medium_get_content_object(CAMEL_MEDIUM (attachment->body)), str);
}
+
+ if (attachment->is_available_local) {
+ switch (gtk_toggle_button_get_active (dialog_data->disposition_checkbox)) {
+ case 0:
+ camel_mime_part_set_disposition (attachment->body, "attachment");
+ break;
+ case 1:
+ camel_mime_part_set_disposition (attachment->body, "inline");
+ break;
+ default:
+ /* Hmmmm? */
+ break;
+ }
+ } else {
+ attachment->disposition = gtk_toggle_button_get_active (dialog_data->disposition_checkbox);
+ }
changed (attachment);
close_cb (widget, data);
@@ -461,19 +603,35 @@ cal_attachment_edit (CalAttachment *attachment, GtkWidget *parent)
glade_xml_get_widget (editor_gui, "mime_type_entry"));
dialog_data->disposition_checkbox = GTK_TOGGLE_BUTTON (
glade_xml_get_widget (editor_gui, "disposition_checkbox"));
-
- set_entry (editor_gui, "file_name_entry",
- camel_mime_part_get_filename (attachment->body));
- set_entry (editor_gui, "description_entry",
- camel_mime_part_get_description (attachment->body));
- content_type = camel_mime_part_get_content_type (attachment->body);
- type = camel_content_type_simple (content_type);
- set_entry (editor_gui, "mime_type_entry", type);
- g_free (type);
-
- disposition = camel_mime_part_get_disposition (attachment->body);
- gtk_toggle_button_set_active (dialog_data->disposition_checkbox,
- disposition && !g_ascii_strcasecmp (disposition, "inline"));
+
+ if (attachment->is_available_local) {
+ set_entry (editor_gui, "file_name_entry",
+ camel_mime_part_get_filename (attachment->body));
+ set_entry (editor_gui, "description_entry",
+ camel_mime_part_get_description (attachment->body));
+ content_type = camel_mime_part_get_content_type (attachment->body);
+ type = camel_content_type_simple (content_type);
+ set_entry (editor_gui, "mime_type_entry", type);
+ g_free (type);
+
+ disposition = camel_mime_part_get_disposition (attachment->body);
+ gtk_toggle_button_set_active (dialog_data->disposition_checkbox,
+ disposition && !g_ascii_strcasecmp (disposition, "inline"));
+ } else {
+ set_entry (editor_gui, "file_name_entry",
+ attachment->file_name);
+ set_entry (editor_gui, "description_entry",
+ attachment->description);
+ type = cal_attachment_guess_mime_type (attachment->file_name);
+ if (type) {
+ set_entry (editor_gui, "mime_type_entry", type);
+ g_free (type);
+ } else {
+ set_entry (editor_gui, "mime_type_entry", "");
+ }
+ gtk_toggle_button_set_active (dialog_data->disposition_checkbox, attachment->disposition);
+
+ }
connect_widget (editor_gui, "dialog", "response", (GCallback)response_cb, dialog_data);
#warning "signal connect while alive"