[folks] Take "im-addresses" as the parameter for a new Kf.Persona
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [folks] Take "im-addresses" as the parameter for a new Kf.Persona
- Date: Mon, 9 Aug 2010 17:44:49 +0000 (UTC)
commit aafc38cfcfe923549cedeed9641d939933e03b08
Author: Philip Withnall <philip withnall collabora co uk>
Date: Mon Aug 9 14:47:36 2010 +0100
Take "im-addresses" as the parameter for a new Kf.Persona
This allows construction of new key file personas which contain multiple
IM addresses from different protocols.
backends/key-file/kf-persona-store.vala | 24 +++++++++---------------
backends/key-file/kf-persona.vala | 15 ++++++++++-----
2 files changed, 19 insertions(+), 20 deletions(-)
---
diff --git a/backends/key-file/kf-persona-store.vala b/backends/key-file/kf-persona-store.vala
index 5b046bd..831a186 100644
--- a/backends/key-file/kf-persona-store.vala
+++ b/backends/key-file/kf-persona-store.vala
@@ -177,32 +177,26 @@ public class Folks.Backends.Kf.PersonaStore : Folks.PersonaStore
public override async Folks.Persona? add_persona_from_details (
HashTable<string, Value?> details) throws Folks.PersonaStoreError
{
- Value val = details.lookup ("im-address");
- unowned string im_address = val.get_string ();
- val = details.lookup ("protocol");
- unowned string protocol = val.get_string ();
+ unowned Value val = details.lookup ("im-addresses");
+ unowned HashTable<string, GenericArray<string>> im_addresses =
+ (HashTable<string, GenericArray<string>>) val.get_boxed ();
- if (im_address == null || protocol == null)
+ if (im_addresses == null || im_addresses.size () == 0)
{
throw new PersonaStoreError.INVALID_ARGUMENT (
"persona store (%s, %s) requires the following details:\n" +
- " im-address (provided: '%s')\n",
- " protocol (provided: '%s')\n",
- this.type_id, this.id, im_address, protocol);
+ " im-addresses (provided: '%p')\n",
+ this.type_id, this.id, im_addresses);
}
string persona_id = this.first_unused_id.to_string ();
this.first_unused_id++;
- /* Insert the new IM details into the key file and create a Persona from
- * them */
- string[] im_addresses = new string[1];
- im_addresses[0] = im_address;
- this.key_file.set_string_list (persona_id, protocol, im_addresses);
- yield this.save_key_file ();
-
+ /* Create a new persona and set its im-addresses property to update the
+ * key file */
Persona persona = new Kf.Persona (this.key_file, persona_id, this);
this._personas.insert (persona.iid, persona);
+ persona.im_addresses = im_addresses;
/* FIXME: Groups.ChangeReason is not the right enum to use here */
GLib.List<Persona> personas = new GLib.List<Persona> ();
diff --git a/backends/key-file/kf-persona.vala b/backends/key-file/kf-persona.vala
index df5b935..c3133d5 100644
--- a/backends/key-file/kf-persona.vala
+++ b/backends/key-file/kf-persona.vala
@@ -65,8 +65,10 @@ public class Folks.Backends.Kf.Persona : Folks.Persona,
this._im_addresses.foreach ((k, v) =>
{
unowned string protocol = (string) k;
- unowned string[] addresses = (string[]) v;
- this.key_file.set_string_list (this.uid, protocol, addresses);
+ unowned PtrArray addresses = (PtrArray) v;
+ unowned string[] _addresses = (string[]) addresses.pdata;
+ _addresses.length = (int) addresses.len;
+ this.key_file.set_string_list (this.uid, protocol, _addresses);
});
/* Get the PersonaStore to save the key file */
@@ -118,9 +120,12 @@ public class Folks.Backends.Kf.Persona : Folks.Persona,
}
catch (KeyFileError e)
{
- /* This should never be reached, as we're listing the keys then
- * iterating through the list. */
- GLib.assert_not_reached ();
+ /* We get a GROUP_NOT_FOUND exception if we're creating a new
+ * Persona, since it doesn't yet exist in the key file. We shouldn't
+ * get any other exceptions, since we're iterating through a list of
+ * keys we've just retrieved. */
+ if (!(e is KeyFileError.GROUP_NOT_FOUND))
+ GLib.assert_not_reached ();
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]