[gnome-contacts] Split out list pane to own file



commit c5aa54c8079370463057a1cfa56fa8bdf95eda29
Author: Alexander Larsson <alexl redhat com>
Date:   Thu Jun 9 19:19:35 2011 +0200

    Split out list pane to own file

 src/Makefile.am             |    1 +
 src/contacts-app.vala       |  174 ++-----------------------------------
 src/contacts-list-pane.vala |  202 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 211 insertions(+), 166 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 2f5eb87..8920997 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -20,6 +20,7 @@ gnome_contacts_SOURCES = \
 	contacts-contact.vala \
 	contacts-menu-button.vala \
 	contacts-store.vala \
+	contacts-list-pane.vala \
 	contacts-utils.vala \
 	main.vala \
 	$(NULL)
diff --git a/src/contacts-app.vala b/src/contacts-app.vala
index 5478211..0eb841e 100644
--- a/src/contacts-app.vala
+++ b/src/contacts-app.vala
@@ -28,10 +28,9 @@ public class Contacts.App : Window {
     NOTES,
     EDIT
   }
-  private Store contacts_store;
+  private ListPane list_pane;
   private Contact? selected_contact;
   private DisplayMode display_mode;
-  private TreeView contacts_tree_view;
   private Grid fields_grid;
   private SizeGroup label_size_group;
   private bool has_notes;
