152 } |
152 } |
153 |
153 |
154 /* |
154 /* |
155 * |
155 * |
156 */ |
156 */ |
157 void CCreatorMessageElement::AsyncExecuteCommandL() |
|
158 { |
|
159 LOGSTRING("Creator: CCreatorMessageElement::AsyncExecuteCommandL"); |
|
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::AsyncExecuteCommandL: 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 if( iLoopIndex < msgAmount ) |
|
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, iLoopIndex, 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, iLoopIndex, 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 StartNextLoop(); |
|
445 } |
|
446 else |
|
447 { |
|
448 AsyncCommandFinished(); |
|
449 } |
|
450 } |
|
451 else |
|
452 { |
|
453 if( iLoopIndex < msgAmount ) |
|
454 { |
|
455 TInt randMsg = 0; |
|
456 if( msgType == KSms ) |
|
457 randMsg = iEngine->RandomNumber(ECmdCreateRandomEntrySMSInbox, ECmdCreateRandomEntrySMSSent); |
|
458 else if( msgType == KMms ) |
|
459 randMsg = iEngine->RandomNumber(ECmdCreateRandomEntryMMSInbox, ECmdCreateRandomEntryMMSSent); |
|
460 else if( msgType == KAms ) |
|
461 randMsg = iEngine->RandomNumber(ECmdCreateRandomEntryAMSInbox, ECmdCreateRandomEntryAMSSent); |
|
462 else if( msgType == KEmail ) |
|
463 randMsg = iEngine->RandomNumber(ECmdCreateRandomEntryEmailInbox, ECmdCreateRandomEntryEmailSent); |
|
464 else if( msgType == KSmart ) |
|
465 randMsg = iEngine->RandomNumber(ECmdCreateRandomEntryBIOInbox, ECmdCreateRandomEntryBIOSent); |
|
466 else if( msgType == KBt ) |
|
467 randMsg = iEngine->RandomNumber(ECmdCreateRandomEntryBTInbox, ECmdCreateRandomEntryBTSent); |
|
468 else if( msgType == KIr ) |
|
469 randMsg = iEngine->RandomNumber(ECmdCreateRandomEntryIRInbox, ECmdCreateRandomEntryIRSent); |
|
470 |
|
471 if( randMsg > 0 ) |
|
472 { |
|
473 iEngine->AppendToCommandArrayL(randMsg, 0, 1); |
|
474 } |
|
475 StartNextLoop(); |
|
476 } |
|
477 else |
|
478 { |
|
479 AsyncCommandFinished(); |
|
480 } |
|
481 } |
|
482 } |
|
483 void CCreatorMessageElement::ExecuteCommandL() |
157 void CCreatorMessageElement::ExecuteCommandL() |
484 { |
158 { |
485 LOGSTRING("Creator: CCreatorMessageElement::ExecuteCommandL"); |
159 LOGSTRING("Creator: CCreatorMessageElement::ExecuteCommandL"); |
486 |
160 |
487 // Find out the message type: |
161 // Find out the message type: |