X-Git-Url: http://git.maemo.org/git/?a=blobdiff_plain;f=src%2Fwidgets%2Fmodest-attachments-view.c;h=b52b543b6edfeda75df89bb0ea7acc61b045d933;hb=61bbe9ed9335ddcc1957bf8c3158975139c794a7;hp=557fc8831994b35add91dd766f78177c3fd0e6ac;hpb=20f40360ad626eb860e7d106e5dcfd43a59d21d4;p=modest diff --git a/src/widgets/modest-attachments-view.c b/src/widgets/modest-attachments-view.c index 557fc88..b52b543 100644 --- a/src/widgets/modest-attachments-view.c +++ b/src/widgets/modest-attachments-view.c @@ -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,10 +129,39 @@ 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")) { - gtk_widget_queue_draw (GTK_WIDGET (attachments_view)); - return; + gchar *header_content_type; + gboolean application_multipart = FALSE; + + 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 != NULL) && + !strstr (header_content_type, "application/")) { + application_multipart = TRUE; + } + g_free (header_content_type); + + if (application_multipart) { + gtk_widget_queue_draw (GTK_WIDGET (attachments_view)); + return; + } + } else { + gboolean direct_attach; + + 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)); + return; + } } parts = TNY_LIST (tny_simple_list_new ()); @@ -176,6 +206,7 @@ modest_attachments_view_add_attachment (ModestAttachmentsView *attachments_view, 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); + gtk_widget_queue_resize (GTK_WIDGET (attachments_view)); } void @@ -227,6 +258,7 @@ modest_attachments_view_remove_attachment (ModestAttachmentsView *atts_view, Tny own_clipboard (atts_view); } + gtk_widget_queue_resize (GTK_WIDGET (atts_view)); } void @@ -257,6 +289,7 @@ modest_attachments_view_remove_attachment_by_id (ModestAttachmentsView *atts_vie own_clipboard (atts_view); + gtk_widget_queue_resize (GTK_WIDGET (atts_view)); } static void @@ -324,6 +357,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; } @@ -380,9 +422,15 @@ button_press_event (GtkWidget *widget, g_object_unref (mime_part); } } else { - set_selected (MODEST_ATTACHMENTS_VIEW (widget), MODEST_ATTACHMENT_VIEW (att_view)); - priv->rubber_start = att_view; - gtk_grab_add (widget); + TnyMimePart *mime_part = tny_mime_part_view_get_part (TNY_MIME_PART_VIEW (att_view)); + + /* Do not select purged attachments */ + if (TNY_IS_MIME_PART (mime_part) && !tny_mime_part_is_purged (mime_part)) { + set_selected (MODEST_ATTACHMENTS_VIEW (widget), MODEST_ATTACHMENT_VIEW (att_view)); + priv->rubber_start = att_view; + gtk_grab_add (widget); + } + g_object_unref (mime_part); } } } @@ -436,6 +484,46 @@ motion_notify_event (GtkWidget *widget, return TRUE; } +static GList* +find_prev_or_next_not_purged (GList *list, gboolean prev, gboolean include_this) +{ + GList *tmp = NULL; + gboolean is_valid; + + if (!include_this) { + if (prev) { + tmp = g_list_previous (list); + } else { + tmp = g_list_next (list); + } + } else { + tmp = list; + } + + if (!tmp) + return NULL; + + do { + ModestAttachmentView *att_view = (ModestAttachmentView *) tmp->data; + TnyMimePart *mime_part = tny_mime_part_view_get_part (TNY_MIME_PART_VIEW (att_view)); + + /* Do not select purged attachments */ + if (TNY_IS_MIME_PART (mime_part) && !tny_mime_part_is_purged (mime_part)) { + is_valid = TRUE; + } else { + if (prev) + tmp = g_list_previous (tmp); + else + tmp = g_list_next (tmp); + is_valid = FALSE; + } + g_object_unref (mime_part); + } while (!is_valid && tmp); + + return tmp; +} + + static gboolean key_press_event (GtkWidget *widget, GdkEventKey *event, @@ -458,15 +546,23 @@ key_press_event (GtkWidget *widget, if (event->keyval == GDK_Up) { ModestAttachmentView *current_sel = NULL; gboolean move_out = FALSE; - GList * box_children, *new_sel; + GList * box_children, *new_sel, *first_child; box_children = gtk_container_get_children (GTK_CONTAINER (priv->box)); - if (box_children == NULL) - move_out = TRUE; - else if ((priv->selected != NULL)&&(priv->selected->data != box_children->data)) - current_sel = (ModestAttachmentView *) priv->selected->data; - else + if (box_children == NULL) { move_out = TRUE; + } else { + first_child = box_children; + first_child = find_prev_or_next_not_purged (box_children, FALSE, TRUE); + if (priv->selected != NULL && first_child != NULL) { + if (priv->selected->data != first_child->data) + current_sel = (ModestAttachmentView *) priv->selected->data; + else + move_out = TRUE; + } else { + move_out = TRUE; + } + } if (move_out) { GtkWidget *toplevel = NULL; @@ -477,7 +573,10 @@ key_press_event (GtkWidget *widget, unselect_all (atts_view); } else { new_sel = g_list_find (box_children, (gpointer) current_sel); - new_sel = g_list_previous (new_sel); + new_sel = find_prev_or_next_not_purged (new_sel, TRUE, FALSE); + /* We assume that we detected properly that + there is a not purge attachment so we don't + need to check NULL */ set_selected (MODEST_ATTACHMENTS_VIEW (atts_view), MODEST_ATTACHMENT_VIEW (new_sel->data)); } g_list_free (box_children); @@ -495,7 +594,8 @@ key_press_event (GtkWidget *widget, move_out = TRUE; } else { last_child = g_list_last (box_children); - if (priv->selected != NULL) { + last_child = find_prev_or_next_not_purged (last_child, TRUE, TRUE); + if (priv->selected != NULL && last_child != NULL) { GList *last_selected = g_list_last (priv->selected); if (last_selected->data != last_child->data) current_sel = (ModestAttachmentView *) last_selected->data; @@ -515,13 +615,18 @@ key_press_event (GtkWidget *widget, unselect_all (atts_view); } else { new_sel = g_list_find (box_children, (gpointer) current_sel); - new_sel = g_list_next (new_sel); + new_sel = find_prev_or_next_not_purged (new_sel, FALSE, FALSE); set_selected (MODEST_ATTACHMENTS_VIEW (atts_view), MODEST_ATTACHMENT_VIEW (new_sel->data)); } g_list_free (box_children); 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; @@ -686,13 +791,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) { @@ -751,10 +849,16 @@ modest_attachments_view_select_all (ModestAttachmentsView *atts_view) g_list_free (priv->selected); priv->selected = NULL; - for (node = children; node != NULL; node = g_list_next (node)) { - gtk_widget_set_state (GTK_WIDGET (node->data), GTK_STATE_SELECTED); - priv->selected = g_list_append (priv->selected, node->data); + ModestAttachmentView *att_view = (ModestAttachmentView *) node->data; + TnyMimePart *mime_part = tny_mime_part_view_get_part (TNY_MIME_PART_VIEW (att_view)); + + /* Do not select purged attachments */ + if (TNY_IS_MIME_PART (mime_part) && !tny_mime_part_is_purged (mime_part)) { + 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); @@ -801,7 +905,7 @@ modest_attachments_view_get_sizes (ModestAttachmentsView *attachments_view, if (!tny_mime_part_is_purged (part)) { guint64 size; - *attachments_count ++; + (*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 */ @@ -824,7 +928,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)); }