|
1 /* |
|
2 * Copyright (c) 2002-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 #include <eposlmasyncops.rsg> |
|
21 #include <EPos_LandmarksErrors.h> |
|
22 #include <EPos_CPosLandmarkParser.h> |
|
23 #include <EPos_PosLmImplExtension.h> |
|
24 #include <epos_poslmlandmarkhandler.h> |
|
25 #include <epos_poslmcategoryhandler.h> |
|
26 #include <epos_cposlmglobalcategoryreader.h> |
|
27 #include <epos_cposlmdiskutilities.h> |
|
28 |
|
29 #include "epos_cposlmlocaldatabase.h" |
|
30 #include "epos_cposlmlocaldbaccess.h" |
|
31 #include "EPos_LocalLandmarks.h" |
|
32 #include "EPos_RPosLmLocalAccessSubsession.h" |
|
33 #include "EPos_CPosLmLocalInternalOpActive.h" |
|
34 #include "EPos_CPosLmLocalImportOp.h" |
|
35 |
|
36 // ============================ MEMBER FUNCTIONS =============================== |
|
37 |
|
38 // ----------------------------------------------------------------------------- |
|
39 // ----------------------------------------------------------------------------- |
|
40 // |
|
41 CPosLmLocalImportOp::CPosLmLocalImportOp( |
|
42 CPosLmLocalDatabase& aDb, |
|
43 CPosLandmarkParser& aLandmarkParser, |
|
44 CPosLandmarkDatabase::TTransferOptions aTransferOptions, |
|
45 CPosLmDiskUtilities& aDiskUtils) |
|
46 : CPosLmLocalModifyOp(aDb), |
|
47 iLandmarkParser(&aLandmarkParser), |
|
48 iTransferOptions(aTransferOptions), |
|
49 iImportState(EImportParseLm), |
|
50 iParserOpStatus(KPosLmOperationNotComplete), |
|
51 iDiskUtils(&aDiskUtils) |
|
52 { |
|
53 iUsesServerData = ETrue; // updates lm name index |
|
54 } |
|
55 |
|
56 // ----------------------------------------------------------------------------- |
|
57 // ----------------------------------------------------------------------------- |
|
58 // |
|
59 void CPosLmLocalImportOp::ConstructL() |
|
60 { |
|
61 CPosLandmarkDatabase::TTransferOptions invalidOptions = |
|
62 iTransferOptions & |
|
63 ~CPosLandmarkDatabase::EIncludeCategories & |
|
64 ~CPosLandmarkDatabase::EIncludeGlobalCategoryNames & |
|
65 ~CPosLandmarkDatabase::ESupressCategoryCreation; |
|
66 |
|
67 __ASSERT_ALWAYS(invalidOptions == CPosLandmarkDatabase::EDefaultOptions, |
|
68 Panic(KPosLandmarksClientPanic, EPosLmInvalidArgument)); |
|
69 |
|
70 BaseConstructL(); |
|
71 |
|
72 ReadInfoFromResourceFileL(R_POS_LM_LOCAL_IMPORT_LMS_OP); |
|
73 |
|
74 if (iTransferOptions & CPosLandmarkDatabase::EIncludeCategories) |
|
75 { |
|
76 iReader = CPosLmGlobalCategoryReader::NewL(); |
|
77 } |
|
78 |
|
79 CPosLmOperation* parserOp = iLandmarkParser->ParseContentL(EFalse); |
|
80 CleanupStack::PushL(parserOp); |
|
81 |
|
82 iInternalOpActive = CPosLmLocalInternalOpActive::NewL(*this, parserOp); |
|
83 CleanupStack::Pop(parserOp); // ownership transferred |
|
84 } |
|
85 |
|
86 // ----------------------------------------------------------------------------- |
|
87 // ----------------------------------------------------------------------------- |
|
88 // |
|
89 void CPosLmLocalImportOp::ConstructL( |
|
90 const RArray<TUint>& aLandmarksSelection) |
|
91 { |
|
92 if (aLandmarksSelection.Count() == 0) |
|
93 { |
|
94 User::Leave(KErrArgument); |
|
95 } |
|
96 |
|
97 for (TInt i = 0; i < aLandmarksSelection.Count(); i++) |
|
98 { |
|
99 User::LeaveIfError(iSelectedLmIds.Append(aLandmarksSelection[i])); |
|
100 } |
|
101 iSelectedLmIds.SortUnsigned(); |
|
102 |
|
103 ConstructL(); |
|
104 } |
|
105 |
|
106 // ----------------------------------------------------------------------------- |
|
107 // ----------------------------------------------------------------------------- |
|
108 // |
|
109 CPosLmLocalImportOp* CPosLmLocalImportOp::NewL( |
|
110 CPosLmLocalDatabase& aDb, |
|
111 CPosLandmarkParser& aLandmarkParser, |
|
112 CPosLandmarkDatabase::TTransferOptions aTransferOptions, |
|
113 CPosLmDiskUtilities& aDiskUtils) |
|
114 { |
|
115 CPosLmLocalImportOp* self = new (ELeave) |
|
116 CPosLmLocalImportOp(aDb, aLandmarkParser, aTransferOptions, aDiskUtils); |
|
117 CleanupStack::PushL(self); |
|
118 self->ConstructL(); |
|
119 CleanupStack::Pop(self); |
|
120 return self; |
|
121 } |
|
122 |
|
123 // ----------------------------------------------------------------------------- |
|
124 // ----------------------------------------------------------------------------- |
|
125 // |
|
126 CPosLmLocalImportOp* CPosLmLocalImportOp::NewL( |
|
127 CPosLmLocalDatabase& aDb, |
|
128 CPosLandmarkParser& aLandmarkParser, |
|
129 const RArray<TUint>& aLandmarksSelection, |
|
130 CPosLandmarkDatabase::TTransferOptions aTransferOptions, |
|
131 CPosLmDiskUtilities& aDiskUtils) |
|
132 { |
|
133 CPosLmLocalImportOp* self = new (ELeave) |
|
134 CPosLmLocalImportOp(aDb, aLandmarkParser, aTransferOptions, aDiskUtils); |
|
135 CleanupStack::PushL(self); |
|
136 self->ConstructL(aLandmarksSelection); |
|
137 CleanupStack::Pop(self); |
|
138 return self; |
|
139 } |
|
140 |
|
141 // ----------------------------------------------------------------------------- |
|
142 // ----------------------------------------------------------------------------- |
|
143 // |
|
144 CPosLmLocalImportOp::~CPosLmLocalImportOp() |
|
145 { |
|
146 RollbackAndGenerateEventIfNeeded(Progress()); |
|
147 |
|
148 delete iReader; |
|
149 |
|
150 delete iCurrentLm; |
|
151 iCurrentCategoryIds.Close(); |
|
152 |
|
153 iSelectedLmIds.Close(); |
|
154 iImportedLmIds.Close(); |
|
155 |
|
156 delete iInternalOpActive; |
|
157 } |
|
158 |
|
159 // ----------------------------------------------------------------------------- |
|
160 // ----------------------------------------------------------------------------- |
|
161 // |
|
162 void CPosLmLocalImportOp::ImportedLandmarkItemIdsL( |
|
163 RArray<TPosLmItemId>& aLmItemIds) |
|
164 { |
|
165 for (TInt i=0; i<iImportedLmIds.Count(); i++) |
|
166 { |
|
167 User::LeaveIfError(aLmItemIds.Append(iImportedLmIds[i])); |
|
168 } |
|
169 } |
|
170 |
|
171 // ----------------------------------------------------------------------------- |
|
172 // ----------------------------------------------------------------------------- |
|
173 // |
|
174 void CPosLmLocalImportOp::DoNextStepPreL( |
|
175 TReal32& aProgress) |
|
176 { |
|
177 if (iImportState == EImportParseLm) |
|
178 { |
|
179 ParseLandmarkL(); |
|
180 |
|
181 // If it is a selected landmark we need to import it to db |
|
182 if (IsSelectedLandmark()) |
|
183 { |
|
184 GetParsedLandmarkL(); |
|
185 if (iTransferOptions & CPosLandmarkDatabase::EIncludeCategories && |
|
186 iCurrentCategoryIds.Count() != 0) |
|
187 { |
|
188 iImportState = EImportAddLmCatToDb; |
|
189 } |
|
190 else |
|
191 { |
|
192 iImportState = EImportAddLmToDb; |
|
193 } |
|
194 } |
|
195 } |
|
196 else if (iImportState == EImportAddLmCatToDb) |
|
197 { |
|
198 ImportLmCategoriesL(); |
|
199 // Ready importing categories ? |
|
200 if (iCurrentCategory == iCurrentCategoryIds.Count()) |
|
201 { |
|
202 iImportState = EImportAddLmToDb; |
|
203 } |
|
204 } |
|
205 else |
|
206 { |
|
207 // iImportState == EImportAddLmToDb |
|
208 ImportLandmarkL(); |
|
209 // Ready importing landmark |
|
210 iImportState = EImportParseLm; |
|
211 } |
|
212 |
|
213 // Update progress |
|
214 UpdateProgress(aProgress); |
|
215 } |
|
216 |
|
217 // ----------------------------------------------------------------------------- |
|
218 // ----------------------------------------------------------------------------- |
|
219 // |
|
220 TBool CPosLmLocalImportOp::DoNextStepPostL( |
|
221 TReal32& aProgress) |
|
222 { |
|
223 // Check if we are ready parsing or not |
|
224 if ((iParserOpStatus == KErrNone && iImportState == EImportParseLm) || |
|
225 (IsSelectedLandmarksImported())) |
|
226 { |
|
227 __ASSERT_ALWAYS(!LandmarkSelection() || |
|
228 IsSelectedLandmarksImported() || |
|
229 (LandmarkSelection() && |
|
230 iSelectedLmIds.Count() > iSelectedLmIdPos && |
|
231 iCurrentLmIndex > iSelectedLmIds[iSelectedLmIdPos]), |
|
232 Panic(KPosLandmarksClientPanic, EPosInvalidIndex)); |
|
233 |
|
234 User::LeaveIfError(GenerateEventIfNeeded(aProgress)); |
|
235 iStatusFlag = KErrNone; |
|
236 return EFalse; |
|
237 } |
|
238 |
|
239 return ETrue; |
|
240 } |
|
241 |
|
242 // ----------------------------------------------------------------------------- |
|
243 // ----------------------------------------------------------------------------- |
|
244 // |
|
245 TReal32 CPosLmLocalImportOp::Step() |
|
246 { |
|
247 return iCurrentProgress - iLastReportedProgress; |
|
248 } |
|
249 |
|
250 // ----------------------------------------------------------------------------- |
|
251 // ----------------------------------------------------------------------------- |
|
252 // |
|
253 void CPosLmLocalImportOp::CheckResourceValue( |
|
254 TInt /*aResourceId*/, |
|
255 TInt aNoOfSubOperations) |
|
256 { |
|
257 __ASSERT_ALWAYS(aNoOfSubOperations > 0, Panic(KPosLandmarksClientPanic, |
|
258 EPosInvalidValueSpecifiedInResourceFile)); |
|
259 } |
|
260 |
|
261 // ----------------------------------------------------------------------------- |
|
262 // ----------------------------------------------------------------------------- |
|
263 // |
|
264 void CPosLmLocalImportOp::HandleError( |
|
265 TInt& aError) |
|
266 { |
|
267 iStatusFlag = aError; |
|
268 RollbackAndGenerateEventIfNeeded(Progress()); |
|
269 } |
|
270 |
|
271 // ----------------------------------------------------------------------------- |
|
272 // ----------------------------------------------------------------------------- |
|
273 // |
|
274 void CPosLmLocalImportOp::InternalOpCompleted( |
|
275 TInt aStatus, |
|
276 TReal32 aProgress, |
|
277 TRequestStatus& aClientStatus, |
|
278 TReal32& aClientProgress) |
|
279 { |
|
280 iParserOpStatus = aStatus; |
|
281 iParserProgress = aProgress; |
|
282 |
|
283 if (aStatus == KErrNone || aStatus == KPosLmOperationNotComplete) |
|
284 { |
|
285 // Internal operation did not fail. Even if parser operation completed |
|
286 // with KErrNone, this operation is not done; the landmark must be |
|
287 // imported as well. |
|
288 |
|
289 TRAP(aStatus, DoNextStepPreL(aClientProgress)); |
|
290 |
|
291 if (aStatus == KErrNone) |
|
292 { |
|
293 // Status must be changed to KPosLmOperationNotComplete. Otherwise, |
|
294 // the client thinks that the operation is done. |
|
295 aStatus = KPosLmOperationNotComplete; |
|
296 } |
|
297 else |
|
298 { |
|
299 RollbackAndGenerateEventIfNeeded(aProgress); |
|
300 } |
|
301 } |
|
302 else |
|
303 { |
|
304 RollbackAndGenerateEventIfNeeded(aProgress); |
|
305 } |
|
306 |
|
307 TRequestStatus* clientStatus = &aClientStatus; |
|
308 User::RequestComplete(clientStatus, aStatus); |
|
309 } |
|
310 |
|
311 // ----------------------------------------------------------------------------- |
|
312 // ----------------------------------------------------------------------------- |
|
313 // |
|
314 void CPosLmLocalImportOp::DoNextStep( |
|
315 TRequestStatus& aStatus, |
|
316 TReal32& aProgress) |
|
317 { |
|
318 if (IsInParsingState()) |
|
319 { |
|
320 // Performs next step on parser operation with active object. |
|
321 aStatus = KRequestPending; |
|
322 PrepareNextParsingStep(); |
|
323 iInternalOpActive->DoNext(aStatus, aProgress); |
|
324 } |
|
325 else |
|
326 { |
|
327 // Import landmark or categories. May also be in compacting state. |
|
328 NextStep(aStatus, aProgress); |
|
329 } |
|
330 } |
|
331 |
|
332 // ----------------------------------------------------------------------------- |
|
333 // ----------------------------------------------------------------------------- |
|
334 // |
|
335 void CPosLmLocalImportOp::DoExecuteL() |
|
336 { |
|
337 TRequestStatus status(KPosLmOperationNotComplete); |
|
338 TRequestStatus statusInternalOp; |
|
339 TReal32 progress; |
|
340 |
|
341 do |
|
342 { |
|
343 if (IsInParsingState()) |
|
344 { |
|
345 // Performs next step on parser operation without active object. |
|
346 // Using an active object would hang the thread when calling |
|
347 // User::WaitForRequest. |
|
348 PrepareNextParsingStep(); |
|
349 iInternalOpActive->InternalOpNextStep(statusInternalOp, progress); |
|
350 User::WaitForRequest(statusInternalOp); |
|
351 User::LeaveIfError(statusInternalOp.Int()); |
|
352 |
|
353 // To finish a parsing next step, this function must be called. |
|
354 // The function would have been called by the active object if |
|
355 // running asynchronously (DoNextStep). |
|
356 InternalOpCompleted(statusInternalOp.Int(), progress, status, |
|
357 progress); |
|
358 } |
|
359 else |
|
360 { |
|
361 // Import landmark or categories. May also be in compacting state. |
|
362 NextStep(status, progress); |
|
363 } |
|
364 |
|
365 User::WaitForRequest(status); |
|
366 User::LeaveIfError(status.Int()); |
|
367 } while (status.Int() == KPosLmOperationNotComplete); |
|
368 } |
|
369 |
|
370 // ----------------------------------------------------------------------------- |
|
371 // ----------------------------------------------------------------------------- |
|
372 // |
|
373 void CPosLmLocalImportOp::ParseLandmarkL() |
|
374 { |
|
375 // A landmark has previously been parsed when this function is called. |
|
376 |
|
377 // Error during parsing of landmarks |
|
378 if (iParserOpStatus != KErrNone && |
|
379 iParserOpStatus != KPosLmOperationNotComplete) |
|
380 { |
|
381 User::Leave(iParserOpStatus); |
|
382 } |
|
383 |
|
384 // Reset landmark and landmark category |
|
385 delete iCurrentLm; |
|
386 iCurrentLm = NULL; |
|
387 iCurrentCategoryIds.Reset(); |
|
388 } |
|
389 |
|
390 // ----------------------------------------------------------------------------- |
|
391 // ----------------------------------------------------------------------------- |
|
392 // |
|
393 void CPosLmLocalImportOp::GetParsedLandmarkL() |
|
394 { |
|
395 // Get landmark and landmark category ids |
|
396 iCurrentLm = iLandmarkParser->LandmarkLC(); |
|
397 CleanupStack::Pop(); |
|
398 iCurrentLm->GetCategoriesL(iCurrentCategoryIds); |
|
399 |
|
400 // Reset category ids in landmark |
|
401 iCurrentLm->RemoveLandmarkAttributes(CPosLandmark::ECategoryInfo); |
|
402 } |
|
403 |
|
404 // ----------------------------------------------------------------------------- |
|
405 // ----------------------------------------------------------------------------- |
|
406 // |
|
407 void CPosLmLocalImportOp::ImportLandmarkL() |
|
408 { |
|
409 iDiskUtils->DiskSpaceBelowCriticalLevelL( |
|
410 iDiskUtils->EstimatedDiskSizeOfLmOperation( |
|
411 CPosLmDiskUtilities::EAddLandmarkOp, |
|
412 *iCurrentLm ), iDb->DatabaseDrive() ); |
|
413 |
|
414 // Add landmark to db |
|
415 PosLmLandmarkHandler::AddLandmarkL( *iDb->DatabaseAccess(), *iCurrentLm ); |
|
416 iDb->NameIndex().AddL( *iCurrentLm ); |
|
417 |
|
418 // Add lm item id to array of imported lm item ids |
|
419 User::LeaveIfError( iImportedLmIds.Append( iCurrentLm->LandmarkId() ) ); |
|
420 |
|
421 // Imported a selected landmark, so point to next id in array |
|
422 iSelectedLmIdPos++; |
|
423 |
|
424 iCurrentCategory = 0; |
|
425 } |
|
426 |
|
427 // ----------------------------------------------------------------------------- |
|
428 // ----------------------------------------------------------------------------- |
|
429 // |
|
430 void CPosLmLocalImportOp::ImportLmCategoriesL() |
|
431 { |
|
432 for (TInt i = 0; |
|
433 i < iNoOfSubOperations && |
|
434 iCurrentCategory < iCurrentCategoryIds.Count(); |
|
435 i++) |
|
436 { |
|
437 // Get next gategory |
|
438 CPosLandmarkCategory* lmcat = |
|
439 iLandmarkParser->LandmarkCategoryLC( |
|
440 iCurrentCategoryIds[iCurrentCategory++]); |
|
441 TPosLmItemId dbItemId; |
|
442 TBool lmCatInDb = ETrue; |
|
443 |
|
444 // Is global category ? |
|
445 if (lmcat->GlobalCategory() != KPosLmNullGlobalCategory) |
|
446 { |
|
447 TBool dummyBool; |
|
448 // Is global category in db ? |
|
449 if (PosLmCategoryHandler::IsGlobalCategoryExistingL( |
|
450 *iDb->DatabaseAccess(), lmcat->GlobalCategory(), |
|
451 dbItemId, dummyBool)) |
|
452 { |
|
453 // Set category id for global category |
|
454 PosLmImplExtension::SetCategoryIdL(*lmcat, dbItemId); |
|
455 |
|
456 // Import global category names ? |
|
457 if (iTransferOptions & |
|
458 CPosLandmarkDatabase::EIncludeGlobalCategoryNames) |
|
459 { |
|
460 // Update global category name in db |
|
461 TPtrC categoryName; |
|
462 TInt err = lmcat->GetCategoryName(categoryName); |
|
463 if (err == KErrNone) |
|
464 { |
|
465 PosLmCategoryHandler::UpdateGlobalCategoryNameL( |
|
466 *iDb->DatabaseAccess(), *lmcat); |
|
467 iLastChangedCategoryId = lmcat->CategoryId(); |
|
468 iNrOfCategoriesUpdated++; |
|
469 } |
|
470 } |
|
471 } |
|
472 else |
|
473 { |
|
474 // Is global category in resource ? |
|
475 HBufC* categoryNameFromResource = |
|
476 GlobalCategoryNameInResourceL(lmcat); |
|
477 CleanupStack::PushL(categoryNameFromResource); |
|
478 if (categoryNameFromResource) |
|
479 { |
|
480 // Import global category names ? |
|
481 if (iTransferOptions & |
|
482 CPosLandmarkDatabase::EIncludeGlobalCategoryNames) |
|
483 { |
|
484 // Add global category to db with imported name |
|
485 lmCatInDb = AddCategoryL(*lmcat); |
|
486 } |
|
487 else |
|
488 { |
|
489 // Add global category to db with name from resource |
|
490 lmcat->SetCategoryNameL( |
|
491 categoryNameFromResource->Des()); |
|
492 lmCatInDb = AddCategoryL(*lmcat); |
|
493 } |
|
494 } |
|
495 else |
|
496 { |
|
497 // Global category neither in db or resource file |
|
498 lmCatInDb = AddLocalCategoryL(*lmcat, dbItemId); |
|
499 } |
|
500 |
|
501 CleanupStack::PopAndDestroy(categoryNameFromResource); |
|
502 } |
|
503 } |
|
504 else |
|
505 { |
|
506 // Not a global category |
|
507 lmCatInDb = AddLocalCategoryL(*lmcat, dbItemId); |
|
508 } |
|
509 |
|
510 if (lmCatInDb) |
|
511 { |
|
512 // Add category id to landmark |
|
513 iCurrentLm->AddCategoryL(lmcat->CategoryId()); |
|
514 } |
|
515 |
|
516 CleanupStack::PopAndDestroy(lmcat); |
|
517 } |
|
518 } |
|
519 |
|
520 // ----------------------------------------------------------------------------- |
|
521 // ----------------------------------------------------------------------------- |
|
522 // |
|
523 TBool CPosLmLocalImportOp::AddLocalCategoryL( |
|
524 CPosLandmarkCategory& aLmCat, |
|
525 TPosLmItemId& aLmItemId) |
|
526 { |
|
527 // Set category id for category |
|
528 PosLmImplExtension::SetGlobalCategory(aLmCat, KPosLmNullGlobalCategory); |
|
529 |
|
530 // Category name doesn't exists in db ? |
|
531 if (PosLmCategoryHandler::VerifyCategoryNameNotExistsL( |
|
532 *iDb->DatabaseAccess(), aLmCat, PosLmCategoryHandler::EAddCheck, |
|
533 aLmItemId) == KErrNone) |
|
534 { |
|
535 // Add local category |
|
536 return AddCategoryL(aLmCat); |
|
537 } |
|
538 else |
|
539 { |
|
540 // Set category id for category |
|
541 PosLmImplExtension::SetCategoryIdL(aLmCat, aLmItemId); |
|
542 } |
|
543 |
|
544 return ETrue; |
|
545 } |
|
546 |
|
547 // ----------------------------------------------------------------------------- |
|
548 // ----------------------------------------------------------------------------- |
|
549 // |
|
550 void CPosLmLocalImportOp::UpdateProgress(TReal32& aProgress) |
|
551 { |
|
552 iLastReportedProgress = iCurrentProgress; |
|
553 |
|
554 // Set the progress for the operation |
|
555 TReal32 importStateProgress; |
|
556 // Three (3) step are taken per imported landmark for each NextStepL call |
|
557 TReal32 importStatePartProgress = |
|
558 (iParserProgress - iOldParserProgress) / 3; |
|
559 if (iImportState == EImportAddLmCatToDb) |
|
560 { |
|
561 TReal32 importLmCatPart = importStatePartProgress; |
|
562 // Add current lm cat index |
|
563 if (iCurrentCategoryIds.Count() > 0) |
|
564 { |
|
565 importStatePartProgress = |
|
566 (TReal32(1) / iCurrentCategoryIds.Count()) * |
|
567 importStatePartProgress; |
|
568 importLmCatPart = importStatePartProgress * |
|
569 (iCurrentCategory + 1); |
|
570 } |
|
571 aProgress = iOldParserProgress + importLmCatPart; |
|
572 } |
|
573 else if (iImportState == EImportAddLmToDb) |
|
574 { |
|
575 importStateProgress = importStatePartProgress; |
|
576 aProgress = iOldParserProgress + (2 * importStateProgress); |
|
577 } |
|
578 else |
|
579 { |
|
580 // iImportState == EImportParseLm |
|
581 aProgress = iParserProgress; |
|
582 } |
|
583 |
|
584 iCurrentProgress = aProgress; |
|
585 } |
|
586 |
|
587 // ----------------------------------------------------------------------------- |
|
588 // ----------------------------------------------------------------------------- |
|
589 // |
|
590 TBool CPosLmLocalImportOp::LandmarkSelection() |
|
591 { |
|
592 return (iSelectedLmIds.Count() > 0); |
|
593 } |
|
594 |
|
595 // ----------------------------------------------------------------------------- |
|
596 // ----------------------------------------------------------------------------- |
|
597 // |
|
598 TBool CPosLmLocalImportOp::IsSelectedLandmark() |
|
599 { |
|
600 if (!LandmarkSelection() || |
|
601 (LandmarkSelection() && |
|
602 iSelectedLmIds.Count() > iSelectedLmIdPos && |
|
603 iCurrentLmIndex == iSelectedLmIds[iSelectedLmIdPos])) |
|
604 { |
|
605 return ETrue; |
|
606 } |
|
607 |
|
608 return EFalse; |
|
609 } |
|
610 |
|
611 // ----------------------------------------------------------------------------- |
|
612 // ----------------------------------------------------------------------------- |
|
613 // |
|
614 TBool CPosLmLocalImportOp::IsSelectedLandmarksImported() |
|
615 { |
|
616 if (LandmarkSelection() && |
|
617 iSelectedLmIds.Count() == iSelectedLmIdPos) |
|
618 { |
|
619 return ETrue; |
|
620 } |
|
621 |
|
622 return EFalse; |
|
623 } |
|
624 |
|
625 // ----------------------------------------------------------------------------- |
|
626 // ----------------------------------------------------------------------------- |
|
627 // |
|
628 HBufC* CPosLmLocalImportOp::GlobalCategoryNameInResourceL( |
|
629 CPosLandmarkCategory* aCategory) |
|
630 { |
|
631 HBufC* name = NULL; |
|
632 TPosLmGlobalCategory globalCat = aCategory->GlobalCategory(); |
|
633 |
|
634 for (TInt i = 0; i < iReader->Count() && !name; i++) |
|
635 { |
|
636 CPosLandmarkCategory* readerCategory = iReader->GlobalCategoryLC(i); |
|
637 |
|
638 TPtrC catName; |
|
639 if (readerCategory->GlobalCategory() == globalCat && |
|
640 readerCategory->GetCategoryName(catName) == KErrNone) |
|
641 { |
|
642 name = catName.AllocL(); |
|
643 } |
|
644 |
|
645 CleanupStack::PopAndDestroy(readerCategory); |
|
646 } |
|
647 |
|
648 return name; |
|
649 } |
|
650 |
|
651 // ----------------------------------------------------------------------------- |
|
652 // ----------------------------------------------------------------------------- |
|
653 // |
|
654 void CPosLmLocalImportOp::RollbackAndGenerateEventIfNeeded( |
|
655 TReal32 aProgress) |
|
656 { |
|
657 RollbackIfNeeded(); |
|
658 |
|
659 GenerateEventIfNeeded(aProgress); |
|
660 |
|
661 // Reset flag: rollback and event generation should not be done twice. |
|
662 iStatusFlag = KErrNone; |
|
663 } |
|
664 |
|
665 // ----------------------------------------------------------------------------- |
|
666 // ----------------------------------------------------------------------------- |
|
667 // |
|
668 TInt CPosLmLocalImportOp::GenerateEventIfNeeded( |
|
669 TReal32 /*aProgress*/) |
|
670 { |
|
671 TInt status = KErrNone; |
|
672 if (iStatusFlag != KErrNone && iImportedLmIds.Count() > 0) |
|
673 { |
|
674 if (iImportedLmIds.Count() == 1) |
|
675 { |
|
676 status = iDb->RegisterEvent(EPosLmEventLandmarkCreated, |
|
677 iImportedLmIds[0]); |
|
678 if (status != KErrNone) |
|
679 { |
|
680 return status; |
|
681 } |
|
682 } |
|
683 if (iNrOfCategoriesAdded == 1 && iNrOfCategoriesUpdated <= 1) |
|
684 { |
|
685 status = iDb->RegisterEvent(EPosLmEventCategoryCreated, |
|
686 iLastChangedCategoryId); |
|
687 if (status != KErrNone) |
|
688 { |
|
689 return status; |
|
690 } |
|
691 } |
|
692 if (iNrOfCategoriesUpdated == 1 && iNrOfCategoriesAdded <= 1) |
|
693 { |
|
694 status = iDb->RegisterEvent(EPosLmEventCategoryUpdated, |
|
695 iLastChangedCategoryId); |
|
696 if (status != KErrNone) |
|
697 { |
|
698 return status; |
|
699 } |
|
700 } |
|
701 |
|
702 if (iImportedLmIds.Count() > 1 && |
|
703 (iNrOfCategoriesAdded > 1 || iNrOfCategoriesUpdated > 1)) |
|
704 { |
|
705 return iDb->RegisterEvent(EPosLmEventUnknownChanges); |
|
706 } |
|
707 else if (iImportedLmIds.Count() > 1) |
|
708 { |
|
709 return iDb->RegisterEvent(EPosLmEventLandmarkUnknownChanges); |
|
710 } |
|
711 else if (iNrOfCategoriesAdded > 1 || iNrOfCategoriesUpdated > 1) |
|
712 { |
|
713 return iDb->RegisterEvent(EPosLmEventCategoryUnknownChanges); |
|
714 } |
|
715 } |
|
716 return status; |
|
717 } |
|
718 |
|
719 // ----------------------------------------------------------------------------- |
|
720 // ----------------------------------------------------------------------------- |
|
721 // |
|
722 TBool CPosLmLocalImportOp::AddCategoryL( |
|
723 CPosLandmarkCategory& aCategory) |
|
724 { |
|
725 TBool toreturn = ETrue; |
|
726 |
|
727 if (iTransferOptions & |
|
728 CPosLandmarkDatabase::ESupressCategoryCreation) |
|
729 { |
|
730 toreturn = EFalse; |
|
731 } |
|
732 else |
|
733 { |
|
734 iDiskUtils->DiskSpaceBelowCriticalLevelL( |
|
735 iDiskUtils->EstimatedDiskSizeOfLmOperation( |
|
736 CPosLmDiskUtilities::EAddLmCategoryOp, aCategory), |
|
737 iDb->DatabaseDrive()); |
|
738 |
|
739 PosLmCategoryHandler::AddCategoryL(*iDb->DatabaseAccess(), aCategory); |
|
740 iLastChangedCategoryId = aCategory.CategoryId(); |
|
741 iNrOfCategoriesAdded++; |
|
742 } |
|
743 |
|
744 return toreturn; |
|
745 } |
|
746 |
|
747 // ----------------------------------------------------------------------------- |
|
748 // ----------------------------------------------------------------------------- |
|
749 // |
|
750 void CPosLmLocalImportOp::PrepareNextParsingStep() |
|
751 { |
|
752 iOldParserProgress = iParserProgress; |
|
753 iCurrentLmIndex = iLandmarkParser->NumOfParsedLandmarks(); |
|
754 } |
|
755 |
|
756 // ----------------------------------------------------------------------------- |
|
757 // ----------------------------------------------------------------------------- |
|
758 // |
|
759 TBool CPosLmLocalImportOp::IsInParsingState() |
|
760 { |
|
761 return (iImportState == EImportParseLm && !IsInCompactingState() && |
|
762 iParserOpStatus == KPosLmOperationNotComplete); |
|
763 } |
|
764 |