diff options
author | nobody <nobody@localhost> | 2003-04-02 01:15:53 +0800 |
---|---|---|
committer | nobody <nobody@localhost> | 2003-04-02 01:15:53 +0800 |
commit | 2e5b2bbb530b642dda56b332cfd93810ac415098 (patch) | |
tree | e2b63c11a404a5dd99d407c989c8846fd0d5379d /composer/e-msg-composer-attachment.c | |
parent | 5cda225087bfdc66e19edb703689e8af655e171c (diff) | |
download | gsoc2013-evolution-EVOLUTION_1_2_4.tar gsoc2013-evolution-EVOLUTION_1_2_4.tar.gz gsoc2013-evolution-EVOLUTION_1_2_4.tar.bz2 gsoc2013-evolution-EVOLUTION_1_2_4.tar.lz gsoc2013-evolution-EVOLUTION_1_2_4.tar.xz gsoc2013-evolution-EVOLUTION_1_2_4.tar.zst gsoc2013-evolution-EVOLUTION_1_2_4.zip |
This commit was manufactured by cvs2svn to create tagEVOLUTION_1_2_4
'EVOLUTION_1_2_4'.
svn path=/tags/EVOLUTION_1_2_4/; revision=20614
Diffstat (limited to 'composer/e-msg-composer-attachment.c')
-rw-r--r-- | composer/e-msg-composer-attachment.c | 188 |
1 files changed, 101 insertions, 87 deletions
diff --git a/composer/e-msg-composer-attachment.c b/composer/e-msg-composer-attachment.c index 2be55b1f69..5da1bf6068 100644 --- a/composer/e-msg-composer-attachment.c +++ b/composer/e-msg-composer-attachment.c @@ -23,22 +23,20 @@ /* This is the object representing an email attachment. It is implemented as a - GObject to make it easier for the application to handle it. For example, + GtkObject to make it easier for the application to handle it. For example, the "changed" signal is emitted whenever something changes in the attachment. Also, this contains the code to let users edit the attachment manually. */ #include <sys/stat.h> -#include <string.h> #include <errno.h> -#include <camel/camel.h> #include <gtk/gtknotebook.h> #include <gtk/gtktogglebutton.h> +#include <camel/camel.h> +#include <gal/widgets/e-unicode.h> #include <libgnomevfs/gnome-vfs-mime.h> -#include "e-util/e-mktemp.h" - #include "e-msg-composer.h" #include "e-msg-composer-attachment.h" @@ -49,30 +47,28 @@ enum { }; static guint signals[LAST_SIGNAL] = { 0 }; -static GObjectClass *parent_class = NULL; +static GtkObjectClass *parent_class = NULL; static void changed (EMsgComposerAttachment *attachment) { - g_signal_emit (attachment, signals[CHANGED], 0); + gtk_signal_emit (GTK_OBJECT (attachment), signals[CHANGED]); } /* GtkObject methods. */ static void -finalise(GObject *object) +destroy (GtkObject *object) { EMsgComposerAttachment *attachment; - + attachment = E_MSG_COMPOSER_ATTACHMENT (object); - camel_object_unref (attachment->body); + camel_object_unref (CAMEL_OBJECT (attachment->body)); if (attachment->pixbuf_cache != NULL) - g_object_unref (attachment->pixbuf_cache); - - G_OBJECT_CLASS (parent_class)->finalize (object); + gdk_pixbuf_unref (attachment->pixbuf_cache); } @@ -81,6 +77,7 @@ finalise(GObject *object) static void real_changed (EMsgComposerAttachment *msg_composer_attachment) { + g_return_if_fail (msg_composer_attachment != NULL); g_return_if_fail (E_IS_MSG_COMPOSER_ATTACHMENT (msg_composer_attachment)); } @@ -88,22 +85,27 @@ real_changed (EMsgComposerAttachment *msg_composer_attachment) static void class_init (EMsgComposerAttachmentClass *klass) { - GObjectClass *object_class; - - object_class = (GObjectClass*) klass; - parent_class = g_type_class_ref (G_TYPE_OBJECT); - - object_class->finalize = finalise; + GtkObjectClass *object_class; + + object_class = (GtkObjectClass*) klass; + + parent_class = gtk_type_class (gtk_object_get_type ()); + + object_class->destroy = destroy; + + signals[CHANGED] = gtk_signal_new ("changed", + GTK_RUN_FIRST, + object_class->type, + GTK_SIGNAL_OFFSET + (EMsgComposerAttachmentClass, + changed), + gtk_marshal_NONE__NONE, + GTK_TYPE_NONE, 0); + + + gtk_object_class_add_signals (object_class, signals, LAST_SIGNAL); + klass->changed = real_changed; - - signals[CHANGED] = g_signal_new ("changed", - E_TYPE_MSG_COMPOSER_ATTACHMENT, - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (EMsgComposerAttachmentClass, changed), - NULL, - NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); } static void @@ -115,27 +117,26 @@ init (EMsgComposerAttachment *msg_composer_attachment) msg_composer_attachment->pixbuf_cache = NULL; } -GType +GtkType e_msg_composer_attachment_get_type (void) { - static GType type = 0; - + static GtkType type = 0; + if (type == 0) { - static const GTypeInfo info = { - sizeof (EMsgComposerAttachmentClass), - NULL, - NULL, - (GClassInitFunc) class_init, - NULL, - NULL, + static const GtkTypeInfo info = { + "EMsgComposerAttachment", sizeof (EMsgComposerAttachment), - 0, - (GInstanceInitFunc) init, + sizeof (EMsgComposerAttachmentClass), + (GtkClassInitFunc) class_init, + (GtkObjectInitFunc) init, + /* reserved_1 */ NULL, + /* reserved_2 */ NULL, + (GtkClassInitFunc) NULL, }; - - type = g_type_register_static (G_TYPE_OBJECT, "EMsgComposerAttachment", &info, 0); + + type = gtk_type_unique (gtk_object_get_type (), &info); } - + return type; } @@ -204,21 +205,21 @@ e_msg_composer_attachment_new (const char *file_name, } else camel_data_wrapper_set_mime_type (wrapper, "application/octet-stream"); - camel_object_unref (stream); + camel_object_unref (CAMEL_OBJECT (stream)); part = camel_mime_part_new (); camel_medium_set_content_object (CAMEL_MEDIUM (part), wrapper); - camel_object_unref (wrapper); + camel_object_unref (CAMEL_OBJECT (wrapper)); camel_mime_part_set_disposition (part, disposition); - filename = g_path_get_basename(file_name); + filename = e_utf8_from_locale_string (g_basename (file_name)); camel_mime_part_set_filename (part, filename); g_free (filename); #if 0 /* Note: Outlook 2002 is broken with respect to Content-Ids on non-multipart/related parts, so as an interoperability - workaround, don't set a Content-Id on these parts. Fixes + workwaround, don't set a Content-Id on these parts. Fixes bug #10032 */ /* set the Content-Id */ content_id = header_msgid_generate (); @@ -226,7 +227,7 @@ e_msg_composer_attachment_new (const char *file_name, g_free (content_id); #endif - new = g_object_new (E_TYPE_MSG_COMPOSER_ATTACHMENT, NULL); + new = gtk_type_new (e_msg_composer_attachment_get_type ()); new->editor_gui = NULL; new->body = part; new->size = statbuf.st_size; @@ -268,7 +269,7 @@ e_msg_composer_attachment_new_from_mime_part (CamelMimePart *part) camel_object_unref (stream); - new = g_object_new (E_TYPE_MSG_COMPOSER_ATTACHMENT, NULL); + new = gtk_type_new (e_msg_composer_attachment_get_type ()); new->editor_gui = NULL; new->body = mime_part; new->guessed_type = FALSE; @@ -280,14 +281,15 @@ e_msg_composer_attachment_new_from_mime_part (CamelMimePart *part) /* The attachment property dialog. */ -typedef struct { +struct _DialogData { GtkWidget *dialog; GtkEntry *file_name_entry; GtkEntry *description_entry; GtkEntry *mime_type_entry; GtkToggleButton *disposition_checkbox; EMsgComposerAttachment *attachment; -} DialogData; +}; +typedef struct _DialogData DialogData; static void destroy_dialog_data (DialogData *data) @@ -304,38 +306,45 @@ destroy_dialog_data (DialogData *data) static void update_mime_type (DialogData *data) { - const char *filename, *mime_type; - + const gchar *mime_type; + gchar *file_name; + if (!data->attachment->guessed_type) return; - - filename = gtk_entry_get_text (data->file_name_entry); - if (filename) { - if ((mime_type = gnome_vfs_mime_type_from_name (filename))) - gtk_entry_set_text (data->mime_type_entry, mime_type); - } + + file_name = e_utf8_gtk_entry_get_text (data->file_name_entry); + mime_type = gnome_vfs_mime_type_from_name_or_default (file_name, NULL); + g_free (file_name); + + if (mime_type) + e_utf8_gtk_entry_set_text (data->mime_type_entry, mime_type); } static void -set_entry (GladeXML *xml, const char *widget_name, const char *value) +set_entry (GladeXML *xml, + const gchar *widget_name, + const gchar *value) { GtkEntry *entry; - + entry = GTK_ENTRY (glade_xml_get_widget (xml, widget_name)); if (entry == NULL) g_warning ("Entry for `%s' not found.", widget_name); else - gtk_entry_set_text (entry, value ? value : ""); + e_utf8_gtk_entry_set_text (entry, value ? value : ""); } static void -connect_widget (GladeXML *gui, const char *name, const char *signal_name, - GCallback func, gpointer data) +connect_widget (GladeXML *gui, + const gchar *name, + const gchar *signal_name, + GtkSignalFunc func, + gpointer data) { GtkWidget *widget; - + widget = glade_xml_get_widget (gui, name); - g_signal_connect (widget, signal_name, func, data); + gtk_signal_connect (GTK_OBJECT (widget), signal_name, func, data); } static void @@ -348,10 +357,10 @@ close_cb (GtkWidget *widget, gpointer data) attachment = dialog_data->attachment; gtk_widget_destroy (dialog_data->dialog); - g_object_unref (attachment->editor_gui); + gtk_object_unref (GTK_OBJECT (attachment->editor_gui)); attachment->editor_gui = NULL; - g_object_unref (attachment); + gtk_object_unref (GTK_OBJECT (attachment)); destroy_dialog_data (dialog_data); } @@ -361,21 +370,25 @@ ok_cb (GtkWidget *widget, gpointer data) { DialogData *dialog_data; EMsgComposerAttachment *attachment; - const char *str; + char *str; dialog_data = (DialogData *) data; attachment = dialog_data->attachment; - str = gtk_entry_get_text (dialog_data->file_name_entry); + str = e_utf8_gtk_entry_get_text (dialog_data->file_name_entry); camel_mime_part_set_filename (attachment->body, str); + g_free (str); - str = gtk_entry_get_text (dialog_data->description_entry); + str = e_utf8_gtk_entry_get_text (dialog_data->description_entry); camel_mime_part_set_description (attachment->body, str); + g_free (str); - str = gtk_entry_get_text (dialog_data->mime_type_entry); + str = e_utf8_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); + camel_data_wrapper_set_mime_type ( + camel_medium_get_content_object (CAMEL_MEDIUM (attachment->body)), str); + g_free (str); switch (gtk_toggle_button_get_active (dialog_data->disposition_checkbox)) { case 0: @@ -394,7 +407,9 @@ ok_cb (GtkWidget *widget, gpointer data) } static void -file_name_focus_out_cb (GtkWidget *widget, GdkEventFocus *event, gpointer data) +file_name_focus_out_cb (GtkWidget *widget, + GdkEventFocus *event, + gpointer data) { DialogData *dialog_data; @@ -404,15 +419,15 @@ file_name_focus_out_cb (GtkWidget *widget, GdkEventFocus *event, gpointer data) void -e_msg_composer_attachment_edit (EMsgComposerAttachment *attachment, GtkWidget *parent) +e_msg_composer_attachment_edit (EMsgComposerAttachment *attachment, + GtkWidget *parent) { CamelContentType *content_type; - const char *disposition; DialogData *dialog_data; + const char *disposition; GladeXML *editor_gui; char *type; - g_return_if_fail (attachment != NULL); g_return_if_fail (E_IS_MSG_COMPOSER_ATTACHMENT (attachment)); if (attachment->editor_gui != NULL) { @@ -424,8 +439,8 @@ e_msg_composer_attachment_edit (EMsgComposerAttachment *attachment, GtkWidget *p return; } - editor_gui = glade_xml_new (EVOLUTION_GLADEDIR "/e-msg-composer-attachment.glade", - NULL, NULL); + editor_gui = glade_xml_new (E_GLADEDIR "/e-msg-composer-attachment.glade", + NULL); if (editor_gui == NULL) { g_warning ("Cannot load `e-msg-composer-attachment.glade'"); return; @@ -438,8 +453,8 @@ e_msg_composer_attachment_edit (EMsgComposerAttachment *attachment, GtkWidget *p GTK_WINDOW (gtk_widget_get_toplevel (parent))); dialog_data = g_new (DialogData, 1); - g_object_ref (attachment); dialog_data->attachment = attachment; + gtk_object_ref (GTK_OBJECT (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")); @@ -461,19 +476,18 @@ e_msg_composer_attachment_edit (EMsgComposerAttachment *attachment, GtkWidget *p disposition = camel_mime_part_get_disposition (attachment->body); gtk_toggle_button_set_active (dialog_data->disposition_checkbox, - disposition && !g_ascii_strcasecmp (disposition, "inline")); + disposition && !g_strcasecmp (disposition, "inline")); - connect_widget (editor_gui, "ok_button", "clicked", (GCallback)ok_cb, dialog_data); - connect_widget (editor_gui, "close_button", "clicked", (GCallback)close_cb, dialog_data); + connect_widget (editor_gui, "ok_button", "clicked", ok_cb, dialog_data); + connect_widget (editor_gui, "close_button", "clicked", close_cb, dialog_data); connect_widget (editor_gui, "file_name_entry", "focus_out_event", - (GCallback)file_name_focus_out_cb, dialog_data); + file_name_focus_out_cb, dialog_data); -#warning "signal connect while alive" /* make sure that when the composer 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", 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", close_cb, dialog_data, GTK_OBJECT (dialog_data->dialog)); } |