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/>.
22 class IMDbPlugin : Plugin {
23 private dynamic DBus.Object server;
24 List<MovieSource> sources;
26 public override void hello (Gtk.Window window) {
27 string filename = Path.build_filename (Environment.get_user_cache_dir(),
28 "cinaest", "imdb.db", null);
29 stdout.printf ("IMDb Plugin Loaded. Cache Db: %s\n", filename);
31 if (!FileUtils.test (filename, FileTest.EXISTS)) {
32 var note = new Note.confirmation (window, "There is no local copy of the Internet Movie Database (IMDb). Download it now?\n\nThis can be started later from the Settings dialog.");
34 var response = note.run ();
37 if (response == ResponseType.OK) {
38 download_imdb (window);
42 var source = new IMDBSource ();
44 sources = new List<MovieSource> ();
45 sources.append (source);
47 // FIXME - this forces the inclusion of config.h
48 (void) Config.GETTEXT_PACKAGE;
51 private void download_imdb (Gtk.Window window) {
52 var picker = new PickerDialog (window);
53 var selector = new TouchSelector.text ();
57 var conn = DBus.Bus.get (DBus.BusType.SESSION);
58 server = conn.get_object (IMDbDownloader.DBUS_SERVICE,
59 IMDbDownloader.DBUS_OBJECT,
60 IMDbDownloader.DBUS_IFACE);
62 mirrors = server.get_mirrors ();
63 } catch (DBus.Error e) {
64 warning ("Failed connect to IMDb downloader: %s", e.message);
68 foreach (string mirror in mirrors) {
69 selector.append_text (mirror);
72 picker.set_title ("Please select a source mirror");
73 picker.set_selector (selector);
75 int res = picker.run();
76 string mirror = selector.get_current_text ();
79 if (res == ResponseType.OK) {
80 var download = new IMDbDownloadDialog (window);
81 download.run (server, mirror);
86 public override unowned List<MovieSource> get_sources () {
90 public override void settings_dialog (Gtk.Window window) {
91 var dialog = new Gtk.Dialog ();
92 dialog.set_transient_for (window);
93 dialog.set_title (_("IMDb plugin settings"));
95 string filename = Path.build_filename (Environment.get_user_cache_dir(),
96 "cinaest", "imdb.db", null);
97 var file = File.new_for_path (filename);
98 var info = file.query_info (FILE_ATTRIBUTE_TIME_MODIFIED, FileQueryInfoFlags.NONE, null);
100 info.get_modification_time (out tv);
103 date.set_time_val (tv);
104 char[] s = new char[64];
105 date.strftime (s, "%x");
107 var download = new Hildon.Button.with_text (SizeType.FINGER_HEIGHT, ButtonArrangement.VERTICAL, _("Download"), "Last update: " + (string) s);
109 VBox content = (VBox) dialog.get_content_area ();
110 content.pack_start (download, true, true, 0);
112 download.clicked.connect (() => {
113 download_imdb (window);
121 public override unowned string get_name () {
126 class IMDBSource : MovieSource {
127 MovieSource.ReceiveMovieFunction _get_callback;
128 public override void get_movies (MovieFilter filter, MovieSource.ReceiveMovieFunction callback, int limit) {
129 // IMDb has too many movies
130 if (filter.title == "")
132 var sqlite = new IMDbSqlite (Path.build_filename (Environment.get_user_cache_dir (),
133 "cinaest", "imdb.db", null));
135 _get_callback = callback;
136 sqlite.query (filter, receive_movie);
139 private void receive_movie (string title, int year, int rating, int genres) {
140 Movie movie = new Movie ();
143 movie.rating = rating;
144 movie.genres.field = genres;
145 // TODO - depending on settings, this could be something else, like director info or runtime
146 movie.secondary = movie.genres.to_string ();
147 _get_callback (movie);
150 public override void add_movie (Movie movie) {
153 public override unowned string get_name () {
157 public override unowned string get_description () {
158 return "Movies on IMDb";
163 public Type register_plugin () {
164 // types are registered automatically
165 return typeof (IMDbPlugin);