[folks] core: Add WebServiceDetails.change_web_service_addresses()
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [folks] core: Add WebServiceDetails.change_web_service_addresses()
- Date: Fri, 2 Sep 2011 18:32:02 +0000 (UTC)
commit 6dd4365dbbc2fd317f1fb6287d9a1b1d6d765e77
Author: Philip Withnall <philip tecnocode co uk>
Date: Tue Aug 30 20:34:32 2011 +0100
core: Add WebServiceDetails.change_web_service_addresses()
This allows the web service addresses of an implementing class to be changed
asynchronously with proper error notification.
Helps: bgo#657510
backends/eds/lib/edsf-persona-store.vala | 4 +-
backends/eds/lib/edsf-persona.vala | 19 +++++--
backends/key-file/kf-persona.vala | 83 +++++++++++++++------------
backends/libsocialweb/lib/swf-persona.vala | 6 +-
backends/tracker/lib/trf-persona.vala | 19 +++++-
folks/individual.vala | 4 +-
folks/web-service-details.vala | 23 ++++++++
po/POTFILES.in | 1 +
po/POTFILES.skip | 1 +
9 files changed, 110 insertions(+), 50 deletions(-)
---
diff --git a/backends/eds/lib/edsf-persona-store.vala b/backends/eds/lib/edsf-persona-store.vala
index 54f08e4..9cf9274 100644
--- a/backends/eds/lib/edsf-persona-store.vala
+++ b/backends/eds/lib/edsf-persona-store.vala
@@ -718,6 +718,7 @@ public class Edsf.PersonaStore : Folks.PersonaStore
internal async void _set_web_service_addresses (Edsf.Persona persona,
MultiMap<string, WebServiceFieldDetails> web_service_addresses)
+ throws PropertyError
{
if (Utils.multi_map_str_afd_equal (persona.web_service_addresses,
web_service_addresses))
@@ -732,7 +733,8 @@ public class Edsf.PersonaStore : Folks.PersonaStore
}
catch (GLib.Error e)
{
- GLib.warning ("Can't set local IDS: %s\n", e.message);
+ throw this.e_client_error_to_property_error ("web-service-addresses",
+ e);
}
}
diff --git a/backends/eds/lib/edsf-persona.vala b/backends/eds/lib/edsf-persona.vala
index 04e4d24..e7ed2ed 100644
--- a/backends/eds/lib/edsf-persona.vala
+++ b/backends/eds/lib/edsf-persona.vala
@@ -146,11 +146,20 @@ public class Edsf.Persona : Folks.Persona,
public MultiMap<string, WebServiceFieldDetails> web_service_addresses
{
get { return this._web_service_addresses; }
- set
- {
- var store = (Edsf.PersonaStore) this.store;
- store._set_web_service_addresses (this, value);
- }
+ set { this.change_web_service_addresses.begin (value); }
+ }
+
+ /**
+ * { inheritDoc}
+ *
+ * @since UNRELEASED
+ */
+ public async void change_web_service_addresses (
+ MultiMap<string, WebServiceFieldDetails> web_service_addresses)
+ throws PropertyError
+ {
+ yield ((Edsf.PersonaStore) this.store)._set_web_service_addresses (this,
+ web_service_addresses);
}
/**
diff --git a/backends/key-file/kf-persona.vala b/backends/key-file/kf-persona.vala
index 11622b8..0a70b79 100644
--- a/backends/key-file/kf-persona.vala
+++ b/backends/key-file/kf-persona.vala
@@ -185,56 +185,65 @@ public class Folks.Backends.Kf.Persona : Folks.Persona,
/**
* { inheritDoc}
*/
+ [CCode (notify = false)]
public MultiMap<string, WebServiceFieldDetails> web_service_addresses
{
- get
- { return this._web_service_addresses; }
+ get { return this._web_service_addresses; }
+ set { this.change_web_service_addresses.begin (value); }
+ }
- set
+ /**
+ * { inheritDoc}
+ *
+ * @since UNRELEASED
+ */
+ public async void change_web_service_addresses (
+ MultiMap<string, WebServiceFieldDetails> web_service_addresses)
+ throws PropertyError
+ {
+ /* Remove the current web service addresses from the key file */
+ foreach (var web_service1 in this._web_service_addresses.get_keys ())
{
- /* Remove the current web service addresses from the key file */
- foreach (var web_service in this._web_service_addresses.get_keys ())
+ try
{
- try
- {
- this._key_file.remove_key (this.display_id,
- "web-service." + web_service);
- }
- catch (KeyFileError e)
- {
- /* Ignore the error, since it's just a group or key not found
- * error. */
- }
+ this._key_file.remove_key (this.display_id,
+ "web-service." + web_service1);
}
-
- /* Add the new web service addresses to the key file and build a
- * table of them to set as the new property value */
- var web_service_addresses =
- new HashMultiMap<string, WebServiceFieldDetails> (
- null, null,
- (GLib.HashFunc) WebServiceFieldDetails.hash,
- (GLib.EqualFunc) WebServiceFieldDetails.equal);
-
- foreach (var web_service in value.get_keys ())
+ catch (KeyFileError e)
{
- var ws_fds = value.get (web_service);
+ /* Ignore the error, since it's just a group or key not found
+ * error. */
+ }
+ }
- string[] addrs = new string[0];
- foreach (var ws_fd in ws_fds)
- addrs += ws_fd.value;
+ /* Add the new web service addresses to the key file and build a
+ * table of them to set as the new property value */
+ var new_web_service_addresses =
+ new HashMultiMap<string, WebServiceFieldDetails> (
+ null, null,
+ (GLib.HashFunc) WebServiceFieldDetails.hash,
+ (GLib.EqualFunc) WebServiceFieldDetails.equal);
- this._key_file.set_string_list (this.display_id,
- "web-service." + web_service, addrs);
+ foreach (var web_service2 in web_service_addresses.get_keys ())
+ {
+ var ws_fds = web_service_addresses.get (web_service2);
- foreach (var ws_fd in ws_fds)
- web_service_addresses.set (web_service, ws_fd);
- }
+ string[] addrs = new string[0];
+ foreach (var ws_fd1 in ws_fds)
+ addrs += ws_fd1.value;
- this._web_service_addresses = web_service_addresses;
+ this._key_file.set_string_list (this.display_id,
+ "web-service." + web_service2, addrs);
- /* Get the PersonaStore to save the key file */
- ((Kf.PersonaStore) this.store).save_key_file.begin ();
+ foreach (var ws_fd2 in ws_fds)
+ new_web_service_addresses.set (web_service2, ws_fd2);
}
+
+ /* Get the PersonaStore to save the key file */
+ yield ((Kf.PersonaStore) this.store).save_key_file ();
+
+ this._web_service_addresses = new_web_service_addresses;
+ this.notify_property ("web-service-addresses");
}
/**
diff --git a/backends/libsocialweb/lib/swf-persona.vala b/backends/libsocialweb/lib/swf-persona.vala
index b2dc631..0778a45 100644
--- a/backends/libsocialweb/lib/swf-persona.vala
+++ b/backends/libsocialweb/lib/swf-persona.vala
@@ -169,10 +169,12 @@ public class Swf.Persona : Folks.Persona,
/**
* { inheritDoc}
*/
- public MultiMap<string, string> web_service_addresses
+ [CCode (notify = false)]
+ public MultiMap<string, WebServiceFieldDetails> web_service_addresses
{
get { return this._web_service_addresses; }
- private set {}
+ /* Not writeable: */
+ set { this.change_web_service_addresses.begin (value); }
}
private Contact _lsw_contact;
diff --git a/backends/tracker/lib/trf-persona.vala b/backends/tracker/lib/trf-persona.vala
index a3c552d..0f567e3 100644
--- a/backends/tracker/lib/trf-persona.vala
+++ b/backends/tracker/lib/trf-persona.vala
@@ -474,13 +474,24 @@ public class Trf.Persona : Folks.Persona,
/**
* { inheritDoc}
*/
+ [CCode (notify = false)]
public MultiMap<string, WebServiceFieldDetails> web_service_addresses
{
get { return this._web_service_addresses; }
- set
- {
- ((Trf.PersonaStore) this.store)._set_web_service_addrs (this, value);
- }
+ set { this.change_web_service_addresses.begin (value); }
+ }
+
+ /**
+ * { inheritDoc}
+ *
+ * @since UNRELEASED
+ */
+ public async void change_web_service_addresses (
+ MultiMap<string, WebServiceFieldDetails> web_service_addresses)
+ throws PropertyError
+ {
+ yield ((Trf.PersonaStore) this.store)._set_web_service_addrs (this,
+ web_service_addresses);
}
/**
diff --git a/folks/individual.vala b/folks/individual.vala
index 0e1617a..9a2f212 100644
--- a/folks/individual.vala
+++ b/folks/individual.vala
@@ -592,10 +592,12 @@ public class Folks.Individual : Object,
/**
* { inheritDoc}
*/
+ [CCode (notify = false)]
public MultiMap<string, WebServiceFieldDetails> web_service_addresses
{
get { return this._web_service_addresses; }
- private set {}
+ /* Not writeable: */
+ set { this.change_web_service_addresses.begin (value); }
}
/**
diff --git a/folks/web-service-details.vala b/folks/web-service-details.vala
index 66b41b8..6a245b5 100644
--- a/folks/web-service-details.vala
+++ b/folks/web-service-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
@@ -16,6 +17,7 @@
*
* Authors:
* Alban Crequy <alban crequy collabora co uk>
+ * Philip Withnall <philip tecnocode co uk>
*/
using Gee;
@@ -94,4 +96,25 @@ public interface Folks.WebServiceDetails : Object
{
get; set;
}
+
+ /**
+ * Change the contact's web service addresses.
+ *
+ * It's preferred to call this rather than setting
+ * { link WebServiceDetails.web_service_addresses} directly, as this method
+ * gives error notification and will only return once the addresses have been
+ * written to the relevant backing store (or the operation's failed).
+ *
+ * @param web_service_addresses the set of addresses
+ * @throws PropertyError if setting the addresses failed
+ * @since UNRELEASED
+ */
+ public virtual async void change_web_service_addresses (
+ MultiMap<string, WebServiceFieldDetails> web_service_addresses)
+ throws PropertyError
+ {
+ /* Default implementation. */
+ throw new PropertyError.NOT_WRITEABLE (
+ _("Web service addresses are not writeable on this contact."));
+ }
}
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 0e67040..390b0b9 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -23,5 +23,6 @@ folks/phone-details.vala
folks/postal-address-details.vala
folks/role-details.vala
folks/url-details.vala
+folks/web-service-details.vala
tools/import-pidgin.vala
tools/import.vala
diff --git a/po/POTFILES.skip b/po/POTFILES.skip
index 821d3ab..16bf20d 100644
--- a/po/POTFILES.skip
+++ b/po/POTFILES.skip
@@ -22,5 +22,6 @@ folks/phone-details.c
folks/postal-address-details.c
folks/role-details.c
folks/url-details.c
+folks/web-service-details.c
tools/import-pidgin.c
tools/import.c
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]