diff options
Diffstat (limited to 'composer/e-msg-composer-attachment.c')
-rw-r--r-- | composer/e-msg-composer-attachment.c | 136 |
1 files changed, 67 insertions, 69 deletions
diff --git a/composer/e-msg-composer-attachment.c b/composer/e-msg-composer-attachment.c index 5903fc3928..0f7c06ff26 100644 --- a/composer/e-msg-composer-attachment.c +++ b/composer/e-msg-composer-attachment.c @@ -35,7 +35,7 @@ #include <gtk/gtktogglebutton.h> #include <camel/camel.h> #include <gal/widgets/e-unicode.h> -#include <libgnomevfs/gnome-vfs-mime.h> +#include <libgnomevfs/gnome-vfs-mime-utils.h> #include "e-msg-composer.h" #include "e-msg-composer-attachment.h" @@ -53,22 +53,24 @@ static GtkObjectClass *parent_class = NULL; static void changed (EMsgComposerAttachment *attachment) { - gtk_signal_emit (GTK_OBJECT (attachment), signals[CHANGED]); + g_signal_emit(attachment, signals[CHANGED], 0); } /* GtkObject methods. */ static void -destroy (GtkObject *object) +finalise(GObject *object) { EMsgComposerAttachment *attachment; attachment = E_MSG_COMPOSER_ATTACHMENT (object); - camel_object_unref (CAMEL_OBJECT (attachment->body)); + camel_object_unref(attachment->body); if (attachment->pixbuf_cache != NULL) - gdk_pixbuf_unref (attachment->pixbuf_cache); + g_object_unref(attachment->pixbuf_cache); + + G_OBJECT_CLASS(parent_class)->finalize(object); } @@ -85,27 +87,22 @@ real_changed (EMsgComposerAttachment *msg_composer_attachment) static void class_init (EMsgComposerAttachmentClass *klass) { - 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); + GObjectClass *object_class; + object_class = (GObjectClass*) klass; + parent_class = g_type_class_ref(G_TYPE_OBJECT); - gtk_object_class_add_signals (object_class, signals, LAST_SIGNAL); - + object_class->finalize = finalise; 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 @@ -117,24 +114,25 @@ init (EMsgComposerAttachment *msg_composer_attachment) msg_composer_attachment->pixbuf_cache = NULL; } -GtkType +GType e_msg_composer_attachment_get_type (void) { - static GtkType type = 0; + static GType type = 0; if (type == 0) { - static const GtkTypeInfo info = { - "EMsgComposerAttachment", - sizeof (EMsgComposerAttachment), + static const GTypeInfo info = { sizeof (EMsgComposerAttachmentClass), - (GtkClassInitFunc) class_init, - (GtkObjectInitFunc) init, - /* reserved_1 */ NULL, - /* reserved_2 */ NULL, - (GtkClassInitFunc) NULL, + NULL, + NULL, + (GClassInitFunc) class_init, + NULL, + NULL, + sizeof (EMsgComposerAttachment), + 0, + (GInstanceInitFunc) init, }; - type = gtk_type_unique (gtk_object_get_type (), &info); + type = g_type_register_static(G_TYPE_OBJECT, "EMsgComposerAttachment", &info, 0); } return type; @@ -161,7 +159,7 @@ e_msg_composer_attachment_new (const char *file_name, struct stat statbuf; char *mime_type; char *filename; - + g_return_val_if_fail (file_name != NULL, NULL); if (stat (file_name, &statbuf) < 0) { @@ -205,14 +203,14 @@ e_msg_composer_attachment_new (const char *file_name, } else camel_data_wrapper_set_mime_type (wrapper, "application/octet-stream"); - camel_object_unref (CAMEL_OBJECT (stream)); + camel_object_unref (stream); part = camel_mime_part_new (); camel_medium_set_content_object (CAMEL_MEDIUM (part), wrapper); - camel_object_unref (CAMEL_OBJECT (wrapper)); + camel_object_unref (wrapper); camel_mime_part_set_disposition (part, disposition); - filename = e_utf8_from_locale_string (g_basename (file_name)); + filename = g_path_get_basename(file_name); camel_mime_part_set_filename (part, filename); g_free (filename); @@ -227,7 +225,7 @@ e_msg_composer_attachment_new (const char *file_name, g_free (content_id); #endif - new = gtk_type_new (e_msg_composer_attachment_get_type ()); + new = g_object_new(E_TYPE_MSG_COMPOSER_ATTACHMENT, NULL); new->editor_gui = NULL; new->body = part; new->size = statbuf.st_size; @@ -269,7 +267,7 @@ e_msg_composer_attachment_new_from_mime_part (CamelMimePart *part) camel_object_unref (stream); - new = gtk_type_new (e_msg_composer_attachment_get_type ()); + new = g_object_new(E_TYPE_MSG_COMPOSER_ATTACHMENT, NULL); new->editor_gui = NULL; new->body = mime_part; new->guessed_type = FALSE; @@ -306,18 +304,20 @@ destroy_dialog_data (DialogData *data) static void update_mime_type (DialogData *data) { - const gchar *mime_type; - gchar *file_name; + gchar *mime_type; + const gchar *file_name; if (!data->attachment->guessed_type) return; - 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); + file_name = gtk_entry_get_text(data->file_name_entry); +#warning "do we need to create file uri for gnome-vfs-get-mime-type" + mime_type = gnome_vfs_get_mime_type (file_name); - if (mime_type) - e_utf8_gtk_entry_set_text (data->mime_type_entry, mime_type); + if (mime_type) { + gtk_entry_set_text (data->mime_type_entry, mime_type); + g_free(mime_type); + } } static void @@ -331,20 +331,20 @@ set_entry (GladeXML *xml, if (entry == NULL) g_warning ("Entry for `%s' not found.", widget_name); else - e_utf8_gtk_entry_set_text (entry, value ? value : ""); + gtk_entry_set_text (entry, value ? value : ""); } static void connect_widget (GladeXML *gui, const gchar *name, const gchar *signal_name, - GtkSignalFunc func, + GCallback func, gpointer data) { GtkWidget *widget; widget = glade_xml_get_widget (gui, name); - gtk_signal_connect (GTK_OBJECT (widget), signal_name, func, data); + g_signal_connect(widget, signal_name, func, data); } static void @@ -355,9 +355,10 @@ close_cb (GtkWidget *widget, gpointer data) dialog_data = (DialogData *) data; attachment = dialog_data->attachment; - + + /* need to unref dialog? */ gtk_widget_destroy (dialog_data->dialog); - gtk_object_unref (GTK_OBJECT (attachment->editor_gui)); + g_object_unref(attachment->editor_gui); attachment->editor_gui = NULL; destroy_dialog_data (dialog_data); @@ -368,25 +369,21 @@ ok_cb (GtkWidget *widget, gpointer data) { DialogData *dialog_data; EMsgComposerAttachment *attachment; - char *str; + const gchar *str; dialog_data = (DialogData *) data; attachment = dialog_data->attachment; - str = e_utf8_gtk_entry_get_text (dialog_data->file_name_entry); + str = gtk_entry_get_text (dialog_data->file_name_entry); camel_mime_part_set_filename (attachment->body, str); - g_free (str); - str = e_utf8_gtk_entry_get_text (dialog_data->description_entry); + str = gtk_entry_get_text (dialog_data->description_entry); camel_mime_part_set_description (attachment->body, str); - g_free (str); - str = e_utf8_gtk_entry_get_text (dialog_data->mime_type_entry); + 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); - g_free (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: @@ -436,7 +433,7 @@ e_msg_composer_attachment_edit (EMsgComposerAttachment *attachment, } editor_gui = glade_xml_new (E_GLADEDIR "/e-msg-composer-attachment.glade", - NULL); + NULL, NULL); if (editor_gui == NULL) { g_warning ("Cannot load `e-msg-composer-attachment.glade'"); return; @@ -476,19 +473,20 @@ e_msg_composer_attachment_edit (EMsgComposerAttachment *attachment, disposition = camel_mime_part_get_disposition (attachment->body); gtk_toggle_button_set_active (dialog_data->disposition_checkbox, - disposition && !g_strcasecmp (disposition, "inline")); + disposition && !g_ascii_strcasecmp (disposition, "inline")); } - 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, "ok_button", "clicked", (GCallback)ok_cb, dialog_data); + connect_widget (editor_gui, "close_button", "clicked", (GCallback)close_cb, dialog_data); connect_widget (editor_gui, "file_name_entry", "focus_out_event", - file_name_focus_out_cb, dialog_data); - + (GCallback)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", 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", close_cb, dialog_data, + gtk_signal_connect_while_alive (GTK_OBJECT (parent), "hide", (GCallback)close_cb, dialog_data, GTK_OBJECT (dialog_data->dialog)); } |