drmimageprovider.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #include "drmimageprovider.h"
  2. #include <QApplication>
  3. #include <QUrl>
  4. #include <QDebug>
  5. #if defined(USESYMBIANDRM)
  6. #include "DRMFile.h"
  7. #endif
  8. DrmImageProvider::DrmImageProvider()
  9. : QDeclarativeImageProvider(QDeclarativeImageProvider::Image)
  10. {
  11. }
  12. QImage DrmImageProvider::requestImage(const QString & id, QSize * size, const QSize & requestedSize)
  13. {
  14. QString path;
  15. if (id.startsWith("resourceid"))
  16. {
  17. path = QUrl(getDrmDataRoot()).toLocalFile();
  18. }
  19. else
  20. {
  21. path = QUrl(getFreeDataRoot()).toLocalFile();
  22. }
  23. path += id;
  24. qDebug() << "requestImage " << path;
  25. int width = 100;
  26. int height = 50;
  27. if (size)
  28. *size = QSize(width, height);
  29. QImage image(requestedSize.width() > 0 ? requestedSize.width() : width,
  30. requestedSize.height() > 0 ? requestedSize.height() : height,
  31. QImage::Format_ARGB32_Premultiplied);
  32. #if defined(USESYMBIANDRM)
  33. uchar* buffer = NULL;
  34. int filesize = 0;
  35. DRMFile file;
  36. if(file.open(path) == 0)
  37. {
  38. filesize = file.size();
  39. buffer = new uchar[filesize];
  40. int result = file.read((char*)buffer, filesize);
  41. if(result != filesize)
  42. {
  43. qDebug() << "Failed to read the file";
  44. delete [] buffer;
  45. buffer = NULL;
  46. }
  47. file.close();
  48. }
  49. else
  50. qDebug() << "Failed to open the file!" ;
  51. if(buffer!=NULL)
  52. {
  53. if(!image.loadFromData(buffer, filesize))
  54. qDebug() << "Loading image failed";
  55. }
  56. delete [] buffer;
  57. #else
  58. if(!image.load(path))
  59. {
  60. qDebug() << "load failed";
  61. }
  62. #endif
  63. return image;
  64. }