purchasableitemBase.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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 DeclarativePurchaseListModel;
  15. class PurchasableItemBase : public QObject
  16. {
  17. Q_OBJECT
  18. Q_PROPERTY(QImage image READ stateIcon)// NOTIFY imageChanged)
  19. public:
  20. explicit PurchasableItemBase(DeclarativePurchaseListModel& model, QString& productID, QString& productUrl);
  21. virtual ~PurchasableItemBase();
  22. signals:
  23. public slots:
  24. protected slots:
  25. /*
  26. * In-Application Purchase specific slots
  27. *
  28. * Slots matching the signals of the In-Application Purchase API, allowing
  29. * the application to receive callbacks
  30. */
  31. void productDataReceived( int requestId, QString status, IAPClient::ProductDataHash productData );
  32. void purchaseCompleted( int requestId, QString status, QString purchaseTicket );
  33. void purchaseFlowFinished( int requestId );
  34. void restorationCompleted( int requestId, QString status, QString purchaseTicket );
  35. void restorationFlowFinished( int requestId );
  36. public:
  37. bool isMetaDataKnown() const;
  38. bool isBusy();
  39. bool isActivated() const;
  40. void purchase();
  41. void restore();
  42. enum Roles {
  43. ProductIdRole = Qt::UserRole+1,
  44. DataReqResultRole,
  45. TitleRole,
  46. ShortDescriptionRole,
  47. LongDescriptionRole,
  48. PriceRole,
  49. DrmProtectionRole,
  50. IsMetadataKnown,
  51. IsBusy,
  52. IsActivated
  53. };
  54. virtual QImage& stateIcon() const;
  55. virtual QVariant metadata(int role) const;
  56. bool setMetadata(const QVariant & value, int role);
  57. /**
  58. * checks whether 'this' is included to a given list
  59. */
  60. bool isIncluded(IAPClient::ProductDataList& list);
  61. static QString getTicketDir();
  62. protected:
  63. void fetchMetadata();
  64. bool setBusy();
  65. virtual void setUnlocked(QString* purchaseTicket) = 0;
  66. virtual bool isPurchased() = 0;
  67. /**
  68. * these methods below related to purchase ticket
  69. * are only for IAP in test mode
  70. * normally we don't need to operate or keep tickets
  71. * because purchase verification is done :
  72. * 1) transparently by system for DRM protected items
  73. * 2) and by third party server for non-protected items via ticket verification API
  74. *
  75. * Tickets are transient data that can be requested any time from OVI Store for a certain
  76. * product id.
  77. *
  78. * if it is decided that keeping tickets in the application private directory
  79. * does not bring vulnerability issue this functionality may remain
  80. **/
  81. void saveTicket(QString* purchaseTicket);
  82. bool readTicket();
  83. void deactivate();// used to purge item
  84. private:
  85. QString getTicketUri();
  86. protected:
  87. //data
  88. IAPClient::ProductData m_productMetadata;
  89. DeclarativePurchaseListModel *m_model; //does not own
  90. int m_requestId;
  91. bool m_isBusy;
  92. QString m_productUrl;
  93. bool m_isKnown;
  94. QImage *m_unlocked_icon;
  95. QImage *m_buy_icon;
  96. QImage *m_notready_icon;
  97. };
  98. #endif // PurchasableItemBase_H