mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-10 14:57:52 +00:00
- URLStream is now constructed in downloadThread constructor
This commit is contained in:
parent
c019b0d72c
commit
4f17339820
@ -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,7 +61,6 @@ 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");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,14 +69,10 @@ 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(url_stream == 0)
|
|
||||||
url_stream = new URLStream();
|
|
||||||
QMutexLocker locker(&mutex);
|
QMutexLocker locker(&mutex);
|
||||||
url_list << url;
|
url_list << url;
|
||||||
if(!isRunning()){
|
if(!isRunning()){
|
||||||
@ -144,31 +139,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{
|
||||||
|
Loading…
Reference in New Issue
Block a user