itom 1.3.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 class FileDownloader : public QObject
00012 {
00013     Q_OBJECT
00014 public:
00015     explicit FileDownloader(QUrl imageUrl, int nrOfAllowedRedirects = 0, QObject *parent = 0);
00016      
00017     virtual ~FileDownloader();
00018 
00019     enum Status { sRunning, sAborted, sFinished, sError };
00020      
00021     QByteArray downloadedData() const;
00022 
00023     void abortDownload();
00024 
00025     int getDownloadProgress();
00026 
00027     Status getStatus(QString &errorMsg);
00028      
00029 signals:
00030     //void downloaded();
00031      
00032 private slots:
00033      
00034     void fileDownloaded(QNetworkReply* pReply);
00035     void downloadProgress(qint64 bytesReceived, qint64 bytesTotal);
00036      
00037 private:
00038 
00039     int checkRedirect(QString &errorMsg);
00040      
00041     QNetworkAccessManager m_WebCtrl;
00042      
00043     QByteArray m_DownloadedData;
00044     
00045     QNetworkReply *m_pCurrentNetworkReply;
00046 
00047     qint64 m_bytesReceived;
00048     qint64 m_bytesTotal;
00049 
00050     int m_nrOfAllowedRedirects;
00051      
00052 };
00053      
00054 #endif // FILEDOWNLOADER_H
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends