* Implementation of 'email menu' dimming rules of main window.
[modest] / src / modest-ui-actions.c
index fc09b38..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, 
@@ -784,6 +806,9 @@ download_uncached_messages (TnyList *header_list, GtkWindow *win)
 
                header = TNY_HEADER (tny_iterator_get_current (iter));
                flags = tny_header_get_flags (header);
+               /* TODO: is this the right flag?, it seems that some
+                  headers that have been previously downloaded do not
+                  come with it */
                found = !(flags & TNY_HEADER_FLAG_CACHED);
                g_object_unref (header);
                tny_iterator_next (iter);
@@ -865,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, 
@@ -964,28 +992,6 @@ modest_ui_actions_on_sort (GtkAction *action,
        }
 }
 
-/** Check that an appropriate connection is open.
- */
-gboolean check_for_connection (const gchar *account_name)
-{
-       TnyDevice *device = modest_runtime_get_device ();
-
-/*
-       g_assert (TNY_IS_MAEMO_CONIC_DEVICE (device));
-       
-       TnyMaemoConicDevice *maemo_device = TNY_MAEMO_CONIC_DEVICE (device);
-*/
-       
-       if (tny_device_is_online (device))
-               return TRUE;
-       else {
-               modest_platform_connect_and_wait (NULL);
-               
-               /* TODO: Wait until a result. */
-               return TRUE;
-       }
-}
-
 /*
  * This function performs the send & receive required actions. The
  * window is used to create the mail operation. Typically it should
@@ -996,6 +1002,7 @@ void
 modest_ui_actions_do_send_receive (const gchar *account_name, ModestWindow *win)
 {
        gchar *acc_name = NULL;
+       ModestMailOperation *mail_op;
 
        /* If no account name was provided then get the current account, and if
           there is no current account then pick the default one: */
@@ -1012,33 +1019,12 @@ modest_ui_actions_do_send_receive (const gchar *account_name, ModestWindow *win)
        }
 
        /* Send & receive. */
-       
-       /* Do not continue if no suitable connection
-          is open */
-       if (!check_for_connection (acc_name)) {
-               g_free (acc_name);
-               return;
-       }
-       
-       /* TODO: Do not continue if an operation is already in progress:
-        * Maybe there are some operations that tinymail allows to 
-        * happen simulatenously.
-        * TODO: Maybe a simple global gboolean is_updating is enough?
-        * murrayc.
-        */
-       
-       /* As per the UI spec,
-        * Store:
-        * - for POP accounts, we should receive,
-        * - for IMAP we should synchronize everything, including receiving,
-        * Transport:
-        * - for SMTP we should send.
-        * First receiving (store), then sending (transport):
-        */
        /* TODO: The spec wants us to first do any pending deletions, before receiving. */
-
-       /* Receive, by creating the mail operation */
-       ModestMailOperation *mail_op;
+       /* Receive and then send. The operation is tagged initially as
+          a receive operation because the account update performs a
+          receive and then a send. The operation changes its type
+          internally, so the progress objects will receive the proper
+          progress information */
        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);
        modest_mail_operation_update_account (mail_op, acc_name);
@@ -1208,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 {
@@ -1744,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;
@@ -1775,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));
        }
 
@@ -2511,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"));
 }
 
 /*
@@ -2571,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 */
@@ -2611,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);
 }
@@ -2798,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);
 
@@ -2806,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);     
+}