X-Git-Url: https://vcs.maemo.org/git/?a=blobdiff_plain;f=src%2Fposter%2Fmovie-poster-factory.vala;h=b979cd23591f769568821f657bc18abe1090a110;hb=42da3f4e9c3108d28e9bd9e8b24fff78cc685606;hp=095af927e470b8521ae4f185a381e588a7e92dbe;hpb=69b7ed27cb6719747d9c3a62735d529d55f07ff0;p=cinaest diff --git a/src/poster/movie-poster-factory.vala b/src/poster/movie-poster-factory.vala index 095af92..b979cd2 100644 --- a/src/poster/movie-poster-factory.vala +++ b/src/poster/movie-poster-factory.vala @@ -33,18 +33,23 @@ namespace MoviePoster { construct { try { var conn = DBus.Bus.get (DBus.BusType.SESSION); - server = conn.get_object ("org.maemo.movieposter.GoogleImages", - "/org/maemo/movieposter/GoogleImages", + server = conn.get_object ("org.maemo.movieposter.IMDb", + "/org/maemo/movieposter/IMDb", "org.maemo.movieposter.Provider"); - server.Fetched += this.on_poster_fetched; + server.Fetched.connect (this.on_poster_fetched); + server.Failed.connect (this.on_poster_failed); } catch (Error e) { - warning ("Couldn't connect to Google image downloader: %s\n", e.message); + warning ("Couldn't connect to IMDb poster downloader: %s\n", e.message); } gc = GConf.Client.get_default (); - download_posters = gc.get_bool ("/apps/cinaest/download_posters"); - gc.add_dir ("/apps/cinaest", GConf.ClientPreloadType.ONELEVEL); - cxnid = gc.notify_add ("/apps/cinaest/download_posters", on_download_posters_changed); + try { + download_posters = gc.get_bool ("/apps/cinaest/download_posters"); + gc.add_dir ("/apps/cinaest", GConf.ClientPreloadType.ONELEVEL); + cxnid = gc.notify_add ("/apps/cinaest/download_posters", on_download_posters_changed); + } catch (Error e) { + stdout.printf ("Error installing GConf notification: %s\n", e.message); + } } private static void on_download_posters_changed (GConf.Client gc, uint cxnid, GConf.Entry entry) { @@ -67,7 +72,7 @@ namespace MoviePoster { } else if (server != null && download_posters) { var request = new Request (); - request.handle = server.fetch (movie.title.down (), movie.year.to_string (), "movie"); + request.handle = server.Fetch (movie.title, movie.year.to_string (), "movie"); request.movie = movie; request.callback = callback; request.width = 268; @@ -80,14 +85,19 @@ namespace MoviePoster { public int queue_thumbnail (Movie movie, uint width, uint height, bool cropped, RequestCallback callback) throws Error { string path = get_path_thumbnail (movie); + foreach (Request request in requests) + if (request.movie == movie) + return 0; + if (FileUtils.test (path, FileTest.IS_REGULAR)) { // TODO: make this async? - var pixbuf = new Gdk.Pixbuf.from_file_at_size (path, (int) width, (int) height); + var pixbuf = new Gdk.Pixbuf.from_file_at_scale (path, (int) width, (int) height, true); + callback (pixbuf, movie); } else if (server != null && download_posters) { var request = new Request (); - request.handle = server.fetch_thumbnail (movie.title.down (), movie.year.to_string (), "movie"); + request.handle = server.FetchThumbnail (movie.title, movie.year.to_string (), "movie"); request.movie = movie; request.callback = callback; request.width = (int) width; @@ -118,6 +128,20 @@ namespace MoviePoster { } } + private void on_poster_failed (dynamic DBus.Object server, int handle) { + Request request = null; + foreach (Request r in requests) { + if (r.handle == handle) { + request = r; + break; + } + } + if (request == null) + return; + requests.remove (request); + // request.callback (pixbuf, request.movie); + } + public void join () { } @@ -130,7 +154,7 @@ namespace MoviePoster { public void clear_queue () { if (server != null) { foreach (Request r in requests) - server.unqueue (r.handle); + server.Unqueue (r.handle); } requests = null; } @@ -145,7 +169,7 @@ namespace MoviePoster { public void unqueue () { if (Factory.get_instance ().server != null) - Factory.get_instance ().server.unqueue (this.handle); + Factory.get_instance ().server.Unqueue (this.handle); Factory.get_instance ().requests.remove (this); }