diff options
author | Alberto Mardegan <mardy@users.sourceforge.net> | 2007-09-14 11:57:47 +0000 |
---|---|---|
committer | Alberto Mardegan <mardy@users.sourceforge.net> | 2007-09-14 11:57:47 +0000 |
commit | 0777460aee70a844a3bbd76b5534c249ac665406 (patch) | |
tree | f0698a323abb00f782755cd54fb99d087cb42032 | |
parent | ef00de1bcbc692a3b20a2f1d2709ec20eeadba05 (diff) |
Cache normalized and display name, instead of always retrieving them
from GConf.
git-svn-id: https://mission-control.svn.sourceforge.net/svnroot/mission-control/trunk@134 d91c8aed-3f2b-0410-a83d-924a1c20a0ba
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | libmissioncontrol/mc-account-monitor.c | 12 | ||||
-rw-r--r-- | libmissioncontrol/mc-account-priv.h | 2 | ||||
-rw-r--r-- | libmissioncontrol/mc-account.c | 95 |
4 files changed, 76 insertions, 38 deletions
@@ -2,6 +2,11 @@ * libmissioncontrol/mc-account-monitor.c, libmissioncontrol/mc-account-priv.h, libmissioncontrol/mc-account.c: + Cache normalized and display name, instead of always retrieving them + from GConf. + + * libmissioncontrol/mc-account-monitor.c, + libmissioncontrol/mc-account-priv.h, libmissioncontrol/mc-account.c: Move account enabledness related code to McAccount, avoiding some GConf lookups. diff --git a/libmissioncontrol/mc-account-monitor.c b/libmissioncontrol/mc-account-monitor.c index abb1c04e..f65c6ffe 100644 --- a/libmissioncontrol/mc-account-monitor.c +++ b/libmissioncontrol/mc-account-monitor.c @@ -291,6 +291,18 @@ _gconf_notify_cb (GConfClient *client, guint conn_id, GConfEntry *entry, if (strncmp (key, "param-", 6) == 0) g_signal_emit (monitor, signals[PARAM_CHANGED], 0, name, key + 6); + + /* report the changed value to the McAccount, if it's a cached setting */ + if (entry->value != NULL && entry->value->type == GCONF_VALUE_STRING) + { + const gchar *value; + + value = gconf_value_get_string (entry->value); + if (strcmp (key, MC_ACCOUNTS_GCONF_KEY_NORMALIZED_NAME) == 0) + _mc_account_set_normalized_name_priv (account, value); + else if (strcmp (key, MC_ACCOUNTS_GCONF_KEY_DISPLAY_NAME) == 0) + _mc_account_set_display_name_priv (account, value); + } } /* If we are enabling/disabling account */ diff --git a/libmissioncontrol/mc-account-priv.h b/libmissioncontrol/mc-account-priv.h index ba8634e5..a5c2f4c6 100644 --- a/libmissioncontrol/mc-account-priv.h +++ b/libmissioncontrol/mc-account-priv.h @@ -40,6 +40,8 @@ McAccount * _mc_account_new (const gchar *unique_name); void _mc_account_set_enabled_priv (McAccount *account, gboolean enabled); +void _mc_account_set_normalized_name_priv (McAccount *account, const gchar *name); +void _mc_account_set_display_name_priv (McAccount *account, const gchar *name); #endif /* __MC_ACCOUNT_PRIV_H__ */ diff --git a/libmissioncontrol/mc-account.c b/libmissioncontrol/mc-account.c index b3c545bf..2c11c90b 100644 --- a/libmissioncontrol/mc-account.c +++ b/libmissioncontrol/mc-account.c @@ -59,6 +59,8 @@ static gboolean mc_account_set_deleted (McAccount *account, gboolean deleted); static gboolean mc_account_is_deleted (McAccount *account); static gboolean _mc_account_gconf_get_boolean (McAccount *account, const gchar *name, gboolean param, gboolean *value); +static gboolean _mc_account_gconf_get_string (McAccount *account, + const gchar *name, gboolean param, gchar **value); static void mc_account_finalize (GObject *object) @@ -89,15 +91,27 @@ mc_account_clear_cache (void) McAccount * _mc_account_new (const gchar *unique_name) { + McAccountPrivate *priv; McAccount *new; gboolean enabled; + gchar *name; + new = (McAccount *)g_object_new (MC_TYPE_ACCOUNT, NULL); - MC_ACCOUNT_PRIV (new)->unique_name = g_strdup (unique_name); + priv = MC_ACCOUNT_PRIV (new); + priv->unique_name = g_strdup (unique_name); /* get enabledness status */ if (_mc_account_gconf_get_boolean (new, MC_ACCOUNTS_GCONF_KEY_ENABLED, FALSE, &enabled) && enabled) - MC_ACCOUNT_PRIV (new)->enabled = TRUE; + priv->enabled = TRUE; + + if (_mc_account_gconf_get_string (new, MC_ACCOUNTS_GCONF_KEY_NORMALIZED_NAME, + FALSE, &name)) + priv->normalized_names = g_slist_prepend (NULL, name); + + if (_mc_account_gconf_get_string (new, MC_ACCOUNTS_GCONF_KEY_DISPLAY_NAME, + FALSE, &name)) + priv->display_names = g_slist_prepend (NULL, name); return new; } @@ -109,6 +123,45 @@ _mc_account_set_enabled_priv (McAccount *account, gboolean enabled) MC_ACCOUNT_PRIV (account)->enabled = enabled; } +static GSList * +set_first_element (GSList *list, const gchar *value) +{ + GSList *elem; + + if ((elem = g_slist_find_custom(list, value, (GCompareFunc)strcmp)) != NULL) + { + if (elem != list) + { + /* move the new name at the beginning of the list */ + list = g_slist_remove_link (list, elem); + list = g_slist_concat (elem, list); + } + } + else + list = g_slist_prepend (list, g_strdup (value)); + return list; +} + +void +_mc_account_set_normalized_name_priv (McAccount *account, const gchar *name) +{ + McAccountPrivate *priv; + + g_return_if_fail (account != NULL); + priv = MC_ACCOUNT_PRIV (account); + priv->normalized_names = set_first_element (priv->normalized_names, name); +} + +void +_mc_account_set_display_name_priv (McAccount *account, const gchar *name) +{ + McAccountPrivate *priv; + + g_return_if_fail (account != NULL); + priv = MC_ACCOUNT_PRIV (account); + priv->display_names = set_first_element (priv->display_names, name); +} + static void mc_account_class_init (McAccountClass *klass) { @@ -978,29 +1031,11 @@ const gchar * mc_account_get_normalized_name (McAccount *account) { McAccountPrivate *priv; - GSList *list; - gchar *name; g_return_val_if_fail (account != NULL, NULL); priv = MC_ACCOUNT_PRIV (account); - if (!_mc_account_gconf_get_string (account, - MC_ACCOUNTS_GCONF_KEY_NORMALIZED_NAME, - FALSE, &name)) - return NULL; - - if ((list = g_slist_find_custom(priv->normalized_names, name, - (GCompareFunc)strcmp)) != NULL) - { - g_free (name); - name = list->data; - } - else - { - priv->normalized_names = g_slist_prepend (priv->normalized_names, - name); - } - return name; + return (priv->normalized_names) ? priv->normalized_names->data : NULL; } /** @@ -1076,27 +1111,11 @@ const gchar * mc_account_get_display_name (McAccount *account) { McAccountPrivate *priv; - GSList *list; - gchar *name; g_return_val_if_fail (account != NULL, NULL); priv = MC_ACCOUNT_PRIV (account); - if (!_mc_account_gconf_get_string (account, MC_ACCOUNTS_GCONF_KEY_DISPLAY_NAME, - FALSE, &name)) - return NULL; - - if ((list = g_slist_find_custom(priv->display_names, name, - (GCompareFunc)strcmp)) != NULL) - { - g_free (name); - name = list->data; - } - else - { - priv->display_names = g_slist_prepend (priv->display_names, name); - } - return name; + return (priv->display_names) ? priv->display_names->data : NULL; } /** |