Fixes NB#114785, fixes a crash when removing attachments.
[modest] / src / widgets / modest-attachments-view.c
index 2e717eb..a269d4f 100644 (file)
@@ -40,6 +40,7 @@
 #include <modest-attachment-view.h>
 #include <modest-attachments-view.h>
 #include <modest-tny-mime-part.h>
+#include <modest-tny-msg.h>
 
 static GObjectClass *parent_class = NULL;
 
@@ -129,39 +130,9 @@ modest_attachments_view_set_message (ModestAttachmentsView *attachments_view, Tn
                return;
        }
 
-       msg_content_type = modest_tny_mime_part_get_content_type (TNY_MIME_PART (priv->msg));
-       /* If the top mime part is a multipart/signed, we have to work with its first child (if available)
-        * as "message" for showing attachments */
-
-       part_to_check = NULL;
-       if ((msg_content_type != NULL) && !strcasecmp (msg_content_type, "multipart/signed")) {
-               TnyList *msg_children;
-               guint length;
-
-               msg_children = TNY_LIST (tny_simple_list_new ());
-               tny_mime_part_get_parts (TNY_MIME_PART (priv->msg), msg_children);
-
-               length = tny_list_get_length (msg_children);
-               if (length == 1 || length == 2) {
-                       TnyIterator *iterator;
-
-                       iterator = tny_list_create_iterator (msg_children);
-
-                       part_to_check = TNY_MIME_PART (tny_iterator_get_current (iterator));
-
-                       g_object_unref (iterator);
-               }
-
-               g_object_unref (msg_children);
-
-       }
-
-       if (part_to_check == NULL) {
-               part_to_check = g_object_ref (priv->msg);
-       } else {
-               msg_content_type = modest_tny_mime_part_get_content_type (TNY_MIME_PART (part_to_check));
-       }
+       part_to_check = modest_tny_msg_get_attachments_parent (TNY_MSG (msg));
 
+       msg_content_type = modest_tny_mime_part_get_content_type (TNY_MIME_PART (part_to_check));
 
        /* If the top mime part is a multipart/related, we don't show the attachments, as they're
         * embedded images in body */
@@ -964,7 +935,6 @@ modest_attachments_view_get_sizes (ModestAttachmentsView *attachments_view,
                                size = 32768;
                        }
                        *attachments_size += size;
-                       
                }
                g_object_unref (part);
        }
@@ -972,6 +942,13 @@ modest_attachments_view_get_sizes (ModestAttachmentsView *attachments_view,
 }
 
 static void
+dummy_clear_func (GtkClipboard *clipboard,
+                 gpointer user_data_or_owner)
+{
+       /* Do nothing */
+}
+
+static void
 own_clipboard (ModestAttachmentsView *atts_view)
 {
        GtkTargetEntry targets[] = {
@@ -980,8 +957,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, NULL, G_OBJECT(atts_view));
-                             
+                                     clipboard_get, dummy_clear_func, G_OBJECT(atts_view));
 }
 
 static gboolean 
@@ -1035,3 +1011,20 @@ modest_attachments_view_set_style (ModestAttachmentsView *self,
 
        }
 }
+
+guint
+modest_attachments_view_get_num_attachments (ModestAttachmentsView *atts_view)
+{
+       ModestAttachmentsViewPrivate *priv;
+       GList *children;
+       gint result;
+
+       g_return_val_if_fail (MODEST_IS_ATTACHMENTS_VIEW (atts_view), 0);
+       priv = MODEST_ATTACHMENTS_VIEW_GET_PRIVATE (atts_view);
+
+       children = gtk_container_get_children (GTK_CONTAINER (priv->box));
+       result = g_list_length (children);
+       g_list_free (children);
+
+       return result;
+}