Google plugin: report D-Bus errors
[cinaest] / src / plugins / google-plugin.vala
index 5491a6d..600c407 100644 (file)
@@ -22,7 +22,7 @@ using Hildon;
 public class GoogleMovie : Movie {
        public string cinema_name;
        public string cinema_phone;
-       public string runtime;
+       public int runtime;
        public string showtimes;
 }
 
@@ -96,7 +96,7 @@ class GooglePlugin : Plugin {
                        timeinfo.hour = hour;
                        showtime = timeinfo.mktime ();
 
-                       int runtime = 3600 * movie.runtime.to_int () + 60 * movie.runtime.str ("hr ").offset (3).to_int ();
+                       int runtime = movie.runtime;
                        if (runtime == 0) {
                                // Default to 120min if we failed to parse the runtime
                                runtime = 7200;
@@ -210,21 +210,27 @@ class GoogleSource : MovieSource {
 
        SourceFunc get_movies_callback;
        public override async int get_movies (MovieFilter filter, MovieSource.ReceiveMovieFunction _callback, int limit, Cancellable? cancellable) {
-               var conn = DBus.Bus.get (DBus.BusType.SESSION);
-               string search_path;
-
-               dynamic DBus.Object server = conn.get_object ("org.maemo.cinaest.GoogleShowtimes",
-                                                             "/org/maemo/cinaest/googleshowtimes",
-                                                             "org.maemo.cinaest.MovieService");
-               server.NewSearch (out search_path);
-
-               search = conn.get_object ("org.maemo.cinaest.GoogleShowtimes",
-                                         search_path,
-                                         "org.maemo.cinaest.MovieSearch");
-
-               callback = _callback;
-               search.MoviesFound += on_movies_found;
-               search.start (filter.title);
+               try {
+                       string search_path;
+                       dynamic DBus.Object server;
+                       var conn = DBus.Bus.get (DBus.BusType.SESSION);
+
+                       server = conn.get_object ("org.maemo.cinaest.GoogleShowtimes",
+                                                 "/org/maemo/cinaest/googleshowtimes",
+                                                 "org.maemo.cinaest.MovieService");
+                       server.NewSearch (out search_path);
+
+                       search = conn.get_object ("org.maemo.cinaest.GoogleShowtimes",
+                                                 search_path,
+                                                 "org.maemo.cinaest.MovieSearch");
+
+                       callback = _callback;
+                       search.MoviesFound.connect (on_movies_found);
+                       search.start (filter.title);
+               } catch (Error e1) {
+                       Banner.show_information (null, null, e1.message);
+                       return 0;
+               }
 
                get_movies_callback = get_movies.callback;
                if (cancellable != null)
@@ -258,8 +264,12 @@ class GoogleSource : MovieSource {
                        movie.rating = (int) object.get_double_member ("rating");
                        movie.cinema_name = object.get_string_member ("cinema_name");
                        movie.cinema_phone = object.get_string_member ("cinema_phone");
+                       movie.runtime = (int) object.get_int_member ("runtime");
                        movie.showtimes = object.get_string_member ("showtimes");
-                       movie.secondary = movie.cinema_name + " - " + movie.showtimes;
+                       if (movie.runtime > 0)
+                               movie.secondary = "%d min - %s - %s".printf (movie.runtime / 60, movie.cinema_name, movie.showtimes);
+                       else
+                               movie.secondary = movie.cinema_name + " - " + movie.showtimes;
 
                        callback (movie);
                }
@@ -295,7 +305,7 @@ class GoogleSource : MovieSource {
 }
 
 [ModuleInit]
-public Type register_plugin () {
+public Type register_plugin (TypeModule module) {
        // types are registered automatically
        return typeof (GooglePlugin);
 }