declarativepurchaselistmodel.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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 DECLARATIVEPURCHASELISTMODEL_H
  9. #define DECLARATIVEPURCHASELISTMODEL_H
  10. #include <QAbstractListModel>
  11. #include <QDeclarativeParserStatus>
  12. #include <QImage>
  13. #include <iapclient.h>
  14. class PurchasableItemBase;
  15. /**
  16. * @class DeclarativePurchaseListModel
  17. *
  18. * @brief Implementents Catalog list model
  19. *
  20. */
  21. class DeclarativePurchaseListModel : public QAbstractListModel, public QDeclarativeParserStatus
  22. {
  23. Q_OBJECT
  24. Q_INTERFACES(QDeclarativeParserStatus)
  25. public:
  26. Q_PROPERTY(bool drmFilter READ drmFilter WRITE setDrmFilter)
  27. Q_PROPERTY(bool isApplicationBusy READ isApplicationBusy NOTIFY applicationBusyChanged)
  28. /**
  29. * @see QAbstractListModel
  30. *
  31. * @brief base class abstract method implementation
  32. *
  33. * @param parent
  34. */
  35. int rowCount(const QModelIndex & parent = QModelIndex()) const;
  36. /**
  37. * @see QAbstractListModel
  38. *
  39. * @brief base class abstract method implementation
  40. *
  41. * @param index
  42. * @param role
  43. */
  44. QVariant data(const QModelIndex &index, int role) const;
  45. /**
  46. * @see QAbstractListModel
  47. *
  48. * @brief base class abstract method implementation
  49. *
  50. * @param index
  51. * @param value
  52. * @param role
  53. */
  54. bool setData (const QModelIndex & index, const QVariant & value, int role = Qt::EditRole);
  55. //property accesors
  56. /**
  57. * @brief
  58. *
  59. */
  60. bool drmFilter() const;
  61. /**
  62. * @brief
  63. *
  64. * @param val
  65. */
  66. void setDrmFilter(bool val);
  67. /**
  68. * @brief
  69. *
  70. */
  71. bool isApplicationBusy() const;
  72. /**
  73. * @brief
  74. *
  75. * @param index
  76. */
  77. Q_INVOKABLE void buy(int index);
  78. /**
  79. * @brief
  80. *
  81. */
  82. Q_INVOKABLE void restoreProducts();
  83. /**
  84. * @brief
  85. *
  86. */
  87. Q_INVOKABLE void getUserInfo();
  88. /**
  89. * @brief
  90. *
  91. */
  92. Q_INVOKABLE void purgeProducts();
  93. public:
  94. Q_DISABLE_COPY(DeclarativePurchaseListModel)
  95. /**
  96. * @brief
  97. *
  98. * @param
  99. */
  100. explicit DeclarativePurchaseListModel(QObject *parent = 0);
  101. /**
  102. * @brief
  103. *
  104. */
  105. ~DeclarativePurchaseListModel();
  106. //QDeclarativeParserStatus interface
  107. /**
  108. * @brief
  109. *
  110. */
  111. void classBegin();
  112. /**
  113. * @brief
  114. *
  115. */
  116. void componentComplete();
  117. public:
  118. // for model items to use only
  119. /**
  120. * @brief
  121. *
  122. */
  123. void beginModelUpdate();
  124. /**
  125. * @brief
  126. *
  127. */
  128. void commitModelUpdate();
  129. /**
  130. * @brief
  131. *
  132. */
  133. IAPClient& client();
  134. /**
  135. * @brief
  136. *
  137. * @param index
  138. */
  139. PurchasableItemBase* record(int index) const;
  140. signals:
  141. /**
  142. * @brief
  143. *
  144. */
  145. void applicationBusyChanged();
  146. protected slots:
  147. /*
  148. * In-Application Purchase specific slots
  149. */
  150. /**
  151. * @brief
  152. *
  153. * @param requestId
  154. * @param status
  155. * @param items
  156. */
  157. void restorableProductsReceived( int requestId, QString status,
  158. IAPClient::ProductDataList items);
  159. /**
  160. * @brief
  161. *
  162. * @param requestId
  163. * @param status
  164. * @param userdata
  165. */
  166. void userAndDeviceDataReceived (int requestId, QString status,
  167. IAPClient::UserAndDeviceDataHash userdata);
  168. private:
  169. //utility functions
  170. /**
  171. * @brief
  172. *
  173. */
  174. void readNonProtectedCatalog();
  175. /**
  176. * @brief
  177. *
  178. */
  179. void readDRMCatalog();
  180. private:
  181. // In-Application Purchase API
  182. IAPClient m_client; /**< TODO */
  183. //for aggregate query to product list getRestorableProducts()
  184. int m_requestId; /**< TODO */
  185. QList<PurchasableItemBase*> m_data; /**< TODO */
  186. int m_modelCommitRefCounter; /**< TODO */
  187. // enables the whole application busy indicator
  188. bool m_isApplicationBusy; /**< TODO */
  189. };
  190. #endif // DECLARATIVEPURCHASELISTMODEL_H