sammarks

simpledownloader.h

Apr 14th, 2011
192
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #ifndef SIMPLEDOWNLOADER_H
  2. #define SIMPLEDOWNLOADER_H
  3.  
  4. #include <QObject>
  5.  
  6. #include <QNetworkAccessManager>
  7. #include <QNetworkReply>
  8. #include <QNetworkRequest>
  9. #include <QFile>
  10. #include <QStringList>
  11. #include <QFileInfo>
  12. #include <QDir>
  13. #include <QUrl>
  14. #include <QIODevice>
  15. #include <QTime>
  16.  
  17. class SimpleDownloader : public QObject
  18. {
  19.     Q_OBJECT
  20.  
  21.     QNetworkAccessManager manager;
  22.     QUrl currentDownload;
  23.     QString currentSaveDirectory;
  24.     QTime *timer;
  25.     QNetworkReply *reply;
  26.  
  27. public:
  28.     SimpleDownloader();
  29.  
  30.     void InitDownload(QString url, QString saveDirectory);
  31.  
  32. signals:
  33.     void Progress(int received, int total, QString message);
  34.     void Finished(QString filename, bool success, QString message);
  35.  
  36. private:
  37.     QString saveFileName(QUrl url);
  38.     bool saveReply(QString filename, QIODevice *data);
  39.  
  40. private slots:
  41.     void DownloadFinished(QNetworkReply *reply);
  42.     void DownloadProgress(qint64 bytesReceived, qint64 bytesTotal);
  43.     void DownloadError(QNetworkReply::NetworkError);
  44.     void ReplyDownloadFinished();
  45. };
  46.  
  47. #endif // SIMPLEDOWNLOADER_H
RAW Paste Data