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