+static guint signals[LAST_SIGNAL] = {0};
+
+static void
+on_key_change (ModestConf *conf, const gchar *key, ModestConfEvent event, gpointer user_data)
+{
+ ModestAccountMgr *self;
+ ModestAccountMgrPrivate *priv;
+
+ gchar *account;
+ gboolean is_account_key, is_server_account;
+ gboolean enabled;
+
+ self = MODEST_ACCOUNT_MGR (user_data);
+ priv = MODEST_ACCOUNT_MGR_GET_PRIVATE (self);
+
+ /* there is only one not-really-account key which will still emit
+ * a signal: a change in MODEST_CONF_DEFAULT_ACCOUNT */
+ if (key && strcmp (key, MODEST_CONF_DEFAULT_ACCOUNT) == 0) {
+ gchar *default_account =
+ modest_account_mgr_get_default_account (self);
+ g_signal_emit (G_OBJECT(self), signals[ACCOUNT_CHANGED_SIGNAL], 0,
+ default_account, key, FALSE);
+ g_free (default_account);
+ return;
+ }
+
+ account = _modest_account_mgr_account_from_key (key, &is_account_key, &is_server_account);
+
+ /* if this is not an account-related key change, ignore */
+ if (!account)
+ return;
+
+ /* account was removed -- emit this, even if the account was disabled */
+ if (is_account_key && event == MODEST_CONF_EVENT_KEY_UNSET) {
+ g_signal_emit (G_OBJECT(self), signals[ACCOUNT_REMOVED_SIGNAL], 0,
+ account, is_server_account);
+ g_free (account);
+ return;
+ }
+
+ /* is this account enabled? */
+ if (is_server_account)
+ enabled = TRUE;
+ else
+ enabled = modest_account_mgr_get_enabled (self, account);
+
+ /* server account was changed, default account was changed
+ * and always notify when enabled/disabled changes
+ */
+ if (enabled ||
+ g_str_has_suffix (key, MODEST_ACCOUNT_ENABLED) ||
+ strcmp (key, MODEST_CONF_DEFAULT_ACCOUNT) == 0)
+ g_signal_emit (G_OBJECT(self), signals[ACCOUNT_CHANGED_SIGNAL], 0,
+ account, key, is_server_account);
+
+ g_free (account);
+}