[gnome-contacts] Added handling of single-value details on Contact.



commit 86418c8e573f8ff8e6a601f85f6117dcce038318
Author: Erick PÃrez Castellanos <erick red gmail com>
Date:   Mon Dec 17 08:07:03 2012 -0500

    Added handling of single-value details on Contact.
    
    This handles every main persona has just one birthday field, one nickname
    and one notes field.
    The notes case, I don't undertsand pretty well yet, so the code is little
    bit ugly. It does work, though.

 src/contacts-contact-pane.vala |   39 +++++++++++++++++++++++++++++----------
 src/contacts-contact.vala      |   24 ++++++++++++++++++++++++
 2 files changed, 53 insertions(+), 10 deletions(-)
---
diff --git a/src/contacts-contact-pane.vala b/src/contacts-contact-pane.vala
index 6df948d..7acbc88 100644
--- a/src/contacts-contact-pane.vala
+++ b/src/contacts-contact-pane.vala
@@ -56,6 +56,11 @@ public class Contacts.ContactPane : Grid {
   private Revealer edit_revealer;
   private ContactEditor editor;
 
+  /* single value details */
+  private Gtk.MenuItem nickname_item;
+  private Gtk.MenuItem birthday_item;
+  private Gtk.MenuItem notes_item;
+
   private Grid no_selection_grid;
 
   public Grid suggestion_grid;
@@ -312,15 +317,14 @@ public class Contacts.ContactPane : Grid {
     item.activate.connect (() => {
 	editor.add_new_row_for_property (contact.find_primary_persona (), "urls");
       });
-    /* FIXME: There's only one nickname allowed, per individual */
-    item = new Gtk.MenuItem.with_label (_("Nickname"));
-    details_menu.append (item);
-    item.activate.connect (() => {
+    nickname_item = new Gtk.MenuItem.with_label (_("Nickname"));
+    details_menu.append (nickname_item);
+    nickname_item.activate.connect (() => {
 	editor.add_new_row_for_property (contact.find_primary_persona (), "nickname");
       });
-    item = new Gtk.MenuItem.with_label (_("Birthday"));
-    details_menu.append (item);
-    item.activate.connect (() => {
+    birthday_item = new Gtk.MenuItem.with_label (_("Birthday"));
+    details_menu.append (birthday_item);
+    birthday_item.activate.connect (() => {
 	editor.add_new_row_for_property (contact.find_primary_persona (), "birthday");
       });
     item = new Gtk.MenuItem.with_label (_("Address"));
@@ -328,9 +332,9 @@ public class Contacts.ContactPane : Grid {
     item.activate.connect (() => {
 	editor.add_new_row_for_property (contact.find_primary_persona (), "postal-address");
       });
-    item = new Gtk.MenuItem.with_label (_("Notes"));
-    details_menu.append (item);
-    item.activate.connect (() => {
+    notes_item = new Gtk.MenuItem.with_label (_("Notes"));
+    details_menu.append (notes_item);
+    notes_item.activate.connect (() => {
 	editor.add_new_row_for_property (contact.find_primary_persona (), "notes");
       });
     details_menu.show_all ();
@@ -400,6 +404,21 @@ public class Contacts.ContactPane : Grid {
     if (on_edit) {
       on_edit_mode = true;
 
+      if (contact.has_birthday ())
+	birthday_item.hide ();
+      else
+	birthday_item.show ();
+
+      if (contact.has_nickname ())
+	nickname_item.hide ();
+      else
+	nickname_item.show ();
+
+      if (contact.has_notes ())
+	notes_item.hide ();
+      else
+	notes_item.show ();
+
       edit_revealer.reveal ();
 
       sheet.clear ();
diff --git a/src/contacts-contact.vala b/src/contacts-contact.vala
index 3f873fe..fcd7e85 100644
--- a/src/contacts-contact.vala
+++ b/src/contacts-contact.vala
@@ -497,6 +497,30 @@ public class Contacts.Contact : GLib.Object  {
     return false;
   }
 
+  public bool has_birthday () {
+    return individual.birthday != null;
+  }
+
+  public bool has_nickname () {
+    return individual.nickname != null &&
+           individual.nickname != "";
+  }
+
+  public bool has_notes () {
+    bool has_notes = false;
+
+    foreach (var p in get_personas_for_display ()) {
+      var note_details = p as NoteDetails;
+      if (note_details != null) {
+	foreach (var note in note_details.notes) {
+	  if (note.value != "")
+	    return true;
+	}
+      }
+    }
+    return false;
+  }
+
   public bool contains_strings (string [] strings) {
     foreach (string i in strings) {
       if (! (i in filter_data))



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]