|
1 /* |
|
2 * Copyright (c) 2008-2009 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: Generic selection popup class |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 /** |
|
22 * @internal reviewed 06/06/2007 by Dave Schofield |
|
23 * @internal reviewed 13/07/2007 by Aki Vanhatalo |
|
24 */ |
|
25 // INCLUDE FILES |
|
26 |
|
27 #include "glxmediaselectionpopup.h" |
|
28 |
|
29 #include <data_caging_path_literals.hrh>// for KDC_APP_RESOURCE_DIR |
|
30 |
|
31 #include <aknconsts.h> |
|
32 #include <AknIconArray.h> |
|
33 #include <aknlists.h> |
|
34 #include <AknQueryDialog.h> |
|
35 #include <avkon.mbg> |
|
36 #include <bautils.h> |
|
37 #include <eikclbd.h> |
|
38 #include <glxattributecontext.h> |
|
39 #include <glxattributeretriever.h> |
|
40 #include <glxcollectiongeneraldefs.h> |
|
41 #include <glxcommoncommandhandlers.rsg> |
|
42 #include <glxfetchcontextremover.h> |
|
43 #include <glxgeneraluiutilities.h> |
|
44 #include <glxlog.h> |
|
45 #include <glxresourceutilities.h> // for CGlxResourceUtilities |
|
46 #include <glxuistd.h> |
|
47 #include <mpxcollectionmessage.h> |
|
48 #include <mpxmediacontainerdefs.h> |
|
49 #include <mpxmediageneraldefs.h> |
|
50 #include <StringLoader.h> |
|
51 |
|
52 #include "glxcommandhandlernewmedia.h" |
|
53 |
|
54 |
|
55 _LIT(KUnselectedIconIndex, "1\t"); |
|
56 _LIT(KAlbumIconIndex, "2\t"); |
|
57 _LIT(KBlankIconIndex, "3\t"); // No icon |
|
58 |
|
59 _LIT(KGlxCommonCommandHandlerResource, "glxcommoncommandhandlers.rsc"); |
|
60 |
|
61 const TInt KMediaSelectionPopupMediaListHierarchyId = 0x2000A77A; |
|
62 const TInt KIconArrayGranularity = 2; |
|
63 const TInt KNewItemId = 12345; |
|
64 |
|
65 // --------------------------------------------------------------------------- |
|
66 // Constructor |
|
67 // --------------------------------------------------------------------------- |
|
68 // |
|
69 EXPORT_C CGlxMediaListAdaptor::CGlxMediaListAdaptor(const MGlxMediaList* aMediaList, TBool aMultiSelection) |
|
70 : iMediaList(aMediaList), iMultiSelection(aMultiSelection) |
|
71 { |
|
72 } |
|
73 |
|
74 // --------------------------------------------------------------------------- |
|
75 // CGlxMediaListAdaptor::SetEnabled() |
|
76 // --------------------------------------------------------------------------- |
|
77 // |
|
78 void CGlxMediaListAdaptor::SetEnabled(TBool aEnabled) |
|
79 { |
|
80 iEnabled = aEnabled; |
|
81 } |
|
82 |
|
83 // --------------------------------------------------------------------------- |
|
84 // CGlxMediaListAdaptor::MediaList() |
|
85 // --------------------------------------------------------------------------- |
|
86 // |
|
87 const MGlxMediaList* CGlxMediaListAdaptor::MediaList() |
|
88 { |
|
89 return iMediaList; |
|
90 } |
|
91 |
|
92 // --------------------------------------------------------------------------- |
|
93 // CGlxMediaListAdaptor::MultiSelectionEnabled() |
|
94 // --------------------------------------------------------------------------- |
|
95 // |
|
96 TBool CGlxMediaListAdaptor::MultiSelectionEnabled() |
|
97 { |
|
98 return iMultiSelection; |
|
99 } |
|
100 |
|
101 // --------------------------------------------------------------------------- |
|
102 // CGlxMediaListAdaptor::MdcaCount() |
|
103 // --------------------------------------------------------------------------- |
|
104 // |
|
105 EXPORT_C TInt CGlxMediaListAdaptor::MdcaCount() const |
|
106 { |
|
107 __ASSERT_DEBUG(iMediaList, Panic(EGlxPanicNullPointer)); |
|
108 if (iEnabled) |
|
109 { |
|
110 return iMediaList->Count(); |
|
111 } |
|
112 else |
|
113 { |
|
114 return 0; |
|
115 } |
|
116 } |
|
117 |
|
118 // --------------------------------------------------------------------------- |
|
119 // CGlxMediaListAdaptor::MdcaPoint() |
|
120 // --------------------------------------------------------------------------- |
|
121 // |
|
122 EXPORT_C TPtrC CGlxMediaListAdaptor::MdcaPoint(TInt aIndex) const |
|
123 { |
|
124 const TGlxMedia& item = iMediaList->Item(aIndex); |
|
125 |
|
126 TPtrC title = item.Title(); |
|
127 if ( item.IsStatic() || title.Length() == 0 ) |
|
128 { |
|
129 // The item is a static item or the item's title length is 0 |
|
130 iCurrentTitleString = KBlankIconIndex; |
|
131 } |
|
132 else |
|
133 { |
|
134 if (iMultiSelection) |
|
135 { |
|
136 iCurrentTitleString = KUnselectedIconIndex; |
|
137 } |
|
138 else |
|
139 { |
|
140 iCurrentTitleString = KAlbumIconIndex; |
|
141 } |
|
142 } |
|
143 |
|
144 // iCurrentTitleString contains a tab character |
|
145 iCurrentTitleString.Append(title.Left(KMaxTitleStringLength - iCurrentTitleString.Length())); |
|
146 |
|
147 return TPtrC(iCurrentTitleString); |
|
148 } |
|
149 |
|
150 // --------------------------------------------------------------------------- |
|
151 // CGlxSingleGraphicPopupMenuStyleListBox::IsVisible |
|
152 // --------------------------------------------------------------------------- |
|
153 // |
|
154 TBool CGlxSingleGraphicPopupMenuStyleListBox::IsVisible(TInt aItemIndex) |
|
155 { |
|
156 return (TopItemIndex() <= aItemIndex && aItemIndex <= BottomItemIndex()); |
|
157 } |
|
158 |
|
159 // --------------------------------------------------------------------------- |
|
160 // CGlxSingleGraphicPopupMenuStyleListBox::OfferKeyEventL() |
|
161 // --------------------------------------------------------------------------- |
|
162 // |
|
163 EXPORT_C TKeyResponse CGlxSingleGraphicPopupMenuStyleListBox:: |
|
164 OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType) |
|
165 { |
|
166 __ASSERT_DEBUG(dynamic_cast< CGlxMediaListAdaptor* >(Model()->ItemTextArray()), Panic(EGlxPanicCastFailed)); |
|
167 |
|
168 if (aKeyEvent.iCode == EKeyOK && iView) |
|
169 { |
|
170 CGlxMediaListAdaptor* mediaListAdaptor = static_cast <CGlxMediaListAdaptor*>(Model()->ItemTextArray()); |
|
171 |
|
172 if (mediaListAdaptor->MultiSelectionEnabled() && View()->CurrentItemIndex() >= 0 ) |
|
173 { |
|
174 const TGlxMedia& item = mediaListAdaptor->MediaList()->Item(View()->CurrentItemIndex()); |
|
175 // Reset the observer to populist |
|
176 SetListBoxObserver(iPopupList) ; |
|
177 if ( item.IsStatic() ) |
|
178 { |
|
179 iListBoxFlags &= (~EMultipleSelection); // turn off multiple selection |
|
180 } |
|
181 else |
|
182 { |
|
183 iListBoxFlags |= EMultipleSelection; // turn on multiple selection |
|
184 } |
|
185 } |
|
186 } |
|
187 |
|
188 return CAknSingleGraphicPopupMenuStyleListBox::OfferKeyEventL(aKeyEvent, aType); |
|
189 } |
|
190 |
|
191 // --------------------------------------------------------------------------- |
|
192 // CGlxSingleGraphicPopupMenuStyleListBox::HandleListBoxEventL() |
|
193 // --------------------------------------------------------------------------- |
|
194 // |
|
195 void CGlxSingleGraphicPopupMenuStyleListBox::HandleListBoxEventL (CEikListBox *aListBox, TListBoxEvent aEventType) |
|
196 { |
|
197 switch(aEventType) |
|
198 { |
|
199 case EEventItemClicked : |
|
200 { |
|
201 CGlxMediaListAdaptor* mediaListAdaptor = static_cast <CGlxMediaListAdaptor*>(Model()->ItemTextArray()); |
|
202 if (mediaListAdaptor->MultiSelectionEnabled() && View()->CurrentItemIndex() >= 0 ) |
|
203 { |
|
204 const TGlxMedia& item = mediaListAdaptor->MediaList()->Item(View()->CurrentItemIndex()); |
|
205 if ( item.IsStatic() ) |
|
206 { |
|
207 // when the user marks a non-static item and then clicks on |
|
208 // a static item without moving highlight, the control comes here. |
|
209 iListBoxFlags &= (~EMultipleSelection); // turn off multiple selection |
|
210 } |
|
211 else |
|
212 { |
|
213 iListBoxFlags |= EMultipleSelection; // turn on multiple selection |
|
214 |
|
215 TBool isMarked = View()->ItemIsSelected(View()->CurrentItemIndex()) ; |
|
216 (isMarked == (TBool) ETrue) ? ( View()->DeselectItem(View()->CurrentItemIndex()) ) |
|
217 : ( View()->SelectItemL(View()->CurrentItemIndex()) ) ; |
|
218 } |
|
219 } |
|
220 aListBox->DrawDeferred(); |
|
221 break ; |
|
222 } |
|
223 default : |
|
224 break ; |
|
225 } |
|
226 } |
|
227 |
|
228 // --------------------------------------------------------------------------- |
|
229 // CGlxSingleGraphicPopupMenuStyleListBox::HandlePointerEventL() |
|
230 // --------------------------------------------------------------------------- |
|
231 // |
|
232 void CGlxSingleGraphicPopupMenuStyleListBox::HandlePointerEventL(const TPointerEvent& aPointerEvent) |
|
233 { |
|
234 CGlxMediaListAdaptor* mediaListAdaptor = static_cast <CGlxMediaListAdaptor*>(Model()->ItemTextArray()); |
|
235 if (mediaListAdaptor->MultiSelectionEnabled()) |
|
236 { |
|
237 // Need to handle the case when the highlight is on one item |
|
238 // and the user clicks on another media item. The notification |
|
239 // of changed item index is received very late. In order to |
|
240 // handle this, checking if the index has changed. |
|
241 TInt changedItemIndex = -1; |
|
242 TInt itemIndex = View()->CurrentItemIndex(); |
|
243 TBool isItemChanged = View()->XYPosToItemIndex(aPointerEvent.iPosition, changedItemIndex); |
|
244 if (isItemChanged) |
|
245 { |
|
246 itemIndex = changedItemIndex; |
|
247 } |
|
248 const TGlxMedia& item = mediaListAdaptor->MediaList()->Item(itemIndex); |
|
249 if (item.IsStatic()) |
|
250 { |
|
251 // A static item is not markable. Turn off multiple selection |
|
252 // Set the listbox observer to default that is CAknPopupList |
|
253 // object, which will process it further. |
|
254 iListBoxFlags &= (~EMultipleSelection); |
|
255 SetListBoxObserver(iPopupList) ; |
|
256 } |
|
257 else |
|
258 { |
|
259 // Markable object. The event is handled in HandleListBoxEventL() |
|
260 // Set the listbox observer to the current object. |
|
261 SetListBoxObserver(this) ; |
|
262 } |
|
263 } |
|
264 CAknSingleGraphicPopupMenuStyleListBox::HandlePointerEventL(aPointerEvent) ; |
|
265 } |
|
266 |
|
267 // --------------------------------------------------------------------------- |
|
268 // CGlxSingleGraphicPopupMenuStyleListBox::SetPopupList() |
|
269 // --------------------------------------------------------------------------- |
|
270 // |
|
271 void CGlxSingleGraphicPopupMenuStyleListBox::SetPopupList(CAknPopupList* aPopupList) |
|
272 { |
|
273 iPopupList = aPopupList; |
|
274 } |
|
275 |
|
276 // --------------------------------------------------------------------------- |
|
277 // Constructor |
|
278 // --------------------------------------------------------------------------- |
|
279 // |
|
280 EXPORT_C CGlxMediaSelectionPopup::CGlxMediaSelectionPopup() |
|
281 : CActive(EPriorityStandard) |
|
282 { |
|
283 CActiveScheduler::Add(this); |
|
284 } |
|
285 |
|
286 // --------------------------------------------------------------------------- |
|
287 // CGlxMediaSelectionPopup::RunL() |
|
288 // --------------------------------------------------------------------------- |
|
289 // |
|
290 void CGlxMediaSelectionPopup::RunL() |
|
291 { |
|
292 // The media list adaptor is enabled after the popup list is invoked |
|
293 // to ensure that the popup list is laid out correctly. |
|
294 iMediaListAdaptor->SetEnabled(ETrue); |
|
295 AddNewMediaCreationItemL(); |
|
296 } |
|
297 |
|
298 // --------------------------------------------------------------------------- |
|
299 // CGlxMediaSelectionPopup::DoCancel() |
|
300 // --------------------------------------------------------------------------- |
|
301 // |
|
302 void CGlxMediaSelectionPopup::DoCancel() |
|
303 { |
|
304 // no implementation required |
|
305 } |
|
306 |
|
307 // --------------------------------------------------------------------------- |
|
308 // CGlxMediaSelectionPopup::ExecuteLD() |
|
309 // --------------------------------------------------------------------------- |
|
310 // |
|
311 EXPORT_C CMPXCollectionPath* CGlxMediaSelectionPopup::ExecuteLD(CMPXCollectionPath& aPath, |
|
312 TBool& aAccepted, |
|
313 TBool aMultiSelection, |
|
314 TBool aEnableContainerCreation, |
|
315 CMPXFilter* aFilter) |
|
316 { |
|
317 CleanupStack::PushL(this); // if something leaves delete 'this' object |
|
318 |
|
319 iEnableContainerCreation = aEnableContainerCreation; |
|
320 |
|
321 iCollectionId = TGlxMediaId(aPath.Id(0)); |
|
322 |
|
323 FetchTitlesL(); |
|
324 |
|
325 iMediaList = MGlxMediaList::InstanceL(aPath, KMediaSelectionPopupMediaListHierarchyId, aFilter); |
|
326 |
|
327 iMediaList->AddMediaListObserverL(this); |
|
328 |
|
329 iMediaListAdaptor = new(ELeave) CGlxMediaListAdaptor(iMediaList, aMultiSelection); |
|
330 |
|
331 |
|
332 SetupAttributeContextL(); |
|
333 |
|
334 AddResourceFileL(); |
|
335 ConstructPopupListL(aMultiSelection); |
|
336 InitIconsL(); |
|
337 |
|
338 CompleteSelf(); // This will cause RunL() to be called by the active scheduler. |
|
339 |
|
340 // Invoke the dialog. |
|
341 // The media list adaptor MdcaCount() method must return 0 at this point in order |
|
342 // for the popup to be displayed correctly. If MdcaCount() returns 1 then the popup will contain only |
|
343 // a single row. |
|
344 // iPopupList->ExecuteLD() starts a nested active scheduler so acvtive objects will be executed before |
|
345 // iPopupList->ExecuteLD() completes. |
|
346 aAccepted = iPopupList->ExecuteLD(); |
|
347 |
|
348 if (iListBox->CurrentItemIndex() < 0) |
|
349 { |
|
350 // There is no current item therefore there is nothing to select |
|
351 // Fix for error ID: ERBS-7BSKFV Application crashes if user attempts to add a tag when in full screen view. |
|
352 aAccepted = EFalse; |
|
353 } |
|
354 |
|
355 iMediaList->RemoveMediaListObserver(this); // We no longer require any callbacks from the media list |
|
356 |
|
357 |
|
358 CMPXCollectionPath* path = NULL; |
|
359 if (aAccepted) |
|
360 { |
|
361 |
|
362 if(iMediaList->Item(iListBox->CurrentItemIndex()).IsStatic()) |
|
363 { |
|
364 |
|
365 CGlxCommandHandlerNewMedia* commandHandlerNewMedia = CGlxCommandHandlerNewMedia::NewL(this); |
|
366 TGlxMediaId newMediaId; |
|
367 TInt error = commandHandlerNewMedia->ExecuteLD(newMediaId); |
|
368 if (error == KErrNone) |
|
369 { |
|
370 path = CMPXCollectionPath::NewL(aPath); |
|
371 CleanupStack::PopAndDestroy(this); |
|
372 CleanupStack::PushL(path); |
|
373 path->AppendL(newMediaId.Value()); |
|
374 CleanupStack::Pop(path); |
|
375 } |
|
376 else if (error == KErrCancel) |
|
377 { |
|
378 // The user has cancelled the popup list |
|
379 aAccepted = EFalse; |
|
380 CleanupStack::PopAndDestroy(this); |
|
381 } |
|
382 else |
|
383 { |
|
384 // The error is neither KErrNone or KErrCancel, leave. |
|
385 User::Leave(error); |
|
386 } |
|
387 |
|
388 } |
|
389 else |
|
390 { |
|
391 iMediaList->SetFocusL(NGlxListDefs::EAbsolute, iListBox->CurrentItemIndex()); |
|
392 |
|
393 const CListBoxView::CSelectionIndexArray* selectionIndices = |
|
394 iListBox->SelectionIndexes(); |
|
395 |
|
396 TInt count = selectionIndices->Count(); |
|
397 for (TInt i = 0; i < count; i++) |
|
398 { |
|
399 iMediaList->SetSelectedL(selectionIndices->At(i), ETrue); |
|
400 } |
|
401 |
|
402 path = iMediaList->PathLC( NGlxListDefs::EPathFocusOrSelection ); |
|
403 CleanupStack::Pop(path); |
|
404 CleanupStack::PopAndDestroy(this); |
|
405 } |
|
406 } |
|
407 else |
|
408 { |
|
409 CleanupStack::PopAndDestroy(this); |
|
410 } |
|
411 |
|
412 return path; |
|
413 } |
|
414 |
|
415 // --------------------------------------------------------------------------- |
|
416 // CGlxMediaSelectionPopup::ListBoxItemsChanged() |
|
417 // --------------------------------------------------------------------------- |
|
418 // |
|
419 void CGlxMediaSelectionPopup::ListBoxItemsChanged( CEikListBox* /*aListBox*/ ) |
|
420 { |
|
421 // Don't do anything. |
|
422 } |
|
423 |
|
424 // ----------------------------------------------------------------------------- |
|
425 // Destructor |
|
426 // ----------------------------------------------------------------------------- |
|
427 // |
|
428 CGlxMediaSelectionPopup::~CGlxMediaSelectionPopup() |
|
429 { |
|
430 Cancel(); |
|
431 |
|
432 delete iMediaListAdaptor; |
|
433 delete iListBox; |
|
434 |
|
435 if (iResourceOffset) |
|
436 { |
|
437 CCoeEnv::Static()->DeleteResourceFile(iResourceOffset); |
|
438 } |
|
439 |
|
440 if (iMediaList) |
|
441 { |
|
442 if (iAttributeContext) |
|
443 { |
|
444 iMediaList->RemoveContext(iAttributeContext); |
|
445 } |
|
446 iMediaList->RemoveMediaListObserver(this); // This is required in case ExecuteLD() left. |
|
447 |
|
448 iMediaList->Close(); |
|
449 } |
|
450 |
|
451 delete iAttributeContext; |
|
452 delete iSelectMediaPopupTitle; |
|
453 delete iNewMediaItemTitle; |
|
454 } |
|
455 |
|
456 // ----------------------------------------------------------------------------- |
|
457 // CGlxMediaSelectionPopup::HandleItemAddedL() |
|
458 // ----------------------------------------------------------------------------- |
|
459 // |
|
460 void CGlxMediaSelectionPopup::HandleItemAddedL( TInt aStartIndex, |
|
461 TInt aEndIndex, MGlxMediaList* aList ) |
|
462 { |
|
463 // The call to HandleItemAdditionL() should be deferred if all of the new items |
|
464 // don't have title attributes as unnecessary calls to HandleItemAdditionL will |
|
465 // cause the dialog to flicker. |
|
466 if (iListBox) |
|
467 { |
|
468 TBool handleItemAdditionRequired = EFalse; |
|
469 for (TInt i = aStartIndex; i <= aEndIndex; i++) |
|
470 { |
|
471 TGlxMedia item = aList->Item(i); |
|
472 if (item.Title().Length() > 0) |
|
473 // The title length is greater than 0, i.e. there is a title. |
|
474 { |
|
475 handleItemAdditionRequired = ETrue; |
|
476 break; |
|
477 } |
|
478 } |
|
479 |
|
480 if (handleItemAdditionRequired) |
|
481 { |
|
482 iListBox->HandleItemAdditionL(); |
|
483 } |
|
484 else |
|
485 { |
|
486 iHandleItemAdditionRequired = ETrue; // defer the call until we have title attributes |
|
487 } |
|
488 } |
|
489 |
|
490 CEikButtonGroupContainer* cbaContainer = iPopupList->ButtonGroupContainer(); |
|
491 cbaContainer->SetCommandSetL(R_GLX_SOFTKEYS_OK_CANCEL); |
|
492 cbaContainer->DrawDeferred(); |
|
493 |
|
494 ///@todo if required: update the existing selection when items are added |
|
495 } |
|
496 |
|
497 // ----------------------------------------------------------------------------- |
|
498 // CGlxMediaSelectionPopup::HandleMediaL() |
|
499 // ----------------------------------------------------------------------------- |
|
500 // |
|
501 void CGlxMediaSelectionPopup::HandleMediaL( TInt /*aListIndex*/, |
|
502 MGlxMediaList* /*aList*/ ) |
|
503 { |
|
504 // Don't do anything. |
|
505 } |
|
506 |
|
507 // ----------------------------------------------------------------------------- |
|
508 // CGlxMediaSelectionPopup::HandleItemRemovedL() |
|
509 // ----------------------------------------------------------------------------- |
|
510 // |
|
511 void CGlxMediaSelectionPopup::HandleItemRemovedL( TInt /*aStartIndex*/, |
|
512 TInt /*aEndIndex*/, MGlxMediaList* /*aList*/ ) |
|
513 { |
|
514 if (iListBox) |
|
515 { |
|
516 iListBox->HandleItemRemovalL(); |
|
517 } |
|
518 } |
|
519 |
|
520 // ----------------------------------------------------------------------------- |
|
521 // CGlxMediaSelectionPopup::HandleItemModifiedL() |
|
522 // ----------------------------------------------------------------------------- |
|
523 // |
|
524 void CGlxMediaSelectionPopup::HandleItemModifiedL( |
|
525 const RArray<TInt>& aItemIndexes, MGlxMediaList* /*aList*/ ) |
|
526 { |
|
527 if (iListBox) |
|
528 { |
|
529 for (TInt i = 0; i < aItemIndexes.Count(); i++) |
|
530 { |
|
531 if (iListBox->IsVisible(aItemIndexes[i])) |
|
532 { |
|
533 iListBox->RedrawItem(aItemIndexes[i]); |
|
534 } |
|
535 } |
|
536 } |
|
537 } |
|
538 |
|
539 // ----------------------------------------------------------------------------- |
|
540 // CGlxMediaSelectionPopup::HandleAttributesAvailableL() |
|
541 // ----------------------------------------------------------------------------- |
|
542 // |
|
543 void CGlxMediaSelectionPopup::HandleAttributesAvailableL( TInt aItemIndex, |
|
544 const RArray<TMPXAttribute>& /*aAttributes*/, MGlxMediaList* /*aList*/ ) |
|
545 { |
|
546 if (iListBox) |
|
547 { |
|
548 if (iHandleItemAdditionRequired) |
|
549 { |
|
550 iListBox->HandleItemAdditionL(); |
|
551 iHandleItemAdditionRequired = EFalse; |
|
552 } |
|
553 if(iListBox->IsVisible(aItemIndex)) |
|
554 { |
|
555 iListBox->RedrawItem(aItemIndex); |
|
556 } |
|
557 } |
|
558 } |
|
559 |
|
560 // ----------------------------------------------------------------------------- |
|
561 // CGlxMediaSelectionPopup::HandleFocusChangedL() |
|
562 // ----------------------------------------------------------------------------- |
|
563 // |
|
564 void CGlxMediaSelectionPopup::HandleFocusChangedL( |
|
565 NGlxListDefs::TFocusChangeType /*aType*/, TInt /*aNewIndex*/, |
|
566 TInt /*aOldIndex*/, MGlxMediaList* /*aList*/ ) |
|
567 { |
|
568 // Don't do anything. |
|
569 } |
|
570 |
|
571 // ----------------------------------------------------------------------------- |
|
572 // CGlxMediaSelectionPopup::HandleItemSelectedL() |
|
573 // ----------------------------------------------------------------------------- |
|
574 // |
|
575 void CGlxMediaSelectionPopup::HandleItemSelectedL( TInt /*aIndex*/, |
|
576 TBool /*aSelected*/, MGlxMediaList* /*aList*/ ) |
|
577 { |
|
578 // Don't do anything. |
|
579 } |
|
580 |
|
581 // ----------------------------------------------------------------------------- |
|
582 // CGlxMediaSelectionPopup::HandleMessageL() |
|
583 // ----------------------------------------------------------------------------- |
|
584 // |
|
585 void CGlxMediaSelectionPopup::HandleMessageL( const CMPXMessage& /*aMessage*/, |
|
586 MGlxMediaList* /*aList*/ ) |
|
587 { |
|
588 // Don't do anything. |
|
589 } |
|
590 |
|
591 // ----------------------------------------------------------------------------- |
|
592 // CGlxMediaSelectionPopup::HandleError() |
|
593 // ----------------------------------------------------------------------------- |
|
594 // |
|
595 void CGlxMediaSelectionPopup::HandleError( TInt /*aError*/ ) |
|
596 { |
|
597 ///@todo implement |
|
598 } |
|
599 |
|
600 // ----------------------------------------------------------------------------- |
|
601 // CGlxMediaSelectionPopup::MediaList() |
|
602 // ----------------------------------------------------------------------------- |
|
603 // |
|
604 MGlxMediaList& CGlxMediaSelectionPopup::MediaList() |
|
605 { |
|
606 // Provides a media list to CGlxCommandHandlerNewMedia |
|
607 return *iMediaList; |
|
608 } |
|
609 |
|
610 // ----------------------------------------------------------------------------- |
|
611 // CGlxMediaSelectionPopup::AddResourceFileL() |
|
612 // ----------------------------------------------------------------------------- |
|
613 // |
|
614 void CGlxMediaSelectionPopup::AddResourceFileL() |
|
615 { |
|
616 // Load resource |
|
617 TParse parse; |
|
618 parse.Set(KGlxCommonCommandHandlerResource, &KDC_APP_RESOURCE_DIR, NULL); |
|
619 TFileName resourceFile; |
|
620 resourceFile.Append(parse.FullName()); |
|
621 CGlxResourceUtilities::GetResourceFilenameL(resourceFile); |
|
622 iResourceOffset = CCoeEnv::Static()->AddResourceFileL(resourceFile); |
|
623 } |
|
624 |
|
625 // ----------------------------------------------------------------------------- |
|
626 // CGlxMediaSelectionPopup::SetupAttributeContextL() |
|
627 // ----------------------------------------------------------------------------- |
|
628 // |
|
629 void CGlxMediaSelectionPopup::SetupAttributeContextL() |
|
630 { |
|
631 iAttributeContext = new (ELeave) CGlxAttributeContext(&iIterator); |
|
632 iAttributeContext->AddAttributeL(KMPXMediaGeneralTitle); |
|
633 iMediaList->AddContextL( iAttributeContext, KGlxFetchContextPriorityLow ); |
|
634 } |
|
635 |
|
636 // ----------------------------------------------------------------------------- |
|
637 // CGlxMediaSelectionPopup::SetupAttributeContextL() |
|
638 // ----------------------------------------------------------------------------- |
|
639 // |
|
640 void CGlxMediaSelectionPopup::InitIconsL() |
|
641 { |
|
642 CAknIconArray* iconArray = new (ELeave) CAknIconArray(KIconArrayGranularity); |
|
643 CleanupStack::PushL(iconArray); |
|
644 |
|
645 // Sets graphics as ListBox icon. |
|
646 iListBox->ItemDrawer()->ColumnData()->SetIconArray(iconArray); |
|
647 |
|
648 CleanupStack::Pop(iconArray); // iconArray |
|
649 |
|
650 ///@todo use mgallery icons when available |
|
651 MAknsSkinInstance* skin = AknsUtils::SkinInstance(); |
|
652 CGulIcon* icon = AknsUtils::CreateGulIconL( |
|
653 skin, |
|
654 KAknsIIDQgnPropCheckboxOn, |
|
655 KAvkonBitmapFile, |
|
656 EMbmAvkonQgn_prop_checkbox_on, |
|
657 EMbmAvkonQgn_prop_checkbox_on_mask ); |
|
658 CleanupStack::PushL(icon); |
|
659 iconArray->AppendL(icon); |
|
660 CleanupStack::Pop(icon); |
|
661 |
|
662 icon = AknsUtils::CreateGulIconL( |
|
663 skin, |
|
664 KAknsIIDQgnPropCheckboxOff, |
|
665 KAvkonBitmapFile, |
|
666 EMbmAvkonQgn_prop_checkbox_off, |
|
667 EMbmAvkonQgn_prop_checkbox_off_mask ); |
|
668 CleanupStack::PushL(icon); |
|
669 iconArray->AppendL(icon); |
|
670 CleanupStack::Pop(icon); |
|
671 |
|
672 iconArray->AppendFromResourceL(R_GLX_ALBUM_SELECTION_ICONS); |
|
673 |
|
674 ///@todo Find a more elegant way of not painting an icon. |
|
675 CFbsBitmap* bitmap = new (ELeave) CFbsBitmap; |
|
676 CleanupStack::PushL(bitmap); |
|
677 icon = CGulIcon::NewL(bitmap); |
|
678 CleanupStack::Pop(bitmap); |
|
679 CleanupStack::PushL(icon); |
|
680 iconArray->AppendL(icon); |
|
681 CleanupStack::Pop(icon); |
|
682 } |
|
683 |
|
684 // ----------------------------------------------------------------------------- |
|
685 // CGlxMediaSelectionPopup::AddNewMediaCreationItemL() |
|
686 // ----------------------------------------------------------------------------- |
|
687 // |
|
688 void CGlxMediaSelectionPopup::AddNewMediaCreationItemL() |
|
689 { |
|
690 if (iEnableContainerCreation) |
|
691 { |
|
692 CGlxMedia* newMediaCreationStaticItem = new (ELeave) CGlxMedia(TGlxMediaId(KNewItemId)); |
|
693 CleanupStack::PushL(newMediaCreationStaticItem); |
|
694 __ASSERT_DEBUG(iNewMediaItemTitle, Panic(EGlxPanicNullPointer)); |
|
695 newMediaCreationStaticItem->SetTextValueL(KMPXMediaGeneralTitle, *iNewMediaItemTitle); |
|
696 iMediaList->AddStaticItemL(newMediaCreationStaticItem, NGlxListDefs::EInsertFirst); |
|
697 CleanupStack::Pop(newMediaCreationStaticItem); |
|
698 } |
|
699 } |
|
700 |
|
701 // ----------------------------------------------------------------------------- |
|
702 // CGlxMediaSelectionPopup::CompleteSelf() |
|
703 // ----------------------------------------------------------------------------- |
|
704 // |
|
705 void CGlxMediaSelectionPopup::CompleteSelf() |
|
706 { |
|
707 TRequestStatus* status=&iStatus; |
|
708 User::RequestComplete(status, KErrNone); |
|
709 SetActive(); |
|
710 } |
|
711 |
|
712 // ----------------------------------------------------------------------------- |
|
713 // CGlxMediaSelectionPopup::FetchTitlesL() |
|
714 // ----------------------------------------------------------------------------- |
|
715 // |
|
716 void CGlxMediaSelectionPopup::FetchTitlesL() |
|
717 { |
|
718 CMPXCollectionPath* path = CMPXCollectionPath::NewL(); |
|
719 CleanupStack::PushL(path); |
|
720 |
|
721 MGlxMediaList* rootList = MGlxMediaList::InstanceL(*path); |
|
722 CleanupClosePushL(*rootList); |
|
723 |
|
724 TGlxSpecificIdIterator iter(KGlxIdSpaceIdRoot, iCollectionId); |
|
725 CGlxAttributeContext* attributeContext = new (ELeave) CGlxAttributeContext(&iter); |
|
726 CleanupStack::PushL(attributeContext); |
|
727 attributeContext->AddAttributeL(KGlxMediaCollectionPluginSpecificNewMediaItemTitle); |
|
728 attributeContext->AddAttributeL(KGlxMediaCollectionPluginSpecificSelectMediaPopupTitle); |
|
729 rootList->AddContextL(attributeContext, KGlxFetchContextPriorityBlocking); |
|
730 |
|
731 // TGlxContextRemover will remove the context when it goes out of scope |
|
732 // Used here to avoid a trap and still have safe cleanup |
|
733 TGlxFetchContextRemover contextRemover(attributeContext, *rootList); |
|
734 CleanupClosePushL( contextRemover ); |
|
735 User::LeaveIfError(GlxAttributeRetriever::RetrieveL(*attributeContext, *rootList, EFalse)); |
|
736 // context off the list |
|
737 CleanupStack::PopAndDestroy( &contextRemover ); |
|
738 |
|
739 TInt index = rootList->Index(KGlxIdSpaceIdRoot, iCollectionId); |
|
740 |
|
741 __ASSERT_DEBUG(index > KErrNotFound, Panic(EGlxPanicRequiredItemNotFound)); |
|
742 TGlxMedia item = rootList->Item(index); |
|
743 |
|
744 const CGlxMedia* media = item.Properties(); |
|
745 if (media) |
|
746 { |
|
747 iNewMediaItemTitle = media->ValueText(KGlxMediaCollectionPluginSpecificNewMediaItemTitle).AllocL(); |
|
748 iSelectMediaPopupTitle = media->ValueText(KGlxMediaCollectionPluginSpecificSelectMediaPopupTitle).AllocL(); |
|
749 } |
|
750 |
|
751 |
|
752 CleanupStack::PopAndDestroy(attributeContext); |
|
753 CleanupStack::PopAndDestroy(rootList); |
|
754 CleanupStack::PopAndDestroy(path); |
|
755 } |
|
756 |
|
757 // ----------------------------------------------------------------------------- |
|
758 // CGlxMediaSelectionPopup::ConstructPopupListL() |
|
759 // ----------------------------------------------------------------------------- |
|
760 // |
|
761 void CGlxMediaSelectionPopup::ConstructPopupListL(TBool aMultiSelection) |
|
762 { |
|
763 // create the list box |
|
764 iListBox = new (ELeave) CGlxSingleGraphicPopupMenuStyleListBox; |
|
765 |
|
766 // create the popup list |
|
767 iPopupList = CAknPopupList::NewL(iListBox, R_AVKON_SOFTKEYS_CANCEL); |
|
768 |
|
769 // set the title of the popup |
|
770 __ASSERT_DEBUG(iSelectMediaPopupTitle, Panic(EGlxPanicNullPointer)); |
|
771 |
|
772 iPopupList->SetTitleL(*iSelectMediaPopupTitle); |
|
773 |
|
774 iListBox ->ConstructL(iPopupList, aMultiSelection ? EAknListBoxMultiselectionList : EAknListBoxMenuList); |
|
775 iListBox->CreateScrollBarFrameL(); |
|
776 iListBox->ScrollBarFrame()->SetScrollBarVisibilityL( |
|
777 CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto ); |
|
778 // create the listbox model |
|
779 iListBox->Model()->SetItemTextArray(iMediaListAdaptor); |
|
780 iListBox->View()->CalcBottomItemIndex(); |
|
781 iListBox->Model()->SetOwnershipType(ELbmDoesNotOwnItemArray); |
|
782 |
|
783 // Store the pointer of AknPopupList |
|
784 iListBox->SetPopupList(iPopupList); |
|
785 } |
|
786 |