#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);
ACCOUNT_BUSY_SIGNAL,
DEFAULT_ACCOUNT_CHANGED_SIGNAL,
DISPLAY_NAME_CHANGED_SIGNAL,
+ ACCOUNT_UPDATED_SIGNAL,
LAST_SIGNAL
};
NULL, NULL,
g_cclosure_marshal_VOID__STRING,
G_TYPE_NONE, 1, G_TYPE_STRING);
+
+ signals[ACCOUNT_UPDATED_SIGNAL] =
+ g_signal_new ("account_updated",
+ MODEST_TYPE_ACCOUNT_MGR,
+ G_SIGNAL_RUN_FIRST,
+ G_STRUCT_OFFSET(ModestAccountMgrClass, account_updated),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__STRING,
+ G_TYPE_NONE, 1, G_TYPE_STRING);
+
modest_account_mgr_initialized = TRUE;
}
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
return str ? str : "";
}
+gboolean
+modest_account_mgr_add_account_from_settings (ModestAccountMgr *self,
+ ModestAccountSettings *settings)
+{
+ ModestAccountMgrPrivate *priv;
+ const gchar* display_name;
+ gchar *account_name_start, *account_name;
+ gchar *store_name_start, *store_name;
+ gchar *transport_name_start, *transport_name;
+ gchar *default_account;
+ ModestServerAccountSettings *store_settings, *transport_settings;
+
+ g_return_val_if_fail (MODEST_IS_ACCOUNT_MGR (self), FALSE);
+ g_return_val_if_fail (MODEST_IS_ACCOUNT_SETTINGS (settings), FALSE);
+
+ priv = MODEST_ACCOUNT_MGR_GET_PRIVATE (self);
+ display_name = modest_account_settings_get_display_name (settings);
+
+ /* We should have checked for this already, and changed that name accordingly,
+ * but let's check again just in case */
+ if (!display_name ||
+ modest_account_mgr_account_with_display_name_exists (self, display_name)) {
+ return FALSE;
+ }
+
+ /* Increment the non-user visible name if necessary,
+ * based on the display name: */
+ account_name_start = g_strdup_printf ("%sID", display_name);
+ account_name = modest_account_mgr_get_unused_account_name (self,
+ account_name_start, FALSE /* not a server account */);
+ g_free (account_name_start);
+
+ /* Add a (incoming) server account, to be used by the account: */
+ store_name_start = g_strconcat (account_name, "_store", NULL);
+ store_name = modest_account_mgr_get_unused_account_name (self,
+ store_name_start, TRUE /* server account */);
+ g_free (store_name_start);
+
+ /* Add a (outgoing) server account to be used by the account: */
+ transport_name_start = g_strconcat (account_name, "_transport", NULL);
+ transport_name = modest_account_mgr_get_unused_account_name (self,
+ transport_name_start, TRUE /* server account */);
+ g_free (transport_name_start);
+
+ modest_account_settings_set_account_name (settings, account_name);
+ store_settings = modest_account_settings_get_store_settings (settings);
+ modest_server_account_settings_set_account_name (store_settings, store_name);
+ transport_settings = modest_account_settings_get_transport_settings (settings);
+ modest_server_account_settings_set_account_name (transport_settings, transport_name);
+ g_object_unref (store_settings);
+ g_object_unref (transport_settings);
+
+ /* Create the account, which will contain the two "server accounts": */
+ modest_account_mgr_save_account_settings (self, settings);
+ g_free (store_name);
+ g_free (transport_name);
+
+ /* Sanity check: */
+ /* There must be at least one account now: */
+ /* Note, when this fails is is caused by a Maemo gconf bug that has been
+ * fixed in versions after 3.1. */
+ if(!modest_account_mgr_has_accounts (self, FALSE))
+ g_warning ("modest_account_mgr_account_names() returned NULL after adding an account.");
+
+ /* Notify the observers */
+ g_signal_emit (self, signals[ACCOUNT_INSERTED_SIGNAL], 0, account_name);
+
+ /* if no default account has been defined yet, do so now */
+ default_account = modest_account_mgr_get_default_account (self);
+ if (!default_account) {
+ modest_account_mgr_set_default_account (self, account_name);
+ modest_account_settings_set_is_default (settings, TRUE);
+ }
+ g_free (default_account);
+ g_free (account_name);
+
+ /* (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;
+}
+
gboolean
modest_account_mgr_add_account (ModestAccountMgr *self,
const gchar *name,
+ const gchar *display_name,
+ const gchar *user_fullname,
+ const gchar *user_email,
+ ModestAccountRetrieveType retrieve_type,
const gchar *store_account,
const gchar *transport_account,
gboolean enabled)
modest_account_mgr_set_bool (self, name, MODEST_ACCOUNT_LEAVE_ON_SERVER, TRUE, FALSE);
modest_account_mgr_set_bool (self, name, MODEST_ACCOUNT_ENABLED, enabled,FALSE);
+ /* Fill other data */
+ modest_account_mgr_set_string (self, name,
+ MODEST_ACCOUNT_DISPLAY_NAME,
+ display_name, FALSE);
+ modest_account_mgr_set_string (self, name,
+ MODEST_ACCOUNT_FULLNAME,
+ user_fullname, FALSE);
+ modest_account_mgr_set_string (self, name,
+ MODEST_ACCOUNT_EMAIL,
+ user_email, FALSE);
+ modest_account_mgr_set_retrieve_type (self, name,
+ retrieve_type);
+
/* Notify the observers */
g_signal_emit (self, signals[ACCOUNT_INSERTED_SIGNAL], 0, name);
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;
}
const gchar *key, ModestConfValueType list_type,
gboolean server_account)
{
- ModestAccountMgrPrivate *priv;
+ ModestAccountMgrPrivate *priv = MODEST_ACCOUNT_MGR_GET_PRIVATE (self);
const gchar *keyname;
GSList *retval;
const gchar * key, int val, gboolean server_account)
{
ModestAccountMgrPrivate *priv;
-
const gchar *keyname;
gboolean retval;
GError *err = NULL;
g_printerr ("modest: error setting int '%s': %s\n", keyname, err->message);
g_error_free (err);
retval = FALSE;
+ } else {
+ /* check whether this field is one of those interesting for the
+ * "account-updated" signal */
+ if (strcmp(key, MODEST_ACCOUNT_LAST_UPDATED) == 0) {
+ g_signal_emit (G_OBJECT(self), signals[ACCOUNT_UPDATED_SIGNAL],
+ 0, name);
+ }
}
return retval;
}
/* Look at each non-server account to check their display names; */
while (cursor) {
- const gchar * account_name = (gchar*)cursor->data;
+ const gchar *account_name = (gchar*)cursor->data;
+ const gchar *cursor_display_name;
- ModestAccountData *account_data = modest_account_mgr_get_account_data (self, account_name);
- if (!account_data) {
+ ModestAccountSettings *settings = modest_account_mgr_load_account_settings (self, account_name);
+ if (!settings) {
g_printerr ("modest: failed to get account data for %s\n", account_name);
continue;
}
- if(account_data->display_name && (strcmp (account_data->display_name, display_name) == 0)) {
+ cursor_display_name = modest_account_settings_get_display_name (settings);
+ if(cursor_display_name && (strcmp (cursor_display_name, display_name) == 0)) {
found = TRUE;
+ g_object_unref (settings);
break;
}
- modest_account_mgr_free_account_data (self, account_data);
+ g_object_unref (settings);
cursor = cursor->next;
}
modest_account_mgr_free_account_names (account_names);
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,