[folks] core: Add UrlDetails.change_urls()
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [folks] core: Add UrlDetails.change_urls()
- Date: Fri, 2 Sep 2011 18:31:52 +0000 (UTC)
commit a8f586f2cba4e46c0aba4190c8d0bb3c7575070e
Author: Philip Withnall <philip tecnocode co uk>
Date: Tue Aug 30 20:20:23 2011 +0100
core: Add UrlDetails.change_urls()
This allows the URLs of an implementing class to be changed asynchronously
with proper error notification.
Helps: bgo#657510
backends/eds/lib/edsf-persona-store.vala | 6 +++---
backends/eds/lib/edsf-persona.vala | 15 +++++++++++----
backends/libsocialweb/lib/swf-persona.vala | 19 ++++++++-----------
backends/tracker/lib/trf-persona.vala | 18 ++++++++++++++----
folks/individual.vala | 8 ++------
folks/url-details.vala | 22 ++++++++++++++++++++++
po/POTFILES.in | 1 +
po/POTFILES.skip | 1 +
8 files changed, 62 insertions(+), 28 deletions(-)
---
diff --git a/backends/eds/lib/edsf-persona-store.vala b/backends/eds/lib/edsf-persona-store.vala
index 19273bb..54f08e4 100644
--- a/backends/eds/lib/edsf-persona-store.vala
+++ b/backends/eds/lib/edsf-persona-store.vala
@@ -241,7 +241,7 @@ public class Edsf.PersonaStore : Folks.PersonaStore
* - PersonaStore.detail_key (PersonaDetail.LOCAL_IDS)
* - PersonaStore.detail_key (PersonaDetail.WEB_SERVICE_ADDRESSES)
* - PersonaStore.detail_key (PersonaDetail.NOTES)
- * - PersonaStore.detail_key (PersonaDetail.URL)
+ * - PersonaStore.detail_key (PersonaDetail.URLS)
*
* See { link Folks.PersonaStore.add_persona_from_details}.
*
@@ -760,7 +760,7 @@ public class Edsf.PersonaStore : Folks.PersonaStore
}
internal async void _set_urls (Edsf.Persona persona,
- Set<UrlFieldDetails> urls)
+ Set<UrlFieldDetails> urls) throws PropertyError
{
if (Utils.set_afd_equal (persona.urls, urls))
return;
@@ -773,7 +773,7 @@ public class Edsf.PersonaStore : Folks.PersonaStore
}
catch (GLib.Error e)
{
- GLib.warning ("Can't set urls: %s", e.message);
+ throw this.e_client_error_to_property_error ("urls", e);
}
}
diff --git a/backends/eds/lib/edsf-persona.vala b/backends/eds/lib/edsf-persona.vala
index ad69a03..04e4d24 100644
--- a/backends/eds/lib/edsf-persona.vala
+++ b/backends/eds/lib/edsf-persona.vala
@@ -438,10 +438,17 @@ public class Edsf.Persona : Folks.Persona,
public Set<UrlFieldDetails> urls
{
get { return this._urls_ro; }
- set
- {
- ((Edsf.PersonaStore) this.store)._set_urls (this, value);
- }
+ set { this.change_urls.begin (value); }
+ }
+
+ /**
+ * { inheritDoc}
+ *
+ * @since UNRELEASED
+ */
+ public async void change_urls (Set<UrlFieldDetails> urls) throws PropertyError
+ {
+ yield ((Edsf.PersonaStore) this.store)._set_urls (this, urls);
}
private HashMultiMap<string, ImFieldDetails> _im_addresses =
diff --git a/backends/libsocialweb/lib/swf-persona.vala b/backends/libsocialweb/lib/swf-persona.vala
index 50e25bc..b2dc631 100644
--- a/backends/libsocialweb/lib/swf-persona.vala
+++ b/backends/libsocialweb/lib/swf-persona.vala
@@ -139,18 +139,11 @@ public class Swf.Persona : Folks.Persona,
/**
* { inheritDoc}
*/
+ [CCode (notify = false)]
public Set<UrlFieldDetails> urls
{
get { return this._urls_ro; }
- private set
- {
- this._urls = new HashSet<UrlFieldDetails> (
- (GLib.HashFunc) UrlFieldDetails.hash,
- (GLib.EqualFunc) UrlFieldDetails.equal);
- this._urls_ro = this._urls.read_only_view;
- foreach (var url_fd in value)
- this._urls.add (url_fd);
- }
+ set { this.change_urls.begin (value); } /* not writeable */
}
private HashMultiMap<string, ImFieldDetails> _im_addresses =
@@ -367,8 +360,12 @@ public class Swf.Persona : Folks.Persona,
foreach (string website in websites)
urls.add (new UrlFieldDetails (website));
*/
- if (this.urls != urls)
- this.urls = urls;
+ if (this._urls != urls)
+ {
+ this._urls = urls;
+ this._urls_ro = urls.read_only_view;
+ this.notify_property ("urls");
+ }
var gender_string = contact.get_value ("x-gender");
Gender gender;
diff --git a/backends/tracker/lib/trf-persona.vala b/backends/tracker/lib/trf-persona.vala
index 18ebf1b..a3c552d 100644
--- a/backends/tracker/lib/trf-persona.vala
+++ b/backends/tracker/lib/trf-persona.vala
@@ -331,13 +331,21 @@ public class Trf.Persona : Folks.Persona,
/**
* { inheritDoc}
*/
+ [CCode (notify = false)]
public Set<UrlFieldDetails> urls
{
get { return this._urls_ro; }
- public set
- {
- ((Trf.PersonaStore) this.store)._set_urls (this, value);
- }
+ set { this.change_urls.begin (value); }
+ }
+
+ /**
+ * { inheritDoc}
+ *
+ * @since UNRELEASED
+ */
+ public async void change_urls (Set<UrlFieldDetails> urls) throws PropertyError
+ {
+ yield ((Trf.PersonaStore) this.store)._set_urls (this, urls);
}
private HashSet<PostalAddressFieldDetails> _postal_addresses;
@@ -1343,6 +1351,8 @@ public class Trf.Persona : Folks.Persona,
this._urls = url_fds;
this._urls_ro = this._urls.read_only_view;
+
+ this.notify_property ("urls");
}
internal bool _add_url (string url, string tracker_id, string type = "")
diff --git a/folks/individual.vala b/folks/individual.vala
index 6c7f64d..0e1617a 100644
--- a/folks/individual.vala
+++ b/folks/individual.vala
@@ -380,15 +380,11 @@ public class Folks.Individual : Object,
/**
* { inheritDoc}
*/
+ [CCode (notify = false)]
public Set<UrlFieldDetails> urls
{
get { return this._urls_ro; }
- private set
- {
- this._urls.clear ();
- foreach (var url_fd in value)
- this._urls.add (url_fd);
- }
+ set { this.change_urls.begin (value); } /* not writeable */
}
private HashSet<PhoneFieldDetails> _phone_numbers;
diff --git a/folks/url-details.vala b/folks/url-details.vala
index 6ee085c..57e6a33 100644
--- a/folks/url-details.vala
+++ b/folks/url-details.vala
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2011 Collabora Ltd.
+ * Copyright (C) 2011 Philip Withnall
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
@@ -17,6 +18,7 @@
* Authors:
* Marco Barisione <marco barisione collabora co uk>
* Travis Reitter <travis reitter collabora co uk>
+ * Philip Withnall <philip tecnocode co uk>
*/
using GLib;
@@ -88,4 +90,24 @@ public interface Folks.UrlDetails : Object
* @since 0.5.1
*/
public abstract Set<UrlFieldDetails> urls { get; set; }
+
+ /**
+ * Change the contact's URLs.
+ *
+ * It's preferred to call this rather than setting { link UrlDetails.urls}
+ * directly, as this method gives error notification and will only return once
+ * the URLs have been written to the relevant backing store (or the
+ * operation's failed).
+ *
+ * @param urls the set of URLs
+ * @throws PropertyError if setting the URLs failed
+ * @since UNRELEASED
+ */
+ public virtual async void change_urls (Set<UrlFieldDetails> urls)
+ throws PropertyError
+ {
+ /* Default implementation. */
+ throw new PropertyError.NOT_WRITEABLE (
+ _("URLs are not writeable on this contact."));
+ }
}
diff --git a/po/POTFILES.in b/po/POTFILES.in
index b50a2ab..0e67040 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -22,5 +22,6 @@ folks/note-details.vala
folks/phone-details.vala
folks/postal-address-details.vala
folks/role-details.vala
+folks/url-details.vala
tools/import-pidgin.vala
tools/import.vala
diff --git a/po/POTFILES.skip b/po/POTFILES.skip
index a467645..821d3ab 100644
--- a/po/POTFILES.skip
+++ b/po/POTFILES.skip
@@ -21,5 +21,6 @@ folks/note-details.c
folks/phone-details.c
folks/postal-address-details.c
folks/role-details.c
+folks/url-details.c
tools/import-pidgin.c
tools/import.c
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]