Add dialog to select attachments in save/remove actions.
authorJose Dapena Paz <jdapena@igalia.com>
Wed, 11 Feb 2009 17:30:08 +0000 (17:30 +0000)
committerJose Dapena Paz <jdapena@igalia.com>
Wed, 11 Feb 2009 17:30:08 +0000 (17:30 +0000)
pmo-trunk-r7470

src/hildon2/modest-maemo-utils.c
src/hildon2/modest-maemo-utils.h
src/hildon2/modest-msg-edit-window.c
src/hildon2/modest-msg-view-window.c
src/modest-ui-dimming-rules.c

index 585f35b..4d2a495 100644 (file)
@@ -52,6 +52,7 @@
 #include "modest-text-utils.h"
 #include "modest-platform.h"
 #include "modest-ui-constants.h"
 #include "modest-text-utils.h"
 #include "modest-platform.h"
 #include "modest-ui-constants.h"
+#include <hildon/hildon-picker-dialog.h>
 
 /*
  * For getting and tracking the Bluetooth name
 
 /*
  * For getting and tracking the Bluetooth name
@@ -459,3 +460,94 @@ modest_maemo_utils_create_group_box (const gchar *label_text, GtkWidget *content
 
        return box;
 }
 
        return box;
 }
+
+static gboolean match_all (TnyList *list, GObject *item, gpointer match_data)
+{
+       return TRUE;
+}
+
+gboolean
+modest_maemo_utils_select_attachments (GtkWindow *window, TnyList *att_list)
+{
+       GtkTreeModel *model;
+       TnyIterator *iterator;
+       GtkWidget *selector;
+       GtkCellRenderer *renderer;
+       GtkWidget *dialog;
+       gint response;
+       gboolean result = TRUE;
+
+       model = GTK_TREE_MODEL (gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_OBJECT));
+       for (iterator = tny_list_create_iterator (att_list);
+            !tny_iterator_is_done (iterator);
+            tny_iterator_next (iterator)) {
+               GtkTreeIter iter;
+               TnyMimePart *part;
+               gchar *label;
+               gchar *filename = NULL;
+
+               part = (TnyMimePart *) tny_iterator_get_current (iterator);
+
+               if (TNY_IS_MSG (part)) {
+                       TnyHeader *header;
+                       
+                       header = tny_msg_get_header (TNY_MSG (part));
+                       if (TNY_IS_HEADER (header)) {
+                               filename = g_strdup (tny_mime_part_get_filename (part));
+                               if (!filename)
+                                       filename = tny_header_dup_subject (header);
+                               if (filename == NULL || filename[0] == '\0')
+                                       filename = g_strdup (_("mail_va_no_subject"));
+                       }
+               } else {
+                       filename = g_strdup (tny_mime_part_get_filename (part));
+               }
+
+               label = g_strconcat (filename, NULL);
+               gtk_list_store_append (GTK_LIST_STORE (model), &iter);
+               gtk_list_store_set (GTK_LIST_STORE (model), &iter, 0, label, 1, part, -1);
+               g_free (label);
+               g_object_unref (part);
+       }
+
+       selector = GTK_WIDGET (hildon_touch_selector_new ());
+       renderer = gtk_cell_renderer_text_new ();
+       hildon_touch_selector_append_column (HILDON_TOUCH_SELECTOR (selector), model, renderer,
+                                            "text", 0, NULL);
+       hildon_touch_selector_set_column_selection_mode (HILDON_TOUCH_SELECTOR (selector), 
+                                                        HILDON_TOUCH_SELECTOR_SELECTION_MODE_MULTIPLE);
+
+       dialog = hildon_picker_dialog_new (window);
+       gtk_window_set_title (GTK_WINDOW (dialog), _("mcen_ti_select_attachment_title"));
+       hildon_picker_dialog_set_selector (HILDON_PICKER_DIALOG (dialog), HILDON_TOUCH_SELECTOR (selector));
+       hildon_picker_dialog_set_done_label (HILDON_PICKER_DIALOG (dialog), _HL("wdgt_bd_done"));
+
+       response = gtk_dialog_run (GTK_DIALOG (dialog));
+
+       if (response == GTK_RESPONSE_OK) {
+               GList *selected_rows, *node;
+
+               tny_list_remove_matches (att_list, match_all, NULL);
+               selected_rows = hildon_touch_selector_get_selected_rows (HILDON_TOUCH_SELECTOR (selector), 0);
+               for (node = selected_rows; node != NULL; node = g_list_next (node)) {
+                       GtkTreePath *path;
+                       GObject *selected;
+                       GtkTreeIter iter;
+
+                       path = (GtkTreePath *) node->data;
+                       gtk_tree_model_get_iter (model, &iter, path);
+                       gtk_tree_model_get (model, &iter, 1, &selected, -1);
+                       tny_list_append (att_list, selected);
+               }
+               if (tny_list_get_length (att_list) == 0)
+                       result = FALSE;
+       } else {
+               result = FALSE;
+       }
+
+       gtk_widget_destroy (dialog);
+
+       g_object_unref (model);
+
+       return result;
+}
index bd679c7..4f54dce 100644 (file)
@@ -151,4 +151,6 @@ void       modest_maemo_utils_set_vbutton_layout (GtkSizeGroup *sizegroup,
 
 GtkWidget *modest_maemo_utils_create_group_box (const gchar *label, GtkWidget *contents);
 
 
 GtkWidget *modest_maemo_utils_create_group_box (const gchar *label, GtkWidget *contents);
 
+gboolean   modest_maemo_utils_select_attachments (GtkWindow *window, TnyList *att_list);
+
 #endif /*__MODEST_MAEMO_UTILS_H__*/
 #endif /*__MODEST_MAEMO_UTILS_H__*/
