This wraps the genres bitfield and provides utility functions like to_string.
# Sources
cinaest_SOURCES = \
src/main.c \
+ src/genres.c \
src/movie.c \
src/movie-filter.c \
src/movie-list-menu.c \
cinaest_VALASOURCES = \
src/main.vala \
+ src/genres.vala \
src/movie.vala \
src/movie-filter.vala \
src/movie-list-menu.vala \
libimdb_plugin_la_SOURCES = \
src/plugins/imdb-plugin.c \
+ src/genres.c \
src/imdb/imdb-sqlite.c \
src/movie.c \
src/plugin-interface.c \
libimdb_plugin_la_VALASOURCES = \
src/plugins/imdb-plugin.vala \
+ src/genres.vala \
src/imdb/imdb-sqlite.vala \
src/imdb/plaintext-downloader-interface.vala \
src/movie.vala \
imdb_plaintext_downloader_VALASOURCES = \
src/imdb/imdb-plaintext-downloader.vala \
+ src/genres.vala \
src/imdb/gzip-input-stream.vala \
src/imdb/imdb-sqlite.vala \
src/imdb/plaintext-downloader-interface.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/>.
+ */
+
+public enum GenreType {
+ ANIMATION = 0,
+ ADULT,
+ DRAMA,
+ SHORT,
+ ACTION,
+ FANTASY,
+ HORROR,
+ SCIFI,
+ THRILLER,
+ BIOGRAPHY,
+ COMEDY,
+ MUSICAL,
+ ADVENTURE,
+ DOCUMENTARY,
+ CRIME,
+ MUSIC,
+ SPORT,
+ ROMANCE,
+ HISTORY,
+ MYSTERY,
+ WAR,
+ WESTERN,
+ FAMILY,
+ TALKSHOW,
+ REALITYTV,
+ GAMESHOW,
+ NEWS,
+ FILMNOIR
+}
+
+public struct Genres {
+ private static const string[] _genre_string = {
+ "Animation",
+ "Adult",
+ "Drama",
+ "Short",
+ "Action",
+ "Fantasy",
+ "Horror",
+ "Sci-Fi",
+ "Thriller",
+ "Biography",
+ "Comedy",
+ "Musical",
+ "Adventure",
+ "Documentary",
+ "Crime",
+ "Music",
+ "Sport",
+ "Romance",
+ "History",
+ "Mystery",
+ "War",
+ "Western",
+ "Family",
+ "Talk-Show",
+ "Game-Show",
+ "News",
+ "Film-Noir"
+ };
+
+ public int field;
+
+ public string to_string () {
+ string s = null;
+
+ for (int i = 0; i < 28; i++) {
+ if ((1 << i) in field) {
+ if (s == null) {
+ s = _genre_string[i];
+ } else {
+ s += ", " + _genre_string[i];
+ }
+ }
+ }
+
+ return s;
+ }
+
+ public void set_bit (GenreType genre, bool enable) {
+ if (enable)
+ field |= (1 << genre);
+ else
+ field &= ~(1 << genre);
+ }
+
+ public bool get_bit (GenreType genre) {
+ return (genre in field);
+ }
+
+ public static unowned string genre_string (GenreType genre) {
+ return _genre_string[genre];
+ }
+
+/*
+ public static int genre_bit (string genre) {
+ int i = 0;
+
+ do {
+ if (_genres[i] == genre) {
+ return (1 << i);
+ }
+ } while (++i < 28);
+
+ return 0;
+ }
+*/
+}
+
Database db;
List<string> genres;
- public delegate void ReceiveMovieFunction (string title, int year, int rating);
+ public delegate void ReceiveMovieFunction (string title, int year, int rating, int genres);
public IMDbSqlite (string filename) {
int rc;
}
public int query (MovieFilter filter, ReceiveMovieFunction receive_movie) {
- var sql = "SELECT Title, Year, Rating FROM Movies";
+ var sql = "SELECT Title, Year, Rating, Genres FROM Movies";
var sep = " WHERE ";
Statement stmt;
int rc;
sql += sep + "Rating >= = %d".printf (filter.rating_min);
sep = " AND ";
}
- if (filter.genres > 0) {
- sql += sep + "Genres&%d = %d".printf (filter.genres, filter.genres);
+ if (filter.genres.field != 0) {
+ sql += sep + "Genres&%d = %d".printf (filter.genres.field, filter.genres.field);
}
sql += " LIMIT %d;".printf (100);
string title = stmt.column_text (0);
int year = stmt.column_int (1);
int rating = stmt.column_int (2);
- receive_movie (title, year, rating);
+ int genres = stmt.column_int (3);
+ receive_movie (title, year, rating, genres);
}
} while (rc == Sqlite.ROW);
public int year_min;
public int year_max;
public int rating_min;
- public int genres;
+ public Genres genres;
}
public string title { get; set; }
public int year { get; set; }
public int rating { get; set; }
- public int genres { get; set; }
+ public Genres genres;
public Poster poster { get; set; }
construct {
sqlite.query (filter, receive_movie);
}
- private void receive_movie (string title, int year, int rating) {
+ private void receive_movie (string title, int year, int rating, int genres) {
Movie movie = new Movie ();
movie.title = title;
movie.year = year;
movie.rating = rating;
+ movie.genres.field = genres;
_get_callback (movie);
}