|
1 /* |
|
2 * Copyright (c) 2008 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: a single field with type |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "cvimpstfieldpropertyarray.h" |
|
20 |
|
21 #include "cvimpstfieldproperty.h" |
|
22 #include "vimpstdetailsview.hrh" |
|
23 |
|
24 // Virtual Phonebook |
|
25 #include <MVPbkFieldType.h> |
|
26 #include <MVPbkStoreContactField.h> |
|
27 #include <MVPbkStoreContact.h> |
|
28 #include <MVPbkContactFieldUriData.h> |
|
29 // System includes |
|
30 #include <barsread.h> |
|
31 _LIT(KColon,":"); |
|
32 |
|
33 // --------------------------------------------------------------------------- |
|
34 // CVIMPSTFieldPropertyArray::CVIMPSTFieldPropertyArray |
|
35 // --------------------------------------------------------------------------- |
|
36 // |
|
37 inline CVIMPSTFieldPropertyArray::CVIMPSTFieldPropertyArray(MVPbkStoreContact& aContact ): |
|
38 iContact( aContact ) |
|
39 { |
|
40 } |
|
41 |
|
42 // --------------------------------------------------------------------------- |
|
43 // CVIMPSTFieldPropertyArray::ConstructL |
|
44 // --------------------------------------------------------------------------- |
|
45 // |
|
46 inline void CVIMPSTFieldPropertyArray::ConstructL( |
|
47 const MVPbkFieldTypeList& aSupportedFieldTypeList,TResourceReader& aReader, |
|
48 TBool aPresenceSupported, |
|
49 TDesC& aServiceName, TStoreType aStoreType) |
|
50 { |
|
51 ReadFieldPropertiesL( aReader, aSupportedFieldTypeList, aPresenceSupported , aServiceName, aStoreType); |
|
52 } |
|
53 |
|
54 // --------------------------------------------------------------------------- |
|
55 // CVIMPSTFieldPropertyArray::NewL |
|
56 // --------------------------------------------------------------------------- |
|
57 // |
|
58 CVIMPSTFieldPropertyArray* CVIMPSTFieldPropertyArray::NewL |
|
59 (const MVPbkFieldTypeList& aSupportedFieldTypeList, MVPbkStoreContact& aContact, |
|
60 TResourceReader& aReader, |
|
61 TBool aPresenceSupported, |
|
62 TDesC& aServiceName, TStoreType aStoreType ) |
|
63 { |
|
64 CVIMPSTFieldPropertyArray* self = new(ELeave) CVIMPSTFieldPropertyArray( aContact ); |
|
65 CleanupStack::PushL(self); |
|
66 self->ConstructL( aSupportedFieldTypeList ,aReader, aPresenceSupported, aServiceName, aStoreType); |
|
67 CleanupStack::Pop(self); |
|
68 return self; |
|
69 } |
|
70 // --------------------------------------------------------------------------- |
|
71 // CVIMPSTFieldPropertyArray::~CVIMPSTFieldPropertyArray |
|
72 // --------------------------------------------------------------------------- |
|
73 // |
|
74 CVIMPSTFieldPropertyArray::~CVIMPSTFieldPropertyArray() |
|
75 { |
|
76 iFieldProperties.ResetAndDestroy(); |
|
77 } |
|
78 |
|
79 // --------------------------------------------------------------------------- |
|
80 // CVIMPSTFieldPropertyArray::Count |
|
81 // --------------------------------------------------------------------------- |
|
82 // |
|
83 TInt CVIMPSTFieldPropertyArray::Count() const |
|
84 { |
|
85 return iFieldProperties.Count(); |
|
86 } |
|
87 |
|
88 // --------------------------------------------------------------------------- |
|
89 // CVIMPSTFieldPropertyArray::At |
|
90 // --------------------------------------------------------------------------- |
|
91 // |
|
92 CVIMPSTFieldProperty& CVIMPSTFieldPropertyArray::At |
|
93 (TInt aIndex) const |
|
94 { |
|
95 return *iFieldProperties[aIndex]; |
|
96 } |
|
97 |
|
98 // --------------------------------------------------------------------------- |
|
99 // CVIMPSTFieldPropertyArray::GetFieldById |
|
100 // --------------------------------------------------------------------------- |
|
101 // |
|
102 CVIMPSTFieldProperty* CVIMPSTFieldPropertyArray::GetFieldById( TInt aFieldId ) |
|
103 { |
|
104 CVIMPSTFieldProperty* retField = NULL; |
|
105 |
|
106 TInt count = Count(); |
|
107 |
|
108 for( TInt i=0; i< count; i++ ) |
|
109 { |
|
110 CVIMPSTFieldProperty* field = iFieldProperties[i]; |
|
111 if( field && field->FieldId() == aFieldId ) |
|
112 { |
|
113 retField = field; |
|
114 break; |
|
115 } |
|
116 } |
|
117 return retField; |
|
118 } |
|
119 |
|
120 |
|
121 // --------------------------------------------------------------------------- |
|
122 // CVIMPSTFieldPropertyArray::ReadFieldPropertiesL |
|
123 // --------------------------------------------------------------------------- |
|
124 // |
|
125 void CVIMPSTFieldPropertyArray::ReadFieldPropertiesL( |
|
126 TResourceReader& aReader, |
|
127 const MVPbkFieldTypeList& aSupportedFieldTypeList, |
|
128 TBool aPresenceSupported, |
|
129 TDesC& aServiceName, TStoreType aStoreType) |
|
130 { |
|
131 // aSupportedFieldTypeList is a list of the supported field type of the used store |
|
132 const TInt count = aReader.ReadInt16(); |
|
133 |
|
134 for (TInt i = 0; i < count; ++i) |
|
135 { |
|
136 // do not change the order of reading from aReader |
|
137 const TInt fieldTypeResId = aReader.ReadInt32(); |
|
138 TInt fieldId = aReader.ReadInt8(); |
|
139 TInt maxLength = aReader.ReadInt16(); |
|
140 TInt iconId = aReader.ReadInt8(); |
|
141 HBufC* defaultLabel = aReader.ReadHBufCL(); |
|
142 if( !defaultLabel ) |
|
143 { |
|
144 defaultLabel = KNullDesC().AllocL(); |
|
145 } |
|
146 CleanupStack::PushL(defaultLabel); |
|
147 const MVPbkFieldType* fieldType = aSupportedFieldTypeList.Find( fieldTypeResId ); |
|
148 |
|
149 if( fieldId == EVIMPSTFieldIdStatusMsg && aPresenceSupported ) // currently not supported |
|
150 { |
|
151 CVIMPSTFieldProperty* property = CVIMPSTFieldProperty::NewLC( fieldId, iconId, maxLength, *defaultLabel ); |
|
152 iFieldProperties.AppendL( property ); |
|
153 CleanupStack::Pop(property);// property |
|
154 } |
|
155 else if( fieldType ) |
|
156 { |
|
157 MVPbkStoreContactFieldCollection& fieldCollection = iContact.Fields(); |
|
158 TInt fieldCount = fieldCollection.FieldCount(); |
|
159 for( TInt i=0; i< fieldCount; i++ ) |
|
160 { |
|
161 MVPbkStoreContactField& field = fieldCollection.FieldAt( i ); |
|
162 const MVPbkFieldType* type = field.BestMatchingFieldType() ; |
|
163 if( fieldType == type ) |
|
164 { |
|
165 if( fieldId == EVIMPSTFieldIdImpp ) |
|
166 { |
|
167 const MVPbkContactFieldData& fieldData = field.FieldData(); |
|
168 const MVPbkContactFieldUriData& uri = MVPbkContactFieldUriData::Cast(fieldData); |
|
169 TPtrC xspId = uri.Uri(); |
|
170 TInt index = xspId.Find( KColon ); |
|
171 if( index>0 ) |
|
172 { |
|
173 TPtrC servicename = xspId.Left(index); |
|
174 if( servicename.Compare(aServiceName) == 0) |
|
175 { |
|
176 CVIMPSTFieldProperty* property = CVIMPSTFieldProperty::NewLC( fieldId, iconId, maxLength, *defaultLabel ); |
|
177 property->SetStoredFieldL( field ); |
|
178 iFieldProperties.AppendL( property ); |
|
179 CleanupStack::Pop(property); //property |
|
180 } |
|
181 } |
|
182 } |
|
183 else if( fieldId == EVIMPSTFieldIdDisplayName || |
|
184 fieldId == EVIMPSTFieldIdFirstName || |
|
185 fieldId == EVIMPSTFieldIdLastName ) |
|
186 { |
|
187 CVIMPSTFieldProperty* property = CVIMPSTFieldProperty::NewLC( fieldId, iconId, maxLength, *defaultLabel ); |
|
188 property->SetStoredFieldL( field ); |
|
189 iFieldProperties.AppendL( property ); |
|
190 CleanupStack::Pop(property); //property |
|
191 } |
|
192 else if( aStoreType == EStoreServer ) //append all fields to details view if it is server store |
|
193 { |
|
194 CVIMPSTFieldProperty* property = CVIMPSTFieldProperty::NewLC( fieldId, iconId, maxLength, *defaultLabel ); |
|
195 property->SetStoredFieldL( field ); |
|
196 iFieldProperties.AppendL( property ); |
|
197 CleanupStack::Pop(property); //property |
|
198 } |
|
199 } |
|
200 } |
|
201 } |
|
202 CleanupStack::PopAndDestroy(defaultLabel); |
|
203 } |
|
204 |
|
205 } |
|
206 |
|
207 // End of File |