* Uncomment flush call to tny_send_queue.
authorJavier Fernandez Garcia-Boente <jfernandez@igalia.com>
Fri, 6 Jul 2007 17:51:08 +0000 (17:51 +0000)
committerJavier Fernandez Garcia-Boente <jfernandez@igalia.com>
Fri, 6 Jul 2007 17:51:08 +0000 (17:51 +0000)
* Implement cancel sending operation, seting the
TNY_HEADER_FLAG_SUSPENDED_PRIORITY flag.

pmo-trunk-r2619

src/maemo/modest-main-window-ui.h
src/maemo/modest-main-window.c
src/modest-mail-operation.c
src/modest-tny-send-queue.c
src/modest-ui-actions.c
src/modest-ui-actions.h
src/widgets/modest-header-view-render.c

index 54b87f0..caf3ce7 100644 (file)
@@ -97,7 +97,7 @@ static const GtkActionEntry modest_action_entries [] = {
        { "ToolsSMTPServers",     NULL,      N_("mcen_me_inbox_globalsmtpservers"),                NULL, NULL,  G_CALLBACK(modest_ui_actions_on_smtp_servers) },
        { "ToolsSendReceive", NULL, N_("mcen_me_inbox_sendandreceive") }, /* submenu */
        { "ToolsSendReceiveAll",    NULL,      N_("mcen_me_inbox_sendandreceive_all"),          NULL, NULL, G_CALLBACK (modest_ui_actions_on_send_receive) },
-       { "ToolsSendReceiveCancelSending",  NULL,      N_("mcen_me_outbox_cancelsend"),        NULL, NULL,  NULL },
+       { "ToolsSendReceiveCancelSending",  NULL,      N_("mcen_me_outbox_cancelsend"),        NULL, NULL,  G_CALLBACK (modest_ui_actions_cancel_send) },
        { "ToolsContacts",            NULL,      N_("mcen_me_inbox_open_addressbook"),                      NULL, NULL,  G_CALLBACK (modest_ui_actions_on_open_addressbook) },
        { "ToolsAddToContacts",            NULL,      N_("mcen_me_viewer_addtocontacts"),                      NULL, NULL,  G_CALLBACK (modest_ui_actions_on_add_to_contacts) },
        { "ToolsSearchMessages",            NULL,      N_("mcen_me_inbox_search"),                      NULL, NULL,  G_CALLBACK (modest_ui_actions_on_search_messages) },
index 5281a49..d413712 100644 (file)
@@ -248,7 +248,7 @@ static const GtkActionEntry modest_header_view_action_entries [] = {
        { "HeaderViewCSMCopy",          NULL,  N_("mcen_me_inbox_copy"),        "<CTRL>C", NULL, G_CALLBACK (modest_ui_actions_on_copy) },
        { "HeaderViewCSMPaste",         NULL,  N_("mcen_me_inbox_paste"),       "<CTRL>V", NULL, G_CALLBACK (modest_ui_actions_on_paste) },
        { "HeaderViewCSMDelete",        NULL,  N_("mcen_me_inbox_delete"),      NULL,      NULL, G_CALLBACK (modest_ui_actions_on_delete) },
-       { "HeaderViewCSMCancelSending", NULL,  N_("mcen_me_outbox_cancelsend"), NULL,      NULL, NULL },
+       { "HeaderViewCSMCancelSending", NULL,  N_("mcen_me_outbox_cancelsend"), NULL,      NULL, G_CALLBACK (modest_ui_actions_cancel_send) },
        { "HeaderViewCSMHelp",          NULL,  N_("mcen_me_inbox_help"),        NULL,      NULL, G_CALLBACK (modest_ui_actions_on_help) },
 };
 
index 114cd7b..8f4cb07 100644 (file)
@@ -1094,7 +1094,8 @@ update_account_thread (gpointer thr_user_data)
                g_ptr_array_free (new_headers, FALSE);
        }
        
-       /* Perform send */
+       /* Perform send (if operation was not cancelled) */
+       if (did_a_cancel) goto out;             
        priv->op_type = MODEST_MAIL_OPERATION_TYPE_SEND;
        priv->done = 0;
        priv->total = 0;
