[folks] Migrate RoleDetails to AbstractFieldDetails.id
- From: Travis Reitter <treitter src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [folks] Migrate RoleDetails to AbstractFieldDetails.id
- Date: Mon, 24 Oct 2011 19:19:07 +0000 (UTC)
commit ba233588b1208c761e4512054626f6ddb6db8647
Author: Travis Reitter <travis reitter collabora co uk>
Date: Thu Oct 20 10:24:14 2011 -0700
Migrate RoleDetails to AbstractFieldDetails.id
Deprecate Role.uid in favor of AbstractFieldDetails.id
Helps: bgo#662433 - AbstractFieldDetails.equal() is ambiguous about
checking parameters.
NEWS | 1 +
backends/tracker/lib/trf-persona.vala | 8 +++++---
folks/role-details.vala | 29 +++++++++++++++++++++++++++++
tests/tracker/role-details-interface.vala | 18 ++++++++++++++++++
4 files changed, 53 insertions(+), 3 deletions(-)
---
diff --git a/NEWS b/NEWS
index 020a38a..0f973c6 100644
--- a/NEWS
+++ b/NEWS
@@ -7,6 +7,7 @@ API changes:
* Add AbstractFieldDetails.id to identify instances of details
* Deprecate PostalAddress.uid in favor of AbstractFieldDetails.id
* Deprecate NoteFieldDetails.uid in favor of AbstractFieldDetails.id
+* Deprecate Role.uid in favor of AbstractFieldDetails.id
Behavior changes:
* PostalAddress.equal() now ignores PostalAddress.uid
diff --git a/backends/tracker/lib/trf-persona.vala b/backends/tracker/lib/trf-persona.vala
index 8867684..b37b0af 100644
--- a/backends/tracker/lib/trf-persona.vala
+++ b/backends/tracker/lib/trf-persona.vala
@@ -967,9 +967,10 @@ public class Trf.Persona : Folks.Persona,
var title = r_info[Trf.RoleFields.TITLE];
var organisation = r_info[Trf.RoleFields.DEPARTMENT];
- var new_role = new Role (title, organisation, tracker_id);
+ var new_role = new Role (title, organisation, null);
new_role.role = role;
var role_fd = new RoleFieldDetails (new_role);
+ role_fd.id = tracker_id;
role_fds.add (role_fd);
}
@@ -981,9 +982,10 @@ public class Trf.Persona : Folks.Persona,
internal bool _add_role (string tracker_id, string? role, string? title, string? org)
{
- var new_role = new Role (title, org, tracker_id);
+ var new_role = new Role (title, org, null);
new_role.role = role;
var role_fd = new RoleFieldDetails (new_role);
+ role_fd.id = tracker_id;
if (this._roles.add (role_fd))
{
this.notify_property ("roles");
@@ -996,7 +998,7 @@ public class Trf.Persona : Folks.Persona,
{
foreach (var role_fd in this._roles)
{
- if (role_fd.value.uid == tracker_id)
+ if (role_fd.id == tracker_id)
{
this._roles.remove (role_fd);
this.notify_property ("roles");
diff --git a/folks/role-details.vala b/folks/role-details.vala
index 890acfc..f13b7a2 100644
--- a/folks/role-details.vala
+++ b/folks/role-details.vala
@@ -68,9 +68,11 @@ public class Folks.Role : Object
set { this._role = (value != null ? value : ""); }
}
+ private string _uid;
/**
* The UID that distinguishes this role.
*/
+ [Deprecated (since = "UNRELEASED", replacement = "AbstractFieldDetails.id")]
public string uid
{
get { return _uid; }
@@ -143,6 +145,23 @@ public class Folks.Role : Object
*/
public class Folks.RoleFieldDetails : AbstractFieldDetails<Role>
{
+ private string _id;
+ /**
+ * { inheritDoc}
+ */
+ public override string id
+ {
+ get { return this._id; }
+ set
+ {
+ this._id = (value != null ? value : "");
+
+ /* Keep the Role.uid sync'd from our id */
+ if (this._id != this.value.uid)
+ this.value.uid = this._id;
+ }
+ }
+
/**
* Create a new RoleFieldDetails.
*
@@ -161,6 +180,16 @@ public class Folks.RoleFieldDetails : AbstractFieldDetails<Role>
this.value = value;
if (parameters != null)
this.parameters = parameters;
+
+ /* We keep these sync'd both directions */
+ this.id = this.value.uid;
+
+ /* Keep the Role.uid sync'd to our id */
+ this.value.notify["uid"].connect ((s, p) =>
+ {
+ if (this.id != this.value.uid)
+ this.id = this.value.uid;
+ });
}
/**
diff --git a/tests/tracker/role-details-interface.vala b/tests/tracker/role-details-interface.vala
index beea993..79baadc 100644
--- a/tests/tracker/role-details-interface.vala
+++ b/tests/tracker/role-details-interface.vala
@@ -115,8 +115,26 @@ public class RoleDetailsInterfaceTests : Folks.TestCase
var role_expected = new Role ("boss", "Company");
role_expected.role = "Role";
var role_fd_expected = new RoleFieldDetails (role_expected);
+
+ /* We copy the tracker_id - we don't know it.
+ * We could get it from the 1st personas iid but there is no
+ * real need. */
+ role_fd_expected.id = role_fd.id;
+
if (role_fd.equal (role_fd_expected))
{
+ /* Ensure that setting the Role uid directly (which is
+ * deprecated) is equivalent to setting the id on a
+ * RoleFieldDetails directly */
+ var role_2 = new Role (
+ role_expected.title,
+ role_expected.organisation_name,
+ role_fd.id);
+ role_2.role = role_expected.role;
+ var role_fd_2 = new RoleFieldDetails (role_2);
+ assert (role_fd.equal (role_fd_2));
+ assert (role_fd.id == role_fd_2.id);
+
this._found_role = true;
this._main_loop.quit ();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]