diff options
author | Philip Withnall <philip.withnall@collabora.co.uk> | 2011-04-19 20:29:12 +0100 |
---|---|---|
committer | Philip Withnall <philip.withnall@collabora.co.uk> | 2011-04-23 21:59:50 +0100 |
commit | 754541d94a53004aa38dfb163f49f9e258930ca5 (patch) | |
tree | c7f4bc82b2bbcef42a111931f99dd7ad4bc5a7cf /folks | |
parent | beef9692895520e335770e0035bbec85240a61b1 (diff) |
Change GroupDetails.groups to be a Set<string>
Helps: bgo#640092
Diffstat (limited to 'folks')
-rw-r--r-- | folks/group-details.vala | 5 | ||||
-rw-r--r-- | folks/individual.vala | 37 |
2 files changed, 21 insertions, 21 deletions
diff --git a/folks/group-details.vala b/folks/group-details.vala index 8244dc4..7fc167c 100644 --- a/folks/group-details.vala +++ b/folks/group-details.vala @@ -19,6 +19,7 @@ */ using GLib; +using Gee; /** * Interface for {@link Persona}s or {@link Individual}s which can be grouped @@ -117,8 +118,10 @@ public interface Folks.GroupDetails : Object * * Freeform group IDs are mapped to a boolean which is `true` if the * contact is a member of the group, and `false` otherwise. + * + * @since UNRELEASED */ - public abstract HashTable<string, bool> groups { get; set; } + public abstract Set<string> groups { get; set; } /** * Add or remove the contact from the specified group. diff --git a/folks/individual.vala b/folks/individual.vala index 2281a54..5e67770 100644 --- a/folks/individual.vala +++ b/folks/individual.vala @@ -83,7 +83,7 @@ public class Folks.Individual : Object, { private bool _is_favourite; private string _alias; - private HashTable<string, bool> _groups; + private HashSet<string> _groups; /* These two data structures should store exactly the same set of Personas: * the Personas contained in this Individual. The HashSet is used for fast * lookups, whereas the List is used for iteration. @@ -402,18 +402,18 @@ public class Folks.Individual : Object, /** * {@inheritDoc} */ - public HashTable<string, bool> groups + public Set<string> groups { get { return this._groups; } set { - this._groups = value; this._persona_list.foreach ((p) => { if (p is GroupDetails && ((Persona) p).store.is_writeable == true) ((GroupDetails) p).groups = value; }); + this._update_groups (); } } @@ -691,11 +691,11 @@ public class Folks.Individual : Object, private void _update_groups () { - var new_groups = new HashTable<string, bool> (str_hash, str_equal); + var new_groups = new HashSet<string> (); /* this._groups is null during initial construction */ if (this._groups == null) - this._groups = new HashTable<string, bool> (str_hash, str_equal); + this._groups = new HashSet<string> (); /* FIXME: this should partition the personas by store (maybe we should * keep that mapping in general in this class), and execute @@ -708,37 +708,34 @@ public class Folks.Individual : Object, { var persona = (GroupDetails) p; - persona.groups.foreach ((k, v) => + foreach (var group in persona.groups) { - new_groups.insert ((string) k, true); - }); + new_groups.add (group); + } } }); - new_groups.foreach ((k, v) => + foreach (var group in new_groups) { - unowned string group = (string) k; - if (this._groups.lookup (group) != true) + if (!this._groups.contains (group)) { - this._groups.insert (group, true); - this._groups.foreach ((k, v) => + this._groups.add (group); + foreach (var g in this._groups) { - unowned string g = (string) k; debug (" %s", g); - }); + } this.group_changed (group, true); } - }); + } /* buffer the removals, so we don't remove while iterating */ var removes = new GLib.List<string> (); - this._groups.foreach ((k, v) => + foreach (var group in this._groups) { - unowned string group = (string) k; - if (new_groups.lookup (group) != true) + if (!new_groups.contains (group)) removes.prepend (group); - }); + } removes.foreach ((l) => { |