|
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: This file contains methods for aiding the process of saving |
|
15 * : landmarks which are received via messaging |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 // INCLUDE FILES |
|
26 #include <e32std.h> |
|
27 #include <eikenv.h> |
|
28 #include <StringLoader.h> |
|
29 #include <AknQueryDialog.h> |
|
30 #include <AknWaitDialog.h> |
|
31 #include <aknnotewrappers.h> |
|
32 #include <EPos_CPosLmCategoryManager.h> |
|
33 #include <lmkui.rsg> |
|
34 #include "CLmkParser.h" |
|
35 #include "CLmkLandMarkCategoriesName.h" |
|
36 #include "CLmkSaveLandmarkUtils.h" |
|
37 #include "CLmkPkgFindNewCatOp.h" |
|
38 |
|
39 // ============================ MEMBER FUNCTIONS =============================== |
|
40 |
|
41 // ----------------------------------------------------------------------------- |
|
42 // CLmkSaveLandmarkUtils::CLmkSaveLandmarkUtils |
|
43 // C++ default constructor can NOT contain any code, that |
|
44 // might leave. |
|
45 // ----------------------------------------------------------------------------- |
|
46 // |
|
47 CLmkSaveLandmarkUtils::CLmkSaveLandmarkUtils( |
|
48 CPosLandmarkDatabase& aDb, |
|
49 CLmkParser& aParser) |
|
50 : iDb( aDb ), |
|
51 iParser( aParser ) |
|
52 { |
|
53 } |
|
54 |
|
55 // ----------------------------------------------------------------------------- |
|
56 // CLmkSaveLandmarkUtils::ConstructL |
|
57 // Symbian 2nd phase constructor can leave. |
|
58 // ----------------------------------------------------------------------------- |
|
59 // |
|
60 void CLmkSaveLandmarkUtils::ConstructL() |
|
61 { |
|
62 iEnv = CEikonEnv::Static(); |
|
63 } |
|
64 |
|
65 // ----------------------------------------------------------------------------- |
|
66 // CLmkSaveLandmarkUtils::NewL |
|
67 // Two-phased constructor. |
|
68 // ----------------------------------------------------------------------------- |
|
69 // |
|
70 EXPORT_C CLmkSaveLandmarkUtils* CLmkSaveLandmarkUtils::NewL( |
|
71 CPosLandmarkDatabase& aDb, |
|
72 CLmkParser& aParser) |
|
73 { |
|
74 CLmkSaveLandmarkUtils* self = |
|
75 new( ELeave )CLmkSaveLandmarkUtils( aDb, aParser ); |
|
76 |
|
77 CleanupStack::PushL( self ); |
|
78 self->ConstructL(); |
|
79 CleanupStack::Pop(); |
|
80 return self; |
|
81 } |
|
82 |
|
83 // ---------------------------------------------------- |
|
84 // CLmkSaveLandmarkUtils::~CLmkSaveLandmarkUtils |
|
85 // ---------------------------------------------------- |
|
86 // |
|
87 CLmkSaveLandmarkUtils::~CLmkSaveLandmarkUtils() |
|
88 { |
|
89 CancelSearchNewCat(); |
|
90 } |
|
91 |
|
92 // ---------------------------------------------------- |
|
93 // CLmkSaveLandmarkUtils::~CheckForNewCategoriesL |
|
94 // ---------------------------------------------------- |
|
95 // |
|
96 TInt CLmkSaveLandmarkUtils::CheckForNewCategoriesL(RArray<TUint> & aSelectedIndices, |
|
97 TDes& aNewFoundCategory, |
|
98 RArray<TCategoryName>& aNewcategories) |
|
99 { |
|
100 TInt TotalCount = aSelectedIndices.Count(); |
|
101 RArray<TCategoryName> categories; |
|
102 CleanupClosePushL(categories); |
|
103 |
|
104 for(TInt cnt = 0; cnt < TotalCount; cnt++ ) |
|
105 { |
|
106 CLmkLandMarkCategoriesName* categoryNames = iParser.CategoryNameLC(aSelectedIndices[cnt]); |
|
107 categories.Reset(); |
|
108 categoryNames->GetCategoryNames(categories); |
|
109 TInt totCategories = categories.Count(); |
|
110 for(TInt catCount = 0; catCount < totCategories; catCount++ ) |
|
111 { |
|
112 CheckCategoryInDatabaseL(aNewcategories,categories[catCount]); |
|
113 } |
|
114 |
|
115 CleanupStack::PopAndDestroy(); //categoryNames |
|
116 } |
|
117 |
|
118 TInt newCategoriesFound = aNewcategories.Count(); |
|
119 if ( newCategoriesFound == 1 ) |
|
120 { |
|
121 aNewFoundCategory.Copy(aNewcategories[0]); |
|
122 } |
|
123 CleanupStack::PopAndDestroy(); // categories |
|
124 return newCategoriesFound; |
|
125 } |
|
126 |
|
127 // ---------------------------------------------------- |
|
128 // CLmkSaveLandmarkUtils::CheckCategoryInDatabase |
|
129 // This routine check wheather category associated with landmark is already exist in database or not. |
|
130 // ---------------------------------------------------- |
|
131 void CLmkSaveLandmarkUtils::CheckCategoryInDatabaseL(RArray<TCategoryName>& aNewcategories,const TDesC& aCategoryTobeAdded) |
|
132 { |
|
133 TInt Total = aNewcategories.Count(); |
|
134 for(TInt cnt = 0; cnt < Total; cnt++ ) |
|
135 { |
|
136 if (aNewcategories[cnt] == aCategoryTobeAdded) |
|
137 return; |
|
138 } |
|
139 |
|
140 CPosLmCategoryManager* categoryManager = CPosLmCategoryManager::NewL( iDb ); |
|
141 CleanupStack::PushL( categoryManager ); |
|
142 |
|
143 if ( categoryManager->GetCategoryL(aCategoryTobeAdded) == KPosLmNullItemId) |
|
144 { |
|
145 aNewcategories.Append(aCategoryTobeAdded); |
|
146 } |
|
147 CleanupStack::PopAndDestroy(); //categoryManager |
|
148 } |
|
149 |
|
150 // ---------------------------------------------------- |
|
151 // CLmkSaveLandmarkUtils::CategoryAddConfirmationQueryL |
|
152 // This routine ask confirmation about adding landmark , with OR without category |
|
153 // ---------------------------------------------------- |
|
154 TInt CLmkSaveLandmarkUtils::CategoryAddConfirmationQueryL( TInt aAmount,const TDesC& aNewCategoryName ) |
|
155 { |
|
156 HBufC* noteText = NULL; |
|
157 |
|
158 if ( aAmount > 1) |
|
159 { |
|
160 noteText = StringLoader::LoadLC( R_LMK_ADD_CATEGORIES,aAmount, iEnv ); |
|
161 } |
|
162 else if ( aAmount == 1) |
|
163 { |
|
164 noteText = StringLoader::LoadLC( R_LMK_ADD_CATEGORY,aNewCategoryName, iEnv ); |
|
165 } |
|
166 else |
|
167 { |
|
168 return 1; |
|
169 } |
|
170 |
|
171 CAknQueryDialog* query = |
|
172 new( ELeave ) CAknQueryDialog( *noteText ); |
|
173 TInt ret = query->ExecuteLD( R_LMK_QUERY ); // noteText |
|
174 |
|
175 CleanupStack::PopAndDestroy(noteText); //noteText |
|
176 return ret; |
|
177 } |
|
178 |
|
179 // ---------------------------------------------------- |
|
180 // CLmkSaveLandmarkUtils::LmsSavedConfirmationNoteL |
|
181 // This method takes care of importing the selected Landmarks |
|
182 // ---------------------------------------------------- |
|
183 void CLmkSaveLandmarkUtils::LmsSavedConfirmationNoteL(RArray<TUint> & aImportIndexes, |
|
184 TInt aEditedItemIndex) |
|
185 |
|
186 { |
|
187 HBufC* noteText = NULL; |
|
188 |
|
189 // Display Landmark numbers in the Note |
|
190 CPosLandmark* landmark = iParser.LandmarkLC(aEditedItemIndex); |
|
191 TPtrC lmName; |
|
192 User::LeaveIfError(landmark->GetLandmarkName(lmName)); |
|
193 TUint lmCount = aImportIndexes.Count(); |
|
194 |
|
195 if (lmCount > 1) |
|
196 { |
|
197 noteText = StringLoader::LoadLC( R_LMK_NOTE_LMS_SAVED,lmCount, iEnv ); |
|
198 } |
|
199 else if (lmCount == 1) |
|
200 { |
|
201 noteText = StringLoader::LoadLC( R_LMK_NOTE_LANDMARK_SAVED, lmName, iEnv ); |
|
202 } |
|
203 else |
|
204 { |
|
205 return; |
|
206 } |
|
207 |
|
208 CAknConfirmationNote* note = new (ELeave) CAknConfirmationNote( ETrue ); |
|
209 TInt retVal = note->ExecuteLD( *noteText ); |
|
210 CleanupStack::PopAndDestroy(2);// noteText |
|
211 } |
|
212 |
|
213 // ---------------------------------------------------- |
|
214 // CLmkSaveLandmarkUtils::CheckForNewCategories2L |
|
215 // ---------------------------------------------------- |
|
216 // |
|
217 TInt CLmkSaveLandmarkUtils::CheckForNewCategories2L( |
|
218 TDes& aNewFoundCategory, |
|
219 RArray<TCategoryName>& aNewcategories) |
|
220 { |
|
221 TInt TotalCount = iParser.NumOfParsedLandmarks(); |
|
222 RArray<TCategoryName> categories; |
|
223 CleanupClosePushL(categories); |
|
224 |
|
225 for(TInt cnt = 0; cnt < TotalCount; cnt++ ) |
|
226 { |
|
227 CLmkLandMarkCategoriesName* categoryNames = iParser.CategoryNameLC(cnt); |
|
228 categories.Reset(); |
|
229 categoryNames->GetCategoryNames(categories); |
|
230 TInt totCategories = categories.Count(); |
|
231 for(TInt catCount = 0; catCount < totCategories; catCount++ ) |
|
232 { |
|
233 CheckCategoryInDatabaseL(aNewcategories,categories[catCount]); |
|
234 } |
|
235 |
|
236 CleanupStack::PopAndDestroy(); //categoryNames |
|
237 } |
|
238 |
|
239 TInt newCategoriesFound = aNewcategories.Count(); |
|
240 if ( newCategoriesFound == 1 ) |
|
241 { |
|
242 aNewFoundCategory.Copy(aNewcategories[0]); |
|
243 } |
|
244 CleanupStack::PopAndDestroy(); // categories |
|
245 return newCategoriesFound; |
|
246 } |
|
247 |
|
248 // ---------------------------------------------------- |
|
249 // CLmkSaveLandmarkUtils::StartSearchNewCatL |
|
250 // ---------------------------------------------------- |
|
251 // |
|
252 void CLmkSaveLandmarkUtils::StartSearchNewCatL( |
|
253 TInt& aNoOfNewCategories, |
|
254 RArray<TCategoryName>& aNewCategories, |
|
255 TCategoryName& aNewCategoryFound) |
|
256 { |
|
257 CPosLmOperation* operation = CLmkPkgFindNewCatOp::NewL |
|
258 (aNoOfNewCategories, |
|
259 aNewCategories, |
|
260 aNewCategoryFound, |
|
261 this); |
|
262 CleanupStack::PushL( operation ); |
|
263 iAOOperation = |
|
264 CLmkAOOperation::NewL( operation, |
|
265 *this, |
|
266 ENewPkgCategory, |
|
267 ETrue ); |
|
268 CleanupStack::Pop( operation ); // ownership transferred |
|
269 |
|
270 iAOOperation->StartOperation(); |
|
271 } |
|
272 // ---------------------------------------------------- |
|
273 // CLmkSaveLandmarkUtils::CancelSearchNewCat |
|
274 // ---------------------------------------------------- |
|
275 // |
|
276 void CLmkSaveLandmarkUtils::CancelSearchNewCat() |
|
277 { |
|
278 if (iAOOperation) |
|
279 { |
|
280 delete iAOOperation; |
|
281 iAOOperation = NULL; |
|
282 } |
|
283 } |
|
284 // ---------------------------------------------------- |
|
285 // CLmkSaveLandmarkUtils::HandleOperationL |
|
286 // ---------------------------------------------------- |
|
287 // |
|
288 void CLmkSaveLandmarkUtils::HandleOperationL( |
|
289 TOperationTypes aType, |
|
290 TReal32 aProgress, |
|
291 TInt aStatus ) |
|
292 { |
|
293 if ( iObserver ) |
|
294 { |
|
295 iObserver->HandleOperationL(aType,aProgress,aStatus); |
|
296 } |
|
297 } |
|
298 // ---------------------------------------------------- |
|
299 // CLmkSaveLandmarkUtils::SetObserver |
|
300 // ---------------------------------------------------- |
|
301 // |
|
302 void CLmkSaveLandmarkUtils::SetObserver(MLmkAOOperationObserver* aObserver) |
|
303 { |
|
304 iObserver = aObserver; |
|
305 } |
|
306 // End of File |