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