|
1 /* |
|
2 * Copyright (c) 2006-2006 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: VirtualPhonebook support for importing VCard messages |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #ifndef C_VCARDVPBUTIL_H |
|
21 #define C_VCARDVPBUTIL_H |
|
22 |
|
23 #include <e32base.h> |
|
24 #include <s32file.h> // for RFile |
|
25 |
|
26 //Phonebook2 API includes |
|
27 |
|
28 #include <MVPbkSingleContactOperationObserver.h> |
|
29 #include <MVPbkContactStoreListObserver.h> |
|
30 #include <MVPbkBatchOperationObserver.h> |
|
31 |
|
32 #include "vcardbiocontrol.hrh" |
|
33 |
|
34 // FORWARD DECLARATIONS |
|
35 class CVPbkVCardEng; |
|
36 class CVPbkContactManager; |
|
37 class MVPbkStoreContact; |
|
38 class CPbk2StoreConfiguration; |
|
39 class MVPbkContactStoreList; |
|
40 class RFileReadStream; |
|
41 class MVPbkBaseContactField; |
|
42 class MVPbkFieldType; |
|
43 class CVPbkContactStoreUriArray; |
|
44 |
|
45 NONSHARABLE_CLASS(CVCardVpbUtil): |
|
46 public CBase, |
|
47 public MVPbkContactStoreListObserver, |
|
48 public MVPbkSingleContactOperationObserver, |
|
49 public MVPbkBatchOperationObserver |
|
50 { |
|
51 |
|
52 public: |
|
53 |
|
54 //construction and destruction |
|
55 |
|
56 static CVCardVpbUtil* NewL(); |
|
57 |
|
58 // Destructor |
|
59 ~CVCardVpbUtil(); |
|
60 |
|
61 |
|
62 // public API |
|
63 |
|
64 /** |
|
65 * Imports the VCard to both the phone store (for display) and |
|
66 * Default store (for storing) |
|
67 * |
|
68 * @since S60 3.1 |
|
69 * @param TVCardBCBusinessCardType aVCardType |
|
70 * The type of imported vcard |
|
71 * @param aFileHandle The filehandle for the VCard file |
|
72 * @return void |
|
73 */ |
|
74 void ImportVCardL( TVCardBCBusinessCardType aVCardType, RFile aFileHandle ); |
|
75 |
|
76 /** |
|
77 * Commits the VCard to store |
|
78 * |
|
79 * @since S60 3.1 |
|
80 * @return ETrue if contact was stored, EFalse if not |
|
81 */ |
|
82 TBool CommitVCardToStoreL(); |
|
83 |
|
84 /** |
|
85 * Returns the imported contact data from the |
|
86 * Phone default store |
|
87 * |
|
88 * @since S60 3.1 |
|
89 * @return const MVPbkStoreContact contact item |
|
90 * Ownership is not transferred |
|
91 */ |
|
92 MVPbkStoreContact* ContactData() const; |
|
93 |
|
94 /** |
|
95 * Check for contact item fields if they are empty |
|
96 * @return ETrue for empty contact item, |
|
97 * EFalse for not empty |
|
98 */ |
|
99 TBool IsContactItemEmpty(); |
|
100 |
|
101 /** |
|
102 |
|
103 // from base class MVPbkContactStoreListObserver |
|
104 |
|
105 /** |
|
106 * Called when the opening process is complete, ie. all stores have been reported |
|
107 * either failed or successful open. |
|
108 */ |
|
109 void OpenComplete(); |
|
110 |
|
111 /** |
|
112 * Called when a contact store is ready to use. |
|
113 */ |
|
114 void StoreReady( MVPbkContactStore& aContactStore ); |
|
115 |
|
116 /** |
|
117 * Called when a contact store becomes unavailable. |
|
118 * Client may inspect the reason of the unavailability and decide whether or not |
|
119 * it will keep the store opened (ie. listen to the store events). |
|
120 * @param aContactStore The store that became unavailable. |
|
121 * @param aReason The reason why the store is unavailable. |
|
122 * This is one of the system wide error codes. |
|
123 */ |
|
124 void StoreUnavailable( MVPbkContactStore& aContactStore, TInt aReason ); |
|
125 |
|
126 /** |
|
127 * Called when changes occur in the contact store. |
|
128 * @see TVPbkContactStoreEvent |
|
129 * @param aContactStore The store the event occurred in. |
|
130 * @param aStoreEvent Event that has occured. |
|
131 */ |
|
132 void HandleStoreEventL( |
|
133 MVPbkContactStore& aContactStore, |
|
134 TVPbkContactStoreEvent aStoreEvent ); |
|
135 |
|
136 |
|
137 // from base class MVPbkSingleContactOperationObserver |
|
138 |
|
139 /** |
|
140 * Called when operation is completed. |
|
141 * |
|
142 * @param aOperation the completed operation. |
|
143 * @param aContact the contact returned by the operation. |
|
144 * Client must take the ownership immediately. |
|
145 * |
|
146 * !!! NOTICE !!! |
|
147 * If you use Cleanupstack for MVPbkStoreContact |
|
148 * Use MVPbkStoreContact::PushL or |
|
149 * CleanupDeletePushL from e32base.h. |
|
150 * (Do Not Use CleanupStack::PushL(TAny*) because |
|
151 * then the virtual destructor of the M-class |
|
152 * won't be called when the object is deleted). |
|
153 */ |
|
154 void VPbkSingleContactOperationComplete( |
|
155 MVPbkContactOperationBase& aOperation, |
|
156 MVPbkStoreContact* aContact ); |
|
157 |
|
158 /** |
|
159 * Called if the operation fails. |
|
160 * |
|
161 * @param aOperation the failed operation. |
|
162 * @param aError error code of the failure. |
|
163 */ |
|
164 void VPbkSingleContactOperationFailed( |
|
165 MVPbkContactOperationBase& aOperation, |
|
166 TInt aError ); |
|
167 |
|
168 |
|
169 // from base class MVPbkBatchOperationObserver |
|
170 |
|
171 void StepComplete( MVPbkContactOperationBase& aOperation, |
|
172 TInt aStepSize ); |
|
173 |
|
174 TBool StepFailed( |
|
175 MVPbkContactOperationBase& aOperation, |
|
176 TInt aStepSize, TInt aError ); |
|
177 |
|
178 void OperationComplete( MVPbkContactOperationBase& aOperation ); |
|
179 |
|
180 /** |
|
181 * Returns formatted contents of aField. |
|
182 * @param aField the field to format |
|
183 * @return formatted content of the field. |
|
184 */ |
|
185 TPtrC FormatFieldContentL(const MVPbkBaseContactField& aField); |
|
186 |
|
187 private: |
|
188 |
|
189 // private construction |
|
190 |
|
191 /** |
|
192 * The constructor. |
|
193 */ |
|
194 CVCardVpbUtil(); |
|
195 |
|
196 /// Second phase constructor. |
|
197 void ConstructL(); |
|
198 |
|
199 |
|
200 // private API |
|
201 |
|
202 /** |
|
203 * Checking whether the default contact store |
|
204 * supports all imported fields |
|
205 * |
|
206 * @return ETrue if all the fields are supported |
|
207 * EFalse if some fields are not supported |
|
208 */ |
|
209 TBool DefaultStoreSupportsAllFieldsL(); |
|
210 |
|
211 /** |
|
212 * Implementation to import the contact data |
|
213 * to phone internal contact database |
|
214 * |
|
215 * @param aStream The stream from which data is imported |
|
216 */ |
|
217 void VCardToPhoneStoreL( RFileReadStream& aStream ); |
|
218 |
|
219 /** |
|
220 * Implementation to import the contact data |
|
221 * to phone default contact database |
|
222 * this can be eg. SIM store |
|
223 * |
|
224 ** @param iStream The stream from which data is imported |
|
225 */ |
|
226 void VCardToDefaultStoreL( RFileReadStream& aStream ); |
|
227 |
|
228 /** |
|
229 * Function to start the Active Scheduler |
|
230 * and to trigger a leave if asynchronius |
|
231 * operation returned with a error code |
|
232 */ |
|
233 void StartSchedulerAndDecideToLeaveL(); |
|
234 |
|
235 /** |
|
236 * Checking of the field type. |
|
237 * @param aFieldType The field to be checked |
|
238 * @param aResourceId The resource id that it is checked against |
|
239 * @return TBool Field type matching status |
|
240 */ |
|
241 TBool IsFieldTypeL( |
|
242 const MVPbkFieldType& aFieldType, |
|
243 TInt aResourceId) const; |
|
244 |
|
245 TPtr ReallocBufferL(TInt aNewSize); |
|
246 |
|
247 /** |
|
248 * Panic notifying functionality |
|
249 */ |
|
250 static void Panic( TInt aReason ); |
|
251 TBool StoreFullL(); |
|
252 void ShowNoteL( TInt aResourceId, const TDesC& aString ); |
|
253 |
|
254 private: // data |
|
255 |
|
256 /** |
|
257 * last error code from asynchronous operations |
|
258 */ |
|
259 TInt iLastError; |
|
260 |
|
261 /** |
|
262 * Current status to take action to observed event |
|
263 */ |
|
264 TBool iRespondToObserverEvent; |
|
265 |
|
266 /** |
|
267 * The type of imported VCard |
|
268 */ |
|
269 TVCardBCBusinessCardType iVCardType; |
|
270 |
|
271 /** |
|
272 * VirtualPhonebook contact manager API |
|
273 * Own. |
|
274 */ |
|
275 CVPbkContactManager* iContactManager; |
|
276 |
|
277 /** |
|
278 * VirtualPhonebook VCard Importing engine |
|
279 * Own. |
|
280 */ |
|
281 CVPbkVCardEng* iVCardEngine; |
|
282 |
|
283 /** |
|
284 * Default contact store for saved contacts |
|
285 * Own. |
|
286 */ |
|
287 MVPbkContactStore* iDefaultContactStore; |
|
288 |
|
289 /** |
|
290 * Shown contact store ie. phone memory Agenda database |
|
291 * This is for display purposes and is not used to save data |
|
292 * Own. |
|
293 */ |
|
294 MVPbkContactStore* iShowContactStore; |
|
295 |
|
296 /** |
|
297 * Array of imported contacts to show on screen |
|
298 * Own. |
|
299 */ |
|
300 RPointerArray<MVPbkStoreContact> iContactsToShow; |
|
301 |
|
302 /** |
|
303 * Array of imported contacts to store on device |
|
304 * Own. |
|
305 */ |
|
306 RPointerArray<MVPbkStoreContact> iContactsToStore; |
|
307 |
|
308 /** |
|
309 * List of all opened contact stores. Note that they might not be succesfully opened. |
|
310 * Own. |
|
311 */ |
|
312 MVPbkContactStoreList* iStoreList; |
|
313 |
|
314 /** |
|
315 * Buffer for handling line strings |
|
316 * Own. |
|
317 */ |
|
318 HBufC* iBuffer; |
|
319 |
|
320 /** |
|
321 * List of all succesfully opened contact stores. |
|
322 * Own. |
|
323 */ |
|
324 CVPbkContactStoreUriArray* iAvailableUris; |
|
325 }; |
|
326 #endif //C_VCARDVPBUTIL_H |