27 #include <MVPbkContactStoreListObserver.h> |
27 #include <MVPbkContactStoreListObserver.h> |
28 #include <MVPbkContactFindFromStoresObserver.h> |
28 #include <MVPbkContactFindFromStoresObserver.h> |
29 #include <MVPbkSingleContactOperationObserver.h> |
29 #include <MVPbkSingleContactOperationObserver.h> |
30 #include <MVPbkContactViewObserver.h> |
30 #include <MVPbkContactViewObserver.h> |
31 #include <CVPbkContactManager.h> |
31 #include <CVPbkContactManager.h> |
32 #include <CVPbkContactLinkArray.h> |
32 |
33 |
33 // USER INCLUDES |
34 // USER INCLUDES |
|
35 #include "mdatastoreobserver.h" |
34 #include "mdatastoreobserver.h" |
36 #include "PSContactsAdapterInternalCRKeys.h" |
35 #include "PSContactsAdapterInternalCRKeys.h" |
37 |
36 |
38 // FORWARD DECLARATIONS |
37 // FORWARD DECLARATIONS |
39 class CPsData; |
38 class CPsData; |
40 class CVPbkContactManager; |
39 class CVPbkContactManager; |
41 class CVPbkContactStoreUriArray; |
|
42 class CVPbkContactLinkArray; |
40 class CVPbkContactLinkArray; |
43 class MVPbkContactOperationBase; |
41 class MVPbkContactOperationBase; |
44 class MVPbkContactLinkArray; |
|
45 class MVPbkBaseContact; |
42 class MVPbkBaseContact; |
46 class CVPbkFieldTypeRefsList; |
43 class CVPbkFieldTypeRefsList; |
47 class CVPbkFieldTypeRefsList; |
|
48 class MVPbkContactViewObserver; |
44 class MVPbkContactViewObserver; |
|
45 class CPbk2SortOrderManager; |
|
46 |
49 /** |
47 /** |
50 * States involved in fetching the contacts |
48 * States involved in fetching the contacts |
51 */ |
49 */ |
52 enum |
50 enum |
53 { |
51 { |
54 ECreateView, |
52 ECreateView, |
55 EFetchContactBlock, |
53 EFetchContactBlock, |
56 EComplete |
54 EComplete |
57 }; |
55 }; |
58 |
56 |
59 /** |
57 /** |
60 * This class represents the data store for the contacts |
58 * This class represents the data store for the contacts |
61 * Each data store (phonecontacts, simcontact, group contacts) is an |
59 * Each data store (phonecontacts, simcontact, group contacts) is an |
62 * instance of this class |
60 * instance of this class |
63 * @lib pscontactsadapter.lib |
61 * @lib pscontactsadapter.lib |
64 */ |
62 */ |
65 class CPcsContactStore: public CActive, |
63 class CPcsContactStore: public CActive, |
66 public MVPbkSingleContactOperationObserver, |
64 public MVPbkSingleContactOperationObserver, |
67 public MVPbkContactViewObserver |
65 public MVPbkContactViewObserver |
68 |
66 |
69 { |
67 { |
70 public: |
68 public: |
71 |
69 |
72 /** |
70 /** |
73 * 2 phase construction |
71 * 2 phase construction |
74 * @param aContactManager - the contact manager |
72 * @param aContactManager - the contact manager |
75 * @param aObserver - observer for receiving data |
73 * @param aObserver - observer for receiving data |
76 * @param aUri - the data store uri |
74 * @param aUri - the data store uri |
77 * @return returns pointer to the constructed object of type CPcsContactStore |
75 * @return returns pointer to the constructed object of type CPcsContactStore |
78 */ |
76 */ |
79 static CPcsContactStore* NewL(CVPbkContactManager& aContactManager, |
77 static CPcsContactStore* NewL(CVPbkContactManager& aContactManager, |
80 MDataStoreObserver& aObserver, |
78 MDataStoreObserver& aObserver, |
81 const TDesC& aUri); |
79 const TDesC& aUri); |
82 |
80 |
83 /** |
81 /** |
84 * Destructor |
82 * Destructor |
85 */ |
83 */ |
86 virtual ~CPcsContactStore(); |
84 virtual ~CPcsContactStore(); |
|
85 |
|
86 /** |
|
87 * Handles store events (contact/group addition/modification/deletion etc.) |
|
88 * @param aContactStore - the contact store |
|
89 * @param aStoreEvent - store event |
|
90 */ |
|
91 void HandleStoreEventL(MVPbkContactStore& aContactStore, |
|
92 TVPbkContactStoreEvent aStoreEvent); |
|
93 |
|
94 /** |
|
95 * Gets the store Uri |
|
96 * @return - the store uri supported by this instance |
|
97 */ |
|
98 TDesC& GetStoreUri(); |
|
99 |
|
100 public: |
|
101 |
|
102 // From base class MVPbkSingleContactOperationObserver |
|
103 |
|
104 /** |
|
105 * From MVPbkSingleContactOperationObserver |
|
106 * Called when operation is completed. |
|
107 * |
|
108 * @param aOperation the completed operation. |
|
109 * @param aContact the contact returned by the operation. |
|
110 * Client must take the ownership immediately. |
|
111 * |
|
112 * !!! NOTICE !!! |
|
113 * If you use Cleanupstack for MVPbkStoreContact |
|
114 * Use MVPbkStoreContact::PushL or |
|
115 * CleanupDeletePushL from e32base.h. |
|
116 * (Do Not Use CleanupStack::PushL(TAny*) because |
|
117 * then the virtual destructor of the M-class |
|
118 * won't be called when the object is deleted). |
|
119 */ |
|
120 void VPbkSingleContactOperationComplete( |
|
121 MVPbkContactOperationBase& aOperation, |
|
122 MVPbkStoreContact* aContact ); |
|
123 |
|
124 /** |
|
125 * From MVPbkSingleContactOperationObserver |
|
126 * Called if the operation fails. |
|
127 * |
|
128 * @param aOperation the failed operation. |
|
129 * @param aError error code of the failure. |
|
130 */ |
|
131 void VPbkSingleContactOperationFailed( |
|
132 MVPbkContactOperationBase& aOperation, |
|
133 TInt aError ); |
|
134 |
|
135 public : |
|
136 |
|
137 // From base class MVPbkContactViewObserver |
|
138 |
|
139 void ContactViewReady( |
|
140 MVPbkContactViewBase& aView ); |
|
141 |
|
142 void ContactViewUnavailable( |
|
143 MVPbkContactViewBase& aView ); |
|
144 |
|
145 void ContactAddedToView( |
|
146 MVPbkContactViewBase& aView, |
|
147 TInt aIndex, |
|
148 const MVPbkContactLink& aContactLink ); |
|
149 |
|
150 void ContactRemovedFromView( |
|
151 MVPbkContactViewBase& aView, |
|
152 TInt aIndex, |
|
153 const MVPbkContactLink& aContactLink ); |
|
154 |
|
155 void ContactViewError( |
|
156 MVPbkContactViewBase& aView, |
|
157 TInt aError, |
|
158 TBool aErrorNotified ); |
|
159 |
|
160 protected: |
|
161 |
|
162 // From base class CActive |
|
163 |
|
164 /** |
|
165 * From CActive |
|
166 * Implements cancellation of an outstanding request. |
|
167 * |
|
168 * This function is called as part of the active object's Cancel(). |
|
169 */ |
|
170 void DoCancel(); |
|
171 |
|
172 /** |
|
173 * From CActive |
|
174 * Handles an active object's request completion event. |
|
175 * |
|
176 * The function is called by the active scheduler when a request |
|
177 * completion event occurs, i.e. after the active scheduler's |
|
178 * WaitForAnyRequest() function completes. |
|
179 * |
|
180 * Before calling this active object's RunL() function, the active scheduler |
|
181 * has: |
|
182 * |
|
183 * 1. decided that this is the highest priority active object with |
|
184 * a completed request |
|
185 * |
|
186 * 2. marked this active object's request as complete (i.e. the request is no |
|
187 * longer outstanding) |
|
188 * |
|
189 * RunL() runs under a trap harness in the active scheduler. If it leaves, |
|
190 * then the active scheduler calls RunError() to handle the leave. |
|
191 * |
|
192 * Note that once the active scheduler's Start() function has been called, |
|
193 * all user code is run under one of the program's active object's RunL() or |
|
194 * RunError() functions. |
|
195 */ |
|
196 void RunL(); |
|
197 |
|
198 /** |
|
199 * From CActive |
|
200 * If the RunL function leaves, |
|
201 * then the active scheduler calls RunError() to handle the leave. |
|
202 * @param aError - The error code |
|
203 */ |
|
204 TInt RunError( TInt aError ); |
|
205 |
|
206 private: |
|
207 |
|
208 /** |
|
209 * Constructor |
|
210 */ |
|
211 CPcsContactStore(); |
|
212 |
|
213 /** |
|
214 * 2nd phase constructor |
|
215 */ |
|
216 void ConstructL(CVPbkContactManager& aContactManager, MDataStoreObserver& aObserver,const TDesC& aUri); |
|
217 |
|
218 /** |
|
219 * Handles the operations for a single contact after it is fetched |
|
220 * @param aContact - The contact from database |
|
221 */ |
|
222 void HandleRetrievedContactL(MVPbkStoreContact* aContact); |
|
223 |
|
224 /** |
|
225 * Fetches the data from a particular contact |
|
226 * @param aContact - The contact from database |
|
227 * |
|
228 */ |
|
229 void GetDataForSingleContactL ( MVPbkBaseContact& aContact, CPsData* aPhoneData ); |
|
230 |
|
231 /** |
|
232 * Add the data from contact fields |
|
233 * @param aContact - The contact from database |
|
234 * @param afieldtype - Field to be added |
|
235 * @param aPhoneData - the contact data in PS format |
|
236 */ |
|
237 void AddContactFieldsL(MVPbkBaseContact& aContact, TInt afieldtype, CPsData* aPhoneData); |
|
238 |
|
239 /** |
|
240 * Fetches the data from contact links from the view |
|
241 */ |
|
242 void FetchlinksL(); |
|
243 |
|
244 /** |
|
245 * Reads the fields to cache from the central repository |
|
246 */ |
|
247 void ReadFieldsToCacheFromCenrepL(); |
|
248 |
|
249 /** |
|
250 * Creates a cacheId corresponding to sim Id Array Index |
|
251 * @param - aSimId - The sim id |
|
252 */ |
|
253 TInt CreateCacheIDfromSimArrayIndex(TInt aSimId); |
|
254 |
|
255 /** |
|
256 * Creates the contact fetch view |
|
257 */ |
|
258 void CreateContactFetchViewL(); |
|
259 |
|
260 /** |
|
261 * Issues request to active object to call RunL method |
|
262 */ |
|
263 void IssueRequest(); |
|
264 |
|
265 /** |
|
266 * Creates a sort order depending on the fields specified in the cenrep |
|
267 * @param aMasterList - aMasterList (i.e list containing all the vpbk fields) |
|
268 */ |
|
269 void CreateSortOrderL(const MVPbkFieldTypeList& aMasterList); |
|
270 |
|
271 /** |
|
272 * Checks if contact is my card |
|
273 */ |
|
274 TBool IsMyCard( const MVPbkBaseContact& aContact ); |
|
275 |
|
276 private: |
|
277 |
|
278 |
|
279 /** |
|
280 * Flags for store operations |
|
281 */ |
|
282 TInt iAllContactLinksCount; |
|
283 TInt iFetchedContactCount; |
|
284 TBool iContactViewReady; |
|
285 |
|
286 /** |
|
287 * Variable to store the next state for the RunL to take appropriate action |
|
288 */ |
|
289 TInt iNextState; |
|
290 |
|
291 /** |
|
292 * The contact manager for accessing the phone contacts |
|
293 * Not Own. |
|
294 */ |
|
295 CVPbkContactManager* iContactManager; |
|
296 |
|
297 /** |
|
298 * Holds a view base instance |
|
299 * Own. |
|
300 */ |
|
301 MVPbkContactViewBase* iContactViewBase; |
|
302 |
|
303 /** |
|
304 * Holds a contact operation |
|
305 * Own. |
|
306 */ |
|
307 MVPbkContactOperationBase* iOp; |
|
308 |
|
309 /** |
|
310 * Owns an instance of active scheduler wait |
|
311 */ |
|
312 CActiveSchedulerWait *iWait; |
|
313 |
|
314 /** |
|
315 * data fields to be cached(read from the central repository) |
|
316 */ |
|
317 RArray<TInt> iFieldsToCache; |
|
318 |
|
319 /** |
|
320 * Array of contact links |
|
321 */ |
|
322 CVPbkContactLinkArray *iSimContactItems; |
|
323 |
|
324 /** |
|
325 * Holds the observer object to communicate add/modify/delete of contacts |
|
326 * Not owned. |
|
327 */ |
|
328 MDataStoreObserver* iObserver; |
|
329 |
|
330 /** |
|
331 * Contacts Database URI |
|
332 */ |
|
333 HBufC* iUri; |
|
334 |
|
335 /** |
|
336 * File session |
|
337 */ |
|
338 RFs iFs; |
|
339 |
|
340 /** |
|
341 * RTimer variable to set the timer before RunL calls any function. |
|
342 * This is required to allow other threads to run since contact fetch |
|
343 * is CPU intensive task. |
|
344 */ |
|
345 RTimer iTimer; |
|
346 |
|
347 /** |
|
348 * Holds the sort order fields |
|
349 */ |
|
350 CVPbkFieldTypeRefsList *iSortOrder; |
|
351 |
|
352 /** |
|
353 * Holds MyCard supported status |
|
354 */ |
|
355 TBool iMyCardSupported; |
87 |
356 |
88 /** |
357 /** |
89 * Handles store events (contact/group addition/modification/deletion etc.) |
358 * Own. Sort order for all contacts view |
90 * @param aContactStore - the contact store |
359 */ |
91 * @param aStoreEvent - store event |
360 CPbk2SortOrderManager* iSortOrderMan; |
92 */ |
|
93 void HandleStoreEventL(MVPbkContactStore& aContactStore, |
|
94 TVPbkContactStoreEvent aStoreEvent); |
|
95 |
|
96 /** |
|
97 * Gets the store Uri |
|
98 * @return - the store uri supported by this instance |
|
99 */ |
|
100 TDesC& GetStoreUri(); |
|
101 |
|
102 public: |
|
103 |
|
104 // From base class MVPbkSingleContactOperationObserver |
|
105 |
|
106 /** |
|
107 * From MVPbkSingleContactOperationObserver |
|
108 * Called when operation is completed. |
|
109 * |
|
110 * @param aOperation the completed operation. |
|
111 * @param aContact the contact returned by the operation. |
|
112 * Client must take the ownership immediately. |
|
113 * |
|
114 * !!! NOTICE !!! |
|
115 * If you use Cleanupstack for MVPbkStoreContact |
|
116 * Use MVPbkStoreContact::PushL or |
|
117 * CleanupDeletePushL from e32base.h. |
|
118 * (Do Not Use CleanupStack::PushL(TAny*) because |
|
119 * then the virtual destructor of the M-class |
|
120 * won't be called when the object is deleted). |
|
121 */ |
|
122 void VPbkSingleContactOperationComplete( |
|
123 MVPbkContactOperationBase& aOperation, |
|
124 MVPbkStoreContact* aContact ); |
|
125 |
|
126 /** |
|
127 * From MVPbkSingleContactOperationObserver |
|
128 * Called if the operation fails. |
|
129 * |
|
130 * @param aOperation the failed operation. |
|
131 * @param aError error code of the failure. |
|
132 */ |
|
133 void VPbkSingleContactOperationFailed( |
|
134 MVPbkContactOperationBase& aOperation, |
|
135 TInt aError ); |
|
136 |
|
137 public : |
|
138 |
|
139 // From base class MVPbkContactViewObserver |
|
140 |
|
141 void ContactViewReady( |
|
142 MVPbkContactViewBase& aView ) ; |
|
143 |
|
144 void ContactViewUnavailable( |
|
145 MVPbkContactViewBase& aView ) ; |
|
146 |
|
147 void ContactAddedToView( |
|
148 MVPbkContactViewBase& aView, |
|
149 TInt aIndex, |
|
150 const MVPbkContactLink& aContactLink ); |
|
151 |
|
152 void ContactRemovedFromView( |
|
153 MVPbkContactViewBase& aView, |
|
154 TInt aIndex, |
|
155 const MVPbkContactLink& aContactLink ) ; |
|
156 |
|
157 void ContactViewError( |
|
158 MVPbkContactViewBase& aView, |
|
159 TInt aError, |
|
160 TBool aErrorNotified ) ; |
|
161 |
|
162 |
|
163 protected: |
|
164 |
|
165 // From base class CActive |
|
166 |
|
167 /** |
|
168 * From CActive |
|
169 * Implements cancellation of an outstanding request. |
|
170 * |
|
171 * This function is called as part of the active object's Cancel(). |
|
172 */ |
|
173 void DoCancel() ; |
|
174 |
|
175 /** |
|
176 * From CActive |
|
177 * Handles an active object's request completion event. |
|
178 * |
|
179 * The function is called by the active scheduler when a request |
|
180 * completion event occurs, i.e. after the active scheduler's |
|
181 * WaitForAnyRequest() function completes. |
|
182 * |
|
183 * Before calling this active object's RunL() function, the active scheduler |
|
184 * has: |
|
185 * |
|
186 * 1. decided that this is the highest priority active object with |
|
187 * a completed request |
|
188 * |
|
189 * 2. marked this active object's request as complete (i.e. the request is no |
|
190 * longer outstanding) |
|
191 * |
|
192 * RunL() runs under a trap harness in the active scheduler. If it leaves, |
|
193 * then the active scheduler calls RunError() to handle the leave. |
|
194 * |
|
195 * Note that once the active scheduler's Start() function has been called, |
|
196 * all user code is run under one of the program's active object's RunL() or |
|
197 * RunError() functions. |
|
198 */ |
|
199 void RunL(); |
|
200 |
|
201 |
|
202 /** |
|
203 * From CActive |
|
204 * If the RunL function leaves, |
|
205 * then the active scheduler calls RunError() to handle the leave. |
|
206 * @param aError - The error code |
|
207 */ |
|
208 TInt RunError( TInt aError ); |
|
209 |
|
210 private: |
|
211 |
|
212 /** |
|
213 * Constructor |
|
214 */ |
|
215 CPcsContactStore(); |
|
216 |
|
217 /** |
|
218 * 2nd phase constructor |
|
219 */ |
|
220 void ConstructL(CVPbkContactManager& aContactManager,MDataStoreObserver& aObserver,const TDesC& aUri); |
|
221 |
|
222 /** |
|
223 * Handles the operations for a single contact after it is fetched |
|
224 * @param aContact - The contact from database |
|
225 */ |
|
226 void HandleRetrievedContactL(MVPbkStoreContact* aContact); |
|
227 |
|
228 /** |
|
229 * Fetches the data from a particular contact |
|
230 * @param aContact - The contact from database |
|
231 * |
|
232 */ |
|
233 void GetDataForSingleContactL ( MVPbkBaseContact& aContact,CPsData* aPhoneData ); |
|
234 |
|
235 /** |
|
236 * Add the data from contact fields |
|
237 * @param aContact - The contact from database |
|
238 * @param afieldtype - Field to be added |
|
239 * @param aPhoneData - the contact data in PS format |
|
240 */ |
|
241 void AddContactFieldsL(MVPbkBaseContact& aContact,TInt afieldtype,CPsData* aPhoneData); |
|
242 |
|
243 /** |
|
244 * Fetches the data from contact links from the view |
|
245 */ |
|
246 void FetchlinksL(); |
|
247 |
|
248 /** |
|
249 * Reads the fields to cache from the central repository |
|
250 */ |
|
251 void ReadFieldsToCacheFromCenrepL(); |
|
252 |
|
253 /** |
|
254 * Creates a cacheId corresponding to sim Id Array Index |
|
255 * @param - aSimId - The sim id |
|
256 */ |
|
257 TInt CreateCacheIDfromSimArrayIndex(TInt aSimId); |
|
258 |
|
259 /** |
|
260 * Creates the contact fetch view |
|
261 */ |
|
262 void CreateContactFetchViewL(); |
|
263 /** |
|
264 * Issues request to active object to call RunL method |
|
265 */ |
|
266 void IssueRequest(); |
|
267 |
|
268 /** |
|
269 * Creates a sort order depending on the fields specified in the cenrep |
|
270 * @param aMasterList - aMasterList (i.e list containing all the vpbk fields) |
|
271 */ |
|
272 void CreateSortOrderL(const MVPbkFieldTypeList& aMasterList); |
|
273 |
|
274 private: |
|
275 |
|
276 |
|
277 /** |
|
278 * Flags for store operations |
|
279 */ |
|
280 TInt iAllContactLinksCount; |
|
281 TInt iFetchedContactCount; |
|
282 TBool iContactViewReady; |
|
283 /** |
|
284 * Variable to store the next state for the RunL to take appropriate action |
|
285 */ |
|
286 TInt iNextState; |
|
287 |
|
288 /** |
|
289 * The contact manager for accessing the phone contacts |
|
290 * Not Own. |
|
291 */ |
|
292 CVPbkContactManager* iContactManager; |
|
293 |
|
294 /** |
|
295 * Holds a view base instance |
|
296 * Own. |
|
297 */ |
|
298 MVPbkContactViewBase* iContactViewBase; |
|
299 |
|
300 /** |
|
301 * Holds a contact operation |
|
302 * Own. |
|
303 */ |
|
304 MVPbkContactOperationBase* iOp; |
|
305 |
|
306 /** |
|
307 * Owns an instance of active scheduler wait |
|
308 */ |
|
309 CActiveSchedulerWait *iWait; |
|
310 |
|
311 /** |
|
312 * data fields to be cached(read from the central repository) |
|
313 */ |
|
314 RArray<TInt> iFieldsToCache; |
|
315 |
|
316 /** |
|
317 * Array of contact links |
|
318 */ |
|
319 CVPbkContactLinkArray *iSimContactItems; |
|
320 |
|
321 /** |
|
322 * Holds the observer object to communicate add/modify/delete of contacts |
|
323 * Not owned. |
|
324 */ |
|
325 MDataStoreObserver* iObserver; |
|
326 |
|
327 /** |
|
328 * Contacts Database URI |
|
329 */ |
|
330 HBufC* iUri; |
|
331 |
|
332 /** |
|
333 * File session |
|
334 */ |
|
335 RFs iFs; |
|
336 |
|
337 /** |
|
338 * RTimer variable to set the timer before RunL calls any function. |
|
339 * This is required to allow other threads to run since contact fetch |
|
340 * is CPU intensive task. |
|
341 */ |
|
342 RTimer iTimer; |
|
343 /** |
|
344 * Holds the sort order fields |
|
345 */ |
|
346 CVPbkFieldTypeRefsList *iSortOrder; |
|
347 |
|
348 }; |
361 }; |
349 |
362 |
350 #endif // C_PCS_CONTACT_STORE_H |
363 #endif // C_PCS_CONTACT_STORE_H |