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