X-Git-Url: http://git.maemo.org/git/?a=blobdiff_plain;f=src%2Fmodest-account-mgr.c;h=a129e51aaf7db4d805795f3ad87ebdac27781a25;hb=6bab4bfef92fef73852d6acd51d1ebf381a338e4;hp=84e6e0fafb4b09f452062d2094bbc6c895fb7b83;hpb=c0d1c43e9e48abc7d867cabcd57ccc9a6917a41b;p=modest diff --git a/src/modest-account-mgr.c b/src/modest-account-mgr.c index 84e6e0f..a129e51 100644 --- a/src/modest-account-mgr.c +++ b/src/modest-account-mgr.c @@ -53,15 +53,10 @@ static guint signals[LAST_SIGNAL] = {0}; static void on_key_change (ModestConf *conf, const gchar *key, ModestConfEvent event, gpointer user_data) { - ModestAccountMgr *self; - ModestAccountMgrPrivate *priv; - - gchar *account; - gboolean is_account_key, is_server_account; - gboolean enabled; - - self = MODEST_ACCOUNT_MGR (user_data); - priv = MODEST_ACCOUNT_MGR_GET_PRIVATE (self); + /* printf("DEBUG: %s: key=%s\n", __FUNCTION__, key); */ + + ModestAccountMgr *self = MODEST_ACCOUNT_MGR (user_data); + /* ModestAccountMgrPrivate *priv = MODEST_ACCOUNT_MGR_GET_PRIVATE (self); */ /* there is only one not-really-account key which will still emit * a signal: a change in MODEST_CONF_DEFAULT_ACCOUNT */ @@ -74,7 +69,9 @@ on_key_change (ModestConf *conf, const gchar *key, ModestConfEvent event, gpoint return; } - account = _modest_account_mgr_account_from_key (key, &is_account_key, &is_server_account); + gboolean is_account_key = FALSE; + gboolean is_server_account = FALSE; + gchar* account = _modest_account_mgr_account_from_key (key, &is_account_key, &is_server_account); /* if this is not an account-related key change, ignore */ if (!account) @@ -89,13 +86,14 @@ on_key_change (ModestConf *conf, const gchar *key, ModestConfEvent event, gpoint } /* is this account enabled? */ + gboolean enabled = FALSE; if (is_server_account) enabled = TRUE; else enabled = modest_account_mgr_get_enabled (self, account); - /* server account was changed, default account was changed - * and always notify when enabled/disabled changes + /* Notify is server account was changed, default account was changed + * or when enabled/disabled changes: */ if (enabled || g_str_has_suffix (key, MODEST_ACCOUNT_ENABLED) || @@ -222,7 +220,8 @@ gboolean modest_account_mgr_add_account (ModestAccountMgr *self, const gchar *name, const gchar *store_account, - const gchar *transport_account) + const gchar *transport_account, + gboolean enabled) { ModestAccountMgrPrivate *priv; gchar *key; @@ -252,7 +251,7 @@ modest_account_mgr_add_account (ModestAccountMgr *self, if (!ok) { g_printerr ("modest: cannot set display name\n"); if (err) { - g_printerr ("modest: %s\n", err->message); + g_printerr ("modest: Error adding account conf: %s\n", err->message); g_error_free (err); } return FALSE; @@ -266,7 +265,7 @@ modest_account_mgr_add_account (ModestAccountMgr *self, g_printerr ("modest: failed to set store account '%s'\n", store_account); if (err) { - g_printerr ("modest: %s\n", err->message); + g_printerr ("modest: Error adding store account conf: %s\n", err->message); g_error_free (err); } @@ -283,13 +282,21 @@ modest_account_mgr_add_account (ModestAccountMgr *self, g_printerr ("modest: failed to set transport account '%s'\n", transport_account); if (err) { - g_printerr ("modest: %s\n", err->message); + g_printerr ("modest: Error adding transport account conf: %s\n", err->message); g_error_free (err); } return FALSE; } } - modest_account_mgr_set_enabled (self, name, TRUE); + + /* Make sure that leave-messages-on-server is enabled by default, + * as per the UI spec, though it is only meaningful for accounts using POP. + * (possibly this gconf key should be under the server account): */ + modest_account_mgr_set_bool (self, name, + MODEST_ACCOUNT_LEAVE_ON_SERVER, TRUE, FALSE /* not server account */); + + + modest_account_mgr_set_enabled (self, name, enabled); /* if no default account has been defined yet, do so now */ default_account = modest_account_mgr_get_default_account (self); @@ -306,33 +313,30 @@ modest_account_mgr_add_account (ModestAccountMgr *self, gboolean modest_account_mgr_add_server_account (ModestAccountMgr * self, const gchar * name, const gchar *hostname, + guint portnumber, const gchar * username, const gchar * password, - ModestProtocol proto) + ModestTransportStoreProtocol proto, + ModestConnectionProtocol security, + ModestAuthProtocol auth) { ModestAccountMgrPrivate *priv; gchar *key; - ModestProtocolType proto_type; - gboolean ok; + gboolean ok = TRUE; GError *err = NULL; g_return_val_if_fail (MODEST_IS_ACCOUNT_MGR(self), FALSE); g_return_val_if_fail (name, FALSE); g_return_val_if_fail (strchr(name, '/') == NULL, FALSE); - - proto_type = modest_protocol_info_get_protocol_type (proto); - g_return_val_if_fail (proto_type == MODEST_PROTOCOL_TYPE_TRANSPORT || - proto_type == MODEST_PROTOCOL_TYPE_STORE, FALSE); priv = MODEST_ACCOUNT_MGR_GET_PRIVATE (self); /* hostname */ key = _modest_account_mgr_get_account_keyname (name, MODEST_ACCOUNT_HOSTNAME, TRUE); if (modest_conf_key_exists (priv->modest_conf, key, &err)) { - g_printerr ("modest: server account '%s' already exists", name); + g_printerr ("modest: server account '%s' already exists\n", name); g_free (key); ok = FALSE; } - g_free (key); if (!ok) goto cleanup; @@ -374,14 +378,48 @@ modest_account_mgr_add_server_account (ModestAccountMgr * self, /* proto */ key = _modest_account_mgr_get_account_keyname (name, MODEST_ACCOUNT_PROTO, TRUE); ok = modest_conf_set_string (priv->modest_conf, key, - modest_protocol_info_get_protocol_name(proto), &err); + modest_protocol_info_get_transport_store_protocol_name(proto), + &err); + if (err) { + g_printerr ("modest: failed to set %s: %s\n", key, err->message); + g_error_free (err); + ok = FALSE; + } + g_free (key); + if (!ok) + goto cleanup; + + + /* portnumber */ + key = _modest_account_mgr_get_account_keyname (name, MODEST_ACCOUNT_PORT, TRUE); + ok = modest_conf_set_int (priv->modest_conf, key, portnumber, &err); if (err) { g_printerr ("modest: failed to set %s: %s\n", key, err->message); g_error_free (err); ok = FALSE; } g_free (key); + if (!ok) + goto cleanup; + + /* auth mechanism */ + key = _modest_account_mgr_get_account_keyname (name, MODEST_ACCOUNT_AUTH_MECH, TRUE); + ok = modest_conf_set_string (priv->modest_conf, key, + modest_protocol_info_get_auth_protocol_name (auth), + &err); + if (err) { + g_printerr ("modest: failed to set %s: %s\n", key, err->message); + g_error_free (err); + ok = FALSE; + } + g_free (key); + if (!ok) + goto cleanup; + + /* Add the security settings: */ + modest_server_account_set_security (self, name, security); + cleanup: if (!ok) { g_printerr ("modest: failed to add server account\n"); @@ -391,10 +429,12 @@ cleanup: return TRUE; } - +/** modest_account_mgr_add_server_account_uri: + * Only used for mbox and maildir accounts. + */ gboolean modest_account_mgr_add_server_account_uri (ModestAccountMgr * self, - const gchar *name, ModestProtocol proto, + const gchar *name, ModestTransportStoreProtocol proto, const gchar *uri) { ModestAccountMgrPrivate *priv; @@ -412,7 +452,8 @@ modest_account_mgr_add_server_account_uri (ModestAccountMgr * self, /* proto */ key = _modest_account_mgr_get_account_keyname (name, MODEST_ACCOUNT_PROTO, TRUE); ok = modest_conf_set_string (priv->modest_conf, key, - modest_protocol_info_get_protocol_name(proto), NULL); + modest_protocol_info_get_transport_store_protocol_name(proto), + NULL); g_free (key); if (!ok) { @@ -451,6 +492,31 @@ modest_account_mgr_remove_account (ModestAccountMgr * self, return FALSE; } + /* in case we're not deleting an account, also delete the dependent store and transport account */ + if (!server_account) { + gchar *server_account_name; + + server_account_name = modest_account_mgr_get_string (self, name, MODEST_ACCOUNT_STORE_ACCOUNT, + FALSE); + if (server_account_name) { + if (!modest_account_mgr_remove_account (self, server_account_name, TRUE)) + g_printerr ("modest: failed to remove store account '%s' (%s)\n", + server_account_name, name); + g_free (server_account_name); + } else + g_printerr ("modest: could not find the store account for %s\n", name); + + server_account_name = modest_account_mgr_get_string (self, name, MODEST_ACCOUNT_TRANSPORT_ACCOUNT, + FALSE); + if (server_account_name) { + if (!modest_account_mgr_remove_account (self, server_account_name, TRUE)) + g_printerr ("modest: failed to remove transport account '%s' (%s)\n", + server_account_name, name); + g_free (server_account_name); + } else + g_printerr ("modest: could not find the transport account for %s\n", name); + } + priv = MODEST_ACCOUNT_MGR_GET_PRIVATE (self); key = _modest_account_mgr_get_account_keyname (name, NULL, server_account); @@ -461,6 +527,14 @@ modest_account_mgr_remove_account (ModestAccountMgr * self, g_printerr ("modest: error removing key: %s\n", err->message); g_error_free (err); } + + /* If this was the default, then remove that setting: */ + if (!server_account) { + gchar *default_account_name = modest_account_mgr_get_default_account (self); + if (default_account_name && (strcmp (default_account_name, name) == 0)) + modest_account_mgr_unset_default_account (self); + g_free (default_account_name); + } return retval; } @@ -482,12 +556,12 @@ strip_prefix_from_elements (GSList * lst, guint n) } } - +#if 0 +/* Not used. */ GSList* modest_account_mgr_search_server_accounts (ModestAccountMgr * self, const gchar * account_name, - ModestProtocolType type, - ModestProtocol proto) + ModestTransportStoreProtocol proto) { GSList *accounts; GSList *cursor; @@ -496,13 +570,6 @@ modest_account_mgr_search_server_accounts (ModestAccountMgr * self, GError *err = NULL; g_return_val_if_fail (self, NULL); - - if (proto != MODEST_PROTOCOL_UNKNOWN) { - ModestProtocolType proto_type; - proto_type = modest_protocol_info_get_protocol_type (proto); - g_return_val_if_fail (proto_type == MODEST_PROTOCOL_TYPE_TRANSPORT || - proto_type == MODEST_PROTOCOL_TYPE_STORE, NULL); - } key = _modest_account_mgr_get_account_keyname (account_name, NULL, TRUE); priv = MODEST_ACCOUNT_MGR_GET_PRIVATE (self); @@ -523,11 +590,9 @@ modest_account_mgr_search_server_accounts (ModestAccountMgr * self, while (cursor) { gchar *account = _modest_account_mgr_account_from_key ((gchar*)cursor->data, NULL, NULL); gchar *acc_proto = modest_account_mgr_get_string (self, account, MODEST_ACCOUNT_PROTO,TRUE); - ModestProtocol this_proto = modest_protocol_info_get_protocol (acc_proto); - ModestProtocolType this_type = modest_protocol_info_get_protocol_type (this_proto); - - if ((this_type != MODEST_PROTOCOL_TYPE_UNKNOWN && this_type != type) || - (this_proto != MODEST_PROTOCOL_UNKNOWN && this_proto != proto)) { + ModestTransportStoreProtocol this_proto = + modest_protocol_info_get_transport_store_protocol (acc_proto); + if (this_proto != MODEST_PROTOCOL_TRANSPORT_STORE_UNKNOWN && this_proto != proto) { GSList *nxt = cursor->next; accounts = g_slist_delete_link (accounts, cursor); cursor = nxt; @@ -542,10 +607,10 @@ modest_account_mgr_search_server_accounts (ModestAccountMgr * self, strip_prefix_from_elements (accounts, strlen(key)+1); return accounts; } - +#endif GSList* -modest_account_mgr_account_names (ModestAccountMgr * self) +modest_account_mgr_account_names (ModestAccountMgr * self, gboolean only_enabled) { GSList *accounts; ModestAccountMgrPrivate *priv; @@ -567,7 +632,45 @@ modest_account_mgr_account_names (ModestAccountMgr * self) } strip_prefix_from_elements (accounts, prefix_len); - return accounts; + + GSList *result = NULL; + + /* Unescape the keys to get the account names: */ + GSList *iter = accounts; + while (iter) { + if (!(iter->data)) + continue; + + const gchar* account_name_key = (const gchar*)iter->data; + /* printf ("DEBUG: %s: account_name_key=%s\n", __FUNCTION__, account_name_key); */ + gchar* unescaped_name = account_name_key ? + modest_conf_key_unescape (account_name_key) + : NULL; + /* printf (" DEBUG: %s: unescaped name=%s\n", __FUNCTION__, unescaped_name); */ + + gboolean add = TRUE; + if (only_enabled) { + if (unescaped_name && + !modest_account_mgr_get_enabled (self, unescaped_name)) { + add = FALSE; + } + } + + if (add) { + result = g_slist_append (result, unescaped_name); + } + else { + g_free (unescaped_name); + } + + iter = g_slist_next (iter); + } + + /* TODO: Free the strings too? */ + g_slist_free (accounts); + accounts = NULL; + + return result; } @@ -857,6 +960,41 @@ modest_account_mgr_account_exists (ModestAccountMgr * self, const gchar * name, return retval; } +gboolean modest_account_mgr_account_with_display_name_exists (ModestAccountMgr *self, + const gchar *display_name) +{ + GSList *account_names = NULL; + GSList *cursor = NULL; + + cursor = account_names = modest_account_mgr_account_names (self, + TRUE /* enabled accounts, because disabled accounts are not user visible. */); + + gboolean found = FALSE; + + /* Look at each non-server account to check their display names; */ + while (cursor) { + const gchar * account_name = (gchar*)cursor->data; + + ModestAccountData *account_data = modest_account_mgr_get_account_data (self, account_name); + if (!account_data) { + 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)) { + found = TRUE; + break; + } + + modest_account_mgr_free_account_data (self, account_data); + cursor = cursor->next; + } + g_slist_free (account_names); + + return found; +} + + gboolean