|
1 /* |
|
2 * Copyright (c) 2010 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 "engine.h" |
|
20 #include "enginewrapper.h" |
|
21 |
|
22 #include "creator_message.h" |
|
23 #include "creator_traces.h" |
|
24 #include "creator_contactsetcache.h" |
|
25 #include <apgcli.h> |
|
26 #include <MuiuServiceUtilities.h> |
|
27 |
|
28 #include <mmf/common/mmfcontrollerpluginresolver.h> // for CleanupResetAndDestroyPushL |
|
29 |
|
30 //static const TInt KMessagesFieldLength = 1024; |
|
31 |
|
32 //_LIT(KCreatorMessagesPrefixName, "CR_"); |
|
33 //_LIT(KCreatorMessagesPrefixFolderName, "CR_FLDR_"); |
|
34 |
|
35 |
|
36 const TUid KUidBIOBusinessCardMsg = {0x10005531}; |
|
37 _LIT(KEmpty, ""); |
|
38 |
|
39 //---------------------------------------------------------------------------- |
|
40 |
|
41 CMessagesParameters::CMessagesParameters() |
|
42 { |
|
43 LOGSTRING("Creator: CMessagesParameters::CMessagesParameters"); |
|
44 |
|
45 iSenderAddress = HBufC::New(128); |
|
46 iRecipientAddress = HBufC::New(128); |
|
47 iMessageSubject = HBufC::New(128); |
|
48 iMessageBodyText = HBufC::New(10240); |
|
49 TRAP_IGNORE(iAttachments = new(ELeave) CArrayFixFlat<TInt>(64)); |
|
50 iCreateAsUnread = ETrue; |
|
51 } |
|
52 |
|
53 CMessagesParameters::~CMessagesParameters() |
|
54 { |
|
55 LOGSTRING("Creator: CMessagesParameters::~CMessagesParameters"); |
|
56 |
|
57 |
|
58 delete iMessageBodyText; |
|
59 delete iMessageSubject; |
|
60 delete iRecipientAddress; |
|
61 delete iSenderAddress; |
|
62 delete iAttachments; |
|
63 iAttachmentPaths.ResetAndDestroy(); |
|
64 iAttachmentPaths.Close(); |
|
65 iRecipientAddressArray.ResetAndDestroy(); |
|
66 iRecipientAddressArray.Close(); |
|
67 iRecipientLinkIds.Close(); |
|
68 iSenderLinkIds.Close(); |
|
69 } |
|
70 |
|
71 //---------------------------------------------------------------------------- |
|
72 |
|
73 CCreatorMessages* CCreatorMessages::NewL(CCreatorEngine* aEngine) |
|
74 { |
|
75 CCreatorMessages* self = CCreatorMessages::NewLC(aEngine); |
|
76 CleanupStack::Pop(self); |
|
77 return self; |
|
78 } |
|
79 |
|
80 CCreatorMessages* CCreatorMessages::NewLC(CCreatorEngine* aEngine) |
|
81 { |
|
82 CCreatorMessages* self = new (ELeave) CCreatorMessages; |
|
83 CleanupStack::PushL(self); |
|
84 self->ConstructL(aEngine); |
|
85 return self; |
|
86 } |
|
87 |
|
88 CCreatorMessages::CCreatorMessages() |
|
89 { |
|
90 } |
|
91 |
|
92 void CCreatorMessages::ConstructL(CCreatorEngine* aEngine) |
|
93 { |
|
94 LOGSTRING("Creator: CCreatorMessages::ConstructL"); |
|
95 iEngine = aEngine; |
|
96 |
|
97 TRAP_IGNORE(iAttachments = new(ELeave) CArrayFixFlat<TInt>(64)); |
|
98 iWaiter = CAsyncWaiter::NewL(); |
|
99 } |
|
100 |
|
101 CCreatorMessages::~CCreatorMessages() |
|
102 { |
|
103 LOGSTRING("Creator: CCreatorMessages::~CCreatorMessages"); |
|
104 |
|
105 if ( iEngine && iEntryIds.Count() ) |
|
106 { |
|
107 TRAP_IGNORE( iEngine->WriteEntryIdsToStoreL( iEntryIds, KUidDictionaryUidMessages ) ); |
|
108 } |
|
109 iEntryIds.Reset(); |
|
110 iEntryIds.Close(); |
|
111 |
|
112 delete iParameters; |
|
113 delete iWaiter; |
|
114 delete iTmpPhoneNumber; |
|
115 delete iTmpEmail; |
|
116 delete iAttachments; |
|
117 |
|
118 iRecipientArray.ResetAndDestroy(); |
|
119 iRecipientArray.Close(); |
|
120 iSenderArray.ResetAndDestroy(); |
|
121 iSenderArray.Close(); |
|
122 } |
|
123 |
|
124 //---------------------------------------------------------------------------- |
|
125 |
|
126 TBool CCreatorMessages::AskDataFromUserL(TInt aCommand, TInt& aNumberOfEntries) |
|
127 { |
|
128 LOGSTRING("Creator: CCreatorMessages::AskDataFromUserL"); |
|
129 |
|
130 if ( aCommand == ECmdDeleteMessages ) |
|
131 { |
|
132 return iEngine->GetEngineWrapper()->YesNoQueryDialog( _L("Delete all messages?") ); |
|
133 } |
|
134 else if ( aCommand == ECmdDeleteCreatorMessages ) |
|
135 { |
|
136 return iEngine->GetEngineWrapper()->YesNoQueryDialog( _L("Delete all messages created with Creator?") ); |
|
137 } |
|
138 |
|
139 if (iEngine->GetEngineWrapper()->EntriesQueryDialog(aNumberOfEntries, _L("How many entries to create?"))) |
|
140 { |
|
141 |
|
142 // message type query |
|
143 if (iEngine->GetEngineWrapper()->ListQueryDialog(_L("Message type"), R_MESSAGE_TYPE_QUERY, (TInt&) iMessageType)) |
|
144 { |
|
145 if (iEngine->GetEngineWrapper()->ListQueryDialog(_L("Folder type"), R_FOLDER_TYPE_QUERY, (TInt&) iFolderType)) |
|
146 { |
|
147 /* |
|
148 if (iFolderType == EMailbox) |
|
149 { |
|
150 // array to hold mailbox names |
|
151 CDesCArray* names = new (ELeave) CDesCArrayFlat(16); |
|
152 CleanupStack::PushL(names); |
|
153 |
|
154 CMsvSession* session = CMsvSession::OpenSyncL(*this); |
|
155 CleanupStack::PushL(session); |
|
156 |
|
157 // generate list of mailboxes |
|
158 CMsvEntrySelection* entrySelection = MsvUiServiceUtilities::GetListOfAccountsWithMTML(*session, KUidMsgTypeSMTP, ETrue); |
|
159 CleanupStack::PushL(entrySelection); |
|
160 |
|
161 TBool doReturn(EFalse); |
|
162 |
|
163 if (entrySelection->Count() == 0) |
|
164 { |
|
165 CAknInformationNote* note = new(ELeave) CAknInformationNote; |
|
166 note->ExecuteLD(_L("No mailboxes found")); |
|
167 |
|
168 doReturn = ETrue; |
|
169 } |
|
170 else |
|
171 { |
|
172 // get mailbox names |
|
173 for (TInt i=0; i<entrySelection->Count(); i++) |
|
174 { |
|
175 CMsvEntry* centry = session->GetEntryL(entrySelection->At(i)); |
|
176 CleanupStack::PushL(centry); |
|
177 |
|
178 TMsvEntry tentry = centry->Entry(); |
|
179 names->AppendL(tentry.iDetails); |
|
180 CleanupStack::PopAndDestroy(); //centry |
|
181 } |
|
182 |
|
183 // show query |
|
184 TInt index(0); |
|
185 CAknListQueryDialog* dlg = new(ELeave) CAknListQueryDialog(&index); |
|
186 dlg->PrepareLC(R_MAILBOX_SELECTION_QUERY); |
|
187 dlg->SetItemTextArray(names); |
|
188 dlg->SetOwnershipType(ELbmDoesNotOwnItemArray); |
|
189 |
|
190 if(dlg->RunLD()) |
|
191 { |
|
192 iUserSelectedMailbox = entrySelection->At(index); |
|
193 |
|
194 doReturn = EFalse; |
|
195 } |
|
196 else |
|
197 { |
|
198 doReturn = ETrue; |
|
199 } |
|
200 |
|
201 } |
|
202 |
|
203 CleanupStack::PopAndDestroy(3); // names, session, entrySelection |
|
204 |
|
205 if (doReturn) |
|
206 return EFalse; |
|
207 } |
|
208 */ |
|
209 |
|
210 // query create as unread |
|
211 if (iEngine->GetEngineWrapper()->ListQueryDialog(_L("Message status"), R_UNREAD_QUERY, (TInt&)iCreateAsUnread)) |
|
212 { |
|
213 // query number of characters in msg body |
|
214 switch (iMessageType) |
|
215 { |
|
216 case ESMS: |
|
217 case EMMS: |
|
218 case EEmail: |
|
219 { |
|
220 iDefinedMessageLength = 100; |
|
221 if (iEngine->GetEngineWrapper()->EntriesQueryDialog(iDefinedMessageLength, _L("Amount of characters in message body?"), ETrue)) |
|
222 { |
|
223 ; |
|
224 } |
|
225 else |
|
226 return EFalse; |
|
227 |
|
228 break; |
|
229 } |
|
230 case EAMS: |
|
231 { |
|
232 iDefinedMessageLength = 0; |
|
233 break; |
|
234 } |
|
235 default: break; |
|
236 } |
|
237 |
|
238 // query attachments |
|
239 iAttachments->Reset(); |
|
240 |
|
241 switch (iMessageType) |
|
242 { |
|
243 case EMMS: |
|
244 case EEmail: |
|
245 { |
|
246 if (iEngine->GetEngineWrapper()->ListQueryDialog(_L("Choose attachment:"), R_ATTACHMENT_MULTI_SELECTION_QUERY, iAttachments)) |
|
247 { |
|
248 // "none" is selected |
|
249 if (iAttachments->At(0) == 0) |
|
250 iAttachments->Reset(); |
|
251 else // otherwise fix indexes |
|
252 { |
|
253 for (TInt i=0; i<iAttachments->Count(); i++) |
|
254 iAttachments->At(i)--; // decrease value by one |
|
255 |
|
256 } |
|
257 } |
|
258 else |
|
259 return EFalse; |
|
260 |
|
261 break; |
|
262 } |
|
263 case EAMS: |
|
264 { |
|
265 iAttachments->AppendL( TInt(0) ); |
|
266 if (iEngine->GetEngineWrapper()->ListQueryDialog(_L("Choose attachment:"), R_AMS_ATTACHMENT_SINGLE_SELECTION_QUERY, iAttachments->At(0))) |
|
267 { |
|
268 ; |
|
269 } |
|
270 else |
|
271 return EFalse; |
|
272 |
|
273 break; |
|
274 } |
|
275 |
|
276 case EIrMessage: |
|
277 case EBTMessage: |
|
278 { |
|
279 iAttachments->AppendL( TInt(0) ); |
|
280 if (iEngine->GetEngineWrapper()->ListQueryDialog(_L("Choose attachment:"), R_ATTACHMENT_SINGLE_SELECTION_QUERY, iAttachments->At(0))) |
|
281 { |
|
282 ; |
|
283 } |
|
284 else |
|
285 return EFalse; |
|
286 |
|
287 break; |
|
288 } |
|
289 default: break; |
|
290 } |
|
291 |
|
292 return ETrue; // all queries accepted |
|
293 |
|
294 } |
|
295 else |
|
296 return EFalse; |
|
297 } |
|
298 else |
|
299 return EFalse; |
|
300 } |
|
301 else |
|
302 return EFalse; |
|
303 |
|
304 } |
|
305 // else |
|
306 return EFalse; |
|
307 } |
|
308 |
|
309 //---------------------------------------------------------------------------- |
|
310 |
|
311 TInt CCreatorMessages::CreateRandomMessageEntryL(TInt aCommand) |
|
312 { |
|
313 LOGSTRING2("Creator: CCreatorMessages::CreateRandomMessageEntryL - Command: %d", aCommand); |
|
314 |
|
315 TInt err = KErrNone; |
|
316 |
|
317 iDefinedMessageLength = iEngine->RandomNumber(100, 300); |
|
318 |
|
319 |
|
320 switch (aCommand) |
|
321 { |
|
322 case ECmdCreateRandomEntrySMSInbox: { iMessageType=ESMS; iFolderType=EInbox; err=CreateMessageEntryL(NULL); break;} |
|
323 case ECmdCreateRandomEntrySMSDrafts: { iMessageType=ESMS; iFolderType=EDrafts; err=CreateMessageEntryL(NULL); break;} |
|
324 case ECmdCreateRandomEntrySMSOutbox: { iMessageType=ESMS; iFolderType=EOutbox; err=CreateMessageEntryL(NULL); break;} |
|
325 case ECmdCreateRandomEntrySMSSent: { iMessageType=ESMS; iFolderType=ESent; err=CreateMessageEntryL(NULL); break;} |
|
326 |
|
327 case ECmdCreateRandomEntryMMSInbox: { iMessageType=EMMS; iFolderType=EInbox; err=CreateMessageEntryL(NULL); break;} |
|
328 case ECmdCreateRandomEntryMMSDrafts: { iMessageType=EMMS; iFolderType=EDrafts; err=CreateMessageEntryL(NULL); break;} |
|
329 case ECmdCreateRandomEntryMMSOutbox: { iMessageType=EMMS; iFolderType=EOutbox; err=CreateMessageEntryL(NULL); break;} |
|
330 case ECmdCreateRandomEntryMMSSent: { iMessageType=EMMS; iFolderType=ESent; err=CreateMessageEntryL(NULL); break;} |
|
331 |
|
332 case ECmdCreateRandomEntryEmailInbox: { iMessageType=EEmail; iFolderType=EInbox; err=CreateMessageEntryL(NULL); break;} |
|
333 case ECmdCreateRandomEntryEmailDrafts: { iMessageType=EEmail; iFolderType=EDrafts; err=CreateMessageEntryL(NULL); break;} |
|
334 case ECmdCreateRandomEntryEmailOutbox: { iMessageType=EEmail; iFolderType=EOutbox; err=CreateMessageEntryL(NULL); break;} |
|
335 case ECmdCreateRandomEntryEmailSent: { iMessageType=EEmail; iFolderType=ESent; err=CreateMessageEntryL(NULL); break;} |
|
336 |
|
337 case ECmdCreateRandomEntryBIOInbox: { iMessageType=ESmartMessage; iFolderType=EInbox; err=CreateMessageEntryL(NULL); break;} |
|
338 case ECmdCreateRandomEntryBIODrafts: { iMessageType=ESmartMessage; iFolderType=EDrafts; err=CreateMessageEntryL(NULL); break;} |
|
339 case ECmdCreateRandomEntryBIOOutbox: { iMessageType=ESmartMessage; iFolderType=EOutbox; err=CreateMessageEntryL(NULL); break;} |
|
340 case ECmdCreateRandomEntryBIOSent: { iMessageType=ESmartMessage; iFolderType=ESent; err=CreateMessageEntryL(NULL); break;} |
|
341 |
|
342 case ECmdCreateRandomEntryIRInbox: { iMessageType=EIrMessage; iFolderType=EInbox; iAttachments->Reset(); iAttachments->AppendL( iEngine->RandomNumber(CCreatorEngine::EJPEG_25kB, CCreatorEngine::LAST_FILE_ID-1) ); err=CreateMessageEntryL(NULL); break;} |
|
343 case ECmdCreateRandomEntryIRDrafts: { iMessageType=EIrMessage; iFolderType=EDrafts; iAttachments->Reset(); iAttachments->AppendL( iEngine->RandomNumber(CCreatorEngine::EJPEG_25kB, CCreatorEngine::LAST_FILE_ID-1) ); err=CreateMessageEntryL(NULL); break;} |
|
344 case ECmdCreateRandomEntryIROutbox: { iMessageType=EIrMessage; iFolderType=EOutbox; iAttachments->Reset(); iAttachments->AppendL( iEngine->RandomNumber(CCreatorEngine::EJPEG_25kB, CCreatorEngine::LAST_FILE_ID-1) ); err=CreateMessageEntryL(NULL); break;} |
|
345 case ECmdCreateRandomEntryIRSent: { iMessageType=EIrMessage; iFolderType=ESent; iAttachments->Reset(); iAttachments->AppendL( iEngine->RandomNumber(CCreatorEngine::EJPEG_25kB, CCreatorEngine::LAST_FILE_ID-1) ); err=CreateMessageEntryL(NULL); break;} |
|
346 |
|
347 case ECmdCreateRandomEntryBTInbox: { iMessageType=EBTMessage; iFolderType=EInbox; iAttachments->Reset(); iAttachments->AppendL( iEngine->RandomNumber(CCreatorEngine::EJPEG_25kB, CCreatorEngine::LAST_FILE_ID-1) ); err=CreateMessageEntryL(NULL); break;} |
|
348 case ECmdCreateRandomEntryBTDrafts: { iMessageType=EBTMessage; iFolderType=EDrafts; iAttachments->Reset(); iAttachments->AppendL( iEngine->RandomNumber(CCreatorEngine::EJPEG_25kB, CCreatorEngine::LAST_FILE_ID-1) ); err=CreateMessageEntryL(NULL); break;} |
|
349 case ECmdCreateRandomEntryBTOutbox: { iMessageType=EBTMessage; iFolderType=EOutbox; iAttachments->Reset(); iAttachments->AppendL( iEngine->RandomNumber(CCreatorEngine::EJPEG_25kB, CCreatorEngine::LAST_FILE_ID-1) ); err=CreateMessageEntryL(NULL); break;} |
|
350 case ECmdCreateRandomEntryBTSent: { iMessageType=EBTMessage; iFolderType=ESent; iAttachments->Reset(); iAttachments->AppendL( iEngine->RandomNumber(CCreatorEngine::EJPEG_25kB, CCreatorEngine::LAST_FILE_ID-1) ); err=CreateMessageEntryL(NULL); break;} |
|
351 |
|
352 case ECmdCreateRandomEntryAMSInbox: { iMessageType=EAMS; iFolderType=EInbox; iAttachments->Reset(); iAttachments->AppendL( CCreatorEngine::EMP3_250kB); err=CreateMessageEntryL(NULL); break;} |
|
353 case ECmdCreateRandomEntryAMSDrafts: { iMessageType=EAMS; iFolderType=EDrafts; iAttachments->Reset(); iAttachments->AppendL( CCreatorEngine::EMP3_250kB); err=CreateMessageEntryL(NULL); break;} |
|
354 case ECmdCreateRandomEntryAMSOutbox: { iMessageType=EAMS; iFolderType=EOutbox; iAttachments->Reset(); iAttachments->AppendL( CCreatorEngine::EMP3_250kB); err=CreateMessageEntryL(NULL); break;} |
|
355 case ECmdCreateRandomEntryAMSSent: { iMessageType=EAMS; iFolderType=ESent; iAttachments->Reset(); iAttachments->AppendL( CCreatorEngine::EMP3_250kB); err=CreateMessageEntryL(NULL); break;} |
|
356 |
|
357 default: { User::Panic(_L("MessageCommand"), 901); break;} |
|
358 } |
|
359 |
|
360 return err; |
|
361 } |
|
362 |
|
363 //---------------------------------------------------------------------------- |
|
364 |
|
365 TInt CCreatorMessages::CreateMessageEntryL(CMessagesParameters *aParameters, TBool /*aTakeUserGivenParameters*/) |
|
366 { |
|
367 LOGSTRING("Creator: CCreatorMessages::CreateMessageEntryL"); |
|
368 |
|
369 delete iParameters; |
|
370 iParameters = 0; |
|
371 |
|
372 CMessagesParameters* parameters = aParameters; |
|
373 |
|
374 // random data needed if no predefined data available |
|
375 if (!parameters) |
|
376 { |
|
377 iParameters = new(ELeave) CMessagesParameters; |
|
378 parameters = iParameters; |
|
379 // check if values from ui needed |
|
380 //if (aTakeUserGivenParameters) |
|
381 // { |
|
382 parameters->iMessageType = iMessageType; |
|
383 parameters->iFolderType = iFolderType; |
|
384 parameters->iDefinedMessageLength = iDefinedMessageLength; |
|
385 parameters->iCreateAsUnread = iCreateAsUnread; |
|
386 |
|
387 for (TInt i=0; i<iAttachments->Count(); i++) |
|
388 parameters->iAttachments->AppendL(iAttachments->At(i)); |
|
389 // } |
|
390 //else |
|
391 // { |
|
392 // message length |
|
393 // parameters->iDefinedMessageLength = iEngine->RandomNumber(100, 300); |
|
394 // } |
|
395 |
|
396 if (parameters->iMessageType == EEmail) |
|
397 { |
|
398 parameters->iSenderAddress->Des().Copy( iEngine->RandomString(CCreatorEngine::EFirstName) ); |
|
399 parameters->iSenderAddress->Des().Append( _L("@") ); |
|
400 parameters->iSenderAddress->Des().Append( iEngine->RandomString(CCreatorEngine::ECompany) ); |
|
401 parameters->iSenderAddress->Des().Append( _L(".com") ); |
|
402 |
|
403 parameters->iRecipientAddress->Des().Copy( iEngine->RandomString(CCreatorEngine::EFirstName) ); |
|
404 parameters->iRecipientAddress->Des().Append( _L("@") ); |
|
405 parameters->iRecipientAddress->Des().Append( iEngine->RandomString(CCreatorEngine::ECompany) ); |
|
406 parameters->iRecipientAddress->Des().Append( _L(".net") ); |
|
407 } |
|
408 else if (parameters->iMessageType == EIrMessage || parameters->iMessageType == EBTMessage) |
|
409 { |
|
410 parameters->iSenderAddress->Des().Copy( iEngine->RandomString(CCreatorEngine::EFirstName) ); |
|
411 parameters->iRecipientAddress->Des().Copy( iEngine->RandomString(CCreatorEngine::EFirstName) ); |
|
412 } |
|
413 else |
|
414 { |
|
415 parameters->iSenderAddress->Des().Copy( iEngine->RandomString(CCreatorEngine::EPhoneNumber) ); |
|
416 parameters->iRecipientAddress->Des().Copy( iEngine->RandomString(CCreatorEngine::EPhoneNumber) ); |
|
417 } |
|
418 |
|
419 // subject |
|
420 parameters->iMessageSubject->Des() = iEngine->RandomString(CCreatorEngine::EMessageSubject); |
|
421 |
|
422 // message body |
|
423 parameters->iMessageBodyText->Des().Copy(_L("")); |
|
424 TPtrC randText = iEngine->RandomString(CCreatorEngine::EMessageText); |
|
425 for (TInt i=0; i<parameters->iDefinedMessageLength / randText.Length() +1; i++) |
|
426 { |
|
427 parameters->iMessageBodyText->Des().Append( randText ); |
|
428 parameters->iMessageBodyText->Des().Append( _L(" ") ); |
|
429 } |
|
430 parameters->iMessageBodyText->Des() = parameters->iMessageBodyText->Des().Left(parameters->iDefinedMessageLength); |
|
431 |
|
432 // BIO message type (from bitsids.h) // TO-DO: add support for all BIO message types... |
|
433 parameters->iBIOMessageType = KUidBIOBusinessCardMsg; |
|
434 } |
|
435 |
|
436 |
|
437 |
|
438 TInt err = KErrNone; |
|
439 |
|
440 switch (parameters->iMessageType) |
|
441 { |
|
442 case ESMS: { err = CreateSMSEntryL(*parameters); break; } |
|
443 case EMMS: { err = CreateMMSEntryL(*parameters); break; } |
|
444 case EAMS: { err = CreateAMSEntryL(*parameters); break; } |
|
445 case EEmail: { err = CreateEmailEntryL(*parameters); break; } |
|
446 case ESmartMessage: { err = CreateSmartMessageEntryL(*parameters); break; } |
|
447 case EIrMessage: { err = CreateObexEntryL( TUid::Uid(KUidMsgTypeIrTInt32), *parameters ); break; } |
|
448 case EBTMessage: { err = CreateObexEntryL( TUid::Uid(KUidMsgTypeBtTInt32), *parameters ); break; } |
|
449 default: { User::Panic(_L("MsgType"), 851); break;} |
|
450 |
|
451 } |
|
452 |
|
453 iSenderArray.ResetAndDestroy(); |
|
454 iRecipientArray.ResetAndDestroy(); |
|
455 return err; |
|
456 } |
|
457 |
|
458 //---------------------------------------------------------------------------- |
|
459 |
|
460 TInt CCreatorMessages::CreateSMSEntryL(const CMessagesParameters& parameters) |
|
461 { |
|
462 LOGSTRING("Creator: CCreatorMessages::CreateSMSEntryL"); |
|
463 |
|
464 TInt err = KErrNone; |
|
465 |
|
466 |
|
467 // init |
|
468 CMsvSession* session = CMsvSession::OpenSyncL(*this); |
|
469 CleanupStack::PushL(session); |
|
470 CClientMtmRegistry* registry = CClientMtmRegistry::NewL(*session); |
|
471 CleanupStack::PushL(registry); |
|
472 |
|
473 // get the client mtm and return if it isn't supported in the system |
|
474 CSmsClientMtm* clientMtm = NULL; |
|
475 TRAP(err, clientMtm = static_cast<CSmsClientMtm*>(registry->NewMtmL(KUidMsgTypeSMS))); |
|
476 if (err || !clientMtm) |
|
477 { |
|
478 iEngine->GetEngineWrapper()->ShowErrorMessage(_L("SMS: Message type module not found")); |
|
479 CleanupStack::PopAndDestroy(2); |
|
480 User::Leave(KErrNotFound); |
|
481 } |
|
482 CleanupStack::PushL(clientMtm); |
|
483 |
|
484 // create a new object to access an existing entry |
|
485 CMsvEntry* msvEntry = CMsvEntry::NewL(*session, KMsvGlobalInBoxIndexEntryId, TMsvSelectionOrdering()); |
|
486 CleanupStack::PushL(msvEntry); |
|
487 |
|
488 // get default service |
|
489 TMsvId defaultServiceId = 0; |
|
490 TRAP(err, defaultServiceId = clientMtm->DefaultServiceL()); |
|
491 if (err) |
|
492 { |
|
493 iEngine->GetEngineWrapper()->ShowErrorMessage(_L("SMS: Define a SMS centre first")); |
|
494 CleanupStack::PopAndDestroy(2); |
|
495 User::Leave(KErrNotFound); |
|
496 } |
|
497 |
|
498 // set folder type |
|
499 switch (parameters.iFolderType) |
|
500 { |
|
501 case EInbox: { msvEntry->SetEntryL(KMsvGlobalInBoxIndexEntryId); break; } |
|
502 case EDrafts: { msvEntry->SetEntryL(KMsvDraftEntryId); break; } |
|
503 case EOutbox: { msvEntry->SetEntryL(KMsvGlobalOutBoxIndexEntryId); break; } |
|
504 case ESent: { msvEntry->SetEntryL(KMsvSentEntryId); break; } |
|
505 default: { User::Panic(_L("Folder Type"), 871); break; } |
|
506 } |
|
507 |
|
508 // mtm takes ownership of entry context |
|
509 CleanupStack::Pop(msvEntry); |
|
510 clientMtm->SetCurrentEntryL(msvEntry); |
|
511 |
|
512 // create a new message |
|
513 clientMtm->CreateMessageL(defaultServiceId); |
|
514 |
|
515 // set the from field to sms header |
|
516 if (parameters.iFolderType == EInbox) |
|
517 { |
|
518 CSmsHeader* smsHeader = &clientMtm->SmsHeader(); |
|
519 delete smsHeader; |
|
520 smsHeader = NULL; |
|
521 smsHeader = CSmsHeader::NewL(CSmsPDU::ESmsDeliver, clientMtm->Body()); |
|
522 if( parameters.iSenderAddress ) |
|
523 { |
|
524 smsHeader->SetFromAddressL( parameters.iSenderAddress->Des() ); |
|
525 } |
|
526 else |
|
527 { |
|
528 smsHeader->SetFromAddressL(KEmpty); |
|
529 } |
|
530 } |
|
531 |
|
532 // set body |
|
533 clientMtm->Body().Reset(); |
|
534 clientMtm->Body().InsertL(0, parameters.iMessageBodyText->Des()); |
|
535 |
|
536 // get the entry of the message |
|
537 TMsvEntry messageEntry = clientMtm->Entry().Entry(); |
|
538 |
|
539 // set the details field |
|
540 if (parameters.iFolderType == EInbox) |
|
541 { |
|
542 SetSenderToEntryDetails(messageEntry, parameters, EFalse); |
|
543 } |
|
544 else |
|
545 { |
|
546 SetRecipientToEntryDetails(messageEntry, parameters, EFalse); |
|
547 // Add all recipients to clientMtm |
|
548 // iRecipientArray is up-to-date so don't call AddRecipientsL here |
|
549 for( TInt i = 0; i < iRecipientArray.Count(); i++ ) |
|
550 { |
|
551 clientMtm->AddAddresseeL( iRecipientArray[i]->Des() ); |
|
552 } |
|
553 } |
|
554 |
|
555 // set the sending state for outbox message |
|
556 // to avoid SMSMtmUI:15 panic in messages application |
|
557 if (parameters.iFolderType == EOutbox ) |
|
558 { |
|
559 messageEntry.SetSendingState( KMsvSendStateWaiting ); |
|
560 } |
|
561 |
|
562 // set the description field same as the first part of the message body |
|
563 messageEntry.iDescription.Set( parameters.iMessageBodyText->Des().Left(KSmsDescriptionLength) ); |
|
564 |
|
565 // save the changes done above |
|
566 clientMtm->Entry().ChangeL(messageEntry); |
|
567 |
|
568 // save the message |
|
569 clientMtm->SaveMessageL(); |
|
570 |
|
571 // final fine tuning |
|
572 messageEntry.SetAttachment(EFalse); |
|
573 messageEntry.iDate.HomeTime(); |
|
574 messageEntry.SetVisible(ETrue); |
|
575 messageEntry.SetInPreparation(EFalse); |
|
576 |
|
577 if (parameters.iCreateAsUnread) |
|
578 { |
|
579 messageEntry.SetUnread(ETrue); |
|
580 messageEntry.SetNew(ETrue); |
|
581 } |
|
582 else |
|
583 { |
|
584 messageEntry.SetUnread(EFalse); |
|
585 messageEntry.SetNew(EFalse); |
|
586 } |
|
587 |
|
588 messageEntry.SetComplete(ETrue); |
|
589 messageEntry.iServiceId = defaultServiceId; |
|
590 messageEntry.iRelatedId = 0; |
|
591 clientMtm->Entry().ChangeL(messageEntry); |
|
592 |
|
593 // id has been generated, store it for being able to delete |
|
594 // only entries created with Creator |
|
595 iEntryIds.Append( messageEntry.Id() ); |
|
596 |
|
597 CleanupStack::PopAndDestroy(3); //session, registry, clientMtm |
|
598 |
|
599 return err; |
|
600 |
|
601 } |
|
602 |
|
603 //---------------------------------------------------------------------------- |
|
604 |
|
605 TInt CCreatorMessages::CreateMMSEntryL(const CMessagesParameters& parameters) |
|
606 { |
|
607 LOGSTRING("Creator: CCreatorMessages::CreateMMSEntryL"); |
|
608 |
|
609 TInt err = KErrNone; |
|
610 |
|
611 // init |
|
612 CMsvSession* session = CMsvSession::OpenSyncL(*this); |
|
613 CleanupStack::PushL(session); |
|
614 CClientMtmRegistry* registry = CClientMtmRegistry::NewL(*session); |
|
615 CleanupStack::PushL(registry); |
|
616 |
|
617 // get the client mtm and return if it isn't supported in the system |
|
618 CMmsClientMtm* clientMtm = NULL; |
|
619 TRAP(err, clientMtm = static_cast<CMmsClientMtm*>(registry->NewMtmL(KUidMsgTypeMultimedia))); |
|
620 if (err || !clientMtm) |
|
621 { |
|
622 iEngine->GetEngineWrapper()->ShowErrorMessage(_L("MMS: Message type module not found")); |
|
623 CleanupStack::PopAndDestroy(2); |
|
624 User::Leave(KErrNotFound); |
|
625 } |
|
626 CleanupStack::PushL(clientMtm); |
|
627 |
|
628 // create a new object to access an existing entry |
|
629 CMsvEntry* msvEntry = CMsvEntry::NewL(*session, KMsvGlobalInBoxIndexEntryId, TMsvSelectionOrdering()); |
|
630 CleanupStack::PushL(msvEntry); |
|
631 |
|
632 // get default service |
|
633 TMsvId defaultServiceId = 0; |
|
634 TRAP(err, defaultServiceId = clientMtm->DefaultServiceL()); |
|
635 if (err) |
|
636 { |
|
637 iEngine->GetEngineWrapper()->ShowErrorMessage(_L("MMS: Define MMS settings first")); |
|
638 CleanupStack::PopAndDestroy(4); |
|
639 User::Leave(KErrNotFound); |
|
640 } |
|
641 |
|
642 // set folder type |
|
643 switch (parameters.iFolderType) |
|
644 { |
|
645 case EInbox: { msvEntry->SetEntryL(KMsvGlobalInBoxIndexEntryId); break; } |
|
646 case EDrafts: { msvEntry->SetEntryL(KMsvDraftEntryId); break; } |
|
647 case EOutbox: { msvEntry->SetEntryL(KMsvGlobalOutBoxIndexEntryId); break; } |
|
648 case ESent: { msvEntry->SetEntryL(KMsvSentEntryId); break; } |
|
649 default: { User::Panic(_L("Folder Type"), 871); break; } |
|
650 } |
|
651 |
|
652 // mtm takes ownership of entry context |
|
653 CleanupStack::Pop(msvEntry); |
|
654 clientMtm->SetCurrentEntryL(msvEntry); |
|
655 |
|
656 // create a new message |
|
657 clientMtm->CreateMessageL(defaultServiceId); |
|
658 |
|
659 // set subject |
|
660 clientMtm->SetSubjectL( parameters.iMessageSubject->Des() ); |
|
661 |
|
662 // set some mms defaults |
|
663 clientMtm->SetMessageClass(EMmsClassPersonal); |
|
664 clientMtm->SetExpiryInterval(86400); |
|
665 clientMtm->SetDeliveryTimeInterval(3600); |
|
666 clientMtm->SetMessagePriority(EMmsPriorityLow); |
|
667 clientMtm->SetSenderVisibility(EMmsMaximumSenderVisibility); |
|
668 clientMtm->SetDeliveryReport(EMmsDeliveryReportYes); |
|
669 clientMtm->SetReadReply(EMmsReadReplyYes); |
|
670 |
|
671 // set the sender / addressee field |
|
672 if (parameters.iFolderType == EInbox) |
|
673 { |
|
674 AddMtmSenderL(*clientMtm, parameters, EFalse); |
|
675 } |
|
676 |
|
677 // Add all recipients to clientMtm |
|
678 AddRecipientsL( *clientMtm, parameters, EFalse ); |
|
679 |
|
680 // get an access to the message store |
|
681 CMsvStore* store = msvEntry->EditStoreL(); |
|
682 CleanupStack::PushL(store); |
|
683 |
|
684 |
|
685 // set body as an attachment |
|
686 CMsvMimeHeaders* mimeHeaders = CMsvMimeHeaders::NewL(); |
|
687 CleanupStack::PushL(mimeHeaders); |
|
688 mimeHeaders->SetContentTypeL( _L8("text") ); |
|
689 mimeHeaders->SetContentSubTypeL( _L8("plain") ); |
|
690 mimeHeaders->SetMimeCharset( KMmsUtf8 ); |
|
691 mimeHeaders->SetSuggestedFilenameL( _L("body.txt") ); |
|
692 |
|
693 MMsvAttachmentManager& attachMan = store->AttachmentManagerL(); |
|
694 CMsvAttachment* attachmentInfo = CMsvAttachment::NewL(CMsvAttachment::EMsvFile); // ownership of attachmentInfo will be transferred |
|
695 CleanupStack::PushL(attachmentInfo); |
|
696 attachmentInfo->SetAttachmentNameL( _L("body.txt") ); |
|
697 attachmentInfo->SetMimeTypeL( _L8("text/plain") ); |
|
698 mimeHeaders->StoreL( *attachmentInfo ); |
|
699 |
|
700 RFile textFile; |
|
701 |
|
702 CAsyncWaiter* waiter = CAsyncWaiter::NewLC(); |
|
703 attachMan.CreateAttachmentL(_L("body.txt"), textFile, attachmentInfo, waiter->iStatus ); |
|
704 CleanupStack::Pop(); // waiter |
|
705 CleanupStack::Pop(); // attachmentInfo |
|
706 CleanupStack::PushL(waiter); |
|
707 waiter->StartAndWait(); |
|
708 CleanupStack::PopAndDestroy(waiter); |
|
709 |
|
710 HBufC8* tempBuf = HBufC8::NewLC( parameters.iMessageBodyText->Des().Length() ); |
|
711 tempBuf->Des().Copy( parameters.iMessageBodyText->Des() ); |
|
712 textFile.Write( tempBuf->Des() ); |
|
713 textFile.Close(); |
|
714 CleanupStack::PopAndDestroy(); //tempBuf |
|
715 |
|
716 CleanupStack::PopAndDestroy(); //mimeHeaders |
|
717 |
|
718 |
|
719 // get the entry of the message |
|
720 TMsvEntry messageEntry = clientMtm->Entry().Entry(); |
|
721 |
|
722 // set the details field |
|
723 if (parameters.iFolderType == EInbox) |
|
724 { |
|
725 SetSenderToEntryDetails(messageEntry, parameters, EFalse); |
|
726 } |
|
727 else |
|
728 { |
|
729 SetRecipientToEntryDetails(messageEntry, parameters, EFalse); |
|
730 } |
|
731 |
|
732 // set the description field same as the message subject |
|
733 messageEntry.iDescription.Set( parameters.iMessageSubject->Des().Left(KSmsDescriptionLength) ); |
|
734 |
|
735 // save the changes done above |
|
736 clientMtm->Entry().ChangeL(messageEntry); |
|
737 |
|
738 |
|
739 // save the attachments |
|
740 HandleAttachementsL(parameters, store, err ); |
|
741 // for (TInt i=0; i<parameters.iAttachments->Count(); i++) |
|
742 // { |
|
743 // TFileName sourceFileName = iEngine->TestDataPathL( (CCreatorEngine::TTestDataPath) parameters.iAttachments->At(i) ); |
|
744 // |
|
745 // TParse parser; |
|
746 // parser.Set(sourceFileName, NULL, NULL); |
|
747 // TFileName shortFileName = parser.NameAndExt(); |
|
748 // |
|
749 // // get the mime type |
|
750 // RApaLsSession ls; |
|
751 // User::LeaveIfError(ls.Connect()); |
|
752 // CleanupClosePushL<RApaLsSession>(ls); |
|
753 // TUid appUid; |
|
754 // TDataType dataType; |
|
755 // ls.AppForDocument(sourceFileName, appUid, dataType); |
|
756 // CleanupStack::PopAndDestroy(); //ls |
|
757 // TPtrC8 mimeType = dataType.Des8(); |
|
758 // |
|
759 // // attachment settings |
|
760 // MMsvAttachmentManager& attachMan = store->AttachmentManagerL(); |
|
761 // CMsvAttachment* attachmentInfo = CMsvAttachment::NewL(CMsvAttachment::EMsvFile); // ownership of attachmentInfo will be transferred |
|
762 // attachmentInfo->SetAttachmentNameL( shortFileName ); |
|
763 // attachmentInfo->SetMimeTypeL( mimeType ); |
|
764 // |
|
765 // // save |
|
766 // CAsyncWaiter* waiter = CAsyncWaiter::NewLC(); |
|
767 // |
|
768 // TRAP(err, attachMan.AddAttachmentL(sourceFileName, attachmentInfo, waiter->iStatus )); |
|
769 // if (err == KErrNone) |
|
770 // waiter->StartAndWait(); |
|
771 // else |
|
772 // LOGSTRING2("Creator: CCreatorMessages::CreateMMSEntryL failed to attach %S", &sourceFileName); |
|
773 // |
|
774 // CleanupStack::PopAndDestroy(waiter); |
|
775 // } |
|
776 |
|
777 // save the changes made to the message store |
|
778 store->CommitL(); |
|
779 CleanupStack::PopAndDestroy(store); |
|
780 |
|
781 |
|
782 // save the message |
|
783 clientMtm->SaveMessageL(); |
|
784 |
|
785 // final fine tuning |
|
786 messageEntry.SetAttachment(ETrue); |
|
787 messageEntry.iDate.HomeTime(); |
|
788 messageEntry.SetVisible(ETrue); |
|
789 messageEntry.SetInPreparation(EFalse); |
|
790 if (parameters.iCreateAsUnread) |
|
791 { |
|
792 messageEntry.SetUnread(ETrue); |
|
793 messageEntry.SetNew(ETrue); |
|
794 } |
|
795 else |
|
796 { |
|
797 messageEntry.SetUnread(EFalse); |
|
798 messageEntry.SetNew(EFalse); |
|
799 } |
|
800 messageEntry.SetComplete(ETrue); |
|
801 messageEntry.iServiceId = defaultServiceId; |
|
802 messageEntry.iRelatedId = 0; |
|
803 |
|
804 if (parameters.iFolderType == EDrafts) |
|
805 messageEntry.SetReadOnly(EFalse); |
|
806 else |
|
807 messageEntry.SetReadOnly(ETrue); |
|
808 |
|
809 messageEntry.iMtmData1 = KMmsMessageMRetrieveConf | KMmsMessageMobileTerminated; |
|
810 |
|
811 clientMtm->Entry().ChangeL(messageEntry); |
|
812 |
|
813 // id has been generated, store it for being able to delete |
|
814 // only entries created with Creator |
|
815 iEntryIds.Append( messageEntry.Id() ); |
|
816 |
|
817 CleanupStack::PopAndDestroy(3); //session, registry, clientMtm |
|
818 |
|
819 |
|
820 return err; |
|
821 } |
|
822 |
|
823 //---------------------------------------------------------------------------- |
|
824 void CCreatorMessages::HandleAttachementsL(const CMessagesParameters& parameters, CMsvStore* store, TInt err ) |
|
825 { |
|
826 // save the attachments (added with id's) |
|
827 for (TInt i=0; i<parameters.iAttachments->Count(); i++) |
|
828 { |
|
829 TFileName sourceFileName = iEngine->TestDataPathL( (CCreatorEngine::TTestDataPath) parameters.iAttachments->At(i) ); |
|
830 HandleAttachementL(store, err, sourceFileName ); |
|
831 |
|
832 } |
|
833 //Adding attachmentpaths |
|
834 for (TInt i=0; i<parameters.iAttachmentPaths.Count(); i++) |
|
835 { |
|
836 HBufC* point = parameters.iAttachmentPaths[i]; |
|
837 TFileName sourceFileName(point->Des()); |
|
838 HandleAttachementL(store, err, sourceFileName ); |
|
839 } |
|
840 } |
|
841 //---------------------------------------------------------------------------- |
|
842 |
|
843 void CCreatorMessages::HandleAttachementL(CMsvStore* store, TInt err, TFileName& sourceFileName ) |
|
844 { |
|
845 TParse parser; |
|
846 parser.Set(sourceFileName, NULL, NULL); |
|
847 TFileName shortFileName = parser.NameAndExt(); |
|
848 |
|
849 // get the mime type |
|
850 RApaLsSession ls; |
|
851 User::LeaveIfError(ls.Connect()); |
|
852 CleanupClosePushL<RApaLsSession>(ls); |
|
853 TUid appUid; |
|
854 TDataType dataType; |
|
855 ls.AppForDocument(sourceFileName, appUid, dataType); |
|
856 CleanupStack::PopAndDestroy(); //ls |
|
857 TPtrC8 mimeType = dataType.Des8(); |
|
858 |
|
859 // attachment settings |
|
860 MMsvAttachmentManager& attachMan = store->AttachmentManagerL(); |
|
861 CMsvAttachment* attachmentInfo = CMsvAttachment::NewL(CMsvAttachment::EMsvFile); // ownership of attachmentInfo will be transferred |
|
862 CleanupStack::PushL(attachmentInfo); |
|
863 attachmentInfo->SetAttachmentNameL( shortFileName ); |
|
864 attachmentInfo->SetMimeTypeL( mimeType ); |
|
865 |
|
866 if ( mimeType == _L8("text/plain") ) |
|
867 { |
|
868 // CMsvMimeHeaders needs to be stored in case of text file |
|
869 CMsvMimeHeaders* mimeHeaders = CMsvMimeHeaders::NewL(); |
|
870 CleanupStack::PushL(mimeHeaders); |
|
871 mimeHeaders->SetContentTypeL( _L8("text") ); |
|
872 mimeHeaders->SetContentSubTypeL( _L8("plain") ); |
|
873 mimeHeaders->SetMimeCharset( KMmsUtf8 ); |
|
874 mimeHeaders->StoreL( *attachmentInfo ); |
|
875 CleanupStack::PopAndDestroy( mimeHeaders ); |
|
876 } |
|
877 |
|
878 // save |
|
879 |
|
880 CAsyncWaiter* waiter = CAsyncWaiter::NewLC(); |
|
881 TRAP(err, attachMan.AddAttachmentL(sourceFileName, attachmentInfo, waiter->iStatus )); |
|
882 if (err == KErrNone) |
|
883 { |
|
884 waiter->StartAndWait(); |
|
885 CleanupStack::PopAndDestroy(waiter); |
|
886 CleanupStack::Pop(); // attachmentInfo, the ownership is transferred |
|
887 } |
|
888 else |
|
889 { |
|
890 CleanupStack::PopAndDestroy(waiter); |
|
891 CleanupStack::PopAndDestroy(); // attachmentInfo, ownership is not transferred (leave occurs) |
|
892 LOGSTRING2("Creator: CCreatorMessages::HandleAttachementsL failed to attach %S", &sourceFileName); |
|
893 } |
|
894 } |
|
895 //---------------------------------------------------------------------------- |
|
896 |
|
897 TInt CCreatorMessages::CreateAMSEntryL(const CMessagesParameters& parameters) |
|
898 { |
|
899 LOGSTRING("Creator: CCreatorMessages::CreateAMSEntryL"); |
|
900 |
|
901 TInt err = KErrNone; |
|
902 |
|
903 |
|
904 // init |
|
905 CMsvSession* session = CMsvSession::OpenSyncL(*this); |
|
906 CleanupStack::PushL(session); |
|
907 CClientMtmRegistry* registry = CClientMtmRegistry::NewL(*session); |
|
908 CleanupStack::PushL(registry); |
|
909 |
|
910 // get the client mtm and return if it isn't supported in the system |
|
911 CMmsClientMtm* clientMtm = NULL; |
|
912 TRAP(err, clientMtm = static_cast<CMmsClientMtm*>(registry->NewMtmL(KUidMsgTypeMultimedia))); |
|
913 if (err || !clientMtm) |
|
914 { |
|
915 iEngine->GetEngineWrapper()->ShowErrorMessage(_L("MMS: Message type module not found")); |
|
916 CleanupStack::PopAndDestroy(2); |
|
917 User::Leave(KErrNotFound); |
|
918 } |
|
919 CleanupStack::PushL(clientMtm); |
|
920 |
|
921 // create a new object to access an existing entry |
|
922 CMsvEntry* msvEntry = CMsvEntry::NewL(*session, KMsvGlobalInBoxIndexEntryId, TMsvSelectionOrdering()); |
|
923 CleanupStack::PushL(msvEntry); |
|
924 |
|
925 // get default service |
|
926 TMsvId defaultServiceId = 0; |
|
927 TRAP(err, defaultServiceId = clientMtm->DefaultServiceL()); |
|
928 if (err) |
|
929 { |
|
930 iEngine->GetEngineWrapper()->ShowErrorMessage(_L("MMS: Define MMS settings first")); |
|
931 CleanupStack::PopAndDestroy(2); |
|
932 User::Leave(KErrNotFound); |
|
933 } |
|
934 |
|
935 // set folder type |
|
936 switch (parameters.iFolderType) |
|
937 { |
|
938 case EInbox: { msvEntry->SetEntryL(KMsvGlobalInBoxIndexEntryId); break; } |
|
939 case EDrafts: { msvEntry->SetEntryL(KMsvDraftEntryId); break; } |
|
940 case EOutbox: { msvEntry->SetEntryL(KMsvGlobalOutBoxIndexEntryId); break; } |
|
941 case ESent: { msvEntry->SetEntryL(KMsvSentEntryId); break; } |
|
942 default: { User::Panic(_L("Folder Type"), 871); break; } |
|
943 } |
|
944 |
|
945 // mtm takes ownership of entry context |
|
946 CleanupStack::Pop(msvEntry); |
|
947 clientMtm->SetCurrentEntryL(msvEntry); |
|
948 |
|
949 // create a new message |
|
950 clientMtm->CreateMessageL(defaultServiceId); |
|
951 |
|
952 // set subject |
|
953 clientMtm->SetSubjectL(parameters.iMessageSubject->Des() ); |
|
954 |
|
955 // set some mms defaults |
|
956 clientMtm->SetMessageClass(EMmsClassPersonal); |
|
957 clientMtm->SetExpiryInterval(86400); |
|
958 clientMtm->SetDeliveryTimeInterval(3600); |
|
959 clientMtm->SetMessagePriority(EMmsPriorityLow); |
|
960 clientMtm->SetSenderVisibility(EMmsMaximumSenderVisibility); |
|
961 clientMtm->SetDeliveryReport(EMmsDeliveryReportYes); |
|
962 clientMtm->SetReadReply(EMmsReadReplyYes); |
|
963 |
|
964 // set the sender / addressee field |
|
965 if (parameters.iFolderType == EInbox) |
|
966 { |
|
967 AddMtmSenderL(*clientMtm, parameters, EFalse); |
|
968 } |
|
969 |
|
970 // Add all recipients to clientMtm |
|
971 AddRecipientsL( *clientMtm, parameters, EFalse ); |
|
972 |
|
973 |
|
974 // get an access to the message store |
|
975 CMsvStore* store = msvEntry->EditStoreL(); |
|
976 CleanupStack::PushL(store); |
|
977 |
|
978 // get the entry of the message |
|
979 TMsvEntry messageEntry = clientMtm->Entry().Entry(); |
|
980 |
|
981 // set the details field |
|
982 if (parameters.iFolderType == EInbox) |
|
983 { |
|
984 SetSenderToEntryDetails(messageEntry, parameters, EFalse); |
|
985 } |
|
986 else |
|
987 { |
|
988 SetRecipientToEntryDetails(messageEntry, parameters, EFalse); |
|
989 } |
|
990 |
|
991 // set the description field same as the message subject |
|
992 messageEntry.iDescription.Set( parameters.iMessageSubject->Des().Left(KSmsDescriptionLength) ); |
|
993 messageEntry.iBioType = KUidMsgSubTypeMmsAudioMsg.iUid; |
|
994 |
|
995 // save the changes done above |
|
996 clientMtm->Entry().ChangeL(messageEntry); |
|
997 |
|
998 |
|
999 TFileName sourceFileName = iEngine->TestDataPathL( CCreatorEngine::EAMR_20kB ); |
|
1000 TParse parser; |
|
1001 parser.Set(sourceFileName, NULL, NULL); |
|
1002 TFileName shortFileName = parser.NameAndExt(); |
|
1003 |
|
1004 // get the mime type |
|
1005 RApaLsSession ls; |
|
1006 User::LeaveIfError(ls.Connect()); |
|
1007 CleanupClosePushL<RApaLsSession>(ls); |
|
1008 TUid appUid; |
|
1009 TDataType dataType; |
|
1010 ls.AppForDocument(sourceFileName, appUid, dataType); |
|
1011 CleanupStack::PopAndDestroy(); //ls |
|
1012 TPtrC8 mimeType = dataType.Des8(); |
|
1013 |
|
1014 // attachment settings |
|
1015 MMsvAttachmentManager& attachMan = store->AttachmentManagerL(); |
|
1016 CMsvAttachment* attachmentInfo = CMsvAttachment::NewL(CMsvAttachment::EMsvFile); // ownership of attachmentInfo will be transferred |
|
1017 attachmentInfo->SetAttachmentNameL( shortFileName ); |
|
1018 attachmentInfo->SetMimeTypeL( mimeType ); |
|
1019 |
|
1020 // save |
|
1021 CAsyncWaiter* waiter = CAsyncWaiter::NewLC(); |
|
1022 |
|
1023 TRAP(err, attachMan.AddAttachmentL(sourceFileName, attachmentInfo, waiter->iStatus )); |
|
1024 if (err == KErrNone) |
|
1025 waiter->StartAndWait(); |
|
1026 else |
|
1027 LOGSTRING2("Creator: CCreatorMessages::CreateAMSEntryL failed to attach %S", &sourceFileName); |
|
1028 |
|
1029 CleanupStack::PopAndDestroy(waiter); |
|
1030 |
|
1031 // save the changes made to the message store |
|
1032 store->CommitL(); |
|
1033 CleanupStack::PopAndDestroy(store); |
|
1034 |
|
1035 |
|
1036 // save the message |
|
1037 clientMtm->SaveMessageL(); |
|
1038 |
|
1039 // final fine tuning |
|
1040 messageEntry.SetAttachment(ETrue); |
|
1041 messageEntry.iDate.HomeTime(); |
|
1042 messageEntry.SetVisible(ETrue); |
|
1043 messageEntry.SetInPreparation(EFalse); |
|
1044 if (parameters.iCreateAsUnread) |
|
1045 { |
|
1046 messageEntry.SetUnread(ETrue); |
|
1047 messageEntry.SetNew(ETrue); |
|
1048 } |
|
1049 else |
|
1050 { |
|
1051 messageEntry.SetUnread(EFalse); |
|
1052 messageEntry.SetNew(EFalse); |
|
1053 } |
|
1054 messageEntry.SetComplete(ETrue); |
|
1055 messageEntry.iServiceId = defaultServiceId; |
|
1056 messageEntry.iRelatedId = 0; |
|
1057 |
|
1058 if (parameters.iFolderType == EDrafts) |
|
1059 messageEntry.SetReadOnly(EFalse); |
|
1060 else |
|
1061 messageEntry.SetReadOnly(ETrue); |
|
1062 |
|
1063 messageEntry.iMtmData1 = KMmsMessageMRetrieveConf | KMmsMessageMobileTerminated; |
|
1064 |
|
1065 clientMtm->Entry().ChangeL(messageEntry); |
|
1066 |
|
1067 // id has been generated, store it for being able to delete |
|
1068 // only entries created with Creator |
|
1069 iEntryIds.Append( messageEntry.Id() ); |
|
1070 |
|
1071 CleanupStack::PopAndDestroy(3); //session, registry, clientMtm |
|
1072 |
|
1073 |
|
1074 return err; |
|
1075 } |
|
1076 |
|
1077 //---------------------------------------------------------------------------- |
|
1078 |
|
1079 TInt CCreatorMessages::CreateEmailEntryL(const CMessagesParameters& parameters) |
|
1080 { |
|
1081 LOGSTRING("Creator: CCreatorMessages::CreateEmailEntryL"); |
|
1082 |
|
1083 TInt err = KErrNone; |
|
1084 |
|
1085 // init |
|
1086 CMsvSession* session = CMsvSession::OpenSyncL(*this); |
|
1087 CleanupStack::PushL(session); |
|
1088 CClientMtmRegistry* registry = CClientMtmRegistry::NewL(*session); |
|
1089 CleanupStack::PushL(registry); |
|
1090 |
|
1091 // get the client mtm and return if it isn't supported in the system |
|
1092 CSmtpClientMtm* clientMtm = NULL; |
|
1093 TRAP(err, clientMtm = static_cast<CSmtpClientMtm*>(registry->NewMtmL(KUidMsgTypeSMTP))); |
|
1094 |
|
1095 if (err || !clientMtm) |
|
1096 { |
|
1097 iEngine->GetEngineWrapper()->ShowErrorMessage(_L("Email: Message type module not found")); |
|
1098 CleanupStack::PopAndDestroy(2); |
|
1099 User::Leave(KErrNotFound); |
|
1100 } |
|
1101 CleanupStack::PushL(clientMtm); |
|
1102 |
|
1103 // create a new object to access an existing entry |
|
1104 CMsvEntry* msvEntry = CMsvEntry::NewL(*session, KMsvGlobalInBoxIndexEntryId, TMsvSelectionOrdering()); |
|
1105 CleanupStack::PushL(msvEntry); |
|
1106 |
|
1107 // get default service |
|
1108 TMsvId defaultServiceId(0); |
|
1109 TRAP(err, defaultServiceId = clientMtm->DefaultServiceL()); |
|
1110 if (err) |
|
1111 { |
|
1112 iEngine->GetEngineWrapper()->ShowErrorMessage(_L("Email: Define a mailbox first")); |
|
1113 CleanupStack::PopAndDestroy(2); |
|
1114 User::Leave(KErrNotFound); |
|
1115 } |
|
1116 |
|
1117 // set folder type |
|
1118 switch (parameters.iFolderType) |
|
1119 { |
|
1120 case EInbox: { msvEntry->SetEntryL(KMsvGlobalInBoxIndexEntryId); break; } |
|
1121 case EDrafts: { msvEntry->SetEntryL(KMsvDraftEntryId); break; } |
|
1122 case EOutbox: { msvEntry->SetEntryL(KMsvGlobalOutBoxIndexEntryId); break; } |
|
1123 case ESent: { msvEntry->SetEntryL(KMsvSentEntryId); break; } |
|
1124 case EMailbox: { msvEntry->SetEntryL(iUserSelectedMailbox); break; } |
|
1125 default: { User::Panic(_L("Folder Type"), 871); break; } |
|
1126 } |
|
1127 |
|
1128 // mtm takes ownership of entry context |
|
1129 CleanupStack::Pop(msvEntry); |
|
1130 clientMtm->SetCurrentEntryL(msvEntry); |
|
1131 |
|
1132 // create a new message |
|
1133 clientMtm->CreateMessageL(defaultServiceId); |
|
1134 |
|
1135 // set subject |
|
1136 clientMtm->SetSubjectL( parameters.iMessageSubject->Des() ); |
|
1137 |
|
1138 // set body |
|
1139 clientMtm->Body().Reset(); |
|
1140 clientMtm->Body().InsertL(0, parameters.iMessageBodyText->Des()); |
|
1141 |
|
1142 // get the entry of the message |
|
1143 TMsvEntry messageEntry = clientMtm->Entry().Entry(); |
|
1144 |
|
1145 // set the address fields |
|
1146 if (parameters.iFolderType == EInbox) |
|
1147 { |
|
1148 AddSenderToMtmAddresseeL(*clientMtm, parameters, ETrue ); |
|
1149 SetSenderToEntryDetails(messageEntry, parameters, ETrue); |
|
1150 messageEntry.iMtm = KUidMsgTypeIMAP4; // or any other than KUidMsgTypeSMTP to display 'from' field instead of 'to' field |
|
1151 } |
|
1152 else |
|
1153 { |
|
1154 // Add all recipients to clientMtm |
|
1155 AddRecipientsL( *clientMtm, parameters, ETrue ); |
|
1156 SetRecipientToEntryDetails(messageEntry, parameters, EFalse); |
|
1157 } |
|
1158 |
|
1159 // set the description field same as the message subject |
|
1160 messageEntry.iDescription.Set( parameters.iMessageSubject->Des().Left(KSmsDescriptionLength) ); |
|
1161 |
|
1162 // save the changes done above |
|
1163 clientMtm->Entry().ChangeL(messageEntry); |
|
1164 |
|
1165 // get an access to the message store |
|
1166 CMsvStore* store = msvEntry->EditStoreL(); |
|
1167 CleanupStack::PushL(store); |
|
1168 |
|
1169 // save the attachments |
|
1170 HandleAttachementsL(parameters, store, err); |
|
1171 // for (TInt i=0; i<parameters.iAttachments->Count(); i++) |
|
1172 // { |
|
1173 // TFileName sourceFileName = iEngine->TestDataPathL( (CCreatorEngine::TTestDataPath) parameters.iAttachments->At(i) ); |
|
1174 // |
|
1175 // TParse parser; |
|
1176 // parser.Set(sourceFileName, NULL, NULL); |
|
1177 // TFileName shortFileName = parser.NameAndExt(); |
|
1178 // |
|
1179 // // get the mime type |
|
1180 // RApaLsSession ls; |
|
1181 // User::LeaveIfError(ls.Connect()); |
|
1182 // CleanupClosePushL<RApaLsSession>(ls); |
|
1183 // TUid appUid; |
|
1184 // TDataType dataType; |
|
1185 // ls.AppForDocument(sourceFileName, appUid, dataType); |
|
1186 // CleanupStack::PopAndDestroy(); //ls |
|
1187 // TPtrC8 mimeType = dataType.Des8(); |
|
1188 // |
|
1189 // // attachment settings |
|
1190 // MMsvAttachmentManager& attachMan = store->AttachmentManagerL(); |
|
1191 // CMsvAttachment* attachmentInfo = CMsvAttachment::NewL(CMsvAttachment::EMsvFile); // ownership of attachmentInfo will be transferred |
|
1192 // attachmentInfo->SetAttachmentNameL( shortFileName ); |
|
1193 // attachmentInfo->SetMimeTypeL( mimeType ); |
|
1194 // |
|
1195 // // save |
|
1196 // CAsyncWaiter* waiter = CAsyncWaiter::NewLC(); |
|
1197 // |
|
1198 // TRAP(err, attachMan.AddAttachmentL(sourceFileName, attachmentInfo, waiter->iStatus )); |
|
1199 // if (err == KErrNone) |
|
1200 // waiter->StartAndWait(); |
|
1201 // else |
|
1202 // LOGSTRING2("Creator: CCreatorMessages::CreateEmailEntryL failed to attach %S", &sourceFileName); |
|
1203 // |
|
1204 // CleanupStack::PopAndDestroy(waiter); |
|
1205 // } |
|
1206 |
|
1207 // save the changes made to the message store |
|
1208 store->CommitL(); |
|
1209 CleanupStack::PopAndDestroy(store); |
|
1210 |
|
1211 // save the message |
|
1212 clientMtm->SaveMessageL(); |
|
1213 |
|
1214 // final fine tuning |
|
1215 TMsvEmailEntry temailEntry = static_cast<TMsvEmailEntry>(messageEntry); |
|
1216 temailEntry.SetMessageFolderType(EFolderTypeUnknown); |
|
1217 temailEntry.SetDisconnectedOperation(ENoDisconnectedOperations); |
|
1218 temailEntry.SetEncrypted(EFalse); |
|
1219 temailEntry.SetSigned(EFalse); |
|
1220 temailEntry.SetVCard(EFalse); |
|
1221 temailEntry.SetVCalendar(EFalse); |
|
1222 temailEntry.SetReceipt(EFalse); |
|
1223 temailEntry.SetMHTMLEmail(EFalse); |
|
1224 temailEntry.SetBodyTextComplete(ETrue); |
|
1225 |
|
1226 if (parameters.iAttachments->Count() > 0) |
|
1227 temailEntry.SetAttachment(ETrue); |
|
1228 else |
|
1229 temailEntry.SetAttachment(EFalse); |
|
1230 |
|
1231 temailEntry.iDate.HomeTime(); |
|
1232 temailEntry.SetVisible(ETrue); |
|
1233 temailEntry.SetInPreparation(EFalse); |
|
1234 if (parameters.iCreateAsUnread) |
|
1235 { |
|
1236 temailEntry.SetUnread(ETrue); |
|
1237 temailEntry.SetNew(ETrue); |
|
1238 } |
|
1239 else |
|
1240 { |
|
1241 temailEntry.SetUnread(EFalse); |
|
1242 temailEntry.SetNew(EFalse); |
|
1243 } |
|
1244 temailEntry.SetComplete(ETrue); |
|
1245 temailEntry.iServiceId = defaultServiceId; |
|
1246 temailEntry.iRelatedId = 0; |
|
1247 |
|
1248 clientMtm->Entry().ChangeL(temailEntry); |
|
1249 |
|
1250 // reset email headers |
|
1251 CImHeader* header = CImHeader::NewLC(); |
|
1252 CMsvStore* msvStore = msvEntry->EditStoreL(); |
|
1253 CleanupStack::PushL(msvStore); |
|
1254 header->RestoreL(*msvStore); |
|
1255 header->SetSubjectL( parameters.iMessageSubject->Des() ); |
|
1256 if( iSenderArray.Count() == 0 ) |
|
1257 { |
|
1258 GetSendersL(iSenderArray, parameters, ETrue, 1 ); |
|
1259 } |
|
1260 |
|
1261 if( iSenderArray.Count() > 0 ) |
|
1262 { |
|
1263 header->SetFromL(iSenderArray[0]->Des()); |
|
1264 } |
|
1265 else |
|
1266 { |
|
1267 header->SetFromL( parameters.iSenderAddress->Des() ); |
|
1268 } |
|
1269 if( parameters.iRecipientAddress->Length() > 0 ) |
|
1270 { |
|
1271 header->SetReceiptAddressL( parameters.iRecipientAddress->Des() ); |
|
1272 } |
|
1273 else if( parameters.iRecipientAddressArray.Count() > 0 ) |
|
1274 { |
|
1275 header->SetReceiptAddressL( parameters.iRecipientAddressArray[0]->Des()); |
|
1276 } |
|
1277 |
|
1278 header->StoreL( *msvStore ); |
|
1279 msvStore->CommitL(); |
|
1280 CleanupStack::PopAndDestroy(2); // msvStore, header |
|
1281 |
|
1282 // id has been generated, store it for being able to delete |
|
1283 // only entries created with Creator |
|
1284 iEntryIds.Append( messageEntry.Id() ); |
|
1285 |
|
1286 CleanupStack::PopAndDestroy(3); //session, registry, clientMtm |
|
1287 |
|
1288 return err; |
|
1289 } |
|
1290 |
|
1291 //---------------------------------------------------------------------------- |
|
1292 |
|
1293 TInt CCreatorMessages::CreateSmartMessageEntryL(const CMessagesParameters& parameters) |
|
1294 { |
|
1295 LOGSTRING("Creator: CCreatorMessages::CreateSmartMessageEntryL"); |
|
1296 |
|
1297 TInt err = KErrNone; |
|
1298 |
|
1299 // init |
|
1300 CMsvSession* session = CMsvSession::OpenSyncL(*this); |
|
1301 CleanupStack::PushL(session); |
|
1302 CClientMtmRegistry* registry = CClientMtmRegistry::NewL(*session); |
|
1303 CleanupStack::PushL(registry); |
|
1304 |
|
1305 // get the client mtm and return if it isn't supported in the system |
|
1306 CSmsClientMtm* clientMtm = NULL; |
|
1307 TRAP(err, clientMtm = static_cast<CSmsClientMtm*>(registry->NewMtmL(KUidMsgTypeSMS))); |
|
1308 if (err || !clientMtm) |
|
1309 { |
|
1310 iEngine->GetEngineWrapper()->ShowErrorMessage(_L("BIO: Message type module not found")); |
|
1311 CleanupStack::PopAndDestroy(2); |
|
1312 User::Leave(KErrNotFound); |
|
1313 } |
|
1314 CleanupStack::PushL(clientMtm); |
|
1315 |
|
1316 // create a new object to access an existing entry |
|
1317 CMsvEntry* msvEntry = CMsvEntry::NewL(*session, KMsvGlobalInBoxIndexEntryId, TMsvSelectionOrdering()); |
|
1318 CleanupStack::PushL(msvEntry); |
|
1319 |
|
1320 // get default service |
|
1321 TMsvId defaultServiceId = 0; |
|
1322 TRAP(err, defaultServiceId = clientMtm->DefaultServiceL()); |
|
1323 if (err) |
|
1324 { |
|
1325 iEngine->GetEngineWrapper()->ShowErrorMessage(_L("SMS: Define a SMS centre first")); |
|
1326 CleanupStack::PopAndDestroy(2); |
|
1327 User::Leave(KErrNotFound); |
|
1328 } |
|
1329 |
|
1330 // set folder type |
|
1331 switch (parameters.iFolderType) |
|
1332 { |
|
1333 case EInbox: { msvEntry->SetEntryL(KMsvGlobalInBoxIndexEntryId); break; } |
|
1334 case EDrafts: { msvEntry->SetEntryL(KMsvDraftEntryId); break; } |
|
1335 case EOutbox: { msvEntry->SetEntryL(KMsvGlobalOutBoxIndexEntryId); break; } |
|
1336 case ESent: { msvEntry->SetEntryL(KMsvSentEntryId); break; } |
|
1337 default: { User::Panic(_L("Folder Type"), 871); break; } |
|
1338 } |
|
1339 |
|
1340 // mtm takes ownership of entry context |
|
1341 CleanupStack::Pop(msvEntry); |
|
1342 clientMtm->SetCurrentEntryL(msvEntry); |
|
1343 |
|
1344 // create a new message |
|
1345 clientMtm->CreateMessageL(defaultServiceId); |
|
1346 |
|
1347 // set the from field to sms header |
|
1348 if (parameters.iFolderType == EInbox) |
|
1349 { |
|
1350 CSmsHeader* smsHeader = &clientMtm->SmsHeader(); |
|
1351 delete smsHeader; |
|
1352 smsHeader = NULL; |
|
1353 smsHeader = CSmsHeader::NewL(CSmsPDU::ESmsDeliver, clientMtm->Body()); |
|
1354 if( parameters.iSenderAddress ) |
|
1355 { |
|
1356 smsHeader->SetFromAddressL( parameters.iSenderAddress->Des() ); |
|
1357 } |
|
1358 else |
|
1359 { |
|
1360 smsHeader->SetFromAddressL(KEmpty); |
|
1361 } |
|
1362 } |
|
1363 |
|
1364 // set body, the BIO message itself |
|
1365 clientMtm->Body().Reset(); |
|
1366 clientMtm->Body().InsertL(0, _L("Business Card\nTester Mike\nThe Company Ltd.\nSoftware Engineer\ntel +358 66 1234567\n")); |
|
1367 |
|
1368 // get the entry of the message |
|
1369 TMsvEntry messageEntry = clientMtm->Entry().Entry(); |
|
1370 |
|
1371 // TO-DO: Add support for all BIO messages, currently just insert a business card message ... : |
|
1372 // set the message type |
|
1373 // parameters.iBIOMessageType ... |
|
1374 clientMtm->BioTypeChangedL(KUidBIOBusinessCardMsg); |
|
1375 messageEntry.iBioType = KUidBIOBusinessCardMsg.iUid; |
|
1376 |
|
1377 // set the details field |
|
1378 if (parameters.iFolderType == EInbox) |
|
1379 { |
|
1380 SetSenderToEntryDetails(messageEntry, parameters, EFalse); |
|
1381 } |
|
1382 else |
|
1383 { |
|
1384 SetRecipientToEntryDetails(messageEntry, parameters, EFalse); |
|
1385 } |
|
1386 |
|
1387 // set the subject line |
|
1388 messageEntry.iDescription.Set( parameters.iMessageSubject->Des().Left(KSmsDescriptionLength) ); |
|
1389 |
|
1390 // set correct MTM type |
|
1391 messageEntry.iMtm= KUidBIOMessageTypeMtm; |
|
1392 |
|
1393 // save the changes done above |
|
1394 clientMtm->Entry().ChangeL(messageEntry); |
|
1395 |
|
1396 // save the message |
|
1397 clientMtm->SaveMessageL(); |
|
1398 |
|
1399 // final fine tuning |
|
1400 messageEntry.SetAttachment(EFalse); |
|
1401 messageEntry.iDate.HomeTime(); |
|
1402 messageEntry.SetVisible(ETrue); |
|
1403 messageEntry.SetInPreparation(EFalse); |
|
1404 if (parameters.iCreateAsUnread) |
|
1405 { |
|
1406 messageEntry.SetUnread(ETrue); |
|
1407 messageEntry.SetNew(ETrue); |
|
1408 } |
|
1409 else |
|
1410 { |
|
1411 messageEntry.SetUnread(EFalse); |
|
1412 messageEntry.SetNew(EFalse); |
|
1413 } |
|
1414 messageEntry.SetComplete(ETrue); |
|
1415 messageEntry.iServiceId = defaultServiceId; |
|
1416 messageEntry.iRelatedId = 0; |
|
1417 clientMtm->Entry().ChangeL(messageEntry); |
|
1418 |
|
1419 // id has been generated, store it for being able to delete |
|
1420 // only entries created with Creator |
|
1421 iEntryIds.Append( messageEntry.Id() ); |
|
1422 |
|
1423 CleanupStack::PopAndDestroy(3); //session, registry, clientMtm |
|
1424 |
|
1425 |
|
1426 return err; |
|
1427 } |
|
1428 |
|
1429 //---------------------------------------------------------------------------- |
|
1430 |
|
1431 TInt CCreatorMessages::CreateObexEntryL(TUid aMtm, const CMessagesParameters& parameters) |
|
1432 { |
|
1433 LOGSTRING("Creator: CCreatorMessages::CreateObexEntryL"); |
|
1434 |
|
1435 TInt err = KErrNone; |
|
1436 |
|
1437 // init |
|
1438 CMsvSession* session = CMsvSession::OpenSyncL(*this); |
|
1439 CleanupStack::PushL(session); |
|
1440 CClientMtmRegistry* registry = CClientMtmRegistry::NewL(*session); |
|
1441 CleanupStack::PushL(registry); |
|
1442 |
|
1443 // get the client mtm and return if it isn't supported in the system |
|
1444 CObexClientMtm* clientMtm = NULL; |
|
1445 TRAP(err, clientMtm = static_cast<CObexClientMtm*>(registry->NewMtmL(aMtm))); |
|
1446 if (err || !clientMtm) |
|
1447 { |
|
1448 iEngine->GetEngineWrapper()->ShowErrorMessage(_L("Obex: Message type module not found")); |
|
1449 CleanupStack::PopAndDestroy(2); |
|
1450 User::Leave(KErrNotFound); |
|
1451 } |
|
1452 CleanupStack::PushL(clientMtm); |
|
1453 |
|
1454 // create a new object to access an existing entry |
|
1455 CMsvEntry* msvEntry = CMsvEntry::NewL(*session, KMsvGlobalInBoxIndexEntryId, TMsvSelectionOrdering()); |
|
1456 CleanupStack::PushL(msvEntry); |
|
1457 |
|
1458 // define default service |
|
1459 TMsvId defaultServiceId = 0; |
|
1460 |
|
1461 // set folder type |
|
1462 switch (parameters.iFolderType) |
|
1463 { |
|
1464 case EInbox: { msvEntry->SetEntryL(KMsvGlobalInBoxIndexEntryId); break; } |
|
1465 case EDrafts: { msvEntry->SetEntryL(KMsvDraftEntryId); break; } |
|
1466 case EOutbox: { msvEntry->SetEntryL(KMsvGlobalOutBoxIndexEntryId); break; } |
|
1467 case ESent: { msvEntry->SetEntryL(KMsvSentEntryId); break; } |
|
1468 default: { User::Panic(_L("Folder Type"), 871); break; } |
|
1469 } |
|
1470 |
|
1471 // mtm takes ownership of entry context |
|
1472 CleanupStack::Pop(msvEntry); |
|
1473 clientMtm->SetCurrentEntryL(msvEntry); |
|
1474 |
|
1475 // create a new message |
|
1476 clientMtm->CreateMessageL(defaultServiceId); |
|
1477 |
|
1478 // get the entry of the message |
|
1479 TMsvEntry messageEntry = clientMtm->Entry().Entry(); |
|
1480 |
|
1481 // set subject |
|
1482 clientMtm->SetSubjectL( parameters.iMessageSubject->Des() ); |
|
1483 messageEntry.iDescription.Set( parameters.iMessageSubject->Des().Left(KSmsDescriptionLength) ); |
|
1484 |
|
1485 // set body, must be empty for obex messages |
|
1486 clientMtm->Body().Reset(); |
|
1487 |
|
1488 // set the details field and |
|
1489 if (parameters.iFolderType == EInbox) |
|
1490 { |
|
1491 SetSenderToEntryDetails(messageEntry, parameters, EFalse); |
|
1492 } |
|
1493 else |
|
1494 { |
|
1495 SetRecipientToEntryDetails(messageEntry, parameters, EFalse); |
|
1496 } |
|
1497 |
|
1498 // set mtm |
|
1499 messageEntry.iMtm = aMtm; |
|
1500 messageEntry.iType = KUidMsvMessageEntry; |
|
1501 messageEntry.iServiceId = KMsvUnknownServiceIndexEntryId; |
|
1502 |
|
1503 // save the changes done above |
|
1504 clientMtm->Entry().ChangeL(messageEntry); |
|
1505 |
|
1506 // save the message |
|
1507 clientMtm->SaveMessageL(); |
|
1508 |
|
1509 // final fine tuning |
|
1510 messageEntry.iDate.HomeTime(); |
|
1511 messageEntry.SetVisible(ETrue); |
|
1512 messageEntry.SetInPreparation(EFalse); |
|
1513 if (parameters.iCreateAsUnread) |
|
1514 { |
|
1515 messageEntry.SetUnread(ETrue); |
|
1516 messageEntry.SetNew(ETrue); |
|
1517 } |
|
1518 else |
|
1519 { |
|
1520 messageEntry.SetUnread(EFalse); |
|
1521 messageEntry.SetNew(EFalse); |
|
1522 } |
|
1523 messageEntry.SetComplete(ETrue); |
|
1524 clientMtm->Entry().ChangeL(messageEntry); |
|
1525 |
|
1526 // save the attachment |
|
1527 if (parameters.iAttachments->Count() >= 1) |
|
1528 { |
|
1529 // create a new entry for the attachment |
|
1530 TMsvEntry attachTEntry; |
|
1531 attachTEntry.iType = KUidMsvAttachmentEntry; |
|
1532 attachTEntry.iServiceId = KMsvUnknownServiceIndexEntryId; |
|
1533 attachTEntry.iMtm = KUidMsgTypeBt; //save as bt message |
|
1534 |
|
1535 msvEntry->CreateL(attachTEntry); |
|
1536 |
|
1537 CMsvEntry* attachEntry = session->GetEntryL(attachTEntry.Id()); |
|
1538 clientMtm->SetCurrentEntryL(attachEntry); |
|
1539 |
|
1540 // get source file |
|
1541 TFileName sourceFileName = iEngine->TestDataPathL( (CCreatorEngine::TTestDataPath) parameters.iAttachments->At(0) ); |
|
1542 |
|
1543 // get the mime type |
|
1544 RApaLsSession ls; |
|
1545 User::LeaveIfError(ls.Connect()); |
|
1546 CleanupClosePushL<RApaLsSession>(ls); |
|
1547 TUid appUid; |
|
1548 TDataType mimeType; |
|
1549 ls.AppForDocument(sourceFileName, appUid, mimeType); |
|
1550 CleanupStack::PopAndDestroy(); //ls |
|
1551 |
|
1552 CAsyncWaiter* waiter = CAsyncWaiter::NewLC(); |
|
1553 |
|
1554 // add an attachment to the current message entry |
|
1555 TRAP(err, clientMtm->AddAttachmentL( sourceFileName, mimeType.Des8(), 0, waiter->iStatus )); |
|
1556 if (err == KErrNone) |
|
1557 waiter->StartAndWait(); |
|
1558 else |
|
1559 LOGSTRING2("Creator: CCreatorMessages::CreateObexEntryL failed to attach %S", &sourceFileName); |
|
1560 |
|
1561 CleanupStack::PopAndDestroy(waiter); |
|
1562 } |
|
1563 |
|
1564 // id has been generated, store it for being able to delete |
|
1565 // only entries created with Creator |
|
1566 iEntryIds.Append( messageEntry.Id() ); |
|
1567 |
|
1568 CleanupStack::PopAndDestroy(3); //session, registry, clientMtm |
|
1569 |
|
1570 |
|
1571 return err; |
|
1572 } |
|
1573 |
|
1574 //---------------------------------------------------------------------------- |
|
1575 |
|
1576 void CCreatorMessages::HandleSessionEventL(TMsvSessionEvent /*aEvent*/, TAny* /*aArg1*/, TAny* /*aArg2*/, TAny* /*aArg3*/) // from MMsvSessionObserver |
|
1577 { |
|
1578 } |
|
1579 |
|
1580 //---------------------------------------------------------------------------- |
|
1581 void CCreatorMessages::SetSenderToEntryDetails(TMsvEntry& aMsgEntry, const CMessagesParameters& aParameters, TBool aUseEmailAddress) |
|
1582 { |
|
1583 // Only one sender allowed: |
|
1584 if( iSenderArray.Count() == 0 ) |
|
1585 { |
|
1586 GetSendersL(iSenderArray, aParameters, aUseEmailAddress, 1 ); |
|
1587 } |
|
1588 if( iSenderArray.Count() > 0 ) |
|
1589 { |
|
1590 aMsgEntry.iDetails.Set( iSenderArray[0]->Des() ); |
|
1591 } |
|
1592 else |
|
1593 { |
|
1594 aMsgEntry.iDetails.Set(KEmpty); |
|
1595 } |
|
1596 } |
|
1597 |
|
1598 //---------------------------------------------------------------------------- |
|
1599 void CCreatorMessages::SetRecipientToEntryDetails(TMsvEntry& aMsgEntry, const CMessagesParameters& aParameters, TBool aUseEmailAddress) |
|
1600 { |
|
1601 // Only one sender allowed: |
|
1602 GetAllRecipientsL(iRecipientArray, aParameters, aUseEmailAddress); |
|
1603 if( iRecipientArray.Count() > 0 ) |
|
1604 { |
|
1605 const TDesC& temp = iRecipientArray[0]->Des(); |
|
1606 aMsgEntry.iDetails.Set( temp ); |
|
1607 } |
|
1608 else |
|
1609 { |
|
1610 aMsgEntry.iDetails.Set(KEmpty); |
|
1611 } |
|
1612 } |
|
1613 |
|
1614 //---------------------------------------------------------------------------- |
|
1615 void CCreatorMessages::AddSenderToMtmAddresseeL(CBaseMtm& aMtm, const CMessagesParameters& aParameters, TBool aUseEmailAddress ) |
|
1616 { |
|
1617 // Only one sender allowed: |
|
1618 if( iSenderArray.Count() == 0 ) |
|
1619 { |
|
1620 GetSendersL(iSenderArray, aParameters, aUseEmailAddress, 1 ); |
|
1621 } |
|
1622 |
|
1623 for( TInt i = 0; i < iSenderArray.Count(); ++i ) |
|
1624 { |
|
1625 aMtm.AddAddresseeL( iSenderArray[i]->Des() ); |
|
1626 } |
|
1627 } |
|
1628 |
|
1629 //---------------------------------------------------------------------------- |
|
1630 void CCreatorMessages::AddMtmSenderL(CMmsClientMtm& aMtm, const CMessagesParameters& aParameters, TBool aUseEmailAddress ) |
|
1631 { |
|
1632 // Only one sender allowed: |
|
1633 if( iSenderArray.Count() == 0 ) |
|
1634 { |
|
1635 GetSendersL(iSenderArray, aParameters, aUseEmailAddress, 1 ); |
|
1636 } |
|
1637 |
|
1638 if( iSenderArray.Count() > 0 ) |
|
1639 { |
|
1640 aMtm.SetSenderL( iSenderArray[0]->Des() ); |
|
1641 } |
|
1642 } |
|
1643 |
|
1644 //---------------------------------------------------------------------------- |
|
1645 void CCreatorMessages::GetSendersL(RPointerArray<HBufC>& aSenderArray, const CMessagesParameters& aParameters, TBool aUseEmailAddress, TInt aMaxNum ) |
|
1646 { |
|
1647 TInt counter = 0; |
|
1648 |
|
1649 if( counter < aMaxNum || aMaxNum == KUndef ) |
|
1650 { |
|
1651 if( aParameters.iSenderAddress && aParameters.iSenderAddress->Length() > 0 ) |
|
1652 { |
|
1653 HBufC* temp = HBufC::NewL(aParameters.iSenderAddress->Length()); |
|
1654 CleanupStack::PushL(temp); |
|
1655 temp->Des().Copy(aParameters.iSenderAddress->Des()); |
|
1656 aSenderArray.AppendL( temp ); |
|
1657 CleanupStack::Pop(); // temp |
|
1658 ++counter; |
|
1659 } |
|
1660 } |
|
1661 |
|
1662 if( counter < aMaxNum || aMaxNum == KUndef ) |
|
1663 { |
|
1664 RPointerArray<HBufC> tempArray; |
|
1665 CleanupResetAndDestroyPushL( tempArray ); |
|
1666 GetLinkedAddressesL(tempArray, aParameters.iSenderLinkIds, aUseEmailAddress, aParameters.iNumberOfExistingSenders); |
|
1667 for( TInt i = 0; i < tempArray.Count() && (counter < aMaxNum || aMaxNum == KUndef); ++i ) |
|
1668 { |
|
1669 HBufC* temp = tempArray[i]->AllocLC(); |
|
1670 aSenderArray.AppendL(temp); |
|
1671 CleanupStack::Pop(); // temp |
|
1672 ++counter; |
|
1673 } |
|
1674 CleanupStack::PopAndDestroy(); // tempArray |
|
1675 } |
|
1676 } |
|
1677 |
|
1678 //---------------------------------------------------------------------------- |
|
1679 void CCreatorMessages::AddRecipientsL(CBaseMtm& aMtm, const CMessagesParameters& aParameters, TBool aUseEmailAddress ) |
|
1680 { |
|
1681 GetAllRecipientsL(iRecipientArray, aParameters, aUseEmailAddress); |
|
1682 for( TInt i = 0; i < iRecipientArray.Count(); ++i ) |
|
1683 { |
|
1684 aMtm.AddAddresseeL( iRecipientArray[i]->Des() ); |
|
1685 } |
|
1686 } |
|
1687 |
|
1688 //---------------------------------------------------------------------------- |
|
1689 void CCreatorMessages::GetAllRecipientsL(RPointerArray<HBufC>& aRecipientArray, const CMessagesParameters& aParameters, TBool aUseEmailAddress ) |
|
1690 { |
|
1691 |
|
1692 // If iRecipientAddress is given, add it to the array: |
|
1693 if( aParameters.iRecipientAddress && aParameters.iRecipientAddress->Length() > 0 ) |
|
1694 { |
|
1695 HBufC* temp = HBufC::NewL(aParameters.iRecipientAddress->Length()); |
|
1696 CleanupStack::PushL(temp); |
|
1697 temp->Des().Copy(aParameters.iRecipientAddress->Des()); |
|
1698 aRecipientArray.AppendL( temp ); |
|
1699 CleanupStack::Pop(); // temp |
|
1700 } |
|
1701 |
|
1702 // Add all recipients listed in iRecipientAddressArray: |
|
1703 for( TInt i = 0; i < aParameters.iRecipientAddressArray.Count(); ++i ) |
|
1704 { |
|
1705 HBufC* temp = HBufC::NewL(aParameters.iRecipientAddressArray[i]->Length()); |
|
1706 CleanupStack::PushL(temp); |
|
1707 temp->Des().Copy(aParameters.iRecipientAddressArray[i]->Des()); |
|
1708 aRecipientArray.AppendL( temp ); |
|
1709 CleanupStack::Pop(); // temp |
|
1710 } |
|
1711 |
|
1712 // Get all linked addresses. |
|
1713 GetLinkedAddressesL(aRecipientArray, aParameters.iRecipientLinkIds, aUseEmailAddress, aParameters.iNumberOfExistingRecipients); |
|
1714 } |
|
1715 |
|
1716 /* |
|
1717 * Get all linked addresses. This method gets addresses that are linked with contact-set id and |
|
1718 * existing addresses from the contact database, if required. |
|
1719 */ |
|
1720 void CCreatorMessages::GetLinkedAddressesL( |
|
1721 RPointerArray<HBufC>& aAddressArray, |
|
1722 const RArray<TLinkIdParam>& aLinkIds, |
|
1723 TBool aUseEmailAddress, |
|
1724 TInt aNumOfExistingAddresses ) |
|
1725 { |
|
1726 } |
|
1727 |
|
1728 //---------------------------------------------------------------------------- |
|
1729 void CCreatorMessages::DeleteAllL() |
|
1730 { |
|
1731 LOGSTRING("Creator: CCreatorMessages::DeleteAllL"); |
|
1732 DeleteAllMessagesL( EFalse ); |
|
1733 } |
|
1734 |
|
1735 //---------------------------------------------------------------------------- |
|
1736 void CCreatorMessages::DeleteAllMessagesL( TBool aOnlyCreatedWithCreator ) |
|
1737 { |
|
1738 LOGSTRING("Creator: CCreatorMessages::DeleteAllMessagesL"); |
|
1739 TInt err( KErrNone ); |
|
1740 |
|
1741 // init |
|
1742 CMsvSession* session = CMsvSession::OpenSyncL(*this); |
|
1743 CleanupStack::PushL( session ); |
|
1744 CClientMtmRegistry* registry = CClientMtmRegistry::NewL(*session); |
|
1745 CleanupStack::PushL( registry ); |
|
1746 |
|
1747 // get the client mtm and return if it isn't supported in the system |
|
1748 CSmsClientMtm* clientMtm( NULL ); |
|
1749 TRAP( err, clientMtm = static_cast<CSmsClientMtm*>( registry->NewMtmL( KUidMsgTypeSMS ) ) ); |
|
1750 if ( err || !clientMtm ) |
|
1751 { |
|
1752 iEngine->GetEngineWrapper()->ShowErrorMessage( _L( "SMS: Message type module not found" ) ); |
|
1753 CleanupStack::PopAndDestroy( 2 ); |
|
1754 User::Leave( KErrNotFound ); |
|
1755 } |
|
1756 CleanupStack::PushL( clientMtm ); |
|
1757 |
|
1758 TRAP_IGNORE( DeleteAllFromFolderL( KMsvGlobalInBoxIndexEntryId, session, clientMtm, aOnlyCreatedWithCreator ) ); |
|
1759 TRAP_IGNORE( DeleteAllFromFolderL( KMsvDraftEntryId, session, clientMtm, aOnlyCreatedWithCreator ) ); |
|
1760 TRAP_IGNORE( DeleteAllFromFolderL( KMsvGlobalOutBoxIndexEntryId, session, clientMtm, aOnlyCreatedWithCreator ) ); |
|
1761 TRAP_IGNORE( DeleteAllFromFolderL( KMsvSentEntryId, session, clientMtm, aOnlyCreatedWithCreator ) ); |
|
1762 |
|
1763 // reset must be done here, because iEntryIds is stored in destructor |
|
1764 iEntryIds.Reset(); |
|
1765 |
|
1766 // all entries deleted, remove the Messages related registry |
|
1767 iEngine->RemoveStoreL( KUidDictionaryUidMessages ); |
|
1768 |
|
1769 CleanupStack::PopAndDestroy( clientMtm ); |
|
1770 CleanupStack::PopAndDestroy( registry ); |
|
1771 CleanupStack::PopAndDestroy( session ); |
|
1772 } |
|
1773 |
|
1774 //---------------------------------------------------------------------------- |
|
1775 void CCreatorMessages::DeleteAllFromFolderL( const TMsvId aContext, |
|
1776 CMsvSession* aSession, |
|
1777 CSmsClientMtm* aClientMtm, |
|
1778 TBool aOnlyCreatedWithCreator ) |
|
1779 { |
|
1780 LOGSTRING("Creator: CCreatorMessages::DeleteAllFromFolderL"); |
|
1781 |
|
1782 TMsvSelectionOrdering sort; |
|
1783 sort.SetShowInvisibleEntries( ETrue ); |
|
1784 |
|
1785 CMsvEntry* inboxContext = CMsvEntry::NewL( *aSession, aContext, sort ); |
|
1786 CleanupStack::PushL( inboxContext ); |
|
1787 |
|
1788 CMsvEntrySelection* entries = inboxContext->ChildrenL(); |
|
1789 CleanupStack::PushL( entries ); |
|
1790 |
|
1791 TInt msgCount = entries->Count(); |
|
1792 for ( TInt i = 0; i < entries->Count(); i++) |
|
1793 { |
|
1794 TMsvId entryID = entries->At(i); |
|
1795 aClientMtm->SwitchCurrentEntryL( entryID ); |
|
1796 |
|
1797 if ( !aOnlyCreatedWithCreator || iEntryIds.Find( entryID ) != KErrNotFound ) |
|
1798 { |
|
1799 CMsvEntry* entry = aSession->GetEntryL( (*entries)[i] ); |
|
1800 CleanupStack::PushL( entry ); |
|
1801 |
|
1802 entry->DeleteL( entries->At(i) ); |
|
1803 CleanupStack::PopAndDestroy( entry ); |
|
1804 } |
|
1805 } |
|
1806 |
|
1807 CleanupStack::PopAndDestroy( entries ); |
|
1808 CleanupStack::PopAndDestroy( inboxContext ); |
|
1809 } |
|
1810 |
|
1811 //---------------------------------------------------------------------------- |
|
1812 void CCreatorMessages::DeleteAllCreatedByCreatorL() |
|
1813 { |
|
1814 LOGSTRING("Creator: CCreatorMessages::DeleteAllCreatedByCreatorL"); |
|
1815 |
|
1816 iEntryIds.Reset(); |
|
1817 |
|
1818 // fetch ids of entries created by Creator |
|
1819 iEngine->ReadEntryIdsFromStoreL( iEntryIds, KUidDictionaryUidMessages ); |
|
1820 |
|
1821 // delete them |
|
1822 DeleteAllMessagesL( ETrue ); |
|
1823 } |
|
1824 |
|
1825 CRecipientInfo::CRecipientInfo() |
|
1826 { |
|
1827 |
|
1828 } |
|
1829 |
|
1830 CRecipientInfo::~CRecipientInfo() |
|
1831 { |
|
1832 delete iPhoneNumber; |
|
1833 delete iEmailAddress; |
|
1834 } |
|
1835 |
|
1836 void CRecipientInfo::SetPhoneNumber(HBufC* aPhone) |
|
1837 { |
|
1838 delete iPhoneNumber; |
|
1839 iPhoneNumber = aPhone; |
|
1840 } |
|
1841 |
|
1842 void CRecipientInfo::SetEmailAddress(HBufC* aEmail) |
|
1843 { |
|
1844 delete iEmailAddress; |
|
1845 iEmailAddress = aEmail; |
|
1846 } |
|
1847 |
|
1848 const HBufC* CRecipientInfo::PhoneNumber() const |
|
1849 { |
|
1850 return iPhoneNumber; |
|
1851 } |
|
1852 |
|
1853 const HBufC* CRecipientInfo::EmailAddress() const |
|
1854 { |
|
1855 return iEmailAddress; |
|
1856 } |