- optimized downloadthreads

- fixed resizing in torrent addition dialog
This commit is contained in:
Christophe Dumez
2008-07-27 18:11:45 +00:00
parent dad79d2cc8
commit dc399e9ed9
3 changed files with 14 additions and 14 deletions

View File

@@ -24,6 +24,8 @@
#include <QSettings> #include <QSettings>
#include <stdio.h> #include <stdio.h>
#define MAX_THREADS 3
// http://curl.rtin.bz/libcurl/c/libcurl-errors.html // http://curl.rtin.bz/libcurl/c/libcurl-errors.html
QString subDownloadThread::errorCodeToString(CURLcode status) { QString subDownloadThread::errorCodeToString(CURLcode status) {
switch(status){ switch(status){
@@ -150,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{
@@ -165,8 +165,8 @@ void downloadThread::run(){
if(abort) if(abort)
return; return;
mutex.lock(); mutex.lock();
if(url_list.size() != 0){ 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;
@@ -187,9 +187,9 @@ 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); condition.wakeOne();
downloading_list.removeAt(index); }
mutex.unlock(); mutex.unlock();
} }
@@ -200,8 +200,8 @@ 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); condition.wakeOne();
downloading_list.removeAt(index); }
mutex.unlock(); mutex.unlock();
} }

View File

@@ -30,6 +30,7 @@
#include <QWaitCondition> #include <QWaitCondition>
#include <QStringList> #include <QStringList>
#include <curl/curl.h> #include <curl/curl.h>
#include <QQueue>
class subDownloadThread : public QThread { class subDownloadThread : public QThread {
Q_OBJECT Q_OBJECT
@@ -55,8 +56,7 @@ class downloadThread : public QThread {
Q_OBJECT Q_OBJECT
private: private:
QStringList url_list; QQueue<QString> urls_queue;
QStringList downloading_list;
QMutex mutex; QMutex mutex;
QWaitCondition condition; QWaitCondition condition;
bool abort; bool abort;

View File

@@ -80,7 +80,7 @@ class torrentAdditionDialog : public QDialog, private Ui_addTorrentDialog{
connect(actionHigh, SIGNAL(triggered()), this, SLOT(highSelection())); connect(actionHigh, SIGNAL(triggered()), this, SLOT(highSelection()));
connect(actionMaximum, SIGNAL(triggered()), this, SLOT(maximumSelection())); connect(actionMaximum, SIGNAL(triggered()), this, SLOT(maximumSelection()));
torrentContentList->header()->resizeSection(0, 200); torrentContentList->header()->resizeSection(0, 200);
torrentContentList->header()->setResizeMode(0, QHeaderView::Stretch); //torrentContentList->header()->setResizeMode(0, QHeaderView::Stretch);
QString home = QDir::homePath(); QString home = QDir::homePath();
if(home[home.length()-1] != QDir::separator()){ if(home[home.length()-1] != QDir::separator()){
home += QDir::separator(); home += QDir::separator();