|
1 /* |
|
2 * Copyright (c) 2007-2008 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: item presentation model |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <liwservicehandler.h> |
|
20 #include "hnitemmodel.h" |
|
21 #include "hnmenuitemmodel.h" |
|
22 #include "hnactionmodel.h" |
|
23 #include "hntoolbarmodel.h" |
|
24 #include "hnattributebase.h" |
|
25 #include "hnattributetext.h" |
|
26 #include "hnbuttonmodel.h" |
|
27 #include "hnglobals.h" |
|
28 #include "hnconvutils.h" |
|
29 |
|
30 // ============================ MEMBER FUNCTIONS ============================= |
|
31 |
|
32 |
|
33 // --------------------------------------------------------------------------- |
|
34 // |
|
35 // --------------------------------------------------------------------------- |
|
36 // |
|
37 EXPORT_C CHnItemModel* CHnItemModel::NewL() |
|
38 { |
|
39 CHnItemModel* self = new( ELeave ) CHnItemModel(); |
|
40 CleanupStack::PushL( self ); |
|
41 self->ConstructL(); |
|
42 CleanupStack::Pop( self ); |
|
43 return self; |
|
44 } |
|
45 |
|
46 // --------------------------------------------------------------------------- |
|
47 // |
|
48 // --------------------------------------------------------------------------- |
|
49 // |
|
50 CHnItemModel::~CHnItemModel() |
|
51 { |
|
52 iTemplate.Close(); |
|
53 delete iMenuModel; |
|
54 delete iToolbarModel; |
|
55 delete iMskModel; |
|
56 DeleteAllActionModels(); |
|
57 iAttrs.ResetAndDestroy(); |
|
58 } |
|
59 |
|
60 // --------------------------------------------------------------------------- |
|
61 // |
|
62 // --------------------------------------------------------------------------- |
|
63 // |
|
64 EXPORT_C void CHnItemModel::DeleteAllActionModels() |
|
65 { |
|
66 THashMapIter< TInt, CArrayPtr<CHnActionModel>* > iterator( iActions ); |
|
67 while( iterator.NextKey() ) |
|
68 { |
|
69 CArrayPtr<CHnActionModel>** actions = iterator.CurrentValue(); |
|
70 (*actions)->ResetAndDestroy(); |
|
71 delete *actions; |
|
72 iterator.RemoveCurrent(); |
|
73 } |
|
74 iActions.Close(); |
|
75 } |
|
76 |
|
77 // --------------------------------------------------------------------------- |
|
78 // |
|
79 // --------------------------------------------------------------------------- |
|
80 // |
|
81 void CHnItemModel::RemoveLiwObjects() |
|
82 { |
|
83 if ( iToolbarModel ) |
|
84 { |
|
85 iToolbarModel->RemoveLiwObjects(); |
|
86 } |
|
87 |
|
88 for( TInt i = 0; i < iAttrs.Count(); ++i ) |
|
89 { |
|
90 iAttrs[i]->RemoveLiwObjects(); |
|
91 } |
|
92 } |
|
93 |
|
94 // --------------------------------------------------------------------------- |
|
95 // |
|
96 // --------------------------------------------------------------------------- |
|
97 // |
|
98 TInt CHnItemModel::OfferHnEventL( CHnEventHandler & aEventHandler, |
|
99 const TInt aEventId, CLiwGenericParamList* aEventParameters ) |
|
100 { |
|
101 TInt err = KErrNotFound; |
|
102 CArrayPtr<CHnActionModel>* actions = GetActions( aEventId ); |
|
103 if ( actions ) |
|
104 { |
|
105 TInt actionsCount = actions->Count(); |
|
106 for( TInt i = 0; i < actionsCount; i++ ) |
|
107 { |
|
108 ASSERT( actions->At( i ) ); |
|
109 err = actions->At( i )->ExecuteL( aEventHandler, aEventParameters ); |
|
110 if ( err != KErrNone ) |
|
111 { |
|
112 break; |
|
113 } |
|
114 } |
|
115 } |
|
116 return err; |
|
117 } |
|
118 |
|
119 // --------------------------------------------------------------------------- |
|
120 // |
|
121 // --------------------------------------------------------------------------- |
|
122 // |
|
123 CHnItemModel::CHnItemModel() : |
|
124 iActions( &DefaultHash::Integer, &DefaultIdentity::Integer ), |
|
125 iEditable( EFalse ), |
|
126 iCustomId( KErrNotFound ), |
|
127 iMskModel( NULL ) |
|
128 { |
|
129 |
|
130 } |
|
131 |
|
132 // --------------------------------------------------------------------------- |
|
133 // |
|
134 // --------------------------------------------------------------------------- |
|
135 // |
|
136 void CHnItemModel::ConstructL() |
|
137 { |
|
138 iUid = TUid::Null(); |
|
139 } |
|
140 |
|
141 // --------------------------------------------------------------------------- |
|
142 // |
|
143 // --------------------------------------------------------------------------- |
|
144 // |
|
145 EXPORT_C void CHnItemModel::SetMenuItemModel( CHnMenuItemModel* aMenu ) |
|
146 { |
|
147 ASSERT( aMenu ); |
|
148 delete iMenuModel; |
|
149 iMenuModel = aMenu; |
|
150 } |
|
151 |
|
152 // --------------------------------------------------------------------------- |
|
153 // |
|
154 // --------------------------------------------------------------------------- |
|
155 // |
|
156 MHnMenuItemModelIterator* CHnItemModel::GetMenuStructure() |
|
157 { |
|
158 if( iMenuModel ) |
|
159 return iMenuModel->GetMenuStructure(); |
|
160 else |
|
161 return 0; |
|
162 } |
|
163 |
|
164 // --------------------------------------------------------------------------- |
|
165 // |
|
166 // --------------------------------------------------------------------------- |
|
167 // |
|
168 EXPORT_C void CHnItemModel::SetMiddleSoftKey( CHnButtonModel* aMsk ) |
|
169 { |
|
170 delete iMskModel; |
|
171 iMskModel = aMsk; |
|
172 } |
|
173 |
|
174 // --------------------------------------------------------------------------- |
|
175 // |
|
176 // --------------------------------------------------------------------------- |
|
177 // |
|
178 EXPORT_C CHnButtonModel* CHnItemModel::GetMiddleSoftKey() |
|
179 { |
|
180 return iMskModel; |
|
181 } |
|
182 |
|
183 // --------------------------------------------------------------------------- |
|
184 // |
|
185 // --------------------------------------------------------------------------- |
|
186 // |
|
187 EXPORT_C RHashMap< TInt, CArrayPtr<CHnActionModel>* >& |
|
188 CHnItemModel::GetActions() |
|
189 { |
|
190 return iActions; |
|
191 } |
|
192 |
|
193 // --------------------------------------------------------------------------- |
|
194 // |
|
195 // --------------------------------------------------------------------------- |
|
196 // |
|
197 EXPORT_C CArrayPtr<CHnActionModel>* CHnItemModel::GetActions( TInt aId ) |
|
198 { |
|
199 CArrayPtr<CHnActionModel>** ret = iActions.Find( aId ); |
|
200 if( ret ) |
|
201 { |
|
202 return *ret; |
|
203 } |
|
204 return NULL; |
|
205 } |
|
206 |
|
207 // --------------------------------------------------------------------------- |
|
208 // |
|
209 // --------------------------------------------------------------------------- |
|
210 // |
|
211 EXPORT_C const CHnToolbarModel* CHnItemModel::GetToolbarModel() const |
|
212 { |
|
213 return iToolbarModel; |
|
214 } |
|
215 |
|
216 // --------------------------------------------------------------------------- |
|
217 // |
|
218 // --------------------------------------------------------------------------- |
|
219 // |
|
220 EXPORT_C void CHnItemModel::SetToolbarModel( CHnToolbarModel* aToolbar ) |
|
221 { |
|
222 delete iToolbarModel; |
|
223 iToolbarModel = NULL; |
|
224 iToolbarModel = aToolbar; |
|
225 } |
|
226 |
|
227 // --------------------------------------------------------------------------- |
|
228 // |
|
229 // --------------------------------------------------------------------------- |
|
230 // |
|
231 EXPORT_C const TDesC8& CHnItemModel::GetTemplate() |
|
232 { |
|
233 CHnAttributeBase* templateAttr = GetAttribute( KTemplate8() ); |
|
234 if ( templateAttr ) |
|
235 { |
|
236 return templateAttr->Value(); |
|
237 } |
|
238 return KNullDesC8(); |
|
239 } |
|
240 |
|
241 // --------------------------------------------------------------------------- |
|
242 // |
|
243 // --------------------------------------------------------------------------- |
|
244 // |
|
245 EXPORT_C void CHnItemModel::SetTemplateL( const TDesC8& aTemplate ) |
|
246 { |
|
247 CHnAttributeText* templateAttr = CHnAttributeText::NewL(); |
|
248 templateAttr->SetNameL( KTemplate8 ); |
|
249 templateAttr->SetValueL( aTemplate ); |
|
250 SetAttributeL( templateAttr ); |
|
251 } |
|
252 |
|
253 // --------------------------------------------------------------------------- |
|
254 // |
|
255 // --------------------------------------------------------------------------- |
|
256 // |
|
257 EXPORT_C void CHnItemModel::SetAttributeL( CHnAttributeBase* aAttr ) |
|
258 { |
|
259 for( TInt i( 0 ); i < iAttrs.Count(); i++ ) |
|
260 { |
|
261 if( iAttrs[i]->Name() == aAttr->Name() ) |
|
262 { |
|
263 delete iAttrs[i]; |
|
264 iAttrs.Remove(i); |
|
265 break; |
|
266 } |
|
267 } |
|
268 iAttrs.AppendL( aAttr ); |
|
269 } |
|
270 |
|
271 // --------------------------------------------------------------------------- |
|
272 // |
|
273 // --------------------------------------------------------------------------- |
|
274 // |
|
275 EXPORT_C void CHnItemModel::ClearAttributesL() |
|
276 { |
|
277 iAttrs.ResetAndDestroy(); |
|
278 } |
|
279 |
|
280 // --------------------------------------------------------------------------- |
|
281 // |
|
282 // --------------------------------------------------------------------------- |
|
283 // |
|
284 EXPORT_C CHnAttributeBase* CHnItemModel::GetAttribute( const TDesC8 & aMulAttribute ) |
|
285 { |
|
286 CHnAttributeBase* attr = NULL; |
|
287 for( TInt i( 0 ); i < iAttrs.Count(); i++ ) |
|
288 { |
|
289 if( ! iAttrs[i]->Name().Compare( aMulAttribute ) ) |
|
290 { |
|
291 attr = iAttrs[i]; |
|
292 break; |
|
293 } |
|
294 } |
|
295 return attr; |
|
296 } |
|
297 |
|
298 // --------------------------------------------------------------------------- |
|
299 // |
|
300 // --------------------------------------------------------------------------- |
|
301 // |
|
302 EXPORT_C TBool CHnItemModel::IsDeleteLocked() |
|
303 { |
|
304 TBool res = EFalse; |
|
305 if ( iFlags & EItemFlagRemoveLocked ) |
|
306 { |
|
307 res = ETrue; |
|
308 } |
|
309 return res; |
|
310 } |
|
311 |
|
312 // --------------------------------------------------------------------------- |
|
313 // |
|
314 // --------------------------------------------------------------------------- |
|
315 // |
|
316 EXPORT_C TBool CHnItemModel::IsMoveLocked() |
|
317 { |
|
318 TBool res = EFalse; |
|
319 if ( iFlags & EItemFlagMoveLocked ) |
|
320 { |
|
321 res = ETrue; |
|
322 } |
|
323 return res; |
|
324 } |
|
325 |
|
326 // --------------------------------------------------------------------------- |
|
327 // |
|
328 // --------------------------------------------------------------------------- |
|
329 // |
|
330 EXPORT_C TBool CHnItemModel::IsDrmExpired() |
|
331 { |
|
332 TBool res = EFalse; |
|
333 if ( iFlags & EItemFlagDrmExpired ) |
|
334 { |
|
335 res = ETrue; |
|
336 } |
|
337 return res; |
|
338 } |
|
339 |
|
340 // --------------------------------------------------------------------------- |
|
341 // |
|
342 // --------------------------------------------------------------------------- |
|
343 // |
|
344 EXPORT_C TBool CHnItemModel::IsRunning() |
|
345 { |
|
346 TBool res = EFalse; |
|
347 if ( iFlags & EItemFlagRunning ) |
|
348 { |
|
349 res = ETrue; |
|
350 } |
|
351 return res; |
|
352 } |
|
353 |
|
354 // --------------------------------------------------------------------------- |
|
355 // |
|
356 // --------------------------------------------------------------------------- |
|
357 // |
|
358 EXPORT_C void CHnItemModel::SetFlag( TInt aFlag ) |
|
359 { |
|
360 if ( ( iFlags & aFlag ) == 0 ) |
|
361 { |
|
362 iFlags |= aFlag; |
|
363 } |
|
364 } |
|
365 |
|
366 // --------------------------------------------------------------------------- |
|
367 // |
|
368 // --------------------------------------------------------------------------- |
|
369 // |
|
370 EXPORT_C void CHnItemModel::ClearFlags() |
|
371 { |
|
372 iFlags = 0; |
|
373 } |
|
374 |
|
375 // --------------------------------------------------------------------------- |
|
376 // |
|
377 // --------------------------------------------------------------------------- |
|
378 // |
|
379 EXPORT_C void CHnItemModel::SetType( const TDesC8& aType ) |
|
380 { |
|
381 if ( !aType.Compare( KMenuFolder8 ) ) |
|
382 { |
|
383 iType = EItemTypeFolder; |
|
384 } |
|
385 else if ( !aType.Compare( KMenuSuite8 ) ) |
|
386 { |
|
387 iType = EItemTypeSuite; |
|
388 } |
|
389 else if ( !aType.Compare( KMenuApplication8 ) ) |
|
390 { |
|
391 iType = EItemTypeApplication; |
|
392 } |
|
393 else if ( !aType.Compare( KMenuParentFolder8 ) ) |
|
394 { |
|
395 iType = EItemTypeParentFolder; |
|
396 } |
|
397 else |
|
398 { |
|
399 iType = EItemTypeUnknown; |
|
400 } |
|
401 } |
|
402 |
|
403 // --------------------------------------------------------------------------- |
|
404 // |
|
405 // --------------------------------------------------------------------------- |
|
406 // |
|
407 EXPORT_C void CHnItemModel::SetCustomId( TInt64 aCustomId ) |
|
408 { |
|
409 iCustomId = aCustomId; |
|
410 } |
|
411 |
|
412 // --------------------------------------------------------------------------- |
|
413 // |
|
414 // --------------------------------------------------------------------------- |
|
415 // |
|
416 EXPORT_C TInt64 CHnItemModel::CustomId() |
|
417 { |
|
418 return iCustomId; |
|
419 } |
|
420 |
|
421 // --------------------------------------------------------------------------- |
|
422 // |
|
423 // --------------------------------------------------------------------------- |
|
424 // |
|
425 EXPORT_C TMcsItemType CHnItemModel::GetItemType() |
|
426 { |
|
427 return iType; |
|
428 } |
|
429 |
|
430 // --------------------------------------------------------------------------- |
|
431 // |
|
432 // --------------------------------------------------------------------------- |
|
433 // |
|
434 EXPORT_C TUid CHnItemModel::GetItemUid() |
|
435 { |
|
436 return iUid; |
|
437 } |
|
438 |
|
439 // --------------------------------------------------------------------------- |
|
440 // |
|
441 // --------------------------------------------------------------------------- |
|
442 // |
|
443 EXPORT_C void CHnItemModel::SetItemUidL( const TDesC8& aUid ) |
|
444 { |
|
445 TUint uint( KErrNone ); |
|
446 HBufC* str = HnConvUtils::Str8ToStr( aUid ); |
|
447 CleanupStack::PushL( str ); |
|
448 |
|
449 TInt position( str->Find( KHexPrefix16 ) ); |
|
450 TPtrC string( *str ); |
|
451 TRadix radix( EDecimal ); |
|
452 if ( position == 0 ) |
|
453 { |
|
454 radix = EHex; |
|
455 string.Set( str->Mid( KHexPrefix16().Length() ) ); |
|
456 } |
|
457 |
|
458 TLex( string ).Val( uint, radix ); |
|
459 CleanupStack::PopAndDestroy( str ); |
|
460 |
|
461 iUid = TUid::Uid( uint ); |
|
462 } |
|
463 |