2007-04-27 Murray Cumming <murrayc@murrayc.com>
authorMurray Cumming <murrayc@murrayc.com>
Fri, 27 Apr 2007 11:12:36 +0000 (11:12 +0000)
committerMurray Cumming <murrayc@murrayc.com>
Fri, 27 Apr 2007 11:12:36 +0000 (11:12 +0000)
* src/modest-tny-account-store.h:
        * src/modest-tny-account-store.c:
        Added modest_tny_account_store_get_transport_account_for_open_connection(), which respects
        the connection-specific SMTP server settings in the configuration.

        * src/dbus_api/modest-dbus-callbacks.c: (on_idle_send_mail),
        (on_idle_mail_to):
        * src/maemo/modest-main-window.c: (on_connection_changed),
        (connect_signals):
        * src/modest-main.c: (main), (start_ui), (send_mail):
        Use tny_maemo_conic_device_connect() instead of tny_maemo_conic_force_online(), when
        that is what is intended.

        * src/modest-ui-actions.c: (action_send), (action_receive),
        (modest_ui_actions_on_item_not_found), (modest_ui_actions_on_send):
        Use modest_tny_account_store_get_transport_account_for_open_connection() instead of
        modest_tny_account_store_get_tny_account_by_account() so that the connection-specific
        SMTP server is used when it is specified.

        (modest_ui_actions_on_send_receive):
        Check that a connection is open before proceeding.
        Receive and then send, instead of vice-versa, as per the specification

pmo-trunk-r1691

ChangeLog2
src/dbus_api/modest-dbus-callbacks.c
src/maemo/modest-main-window.c
src/modest-main.c
src/modest-tny-account-store.c
src/modest-tny-account-store.h
src/modest-ui-actions.c

index d25c83d..11c02a0 100644 (file)
@@ -1,3 +1,28 @@
+2007-04-27  Murray Cumming  <murrayc@murrayc.com>
+
+       * src/modest-tny-account-store.h:
+       * src/modest-tny-account-store.c:
+       Added modest_tny_account_store_get_transport_account_for_open_connection(), which respects 
+       the connection-specific SMTP server settings in the configuration.
+       
+       * src/dbus_api/modest-dbus-callbacks.c: (on_idle_send_mail),
+       (on_idle_mail_to):
+       * src/maemo/modest-main-window.c: (on_connection_changed),
+       (connect_signals):
+       * src/modest-main.c: (main), (start_ui), (send_mail):
+       Use tny_maemo_conic_device_connect() instead of tny_maemo_conic_force_online(), when 
+       that is what is intended.
+       
+       * src/modest-ui-actions.c: (action_send), (action_receive),
+       (modest_ui_actions_on_item_not_found), (modest_ui_actions_on_send):
+       Use modest_tny_account_store_get_transport_account_for_open_connection() instead of 
+       modest_tny_account_store_get_tny_account_by_account() so that the connection-specific 
+       SMTP server is used when it is specified.
+       
+       (modest_ui_actions_on_send_receive): 
+       Check that a connection is open before proceeding.
+       Receive and then send, instead of vice-versa, as per the specification
+
 2007-04-26  Murray Cumming  <murrayc@murrayc.com>
 
        * src/modest-mail-operation.c:
index a8fbc5e..2a1679d 100644 (file)
@@ -61,10 +61,9 @@ on_idle_send_mail(gpointer user_data)
        
        TnyTransportAccount *transport_account = NULL;
        if (account_mgr) {
-               transport_account = TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_tny_account_by_account
+               transport_account = TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_transport_account_for_open_connection
                                      (modest_runtime_get_account_store(),
-                                      account_name,
-                                      TNY_ACCOUNT_TYPE_TRANSPORT));
+                                      account_name));
        }
        
        if (!transport_account) {
@@ -270,9 +269,8 @@ on_idle_mail_to(gpointer user_data)
        
        TnyAccount *account = NULL;
        if (account_mgr) {
-               account = modest_tny_account_store_get_tny_account_by_account (
-                       modest_runtime_get_account_store(), account_name,
-                       TNY_ACCOUNT_TYPE_TRANSPORT);
+               account = modest_tny_account_store_get_transport_account_for_open_connection (
+                       modest_runtime_get_account_store(), account_name);
        }
        
        if (!account) {
index 40204ea..34fb4e8 100644 (file)
@@ -317,6 +317,19 @@ on_delete_event (GtkWidget *widget, GdkEvent  *event, ModestMainWindow *self)
        return FALSE;
 }
 
+
+static void
+on_connection_changed (TnyDevice *device, gboolean online, ModestMainWindow *self)
+{
+       /* When going online, do the equivalent of pressing the send/receive button, 
+        * as per the specification: */
+       if (online) {
+               modest_ui_actions_on_send_receive (NULL /* action */, MODEST_WINDOW (self));
+       }
+}
+
+
+
 static void
 connect_signals (ModestMainWindow *self)
 {      
@@ -374,12 +387,17 @@ connect_signals (ModestMainWindow *self)
                          "account_update",
                          G_CALLBACK (on_account_update),
                          self);
+
+       /* Device */
+       g_signal_connect (G_OBJECT(modest_runtime_get_device()), "connection_changed",
+                         G_CALLBACK(on_connection_changed), self);
 }
 
 
 gboolean
 sync_accounts_cb (ModestMainWindow *win)
 {
+       /* TODO: Only for auto-update accounts. */
        modest_ui_actions_on_send_receive (NULL, MODEST_WINDOW(win));
        return FALSE;
 }
