Loading...
Searching...
No Matches
simpleDownloader.h
Go to the documentation of this file.
#ifndef BALL_SYSTEM_SIMPLEDOWNLOADER_H
#define BALL_SYSTEM_SIMPLEDOWNLOADER_H
#ifndef BALL_DATATYPE_STRING_H
#include <BALL/DATATYPE/string.h>
#endif
#include <QtCore/QThread>
#include <QtCore/QFile>
#include <QtNetwork/QNetworkReply>
class QByteArray;
namespace BALL
{
namespace SimpleDownloaderHelper
{
class HelperThread;
}
class BALL_EXPORT SimpleDownloader
: public QObject
{
Q_OBJECT
public:
/*
* Default Constructor.
*
* @param url The URL to download.
* @param timeout The maximum number of milliseconds the download is allowed to take.
* default: infinite
*/
SimpleDownloader(const String& url, unsigned int timeout = UINT_MAX);
/*
* Default Constructor.
*
* @param url The URL to download.
* @param timeout The maximum number of milliseconds the download is allowed to take.
* default: infinite
*/
SimpleDownloader(const QUrl& url, unsigned int timeout = UINT_MAX);
int downloadToBuffer(std::vector<char>& buffer);
int downloadToFile(const String& path);
int uploadStringToBuffer(const String& data, std::vector<char>& response);
int uploadStringToFile(const String& data, const String& response);
int uploadFileToBuffer(const String& path, std::vector<char>& response);
int uploadFileToFile(const String& path, const String& response);
void setTimeout(unsigned int timeout);
void setURL(const String& url);
void setURL(const QUrl& url);
const QUrl& getURL() const;
private:
int download_(SimpleDownloaderHelper::HelperThread& thread);
QUrl url_;
unsigned int timeout_;
};
namespace SimpleDownloaderHelper
{
class HelperThread : public QThread
{
public:
HelperThread(const QUrl& url, QByteArray* result, SimpleDownloader* parent);
HelperThread(const QUrl& url, const String& path, SimpleDownloader* parent);
int getStatus();
protected:
virtual QNetworkReply* getReply_(QNetworkAccessManager* man) = 0;
void run();
int err_;
QUrl url_;
QByteArray* result_;
String path_;
SimpleDownloader* parent_;
};
class DLThread : public HelperThread
{
public:
DLThread(const QUrl& url, QByteArray* result, SimpleDownloader* parent);
DLThread(const QUrl& url, const String& path, SimpleDownloader* parent);
protected:
virtual QNetworkReply* getReply_(QNetworkAccessManager* man);
};
class UPThread : public HelperThread
{
public:
UPThread(const QUrl& url, const QByteArray* data, QByteArray* result, SimpleDownloader* parent);
UPThread(const QUrl& url, const QByteArray* data, const String& path, SimpleDownloader* parent);
UPThread(const QUrl& url, QIODevice* file, QByteArray* result, SimpleDownloader* parent);
UPThread(const QUrl& url, QIODevice* file, const String& path, SimpleDownloader* parent);
protected:
virtual QNetworkReply* getReply_(QNetworkAccessManager* man);
const QByteArray* data_;
QIODevice* file_;
};
class BasicHelper : public QObject
{
Q_OBJECT
public:
BasicHelper(HelperThread* caller, QNetworkReply* reply);
virtual ~BasicHelper(){}
public Q_SLOTS:
void error(QNetworkReply::NetworkError error);
#ifndef QT_NO_SSL
void sslErrors(const QList<QSslError>& errors);
#endif
virtual void finished() = 0;
protected:
HelperThread* caller_;
QNetworkReply* reply_;
};
class DLArrayHelper : public BasicHelper
{
Q_OBJECT
public:
DLArrayHelper(HelperThread* caller, QNetworkReply* reply, QByteArray* result);
public Q_SLOTS:
void finished();
private:
QByteArray* result_;
};
class DLHelper : public BasicHelper
{
Q_OBJECT
public:
DLHelper(HelperThread* caller, QNetworkReply* reply, const String& path);
public Q_SLOTS:
void finished();
void receivedData();
private:
QFile file_;
};
}
}
#endif //BALL_SYSTEM_SIMPLEDOWNLOADER_H
BALL_EXPORT
#define BALL_EXPORT
Definition COMMON/global.h:50
BALL::SimpleDownloaderHelper::BasicHelper::error
void error(QNetworkReply::NetworkError error)
BALL::SimpleDownloaderHelper::BasicHelper::caller_
HelperThread * caller_
Definition simpleDownloader.h:212
BALL::SimpleDownloaderHelper::BasicHelper::~BasicHelper
virtual ~BasicHelper()
Definition simpleDownloader.h:202
BALL::SimpleDownloaderHelper::BasicHelper::BasicHelper
BasicHelper(HelperThread *caller, QNetworkReply *reply)
BALL::SimpleDownloaderHelper::BasicHelper::reply_
QNetworkReply * reply_
Definition simpleDownloader.h:213
BALL::SimpleDownloaderHelper::BasicHelper::sslErrors
void sslErrors(const QList< QSslError > &errors)
BALL::SimpleDownloaderHelper::BasicHelper::finished
virtual void finished()=0
BALL::SimpleDownloaderHelper::DLArrayHelper::finished
void finished()
BALL::SimpleDownloaderHelper::DLArrayHelper::DLArrayHelper
DLArrayHelper(HelperThread *caller, QNetworkReply *reply, QByteArray *result)
BALL::SimpleDownloaderHelper::DLHelper::DLHelper
DLHelper(HelperThread *caller, QNetworkReply *reply, const String &path)
BALL::SimpleDownloaderHelper::DLHelper::receivedData
void receivedData()
BALL::SimpleDownloaderHelper::DLHelper::finished
void finished()
BALL::SimpleDownloaderHelper::DLThread::getReply_
virtual QNetworkReply * getReply_(QNetworkAccessManager *man)
BALL::SimpleDownloaderHelper::DLThread::DLThread
DLThread(const QUrl &url, const String &path, SimpleDownloader *parent)
BALL::SimpleDownloaderHelper::DLThread::DLThread
DLThread(const QUrl &url, QByteArray *result, SimpleDownloader *parent)
BALL::SimpleDownloaderHelper::HelperThread
Definition simpleDownloader.h:152
BALL::SimpleDownloaderHelper::HelperThread::HelperThread
HelperThread(const QUrl &url, const String &path, SimpleDownloader *parent)
BALL::SimpleDownloaderHelper::HelperThread::url_
QUrl url_
Definition simpleDownloader.h:165
BALL::SimpleDownloaderHelper::HelperThread::HelperThread
HelperThread(const QUrl &url, QByteArray *result, SimpleDownloader *parent)
BALL::SimpleDownloaderHelper::HelperThread::path_
String path_
Definition simpleDownloader.h:167
BALL::SimpleDownloaderHelper::HelperThread::parent_
SimpleDownloader * parent_
Definition simpleDownloader.h:168
BALL::SimpleDownloaderHelper::HelperThread::run
void run()
BALL::SimpleDownloaderHelper::HelperThread::getStatus
int getStatus()
BALL::SimpleDownloaderHelper::HelperThread::getReply_
virtual QNetworkReply * getReply_(QNetworkAccessManager *man)=0
BALL::SimpleDownloaderHelper::HelperThread::result_
QByteArray * result_
Definition simpleDownloader.h:166
BALL::SimpleDownloaderHelper::HelperThread::err_
int err_
Definition simpleDownloader.h:164
BALL::SimpleDownloaderHelper::UPThread::UPThread
UPThread(const QUrl &url, QIODevice *file, QByteArray *result, SimpleDownloader *parent)
BALL::SimpleDownloaderHelper::UPThread::getReply_
virtual QNetworkReply * getReply_(QNetworkAccessManager *man)
BALL::SimpleDownloaderHelper::UPThread::UPThread
UPThread(const QUrl &url, const QByteArray *data, const String &path, SimpleDownloader *parent)
BALL::SimpleDownloaderHelper::UPThread::data_
const QByteArray * data_
Definition simpleDownloader.h:192
BALL::SimpleDownloaderHelper::UPThread::UPThread
UPThread(const QUrl &url, const QByteArray *data, QByteArray *result, SimpleDownloader *parent)
BALL::SimpleDownloaderHelper::UPThread::file_
QIODevice * file_
Definition simpleDownloader.h:193
BALL::SimpleDownloaderHelper::UPThread::UPThread
UPThread(const QUrl &url, QIODevice *file, const String &path, SimpleDownloader *parent)
BALL::SimpleDownloader
Definition simpleDownloader.h:34
BALL::SimpleDownloader::SimpleDownloader
SimpleDownloader(const QUrl &url, unsigned int timeout=UINT_MAX)
BALL::SimpleDownloader::uploadStringToFile
int uploadStringToFile(const String &data, const String &response)
BALL::SimpleDownloader::uploadFileToBuffer
int uploadFileToBuffer(const String &path, std::vector< char > &response)
BALL::SimpleDownloader::downloadToFile
int downloadToFile(const String &path)
BALL::SimpleDownloader::setURL
void setURL(const QUrl &url)
BALL::SimpleDownloader::downloadToBuffer
int downloadToBuffer(std::vector< char > &buffer)
BALL::SimpleDownloader::getURL
const QUrl & getURL() const
BALL::SimpleDownloader::setTimeout
void setTimeout(unsigned int timeout)
BALL::SimpleDownloader::uploadStringToBuffer
int uploadStringToBuffer(const String &data, std::vector< char > &response)
BALL::SimpleDownloader::uploadFileToFile
int uploadFileToFile(const String &path, const String &response)
BALL::SimpleDownloader::setURL
void setURL(const String &url)
BALL::SimpleDownloader::SimpleDownloader
SimpleDownloader(const String &url, unsigned int timeout=UINT_MAX)
BALL::String
Definition string.h:57
QObject
QThread
BALL::SimpleDownloaderHelper
Definition simpleDownloader.h:18
BALL
Definition constants.h:13
string.h