Google backend: align with MoviePilot backend
authorPhilipp Zabel <philipp.zabel@gmail.com>
Thu, 8 Jul 2010 19:45:41 +0000 (21:45 +0200)
committerPhilipp Zabel <philipp.zabel@gmail.com>
Wed, 14 Jul 2010 21:34:09 +0000 (23:34 +0200)
src/backends/google/google-backend.vala

index 1b78685..7e4d89e 100644 (file)
@@ -12,6 +12,9 @@ public class MovieSearch : Object {
        GLib.List<GoogleMovie> results;
        GoogleMovieService service;
 
+       public string path;
+       public string sender;
+
        // D-Bus API
 
        public void abort () {
@@ -30,8 +33,10 @@ public class MovieSearch : Object {
 
        // Internal methods
 
-       internal MovieSearch (GoogleMovieService _service) {
+       internal MovieSearch (GoogleMovieService _service, string _sender, string _path) {
                service = _service;
+               sender = _sender;
+               path = _path;
        }
 
        private async void query_async () {
@@ -102,25 +107,25 @@ public class MovieSearch : Object {
 public class GoogleMovieService : Object {
        private MainLoop loop;
        private uint source_id;
+       int id = 0;
 
        // D-Bus API
 
        public string new_search (DBus.BusName sender) {
-               print ("new search requested by %s\n", sender);
-               var search = new MovieSearch (this);
-
-               search.id = searches.size;
-               string path = "/org/maemo/cinaest/googleshowtimes/search%d".printf (search.id);
+               var path = "/org/maemo/cinaest/moviepilot/search%d".printf (id);
+               var search = new MovieSearch (this, sender, path);
+               search.id = id++;
                conn.register_object (path, search);
 
+               print ("creating new search %s for %s\n", path, sender);
                searches.set (path, search);
 
                return path;
        }
 
        public void unregister (string path) {
+               print ("unregistering search %s\n", path);
 
-       print ("unregistering %s\n", path);
                searches.remove (path);
                print ("%d\n", searches.size);
        }
@@ -153,15 +158,21 @@ public class GoogleMovieService : Object {
 
 void on_client_lost (DBus.Object sender, string name, string prev, string newp) {
        if (newp == "") {
+               var remove_list = new SList<string> ();
                // We lost a client
-               print ("lost a client: prev:%s\n", prev);
-               searches.remove (prev);
+               print ("lost a client: %s\n", prev);
+               foreach (MovieSearch search in searches.values) {
+                       if (search.sender == prev) {
+                               print ("removing %s\n", search.path);
+                               remove_list.append (search.path);
+                       }
+               }
+               foreach (string path in remove_list)
+                       searches.remove (path);
        }
 }
 
 void main () {
-       var loop = new MainLoop (null, false);
-
        try {
                conn = DBus.Bus.get (DBus.BusType. SESSION);
 
@@ -176,7 +187,7 @@ void main () {
                if (res == DBus.RequestNameReply.PRIMARY_OWNER) {
                        var server = new GoogleMovieService ();
 
-                       conn.register_object ("/org/maemo/cinaest/movies", server);
+                       conn.register_object ("/org/maemo/cinaest/googleshowtimes", server);
 
                        bus.NameOwnerChanged.connect (on_client_lost);