* Reworked attachments mime type detection and body detection, to work
[modest] / src / widgets / modest-attachments-view.c
index d144c37..6a17f99 100644 (file)
@@ -46,6 +46,7 @@ static GObjectClass *parent_class = NULL;
 /* signals */
 enum {
        ACTIVATE_SIGNAL,
+       DELETE_SIGNAL,
        LAST_SIGNAL
 };
 
@@ -75,7 +76,6 @@ static void set_selected (ModestAttachmentsView *atts_view, ModestAttachmentView
 static void select_range (ModestAttachmentsView *atts_view, ModestAttachmentView *att1, ModestAttachmentView *att2);
 static void clipboard_get (GtkClipboard *clipboard, GtkSelectionData *selection_data,
                           guint info, gpointer userdata);
-static void clipboard_clear (GtkClipboard *clipboard, gpointer userdata);
 static void own_clipboard (ModestAttachmentsView *atts_view);
 
 static guint signals[LAST_SIGNAL] = {0};
@@ -100,13 +100,14 @@ modest_attachments_view_new (TnyMsg *msg)
        return GTK_WIDGET (self);
 }
 
+
 void
 modest_attachments_view_set_message (ModestAttachmentsView *attachments_view, TnyMsg *msg)
 {
        ModestAttachmentsViewPrivate *priv = MODEST_ATTACHMENTS_VIEW_GET_PRIVATE (attachments_view);
        TnyList *parts;
        TnyIterator *iter;
-       const gchar *msg_content_type = NULL;
+       gchar *msg_content_type = NULL;
        
        if (msg == priv->msg) return;
 
@@ -128,20 +129,18 @@ modest_attachments_view_set_message (ModestAttachmentsView *attachments_view, Tn
 
        /* If the top mime part is a multipart/related, we don't show the attachments, as they're
         * embedded images in body */
-       msg_content_type = tny_mime_part_get_content_type (TNY_MIME_PART (priv->msg));
+       msg_content_type = modest_tny_mime_part_get_content_type (TNY_MIME_PART (priv->msg));
        if ((msg_content_type != NULL) && !strcasecmp (msg_content_type, "multipart/related")) {
                gchar *header_content_type;
-               gchar *header_content_type_lower;
                gboolean application_multipart = FALSE;
-               header_content_type = modest_tny_mime_part_get_header_value (TNY_MIME_PART (priv->msg), "Content-Type");
-               header_content_type = g_strstrip (header_content_type);
-               header_content_type_lower = (header_content_type ) ?
-                       g_ascii_strdown (header_content_type, -1) : NULL;
+
+               g_free (msg_content_type);
+
+               header_content_type = modest_tny_mime_part_get_headers_content_type (TNY_MIME_PART (priv->msg));
                
-               if ((header_content_type_lower != NULL) && 
-                   !strstr (header_content_type_lower, "application/")) {
+               if ((header_content_type != NULL) && 
+                   !strstr (header_content_type, "application/")) {
                        application_multipart = TRUE;
-                       g_free (header_content_type_lower);
                }
                g_free (header_content_type);
 
@@ -150,14 +149,14 @@ modest_attachments_view_set_message (ModestAttachmentsView *attachments_view, Tn
                        return;
                }
        } else {
-               gchar *lower;
                gboolean direct_attach;
 
-               lower = g_ascii_strdown (msg_content_type, -1);
-               direct_attach = (!g_str_has_prefix (lower, "message/rfc822") && 
-                                !g_str_has_prefix (lower, "multipart") && 
-                                !g_str_has_prefix (lower, "text/"));
-               g_free (lower);
+               direct_attach = (!g_str_has_prefix (msg_content_type, "message/rfc822") && 
+                                !g_str_has_prefix (msg_content_type, "multipart") && 
+                                !g_str_has_prefix (msg_content_type, "text/"));
+
+               g_free (msg_content_type);
+
                if (direct_attach) {
                        modest_attachments_view_add_attachment (attachments_view, TNY_MIME_PART (msg), TRUE, 0);
                        gtk_widget_queue_draw (GTK_WIDGET (attachments_view));
@@ -355,6 +354,15 @@ modest_attachments_view_class_init (ModestAttachmentsViewClass *klass)
                              g_cclosure_marshal_VOID__OBJECT,
                              G_TYPE_NONE, 1, G_TYPE_OBJECT);
        
+       signals[DELETE_SIGNAL] =
+               g_signal_new ("delete",
+                             G_TYPE_FROM_CLASS (object_class),
+                             G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
+                             G_STRUCT_OFFSET(ModestAttachmentsViewClass, delete),
+                             NULL, NULL,
+                             g_cclosure_marshal_VOID__VOID,
+                             G_TYPE_NONE, 0);
+
        return;
 }
 
@@ -419,6 +427,7 @@ button_press_event (GtkWidget *widget,
                                        priv->rubber_start = att_view;
                                        gtk_grab_add (widget);
                                }
+                               g_object_unref (mime_part);
                        }
                }
        }
@@ -505,6 +514,7 @@ find_prev_or_next_not_purged (GList *list, gboolean prev, gboolean include_this)
                                tmp = g_list_next (tmp);
                        is_valid = FALSE;
                }
+               g_object_unref (mime_part);
        } while (!is_valid && tmp);
 
        return tmp;
@@ -609,6 +619,11 @@ key_press_event (GtkWidget *widget,
                return TRUE;
        }
 
+       if (event->keyval == GDK_BackSpace) {
+               g_signal_emit (G_OBJECT (widget), signals[DELETE_SIGNAL], 0);
+               return TRUE;
+       }
+
        /* Activates selected item */
        if (g_list_length (priv->selected) == 1) {
                ModestAttachmentView *att_view = (ModestAttachmentView *) priv->selected->data;
@@ -773,13 +788,6 @@ static void clipboard_get (GtkClipboard *clipboard, GtkSelectionData *selection_
        }
 }
 
-static void clipboard_clear (GtkClipboard *clipboard, gpointer userdata)
-{
-       ModestAttachmentsView *atts_view = (ModestAttachmentsView *) userdata;
-
-       unselect_all (atts_view);
-}
-
 TnyList *
 modest_attachments_view_get_selection (ModestAttachmentsView *atts_view)
 {
@@ -847,6 +855,7 @@ modest_attachments_view_select_all (ModestAttachmentsView *atts_view)
                        gtk_widget_set_state (GTK_WIDGET (node->data), GTK_STATE_SELECTED);
                        priv->selected = g_list_append (priv->selected, node->data);
                }
+               g_object_unref (mime_part);
        }
        g_list_free (children);
 
@@ -916,7 +925,7 @@ own_clipboard (ModestAttachmentsView *atts_view)
 
        gtk_clipboard_set_with_owner (gtk_widget_get_clipboard (GTK_WIDGET (atts_view), GDK_SELECTION_PRIMARY),
                                      targets, G_N_ELEMENTS (targets),
-                                     clipboard_get, clipboard_clear, G_OBJECT(atts_view));
+                                     clipboard_get, NULL, G_OBJECT(atts_view));
                              
 }