index 57468a8..bbad202 100644 (file)
@@ -47,6 +47,8 @@ static void modest_tny_send_queue_instance_init (GTypeInstance *instance, gpoint
 static void _on_msg_has_been_sent (TnySendQueue *self, TnyMsg *msg, gpointer user_data);
 static void _on_msg_error_happened (TnySendQueue *self, TnyHeader *header, TnyMsg *msg, GError *err, gpointer user_data);
 
+static TnyFolder*modest_tny_send_queue_get_outbox (TnySendQueue *self);
+static TnyFolder*modest_tny_send_queue_get_sentbox (TnySendQueue *self);
 
 /* list my signals  */
 enum {
@@ -127,6 +129,28 @@ modest_tny_send_queue_cancel (TnySendQueue *self, gboolean remove, GError **err)
                g_signal_emit (self, signals[STATUS_CHANGED], 0, info->msg_id, info->status);
        }
 
+       /* Set flags to supend sending operaiton (if removed, this is not necessary) */
+       if (!remove) {
+               TnyIterator *iter = NULL;
+               TnyFolder *outbox = NULL;
+               TnyList *headers = tny_simple_list_new ();
+               outbox = modest_tny_send_queue_get_outbox (self);
+               tny_folder_get_headers (outbox, headers, TRUE, err);
+               if (err != NULL && *err != NULL) goto frees;
+               iter = tny_list_create_iterator (headers);
+               while (!tny_iterator_is_done (iter)) {
+                       TnyHeader *header = TNY_HEADER (tny_iterator_get_current (iter));
+                       tny_header_unset_flags (header, TNY_HEADER_FLAG_PRIORITY);
+                       tny_header_set_flags (header, TNY_HEADER_FLAG_SUSPENDED_PRIORITY);
+                       g_object_unref (header);
+                       tny_iterator_next (iter);
+               }
+       frees:
+               g_object_unref (G_OBJECT (headers));
+               g_object_unref (G_OBJECT (outbox));
+       }
+               
+       /* Dont call super class implementaiton, becasue camel removes messages from outbox */
        TNY_CAMEL_SEND_QUEUE_CLASS(parent_class)->cancel_func (self, remove, err); /* FIXME */
 }
 
@@ -334,9 +358,8 @@ modest_tny_send_queue_new (TnyCamelTransportAccount *account)
 void
 modest_tny_send_queue_try_to_send (ModestTnySendQueue* self)
 {
-       /* TODO: Rename this to tny_camel_send_queue_try_to_send() in tinymail 
-       and check that it works, without creating a second worker. */
-/*     tny_camel_send_queue_flush (TNY_CAMEL_SEND_QUEUE(self)); */
+       /* Flush send queue */
+       tny_camel_send_queue_flush (TNY_CAMEL_SEND_QUEUE(self));
 }
 
 gboolean
index d0bb2aa..4ea00fd 100644 (file)
@@ -1342,6 +1342,76 @@ modest_ui_actions_do_send_receive (const gchar *account_name, ModestWindow *win)
        g_free (acc_name);
 }
 
