X-Git-Url: https://vcs.maemo.org/git/?a=blobdiff_plain;f=src%2Fplugins%2Fimdb-plugin.vala;h=64d8bb384d41dbc7a8d11fd256bc117f842fd771;hb=a227131f3236592460414b7f632a82d08c1db0d0;hp=85ece4366f1b19e8203140d493b4b0f83a5f7ae0;hpb=db5ed88f2fb8d2c0d9c73fc9ad53007b1c1de966;p=cinaest diff --git a/src/plugins/imdb-plugin.vala b/src/plugins/imdb-plugin.vala index 85ece43..64d8bb3 100644 --- a/src/plugins/imdb-plugin.vala +++ b/src/plugins/imdb-plugin.vala @@ -23,7 +23,6 @@ class IMDbPlugin : Plugin { private dynamic DBus.Object server; List sources; private weak Osso.Context osso_context; - private Gtk.Window _window; public override void hello (Gtk.Window window, Osso.Context context) { string filename = Path.build_filename (Environment.get_user_cache_dir(), @@ -37,7 +36,7 @@ class IMDbPlugin : Plugin { note.destroy (); if (response == ResponseType.OK) { - download_imdb (window); + download_imdb (window, false); } } @@ -47,13 +46,12 @@ class IMDbPlugin : Plugin { sources.append (source); osso_context = context; - _window = window; // FIXME - this forces the inclusion of config.h (void) Config.GETTEXT_PACKAGE; } - private void download_imdb (Gtk.Window window) { + private void download_imdb (Gtk.Window window, bool plots) { var picker = new PickerDialog (window); var selector = new TouchSelector.text (); string[] mirrors; @@ -82,7 +80,7 @@ class IMDbPlugin : Plugin { picker.destroy(); if (res == ResponseType.OK) { - var download = new IMDbDownloadDialog (window); + var download = new IMDbDownloadDialog (window, plots); download.run (server, mirror); download.destroy (); } @@ -92,25 +90,25 @@ class IMDbPlugin : Plugin { return sources; } - public override List get_actions (Movie movie) { + public override List get_actions (Movie movie, Gtk.Window window) { List list = null; if (movie.year > 0) - list.append (new MovieAction (_("IMDb page"), on_visit_imdb, movie)); + list.append (new MovieAction (_("IMDb page"), on_visit_imdb, movie, window)); else - list.append (new MovieAction (_("Lookup on IMDb"), on_visit_imdb, movie)); + list.append (new MovieAction (_("Lookup on IMDb"), on_visit_imdb, movie, window)); return list; } - private void on_visit_imdb (Movie movie) { + private void on_visit_imdb (Movie movie, Gtk.Window window) { var url = "http://www.imdb.com/find?s=tt&q=" + movie.title.replace(" ", "+"); if (movie.year > 0) url += "+(%d)".printf (movie.year); var status = osso_context.rpc_run_with_defaults ("osso_browser", "open_new_window", null, 's', url, 'b', false); if (status != Osso.Status.OK) { - var banner = (Banner) Hildon.Banner.show_information_with_markup (_window, null, "Failed to open browser."); + var banner = (Banner) Hildon.Banner.show_information_with_markup (window, null, "Failed to open browser."); banner.set_timeout (1500); } } @@ -120,6 +118,19 @@ class IMDbPlugin : Plugin { dialog.set_transient_for (window); dialog.set_title (_("IMDb plugin settings")); + bool download_plots; + try { + var sqlite = new IMDbSqlite (Path.build_filename (Environment.get_user_cache_dir (), + "cinaest", "imdb.db", null)); + download_plots = sqlite.has_plots (); + } catch (Error e) { + download_plots = false; + } + + var plots = new Hildon.CheckButton (SizeType.FINGER_HEIGHT); + plots.set_label (_("Download and store movie plots")); + plots.set_active (download_plots); + string updated; string filename = Path.build_filename (Environment.get_user_cache_dir(), "cinaest", "imdb.db", null); @@ -141,10 +152,16 @@ class IMDbPlugin : Plugin { var download = new Hildon.Button.with_text (SizeType.FINGER_HEIGHT, ButtonArrangement.VERTICAL, _("Download"), _("Last update: ") + updated); VBox content = (VBox) dialog.get_content_area (); + content.pack_start (plots, true, true, 0); content.pack_start (download, true, true, 0); + // Connect signals + plots.toggled.connect (() => { + if (download_plots != plots.get_active ()) + Hildon.Banner.show_information (window, null, _("Redownload the IMDb for this change to take effect.")); + }); download.clicked.connect (() => { - download_imdb (window); + download_imdb (window, plots.get_active ()); }); dialog.show_all (); @@ -157,39 +174,59 @@ class IMDbPlugin : Plugin { } } +class IMDbMovie : Movie { + public override string get_plot () { + var sqlite = new IMDbSqlite (Path.build_filename (Environment.get_user_cache_dir (), + "cinaest", "imdb.db", null)); + print ("IMDb get_plot(\"%s (%d)\")\n", title, year); + return sqlite.get_plot ("%s (%d)".printf (title, year)); + } +} + class IMDBSource : MovieSource { + public override bool active { get; set construct; } + + public IMDBSource () { + GLib.Object (active: true); + } + MovieSource.ReceiveMovieFunction _get_callback; - public override async void get_movies (MovieFilter filter, MovieSource.ReceiveMovieFunction callback, int limit, Cancellable? cancellable) { - // IMDb has too many movies - if (filter.title == "") - return; + public override async int get_movies (MovieFilter filter, MovieSource.ReceiveMovieFunction callback, int limit, Cancellable? cancellable) { var sqlite = new IMDbSqlite (Path.build_filename (Environment.get_user_cache_dir (), "cinaest", "imdb.db", null)); _get_callback = callback; - yield sqlite.query (filter, receive_movie, cancellable); + int n = yield sqlite.query (filter, receive_movie, limit, cancellable); + return n; } - private void receive_movie (string title, int year, int rating, int genres) { - Movie movie = new Movie (); + private void receive_movie (string title, string? aka, int year, int rating, int genres) { + var movie = new IMDbMovie (); movie.title = title; movie.year = year; movie.rating = rating; movie.genres.field = genres; // TODO - depending on settings, this could be something else, like director info or runtime - movie.secondary = movie.genres.to_string (); + if (aka != null) { + movie.secondary = "aka \"%s\" - %s".printf (aka, movie.genres.to_string ()); + } else { + movie.secondary = movie.genres.to_string (); + } _get_callback (movie); } public override void add_movie (Movie movie) { } + public override void delete_movie (Movie movie) { + } + public override unowned string get_name () { return "IMDb"; } public override unowned string get_description () { - return "Movies on IMDb"; + return _("Movies on IMDb"); } public override bool get_editable () { @@ -198,7 +235,7 @@ class IMDBSource : MovieSource { } [ModuleInit] -public Type register_plugin () { +public Type register_plugin (TypeModule module) { // types are registered automatically return typeof (IMDbPlugin); }