[folks] Change UrlDetails.urls to be a Set<FieldDetails>
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [folks] Change UrlDetails.urls to be a Set<FieldDetails>
- Date: Sat, 23 Apr 2011 21:02:22 +0000 (UTC)
commit f8baf37765580eaa497f675f102ef713a67083fe
Author: Philip Withnall <philip withnall collabora co uk>
Date: Tue Apr 19 22:27:27 2011 +0100
Change UrlDetails.urls to be a Set<FieldDetails>
Helps: bgo#640092
NEWS | 1 +
backends/libsocialweb/lib/swf-persona.vala | 18 ++--
backends/tracker/lib/trf-persona-store.vala | 115 ++++----------------------
backends/tracker/lib/trf-persona.vala | 22 ++---
folks/individual.vala | 31 +++----
folks/url-details.vala | 5 +-
tests/tracker/add-persona.vala | 11 +--
tests/tracker/set-urls.vala | 12 ++--
tests/tracker/website-updates.vala | 4 +-
tools/inspect/utils.vala | 23 +-----
10 files changed, 68 insertions(+), 174 deletions(-)
---
diff --git a/NEWS b/NEWS
index 718c3a8..56aef5e 100644
--- a/NEWS
+++ b/NEWS
@@ -24,6 +24,7 @@ API changes:
* PostalAddressDetails.postal_addresses is now of type Set<PostalAddress>
* EmailDetails.email_addresses is now of type Set<FieldDetails>
* PhoneDetails.phone_numbers is now of type Set<FieldDetails>
+* UrlDetails.urls is now of type Set<FieldDetails>
Overview of changes from libfolks 0.4.0 to libfolks 0.5.0
=========================================================
diff --git a/backends/libsocialweb/lib/swf-persona.vala b/backends/libsocialweb/lib/swf-persona.vala
index bf25d11..c913331 100644
--- a/backends/libsocialweb/lib/swf-persona.vala
+++ b/backends/libsocialweb/lib/swf-persona.vala
@@ -79,19 +79,19 @@ public class Swf.Persona : Folks.Persona,
*/
public Gender gender { get; private set; }
- private GLib.List<FieldDetails> _urls;
+ private HashSet<FieldDetails> _urls;
+
/**
* { inheritDoc}
*/
- public GLib.List<FieldDetails> urls
+ public Set<FieldDetails> urls
{
get { return this._urls; }
private set
{
- this._urls = new GLib.List<FieldDetails> ();
- foreach (unowned FieldDetails ps in value)
- this._urls.prepend (ps);
- this._urls.reverse ();
+ this._urls = new HashSet<FieldDetails> ();
+ foreach (var ps in value)
+ this._urls.add (ps);
}
}
@@ -251,16 +251,16 @@ public class Swf.Persona : Folks.Persona,
if (this.full_name != full_name)
this.full_name = full_name;
- var urls = new GLib.List<FieldDetails> ();
+ var urls = new HashSet<FieldDetails> ();
var website = contact.get_value ("url");
if (website != null)
- urls.prepend (new FieldDetails (website));
+ urls.add (new FieldDetails (website));
/* https://bugzilla.gnome.org/show_bug.cgi?id=645139
string[] websites = contact.get_value_all ("url");
foreach (string website in websites)
- urls.prepend (new FieldDetails (website));
+ urls.add (new FieldDetails (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 86f9f10..7cff6c2 100644
--- a/backends/tracker/lib/trf-persona-store.vala
+++ b/backends/tracker/lib/trf-persona-store.vala
@@ -612,8 +612,7 @@ public class Trf.PersonaStore : Folks.PersonaStore
}
else if (k == Folks.PersonaStore.detail_key (PersonaDetail.URLS))
{
- unowned GLib.List<FieldDetails> urls =
- (GLib.List<FieldDetails>) v.get_pointer ();
+ Set<FieldDetails> urls = (Set<FieldDetails>) v.get_object ();
int url_cnt = 0;
foreach (var u in urls)
@@ -1970,9 +1969,9 @@ public class Trf.PersonaStore : Folks.PersonaStore
}
internal async void _set_urls (Folks.Persona persona,
- owned GLib.List<FieldDetails> urls)
+ Set<FieldDetails> urls)
{
- yield this._set_attrib (persona, (owned) urls,
+ yield this._set_attrib_set (persona, urls,
Trf.Attrib.URLS);
}
@@ -2257,97 +2256,6 @@ public class Trf.PersonaStore : Folks.PersonaStore
* - first we nuke old attribs
* - we create new affls with the new attribs
*/
- private async void _set_attrib (Folks.Persona persona,
- owned GLib.List<Object> attribs, Trf.Attrib what)
- {
- var p_id = ((Trf.Persona) persona).tracker_id ();
-
- unowned string? related_attrib = null;
- unowned string? related_prop = null;
- unowned string? related_prop_2 = null;
- unowned string? related_connection = null;
-
- switch (what)
- {
- case Trf.Attrib.URLS:
- related_attrib = Trf.OntologyDefs.NCO_URL;
- related_connection = Trf.OntologyDefs.NCO_URL;
- break;
- case Trf.Attrib.IM_ADDRESSES:
- assert_not_reached ();
- case Trf.Attrib.POSTAL_ADDRESSES:
- assert_not_reached ();
- }
-
- var builder = new Tracker.Sparql.Builder.update ();
- builder.insert_open (null);
- int i = 0;
- foreach (var p in attribs)
- {
- FieldDetails fd = null;
-
- string affl = "_:a%d".printf (i);
- string attr;
-
- if (what == Trf.Attrib.URLS)
- {
- fd = (FieldDetails) p;
- var type_p = fd.get_parameter_values ("type");
- if (type_p.contains ("blog"))
- {
- related_connection = Trf.OntologyDefs.NCO_BLOG;
- }
- else if (type_p.contains ("website"))
- {
- related_connection = Trf.OntologyDefs.NCO_WEBSITE;
- }
- attr = "'%s'".printf (fd.value);
- }
- else
- {
- fd = (FieldDetails) p;
- attr = "_:p%d".printf (i);
- builder.subject (attr);
- builder.predicate ("a");
- builder.object (related_attrib);
- builder.predicate (related_prop);
- builder.object_string (fd.value);
-
- if (what == Trf.Attrib.IM_ADDRESSES)
- {
- builder.predicate (related_prop_2);
- var im_params = fd.get_parameter_values ("proto").to_array ();
- builder.object_string (im_params[0]);
- }
- }
-
- builder.subject (affl);
- builder.predicate ("a");
- builder.object (Trf.OntologyDefs.NCO_AFFILIATION);
- builder.predicate (related_connection);
- builder.object (attr);
- builder.subject ("?contact");
- builder.predicate (Trf.OntologyDefs.NCO_HAS_AFFILIATION);
- builder.object (affl);
-
- i++;
- }
- builder.insert_close ();
- builder.where_open ();
- builder.subject ("?contact");
- builder.predicate ("a");
- builder.object (Trf.OntologyDefs.NCO_PERSON);
- string filter = " FILTER(tracker:id(?contact) = %s) ".printf (p_id);
- builder.append (filter);
- builder.where_close ();
-
- yield this._tracker_update (builder.result, "set_attrib");
- }
-
- /* NOTE:
- * - first we nuke old attribs
- * - we create new affls with the new attribs
- */
private async void _set_attrib_set (Folks.Persona persona,
Set<Object> attribs, Trf.Attrib what)
{
@@ -2375,7 +2283,9 @@ public class Trf.PersonaStore : Folks.PersonaStore
_REMOVE_POSTALS);
break;
case Trf.Attrib.URLS:
- assert_not_reached ();
+ related_attrib = Trf.OntologyDefs.NCO_URL;
+ related_connection = Trf.OntologyDefs.NCO_URL;
+ break;
}
var builder = new Tracker.Sparql.Builder.update ();
@@ -2413,7 +2323,18 @@ public class Trf.PersonaStore : Folks.PersonaStore
builder.object_string (pa.region);
break;
case Trf.Attrib.URLS:
- assert_not_reached ();
+ fd = (FieldDetails) p;
+ var type_p = fd.get_parameter_values ("type");
+ if (type_p.contains ("blog"))
+ {
+ related_connection = Trf.OntologyDefs.NCO_BLOG;
+ }
+ else if (type_p.contains ("website"))
+ {
+ related_connection = Trf.OntologyDefs.NCO_WEBSITE;
+ }
+ attr = "'%s'".printf (fd.value);
+ break;
case Trf.Attrib.IM_ADDRESSES:
default:
fd = (FieldDetails) p;
diff --git a/backends/tracker/lib/trf-persona.vala b/backends/tracker/lib/trf-persona.vala
index 6675552..8a818be 100644
--- a/backends/tracker/lib/trf-persona.vala
+++ b/backends/tracker/lib/trf-persona.vala
@@ -214,22 +214,17 @@ public class Trf.Persona : Folks.Persona,
}
}
- private GLib.List<FieldDetails> _urls;
+ private HashSet<FieldDetails> _urls = new HashSet<FieldDetails> ();
+
/**
* { inheritDoc}
*/
- public GLib.List<FieldDetails> urls
+ public Set<FieldDetails> urls
{
get { return this._urls; }
public set
{
- var _temp = new GLib.List<FieldDetails> ();
- foreach (unowned FieldDetails e in value)
- _temp.prepend (e);
- _temp.reverse ();
-
- ((Trf.PersonaStore) this.store)._set_urls (this,
- (owned) _temp);
+ ((Trf.PersonaStore) this.store)._set_urls (this, value);
}
}
@@ -1050,7 +1045,7 @@ public class Trf.Persona : Folks.Persona,
private void _update_urls ()
{
- var urls = new GLib.List<FieldDetails> ();
+ var urls = new HashSet<FieldDetails> ();
var _urls_field = this._cursor.get_string (Trf.Fields.URLS).dup ();
if (_urls_field == null)
@@ -1085,12 +1080,11 @@ public class Trf.Persona : Folks.Persona,
var fd = new FieldDetails (u[i]);
fd.set_parameter ("tracker_id", tracker_id);
fd.set_parameter ("type", type);
- urls.prepend ((owned) fd);
+ urls.add (fd);
}
}
- urls.reverse ();
- this._urls = (owned) urls;
+ this._urls = urls;
}
internal bool _add_url (string url, string tracker_id, string type = "")
@@ -1111,7 +1105,7 @@ public class Trf.Persona : Folks.Persona,
var fd = new FieldDetails (url);
fd.set_parameter ("tracker_id", tracker_id);
fd.set_parameter ("type", type);
- this._urls.prepend ((owned) fd);
+ this._urls.add (fd);
this.notify_property ("urls");
}
diff --git a/folks/individual.vala b/folks/individual.vala
index 94bad5d..4994f59 100644
--- a/folks/individual.vala
+++ b/folks/individual.vala
@@ -256,19 +256,18 @@ public class Folks.Individual : Object,
}
}
- private GLib.List<FieldDetails> _urls;
+ private HashSet<FieldDetails> _urls;
/**
* { inheritDoc}
*/
- public GLib.List<FieldDetails> urls
+ public Set<FieldDetails> urls
{
get { return this._urls; }
private set
{
- this._urls = new GLib.List<FieldDetails> ();
- foreach (unowned FieldDetails ps in value)
- this._urls.prepend (ps);
- this._urls.reverse ();
+ this._urls = new HashSet<FieldDetails> ();
+ foreach (var ps in value)
+ this._urls.add (ps);
}
}
@@ -1135,37 +1134,35 @@ public class Folks.Individual : Object,
private void _update_urls ()
{
/* Populate the URLs as the union of our Personas' URLs.
- * If the same URL exist multiple times we merge the parameters. */
- var urls_set = new HashTable<unowned string, unowned FieldDetails> (
- str_hash, str_equal);
- var urls = new GLib.List<FieldDetails> ();
+ * If the same URL exists multiple times we merge the parameters. */
+ var urls_set = new HashMap<unowned string, unowned FieldDetails> ();
+ var urls = new HashSet<FieldDetails> ();
foreach (var persona in this._persona_list)
{
var url_details = persona as UrlDetails;
if (url_details != null)
{
- foreach (unowned FieldDetails ps in url_details.urls)
+ foreach (var ps in url_details.urls)
{
if (ps.value == null)
continue;
- var existing = urls_set.lookup (ps.value);
+ var existing = urls_set.get (ps.value);
if (existing != null)
existing.extend_parameters (ps.parameters);
else
{
var new_ps = new FieldDetails (ps.value);
new_ps.extend_parameters (ps.parameters);
- urls_set.insert (ps.value, new_ps);
- urls.prepend ((owned) new_ps);
+ urls_set.set (ps.value, new_ps);
+ urls.add (new_ps);
}
}
}
}
- /* Set the private member directly to avoid iterating this list again */
- urls.reverse ();
- this._urls = (owned) urls;
+ /* Set the private member directly to avoid iterating this set again */
+ this._urls = urls;
this.notify_property ("urls");
}
diff --git a/folks/url-details.vala b/folks/url-details.vala
index 80ac343..e8b47ed 100644
--- a/folks/url-details.vala
+++ b/folks/url-details.vala
@@ -20,6 +20,7 @@
*/
using GLib;
+using Gee;
/**
* Associates a list of URLs with a contact.
@@ -33,7 +34,7 @@ public interface Folks.UrlDetails : Object
*
* A list or websites associated to the contact.
*
- * @since 0.3.5
+ * @since UNRELEASED
*/
- public abstract List<FieldDetails> urls { get; set; }
+ public abstract Set<FieldDetails> urls { get; set; }
}
diff --git a/tests/tracker/add-persona.vala b/tests/tracker/add-persona.vala
index c73eb7a..e1c2cc0 100644
--- a/tests/tracker/add-persona.vala
+++ b/tests/tracker/add-persona.vala
@@ -280,14 +280,13 @@ public class AddPersonaTests : Folks.TestCase
Folks.PersonaStore.detail_key (PersonaDetail.POSTAL_ADDRESSES),
(owned) v13);
- Value? v14 = Value (typeof (GLib.List<FieldDetails>));
- GLib.List<FieldDetails> urls =
- new GLib.List<FieldDetails> ();
+ Value? v14 = Value (typeof (Set<FieldDetails>));
+ var urls = new HashSet<FieldDetails> ();
var url_1 = new FieldDetails (this._url_1);
- urls.prepend ((owned) url_1);
+ urls.add (url_1);
var url_2 = new FieldDetails (this._url_2);
- urls.prepend ((owned) url_2);
- v14.set_pointer (urls);
+ urls.add (url_2);
+ v14.set_object (urls);
details.insert (Folks.PersonaStore.detail_key (PersonaDetail.URLS),
(owned) v14);
diff --git a/tests/tracker/set-urls.vala b/tests/tracker/set-urls.vala
index ed3744d..eb1e02f 100644
--- a/tests/tracker/set-urls.vala
+++ b/tests/tracker/set-urls.vala
@@ -108,19 +108,19 @@ public class SetURLsTests : Folks.TestCase
{
i.notify["urls"].connect (this._notify_urls_cb);
- GLib.List<FieldDetails> urls = new GLib.List<FieldDetails> ();
+ var urls = new HashSet<FieldDetails> ();
var p1 = new FieldDetails (this._urls.get ("blog"));
p1.set_parameter ("type", "blog");
- urls.prepend ((owned) p1);
+ urls.add (p1);
var p2 = new FieldDetails (this._urls.get ("website"));
p2.set_parameter ("type", "website");
- urls.prepend ((owned) p2);
+ urls.add (p2);
var p3 = new FieldDetails (this._urls.get ("url"));
p3.set_parameter ("type", "url");
- urls.prepend ((owned) p3);
+ urls.add (p3);
Trf.Persona p = (Trf.Persona)i.personas.nth_data (0);
- p.urls = (owned) urls;
+ p.urls = urls;
}
}
@@ -132,7 +132,7 @@ public class SetURLsTests : Folks.TestCase
Folks.Individual i = (Folks.Individual) individual_obj;
if (i.full_name == this._persona_fullname)
{
- foreach (unowned FieldDetails p in i.urls)
+ foreach (var p in i.urls)
{
var type_p = p.get_parameter_values ("type");
diff --git a/tests/tracker/website-updates.vala b/tests/tracker/website-updates.vala
index d7689d8..ea0f0d1 100644
--- a/tests/tracker/website-updates.vala
+++ b/tests/tracker/website-updates.vala
@@ -125,7 +125,7 @@ public class WebsiteUpdatesTests : Folks.TestCase
this._individual_id = i.id;
- foreach (unowned FieldDetails fd in i.urls)
+ foreach (var fd in i.urls)
{
var website = fd.value;
if (website == this._initial_website)
@@ -150,7 +150,7 @@ public class WebsiteUpdatesTests : Folks.TestCase
{
Folks.Individual i = (Folks.Individual) individual_obj;
- foreach (unowned FieldDetails fd in i.urls)
+ foreach (var fd in i.urls)
{
var website = fd.value;
if (website == this._updated_website)
diff --git a/tools/inspect/utils.vala b/tools/inspect/utils.vala
index c25ab23..b1639a2 100644
--- a/tools/inspect/utils.vala
+++ b/tools/inspect/utils.vala
@@ -321,7 +321,8 @@ private class Folks.Inspect.Utils
return output_string;
}
else if (prop_name == "email-addresses" ||
- prop_name == "phone-numbers")
+ prop_name == "phone-numbers" ||
+ prop_name == "urls")
{
output_string = "{ ";
bool first = true;
@@ -341,26 +342,6 @@ private class Folks.Inspect.Utils
return output_string;
}
- else if (prop_name == "urls")
- {
- output_string = "{ ";
- bool first = true;
- unowned GLib.List<FieldDetails> prop_list =
- (GLib.List<FieldDetails>) prop_value.get_pointer ();
-
- foreach (var p in prop_list)
- {
- if (!first)
- {
- output_string += ", ";
- }
- output_string += p.value;
- first = false;
- }
- output_string += " }";
-
- return output_string;
- }
else if (prop_name == "birthday")
{
unowned DateTime dobj = (DateTime) prop_value.get_boxed ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]