X-Git-Url: http://git.maemo.org/git/?a=blobdiff_plain;f=src%2Fwidgets%2Fmodest-attachments-view.c;h=a269d4f357f1ec32958505bde55f764b0873ed17;hb=2cdfabbab55f149d58e6990fccae90456b6d059d;hp=39babdf4d93a5f54206ae3444e7eaedfdccedb5c;hpb=0223be48087492b7aa9ec29ec36edd6944af9ff1;p=modest diff --git a/src/widgets/modest-attachments-view.c b/src/widgets/modest-attachments-view.c index 39babdf..a269d4f 100644 --- a/src/widgets/modest-attachments-view.c +++ b/src/widgets/modest-attachments-view.c @@ -40,6 +40,7 @@ #include #include #include +#include static GObjectClass *parent_class = NULL; @@ -109,6 +110,7 @@ modest_attachments_view_set_message (ModestAttachmentsView *attachments_view, Tn TnyList *parts; TnyIterator *iter; gchar *msg_content_type = NULL; + TnyMimePart *part_to_check; if (msg == priv->msg) return; @@ -128,16 +130,19 @@ modest_attachments_view_set_message (ModestAttachmentsView *attachments_view, Tn return; } + 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 */ - 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; 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)); + header_content_type = modest_tny_mime_part_get_headers_content_type (TNY_MIME_PART (part_to_check)); if ((header_content_type != NULL) && !strstr (header_content_type, "application/")) { @@ -147,6 +152,7 @@ modest_attachments_view_set_message (ModestAttachmentsView *attachments_view, Tn if (application_multipart) { gtk_widget_queue_draw (GTK_WIDGET (attachments_view)); + g_object_unref (part_to_check); return; } } else { @@ -159,14 +165,15 @@ modest_attachments_view_set_message (ModestAttachmentsView *attachments_view, Tn g_free (msg_content_type); if (direct_attach) { - modest_attachments_view_add_attachment (attachments_view, TNY_MIME_PART (msg), TRUE, 0); + modest_attachments_view_add_attachment (attachments_view, TNY_MIME_PART (part_to_check), TRUE, 0); gtk_widget_queue_draw (GTK_WIDGET (attachments_view)); + g_object_unref (part_to_check); return; } } parts = TNY_LIST (tny_simple_list_new ()); - tny_mime_part_get_parts (TNY_MIME_PART (priv->msg), parts); + tny_mime_part_get_parts (TNY_MIME_PART (part_to_check), parts); iter = tny_list_create_iterator (parts); while (!tny_iterator_is_done (iter)) { @@ -184,6 +191,7 @@ modest_attachments_view_set_message (ModestAttachmentsView *attachments_view, Tn } g_object_unref (iter); g_object_unref (parts); + g_object_unref (part_to_check); gtk_widget_queue_draw (GTK_WIDGET (attachments_view)); @@ -205,7 +213,7 @@ modest_attachments_view_add_attachment (ModestAttachmentsView *attachments_view, 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_box_pack_start (GTK_BOX (priv->box), att_view, FALSE, FALSE, 0); gtk_widget_show_all (att_view); gtk_widget_queue_resize (GTK_WIDGET (attachments_view)); } @@ -243,14 +251,14 @@ modest_attachments_view_remove_attachment (ModestAttachmentsView *atts_view, Tny box_children = gtk_container_get_children (GTK_CONTAINER (priv->box)); node = g_list_find (box_children, found_att_view); - if (node->next) + if (node && node->next) next_widget = node->next->data; g_list_free (box_children); gtk_widget_destroy (GTK_WIDGET (found_att_view)); node = g_list_find (priv->selected, found_att_view); - if (node != NULL) { + if (node) { priv->selected = g_list_delete_link (priv->selected, node); if ((priv->selected == NULL) && (next_widget != NULL)) set_selected (MODEST_ATTACHMENTS_VIEW (atts_view), @@ -419,7 +427,9 @@ button_press_event (GtkWidget *widget, (gint) event->x_root, (gint) event->y_root); if (att_view != NULL) { - if ((priv->style == MODEST_ATTACHMENTS_VIEW_STYLE_LINKS) || + if (priv->style == MODEST_ATTACHMENTS_VIEW_STYLE_NO_FOCUS) { + unselect_all (MODEST_ATTACHMENTS_VIEW (widget)); + } else if ((priv->style == MODEST_ATTACHMENTS_VIEW_STYLE_LINKS) || (GTK_WIDGET_STATE (att_view) == GTK_STATE_SELECTED && (g_list_length (priv->selected) < 2))) { TnyMimePart *mime_part = tny_mime_part_view_get_part (TNY_MIME_PART_VIEW (att_view)); if (TNY_IS_MIME_PART (mime_part)) { @@ -536,6 +546,11 @@ key_press_event (GtkWidget *widget, { ModestAttachmentsViewPrivate *priv = MODEST_ATTACHMENTS_VIEW_GET_PRIVATE (atts_view); + if (priv->style == MODEST_ATTACHMENTS_VIEW_STYLE_NO_FOCUS) { + unselect_all (atts_view); + return FALSE; + } + /* If grabbed (for example rubber banding), escape leaves the rubberbanding mode */ if (gtk_grab_get_current () == widget) { if (event->keyval == GDK_Escape) { @@ -920,7 +935,6 @@ modest_attachments_view_get_sizes (ModestAttachmentsView *attachments_view, size = 32768; } *attachments_size += size; - } g_object_unref (part); } @@ -928,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[] = { @@ -936,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 @@ -960,11 +980,13 @@ focus (GtkWidget *widget, GtkDirectionType direction, ModestAttachmentsView *att if (!gtk_window_has_toplevel_focus (GTK_WINDOW (toplevel))) return FALSE; - children = gtk_container_get_children (GTK_CONTAINER (priv->box)); - if (children != NULL) { - set_selected (atts_view, MODEST_ATTACHMENT_VIEW (children->data)); + if (priv->style != MODEST_ATTACHMENTS_VIEW_STYLE_NO_FOCUS) { + children = gtk_container_get_children (GTK_CONTAINER (priv->box)); + if (children != NULL) { + set_selected (atts_view, MODEST_ATTACHMENT_VIEW (children->data)); + } + g_list_free (children); } - g_list_free (children); return FALSE; } @@ -981,11 +1003,28 @@ modest_attachments_view_set_style (ModestAttachmentsView *self, if (priv->style != style) { priv->style = style; gtk_widget_queue_draw (GTK_WIDGET (self)); - if (priv->style == MODEST_ATTACHMENTS_VIEW_STYLE_LINKS) { - GTK_WIDGET_UNSET_FLAGS (self, GTK_CAN_FOCUS); - } else { + if (priv->style == MODEST_ATTACHMENTS_VIEW_STYLE_SELECTABLE) { GTK_WIDGET_SET_FLAGS (self, GTK_CAN_FOCUS); + } else { + GTK_WIDGET_UNSET_FLAGS (self, GTK_CAN_FOCUS); } } } + +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; +}