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