* Migrated Modest to the new send queue API
[modest] / src / modest-ui-actions.c
index ea4cd48..110a26f 100644 (file)
@@ -398,7 +398,8 @@ modest_ui_actions_refresh_message_window_after_delete (ModestMsgViewWindow* win)
        if (modest_msg_view_window_last_message_selected (win) &&
                modest_msg_view_window_first_message_selected (win)) {
                modest_ui_actions_on_close_window (NULL, MODEST_WINDOW (win));
-       } else if (!modest_msg_view_window_select_next_message (win)) {
+       } else if (!modest_msg_view_window_select_next_message (win) &&
+                  !modest_msg_view_window_select_previous_message (win)) {
                gboolean ret_value;
                g_signal_emit_by_name (G_OBJECT (win), "delete-event", NULL, &ret_value);       
        }
@@ -1020,16 +1021,10 @@ modest_ui_actions_get_msgs_full_error_handler (ModestMailOperation *mail_op,
 {
        const GError *error;
        GObject *win = NULL;
-       const gchar *err_msg;
+       const gchar *err_msg = (const gchar *) user_data;
 
        win = modest_mail_operation_get_source (mail_op);
        error = modest_mail_operation_get_error (mail_op);
-       /* Select error message */
-       if (error->code == MODEST_MAIL_OPERATION_ERROR_MESSAGE_SIZE_LIMIT)
-               err_msg = _("emev_ni_ui_imap_msg_size_exceed_error");
-       else
-               err_msg = (const gchar *) user_data;
 
        /* Show error */
        modest_platform_run_information_dialog ((GtkWindow *) win, err_msg);
@@ -1680,7 +1675,7 @@ new_messages_arrived (ModestMailOperation *self,
           send&receive was invoked by the user then do not show any
           visual notification, only play a sound and activate the LED
           (for the Maemo version) */
-       if ((new_headers != NULL) && (tny_list_get_length (new_headers) > 0))
+       if (TNY_IS_LIST(new_headers) && (tny_list_get_length (new_headers)) > 0)
                modest_platform_on_new_headers_received (new_headers, 
                                                         show_visual_notifications);
 
@@ -1835,9 +1830,12 @@ modest_ui_actions_do_cancel_send (const gchar *account_name,
                             MODEST_MAIL_OPERATION_ERROR_ITEM_NOT_FOUND,
                             "modest: could not find send queue for account\n");
        } else {
-               /* Keeep messages in outbox folder */
-               tny_send_queue_cancel (send_queue, FALSE, &error);
-       }       
+               /* Cancel the current send */
+               tny_account_cancel (TNY_ACCOUNT (transport_account));
+
+               /* Suspend all pending messages */
+               tny_send_queue_cancel (send_queue, TNY_SEND_QUEUE_CANCEL_ACTION_SUSPEND, &error);
+       }
 
  frees:
        if (transport_account != NULL) 
@@ -3945,10 +3943,15 @@ on_move_to_dialog_folder_selection_changed (ModestFolderView* self,
 
                if ((gpointer) local_account != (gpointer) folder_store &&
                    (gpointer) mmc_account != (gpointer) folder_store) {
+                       const char *proto_name = tny_account_get_proto (TNY_ACCOUNT (folder_store));
+                       ModestTransportStoreProtocol proto = MODEST_PROTOCOL_STORE_MAILDIR;
+                       if (proto_name != NULL) {
+                               proto = modest_protocol_info_get_transport_store_protocol (proto_name);
+                       }
                        is_local_account = FALSE;
                        /* New button should be dimmed on remote
-                          account root */
-                       new_sensitive = FALSE;
+                          POP account root */
+                       new_sensitive = (proto != MODEST_PROTOCOL_STORE_POP);
                }
                g_object_unref (local_account);
        }
@@ -4259,10 +4262,14 @@ move_to_cb (ModestMailOperation *mail_op,
                if (MODEST_IS_MSG_VIEW_WINDOW (object)) {
                        ModestMsgViewWindow *self = MODEST_MSG_VIEW_WINDOW (object);
 
-                       if (!modest_msg_view_window_select_next_message (self))
-                               if (!modest_msg_view_window_select_previous_message (self))
-                                       /* No more messages to view, so close this window */
-                                       modest_ui_actions_on_close_window (NULL, MODEST_WINDOW(self));
+                       if (modest_msg_view_window_last_message_selected (self) &&
+                           modest_msg_view_window_first_message_selected (self)) {
+                               modest_ui_actions_on_close_window (NULL, MODEST_WINDOW (self));
+                       } else if (!modest_msg_view_window_select_next_message (self) &&
+                                  !modest_msg_view_window_select_previous_message (self)) {
+                               /* No more messages to view, so close this window */
+                               modest_ui_actions_on_close_window (NULL, MODEST_WINDOW(self));
+                       }
                } else if (MODEST_IS_MAIN_WINDOW (object) && helper->reference != NULL) {
                        GtkWidget *header_view;
                        GtkTreePath *path;
@@ -5257,7 +5264,7 @@ modest_ui_actions_on_send_queue_error_happened (TnySendQueue *self,
        gchar *message = NULL;
 
        /* Don't show anything if the user cancelled something */
-       if (err->code == TNY_TRANSPORT_ACCOUNT_ERROR_SEND_USER_CANCEL)
+       if (err->code == TNY_SYSTEM_ERROR_CANCEL)
                return;
 
        /* Get the server name: */
@@ -5274,20 +5281,17 @@ modest_ui_actions_on_send_queue_error_happened (TnySendQueue *self,
 
        /* Show the appropriate message text for the GError: */
        switch (err->code) {
-       case TNY_TRANSPORT_ACCOUNT_ERROR_SEND_HOST_LOOKUP_FAILED:
+       case TNY_SERVICE_ERROR_CONNECT:
                message = g_strdup_printf (_("emev_ib_ui_smtp_server_invalid"), server_name);
                break;
-       case TNY_TRANSPORT_ACCOUNT_ERROR_SEND_SERVICE_UNAVAILABLE:
-               message = g_strdup_printf (_("emev_ib_ui_smtp_server_invalid"), server_name);
-               break;
-       case TNY_TRANSPORT_ACCOUNT_ERROR_SEND_AUTHENTICATION_NOT_SUPPORTED:
+       case TNY_SERVICE_ERROR_AUTHENTICATE:
                message = g_strdup_printf (_("emev_ni_ui_smtp_authentication_fail_error"), server_name);
                break;
-       case TNY_TRANSPORT_ACCOUNT_ERROR_SEND:
+       case TNY_SERVICE_ERROR_SEND:
                message = g_strdup (_("emev_ib_ui_smtp_send_error"));
                break;
        default:
-               g_warning ("%s: unexpected TNY_TRANSPORT_ACCOUNT_ERROR %d",
+               g_warning ("%s: unexpected ERROR %d",
                           __FUNCTION__, err->code);
                message = g_strdup (_("emev_ib_ui_smtp_send_error"));
                break;  
@@ -5342,6 +5346,10 @@ modest_ui_actions_on_send_queue_status_changed (ModestTnySendQueue *send_queue,
 #else
        gtk_widget_queue_draw (header_view);
 #endif         
+
+       /* Rerun dimming rules, because the message could become deletable for example */
+       modest_window_check_dimming_rules_group (MODEST_WINDOW (main_window), 
+                                                MODEST_DIMMING_RULES_TOOLBAR);
        
        /* Free */
  frees: