purchasableitem.cpp 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. #include "purchasableitem.h"
  9. #include <QApplication>
  10. #include <QDebug>
  11. #include <QDir>
  12. #include "catalog_constants.h"
  13. #include "drmfile.h"
  14. #define QMLICONRESOURCE_NOTREADY "/qml/mototrialracer/in_application_billing/gfx/notready.png"
  15. PurchasableItem::PurchasableItem(ProductListModel &model,
  16. const QString &productID,
  17. const QString &productUrl):
  18. PurchasableItemBase(model, productID, productUrl)
  19. {
  20. m_productMetadata.drmProtection = IAPClient::OtherDrm;
  21. QString filepath(productUrl);
  22. filepath.replace(QString(KProtectedCatalog), QString(KProductIcon));
  23. filepath.append( + "/" + QString(KProductBuyIcon));
  24. m_buy_icon = new QImage(filepath);
  25. if (isPurchased()){
  26. m_unlocked_icon = new QImage(*m_buy_icon); // use copy constructor because
  27. // 'm_unlocked_icon' and 'm_buy_icon' are
  28. // deleted in the base class destructor
  29. // separatelly
  30. }
  31. //NOTE: the condittion (m_unlocked_icon == NULL) indicates locked content
  32. m_notready_icon = new QImage(QApplication::applicationDirPath() + QMLICONRESOURCE_NOTREADY);
  33. m_productUrl.append("/");
  34. m_productUrl.append(KProtectedResource);
  35. }
  36. void PurchasableItem::setUnlocked(QString* purchaseTicket)
  37. {
  38. saveTicket(purchaseTicket);
  39. bool success = true;
  40. QDir currentDir(m_productUrl);
  41. QStringList files = currentDir.entryList();
  42. foreach (QString filepath, files){
  43. DRMFile file;
  44. int error = file.open(m_productUrl + "/" + filepath);
  45. //IMPORTANT NOTE: Access to unprotected content is unrestricted by CAF
  46. //thus the checking below will pass for ordinary non-protected files
  47. success = (success && (error == KErrNone));
  48. if (!success){
  49. file.close();
  50. break;
  51. }
  52. //DRM protected file is unlocked
  53. qDebug() << "start iterating DRM file";
  54. for (int i = 0; i < file.count(); i++){
  55. QString tmp(file.getName(i));
  56. qDebug() << "DRM file : <" << tmp << ">";
  57. }
  58. file.close();
  59. }
  60. if (success){
  61. delete m_unlocked_icon; // just in case to prevent possible memory leak
  62. m_unlocked_icon = new QImage(*m_buy_icon);
  63. }
  64. }
  65. bool PurchasableItem::isPurchased()
  66. {
  67. return readTicket();
  68. }