|
1 /* |
|
2 * Copyright (c) 2005 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: Operation for importing landmarks to a database. |
|
15 * |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 #ifndef CPOSLMLOCALIMPORTOP_H |
|
21 #define CPOSLMLOCALIMPORTOP_H |
|
22 |
|
23 // INCLUDES |
|
24 #include <EPos_CPosLandmarkDatabase.h> |
|
25 #include "EPos_CPosLmLocalModifyOp.h" |
|
26 #include "EPos_MPosLmLocalInternalProxyOpClient.h" |
|
27 #include "EPos_MPosLmLocalInternalOpExecutor.h" |
|
28 |
|
29 // CONSTANTS |
|
30 |
|
31 // FORWARD DECLARATIONS |
|
32 class CPosLmLocalDatabase; |
|
33 class CPosLmGlobalCategoryReader; |
|
34 class CPosLandmarkParser; |
|
35 class CPosLandmarkCategory; |
|
36 class CPosLmDiskUtilities; |
|
37 class CPosLmLocalInternalOpActive; |
|
38 |
|
39 // CLASS DECLARATION |
|
40 |
|
41 /** |
|
42 * Operation for importing landmarks to a database. |
|
43 * |
|
44 * @lib eposlmlocalaccess.lib |
|
45 */ |
|
46 NONSHARABLE_CLASS(CPosLmLocalImportOp) : public CPosLmLocalModifyOp, |
|
47 public MPosLmLocalInternalOpExecutor, |
|
48 public MPosLmLocalInternalProxyOpClient |
|
49 { |
|
50 |
|
51 public: // Constructors and destructor |
|
52 |
|
53 /** |
|
54 * Two-phased constructor. |
|
55 * |
|
56 * @param aDb A landmark database. |
|
57 * @param aLandmarkParser A landmark parser object. |
|
58 * @param aTransferOptions A bitmap representing the options for the |
|
59 * import operation. The bitmap values are defined by |
|
60 * @ref _TTransferOptions. |
|
61 * @param aDiskUtils Disk utilities. |
|
62 * @return A new instance of this class. |
|
63 */ |
|
64 static CPosLmLocalImportOp* NewL( |
|
65 /* IN */ CPosLmLocalDatabase& aDb, |
|
66 /* IN */ CPosLandmarkParser& aLandmarkParser, |
|
67 /* IN */ CPosLandmarkDatabase::TTransferOptions aTransferOptions, |
|
68 /* IN */ CPosLmDiskUtilities& aDiskUtils |
|
69 ); |
|
70 |
|
71 /** |
|
72 * Two-phased constructor. |
|
73 * |
|
74 * @param aDb A landmark database. |
|
75 * @param aLandmarkParser A landmark parser object. |
|
76 * @param aLandmarksSelection The indexes for the landmarks that should |
|
77 * be imported. |
|
78 * @param aTransferOptions A bitmap representing the options for the |
|
79 * import operation. The bitmap values are defined by |
|
80 * @ref _TTransferOptions. |
|
81 * @param aDiskUtils Disk utilities. |
|
82 * @return A new instance of this class. |
|
83 */ |
|
84 static CPosLmLocalImportOp* NewL( |
|
85 /* IN */ CPosLmLocalDatabase& aDb, |
|
86 /* IN */ CPosLandmarkParser& aLandmarkParser, |
|
87 /* IN */ const RArray<TUint>& aLandmarksSelection, |
|
88 /* IN */ CPosLandmarkDatabase::TTransferOptions aTransferOptions, |
|
89 /* IN */ CPosLmDiskUtilities& aDiskUtils |
|
90 ); |
|
91 |
|
92 /** |
|
93 * Destructor. |
|
94 */ |
|
95 virtual ~CPosLmLocalImportOp(); |
|
96 |
|
97 public: // New functions |
|
98 |
|
99 /** |
|
100 * Copies all imported landmark item ids into array aLmItemIds. |
|
101 * |
|
102 * @param aLmItemIds Array of imported landmark item ids. |
|
103 */ |
|
104 void ImportedLandmarkItemIdsL( |
|
105 /* IN/OUT */ RArray<TPosLmItemId>& aLmItemIds |
|
106 ); |
|
107 |
|
108 public: // Functions from base classes |
|
109 |
|
110 /** |
|
111 * From CPosLmLocalModifyOp. |
|
112 * |
|
113 * @param aProgress The current progress. |
|
114 */ |
|
115 void DoNextStepPreL( |
|
116 /* OUT */ TReal32& aProgress |
|
117 ); |
|
118 |
|
119 /** |
|
120 * From CPosLmLocalModifyOp. |
|
121 * |
|
122 * @param aProgress The current progress. |
|
123 * @return ETrue if a begin transaction should be made. EFalse otherwise. |
|
124 */ |
|
125 TBool DoNextStepPostL( |
|
126 /* OUT */ TReal32& aProgress |
|
127 ); |
|
128 |
|
129 /** |
|
130 * From CPosLmLocalModifyOp. |
|
131 * |
|
132 * @return Current step size. |
|
133 */ |
|
134 TReal32 Step(); |
|
135 |
|
136 /** |
|
137 * From CPosLmLocalModifyOp. |
|
138 * |
|
139 * @param aResourceId A resource id. |
|
140 * @param aNoOfSubOperations A number of sub operations. |
|
141 */ |
|
142 void CheckResourceValue( |
|
143 /* IN */ TInt aResourceId, |
|
144 /* IN */ TInt aNoOfSubOperations |
|
145 ); |
|
146 |
|
147 /** |
|
148 * From CPosLmLocalOperation; |
|
149 * |
|
150 * @param aError An error code generated by NextStepL. |
|
151 */ |
|
152 void HandleError( |
|
153 /* IN/OUT */ TInt& aError |
|
154 ); |
|
155 |
|
156 /** |
|
157 * From MPosLmLocalInternalOpExecutor. |
|
158 * |
|
159 * @param aStatus Internal operation complete status. |
|
160 * @param aProgress Internal operation progress. |
|
161 * @param aStatus Client request status. |
|
162 * @param aProgress Client progress. |
|
163 */ |
|
164 void InternalOpCompleted( |
|
165 /* IN */ TInt aStatus, |
|
166 /* IN */ TReal32 aProgress, |
|
167 /* IN/OUT */ TRequestStatus& aClientStatus, |
|
168 /* IN/OUT */ TReal32& aClientProgress |
|
169 ); |
|
170 |
|
171 /** |
|
172 * From MPosLmLocalInternalProxyOpClient. |
|
173 * |
|
174 * @param aStatus A request status. |
|
175 * @param aProgress The operation progress |
|
176 */ |
|
177 void DoNextStep( |
|
178 /* OUT */ TRequestStatus& aStatus, |
|
179 /* OUT */ TReal32& aProgress |
|
180 ); |
|
181 |
|
182 /** |
|
183 * From MPosLmLocalInternalProxyOpClient. |
|
184 */ |
|
185 void DoExecuteL(); |
|
186 |
|
187 private: |
|
188 |
|
189 /** |
|
190 * C++ default constructor. |
|
191 * @param aDb A landmark db. |
|
192 * @param aLandmarkParser A landmark parser. |
|
193 * @param aTransferOptions A transfer options. |
|
194 * @param aDiskUtils Disk utils. |
|
195 */ |
|
196 CPosLmLocalImportOp( |
|
197 /* IN */ CPosLmLocalDatabase& aDb, |
|
198 /* IN */ CPosLandmarkParser& aLandmarkParser, |
|
199 /* IN */ CPosLandmarkDatabase::TTransferOptions aTransferOptions, |
|
200 /* IN */ CPosLmDiskUtilities& aDiskUtils |
|
201 ); |
|
202 |
|
203 /** |
|
204 * By default Symbian 2nd phase constructor is private. |
|
205 */ |
|
206 void ConstructL(); |
|
207 |
|
208 /** |
|
209 * By default Symbian 2nd phase constructor is private. |
|
210 * |
|
211 * @param aLandmarkIdArray Array of selected landmark index to import. |
|
212 */ |
|
213 void ConstructL( |
|
214 /* IN */ const RArray<TUint>& aLandmarkIdArray |
|
215 ); |
|
216 |
|
217 /** |
|
218 * Parse landmark using landmark parser. |
|
219 */ |
|
220 void ParseLandmarkL(); |
|
221 |
|
222 /** |
|
223 * Get parsed landmark from landmark parser. |
|
224 */ |
|
225 void GetParsedLandmarkL(); |
|
226 |
|
227 /** |
|
228 * Import landmark to database. |
|
229 */ |
|
230 void ImportLandmarkL(); |
|
231 |
|
232 /** |
|
233 * Import landmark categories to database. |
|
234 */ |
|
235 void ImportLmCategoriesL(); |
|
236 |
|
237 /** |
|
238 * Add local category to landmark database. |
|
239 * |
|
240 * @return @p ETrue if category is added to database or |
|
241 * item id is set for category. If category doesn't exist in |
|
242 * database and import operation should supress creation of |
|
243 * categories @p EFalse is returned. |
|
244 */ |
|
245 TBool AddLocalCategoryL( |
|
246 /* IN */ CPosLandmarkCategory& aLmCat, |
|
247 /* IN */ TPosLmItemId& aLmItemId |
|
248 ); |
|
249 |
|
250 /** |
|
251 * Update the progress of the import operation. |
|
252 * |
|
253 * @param aProgress Progress of the import operation. |
|
254 */ |
|
255 void UpdateProgress( |
|
256 /* IN/OUT */ TReal32& aProgress |
|
257 ); |
|
258 |
|
259 /** |
|
260 * Check whether import operation should import selected |
|
261 * landmarks or not. |
|
262 * |
|
263 * @return TBool ETrue if import operation should import |
|
264 * selected landmarks. |
|
265 */ |
|
266 TBool LandmarkSelection(); |
|
267 |
|
268 /** |
|
269 * Check whether current landmark is a selected one or not. |
|
270 * |
|
271 * @return ETrue if it is a selected landmark, otherwise EFalse. |
|
272 */ |
|
273 TBool IsSelectedLandmark(); |
|
274 |
|
275 /** |
|
276 * Checks whether all selected landmarks are imported or not. |
|
277 * |
|
278 * @return ETrue if all selected landmarks is imported, |
|
279 * otherwise EFalse. |
|
280 */ |
|
281 TBool IsSelectedLandmarksImported(); |
|
282 |
|
283 /** |
|
284 * Function is returning global category name from resource file. |
|
285 * |
|
286 * @param aCategory Category to check in resource file. |
|
287 * @return NULL if aCategory is not found in resource file, otherwise |
|
288 * category name from resource file is returned. |
|
289 */ |
|
290 HBufC* GlobalCategoryNameInResourceL( |
|
291 /* IN/OUT */ CPosLandmarkCategory* aCategory |
|
292 ); |
|
293 |
|
294 /** |
|
295 * Rollback if in transaction and generate an event. |
|
296 * @param aProgress Current progress. |
|
297 */ |
|
298 void RollbackAndGenerateEventIfNeeded( |
|
299 /* IN */ TReal32 aProgress |
|
300 ); |
|
301 |
|
302 /** |
|
303 * Generates an event. |
|
304 * @param aProgress Current progress. |
|
305 * @return KErrNone if successful. Otherwise any system-wide error code. |
|
306 */ |
|
307 TInt GenerateEventIfNeeded( |
|
308 /* IN */ TReal32 aProgress |
|
309 ); |
|
310 |
|
311 /** |
|
312 * Adds a category if enough disk space is available. |
|
313 * @param aCategory A category. |
|
314 * |
|
315 * @return @p ETrue if category is added to database or |
|
316 * item id is set for category. If category doesn't exist in |
|
317 * database and import operation should supress creation of |
|
318 * categories @p EFalse is returned. |
|
319 */ |
|
320 TBool AddCategoryL( |
|
321 /* IN */ CPosLandmarkCategory& aCategory |
|
322 ); |
|
323 |
|
324 void PrepareNextParsingStep(); |
|
325 |
|
326 TBool IsInParsingState(); |
|
327 |
|
328 // Prohibit copy constructor if not deriving from CBase. |
|
329 CPosLmLocalImportOp(const CPosLmLocalImportOp&); |
|
330 // Prohibit assigment operator if not deriving from CBase. |
|
331 CPosLmLocalImportOp& operator=(const CPosLmLocalImportOp&); |
|
332 |
|
333 private: // Data |
|
334 |
|
335 // States of the import operation. |
|
336 enum TImportState |
|
337 { |
|
338 EImportParseLm, |
|
339 EImportAddLmCatToDb, |
|
340 EImportAddLmToDb, |
|
341 EReadyImportingLm |
|
342 }; |
|
343 |
|
344 // Landmark parser (no ownership). |
|
345 CPosLandmarkParser* iLandmarkParser; |
|
346 |
|
347 // Transfer options |
|
348 CPosLandmarkDatabase::TTransferOptions iTransferOptions; |
|
349 |
|
350 // Landmark global category reader. |
|
351 CPosLmGlobalCategoryReader* iReader; |
|
352 |
|
353 // State of the import operation. |
|
354 TImportState iImportState; |
|
355 |
|
356 // Latest status of the parser operation |
|
357 TInt iParserOpStatus; |
|
358 |
|
359 // Old progress of the parser operation |
|
360 TReal32 iOldParserProgress; |
|
361 |
|
362 // Current progress of the parser operation |
|
363 TReal32 iParserProgress; |
|
364 |
|
365 // Current landmark parsed from parser |
|
366 CPosLandmark* iCurrentLm; |
|
367 |
|
368 // The current category handled in the id array. |
|
369 TInt iCurrentCategory; |
|
370 |
|
371 // Current landmark category ids for parsed landmark |
|
372 RArray<TPosLmItemId> iCurrentCategoryIds; |
|
373 |
|
374 // Current parser landmark index |
|
375 TUint iCurrentLmIndex; |
|
376 |
|
377 // Item list with landmarks to import. |
|
378 RArray<TPosLmItemId> iSelectedLmIds; |
|
379 |
|
380 // Position of next selected landmark id in iSelectedLmIds. |
|
381 TInt iSelectedLmIdPos; |
|
382 |
|
383 // Item list with imported landmarks. |
|
384 RArray<TPosLmItemId> iImportedLmIds; |
|
385 |
|
386 // Number of categories added |
|
387 TInt iNrOfCategoriesAdded; |
|
388 |
|
389 // Number of categories updated |
|
390 TInt iNrOfCategoriesUpdated; |
|
391 |
|
392 // Item id of last changed category id |
|
393 TPosLmItemId iLastChangedCategoryId; |
|
394 |
|
395 // Last reported progress for this operation |
|
396 TReal32 iLastReportedProgress; |
|
397 |
|
398 // Current progress |
|
399 TReal32 iCurrentProgress; |
|
400 |
|
401 // Disk utilities (no ownership) |
|
402 CPosLmDiskUtilities* iDiskUtils; |
|
403 |
|
404 // Active object running the internal operation asynchronously |
|
405 CPosLmLocalInternalOpActive* iInternalOpActive; |
|
406 |
|
407 }; |
|
408 |
|
409 #endif // CPOSLMLOCALIMPORTOP_H |
|
410 |
|
411 // End of File |