summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Withnall <philip.withnall@collabora.co.uk>2011-04-20 01:31:54 +0100
committerPhilip Withnall <philip.withnall@collabora.co.uk>2011-04-23 22:00:38 +0100
commit37a01ab4fdc9e0ac85b850824212a1ed44e8d27e (patch)
treeaba00187241312ec6ba4c73d42c9bd4d6e373b81
parent03bfb40e46b9c804700c57e0a6a6faf6aa503cda (diff)
Change PersonaStore.personas to be a Map<string, Persona>
This helps in our quest to get rid of HashTable. Helps: bgo#640092
-rw-r--r--NEWS1
-rw-r--r--backends/key-file/kf-persona-store.vala20
-rw-r--r--backends/libsocialweb/lib/swf-persona-store.vala14
-rw-r--r--backends/telepathy/lib/tpf-persona-store.vala11
-rw-r--r--backends/tracker/lib/trf-persona-store.vala20
-rw-r--r--folks/persona-store.vala4
-rw-r--r--tests/tracker/remove-persona.vala4
-rw-r--r--tools/inspect/utils.vala14
8 files changed, 44 insertions, 44 deletions
diff --git a/NEWS b/NEWS
index dccbbbf..3387867 100644
--- a/NEWS
+++ b/NEWS
@@ -40,6 +40,7 @@ API changes:
* IndividualAggregator.get_potential_matches() now returns a
Map<Individual, MatchResult>
* IndividualAggregator.individuals now has type Map<string, Individual>
+* PersonaStore.personas now has type Map<string, Persona>
Overview of changes from libfolks 0.4.0 to libfolks 0.5.0
=========================================================
diff --git a/backends/key-file/kf-persona-store.vala b/backends/key-file/kf-persona-store.vala
index 5ca588e..f5fee5b 100644
--- a/backends/key-file/kf-persona-store.vala
+++ b/backends/key-file/kf-persona-store.vala
@@ -32,8 +32,7 @@ using Folks.Backends.Kf;
*/
public class Folks.Backends.Kf.PersonaStore : Folks.PersonaStore
{
- private HashTable<string, Persona> _personas;
- private HashSet<Persona> _persona_set;
+ private HashMap<string, Persona> _personas;
private File _file;
private GLib.KeyFile _key_file;
private unowned Cancellable _save_key_file_cancellable = null;
@@ -107,7 +106,7 @@ public class Folks.Backends.Kf.PersonaStore : Folks.PersonaStore
/**
* {@inheritDoc}
*/
- public override HashTable<string, Persona> personas
+ public override Map<string, Persona> personas
{
get { return this._personas; }
}
@@ -127,8 +126,7 @@ public class Folks.Backends.Kf.PersonaStore : Folks.PersonaStore
this.trust_level = PersonaStoreTrust.FULL;
this._file = key_file;
- this._personas = new HashTable<string, Persona> (str_hash, str_equal);
- this._persona_set = new HashSet<Persona> ();
+ this._personas = new HashMap<string, Persona> ();
}
/**
@@ -228,19 +226,20 @@ public class Folks.Backends.Kf.PersonaStore : Folks.PersonaStore
* groups: each group is a persona which we have to create and
* emit */
var groups = this._key_file.get_groups ();
+ var added_personas = new HashSet<Persona> ();
foreach (var persona_id in groups)
{
Persona persona = new Kf.Persona (this._key_file, persona_id,
this);
- this._personas.insert (persona.iid, persona);
- this._persona_set.add (persona);
+ this._personas.set (persona.iid, persona);
+ added_personas.add (persona);
}
- if (this._personas.size () > 0)
+ if (this._personas.size > 0)
{
/* FIXME: GroupDetails.ChangeReason is not the right enum to
* use here */
- this.personas_changed (this._persona_set,
+ this.personas_changed (added_personas,
new HashSet<Persona> (),
null, null, GroupDetails.ChangeReason.NONE);
}
@@ -348,8 +347,7 @@ public class Folks.Backends.Kf.PersonaStore : Folks.PersonaStore
/* Create a new persona and set its addresses property to update the
* key file */
Persona persona = new Kf.Persona (this._key_file, persona_id, this);
- this._personas.insert (persona.iid, persona);
- this._persona_set.add (persona);
+ this._personas.set (persona.iid, persona);
if (im_addresses_size > 0)
persona.im_addresses = im_addresses;
if (web_service_addresses_size > 0)
diff --git a/backends/libsocialweb/lib/swf-persona-store.vala b/backends/libsocialweb/lib/swf-persona-store.vala
index 8505ccd..825b337 100644
--- a/backends/libsocialweb/lib/swf-persona-store.vala
+++ b/backends/libsocialweb/lib/swf-persona-store.vala
@@ -34,7 +34,7 @@ extern const string BACKEND_NAME;
*/
public class Swf.PersonaStore : Folks.PersonaStore
{
- private HashTable<string, Persona> _personas;
+ private HashMap<string, Persona> _personas;
private bool _is_prepared = false;
private ClientService _service;
private ClientContactView _contact_view;
@@ -111,7 +111,7 @@ public class Swf.PersonaStore : Folks.PersonaStore
*
* See {@link Folks.PersonaStore.personas}.
*/
- public override HashTable<string, Persona> personas
+ public override Map<string, Persona> personas
{
get { return this._personas; }
}
@@ -129,7 +129,7 @@ public class Swf.PersonaStore : Folks.PersonaStore
this.trust_level = PersonaStoreTrust.PARTIAL;
this._service = service;
- this._personas = new HashTable<string, Persona> (str_hash, str_equal);
+ this._personas = new HashMap<string, Persona> ();
}
~PersonaStore ()
@@ -218,7 +218,7 @@ public class Swf.PersonaStore : Folks.PersonaStore
foreach (var contact in contacts)
{
var persona = new Persona(this, contact);
- _personas.insert(persona.iid, persona);
+ _personas.set (persona.iid, persona);
added_personas.add (persona);
}
@@ -238,7 +238,7 @@ public class Swf.PersonaStore : Folks.PersonaStore
continue;
}
var iid = Swf.Persona._build_iid(contact.service, Persona.get_contact_id (contact));
- var persona = _personas.lookup(iid);
+ var persona = _personas.get (iid);
if (persona != null)
persona.update (contact);
}
@@ -254,11 +254,11 @@ public class Swf.PersonaStore : Folks.PersonaStore
continue;
}
var iid = Swf.Persona._build_iid(contact.service, Persona.get_contact_id (contact));
- var persona = _personas.lookup(iid);
+ var persona = _personas.get (iid);
if (persona != null)
{
removed_personas.add (persona);
- _personas.remove(persona.iid);
+ _personas.unset (persona.iid);
}
}
diff --git a/backends/telepathy/lib/tpf-persona-store.vala b/backends/telepathy/lib/tpf-persona-store.vala
index c9dab7a..9be0694 100644
--- a/backends/telepathy/lib/tpf-persona-store.vala
+++ b/backends/telepathy/lib/tpf-persona-store.vala
@@ -60,7 +60,7 @@ public class Tpf.PersonaStore : Folks.PersonaStore
ContactFeature.PRESENCE
};
- private HashTable<string, Persona> _personas;
+ private HashMap<string, Persona> _personas;
private HashSet<Persona> _persona_set;
/* universal, contact owner handles (not channel-specific) */
private HashMap<uint, Persona> _handle_persona_map;
@@ -170,7 +170,7 @@ public class Tpf.PersonaStore : Folks.PersonaStore
*
* See {@link Folks.PersonaStore.personas}.
*/
- public override HashTable<string, Persona> personas
+ public override Map<string, Persona> personas
{
get { return this._personas; }
}
@@ -202,8 +202,7 @@ public class Tpf.PersonaStore : Folks.PersonaStore
else
this.trust_level = PersonaStoreTrust.PARTIAL;
- this._personas = new HashTable<string, Persona> (str_hash,
- str_equal);
+ this._personas = new HashMap<string, Persona> ();
this._persona_set = new HashSet<Persona> ();
this._conn = null;
this._handle_persona_map = new HashMap<uint, Persona> ();
@@ -992,7 +991,7 @@ public class Tpf.PersonaStore : Folks.PersonaStore
this.personas_changed (new HashSet<Persona> (), personas,
message, actor, reason);
- this._personas.remove (persona.iid);
+ this._personas.unset (persona.iid);
this._persona_set.remove (persona);
}
@@ -1361,7 +1360,7 @@ public class Tpf.PersonaStore : Folks.PersonaStore
{
persona = new Tpf.Persona (contact, this);
- this._personas.insert (persona.iid, persona);
+ this._personas.set (persona.iid, persona);
this._persona_set.add (persona);
this._handle_persona_map[h] = persona;
diff --git a/backends/tracker/lib/trf-persona-store.vala b/backends/tracker/lib/trf-persona-store.vala
index 9e8ffed..d20f445 100644
--- a/backends/tracker/lib/trf-persona-store.vala
+++ b/backends/tracker/lib/trf-persona-store.vala
@@ -161,7 +161,7 @@ public class Trf.PersonaStore : Folks.PersonaStore
private const string _OBJECT_NAME = "org.freedesktop.Tracker1";
private const string _OBJECT_IFACE = "org.freedesktop.Tracker1.Resources";
private const string _OBJECT_PATH = "/org/freedesktop/Tracker1/Resources";
- private HashTable<string, Persona> _personas;
+ private HashMap<string, Persona> _personas;
private bool _is_prepared = false;
private static const int _default_timeout = 100;
private Resources _resources_object;
@@ -356,7 +356,7 @@ public class Trf.PersonaStore : Folks.PersonaStore
*
* See {@link Folks.PersonaStore.personas}.
*/
- public override HashTable<string, Persona> personas
+ public override Map<string, Persona> personas
{
get { return this._personas; }
}
@@ -369,7 +369,7 @@ public class Trf.PersonaStore : Folks.PersonaStore
public PersonaStore ()
{
Object (id: BACKEND_NAME, display_name: BACKEND_NAME);
- this._personas = new HashTable<string, Persona> (str_hash, str_equal);
+ this._personas = new HashMap<string, Persona> ();
debug ("Initial query : \n%s\n", this._INITIAL_QUERY);
}
@@ -1215,17 +1215,17 @@ public class Trf.PersonaStore : Folks.PersonaStore
{
lock (this._personas)
{
- var removed_p = this._personas.lookup (p_id);
+ var removed_p = this._personas.get (p_id);
if (removed_p != null)
{
removed_personas.add (removed_p);
- _personas.remove (removed_p.iid);
+ _personas.unset (removed_p.iid);
}
}
}
else
{
- var persona = this._personas.lookup (p_id);
+ var persona = this._personas.get (p_id);
if (persona != null)
{
yield this._do_update (persona, e, false);
@@ -1253,11 +1253,11 @@ public class Trf.PersonaStore : Folks.PersonaStore
Trf.Persona persona;
lock (this._personas)
{
- persona = this._personas.lookup (p_id);
+ persona = this._personas.get (p_id);
if (persona == null)
{
persona = new Trf.Persona (this, subject_tracker_id);
- this._personas.insert (persona.iid, persona);
+ this._personas.set (persona.iid, persona);
added_personas.add (persona);
}
}
@@ -1282,11 +1282,11 @@ public class Trf.PersonaStore : Folks.PersonaStore
{
int tracker_id = (int) cursor.get_integer (Trf.Fields.TRACKER_ID);
var p_id = Trf.Persona.build_iid (this.id, tracker_id.to_string ());
- if (this._personas.lookup (p_id) == null)
+ if (this._personas.get (p_id) == null)
{
var persona = new Trf.Persona (this,
tracker_id.to_string (), cursor);
- this._personas.insert (persona.iid, persona);
+ this._personas.set (persona.iid, persona);
added_personas.add (persona);
}
}
diff --git a/folks/persona-store.vala b/folks/persona-store.vala
index 1d15980..9b26b07 100644
--- a/folks/persona-store.vala
+++ b/folks/persona-store.vala
@@ -253,8 +253,10 @@ public abstract class Folks.PersonaStore : Object
/**
* The {@link Persona}s exposed by this PersonaStore.
+ *
+ * @since UNRELEASED
*/
- public abstract HashTable<string, Persona> personas { get; }
+ public abstract Map<string, Persona> personas { get; }
/**
* Whether this {@link PersonaStore} can add {@link Persona}s.
diff --git a/tests/tracker/remove-persona.vala b/tests/tracker/remove-persona.vala
index 5bc7770..b38b1f1 100644
--- a/tests/tracker/remove-persona.vala
+++ b/tests/tracker/remove-persona.vala
@@ -175,7 +175,7 @@ public class RemovePersonaTests : Folks.TestCase
}
this._individual = i;
- if (this._pstore.personas.lookup (this._persona_id) != null)
+ if (this._pstore.personas.has_key (this._persona_id) == true)
{
this._pstore.personas_changed.connect (this._personas_cb);
this._aggregator.remove_individual (this._individual);
@@ -194,7 +194,7 @@ public class RemovePersonaTests : Folks.TestCase
private void _personas_cb ()
{
- if (this._pstore.personas.lookup (this._persona_id) == null)
+ if (this._pstore.personas.has_key (this._persona_id) == false)
{
this._persona_removed = true;
this._main_loop.quit ();
diff --git a/tools/inspect/utils.vala b/tools/inspect/utils.vala
index e5928fc..0b36547 100644
--- a/tools/inspect/utils.vala
+++ b/tools/inspect/utils.vala
@@ -174,7 +174,7 @@ private class Folks.Inspect.Utils
bool show_personas)
{
Utils.print_line ("Persona store '%s' with %u personas:",
- store.id, store.personas.size ());
+ store.id, store.personas.size);
/* List the store's properties */
unowned ParamSpec[] properties =
@@ -205,10 +205,10 @@ private class Folks.Inspect.Utils
Utils.print_line ("Personas:");
Utils.indent ();
- store.personas.foreach ((k, v) =>
+ foreach (var persona in store.personas.values)
{
- Utils.print_persona ((Persona) v);
- });
+ Utils.print_persona (persona);
+ }
Utils.unindent ();
}
Utils.unindent ();
@@ -229,9 +229,9 @@ private class Folks.Inspect.Utils
else if (object_type.is_a (typeof (PersonaStore)) &&
prop_name == "personas")
{
- unowned HashTable<string, Persona> personas =
- (HashTable<string, Persona>) prop_value.get_boxed ();
- return "Set of %u personas".printf (personas.size ());
+ Map<string, Persona> personas =
+ (Map<string, Persona>) prop_value.get_object ();
+ return "Set of %u personas".printf (personas.size);
}
else if (prop_name == "groups")
{