* Add a error_handler for send_receive operation.
authorJavier Fernandez Garcia-Boente <jfernandez@igalia.com>
Sat, 30 Jun 2007 11:49:10 +0000 (11:49 +0000)
committerJavier Fernandez Garcia-Boente <jfernandez@igalia.com>
Sat, 30 Jun 2007 11:49:10 +0000 (11:49 +0000)
* Review dimming rules of 'Cancel sending' command.
* Fixes: NB#61952

pmo-trunk-r2507

src/maemo/modest-main-window.c
src/modest-ui-actions.c
src/modest-ui-actions.h
src/modest-ui-dimming-rules.c
src/widgets/modest-main-window.h

index 921cfc2..fd3beda 100644 (file)
@@ -1536,13 +1536,29 @@ create_details_widget (GtkWidget *styled_widget, TnyAccount *account)
        return vbox;
 }
 
+gboolean
+modest_main_window_send_receive_in_progress (ModestMainWindow *self)
+{
+       ModestMainWindowPrivate *priv = NULL;
+       
+       g_return_val_if_fail (MODEST_IS_MAIN_WINDOW (self), FALSE);
+
+       priv = MODEST_MAIN_WINDOW_GET_PRIVATE(self);
+
+       return priv->send_receive_in_progress;
+}
+
 void 
 modest_main_window_notify_send_receive_initied (ModestMainWindow *self)
 {
        GtkAction *action = NULL;
        GtkWidget *widget = NULL;
-
+       ModestMainWindowPrivate *priv = NULL;
+               
        g_return_if_fail (MODEST_IS_MAIN_WINDOW (self));
+       priv = MODEST_MAIN_WINDOW_GET_PRIVATE(self);
+       
+       priv->send_receive_in_progress  = TRUE;
 
         action = modest_window_get_action (MODEST_WINDOW(self), "/MenuBar/ToolsMenu/ToolsSendReceiveMainMenu/ToolsSendReceiveAllMenu");        
        gtk_action_set_sensitive (action, FALSE);
@@ -1557,8 +1573,12 @@ modest_main_window_notify_send_receive_completed (ModestMainWindow *self)
 {
        GtkAction *action = NULL;
        GtkWidget *widget = NULL;
-
+       ModestMainWindowPrivate *priv = NULL;
+               
        g_return_if_fail (MODEST_IS_MAIN_WINDOW (self));
+       priv = MODEST_MAIN_WINDOW_GET_PRIVATE(self);
+
+       priv->send_receive_in_progress  = FALSE;
 
         action = modest_window_get_action (MODEST_WINDOW(self), "/MenuBar/ToolsMenu/ToolsSendReceiveMainMenu/ToolsSendReceiveAllMenu");        
        gtk_action_set_sensitive (action, TRUE);
index bff8e5b..012eea8 100644 (file)
@@ -361,16 +361,19 @@ modest_ui_actions_on_quit (GtkAction *action, ModestWindow *win)
 void
 modest_ui_actions_on_close_window (GtkAction *action, ModestWindow *win)
 {
-       if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
-               gtk_widget_destroy (GTK_WIDGET (win));
-       } else if (MODEST_IS_MSG_EDIT_WINDOW (win)) {
-               gboolean ret_value;
-               g_signal_emit_by_name (G_OBJECT (win), "delete-event", NULL, &ret_value);
-       } else if (MODEST_IS_WINDOW (win)) {
-               gtk_widget_destroy (GTK_WIDGET (win));
-       } else {
-               g_return_if_reached ();
-       }
+       gboolean ret_value;
+       g_signal_emit_by_name (G_OBJECT (win), "delete-event", NULL, &ret_value);
+
+/*     if (MODEST_IS_MSG_VIEW_WINDOW (win)) { */
+/*             gtk_widget_destroy (GTK_WIDGET (win)); */
+/*     } else if (MODEST_IS_MSG_EDIT_WINDOW (win)) { */
+/*             gboolean ret_value; */
+/*             g_signal_emit_by_name (G_OBJECT (win), "delete-event", NULL, &ret_value); */
+/*     } else if (MODEST_IS_WINDOW (win)) { */
+/*             gtk_widget_destroy (GTK_WIDGET (win)); */
+/*     } else { */
+/*             g_return_if_reached (); */
+/*     } */
 }
 
 void
@@ -1191,7 +1194,12 @@ modest_ui_actions_do_send_receive (const gchar *account_name, ModestWindow *win)
        /* Set send/receive operation in progress */    
        modest_main_window_notify_send_receive_initied (MODEST_MAIN_WINDOW(win));
 
-       mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_TYPE_RECEIVE, G_OBJECT(win));
+/*     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_OPEN,
+                                                                G_OBJECT (win),
+                                                                modest_ui_actions_send_receive_error_handler,
+                                                                NULL);
+
        g_signal_connect (G_OBJECT(mail_op), "progress-changed", 
                          G_CALLBACK (_on_send_receive_progress_changed), 
                          win);
@@ -2897,6 +2905,25 @@ modest_ui_actions_move_folder_error_handler (ModestMailOperation *mail_op,
        g_object_unref (win);
 }
 
+void
+modest_ui_actions_send_receive_error_handler (ModestMailOperation *mail_op, 
+                                             gpointer user_data)
+{
+       GObject *win = modest_mail_operation_get_source (mail_op);
+       const GError *error = modest_mail_operation_get_error (mail_op);
+
+       g_return_if_fail (error != NULL);
+       if (error->message != NULL)             
+               g_printerr ("modest: %s\n", error->message);
+       else
+               g_printerr ("modest: unkonw error on sedn&receive operation");
+
+       /* Show error message */
+       modest_platform_run_information_dialog ((win) ? GTK_WINDOW (win) : NULL,
+                                               _CS("sfil_ib_unable_to_send")); 
+/*     g_object_unref (win); */
+}
+
 static void
 open_msg_for_purge_cb (ModestMailOperation *mail_op, 
                       TnyHeader *header, 
index a0dcd51..868a672 100644 (file)
@@ -375,6 +375,16 @@ modest_ui_actions_check_toolbar_dimming_rules (ModestWindow *window);
  **/
 void     modest_ui_actions_move_folder_error_handler      (ModestMailOperation *mail_op, 
                                                           gpointer user_data);
+/**
+ * modest_ui_actions_send-receive_error_handler:
+ * @mail_op: a #ModestMailOperation
+ * @user_data: user data
+ * 
+ * manages an error in a mail operation that tries to execute
+ * a send&receive operation.
+ **/
+void     modest_ui_actions_send_receive_error_handler      (ModestMailOperation *mail_op, 
+                                                           gpointer user_data);
 
 /**
  * modest_ui_actions_on_search_messages:
index d3c620d..94c7919 100644 (file)
@@ -986,12 +986,34 @@ modest_ui_dimming_rules_on_tools_smtp_servers (ModestWindow *win, gpointer user_
 gboolean 
 modest_ui_dimming_rules_on_cancel_sending (ModestWindow *win, gpointer user_data)
 {
+       ModestDimmingRule *rule = NULL;
+       TnyFolderType types[1];
+       guint n_messages = 0;
        gboolean dimmed = FALSE;
 
-       /* Check dimmed rule */ 
-       if (!dimmed) 
+       g_return_val_if_fail (MODEST_IS_MAIN_WINDOW(win), FALSE);
+       g_return_val_if_fail (MODEST_IS_DIMMING_RULE (user_data), FALSE);
+       rule = MODEST_DIMMING_RULE (user_data);
+
+       types[0] = TNY_FOLDER_TYPE_OUTBOX; 
+
+       /* Check dimmed rules */        
+       if (!dimmed) {
+               dimmed = _already_opened_msg (win, &n_messages);
+               if (dimmed) 
+                       modest_dimming_rule_set_notification (rule, _("mcen_ib_message_unableto_cancel_send"));
+       }
+       if (!dimmed) {
+               dimmed = !_selected_folder_is_any_of_type (win, types, 1);
+               if (dimmed) 
+                       modest_dimming_rule_set_notification (rule, "");
+       }
+       if (!dimmed) {
                dimmed = !_sending_in_progress (win);
-               
+               if (dimmed) 
+                       modest_dimming_rule_set_notification (rule, "");
+       }
+
        return dimmed;
 }
 
