[gnome-contacts] Implement ensure_primary_persona
- From: Alexander Larsson <alexl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-contacts] Implement ensure_primary_persona
- Date: Wed, 24 Aug 2011 21:05:03 +0000 (UTC)
commit a0732a6ed41201a2476bce6b44ccf7634159a97c
Author: Alexander Larsson <alexl redhat com>
Date: Wed Aug 24 21:00:11 2011 +0200
Implement ensure_primary_persona
src/contacts-contact-pane.vala | 5 +++--
src/contacts-contact.vala | 28 ++++++++++++++++++++++++----
2 files changed, 27 insertions(+), 6 deletions(-)
---
diff --git a/src/contacts-contact-pane.vala b/src/contacts-contact-pane.vala
index a39b793..53f548a 100644
--- a/src/contacts-contact-pane.vala
+++ b/src/contacts-contact-pane.vala
@@ -727,9 +727,10 @@ public class Contacts.ContactPane : EventBox {
if (modified) {
if (persona == null) {
- selected_contact.ensure_writable_persona.begin ( (obj, result) => {
+ var c = selected_contact;
+ c.ensure_primary_persona.begin ( (obj, result) => {
try {
- var p = selected_contact.ensure_writable_persona.end (result);
+ var p = c.ensure_primary_persona.end (result);
if (p is NoteDetails)
(p as NoteDetails).notes = notes;
else
diff --git a/src/contacts-contact.vala b/src/contacts-contact.vala
index 9d62608..3c0337e 100644
--- a/src/contacts-contact.vala
+++ b/src/contacts-contact.vala
@@ -22,7 +22,8 @@ using Folks;
using Gee;
public errordomain ContactError {
- NOT_IMPLEMENTED
+ NOT_IMPLEMENTED,
+ NO_PRIMARY
}
public class Contacts.ContactPresence : Grid {
@@ -796,12 +797,31 @@ public class Contacts.Contact : GLib.Object {
return uri;
}
- public async Persona ensure_writable_persona () throws GLib.Error {
+ public async Persona ensure_primary_persona () throws GLib.Error {
Persona? p = find_primary_persona ();
if (p != null)
return p;
- print ("new writable persona: %p\n", p);
- throw new ContactError.NOT_IMPLEMENTED ("Not implemented yet");
+
+ // There is no primary persona, so we link all the current personas
+ // together. This will create a new persona in the primary store
+ // that links all the personas together
+
+ // HACK-ATTACK:
+ // We need to create a fake persona since link_personas is a no-op
+ // for single-persona sets
+ var persona_set = new HashSet<Persona>();
+ persona_set.add_all (individual.personas);
+ var fake_persona = FakePersona.maybe_create_for (this);
+ if (fake_persona != null)
+ persona_set.add (fake_persona);
+
+ yield store.aggregator.link_personas (persona_set);
+
+ p = find_primary_persona ();
+ if (p == null)
+ throw new ContactError.NO_PRIMARY (_("Unexpected internal error: created contact was not found"));
+
+ return p;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]