|
1 /* |
|
2 * Copyright (c) 2005 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Message Base class. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "CCAMessageBase.h" |
|
20 #include "MCAMessageContainerInfo.h" |
|
21 #include "PublicEngineDefinitions.h" |
|
22 #include "PrivateEngineDefinitions.h" |
|
23 #include "CAUtils.h" |
|
24 #include "MCAContentProcessor.h" |
|
25 #include "MCAContentProcessObserver.h" |
|
26 |
|
27 #include "ChatDebugAssert.h" |
|
28 #include "ChatDebugPrint.h" |
|
29 |
|
30 #include <stringloader.h> |
|
31 #include <caengineNG.rsg> |
|
32 #include <avkon.rsg> |
|
33 #include <txtetext.h> //for CEditableText::ELineBreak |
|
34 |
|
35 _LIT( KLineFeedFormat, "%c" ); |
|
36 _LIT( KSpace, " " ); |
|
37 const TInt KTimeStampMaxLength = 20; // max timestamp string length |
|
38 |
|
39 // Identification tool |
|
40 TBool Compare( const CCAMessageBase::SProcessorObserverPair& aFirst, |
|
41 const CCAMessageBase::SProcessorObserverPair& aSecond ) |
|
42 { |
|
43 if ( aFirst.iProcessor == aSecond.iProcessor ) |
|
44 { |
|
45 return ETrue; |
|
46 } |
|
47 return EFalse; |
|
48 } |
|
49 |
|
50 //----------------------------------------------------------------------------- |
|
51 // CCAMessageBase::CCAMessageBase |
|
52 // ( Other items commented in header ) |
|
53 //----------------------------------------------------------------------------- |
|
54 CCAMessageBase::CCAMessageBase() |
|
55 { |
|
56 } |
|
57 |
|
58 |
|
59 //----------------------------------------------------------------------------- |
|
60 // CCAMessageBase::ConstructL |
|
61 // ( Other items commented in header ) |
|
62 //----------------------------------------------------------------------------- |
|
63 void CCAMessageBase::ConstructL( TInt aOpCode, |
|
64 const TDesC& aSender, |
|
65 const TDesC& aRecipient, |
|
66 const MDesCArray* aRecipients, |
|
67 const MDesCArray* aScreenNames ) |
|
68 { |
|
69 iOperationCode = aOpCode; |
|
70 |
|
71 iSender = aSender.AllocL(); |
|
72 iRecipient = aRecipient.AllocL(); |
|
73 |
|
74 // Sender & recipient |
|
75 if ( aRecipients ) |
|
76 { |
|
77 CDesCArrayFlat* tempArray = new ( ELeave ) CDesCArrayFlat( 1 ); |
|
78 CleanupStack::PushL( tempArray ); |
|
79 TInt count( aRecipients->MdcaCount() ); |
|
80 for ( TInt a( 0 ); a < count; ++a ) |
|
81 { |
|
82 tempArray->AppendL( aRecipients->MdcaPoint( a ) ); |
|
83 } |
|
84 CleanupStack::Pop( tempArray ); |
|
85 delete iRecipients; |
|
86 iRecipients = tempArray; |
|
87 } |
|
88 |
|
89 if ( aScreenNames ) |
|
90 { |
|
91 CDesCArrayFlat* tempArray = new ( ELeave ) CDesCArrayFlat( 1 ); |
|
92 CleanupStack::PushL( tempArray ); |
|
93 TInt count( aScreenNames->MdcaCount() ); |
|
94 for ( TInt a( 0 ); a < count; ++a ) |
|
95 { |
|
96 tempArray->AppendL( aScreenNames->MdcaPoint( a ) ); |
|
97 } |
|
98 CleanupStack::Pop( tempArray ); |
|
99 delete iScreenNames; |
|
100 iScreenNames = tempArray; |
|
101 } |
|
102 |
|
103 |
|
104 iMessagerType = EMessageOther; |
|
105 iSystemMessageType = ESystemMessageNone; |
|
106 iTime.HomeTime(); |
|
107 iMessageVersion = KVersionNum; |
|
108 |
|
109 ResolveMessageType( aRecipients, aScreenNames ); |
|
110 } |
|
111 |
|
112 //----------------------------------------------------------------------------- |
|
113 // CCAMessageBase::~CCAMessageBase |
|
114 // ( Other items commented in header ) |
|
115 //----------------------------------------------------------------------------- |
|
116 CCAMessageBase::~CCAMessageBase() |
|
117 { |
|
118 __CHAT_ASSERT_DEBUG( iOwnerCount == 0 ); |
|
119 delete iMimeType; |
|
120 delete iSender; |
|
121 delete iRecipient; |
|
122 delete iContentData; |
|
123 delete iText; |
|
124 delete iRecipients; |
|
125 delete iScreenNames; |
|
126 if ( iProcessors.Count() ) |
|
127 { |
|
128 TInt ignore = KErrNone; |
|
129 TRAP( ignore, iProcessors[ 0 ].iProcessor->RemoveProcessingL( *this ) ); |
|
130 } |
|
131 iProcessors.Close(); |
|
132 delete iForwardPart; |
|
133 } |
|
134 |
|
135 //----------------------------------------------------------------------------- |
|
136 // CCAMessageBase::TimeStamp |
|
137 // ( Other items commented in header ) |
|
138 //----------------------------------------------------------------------------- |
|
139 const TTime& CCAMessageBase::TimeStamp() const |
|
140 { |
|
141 return iTime; |
|
142 } |
|
143 |
|
144 //----------------------------------------------------------------------------- |
|
145 // CCAMessageBase::MessageType |
|
146 // ( Other items commented in header ) |
|
147 //----------------------------------------------------------------------------- |
|
148 MCAMessage::TMessageType CCAMessageBase::MessageType() const |
|
149 { |
|
150 return iMessageType; |
|
151 } |
|
152 |
|
153 //----------------------------------------------------------------------------- |
|
154 // CCAMessageBase::MessagerType |
|
155 // ( Other items commented in header ) |
|
156 //----------------------------------------------------------------------------- |
|
157 MCAMessage::TMessagerType CCAMessageBase::MessagerType() const |
|
158 { |
|
159 return iMessagerType; |
|
160 } |
|
161 |
|
162 //----------------------------------------------------------------------------- |
|
163 // CCAMessageBase::OperationCode |
|
164 // ( Other items commented in header ) |
|
165 //----------------------------------------------------------------------------- |
|
166 TInt CCAMessageBase::OperationCode() const |
|
167 { |
|
168 return iOperationCode; |
|
169 } |
|
170 |
|
171 //----------------------------------------------------------------------------- |
|
172 // CCAMessageBase::Recipient |
|
173 // ( Other items commented in header ) |
|
174 //----------------------------------------------------------------------------- |
|
175 void CCAMessageBase::SetOperationCode( TInt aOpId ) |
|
176 { |
|
177 iOperationCode = aOpId; |
|
178 } |
|
179 |
|
180 //----------------------------------------------------------------------------- |
|
181 // CCAMessageBase::Recipient |
|
182 // ( Other items commented in header ) |
|
183 //----------------------------------------------------------------------------- |
|
184 const TDesC& CCAMessageBase::Recipient() const |
|
185 { |
|
186 if ( iRecipient ) |
|
187 { |
|
188 return *iRecipient; |
|
189 } |
|
190 return KNullDesC; |
|
191 } |
|
192 |
|
193 //----------------------------------------------------------------------------- |
|
194 // CCAMessageBase::Recipients |
|
195 // ( Other items commented in header ) |
|
196 //----------------------------------------------------------------------------- |
|
197 const MDesCArray* CCAMessageBase::Recipients() const |
|
198 { |
|
199 return iRecipients; |
|
200 } |
|
201 |
|
202 //----------------------------------------------------------------------------- |
|
203 // CCAMessageBase::ScreenNames |
|
204 // ( Other items commented in header ) |
|
205 //----------------------------------------------------------------------------- |
|
206 const MDesCArray* CCAMessageBase::ScreenNames() const |
|
207 { |
|
208 return iScreenNames; |
|
209 } |
|
210 |
|
211 //----------------------------------------------------------------------------- |
|
212 // CCAMessageBase::IncreaseOwnerCount |
|
213 // ( Other items commented in header ) |
|
214 //----------------------------------------------------------------------------- |
|
215 void CCAMessageBase::IncreaseOwnerCount() |
|
216 { |
|
217 ++iOwnerCount; |
|
218 } |
|
219 |
|
220 //----------------------------------------------------------------------------- |
|
221 // CCAMessageBase::DecreaseOwnerCount |
|
222 // ( Other items commented in header ) |
|
223 //----------------------------------------------------------------------------- |
|
224 TBool CCAMessageBase::DecreaseOwnerCount() |
|
225 { |
|
226 return ( --iOwnerCount <= 0 ); |
|
227 } |
|
228 |
|
229 //----------------------------------------------------------------------------- |
|
230 // CCAMessageBase::Target |
|
231 // ( Other items commented in header ) |
|
232 //----------------------------------------------------------------------------- |
|
233 const TDesC& CCAMessageBase::ServerAddress() const |
|
234 { |
|
235 if ( iInfo ) |
|
236 { |
|
237 return iInfo->ServerAddress(); |
|
238 } |
|
239 return KNullDesC; |
|
240 } |
|
241 |
|
242 //----------------------------------------------------------------------------- |
|
243 // CCAMessageBase::Target |
|
244 // ( Other items commented in header ) |
|
245 //----------------------------------------------------------------------------- |
|
246 const TDesC& CCAMessageBase::UserId() const |
|
247 { |
|
248 if ( iInfo ) |
|
249 { |
|
250 return iInfo->UserId(); |
|
251 } |
|
252 return KNullDesC; |
|
253 } |
|
254 |
|
255 //----------------------------------------------------------------------------- |
|
256 // CCAMessageBase::Target |
|
257 // ( Other items commented in header ) |
|
258 //----------------------------------------------------------------------------- |
|
259 const TDesC& CCAMessageBase::Target() const |
|
260 { |
|
261 if ( iInfo ) |
|
262 { |
|
263 return iInfo->Target(); |
|
264 } |
|
265 return KNullDesC; |
|
266 } |
|
267 |
|
268 //----------------------------------------------------------------------------- |
|
269 // CCAMessageBase::SetMessageContainerInfo |
|
270 // ( Other items commented in header ) |
|
271 //----------------------------------------------------------------------------- |
|
272 void CCAMessageBase::SetContainerInfo( MCAMessageContainerInfo* aInfo ) |
|
273 { |
|
274 iInfo = aInfo; |
|
275 } |
|
276 |
|
277 //----------------------------------------------------------------------------- |
|
278 // CCAMessageBase::Text |
|
279 // ( Other items commented in header ) |
|
280 //----------------------------------------------------------------------------- |
|
281 MCALoggerMessage& CCAMessageBase::LoggerMessage() |
|
282 { |
|
283 return *this; |
|
284 } |
|
285 |
|
286 //----------------------------------------------------------------------------- |
|
287 // CCAMessageBase::AddContentProcessor |
|
288 // ( Other items commented in header ) |
|
289 //----------------------------------------------------------------------------- |
|
290 TInt CCAMessageBase::AddContentProcessor( MCAContentProcessor& aProcessor, |
|
291 MCAContentProcessObserver* aObserver ) |
|
292 { |
|
293 CHAT_DP_FUNC_ENTER( "CCAMessageBase::AddContentProcessor" ); |
|
294 |
|
295 SProcessorObserverPair pair = |
|
296 { |
|
297 &aProcessor, |
|
298 aObserver |
|
299 }; |
|
300 |
|
301 TInt originalCountOfProcessors = iProcessors.Count(); |
|
302 TInt error = iProcessors.Append( pair ); |
|
303 if ( error == KErrNone ) |
|
304 { |
|
305 CHAT_DP( D_CHAT_LIT( " Processor added." ) ); |
|
306 if ( iProcessors.Count() == 1 ) |
|
307 { |
|
308 TRAP( error, LaunchProcessingL() ); |
|
309 CHAT_DP( D_CHAT_LIT( " Launch processing. Retval = %d" ), error ); |
|
310 } |
|
311 } |
|
312 CHAT_DP_FUNC_DONE( "CCAMessageBase::AddContentProcessor" ); |
|
313 if ( error < KErrNone ) |
|
314 { |
|
315 return error; |
|
316 } |
|
317 return iProcessors.Count() > originalCountOfProcessors; |
|
318 } |
|
319 |
|
320 //----------------------------------------------------------------------------- |
|
321 // CCAMessageBase::HandleProcessingComplete |
|
322 // ( Other items commented in header ) |
|
323 //----------------------------------------------------------------------------- |
|
324 void CCAMessageBase::HandleProcessingComplete( MCAContentProcessor& aProcessor, |
|
325 TInt aStatus ) |
|
326 { |
|
327 CHAT_DP_FUNC_ENTER( "CCAMessageBase::HandleProcessingComplete" ); |
|
328 SProcessorObserverPair pair = |
|
329 { |
|
330 &aProcessor, |
|
331 NULL |
|
332 }; |
|
333 TIdentityRelation< SProcessorObserverPair > rule( *Compare ); |
|
334 TInt index = iProcessors.Find( pair, rule ); |
|
335 if ( index >= 0 ) |
|
336 { |
|
337 if ( iProcessors[ index ].iObserver ) |
|
338 { |
|
339 CHAT_DP( D_CHAT_LIT( "Inform processing observer about completion \ |
|
340 of processor." ) ); |
|
341 iProcessors[ index ].iObserver->HandleProcessingComplete( |
|
342 aProcessor, *this, aStatus ); |
|
343 } |
|
344 iProcessors.Remove( index ); |
|
345 } |
|
346 if ( iDefaultContentObserver ) |
|
347 { |
|
348 iDefaultContentObserver->HandleProcessingComplete( aProcessor, *this, |
|
349 aStatus ); |
|
350 } |
|
351 CHAT_DP_FUNC_DONE( "CCAMessageBase::HandleProcessingComplete" ); |
|
352 } |
|
353 |
|
354 //----------------------------------------------------------------------------- |
|
355 // CCAMessageBase::MimeType |
|
356 // ( Other items commented in header ) |
|
357 //----------------------------------------------------------------------------- |
|
358 const TDesC8& CCAMessageBase::MimeType() const |
|
359 { |
|
360 if ( iMimeType ) |
|
361 { |
|
362 return *iMimeType; |
|
363 } |
|
364 return KNullDesC8; |
|
365 } |
|
366 |
|
367 //----------------------------------------------------------------------------- |
|
368 // CCAMessageBase::ContentData |
|
369 // ( Other items commented in header ) |
|
370 //----------------------------------------------------------------------------- |
|
371 const TDesC8& CCAMessageBase::ContentData() const |
|
372 { |
|
373 if ( iContentData ) |
|
374 { |
|
375 return *iContentData; |
|
376 } |
|
377 return KNullDesC8; |
|
378 } |
|
379 |
|
380 //----------------------------------------------------------------------------- |
|
381 // CCAMessageBase::SetContentData |
|
382 // ( Other items commented in header ) |
|
383 //----------------------------------------------------------------------------- |
|
384 void CCAMessageBase::SetContentData( HBufC8* aNewContent ) |
|
385 { |
|
386 delete iContentData; |
|
387 iContentData = aNewContent; |
|
388 } |
|
389 |
|
390 //----------------------------------------------------------------------------- |
|
391 // CCAMessageBase::ContentProcessState |
|
392 // ( Other items commented in header ) |
|
393 //----------------------------------------------------------------------------- |
|
394 MCAMessage::TContentProcessState CCAMessageBase::ContentProcessState() const |
|
395 { |
|
396 return iContentProcessingState; |
|
397 } |
|
398 |
|
399 |
|
400 //----------------------------------------------------------------------------- |
|
401 // CCAMessageBase::SetProcessState |
|
402 // ( Other items commented in header ) |
|
403 //----------------------------------------------------------------------------- |
|
404 void CCAMessageBase::SetProcessState( TContentProcessState aNewState ) |
|
405 { |
|
406 iContentProcessingState = aNewState; |
|
407 } |
|
408 |
|
409 //----------------------------------------------------------------------------- |
|
410 // CCAMessageBase::ReleaseTemporaryContentData |
|
411 // ( Other items commented in header ) |
|
412 //----------------------------------------------------------------------------- |
|
413 void CCAMessageBase::ReleaseTemporaryContentData() |
|
414 { |
|
415 // No temporary content data. |
|
416 } |
|
417 |
|
418 //----------------------------------------------------------------------------- |
|
419 // CCAMessageBase::Text |
|
420 // ( Other items commented in header ) |
|
421 //----------------------------------------------------------------------------- |
|
422 const TDesC& CCAMessageBase::Text() const |
|
423 { |
|
424 if ( iText ) |
|
425 { |
|
426 return *iText; |
|
427 } |
|
428 return KNullDesC; |
|
429 } |
|
430 |
|
431 //----------------------------------------------------------------------------- |
|
432 // CCAMessageBase::Sender |
|
433 // ( Other items commented in header ) |
|
434 //----------------------------------------------------------------------------- |
|
435 const TDesC& CCAMessageBase::Sender() const |
|
436 { |
|
437 if ( iSender ) |
|
438 { |
|
439 return *iSender; |
|
440 } |
|
441 return KNullDesC; |
|
442 } |
|
443 |
|
444 //----------------------------------------------------------------------------- |
|
445 // CCAMessageBase::Sender |
|
446 // ( Other items commented in header ) |
|
447 //----------------------------------------------------------------------------- |
|
448 void CCAMessageBase::SetContentProcessObserver( |
|
449 MCAContentProcessObserver* aObserver ) |
|
450 { |
|
451 iDefaultContentObserver = aObserver; |
|
452 } |
|
453 |
|
454 //----------------------------------------------------------------------------- |
|
455 // CCAMessageBase::SizeInBytes |
|
456 // ( Other items commented in header ) |
|
457 //----------------------------------------------------------------------------- |
|
458 TInt CCAMessageBase::SizeInBytes() const |
|
459 { |
|
460 return iSender->Size() + |
|
461 iRecipient->Size(); |
|
462 } |
|
463 |
|
464 // --------------------------------------------------------- |
|
465 // CCAMessageBase::FailedMessage() |
|
466 // --------------------------------------------------------- |
|
467 // |
|
468 TBool CCAMessageBase::FailedMessage() const |
|
469 { |
|
470 return iFailed; |
|
471 } |
|
472 |
|
473 // --------------------------------------------------------- |
|
474 // CCAMessageBase::SetForwardPart() |
|
475 // --------------------------------------------------------- |
|
476 // |
|
477 void CCAMessageBase::SetForwardPartL( const HBufC* aFwdPart ) |
|
478 { |
|
479 // If NULL |
|
480 if ( !aFwdPart ) |
|
481 { |
|
482 delete iForwardPart; |
|
483 iForwardPart = NULL; |
|
484 return; |
|
485 } |
|
486 |
|
487 HBufC* temp = aFwdPart->AllocL(); |
|
488 // Delete old |
|
489 delete iForwardPart; |
|
490 iForwardPart = NULL; |
|
491 iForwardPart = temp; |
|
492 } |
|
493 |
|
494 // --------------------------------------------------------- |
|
495 // CCAMessageBase::ForwardPart() |
|
496 // --------------------------------------------------------- |
|
497 // |
|
498 const HBufC* CCAMessageBase::ForwardPart() const |
|
499 { |
|
500 return iForwardPart; |
|
501 } |
|
502 |
|
503 // --------------------------------------------------------- |
|
504 // CCAMessageBase::FailedMessage() |
|
505 // --------------------------------------------------------- |
|
506 // |
|
507 void CCAMessageBase::SetFailed( TBool aFailed /* = ETrue */ ) |
|
508 { |
|
509 iFailed = aFailed; |
|
510 } |
|
511 |
|
512 // --------------------------------------------------------- |
|
513 // CCAMessageBase::InternalizeL() |
|
514 // --------------------------------------------------------- |
|
515 // |
|
516 void CCAMessageBase::InternalizeL( RReadStream& aStream ) |
|
517 { |
|
518 iMessageType = static_cast< TMessageType >( aStream.ReadUint16L() ); |
|
519 iMessagerType = static_cast< TMessagerType >( aStream.ReadUint16L() ); |
|
520 |
|
521 // This item does not exist in version 0 |
|
522 if ( iMessageVersion > 0 ) |
|
523 { |
|
524 iSystemMessageType = |
|
525 static_cast< TSystemMessage >( aStream.ReadUint16L() ); |
|
526 } |
|
527 |
|
528 iFailed = static_cast< TBool >( aStream.ReadUint8L() ); |
|
529 |
|
530 //this member was newly added. |
|
531 //read also this member from the file, because |
|
532 //the user could have saved the image before saving a conversation |
|
533 iSaved = static_cast< TBool >( aStream.ReadUint8L() ); |
|
534 |
|
535 TUint32 high = aStream.ReadUint32L(); |
|
536 TUint32 low = aStream.ReadUint32L(); |
|
537 |
|
538 iTime = MAKE_TINT64( high, low ); |
|
539 |
|
540 HBufC* tempSender = CAUtils::InternalizeBufferFromStreamL( aStream ); |
|
541 delete iSender; |
|
542 iSender = tempSender; |
|
543 |
|
544 HBufC* tempRecipient = CAUtils::InternalizeBufferFromStreamL( aStream ); |
|
545 delete iRecipient; |
|
546 iRecipient = tempRecipient; |
|
547 |
|
548 HBufC* tempMessage = CAUtils::InternalizeBufferFromStreamL( aStream ); |
|
549 delete iText; |
|
550 iText = tempMessage; |
|
551 |
|
552 if ( ContentType() != EContentText && ContentType() != EContentInvalid ) |
|
553 { |
|
554 HBufC8* tempContentType = |
|
555 CAUtils::InternalizeBuffer8FromStreamL( aStream ); |
|
556 delete iMimeType; |
|
557 iMimeType = tempContentType; |
|
558 |
|
559 HBufC8* tempContent = CAUtils::InternalizeBuffer8FromStreamL( aStream ); |
|
560 delete iContentData; |
|
561 iContentData = tempContent; |
|
562 } |
|
563 SetProcessState( EContentReady ); |
|
564 } |
|
565 |
|
566 // --------------------------------------------------------- |
|
567 // CCAMessageBase::ExternalizeL() |
|
568 // --------------------------------------------------------- |
|
569 // |
|
570 void CCAMessageBase::ExternalizeL( RWriteStream& aStream ) const |
|
571 { |
|
572 aStream.WriteUint16L( static_cast< TUint16 >( ContentType() ) ); |
|
573 aStream.WriteUint16L( static_cast< TUint16 >( KVersionNum ) ); |
|
574 aStream.WriteUint16L( static_cast< TUint16 >( iMessageType ) ); |
|
575 aStream.WriteUint16L( static_cast< TUint16 >( iMessagerType ) ); |
|
576 aStream.WriteUint16L( static_cast< TUint16 >( iSystemMessageType ) ); |
|
577 aStream.WriteUint8L( static_cast< TUint8 >( iFailed ) ); |
|
578 |
|
579 //this member was newly added. |
|
580 //write also this member to the file, because |
|
581 //the user could have saved the image. |
|
582 aStream.WriteUint8L( static_cast< TUint8 >( iSaved ) ); |
|
583 |
|
584 aStream.WriteUint32L( I64HIGH( iTime.Int64() ) ); |
|
585 aStream.WriteUint32L( I64LOW( iTime.Int64() ) ); |
|
586 |
|
587 CAUtils::ExternalizeBufferToStreamL( *iSender, aStream ); |
|
588 // if the type of current received message are EMessageWhisper and EMessageGroup, |
|
589 // store recipient's screen name when try to save conversation. |
|
590 if ( iMessagerType == EMessageReceived && ( iMessageType == EMessageWhisper || iMessageType == EMessageGroup ) ) |
|
591 { |
|
592 TInt count = iScreenNames->MdcaCount(); |
|
593 if ( count ) |
|
594 { |
|
595 // iScreenNames have only one element as current account's ScreenName. |
|
596 CAUtils::ExternalizeBufferToStreamL( iScreenNames->MdcaPoint( 0 ), aStream ); |
|
597 } |
|
598 else |
|
599 { |
|
600 CAUtils::ExternalizeBufferToStreamL( *iRecipient, aStream ); |
|
601 } |
|
602 } |
|
603 else |
|
604 { |
|
605 CAUtils::ExternalizeBufferToStreamL( *iRecipient, aStream ); |
|
606 } |
|
607 |
|
608 CAUtils::ExternalizeBufferToStreamL( *iText, aStream ); |
|
609 |
|
610 if ( ContentType() != EContentText && ContentType() != EContentInvalid ) |
|
611 { |
|
612 CAUtils::ExternalizeBufferToStreamL( *iMimeType, aStream ); |
|
613 CAUtils::ExternalizeBufferToStreamL( *iContentData, aStream ); |
|
614 } |
|
615 } |
|
616 |
|
617 // --------------------------------------------------------- |
|
618 // CCAMessageBase::MessageSizeInBytesL() |
|
619 // --------------------------------------------------------- |
|
620 // |
|
621 TInt CCAMessageBase::MessageSizeInBytesL() const |
|
622 { |
|
623 TInt memoryRequired( 0 ); |
|
624 |
|
625 if ( iMessageType != EMessageSystem ) |
|
626 { |
|
627 HBufC* separator = |
|
628 StringLoader::LoadLC( R_CHATCLIENT_HISTORY_MSG_SEPARATOR ); |
|
629 if ( iMessagerType == EMessageSent ) |
|
630 { |
|
631 memoryRequired += KFromMe().Size(); |
|
632 memoryRequired += CAUtils::DisplayId( *iRecipient ).Size(); |
|
633 } |
|
634 else |
|
635 { |
|
636 memoryRequired += CAUtils::DisplayId( *iSender ).Size(); |
|
637 if ( iMessageType == EMessagePTOP ) |
|
638 { |
|
639 memoryRequired += KWhiteSpace().Size(); |
|
640 memoryRequired += KToMe().Size(); |
|
641 } |
|
642 memoryRequired += separator->Size(); |
|
643 memoryRequired += KWhiteSpace().Size(); |
|
644 } |
|
645 CleanupStack::PopAndDestroy( separator ); |
|
646 } |
|
647 |
|
648 memoryRequired += iText->Size(); |
|
649 memoryRequired += KLineEnd().Size(); |
|
650 |
|
651 return memoryRequired; |
|
652 } |
|
653 |
|
654 // ----------------------------------------------------------------------------- |
|
655 // CCAMessageBase::ExternalizeForMTML |
|
656 // Externalize message to MTM send format. |
|
657 // ----------------------------------------------------------------------------- |
|
658 // |
|
659 void CCAMessageBase::ExternalizeForMTML( RWriteStream& aStream, |
|
660 TBool aShowTimeStamps ) const |
|
661 { |
|
662 if ( !aShowTimeStamps && |
|
663 iSystemMessageType == ESystemMessageDateChange ) |
|
664 { |
|
665 // Hide date change messages when we don't show timestamps |
|
666 return; |
|
667 } |
|
668 |
|
669 // TimeStamp |
|
670 if ( aShowTimeStamps && |
|
671 iSystemMessageType != ESystemMessageDateChange ) |
|
672 { |
|
673 HBufC* timeStamp = |
|
674 HBufC::NewLC( KTimeStampMaxLength ); |
|
675 TPtr timePtr( timeStamp->Des() ); |
|
676 |
|
677 HBufC* timeStampFormat = |
|
678 StringLoader::LoadLC( R_QTN_TIME_USUAL_WITH_ZERO ); |
|
679 |
|
680 // construct timestamp |
|
681 TRAPD( err, TimeStamp().FormatL( timePtr, *timeStampFormat ) ); |
|
682 if ( err == KErrNone ) |
|
683 { |
|
684 // Convert timestamp to correct number mode |
|
685 CAUtils::LanguageSpecificNumberConversion( timePtr ); |
|
686 aStream.WriteL( timePtr ); |
|
687 aStream.WriteL( KSpace ); |
|
688 } |
|
689 |
|
690 //timeStamp, timeStampFormat |
|
691 CleanupStack::PopAndDestroy( 2, timeStamp ); |
|
692 } |
|
693 |
|
694 if ( iMessageType != EMessageSystem ) |
|
695 { |
|
696 HBufC* separator = |
|
697 StringLoader::LoadLC( R_CHATCLIENT_HISTORY_MSG_SEPARATOR ); |
|
698 |
|
699 if ( iMessageType != EMessageGroup ) |
|
700 { |
|
701 if ( iMessagerType == EMessageSent ) |
|
702 { |
|
703 aStream.WriteL( KFromMe ); |
|
704 aStream.WriteL( CAUtils::DisplayId( *iRecipient ) ); |
|
705 } |
|
706 else |
|
707 { |
|
708 aStream.WriteL( CAUtils::DisplayId( *iSender ) ); |
|
709 aStream.WriteL( KWhiteSpace ); |
|
710 aStream.WriteL( KToMe ); |
|
711 } |
|
712 } |
|
713 else |
|
714 { |
|
715 if ( iMessagerType == EMessageSent ) |
|
716 { |
|
717 aStream.WriteL( CAUtils::DisplayId( *iSender ) ); |
|
718 } |
|
719 else |
|
720 { |
|
721 aStream.WriteL( CAUtils::DisplayId( *iSender ) ); |
|
722 } |
|
723 } |
|
724 aStream.WriteL( *separator ); |
|
725 aStream.WriteL( KWhiteSpace ); |
|
726 CleanupStack::PopAndDestroy( separator ); |
|
727 } |
|
728 |
|
729 if ( ContentType() != EContentText ) // For media files. |
|
730 { |
|
731 HBufC* mediaFile = StringLoader::LoadLC( R_QTN_CHAT_LOG_MEDIA_FILE ); |
|
732 aStream.WriteL( *mediaFile ); |
|
733 CleanupStack::PopAndDestroy( mediaFile ); |
|
734 } |
|
735 else if ( aShowTimeStamps && |
|
736 iSystemMessageType == ESystemMessageDateChange ) |
|
737 { |
|
738 // Date change system msg |
|
739 HBufC* dateChange = iText->AllocLC(); |
|
740 TPtr dateChangePtr( dateChange->Des() ); |
|
741 // Convert message to correct number mode |
|
742 CAUtils::LanguageSpecificNumberConversion( dateChangePtr ); |
|
743 // Write to stream |
|
744 aStream.WriteL( dateChangePtr ); |
|
745 CleanupStack::PopAndDestroy( dateChange ); |
|
746 } |
|
747 else |
|
748 { |
|
749 aStream.WriteL( *iText ); |
|
750 } |
|
751 |
|
752 TBuf<1> lineFeed; |
|
753 lineFeed.Format( KLineFeedFormat, CEditableText::ELineBreak ); |
|
754 aStream.WriteL( lineFeed ); |
|
755 } |
|
756 |
|
757 // ----------------------------------------------------------------------------- |
|
758 // CCAMessageBase::SetMessageType |
|
759 // ----------------------------------------------------------------------------- |
|
760 // |
|
761 void CCAMessageBase::SetMessageType( TMessageType aNewType ) |
|
762 { |
|
763 iMessageType = aNewType; |
|
764 } |
|
765 |
|
766 // ----------------------------------------------------------------------------- |
|
767 // CCAMessageBase::SetMessagerType |
|
768 // ----------------------------------------------------------------------------- |
|
769 // |
|
770 void CCAMessageBase::SetMessagerType( TMessagerType aNewType ) |
|
771 { |
|
772 iMessagerType = aNewType; |
|
773 } |
|
774 |
|
775 // ----------------------------------------------------------------------------- |
|
776 // CCAMessageBase::LaunchProcessing |
|
777 // ----------------------------------------------------------------------------- |
|
778 // |
|
779 void CCAMessageBase::LaunchProcessingL() |
|
780 { |
|
781 if ( iProcessors.Count() > 0 ) |
|
782 { |
|
783 CHAT_DP( D_CHAT_LIT( "Request processing." ) ); |
|
784 iProcessors[ 0 ].iProcessor->RequestProcessingL( *this ); |
|
785 } |
|
786 } |
|
787 |
|
788 // ----------------------------------------------------------------------------- |
|
789 // CCAMessageBase::ResolveMessageType |
|
790 // ----------------------------------------------------------------------------- |
|
791 // |
|
792 void CCAMessageBase::ResolveMessageType( const MDesCArray* aRecipients, |
|
793 const MDesCArray* aScreenNames ) |
|
794 { |
|
795 // aData.iRecipients > 0 -> ptop |
|
796 // aData.iScreenNames > 0 -> whisper |
|
797 // other cases -> group |
|
798 |
|
799 TInt countOfRecipients( aRecipients ? aRecipients->MdcaCount() : 0 ); |
|
800 TInt countOfScreenNames( aScreenNames ? aScreenNames->MdcaCount() : 0 ); |
|
801 |
|
802 if ( countOfRecipients ) // received ptop |
|
803 { |
|
804 iMessageType = EMessagePTOP; |
|
805 } |
|
806 else if ( countOfScreenNames ) // sent / received whisper |
|
807 { |
|
808 iMessageType = EMessageWhisper; |
|
809 } |
|
810 else if ( !aRecipients && !aScreenNames ) // sent ptop |
|
811 { |
|
812 iMessageType = EMessagePTOP; |
|
813 } |
|
814 else |
|
815 { |
|
816 iMessageType = EMessageGroup; |
|
817 } |
|
818 } |
|
819 |
|
820 // ----------------------------------------------------------------------------- |
|
821 // CCAMessageBase::SetSystem |
|
822 // ----------------------------------------------------------------------------- |
|
823 // |
|
824 void CCAMessageBase::SetSystem( TSystemMessage aType ) |
|
825 { |
|
826 iSystemMessageType = aType; |
|
827 iMessagerType = EMessageSent; |
|
828 iMessageType = EMessageSystem; |
|
829 } |
|
830 |
|
831 // ----------------------------------------------------------------------------- |
|
832 // CCAMessageBase::SystemMessageType |
|
833 // ----------------------------------------------------------------------------- |
|
834 // |
|
835 MCAMessage::TSystemMessage CCAMessageBase::SystemMessageType() |
|
836 { |
|
837 if ( iMessageType != EMessageSystem ) |
|
838 { |
|
839 // not a system message |
|
840 return ESystemMessageNone; |
|
841 } |
|
842 return iSystemMessageType; |
|
843 } |
|
844 |
|
845 // ----------------------------------------------------------------------------- |
|
846 // CCAMessageBase::SetVersionNumber |
|
847 // ----------------------------------------------------------------------------- |
|
848 // |
|
849 void CCAMessageBase::SetVersionNumber( TUint16 aVersion ) |
|
850 { |
|
851 iMessageVersion = aVersion; |
|
852 } |
|
853 |
|
854 |
|
855 |
|
856 //The following API's are used, if message content is a image |
|
857 //This is part of new implementation required for wvuing |
|
858 //While merging with wvui20, please make sure you preserve |
|
859 //this change also. |
|
860 |
|
861 // ----------------------------------------------------------------------------- |
|
862 // CCAMessageBase::SetImageAsSaved |
|
863 // ----------------------------------------------------------------------------- |
|
864 // |
|
865 void CCAMessageBase::SetImageAsSaved( const TBool aSaved ) |
|
866 { |
|
867 iSaved = aSaved; |
|
868 } |
|
869 |
|
870 // ----------------------------------------------------------------------------- |
|
871 // CCAMessageBase::IsImageSaved |
|
872 // ----------------------------------------------------------------------------- |
|
873 // |
|
874 TBool CCAMessageBase::IsImageSaved() |
|
875 { |
|
876 return iSaved; |
|
877 } |
|
878 |
|
879 |
|
880 // end of file |