[folks] core: Add RoleDetails.change_roles()
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [folks] core: Add RoleDetails.change_roles()
- Date: Fri, 2 Sep 2011 18:31:47 +0000 (UTC)
commit 418a2f2338d131769f80b3d264b3b015c785114e
Author: Philip Withnall <philip tecnocode co uk>
Date: Tue Aug 30 20:11:53 2011 +0100
core: Add RoleDetails.change_roles()
This allows the roles of an implementing class to be changed asynchronously
with proper error notification.
Helps: bgo#657510
backends/tracker/lib/trf-persona.vala | 19 +++++++++++++++----
folks/individual.vala | 9 ++-------
folks/role-details.vala | 22 ++++++++++++++++++++++
3 files changed, 39 insertions(+), 11 deletions(-)
---
diff --git a/backends/tracker/lib/trf-persona.vala b/backends/tracker/lib/trf-persona.vala
index f3b947e..18ebf1b 100644
--- a/backends/tracker/lib/trf-persona.vala
+++ b/backends/tracker/lib/trf-persona.vala
@@ -283,13 +283,22 @@ public class Trf.Persona : Folks.Persona,
/**
* { inheritDoc}
*/
+ [CCode (notify = false)]
public Set<RoleFieldDetails> roles
{
get { return this._roles_ro; }
- public set
- {
- ((Trf.PersonaStore) this.store)._set_roles (this, value);
- }
+ set { this.change_roles.begin (value); }
+ }
+
+ /**
+ * { inheritDoc}
+ *
+ * @since UNRELEASED
+ */
+ public async void change_roles (Set<RoleFieldDetails> roles)
+ throws PropertyError
+ {
+ yield ((Trf.PersonaStore) this.store)._set_roles (this, roles);
}
private HashSet<NoteFieldDetails> _notes;
@@ -934,6 +943,8 @@ public class Trf.Persona : Folks.Persona,
this._roles = role_fds;
this._roles_ro = this._roles.read_only_view;
+
+ this.notify_property ("roles");
}
internal bool _add_role (string tracker_id, string? role, string? title, string? org)
diff --git a/folks/individual.vala b/folks/individual.vala
index e5ac6c6..6c7f64d 100644
--- a/folks/individual.vala
+++ b/folks/individual.vala
@@ -423,16 +423,11 @@ public class Folks.Individual : Object,
/**
* { inheritDoc}
*/
+ [CCode (notify = false)]
public Set<RoleFieldDetails> roles
{
get { return this._roles_ro; }
- private set
- {
- this._roles.clear ();
- foreach (var role in value)
- this._roles.add (role);
- this.notify_property ("roles");
- }
+ set { this.change_roles.begin (value); } /* not writeable */
}
private HashSet<string> _local_ids;
diff --git a/folks/role-details.vala b/folks/role-details.vala
index cccc5de..cac9f65 100644
--- a/folks/role-details.vala
+++ b/folks/role-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:
* Raul Gutierrez Segales <raul gutierrez segales collabora co uk>
* Travis Reitter <travis reitter collabora co uk>
+ * Philip Withnall <philip tecnocode co uk>
*/
using Gee;
@@ -197,4 +199,24 @@ public interface Folks.RoleDetails : Object
* @since 0.6.0
*/
public abstract Set<RoleFieldDetails> roles { get; set; }
+
+ /**
+ * Change the contact's roles.
+ *
+ * It's preferred to call this rather than setting { link RoleDetails.roles}
+ * directly, as this method gives error notification and will only return once
+ * the roles have been written to the relevant backing store (or the
+ * operation's failed).
+ *
+ * @param roles the set of roles
+ * @throws PropertyError if setting the roles failed
+ * @since UNRELEASED
+ */
+ public virtual async void change_roles (Set<RoleFieldDetails> roles)
+ throws PropertyError
+ {
+ /* Default implementation. */
+ throw new PropertyError.NOT_WRITEABLE (
+ _("Roles are not writeable on this contact."));
+ }
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]