1 /* This file is part of Cinaest.
3 * Copyright (C) 2009 Philipp Zabel
5 * Cinaest is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * Cinaest is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with Cinaest. If not, see <http://www.gnu.org/licenses/>.
21 public class MovieListStore : ListStore, TreeModel {
30 private GLib.Type[] types = {
37 private GLib.Type[] base_type = {
40 private Gdk.Pixbuf no_poster;
43 set_column_types (base_type);
47 public void add (Movie movie, out TreeIter iter) {
51 base.set (iter1, 0, movie);
53 movie.notify.connect ((source, property) => { on_movie_changed(source); });
58 private void on_movie_changed (GLib.Object source) {
59 Movie movie = (Movie) source;
62 if (get_iter_from_movie (out iter, movie)) {
63 TreePath path = get_path (iter);
64 base.row_changed (path, iter);
68 public bool get_iter_from_movie (out TreeIter iter, Movie movie_a) {
69 if (get_iter_first (out iter)) {
72 get (iter, Columns.MOVIE, out movie_b);
73 if (movie_a == movie_b)
75 } while (iter_next (ref iter));
80 // Implement TreeModel interface
81 public virtual GLib.Type get_column_type (int index_) {
82 return_val_if_fail (index_ >= 0 && index_ < Columns.N_COLUMNS, 0);
87 public virtual int get_n_columns () {
88 return Columns.N_COLUMNS;
91 public virtual void get_value (TreeIter iter, int column, out GLib.Value value) {
95 if (no_poster == null) try {
96 no_poster = new Gdk.Pixbuf.from_file ("/usr/share/icons/hicolor/64x64/hildon/general_video.png");
98 critical ("Missing general_video icon: %s\n", e.message);
101 return_if_fail (column >= 0 && column < Columns.N_COLUMNS);
103 // Get the Movie from our parent's storage
105 base.get_value (iter, 0, out val);
106 movie = (Movie) val.get_object ();
108 value.init (get_column_type (column));
113 value.set_string (movie.title);
115 value.set_string ("");
121 value.set_int (movie.year);
129 value.set_int (movie.rating);
136 if ((movie.poster != null) && (movie.poster.thumbnail != null))
137 value.set_object (movie.poster.thumbnail);
139 value.set_object (no_poster);
143 value.set_object (movie);
147 assert_not_reached ();