Fix download progress (bars)
This commit is contained in:
parent
2ae60038aa
commit
91a3e650e9
@ -10,6 +10,8 @@ ByteArrayDownloadPtr DownloadJob::add ( QUrl url )
|
|||||||
ByteArrayDownloadPtr ptr (new ByteArrayDownload(url));
|
ByteArrayDownloadPtr ptr (new ByteArrayDownload(url));
|
||||||
ptr->index_within_job = downloads.size();
|
ptr->index_within_job = downloads.size();
|
||||||
downloads.append(ptr);
|
downloads.append(ptr);
|
||||||
|
parts_progress.append(QPair<qint64, qint64>(0,1));
|
||||||
|
total_progress++;
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -18,6 +20,8 @@ FileDownloadPtr DownloadJob::add ( QUrl url, QString rel_target_path)
|
|||||||
FileDownloadPtr ptr (new FileDownload(url, rel_target_path));
|
FileDownloadPtr ptr (new FileDownload(url, rel_target_path));
|
||||||
ptr->index_within_job = downloads.size();
|
ptr->index_within_job = downloads.size();
|
||||||
downloads.append(ptr);
|
downloads.append(ptr);
|
||||||
|
parts_progress.append(QPair<qint64, qint64>(0,1));
|
||||||
|
total_progress++;
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -26,6 +30,8 @@ CacheDownloadPtr DownloadJob::add ( QUrl url, MetaEntryPtr entry)
|
|||||||
CacheDownloadPtr ptr (new CacheDownload(url, entry));
|
CacheDownloadPtr ptr (new CacheDownload(url, entry));
|
||||||
ptr->index_within_job = downloads.size();
|
ptr->index_within_job = downloads.size();
|
||||||
downloads.append(ptr);
|
downloads.append(ptr);
|
||||||
|
parts_progress.append(QPair<qint64, qint64>(0,1));
|
||||||
|
total_progress++;
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,7 +66,16 @@ void DownloadJob::partFailed ( int index )
|
|||||||
|
|
||||||
void DownloadJob::partProgress ( int index, qint64 bytesReceived, qint64 bytesTotal )
|
void DownloadJob::partProgress ( int index, qint64 bytesReceived, qint64 bytesTotal )
|
||||||
{
|
{
|
||||||
// PROGRESS? DENIED!
|
auto & slot = parts_progress[index];
|
||||||
|
|
||||||
|
current_progress -= slot.first;
|
||||||
|
slot.first = bytesReceived;
|
||||||
|
current_progress += slot.first;
|
||||||
|
|
||||||
|
total_progress -= slot.second;
|
||||||
|
slot.second = bytesTotal;
|
||||||
|
total_progress += slot.second;
|
||||||
|
emit progress(current_progress, total_progress);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -70,6 +85,8 @@ void DownloadJob::start()
|
|||||||
for(auto iter: downloads)
|
for(auto iter: downloads)
|
||||||
{
|
{
|
||||||
connect(iter.data(), SIGNAL(succeeded(int)), SLOT(partSucceeded(int)));
|
connect(iter.data(), SIGNAL(succeeded(int)), SLOT(partSucceeded(int)));
|
||||||
|
connect(iter.data(), SIGNAL(failed(int)), SLOT(partFailed(int)));
|
||||||
|
connect(iter.data(), SIGNAL(progress(int,qint64,qint64)), SLOT(partProgress(int,qint64,qint64)));
|
||||||
iter->start();
|
iter->start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,6 +51,9 @@ private slots:
|
|||||||
private:
|
private:
|
||||||
QString m_job_name;
|
QString m_job_name;
|
||||||
QList<DownloadPtr> downloads;
|
QList<DownloadPtr> downloads;
|
||||||
|
QList<QPair<qint64, qint64>> parts_progress;
|
||||||
|
qint64 current_progress = 0;
|
||||||
|
qint64 total_progress = 0;
|
||||||
int num_succeeded = 0;
|
int num_succeeded = 0;
|
||||||
int num_failed = 0;
|
int num_failed = 0;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user