|
1 /* |
|
2 * Copyright (c) 2010 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: IETF SIMPLE Protocol implementation for XIMP Framework |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <VPbkContactStoreUris.h> |
|
20 #include <spsettings.h> |
|
21 #include <spproperty.h> |
|
22 #include <CVPbkContactManager.h> |
|
23 #include <CVPbkContactStoreUriArray.h> |
|
24 #include <TVPbkContactStoreUriPtr.h> |
|
25 #include <MVPbkContactOperationBase.h> |
|
26 #include <MVPbkContactStoreList.h> |
|
27 #include <MVPbkContactLinkArray.h> |
|
28 #include <MVPbkContactLink.h> |
|
29 #include <MVPbkStoreContact.h> |
|
30 #include <MVPbkContactFieldData.h> |
|
31 #include <MVPbkContactFieldTextData.h> |
|
32 #include <MVPbkContactFieldUriData.h> |
|
33 #include <CVPbkContactIdConverter.h> |
|
34 #include <MVPbkStoreContactFieldCollection.h> |
|
35 #include <CVPbkFieldTypeRefsList.h> |
|
36 #include <VPbkEng.rsg> |
|
37 |
|
38 #include "presenceplugincontacts.h" |
|
39 #include "presencelogger.h" |
|
40 #include "presenceplugincontactsobs.h" |
|
41 #include "presenceplugincontactstatehandler.h" |
|
42 #include "presencepluginlocalstore.h" |
|
43 // States |
|
44 #include "presenceplugincontactstate.h" |
|
45 #include "presenceplugincontactstateopen.h" |
|
46 #include "presenceplugincontactstateresolve.h" |
|
47 #include "presenceplugincontactstatesearch.h" |
|
48 #include "presenceplugincontactstateend.h" |
|
49 |
|
50 const TInt KSDMASPSMaxPropertyLength = 512; |
|
51 |
|
52 |
|
53 // ======== MEMBER FUNCTIONS ======== |
|
54 |
|
55 // --------------------------------------------------------------------------- |
|
56 // CPresencePluginContacts::CPresencePluginContacts() |
|
57 // --------------------------------------------------------------------------- |
|
58 // |
|
59 CPresencePluginContacts::CPresencePluginContacts( TInt aServiceId, |
|
60 MPresencePluginContactsObs& aObserver ) |
|
61 : CActive( CActive::EPriorityStandard ), |
|
62 iServiceId( aServiceId ), |
|
63 iObserver( &aObserver ) |
|
64 { |
|
65 CActiveScheduler::Add(this); |
|
66 } |
|
67 |
|
68 |
|
69 // --------------------------------------------------------------------------- |
|
70 // CPresencePluginContacts::ConstructL() |
|
71 // --------------------------------------------------------------------------- |
|
72 // |
|
73 void CPresencePluginContacts::ConstructL( const TDesC& aServiceName ) |
|
74 { |
|
75 DP_SDA( "CPresencePluginContacts::ConstructL()" ); |
|
76 |
|
77 iServiceName = aServiceName.AllocL(); |
|
78 CVPbkContactStoreUriArray* uriArray = CVPbkContactStoreUriArray::NewLC(); |
|
79 HBufC* storeName = ContactStoreNameL(); |
|
80 |
|
81 if ( NULL != storeName ) |
|
82 { |
|
83 DP_SDA2( "CPresencePluginContacts::ConstructL() %S", storeName ); |
|
84 CleanupStack::PushL( storeName ); |
|
85 uriArray->AppendL( TVPbkContactStoreUriPtr( *storeName ) ); |
|
86 CleanupStack::PopAndDestroy( storeName ); |
|
87 } |
|
88 else |
|
89 { |
|
90 DP_SDA( "CPresencePluginContacts::ConstructL() Use default contact store uri" ); |
|
91 uriArray->AppendL( TVPbkContactStoreUriPtr( |
|
92 VPbkContactStoreUris::DefaultCntDbUri() ) ); |
|
93 } |
|
94 iContactManager = CVPbkContactManager::NewL( *uriArray ); |
|
95 CleanupStack::PopAndDestroy( uriArray ); |
|
96 |
|
97 DP_SDA( "CPresencePluginContacts::ConstructL() -exit" ); |
|
98 } |
|
99 |
|
100 |
|
101 // --------------------------------------------------------------------------- |
|
102 // CPresencePluginContacts::NewL() |
|
103 // --------------------------------------------------------------------------- |
|
104 // |
|
105 CPresencePluginContacts* CPresencePluginContacts::NewL( TInt aServiceId, |
|
106 const TDesC& aServiceName, MPresencePluginContactsObs& aObserver ) |
|
107 { |
|
108 CPresencePluginContacts* self = |
|
109 CPresencePluginContacts::NewLC( aServiceId, aServiceName, aObserver ); |
|
110 CleanupStack::Pop( self ); |
|
111 return self; |
|
112 } |
|
113 |
|
114 |
|
115 // --------------------------------------------------------------------------- |
|
116 // CPresencePluginContacts::NewLC() |
|
117 // --------------------------------------------------------------------------- |
|
118 // |
|
119 CPresencePluginContacts* CPresencePluginContacts::NewLC( TInt aServiceId, |
|
120 const TDesC& aServiceName, MPresencePluginContactsObs& aObserver ) |
|
121 { |
|
122 CPresencePluginContacts* self = |
|
123 new( ELeave ) CPresencePluginContacts( aServiceId, aObserver ); |
|
124 CleanupStack::PushL( self ); |
|
125 self->ConstructL( aServiceName ); |
|
126 return self; |
|
127 } |
|
128 |
|
129 |
|
130 // --------------------------------------------------------------------------- |
|
131 // CPresencePluginContacts::~CPresencePluginContacts() |
|
132 // --------------------------------------------------------------------------- |
|
133 // |
|
134 CPresencePluginContacts::~CPresencePluginContacts() |
|
135 { |
|
136 DP_SDA("CPresencePluginContacts::~CPresencePluginContacts"); |
|
137 |
|
138 delete iServiceName; |
|
139 delete iSearchText; |
|
140 delete iContactOperation; |
|
141 iStoreContactArray.ResetAndDestroy(); |
|
142 delete iStateHandler; |
|
143 delete iFieldTypeRefList; |
|
144 delete iContactLinkArray; |
|
145 if( iContactManager ) |
|
146 { |
|
147 TRAP_IGNORE( iContactManager->ContactStoresL().CloseAll( *this ) ); |
|
148 } |
|
149 delete iContactManager; |
|
150 iClientStatus = NULL; |
|
151 } |
|
152 |
|
153 |
|
154 // --------------------------------------------------------------------------- |
|
155 // CPresencePluginContacts::PresenceIdStoredL |
|
156 // --------------------------------------------------------------------------- |
|
157 // |
|
158 void CPresencePluginContacts::IsPresenceIdStoredL( |
|
159 const TDesC16& aPresenceId, TRequestStatus& aStatus ) |
|
160 { |
|
161 DP_SDA( "CPresencePluginContacts::IsPresenceIdStoredL -Enter" ); |
|
162 |
|
163 iOperation = EOperationIsPresenceStoredToContacts; |
|
164 |
|
165 aStatus = KRequestPending; |
|
166 iClientStatus = &aStatus; |
|
167 |
|
168 iSearchText = HBufC::NewL( |
|
169 iServiceName->Length() + aPresenceId.Length() + 1 ); |
|
170 TPtr searchTextPtr = iSearchText->Des(); |
|
171 searchTextPtr.Copy( *iServiceName ); |
|
172 searchTextPtr.Append( ':' ); |
|
173 searchTextPtr.Append( aPresenceId ); |
|
174 |
|
175 iFieldTypeRefList = CVPbkFieldTypeRefsList::NewL(); |
|
176 iFieldTypeRefList->AppendL( |
|
177 *iContactManager->FieldTypes().Find( R_VPBK_FIELD_TYPE_IMPP ) ); |
|
178 |
|
179 iStateHandler = CPresencePluginContactStateHandler::NewL(); |
|
180 |
|
181 iStateHandler->AddStateL( new( ELeave ) CPresencePluginContactStateOpen( |
|
182 *this, *iStateHandler ) ); |
|
183 iStateHandler->AddStateL( new( ELeave ) CPresencePluginContactStateSearch( |
|
184 *this, *iStateHandler ) ); |
|
185 iStateHandler->AddStateL( new( ELeave ) CPresencePluginContactStateResolve( |
|
186 *this, *iStateHandler ) ); |
|
187 iStateHandler->AddStateL( new( ELeave ) CPresencePluginContactStateEnd( |
|
188 *this, *iStateHandler ) ); |
|
189 |
|
190 iStateHandler->Start( &iStatus ); |
|
191 SetActive(); |
|
192 |
|
193 DP_SDA( "CPresencePluginContacts::IsPresenceIdStoredL - exit" ); |
|
194 } |
|
195 |
|
196 |
|
197 // --------------------------------------------------------------------------- |
|
198 // CPresencePluginContacts::ContactStoreNameL |
|
199 // --------------------------------------------------------------------------- |
|
200 // |
|
201 HBufC* CPresencePluginContacts::ContactStoreNameL() |
|
202 { |
|
203 DP_SDA( "CPresencePluginContacts::ContactStoreNameL()" ); |
|
204 |
|
205 HBufC* storeName = NULL; |
|
206 CSPSettings* spSettings = CSPSettings::NewLC(); |
|
207 CSPProperty* property = CSPProperty::NewLC(); |
|
208 |
|
209 TInt err = spSettings->FindPropertyL( iServiceId, |
|
210 EPropertyContactStoreId, |
|
211 *property ); |
|
212 |
|
213 if ( KErrNone == err ) |
|
214 { |
|
215 storeName = HBufC::NewL( KSDMASPSMaxPropertyLength ); |
|
216 TPtr16 storeNamePtr = storeName->Des(); |
|
217 err = property->GetValue( storeNamePtr ); |
|
218 } |
|
219 |
|
220 CleanupStack::PopAndDestroy( property ); |
|
221 CleanupStack::PopAndDestroy( spSettings ); |
|
222 |
|
223 return storeName; |
|
224 } |
|
225 |
|
226 |
|
227 // --------------------------------------------------------------------------- |
|
228 // From class MPresenceContactsContextBase. |
|
229 // CPresencePluginContacts::Open |
|
230 // --------------------------------------------------------------------------- |
|
231 // |
|
232 void CPresencePluginContacts::OpenL() |
|
233 { |
|
234 DP_SDA( "CPresencePluginContacts::Open()" ); |
|
235 iContactManager->ContactStoresL().OpenAllL( *this ); |
|
236 } |
|
237 |
|
238 |
|
239 // --------------------------------------------------------------------------- |
|
240 // From class MPresenceContactsContextBase. |
|
241 // CPresencePluginContacts::Search |
|
242 // --------------------------------------------------------------------------- |
|
243 // |
|
244 void CPresencePluginContacts::SearchL() |
|
245 { |
|
246 DP_SDA( "CPresencePluginContacts::Search()" ); |
|
247 iContactOperation = iContactManager->FindL( |
|
248 *iSearchText, *iFieldTypeRefList, *this ); |
|
249 } |
|
250 |
|
251 |
|
252 // --------------------------------------------------------------------------- |
|
253 // From class MPresenceContactsContextBase. |
|
254 // CPresencePluginContacts::ContactLinkArray |
|
255 // --------------------------------------------------------------------------- |
|
256 // |
|
257 const MVPbkContactLinkArray& CPresencePluginContacts::ContactLinkArrayL() |
|
258 { |
|
259 if ( NULL == iContactLinkArray ) |
|
260 { |
|
261 User::Leave( KErrNotReady ); |
|
262 } |
|
263 return *iContactLinkArray; |
|
264 } |
|
265 |
|
266 |
|
267 // --------------------------------------------------------------------------- |
|
268 // From class MPresenceContactsContextBase. |
|
269 //CPresencePluginContacts::RetrieveContactL |
|
270 // --------------------------------------------------------------------------- |
|
271 // |
|
272 void CPresencePluginContacts::RetrieveContactL( |
|
273 const MVPbkContactLink& aContactLink ) |
|
274 { |
|
275 DP_SDA( "CPresencePluginContacts::RetrieveContactL()" ); |
|
276 iContactOperation = |
|
277 iContactManager->RetrieveContactL( aContactLink, *this ); |
|
278 } |
|
279 |
|
280 |
|
281 // --------------------------------------------------------------------------- |
|
282 // From class MVPbkContactStoreListObserver. |
|
283 // CPresencePluginContacts::OpenComplete |
|
284 // --------------------------------------------------------------------------- |
|
285 // |
|
286 void CPresencePluginContacts::OpenComplete() |
|
287 { |
|
288 DP_SDA( "CPresencePluginContacts::OpenComplete()" ); |
|
289 iStateHandler->State()->Complete(); |
|
290 } |
|
291 |
|
292 |
|
293 // --------------------------------------------------------------------------- |
|
294 // From class MVPbkContactStoreObserver. |
|
295 // CPresencePluginContacts::StoreReady |
|
296 // --------------------------------------------------------------------------- |
|
297 // |
|
298 void CPresencePluginContacts::StoreReady( |
|
299 MVPbkContactStore& /*aContactStore*/ ) |
|
300 { |
|
301 DP_SDA( "CPresencePluginContacts::StoreReady()" ); |
|
302 } |
|
303 |
|
304 |
|
305 // --------------------------------------------------------------------------- |
|
306 // From class MVPbkContactStoreObserver. |
|
307 // CPresencePluginContacts::StoreUnavailable |
|
308 // --------------------------------------------------------------------------- |
|
309 // |
|
310 void CPresencePluginContacts::StoreUnavailable( |
|
311 MVPbkContactStore& /*aContactStore*/, TInt /*aReason*/ ) |
|
312 { |
|
313 DP_SDA( "CPresencePluginContacts::StoreUnavailable()" ); |
|
314 } |
|
315 |
|
316 |
|
317 // --------------------------------------------------------------------------- |
|
318 // From class MVPbkContactStoreObserver. |
|
319 // CPresencePluginContacts::HandleStoreEventL |
|
320 // --------------------------------------------------------------------------- |
|
321 // |
|
322 void CPresencePluginContacts::HandleStoreEventL( |
|
323 MVPbkContactStore& /*aContactStore*/, |
|
324 TVPbkContactStoreEvent /*aStoreEvent*/ ) |
|
325 { |
|
326 DP_SDA( "CPresencePluginContacts::HandleStoreEventL()" ); |
|
327 } |
|
328 |
|
329 |
|
330 // --------------------------------------------------------------------------- |
|
331 // From class MVPbkContactFindObserver. |
|
332 // CPresencePluginContacts::FindCompleteL |
|
333 // --------------------------------------------------------------------------- |
|
334 // |
|
335 void CPresencePluginContacts::FindCompleteL( MVPbkContactLinkArray* aResults ) |
|
336 { |
|
337 DP_SDA( "CPresencePluginContacts::FindCompleteL()" ); |
|
338 |
|
339 delete iContactLinkArray; |
|
340 iContactLinkArray = NULL; |
|
341 iContactLinkArray = aResults; |
|
342 |
|
343 delete iContactOperation; |
|
344 iContactOperation = NULL; |
|
345 |
|
346 iStateHandler->State()->Complete(); |
|
347 } |
|
348 |
|
349 |
|
350 // --------------------------------------------------------------------------- |
|
351 // From class MVPbkContactFindObserver. |
|
352 // CPresencePluginContacts::FindFailed |
|
353 // --------------------------------------------------------------------------- |
|
354 // |
|
355 void CPresencePluginContacts::FindFailed( TInt aError ) |
|
356 { |
|
357 DP_SDA( "CPresencePluginContacts::FindFailed()" ); |
|
358 |
|
359 delete iContactOperation; |
|
360 iContactOperation = NULL; |
|
361 |
|
362 iStateHandler->State()->Error( aError ); |
|
363 } |
|
364 |
|
365 |
|
366 // --------------------------------------------------------------------------- |
|
367 // From class MVPbkSingleContactOperationObserver. |
|
368 // CPresencePluginContacts::VPbkSingleContactOperationComplete |
|
369 // --------------------------------------------------------------------------- |
|
370 // |
|
371 void CPresencePluginContacts::VPbkSingleContactOperationComplete( |
|
372 MVPbkContactOperationBase& aOperation, |
|
373 MVPbkStoreContact* aContact ) |
|
374 { |
|
375 DP_SDA( "CPresencePluginContacts::VPbkSingleContactOperationComplete()" ); |
|
376 |
|
377 if ( iContactOperation == &aOperation ) |
|
378 { |
|
379 delete iContactOperation; |
|
380 iContactOperation = NULL; |
|
381 } |
|
382 |
|
383 TInt error = iStoreContactArray.Append( aContact ); |
|
384 if ( KErrNone != error ) |
|
385 { |
|
386 delete aContact; |
|
387 aContact = NULL; |
|
388 iStateHandler->State()->Error( error ); |
|
389 } |
|
390 else |
|
391 { |
|
392 iStateHandler->State()->Complete(); |
|
393 } |
|
394 } |
|
395 |
|
396 |
|
397 // --------------------------------------------------------------------------- |
|
398 // From class MVPbkSingleContactOperationObserver. |
|
399 // CPresencePluginContacts::VPbkSingleContactOperationFailed |
|
400 // --------------------------------------------------------------------------- |
|
401 // |
|
402 void CPresencePluginContacts::VPbkSingleContactOperationFailed( |
|
403 MVPbkContactOperationBase& aOperation, |
|
404 TInt aError ) |
|
405 { |
|
406 DP_SDA( "CPresencePluginContacts::VPbkSingleContactOperationFailed()" ); |
|
407 |
|
408 if ( iContactOperation == &aOperation ) |
|
409 { |
|
410 delete iContactOperation; |
|
411 iContactOperation = NULL; |
|
412 } |
|
413 |
|
414 iStateHandler->State()->Error( aError); |
|
415 } |
|
416 |
|
417 |
|
418 // --------------------------------------------------------------------------- |
|
419 // From class CActive. |
|
420 // CPresencePluginContacts::RunL |
|
421 // --------------------------------------------------------------------------- |
|
422 // |
|
423 void CPresencePluginContacts::RunL() |
|
424 { |
|
425 DP_SDA2( "CPresencePluginContacts::RunL - status %d", iStatus.Int() ); |
|
426 |
|
427 TBool result( EFalse ); |
|
428 TBool found( EFalse ); |
|
429 CPresencePluginLocalstore* localStore = NULL; |
|
430 TInt error = iStatus.Int(); |
|
431 |
|
432 switch( iOperation ) |
|
433 { |
|
434 case EOperationIsPresenceStoredToContacts: |
|
435 DP_SDA( "CPresencePluginContacts::RunL -EOperationIsPresenceStoredToContacts" ); |
|
436 |
|
437 if ( KErrNone == error ) |
|
438 { |
|
439 localStore = CPresencePluginLocalstore::NewLC( *iServiceName ); |
|
440 |
|
441 for ( TInt i( 0 ); ( i < iStoreContactArray.Count() ) && !found; i++ ) |
|
442 { |
|
443 MVPbkContactLink* link = iStoreContactArray[ i ]->CreateLinkLC(); |
|
444 CVPbkContactIdConverter* converter = |
|
445 CVPbkContactIdConverter::NewL( link->ContactStore() ); |
|
446 CleanupStack::PushL( converter ); |
|
447 |
|
448 TInt32 id = converter->LinkToIdentifier( *link ); |
|
449 if ( localStore->SeekRowAtContactColL( id ) ) |
|
450 { |
|
451 found = ETrue; |
|
452 result = ETrue; |
|
453 } |
|
454 CleanupStack::PopAndDestroy( converter ); |
|
455 CleanupStack::PopAndDestroy(); // link |
|
456 } |
|
457 |
|
458 CleanupStack::PopAndDestroy( localStore ); |
|
459 } |
|
460 if ( KErrNotFound == error ) |
|
461 { |
|
462 error = KErrNone; |
|
463 } |
|
464 iObserver->RequestComplete( &result, iOperation, error ); |
|
465 break; |
|
466 default: |
|
467 break; |
|
468 } |
|
469 // Operation completed. |
|
470 // State handler not needet anymore |
|
471 delete iStateHandler; |
|
472 iStateHandler = NULL; |
|
473 // Close contact stores |
|
474 iContactManager->ContactStoresL().CloseAll( *this ); |
|
475 |
|
476 User::RequestComplete( iClientStatus, error ); |
|
477 } |
|
478 |
|
479 |
|
480 // --------------------------------------------------------------------------- |
|
481 // From class CActive. |
|
482 // CPresencePluginContacts::DoCancel |
|
483 // --------------------------------------------------------------------------- |
|
484 // |
|
485 void CPresencePluginContacts::DoCancel() |
|
486 { |
|
487 if ( iClientStatus && *iClientStatus == KRequestPending ) |
|
488 { |
|
489 User::RequestComplete( iClientStatus, KErrCancel ); |
|
490 } |
|
491 iStateHandler->Complete( KErrCancel ); |
|
492 } |
|
493 |
|
494 |
|
495 // --------------------------------------------------------------------------- |
|
496 // From class CActive. |
|
497 // CPresencePluginContacts::RunError |
|
498 // --------------------------------------------------------------------------- |
|
499 // |
|
500 TInt CPresencePluginContacts::RunError( TInt aError ) |
|
501 { |
|
502 DP_SDA2( "CPresencePluginContacts::RunError - status %d", aError ); |
|
503 User::RequestComplete( iClientStatus, aError ); |
|
504 return KErrNone; |
|
505 } |
|
506 |
|
507 // End of file |