|
1 /* |
|
2 * Copyright (c) 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 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: UI level handler for category data.* |
|
15 */ |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <StringLoader.h> |
|
22 |
|
23 #include <mpxmediageneraldefs.h> |
|
24 #include <mpxmedia.h> |
|
25 #include <mpxmediaarray.h> |
|
26 |
|
27 #include <ganes/HgScroller.h> |
|
28 #include <ganes/HgItem.h> |
|
29 |
|
30 #include <vcxhgmyvideos.rsg> |
|
31 #include <vcxmyvideosdefs.h> |
|
32 #include "IptvDebug.h" |
|
33 |
|
34 #include "vcxhgmyvideoscategorymodelhandler.h" |
|
35 #include "vcxhgmyvideosmodel.h" |
|
36 #include "vcxhgmyvideoscollectionclient.h" |
|
37 |
|
38 // ============================ MEMBER FUNCTIONS =============================== |
|
39 |
|
40 // ----------------------------------------------------------------------------- |
|
41 // CVcxHgMyVideosCategoryModelHandler::CVcxHgMyVideosCategoryModelHandler() |
|
42 // ----------------------------------------------------------------------------- |
|
43 // |
|
44 CVcxHgMyVideosCategoryModelHandler::CVcxHgMyVideosCategoryModelHandler( |
|
45 CVcxHgMyVideosModel& aModel, CHgScroller& aScroller ) |
|
46 : iModel( aModel ), |
|
47 iScroller( aScroller ) |
|
48 { |
|
49 } |
|
50 |
|
51 // ----------------------------------------------------------------------------- |
|
52 // CVcxHgMyVideosCategoryModelHandler::~CVcxHgMyVideosCategoryModelHandler() |
|
53 // ----------------------------------------------------------------------------- |
|
54 // |
|
55 CVcxHgMyVideosCategoryModelHandler::~CVcxHgMyVideosCategoryModelHandler() |
|
56 { |
|
57 delete iCategoryList; |
|
58 iCategoryIdArray.Reset(); |
|
59 } |
|
60 |
|
61 // ----------------------------------------------------------------------------- |
|
62 // CVcxHgMyVideosCategoryModelHandler::DoModelActivateL() |
|
63 // ----------------------------------------------------------------------------- |
|
64 // |
|
65 void CVcxHgMyVideosCategoryModelHandler::DoModelActivateL() |
|
66 { |
|
67 IPTVLOGSTRING_LOW_LEVEL( |
|
68 "MPX My Videos UI # CVcxHgMyVideosCategoryModelHandler::DoModelActivateL() - Enter" ); |
|
69 |
|
70 iModel.CollectionClient().SetCategoryModelObserver( this ); |
|
71 |
|
72 IPTVLOGSTRING_LOW_LEVEL( |
|
73 "MPX My Videos UI # CVcxHgMyVideosCategoryModelHandler::DoModelActivateL() - Exit" ); |
|
74 } |
|
75 |
|
76 // ----------------------------------------------------------------------------- |
|
77 // CVcxHgMyVideosCategoryModelHandler::DoModelDeactivate() |
|
78 // ----------------------------------------------------------------------------- |
|
79 // |
|
80 void CVcxHgMyVideosCategoryModelHandler::DoModelDeactivate() |
|
81 { |
|
82 IPTVLOGSTRING_LOW_LEVEL( |
|
83 "MPX My Videos UI # CVcxHgMyVideosCategoryModelHandler::DoModelDeactivate() - Enter" ); |
|
84 |
|
85 iModel.CollectionClient().SetCategoryModelObserver( NULL ); |
|
86 |
|
87 IPTVLOGSTRING_LOW_LEVEL( |
|
88 "MPX My Videos UI # CVcxHgMyVideosCategoryModelHandler::DoModelDeactivate() - Exit" ); |
|
89 } |
|
90 |
|
91 // ----------------------------------------------------------------------------- |
|
92 // CVcxHgMyVideosCategoryModelHandler::GetCategoryListL() |
|
93 // ----------------------------------------------------------------------------- |
|
94 // |
|
95 void CVcxHgMyVideosCategoryModelHandler::GetCategoryListL() |
|
96 { |
|
97 IPTVLOGSTRING_LOW_LEVEL( |
|
98 "MPX My Videos UI # CVcxHgMyVideosCategoryModelHandler::GetCategoryListL() - Enter" ); |
|
99 |
|
100 iModel.CollectionClient().GetCategoryListL(); |
|
101 |
|
102 IPTVLOGSTRING_LOW_LEVEL( |
|
103 "MPX My Videos UI # CVcxHgMyVideosCategoryModelHandler::GetCategoryListL() - Exit" ); |
|
104 } |
|
105 |
|
106 // ----------------------------------------------------------------------------- |
|
107 // CVcxHgMyVideosCategoryModelHandler::Highlight() |
|
108 // ----------------------------------------------------------------------------- |
|
109 // |
|
110 TInt CVcxHgMyVideosCategoryModelHandler::Highlight() |
|
111 { |
|
112 return iScroller.SelectedIndex(); |
|
113 } |
|
114 |
|
115 // ----------------------------------------------------------------------------- |
|
116 // CVcxHgMyVideosCategoryModelHandler::GetCategoryNameLC() |
|
117 // ----------------------------------------------------------------------------- |
|
118 // |
|
119 HBufC* CVcxHgMyVideosCategoryModelHandler::GetCategoryNameLC( TInt aIndex ) |
|
120 { |
|
121 HBufC* name = NULL; |
|
122 |
|
123 switch ( aIndex ) |
|
124 { |
|
125 case KVcxMvcCategoryIdAll: |
|
126 name = StringLoader::LoadLC( R_VCXHGMYVIDEOS_STORAGE_ALL_LIST ); |
|
127 break; |
|
128 case KVcxMvcCategoryIdDownloads: |
|
129 name = StringLoader::LoadLC( R_VCXHGMYVIDEOS_STORAGE_DOWNLOADS_LIST ); |
|
130 break; |
|
131 case KVcxMvcCategoryIdCaptured: |
|
132 name = StringLoader::LoadLC( R_VCXHGMYVIDEOS_STORAGE_CAPTURED_LIST ); |
|
133 break; |
|
134 case KVcxMvcCategoryIdOther: |
|
135 name = StringLoader::LoadLC( R_VCXHGMYVIDEOS_STORAGE_OTHER_LIST ); |
|
136 break; |
|
137 default: |
|
138 { |
|
139 IPTVLOGSTRING_LOW_LEVEL( |
|
140 "MPX My Videos UI # GetCategoryNameLC() Unexpected category!" ); |
|
141 } |
|
142 break; |
|
143 } |
|
144 return name; |
|
145 } |
|
146 |
|
147 // ----------------------------------------------------------------------------- |
|
148 // CVcxHgMyVideosCategoryModelHandler::FormatCategorySecondRowLC() |
|
149 // ----------------------------------------------------------------------------- |
|
150 // |
|
151 HBufC* CVcxHgMyVideosCategoryModelHandler::FormatCategorySecondRowLC( CMPXMedia& aMedia ) |
|
152 { |
|
153 HBufC* details = NULL; |
|
154 HBufC* newVideoName = NULL; |
|
155 TInt newVideos = 0; |
|
156 TInt videos = 0; |
|
157 |
|
158 if ( aMedia.IsSupported( KVcxMediaMyVideosCategoryNewItemCount ) ) |
|
159 { |
|
160 newVideos = *( aMedia.Value<TInt>( KVcxMediaMyVideosCategoryNewItemCount ) ); |
|
161 } |
|
162 if ( aMedia.IsSupported( KVcxMediaMyVideosCategoryItemCount ) ) |
|
163 { |
|
164 videos = *( aMedia.Value<TInt>( KVcxMediaMyVideosCategoryItemCount ) ); |
|
165 } |
|
166 |
|
167 if ( newVideos > 0 ) |
|
168 { |
|
169 if ( aMedia.IsSupported( KVcxMediaMyVideosCategoryNewItemName ) ) |
|
170 { |
|
171 newVideoName = aMedia.ValueText( KVcxMediaMyVideosCategoryNewItemName ).AllocLC(); |
|
172 } |
|
173 else |
|
174 { |
|
175 newVideoName = KNullDesC().AllocLC(); |
|
176 } |
|
177 |
|
178 if ( newVideos == 1 ) |
|
179 { |
|
180 details = StringLoader::LoadL( R_VCXHGMYVIDEOS_ONE_NEW_VIDEO, *newVideoName ); |
|
181 } |
|
182 else |
|
183 { |
|
184 CDesCArrayFlat* arrayForStrings = new ( ELeave ) CDesCArrayFlat( 1 ); |
|
185 CleanupStack::PushL( arrayForStrings ); |
|
186 arrayForStrings->AppendL( *newVideoName ); |
|
187 |
|
188 CArrayFixFlat<TInt>* arrayForInts = new ( ELeave ) CArrayFixFlat<TInt>( 3 ); |
|
189 CleanupStack::PushL( arrayForInts ); |
|
190 arrayForInts->AppendL( newVideos ); |
|
191 |
|
192 details = StringLoader::LoadL( R_VCXHGMYVIDEOS_N_NEW_VIDEOS, |
|
193 *arrayForStrings, |
|
194 *arrayForInts ); |
|
195 |
|
196 CleanupStack::PopAndDestroy( arrayForInts ); |
|
197 CleanupStack::PopAndDestroy( arrayForStrings ); |
|
198 } |
|
199 |
|
200 CleanupStack::PopAndDestroy( newVideoName ); |
|
201 CleanupStack::PushL( details ); |
|
202 } |
|
203 else |
|
204 { |
|
205 if ( videos == 0 ) |
|
206 { |
|
207 details = StringLoader::LoadLC( R_VCXHGMYVIDEOS_NO_VIDEOS_IN_CATEGORY ); |
|
208 } |
|
209 else if ( videos == 1 ) |
|
210 { |
|
211 details = StringLoader::LoadLC( R_VCXHGMYVIDEOS_ONE_VIDEO_IN_CATEGORY ); |
|
212 } |
|
213 else |
|
214 { |
|
215 details = StringLoader::LoadLC( R_VCXHGMYVIDEOS_VIDEOS_IN_CATEGORY, videos ); |
|
216 } |
|
217 } |
|
218 |
|
219 return details; |
|
220 } |
|
221 |
|
222 // ----------------------------------------------------------------------------- |
|
223 // CVcxHgMyVideosCategoryModelHandler::UiIndexFromMpxItemId() |
|
224 // ----------------------------------------------------------------------------- |
|
225 // |
|
226 TInt CVcxHgMyVideosCategoryModelHandler::UiIndexFromMpxItemId( TMPXItemId& aMpxItemId ) |
|
227 { |
|
228 IPTVLOGSTRING_LOW_LEVEL( "MPX My Videos UI # UiIndexFromMpxItemId() - Enter" ); |
|
229 |
|
230 TInt index ( KErrNotFound ); |
|
231 |
|
232 if ( iCategoryList ) |
|
233 { |
|
234 CMPXMedia* media = NULL; |
|
235 TMPXItemId mpxItemId; |
|
236 |
|
237 for ( TInt i = 0; i < iCategoryList->Count(); i++ ) |
|
238 { |
|
239 media = (*iCategoryList)[i]; |
|
240 |
|
241 if ( media && media->IsSupported( KMPXMediaGeneralId ) ) |
|
242 { |
|
243 mpxItemId = *media->Value<TMPXItemId>( KMPXMediaGeneralId ); |
|
244 |
|
245 if ( mpxItemId == aMpxItemId ) |
|
246 { |
|
247 index = ResolveCategoryArrayIndexById( i ); |
|
248 break; |
|
249 } |
|
250 } |
|
251 } |
|
252 } |
|
253 |
|
254 IPTVLOGSTRING2_LOW_LEVEL( "MPX My Videos UI # UiIndexFromMpxItemId(), index = %d - Exit", index ); |
|
255 return index; |
|
256 } |
|
257 |
|
258 // ----------------------------------------------------------------------------- |
|
259 // CVcxHgMyVideosCategoryModelHandler::ResolveCategoryArrayIndexById() |
|
260 // ----------------------------------------------------------------------------- |
|
261 // |
|
262 TInt CVcxHgMyVideosCategoryModelHandler::ResolveCategoryArrayIndexById( TInt aCategoryId ) |
|
263 { |
|
264 TInt ret( 0 ); |
|
265 for(TInt i = 0; i < iCategoryIdArray.Count(); i++ ) |
|
266 { |
|
267 if( iCategoryIdArray[ i ] == aCategoryId ) |
|
268 { |
|
269 ret = i; |
|
270 break; |
|
271 } |
|
272 } |
|
273 return ret; |
|
274 } |
|
275 |
|
276 // ----------------------------------------------------------------------------- |
|
277 // CVcxHgMyVideosCategoryModelHandler::NewCategoryListL() |
|
278 // MPX Collection calls this callback when new category list is available. |
|
279 // ----------------------------------------------------------------------------- |
|
280 // |
|
281 void CVcxHgMyVideosCategoryModelHandler::NewCategoryListL( |
|
282 CMPXMediaArray* aCategoryList ) |
|
283 { |
|
284 IPTVLOGSTRING_LOW_LEVEL( "MPX My Videos UI # NewCategoryListL() - Enter" ); |
|
285 |
|
286 delete iCategoryList; |
|
287 iCategoryList = aCategoryList; |
|
288 |
|
289 UpdateCategoryListL(); |
|
290 |
|
291 IPTVLOGSTRING_LOW_LEVEL( "MPX My Videos UI # NewCategoryListL() - Exit" ); |
|
292 } |
|
293 |
|
294 // ----------------------------------------------------------------------------- |
|
295 // CVcxHgMyVideosCategoryModelHandler::CategoryListModifiedL() |
|
296 // MPX Collection calls this callback when the category list is modified. |
|
297 // ----------------------------------------------------------------------------- |
|
298 // |
|
299 void CVcxHgMyVideosCategoryModelHandler::CategoryListModifiedL() |
|
300 { |
|
301 IPTVLOGSTRING_LOW_LEVEL( "MPX My Videos UI # CategoryListModifiedL() - Enter" ); |
|
302 |
|
303 UpdateCategoryListL(); |
|
304 |
|
305 IPTVLOGSTRING_LOW_LEVEL( "MPX My Videos UI # CategoryListModifiedL() - Exit" ); |
|
306 } |
|
307 |
|
308 // ----------------------------------------------------------------------------- |
|
309 // CVcxHgMyVideosCategoryModelHandler::CategoryModifiedL() |
|
310 // MPX Collection calls this callback when single category is modified. |
|
311 // ----------------------------------------------------------------------------- |
|
312 // |
|
313 void CVcxHgMyVideosCategoryModelHandler::CategoryModifiedL( TMPXChangeEventType aEventType, |
|
314 TMPXItemId& aMpxItemId ) |
|
315 { |
|
316 IPTVLOGSTRING2_LOW_LEVEL( |
|
317 "MPX My Videos UI # CategoryModifiedL(event=%d)", aEventType ); |
|
318 |
|
319 switch ( aEventType ) |
|
320 { |
|
321 case EMPXItemModified: |
|
322 { |
|
323 TInt uiIndex = UiIndexFromMpxItemId( aMpxItemId ); |
|
324 UpdateCategoryListItemL( uiIndex ); |
|
325 iScroller.RefreshScreen( uiIndex ); |
|
326 } |
|
327 break; |
|
328 |
|
329 case EMPXItemInserted: |
|
330 case EMPXItemDeleted: |
|
331 default: |
|
332 { |
|
333 IPTVLOGSTRING_LOW_LEVEL( |
|
334 "MPX My Videos UI # CategoryModifiedL() Unexpected event!" ); |
|
335 } |
|
336 break; |
|
337 } |
|
338 } |
|
339 |
|
340 // ----------------------------------------------------------------------------- |
|
341 // CVcxHgMyVideosCategoryModelHandler::UpdateCategoryListL() |
|
342 // ----------------------------------------------------------------------------- |
|
343 // |
|
344 void CVcxHgMyVideosCategoryModelHandler::UpdateCategoryListL() |
|
345 { |
|
346 IPTVLOGSTRING_LOW_LEVEL( "MPX My Videos UI # UpdateCategoryListL() - Enter" ); |
|
347 |
|
348 if ( iCategoryList ) |
|
349 { |
|
350 TInt categoryCount = iCategoryList->Count(); |
|
351 |
|
352 MakeCategoryIdArray( categoryCount ); |
|
353 |
|
354 IPTVLOGSTRING2_LOW_LEVEL( |
|
355 "MPX My Videos UI # UpdateCategoryListL() - count = %d", categoryCount ); |
|
356 |
|
357 if ( iCategoryIdArray.Count() != iScroller.ItemCount() ) |
|
358 { |
|
359 iScroller.ResizeL( iCategoryIdArray.Count() ); |
|
360 } |
|
361 |
|
362 if ( iCategoryIdArray.Count() > 0 ) |
|
363 { |
|
364 for ( TInt i = 0; i < iCategoryIdArray.Count(); i++ ) |
|
365 { |
|
366 UpdateCategoryListItemL( i ); |
|
367 } |
|
368 if ( iScroller.SelectedIndex() < 0 || |
|
369 iScroller.SelectedIndex() >= iScroller.ItemCount() ) |
|
370 { |
|
371 iScroller.SetSelectedIndex( 0 ); |
|
372 } |
|
373 } |
|
374 |
|
375 // Refresh the whole list. |
|
376 iScroller.DrawDeferred(); |
|
377 } |
|
378 IPTVLOGSTRING_LOW_LEVEL( "MPX My Videos UI # UpdateCategoryListL() - Exit" ); |
|
379 } |
|
380 |
|
381 // ----------------------------------------------------------------------------- |
|
382 // CVcxHgMyVideosCategoryModelHandler::UpdateCategoryListItemL() |
|
383 // ----------------------------------------------------------------------------- |
|
384 // |
|
385 void CVcxHgMyVideosCategoryModelHandler::UpdateCategoryListItemL( TInt aListIndex ) |
|
386 { |
|
387 IPTVLOGSTRING2_LOW_LEVEL( |
|
388 "MPX My Videos UI # UpdateCategoryListItemL (index=%d)", aListIndex ); |
|
389 |
|
390 if( aListIndex >= 0 && |
|
391 aListIndex < iScroller.ItemCount() && |
|
392 aListIndex < iCategoryIdArray.Count() ) |
|
393 { |
|
394 CHgItem& listItem = iScroller.ItemL( aListIndex ); |
|
395 |
|
396 CMPXMedia* media( NULL ); |
|
397 media = (*iCategoryList)[ iCategoryIdArray[ aListIndex ] ]; |
|
398 |
|
399 HBufC* categoryName( NULL ); |
|
400 categoryName = GetCategoryNameLC( iCategoryIdArray[ aListIndex ] ); |
|
401 |
|
402 if ( categoryName && media ) |
|
403 { |
|
404 // Insert the category name into first row of list item. |
|
405 listItem.SetTitleL( *categoryName ); |
|
406 CleanupStack::PopAndDestroy( categoryName ); |
|
407 |
|
408 // Insert video count into second row of list item. |
|
409 HBufC* secondRow( NULL ); |
|
410 secondRow = FormatCategorySecondRowLC( *media ); |
|
411 listItem.SetTextL( *secondRow ); |
|
412 CleanupStack::PopAndDestroy( secondRow ); |
|
413 } |
|
414 else |
|
415 { |
|
416 // If category name or media was not found then |
|
417 // the whole list item should be removed. |
|
418 RemoveCategoryListItem( aListIndex ); |
|
419 } |
|
420 } |
|
421 |
|
422 IPTVLOGSTRING_LOW_LEVEL( |
|
423 "MPX My Videos UI # UpdateCategoryListItemL() - Exit" ); |
|
424 } |
|
425 |
|
426 // ----------------------------------------------------------------------------- |
|
427 // CVcxHgMyVideosCategoryModelHandler::RemoveCategoryListItem() |
|
428 // ----------------------------------------------------------------------------- |
|
429 // |
|
430 void CVcxHgMyVideosCategoryModelHandler::RemoveCategoryListItem( TInt aListIndex ) |
|
431 { |
|
432 if ( aListIndex >= 0 && aListIndex < iScroller.ItemCount() ) |
|
433 { |
|
434 iScroller.RemoveItem( aListIndex ); |
|
435 } |
|
436 } |
|
437 |
|
438 // ----------------------------------------------------------------------------- |
|
439 // CVcxHgMyVideosCategoryModelHandler::ResolveCategoryId() |
|
440 // ----------------------------------------------------------------------------- |
|
441 // |
|
442 TInt CVcxHgMyVideosCategoryModelHandler::ResolveCategoryId( TInt aScrollerIndex ) |
|
443 { |
|
444 TInt ret( -1 ); |
|
445 if ( aScrollerIndex <= iCategoryIdArray.Count() ) |
|
446 { |
|
447 ret = iCategoryIdArray[ aScrollerIndex ]; |
|
448 } |
|
449 return ret; |
|
450 } |
|
451 |
|
452 // ----------------------------------------------------------------------------- |
|
453 // CVcxHgMyVideosCategoryModelHandler::MakeCategoryIdArray() |
|
454 // ----------------------------------------------------------------------------- |
|
455 // |
|
456 void CVcxHgMyVideosCategoryModelHandler::MakeCategoryIdArray( TInt aCategoriesAvailable ) |
|
457 { |
|
458 IPTVLOGSTRING2_LOW_LEVEL( |
|
459 "MPX My Videos UI # MakeCategoryArray (number of categories=%d)", aCategoriesAvailable ); |
|
460 |
|
461 iCategoryIdArray.Reset(); |
|
462 |
|
463 for(TInt i = 0; i < aCategoriesAvailable; i++) |
|
464 { |
|
465 if( AcceptCategory( i ) ) |
|
466 { |
|
467 iCategoryIdArray.Append( i ); |
|
468 } |
|
469 } |
|
470 } |
|
471 |
|
472 // ----------------------------------------------------------------------------- |
|
473 // CVcxHgMyVideosCategoryModelHandler::AcceptCategory() |
|
474 // ----------------------------------------------------------------------------- |
|
475 // |
|
476 TBool CVcxHgMyVideosCategoryModelHandler::AcceptCategory( TInt aCategoryId ) |
|
477 { |
|
478 TBool ret(EFalse); |
|
479 switch ( aCategoryId ) |
|
480 { |
|
481 case KVcxMvcCategoryIdAll: |
|
482 case KVcxMvcCategoryIdDownloads: |
|
483 case KVcxMvcCategoryIdCaptured: |
|
484 case KVcxMvcCategoryIdOther: |
|
485 IPTVLOGSTRING2_LOW_LEVEL( |
|
486 "MPX My Videos UI # AcceptCategory() Accepted category: %d", aCategoryId ); |
|
487 ret = ETrue; |
|
488 break; |
|
489 default: |
|
490 IPTVLOGSTRING2_LOW_LEVEL( |
|
491 "MPX My Videos UI # AcceptCategory() Uknowns category: %d", aCategoryId ); |
|
492 break; |
|
493 } |
|
494 |
|
495 return ret; |
|
496 } |