[folks] Support vCard-like parameters for Roles
- From: Travis Reitter <treitter src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [folks] Support vCard-like parameters for Roles
- Date: Fri, 12 Aug 2011 15:58:06 +0000 (UTC)
commit b3c63593fde17fbed7e5b57432e755123bc3a59b
Author: Travis Reitter <travis reitter collabora co uk>
Date: Thu Aug 11 13:23:01 2011 +0200
Support vCard-like parameters for Roles
Closes: bug#655921 - Change RoleDetails.roles to support vCard-like arbitrary parameters
NEWS | 3 +
backends/tracker/lib/trf-persona-store.vala | 24 +++++-----
backends/tracker/lib/trf-persona.vala | 32 +++++++-------
folks/individual.vala | 15 ++++---
folks/role-details.vala | 61 ++++++++++++++++++++++++++-
tests/tracker/add-persona.vala | 24 ++++++-----
tests/tracker/role-details-interface.vala | 9 ++--
tests/tracker/set-roles.vala | 26 +++++++-----
8 files changed, 132 insertions(+), 62 deletions(-)
---
diff --git a/NEWS b/NEWS
index 9ce3520..618dea6 100644
--- a/NEWS
+++ b/NEWS
@@ -43,6 +43,8 @@ Bugs fixed:
class
* Bug 653682 â Change WebServiceDetails.web_service_addresses to support
vCard-like arbitrary parameters
+* Bug 655921 â Change RoleDetails.roles to support vCard-like arbitrary
+ parameters
API changes:
* Swf.Persona retains and exposes its libsocialweb Contact
@@ -77,6 +79,7 @@ API changes:
* Remove all PhoneDetails functions (obsoleted by PhoneFieldDetails)
* Add and use WebServiceFieldDetails for
WebServiceFieldDetails.web_service_addresses
+* Use RoleFieldDetails for RoleDetails.roles
Overview of changes from libfolks 0.5.1 to libfolks 0.5.2
=========================================================
diff --git a/backends/tracker/lib/trf-persona-store.vala b/backends/tracker/lib/trf-persona-store.vala
index c5ee25f..31b6bd2 100644
--- a/backends/tracker/lib/trf-persona-store.vala
+++ b/backends/tracker/lib/trf-persona-store.vala
@@ -554,10 +554,10 @@ public class Trf.PersonaStore : Folks.PersonaStore
}
else if (k == Folks.PersonaStore.detail_key (PersonaDetail.ROLES))
{
- var roles = (Gee.HashSet<Role>) v.get_object ();
+ var roles = (Gee.HashSet<RoleFieldDetails>) v.get_object ();
int roles_cnt = 0;
- foreach (var r in roles)
+ foreach (var role_fd in roles)
{
var role_affl = "_:role_affl%d".printf (roles_cnt);
@@ -565,11 +565,11 @@ public class Trf.PersonaStore : Folks.PersonaStore
builder.predicate ("a");
builder.object (Trf.OntologyDefs.NCO_AFFILIATION);
builder.predicate (Trf.OntologyDefs.NCO_ROLE);
- builder.object_string (r.role);
- builder.predicate (Trf.OntologyDefs.NCO_ORG);
- builder.object_string (r.organisation_name);
+ builder.object_string (role_fd.value.role);
builder.predicate (Trf.OntologyDefs.NCO_TITLE);
- builder.object_string (r.title);
+ builder.object_string (role_fd.value.title);
+ builder.predicate (Trf.OntologyDefs.NCO_ORG);
+ builder.object_string (role_fd.value.organisation_name);
builder.subject ("_:p");
builder.predicate (Trf.OntologyDefs.NCO_HAS_AFFILIATION);
@@ -2030,7 +2030,7 @@ public class Trf.PersonaStore : Folks.PersonaStore
}
internal async void _set_roles (Folks.Persona persona,
- Set<Role> roles)
+ Set<RoleFieldDetails> roles)
{
const string del_t = "DELETE { " +
" ?p " + Trf.OntologyDefs.NCO_HAS_AFFILIATION + " ?a " +
@@ -2051,7 +2051,7 @@ public class Trf.PersonaStore : Folks.PersonaStore
builder.insert_open (null);
int i = 0;
- foreach (var r in roles)
+ foreach (var role_fd in roles)
{
string affl = "_:a%d".printf (i);
@@ -2059,11 +2059,11 @@ public class Trf.PersonaStore : Folks.PersonaStore
builder.predicate ("a");
builder.object (Trf.OntologyDefs.NCO_AFFILIATION);
builder.predicate (Trf.OntologyDefs.NCO_ROLE);
- builder.object_string (r.role);
- builder.predicate (Trf.OntologyDefs.NCO_ORG);
- builder.object_string (r.organisation_name);
+ builder.object_string (role_fd.value.role);
builder.predicate (Trf.OntologyDefs.NCO_TITLE);
- builder.object_string (r.title);
+ builder.object_string (role_fd.value.title);
+ builder.predicate (Trf.OntologyDefs.NCO_ORG);
+ builder.object_string (role_fd.value.organisation_name);
builder.subject ("?contact");
builder.predicate (Trf.OntologyDefs.NCO_HAS_AFFILIATION);
builder.object (affl);
diff --git a/backends/tracker/lib/trf-persona.vala b/backends/tracker/lib/trf-persona.vala
index 5b97a52..63f94cc 100644
--- a/backends/tracker/lib/trf-persona.vala
+++ b/backends/tracker/lib/trf-persona.vala
@@ -214,13 +214,13 @@ public class Trf.Persona : Folks.Persona,
private set {}
}
- private HashSet<Role> _roles;
- private Set<Role> _roles_ro;
+ private HashSet<RoleFieldDetails> _roles;
+ private Set<RoleFieldDetails> _roles_ro;
/**
* { inheritDoc}
*/
- public Set<Role> roles
+ public Set<RoleFieldDetails> roles
{
get { return this._roles_ro; }
public set
@@ -417,8 +417,9 @@ public class Trf.Persona : Folks.Persona,
(GLib.HashFunc) EmailFieldDetails.hash,
(GLib.EqualFunc) EmailFieldDetails.equal);
this._email_addresses_ro = this._email_addresses.read_only_view;
- this._roles = new HashSet<Role> ((GLib.HashFunc) Role.hash,
- (GLib.EqualFunc) Role.equal);
+ this._roles = new HashSet<RoleFieldDetails> (
+ (GLib.HashFunc) RoleFieldDetails.hash,
+ (GLib.EqualFunc) RoleFieldDetails.equal);
this._roles_ro = this._roles.read_only_view;
this._notes = new HashSet<NoteFieldDetails> (
(GLib.HashFunc) NoteFieldDetails.hash,
@@ -756,9 +757,9 @@ public class Trf.Persona : Folks.Persona,
return;
}
- HashSet<Role> roles = new HashSet<Role> (
- (GLib.HashFunc) Role.hash,
- (GLib.EqualFunc) Role.equal);
+ HashSet<RoleFieldDetails> role_fds = new HashSet<RoleFieldDetails> (
+ (GLib.HashFunc) RoleFieldDetails.hash,
+ (GLib.EqualFunc) RoleFieldDetails.equal);
string[] roles_a = roles_field.split ("\n");
@@ -772,10 +773,11 @@ public class Trf.Persona : Folks.Persona,
var new_role = new Role (title, organisation, tracker_id);
new_role.role = role;
- roles.add (new_role);
+ var role_fd = new RoleFieldDetails (new_role);
+ role_fds.add (role_fd);
}
- this._roles = roles;
+ this._roles = role_fds;
this._roles_ro = this._roles.read_only_view;
}
@@ -783,8 +785,8 @@ public class Trf.Persona : Folks.Persona,
{
var new_role = new Role (title, org, tracker_id);
new_role.role = role;
-
- if (this._roles.add (new_role))
+ var role_fd = new RoleFieldDetails (new_role);
+ if (this._roles.add (role_fd))
{
this.notify_property ("roles");
return true;
@@ -794,11 +796,11 @@ public class Trf.Persona : Folks.Persona,
internal bool _remove_role (string tracker_id)
{
- foreach (var r in this._roles)
+ foreach (var role_fd in this._roles)
{
- if (r.uid == tracker_id)
+ if (role_fd.value.uid == tracker_id)
{
- this._roles.remove (r);
+ this._roles.remove (role_fd);
this.notify_property ("roles");
return true;
}
diff --git a/folks/individual.vala b/folks/individual.vala
index 959a612..9c294f6 100644
--- a/folks/individual.vala
+++ b/folks/individual.vala
@@ -368,13 +368,13 @@ public class Folks.Individual : Object,
}
}
- private HashSet<Role> _roles;
- private Set<Role> _roles_ro;
+ private HashSet<RoleFieldDetails> _roles;
+ private Set<RoleFieldDetails> _roles_ro;
/**
* { inheritDoc}
*/
- public Set<Role> roles
+ public Set<RoleFieldDetails> roles
{
get { return this._roles_ro; }
private set
@@ -710,8 +710,9 @@ public class Folks.Individual : Object,
(GLib.HashFunc) EmailFieldDetails.hash,
(GLib.EqualFunc) EmailFieldDetails.equal);
this._email_addresses_ro = this._email_addresses.read_only_view;
- this._roles = new HashSet<Role>
- ((GLib.HashFunc) Role.hash, (GLib.EqualFunc) Role.equal);
+ this._roles = new HashSet<RoleFieldDetails> (
+ (GLib.HashFunc) RoleFieldDetails.hash,
+ (GLib.EqualFunc) RoleFieldDetails.equal);
this._roles_ro = this._roles.read_only_view;
this._local_ids = new HashSet<string> ();
this._local_ids_ro = this._local_ids.read_only_view;
@@ -1422,9 +1423,9 @@ public class Folks.Individual : Object,
var role_details = persona as RoleDetails;
if (role_details != null)
{
- foreach (var r in role_details.roles)
+ foreach (var role_fd in role_details.roles)
{
- this._roles.add (r);
+ this._roles.add (role_fd);
}
}
}
diff --git a/folks/role-details.vala b/folks/role-details.vala
index 8a2c489..16baf24 100644
--- a/folks/role-details.vala
+++ b/folks/role-details.vala
@@ -16,6 +16,7 @@
*
* Authors:
* Raul Gutierrez Segales <raul gutierrez segales collabora co uk>
+ * Travis Reitter <travis reitter collabora co uk>
*/
using Gee;
@@ -127,6 +128,62 @@ public class Folks.Role : Object
}
/**
+ * Object representing details of a contact in an organisation which can have
+ * some parameters associated with it.
+ *
+ * See { link Folks.AbstractFieldDetails}.
+ *
+ * @since UNRELEASED
+ */
+public class Folks.RoleFieldDetails : AbstractFieldDetails<Role>
+{
+ /**
+ * Create a new RoleFieldDetails.
+ *
+ * @param value the { link Role}} of the field
+ * @param parameters initial parameters. See
+ * { link AbstractFieldDetails.parameters}. A `null` value is equivalent to an
+ * empty map of parameters.
+ *
+ * @return a new RoleFieldDetails
+ *
+ * @since UNRELEASED
+ */
+ public RoleFieldDetails (Role value,
+ MultiMap<string, string>? parameters = null)
+ {
+ this.value = value;
+ if (parameters != null)
+ this.parameters = parameters;
+ }
+
+ /**
+ * { inheritDoc}
+ *
+ * @since UNRELEASED
+ */
+ public override bool equal (AbstractFieldDetails<string> that)
+ {
+ var that_fd = that as RoleFieldDetails;
+
+ if (that_fd == null)
+ return false;
+
+ return Role.equal (this.value, that_fd.value);
+ }
+
+ /**
+ * { inheritDoc}
+ *
+ * @since UNRELEASED
+ */
+ public override uint hash ()
+ {
+ return str_hash (this.value.to_string ());
+ }
+}
+
+/**
* This interfaces represents the list of roles a { link Persona} and
* { link Individual} might have.
*
@@ -137,7 +194,7 @@ public interface Folks.RoleDetails : Object
/**
* The roles of the contact.
*
- * @since 0.5.1
+ * @since UNRELEASED
*/
- public abstract Set<Role> roles { get; set; }
+ public abstract Set<RoleFieldDetails> roles { get; set; }
}
diff --git a/tests/tracker/add-persona.vala b/tests/tracker/add-persona.vala
index eedb3d3..be42b9f 100644
--- a/tests/tracker/add-persona.vala
+++ b/tests/tracker/add-persona.vala
@@ -272,11 +272,14 @@ public class AddPersonaTests : Folks.TestCase
(owned) v11);
Value? v12 = Value (typeof (Set<Role>));
- var roles = new HashSet<Role> ();
- Role r1 = new Role (this._title_1, this._organisation_1);
+ var role_fds = new HashSet<RoleFieldDetails> (
+ (GLib.HashFunc) RoleFieldDetails.hash,
+ (GLib.EqualFunc) RoleFieldDetails.equal);
+ var r1 = new Role (this._title_1, this._organisation_1);
r1.role = this._role_1;
- roles.add (r1);
- v12.set_object (roles);
+ var role_fd1 = new RoleFieldDetails (r1);
+ role_fds.add (role_fd1);
+ v12.set_object (role_fds);
details.insert (Folks.PersonaStore.detail_key (PersonaDetail.ROLES),
(owned) v12);
@@ -474,14 +477,13 @@ public class AddPersonaTests : Folks.TestCase
}
}
- foreach (var r in i.roles)
+ foreach (var role_fd in i.roles)
{
- if (r.title == this._title_1 &&
- r.organisation_name == this._organisation_1 &&
- r.role == this._role_1)
- {
- this._properties_found.replace ("role-1", true);
- }
+ var role_expected = new Role (this._title_1, this._organisation_1);
+ role_expected.role = this._role_1;
+ var role_fd_expected = new RoleFieldDetails (role_expected);
+ if (role_fd.equal (role_fd_expected))
+ this._properties_found.replace ("role-1", true);
}
foreach (var pafd in i.postal_addresses)
diff --git a/tests/tracker/role-details-interface.vala b/tests/tracker/role-details-interface.vala
index d1c3e19..9fa51e9 100644
--- a/tests/tracker/role-details-interface.vala
+++ b/tests/tracker/role-details-interface.vala
@@ -109,11 +109,12 @@ public class RoleDetailsInterfaceTests : Folks.TestCase
{
if (i.full_name == this._fullname)
{
- foreach (var role in i.roles)
+ foreach (var role_fd in i.roles)
{
- if (role.title == "boss" &&
- role.organisation_name == "Company" &&
- role.role == "Role")
+ var role_expected = new Role ("boss", "Company");
+ role_expected.role = "Role";
+ var role_fd_expected = new RoleFieldDetails (role_expected);
+ if (role_fd.equal (role_fd_expected))
{
this._found_role = true;
this._main_loop.quit ();
diff --git a/tests/tracker/set-roles.vala b/tests/tracker/set-roles.vala
index 13858eb..bd20316 100644
--- a/tests/tracker/set-roles.vala
+++ b/tests/tracker/set-roles.vala
@@ -30,7 +30,7 @@ public class SetRolesTests : Folks.TestCase
private IndividualAggregator _aggregator;
private string _persona_fullname;
private bool _role_found;
- private Role _role;
+ private RoleFieldDetails _role_fd;
public SetRolesTests ()
{
@@ -59,8 +59,9 @@ public class SetRolesTests : Folks.TestCase
c1.set (Trf.OntologyDefs.NCO_FULLNAME, this._persona_fullname);
this._tracker_backend.add_contact (c1);
- this._role = new Role ("some title", "some organisation");
- this._role.role = "some role";
+ var role = new Role ("some title", "some organisation");
+ role.role = "some role";
+ this._role_fd = new RoleFieldDetails (role);
this._tracker_backend.set_up ();
@@ -111,15 +112,18 @@ public class SetRolesTests : Folks.TestCase
{
i.notify["roles"].connect (this._notify_roles_cb);
- Gee.HashSet<Role> roles = new HashSet<Role>
- ((GLib.HashFunc) Role.hash, (GLib.EqualFunc) Role.equal);
- var r = new Role ("some title", "some organisation");
- r.role = "some role";
- roles.add ((owned) r);
+ Gee.HashSet<RoleFieldDetails> role_fds =
+ new HashSet<RoleFieldDetails>
+ ((GLib.HashFunc) RoleFieldDetails.hash,
+ (GLib.EqualFunc) RoleFieldDetails.equal);
+ var role = new Role ("some title", "some organisation");
+ role.role = "some role";
+ var role_fd = new RoleFieldDetails (role);
+ role_fds.add ((owned) role_fd);
foreach (var p in i.personas)
{
- ((RoleDetails) p).roles = roles;
+ ((RoleDetails) p).roles = role_fds;
}
}
}
@@ -132,9 +136,9 @@ public class SetRolesTests : Folks.TestCase
Folks.Individual i = (Folks.Individual) individual_obj;
if (i.full_name == this._persona_fullname)
{
- foreach (var r in i.roles)
+ foreach (var role_fd in i.roles)
{
- if (Role.equal (r, this._role))
+ if (role_fd.equal (this._role_fd))
{
this._role_found = true;
this._main_loop.quit ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]