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