2007-06-12 Murray Cumming <murrayc@murrayc.com>
[modest] / src / modest-account-mgr.c
index f5bde23..44d7421 100644 (file)
@@ -56,12 +56,12 @@ on_timeout_notify_changes (gpointer data)
 {
        ModestAccountMgr *self = MODEST_ACCOUNT_MGR (data);
        ModestAccountMgrPrivate *priv = MODEST_ACCOUNT_MGR_GET_PRIVATE (self);
-       
+               
        /* TODO: Also store the account names, and notify one list for each account,
         * if anything uses the account names. */
        
        if (priv->changed_conf_keys) {
-               gchar *default_account =
+               gchar *default_account = 
                                modest_account_mgr_get_default_account (self);
                
                g_signal_emit (G_OBJECT(self), signals[ACCOUNT_CHANGED_SIGNAL], 0,
@@ -80,8 +80,6 @@ on_timeout_notify_changes (gpointer data)
 static void
 on_key_change (ModestConf *conf, const gchar *key, ModestConfEvent event, gpointer user_data)
 {
-       /* printf("DEBUG: %s: key=%s\n", __FUNCTION__, key); */
-       
        ModestAccountMgr *self = MODEST_ACCOUNT_MGR (user_data);
        ModestAccountMgrPrivate *priv = MODEST_ACCOUNT_MGR_GET_PRIVATE (self);
 
@@ -92,7 +90,7 @@ on_key_change (ModestConf *conf, const gchar *key, ModestConfEvent event, gpoint
                
                /* Store the key for later notification in our timeout callback.
                 * Notifying for every key change would cause unnecessary work: */
-               priv->changed_conf_keys = g_slist_append (NULL, 
+               priv->changed_conf_keys = g_slist_append (priv->changed_conf_keys, 
                        (gpointer) g_strdup (key));
        }
        
@@ -350,8 +348,6 @@ modest_account_mgr_add_account (ModestAccountMgr *self,
 }
 
 
-
-
 gboolean
 modest_account_mgr_add_server_account (ModestAccountMgr * self,
                                       const gchar * name, const gchar *hostname,
@@ -584,8 +580,10 @@ modest_account_mgr_remove_account (ModestAccountMgr * self,
                if (default_account_name && (strcmp (default_account_name, name) == 0))
                        modest_account_mgr_unset_default_account (self);
                g_free (default_account_name);
+               
+               /* pick another one as the new default account */
+               modest_account_mgr_set_first_account_as_default (self);
        }
-       
        return retval;
 }
 
@@ -997,7 +995,6 @@ modest_account_mgr_account_exists (ModestAccountMgr * self, const gchar * name,
         g_return_val_if_fail (name, FALSE);
 
        keyname = _modest_account_mgr_get_account_keyname (name, NULL, server_account);
-
        priv = MODEST_ACCOUNT_MGR_GET_PRIVATE (self);
        retval = modest_conf_key_exists (priv->modest_conf, keyname, &err);
        if (err) {
@@ -1010,8 +1007,8 @@ 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)
+gboolean
+modest_account_mgr_account_with_display_name_exists  (ModestAccountMgr *self, const gchar *display_name)
 {
        GSList *account_names = NULL;
        GSList *cursor = NULL;
@@ -1163,3 +1160,15 @@ _modest_account_mgr_get_account_keyname (const gchar *account_name, const gchar
 
        return retval;
 }
+
+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;
+       g_slist_free (account_names);
+       
+       return accounts_exist;
+}