photosgallery/viewframework/dataprovider/src/glxcontainerlistbinding.cpp
changeset 0 4e91876724a2
child 18 bcb43dc84c44
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:    CGlxContainerListBinding This class holds the list of 
       
    15 *                 tags/albums associated with a media item
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 #include "glxcontainerlistbinding.h"        // his class holds the list of tags/albums associated with a media item
       
    23 
       
    24 #include <glxfilterfactory.h>        		// for TGlxFilterFactory
       
    25 #include <glxuistd.h>                       // for attribute priority
       
    26 #include <mul/mulvisualitem.h>              // Client need to use this class to add data in data model       
       
    27 
       
    28 using namespace Alf;
       
    29 
       
    30 //CONSTANTS
       
    31 const TInt  KTagMediaListId = 0x2000D248;
       
    32 const TInt  KRangeOffset = 50;
       
    33 
       
    34 // ----------------------------------------------------------------------------
       
    35 // NewL
       
    36 // ----------------------------------------------------------------------------
       
    37 //
       
    38 CGlxContainerListBinding* CGlxContainerListBinding::NewL( const Alf::mulvisualitem::TVisualAttribute& aMulTag /*const char* const
       
    39         aMulTag*/, const CMPXCollectionPath& aPath )
       
    40 	{
       
    41 	CGlxContainerListBinding* self = CGlxContainerListBinding::NewLC( aMulTag, aPath);
       
    42 	CleanupStack::Pop( self );
       
    43 	return self;
       
    44 	}
       
    45 	
       
    46 
       
    47 // ----------------------------------------------------------------------------
       
    48 // NewLC
       
    49 // ----------------------------------------------------------------------------
       
    50 //	
       
    51 CGlxContainerListBinding* CGlxContainerListBinding::NewLC( const Alf::mulvisualitem::TVisualAttribute& aMulTag /*const char* const
       
    52         aMulTag*/, const CMPXCollectionPath& aPath )
       
    53 	{
       
    54 	CGlxContainerListBinding* self = new ( ELeave ) CGlxContainerListBinding();
       
    55 	CleanupStack::PushL( self );
       
    56 	self->ConstructL( aMulTag, aPath );
       
    57 	return self;
       
    58 	}
       
    59 
       
    60 // ----------------------------------------------------------------------------
       
    61 // ConstructL
       
    62 // ----------------------------------------------------------------------------
       
    63 //
       
    64 void CGlxContainerListBinding::ConstructL( const Alf::mulvisualitem::TVisualAttribute& aMulTag /*const char* const aMulTag*/, 
       
    65         const CMPXCollectionPath& aPath )
       
    66 	{
       
    67 	CGlxSingleTagBinding::BaseConstructL( aMulTag );
       
    68 	iContainerPath = CMPXCollectionPath::NewL( aPath );
       
    69 	
       
    70 	// attributes for Title of tags and albums
       
    71 	iFetchContext = CGlxDefaultAttributeContext::NewL();
       
    72 	iFetchContext->AddAttributeL( KMPXMediaGeneralTitle );
       
    73 	iFetchContext->SetRangeOffsets(KRangeOffset,KRangeOffset);
       
    74 	}
       
    75 
       
    76 // ----------------------------------------------------------------------------
       
    77 // Destructor
       
    78 // ----------------------------------------------------------------------------
       
    79 //
       
    80 CGlxContainerListBinding::~CGlxContainerListBinding()
       
    81 	{
       
    82 	CloseMediaList();
       
    83 	}
       
    84 	
       
    85 // ---------------------------------------------------------------------------
       
    86 // PopulateT
       
    87 // ---------------------------------------------------------------------------
       
    88 //
       
    89 void CGlxContainerListBinding::PopulateT( Alf::MulVisualItem& aItem,
       
    90         const TGlxMedia& aMedia, TBool /*aIsFocused*/ ) const
       
    91 	{
       
    92     const TInt KCommaLength = 2;
       
    93     _LIT(KComma,",");
       
    94 
       
    95     //T is used for throws as per C++ standard.Hence used instead of "L"
       
    96     //Ignoring this for code scanner warnings - Leaving functions called in non-leaving functions.
       
    97     
       
    98 	if(!iContainerList)
       
    99 		{
       
   100 		CreateMediaListL( aMedia.Id() );
       
   101 		}
       
   102 
       
   103 	if( iContainerList )
       
   104 		{
       
   105 		CGlxUStringConverter* stringConverter = CGlxUStringConverter::NewL();
       
   106 		CleanupStack::PushL(stringConverter );
       
   107 
       
   108 		TInt tagListcount = iContainerList->Count();
       
   109 		//if tags count is grater than 1 then display tags saperated by comma
       
   110 		if( tagListcount > 0 )
       
   111 			{
       
   112 			HBufC* stringBuffer = NULL;
       
   113 			
       
   114 			for(TInt i=0; i < tagListcount; i++ )
       
   115 				{
       
   116 				HBufC* string = NULL;
       
   117 				stringConverter->AsStringL( iContainerList->Item(i),    
       
   118 				    KMPXMediaGeneralTitle, NULL, string );
       
   119 				if( string )
       
   120 					{
       
   121 					if( stringBuffer )
       
   122 					    {
       
   123 					    stringBuffer = stringBuffer->ReAlloc( stringBuffer->Length() +  string->Length() );
       
   124 					    stringBuffer->Des().Append ( string->Des() );
       
   125 					    }
       
   126 				    
       
   127 					if( !stringBuffer )
       
   128 					    {
       
   129 	   				    stringBuffer = string->Alloc();
       
   130 					    }
       
   131 						
       
   132 				    delete string;
       
   133 				    string = NULL;
       
   134 					}
       
   135 				if( i < tagListcount -1 )
       
   136 					{
       
   137 			    	if( stringBuffer )
       
   138 			    	    {
       
   139     					stringBuffer = stringBuffer->ReAlloc( stringBuffer->Length() +  KCommaLength );
       
   140     					stringBuffer->Des().Append( KComma );
       
   141 			    	    }
       
   142 					}
       
   143 				}
       
   144 					
       
   145 			if( stringBuffer )
       
   146 			    {
       
   147     			aItem.SetAttribute( MulTag(), *stringBuffer );
       
   148     			delete stringBuffer;
       
   149     			stringBuffer = NULL;
       
   150 			    }
       
   151 			}
       
   152 		else
       
   153 			{		
       
   154 			aItem.SetAttribute( MulTag(), _L("") );
       
   155 			}
       
   156 		CleanupStack::PopAndDestroy(stringConverter );
       
   157 		}
       
   158 		
       
   159 }
       
   160 // ---------------------------------------------------------------------------
       
   161 // CreateMediaListL
       
   162 // ---------------------------------------------------------------------------
       
   163 //
       
   164 void CGlxContainerListBinding::CreateMediaListL(TGlxMediaId aMediaId) const
       
   165     {
       
   166     //create filter that excludes all containers that do not contain the specified item
       
   167     CMPXFilter* itemFilter  = TGlxFilterFactory::CreateExcludeContainersWithoutItemFilterL( aMediaId );
       
   168     CleanupStack::PushL(itemFilter);
       
   169 
       
   170     TGlxFilterProperties filterProperty;
       
   171     filterProperty.iSortOrder = EGlxFilterSortOrderAlphabetical;
       
   172     filterProperty.iSortDirection = EGlxFilterSortDirectionAscending;
       
   173     //creates a combined filter, items will be sorted by the filters specified
       
   174     CMPXFilter* filter  = TGlxFilterFactory::CreateCombinedFilterL( filterProperty,
       
   175                                                                         itemFilter, EFalse);
       
   176     CleanupStack::PushL(filter); 
       
   177     //create media list
       
   178     iContainerList = MGlxMediaList::InstanceL( *iContainerPath, TGlxHierarchyId(KTagMediaListId), filter );
       
   179     iContainerList->AddContextL( iFetchContext, KGlxFetchContextPriorityNormal );
       
   180     iContainerList->AddMediaListObserverL( const_cast<CGlxContainerListBinding*>(this));
       
   181     CleanupStack::PopAndDestroy(filter);
       
   182     CleanupStack::PopAndDestroy(itemFilter);
       
   183     }
       
   184 // ---------------------------------------------------------------------------
       
   185 // CloseMediaListL
       
   186 // ---------------------------------------------------------------------------
       
   187 //
       
   188 void CGlxContainerListBinding::CloseMediaList()
       
   189     {
       
   190     if(iContainerList)
       
   191         {
       
   192         iContainerList->RemoveMediaListObserver( this );
       
   193 		if (iFetchContext)
       
   194 			{
       
   195 			iContainerList->RemoveContext( iFetchContext );
       
   196 			delete iFetchContext;
       
   197 			iFetchContext = NULL;
       
   198 			}
       
   199         iContainerList->Close();
       
   200         }
       
   201     if (iContainerPath)
       
   202 		{
       
   203 		delete iContainerPath;
       
   204 		iContainerPath= NULL;
       
   205 		}
       
   206     }
       
   207     
       
   208 // ---------------------------------------------------------------------------
       
   209 // HandleItemAddedL
       
   210 // ---------------------------------------------------------------------------
       
   211 //
       
   212 void CGlxContainerListBinding::HandleItemAddedL( TInt /*aStartIndex*/, TInt /*aEndIndex*/, 
       
   213         MGlxMediaList* /*aList*/ )
       
   214     {
       
   215     //No implementation
       
   216     }
       
   217     
       
   218 // ---------------------------------------------------------------------------
       
   219 // HandleItemRemovedL
       
   220 // ---------------------------------------------------------------------------
       
   221 //
       
   222 void CGlxContainerListBinding::HandleItemRemovedL( TInt /*aStartIndex*/, 
       
   223         TInt /*aEndIndex*/, MGlxMediaList* /*aList*/ )
       
   224     {
       
   225     //No implementation    
       
   226     }
       
   227     
       
   228 // ---------------------------------------------------------------------------
       
   229 // HandleAttributesAvailableL
       
   230 // ---------------------------------------------------------------------------
       
   231 //
       
   232 void CGlxContainerListBinding::HandleAttributesAvailableL( TInt /*aItemIndex*/, 
       
   233     const RArray<TMPXAttribute>& /*aAttributes*/, MGlxMediaList* aList )
       
   234 	{
       
   235 	if( aList == iContainerList )
       
   236 		{
       
   237 		Update();
       
   238 		}
       
   239 	}
       
   240 
       
   241 // ----------------------------------------------------------------------------
       
   242 // HandleFocusChanged
       
   243 // checks whether the focus has changed,returns the response status 
       
   244 // ----------------------------------------------------------------------------
       
   245 //  
       
   246 CGlxBinding::TResponse CGlxContainerListBinding::HandleFocusChanged( 
       
   247         TBool /*aIsGained*/ )
       
   248     {
       
   249     //@todo - Need further implementation
       
   250     //return aIsGained ? EUpdateRequested : ENoUpdateNeeded ;
       
   251     //need to remove once bug ESPK-7G6GJX is fixed
       
   252     return ENoUpdateNeeded ;
       
   253     }
       
   254     
       
   255 // ---------------------------------------------------------------------------
       
   256 // HandleFocusChangedL
       
   257 // ---------------------------------------------------------------------------
       
   258 //
       
   259 void CGlxContainerListBinding::HandleFocusChangedL( NGlxListDefs::TFocusChangeType /*aType*/, 
       
   260         TInt /*aNewIndex*/, TInt /*aOldIndex*/, MGlxMediaList* /*aList*/ )
       
   261     {
       
   262     //No implementation   
       
   263     }
       
   264 
       
   265 // ---------------------------------------------------------------------------
       
   266 // HandleItemSelectedL
       
   267 // ---------------------------------------------------------------------------
       
   268 //
       
   269 void CGlxContainerListBinding::HandleItemSelectedL(TInt /*aIndex*/,
       
   270         TBool /*aSelected*/, MGlxMediaList* /*aList*/ ) 
       
   271     {
       
   272     //No implementation    
       
   273     }
       
   274 
       
   275 // ---------------------------------------------------------------------------
       
   276 // HandleMessageL
       
   277 // ---------------------------------------------------------------------------
       
   278 //
       
   279 void CGlxContainerListBinding::HandleMessageL( const CMPXMessage& /*aMessage*/,
       
   280         MGlxMediaList* /*aList*/ ) 
       
   281     {
       
   282     //No implementation    
       
   283     }
       
   284 
       
   285 // ---------------------------------------------------------------------------
       
   286 // HandleMediaL
       
   287 // ---------------------------------------------------------------------------
       
   288 //
       
   289 void CGlxContainerListBinding::HandleMediaL( TInt /*aListIndex*/,
       
   290         MGlxMediaList* /*aList*/ ) 
       
   291     {
       
   292     //No implementation    
       
   293     }
       
   294 
       
   295 // ---------------------------------------------------------------------------
       
   296 // HandleItemModifiedL
       
   297 // ---------------------------------------------------------------------------
       
   298 //
       
   299 void CGlxContainerListBinding::HandleItemModifiedL( const RArray<TInt>& /*aItemIndexes*/,
       
   300         MGlxMediaList* /*aList*/ )
       
   301     {
       
   302     //No implementation    
       
   303     }