135 CMsvEntry* aParentEntry, // A pointer to new message server entry. |
135 CMsvEntry* aParentEntry, // A pointer to new message server entry. |
136 RFile& aFile) // New file to store |
136 RFile& aFile) // New file to store |
137 { |
137 { |
138 FLOG(_L("[OBEXUTILS]\t StoreAsRichTextL()")); |
138 FLOG(_L("[OBEXUTILS]\t StoreAsRichTextL()")); |
139 |
139 |
140 // Read the file into buffer |
|
141 |
|
142 CBufFlat* buffer = CBufFlat::NewL( 16 ); |
|
143 CleanupStack::PushL(buffer); // 1st push |
|
144 |
|
145 TInt fileLength = 0; |
140 TInt fileLength = 0; |
146 User::LeaveIfError( aFile.Size( fileLength ) ); |
141 User::LeaveIfError( aFile.Size( fileLength ) ); |
147 |
142 |
148 buffer->ResizeL( fileLength ); |
143 // Calculate the number of blocks to read |
149 TPtr8 bufferPtr = buffer->Ptr(0); |
144 const TInt blockSize = 128 * 1024; |
150 |
145 TInt fullBlockCnt = fileLength / blockSize; |
151 User::LeaveIfError( aFile.Read( bufferPtr ) ); |
146 if (fileLength % blockSize > 0) |
152 |
147 { |
153 // In order for Bio to understand 8-bit binary data, |
148 fullBlockCnt++; |
154 // it needs to be stored in wide rich text object |
149 } |
155 // in the low byte of each word with the upper byte as 0. |
150 |
156 // Do not use UTF8, just convert 8-bit to 16-bit. |
151 CRichText* richText = ConstructRichTextLC(); // 1st, 2nd, 3rd push |
157 |
152 |
158 CRichText* richText = ConstructRichTextLC(); // 2nd, 3rd, 4th push |
153 RBuf8 buffer8; |
159 HBufC* convert8BitTo16Bit = HBufC::NewLC(fileLength); // 5th push |
154 CleanupClosePushL(buffer8); // 4th push |
160 convert8BitTo16Bit->Des().Copy( bufferPtr ); |
155 buffer8.CreateL( blockSize ); |
161 buffer->Reset(); // free unused memory before InsertL() |
156 RBuf buffer16; |
162 |
157 CleanupClosePushL(buffer16); // 5th push |
163 richText->InsertL(0, *convert8BitTo16Bit); |
158 buffer16.CreateL(blockSize); |
164 CleanupStack::PopAndDestroy(convert8BitTo16Bit); |
159 |
165 // -1 pop: free unused memory before StoreBodyTextL() |
160 // Read the file into buffer in small chunks |
|
161 TInt readBytes = 0; |
|
162 for (TInt i = 0; i < fullBlockCnt; ++i) |
|
163 { |
|
164 User::LeaveIfError( aFile.Read( buffer8 ) ); |
|
165 |
|
166 // In order for Bio to understand 8-bit binary data, |
|
167 // it needs to be stored in wide rich text object |
|
168 // in the low byte of each word with the upper byte as 0. |
|
169 // Do not use UTF8, just convert 8-bit to 16-bit. |
|
170 buffer16.Copy( buffer8 ); |
|
171 |
|
172 richText->InsertL(readBytes, buffer16); |
|
173 readBytes += buffer8.Length(); |
|
174 } |
|
175 CleanupStack::PopAndDestroy(2, &buffer8); |
|
176 // -2 pop: free unused memory before StoreBodyTextL() |
166 |
177 |
167 CMsvStore* parentStore = aParentEntry->EditStoreL(); |
178 CMsvStore* parentStore = aParentEntry->EditStoreL(); |
168 CleanupStack::PushL(parentStore); // 5th push |
179 CleanupStack::PushL(parentStore); // 4th push |
169 parentStore->StoreBodyTextL(*richText); |
180 parentStore->StoreBodyTextL(*richText); |
170 parentStore->CommitL(); |
181 parentStore->CommitL(); |
171 |
182 |
172 CleanupStack::PopAndDestroy(5); // parentStore, richText, richParaFormatLayer, |
183 CleanupStack::PopAndDestroy(4); // parentStore, richText, richParaFormatLayer, |
173 // richCharFormatLayer, buffer |
184 // richCharFormatLayer |
174 |
185 |
175 FLOG(_L("[OBEXUTILS]\t StoreAsRichTextL() completed")); |
186 FLOG(_L("[OBEXUTILS]\t StoreAsRichTextL() completed")); |
176 } |
187 } |
177 |
188 |
178 // ----------------------------------------------------------------------------- |
189 // ----------------------------------------------------------------------------- |
325 HBufC* buf16 = HBufC::NewLC(mimeType.Length()); |
336 HBufC* buf16 = HBufC::NewLC(mimeType.Length()); |
326 buf16->Des().Copy(mimeType); |
337 buf16->Des().Copy(mimeType); |
327 TPtrC mimeType16(buf16->Des()); |
338 TPtrC mimeType16(buf16->Des()); |
328 CleanupStack::PopAndDestroy(); // buf16 |
339 CleanupStack::PopAndDestroy(); // buf16 |
329 |
340 |
330 CUpdateMusicCollection* updateMusiccollection =CUpdateMusicCollection::NewL() ; |
341 CUpdateMusicCollection* updateMusicCollection = CUpdateMusicCollection::NewL() ; |
331 if (updateMusiccollection->isSupported(mimeType16)) |
342 if (updateMusicCollection->isSupported(mimeType16)) |
332 { |
343 { |
333 updateMusiccollection->addToCollectionL(aFileName); |
344 updateMusicCollection->addToCollectionL(aFileName); |
334 } |
345 } |
335 |
346 |
336 aAttachInfo->SetMimeTypeL( mimeType ); |
347 aAttachInfo->SetMimeTypeL( mimeType ); |
337 |
348 |
338 FLOG(_L("[OBEXUTILS]\t RecogniseObjectsL() completed")); |
349 FLOG(_L("[OBEXUTILS]\t RecogniseObjectsL() completed")); |