X-Git-Url: http://vcs.maemo.org/git/?a=blobdiff_plain;f=src%2Fplugins%2Fimdb-plugin.vala;h=b8b33ea0e96e143d999d3860947cf6d2b9addfbc;hb=ec13e711f3c3797eb222cdf4d1788030efbf3400;hp=cd045e8840dcebf79ca483a019de3726cf7ef959;hpb=bea1841a949d790b6880d2851d011070c427b644;p=cinaest diff --git a/src/plugins/imdb-plugin.vala b/src/plugins/imdb-plugin.vala index cd045e8..b8b33ea 100644 --- a/src/plugins/imdb-plugin.vala +++ b/src/plugins/imdb-plugin.vala @@ -22,8 +22,9 @@ using Hildon; class IMDbPlugin : Plugin { private dynamic DBus.Object server; List sources; + private weak Osso.Context osso_context; - public override void hello (Gtk.Window window) { + public override void hello (Gtk.Window window, Osso.Context context) { string filename = Path.build_filename (Environment.get_user_cache_dir(), "cinaest", "imdb.db", null); stdout.printf ("IMDb Plugin Loaded. Cache Db: %s\n", filename); @@ -43,6 +44,11 @@ class IMDbPlugin : Plugin { sources = new List (); sources.append (source); + + osso_context = context; + + // FIXME - this forces the inclusion of config.h + (void) Config.GETTEXT_PACKAGE; } private void download_imdb (Gtk.Window window) { @@ -83,29 +89,112 @@ class IMDbPlugin : Plugin { public override unowned List get_sources () { return sources; } + + 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, window)); + else + list.append (new MovieAction (_("Lookup on IMDb"), on_visit_imdb, movie, window)); + + return list; + } + + 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."); + banner.set_timeout (1500); + } + } + + public override void settings_dialog (Gtk.Window window) { + var dialog = new Gtk.Dialog (); + dialog.set_transient_for (window); + dialog.set_title (_("IMDb plugin settings")); + + string updated; + string filename = Path.build_filename (Environment.get_user_cache_dir(), + "cinaest", "imdb.db", null); + var file = File.new_for_path (filename); + try { + var info = file.query_info (FILE_ATTRIBUTE_TIME_MODIFIED, FileQueryInfoFlags.NONE, null); + TimeVal tv; + info.get_modification_time (out tv); + + var date = Date (); + date.set_time_val (tv); + char[] s = new char[64]; + date.strftime (s, "%x"); + updated = (string) s; + } catch (Error e) { + updated = _("unknown"); + } + + 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 (download, true, true, 0); + + download.clicked.connect (() => { + download_imdb (window); + }); + + dialog.show_all (); + dialog.run (); + dialog.destroy (); + } + + public override unowned string get_name () { + return "IMDb"; + } } class IMDBSource : MovieSource { + public override bool active { get; set construct; } + + public IMDBSource () { + GLib.Object (active: true); + } + MovieSource.ReceiveMovieFunction _get_callback; - public override void get_movies (string filter, MovieSource.ReceiveMovieFunction callback, int limit) { + public override async void get_movies (MovieFilter filter, MovieSource.ReceiveMovieFunction callback, int limit, Cancellable? cancellable) { + // IMDb has too many movies + if (filter.title == "" && filter.year_min == 0 && filter.year_max == 0 && filter.genres.field == 0 && filter.rating_min == 0) + return; var sqlite = new IMDbSqlite (Path.build_filename (Environment.get_user_cache_dir (), "cinaest", "imdb.db", null)); _get_callback = callback; - sqlite.query (filter, receive_movie); + yield sqlite.query (filter, receive_movie, limit, cancellable); } - private void receive_movie (string title, int year, int rating) { + private void receive_movie (string title, string? aka, int year, int rating, int genres) { Movie movie = new Movie (); 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 + 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"; } @@ -113,6 +202,10 @@ class IMDBSource : MovieSource { public override unowned string get_description () { return "Movies on IMDb"; } + + public override bool get_editable () { + return false; + } } [ModuleInit]