|
1 /* |
|
2 * Copyright (c) 2005-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: Phonebook 2 store property. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <CPbk2StoreProperty.h> |
|
20 |
|
21 // Phonebook 2 |
|
22 #include "CPbk2LocalizedText.h" |
|
23 #include <CPbk2StoreViewDefinition.h> |
|
24 #include <CPbk2FieldPropertyArray.h> |
|
25 #include <CPbk2StorePropertyContentStoreName.h> |
|
26 |
|
27 // System includes |
|
28 #include <barsread.h> |
|
29 #include <coemain.h> |
|
30 |
|
31 |
|
32 // -------------------------------------------------------------------------- |
|
33 // CPbk2StoreProperty::CPbk2StoreProperty |
|
34 // -------------------------------------------------------------------------- |
|
35 // |
|
36 CPbk2StoreProperty::CPbk2StoreProperty() |
|
37 { |
|
38 } |
|
39 |
|
40 // -------------------------------------------------------------------------- |
|
41 // CPbk2StoreProperty::~CPbk2StoreProperty |
|
42 // -------------------------------------------------------------------------- |
|
43 // |
|
44 CPbk2StoreProperty::~CPbk2StoreProperty() |
|
45 { |
|
46 delete iStoreUri; |
|
47 delete iStoreName; |
|
48 iStoreViews.ResetAndDestroy(); |
|
49 iLocalizedTexts.ResetAndDestroy(); |
|
50 } |
|
51 |
|
52 // -------------------------------------------------------------------------- |
|
53 // CPbk2StoreProperty::NewL |
|
54 // -------------------------------------------------------------------------- |
|
55 // |
|
56 EXPORT_C CPbk2StoreProperty* CPbk2StoreProperty::NewL() |
|
57 { |
|
58 return new ( ELeave ) CPbk2StoreProperty; |
|
59 } |
|
60 |
|
61 // -------------------------------------------------------------------------- |
|
62 // CPbk2StoreProperty::NewLC |
|
63 // -------------------------------------------------------------------------- |
|
64 // |
|
65 EXPORT_C CPbk2StoreProperty* CPbk2StoreProperty::NewLC |
|
66 ( TResourceReader& aReader ) |
|
67 { |
|
68 CPbk2StoreProperty* self = new ( ELeave ) CPbk2StoreProperty; |
|
69 CleanupStack::PushL( self ); |
|
70 self->ConstructL( aReader ); |
|
71 return self; |
|
72 } |
|
73 |
|
74 // -------------------------------------------------------------------------- |
|
75 // CPbk2StoreProperty::NewLC |
|
76 // -------------------------------------------------------------------------- |
|
77 // |
|
78 EXPORT_C CPbk2StoreProperty* CPbk2StoreProperty::NewLC |
|
79 ( const CPbk2StoreProperty& aProperty ) |
|
80 { |
|
81 CPbk2StoreProperty* self = new ( ELeave ) CPbk2StoreProperty; |
|
82 CleanupStack::PushL( self ); |
|
83 self->ConstructL( aProperty ); |
|
84 return self; |
|
85 } |
|
86 |
|
87 // -------------------------------------------------------------------------- |
|
88 // CPbk2StoreProperty::ConstructL |
|
89 // -------------------------------------------------------------------------- |
|
90 // |
|
91 void CPbk2StoreProperty::ConstructL( TResourceReader& aReader ) |
|
92 { |
|
93 aReader.ReadInt8(); // read version number |
|
94 iStoreUri = aReader.ReadHBufCL(); |
|
95 iStoreName = aReader.ReadHBufCL(); |
|
96 iFlags = aReader.ReadUint32(); |
|
97 TInt viewCount = aReader.ReadInt16(); |
|
98 while (viewCount-- > 0 ) |
|
99 { |
|
100 iStoreViews.AppendL(CPbk2StoreViewDefinition::NewLC(aReader)); |
|
101 CleanupStack::Pop(); // CPbk2StoreView::NewLC(aReader) |
|
102 } |
|
103 iMemoryInfoTypes = aReader.ReadUint32(); |
|
104 iFieldPropertiesResId = aReader.ReadInt32(); |
|
105 TInt textCount = aReader.ReadInt16(); |
|
106 while ( textCount-- > 0 ) |
|
107 { |
|
108 iLocalizedTexts.AppendL( CPbk2LocalizedText::NewL( aReader ) ); |
|
109 } |
|
110 } |
|
111 |
|
112 // -------------------------------------------------------------------------- |
|
113 // CPbk2StoreProperty::ConstructL |
|
114 // -------------------------------------------------------------------------- |
|
115 // |
|
116 void CPbk2StoreProperty::ConstructL( const CPbk2StoreProperty& aProperty ) |
|
117 { |
|
118 iStoreUri = aProperty.StoreUri().UriDes().AllocL(); |
|
119 iStoreName = aProperty.StoreName().AllocL(); |
|
120 |
|
121 iFlags = aProperty.Flags(); |
|
122 TArray<const CPbk2StoreViewDefinition*> views = aProperty.Views(); |
|
123 TInt viewCount = views.Count(); |
|
124 for (TInt i = 0; i < viewCount; ++i) |
|
125 { |
|
126 iStoreViews.AppendL(CPbk2StoreViewDefinition::NewLC(*views[i])); |
|
127 CleanupStack::Pop(); // CPbk2StoreView::NewLC(aReader) |
|
128 } |
|
129 iMemoryInfoTypes = aProperty.MemoryInfoTypes(); |
|
130 iFieldPropertiesResId = aProperty.FieldPropertiesResId(); |
|
131 CreateLocalizedTextsL( aProperty ); |
|
132 } |
|
133 |
|
134 // -------------------------------------------------------------------------- |
|
135 // CPbk2StoreProperty::StoreUri |
|
136 // -------------------------------------------------------------------------- |
|
137 // |
|
138 EXPORT_C TVPbkContactStoreUriPtr CPbk2StoreProperty::StoreUri() const |
|
139 { |
|
140 return TVPbkContactStoreUriPtr(*iStoreUri); |
|
141 } |
|
142 |
|
143 // -------------------------------------------------------------------------- |
|
144 // CPbk2StoreProperty::StoreName |
|
145 // -------------------------------------------------------------------------- |
|
146 // |
|
147 EXPORT_C const TDesC& CPbk2StoreProperty::StoreName() const |
|
148 { |
|
149 return *iStoreName; |
|
150 } |
|
151 |
|
152 // -------------------------------------------------------------------------- |
|
153 // CPbk2StoreProperty::MemoryInfoTypes |
|
154 // -------------------------------------------------------------------------- |
|
155 // |
|
156 EXPORT_C TUint32 CPbk2StoreProperty::MemoryInfoTypes() const |
|
157 { |
|
158 return iMemoryInfoTypes; |
|
159 } |
|
160 |
|
161 // -------------------------------------------------------------------------- |
|
162 // CPbk2StoreProperty::Views |
|
163 // -------------------------------------------------------------------------- |
|
164 // |
|
165 EXPORT_C TArray<const CPbk2StoreViewDefinition*> |
|
166 CPbk2StoreProperty::Views() const |
|
167 { |
|
168 return iStoreViews.Array(); |
|
169 } |
|
170 |
|
171 // -------------------------------------------------------------------------- |
|
172 // CPbk2StoreProperty::Flags |
|
173 // -------------------------------------------------------------------------- |
|
174 // |
|
175 EXPORT_C TUint32 CPbk2StoreProperty::Flags() const |
|
176 { |
|
177 return iFlags; |
|
178 } |
|
179 |
|
180 // -------------------------------------------------------------------------- |
|
181 // CPbk2StoreProperty::FieldPropertiesResId |
|
182 // -------------------------------------------------------------------------- |
|
183 // |
|
184 EXPORT_C TInt CPbk2StoreProperty::FieldPropertiesResId() const |
|
185 { |
|
186 return iFieldPropertiesResId; |
|
187 } |
|
188 |
|
189 // -------------------------------------------------------------------------- |
|
190 // CPbk2StoreProperty::SetStoreUriL |
|
191 // -------------------------------------------------------------------------- |
|
192 // |
|
193 EXPORT_C void CPbk2StoreProperty::SetStoreUriL(const TDesC& aStoreUri) |
|
194 { |
|
195 HBufC* temp = aStoreUri.AllocL(); |
|
196 delete iStoreUri; |
|
197 iStoreUri = temp; |
|
198 } |
|
199 |
|
200 // -------------------------------------------------------------------------- |
|
201 // CPbk2StoreProperty::SetStoreNameL |
|
202 // -------------------------------------------------------------------------- |
|
203 // |
|
204 EXPORT_C void CPbk2StoreProperty::SetStoreNameL(const TDesC& aStoreName) |
|
205 { |
|
206 HBufC* temp = aStoreName.AllocL(); |
|
207 delete iStoreName; |
|
208 iStoreName = temp; |
|
209 } |
|
210 |
|
211 // -------------------------------------------------------------------------- |
|
212 // CPbk2StoreProperty::AppendViewDefinitionL |
|
213 // -------------------------------------------------------------------------- |
|
214 // |
|
215 EXPORT_C void CPbk2StoreProperty::AppendViewDefinitionL |
|
216 ( CPbk2StoreViewDefinition* aViewDefinition ) |
|
217 { |
|
218 iStoreViews.AppendL( aViewDefinition ); |
|
219 } |
|
220 |
|
221 // -------------------------------------------------------------------------- |
|
222 // CPbk2StoreProperty::SetMemoryInfoTypes |
|
223 // -------------------------------------------------------------------------- |
|
224 // |
|
225 EXPORT_C void CPbk2StoreProperty::SetMemoryInfoTypes(TUint32 aInfoTypes) |
|
226 { |
|
227 iMemoryInfoTypes = aInfoTypes; |
|
228 } |
|
229 |
|
230 // -------------------------------------------------------------------------- |
|
231 // CPbk2StoreProperty::SetFlags |
|
232 // -------------------------------------------------------------------------- |
|
233 // |
|
234 EXPORT_C void CPbk2StoreProperty::SetFlags(TUint32 aFlags) |
|
235 { |
|
236 iFlags = aFlags; |
|
237 } |
|
238 |
|
239 // -------------------------------------------------------------------------- |
|
240 // CPbk2StoreProperty::SetFieldPropertiesResId |
|
241 // -------------------------------------------------------------------------- |
|
242 // |
|
243 EXPORT_C void CPbk2StoreProperty::SetFieldPropertiesResId |
|
244 ( TInt aFieldPropertiesResId ) |
|
245 { |
|
246 iFieldPropertiesResId = aFieldPropertiesResId; |
|
247 } |
|
248 |
|
249 // -------------------------------------------------------------------------- |
|
250 // CPbk2StoreProperty::FindView |
|
251 // -------------------------------------------------------------------------- |
|
252 // |
|
253 EXPORT_C const CPbk2StoreViewDefinition* CPbk2StoreProperty::FindView |
|
254 ( TPbk2ContactViewType aViewType ) const |
|
255 { |
|
256 const CPbk2StoreViewDefinition* result = NULL; |
|
257 |
|
258 const TInt count = iStoreViews.Count(); |
|
259 for (TInt i = 0; i < count; ++i) |
|
260 { |
|
261 if (iStoreViews[i]->ViewType() == aViewType) |
|
262 { |
|
263 result = iStoreViews[i]; |
|
264 break; |
|
265 } |
|
266 } |
|
267 |
|
268 return result; |
|
269 } |
|
270 |
|
271 // -------------------------------------------------------------------------- |
|
272 // CPbk2StoreProperty::CreateStoreSpecificFieldPropertiesL |
|
273 // -------------------------------------------------------------------------- |
|
274 // |
|
275 EXPORT_C MPbk2FieldPropertyArray* |
|
276 CPbk2StoreProperty::CreateStoreSpecificFieldPropertiesL |
|
277 ( const MVPbkFieldTypeList& aFieldTypeList ) const |
|
278 { |
|
279 CPbk2FieldPropertyArray* props = NULL; |
|
280 if ( iFieldPropertiesResId ) |
|
281 { |
|
282 TResourceReader reader; |
|
283 CCoeEnv::Static()->CreateResourceReaderLC |
|
284 (reader, iFieldPropertiesResId); |
|
285 props = CPbk2FieldPropertyArray::NewL(aFieldTypeList, reader, |
|
286 CCoeEnv::Static()->FsSession() ); |
|
287 CleanupStack::PopAndDestroy(); // reader |
|
288 } |
|
289 return props; |
|
290 } |
|
291 |
|
292 // -------------------------------------------------------------------------- |
|
293 // CPbk2StoreProperty::RetrieveContentLC |
|
294 // -------------------------------------------------------------------------- |
|
295 // |
|
296 EXPORT_C CPbk2Content* CPbk2StoreProperty::RetrieveContentLC |
|
297 ( TPbk2ContentId aContext ) const |
|
298 { |
|
299 CPbk2Content* content = NULL; |
|
300 |
|
301 if ( aContext == EPbk2MemInfoPhone || aContext == EPbk2CopyQueryItem || aContext == EPbk2MemInfoContacts ) |
|
302 { |
|
303 // Both EPbk2MemInfoPhone EPbk2CopyQueryItem and EPbk2MemInfoContacts use same kind of |
|
304 // content |
|
305 content = new ( ELeave ) CPbk2StorePropertyContentStoreName |
|
306 ( iLocalizedTexts.Array(), aContext ); |
|
307 CleanupStack::PushL( content ); |
|
308 } |
|
309 |
|
310 return content; |
|
311 } |
|
312 |
|
313 // -------------------------------------------------------------------------- |
|
314 // CPbk2StoreProperty::CreateLocalizedTextsL |
|
315 // -------------------------------------------------------------------------- |
|
316 // |
|
317 void CPbk2StoreProperty::CreateLocalizedTextsL( |
|
318 const CPbk2StoreProperty& aProperty ) |
|
319 { |
|
320 // Remember to make copies of all supported content types. |
|
321 // Check RetrieveContentLC() to see all supported types. |
|
322 |
|
323 // Copy EPbk2MemInfoPhone |
|
324 CPbk2Content* content = |
|
325 aProperty.RetrieveContentLC( EPbk2MemInfoPhone ); |
|
326 CPbk2StorePropertyContentStoreName* propContent = |
|
327 dynamic_cast<CPbk2StorePropertyContentStoreName*>( content ); |
|
328 if ( propContent ) |
|
329 { |
|
330 TInt uid = propContent->Uid(); |
|
331 HBufC* text = propContent->StoreName().AllocLC(); |
|
332 iLocalizedTexts.AppendL( CPbk2LocalizedText::NewL( uid, text ) ); |
|
333 CleanupStack::Pop( text ); |
|
334 // CPbk2LocalizedText::NewL has taken the ownership of text |
|
335 } |
|
336 CleanupStack::PopAndDestroy( content ); |
|
337 |
|
338 // Copy EPbk2CopyQueryItem |
|
339 content = |
|
340 aProperty.RetrieveContentLC( EPbk2CopyQueryItem ); |
|
341 propContent = |
|
342 dynamic_cast<CPbk2StorePropertyContentStoreName*>( content ); |
|
343 if ( propContent ) |
|
344 { |
|
345 TInt uid = propContent->Uid(); |
|
346 HBufC* text = propContent->StoreName().AllocLC(); |
|
347 iLocalizedTexts.AppendL( CPbk2LocalizedText::NewL( uid, text ) ); |
|
348 CleanupStack::Pop( text ); |
|
349 // CPbk2LocalizedText::NewL has taken the ownership of text |
|
350 } |
|
351 CleanupStack::PopAndDestroy( content ); |
|
352 |
|
353 // Copy EPbk2MemInfoContacts |
|
354 content = |
|
355 aProperty.RetrieveContentLC( EPbk2MemInfoContacts ); |
|
356 propContent = |
|
357 dynamic_cast<CPbk2StorePropertyContentStoreName*>( content ); |
|
358 if ( propContent ) |
|
359 { |
|
360 TInt uid = propContent->Uid(); |
|
361 HBufC* text = propContent->StoreName().AllocLC(); |
|
362 iLocalizedTexts.AppendL( CPbk2LocalizedText::NewL( uid, text ) ); |
|
363 CleanupStack::Pop( text ); |
|
364 // CPbk2LocalizedText::NewL has taken the ownership of text |
|
365 } |
|
366 CleanupStack::PopAndDestroy( content ); |
|
367 |
|
368 } |
|
369 |
|
370 // End of File |