[gnome-contacts] Use Contacts.Store for the listview



commit 26af661ffeff67a6e4f218231cf3e012bde57e0b
Author: Alexander Larsson <alexl redhat com>
Date:   Tue May 24 10:56:05 2011 +0200

    Use Contacts.Store for the listview

 src/contacts-app.vala     |   40 ++++++++--------------------------------
 src/contacts-contact.vala |   30 +-----------------------------
 2 files changed, 9 insertions(+), 61 deletions(-)
---
diff --git a/src/contacts-app.vala b/src/contacts-app.vala
index 9e40752..861adec 100644
--- a/src/contacts-app.vala
+++ b/src/contacts-app.vala
@@ -21,12 +21,9 @@ using Gtk;
 using Folks;
 
 public class Contacts.App : Window {
-  private ContactStore contacts_store;
-  private TreeModelFilter filter_model;
+  private Store contacts_store;
   private Entry filter_entry;
   private Contact selected_contact;
-  string []? filter_values;
-  bool filter_favourites;
   TreeView contacts_tree_view;
   Grid fields_grid;
   Grid card_grid;
@@ -84,27 +81,8 @@ public class Contacts.App : Window {
     tree_view.append_column (column);
   }
 
-  private bool filter_row (TreeModel model,
-			   TreeIter iter) {
-    Contact contact;
-
-    model.get (iter, 0, out contact);
-
-    if (contact == null)
-      return false;
-
-    if (filter_favourites && !contact.individual.is_favourite)
-      return false;
-
-    if (filter_values == null || filter_values.length == 0)
-      return true;
-
-    return contact.contains_strings (filter_values);
-  }
-
   private void favourites_button_toggled (ToggleToolButton toggle_button) {
-    filter_favourites = toggle_button.get_active ();
-    filter_model.refilter ();
+    contacts_store.set_filter_favourites (toggle_button.get_active ());
   }
 
   private void filter_entry_changed (Editable editable) {
@@ -118,8 +96,7 @@ public class Contacts.App : Window {
       values = str.split(" ");
     }
 
-    filter_values = values;
-    filter_model.refilter ();
+    contacts_store.set_filter_values (values);
   }
 
   private struct DetailsRow {
@@ -367,17 +344,16 @@ public class Contacts.App : Window {
   }
 
   public App () {
-    contacts_store = new ContactStore ();
-    filter_model = new TreeModelFilter (contacts_store, null);
-    filter_model.set_visible_func (filter_row);
+    contacts_store = new Store ();
 
     aggregator = new IndividualAggregator ();
     aggregator.individuals_changed.connect ((added, removed, m, a, r) =>   {
 	foreach (Individual i in removed) {
-	  contacts_store.remove_individual (i);
+	  contacts_store.remove (Contact.from_individual (i));
 	}
 	foreach (Individual i in added) {
-	  contacts_store.insert_individual (i);
+	  var c = new Contact (i);
+	  contacts_store.add (c);
 	}
       });
     aggregator.prepare ();
@@ -443,7 +419,7 @@ public class Contacts.App : Window {
     middle_grid.attach (scrolled, 0, 1, 1, 1);
     grid.attach (frame, 0, 0, 1, 2);
 
-    contacts_tree_view = new TreeView.with_model (filter_model);
+    contacts_tree_view = new TreeView.with_model (contacts_store.model);
     setup_contacts_view (contacts_tree_view);
     scrolled.add (contacts_tree_view);
 
diff --git a/src/contacts-contact.vala b/src/contacts-contact.vala
index 7e29421..211a36e 100644
--- a/src/contacts-contact.vala
+++ b/src/contacts-contact.vala
@@ -20,31 +20,10 @@
 using Gtk;
 using Folks;
 
-public class Contacts.ContactStore : ListStore  {
-  public ContactStore () {
-    GLib.Type[] types = { typeof (Contact) };
-
-    set_column_types (types);
-  }
-  public Contact insert_individual (Individual i) {
-    return new Contact (i, this);
-  }
-  public void remove_individual (Individual i) {
-    Contact contact = Contact.from_individual (i);
-    if (contact != null) {
-      contact.remove ();
-    } else {
-      stdout.printf("removed individual %p with no contact!\n", i);
-    }
-  }
-}
-
 public class Contacts.Contact : GLib.Object  {
   static Gdk.Pixbuf fallback_avatar;
 
   public Individual individual;
-  public ContactStore store;
-  private TreeIter iter;
   uint changed_id;
 
   private Gdk.Pixbuf? _avatar;
@@ -79,22 +58,17 @@ public class Contacts.Contact : GLib.Object  {
     fallback_avatar = draw_fallback_avatar ();
   }
 
-  public Contact(Individual i, ContactStore s) {
+  public Contact(Individual i) {
     individual = i;
-    store = s;
     individual.set_data ("contact", this);
     update ();
 
-    store.append (out iter);
-    store.set (iter, 0, this);
-
     individual.notify.connect(notify_cb);
   }
 
   public void remove () {
     unqueue_changed ();
     individual.notify.disconnect(notify_cb);
-    store.remove (this.iter);
   }
 
   public bool contains_strings (string [] strings) {
@@ -172,8 +146,6 @@ public class Contacts.Contact : GLib.Object  {
     changed_id = 0;
     update ();
     changed ();
-    var path = store.get_path (iter);
-    store.row_changed (path, iter);
     return false;
   }
 



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