From ad5b00fc906523b4eefee64ca6a1388bc6673406 Mon Sep 17 00:00:00 2001 From: Zlatin Balevsky Date: Wed, 3 Jul 2019 12:50:24 +0100 Subject: [PATCH] prettier progress status thanks to Aegon --- .../muwire/core/upload/ContentUploader.groovy | 4 +++ .../core/upload/HashListUploader.groovy | 5 +++- .../com/muwire/core/upload/Uploader.groovy | 4 ++- .../views/com/muwire/gui/MainFrameView.groovy | 26 ++++++++++++++++--- 4 files changed, 33 insertions(+), 6 deletions(-) diff --git a/core/src/main/groovy/com/muwire/core/upload/ContentUploader.groovy b/core/src/main/groovy/com/muwire/core/upload/ContentUploader.groovy index 6319c86d..27c921e6 100644 --- a/core/src/main/groovy/com/muwire/core/upload/ContentUploader.groovy +++ b/core/src/main/groovy/com/muwire/core/upload/ContentUploader.groovy @@ -119,4 +119,8 @@ class ContentUploader extends Uploader { return mesh.pieces.nPieces; } + @Override + public long getTotalSize() { + return file.length(); + } } diff --git a/core/src/main/groovy/com/muwire/core/upload/HashListUploader.groovy b/core/src/main/groovy/com/muwire/core/upload/HashListUploader.groovy index 64ccf652..bd3aceec 100644 --- a/core/src/main/groovy/com/muwire/core/upload/HashListUploader.groovy +++ b/core/src/main/groovy/com/muwire/core/upload/HashListUploader.groovy @@ -61,5 +61,8 @@ class HashListUploader extends Uploader { return 1; } - + @Override + public long getTotalSize() { + return -1; + } } diff --git a/core/src/main/groovy/com/muwire/core/upload/Uploader.groovy b/core/src/main/groovy/com/muwire/core/upload/Uploader.groovy index ce0489b1..76bbd37a 100644 --- a/core/src/main/groovy/com/muwire/core/upload/Uploader.groovy +++ b/core/src/main/groovy/com/muwire/core/upload/Uploader.groovy @@ -35,5 +35,7 @@ abstract class Uploader { abstract int getDonePieces(); - abstract int getTotalPieces() + abstract int getTotalPieces(); + + abstract long getTotalSize(); } diff --git a/gui/griffon-app/views/com/muwire/gui/MainFrameView.groovy b/gui/griffon-app/views/com/muwire/gui/MainFrameView.groovy index b2492841..c0cb1de8 100644 --- a/gui/griffon-app/views/com/muwire/gui/MainFrameView.groovy +++ b/gui/griffon-app/views/com/muwire/gui/MainFrameView.groovy @@ -129,12 +129,19 @@ class MainFrameView { scrollPane (constraints : BorderLayout.CENTER) { downloadsTable = table(id : "downloads-table", autoCreateRowSorter : true) { tableModel(list: model.downloads) { - closureColumn(header: "Name", preferredWidth: 350, type: String, read : {row -> row.downloader.file.getName()}) + closureColumn(header: "Name", preferredWidth: 300, type: String, read : {row -> row.downloader.file.getName()}) closureColumn(header: "Status", preferredWidth: 50, type: String, read : {row -> row.downloader.getCurrentState().toString()}) - closureColumn(header: "Progress", preferredWidth: 20, type: String, read: { row -> + closureColumn(header: "Progress", preferredWidth: 70, type: String, read: { row -> int pieces = row.downloader.nPieces int done = row.downloader.donePieces() - "$done/$pieces pieces".toString() + int percent = -1 + if ( row.downloader.nPieces != 0 ) { + percent = (done * 100) / pieces + } + long size = row.downloader.pieceSize + size *= pieces + String totalSize = DataHelper.formatSize2Decimal(size, false) + "B" + "${percent}% of " + totalSize + " ($done/$pieces pcs)" }) closureColumn(header: "Sources", preferredWidth : 10, type: Integer, read : {row -> row.downloader.activeWorkers()}) closureColumn(header: "Speed", preferredWidth: 50, type:String, read :{row -> @@ -200,7 +207,18 @@ class MainFrameView { row.getDownloader() }) closureColumn(header : "Remote Pieces", type : String, read : { row -> - "${row.getDonePieces()}/${row.getTotalPieces()}".toString() + int pieces = row.getTotalPieces() + int done = row.getDonePieces() + int percent = -1 + if ( pieces != 0 ) { + percent = (done * 100) / pieces + } + long size = row.getTotalSize() + String totalSize = "" + if (size >= 0 ) { + totalSize = " of " + DataHelper.formatSize2Decimal(size, false) + "B" + } + "${percent}%" + totalSize + " ($done/$pieces pcs)" }) } }