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.
This commit is contained in:
parent
8dd9987a9c
commit
1797f45e8f
@ -59,15 +59,38 @@ void NetJob::partAborted(int index)
|
|||||||
void NetJob::partProgress(int index, qint64 bytesReceived, qint64 bytesTotal)
|
void NetJob::partProgress(int index, qint64 bytesReceived, qint64 bytesTotal)
|
||||||
{
|
{
|
||||||
auto &slot = parts_progress[index];
|
auto &slot = parts_progress[index];
|
||||||
|
|
||||||
current_progress -= slot.current_progress;
|
|
||||||
slot.current_progress = bytesReceived;
|
slot.current_progress = bytesReceived;
|
||||||
current_progress += slot.current_progress;
|
|
||||||
|
|
||||||
total_progress -= slot.total_progress;
|
|
||||||
slot.total_progress = bytesTotal;
|
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()
|
void NetJob::executeTask()
|
||||||
@ -177,16 +200,9 @@ bool NetJob::addNetAction(NetActionPtr action)
|
|||||||
action->m_index_within_job = downloads.size();
|
action->m_index_within_job = downloads.size();
|
||||||
downloads.append(action);
|
downloads.append(action);
|
||||||
part_info pi;
|
part_info pi;
|
||||||
{
|
|
||||||
pi.current_progress = action->currentProgress();
|
|
||||||
pi.total_progress = action->totalProgress();
|
|
||||||
pi.failures = 0;
|
|
||||||
}
|
|
||||||
parts_progress.append(pi);
|
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())
|
if(action->isRunning())
|
||||||
{
|
{
|
||||||
connect(action.get(), SIGNAL(succeeded(int)), SLOT(partSucceeded(int)));
|
connect(action.get(), SIGNAL(succeeded(int)), SLOT(partSucceeded(int)));
|
||||||
|
@ -84,7 +84,6 @@ private:
|
|||||||
QSet<int> m_doing;
|
QSet<int> m_doing;
|
||||||
QSet<int> m_done;
|
QSet<int> m_done;
|
||||||
QSet<int> m_failed;
|
QSet<int> m_failed;
|
||||||
qint64 current_progress = 0;
|
qint64 m_current_progress = 0;
|
||||||
qint64 total_progress = 0;
|
|
||||||
bool m_aborted = false;
|
bool m_aborted = false;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user