phonebookengines/VirtualPhonebook/VPbkSimStoreImpl/src/CVPbkSimContact.cpp
branchRCL_3
changeset 63 f4a778e096c2
child 64 c1e8ba0c2b16
child 85 38bb213f60ba
equal deleted inserted replaced
62:5b6f26637ad3 63:f4a778e096c2
       
     1 /*
       
     2 * Copyright (c) 2002-2007 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:  The sim contact
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <featmgr.h>
       
    22 #include "CVPbkSimContact.h"
       
    23 
       
    24 #include "CVPbkSimCntField.h"
       
    25 #include "MVPbkSimCntStore.h"
       
    26 #include "CVPbkETelCntConverter.h"
       
    27 #include "VPbkSimStoreTemplateFunctions.h"
       
    28 #include "VPbkSimStoreImplError.h"
       
    29 
       
    30 // ============================ MEMBER FUNCTIONS ===============================
       
    31 
       
    32 // -----------------------------------------------------------------------------
       
    33 // CVPbkSimContact::CVPbkSimContact
       
    34 // C++ default constructor can NOT contain any code, that
       
    35 // might leave.
       
    36 // -----------------------------------------------------------------------------
       
    37 //
       
    38 CVPbkSimContact::CVPbkSimContact( MVPbkSimCntStore& aSimStore )
       
    39 :   CVPbkSimContactBase( aSimStore ),
       
    40     iSimIndex( KVPbkSimStoreFirstFreeIndex )
       
    41     {
       
    42     }
       
    43 
       
    44 // -----------------------------------------------------------------------------
       
    45 // CVPbkSimContact::ConstructL
       
    46 // Symbian 2nd phase constructor can leave.
       
    47 // -----------------------------------------------------------------------------
       
    48 //
       
    49 void CVPbkSimContact::ConstructL( const TDesC8* aETelContact )
       
    50     {
       
    51     if ( aETelContact )
       
    52         {
       
    53         SetL( *aETelContact );
       
    54         if( FeatureManager::FeatureSupported( KFeatureIdFfTdClmcontactreplicationfromphonebooktousimcard ) )
       
    55         	{
       
    56 			IndentifyAdditionalFields();
       
    57         	}
       
    58         }
       
    59     }
       
    60 
       
    61 // -----------------------------------------------------------------------------
       
    62 // CVPbkSimContact::NewL
       
    63 // Two-phased constructor.
       
    64 // -----------------------------------------------------------------------------
       
    65 //
       
    66 EXPORT_C CVPbkSimContact* CVPbkSimContact::NewL( const TDesC8& aETelContact,
       
    67     MVPbkSimCntStore& aSimStore )
       
    68     {
       
    69     CVPbkSimContact* self = NewLC( aETelContact, aSimStore );
       
    70     CleanupStack::Pop();
       
    71     return self;
       
    72     }
       
    73 
       
    74 // -----------------------------------------------------------------------------
       
    75 // CVPbkSimContact::NewL
       
    76 // Two-phased constructor.
       
    77 // -----------------------------------------------------------------------------
       
    78 //
       
    79 EXPORT_C CVPbkSimContact* CVPbkSimContact::NewL( MVPbkSimCntStore& aSimStore )
       
    80     {
       
    81     CVPbkSimContact* self = NewLC( aSimStore );
       
    82     CleanupStack::Pop();
       
    83     return self;
       
    84     }
       
    85 
       
    86 // -----------------------------------------------------------------------------
       
    87 // CVPbkSimContact::NewLC
       
    88 // Two-phased constructor.
       
    89 // -----------------------------------------------------------------------------
       
    90 //
       
    91 EXPORT_C CVPbkSimContact* CVPbkSimContact::NewLC( const TDesC8& aETelContact,
       
    92     MVPbkSimCntStore& aSimStore )
       
    93     {
       
    94     CVPbkSimContact* self = new( ELeave ) CVPbkSimContact( aSimStore );
       
    95     CleanupStack::PushL( self );
       
    96     self->ConstructL( &aETelContact );
       
    97     return self;
       
    98     }
       
    99 
       
   100 // -----------------------------------------------------------------------------
       
   101 // CVPbkSimContact::NewLC
       
   102 // Two-phased constructor.
       
   103 // -----------------------------------------------------------------------------
       
   104 //
       
   105 EXPORT_C CVPbkSimContact* CVPbkSimContact::NewLC( MVPbkSimCntStore& aSimStore )
       
   106     {
       
   107     CVPbkSimContact* self = new( ELeave ) CVPbkSimContact( aSimStore );
       
   108     CleanupStack::PushL( self );
       
   109     self->ConstructL( NULL );
       
   110     return self;
       
   111     }
       
   112 
       
   113 // Destructor
       
   114 CVPbkSimContact::~CVPbkSimContact()
       
   115     {
       
   116     iFieldArray.ResetAndDestroy();
       
   117     iFieldArray.Close();
       
   118     delete iData;
       
   119     }
       
   120 
       
   121 // -----------------------------------------------------------------------------
       
   122 // CVPbkSimContact::CreateFieldLC
       
   123 // -----------------------------------------------------------------------------
       
   124 //
       
   125 EXPORT_C CVPbkSimCntField* CVPbkSimContact::CreateFieldLC( 
       
   126     TVPbkSimCntFieldType aType ) const
       
   127     {
       
   128     return CVPbkSimCntField::NewLC( aType, *this );
       
   129     }
       
   130 
       
   131 // -----------------------------------------------------------------------------
       
   132 // CVPbkSimContact::DeleteField
       
   133 // -----------------------------------------------------------------------------
       
   134 //
       
   135 EXPORT_C void CVPbkSimContact::DeleteField( TInt aIndex )
       
   136     {
       
   137     delete iFieldArray[aIndex];
       
   138     iFieldArray.Remove( aIndex );
       
   139     }
       
   140 
       
   141 // -----------------------------------------------------------------------------
       
   142 // CVPbkSimContact::AddFieldL
       
   143 // -----------------------------------------------------------------------------
       
   144 //
       
   145 EXPORT_C void CVPbkSimContact::AddFieldL( CVPbkSimCntField* aField )
       
   146     {
       
   147     if ( aField )
       
   148         {
       
   149         iFieldArray.AppendL( aField ); 
       
   150         }
       
   151     }
       
   152 
       
   153 // -----------------------------------------------------------------------------
       
   154 // CVPbkSimContact::DeleteAllFields
       
   155 // -----------------------------------------------------------------------------
       
   156 //
       
   157 EXPORT_C void CVPbkSimContact::DeleteAllFields()
       
   158     {
       
   159     for ( TInt i = iFieldArray.Count() - 1; i >= 0; --i )
       
   160         {
       
   161         // Destroys instances but doesn't free the array memory
       
   162         DeleteField( i );
       
   163         }
       
   164     }
       
   165 
       
   166 // -----------------------------------------------------------------------------
       
   167 // CVPbkSimContact::SaveL
       
   168 // -----------------------------------------------------------------------------
       
   169 //
       
   170 EXPORT_C MVPbkSimStoreOperation* CVPbkSimContact::SaveL( 
       
   171         MVPbkSimContactObserver& aObserver )
       
   172     {
       
   173     __ASSERT_DEBUG( iFieldArray.Count() > 0,
       
   174         VPbkSimStoreImpl::Panic( VPbkSimStoreImpl::EZeroFieldCount ) );
       
   175     // Convert to ETel contact
       
   176     CreateETelContactL();
       
   177     return iStore.SaveL( *iData, iSimIndex, aObserver );
       
   178     }
       
   179 
       
   180 // -----------------------------------------------------------------------------
       
   181 // CVPbkSimContact::SetSimIndex
       
   182 // -----------------------------------------------------------------------------
       
   183 //
       
   184 void CVPbkSimContact::SetSimIndex( TInt aSimIndex )
       
   185     {
       
   186     iSimIndex = aSimIndex;
       
   187     }
       
   188 
       
   189 // -----------------------------------------------------------------------------
       
   190 // CVPbkSimContact::ConstFieldAt
       
   191 // -----------------------------------------------------------------------------
       
   192 //
       
   193 const CVPbkSimCntField& CVPbkSimContact::ConstFieldAt( TInt aIndex ) const
       
   194     {
       
   195     return *iFieldArray[aIndex];
       
   196     }
       
   197 
       
   198 // -----------------------------------------------------------------------------
       
   199 // CVPbkSimContact::FieldCount
       
   200 // -----------------------------------------------------------------------------
       
   201 //
       
   202 TInt CVPbkSimContact::FieldCount() const
       
   203     {
       
   204     return iFieldArray.Count();
       
   205     }
       
   206 
       
   207 // -----------------------------------------------------------------------------
       
   208 // CVPbkSimContact::SimIndex
       
   209 // -----------------------------------------------------------------------------
       
   210 //
       
   211 TInt CVPbkSimContact::SimIndex() const
       
   212     {
       
   213     return iSimIndex;
       
   214     }
       
   215 
       
   216 // -----------------------------------------------------------------------------
       
   217 // CVPbkSimContact::ETelContactL
       
   218 // -----------------------------------------------------------------------------
       
   219 //
       
   220 const TDesC8& CVPbkSimContact::ETelContactL() const
       
   221     {
       
   222     CreateETelContactL();
       
   223     return *iData;
       
   224     }
       
   225   
       
   226 // -----------------------------------------------------------------------------
       
   227 // CVPbkSimContact::SetL
       
   228 // -----------------------------------------------------------------------------
       
   229 // 
       
   230 void CVPbkSimContact::SetL( const TDesC8& aETelContact )
       
   231     {
       
   232     iFieldArray.ResetAndDestroy();
       
   233     
       
   234     HBufC8* buf = aETelContact.AllocLC();
       
   235     TPtr8 ptr( buf->Des() );
       
   236     iStore.ContactConverter().ConvertFromETelToVPbkSimContactL( 
       
   237         ptr, *this );
       
   238     CleanupStack::PopAndDestroy( buf );
       
   239     }
       
   240 
       
   241 // -----------------------------------------------------------------------------
       
   242 // CVPbkSimContact::IndentifyAdditionalFields()
       
   243 // -----------------------------------------------------------------------------
       
   244 //
       
   245 void CVPbkSimContact::IndentifyAdditionalFields()
       
   246     {
       
   247     TInt anrNumberFieldCount = 0;
       
   248     for( int i = 0; i < iFieldArray.Count(); i ++ )
       
   249         {
       
   250         if( iFieldArray[i]->Type() == EVPbkSimAdditionalNumber )
       
   251             {
       
   252             anrNumberFieldCount ++;
       
   253             switch( anrNumberFieldCount )
       
   254                 {
       
   255                 case 1:
       
   256                     iFieldArray[i]->SetType( EVPbkSimAdditionalNumber1 );
       
   257                     break;
       
   258                 case 2:
       
   259                     iFieldArray[i]->SetType( EVPbkSimAdditionalNumber2 );
       
   260                     break;
       
   261                 case 3:
       
   262                     iFieldArray[i]->SetType( EVPbkSimAdditionalNumber3 );
       
   263                     break;
       
   264                 default:
       
   265                     iFieldArray[i]->SetType( EVPbkSimAdditionalNumberLast );
       
   266                     break;
       
   267                 }
       
   268             }
       
   269         }
       
   270     }
       
   271 
       
   272 // -----------------------------------------------------------------------------
       
   273 // CVPbkSimContact::CreateETelContactL
       
   274 // -----------------------------------------------------------------------------
       
   275 // 
       
   276 void CVPbkSimContact::CreateETelContactL() const
       
   277     {
       
   278     // Convert to ETel contact
       
   279     HBufC8* buf = 
       
   280         iStore.ContactConverter().ConvertFromVPbkSimFieldsToETelCntLC(
       
   281         iFieldArray.Array(), iSimIndex );
       
   282     
       
   283     if (!iData)
       
   284         {
       
   285         iData = buf;
       
   286         CleanupStack::Pop(buf);
       
   287         }
       
   288     else
       
   289         {
       
   290         TPtr8 ptr( iData->Des() );
       
   291         VPbkSimStoreImpl::CheckAndUpdateBufferSizeL( iData, ptr, buf->Length() );
       
   292         ptr.Copy( *buf );
       
   293         CleanupStack::PopAndDestroy( buf );
       
   294         }
       
   295     }
       
   296 
       
   297 //  End of File