omaprovisioning/provisioning/MbxNbrAdapter/Src/MbxNbrAdapter.cpp
branchRCL_3
changeset 25 b183ec05bd8c
parent 24 13d7c31c74e0
child 26 19bba8228ff0
equal deleted inserted replaced
24:13d7c31c74e0 25:b183ec05bd8c
     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:  Handles mailbox number settings in OMA provisioning.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include    <f32file.h>
       
    21 #include    <CWPCharacteristic.h>
       
    22 #include    <CWPParameter.h>
       
    23 #include    <wpmbxnbradapterresource.rsg>
       
    24 #include    <vmnumber.h>
       
    25 #include    <commonphoneparser.h>
       
    26 #include 	<voicemailboxdomaincrkeys.h>
       
    27 #include 	<centralrepository.h>
       
    28 
       
    29 #include    "WPAdapterUtil.h"
       
    30 #include    "MbxNbrAdapter.h"
       
    31 #include    "ProvisioningDebug.h"
       
    32 
       
    33 // CONSTANTS
       
    34 #if ( defined (__WINS__) || defined (__WINSCW) ) // this different on hw
       
    35     _LIT( KAdapterName, "WPMbxNbrAdapterResource" );
       
    36 #else
       
    37     _LIT( KAdapterName, "WPMbxNbrAdapter" );
       
    38 #endif
       
    39 _LIT( KMailboxNumberStr, "MBNMBR" );
       
    40 _LIT( KMailboxTypeStr, "MBTYPE" );
       
    41 _LIT( KCSVideoMailboxType, "VIDEO" );
       
    42 _LIT( KVideoSupportType, "VIDEO_MBOX_SUPPORT" );
       
    43 _LIT( KVideoSupportTypeTrue, "TRUE" );
       
    44 _LIT( KVideoSupportTypeFalse, "FALSE" );
       
    45 _LIT( KMailboxAppId, "w9027" );        // From OMA provisioning registration document
       
    46 const TInt KSettingsGranularity = 2;
       
    47 
       
    48 // ============================ MEMBER FUNCTIONS ===============================
       
    49 
       
    50 // -----------------------------------------------------------------------------
       
    51 // CMbxNbrAdapter::CMbxNbrAdapter
       
    52 // C++ default constructor can NOT contain any code, that
       
    53 // might leave.
       
    54 // -----------------------------------------------------------------------------
       
    55 //
       
    56 CMbxNbrAdapter::CMbxNbrAdapter() : 
       
    57     iSettings( KSettingsGranularity )
       
    58     {
       
    59     }
       
    60 
       
    61 // -----------------------------------------------------------------------------
       
    62 // CMbxNbrAdapter::ConstructL
       
    63 // Symbian 2nd phase constructor can leave.
       
    64 // -----------------------------------------------------------------------------
       
    65 //
       
    66 void CMbxNbrAdapter::ConstructL()
       
    67     {
       
    68     FLOG( _L( "[Provisioning] CMbxNbrAdapter::ConstructL:" ) );
       
    69     
       
    70     TFileName fileName;
       
    71     Dll::FileName( fileName );
       
    72     iTitle = WPAdapterUtil::ReadHBufCL( fileName,
       
    73                                         KAdapterName,
       
    74                                         R_MAILBOX_NUMBER_ADAPTER_TITLE );
       
    75                                         
       
    76     FLOG( _L( "[Provisioning] CMbxNbrAdapter::ConstructL: Done" ) );
       
    77     }
       
    78 
       
    79 // -----------------------------------------------------------------------------
       
    80 // CMbxNbrAdapter::NewL
       
    81 // Two-phased constructor.
       
    82 // -----------------------------------------------------------------------------
       
    83 //
       
    84 CMbxNbrAdapter* CMbxNbrAdapter::NewL()
       
    85     {
       
    86     CMbxNbrAdapter* self = new( ELeave ) CMbxNbrAdapter; 
       
    87     CleanupStack::PushL( self );
       
    88     self->ConstructL();
       
    89     CleanupStack::Pop( self );
       
    90 
       
    91     return self;
       
    92     }
       
    93 
       
    94 // -----------------------------------------------------------------------------
       
    95 // CMbxNbrAdapter::~CMbxNbrAdapter
       
    96 // Destructor
       
    97 // -----------------------------------------------------------------------------
       
    98 //
       
    99 CMbxNbrAdapter::~CMbxNbrAdapter()
       
   100     {
       
   101     delete iTitle;
       
   102     iSettings.Close();
       
   103     }
       
   104 
       
   105 // -----------------------------------------------------------------------------
       
   106 // CMbxNbrAdapter::ItemCount
       
   107 // -----------------------------------------------------------------------------
       
   108 //
       
   109 TInt CMbxNbrAdapter::ItemCount() const
       
   110     {
       
   111 	// SummaryTitle(), SummaryText(), SaveL(), SetAsDefaultL() and 
       
   112 	// CanSetAsDefault() are called ItemCount() times
       
   113 	return iSettings.Count();
       
   114     }
       
   115 
       
   116 // -----------------------------------------------------------------------------
       
   117 // CMbxNbrAdapter::SummaryTitle
       
   118 // -----------------------------------------------------------------------------
       
   119 //
       
   120 const TDesC16& CMbxNbrAdapter::SummaryTitle( TInt /*aIndex*/ ) const
       
   121     {
       
   122     return *iTitle;
       
   123     }
       
   124 
       
   125 // -----------------------------------------------------------------------------
       
   126 // CMbxNbrAdapter::SummaryText
       
   127 // -----------------------------------------------------------------------------
       
   128 //
       
   129 const TDesC16& CMbxNbrAdapter::SummaryText( TInt aIndex ) const
       
   130     {
       
   131     // SummaryText should be called ItemCount() times
       
   132     __ASSERT_DEBUG( iSettings.Count() > aIndex, 
       
   133         User::Panic( _L("CMbxNbrAdapter::SummaryText"),  KErrCorrupt ) );
       
   134     __ASSERT_DEBUG( aIndex >= 0, 
       
   135         User::Panic( _L("CMbxNbrAdapter::SummaryText"),  KErrCorrupt ) );              
       
   136     return iSettings[ aIndex ].iName;
       
   137     }
       
   138 
       
   139 // -----------------------------------------------------------------------------
       
   140 // CMbxNbrAdapter::DetailsL
       
   141 // -----------------------------------------------------------------------------
       
   142 //
       
   143 TInt CMbxNbrAdapter::DetailsL( TInt /*aItem*/, MWPPairVisitor& /*aVisitor*/ )
       
   144     {
       
   145     // Detail view is a feature for later release.
       
   146     return KErrNotSupported;
       
   147     }
       
   148 
       
   149 // -----------------------------------------------------------------------------
       
   150 // CMbxNbrAdapter::SaveL
       
   151 // -----------------------------------------------------------------------------
       
   152 //
       
   153 void CMbxNbrAdapter::SaveL( TInt aItem )
       
   154     {
       
   155     FLOG( _L( "[Provisioning] CMbxNbrAdapter::SaveL:" ) );
       
   156     __ASSERT_DEBUG( iSettings.Count() > aItem, User::Leave( KErrCorrupt ) ); 
       
   157     __ASSERT_DEBUG( aItem >= 0, User::Leave( KErrCorrupt ) ); 
       
   158    
       
   159     RVmbxNumber model;
       
   160     User::LeaveIfError( model.Open() );
       
   161     CleanupClosePushL( model );  
       
   162        
       
   163     TInt err( KErrNone );    
       
   164     switch( iSettings[aItem].iMailboxType )
       
   165         {
       
   166         case ECSVoiceMailbox:
       
   167             err = model.SaveVmbxNumber( iSettings[aItem].iMailboxNumber, 
       
   168                                         EAlsActiveLineEntry );
       
   169             break;
       
   170         case ECSVideoMailbox:
       
   171         FLOG( _L( "[Provisioning] CMbxNbrAdapter::SaveL:case ECSVideoMailbox" ) );
       
   172             err = model.SaveVideoMbxNumber( iSettings[aItem].iMailboxNumber, 
       
   173                                             EAlsActiveLineEntry );        
       
   174             if ( iSettings[aItem].iIsVideosupport )
       
   175             {
       
   176             CRepository* cenrep = CRepository::NewL( KCRUidVideoMailbox );
       
   177 	        FLOG( _L( "[Provisioning] CMbxNbrAdapter::SaveL:case Saving it to Cenrep" ) );
       
   178 	        TBuf<100> buf1;
       
   179 	        buf1.AppendNum( iSettings[aItem].iVidiosupport );
       
   180 	        
       
   181 	        FLOG( buf1 );
       
   182             CleanupStack::PushL(cenrep);
       
   183 			User::LeaveIfError(
       
   184 			cenrep->Set( KVideoMbxSupport, iSettings[aItem].iVidiosupport )); 
       
   185 			FLOG( _L( "[Provisioning] CMbxNbrAdapter::SaveL:case Saved" ) );
       
   186 			CleanupStack::PopAndDestroy(cenrep);
       
   187             }
       
   188             break;
       
   189         default:
       
   190             User::Leave( KErrCorrupt );
       
   191             break;  
       
   192         }
       
   193 
       
   194     User::LeaveIfError( err );        
       
   195     CleanupStack::PopAndDestroy();  // Close model
       
   196     
       
   197     FLOG( _L( "[Provisioning] CStreamingAdapter::SaveL: Done" ) );
       
   198     }
       
   199 
       
   200 // -----------------------------------------------------------------------------
       
   201 // CMbxNbrAdapter::CanSetAsDefault
       
   202 // -----------------------------------------------------------------------------
       
   203 //
       
   204 TBool CMbxNbrAdapter::CanSetAsDefault( TInt /*aItem*/ ) const
       
   205     {
       
   206     return EFalse;
       
   207     }
       
   208 
       
   209 // -----------------------------------------------------------------------------
       
   210 // CMbxNbrAdapter::SetAsDefault
       
   211 // -----------------------------------------------------------------------------
       
   212 //
       
   213 void CMbxNbrAdapter::SetAsDefaultL( TInt /*aItem*/ )
       
   214     {
       
   215     // This shouldn't be called because CanSetAsDefault
       
   216     // always returns EFalse.
       
   217     }
       
   218 
       
   219 // -----------------------------------------------------------------------------
       
   220 // CMbxNbrAdapter::VisitL
       
   221 // -----------------------------------------------------------------------------
       
   222 //
       
   223 void CMbxNbrAdapter::VisitL( CWPCharacteristic& aCharacteristic )
       
   224     {
       
   225     switch( aCharacteristic.Type() )
       
   226         {
       
   227         case KWPApplication:
       
   228             // Initialize iTempData's members
       
   229             iTempData.iName.Set( KNullDesC );
       
   230             iTempData.iMailboxNumber.Set( KNullDesC );
       
   231             iTempData.iVidiosupport = EFalse;
       
   232             iTempData.iIsVideosupport = EFalse;
       
   233             iTempData.iMailboxType = ECSVoiceMailbox;
       
   234 
       
   235             // Accept characteristic
       
   236             aCharacteristic.AcceptL( *this );
       
   237 
       
   238             // Check iAppId and validate data
       
   239             if( iAppId == KMailboxAppId && IsValid() )
       
   240                 {
       
   241                 // iAppId is correct and data is valid
       
   242                 // -> Lets append it to array                
       
   243                 iSettings.Append( iTempData );
       
   244                 }
       
   245             break;
       
   246         default:
       
   247             break;
       
   248         }
       
   249     }
       
   250 
       
   251 // -----------------------------------------------------------------------------
       
   252 // CMbxNbrAdapter::VisitL
       
   253 // -----------------------------------------------------------------------------
       
   254 //
       
   255 void CMbxNbrAdapter::VisitL( CWPParameter& aParameter )
       
   256     {   
       
   257     switch( aParameter.ID() )
       
   258         {
       
   259         case EWPParameterAppID:
       
   260             iAppId.Set( aParameter.Value() );
       
   261             break;
       
   262         case EWPParameterName:
       
   263             iTempData.iName.Set( aParameter.Value() );
       
   264             break;
       
   265 		case EWPNamedParameter:
       
   266 			{
       
   267 			if( aParameter.Name().Compare( KMailboxNumberStr ) == 0 )
       
   268 			    {
       
   269 			    iTempData.iMailboxNumber.Set( aParameter.Value() );
       
   270 			    }
       
   271 			else if( aParameter.Name().Compare( KMailboxTypeStr ) == 0 )
       
   272 			    {
       
   273 			    ParseMbxTypeL( aParameter.Value(), iTempData.iMailboxType );
       
   274 			    }
       
   275 			else if( aParameter.Name().Compare( KVideoSupportType ) == 0)
       
   276 				{
       
   277 			FLOG( _L( "[Provisioning] CMbxNbrAdapter::VisitL:Visiting to ParseVideoTypeL" ) );
       
   278 				ParseVideoTypeL( aParameter.Value(), iTempData.iVidiosupport, iTempData.iIsVideosupport );	
       
   279 			    }
       
   280 			break;
       
   281 			}
       
   282         default:
       
   283             break;
       
   284         }
       
   285     }
       
   286 
       
   287 // -----------------------------------------------------------------------------
       
   288 // CMbxNbrAdapter::VisitLinkL
       
   289 // -----------------------------------------------------------------------------
       
   290 //
       
   291 void CMbxNbrAdapter::VisitLinkL( CWPCharacteristic& /*aCharacteristic*/ )
       
   292     { 
       
   293     }
       
   294 
       
   295 
       
   296 // -----------------------------------------------------------------------------
       
   297 // CMbxNbrAdapter::IsValid
       
   298 // -----------------------------------------------------------------------------
       
   299 //
       
   300 TBool CMbxNbrAdapter::IsValid()
       
   301     {
       
   302     TBool validity( EFalse );
       
   303     
       
   304     // Validity check:
       
   305     //  iMailboxType is either ECSVideoMailbox or ECSVoiceMailbox and
       
   306     //  iMailboxNumber is valid number in e.164 format  
       
   307     if( ( iTempData.iMailboxType == ECSVideoMailbox || 
       
   308         iTempData.iMailboxType == ECSVoiceMailbox ) &&
       
   309         IsValidPhoneNumber( iTempData.iMailboxNumber ) )
       
   310         {
       
   311         validity = ETrue;
       
   312         }    
       
   313         
       
   314     return validity;
       
   315     }
       
   316     
       
   317 // -----------------------------------------------------------------------------
       
   318 // CMbxNbrAdapter::IsValidPhoneNumber
       
   319 // -----------------------------------------------------------------------------
       
   320 //
       
   321 TBool CMbxNbrAdapter::IsValidPhoneNumber( const TDesC& aPtr ) 
       
   322     {
       
   323     return CommonPhoneParser::IsValidPhoneNumber( aPtr, 
       
   324                                 CommonPhoneParser::EPhoneClientNumber );
       
   325     }       
       
   326     
       
   327 // -----------------------------------------------------------------------------
       
   328 // CMbxNbrAdapter::ParseMbxTypeL
       
   329 // -----------------------------------------------------------------------------
       
   330 //
       
   331 void CMbxNbrAdapter::ParseMbxTypeL( const TDesC& aPtr, TMailboxType& aType ) 
       
   332     {
       
   333     if( aPtr.Length() )
       
   334         {
       
   335         if( aPtr.Compare( KCSVideoMailboxType ) == 0 )
       
   336             {
       
   337             aType = ECSVideoMailbox;   
       
   338             }
       
   339         else
       
   340             {
       
   341             User::Leave( KErrNotSupported );
       
   342             }
       
   343         }
       
   344     else
       
   345         {
       
   346         aType = ECSVoiceMailbox;
       
   347         }
       
   348     }
       
   349 // -----------------------------------------------------------------------------
       
   350 // CMbxNbrAdapter::ParseVideoTypeL
       
   351 // -----------------------------------------------------------------------------
       
   352 //
       
   353 void CMbxNbrAdapter::ParseVideoTypeL( const TDesC& aPtr, TBool& aType, TBool& aType1 ) 
       
   354     {
       
   355     FLOG( _L( "[Provisioning] CMbxNbrAdapter::ParseVideoTypeL:in" ) );
       
   356     if( aPtr.Length() )
       
   357         {
       
   358         FLOG( _L( "[Provisioning] CMbxNbrAdapter::ParseVideoTypeL:If there is ON/OFF Value" ) );
       
   359         if( aPtr.Compare( KVideoSupportTypeTrue ) == 0 )
       
   360             {
       
   361             FLOG( _L( "[Provisioning] CMbxNbrAdapter::ParseVideoTypeL:if ON set TRUE" ) );
       
   362             aType = ETrue;
       
   363             aType1 = ETrue;
       
   364             }
       
   365         else if( aPtr.Compare( KVideoSupportTypeFalse ) == 0 )
       
   366             {
       
   367             FLOG( _L( "[Provisioning] CMbxNbrAdapter::ParseVideoTypeL:if OFF set False" ) );
       
   368             aType = EFalse;
       
   369             aType1 = ETrue;
       
   370             }
       
   371         else
       
   372         {
       
   373         	FLOG( _L( "[Provisioning] CMbxNbrAdapter::ParseVideoTypeL:if some thing else set False" ) );
       
   374         	aType1 = EFalse;
       
   375         }
       
   376         }
       
   377     else
       
   378         {
       
   379         FLOG( _L( "[Provisioning] CMbxNbrAdapter::ParseVideoTypeL:no ON/OFF" ) );
       
   380         aType1 = EFalse;
       
   381         }
       
   382     }
       
   383 	
       
   384 //  End of File