diff options
author | Dan Winship <danw@src.gnome.org> | 2000-06-06 05:14:32 +0800 |
---|---|---|
committer | Dan Winship <danw@src.gnome.org> | 2000-06-06 05:14:32 +0800 |
commit | 5ec9e5b2287aef03893e0ce310013c99fe1dce4d (patch) | |
tree | dc296b5a1c41c4424aa0585f76b0b9d7672d227e /composer/e-msg-composer-attachment-bar.c | |
parent | 4a85bdfa85217a08bf415e2dcb3a688bf0254d71 (diff) | |
download | gsoc2013-evolution-5ec9e5b2287aef03893e0ce310013c99fe1dce4d.tar gsoc2013-evolution-5ec9e5b2287aef03893e0ce310013c99fe1dce4d.tar.gz gsoc2013-evolution-5ec9e5b2287aef03893e0ce310013c99fe1dce4d.tar.bz2 gsoc2013-evolution-5ec9e5b2287aef03893e0ce310013c99fe1dce4d.tar.lz gsoc2013-evolution-5ec9e5b2287aef03893e0ce310013c99fe1dce4d.tar.xz gsoc2013-evolution-5ec9e5b2287aef03893e0ce310013c99fe1dce4d.tar.zst gsoc2013-evolution-5ec9e5b2287aef03893e0ce310013c99fe1dce4d.zip |
New convenience function.
* e-msg-composer.c (e_msg_composer_attach): New convenience
function.
* e-msg-composer-attachment.c: Store a CamelMimePart rather than
filename/description/mime_type info. Also record whether we were
told or guessed the MIME type.
(e_msg_composer_attachment_new_from_mime_part): New constructor.
(e_msg_composer_attachment_edit): Remove the "browse" button. (If
the user wants to change the actual file that the attachment is
based on, he should delete the attachment and create a new one...)
Remove the "Apply" button, because it's not all that useful. Make
the MIME type only track the filename if it was guessed rather
than being provided.
* e-msg-composer-attachment.glade: Remove "browse" and "apply"
buttons. Make filename editable.
* e-msg-composer-attachment-bar.c (sort): Removed. Send the
attachments in the order the user attached them in.
(text_changed): Removed, since we weren't enabling the relevant
GnomeIconList functionality that would have used this.
(update): Don't print the size if it's 0.
(attach_to_multipart, etc): adjust for EMsgComposerAttachment
changes.
(attach_to_multipart): Use 7bit encoding for message/ subparts.
(e_msg_composer_attachment_bar_attach_mime_part): New convenience
function.
svn path=/trunk/; revision=3430
Diffstat (limited to 'composer/e-msg-composer-attachment-bar.c')
-rw-r--r-- | composer/e-msg-composer-attachment-bar.c | 160 |
1 files changed, 57 insertions, 103 deletions
diff --git a/composer/e-msg-composer-attachment-bar.c b/composer/e-msg-composer-attachment-bar.c index 5041164d9b..d6749f72c4 100644 --- a/composer/e-msg-composer-attachment-bar.c +++ b/composer/e-msg-composer-attachment-bar.c @@ -98,32 +98,6 @@ size_to_string (gulong size) return size_string; } - -/* Sorting. */ - -static gint -attachment_sort_func (gconstpointer a, gconstpointer b) -{ - const EMsgComposerAttachment *attachment_a, *attachment_b; - - attachment_a = (EMsgComposerAttachment *) a; - attachment_b = (EMsgComposerAttachment *) b; - - return strcmp (attachment_a->description, attachment_b->description); -} - -static void -sort (EMsgComposerAttachmentBar *bar) -{ - EMsgComposerAttachmentBarPrivate *priv; - - priv = bar->priv; - - priv->attachments = g_list_sort (priv->attachments, - attachment_sort_func); -} - - /* Attachment handling functions. */ static void @@ -146,13 +120,9 @@ attachment_changed_cb (EMsgComposerAttachment *attachment, } static void -add_from_file (EMsgComposerAttachmentBar *bar, - const gchar *file_name) +add_common (EMsgComposerAttachmentBar *bar, + EMsgComposerAttachment *attachment) { - EMsgComposerAttachment *attachment; - - attachment = e_msg_composer_attachment_new (file_name); - gtk_signal_connect (GTK_OBJECT (attachment), "changed", GTK_SIGNAL_FUNC (attachment_changed_cb), bar); @@ -161,13 +131,26 @@ add_from_file (EMsgComposerAttachmentBar *bar, attachment); bar->priv->num_attachments++; - sort (bar); update (bar); gtk_signal_emit (GTK_OBJECT (bar), signals[CHANGED]); } static void +add_from_mime_part (EMsgComposerAttachmentBar *bar, + CamelMimePart *part) +{ + add_common (bar, e_msg_composer_attachment_new_from_mime_part (part)); +} + +static void +add_from_file (EMsgComposerAttachmentBar *bar, + const gchar *file_name) +{ + add_common (bar, e_msg_composer_attachment_new (file_name)); +} + +static void remove_attachment (EMsgComposerAttachmentBar *bar, EMsgComposerAttachment *attachment) { @@ -201,30 +184,37 @@ update (EMsgComposerAttachmentBar *bar) for (p = priv->attachments; p != NULL; p = p->next) { EMsgComposerAttachment *attachment; - const gchar *icon_name; - gchar *size_string; - gchar *label; + const gchar *icon_name, *desc; + gchar *size_string, *label, *mime_type; + GMimeContentField *content_type; attachment = p->data; - icon_name = gnome_mime_get_value (attachment->mime_type, - "icon-filename"); + content_type = camel_mime_part_get_content_type (attachment->body); + mime_type = g_strdup_printf ("%s/%s", content_type->type, + content_type->subtype); + icon_name = gnome_mime_get_value (mime_type, "icon-filename"); + g_free (mime_type); /* FIXME we need some better default icon. */ if (icon_name == NULL) icon_name = gnome_mime_get_value ("text/plain", "icon-filename"); - size_string = size_to_string (attachment->size); + desc = camel_mime_part_get_description (attachment->body); + if (!desc) + desc = camel_mime_part_get_filename (attachment->body); + if (!desc) + desc = "attachment"; - /* FIXME: If GnomeIconList honoured "\n", the result would be a - lot better. */ - label = g_strconcat (attachment->description, "\n(", - size_string, ")", NULL); + if (attachment->size) { + size_string = size_to_string (attachment->size); + label = g_strdup_printf ("%s (%s)", desc, size_string); + g_free (size_string); + } else + label = g_strdup (desc); gnome_icon_list_append (icon_list, icon_name, label); - g_free (label); - g_free (size_string); } gnome_icon_list_thaw (icon_list); @@ -469,28 +459,6 @@ button_press_event (GtkWidget *widget, } -/* GnomeIconList methods. */ - -static gboolean -text_changed (GnomeIconList *gil, - gint num, - const gchar *new_text) -{ - EMsgComposerAttachmentBar *bar; - EMsgComposerAttachment *attachment; - GList *p; - - bar = E_MSG_COMPOSER_ATTACHMENT_BAR (gil); - p = g_list_nth (bar->priv->attachments, num); - attachment = p->data; - - g_free (attachment->description); - attachment->description = g_strdup (new_text); - - return TRUE; -} - - /* Initialization. */ static void @@ -510,8 +478,6 @@ class_init (EMsgComposerAttachmentBarClass *class) widget_class->button_press_event = button_press_event; - icon_list_class->text_changed = text_changed; - /* Setup signals. */ signals[CHANGED] = @@ -605,43 +571,23 @@ static void attach_to_multipart (CamelMultipart *multipart, EMsgComposerAttachment *attachment) { - CamelMimePart *part; - struct stat st; - int fd; - char *data; - - part = camel_mime_part_new (); - fd = open (attachment->file_name, O_RDONLY); - if (fd != -1 && fstat (fd, &st) != -1) { - data = g_malloc (st.st_size); - read (fd, data, st.st_size); - close (fd); - - camel_mime_part_set_content (part, data, st.st_size, - attachment->mime_type); - } else { - g_warning ("couldn't open %s", attachment->file_name); - gtk_object_sink (GTK_OBJECT (part)); - return; - } + GMimeContentField *content_type; - camel_mime_part_set_disposition (part, "attachment"); - camel_mime_part_set_filename (part, - g_basename (attachment->file_name)); - camel_mime_part_set_description (part, attachment->description); + content_type = camel_mime_part_get_content_type (attachment->body); - /* Kludge a bit on CTE. For now, we set QP for text/ and message/ - * and B64 for all else. FIXME. + /* Kludge a bit on CTE. For now, we set QP for text and B64 + * for all else except message (which must be 7bit, 8bit, or + * binary). FIXME. */ + if (!strcasecmp (content_type->type, "text")) { + camel_mime_part_set_encoding (attachment->body, + CAMEL_MIME_PART_ENCODING_QUOTEDPRINTABLE); + } else if (strcasecmp (content_type->type, "message") != 0) { + camel_mime_part_set_encoding (attachment->body, + CAMEL_MIME_PART_ENCODING_BASE64); + } - if (!strncasecmp (attachment->mime_type, "text/", 5) || - !strncasecmp (attachment->mime_type, "message/", 8)) - camel_mime_part_set_encoding (part, CAMEL_MIME_PART_ENCODING_QUOTEDPRINTABLE); - else - camel_mime_part_set_encoding (part, CAMEL_MIME_PART_ENCODING_BASE64); - - camel_multipart_add_part (multipart, part); - gtk_object_unref (GTK_OBJECT (part)); + camel_multipart_add_part (multipart, attachment->body); } void @@ -681,7 +627,6 @@ void e_msg_composer_attachment_bar_attach (EMsgComposerAttachmentBar *bar, const gchar *file_name) { - g_return_if_fail (bar != NULL); g_return_if_fail (E_IS_MSG_COMPOSER_ATTACHMENT_BAR (bar)); if (file_name == NULL) @@ -689,3 +634,12 @@ e_msg_composer_attachment_bar_attach (EMsgComposerAttachmentBar *bar, else add_from_file (bar, file_name); } + +void +e_msg_composer_attachment_bar_attach_mime_part (EMsgComposerAttachmentBar *bar, + CamelMimePart *part) +{ + g_return_if_fail (E_IS_MSG_COMPOSER_ATTACHMENT_BAR (bar)); + + add_from_mime_part (bar, part); +} |