iapurchase.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /**
  2. * Copyright (c) 2011 Nokia Corporation.
  3. */
  4. #ifndef IAPURCHASE_H
  5. #define IAPURCHASE_H
  6. #include <QDeclarativeListProperty>
  7. #include <QMetaType>
  8. #include <QObject>
  9. #include <QString>
  10. #include <iapclient.h>
  11. #include "request.h"
  12. // Forward declarations
  13. class DownloadManager;
  14. class Product;
  15. class IAPurchase : public QObject
  16. {
  17. Q_OBJECT
  18. Q_PROPERTY(bool iapready READ iapready NOTIFY iapCreatedAndReady)
  19. public:
  20. explicit IAPurchase(QObject *parent = 0);
  21. public:
  22. bool iapready() const;
  23. Q_INVOKABLE QVariant productDataAt(int index);
  24. Q_INVOKABLE int productDataCount();
  25. public slots:
  26. void cancel();
  27. void getIapDataFromBackend(QString productName);
  28. // In-Application Purchase requests
  29. void getIapDataFromStore(QString iapId);
  30. void buyProduct(QString iapId);
  31. // Signals from DownloadManager
  32. void productIdsCompleted(QList<QObject*>);
  33. private:
  34. Product *productFromCacheByProductId(QString productId);
  35. Product *productFromCacheByRequestId(int productId);
  36. private slots:
  37. void createIAP();
  38. void onDownloadProgress(QString productId, qint64 bytesReceived, qint64 bytesTotal);
  39. void downloadCompleted(Request::RequestType, QString productId, QString fileName, int error);
  40. // In-Application Purchase specific slots
  41. void productDataReceived(int requestId, QString status, IAPClient::ProductDataHash);
  42. void purchaseCompleted(int requestId, QString status, QString purchaseTicket);
  43. void purchaseFlowFinished(int requestId);
  44. signals: // Signals to the QML side for the requests
  45. void iapCreatedAndReady(bool ready);
  46. void productDataRead(QObject *product);
  47. void productDataReadError();
  48. void iapBackendDataReaded();
  49. void iapBackendDataReadError();
  50. void productPurchaseError();
  51. void productDoesNotExists(QString productId);
  52. void productPurchaseDone(QString productId);
  53. void downloadingProduct(QString productId);
  54. void downloadProgress(QString productId, qint64 bytesReceived, qint64 bytesTotal);
  55. void downloaded(QString productId);
  56. void downloadingError();
  57. void installingProduct(QString productId);
  58. void busy();
  59. private: // Data
  60. IAPClient *m_iapClient; // In-Application Purchase API, owned
  61. DownloadManager *m_downloadMgr; // Owned
  62. QList<QObject*> m_productCache; // Content not owned
  63. int m_buyProductRequestId;
  64. int m_invalidProductPurchaseRequestId;
  65. bool m_iapReady;
  66. };
  67. #endif // IAPURCHASE_H