* Implementation of 'email menu' dimming rules of main window.
[modest] / src / modest-ui-actions.c
index 45321f1..d44cd5a 100644 (file)
@@ -38,7 +38,7 @@
 #include <modest-tny-msg.h>
 #include <modest-tny-account.h>
 #include <modest-address-book.h>
-
+#include "modest-error.h"
 #include "modest-ui-actions.h"
 
 #include "modest-tny-platform-factory.h"
@@ -590,6 +590,25 @@ open_msg_cb (ModestMailOperation *mail_op,
 }
 
 /*
+ * This function is the error handler of the
+ * modest_mail_operation_get_msgs_full operation
+ */
+static void
+modest_ui_actions_get_msgs_full_error_handler (ModestMailOperation *mail_op,
+                                              gpointer user_data)
+{
+       const GError *error;
+
+       error = modest_mail_operation_get_error (mail_op);
+       if (error->code == MODEST_MAIL_OPERATION_ERROR_SIZE_LIMIT) {
+               GObject *win = modest_mail_operation_get_source (mail_op);
+
+               modest_platform_run_information_dialog ((win) ? GTK_WINDOW (win) : NULL,
+                                                       error->message);
+       }
+}
+
+/*
  * This function is used by both modest_ui_actions_on_open and
  * modest_ui_actions_on_header_activated. This way we always do the
  * same when trying to open messages.
@@ -620,7 +639,10 @@ _modest_ui_actions_open (TnyList *headers, ModestWindow *win)
        }
 
        /* Open each message */
-       mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_TYPE_RECEIVE, G_OBJECT (win));
+       mail_op = modest_mail_operation_new_with_error_handling (MODEST_MAIL_OPERATION_TYPE_RECEIVE, 
+                                                                G_OBJECT (win), 
+                                                                modest_ui_actions_get_msgs_full_error_handler, 
+                                                                NULL);
        modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
        modest_mail_operation_get_msgs_full (mail_op, 
                                             headers, 
@@ -868,7 +890,10 @@ reply_forward (ReplyForwardAction action, ModestWindow *win)
                        reply_forward_cb (NULL, header, msg, rf_helper);
        } else {
                /* Retrieve messages */
-               mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_TYPE_RECEIVE, G_OBJECT(win));
+               mail_op = modest_mail_operation_new_with_error_handling (MODEST_MAIL_OPERATION_TYPE_RECEIVE, 
+                                                                        G_OBJECT(win),
+                                                                        modest_ui_actions_get_msgs_full_error_handler, 
+                                                                        NULL);
                modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
                modest_mail_operation_get_msgs_full (mail_op, 
                                                     header_list, 
@@ -1704,6 +1729,16 @@ modest_ui_actions_on_rename_folder (GtkAction *action,
 }
 
 static void
+modest_ui_actions_delete_folder_error_handler (ModestMailOperation *mail_op,
+                                              gpointer user_data)
+{
+       GObject *win = modest_mail_operation_get_source (mail_op);
+
+       modest_platform_run_information_dialog ((win) ? GTK_WINDOW (win) : NULL,
+                                               _("mail_in_ui_folder_delete_error"));
+}
+
+static void
 delete_folder (ModestMainWindow *main_window, gboolean move_to_trash) 
 {
        TnyFolderStore *folder;
@@ -1735,17 +1770,15 @@ delete_folder (ModestMainWindow *main_window, gboolean move_to_trash)
        g_free (message);
 
        if (response == GTK_RESPONSE_OK) {
-               ModestMailOperation *mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_TYPE_DELETE, G_OBJECT(main_window));
+               ModestMailOperation *mail_op = 
+                       modest_mail_operation_new_with_error_handling (MODEST_MAIL_OPERATION_TYPE_DELETE, 
+                                                                      G_OBJECT(main_window),
+                                                                      modest_ui_actions_delete_folder_error_handler,
+                                                                      NULL);
 
                modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
                                                 mail_op);
                modest_mail_operation_remove_folder (mail_op, TNY_FOLDER (folder), move_to_trash);
-
-               /* Show error if happened */
-               if (modest_mail_operation_get_error (mail_op))
-                       modest_platform_run_information_dialog (GTK_WINDOW (main_window),
-                                                               _("mail_in_ui_folder_delete_error"));
-
                g_object_unref (G_OBJECT (mail_op));
        }
 
@@ -2471,16 +2504,14 @@ tranasfer_msgs_from_viewer_cb (const GObject *object, gpointer user_data)
        g_return_if_fail (found);
 }
 
