107 } |
107 } |
108 |
108 |
109 TInt MessagingUtils::CreateMessageL(CMsvSession* aMsgSession, const TDesC& aMsgFrom, |
109 TInt MessagingUtils::CreateMessageL(CMsvSession* aMsgSession, const TDesC& aMsgFrom, |
110 const TDesC& aMsgTo,const TDesC& aMsgBody) |
110 const TDesC& aMsgTo,const TDesC& aMsgBody) |
111 { |
111 { |
|
112 CSmsClientMtm* smsMtm = NULL; |
|
113 TMsvId newMsgId = NULL; |
112 CClientMtmRegistry* mtmReg = CClientMtmRegistry::NewL( *aMsgSession ); |
114 CClientMtmRegistry* mtmReg = CClientMtmRegistry::NewL( *aMsgSession ); |
113 CSmsClientMtm* smsMtm = static_cast<CSmsClientMtm*>( mtmReg->NewMtmL( KUidMsgTypeSMS )); |
115 TRAPD(err,smsMtm = static_cast<CSmsClientMtm*>( mtmReg->NewMtmL( KUidMsgTypeSMS ))); |
114 smsMtm->SwitchCurrentEntryL( KMsvGlobalInBoxIndexEntryId ); |
116 if( err == KErrNone) |
115 smsMtm->CreateMessageL( KUidMsgTypeSMS.iUid ); |
117 { |
116 TMsvId newMsgId = smsMtm->Entry().EntryId(); |
118 smsMtm->SwitchCurrentEntryL( KMsvGlobalInBoxIndexEntryId ); |
117 smsMtm->AddAddresseeL( aMsgTo ); //to address if need |
119 smsMtm->CreateMessageL( KUidMsgTypeSMS.iUid ); |
118 CMsvStore* messageStore = smsMtm->Entry().EditStoreL(); |
120 newMsgId = smsMtm->Entry().EntryId(); |
119 CleanupStack::PushL( messageStore ); |
121 smsMtm->AddAddresseeL( aMsgTo ); //to address if need |
120 CSmsHeader& header = smsMtm->SmsHeader(); |
122 CMsvStore* messageStore = smsMtm->Entry().EditStoreL(); |
121 header.SetFromAddressL(aMsgFrom); |
123 CleanupStack::PushL( messageStore ); |
122 header.StoreL( *messageStore ); |
124 CSmsHeader& header = smsMtm->SmsHeader(); |
123 CleanupStack::PopAndDestroy( messageStore ); |
125 header.SetFromAddressL(aMsgFrom); |
124 CRichText& body = smsMtm->Body(); |
126 header.StoreL( *messageStore ); |
125 body.Reset(); |
127 CleanupStack::PopAndDestroy( messageStore ); |
126 // Put 16bits stream stored in 8bits buffer back to 16bits buffer. |
128 CRichText& body = smsMtm->Body(); |
127 body.InsertL( 0, aMsgBody); |
129 body.Reset(); |
128 TMsvEntry entry = smsMtm->Entry().Entry(); |
130 // Put 16bits stream stored in 8bits buffer back to 16bits buffer. |
129 entry.SetInPreparation( EFalse ); |
131 body.InsertL( 0, aMsgBody); |
130 entry.SetVisible( ETrue ); |
132 TMsvEntry entry = smsMtm->Entry().Entry(); |
131 entry.iDate.HomeTime(); |
133 entry.SetInPreparation( EFalse ); |
132 entry.iDetails.Set(aMsgFrom); |
134 entry.SetVisible( ETrue ); |
133 entry.SetUnread( EFalse ); |
135 entry.iDate.HomeTime(); |
134 smsMtm->Entry().ChangeL( entry ); |
136 entry.iDetails.Set(aMsgFrom); |
135 smsMtm->SaveMessageL(); |
137 entry.SetUnread( EFalse ); |
|
138 smsMtm->Entry().ChangeL( entry ); |
|
139 smsMtm->SaveMessageL(); |
|
140 } |
136 delete smsMtm; |
141 delete smsMtm; |
137 delete mtmReg; |
142 delete mtmReg; |
138 return newMsgId; |
143 return newMsgId; |
139 } |
144 } |
140 |
145 |