#include <modest-account-mgr.h>
#include <modest-account-mgr-priv.h>
#include <modest-account-mgr-helpers.h>
+#include <modest-platform.h>
/* 'private'/'protected' functions */
static void modest_account_mgr_class_init (ModestAccountMgrClass * klass);
g_str_equal,
g_free,
(GDestroyNotify)g_hash_table_destroy);
+
+ /* FALSE means: status is unknown */
+ priv->has_accounts = FALSE;
+ priv->has_enabled_accounts = FALSE;
}
static void
if (!default_account)
modest_account_mgr_set_default_account (self, name);
g_free (default_account);
-
+
+ /* (re)set the automatic account update */
+ modest_platform_set_update_interval
+ (modest_conf_get_int (priv->modest_conf, MODEST_CONF_UPDATE_INTERVAL, NULL));
+
return TRUE;
}
/* Add the security settings: */
modest_account_mgr_set_server_account_security (self, name, security);
-
+
cleanup:
if (!ok) {
g_printerr ("modest: failed to add server account\n");
will retrieve also the deleted account */
g_signal_emit (G_OBJECT(self), signals[ACCOUNT_REMOVED_SIGNAL], 0, name);
+ /* if this was the last account, stop any auto-updating */
+ /* (re)set the automatic account update */
+ GSList *acc_names = modest_account_mgr_account_names (self, TRUE);
+ if (!acc_names) {
+ modest_platform_set_update_interval (0);
+ /* it was the last account, the has_account / has_enabled_account
+ * changes
+ */
+ priv->has_accounts = priv->has_enabled_accounts = FALSE;
+ } else
+ modest_account_mgr_free_account_names (acc_names);
+
return TRUE;
}
retval = g_strconcat (namespace, "/", escaped_account_name, NULL);
/* Sanity check: */
- if (!modest_conf_key_is_valid (retval)) {
- g_warning ("%s: Generated conf key was invalid: %s", __FUNCTION__, retval);
+ if (!retval || !modest_conf_key_is_valid (retval)) {
+ g_warning ("%s: Generated conf key was invalid: %s", __FUNCTION__,
+ retval ? retval: "<empty>");
g_free (retval);
retval = NULL;
}
gboolean
modest_account_mgr_has_accounts (ModestAccountMgr* self, gboolean enabled)
{
- /* Check that at least one account exists: */
- GSList *account_names = modest_account_mgr_account_names (self,
- enabled);
- gboolean accounts_exist = account_names != NULL;
+ ModestAccountMgrPrivate* priv;
+ GSList *account_names;
+ gboolean accounts_exist;
+
+ g_return_val_if_fail (MODEST_IS_ACCOUNT_MGR(self), FALSE);
+ priv = MODEST_ACCOUNT_MGR_GET_PRIVATE (self);
+
+ if (enabled && priv->has_enabled_accounts)
+ return TRUE;
+ else if (priv->has_accounts)
+ return TRUE;
+
+ /* Check that at least one account exists: */
+ account_names = modest_account_mgr_account_names (self,enabled);
+ accounts_exist = account_names != NULL;
modest_account_mgr_free_account_names (account_names);
account_names = NULL;
+
+ /* cache it. */
+ if (enabled)
+ priv->has_enabled_accounts = accounts_exist;
+ else
+ priv->has_accounts = accounts_exist;
return accounts_exist;
}
const gchar* account_name,
gboolean busy)
{
- ModestAccountMgrPrivate* priv = MODEST_ACCOUNT_MGR_GET_PRIVATE (self);
- if (busy)
- {
+ ModestAccountMgrPrivate* priv;
+
+ g_return_if_fail (MODEST_IS_ACCOUNT_MGR(self));
+ g_return_if_fail (account_name);
+
+ priv = MODEST_ACCOUNT_MGR_GET_PRIVATE (self);
+ if (busy) {
GSList *account_names = modest_account_mgr_account_names (self, TRUE);
GSList* account = g_slist_find_custom(account_names, account_name,
(GCompareFunc) compare_account_name);
}
gboolean
-modest_account_mgr_account_is_busy(ModestAccountMgr* self, const gchar* account_name)
+modest_account_mgr_account_is_busy (ModestAccountMgr* self, const gchar* account_name)
{
- ModestAccountMgrPrivate* priv = MODEST_ACCOUNT_MGR_GET_PRIVATE (self);
+ ModestAccountMgrPrivate* priv;
+
+ g_return_val_if_fail (MODEST_IS_ACCOUNT_MGR(self), FALSE);
+ g_return_val_if_fail (account_name, FALSE);
+
+ priv = MODEST_ACCOUNT_MGR_GET_PRIVATE (self);
+
return (g_slist_find_custom(priv->busy_accounts, account_name, (GCompareFunc) compare_account_name)
- != NULL);
+ != NULL);
}
void
const gchar *server_account_name)
{
ModestTransportStoreProtocol proto;
+ ModestAccountMgrPrivate* priv;
gchar *proto_name = NULL;
+ g_return_if_fail (self);
+ g_return_if_fail (server_account_name);
+
+ priv = MODEST_ACCOUNT_MGR_GET_PRIVATE (self);
+
/* Get protocol */
proto_name = modest_account_mgr_get_string (self, server_account_name,
MODEST_ACCOUNT_PROTO, TRUE);
proto = modest_protocol_info_get_transport_store_protocol (proto_name);
g_free (proto_name);
+ /* there is some update in the account, so we can't
+ * be sure about whether there are still enabled accounts...
+ */
+ priv->has_enabled_accounts = FALSE;
+ priv->has_accounts = FALSE;
+
/* Emit "update-account" */
g_signal_emit (G_OBJECT(self),
signals[ACCOUNT_CHANGED_SIGNAL], 0,