|
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: Implementation of store contact analyzer. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "emailtrace.h" |
|
20 #include "TFscStoreContactAnalyzer.h" |
|
21 |
|
22 // Virtual Phonebook |
|
23 #include <CVPbkContactManager.h> |
|
24 #include <CVPbkFieldTypeSelector.h> |
|
25 #include <MVPbkStoreContactFieldCollection.h> |
|
26 #include <MVPbkStoreContact.h> |
|
27 #include <MVPbkContactStore.h> |
|
28 #include <MVPbkFieldType.h> |
|
29 #include <MVPbkContactStoreProperties.h> |
|
30 #include <VPbkUtils.h> |
|
31 |
|
32 // System includes |
|
33 #include <barsread.h> |
|
34 #include <coemain.h> |
|
35 |
|
36 // -------------------------------------------------------------------------- |
|
37 // TFscStoreContactAnalyzer::TFscStoreContactAnalyzer |
|
38 // -------------------------------------------------------------------------- |
|
39 // |
|
40 TFscStoreContactAnalyzer::TFscStoreContactAnalyzer |
|
41 ( const CVPbkContactManager& aContactManager, |
|
42 const MVPbkStoreContact* aContact ) : |
|
43 iContactManager( aContactManager ), |
|
44 iContact( aContact ) |
|
45 { |
|
46 FUNC_LOG; |
|
47 } |
|
48 |
|
49 // -------------------------------------------------------------------------- |
|
50 // TFscStoreContactAnalyzer::HasFieldL |
|
51 // -------------------------------------------------------------------------- |
|
52 // |
|
53 TInt TFscStoreContactAnalyzer::HasFieldL |
|
54 ( TInt aResId, TInt aStartIndex/* = 0*/, |
|
55 const MVPbkStoreContact* aContact/* = NULL*/ ) const |
|
56 { |
|
57 FUNC_LOG; |
|
58 TInt ret = KErrNotFound; |
|
59 const MVPbkStoreContact* tempContact = iContact; |
|
60 |
|
61 if ( aContact ) |
|
62 { |
|
63 tempContact = aContact; |
|
64 } |
|
65 |
|
66 // Check that there is contact to analyze |
|
67 if ( tempContact ) |
|
68 { |
|
69 // Read the contact field selector from resource |
|
70 MVPbkContactFieldSelector* fieldTypeSelector = |
|
71 static_cast<MVPbkContactFieldSelector*> |
|
72 ( CreateFieldTypeSelectorLC( aResId ) ); |
|
73 |
|
74 // Check if the specified field is included to contact |
|
75 const MVPbkStoreContactFieldCollection& fields = |
|
76 tempContact->Fields(); |
|
77 ret = IsFieldIncluded( fields, aStartIndex, *fieldTypeSelector ); |
|
78 CleanupStack::PopAndDestroy(); // fieldTypeSelector; |
|
79 } |
|
80 |
|
81 return ret; |
|
82 } |
|
83 |
|
84 // -------------------------------------------------------------------------- |
|
85 // TFscStoreContactAnalyzer::IsFieldTypeSupportedL |
|
86 // -------------------------------------------------------------------------- |
|
87 // |
|
88 TBool TFscStoreContactAnalyzer::IsFieldTypeSupportedL |
|
89 ( TInt aResId, const MVPbkStoreContact* aContact /*= NULL*/ ) const |
|
90 { |
|
91 FUNC_LOG; |
|
92 TBool ret = EFalse; |
|
93 const MVPbkStoreContact* tempContact = iContact; |
|
94 |
|
95 if (aContact) |
|
96 { |
|
97 tempContact = aContact; |
|
98 } |
|
99 |
|
100 // Check that there is contact to analyze |
|
101 if ( tempContact ) |
|
102 { |
|
103 // Read the field type selector from resource |
|
104 MVPbkFieldTypeSelector* fieldTypeSelector = |
|
105 static_cast<MVPbkFieldTypeSelector*> |
|
106 ( CreateFieldTypeSelectorLC( aResId ) ); |
|
107 |
|
108 // Check if the specified field type is supported by contact |
|
109 const MVPbkFieldTypeList& fieldTypes = |
|
110 tempContact->ParentStore().StoreProperties().SupportedFields(); |
|
111 ret = IsFieldTypeIncluded( fieldTypes, *fieldTypeSelector ); |
|
112 CleanupStack::PopAndDestroy(); // fieldTypeSelector; |
|
113 } |
|
114 |
|
115 return ret; |
|
116 } |
|
117 |
|
118 // -------------------------------------------------------------------------- |
|
119 // TFscStoreContactAnalyzer::IsFieldTypeIncludedL |
|
120 // -------------------------------------------------------------------------- |
|
121 // |
|
122 TBool TFscStoreContactAnalyzer::IsFieldTypeIncludedL |
|
123 ( const MVPbkFieldType& aFieldType, TInt aResId ) const |
|
124 { |
|
125 FUNC_LOG; |
|
126 CVPbkFieldTypeSelector* selector = CreateFieldTypeSelectorLC( aResId ); |
|
127 TBool ret = selector->IsFieldTypeIncluded( aFieldType ); |
|
128 CleanupStack::PopAndDestroy( selector ); |
|
129 return ret; |
|
130 } |
|
131 |
|
132 // -------------------------------------------------------------------------- |
|
133 // TFscStoreContactAnalyzer::IsFieldTypeIncludedL |
|
134 // -------------------------------------------------------------------------- |
|
135 // |
|
136 TBool TFscStoreContactAnalyzer::IsFieldTypeIncludedL |
|
137 ( const MVPbkBaseContactField& aField, TInt aResId ) const |
|
138 { |
|
139 FUNC_LOG; |
|
140 // Get the field type |
|
141 const MVPbkFieldType* fieldType = |
|
142 VPbkUtils::MatchFieldType( iContactManager.FieldTypes(), aField ); |
|
143 CVPbkFieldTypeSelector* selector = CreateFieldTypeSelectorLC( aResId ); |
|
144 TBool ret = selector->IsFieldTypeIncluded( *fieldType ); |
|
145 CleanupStack::PopAndDestroy( selector ); |
|
146 return ret; |
|
147 } |
|
148 |
|
149 // -------------------------------------------------------------------------- |
|
150 // TFscStoreContactAnalyzer::IsFieldIncluded |
|
151 // -------------------------------------------------------------------------- |
|
152 // |
|
153 TInt TFscStoreContactAnalyzer::IsFieldIncluded |
|
154 (const MVPbkBaseContactFieldCollection& aFields, |
|
155 TInt aStartIndex, |
|
156 const MVPbkContactFieldSelector& aFieldTypeSelector) const |
|
157 { |
|
158 FUNC_LOG; |
|
159 TInt ret( KErrNotFound ); |
|
160 TInt fieldCount( aFields.FieldCount() ); |
|
161 |
|
162 for ( TInt i = aStartIndex; i < fieldCount && ret == KErrNotFound; ++i ) |
|
163 { |
|
164 const MVPbkBaseContactField& field = aFields.FieldAt( i ); |
|
165 if ( aFieldTypeSelector.IsFieldIncluded( field ) ) |
|
166 { |
|
167 ret = i; |
|
168 } |
|
169 } |
|
170 |
|
171 return ret; |
|
172 } |
|
173 |
|
174 // -------------------------------------------------------------------------- |
|
175 // TFscStoreContactAnalyzer::IsFieldTypeIncluded |
|
176 // -------------------------------------------------------------------------- |
|
177 // |
|
178 TBool TFscStoreContactAnalyzer::IsFieldTypeIncluded |
|
179 ( const MVPbkFieldTypeList& aFieldTypes, |
|
180 const MVPbkFieldTypeSelector& aFieldTypeSelector ) const |
|
181 { |
|
182 FUNC_LOG; |
|
183 TBool ret( EFalse ); |
|
184 TInt fieldTypeCount( aFieldTypes.FieldTypeCount() ); |
|
185 |
|
186 for ( TInt i = 0; i < fieldTypeCount && !ret; ++i ) |
|
187 { |
|
188 const MVPbkFieldType& fieldType = aFieldTypes.FieldTypeAt( i ); |
|
189 if ( aFieldTypeSelector.IsFieldTypeIncluded( fieldType ) ) |
|
190 { |
|
191 ret = ETrue; |
|
192 } |
|
193 } |
|
194 |
|
195 return ret; |
|
196 } |
|
197 |
|
198 // -------------------------------------------------------------------------- |
|
199 // TFscStoreContactAnalyzer::CreateFieldTypeSelectorLC |
|
200 // -------------------------------------------------------------------------- |
|
201 // |
|
202 CVPbkFieldTypeSelector* TFscStoreContactAnalyzer::CreateFieldTypeSelectorLC |
|
203 ( TInt aResId ) const |
|
204 { |
|
205 FUNC_LOG; |
|
206 TResourceReader resReader; |
|
207 CCoeEnv::Static()->CreateResourceReaderLC( resReader, aResId ); |
|
208 |
|
209 CVPbkFieldTypeSelector* fieldTypeSelector = CVPbkFieldTypeSelector::NewL |
|
210 ( resReader, iContactManager.FieldTypes() ); |
|
211 |
|
212 CleanupStack::PopAndDestroy(); // resReader |
|
213 CleanupStack::PushL( fieldTypeSelector ); |
|
214 return fieldTypeSelector; |
|
215 } |
|
216 |
|
217 // End of File |
|
218 |