bool QMessageContentContainerPrivate::createAttachment(const QString& attachmentPath) { //set the attachment data if (!QFile::exists(attachmentPath)) { return false; } QFile attachmentFile(attachmentPath); if (!attachmentFile.open(QIODevice::ReadOnly)) { return false; } _content = attachmentFile.readAll(); _available = true; _size = attachmentFile.size(); attachmentFile.close(); QFileInfo fi(attachmentPath); _name = fi.fileName().toLatin1(); //set the mime-type QByteArray mimeType; QString type; TBuf8<255> fileBuffer; RApaLsSession session; QString fileString = fi.fileName(); TPtrC16 filePtr(reinterpret_cast<const TUint16*>(fileString.utf16())); TBuf8<20> fileType; TPtrC8 ptr8((TUint8 *)(_content.constData()), _content.length()); if(session.Connect() == KErrNone){ TDataRecognitionResult fileDataType; session.RecognizeData(filePtr, ptr8, fileDataType); fileType.Copy(fileDataType.iDataType.Des8()); mimeType = QByteArray((const char*)fileType.Ptr(), fileType.Length()); session.Close(); } QString extension(fi.suffix()); int index = mimeType.indexOf("/"); if (index != -1) { _type = mimeType.left(index).trimmed(); _subType = mimeType.mid(index + 1).trimmed(); } // set the whole filepath to _filename _filename = fi.filePath().toLatin1(); return true; }
bool QMessageContentContainerPrivate::createAttachment(const QString& attachmentPath) { //set the attachment data if (!QFile::exists(attachmentPath)) { return false; } QFile attachmentFile(attachmentPath); if (!attachmentFile.open(QIODevice::ReadOnly)) { return false; } _content = attachmentFile.readAll(); _available = true; _size = attachmentFile.size(); attachmentFile.close(); QFileInfo fi(attachmentPath); _name = fi.fileName().toLatin1(); //set the mime-type QByteArray mimeType; QString type; // TODO: QString extension(fi.suffix()); int index = mimeType.indexOf("/"); if (index != -1) { _type = mimeType.left(index).trimmed(); _subType = mimeType.mid(index + 1).trimmed(); } // set the whole filepath to _filename _filename = fi.filePath().toLatin1(); return true; }
//--------------------------------------------------------------- // TestUniDataModelPlugin::createMMS //--------------------------------------------------------------- void TestUniDataModelMMSPlugin::createMMS(TMsvId pId, TBool subjectField) { TMsvEntry indexEntry; indexEntry.iType = KUidMsvMessageEntry; indexEntry.iMtm = KUidMsgTypeMultimedia; indexEntry.iServiceId = iServiceId; indexEntry.iDate.HomeTime(); // Convert TTime to QDateTime , this will be used for comparing the time of mesage // when fetched from datamodel TTime unixEpoch(KUnixEpoch); TTimeIntervalSeconds seconds; TTime timeStamp = indexEntry.iDate; timeStamp.SecondsFrom(unixEpoch, seconds); retTimeStamp.setTime_t(seconds.Int()); TMsvId parentId = pId; CMsvEntry* entry = CMsvEntry::NewL(*iMSession,parentId,TMsvSelectionOrdering()); CleanupStack::PushL(entry); entry->SetEntryL(parentId); entry->CreateL(indexEntry); entry->SetEntryL(indexEntry.Id()); iMmsClientMtm->SwitchCurrentEntryL(entry->EntryId()); CMsvStore* store = iMmsClientMtm->Entry().EditStoreL(); CleanupStack::PushL(store); //MMS Message ID Saved iMessageId = indexEntry.Id(); //Adding Subject if(subjectField) { QString subject(TEST_MSG_SUBJECT); HBufC* subj = XQConversions::qStringToS60Desc(subject); iMmsClientMtm->SetSubjectL(*subj); } //Adding Sender QString sender(TEST_MSG_FROM1); HBufC* addr = XQConversions::qStringToS60Desc(sender); if (addr) { CleanupStack::PushL(addr); TBuf<32> name; name.Copy(addr->Left(32)); indexEntry.iDetails.Set(name); iMmsClientMtm->SetSenderL(*addr); CleanupStack::PopAndDestroy(addr); } //Adding Recipient QString recipient(TEST_MSG_RECIEPIENT1); HBufC* addr2 = XQConversions::qStringToS60Desc(recipient); if (addr2) { CleanupStack::PushL(addr2); iMmsClientMtm->AddAddresseeL(EMsvRecipientTo,*addr2); CleanupStack::PopAndDestroy(addr2); } //Adding cCRecipient QString recipient2(TEST_MSG_RECIEPIENT2); HBufC* addr3 = XQConversions::qStringToS60Desc(recipient2); if (addr3) { CleanupStack::PushL(addr3); iMmsClientMtm->AddAddresseeL(EMsvRecipientCc,*addr3); CleanupStack::PopAndDestroy(addr3); } //Adding bCCRecipient QString recipient3(TEST_MSG_RECIEPIENT3); HBufC* addr4 = XQConversions::qStringToS60Desc(recipient3); if (addr4) { CleanupStack::PushL(addr4); iMmsClientMtm->AddAddresseeL(EMsvRecipientBcc,*addr4); CleanupStack::PopAndDestroy(addr4); } //Create Text Attachment TMsvAttachmentId attaId = 0; TFileName attachmentFile( _L("story.txt") ); TBufC<12> story = _L( "Hello world!" ); iMmsClientMtm->CreateTextAttachmentL(*store, attaId, story, attachmentFile, ETrue ); qDebug() << "Text Attachment id" << attaId; //Image Attachment added to the message entry RFile attaFile; // Set filename of attachment TFileName name( KPictureFileName ); CMsvMimeHeaders* mimeHeaders = CMsvMimeHeaders::NewL(); CleanupStack::PushL( mimeHeaders ); // Set values to mime headers mimeHeaders->SetContentTypeL( _L8( "image") ); mimeHeaders->SetContentSubTypeL( _L8( "jpeg" ) ); _LIT8(KMimeType, "image/jpeg"); TBufC8<10> mimeType(KMimeType); // CreateAttachment2L will set the content type to attachment Info // Open the attachment file for reading attaFile.Open( iFs, name, EFileShareReadersOnly | EFileRead ); CleanupClosePushL(attaFile); CMsvAttachment* attaInfo = CMsvAttachment::NewL(CMsvAttachment::EMsvFile); // attaInfo ownerhip will be transferred to Attachment Manager. // It must not be pushed onto the cleanupStack before calling // CreateAttachment2L. iMmsClientMtm->CreateAttachment2L(*store, attaFile,mimeType,*mimeHeaders,attaInfo,attaId); qDebug() << "Image Attachment id" << attaId; // Now Attachment Manager owns the attaInfo CleanupStack::Pop(); // attaFile.Close() CleanupStack::PopAndDestroy(); // mimeHeaders store->CommitL(); CleanupStack::PopAndDestroy(store); // store iMmsClientMtm->SaveMessageL(); //Saving the message size for future checking msgSize = iMmsClientMtm->MessageSize(); CleanupStack::Pop(entry); // entry }