itom 2.0.0
D:/git-itom/sources/itom/Qitom/helper/fileDownloader.h
00001 #ifndef FILEDOWNLOADER_H
00002 #define FILEDOWNLOADER_H
00003      
00004 #include <qobject.h>
00005 #include <qbytearray.h>
00006 #include <qnetworkaccessmanager.h>
00007 #include <qnetworkrequest.h>
00008 #include <qnetworkreply.h>
00009 #include <qurl.h>
00010 
00011 namespace ito
00012 {
00013      
00014 class FileDownloader : public QObject
00015 {
00016     Q_OBJECT
00017 public:
00018     explicit FileDownloader(QUrl imageUrl, int nrOfAllowedRedirects = 0, QObject *parent = 0);
00019      
00020     virtual ~FileDownloader();
00021 
00022     enum Status { sRunning, sAborted, sFinished, sError };
00023      
00024     QByteArray downloadedData() const;
00025 
00026     void abortDownload();
00027 
00028     int getDownloadProgress();
00029 
00030     Status getStatus(QString &errorMsg);
00031      
00032 signals:
00033     //void downloaded();
00034      
00035 private slots:
00036      
00037     void fileDownloaded(QNetworkReply* pReply);
00038     void downloadProgress(qint64 bytesReceived, qint64 bytesTotal);
00039      
00040 private:
00041 
00042     int checkRedirect(QString &errorMsg);
00043      
00044     QNetworkAccessManager m_WebCtrl;
00045      
00046     QByteArray m_DownloadedData;
00047     
00048     QNetworkReply *m_pCurrentNetworkReply;
00049 
00050     qint64 m_bytesReceived;
00051     qint64 m_bytesTotal;
00052 
00053     int m_nrOfAllowedRedirects;
00054      
00055 };
00056 
00057 } //end namespace ito
00058      
00059 #endif // FILEDOWNLOADER_H
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends