[gnome-contacts] Combine View and ViewWidget



commit b5572d8fb35cc75300ebb0caa61cc24f455452f6
Author: Alexander Larsson <alexl redhat com>
Date:   Sun Feb 19 16:16:26 2012 +0100

    Combine View and ViewWidget

 src/contacts-link-dialog.vala |    9 +++------
 src/contacts-list-pane.vala   |   11 ++++-------
 src/contacts-view.vala        |   23 +++++++++++------------
 3 files changed, 18 insertions(+), 25 deletions(-)
---
diff --git a/src/contacts-link-dialog.vala b/src/contacts-link-dialog.vala
index 229547d..7a3ec1f 100644
--- a/src/contacts-link-dialog.vala
+++ b/src/contacts-link-dialog.vala
@@ -29,7 +29,6 @@ public class Contacts.LinkDialog : Dialog {
   private Contact? selected_contact;
   private Entry filter_entry;
   private View view;
-  private ViewWidget list;
   private Grid list_grid;
   private Grid persona_grid;
   private uint filter_entry_changed_id;
@@ -155,7 +154,7 @@ public class Contacts.LinkDialog : Dialog {
       add_buttons (_("Cancel"), ResponseType.CANCEL, _("Link"), ResponseType.APPLY, null);
     }
 
-    view = new View (contact.store);
+    view = new View (contact.store, View.TextDisplay.STORES);
     view.hide_contact (contact);
     if (contact.is_main)
       view.set_show_subset (View.Subset.OTHER);
@@ -171,8 +170,6 @@ public class Contacts.LinkDialog : Dialog {
       }
     }
 
-    list = new ViewWidget (view, ViewWidget.TextDisplay.STORES);
-
     var grid = new Grid ();
     grid.set_row_spacing (6);
     grid.set_column_homogeneous (true);
@@ -223,10 +220,10 @@ public class Contacts.LinkDialog : Dialog {
     scrolled.set_vexpand (true);
     scrolled.set_hexpand (true);
     scrolled.set_shadow_type (ShadowType.NONE);
-    scrolled.add (list);
+    scrolled.add (view);
     list_grid.add (scrolled);
 
-    list.selection_changed.connect ( (c) => {
+    view.selection_changed.connect ( (c) => {
 	selected_contact = c;
 	update_contact ();
       });
diff --git a/src/contacts-list-pane.vala b/src/contacts-list-pane.vala
index 384ebe5..50ae1fe 100644
--- a/src/contacts-list-pane.vala
+++ b/src/contacts-list-pane.vala
@@ -22,7 +22,6 @@ using Folks;
 public class Contacts.ListPane : Frame {
   private Store contacts_store;
   private View contacts_view;
-  private ViewWidget list;
   public Entry filter_entry;
   private uint filter_entry_changed_id;
   private bool ignore_selection_change;
@@ -139,15 +138,13 @@ public class Contacts.ListPane : Frame {
     grid.set_orientation (Orientation.VERTICAL);
     this.add (grid);
 
-
-    list = new ViewWidget (contacts_view);
-    list.selection_changed.connect( (l, contact) => {
+    contacts_view.selection_changed.connect( (l, contact) => {
 	if (!ignore_selection_change)
 	  selection_changed (contact);
       });
 
-    scrolled.add (list);
-    list.show_all ();
+    scrolled.add (contacts_view);
+    contacts_view.show_all ();
     scrolled.set_no_show_all (true);
 
     grid.add (search_revealer);
@@ -163,7 +160,7 @@ public class Contacts.ListPane : Frame {
   public void select_contact (Contact contact, bool ignore_change = false) {
     if (ignore_change)
       ignore_selection_change = true;
-    list.select_contact (contact);
+    contacts_view.select_contact (contact);
     ignore_selection_change = false;
   }
 }
diff --git a/src/contacts-view.vala b/src/contacts-view.vala
index 79ac2ef..ad6969c 100644
--- a/src/contacts-view.vala
+++ b/src/contacts-view.vala
@@ -20,7 +20,7 @@ using Gtk;
 using Folks;
 using Gee;
 
-public class Contacts.View : GLib.Object {
+public class Contacts.View : TreeView {
   private class ContactData {
     public Contact contact;
     public TreeIter iter;
@@ -46,7 +46,7 @@ public class Contacts.View : GLib.Object {
   ContactData padding_data;
   ContactData other_header_data;
 
-  public View (Store store) {
+  public View (Store store, TextDisplay text_display = TextDisplay.PRESENCE) {
     contacts_store = store;
     hidden_contacts = new HashSet<Contact>();
     show_subset = Subset.ALL;
@@ -74,6 +74,8 @@ public class Contacts.View : GLib.Object {
     contacts_store.changed.connect (contact_changed_cb);
     foreach (var c in store.get_contacts ())
       contact_added_cb (store, c);
+
+      init_view (text_display);
   }
 
   private int compare_data (ContactData a_data, ContactData b_data) {
@@ -388,11 +390,9 @@ public class Contacts.View : GLib.Object {
     iter = data.iter;
     return data.visible;
   }
-}
 
 
-public class Contacts.ViewWidget : TreeView {
-  public View view;
+
   private CellRendererShape shape;
   public enum TextDisplay {
     NONE,
@@ -403,11 +403,10 @@ public class Contacts.ViewWidget : TreeView {
 
   public signal void selection_changed (Contact? contact);
 
-  public ViewWidget (View view, TextDisplay text_display = TextDisplay.PRESENCE) {
-    this.view = view;
+  private void init_view (TextDisplay text_display) {
     this.text_display = text_display;
 
-    set_model (view.model);
+    set_model (model);
     set_headers_visible (false);
 
     var row_padding = 12;
@@ -418,7 +417,7 @@ public class Contacts.ViewWidget : TreeView {
 	Contact contact;
 	TreeIter iter;
 	model.get_iter (out iter, path);
-	view.model.get (iter, 0, out contact);
+	model.get (iter, 0, out contact);
 	return contact != null;
       });
     selection.changed.connect (contacts_selection_changed);
@@ -500,7 +499,7 @@ public class Contacts.ViewWidget : TreeView {
 	model.get (iter, 0, out contact);
 	cell.visible = contact == null;
 	if (cell.visible) {
-	  string header = view.get_header_text (iter);
+	  string header = get_header_text (iter);
 	  cell.set ("text", header);
 	  if (header == "")
 	    cell.height = 6; // PADDING
@@ -526,9 +525,9 @@ public class Contacts.ViewWidget : TreeView {
 
   public void select_contact (Contact contact) {
     TreeIter iter;
-    if (view.lookup_iter (contact, out iter)) {
+    if (lookup_iter (contact, out iter)) {
       get_selection ().select_iter (iter);
-      scroll_to_cell (view.model.get_path (iter),
+      scroll_to_cell (model.get_path (iter),
 		      null, true, 0.0f, 0.0f);
     }
   }



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