|
1 /* |
|
2 * Copyright (c) 2009 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 #include "presencecachebuddyidcreatorprivate.h" |
|
19 #include <CVPbkContactIdConverter.h> |
|
20 #include <CVPbkContactStoreUriArray.h> |
|
21 #include <VPbkContactStoreUris.h> |
|
22 #include <MVPbkContactStore.h> |
|
23 #include <TVPbkContactStoreUriPtr.h> |
|
24 #include <CVPbkContactManager.h> |
|
25 #include <MVPbkContactStoreList.h> |
|
26 #include <MVPbkContactStore.h> |
|
27 #include <MVPbkContactLinkArray.h> |
|
28 #include <cntdef.h> |
|
29 |
|
30 _LIT( KServiceIdentifier, "ContactStatusService:" ); |
|
31 |
|
32 CPresenceCacheBuddyIdCreatorPrivate* CPresenceCacheBuddyIdCreatorPrivate::NewL( |
|
33 CVPbkContactManager* aContactManager ) |
|
34 { |
|
35 CPresenceCacheBuddyIdCreatorPrivate* self = |
|
36 new (ELeave) CPresenceCacheBuddyIdCreatorPrivate( aContactManager ); |
|
37 CleanupStack::PushL( self ); |
|
38 self->ConstructL(); |
|
39 CleanupStack::Pop( self ); |
|
40 return self; |
|
41 } |
|
42 |
|
43 inline CPresenceCacheBuddyIdCreatorPrivate::CPresenceCacheBuddyIdCreatorPrivate( |
|
44 CVPbkContactManager* aContactManager ) |
|
45 : iContactManager( aContactManager ) |
|
46 { |
|
47 } |
|
48 |
|
49 inline void CPresenceCacheBuddyIdCreatorPrivate::ConstructL() |
|
50 { |
|
51 if( !iContactManager ) |
|
52 { |
|
53 CVPbkContactStoreUriArray* uriList = CVPbkContactStoreUriArray::NewLC(); |
|
54 uriList->AppendL( TVPbkContactStoreUriPtr( |
|
55 VPbkContactStoreUris::DefaultCntDbUri() ) ); |
|
56 |
|
57 iContactManager = CVPbkContactManager::NewL( *uriList ); |
|
58 CleanupStack::PopAndDestroy( uriList ); |
|
59 iOwnContactManager = ETrue; |
|
60 } |
|
61 MVPbkContactStore* store = iContactManager->ContactStoresL(). |
|
62 Find( VPbkContactStoreUris::DefaultCntDbUri() ); |
|
63 |
|
64 iConverter = CVPbkContactIdConverter::NewL( *store ); |
|
65 } |
|
66 |
|
67 CPresenceCacheBuddyIdCreatorPrivate::~CPresenceCacheBuddyIdCreatorPrivate() |
|
68 { |
|
69 delete iConverter; |
|
70 if( iOwnContactManager ) |
|
71 { |
|
72 delete iContactManager; |
|
73 } |
|
74 } |
|
75 |
|
76 HBufC* CPresenceCacheBuddyIdCreatorPrivate::CreateBuddyIdLC( |
|
77 const TDesC8& aContactLink ) |
|
78 { |
|
79 MVPbkContactLinkArray* linkList = |
|
80 iContactManager->CreateLinksLC( aContactLink ); |
|
81 TInt32 id = KNullContactId; |
|
82 if( linkList->Count() > 0 ) |
|
83 { |
|
84 const MVPbkContactLink& link = linkList->At( 0 ); |
|
85 id = iConverter->LinkToIdentifier( link ); |
|
86 } |
|
87 CleanupStack::PopAndDestroy(); // linkList |
|
88 |
|
89 HBufC* buddyId = NULL; |
|
90 if( KNullContactId == id ) |
|
91 { |
|
92 // incorrect aContactLink |
|
93 // -> can't create identifier |
|
94 User::Leave( KErrArgument ); |
|
95 } |
|
96 else |
|
97 { |
|
98 // generate presence identity from contact id in format |
|
99 // "[ServiceName]:[contact id]" |
|
100 // |
|
101 TBuf<11> num; // enough space to hold 32bit number |
|
102 num.Num( id ); |
|
103 buddyId = HBufC::NewLC( num.Length() + KServiceIdentifier().Length() ); |
|
104 TPtr retPtr( buddyId->Des() ); |
|
105 retPtr.Copy( KServiceIdentifier ); |
|
106 retPtr.Append( num ); |
|
107 } |
|
108 |
|
109 return buddyId; |
|
110 } |
|
111 |