2007-05-28 Murray Cumming <murrayc@murrayc.com>
[modest] / src / modest-ui-actions.c
index 348b2b8..f05af2b 100644 (file)
@@ -391,11 +391,22 @@ modest_ui_actions_on_smtp_servers (GtkAction *action, ModestWindow *win)
 #ifdef MODEST_PLATFORM_MAEMO /* Defined in config.h */
        
        /* Create the window if necessary: */
+       const gchar *active_account_name = modest_window_get_active_account (win);
+       
+       /* TODO: Dim the menu item (not in the UI spec)? or show a warning,
+        * or show the default account?
+        * If we show the default account then the account name should be shown in 
+        * the window when we show it. */
+       if (!active_account_name) {
+               g_warning ("%s: No account is active.", __FUNCTION__);
+               return;
+       }
+               
        GtkWidget *specific_window = GTK_WIDGET (modest_connection_specific_smtp_window_new ());
        modest_connection_specific_smtp_window_fill_with_connections (
                MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (specific_window), 
                modest_runtime_get_account_mgr(), 
-               modest_window_get_active_account (win));
+               active_account_name);
 
        /* Show the window: */  
        gtk_window_set_transient_for (GTK_WINDOW (specific_window), GTK_WINDOW (win));
@@ -977,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
@@ -986,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)
@@ -1017,13 +1028,21 @@ 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 and then send:
+        * TODO: This API is strange: We create a receive operation, which is then converted to 
+        * a send operation. But we don't even seem to monitor the operation, so we maybe don't 
+        * even need to create it here.
+        * Also, do we use the window parameter at all?
+        */
        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);
@@ -1376,47 +1395,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,
@@ -1428,7 +1442,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));
@@ -1436,7 +1451,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));
 }