photosgallery/viewframework/views/viewbase/src/glxmedialistviewbase.cpp
changeset 0 4e91876724a2
child 2 7d9067c6fcb1
equal deleted inserted replaced
-1:000000000000 0:4e91876724a2
       
     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:    Media List View Base
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #include "glxmedialistviewbase.h"
       
    22 
       
    23 #include <mpxcollectionutility.h>
       
    24 #include <glxcommandhandler.h>
       
    25 #include <glxassert.h>
       
    26 #include <glxgallery.hrh>
       
    27 #include <glxattributecontext.h>
       
    28 #include <glxuistd.h>
       
    29 #include <glxfetchcontextremover.h>
       
    30 #include <glxcommandhandlers.hrh>
       
    31 #include <AknUtils.h>
       
    32 #include <glxtracer.h>                         // For Logs
       
    33 #include <glxattributeretriever.h>
       
    34 #include "glxtitlefetcher.h"
       
    35 #include "glxmedialistfactory.h"
       
    36 #include "mglxmedialist.h"
       
    37 
       
    38  _LIT(KBlankTitle,"    ");
       
    39 
       
    40 // -----------------------------------------------------------------------------
       
    41 // Constructor
       
    42 // -----------------------------------------------------------------------------
       
    43 //	
       
    44 EXPORT_C CGlxMediaListViewBase::CGlxMediaListViewBase()
       
    45     {
       
    46     }
       
    47 
       
    48 // -----------------------------------------------------------------------------
       
    49 // MLViewBaseConstructL
       
    50 // -----------------------------------------------------------------------------
       
    51 //	
       
    52 EXPORT_C void CGlxMediaListViewBase::MLViewBaseConstructL(
       
    53         MGlxMediaListFactory* aMediaListFactory, 
       
    54         const TDesC& aTitle,TBool aEnableMiddleSoftkey)
       
    55     {
       
    56     iMediaListFactory = aMediaListFactory;
       
    57     iCollectionUtility = MMPXCollectionUtility::NewL(NULL, KMcModeDefault);
       
    58     iEnableMidddleSoftkey = aEnableMiddleSoftkey; 
       
    59 
       
    60     iSelectionIterator.SetRange(KMaxTInt);
       
    61     iPreloadContextForCommandHandlers  = new (ELeave) CGlxAttributeContext(&iSelectionIterator);
       
    62     
       
    63     if(aTitle.Length() > 0)
       
    64         {
       
    65         iFixedTitle = aTitle.AllocL();
       
    66         }
       
    67     
       
    68     
       
    69     if(iUiUtility->IsPenSupported())
       
    70         {
       
    71         // Responsible for controlling the ui states of toolbar
       
    72         // Create ToolbarController only for touch supported devices.
       
    73            iToolbarControl = CGlxToolbarController::NewL();
       
    74         }
       
    75     else
       
    76         {
       
    77         // Responsible for controlling the middle softkey if enabled.
       
    78         // Create Middle Softkey Controller only for non-touch devices
       
    79             iCbaControl = CGlxMSKController::NewL();
       
    80         }   
       
    81     }
       
    82 
       
    83 // -----------------------------------------------------------------------------
       
    84 // Destructor
       
    85 // -----------------------------------------------------------------------------
       
    86 //	
       
    87 EXPORT_C CGlxMediaListViewBase::~CGlxMediaListViewBase()
       
    88     {
       
    89     CloseMediaList();
       
    90 
       
    91     if ( iCollectionUtility )
       
    92         {
       
    93         iCollectionUtility->Close();
       
    94         }
       
    95 
       
    96     delete iFixedTitle;
       
    97     delete iTitleFetcher;
       
    98     delete iPreloadContextForCommandHandlers;
       
    99         
       
   100     if( iCbaControl )
       
   101         {
       
   102         delete iCbaControl;                                          
       
   103         }
       
   104     
       
   105     if( iToolbarControl )
       
   106         {
       
   107         delete iToolbarControl;        
       
   108         }    
       
   109     }
       
   110 
       
   111 // -----------------------------------------------------------------------------
       
   112 // MediaList
       
   113 // -----------------------------------------------------------------------------
       
   114 //	
       
   115 EXPORT_C MGlxMediaList& CGlxMediaListViewBase::MediaList()
       
   116     {
       
   117     GLX_ASSERT_ALWAYS( iMediaList, Panic( EGlxPanicNullMediaList ),
       
   118                        "Media list has been closed" );
       
   119     return *iMediaList;
       
   120     }
       
   121 
       
   122 // -----------------------------------------------------------------------------
       
   123 // DoViewActivateL
       
   124 // -----------------------------------------------------------------------------
       
   125 //	
       
   126 EXPORT_C void CGlxMediaListViewBase::DoViewActivateL(
       
   127         const TVwsViewId& aPrevViewId, TUid aCustomMessageId, 
       
   128         const TDesC8& aCustomMessage)
       
   129     {
       
   130     TRACER ("CGlxMediaListViewBase::DoViewActivateL()");
       
   131     iUiUtility->SetAppOrientationL( EGlxOrientationDefault );	
       
   132     if ( iMediaList )
       
   133         {
       
   134         // may need to refresh the media list if it has got out of sync
       
   135         // with the current navigational state, e.g. when jumping back two views
       
   136         // instead of just one, the intermediate view's media list will not have
       
   137         // been closed so if that view is subsequently re-opened its media list
       
   138         // could contain out of date items
       
   139         CMPXCollectionPath* path = iMediaList->PathLC();
       
   140         // current navigational state
       
   141         CMPXCollectionPath* navigationalState = 
       
   142             iCollectionUtility->Collection().PathL();
       
   143         CleanupStack::PushL( navigationalState );
       
   144         // current node id in UI Hierarchy
       
   145         TMPXItemId navStateNodeId = 
       
   146             navigationalState->Id( navigationalState->Levels() - 2 );
       
   147         // current media list's node id in UI hierarchy
       
   148         TMPXItemId mediaListNodeId = path->Id( path->Levels() - 2 );
       
   149         
       
   150         if ( mediaListNodeId != navStateNodeId )
       
   151             {
       
   152             // the node ids are out of synch so close the media list
       
   153             // for it to be recreated later on
       
   154             CloseMediaList();
       
   155             }
       
   156         CleanupStack::PopAndDestroy( navigationalState );
       
   157         CleanupStack::PopAndDestroy( path );        
       
   158         }
       
   159     
       
   160     if (!iMediaList && iMediaListFactory)
       
   161         {
       
   162         iMediaList = &iMediaListFactory->CreateMediaListL(*iCollectionUtility);
       
   163     	iMediaList->AddContextL(iPreloadContextForCommandHandlers, 0);
       
   164         }
       
   165 
       
   166     if(iFixedTitle)
       
   167         {
       
   168         // If there is a fixed title, set it
       
   169         SetTitleL(*iFixedTitle);
       
   170         }
       
   171     else
       
   172         {
       
   173         // else obtain a title from the media list
       
   174         // First set a blank title to claim the title space
       
   175         SetTitleL(KBlankTitle);
       
   176 
       
   177         CMPXCollectionPath* path = iMediaList->PathLC( NGlxListDefs::EPathParent );
       
   178         iTitleFetcher = CGlxTitleFetcher::NewL(*this, path);
       
   179         CleanupStack::PopAndDestroy(path);
       
   180         }
       
   181    
       
   182     //Allow the MskController to observe medialist everytime a view with a valid
       
   183     //medialist becomes active
       
   184     if( iCbaControl && iMediaList && Cba()&& iEnableMidddleSoftkey )
       
   185         {
       
   186         CMPXCollectionPath* navigationalState = iCollectionUtility->Collection().PathL();
       
   187         CleanupStack::PushL(navigationalState);
       
   188         iCbaControl->AddToObserverL(*iMediaList,Cba()); 
       
   189         if(!(1 == navigationalState->Levels())) // Checking for the main list view
       
   190           {
       
   191             iCbaControl->SetStatusOnViewActivationL(iMediaList);
       
   192             }
       
   193         else
       
   194             {
       
   195             iCbaControl->SetMainStatusL();
       
   196             }
       
   197         CleanupStack::PopAndDestroy(navigationalState);
       
   198         }
       
   199     
       
   200     //Allow the toolbarController to observe medialist everytime a view with a valid
       
   201     //medialist becomes active
       
   202     if( Toolbar() && iToolbarControl )
       
   203         {
       
   204         iToolbarControl->AddToObserverL(*iMediaList, Toolbar());
       
   205         iToolbarControl->SetStatusOnViewActivationL(iMediaList);
       
   206         }    
       
   207   
       
   208     DoMLViewActivateL(aPrevViewId, aCustomMessageId, aCustomMessage);
       
   209     }
       
   210 
       
   211 // -----------------------------------------------------------------------------
       
   212 // DoViewDeactivate
       
   213 // -----------------------------------------------------------------------------
       
   214 //	
       
   215 EXPORT_C void CGlxMediaListViewBase::DoViewDeactivate()
       
   216     {
       
   217     DoMLViewDeactivate();
       
   218     if( iCbaControl && iMediaList && Cba() )
       
   219         {
       
   220         //Remove Mskcontroller from medialist observer
       
   221         iCbaControl->RemoveFromObserver(*iMediaList);
       
   222         }
       
   223     if( Toolbar() && iToolbarControl )
       
   224         {
       
   225         //Remove Toolbarcontroller from medialist observer
       
   226         iToolbarControl->RemoveFromObserver(*iMediaList);
       
   227         }    
       
   228     
       
   229     // Only close the medialist if navigating backwards
       
   230     if ( iUiUtility->ViewNavigationDirection() == EGlxNavigationBackwards )
       
   231         {
       
   232         CloseMediaList();
       
   233         }
       
   234 
       
   235     delete iTitleFetcher;
       
   236     iTitleFetcher = NULL;
       
   237     }
       
   238 
       
   239 // -----------------------------------------------------------------------------
       
   240 // CGlxMediaListViewBase::FetchAttributesL
       
   241 // -----------------------------------------------------------------------------
       
   242 //	
       
   243 EXPORT_C void CGlxMediaListViewBase::FetchAttributesL()
       
   244 	{
       
   245 	FetchAttributesL(EFalse);
       
   246 	}
       
   247 
       
   248 // -----------------------------------------------------------------------------
       
   249 // CGlxMediaListViewBase::FetchAttributesForCommandL
       
   250 // -----------------------------------------------------------------------------
       
   251 //	
       
   252 EXPORT_C void CGlxMediaListViewBase::FetchAttributesForCommandL(TInt aCommand)
       
   253 	{
       
   254 	FetchAttributesL(ETrue, aCommand);
       
   255 	}
       
   256 
       
   257 // -----------------------------------------------------------------------------
       
   258 // SetToolbarStateL
       
   259 // -----------------------------------------------------------------------------
       
   260 //
       
   261 EXPORT_C void CGlxMediaListViewBase::SetToolbarStateL()
       
   262     {
       
   263     TRACER("CGlxMediaListViewBase::SetToolbarStateL");
       
   264     
       
   265     if( iToolbarControl && iMediaList )
       
   266         {
       
   267         iToolbarControl->SetStatusL(iMediaList);
       
   268         }
       
   269     }
       
   270 
       
   271 // -----------------------------------------------------------------------------
       
   272 // CGlxMediaListViewBase::FetchAttributesL
       
   273 // -----------------------------------------------------------------------------
       
   274 //	
       
   275 void CGlxMediaListViewBase::FetchAttributesL(TBool aFilterUsingCommandId, 
       
   276 		                                                   TInt aCommandId)
       
   277 	{
       
   278 	TRACER("CGlxMediaListViewBase::FetchAttributesL");
       
   279 
       
   280     TGlxSelectionIterator iterator;
       
   281     CGlxAttributeContext* attributeContext = new(ELeave) CGlxAttributeContext(&iterator);
       
   282     CleanupStack::PushL(attributeContext);
       
   283     
       
   284 	TInt commandHandlerCount = iCommandHandlerList.Count();
       
   285 	for (TInt i = 0; i < commandHandlerCount; i++)
       
   286 		{
       
   287 		AddAttributesToContextL(*attributeContext, iCommandHandlerList[i], ETrue, aFilterUsingCommandId, aCommandId);
       
   288 		}
       
   289 	
       
   290 	if (attributeContext->AttributeCount())
       
   291 		{
       
   292 		// Check if media attributes are already fetched.
       
   293 		// If media item is NULL, Cancel the previous pending request
       
   294 		MediaList().CancelPreviousRequests();
       
   295 				
       
   296 	    MediaList().AddContextL(attributeContext, KGlxFetchContextPriorityCommandHandlerOpening );
       
   297 	    
       
   298     	// TGlxContextRemover will remove the context when it goes out of scope
       
   299     	// Used here to avoid a trap and still have safe cleanup
       
   300 	    	TGlxFetchContextRemover contextRemover(attributeContext, MediaList());
       
   301         // put to cleanupstack as cleanupstack is emptied before stack objects
       
   302         // are deleted
       
   303         CleanupClosePushL( contextRemover );
       
   304         // retrieve attributes, ignore return value
       
   305     	(void)GlxAttributeRetriever::RetrieveL(*attributeContext, MediaList(), ETrue);
       
   306         // context off the list
       
   307         CleanupStack::PopAndDestroy( &contextRemover );
       
   308 		}
       
   309 
       
   310 	CleanupStack::PopAndDestroy(attributeContext);
       
   311 	}
       
   312 
       
   313 // -----------------------------------------------------------------------------
       
   314 // HandleTitleAvailableL
       
   315 // -----------------------------------------------------------------------------
       
   316 //	
       
   317 EXPORT_C void CGlxMediaListViewBase::HandleTitleAvailableL(
       
   318         const TDesC& aTitle)
       
   319     {
       
   320 	 // Convertion of unsigned short  to unsigned int  
       
   321     TUint16* tileConv = const_cast<TUint16*>(aTitle.Ptr());
       
   322 	TInt titleLen = aTitle.Length();
       
   323 	TPtr titlePtr(tileConv,titleLen,titleLen);
       
   324 	
       
   325 	//to convert between arabic-indic digits and european digits.
       
   326 	//based on existing language setting.
       
   327     AknTextUtils::LanguageSpecificNumberConversion(titlePtr);
       
   328     
       
   329     // Set a title after it has been obtained by the title fetcher
       
   330     SetTitleL(aTitle);
       
   331     }
       
   332 
       
   333 // -----------------------------------------------------------------------------
       
   334 // CGlxMediaListViewBase::DoPrepareCommandHandlerL
       
   335 // -----------------------------------------------------------------------------
       
   336 //
       
   337 EXPORT_C void CGlxMediaListViewBase::DoPrepareCommandHandlerL(
       
   338 											CGlxCommandHandler* aCommandHandler)
       
   339 	{
       
   340 	AddAttributesToContextL(*iPreloadContextForCommandHandlers, 
       
   341 			                                            aCommandHandler, EFalse, EFalse);
       
   342 	}
       
   343 	
       
   344 // -----------------------------------------------------------------------------
       
   345 // CGlxMediaListViewBase::CloseMediaList
       
   346 // -----------------------------------------------------------------------------
       
   347 //
       
   348 void CGlxMediaListViewBase::CloseMediaList()
       
   349 	{
       
   350     if (iMediaList)
       
   351         {
       
   352         iMediaList->RemoveContext(iPreloadContextForCommandHandlers);
       
   353         iMediaList->Close();
       
   354         iMediaList = NULL;
       
   355         }
       
   356 	}
       
   357 
       
   358 // -----------------------------------------------------------------------------
       
   359 // CGlxMediaListViewBase::AddAttributesToContextL
       
   360 // -----------------------------------------------------------------------------
       
   361 //
       
   362 void CGlxMediaListViewBase::AddAttributesToContextL(
       
   363 								 CGlxAttributeContext& aAttributeContext, 
       
   364 			                     CGlxCommandHandler* aCommandHandler, 
       
   365 			                     TBool aFilterUsingSelection, 
       
   366 			                     TBool aFilterUsingCommandId, 
       
   367 			                     TInt aCommandId)
       
   368     {
       
   369 	RArray<TMPXAttribute> requiredAttributes;
       
   370 	CleanupClosePushL(requiredAttributes); 
       
   371 	aCommandHandler->
       
   372 	GetRequiredAttributesL(requiredAttributes, aFilterUsingSelection, aFilterUsingCommandId, aCommandId); 
       
   373 	
       
   374 	TInt attributeCount = requiredAttributes.Count();
       
   375 	for (TInt i = 0; i < attributeCount; i++)
       
   376 		{
       
   377 		aAttributeContext.AddAttributeL(requiredAttributes[i]);
       
   378 		}
       
   379 	CleanupStack::PopAndDestroy(&requiredAttributes);
       
   380 	}
       
   381 
       
   382 // -----------------------------------------------------------------------------
       
   383 // HandleViewCommandL
       
   384 // -----------------------------------------------------------------------------
       
   385 //	
       
   386 EXPORT_C TBool CGlxMediaListViewBase::HandleViewCommandL(TInt /*aCommand*/)
       
   387 	{
       
   388 	return EFalse;
       
   389 	}
       
   390  
       
   391 // -----------------------------------------------------------------------------
       
   392 // DoHandleCommandL
       
   393 // -----------------------------------------------------------------------------
       
   394 //
       
   395 EXPORT_C TInt CGlxMediaListViewBase::DoHandleCommandL(TInt aCommand)
       
   396     {
       
   397     // Pass the command to the deriving class
       
   398     return HandleViewCommandL( aCommand );
       
   399     }
       
   400