Modified webpage: now tinymail repository is in gitorious.
[modest] / src / modest-account-mgr.c
index 913d7d4..a52eec6 100644 (file)
@@ -342,6 +342,7 @@ modest_account_mgr_add_account_from_settings (ModestAccountMgr *self,
                                
        /* Notify the observers */
        g_signal_emit (self, signals[ACCOUNT_INSERTED_SIGNAL], 0, account_name);
+       modest_platform_emit_account_created_signal (account_name);
 
        /* if no default account has been defined yet, do so now */
        default_account = modest_account_mgr_get_default_account (self);
@@ -456,6 +457,7 @@ modest_account_mgr_add_account (ModestAccountMgr *self,
 
        /* Notify the observers */
        g_signal_emit (self, signals[ACCOUNT_INSERTED_SIGNAL], 0, name);
+       modest_platform_emit_account_created_signal (name);
 
        /* if no default account has been defined yet, do so now */
        default_account = modest_account_mgr_get_default_account (self);
@@ -717,10 +719,31 @@ modest_account_mgr_remove_account (ModestAccountMgr * self,
           the keys, because otherwise a call to account_names
           will retrieve also the deleted account */
        g_signal_emit (G_OBJECT(self), signals[ACCOUNT_REMOVED_SIGNAL], 0, name);
+       modest_platform_emit_account_removed_signal (name);
        
        return TRUE;
 }
 
+gboolean
+modest_account_mgr_remove_server_account (ModestAccountMgr * self,
+                                         const gchar* name)
+{
+       ModestAccountMgrPrivate *priv;
+
+       g_return_val_if_fail (MODEST_IS_ACCOUNT_MGR(self), FALSE);
+       g_return_val_if_fail (name, FALSE);
+
+       if (!modest_account_mgr_account_exists (self, name, TRUE)) {
+               g_printerr ("modest: %s: server account '%s' does not exist\n", __FUNCTION__, name);
+               return FALSE;
+       }
+
+       priv = MODEST_ACCOUNT_MGR_GET_PRIVATE (self);
+       real_remove_account (priv->modest_conf, name, TRUE);
+
+       return TRUE;
+}
+
 
 
 /* strip the first /n/ character from each element
@@ -746,7 +769,8 @@ modest_account_mgr_account_names (ModestAccountMgr * self, gboolean only_enabled
        ModestAccountMgrPrivate *priv;
        GError *err = NULL;
        
-       const size_t prefix_len = strlen (MODEST_ACCOUNT_NAMESPACE "/");
+       /* we add 1 for the trailing "/" */
+       const size_t prefix_len = strlen (MODEST_ACCOUNT_NAMESPACE) + 1;
 
        g_return_val_if_fail (self, NULL);
 
@@ -768,9 +792,11 @@ modest_account_mgr_account_names (ModestAccountMgr * self, gboolean only_enabled
        /* Unescape the keys to get the account names: */
        GSList *iter = accounts;
        while (iter) {
-               if (!(iter->data))
+               if (!(iter->data)) {
+                       iter = iter->next;
                        continue;
-                       
+               }
+
                const gchar* account_name_key = (const gchar*)iter->data;
                gchar* unescaped_name = account_name_key ? 
                        modest_conf_key_unescape (account_name_key) 
@@ -936,7 +962,7 @@ modest_account_mgr_get_list (ModestAccountMgr *self, const gchar *name,
                             const gchar *key, ModestConfValueType list_type,
                             gboolean server_account)
 {
-       ModestAccountMgrPrivate *priv = MODEST_ACCOUNT_MGR_GET_PRIVATE (self);
+       ModestAccountMgrPrivate *priv = NULL;
 
        const gchar *keyname;
        GSList *retval;
@@ -1049,6 +1075,13 @@ modest_account_mgr_set_bool (ModestAccountMgr * self, const gchar * name,
                g_printerr ("modest: error setting bool '%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_HAS_NEW_MAILS) == 0) {
+                       g_signal_emit (G_OBJECT(self), signals[ACCOUNT_UPDATED_SIGNAL], 
+                                       0, name);
+               }
        }
 
        return retval;
@@ -1132,6 +1165,7 @@ modest_account_mgr_account_with_display_name_exists  (ModestAccountMgr *self,
                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);
+                       cursor = cursor->next;
                        continue;
                }
 
@@ -1210,6 +1244,7 @@ modest_account_mgr_check_already_configured_account  (ModestAccountMgr *self,
                from_mgr_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);
+                       cursor = cursor->next;
                        continue;
                }
 
@@ -1266,6 +1301,11 @@ modest_account_mgr_unset (ModestAccountMgr *self, const gchar *name,
 gchar*
 _modest_account_mgr_account_from_key (const gchar *key, gboolean *is_account_key, gboolean *is_server_account)
 {
+       const gchar* account_ns;
+       const gchar* server_account_ns;
+       gchar *account = NULL;
+       gchar *unescaped_name = NULL;
+
        /* Initialize input parameters: */
        if (is_account_key)
                *is_account_key = FALSE;
@@ -1273,10 +1313,8 @@ _modest_account_mgr_account_from_key (const gchar *key, gboolean *is_account_key
        if (is_server_account)
                *is_server_account = FALSE;
 
-       const gchar* account_ns        = MODEST_ACCOUNT_NAMESPACE "/";
-       const gchar* server_account_ns = MODEST_SERVER_ACCOUNT_NAMESPACE "/";
-       gchar *cursor;
-       gchar *account = NULL;
+       account_ns        = modest_defs_namespace (MODEST_ACCOUNT_SUBNAMESPACE "/");
+       server_account_ns = modest_defs_namespace (MODEST_SERVER_ACCOUNT_SUBNAMESPACE "/");
 
        /* determine whether it's an account or a server account,
         * based on the prefix */
@@ -1284,37 +1322,40 @@ _modest_account_mgr_account_from_key (const gchar *key, gboolean *is_account_key
 
                if (is_server_account)
                        *is_server_account = FALSE;
-               
+
                account = g_strdup (key + strlen (account_ns));
 
        } else if (g_str_has_prefix (key, server_account_ns)) {
 
                if (is_server_account)
                        *is_server_account = TRUE;
-               
-               account = g_strdup (key + strlen (server_account_ns));  
+
+               account = g_strdup (key + strlen (server_account_ns));
        } else
                return NULL;
 
-       /* if there are any slashes left in the key, it's not
-        * the toplevel entry for an account
-        */
-       cursor = strstr(account, "/");
-       
-       if (is_account_key && cursor)
-               *is_account_key = TRUE;
+       if (account) {
+               gchar *cursor;
 
-       /* put a NULL where the first slash was */
-       if (cursor)
-               *cursor = '\0';
+               /* if there are any slashes left in the key, it's not
+                * the toplevel entry for an account
+                */
+               cursor = strstr(account, "/");
 
-       if (account) {
-               /* The key is an escaped string, so unescape it to get the actual account name: */
-               gchar *unescaped_name = modest_conf_key_unescape (account);
+               if (cursor) {
+                       if (is_account_key)
+                               *is_account_key = TRUE;
+
+                       /* put a NULL where the first slash was */
+                       *cursor = '\0';
+               }
+
+               /* The key is an escaped string, so unescape it to get the actual account name */
+               unescaped_name = modest_conf_key_unescape (account);
                g_free (account);
-               return unescaped_name;
-       } else
-               return NULL;
+       }
+
+       return unescaped_name;
 }
 
 
@@ -1345,7 +1386,7 @@ _modest_account_mgr_get_account_keyname (const gchar *account_name, const gchar*
                                         gboolean server_account)
 {
        gchar *retval = NULL;   
-       gchar *namespace = server_account ? MODEST_SERVER_ACCOUNT_NAMESPACE : MODEST_ACCOUNT_NAMESPACE;
+       gchar *namespace = server_account ? (gchar *) MODEST_SERVER_ACCOUNT_NAMESPACE : (gchar *) MODEST_ACCOUNT_NAMESPACE;
        gchar *escaped_account_name, *escaped_name;
        
        if (!account_name)
@@ -1434,7 +1475,7 @@ modest_account_mgr_has_accounts (ModestAccountMgr* self, gboolean enabled)
        
        if (enabled && priv->has_enabled_accounts)
                return TRUE;
-       else if (priv->has_accounts)
+       else if (!enabled && priv->has_accounts)
                return TRUE;
                
        /* Check that at least one account exists: */
@@ -1659,7 +1700,7 @@ modest_account_mgr_singleton_protocol_exists (ModestAccountMgr *mgr,
        gboolean found = FALSE;
 
        g_return_val_if_fail (MODEST_IS_ACCOUNT_MGR (mgr), FALSE);
-       account_names = modest_account_mgr_account_names (mgr, TRUE);
+       account_names = modest_account_mgr_account_names (mgr, FALSE);
 
        for (node = account_names; node != NULL; node = g_slist_next (node)) {
                ModestProtocolType current_protocol;