BALL  1.4.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Public Member Functions | Private Member Functions | Private Attributes | List of all members
BALL::SimpleDownloader Class Reference

#include <BALL/SYSTEM/simpleDownloader.h>

Inheritance diagram for BALL::SimpleDownloader:
QObject

Public Member Functions

 SimpleDownloader (const String &url, unsigned int timeout=UINT_MAX)
 
 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 Member Functions

int download_ (SimpleDownloaderHelper::HelperThread &thread)
 
int qftpDownloadHack_ (QIODevice *iodev)
 

Private Attributes

QUrl url_
 
unsigned int timeout_
 

Detailed Description

This class provides an interface for synchronous downloads. It currently relies on QNetworkAccessManager and thus on the existence of a QCoreApplication object. If no global instance is existing a local application object is created. For this reason you must not use this class in any thread but the main thread if you did not create a QCoreApplication object yourself.

REMARK: this class is considered experimental and its interface can be a subject to redesign.

Definition at line 33 of file simpleDownloader.h.

Constructor & Destructor Documentation

BALL::SimpleDownloader::SimpleDownloader ( const String url,
unsigned int  timeout = UINT_MAX 
)
BALL::SimpleDownloader::SimpleDownloader ( const QUrl &  url,
unsigned int  timeout = UINT_MAX 
)

Member Function Documentation

int BALL::SimpleDownloader::download_ ( SimpleDownloaderHelper::HelperThread thread)
private
int BALL::SimpleDownloader::downloadToBuffer ( std::vector< char > &  buffer)

If the content of the download should be kept in memory you can use this function that stores the received bytes in the provides vector. Any previous content is overwritten.

Parameters
bufferThe buffer vector to use.
Returns
Non-zero if an error occurred while downloading
int BALL::SimpleDownloader::downloadToFile ( const String path)

Download the url and store the contents to a file.

Parameters
pathThe path to the file the content is stored in.
Returns
Non-zero if an error occurred while downloading
const QUrl& BALL::SimpleDownloader::getURL ( ) const

Returns the current URL.

Returns
The currently set URL
int BALL::SimpleDownloader::qftpDownloadHack_ ( QIODevice *  iodev)
private
void BALL::SimpleDownloader::setTimeout ( unsigned int  timeout)

Sets the maximum amount of time a download my take. The time is specified in milliseconds.

Parameters
timeoutThe time in milliseconds.
void BALL::SimpleDownloader::setURL ( const String url)

Sets the url of the download.

Parameters
urlThe URL to download
void BALL::SimpleDownloader::setURL ( const QUrl &  url)

Sets the url of the download.

Parameters
urlThe URL to download
int BALL::SimpleDownloader::uploadFileToBuffer ( const String path,
std::vector< char > &  response 
)

Upload the passed string to the specified URL and save the response to the specified file

Parameters
paththe path of the file to upload
responsethe response of the server
Returns
Non-zero if an error occured while uploading
int BALL::SimpleDownloader::uploadFileToFile ( const String path,
const String response 
)

Upload the passed string to the specified URL and save the response to the specified file

Parameters
paththe path of the file to upload
responsethe file the response is saved to
Returns
Non-zero if an error occured while uploading
int BALL::SimpleDownloader::uploadStringToBuffer ( const String data,
std::vector< char > &  response 
)

Upload the passed string to the specified URL and save the response to the specified buffer

Parameters
datathe string which is uploaded
responsethe response of the server
Returns
Non-zero if an error occured while uploading
int BALL::SimpleDownloader::uploadStringToFile ( const String data,
const String response 
)

Upload the passed string to the specified URL and save the response to the specified file

Parameters
datathe string which is uploaded
responsethe file the response is saved to
Returns
Non-zero if an error occured while uploading

Member Data Documentation

unsigned int BALL::SimpleDownloader::timeout_
private

Definition at line 148 of file simpleDownloader.h.

QUrl BALL::SimpleDownloader::url_
private

Definition at line 147 of file simpleDownloader.h.