imagehandlingutilities/thumbnailmanager/thumbagdaemon/src/thumbagprocessor.cpp
changeset 14 2edacbf5d3f9
parent 0 2014ca87e772
child 15 7197e789b953
equal deleted inserted replaced
1:235a7fc86938 14:2edacbf5d3f9
    19 #include <e32base.h>
    19 #include <e32base.h>
    20 
    20 
    21 #include <mdeconstants.h>
    21 #include <mdeconstants.h>
    22 #include <centralrepository.h>
    22 #include <centralrepository.h>
    23 
    23 
       
    24 #include <mpxcollectionutility.h>
       
    25 #include <mpxmessagegeneraldefs.h>
       
    26 #include <mpxcollectionmessage.h>
       
    27 #include <coreapplicationuisdomainpskeys.h> 
       
    28 
    24 #include "thumbagprocessor.h"
    29 #include "thumbagprocessor.h"
    25 #include "thumbnaillog.h"
    30 #include "thumbnaillog.h"
    26 #include "thumbnailmanagerconstants.h"
    31 #include "thumbnailmanagerconstants.h"
    27 #include "thumbnailmanagerprivatecrkeys.h"
    32 #include "thumbnailmanagerprivatecrkeys.h"
    28 #include "thumbagformatobserver.h"
       
    29 #include <mpxcollectionutility.h>
       
    30 #include <mpxmessagegeneraldefs.h>
       
    31 #include <mpxcollectionmessage.h>
       
    32 
    33 
    33 // ---------------------------------------------------------------------------
    34 // ---------------------------------------------------------------------------
    34 // CThumbAGProcessor::NewL()
    35 // CThumbAGProcessor::NewL()
    35 // ---------------------------------------------------------------------------
    36 // ---------------------------------------------------------------------------
    36 //
    37 //
    62 //
    63 //
    63 void CThumbAGProcessor::ConstructL()
    64 void CThumbAGProcessor::ConstructL()
    64     {
    65     {
    65     TN_DEBUG1( "CThumbAGProcessor::ConstructL() - begin" );
    66     TN_DEBUG1( "CThumbAGProcessor::ConstructL() - begin" );
    66     
    67     
    67 #ifdef _DEBUG
       
    68     iAddCounter = 0;
       
    69     iModCounter = 0;
       
    70     iDelCounter = 0;
       
    71 #endif
       
    72     
       
    73     iTMSession = CThumbnailManager::NewL( *this );
    68     iTMSession = CThumbnailManager::NewL( *this );
    74     
    69     iQueryAllItems = NULL;
       
    70     iQueryPlaceholders = NULL;
    75     iQuery = NULL;
    71     iQuery = NULL;
    76     iQueryActive = EFalse;
    72     iQueryActive = EFalse;
    77     iModify = EFalse;
    73     iModify = EFalse;
    78     iProcessingCount = 0;
    74     iProcessingCount = 0;
    79     
    75     
    82     // set auto create values from cenrep
    78     // set auto create values from cenrep
    83     CheckAutoCreateValuesL();
    79     CheckAutoCreateValuesL();
    84     
    80     
    85     iPeriodicTimer = CPeriodic::NewL(CActive::EPriorityIdle);
    81     iPeriodicTimer = CPeriodic::NewL(CActive::EPriorityIdle);
    86     
    82     
    87     //do some initializing async in RunL()
    83     SetForceRun( EFalse );    
    88     iInit = ETrue;
       
    89     iForceRun = EFalse;    
       
    90     iActive = EFalse;
    84     iActive = EFalse;
    91     
    85     
    92     iFormatObserver = CThumbAGFormatObserver::NewL( this );
    86     iFormatObserver = CTMFormatObserver::NewL( *this );
    93        
    87        
    94     iFormatting = EFalse;     
    88     iFormatting = EFalse;     
    95     iSessionDied = EFalse;
    89     iSessionDied = EFalse;
    96     
    90     
    97     iCollectionUtility = NULL;
    91     iCollectionUtility = NULL;
    98         
    92     
       
    93     iActivityManager = CTMActivityManager::NewL( this, KBackgroundGenerationIdle);
       
    94 
       
    95     UpdatePSValues(ETrue);
       
    96 
       
    97     if(iForegroundGenerationObserver)
       
    98       {
       
    99       delete iForegroundGenerationObserver;
       
   100       iForegroundGenerationObserver = NULL;
       
   101       }
       
   102     
       
   103     RProperty::Define(KTAGDPSNotification, KMPXHarvesting, RProperty::EInt);
       
   104     
       
   105 	//start foreground generation observer
       
   106     iForegroundGenerationObserver = CTMRPropertyObserver::NewL( *this, KTAGDPSNotification, KForceBackgroundGeneration, ETrue );  
       
   107     
    99     TN_DEBUG1( "CThumbAGProcessor::ConstructL() - end" );
   108     TN_DEBUG1( "CThumbAGProcessor::ConstructL() - end" );
   100     }
   109     }
   101 
   110 
   102 // ---------------------------------------------------------------------------
   111 // ---------------------------------------------------------------------------
   103 // CThumbAGProcessor::~CThumbAGProcessor()
   112 // CThumbAGProcessor::~CThumbAGProcessor()
   104 // ---------------------------------------------------------------------------
   113 // ---------------------------------------------------------------------------
   105 //
   114 //
   106 CThumbAGProcessor::~CThumbAGProcessor()
   115 CThumbAGProcessor::~CThumbAGProcessor()
   107     {
   116     {
   108     TN_DEBUG1( "CThumbAGProcessor::~CThumbAGProcessor() - begin" );
   117     TN_DEBUG1( "CThumbAGProcessor::~CThumbAGProcessor() - begin" );
       
   118     
       
   119     if(iForegroundGenerationObserver)
       
   120       {
       
   121       delete iForegroundGenerationObserver;
       
   122       iForegroundGenerationObserver = NULL;
       
   123       }
       
   124     
       
   125     if(iActivityManager)
       
   126         {
       
   127         delete iActivityManager;
       
   128         iActivityManager = NULL;
       
   129         }
       
   130     
       
   131     if (iInactivityTimer)
       
   132         {
       
   133         iInactivityTimer->Cancel();
       
   134         delete iInactivityTimer;
       
   135         iInactivityTimer = NULL;
       
   136         }
   109     
   137     
   110     if(iPeriodicTimer)
   138     if(iPeriodicTimer)
   111         {
   139         {
   112         iPeriodicTimer->Cancel();
   140         iPeriodicTimer->Cancel();
   113         delete iPeriodicTimer;
   141         delete iPeriodicTimer;
   114         }
   142         }
   115     
   143     
   116     if (!iInit)
   144     if (!iInit)
   117         {
   145         {
       
   146     /*
   118         iHarvesterClient.RemoveHarvesterEventObserver(*this);
   147         iHarvesterClient.RemoveHarvesterEventObserver(*this);
   119         iHarvesterClient.Close();
   148         iHarvesterClient.Close();*/
   120         }
   149         }
   121     
   150     
   122     if ( iCollectionUtility )
   151     if ( iCollectionUtility )
   123         {
   152         {
   124         iCollectionUtility->Close();
   153         iCollectionUtility->Close();
   125         iCollectionUtility = NULL;
   154         iCollectionUtility = NULL;
   126         }
   155         }
   127 
   156 
   128     Cancel();
   157     Cancel();
       
   158     
       
   159     if(iQueryPlaceholders)
       
   160         {
       
   161         iQueryPlaceholders->Cancel();
       
   162         delete iQueryPlaceholders;
       
   163         iQueryPlaceholders = NULL;
       
   164         }
   129     
   165     
   130     if (iQuery)
   166     if (iQuery)
   131         {
   167         {
   132         iQuery->Cancel();
   168         iQuery->Cancel();
   133         delete iQuery;
   169         delete iQuery;
   134         iQuery = NULL;
   170         iQuery = NULL;
   135         }
   171         }
   136     
   172     
   137     if (iQueryForPlaceholders)
   173     if (iQueryAllItems)
   138        {
   174        {
   139        iQueryForPlaceholders->Cancel();
   175        iQueryAllItems->Cancel();
   140        delete iQueryForPlaceholders;
   176        delete iQueryAllItems;
   141        iQueryForPlaceholders = NULL;
   177        iQueryAllItems = NULL;
   142        }
   178        }
   143     
   179 
   144     iAddQueue.Close();
   180     iAddQueue.Close();
   145     iModifyQueue.Close();
   181     iModifyQueue.Close();
   146     iRemoveQueue.Close();
   182     iRemoveQueue.ResetAndDestroy();
   147     iQueryQueue.Close();
   183     iQueryQueue.Close();
   148     iPresentQueue.Close();
   184     iPlaceholderQueue.Close();
   149     iTempModifyQueue.Close();
   185 	  
   150     iTempAddQueue.Close();
   186     i2ndRoundGenerateQueue.Close();
   151     iPlaceholderIDs.Close();
       
   152     
   187     
   153     if (iTMSession)
   188     if (iTMSession)
   154         {
   189         {
   155         delete iTMSession;
   190         delete iTMSession;
   156         iTMSession = NULL;
   191         iTMSession = NULL;
   174 
   209 
   175 // -----------------------------------------------------------------------------
   210 // -----------------------------------------------------------------------------
   176 // CThumbAGProcessor::HandleQueryCompleted()
   211 // CThumbAGProcessor::HandleQueryCompleted()
   177 // -----------------------------------------------------------------------------
   212 // -----------------------------------------------------------------------------
   178 //
   213 //
   179 void CThumbAGProcessor::HandleQueryCompleted( CMdEQuery& /*aQuery*/, const TInt aError )
   214 void CThumbAGProcessor::HandleQueryCompleted( CMdEQuery& aQuery, const TInt aError )
   180     {
   215     {
   181 
   216     TN_DEBUG3( "CThumbAGProcessor::HandleQueryCompleted, aError == %d Count== %d", aError, aQuery.Count());
   182     if( iQueryForPlaceholdersActive && iQueryForPlaceholders)
   217     
   183         {
   218     if(&aQuery == iQueryPlaceholders)
   184         TN_DEBUG3( "CThumbAGProcessor::HandleQueryCompletedv2, aError == %d Count== %d", aError, iQueryForPlaceholders->Count());
   219         {
   185         
   220         TN_DEBUG1( "CThumbAGProcessor::HandleQueryCompleted - iQueryPlaceholders completed");
       
   221         
       
   222         iPlaceholderQueue.Reset();
   186         // if no errors in query
   223         // if no errors in query
   187         if (aError == KErrNone )
   224         if (aError == KErrNone )
   188             {
   225             {
   189             
   226             for(TInt i = 0; i < iQueryPlaceholders->Count(); i++)
   190             for(TInt i = 0; i < iQueryForPlaceholders->Count(); i++)
   227                {    
       
   228                const CMdEObject* object = &iQueryPlaceholders->Result(i);
       
   229               
       
   230                if(!object)
       
   231                    {
       
   232                    continue;
       
   233                    }
       
   234               
       
   235                if(!object->Placeholder())
       
   236                    {
       
   237                    TN_DEBUG2( "CThumbAGProcessor::HandleQueryCompleted %d not placeholder", object->Id());
       
   238                    continue;
       
   239                    }
       
   240               
       
   241                /*if (iPlaceholderQueue.Find( object->Id() ) == KErrNotFound)
       
   242                    {
       
   243                    TN_DEBUG2( "CThumbAGProcessor::HandleQueryCompleted %d added to placeholder queue", object->Id());*/
       
   244                    TRAP_IGNORE( iPlaceholderQueue.AppendL( object->Id() )); 
       
   245                  //}
       
   246                }
       
   247            }
       
   248            delete iQueryPlaceholders;
       
   249            iQueryPlaceholders = NULL;
       
   250         }
       
   251     else if(&aQuery == iQueryAllItems)
       
   252         {
       
   253         TN_DEBUG1( "CThumbAGProcessor::HandleQueryCompleted - QueryAllItems completed");
       
   254         // if no errors in query
       
   255         if (aError == KErrNone )
       
   256             {
       
   257             for(TInt i = 0; i < iQueryAllItems->Count(); i++)
   191                 {    
   258                 {    
   192                 const CMdEObject* object = &iQueryForPlaceholders->Result(i);
   259                 const CMdEObject* object = &iQueryAllItems->Result(i);
   193                 
   260                
   194                 if(!object)
   261                 if(!object)
   195                     continue;
       
   196                 
       
   197                 if(!object->Placeholder())
       
   198                     {
   262                     {
   199                     TN_DEBUG2( "CThumbAGProcessor::HandleQueryCompletedv2 %d not placeholder",object->Id());
       
   200                     continue;
   263                     continue;
   201                     }
   264                     }
   202                 
   265                
   203                 if (iPlaceholderIDs.Find( object->Id() ) == KErrNotFound)
   266                 if (iAddQueue.Find( object->Id() ) == KErrNotFound && iModifyQueue.Find( object->Id()) == KErrNotFound  )
   204                    {
   267                     {
   205                    TRAP_IGNORE( iPlaceholderIDs.AppendL( object->Id() )); 
   268                     TRAP_IGNORE( iAddQueue.AppendL( object->Id() ));
   206                    }
   269                     }
   207                 }
   270                 }
   208                 
   271 #ifdef _DEBUG
   209             }
   272 TN_DEBUG2( "CThumbAGProcessor::HandleQueryCompleted IN-COUNTERS---------- Amount: %d, Add",iQueryAllItems->Count());
   210         else
   273 #endif
   211             {
   274             }
   212             TN_DEBUG1( "CThumbAGProcessor::HandleQueryCompleted() FAILED!");   
   275             //free query
   213             }
   276             delete iQueryAllItems;
   214         
   277             iQueryAllItems = NULL;
   215         iQueryForPlaceholdersActive = EFalse;
   278         }
   216         }
   279     else if(&aQuery == iQuery )
   217     
   280         {
   218     else if(iQueryActive)
   281         TN_DEBUG1( "CThumbAGProcessor::HandleQueryCompleted - Query completed");
   219         {
   282         
   220         TN_DEBUG3( "CThumbAGProcessor::HandleQueryCompleted, aError == %d Count== %d", aError, iQuery->Count());
   283         if(iQueryActive)
   221         iQueryReady = ETrue;
   284             {
   222         iQueryActive = EFalse;
   285             iQueryReady = ETrue;
       
   286             iQueryActive = EFalse;
       
   287             }
   223     
   288     
   224         // if no errors in query
   289         // if no errors in query
   225         if (aError == KErrNone && iQuery)
   290         if (aError == KErrNone && iQuery)
   226             {
   291             {
   227             iProcessingCount = iQuery->Count();
   292             iProcessingCount = iQuery->Count();
       
   293 			
       
   294             if( !iProcessingCount)
       
   295                 {
       
   296                 delete iQuery;
       
   297                 iQuery = NULL;
       
   298                 iProcessingCount = 0;
       
   299                 iModify = EFalse;
       
   300                 }
   228             }
   301             }
   229         else
   302         else
   230             {
   303             {
       
   304             TInt itemIndex(KErrNotFound);
       
   305             
       
   306             //cleanup current queue
       
   307             while(iQueryQueue.Count())
       
   308                 {
       
   309                 itemIndex = iLastQueue->Find(iQueryQueue[0]);
       
   310                 if(itemIndex >= 0)
       
   311                     {
       
   312                     iLastQueue->Remove( itemIndex );
       
   313                     }
       
   314                 iQueryQueue.Remove(0);
       
   315                 }
       
   316         
       
   317             delete iQuery;
       
   318             iQuery = NULL;
   231             iProcessingCount = 0;
   319             iProcessingCount = 0;
   232             TN_DEBUG1( "CThumbAGProcessor::HandleQueryCompleted() FAILED!");   
   320             TN_DEBUG1( "CThumbAGProcessor::HandleQueryCompleted() Query FAILED!");   
   233             }
   321             }
   234         }
   322         }
   235     else
   323     else
   236         {
   324         {
   237         TN_DEBUG1( "CThumbAGProcessor::HandleQueryCompleted() - NO QUERY ACTIVE"); 
   325         TN_DEBUG1( "CThumbAGProcessor::HandleQueryCompleted() - NO QUERY ACTIVE"); 
       
   326         __ASSERT_DEBUG((EFalse), User::Panic(_L("CThumbAGProcessor::HandleQueryCompleted()"), -1));
   238         }
   327         }
   239     
   328     
   240     ActivateAO();
   329     ActivateAO();
   241     }
   330     }
   242 
   331 
   245 // -----------------------------------------------------------------------------
   334 // -----------------------------------------------------------------------------
   246 //
   335 //
   247 void CThumbAGProcessor::ThumbnailPreviewReady( MThumbnailData& /*aThumbnail*/, 
   336 void CThumbAGProcessor::ThumbnailPreviewReady( MThumbnailData& /*aThumbnail*/, 
   248                                                TThumbnailRequestId /*aId*/)
   337                                                TThumbnailRequestId /*aId*/)
   249     {
   338     {
       
   339     TN_DEBUG1( "CThumbAGProcessor::ThumbnailPreviewReady()");
   250     // No implementation required
   340     // No implementation required
   251     }
   341     }
   252 
   342 
   253 // -----------------------------------------------------------------------------
   343 // -----------------------------------------------------------------------------
   254 // CThumbAGProcessor::ThumbnailReady()
   344 // CThumbAGProcessor::ThumbnailReady()
   256 //
   346 //
   257 void CThumbAGProcessor::ThumbnailReady( TInt aError, MThumbnailData& /*aThumbnail*/,
   347 void CThumbAGProcessor::ThumbnailReady( TInt aError, MThumbnailData& /*aThumbnail*/,
   258                                         TThumbnailRequestId /*aId*/ )
   348                                         TThumbnailRequestId /*aId*/ )
   259     {
   349     {
   260     TN_DEBUG2( "CThumbAGProcessor::ThumbnailReady() aError == %d", aError );
   350     TN_DEBUG2( "CThumbAGProcessor::ThumbnailReady() aError == %d", aError );
   261  
   351     
   262     iActive = EFalse; 
   352     iActiveCount--;
       
   353     
       
   354     if(iActiveCount <= 0)
       
   355         {
       
   356         iActiveCount = 0;
       
   357         iActive = EFalse;
       
   358         }
   263     
   359     
   264     // TNM server died, delete session
   360     // TNM server died, delete session
   265     if( aError == KErrServerTerminated )
   361     if( aError == KErrServerTerminated )
   266         {
   362         {
   267         TN_DEBUG1( "CThumbAGProcessor::ThumbnailReady() - **** THUMBNAIL SERVER DIED ****" );
   363         TN_DEBUG1( "CThumbAGProcessor::ThumbnailReady() - **** THUMBNAIL SERVER DIED ****" );
   268 		
   364 		
   269         iSessionDied = ETrue;
   365         iSessionDied = ETrue;
   270         
   366         
   271         if( !iTimerActive)
   367         if( !iPeriodicTimer->IsActive())
   272             {
   368             {
   273             StartTimeout();
   369             StartTimeout();
   274 			}
   370 			}
   275 			
   371 			
   276         //reset PS idle so that RunL() can startup reopen TNM session and proceed
   372         //reset PS idle so that RunL() can startup reopen TNM session and proceed
   279         
   375         
   280         return;
   376         return;
   281         }
   377         }
   282     
   378     
   283     ActivateAO();
   379     ActivateAO();
       
   380 	
   284     TN_DEBUG1( "CThumbAGProcessor::ThumbnailReady() - end" );
   381     TN_DEBUG1( "CThumbAGProcessor::ThumbnailReady() - end" );
   285     }
   382     }
   286 
   383 
   287 // ---------------------------------------------------------------------------
   384 // ---------------------------------------------------------------------------
   288 // CThumbAGProcessor::SetMdESession()
   385 // CThumbAGProcessor::SetMdESession()
   291 void CThumbAGProcessor::SetMdESession( CMdESession* aMdESession )
   388 void CThumbAGProcessor::SetMdESession( CMdESession* aMdESession )
   292     {
   389     {
   293     TN_DEBUG1( "CThumbAGProcessor::SetMdESession() - begin" );
   390     TN_DEBUG1( "CThumbAGProcessor::SetMdESession() - begin" );
   294     
   391     
   295     iMdESession = aMdESession;
   392     iMdESession = aMdESession;
       
   393     
       
   394     __ASSERT_DEBUG((iMdESession), User::Panic(_L("CThumbAGProcessor::SetMdESession() !iMdESession "), KErrBadHandle));
   296     
   395     
   297     TRAPD( err, iDefNamespace = &iMdESession->GetDefaultNamespaceDefL() );
   396     TRAPD( err, iDefNamespace = &iMdESession->GetDefaultNamespaceDefL() );
   298     if (err != KErrNone)
   397     if (err != KErrNone)
   299         {
   398         {
   300         TN_DEBUG1( "CThumbAGProcessor::SetMdESession - Error: GetDefaultNamespaceDefL leave" );
   399         TN_DEBUG2( "CThumbAGProcessor::SetMdESession() GetDefaultNamespaceDefL() err = %d", err );
   301         }
   400         }
       
   401     
       
   402     __ASSERT_DEBUG((iDefNamespace), User::Panic(_L("CThumbAGProcessor::SetMdESession() !iDefNamespace "), KErrBadHandle));
       
   403        
       
   404     //do async init
       
   405     iInit = ETrue;
       
   406     
   302 	ActivateAO();
   407 	ActivateAO();
   303     }
   408     }
   304 
   409 
   305 // ---------------------------------------------------------------------------
   410 // ---------------------------------------------------------------------------
   306 // CThumbAGProcessor::AddToQueue()
   411 // CThumbAGProcessor::AddToQueue()
   307 // ---------------------------------------------------------------------------
   412 // ---------------------------------------------------------------------------
   308 //
   413 //
   309 void CThumbAGProcessor::AddToQueueL( TObserverNotificationType aType, 
   414 void CThumbAGProcessor::AddToQueueL( TObserverNotificationType aType, 
   310                                     const RArray<TItemId>& aIDArray, TBool aPresent )
   415                                     const RArray<TItemId>& aIDArray, 
       
   416                                     const RPointerArray<HBufC>& aObjectUriArray,
       
   417                                     TBool /*aPresent*/ )
   311     {
   418     {
   312     TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - begin" );
   419     TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - begin" );
   313     
   420 
   314     if(aPresent)
   421     // update queues
   315         {
   422     if (aType == ENotifyAdd)
   316         TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - Add to SetPresentQueue" );
   423         {
       
   424         TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - ENotifyAdd" );
       
   425         
   317         for (int i=0; i<aIDArray.Count(); i++)
   426         for (int i=0; i<aIDArray.Count(); i++)
   318              {
   427             {
   319              // only add to Present queue if not already in Add or Present queue        
   428             // do not to append to Add queue if exist already in Add or 2nd Add queue (just processed)     
   320               if (iAddQueue.Find( aIDArray[i] ) == KErrNotFound)
   429             if (iAddQueue.Find( aIDArray[i] ) == KErrNotFound && i2ndRoundGenerateQueue.Find( aIDArray[i] ) == KErrNotFound)
   321                   {
   430                 {
   322                   if (iPresentQueue.Find( aIDArray[i] ) == KErrNotFound)
   431                 iAddQueue.AppendL(aIDArray[i]);
   323                       {
   432                 }
   324                       iPresentQueue.AppendL(aIDArray[i]);
   433             }
   325                       }
   434         }
   326                   }
   435     else if (aType == ENotifyModify)
   327              }     
   436         {
   328         }
   437         TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - ENotifyModify" );
   329     // update queues
   438         
   330     else if (aType == ENotifyAdd)
   439         if(iPHHarvesting)
   331         {
   440             {
   332         TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - ENotifyAdd" );
   441         
   333         
   442             TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - PH  harvesting active, treat like add" );
   334         for (int i=0; i<aIDArray.Count(); i++)
   443             for (int i=0; i<aIDArray.Count(); i++)
   335             {
   444                 {
   336             // only add to Add queue if not already in Add queue        
   445                 TInt itemIndex = iPlaceholderQueue.Find( aIDArray[i] );
   337             if (iAddQueue.Find( aIDArray[i] ) == KErrNotFound)
   446                                 
   338                 {
   447                 if (itemIndex >= 0)
   339                 //if in Present Queue remove from there and and put to add queue
       
   340                 TInt index = iPresentQueue.Find( aIDArray[i] );
       
   341                 if( index != KErrNotFound)
       
   342                     {
   448                     {
   343                     iPresentQueue.Remove( index );
   449                     TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - remove from placeholder queue");
       
   450                     iPlaceholderQueue.Remove( itemIndex );
   344                     }
   451                     }
   345                 iAddQueue.AppendL(aIDArray[i]); 
   452                 
   346                 iTempAddQueue.AppendL(aIDArray[i]);
   453                 if(iAddQueue.Find( aIDArray[i]) == KErrNotFound && i2ndRoundGenerateQueue.Find( aIDArray[i]))
   347                 }
   454                     {
   348             }
   455                     TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - append to add queue");
   349         }
   456                     iAddQueue.Append( aIDArray[i]);
   350     else if (aType == ENotifyModify)
   457                     }
   351         {
   458                 }
   352         TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - ENotifyModify" );
   459             }
   353             
   460         else
   354         for (int i=0; i<aIDArray.Count(); i++)
   461             {
   355              {
   462             TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - PH  harvesting finished, check is real modify!" );
   356              TInt itemIndex = iPlaceholderIDs.Find( aIDArray[i] );
   463             
   357              if(itemIndex >= 0 )
   464             TInt itemIndex(KErrNotFound);
   358                  {
   465             
   359                  TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - harvesting now ended for this placeholder - not Real ENotifyModify" );
   466             for (int i=0; i<aIDArray.Count(); i++)
   360                  iPlaceholderIDs.Remove(itemIndex);
   467                 {
   361                  TN_DEBUG2( "CThumbAGProcessor::AddToQueueL() - placeholders left %d", iPlaceholderIDs.Count() );
   468                 itemIndex = iPlaceholderQueue.Find( aIDArray[i] );
   362                  if (iAddQueue.Find( aIDArray[i] ) == KErrNotFound)
   469                 
   363                      {
   470                 if (itemIndex >= 0)
   364                      iAddQueue.AppendL(aIDArray[i]);
   471                     {
   365                      }
   472                     TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - placeholder modify, remove from placeholder queue");
   366                  if (iTempModifyQueue.Find( aIDArray[i] ) == KErrNotFound)
   473                     iPlaceholderQueue.Remove( itemIndex );
   367                      {
   474                     }
   368                      iTempModifyQueue.AppendL( aIDArray[i] );
   475                 else
   369                      }
   476                     {
   370                  }
   477                     TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - real modify");
   371              else if ( iTempAddQueue.Find( aIDArray[i] ) == KErrNotFound)
   478                     itemIndex = iAddQueue.Find( aIDArray[i] );
   372                  {
   479                                     
   373                  TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - Real ENotifyModify, force run" );
   480                     if (itemIndex >= 0)
   374                  iModifyQueue.InsertL( aIDArray[i], 0 );
   481                         {
   375                   
   482                         TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - remove from add queue");
   376                  TInt itemIndex = iAddQueue.Find( aIDArray[i] );
   483                         iAddQueue.Remove( itemIndex );
   377                  if(itemIndex >= 0)
   484                         }
       
   485 					else
       
   486 						{
       
   487 						
       
   488 						itemIndex = i2ndRoundGenerateQueue.Find( aIDArray[i] );
       
   489                                     
       
   490 	                    if (itemIndex >= 0)
       
   491 	                        {
       
   492 	                        TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - remove from 2nd round add queue");
       
   493 	                        i2ndRoundGenerateQueue.Remove( itemIndex );
       
   494 	                        }
       
   495 					}
       
   496                     
       
   497                     TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - append to modify queue");
       
   498                     iModifyQueue.AppendL(aIDArray[i]);
       
   499                     
       
   500                     SetForceRun( ETrue );
       
   501                     } 
       
   502                 }
       
   503             }
       
   504         }
       
   505         else if (aType == ENotifyRemove)
       
   506             {
       
   507             TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - ENotifyRemove, remove IDs from all queues");
       
   508             
       
   509             for (int i=0; i<aIDArray.Count(); i++)
       
   510                 {
       
   511                 // can be removed from Add queue
       
   512                 TInt itemIndex = iAddQueue.Find( aIDArray[i] );
       
   513                 if(itemIndex >= 0)
   378                     {
   514                     {
   379                     iAddQueue.Remove(itemIndex);
   515                     iAddQueue.Remove(itemIndex);
   380                     }
   516                     }
   381                  itemIndex = iPresentQueue.Find( aIDArray[i] );
   517     
   382                  if(itemIndex >= 0)
   518                 // ..and Modify Queue
       
   519                 itemIndex = iModifyQueue.Find( aIDArray[i] );
       
   520                 if(itemIndex >= 0)
   383                     {
   521                     {
   384                     iPresentQueue.Remove(itemIndex);
   522                     iModifyQueue.Remove(itemIndex);
   385                     }
   523                     }
   386                  SetForceRun( ETrue );
   524                 }
   387                  }
   525             
   388              else
   526             TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - ENotifyRemove append URIs to remove queue");
   389                  {
   527             for (int i=0; i<aObjectUriArray.Count(); i++)
   390                  if (iTempModifyQueue.Find( aIDArray[i] ) == KErrNotFound)
   528                 {
   391                      {
   529                 HBufC* temp = aObjectUriArray[i]->AllocL();
   392                      TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - harvesting now ended for this file - not Real ENotifyModify" );
   530                 iRemoveQueue.Append( temp );
   393                      iTempModifyQueue.AppendL( aIDArray[i] );
   531                 TN_DEBUG2( "CThumbAGProcessor::AddToQueueL() - %S", temp); 
   394                      }
   532                 }
   395                 else
   533             }
   396                      {
   534 #ifdef _DEBUG
   397                      TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - harvesting ended allready for this file - Real ENotifyModify, force run" );
   535         else
   398                      iModifyQueue.InsertL( aIDArray[i], 0 );
   536             {
   399                      TInt itemIndex = iAddQueue.Find( aIDArray[i] );
   537 	        TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() -  should not come here" );
   400                      if(itemIndex >= 0)
   538 	        User::Leave( KErrArgument );
   401                         {
   539             }
   402                         iAddQueue.Remove(itemIndex);
   540 #endif
   403                         }
   541     
   404                      itemIndex = iPresentQueue.Find( aIDArray[i] );
   542     ActivateAO(); 
   405                      if(itemIndex >= 0)
   543     
   406                         {
   544     TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - end" );
   407                         iPresentQueue.Remove(itemIndex);
   545     }
   408                         }
   546 
   409                      SetForceRun( ETrue );
   547 // ---------------------------------------------------------------------------
   410                      }
   548 // CThumbAGProcessor::CreateThumbnailsL()
   411                  } 
   549 // ---------------------------------------------------------------------------
   412              }        
   550 //
   413         }
   551 void CThumbAGProcessor::CreateThumbnailsL( const CMdEObject* aObject )
   414     else if (aType == ENotifyRemove)
   552     {
   415         {
   553     TN_DEBUG1( "CThumbAGProcessor::CreateThumbnailsL() - begin" );
   416         TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - ENotifyRemove" );
   554     
   417         
   555     __ASSERT_DEBUG((iTMSession), User::Panic(_L("CThumbAGProcessor::CreateThumbnailsL() !iTMSession "), KErrBadHandle));
   418         for (int i=0; i<aIDArray.Count(); i++)
   556     __ASSERT_DEBUG((iDefNamespace), User::Panic(_L("CThumbAGProcessor::CreateThumbnailsL() !iDefNamespace "), KErrBadHandle));
   419             {
   557     
   420             // only add to Remove queue if not already in Remove queue        
   558     if(!iTMSession || !iDefNamespace)
   421             if (iRemoveQueue.Find( aIDArray[i] ) == KErrNotFound)
   559         {
   422                 {
   560         return;
   423                 iRemoveQueue.AppendL(aIDArray[i]);
   561         }
   424                 }
   562     
   425 
   563     TInt orientationVal = 0;
   426             // can be removed from Add queue
   564     TInt64 modifiedVal = 0;
   427             TInt itemIndex = iAddQueue.Find( aIDArray[i] );
   565     
   428             if(itemIndex >= 0)
   566     CMdEProperty* orientation = NULL;
   429                 {
   567     CMdEObjectDef& imageObjectDef = iDefNamespace->GetObjectDefL( MdeConstants::Image::KImageObject );       
   430                 iAddQueue.Remove(itemIndex);
   568     TInt orientErr = aObject->Property( imageObjectDef.GetPropertyDefL( MdeConstants::Image::KOrientationProperty ), orientation, 0 );
   431                 }
   569     
   432             // ..and Present Queue
   570     if (orientErr == KErrNone)
   433             itemIndex = iPresentQueue.Find( aIDArray[i] );
   571         {
   434             if(itemIndex >= 0)
   572         orientationVal = orientation->Uint16ValueL();
   435                 {
   573         }
   436                 iPresentQueue.Remove(itemIndex);
   574         
   437                 }
   575     CMdEProperty* modified = NULL;
   438             // ..and Modify Queue
   576     CMdEObjectDef& baseObjDef = iDefNamespace->GetObjectDefL( MdeConstants::Object::KBaseObject );       
   439             itemIndex = iModifyQueue.Find( aIDArray[i] );
   577     TInt modifyErr = aObject->Property( baseObjDef.GetPropertyDefL( MdeConstants::Object::KLastModifiedDateProperty ), modified, 0 );
   440             if(itemIndex >= 0)
   578 
   441                 {
   579     if (modifyErr >= 0)
   442                 iModifyQueue.Remove(itemIndex);
   580         {
   443                 }
   581         modifiedVal = modified->TimeValueL().Int64();
   444             }  
   582         }
       
   583     
       
   584     // update thumbs
       
   585     if (iTMSession)
       
   586         {
       
   587 		// 2nd round and modify updates both sizes if needed
       
   588         if( i2ndRound )
       
   589             {
       
   590             //generate both if needed
       
   591             TN_DEBUG1( "CThumbAGProcessor::CreateThumbnailsL() EOptimizeForQuality ");
       
   592             iTMSession->SetQualityPreferenceL( CThumbnailManager::EOptimizeForQuality );
       
   593             }
       
   594 		// 1st roung generation
       
   595         else
       
   596             {
       
   597             //1st round
       
   598             TN_DEBUG1( "CThumbAGProcessor::CreateThumbnailsL() EOptimizeForQualityWithPreview");
       
   599             iTMSession->SetQualityPreferenceL( CThumbnailManager::EOptimizeForQualityWithPreview );
       
   600             
       
   601             CMdEObjectDef& videoObjectDef = iDefNamespace->GetObjectDefL( MdeConstants::Video::KVideoObject );
       
   602             
       
   603             // add item to 2nd round queue 
       
   604             if(iLastQueue == &iAddQueue || iLastQueue == &iModifyQueue)
       
   605                 {
       
   606                 TN_DEBUG2( "CThumbAGProcessor::CreateThumbnailsL() - 1st round add/modify, append to 2nd round queue", aObject->Id() );
       
   607                 if(i2ndRoundGenerateQueue.Find(aObject->Id()) == KErrNotFound)
       
   608                     {
       
   609                     i2ndRoundGenerateQueue.Append( aObject->Id() );
       
   610                     }
       
   611                 }
       
   612             
       
   613            if( !(imageObjectDef.Id() == aObject->Def().Id() || videoObjectDef.Id() == aObject->Def().Id()) )
       
   614                 {
       
   615                 TN_DEBUG1( "CThumbAGProcessor::CreateThumbnailsL() 1st round and not image or video, skip");
       
   616                 ActivateAO();
       
   617                 return;
       
   618                 }
       
   619             }
       
   620 
       
   621         // run as lower priority than getting but higher that creating thumbnails
       
   622         TRAPD(err, iTMSession->UpdateThumbnailsL(KNoId, aObject->Uri(), orientationVal, modifiedVal, CActive::EPriorityIdle ));
       
   623       
       
   624         if ( err != KErrNone )
       
   625             {
       
   626             TN_DEBUG2( "CThumbAGProcessor::CreateThumbnailsL, iTMSession error == %d", err );
       
   627             
       
   628             iSessionDied = ETrue;
       
   629             iActive = EFalse;
       
   630             ActivateAO();
       
   631             } 
       
   632         else
       
   633             {
       
   634             iActiveCount++;
       
   635             iActive = ETrue;
       
   636             }
   445         }
   637         }
   446     else
   638     else
   447         {
   639         {
   448         // should not come here
   640         ActivateAO();
   449         TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() -  should not come here" );
   641         }
       
   642         
       
   643     TN_DEBUG1( "CThumbAGProcessor::CreateThumbnailsL() - end" );
       
   644     }
       
   645 
       
   646 // ---------------------------------------------------------------------------
       
   647 // CThumbAGProcessor::QueryL()
       
   648 // ---------------------------------------------------------------------------
       
   649 //
       
   650 void CThumbAGProcessor::QueryL( RArray<TItemId>& aIDArray )
       
   651     {
       
   652     TN_DEBUG1( "CThumbAGProcessor::QueryL() - begin" );
       
   653     
       
   654     __ASSERT_DEBUG((iMdESession), User::Panic(_L("CThumbAGProcessor::QueryL() !iMdeSession "), KErrBadHandle));
       
   655     __ASSERT_DEBUG((iDefNamespace), User::Panic(_L("CThumbAGProcessor::QueryL() !iDefNamespace "), KErrBadHandle));
       
   656     
       
   657     if(!iMdESession  || !iDefNamespace)
       
   658         {
   450         return;
   659         return;
   451         }
   660         }
   452 
   661     
   453     ActivateAO(); 
   662 	//reset query queue
   454     
   663     iQueryQueue.Reset();
   455     TN_DEBUG1( "CThumbAGProcessor::AddToQueueL() - end" );
   664 	//set reference to current pprocessing queue
   456     }
   665     iLastQueue = &aIDArray;
   457 
       
   458 // ---------------------------------------------------------------------------
       
   459 // CThumbAGProcessor::CreateThumbnailsL()
       
   460 // ---------------------------------------------------------------------------
       
   461 //
       
   462 void CThumbAGProcessor::CreateThumbnailsL( const CMdEObject* aObject )
       
   463     {
       
   464     TN_DEBUG1( "CThumbAGProcessor::CreateThumbnailsL() - begin" );
       
   465     
       
   466     if( iModify )
       
   467         {
       
   468         TInt orientationVal = 0;
       
   469         TInt64 modifiedVal = 0;
       
   470         
       
   471         CMdEProperty* orientation = NULL;
       
   472         CMdEObjectDef& objDef = iDefNamespace->GetObjectDefL( MdeConstants::Image::KImageObject );       
       
   473         TInt orientErr = aObject->Property( objDef.GetPropertyDefL( MdeConstants::Image::KOrientationProperty ), orientation, 0 );
       
   474         
       
   475         if (orientErr == KErrNone)
       
   476             {
       
   477             orientationVal = orientation->Uint16ValueL();
       
   478             }
       
   479         
       
   480         CMdEProperty* modified = NULL;
       
   481         CMdEObjectDef& objDef2 = iDefNamespace->GetObjectDefL( MdeConstants::Object::KBaseObject );       
       
   482         TInt modifyErr = aObject->Property( objDef2.GetPropertyDefL( MdeConstants::Object::KLastModifiedDateProperty ), modified, 0 );
       
   483         
       
   484         if (modifyErr >= 0)
       
   485             {
       
   486             modifiedVal = modified->TimeValueL().Int64();
       
   487             }
       
   488         
       
   489         // modify existing thumbs
       
   490         if (iTMSession)
       
   491             {
       
   492 			// run as lower priority than getting but higher that creating thumbnails
       
   493             TRAPD(err, iTMSession->UpdateThumbnailsL(aObject->Id(), aObject->Uri(), orientationVal, modifiedVal, CActive::EPriorityIdle ));
       
   494             
       
   495             if ( err != KErrNone )
       
   496                 {
       
   497                 TN_DEBUG2( "CThumbAGProcessor::UpdateThumbnailsL, iTMSession error == %d", err );
       
   498                 
       
   499                 iSessionDied = ETrue;
       
   500                 iActive = EFalse;
       
   501                 ActivateAO();
       
   502                 } 
       
   503             else
       
   504                 {
       
   505                 iActive = ETrue;
       
   506                 }
       
   507             }
       
   508         else
       
   509             {
       
   510             ActivateAO();
       
   511             }
       
   512         
       
   513 #ifdef _DEBUG
       
   514         iModCounter++;
       
   515 #endif     
       
   516         }
       
   517     else
       
   518         {
       
   519         CThumbnailObjectSource* source = NULL;
       
   520         CMdEProperty* mimeType = NULL;
       
   521         CMdEObjectDef& objDef = iDefNamespace->GetObjectDefL( MdeConstants::Object::KBaseObject );       
       
   522         TInt mime = aObject->Property( objDef.GetPropertyDefL( MdeConstants::Object::KItemTypeProperty ), mimeType, 0 );
       
   523         
       
   524         // create new thumbs
       
   525         if (mime != KErrNotFound)
       
   526             {
       
   527             source = CThumbnailObjectSource::NewLC(aObject->Uri(), aObject->Id(), mimeType->TextValueL());
       
   528             }
       
   529         else
       
   530             {
       
   531             source = CThumbnailObjectSource::NewLC(aObject->Uri(), aObject->Id());
       
   532             }
       
   533         
       
   534         if (iTMSession)
       
   535             {
       
   536             // run as very low priority task
       
   537             TInt id = iTMSession->CreateThumbnails(*source, CActive::EPriorityIdle );
       
   538             if ( id < 0 )
       
   539                 {
       
   540                 TN_DEBUG2( "CThumbAGProcessor::CreateThumbnailsL, iTMSession error == %d", id );
       
   541                            
       
   542                 iSessionDied = ETrue;
       
   543                 iActive = EFalse;
       
   544                 CleanupStack::PopAndDestroy( source );
       
   545                 ActivateAO();
       
   546                 } 
       
   547            else
       
   548                 {
       
   549                 iActive = ETrue;
       
   550                 CleanupStack::PopAndDestroy( source );
       
   551                 }
       
   552             
       
   553             }
       
   554         else
       
   555             {
       
   556             ActivateAO();
       
   557             }
       
   558         
       
   559 #ifdef _DEBUG
       
   560         iAddCounter++;
       
   561 #endif
       
   562         }
       
   563     
       
   564 #ifdef _DEBUG
       
   565     TN_DEBUG3( "CThumbAGProcessor::OUT-COUNTERS----------, Add = %d Modify = %d", 
       
   566                iAddCounter, iModCounter );
       
   567 #endif
       
   568    
       
   569     TN_DEBUG1( "CThumbAGProcessor::CreateThumbnailsL() - end" );
       
   570     }
       
   571 
       
   572 // ---------------------------------------------------------------------------
       
   573 // CThumbAGProcessor::QueryL()
       
   574 // ---------------------------------------------------------------------------
       
   575 //
       
   576 void CThumbAGProcessor::QueryL( RArray<TItemId>& aIDArray )
       
   577     {
       
   578     TN_DEBUG1( "CThumbAGProcessor::QueryL() - begin" );
       
   579     
   666     
   580     iQueryReady = EFalse;
   667     iQueryReady = EFalse;
   581 
   668 
   582     // delete old query
   669     // delete old query
   583     if (iQuery)
   670     if (iQuery)
   591         
   678         
   592     TN_DEBUG3( "CThumbAGProcessor::QueryL() - fill begin aIDArray == %d, iQueryQueue == %d", aIDArray.Count(), iQueryQueue.Count() );
   679     TN_DEBUG3( "CThumbAGProcessor::QueryL() - fill begin aIDArray == %d, iQueryQueue == %d", aIDArray.Count(), iQueryQueue.Count() );
   593     
   680     
   594     for(TInt i=0;i < KMaxQueryItems && i < maxCount; i++)
   681     for(TInt i=0;i < KMaxQueryItems && i < maxCount; i++)
   595         {
   682         {
   596         TN_DEBUG2( "CThumbAGProcessor::QueryL() - fill %d", aIDArray[0] );
   683         TN_DEBUG2( "CThumbAGProcessor::QueryL() - fill %d", aIDArray[i] );
   597         iQueryQueue.Append( aIDArray[0] );
   684         iQueryQueue.Append( aIDArray[i] );
   598         aIDArray.Remove( 0 );
       
   599         }
   685         }
   600     
   686     
   601     TN_DEBUG3( "CThumbAGProcessor::QueryL() - fill end aIDArray == %d, iQueryQueue == %d", aIDArray.Count(), iQueryQueue.Count() );
   687     TN_DEBUG3( "CThumbAGProcessor::QueryL() - fill end aIDArray == %d, iQueryQueue == %d", aIDArray.Count(), iQueryQueue.Count() );
   602     
   688     
   603     CMdEObjectDef& objDef = iDefNamespace->GetObjectDefL( MdeConstants::Object::KBaseObject );
   689     CMdEObjectDef& objDef = iDefNamespace->GetObjectDefL( MdeConstants::Object::KBaseObject );
   634             }    
   720             }    
   635         }
   721         }
   636     
   722     
   637     iQuery->FindL();
   723     iQuery->FindL();
   638     
   724     
   639     iQueryQueue.Reset();
       
   640     
       
   641     TN_DEBUG1( "CThumbAGProcessor::QueryL() - end" );
   725     TN_DEBUG1( "CThumbAGProcessor::QueryL() - end" );
   642     }
   726     }
   643 
   727 
       
   728 
       
   729 // ---------------------------------------------------------------------------
       
   730 // CThumbAGProcessor::QueryForPlaceholders()
       
   731 // ---------------------------------------------------------------------------
       
   732 //
       
   733 
       
   734 void CThumbAGProcessor::QueryPlaceholdersL()
       
   735     {
       
   736     TN_DEBUG1( "CThumbAGProcessor::QueryPlaceholdersL" );
       
   737     
       
   738     __ASSERT_DEBUG((iMdESession), User::Panic(_L("CThumbAGProcessor::QueryPlaceholdersL() !iMdeSession "), KErrBadHandle));
       
   739     __ASSERT_DEBUG((iDefNamespace), User::Panic(_L("CThumbAGProcessor::QueryPlaceholdersL() !iDefNamespace "), KErrBadHandle));
       
   740     
       
   741     if(!iMdESession  || !iDefNamespace)
       
   742          {
       
   743          return;
       
   744          }
       
   745     
       
   746     if( iQueryPlaceholders )
       
   747         {
       
   748         if( !iQueryPlaceholders->IsComplete() )
       
   749             {
       
   750             TN_DEBUG1( "CThumbAGProcessor::QueryPlaceholdersL active- skip" );
       
   751             return;
       
   752             }
       
   753         
       
   754         // delete old query
       
   755         iQueryPlaceholders->Cancel();
       
   756         delete iQueryPlaceholders;
       
   757         iQueryPlaceholders = NULL;
       
   758         }
       
   759    
       
   760     TN_DEBUG1( "CThumbAGProcessor::QueryPlaceholdersL - start" );
       
   761 
       
   762     CMdEObjectDef& imageObjDef = iDefNamespace->GetObjectDefL( MdeConstants::Image::KImageObject );
       
   763     CMdEObjectDef& videoObjDef = iDefNamespace->GetObjectDefL( MdeConstants::Video::KVideoObject );
       
   764     CMdEObjectDef& audioObjDef = iDefNamespace->GetObjectDefL( MdeConstants::Audio::KAudioObject );
       
   765     
       
   766     CMdEObjectDef& objDef = iDefNamespace->GetObjectDefL( MdeConstants::Object::KBaseObject);
       
   767     iQueryPlaceholders = iMdESession->NewObjectQueryL( *iDefNamespace, objDef, this );
       
   768         
       
   769     iQueryPlaceholders->SetResultMode( EQueryResultModeItem );
       
   770     
       
   771     CMdELogicCondition& rootCondition = iQueryPlaceholders->Conditions();
       
   772     rootCondition.SetOperator( ELogicConditionOperatorOr );
       
   773     
       
   774     CMdEObjectCondition& imagePHObjectCondition = rootCondition.AddObjectConditionL(imageObjDef);
       
   775     imagePHObjectCondition.SetPlaceholderOnly( ETrue );
       
   776     imagePHObjectCondition.SetNotPresent( ETrue );
       
   777     
       
   778     CMdEObjectCondition& videoPHObjectCondition = rootCondition.AddObjectConditionL(videoObjDef);
       
   779     videoPHObjectCondition.SetPlaceholderOnly( ETrue );
       
   780     videoPHObjectCondition.SetNotPresent( ETrue );
       
   781     
       
   782     CMdEObjectCondition& audioPHObjectCondition = rootCondition.AddObjectConditionL(audioObjDef);
       
   783     audioPHObjectCondition.SetPlaceholderOnly( ETrue );
       
   784     audioPHObjectCondition.SetNotPresent( ETrue );
       
   785     
       
   786     iQueryPlaceholders->FindL();  
       
   787    
       
   788     TN_DEBUG1( "CThumbAGProcessor::QueryPlaceholdersL - end" );
       
   789     }
       
   790 
       
   791 
   644 // ---------------------------------------------------------------------------
   792 // ---------------------------------------------------------------------------
   645 // CThumbAGProcessor::RunL()
   793 // CThumbAGProcessor::RunL()
   646 // ---------------------------------------------------------------------------
   794 // ---------------------------------------------------------------------------
   647 //
   795 //
   648 void CThumbAGProcessor::RunL()
   796 void CThumbAGProcessor::RunL()
   649     {
   797     {
   650     TN_DEBUG1( "CThumbAGProcessor::RunL() - begin" );
   798     TN_DEBUG1( "CThumbAGProcessor::RunL() - begin" );
   651     
   799     
   652     if (iSessionDied)
   800     if (iSessionDied)
   653         {
   801         {
       
   802         TN_DEBUG1( "CThumbAGProcessor::RunL() - iSessionDied" );
   654         delete iTMSession;
   803         delete iTMSession;
   655         iTMSession = NULL;
   804         iTMSession = NULL;
   656         }
   805         }
   657     
   806     
   658     if (iInit)
   807     if (iInit)
   659         {
   808         {
   660         TN_DEBUG1( "CThumbAGProcessor::RunL() - Do Initialisation" );
   809         TN_DEBUG1( "CThumbAGProcessor::RunL() - Do Initialisation 1" );
       
   810         
   661         iInit = EFalse;
   811         iInit = EFalse;
   662         TN_DEBUG1( "iHarvesterClient");
   812         iInit2 = ETrue;
   663         if( iHarvesterClient.Connect() == KErrNone )
   813 
   664             {
   814         iAddQueue.Reset();
   665             TN_DEBUG1( "iHarvesterClient connected");
   815         iModifyQueue.Reset();
   666             iHarvesterClient.AddHarvesterEventObserver( *this, EHEObserverTypeOverall, KMaxTInt );
   816         iRemoveQueue.ResetAndDestroy();
   667             iHarvesterClient.AddHarvesterEventObserver( *this, EHEObserverTypePlaceholder, KMaxTInt );
   817         iQueryQueue.Reset();
   668             TN_DEBUG1( "iHarvesterClient AddHarvesterEventObserver added");
   818         iPlaceholderQueue.Reset();
   669             }
   819         
   670         
   820         TRAP_IGNORE(QueryPlaceholdersL());
   671         TN_DEBUG1( "create MMPXCollectionUtility");
   821         TN_DEBUG1( "CThumbAGProcessor::RunL() - Initialisation 1 done" );
   672         iCollectionUtility = MMPXCollectionUtility::NewL( this, KMcModeIsolated );
   822         ActivateAO();
   673         TN_DEBUG1( "CThumbAGProcessor::RunL() - Initialisation done" );
   823         return;
       
   824         }
       
   825     
       
   826     if(iInit2)
       
   827         {
       
   828         TN_DEBUG1( "CThumbAGProcessor::RunL() - Do Initialisation 2" );
       
   829 		
       
   830         iInit2 = EFalse;
       
   831         TInt err(KErrNone);
       
   832         /*
       
   833         TN_DEBUG1( "CThumbAGProcessor::RunL() do iHarvesterClient connect");
       
   834         TInt err = iHarvesterClient.Connect();
       
   835         TN_DEBUG2( "CThumbAGProcessor::RunL() iHarvesterClient connect err = %d", err);
       
   836         
       
   837         __ASSERT_DEBUG((err==KErrNone), User::Panic(_L("CThumbAGProcessor::RunL(), !iHarvesterClient "), err));
       
   838         
       
   839         if(  err == KErrNone )
       
   840             {
       
   841             TN_DEBUG1( "CThumbAGProcessor::RunL() add iHarvesterClient observer");
       
   842             err = iHarvesterClient.AddHarvesterEventObserver( *this, EHEObserverTypeOverall | EHEObserverTypePlaceholder, KMaxTInt );
       
   843             TN_DEBUG2( "CThumbAGProcessor::RunL() iHarvesterClient observer err = %d", err);
       
   844             __ASSERT_DEBUG((err==KErrNone), User::Panic(_L("CThumbAGProcessor::RunL(), !iHarvesterClient "), err));
       
   845             }*/
       
   846  
       
   847         TN_DEBUG1( "CThumbAGProcessor::RunL() MMPXCollectionUtility");
       
   848         TRAP( err, iCollectionUtility = MMPXCollectionUtility::NewL( this, KMcModeIsolated ));
       
   849         TN_DEBUG2( "CThumbAGProcessor::RunL() create MMPXCollectionUtility err = %d", err);
       
   850         __ASSERT_DEBUG((iCollectionUtility), User::Panic(_L("CThumbAGProcessor::RunL(), !iCollectionUtility "), err));
       
   851         
       
   852         __ASSERT_DEBUG((iActivityManager), User::Panic(_L("CThumbAGProcessor::RunL(), !iActivityManager "), KErrBadHandle));
       
   853         if(iActivityManager)
       
   854             {
       
   855             iActivityManager->Start();
       
   856             }
       
   857         
       
   858         TRAP_IGNORE(QueryAllItemsL());
       
   859 		
       
   860         TN_DEBUG1( "CThumbAGProcessor::RunL() - Initialisation 2 done" );
   674         return;
   861         return;
   675         }
   862         }
   676     
   863     
   677     // restart session if died
   864     // restart session if died
   678     if (!iTMSession)
   865     if (!iTMSession)
   682         TRAPD( err, iTMSession = CThumbnailManager::NewL( *this ) );
   869         TRAPD( err, iTMSession = CThumbnailManager::NewL( *this ) );
   683 		
   870 		
   684         if (err != KErrNone)
   871         if (err != KErrNone)
   685             {
   872             {
   686             iTMSession = NULL;
   873             iTMSession = NULL;
       
   874             ActivateAO();
   687             TN_DEBUG2( "CThumbAGProcessor::RunL() - Session restart failed, error == %d", err );
   875             TN_DEBUG2( "CThumbAGProcessor::RunL() - Session restart failed, error == %d", err );
   688             }        
   876             }        
   689         else {
   877         else 
       
   878             {
   690             iSessionDied = EFalse;
   879             iSessionDied = EFalse;
   691             }
   880             }
   692         }    
   881         }    
   693    
   882    
   694     // do not run if request is already issued to TNM server even if forced
   883     // do not run if request is already issued to TNM server even if forced
   695     if( iActive)
   884     if( iActive)
   696         {
   885         {
   697         if(iActiveCount <= KMaxDaemonRequests)
   886         if(iActiveCount >= KMaxDaemonRequests)
   698             {
   887             {
   699             iActiveCount++;
       
   700             TN_DEBUG1( "CThumbAGProcessor::RunL() - waiting for previous to complete, abort..." );
   888             TN_DEBUG1( "CThumbAGProcessor::RunL() - waiting for previous to complete, abort..." );
   701             return;
   889             return;
   702             }
   890             }
       
   891         }
       
   892     else
       
   893         {
       
   894         iActiveCount = 0;   
       
   895         }
       
   896     
       
   897     
       
   898     //force run can proceed from this point
       
   899 #ifdef _DEBUG
       
   900 	if( iForegroundRun )
       
   901 		{
       
   902       	TN_DEBUG1( "void CThumbAGProcessor::RunL() KForceBackgroundGeneration enabled");
       
   903 	  	}
       
   904 	
       
   905     if( iForceRun )
       
   906         {
       
   907         TN_DEBUG1( "CThumbAGProcessor::RunL() - *** FORCED RUN ***");
       
   908         }
       
   909 #endif
       
   910 	
       
   911   	if( /*iForceRun || */iForegroundRun )
       
   912       	{
       
   913         TN_DEBUG1( "void CThumbAGProcessor::RunL() skip idle detection!");
       
   914       	CancelTimeout();
       
   915      	 }
       
   916   	else
       
   917 	    {
       
   918         if(iActivityManager)
       
   919             {
       
   920             iIdle = iActivityManager->IsInactive();
       
   921             }
       
   922 	    
       
   923         if( !iIdle || iHarvesting || iMPXHarvesting || iPeriodicTimer->IsActive() )
       
   924             {
       
   925             TN_DEBUG1( "void CThumbAGProcessor::RunL() device not idle");
       
   926             return;
       
   927             }
   703         else
   928         else
   704             {
   929             {
   705             TN_DEBUG1( "CThumbAGProcessor::RunL() - iActive jammed - resetted" );
       
   706             iActive = EFalse;
       
   707             iActiveCount = 0;
       
   708             }     
       
   709         }
       
   710     else
       
   711         {
       
   712         iActiveCount = 0;   
       
   713         }
       
   714     
       
   715     //Iforce run can proceed from this point
       
   716     if( !iForceRun )
       
   717         {
       
   718         //check if harvesting or waiting timeout
       
   719         if( iHarvesting || iTimerActive || iMPXHarvesting )
       
   720             {
       
   721             TN_DEBUG1( "void CThumbAGProcessor::RunL() Harvester or timer active, abort");
       
   722             return;
       
   723             }
       
   724         else
       
   725             {
       
   726             //check is server idle
   930             //check is server idle
   727 	        TInt idle(-1);
   931             TInt serveIdle(KErrNotFound);
   728 
   932             TInt ret = RProperty::Get(KServerIdle, KIdle, serveIdle);
   729             TInt ret = RProperty::Get(KServerIdle, KIdle, idle);
   933             
   730 	        
   934             if(ret == KErrNone )
   731 	        if(ret == KErrNone )
   935                 {
   732 	            {
   936                 if(!serveIdle)
   733 	            if(!idle)
   937                     {
   734 	                {
   938                     //start inactivity timer and retry on after callback
   735 					//start wait timer and retry on after callback
   939                     TN_DEBUG1( "void CThumbAGProcessor::RunL() server not idle");
   736 	                TN_DEBUG1( "CThumbAGProcessor::RunL() server not idle, wait... " );
   940                     StartTimeout();
   737 	                if( !iTimerActive)
   941                     return;
   738 	                    {
   942                     }
   739 	                    StartTimeout();
   943                 }
   740 	                    }
   944             TN_DEBUG1( "void CThumbAGProcessor::RunL() device and server idle, process");
   741 	                return;
   945             }
   742 	                }
   946 	    }
   743 	            }
       
   744 	        else
       
   745 	            {
       
   746 	            TN_DEBUG2( "CThumbAGProcessor::RunL() get KServerIdle failed %d, continue...", ret );
       
   747 	            }
       
   748             }
       
   749         }
       
   750     else
       
   751         {
       
   752         TN_DEBUG1( "void CThumbAGProcessor::RunL() forced run");
       
   753         }
       
   754     
       
   755     
   947     
   756     //Handle completed MDS Query
   948     //Handle completed MDS Query
   757     if( iQueryReady && iProcessingCount)
   949     if( iQueryReady && iProcessingCount)
   758         {
   950         {
   759         TInt err(KErrNone);
   951         TInt err(KErrNone);
   760         if((iForceRun && iModify) || (!iForceRun && !iModify))
   952         //if force or non forced
       
   953         if((iForceRun && iModify ) || (!iForceRun && !iModify ))
   761             {
   954             {
   762             TN_DEBUG1( "CThumbAGProcessor::RunL() - iQueryReady START" );
   955             TN_DEBUG1( "CThumbAGProcessor::RunL() - iQueryReady START" );
   763             
   956             
   764         
       
   765             const CMdEObject* object = &iQuery->Result( iProcessingCount-1 );
   957             const CMdEObject* object = &iQuery->Result( iProcessingCount-1 );
   766             iProcessingCount--;
   958             iProcessingCount--;
   767         
   959             
       
   960             TInt itemIndex = iLastQueue->Find( object->Id());
       
   961             if(itemIndex >= 0)
       
   962                 {
       
   963                 iLastQueue->Remove(itemIndex);
       
   964                 }
       
   965 				
   768             // process one item at once
   966             // process one item at once
   769             if ( object )
   967             if ( object )
   770                 {
   968                 {
       
   969                 //remove item from queryQueue when request is issued 
       
   970                 itemIndex = iQueryQueue.Find( object->Id());
       
   971                 if(itemIndex >= 0)
       
   972                     {
       
   973                     iQueryQueue.Remove(itemIndex);
       
   974                     }
       
   975             
   771                 TRAP( err, CreateThumbnailsL(object) );
   976                 TRAP( err, CreateThumbnailsL(object) );
   772             
   977                 TN_DEBUG2( "CThumbAGProcessor::RunL(), CreateThumbnailsL error == %d", err );
   773                 if ( err != KErrNone )
   978                 __ASSERT_DEBUG((err==KErrNone), User::Panic(_L("CThumbAGProcessor::RunL(), CreateThumbnailsL() "), err));
   774                    { 
   979                 }
   775                    TN_DEBUG2( "CThumbAGProcessor::RunL(), CreateThumbnailsL error == %d", err );
   980             }
   776                    }
   981         //force is coming, but executing non-forced query complete-> cancel old
   777                 }
       
   778             }
       
   779         else
   982         else
   780             {
   983             {
   781             TN_DEBUG1( "CThumbAGProcessor::RunL() - deleting query" );
   984             TN_DEBUG1( "CThumbAGProcessor::RunL() - deleting query 1" );
   782             delete iQuery;
   985             delete iQuery;
   783             iQuery = NULL;
   986             iQuery = NULL;
   784             iQueryReady = EFalse;
   987             iQueryReady = EFalse;
   785             iProcessingCount = 0;
   988             iProcessingCount = 0;
       
   989             
       
   990             //move remainig IDs in query queue back to original queue
       
   991             while(iQueryQueue.Count())
       
   992                 {
       
   993                 if(iLastQueue)
       
   994                     {
       
   995                     if(iLastQueue->Find( iQueryQueue[0]) == KErrNotFound)
       
   996                         {
       
   997                         iLastQueue->Append(iQueryQueue[0]);
       
   998                         }
       
   999                     }
       
  1000                 iQueryQueue.Remove(0);
       
  1001                 }
       
  1002             iLastQueue = NULL;
   786             ActivateAO();
  1003             ActivateAO();
   787             return;    
  1004             return;    
   788             }
  1005             }
   789         
  1006         
   790         //is last query item
  1007         //is last query item
   796             iModify = EFalse;
  1013             iModify = EFalse;
   797             
  1014             
   798             //check if forced run needs to continue
  1015             //check if forced run needs to continue
   799             if (iModifyQueue.Count())
  1016             if (iModifyQueue.Count())
   800                 {
  1017                 {
   801                 iForceRun = ETrue;
  1018                 SetForceRun( ETrue );
   802                 }
  1019                 }
   803             else
  1020             else
   804                 {
  1021                 {
   805                 iForceRun = EFalse;
  1022                 SetForceRun( EFalse );
   806                 }
  1023                 }   
   807                 
       
   808             }
  1024             }
   809         //keep going if processing Remove items or if Add item fails
  1025         //keep going if processing Remove items or if Add item fails
   810         else if( iModify || err )
  1026         else if( iModify || err )
   811             {
  1027             {
   812             ActivateAO();
  1028             ActivateAO();
   813             }
  1029             }
   814         }
  1030         }
   815     //waiting for MDS query to complete
  1031     //waiting for MDS query to complete
   816     else if( iQueryActive || iQueryForPlaceholdersActive )
  1032     else if( iQueryActive )
   817         {
  1033         {
   818         if(iForceRun && !iModify && iQueryActive)
  1034         if(iForceRun && !iModify)
   819             {
  1035             {
   820             iQuery->Cancel();
  1036             if(iQuery)
   821             delete iQuery;
  1037                 {
   822             iQuery = NULL;
  1038                 TN_DEBUG1( "CThumbAGProcessor::RunL() - deleting query 2" );
   823             TN_DEBUG1( "CThumbAGProcessor::RunL() - canceling query..." );
  1039                 iQuery->Cancel();
       
  1040                 delete iQuery;
       
  1041                 iQuery = NULL;
       
  1042                 }
       
  1043 
   824             iQueryReady = EFalse;
  1044             iQueryReady = EFalse;
   825             iQueryActive = EFalse;
  1045             iQueryActive = EFalse;
       
  1046             
       
  1047             //move remainig IDs in query queue back to original queue
       
  1048             while(iQueryQueue.Count())
       
  1049                 {
       
  1050                 if(iLastQueue)
       
  1051                     {
       
  1052                     if(iLastQueue->Find( iQueryQueue[0]) == KErrNotFound)
       
  1053                         {
       
  1054                         iLastQueue->Append(iQueryQueue[0]);
       
  1055                         }
       
  1056                     }
       
  1057                 iQueryQueue.Remove(0);
       
  1058                 }
       
  1059             iLastQueue = NULL;
       
  1060             
   826             ActivateAO();
  1061             ActivateAO();
   827             }
  1062             }
   828         else  
  1063         else  
   829             {
  1064             {
   830             TN_DEBUG1( "CThumbAGProcessor::RunL() - waiting for query to complete, abort..." );
  1065             TN_DEBUG1( "CThumbAGProcessor::RunL() - waiting for query to complete, abort..." );
   831             }    
  1066             }    
   832         }
  1067         }
   833 
  1068 
   834     // select queue to process, priority by type. Process modify events before new images
  1069     // no items in query queue, start new
       
  1070     // select queue to process, priority by type
   835     else if ( iModifyQueue.Count() > 0 )
  1071     else if ( iModifyQueue.Count() > 0 )
   836         {
  1072         {
   837         TN_DEBUG1( "void CThumbAGProcessor::RunL() update thumbnails");
  1073         TN_DEBUG1( "void CThumbAGProcessor::RunL() update thumbnails");
       
  1074         
       
  1075         i2ndRound = EFalse;
   838         
  1076         
   839         // query for object info
  1077         // query for object info
   840         iQueryActive = ETrue;
  1078         iQueryActive = ETrue;
   841         iModify = ETrue;
  1079         iModify = ETrue;
   842         QueryL( iModifyQueue );
  1080         QueryL( iModifyQueue );
   843        }
  1081        }
   844     else if ( iRemoveQueue.Count() > 0 )
       
   845         {
       
   846         TN_DEBUG1( "void CThumbAGProcessor::RunL() delete thumbnails");
       
   847         
       
   848         // delete thumbs by ID
       
   849         if (iTMSession)
       
   850             {
       
   851             iTMSession->DeleteThumbnails( iRemoveQueue[0] );
       
   852             }
       
   853         iRemoveQueue.Remove( 0 );
       
   854             
       
   855 #ifdef _DEBUG
       
   856         iDelCounter++;
       
   857         TN_DEBUG2( "CThumbAGProcessor::OUT-COUNTERS----------, Delete = %d", iDelCounter );
       
   858 #endif
       
   859         ActivateAO();
       
   860         }
       
   861     else if ( iAddQueue.Count() > 0 )
  1082     else if ( iAddQueue.Count() > 0 )
   862         {
  1083         {
   863         TN_DEBUG1( "void CThumbAGProcessor::RunL() add thumbnails");
  1084         TN_DEBUG1( "void CThumbAGProcessor::RunL() update 1st round thumbnails");
       
  1085         
       
  1086         i2ndRound = EFalse;
   864         
  1087         
   865         // query for object info
  1088         // query for object info
   866         iQueryActive = ETrue;
  1089         iQueryActive = ETrue;
   867         
  1090         
   868         QueryL( iAddQueue );     
  1091         QueryL( iAddQueue );     
   869         }
  1092         }
   870     else if ( iPresentQueue.Count() > 0 )
  1093     else if ( iRemoveQueue.Count() > 0 )
   871         {
  1094         {
   872         TN_DEBUG1( "void CThumbAGProcessor::RunL() add thumbnails for present thumbnails" );
  1095         TN_DEBUG1( "void CThumbAGProcessor::RunL() delete thumbnails");
   873                 
  1096 
       
  1097         i2ndRound = EFalse;
       
  1098         
       
  1099         // delete thumbs by URI
       
  1100         __ASSERT_DEBUG((iTMSession), User::Panic(_L("CThumbAGProcessor::RunL() !iTMSession "), KErrBadHandle));
       
  1101         if(iTMSession)
       
  1102             {
       
  1103             HBufC* uri = iRemoveQueue[0];
       
  1104             TN_DEBUG2( "void CThumbAGProcessor::RunL() delete %S",  uri);
       
  1105             CThumbnailObjectSource* source = NULL;
       
  1106             TRAPD(err,  source = CThumbnailObjectSource::NewL( *uri, KNullDesC));
       
  1107                
       
  1108         	if(err == KErrNone)
       
  1109             	{
       
  1110                 iTMSession->DeleteThumbnails( *source );
       
  1111                 }
       
  1112             iRemoveQueue.Remove( 0 );
       
  1113             delete source;
       
  1114             delete uri;
       
  1115             }
       
  1116             
       
  1117         ActivateAO();
       
  1118         }
       
  1119     else if( i2ndRoundGenerateQueue.Count() > 0)
       
  1120         {
       
  1121         TN_DEBUG1( "void CThumbAGProcessor::RunL() update 2nd round thumbnails");
       
  1122             
   874         // query for object info
  1123         // query for object info
   875         iQueryActive = ETrue;
  1124         iQueryActive = ETrue;
   876                 
  1125         i2ndRound = ETrue;
   877         QueryL( iPresentQueue );  
  1126         QueryL( i2ndRoundGenerateQueue );     
   878         }
  1127         }
   879     
  1128         
   880     TN_DEBUG1( "CThumbAGProcessor::RunL() - end" );
  1129     TN_DEBUG1( "CThumbAGProcessor::RunL() - end" );
   881     }
  1130     }
   882 
  1131 
   883 // ---------------------------------------------------------------------------
  1132 // ---------------------------------------------------------------------------
   884 // CThumbAGProcessor::DoCancel()
  1133 // CThumbAGProcessor::DoCancel()
   893          HarvesterEventObserverType aHEObserverType, 
  1142          HarvesterEventObserverType aHEObserverType, 
   894          HarvesterEventState aHarvesterEventState,
  1143          HarvesterEventState aHarvesterEventState,
   895          TInt /*aItemsLeft*/ )
  1144          TInt /*aItemsLeft*/ )
   896     {
  1145     {
   897     TN_DEBUG3( "CThumbAGProcessor::HarvestingUpdated -- start() aHEObserverType = %d, aHarvesterEventState = %d", aHEObserverType, aHarvesterEventState );
  1146     TN_DEBUG3( "CThumbAGProcessor::HarvestingUpdated -- start() aHEObserverType = %d, aHarvesterEventState = %d", aHEObserverType, aHarvesterEventState );
   898   
  1147 
       
  1148     #ifdef _DEBUG
   899     if( aHEObserverType == EHEObserverTypePlaceholder)
  1149     if( aHEObserverType == EHEObserverTypePlaceholder)
   900         {
  1150         {
   901         TRAP_IGNORE( QueryForPlaceholdersL() );
  1151         TN_DEBUG1( "CThumbAGProcessor::HarvestingUpdated -- type EHEObserverTypePlaceholder");
   902         return;
  1152         }
   903         }    
  1153     else if( aHEObserverType == EHEObserverTypeOverall)
   904     
  1154         {
   905     if( aHEObserverType != EHEObserverTypeOverall)
  1155         TN_DEBUG1( "CThumbAGProcessor::HarvestingUpdated -- type EHEObserverTypeOverall");
   906         {
  1156         }
   907         return;
  1157     #endif
   908         }
  1158     
   909     
  1159     //placeholder harvesting
   910     switch(aHarvesterEventState)
  1160     if( aHEObserverType == EHEObserverTypePlaceholder)
   911         {
  1161         {
   912         case EHEStateStarted:
  1162         switch(aHarvesterEventState)
   913         case EHEStateHarvesting:
  1163             {
   914         case EHEStatePaused:
  1164             case EHEStateStarted:
   915         case EHEStateResumed:
  1165             case EHEStateHarvesting:
   916            {
  1166             case EHEStateResumed:
   917            iHarvestingTemp = ETrue;
  1167                 {
   918            break;
  1168                 iPHHarvestingTemp = ETrue;
   919            }
  1169                 break;
   920         case EHEStateFinished:
  1170                 }
   921         case EHEStateUninitialized:
  1171             case EHEStatePaused:
   922            {
  1172             case EHEStateFinished:
   923            iHarvestingTemp = EFalse;
  1173             case EHEStateUninitialized:
   924            break;
  1174                 {
   925            }
  1175                 iPHHarvestingTemp = EFalse;
   926         };
  1176                 break;
   927     
  1177                 }
   928     if(iHarvestingTemp == iHarvesting)
  1178             };
   929         {
  1179     
   930         TN_DEBUG2( "CThumbAGProcessor::HarvestingUpdated -- no change %d", iHarvesting);
  1180         if(iPHHarvestingTemp != iPHHarvesting)
   931         }
  1181             {
   932     else
  1182             iPHHarvesting = iPHHarvestingTemp;
   933         {
  1183            
   934         iHarvesting = iHarvestingTemp;
  1184             if( iPHHarvesting )
   935         
  1185                 {
   936         if( iHarvesting )
  1186                 TN_DEBUG1( "CThumbAGProcessor::HarvestingUpdated -- MDS placeholder harvesterin started");
   937             {
  1187                 }
   938             TN_DEBUG1( "CThumbAGProcessor::HarvestingUpdated -- MDS harvesterin started");
  1188             else
   939             CancelTimeout();
  1189                 {
   940             }
  1190                 TN_DEBUG1( "CThumbAGProcessor::HarvestingUpdated -- MDS placeholder harvesting finished");
   941         else
  1191                 TRAP_IGNORE(QueryPlaceholdersL());
   942             {
  1192                 }
   943              TN_DEBUG1( "CThumbAGProcessor::HarvestingUpdated -- MDS harvesting finished ");
  1193             }
   944              // continue processing if needed
  1194         }
   945             StartTimeout();
  1195     //overall harvesting
   946                  
  1196     else if ( aHEObserverType == EHEObserverTypeOverall)
   947              iTempModifyQueue.Reset();
  1197         {
   948              iTempAddQueue.Reset();
  1198         switch(aHarvesterEventState)
   949              iPlaceholderIDs.Reset();
  1199             {
   950             }
  1200             case EHEStateStarted:
   951         }
  1201             case EHEStateHarvesting:
   952 
  1202             case EHEStatePaused:
   953     TN_DEBUG3( "CThumbAGProcessor::HarvestingUpdated -- end() iHarvesting == %d, iMPXHarvesting == %d", iHarvesting, iMPXHarvesting);
  1203             case EHEStateResumed:
       
  1204                 {
       
  1205                 iHarvestingTemp = ETrue;
       
  1206                 break;
       
  1207                 }
       
  1208             case EHEStateFinished:
       
  1209             case EHEStateUninitialized:
       
  1210                 {
       
  1211                 iHarvestingTemp = EFalse;
       
  1212                 break;
       
  1213                 }
       
  1214             };
       
  1215         
       
  1216         if(iHarvestingTemp != iHarvesting)
       
  1217             {
       
  1218             iHarvesting = iHarvestingTemp;
       
  1219             
       
  1220             if( iHarvesting )
       
  1221                 {
       
  1222                 TN_DEBUG1( "CThumbAGProcessor::HarvestingUpdated -- MDS harvesterin started");
       
  1223                 CancelTimeout();
       
  1224                 }
       
  1225             else
       
  1226                 {
       
  1227                 TN_DEBUG1( "CThumbAGProcessor::HarvestingUpdated -- MDS harvesting finished ");
       
  1228                 // continue processing if needed
       
  1229                 StartTimeout();
       
  1230                 }
       
  1231             }
       
  1232         }
       
  1233    
       
  1234     TN_DEBUG3( "CThumbAGProcessor::HarvestingUpdated -- end() iHarvesting == %d, iPHHarvesting == %d ", iHarvesting, iPHHarvesting);
   954     }
  1235     }
   955 
  1236 
   956 // ---------------------------------------------------------------------------
  1237 // ---------------------------------------------------------------------------
   957 // CThumbAGProcessor::StartTimeout()
  1238 // CThumbAGProcessor::StartTimeout()
   958 // ---------------------------------------------------------------------------
  1239 // ---------------------------------------------------------------------------
   959 //
  1240 //
   960 void CThumbAGProcessor::StartTimeout()
  1241 void CThumbAGProcessor::StartTimeout()
   961     {
  1242     {
       
  1243     TN_DEBUG1( "CThumbAGProcessor::StartTimeout()");
   962     CancelTimeout();
  1244     CancelTimeout();
   963     
  1245     
   964     if(!iHarvesting && !iMPXHarvesting && !iPeriodicTimer->IsActive())
  1246     if(!iHarvesting && !iMPXHarvesting && !iPeriodicTimer->IsActive())
   965         {
  1247         {
   966         iPeriodicTimer->Start( KHarvestingCompleteTimeout, KHarvestingCompleteTimeout, 
  1248         iPeriodicTimer->Start( KHarvestingCompleteTimeout, KHarvestingCompleteTimeout,
   967                 TCallBack(PeriodicTimerCallBack, this));
  1249                 TCallBack(PeriodicTimerCallBack, this));
   968         iTimerActive = ETrue;
       
   969         }
       
   970     else
       
   971         {
       
   972         iTimerActive = EFalse;
       
   973         }
  1250         }
   974     }
  1251     }
   975 
  1252 
   976 // ---------------------------------------------------------------------------
  1253 // ---------------------------------------------------------------------------
   977 // CThumbAGProcessor::StopTimeout()
  1254 // CThumbAGProcessor::StopTimeout()
   978 // ---------------------------------------------------------------------------
  1255 // ---------------------------------------------------------------------------
   979 //
  1256 //
   980 void CThumbAGProcessor::CancelTimeout()
  1257 void CThumbAGProcessor::CancelTimeout()
   981     {
  1258     {
   982     if(iTimerActive)
  1259     if(iPeriodicTimer->IsActive())
   983        {
  1260         {
   984        iPeriodicTimer->Cancel();
  1261         iPeriodicTimer->Cancel();
   985        }
  1262         }
   986     iTimerActive = EFalse;
       
   987     }
  1263     }
   988 
  1264 
   989 // ---------------------------------------------------------------------------
  1265 // ---------------------------------------------------------------------------
   990 // CThumbAGProcessor::RunError()
  1266 // CThumbAGProcessor::RunError()
   991 // ---------------------------------------------------------------------------
  1267 // ---------------------------------------------------------------------------
   992 //
  1268 //
       
  1269 #ifdef _DEBUG
   993 TInt CThumbAGProcessor::RunError(TInt aError)
  1270 TInt CThumbAGProcessor::RunError(TInt aError)
   994     {
  1271 #else
   995     if (aError != KErrNone)
  1272 TInt CThumbAGProcessor::RunError(TInt /*aError*/)
   996         {
  1273 #endif
   997         TN_DEBUG2( "CThumbAGProcessor::RunError = %d", aError );
  1274     {
   998         }
  1275     TN_DEBUG2( "CThumbAGrocessor::RunError() %d", aError);
   999     
  1276     
  1000     iActive = EFalse;
  1277     UpdatePSValues();
  1001     
  1278         
       
  1279     iActiveCount--;
       
  1280     
       
  1281     if(iActiveCount <= 0)
       
  1282         {
       
  1283         iActiveCount = 0;
       
  1284         iActive = EFalse;
       
  1285         }
       
  1286     
       
  1287 	ActivateAO();
       
  1288 	
  1002     // nothing to do
  1289     // nothing to do
  1003     return KErrNone;
  1290     return KErrNone;
  1004     }
  1291     }
  1005 
  1292 
  1006 // ---------------------------------------------------------------------------
  1293 // ---------------------------------------------------------------------------
  1007 // CThumbAGProcessor::ActivateAO()
  1294 // CThumbAGProcessor::ActivateAO()
  1008 // ---------------------------------------------------------------------------
  1295 // ---------------------------------------------------------------------------
  1009 //
  1296 //
  1010 void CThumbAGProcessor::ActivateAO()
  1297 void CThumbAGProcessor::ActivateAO()
  1011     {
  1298     {
       
  1299 #ifdef _DEBUG
       
  1300     TN_DEBUG6( "CThumbAGProcessor::ActivateAO() items in queue Add = %d, Mod = %d, Del = %d, Query = %d, iPlaceholder = %d", iAddQueue.Count(),  iModifyQueue.Count(), iRemoveQueue.Count(), iQueryQueue.Count(), iPlaceholderQueue.Count());
       
  1301     TN_DEBUG2( "CThumbAGProcessor::ActivateAO() items in queue 2nd Add = %d", i2ndRoundGenerateQueue.Count());
       
  1302     TN_DEBUG3( "CThumbAGProcessor::ActivateAO() iActive = %d, iActiveCount = %d", iActive, iActiveCount);
       
  1303     TN_DEBUG3( "CThumbAGProcessor::ActivateAO() iHarvesting == %d, iMPXHarvesting == %d", iHarvesting, iMPXHarvesting);
       
  1304     TN_DEBUG4( "CThumbAGProcessor::ActivateAO() iIdle = %d, timer = %d, iForceRun = %d", iIdle, iPeriodicTimer->IsActive(), iForceRun);
       
  1305     TN_DEBUG4( "CThumbAGProcessor::ActivateAO() iModify = %d, iQueryReady = %d, iProcessingCount = %d", iModify, iQueryReady, iProcessingCount);
       
  1306 #endif
       
  1307     
  1012     if(iFormatting)
  1308     if(iFormatting)
  1013         {
  1309         {
  1014         TN_DEBUG1( "CThumbAGProcessor::ActivateAO() - FORMATTING - DAEMON ON PAUSE");
  1310         TN_DEBUG1( "CThumbAGProcessor::ActivateAO() - FORMATTING - DAEMON ON PAUSE");
  1015         return;
  1311         return;
  1016         }
  1312         }
  1017         
  1313         
  1018     if( !IsActive() && (!iHarvesting || iForceRun ))
  1314     if( !IsActive() )
  1019         {
  1315         {
  1020 #ifdef _DEBUG
       
  1021         if( iForceRun )
       
  1022             {
       
  1023             TN_DEBUG1( "CThumbAGProcessor::ActivateAO() - *** FORCED RUN ***");
       
  1024             }
       
  1025 #endif
       
  1026         SetActive();
  1316         SetActive();
  1027         TRequestStatus* statusPtr = &iStatus;
  1317         TRequestStatus* statusPtr = &iStatus;
  1028         User::RequestComplete( statusPtr, KErrNone );
  1318         User::RequestComplete( statusPtr, KErrNone );
  1029         }
  1319         }
       
  1320 
       
  1321     UpdatePSValues();
  1030     }
  1322     }
  1031 
  1323 
  1032 // ---------------------------------------------------------------------------
  1324 // ---------------------------------------------------------------------------
  1033 // CThumbAGProcessor::PeriodicTimerCallBack()
  1325 // CThumbAGProcessor::PeriodicTimerCallBack()
  1034 // ---------------------------------------------------------------------------
  1326 // ---------------------------------------------------------------------------
  1061     TBool audioGrid( EFalse );
  1353     TBool audioGrid( EFalse );
  1062     TBool audioList( EFalse );
  1354     TBool audioList( EFalse );
  1063     TBool audioFull( EFalse );
  1355     TBool audioFull( EFalse );
  1064 
  1356 
  1065     // get cenrep values
  1357     // get cenrep values
  1066     rep->Get( KAutoCreateImageGrid, imageGrid );
  1358     TInt ret = rep->Get( KAutoCreateImageGrid, imageGrid );
  1067     rep->Get( KAutoCreateImageList, imageList );
  1359     TN_DEBUG2( "CThumbAGProcessor::CheckAutoCreateValuesL() KAutoCreateImageGrid %d", ret);
  1068     rep->Get( KAutoCreateImageFullscreen, imageFull );
  1360     ret = rep->Get( KAutoCreateImageList, imageList );
  1069     rep->Get( KAutoCreateVideoGrid, videoGrid );
  1361     TN_DEBUG2( "CThumbAGProcessor::CheckAutoCreateValuesL() KAutoCreateImageList %d", ret);
  1070     rep->Get( KAutoCreateVideoList, videoList );
  1362     ret = rep->Get( KAutoCreateImageFullscreen, imageFull );
  1071     rep->Get( KAutoCreateVideoFullscreen, videoFull );
  1363     TN_DEBUG2( "CThumbAGProcessor::CheckAutoCreateValuesL() KAutoCreateImageFullscreen %d", ret);
  1072     rep->Get( KAutoCreateAudioGrid, audioGrid );
  1364     ret = rep->Get( KAutoCreateVideoGrid, videoGrid );
  1073     rep->Get( KAutoCreateAudioList, audioList );
  1365     TN_DEBUG2( "CThumbAGProcessor::CheckAutoCreateValuesL() KAutoCreateVideoGrid %d", ret);
  1074     rep->Get( KAutoCreateAudioFullscreen, audioFull );
  1366     ret = rep->Get( KAutoCreateVideoList, videoList );
       
  1367     TN_DEBUG2( "CThumbAGProcessor::CheckAutoCreateValuesL() KAutoCreateVideoList %d", ret);
       
  1368     ret = rep->Get( KAutoCreateVideoFullscreen, videoFull );
       
  1369     TN_DEBUG2( "CThumbAGProcessor::CheckAutoCreateValuesL() KAutoCreateVideoFullscreen %d", ret);
       
  1370     ret = rep->Get( KAutoCreateAudioGrid, audioGrid );
       
  1371     TN_DEBUG2( "CThumbAGProcessor::CheckAutoCreateValuesL() KAutoCreateAudioGrid %d", ret);
       
  1372     ret = rep->Get( KAutoCreateAudioList, audioList );
       
  1373     TN_DEBUG2( "CThumbAGProcessor::CheckAutoCreateValuesL() KAutoCreateAudioList %d", ret);
       
  1374     ret = rep->Get( KAutoCreateAudioFullscreen, audioFull );
       
  1375     TN_DEBUG2( "CThumbAGProcessor::CheckAutoCreateValuesL() KAutoCreateAudioFullscreen %d", ret);
  1075     
  1376     
  1076     iAutoImage = EFalse;
  1377     iAutoImage = EFalse;
  1077     iAutoVideo = EFalse;
  1378     iAutoVideo = EFalse;
  1078     iAutoAudio = EFalse;
  1379     iAutoAudio = EFalse;
  1079     
  1380     
  1096 
  1397 
  1097 // ---------------------------------------------------------------------------
  1398 // ---------------------------------------------------------------------------
  1098 // CThumbAGProcessor::RemoveFromQueues()
  1399 // CThumbAGProcessor::RemoveFromQueues()
  1099 // ---------------------------------------------------------------------------
  1400 // ---------------------------------------------------------------------------
  1100 //
  1401 //
       
  1402 #ifdef _DEBUG
  1101 void CThumbAGProcessor::RemoveFromQueues( const RArray<TItemId>& aIDArray, const TBool aRemoveFromDelete )
  1403 void CThumbAGProcessor::RemoveFromQueues( const RArray<TItemId>& aIDArray, const TBool aRemoveFromDelete )
       
  1404 #else
       
  1405 void CThumbAGProcessor::RemoveFromQueues( const RArray<TItemId>& aIDArray, const TBool /*aRemoveFromDelete*/ )
       
  1406 #endif
  1102     {
  1407     {
  1103     TN_DEBUG2( "CThumbAGProcessor::RemoveFromQueues() aRemoveFromDelete == %d - begin", aRemoveFromDelete );
  1408     TN_DEBUG2( "CThumbAGProcessor::RemoveFromQueues() aRemoveFromDelete == %d - begin", aRemoveFromDelete );
  1104     
  1409     
  1105     TInt itemIndex = KErrNotFound;
  1410     TInt itemIndex = KErrNotFound;
  1106     
  1411     
  1107     for (int i=0; i< aIDArray.Count(); i++)
  1412     for (int i=0; i< aIDArray.Count(); i++)
  1108         {
  1413         {
  1109         TN_DEBUG2( "CThumbAGProcessor::RemoveFromQueues() - %d", aIDArray[i]);
  1414         TN_DEBUG2( "CThumbAGProcessor::RemoveFromQueues() - %d", aIDArray[i]);
       
  1415 
       
  1416         itemIndex = iPlaceholderQueue.Find( aIDArray[i] );
       
  1417                          
       
  1418         if(itemIndex >= 0)
       
  1419             {
       
  1420             iPlaceholderQueue.Remove(itemIndex);
       
  1421             TN_DEBUG1( "CThumbAGProcessor::RemoveFromQueues() - iPlaceholderQueue" );
       
  1422             }
  1110                 
  1423                 
  1111         itemIndex = iAddQueue.Find( aIDArray[i] );
  1424         itemIndex = iAddQueue.Find( aIDArray[i] );
  1112         
  1425         
  1113         if(itemIndex >= 0)
  1426         if(itemIndex >= 0)
  1114             {
  1427             {
  1115             iAddQueue.Remove(itemIndex);
  1428             iAddQueue.Remove(itemIndex);
  1116             TN_DEBUG1( "CThumbAGProcessor::RemoveFromQueues() - iAddQueue" );
  1429             TN_DEBUG1( "CThumbAGProcessor::RemoveFromQueues() - iAddQueue" );
  1117             continue;
  1430             }
  1118             }
  1431 
  1119         
  1432         itemIndex = i2ndRoundGenerateQueue.Find( aIDArray[i] );
  1120         itemIndex = iPresentQueue.Find( aIDArray[i] );
       
  1121                 
  1433                 
  1122         if(itemIndex >= 0)
  1434         if(itemIndex >= 0)
  1123             {
  1435             {
  1124             iPresentQueue.Remove(itemIndex);
  1436             i2ndRoundGenerateQueue.Remove(itemIndex);
  1125             TN_DEBUG1( "CThumbAGProcessor::RemoveFromQueues() - iPresentQueue" );
  1437             TN_DEBUG1( "CThumbAGProcessor::RemoveFromQueues() - i2ndRoundGenerateQueue" );
  1126             continue;
  1438             }
  1127             }
  1439         
  1128    
       
  1129         itemIndex = iModifyQueue.Find( aIDArray[i] );
  1440         itemIndex = iModifyQueue.Find( aIDArray[i] );
  1130          
  1441          
  1131         if(itemIndex >= 0)
  1442         if(itemIndex >= 0)
  1132            {
  1443             {
  1133            iModifyQueue.Remove(itemIndex);
  1444             iModifyQueue.Remove(itemIndex);
  1134            TN_DEBUG1( "CThumbAGProcessor::RemoveFromQueues() - iModifyQueue" );
  1445             TN_DEBUG1( "CThumbAGProcessor::RemoveFromQueues() - iModifyQueue" );
  1135 			 
  1446 			 
  1136            if( iModifyQueue.Count() == 0)
  1447             if( iModifyQueue.Count() == 0)
  1137 			  {
  1448 			    {
  1138 			  iForceRun = EFalse;
  1449 			    SetForceRun( EFalse );
  1139 		      }
  1450 		        }
  1140 			 
  1451 			 
  1141            continue;
  1452             continue;
  1142            }
  1453             }
  1143     
  1454     
  1144         if( aRemoveFromDelete )
  1455         /*if( aRemoveFromDelete )
  1145            {
  1456             {
  1146            itemIndex = iRemoveQueue.Find( aIDArray[i] );
  1457             itemIndex = iRemoveQueue.Find( aIDArray[i] );
  1147              
  1458              
  1148            if(itemIndex >= 0)
  1459             if(itemIndex >= 0)
  1149               {
  1460                 {
  1150               iRemoveQueue.Remove(itemIndex);
  1461                 iRemoveQueue.Remove(itemIndex);
  1151               TN_DEBUG1( "CThumbAGProcessor::RemoveFromQueues() - iRemoveQueue" );
  1462                 TN_DEBUG1( "CThumbAGProcessor::RemoveFromQueues() - iRemoveQueue" );
  1152               continue;
  1463                 continue;
  1153               }
  1464                 }
  1154            }
  1465             }*/
  1155         }
  1466         }
  1156     
  1467     
  1157     TN_DEBUG1( "CThumbAGProcessor::RemoveFromQueues() - end" );
  1468     TN_DEBUG1( "CThumbAGProcessor::RemoveFromQueues() - end" );
  1158     }
  1469     }
  1159 	
  1470 	
  1171         iForceRun = aForceRun;
  1482         iForceRun = aForceRun;
  1172         }
  1483         }
  1173     }
  1484     }
  1174 
  1485 
  1175 // ---------------------------------------------------------------------------
  1486 // ---------------------------------------------------------------------------
  1176 // CThumbAGProcessor::SetFormat()
       
  1177 // ---------------------------------------------------------------------------
       
  1178 //
       
  1179 
       
  1180 void CThumbAGProcessor::SetFormat(TBool aStatus)
       
  1181     {
       
  1182     TN_DEBUG2( "CThumbAGProcessor::SetFormat(%d) - end", aStatus );
       
  1183     
       
  1184     iFormatting = aStatus;
       
  1185     if(!aStatus)
       
  1186         {
       
  1187         ActivateAO();
       
  1188         }
       
  1189     }
       
  1190 
       
  1191 // ---------------------------------------------------------------------------
       
  1192 // CThumbAGProcessor::QueryForPlaceholders()
  1487 // CThumbAGProcessor::QueryForPlaceholders()
  1193 // ---------------------------------------------------------------------------
  1488 // ---------------------------------------------------------------------------
  1194 //
  1489 //
  1195 
  1490 void CThumbAGProcessor::QueryAllItemsL()
  1196 void CThumbAGProcessor::QueryForPlaceholdersL()
  1491     {
  1197     {
  1492     TN_DEBUG1( "CThumbAGProcessor::QueryAllItemsL" );
  1198     TN_DEBUG1( "CThumbAGProcessor::QueryForPlaceholders" );
  1493     
  1199     if(iQueryForPlaceholdersActive)
  1494     __ASSERT_DEBUG((iMdESession), User::Panic(_L("CThumbAGProcessor::QueryAllItemsL() !iMdeSession "), KErrBadHandle));
  1200         {
  1495     
  1201         TN_DEBUG1( "CThumbAGProcessor::QueryForPlaceholders - skip" );
  1496     if(!iMdESession)
  1202         return;
  1497          {
  1203         }
  1498          return;
  1204     
  1499          }
  1205     TN_DEBUG1( "CThumbAGProcessor::QueryForPlaceholders - start" );
  1500     
  1206 
  1501     if( iQueryAllItems )
  1207     // delete old query
  1502         {
  1208     if (iQueryForPlaceholders)
  1503         if( !iQueryAllItems->IsComplete() )
  1209        {
  1504             {
  1210        iQueryForPlaceholdersActive = EFalse;
  1505             TN_DEBUG1( "CThumbAGProcessor::QueryAllItemsL active- skip" );
  1211        iQueryForPlaceholders->Cancel();
  1506             return;
  1212        delete iQueryForPlaceholders;
  1507             }
  1213        iQueryForPlaceholders = NULL;
  1508         
  1214        }
  1509         // delete old query
       
  1510         iQueryAllItems->Cancel();
       
  1511         delete iQueryAllItems;
       
  1512         iQueryAllItems = NULL;
       
  1513         }
       
  1514     
       
  1515     TN_DEBUG1( "CThumbAGProcessor::QueryAllItemsL - start" );
  1215     
  1516     
  1216     CMdEObjectDef& imageObjDef = iDefNamespace->GetObjectDefL( MdeConstants::Image::KImageObject );
  1517     CMdEObjectDef& imageObjDef = iDefNamespace->GetObjectDefL( MdeConstants::Image::KImageObject );
  1217     CMdEObjectDef& videoObjDef = iDefNamespace->GetObjectDefL( MdeConstants::Video::KVideoObject );
  1518     CMdEObjectDef& videoObjDef = iDefNamespace->GetObjectDefL( MdeConstants::Video::KVideoObject );
  1218     CMdEObjectDef& audioObjDef = iDefNamespace->GetObjectDefL( MdeConstants::Audio::KAudioObject );
  1519     CMdEObjectDef& audioObjDef = iDefNamespace->GetObjectDefL( MdeConstants::Audio::KAudioObject );
  1219     
  1520     
  1220     CMdEObjectDef& objDef = iDefNamespace->GetObjectDefL( MdeConstants::Object::KBaseObject);
  1521     CMdEObjectDef& objDef = iDefNamespace->GetObjectDefL( MdeConstants::Object::KBaseObject);
  1221     iQueryForPlaceholders = iMdESession->NewObjectQueryL( *iDefNamespace, objDef, this );
  1522     iQueryAllItems = iMdESession->NewObjectQueryL( *iDefNamespace, objDef, this );
  1222         
  1523         
  1223     iQueryForPlaceholders->SetResultMode( EQueryResultModeItem );
  1524     iQueryAllItems->SetResultMode( EQueryResultModeItem );
  1224     
  1525     
  1225     CMdELogicCondition& rootCondition = iQueryForPlaceholders->Conditions();
  1526     CMdELogicCondition& rootCondition = iQueryAllItems->Conditions();
  1226     rootCondition.SetOperator( ELogicConditionOperatorOr );
  1527     rootCondition.SetOperator( ELogicConditionOperatorOr );
  1227     
  1528     
  1228     CMdEObjectCondition& imagePHObjectCondition = rootCondition.AddObjectConditionL(imageObjDef);
  1529     CMdEObjectCondition& imagePHObjectCondition = rootCondition.AddObjectConditionL(imageObjDef);
  1229     imagePHObjectCondition.SetPlaceholderOnly( ETrue );
       
  1230     imagePHObjectCondition.SetNotPresent( ETrue );
       
  1231     
  1530     
  1232     CMdEObjectCondition& videoPHObjectCondition = rootCondition.AddObjectConditionL(videoObjDef);
  1531     CMdEObjectCondition& videoPHObjectCondition = rootCondition.AddObjectConditionL(videoObjDef);
  1233     videoPHObjectCondition.SetPlaceholderOnly( ETrue );
       
  1234     videoPHObjectCondition.SetNotPresent( ETrue );
       
  1235     
  1532     
  1236     CMdEObjectCondition& audioPHObjectCondition = rootCondition.AddObjectConditionL(audioObjDef);
  1533     CMdEObjectCondition& audioPHObjectCondition = rootCondition.AddObjectConditionL(audioObjDef);
  1237     audioPHObjectCondition.SetPlaceholderOnly( ETrue );
  1534     
  1238     audioPHObjectCondition.SetNotPresent( ETrue );
  1535     iQueryAllItems->FindL();  
  1239     
  1536     
  1240     iQueryForPlaceholders->FindL();  
  1537     TN_DEBUG1( "CThumbAGProcessor::QueryAllItemsL - end" );
  1241     
       
  1242     iQueryForPlaceholdersActive = ETrue;
       
  1243     
       
  1244     TN_DEBUG1( "CThumbAGProcessor::QueryForPlaceholders - end" );
       
  1245     }
  1538     }
  1246 
  1539 
  1247 // -----------------------------------------------------------------------------
  1540 // -----------------------------------------------------------------------------
  1248 // CThumbAGProcessor::HandleCollectionMessage
  1541 // CThumbAGProcessor::HandleCollectionMessage
  1249 // From MMPXCollectionObserver
  1542 // From MMPXCollectionObserver
  1250 // Handle collection message.
  1543 // Handle collection message.
  1251 // -----------------------------------------------------------------------------
  1544 // -----------------------------------------------------------------------------
  1252 //
  1545 //
  1253 
  1546 void CThumbAGProcessor::HandleCollectionMessage( CMPXMessage* aMessage, TInt aError )
  1254 void CThumbAGProcessor::HandleCollectionMessage( CMPXMessage* aMessage,
       
  1255                                                         TInt aError )
       
  1256     {
  1547     {
  1257     if ( aError != KErrNone || !aMessage )
  1548     if ( aError != KErrNone || !aMessage )
  1258         {
  1549         {
  1259         return;
  1550         return;
  1260         }
  1551         }
  1269         TInt event( *aMessage->Value<TInt>( KMPXMessageGeneralEvent ) );
  1560         TInt event( *aMessage->Value<TInt>( KMPXMessageGeneralEvent ) );
  1270         if ( event == TMPXCollectionMessage::EBroadcastEvent )
  1561         if ( event == TMPXCollectionMessage::EBroadcastEvent )
  1271             {
  1562             {
  1272             TInt op( *aMessage->Value<TInt>( KMPXMessageGeneralType ) );
  1563             TInt op( *aMessage->Value<TInt>( KMPXMessageGeneralType ) );
  1273                
  1564                
  1274            switch( op )
  1565             switch( op )
  1275                {
  1566                 {
  1276 			   //when MTP sync or music collection is started then pause processing
  1567 			    //when MTP sync or music collection is started then pause processing
  1277                case EMcMsgRefreshStart:
  1568                 case EMcMsgRefreshStart:
  1278                case EMcMsgUSBMTPStart:
  1569                 case EMcMsgUSBMTPStart:
  1279                    TN_DEBUG1("CThumbAGProcessor::HandleCollectionMessage MPX refresh started" );
  1570                     TN_DEBUG1("CThumbAGProcessor::HandleCollectionMessage MPX refresh started" );
  1280                    iMPXHarvesting = ETrue;
  1571                     iMPXHarvesting = ETrue;
  1281                    CancelTimeout();
  1572                     CancelTimeout();
  1282                    break;
  1573                     break;
  1283 			   //when MTP sync or music collection refresh is complete then resume processing
  1574 			    //when MTP sync or music collection refresh is complete then resume processing
  1284                case EMcMsgRefreshEnd:
  1575                 case EMcMsgRefreshEnd:
  1285                case EMcMsgUSBMTPEnd:
  1576                 case EMcMsgUSBMTPEnd:
  1286                case EMcMsgUSBMTPNotActive:
  1577                 case EMcMsgUSBMTPNotActive:
  1287                    TN_DEBUG1("CThumbAGProcessor::HandleCollectionMessage MPX refresh finished/not active" );
  1578                     TN_DEBUG1("CThumbAGProcessor::HandleCollectionMessage MPX refresh finished/not active" );
  1288                    iMPXHarvesting = EFalse;
  1579                     iMPXHarvesting = EFalse;
  1289                    StartTimeout();
  1580                     StartTimeout();
  1290                    break;
  1581                     break;
  1291                default:
  1582                 default:
  1292                    break;
  1583                     break;
  1293                }
  1584                 }
  1294            TN_DEBUG3( "CThumbAGProcessor::HandleCollectionMessage -- end() iHarvesting == %d, iMPXHarvesting == %d", iHarvesting, iMPXHarvesting);
  1585             
  1295             }
  1586             //signal Server's stores about MPX harvesting state
  1296         }
  1587             if( iMPXHarvesting )
  1297     }
  1588                 {
       
  1589                 RProperty::Set(KTAGDPSNotification, KMPXHarvesting, ETrue);
       
  1590                 }
       
  1591             else
       
  1592                 {
       
  1593                 RProperty::Set(KTAGDPSNotification, KMPXHarvesting, EFalse);
       
  1594                 }
       
  1595                 
       
  1596             TN_DEBUG3( "CThumbAGProcessor::HandleCollectionMessage -- end() iHarvesting == %d, iMPXHarvesting == %d", iHarvesting, iMPXHarvesting);
       
  1597             }
       
  1598         }
       
  1599     }
       
  1600 
  1298 // -----------------------------------------------------------------------------
  1601 // -----------------------------------------------------------------------------
  1299 // CThumbAGProcessor::HandleOpenL
  1602 // CThumbAGProcessor::HandleOpenL
  1300 // From MMPXCollectionObserver
  1603 // From MMPXCollectionObserver
  1301 // Handles the collection entries being opened.
  1604 // Handles the collection entries being opened.
  1302 // -----------------------------------------------------------------------------
  1605 // -----------------------------------------------------------------------------
  1303 //
  1606 //
  1304 void CThumbAGProcessor::HandleOpenL( const CMPXMedia& /*aEntries*/,
  1607 void CThumbAGProcessor::HandleOpenL( const CMPXMedia& /*aEntries*/, TInt /*aIndex*/,
  1305                                             TInt /*aIndex*/,
  1608                                                TBool /*aComplete*/, TInt /*aError*/ )
  1306                                             TBool /*aComplete*/,
       
  1307                                             TInt /*aError*/ )
       
  1308      {
  1609      {
  1309      // not needed here
  1610      // not needed here
  1310      }
  1611      }
  1311 
  1612 
  1312 // -----------------------------------------------------------------------------
  1613 // -----------------------------------------------------------------------------
  1329                                                        TInt /*aError*/ )
  1630                                                        TInt /*aError*/ )
  1330     {
  1631     {
  1331     // not needed here
  1632     // not needed here
  1332     }
  1633     }
  1333 
  1634 
       
  1635 // -----------------------------------------------------------------------------
       
  1636 // ActivityChanged()
       
  1637 // -----------------------------------------------------------------------------
       
  1638 //
       
  1639 void CThumbAGProcessor::ActivityChanged(const TBool aActive)
       
  1640     {
       
  1641     TN_DEBUG2( "void CThumbAGProcessor::ActivityChanged() aActive == %d", aActive);
       
  1642     if(aActive)
       
  1643         {
       
  1644         iIdle = EFalse;
       
  1645         }
       
  1646     else
       
  1647         {
       
  1648         iIdle = ETrue; 
       
  1649         
       
  1650         if(iAddQueue.Count() + iModifyQueue.Count() + iRemoveQueue.Count() + i2ndRoundGenerateQueue.Count() > 0 )
       
  1651             {
       
  1652             ActivateAO();
       
  1653             }
       
  1654         }
       
  1655     }
       
  1656 
       
  1657 
       
  1658 // ---------------------------------------------------------------------------
       
  1659 // CThumbAGProcessor::FormatNotification
       
  1660 // Handles a format operation
       
  1661 // ---------------------------------------------------------------------------
       
  1662 //
       
  1663 void CThumbAGProcessor::FormatNotification( TBool aFormat )
       
  1664     {
       
  1665     TN_DEBUG2( "CThumbAGProcessor::FormatNotification(%d)", aFormat );
       
  1666     
       
  1667     iFormatting = aFormat;
       
  1668     if(!aFormat)
       
  1669         {
       
  1670         ActivateAO();
       
  1671         }
       
  1672     }
       
  1673 
       
  1674 // ---------------------------------------------------------------------------
       
  1675 // CThumbAGProcessor::RPropertyNotification
       
  1676 // Handles a RProperty changed operation
       
  1677 // ---------------------------------------------------------------------------
       
  1678 //
       
  1679 void CThumbAGProcessor::RPropertyNotification(const TInt aError, const TUid aKeyCategory, const TUint aPropertyKey, const TInt aValue)
       
  1680     {
       
  1681     TN_DEBUG5( "CThumbAGProcessor::RPropertyNotification() aError = %d, aPropertyKey = %d, aKeyCategory = %d, aValue = %d", aError, aPropertyKey, aKeyCategory, aValue );
       
  1682     
       
  1683     if(aPropertyKey == KForceBackgroundGeneration && aKeyCategory == KTAGDPSNotification )
       
  1684         {
       
  1685         if( aValue == 1 && aError == KErrNone )
       
  1686             {
       
  1687             iForegroundRun = ETrue;
       
  1688             ActivateAO();
       
  1689             }
       
  1690         else
       
  1691             {
       
  1692             iForegroundRun = EFalse;
       
  1693             }
       
  1694         }
       
  1695     }
       
  1696 
       
  1697 // ---------------------------------------------------------------------------
       
  1698 // CThumbAGProcessor::UpdateItemsLeft
       
  1699 // Update KItemsleft PS value if changed
       
  1700 // ---------------------------------------------------------------------------
       
  1701 //
       
  1702 void CThumbAGProcessor::UpdatePSValues(const TBool aDefine)
       
  1703     {
       
  1704     TInt itemsLeft = iModifyQueue.Count() + iAddQueue.Count();
       
  1705     TBool daemonProcessing = EFalse;
       
  1706     
       
  1707     if(itemsLeft + i2ndRoundGenerateQueue.Count() + iRemoveQueue.Count() > 0 )
       
  1708         {
       
  1709         daemonProcessing = ETrue;
       
  1710         }
       
  1711     
       
  1712     if(aDefine)
       
  1713         {
       
  1714         TN_DEBUG1( "CThumbAGProcessor::UpdatePSValues() define");
       
  1715         RProperty::Define(KTAGDPSNotification, KDaemonProcessing, RProperty::EInt);
       
  1716         RProperty::Set(KTAGDPSNotification, KDaemonProcessing, 0);
       
  1717         daemonProcessing = EFalse;
       
  1718         RProperty::Define(KTAGDPSNotification, KItemsleft, RProperty::EInt);
       
  1719         RProperty::Set(KTAGDPSNotification, KItemsleft, 0);
       
  1720         iPreviousItemsLeft = 0;
       
  1721         }
       
  1722     
       
  1723     if( daemonProcessing != iPreviousDaemonProcessing)
       
  1724         {
       
  1725         TN_DEBUG2( "CThumbAGProcessor::UpdatePSValues() update KDaemonProcessing == %d", daemonProcessing);
       
  1726         iPreviousDaemonProcessing = daemonProcessing;
       
  1727         RProperty::Set(KTAGDPSNotification, KDaemonProcessing, daemonProcessing);
       
  1728         }
       
  1729     
       
  1730     if( itemsLeft != iPreviousItemsLeft)
       
  1731         {
       
  1732         TN_DEBUG2( "CThumbAGProcessor::UpdatePSValues() update KItemsleft == %d", itemsLeft);
       
  1733         iPreviousItemsLeft = itemsLeft;
       
  1734         RProperty::Set(KTAGDPSNotification, KItemsleft, itemsLeft );
       
  1735         }
       
  1736     }
       
  1737 
  1334 // End of file
  1738 // End of file