2007-05-28 Murray Cumming <murrayc@murrayc.com>
+ * src/maemo/modest-maemo-global-settings-dialog.c:
+ (current_connection):
+ * src/widgets/modest-global-settings-dialog.c:
+ (current_connection_default):
+ Use the enum values instead of 0, 1 and -1,
+ to make the code clearer.
+
+ * src/modest-account-mgr-helpers.c:
+ (modest_account_mgr_get_connection_specific_smtp): Make this code
+ more robust.
+
+ * src/modest-runtime.h:
+ * src/modest-runtime.c:
+ Added modest_runtime_remove_all_send_queues().
+ * src/maemo/modest-main-window.c:
+ (on_account_store_connecting_finished): Recreate the send queues,
+ using the appropriate transport accounts for this new connection.
+ Some futher adapting might be needed if the old send queues are not
+ automatically stopped at this point.
+
+ * src/modest-tny-account-store.c: (get_server_accounts):
+ Create the connection-specific transport accounts, so that they can
+ be found later by their ID.
+
+ * src/modest-tny-account.h:
+ * src/modest-tny-account.c:
+ Added modest_tny_account_new_from_server_account_name().
+ modest_tny_account_new_from_server_account(): Do not create the
+ send queues here, because they will be
+ recreated anyway when the connection changes for the first time.
+
+2007-05-28 Murray Cumming <murrayc@murrayc.com>
+
* src/modest-local-folder-info.h:
* src/modest-local-folder-info.c:
(modest_per_account_local_outbox_folder_info_get_maildir_path),
{
TnyAccountStore *account_store;
TnyDevice *device;
- gboolean retval = FALSE;
+ ModestConnectedVia retval = MODEST_CONNECTED_VIA_ANY;
account_store = TNY_ACCOUNT_STORE (modest_runtime_get_account_store ());
device = tny_account_store_get_device (account_store);
#include <gtk/gtktreeviewcolumn.h>
#include <tny-account-store-view.h>
#include <tny-simple-list.h>
+#include <tny-maemo-conic-device.h>
#include "modest-hildon-includes.h"
#include "modest-defs.h"
#include <string.h>
/* When going online, do the equivalent of pressing the send/receive button,
* as per the specification:
* (without the check for >0 accounts, though that is not specified): */
+
+ TnyDevice *device = tny_account_store_get_device (store);
+ const gchar *iap_id = tny_maemo_conic_device_get_current_iap_id (TNY_MAEMO_CONIC_DEVICE (device));
+ printf ("DEBUG: %s: connection id=%s\n", __FUNCTION__, iap_id);
+
+ /* Stop the existing send queues: */
+ modest_runtime_remove_all_send_queues ();
+
+ /* Create the send queues again, using the appropriate transport accounts
+ * for this new connection.
+ * This could be the first time that they are created if this is the first
+ * connection. */
+ /* TODO: Does this really destroy the TnySendQueues and their threads
+ * We do not want 2 TnySendQueues to exist with the same underlying
+ * outbox directory. */
+ GSList *account_names = modest_account_mgr_account_names (
+ modest_runtime_get_account_mgr(),
+ TRUE /* enabled accounts only */);
+ GSList *iter = account_names;
+ while (iter) {
+ const gchar *account_name = (const gchar*)(iter->data);
+ if (account_name) {
+ TnyTransportAccount *account = TNY_TRANSPORT_ACCOUNT (
+ modest_tny_account_store_get_transport_account_for_open_connection
+ (modest_runtime_get_account_store(), account_name));
+ if (account) {
+ printf ("debug: %s:\n Transport account for %s: %s\n", __FUNCTION__, account_name,
+ tny_account_get_id(TNY_ACCOUNT(account)));
+ modest_runtime_get_send_queue (account);
+ }
+ }
+
+ iter = g_slist_next (iter);
+ }
+
+ g_slist_free (account_names);
+
+
modest_ui_actions_do_send_receive (NULL, MODEST_WINDOW (self));
}
MODEST_CONF_VALUE_STRING, FALSE);
if (!list)
return NULL;
-
+
/* The server account is in the item after the connection name: */
- GSList *list_connection = g_slist_find_custom (list, connection_name, (GCompareFunc)strcmp);
- if (list_connection) {
- GSList * list_server_account = g_slist_next(list_connection);
- if (list_server_account)
- result = g_strdup ((gchar*)(list_server_account->data));
+ GSList *iter = list;
+ while (iter) {
+ const gchar* this_connection_name = (const gchar*)(iter->data);
+ if (strcmp (this_connection_name, connection_name) == 0) {
+ iter = g_slist_next (iter);
+
+ if (iter) {
+ const gchar* account_name = (const gchar*)(iter->data);
+ if (account_name) {
+ result = g_strdup (account_name);
+ break;
+ }
+ }
+ }
+
+ /* Skip 2 to go to the next connection in the list: */
+ iter = g_slist_next (iter);
+ if (iter)
+ iter = g_slist_next (iter);
+ }
+
+ /*
+ if (!result) {
+ printf (" debug: no server found for connection_name=%s.\n", connection_name);
}
+ */
/* TODO: Should we free the items too, or just the list? */
g_slist_free (list);
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,
+ /* Each modest account has its own send queue.
+ * Note that each modest 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)) {
send_queue = (gpointer)modest_tny_send_queue_new (TNY_CAMEL_TRANSPORT_ACCOUNT(account));
g_hash_table_insert (send_queue_cache, account, send_queue);
+ g_object_ref (send_queue);
}
return MODEST_TNY_SEND_QUEUE(send_queue);
}
+void modest_runtime_remove_all_send_queues ()
+{
+ ModestCacheMgr *cache_mgr = modest_singletons_get_cache_mgr (_singletons);
+
+ modest_cache_mgr_flush (cache_mgr, MODEST_CACHE_MGR_CACHE_TYPE_SEND_QUEUE);
+}
+
ModestWindowMgr *
modest_runtime_get_window_mgr (void)
{
**/
ModestTnySendQueue* modest_runtime_get_send_queue (TnyTransportAccount *account);
+/**
+ * modest_runtime_remove_all_send_queues:
+ *
+ * Removes all send queues, ready for them to be recreated, for instance
+ * with a new connection.
+ **/
+void modest_runtime_remove_all_send_queues ();
/**
* modest_runtime_get_window_mgr:
/* Do nothing if the accounts are already cached: */
if (type == TNY_ACCOUNT_TYPE_STORE) {
- if (priv->store_accounts)
- return;
+ if (priv->store_accounts)
+ return;
} else if (type == TNY_ACCOUNT_TYPE_TRANSPORT) {
- if (priv->transport_accounts)
- return;
+ if (priv->transport_accounts)
+ return;
}
GSList *account_names = NULL, *cursor = NULL;
GSList *accounts = NULL;
- /* these account names, not server_account names */
+ /* These are account names, not server_account names */
account_names = modest_account_mgr_account_names (priv->account_mgr,FALSE);
for (cursor = account_names; cursor; cursor = cursor->next) {
g_printerr ("modest: failed to create account for %s\n",
account_name);
}
- g_free (account_name);
}
- g_slist_free (account_names);
if (type == TNY_ACCOUNT_TYPE_STORE) {
/* Also add the local folder pseudo-account: */
tny_list_prepend (list, G_OBJECT(tny_account));
accounts = g_slist_append (accounts, tny_account); /* cache it */
}
-
- /* Do this here, because create_per_account_local_outbox_folders() needs it. */
+
+ /* And add the connection-specific transport accounts, if any.
+ * Note that these server account instances might never be used
+ * if their connections are never active: */
+ /* Look at each modest account: */
if (type == TNY_ACCOUNT_TYPE_TRANSPORT) {
- /* Store the cache: */
- priv->transport_accounts = accounts;
+ GSList *iter_account_names = account_names;
+ while (iter_account_names) {
+ const gchar* account_name = (const gchar*)(iter_account_names->data);
+ GSList *list_specifics = modest_account_mgr_get_list (priv->account_mgr,
+ account_name,
+ MODEST_ACCOUNT_CONNECTION_SPECIFIC_SMTP_LIST,
+ MODEST_CONF_VALUE_STRING, FALSE);
+
+ /* Look at each connection-specific transport account for the
+ * modest account: */
+ GSList *iter = list_specifics;
+ while (iter) {
+ /* const gchar* this_connection_name = (const gchar*)(iter->data); */
+ iter = g_slist_next (iter);
+ if (iter) {
+ const gchar* transport_account_name = (const gchar*)(iter->data);
+ if (transport_account_name) {
+ TnyAccount * tny_account = NULL;
+ /* Add the account: */
+ tny_account = modest_tny_account_new_from_server_account_name (
+ priv->account_mgr, transport_account_name);
+ if (tny_account) {
+ g_object_set_data (G_OBJECT(tny_account), "account_store",
+ (gpointer)self);
+ if (list)
+ tny_list_prepend (list, G_OBJECT(tny_account));
+
+ accounts = g_slist_append (accounts, tny_account); /* cache it */
+ } else
+ g_printerr ("modest: failed to create smtp-specific account for %s\n",
+ transport_account_name);
+ }
+ }
+
+ iter = g_slist_next (iter);
+ }
+
+ iter_account_names = g_slist_next (iter_account_names);
+ }
}
+ g_slist_free (account_names);
+ account_names = NULL;
+
+ /* TODO: Delete the strings in the GSList */
+
+
/* We also create a per-account local outbox folder (a _store_ account)
* for each _transport_ account. */
if (type == TNY_ACCOUNT_TYPE_TRANSPORT) {
if (type == TNY_ACCOUNT_TYPE_STORE) {
/* Store the cache: */
priv->store_accounts = accounts;
+ } else if (type == TNY_ACCOUNT_TYPE_TRANSPORT) {
+ /* Store the cache: */
+ priv->transport_accounts = accounts;
}
}
account_data = modest_account_mgr_get_account_data (priv->account_mgr, account_name);
if (!account_data) {
- g_printerr ("modest: cannot get account data for account '%s'\n", account_name);
+ g_printerr ("modest: %s: cannot get account data for account '%s'\n", __FUNCTION__, account_name);
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);
+ /* printf ("DEBUG: %s: iap_id=%s\n", __FUNCTION__, iap_id); */
if (!iap_id)
return NULL;
return NULL;
const gchar *connection_name = con_ic_iap_get_name (connection);
+ /* printf ("DEBUG: %s: connection_name=%s\n", __FUNCTION__, connection_name); */
if (!connection_name)
return NULL;
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)
+
+ /* printf ("DEBUG: %s: server_account_name=%s\n", __FUNCTION__, server_account_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);
+
+ /* printf ("DEBUG: %s: account=%p\n", __FUNCTION__, account); */
g_free (server_account_name);
/* Unref the get()ed object, as required by the tny_maemo_conic_device_get_iap() documentation. */
/* If there is no connection-specific transport account (the common case),
* just get the regular transport account: */
- if (!account) {
+ if (!account) {
+ /* printf("DEBUG: %s: using regular transport account for account %s.\n", __FUNCTION__, account_name); */
account = modest_tny_account_store_get_tny_account_by_account (self, account_name,
TNY_ACCOUNT_TYPE_TRANSPORT);
}
#define MODEST_ACCOUNT_AUTH_CRAMMD5 "CRAM-MD5"
+
/**
* modest_tny_account_new_from_server_account:
* @account_mgr: a valid account mgr instance
static TnyAccount*
modest_tny_account_new_from_server_account (ModestAccountMgr *account_mgr,
ModestServerAccountData *account_data)
-{
+{
gchar *url = NULL;
g_return_val_if_fail (account_mgr, NULL);
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;
}
+TnyAccount*
+modest_tny_account_new_from_server_account_name (ModestAccountMgr *account_mgr,
+ const gchar *server_account_name)
+{
+ ModestServerAccountData *account_data =
+ modest_account_mgr_get_server_account_data (account_mgr,
+ server_account_name);
+ if (!account_data)
+ return NULL;
+
+ TnyAccount *result = modest_tny_account_new_from_server_account (
+ account_mgr, account_data);
+
+ modest_account_mgr_free_server_account_data (account_mgr, account_data);
+
+ return result;
+}
+
/* we need these dummy functions, or tinymail will complain */
static gchar*
account_data = modest_account_mgr_get_account_data (account_mgr, account_name);
if (!account_data) {
- g_printerr ("modest: cannot get account data for account %s\n", account_name);
+ g_printerr ("modest: %s: cannot get account data for account %s\n", __FUNCTION__, account_name);
return NULL;
}
/**
* modest_tny_account_new_from_account:
* @account_mgr: a valid account mgr instance
- * @account_name: the account name for which to create a corresponding tny account
+ * @account_name: the modest account name for which to create a corresponding tny account of the given type.
* @type: the type of account to create (TNY_ACCOUNT_TYPE_STORE or TNY_ACCOUNT_TYPE_TRANSPORT)
* @session: a tny camel session
* @get_pass_func: the get-password function
TnyAccount* modest_tny_account_new_for_per_account_local_outbox_folder (
ModestAccountMgr *account_mgr, const gchar* account_name,
TnySessionCamel *session);
+
+/**
+ * modest_tny_account_new_from_server_account_name:
+ * @account_mgr: a valid account mgr instance
+ * @server_account_name: the name of a server account in the configuration system.
+ *
+ * Returns: a new TnyAccount or NULL in case of error.
+ */
+TnyAccount*
+modest_tny_account_new_from_server_account_name (ModestAccountMgr *account_mgr,
+ const gchar* server_account_name);
/**
* modest_tny_account_get_special_folder:
current_connection_default (void)
{
g_warning ("You must implement %s", __FUNCTION__);
- g_return_val_if_reached (-1);
+ g_return_val_if_reached (MODEST_CONNECTED_VIA_ANY);
}