+ if (g_str_has_suffix (server_account_name, t))
+ server_account_name [len_a - len_t] = '\0';
+ else if (g_str_has_suffix (server_account_name, s))
+ server_account_name [len_a - len_s] = '\0';
+}
+
+
+
+static void
+on_key_change (ModestConf *conf, const gchar *key, ModestConfEvent event,
+ ModestConfNotificationId id, gpointer user_data)
+{
+ ModestAccountMgr *self = MODEST_ACCOUNT_MGR (user_data);
+ ModestAccountMgrPrivate *priv = MODEST_ACCOUNT_MGR_GET_PRIVATE (self);
+
+ gboolean is_account_key;
+ gboolean is_server_account;
+ gchar* account_name = NULL;
+
+ /* 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) {
+ /* Get the default account instead. */
+ gchar *default_account = modest_account_mgr_get_default_account (self);
+ if (!default_account) {
+ g_warning ("BUG: cannot find default account");
+ return;
+ } else {
+ g_signal_emit (G_OBJECT(self), signals[ACCOUNT_CHANGED_SIGNAL], 0,
+ default_account);
+ g_free(default_account);
+ return;
+ }
+ }
+
+ is_account_key = FALSE;
+ is_server_account = FALSE;
+ account_name = _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_name)
+ return;
+
+ /* ignore server account changes */
+ if (is_server_account)
+ /* change in place: retrieve the parent account name */
+ get_account_name_from_server_account (account_name);
+
+ /* account was removed. Do not emit an account removed signal
+ because it was already being done in the remove_account
+ method. Do not notify also the removal of the server
+ account keys for the same reason */
+ if ((is_account_key || is_server_account) &&
+ event == MODEST_CONF_EVENT_KEY_UNSET) {
+ g_free (account_name);
+ return;
+ }
+
+ /* is this account enabled? */
+ gboolean enabled = FALSE;
+ if (is_server_account)
+ enabled = TRUE;
+ else
+ enabled = modest_account_mgr_get_enabled (self, account_name);
+
+ /* Notify is server account was changed, default account was changed
+ * or when enabled/disabled changes:
+ */
+ if (!is_server_account)
+ if (enabled || g_str_has_suffix (key, MODEST_ACCOUNT_ENABLED) ||
+ strcmp (key, MODEST_CONF_DEFAULT_ACCOUNT) == 0) {
+ if (!in_change_queue (priv->change_queue, account_name)) {
+ priv->change_queue = add_to_change_queue (priv->change_queue,
+ account_name);
+ /* hmm, small race when this object is destroyed within
+ * 500ms of the last change, and there are multiple timeouts... */
+ priv->timeout = g_timeout_add (500, (GSourceFunc)on_timeout_notify_changes,
+ self);
+ }
+ }
+ g_free (account_name);