X-Git-Url: http://vcs.maemo.org/git/?a=blobdiff_plain;f=src%2Fbackends%2Fgoogle%2Fgoogle-backend.vala;h=1815970a3486c509fd5848c61ecbea9b0e580c4f;hb=45ff969eb86dd5d4b2c9644e7caa99f27c79e051;hp=6a375b81e8631a4276898ef74fd2834ba12bfa6a;hpb=691d0d71efa25af00773285d3eca0845b8734168;p=cinaest diff --git a/src/backends/google/google-backend.vala b/src/backends/google/google-backend.vala index 6a375b8..1815970 100644 --- a/src/backends/google/google-backend.vala +++ b/src/backends/google/google-backend.vala @@ -12,6 +12,9 @@ public class MovieSearch : Object { GLib.List 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 () { @@ -68,7 +73,7 @@ public class MovieSearch : Object { var m = new string[results.length ()]; int i = 0; for (unowned GLib.List node = results.first (); node != null; node = node.next) { - m[i++] = "{\"title\":\"%s\",\"rating\":%f,\"showtimes\":\"%s\",\"cinema_name\":\"%s\",\"cinema_phone\":\"%s\"}".printf (node.data.title, node.data.rating, node.data.showtimes, node.data.cinema.name, node.data.cinema.phone); + m[i++] = "{\"title\":\"%s\",\"rating\":%f,\"runtime\":%d,\"showtimes\":\"%s\",\"cinema_name\":\"%s\",\"cinema_phone\":\"%s\"}".printf (node.data.title, node.data.rating, node.data.runtime, node.data.showtimes, node.data.theater.name, node.data.theater.phone); } movies_found (m, true); service.timeout_quit (); @@ -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 (); // 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);