[gnome-contacts] Add initial cut at show individual id



commit b3bbb079f82600546c073aaf3718b13232a61c86
Author: Alexander Larsson <alexl redhat com>
Date:   Tue Aug 9 12:32:49 2011 +0200

    Add initial cut at show individual id

 src/contacts-app.vala       |   28 ++++++++++++++++++++++++++++
 src/contacts-list-pane.vala |    9 +++++++++
 src/contacts-store.vala     |   14 ++++++++++++++
 src/main.vala               |   12 +++++++++++-
 4 files changed, 62 insertions(+), 1 deletions(-)
---
diff --git a/src/contacts-app.vala b/src/contacts-app.vala
index 4791b72..693802f 100644
--- a/src/contacts-app.vala
+++ b/src/contacts-app.vala
@@ -41,6 +41,34 @@ public class Contacts.App : Window {
     contacts_pane.show_contact (new_selection);
   }
 
+  private string show_individual_id = null;
+  private void show_individual_cb (Contact contact) {
+    if (contact.individual.id == show_individual_id) {
+      show_individual_id = null;
+      contacts_store.changed.disconnect (show_individual_cb);
+      contacts_store.added.disconnect (show_individual_cb);
+
+      list_pane.select_contact (contact);
+      contacts_pane.show_contact (contact);
+    }
+  }
+
+  public void show_individual (string id) {
+    var contact = contacts_store.find_contact_with_id (id);
+    if (contact != null) {
+      list_pane.select_contact (contact);
+      contacts_pane.show_contact (contact);
+    } else {
+      if (show_individual_id == null) {
+	contacts_store.changed.connect (show_individual_cb);
+	contacts_store.added.connect (show_individual_cb);
+
+	// TODO: Wait for quiescent state to detect no such contact
+      }
+      show_individual_id = id;
+    }
+  }
+
   public App () {
     this.app = this;
     set_title (_("Contacts"));
diff --git a/src/contacts-list-pane.vala b/src/contacts-list-pane.vala
index f6f4227..571759b 100644
--- a/src/contacts-list-pane.vala
+++ b/src/contacts-list-pane.vala
@@ -462,4 +462,13 @@ public class Contacts.ListPane : Frame {
 
     this.show_all ();
   }
+
+  public void select_contact (Contact contact) {
+    TreeIter iter;
+    if (contacts_store.lookup_iter (contact, out iter)) {
+      contacts_tree_view.get_selection ().select_iter (iter);
+      contacts_tree_view.scroll_to_cell (contacts_store.model.get_path (iter),
+					 null, true, 0.0f, 0.0f);
+    }
+  }
 }
diff --git a/src/contacts-store.vala b/src/contacts-store.vala
index fda1971..2304be9 100644
--- a/src/contacts-store.vala
+++ b/src/contacts-store.vala
@@ -224,6 +224,20 @@ public class Contacts.Store  {
     return c.get_data ("contact-data");
   }
 
+  public bool lookup_iter (Contact c, out TreeIter iter) {
+    var data = lookup_data (c);
+    iter = data.iter;
+    return data.visible;
+  }
+
+  public Contact? find_contact_with_id (string individual_id) {
+    foreach (var data in contacts) {
+      if (data.contact.individual.id == individual_id)
+	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 ed7e274..89dd454 100644
--- a/src/main.vala
+++ b/src/main.vala
@@ -20,6 +20,14 @@
 using Gtk;
 using Contacts;
 
+
+private static string individual_id = null;
+private static const OptionEntry[] options = {
+    { "individual", 'i', 0, OptionArg.STRING, ref individual_id,
+      N_("Show contact with this individual id"), null },
+    { null }
+  };
+
 public static int
 main (string[] args) {
   Notify.init (_("Contacts"));
@@ -27,7 +35,7 @@ main (string[] args) {
   Intl.bind_textdomain_codeset (Config.GETTEXT_PACKAGE, "UTF-8");
   Intl.textdomain (Config.GETTEXT_PACKAGE);
 
-  Gtk.init (ref args);
+  Gtk.init_with_args (ref args, "â contact management", options, Config.GETTEXT_PACKAGE);
 
   try {
     var provider = new CssProvider ();
@@ -38,6 +46,8 @@ main (string[] args) {
   }
 
   var app = new App ();
+  if (individual_id != null)
+    app.show_individual (individual_id);
   app.show ();
 
   Gtk.main ();



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