X-Git-Url: http://vcs.maemo.org/git/?a=blobdiff_plain;f=src%2Fplugins%2Fimdb-plugin.vala;h=1fb5d8e0e2d7d9e4a750ff3a8ba4e06f8518c437;hb=d3bbd5f87a7a48f6aa2e2d43bb440a77ab4ef749;hp=e60e6c34e908aca261442eef5e1f33b689bf2833;hpb=9519b2f0c86fcbe2036db8dee7aa7c93271502ae;p=cinaest diff --git a/src/plugins/imdb-plugin.vala b/src/plugins/imdb-plugin.vala index e60e6c3..1fb5d8e 100644 --- a/src/plugins/imdb-plugin.vala +++ b/src/plugins/imdb-plugin.vala @@ -36,7 +36,7 @@ class IMDbPlugin : Plugin { note.destroy (); if (response == ResponseType.OK) { - download_imdb (window); + download_imdb (window, false); } } @@ -51,7 +51,7 @@ class IMDbPlugin : Plugin { (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; @@ -80,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 (); } @@ -118,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); @@ -139,10 +152,38 @@ 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); + var sizegroup = new Gtk.SizeGroup (SizeGroupMode.HORIZONTAL); + + // User name + var hbox = new Gtk.HBox (false, MARGIN_DOUBLE); + var label = new Gtk.Label (_("User name")); + sizegroup.add_widget (label); + var entry = new Hildon.Entry (SizeType.FINGER_HEIGHT); + hbox.pack_start (label, false, false, 0); + hbox.pack_start (entry, true, true, 0); + content.pack_start (hbox, true, true, 0); + + // Password + hbox = new Gtk.HBox (false, MARGIN_DOUBLE); + label = new Gtk.Label ("Password"); + sizegroup.add_widget (label); + entry = new Hildon.Entry (SizeType.FINGER_HEIGHT); + hbox.pack_start (label, false, false, 0); + hbox.pack_start (entry, true, true, 0); + content.pack_start (hbox, true, true, 0); + + dialog.add_button (_("Save"), ResponseType.ACCEPT); + + // 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 (); @@ -155,7 +196,19 @@ 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 { + SList result; + int results_waiting; + public override bool active { get; set construct; } public IMDBSource () { @@ -163,19 +216,22 @@ class IMDBSource : MovieSource { } 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 == "" && filter.year_min == 0 && filter.year_max == 0 && filter.genres.field == 0 && filter.rating_min == 0) - 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, limit, cancellable); + result = new SList (); + results_waiting = 0; + int n = yield sqlite.query (filter, receive_movie, limit, cancellable); + if (results_waiting > 0) + _get_callback (result); + result = new SList (); + return n; } private void receive_movie (string title, string? aka, int year, int rating, int genres) { - Movie movie = new Movie (); + var movie = new IMDbMovie (); movie.title = title; movie.year = year; movie.rating = rating; @@ -186,7 +242,12 @@ class IMDBSource : MovieSource { } else { movie.secondary = movie.genres.to_string (); } - _get_callback (movie); + result.append (movie); + if (++results_waiting >= 10) { + _get_callback (result); + result = new SList (); + results_waiting = 0; + } } public override void add_movie (Movie movie) { @@ -203,13 +264,13 @@ class IMDBSource : MovieSource { return _("Movies on IMDb"); } - public override bool get_editable () { - return false; + public override SourceFlags get_flags () { + return 0; } } [ModuleInit] -public Type register_plugin () { +public Type register_plugin (TypeModule module) { // types are registered automatically return typeof (IMDbPlugin); }