photosgallery/contentharvesterplugin/src/glxcontentharvesterpluginmonths.cpp
changeset 2 7d9067c6fcb1
parent 1 9ba538e329bd
equal deleted inserted replaced
1:9ba538e329bd 2:7d9067c6fcb1
    37 
    37 
    38 #include "glxcontentharvesterpluginmonths.h"
    38 #include "glxcontentharvesterpluginmonths.h"
    39 #include "glxcontentharvesterplugin.hrh"
    39 #include "glxcontentharvesterplugin.hrh"
    40 #include "glxmapconstants.h"
    40 #include "glxmapconstants.h"
    41 
    41 
       
    42 
    42 // ============================ MEMBER FUNCTIONS ==============================
    43 // ============================ MEMBER FUNCTIONS ==============================
    43 LOCAL_C TInt TimerCallbackL( TAny* aPtr )
       
    44     {
       
    45     TRACER( "CGlxContentHarvesterPluginMonths::TimerCallbackL" );
       
    46     static_cast<CGlxContentHarvesterPluginMonths*>(aPtr)->UpdateDataL();
       
    47     return KErrNone;
       
    48     }
       
    49 
    44 
    50 // ----------------------------------------------------------------------------
    45 // ----------------------------------------------------------------------------
    51 // Constructor
    46 // Constructor
    52 // ----------------------------------------------------------------------------
    47 // ----------------------------------------------------------------------------
    53 //
    48 //
    70     TRACER( "CGlxContentHarvesterPluginMonths::ConstructL" );
    65     TRACER( "CGlxContentHarvesterPluginMonths::ConstructL" );
    71 
    66 
    72     //Call the base class ConstructL to create default bitmap
    67     //Call the base class ConstructL to create default bitmap
    73     CGlxContentHarvesterPluginBase::ConstructL(EMbmGlxiconsQgn_prop_image_notcreated);
    68     CGlxContentHarvesterPluginBase::ConstructL(EMbmGlxiconsQgn_prop_image_notcreated);
    74 
    69 
    75     iPeriodic = CPeriodic::NewL( CActive::EPriorityLow );
       
    76     
       
    77     iUriAttributeContext = new (ELeave) CGlxAttributeContext(&iThumbnailIterator); 
    70     iUriAttributeContext = new (ELeave) CGlxAttributeContext(&iThumbnailIterator); 
    78     iThumbnailAttributeContext = new (ELeave) CGlxAttributeContext(&iThumbnailIterator); 
    71     iThumbnailAttributeContext = new (ELeave) CGlxAttributeContext(&iThumbnailIterator); 
    79 
    72 
    80     //Register/Subscribe with matrix menu for the notifications 
    73     //Register/Subscribe with matrix menu for the notifications 
    81     GetInterfaceForNotificationL();
    74     GetInterfaceForNotificationL();
   105 //
    98 //
   106 CGlxContentHarvesterPluginMonths::~CGlxContentHarvesterPluginMonths()
    99 CGlxContentHarvesterPluginMonths::~CGlxContentHarvesterPluginMonths()
   107     {
   100     {
   108     TRACER( "CGlxContentHarvesterPluginMonths::~CGlxContentHarvesterPluginMonths" );
   101     TRACER( "CGlxContentHarvesterPluginMonths::~CGlxContentHarvesterPluginMonths" );
   109     DestroyMedialist();
   102     DestroyMedialist();
   110     if ( iPeriodic )
       
   111         {
       
   112         iPeriodic->Cancel();
       
   113         }
       
   114     delete iPeriodic;
       
   115 
       
   116     }
   103     }
   117 
   104 
   118 // ----------------------------------------------------------------------------
   105 // ----------------------------------------------------------------------------
   119 // CGlxContentHarvesterPluginMonths::UpdateDataL()
   106 // CGlxContentHarvesterPluginMonths::UpdateDataL()
   120 // ----------------------------------------------------------------------------
   107 // ----------------------------------------------------------------------------
   121 //
   108 //
   122 void CGlxContentHarvesterPluginMonths::UpdateDataL() 
   109 void CGlxContentHarvesterPluginMonths::UpdateDataL() 
   123     {
   110     {
   124     TRACER( "CGlxContentHarvesterPluginMonths::UpdateDataL" );
   111     TRACER( "CGlxContentHarvesterPluginMonths::UpdateDataL" );
   125     if(iMediaList && iMediaList->Count() && iPreviewItemCount.Count() )
   112     
   126         {
   113     if (!iMediaList)
   127         GLX_LOG_INFO1("CGlxContentHarvesterPluginMonths::UpdateDataL(),iProgressIndex=%d",iProgressIndex);
   114         {
   128         TInt ret = UpdateItem(iPreviewItemCount[iProgressIndex]);
   115         return;
       
   116         }
       
   117     
       
   118     if (iMediaList->Count())
       
   119         {
       
   120         TInt ret = UpdateItem(KPreviewItemIndex);
   129         if(ret != KErrNotFound)
   121         if(ret != KErrNotFound)
   130             {
   122             {
   131             //Updates the thumbnail in the collection 
   123             //Updates the thumbnail in the collection 
   132             UpdateDataInCPSL(ret);
   124             UpdateDataInCPSL(ret);
   133             }
       
   134         else
       
   135             {
       
   136             UpdateDataInCPSL(GetBitmapHandle());
       
   137             }
   125             }
   138         }
   126         }
   139     else
   127     else
   140         {
   128         {
   141         // Show previous thumbnail until the new thumbnail is
   129         // Show previous thumbnail until the new thumbnail is
   163     HandleStateChangeL(KItemIndexMonths);
   151     HandleStateChangeL(KItemIndexMonths);
   164     return KErrNone;
   152     return KErrNone;
   165     }
   153     }
   166 
   154 
   167 // ----------------------------------------------------------------------------
   155 // ----------------------------------------------------------------------------
   168 // CGlxContentHarvesterPluginMonths::HandleItemChanged()
       
   169 // ----------------------------------------------------------------------------
       
   170 //
       
   171 void CGlxContentHarvesterPluginMonths::HandleItemChanged()
       
   172     {
       
   173     TRACER("CGlxContentHarvesterPluginMonths::HandleItemChanged");
       
   174 
       
   175     iProgressIndex = 0;
       
   176     iPreviewItemCount.Reset();
       
   177 
       
   178     TSize gridIconSize = GetGridIconSize();
       
   179     TMPXAttribute thumbnailAttribute(KGlxMediaIdThumbnail, 
       
   180             GlxFullThumbnailAttributeId( ETrue,  gridIconSize.iWidth, gridIconSize.iHeight ) );
       
   181     if(iMediaList)  
       
   182         {
       
   183         TInt count = iMediaList->Count();
       
   184         GLX_LOG_INFO1("CGlxContentHarvesterPluginMonths:: HandleItemChanged ,count=%d",count);
       
   185 
       
   186         TBool inFocus = IsFocused();
       
   187         for(TInt aItemIndex = 0; aItemIndex < count; aItemIndex++)
       
   188             {
       
   189             const TGlxMedia& item = iMediaList->Item( aItemIndex );
       
   190             const CGlxThumbnailAttribute* value = item.ThumbnailAttribute( thumbnailAttribute );
       
   191             if (value)
       
   192                 {
       
   193                 iPreviewItemCount.InsertInOrder(aItemIndex);
       
   194                 if(!inFocus)
       
   195                     {
       
   196                     //if the collection is NOT in Focus,retrieve only one thumbnail and break
       
   197                     GLX_LOG_INFO1("CGlxContentHarvesterPluginMonths::HandleItemChanged,Range=1,aItemIndex=%d",aItemIndex);
       
   198                     break;
       
   199                     }
       
   200                 else if(iPreviewItemCount.Count() == KPreviewThumbnailFetchCount ||
       
   201                         iPreviewItemCount.Count() == count )
       
   202                     {
       
   203                     //if the collection is not in Focus,retrieve 15 thumbnail and break
       
   204                     GLX_LOG_INFO1("CGlxContentHarvesterPluginMonths::HandleItemChanged,Range=15,aItemIndex=%d",aItemIndex);
       
   205                     break;
       
   206                     }
       
   207 
       
   208                 }
       
   209             }
       
   210         }
       
   211     }
       
   212 
       
   213 // ----------------------------------------------------------------------------
       
   214 // CGlxContentHarvesterPluginMonths::UpdateDataInCPSL()
   156 // CGlxContentHarvesterPluginMonths::UpdateDataInCPSL()
   215 // ----------------------------------------------------------------------------
   157 // ----------------------------------------------------------------------------
   216 // 
   158 // 
   217 void CGlxContentHarvesterPluginMonths::UpdateDataInCPSL(TInt aHandle) 
   159 void CGlxContentHarvesterPluginMonths::UpdateDataInCPSL(TInt aHandle) 
   218     {
   160     {
   249             GlxFullThumbnailAttributeId( ETrue,  gridIconSize.iWidth, gridIconSize.iHeight ) );
   191             GlxFullThumbnailAttributeId( ETrue,  gridIconSize.iWidth, gridIconSize.iHeight ) );
   250     GLX_LOG_INFO1("CGlxContentHarvesterPluginMonths::UpdateItem,aItemIndex=%d ",aItemIndex);
   192     GLX_LOG_INFO1("CGlxContentHarvesterPluginMonths::UpdateItem,aItemIndex=%d ",aItemIndex);
   251     const CGlxThumbnailAttribute* value = item.ThumbnailAttribute( thumbnailAttribute );
   193     const CGlxThumbnailAttribute* value = item.ThumbnailAttribute( thumbnailAttribute );
   252     if (value)
   194     if (value)
   253         {
   195         {
   254         GLX_LOG_INFO1("CGlxContentHarvesterPluginMonths::UpdateItem,iProgressIndex=%d ",iProgressIndex);
       
   255         iProgressIndex++;
       
   256         if (iProgressIndex >= KPreviewThumbnailFetchCount || 
       
   257                 iProgressIndex >= iPreviewItemCount.Count() ||
       
   258                 iProgressIndex >= iMediaList->Count())
       
   259             {
       
   260             iProgressIndex = 0;
       
   261             }
       
   262         return value->iBitmap->Handle();
   196         return value->iBitmap->Handle();
   263         }
   197         }
   264     return KErrNotFound;
   198     return KErrNotFound;
   265     }
   199     }
   266 
   200 
   273     TRACER( "CGlxContentHarvesterPluginMonths::ActivateL" );
   207     TRACER( "CGlxContentHarvesterPluginMonths::ActivateL" );
   274 
   208 
   275     GLX_LOG_INFO1("CGlxContentHarvesterPluginMonths::ActivateL aOn =%d",aOn);
   209     GLX_LOG_INFO1("CGlxContentHarvesterPluginMonths::ActivateL aOn =%d",aOn);
   276     SetFocus(aOn);
   210     SetFocus(aOn);
   277 
   211 
   278     if (IsMatrixMenuInForegroundL() && aOn && !iPeriodic->IsActive() )
   212     if (IsMatrixMenuInForegroundL() && aOn )
   279         {
   213         {
   280         if(GetCHPlugin()->IsRefreshNeeded())
   214         if(GetCHPlugin()->IsRefreshNeeded())
   281             {
   215             {
   282             //Update the rest of all the collections on receving the focus...
   216             //Update the rest of all the collections on receving the focus...
   283             GetCHPlugin()->UpdatePlugins(aOn);     
   217             GetCHPlugin()->UpdatePlugins(aOn);     
   286             {
   220             {
   287             //As the collection is not updated by the contentharvester plugin
   221             //As the collection is not updated by the contentharvester plugin
   288             //to update the thumbnails on the focus , need to call the below function
   222             //to update the thumbnails on the focus , need to call the below function
   289             UpdatePreviewThumbnailListL();
   223             UpdatePreviewThumbnailListL();
   290             }
   224             }
   291 
       
   292         iPeriodic->Start( KTimerInterval, 
       
   293                 KTimerInterval, 
       
   294                 TCallBack( TimerCallbackL, this ) );
       
   295         }
   225         }
   296     else if ( !aOn )
   226     else if ( !aOn )
   297         {
   227         {
   298           if(!IsMatrixMenuInForegroundL())
   228           if(!IsMatrixMenuInForegroundL())
   299             {
   229             {
   300             //use case:Matrix Menu is exited, by entering into grid view,application view,capture mode...
   230             //use case:Matrix Menu is exited, by entering into grid view,application view,capture mode...
   301             //Need to destroy all the collection's observers and context
   231             //Need to destroy all the collection's observers and context
   302             GLX_LOG_INFO1("CGlxContentHarvesterPluginMonths::ActivateL !aOn =%d and matrix not in foreground",aOn);
   232             GLX_LOG_INFO1("CGlxContentHarvesterPluginMonths::ActivateL !aOn =%d and matrix not in foreground",aOn);
   303             GetCHPlugin()->UpdatePlugins(aOn);
   233             GetCHPlugin()->UpdatePlugins(aOn);
   304             }
   234             }
   305         iPeriodic->Cancel();
       
   306         }
   235         }
   307     }
   236     }
   308 
   237 
   309 // ----------------------------------------------------------------------------
   238 // ----------------------------------------------------------------------------
   310 // CGlxContentHarvesterPluginMonths::HandleItemAddedL
   239 // CGlxContentHarvesterPluginMonths::HandleItemAddedL
   367         const TGlxMedia& item = aList->Item( aItemIndex );
   296         const TGlxMedia& item = aList->Item( aItemIndex );
   368         const CGlxThumbnailAttribute* value = item.ThumbnailAttribute( thumbnailAttribute );
   297         const CGlxThumbnailAttribute* value = item.ThumbnailAttribute( thumbnailAttribute );
   369         if (value)
   298         if (value)
   370             {
   299             {
   371             GLX_LOG_INFO("CGlxContentHarvesterPluginMonths::HandleAttributesAvailableL Thumbnail is present ");
   300             GLX_LOG_INFO("CGlxContentHarvesterPluginMonths::HandleAttributesAvailableL Thumbnail is present ");
   372             iPreviewItemCount.InsertInOrder(aItemIndex);
   301 
   373 
   302 			// Update the preview thumbnail
   374             //if the collection on the matrix menu is not focused,then show only one thumbnail
   303 			//remove the observer as client need not listen to the callbacks 
   375             if(!IsFocused())
       
   376                 {
       
   377                 GLX_LOG_INFO("CGlxContentHarvesterPluginMonths::HandleAttributesAvailableL,one thumbnail fetched");
   304                 GLX_LOG_INFO("CGlxContentHarvesterPluginMonths::HandleAttributesAvailableL,one thumbnail fetched");
   378                 UpdateDataInCPSL( value->iBitmap->Handle());
   305 			UpdateDataInCPSL( value->iBitmap->Handle());           
   379                 //if one thumbnail is fetched,it is sufficent when the collection is not in focus.
   306 			iMediaList->RemoveMediaListObserver( this );
   380                 //remove the observer as client need not listen to the callbacks 
       
   381                 iMediaList->RemoveMediaListObserver( this );
       
   382                 }
       
   383             else if (iPreviewItemCount.Count()  == KPreviewThumbnailFetchCount || 
       
   384                     iPreviewItemCount.Count() == aList->Count() )
       
   385                 {
       
   386                 GLX_LOG_INFO1("CGlxContentHarvesterPluginMonths::HandleAttributesAvailableL,media list count=%d",aList->Count());
       
   387                 //if the PreviewItemCount  equals 15 or if it is eqaul to the total count
       
   388                 //remove the observer as client need not listen to the callbacks
       
   389                 iMediaList->RemoveMediaListObserver( this );
       
   390                 }
       
   391             }//end of  check against value 
   307             }//end of  check against value 
   392         }//end of  attribute match
   308         }//end of  attribute match
   393     }
   309     }
   394 
   310 
   395 // ---------------------------------------------------------------------------
   311 // ---------------------------------------------------------------------------
   457 void CGlxContentHarvesterPluginMonths::CreateMedialistL( )
   373 void CGlxContentHarvesterPluginMonths::CreateMedialistL( )
   458     {
   374     {
   459     TRACER( "CGlxContentHarvesterPluginMonths::CreateMedialistL" );
   375     TRACER( "CGlxContentHarvesterPluginMonths::CreateMedialistL" );
   460     if(!iMediaList)
   376     if(!iMediaList)
   461         {
   377         {
   462         //if the collection is in focus then , create media list with context of 15 items else
   378 		iThumbnailIterator.SetRange( KSinglePreviewThumbnail );
   463         // with context of single item.
       
   464         if(IsFocused())
       
   465             {
       
   466             iThumbnailIterator.SetRange( KPreviewThumbnailFetchCount ); 
       
   467             }
       
   468         else
       
   469             {
       
   470             iThumbnailIterator.SetRange( KSinglePreviewThumbnail );
       
   471             }
       
   472 
   379 
   473         iMediaList = CreateMedialistAndAttributeContextL( TGlxMediaId( 
   380         iMediaList = CreateMedialistAndAttributeContextL( TGlxMediaId( 
   474                 KGlxCollectionPluginMonthsImplementationUid ), 
   381                 KGlxCollectionPluginMonthsImplementationUid ), 
   475                 iUriAttributeContext,iThumbnailAttributeContext);
   382                 iUriAttributeContext,iThumbnailAttributeContext);
   476         AddContextAndObserverL();
   383         AddContextAndObserverL();
   487 
   394 
   488     //when there is an update of content in the collection
   395     //when there is an update of content in the collection
   489     //this function is executed or when the collection recives the focus. 
   396     //this function is executed or when the collection recives the focus. 
   490     if(!iMediaList)
   397     if(!iMediaList)
   491         {
   398         {
   492         //medis list is not created yet,create it.
   399         //media list is not created yet,create it.
   493         CreateMedialistL( );
   400         CreateMedialistL( );
   494         //This is called to show the preview thumbnails. If no thumbnails are
       
   495         //present, display nothing 
       
   496         UpdateDataL();
   401         UpdateDataL();
   497         }
   402         }
   498     else
   403     else
   499         {
   404         {
   500         if(GetCHPlugin()->IsRefreshNeeded())
   405         if(GetCHPlugin()->IsRefreshNeeded())
   501             {
   406             {
   502             ContainerCacheCleanupL(iMediaList);
   407             ContainerCacheCleanupL(iMediaList);
   503             }  
   408             }  
   504         if(IsFocused())
   409 
   505 	        {
       
   506 	        //1.This loop is executed,when the collection gets focus
       
   507 	        //2.This loop is executed,when the contents are updated for this collection
       
   508 	        //and this collection has focus,so 15 thumbnails are fetched.
       
   509 	        HandleItemChanged();
       
   510 	        iThumbnailIterator.SetRange( KPreviewThumbnailFetchCount );
       
   511 	        RemoveContextAndObserver();
       
   512 	        AddContextAndObserverL();
       
   513 	        }
       
   514 	    else
       
   515 	        {
       
   516 	        //1.This loop is executed,when the contents are updated for this collection
       
   517 	        //and this collection doesn't have the focus,so only one thumbnail is fetched.
       
   518 
       
   519 	        //here we need to fetch only one item 
       
   520 	        //1.if the content is deleted,then creating a context doesn't fetch the attributes
   410 	        //1.if the content is deleted,then creating a context doesn't fetch the attributes
   521 	        //2.if the content is added and the content is not the latest as per the sorted order of the
   411 	        //2.if the content is added and the content is not the latest as per the sorted order of the
   522 	        // media list,then the thumbnails are not fetched.
   412 	        // media list,then the thumbnails are not fetched.
   523 	        // so show the first available thumbnail in the media list.
   413 	        // so show the first available thumbnail in the media list.
   524 
   414 
   525 	        HandleItemChanged();
       
   526 	        UpdateDataL();
   415 	        UpdateDataL();
   527 
   416 
   528 	        //Adding the context doesn't gaurantee we get a call back for
   417 	        //Adding the context doesn't gaurantee we get a call back for
   529 	        //Handle attributes available,if the latest item is already fetched.
   418 	        //Handle attributes available,if the latest item is already fetched.
   530 	        //and for the content added for this collection,if it is not latest
   419 	        //and for the content added for this collection,if it is not latest
   534 
   423 
   535 	        iThumbnailIterator.SetRange( KSinglePreviewThumbnail );
   424 	        iThumbnailIterator.SetRange( KSinglePreviewThumbnail );
   536 	        RemoveContextAndObserver();
   425 	        RemoveContextAndObserver();
   537 	        AddContextAndObserverL();
   426 	        AddContextAndObserverL();
   538 			}
   427 			}
   539         }
   428 	
   540     }
   429     }
   541 
   430 
   542 
   431 
   543 // ---------------------------------------------------------------------------
   432 // ---------------------------------------------------------------------------
   544 // CGlxContentHarvesterPluginAlbums::AddContextAndObserverL
   433 // CGlxContentHarvesterPluginAlbums::AddContextAndObserverL