diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2012-12-25 13:49:23 +0100 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2012-12-25 13:49:23 +0100 |
commit | 1d439af8b7071dc71eb79333ffcc2777df030657 (patch) | |
tree | a86c26584e84274627a61592c619e9eb4b7fe1f9 | |
parent | Don't print garbage time values to console. (diff) | |
download | oldgen-zmusicuploader-1d439af8b7071dc71eb79333ffcc2777df030657.tar.xz oldgen-zmusicuploader-1d439af8b7071dc71eb79333ffcc2777df030657.zip |
Less cluttered indicator.
-rw-r--r-- | RateCalculator.cpp | 8 | ||||
-rw-r--r-- | RateCalculator.h | 1 | ||||
-rw-r--r-- | Uploader.cpp | 8 |
3 files changed, 15 insertions, 2 deletions
diff --git a/RateCalculator.cpp b/RateCalculator.cpp index de6fe3b..bfc268e 100644 --- a/RateCalculator.cpp +++ b/RateCalculator.cpp @@ -39,3 +39,11 @@ double RateCalculator::rate(qint64 interval) const } return static_cast<double>(bytes) / static_cast<double>(time); } +double RateCalculator::elapsed() const +{ + qint64 time = 0; + QPair<qint64, qint64> i; + foreach (i, m_segments) + time += i.first; + return time; +} diff --git a/RateCalculator.h b/RateCalculator.h index a8bec1c..14acaba 100644 --- a/RateCalculator.h +++ b/RateCalculator.h @@ -15,6 +15,7 @@ public: void stop(); void reset(); double rate(qint64 interval = -1) const; + double elapsed() const; private: QElapsedTimer m_timer; QLinkedList<QPair<qint64, qint64> > m_segments; diff --git a/Uploader.cpp b/Uploader.cpp index f4c0b0d..21322f2 100644 --- a/Uploader.cpp +++ b/Uploader.cpp @@ -116,8 +116,12 @@ void Uploader::dataTransferProgress(qint64 done, qint64 total) { m_rateCalculator.updateTotalBytes(done); const double rate = m_rateCalculator.rate(25000); - const qint64 time = (total - done) / rate; + qint64 time; + if (done == total) + time = m_rateCalculator.elapsed(); + else + time = (total - done) / rate; if (rate < 0 || time < 0) return; - cerr << "\r\033[2K" << static_cast<qint64>(round(done / 1024.0)) << " of " << static_cast<qint64>(round(total / 1024.0)) << " kilobytes transferred at " << static_cast<qint64>(round(rate * 1024.0 / 1000.0)) << " kilobytes per second, " << time / 1000 / 60 << " minutes and " << time / 1000 % 60 << " seconds left."; + cerr << "\r\033[2K" << static_cast<qint64>(round(done / 1024.0)) << "/" << static_cast<qint64>(round(total / 1024.0)) << " kB | " << static_cast<qint64>(round(rate * 1024.0 / 1000.0)) << " kB/s | ETA: " << time / 1000 / 60 << ":" << time / 1000 % 60; } |