+
+ public override List<MovieAction> get_actions (Movie movie, Gtk.Window window) {
+ List<MovieAction> 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"));
+
+ bool download_plots;
+ bool download_actors;
+ try {
+ var sqlite = new IMDbSqlite (Path.build_filename (Environment.get_user_cache_dir (),
+ "cinaest", "imdb.db", null));
+ download_plots = sqlite.has_table ("Plots");
+ download_actors = sqlite.has_table ("Actors");
+ } catch (Error e) {
+ download_plots = false;
+ download_actors = false;
+ }
+
+ var plots = new Hildon.CheckButton (SizeType.FINGER_HEIGHT);
+ plots.set_label (_("Download and store movie plots"));
+ plots.set_active (download_plots);
+
+ var actors = new Hildon.CheckButton (SizeType.FINGER_HEIGHT);
+ actors.set_label (_("Download and store actors and actresses"));
+ actors.set_active (download_actors);
+
+ 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 (plots, true, true, 0);
+ content.pack_start (actors, 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"));
+ label.set_alignment (0, 0.5f);
+ 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"));
+ label.set_alignment (0, 0.5f);
+ 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."));
+ });
+ actors.toggled.connect (() => {
+ if (download_actors != actors.get_active ())
+ Hildon.Banner.show_information (window, null, _("Redownload the IMDb for this change to take effect."));
+ });
+ download.clicked.connect (() => {
+ download_imdb (window, plots.get_active (), actors.get_active ());
+ });
+
+ dialog.show_all ();
+ dialog.run ();
+ dialog.destroy ();
+ }
+
+ public override unowned string get_name () {
+ return "IMDb";
+ }
+}
+
+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));
+ }