|
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 the License "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: Store list observer implementation for getlist service api. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "contactservice.h" |
|
20 #include <CVPbkContactManager.h> |
|
21 #include <MVPbkContactStore.h> |
|
22 #include <barsread.h>//resource reader |
|
23 #include "contactiter.h" |
|
24 #include <MVPbkContactViewBase.h> |
|
25 #include <MVPbkContactViewFiltering.h> |
|
26 #include <cvpbkcontactviewdefinition.h> |
|
27 #include <MVPbkContactLink.h> |
|
28 #include <mvpbkcontactstoreproperties.h> |
|
29 #include <MVPbkContactOperationBase.h> |
|
30 #include "contactviewobserver.h" |
|
31 #include "getliststorelistobserver.h" |
|
32 #include "contactiter.h" |
|
33 |
|
34 |
|
35 /* |
|
36 ------------------------------------------------------------------------------------- |
|
37 CGetListStoreListObserver::Cancel() |
|
38 Description : Cancel implementation relevant to GetListObserver |
|
39 Return values : KErrorNone on Success and KErrGeneral on Failure |
|
40 ------------------------------------------------------------------------------------- |
|
41 */ |
|
42 |
|
43 void CGetListStoreListObserver::Cancel() |
|
44 { |
|
45 if(iIter) |
|
46 { |
|
47 delete iIter; |
|
48 iIter = NULL; |
|
49 } |
|
50 if(iRetOp) |
|
51 { |
|
52 delete iRetOp; |
|
53 iRetOp = NULL; |
|
54 } |
|
55 iCallback->HandleReturnValue(EOpCancel, KErrNone, iTransId); |
|
56 delete this; |
|
57 } |
|
58 |
|
59 // --------------------------------------------------------------------------- |
|
60 // Called By MVPbkContactStoreListObserver indicate the |
|
61 // the store is ready |
|
62 // --------------------------------------------------------------------------- |
|
63 // |
|
64 void CGetListStoreListObserver::StoreReady( MVPbkContactStore& aContactStore ) |
|
65 { |
|
66 iContactStore = &aContactStore; |
|
67 TRAPD(error,CreateAndFilterViewL(*iContactStore)); |
|
68 |
|
69 if(error !=KErrNone) |
|
70 { |
|
71 iContactService->RequestComplete(iTransId); |
|
72 iCallback->HandleReturnValue(EOpComplete, error, iTransId); |
|
73 } |
|
74 iContactService->RequestComplete(iTransId); |
|
75 if(iType != EOthers) |
|
76 delete this; |
|
77 } |
|
78 |
|
79 |
|
80 //---------------------------------------------------------------------------- |
|
81 // First creates the default view of the database, then creates a filtered view for it. |
|
82 // The fields to be searched in are made a part of the default view. |
|
83 // And the string to be searched for is used for filtering the view to obtain the results. |
|
84 // Sorting is taken into consideration for contacts alone. |
|
85 //---------------------------------------------------------------------------- |
|
86 void CGetListStoreListObserver::CreateAndFilterViewL( MVPbkContactStore& aContactStore) |
|
87 { |
|
88 |
|
89 CVPbkContactManager* contactManager =&(iContactService->GetContactManager()); |
|
90 |
|
91 if(iContactId && iContactId->Compare(KNullDesC8)) |
|
92 { |
|
93 CActiveSchedulerWait* schedulerWait = new (ELeave) CActiveSchedulerWait; |
|
94 CleanupStack::PushL(schedulerWait); |
|
95 |
|
96 //Extract the contactlink from the contactid |
|
97 MVPbkContactLinkArray* linkArray = (contactManager)->CreateLinksLC(*iContactId); |
|
98 |
|
99 |
|
100 //Set the params for iterator |
|
101 iIter->SetParams(linkArray, iUri, EAsc, iTransId, iType, iContactService); |
|
102 |
|
103 CContactRetrieveObserver* retrieveObserver = CContactRetrieveObserver::NewL(iIter, |
|
104 iCallback, |
|
105 iContactService, |
|
106 iType, |
|
107 iTransId, |
|
108 schedulerWait); |
|
109 |
|
110 CleanupStack::PushL(retrieveObserver); |
|
111 //Retrieve contact |
|
112 iRetOp = (contactManager)->RetrieveContactL((*linkArray)[0],*retrieveObserver ); |
|
113 iContactService->AddAsyncObjL(iTransId, retrieveObserver); |
|
114 |
|
115 CleanupStack::Pop(retrieveObserver); |
|
116 |
|
117 schedulerWait->Start(); |
|
118 |
|
119 iRetOp = NULL; |
|
120 CleanupStack::Pop(); |
|
121 CleanupStack::PopAndDestroy(schedulerWait); |
|
122 } |
|
123 else if(iType == EContacts) |
|
124 { |
|
125 if(!iSearchFields) |
|
126 { |
|
127 iFieldsList = CVPbkFieldTypeRefsList::NewL(); |
|
128 iFieldsList->AppendL(*(contactManager)->FieldTypes().Find(R_VPBK_FIELD_TYPE_LASTNAME)); |
|
129 iFieldsList->AppendL(*(contactManager)->FieldTypes().Find(R_VPBK_FIELD_TYPE_FIRSTNAME)); |
|
130 } |
|
131 |
|
132 CVPbkContactViewDefinition* viewdef = |
|
133 CVPbkContactViewDefinition::NewL(); |
|
134 CleanupStack::PushL(viewdef); |
|
135 |
|
136 //Set the Uri on which the view is to be built |
|
137 viewdef->SetUriL(iUri); |
|
138 |
|
139 CActiveSchedulerWait* schedulerWait = |
|
140 new (ELeave) CActiveSchedulerWait; |
|
141 |
|
142 CleanupStack::PushL(schedulerWait); |
|
143 |
|
144 |
|
145 CContactViewObserver* defaultView = |
|
146 CContactViewObserver::NewL(iCallback, |
|
147 EContactDefaultView, |
|
148 iIter, |
|
149 iContactService, |
|
150 iUri, |
|
151 iSortOrder, |
|
152 iTransId, |
|
153 schedulerWait); |
|
154 CleanupStack::PushL(defaultView); |
|
155 if(iSearchVal->Length() <= 0) |
|
156 { |
|
157 defaultView->ReturnDefaultView(); |
|
158 } |
|
159 MVPbkContactViewBase* contactView = NULL; |
|
160 |
|
161 if(iFieldsList) |
|
162 { |
|
163 //Create the default view for the database |
|
164 contactView = |
|
165 contactManager->CreateContactViewLC(*defaultView, |
|
166 *viewdef, |
|
167 *iFieldsList); |
|
168 } |
|
169 else |
|
170 { |
|
171 CVPbkFieldTypeRefsList* fieldList = iSearchFields->GetFieldListL(); |
|
172 //Create the default view for the database |
|
173 if(fieldList) |
|
174 { |
|
175 contactView = |
|
176 contactManager->CreateContactViewLC(*defaultView, |
|
177 *viewdef, |
|
178 *fieldList); |
|
179 } |
|
180 else |
|
181 { |
|
182 User::Leave(KErrArgument); |
|
183 } |
|
184 |
|
185 } |
|
186 iContactService->AddAsyncObjL(iTransId, defaultView); |
|
187 |
|
188 schedulerWait->Start(); |
|
189 |
|
190 if(iSearchVal->Length() > 0) //Filter the view only if searchVal is given |
|
191 { |
|
192 // Initialise the Search Strings |
|
193 CDesCArrayFlat* findStrings; |
|
194 findStrings = new(ELeave)CDesCArrayFlat( 10 ); |
|
195 CleanupStack::PushL(findStrings); |
|
196 |
|
197 findStrings->AppendL(*iSearchVal); |
|
198 |
|
199 //Create filtered view of the database |
|
200 CContactViewObserver* filteredView = |
|
201 CContactViewObserver::NewL(iCallback, |
|
202 EContactFilteredView, |
|
203 iIter, |
|
204 iContactService, |
|
205 iUri, |
|
206 iSortOrder, |
|
207 iTransId, |
|
208 schedulerWait); |
|
209 |
|
210 CleanupStack::PushL(filteredView); |
|
211 //Filtering the view to find the iFindStrings |
|
212 MVPbkContactViewBase* findView = |
|
213 contactView->ViewFiltering()->CreateFilteredViewLC(*filteredView, |
|
214 *findStrings, |
|
215 NULL); |
|
216 iContactService->AddAsyncObjL(iTransId, filteredView); |
|
217 schedulerWait->Start(); |
|
218 CleanupStack::PopAndDestroy(); |
|
219 CleanupStack::PopAndDestroy(filteredView); |
|
220 CleanupStack::PopAndDestroy(findStrings); |
|
221 } |
|
222 CleanupStack::PopAndDestroy(); |
|
223 CleanupStack::PopAndDestroy(defaultView); |
|
224 CleanupStack::PopAndDestroy(schedulerWait); |
|
225 CleanupStack::PopAndDestroy(viewdef); |
|
226 } |
|
227 else if(iType == EGroups) |
|
228 { |
|
229 //Get the linkarray of the groups in the database |
|
230 MVPbkContactLinkArray* array = aContactStore.ContactGroupsLC(); |
|
231 if(array->Count()) |
|
232 { |
|
233 //Set the iterator with the result |
|
234 iIter->SetParams(array, iUri, EAsc, iTransId, EGroups, iContactService); |
|
235 |
|
236 iContactService->RequestComplete(iTransId); |
|
237 //Notify the user |
|
238 iCallback->HandleReturnIter(KErrNone, iIter, iTransId); |
|
239 } |
|
240 else |
|
241 { |
|
242 iContactService->RequestComplete(iTransId); |
|
243 //Notify the user |
|
244 iCallback->HandleReturnValue(EOpComplete, KErrNotFound, iTransId); |
|
245 } |
|
246 CleanupStack::Pop(); |
|
247 } |
|
248 else if(iType == EOthers) |
|
249 { |
|
250 TRequestStatus* status = &(iIter->iSyncIter->iStatus); |
|
251 User::RequestComplete(status, KErrNone); |
|
252 } |
|
253 } |
|
254 |
|
255 |
|
256 // --------------------------------------------------------------------------- |
|
257 // For a possibility that store might be unavailable. |
|
258 // Appropriate error code is returned |
|
259 // --------------------------------------------------------------------------- |
|
260 void CGetListStoreListObserver::StoreUnavailable( |
|
261 MVPbkContactStore& aContactStore, |
|
262 TInt aReason ) |
|
263 { |
|
264 if(iType == EOthers) |
|
265 { |
|
266 TRequestStatus* status = &(iIter->iSyncIter->iStatus); |
|
267 User::RequestComplete(status, KErrNone); |
|
268 } |
|
269 else |
|
270 { |
|
271 iContactService->RequestComplete(iTransId); |
|
272 //Notify User |
|
273 iCallback->HandleReturnValue(EOpError, aReason, iTransId); |
|
274 } |
|
275 aContactStore.Close(*this); |
|
276 delete iIter; |
|
277 iIter = NULL; |
|
278 delete this; |
|
279 } |
|
280 |
|
281 // --------------------------------------------------------------------------- |
|
282 // NewL() method |
|
283 // --------------------------------------------------------------------------- |
|
284 |
|
285 CGetListStoreListObserver* CGetListStoreListObserver:: |
|
286 NewL(const TDesC& aUri, |
|
287 const TDesC8& aContactId, |
|
288 const TDesC& aSearchVal, |
|
289 CSearchFields* aSearchFields, |
|
290 TOrder aSortOrder, |
|
291 MContactCallback *aCallback, |
|
292 CContactService *aContactService, |
|
293 CContactIter* aIter, |
|
294 enum Ttype aType, TInt aTransId, |
|
295 MVPbkContactStore* aContactStore) |
|
296 |
|
297 { |
|
298 CGetListStoreListObserver* self = |
|
299 new( ELeave ) CGetListStoreListObserver(aUri, |
|
300 aContactId, |
|
301 aSearchVal, |
|
302 aSearchFields, |
|
303 aSortOrder, |
|
304 aCallback, |
|
305 aContactService, |
|
306 aIter, |
|
307 aType, |
|
308 aTransId, |
|
309 aContactStore); |
|
310 self->ConstructL(aContactId, aSearchVal); |
|
311 return self; |
|
312 } |
|
313 |
|
314 |
|
315 void CGetListStoreListObserver::ConstructL( const TDesC8& aContactId, |
|
316 const TDesC& aSearchVal ) |
|
317 { |
|
318 if(&aContactId) |
|
319 { |
|
320 iContactId = HBufC8 :: NewL(aContactId.Length()); |
|
321 *iContactId = aContactId; |
|
322 } |
|
323 if(&aSearchVal) |
|
324 { |
|
325 iSearchVal = HBufC :: NewL(aSearchVal.Length()); |
|
326 *iSearchVal = aSearchVal; |
|
327 } |
|
328 } |
|
329 |
|
330 CGetListStoreListObserver:: |
|
331 CGetListStoreListObserver(const TDesC& aUri,const TDesC8& /*aContactId*/, |
|
332 const TDesC& /*aSearchVal*/, |
|
333 CSearchFields* aSearchFields, |
|
334 TOrder aSortOrder, |
|
335 MContactCallback *aCallback, |
|
336 CContactService *aContactService, |
|
337 CContactIter* aIter, |
|
338 enum Ttype aType, TInt aTransId, |
|
339 MVPbkContactStore* aContactStore) |
|
340 { |
|
341 iUri = aUri; |
|
342 iSearchFields = aSearchFields; |
|
343 iSortOrder = aSortOrder; |
|
344 iCallback=aCallback; |
|
345 iContactService = aContactService; |
|
346 iIter = aIter; |
|
347 iType = aType; |
|
348 iTransId = aTransId; |
|
349 iFieldsList = NULL; |
|
350 iRetOp = NULL; |
|
351 iContactStore = aContactStore; |
|
352 } |
|
353 |
|
354 |
|
355 CGetListStoreListObserver::~CGetListStoreListObserver() |
|
356 { |
|
357 if(iSearchFields) |
|
358 { |
|
359 delete iSearchFields; |
|
360 iSearchFields =NULL; |
|
361 } |
|
362 delete iFieldsList; |
|
363 delete iContactId; |
|
364 delete iSearchVal; |
|
365 if(iContactStore) |
|
366 { |
|
367 iContactStore->Close(*this); |
|
368 iContactStore = NULL; |
|
369 } |
|
370 } |
|
371 |
|
372 |
|
373 void CGetListStoreListObserver::HandleStoreEventL( |
|
374 MVPbkContactStore& /*aContactStore*/, |
|
375 TVPbkContactStoreEvent /*aStoreEvent*/ ) |
|
376 { |
|
377 } |
|
378 |
|
379 void CGetListStoreListObserver::OpenComplete() |
|
380 { |
|
381 } |