-static void
-move_to_error_checking (const GObject *obj, gpointer user_data)
+void
+modest_ui_actions_move_folder_error_handler (ModestMailOperation *mail_op, 
+                                            gpointer user_data)
 {
-       ModestWindow *win = NULL;
-       
-       g_return_if_fail (MODEST_IS_WINDOW (obj));
-       win = MODEST_WINDOW (obj);
+       GObject *win = modest_mail_operation_get_source (mail_op);
 
        /* TODO: show error message */
-       modest_platform_run_information_dialog (GTK_WINDOW (win),
+       modest_platform_run_information_dialog ((win) ? GTK_WINDOW (win) : NULL,
                                                _("mail_in_ui_folder_move_target_error"));
 }
 
@@ -2497,7 +2528,6 @@ modest_ui_actions_on_main_window_move_to (GtkAction *action,
        gint result;
        TnyFolderStore *folder_store = NULL;
        ModestMailOperation *mail_op = NULL;
-       ModestMailOperationStatus status = MODEST_MAIL_OPERATION_STATUS_SUCCESS;
 
        g_return_if_fail (MODEST_IS_MAIN_WINDOW (win));
 
@@ -2532,17 +2562,18 @@ modest_ui_actions_on_main_window_move_to (GtkAction *action,
                modest_header_view_set_folder (MODEST_HEADER_VIEW (header_view), NULL); 
 
                if (TNY_IS_FOLDER (src_folder)) {
-                       mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_TYPE_RECEIVE, 
-                                                            G_OBJECT(win));
-                       modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), 
-                                                        mail_op);
+                       mail_op = 
+                               modest_mail_operation_new_with_error_handling (MODEST_MAIL_OPERATION_TYPE_RECEIVE, 
+                                                                              G_OBJECT(win),
+                                                                              modest_ui_actions_move_folder_error_handler,
+                                                                              NULL);
+                       modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
 
                        modest_mail_operation_xfer_folder (mail_op, 
                                                           TNY_FOLDER (src_folder),
                                                           folder_store,
-                                                          TRUE);                       
-                       /* Get status and unref mail operation */
-                       status = modest_mail_operation_get_status (mail_op);                                            
+                                                          TRUE);
+                       /* Unref mail operation */
                        g_object_unref (G_OBJECT (mail_op));
                }
 
@@ -2573,18 +2604,12 @@ modest_ui_actions_on_main_window_move_to (GtkAction *action,
                                                                 NULL,
                                                                 NULL);
 
-                               /* Get status and unref mail operation */
-                               status = modest_mail_operation_get_status (mail_op);                                            
                                g_object_unref (G_OBJECT (mail_op));
                        }
                        g_object_unref (headers);
                }
        }
        g_object_unref (folder_store);
-       
-       /* Check errors */                      
-       if (status != MODEST_MAIL_OPERATION_STATUS_SUCCESS) 
-               move_to_error_checking (G_OBJECT(win), NULL);
  end:
        gtk_widget_destroy (dialog);
 }
@@ -2765,7 +2790,10 @@ modest_ui_actions_on_retrieve_msg_contents (GtkAction *action,
                return;
 
        /* Create mail operation */
-       mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_TYPE_RECEIVE, G_OBJECT (window));
+       mail_op = modest_mail_operation_new_with_error_handling (MODEST_MAIL_OPERATION_TYPE_RECEIVE, 
+                                                                G_OBJECT (window),
+                                                                modest_ui_actions_get_msgs_full_error_handler, 
+                                                                NULL);
        modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
        modest_mail_operation_get_msgs_full (mail_op, headers, NULL, NULL, NULL);
 
@@ -2775,6 +2803,16 @@ modest_ui_actions_on_retrieve_msg_contents (GtkAction *action,
 }
 
 void
+modest_ui_actions_on_email_menu_activated (GtkAction *action,
+                                         ModestWindow *window)
+{
+       g_return_if_fail (MODEST_IS_WINDOW (window));
+
+       /* Update dimmed */     
+       modest_window_check_dimming_rules (window);     
+}
+
+void
 modest_ui_actions_on_edit_menu_activated (GtkAction *action,
                                          ModestWindow *window)
 {
@@ -2783,3 +2821,33 @@ modest_ui_actions_on_edit_menu_activated (GtkAction *action,
        /* Update dimmed */     
        modest_window_check_dimming_rules (window);     
 }
+
+void
+modest_ui_actions_on_toolbar_csm_menu_activated (GtkAction *action,
+                                                ModestWindow *window)
+{
+       g_return_if_fail (MODEST_IS_WINDOW (window));
+
+       /* Update dimmed */     
+       modest_window_check_dimming_rules (window);     
+}
+
+void
+modest_ui_actions_on_folder_view_csm_menu_activated (GtkAction *action,
+                                                    ModestWindow *window)
+{
+       g_return_if_fail (MODEST_IS_WINDOW (window));
+
+       /* Update dimmed */     
+       modest_window_check_dimming_rules (window);     
+}
+
+void
+modest_ui_actions_on_header_view_csm_menu_activated (GtkAction *action,
+                                                    ModestWindow *window)
+{
+       g_return_if_fail (MODEST_IS_WINDOW (window));
+
+       /* Update dimmed */     
+       modest_window_check_dimming_rules (window);     
+}