X-Git-Url: https://vcs.maemo.org/git/?a=blobdiff_plain;f=src%2Fposter%2Fmovie-poster-factory.vala;h=f665d7805263cd15a873a5f6e5b4849aab32b692;hb=ca44287bed0bc2cfa94425ac9a318bbcd6d4badf;hp=d7cff953f1f065abc5bd211e521bb5eee8266609;hpb=4d7936832ef3c56a6b481287f09183f978c5eefb;p=cinaest diff --git a/src/poster/movie-poster-factory.vala b/src/poster/movie-poster-factory.vala index d7cff95..f665d78 100644 --- a/src/poster/movie-poster-factory.vala +++ b/src/poster/movie-poster-factory.vala @@ -1,3 +1,21 @@ +/* This file is part of Cinaest. + * + * Copyright (C) 2009 Philipp Zabel + * + * Cinaest is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Cinaest is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Cinaest. If not, see . + */ + using GLib; namespace MoviePoster { @@ -6,8 +24,8 @@ namespace MoviePoster { public class Factory : Object { private static Factory the_factory = null; - private List requests; - dynamic DBus.Object server; + internal List requests; + internal dynamic DBus.Object server; internal bool download_posters; private GConf.Client gc; private uint cxnid; @@ -24,9 +42,13 @@ namespace MoviePoster { } 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) { @@ -49,7 +71,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.down (), movie.year.to_string (), "movie"); request.movie = movie; request.callback = callback; request.width = 268; @@ -69,7 +91,7 @@ namespace MoviePoster { } 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.down (), movie.year.to_string (), "movie"); request.movie = movie; request.callback = callback; request.width = (int) width; @@ -80,19 +102,24 @@ namespace MoviePoster { } private void on_poster_fetched (dynamic DBus.Object server, int handle, string path) { - foreach (Request request in requests) { - if (request.handle != handle) - continue; - try { - var pixbuf = new Gdk.Pixbuf.from_file_at_size (path, request.width, request.height); - - requests.remove (request); - request.callback (pixbuf, request.movie); - return; - } catch (Error e) { - warning ("Failed to open poster: %s\n", e.message); + Request request = null; + foreach (Request r in requests) { + if (r.handle == handle) { + request = r; + break; } } + if (request == null) + return; + try { + var pixbuf = new Gdk.Pixbuf.from_file_at_size (path, request.width, request.height); + + requests.remove (request); + request.callback (pixbuf, request.movie); + return; + } catch (Error e) { + warning ("Failed to open poster: %s\n", e.message); + } } public void join () { @@ -103,6 +130,14 @@ namespace MoviePoster { public static void factory_clean_cache (int max_size, time_t min_mtime) { } + + public void clear_queue () { + if (server != null) { + foreach (Request r in requests) + server.Unqueue (r.handle); + } + requests = null; + } } public class Request { @@ -113,6 +148,10 @@ namespace MoviePoster { public int height; public void unqueue () { + if (Factory.get_instance ().server != null) + Factory.get_instance ().server.Unqueue (this.handle); + + Factory.get_instance ().requests.remove (this); } public void join () {