* only set auto-update alarms when there are accounts;
authorDirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>
Thu, 25 Oct 2007 15:42:12 +0000 (15:42 +0000)
committerDirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>
Thu, 25 Oct 2007 15:42:12 +0000 (15:42 +0000)
  also check with account addition/deletion.

Fixes: NB#64945

pmo-trunk-r3578

src/maemo/modest-platform.c
src/modest-account-mgr.c

index c1143f4..2bdd043 100644 (file)
 #define HILDON_OSSO_URI_ACTION "uri-action"
 #define URI_ACTION_COPY "copy:"
 
-/* The maximun number of notifications that could be shown in the
-   desktop. It's specified by the specs and limited by the screen
-   size */
-#define MAX_NOTIFICATIONS 6
-
-static osso_context_t *osso_context = NULL;
+static osso_context_t *osso_context = NULL; /* urgh global */
 
 static void    
 on_modest_conf_update_interval_changed (ModestConf* self, 
@@ -73,6 +68,8 @@ on_modest_conf_update_interval_changed (ModestConf* self,
                                        ModestConfNotificationId id, 
                                        gpointer user_data)
 {
+       g_return_if_fail (key);
+       
        if (strcmp (key, MODEST_CONF_UPDATE_INTERVAL) == 0) {
                const guint update_interval_minutes = 
                        modest_conf_get_int (self, MODEST_CONF_UPDATE_INTERVAL, NULL);
@@ -107,7 +104,8 @@ modest_platform_init (int argc, char *argv[])
 {
        osso_hw_state_t hw_state = { 0 };
        DBusConnection *con;    
-
+       GSList *acc_names;
+       
        if (!check_required_files ()) {
                g_printerr ("modest: missing required files\n");
                return FALSE;
@@ -190,10 +188,16 @@ modest_platform_init (int argc, char *argv[])
                          "key_changed",
                          G_CALLBACK (on_modest_conf_update_interval_changed), 
                          NULL);
-                         
-       /* Get the initial update interval from gconf: */
-       on_modest_conf_update_interval_changed(conf, MODEST_CONF_UPDATE_INTERVAL,
-                                              MODEST_CONF_EVENT_KEY_CHANGED, 0, NULL);
+
+       /* only force the setting of the default interval, if there are actually
+        * any accounts */
+       acc_names = modest_account_mgr_account_names (modest_runtime_get_account_mgr(), TRUE);
+       if (acc_names) {
+               /* Get the initial update interval from gconf: */
+               on_modest_conf_update_interval_changed(conf, MODEST_CONF_UPDATE_INTERVAL,
+                                                      MODEST_CONF_EVENT_KEY_CHANGED, 0, NULL);
+               modest_account_mgr_free_account_names (acc_names);
+       }
 
        /* initialize the addressbook */
        if (!osso_abook_init (&argc, &argv, osso_context)) {
index ae3848b..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);
@@ -358,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;
 }
 
@@ -594,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;
 }