[folks] Support vCard-like parameters for URLs
- From: Travis Reitter <treitter src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [folks] Support vCard-like parameters for URLs
- Date: Fri, 12 Aug 2011 15:58:11 +0000 (UTC)
commit 3a849aec763faa86f81b16d231cb4a167a3ac701
Author: Travis Reitter <travis reitter collabora co uk>
Date: Thu Aug 11 16:37:22 2011 +0200
Support vCard-like parameters for URLs
Closes: bgo#655922 - Rebase UrlDetails.urls upon an
AbstractFieldDetails-derived class
NEWS | 3 +-
backends/eds/lib/edsf-persona.vala | 12 ++++---
backends/libsocialweb/lib/swf-persona.vala | 25 +++++++------
backends/tracker/lib/trf-persona-store.vala | 13 ++++---
backends/tracker/lib/trf-persona.vala | 44 ++++++++++++-----------
folks/individual.vala | 35 +++++++++---------
folks/url-details.vala | 53 ++++++++++++++++++++++++++-
tests/tracker/add-persona.vala | 11 +++---
tests/tracker/set-urls.vala | 20 +++++-----
9 files changed, 138 insertions(+), 78 deletions(-)
---
diff --git a/NEWS b/NEWS
index 618dea6..07ca7b0 100644
--- a/NEWS
+++ b/NEWS
@@ -45,7 +45,7 @@ Bugs fixed:
vCard-like arbitrary parameters
* Bug 655921 â Change RoleDetails.roles to support vCard-like arbitrary
parameters
-
+* Bug 655922 - Rebase UrlDetails.urls upon an AbstractFieldDetails-derived class
API changes:
* Swf.Persona retains and exposes its libsocialweb Contact
* Add a PresenceDetails.presence_status property
@@ -80,6 +80,7 @@ API changes:
* Add and use WebServiceFieldDetails for
WebServiceFieldDetails.web_service_addresses
* Use RoleFieldDetails for RoleDetails.roles
+* Use UrlFieldDetails for UrlDetails.urls
Overview of changes from libfolks 0.5.1 to libfolks 0.5.2
=========================================================
diff --git a/backends/eds/lib/edsf-persona.vala b/backends/eds/lib/edsf-persona.vala
index a0f789a..523a016 100644
--- a/backends/eds/lib/edsf-persona.vala
+++ b/backends/eds/lib/edsf-persona.vala
@@ -337,14 +337,14 @@ public class Edsf.Persona : Folks.Persona,
}
}
- private HashSet<FieldDetails> _urls;
- private Set<FieldDetails> _urls_ro;
+ private HashSet<UrlFieldDetails> _urls;
+ private Set<UrlFieldDetails> _urls_ro;
/**
* { inheritDoc}
*
* @since 0.5.UNRELEASED
*/
- public Set<FieldDetails> urls
+ public Set<UrlFieldDetails> urls
{
get { return this._urls_ro; }
set
@@ -496,7 +496,9 @@ public class Edsf.Persona : Folks.Persona,
(GLib.HashFunc) NoteFieldDetails.hash,
(GLib.EqualFunc) NoteFieldDetails.equal);
this._notes_ro = this._notes.read_only_view;
- this._urls = new HashSet<FieldDetails> ();
+ this._urls = new HashSet<UrlFieldDetails> (
+ (GLib.HashFunc) UrlFieldDetails.hash,
+ (GLib.EqualFunc) UrlFieldDetails.equal);
this._urls_ro = this._urls.read_only_view;
this._postal_addresses = new HashSet<PostalAddressFieldDetails> (
(GLib.HashFunc) PostalAddressFieldDetails.hash,
@@ -806,7 +808,7 @@ public class Edsf.Persona : Folks.Persona,
string u = (string) this._get_property (url_property);
if (u != null && u != "")
{
- this._urls.add (new FieldDetails (u));
+ this._urls.add (new UrlFieldDetails (u));
}
}
diff --git a/backends/libsocialweb/lib/swf-persona.vala b/backends/libsocialweb/lib/swf-persona.vala
index d544270..05070bc 100644
--- a/backends/libsocialweb/lib/swf-persona.vala
+++ b/backends/libsocialweb/lib/swf-persona.vala
@@ -96,23 +96,23 @@ public class Swf.Persona : Folks.Persona,
*/
public Gender gender { get; private set; }
- private HashSet<FieldDetails> _urls;
- private Set<FieldDetails> _urls_ro;
+ private HashSet<UrlFieldDetails> _urls;
+ private Set<UrlFieldDetails> _urls_ro;
/**
* { inheritDoc}
*/
- public Set<FieldDetails> urls
+ public Set<UrlFieldDetails> urls
{
get { return this._urls_ro; }
private set
{
- this._urls = new HashSet<FieldDetails> (
- (GLib.HashFunc) FieldDetails.hash,
- (GLib.EqualFunc) FieldDetails.equal);
+ this._urls = new HashSet<UrlFieldDetails> (
+ (GLib.HashFunc) UrlFieldDetails.hash,
+ (GLib.EqualFunc) UrlFieldDetails.equal);
this._urls_ro = this._urls.read_only_view;
- foreach (var ps in value)
- this._urls.add (ps);
+ foreach (var url_fd in value)
+ this._urls.add (url_fd);
}
}
@@ -303,17 +303,18 @@ public class Swf.Persona : Folks.Persona,
if (this.full_name != full_name)
this.full_name = full_name;
- var urls = new HashSet<FieldDetails> ((GLib.HashFunc) FieldDetails.hash,
- (GLib.EqualFunc) FieldDetails.equal);
+ var urls = new HashSet<UrlFieldDetails> (
+ (GLib.HashFunc) UrlFieldDetails.hash,
+ (GLib.EqualFunc) UrlFieldDetails.equal);
var website = contact.get_value ("url");
if (website != null)
- urls.add (new FieldDetails (website));
+ urls.add (new UrlFieldDetails (website));
/* https://bugzilla.gnome.org/show_bug.cgi?id=645139
string[] websites = contact.get_value_all ("url");
foreach (string website in websites)
- urls.add (new FieldDetails (website));
+ urls.add (new UrlFieldDetails (website));
*/
if (this.urls != urls)
this.urls = urls;
diff --git a/backends/tracker/lib/trf-persona-store.vala b/backends/tracker/lib/trf-persona-store.vala
index 31b6bd2..adbbd90 100644
--- a/backends/tracker/lib/trf-persona-store.vala
+++ b/backends/tracker/lib/trf-persona-store.vala
@@ -623,10 +623,11 @@ public class Trf.PersonaStore : Folks.PersonaStore
}
else if (k == Folks.PersonaStore.detail_key (PersonaDetail.URLS))
{
- Set<FieldDetails> urls = (Set<FieldDetails>) v.get_object ();
+ Set<UrlFieldDetails> url_fds =
+ (Set<UrlFieldDetails>) v.get_object ();
int url_cnt = 0;
- foreach (var u in urls)
+ foreach (var url_fd in url_fds)
{
var url_affl = "_:url_affl%d".printf (url_cnt);
@@ -634,7 +635,7 @@ public class Trf.PersonaStore : Folks.PersonaStore
builder.predicate ("a");
builder.object (Trf.OntologyDefs.NCO_AFFILIATION);
builder.predicate (Trf.OntologyDefs.NCO_URL);
- builder.object_string (u.value);
+ builder.object_string (url_fd.value);
builder.subject ("_:p");
builder.predicate (Trf.OntologyDefs.NCO_HAS_AFFILIATION);
@@ -1998,7 +1999,7 @@ public class Trf.PersonaStore : Folks.PersonaStore
}
internal async void _set_urls (Folks.Persona persona,
- Set<FieldDetails> urls)
+ Set<UrlFieldDetails> urls)
{
yield this._set_attrib_set (persona, urls,
Trf.Attrib.URLS);
@@ -2382,7 +2383,7 @@ public class Trf.PersonaStore : Folks.PersonaStore
builder.object_string (pa.region);
break;
case Trf.Attrib.URLS:
- fd = (FieldDetails) p;
+ fd = (UrlFieldDetails) p;
var type_p = fd.get_parameter_values ("type");
if (type_p.contains ("blog"))
{
@@ -2392,7 +2393,7 @@ public class Trf.PersonaStore : Folks.PersonaStore
{
related_connection = Trf.OntologyDefs.NCO_WEBSITE;
}
- attr = "'%s'".printf (((FieldDetails) fd).value);
+ attr = "'%s'".printf (((UrlFieldDetails) fd).value);
break;
case Trf.Attrib.IM_ADDRESSES:
default:
diff --git a/backends/tracker/lib/trf-persona.vala b/backends/tracker/lib/trf-persona.vala
index 63f94cc..8c4ed0a 100644
--- a/backends/tracker/lib/trf-persona.vala
+++ b/backends/tracker/lib/trf-persona.vala
@@ -244,13 +244,13 @@ public class Trf.Persona : Folks.Persona,
}
}
- private HashSet<FieldDetails> _urls;
- private Set<FieldDetails> _urls_ro;
+ private HashSet<UrlFieldDetails> _urls;
+ private Set<UrlFieldDetails> _urls_ro;
/**
* { inheritDoc}
*/
- public Set<FieldDetails> urls
+ public Set<UrlFieldDetails> urls
{
get { return this._urls_ro; }
public set
@@ -425,8 +425,9 @@ public class Trf.Persona : Folks.Persona,
(GLib.HashFunc) NoteFieldDetails.hash,
(GLib.EqualFunc) NoteFieldDetails.equal);
this._notes_ro = this._notes.read_only_view;
- this._urls = new HashSet<FieldDetails> ((GLib.HashFunc) FieldDetails.hash,
- (GLib.EqualFunc) FieldDetails.equal);
+ this._urls = new HashSet<UrlFieldDetails> (
+ (GLib.HashFunc) UrlFieldDetails.hash,
+ (GLib.EqualFunc) UrlFieldDetails.equal);
this._urls_ro = this._urls.read_only_view;
this._postal_addresses = new HashSet<PostalAddressFieldDetails> (
(GLib.HashFunc) PostalAddressFieldDetails.hash,
@@ -1130,8 +1131,9 @@ public class Trf.Persona : Folks.Persona,
private void _update_urls ()
{
- var urls = new HashSet<FieldDetails> ((GLib.HashFunc) FieldDetails.hash,
- (GLib.EqualFunc) FieldDetails.equal);
+ var url_fds = new HashSet<UrlFieldDetails> (
+ (GLib.HashFunc) UrlFieldDetails.hash,
+ (GLib.EqualFunc) UrlFieldDetails.equal);
var _urls_field = this._cursor.get_string (Trf.Fields.URLS).dup ();
if (_urls_field == null)
@@ -1163,14 +1165,14 @@ public class Trf.Persona : Folks.Persona,
break;
}
- var fd = new FieldDetails (u[i]);
- fd.set_parameter ("tracker_id", tracker_id);
- fd.set_parameter ("type", type);
- urls.add (fd);
+ var url_fd = new UrlFieldDetails (u[i]);
+ url_fd.set_parameter ("tracker_id", tracker_id);
+ url_fd.set_parameter ("type", type);
+ url_fds.add (url_fd);
}
}
- this._urls = urls;
+ this._urls = url_fds;
this._urls_ro = this._urls.read_only_view;
}
@@ -1178,9 +1180,9 @@ public class Trf.Persona : Folks.Persona,
{
bool found = false;
- foreach (var p in this._urls)
+ foreach (var url_fd in this._urls)
{
- if (p.get_parameter_values ("tracker_id").contains (tracker_id))
+ if (url_fd.get_parameter_values ("tracker_id").contains (tracker_id))
{
found = true;
break;
@@ -1189,10 +1191,10 @@ public class Trf.Persona : Folks.Persona,
if (!found)
{
- var fd = new FieldDetails (url);
- fd.set_parameter ("tracker_id", tracker_id);
- fd.set_parameter ("type", type);
- this._urls.add (fd);
+ var url_fd = new UrlFieldDetails (url);
+ url_fd.set_parameter ("tracker_id", tracker_id);
+ url_fd.set_parameter ("type", type);
+ this._urls.add (url_fd);
this.notify_property ("urls");
}
@@ -1203,11 +1205,11 @@ public class Trf.Persona : Folks.Persona,
{
bool found = false;
- foreach (var u in this._urls)
+ foreach (var url_fd in this._urls)
{
- if (u.get_parameter_values ("tracker_id").contains (tracker_id))
+ if (url_fd.get_parameter_values ("tracker_id").contains (tracker_id))
{
- this._urls.remove (u);
+ this._urls.remove (url_fd);
found = true;
}
}
diff --git a/folks/individual.vala b/folks/individual.vala
index 9c294f6..3ee366e 100644
--- a/folks/individual.vala
+++ b/folks/individual.vala
@@ -317,20 +317,20 @@ public class Folks.Individual : Object,
}
}
- private HashSet<FieldDetails> _urls;
- private Set<FieldDetails> _urls_ro;
+ private HashSet<UrlFieldDetails> _urls;
+ private Set<UrlFieldDetails> _urls_ro;
/**
* { inheritDoc}
*/
- public Set<FieldDetails> urls
+ public Set<UrlFieldDetails> urls
{
get { return this._urls_ro; }
private set
{
this._urls.clear ();
- foreach (var ps in value)
- this._urls.add (ps);
+ foreach (var url_fd in value)
+ this._urls.add (url_fd);
}
}
@@ -699,8 +699,9 @@ public class Folks.Individual : Object,
this._persona_set_ro = this._persona_set.read_only_view;
this._stores = new HashMap<PersonaStore, uint> (null, null);
this._gender = Gender.UNSPECIFIED;
- this._urls = new HashSet<FieldDetails> ((GLib.HashFunc) FieldDetails.hash,
- (GLib.EqualFunc) FieldDetails.equal);
+ this._urls = new HashSet<UrlFieldDetails> (
+ (GLib.HashFunc) UrlFieldDetails.hash,
+ (GLib.EqualFunc) UrlFieldDetails.equal);
this._urls_ro = this._urls.read_only_view;
this._phone_numbers = new HashSet<PhoneFieldDetails> (
(GLib.HashFunc) PhoneFieldDetails.hash,
@@ -1309,8 +1310,8 @@ public class Folks.Individual : Object,
{
/* Populate the URLs as the union of our Personas' URLs.
* If the same URL exists multiple times we merge the parameters. */
- var urls_set = new HashMap<unowned string, unowned FieldDetails> (
- null, null, (GLib.EqualFunc) FieldDetails.equal);
+ var urls_set = new HashMap<unowned string, unowned UrlFieldDetails> (
+ null, null, (GLib.EqualFunc) UrlFieldDetails.equal);
this._urls.clear ();
@@ -1319,20 +1320,20 @@ public class Folks.Individual : Object,
var url_details = persona as UrlDetails;
if (url_details != null)
{
- foreach (var ps in url_details.urls)
+ foreach (var url_fd in url_details.urls)
{
- if (ps.value == null)
+ if (url_fd.value == null)
continue;
- var existing = urls_set.get (ps.value);
+ var existing = urls_set.get (url_fd.value);
if (existing != null)
- existing.extend_parameters (ps.parameters);
+ existing.extend_parameters (url_fd.parameters);
else
{
- var new_ps = new FieldDetails (ps.value);
- new_ps.extend_parameters (ps.parameters);
- urls_set.set (ps.value, new_ps);
- this._urls.add (new_ps);
+ var new_url_fd = new UrlFieldDetails (url_fd.value);
+ new_url_fd.extend_parameters (url_fd.parameters);
+ urls_set.set (url_fd.value, new_url_fd);
+ this._urls.add (new_url_fd);
}
}
}
diff --git a/folks/url-details.vala b/folks/url-details.vala
index fa5c1ed..820d61e 100644
--- a/folks/url-details.vala
+++ b/folks/url-details.vala
@@ -23,6 +23,57 @@ using GLib;
using Gee;
/**
+ * Object representing a URL that can have some parameters associated with it.
+ *
+ * See { link Folks.AbstractFieldDetails} for details on common parameter names
+ * and values.
+ *
+ * @since UNRELEASED
+ */
+public class Folks.UrlFieldDetails : AbstractFieldDetails<string>
+{
+ /**
+ * Create a new UrlFieldDetails.
+ *
+ * @param value the value of the field
+ * @param parameters initial parameters. See
+ * { link AbstractFieldDetails.parameters}. A `null` value is equivalent to a
+ * empty map of parameters.
+ *
+ * @return a new UrlFieldDetails
+ *
+ * @since UNRELEASED
+ */
+ public UrlFieldDetails (string 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)
+ {
+ return base.equal<string> (that);
+ }
+
+ /**
+ * { inheritDoc}
+ *
+ * @since UNRELEASED
+ */
+ public override uint hash ()
+ {
+ return base.hash ();
+ }
+}
+
+/**
* Associates a list of URLs with a contact.
*
* @since 0.3.5
@@ -36,5 +87,5 @@ public interface Folks.UrlDetails : Object
*
* @since 0.5.1
*/
- public abstract Set<FieldDetails> urls { get; set; }
+ public abstract Set<UrlFieldDetails> urls { get; set; }
}
diff --git a/tests/tracker/add-persona.vala b/tests/tracker/add-persona.vala
index be42b9f..f814935 100644
--- a/tests/tracker/add-persona.vala
+++ b/tests/tracker/add-persona.vala
@@ -299,12 +299,13 @@ public class AddPersonaTests : Folks.TestCase
Folks.PersonaStore.detail_key (PersonaDetail.POSTAL_ADDRESSES),
(owned) v13);
- Value? v14 = Value (typeof (Set<FieldDetails>));
- var urls = new HashSet<FieldDetails> ((GLib.HashFunc) FieldDetails.hash,
- (GLib.EqualFunc) FieldDetails.equal);
- var url_1 = new FieldDetails (this._url_1);
+ Value? v14 = Value (typeof (Set<UrlFieldDetails>));
+ var urls = new HashSet<UrlFieldDetails> (
+ (GLib.HashFunc) UrlFieldDetails.hash,
+ (GLib.EqualFunc) UrlFieldDetails.equal);
+ var url_1 = new UrlFieldDetails (this._url_1);
urls.add (url_1);
- var url_2 = new FieldDetails (this._url_2);
+ var url_2 = new UrlFieldDetails (this._url_2);
urls.add (url_2);
v14.set_object (urls);
details.insert (Folks.PersonaStore.detail_key (PersonaDetail.URLS),
diff --git a/tests/tracker/set-urls.vala b/tests/tracker/set-urls.vala
index 239e23c..7682b14 100644
--- a/tests/tracker/set-urls.vala
+++ b/tests/tracker/set-urls.vala
@@ -108,22 +108,22 @@ public class SetURLsTests : Folks.TestCase
{
i.notify["urls"].connect (this._notify_urls_cb);
- var urls = new HashSet<FieldDetails> (
- (GLib.HashFunc) FieldDetails.hash,
- (GLib.EqualFunc) FieldDetails.equal);
- var p1 = new FieldDetails (this._urls.get ("blog"));
+ var url_fds = new HashSet<UrlFieldDetails> (
+ (GLib.HashFunc) UrlFieldDetails.hash,
+ (GLib.EqualFunc) UrlFieldDetails.equal);
+ var p1 = new UrlFieldDetails (this._urls.get ("blog"));
p1.set_parameter ("type", "blog");
- urls.add (p1);
- var p2 = new FieldDetails (this._urls.get ("website"));
+ url_fds.add (p1);
+ var p2 = new UrlFieldDetails (this._urls.get ("website"));
p2.set_parameter ("type", "website");
- urls.add (p2);
- var p3 = new FieldDetails (this._urls.get ("url"));
+ url_fds.add (p2);
+ var p3 = new UrlFieldDetails (this._urls.get ("url"));
p3.set_parameter ("type", "url");
- urls.add (p3);
+ url_fds.add (p3);
foreach (var p in i.personas)
{
- ((UrlDetails) p).urls = urls;
+ ((UrlDetails) p).urls = url_fds;
}
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]