[gnome-boxes] downloader: Allow tracking of download progress
- From: Zeeshan Ali Khattak <zeeshanak src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-boxes] downloader: Allow tracking of download progress
- Date: Fri, 21 Dec 2012 19:19:32 +0000 (UTC)
commit 1ea950b73cc008437dc6dbaf1262ac535b01c989
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date: Mon Dec 17 04:55:17 2012 +0200
downloader: Allow tracking of download progress
https://bugzilla.gnome.org/show_bug.cgi?id=690321
src/downloader.vala | 20 ++++++++++++++++++--
1 files changed, 18 insertions(+), 2 deletions(-)
---
diff --git a/src/downloader.vala b/src/downloader.vala
index 3392b1f..749116f 100644
--- a/src/downloader.vala
+++ b/src/downloader.vala
@@ -42,12 +42,14 @@ private class Boxes.Downloader : GLib.Object {
session.add_feature_by_type (typeof (Soup.ProxyResolverDefault));
}
- public async File download (File remote_file, string cached_path) throws GLib.Error {
+ public async File download (File remote_file,
+ string cached_path,
+ ActivityProgress progress = new ActivityProgress ()) throws GLib.Error {
var uri = remote_file.get_uri ();
if (downloads.contains (uri))
// Already being downloaded
- return yield await_download (uri, cached_path);
+ return yield await_download (uri, cached_path); // FIXME: No progress report in this case.
var cached_file = File.new_for_path (cached_path);
if (cached_file.query_exists ()) {
@@ -66,6 +68,20 @@ private class Boxes.Downloader : GLib.Object {
if (!(yield network_monitor.can_reach_async (connectable)))
throw new Boxes.Error.INVALID ("Failed to reach host '%s' on port '%d'", address.name, address.port);
+ int64 total_num_bytes = 0;
+ msg.got_headers.connect (() => {
+ total_num_bytes = msg.response_headers.get_content_length ();
+ });
+
+ int64 current_num_bytes = 0;
+ msg.got_chunk.connect ((msg, chunk) => {
+ if (total_num_bytes <= 0)
+ return;
+
+ current_num_bytes += chunk.length;
+ progress.progress = (double) current_num_bytes / total_num_bytes;
+ });
+
session.queue_message (msg, (session, msg) => {
download.callback ();
});
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]