|
1 /* |
|
2 * Copyright (c) 2008 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "creator_messageelement.h" |
|
20 #include "creator_traces.h" |
|
21 #include "creator_message.h" |
|
22 |
|
23 using namespace creatormsg; |
|
24 |
|
25 /* |
|
26 * |
|
27 */ |
|
28 CCreatorMessageElement* CCreatorMessageElement::NewL(CCreatorEngine* aEngine, const TDesC& aName, const TDesC& aContext ) |
|
29 { |
|
30 CCreatorMessageElement* self = new (ELeave) CCreatorMessageElement(aEngine); |
|
31 CleanupStack::PushL(self); |
|
32 self->ConstructL(aName, aContext); |
|
33 CleanupStack::Pop(self); |
|
34 return self; |
|
35 } |
|
36 /* |
|
37 * |
|
38 */ |
|
39 CCreatorMessageElement::CCreatorMessageElement(CCreatorEngine* aEngine) |
|
40 : |
|
41 CCreatorScriptElement(aEngine) |
|
42 { |
|
43 iIsCommandElement = ETrue; |
|
44 } |
|
45 /* |
|
46 * Sets message type |
|
47 */ |
|
48 void CCreatorMessageElement::SetMessageTypeL(CMessagesParameters& aParameters, const TDesC& aMsgTypeStr ) const |
|
49 { |
|
50 if( CompareIgnoreCase(aMsgTypeStr, KSms) == 0 ) |
|
51 { |
|
52 aParameters.iMessageType = ESMS; |
|
53 } |
|
54 else if( CompareIgnoreCase(aMsgTypeStr, KMms) == 0 ) |
|
55 { |
|
56 aParameters.iMessageType = EMMS; |
|
57 } |
|
58 else if( CompareIgnoreCase(aMsgTypeStr, KAms) == 0 ) |
|
59 { |
|
60 aParameters.iMessageType = EAMS; |
|
61 } |
|
62 else if( CompareIgnoreCase(aMsgTypeStr, KEmail) == 0 ) |
|
63 { |
|
64 aParameters.iMessageType = EEmail; |
|
65 } |
|
66 else if( CompareIgnoreCase(aMsgTypeStr, KSmart) == 0 ) |
|
67 { |
|
68 aParameters.iMessageType = ESmartMessage; |
|
69 } |
|
70 else if( CompareIgnoreCase(aMsgTypeStr, KIr) == 0 ) |
|
71 { |
|
72 aParameters.iMessageType = EIrMessage; |
|
73 } |
|
74 else if( CompareIgnoreCase(aMsgTypeStr, KBt) == 0 ) |
|
75 { |
|
76 aParameters.iMessageType = EBTMessage; |
|
77 } |
|
78 else |
|
79 { |
|
80 LOGSTRING2("ERROR in CCreatorMessageElement::SetMessageTypeL: Unknown message type: %S", &aMsgTypeStr); |
|
81 User::Leave(KErrGeneral); |
|
82 } |
|
83 } |
|
84 /* |
|
85 * Returns maximum length of the body text, when randomlength=max is used. |
|
86 */ |
|
87 TInt CCreatorMessageElement::GetMaxBodyLength( const TDesC& aMsgType ) const |
|
88 { |
|
89 TInt len = 0; |
|
90 if( CompareIgnoreCase(aMsgType, KSms) == 0 ) |
|
91 { |
|
92 len = 160; |
|
93 } |
|
94 else if( CompareIgnoreCase(aMsgType, KMms) == 0 ) |
|
95 { |
|
96 len = 160; |
|
97 } |
|
98 else if( CompareIgnoreCase(aMsgType, KEmail) == 0 ) |
|
99 { |
|
100 len = 1024; |
|
101 } |
|
102 else |
|
103 { |
|
104 len = KUndef; |
|
105 } |
|
106 return len; |
|
107 } |
|
108 /* |
|
109 * Returns random body text length |
|
110 */ |
|
111 TInt CCreatorMessageElement::GetRandomBodyLengthL(const TDesC& aRandomLenStr, const TDesC& aMsgType ) const |
|
112 { |
|
113 TInt len = 0; |
|
114 if( aRandomLenStr == KMax ) |
|
115 { |
|
116 len = GetMaxBodyLength(aMsgType); |
|
117 } |
|
118 else if( aRandomLenStr == KDefault ) |
|
119 { |
|
120 len = KUndef; |
|
121 } |
|
122 else |
|
123 { |
|
124 len = ConvertStrToIntL(aRandomLenStr); |
|
125 } |
|
126 return len; |
|
127 } |
|
128 |
|
129 /* |
|
130 * Creates random message address (To/From) |
|
131 * Returns phone number for SMS, MMS, AMS and Smart messages. |
|
132 * Email address for others |
|
133 */ |
|
134 HBufC* CCreatorMessageElement::CreateMessageAddressLC(const TDesC& msgType) |
|
135 { |
|
136 HBufC* toAddr; |
|
137 if( CompareIgnoreCase(msgType, KSms) == 0 || |
|
138 CompareIgnoreCase(msgType, KMms) == 0 || |
|
139 CompareIgnoreCase(msgType, KAms) == 0 || |
|
140 CompareIgnoreCase(msgType, KSmart) == 0) |
|
141 { |
|
142 TPtrC temp = iEngine->RandomString(CCreatorEngine::EPhoneNumber); |
|
143 toAddr = HBufC::NewL(temp.Length()); |
|
144 CleanupStack::PushL(toAddr); |
|
145 toAddr->Des().Copy(temp); |
|
146 } |
|
147 else |
|
148 { |
|
149 toAddr = iEngine->CreateEmailAddressLC(); |
|
150 } |
|
151 return toAddr; |
|
152 } |
|
153 |
|
154 /* |
|
155 * |
|
156 */ |
|
157 void CCreatorMessageElement::ExecuteCommandL() |
|
158 { |
|
159 LOGSTRING("Creator: CCreatorMessageElement::ExecuteCommandL"); |
|
160 |
|
161 // Find out the message type: |
|
162 const CCreatorScriptAttribute* msgTypeAttr = this->FindAttributeByName(KType); |
|
163 TPtrC msgType; |
|
164 if( msgTypeAttr ) |
|
165 { |
|
166 msgType.Set(msgTypeAttr->Value()); |
|
167 } |
|
168 else |
|
169 { |
|
170 LOGSTRING("ERROR in CCreatorMessageElement::ExecuteCommandL: Type attribute is missing."); |
|
171 User::Leave(KErrGeneral); // type is required attribute |
|
172 } |
|
173 |
|
174 // Find out the amount of calendar entries: |
|
175 const CCreatorScriptAttribute* msgAmountAttr = this->FindAttributeByName(KAmount); |
|
176 TInt msgAmount = 1; |
|
177 if( msgAmountAttr ) |
|
178 { |
|
179 msgAmount = ConvertStrToIntL(msgAmountAttr->Value()); |
|
180 } |
|
181 |
|
182 // Get 'fields' element |
|
183 CCreatorScriptElement* fieldsElement = FindSubElement(KFields); |
|
184 if( fieldsElement && fieldsElement->SubElements().Count() > 0 ) |
|
185 { |
|
186 // Get sub-elements (i.e the message field elements) |
|
187 const RPointerArray<CCreatorScriptElement>& fields = fieldsElement->SubElements(); |
|
188 |
|
189 // Create message entries, the amount of entries is defined by msgAmount: |
|
190 for( TInt cI = 0; cI < msgAmount; ++cI ) |
|
191 { |
|
192 CMessagesParameters* param = new (ELeave) CMessagesParameters; |
|
193 CleanupStack::PushL(param); |
|
194 |
|
195 // Message type: |
|
196 if( msgTypeAttr ) |
|
197 { |
|
198 SetMessageTypeL(*param, msgTypeAttr->Value()); |
|
199 } |
|
200 |
|
201 // Loop all the message field elements: |
|
202 for( TInt i = 0; i < fields.Count(); ++i ) |
|
203 { |
|
204 CCreatorScriptElement* field = fields[i]; |
|
205 TPtrC elemName = field->Name(); |
|
206 TPtrC elemContent = field->Content(); |
|
207 const RPointerArray<CCreatorScriptElement>& contactReferences = field->SubElements(); |
|
208 const CCreatorScriptAttribute* randomAttr = field->FindAttributeByName(KRandomLength); |
|
209 const CCreatorScriptAttribute* amountAttr = field->FindAttributeByName(KAmount); |
|
210 const CCreatorScriptAttribute* increaseAttr = field->FindAttributeByName(KIncrease); |
|
211 TBool increase( EFalse ); |
|
212 if ( increaseAttr ) |
|
213 { |
|
214 increase = ConvertStrToBooleanL( increaseAttr->Value() ); |
|
215 } |
|
216 TInt fieldAmount = 1; |
|
217 if( amountAttr ) |
|
218 { |
|
219 fieldAmount = ConvertStrToIntL(amountAttr->Value()); |
|
220 } |
|
221 |
|
222 if( elemName == KTo ) |
|
223 { |
|
224 // Recipient ('to'-field) |
|
225 for( TInt amountIndex = 0; amountIndex < fieldAmount; ++amountIndex ) |
|
226 { |
|
227 if( (randomAttr || elemContent.Length() == 0 ) && contactReferences.Count() == 0 ) |
|
228 { |
|
229 // Random content |
|
230 HBufC* toAddr = CreateMessageAddressLC(msgType); |
|
231 if( toAddr ) |
|
232 { |
|
233 param->iRecipientAddressArray.AppendL(toAddr); |
|
234 CleanupStack::Pop(); // toAddr |
|
235 } |
|
236 } |
|
237 else |
|
238 { |
|
239 if( elemContent.Length() > 0 && contactReferences.Count() == 0) |
|
240 { |
|
241 // Explicit recipient given |
|
242 HBufC* recipient = HBufC::NewL( elemContent.Length() + 3 ); |
|
243 CleanupStack::PushL(recipient); |
|
244 if ( increase ) |
|
245 { |
|
246 IncreasePhoneNumL( elemContent, cI, recipient ); |
|
247 } |
|
248 else |
|
249 { |
|
250 recipient->Des().Copy(elemContent); |
|
251 } |
|
252 param->iRecipientAddressArray.AppendL(recipient); |
|
253 CleanupStack::Pop(); // recipient |
|
254 } |
|
255 else |
|
256 { |
|
257 // Recipients specified with contact-set-references (if any) |
|
258 for( TInt csI = 0; csI < contactReferences.Count(); ++csI ) |
|
259 { |
|
260 CCreatorScriptElement* contactSetRef = contactReferences[csI]; |
|
261 AppendContactSetReferenceL(*contactSetRef, param->iRecipientLinkIds); |
|
262 } |
|
263 } |
|
264 } |
|
265 } |
|
266 } |
|
267 else if( elemName == KFrom ) |
|
268 { |
|
269 // Sender ('from'-field) |
|
270 // Amount attribute for sender is ignored, because there can be only one sender |
|
271 delete param->iSenderAddress; |
|
272 param->iSenderAddress = 0; |
|
273 if( (randomAttr || elemContent.Length() == 0 ) && contactReferences.Count() == 0 ) |
|
274 { |
|
275 // Get random address |
|
276 param->iSenderAddress = CreateMessageAddressLC(msgType); |
|
277 CleanupStack::Pop(); // param->iSenderAddress |
|
278 } |
|
279 else |
|
280 { |
|
281 if( elemContent.Length() > 0 && contactReferences.Count() == 0) |
|
282 { |
|
283 // Explicit sender address given |
|
284 param->iSenderAddress = HBufC::NewL(elemContent.Length()); |
|
285 if ( increase ) |
|
286 { |
|
287 IncreasePhoneNumL( elemContent, cI, param->iSenderAddress ); |
|
288 } |
|
289 else |
|
290 { |
|
291 param->iSenderAddress->Des().Copy(elemContent); |
|
292 } |
|
293 } |
|
294 else |
|
295 { |
|
296 // Senders specified with contact-set-references (if any) |
|
297 for( TInt csI = 0; csI < contactReferences.Count(); ++csI ) |
|
298 { |
|
299 CCreatorScriptElement* contactSetRef = contactReferences[csI]; |
|
300 AppendContactSetReferenceL(*contactSetRef, param->iSenderLinkIds); |
|
301 } |
|
302 } |
|
303 } |
|
304 } |
|
305 else if( elemName == KFolder ) |
|
306 { |
|
307 // Folder type |
|
308 if( CompareIgnoreCase(elemContent, KSent) == 0 ) |
|
309 { |
|
310 param->iFolderType = ESent; |
|
311 } |
|
312 else if( CompareIgnoreCase(elemContent, KInbox) == 0 ) |
|
313 { |
|
314 param->iFolderType = EInbox; |
|
315 } |
|
316 else if( CompareIgnoreCase(elemContent, KOutbox) == 0 ) |
|
317 { |
|
318 param->iFolderType = EOutbox; |
|
319 } |
|
320 else if( CompareIgnoreCase(elemContent, KDraft) == 0 ) |
|
321 { |
|
322 param->iFolderType = EDrafts; |
|
323 } |
|
324 } |
|
325 else if( elemName == KSubject ) |
|
326 { |
|
327 // Message subject |
|
328 delete param->iMessageSubject; |
|
329 param->iMessageSubject = 0; |
|
330 |
|
331 if( randomAttr || elemContent.Length() == 0 ) |
|
332 { |
|
333 // Random data should be used |
|
334 TPtrC temp = iEngine->RandomString(CCreatorEngine::EMessageSubject); |
|
335 param->iMessageSubject = HBufC::NewL(temp.Length()); |
|
336 param->iMessageSubject->Des().Copy(temp); |
|
337 } |
|
338 else |
|
339 { |
|
340 param->iMessageSubject = HBufC::NewL(elemContent.Length()); |
|
341 param->iMessageSubject->Des().Copy(elemContent); |
|
342 } |
|
343 } |
|
344 else if( elemName == KText ) |
|
345 { |
|
346 // Body text |
|
347 delete param->iMessageBodyText; |
|
348 param->iMessageBodyText = 0; |
|
349 |
|
350 if( randomAttr || elemContent.Length() == 0 ) |
|
351 { |
|
352 // Put random text: |
|
353 if( randomAttr && randomAttr->Value() != KDefault ) |
|
354 { |
|
355 // Get the random length |
|
356 TInt len = GetRandomBodyLengthL(randomAttr->Value(), msgTypeAttr->Value()); |
|
357 if( len != KUndef ) |
|
358 { |
|
359 param->iMessageBodyText = iEngine->CreateRandomStringLC(len); |
|
360 CleanupStack::Pop(); // param->iMessageBodyText |
|
361 } |
|
362 } |
|
363 else |
|
364 { |
|
365 // Use default random data |
|
366 TPtrC temp = iEngine->RandomString(CCreatorEngine::EMessageText); |
|
367 param->iMessageBodyText = HBufC::NewL(temp.Length()); |
|
368 param->iMessageBodyText->Des().Copy(temp); |
|
369 } |
|
370 } |
|
371 else |
|
372 { |
|
373 param->iMessageBodyText = HBufC::NewL(elemContent.Length()); |
|
374 param->iMessageBodyText->Des().Copy(elemContent); |
|
375 } |
|
376 } |
|
377 else if( elemName == KAttachmentId ) |
|
378 { |
|
379 // Attachment file id |
|
380 for( TInt amountIndex = 0; amountIndex < fieldAmount; ++amountIndex ) |
|
381 { |
|
382 if( randomAttr || elemContent.Length() == 0) |
|
383 { |
|
384 //When type is AMS, attachement will be audio |
|
385 if(param->iMessageType == EAMS) |
|
386 { |
|
387 param->iAttachments->AppendL(CCreatorEngine::EMP3_250kB); |
|
388 } |
|
389 //Otherwise attachement can be any file |
|
390 else |
|
391 { |
|
392 //EJPEG_25kB is first (0) in the enum and LAST_FILE_ID is last in the enum, so real last item id is one before LAST_FILE_ID |
|
393 param->iAttachments->AppendL( iEngine->RandomNumber(CCreatorEngine::EJPEG_25kB, CCreatorEngine::LAST_FILE_ID-1) ); |
|
394 } |
|
395 } |
|
396 else |
|
397 { |
|
398 //When user has been set attechment by it self, we trust user selection (not validating value, e.g. if message is SMS and there is attachement) |
|
399 TInt id = iEngine->GetAttachmentIdL(elemContent); |
|
400 if( id != KUndef ) |
|
401 { |
|
402 param->iAttachments->AppendL( id ); |
|
403 } |
|
404 } |
|
405 } |
|
406 } |
|
407 // Attachment file path handling |
|
408 //E.g. C:\data\others\DOC-20kB.doc |
|
409 else if( elemName == KAttachmentPath ) |
|
410 { |
|
411 // Attachment file id |
|
412 for( TInt amountIndex = 0; amountIndex < fieldAmount; ++amountIndex ) |
|
413 { |
|
414 //Path is random, getting one of the files (not even using path attribute, but id with random) |
|
415 if( randomAttr || elemContent.Length() == 0) |
|
416 { |
|
417 //EJPEG_25kB is first (0) in the enum and LAST_FILE_ID is last in the enum, so real last item id is one before LAST_FILE_ID |
|
418 param->iAttachments->AppendL( iEngine->RandomNumber(CCreatorEngine::EJPEG_25kB, CCreatorEngine::LAST_FILE_ID -1) ); |
|
419 } |
|
420 //Otherwise adding attachement path as it is to paths. |
|
421 else |
|
422 { |
|
423 //Adding Attachement file path |
|
424 HBufC* elemData = elemContent.AllocLC(); |
|
425 param->iAttachmentPaths.AppendL( elemData ); |
|
426 CleanupStack::Pop(elemData); |
|
427 } |
|
428 } |
|
429 } |
|
430 else if ( elemName == KStatus ) |
|
431 { |
|
432 if( CompareIgnoreCase( elemContent, KNew ) == 0 ) |
|
433 { |
|
434 param->iCreateAsUnread = ETrue; |
|
435 } |
|
436 else if( CompareIgnoreCase( elemContent, KRead ) == 0 ) |
|
437 { |
|
438 param->iCreateAsUnread = EFalse; |
|
439 } |
|
440 } |
|
441 } |
|
442 iEngine->AppendToCommandArrayL(ECmdCreateMessagingEntryMessagesViaScript, param); |
|
443 CleanupStack::Pop(); // param |
|
444 } |
|
445 } |
|
446 else |
|
447 { |
|
448 for( TInt i = 0; i < msgAmount; ++i ) |
|
449 { |
|
450 TInt randMsg = 0; |
|
451 if( msgType == KSms ) |
|
452 randMsg = iEngine->RandomNumber(ECmdCreateRandomEntrySMSInbox, ECmdCreateRandomEntrySMSSent); |
|
453 else if( msgType == KMms ) |
|
454 randMsg = iEngine->RandomNumber(ECmdCreateRandomEntryMMSInbox, ECmdCreateRandomEntryMMSSent); |
|
455 else if( msgType == KAms ) |
|
456 randMsg = iEngine->RandomNumber(ECmdCreateRandomEntryAMSInbox, ECmdCreateRandomEntryAMSSent); |
|
457 else if( msgType == KEmail ) |
|
458 randMsg = iEngine->RandomNumber(ECmdCreateRandomEntryEmailInbox, ECmdCreateRandomEntryEmailSent); |
|
459 else if( msgType == KSmart ) |
|
460 randMsg = iEngine->RandomNumber(ECmdCreateRandomEntryBIOInbox, ECmdCreateRandomEntryBIOSent); |
|
461 else if( msgType == KBt ) |
|
462 randMsg = iEngine->RandomNumber(ECmdCreateRandomEntryBTInbox, ECmdCreateRandomEntryBTSent); |
|
463 else if( msgType == KIr ) |
|
464 randMsg = iEngine->RandomNumber(ECmdCreateRandomEntryIRInbox, ECmdCreateRandomEntryIRSent); |
|
465 |
|
466 if( randMsg > 0 ) |
|
467 { |
|
468 iEngine->AppendToCommandArrayL(randMsg, 0, 1); |
|
469 } |
|
470 } |
|
471 } |
|
472 } |
|
473 |
|
474 // End of file |