Plugins: allow returning multiple movies per callback invocation
[cinaest] / src / plugins / google-plugin.vala
index d02b7a8..65abc6f 100644 (file)
@@ -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)
@@ -244,6 +250,7 @@ class GoogleSource : MovieSource {
        private void on_movies_found (DBus.Object sender, string[] movies, bool finished) {
                print ("found %d movies\n", movies.length);
                var parser = new Json.Parser ();
+               var result = new SList<Movie> ();
 
                for (int i = 0; i < movies.length; i++) {
                        var movie = new GoogleMovie ();
@@ -265,9 +272,11 @@ class GoogleSource : MovieSource {
                        else
                                movie.secondary = movie.cinema_name + " - " + movie.showtimes;
 
-                       callback (movie);
+                       result.append (movie);
                }
 
+               callback (result);
+
                if (finished) {
                        search = null;
                        Idle.add (get_movies_callback);
@@ -293,13 +302,13 @@ class GoogleSource : MovieSource {
                return description;
        }
 
-       public override bool get_editable () {
-               return false;
+       public override SourceFlags get_flags () {
+               return SourceFlags.ONLINE;
        }
 }
 
 [ModuleInit]
-public Type register_plugin () {
+public Type register_plugin (TypeModule module) {
        // types are registered automatically
        return typeof (GooglePlugin);
 }