photosgallery/contentharvesterplugin/src/glxcontentharvesterplugintags.cpp
changeset 0 4e91876724a2
child 1 9ba538e329bd
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:    Updates CPS storage for all collection
       
    15  *
       
    16  */
       
    17 
       
    18 // INCLUDE FILES
       
    19 
       
    20 #include <mmf/common/mmfcontrollerpluginresolver.h>
       
    21 #include <liwservicehandler.h>
       
    22 
       
    23 #include <glxuistd.h>
       
    24 #include <glxicons.mbg>   // Glx Icons
       
    25 #include <glxcollectionplugintags.hrh>
       
    26 #include <glxthumbnailattributeinfo.h>  // for KGlxMediaIdThumbnail
       
    27 #include <glxattributecontext.h>
       
    28 #include <glxthumbnailcontext.h>
       
    29 #include <glxtracer.h>
       
    30 #include <glxlog.h>
       
    31 #include <mglxmedialist.h>       // for MGlxMediaList
       
    32 #include <glxcollectiongeneraldefs.h>
       
    33 #include <glxgallery.hrh>               // for KGlxGalleryApplicationUid
       
    34 #include <glxmediaid.h>
       
    35 #include <glxerrormanager.h>    
       
    36 
       
    37 #include "glxcontentharvesterplugintags.h"
       
    38 #include "glxcontentharvesterplugin.hrh"
       
    39 #include "glxmapconstants.h"
       
    40 
       
    41 // ============================ MEMBER FUNCTIONS ==============================
       
    42 LOCAL_C TInt TimerCallbackL( TAny* aPtr )
       
    43     {
       
    44     TRACER( "CGlxContentHarvesterPluginTags::TimerCallbackL" );
       
    45     static_cast<CGlxContentHarvesterPluginTags*>(aPtr)->UpdateDataL();
       
    46     return KErrNone;
       
    47     }
       
    48 
       
    49 // ----------------------------------------------------------------------------
       
    50 // Constructor
       
    51 // ----------------------------------------------------------------------------
       
    52 //
       
    53 CGlxContentHarvesterPluginTags::CGlxContentHarvesterPluginTags( 
       
    54         MLiwInterface* aCPSInterface,
       
    55         MGlxContentHarvesterPlugin* aCHplugin )
       
    56 
       
    57     {
       
    58     TRACER( "CGlxContentHarvesterPluginTags::CGlxContentHarvesterPluginTags" );
       
    59     iCPSInterface = aCPSInterface;
       
    60     SetCHPlugin(aCHplugin);
       
    61     }
       
    62 
       
    63 // ----------------------------------------------------------------------------
       
    64 // Symbian 2nd phase constructor can leave.
       
    65 // ----------------------------------------------------------------------------
       
    66 //
       
    67 void CGlxContentHarvesterPluginTags::ConstructL()
       
    68     {
       
    69     TRACER( "CGlxContentHarvesterPluginTags::ConstructL" );
       
    70 
       
    71     //Call the base class ConstructL to create default bitmap
       
    72     CGlxContentHarvesterPluginBase::ConstructL(EMbmGlxiconsQgn_prop_image_notcreated);
       
    73 
       
    74     iPeriodic = CPeriodic::NewL( CActive::EPriorityLow );
       
    75     iThumbnailContext = CGlxThumbnailContext::NewL(&iThumbnailIterator);
       
    76 
       
    77     //Register/Subscribe with matrix menu for the notifications 
       
    78     GetInterfaceForNotificationL();
       
    79     SetupPublisherL(KItemIndexTags);
       
    80     RequestCpsNotificationL(KItemIndexTags);
       
    81     HandleStateChangeL(KItemIndexTags);
       
    82     }
       
    83 
       
    84 // ----------------------------------------------------------------------------
       
    85 // Two-phased constructor.
       
    86 // ----------------------------------------------------------------------------
       
    87 //
       
    88 CGlxContentHarvesterPluginTags* CGlxContentHarvesterPluginTags::NewLC( 
       
    89         MLiwInterface* aCPSInterface,
       
    90         MGlxContentHarvesterPlugin* aCHplugin )
       
    91     {
       
    92     TRACER( "CGlxContentHarvesterPluginTags::NewL" );
       
    93     CGlxContentHarvesterPluginTags* self = new ( ELeave )CGlxContentHarvesterPluginTags( aCPSInterface,aCHplugin );
       
    94 
       
    95     CleanupStack::PushL(self);
       
    96     self->ConstructL();
       
    97     return self;
       
    98     }
       
    99 
       
   100 // ---------------------------------------------------------------------------
       
   101 // Destructor
       
   102 // ---------------------------------------------------------------------------
       
   103 //
       
   104 CGlxContentHarvesterPluginTags::~CGlxContentHarvesterPluginTags()
       
   105     {
       
   106     TRACER( "CGlxContentHarvesterPluginTags::~CGlxContentHarvesterPluginTags" );
       
   107 
       
   108     DestroyMedialist();
       
   109     if ( iPeriodic )
       
   110         {
       
   111         iPeriodic->Cancel();
       
   112         }
       
   113     delete iPeriodic;
       
   114 
       
   115     }
       
   116 
       
   117 // ----------------------------------------------------------------------------
       
   118 // CGlxContentHarvesterPluginTags::UpdateDataL()
       
   119 // ----------------------------------------------------------------------------
       
   120 //
       
   121 void CGlxContentHarvesterPluginTags::UpdateDataL() 
       
   122     {
       
   123     TRACER( "CGlxContentHarvesterPluginTags::UpdateDataL" );
       
   124     if(iMediaList && iMediaList->Count() && iPreviewItemCount.Count() )
       
   125         {
       
   126         GLX_LOG_INFO1("CGlxContentHarvesterPluginTags::UpdateDataL(),iProgressIndex=%d",iProgressIndex);
       
   127         TInt ret = UpdateItem(iPreviewItemCount[iProgressIndex]);
       
   128         if(ret != KErrNotFound)
       
   129             {
       
   130             //Updates the thumbnail in the collection 
       
   131             UpdateDataInCPSL(ret);
       
   132             }
       
   133         else
       
   134             {
       
   135             UpdateDataInCPSL(GetBitmapHandle());
       
   136             }
       
   137         }
       
   138     else
       
   139         {
       
   140         // Show previous thumbnail until the new thumbnail is
       
   141         // fecthed.Added this check to avoid flicker
       
   142         if(!GetCHPlugin()->IsRefreshNeeded() || (iMediaList->Count() == 0))
       
   143         	{
       
   144 			//Don't Show the Thumbnail/Show nothing
       
   145 			GLX_LOG_INFO("CGlxContentHarvesterPluginTags::UpdateDataL() --O");
       
   146 			UpdateDataInCPSL(GetBitmapHandle());
       
   147         	}
       
   148         }
       
   149     }
       
   150 
       
   151 // ----------------------------------------------------------------------------
       
   152 // CGlxContentHarvesterPluginTags::HandleNotifyL()
       
   153 // ----------------------------------------------------------------------------
       
   154 //
       
   155 TInt CGlxContentHarvesterPluginTags::HandleNotifyL(
       
   156         TInt /* aCmdId*/,
       
   157         TInt/* aEventId */,
       
   158         CLiwGenericParamList& /*aEventParamList*/,
       
   159         const CLiwGenericParamList& /*aInParamList*/ )
       
   160     {
       
   161     TRACER( "CGlxContentHarvesterPluginTags::HandleNotifyL" );
       
   162     HandleStateChangeL(KItemIndexTags);
       
   163     return KErrNone;
       
   164     }
       
   165 
       
   166 // ----------------------------------------------------------------------------
       
   167 // CGlxContentHarvesterPluginTags::HandleItemChanged()
       
   168 // ----------------------------------------------------------------------------
       
   169 //
       
   170 void CGlxContentHarvesterPluginTags::HandleItemChanged()
       
   171     {
       
   172     TRACER("CGlxContentHarvesterPluginTags::HandleItemChanged");
       
   173 
       
   174     iProgressIndex = 0;
       
   175     iPreviewItemCount.Reset();
       
   176 
       
   177     TSize gridIconSize = GetGridIconSize();
       
   178     TMPXAttribute thumbnailAttribute(KGlxMediaIdThumbnail, 
       
   179             GlxFullThumbnailAttributeId( ETrue,  gridIconSize.iWidth, gridIconSize.iHeight ) );
       
   180     if(iMediaList)  
       
   181         {
       
   182         TInt count = iMediaList->Count();
       
   183         GLX_LOG_INFO1("CGlxContentHarvesterPluginTags:: HandleItemChanged ,count=%d",count);
       
   184 
       
   185         TBool inFocus = IsFocused();
       
   186         for(TInt aItemIndex = 0; aItemIndex < count; aItemIndex++)
       
   187             {
       
   188             const TGlxMedia& item = iMediaList->Item( aItemIndex );
       
   189             const CGlxThumbnailAttribute* value = item.ThumbnailAttribute( thumbnailAttribute );
       
   190             if (value)
       
   191                 {
       
   192                 iPreviewItemCount.InsertInOrder(aItemIndex);
       
   193                 if(!inFocus)
       
   194                     {
       
   195                     //if the collection is in Focus,retrieve only one thumbnail and break
       
   196                     GLX_LOG_INFO1("CGlxContentHarvesterPluginTags::HandleItemChanged,iRange=1,aItemIndex=%d",aItemIndex);
       
   197                     break;
       
   198                     }
       
   199                 else if(iPreviewItemCount.Count() == KPreviewThumbnailFetchCount || 
       
   200                         iPreviewItemCount.Count() == count )
       
   201                     {
       
   202                     //if the collection is not in Focus,retrieve 15 thumbnail and break
       
   203                     GLX_LOG_INFO1("CGlxContentHarvesterPluginTags::HandleItemChanged,iRange=15,aItemIndex=%d",aItemIndex);
       
   204                     break;
       
   205                     }
       
   206 
       
   207                 }
       
   208             }
       
   209         }
       
   210     }
       
   211 
       
   212 // ----------------------------------------------------------------------------
       
   213 // CGlxContentHarvesterPluginTags::UpdateDataInCPSL()
       
   214 // ----------------------------------------------------------------------------
       
   215 //  
       
   216 void CGlxContentHarvesterPluginTags::UpdateDataInCPSL(TInt aHandle) 
       
   217     {
       
   218     TRACER( "CGlxContentHarvesterPluginTags::UpdateDataInCPSL" );
       
   219     //update data in CPS
       
   220     _LIT(KExamplePluginPub,"photossuite");
       
   221     _LIT(KContTypeText,"tags");
       
   222     _LIT(KContId1,"category1");
       
   223 
       
   224     if(iCPSInterface && iMediaList )
       
   225         {
       
   226         CLiwGenericParamList* inParamList = CLiwGenericParamList::NewLC();
       
   227         CLiwGenericParamList* outParamList = CLiwGenericParamList::NewLC();
       
   228 
       
   229         FillInputListWithDataL(inParamList, KExamplePluginPub, KContTypeText , 
       
   230                 KContId1, aHandle);
       
   231 
       
   232         iCPSInterface->ExecuteCmdL( KAdd,  *inParamList, *outParamList );
       
   233         CleanupStack::PopAndDestroy(outParamList);
       
   234         CleanupStack::PopAndDestroy(inParamList);
       
   235         }
       
   236     }
       
   237 
       
   238 // ----------------------------------------------------------------------------
       
   239 // CGlxContentHarvesterPluginTags::UpdateItem()
       
   240 // ----------------------------------------------------------------------------
       
   241 //
       
   242 TInt CGlxContentHarvesterPluginTags::UpdateItem(TInt aItemIndex)
       
   243     {
       
   244     TRACER( "CGlxContentHarvesterPluginTags::UpdateItem" );
       
   245     const TGlxMedia& item = iMediaList->Item(aItemIndex);
       
   246     TSize gridIconSize = GetGridIconSize();
       
   247     TMPXAttribute thumbnailAttribute(KGlxMediaIdThumbnail, 
       
   248             GlxFullThumbnailAttributeId( ETrue,  gridIconSize.iWidth, gridIconSize.iHeight ) );
       
   249     GLX_LOG_INFO1("CGlxContentHarvesterPluginTags::UpdateItem,aItemIndex=%d ",aItemIndex);
       
   250     const CGlxThumbnailAttribute* value = item.ThumbnailAttribute( thumbnailAttribute );
       
   251     if (value)
       
   252         {
       
   253         GLX_LOG_INFO1("CGlxContentHarvesterPluginTags::UpdateItem,iProgressIndex=%d ",iProgressIndex);
       
   254         iProgressIndex++;
       
   255         if (iProgressIndex >= KPreviewThumbnailFetchCount || 
       
   256                 iProgressIndex >= iPreviewItemCount.Count() ||
       
   257                 iProgressIndex >= iMediaList->Count())
       
   258             {
       
   259             iProgressIndex = 0;
       
   260             }
       
   261         return value->iBitmap->Handle();
       
   262         }
       
   263     return KErrNotFound;
       
   264     }
       
   265 
       
   266 // ----------------------------------------------------------------------------
       
   267 // CGlxContentHarvesterPluginTags::ActivateL()
       
   268 // ----------------------------------------------------------------------------
       
   269 //
       
   270 void CGlxContentHarvesterPluginTags::ActivateL( TBool aOn )
       
   271     {
       
   272     TRACER( "CGlxContentHarvesterPluginTags::ActivateL" );
       
   273 
       
   274     GLX_LOG_INFO1("CGlxContentHarvesterPluginTags::ActivateL aOn =%d",aOn);
       
   275     SetFocus(aOn);
       
   276 
       
   277     if (IsMatrixMenuInForegroundL() && aOn && !iPeriodic->IsActive() )
       
   278         {
       
   279         if(GetCHPlugin()->IsRefreshNeeded())
       
   280             {
       
   281             //Update the rest of all the collections on receving the focus...
       
   282             GetCHPlugin()->UpdatePlugins(aOn);     
       
   283             }
       
   284         else
       
   285             {
       
   286             //As the collection is not updated by the contentharvester plugin
       
   287             //to update the thumbnails on the focus , need to call the below function
       
   288             UpdatePreviewThumbnailListL();
       
   289             }
       
   290 
       
   291         iPeriodic->Start( KTimerInterval, 
       
   292                 KTimerInterval, 
       
   293                 TCallBack( TimerCallbackL, this ) );
       
   294         }
       
   295     else if ( !aOn )
       
   296         {
       
   297           if(!IsMatrixMenuInForegroundL())
       
   298             {
       
   299             //use case:Matrix Menu is exited, by entering into grid view,application view,capture mode...
       
   300             //Need to destroy all the collection's observers and context
       
   301             GLX_LOG_INFO1("CGlxContentHarvesterPluginTags::ActivateL !aOn =%d and matrix not in foreground",aOn);
       
   302             GetCHPlugin()->UpdatePlugins(aOn);    
       
   303             }
       
   304         iPeriodic->Cancel();
       
   305         }
       
   306     }
       
   307 
       
   308 // ----------------------------------------------------------------------------
       
   309 // CGlxContentHarvesterPluginTags::HandleItemAddedL
       
   310 // ----------------------------------------------------------------------------
       
   311 //
       
   312 void CGlxContentHarvesterPluginTags::HandleItemAddedL(TInt /*aStartIndex*/, TInt /*aEndIndex*/, 
       
   313         MGlxMediaList* /*aList*/)
       
   314     {
       
   315     TRACER( "CGlxContentHarvesterPluginTags::HandleItemAddedL" );
       
   316     }
       
   317 
       
   318 // ---------------------------------------------------------------------------
       
   319 // CGlxContentHarvesterPluginTags::HandleMediaL
       
   320 // ---------------------------------------------------------------------------
       
   321 //
       
   322 void CGlxContentHarvesterPluginTags::HandleMediaL(TInt /*aListIndex*/, 
       
   323         MGlxMediaList* /*aList*/)
       
   324     {
       
   325     TRACER( "CGlxContentHarvesterPluginTags::HandleMediaL" );
       
   326     } 
       
   327 
       
   328 // ---------------------------------------------------------------------------
       
   329 // CGlxContentHarvesterPluginTags::HandleItemRemovedL
       
   330 // ---------------------------------------------------------------------------
       
   331 //
       
   332 void CGlxContentHarvesterPluginTags::HandleItemRemovedL(TInt /*aStartIndex*/, 
       
   333         TInt /* aEndIndex */, MGlxMediaList* /*aList*/)
       
   334     {
       
   335     TRACER( "CGlxContentHarvesterPluginTags::HandleItemRemovedL" );
       
   336     }
       
   337 
       
   338 // ---------------------------------------------------------------------------
       
   339 // CGlxContentHarvesterPluginTags::HandleItemModifiedL
       
   340 // ---------------------------------------------------------------------------
       
   341 //
       
   342 void CGlxContentHarvesterPluginTags::HandleItemModifiedL(
       
   343         const RArray<TInt>& /*aItemIndexes*/, 
       
   344         MGlxMediaList* /*aList*/)
       
   345     {
       
   346     TRACER( "CGlxContentHarvesterPluginTags::HandleItemModifiedL" );
       
   347     }
       
   348 
       
   349 // ---------------------------------------------------------------------------
       
   350 // CGlxContentHarvesterPluginTags::HandleAttributesAvailableL
       
   351 // ---------------------------------------------------------------------------
       
   352 //
       
   353 void CGlxContentHarvesterPluginTags::HandleAttributesAvailableL(TInt aItemIndex, 
       
   354         const RArray<TMPXAttribute>& aAttributes, MGlxMediaList* aList)
       
   355     {
       
   356     TRACER( "CGlxContentHarvesterPluginTags::HandleAttributesAvailableL" );
       
   357     TSize gridIconSize = GetGridIconSize();
       
   358     TMPXAttribute thumbnailAttribute(KGlxMediaIdThumbnail, 
       
   359             GlxFullThumbnailAttributeId( ETrue,  gridIconSize.iWidth, gridIconSize.iHeight ) );
       
   360 
       
   361     TIdentityRelation< TMPXAttribute > match ( &TMPXAttribute::Match );
       
   362 
       
   363     GLX_LOG_INFO1("CGlxContentHarvesterPluginTags::HandleAttributesAvailableL =%d ",aItemIndex);
       
   364     if (KErrNotFound != aAttributes.Find( thumbnailAttribute, match ))
       
   365         {
       
   366         const TGlxMedia& item = aList->Item( aItemIndex );
       
   367         const CGlxThumbnailAttribute* value = item.ThumbnailAttribute( thumbnailAttribute );
       
   368         if (value)
       
   369             {
       
   370             GLX_LOG_INFO("CGlxContentHarvesterPluginTags::HandleAttributesAvailableL Thumbnail is present ");
       
   371             iPreviewItemCount.InsertInOrder(aItemIndex);
       
   372 
       
   373             //if the collection on the matrix menu is not focused,then show only one thumbnail
       
   374             if(!IsFocused())
       
   375                 {
       
   376                 GLX_LOG_INFO("CGlxContentHarvesterPluginTags::HandleAttributesAvailableL,one thumbnail fetched");
       
   377                 UpdateDataInCPSL( value->iBitmap->Handle());
       
   378                 //if one thumbnail is fetched,it is sufficent when the collection is not in focus.
       
   379                 //remove the observer as client need not listen to the callbacks
       
   380                 iMediaList->RemoveMediaListObserver( this );
       
   381                 }
       
   382             else if (iPreviewItemCount.Count() == KPreviewThumbnailFetchCount ||
       
   383                     iPreviewItemCount.Count() == aList->Count() )
       
   384                 {
       
   385                 GLX_LOG_INFO1("CGlxContentHarvesterPluginTags::HandleAttributesAvailableL,media list count=%d",aList->Count());
       
   386                 //if the PreviewItemCount  equals 15 or if it is eqaul to the total count
       
   387                 //remove the observer as client need not listen to the callbacks
       
   388                 iMediaList->RemoveMediaListObserver( this );
       
   389                 }
       
   390             }//end of  check against value 
       
   391         }//end of  attribute match
       
   392     }
       
   393 
       
   394 // ---------------------------------------------------------------------------
       
   395 // CGlxContentHarvesterPluginTags::HandleFocusChangedL
       
   396 // ---------------------------------------------------------------------------
       
   397 //
       
   398 void CGlxContentHarvesterPluginTags::HandleFocusChangedL(
       
   399         NGlxListDefs::TFocusChangeType /*aType*/, 
       
   400         TInt /*aNewIndex*/, 
       
   401         TInt /*aOldIndex*/, 
       
   402         MGlxMediaList* /*aList*/)
       
   403     {
       
   404     TRACER( "CGlxContentHarvesterPluginTags::HandleFocusChangedL" );
       
   405     }
       
   406 
       
   407 
       
   408 // ---------------------------------------------------------------------------
       
   409 // CGlxContentHarvesterPluginTags::HandleItemSelectedL
       
   410 // ---------------------------------------------------------------------------
       
   411 //
       
   412 void CGlxContentHarvesterPluginTags::HandleItemSelectedL(TInt /*aIndex*/, 
       
   413         TBool /*aSelected*/, 
       
   414         MGlxMediaList* /*aList*/)
       
   415     {
       
   416     TRACER( "CGlxContentHarvesterPluginTags::HandleItemSelectedL" );
       
   417     }
       
   418 
       
   419 // ---------------------------------------------------------------------------
       
   420 // CGlxContentHarvesterPluginTags::HandleMessageL
       
   421 // ---------------------------------------------------------------------------
       
   422 //
       
   423 void CGlxContentHarvesterPluginTags::HandleMessageL(const CMPXMessage& /*aMessage*/, 
       
   424         MGlxMediaList* /*aList*/)
       
   425     {
       
   426     // Do nothing
       
   427     TRACER( "CGlxContentHarvesterPluginTags::HandleMessageL" );
       
   428     }   
       
   429 
       
   430 // ---------------------------------------------------------------------------
       
   431 // CGlxContentHarvesterPluginTags::DestroyMedialist
       
   432 // ---------------------------------------------------------------------------
       
   433 //
       
   434 void CGlxContentHarvesterPluginTags::DestroyMedialist()
       
   435     {
       
   436     TRACER( "CGlxContentHarvesterPluginTags::DestroyMedialist" );
       
   437     if( iMediaList )
       
   438         {
       
   439         GLX_LOG_INFO("CGlxContentHarvesterPluginTags::DestroyMedialist,media list deleted");
       
   440         RemoveContextAndObserver();
       
   441         delete iThumbnailContext;
       
   442         iThumbnailContext = NULL;
       
   443         iMediaList->Close();
       
   444         iMediaList = NULL;
       
   445         }
       
   446     }
       
   447 
       
   448 // ---------------------------------------------------------------------------
       
   449 // CGlxContentHarvesterPluginTags::CreateMedialistL
       
   450 // ---------------------------------------------------------------------------
       
   451 //
       
   452 void CGlxContentHarvesterPluginTags::CreateMedialistL( )
       
   453     {
       
   454     TRACER( "CGlxContentHarvesterPluginTags::CreateMedialistL" );
       
   455     if(!iMediaList)
       
   456         {
       
   457         //if the collection is in focus then , create media list with context of 15 items else
       
   458         // with context of single item.
       
   459         if(IsFocused())
       
   460             {
       
   461             iThumbnailIterator.SetRange( KPreviewThumbnailFetchCount ); 
       
   462             }
       
   463         else
       
   464             {
       
   465             iThumbnailIterator.SetRange( KSinglePreviewThumbnail );
       
   466             }
       
   467 
       
   468         iMediaList = CreateMedialistAndThumbnailContextL( TGlxMediaId( 
       
   469                 KGlxTagCollectionPluginImplementationUid ),iThumbnailContext);
       
   470         AddContextAndObserverL();
       
   471         }
       
   472     }
       
   473 
       
   474 // ---------------------------------------------------------------------------
       
   475 // CGlxContentHarvesterPluginTags::UpdatePreviewThumbnailListL
       
   476 // ---------------------------------------------------------------------------
       
   477 //
       
   478 void CGlxContentHarvesterPluginTags::UpdatePreviewThumbnailListL( )
       
   479     {
       
   480     TRACER( "CGlxContentHarvesterPluginTags::UpdatePreviewThumbnailListL" );
       
   481 
       
   482     //when there is an update of content in the collection
       
   483     //this function is executed or when the collection recives the focus. 
       
   484     if(!iMediaList)
       
   485         {
       
   486         //medis list is not created yet,create it.
       
   487         CreateMedialistL( );
       
   488         //This is called to show the preview thumbnails. If no thumbnails are
       
   489         //present, display nothing
       
   490         UpdateDataL();
       
   491         }
       
   492     else
       
   493         {        
       
   494         if(GetCHPlugin()->IsRefreshNeeded())
       
   495             {
       
   496             ContainerCacheCleanupL(iMediaList);
       
   497             }
       
   498         if(IsFocused())
       
   499 	        {			
       
   500 	        //1.This loop is executed,when the collection gets focus
       
   501 	        //2.This loop is executed,when the contents are updated for this collection
       
   502 	        //and this collection has focus,so 15 thumbnails are fetched.
       
   503 	        HandleItemChanged();
       
   504 	        iThumbnailIterator.SetRange( KPreviewThumbnailFetchCount );
       
   505 	        RemoveContextAndObserver();
       
   506 	        AddContextAndObserverL();
       
   507 	        }
       
   508 	    else
       
   509 	        {
       
   510 	        //1.This loop is executed,when the contents are updated for this collection
       
   511 	        //and this collection doesn't have the focus,so only one thumbnail is fetched.
       
   512 
       
   513 	        //here we need to fetch only one item 
       
   514 	        //1.if the content is deleted,then creating a context doesn't fetch the attributes
       
   515 	        //2.if the content is added and the content is not the latest as per the sorted order of the
       
   516 	        // media list,then the thumbnails are not fetched.
       
   517 	        // so show the first available thumbnail in the media list.
       
   518 
       
   519 	        HandleItemChanged();
       
   520 	        UpdateDataL();
       
   521 
       
   522 	        //Adding the context doesn't gaurantee we get a call back for
       
   523 	        //Handle attributes available,if the latest item is already fetched.
       
   524 	        //and for the content added for this collection,if it is not latest
       
   525 	        //we will not recieve the attributes .so show the first available thumbnail 
       
   526 	        //in the media list.if there is any new latest content added,the thumbnail will be 
       
   527 	        //fetched and shown.
       
   528 
       
   529 	        iThumbnailIterator.SetRange( KSinglePreviewThumbnail );
       
   530 	        RemoveContextAndObserver();
       
   531 	        AddContextAndObserverL();
       
   532 			}
       
   533         }
       
   534     }
       
   535 
       
   536 // ---------------------------------------------------------------------------
       
   537 // CGlxContentHarvesterPluginTags::AddContextAndObserverL
       
   538 // ---------------------------------------------------------------------------
       
   539 //
       
   540 void CGlxContentHarvesterPluginTags::AddContextAndObserverL()
       
   541     {
       
   542     TRACER( "CGlxContentHarvesterPluginTags::AddRemoveContextAndObserverL" );   
       
   543     if(iMediaList)
       
   544         {
       
   545         iMediaList->AddMediaListObserverL( this );
       
   546         iMediaList->AddContextL(iThumbnailContext, KGlxFetchContextPriorityNormal);
       
   547         }
       
   548     }
       
   549 
       
   550 // ---------------------------------------------------------------------------
       
   551 // CGlxContentHarvesterPluginTags::RemoveContextAndObserver
       
   552 // ---------------------------------------------------------------------------
       
   553 //
       
   554 void CGlxContentHarvesterPluginTags::RemoveContextAndObserver()
       
   555     {
       
   556     TRACER( "CGlxContentHarvesterPluginTags::RemoveContextAndObserver" );   
       
   557     if(iMediaList)
       
   558         {
       
   559         iMediaList->RemoveMediaListObserver( this );
       
   560         iMediaList->RemoveContext(iThumbnailContext);
       
   561         }
       
   562     }
       
   563 
       
   564 // ---------------------------------------------------------------------------
       
   565 // CGlxContentHarvesterPluginTags::HandleError
       
   566 // ---------------------------------------------------------------------------
       
   567 //
       
   568 void CGlxContentHarvesterPluginTags::HandleError(TInt /*aError*/)
       
   569     {
       
   570     TRACER( "CGlxContentHarvesterPluginTags::HandleError" );    
       
   571 
       
   572 #ifdef _DEBUG
       
   573     if(iMediaList)
       
   574         {
       
   575         TInt count=iMediaList->Count();
       
   576         GLX_LOG_INFO1("CGlxContentHarvesterPluginTags::HandleError,count=%d",count);
       
   577         for ( TInt i = 0; i < count ; i++ )
       
   578             {
       
   579             const TGlxMedia& item = iMediaList->Item( i );
       
   580             TInt thumbnailError = GlxErrorManager::HasAttributeErrorL(
       
   581                     item.Properties(), KGlxMediaIdThumbnail );
       
   582             GLX_LOG_INFO1("CGlxContentHarvesterPluginTags::HandleError,Error=%d ",thumbnailError);
       
   583 
       
   584             }
       
   585         }
       
   586 #endif
       
   587     }
       
   588 
       
   589 // ---------------------------------------------------------------------------
       
   590 // CGlxContentHarvesterPluginTags::Count
       
   591 // ---------------------------------------------------------------------------
       
   592 //
       
   593 TInt CGlxContentHarvesterPluginTags::Count()
       
   594     {
       
   595     TRACER( "CGlxContentHarvesterPluginTags::Count" );    
       
   596     TInt count = KErrNone;
       
   597     if(iMediaList)
       
   598         {
       
   599         count = iMediaList->Count();
       
   600         GLX_LOG_INFO1("GlxCHP:Tags::Count(%d)",count);
       
   601         }
       
   602     return count;
       
   603     }
       
   604 //  End of File
       
   605