buycatalog.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. #ifndef BUYCATALOG_H
  2. #define BUYCATALOG_H
  3. #include "ui_buycatalog.h"
  4. #include <QtGui/QDialog>
  5. #include <iapclient.h>
  6. class ProductInfo;
  7. class QProgressDialog;
  8. class DownloadManager;
  9. class BuyCatalog : public QDialog
  10. {
  11. Q_OBJECT
  12. private:
  13. struct CatalogItem
  14. {
  15. IAPClient::ProductData productData;
  16. QString url;
  17. int requestID;
  18. } ;
  19. typedef QList<CatalogItem> Catalog;
  20. public:
  21. explicit BuyCatalog(QWidget *parent = NULL);
  22. virtual ~BuyCatalog();
  23. inline void setDefaultProduct(QString& product){
  24. defaultProduct = product;
  25. }
  26. private:
  27. void requestNextProduct();
  28. bool isProductActivated(QString product);
  29. bool isIAPclientBusy();
  30. bool resetIAPrequest(int requestId);
  31. bool isReadyToBuy();
  32. private slots:
  33. /*
  34. * In-Application Purchase specific slots
  35. *
  36. * Slots matching the signals of the In-Application Purchase API, allowing
  37. * the application to receive callbacks
  38. */
  39. void productDataReceived( int requestId, QString status,
  40. IAPClient::ProductDataHash productData );
  41. void purchaseCompleted( int requestId, QString status, QString purchaseTicket );
  42. void purchaseFlowFinished( int requestId );
  43. void userAndDeviceDataReceived( int requestId, QString status,
  44. IAPClient::UserAndDeviceDataHash userdata );
  45. void restorableProductsReceived( int requestId, QString status,
  46. IAPClient::ProductDataList items );
  47. void restorationFlowFinished( int requestId );
  48. void restorationCompleted( int requestId, QString status, QString purchaseTicket );
  49. private slots:
  50. /*
  51. * Slot to handle user's tap on the Buy button on a catalog's product item.
  52. */
  53. void buyProduct();
  54. /*
  55. * Slot to handle user's tap on a catalog's product item, as a way of
  56. * accessing more information about it.
  57. *
  58. * QListWidgetItem* item - the list item on which the tap occured
  59. */
  60. void moreProductInfo(QListWidgetItem* item);
  61. /*
  62. * infoDialogClosed will be closed when the opened infoDialog gets closed.
  63. *
  64. * int result - the reason (positive or negative choice) for which the dialog was closed
  65. */
  66. void infoDialogClosed(int result);
  67. /*
  68. * Slot to handle user's tap on the Restore button on a catalog's product item.
  69. */
  70. void restoreProducts();
  71. void productListComplete();
  72. void productComplete(QByteArray* buf);
  73. private:
  74. /*
  75. * UI class.
  76. */
  77. Ui::BuyCatalogClass ui;
  78. QString defaultProduct;
  79. /*
  80. * List of product items as read from app's config file.
  81. */
  82. QStringList products;
  83. /*
  84. * Index in *products* list indicating which is the last product for which
  85. * info was requested from Ovi
  86. */
  87. int productsRequested;
  88. /*
  89. * Holds the requestId returned by the current In-Application Purchase call
  90. */
  91. int current_requestId;
  92. QString current_productId;
  93. /*
  94. * In-Application Purchase API
  95. */
  96. IAPClient *iap_client;
  97. /*
  98. * List of availble products as retrieved from Ovi
  99. */
  100. QList<IAPClient::ProductDataHash> available_products;
  101. /*
  102. * Dialog showing the full IAPClient::ProductData product description
  103. */
  104. ProductInfo* infoDialog;
  105. DownloadManager* dm;
  106. /*
  107. * The index of the product for which more info is displayed.
  108. */
  109. int current_product_index;
  110. IAPClient::ProductDataList restorableProductItems;
  111. QProgressDialog* busyIndicator;
  112. QString userAuth; // account digest
  113. };
  114. #endif // BUYCATALOG_H