#include <config.h>
-//#include <glib/gi18n-lib.h>
-
#include <string.h>
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
#include <modest-runtime.h>
#include <modest-attachment-view.h>
#include <modest-attachments-view.h>
+#include <modest-tny-mime-part.h>
static GObjectClass *parent_class = NULL;
return;
}
-
parts = TNY_LIST (tny_simple_list_new ());
tny_mime_part_get_parts (TNY_MIME_PART (priv->msg), parts);
iter = tny_list_create_iterator (parts);
TnyMimePart *part;
part = TNY_MIME_PART (tny_iterator_get_current (iter));
- if (part && (tny_mime_part_is_attachment (part) || TNY_IS_MSG (part))) {
- modest_attachments_view_add_attachment (attachments_view, part);
- }
+
+ if (part && (modest_tny_mime_part_is_attachment_for_modest (part)))
+ modest_attachments_view_add_attachment (attachments_view, part, TRUE, 0);
if (part)
g_object_unref (part);
tny_iterator_next (iter);
}
+ g_object_unref (iter);
+ g_object_unref (parts);
+
gtk_widget_queue_draw (GTK_WIDGET (attachments_view));
}
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;
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);
}
unselect_all (atts_view);
}
-GList *
+TnyList *
modest_attachments_view_get_selection (ModestAttachmentsView *atts_view)
{
ModestAttachmentsViewPrivate *priv;
- GList *selection, *node;
+ TnyList *selection;
+ GList *node;
g_return_val_if_fail (MODEST_IS_ATTACHMENTS_VIEW (atts_view), NULL);
priv = MODEST_ATTACHMENTS_VIEW_GET_PRIVATE (atts_view);
- selection = NULL;
+ selection = tny_simple_list_new ();
for (node = priv->selected; node != NULL; node = g_list_next (node)) {
ModestAttachmentView *att_view = (ModestAttachmentView *) node->data;
TnyMimePart *part = tny_mime_part_view_get_part (TNY_MIME_PART_VIEW (att_view));
- selection = g_list_append (selection, part);
+ tny_list_append (selection, (GObject *) part);
+ g_object_unref (part);
}
return selection;
}
-GList *
+TnyList *
modest_attachments_view_get_attachments (ModestAttachmentsView *atts_view)
{
ModestAttachmentsViewPrivate *priv;
- GList *children, *node, *att_list = NULL;
+ TnyList *att_list;
+ GList *children, *node= NULL;
g_return_val_if_fail (MODEST_IS_ATTACHMENTS_VIEW (atts_view), NULL);
priv = MODEST_ATTACHMENTS_VIEW_GET_PRIVATE (atts_view);
+ att_list = TNY_LIST (tny_simple_list_new ());
+
children = gtk_container_get_children (GTK_CONTAINER (priv->box));
for (node = children; node != NULL; node = g_list_next (node)) {
GtkWidget *att_view = GTK_WIDGET (node->data);
TnyMimePart *mime_part = tny_mime_part_view_get_part (TNY_MIME_PART_VIEW (att_view));
- att_list = g_list_prepend (att_list, mime_part);
+ tny_list_append (att_list, (GObject *) mime_part);
+ g_object_unref (mime_part);
}
g_list_free (children);
- att_list = g_list_reverse (att_list);
return att_list;
}
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)
{