simpleengine/presenceprovisioning/src/presenceprovadapter.cpp
changeset 0 c8caa15ef882
child 25 e53c01f160bc
equal deleted inserted replaced
-1:000000000000 0:c8caa15ef882
       
     1 /*
       
     2 * Copyright (c) 2006 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:    Implementation for main Adapter class
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include <CWPCharacteristic.h>
       
    23 #include <WPAdapterUtil.h>
       
    24 #include <presenceprovisioningtexts.rsg>
       
    25 #include <pressettingsapi.h>
       
    26 
       
    27 #include "presenceprovitem.h"
       
    28 #include "presenceprovadapter.h"
       
    29 #include "presenceprovlogger.h"
       
    30 
       
    31 
       
    32 // ============================ MEMBER FUNCTIONS ===============================
       
    33 
       
    34 // -----------------------------------------------------------------------------
       
    35 // CPresProvAdapter::CPresProvAdapter
       
    36 //
       
    37 // -----------------------------------------------------------------------------
       
    38 //
       
    39 CPresProvAdapter::CPresProvAdapter()
       
    40     {    
       
    41     }
       
    42 
       
    43 // -----------------------------------------------------------------------------
       
    44 // CPresProvAdapter::ConstructL
       
    45 // Symbian 2nd phase constructor can leave.
       
    46 // -----------------------------------------------------------------------------
       
    47 //
       
    48 void CPresProvAdapter::ConstructL()
       
    49     {
       
    50     PRES_PROV_LOG(LOG_LIT8( "CPresProvItem::ConstructL"));
       
    51     // AdapterUtil needs the name of the resource file without the prefix and
       
    52     // the path returned by Dll::FileName. Note that Dll::FileName is an
       
    53     // undocumented method.
       
    54     //
       
    55     _LIT( KPresAdapterName, "PresenceProvisioningTexts");  //  presenceprovisioningtexts.rss
       
    56     TFileName fileName;
       
    57     Dll::FileName(fileName);
       
    58    
       
    59     iTitle       = WPAdapterUtil::ReadHBufCL( fileName,
       
    60                                               KPresAdapterName,
       
    61                                               R_QTN_OP_HEAD_PRESENCE);
       
    62     iDefaultName = WPAdapterUtil::ReadHBufCL( fileName,
       
    63                                               KPresAdapterName,
       
    64                                               R_QTN_OP_HEAD_PRESENCE);
       
    65                                               
       
    66     PRES_PROV_LOG(LOG_LIT8( " iTitle: %S"), &(*iTitle));
       
    67     PRES_PROV_LOG(LOG_LIT8( " iDefaultName: %S"), &(*iDefaultName));
       
    68     }
       
    69 
       
    70 // -----------------------------------------------------------------------------
       
    71 // CPresProvAdapter::NewL
       
    72 // Two-phased constructor.
       
    73 // -----------------------------------------------------------------------------
       
    74 //
       
    75 CPresProvAdapter* CPresProvAdapter::NewL()
       
    76     {
       
    77     PRES_PROV_LOG(LOG_LIT8( "CPresProvItem::NewL"));
       
    78     CPresProvAdapter* self = new(ELeave) CPresProvAdapter;
       
    79     CleanupStack::PushL(self);
       
    80     self->ConstructL();
       
    81     CleanupStack::Pop();
       
    82     return self;
       
    83     }
       
    84 
       
    85 // -----------------------------------------------------------------------------
       
    86 // CPresProvAdapter::~CPresProvAdapter
       
    87 // Destructor
       
    88 // -----------------------------------------------------------------------------
       
    89 //
       
    90 CPresProvAdapter::~CPresProvAdapter()
       
    91     {
       
    92     
       
    93     PRES_PROV_LOG(LOG_LIT8( "CPresProvAdapter::~CPresProvAdapter" ) );
       
    94     delete iTitle;
       
    95     delete iDefaultName;
       
    96     iProvItems.ResetAndDestroy();
       
    97     iProvItems.Close();
       
    98     }
       
    99 
       
   100 // -----------------------------------------------------------------------------
       
   101 // CPresProvAdapter::ItemCount
       
   102 // -----------------------------------------------------------------------------
       
   103 //
       
   104 TInt CPresProvAdapter::ItemCount() const
       
   105     {
       
   106     PRES_PROV_LOG(LOG_LIT8( "CPresProvAdapter::ItemCount returns %d" ), iProvItems.Count());
       
   107     return iProvItems.Count();  
       
   108     }
       
   109 
       
   110 // -----------------------------------------------------------------------------
       
   111 // CPresProvAdapter::SummaryTitle
       
   112 // -----------------------------------------------------------------------------
       
   113 //
       
   114 const TDesC16& CPresProvAdapter::SummaryTitle(TInt /*aIndex*/) const
       
   115     {
       
   116     PRES_PROV_LOG(LOG_LIT8( "CPresProvAdapter::SummaryTitle" ) );
       
   117     return *iTitle;
       
   118     }
       
   119 
       
   120 // -----------------------------------------------------------------------------
       
   121 // CPresProvAdapter::SummaryText
       
   122 // -----------------------------------------------------------------------------
       
   123 //
       
   124 const TDesC16& CPresProvAdapter::SummaryText( TInt aIndex ) const
       
   125     {
       
   126     PRES_PROV_LOG(LOG_LIT8( "CPresProvAdapter::SummaryText" ) );
       
   127     if( aIndex < iProvItems.Count() )
       
   128         {
       
   129         if( iProvItems[aIndex]->Name().Length() > 0 )
       
   130             {
       
   131             return iProvItems[aIndex]->Name();
       
   132             }
       
   133         }
       
   134     return *iDefaultName;   
       
   135     }
       
   136     
       
   137 // -----------------------------------------------------------------------------
       
   138 // CPresProvAdapter::SaveL
       
   139 // -----------------------------------------------------------------------------
       
   140 //
       
   141 void CPresProvAdapter::SaveL( TInt aItem )
       
   142     {
       
   143     PRES_PROV_LOG(LOG_LIT8( "CPresProvAdapter::SaveL done" ) );
       
   144     if ( aItem < iProvItems.Count() - 1 )
       
   145         {
       
   146         PRES_PROV_LOG(LOG_LIT8( " CPresProvAdapter::SaveL leaves with KErrArgument" ) );
       
   147         User::Leave ( KErrArgument );
       
   148         }
       
   149     iProvItems[aItem]->SaveL();
       
   150     PRES_PROV_LOG(LOG_LIT8( " CPresProvAdapter::SaveL done" ) );
       
   151     }
       
   152 
       
   153 // -----------------------------------------------------------------------------
       
   154 // CPresProvAdapter::CanSetAsDefault
       
   155 // -----------------------------------------------------------------------------
       
   156 //
       
   157 TBool CPresProvAdapter::CanSetAsDefault( TInt /*aItem*/ ) const
       
   158     {
       
   159     PRES_PROV_LOG(LOG_LIT8( "CPresProvAdapter::CanSetAsDefault" ) );
       
   160     return EFalse;
       
   161     }
       
   162 
       
   163 // -----------------------------------------------------------------------------
       
   164 // CPresProvAdapter::SetAsDefaultL
       
   165 // -----------------------------------------------------------------------------
       
   166 //
       
   167 void CPresProvAdapter::SetAsDefaultL( TInt /*aItem*/ )
       
   168     {
       
   169     PRES_PROV_LOG(LOG_LIT8( "CPresProvAdapter::SetAsDefaultL" ) );
       
   170     }
       
   171 
       
   172 // -----------------------------------------------------------------------------
       
   173 // CPresProvAdapter::DetailsL
       
   174 //
       
   175 // -----------------------------------------------------------------------------
       
   176 //
       
   177 TInt CPresProvAdapter::DetailsL( TInt /*aItem*/, MWPPairVisitor& /*aVisitor*/ )
       
   178     {
       
   179     PRES_PROV_LOG(LOG_LIT8( "CPresProvAdapter::DetailsL" ) );
       
   180     return KErrNotSupported;
       
   181     }
       
   182 
       
   183 // -----------------------------------------------------------------------------
       
   184 // CPresProvAdapter::VisitL
       
   185 // -----------------------------------------------------------------------------
       
   186 //
       
   187 void CPresProvAdapter::VisitL( CWPCharacteristic& aCharacteristic )
       
   188     {
       
   189     PRES_PROV_LOG(LOG_LIT8( "CPresProvAdapter::VisitL( CWPCharacteristic& aCharacteristic)" ) );
       
   190     if( aCharacteristic.Type() == KWPApplication )
       
   191         {       
       
   192         CPresProvItem* item = CPresProvItem::NewL();
       
   193         CleanupStack::PushL( item );
       
   194         aCharacteristic.AcceptL( *item );
       
   195     
       
   196         if( item->Validate() )
       
   197             {
       
   198             iProvItems.AppendL( item );
       
   199             CleanupStack::Pop( item );
       
   200             }
       
   201         else
       
   202             {
       
   203             CleanupStack::PopAndDestroy( item );                                
       
   204             }
       
   205         }
       
   206     }
       
   207         
       
   208 // -----------------------------------------------------------------------------
       
   209 // CPresProvAdapter::VisitL
       
   210 // -----------------------------------------------------------------------------
       
   211 //
       
   212 void CPresProvAdapter::VisitL( CWPParameter& /*aParameter*/ )
       
   213     {
       
   214     PRES_PROV_LOG(LOG_LIT8( "CPresProvAdapter::VisitL( CWPParameter& /*aParameter*/" ) );
       
   215     // Not used.
       
   216     }
       
   217 
       
   218 // -----------------------------------------------------------------------------
       
   219 // CPresProvAdapter::VisitLinkL
       
   220 // -----------------------------------------------------------------------------
       
   221 //
       
   222 void CPresProvAdapter::VisitLinkL( CWPCharacteristic& /*aLink*/ )
       
   223     {
       
   224     PRES_PROV_LOG(LOG_LIT8( "CPresProvAdapter::VisitLinkL( CWPCharacteristic& aLink" ) );
       
   225     // Not used.
       
   226     }
       
   227     
       
   228 // -----------------------------------------------------------------------------
       
   229 // CPresProvAdapter::SettingsSavedL
       
   230 // -----------------------------------------------------------------------------
       
   231 void CPresProvAdapter::SettingsSavedL( const TDesC8& aAppIdOfSavingItem,
       
   232                                       const TDesC8& aAppRef, 
       
   233                                       const TDesC8& aStorageIdValue )
       
   234     {
       
   235     PRES_PROV_LOG(LOG_LIT8( "CPresProvAdapter::SettingsSavedL" ) );
       
   236     PRES_PROV_LOG(LOG_LIT8( "   aAppIdOfSavingItem: %S, aAppRef: %S, aStorageIdValue: %S " )
       
   237                                 ,&aAppIdOfSavingItem, &aAppRef, &aStorageIdValue);
       
   238 
       
   239     // Convert aAppRef
       
   240     HBufC* appRef16 = HBufC::NewLC( aAppRef.Length() ); // << aAppRef16
       
   241     appRef16->Des().Copy( aAppRef );
       
   242     
       
   243     // Offer application references to all provisioned Pres settings
       
   244     // Only 2 possible, so performance doesnt matter
       
   245     for( TInt i(0); i < iProvItems.Count(); i++ )
       
   246         {
       
   247         CPresProvItem* item = iProvItems[i];
       
   248         const RArray<TPtrC>& toAppRefs = item->ToAppReferences();
       
   249     
       
   250         // Find application reference that is being offered
       
   251         for( TInt j(0); j < toAppRefs.Count(); j++ )
       
   252             {
       
   253             const TDesC& toAppRef = toAppRefs[j];
       
   254             if( !toAppRef.Compare( *appRef16 ) )
       
   255                 {
       
   256                 // Set correct application reference
       
   257                 if( !aAppIdOfSavingItem.Compare(KPresProvisioningSipId) )
       
   258                     {
       
   259                     item->SetSipSetIdL( DesToInt(aStorageIdValue) );
       
   260                     }
       
   261                 else if( !aAppIdOfSavingItem.Compare(KPresProvisioningXdmId) )
       
   262                     {
       
   263                     item->SetXDMSetIdL( DesToInt(aStorageIdValue) );
       
   264                     }   
       
   265                 }               
       
   266             }
       
   267         }
       
   268     CleanupStack::PopAndDestroy( appRef16 );    // >>> appRef16
       
   269     }
       
   270 
       
   271 // -----------------------------------------------------------------------------
       
   272 // CPresProvAdapter::GetSavingInfoL
       
   273 // -----------------------------------------------------------------------------
       
   274 void CPresProvAdapter::GetSavingInfoL( TInt aIndex,
       
   275                                       RPointerArray<HBufC8>& aSavingInfo )
       
   276     {
       
   277     PRES_PROV_LOG(LOG_LIT8( "CPresProvAdapter::GetSavingInfoL" ) );
       
   278     
       
   279     if ( aIndex < iProvItems.Count() - 1 )
       
   280         {
       
   281     PRES_PROV_LOG(LOG_LIT8( " CPresProvAdapter::GetSavingInfoL leaves with KErrArgument" ) );
       
   282 
       
   283         User::Leave ( KErrArgument );
       
   284         }
       
   285     TInt length ( iProvItems[aIndex]->AppReference().Length() );
       
   286     // if the APPREF exists
       
   287     if ( length > 0 )
       
   288         {
       
   289         // APPID into place [0].
       
   290         TPtrC8 appId ( KPresProvisioningAppId8 );
       
   291         HBufC8* appIdBuf = appId.AllocLC();             // << appIdBuf
       
   292         aSavingInfo.Append( appIdBuf );
       
   293         CleanupStack::Pop( appIdBuf );                  // >> appIdBuf
       
   294         appIdBuf = NULL;
       
   295         
       
   296         // APPREF into place [1].
       
   297         HBufC8* appRefBuf = HBufC8::NewLC( length );    // << appRefBuf
       
   298         TPtr8 appRef = appRefBuf->Des();
       
   299         appRef.Copy( iProvItems[aIndex]->AppReference() );
       
   300         aSavingInfo.Append( appRefBuf );
       
   301         CleanupStack::Pop( appRefBuf );                 // >> appRefBuf
       
   302         appRefBuf = NULL;
       
   303         
       
   304         // Pres settings id into place [2]. 
       
   305         // 10 = max length of 32bit integer
       
   306         HBufC8* idBuf = HBufC8::NewLC( 10 );            // << idBuf
       
   307         TPtr8 id = idBuf->Des();
       
   308         id.Num( iProvItems[aIndex]->PresSetId() );
       
   309         aSavingInfo.Append( idBuf );
       
   310         CleanupStack::Pop( idBuf );                     // >> idBuf
       
   311         idBuf = NULL;
       
   312         }
       
   313         
       
   314     PRES_PROV_LOG(LOG_LIT8( " CPresProvAdapter::GetSavingInfoL done" ) );
       
   315 
       
   316     }
       
   317     
       
   318 // -----------------------------------------------------------------------------
       
   319 // CPresProvAdapter::SavingFinalizedL()
       
   320 //
       
   321 // -----------------------------------------------------------------------------
       
   322 void CPresProvAdapter::SavingFinalizedL()
       
   323     {
       
   324     PRES_PROV_LOG(LOG_LIT8( "CPresProvAdapter::SavingFinalizedL" ) );
       
   325     }
       
   326     
       
   327 // ----------------------------------------------------------------------------
       
   328 // CPresProvAdapter::DesToInt
       
   329 // ----------------------------------------------------------------------------
       
   330 TInt CPresProvAdapter::DesToInt( const TDesC8& aSrcDes ) const
       
   331     {
       
   332     TLex8 lex( aSrcDes );
       
   333     TInt value ( KErrNotFound );
       
   334     lex.Val( value );
       
   335     return value;
       
   336     }    
       
   337     
       
   338 //  End of File