|
1 /* |
|
2 * Copyright (c) 2006,2007 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: UniEditor header. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 |
|
22 #include <eikrted.h> |
|
23 #include <txtrich.h> // CRichText |
|
24 |
|
25 #include <centralrepository.h> // link against centralrepository.lib |
|
26 #include <messaginginternalcrkeys.h> // for Central Repository keys |
|
27 #include <MuiuMsvUiServiceUtilities.h> |
|
28 |
|
29 #include <mmsgenutils.h> |
|
30 |
|
31 #include <messagingvariant.hrh> |
|
32 |
|
33 #include <MsgExpandableControl.h> |
|
34 #include <MsgAddressControl.h> |
|
35 #include <MsgAttachmentControl.h> |
|
36 #include <MsgRecipientItem.h> |
|
37 |
|
38 #include <MsgMediaInfo.h> |
|
39 |
|
40 #include <unimsventry.h> |
|
41 #include <UniEditor.rsg> |
|
42 #include <unidatautils.h> |
|
43 #include <uniaddresshandler.h> |
|
44 |
|
45 #include "UniEditorEnum.h" // Panic |
|
46 #include "UniEditorDocument.h" |
|
47 #include "UniEditorHeader.h" |
|
48 |
|
49 |
|
50 // ========================================================== |
|
51 |
|
52 // EXTERNAL DATA STRUCTURES |
|
53 |
|
54 // EXTERNAL FUNCTION PROTOTYPES |
|
55 |
|
56 // CONSTANTS |
|
57 const TInt KUniCharAt = '@'; |
|
58 const TInt KUniMaxSubject = 40; |
|
59 |
|
60 // MACROS |
|
61 |
|
62 // LOCAL CONSTANTS AND MACROS |
|
63 |
|
64 // MODULE DATA STRUCTURES |
|
65 |
|
66 // LOCAL FUNCTION PROTOTYPES |
|
67 |
|
68 // ================= MEMBER FUNCTIONS ======================= |
|
69 |
|
70 // --------------------------------------------------------- |
|
71 // CUniEditorHeader::NewL |
|
72 // |
|
73 // Two-phased constructor. |
|
74 // --------------------------------------------------------- |
|
75 // |
|
76 CUniEditorHeader* CUniEditorHeader::NewL( CUniClientMtm& aMtm, |
|
77 CUniEditorDocument& aDoc, |
|
78 CMsgEditorView& aView, |
|
79 RFs& aFs ) |
|
80 { |
|
81 CUniEditorHeader* self = new ( ELeave ) CUniEditorHeader( aMtm, aDoc, aView, aFs ); |
|
82 |
|
83 CleanupStack::PushL( self ); |
|
84 self->ConstructL(); |
|
85 CleanupStack::Pop( self ); |
|
86 |
|
87 return self; |
|
88 } |
|
89 |
|
90 // --------------------------------------------------------- |
|
91 // CUniEditorHeader::CUniEditorHeader |
|
92 // |
|
93 // Constructor. |
|
94 // --------------------------------------------------------- |
|
95 // |
|
96 CUniEditorHeader::CUniEditorHeader( CUniClientMtm& aMtm, |
|
97 CUniEditorDocument& aDoc, |
|
98 CMsgEditorView& aView, |
|
99 RFs& aFs ): |
|
100 CUniBaseHeader( aMtm, aView, aFs ), |
|
101 iDoc( aDoc), |
|
102 iLongestEmail( 0 ) |
|
103 { |
|
104 } |
|
105 |
|
106 // --------------------------------------------------------- |
|
107 // CUniEditorHeader::ConstructL |
|
108 // --------------------------------------------------------- |
|
109 // |
|
110 void CUniEditorHeader::ConstructL() |
|
111 { |
|
112 AddHeadersVariationL( TUniMsvEntry::IsMmsUpload( iMtm.Entry().Entry() ) ); |
|
113 AddHeadersConfigL(); |
|
114 |
|
115 iAddDelayed = EUniFeatureTo; |
|
116 |
|
117 iDoc.DataModel()->AttachmentList().SetListObserver( this ); |
|
118 |
|
119 const TPtrC subject = iMtm.SubjectL(); |
|
120 |
|
121 TBool lockedSMS = EFalse; |
|
122 if ( iDoc.Mtm().MessageTypeSetting() == EUniMessageTypeSettingSms ) |
|
123 { |
|
124 lockedSMS = ETrue; |
|
125 } |
|
126 |
|
127 if ( iAddHeadersVariation & EUniFeatureSubject ) |
|
128 { |
|
129 // Subject is supported |
|
130 if ( !( iAddHeadersVariation & EUniFeatureSubjectConfigurable ) ) |
|
131 { |
|
132 // and it's not configurable -> it's always on |
|
133 iAddDelayed |= EUniFeatureSubject; |
|
134 } |
|
135 else if ( iAddHeadersConfig & EUniFeatureSubject && |
|
136 !lockedSMS ) |
|
137 { |
|
138 // or it's currently configured on and we are not on locked SMS mode. |
|
139 iAddDelayed |= EUniFeatureSubject; |
|
140 } |
|
141 else if ( subject.Length() ) |
|
142 { |
|
143 // or there's something in the subject |
|
144 iAddDelayed |= EUniFeatureSubject; |
|
145 } |
|
146 } |
|
147 |
|
148 // check adding into other field than 'home' field |
|
149 TInt addIntoOther( 0 ); |
|
150 TInt addressesInStore = MtmAddressTypes(); |
|
151 |
|
152 // configured or variated on but contains data |
|
153 if ( !lockedSMS && |
|
154 ( iAddHeadersConfig & EUniFeatureCc || |
|
155 ( iAddHeadersVariation & EUniFeatureCc && |
|
156 addressesInStore & EUniFeatureCc ) ) ) |
|
157 { |
|
158 iAddDelayed |= EUniFeatureCc; |
|
159 } |
|
160 else if ( !( iAddHeadersVariation & EUniFeatureCc ) && |
|
161 addressesInStore & EUniFeatureCc ) |
|
162 { |
|
163 // show in the other field if variated off |
|
164 addIntoOther |= EUniFeatureCc; |
|
165 } |
|
166 |
|
167 // configured or variated on but contains data |
|
168 if ( !lockedSMS && |
|
169 ( iAddHeadersConfig & EUniFeatureBcc || |
|
170 ( iAddHeadersVariation & EUniFeatureBcc && |
|
171 addressesInStore & EUniFeatureBcc ) ) ) |
|
172 { |
|
173 iAddDelayed |= EUniFeatureBcc; |
|
174 } |
|
175 else if ( !( iAddHeadersVariation & EUniFeatureBcc ) && |
|
176 addressesInStore & EUniFeatureBcc ) |
|
177 { |
|
178 // show in the other field if variated off |
|
179 addIntoOther |= EUniFeatureBcc; |
|
180 } |
|
181 |
|
182 if ( iDoc.DataModel()->AttachmentList().Count() > 0 ) |
|
183 { |
|
184 iAddDelayed |= EUniFeatureAttachment; |
|
185 } |
|
186 |
|
187 DoAddToViewL( ETrue ); |
|
188 |
|
189 // Add data to those which are not configured but are variated off and contains data |
|
190 // CMsgEditorAppUi must set Document always modified! |
|
191 // Its is done in CUniEditorLaunchOperation::DoHandleMessageL() |
|
192 // Variation has changed On->Off and message opened from Drafts |
|
193 if ( addIntoOther & EUniFeatureCc ) |
|
194 { |
|
195 iHeaders[EHeaderAddressTo].iAddressHandler->CopyAddressesFromMtmL( EMsvRecipientCc, ETrue ); |
|
196 } |
|
197 if ( addIntoOther & EUniFeatureBcc && |
|
198 iHeaders[EHeaderAddressCc].iAddressHandler ) |
|
199 { |
|
200 iHeaders[EHeaderAddressCc].iAddressHandler->CopyAddressesFromMtmL( EMsvRecipientBcc, ETrue ); |
|
201 } |
|
202 else if ( addIntoOther & EUniFeatureBcc ) |
|
203 { |
|
204 iHeaders[EHeaderAddressTo].iAddressHandler->CopyAddressesFromMtmL( EMsvRecipientBcc, ETrue ); |
|
205 } |
|
206 |
|
207 if ( iDoc.MessageType() == EUniReply ) |
|
208 { |
|
209 RemoveDuplicateAddressesL(); |
|
210 } |
|
211 } |
|
212 |
|
213 // --------------------------------------------------------- |
|
214 // CUniEditorHeader::~CUniEditorHeader |
|
215 // --------------------------------------------------------- |
|
216 // |
|
217 CUniEditorHeader::~CUniEditorHeader() |
|
218 { |
|
219 } |
|
220 |
|
221 // --------------------------------------------------------- |
|
222 // CUniEditorHeader::AddHeadersAddL |
|
223 // --------------------------------------------------------- |
|
224 // |
|
225 void CUniEditorHeader::AddHeadersAddL(TInt aFlags) |
|
226 { |
|
227 if ( !aFlags ) |
|
228 { |
|
229 // nothing to add |
|
230 return; |
|
231 } |
|
232 |
|
233 // don't use anything, which is variated off |
|
234 aFlags &= iAddHeadersVariation; |
|
235 |
|
236 // do not add anything existing |
|
237 if ( iHeaders[EHeaderAddressCc].iControl ) |
|
238 { |
|
239 aFlags &= ( ~EUniFeatureCc ); |
|
240 } |
|
241 if ( iHeaders[EHeaderAddressBcc].iControl ) |
|
242 { |
|
243 aFlags &= ( ~EUniFeatureBcc ); |
|
244 } |
|
245 if ( iHeaders[EHeaderSubject].iControl ) |
|
246 { |
|
247 aFlags &= ( ~EUniFeatureSubject ); |
|
248 } |
|
249 if ( iHeaders[EHeaderAttachment].iControl ) |
|
250 { |
|
251 aFlags &= ( ~EUniFeatureAttachment ); |
|
252 } |
|
253 |
|
254 iAddDelayed = aFlags; |
|
255 |
|
256 // Test whether on the first slide. |
|
257 // Check whether we can add immediately. |
|
258 // Adding can be done only when on first slide. |
|
259 if ( iHeaders[EHeaderAddressTo].iOwned ) |
|
260 { |
|
261 return; |
|
262 } |
|
263 |
|
264 DoAddToViewL(EFalse); // do no read data |
|
265 } |
|
266 |
|
267 // --------------------------------------------------------- |
|
268 // CUniEditorHeader::AddHeadersDeleteL |
|
269 // --------------------------------------------------------- |
|
270 // |
|
271 void CUniEditorHeader::AddHeadersDeleteL( TInt aFlags, |
|
272 TBool aContentModified) |
|
273 { |
|
274 if ( !aFlags ) |
|
275 { |
|
276 return; |
|
277 } |
|
278 |
|
279 // Test whether on the first slide. |
|
280 if ( !iHeaders[EHeaderAddressTo].iOwned ) |
|
281 { |
|
282 RemoveFromViewL( aFlags ); |
|
283 } |
|
284 |
|
285 for (TInt i = EHeaderAddressCc; i <= EHeaderAttachment; i++ ) |
|
286 { |
|
287 TInt flag = EUniFeatureCc; |
|
288 if ( i == EHeaderAddressBcc ) |
|
289 { |
|
290 flag = EUniFeatureBcc; |
|
291 } |
|
292 else if ( i == EHeaderSubject ) |
|
293 { |
|
294 flag = EUniFeatureSubject; |
|
295 } |
|
296 else if ( i == EHeaderAttachment ) |
|
297 { |
|
298 flag = EUniFeatureAttachment; |
|
299 } |
|
300 |
|
301 if ( iHeaders[i].iOwned && |
|
302 aFlags & flag ) |
|
303 { |
|
304 delete iHeaders[i].iControl; |
|
305 iHeaders[i].iControl = NULL; |
|
306 |
|
307 delete iHeaders[i].iAddressHandler; |
|
308 iHeaders[i].iAddressHandler = NULL; |
|
309 } |
|
310 } |
|
311 if ( aContentModified ) |
|
312 { |
|
313 iView.SetControlsModified ( ETrue ); |
|
314 } |
|
315 } |
|
316 |
|
317 // --------------------------------------------------------- |
|
318 // CUniEditorHeader::InsertRecipientL |
|
319 // --------------------------------------------------------- |
|
320 // |
|
321 void CUniEditorHeader::InsertRecipientL(TAddressData& aData, |
|
322 THeaderFields aRecipientType, |
|
323 TBool aReadContent) |
|
324 { |
|
325 // cannot add existing control |
|
326 __ASSERT_DEBUG( !aData.iControl, Panic( EUniIllegalArgument ) ); |
|
327 |
|
328 TInt res( R_UNIEDITOR_TO ); |
|
329 |
|
330 if ( aRecipientType == EHeaderAddressCc ) |
|
331 { |
|
332 res = R_UNIEDITOR_CC; |
|
333 } |
|
334 else if ( aRecipientType == EHeaderAddressBcc ) |
|
335 { |
|
336 res = R_UNIEDITOR_BCC; |
|
337 } |
|
338 else if ( aRecipientType != EHeaderAddressTo ) |
|
339 { |
|
340 return; |
|
341 } |
|
342 |
|
343 iView.AddControlFromResourceL( res, |
|
344 EMsgAddressControl, |
|
345 ControlIndexForAdding( aRecipientType ), |
|
346 EMsgHeader ); |
|
347 |
|
348 aData.iControl = static_cast<CMsgAddressControl*> |
|
349 ( iView.ControlById( aData.iControlType ) ); |
|
350 aData.iOwned = EFalse; |
|
351 |
|
352 TBool addInvalidRecipient = EFalse; |
|
353 |
|
354 if( TUniMsvEntry::IsMmsUpload( iMtm.Entry().Entry() ) ) |
|
355 { |
|
356 aData.iControl->SetReadOnly( ETrue ); |
|
357 addInvalidRecipient = ETrue; |
|
358 } |
|
359 |
|
360 if( TUniMsvEntry::IsEditorOriented( iMtm.Entry().Entry() ) ) |
|
361 { |
|
362 addInvalidRecipient = ETrue; |
|
363 } |
|
364 |
|
365 aData.iAddressHandler = CUniAddressHandler::NewL( |
|
366 iMtm, |
|
367 *static_cast<CMsgAddressControl*>(aData.iControl), |
|
368 *( iView.ControlEnv() ) ); |
|
369 |
|
370 if ( aReadContent ) |
|
371 { |
|
372 aData.iAddressHandler->CopyAddressesFromMtmL(aData.iRecipientTypeValue, addInvalidRecipient ); |
|
373 } |
|
374 } |
|
375 |
|
376 // --------------------------------------------------------- |
|
377 // CUniEditorHeader::InsertSubjectL |
|
378 // --------------------------------------------------------- |
|
379 // |
|
380 void CUniEditorHeader::InsertSubjectL( TBool aReadContent ) |
|
381 { |
|
382 iView.AddControlFromResourceL( R_UNIEDITOR_SUBJECT, |
|
383 EMsgExpandableControl, |
|
384 ControlIndexForAdding( EHeaderSubject ), |
|
385 EMsgHeader ); |
|
386 iHeaders[EHeaderSubject].iControl = static_cast<CMsgExpandableControl*> |
|
387 ( iView.ControlById( EMsgComponentIdSubject ) ); |
|
388 iHeaders[EHeaderSubject].iOwned = EFalse; |
|
389 |
|
390 if ( aReadContent ) |
|
391 { |
|
392 const TPtrC subject = iMtm.SubjectL(); |
|
393 if ( subject.Length() ) |
|
394 { |
|
395 iHeaders[EHeaderSubject].iControl->Editor().SetTextL( &subject ); |
|
396 } |
|
397 } |
|
398 } |
|
399 |
|
400 // --------------------------------------------------------- |
|
401 // CUniEditorHeader::InsertAttachmentL |
|
402 // --------------------------------------------------------- |
|
403 // |
|
404 void CUniEditorHeader::InsertAttachmentL( TBool aReadContent ) |
|
405 { |
|
406 CMsgAttachmentControl* attachmentControl = CMsgAttachmentControl::NewL( iView, iView ); |
|
407 |
|
408 if ( iDoc.CurrentSlide() == 0 ) |
|
409 { |
|
410 CleanupStack::PushL( attachmentControl ); |
|
411 iView.AddControlL( attachmentControl, |
|
412 EMsgComponentIdAttachment, |
|
413 ControlIndexForAdding( EHeaderAttachment ), |
|
414 EMsgHeader ); |
|
415 CleanupStack::Pop( attachmentControl ); |
|
416 |
|
417 iHeaders[EHeaderAttachment].iControl = |
|
418 static_cast<CMsgAttachmentControl*>( iView.ControlById( EMsgComponentIdAttachment ) ); |
|
419 |
|
420 iHeaders[EHeaderAttachment].iOwned = EFalse; |
|
421 } |
|
422 else |
|
423 { |
|
424 iHeaders[EHeaderAttachment].iControl = attachmentControl; |
|
425 iHeaders[EHeaderAttachment].iOwned = ETrue; |
|
426 } |
|
427 |
|
428 if ( aReadContent ) |
|
429 { |
|
430 CUniObjectList& attaList = iDoc.DataModel()->AttachmentList(); |
|
431 |
|
432 for( TInt index = 0; index < attaList.Count(); index++ ) |
|
433 { |
|
434 TParsePtrC fileParser( attaList.GetByIndex( index )->MediaInfo()->FullFilePath() ); |
|
435 |
|
436 attachmentControl->AppendAttachmentL( fileParser.NameAndExt() ); |
|
437 } |
|
438 |
|
439 } |
|
440 } |
|
441 |
|
442 // --------------------------------------------------------- |
|
443 // CUniEditorHeader::RemoveAttachmentL |
|
444 // --------------------------------------------------------- |
|
445 // |
|
446 void CUniEditorHeader::RemoveAttachmentL() |
|
447 { |
|
448 if ( iDoc.CurrentSlide() == 0 ) |
|
449 { |
|
450 iView.DeleteControlL( EMsgComponentIdAttachment ); |
|
451 } |
|
452 else |
|
453 { |
|
454 delete iHeaders[EHeaderAttachment].iControl; |
|
455 } |
|
456 |
|
457 iHeaders[EHeaderAttachment].iControl = NULL; |
|
458 iHeaders[EHeaderAttachment].iOwned = EFalse; |
|
459 } |
|
460 |
|
461 // --------------------------------------------------------- |
|
462 // CUniEditorHeader::CopyAddressesToMtmL |
|
463 // --------------------------------------------------------- |
|
464 // |
|
465 TBool CUniEditorHeader::CopyAddressesToMtmL( TBool aDocumentHeaderModified) |
|
466 { |
|
467 TBool modified = EFalse; |
|
468 if ( aDocumentHeaderModified ) |
|
469 { |
|
470 modified = ETrue; |
|
471 } |
|
472 if ( modified ) |
|
473 { |
|
474 // variation has changed On->Off and message opened from Drafts |
|
475 iHeaders[EHeaderAddressTo].iAddressHandler-> |
|
476 RemoveAddressesFromMtmL( iHeaders[EHeaderAddressTo].iRecipientTypeValue ); |
|
477 iHeaders[EHeaderAddressTo].iAddressHandler-> |
|
478 RemoveAddressesFromMtmL( iHeaders[EHeaderAddressCc].iRecipientTypeValue ); |
|
479 iHeaders[EHeaderAddressTo].iAddressHandler-> |
|
480 RemoveAddressesFromMtmL( iHeaders[EHeaderAddressBcc].iRecipientTypeValue ); |
|
481 } |
|
482 for (TInt i = EHeaderAddressTo; i <= EHeaderAddressBcc ; i++ ) |
|
483 { |
|
484 // all or nothing |
|
485 if ( iHeaders[i].iControl |
|
486 && modified ) |
|
487 { |
|
488 if ( iHeaders[i].iAddressHandler ) |
|
489 { |
|
490 iHeaders[i].iAddressHandler->CopyAddressesToMtmL( |
|
491 iHeaders[i].iRecipientTypeValue); |
|
492 } |
|
493 modified = ETrue; |
|
494 } |
|
495 } |
|
496 return modified; |
|
497 } |
|
498 |
|
499 // --------------------------------------------------------- |
|
500 // CUniEditorHeader::CopyHeadersToMtmL |
|
501 // --------------------------------------------------------- |
|
502 // |
|
503 TBool CUniEditorHeader::CopyHeadersToMtmL( TBool aDocumentHeaderModified, |
|
504 TBool aSaveToMtm ) |
|
505 { |
|
506 TBool modified = EFalse; |
|
507 if ( aDocumentHeaderModified ) |
|
508 { |
|
509 modified = ETrue; |
|
510 } |
|
511 CMsgExpandableControl* subj = iHeaders[EHeaderSubject].iControl; |
|
512 |
|
513 if ( subj && modified ) |
|
514 { |
|
515 TInt length = subj->TextContent().DocumentLength(); |
|
516 |
|
517 if( length ) |
|
518 { |
|
519 TBuf<KUniMaxSubject> description; |
|
520 description.Zero(); |
|
521 |
|
522 // Copying as pure text from the editor which may contain emoticons. |
|
523 |
|
524 HBufC *text = subj->Editor().GetTextInHBufL(); |
|
525 CleanupStack::PushL( text ); |
|
526 description.Copy( text->Ptr(), length ); |
|
527 CleanupStack::PopAndDestroy( text ); |
|
528 iMtm.SetSubjectL( description ); |
|
529 modified = ETrue; |
|
530 } |
|
531 } |
|
532 // variation has changed On->Off and message opened from Drafts |
|
533 else if ( modified ) |
|
534 { |
|
535 iMtm.SetSubjectL( KNullDesC() ); |
|
536 } |
|
537 |
|
538 modified = CopyAddressesToMtmL (modified); |
|
539 if ( modified |
|
540 && aSaveToMtm ) |
|
541 { |
|
542 iMtm.SaveMessageL(); |
|
543 } |
|
544 |
|
545 return modified; |
|
546 } |
|
547 |
|
548 // --------------------------------------------------------- |
|
549 // CUniEditorHeader::VerifyAddressesL |
|
550 // --------------------------------------------------------- |
|
551 // |
|
552 TBool CUniEditorHeader::VerifyAddressesL( TBool& aModified, TBool aAcceptEmails ) |
|
553 { |
|
554 aModified = EFalse; |
|
555 TBool modified = EFalse; |
|
556 TBool ret = ETrue; |
|
557 for (TInt i = EHeaderAddressTo; i <= EHeaderAddressBcc ; i++ ) |
|
558 { |
|
559 // all or nothing |
|
560 if ( iHeaders[i].iAddressHandler ) |
|
561 { |
|
562 CMsgCheckNames::TMsgAddressSelectType |
|
563 msgType = aAcceptEmails?CMsgCheckNames::EMsgTypeMms:CMsgCheckNames::EMsgTypeSms; |
|
564 iHeaders[i].iAddressHandler->SetValidAddressType( msgType ); |
|
565 TBool retTemp = iHeaders[i].iAddressHandler->VerifyAddressesL( modified ); |
|
566 if ( modified ) |
|
567 { |
|
568 aModified = ETrue; |
|
569 } |
|
570 if ( !retTemp ) |
|
571 { |
|
572 // unvalidated addresses |
|
573 ret = EFalse; |
|
574 break; |
|
575 } |
|
576 } |
|
577 } |
|
578 return ret; |
|
579 } |
|
580 |
|
581 // --------------------------------------------------------- |
|
582 // CUniEditorHeader::NeedsVerificationL |
|
583 // --------------------------------------------------------- |
|
584 // |
|
585 TBool CUniEditorHeader::NeedsVerificationL() |
|
586 { |
|
587 CMsgRecipientArray* recipients = NULL; |
|
588 for (TInt currentHeader = EHeaderAddressTo; currentHeader <= EHeaderAddressBcc ; currentHeader++ ) |
|
589 { |
|
590 // all or nothing |
|
591 if ( iHeaders[currentHeader].iAddressHandler ) |
|
592 { |
|
593 recipients = |
|
594 static_cast<CMsgAddressControl*>( iHeaders[currentHeader].iControl )->GetRecipientsL(); |
|
595 |
|
596 for( TInt currentRecipient = 0; currentRecipient < recipients->Count(); currentRecipient++ ) |
|
597 { |
|
598 if( !(recipients->At( currentRecipient )->IsVerified() ) ) |
|
599 { |
|
600 return ETrue; |
|
601 } |
|
602 } |
|
603 } |
|
604 } |
|
605 return EFalse; |
|
606 } |
|
607 |
|
608 // --------------------------------------------------------- |
|
609 // CUniEditorHeader::AddRecipientL |
|
610 // --------------------------------------------------------- |
|
611 // |
|
612 TBool CUniEditorHeader::AddRecipientL( CMsgBaseControl* aFocusedControl, |
|
613 MObjectProvider* /*aParent*/, |
|
614 TBool aIncludeEmailAddresses, |
|
615 TBool& aInvalid ) |
|
616 { |
|
617 TBool added = EFalse; |
|
618 |
|
619 // note order of for () |
|
620 for ( TInt i = EHeaderAddressBcc; i >= EHeaderAddressTo ; i-- ) |
|
621 { |
|
622 CMsgCheckNames::TMsgAddressSelectType msgType = aIncludeEmailAddresses ? CMsgCheckNames::EMsgTypeMms: |
|
623 CMsgCheckNames::EMsgTypeSms; |
|
624 if ( iHeaders[i].iControl == aFocusedControl && |
|
625 iHeaders[i].iAddressHandler ) |
|
626 { |
|
627 iHeaders[i].iAddressHandler->SetValidAddressType( msgType ); |
|
628 added = iHeaders[i].iAddressHandler->AddRecipientL( aInvalid ); |
|
629 break; |
|
630 } |
|
631 |
|
632 // if focus on any other control, add to To: recipient list |
|
633 if ( i == EHeaderAddressTo && |
|
634 iHeaders[EHeaderAddressTo].iAddressHandler ) |
|
635 { |
|
636 iHeaders[i].iAddressHandler->SetValidAddressType( msgType ); |
|
637 added = iHeaders[i].iAddressHandler->AddRecipientL( aInvalid ); |
|
638 } |
|
639 } |
|
640 |
|
641 return added; |
|
642 } |
|
643 |
|
644 // --------------------------------------------------------- |
|
645 // CUniEditorHeader::RemoveDuplicateAddressesL |
|
646 // --------------------------------------------------------- |
|
647 // |
|
648 TBool CUniEditorHeader::RemoveDuplicateAddressesL() |
|
649 { |
|
650 TBool retVal = EFalse; |
|
651 CArrayPtrFlat<CMsgAddressControl>* addressControls = new ( ELeave ) CArrayPtrFlat<CMsgAddressControl>( 3 ); |
|
652 CleanupStack::PushL( addressControls ); |
|
653 |
|
654 if ( AddressControl( CUniBaseHeader::EHeaderAddressTo ) ) |
|
655 { |
|
656 addressControls->AppendL( AddressControl( CUniBaseHeader::EHeaderAddressTo ) ); |
|
657 } |
|
658 if ( AddressControl( CUniBaseHeader::EHeaderAddressCc ) ) |
|
659 { |
|
660 addressControls->AppendL( AddressControl( CUniBaseHeader::EHeaderAddressCc ) ); |
|
661 } |
|
662 if ( AddressControl( CUniBaseHeader::EHeaderAddressBcc ) ) |
|
663 { |
|
664 addressControls->AppendL( AddressControl( CUniBaseHeader::EHeaderAddressBcc ) ); |
|
665 } |
|
666 |
|
667 retVal = CUniAddressHandler::RemoveDuplicateAddressesL( *addressControls ); |
|
668 CleanupStack::PopAndDestroy( addressControls ); |
|
669 return retVal; |
|
670 } |
|
671 |
|
672 // --------------------------------------------------------- |
|
673 // CUniEditorHeader::IsHeaderSmsL |
|
674 // --------------------------------------------------------- |
|
675 // |
|
676 TBool CUniEditorHeader::IsHeaderSmsL() |
|
677 { |
|
678 // Is one of the following visible and do they have content |
|
679 CMsgRecipientArray* recipients = NULL; |
|
680 |
|
681 if ( iHeaders[EHeaderAddressCc].iControl ) |
|
682 { |
|
683 // CC is visible |
|
684 recipients = static_cast<CMsgAddressControl*>( iHeaders[EHeaderAddressCc].iControl )->GetRecipientsL(); |
|
685 |
|
686 if ( recipients && |
|
687 recipients->Count() > 0 ) |
|
688 { |
|
689 // There are recipients -> this is not sms |
|
690 iLongestEmail = 0; |
|
691 return EFalse; |
|
692 } |
|
693 } |
|
694 |
|
695 if ( iHeaders[EHeaderAddressBcc].iControl ) |
|
696 { |
|
697 // BCC is visible |
|
698 recipients = static_cast<CMsgAddressControl*>( iHeaders[EHeaderAddressBcc].iControl )->GetRecipientsL(); |
|
699 |
|
700 if ( recipients && |
|
701 recipients->Count() > 0 ) |
|
702 { // there are recipients -> this is not sms |
|
703 iLongestEmail = 0; |
|
704 return EFalse; |
|
705 } |
|
706 } |
|
707 |
|
708 // Are there too many recipients in To field? |
|
709 if ( iHeaders[CUniEditorHeader::EHeaderAddressTo].iControl ) |
|
710 { |
|
711 recipients = static_cast<CMsgAddressControl*>( iHeaders[EHeaderAddressTo].iControl )->GetRecipientsL(); |
|
712 |
|
713 if ( recipients && |
|
714 recipients->Count() > iDoc.MaxSmsRecipients() ) |
|
715 { |
|
716 iLongestEmail = 0; |
|
717 return EFalse; |
|
718 } |
|
719 |
|
720 // Refresh the longest email address length |
|
721 RefreshLongestEmailAddressL(); |
|
722 |
|
723 if ( !iDoc.EmailOverSmsSupported() ) |
|
724 { |
|
725 for ( TInt i = 0; i < recipients->Count(); i++ ) |
|
726 { |
|
727 if ( IsValidEmailAddress( recipients->At( i )->Address()->Des() ) ) |
|
728 { |
|
729 return EFalse; |
|
730 } |
|
731 } |
|
732 } |
|
733 } |
|
734 return ETrue; |
|
735 } |
|
736 |
|
737 // --------------------------------------------------------- |
|
738 // CUniEditorHeader::ObjectAddedL |
|
739 // --------------------------------------------------------- |
|
740 // |
|
741 void CUniEditorHeader::ObjectAddedL( CUniObjectList* aList, |
|
742 CUniObject* aObject, |
|
743 TInt aIndex ) |
|
744 { |
|
745 if ( aObject && |
|
746 aList == &iDoc.DataModel()->AttachmentList() ) |
|
747 { |
|
748 if ( !iHeaders[CUniEditorHeader::EHeaderAttachment].iControl ) |
|
749 { |
|
750 InsertAttachmentL( EFalse ); |
|
751 } |
|
752 |
|
753 CMsgAttachmentControl* attachmentControl = |
|
754 static_cast<CMsgAttachmentControl*>( |
|
755 iHeaders[CUniEditorHeader::EHeaderAttachment].iControl ); |
|
756 |
|
757 TParsePtrC fileParser( aObject->MediaInfo()->FullFilePath() ); |
|
758 |
|
759 attachmentControl->InsertAttachmentL( fileParser.NameAndExt(), aIndex ); |
|
760 } |
|
761 } |
|
762 |
|
763 // --------------------------------------------------------- |
|
764 // CUniEditorHeader::ObjectRemovedL |
|
765 // --------------------------------------------------------- |
|
766 // |
|
767 void CUniEditorHeader::ObjectRemovedL( CUniObjectList* aList, |
|
768 CUniObject* aObject, |
|
769 TInt aIndex ) |
|
770 { |
|
771 if ( aObject && |
|
772 aList == &iDoc.DataModel()->AttachmentList() ) |
|
773 { |
|
774 CMsgAttachmentControl* attachmentControl = |
|
775 static_cast<CMsgAttachmentControl*>( |
|
776 iHeaders[CUniEditorHeader::EHeaderAttachment].iControl ); |
|
777 |
|
778 if ( attachmentControl ) |
|
779 { |
|
780 TParsePtrC fileParser( aObject->MediaInfo()->FullFilePath() ); |
|
781 TPtrC plainFileName = fileParser.NameAndExt(); |
|
782 |
|
783 HBufC* attachmentName = attachmentControl->Attachment( aIndex ).AllocLC(); |
|
784 |
|
785 if ( plainFileName.Match( *attachmentName ) ) |
|
786 { |
|
787 attachmentControl->RemoveAttachmentL( aIndex ); |
|
788 } |
|
789 else |
|
790 { |
|
791 attachmentControl->RemoveAttachmentL( plainFileName ); |
|
792 } |
|
793 |
|
794 CleanupStack::PopAndDestroy( attachmentName ); |
|
795 } |
|
796 |
|
797 if ( aList->Count() == 0 ) |
|
798 { |
|
799 RemoveAttachmentL(); |
|
800 } |
|
801 } |
|
802 } |
|
803 |
|
804 // --------------------------------------------------------- |
|
805 // CUniEditorHeader::RefreshLongestEmailAddressL |
|
806 // --------------------------------------------------------- |
|
807 // |
|
808 void CUniEditorHeader::RefreshLongestEmailAddressL() |
|
809 { |
|
810 TInt longestOne = 0; |
|
811 if ( iDoc.EmailOverSmsSupported() && iHeaders[CUniEditorHeader::EHeaderAddressTo].iControl ) |
|
812 { |
|
813 CMsgRecipientArray* recipients = NULL; |
|
814 recipients = static_cast<CMsgAddressControl*> |
|
815 ( iHeaders[CUniEditorHeader::EHeaderAddressTo].iControl )->GetRecipientsL(); |
|
816 for( TInt i = 0; i < recipients->Count(); i++ ) |
|
817 { |
|
818 if( IsValidEmailAddress( recipients->At( i )->Address()->Des() ) ) |
|
819 { |
|
820 if( recipients->At( i )->Address()->Length() > longestOne ) |
|
821 { |
|
822 longestOne = recipients->At( i )->Address()->Length(); |
|
823 } |
|
824 } |
|
825 } |
|
826 } |
|
827 iLongestEmail = longestOne; |
|
828 } |
|
829 |
|
830 // --------------------------------------------------------- |
|
831 // CUniEditorHeader::ControlIndexForAdding |
|
832 // --------------------------------------------------------- |
|
833 // |
|
834 TInt CUniEditorHeader::ControlIndexForAdding( TInt aControlToAdd ) |
|
835 { |
|
836 TInt index = 0; |
|
837 switch( aControlToAdd ) |
|
838 { |
|
839 case EHeaderAttachment: |
|
840 { |
|
841 if ( iHeaders[EHeaderSubject].iControl && |
|
842 iHeaders[EHeaderSubject].iControl->IsVisible() ) |
|
843 { |
|
844 index++; |
|
845 } |
|
846 } // Ok to flow thru |
|
847 case EHeaderSubject: |
|
848 { |
|
849 if ( iHeaders[EHeaderAddressBcc].iControl && |
|
850 iHeaders[EHeaderAddressBcc].iControl->IsVisible() ) |
|
851 { |
|
852 index++; |
|
853 } |
|
854 } // Ok to flow thru |
|
855 case EHeaderAddressBcc: |
|
856 { |
|
857 if ( iHeaders[EHeaderAddressCc].iControl && |
|
858 iHeaders[EHeaderAddressCc].iControl->IsVisible() ) |
|
859 { |
|
860 index++; |
|
861 } |
|
862 } // Ok to flow thru |
|
863 case EHeaderAddressCc: |
|
864 { |
|
865 if ( iHeaders[EHeaderAddressTo].iControl && |
|
866 iHeaders[EHeaderAddressTo].iControl->IsVisible() ) |
|
867 { |
|
868 index++; |
|
869 } |
|
870 |
|
871 break; |
|
872 } |
|
873 default: |
|
874 { |
|
875 break; |
|
876 } |
|
877 } |
|
878 |
|
879 return index; |
|
880 } |
|
881 |
|
882 // --------------------------------------------------------- |
|
883 // CUniEditorHeader::ShowInvalidContactNotesL |
|
884 // --------------------------------------------------------- |
|
885 // |
|
886 void CUniEditorHeader::ShowInvalidContactNotesL() |
|
887 { |
|
888 for (TInt i = EHeaderAddressTo; i <= EHeaderAddressBcc ; i++ ) |
|
889 { |
|
890 // all or nothing |
|
891 if ( iHeaders[i].iAddressHandler ) |
|
892 { |
|
893 iHeaders[i].iAddressHandler->ShowInvalidRecipientInfoNotesL(); |
|
894 } |
|
895 } |
|
896 } |
|
897 |
|
898 // --------------------------------------------------------- |
|
899 // CUniEditorHeader::IsValidEmailAddress |
|
900 // --------------------------------------------------------- |
|
901 // |
|
902 TBool CUniEditorHeader::IsValidEmailAddress( const TDesC& aAddress ) |
|
903 { |
|
904 // valid email address contains at least 3 characters |
|
905 if( aAddress.Length() >= 3 ) |
|
906 { |
|
907 // search for @ from the address. however, it can't be the first or the last item |
|
908 for ( TInt i = 1; i < aAddress.Length() - 1; i++ ) |
|
909 { |
|
910 if ( aAddress[ i ] == KUniCharAt ) |
|
911 { |
|
912 return ETrue; |
|
913 } |
|
914 } |
|
915 } |
|
916 return EFalse; |
|
917 } |
|
918 |
|
919 |
|
920 |
|
921 |
|
922 // End of File |