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