itom  3.0.0
fileDownloader.h
1 #ifndef FILEDOWNLOADER_H
2 #define FILEDOWNLOADER_H
3 
4 #include <qobject.h>
5 #include <qbytearray.h>
6 #include <qnetworkaccessmanager.h>
7 #include <qnetworkrequest.h>
8 #include <qnetworkreply.h>
9 #include <qurl.h>
10 
11 namespace ito
12 {
13 
14 class FileDownloader : public QObject
15 {
16  Q_OBJECT
17 public:
18  explicit FileDownloader(QUrl imageUrl, int nrOfAllowedRedirects = 0, QObject *parent = 0);
19 
20  virtual ~FileDownloader();
21 
22  enum Status { sRunning, sAborted, sFinished, sError };
23 
24  QByteArray downloadedData() const;
25 
26  void abortDownload();
27 
28  int getDownloadProgress();
29 
30  Status getStatus(QString &errorMsg);
31 
32 signals:
33  //void downloaded();
34 
35 private slots:
36 
37  void fileDownloaded(QNetworkReply* pReply);
38  void downloadProgress(qint64 bytesReceived, qint64 bytesTotal);
39 
40 private:
41 
42  int checkRedirect(QString &errorMsg);
43 
44  QNetworkAccessManager m_WebCtrl;
45 
46  QByteArray m_DownloadedData;
47 
48  QNetworkReply *m_pCurrentNetworkReply;
49 
50  qint64 m_bytesReceived;
51  qint64 m_bytesTotal;
52 
53  int m_nrOfAllowedRedirects;
54 
55 };
56 
57 } //end namespace ito
58 
59 #endif // FILEDOWNLOADER_H
Definition: fileDownloader.h:14
Status getStatus(QString &errorMsg)
Returns the status of a download.
Definition: fileDownloader.cpp:76
Definition: apiFunctionsGraph.cpp:39
int checkRedirect(QString &errorMsg)
This function checks if the given error message is caused by a redirect.
Definition: fileDownloader.cpp:171
void fileDownloaded(QNetworkReply *pReply)
This function is called when the download is finished.
Definition: fileDownloader.cpp:140
int getDownloadProgress()
This functions returns the downloadprogress of a file.
Definition: fileDownloader.cpp:57
void downloadProgress(qint64 bytesReceived, qint64 bytesTotal)
Setting method to set the meber variables.
Definition: fileDownloader.cpp:126
void abortDownload()
Aboarts a download.
Definition: fileDownloader.cpp:42
QByteArray downloadedData() const
This function returns the downloaded data.
Definition: fileDownloader.cpp:160