X-Git-Url: https://vcs.maemo.org/git/?a=blobdiff_plain;f=src%2Fmovie-list-view.vala;h=56bcaffcc512d609fab75b2e18a2c04dabda5493;hb=563c736e29a8f3fddc13f00d917eff53c443e25b;hp=4b2a1b838c0bb2577c652a2395179899da3ee27c;hpb=417513a5d5f0fbfe4be6ceff758cd4f0ea6e2ac9;p=cinaest diff --git a/src/movie-list-view.vala b/src/movie-list-view.vala index 4b2a1b8..56bcaff 100644 --- a/src/movie-list-view.vala +++ b/src/movie-list-view.vala @@ -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 (); @@ -55,6 +57,7 @@ public class MovieListView : PannableArea { // Add poster icon to column var pixbuf_renderer = new CellRendererPixbuf (); + pixbuf_renderer.width = 64; title_column.pack_start (pixbuf_renderer, false); title_column.add_attribute (pixbuf_renderer, "pixbuf", MovieListStore.Columns.POSTER); @@ -75,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); @@ -102,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) { @@ -132,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) : ""; } }