|
1 /* |
|
2 * Copyright (c) 2006-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: Field group properties |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <CPbk2FieldGroupPropertyArray.h> |
|
20 |
|
21 // Phonebook 2 |
|
22 #include "Pbk2PresentationUtils.h" |
|
23 #include <MPbk2FieldPropertyArray.h> |
|
24 #include <RPbk2LocalizedResourceFile.h> |
|
25 #include <Pbk2Presentation.rsg> |
|
26 #include <MPbk2FieldProperty.h> |
|
27 #include <CPbk2FieldPropertyGroup.h> |
|
28 #include <Pbk2DataCaging.hrh> |
|
29 |
|
30 // Virtual Phonebook |
|
31 #include <MVPbkFieldType.h> |
|
32 #include <TVPbkFieldVersitProperty.h> |
|
33 #include <CVPbkFieldTypeSelector.h> |
|
34 |
|
35 // System includes |
|
36 #include <barsc.h> |
|
37 #include <barsread.h> |
|
38 #include <coemain.h> |
|
39 |
|
40 // --------------------------------------------------------------------------- |
|
41 // CPbk2FieldGroupPropertyArray::CPbk2FieldGroupPropertyArra |
|
42 // --------------------------------------------------------------------------- |
|
43 // |
|
44 CPbk2FieldGroupPropertyArray::CPbk2FieldGroupPropertyArray() |
|
45 { |
|
46 } |
|
47 |
|
48 // --------------------------------------------------------------------------- |
|
49 // CPbk2FieldGroupPropertyArray::ConstructL |
|
50 // --------------------------------------------------------------------------- |
|
51 // |
|
52 void CPbk2FieldGroupPropertyArray::ConstructL( |
|
53 const MPbk2FieldPropertyArray& aFieldProperties ) |
|
54 { |
|
55 RPbk2LocalizedResourceFile resFile( *CCoeEnv::Static() ); |
|
56 resFile.OpenLC(KPbk2RomFileDrive, |
|
57 KDC_RESOURCE_FILES_DIR, |
|
58 Pbk2PresentationUtils::PresentationResourceFile()); |
|
59 |
|
60 // Read field group properties |
|
61 TResourceReader reader; |
|
62 CCoeEnv::Static()->CreateResourceReaderLC( reader, |
|
63 R_PHONEBOOK2_FIELD_GROUP_ARRAY ); |
|
64 ReadFieldGroupsL( reader ); |
|
65 CleanupStack::PopAndDestroy(2); // reader, resFile |
|
66 |
|
67 PopulateGroupsL( aFieldProperties ); |
|
68 } |
|
69 |
|
70 |
|
71 // --------------------------------------------------------------------------- |
|
72 // CPbk2FieldGroupPropertyArray::NewL |
|
73 // --------------------------------------------------------------------------- |
|
74 // |
|
75 EXPORT_C CPbk2FieldGroupPropertyArray* CPbk2FieldGroupPropertyArray::NewL( |
|
76 const MPbk2FieldPropertyArray& aFieldProperties ) |
|
77 { |
|
78 CPbk2FieldGroupPropertyArray* self = |
|
79 CPbk2FieldGroupPropertyArray::NewLC( aFieldProperties ); |
|
80 CleanupStack::Pop( self ); |
|
81 return self; |
|
82 } |
|
83 |
|
84 |
|
85 // --------------------------------------------------------------------------- |
|
86 // CPbk2FieldGroupPropertyArray::NewLC |
|
87 // --------------------------------------------------------------------------- |
|
88 // |
|
89 EXPORT_C CPbk2FieldGroupPropertyArray* CPbk2FieldGroupPropertyArray::NewLC( |
|
90 const MPbk2FieldPropertyArray& aFieldProperties ) |
|
91 { |
|
92 CPbk2FieldGroupPropertyArray* self = new( ELeave ) CPbk2FieldGroupPropertyArray; |
|
93 CleanupStack::PushL( self ); |
|
94 self->ConstructL( aFieldProperties ); |
|
95 return self; |
|
96 } |
|
97 |
|
98 CPbk2FieldGroupPropertyArray::~CPbk2FieldGroupPropertyArray() |
|
99 { |
|
100 iFieldGroups.ResetAndDestroy(); |
|
101 } |
|
102 |
|
103 // --------------------------------------------------------------------------- |
|
104 // CPbk2FieldGroupPropertyArray::GroupCount |
|
105 // --------------------------------------------------------------------------- |
|
106 // |
|
107 EXPORT_C TInt CPbk2FieldGroupPropertyArray::GroupCount() const |
|
108 { |
|
109 return iFieldGroups.Count(); |
|
110 } |
|
111 |
|
112 // --------------------------------------------------------------------------- |
|
113 // CPbk2FieldGroupPropertyArray::GroupAt |
|
114 // --------------------------------------------------------------------------- |
|
115 // |
|
116 EXPORT_C const CPbk2FieldPropertyGroup& CPbk2FieldGroupPropertyArray::GroupAt( |
|
117 TInt aIndex ) const |
|
118 { |
|
119 return *iFieldGroups[aIndex]; |
|
120 } |
|
121 |
|
122 // --------------------------------------------------------------------------- |
|
123 // CPbk2FieldGroupPropertyArray::FindGroupForProperty |
|
124 // --------------------------------------------------------------------------- |
|
125 // |
|
126 EXPORT_C const CPbk2FieldPropertyGroup* |
|
127 CPbk2FieldGroupPropertyArray::FindGroupForProperty( |
|
128 const MPbk2FieldProperty& aProperty) const |
|
129 { |
|
130 const TInt groupCount = iFieldGroups.Count(); |
|
131 for (TInt i = 0; i < groupCount; ++i) |
|
132 { |
|
133 const CPbk2FieldPropertyGroup& group = *iFieldGroups[i]; |
|
134 TInt propCount = group.Count(); |
|
135 for (TInt j = 0; j < propCount; ++j) |
|
136 { |
|
137 if (aProperty.FieldType().IsSame(group.At(j).FieldType())) |
|
138 { |
|
139 return &group; |
|
140 } |
|
141 } |
|
142 } |
|
143 return NULL; |
|
144 } |
|
145 |
|
146 // --------------------------------------------------------------------------- |
|
147 // CPbk2FieldGroupPropertyArray::ReadFieldGroupsL |
|
148 // --------------------------------------------------------------------------- |
|
149 // |
|
150 void CPbk2FieldGroupPropertyArray::ReadFieldGroupsL |
|
151 (TResourceReader& aReader) |
|
152 { |
|
153 const TInt count = aReader.ReadInt16(); |
|
154 for (TInt i = 0; i < count; ++i) |
|
155 { |
|
156 CPbk2FieldPropertyGroup* group = |
|
157 CPbk2FieldPropertyGroup::NewLC(aReader); |
|
158 iFieldGroups.AppendL(group); |
|
159 CleanupStack::Pop(group); |
|
160 } |
|
161 } |
|
162 |
|
163 // --------------------------------------------------------------------------- |
|
164 // CPbk2FieldGroupPropertyArray::PopulateGroupsL |
|
165 // --------------------------------------------------------------------------- |
|
166 // |
|
167 void CPbk2FieldGroupPropertyArray::PopulateGroupsL( |
|
168 const MPbk2FieldPropertyArray& aFieldProperties ) |
|
169 { |
|
170 const TInt propCount = aFieldProperties.Count(); |
|
171 const TInt groupCount = iFieldGroups.Count(); |
|
172 for (TInt i = 0; i < propCount; ++i) |
|
173 { |
|
174 TInt groupId = aFieldProperties.At( i ).GroupId(); |
|
175 for (TInt j = 0; j < groupCount; ++j) |
|
176 { |
|
177 if (iFieldGroups[j]->GroupId() == groupId) |
|
178 { |
|
179 iFieldGroups[j]->AddFieldPropertyL( |
|
180 aFieldProperties.At( i ) ); |
|
181 break; |
|
182 } |
|
183 } |
|
184 } |
|
185 |
|
186 // Remove empty groups |
|
187 for (TInt j = groupCount - 1; j >= 0; --j) |
|
188 { |
|
189 if (iFieldGroups[j]->Count() == 0) |
|
190 { |
|
191 delete iFieldGroups[j]; |
|
192 iFieldGroups.Remove(j); |
|
193 } |
|
194 } |
|
195 } |
|
196 |
|
197 // End of File |