phonebookui/Phonebook2/Presentation/src/CPbk2StorePropertyArray.cpp
changeset 0 e686773b3f54
child 21 9da50d567e3c
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: 
       
    15 *     Field property for a Phonebook 2 field type.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "CPbk2StorePropertyArray.h"
       
    22 
       
    23 // From Phonebook2
       
    24 #include "Pbk2PresentationUtils.h"
       
    25 #include "CPbk2StoreProperty.h"
       
    26 #include <RPbk2LocalizedResourceFile.h>
       
    27 #include <Pbk2Presentation.rsg>
       
    28 #include <Pbk2DataCaging.hrh>
       
    29 
       
    30 // From Virtual Phonebook
       
    31 
       
    32 // From System
       
    33 #include <barsread.h>
       
    34 #include <coemain.h>
       
    35 
       
    36 // ========================= MEMBER FUNCTIONS ===============================
       
    37 
       
    38 // --------------------------------------------------------------------------
       
    39 // CPbk2StorePropertyArray::CPbk2StorePropertyArray
       
    40 // --------------------------------------------------------------------------
       
    41 //
       
    42 CPbk2StorePropertyArray::CPbk2StorePropertyArray()
       
    43     {
       
    44     }
       
    45 
       
    46 // --------------------------------------------------------------------------
       
    47 // CPbk2StorePropertyArray::~CPbk2StorePropertyArray
       
    48 // --------------------------------------------------------------------------
       
    49 //
       
    50 CPbk2StorePropertyArray::~CPbk2StorePropertyArray()
       
    51     {
       
    52     iStoreProperties.ResetAndDestroy();
       
    53     }
       
    54 
       
    55 // --------------------------------------------------------------------------
       
    56 // CPbk2StorePropertyArray::NewL
       
    57 // --------------------------------------------------------------------------
       
    58 //
       
    59 EXPORT_C CPbk2StorePropertyArray* CPbk2StorePropertyArray::NewL(
       
    60         TResourceReader& aReader)
       
    61     {
       
    62     CPbk2StorePropertyArray* self = new(ELeave) CPbk2StorePropertyArray;
       
    63     CleanupStack::PushL(self);
       
    64     self->ConstructFromResourceL(aReader);
       
    65     CleanupStack::Pop(self);
       
    66     return self;
       
    67     }
       
    68 
       
    69 // --------------------------------------------------------------------------
       
    70 // CPbk2StorePropertyArray::NewL
       
    71 // --------------------------------------------------------------------------
       
    72 //
       
    73 EXPORT_C CPbk2StorePropertyArray* CPbk2StorePropertyArray::NewL()
       
    74     {
       
    75     CPbk2StorePropertyArray* self = new(ELeave) CPbk2StorePropertyArray;
       
    76     CleanupStack::PushL(self);
       
    77     self->ConstructL();
       
    78     CleanupStack::Pop(self);
       
    79     return self;
       
    80     }
       
    81             
       
    82 // --------------------------------------------------------------------------
       
    83 // CPbk2StorePropertyArray::ConstructL
       
    84 // --------------------------------------------------------------------------
       
    85 //
       
    86 void CPbk2StorePropertyArray::ConstructL()
       
    87     {
       
    88     RPbk2LocalizedResourceFile resFile(*CCoeEnv::Static());
       
    89     resFile.OpenLC(KPbk2RomFileDrive, 
       
    90                    KDC_RESOURCE_FILES_DIR, 
       
    91                    Pbk2PresentationUtils::PresentationResourceFile());
       
    92     
       
    93     TResourceReader reader;
       
    94     CCoeEnv::Static()->CreateResourceReaderLC
       
    95         (reader, R_PHONEBOOK2_STORE_PROPERTIES);
       
    96     ConstructFromResourceL(reader);
       
    97         
       
    98     CleanupStack::PopAndDestroy(2); // reader, resFile
       
    99     }
       
   100 
       
   101 // --------------------------------------------------------------------------
       
   102 // CPbk2StorePropertyArray::ConstructFromResourceL
       
   103 // --------------------------------------------------------------------------
       
   104 //
       
   105 void CPbk2StorePropertyArray::ConstructFromResourceL(TResourceReader& aReader)
       
   106     {
       
   107     TInt storePropertyCount = aReader.ReadInt16();
       
   108     while (storePropertyCount--)
       
   109         {
       
   110         iStoreProperties.AppendL(CPbk2StoreProperty::NewLC(aReader));
       
   111         CleanupStack::Pop(); // CPbk2StoreProperty::NewLC(aReader)
       
   112         }
       
   113     }
       
   114 
       
   115 // --------------------------------------------------------------------------
       
   116 // CPbk2StorePropertyArray::Count
       
   117 // --------------------------------------------------------------------------
       
   118 //
       
   119 EXPORT_C TInt CPbk2StorePropertyArray::Count() const
       
   120     {
       
   121     return iStoreProperties.Count();
       
   122     }
       
   123     
       
   124 // --------------------------------------------------------------------------
       
   125 // CPbk2StorePropertyArray::At
       
   126 // --------------------------------------------------------------------------
       
   127 //
       
   128 EXPORT_C const CPbk2StoreProperty& CPbk2StorePropertyArray::At(TInt aIndex) const
       
   129     {
       
   130     return *iStoreProperties[aIndex];   
       
   131     }
       
   132         
       
   133 // --------------------------------------------------------------------------
       
   134 // CPbk2StorePropertyArray::FindProperty
       
   135 // --------------------------------------------------------------------------
       
   136 //
       
   137 EXPORT_C const CPbk2StoreProperty* CPbk2StorePropertyArray::FindProperty(
       
   138         const TVPbkContactStoreUriPtr& aUriPtr) const
       
   139     {
       
   140     const CPbk2StoreProperty* result = NULL;
       
   141     
       
   142     const TInt count = iStoreProperties.Count();
       
   143     for (TInt i = 0; i < count; ++i)
       
   144         {
       
   145         if (iStoreProperties[i]->StoreUri().UriDes().Compare(aUriPtr.UriDes()) == 0)
       
   146             {
       
   147             result = iStoreProperties[i];
       
   148             break;
       
   149             }
       
   150         }
       
   151     
       
   152     return result;
       
   153     }
       
   154 
       
   155 // --------------------------------------------------------------------------
       
   156 // CPbk2StorePropertyArray::AppendFromResourceL
       
   157 // --------------------------------------------------------------------------
       
   158 //
       
   159 EXPORT_C void CPbk2StorePropertyArray::AppendFromResourceL(
       
   160         TResourceReader& aReader)
       
   161     {
       
   162     CPbk2StorePropertyArray* newProps = CPbk2StorePropertyArray::NewL(aReader);
       
   163     CleanupStack::PushL(newProps);
       
   164     AppendFromArrayL(*newProps);
       
   165     CleanupStack::PopAndDestroy(newProps);
       
   166     }
       
   167 
       
   168 // --------------------------------------------------------------------------
       
   169 // CPbk2StorePropertyArray::AppendFromArrayL
       
   170 // --------------------------------------------------------------------------
       
   171 //
       
   172 EXPORT_C void CPbk2StorePropertyArray::AppendFromArrayL(
       
   173         CPbk2StorePropertyArray& aPropertyArray)
       
   174     {
       
   175     const TInt count = aPropertyArray.Count();
       
   176     for (TInt i = 0; i < count; ++i)
       
   177         {
       
   178         CPbk2StoreProperty* prop = CPbk2StoreProperty::NewLC(aPropertyArray.At(i));
       
   179         AppendL(prop);
       
   180         CleanupStack::Pop(prop);  
       
   181         }
       
   182     }
       
   183     
       
   184 // --------------------------------------------------------------------------
       
   185 // CPbk2StorePropertyArray::AppendL
       
   186 // --------------------------------------------------------------------------
       
   187 //
       
   188 EXPORT_C void CPbk2StorePropertyArray::AppendL(CPbk2StoreProperty* aProperty)
       
   189     {
       
   190     RemoveDuplicates(*aProperty);
       
   191     iStoreProperties.AppendL(aProperty);
       
   192     }
       
   193 
       
   194 // --------------------------------------------------------------------------
       
   195 // CPbk2StorePropertyArray::DeleteProperty
       
   196 // --------------------------------------------------------------------------
       
   197 //
       
   198 EXPORT_C void CPbk2StorePropertyArray::DeleteProperty(
       
   199         const TVPbkContactStoreUriPtr& aUriPtr)
       
   200     {
       
   201     TInt index = FindPropertyIndex(aUriPtr);
       
   202     if (index != KErrNotFound) 
       
   203         {
       
   204         delete iStoreProperties[index];
       
   205         iStoreProperties.Remove(index);
       
   206         }
       
   207     }
       
   208     
       
   209 // --------------------------------------------------------------------------
       
   210 // CPbk2StorePropertyArray::RemoveDuplicates
       
   211 // --------------------------------------------------------------------------
       
   212 //
       
   213 void CPbk2StorePropertyArray::RemoveDuplicates(CPbk2StoreProperty& aProperty)
       
   214     {
       
   215     TVPbkContactStoreUriPtr ptr(aProperty.StoreUri());
       
   216     if (FindProperty(ptr))
       
   217         {
       
   218         DeleteProperty(ptr);
       
   219         }
       
   220     }
       
   221     
       
   222 // --------------------------------------------------------------------------
       
   223 // CPbk2StorePropertyArray::FindPropertyIndex
       
   224 // --------------------------------------------------------------------------
       
   225 //
       
   226 TInt CPbk2StorePropertyArray::FindPropertyIndex(
       
   227     const TVPbkContactStoreUriPtr& aUriPtr)
       
   228     {
       
   229     TInt result = KErrNotFound;
       
   230     const TInt count = iStoreProperties.Count();
       
   231     for (TInt i = 0; (i < count) && (result == KErrNotFound); ++i)
       
   232         {
       
   233         if (iStoreProperties[i]->StoreUri().UriDes().Compare(aUriPtr.UriDes()) == 0)
       
   234             {
       
   235             result = i;
       
   236             }
       
   237         }
       
   238     
       
   239     return result;
       
   240     }
       
   241 
       
   242 // End of File