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