|
1 /* |
|
2 * Copyright (c) 2002 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 * Mixed class to offer different account functions. |
|
16 * Implemented by CMceUi. |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 // INCLUDE FILES |
|
24 #include <msvids.h> |
|
25 #include <msvapi.h> |
|
26 #include <AknUtils.h> // AknTextUtils |
|
27 #include "MceUtils.h" |
|
28 #include "MceIds.h" |
|
29 #include "MceListItem.h" |
|
30 #include <featmgr.h> |
|
31 |
|
32 #include <messagingvariant.hrh> |
|
33 #include <centralrepository.h> |
|
34 #include <MessagingDomainCRKeys.h> |
|
35 #include <centralrepository.h> |
|
36 #include <messaginginternalcrkeys.h> |
|
37 |
|
38 #include <NumberGroupingCRKeys.h> |
|
39 |
|
40 #include <mmsvattachmentmanager.h> |
|
41 #include <cmsvattachment.h> |
|
42 |
|
43 #include <SenduiMtmUids.h> // mtm uids |
|
44 #include <mmsconst.h> |
|
45 #include <mmsgenutils.h> |
|
46 #include <mmsclient.h> |
|
47 #include <mtclreg.h> |
|
48 #include <mtudreg.h> // CMtmUiDataRegistry |
|
49 #include <miutset.h> |
|
50 #include <commonphoneparser.h> |
|
51 #include <smuthdr.h> |
|
52 |
|
53 #include <ImumInternalApi.h> |
|
54 #include <ImumInHealthServices.h> |
|
55 |
|
56 // CONSTANTS |
|
57 |
|
58 const TInt KMceReplaceCharacterCount = 3; |
|
59 |
|
60 |
|
61 // ================= MEMBER FUNCTIONS ======================= |
|
62 |
|
63 // --------------------------------------------------------- |
|
64 // MceUtils::IsEntryFixed |
|
65 // This is static function |
|
66 // (other items were commented in a header). |
|
67 // --------------------------------------------------------- |
|
68 // |
|
69 TBool MceUtils::IsEntryFixed(TMsvId aId) |
|
70 { |
|
71 return (aId == KMsvGlobalInBoxIndexEntryId |
|
72 || aId == KMsvGlobalOutBoxIndexEntryId |
|
73 || aId == KMsvDraftEntryId |
|
74 || aId == KMsvSentEntryId |
|
75 || aId == KMsvLocalServiceIndexEntryId |
|
76 || aId == KMceDocumentsEntryId |
|
77 || aId == KMceTemplatesEntryId |
|
78 ); |
|
79 } |
|
80 |
|
81 // --------------------------------------------------------- |
|
82 // MceUtils::ReplaceCharacters |
|
83 // This is static function |
|
84 // (other items were commented in a header). |
|
85 // --------------------------------------------------------- |
|
86 // |
|
87 void MceUtils::ReplaceCharacters( TDes& aText ) |
|
88 { |
|
89 TBuf<KMceReplaceCharacterCount> replaceChars; |
|
90 replaceChars.Zero(); |
|
91 replaceChars.Append( CEditableText::EParagraphDelimiter ); |
|
92 replaceChars.Append( CEditableText::ETabCharacter ); |
|
93 replaceChars.Append( CEditableText::EByteOrderMark ); |
|
94 AknTextUtils::ReplaceCharacters( |
|
95 aText, |
|
96 replaceChars, |
|
97 CEditableText::ESpace ); |
|
98 } |
|
99 |
|
100 // --------------------------------------------------------- |
|
101 // MceUtils::GetIrFilePathL |
|
102 // This is static function |
|
103 // (other items were commented in a header). |
|
104 // --------------------------------------------------------- |
|
105 // |
|
106 void MceUtils::GetIrFilePathL( CMsvSession& aSession, TMsvId aEntryId, TFileName& aFileName, RFile& aFileHandle, TInt& aSize ) |
|
107 { |
|
108 aFileName.Zero(); |
|
109 |
|
110 // Get attachment manager from the entry's store |
|
111 |
|
112 CMsvEntry* message = aSession.GetEntryL( aEntryId ); |
|
113 CleanupStack::PushL( message ); // message |
|
114 |
|
115 // In case of incomplete message which has no attachment |
|
116 if ( message->Count() ) |
|
117 { |
|
118 CMsvEntry* entry = aSession.GetEntryL( ((*message)[0]).Id() ); |
|
119 CleanupStack::PushL( entry ); // entry, message |
|
120 CMsvStore* store = entry->ReadStoreL(); |
|
121 CleanupStack::PushL( store ); // store, entry, message |
|
122 |
|
123 MMsvAttachmentManager& attachMan = store->AttachmentManagerL(); |
|
124 |
|
125 if ( attachMan.AttachmentCount() != 1 ) |
|
126 { |
|
127 User::Leave( KErrNotFound ); |
|
128 } |
|
129 |
|
130 // Get the path |
|
131 CMsvAttachment *attachment = attachMan.GetAttachmentInfoL(0); |
|
132 CleanupStack::PushL( attachment ); // attachment, store, entry, message |
|
133 const TDesC& filePath = attachment->FilePath(); |
|
134 // Save |
|
135 aFileName.Copy( filePath ); |
|
136 |
|
137 aFileHandle = attachMan.GetAttachmentFileL( 0 ); |
|
138 |
|
139 // Get the size |
|
140 aSize = attachment->Size(); |
|
141 |
|
142 CleanupStack::PopAndDestroy( 4 ); // attachment, store, entry, message |
|
143 } |
|
144 else |
|
145 { |
|
146 CleanupStack::PopAndDestroy(); // message |
|
147 User::Leave( KErrNotFound ); |
|
148 } |
|
149 } |
|
150 |
|
151 // --------------------------------------------------------- |
|
152 // MceUtils::MemoryInUseOptionL |
|
153 // This is static function |
|
154 // Returns ETrue if 'Memory in use' option is enabled in |
|
155 // mce/settings |
|
156 // --------------------------------------------------------- |
|
157 // |
|
158 TBool MceUtils::MemoryInUseOptionL( ) |
|
159 { |
|
160 TBool memoryInUse = ETrue; |
|
161 if ( FeatureManager::FeatureSupported( KFeatureIdMmc ) ) |
|
162 { |
|
163 if ( FeatureManager::FeatureSupported( KFeatureIdMmcHotswap) ) |
|
164 { |
|
165 // if not hotswap phone, then Memory in use is enabled |
|
166 // if hotswap phone, check from shared data, if |
|
167 // Memory in use is enabled |
|
168 |
|
169 CRepository* repository = NULL; |
|
170 TRAPD( ret, repository = CRepository::NewL(KCRUidMuiuVariation) ); |
|
171 CleanupStack::PushL( repository ); |
|
172 |
|
173 TInt featureBitmask = 0; |
|
174 |
|
175 if ( ret == KErrNone ) |
|
176 { |
|
177 if ( repository->Get(KMuiuMceFeatures,featureBitmask) != KErrNone ) |
|
178 { |
|
179 memoryInUse = ETrue; |
|
180 } |
|
181 else |
|
182 { |
|
183 if ( !(featureBitmask & KMceFeatureIdHotswap) ) |
|
184 { |
|
185 memoryInUse = EFalse; |
|
186 } |
|
187 } |
|
188 } |
|
189 |
|
190 CleanupStack::Pop( repository ); |
|
191 delete repository; |
|
192 |
|
193 } |
|
194 |
|
195 } |
|
196 else |
|
197 { |
|
198 //no mmc support |
|
199 memoryInUse = EFalse; |
|
200 } |
|
201 return memoryInUse; |
|
202 } |
|
203 |
|
204 // --------------------------------------------------------- |
|
205 // MceUtils::GetHealthyMailboxList |
|
206 // This is static function |
|
207 // (other items were commented in a header). |
|
208 // --------------------------------------------------------- |
|
209 // |
|
210 TInt MceUtils::GetHealthyMailboxListL( |
|
211 const MImumInHealthServices& aHealthServices, |
|
212 MImumInHealthServices::RMailboxIdArray& aMailboxIdArray, |
|
213 TBool aGetImap4, |
|
214 TBool aGetPop3, |
|
215 TBool aGetSyncML, |
|
216 TBool aGetOther ) |
|
217 { |
|
218 TInt64 mailboxFlags = MImumInHealthServices::EFlagGetHealthy; |
|
219 |
|
220 TInt mtmPluginID = 0; |
|
221 if ( FeatureManager::FeatureSupported( KFeatureIdEmailMceIntegration ) ) |
|
222 { |
|
223 // Check if there is other than platform email application registered |
|
224 // to handle S60 mailboxes |
|
225 CRepository* repository = NULL; |
|
226 TRAPD( ret, repository = CRepository::NewL( |
|
227 KCRUidSelectableDefaultEmailSettings ) ); |
|
228 |
|
229 if ( ret == KErrNone ) |
|
230 { |
|
231 TInt err = repository->Get( KIntegratedEmailAppMtmPluginId, |
|
232 mtmPluginID ); |
|
233 if ( err != KErrNone ) |
|
234 { |
|
235 mtmPluginID = 0; |
|
236 } |
|
237 } |
|
238 delete repository; |
|
239 } |
|
240 if ( mtmPluginID == 0 ) |
|
241 { |
|
242 if ( aGetImap4 ) |
|
243 { |
|
244 mailboxFlags |= MImumInHealthServices::EFlagIncludeImap4; |
|
245 } |
|
246 if ( aGetPop3 ) |
|
247 { |
|
248 mailboxFlags |= MImumInHealthServices::EFlagIncludePop3; |
|
249 } |
|
250 } |
|
251 if ( aGetSyncML ) |
|
252 { |
|
253 mailboxFlags |= MImumInHealthServices::EFlagIncludeSyncMl; |
|
254 } |
|
255 if ( aGetOther ) |
|
256 { |
|
257 mailboxFlags |= MImumInHealthServices::EFlagIncludeOther; |
|
258 } |
|
259 |
|
260 TInt error = aHealthServices.GetMailboxList( |
|
261 aMailboxIdArray, |
|
262 mailboxFlags ); |
|
263 |
|
264 return error; |
|
265 } |
|
266 |
|
267 // --------------------------------------------------------- |
|
268 // MceUtils::ValidPhoneNumberL |
|
269 // This is static function |
|
270 // Returns ETrue if phonenumber is valid |
|
271 // --------------------------------------------------------- |
|
272 // |
|
273 TBool MceUtils::ValidPhoneNumberL( |
|
274 TMsvId aEntryId, |
|
275 CMsvSession& aSession, |
|
276 TPhCltTelephoneNumber& aPhoneNumber, |
|
277 TDes* aEntryDetails ) |
|
278 { |
|
279 TBool validNumber = EFalse; |
|
280 TMsvEntry entry; |
|
281 TMsvId service = KMsvLocalServiceIndexEntryId; |
|
282 User::LeaveIfError( aSession.GetEntry( aEntryId, service, entry ) ); |
|
283 if ( aEntryDetails ) |
|
284 { |
|
285 aEntryDetails->Copy( entry.iDetails.Left( KMceVisibleTextLength ) ); |
|
286 } |
|
287 if ( entry.iMtm == KSenduiMtmSmsUid || entry.iMtm == KSenduiMtmBioUid ) |
|
288 { |
|
289 MceUtils::GetSmsNumberL( aEntryId, aSession, aPhoneNumber ); |
|
290 validNumber = CommonPhoneParser::IsValidPhoneNumber( |
|
291 aPhoneNumber, CommonPhoneParser::ESMSNumber ); |
|
292 } |
|
293 else if ( entry.iMtm == KSenduiMtmMmsUid || entry.iMtm == KSenduiMMSNotificationUid ) |
|
294 { |
|
295 MceUtils::GetMmsNumberL( entry, aSession, aPhoneNumber ); |
|
296 validNumber = CommonPhoneParser::IsValidPhoneNumber( |
|
297 aPhoneNumber, CommonPhoneParser::ESMSNumber ); |
|
298 } |
|
299 return validNumber; |
|
300 } |
|
301 |
|
302 // --------------------------------------------------------- |
|
303 // MceUtils::ValidPhoneNumberL |
|
304 // This is static function |
|
305 // Returns ETrue if phonenumber is valid |
|
306 // --------------------------------------------------------- |
|
307 // |
|
308 TBool MceUtils::ValidPhoneNumberL( |
|
309 TMsvId aEntryId, |
|
310 CMsvSession& aSession ) |
|
311 { |
|
312 TPhCltTelephoneNumber number; |
|
313 |
|
314 |
|
315 return MceUtils::ValidPhoneNumberL( |
|
316 aEntryId, |
|
317 aSession, |
|
318 number, |
|
319 NULL ); |
|
320 } |
|
321 |
|
322 // ---------------------------------------------------- |
|
323 // MceUtils::GetSmsNumberL |
|
324 // Gets phone number from SMS entry |
|
325 // ---------------------------------------------------- |
|
326 void MceUtils::GetSmsNumberL( |
|
327 TMsvId aEntryId, |
|
328 CMsvSession& aSession, |
|
329 TPhCltTelephoneNumber& aNumber ) |
|
330 { |
|
331 CMsvEntry* parentEntry = aSession.GetEntryL( aEntryId ); |
|
332 CleanupStack::PushL( parentEntry ); |
|
333 CPlainText* nullString = CPlainText::NewL(); |
|
334 CleanupStack::PushL( nullString ); |
|
335 CSmsHeader* header = CSmsHeader::NewL( CSmsPDU::ESmsDeliver, *nullString ); |
|
336 CleanupStack::PushL( header ); |
|
337 CMsvStore* store = parentEntry->ReadStoreL(); |
|
338 CleanupStack::PushL( store ); |
|
339 header->RestoreL( *store ); |
|
340 aNumber = header->FromAddress(); |
|
341 CleanupStack::PopAndDestroy( 4 ); // store, header, parentEntry, nullString |
|
342 } |
|
343 |
|
344 // ---------------------------------------------------- |
|
345 // MceUtils::GetMmsNumberL |
|
346 // Gets phone number from MMS entry |
|
347 // ---------------------------------------------------- |
|
348 void MceUtils::GetMmsNumberL( |
|
349 TMsvEntry& aEntry, |
|
350 CMsvSession& aSession, |
|
351 TPhCltTelephoneNumber& aNumber ) |
|
352 { |
|
353 TMsvId id = aEntry.Id(); |
|
354 CClientMtmRegistry* mtmRegistry = CClientMtmRegistry::NewL( aSession ); |
|
355 CleanupStack::PushL( mtmRegistry ); |
|
356 |
|
357 CMmsClientMtm* mmsMtm = (CMmsClientMtm *) mtmRegistry->NewMtmL( aEntry.iMtm ); |
|
358 CleanupStack::PushL( mmsMtm ); |
|
359 mmsMtm->SwitchCurrentEntryL( aEntry.Id() ); |
|
360 mmsMtm->LoadMessageL(); |
|
361 TPtrC sender = mmsMtm->Sender(); |
|
362 aNumber = TMmsGenUtils::PureAddress( sender ); |
|
363 CleanupStack::PopAndDestroy( 2 ); // mtmRegistry, mmsMtm |
|
364 } |
|
365 |
|
366 |
|
367 |
|
368 // --------------------------------------------------------- |
|
369 // MceUtils::StripAndAppendStringL |
|
370 // This is static function |
|
371 // --------------------------------------------------------- |
|
372 // |
|
373 void MceUtils::StripAndAppendStringL( |
|
374 TDes& aTargetString, |
|
375 const TDesC& aSourceString, |
|
376 TInt aDescriptionLength ) |
|
377 { |
|
378 TBool addThreeDots = EFalse; |
|
379 |
|
380 if ( aDescriptionLength <= 0 ) |
|
381 { |
|
382 aDescriptionLength = MceUtils::DescriptionLength(); |
|
383 } |
|
384 |
|
385 TInt length = aSourceString.Left( aDescriptionLength ).Length(); |
|
386 if ( length == 0 ) |
|
387 { |
|
388 // append space, needed by list box |
|
389 aTargetString.Append( CEditableText::ESpace ); |
|
390 return; |
|
391 } |
|
392 |
|
393 if ( aSourceString.Length() > length ) |
|
394 { |
|
395 length--; |
|
396 addThreeDots = ETrue; |
|
397 } |
|
398 |
|
399 HBufC* tempString = aSourceString.Left( length ).AllocLC(); |
|
400 TPtr tempStringPtr = tempString->Des(); |
|
401 MceUtils::ReplaceCharacters( tempStringPtr ); |
|
402 aTargetString.Append( tempStringPtr ); |
|
403 CleanupStack::PopAndDestroy( tempString ); |
|
404 if ( addThreeDots ) |
|
405 { |
|
406 aTargetString.Append( CEditableText::EEllipsis ); |
|
407 } |
|
408 } |
|
409 |
|
410 |
|
411 // --------------------------------------------------------- |
|
412 // MceUtils::DescriptionLength |
|
413 // This is static function |
|
414 // --------------------------------------------------------- |
|
415 // |
|
416 TInt MceUtils::DescriptionLength() |
|
417 { |
|
418 TInt descriptionLength = KMceVisibleTextLength; |
|
419 TRAPD( error, descriptionLength = MceUtils::DescriptionLengthL() ); |
|
420 if ( error != KErrNone ) |
|
421 { |
|
422 descriptionLength = KMceVisibleTextLength; |
|
423 } |
|
424 return descriptionLength; |
|
425 } |
|
426 |
|
427 // --------------------------------------------------------- |
|
428 // MceUtils::DescriptionLengthL |
|
429 // This is static function |
|
430 // --------------------------------------------------------- |
|
431 // |
|
432 TInt MceUtils::DescriptionLengthL() |
|
433 { |
|
434 TInt descriptionLength = KMceVisibleTextLength; |
|
435 CRepository* repository = CRepository::NewLC(KCRUidMuiuSettings); |
|
436 if ( repository->Get(KMuiuDescriptionLength, descriptionLength) != KErrNone ) |
|
437 { |
|
438 descriptionLength = KMceVisibleTextLength; |
|
439 } |
|
440 if ( descriptionLength < KMceVisibleTextLength ) |
|
441 { |
|
442 descriptionLength = KMceVisibleTextLength; |
|
443 } |
|
444 // How to make sure it is sensible? |
|
445 else if ( descriptionLength > 3*KMceVisibleTextLength ) |
|
446 { |
|
447 descriptionLength = 3*KMceVisibleTextLength; |
|
448 } |
|
449 CleanupStack::PopAndDestroy( repository ); |
|
450 return descriptionLength; |
|
451 } |
|
452 |
|
453 |
|
454 // --------------------------------------------------------- |
|
455 // MceUtils::IsMtmBuiltIn |
|
456 // This is static function |
|
457 // --------------------------------------------------------- |
|
458 // |
|
459 TBool MceUtils::IsMtmBuiltIn( TUid aMtmUid ) |
|
460 { |
|
461 TBool mtmIsBuiltIn = EFalse; |
|
462 switch ( aMtmUid.iUid ) |
|
463 { |
|
464 case KSenduiMtmSmtpUidValue: |
|
465 case KSenduiMtmImap4UidValue: |
|
466 case KSenduiMtmPop3UidValue: |
|
467 case KSenduiMtmSmsUidValue: |
|
468 case KSenduiMtmMmsUidValue: |
|
469 case KSenduiMtmIrUidValue: |
|
470 case KSenduiMtmBtUidValue: |
|
471 case KSenduiMtmPushMtmUidValue: |
|
472 case KSenduiMtmSyncMLEmailUidValue: |
|
473 case KSenduiMtmBioUidValue: |
|
474 case KSenduiMtmRoUidValue: |
|
475 case KSenduiMMSNotificationUidValue: |
|
476 case KSenduiMtmPostcardUidValue: |
|
477 case KSenduiMtmAudioMessageUidValue: |
|
478 case KSenduiMtmUniMessageUidValue: |
|
479 mtmIsBuiltIn = ETrue; |
|
480 break; |
|
481 |
|
482 default: |
|
483 break; |
|
484 } |
|
485 return mtmIsBuiltIn; |
|
486 } |
|
487 |
|
488 // --------------------------------------------------------- |
|
489 // MceUtils::NumberGroupingEnabled |
|
490 // This is static function |
|
491 // --------------------------------------------------------- |
|
492 // |
|
493 TBool MceUtils::NumberGroupingEnabled() |
|
494 { |
|
495 TBool numberGroupingEnabled = EFalse; |
|
496 TRAPD( error, numberGroupingEnabled = MceUtils::NumberGroupingEnabledL() ); |
|
497 if ( error != KErrNone ) |
|
498 { |
|
499 numberGroupingEnabled = EFalse; |
|
500 } |
|
501 return numberGroupingEnabled; |
|
502 } |
|
503 |
|
504 // --------------------------------------------------------- |
|
505 // MceUtils::NumberGroupingEnabledL |
|
506 // This is static function |
|
507 // --------------------------------------------------------- |
|
508 // |
|
509 TBool MceUtils::NumberGroupingEnabledL() |
|
510 { |
|
511 TInt numberGrouping = 0; |
|
512 CRepository* repository = CRepository::NewL(KCRUidNumberGrouping); |
|
513 // CleanupStack is not needed since no leavable functions below |
|
514 if ( repository->Get(KNumberGrouping, numberGrouping) != KErrNone ) |
|
515 { |
|
516 numberGrouping = 0; |
|
517 } |
|
518 delete repository; |
|
519 |
|
520 // CenRep key KCRUidNumberGrouping / KNumberGrouping is used to check if |
|
521 // number grouping is supported |
|
522 return ( numberGrouping == 1 ); |
|
523 // return FeatureManager::FeatureSupported( KFeatureIdPhoneNumberGrouping ); |
|
524 } |
|
525 |
|
526 |
|
527 |
|
528 // --------------------------------------------------------- |
|
529 // TMceFlags::TMceFlags |
|
530 // This is static function |
|
531 // (other items were commented in a header). |
|
532 // --------------------------------------------------------- |
|
533 // |
|
534 TMceFlags::TMceFlags() |
|
535 : |
|
536 iFlags( 0 ) |
|
537 { |
|
538 } |
|
539 |
|
540 // End of File |