[folks] core: Add NoteDetails.change_notes()
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [folks] core: Add NoteDetails.change_notes()
- Date: Fri, 2 Sep 2011 18:31:32 +0000 (UTC)
commit e0a2bd2e7abddf6e47d78809ba45caab62099de9
Author: Philip Withnall <philip tecnocode co uk>
Date: Tue Aug 30 19:47:26 2011 +0100
core: Add NoteDetails.change_notes()
This allows the notes 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 | 16 ++++++++++++----
backends/tracker/lib/trf-persona.vala | 17 +++++++++++++----
folks/individual.vala | 9 ++-------
folks/note-details.vala | 22 ++++++++++++++++++++++
po/POTFILES.in | 1 +
po/POTFILES.skip | 1 +
7 files changed, 54 insertions(+), 18 deletions(-)
---
diff --git a/backends/eds/lib/edsf-persona-store.vala b/backends/eds/lib/edsf-persona-store.vala
index 53b432d..2017035 100644
--- a/backends/eds/lib/edsf-persona-store.vala
+++ b/backends/eds/lib/edsf-persona-store.vala
@@ -1066,7 +1066,7 @@ public class Edsf.PersonaStore : Folks.PersonaStore
}
internal async void _set_notes (Edsf.Persona persona,
- Set<NoteFieldDetails> notes)
+ Set<NoteFieldDetails> notes) throws PropertyError
{
try
{
@@ -1074,9 +1074,9 @@ public class Edsf.PersonaStore : Folks.PersonaStore
yield this._set_contact_notes (contact, notes);
yield this._addressbook.modify_contact (contact, null);
}
- catch (GLib.Error error)
+ catch (GLib.Error e)
{
- GLib.warning ("Can't update notes: %s\n", error.message);
+ throw this.e_client_error_to_property_error ("notes", e);
}
}
diff --git a/backends/eds/lib/edsf-persona.vala b/backends/eds/lib/edsf-persona.vala
index bb8470f..9efbc5b 100644
--- a/backends/eds/lib/edsf-persona.vala
+++ b/backends/eds/lib/edsf-persona.vala
@@ -246,10 +246,18 @@ public class Edsf.Persona : Folks.Persona,
public Set<NoteFieldDetails> notes
{
get { return this._notes_ro; }
- set
- {
- ((Edsf.PersonaStore) this.store)._set_notes (this, value);
- }
+ set { this.change_notes.begin (value); }
+ }
+
+ /**
+ * { inheritDoc}
+ *
+ * @since UNRELEASED
+ */
+ public async void change_notes (Set<NoteFieldDetails> notes)
+ throws PropertyError
+ {
+ yield ((Edsf.PersonaStore) this.store)._set_notes (this, notes);
}
/**
diff --git a/backends/tracker/lib/trf-persona.vala b/backends/tracker/lib/trf-persona.vala
index 12c0745..2da08f3 100644
--- a/backends/tracker/lib/trf-persona.vala
+++ b/backends/tracker/lib/trf-persona.vala
@@ -289,13 +289,22 @@ public class Trf.Persona : Folks.Persona,
/**
* { inheritDoc}
*/
+ [CCode (notify = false)]
public Set<NoteFieldDetails> notes
{
get { return this._notes_ro; }
- set
- {
- ((Trf.PersonaStore) this.store)._set_notes (this, value);
- }
+ set { this.change_notes.begin (value); }
+ }
+
+ /**
+ * { inheritDoc}
+ *
+ * @since UNRELEASED
+ */
+ public async void change_notes (Set<NoteFieldDetails> notes)
+ throws PropertyError
+ {
+ yield ((Trf.PersonaStore) this.store)._set_notes (this, notes);
}
private HashSet<UrlFieldDetails> _urls;
diff --git a/folks/individual.vala b/folks/individual.vala
index c82d04c..9c00e43 100644
--- a/folks/individual.vala
+++ b/folks/individual.vala
@@ -482,16 +482,11 @@ public class Folks.Individual : Object,
/**
* { inheritDoc}
*/
+ [CCode (notify = false)]
public Set<NoteFieldDetails> notes
{
get { return this._notes_ro; }
- private set
- {
- this._notes.clear ();
- foreach (var note in value)
- this._notes.add (note);
- this.notify_property ("notes");
- }
+ set { this.change_notes.begin (value); } /* not writeable */
}
private HashSet<PostalAddressFieldDetails> _postal_addresses;
diff --git a/folks/note-details.vala b/folks/note-details.vala
index 1ea014d..0c04106 100644
--- a/folks/note-details.vala
+++ b/folks/note-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:
* Raul Gutierrez Segales <raul gutierrez segales collabora co uk>
+ * Philip Withnall <philip tecnocode co uk>
*/
using Gee;
@@ -106,4 +108,24 @@ public interface Folks.NoteDetails : Object
* @since 0.5.1
*/
public abstract Set<NoteFieldDetails> notes { get; set; }
+
+ /**
+ * Change the contact's notes.
+ *
+ * It's preferred to call this rather than setting { link NoteDetails.notes}
+ * directly, as this method gives error notification and will only return once
+ * the notes have been written to the relevant backing store (or the
+ * operation's failed).
+ *
+ * @param notes the set of notes
+ * @throws PropertyError if setting the notes failed
+ * @since UNRELEASED
+ */
+ public virtual async void change_notes (Set<NoteFieldDetails> notes)
+ throws PropertyError
+ {
+ /* Default implementation. */
+ throw new PropertyError.NOT_WRITEABLE (
+ _("Notes are not writeable on this contact."));
+ }
}
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 7bce721..e4801ce 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -18,6 +18,7 @@ folks/im-details.vala
folks/individual-aggregator.vala
folks/local-id-details.vala
folks/name-details.vala
+folks/note-details.vala
folks/postal-address-details.vala
folks/role-details.vala
tools/import-pidgin.vala
diff --git a/po/POTFILES.skip b/po/POTFILES.skip
index 2291af2..b66348d 100644
--- a/po/POTFILES.skip
+++ b/po/POTFILES.skip
@@ -17,6 +17,7 @@ folks/im-details.c
folks/individual-aggregator.c
folks/local-id-details.c
folks/name-details.c
+folks/note-details.c
folks/postal-address-details.c
folks/role-details.c
tools/import-pidgin.c
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]