QContactDetail *CntTransformThumbnail::transformItemField(const CContactItemField& field, const QContact &contact) { Q_UNUSED(contact); QContactThumbnail *thumbnail = NULL; if (field.ContentType().ContainsFieldType(KUidContactFieldPicture) || field.ContentType().ContainsFieldType(KUidContactFieldVCardMapJPEG)) { // check storage type if (field.StorageType() != KStorageTypeStore) { return NULL; } // Create new field CContactStoreField* storage = field.StoreStorage(); QImage image; HBufC8 *theThing = storage->Thing(); if (theThing != NULL) { QByteArray bytes((char*)theThing->Ptr(), theThing->Length()); bool loaded = image.loadFromData(bytes, "JPG"); if (loaded) { // Create thumbnail detail thumbnail = new QContactThumbnail(); thumbnail->setThumbnail(image); // Keep jpg image, so no need for conversion when saving thumbnail detail. thumbnail->setValue(KThumbnailChecksum, image.cacheKey()); thumbnail->setValue(KThumbnailJpgImage, bytes); } } } return thumbnail; }
//Only support local file void QDeclarativeContact::setThumbnail(const QUrl& url) { QImage image(100, 50, QImage::Format_RGB32); image.load(url.toLocalFile()); QContactThumbnail detail; detail.setThumbnail(image); d->m_contact.saveDetail(&detail); emit detailsChanged(); }