340 |
387 |
341 tmpfile.Temp(rFs, filePath, iBodyTextFileName, EFileShareExclusive|EFileWrite); |
388 tmpfile.Temp(rFs, filePath, iBodyTextFileName, EFileShareExclusive|EFileWrite); |
342 |
389 |
343 iBodyTextFileFlag = ETrue; |
390 iBodyTextFileFlag = ETrue; |
344 |
391 |
345 HBufC8* buffer=HBufC8::NewL( bodyText.Length() ); |
392 HBufC8* buffer=HBufC8::NewL( bodyText.Length()* 4 ); |
|
393 TPtr8 tmpBuffer = buffer->Des(); |
|
394 CnvUtfConverter::ConvertFromUnicodeToUtf8(tmpBuffer, bodyText); |
346 CleanupStack::PushL( buffer ); |
395 CleanupStack::PushL( buffer ); |
347 buffer->Des().Copy( bodyText ); |
396 buffer->Des().Copy( tmpBuffer ); |
348 tmpfile.Write( *buffer ); |
397 tmpfile.Write( *buffer ); |
349 tmpfile.Flush(); |
398 tmpfile.Flush(); |
350 tmpfile.Close(); |
399 tmpfile.Close(); |
351 rFs.Close(); |
400 rFs.Close(); |
352 CleanupStack::PopAndDestroy( buffer ); |
401 CleanupStack::PopAndDestroy( buffer ); |
353 |
|
354 TRequestStatus stat; |
402 TRequestStatus stat; |
355 iMessage.AddAttachment( iBodyTextFileName, KMmsTextPlain, stat ); |
403 iMessage.AddAttachment( iBodyTextFileName, KMmsTextPlain, 0, stat ); |
356 User::WaitForRequest( stat ); |
404 User::WaitForRequest( stat ); |
357 } |
405 } |
358 else |
406 else |
359 { |
407 { |
360 iMessage.SetBodyTextL( bodyText ); |
408 iMessage.SetBodyTextL( bodyText ); |
393 error = tmpfile.Open(rFs, ((*attachmentArray)[count])->AttachmentName(), EFileRead); |
441 error = tmpfile.Open(rFs, ((*attachmentArray)[count])->AttachmentName(), EFileRead); |
394 |
442 |
395 if( error == KErrNone ) |
443 if( error == KErrNone ) |
396 { |
444 { |
397 TBuf8<256> tmpbuf; |
445 TBuf8<256> tmpbuf; |
398 |
|
399 tmpfile.Read(tmpbuf, 255 ); |
446 tmpfile.Read(tmpbuf, 255 ); |
400 |
447 |
401 tmpfile.Close(); |
448 tmpfile.Close(); |
402 |
449 |
403 TDataRecognitionResult aDataType; |
450 TDataRecognitionResult aDataType; |
404 |
451 |
405 error = rapaSesion.RecognizeData(((*attachmentArray)[count])->AttachmentName(), tmpbuf, aDataType); |
452 error = rapaSesion.RecognizeData(((*attachmentArray)[count])->AttachmentName(), tmpbuf, aDataType); |
406 |
453 |
|
454 |
|
455 |
407 if( error == KErrNone ) |
456 if( error == KErrNone ) |
408 { |
457 { |
409 TBuf8< KMaxDataTypeLength > tmp; |
458 TBuf8< KMaxDataTypeLength > tmp; |
410 tmp.Copy( aDataType.iDataType.Des() ); |
459 tmp.Copy( aDataType.iDataType.Des() ); |
411 |
460 |
412 iMessage.AddAttachment( ((*attachmentArray)[count])->AttachmentName(), |
461 if(!(tmp.CompareF(KMmsTextPlain))) |
|
462 { |
|
463 iMessage.AddAttachment( ((*attachmentArray)[count])->AttachmentName(), |
|
464 tmp, 0, |
|
465 attachstatus ); |
|
466 } |
|
467 else |
|
468 { |
|
469 iMessage.AddAttachment( ((*attachmentArray)[count])->AttachmentName(), |
413 tmp, |
470 tmp, |
414 attachstatus ); |
471 attachstatus ); |
|
472 } |
415 } |
473 } |
416 else |
474 else |
417 { |
475 { |
418 if ( ((*attachmentArray)[count])->MimeType().Length() ) |
476 if ( ((*attachmentArray)[count])->MimeType().Length() ) |
419 { |
477 { |
|
478 |
420 iMessage.AddAttachment( ((*attachmentArray)[count])->AttachmentName(), |
479 iMessage.AddAttachment( ((*attachmentArray)[count])->AttachmentName(), |
421 ((*attachmentArray)[count])->MimeType(), |
480 ((*attachmentArray)[count])->MimeType(), |
422 attachstatus ); |
481 attachstatus ); |
423 } |
482 } |
424 else |
483 else |
425 { |
484 { |
|
485 |
426 iMessage.AddAttachment( ((*attachmentArray)[count])->AttachmentName(), |
486 iMessage.AddAttachment( ((*attachmentArray)[count])->AttachmentName(), |
427 attachstatus ); |
487 attachstatus ); |
428 } |
488 } |
429 } |
489 } |
430 |
490 |
435 else |
495 else |
436 { |
496 { |
437 User::Leave( error ); |
497 User::Leave( error ); |
438 } |
498 } |
439 } |
499 } |
|
500 |
440 CleanupStack::PopAndDestroy( &rFs ); |
501 CleanupStack::PopAndDestroy( &rFs ); |
441 CleanupStack::PopAndDestroy( &rapaSesion ); |
502 CleanupStack::PopAndDestroy( &rapaSesion ); |
442 } |
503 } |
443 } |
504 } |
444 |
505 |
445 |
506 // --------------------------------------------------------------------------- |
|
507 // Two-phased constructor. |
|
508 // --------------------------------------------------------------------------- |
|
509 // |
|
510 CAsyncWaiter* CAsyncWaiter::NewL(TInt aPriority) |
|
511 { |
|
512 CAsyncWaiter* self = new(ELeave) CAsyncWaiter(aPriority); |
|
513 return self; |
|
514 } |
|
515 |
|
516 // --------------------------------------------------------------------------- |
|
517 // Two-phased constructor. |
|
518 // --------------------------------------------------------------------------- |
|
519 // |
|
520 CAsyncWaiter* CAsyncWaiter::NewLC(TInt aPriority) |
|
521 { |
|
522 CAsyncWaiter* self = new(ELeave) CAsyncWaiter(aPriority); |
|
523 CleanupStack::PushL(self); |
|
524 return self; |
|
525 } |
|
526 |
|
527 // --------------------------------------------------------------------------- |
|
528 // Two-phased constructor. |
|
529 // --------------------------------------------------------------------------- |
|
530 // |
|
531 CAsyncWaiter::CAsyncWaiter(TInt aPriority) : CActive(aPriority) |
|
532 { |
|
533 CActiveScheduler::Add(this); |
|
534 } |
|
535 |
|
536 // --------------------------------------------------------------------------- |
|
537 // Destructor. |
|
538 // --------------------------------------------------------------------------- |
|
539 // |
|
540 CAsyncWaiter::~CAsyncWaiter() |
|
541 { |
|
542 Cancel(); |
|
543 } |
|
544 |
|
545 // --------------------------------------------------------------------------- |
|
546 // Starts the active scheduler. |
|
547 // --------------------------------------------------------------------------- |
|
548 // |
|
549 void CAsyncWaiter::StartAndWait() |
|
550 { |
|
551 iStatus = KRequestPending; |
|
552 SetActive(); |
|
553 iWait.Start(); |
|
554 } |
|
555 |
|
556 // --------------------------------------------------------------------------- |
|
557 // Returns the error |
|
558 // --------------------------------------------------------------------------- |
|
559 // |
|
560 TInt CAsyncWaiter::Result() const |
|
561 { |
|
562 return iError; |
|
563 } |
|
564 |
|
565 // --------------------------------------------------------------------------- |
|
566 // Inherited from CActive class |
|
567 // --------------------------------------------------------------------------- |
|
568 // |
|
569 void CAsyncWaiter::RunL() |
|
570 { |
|
571 iError = iStatus.Int(); |
|
572 iWait.AsyncStop(); |
|
573 } |
|
574 |
|
575 // --------------------------------------------------------------------------- |
|
576 // Inherited from CActive class |
|
577 // --------------------------------------------------------------------------- |
|
578 // |
|
579 void CAsyncWaiter::DoCancel() |
|
580 { |
|
581 iError = KErrCancel; |
|
582 if( iStatus == KRequestPending ) |
|
583 { |
|
584 TRequestStatus* s=&iStatus; |
|
585 User::RequestComplete( s, KErrCancel ); |
|
586 } |
|
587 |
|
588 iWait.AsyncStop(); |
|
589 } |
|
590 |
|
591 // --------------------------------------------------------------------------- |
|
592 // Sends the sms. |
|
593 // --------------------------------------------------------------------------- |
|
594 // |
|
595 void CSendMessage::SendSMSMessageL() |
|
596 { |
|
597 if ( iTemplateDetail ) |
|
598 { |
|
599 if ( iTemplateDetail->BodyText().Length() ) |
|
600 { |
|
601 iMessageParam->AppendBodyTextL( iTemplateDetail->BodyText() ); |
|
602 } |
|
603 delete iTemplateDetail; |
|
604 iTemplateDetail = NULL; |
|
605 } |
|
606 |
|
607 CClientMtmRegistry* registry = CClientMtmRegistry::NewL(iServerSession); |
|
608 CleanupStack::PushL(registry); |
|
609 |
|
610 // get the client mtm and return if it isn't supported in the system |
|
611 CSmsClientMtm* clientMtm = NULL; |
|
612 TRAPD(err, clientMtm = static_cast<CSmsClientMtm*>(registry->NewMtmL(KUidMsgTypeSMS))); |
|
613 if (err || !clientMtm) |
|
614 { |
|
615 User::Leave(KErrNotFound); |
|
616 } |
|
617 CleanupStack::PushL(clientMtm); |
|
618 |
|
619 // create a new object to access an existing entry |
|
620 CMsvEntry* msvEntry = CMsvEntry::NewL(iServerSession, KMsvGlobalInBoxIndexEntryId, TMsvSelectionOrdering()); |
|
621 CleanupStack::PushL(msvEntry); |
|
622 |
|
623 // get default service |
|
624 TMsvId defaultServiceId = 0; |
|
625 TRAP(err, defaultServiceId = clientMtm->DefaultServiceL()); |
|
626 if (err) |
|
627 { |
|
628 User::Leave(KErrNotFound); |
|
629 } |
|
630 |
|
631 if( iMessageParam->LaunchEditor() ) |
|
632 { |
|
633 msvEntry->SetEntryL(KMsvDraftEntryId); |
|
634 } |
|
635 else |
|
636 { |
|
637 msvEntry->SetEntryL(KMsvGlobalOutBoxIndexEntryId); |
|
638 } |
|
639 |
|
640 // mtm takes ownership of entry context |
|
641 CleanupStack::Pop(msvEntry); |
|
642 clientMtm->SetCurrentEntryL(msvEntry); |
|
643 |
|
644 // create a new message |
|
645 clientMtm->CreateMessageL(defaultServiceId); |
|
646 |
|
647 |
|
648 // set body |
|
649 clientMtm->Body().Reset(); |
|
650 clientMtm->Body().InsertL(0, iMessageParam->BodyText()); |
|
651 TPtrC subject( iMessageParam->Subject()); |
|
652 if ( subject.Length() ) |
|
653 clientMtm->SetSubjectL( iMessageParam->Subject() ); |
|
654 // get the entry of the message |
|
655 TMsvEntry messageEntry = clientMtm->Entry().Entry(); |
|
656 |
|
657 const CRecipientList* recipientArray = iMessageParam->RecipientArray(); |
|
658 if ( recipientArray ) |
|
659 { |
|
660 TInt count = recipientArray->Count(); |
|
661 if(count) |
|
662 { |
|
663 messageEntry.iDetails.Set((*recipientArray)[0]); |
|
664 } |
|
665 for( TInt pos = 0; pos < count; pos++ ) |
|
666 { |
|
667 clientMtm->AddAddresseeL(( *recipientArray)[pos]); |
|
668 } |
|
669 } |
|
670 |
|
671 // set the description field same as the first part of the message body |
|
672 messageEntry.iDescription.Set( iMessageParam->BodyText().Left(KSmsDescriptionLength) ); |
|
673 |
|
674 |
|
675 CSmsHeader& smsHdr = clientMtm->SmsHeader(); |
|
676 CSmsSettings* smsSetting = CSmsSettings::NewLC(); |
|
677 smsSetting->CopyL(clientMtm->ServiceSettings()); |
|
678 smsSetting->SetCharacterSet(TSmsDataCodingScheme::ESmsAlphabetUCS2); |
|
679 smsHdr.SetSmsSettingsL(*smsSetting); |
|
680 CleanupStack::PopAndDestroy(smsSetting); |
|
681 |
|
682 // save the changes done above |
|
683 clientMtm->Entry().ChangeL(messageEntry); |
|
684 |
|
685 // save the message |
|
686 clientMtm->SaveMessageL(); |
|
687 |
|
688 |
|
689 // final fine tuning |
|
690 messageEntry.SetAttachment(EFalse); |
|
691 messageEntry.iDate.DateTime().SetSecond( messageEntry.iDate.DateTime().Second()+1); |
|
692 messageEntry.SetVisible(ETrue); |
|
693 messageEntry.SetInPreparation(EFalse); |
|
694 messageEntry.SetComplete(ETrue); |
|
695 messageEntry.iServiceId = defaultServiceId; |
|
696 messageEntry.iRelatedId = 0; |
|
697 if( iMessageParam->LaunchEditor() ) |
|
698 { |
|
699 messageEntry.SetSendingState( KMsvSendStateNotApplicable ); |
|
700 } |
|
701 else |
|
702 { |
|
703 messageEntry.SetSendingState( KMsvSendStateWaiting ); |
|
704 } |
|
705 |
|
706 clientMtm->Entry().ChangeL(messageEntry); |
|
707 clientMtm->SaveMessageL(); |
|
708 |
|
709 if( iMessageParam->LaunchEditor() ) |
|
710 { |
|
711 MturUtils::LaunchEditorAndWaitL(messageEntry.Id()); |
|
712 } |
|
713 else |
|
714 { |
|
715 CMsvEntrySelection* sel = new(ELeave) CMsvEntrySelection; |
|
716 CleanupStack::PushL(sel); |
|
717 sel->AppendL(messageEntry.Id()); |
|
718 |
|
719 TBuf8<1> dummy; |
|
720 CAsyncWaiter* waiter = CAsyncWaiter::NewL(); |
|
721 CleanupStack::PushL(waiter); |
|
722 CMsvOperation* sndCall = clientMtm->InvokeAsyncFunctionL(ESmsMtmCommandScheduleCopy,*sel,dummy,waiter->iStatus); |
|
723 CleanupStack::PushL(sndCall); |
|
724 waiter->StartAndWait(); |
|
725 CleanupStack::PopAndDestroy(2); //sndCall, waiter |
|
726 sel->Reset(); |
|
727 CleanupStack::PopAndDestroy(sel); |
|
728 } |
|
729 CleanupStack::PopAndDestroy(2);//registry, clientMtm |
|
730 } |
|
731 |
|
732 |