mobilemessaging/smum/src/SmumUtil.cpp
changeset 0 72b543305e3a
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     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 *       Finds default name for Service Centre and adds ordinal
       
    16 *       number in the end if it is needed.
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 
       
    22 // INCLUDE FILES
       
    23 #include <coemain.h>                    // CCoeEnv::Static()
       
    24 #include <SMUM.rsg>                     // resource identifiers
       
    25 #include <stringresourcereader.h>       // CStringResourceReader
       
    26 #include <StringLoader.h>               // StringLoader
       
    27 #include <aknnotewrappers.h>			// CAknInformationNote
       
    28 
       
    29 #include <smutset.h>                    // CSmsSettings
       
    30 #include "SmumUtil.h"                   // SmumUtil
       
    31 #include "SmumLogging.h"
       
    32 #include <messagingvariant.hrh>
       
    33 #include <RCustomerServiceProfileCache.h>
       
    34 #include "smsui.pan"                    // Panic codes
       
    35 #include <data_caging_path_literals.hrh>
       
    36 #include <centralrepository.h>          // CRepository
       
    37 #include <messaginginternalcrkeys.h>    // Keys
       
    38 
       
    39 // CONSTANTS
       
    40 _LIT(KFmtSpec, "%S(%02d)");
       
    41 _LIT(KSmumResourceFileName, "smum.rsc");
       
    42 const TInt KTestStringLength = 100;
       
    43 
       
    44 // ----------------------------------------------------
       
    45 // FindDefaultNameL
       
    46 // Finds default name for Service Centre and adds ordinal
       
    47 // number in the end if it is needed.
       
    48 // ----------------------------------------------------
       
    49 EXPORT_C void SmumUtil::FindDefaultNameForSCL(
       
    50     TDes& aName,
       
    51     TBool aNameIsForSCentreFromSIM,
       
    52     CDesCArrayFlat* aSCNamesList)
       
    53     { 
       
    54     // Parse the filename
       
    55     TFileName myFileName;
       
    56     TParse tp;
       
    57     tp.Set( KSmumResourceFileName, &KDC_MTM_RESOURCE_DIR, NULL );
       
    58     myFileName.Copy( tp.FullName() );
       
    59 
       
    60     // Initialise string resource reader
       
    61     CStringResourceReader* reader = CStringResourceReader::NewLC( myFileName );
       
    62  
       
    63     // Load default name without ordinals
       
    64     HBufC* buf = reader->ReadResourceString( aNameIsForSCentreFromSIM ? 
       
    65         R_QTN_MCE_SETTINGS_SIM_CENTRE : R_QTN_MCE_SETTINGS_SMS_SC_D_NAME ).AllocLC();
       
    66   
       
    67 
       
    68     TInt nameMaxLength = aName.MaxLength();
       
    69     if ( nameMaxLength < buf->Length())
       
    70         {
       
    71         User::Leave(KErrOverflow);
       
    72         }
       
    73     aName.Append(buf->Des());
       
    74 
       
    75     if (aSCNamesList)
       
    76         {
       
    77         // Launched from CSmsServiceCentresDialog, so we need
       
    78         // to check the list and use ordinals if needed
       
    79         const TInt lBoxCount = aSCNamesList->Count();
       
    80         TInt defOrdinal = 0;
       
    81         TBool nameAlreadyInUse = EFalse;
       
    82         TBool canExit = EFalse;
       
    83         
       
    84         if (lBoxCount)
       
    85             {
       
    86             while (!canExit)
       
    87                 {
       
    88                 // tried name already in use, let's increase ordinal
       
    89                 if (nameAlreadyInUse)
       
    90                     {                
       
    91                     TBuf<KTestStringLength> testBuf;
       
    92                     testBuf.Format( KFmtSpec, buf, defOrdinal );
       
    93                     if ( nameMaxLength < testBuf.Length() ) 
       
    94                         {
       
    95                         User::Leave( KErrOverflow );
       
    96                         }
       
    97                     aName.Format( KFmtSpec, buf, defOrdinal );
       
    98                     AknTextUtils::LanguageSpecificNumberConversion( aName );
       
    99                     nameAlreadyInUse = EFalse;
       
   100                     }        
       
   101                 // do we already have this name?
       
   102                 for ( TInt loop = 0; loop < lBoxCount && !nameAlreadyInUse; loop++ )
       
   103                     {
       
   104                     // yes
       
   105                     if ( KErrNotFound != aName.Match((*aSCNamesList)[loop]) )
       
   106                         {
       
   107                         nameAlreadyInUse = ETrue;
       
   108                         defOrdinal++;
       
   109                         }
       
   110                     // no, let's use it
       
   111                     else if ( loop == lBoxCount-1 )
       
   112                         {
       
   113                         canExit = ETrue;
       
   114                         }
       
   115                     }
       
   116                 }
       
   117             }
       
   118         }
       
   119     CleanupStack::PopAndDestroy( 2 ); // buf, reader 
       
   120     }
       
   121 
       
   122 // ----------------------------------------------------
       
   123 // SmumUtil::::ShowInformationNoteL
       
   124 //
       
   125 // ----------------------------------------------------
       
   126 void SmumUtil::ShowInformationNoteL( TInt aResource )
       
   127     {
       
   128     CCoeEnv* coeEnv = CEikonEnv::Static();
       
   129     __ASSERT_DEBUG( coeEnv, Panic( ESmumUtilNullPointer ) );
       
   130     if ( !coeEnv )
       
   131         {
       
   132         User::Leave( KErrGeneral );        
       
   133         }
       
   134     HBufC* text = StringLoader::LoadLC( aResource, coeEnv );
       
   135     CAknInformationNote* note = new ( ELeave ) CAknInformationNote( ETrue );
       
   136     note->ExecuteLD( *text );
       
   137     CleanupStack::PopAndDestroy(); // text
       
   138     }
       
   139     
       
   140 // ----------------------------------------------------------------------------
       
   141 // SmumUtil::CheckVariationFlagsL()
       
   142 // Function to check and set variation according to 
       
   143 // flags set in Central Repository
       
   144 // ----------------------------------------------------------------------------
       
   145 TInt SmumUtil::CheckVariationFlagsL( const TUid aUid, const TUint32 aKey )
       
   146     {
       
   147     TInt flags = KErrNotFound;
       
   148     // Create storage
       
   149     CRepository* storage = CRepository::NewLC( aUid );
       
   150     TInt error = storage->Get( aKey, flags ); 
       
   151     // Leave on error
       
   152     User::LeaveIfError( error );
       
   153     CleanupStack::PopAndDestroy(); // storage
       
   154     return flags;
       
   155     }    
       
   156 
       
   157 // ----------------------------------------------------
       
   158 // SmumUtil::ReadEmailOverSmsSettingsL
       
   159 // ----------------------------------------------------
       
   160 //
       
   161 EXPORT_C TInt SmumUtil::ReadEmailOverSmsSettingsL( 
       
   162     TDes& aSmsc, 
       
   163     TDes& aDestinationAddress,
       
   164     TBool& aModifiable )
       
   165     {
       
   166     SMUMLOGGER_ENTERFN("SmumUtil::ReadEmailOverSmsSettingsL")
       
   167 	// Create storage
       
   168     CRepository* storage = CRepository::NewLC( KCRUidSmum );
       
   169 	storage->Get( KSumEmailSC, aSmsc );
       
   170 	SMUMLOGGER_WRITE_FORMAT(
       
   171         "ReadEmailOverSmsSettingsL - SmsC: %s", aSmsc.Ptr() )
       
   172 	storage->Get( KSumEmailGateway, aDestinationAddress );
       
   173 	SMUMLOGGER_WRITE_FORMAT(
       
   174         "ReadEmailOverSmsSettingsL - Gateway: %s", aDestinationAddress.Ptr() )
       
   175 	storage->Get( KSumEmailModifiable, aModifiable );
       
   176 	SMUMLOGGER_WRITE_FORMAT("ReadEmailOverSmsSettingsL - Modifiable: %d", aModifiable)
       
   177     CleanupStack::PopAndDestroy(); // storage
       
   178     SMUMLOGGER_LEAVEFN("SmumUtil::ReadEmailOverSmsSettingsL")
       
   179     return KErrNone;
       
   180     }
       
   181 
       
   182 // ----------------------------------------------------
       
   183 // SmumUtil::WriteEmailOverSmsSettingsL
       
   184 // ----------------------------------------------------
       
   185 //
       
   186 EXPORT_C TInt SmumUtil::WriteEmailOverSmsSettingsL( 
       
   187     const TDes& aSmsc, 
       
   188     const TDes& aDestinationAddress,
       
   189     const TBool& aModifiable )
       
   190     {
       
   191     SMUMLOGGER_ENTERFN("SmumUtil::WriteEmailOverSmsSettingsL")
       
   192     // Create storage
       
   193     CRepository* storage = CRepository::NewLC( KCRUidSmum );
       
   194 	storage->Set( KSumEmailSC, aSmsc );
       
   195 	SMUMLOGGER_WRITE_FORMAT(
       
   196         "WriteEmailOverSmsSettingsL - SmsC: %s", aSmsc.Ptr() )
       
   197 	storage->Set( KSumEmailGateway, aDestinationAddress );
       
   198 	SMUMLOGGER_WRITE_FORMAT(
       
   199     	"WriteEmailOverSmsSettingsL - Gateway: %s", aDestinationAddress.Ptr() )
       
   200 	storage->Set( KSumEmailModifiable, aModifiable );
       
   201 	SMUMLOGGER_WRITE_FORMAT("WriteEmailOverSmsSettingsL - Modifiable: #%d", aModifiable)
       
   202     CleanupStack::PopAndDestroy(); // storage
       
   203     SMUMLOGGER_LEAVEFN("SmumUtil::WriteEmailOverSmsSettingsL")
       
   204     return KErrNone;
       
   205     }
       
   206 
       
   207 // ----------------------------------------------------
       
   208 // SmumUtil::CheckEmailOverSmsSupportL
       
   209 //
       
   210 // ----------------------------------------------------
       
   211 EXPORT_C TBool SmumUtil::CheckEmailOverSmsSupportL()
       
   212     {
       
   213     SMUMLOGGER_ENTERFN("SmumUtil::CheckEmailOverSmsSupportL")
       
   214     TBool emailSupported( EFalse );
       
   215     TInt tmpInt( KErrNotFound );
       
   216     tmpInt = CheckVariationFlagsL( KCRUidMuiuVariation, KMuiuSmsFeatures );
       
   217     if ( tmpInt & KSmsFeatureIdEmailOverSms ) 
       
   218         { // Feature is supported by S60 local variation
       
   219         SMUMLOGGER_WRITE_FORMAT(
       
   220             "CheckEmailOverSmsSupportL - KSmsFeatureIdEmailOverSms :%d",
       
   221             tmpInt )
       
   222         // Now we must check if the feature is supported by 
       
   223         // Value Added Services, (U)SIM bit
       
   224         emailSupported = ReadEmailSupportFromVASL();
       
   225         SMUMLOGGER_WRITE_FORMAT(
       
   226             "CheckEmailOverSmsSupportL - ReadEmailSupportFromVASL returned :%d",
       
   227             emailSupported )
       
   228         }
       
   229     SMUMLOGGER_WRITE_FORMAT(
       
   230                 "CheckEmailOverSmsSupportL - EmailOverSmsSupport :%d",
       
   231                 emailSupported )
       
   232     SMUMLOGGER_LEAVEFN("SmumUtil::CheckEmailOverSmsSupportL")
       
   233     return emailSupported;
       
   234     }
       
   235 
       
   236 // ---------------------------------------------------------------------------
       
   237 // SmumUtil::ReadEmailSupportFromVASL
       
   238 // 
       
   239 // ---------------------------------------------------------------------------
       
   240 TBool SmumUtil::ReadEmailSupportFromVASL()
       
   241     {
       
   242     SMUMLOGGER_ENTERFN("CSmumMainSettingsDialogGSM::ReadEmailSupportFromVASL")
       
   243     TBool featureSupport( EFalse );
       
   244     RCustomerServiceProfileCache* cspProfile = 
       
   245         new (ELeave) RCustomerServiceProfileCache;    
       
   246     __ASSERT_DEBUG( cspProfile, Panic( ESmsuNullPointer ) );
       
   247     TInt error = cspProfile->Open();
       
   248     if( KErrNone == error )
       
   249         {
       
   250         // Get tele services flags from CSP
       
   251         RMobilePhone::TCspValueAdded params;
       
   252         // If not supported (-5) or any other error
       
   253         // we assume all settings are supported
       
   254         error = cspProfile->CspCPHSValueAddedServices( params );
       
   255         if ( KErrNone == error ) 
       
   256             {
       
   257             SMUMLOGGER_WRITE_FORMAT(
       
   258                 "ReadEmailSupportFromVASL - RMobilePhone::TCspTeleservices #%d", params )
       
   259             if( 0 != ( params&RMobilePhone::KCspSMMOEmail ) ) 
       
   260                 {
       
   261                 SMUMLOGGER_WRITE(
       
   262                     "ReadEmailSupportFromVASL - KCspSMMOEmail supported" )
       
   263                 featureSupport = ETrue;
       
   264                 }
       
   265             }
       
   266         else
       
   267             {
       
   268             SMUMLOGGER_WRITE_FORMAT(
       
   269                 "ReadEmailSupportFromVASL - cspProfile->CspTeleServices() #%d", error )
       
   270             }
       
   271         cspProfile->Close();
       
   272         }
       
   273     else
       
   274         {
       
   275         SMUMLOGGER_WRITE_FORMAT(
       
   276                 "ReadEmailSupportFromVASL - cspProfile->Open() #%d", error )
       
   277         }
       
   278     delete cspProfile;    
       
   279     SMUMLOGGER_LEAVEFN("CSmumMainSettingsDialogGSM::ReadEmailSupportFromVASL")
       
   280     return featureSupport;
       
   281     }
       
   282 
       
   283 //  End of File