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