The movie object directly contains title, year, rating and genre information.
It is is stored in a movie list store which serves as backend for the
movie list view.
cinaest_SOURCES = \
src/main.vala \
+ src/movie.vala \
src/movie-list-menu.vala \
+ src/movie-list-store.vala \
src/movie-list-view.vala \
src/movie-list-window.vala
--- /dev/null
+/* This file is part of Cinaest.
+ *
+ * Copyright (C) 2009 Philipp Zabel
+ *
+ * Cinaest is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Cinaest is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Cinaest. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+using Gtk;
+
+public class MovieListStore : ListStore, TreeModel {
+ public enum Columns {
+ TITLE,
+ YEAR,
+ RATING,
+ POSTER,
+ MOVIE,
+ N_COLUMNS
+ }
+ private GLib.Type[] types = {
+ typeof (string),
+ typeof (int),
+ typeof (int),
+ typeof (Gdk.Pixbuf),
+ typeof (Movie)
+ };
+ private GLib.Type[] base_type = {
+ typeof (Movie)
+ };
+ private Gdk.Pixbuf no_poster;
+
+ construct {
+ set_column_types (base_type);
+ no_poster = null;
+ }
+
+ public void add (Movie movie, out TreeIter iter) {
+ TreeIter iter1;
+
+ append (out iter1);
+ base.set (iter1, 0, movie);
+
+ movie.notify.connect ((source, property) => { on_movie_changed(source); });
+
+ iter = iter1;
+ }
+
+ private void on_movie_changed (GLib.Object source) {
+ Movie movie = (Movie) source;
+
+ TreeIter iter;
+ if (get_iter_from_movie (out iter, movie)) {
+ TreePath path = get_path (iter);
+ base.row_changed (path, iter);
+ }
+ }
+
+ public bool get_iter_from_movie (out TreeIter iter, Movie movie_a) {
+ if (get_iter_first (out iter)) {
+ do {
+ Movie movie_b;
+ get (iter, Columns.MOVIE, out movie_b);
+ if (movie_a == movie_b)
+ return true;
+ } while (iter_next (ref iter));
+ }
+ return false;
+ }
+
+ // Implement TreeModel interface
+ public virtual GLib.Type get_column_type (int index_) {
+ return_val_if_fail (index_ >= 0 && index_ < Columns.N_COLUMNS, 0);
+
+ return types[index_];
+ }
+
+ public virtual int get_n_columns () {
+ return Columns.N_COLUMNS;
+ }
+
+ public virtual void get_value (TreeIter iter, int column, out GLib.Value value) {
+ Movie movie;
+
+ // FIXME
+ if (no_poster == null) try {
+ no_poster = new Gdk.Pixbuf.from_file ("/usr/share/icons/hicolor/64x64/hildon/general_video.png");
+ } catch (Error e) {
+ critical ("Missing general_video icon: %s\n", e.message);
+ }
+
+ return_if_fail (column >= 0 && column < Columns.N_COLUMNS);
+
+ // Get the Movie from our parent's storage
+ Value val;
+ base.get_value (iter, 0, out val);
+ movie = (Movie) val.get_object ();
+
+ value.init (get_column_type (column));
+
+ switch (column) {
+ case Columns.TITLE:
+ if (movie != null) {
+ value.set_string (movie.title);
+ } else {
+ value.set_string ("");
+ }
+ break;
+
+ case Columns.YEAR:
+ if (movie != null) {
+ value.set_int (movie.year);
+ } else {
+ value.set_int (-1);
+ }
+ break;
+
+ case Columns.RATING:
+ if (movie != null) {
+ value.set_int (movie.rating);
+ } else {
+ value.set_int (-1);
+ }
+ break;
+
+ case Columns.POSTER:
+ if ((movie.poster != null) && (movie.poster.thumbnail != null))
+ value.set_object (movie.poster.thumbnail);
+ else
+ value.set_object (no_poster);
+ break;
+
+ case Columns.MOVIE:
+ value.set_object (movie);
+ break;
+
+ default:
+ assert_not_reached ();
+ }
+ }
+}
using Hildon;
public class MovieListView : PannableArea {
- private enum Columns {
- TITLE,
- YEAR,
- RATING,
- N_COLUMNS
- }
-
- ListStore store;
+ MovieListStore store;
TreeView tree;
public TreeSortable sorted_store;
construct {
- store = new ListStore (3, typeof (string), typeof (int), typeof (int));
+ store = new MovieListStore ();
// FIXME - fill store with test data
int i;
for (i = 0; i < 10; i++) {
+ var m = new Movie ();
+ m.title = "Test %d".printf (i);
+ m.year = 2000 - i;
+ m.rating = 10 * (i % 5) + i;
TreeIter iter;
-
- store.append (out iter);
- store.set_value (iter, Columns.TITLE, "Test %d".printf (i));
- store.set_value (iter, Columns.YEAR, 2000 - i);
- store.set_value (iter, Columns.RATING, 10 * (i % 5) + i);
+ store.add (m, out iter);
}
// Add filter wrapper
var selection = tree.get_selection ();
selection.set_mode (SelectionMode.SINGLE);
- // Title column
+ // Title column with poster
var title_column = new TreeViewColumn ();
title_column.set_title ("Movie");
- title_column.set_sort_column_id (Columns.TITLE);
+ title_column.set_sort_column_id (MovieListStore.Columns.TITLE);
title_column.set_reorderable (false);
title_column.set_sizing (TreeViewColumnSizing.AUTOSIZE);
title_column.set_expand (true);
+ // Add poster icon to column
+ var pixbuf_renderer = new CellRendererPixbuf ();
+ title_column.pack_start (pixbuf_renderer, false);
+ title_column.add_attribute (pixbuf_renderer, "pixbuf", MovieListStore.Columns.POSTER);
+
// Add text to column
var renderer = new CellRendererText ();
renderer.set ("ellipsize", Pango.EllipsizeMode.END);
title_column.pack_start (renderer, true);
- title_column.add_attribute (renderer, "text", Columns.TITLE);
+ title_column.add_attribute (renderer, "text", MovieListStore.Columns.TITLE);
tree.append_column (title_column);
// Sort by title
- sorted_store.set_sort_column_id (Columns.TITLE, SortType.ASCENDING);
+ sorted_store.set_sort_column_id (MovieListStore.Columns.TITLE, SortType.ASCENDING);
// Year column
renderer = new CellRendererText ();
- var year_column = new TreeViewColumn.with_attributes ("Year", renderer, "text", Columns.YEAR);
- year_column.set_sort_column_id (Columns.YEAR);
+ var year_column = new TreeViewColumn.with_attributes ("Year", renderer, "text", MovieListStore.Columns.YEAR);
+ year_column.set_sort_column_id (MovieListStore.Columns.YEAR);
year_column.set_reorderable (false);
year_column.set_sort_order (SortType.DESCENDING);
tree.append_column (year_column);
// Rating column
renderer = new CellRendererText ();
- var rating_column = new TreeViewColumn.with_attributes ("Rating", renderer, "text", Columns.RATING);
- rating_column.set_sort_column_id (Columns.RATING);
+ var rating_column = new TreeViewColumn.with_attributes ("Rating", renderer, "text", MovieListStore.Columns.RATING);
+ rating_column.set_sort_column_id (MovieListStore.Columns.RATING);
rating_column.set_reorderable (false);
rating_column.set_sort_order (SortType.DESCENDING);
rating_column.set_cell_data_func (renderer, rating_data_func);
--- /dev/null
+/* This file is part of Cinaest.
+ *
+ * Copyright (C) 2009 Philipp Zabel
+ *
+ * Cinaest is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Cinaest is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Cinaest. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+public class Poster : Object {
+ public Gdk.Pixbuf pixbuf;
+ public Gdk.Pixbuf thumbnail;
+}
+
+public class Movie : Object {
+ public string title { get; set; }
+ public int year { get; set; }
+ public int rating { get; set; }
+ public int genres { get; set; }
+ public Poster poster { get; set; }
+
+ construct {
+ rating = -1;
+ }
+}
+