@@ -39,99 +38,6 @@ public class Contacts.App : Window {
   private ButtonBox normal_buttons;
   private ButtonBox editing_buttons;
 
-  public IndividualAggregator aggregator { get; private set; }
-  public BackendStore backend_store { get; private set; }
-
-  private void setup_contacts_view (TreeView tree_view) {
-    tree_view.set_headers_visible (false);
-
-    var selection = tree_view.get_selection ();
-    selection.set_mode (SelectionMode.BROWSE);
-    selection.changed.connect (contacts_selection_changed);
-
-    var column = new TreeViewColumn ();
-    column.set_spacing (10);
-
-    var text = new CellRendererText ();
-    text.set_alignment (0, 0);
-    column.pack_start (text, true);
-    text.set ("weight", Pango.Weight.BOLD, "scale", 1.28);
-    column.set_cell_data_func (text, (column, cell, model, iter) => {
-	Contact contact;
-
-	model.get (iter, 0, out contact);
-
-	string letter = "";
-	if (contacts_store.is_first (iter))
-	  letter = contact.display_name.get_char ().totitle ().to_string ();
-	cell.set ("text", letter);
-      });
-
-    var icon = new CellRendererPixbuf ();
-    column.pack_start (icon, false);
-    column.set_cell_data_func (icon, (column, cell, model, iter) => {
-	Contact contact;
-
-	model.get (iter, 0, out contact);
-
-	cell.set ("pixbuf", contact.avatar);
-      });
-
-    tree_view.append_column (column);
-
-    column = new TreeViewColumn ();
-
-    var area = (CellAreaBox)column.get_area ();
-    area.set_orientation (Orientation.VERTICAL);
-
-    text = new CellRendererText ();
-    column.pack_start (text, false);
-    text.set ("weight", Pango.Weight.BOLD);
-    column.set_cell_data_func (text, (column, cell, model, iter) => {
-	Contact contact;
-
-	model.get (iter, 0, out contact);
-
-	string name = contact.display_name;
-	cell.set ("text", name);
-      });
-
-    icon = new CellRendererPixbuf ();
-
-    icon.set_alignment (0, 0.5f);
-    column.pack_start (icon, false);
-    column.set_cell_data_func (icon, (column, cell, model, iter) => {
-	Contact contact;
-
-	model.get (iter, 0, out contact);
-	Individual individual = contact.individual;
-
-	string? iconname = Contact.presence_to_icon (individual.presence_type);
-	//cell.set ("visible", icon != null);
-	if (icon != null)
-	  cell.set ("icon-name", iconname);
-	else
-	  cell.set ("icon-name", null);
-
-      });
-
-    tree_view.append_column (column);
-  }
-
-  private void filter_entry_changed (Editable editable) {
-    string []? values;
-    string str = (editable as Entry).get_text ();
-
-    if (str.length == 0)
-      values = null;
-    else {
-      str = str.casefold();
-      values = str.split(" ");
-    }
-
-    contacts_store.set_filter_values (values);
-  }
-
   private struct DetailsRow {
     Grid grid;
     Widget label;
@@ -440,41 +346,21 @@ public class Contacts.App : Window {
     clear_display ();
   }
 
-  private void contacts_selection_changed (TreeSelection selection) {
-    TreeIter iter;
-    TreeModel model;
-
+  private void selection_changed (Contact? new_selection) {
     if (selected_contact != null)
       selected_contact.changed.disconnect (selected_contact_changed);
 
-    selected_contact = null;
+    selected_contact = new_selection;
     set_display_mode (DisplayMode.EMPTY);
     set_has_notes (false);
 
-    if (selection.get_selected (out model, out iter)) {
-      model.get (iter, 0, out selected_contact);
-      if (selected_contact != null) {
+    if (selected_contact != null) {
 	display_contact (selected_contact);
 	selected_contact.changed.connect (selected_contact_changed);
-      }
     }
   }
 
   public App () {
-    contacts_store = new Store ();
-
-    aggregator = new IndividualAggregator ();
-    aggregator.individuals_changed.connect ((added, removed, m, a, r) =>   {
-	foreach (Individual i in removed) {
-	  contacts_store.remove (Contact.from_individual (i));
-	}
-	foreach (Individual i in added) {
-	  var c = new Contact (i);
-	  contacts_store.add (c);
-	}
-      });
-    aggregator.prepare ();
-
     set_title (_("Contacts"));
     set_default_size (800, 500);
     this.destroy.connect (Gtk.main_quit);
@@ -482,59 +368,15 @@ public class Contacts.App : Window {
     var grid = new Grid();
     add (grid);
 
-    var toolbar = new Toolbar ();
-    toolbar.get_style_context ().add_class (STYLE_CLASS_PRIMARY_TOOLBAR);
-    toolbar.set_icon_size (IconSize.MENU);
-    toolbar.set_vexpand (false);
-
-    var separator = new SeparatorToolItem ();
-    separator.set_draw (false);
-    toolbar.add (separator);
-
-    var filter_entry = new Entry ();
-    filter_entry.set ("placeholder-text", _("Type here to filter"));
-    filter_entry.set_icon_from_icon_name (EntryIconPosition.SECONDARY, "edit-find-symbolic");
-    filter_entry.changed.connect (filter_entry_changed);
+    list_pane = new ListPane ();
+    list_pane.selection_changed.connect (selection_changed);
 
     map_event.connect (() => {
-	filter_entry.grab_focus ();
+	list_pane.filter_entry.grab_focus ();
 	return true;
       });
 
-    var search_entry_item = new ToolItem ();
-    search_entry_item.is_important = false;
-    search_entry_item.set_expand (true);
-    search_entry_item.add (filter_entry);
-    toolbar.add (search_entry_item);
-
-    separator = new SeparatorToolItem ();
-    separator.set_draw (false);
-    toolbar.add (separator);
-
-    var add_button = new ToolButton (null, null);
-    add_button.set_icon_name ("list-add-symbolic");
-    add_button.get_style_context ().add_class (STYLE_CLASS_RAISED);
-    add_button.is_important = false;
-    toolbar.add (add_button);
-
-    var scrolled = new ScrolledWindow(null, null);
-    scrolled.set_min_content_width (400);
-    scrolled.set_policy (PolicyType.AUTOMATIC, PolicyType.AUTOMATIC);
-    scrolled.set_vexpand (true);
-    scrolled.set_shadow_type (ShadowType.NONE);
-    scrolled.get_style_context ().set_junction_sides (JunctionSides.RIGHT | JunctionSides.LEFT | JunctionSides.TOP);
-
-    var frame = new Frame (null);
-    var middle_grid = new Grid ();
-    frame.add (middle_grid);
-
-    middle_grid.attach (toolbar, 0, 0, 1, 1);
-    middle_grid.attach (scrolled, 0, 1, 1, 1);
-    grid.attach (frame, 0, 0, 1, 2);
-
-    contacts_tree_view = new TreeView.with_model (contacts_store.model);
-    setup_contacts_view (contacts_tree_view);
-    scrolled.add (contacts_tree_view);
+    grid.attach (list_pane, 0, 0, 1, 2);
 
     var ebox = new EventBox ();
     ebox.get_style_context ().add_class ("contact-pane");
diff --git a/src/contacts-list-pane.vala b/src/contacts-list-pane.vala
new file mode 100644
index 0000000..777d56e
--- /dev/null
+++ b/src/contacts-list-pane.vala
@@ -0,0 +1,202 @@
+/* -*- Mode: vala; indent-tabs-mode: t; c-basic-offset: 2; tab-width: 8 -*- */
+/*
+ * Copyright (C) 2011 Alexander Larsson <alexl redhat com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+using Gtk;
+using Folks;
+
+public class Contacts.ListPane : Frame {
+  private Store contacts_store;
+  private TreeView contacts_tree_view;
+  public Entry filter_entry;
+
+  public IndividualAggregator aggregator { get; private set; }
+  public BackendStore backend_store { get; private set; }
+
+  public signal void selection_changed (Contact? contact);
+  public signal void create_new ();
+
+  private void setup_contacts_view (TreeView tree_view) {
+    tree_view.set_headers_visible (false);
+
+    var selection = tree_view.get_selection ();
+    selection.set_mode (SelectionMode.BROWSE);
+    selection.changed.connect (contacts_selection_changed);
+
+    var column = new TreeViewColumn ();
+    column.set_spacing (10);
+
+    var text = new CellRendererText ();
+    text.set_alignment (0, 0);
+    column.pack_start (text, true);
+    text.set ("weight", Pango.Weight.BOLD, "scale", 1.28);
+    column.set_cell_data_func (text, (column, cell, model, iter) => {
+	Contact contact;
+
+	model.get (iter, 0, out contact);
+
+	string letter = "";
+	if (contacts_store.is_first (iter))
+	  letter = contact.display_name.get_char ().totitle ().to_string ();
+	cell.set ("text", letter);
+      });
+
+    var icon = new CellRendererPixbuf ();
+    column.pack_start (icon, false);
+    column.set_cell_data_func (icon, (column, cell, model, iter) => {
+	Contact contact;
+
+	model.get (iter, 0, out contact);
+
+	cell.set ("pixbuf", contact.avatar);
+      });
+
+    tree_view.append_column (column);
+
+    column = new TreeViewColumn ();
+
+    var area = (CellAreaBox)column.get_area ();
+    area.set_orientation (Orientation.VERTICAL);
+
+    text = new CellRendererText ();
+    column.pack_start (text, false);
+    text.set ("weight", Pango.Weight.BOLD);
+    column.set_cell_data_func (text, (column, cell, model, iter) => {
+	Contact contact;
+
+	model.get (iter, 0, out contact);
+
+	string name = contact.display_name;
+	cell.set ("text", name);
+      });
+
+    icon = new CellRendererPixbuf ();
+
+    icon.set_alignment (0, 0.5f);
+    column.pack_start (icon, false);
+    column.set_cell_data_func (icon, (column, cell, model, iter) => {
+	Contact contact;
+
+	model.get (iter, 0, out contact);
+	Individual individual = contact.individual;
+
+	string? iconname = Contact.presence_to_icon (individual.presence_type);
+	if (icon != null)
+	  cell.set ("icon-name", iconname);
+	else
+	  cell.set ("icon-name", null);
+
+      });
+
+    tree_view.append_column (column);
+  }
+
+  private void filter_entry_changed (Editable editable) {
+    string []? values;
+    string str = (editable as Entry).get_text ();
+
+    if (str.length == 0)
+      values = null;
+    else {
+      str = str.casefold();
+      values = str.split(" ");
+    }
+
+    contacts_store.set_filter_values (values);
+  }
+
+  private void contacts_selection_changed (TreeSelection selection) {
+    TreeIter iter;
+    TreeModel model;
+
+    Contact? contact = null;
+    if (selection.get_selected (out model, out iter)) {
+      model.get (iter, 0, out contact);
+    }
+
+    selection_changed (contact);
+  }
+
+  public ListPane () {
+    contacts_store = new Store ();
+
+    aggregator = new IndividualAggregator ();
+    aggregator.individuals_changed.connect ((added, removed, m, a, r) =>   {
+	foreach (Individual i in removed) {
+	  contacts_store.remove (Contact.from_individual (i));
+	}
+	foreach (Individual i in added) {
+	  var c = new Contact (i);
+	  contacts_store.add (c);
+	}
+      });
+    aggregator.prepare ();
+
+    var toolbar = new Toolbar ();
+    toolbar.get_style_context ().add_class (STYLE_CLASS_PRIMARY_TOOLBAR);
+    toolbar.set_icon_size (IconSize.MENU);
+    toolbar.set_vexpand (false);
+
+    var separator = new SeparatorToolItem ();
+    separator.set_draw (false);
+    toolbar.add (separator);
+
+    filter_entry = new Entry ();
+    filter_entry.set ("placeholder-text", _("Type here to filter"));
+    filter_entry.set_icon_from_icon_name (EntryIconPosition.SECONDARY, "edit-find-symbolic");
+    filter_entry.changed.connect (filter_entry_changed);
+
+    var search_entry_item = new ToolItem ();
+    search_entry_item.is_important = false;
+    search_entry_item.set_expand (true);
+    search_entry_item.add (filter_entry);
+    toolbar.add (search_entry_item);
+
+    separator = new SeparatorToolItem ();
+    separator.set_draw (false);
+    toolbar.add (separator);
+
+    var add_button = new ToolButton (null, null);
+    add_button.set_icon_name ("list-add-symbolic");
+    add_button.get_style_context ().add_class (STYLE_CLASS_RAISED);
+    add_button.is_important = false;
+    toolbar.add (add_button);
+    add_button.clicked.connect ( (button) => {
+	create_new ();
+      });
+
+    var scrolled = new ScrolledWindow(null, null);
+    scrolled.set_min_content_width (400);
+    scrolled.set_policy (PolicyType.AUTOMATIC, PolicyType.AUTOMATIC);
+    scrolled.set_vexpand (true);
+    scrolled.set_shadow_type (ShadowType.NONE);
+    scrolled.get_style_context ().set_junction_sides (JunctionSides.RIGHT | JunctionSides.LEFT | JunctionSides.TOP);
+
+    var grid = new Grid ();
+    this.add (grid);
+
+    grid.attach (toolbar, 0, 0, 1, 1);
+    grid.attach (scrolled, 0, 1, 1, 1);
+
+    contacts_tree_view = new TreeView.with_model (contacts_store.model);
+    setup_contacts_view (contacts_tree_view);
+    scrolled.add (contacts_tree_view);
+
+    this.show_all ();
+  }
+}



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