|
|
@ -152,9 +152,7 @@ downloadThread::~downloadThread(){ |
|
|
|
|
|
|
|
|
|
|
|
void downloadThread::downloadUrl(QString url){ |
|
|
|
void downloadThread::downloadUrl(QString url){ |
|
|
|
QMutexLocker locker(&mutex); |
|
|
|
QMutexLocker locker(&mutex); |
|
|
|
if(downloading_list.contains(url)) return; |
|
|
|
urls_queue.enqueue(url); |
|
|
|
url_list << url; |
|
|
|
|
|
|
|
downloading_list << url; |
|
|
|
|
|
|
|
if(!isRunning()){ |
|
|
|
if(!isRunning()){ |
|
|
|
start(); |
|
|
|
start(); |
|
|
|
}else{ |
|
|
|
}else{ |
|
|
@ -167,8 +165,8 @@ void downloadThread::run(){ |
|
|
|
if(abort) |
|
|
|
if(abort) |
|
|
|
return; |
|
|
|
return; |
|
|
|
mutex.lock(); |
|
|
|
mutex.lock(); |
|
|
|
if(url_list.size() != 0 && subThreads.size() < MAX_THREADS){ |
|
|
|
if(!urls_queue.empty() && subThreads.size() < MAX_THREADS){ |
|
|
|
QString url = url_list.takeFirst(); |
|
|
|
QString url = urls_queue.dequeue(); |
|
|
|
mutex.unlock(); |
|
|
|
mutex.unlock(); |
|
|
|
subDownloadThread *st = new subDownloadThread(0, url); |
|
|
|
subDownloadThread *st = new subDownloadThread(0, url); |
|
|
|
subThreads << st; |
|
|
|
subThreads << st; |
|
|
@ -189,10 +187,7 @@ void downloadThread::propagateDownloadedFile(subDownloadThread* st, QString url, |
|
|
|
delete st; |
|
|
|
delete st; |
|
|
|
emit downloadFinished(url, path); |
|
|
|
emit downloadFinished(url, path); |
|
|
|
mutex.lock(); |
|
|
|
mutex.lock(); |
|
|
|
index = downloading_list.indexOf(url); |
|
|
|
if(!urls_queue.empty()) { |
|
|
|
Q_ASSERT(index != -1); |
|
|
|
|
|
|
|
downloading_list.removeAt(index); |
|
|
|
|
|
|
|
if(url_list.size() != 0) { |
|
|
|
|
|
|
|
condition.wakeOne(); |
|
|
|
condition.wakeOne(); |
|
|
|
} |
|
|
|
} |
|
|
|
mutex.unlock(); |
|
|
|
mutex.unlock(); |
|
|
@ -205,10 +200,7 @@ void downloadThread::propagateDownloadFailure(subDownloadThread* st, QString url |
|
|
|
delete st; |
|
|
|
delete st; |
|
|
|
emit downloadFailure(url, reason); |
|
|
|
emit downloadFailure(url, reason); |
|
|
|
mutex.lock(); |
|
|
|
mutex.lock(); |
|
|
|
index = downloading_list.indexOf(url); |
|
|
|
if(!urls_queue.empty()) { |
|
|
|
Q_ASSERT(index != -1); |
|
|
|
|
|
|
|
downloading_list.removeAt(index); |
|
|
|
|
|
|
|
if(url_list.size() != 0) { |
|
|
|
|
|
|
|
condition.wakeOne(); |
|
|
|
condition.wakeOne(); |
|
|
|
} |
|
|
|
} |
|
|
|
mutex.unlock(); |
|
|
|
mutex.unlock(); |
|
|
|