|
1 /* |
|
2 * Copyright (c) 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: |
|
15 * |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 #ifndef __CMSSERVERASYNCCONTACT__ |
|
21 #define __CMSSERVERASYNCCONTACT__ |
|
22 |
|
23 // INCLUDES |
|
24 #include <e32base.h> |
|
25 |
|
26 // FORWARD DECLARATIONS |
|
27 class CPbk2SortOrderManager; |
|
28 class MPbk2ContactNameFormatter; |
|
29 class CVPbkBaseContactFieldTypeIterator; |
|
30 |
|
31 // CONSTANTS |
|
32 const TInt KDefaultBufferSize = 12; |
|
33 |
|
34 /** |
|
35 * CCmsServerAsyncContact handles contact asynchronous requests. |
|
36 */ |
|
37 NONSHARABLE_CLASS( CCmsServerAsyncContact ) : public CActive |
|
38 { |
|
39 public: |
|
40 |
|
41 /** |
|
42 * Creates an instance of CCmsServerAsyncContact |
|
43 * |
|
44 * @param aSyncContact Reference to CCmsContact instance |
|
45 * @param aCmsServer Reference to CCmsServer instance |
|
46 * @return Instance of CCmsServerAsyncContact |
|
47 */ |
|
48 static CCmsServerAsyncContact* NewL( CCmsServerContact& aSyncContact, |
|
49 CCmsServer& aCmsServer ); |
|
50 |
|
51 /** |
|
52 * Fetches list of enabled fields, i.e. fields with some content |
|
53 */ |
|
54 void FetchEnabledFields(); |
|
55 |
|
56 /** |
|
57 * Fetches contact field |
|
58 * |
|
59 * @param aField Field to be fetched |
|
60 */ |
|
61 void FetchContactData( CCmsContactFieldItem::TCmsContactField aField ); |
|
62 |
|
63 /** |
|
64 * Retrieves content of all fields belonging to some communication method |
|
65 * |
|
66 * @param aFieldGroup Communication type |
|
67 * @return Array of fields. Ownershpi is transfered. |
|
68 */ |
|
69 CDesCArrayFlat* ContactDataTextLC( CCmsContactFieldItem::TCmsContactFieldGroup aFieldGroup ); |
|
70 |
|
71 /** |
|
72 * Reads contact URI fields |
|
73 * |
|
74 * @param aResourceId Resource identifying URI fields |
|
75 * @return Array with URI fields. Ownership is transfered. |
|
76 */ |
|
77 CDesCArrayFlat* ContactDataUriLC( TInt aResourceId ); |
|
78 |
|
79 /** |
|
80 * Read contact's fields to the array |
|
81 * |
|
82 * @param aResourceId Fields to be read |
|
83 * @param aFieldArray Result array |
|
84 */ |
|
85 void PhonebookDataL( TInt aResourceId, CDesCArrayFlat& aFieldArray ); |
|
86 |
|
87 /** |
|
88 * Reads all the data related to a contact: fields content, defaults, |
|
89 * corresponding xSP contacts |
|
90 * |
|
91 * @param aResourceId Specifies type of data to read |
|
92 * @return Packed contact info. Ownership is transfered |
|
93 */ |
|
94 HBufC* DoGetPhonebookDataLC( TInt aResourceId ); |
|
95 |
|
96 /** |
|
97 * Checks if any IM service is supported |
|
98 * |
|
99 * @return 0 if not supported and 1 if supported |
|
100 */ |
|
101 TInt FindImAvailabilityL(); |
|
102 |
|
103 /** |
|
104 * Checks if Voip service is supported |
|
105 * |
|
106 * @param aUri Voip service provider |
|
107 * @return ETrue if this service is supported |
|
108 */ |
|
109 TBool IsVoipCapableL( const TDesC& aUri ); |
|
110 |
|
111 /** |
|
112 * Destructor |
|
113 */ |
|
114 ~CCmsServerAsyncContact(); |
|
115 |
|
116 private: |
|
117 |
|
118 // Types of fetch operation |
|
119 enum TCmsAsyncOperation |
|
120 { |
|
121 ENone = 0, |
|
122 EFetchEnabledFields, |
|
123 EFetchPhonebookBinData, |
|
124 EFetchPhonebookTextData, |
|
125 EFetchPresenceData, |
|
126 EFetchPhonebookUriData, |
|
127 EFetchPhonebookDateTimeData |
|
128 }; |
|
129 |
|
130 private: |
|
131 |
|
132 /** |
|
133 * Default constructor |
|
134 * @param aSyncContact Reference to CCmsContact instance |
|
135 * @param aCmsServer Reference to CCmsServer instance |
|
136 */ |
|
137 CCmsServerAsyncContact( CCmsServerContact& aSyncContact, |
|
138 CCmsServer& aCmsServer ); |
|
139 |
|
140 /** |
|
141 * Second-phase constructor |
|
142 */ |
|
143 void ConstructL(); |
|
144 |
|
145 /** |
|
146 * Reads contact's first binary field |
|
147 * |
|
148 * @param aResourcId Field type |
|
149 * @return Field content. Ownership is transfered. |
|
150 */ |
|
151 HBufC8* ContactDataBinaryL( TInt aResourceId ); |
|
152 |
|
153 /** |
|
154 * Gets the list of fields with some content |
|
155 * |
|
156 * @return Packed list of fields. Ownership is transfered. |
|
157 */ |
|
158 HBufC* GetEnabledFieldsLC(); |
|
159 |
|
160 /** |
|
161 * Gets the list of fields with some content |
|
162 * |
|
163 * @param aBufferIndex Buffer index to insert data |
|
164 * @param aDataBuffer Buffer to save the list of fields |
|
165 * @param aContact Store contact |
|
166 */ |
|
167 void DoGetEnabledFieldsL( TInt& aBufferIndex, CBufFlat* aDataBuffer, |
|
168 const MVPbkStoreContact& aContact ); |
|
169 |
|
170 /** |
|
171 * Gets contact's full name or contact fields with default attributes. |
|
172 * |
|
173 * @param aResourceId: Specifies type of data to read. |
|
174 * @return Buffer with contact's full name, or fields and default |
|
175 * attrtibutes. Ownership is transfered. |
|
176 */ |
|
177 HBufC* DoGetDataLC( TInt aResourceId ); |
|
178 |
|
179 /** |
|
180 * Reads specified contact fields and default field |
|
181 * |
|
182 * @param aItemArray Array of contact fields to be filled |
|
183 * @param aDefaults Array of defaults to be filled |
|
184 * @param aResourceId Field type |
|
185 * @param aContact MVPbkStoreContact |
|
186 */ |
|
187 void HandleOneContactL( CDesCArray& aItemArray, CDesCArray& aInfoArray, RArray<TInt>& aDefaults, |
|
188 TInt aResourceId, const MVPbkStoreContact& aContact ); |
|
189 |
|
190 /** |
|
191 * Packs information about contacts' default fields into the buffer |
|
192 * |
|
193 * @param aItemArray Array of contacts |
|
194 * @param aDefaults Array of default fields for the contacts |
|
195 * @return Packed info about defaults, ownership is transfered |
|
196 */ |
|
197 HBufC* ConstructStreamBufferL( CDesCArray& aItemArray, CDesCArray& aInfoArray, RArray<TInt>& aDefaults ); |
|
198 |
|
199 /** |
|
200 * Get contact's full name. |
|
201 * |
|
202 * @return Contact's full name, ownership is transfered |
|
203 */ |
|
204 HBufC* DoGetFullNameDataLC( ); |
|
205 |
|
206 /** |
|
207 * Checks default attributes of a field. |
|
208 * |
|
209 * @param aContactField Contact field to seach default attributes for. |
|
210 * @return TInt TCmsDefaultAttributeTypes bitmask |
|
211 */ |
|
212 TInt DefaultAttributesL( const MVPbkBaseContactField& aContactField ); |
|
213 |
|
214 /** |
|
215 * Matches VPbk's enum to CMS internal enum. |
|
216 * |
|
217 * @param aDefaultType VPbk's default type. |
|
218 * @return TCmsDefaultAttributeTypes CMS's default type. |
|
219 */ |
|
220 CCmsContactFieldItem::TCmsDefaultAttributeTypes |
|
221 CCmsServerAsyncContact::MatchTypesToInternalEnum( |
|
222 TVPbkDefaultType aDefaultType ); |
|
223 |
|
224 /** |
|
225 * Reads all E-mail, VoIP and IMPP fields |
|
226 * |
|
227 * @return Fields array, ownership is transfered |
|
228 */ |
|
229 CDesCArrayFlat* ContactInfoArrayLC(); |
|
230 |
|
231 /** |
|
232 * Reads field content to the buffer |
|
233 * |
|
234 * @param aField Contact field |
|
235 * @return Field content, ownership is transfered |
|
236 */ |
|
237 HBufC* ParseContactFieldL( const MVPbkBaseContactField& aField ); |
|
238 |
|
239 /** |
|
240 * Reads all contact fields specified in the resource |
|
241 * |
|
242 * @param aCount Number of field definitions in the resource array |
|
243 * @param aResourceArray Resource array |
|
244 * @return Array of fields content, ownership is transfered |
|
245 */ |
|
246 CDesCArrayFlat* FieldsFromArrayLC( TInt aCount, const TInt aResourceArray[] ); |
|
247 |
|
248 /** |
|
249 * Gets all fields content and adds them to the field array |
|
250 * |
|
251 * @param aFieldArray Field array to keep all fields content |
|
252 * @param aFieldIterator Field iterator to go through all fields |
|
253 */ |
|
254 void GetOneFieldL( CDesCArrayFlat& aFieldArray, |
|
255 CVPbkBaseContactFieldTypeIterator& aFieldIterator ); |
|
256 |
|
257 /** |
|
258 * Checks if one string is a subset of another string TODO: why so difficult? |
|
259 * |
|
260 * @param aBuffer Target string |
|
261 * @param aItem Search string |
|
262 * @return ETrue if found |
|
263 */ |
|
264 TBool HasElement( const TDesC8& aBuffer, const TDesC8& aItem ); |
|
265 |
|
266 /** |
|
267 * Copies field type and field content (separated by KDelimiter) |
|
268 * to the buffer. |
|
269 * @param aBuffer Buffer to copy data |
|
270 * @param aDescriptor Field content |
|
271 * @param aFieldType Field type |
|
272 */ |
|
273 void AppendToBufferL( RBuf16& aBuffer, const TDesC& aDescriptor, |
|
274 CCmsContactFieldItem::TCmsContactField aFieldType ); |
|
275 |
|
276 /** |
|
277 * Copies fields from the source to the target string array |
|
278 * |
|
279 * @param aSource Source array |
|
280 * @param aTarget Target array |
|
281 */ |
|
282 void AppendFieldsL( const CDesCArrayFlat& aSource, CDesCArrayFlat& aTarget ); |
|
283 |
|
284 /** |
|
285 * Maps Cms contact field to field type (binary, uri, text, etc.) |
|
286 * |
|
287 * @param aCmsField Cms contact field |
|
288 * @return Field type |
|
289 */ |
|
290 TCmsAsyncOperation SelectOperationType( TInt aCmsField ); |
|
291 |
|
292 /** |
|
293 * Fetches contact's avatar. First found is returned. |
|
294 * |
|
295 * @return Avatar (string or file). Ownership is transfered to client. |
|
296 */ |
|
297 HBufC8* FetchAvatarL(); |
|
298 |
|
299 private: //From CActive |
|
300 |
|
301 void RunL(); |
|
302 void DoCancel(); |
|
303 TInt RunError( TInt aError ); |
|
304 |
|
305 private: //Data |
|
306 |
|
307 /// Server contact. Not owned. |
|
308 CCmsServerContact& iSyncContact; |
|
309 /// Type of fetch operation. |
|
310 TCmsAsyncOperation iAsyncOperation; |
|
311 /// Contact manager. Not owned. |
|
312 CVPbkContactManager* iContactManager; |
|
313 /// Sort order manager. Owned. |
|
314 CPbk2SortOrderManager* iSortOrderManager; |
|
315 /// Name formatter. Owned. |
|
316 MPbk2ContactNameFormatter* iNameFormatter; |
|
317 /// Reference to CCmsServer. Not owned. |
|
318 CCmsServer& iCmsServer; |
|
319 |
|
320 }; |
|
321 |
|
322 #endif //__CMSSERVERASYNCCONTACT__ |
|
323 |
|
324 |
|
325 // End of File |