phonebookengines/VirtualPhonebook/VPbkSimStore/src/TStoreContactField.cpp
changeset 0 e686773b3f54
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:  An adapter between virtual phonebook framework 
       
    15 *                and VPbkSimStoreImpl field
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDES
       
    21 #include "TStoreContactField.h"
       
    22 #include "CContact.h"
       
    23 #include "CContactLink.h"
       
    24 #include "CContactStore.h"
       
    25 #include "CFieldTypeMappings.h"
       
    26 #include <MVPbkBaseContact.h>
       
    27 #include <MVPbkContactStoreProperties.h>
       
    28 #include <CVPbkSimCntField.h>
       
    29 #include <CVPbkSimContact.h>
       
    30 #include <VPbkSimStoreCommon.h>
       
    31 
       
    32 namespace VPbkSimStore {
       
    33 
       
    34 // ============================ MEMBER FUNCTIONS ===============================
       
    35 
       
    36 // -----------------------------------------------------------------------------
       
    37 // TStoreContactField::TStoreContactField
       
    38 // C++ default constructor can NOT contain any code, that
       
    39 // might leave.
       
    40 // -----------------------------------------------------------------------------
       
    41 //
       
    42 TStoreContactField::TStoreContactField()
       
    43     {
       
    44     }
       
    45 
       
    46 // -----------------------------------------------------------------------------
       
    47 // TStoreContactField::SetParentContact
       
    48 // -----------------------------------------------------------------------------
       
    49 //
       
    50 void TStoreContactField::SetParentContact( CContact& aParentContact )
       
    51     {
       
    52     iParentContact = &aParentContact;
       
    53     }
       
    54 
       
    55 // -----------------------------------------------------------------------------
       
    56 // TStoreContactField::SetSimField
       
    57 // -----------------------------------------------------------------------------
       
    58 //
       
    59 void TStoreContactField::SetSimField( CVPbkSimCntField& aSimField )
       
    60     {
       
    61     iSimField = &aSimField;
       
    62     iFieldData.SetField( aSimField );
       
    63     }
       
    64 
       
    65 // -----------------------------------------------------------------------------
       
    66 // TStoreContactField::ParentObject
       
    67 // -----------------------------------------------------------------------------
       
    68 //
       
    69 MVPbkObjectHierarchy& TStoreContactField::ParentObject() const
       
    70     {
       
    71     return *iParentContact;
       
    72     }
       
    73 
       
    74 // -----------------------------------------------------------------------------
       
    75 // TStoreContactField::ParentContact
       
    76 // -----------------------------------------------------------------------------
       
    77 //
       
    78 MVPbkBaseContact& TStoreContactField::ParentContact() const
       
    79     {
       
    80     return *iParentContact;
       
    81     }
       
    82 
       
    83 // -----------------------------------------------------------------------------
       
    84 // TStoreContactField::MatchFieldType
       
    85 // -----------------------------------------------------------------------------
       
    86 //
       
    87 const MVPbkFieldType* TStoreContactField::MatchFieldType( 
       
    88     TInt /*aMatchPriority*/ ) const
       
    89     {
       
    90     return iParentContact->Store().FieldTypeMappings().Match( 
       
    91         iSimField->Type() );
       
    92     }
       
    93 
       
    94 // -----------------------------------------------------------------------------
       
    95 // TStoreContactField::BestMatchingFieldType
       
    96 // -----------------------------------------------------------------------------
       
    97 //
       
    98 const MVPbkFieldType* TStoreContactField::BestMatchingFieldType() const
       
    99     {
       
   100     TInt dummy = 0;
       
   101     return MatchFieldType( dummy );
       
   102     }
       
   103 
       
   104 // -----------------------------------------------------------------------------
       
   105 // TStoreContactField::FieldData
       
   106 // -----------------------------------------------------------------------------
       
   107 //
       
   108 const MVPbkContactFieldData& TStoreContactField::FieldData() const
       
   109     {
       
   110     return iFieldData;
       
   111     }
       
   112 
       
   113 // -----------------------------------------------------------------------------
       
   114 // TStoreContactField::IsSame
       
   115 // -----------------------------------------------------------------------------
       
   116 //
       
   117 TBool TStoreContactField::IsSame( const MVPbkBaseContactField& aOther ) const
       
   118     {
       
   119     if ( &ParentContact() == &aOther.ParentContact() )
       
   120         {
       
   121         return iSimField == static_cast<const TStoreContactField&>
       
   122             ( aOther ).iSimField; 
       
   123         }
       
   124     return EFalse;
       
   125     }
       
   126 
       
   127 // -----------------------------------------------------------------------------
       
   128 // TStoreContactField::SupportsLabel
       
   129 // -----------------------------------------------------------------------------
       
   130 //
       
   131 TBool TStoreContactField::SupportsLabel() const
       
   132     {
       
   133     // Currently sim store doesn't support field labels. However, it's possible
       
   134     // to use labels in additional numbers of the USIM (EF AAS) if the lower
       
   135     // level software and USIM card supports it.
       
   136     return 
       
   137         iParentContact->ParentStore().StoreProperties().SupportsFieldLabels();
       
   138     }
       
   139     
       
   140 // -----------------------------------------------------------------------------
       
   141 // TStoreContactField::FieldLabel
       
   142 // -----------------------------------------------------------------------------
       
   143 //
       
   144 TPtrC TStoreContactField::FieldLabel() const
       
   145     {
       
   146     return KNullDesC();
       
   147     }
       
   148 
       
   149 // -----------------------------------------------------------------------------
       
   150 // TStoreContactField::SetFieldLabelL
       
   151 // -----------------------------------------------------------------------------
       
   152 //
       
   153 void TStoreContactField::SetFieldLabelL( const TDesC& /*aText*/ )
       
   154     {
       
   155     User::Leave( KErrNotSupported );
       
   156     }
       
   157 
       
   158 // -----------------------------------------------------------------------------
       
   159 // TStoreContactField::MaxLabelLength
       
   160 // -----------------------------------------------------------------------------
       
   161 //
       
   162 TInt TStoreContactField::MaxLabelLength() const
       
   163     {
       
   164     // SIM store doesn't support label editing. Return 0 as documented in
       
   165     // MVPbkStoreContactField API
       
   166     return 0;
       
   167     }
       
   168     
       
   169 // -----------------------------------------------------------------------------
       
   170 // TStoreContactField::FieldData
       
   171 // -----------------------------------------------------------------------------
       
   172 //
       
   173 MVPbkContactFieldData& TStoreContactField::FieldData()
       
   174     {
       
   175     return iFieldData;
       
   176     }
       
   177 
       
   178 // -----------------------------------------------------------------------------
       
   179 // TStoreContactField::CloneLC
       
   180 // -----------------------------------------------------------------------------
       
   181 //
       
   182 MVPbkStoreContactField* TStoreContactField::CloneLC() const
       
   183     {
       
   184     TStoreContactField* clone =
       
   185         new (ELeave) TStoreContactField;
       
   186     clone->SetParentContact(*this->iParentContact);
       
   187     clone->SetSimField(*this->iSimField);
       
   188     CleanupDeletePushL(clone);
       
   189     return clone;
       
   190     }
       
   191 
       
   192 // -----------------------------------------------------------------------------
       
   193 // TStoreContactField::CreateLinkLC
       
   194 // -----------------------------------------------------------------------------
       
   195 //    
       
   196 MVPbkContactLink* TStoreContactField::CreateLinkLC() const
       
   197     {
       
   198     MVPbkContactLink* ret = NULL;
       
   199     if ( iParentContact->SimContact().SimIndex() != KVPbkSimStoreFirstFreeIndex )
       
   200         {
       
   201         TInt index = KErrNotFound;
       
   202         
       
   203         // Find the index of this field in the parent contact
       
   204         const TInt count = iParentContact->SimContact().FieldCount();
       
   205         for (TInt i = 0; i < count; ++i)
       
   206             {
       
   207             if (&iParentContact->SimContact().FieldAt(i) == iSimField)
       
   208                 {
       
   209                 index = i;
       
   210                 break;
       
   211                 }
       
   212             }
       
   213         ret = CContactLink::NewLC(
       
   214                 iParentContact->Store(), 
       
   215                 iParentContact->SimContact().SimIndex(),
       
   216                 index);
       
   217         }
       
   218     return ret;
       
   219     }
       
   220 
       
   221 // -----------------------------------------------------------------------------
       
   222 // TContactNewField::TContactNewField
       
   223 // C++ default constructor can NOT contain any code, that
       
   224 // might leave.
       
   225 // -----------------------------------------------------------------------------
       
   226 //
       
   227 TContactNewField::TContactNewField( CVPbkSimCntField* aSimField ) 
       
   228     {
       
   229     // This instance has an ownership of the aSimField now
       
   230     TStoreContactField::SetSimField( *aSimField );
       
   231     iOwnsField = ETrue;
       
   232     }
       
   233 
       
   234 // Destructor
       
   235 TContactNewField::~TContactNewField() 
       
   236     {
       
   237     if ( iOwnsField )
       
   238         {
       
   239         delete TStoreContactField::SimField();
       
   240         }
       
   241     }
       
   242 
       
   243 // -----------------------------------------------------------------------------
       
   244 // TContactNewField::SimField
       
   245 // -----------------------------------------------------------------------------
       
   246 //
       
   247 CVPbkSimCntField* TContactNewField::SimField()
       
   248     {
       
   249     iOwnsField = EFalse;
       
   250     return TStoreContactField::SimField();
       
   251     }
       
   252 }  // namespace VPbkSimStore
       
   253