37
|
1 |
/*
|
|
2 |
* Copyright (c) 2004-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: Implements the CLandmarksModel class
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
#include <eikenv.h>
|
|
21 |
#include <gulicon.h>
|
|
22 |
#include <AknsUtils.h>
|
|
23 |
#include <AknsItemID.h>
|
|
24 |
|
|
25 |
#include <EPos_CPosLandmark.h>
|
|
26 |
|
|
27 |
#include <lmrefapp.mbg>
|
|
28 |
#include "LandmarksCommonData.h"
|
|
29 |
#include "LandmarksModel.h"
|
|
30 |
|
|
31 |
|
|
32 |
const TInt KDefaultIconIndex = 0;
|
|
33 |
|
|
34 |
// ============================ MEMBER FUNCTIONS ===============================
|
|
35 |
|
|
36 |
// -----------------------------------------------------------------------------
|
|
37 |
// -----------------------------------------------------------------------------
|
|
38 |
//
|
|
39 |
CLandmarksModel::CLandmarksModel()
|
|
40 |
{
|
|
41 |
}
|
|
42 |
|
|
43 |
// -----------------------------------------------------------------------------
|
|
44 |
// -----------------------------------------------------------------------------
|
|
45 |
//
|
|
46 |
void CLandmarksModel::ConstructL()
|
|
47 |
{
|
|
48 |
// The list box model uses MDesCArray interface class to take in text items.
|
|
49 |
iListItems = new (ELeave) CDesCArraySeg(KGranularity);
|
|
50 |
}
|
|
51 |
|
|
52 |
// -----------------------------------------------------------------------------
|
|
53 |
// -----------------------------------------------------------------------------
|
|
54 |
//
|
|
55 |
CLandmarksModel* CLandmarksModel::NewL()
|
|
56 |
{
|
|
57 |
CLandmarksModel* self = new (ELeave) CLandmarksModel();
|
|
58 |
CleanupStack::PushL(self);
|
|
59 |
self->ConstructL();
|
|
60 |
CleanupStack::Pop(self);
|
|
61 |
return self;
|
|
62 |
}
|
|
63 |
|
|
64 |
// -----------------------------------------------------------------------------
|
|
65 |
// -----------------------------------------------------------------------------
|
|
66 |
//
|
|
67 |
CLandmarksModel::~CLandmarksModel()
|
|
68 |
{
|
|
69 |
delete iListItems;
|
|
70 |
}
|
|
71 |
|
|
72 |
// -----------------------------------------------------------------------------
|
|
73 |
// -----------------------------------------------------------------------------
|
|
74 |
//
|
|
75 |
void CLandmarksModel::SetItemIds(RArray<TPosLmItemId>* aItemIds)
|
|
76 |
{
|
|
77 |
iItemIds = aItemIds;
|
|
78 |
|
|
79 |
// Empty descriptor model
|
|
80 |
iListItems->Reset();
|
|
81 |
}
|
|
82 |
|
|
83 |
// -----------------------------------------------------------------------------
|
|
84 |
// -----------------------------------------------------------------------------
|
|
85 |
//
|
|
86 |
CDesCArraySeg* CLandmarksModel::ItemList()
|
|
87 |
{
|
|
88 |
return iListItems;
|
|
89 |
}
|
|
90 |
|
|
91 |
// -----------------------------------------------------------------------------
|
|
92 |
// -----------------------------------------------------------------------------
|
|
93 |
//
|
|
94 |
void CLandmarksModel::SetCurrentItem(TInt aIndex)
|
|
95 |
{
|
|
96 |
iCurrentItem = aIndex;
|
|
97 |
}
|
|
98 |
|
|
99 |
// -----------------------------------------------------------------------------
|
|
100 |
// -----------------------------------------------------------------------------
|
|
101 |
//
|
|
102 |
TPosLmItemId CLandmarksModel::CurrentItemId()
|
|
103 |
{
|
|
104 |
if (!iItemIds || iCurrentItem < 0 ||
|
|
105 |
iCurrentItem > iItemIds->Count() - 1)
|
|
106 |
{
|
|
107 |
return KPosLmNullItemId;
|
|
108 |
}
|
|
109 |
|
|
110 |
return (*iItemIds)[iCurrentItem];
|
|
111 |
}
|
|
112 |
|
|
113 |
// -----------------------------------------------------------------------------
|
|
114 |
// -----------------------------------------------------------------------------
|
|
115 |
//
|
|
116 |
void CLandmarksModel::GetItemIdsL(
|
|
117 |
const CArrayFix<TInt>& aSelectionIndexes,
|
|
118 |
RArray<TPosLmItemId>& aItemIds )
|
|
119 |
{
|
|
120 |
CleanupClosePushL(aItemIds);
|
|
121 |
|
|
122 |
aItemIds.Reset();
|
|
123 |
if ( iItemIds )
|
|
124 |
{
|
|
125 |
for ( TInt i = 0; i < aSelectionIndexes.Count(); i++ )
|
|
126 |
{
|
|
127 |
if ( i < iItemIds->Count() )
|
|
128 |
{
|
|
129 |
aItemIds.AppendL( (*iItemIds)[aSelectionIndexes[i]] );
|
|
130 |
}
|
|
131 |
else
|
|
132 |
{
|
|
133 |
break;
|
|
134 |
}
|
|
135 |
}
|
|
136 |
}
|
|
137 |
|
|
138 |
CleanupStack::Pop(&aItemIds);
|
|
139 |
}
|
|
140 |
|
|
141 |
// -----------------------------------------------------------------------------
|
|
142 |
// -----------------------------------------------------------------------------
|
|
143 |
//
|
|
144 |
CIconList* CLandmarksModel::CreateIconListL()
|
|
145 |
{
|
|
146 |
CIconList* iconList =
|
|
147 |
(CIconList*) new (ELeave) CArrayPtrFlat<CGulIcon>(KGranularity);
|
|
148 |
CleanupStack::PushL(iconList);
|
|
149 |
|
|
150 |
// Create the default landmark icon consisting of its image and mask
|
|
151 |
TAknsItemID aknsItemId = {0,0};
|
|
152 |
CGulIcon* icon = AknsUtils::CreateGulIconL(NULL, aknsItemId,
|
|
153 |
KLandmarksMbmFileName,
|
|
154 |
EMbmLmrefappDefault_lm,
|
|
155 |
EMbmLmrefappDefault_lm_mask);
|
|
156 |
CleanupStack::PushL(icon);
|
|
157 |
icon->SetBitmapsOwnedExternally(EFalse);
|
|
158 |
iconList->AppendL(icon);
|
|
159 |
CleanupStack::Pop(2, iconList);
|
|
160 |
|
|
161 |
// initialze iIconList. We don't need to delete any possible previous
|
|
162 |
// iIconList since ownership is transferred to calling object.
|
|
163 |
iIconList = iconList;
|
|
164 |
|
|
165 |
return iIconList;
|
|
166 |
}
|
|
167 |
|
|
168 |
// -----------------------------------------------------------------------------
|
|
169 |
// -----------------------------------------------------------------------------
|
|
170 |
//
|
|
171 |
void CLandmarksModel::RepopulateModelL(
|
|
172 |
CArrayPtr<CPosLandmark>* aLandmarks)
|
|
173 |
{
|
|
174 |
TInt nrOfReadItems = aLandmarks->Count();
|
|
175 |
|
|
176 |
// Format and insert the read landmarks
|
|
177 |
for (TInt i = 0; i < nrOfReadItems; i++)
|
|
178 |
{
|
|
179 |
CPosLandmark* landmark = (*aLandmarks)[i];
|
|
180 |
HBufC* formattedListItem = FormatListItemLC(*landmark);
|
|
181 |
iListItems->AppendL(*formattedListItem);
|
|
182 |
CleanupStack::PopAndDestroy(formattedListItem);
|
|
183 |
}
|
|
184 |
}
|
|
185 |
|
|
186 |
// -----------------------------------------------------------------------------
|
|
187 |
// Formats a list item to the following format "X\tlandmarkName\t"
|
|
188 |
// where X = icon index
|
|
189 |
// (other items were commented in a header).
|
|
190 |
// -----------------------------------------------------------------------------
|
|
191 |
//
|
|
192 |
HBufC* CLandmarksModel::FormatListItemLC(CPosLandmark& aLandmark)
|
|
193 |
{
|
|
194 |
// Extract name
|
|
195 |
TPtrC name;
|
|
196 |
aLandmark.GetLandmarkName(name);
|
|
197 |
// 10 extra chars for icon index and column separator
|
|
198 |
const TInt KExtraChars = 10;
|
|
199 |
HBufC* formattedNameBuf = HBufC::NewLC(name.Length() + KExtraChars);
|
|
200 |
TPtr formattedNamePtr = formattedNameBuf->Des();
|
|
201 |
|
|
202 |
// Extract icon info
|
|
203 |
TPtrC mbmIconFile;
|
|
204 |
TInt iconIndex, maskIndex;
|
|
205 |
TInt res = aLandmark.GetIcon(mbmIconFile, iconIndex, maskIndex);
|
|
206 |
|
|
207 |
// Format list item
|
|
208 |
if (res == KErrNone)
|
|
209 |
{
|
|
210 |
// Create icon and append it to icon array.
|
|
211 |
TRAPD(err, AppendIconL(mbmIconFile, iconIndex, maskIndex));
|
|
212 |
if (err == KErrNone)
|
|
213 |
{
|
|
214 |
// Append the array index where the icon is appended
|
|
215 |
formattedNamePtr.AppendNum(iIconList->Count() - 1);
|
|
216 |
}
|
|
217 |
else
|
|
218 |
{
|
|
219 |
formattedNamePtr.AppendNum(KDefaultIconIndex);
|
|
220 |
}
|
|
221 |
}
|
|
222 |
else // res == KErrNotFound
|
|
223 |
{
|
|
224 |
formattedNamePtr.AppendNum(KDefaultIconIndex);
|
|
225 |
}
|
|
226 |
formattedNamePtr.Append(KTab);
|
|
227 |
formattedNamePtr.Append(name);
|
|
228 |
|
|
229 |
return formattedNameBuf;
|
|
230 |
}
|
|
231 |
|
|
232 |
// -----------------------------------------------------------------------------
|
|
233 |
// -----------------------------------------------------------------------------
|
|
234 |
//
|
|
235 |
void CLandmarksModel::AppendIconL(
|
|
236 |
const TDesC& aMbmFile,
|
|
237 |
TInt aIconOffset,
|
|
238 |
TInt aMaskOffset)
|
|
239 |
{
|
|
240 |
TAknsItemID aknsItemId = {0,0};
|
|
241 |
CGulIcon* icon = AknsUtils::CreateGulIconL(NULL, aknsItemId,
|
|
242 |
aMbmFile,
|
|
243 |
aIconOffset,
|
|
244 |
aMaskOffset);
|
|
245 |
CleanupStack::PushL(icon);
|
|
246 |
icon->SetBitmapsOwnedExternally(EFalse);
|
|
247 |
iIconList->AppendL(icon);
|
|
248 |
CleanupStack::Pop(icon);
|
|
249 |
}
|
|
250 |
|
|
251 |
|