BuildmLearn Toolkit  2.0.4
BuildmLearn Toolkit is an easy-to-use program that helps users make mobile apps without any knowledge of application development.
 All Classes Functions Enumerations Groups Pages
Downloader Class Reference

Simple file downloader with progress reporting. More...

#include <downloader.h>

Collaboration diagram for Downloader:
Collaboration graph

Public Slots

void downloadFile (const QString &url, bool protected_contents=false, const QString &username=QString(), const QString &password=QString())
 Performs asynchronous download of given file. Redirections are handled. More...
 
void uploadBundleFile (QString url, const QString &bundle_data, const QString &key, const QString &author_name, const QString &author_email, const QString &application_name, const QString &application_icon)
 Uploads given bundle_data to store server via HTTP POST. More...
 

Signals

void progress (qint64 bytes_received, qint64 bytes_total)
 Emitted when new progress is known. More...
 
void completed (QNetworkReply::NetworkError status, QByteArray contents=QByteArray())
 Emitted if file download or upload completes (un)successfully. More...
 

Public Member Functions

 Downloader (QObject *parent=0)
 Constructor. More...
 

Detailed Description

Simple file downloader with progress reporting.

Definition at line 47 of file downloader.h.

Constructor & Destructor Documentation

Downloader::Downloader ( QObject *  parent = 0)
explicit

Constructor.

Parameters
parentParent to this instance.

Definition at line 40 of file downloader.cpp.

41  : QObject(parent),
42  m_activeReply(NULL),
43  m_downloadManager(new SilentNetworkAccessManager(this)),
44  m_timer(new QTimer(this)) {
45 
46  m_timer->setInterval(2000);
47  m_timer->setSingleShot(true);
48 
49  //connect(m_timer, SIGNAL(timeout()), this, SLOT(timeout()));
50  connect(m_downloadManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(finished(QNetworkReply*)));
51 }
Network access manager with supressed authentication dialogs.

Member Function Documentation

void Downloader::completed ( QNetworkReply::NetworkError  status,
QByteArray  contents = QByteArray() 
)
signal

Emitted if file download or upload completes (un)successfully.

Parameters
statusStatus of file download/upload.
contentsQByteArray containing downloaded file (if any) or post reply.
void Downloader::downloadFile ( const QString &  url,
bool  protected_contents = false,
const QString &  username = QString(),
const QString &  password = QString() 
)
slot

Performs asynchronous download of given file. Redirections are handled.

Parameters
urlURL of file to be downloaded.
protected_contentsAre contents of URL protected?
usernameUsername if contents are protected.
passwordPassword if contents are protected.

Definition at line 57 of file downloader.cpp.

58  {
59  QNetworkRequest request;
60  QObject originatingObject;
61 
62  // Set credential information as originating object.
63  originatingObject.setProperty("protected", protected_contents);
64  originatingObject.setProperty("username", username);
65  originatingObject.setProperty("password", password);
66  request.setOriginatingObject(&originatingObject);
67 
68  // Set url for this reques.
69  request.setUrl(url);
70  runGetRequest(request);
71 }
void Downloader::progress ( qint64  bytes_received,
qint64  bytes_total 
)
signal

Emitted when new progress is known.

Parameters
bytes_receivedNumber of bytes received.
bytes_totalNumber of bytes total.
void Downloader::uploadBundleFile ( QString  url,
const QString &  bundle_data,
const QString &  key,
const QString &  author_name,
const QString &  author_email,
const QString &  application_name,
const QString &  application_icon 
)
slot

Uploads given bundle_data to store server via HTTP POST.

Parameters
urlURL to store server
bundle_data

Definition at line 73 of file downloader.cpp.

76  {
77  QNetworkRequest request;
78 
79  request.setUrl(url);
80  request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
81 
82  QString data;
83 
84  data += "key=%1&";
85  data += "author_name=%2&";
86  data += "author_email=%3&";
87  data += "application_name=%4&";
88  data += "file_content=%5&";
89  data += "application_icon=%6";
90 
91  // Replace placeholders with actual URL-encoded values.
92  data = data.arg(QUrl::toPercentEncoding(key),
93  QUrl::toPercentEncoding(author_name),
94  QUrl::toPercentEncoding(author_email),
95  QUrl::toPercentEncoding(application_name),
96  QUrl::toPercentEncoding(bundle_data),
97  QUrl::toPercentEncoding(IOFactory::fileToBase64(application_icon)));
98 /*
99  m_timer->start();
100  m_activeReply = m_downloadManager->post(request, data.toLocal8Bit());
101 
102  connect(m_activeReply, SIGNAL(uploadProgress(qint64,qint64)),
103  this, SLOT(progressInternal(qint64,qint64)));
104 */
105  runPostRequest(request, data.toLocal8Bit());
106 }
static QByteArray fileToBase64(const QString &file_name)
Takes input file and reads it into base64 byte array.
Definition: iofactory.cpp:111

Here is the call graph for this function:


The documentation for this class was generated from the following files: