From d92bb2d8c4bddf11095f5984e9616224b73ac2cd Mon Sep 17 00:00:00 2001 From: Maciek Borzecki Date: Tue, 27 Jun 2017 22:29:23 +0200 Subject: [PATCH] share, transfer: user friendly size formatting --- src/mconnect/share.vala | 2 +- src/mconnect/transfer-download.vala | 10 ++++++---- src/mconnect/transfer.vala | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/mconnect/share.vala b/src/mconnect/share.vala index f47fa5c..439319e 100644 --- a/src/mconnect/share.vala +++ b/src/mconnect/share.vala @@ -75,7 +75,7 @@ class ShareHandler : Object, PacketHandlerInterface { } string name = pkt.body.get_string_member("filename"); - debug("file: %s size: %lld", name, pkt.payload.size); + debug("file: %s size: %s", name, format_size(pkt.payload.size)); var t = new DownloadTransfer( new InetSocketAddress(dev.host, diff --git a/src/mconnect/transfer-download.vala b/src/mconnect/transfer-download.vala index 560650b..62c13f2 100644 --- a/src/mconnect/transfer-download.vala +++ b/src/mconnect/transfer-download.vala @@ -70,9 +70,11 @@ class DownloadTransfer : Object { private void start_transfer() { this.transfer = new Transfer(this.conn.input_stream, this.foutstream); - this.transfer.progress.connect((t, p) => { - int percent = (int) (100.0 * ((double)p / (double)this.size)); - debug("progress: %llu/%llu %d %%", p, this.size, percent); + this.transfer.progress.connect((t, done) => { + int percent = (int) (100.0 * ((double)done / (double)this.size)); + debug("progress: %s/%s %d%%", + format_size(done), format_size(this.size), percent); + this.transferred = done; }); this.transfer.transfer_async.begin(this.cancel, this.transfer_complete); @@ -82,7 +84,7 @@ class DownloadTransfer : Object { info("transfer finished"); try { var rcvd_bytes = this.transfer.transfer_async.end(res); - debug("transfer done, got %llu bytes", rcvd_bytes); + debug("transfer done, got %s", format_size(rcvd_bytes)); this.cleanup_success(); diff --git a/src/mconnect/transfer.vala b/src/mconnect/transfer.vala index 57db937..3e96048 100644 --- a/src/mconnect/transfer.vala +++ b/src/mconnect/transfer.vala @@ -47,10 +47,10 @@ class Transfer : Object { chunk_size = max_chunk_size; } - debug("transfer done, got %llu bytes", bytes_done); this.from.close(); this.to.close(); + debug("transfer done, got %llu bytes", format_size(bytes_done)); return bytes_done; }