1 /* |
|
2 * Copyright (c) 2008 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: Converting CPbkContactItem to MVPbkStoreContact |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "emailtrace.h" |
|
19 #include <e32base.h> // CActiveSchedulerWait |
|
20 #include <coemain.h> |
|
21 #include <BCardEng.h> // Old VCard engine |
|
22 #include <s32mem.h> // Memory based streams |
|
23 #include <s32strm.h> // Stream |
|
24 #include <CPbkContactEngine.h> // Old phonebook contact engine |
|
25 #include <CVPbkContactStoreUriArray.h> |
|
26 #include <TVPbkContactStoreUriPtr.h> |
|
27 #include <CVPbkContactManager.h> |
|
28 #include <MVPbkContactStore.h> |
|
29 #include <MVPbkContactStoreList.h> |
|
30 #include <MVPbkContactStoreProperties.h> |
|
31 #include <MVPbkContactOperationBase.h> |
|
32 #include <CVPbkVCardEng.h> |
|
33 #include <MVPbkStoreContact.h> |
|
34 #include <CVPbkContactManager.h> |
|
35 #include <MVPbkContactStore.h> |
|
36 |
|
37 #include "cpbkxrclcontactconverter.h" |
|
38 |
|
39 const TInt KGranularitySize = 128; // "Granularity" of dynamic buffer |
|
40 |
|
41 // ======== MEMBER FUNCTIONS ======== |
|
42 |
|
43 // --------------------------------------------------------------------------- |
|
44 // CPbkxRclContactConverter::CPbkxRclContactConverter() |
|
45 // --------------------------------------------------------------------------- |
|
46 // |
|
47 CPbkxRclContactConverter::CPbkxRclContactConverter( |
|
48 CPbkContactEngine& aContactEngine, |
|
49 CVPbkContactManager& aContactManager, |
|
50 MVPbkContactStore& aContactStore ): |
|
51 iContactEngine( aContactEngine ), |
|
52 iContactManager( aContactManager ), |
|
53 iContactStore( aContactStore ) |
|
54 { |
|
55 FUNC_LOG; |
|
56 // No implementation required |
|
57 } |
|
58 |
|
59 // --------------------------------------------------------------------------- |
|
60 // Destructor |
|
61 // --------------------------------------------------------------------------- |
|
62 // |
|
63 CPbkxRclContactConverter::~CPbkxRclContactConverter() |
|
64 { |
|
65 FUNC_LOG; |
|
66 delete iCardEngine; |
|
67 delete iVPbkCardEngine; |
|
68 delete iWait; |
|
69 } |
|
70 |
|
71 // --------------------------------------------------------------------------- |
|
72 // CPbkxRclContactConverter* CPbkxRclContactConverter::NewLC() |
|
73 // --------------------------------------------------------------------------- |
|
74 // |
|
75 CPbkxRclContactConverter* CPbkxRclContactConverter::NewLC( |
|
76 CPbkContactEngine& aContactEngine, |
|
77 CVPbkContactManager& aContactManager, |
|
78 MVPbkContactStore& aContactStore ) |
|
79 { |
|
80 FUNC_LOG; |
|
81 CPbkxRclContactConverter* self = new (ELeave)CPbkxRclContactConverter( |
|
82 aContactEngine, aContactManager, aContactStore ); |
|
83 CleanupStack::PushL(self); |
|
84 self->ConstructL(); |
|
85 return self; |
|
86 } |
|
87 |
|
88 |
|
89 // --------------------------------------------------------------------------- |
|
90 // CPbkxRclContactConverter* CPbkxRclContactConverter::NewL() |
|
91 // --------------------------------------------------------------------------- |
|
92 // |
|
93 CPbkxRclContactConverter* CPbkxRclContactConverter::NewL( |
|
94 CPbkContactEngine& aContactEngine, |
|
95 CVPbkContactManager& aContactManager, |
|
96 MVPbkContactStore& aContactStore ) |
|
97 { |
|
98 FUNC_LOG; |
|
99 CPbkxRclContactConverter* self = CPbkxRclContactConverter::NewLC( |
|
100 aContactEngine, aContactManager, aContactStore ); |
|
101 CleanupStack::Pop(self); |
|
102 return self; |
|
103 } |
|
104 |
|
105 // --------------------------------------------------------------------------- |
|
106 // CPbkxRclContactConverter::ConstructL() |
|
107 // --------------------------------------------------------------------------- |
|
108 // |
|
109 void CPbkxRclContactConverter::ConstructL() |
|
110 { |
|
111 FUNC_LOG; |
|
112 // Crete Old VCard engine |
|
113 iCardEngine = CBCardEngine::NewL( &iContactEngine ); |
|
114 |
|
115 // New Virtual Phonebook VCard engine |
|
116 iVPbkCardEngine = CVPbkVCardEng::NewL( iContactManager ); |
|
117 |
|
118 iWait = new ( ELeave ) CActiveSchedulerWait(); |
|
119 } |
|
120 |
|
121 // --------------------------------------------------------------------------- |
|
122 // CPbkxRclContactConverter::ConvertContactL() |
|
123 // --------------------------------------------------------------------------- |
|
124 // |
|
125 void CPbkxRclContactConverter::ConvertContactL( |
|
126 CPbkContactItem& aContactItem, |
|
127 RFscStoreContactList& aConvertedContact ) |
|
128 { |
|
129 FUNC_LOG; |
|
130 CBufFlat* buf = CBufFlat::NewL(KGranularitySize); |
|
131 RBufWriteStream bufWriteStream; |
|
132 bufWriteStream.Open(*buf); |
|
133 CleanupClosePushL(bufWriteStream); |
|
134 |
|
135 // Export ContactCard (ContactItem ) to VCard. Sync operation. |
|
136 iCardEngine->ExportBusinessCardL( bufWriteStream, aContactItem ); |
|
137 |
|
138 CleanupStack::PopAndDestroy( &bufWriteStream ); |
|
139 |
|
140 // Create ReadStrem for VPbk VCard engine and associate it with received buf |
|
141 RBufReadStream bufReadStream; |
|
142 bufReadStream.Open(*buf); |
|
143 CleanupClosePushL(bufReadStream); |
|
144 |
|
145 // Pass new ReadStream for VPbk VCard engine and receive MVPbkStoreContact object |
|
146 MVPbkContactOperationBase* oper = iVPbkCardEngine->ImportVCardL( |
|
147 aConvertedContact, |
|
148 iContactStore, |
|
149 bufReadStream, |
|
150 *this ); |
|
151 CleanupDeletePushL( oper ); |
|
152 |
|
153 // Now wait until async ready |
|
154 if ( !(iWait->IsStarted()) ) |
|
155 { |
|
156 iWait->Start(); |
|
157 } |
|
158 |
|
159 CleanupStack::PopAndDestroy(2, &bufReadStream); // bufReadStream, oper |
|
160 delete buf; |
|
161 } |
|
162 // --------------------------------------------------------------------------- |
|
163 // CPbkxRclContactConverter::ConvertAndExportContactL() |
|
164 // --------------------------------------------------------------------------- |
|
165 // |
|
166 void CPbkxRclContactConverter::ConvertAndExportContactL( |
|
167 CPbkContactItem& aContactItem, |
|
168 RWriteStream& aStream ) |
|
169 { |
|
170 FUNC_LOG; |
|
171 RFscStoreContactList convertedContact; |
|
172 CleanupClosePushL( convertedContact ); |
|
173 |
|
174 ConvertContactL( aContactItem, convertedContact ); |
|
175 CleanupDeletePushL( convertedContact[0] ); |
|
176 |
|
177 MVPbkContactOperationBase* oper = iVPbkCardEngine->ExportVCardL( |
|
178 aStream, |
|
179 *convertedContact[0], |
|
180 *this); |
|
181 CleanupDeletePushL( oper ); |
|
182 // Now wait until async ready |
|
183 iWait->Start(); |
|
184 |
|
185 CleanupStack::PopAndDestroy(3, &convertedContact ); |
|
186 } |
|
187 |
|
188 // --------------------------------------------------------------------------- |
|
189 // CPbkxRclContactConverter::VPbkSingleContactOperationComplete() |
|
190 // --------------------------------------------------------------------------- |
|
191 // |
|
192 void CPbkxRclContactConverter::VPbkSingleContactOperationComplete( |
|
193 MVPbkContactOperationBase& /*aOperation*/, |
|
194 MVPbkStoreContact* /* aContact */ ) |
|
195 { |
|
196 FUNC_LOG; |
|
197 // The aContact in the call back is always NULL. |
|
198 iLastError = KErrNone; |
|
199 if (iWait->IsStarted()) |
|
200 { |
|
201 iWait->AsyncStop(); |
|
202 } |
|
203 } |
|
204 |
|
205 // --------------------------------------------------------------------------- |
|
206 // CPbkxRclContactConverter::VPbkSingleContactOperationFailed() |
|
207 // --------------------------------------------------------------------------- |
|
208 // |
|
209 void CPbkxRclContactConverter::VPbkSingleContactOperationFailed( |
|
210 MVPbkContactOperationBase& /*aOperation*/, TInt aError ) |
|
211 { |
|
212 FUNC_LOG; |
|
213 iLastError = aError; |
|
214 if (iWait->IsStarted()) |
|
215 { |
|
216 iWait->AsyncStop(); |
|
217 } |
|
218 } |
|
219 |
|