summaryrefslogtreecommitdiffstats
path: root/api/logic
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2017-07-06 15:38:16 +0200
committerPetr Mrázek <peterix@gmail.com>2017-07-06 15:38:16 +0200
commit1797f45e8fa3ab505987cdaed8a2a8ad9b472456 (patch)
tree32a8c40303ea9008d7bb46393890b26ed71e626d /api/logic
parent8dd9987a9c616c6ee47479007c0757ff468f8d2c (diff)
downloadMultiMC-1797f45e8fa3ab505987cdaed8a2a8ad9b472456.tar
MultiMC-1797f45e8fa3ab505987cdaed8a2a8ad9b472456.tar.gz
MultiMC-1797f45e8fa3ab505987cdaed8a2a8ad9b472456.tar.lz
MultiMC-1797f45e8fa3ab505987cdaed8a2a8ad9b472456.tar.xz
MultiMC-1797f45e8fa3ab505987cdaed8a2a8ad9b472456.zip
NOISSUE fix jumpy download progress bars
They are not as precise, the new logic gives every download 1000 'units' instead of the actual (initially unknown) sizes.
Diffstat (limited to 'api/logic')
-rw-r--r--api/logic/net/NetJob.cpp46
-rw-r--r--api/logic/net/NetJob.h3
2 files changed, 32 insertions, 17 deletions
diff --git a/api/logic/net/NetJob.cpp b/api/logic/net/NetJob.cpp
index 693a0934..325b924b 100644
--- a/api/logic/net/NetJob.cpp
+++ b/api/logic/net/NetJob.cpp
@@ -59,15 +59,38 @@ void NetJob::partAborted(int index)
void NetJob::partProgress(int index, qint64 bytesReceived, qint64 bytesTotal)
{
auto &slot = parts_progress[index];
-
- current_progress -= slot.current_progress;
slot.current_progress = bytesReceived;
- current_progress += slot.current_progress;
-
- total_progress -= slot.total_progress;
slot.total_progress = bytesTotal;
- total_progress += slot.total_progress;
- setProgress(current_progress, total_progress);
+
+ int done = m_done.size();
+ int doing = m_doing.size();
+ int all = parts_progress.size();
+
+ qint64 bytesAll = 0;
+ qint64 bytesTotalAll = 0;
+ for(auto & partIdx: m_doing)
+ {
+ auto part = parts_progress[partIdx];
+ // do not count parts with unknown/nonsensical total size
+ if(part.total_progress <= 0)
+ {
+ continue;
+ }
+ bytesAll += part.current_progress;
+ bytesTotalAll += part.total_progress;
+ }
+
+ qint64 inprogress = (bytesTotalAll == 0) ? 0 : (bytesAll * 1000) / bytesTotalAll;
+ qDebug() << bytesAll << bytesTotalAll << inprogress << doing * inprogress;
+ auto current = done * 1000 + doing * inprogress;
+ auto current_total = all * 1000;
+ // HACK: make sure it never jumps backwards.
+ if(m_current_progress > current)
+ {
+ current = m_current_progress;
+ }
+ m_current_progress = current;
+ setProgress(current, current_total);
}
void NetJob::executeTask()
@@ -177,16 +200,9 @@ bool NetJob::addNetAction(NetActionPtr action)
action->m_index_within_job = downloads.size();
downloads.append(action);
part_info pi;
- {
- pi.current_progress = action->currentProgress();
- pi.total_progress = action->totalProgress();
- pi.failures = 0;
- }
parts_progress.append(pi);
- total_progress += pi.total_progress;
+ partProgress(parts_progress.count() - 1, action->currentProgress(), action->totalProgress());
- // FIXME: detect if the action is already running, put it in m_doing if it is!
- setProgress(current_progress, total_progress);
if(action->isRunning())
{
connect(action.get(), SIGNAL(succeeded(int)), SLOT(partSucceeded(int)));
diff --git a/api/logic/net/NetJob.h b/api/logic/net/NetJob.h
index a7577246..2b5c3d9a 100644
--- a/api/logic/net/NetJob.h
+++ b/api/logic/net/NetJob.h
@@ -84,7 +84,6 @@ private:
QSet<int> m_doing;
QSet<int> m_done;
QSet<int> m_failed;
- qint64 current_progress = 0;
- qint64 total_progress = 0;
+ qint64 m_current_progress = 0;
bool m_aborted = false;
};