+
+static void
+modest_ui_actions_do_cancel_send (const gchar *account_name,  
+                                 ModestWindow *win)
+{
+       TnyTransportAccount *transport_account;
+       TnySendQueue *send_queue = NULL;
+       GError *error = NULL;
+
+       /* Get transport account */
+       transport_account =
+               TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_server_account
+                                     (modest_runtime_get_account_store(),
+                                      account_name,
+                                      TNY_ACCOUNT_TYPE_TRANSPORT));
+       if (!transport_account) {
+               g_printerr ("modest: no transport account found for '%s'\n", account_name);
+               goto frees;
+       }
+
+       /* Get send queue*/
+       send_queue = TNY_SEND_QUEUE (modest_runtime_get_send_queue (transport_account));
+       if (!TNY_IS_SEND_QUEUE(send_queue)) {
+               g_set_error (&error, MODEST_MAIL_OPERATION_ERROR,
+                            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);
+       }       
+
+ frees:
+       if (transport_account != NULL) 
+               g_object_unref (G_OBJECT (transport_account));
+}
+
+static void
+modest_ui_actions_cancel_send_all (ModestWindow *win) 
+{
+       GSList *account_names, *iter;
+
+       account_names = modest_account_mgr_account_names (modest_runtime_get_account_mgr(), 
+                                                         TRUE);
+
+       iter = account_names;
+       while (iter) {                  
+               modest_ui_actions_do_cancel_send ((const char*) iter->data, win);
+               iter = g_slist_next (iter);
+       }
+
+       modest_account_mgr_free_account_names (account_names);
+       account_names = NULL;
+}
+
+void
+modest_ui_actions_cancel_send (GtkAction *action,  ModestWindow *win)
+
+{
+       /* Check if accounts exist */
+       gboolean accounts_exist = 
+               modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE);
+       
+       /* If not, allow the user to create an account before trying to send/receive. */
+       if (!accounts_exist)
+               modest_ui_actions_on_accounts (NULL, win);
+       
+       /* Cancel all sending operaitons */     
+       modest_ui_actions_cancel_send_all (win);
+}
+
 /*
  * Refreshes all accounts. This function will be used by automatic
  * updates
index f95bfba..d8f14a8 100644 (file)
@@ -186,6 +186,8 @@ void     modest_ui_actions_on_mark_as_read            (GtkAction *action,
 void     modest_ui_actions_on_mark_as_unread            (GtkAction *action,
                                                         ModestWindow *window);
 
+void     modest_ui_actions_cancel_send (GtkAction *action,  ModestWindow *win);
+
 /**
  * modest_ui_actions_do_send_receive_all:
  * @win: the window that will be used as source of the refresh mail operation
index 301047f..1d027f6 100644 (file)
@@ -47,31 +47,31 @@ fill_list_of_caches (gpointer key, gpointer value, gpointer userdata)
        *send_queues = g_slist_prepend (*send_queues, value);
 }
 
-static ModestTnySendQueueStatus
-get_status_of_uid (const gchar *uid)
-{
-       ModestCacheMgr *cache_mgr;
-       GHashTable     *send_queue_cache;
-       GSList *send_queues = NULL, *node;
-       /* get_msg_status returns suspended by default, so we want to detect changes */
-       ModestTnySendQueueStatus status = MODEST_TNY_SEND_QUEUE_SUSPENDED;
+/* static ModestTnySendQueueStatus */
+/* get_status_of_uid (const gchar *uid) */
+/* { */
+/*     ModestCacheMgr *cache_mgr; */
+/*     GHashTable     *send_queue_cache; */
+/*     GSList *send_queues = NULL, *node; */
+/*     /\* get_msg_status returns suspended by default, so we want to detect changes *\/ */
+/*     ModestTnySendQueueStatus status = MODEST_TNY_SEND_QUEUE_SUSPENDED; */
        
-       cache_mgr = modest_runtime_get_cache_mgr ();
-       send_queue_cache = modest_cache_mgr_get_cache (cache_mgr,
-                                                      MODEST_CACHE_MGR_CACHE_TYPE_SEND_QUEUE);
-
-       g_hash_table_foreach (send_queue_cache, (GHFunc) fill_list_of_caches, &send_queues);
-
-       for (node = send_queues; node != NULL; node = g_slist_next (node)) {
-               ModestTnySendQueueStatus queue_status = modest_tny_send_queue_get_msg_status (
-                       MODEST_TNY_SEND_QUEUE (node->data), uid);
-               if (queue_status != MODEST_TNY_SEND_QUEUE_SUSPENDED)
-                       status = queue_status;
-               break;
-       }
-       g_slist_free (send_queues);
-       return status;
-}
+/*     cache_mgr = modest_runtime_get_cache_mgr (); */
+/*     send_queue_cache = modest_cache_mgr_get_cache (cache_mgr, */
+/*                                                    MODEST_CACHE_MGR_CACHE_TYPE_SEND_QUEUE); */
+
+/*     g_hash_table_foreach (send_queue_cache, (GHFunc) fill_list_of_caches, &send_queues); */
+
+/*     for (node = send_queues; node != NULL; node = g_slist_next (node)) { */
+/*             ModestTnySendQueueStatus queue_status = modest_tny_send_queue_get_msg_status ( */
+/*                     MODEST_TNY_SEND_QUEUE (node->data), uid); */
+/*             if (queue_status != MODEST_TNY_SEND_QUEUE_SUSPENDED) */
+/*                     status = queue_status; */
+/*             break; */
+/*     } */
+/*     g_slist_free (send_queues); */
+/*     return status; */
+/* } */
 
 static const gchar *
 get_status_string (ModestTnySendQueueStatus status)
