From: Philipp Zabel Date: Tue, 10 Nov 2009 19:18:30 +0000 (+0100) Subject: Google poster downloader: add unqueue method, make downloads cancellable X-Git-Tag: v0.0.4~17 X-Git-Url: http://vcs.maemo.org/git/?a=commitdiff_plain;h=52b7b48e0102fc22f46c8b67f6df6a6d7b38a2f9;p=cinaest Google poster downloader: add unqueue method, make downloads cancellable --- diff --git a/src/poster/google-poster-downloader.vala b/src/poster/google-poster-downloader.vala index d12cacb..5dee8c2 100644 --- a/src/poster/google-poster-downloader.vala +++ b/src/poster/google-poster-downloader.vala @@ -4,6 +4,7 @@ using GLib; public interface Provider { public abstract int Fetch (string title, string year, string kind) throws DBus.Error; public abstract int FetchThumbnail (string title, string year, string kind) throws DBus.Error; + public abstract void Unqueue (int handle) throws DBus.Error; public signal void fetched (int handle, string path); } @@ -16,6 +17,7 @@ public interface Provider { public class GoogleImages : Object, Provider { int fetch_handle; + Cancellable cancellable; public int Fetch (string title, string year, string kind) throws DBus.Error { int handle = fetch_handle++; @@ -31,6 +33,11 @@ public class GoogleImages : Object, Provider { return handle; } + public void Unqueue (int handle) { + // FIXME - cancel everything for now + cancellable.cancel (); + } + private async void _fetch_async (string title, string year, string kind, bool thumbnail, int handle) { uint u = 0; size_t hread = 0; @@ -38,6 +45,9 @@ public class GoogleImages : Object, Provider { string stitched = ""; bool first = true; + // FIXME - cancel everything for now + cancellable = new Cancellable (); + stdout.printf ("Fetching %s \"%s (%s)\" ...\n", kind, title, year); if (title == null || title == "") @@ -88,8 +98,12 @@ public class GoogleImages : Object, Provider { InputStream stream = google_search.read (null); while (total < 40000) { - hread = yield stream.read_async ((char *)buffer + total, 40000 - total, Priority.DEFAULT_IDLE, null); + hread = yield stream.read_async ((char *)buffer + total, 40000 - total, Priority.DEFAULT_IDLE, cancellable); total += hread; + if (cancellable.is_cancelled ()) { + stdout.printf ("CANCELED\n"); + return; + } if (hread == 0) break; } @@ -160,8 +174,12 @@ public class GoogleImages : Object, Provider { yield online_image.copy_async (cache_image, FileCopyFlags.NONE, Priority.DEFAULT_IDLE, - null, + cancellable, null); + if (cancellable.is_cancelled ()) { + stdout.printf ("CANCELED\n"); + return; + } FileUtils.rename (cache_path + ".part", cache_path);