purchasableitemBase.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. /**
  2. * Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
  3. * All rights reserved.
  4. *
  5. * For the applicable distribution terms see the license.txt -file, included in
  6. * the distribution.
  7. */
  8. #ifndef PurchasableItemBase_H
  9. #define PurchasableItemBase_H
  10. #include <QObject>
  11. #include <iapclient.h>
  12. #include <QVariant>
  13. #include <QImage>
  14. class ProductListModel;
  15. /*!
  16. \class PurchasableItemBase abstract class
  17. \brief Represents billable product in memory, handles billing operations
  18. */
  19. class PurchasableItemBase : public QObject
  20. {
  21. Q_OBJECT
  22. Q_PROPERTY(QImage image READ stateIcon)// NOTIFY imageChanged)
  23. public:
  24. /*!
  25. Constructor
  26. accepts product list model, the product Ovi Store product id and unlocked icon URL
  27. */
  28. explicit PurchasableItemBase(ProductListModel &model,
  29. const QString &productID,
  30. const QString &productUrl);
  31. /*!
  32. Destructor
  33. */
  34. virtual ~PurchasableItemBase();
  35. void initProductData();
  36. signals:
  37. public slots:
  38. protected slots:
  39. /*
  40. * In-Application Purchase specific slots
  41. *
  42. * Slots matching the signals of the In-Application Purchase API, allowing
  43. * the application to receive callbacks
  44. */
  45. void productDataReceived( int requestId, QString status, IAPClient::ProductDataHash productData );
  46. void purchaseCompleted( int requestId, QString status, QString purchaseTicket );
  47. void purchaseFlowFinished( int requestId );
  48. void restorationCompleted( int requestId, QString status, QString purchaseTicket );
  49. void restorationFlowFinished( int requestId );
  50. public:
  51. /*!
  52. Checks whether product metadata has been downloaded from Ovi Store
  53. */
  54. bool isMetaDataKnown() const;
  55. /*!
  56. Checks whether product operation is on going
  57. */
  58. bool isBusy();
  59. /*!
  60. Checks whether product has been unlocked
  61. */
  62. bool isActivated() const;
  63. /*!
  64. Purchase request
  65. */
  66. void purchase();
  67. /*!
  68. Product restore request
  69. */
  70. void restore();
  71. //command codes for fetching data in QAbstractListModel::data() interface to QML side
  72. enum Roles {
  73. ProductIdRole = Qt::UserRole+1,
  74. DataReqResultRole, // IAP client request return code
  75. TitleRole, // product title
  76. ShortDescriptionRole, // product short description
  77. LongDescriptionRole, // product long descrtiption
  78. PriceRole, // product price
  79. DrmProtectionRole, // check if the product DRM protected
  80. IsMetadataKnown, // check if the product data has been fetched from OVI Store
  81. IsBusy, // check if the product operation is on-going
  82. IsActivated // check if the product unlocked (bought)
  83. };
  84. /*!
  85. Returns the product current state icon. Can be 'locked', 'unlocked', 'busy'
  86. */
  87. virtual QImage& stateIcon() const;
  88. /*!
  89. Returns product data via QAbstractListModel::data() 'role' interface
  90. */
  91. virtual QVariant metadata(int role) const;
  92. /*!
  93. Sets product data via QAbstractListModel::data() 'role' interface
  94. */
  95. bool setMetadata(const QVariant &value, int role);
  96. /*!
  97. * checks whether the product is included to a given 'list' parameter
  98. */
  99. bool isIncluded(IAPClient::ProductDataList &list);
  100. static QString getTicketDir();
  101. protected:
  102. /*!
  103. Calls IAP client to fetch metadata
  104. */
  105. void fetchMetadata();
  106. /*!
  107. Sets product state to 'busy'
  108. */
  109. bool setBusy();
  110. /*!
  111. Sets product state to 'unlocked'
  112. */
  113. virtual void setUnlocked(QString *purchaseTicket) = 0;
  114. /*!
  115. Checks whether the product has been unlocked
  116. */
  117. virtual bool isPurchased() = 0;
  118. /*!
  119. * these methods below related to purchase ticket
  120. * are only for IAP in test mode
  121. * normally we don't need to operate or keep tickets
  122. * because purchase verification is done :
  123. * 1) transparently by system for DRM protected items
  124. * 2) and by third party server for non-protected items via ticket verification API
  125. *
  126. * Tickets are transient data that can be requested any time from OVI Store for a certain
  127. * product id.
  128. *
  129. * if it is decided that keeping tickets in the application private directory
  130. * does not bring vulnerability issue this functionality may remain
  131. **/
  132. void saveTicket(QString *purchaseTicket);
  133. bool readTicket();
  134. void deactivate();
  135. private:
  136. QString getTicketUri();
  137. protected:
  138. //data
  139. IAPClient::ProductData m_productMetadata;
  140. ProductListModel *m_model; //product list model, does not own
  141. int m_requestId; //current request id to IAP client
  142. bool m_isBusy; //product busy flag
  143. QString m_productUrl; //product unlocked resource URL
  144. bool m_isKnown; //product data obtained from Ovi Store flag
  145. QImage *m_unlocked_icon; //product unlocked icon URL
  146. QImage *m_buy_icon;
  147. QImage *m_notready_icon;
  148. };
  149. #endif // PurchasableItemBase_H