* Partially reverted last commit, sometimes the gdk_threads_enter blocks, still...
[modest] / src / modest-ui-dimming-rules.c
index a816778..43e31df 100644 (file)
@@ -43,7 +43,7 @@
 
 static gboolean _folder_is_any_of_type (TnyFolder *folder, TnyFolderType types[], guint ntypes);
 static gboolean _invalid_msg_selected (ModestMainWindow *win, gboolean unique, ModestDimmingRule *rule);
-static gboolean _invalid_attach_selected (ModestWindow *win, gboolean unique, ModestDimmingRule *rule);
+static gboolean _invalid_attach_selected (ModestWindow *win, gboolean unique, gboolean for_view, ModestDimmingRule *rule);
 static gboolean _invalid_clipboard_selected (ModestWindow *win);
 static gboolean _already_opened_msg (ModestWindow *win);
 static gboolean _selected_msg_marked_as (ModestWindow *win, TnyHeaderFlags mask, gboolean opposite);
@@ -59,6 +59,7 @@ static gboolean _msg_download_completed (ModestMainWindow *win);
 static gboolean _selected_msg_sent_in_progress (ModestWindow *win);
 static gboolean _sending_in_progress (ModestWindow *win);
 static gboolean _marked_as_deleted (ModestWindow *win);
+static gboolean _invalid_attachment_for_purge (ModestWindow *win, ModestDimmingRule *rule);
 
 
 gboolean 
@@ -543,7 +544,7 @@ modest_ui_dimming_rules_on_view_attachments (ModestWindow *win, gpointer user_da
 
        /* Check dimmed rule */ 
        if (!dimmed) 
-               dimmed = _invalid_attach_selected (win, TRUE, rule);                    
+               dimmed = _invalid_attach_selected (win, TRUE, TRUE, rule);                      
                
        return dimmed;
 }
@@ -560,7 +561,7 @@ modest_ui_dimming_rules_on_save_attachments (ModestWindow *win, gpointer user_da
 
        /* Check dimmed rule */ 
        if (!dimmed) 
-               dimmed = _invalid_attach_selected (win, FALSE, rule);                   
+               dimmed = _invalid_attach_selected (win, FALSE, FALSE, rule);                    
                
        return dimmed;
 }
@@ -577,9 +578,11 @@ modest_ui_dimming_rules_on_remove_attachments (ModestWindow *win, gpointer user_
 
        /* Check dimmed rule */ 
        if (!dimmed) {
-               dimmed = _invalid_attach_selected (win, FALSE, NULL);                   
-               if (dimmed) 
-                       modest_dimming_rule_set_notification (rule, _("mcen_ib_unable_to_display_more"));
+               dimmed = _invalid_attachment_for_purge (win, rule);
+       }
+
+       if (!dimmed) {
+               dimmed = _invalid_attach_selected (win, TRUE, TRUE, rule);                      
        }
 
        return dimmed;
@@ -1009,6 +1012,7 @@ _invalid_clipboard_selected (ModestWindow *win)
 static gboolean
 _invalid_attach_selected (ModestWindow *win,
                          gboolean unique,
+                         gboolean for_view,
                          ModestDimmingRule *rule) 
 {
        GList *attachments, *node;
@@ -1029,34 +1033,44 @@ _invalid_attach_selected (ModestWindow *win,
                /* Get selected atachments */
                attachments = modest_msg_view_window_get_attachments (MODEST_MSG_VIEW_WINDOW(win));
                n_selected = g_list_length (attachments);
-               for (node = attachments; node != NULL; node = g_list_next (node)) {
-                       TnyMimePart *mime_part = TNY_MIME_PART (node->data);
-                       TnyList *nested_list = tny_simple_list_new ();
-                       if (!tny_mime_part_is_attachment (mime_part)) {
-                               selected_messages = TRUE;
-                               break;
-                       }
-                       tny_mime_part_get_parts (mime_part, nested_list);
-                       if (tny_list_get_length (nested_list) > 0)
+
+               /* Check unique */              
+               if (!result) {
+                       if (unique) 
+                               result = n_selected != 1;
+                       else
+                               
+                               result = n_selected < 1;
+               }
+
+               /* Check attached type (view operation not required) */
+               if (!result && !for_view)  {
+                       for (node = attachments; node != NULL && !result; node = g_list_next (node)) {
+                               TnyMimePart *mime_part = TNY_MIME_PART (node->data);
+                               TnyList *nested_list = tny_simple_list_new ();
+                               if (TNY_IS_MSG (mime_part)) {
+                                       selected_messages = TRUE;
+                                       result = TRUE;
+                               }
+                               tny_mime_part_get_parts (mime_part, nested_list);
+                               if (tny_list_get_length (nested_list) > 0) {
                                nested_attachments = TRUE;
-                       g_object_unref (nested_list);
+                               result = TRUE;
+                               }
+                               g_object_unref (nested_list);
+                       }
                }
                
-               /* Check unique */
-               if (unique) 
-                       result = n_selected != 1;
-               else
-                       
-                       result = n_selected < 1;
-               
                /* Set notifications */
-               if (!result && rule != NULL) {
+               if (result && rule != NULL) {
                        if (selected_messages) {
                                modest_dimming_rule_set_notification (rule, _("mcen_ib_unable_to_save_attach_mail"));
                        } else if (nested_attachments) {
                                modest_dimming_rule_set_notification (rule, _("FIXME:unable to save attachments with nested elements"));
                        } else if (n_selected == 0) {
                                modest_dimming_rule_set_notification (rule, _("FIXME:no attachment selected"));
+                       } else if (unique) {
+                               modest_dimming_rule_set_notification (rule, _("mcen_ib_unable_to_display_more"));
                        }
                }
                
@@ -1360,3 +1374,43 @@ _sending_in_progress (ModestWindow *win)
 
        return result;
 }
+
+static gboolean
+_invalid_attachment_for_purge (ModestWindow *win, ModestDimmingRule *rule)
+{
+       gboolean result = FALSE;
+
+       if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
+               TnyMsg *msg;
+               TnyFolder *folder;
+               TnyAccount *account;
+
+               msg = modest_msg_view_window_get_message (MODEST_MSG_VIEW_WINDOW (win));
+               folder = tny_msg_get_folder (msg);
+               g_object_unref (msg);
+               account = modest_tny_folder_get_account (folder);
+               g_object_unref (folder);
+               if (modest_tny_account_is_virtual_local_folders (TNY_ACCOUNT (account))) {
+               } else {
+                       const gchar *proto_str = tny_account_get_proto (TNY_ACCOUNT (account));
+                       /* If it's POP then dim */
+                       if (modest_protocol_info_get_transport_store_protocol (proto_str) == 
+                           MODEST_PROTOCOL_STORE_POP) {
+                               GList *attachments;
+                               gint n_selected;
+                               result = TRUE;
+                               attachments = modest_msg_view_window_get_attachments (MODEST_MSG_VIEW_WINDOW(win));
+                               n_selected = g_list_length (attachments);
+                               g_list_free (attachments);
+
+                               modest_dimming_rule_set_notification (
+                                       rule, 
+                                       ngettext ("mail_ib_unable_to_pure_attach_pop_mail_singular",
+                                                 "mail_ib_unable_to_pure_attach_pop_mail_plural", n_selected));
+                       }
+               }
+       }
+
+       return result;
+}
+