messagingappbase/mce/src/MceUtils.cpp
branchRCL_3
changeset 27 7fdbb852d323
equal deleted inserted replaced
26:ebe688cedc25 27:7fdbb852d323
       
     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 #ifdef RD_HIDE_MEMORY_IN_USE
       
   161     return EFalse;
       
   162 #endif // RD_HIDE_MEMORY_IN_USE
       
   163     TBool memoryInUse = ETrue;
       
   164     if ( FeatureManager::FeatureSupported( KFeatureIdMmc ) )
       
   165         {        
       
   166         if ( FeatureManager::FeatureSupported( KFeatureIdMmcHotswap) )
       
   167             {
       
   168             // if not hotswap phone, then Memory in use is enabled
       
   169             // if hotswap phone, check from shared data, if
       
   170             // Memory in use is enabled            
       
   171 
       
   172             CRepository* repository = NULL;
       
   173             TRAPD( ret, repository = CRepository::NewL(KCRUidMuiuVariation) );
       
   174             CleanupStack::PushL( repository );
       
   175 
       
   176             TInt featureBitmask = 0;
       
   177 
       
   178             if ( ret == KErrNone )
       
   179                 {
       
   180                 if ( repository->Get(KMuiuMceFeatures,featureBitmask) != KErrNone )
       
   181                     {
       
   182                     memoryInUse = ETrue;
       
   183                     }
       
   184                 else
       
   185                     {
       
   186                     if ( !(featureBitmask & KMceFeatureIdHotswap) )
       
   187                         {
       
   188                         memoryInUse = EFalse;
       
   189                         }
       
   190                     }
       
   191                 }
       
   192 
       
   193             CleanupStack::Pop( repository );
       
   194             delete repository;
       
   195 
       
   196             }
       
   197         
       
   198         }
       
   199     else
       
   200         {
       
   201         //no mmc support
       
   202         memoryInUse = EFalse;
       
   203         }
       
   204     return memoryInUse;     
       
   205     }
       
   206    
       
   207 // ---------------------------------------------------------
       
   208 // MceUtils::GetHealthyMailboxList
       
   209 // This is static function
       
   210 // (other items were commented in a header).
       
   211 // ---------------------------------------------------------
       
   212 //
       
   213 TInt MceUtils::GetHealthyMailboxListL(
       
   214     const MImumInHealthServices& aHealthServices,
       
   215     MImumInHealthServices::RMailboxIdArray& aMailboxIdArray,
       
   216     TBool aGetImap4,
       
   217     TBool aGetPop3,
       
   218     TBool aGetSyncML,
       
   219     TBool aGetOther )
       
   220     {
       
   221     TInt64 mailboxFlags = MImumInHealthServices::EFlagGetHealthy;
       
   222 
       
   223     TInt mtmPluginID = 0;
       
   224     if ( FeatureManager::FeatureSupported( KFeatureIdEmailMceIntegration ) )
       
   225         {
       
   226         // Check if there is other than platform email application registered
       
   227         // to handle S60 mailboxes	
       
   228         CRepository* repository = NULL;
       
   229          TRAPD( ret, repository = CRepository::NewL(
       
   230                                  KCRUidSelectableDefaultEmailSettings ) );
       
   231 
       
   232         if ( ret == KErrNone )
       
   233             {
       
   234             TInt err = repository->Get( KIntegratedEmailAppMtmPluginId,
       
   235                                         mtmPluginID );
       
   236             if ( err != KErrNone )
       
   237                 {
       
   238                 mtmPluginID = 0;
       
   239                 }
       
   240             }
       
   241         delete repository;
       
   242         }
       
   243     if ( mtmPluginID == 0 )
       
   244         {
       
   245     if ( aGetImap4 )
       
   246         {
       
   247         mailboxFlags |= MImumInHealthServices::EFlagIncludeImap4;
       
   248         }
       
   249     if ( aGetPop3 )
       
   250         {
       
   251         mailboxFlags |= MImumInHealthServices::EFlagIncludePop3;
       
   252         }
       
   253         }
       
   254     if ( aGetSyncML )
       
   255         {
       
   256         mailboxFlags |= MImumInHealthServices::EFlagIncludeSyncMl;
       
   257         }
       
   258     if ( aGetOther )
       
   259         {
       
   260         mailboxFlags |= MImumInHealthServices::EFlagIncludeOther;
       
   261         }
       
   262         
       
   263     TInt error = aHealthServices.GetMailboxList( 
       
   264         aMailboxIdArray,
       
   265         mailboxFlags );
       
   266     
       
   267     return error;
       
   268     }
       
   269 
       
   270 // ---------------------------------------------------------
       
   271 // MceUtils::ValidPhoneNumberL
       
   272 // This is static function
       
   273 // Returns ETrue if phonenumber is valid
       
   274 // ---------------------------------------------------------
       
   275 //
       
   276 TBool MceUtils::ValidPhoneNumberL( 
       
   277     TMsvId aEntryId,
       
   278     CMsvSession& aSession,
       
   279     TPhCltTelephoneNumber& aPhoneNumber,
       
   280     TDes* aEntryDetails )
       
   281     {
       
   282     TBool validNumber = EFalse;
       
   283     TMsvEntry entry;
       
   284     TMsvId service = KMsvLocalServiceIndexEntryId;    
       
   285     User::LeaveIfError( aSession.GetEntry( aEntryId, service, entry ) );
       
   286     if ( aEntryDetails )
       
   287         {
       
   288         aEntryDetails->Copy( entry.iDetails.Left( KMceVisibleTextLength ) );
       
   289         }
       
   290     if ( entry.iMtm == KSenduiMtmSmsUid || entry.iMtm == KSenduiMtmBioUid )
       
   291         {
       
   292         MceUtils::GetSmsNumberL( aEntryId, aSession, aPhoneNumber );
       
   293         validNumber = CommonPhoneParser::IsValidPhoneNumber( 
       
   294             aPhoneNumber, CommonPhoneParser::ESMSNumber );                               
       
   295         }
       
   296     else if ( entry.iMtm == KSenduiMtmMmsUid || entry.iMtm == KSenduiMMSNotificationUid )
       
   297         { 
       
   298         MceUtils::GetMmsNumberL( entry, aSession, aPhoneNumber );
       
   299         validNumber = CommonPhoneParser::IsValidPhoneNumber( 
       
   300             aPhoneNumber, CommonPhoneParser::ESMSNumber );
       
   301         }
       
   302     return validNumber;
       
   303     }
       
   304     
       
   305 // ---------------------------------------------------------
       
   306 // MceUtils::ValidPhoneNumberL
       
   307 // This is static function
       
   308 // Returns ETrue if phonenumber is valid
       
   309 // ---------------------------------------------------------
       
   310 //
       
   311 TBool MceUtils::ValidPhoneNumberL( 
       
   312     TMsvId aEntryId,
       
   313     CMsvSession& aSession )
       
   314     {
       
   315     TPhCltTelephoneNumber number;
       
   316     
       
   317     
       
   318     return MceUtils::ValidPhoneNumberL( 
       
   319         aEntryId,
       
   320         aSession,
       
   321         number,
       
   322         NULL );
       
   323     }
       
   324     
       
   325 // ----------------------------------------------------
       
   326 // MceUtils::GetSmsNumberL
       
   327 // Gets phone number from SMS entry
       
   328 // ----------------------------------------------------
       
   329 void MceUtils::GetSmsNumberL( 
       
   330     TMsvId aEntryId, 
       
   331     CMsvSession& aSession,
       
   332     TPhCltTelephoneNumber& aNumber )
       
   333     {
       
   334     CMsvEntry* parentEntry = aSession.GetEntryL( aEntryId );
       
   335     CleanupStack::PushL( parentEntry );
       
   336     CPlainText* nullString = CPlainText::NewL();
       
   337     CleanupStack::PushL( nullString );
       
   338     CSmsHeader* header = CSmsHeader::NewL( CSmsPDU::ESmsDeliver, *nullString );
       
   339     CleanupStack::PushL( header );
       
   340     CMsvStore* store = parentEntry->ReadStoreL();
       
   341     CleanupStack::PushL( store );
       
   342     header->RestoreL( *store );
       
   343     aNumber = header->FromAddress();
       
   344     CleanupStack::PopAndDestroy( 4 ); // store, header, parentEntry, nullString
       
   345     }
       
   346 
       
   347 // ----------------------------------------------------
       
   348 // MceUtils::GetMmsNumberL
       
   349 // Gets phone number from MMS entry
       
   350 // ----------------------------------------------------
       
   351 void MceUtils::GetMmsNumberL( 
       
   352     TMsvEntry& aEntry, 
       
   353     CMsvSession& aSession,
       
   354     TPhCltTelephoneNumber& aNumber )
       
   355     {
       
   356     TMsvId id = aEntry.Id();
       
   357     CClientMtmRegistry* mtmRegistry = CClientMtmRegistry::NewL( aSession );
       
   358     CleanupStack::PushL( mtmRegistry );
       
   359 
       
   360     CMmsClientMtm* mmsMtm = (CMmsClientMtm *) mtmRegistry->NewMtmL( aEntry.iMtm );
       
   361     CleanupStack::PushL( mmsMtm );
       
   362     mmsMtm->SwitchCurrentEntryL( aEntry.Id() );
       
   363     mmsMtm->LoadMessageL();
       
   364     TPtrC sender = mmsMtm->Sender();
       
   365     aNumber = TMmsGenUtils::PureAddress( sender );
       
   366     CleanupStack::PopAndDestroy( 2 ); // mtmRegistry, mmsMtm
       
   367     }
       
   368 
       
   369 
       
   370 
       
   371 // ---------------------------------------------------------
       
   372 // MceUtils::StripAndAppendStringL
       
   373 // This is static function
       
   374 // ---------------------------------------------------------
       
   375 //
       
   376 void MceUtils::StripAndAppendStringL(
       
   377     TDes& aTargetString, 
       
   378     const TDesC& aSourceString, 
       
   379     TInt aDescriptionLength )
       
   380     {
       
   381     TBool addThreeDots = EFalse;
       
   382     
       
   383     if ( aDescriptionLength <= 0 )
       
   384         {
       
   385         aDescriptionLength = MceUtils::DescriptionLength();
       
   386         }
       
   387 
       
   388     TInt length = aSourceString.Left( aDescriptionLength ).Length();
       
   389     if ( length == 0 )
       
   390         {
       
   391         // append space, needed by list box
       
   392         aTargetString.Append( CEditableText::ESpace );
       
   393         return;
       
   394         }
       
   395 
       
   396     if ( aSourceString.Length() > length )
       
   397         {
       
   398         length--;
       
   399         addThreeDots = ETrue;
       
   400         }
       
   401         
       
   402     HBufC* tempString = aSourceString.Left( length ).AllocLC();
       
   403     TPtr tempStringPtr = tempString->Des();
       
   404     MceUtils::ReplaceCharacters( tempStringPtr );
       
   405     aTargetString.Append( tempStringPtr );
       
   406     CleanupStack::PopAndDestroy( tempString );
       
   407     if ( addThreeDots )
       
   408         {
       
   409         aTargetString.Append( CEditableText::EEllipsis );
       
   410         }
       
   411     }
       
   412     
       
   413     
       
   414 // ---------------------------------------------------------
       
   415 // MceUtils::DescriptionLength
       
   416 // This is static function
       
   417 // ---------------------------------------------------------
       
   418 //
       
   419 TInt MceUtils::DescriptionLength()
       
   420     {
       
   421     TInt descriptionLength = KMceVisibleTextLength;
       
   422     TRAPD( error, descriptionLength = MceUtils::DescriptionLengthL() );
       
   423     if ( error != KErrNone )
       
   424         {
       
   425         descriptionLength = KMceVisibleTextLength;
       
   426         }
       
   427     return descriptionLength;
       
   428     }
       
   429 
       
   430 // ---------------------------------------------------------
       
   431 // MceUtils::DescriptionLengthL
       
   432 // This is static function
       
   433 // ---------------------------------------------------------
       
   434 //
       
   435 TInt MceUtils::DescriptionLengthL()
       
   436     {
       
   437     TInt descriptionLength = KMceVisibleTextLength;
       
   438     CRepository* repository = CRepository::NewLC(KCRUidMuiuSettings);
       
   439         if ( repository->Get(KMuiuDescriptionLength, descriptionLength) != KErrNone )
       
   440             {
       
   441             descriptionLength = KMceVisibleTextLength;
       
   442             }
       
   443         if ( descriptionLength < KMceVisibleTextLength )
       
   444             {
       
   445             descriptionLength = KMceVisibleTextLength;
       
   446             }
       
   447     // How to make sure it is sensible?
       
   448     else if ( descriptionLength > 3*KMceVisibleTextLength )
       
   449             {
       
   450             descriptionLength = 3*KMceVisibleTextLength;
       
   451             }
       
   452         CleanupStack::PopAndDestroy( repository );
       
   453     return descriptionLength;
       
   454     }
       
   455 
       
   456 
       
   457 // ---------------------------------------------------------
       
   458 // MceUtils::IsMtmBuiltIn
       
   459 // This is static function
       
   460 // ---------------------------------------------------------
       
   461 //
       
   462 TBool MceUtils::IsMtmBuiltIn( TUid aMtmUid )
       
   463     {
       
   464     TBool mtmIsBuiltIn = EFalse;
       
   465     switch ( aMtmUid.iUid )
       
   466         {
       
   467         case KSenduiMtmSmtpUidValue:
       
   468         case KSenduiMtmImap4UidValue:
       
   469         case KSenduiMtmPop3UidValue:
       
   470         case KSenduiMtmSmsUidValue:
       
   471         case KSenduiMtmMmsUidValue:
       
   472         case KSenduiMtmIrUidValue:
       
   473         case KSenduiMtmBtUidValue:
       
   474         case KSenduiMtmPushMtmUidValue:
       
   475         case KSenduiMtmSyncMLEmailUidValue:
       
   476         case KSenduiMtmBioUidValue:
       
   477         case KSenduiMtmRoUidValue:
       
   478         case KSenduiMMSNotificationUidValue:
       
   479         case KSenduiMtmPostcardUidValue:
       
   480         case KSenduiMtmAudioMessageUidValue:
       
   481         case KSenduiMtmUniMessageUidValue:
       
   482             mtmIsBuiltIn = ETrue;
       
   483             break;
       
   484 
       
   485         default:
       
   486             break;
       
   487         }
       
   488     return mtmIsBuiltIn;        
       
   489     }
       
   490 
       
   491 // ---------------------------------------------------------
       
   492 // MceUtils::NumberGroupingEnabled
       
   493 // This is static function
       
   494 // ---------------------------------------------------------
       
   495 //
       
   496 TBool MceUtils::NumberGroupingEnabled()
       
   497     {
       
   498     TBool numberGroupingEnabled = EFalse;
       
   499     TRAPD( error, numberGroupingEnabled = MceUtils::NumberGroupingEnabledL() );
       
   500     if ( error != KErrNone )
       
   501         {
       
   502         numberGroupingEnabled = EFalse;
       
   503         }
       
   504     return numberGroupingEnabled;
       
   505     }
       
   506 
       
   507 // ---------------------------------------------------------
       
   508 // MceUtils::NumberGroupingEnabledL
       
   509 // This is static function
       
   510 // ---------------------------------------------------------
       
   511 //
       
   512 TBool MceUtils::NumberGroupingEnabledL()
       
   513     {
       
   514     TInt numberGrouping = 0;
       
   515     CRepository* repository = CRepository::NewL(KCRUidNumberGrouping);
       
   516     // CleanupStack is not needed since no leavable functions below
       
   517     if ( repository->Get(KNumberGrouping, numberGrouping) != KErrNone )
       
   518         {
       
   519         numberGrouping = 0;
       
   520         }
       
   521     delete repository;
       
   522     
       
   523     // CenRep key KCRUidNumberGrouping / KNumberGrouping is used to check if
       
   524     // number grouping is supported
       
   525     return ( numberGrouping == 1 );
       
   526 //    return FeatureManager::FeatureSupported( KFeatureIdPhoneNumberGrouping );
       
   527     }
       
   528 
       
   529 
       
   530 
       
   531 // ---------------------------------------------------------
       
   532 // TMceFlags::TMceFlags
       
   533 // This is static function
       
   534 // (other items were commented in a header).
       
   535 // ---------------------------------------------------------
       
   536 //
       
   537 TMceFlags::TMceFlags()
       
   538     :    
       
   539     iFlags( 0 )
       
   540     {
       
   541     }
       
   542 
       
   543 //  End of File