Movie list view: hide year and rating if zero
authorPhilipp Zabel <philipp.zabel@gmail.com>
Thu, 19 Nov 2009 16:04:23 +0000 (17:04 +0100)
committerPhilipp Zabel <philipp.zabel@gmail.com>
Thu, 19 Nov 2009 16:22:07 +0000 (17:22 +0100)
src/movie-list-view.vala

index d6acff4..4f3eabd 100644 (file)
@@ -105,18 +105,23 @@ 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);
@@ -166,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) : "";
        }
 }