Google poster downloader: tweak search URI to subjectively improve results
[cinaest] / src / movie-list-view.vala
index fb54aea..4f3eabd 100644 (file)
@@ -24,6 +24,8 @@ public class MovieListView : PannableArea {
        TreeView tree;
        public TreeSortable sorted_store;
 
+       public signal void movie_activated (Movie movie);
+
        construct {
                store = new MovieListStore ();
 
@@ -103,21 +105,57 @@ public class MovieListView : PannableArea {
 
                // Year column
                renderer = new CellRendererText ();
-               var year_column = new TreeViewColumn.with_attributes (_("Year"), renderer, "text", MovieListStore.Columns.YEAR);
+               var year_column = new TreeViewColumn ();
+               year_column.set_title (_("Rating"));
                year_column.set_sort_column_id (MovieListStore.Columns.YEAR);
                year_column.set_reorderable (false);
                year_column.set_sort_order (SortType.DESCENDING);
+               year_column.pack_start (renderer, true);
+               year_column.set_cell_data_func (renderer, year_data_func);
                tree.append_column (year_column);
 
                // Rating column
                renderer = new CellRendererText ();
-               var rating_column = new TreeViewColumn.with_attributes (_("Rating"), renderer, "text", MovieListStore.Columns.RATING);
+               var rating_column = new TreeViewColumn ();
+               rating_column.set_title (_("Rating"));
                rating_column.set_sort_column_id (MovieListStore.Columns.RATING);
                rating_column.set_reorderable (false);
                rating_column.set_sort_order (SortType.DESCENDING);
+               rating_column.pack_start (renderer, true);
                rating_column.set_cell_data_func (renderer, rating_data_func);
                rating_column.xalign = (float) 1.0;
                tree.append_column (rating_column);
+
+               // Connect signals
+               tree.row_activated.connect (on_row_activated);
+       }
+
+       public void set_hildon_ui_mode (UIMode mode) {
+               var selection = tree.get_selection ();
+
+               if (mode == UIMode.NORMAL) {
+                       selection.set_mode (SelectionMode.NONE);
+               }
+               Hildon.gtk_tree_view_set_ui_mode (tree, mode);
+               if (mode == UIMode.EDIT) {
+                       selection.set_mode (SelectionMode.MULTIPLE);
+               }
+       }
+
+       public unowned TreeSelection get_selection () {
+               return tree.get_selection ();
+       }
+
+       private void on_row_activated (TreeView tree, TreePath path_, TreeViewColumn column) {
+               TreePath path = path_.copy (); // FIXME - calling model.get_iter with path_ directly causes a C qualifier warning
+               TreeModel model = tree.model;
+               TreeIter iter;
+
+               if (model.get_iter (out iter, path)) {
+                       Movie movie;
+                       model.get (iter, MovieListStore.Columns.MOVIE, out movie);
+                       movie_activated (movie);
+               }
        }
 
        private void vbox_data_func (CellLayout cell_layout, CellRenderer cell, TreeModel model, TreeIter iter) {
@@ -133,10 +171,17 @@ public class MovieListView : PannableArea {
                renderer.text = movie.secondary;
        }
 
+       private void year_data_func (CellLayout cell_layout, CellRenderer cell, TreeModel model, TreeIter iter) {
+               int year;
+
+               model.get (iter, MovieListStore.Columns.YEAR, out year);
+               ((CellRendererText) cell).text = (year > 0) ? year.to_string () : "";
+       }
+
        private void rating_data_func (CellLayout cell_layout, CellRenderer cell, TreeModel model, TreeIter iter) {
                int rating;
 
                model.get (iter, MovieListStore.Columns.RATING, out rating);
-               ((CellRendererText) cell).text = "%d.%d".printf (rating / 10, rating % 10);
+               ((CellRendererText) cell).text = (rating > 0) ? "%d.%d".printf (rating / 10, rating % 10) : "";
        }
 }