2007-05-25 Murray Cumming <murrayc@murrayc.com>
authorMurray Cumming <murrayc@murrayc.com>
Fri, 25 May 2007 11:07:29 +0000 (11:07 +0000)
committerMurray Cumming <murrayc@murrayc.com>
Fri, 25 May 2007 11:07:29 +0000 (11:07 +0000)
* src/modest-tny-account.c:
        (modest_tny_account_new_from_server_account):
        Call modest_runtime_get_send_queue() immediately after creating transport
        accounts, so that they start trying to send email from the outbox as soon
        as possible at startup. This is probably what we want.

        * src/modest-mail-operation.c: (update_account_thread):
        * src/modest-runtime.c: (modest_runtime_get_send_queue):
        * src/modest-tny-send-queue.c: (modest_tny_send_queue_try_to_send):
        * src/modest-tny-send-queue.h:
        * src/modest-ui-actions.c: (modest_ui_actions_do_send_receive),
        (modest_ui_actions_on_send):
        Added comments about how sending works, though it needs some more work.

pmo-trunk-r1976

ChangeLog2
src/modest-mail-operation.c
src/modest-runtime.c
src/modest-tny-account.c
src/modest-tny-send-queue.c
src/modest-tny-send-queue.h
src/modest-ui-actions.c

index 9c5607d..cf9002f 100644 (file)
@@ -1,6 +1,22 @@
 2007-05-25  Murray Cumming  <murrayc@murrayc.com>
 
        * src/modest-tny-account.c:
+       (modest_tny_account_new_from_server_account): 
+       Call modest_runtime_get_send_queue() immediately after creating transport 
+       accounts, so that they start trying to send email from the outbox as soon 
+       as possible at startup. This is probably what we want.
+       
+       * src/modest-mail-operation.c: (update_account_thread):
+       * src/modest-runtime.c: (modest_runtime_get_send_queue):
+       * src/modest-tny-send-queue.c: (modest_tny_send_queue_try_to_send):
+       * src/modest-tny-send-queue.h:
+       * src/modest-ui-actions.c: (modest_ui_actions_do_send_receive),
+       (modest_ui_actions_on_send):
+       Added comments about how sending works, though it needs some more work.
+
+2007-05-25  Murray Cumming  <murrayc@murrayc.com>
+
+       * src/modest-tny-account.c:
        (modest_tny_account_get_special_folder): Add TODO because this fails when 
        the network is busy.
        (modest_tny_folder_store_get_local_size):  Fix an incorrect type check.
index 5c91b9e..38873bd 100644 (file)
@@ -749,8 +749,6 @@ update_account_thread (gpointer thr_user_data)
        TnyIterator *iter = NULL;
        TnyFolderStoreQuery *query = NULL;
        ModestMailOperationPrivate *priv;
-       ModestTnySendQueue *send_queue;
-       gint timeout, msg_num;
 
        info = (UpdateAccountInfo *) thr_user_data;
        priv = MODEST_MAIL_OPERATION_GET_PRIVATE(info->mail_op);
@@ -784,7 +782,7 @@ update_account_thread (gpointer thr_user_data)
           Gtk+. We use a timeout in order to provide more status
           information, because the sync tinymail call does not
           provide it for the moment */
-       timeout = g_timeout_add (250, idle_notify_progress, info->mail_op);
+       gint timeout = g_timeout_add (250, idle_notify_progress, info->mail_op);
 
        /* Refresh folders */
        new_headers = tny_simple_list_new ();
@@ -832,7 +830,7 @@ update_account_thread (gpointer thr_user_data)
        /* Apply message count limit */
        /* TODO if the number of messages exceeds the maximum, ask the
           user to download them all */
