summaryrefslogtreecommitdiff
path: root/backends
diff options
context:
space:
mode:
authorPhilip Withnall <philip.withnall@collabora.co.uk>2011-03-24 16:07:55 +0000
committerPhilip Withnall <philip.withnall@collabora.co.uk>2011-04-23 22:00:17 +0100
commitdd378b72c4bc63567b0ed74d4b319008fbb1c6be (patch)
treecfe33c542c1b748e455f5ca0df550a7baec07c6f /backends
parent4bb93d34cc916f98d6b0c8fa66e4ef5188ad551e (diff)
Port PersonaStore.personas_changed to Set<Persona>
Helps: bgo#640092
Diffstat (limited to 'backends')
-rw-r--r--backends/key-file/kf-persona-store.vala24
-rw-r--r--backends/libsocialweb/lib/swf-persona-store.vala29
-rw-r--r--backends/telepathy/lib/tpf-persona-store.vala72
-rw-r--r--backends/tracker/lib/trf-persona-store.vala42
4 files changed, 105 insertions, 62 deletions
diff --git a/backends/key-file/kf-persona-store.vala b/backends/key-file/kf-persona-store.vala
index d1121c9..5ca588e 100644
--- a/backends/key-file/kf-persona-store.vala
+++ b/backends/key-file/kf-persona-store.vala
@@ -33,6 +33,7 @@ using Folks.Backends.Kf;
public class Folks.Backends.Kf.PersonaStore : Folks.PersonaStore
{
private HashTable<string, Persona> _personas;
+ private HashSet<Persona> _persona_set;
private File _file;
private GLib.KeyFile _key_file;
private unowned Cancellable _save_key_file_cancellable = null;
@@ -127,6 +128,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> ();
}
/**
@@ -231,13 +233,15 @@ public class Folks.Backends.Kf.PersonaStore : Folks.PersonaStore
Persona persona = new Kf.Persona (this._key_file, persona_id,
this);
this._personas.insert (persona.iid, persona);
+ this._persona_set.add (persona);
}
if (this._personas.size () > 0)
{
/* FIXME: GroupDetails.ChangeReason is not the right enum to
* use here */
- this.personas_changed (this._personas.get_values (), null,
+ this.personas_changed (this._persona_set,
+ new HashSet<Persona> (),
null, null, GroupDetails.ChangeReason.NONE);
}
@@ -276,9 +280,11 @@ public class Folks.Backends.Kf.PersonaStore : Folks.PersonaStore
yield this.save_key_file ();
/* Signal the removal of the Persona */
- GLib.List<Folks.Persona> personas = new GLib.List<Folks.Persona> ();
- personas.prepend (persona);
- this.personas_changed (null, personas, null, null, 0);
+ var personas = new HashSet<Folks.Persona> ();
+ personas.add (persona);
+
+ this.personas_changed (new HashSet<Persona> (), personas,
+ null, null, 0);
}
catch (KeyFileError e)
{
@@ -343,16 +349,18 @@ public class Folks.Backends.Kf.PersonaStore : Folks.PersonaStore
* key file */
Persona persona = new Kf.Persona (this._key_file, persona_id, this);
this._personas.insert (persona.iid, persona);
+ this._persona_set.add (persona);
if (im_addresses_size > 0)
persona.im_addresses = im_addresses;
if (web_service_addresses_size > 0)
persona.web_service_addresses = web_service_addresses;
/* FIXME: GroupDetails.ChangeReason is not the right enum to use here */
- GLib.List<Persona> personas = new GLib.List<Persona> ();
- personas.prepend (persona);
- this.personas_changed (personas, null, null, null,
- GroupDetails.ChangeReason.NONE);
+ var personas = new HashSet<Persona> ();
+ personas.add (persona);
+
+ this.personas_changed (personas, new HashSet<Persona> (),
+ null, null, GroupDetails.ChangeReason.NONE);
return persona;
}
diff --git a/backends/libsocialweb/lib/swf-persona-store.vala b/backends/libsocialweb/lib/swf-persona-store.vala
index 0effd7a..8505ccd 100644
--- a/backends/libsocialweb/lib/swf-persona-store.vala
+++ b/backends/libsocialweb/lib/swf-persona-store.vala
@@ -21,6 +21,7 @@
*/
using GLib;
+using Gee;
using Folks;
using SocialWebClient;
@@ -211,21 +212,24 @@ public class Swf.PersonaStore : Folks.PersonaStore
}
}
- private void contacts_added_cb (List<unowned Contact> contacts)
+ private void contacts_added_cb (GLib.List<unowned Contact> contacts)
{
- var added_personas = new Queue<Persona> ();
+ var added_personas = new HashSet<Persona> ();
foreach (var contact in contacts)
{
var persona = new Persona(this, contact);
_personas.insert(persona.iid, persona);
- added_personas.push_tail(persona);
+ added_personas.add (persona);
}
- if (added_personas.length > 0)
- this.personas_changed (added_personas.head, null, null, null, 0);
+ if (added_personas.size > 0)
+ {
+ this.personas_changed (added_personas, new HashSet<Persona> (),
+ null, null, 0);
+ }
}
- private void contacts_changed_cb (List<unowned Contact> contacts)
+ private void contacts_changed_cb (GLib.List<unowned Contact> contacts)
{
foreach (var contact in contacts)
{
@@ -240,9 +244,9 @@ public class Swf.PersonaStore : Folks.PersonaStore
}
}
- private void contacts_removed_cb (List<unowned Contact> contacts)
+ private void contacts_removed_cb (GLib.List<unowned Contact> contacts)
{
- var removed_personas = new Queue<Persona> ();
+ var removed_personas = new HashSet<Persona> ();
foreach (var contact in contacts)
{
if (this._service.get_name () != contact.service)
@@ -253,12 +257,15 @@ public class Swf.PersonaStore : Folks.PersonaStore
var persona = _personas.lookup(iid);
if (persona != null)
{
- removed_personas.push_tail(persona);
+ removed_personas.add (persona);
_personas.remove(persona.iid);
}
}
- if (removed_personas.length > 0)
- this.personas_changed (null, removed_personas.head, null, null, 0);
+ if (removed_personas.size > 0)
+ {
+ this.personas_changed (new HashSet<Persona> (), removed_personas,
+ null, null, 0);
+ }
}
}
diff --git a/backends/telepathy/lib/tpf-persona-store.vala b/backends/telepathy/lib/tpf-persona-store.vala
index c174b44..9a4685e 100644
--- a/backends/telepathy/lib/tpf-persona-store.vala
+++ b/backends/telepathy/lib/tpf-persona-store.vala
@@ -61,6 +61,7 @@ public class Tpf.PersonaStore : Folks.PersonaStore
};
private HashTable<string, Persona> _personas;
+ private HashSet<Persona> _persona_set;
/* universal, contact owner handles (not channel-specific) */
private HashMap<uint, Persona> _handle_persona_map;
private HashMap<Channel, HashSet<Persona>> _channel_group_personas_map;
@@ -203,6 +204,7 @@ public class Tpf.PersonaStore : Folks.PersonaStore
this._personas = new HashTable<string, Persona> (str_hash,
str_equal);
+ this._persona_set = new HashSet<Persona> ();
this._conn = null;
this._handle_persona_map = new HashMap<uint, Persona> ();
this._channel_group_personas_map =
@@ -265,8 +267,8 @@ public class Tpf.PersonaStore : Folks.PersonaStore
{
if (this.account == a)
{
- this.personas_changed (null, this._personas.get_values (),
- null, null, 0);
+ this.personas_changed (new HashSet<Persona> (),
+ this._persona_set, null, null, 0);
this.removed ();
}
});
@@ -274,8 +276,8 @@ public class Tpf.PersonaStore : Folks.PersonaStore
{
if (this.account == a)
{
- this.personas_changed (null, this._personas.get_values (),
- null, null, 0);
+ this.personas_changed (new HashSet<Persona> (),
+ this._persona_set, null, null, 0);
this.removed ();
}
});
@@ -284,8 +286,8 @@ public class Tpf.PersonaStore : Folks.PersonaStore
{
if (!valid && this.account == a)
{
- this.personas_changed (null, this._personas.get_values
- (), null, null, 0);
+ this.personas_changed (new HashSet<Persona> (),
+ this._persona_set, null, null, 0);
this.removed ();
}
});
@@ -479,8 +481,8 @@ public class Tpf.PersonaStore : Folks.PersonaStore
/* When disconnecting, we want the PersonaStore to remain alive, but
* all its Personas to be removed. We do *not* want the PersonaStore
* to be destroyed, as that makes coming back online hard. */
- this.personas_changed (null, this._personas.get_values (), null, null,
- 0);
+ this.personas_changed (new HashSet<Persona> (),
+ this._persona_set, null, null, 0);
this._reset ();
return;
}
@@ -638,11 +640,12 @@ public class Tpf.PersonaStore : Folks.PersonaStore
Contact contact = contacts[0];
Persona persona = this._add_persona_from_contact (contact, false);
- GLib.List<Persona> personas = new GLib.List<Persona> ();
- personas.prepend (persona);
+ var personas = new HashSet<Persona> ();
+ personas.add (persona);
this._self_contact = contact;
- this.personas_changed (personas, null, null, null, 0);
+ this.personas_changed (personas, new HashSet<Persona> (),
+ null, null, 0);
},
this);
}
@@ -984,10 +987,13 @@ public class Tpf.PersonaStore : Folks.PersonaStore
members.remove (persona);
}
- var personas = new GLib.List<Persona> ();
- personas.append (persona);
- this.personas_changed (null, personas, message, actor, reason);
+ var personas = new HashSet<Persona> ();
+ personas.add (persona);
+
+ this.personas_changed (new HashSet<Persona> (), personas,
+ message, actor, reason);
this._personas.remove (persona.iid);
+ this._persona_set.remove (persona);
}
/**
@@ -1309,7 +1315,7 @@ public class Tpf.PersonaStore : Folks.PersonaStore
}
}
- private async GLib.List<Tpf.Persona>? _create_personas_from_contact_ids (
+ private async HashSet<Persona>? _create_personas_from_contact_ids (
string[] contact_ids) throws GLib.Error
{
if (contact_ids.length > 0)
@@ -1318,7 +1324,7 @@ public class Tpf.PersonaStore : Folks.PersonaStore
yield this._ll.connection_get_contacts_by_id_async (
this._conn, contact_ids, (uint[]) _contact_features);
- GLib.List<Persona> personas = new GLib.List<Persona> ();
+ var personas = new HashSet<Persona> ();
var err_count = 0;
var err_string = "";
unowned GLib.List<TelepathyGLib.Contact> l;
@@ -1330,7 +1336,7 @@ public class Tpf.PersonaStore : Folks.PersonaStore
var persona = this._add_persona_from_contact (contact, true);
if (persona != null)
- personas.prepend (persona);
+ personas.add (persona);
}
if (err_count > 0)
@@ -1345,8 +1351,11 @@ public class Tpf.PersonaStore : Folks.PersonaStore
err_count, err_string);
}
- if (personas != null)
- this.personas_changed (personas, null, null, null, 0);
+ if (personas.size > 0)
+ {
+ this.personas_changed (personas, new HashSet<Persona> (),
+ null, null, 0);
+ }
return personas;
}
@@ -1368,6 +1377,7 @@ public class Tpf.PersonaStore : Folks.PersonaStore
persona = new Tpf.Persona (contact, this);
this._personas.insert (persona.iid, persona);
+ this._persona_set.add (persona);
this._handle_persona_map[h] = persona;
/* If the handle is a favourite, ensure the persona's marked
@@ -1409,18 +1419,22 @@ public class Tpf.PersonaStore : Folks.PersonaStore
private void _add_new_personas_from_contacts (Contact[] contacts)
{
- GLib.List<Persona> personas = new GLib.List<Persona> ();
+ var personas = new HashSet<Persona> ();
+
foreach (Contact contact in contacts)
{
var persona = this._add_persona_from_contact (contact, true);
if (persona != null)
- personas.prepend (persona);
+ personas.add (persona);
}
this._channel_groups_add_new_personas ();
- if (personas != null)
- this.personas_changed (personas, null, null, null, 0);
+ if (personas.size > 0)
+ {
+ this.personas_changed (personas, new HashSet<Persona> (),
+ null, null, 0);
+ }
}
private void _channel_groups_add_new_personas ()
@@ -1525,9 +1539,15 @@ public class Tpf.PersonaStore : Folks.PersonaStore
/* the persona already existed */
return null;
}
- else if (personas.length () == 1)
+ else if (personas.size == 1)
{
- var persona = personas.data;
+ /* Get the first (and only) Persona */
+ Persona persona = null;
+ foreach (var p in personas)
+ {
+ persona = p;
+ break;
+ }
if (this._subscribe != null)
this._change_standard_contact_list_membership (this._subscribe,
@@ -1550,7 +1570,7 @@ public class Tpf.PersonaStore : Folks.PersonaStore
{
/* We ignore the case of an empty list, as it just means the
* contact was already in our roster */
- var num_personas = personas.length ();
+ var num_personas = personas.size;
var message =
ngettext (
/* Translators: the parameter is the number of personas
diff --git a/backends/tracker/lib/trf-persona-store.vala b/backends/tracker/lib/trf-persona-store.vala
index 7cff6c2..9e8ffed 100644
--- a/backends/tracker/lib/trf-persona-store.vala
+++ b/backends/tracker/lib/trf-persona-store.vala
@@ -691,9 +691,14 @@ public class Trf.PersonaStore : Folks.PersonaStore
{
string filter = " FILTER(?_contact = <%s>) ".printf (contact_urn);
string query = this._INITIAL_QUERY.printf (filter);
- GLib.Queue<Persona> ret_personas;
- ret_personas = yield this._do_add_contacts (query);
- ret = ret_personas.pop_head ();
+ var ret_personas = yield this._do_add_contacts (query);
+
+ /* Return the first persona we find in the set */
+ foreach (var p in ret_personas)
+ {
+ ret = p;
+ break;
+ }
}
else
{
@@ -1195,7 +1200,7 @@ public class Trf.PersonaStore : Folks.PersonaStore
private async void _handle_delete_events (owned VariantIter iter_del)
{
- var removed_personas = new GLib.Queue<Persona> ();
+ var removed_personas = new HashSet<Persona> ();
var nco_person_id =
this._prefix_tracker_id.get (Trf.OntologyDefs.NCO_PERSON);
var rdf_type_id = this._prefix_tracker_id.get (Trf.OntologyDefs.RDF_TYPE);
@@ -1213,7 +1218,7 @@ public class Trf.PersonaStore : Folks.PersonaStore
var removed_p = this._personas.lookup (p_id);
if (removed_p != null)
{
- removed_personas.push_tail (removed_p);
+ removed_personas.add (removed_p);
_personas.remove (removed_p.iid);
}
}
@@ -1228,15 +1233,16 @@ public class Trf.PersonaStore : Folks.PersonaStore
}
}
- if (removed_personas.length > 0)
+ if (removed_personas.size > 0)
{
- this.personas_changed (null, removed_personas.head, null, null, 0);
+ this.personas_changed (new HashSet<Persona> (), removed_personas,
+ null, null, 0);
}
}
private async void _handle_insert_events (owned VariantIter iter_ins)
{
- var added_personas = new GLib.Queue<Persona> ();
+ var added_personas = new HashSet<Persona> ();
Event e = Event ();
while (iter_ins.next
@@ -1252,23 +1258,24 @@ public class Trf.PersonaStore : Folks.PersonaStore
{
persona = new Trf.Persona (this, subject_tracker_id);
this._personas.insert (persona.iid, persona);
- added_personas.push_tail (persona);
+ added_personas.add (persona);
}
}
yield this._do_update (persona, e);
}
- if (added_personas.length > 0)
+ if (added_personas.size > 0)
{
- this.personas_changed (added_personas.head, null, null, null, 0);
+ this.personas_changed (added_personas, new HashSet<Persona> (),
+ null, null, 0);
}
}
- private async GLib.Queue<Persona> _do_add_contacts (string query)
+ private async HashSet<Persona> _do_add_contacts (string query)
{
- var added_personas = new GLib.Queue<Persona> ();
+ var added_personas = new HashSet<Persona> ();
- try {
+ try {
Sparql.Cursor cursor = yield this._connection.query_async (query);
while (cursor.next ())
@@ -1280,13 +1287,14 @@ public class Trf.PersonaStore : Folks.PersonaStore
var persona = new Trf.Persona (this,
tracker_id.to_string (), cursor);
this._personas.insert (persona.iid, persona);
- added_personas.push_tail (persona);
+ added_personas.add (persona);
}
}
- if (added_personas.length > 0)
+ if (added_personas.size > 0)
{
- this.personas_changed (added_personas.head, null, null, null, 0);
+ this.personas_changed (added_personas,
+ new HashSet<Persona> (), null, null, 0);
}
} catch (GLib.Error e) {
warning ("Couldn't perform queries: %s %s", query, e.message);