[gnome-contacts] Support show contact by email



commit c2954dcde016cf4d9ec08e611c1caaae4330bdbe
Author: Alexander Larsson <alexl redhat com>
Date:   Tue Aug 9 12:54:54 2011 +0200

    Support show contact by email

 src/contacts-app.vala     |   28 ++++++++++++++++++++++++++++
 src/contacts-contact.vala |    9 +++++++++
 src/contacts-store.vala   |    8 ++++++++
 src/main.vala             |    5 +++++
 4 files changed, 50 insertions(+), 0 deletions(-)
---
diff --git a/src/contacts-app.vala b/src/contacts-app.vala
index 693802f..375a3a8 100644
--- a/src/contacts-app.vala
+++ b/src/contacts-app.vala
@@ -69,6 +69,34 @@ public class Contacts.App : Window {
     }
   }
 
+  private string show_email = null;
+  private void show_email_cb (Contact contact) {
+    if (contact.has_email (show_email)) {
+      show_email = null;
+      contacts_store.changed.disconnect (show_email_cb);
+      contacts_store.added.disconnect (show_email_cb);
+
+      list_pane.select_contact (contact);
+      contacts_pane.show_contact (contact);
+    }
+  }
+
+  public void show_by_email (string email) {
+    var contact = contacts_store.find_contact_with_email (email);
+    if (contact != null) {
+      list_pane.select_contact (contact);
+      contacts_pane.show_contact (contact);
+    } else {
+      if (show_email == null) {
+	contacts_store.changed.connect (show_email_cb);
+	contacts_store.added.connect (show_email_cb);
+
+	// TODO: Wait for quiescent state to detect no such contact
+      }
+      show_email = email;
+    }
+  }
+
   public App () {
     this.app = this;
     set_title (_("Contacts"));
diff --git a/src/contacts-contact.vala b/src/contacts-contact.vala
index ea5b8d6..32ba35c 100644
--- a/src/contacts-contact.vala
+++ b/src/contacts-contact.vala
@@ -187,6 +187,15 @@ public class Contacts.Contact : GLib.Object  {
     individual.notify.disconnect(notify_cb);
   }
 
+  public bool has_email (string email_address) {
+    var addrs = individual.email_addresses;
+    foreach (var detail in addrs) {
+      if (detail.value == email_address)
+	return true;
+    }
+    return false;
+  }
+
   public bool contains_strings (string [] strings) {
     foreach (string i in strings) {
       if (! (i in filter_data))
diff --git a/src/contacts-store.vala b/src/contacts-store.vala
index 2304be9..9891a53 100644
--- a/src/contacts-store.vala
+++ b/src/contacts-store.vala
@@ -238,6 +238,14 @@ public class Contacts.Store  {
     return null;
   }
 
+  public Contact? find_contact_with_email (string email_address) {
+    foreach (var data in contacts) {
+      if (data.contact.has_email (email_address))
+	return data.contact;
+    }
+    return null;
+  }
+
   public Contact? find_contact_with_persona (Persona persona) {
     foreach (var data in contacts) {
       if (data.contact.individual.personas.contains (persona))
diff --git a/src/main.vala b/src/main.vala
index 89dd454..e35dfa4 100644
--- a/src/main.vala
+++ b/src/main.vala
@@ -22,9 +22,12 @@ using Contacts;
 
 
 private static string individual_id = null;
+private static string email_address = null;
 private static const OptionEntry[] options = {
     { "individual", 'i', 0, OptionArg.STRING, ref individual_id,
       N_("Show contact with this individual id"), null },
+    { "email", 'e', 0, OptionArg.STRING, ref email_address,
+      N_("Show contact with this email address"), null },
     { null }
   };
 
@@ -48,6 +51,8 @@ main (string[] args) {
   var app = new App ();
   if (individual_id != null)
     app.show_individual (individual_id);
+  if (email_address != null)
+    app.show_by_email (email_address);
   app.show ();
 
   Gtk.main ();



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