engine/collectionframework/datasource/plugins/glxdatasourcemde2.5/src/glxdatasourcemds.cpp
changeset 36 6481344a6d67
parent 24 99ad1390cd33
child 44 aa2fa096cbfb
equal deleted inserted replaced
33:1ee2af37811f 36:6481344a6d67
    18 
    18 
    19 
    19 
    20 // INCLUDE FILES
    20 // INCLUDE FILES
    21 #include "glxdatasourcemds.h"
    21 #include "glxdatasourcemds.h"
    22 
    22 
       
    23 #include <e32base.h>
    23 #include <fbs.h>
    24 #include <fbs.h>
    24 #include <glxbackgroundtnmessagedefs.h>
    25 #include <glxbackgroundtnmessagedefs.h>
    25 #include <glxcollectionmessagedefs.h>
    26 #include <glxcollectionmessagedefs.h>
    26 #include <glxcommandrequest.h>
    27 #include <glxcommandrequest.h>
    27 #include <glxgetrequest.h>
    28 #include <glxgetrequest.h>
    46 #include "glxdatasourcetaskmdsattribute.h"
    47 #include "glxdatasourcetaskmdsattribute.h"
    47 #include "glxdatasourcetaskmdscommand.h"
    48 #include "glxdatasourcetaskmdscommand.h"
    48 #include "glxdatasourcetaskmdsidlist.h"
    49 #include "glxdatasourcetaskmdsidlist.h"
    49 #include "glxdatasourcetaskmdsthumbnail.h"
    50 #include "glxdatasourcetaskmdsthumbnail.h"
    50 
    51 
    51 #ifndef USE_S60_TNM
    52 #ifdef USE_S60_TNM
       
    53 const TInt KMaxGridThumbnailWidth = 200;
       
    54 #else
    52 const TInt KGlxThumbnailCleanupAfterDeletions = 200;
    55 const TInt KGlxThumbnailCleanupAfterDeletions = 200;
    53 
    56 
    54 _LIT(KGlxMdeDataSourceThumbnailDatabase, "glxmdstn");
    57 _LIT(KGlxMdeDataSourceThumbnailDatabase, "glxmdstn");
    55 #endif
    58 #endif
    56 
       
    57 const TInt KMaxGridThumbnailWidth = 200;
       
    58 
    59 
    59 _LIT(KObjectDefLocation, "Location");
    60 _LIT(KObjectDefLocation, "Location");
    60 _LIT(KObjectDefNameAlbum, "Album");
    61 _LIT(KObjectDefNameAlbum, "Album");
    61 _LIT(KObjectDefNameImage, "Image");
    62 _LIT(KObjectDefNameImage, "Image");
    62 _LIT(KObjectDefNameMedia, "MediaObject");
    63 _LIT(KObjectDefNameMedia, "MediaObject");
    75 _LIT(KGlxMdeCameraAlbumUri, "defaultalbum_captured");
    76 _LIT(KGlxMdeCameraAlbumUri, "defaultalbum_captured");
    76 _LIT(KGlxMdeFavoritesUri, "defaultalbum_favourites");
    77 _LIT(KGlxMdeFavoritesUri, "defaultalbum_favourites");
    77 
    78 
    78 #undef __USING_INTELLIGENT_UPDATE_FILTERING
    79 #undef __USING_INTELLIGENT_UPDATE_FILTERING
    79 
    80 
       
    81 const TInt KHarvestUpdateChunkSize = 1000;
       
    82 
    80 // ---------------------------------------------------------------------------
    83 // ---------------------------------------------------------------------------
    81 // MPXChangeEventType
    84 // MPXChangeEventType
    82 // Helper method
    85 // Helper method
    83 // ---------------------------------------------------------------------------
    86 // ---------------------------------------------------------------------------
    84 //
    87 //
    99 		break;
   102 		break;
   100 		}
   103 		}
   101 	return type;
   104 	return type;
   102 	}
   105 	}
   103 
   106 
       
   107 
       
   108 // ---------------------------------------------------------------------------
       
   109 // CGlxMDSShutdownObserver::NewL()
       
   110 // ---------------------------------------------------------------------------
       
   111 //
       
   112 CGlxMDSShutdownObserver* CGlxMDSShutdownObserver::NewL( MGlxMDSShutdownObserver& aObserver,
       
   113                                                 const TUid& aKeyCategory,
       
   114                                                 const TInt aPropertyKey,
       
   115                                                 TBool aDefineKey)
       
   116     {
       
   117     TRACER("CGlxMDSShutdownObserver* CGlxMDSShutdownObserver::NewL");
       
   118     CGlxMDSShutdownObserver* self = new( ELeave )CGlxMDSShutdownObserver( aObserver, 
       
   119                                                                   aKeyCategory,
       
   120                                                                   aPropertyKey,
       
   121                                                                   aDefineKey);
       
   122     CleanupStack::PushL( self );
       
   123     self->ConstructL();
       
   124     CleanupStack::Pop( self );
       
   125     return self;
       
   126     }
       
   127 
       
   128 // ---------------------------------------------------------------------------
       
   129 // CGlxMDSShutdownObserver::CGlxMDSShutdownObserver()
       
   130 // ---------------------------------------------------------------------------
       
   131 //
       
   132 CGlxMDSShutdownObserver::CGlxMDSShutdownObserver( MGlxMDSShutdownObserver& aObserver,
       
   133                                           const TUid& aKeyCategory,
       
   134                                           const TInt aPropertyKey,
       
   135                                           TBool aDefineKey)
       
   136     : CActive( CActive::EPriorityStandard ), iObserver( aObserver ),
       
   137       iKeyCategory( aKeyCategory ), iPropertyKey(aPropertyKey), iDefineKey( aDefineKey )
       
   138     {   
       
   139     TRACER("CGlxMDSShutdownObserver::CGlxMDSShutdownObserver()");
       
   140     CActiveScheduler::Add( this );
       
   141     }
       
   142 
       
   143 // ---------------------------------------------------------------------------
       
   144 // CGlxMDSShutdownObserver::ConstructL()
       
   145 // ---------------------------------------------------------------------------
       
   146 //
       
   147 void CGlxMDSShutdownObserver::ConstructL()
       
   148     { 
       
   149     TRACER("void CGlxMDSShutdownObserver::ConstructL()");
       
   150     // define P&S property types
       
   151     if (iDefineKey)
       
   152         {
       
   153         RProperty::Define(iKeyCategory,iPropertyKey,
       
   154                           RProperty::EInt,KAllowAllPolicy,KPowerMgmtPolicy);
       
   155         }
       
   156     
       
   157     // attach to the property
       
   158     TInt err = iProperty.Attach(iKeyCategory,iPropertyKey,EOwnerThread);
       
   159     User::LeaveIfError(err);
       
   160     
       
   161     // wait for the previously attached property to be updated
       
   162     iProperty.Subscribe(iStatus);
       
   163     SetActive();
       
   164     }
       
   165 
       
   166 // ---------------------------------------------------------------------------
       
   167 // CGlxMDSShutdownObserver::~CGlxMDSShutdownObserver()
       
   168 // ---------------------------------------------------------------------------
       
   169 //
       
   170 CGlxMDSShutdownObserver::~CGlxMDSShutdownObserver()
       
   171     {
       
   172     TRACER("CGlxMDSShutdownObserver::~CGlxMDSShutdownObserver()");
       
   173     Cancel();
       
   174     iProperty.Close();
       
   175     }
       
   176 
       
   177 // ---------------------------------------------------------------------------
       
   178 // CGlxMDSShutdownObserver::RunL()
       
   179 // ---------------------------------------------------------------------------
       
   180 //
       
   181 void CGlxMDSShutdownObserver::RunL()
       
   182     {
       
   183     TRACER("void CGlxMDSShutdownObserver::RunL()");
       
   184 
       
   185     // resubscribe before processing new value to prevent missing updates
       
   186     iProperty.Subscribe(iStatus);
       
   187     SetActive();
       
   188     
       
   189     // retrieve the value
       
   190     TInt value = 0;
       
   191     TInt err = iProperty.Get(value);
       
   192     GLX_DEBUG2("CGlxMDSShutdownObserver::RunL(): iProperty.Get(value); returns %d", err);
       
   193     
       
   194     User::LeaveIfError(err);
       
   195 
       
   196     iObserver.ShutdownNotification(value);
       
   197     }
       
   198 
       
   199 // ---------------------------------------------------------------------------
       
   200 // CGlxMDSShutdownObserver::DoCancel()
       
   201 // ---------------------------------------------------------------------------
       
   202 //
       
   203 void CGlxMDSShutdownObserver::DoCancel()
       
   204     {
       
   205     TRACER("void CGlxMDSShutdownObserver::DoCancel()");
       
   206     iProperty.Cancel();
       
   207     }
       
   208 
       
   209 
       
   210 
   104 // ============================ MEMBER FUNCTIONS ==============================
   211 // ============================ MEMBER FUNCTIONS ==============================
   105 
   212 
   106 // ---------------------------------------------------------------------------
   213 // ---------------------------------------------------------------------------
   107 // NewL()
   214 // NewL()
   108 // ---------------------------------------------------------------------------
   215 // ---------------------------------------------------------------------------
   141     	{
   248     	{
   142     	iThumbnailCreator->Close(iThumbnailDatabase);
   249     	iThumbnailCreator->Close(iThumbnailDatabase);
   143     	}
   250     	}
   144     delete iThumbnailDatabase;
   251     delete iThumbnailDatabase;
   145 #endif
   252 #endif
   146 
       
   147     iFs.Close();
   253     iFs.Close();
       
   254     iHC.Close();
   148     RFbsSession::Disconnect();
   255     RFbsSession::Disconnect();
   149     iMonthArray.Close();
   256     iMonthArray.Close();
   150     iMonthList.Close();
   257     iMonthList.Close();
   151     iUpdateData.Close();
   258     iUpdateData.Close();
       
   259     iAddedItems.Reset();
       
   260     iAddedItems.Close();
   152     delete iUpdateCallback;
   261     delete iUpdateCallback;
   153     delete iCreateSessionCallback;
   262     delete iCreateSessionCallback;
       
   263     delete iMDSShutdownObserver ;
   154 	}
   264 	}
   155 
   265 
   156 // ---------------------------------------------------------------------------
   266 // ---------------------------------------------------------------------------
   157 // CGlxDataSourceMde()
   267 // CGlxDataSourceMde()
   158 // ---------------------------------------------------------------------------
   268 // ---------------------------------------------------------------------------
   159 //
   269 //
   160 CGlxDataSourceMde::CGlxDataSourceMde()
   270 CGlxDataSourceMde::CGlxDataSourceMde()
   161 	{
   271 	{
   162     TRACER("CGlxDataSourceMde::CGlxDataSourceMde()")
   272     TRACER("CGlxDataSourceMde::CGlxDataSourceMde()");
   163     //No Implementation
   273     //No Implementation
   164 	}
   274 	}
   165 
   275 
   166 // ---------------------------------------------------------------------------
   276 // ---------------------------------------------------------------------------
   167 // ConstructL()
   277 // ConstructL()
   168 // ---------------------------------------------------------------------------
   278 // ---------------------------------------------------------------------------
   169 //
   279 //
   170 void CGlxDataSourceMde::ConstructL()
   280 void CGlxDataSourceMde::ConstructL()
   171 	{
   281 	{
   172     TRACER("CGlxDataSourceMde::ConstructL()")
   282     TRACER("CGlxDataSourceMde::ConstructL()");
   173     
   283     
   174 	iDataSourceReady = EFalse;			
   284 	iDataSourceReady = EFalse;			
   175     User::LeaveIfError(iFs.Connect());
   285     User::LeaveIfError(iFs.Connect());
   176 	iSession = CMdESession::NewL( *this );
   286 	iSession = CMdESession::NewL( *this );
   177             
   287             
   178     User::LeaveIfError(RFbsSession::Connect());
   288     User::LeaveIfError(RFbsSession::Connect());
   179 
   289 
   180 #ifdef USE_S60_TNM
   290 #ifdef USE_S60_TNM
   181     iTnEngine = CThumbnailManager::NewL( *this);
   291     iTnEngine = CThumbnailManager::NewL( *this);
   182     iTnEngine->SetFlagsL(CThumbnailManager::EAllowAnySize);
   292     iTnEngine->SetDisplayModeL( EColor16M );
   183     iTnEngine->SetDisplayModeL( EColor64K );
       
   184     iTnRequestInProgress = EFalse;
   293     iTnRequestInProgress = EFalse;
   185 #else
   294 #else
   186 	iThumbnailCreator = CGlxtnThumbnailCreator::InstanceL();
   295 	iThumbnailCreator = CGlxtnThumbnailCreator::InstanceL();
   187 	iThumbnailDatabase = CGlxtnThumbnailDatabase::NewL(
   296 	iThumbnailDatabase = CGlxtnThumbnailDatabase::NewL(
   188             	                        KGlxMdeDataSourceThumbnailDatabase, this);
   297             	                        KGlxMdeDataSourceThumbnailDatabase, this);
   189 #endif
   298 #endif
   190          	                        
   299             	                        
   191     iCreateSessionCallback = new ( ELeave )
   300     iCreateSessionCallback = new ( ELeave )
   192 	    CAsyncCallBack( TCallBack( CreateSession, this ), CActive::EPriorityHigh );
   301 	    CAsyncCallBack( TCallBack( CreateSession, this ), CActive::EPriorityHigh );
       
   302     
       
   303     iMDSShutdownObserver = CGlxMDSShutdownObserver::NewL( *this, KHarvesterPSShutdown, KMdSShutdown, EFalse );
       
   304     
   193     iUpdateCallback = new ( ELeave )
   305     iUpdateCallback = new ( ELeave )
   194 	    CAsyncCallBack( TCallBack( ProcessItemUpdate, this ), CActive::EPriorityLow );
   306 	    CAsyncCallBack( TCallBack( ProcessItemUpdate, this ), CActive::EPriorityLow );
   195     iUpdateData.Reserve(100); // ignore if it fails
   307     iUpdateData.Reserve(100); // ignore if it fails
       
   308     
       
   309     User::LeaveIfError(iHC.Connect());
       
   310     iHC.AddHarvesterEventObserver(*this, EHEObserverTypePlaceholder, KHarvestUpdateChunkSize);
       
   311 
       
   312     iHarvestingOngoing = EFalse;
   196 	}
   313 	}
   197 	
   314 	
   198 // ----------------------------------------------------------------------------
   315 // ----------------------------------------------------------------------------
   199 // from MMdESessionObserver
   316 // from MMdESessionObserver
   200 // CMPXCollectionMdEPlugin::HandleSessionOpened
   317 // CMPXCollectionMdEPlugin::HandleSessionOpened
   201 // ----------------------------------------------------------------------------
   318 // ----------------------------------------------------------------------------
   202 //    
   319 //    
   203 void CGlxDataSourceMde::HandleSessionOpened( CMdESession& aSession, TInt aError )    
   320 void CGlxDataSourceMde::HandleSessionOpened( CMdESession& aSession, TInt aError )    
   204     {
   321     {
   205     TRACER("CGlxDataSourceMde::HandleSessionOpened(CMdESession& aSession, TInt aError)")
   322     TRACER("CGlxDataSourceMde::HandleSessionOpened(CMdESession& aSession, TInt aError)");
   206     if( KErrNone != aError )
   323     if( KErrNone != aError )
   207         {
   324         {
   208         HandleSessionError(aSession, aError);
   325         HandleSessionError(aSession, aError);
   209         }
   326         }
   210     TRAPD(err, DoSessionInitL());
   327     TRAPD(err, DoSessionInitL());
   211     if( KErrNone != err )
   328     if (KErrNone == err)
       
   329         {
       
   330         iSessionOpen = ETrue;
       
   331         iDataSourceReady = ETrue;
       
   332         TryStartTask(ETrue);
       
   333         }
       
   334     else
   212         {
   335         {
   213         HandleSessionError(aSession, err);
   336         HandleSessionError(aSession, err);
   214         }
   337         }
   215     
       
   216     iSessionOpen = ETrue;
       
   217     iDataSourceReady = ETrue;
       
   218 	TryStartTask(ETrue);
       
   219     }
   338     }
   220     
   339     
   221 // ----------------------------------------------------------------------------
   340 // ----------------------------------------------------------------------------
   222 // from MMdESessionObserver
   341 // from MMdESessionObserver
   223 // CMPXCollectionMdEPlugin::HandleSessionError
   342 // CMPXCollectionMdEPlugin::HandleSessionError
   224 // ----------------------------------------------------------------------------
   343 // ----------------------------------------------------------------------------
   225 //     
   344 //     
   226 void CGlxDataSourceMde::HandleSessionError(CMdESession& /*aSession*/, TInt /*aError*/ )    
   345 void CGlxDataSourceMde::HandleSessionError(CMdESession& /*aSession*/, TInt aError )    
   227     {
   346     {
   228     TRACER("CGlxDataSourceMde::HandleSessionError(CMdESession& /*aSession*/, TInt /*aError*/)")
   347     TRACER("CGlxDataSourceMde::HandleSessionError(CMdESession& /*aSession*/, TInt aError)")
   229     delete iSession;
   348     GLX_DEBUG2("void CGlxDataSourceMde::HandleSessionError() aError(%d)", aError);
   230     iSession = NULL;
   349 
   231     iDataSourceReady = EFalse;
   350     iDataSourceReady = EFalse;
   232     iSessionOpen = EFalse;
   351     iSessionOpen = EFalse;
   233     iCreateSessionCallback->CallBack();
   352 
   234     }
   353     // We wait till MDS restarts before starting the session if the current session is locked.
   235 
   354     // that is handled separately by the MDS Shutdown PUB SUB Framework.   
       
   355     // for everything else we use the generic method and continue.
       
   356     if ( (KErrLocked != aError) && ( KErrServerTerminated != aError) )
       
   357         {
       
   358         iCreateSessionCallback->CallBack();
       
   359         }
       
   360     }
   236 
   361 
   237 // ---------------------------------------------------------------------------
   362 // ---------------------------------------------------------------------------
   238 // CreateTaskL
   363 // CreateTaskL
   239 // ---------------------------------------------------------------------------
   364 // ---------------------------------------------------------------------------
   240 //
   365 //
   241 CGlxDataSourceTask* CGlxDataSourceMde::CreateTaskL(CGlxRequest* aRequest, MGlxDataSourceRequestObserver& aObserver)
   366 CGlxDataSourceTask* CGlxDataSourceMde::CreateTaskL(CGlxRequest* aRequest, 
   242 	{
   367         MGlxDataSourceRequestObserver& aObserver)
   243     TRACER("CGlxDataSourceTask* CGlxDataSourceMde::CreateTaskL(CGlxRequest* aRequest, MGlxDataSourceRequestObserver& aObserver)")	
   368 	{
       
   369     TRACER("CGlxDataSourceTask* CGlxDataSourceMde::CreateTaskL(CGlxRequest* aRequest,MGlxDataSourceRequestObserver& aObserver)")	;
   244 	if(dynamic_cast<CGlxCommandRequest*>(aRequest))
   370 	if(dynamic_cast<CGlxCommandRequest*>(aRequest))
   245 		{
   371 		{
   246         CleanupStack::PushL(aRequest);
   372         CleanupStack::PushL(aRequest);
   247         CGlxDataSourceTaskMdeCommand* task = new (ELeave) CGlxDataSourceTaskMdeCommand(static_cast<CGlxCommandRequest*>(aRequest), aObserver, this);
   373         CGlxDataSourceTaskMdeCommand* task = new (ELeave) 
       
   374         CGlxDataSourceTaskMdeCommand(static_cast<CGlxCommandRequest*>(aRequest),
       
   375                 aObserver, this);
   248 		CleanupStack::Pop(aRequest); // now owned by task
   376 		CleanupStack::Pop(aRequest); // now owned by task
   249         CleanupStack::PushL(task);
   377         CleanupStack::PushL(task);
   250         task->ConstructL();
   378         task->ConstructL();
   251 		CleanupStack::Pop(task);
   379 		CleanupStack::Pop(task);
   252 		return task;
   380 		return task;
   253 		}
   381 		}
   254 	else if (dynamic_cast< CGlxGetRequest *>(aRequest))
   382 	else if (dynamic_cast< CGlxGetRequest *>(aRequest))
   255 		{
   383 		{
   256 	    GLX_LOG_INFO("==> CGlxDataSourceMde::CreateTaskL - CGlxDataSourceTaskMdeAttributeMde+");
       
   257 #ifdef _DEBUG
       
   258         _LIT( KFormatTimeStamp, "[%H:%T:%S.%*C5]");
       
   259 	    TTime time;
       
   260 	    time.HomeTime(); // Get home time
       
   261 	    TBuf<32> timeStampBuf;
       
   262 	    time.FormatL(timeStampBuf, KFormatTimeStamp);
       
   263 	    RDebug::Print(_L("%S"), &timeStampBuf);    
       
   264 #endif
       
   265         CleanupStack::PushL(aRequest);
   384         CleanupStack::PushL(aRequest);
   266         CGlxDataSourceTaskMdeAttributeMde* task = new (ELeave) CGlxDataSourceTaskMdeAttributeMde(static_cast<CGlxGetRequest*>(aRequest), aObserver, this);
   385         CGlxDataSourceTaskMdeAttributeMde* task = new (ELeave) 
       
   386         CGlxDataSourceTaskMdeAttributeMde(static_cast<CGlxGetRequest*>(aRequest),
       
   387                 aObserver, this);
   267 		CleanupStack::Pop(aRequest); // now owned by task
   388 		CleanupStack::Pop(aRequest); // now owned by task
   268         CleanupStack::PushL(task);
   389         CleanupStack::PushL(task);
   269         task->ConstructL();
   390         task->ConstructL();
   270 		CleanupStack::Pop(task);
   391 		CleanupStack::Pop(task);
   271 		return task;
   392 		return task;
   272 		}
   393 		}
   273 	else if (dynamic_cast< CGlxIdListRequest *>(aRequest))
   394 	else if (dynamic_cast< CGlxIdListRequest *>(aRequest))
   274 		{	
   395 		{	
   275         CleanupStack::PushL(aRequest);
   396         CleanupStack::PushL(aRequest);
   276         CGlxDataSourceTaskMdeIdList* task = new (ELeave) CGlxDataSourceTaskMdeIdList(static_cast<CGlxIdListRequest*>(aRequest), aObserver, this);
   397         CGlxDataSourceTaskMdeIdList* task = new (ELeave) 
       
   398         CGlxDataSourceTaskMdeIdList(static_cast<CGlxIdListRequest*>(aRequest), 
       
   399                 aObserver, this);
   277         CleanupStack::Pop(aRequest); // now owned by task
   400         CleanupStack::Pop(aRequest); // now owned by task
   278         CleanupStack::PushL(task); 
   401         CleanupStack::PushL(task); 
   279         task->ConstructL();
   402         task->ConstructL();
   280         CleanupStack::Pop(task);
   403         CleanupStack::Pop(task);
   281         return task;
   404         return task;
   282 		}
   405 		}
   283 	else if (dynamic_cast< CGlxThumbnailRequest *>(aRequest))
   406 	else if (dynamic_cast< CGlxThumbnailRequest *>(aRequest))
   284 		{	
   407 		{	
   285 	    GLX_LOG_INFO("==> CGlxDataSourceMde::CreateTaskL - CGlxDataSourceTaskMdeThumbnail+");
       
   286 #ifdef _DEBUG
       
   287         _LIT( KFormatTimeStamp, "[%H:%T:%S.%*C5]");
       
   288 	    TTime time;
       
   289 	    time.HomeTime(); // Get home time
       
   290 	    TBuf<32> timeStampBuf;
       
   291 	    time.FormatL(timeStampBuf, KFormatTimeStamp);
       
   292 	    RDebug::Print(_L("%S"), &timeStampBuf);    
       
   293 #endif
       
   294         CleanupStack::PushL(aRequest);
   408         CleanupStack::PushL(aRequest);
   295         CGlxDataSourceTaskMdeThumbnail* task = new (ELeave) CGlxDataSourceTaskMdeThumbnail(static_cast<CGlxThumbnailRequest*>(aRequest), aObserver, this);
   409         CGlxDataSourceTaskMdeThumbnail* task = new (ELeave) 
       
   410         CGlxDataSourceTaskMdeThumbnail(static_cast<CGlxThumbnailRequest*>(aRequest), 
       
   411                 aObserver, this);
   296         CleanupStack::Pop(aRequest); // now owned by task
   412         CleanupStack::Pop(aRequest); // now owned by task
   297         CleanupStack::PushL(task); 
   413         CleanupStack::PushL(task); 
   298         task->ConstructL();
   414         task->ConstructL();
   299         CleanupStack::Pop(task);
   415         CleanupStack::Pop(task);
   300         return task;
   416         return task;
   309 #ifndef USE_S60_TNM
   425 #ifndef USE_S60_TNM
   310 // ---------------------------------------------------------------------------
   426 // ---------------------------------------------------------------------------
   311 // ThumbnailAvailable
   427 // ThumbnailAvailable
   312 // ---------------------------------------------------------------------------
   428 // ---------------------------------------------------------------------------
   313 //
   429 //
   314 void CGlxDataSourceMde::ThumbnailAvailable(const TGlxMediaId& /*aId*/, const TSize& /*aSize*/)
   430 void CGlxDataSourceMde::ThumbnailAvailable(const TGlxMediaId& 
   315 	{
   431         /*aId*/, const TSize& /*aSize*/)
   316     TRACER("CGlxDataSourceMde::ThumbnailAvailable(const TGlxMediaId& /*aId*/, const TSize& /*aSize*/)")
   432 	{
       
   433     TRACER("CGlxDataSourceMde::ThumbnailAvailable(const TGlxMediaId& /*aId*/, const TSize& /*aSize*/)");
   317 	//No implementation
   434 	//No implementation
   318 	}
   435 	}
   319 
   436 
   320 // ---------------------------------------------------------------------------
   437 // ---------------------------------------------------------------------------
   321 // BackgroundThumbnailError
   438 // BackgroundThumbnailError
   322 // ---------------------------------------------------------------------------
   439 // ---------------------------------------------------------------------------
   323 //
   440 //
   324 void CGlxDataSourceMde::BackgroundThumbnailError(const TGlxMediaId& aId, TInt aError)
   441 void CGlxDataSourceMde::BackgroundThumbnailError(const TGlxMediaId& aId, TInt aError)
   325 	{
   442 	{
   326     TRACER("CGlxDataSourceMde::BackgroundThumbnailError(const TGlxMediaId& aId, TInt aError)")
   443     TRACER("CGlxDataSourceMde::BackgroundThumbnailError(const TGlxMediaId& aId, TInt aError)");
   327 	TSize size(0, 0);
   444 	TSize size(0, 0);
   328 	TRAP_IGNORE(BackgroundThumbnailMessageL(aId, size, aError));
   445 	TRAP_IGNORE(BackgroundThumbnailMessageL(aId, size, aError));
   329 	}
   446 	}
   330 #endif
   447 #endif
   331 
   448 
   332 // ---------------------------------------------------------------------------
   449 // ---------------------------------------------------------------------------
   333 // BackgroundThumbnailMessageL
   450 // BackgroundThumbnailMessageL
   334 // ---------------------------------------------------------------------------
   451 // ---------------------------------------------------------------------------
   335 //
   452 //
   336 void CGlxDataSourceMde::BackgroundThumbnailMessageL(const TGlxMediaId& aId, const TSize& aSize, TInt aError)
   453 void CGlxDataSourceMde::BackgroundThumbnailMessageL(const TGlxMediaId& aId, 
   337 	{
   454         const TSize& aSize, TInt aError)
   338     TRACER("CGlxDataSourceMde::BackgroundThumbnailMessageL(const TGlxMediaId& aId, const TSize& aSize, TInt aError)")
   455 	{
       
   456     TRACER("CGlxDataSourceMde::BackgroundThumbnailMessageL(const TGlxMediaId& aId, const TSize& aSize, TInt aError)");
   339 	CMPXMessage* message = CMPXMessage::NewL();
   457 	CMPXMessage* message = CMPXMessage::NewL();
   340 	CleanupStack::PushL(message);
   458 	CleanupStack::PushL(message);
   341 	message->SetTObjectValueL(KMPXMessageGeneralId, KGlxMessageIdBackgroundThumbnail);
   459 	message->SetTObjectValueL(KMPXMessageGeneralId, KGlxMessageIdBackgroundThumbnail);
   342 	message->SetTObjectValueL<TMPXItemId>(KGlxBackgroundThumbnailMediaId, aId.Value());
   460 	message->SetTObjectValueL<TMPXItemId>(KGlxBackgroundThumbnailMediaId, aId.Value());
   343 	message->SetTObjectValueL(KGlxBackgroundThumbnailSize, aSize);
   461 	message->SetTObjectValueL(KGlxBackgroundThumbnailSize, aSize);
   350 // DoSessionInitL
   468 // DoSessionInitL
   351 // ---------------------------------------------------------------------------
   469 // ---------------------------------------------------------------------------
   352 //
   470 //
   353 void CGlxDataSourceMde::DoSessionInitL()
   471 void CGlxDataSourceMde::DoSessionInitL()
   354 	{
   472 	{
   355     TRACER("CGlxDataSourceMde::DoSessionInitL()")
   473     TRACER("CGlxDataSourceMde::DoSessionInitL()");
   356 	/// @todo check schema version number
   474 	/// @todo check schema version number
   357     iNameSpaceDef = &iSession->GetDefaultNamespaceDefL();
   475     iNameSpaceDef = &iSession->GetDefaultNamespaceDefL();
   358     
   476     
   359 	CMdEObject* cameraAlbum = iSession->GetObjectL(KGlxMdeCameraAlbumUri);
   477 	CMdEObject* cameraAlbum = iSession->GetObjectL(KGlxMdeCameraAlbumUri);
   360 	if ( !cameraAlbum )
   478 	if ( !cameraAlbum )
   394 // AddMdEObserversL
   512 // AddMdEObserversL
   395 // ---------------------------------------------------------------------------
   513 // ---------------------------------------------------------------------------
   396 //
   514 //
   397 void CGlxDataSourceMde::AddMdEObserversL()
   515 void CGlxDataSourceMde::AddMdEObserversL()
   398     {
   516     {
   399     TRACER("CGlxDataSourceMde::AddMdEObserversL()")
   517     TRACER("CGlxDataSourceMde::AddMdEObserversL()");
   400 	iSession->AddRelationObserverL(*this);
   518 	iSession->AddRelationObserverL(*this);
   401 	iSession->AddRelationPresentObserverL(*this);
   519 	iSession->AddRelationPresentObserverL(*this);
   402 	
   520 	
   403 	iSession->AddObjectObserverL(*this);
   521 	//when setting observing conditions,
   404 	iSession->AddObjectPresentObserverL(*this);
   522 	//add filters for all images, videos, Albums & Tags
       
   523 	CMdELogicCondition* addCondition = CMdELogicCondition::NewLC( ELogicConditionOperatorOr );
       
   524 	addCondition->AddObjectConditionL( *iImageDef );
       
   525 	addCondition->AddObjectConditionL( *iAlbumDef );
       
   526 	addCondition->AddObjectConditionL( *iTagDef );
       
   527 	
       
   528 	iSession->AddObjectObserverL(*this, addCondition );
       
   529 	iSession->AddObjectPresentObserverL(*this );
       
   530 		
       
   531 	// This addCondition should only be popped. 
       
   532 	// As the ownership is transferred, the same will be destroyed by MdS.
       
   533 	CleanupStack::Pop( addCondition ); 
   405     }
   534     }
   406 
   535 
   407 // ---------------------------------------------------------------------------
   536 // ---------------------------------------------------------------------------
   408 // CGlxDataSourceMde::HandleObjectNotification
   537 // CGlxDataSourceMde::HandleObjectNotification
   409 // ---------------------------------------------------------------------------
   538 // ---------------------------------------------------------------------------
   411 ///@todo AB test this
   540 ///@todo AB test this
   412 void CGlxDataSourceMde::HandleObjectNotification(CMdESession& /*aSession*/, 
   541 void CGlxDataSourceMde::HandleObjectNotification(CMdESession& /*aSession*/, 
   413 					TObserverNotificationType aType,
   542 					TObserverNotificationType aType,
   414 					const RArray<TItemId>& aObjectIdArray)
   543 					const RArray<TItemId>& aObjectIdArray)
   415 	{
   544 	{
   416     TRACER("CGlxDataSourceMde::HandleObjectNotification()")
   545     TRACER("CGlxDataSourceMde::HandleObjectNotification()");
       
   546     GLX_LOG_INFO3("CGlxDataSourceMde::HandleObjectNotification() aType=%d, aObjectIdArray.Count()=%d, iHarvestingOngoing=%d", 
       
   547 															  aType, aObjectIdArray.Count(),
       
   548 															  iHarvestingOngoing);
       
   549    	if (ENotifyAdd == aType)
       
   550 		{
       
   551 	    for ( TInt i = 0; i < aObjectIdArray.Count(); i++ )
       
   552 	        {
       
   553 			iAddedItems.Append(aObjectIdArray[i]);
       
   554 	        }
       
   555 	    GLX_LOG_INFO1("ENotifyAdd - iAddedItems.Count()=%d", iAddedItems.Count());
       
   556 		}
       
   557     
       
   558    	if (ENotifyModify == aType)
       
   559 		{
       
   560 	    for ( TInt i = 0; i < aObjectIdArray.Count(); i++ )
       
   561 	        {
       
   562 	        if (iAddedItems.Find(aObjectIdArray[i]) != KErrNotFound)
       
   563 	        	{
       
   564 		        if (!iHarvestingOngoing)
       
   565 		        	{
       
   566 		        	GLX_LOG_INFO("ENotifyModify - Harvesting Completed - "
       
   567 		        	        "Reset iAddedItems array");
       
   568 					iAddedItems.Reset();
       
   569 					break;
       
   570 		        	}
       
   571 		        GLX_LOG_INFO("ENotifyModify - Id found in iAddedItems array, DO NOT PROCESS");
       
   572 	        	return;
       
   573 	        	}
       
   574 	        }
       
   575         }
       
   576 
       
   577    	GLX_LOG_INFO("ProcessUpdateArray");
   417 	ProcessUpdateArray(aObjectIdArray,  MPXChangeEventType(aType), ETrue);
   578 	ProcessUpdateArray(aObjectIdArray,  MPXChangeEventType(aType), ETrue);
   418 #ifndef USE_S60_TNM
   579 #ifndef USE_S60_TNM
   419 	if(MPXChangeEventType(aType) == EMPXItemDeleted )
   580 	if(MPXChangeEventType(aType) == EMPXItemDeleted )
   420 		{			
   581 		{			
   421 		TInt count = aObjectIdArray.Count();
   582 		TInt count = aObjectIdArray.Count();
   422 		iDeletedCount += count;
   583 		iDeletedCount += count;
       
   584 		GLX_LOG_INFO2("EMPXItemDeleted - aObjectIdArray.Count()=%d, iDeletedCount=%d", 
       
   585 		        count, iDeletedCount);
   423 		if(iDeletedCount > KGlxThumbnailCleanupAfterDeletions)
   586 		if(iDeletedCount > KGlxThumbnailCleanupAfterDeletions)
   424 		    {
   587 		    {
   425 	    	TRAPD(err, ThumbnailCreator().CleanupThumbnailsL(iThumbnailDatabase));
   588 	    	TRAPD(err, ThumbnailCreator().CleanupThumbnailsL(iThumbnailDatabase));
   426 	    	if(!err)
   589 	    	if(!err)
   427 	    	    {
   590 	    	    {
   428 	    	    iDeletedCount = 0;
   591 	    	    iDeletedCount = 0;
   429 	    	    }
   592 	    	    }
   430 		    }
   593 		    }
   431 		}
   594 		}
       
   595 
       
   596 	if(MPXChangeEventType(aType) == EMPXItemModified )
       
   597 	    {
       
   598 	    GLX_LOG_INFO("EMPXItemModified");
       
   599 	    TRAP_IGNORE(ThumbnailCreator().CleanupThumbnailsL(iThumbnailDatabase));
       
   600 		}
   432 #endif		
   601 #endif		
   433 	}
   602 	}
   434 
       
   435 
   603 
   436 // ---------------------------------------------------------------------------
   604 // ---------------------------------------------------------------------------
   437 // CGlxDataSourceMde::HandleObjectPresentNotification
   605 // CGlxDataSourceMde::HandleObjectPresentNotification
   438 // ---------------------------------------------------------------------------
   606 // ---------------------------------------------------------------------------
   439 //
   607 //
   440 ///@todo AB test this
   608 ///@todo AB test this
   441 void CGlxDataSourceMde::HandleObjectPresentNotification(CMdESession& /*aSession*/, 
   609 void CGlxDataSourceMde::HandleObjectPresentNotification(CMdESession& /*aSession*/, 
   442 		TBool aPresent, const RArray<TItemId>& aObjectIdArray)
   610 		TBool aPresent, const RArray<TItemId>& aObjectIdArray)
   443 	{
   611 	{
   444     TRACER("CGlxDataSourceMde::HandleObjectPresentNotification()")
   612     TRACER("CGlxDataSourceMde::HandleObjectPresentNotification()");
   445 	if (aPresent)
   613 	if (aPresent)
   446 		{
   614 		{
   447 		ProcessUpdateArray(aObjectIdArray, EMPXItemInserted, ETrue);
   615 		ProcessUpdateArray(aObjectIdArray, EMPXItemInserted, ETrue);
   448 		}
   616 		}
   449 	else
   617 	else
   459 ///@todo AB test this
   627 ///@todo AB test this
   460 void CGlxDataSourceMde::HandleRelationNotification(CMdESession& /*aSession*/, 
   628 void CGlxDataSourceMde::HandleRelationNotification(CMdESession& /*aSession*/, 
   461 			TObserverNotificationType aType,
   629 			TObserverNotificationType aType,
   462 			const RArray<TItemId>& aRelationIdArray)
   630 			const RArray<TItemId>& aRelationIdArray)
   463 	{
   631 	{
   464     TRACER("CGlxDataSourceMde::HandleRelationNotification()")
   632     TRACER("CGlxDataSourceMde::HandleRelationNotification()");
   465 	ProcessUpdateArray(aRelationIdArray, MPXChangeEventType(aType), EFalse);
   633 	ProcessUpdateArray(aRelationIdArray, MPXChangeEventType(aType), EFalse);
   466 	}
   634 	}
   467 
   635 
   468 // ---------------------------------------------------------------------------
   636 // ---------------------------------------------------------------------------
   469 // CGlxDataSourceMde::HandleRelationPresentNotification
   637 // CGlxDataSourceMde::HandleRelationPresentNotification
   471 //
   639 //
   472 ///@todo AB test this
   640 ///@todo AB test this
   473 void CGlxDataSourceMde::HandleRelationPresentNotification(CMdESession& /*aSession*/,
   641 void CGlxDataSourceMde::HandleRelationPresentNotification(CMdESession& /*aSession*/,
   474 			TBool aPresent, const RArray<TItemId>& aRelationIdArray)
   642 			TBool aPresent, const RArray<TItemId>& aRelationIdArray)
   475 	{
   643 	{
   476     TRACER("CGlxDataSourceMde::HandleRelationPresentNotification()")
   644     TRACER("CGlxDataSourceMde::HandleRelationPresentNotification()");
   477 	if (aPresent)
   645 	if (aPresent)
   478 		{
   646 		{
   479 		ProcessUpdateArray(aRelationIdArray, EMPXItemInserted, EFalse);
   647 		ProcessUpdateArray(aRelationIdArray, EMPXItemInserted, EFalse);
   480 		}
   648 		}
   481 	else
   649 	else
   486 
   654 
   487 // ---------------------------------------------------------------------------
   655 // ---------------------------------------------------------------------------
   488 // ProcessUpdateArray
   656 // ProcessUpdateArray
   489 // ---------------------------------------------------------------------------
   657 // ---------------------------------------------------------------------------
   490 //
   658 //
   491 void CGlxDataSourceMde::ProcessUpdateArray(const RArray<TItemId>& aArray, TMPXChangeEventType aType, TBool aIsObject)
   659 void CGlxDataSourceMde::ProcessUpdateArray(const RArray<TItemId>& aArray, 
   492 	{
   660         TMPXChangeEventType aType, TBool aIsObject)
   493     TRACER("CGlxDataSourceMde::ProcessUpdateArray(const RArray<TItemId>& aArray, TMPXChangeEventType aType, TBool aIsObject)")
   661 	{
       
   662     TRACER("CGlxDataSourceMde::ProcessUpdateArray(const RArray<TItemId>& aArray,TMPXChangeEventType aType, TBool aIsObject)");
   494     // only need one message so process first item
   663     // only need one message so process first item
   495     TUpdateData update;
   664     TUpdateData update;
   496     update.iId = aArray[0];
   665     update.iId = aArray[0];
   497     update.iType = aType;
   666     update.iType = aType;
   498     update.iIsObject = aIsObject;
   667     update.iIsObject = aIsObject;
   508         iUpdateCallback->CallBack();
   677         iUpdateCallback->CallBack();
   509         }
   678         }
   510 	}
   679 	}
   511 	
   680 	
   512 // ---------------------------------------------------------------------------
   681 // ---------------------------------------------------------------------------
   513 // MPXChangeEventType
   682 // CreateSession
       
   683 // ---------------------------------------------------------------------------
       
   684 //
       
   685 void CGlxDataSourceMde::CreateSession()
       
   686     {
       
   687     TRACER("CGlxDataSourceMde::CreateSession()")
       
   688     TRAP_IGNORE(CreateSessionL());
       
   689     }
       
   690     
       
   691 // ---------------------------------------------------------------------------
       
   692 // CreateSession
   514 // ---------------------------------------------------------------------------
   693 // ---------------------------------------------------------------------------
   515 //
   694 //
   516 TInt CGlxDataSourceMde::CreateSession(TAny* aPtr)
   695 TInt CGlxDataSourceMde::CreateSession(TAny* aPtr)
   517     {
   696     {
   518     TRACER("CGlxDataSourceMde::CreateSession(TAny* aPtr)")
   697     TRACER("CGlxDataSourceMde::CreateSession(TAny* aPtr)");
   519     CGlxDataSourceMde* self
   698     CGlxDataSourceMde* self
   520                     = reinterpret_cast<CGlxDataSourceMde*>( aPtr );
   699                     = reinterpret_cast<CGlxDataSourceMde*>( aPtr );
   521     TRAP_IGNORE(self->CreateSessionL());
   700     TRAP_IGNORE(self->CreateSessionL());
   522     return 0;
   701     return 0;
   523     }
   702     }
   526 // CreateSessionL
   705 // CreateSessionL
   527 // ---------------------------------------------------------------------------
   706 // ---------------------------------------------------------------------------
   528 //
   707 //
   529 void CGlxDataSourceMde::CreateSessionL()
   708 void CGlxDataSourceMde::CreateSessionL()
   530     {
   709     {
   531     TRACER("CGlxDataSourceMde::CreateSessionL()")
   710     TRACER("CGlxDataSourceMde::CreateSessionL()");
       
   711     delete iSession;
       
   712     iSession = NULL;
   532 	iSession = CMdESession::NewL( *this );
   713 	iSession = CMdESession::NewL( *this );
   533     }
   714     }
   534             
   715             
   535 
   716 
   536 // ---------------------------------------------------------------------------
   717 // ---------------------------------------------------------------------------
   537 // ProcessItemUpdate
   718 // ProcessItemUpdate
   538 // ---------------------------------------------------------------------------
   719 // ---------------------------------------------------------------------------
   539 //
   720 //
   540 TInt CGlxDataSourceMde::ProcessItemUpdate(TAny* aPtr)
   721 TInt CGlxDataSourceMde::ProcessItemUpdate(TAny* aPtr)
   541     {
   722     {
   542     TRACER("CGlxDataSourceMde::ProcessItemUpdate(TAny* aPtr)")
   723     TRACER("CGlxDataSourceMde::ProcessItemUpdate(TAny* aPtr)");
   543     CGlxDataSourceMde* self
   724     CGlxDataSourceMde* self
   544                     = reinterpret_cast<CGlxDataSourceMde*>( aPtr );
   725                     = reinterpret_cast<CGlxDataSourceMde*>( aPtr );
   545     TRAP_IGNORE(self->ProcessItemUpdateL());
   726     TRAP_IGNORE(self->ProcessItemUpdateL());
   546     return 0;
   727     return 0;
   547     }
   728     }
   550 // ProcessItemUpdateL
   731 // ProcessItemUpdateL
   551 // ---------------------------------------------------------------------------
   732 // ---------------------------------------------------------------------------
   552 //
   733 //
   553 void CGlxDataSourceMde::ProcessItemUpdateL()
   734 void CGlxDataSourceMde::ProcessItemUpdateL()
   554     {
   735     {
   555     TRACER("CGlxDataSourceMde::ProcessItemUpdateL()")
   736     TRACER("CGlxDataSourceMde::ProcessItemUpdateL()");
   556     //__ASSERT_DEBUG(iUpdateData.Count(), Panic(EGlxPanicIllegalState));
       
   557 	if ( !iUpdateData.Count() || iPauseUpdate )
   737 	if ( !iUpdateData.Count() || iPauseUpdate )
   558         {
   738         {
   559         return;
   739         return;
   560         }
   740         }
   561     CMPXMessage* message = CMPXMessage::NewL();
   741     CMPXMessage* message = CMPXMessage::NewL();
   562     CleanupStack::PushL(message);
   742     CleanupStack::PushL(message);
   563     message->SetTObjectValueL<TInt>(KMPXMessageGeneralId, KMPXMessageIdItemChanged);
   743     message->SetTObjectValueL<TInt>(KMPXMessageGeneralId, KMPXMessageIdItemChanged);
   564     message->SetTObjectValueL<TMPXChangeEventType>(KMPXMessageChangeEventType, iUpdateData[0].iType);
   744     message->SetTObjectValueL<TMPXChangeEventType>(KMPXMessageChangeEventType,
       
   745             iUpdateData[0].iType);
   565     TMPXGeneralCategory category = EMPXNoCategory;
   746     TMPXGeneralCategory category = EMPXNoCategory;
   566 	TMPXItemId id = iUpdateData[0].iId;
   747 	TMPXItemId id = iUpdateData[0].iId;
   567 	
   748 	
   568 #ifdef __USING_INTELLIGENT_UPDATE_FILTERING
   749 #ifdef __USING_INTELLIGENT_UPDATE_FILTERING
   569 	if ( !iUpdateData[0].iIsObject )
   750 	if ( !iUpdateData[0].iIsObject )
   587     			{
   768     			{
   588     			CMdEObject* rightObject = iSession->GetObjectL(rightId);
   769     			CMdEObject* rightObject = iSession->GetObjectL(rightId);
   589     		    __ASSERT_DEBUG(rightObject, Panic(EGlxPanicIllegalState));
   770     		    __ASSERT_DEBUG(rightObject, Panic(EGlxPanicIllegalState));
   590     			TContainerType rightContainer = ContainerType(rightObject);
   771     			TContainerType rightContainer = ContainerType(rightObject);
   591     			delete rightObject;
   772     			delete rightObject;
   592    		    	__ASSERT_DEBUG(( EContainerTypeAlbum != rightContainer), Panic(EGlxPanicIllegalState));
   773    		    	__ASSERT_DEBUG(( EContainerTypeAlbum != rightContainer), 
       
   774    		    	        Panic(EGlxPanicIllegalState));
   593     			if( EContainerTypeTag == rightContainer )
   775     			if( EContainerTypeTag == rightContainer )
   594     				{
   776     				{
   595         			id = leftId;
   777         			id = leftId;
   596         			containerId = rightId;
   778         			containerId = rightId;
   597     		    	containerCategory = EMPXTag;
   779     		    	containerCategory = EMPXTag;
   605     	    	{
   787     	    	{
   606     			id = rightId;
   788     			id = rightId;
   607     			containerId = leftId;
   789     			containerId = leftId;
   608     	    	containerCategory = EMPXAlbum;
   790     	    	containerCategory = EMPXAlbum;
   609     	    	}
   791     	    	}
   610     		message->SetTObjectValueL<TMPXGeneralCategory>(KGlxCollectionMessageContainerCategory, containerCategory);
   792     		message->SetTObjectValueL<TMPXGeneralCategory>(KGlxCollectionMessageContainerCategory,
   611     		message->SetTObjectValueL<TMPXItemId>(KGlxCollectionMessageContainerId, containerId);
   793     		        containerCategory);
       
   794     		message->SetTObjectValueL<TMPXItemId>(KGlxCollectionMessageContainerId, 
       
   795     		        containerId);
   612 			}
   796 			}
   613 	    else
   797 	    else
   614 	        {
   798 	        {
   615   	        // use id 0 to identify to ML that we don't know what was deleted
   799   	        // use id 0 to identify to ML that we don't know what was deleted
   616 	        id = 0;
   800 	        id = 0;
   645             	}
   829             	}
   646         	delete object;
   830         	delete object;
   647     		}
   831     		}
   648 	    }
   832 	    }
   649 #endif // __USING_INTELLIGENT_UPDATE_FILTERING
   833 #endif // __USING_INTELLIGENT_UPDATE_FILTERING
   650 	message->SetTObjectValueL<TMPXGeneralCategory>(KMPXMessageMediaGeneralCategory, category);
   834 	message->SetTObjectValueL<TMPXGeneralCategory>(KMPXMessageMediaGeneralCategory,
       
   835 	        category);
   651    	message->SetTObjectValueL<TMPXItemId>(KMPXMessageMediaGeneralId, id);
   836    	message->SetTObjectValueL<TMPXItemId>(KMPXMessageMediaGeneralId, id);
   652     BroadcastMessage(*message); 
   837     BroadcastMessage(*message); 
   653     CleanupStack::PopAndDestroy(message);
   838     CleanupStack::PopAndDestroy(message);
   654     iUpdateData.Remove(0);
   839     iUpdateData.Remove(0);
   655     }
   840     }
   658 // ContainerType
   843 // ContainerType
   659 // ---------------------------------------------------------------------------
   844 // ---------------------------------------------------------------------------
   660 //
   845 //
   661 CGlxDataSource::TContainerType CGlxDataSourceMde::ContainerType(CMdEObject* aObject)
   846 CGlxDataSource::TContainerType CGlxDataSourceMde::ContainerType(CMdEObject* aObject)
   662 	{
   847 	{
   663     TRACER("CGlxDataSourceMde::ContainerType(CMdEObject* aObject)")
   848     TRACER("CGlxDataSourceMde::ContainerType(CMdEObject* aObject)");
   664 	TContainerType containerType = EContainerTypeNotAContainer;
   849 	TContainerType containerType = EContainerTypeNotAContainer;
   665  	
   850  	
   666 	if( 0 == aObject->Def().Compare(*iAlbumDef) )
   851 	if( 0 == aObject->Def().Compare(*iAlbumDef) )
   667 		{
   852 		{
   668 		containerType = EContainerTypeAlbum;
   853 		containerType = EContainerTypeAlbum;
   682 
   867 
   683 // ---------------------------------------------------------------------------
   868 // ---------------------------------------------------------------------------
   684 // ContainerType
   869 // ContainerType
   685 // ---------------------------------------------------------------------------
   870 // ---------------------------------------------------------------------------
   686 //	
   871 //	
   687 CGlxDataSource::TContainerType CGlxDataSourceMde::ContainerType(CMdEObjectDef* aObjectDef)
   872 CGlxDataSource::TContainerType CGlxDataSourceMde::ContainerType(CMdEObjectDef* 
   688 	{
   873         aObjectDef)
   689     TRACER("CGlxDataSourceMde::ContainerType(CMdEObjectDef* aObjectDef)")
   874 	{
       
   875     TRACER("CGlxDataSourceMde::ContainerType()");
   690 	TContainerType containerType = EContainerTypeNotAContainer;
   876 	TContainerType containerType = EContainerTypeNotAContainer;
   691  	
   877  	
   692 	if( 0 == aObjectDef->Compare(*iAlbumDef) )
   878 	if( 0 == aObjectDef->Compare(*iAlbumDef) )
   693 		{
   879 		{
   694 		containerType = EContainerTypeAlbum;
   880 		containerType = EContainerTypeAlbum;
   709 // ItemType()
   895 // ItemType()
   710 // ---------------------------------------------------------------------------
   896 // ---------------------------------------------------------------------------
   711 //
   897 //
   712 CGlxDataSource::TItemType CGlxDataSourceMde::ItemType(CMdEObject* aObject)
   898 CGlxDataSource::TItemType CGlxDataSourceMde::ItemType(CMdEObject* aObject)
   713 	{
   899 	{
   714     TRACER("CGlxDataSourceMde::ItemType(CMdEObject* aObject)")
   900     TRACER("CGlxDataSourceMde::ItemType(CMdEObject* aObject)");
   715 	TItemType itemType = EItemTypeNotAnItem;
   901 	TItemType itemType = EItemTypeNotAnItem;
   716 	
   902 	
   717 	if( 0 == aObject->Def().Compare(*iImageDef) )
   903 	if( 0 == aObject->Def().Compare(*iImageDef) )
   718 		{
   904 		{
   719 		itemType = EItemTypeImage;
   905 		itemType = EItemTypeImage;
   730 // PrepareMonthsL()
   916 // PrepareMonthsL()
   731 // ---------------------------------------------------------------------------
   917 // ---------------------------------------------------------------------------
   732 //
   918 //
   733 void CGlxDataSourceMde::PrepareMonthsL()
   919 void CGlxDataSourceMde::PrepareMonthsL()
   734     {
   920     {
   735     TRACER("CGlxDataSourceMde::PrepareMonthsL()")
   921     TRACER("CGlxDataSourceMde::PrepareMonthsL()");
   736     TTime month(0);
   922     TTime month(0);
   737     iFirstMonth = month;
   923     iFirstMonth = month;
   738     }
   924     }
   739     
   925     
   740 // ---------------------------------------------------------------------------
   926 // ---------------------------------------------------------------------------
   741 // GetMonthIdL()
   927 // GetMonthIdL()
   742 // ---------------------------------------------------------------------------
   928 // ---------------------------------------------------------------------------
   743 //
   929 //
   744 const TGlxMediaId CGlxDataSourceMde::GetMonthIdL(const TTime& aMonth)
   930 const TGlxMediaId CGlxDataSourceMde::GetMonthIdL(const TTime& aMonth)
   745     {
   931     {
   746     TRACER("CGlxDataSourceMde::GetMonthIdL(const TTime& aMonth)")
   932     TRACER("CGlxDataSourceMde::GetMonthIdL()");
   747     TTime monthStart = iFirstMonth + aMonth.MonthsFrom(iFirstMonth);
   933     TTime monthStart = iFirstMonth + aMonth.MonthsFrom(iFirstMonth);
   748     const TTimeIntervalMonths KGlxOneMonth = 1;
   934     const TTimeIntervalMonths KGlxOneMonth = 1;
   749     const TTimeIntervalMicroSeconds KGlxOneMicrosecond = 1;
   935     const TTimeIntervalMicroSeconds KGlxOneMicrosecond = 1;
   750 
   936 
   751     TGlxMediaId monthId;    
   937     TGlxMediaId monthId;    
   773             {
   959             {
   774             TTime monthEnd = monthStart + KGlxOneMonth - KGlxOneMicrosecond;
   960             TTime monthEnd = monthStart + KGlxOneMonth - KGlxOneMicrosecond;
   775             month = iSession->NewObjectLC(*iMonthDef, title); 
   961             month = iSession->NewObjectLC(*iMonthDef, title); 
   776             
   962             
   777             // A title property def of type text is required.
   963             // A title property def of type text is required.
   778             CMdEPropertyDef& titlePropertyDef = iObjectDef->GetPropertyDefL(KPropertyDefNameTitle);
   964             CMdEPropertyDef& titlePropertyDef = iObjectDef->GetPropertyDefL(
       
   965                     KPropertyDefNameTitle);
   779             if (titlePropertyDef.PropertyType() != EPropertyText)
   966             if (titlePropertyDef.PropertyType() != EPropertyText)
   780             	{
   967             	{
   781             	User::Leave(KErrCorrupt);
   968             	User::Leave(KErrCorrupt);
   782             	}
   969             	}
   783             // Set the object title.
   970             // Set the object title.
   784             month->AddTextPropertyL (titlePropertyDef, title);
   971             month->AddTextPropertyL (titlePropertyDef, title);
   785 
   972 
   786             // A size property is required.
   973             // A size property is required.
   787             CMdEPropertyDef& sizePropertyDef = iObjectDef->GetPropertyDefL(KPropertyDefNameSize);
   974             CMdEPropertyDef& sizePropertyDef = iObjectDef->GetPropertyDefL(
       
   975                     KPropertyDefNameSize);
   788             if (sizePropertyDef.PropertyType() != EPropertyUint32)
   976             if (sizePropertyDef.PropertyType() != EPropertyUint32)
   789             	{
   977             	{
   790             	User::Leave(KErrCorrupt);
   978             	User::Leave(KErrCorrupt);
   791             	}
   979             	}
   792             month->AddUint32PropertyL(sizePropertyDef,0);
   980             month->AddUint32PropertyL(sizePropertyDef,0);
   793 
   981 
   794             
   982             
   795             // A creation date property is required.
   983             // A creation date property is required.
   796         	CMdEPropertyDef& creationDateDef = iObjectDef->GetPropertyDefL(KPropertyDefNameCreationDate);
   984         	CMdEPropertyDef& creationDateDef = iObjectDef->GetPropertyDefL(
       
   985         	        KPropertyDefNameCreationDate);
   797             if (creationDateDef.PropertyType() != EPropertyTime)
   986             if (creationDateDef.PropertyType() != EPropertyTime)
   798             	{
   987             	{
   799             	User::Leave(KErrCorrupt);
   988             	User::Leave(KErrCorrupt);
   800             	}
   989             	}
   801         	month->AddTimePropertyL(creationDateDef, monthStart);
   990         	month->AddTimePropertyL(creationDateDef, monthStart);
   802 
   991 
   803             // A last modified date property is required.
   992             // A last modified date property is required.
   804         	CMdEPropertyDef& lmDateDef = iObjectDef->GetPropertyDefL(KPropertyDefNameLastModifiedDate);
   993         	CMdEPropertyDef& lmDateDef = iObjectDef->GetPropertyDefL(
       
   994         	        KPropertyDefNameLastModifiedDate);
   805             if (lmDateDef.PropertyType() != EPropertyTime)
   995             if (lmDateDef.PropertyType() != EPropertyTime)
   806             	{
   996             	{
   807             	User::Leave(KErrCorrupt);
   997             	User::Leave(KErrCorrupt);
   808             	}
   998             	}
   809             
   999             
   863     {
  1053     {
   864     iPauseUpdate = ETrue;
  1054     iPauseUpdate = ETrue;
   865     }	
  1055     }	
   866     
  1056     
   867 #ifdef USE_S60_TNM
  1057 #ifdef USE_S60_TNM
   868 void CGlxDataSourceMde::FetchThumbnailL(CGlxRequest* aRequest, MThumbnailFetchRequestObserver& aObserver)
  1058 void CGlxDataSourceMde::FetchThumbnailL(CGlxRequest* aRequest, 
   869 	{
  1059         MThumbnailFetchRequestObserver& aObserver)
       
  1060 	{
       
  1061     TRACER("CGlxDataSourceMde::FetchThumbnailL()");
       
  1062 #ifdef _DEBUG
       
  1063     iStartTime.HomeTime(); // Get home time
       
  1064 #endif
       
  1065     
   870 	iTnFetchObserver = &aObserver;
  1066 	iTnFetchObserver = &aObserver;
   871 	
  1067 	
   872     CGlxThumbnailRequest* request = static_cast<CGlxThumbnailRequest*>(aRequest);
  1068     CGlxThumbnailRequest* request = static_cast<CGlxThumbnailRequest*>(aRequest);
   873     
  1069     
   874     TGlxThumbnailRequest tnReq;
  1070     TGlxThumbnailRequest tnReq;
   875     request->ThumbnailRequest(tnReq);
  1071     request->ThumbnailRequest(tnReq);
   876 	User::LeaveIfNull(request->ThumbnailInfo());
  1072 	User::LeaveIfNull(request->ThumbnailInfo());
   877 
  1073 
   878 	iTnHandle = tnReq.iBitmapHandle;
  1074 	iTnHandle = tnReq.iBitmapHandle;
   879 	iMediaId = tnReq.iId;
  1075 	iMediaId = tnReq.iId;
   880 	if (tnReq.iSizeClass.iWidth < KMaxGridThumbnailWidth)
  1076     if (tnReq.iSizeClass.iWidth < KMaxGridThumbnailWidth)
   881 	{
  1077     	{
   882 	    iTnEngine->SetFlagsL(CThumbnailManager::ECropToAspectRatio);
  1078    		iTnEngine->SetFlagsL(CThumbnailManager::ECropToAspectRatio);
   883 	    iTnEngine->SetThumbnailSizeL(EGridThumbnailSize);
  1079 	    iTnEngine->SetThumbnailSizeL(EGridThumbnailSize);
   884 	    GLX_LOG_INFO("CGlxDataSourceMde::FetchThumbnailL() - Fetch TN attrib - EGridThumbnailSize");
  1080 	    GLX_LOG_INFO("CGlxDataSourceMde::FetchThumbnailL() - Fetch TN attrib -"
   885 	}
  1081 	            " EGridThumbnailSize");
       
  1082     	}
   886     else
  1083     else
   887 	{
  1084     	{
   888 	     iTnEngine->SetFlagsL(CThumbnailManager::EDefaultFlags);
  1085    		iTnEngine->SetFlagsL(CThumbnailManager::EDefaultFlags);
   889 	     iTnEngine->SetThumbnailSizeL(EFullScreenThumbnailSize);
  1086     	iTnEngine->SetThumbnailSizeL(EFullScreenThumbnailSize);
   890 	     GLX_LOG_INFO("CGlxDataSourceMde::FetchThumbnailL() - Fetch TN attrib - EFullScreenThumbnailSize");
  1087     	GLX_LOG_INFO("CGlxDataSourceMde::FetchThumbnailL() - Fetch TN attrib - "
   891 	}
  1088     	        "EFullScreenThumbnailSize");
   892     CThumbnailObjectSource* source = CThumbnailObjectSource::NewLC(request->ThumbnailInfo()->FilePath(), 0);
  1089     	}
   893 #ifdef _DEBUG
  1090 
   894     iStartTime.UniversalTime();
  1091     if (tnReq.iPriorityMode == TGlxThumbnailRequest::EPrioritizeQuality)
   895 #endif
  1092         {
       
  1093         iTnEngine->SetQualityPreferenceL(CThumbnailManager::EOptimizeForQuality);
       
  1094         GLX_LOG_INFO("CGlxDataSourceMde::FetchThumbnailL() - Fetch TN attrib -"
       
  1095                 " EOptimizeForQuality");
       
  1096         }
       
  1097     else
       
  1098         {
       
  1099         iTnEngine->SetQualityPreferenceL(CThumbnailManager::EOptimizeForQualityWithPreview);
       
  1100         GLX_LOG_INFO("CGlxDataSourceMde::FetchThumbnailL() - Fetch TN attrib -"
       
  1101                 " EOptimizeForQualityWithPreview");
       
  1102         }
       
  1103     
       
  1104     CThumbnailObjectSource* source = CThumbnailObjectSource::NewLC(
       
  1105                                      request->ThumbnailInfo()->FilePath(), 0);
   896     iTnThumbnailCbId = iTnEngine->GetThumbnailL(*source);
  1106     iTnThumbnailCbId = iTnEngine->GetThumbnailL(*source);
       
  1107     CleanupStack::PopAndDestroy(source);
       
  1108 
   897     iTnRequestInProgress = ETrue;
  1109     iTnRequestInProgress = ETrue;
   898     CleanupStack::PopAndDestroy();
       
   899 	}
  1110 	}
   900 
  1111 
   901 TInt CGlxDataSourceMde::CancelFetchThumbnail()
  1112 TInt CGlxDataSourceMde::CancelFetchThumbnail()
   902 	{
  1113 	{
       
  1114     TRACER("CGlxDataSourceMde::CancelFetchThumbnail");
   903 	TInt ret = KErrNone;
  1115 	TInt ret = KErrNone;
   904 	if (iTnRequestInProgress)
  1116 	if (iTnRequestInProgress)
   905 		{
  1117 		{
   906 		ret = iTnEngine->CancelRequest(iTnThumbnailCbId);
  1118 		ret = iTnEngine->CancelRequest(iTnThumbnailCbId);
       
  1119 		iTnRequestInProgress = EFalse;
       
  1120         iTnFetchObserver->ThumbnailFetchComplete(KErrCancel,EFalse);
   907 		}
  1121 		}
   908 	return ret;
  1122 	return ret;
   909 	}
  1123 	}
   910 
  1124 
   911 void CGlxDataSourceMde::ThumbnailPreviewReady(MThumbnailData& /*aThumbnail*/, 
  1125 // Called when preview thumbnail is created
   912                                                     TThumbnailRequestId /*aId*/)
  1126 void CGlxDataSourceMde::ThumbnailPreviewReady(MThumbnailData& aThumbnail, 
   913     {
  1127                                               TThumbnailRequestId aId)
       
  1128     {
       
  1129     TRACER("CGlxDataSourceMde::ThumbnailPreviewReady()");
       
  1130     
       
  1131     TInt error = KErrNotSupported;
       
  1132     if ( aThumbnail.Bitmap() )
       
  1133          {
       
  1134          GLX_DEBUG1("CGlxDataSourceMde::ThumbnailPreviewReady preview aval");
       
  1135          error = KErrNone;
       
  1136          }
       
  1137     //This function is called number of times as a callback ,
       
  1138     //hence not trapping the leaving function which costs time and memory.
       
  1139     //Ignoring this for code scanner warnings - Leaving functions called in non-leaving functions.
       
  1140     ThumbnailReadyL(error, aThumbnail, aId, EFalse);
   914     }
  1141     }
   915 
  1142 
   916 // Called when real thumbnail is created
  1143 // Called when real thumbnail is created
   917 void CGlxDataSourceMde::ThumbnailReady(TInt aError,
  1144 void CGlxDataSourceMde::ThumbnailReady(TInt aError,
   918         MThumbnailData& aThumbnail, TThumbnailRequestId aId)
  1145         MThumbnailData& aThumbnail, TThumbnailRequestId aId)
   919 	{
  1146 	{
   920 	if (iTnThumbnailCbId == aId)
  1147 	TRACER("CGlxDataSourceMde::ThumbnailReady");
   921 		{
  1148 	GLX_DEBUG2("GlxDataSourceMde::ThumbnailReady aError=%d", aError);
   922 		iTnRequestInProgress = EFalse;
  1149 	//This function is called number of times as a callback ,
       
  1150     //hence not trapping the leaving function which costs time and memory.
       
  1151     //Ignoring this for code scanner warnings - Leaving functions called in non-leaving functions.
       
  1152 	ThumbnailReadyL(aError,aThumbnail, aId, ETrue);
       
  1153 	}
       
  1154 
       
  1155 // ---------------------------------------------------------------------------
       
  1156 // ThumbnailReadyL
       
  1157 // ---------------------------------------------------------------------------
       
  1158 //  
       
  1159 void CGlxDataSourceMde::ThumbnailReadyL(TInt aError,
       
  1160         MThumbnailData& aThumbnail, TThumbnailRequestId aId, TBool aQuality)
       
  1161     {
       
  1162     TRACER("CGlxDataSourceMde::ThumbnailReadyL()");
       
  1163     GLX_DEBUG3("CGlxDataSourceMde::ThumbnailReadyL aError=%d, aQuality=%d",
       
  1164                                 aError, aQuality);
   923 #ifdef _DEBUG
  1165 #ifdef _DEBUG
   924 		iStopTime.UniversalTime();
  1166     iStopTime.HomeTime(); // Get home time
   925 		GLX_LOG_INFO1("==> S60 TNMan fetch took <%d> us", (TInt)iStopTime.MicroSecondsFrom(iStartTime).Int64());
  1167     GLX_DEBUG2("=>CGlxDataSourceMde::ThumbnailReadyL - TN Fetch took <%d> us",
       
  1168                         (TInt)iStopTime.MicroSecondsFrom(iStartTime).Int64());
   926 #endif
  1169 #endif
   927 	    if (aError == KErrNone && iTnHandle)
  1170     
   928 	    	{
  1171     if (iTnThumbnailCbId == aId)
   929 	    	if (iTnHandle == KGlxMessageIdBackgroundThumbnail)
  1172         {
   930 	    		{
  1173         if (aError == KErrNone && iTnHandle)
   931 	    		BackgroundThumbnailMessageL(iMediaId, TSize(), aError);
  1174             {
   932 	    		}
  1175             if (iTnHandle == KGlxMessageIdBackgroundThumbnail)
   933 	    	else
  1176                 {
   934 	    		{
  1177                 BackgroundThumbnailMessageL(iMediaId, TSize(), aError);
       
  1178                 }
       
  1179             else
       
  1180                 {
   935                 delete iTnThumbnail;
  1181                 delete iTnThumbnail;
   936                 iTnThumbnail = NULL;
  1182                 iTnThumbnail = NULL;
   937 			    iTnThumbnail = aThumbnail.DetachBitmap();
  1183                 iTnThumbnail = aThumbnail.DetachBitmap();
   938 
  1184 
   939 				delete iThumbnail;
  1185 				delete iThumbnail;
   940                 iThumbnail = NULL;
  1186                 iThumbnail = NULL;
   941 			    iThumbnail = new (ELeave) CFbsBitmap();
  1187 			    iThumbnail = new (ELeave) CFbsBitmap();
   942 			    User::LeaveIfError( iThumbnail->Duplicate(iTnHandle));
  1188 			    User::LeaveIfError( iThumbnail->Duplicate(iTnHandle));
   946 			    CFbsBitGc* context = NULL;
  1192 			    CFbsBitGc* context = NULL;
   947 			    User::LeaveIfError(device->CreateContext(context));
  1193 			    User::LeaveIfError(device->CreateContext(context));
   948 			    CleanupStack::PushL(context);
  1194 			    CleanupStack::PushL(context);
   949 			    context->BitBlt( TPoint(), iTnThumbnail);
  1195 			    context->BitBlt( TPoint(), iTnThumbnail);
   950 			    CleanupStack::PopAndDestroy(context); 
  1196 			    CleanupStack::PopAndDestroy(context); 
   951 			    CleanupStack::PopAndDestroy(device);
  1197                 CleanupStack::PopAndDestroy(device);
   952 	    		}
  1198                 }
   953 	    	}
  1199             }
   954 
  1200         }
   955 		if (iTnFetchObserver)
  1201     
   956 			{
  1202     if (iTnFetchObserver && iTnRequestInProgress)
   957 			iTnFetchObserver->ThumbnailFetchComplete(aError);
  1203         {
   958 			iTnHandle = KErrNone;
  1204         iTnFetchObserver->ThumbnailFetchComplete(aError, aQuality);
   959 			}
  1205         iTnHandle = KErrNone;
   960 		}
  1206         iTnRequestInProgress = EFalse;
   961 	}
  1207         }
       
  1208     }
   962 #endif
  1209 #endif
       
  1210 
       
  1211 // ---------------------------------------------------------------------------
       
  1212 // CGlxDataSourceMde
       
  1213 // HarvestingUpdated
       
  1214 // ---------------------------------------------------------------------------
       
  1215 //
       
  1216 void CGlxDataSourceMde::HarvestingUpdated( 
       
  1217             HarvesterEventObserverType /*aHEObserverType*/, 
       
  1218             HarvesterEventState aHarvesterEventState,
       
  1219             TInt /*aItemsLeft*/)
       
  1220     {
       
  1221     TRACER("void CGlxDataSourceMde::HarvestingUpdated()");
       
  1222     GLX_LOG_INFO1("CGlxDataSourceMde::HarvestingUpdated() aHarvesterEventState=%d",
       
  1223             aHarvesterEventState);
       
  1224     
       
  1225     switch(aHarvesterEventState)
       
  1226         {
       
  1227         case EHEStateStarted:
       
  1228             GLX_LOG_INFO("CGlxDataSourceMde::HarvestingUpdated() - EHEStateStarted");
       
  1229         case EHEStateResumed:
       
  1230         case EHEStateHarvesting:
       
  1231         	 {
       
  1232              iHarvestingOngoing = ETrue;
       
  1233 	         }
       
  1234              break;
       
  1235         case EHEStatePaused:
       
  1236         case EHEStateFinished:
       
  1237         	 {
       
  1238 	         iHarvestingOngoing = EFalse;
       
  1239 	         GLX_LOG_INFO("CGlxDataSourceMde::HarvestingUpdated() - EHEStateFinished");
       
  1240         	 }
       
  1241              break;
       
  1242         default:
       
  1243             break;
       
  1244         }
       
  1245     }
       
  1246 
       
  1247 // ---------------------------------------------------------------------------
       
  1248 // ShutdownNotification
       
  1249 // ---------------------------------------------------------------------------
       
  1250 //  
       
  1251 void CGlxDataSourceMde::ShutdownNotification(TInt aShutdownState)
       
  1252     {
       
  1253     TRACER("void CGlxDataSourceMde::ShutdownNotification(TInt aShutdownState)")
       
  1254     GLX_DEBUG2("CGlxDataSourceMde::ShutdownNotification(aShutdownState=%d)", 
       
  1255             aShutdownState);
       
  1256 
       
  1257     if (!iDataSourceReady && 0 == aShutdownState)
       
  1258         {
       
  1259         GLX_DEBUG1("Photos MdS ShutdownNotification - MdS Server restarted!");
       
  1260         CreateSession();
       
  1261         }
       
  1262 
       
  1263     if (iDataSourceReady && 1 == aShutdownState)
       
  1264         {
       
  1265         GLX_DEBUG1("Photos MdS ShutdownNotification - MdS Server Shutdown!");
       
  1266         HandleSessionError(*iSession, KErrServerTerminated);
       
  1267         }
       
  1268     }