Add movie object and movie list store
[cinaest] / src / movie-list-view.vala
index 4f2c956..385eeea 100644 (file)
@@ -20,29 +20,22 @@ using Gtk;
 using Hildon;
 
 public class MovieListView : PannableArea {
-       private enum Columns {
-               TITLE,
-               YEAR,
-               RATING,
-               N_COLUMNS
-       }
-
-       ListStore store;
+       MovieListStore store;
        TreeView tree;
        public TreeSortable sorted_store;
 
        construct {
-               store = new ListStore (3, typeof (string), typeof (int), typeof (int));
+               store = new MovieListStore ();
 
                // FIXME - fill store with test data
                int i;
                for (i = 0; i < 10; i++) {
+                       var m = new Movie ();
+                       m.title = "Test %d".printf (i);
+                       m.year = 2000 - i;
+                       m.rating = 10 * (i % 5) + i;
                        TreeIter iter;
-
-                       store.append (out iter);
-                       store.set_value (iter, Columns.TITLE, "Test %d".printf (i));
-                       store.set_value (iter, Columns.YEAR, 2000 - i);
-                       store.set_value (iter, Columns.RATING, 10 * (i % 5) + i);
+                       store.add (m, out iter);
                }
 
                // Add filter wrapper
@@ -63,36 +56,41 @@ public class MovieListView : PannableArea {
                var selection = tree.get_selection ();
                selection.set_mode (SelectionMode.SINGLE);
 
-               // Title column
+               // Title column with poster
                var title_column = new TreeViewColumn ();
                title_column.set_title ("Movie");
-               title_column.set_sort_column_id (Columns.TITLE);
+               title_column.set_sort_column_id (MovieListStore.Columns.TITLE);
                title_column.set_reorderable (false);
                title_column.set_sizing (TreeViewColumnSizing.AUTOSIZE);
                title_column.set_expand (true);
 
+               // Add poster icon to column
+               var pixbuf_renderer = new CellRendererPixbuf ();
+               title_column.pack_start (pixbuf_renderer, false);
+               title_column.add_attribute (pixbuf_renderer, "pixbuf", MovieListStore.Columns.POSTER);
+
                // Add text to column
                var renderer = new CellRendererText ();
                renderer.set ("ellipsize", Pango.EllipsizeMode.END);
                title_column.pack_start (renderer, true);
-               title_column.add_attribute (renderer, "text", Columns.TITLE);
+               title_column.add_attribute (renderer, "text", MovieListStore.Columns.TITLE);
                tree.append_column (title_column);
 
                // Sort by title
-               sorted_store.set_sort_column_id (Columns.TITLE, SortType.ASCENDING);
+               sorted_store.set_sort_column_id (MovieListStore.Columns.TITLE, SortType.ASCENDING);
 
                // Year column
                renderer = new CellRendererText ();
-               var year_column = new TreeViewColumn.with_attributes ("Year", renderer, "text", Columns.YEAR);
-               year_column.set_sort_column_id (Columns.YEAR);
+               var year_column = new TreeViewColumn.with_attributes ("Year", renderer, "text", MovieListStore.Columns.YEAR);
+               year_column.set_sort_column_id (MovieListStore.Columns.YEAR);
                year_column.set_reorderable (false);
                year_column.set_sort_order (SortType.DESCENDING);
                tree.append_column (year_column);
 
                // Rating column
                renderer = new CellRendererText ();
-               var rating_column = new TreeViewColumn.with_attributes ("Rating", renderer, "text", Columns.RATING);
-               rating_column.set_sort_column_id (Columns.RATING);
+               var rating_column = new TreeViewColumn.with_attributes ("Rating", renderer, "text", MovieListStore.Columns.RATING);
+               rating_column.set_sort_column_id (MovieListStore.Columns.RATING);
                rating_column.set_reorderable (false);
                rating_column.set_sort_order (SortType.DESCENDING);
                rating_column.set_cell_data_func (renderer, rating_data_func);