|
1 /* |
|
2 * Copyright (c) 2002 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: LandmarksUi Content File - |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "EPos_CPosLandmarkDatabase.h" |
|
21 #include <EPos_CPosLmCategoryManager.h> |
|
22 #include "CLmkParseAllWrapper.h" |
|
23 #include <EPos_CPosLandmarkParser.h> |
|
24 #include <EPos_CPosLmOperation.h> |
|
25 #include <EPos_CPosLandmark.h> |
|
26 #include <EPos_CPosLmOperation.h> |
|
27 #include "CLmkAOOperation.h" |
|
28 #include "CLmkLandMarkCategoriesName.h" |
|
29 #include <lmkerrors.h> |
|
30 |
|
31 #if defined(_DEBUG) |
|
32 // CONSTANTS |
|
33 /// Unnamed namespace for local definitions |
|
34 namespace { |
|
35 |
|
36 _LIT( KPanicMsg, "CLmkParseAllWrapper" ); |
|
37 |
|
38 void Panic( TPanicCode aReason ) |
|
39 { |
|
40 User::Panic( KPanicMsg, aReason ); |
|
41 } |
|
42 } // namespace |
|
43 #endif |
|
44 // ============================ MEMBER FUNCTIONS =============================== |
|
45 |
|
46 // ----------------------------------------------------------------------------- |
|
47 // CLmkParseAllWrapper::CLmkParseAllWrapper |
|
48 // C++ constructor can NOT contain any code, that |
|
49 // might leave. |
|
50 // ----------------------------------------------------------------------------- |
|
51 // |
|
52 CLmkParseAllWrapper::CLmkParseAllWrapper( |
|
53 CPosLandmarkParser& aParser, |
|
54 MLmkAOOperationObserver& aObserver, |
|
55 CPosLandmarkDatabase& aDb ) |
|
56 : iParser( aParser ), |
|
57 iObserver( aObserver), |
|
58 iDb(aDb) |
|
59 { |
|
60 } |
|
61 |
|
62 // ----------------------------------------------------------------------------- |
|
63 // CLmkParseAllWrapper::ConstructL |
|
64 // Symbian 2nd phase constructor can leave. |
|
65 // ----------------------------------------------------------------------------- |
|
66 // |
|
67 void CLmkParseAllWrapper::ConstructL() |
|
68 { |
|
69 } |
|
70 |
|
71 // ----------------------------------------------------------------------------- |
|
72 // CLmkParseAllWrapper::NewL |
|
73 // Two-phased constructor. |
|
74 // ----------------------------------------------------------------------------- |
|
75 // |
|
76 CLmkParseAllWrapper* CLmkParseAllWrapper::NewL( |
|
77 CPosLandmarkParser& aParser, |
|
78 MLmkAOOperationObserver& aObserver, |
|
79 CPosLandmarkDatabase& aDb ) |
|
80 { |
|
81 CLmkParseAllWrapper* self = |
|
82 new ( ELeave ) CLmkParseAllWrapper( aParser, aObserver, aDb ); |
|
83 |
|
84 CleanupStack::PushL( self ); |
|
85 self->ConstructL(); |
|
86 CleanupStack::Pop(); |
|
87 |
|
88 return self; |
|
89 } |
|
90 |
|
91 // ----------------------------------------------------------------------------- |
|
92 // CLmkParseAllWrapper::~CLmkParseAllWrapper |
|
93 // ----------------------------------------------------------------------------- |
|
94 // |
|
95 CLmkParseAllWrapper::~CLmkParseAllWrapper() |
|
96 { |
|
97 iLmkLandmarks.ResetAndDestroy(); |
|
98 iCategoriesNames.ResetAndDestroy(); |
|
99 delete iAOOperation; |
|
100 } |
|
101 |
|
102 // ----------------------------------------------------------------------------- |
|
103 // CLmkParseAllWrapper::ParseAllL |
|
104 // ----------------------------------------------------------------------------- |
|
105 // |
|
106 void CLmkParseAllWrapper::ParseAllL() |
|
107 { |
|
108 CPosLmOperation* operation = iParser.ParseContentL(); |
|
109 |
|
110 __ASSERT_DEBUG( !iAOOperation, Panic( KLmkPanicAlreadyActive ) ); |
|
111 |
|
112 iAOOperation = |
|
113 CLmkAOOperation::NewL( operation, |
|
114 *this, |
|
115 MLmkAOOperationObserver::EParse, |
|
116 ETrue ); |
|
117 iAOOperation->StartOperation(); |
|
118 } |
|
119 |
|
120 // ----------------------------------------------------------------------------- |
|
121 // CLmkParseAllWrapper::LandmarkLC |
|
122 // ----------------------------------------------------------------------------- |
|
123 // |
|
124 CPosLandmark* CLmkParseAllWrapper::LandmarkLC( TUint aLandmarkIndex ) |
|
125 { |
|
126 __ASSERT_DEBUG( aLandmarkIndex < TUint( iLmkLandmarks.Count() ), |
|
127 Panic( KLmkPanicInvalidIndex ) ); |
|
128 |
|
129 CLmkLandmark* lmkLandmarks = iLmkLandmarks[aLandmarkIndex]; |
|
130 CPosLandmark* landmark = lmkLandmarks->PosLandmark(); |
|
131 return CPosLandmark::NewLC( *landmark ); |
|
132 } |
|
133 |
|
134 // ----------------------------------------------------------------------------- |
|
135 // ----------------------------------------------------------------------------- |
|
136 // CLmkParseAllWrapper::CategoryNameLC |
|
137 // ----------------------------------------------------------------------------- |
|
138 // |
|
139 CLmkLandMarkCategoriesName* CLmkParseAllWrapper::CategoryNameLC( TUint aLandmarkIndex ) |
|
140 { |
|
141 __ASSERT_DEBUG( aLandmarkIndex < TUint( iCategoriesNames.Count() ), |
|
142 Panic( KLmkPanicInvalidIndex ) ); |
|
143 |
|
144 CLmkLandMarkCategoriesName* category = CLmkLandMarkCategoriesName::NewL( *iCategoriesNames[aLandmarkIndex]); |
|
145 CleanupStack::PushL(category); |
|
146 return category; |
|
147 } |
|
148 // CLmkParseAllWrapper::HandleOperationL |
|
149 // ----------------------------------------------------------------------------- |
|
150 // |
|
151 void CLmkParseAllWrapper::HandleOperationL( |
|
152 TOperationTypes aType, |
|
153 TReal32 aProgress, |
|
154 TInt aStatus ) |
|
155 { |
|
156 __ASSERT_DEBUG( aType == EParse, Panic( KLmkPanicUnknownOperation ) ); |
|
157 |
|
158 if ( aStatus == KPosLmOperationNotComplete || |
|
159 aStatus == KErrNone ) |
|
160 { |
|
161 CPosLandmark* landmark = iParser.LandmarkLC(); |
|
162 CLmkLandMarkCategoriesName* categoryNames = CLmkLandMarkCategoriesName::NewL(); |
|
163 CleanupStack::PushL(categoryNames); |
|
164 |
|
165 RArray<TPosLmItemId>* categoryIdArray = new(ELeave) RArray<TPosLmItemId>; |
|
166 CleanupClosePushL(*categoryIdArray); |
|
167 landmark->GetCategoriesL( *categoryIdArray ); |
|
168 HBufC* catName = HBufC::NewLC( KPosLmMaxCategoryNameLength ); |
|
169 TPtrC categoryPtr(catName->Des()); |
|
170 RPointerArray<CPosLandmarkCategory>* categories = new(ELeave) RPointerArray<CPosLandmarkCategory>; |
|
171 CleanupClosePushL(*categories); |
|
172 for( TInt cnt = 0; cnt < categoryIdArray->Count(); cnt++ ) |
|
173 { |
|
174 CPosLandmarkCategory *category = iParser.LandmarkCategoryLC((*categoryIdArray)[cnt]); |
|
175 category->GetCategoryName( categoryPtr ); |
|
176 /* |
|
177 * For predefined category, find the name from local database and |
|
178 * display the localised names to the user |
|
179 * If received predefined category does not exist in the local db, |
|
180 * then treat is as a newly received category |
|
181 */ |
|
182 if ( category->GlobalCategory() != KPosLmNullGlobalCategory ) // global category |
|
183 { |
|
184 // Get the name from db (localised name for predefined category is stored in db) |
|
185 HBufC* globCatName = NULL; |
|
186 CPosLmCategoryManager* categoryMgr = CPosLmCategoryManager::NewL( iDb ); |
|
187 CleanupStack::PushL( categoryMgr ); |
|
188 globCatName = categoryMgr->GlobalCategoryNameL( category->GlobalCategory() ); |
|
189 if ( globCatName == NULL ) |
|
190 { |
|
191 categoryNames->AddCategoryName( categoryPtr ); |
|
192 } |
|
193 else |
|
194 { |
|
195 CleanupStack::PushL( globCatName ); |
|
196 if ( globCatName->Length() > 0 ) |
|
197 { |
|
198 // Add it to categories to be shown |
|
199 categoryNames->AddCategoryName( *globCatName ); |
|
200 } |
|
201 CleanupStack::PopAndDestroy( globCatName ); |
|
202 } |
|
203 CleanupStack::PopAndDestroy( categoryMgr ); |
|
204 } |
|
205 else // User defined categories |
|
206 { |
|
207 categoryNames->AddCategoryName( categoryPtr ); |
|
208 } |
|
209 User::LeaveIfError(categories->Append(category)); |
|
210 CleanupStack::Pop(category); |
|
211 } |
|
212 //categoryIdArray->Close(); |
|
213 CLmkLandmark* lmkLandmarks = CLmkLandmark::NewL(landmark,*categories); |
|
214 CleanupStack::PushL(lmkLandmarks); |
|
215 User::LeaveIfError( iLmkLandmarks.Append( lmkLandmarks ) ); |
|
216 User::LeaveIfError( iCategoriesNames.Append( categoryNames ) ); //Owner ship transferred to array |
|
217 CleanupStack::Pop();//lmkLandmarks |
|
218 CleanupStack::Pop( );//categories |
|
219 categories->ResetAndDestroy(); |
|
220 delete categories; |
|
221 CleanupStack::PopAndDestroy( 2 ); //catName,categoryIdArray |
|
222 delete categoryIdArray; |
|
223 CleanupStack::Pop();//categoryNames |
|
224 CleanupStack::PopAndDestroy();//landmark |
|
225 |
|
226 } |
|
227 |
|
228 if ( aStatus != KPosLmOperationNotComplete ) |
|
229 { // parsing finished or error occured |
|
230 __ASSERT_DEBUG( iAOOperation, Panic( KLmkPanicNullMember ) ); |
|
231 |
|
232 delete iAOOperation; |
|
233 iAOOperation = NULL; |
|
234 |
|
235 iObserver.HandleOperationL( aType, aProgress, aStatus ); |
|
236 } |
|
237 } |
|
238 |
|
239 // ----------------------------------------------------------------------------- |
|
240 // ----------------------------------------------------------------------------- |
|
241 // CLmkParseAllWrapper::NumOfLandmarks |
|
242 // ----------------------------------------------------------------------------- |
|
243 // |
|
244 TInt CLmkParseAllWrapper::NumOfLandmarks() |
|
245 { |
|
246 return iLmkLandmarks.Count(); |
|
247 } |
|
248 |
|
249 // ----------------------------------------------------------------------------- |
|
250 // CLmkParseAllWrapper::LmkLandmarkLC |
|
251 // ----------------------------------------------------------------------------- |
|
252 // |
|
253 CLmkLandmark* CLmkParseAllWrapper::LmkLandmarkLC( TInt aLandmarkIndex ) |
|
254 { |
|
255 __ASSERT_DEBUG( aLandmarkIndex < TUint( iLmkLandmarks.Count() ), |
|
256 Panic( KLmkPanicInvalidIndex ) ); |
|
257 |
|
258 CLmkLandmark* landmark = iLmkLandmarks[aLandmarkIndex]; |
|
259 CLmkLandmark* lmkLandmarks = CLmkLandmark::NewL( *landmark ); |
|
260 CleanupStack::PushL(lmkLandmarks); |
|
261 return lmkLandmarks; |
|
262 } |
|
263 // End of File |