@@ -252,7 +252,7 @@ void
 _modest_header_view_compact_header_cell_data  (GtkTreeViewColumn *column,  GtkCellRenderer *renderer,
                                               GtkTreeModel *tree_model,  GtkTreeIter *iter,  gpointer user_data)
 {
-       TnyHeaderFlags flags;
+       TnyHeaderFlags flags, prior_flags;
        gchar *address, *subject, *header;
        time_t date;
        ModestHeaderViewCompactHeaderMode header_mode;
@@ -289,6 +289,8 @@ _modest_header_view_compact_header_cell_data  (GtkTreeViewColumn *column,  GtkCe
                                    -1);
 
        /* flags */
+       flags = tny_header_get_flags (msg_header);
+       prior_flags = flags & TNY_HEADER_FLAG_PRIORITY;
        if (flags & TNY_HEADER_FLAG_ATTACHMENTS)
                g_object_set (G_OBJECT (attach_cell), "pixbuf",
                              get_pixbuf_for_flag (TNY_HEADER_FLAG_ATTACHMENTS),
@@ -298,7 +300,8 @@ _modest_header_view_compact_header_cell_data  (GtkTreeViewColumn *column,  GtkCe
                              NULL, NULL);
        if (flags & TNY_HEADER_FLAG_PRIORITY)
                g_object_set (G_OBJECT (priority_cell), "pixbuf",
-                             get_pixbuf_for_flag (flags & TNY_HEADER_FLAG_PRIORITY),
+                             get_pixbuf_for_flag (prior_flags),
+/*                           get_pixbuf_for_flag (flags & TNY_HEADER_FLAG_PRIORITY), */
                              NULL);
        else
                g_object_set (G_OBJECT (priority_cell), "pixbuf",
@@ -326,12 +329,15 @@ _modest_header_view_compact_header_cell_data  (GtkTreeViewColumn *column,  GtkCe
                ModestTnySendQueueStatus status = MODEST_TNY_SEND_QUEUE_WAITING;
                const gchar *status_str = "";
                if (msg_header != NULL) {
-                       status = get_status_of_uid (tny_header_get_message_id (msg_header));
+                       /* TODO: ask send queue for msg sending status */
+/*                     status = get_status_of_uid (tny_header_get_message_id (msg_header)); */
+                       if (prior_flags == TNY_HEADER_FLAG_SUSPENDED_PRIORITY)
+                               status = MODEST_TNY_SEND_QUEUE_SUSPENDED;
                }
                status_str = get_status_string (status);
                /* TODO: for now we set the status to waiting always, we need a way to
                 * retrieve the current send status of a message */
-               status_str = get_status_string (MODEST_TNY_SEND_QUEUE_WAITING);
+/*             status_str = get_status_string (MODEST_TNY_SEND_QUEUE_WAITING); */
                display_date = g_strdup_printf("<small>%s</small>", status_str);
                g_object_set (G_OBJECT (date_or_status_cell),
                              "markup", display_date,
@@ -386,17 +392,20 @@ _modest_header_view_status_cell_data  (GtkTreeViewColumn *column,  GtkCellRender
                                       GtkTreeModel *tree_model,  GtkTreeIter *iter,
                                       gpointer user_data)
 {
-        TnyHeaderFlags flags;
+        TnyHeaderFlags flags, prior_flags;
        //guint status;
        gchar *status_str;
        
        gtk_tree_model_get (tree_model, iter,
                            TNY_GTK_HEADER_LIST_MODEL_FLAGS_COLUMN, &flags,
-       //                  TNY_GTK_HEADER_LIST_MODEL_MESSAGE_SIZE_COLUMN, &status,
                            -1);
        
-       status_str = g_strdup(_("mcen_li_outbox_waiting"));
-       
+       prior_flags = flags & TNY_HEADER_FLAG_PRIORITY;
+       if (prior_flags == TNY_HEADER_FLAG_SUSPENDED_PRIORITY)
+              status_str = g_strdup(_("mcen_li_outbox_suspended"));
+       else           
+              status_str = g_strdup(_("mcen_li_outbox_waiting"));
+       
        g_object_set (G_OBJECT(renderer), "text", status_str, NULL);
        set_common_flags (renderer, flags);