@@ -1808,27 +1830,12 @@ _selected_msg_sent_in_progress (ModestWindow *win)
 static gboolean
 _sending_in_progress (ModestWindow *win)
 {
-       ModestTnySendQueue *send_queue = NULL;
-       ModestTnyAccountStore *acc_store = NULL;
-       TnyAccount *account = NULL;
-       const gchar *account_name = NULL;
        gboolean result = FALSE;
        
-       /* Get transport account */
-       acc_store = modest_runtime_get_account_store();
-       account_name = modest_window_get_active_account (win);
-
-       /* If no account defined, this action must be always dimmed  */
-       if (account_name == NULL) return FALSE;
-       account = modest_tny_account_store_get_transport_account_for_open_connection (acc_store, account_name);
-       if (!TNY_IS_TRANSPORT_ACCOUNT (account)) return FALSE;
-
-       /* Get send queue for current ransport account */
-       send_queue = modest_runtime_get_send_queue (TNY_TRANSPORT_ACCOUNT(account));
-       g_return_val_if_fail (MODEST_IS_TNY_SEND_QUEUE (send_queue), FALSE);
+       g_return_val_if_fail (MODEST_IS_MAIN_WINDOW (win), FALSE);
 
-       /* Check if send queue is perfimring any send operation */
-       result = modest_tny_send_queue_sending_in_progress (send_queue);
+       /* Check if send operation is in progress */
+       result = modest_main_window_send_receive_in_progress (MODEST_MAIN_WINDOW (win));
 
        return result;
 }
index 3f4d162..1730bbe 100644 (file)
@@ -190,6 +190,19 @@ ModestMainWindowContentsStyle modest_main_window_get_contents_style (ModestMainW
  * modest_main_window_notify_send_receive_initied:
  * @self: the #ModestMainWindow
  * 
+ * Determines if send&receive operaiton is currently in 
+ * progress.
+ *
+ * Returns: TRUE if send$receive operaton is in 
+ * progress, FALSE otherwise.
+ **/
+gboolean
+modest_main_window_send_receive_in_progress (ModestMainWindow *self);
+
+/**
+ * modest_main_window_notify_send_receive_initied:
+ * @self: the #ModestMainWindow
+ * 
  * Notifies main window that send/receive operaiton was just started. 
  **/
 void