* Implementation of 'email menu' dimming rules of main window.
[modest] / src / modest-ui-actions.c
index 7fcc9a4..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, 
@@ -1169,7 +1194,6 @@ modest_ui_actions_on_folder_selection_changed (ModestFolderView *folder_view,
                /* Show account details */
                modest_main_window_set_contents_style (main_window, MODEST_MAIN_WINDOW_CONTENTS_STYLE_DETAILS);
        } else if (modest_tny_folder_store_is_virtual_local_folders  (folder_store )) {
-               printf ("DEBUG: %s: folder store.\n", __FUNCTION__);
                //TODO: Set the virtual folder store as the "active account" somehow:
                modest_main_window_set_contents_style (main_window, MODEST_MAIN_WINDOW_CONTENTS_STYLE_DETAILS);
        } else {
@@ -1705,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;
@@ -1736,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));
        }
 
@@ -2472,17 +2504,15 @@ 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), */
-/*                                             _("mail_in_ui_folder_move_target_error")); */
+       modest_platform_run_information_dialog ((win) ? GTK_WINDOW (win) : NULL,
+                                               _("mail_in_ui_folder_move_target_error"));
 }
 
 /*
@@ -2532,18 +2562,19 @@ 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_with_error_handling (MODEST_MAIL_OPERATION_TYPE_RECEIVE, 
-                                                                                G_OBJECT(win),
-                                                                                move_to_error_checking);
-                       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);
+                       /* Unref mail operation */
                        g_object_unref (G_OBJECT (mail_op));
-                       
                }
 
                /* Frees */
@@ -2572,13 +2603,13 @@ modest_ui_actions_on_main_window_move_to (GtkAction *action,
                                                                 TRUE,
                                                                 NULL,
                                                                 NULL);
+
                                g_object_unref (G_OBJECT (mail_op));
                        }
                        g_object_unref (headers);
                }
        }
        g_object_unref (folder_store);
-       
  end:
        gtk_widget_destroy (dialog);
 }
@@ -2759,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);
 
@@ -2767,3 +2801,53 @@ modest_ui_actions_on_retrieve_msg_contents (GtkAction *action,
        g_object_unref (headers);
        g_object_unref (mail_op);
 }
+
+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)
+{
+       g_return_if_fail (MODEST_IS_WINDOW (window));
+
+       /* 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);     
+}