@@ -703,7 +721,7 @@ modest_main_window_show_toolbar (ModestWindow *self,
 }
 
 /*
- * TODO: modify the menu dinamically. Add handlers to each item of the
+ * TODO: modify the menu dynamically. Add handlers to each item of the
  * menu when created
  */
 static void 
index 7327119..9dcc063 100644 (file)
@@ -38,6 +38,7 @@
 #include <tny-account-store.h>
 #include <tny-list.h>
 #include <tny-simple-list.h>
+#include <tny-maemo-conic-device.h> /* For tny_maemo_conic_device_connect() */
 
 #include <modest-runtime.h>
 #include <modest-init.h>
@@ -135,7 +136,7 @@ main (int argc, char *argv[])
                } else {
                        if (modest_conf_get_bool (modest_runtime_get_conf(),
                                                  MODEST_CONF_CONNECT_AT_STARTUP, NULL))
-                               tny_device_force_online (modest_runtime_get_device());
+                               tny_maemo_conic_device_connect (TNY_MAEMO_CONIC_DEVICE (modest_runtime_get_device()), NULL);
                        
                        retval = start_ui (account_or_default,
                                           mailto, cc, bcc, subject, body);
@@ -191,9 +192,8 @@ start_ui (const gchar *account_name, const gchar* mailto, const gchar *cc, const
                        return MODEST_ERR_SEND;
                }
 
-               account = modest_tny_account_store_get_tny_account_by_account (
-                       modest_runtime_get_account_store(), account_name,
-                       TNY_ACCOUNT_TYPE_TRANSPORT);
+               account = modest_tny_account_store_get_transport_account_for_open_connection (
+                       modest_runtime_get_account_store(), account_name);
                if (!account) {
                        g_printerr ("modest: failed to get tny account folder\n");
                        g_free (from);
@@ -273,9 +273,8 @@ send_mail (const gchar* account_name,
        return MODEST_ERR_NONE;
        //////////////////////////////////////
        
-       account = TNY_TRANSPORT_ACCOUNT (modest_tny_account_store_get_tny_account_by_account
-                                        (modest_runtime_get_account_store(), account_name,
-                                         TNY_ACCOUNT_TYPE_TRANSPORT));
+       account = TNY_TRANSPORT_ACCOUNT (modest_tny_account_store_get_transport_account_for_open_connection
+                                        (modest_runtime_get_account_store(), account_name));
        if (!account) {
                g_printerr ("modest: no transport defined account for %s\n",
                            account_name);
index 76a9f2a..39f6b78 100644 (file)
@@ -36,6 +36,7 @@
 #include <tny-transport-account.h>
 #include <tny-simple-list.h>
 #include <tny-account-store.h>
+#include <tny-maemo-conic-device.h> /* For ConIcIap */
 #include <tny-camel-transport-account.h>
 #include <tny-camel-imap-store-account.h>
 #include <tny-camel-pop-store-account.h>
@@ -728,7 +729,6 @@ modest_tny_account_store_get_tny_account_by_id  (ModestTnyAccountStore *self, co
        return account;
 }
 
-
 TnyAccount*
 modest_tny_account_store_get_tny_account_by_account (ModestTnyAccountStore *self,
                                                     const gchar *account_name,
@@ -761,7 +761,7 @@ modest_tny_account_store_get_tny_account_by_account (ModestTnyAccountStore *self
                g_printerr ("modest: could not get an id for account %s\n",
                            account_name);
        else    
-               account =  modest_tny_account_store_get_tny_account_by_id  (self, id);
+               account = modest_tny_account_store_get_tny_account_by_id (self, id);
 
        if (!account)
                g_printerr ("modest: could not get tny %s account for %s (id=%s)\n",
@@ -771,3 +771,59 @@ modest_tny_account_store_get_tny_account_by_account (ModestTnyAccountStore *self
        modest_account_mgr_free_account_data (priv->account_mgr, account_data);
        return account; 
 }
+
+static TnyAccount* get_smtp_specific_transport_account_for_open_connection (ModestTnyAccountStore *self, const gchar *account_name)
+{
+       /* Get the current connection: */
+       TnyDevice *device = modest_runtime_get_device ();
+       
+       if (!tny_device_is_online (device))
+               return NULL;
+
+       g_assert (TNY_IS_MAEMO_CONIC_DEVICE (device));
+       TnyMaemoConicDevice *maemo_device = TNY_MAEMO_CONIC_DEVICE (device);    
+       const gchar* iap_id = tny_maemo_conic_device_get_current_iap_id (maemo_device);
+       if (!iap_id)
+               return NULL;
+               
+       ConIcIap* connection = tny_maemo_conic_device_get_iap (maemo_device, iap_id);
+       if (!connection)
+               return NULL;
+               
+       const gchar *connection_name = con_ic_iap_get_name (connection);
+       if (!connection_name)
+               return NULL;
+       
+       /*  Get the connection-specific transport acccount, if any: */
+       ModestAccountMgr *account_manager = modest_runtime_get_account_mgr ();
+       gchar* server_account_name = modest_account_mgr_get_connection_specific_smtp (account_manager, 
+               account_name, connection_name);
+               
+       if (!server_account_name)
+               return NULL; /* No connection-specific SMTP server was specified for this connection. */
+               
+       TnyAccount* account = modest_tny_account_store_get_tny_account_by_id (self, server_account_name);
+       g_free (server_account_name);   
+
+       /* Unref the get()ed object, as required by the tny_maemo_conic_device_get_iap() documentation. */
+       g_object_unref (connection);
+       
+       return account;
+}
+
+                                                                
+TnyAccount* modest_tny_account_store_get_transport_account_for_open_connection (ModestTnyAccountStore *self,
+                                                                const gchar *account_name)
+{
+       /*  Get the connection-specific transport acccount, if any: */
+       TnyAccount *account = get_smtp_specific_transport_account_for_open_connection (self, account_name);
+                       
+       /* If there is no connection-specific transport account (the common case), 
+        * just get the regular transport account: */
+       if (!account) {         
+               account = modest_tny_account_store_get_tny_account_by_account (self, account_name, 
+                                                    TNY_ACCOUNT_TYPE_TRANSPORT);
+       }
+                            
+       return account;
+}
index 07c466c..3ae4f27 100644 (file)
@@ -107,21 +107,35 @@ ModestTnyAccountStore*    modest_tny_account_store_new (ModestAccountMgr *accoun
 TnyAccount* modest_tny_account_store_get_tny_account_by_id  (ModestTnyAccountStore *self,
                                                             const gchar *id);
 
-
 /**
  * modest_tny_account_store_get_tny_account_by_account
  * @self: a ModestTnyAccountStore instance
  * @account_name: an account name
  * @type: the tny account type
  * 
- * get the tny account corresponding to one of the  server_accounts for account with @account_name
+ * Get the tny account corresponding to one of the server_accounts for account with @account_name
  * 
- * Returns: the tnyaccount or NULL in case it's not found or error,
+ * Returns: the tnyaccount for the server account or NULL in case it's not found or error,
  * g_object_unref when it's no longer needed
  */
 TnyAccount* modest_tny_account_store_get_tny_account_by_account (ModestTnyAccountStore *self,
                                                                 const gchar *account_name,
                                                                 TnyAccountType type);
+               
+/**
+ * modest_tny_account_store_get_transport_account_for_open_connection
+ * @self: a ModestTnyAccountStore instance
+ * @account_name: an account name
+ * 
+ * Get the tny account corresponding to the transport server account for the account with @account_name,
+ * returning the connection-specific SMTP-server transport server account if one is specified,
+ * otherwise just returning the regular transport server account.
+ * 
+ * Returns: the tnyaccount for the server account or NULL in case it's not found or error,
+ * g_object_unref when it's no longer needed
+ */                                             
+TnyAccount* modest_tny_account_store_get_transport_account_for_open_connection (ModestTnyAccountStore *self,
+                                                                const gchar *account_name);
 
 /**
  * tny_account_store_get_session
index 3bb0d8f..b7d12f9 100644 (file)
@@ -52,6 +52,7 @@
 #include "modest-account-mgr-helpers.h"
 #include "modest-mail-operation.h"
 #include "modest-text-utils.h"
+#include <tny-maemo-conic-device.h> /* For ConIcIap */
 
 #ifdef MODEST_HAVE_EASYSETUP
 #include "easysetup/modest-easysetup-wizard.h"
@@ -605,14 +606,17 @@ action_send (const gchar* account_name)
 
        g_return_val_if_fail (account_name, FALSE);
 
+       /* Get the transport account according to the open connection, 
+        * because the account might specify connection-specific SMTP servers.
+        */
        tny_account = 
-               modest_tny_account_store_get_tny_account_by_account (modest_runtime_get_account_store(),
-                                                                    account_name,
-                                                                    TNY_ACCOUNT_TYPE_TRANSPORT);
+               modest_tny_account_store_get_transport_account_for_open_connection (modest_runtime_get_account_store(),
+                                                                    account_name);
        if (!tny_account) {
                g_printerr ("modest: cannot get tny transport account for %s\n", account_name);
                return FALSE;
        }
+       
        send_queue = modest_tny_send_queue_new (TNY_CAMEL_TRANSPORT_ACCOUNT(tny_account));
        if (!send_queue) {
                g_object_unref (G_OBJECT(tny_account));
@@ -647,6 +651,7 @@ action_receive (const gchar* account_name)
        }
 
        /* Create the mail operation */
+       /* TODO: The spec wants us to first do any pending deletions, before receiving. */
        mail_op = modest_mail_operation_new ();
        modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
        modest_mail_operation_update_account (mail_op, TNY_STORE_ACCOUNT(tny_account));
@@ -657,7 +662,27 @@ action_receive (const gchar* account_name)
        return TRUE;
 }
 
+/** Check that an appropriate connection is open.
+ */
+gboolean check_for_connection (const gchar *account_name)
+{
+       TnyDevice *device = modest_runtime_get_device ();
 
+/*
+       g_assert (TNY_IS_MAEMO_CONIC_DEVICE (device));
+       
+       TnyMaemoConicDevice *maemo_device = TNY_MAEMO_CONIC_DEVICE (device);
+*/
+       
+       if (tny_device_is_online (device))
+               return TRUE;
+       else {
+               tny_maemo_conic_device_connect (TNY_MAEMO_CONIC_DEVICE (device), NULL);
+               
+               /* TODO: Wait until a result. */
+               return TRUE;
+       }
+}
 
 void
 modest_ui_actions_on_send_receive (GtkAction *action,  ModestWindow *win)
@@ -665,22 +690,35 @@ modest_ui_actions_on_send_receive (GtkAction *action,  ModestWindow *win)
        gchar *account_name;
 
        
-       g_message ("online? %s", 
+       g_message ("%s: online? %s", __FUNCTION__,  
                tny_device_is_online(modest_runtime_get_device()) ? "yes":"no");
-                                                               
+                               
+       /* As per the UI spec, only the active account should be affected, 
+        * else the default folder if there is no active account: */                            
        account_name =
                g_strdup(modest_window_get_active_account(MODEST_WINDOW(win)));
        if (!account_name)
                account_name  = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
        if (!account_name) {
-               g_printerr ("modest: cannot get account\n");
+               g_printerr ("modest: cannot get default account\n");
                return;
        }
+       
+       /* Do not continue if no suitable connection is open: */
+       if (!check_for_connection (account_name))
+               return;
 
-       if (!action_send(account_name))
-               g_printerr ("modest: failed to send\n");
+       /* 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:
+        */
        if (!action_receive(account_name))
                g_printerr ("modest: failed to receive\n");
+       if (!action_send(account_name))
+               g_printerr ("modest: failed to send\n");
+       
 }
 
 
@@ -979,7 +1017,7 @@ modest_ui_actions_on_item_not_found (ModestHeaderView *header_view,ModestItemTyp
 
                gtk_window_set_default_size (GTK_WINDOW(dialog), 300, 300);
                if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
-//                     tny_device_force_online (modest_runtime_get_device());
+//                     tny_maemo_conic_device_connect (TNY_MAEMO_CONIC_DEVICE (modest_runtime_get_device());
                }
        }
        gtk_widget_destroy (dialog);
@@ -1051,10 +1089,9 @@ modest_ui_actions_on_send (GtkWidget *widget, ModestMsgEditWindow *edit_window)
                return;
        }
        transport_account =
-               TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_tny_account_by_account
+               TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_transport_account_for_open_connection
                                      (modest_runtime_get_account_store(),
-                                      account_name,
-                                      TNY_ACCOUNT_TYPE_TRANSPORT));
+                                      account_name));
        if (!transport_account) {
                g_printerr ("modest: no transport account found for '%s'\n", account_name);
                g_free (account_name);