IMDb plugin: add movie action to open the IMDb web page for a given movie
authorPhilipp Zabel <philipp.zabel@gmail.com>
Thu, 12 Nov 2009 14:26:09 +0000 (15:26 +0100)
committerPhilipp Zabel <philipp.zabel@gmail.com>
Thu, 12 Nov 2009 18:23:25 +0000 (19:23 +0100)
src/plugins/imdb-plugin.vala

index 008f001..797def1 100644 (file)
@@ -23,6 +23,7 @@ class IMDbPlugin : Plugin {
        private dynamic DBus.Object server;
        List<MovieSource> 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(),
@@ -46,6 +47,7 @@ class IMDbPlugin : Plugin {
                sources.append (source);
 
                osso_context = context;
+               _window = window;
 
                // FIXME - this forces the inclusion of config.h
                (void) Config.GETTEXT_PACKAGE;
@@ -93,9 +95,26 @@ class IMDbPlugin : Plugin {
        public override List<MovieAction> get_actions (Movie movie) {
                List<MovieAction> list = null;
 
+               if (movie.year > 0)
+                       list.append (new MovieAction (_("IMDb page"), on_visit_imdb, movie));
+               else
+                       list.append (new MovieAction (_("Lookup on IMDb"), on_visit_imdb, movie));
+
                return list;
        }
 
+       private void on_visit_imdb (Movie movie) {
+               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);