[gnome-contacts] Always pretend in the UI that every individual has a persona on the primary store
- From: Alexander Larsson <alexl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-contacts] Always pretend in the UI that every individual has a persona on the primary store
- Date: Wed, 24 Aug 2011 21:05:08 +0000 (UTC)
commit 609500978eecd68a823564998873883a3092c0e3
Author: Alexander Larsson <alexl redhat com>
Date: Wed Aug 24 21:00:47 2011 +0200
Always pretend in the UI that every individual has a persona on the primary store
This means its easy to add new fields in the UI.
Unfortunately there are some hacks in the implementation to work around issues
with the current folks API, but it seems to work for now.
src/contacts-contact-pane.vala | 35 +++++++++++++++++++++++++++++++++--
src/contacts-contact.vala | 31 +++++++++++++++++++++++++++++++
2 files changed, 64 insertions(+), 2 deletions(-)
---
diff --git a/src/contacts-contact-pane.vala b/src/contacts-contact-pane.vala
index 53f548a..ed67b26 100644
--- a/src/contacts-contact-pane.vala
+++ b/src/contacts-contact-pane.vala
@@ -361,7 +361,31 @@ public class Contacts.ContactPane : EventBox {
private void update_detail_property (string property_name,
Set<AbstractFieldDetails> detail_set) {
- editing_persona.set (property_name, detail_set);
+ var editing_backup = editing_persona;
+ if (editing_persona is FakePersona) {
+ var c = selected_contact;
+ c.ensure_primary_persona.begin ( (obj, result) => {
+ try {
+ var p = c.ensure_primary_persona.end (result);
+ p.set (property_name, detail_set);
+ /* HACK: We don't seem to get any callbacks from folks when the actual
+ * new property value is availibile, so we add a small timeout here...
+ * I'm very sorry...
+ */
+ Timeout.add (100, () => {
+ if (c == selected_contact && display_mode == DisplayMode.EDIT &&
+ editing_persona == editing_backup) {
+ display_edit (selected_contact, p, false);
+ }
+ return false;
+ });
+ } catch (Error e) {
+ warning ("Unable to create writable persona: %s", e.message);
+ }
+ });
+ } else {
+ editing_persona.set (property_name, detail_set);
+ }
}
private void update_edit_detail_type (Set<AbstractFieldDetails> detail_set,
@@ -859,8 +883,15 @@ public class Contacts.ContactPane : EventBox {
personas.set_valign (Align.END);
personas.set_vexpand (true);
+ var persona_list = new ArrayList<Persona>();
+ persona_list.add_all (contact.individual.personas);
+ var fake_persona = FakePersona.maybe_create_for (contact);
+ if (fake_persona != null)
+ persona_list.add (fake_persona);
+ // TODO Sort these personas in a stable way
+
PersonaButton button = null;
- foreach (var p in contact.individual.personas) {
+ foreach (var p in persona_list) {
button = new PersonaButton (button, p as AvatarDetails, 48);
personas.add (button);
diff --git a/src/contacts-contact.vala b/src/contacts-contact.vala
index 3c0337e..5b583cf 100644
--- a/src/contacts-contact.vala
+++ b/src/contacts-contact.vala
@@ -854,3 +854,34 @@ public class Contacts.Contact : GLib.Object {
return store.display_name;
}
}
+
+public class Contacts.FakePersona : Persona {
+ public static FakePersona? maybe_create_for (Contact contact) {
+ var primary_persona = contact.find_primary_persona ();
+
+ if (primary_persona != null)
+ return null;
+
+ return new FakePersona (contact, contact.store.aggregator.primary_store);
+ }
+
+ private const string[] _linkable_properties = {};
+ private const string[] _writeable_properties = {};
+ public override string[] linkable_properties
+ {
+ get { return this._linkable_properties; }
+ }
+
+ public override string[] writeable_properties
+ {
+ get { return this._writeable_properties; }
+ }
+
+ public FakePersona (Contact contact, PersonaStore store) {
+ Object (display_id: "display_id",
+ uid: "uid",
+ iid: "iid",
+ store: store,
+ is_user: false);
+ }
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]