Commit 6dd4365d authored by Philip Withnall's avatar Philip Withnall
Browse files

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
parent a8f586f2
......@@ -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);
}
}
......
......@@ -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);
}
/**
......
......@@ -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");
}
/**
......
......@@ -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;
......
......@@ -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);
}
/**
......
......@@ -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); }
}
/**
......
/*
* 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."));
}
}
......@@ -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
......@@ -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
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment