[folks] Support UrlDetails for the Telepathy backend.
- From: Travis Reitter <treitter src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [folks] Support UrlDetails for the Telepathy backend.
- Date: Tue, 11 Oct 2011 01:14:49 +0000 (UTC)
commit 3a3ddc16698519ee396eaf9b51c319f820e11009
Author: Travis Reitter <travis reitter collabora co uk>
Date: Sun Oct 9 16:39:52 2011 -0700
Support UrlDetails for the Telepathy backend.
NEWS | 1 +
backends/telepathy/lib/tpf-persona.vala | 54 +++++++++++++++++++-
tests/lib/telepathy/contactlist/conn.c | 7 +++
.../telepathy/contactlist/contact-list-manager.c | 5 ++
tests/telepathy/individual-properties.vala | 37 +++++++++++++
5 files changed, 103 insertions(+), 1 deletions(-)
---
diff --git a/NEWS b/NEWS
index 49dd758..e4a79cf 100644
--- a/NEWS
+++ b/NEWS
@@ -10,6 +10,7 @@ API changes:
* Implement PhoneDetails on Tpf.Persona
* Implement NameDetails on Tpf.Persona
* Implement EmailDetails on Tpf.Persona
+* Implement UrlDetails on Tpf.Persona
Overview of changes from libfolks 0.6.3.1 to libfolks 0.6.3.2
=============================================================
diff --git a/backends/telepathy/lib/tpf-persona.vala b/backends/telepathy/lib/tpf-persona.vala
index 074e952..d822793 100644
--- a/backends/telepathy/lib/tpf-persona.vala
+++ b/backends/telepathy/lib/tpf-persona.vala
@@ -36,7 +36,8 @@ public class Tpf.Persona : Folks.Persona,
ImDetails,
NameDetails,
PhoneDetails,
- PresenceDetails
+ PresenceDetails,
+ UrlDetails
{
private HashSet<string> _groups;
private Set<string> _groups_ro;
@@ -423,6 +424,32 @@ public class Tpf.Persona : Folks.Persona,
this._phone_numbers, "tel");
}
+ private HashSet<UrlFieldDetails> _urls;
+ private Set<UrlFieldDetails> _urls_ro;
+
+ /**
+ * { inheritDoc}
+ *
+ * @since UNRELEASED
+ */
+ [CCode (notify = false)]
+ public Set<UrlFieldDetails> urls
+ {
+ get { return this._urls_ro; }
+ set { this.change_urls.begin (value); }
+ }
+
+ /**
+ * { inheritDoc}
+ *
+ * @since UNRELEASED
+ */
+ public async void change_urls (Set<UrlFieldDetails> urls) throws PropertyError
+ {
+ yield this._change_details<UrlFieldDetails> (urls,
+ this._urls, "url");
+ }
+
private async void _change_details<T> (
Set<AbstractFieldDetails<string>> details,
Set<AbstractFieldDetails<string>> member_set,
@@ -538,6 +565,10 @@ public class Tpf.Persona : Folks.Persona,
(GLib.HashFunc) PhoneFieldDetails.hash,
(GLib.EqualFunc) PhoneFieldDetails.equal);
this._phone_numbers_ro = this._phone_numbers.read_only_view;
+ this._urls = new HashSet<UrlFieldDetails> (
+ (GLib.HashFunc) UrlFieldDetails.hash,
+ (GLib.EqualFunc) UrlFieldDetails.equal);
+ this._urls_ro = this._urls.read_only_view;
contact.notify["avatar-file"].connect ((s, p) =>
{
@@ -614,6 +645,8 @@ public class Tpf.Persona : Folks.Persona,
this._writeable_properties += "full-name";
if ("tel" in tpf_store.supported_fields)
this._writeable_properties += "phone-numbers";
+ if ("url" in tpf_store.supported_fields)
+ this._writeable_properties += "urls";
}
private void _contact_notify_contact_info ()
@@ -625,6 +658,9 @@ public class Tpf.Persona : Folks.Persona,
var new_phone_numbers = new HashSet<PhoneFieldDetails> (
(GLib.HashFunc) PhoneFieldDetails.hash,
(GLib.EqualFunc) PhoneFieldDetails.equal);
+ var new_urls = new HashSet<UrlFieldDetails> (
+ (GLib.HashFunc) UrlFieldDetails.hash,
+ (GLib.EqualFunc) UrlFieldDetails.equal);
var contact_info = this.contact.get_contact_info ();
foreach (var info in contact_info)
@@ -652,6 +688,15 @@ public class Tpf.Persona : Folks.Persona,
new_phone_numbers.add (phone_fd);
}
}
+ else if (info.field_name == "url")
+ {
+ foreach (var url in info.field_value)
+ {
+ var parameters = this._afd_params_from_strv (info.parameters);
+ var url_fd = new UrlFieldDetails (url, parameters);
+ new_urls.add (url_fd);
+ }
+ }
}
if (!Folks.Internal.equal_sets<EmailFieldDetails> (new_email_addresses,
@@ -675,6 +720,13 @@ public class Tpf.Persona : Folks.Persona,
this._phone_numbers_ro = new_phone_numbers.read_only_view;
this.notify_property ("phone-numbers");
}
+
+ if (!Folks.Internal.equal_sets<UrlFieldDetails> (new_urls, this._urls))
+ {
+ this._urls = new_urls;
+ this._urls_ro = new_urls.read_only_view;
+ this.notify_property ("urls");
+ }
}
private MultiMap<string, string> _afd_params_from_strv (string[] parameters)
diff --git a/tests/lib/telepathy/contactlist/conn.c b/tests/lib/telepathy/contactlist/conn.c
index 6ee114c..55b4d4f 100644
--- a/tests/lib/telepathy/contactlist/conn.c
+++ b/tests/lib/telepathy/contactlist/conn.c
@@ -430,6 +430,13 @@ conn_contact_info_properties_getter (GObject *object,
G_TYPE_UINT, 0,
G_TYPE_UINT, G_MAXUINT32,
G_TYPE_INVALID));
+
+ g_ptr_array_add (supported_fields, tp_value_array_build (4,
+ G_TYPE_STRING, "url",
+ G_TYPE_STRV, NULL,
+ G_TYPE_UINT, 0,
+ G_TYPE_UINT, G_MAXUINT32,
+ G_TYPE_INVALID));
}
g_value_set_boxed (value, supported_fields);
}
diff --git a/tests/lib/telepathy/contactlist/contact-list-manager.c b/tests/lib/telepathy/contactlist/contact-list-manager.c
index 5627989..65e6d18 100644
--- a/tests/lib/telepathy/contactlist/contact-list-manager.c
+++ b/tests/lib/telepathy/contactlist/contact-list-manager.c
@@ -527,6 +527,11 @@ receive_contact_lists (gpointer p)
_insert_contact_field (d->contact_info, "email", NULL,
(const gchar * const *) values);
}
+ {
+ const gchar * values[] = { "ocrete.example.com", NULL };
+ _insert_contact_field (d->contact_info, "url", NULL,
+ (const gchar * const *) values);
+ }
tp_handle_unref (self->priv->contact_repo, handle);
id = "travis example com";
diff --git a/tests/telepathy/individual-properties.vala b/tests/telepathy/individual-properties.vala
index ab63b8c..74091dc 100644
--- a/tests/telepathy/individual-properties.vala
+++ b/tests/telepathy/individual-properties.vala
@@ -113,6 +113,7 @@ public class IndividualPropertiesTests : Folks.TestCase
assert (("full-name" in tpf_persona.writeable_properties));
assert (
("phone-numbers" in tpf_persona.writeable_properties));
+ assert ("urls" in tpf_persona.writeable_properties);
/* Check ContactInfo-provided properties */
assert (i.full_name == "");
@@ -156,6 +157,7 @@ public class IndividualPropertiesTests : Folks.TestCase
assert (!("full-name" in tpf_persona.writeable_properties));
assert (
!("phone-numbers" in tpf_persona.writeable_properties));
+ assert (!("urls" in tpf_persona.writeable_properties));
/* Check ContactInfo-provided properties */
assert (new PhoneFieldDetails ("+15142345678")
@@ -163,6 +165,7 @@ public class IndividualPropertiesTests : Folks.TestCase
assert (i.full_name == "Olivier Crete");
assert (new EmailFieldDetails ("olivier example com")
in i.email_addresses);
+ assert (new UrlFieldDetails ("ocrete.example.com") in i.urls);
}
}
@@ -355,6 +358,7 @@ public class IndividualPropertiesTests : Folks.TestCase
this._changes_pending.add ("email-addresses");
this._changes_pending.add ("phone-numbers");
this._changes_pending.add ("full-name");
+ this._changes_pending.add ("urls");
/* Set up the aggregator */
var aggregator = new IndividualAggregator ();
@@ -394,6 +398,9 @@ public class IndividualPropertiesTests : Folks.TestCase
var new_phone_fd = new PhoneFieldDetails ("+112233445566");
new_phone_fd.set_parameter (AbstractFieldDetails.PARAM_TYPE,
AbstractFieldDetails.PARAM_TYPE_HOME);
+ var new_url_fd = new UrlFieldDetails ("aperturescience.com/cave");
+ new_url_fd.set_parameter (AbstractFieldDetails.PARAM_TYPE,
+ AbstractFieldDetails.PARAM_TYPE_WORK);
var new_full_name = "Cave Johnson";
foreach (Individual i in added)
@@ -404,6 +411,7 @@ public class IndividualPropertiesTests : Folks.TestCase
assert (!(new_email_fd in i.email_addresses));
assert (new_full_name != i.full_name);
assert (!(new_phone_fd in i.phone_numbers));
+ assert (!(new_url_fd in i.urls));
i.notify["email-addresses"].connect ((s, p) =>
{
@@ -436,6 +444,17 @@ public class IndividualPropertiesTests : Folks.TestCase
}
});
+ i.notify["urls"].connect ((s, p) =>
+ {
+ /* we can't re-use i here due to Vala's implementation */
+ var ind = (Individual) s;
+
+ if (new_url_fd in ind.urls)
+ {
+ this._changes_pending.remove ("urls");
+ }
+ });
+
/* the contact list this aggregator is based upon has exactly 1
* Tpf.Persona per Individual */
Folks.Persona persona = null;
@@ -454,6 +473,10 @@ public class IndividualPropertiesTests : Folks.TestCase
(GLib.HashFunc) PhoneFieldDetails.hash,
(GLib.EqualFunc) PhoneFieldDetails.equal);
phones.add (new_phone_fd);
+ var urls = new HashSet<UrlFieldDetails> (
+ (GLib.HashFunc) UrlFieldDetails.hash,
+ (GLib.EqualFunc) UrlFieldDetails.equal);
+ urls.add (new_url_fd);
/* set the extended info through Telepathy's ContactInfo interface and
* wait for it to hit our notification callback above */
@@ -504,6 +527,20 @@ public class IndividualPropertiesTests : Folks.TestCase
}
if (!i.is_user)
+ uncaught_errors++;
+ try
+ {
+ yield ((Tpf.Persona) persona).change_urls (urls);
+ }
+ catch (PropertyError e3)
+ {
+ /* setting the extended info on a non-user is invalid for the
+ * Telepathy backend */
+ if (!i.is_user)
+ uncaught_errors--;
+ }
+
+ if (!i.is_user)
{
assert (uncaught_errors == 0);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]