diff options
author | Jeffrey Stedfast <fejj@novell.com> | 2006-05-27 04:51:51 +0800 |
---|---|---|
committer | Jeffrey Stedfast <fejj@src.gnome.org> | 2006-05-27 04:51:51 +0800 |
commit | cae250057c8ad1a0ce35ff5d119063e187789038 (patch) | |
tree | c3684eb32c29ea83b208c2a28e804d7ff72accde /widgets/misc/e-attachment.c | |
parent | 859a20c8042ec24ab669fe75aca7dce976b17218 (diff) | |
download | gsoc2013-evolution-cae250057c8ad1a0ce35ff5d119063e187789038.tar.gz gsoc2013-evolution-cae250057c8ad1a0ce35ff5d119063e187789038.tar.zst gsoc2013-evolution-cae250057c8ad1a0ce35ff5d119063e187789038.zip |
Fix for Novell bug #178631
2006-05-26 Jeffrey Stedfast <fejj@novell.com>
Fix for Novell bug #178631
* e-attachment-bar.c: Changed the EAttachmentBarPrivate struct, we
no longer use a linked list, instead we use a GPtrArray - faster,
simpler (plus all the code used indexes anyway, so it was really
bizarre).
(free_attachment_list): Removed.
(attachment_destroy): New GWeakNotify callback for when an
EAttachment object gets destroyed. Remove the attachment from the
attachments array.
(add_common): Updated to add to an array rather than a linked
list. Also weak_ref the attachment object.
(remove_attachment): Removed.
(update): Updated to use the array instead of linked list of
attachments.
(e_attachment_bar_remove_selected): Same.
(e_attachment_bar_set_width): Same.
(e_attachment_bar_edit_selected): Same.
(e_attachment_bar_get_selected): Same.
(e_attachment_bar_get_attachment): Same.
(e_attachment_bar_get_all_attachments): Same and also optimised
since we can cheat now without having to g_slist_reverse.
(e_attachment_bar_get_parts): Same.
(destroy): Same.
(eab_drag_data_get): Same.
(init): Init attachments to a g_ptr_array_new
(e_attachment_bar_to_multipart): Updated to use the attachments
array.
(e_attachment_bar_get_num_attachments): Updated to return the
attachments->len.
(e_attachment_bar_get_download_count): Updated to use the array.
* e-attachment.c (finalise): Close the editor dialog if it is
open.
(async_progress_update_cb): If the phase is COMPLETE but the
file_size is 0, then treat it as an error. In the error case,
unref the attachment object (this will magically remove it from
the EAttachmentBar).
(close_cb): Don't unref the attachment object here anymore.
(e_attachment_edit): Don't ref the EAttachment anymore.
svn path=/trunk/; revision=32042
Diffstat (limited to 'widgets/misc/e-attachment.c')
-rw-r--r-- | widgets/misc/e-attachment.c | 217 |
1 files changed, 95 insertions, 122 deletions
diff --git a/widgets/misc/e-attachment.c b/widgets/misc/e-attachment.c index 7dae3d8e21..570c2e3332 100644 --- a/widgets/misc/e-attachment.c +++ b/widgets/misc/e-attachment.c @@ -64,6 +64,7 @@ enum { UPDATE, LAST_SIGNAL }; + static guint signals[LAST_SIGNAL] = { 0 }; static GObjectClass *parent_class = NULL; @@ -74,16 +75,20 @@ changed (EAttachment *attachment) g_signal_emit (attachment, signals[CHANGED], 0); } - + /* GtkObject methods. */ static void -finalise(GObject *object) +finalise (GObject *object) { - EAttachment *attachment; + EAttachment *attachment = (EAttachment *) object; + GtkWidget *dialog; + + if (attachment->editor_gui != NULL) { + dialog = glade_xml_get_widget (attachment->editor_gui, "dialog"); + g_signal_emit_by_name (dialog, "response", GTK_RESPONSE_CLOSE); + } - attachment = E_ATTACHMENT (object); - if (attachment->is_available_local) { camel_object_unref (attachment->body); if (attachment->pixbuf_cache != NULL) @@ -93,14 +98,14 @@ finalise(GObject *object) gnome_vfs_async_cancel(attachment->handle); g_free (attachment->description); } - + g_free (attachment->file_name); g_free (attachment->store_uri); - + G_OBJECT_CLASS (parent_class)->finalize (object); } - + /* Signals. */ static void @@ -115,7 +120,7 @@ real_update_attachment (EAttachment *attachment, char *msg) g_return_if_fail (E_IS_ATTACHMENT (attachment)); } - + static void class_init (EAttachmentClass *klass) { @@ -218,9 +223,7 @@ attachment_guess_mime_type (const char *file_name) * Return value: the new attachment, or %NULL on error **/ EAttachment * -e_attachment_new (const char *file_name, - const char *disposition, - CamelException *ex) +e_attachment_new (const char *file_name, const char *disposition, CamelException *ex) { EAttachment *new; CamelMimePart *part; @@ -229,7 +232,7 @@ e_attachment_new (const char *file_name, struct stat statbuf; char *mime_type; char *filename; - CamelURL *curl; + CamelURL *url; g_return_val_if_fail (file_name != NULL, NULL); @@ -248,16 +251,14 @@ e_attachment_new (const char *file_name, return NULL; } - stream = camel_stream_fs_new_with_name (file_name, O_RDONLY, 0); - if (!stream) { + if (!(stream = camel_stream_fs_new_with_name (file_name, O_RDONLY, 0))) { camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, _("Cannot attach file %s: %s"), file_name, g_strerror (errno)); return NULL; } - mime_type = attachment_guess_mime_type (file_name); - if (mime_type) { + if ((mime_type = attachment_guess_mime_type (file_name))) { if (!g_ascii_strcasecmp (mime_type, "message/rfc822")) { wrapper = (CamelDataWrapper *) camel_mime_message_new (); } else { @@ -303,10 +304,10 @@ e_attachment_new (const char *file_name, new->is_available_local = TRUE; new->file_name = filename; - curl = camel_url_new ("file:", NULL); - camel_url_set_path (curl, file_name); - new->store_uri = camel_url_to_string (curl, 0); - camel_url_free (curl); + url = camel_url_new ("file:", NULL); + camel_url_set_path (url, file_name); + new->store_uri = camel_url_to_string (url, 0); + camel_url_free (url); return new; } @@ -314,8 +315,8 @@ e_attachment_new (const char *file_name, typedef struct DownloadInfo { EAttachment *attachment; - gchar *file_name; -}DownloadInfo; + char *file_name; +} DownloadInfo; static int async_progress_update_cb (GnomeVFSAsyncHandle *handle, @@ -324,7 +325,6 @@ async_progress_update_cb (GnomeVFSAsyncHandle *handle, { switch (info->status) { case GNOME_VFS_XFER_PROGRESS_STATUS_OK: - { if (info->file_size) { download_info->attachment->percentage = info->bytes_copied*100/info->file_size; g_signal_emit (download_info->attachment, signals[UPDATE], 0); @@ -336,6 +336,9 @@ async_progress_update_cb (GnomeVFSAsyncHandle *handle, if (info->phase == GNOME_VFS_XFER_PHASE_COMPLETED) { CamelException ex; + if (!info->file_size) + goto error; + download_info->attachment->is_available_local = TRUE; download_info->attachment->handle = NULL; camel_exception_init (&ex); @@ -346,13 +349,12 @@ async_progress_update_cb (GnomeVFSAsyncHandle *handle, g_free (download_info); } return TRUE; - } case GNOME_VFS_XFER_PROGRESS_STATUS_VFSERROR: - gnome_vfs_async_cancel (handle); + error: + g_object_unref (download_info->attachment); g_free (download_info->file_name); g_free (download_info); return FALSE; - default: break; } @@ -361,46 +363,42 @@ async_progress_update_cb (GnomeVFSAsyncHandle *handle, } static void -download_to_local_path (GnomeVFSURI *source_uri, GnomeVFSURI *target_uri, DownloadInfo *download_info) +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); - + GList *source_uri_list; + GList *target_uri_list; + + source_uri_list = g_list_append (NULL, source_uri); + target_uri_list = g_list_append (NULL, target_uri); + /* Callback info */ - /* Maybe check the result here somewhere? */ - 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 */ - (GnomeVFSAsyncXferProgressCallback) async_progress_update_cb, /* progress_update_callback */ - download_info, /* update_callback_data */ - NULL, /* progress_sync_callback */ - NULL); /* sync_callback_data */ + 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 */ + (GnomeVFSAsyncXferProgressCallback) async_progress_update_cb, + download_info, /* update_callback_data */ + NULL, /* progress_sync_callback */ + NULL); /* sync_callback_data */ } EAttachment * -e_attachment_new_remote_file (const char *url, - const char *disposition, - const char *path, - CamelException *ex) +e_attachment_new_remote_file (const char *uri, const char *disposition, const char *path, CamelException *ex) { EAttachment *new; DownloadInfo *download_info; - gchar *base; - CamelURL *curl; + CamelURL *url; + char *base; - g_return_val_if_fail (url != NULL, NULL); - - curl = camel_url_new (url, NULL); - base = g_path_get_basename (curl->path); + g_return_val_if_fail (uri != NULL, NULL); + + url = camel_url_new (uri, NULL); + base = g_path_get_basename (url->path); + camel_url_free (url); new = g_object_new (E_TYPE_ATTACHMENT, NULL); new->editor_gui = NULL; @@ -411,23 +409,20 @@ e_attachment_new_remote_file (const char *url, new->is_available_local = FALSE; new->percentage = 0; new->file_name = g_build_filename (path, base, NULL); - - g_free(base); - + + g_free (base); + download_info = g_new (DownloadInfo, 1); download_info->attachment = new; download_info->file_name = g_strdup (new->file_name); - download_to_local_path (gnome_vfs_uri_new(url), gnome_vfs_uri_new(new->file_name), download_info); - - camel_url_free (curl); + download_to_local_path (gnome_vfs_uri_new (uri), gnome_vfs_uri_new (new->file_name), download_info); + return new; } + void -e_attachment_build_remote_file (const char *file_name, - EAttachment *attachment, - const char *disposition, - CamelException *ex) +e_attachment_build_remote_file (const char *file_name, EAttachment *attachment, const char *disposition, CamelException *ex) { CamelMimePart *part; CamelDataWrapper *wrapper; @@ -435,11 +430,11 @@ e_attachment_build_remote_file (const char *file_name, struct stat statbuf; char *mime_type; char *filename; - CamelURL *curl; + CamelURL *url; g_return_if_fail (file_name != NULL); - if (g_stat (file_name, &statbuf) < 0) { + if (g_stat (file_name, &statbuf) == -1) { camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, _("Cannot attach file %s: %s"), file_name, g_strerror (errno)); @@ -456,16 +451,14 @@ e_attachment_build_remote_file (const char *file_name, return; } - stream = camel_stream_fs_new_with_name (file_name, O_RDONLY, 0); - if (!stream) { + if (!(stream = camel_stream_fs_new_with_name (file_name, O_RDONLY, 0))) { camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, _("Cannot attach file %s: %s"), file_name, g_strerror (errno)); return; } - mime_type = attachment_guess_mime_type (file_name); - if (mime_type) { + if ((mime_type = attachment_guess_mime_type (file_name))) { if (!g_ascii_strcasecmp (mime_type, "message/rfc822")) { wrapper = (CamelDataWrapper *) camel_mime_message_new (); } else { @@ -512,13 +505,13 @@ e_attachment_build_remote_file (const char *file_name, g_free (attachment->file_name); attachment->file_name = filename; - curl = camel_url_new ("file:", NULL); - camel_url_set_path (curl, file_name); - attachment->store_uri = camel_url_to_string (curl, 0); - camel_url_free (curl); + url = camel_url_new ("file:", NULL); + camel_url_set_path (url, file_name); + attachment->store_uri = camel_url_to_string (url, 0); + camel_url_free (url); } - + /** * e_attachment_new_from_mime_part: @@ -604,8 +597,6 @@ close_cb (GtkWidget *widget, gpointer data) g_object_unref (attachment->editor_gui); attachment->editor_gui = NULL; - g_object_unref (attachment); - destroy_dialog_data (dialog_data); } @@ -638,7 +629,7 @@ ok_cb (GtkWidget *widget, gpointer data) 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: @@ -675,28 +666,22 @@ e_attachment_edit (EAttachment *attachment, GtkWidget *parent) const char *disposition; DialogData *dialog_data; GladeXML *editor_gui; + GtkWidget *window; char *type; char *filename; - g_return_if_fail (attachment != NULL); g_return_if_fail (E_IS_ATTACHMENT (attachment)); if (attachment->editor_gui != NULL) { - GtkWidget *window; - - window = glade_xml_get_widget (attachment->editor_gui, - "dialog"); + window = glade_xml_get_widget (attachment->editor_gui, "dialog"); gdk_window_show (window->window); return; } - filename = g_build_filename (EVOLUTION_GLADEDIR, - "e-attachment.glade", - NULL); - editor_gui = glade_xml_new (filename, - NULL, NULL); + filename = g_build_filename (EVOLUTION_GLADEDIR, "e-attachment.glade", NULL); + editor_gui = glade_xml_new (filename, NULL, NULL); g_free (filename); - + if (editor_gui == NULL) { g_warning ("Cannot load `e-attachment.glade'"); return; @@ -704,59 +689,47 @@ e_attachment_edit (EAttachment *attachment, GtkWidget *parent) attachment->editor_gui = editor_gui; - gtk_window_set_transient_for - (GTK_WINDOW (glade_xml_get_widget (editor_gui, "dialog")), - GTK_WINDOW (gtk_widget_get_toplevel (parent))); + gtk_window_set_transient_for (GTK_WINDOW (glade_xml_get_widget (editor_gui, "dialog")), + GTK_WINDOW (gtk_widget_get_toplevel (parent))); dialog_data = g_new (DialogData, 1); - g_object_ref (attachment); dialog_data->attachment = attachment; dialog_data->dialog = glade_xml_get_widget (editor_gui, "dialog"); - dialog_data->file_name_entry = GTK_ENTRY ( - glade_xml_get_widget (editor_gui, "file_name_entry")); - dialog_data->description_entry = GTK_ENTRY ( - glade_xml_get_widget (editor_gui, "description_entry")); - dialog_data->mime_type_entry = GTK_ENTRY ( - glade_xml_get_widget (editor_gui, "mime_type_entry")); - dialog_data->disposition_checkbox = GTK_TOGGLE_BUTTON ( - glade_xml_get_widget (editor_gui, "disposition_checkbox")); - - 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)); + dialog_data->file_name_entry = GTK_ENTRY (glade_xml_get_widget (editor_gui, "file_name_entry")); + dialog_data->description_entry = GTK_ENTRY (glade_xml_get_widget (editor_gui, "description_entry")); + dialog_data->mime_type_entry = GTK_ENTRY (glade_xml_get_widget (editor_gui, "mime_type_entry")); + dialog_data->disposition_checkbox = GTK_TOGGLE_BUTTON (glade_xml_get_widget (editor_gui, "disposition_checkbox")); + + 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 = attachment_guess_mime_type (attachment->file_name); - if (type) { + set_entry (editor_gui, "file_name_entry", attachment->file_name); + set_entry (editor_gui, "description_entry", attachment->description); + if ((type = attachment_guess_mime_type (attachment->file_name))) { 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); + gtk_toggle_button_set_active (dialog_data->disposition_checkbox, attachment->disposition); } connect_widget (editor_gui, "dialog", "response", (GCallback)response_cb, dialog_data); - + /* make sure that when the parent gets hidden/closed that our windows also close */ parent = gtk_widget_get_toplevel (parent); - gtk_signal_connect_while_alive (GTK_OBJECT (parent), "destroy", (GCallback)close_cb, dialog_data, + gtk_signal_connect_while_alive (GTK_OBJECT (parent), "destroy", (GCallback) close_cb, dialog_data, GTK_OBJECT (dialog_data->dialog)); - gtk_signal_connect_while_alive (GTK_OBJECT (parent), "hide", (GCallback)close_cb, dialog_data, + gtk_signal_connect_while_alive (GTK_OBJECT (parent), "hide", (GCallback) close_cb, dialog_data, GTK_OBJECT (dialog_data->dialog)); } |