-       msg_num = 0;
+       gint msg_num = 0;
        priv->total = MIN (tny_list_get_length (new_headers), info->retrieve_limit);
        iter = tny_list_create_iterator (new_headers);
        while ((msg_num < info->retrieve_limit) && !tny_iterator_is_done (iter)) {
@@ -862,15 +860,18 @@ update_account_thread (gpointer thr_user_data)
        g_object_unref (iter);
        g_object_unref (new_headers);
 
+
        /* Perform send */
        priv->op_type = MODEST_MAIL_OPERATION_TYPE_SEND;
        priv->done = 0;
        priv->total = 0;
 
-       send_queue = modest_tny_send_queue_new (TNY_CAMEL_TRANSPORT_ACCOUNT(info->transport_account));
+       ModestTnySendQueue *send_queue = modest_runtime_get_send_queue
+               (info->transport_account);
 
        timeout = g_timeout_add (250, idle_notify_progress, info->mail_op);
-       modest_tny_send_queue_flush (send_queue);
+       /* TODO: Is this meant to block? */
+       modest_tny_send_queue_try_to_send (send_queue);
        g_source_remove (timeout);
 
        g_object_unref (G_OBJECT(send_queue));
index 66a206d..338cbf5 100644 (file)
@@ -144,6 +144,7 @@ modest_runtime_get_platform_factory  (void)
 ModestTnySendQueue*
 modest_runtime_get_send_queue  (TnyTransportAccount *account)
 {
+       /* printf ("DEBUG: %s: transport account id=%s\n", __FUNCTION__, tny_account_get_id (TNY_ACCOUNT(account))); */
        ModestCacheMgr *cache_mgr;
        GHashTable     *send_queue_cache;
        gpointer       orig_key, send_queue;
@@ -155,8 +156,15 @@ modest_runtime_get_send_queue  (TnyTransportAccount *account)
        send_queue_cache = modest_cache_mgr_get_cache (cache_mgr,
                                                       MODEST_CACHE_MGR_CACHE_TYPE_SEND_QUEUE);
 
+       /* Each transport account has its own send queue.
+        * Note that each transport account will have its own outbox folder, 
+        * returned by TnySendQueue::get_outbox_func().
+        */
        if (!g_hash_table_lookup_extended (send_queue_cache, account, &orig_key, &send_queue)) {
+               /* Note that this send queue will start sending messages from its outbox 
+                * as soon as it is instantiated: */
                send_queue = (gpointer)modest_tny_send_queue_new (TNY_CAMEL_TRANSPORT_ACCOUNT(account));
+
                g_hash_table_insert (send_queue_cache, account, send_queue);
        }
 
index c4b379a..9464edf 100644 (file)
@@ -303,6 +303,15 @@ modest_tny_account_new_from_server_account (ModestAccountMgr *account_mgr,
        g_free (url);
        /***********************/
        
+       /* For transport accounts, now is a good time to create the send queues, 
+        * so that the send queues start trying as soon as possible to send any 
+        * messages that are already in their outboxes: */
+       if ( (account_data->proto == MODEST_PROTOCOL_TRANSPORT_SENDMAIL) ||
+            (account_data->proto == MODEST_PROTOCOL_TRANSPORT_SMTP) ) {
+               /* modest_runtime_get_send_queue() instantiates and stores the send queue: */
+               modest_runtime_get_send_queue( TNY_TRANSPORT_ACCOUNT (tny_account));
+       }
+       
        return tny_account;
 }
 
index 8d0acaa..8fad46e 100644 (file)
@@ -203,7 +203,9 @@ modest_tny_send_queue_new (TnyCamelTransportAccount *account)
 
 
 void
-modest_tny_send_queue_flush (ModestTnySendQueue* self)
+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)); */
 }
