|
1 /* |
|
2 * Copyright (c) 2002-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: The virtual phonebook contact id converter |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "CContactIdConverter.h" |
|
20 #include "CContactLink.h" |
|
21 #include "CContactStore.h" |
|
22 #include "CContact.h" |
|
23 |
|
24 #include <CVPbkContactManager.h> |
|
25 #include <MVPbkContactStoreProperties.h> |
|
26 #include <MVPbkContactStoreList.h> |
|
27 #include <VPbkStoreUriLiterals.h> |
|
28 #include <MVPbkContactLink.h> |
|
29 #include <MVPbkStoreContactField.h> |
|
30 |
|
31 #include <cntdef.h> |
|
32 |
|
33 // From Phonebook |
|
34 #include <CPbkContactEngine.h> |
|
35 #include <CPbkContactItem.h> |
|
36 |
|
37 namespace VPbkCntModel { |
|
38 |
|
39 _LIT( KCntDbURIDomain, "cntdb" ); |
|
40 |
|
41 CContactIdConverter::CContactIdConverter( MVPbkContactStore& aContactStore ) : |
|
42 iContactStore( static_cast<CContactStore&>(aContactStore) ) |
|
43 { |
|
44 } |
|
45 |
|
46 CContactIdConverter* CContactIdConverter::NewL( TAny* aParam ) |
|
47 { |
|
48 MVPbkContactStore& store = *static_cast<MVPbkContactStore*>( aParam ); |
|
49 |
|
50 if ( store.StoreProperties().Uri().Compare( |
|
51 KCntDbURIDomain, |
|
52 TVPbkContactStoreUriPtr::EContactStoreUriStoreType) != 0 ) |
|
53 { |
|
54 User::Leave( KErrNotSupported ); |
|
55 } |
|
56 |
|
57 CContactIdConverter* self = new( ELeave ) CContactIdConverter( store ); |
|
58 return self; |
|
59 } |
|
60 |
|
61 CContactIdConverter::~CContactIdConverter() |
|
62 { |
|
63 delete iPbkEngine; |
|
64 } |
|
65 |
|
66 TInt32 CContactIdConverter::LinkToIdentifier( const MVPbkContactLink& aLink ) const |
|
67 { |
|
68 TInt32 result = KNullContactId; |
|
69 if ( &aLink && &aLink.ContactStore() == &iContactStore ) |
|
70 { |
|
71 const CContactLink& link = static_cast<const CContactLink&>( aLink ); |
|
72 result = link.ContactId(); |
|
73 } |
|
74 return result; |
|
75 } |
|
76 |
|
77 MVPbkContactLink* CContactIdConverter::IdentifierToLinkLC( TInt32 aIdentifier ) const |
|
78 { |
|
79 return CContactLink::NewLC( iContactStore, aIdentifier ); |
|
80 } |
|
81 |
|
82 TInt CContactIdConverter::PbkEngFieldIndexL( |
|
83 const MVPbkStoreContactField& aField ) const |
|
84 { |
|
85 TInt result = KErrNotFound; |
|
86 if ( &aField.ContactStore() == &iContactStore ) |
|
87 { |
|
88 const TContactField& field = static_cast<const TContactField&>( aField ); |
|
89 CContact& contact = static_cast<CContact&>( aField.ParentContact() ); |
|
90 |
|
91 CPbkContactItem* ci = PbkEngineL()->ReadContactLC( |
|
92 contact.NativeContact()->Id() ); |
|
93 |
|
94 CPbkFieldArray& fields = ci->CardFields(); |
|
95 const TInt fieldCount = fields.Count(); |
|
96 for ( TInt i = 0; i < fieldCount; ++i ) |
|
97 { |
|
98 if ( fields[i].ItemField().Id() == field.NativeField()->Id() ) |
|
99 { |
|
100 result = i; |
|
101 break; |
|
102 } |
|
103 } |
|
104 |
|
105 CleanupStack::PopAndDestroy(); // ci |
|
106 } |
|
107 return result; |
|
108 } |
|
109 |
|
110 CPbkContactItem* CContactIdConverter::LinkToPbkContactItemLC( |
|
111 const MVPbkContactLink& aLink ) const |
|
112 { |
|
113 CPbkContactItem* contact = NULL; |
|
114 TInt32 linkId( LinkToIdentifier(aLink) ); |
|
115 if ( linkId != KNullContactId ) |
|
116 { |
|
117 contact = PbkEngineL()->ReadContactLC( linkId ); |
|
118 } |
|
119 return contact; |
|
120 } |
|
121 |
|
122 CPbkContactItem* CContactIdConverter::LinkToOpenPbkContactItemLCX( |
|
123 const MVPbkContactLink& aLink ) const |
|
124 { |
|
125 CPbkContactItem* contact = NULL; |
|
126 TInt32 linkId( LinkToIdentifier(aLink) ); |
|
127 if ( linkId != KNullContactId ) |
|
128 { |
|
129 contact = PbkEngineL()->OpenContactLCX( linkId ); |
|
130 } |
|
131 return contact; |
|
132 } |
|
133 |
|
134 void CContactIdConverter::CommitOpenContactItemL( CPbkContactItem& aContactItem ) |
|
135 { |
|
136 PbkEngineL()->CommitContactL( aContactItem ); |
|
137 } |
|
138 |
|
139 CPbkContactEngine* CContactIdConverter::PbkEngineL() const |
|
140 { |
|
141 if (!iPbkEngine) |
|
142 { |
|
143 iPbkEngine = CPbkContactEngine::NewL(); |
|
144 } |
|
145 return iPbkEngine; |
|
146 } |
|
147 |
|
148 } // namespace VPbkCntModel |
|
149 |
|
150 // End of File |