[gnome-contacts/new-design] Handle personas changing
- From: Alexander Larsson <alexl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-contacts/new-design] Handle personas changing
- Date: Mon, 12 Dec 2011 15:33:28 +0000 (UTC)
commit 66e75c8cc0364f79731dd5a8a803103fcc2bf37c
Author: Alexander Larsson <alexl redhat com>
Date: Mon Dec 12 12:14:32 2011 +0100
Handle personas changing
src/contacts-contact-pane.vala | 63 ++++++++++++++++++++++++++++++++++++++--
1 files changed, 60 insertions(+), 3 deletions(-)
---
diff --git a/src/contacts-contact-pane.vala b/src/contacts-contact-pane.vala
index 47d8836..fa6f976 100644
--- a/src/contacts-contact-pane.vala
+++ b/src/contacts-contact-pane.vala
@@ -503,6 +503,7 @@ public class Contacts.PersonaSheet : Grid {
FieldRow label_row;
public abstract void populate ();
+ public abstract bool reads_param (string param);
construct {
this.set_orientation (Orientation.VERTICAL);
@@ -513,8 +514,17 @@ public class Contacts.PersonaSheet : Grid {
}
public void add_to_sheet () {
- sheet.attach (this, 0, row_nr, 1, 1);
- added = true;
+ if (!added) {
+ sheet.attach (this, 0, row_nr, 1, 1);
+ added = true;
+ }
+ }
+
+ public void remove_from_sheet () {
+ if (added) {
+ sheet.remove (this);
+ added = false;
+ }
}
public bool is_empty () {
@@ -558,6 +568,9 @@ public class Contacts.PersonaSheet : Grid {
row.right_add (button);
}
}
+ public override bool reads_param (string param) {
+ return param == "urls";
+ }
}
class EmailField : Field {
@@ -574,6 +587,9 @@ public class Contacts.PersonaSheet : Grid {
row.text_detail (email.value, TypeSet.general.format_type (email));
}
}
+ public override bool reads_param (string param) {
+ return param == "email-addresses";
+ }
}
class PhoneField : Field {
@@ -590,6 +606,9 @@ public class Contacts.PersonaSheet : Grid {
row.text_detail (phone.value, TypeSet.phone.format_type (phone));
}
}
+ public override bool reads_param (string param) {
+ return param == "phone-numbers";
+ }
}
class ChatField : Field {
@@ -612,6 +631,9 @@ public class Contacts.PersonaSheet : Grid {
}
}
}
+ public override bool reads_param (string param) {
+ return param == "im-addresses";
+ }
}
class BirthdayField : Field {
@@ -636,6 +658,9 @@ public class Contacts.PersonaSheet : Grid {
row.right_add (button);
}
}
+ public override bool reads_param (string param) {
+ return param == "birthday";
+ }
}
class NicknameField : Field {
@@ -652,6 +677,9 @@ public class Contacts.PersonaSheet : Grid {
row.text (details.nickname);
}
}
+ public override bool reads_param (string param) {
+ return param == "nickname";
+ }
}
class NoteField : Field {
@@ -668,6 +696,9 @@ public class Contacts.PersonaSheet : Grid {
row.text (note.value, true);
}
}
+ public override bool reads_param (string param) {
+ return param == "notes";
+ }
}
class AddressField : Field {
@@ -691,6 +722,9 @@ public class Contacts.PersonaSheet : Grid {
}
}
}
+ public override bool reads_param (string param) {
+ return param == "postal-addresses";
+ }
}
static Type[] field_types = {
@@ -707,7 +741,7 @@ public class Contacts.PersonaSheet : Grid {
*/
};
- Field fields[8]; // This is really the size of field_types enum
+ Field? fields[8]; // This is really the size of field_types enum
public PersonaSheet(ContactPane pane, Persona persona) {
assert (fields.length == field_types.length);
@@ -742,6 +776,7 @@ public class Contacts.PersonaSheet : Grid {
for (int i = 0; i < field_types.length; i++) {
var field = (Field) Object.new(field_types[i], sheet: this, row_nr: row_nr++);
+ fields[i] = field;
field.populate ();
if (!field.is_empty ())
@@ -758,6 +793,28 @@ public class Contacts.PersonaSheet : Grid {
footer.pack (b);
}
+ persona.notify.connect(persona_notify_cb);
+ }
+
+ ~PersonaSheet() {
+ persona.notify.disconnect(persona_notify_cb);
+ }
+
+ private void persona_notify_cb (ParamSpec pspec) {
+ var name = pspec.get_name ();
+ foreach (var field in fields) {
+ if (field.reads_param (name)) {
+ field.clear ();
+ field.populate ();
+
+ if (field.is_empty ())
+ field.remove_from_sheet ();
+ else {
+ field.show_all ();
+ field.add_to_sheet ();
+ }
+ }
+ }
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]