QList<CContactItemField *> CntTransformThumbnail::transformDetailL(const QContactDetail &detail) { if(detail.definitionName() != QContactThumbnail::DefinitionName) User::Leave(KErrArgument); QList<CContactItemField *> fieldList; //cast to thumbnail const QContactThumbnail &thumbnail(static_cast<const QContactThumbnail&>(detail)); //if thumbnail was not changed, use existing jpg image bool checksumExists; qint64 checksum = thumbnail.variantValue(KThumbnailChecksum).toLongLong(&checksumExists); if (!thumbnail.thumbnail().isNull() && checksumExists && thumbnail.thumbnail().cacheKey() == checksum) { initializeThumbnailFieldL(); CContactItemField *thumbnailField = CContactItemField::NewLC(*m_thumbnailFieldFromTemplate); QByteArray jpgData = thumbnail.variantValue(KThumbnailJpgImage).toByteArray(); TPtrC8 ptr((TUint8*)jpgData.data(), jpgData.size()); thumbnailField->StoreStorage()->SetThingL(ptr); fieldList.append(thumbnailField); CleanupStack::Pop(thumbnailField); } else if (!thumbnail.thumbnail().isNull()) { QByteArray jpgImage; QImage scaledImage; if (thumbnail.thumbnail().size().width() <= KMaxThumbnailSize.iWidth && thumbnail.thumbnail().size().height() <= KMaxThumbnailSize.iHeight) { scaledImage = thumbnail.thumbnail(); } else { scaledImage = thumbnail.thumbnail().scaled( KMaxThumbnailSize.iWidth, KMaxThumbnailSize.iHeight, Qt::KeepAspectRatio, Qt::SmoothTransformation); } if (!scaledImage.isNull()) { QBuffer buffer(&jpgImage); buffer.open(QIODevice::WriteOnly); scaledImage.save(&buffer, "JPG"); buffer.close(); initializeThumbnailFieldL(); CContactItemField *thumbnailField = CContactItemField::NewLC(*m_thumbnailFieldFromTemplate); TPtrC8 ptr((TUint8*)jpgImage.data(), jpgImage.size()); thumbnailField->StoreStorage()->SetThingL(ptr); fieldList.append(thumbnailField); CleanupStack::Pop(thumbnailField); } } return fieldList; }
void CntThumbnailCreator::CreateContactFieldL() { __ASSERT_DEBUG(m_imageData, User::Panic(KPanicCategory, KPanicUnitialized)); initializeThumbnailFieldL(); CContactItemField *thumbnailField = CContactItemField::NewLC(*m_thumbnailFieldFromTemplate); thumbnailField->StoreStorage()->SetThingL(*m_imageData); QT_TRYCATCH_LEAVING(m_fieldList->append(thumbnailField)); CleanupStack::Pop(thumbnailField); // Complete request to proceed to the final state TRequestStatus *status = &iStatus; User::RequestComplete(status, KErrNone); SetActive(); }