* Fixes NB#80619, do not force the width of the accounts dialog in order not to...
[modest] / src / widgets / modest-attachments-view.c
index 392263d..0a3550d 100644 (file)
@@ -46,7 +46,6 @@ static GObjectClass *parent_class = NULL;
 /* signals */
 enum {
        ACTIVATE_SIGNAL,
-       SELECTION_CHANGED_SIGNAL,
        LAST_SIGNAL
 };
 
@@ -131,8 +130,36 @@ modest_attachments_view_set_message (ModestAttachmentsView *attachments_view, Tn
         * embedded images in body */
        msg_content_type = tny_mime_part_get_content_type (TNY_MIME_PART (priv->msg));
        if ((msg_content_type != NULL) && !strcasecmp (msg_content_type, "multipart/related")) {
-               gtk_widget_queue_draw (GTK_WIDGET (attachments_view));
-               return;
+               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;
+               
+               if (!strstr (header_content_type_lower, "application/"))
+                       application_multipart = TRUE;
+               
+               g_free (header_content_type);
+               g_free (header_content_type_lower);
+               if (application_multipart) {
+                       gtk_widget_queue_draw (GTK_WIDGET (attachments_view));
+                       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);
+               if (direct_attach) {
+                       modest_attachments_view_add_attachment (attachments_view, TNY_MIME_PART (msg), TRUE, 0);
+                       gtk_widget_queue_draw (GTK_WIDGET (attachments_view));
+                       return;
+               }
        }
 
        parts = TNY_LIST (tny_simple_list_new ());
@@ -145,7 +172,7 @@ modest_attachments_view_set_message (ModestAttachmentsView *attachments_view, Tn
                part = TNY_MIME_PART (tny_iterator_get_current (iter));
 
                if (part && (modest_tny_mime_part_is_attachment_for_modest (part))) 
-                       modest_attachments_view_add_attachment (attachments_view, part);
+                       modest_attachments_view_add_attachment (attachments_view, part, TRUE, 0);
 
                if (part)
                        g_object_unref (part);
@@ -161,7 +188,8 @@ modest_attachments_view_set_message (ModestAttachmentsView *attachments_view, Tn
 }
 
 void
-modest_attachments_view_add_attachment (ModestAttachmentsView *attachments_view, TnyMimePart *part)
+modest_attachments_view_add_attachment (ModestAttachmentsView *attachments_view, TnyMimePart *part,
+                                       gboolean detect_size, guint64 size)
 {
        GtkWidget *att_view = NULL;
        ModestAttachmentsViewPrivate *priv = NULL;
@@ -171,7 +199,9 @@ modest_attachments_view_add_attachment (ModestAttachmentsView *attachments_view,
 
        priv = MODEST_ATTACHMENTS_VIEW_GET_PRIVATE (attachments_view);
 
-       att_view = modest_attachment_view_new (part);
+       att_view = modest_attachment_view_new (part, detect_size);
+       if (!detect_size)
+               modest_attachment_view_set_size (MODEST_ATTACHMENT_VIEW (att_view), size);
        gtk_box_pack_end (GTK_BOX (priv->box), att_view, FALSE, FALSE, 0);
        gtk_widget_show_all (att_view);
 }
@@ -321,15 +351,6 @@ modest_attachments_view_class_init (ModestAttachmentsViewClass *klass)
                              NULL, NULL,
                              g_cclosure_marshal_VOID__OBJECT,
                              G_TYPE_NONE, 1, G_TYPE_OBJECT);
-
-       signals[SELECTION_CHANGED_SIGNAL] =
-               g_signal_new ("selection-changed",
-                             G_TYPE_FROM_CLASS (object_class),
-                             G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
-                             G_STRUCT_OFFSET (ModestAttachmentsViewClass, selection_changed),
-                             NULL, NULL,
-                             g_cclosure_marshal_VOID__VOID,
-                             G_TYPE_NONE, 0);
        
        return;
 }
@@ -623,8 +644,6 @@ set_selected (ModestAttachmentsView *atts_view, ModestAttachmentView *att_view)
                g_object_unref (part);
        
        own_clipboard (atts_view);
-
-       g_signal_emit (G_OBJECT (atts_view), signals[SELECTION_CHANGED_SIGNAL], 0);
 }
 
 static void 
@@ -670,8 +689,6 @@ select_range (ModestAttachmentsView *atts_view, ModestAttachmentView *att1, Mode
        g_list_free (children);
        
        own_clipboard (atts_view);
-
-       g_signal_emit (G_OBJECT (atts_view), signals[SELECTION_CHANGED_SIGNAL], 0);
 }
 
 static void clipboard_get (GtkClipboard *clipboard, GtkSelectionData *selection_data,
@@ -770,8 +787,6 @@ modest_attachments_view_select_all (ModestAttachmentsView *atts_view)
        g_list_free (children);
 
        own_clipboard (atts_view);
-
-       g_signal_emit (G_OBJECT (atts_view), signals[SELECTION_CHANGED_SIGNAL], 0);
 }
 
 gboolean
@@ -791,6 +806,43 @@ modest_attachments_view_has_attachments (ModestAttachmentsView *atts_view)
        return result;
 }
 
+void
+modest_attachments_view_get_sizes (ModestAttachmentsView *attachments_view,
+                                  gint *attachments_count,
+                                  guint64 *attachments_size)
+{
+       ModestAttachmentsViewPrivate *priv;
+       GList *children, *node;
+
+       g_return_if_fail (MODEST_IS_ATTACHMENTS_VIEW (attachments_view));
+       g_return_if_fail (attachments_count != NULL && attachments_size != NULL);
+
+       *attachments_count = 0;
+       *attachments_size = 0;
+
+       priv = MODEST_ATTACHMENTS_VIEW_GET_PRIVATE (attachments_view);
+
+       children = gtk_container_get_children (GTK_CONTAINER (priv->box));
+       for (node = children; node != NULL; node = g_list_next (node)) {
+               GtkWidget *att_view = (GtkWidget *) node->data;
+               TnyMimePart *part = tny_mime_part_view_get_part (TNY_MIME_PART_VIEW (att_view));
+
+               if (!tny_mime_part_is_purged (part)) {
+                       guint64 size;
+                       (*attachments_count) ++;
+                       size = modest_attachment_view_get_size (MODEST_ATTACHMENT_VIEW (att_view));
+                       if (size == 0) {
+                               /* we do a random estimation of the size of an attachment */
+                               size = 32768;
+                       }
+                       *attachments_size += size;
+                       
+               }
+               g_object_unref (part);
+       }
+       g_list_free (children);
+}
+
 static void
 own_clipboard (ModestAttachmentsView *atts_view)
 {
@@ -810,8 +862,6 @@ focus_out_event (GtkWidget *widget, GdkEventFocus *event, ModestAttachmentsView
        if (!gtk_widget_is_focus (widget))
                unselect_all (atts_view);
 
-       g_signal_emit (G_OBJECT (atts_view), signals[SELECTION_CHANGED_SIGNAL], 0);
-
        return FALSE;
 }