* do proper refcounting for ModestConf instances
authorDirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>
Thu, 20 Jul 2006 14:16:04 +0000 (14:16 +0000)
committerDirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>
Thu, 20 Jul 2006 14:16:04 +0000 (14:16 +0000)
* API update for enable/disable API
* some internal refactoring

pmo-trunk-r395

src/modest-account-mgr.c
src/modest-account-mgr.h

index 60209b1..c63ff48 100644 (file)
@@ -129,8 +129,8 @@ on_key_change (ModestConf *conf, const gchar *key, ModestConfEvent event, gpoint
        }
 
        /* is this account enabled? */
        }
 
        /* is this account enabled? */
-       enabled = modest_account_mgr_account_is_enabled (self, account,
-                                                        is_server_account);
+       enabled = modest_account_mgr_account_get_enabled (self, account,
+                                                         is_server_account);
 
        /* account was changed.
         * and always notify when enabled/disabled changes
 
        /* account was changed.
         * and always notify when enabled/disabled changes
@@ -216,8 +216,11 @@ modest_account_mgr_finalize (GObject * obj)
 {
        ModestAccountMgrPrivate *priv =
                MODEST_ACCOUNT_MGR_GET_PRIVATE (obj);
 {
        ModestAccountMgrPrivate *priv =
                MODEST_ACCOUNT_MGR_GET_PRIVATE (obj);
-       
-       priv->modest_conf = NULL;
+
+       if (priv->modest_conf) {
+               g_object_unref (G_OBJECT(priv->modest_conf));
+               priv->modest_conf = NULL;
+       }
 }
 
 
 }
 
 
@@ -232,7 +235,8 @@ modest_account_mgr_new (ModestConf * conf)
        obj = G_OBJECT (g_object_new (MODEST_TYPE_ACCOUNT_MGR, NULL));
        priv = MODEST_ACCOUNT_MGR_GET_PRIVATE (obj);
 
        obj = G_OBJECT (g_object_new (MODEST_TYPE_ACCOUNT_MGR, NULL));
        priv = MODEST_ACCOUNT_MGR_GET_PRIVATE (obj);
 
-       priv->modest_conf      = conf;
+       g_object_ref (G_OBJECT(conf));
+       priv->modest_conf = conf;
 
        g_signal_connect (G_OBJECT (conf), "key_changed",
                          G_CALLBACK (on_key_change),
 
        g_signal_connect (G_OBJECT (conf), "key_changed",
                          G_CALLBACK (on_key_change),
@@ -249,30 +253,19 @@ null_means_empty (const gchar * str)
 }
 
 
 }
 
 
-
-gboolean
-modest_account_mgr_disable_account (ModestAccountMgr *self, const gchar* name,
-                                   gboolean is_server_account)
-{
-       return modest_account_mgr_set_bool (self, name,
-                                           MODEST_ACCOUNT_ENABLED, FALSE,
-                                           is_server_account, NULL);
-}
-
-
 gboolean
 gboolean
-modest_account_mgr_enable_account (ModestAccountMgr *self, const gchar* name,
-                                  gboolean is_server_account)
+modest_account_mgr_account_set_enabled (ModestAccountMgr *self, const gchar* name,
+                                       gboolean is_server_account, gboolean enabled)
 {
        return modest_account_mgr_set_bool (self, name,
 {
        return modest_account_mgr_set_bool (self, name,
-                                           MODEST_ACCOUNT_ENABLED, TRUE,
+                                           MODEST_ACCOUNT_ENABLED, enabled,
                                            is_server_account, NULL);
 }
 
 
 gboolean
                                            is_server_account, NULL);
 }
 
 
 gboolean
-modest_account_mgr_account_is_enabled (ModestAccountMgr *self, const gchar* name,
-                                      gboolean is_server_account)
+modest_account_mgr_account_get_enabled (ModestAccountMgr *self, const gchar* name,
+                                       gboolean is_server_account)
 {
        return modest_account_mgr_get_bool (self, name,
                                            MODEST_ACCOUNT_ENABLED, is_server_account,
 {
        return modest_account_mgr_get_bool (self, name,
                                            MODEST_ACCOUNT_ENABLED, is_server_account,
@@ -336,7 +329,7 @@ modest_account_mgr_add_account (ModestAccountMgr *self,
                }
        }
 
                }
        }
 
-       modest_account_mgr_enable_account (self, name, FALSE);
+       modest_account_mgr_account_set_enabled (self, name, FALSE, TRUE);
        
        return TRUE;
 }
        
        return TRUE;
 }
@@ -389,7 +382,7 @@ modest_account_mgr_add_server_account (ModestAccountMgr * self,
        g_free (key);
 
        /* enable it */
        g_free (key);
 
        /* enable it */
