5
|
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 the License "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: CLandmarkIterable class implementation
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
#include <e32math.h>
|
|
20 |
#include <epos_cposlandmark.h>
|
|
21 |
#include <epos_cposlandmarkdatabase.h>
|
|
22 |
#include <epos_cposlmitemiterator.h>
|
|
23 |
#include <lbsposition.h>
|
|
24 |
#include "clandmarkiterable.h"
|
|
25 |
#include "landmarkliwparams.hrh"
|
|
26 |
|
|
27 |
// ============================ MEMBER FUNCTIONS ===============================
|
|
28 |
|
|
29 |
// -----------------------------------------------------------------------------
|
|
30 |
// CLandmarkIterable::NewL( CPosLmItemIterator* aIterator,
|
|
31 |
// TDesC& aDatabaseUri )
|
|
32 |
// Two-phased constructor.
|
|
33 |
// -----------------------------------------------------------------------------
|
|
34 |
//
|
|
35 |
CLandmarkIterable* CLandmarkIterable::NewL( CPosLmItemIterator* aIterator,
|
|
36 |
const TDesC& aDatabaseUri )
|
|
37 |
{
|
|
38 |
CLandmarkIterable* self = new (ELeave) CLandmarkIterable(aIterator);
|
|
39 |
CleanupStack::PushL(self);
|
|
40 |
self->ConstructL(aDatabaseUri);
|
|
41 |
CleanupStack::Pop(self);
|
|
42 |
return self;
|
|
43 |
}
|
|
44 |
|
|
45 |
// -----------------------------------------------------------------------------
|
|
46 |
// CLandmarkIterable::ConstructL( const TDesC & aDatabaseUri )
|
|
47 |
// Symbian 2nd phase constructor can leave.
|
|
48 |
// -----------------------------------------------------------------------------
|
|
49 |
//
|
|
50 |
void CLandmarkIterable::ConstructL( const TDesC& aDatabaseUri )
|
|
51 |
{
|
|
52 |
iDatabase = CPosLandmarkDatabase::OpenL(aDatabaseUri);
|
|
53 |
if ( iDatabase->IsInitializingNeeded() )
|
|
54 |
{
|
|
55 |
ExecuteAndDeleteLD(iDatabase->InitializeL());
|
|
56 |
}
|
|
57 |
}
|
|
58 |
|
|
59 |
// -----------------------------------------------------------------------------
|
|
60 |
// CLandmarkIterable::CLandmarkIterable( CPosLmItemIterator* aIterator )
|
|
61 |
// C++ default constructor can NOT contain any code, that might leave.
|
|
62 |
// -----------------------------------------------------------------------------
|
|
63 |
//
|
|
64 |
CLandmarkIterable::CLandmarkIterable( CPosLmItemIterator* aIterator )
|
|
65 |
: iIterator(aIterator)
|
|
66 |
{
|
|
67 |
}
|
|
68 |
|
|
69 |
// -----------------------------------------------------------------------------
|
|
70 |
// CLandmarkIterable::~CLandmarkIterable()
|
|
71 |
// Destructor.
|
|
72 |
// -----------------------------------------------------------------------------
|
|
73 |
//
|
|
74 |
CLandmarkIterable::~CLandmarkIterable()
|
|
75 |
{
|
|
76 |
delete iIterator;
|
|
77 |
delete iLandmark;
|
|
78 |
delete iDatabase;
|
|
79 |
delete iLandmarkId;
|
|
80 |
iCategoryIds.ResetAndDestroy();
|
|
81 |
iCategoryIds.Close();
|
|
82 |
ReleaseLandmarkResources();
|
|
83 |
}
|
|
84 |
|
|
85 |
// -----------------------------------------------------------------------------
|
|
86 |
// CLandmarkIterable::Reset()
|
|
87 |
// Resets the iterator. NextL has to be called to retrieve the first item.
|
|
88 |
// -----------------------------------------------------------------------------
|
|
89 |
//
|
|
90 |
void CLandmarkIterable::Reset()
|
|
91 |
{
|
|
92 |
iIterator->Reset();
|
|
93 |
}
|
|
94 |
|
|
95 |
// -----------------------------------------------------------------------------
|
|
96 |
// CLandmarkIterable::NextL( TLiwVariant& aEntry )
|
|
97 |
// retrievs the next item in the list.
|
|
98 |
// -----------------------------------------------------------------------------
|
|
99 |
//
|
|
100 |
TBool CLandmarkIterable::NextL( TLiwVariant& aEntry )
|
|
101 |
{
|
|
102 |
if ( iLandmark )
|
|
103 |
{
|
|
104 |
delete iLandmark;
|
|
105 |
iLandmark = NULL;
|
|
106 |
delete iLandmarkId;
|
|
107 |
iLandmarkId = NULL;
|
|
108 |
iCategoryIds.ResetAndDestroy();
|
|
109 |
}
|
|
110 |
|
|
111 |
TPosLmItemId landmarkId = iIterator->NextL();
|
|
112 |
if ( KPosLmNullItemId == landmarkId )
|
|
113 |
{
|
|
114 |
return EFalse;
|
|
115 |
}
|
|
116 |
|
|
117 |
TPtrC landmarkName;
|
|
118 |
TLocality location;
|
|
119 |
TReal32 coverageRadius;
|
|
120 |
TPtrC iconFileName;
|
|
121 |
TInt iconIndex;
|
|
122 |
TInt iconMaskIndex;
|
|
123 |
TPtrC description;
|
|
124 |
TUint numberOfId;
|
|
125 |
|
|
126 |
CLiwMap* landmarkMap = CLiwDefaultMap::NewL();
|
|
127 |
CleanupClosePushL (*landmarkMap );
|
|
128 |
RArray<TPosLmItemId> categoryIdArray;
|
|
129 |
CleanupClosePushL(categoryIdArray);
|
|
130 |
|
|
131 |
iLandmark = iDatabase->ReadLandmarkLC(landmarkId);
|
|
132 |
CleanupStack::Pop(iLandmark);
|
|
133 |
|
|
134 |
iLandmarkId = HBufC::NewL(KMaxIDStringLength);
|
|
135 |
iLandmarkId->Des().Num(landmarkId,EDecimal);
|
|
136 |
landmarkMap->InsertL(KId,TLiwVariant(iLandmarkId));
|
|
137 |
|
|
138 |
if ( iLandmark->GetLandmarkName(landmarkName) == KErrNone )
|
|
139 |
{
|
|
140 |
landmarkMap->InsertL(KLandmarkName,TLiwVariant(landmarkName));
|
|
141 |
}
|
|
142 |
|
|
143 |
if ( iLandmark->GetPosition(location) == KErrNone )
|
|
144 |
{
|
|
145 |
CLiwMap* positionMap = CLiwDefaultMap::NewL();
|
|
146 |
CleanupClosePushL (*positionMap );
|
|
147 |
TRealX num = location.Latitude();
|
|
148 |
if( !num.IsNaN() )
|
|
149 |
{
|
|
150 |
positionMap->InsertL(KLatitude,TLiwVariant((TReal)num));
|
|
151 |
}
|
|
152 |
num = location.Longitude();
|
|
153 |
if( !num.IsNaN() )
|
|
154 |
{
|
|
155 |
positionMap->InsertL(KLongitude,TLiwVariant((TReal)num));
|
|
156 |
}
|
|
157 |
num = location.Altitude();
|
|
158 |
if( !num.IsNaN() )
|
|
159 |
{
|
|
160 |
positionMap->InsertL(KAltitude,TLiwVariant((TReal)num));
|
|
161 |
}
|
|
162 |
num = location.HorizontalAccuracy();
|
|
163 |
if( !num.IsNaN() )
|
|
164 |
{
|
|
165 |
positionMap->InsertL(KHAccuracy,TLiwVariant((TReal)num));
|
|
166 |
}
|
|
167 |
num = location.VerticalAccuracy();
|
|
168 |
if( !num.IsNaN() )
|
|
169 |
{
|
|
170 |
positionMap->InsertL(KVAccuracy,TLiwVariant((TReal)num));
|
|
171 |
}
|
|
172 |
|
|
173 |
landmarkMap->InsertL(KLandmarkPosition,TLiwVariant(positionMap));
|
|
174 |
CleanupStack::PopAndDestroy (positionMap );
|
|
175 |
}
|
|
176 |
|
|
177 |
if ( iLandmark->GetCoverageRadius(coverageRadius) == KErrNone )
|
|
178 |
{
|
|
179 |
landmarkMap->InsertL(KCoverageRadius,TLiwVariant(coverageRadius));
|
|
180 |
}
|
|
181 |
|
|
182 |
iLandmark->GetCategoriesL(categoryIdArray);
|
|
183 |
TInt catCount = categoryIdArray.Count();
|
|
184 |
if ( catCount )
|
|
185 |
{
|
|
186 |
CLiwList* categoryList = CLiwDefaultList::NewL();
|
|
187 |
CleanupClosePushL ( *categoryList );
|
|
188 |
for ( TInt index = 0; index < catCount; ++index )
|
|
189 |
{
|
|
190 |
HBufC* catId = HBufC::NewLC(KMaxIDStringLength);
|
|
191 |
iCategoryIds.AppendL(catId);
|
|
192 |
CleanupStack::Pop(catId);
|
|
193 |
catId->Des().Num(categoryIdArray[index],EDecimal);
|
|
194 |
categoryList->AppendL(TLiwVariant(catId));
|
|
195 |
}
|
|
196 |
landmarkMap->InsertL(KCategoryInfo,TLiwVariant(categoryList));
|
|
197 |
CleanupStack::PopAndDestroy (categoryList );
|
|
198 |
}
|
|
199 |
|
|
200 |
if ( iLandmark->GetIcon(iconFileName,iconIndex,iconMaskIndex) == KErrNone )
|
|
201 |
{
|
|
202 |
landmarkMap->InsertL(KIconFile,TLiwVariant(iconFileName));
|
|
203 |
landmarkMap->InsertL(KIconIndex,TLiwVariant((TInt32)iconIndex));
|
|
204 |
landmarkMap->InsertL(KIconMaskIndex,TLiwVariant((TInt32)iconMaskIndex));
|
|
205 |
}
|
|
206 |
|
|
207 |
if ( iLandmark->GetLandmarkDescription(description) == KErrNone )
|
|
208 |
{
|
|
209 |
landmarkMap->InsertL(KLandmarkDesc,TLiwVariant(description));
|
|
210 |
}
|
|
211 |
|
|
212 |
numberOfId = iLandmark->NumOfAvailablePositionFields();
|
|
213 |
if ( numberOfId )
|
|
214 |
{
|
|
215 |
CLiwMap* fieldMap = CLiwDefaultMap::NewL();
|
|
216 |
CleanupClosePushL (*fieldMap );
|
|
217 |
TPositionFieldId fieldId = iLandmark->FirstPositionFieldId();
|
|
218 |
TPtrC fieldValue;
|
|
219 |
TLiwVariant variant;
|
|
220 |
while( numberOfId-- )
|
|
221 |
{
|
|
222 |
iLandmark->GetPositionField(fieldId,fieldValue);
|
|
223 |
variant.Set(fieldValue);
|
|
224 |
if ( EPositionFieldCountry == fieldId)
|
|
225 |
{
|
|
226 |
fieldMap->InsertL(KLandmarkCountry,variant);
|
|
227 |
}
|
|
228 |
if ( EPositionFieldPostalCode == fieldId)
|
|
229 |
{
|
|
230 |
fieldMap->InsertL(KLandmarkAreaCode,variant);
|
|
231 |
}
|
|
232 |
if ( EPositionFieldCity == fieldId)
|
|
233 |
{
|
|
234 |
fieldMap->InsertL(KLandmarkCity,variant);
|
|
235 |
}
|
|
236 |
if ( EPositionFieldDistrict == fieldId)
|
|
237 |
{
|
|
238 |
fieldMap->InsertL(KLandmarkDistrict,variant);
|
|
239 |
}
|
|
240 |
if ( EPositionFieldBuildingName == fieldId)
|
|
241 |
{
|
|
242 |
fieldMap->InsertL(KLandmarkBuildingName,variant);
|
|
243 |
}
|
|
244 |
if ( EPositionFieldStreet == fieldId)
|
|
245 |
{
|
|
246 |
fieldMap->InsertL(KLandmarkStreet,variant);
|
|
247 |
}
|
|
248 |
if ( EPositionFieldBuildingTelephone == fieldId)
|
|
249 |
{
|
|
250 |
fieldMap->InsertL(KLandmarkTelephone,variant);
|
|
251 |
}
|
|
252 |
fieldId = iLandmark->NextPositionFieldId(fieldId);
|
|
253 |
}
|
|
254 |
landmarkMap->InsertL(KLandmarkFields,TLiwVariant(fieldMap));
|
|
255 |
CleanupStack::PopAndDestroy (fieldMap );
|
|
256 |
variant.Reset();
|
|
257 |
}
|
|
258 |
|
|
259 |
CleanupStack::PopAndDestroy(&categoryIdArray);
|
|
260 |
|
|
261 |
aEntry.SetL(landmarkMap);
|
|
262 |
CleanupStack::PopAndDestroy (landmarkMap );
|
|
263 |
|
|
264 |
return ETrue;
|
|
265 |
}
|
|
266 |
|
|
267 |
//end of file
|