diff options
author | Danielle Madeley <danielle.madeley@collabora.co.uk> | 2010-07-16 16:44:15 +1000 |
---|---|---|
committer | Danielle Madeley <danielle.madeley@collabora.co.uk> | 2010-07-19 13:51:56 +0100 |
commit | f0d5ae23e52e45a5eb2a20d95135309065d9238d (patch) | |
tree | 6df6c51b9378162e92fcc1ab61d5a8305e50936e | |
parent | 30b0ce878d6cb3837b9cd207eb98f873ed553dbf (diff) | |
download | telepathy-logger-f0d5ae23e52e45a5eb2a20d95135309065d9238d.tar.gz |
Add a TplConf::ignore-accounts-changed signal
-rw-r--r-- | telepathy-logger/conf.c | 112 |
1 files changed, 82 insertions, 30 deletions
diff --git a/telepathy-logger/conf.c b/telepathy-logger/conf.c index db3f4c2..86ccda4 100644 --- a/telepathy-logger/conf.c +++ b/telepathy-logger/conf.c @@ -22,6 +22,7 @@ #include "config.h" #include "conf-internal.h" +#include "tpl-marshal.h" #include <glib.h> #include <gio/gio.h> @@ -41,12 +42,71 @@ G_DEFINE_TYPE (TplConf, _tpl_conf, G_TYPE_OBJECT) static TplConf *conf_singleton = NULL; +enum /* signals */ +{ + IGNORE_ACCOUNTS_CHANGED, + LAST_SIGNAL +}; + +static guint _signals[LAST_SIGNAL] = { 0, }; + typedef struct { GSettings *gsettings; + + GHashTable *ignore_accounts; /* char * -> NULL */ } TplConfPriv; static void +_ignore_accounts_changed (GSettings *gsettings, + gchar *key, + TplConf *self) +{ + TplConfPriv *priv = GET_PRIV (self); + GVariant *v, *child; + GVariantIter iter; + GList *added = NULL, *removed; + GHashTable *new_ignore_accounts, *old_ignore_accounts; + + new_ignore_accounts = g_hash_table_new_full (g_str_hash, g_str_equal, + g_free, NULL); + + /* walk the new ignore list, work out what's been added */ + v = g_settings_get_value (priv->gsettings, KEY_IGNORE_ACCOUNTS); + g_variant_iter_init (&iter, v); + while ((child = g_variant_iter_next_value (&iter))) + { + const gchar *o = g_variant_get_string (child, NULL); + + if (!g_hash_table_remove (priv->ignore_accounts, o)) + { + /* account is not in list */ + added = g_list_prepend (added, (gpointer) o); + } + + g_hash_table_insert (new_ignore_accounts, g_strdup (o), + GUINT_TO_POINTER (TRUE)); + + g_variant_unref (child); + } + + /* get the remaining keys */ + removed = g_hash_table_get_keys (priv->ignore_accounts); + + /* swap priv->ignore_accounts over before emitting the signal */ + old_ignore_accounts = priv->ignore_accounts; + priv->ignore_accounts = new_ignore_accounts; + + g_signal_emit (self, _signals[IGNORE_ACCOUNTS_CHANGED], 0, added, removed); + + g_variant_unref (v); + g_list_free (added); + g_list_free (removed); + g_hash_table_destroy (old_ignore_accounts); +} + + +static void tpl_conf_finalize (GObject *obj) { TplConfPriv *priv; @@ -63,15 +123,6 @@ tpl_conf_finalize (GObject *obj) } -static void -tpl_conf_dispose (GObject *obj) -{ - /* TplConf *self = TPL_CONF (obj); */ - - G_OBJECT_CLASS (_tpl_conf_parent_class)->dispose (obj); -} - - static GObject * tpl_conf_constructor (GType type, guint n_props, @@ -79,8 +130,10 @@ tpl_conf_constructor (GType type, { GObject *retval; - if (conf_singleton) - retval = g_object_ref (conf_singleton); + if (conf_singleton != NULL) + { + retval = g_object_ref (conf_singleton); + } else { retval = G_OBJECT_CLASS (_tpl_conf_parent_class)->constructor (type, @@ -88,6 +141,7 @@ tpl_conf_constructor (GType type, conf_singleton = TPL_CONF (retval); g_object_add_weak_pointer (retval, (gpointer *) &conf_singleton); } + return retval; } @@ -98,9 +152,17 @@ _tpl_conf_class_init (TplConfClass *klass) GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->finalize = tpl_conf_finalize; - object_class->dispose = tpl_conf_dispose; object_class->constructor = tpl_conf_constructor; + _signals[IGNORE_ACCOUNTS_CHANGED] = g_signal_new ("ignore-accounts-changed", + G_OBJECT_CLASS_TYPE (klass), + G_SIGNAL_RUN_LAST, + 0, + NULL, NULL, + tpl_marshal_VOID__POINTER_POINTER, + G_TYPE_NONE, + 2, G_TYPE_POINTER, G_TYPE_POINTER); + g_type_class_add_private (object_class, sizeof (TplConfPriv)); } @@ -112,6 +174,12 @@ _tpl_conf_init (TplConf *self) TPL_TYPE_CONF, TplConfPriv); priv->gsettings = g_settings_new (GSETTINGS_SCHEMA); + + priv->ignore_accounts = g_hash_table_new_full (g_str_hash, g_str_equal, + g_free, NULL); + + g_signal_connect (priv->gsettings, "changed::" KEY_IGNORE_ACCOUNTS, + G_CALLBACK (_ignore_accounts_changed), self); } @@ -232,25 +300,9 @@ gboolean _tpl_conf_is_account_ignored (TplConf *self, const gchar *account_path) { - GVariant *v, *child; - GVariantIter iter; - gboolean found = FALSE; - g_return_val_if_fail (TPL_IS_CONF (self), FALSE); g_return_val_if_fail (!TPL_STR_EMPTY (account_path), FALSE); - v = g_settings_get_value (GET_PRIV (self)->gsettings, KEY_IGNORE_ACCOUNTS); - g_variant_iter_init (&iter, v); - while (!found && (child = g_variant_iter_next_value (&iter))) - { - const gchar *o = g_variant_get_string (child, NULL); - - found = !tp_strdiff (o, account_path); - - g_variant_unref (child); - } - - g_variant_unref (v); - - return found; + return g_hash_table_lookup (GET_PRIV (self)->ignore_accounts, account_path) + != NULL; } |