-       modest_account_mgr_enable_account (self, name, TRUE);
+       modest_account_mgr_account_set_enabled (self, name, TRUE, TRUE);
        
        return TRUE;
 }
        
        return TRUE;
 }
@@ -484,7 +477,7 @@ modest_account_mgr_search_server_accounts (ModestAccountMgr * self,
                
                account = account_from_key ((gchar*)cursor->data, NULL, NULL);
                
                
                account = account_from_key ((gchar*)cursor->data, NULL, NULL);
                
-               enabled   = modest_account_mgr_account_is_enabled (self, account, TRUE);
+               enabled   = modest_account_mgr_account_get_enabled (self, account, TRUE);
                acc_proto = modest_account_mgr_get_string (self, account, MODEST_ACCOUNT_PROTO,
                                                           TRUE, NULL);
                if ((!acc_proto) ||                                /* proto not defined? */
                acc_proto = modest_account_mgr_get_string (self, account, MODEST_ACCOUNT_PROTO,
                                                           TRUE, NULL);
                if ((!acc_proto) ||                                /* proto not defined? */
index 7298fac..5c36a63 100644 (file)
@@ -193,39 +193,22 @@ gboolean  modest_account_mgr_account_exists         (ModestAccountMgr *self,
 
 
 /**
 
 
 /**
- * modest_account_mgr_enable_account:
+ * modest_account_mgr_account_set_enabled
  * @self: a ModestAccountMgr instance
  * @self: a ModestAccountMgr instance
- * @name: the account name to disable
+ * @name: the account name 
  * @server_account: if TRUE, this is a server account
  * @server_account: if TRUE, this is a server account
+ * @enabled: if TRUE, the account will be enabled, if FALSE, it will be disabled
  * 
  * 
- * enable an account that has been disabled with 'modest_account_mgr_disable_account'
+ * enable/disabled an account
  *
  * Returns: TRUE if it worked, FALSE otherwise
  */
  *
  * Returns: TRUE if it worked, FALSE otherwise
  */
-gboolean modest_account_mgr_enable_account (ModestAccountMgr *self, const gchar* name,
-                                           gboolean is_server_account);
-
+gboolean modest_account_mgr_set_account_enabled (ModestAccountMgr *self, const gchar* name,
+                                                gboolean is_server_account, gboolean enabled);
 
 
 /**
 
 
 /**
- * modest_account_mgr_disable_account:
- * @self: a ModestAccountMgr instance
- * @name: the account name to disable
- * @server_account: if TRUE, this is a server account
- * 
- * disable an account. this will also stop change notification until
- * modest_account_mgr_enable_account is called. However, in case of removal, the
- * appropriate signal will still be emitted.
- *
- * Returns: TRUE if it worked, FALSE otherwise
- */
-gboolean modest_account_mgr_disable_account (ModestAccountMgr *self, const gchar* name,
-                                            gboolean is_server_account);
-
-
-
-/**
- * modest_account_mgr_account_is_enabled:
+ * modest_account_mgr_account_get_enabled:
  * @self: a ModestAccountMgr instance
  * @name: the account name to check
  * @server_account: if TRUE, this is a server account
  * @self: a ModestAccountMgr instance
  * @name: the account name to check
  * @server_account: if TRUE, this is a server account
@@ -234,10 +217,8 @@ gboolean modest_account_mgr_disable_account (ModestAccountMgr *self, const gchar
  *
  * Returns: TRUE if it is enabled, FALSE otherwise
  */
  *
  * Returns: TRUE if it is enabled, FALSE otherwise
  */
-gboolean modest_account_mgr_account_is_enabled (ModestAccountMgr *self, const gchar* name,
-                                               gboolean is_server_account);
-
-
+gboolean modest_account_mgr_account_get_enabled (ModestAccountMgr *self, const gchar* name,
+                                                gboolean is_server_account);
 
 
 /**
 
 
 /**