levelcontroller.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /*
  2. * Copyright (c) 2011 Nokia Corporation.
  3. */
  4. #ifndef LEVELCONTROLLER_HPP
  5. #define LEVELCONTROLLER_HPP
  6. #include <QObject>
  7. #include <QStringList>
  8. #include <QHash>
  9. #include <QVariant>
  10. #if defined(IAP_ENABLED)
  11. #include <iapclient.h>
  12. #endif
  13. class LevelModel;
  14. class Level;
  15. /***************************************************************************************************
  16. *Class used for handling IAP(in application purchasing) and level/theme loading. *
  17. ***************************************************************************************************/
  18. class LevelController : public QObject
  19. {
  20. Q_OBJECT
  21. /***********************************************************************************************
  22. *A read-only property used to control the game characters look. *
  23. ***********************************************************************************************/
  24. Q_PROPERTY(QString face READ getFace NOTIFY faceChanged)
  25. public:
  26. /***********************************************************************************************
  27. *The constructor, requiring a mandatory level object. *
  28. ***********************************************************************************************/
  29. explicit LevelController(Level *level,QObject *parent = 0);
  30. /***********************************************************************************************
  31. *An invokable method used to trigger level/theme loading form qml. *
  32. ***********************************************************************************************/
  33. Q_INVOKABLE void load(int index);
  34. /***********************************************************************************************
  35. *An invokable method used to trigger IAP purchase form qml. *
  36. ***********************************************************************************************/
  37. Q_INVOKABLE void buy(int index);
  38. /***********************************************************************************************
  39. *A method used to access the model used to represent purchasable items. *
  40. ***********************************************************************************************/
  41. LevelModel* getLevelModel() const;
  42. /***********************************************************************************************
  43. *A method returning the current value of the face property. *
  44. ***********************************************************************************************/
  45. QString getFace() const;
  46. private slots:
  47. #if defined(IAP_ENABLED)
  48. /***************************************************************************************************
  49. *IAP data received handling slots. *
  50. ***************************************************************************************************/
  51. /***********************************************************************************************
  52. *A slot triggered by the IAPClients productDataReceved signal. *
  53. ***********************************************************************************************/
  54. void productDataReceved(int requestId,QString status,IAPClient::ProductData data);
  55. /***********************************************************************************************
  56. *A slot triggered by the IAPClients restorableProductsReceived signal. *
  57. ***********************************************************************************************/
  58. void restorableProductsReceived(int requestId,QString status,IAPClient::ProductList data);
  59. /***********************************************************************************************
  60. *A slot triggered by the IAPClients userAndDeviceDataReceived signal. *
  61. ***********************************************************************************************/
  62. void userAndDeviceDataReceived(int requestId,QString account,QString imei,QString imsi,
  63. QString country,QString language,QString deviceModel);
  64. /**************************************************************************************************/
  65. /***************************************************************************************************
  66. *IAP purchase flow handling slots. *
  67. ***************************************************************************************************/
  68. /***********************************************************************************************
  69. *A slot triggered by the IAPClients purchaseCompleted signal. *
  70. ***********************************************************************************************/
  71. void purchaseCompleted(int requsetId,QString status,QString ticket);
  72. /***********************************************************************************************
  73. *A slot triggered by the IAPClients purchaseFlowFinished signal. *
  74. ***********************************************************************************************/
  75. void purchaseFlowFinished(int requsetId);
  76. /**************************************************************************************************/
  77. /***************************************************************************************************
  78. *IAP restoration flow handling slots. *
  79. ***************************************************************************************************/
  80. /***********************************************************************************************
  81. *A slot triggered by the IAPClients restorationCompleted signal. *
  82. ***********************************************************************************************/
  83. void restorationCompleted(int requsetId,QString status,QString ticket);
  84. /***********************************************************************************************
  85. *A slot triggered by the IAPClients restorationFlowFinished signal. *
  86. ***********************************************************************************************/
  87. void restorationFlowFinished(int requsetId);
  88. /**************************************************************************************************/
  89. #endif
  90. signals:
  91. /***********************************************************************************************
  92. *A signal emitted after the purchase/restore has been finished, to hide the software keys. *
  93. ***********************************************************************************************/
  94. void hack();
  95. /***********************************************************************************************
  96. *A signal emitted after successfully loading a new level, used to trigger qml level reload. *
  97. ***********************************************************************************************/
  98. void levelReload();
  99. /***********************************************************************************************
  100. *A signal emitted after loading a theme, notifies that the face properties value has changed. *
  101. ***********************************************************************************************/
  102. void faceChanged();
  103. private:
  104. /***********************************************************************************************
  105. *A private method used to trigger purchasable item loading. *
  106. ***********************************************************************************************/
  107. void loadItems();
  108. /***********************************************************************************************
  109. *A private method used request IAP data for a single item. *
  110. ***********************************************************************************************/
  111. void requestItemData();
  112. /***********************************************************************************************
  113. *A private method used unlock purchasable items. *
  114. ***********************************************************************************************/
  115. void unlock(QString itemId,QString purchaseTicket);
  116. /***********************************************************************************************
  117. *The level model object. *
  118. ***********************************************************************************************/
  119. LevelModel *m_Model;
  120. /***********************************************************************************************
  121. *The IAPClient object. *
  122. ***********************************************************************************************/
  123. #if defined(IAP_ENABLED)
  124. IAPClient *m_IAPClient;
  125. #endif
  126. /***********************************************************************************************
  127. *The level object. *
  128. ***********************************************************************************************/
  129. Level *m_level;
  130. /***********************************************************************************************
  131. *A list used to hold the strings defining items loaded from the Items.data file. * *
  132. ***********************************************************************************************/
  133. QStringList itemLines;
  134. /***********************************************************************************************
  135. *A request queue for the level items, int request id, QString product id QString level name. *
  136. ***********************************************************************************************/
  137. QHash<int,QPair<QString,QString> > levelRequests;
  138. /***********************************************************************************************
  139. *A request queue for theme items, int request id, QString product id QString theme name. *
  140. ***********************************************************************************************/
  141. QHash<int,QPair<QString,QString> > themeRequests;
  142. /***********************************************************************************************
  143. *A string holding the value of the face property. *
  144. ***********************************************************************************************/
  145. QString face;
  146. };
  147. #endif // LEVELCONTROLLER_HPP