index 148797d..41ecdfc 100644 (file)
@@ -82,13 +82,15 @@ ModestTnySendQueue*    modest_tny_send_queue_new        (TnyCamelTransportAccoun
 
 
 /**
- * modest_tny_send_queue_flush:
+ * modest_tny_send_queue_try_to_send:
  * @self: a valid #ModestTnySendQueue instance
  * 
- * (try to) send the messages in the outbox folder 
- * 
+ * Try to send the messages that are in the queue's outbox folder.
+ * This is not always necessary because the queue tries to send 
+ * messages as soon as a message is added, and as soon as the queue 
+ * is instantiated.
  */
-void modest_tny_send_queue_flush (ModestTnySendQueue* self);
+void modest_tny_send_queue_try_to_send (ModestTnySendQueue* self);
 
 
 G_END_DECLS
index 3638194..fc09b38 100644 (file)
@@ -988,8 +988,8 @@ gboolean check_for_connection (const gchar *account_name)
 
 /*
  * This function performs the send & receive required actions. The
- * window it's used to create the mail operation. Tipically it should
- * be allways the main window, but we pass it as argument in order to
+ * window is used to create the mail operation. Typically it should
+ * always be the main window, but we pass it as argument in order to
  * be more flexible.
  */
 void
@@ -997,8 +997,8 @@ modest_ui_actions_do_send_receive (const gchar *account_name, ModestWindow *win)
 {
        gchar *acc_name = NULL;
 
-       /* If no account name was provided get the current account, if
-          there is none either then pick the default one */
+       /* If no account name was provided then get the current account, and if
+          there is no current account then pick the default one: */
        if (!account_name) {
                acc_name = g_strdup (modest_window_get_active_account(win));
                if (!acc_name)
@@ -1028,13 +1028,16 @@ modest_ui_actions_do_send_receive (const gchar *account_name, ModestWindow *win)
         */
        
        /* As per the UI spec,
-        * for POP accounts, we should receive,
-        * for IMAP we should synchronize everything, including receiving,
-        * for SMTP we should send,
-        * first receiving, then sending:
+        * 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):
         */
-       /* Create the mail operation */
        /* TODO: The spec wants us to first do any pending deletions, before receiving. */
+
+       /* Receive, by creating the mail operation */
        ModestMailOperation *mail_op;
        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);
@@ -1387,47 +1390,42 @@ modest_ui_actions_on_save_to_drafts (GtkWidget *widget, ModestMsgEditWindow *edi
 void
 modest_ui_actions_on_send (GtkWidget *widget, ModestMsgEditWindow *edit_window)
 {
-       TnyTransportAccount *transport_account;
-       ModestMailOperation *mail_operation;
-       MsgData *data;
-       gchar *account_name, *from;
-       ModestAccountMgr *account_mgr;
-
        g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW(edit_window));
 
        if (!modest_msg_edit_window_check_names (edit_window))
                return;
        
-       data = modest_msg_edit_window_get_msg_data (edit_window);
-
        /* FIXME: Code added just for testing. The final version will
           use the send queue provided by tinymail and some
           classifier */
-       account_mgr = modest_runtime_get_account_mgr();
-       account_name = g_strdup(modest_window_get_active_account (MODEST_WINDOW(edit_window)));
+       ModestAccountMgr *account_mgr = modest_runtime_get_account_mgr();
+       gchar *account_name = g_strdup(modest_window_get_active_account (MODEST_WINDOW(edit_window)));
        if (!account_name) 
                account_name = modest_account_mgr_get_default_account (account_mgr);
+               
        if (!account_name) {
                g_printerr ("modest: no account found\n");
-               modest_msg_edit_window_free_msg_data (edit_window, data);
                return;
        }
-       transport_account =
+       
+       /* Get the currently-active transport account for this modest account: */
+       TnyTransportAccount *transport_account =
                TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_transport_account_for_open_connection
                                      (modest_runtime_get_account_store(),
                                       account_name));
        if (!transport_account) {
                g_printerr ("modest: no transport account found for '%s'\n", account_name);
                g_free (account_name);
-               modest_msg_edit_window_free_msg_data (edit_window, data);
                return;
        }
-       from = modest_account_mgr_get_from_string (account_mgr, account_name);
+       
+       gchar *from = modest_account_mgr_get_from_string (account_mgr, account_name);
 
-       /* Create the mail operation */         
-       mail_operation = modest_mail_operation_new (MODEST_MAIL_OPERATION_TYPE_SEND, G_OBJECT(edit_window));
+       /* Create the mail operation */
+       ModestMailOperation *mail_operation = modest_mail_operation_new (MODEST_MAIL_OPERATION_TYPE_SEND, G_OBJECT(edit_window));
        modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_operation);
 
+       MsgData *data = modest_msg_edit_window_get_msg_data (edit_window);
        modest_mail_operation_send_new_mail (mail_operation,
                                             transport_account,
                                             from,
@@ -1439,7 +1437,8 @@ modest_ui_actions_on_send (GtkWidget *widget, ModestMsgEditWindow *edit_window)
                                             data->html_body,
                                             data->attachments,
                                             data->priority_flags);
-       /* Frees */
+                                            
+       /* Free data: */
        g_free (from);
        g_free (account_name);
        g_object_unref (G_OBJECT (transport_account));
@@ -1447,7 +1446,7 @@ modest_ui_actions_on_send (GtkWidget *widget, ModestMsgEditWindow *edit_window)
 
        modest_msg_edit_window_free_msg_data (edit_window, data);
 
-       /* Save settings and close the window */
+       /* Save settings and close the window: */
        gtk_widget_destroy (GTK_WIDGET (edit_window));
 }