|
1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // CIMPLAINBODYTEXT.CPP |
|
15 // |
|
16 |
|
17 #include "MIUTMSG.H" |
|
18 #include "MIUTCONV.H" |
|
19 #include "MIUT_ERR.H" |
|
20 #include "CIMPLAINBODYTEXT.H" |
|
21 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS |
|
22 #include "cimmessagepart.h" |
|
23 #include "cimconvertcharconv.h" |
|
24 #include "miut_errconsts.h" |
|
25 #endif |
|
26 #include <cmsvplainbodytext.h> |
|
27 |
|
28 /** |
|
29 NewL Factory method. |
|
30 @param aEmailMessage. The CImEmailMessage refernce corresponding to the message whose body text is being processed. |
|
31 @param aMsvEntry. The CMsvEntry correspoding to the message being processed. |
|
32 @param aEntryType. The TImEmailEntryType for the message. |
|
33 @param aChunkLength. The length of the chunk that will be stored/restored in a single operation. |
|
34 @param aWriteMode. Indicates whether CMsvStore needs to be opened in Read/Write mode. |
|
35 ETrue indicates Write mode. |
|
36 EFalse indicates Read mode. |
|
37 @return CImPlainBodyText.Pointer to CImPlainBodyText. |
|
38 */ |
|
39 CImPlainBodyText* CImPlainBodyText::NewL(CImEmailMessage& aEmailMessage, CMsvEntry& aMsvEntry, CImEmailMessage::TImEmailEntryType aEntryType, TInt aChunkLength, TBool aWriteMode) |
|
40 { |
|
41 CImPlainBodyText* self = new (ELeave) CImPlainBodyText(aEmailMessage, aMsvEntry); |
|
42 CleanupStack::PushL(self); |
|
43 self->ConstructL(aChunkLength, aEntryType, aWriteMode); |
|
44 CleanupStack::Pop(); |
|
45 return self; |
|
46 } |
|
47 |
|
48 /** |
|
49 Constructor |
|
50 @param aEmailMessage. The CImEmailMessage refernce corresponding to the message whose body text is |
|
51 @param aMsvEntry. The CMsvEntry correspoding to the message being processed. |
|
52 @return None. |
|
53 */ |
|
54 CImPlainBodyText::CImPlainBodyText(CImEmailMessage& aEmailMessage, CMsvEntry& aMsvEntry) |
|
55 : CMsgActive(EPriorityNormal), iEmailMessage(aEmailMessage), iMsvEntry(aMsvEntry) |
|
56 { |
|
57 } |
|
58 |
|
59 /** |
|
60 The 2nd Phase construction. |
|
61 */ |
|
62 void CImPlainBodyText::ConstructL(TInt aChunkLength, CImEmailMessage::TImEmailEntryType aEntryType, TBool aWriteMode) |
|
63 { |
|
64 iMessageId = iMsvEntry.EntryId(); |
|
65 RArray<TMsvId> textIdArray; |
|
66 CleanupClosePushL (textIdArray); |
|
67 iEmailMessage.GetBodyTextEntryIdL(iMessageId, aEntryType); |
|
68 |
|
69 // A message may contain more than one text part. |
|
70 TInt count = iEmailMessage.Selection().Count(); |
|
71 for(TInt i=0;i<count;++i) |
|
72 { |
|
73 textIdArray.Append(iEmailMessage.Selection().At(i)); |
|
74 } |
|
75 |
|
76 TUint charset = 0; // Will contain the charset when GetCharacterSetL returns. |
|
77 TBool override = EFalse; // Will be set to ETrue if the existing charset was overidden. |
|
78 iEmailMessage.GetCharacterSetL(iMessageId,charset,override); |
|
79 |
|
80 if(aWriteMode) |
|
81 { |
|
82 RFs& fileSvrSession = iMsvEntry.Session().FileSession(); |
|
83 |
|
84 CCnvCharacterSetConverter* characterConverter = CCnvCharacterSetConverter::NewL(); |
|
85 CleanupStack::PushL(characterConverter); |
|
86 |
|
87 CImConvertCharconv* charConv = CImConvertCharconv::NewL(*characterConverter, fileSvrSession); |
|
88 CleanupStack::PushL(charConv); |
|
89 |
|
90 TUint defaultCharset = charConv->DefaultCharset(); |
|
91 CleanupStack::PopAndDestroy(2,characterConverter); // charConv, characterConverter |
|
92 |
|
93 iMsvEntry.SetEntryL(textIdArray[0]); |
|
94 iStore = iMsvEntry.EditStoreL(); |
|
95 // Body text is stored in MailStore as 16 bit so set iIs8Bit to EFalse. |
|
96 iPlainTextArray.Append(iStore->InitialisePlainBodyTextForWriteL(EFalse, charset, defaultCharset)); |
|
97 } |
|
98 else |
|
99 { |
|
100 TInt textIdCount = textIdArray.Count(); |
|
101 for(TInt i=0; i<textIdCount; ++i) |
|
102 { |
|
103 // Pointing to the text entry. |
|
104 iMsvEntry.SetEntryL(textIdArray[i]); |
|
105 CMsvStore* store = iMsvEntry.ReadStoreL(); |
|
106 CleanupStack::PushL(store); |
|
107 |
|
108 iPlainTextArray.Append( store->InitialisePlainBodyTextForReadL(aChunkLength)); |
|
109 // if the existing charset was overidden by calling CImEmailMessage::SetCharacterSetL |
|
110 if(override) |
|
111 { |
|
112 iPlainTextArray[i]->SetCharacterSetL(charset); |
|
113 } |
|
114 CleanupStack::PopAndDestroy(store); |
|
115 store = NULL; |
|
116 } |
|
117 } |
|
118 CleanupStack::PopAndDestroy(&textIdArray); |
|
119 CActiveScheduler::Add(this); |
|
120 } |
|
121 |
|
122 /** |
|
123 Destructor |
|
124 */ |
|
125 EXPORT_C CImPlainBodyText::~CImPlainBodyText() |
|
126 { |
|
127 delete iStoreMessagePart; |
|
128 iPlainTextArray.ResetAndDestroy(); |
|
129 iPlainTextArray.Close(); |
|
130 delete iStore; |
|
131 } |
|
132 |
|
133 /** |
|
134 Store the plain body text part in chunks. |
|
135 @param aChunk. The 8 bit chunk that is to be stored. |
|
136 @param aStatus. The TRequestStatus parameter for this request. |
|
137 @leave KErrAccessDenied. If CMsvStore was opened in Read mode or |
|
138 If CommitL is already called. |
|
139 @leave Other Standard system-wide error codes. |
|
140 @return void. |
|
141 */ |
|
142 EXPORT_C void CImPlainBodyText::StoreChunkL(const TDesC8& aChunk, TRequestStatus& aStatus) |
|
143 { |
|
144 iPlainTextArray[0]->StoreChunkL(aChunk, aStatus); |
|
145 } |
|
146 |
|
147 |
|
148 /** |
|
149 Store the plain body text part in chunks,synchronous version. |
|
150 @param aChunk. The 8 bit chunk that is to be stored. |
|
151 @leave KErrAccessDenied. If CMsvStore was opened in Read mode or |
|
152 If CommitL is already called. |
|
153 @leave Other Standard system-wide error codes. |
|
154 @return void. |
|
155 */ |
|
156 EXPORT_C void CImPlainBodyText::StoreChunkL(const TDesC8& aChunk) |
|
157 { |
|
158 iPlainTextArray[0]->StoreChunkL(aChunk); |
|
159 } |
|
160 |
|
161 /** |
|
162 Store the body part in chunks(16 bit version). |
|
163 @param aChunk The 16 bit chunk that is to be stored. |
|
164 @param aStatus The TRequestStatus parameter for this request. |
|
165 @leave KErrNotSupported If the 8-bit storage was enabled. |
|
166 @leave KErrAccessDenied If CMsvStore was opened in Read mode or |
|
167 IfCommitL is already called. |
|
168 @leave Other Standard system-wide error codes. |
|
169 @return void |
|
170 */ |
|
171 EXPORT_C void CImPlainBodyText::StoreChunkL(const TDesC16& aChunk, TRequestStatus& aStatus) |
|
172 { |
|
173 iPlainTextArray[0]->StoreChunkL(aChunk, aStatus); |
|
174 } |
|
175 |
|
176 /** |
|
177 Store the body part in chunks(16 bit synchronous version). |
|
178 @param aChunk The 16 bit chunk that is to be stored. |
|
179 @leave KErrNotSupported If the 8-bit storage was enabled. |
|
180 @leave KErrAccessDenied If CMsvStore was opened in Read mode or |
|
181 If CommitL is already called. |
|
182 @leave Other Standard system-wide error codes. |
|
183 @return void |
|
184 */ |
|
185 EXPORT_C void CImPlainBodyText::StoreChunkL(const TDesC16& aChunk) |
|
186 { |
|
187 iPlainTextArray[0]->StoreChunkL(aChunk); |
|
188 } |
|
189 |
|
190 |
|
191 |
|
192 /** |
|
193 Converts and stores the CRichText contents to a plain text. |
|
194 @param aRichText The CRichText object that will be stored as plain body text. |
|
195 @leave KErrNotSupported If the 8-bit storage was enabled. |
|
196 @leave KErrAccessDenied If CMsvStore was opened in Read mode or |
|
197 If CommitL is already called. |
|
198 @leave Other Standard system-wide error codes. |
|
199 @return void. |
|
200 */ |
|
201 EXPORT_C void CImPlainBodyText::StoreRichTextAsPlainTextL(CRichText& aRichText) |
|
202 { |
|
203 iPlainTextArray[0]->StoreRichTextAsPlainTextL(aRichText); |
|
204 } |
|
205 |
|
206 /** |
|
207 Retrieve the next chunk of the plain body text. |
|
208 @param aChunk The output parameter contains the requested chunk. |
|
209 @param aStatus. The TRequestStatus for this request. |
|
210 @leave KErrAccessDenied If CMsvStore was opened in Write mode. |
|
211 @leave KErrNotSupported If 16-bit storage is enabled. |
|
212 @leave KErrUnderflow If aChunk MaxLength is less than iChunkMaxLength. |
|
213 @leave Other Standard system-wide error codes. |
|
214 @return void |
|
215 */ |
|
216 EXPORT_C void CImPlainBodyText::NextChunkL(TDes8& aChunk, TRequestStatus& aStatus) |
|
217 { |
|
218 __ASSERT_DEBUG(iChunkRetrievalState == EIdleState, gPanic(EImcmNonIdleRetrievalState)); |
|
219 iChunkRetrievalState = ENextChunk8Bit; |
|
220 |
|
221 iChunk8 = &aChunk; |
|
222 iChunk16 = NULL; |
|
223 iPlainTextArray[iIndex]->NextChunkL(aChunk, iStatus); |
|
224 SetActive(); |
|
225 Queue(aStatus); |
|
226 } |
|
227 |
|
228 /** |
|
229 Retrieve the next chunk of the plain body text. |
|
230 @param aChunk The output parameter contains the requested chunk. |
|
231 @leave KErrNotSupported If CMsvStore was opened in Write mode. |
|
232 @leave KErrNotSupported If 16-bit storage is enabled. |
|
233 @leave KErrUnderflow If aChunk MaxLength is less than iChunkMaxLength. |
|
234 @leave Other Standard system-wide error codes. |
|
235 @return void |
|
236 */ |
|
237 EXPORT_C void CImPlainBodyText::NextChunkL(TDes8& aChunk) |
|
238 { |
|
239 iPlainTextArray[iIndex]->NextChunkL(aChunk); |
|
240 // If there is more than one text part for the message move to next text part. |
|
241 if(aChunk.Length() == 0 && iIndex + 1 < iPlainTextArray.Count()) |
|
242 { |
|
243 iPlainTextArray[++iIndex]->NextChunkL(aChunk); |
|
244 } |
|
245 } |
|
246 |
|
247 |
|
248 |
|
249 /** |
|
250 Restore the plain body text into chunks. |
|
251 @param aChunk The output parameter contains the requested chunk on completion. |
|
252 @param aStatus The TRequestStatus parameter for this request. |
|
253 @leave KErrNotSupported If CMsvStore was opened in Write mode. |
|
254 @leave KErrUnderflow If aChunk MaxLength is less than iChunkMaxLength. |
|
255 @leave Other Standard system-wide error codes. |
|
256 @return void |
|
257 */ |
|
258 EXPORT_C void CImPlainBodyText::NextChunkL(TDes16& aChunk, TRequestStatus& aStatus) |
|
259 { |
|
260 __ASSERT_DEBUG(iChunkRetrievalState == EIdleState, gPanic(EImcmNonIdleRetrievalState)); |
|
261 iChunkRetrievalState = ENextChunk16Bit; |
|
262 |
|
263 iChunk16 = &aChunk; |
|
264 iChunk8 = NULL; |
|
265 iPlainTextArray[iIndex]->NextChunkL(aChunk, iStatus); |
|
266 SetActive(); |
|
267 Queue(aStatus); |
|
268 } |
|
269 |
|
270 /** |
|
271 Restores the plain body text into chunks. |
|
272 @param aChunk The output parameter contains the requested chunk on completion. |
|
273 @leave KErrNotSupported If CMsvStore was opened in Write mode. |
|
274 @leave KErrUnderflow If aChunk MaxLength is less than iChunkMaxLength. |
|
275 @leave Other Standard system-wide error codes. |
|
276 @return void |
|
277 */ |
|
278 EXPORT_C void CImPlainBodyText::NextChunkL(TDes16& aChunk) |
|
279 { |
|
280 iPlainTextArray[iIndex]->NextChunkL(aChunk); |
|
281 // If there is more than one text part for the message move to next text part. |
|
282 if(aChunk.Length() == 0 && iIndex + 1 < iPlainTextArray.Count()) |
|
283 { |
|
284 iPlainTextArray[++iIndex]->NextChunkL(aChunk); |
|
285 } |
|
286 } |
|
287 |
|
288 /** |
|
289 Retrieve the next chunk of the plain body text. |
|
290 @param aChunk The output parameter contains the requested chunk. |
|
291 @leave KErrNotSupported If CMsvStore was opened in Write mode. |
|
292 @leave KErrNotSupported If 16-bit storage is enabled. |
|
293 @leave KErrUnderflow If aChunk MaxLength is less than iChunkMaxLength. |
|
294 @leave Other Standard system-wide error codes. |
|
295 @return void |
|
296 */ |
|
297 EXPORT_C void CImPlainBodyText::PreviousChunkL(TDes8& aChunk, TRequestStatus& aStatus) |
|
298 { |
|
299 __ASSERT_DEBUG(iChunkRetrievalState == EIdleState, gPanic(EImcmNonIdleRetrievalState)); |
|
300 iChunkRetrievalState = EPreviousChunk8Bit; |
|
301 |
|
302 iChunk8 = &aChunk; |
|
303 iChunk16 = NULL; |
|
304 iPlainTextArray[iIndex]->PreviousChunkL(aChunk, iStatus); |
|
305 SetActive(); |
|
306 Queue(aStatus); |
|
307 } |
|
308 |
|
309 |
|
310 /** |
|
311 Retrieve the next chunk of the plain body text. |
|
312 @param aChunk The output parameter contains the requested chunk. |
|
313 @leave KErrNotSupported If CMsvStore was opened in Write mode. |
|
314 @leave KErrNotSupported If 16-bit storage is enabled. |
|
315 @leave KErrUnderflow If aChunk MaxLength is less than iChunkMaxLength. |
|
316 @leave Other Standard system-wide error codes. |
|
317 @return void |
|
318 */ |
|
319 EXPORT_C void CImPlainBodyText::PreviousChunkL(TDes8& aChunk) |
|
320 { |
|
321 iPlainTextArray[iIndex]->PreviousChunkL(aChunk); |
|
322 // If message had more than one text part move to previous text part. |
|
323 if(aChunk.Length() == 0 && iIndex - 1 >= 0) |
|
324 { |
|
325 iPlainTextArray[--iIndex]->PreviousChunkL(aChunk); |
|
326 } |
|
327 } |
|
328 |
|
329 /** |
|
330 Restore the plain body text into chunks. |
|
331 @param aChunk The output parameter contains the requested chunk on completion. |
|
332 @param aStatus The TRequestStatus parameter for this request. |
|
333 @leave KErrNotSupported If CMsvStore was opened in Write mode. |
|
334 @leave KErrUnderflow If aChunk MaxLength is less than iChunkMaxLength. |
|
335 @leave Other Standard system-wide error codes. |
|
336 @return void |
|
337 */ |
|
338 EXPORT_C void CImPlainBodyText::PreviousChunkL(TDes16& aChunk, TRequestStatus& aStatus) |
|
339 { |
|
340 __ASSERT_DEBUG(iChunkRetrievalState == EIdleState, gPanic(EImcmNonIdleRetrievalState)); |
|
341 iChunkRetrievalState = EPreviousChunk16Bit; |
|
342 |
|
343 iChunk16 = &aChunk; |
|
344 iChunk8 = NULL; |
|
345 iPlainTextArray[iIndex]->PreviousChunkL(aChunk, iStatus); |
|
346 SetActive(); |
|
347 Queue(aStatus); |
|
348 } |
|
349 |
|
350 /** |
|
351 Restore the plain body text into chunks. |
|
352 @param aChunk The output parameter contains the requested chunk on completion. |
|
353 @leave KErrNotSupported If CMsvStore was opened in Write mode. |
|
354 @leave KErrUnderflow If aChunk MaxLength is less than iChunkMaxLength. |
|
355 @leave Other Standard system-wide error codes. |
|
356 @return void |
|
357 */ |
|
358 EXPORT_C void CImPlainBodyText::PreviousChunkL(TDes16& aChunk) |
|
359 { |
|
360 iPlainTextArray[iIndex]->PreviousChunkL(aChunk); |
|
361 // If message had more than one text part move to previous text part. |
|
362 if(aChunk.Length() == 0 && iIndex - 1 >= 0) |
|
363 { |
|
364 iPlainTextArray[--iIndex]->PreviousChunkL(aChunk); |
|
365 } |
|
366 } |
|
367 |
|
368 |
|
369 |
|
370 void CImPlainBodyText::DoRunL() |
|
371 { |
|
372 __ASSERT_DEBUG(iChunkRetrievalState != EIdleState, gPanic(EImcmIdleRetrievalState)); |
|
373 |
|
374 TBool callComplete = ETrue; |
|
375 switch(iChunkRetrievalState) |
|
376 { |
|
377 // DoRunL is called as a result to a call to 8-bit asynchronous NextChunkL. |
|
378 case ENextChunk8Bit: |
|
379 { |
|
380 // Check if there are more than one body text part. |
|
381 if(iChunk8->Length() == 0 && iIndex + 1 < iPlainTextArray.Count()) |
|
382 { |
|
383 iPlainTextArray[++iIndex]->NextChunkL(*iChunk8, iStatus); |
|
384 SetActive(); |
|
385 callComplete = EFalse; |
|
386 } |
|
387 break; |
|
388 } |
|
389 case ENextChunk16Bit: |
|
390 { |
|
391 // Check if there are more than one body text part |
|
392 if(iChunk16->Length() == 0 && iIndex + 1 < iPlainTextArray.Count()) |
|
393 { |
|
394 iPlainTextArray[iIndex]->NextChunkL(*iChunk16, iStatus); |
|
395 SetActive(); |
|
396 callComplete = EFalse; |
|
397 } |
|
398 break; |
|
399 } |
|
400 |
|
401 case EPreviousChunk8Bit: |
|
402 { |
|
403 // DoRunL is called as a result to a call to 8-bit asynchronous PreviousChunkL. |
|
404 if(iChunk8->Length() == 0 && iIndex - 1 >= 0) |
|
405 { |
|
406 iPlainTextArray[--iIndex]->NextChunkL(*iChunk8, iStatus); |
|
407 SetActive(); |
|
408 callComplete = EFalse; |
|
409 } |
|
410 break; |
|
411 } |
|
412 case EPreviousChunk16Bit: |
|
413 { |
|
414 if(iChunk16->Length() == 0 && iIndex - 1 >= 0) |
|
415 { |
|
416 iPlainTextArray[--iIndex]->PreviousChunkL(*iChunk16, iStatus); |
|
417 SetActive(); |
|
418 callComplete = EFalse; |
|
419 } |
|
420 break; |
|
421 } |
|
422 default: |
|
423 { |
|
424 __ASSERT_DEBUG(iChunkRetrievalState != EIdleState, gPanic(EImcmIdleRetrievalState)); |
|
425 break; |
|
426 } |
|
427 |
|
428 } |
|
429 if(callComplete) |
|
430 { |
|
431 Complete(iStatus.Int()); |
|
432 iChunkRetrievalState = EIdleState; |
|
433 } |
|
434 } |
|
435 |
|
436 /** |
|
437 Commits the email message after it has been completed. |
|
438 @param aStatus The TRequestStatus parameter for this request. |
|
439 @return void |
|
440 */ |
|
441 EXPORT_C void CImPlainBodyText::CommitL(TRequestStatus& aStatus) |
|
442 { |
|
443 iPlainTextArray[0]->CommitL(); |
|
444 delete iStore; |
|
445 iStore = NULL; |
|
446 iStoreMessagePart = CImStoreMessagePart::StorePlainBodyTextL(aStatus, iMsvEntry, iMessageId); |
|
447 } |
|
448 |
|
449 |
|
450 /** |
|
451 Commits the email message after it has been completed along with mime header for this message. |
|
452 @param aStatus The TRequestStatus parameter for this request. |
|
453 @param aMimeHeader The CMimeHeader for this message. |
|
454 @return void |
|
455 */ |
|
456 EXPORT_C void CImPlainBodyText::CommitL(TRequestStatus& aStatus, CImMimeHeader& aMimeHeader) |
|
457 { |
|
458 // Commit the file.This will close the plainbody text file. |
|
459 iPlainTextArray[0]->CommitL(); |
|
460 delete iStore; |
|
461 iStore = NULL; |
|
462 iStoreMessagePart = CImStoreMessagePart::StorePlainBodyTextL(aStatus, iMsvEntry, iMessageId, aMimeHeader); |
|
463 } |
|
464 |
|
465 /** |
|
466 Cancels the relavent CMsvPlainBodyText object |
|
467 */ |
|
468 void CImPlainBodyText::DoCancel() |
|
469 { |
|
470 iPlainTextArray[iIndex]->Cancel(); |
|
471 } |