Simplify the recipients if they are in the form of a@b <a@b> or "a@b" <a@b>
[modest] / src / modest-ui-dimming-rules.c
index 6891397..794c0fa 100644 (file)
@@ -34,6 +34,7 @@
 #include <string.h>
 #include "modest-ui-dimming-rules.h"
 #include "modest-ui-actions.h"
+#include "modest-account-mgr-helpers.h"
 #include "modest-dimming-rule.h"
 #include "modest-debug.h"
 #include "modest-tny-folder.h"
@@ -83,7 +84,7 @@ static gboolean _selected_folder_has_subfolder_with_same_name (ModestWindow *win
 static void fill_list_of_caches (gpointer key, gpointer value, gpointer userdata);
 static gboolean _send_receive_in_progress (ModestWindow *win);
 static gboolean _msgs_send_in_progress (void);
-static gboolean _all_msgs_in_sending_status (ModestHeaderView *header_view);
+static gboolean _all_msgs_in_sending_status (ModestHeaderView *header_view) G_GNUC_UNUSED;
 
 static DimmedState *
 _define_main_window_dimming_state (ModestMainWindow *window)
@@ -618,11 +619,6 @@ modest_ui_dimming_rules_on_rename_folder (ModestWindow *win, gpointer user_data)
                if (dimmed)
                        modest_dimming_rule_set_notification (rule, "");
        }
-       if (!dimmed) {
-               dimmed = _transfer_mode_enabled (win);
-               if (dimmed)
-                       modest_dimming_rule_set_notification (rule, "");
-       }
 
        return dimmed;
 }
@@ -1438,7 +1434,7 @@ modest_ui_dimming_rules_on_save_attachments (ModestWindow *win, gpointer user_da
        dimmed = _invalid_attach_selected (win, FALSE, FALSE, FALSE, rule);
 
        if (!dimmed) {
-               dimmed = _purged_attach_selected (win, TRUE);
+               dimmed = _purged_attach_selected (win, TRUE, NULL);
                if (dimmed) {
                        modest_dimming_rule_set_notification (rule, _("mail_ib_attach_not_local"));
                }
@@ -1469,25 +1465,6 @@ modest_ui_dimming_rules_on_remove_attachments (ModestWindow *win, gpointer user_
                dimmed = _invalid_attach_selected (win, FALSE, FALSE, TRUE, NULL);
                if (dimmed)
                        modest_dimming_rule_set_notification (rule, _("FIXME:no attachment selected"));
-
-               if (!dimmed) {
-                       TnyList *attachments;
-                       TnyIterator *iter;
-                       attachments = modest_msg_view_window_get_attachments (MODEST_MSG_VIEW_WINDOW (win));
-                       if (attachments) {
-                               iter = tny_list_create_iterator (attachments);
-                               while (!tny_iterator_is_done (iter) && !dimmed) {
-                                       TnyMimePart *mime_part = (TnyMimePart *)
-                                               tny_iterator_get_current (iter);
-                                       if (modest_tny_mime_part_is_msg (mime_part))
-                                               dimmed = TRUE;
-                                       g_object_unref (mime_part);
-                                       tny_iterator_next (iter);
-                               }
-                               g_object_unref (iter);
-                               g_object_unref (attachments);
-                       }
-               }
        }
 
        if (!dimmed) {
@@ -1910,20 +1887,52 @@ modest_ui_dimming_rules_on_view_next (ModestWindow *win, gpointer user_data)
        if (!dimmed) {
                dimmed = modest_msg_view_window_last_message_selected (MODEST_MSG_VIEW_WINDOW (win));
                modest_dimming_rule_set_notification (rule, NULL);
-       }               
+       }
 
        return dimmed;
 }
 
 
-gboolean 
+gboolean
 modest_ui_dimming_rules_on_tools_smtp_servers (ModestWindow *win, gpointer user_data)
 {
-       return !modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), 
-                                               TRUE);  
+       gboolean dimmed;
+       ModestAccountMgr *mgr;
+
+       mgr = modest_runtime_get_account_mgr();
+       dimmed = !modest_account_mgr_has_accounts(mgr, TRUE);
+
+       /* Dimm it if we only have metaaccounts */
+       if (!dimmed) {
+               ModestProtocolRegistry *reg = modest_runtime_get_protocol_registry ();
+               GSList *account_names = modest_account_mgr_account_names (mgr, TRUE);
+
+               if (account_names) {
+                       ModestProtocolType store_protocol;
+                       gboolean found = FALSE;
+                       GSList *iter = account_names;
+                       const gchar *tag = MODEST_PROTOCOL_REGISTRY_MULTI_MAILBOX_PROVIDER_PROTOCOLS;
+
+                       while (iter && !found) {
+                               gchar* account_name;
+
+                               account_name = (gchar *) iter->data;
+                               store_protocol = modest_account_mgr_get_store_protocol (mgr, account_name);
+
+                               if (!modest_protocol_registry_protocol_type_has_tag (reg, store_protocol, tag))
+                                       found = TRUE;
+                               else
+                                       iter = g_slist_next (iter);
+                       }
+                       modest_account_mgr_free_account_names (account_names);
+                       dimmed = !found;
+               }
+       }
+
+       return dimmed;
 }
 
-gboolean 
+gboolean
 modest_ui_dimming_rules_on_cancel_sending (ModestWindow *win, gpointer user_data)
 {
        ModestDimmingRule *rule = NULL;
@@ -3129,6 +3138,12 @@ modest_ui_dimming_rules_on_folder_window_move_to (ModestWindow *win, gpointer us
                                                                       MODEST_FOLDER_RULES_FOLDER_NON_MOVEABLE);
        }
 
+       if (!dimmed) {
+               dimmed = _transfer_mode_enabled (win);
+               if (dimmed)
+                       modest_dimming_rule_set_notification (rule, "");
+       }
+
        return dimmed;
 }
 
@@ -3154,6 +3169,12 @@ modest_ui_dimming_rules_on_folder_window_delete (ModestWindow *win, gpointer use
                                                                       MODEST_FOLDER_RULES_FOLDER_NON_DELETABLE);
        }
 
+       if (!dimmed) {
+               dimmed = _transfer_mode_enabled (win);
+               if (dimmed)
+                       modest_dimming_rule_set_notification (rule, "");
+       }
+
        return dimmed;
 }