summaryrefslogtreecommitdiff
path: root/backends
diff options
context:
space:
mode:
authorPhilip Withnall <philip.withnall@collabora.co.uk>2011-04-19 22:27:27 +0100
committerPhilip Withnall <philip.withnall@collabora.co.uk>2011-04-23 22:00:02 +0100
commitf8baf37765580eaa497f675f102ef713a67083fe (patch)
treea8018b84b6679678dcba98adbb0b8661997b69c4 /backends
parent6510a5cee80afafeefd507387455c6ebcb66a880 (diff)
Change UrlDetails.urls to be a Set<FieldDetails>
Helps: bgo#640092
Diffstat (limited to 'backends')
-rw-r--r--backends/libsocialweb/lib/swf-persona.vala18
-rw-r--r--backends/tracker/lib/trf-persona-store.vala115
-rw-r--r--backends/tracker/lib/trf-persona.vala22
3 files changed, 35 insertions, 120 deletions
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");
}