* only set auto-update alarms when there are accounts;
[modest] / src / modest-account-mgr.c
index e3de899..2a309c4 100644 (file)
@@ -33,6 +33,7 @@
 #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);
@@ -258,6 +259,10 @@ null_means_empty (const gchar * str)
 gboolean
 modest_account_mgr_add_account (ModestAccountMgr *self,
                                const gchar *name,
+                               const gchar *display_name,
+                               const gchar *user_fullname,
+                               const gchar *user_email,
+                               const gchar *retrieve_type,
                                const gchar *store_account,
                                const gchar *transport_account,
                                gboolean enabled)
@@ -332,6 +337,20 @@ modest_account_mgr_add_account (ModestAccountMgr *self,
        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_string (self, name,
+                                      MODEST_ACCOUNT_RETRIEVE, 
+                                      retrieve_type, FALSE);
+
        /* Notify the observers */
        g_signal_emit (self, signals[ACCOUNT_INSERTED_SIGNAL], 0, name);
 
@@ -340,7 +359,11 @@ modest_account_mgr_add_account (ModestAccountMgr *self,
        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;
 }
 
@@ -576,6 +599,14 @@ modest_account_mgr_remove_account (ModestAccountMgr * self,
           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);
+       else
+               modest_account_mgr_free_account_names (acc_names);
+       
        return TRUE;
 }
 
@@ -794,7 +825,7 @@ modest_account_mgr_get_list (ModestAccountMgr *self, const gchar *name,
                             const gchar *key, ModestConfValueType list_type,
                             gboolean server_account)
 {
-       ModestAccountMgrPrivate *priv;
+       ModestAccountMgrPrivate *priv = MODEST_ACCOUNT_MGR_GET_PRIVATE (self);
 
        const gchar *keyname;
        GSList *retval;