[gnome-contacts] Add a multi-value back reference from Contact
- From: Alexander Larsson <alexl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-contacts] Add a multi-value back reference from Contact
- Date: Wed, 17 Aug 2011 15:47:45 +0000 (UTC)
commit 152dcd845a4bea879d35dbb2ae662366237cd389
Author: Alexander Larsson <alexl redhat com>
Date: Wed Aug 17 10:39:32 2011 +0200
Add a multi-value back reference from Contact
This is used to get the ContactData from the contact in the store,
allowing us to use the same contact in multiple stores.
src/contacts-contact.vala | 35 +++++++++++++++++++++++++++++++++++
src/contacts-store.vala | 7 +++----
2 files changed, 38 insertions(+), 4 deletions(-)
---
diff --git a/src/contacts-contact.vala b/src/contacts-contact.vala
index f1bde99..ec0a1a7 100644
--- a/src/contacts-contact.vala
+++ b/src/contacts-contact.vala
@@ -106,6 +106,11 @@ public class Contacts.Contact : GLib.Object {
public PresenceType presence_type;
public string presence_message;
public bool is_phone;
+ struct ContactDataRef {
+ void *key;
+ void *data;
+ }
+ private ContactDataRef[] refs;
static Gdk.Pixbuf fallback_avatar;
@@ -178,10 +183,40 @@ public class Contacts.Contact : GLib.Object {
SignalHandler.disconnect_by_func (tp.contact, (void *)persona_notify_cb, this);
}
+ public void *lookup (void *key) {
+ foreach (var data_ref in refs) {
+ if (data_ref.key == key)
+ return data_ref.data;
+ }
+ return null;
+ }
+
+ public void set_lookup (void *key, void *data) {
+ int i = refs.length;
+ refs.resize(i+1);
+ refs[i].key = key;
+ refs[i].data = data;
+ }
+
+ public void remove_lookup (void *key) {
+ int i;
+
+ for (i = 0; i < refs.length; i++) {
+ if (refs[i].key == key) {
+ for (int j = i + 1; j < refs.length; j++) {
+ refs[j-1] = refs[j];
+ }
+ refs.resize(refs.length-1);
+ return;
+ }
+ }
+ }
+
public Contact (Store store, Individual i) {
this.store = store;
individual = i;
individual.set_data ("contact", this);
+ this.refs = new ContactDataRef[0];
foreach (var p in individual.personas)
connect_persona (p);
diff --git a/src/contacts-store.vala b/src/contacts-store.vala
index ead5e55..e3e886e 100644
--- a/src/contacts-store.vala
+++ b/src/contacts-store.vala
@@ -221,7 +221,7 @@ public class Contacts.Store {
}
private ContactData lookup_data (Contact c) {
- return c.get_data ("contact-data");
+ return (ContactData *)c.lookup (this);
}
public bool lookup_iter (Contact c, out TreeIter iter) {
@@ -259,8 +259,7 @@ public class Contacts.Store {
data.contact = c;
data.visible = false;
- // TODO: Make this a separate hashtable to support multiple stores?
- c.set_data ("contact-data", data);
+ c.set_lookup (this, data);
contacts.add (data);
@@ -283,7 +282,7 @@ public class Contacts.Store {
contacts.set (i, contacts.get (contacts.size - 1));
contacts.remove_at (contacts.size - 1);
- c.set_data ("contact-data", null);
+ c.remove_lookup (this);
removed (c);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]