index de57534..e30de18 100644 (file)
@@ -2438,7 +2438,12 @@ modest_msg_edit_window_remove_attachments (ModestMsgEditWindow *window,
        priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
 
        if (att_list == NULL) {
        priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
 
        if (att_list == NULL) {
-               att_list = modest_attachments_view_get_selection (MODEST_ATTACHMENTS_VIEW (priv->attachments_view));
+               att_list = modest_attachments_view_get_attachments (MODEST_ATTACHMENTS_VIEW (priv->attachments_view));
+               if (!modest_maemo_utils_select_attachments (GTK_WINDOW (window), att_list)) {
+                       g_object_unref (att_list);
+                       return;
+               }
+               
        } else {
                g_object_ref (att_list);
        }
        } else {
                g_object_ref (att_list);
        }
index 28dc4f4..70ec230 100644 (file)
@@ -2774,6 +2774,10 @@ modest_msg_view_window_save_attachments (ModestMsgViewWindow *window, TnyList *m
                /* In Hildon 2.2 save and delete operate over all the attachments as there's no
                 * selection available */
                mime_parts = modest_msg_view_get_attachments (MODEST_MSG_VIEW (priv->msg_view));
                /* In Hildon 2.2 save and delete operate over all the attachments as there's no
                 * selection available */
                mime_parts = modest_msg_view_get_attachments (MODEST_MSG_VIEW (priv->msg_view));
+               if (!modest_maemo_utils_select_attachments (GTK_WINDOW (window), mime_parts)) {
+                       g_object_unref (mime_parts);
+                       return;
+               }
                if (mime_parts == NULL || tny_list_get_length (mime_parts) == 0)
                        return;
        } else {
                if (mime_parts == NULL || tny_list_get_length (mime_parts) == 0)
                        return;
        } else {
@@ -2886,7 +2890,8 @@ modest_msg_view_window_remove_attachments (ModestMsgViewWindow *window, gboolean
        }
        g_object_unref (iter);
 
        }
        g_object_unref (iter);
 
-       if (tny_list_get_length (mime_parts) == 0) {
+       if (!modest_maemo_utils_select_attachments (GTK_WINDOW (window), mime_parts) ||
+           tny_list_get_length (mime_parts) == 0) {
                g_object_unref (mime_parts);
                return;
        }
                g_object_unref (mime_parts);
                return;
        }
index f64b9b1..f110751 100644 (file)
@@ -1785,8 +1785,13 @@ modest_ui_dimming_rules_on_editor_remove_attachment (ModestWindow *win, gpointer
                                                                    MODEST_MSG_EDIT_WINDOW (win),
                                                                    MODEST_MSG_EDIT_WINDOW_WIDGET_TYPE_ATTACHMENTS);
        
                                                                    MODEST_MSG_EDIT_WINDOW (win),
                                                                    MODEST_MSG_EDIT_WINDOW_WIDGET_TYPE_ATTACHMENTS);
        
+#ifdef MODEST_TOOLKIT_HILDON2
+       selected_attachments = modest_attachments_view_get_attachments (
+                                                                     MODEST_ATTACHMENTS_VIEW (attachments_view));
+#else
        selected_attachments = modest_attachments_view_get_selection (
                                                                      MODEST_ATTACHMENTS_VIEW (attachments_view));
        selected_attachments = modest_attachments_view_get_selection (
                                                                      MODEST_ATTACHMENTS_VIEW (attachments_view));
+#endif
        n_att_selected = tny_list_get_length (selected_attachments);
        g_object_unref (selected_attachments);
        
        n_att_selected = tny_list_get_length (selected_attachments);
        g_object_unref (selected_attachments);