downloadmanager.h 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #ifndef DOWNLOADMANAGER_H
  2. #define DOWNLOADMANAGER_H
  3. #include <QObject>
  4. #include <QNetworkReply>
  5. class QStringList;
  6. class QNetworkAccessManager;
  7. class DownloadManager: public QObject
  8. {
  9. Q_OBJECT
  10. public:
  11. DownloadManager(QObject* parent);
  12. // API
  13. int getProductList(QStringList& products);
  14. int getProduct(QString account,
  15. QString productId,
  16. QString* ticket = NULL);
  17. bool isNeedToBuy(QByteArray& response);
  18. signals:
  19. void productListComplete();
  20. void productComplete(QByteArray* buf);
  21. private slots:
  22. void replyFinished(QNetworkReply* reply);
  23. void replyError(QNetworkReply::NetworkError error);
  24. private:
  25. void handleProduct(QByteArray& buf);
  26. void handleProductList(QByteArray& buf);
  27. private:
  28. //data
  29. enum ComponentState{
  30. State_IDLE,
  31. State_GETPRODUCTLIST,
  32. State_GETPRODUCT
  33. };
  34. QNetworkAccessManager *manager;
  35. ComponentState state;
  36. QStringList *productList; //does not own
  37. };
  38. #endif // DOWNLOADMANAGER_H