Movie window: change thumbnail image scaling
[cinaest] / src / movie-list-view.vala
index bfaa8a7..56bcaff 100644 (file)
@@ -78,7 +78,7 @@ public class MovieListView : PannableArea {
                Pango.AttrList attr_list = new Pango.AttrList ();
                var style = Gtk.rc_get_style_by_paths (this.get_settings (), "SmallSystemFont", null, typeof (void));
                if (style != null) {
-                       Pango.Attribute attr_font_desc = Pango.attr_font_desc_new (style.font_desc.copy ());
+                       var attr_font_desc = new Pango.AttrFontDesc (style.font_desc.copy ());
                        attr_list.insert ((owned) attr_font_desc);
                } else {
                        Pango.Attribute attr_font_scale = Pango.attr_scale_new (Pango.Scale.SMALL);
@@ -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);
@@ -125,6 +130,22 @@ public class MovieListView : PannableArea {
                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;
@@ -150,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) : "";
        }
 }