/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ /* e-msg-composer-attachment.c * * Copyright (C) 1999 Helix Code, Inc. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. * * Author: Ettore Perazzoli */ /* This is the object representing an email attachment. It is implemented as a 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 #include #include #include "e-msg-composer-attachment.h" enum { CHANGED, LAST_SIGNAL }; static guint signals[LAST_SIGNAL] = { 0 }; static GtkObjectClass *parent_class = NULL; /* Utility functions. */ static const gchar * get_mime_type (const gchar *file_name) { const gchar *mime_type; mime_type = gnome_mime_type_of_file (file_name); if (mime_type == NULL) mime_type = "application/octet-stream"; return mime_type; } static void changed (EMsgComposerAttachment *attachment) { gtk_signal_emit (GTK_OBJECT (attachment), signals[CHANGED]); } /* GtkObject methods. */ static void destroy (GtkObject *object) { EMsgComposerAttachment *attachment; attachment = E_MSG_COMPOSER_ATTACHMENT (object); gtk_object_unref (GTK_OBJECT (attachment->body)); } /* Signals. */ 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)); } 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); gtk_object_class_add_signals (object_class, signals, LAST_SIGNAL); klass->changed = real_changed; } static void init (EMsgComposerAttachment *msg_composer_attachment) { msg_composer_attachment->editor_gui = NULL; msg_composer_attachment->body = NULL; msg_composer_attachment->size = 0; } GtkType e_msg_composer_attachment_get_type (void) { static GtkType type = 0; if (type == 0) { static const GtkTypeInfo info = { "EMsgComposerAttachment", sizeof (EMsgComposerAttachment), sizeof (EMsgComposerAttachmentClass), (GtkClassInitFunc) class_init, (GtkObjectInitFunc) init, /* reserved_1 */ NULL, /* reserved_2 */ NULL, (GtkClassInitFunc) NULL, }; type = gtk_type_unique (gtk_object_get_type (), &info); } return type; } /** * e_msg_composer_attachment_new: * @file_name: * * Return value: **/ EMsgComposerAttachment * e_msg_composer_attachment_new (const gchar *file_name) { EMsgComposerAttachment *new; CamelMimePart *part; CamelDataWrapper *wrapper; CamelStream *data; struct stat statbuf; g_return_val_if_fail (file_name != NULL, NULL); data = camel_stream_fs_new_with_name (file_name, O_RDONLY, 0); if (!data) return NULL; wrapper = camel_data_wrapper_new (); camel_data_wrapper_construct_from_stream (wrapper, data); gtk_object_unref (GTK_OBJECT (data)); camel_data_wrapper_set_mime_type (wrapper, get_mime_type (file_name)); part = camel_mime_part_new (); camel_medium_set_content_object (CAMEL_MEDIUM (part), wrapper); gtk_object_unref (GTK_OBJECT (wrapper)); camel_mime_part_set_disposition (part, "attachment"); if (strchr (file_name, '/')) camel_mime_part_set_filename (part, strrchr (file_name, '/') + 1); else camel_mime_part_set_filename (part, file_name); new = e_msg_composer_attachment_new_from_mime_part (part); if (stat (file_name, &statbuf) < 0) new->size = 0; else new->size = statbuf.st_size; new->guessed_type = TRUE; return new; } /** * e_msg_composer_attachment_new_from_mime_part: * @part: a CamelMimePart * * Return value: a new EMsgComposerAttachment based on the mime part **/ EMsgComposerAttachment * e_msg_composer_attachment_new_from_mime_part (CamelMimePart *part) { EMsgComposerAttachment *new; g_return_val_if_fail (CAMEL_IS_MIME_PART (part), NULL); new = gtk_type_new (e_msg_composer_attachment_get_type ()); new->editor_gui = NULL; new->body = part; gtk_object_ref (GTK_OBJECT (part)); new->guessed_type = FALSE; new->size = 0; return new; } /* The attachment property dialog. */ struct _DialogData { GtkWidget *dialog; GtkEntry *file_name_entry; GtkEntry *description_entry; GtkEntry *mime_type_entry; EMsgComposerAttachment *attachment; }; typedef struct _DialogData DialogData; static void destroy_dialog_data (DialogData *data) { g_free (data); } static void update_mime_type (DialogData *data) { const gchar *mime_type; const gchar *file_name; if (!data->attachment->guessed_type) return; file_name = gtk_entry_get_text (data->file_name_entry); mime_type = get_mime_type (file_name); gtk_entry_set_text (data->mime_type_entry, mime_type); } static void 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); gtk_entry_set_text (entry, value ? value : ""); } static void connect_widget (GladeXML *gui, const gchar *name, const gchar *signal_name, GtkSignalFunc func, gpointer data) { GtkWidget *widget; widget = glade_xml_get_widget (gui, name); gtk_signal_connect (GTK_OBJECT (widget), signal_name, func, data); } static void close_cb (GtkWidget *widget, gpointer data) { EMsgComposerAttachment *attachment; DialogData *dialog_data; dialog_data = (DialogData *) data; attachment = dialog_data->attachment; gtk_widget_destroy (glade_xml_get_widget (attachment->editor_gui, "dialog")); gtk_object_unref (GTK_OBJECT (attachment->editor_gui)); attachment->editor_gui = NULL; destroy_dialog_data (dialog_data); } static void ok_cb (GtkWidget *widget, gpointer data) { DialogData *dialog_data; EMsgComposerAttachment *attachment; dialog_data = (DialogData *) data; attachment = dialog_data->attachment; camel_mime_part_set_filename (attachment->body, gtk_entry_get_text (dialog_data->file_name_entry)); camel_mime_part_set_description (attachment->body, gtk_entry_get_text (dialog_data->description_entry)); camel_mime_part_set_content_type (attachment->body, gtk_entry_get_text (dialog_data->mime_type_entry)); camel_data_wrapper_set_mime_type ( camel_medium_get_content_object (CAMEL_MEDIUM (attachment->body)), gtk_entry_get_text (dialog_data->mime_type_entry)); changed (attachment); close_cb (widget, data); } static void file_name_focus_out_cb (GtkWidget *widget, GdkEventFocus *event, gpointer data) { DialogData *dialog_data; dialog_data = (DialogData *) data; update_mime_type (dialog_data); } void e_msg_composer_attachment_edit (EMsgComposerAttachment *attachment, GtkWidget *parent) { DialogData *dialog_data; GladeXML *editor_gui; g_return_if_fail (attachment != NULL); g_return_if_fail (E_IS_MSG_COMPOSER_ATTACHMENT (attachment)); if (attachment->editor_gui != NULL) { GtkWidget *window; window = glade_xml_get_widget (attachment->editor_gui, "dialog"); gdk_window_show (window->window); return; } 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; } 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))); dialog_data = g_new (DialogData, 1); 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")); if (attachment != NULL) { GMimeContentField *content_type; char *type; 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 = g_strdup_printf ("%s/%s", content_type->type, content_type->subtype); set_entry (editor_gui, "mime_type_entry", type); g_free (type); } 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", file_name_focus_out_cb, dialog_data); } +0800'>2006-05-161-0/+1 * Remove USE_REINPLACE from categories starting with Xedwin2006-05-131-1/+0 * - Add gtk20-reference.jylefort2006-05-101-3/+20 * Update to 2.8.17.marcus2006-04-083-4/+12 * Update to 2.8.16.marcus2006-03-162-4/+4 * Update to 2.8.15.marcus2006-03-154-17/+16 * Conversion to a single libtool environment.ade2006-02-232-1/+56 * Add WITHOUT_DEBUG to support more standard flag, same behavior as withmezz2006-02-211-3/+3 * - Update to 2.8.12ahze2006-02-122-4/+4 * Update to 2.8.11bland2006-01-283-4/+8 * Replace ugly "@unexec rmdir %D... 2>/dev/null || true" with @dirrmtryedwin2006-01-221-28/+28 * - Update to 2.8.10ahze2006-01-122-4/+4 * Update to 2.8.9.marcus2005-12-102-4/+4 * Update to 2.8.8.marcus2005-11-293-23/+4 * We no longer need to touch the icon-theme.cache now that gnome-icon-thememarcus2005-11-212-4/+1 * Reliably detect if icon-theme.cache is uptodate, by checking the mtimejylefort2005-11-202-1/+50 * * Use X11BASE rather than PREFIX or %D to search for iconsmarcus2005-11-192-3/+7 * - Fix build on FreeBSD 4.Xpav2005-11-161-0/+18 * Update to 2.8.7.marcus2005-11-162-4/+4 * Fix the file chooser in gtk-demo.jylefort2005-11-081-0/+5 * Presenting GNOME 2.12 for FreeBSD. The release is chock full of bug fixesmarcus2005-11-058-99/+76 * Unbreak 4-STABLE build (gcc 2.95.x does not know anything about SSE2).bland2005-09-031-1/+2 * There is a SSE2 bug in either GCC or in our libc, when use p4, p-m or elsemezz2005-09-031-1/+12 * Update to 2.6.10.marcus2005-08-282-3/+3 * Re-add drop shadow patch distinfo after recent update.marcus2005-08-021-0/+2 * Update to 2.6.9.marcus2005-08-023-5/+7 * Add -g in CFLAGS and STRIP= #empty when use WITH_DEBUG knob.mezz2005-07-181-0/+2 * - Update to 2.6.8ahze2005-06-163-3/+5 * Add a few brief comments about what it means to set WITH_DEBUG to variousadamw2005-04-131-0/+6 * Update to 2.6.7.marcus2005-04-132-3/+3 * - Add WITH_DEBUG knob that has the following turnables [no|minimum|yes]ahze2005-04-131-0/+20 * - Update to 2.6.6ahze2005-04-113-45/+3 * Fix missing icons bug (bug #169870).bland2005-04-102-0/+42 * - Update to 2.6.5bland2005-04-093-7/+6 * Presenting GNOME 2.10 for FreeBSD!marcus2005-03-1211-102/+107 * Remove another non-system locale directory.kris2004-12-231-0/+2 * Update a link in MASTER_SITES for 2.3 -> 2.4.mezz2004-12-201-1/+1 * Don't remove system locale directories (not listed in the relevantkris2004-12-201-2/+0 * Clean up the pkg-plist voodoo:mezz2004-12-202-7/+11 * Correct the removal of the ${PREFIX}/lib/gtk-2.0/modules directory.marcus2004-12-201-1/+1 * Clean up handling of locale directories at deinstall-time:kris2004-12-161-0/+20 * Create an empty lib/gtk-2.0/modules directory to be used by other ports.marcus2004-12-132-0/+6 * Update to 2.4.14bland2004-12-033-3/+5 * This port really need gmake.marcus2004-11-121-0/+1 * Presenting GNOME 2.8 for FreeBSD (2.8.1 to be exact).marcus2004-11-084-104/+7 * Fix recent XPM buffer overflows as described atmarcus2004-09-172-0/+101 * Update to 2.4.9. This is just a quick fix release that prettyadamw2004-08-263-14/+3 * Update to 2.4.8.marcus2004-08-264-3/+16 * mirror.ac.uk -> mirrorservice.orgvs2004-08-191-1/+1 * Update to 2.4.7 which has the fix for the FileSelector bug as well asmarcus2004-08-153-73/+3 * Fix a bug in GtkFileChooser which prevent files to be opened.bland2004-08-152-0/+70 * Update to 2.4.6bland2004-08-143-4/+5 * Use new libtool scheme.mezz2004-08-092-52/+1 * Sync the MIME search directories from gnome-vfs. This fixes somemarcus2004-08-052-1/+2 * Update to 2.4.4bland2004-07-102-4/+3 * Add support for a mime database in ${X11BASE} as well as ${LOCALBASE}.marcus2004-06-262-1/+14 * Sort plist.bland2004-06-121-13/+13 * Update to 2.4.3.marcus2004-06-122-3/+3 * - Readd distinfo for dropshadow patchpav2004-06-051-0/+2 * Update to 2.4.2.marcus2004-06-053-5/+5 * Reword some of the dropshadow patch warning message text stuff thingers.adamw2004-05-071-2/+3 * Add experimental WITH_DROPSHADOW option back in; it is not supported bymezz2004-05-062-0/+19 * Update to 2.4.1.marcus2004-05-013-3/+12 * Presenting GNOME 2.6.0. The FreeBSD GNOME Team feels this our best releasemarcus2004-04-0512-117/+275 * Add the drop-shadow patch distinfo data back.marcus2004-03-191-0/+2 * - Add SIZE to GNOME portspav2004-03-181-1/+1 * Fix some build issues with the new freetype2.marcus2004-03-171-3/+13 * Whoa there, boy, that's a mighty big commit y'all have there...ade2004-03-141-1/+1 * Bump PORTREVISION on all ports that depend on gettext to aid with upgrading.marcus2004-02-041-1/+1 * Due popular demand and weeling of gnome@ to deliver more eye candybland2003-11-022-0/+18 * Correct some obsolete MASTER_SITESmarcus2003-10-061-1/+1 * * Fix l10n bug with the locale directory [1]marcus2003-09-251-4/+7 * Update to 2.2.4.adamw2003-09-053-2/+3 * Remove a patch forgotten in the last commit.marcus2003-08-271-0/+0 * Update to 2.2.3.marcus2003-08-274-15/+6 * Add a patch from gtk+ CVS that fixes the corrupt thumbnails inmarcus2003-08-152-0/+13 * * Update to 2.2.2marcus2003-06-113-10/+7 * Link executables with -pthread so that they can work with threaded librariesmarcus2003-05-033-3/+25 * Convert to new GNOME infrastructure.marcus2003-04-221-5/+2 * Remove USE_GNOMENG.marcus2003-04-211-1/+0