|
|
@ -45,7 +45,7 @@ class downloadThread : public QThread { |
|
|
|
QMutex mutex; |
|
|
|
QMutex mutex; |
|
|
|
QWaitCondition condition; |
|
|
|
QWaitCondition condition; |
|
|
|
bool abort; |
|
|
|
bool abort; |
|
|
|
URLStream url_stream; |
|
|
|
URLStream *url_stream; |
|
|
|
QList<downloadThread*> subThreads; |
|
|
|
QList<downloadThread*> subThreads; |
|
|
|
bool subThread; |
|
|
|
bool subThread; |
|
|
|
|
|
|
|
|
|
|
@ -61,6 +61,7 @@ class downloadThread : public QThread { |
|
|
|
qDebug("Creating downloadThread"); |
|
|
|
qDebug("Creating downloadThread"); |
|
|
|
abort = false; |
|
|
|
abort = false; |
|
|
|
this->subThread = subThread; |
|
|
|
this->subThread = subThread; |
|
|
|
|
|
|
|
url_stream = 0; |
|
|
|
qDebug("downloadThread created"); |
|
|
|
qDebug("downloadThread created"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -69,10 +70,14 @@ class downloadThread : public QThread { |
|
|
|
abort = true; |
|
|
|
abort = true; |
|
|
|
condition.wakeOne(); |
|
|
|
condition.wakeOne(); |
|
|
|
mutex.unlock(); |
|
|
|
mutex.unlock(); |
|
|
|
|
|
|
|
if(url_stream != 0) |
|
|
|
|
|
|
|
delete url_stream; |
|
|
|
wait(); |
|
|
|
wait(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void downloadUrl(QString url){ |
|
|
|
void downloadUrl(QString url){ |
|
|
|
|
|
|
|
if(subThread && url_stream == 0) |
|
|
|
|
|
|
|
url_stream = new URLStream(); |
|
|
|
QMutexLocker locker(&mutex); |
|
|
|
QMutexLocker locker(&mutex); |
|
|
|
url_list << url; |
|
|
|
url_list << url; |
|
|
|
if(!isRunning()){ |
|
|
|
if(!isRunning()){ |
|
|
@ -139,31 +144,31 @@ class downloadThread : public QThread { |
|
|
|
std::cerr << "Error: could't create temporary file: " << (const char*)filePath.toUtf8() << '\n'; |
|
|
|
std::cerr << "Error: could't create temporary file: " << (const char*)filePath.toUtf8() << '\n'; |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
URLStream::Error status = url_stream.get((const char*)url.toUtf8()); |
|
|
|
URLStream::Error status = url_stream->get((const char*)url.toUtf8()); |
|
|
|
if(status){ |
|
|
|
if(status){ |
|
|
|
// Failure
|
|
|
|
// Failure
|
|
|
|
QString error_msg = errorCodeToString(status); |
|
|
|
QString error_msg = errorCodeToString(status); |
|
|
|
qDebug("Download failed for %s, reason: %s", (const char*)url.toUtf8(), (const char*)error_msg.toUtf8()); |
|
|
|
qDebug("Download failed for %s, reason: %s", (const char*)url.toUtf8(), (const char*)error_msg.toUtf8()); |
|
|
|
url_stream.close(); |
|
|
|
url_stream->close(); |
|
|
|
emit downloadFailureST(this, url, error_msg); |
|
|
|
emit downloadFailureST(this, url, error_msg); |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
qDebug("Downloading %s...", (const char*)url.toUtf8()); |
|
|
|
qDebug("Downloading %s...", (const char*)url.toUtf8()); |
|
|
|
char cbuf[1024]; |
|
|
|
char cbuf[1024]; |
|
|
|
int len; |
|
|
|
int len; |
|
|
|
while(!url_stream.eof()) { |
|
|
|
while(!url_stream->eof()) { |
|
|
|
url_stream.read(cbuf, sizeof(cbuf)); |
|
|
|
url_stream->read(cbuf, sizeof(cbuf)); |
|
|
|
len = url_stream.gcount(); |
|
|
|
len = url_stream->gcount(); |
|
|
|
if(len > 0) |
|
|
|
if(len > 0) |
|
|
|
dest_file.write(cbuf, len); |
|
|
|
dest_file.write(cbuf, len); |
|
|
|
if(abort){ |
|
|
|
if(abort){ |
|
|
|
dest_file.close(); |
|
|
|
dest_file.close(); |
|
|
|
url_stream.close(); |
|
|
|
url_stream->close(); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
dest_file.close(); |
|
|
|
dest_file.close(); |
|
|
|
url_stream.close(); |
|
|
|
url_stream->close(); |
|
|
|
emit downloadFinishedST(this, url, filePath); |
|
|
|
emit downloadFinishedST(this, url, filePath); |
|
|
|
qDebug("download completed here: %s", (const char*)filePath.toUtf8()); |
|
|
|
qDebug("download completed here: %s", (const char*)filePath.toUtf8()); |
|
|
|
}else{ |
|
|
|
}else{ |
|
|
|