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);
}
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++;
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;
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 == "")
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;
}
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);