2006-09-30 20:02:39 +04:00
|
|
|
/*
|
|
|
|
* Bittorrent Client using Qt4 and libtorrent.
|
2007-07-14 18:31:59 +04:00
|
|
|
* Copyright (C) 2006 Christophe Dumez
|
2006-09-30 20:02:39 +04:00
|
|
|
*
|
2007-07-14 18:31:59 +04:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2006-09-30 20:02:39 +04:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2007-07-14 18:31:59 +04:00
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
* Contact : chris@qbittorrent.org
|
2006-09-30 20:02:39 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef DOWNLOADTHREAD_H
|
|
|
|
#define DOWNLOADTHREAD_H
|
|
|
|
|
|
|
|
#include <QThread>
|
|
|
|
#include <QFile>
|
|
|
|
#include <QTemporaryFile>
|
|
|
|
#include <QMutex>
|
|
|
|
#include <QMutexLocker>
|
|
|
|
#include <QWaitCondition>
|
2007-08-08 02:29:46 +04:00
|
|
|
#include <QStringList>
|
2007-07-20 19:55:50 +04:00
|
|
|
|
2007-09-29 12:13:20 +04:00
|
|
|
namespace ost {
|
|
|
|
class URLStream;
|
|
|
|
}
|
2007-07-22 07:04:47 +04:00
|
|
|
|
2007-11-22 01:30:33 +03:00
|
|
|
typedef struct {
|
|
|
|
QString IP;
|
|
|
|
int port;
|
|
|
|
QString username;
|
|
|
|
QString password;
|
|
|
|
} tmp_proxy;
|
|
|
|
|
2007-07-22 19:48:34 +04:00
|
|
|
class subDownloadThread : public QThread {
|
2006-09-30 20:02:39 +04:00
|
|
|
Q_OBJECT
|
|
|
|
private:
|
2007-07-22 19:48:34 +04:00
|
|
|
QString url;
|
2007-09-29 12:00:14 +04:00
|
|
|
ost::URLStream *url_stream;
|
2007-03-09 21:11:43 +03:00
|
|
|
bool abort;
|
2006-09-30 20:02:39 +04:00
|
|
|
|
|
|
|
public:
|
2007-09-29 12:00:14 +04:00
|
|
|
subDownloadThread(QObject *parent, QString url);
|
|
|
|
~subDownloadThread();
|
2007-09-29 12:13:20 +04:00
|
|
|
QString errorCodeToString(int status);
|
2007-07-22 07:04:47 +04:00
|
|
|
|
2007-07-22 19:48:34 +04:00
|
|
|
signals:
|
|
|
|
// For subthreads
|
|
|
|
void downloadFinishedST(subDownloadThread* st, QString url, QString file_path);
|
|
|
|
void downloadFailureST(subDownloadThread* st, QString url, QString reason);
|
|
|
|
|
|
|
|
protected:
|
2007-09-29 12:00:14 +04:00
|
|
|
void run();
|
2007-07-22 19:48:34 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
class downloadThread : public QThread {
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
private:
|
|
|
|
QStringList url_list;
|
2007-08-27 14:06:13 +04:00
|
|
|
QStringList downloading_list;
|
2007-07-22 19:48:34 +04:00
|
|
|
QMutex mutex;
|
|
|
|
QWaitCondition condition;
|
|
|
|
bool abort;
|
|
|
|
QList<subDownloadThread*> subThreads;
|
|
|
|
|
|
|
|
signals:
|
|
|
|
void downloadFinished(QString url, QString file_path);
|
|
|
|
void downloadFailure(QString url, QString reason);
|
|
|
|
|
|
|
|
public:
|
2007-09-29 12:00:14 +04:00
|
|
|
downloadThread(QObject* parent);
|
|
|
|
|
|
|
|
~downloadThread();
|
|
|
|
|
|
|
|
void downloadUrl(QString url);
|
2007-11-22 01:30:33 +03:00
|
|
|
void setProxy(QString IP, int port, QString username, QString password);
|
2007-07-22 19:48:34 +04:00
|
|
|
|
2007-03-09 21:11:43 +03:00
|
|
|
protected:
|
2007-09-29 12:00:14 +04:00
|
|
|
void run();
|
|
|
|
|
2007-07-22 17:21:04 +04:00
|
|
|
protected slots:
|
2007-09-29 12:00:14 +04:00
|
|
|
void propagateDownloadedFile(subDownloadThread* st, QString url, QString path);
|
|
|
|
|
|
|
|
void propagateDownloadFailure(subDownloadThread* st, QString url, QString reason);
|
2006-09-30 20:02:39 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|