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