+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:
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) {
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) {
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)
{
"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;
}
}
/*
- * 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
#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>
} 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);
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);
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);
#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>
return account;
}
-
TnyAccount*
modest_tny_account_store_get_tny_account_by_account (ModestTnyAccountStore *self,
const gchar *account_name,
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",
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;
+}
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
#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"
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));
}
/* 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));
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)
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");
+
}
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);
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);