mtpdataproviders/mtpimagedp/src/cmtpimagedpobjectpropertymgr.cpp
branchRCL_3
changeset 2 4843bb5893b6
parent 0 d0791faffa3f
child 3 8b094906a049
equal deleted inserted replaced
1:f8e15b44d440 2:4843bb5893b6
    24 #include <s32file.h>
    24 #include <s32file.h>
    25 #include <e32const.h>
    25 #include <e32const.h>
    26 #include <e32cmn.h>
    26 #include <e32cmn.h>
    27 #include <imageconversion.h> 
    27 #include <imageconversion.h> 
    28 #include <mdeconstants.h>
    28 #include <mdeconstants.h>
       
    29 #include <thumbnailmanager.h>
    29 
    30 
    30 #include <mtp/mmtpobjectmgr.h>
    31 #include <mtp/mmtpobjectmgr.h>
    31 #include <mtp/cmtpobjectmetadata.h>
    32 #include <mtp/cmtpobjectmetadata.h>
    32 #include <mtp/tmtptypeuint32.h>
    33 #include <mtp/tmtptypeuint32.h>
    33 #include <mtp/cmtptypestring.h>
    34 #include <mtp/cmtptypestring.h>
       
    35 #include <mtp/cmtptypeopaquedata.h>
    34 #include <mtp/mmtpdataproviderframework.h>
    36 #include <mtp/mmtpdataproviderframework.h>
    35 #include <mtp/cmtptypearray.h>
    37 #include <mtp/cmtptypearray.h>
    36 #include <mtp/mmtpdataproviderframework.h>
    38 #include <mtp/mmtpdataproviderframework.h>
    37 #include <mtp/mmtpobjectmgr.h>
    39 #include <mtp/mmtpobjectmgr.h>
    38 #include <mtp/cmtptypestring.h>
    40 #include <mtp/cmtptypestring.h>
    39 #include <mtp/mtpprotocolconstants.h>
    41 #include <mtp/mtpprotocolconstants.h>
    40 
    42 
       
    43 #include "cmtpimagedp.h"
    41 #include "cmtpimagedpobjectpropertymgr.h"
    44 #include "cmtpimagedpobjectpropertymgr.h"
       
    45 #include "cmtpimagedpthumbnailcreator.h"
    42 #include "mtpimagedppanic.h"
    46 #include "mtpimagedppanic.h"
    43 #include "mtpimagedputilits.h"
    47 #include "mtpimagedputilits.h"
    44 #include "mtpimagedpconst.h"
    48 #include "mtpimagedpconst.h"
    45 #include "mtpdebug.h"
    49 #include "mtpdebug.h"
    46 
    50 
   112     iObjectHandle = KMTPHandleNone;   
   116     iObjectHandle = KMTPHandleNone;   
   113     }
   117     }
   114 
   118 
   115 void CMTPImageDpObjectPropertyMgr::CMTPImagePropertiesCache::ResetL()
   119 void CMTPImageDpObjectPropertyMgr::CMTPImagePropertiesCache::ResetL()
   116     {
   120     {
       
   121     iObjectHandle = KMTPHandleNone;
   117     SetUint(EImagePixWidth, 0);
   122     SetUint(EImagePixWidth, 0);
   118     SetUint(EImagePixHeight, 0);
   123     SetUint(EImagePixHeight, 0);
   119     SetUint(EImageBitDepth, 0);
   124     SetUint(EImageBitDepth, 0);
   120     SetDesCL(EDateCreated, KNullDesC);
   125     SetDesCL(EDateCreated, KNullDesC);
   121     }
   126     }
   155 void CMTPImageDpObjectPropertyMgr::CMTPImagePropertiesCache::SetObjectHandle(TUint aObjectHandle)
   160 void CMTPImageDpObjectPropertyMgr::CMTPImagePropertiesCache::SetObjectHandle(TUint aObjectHandle)
   156     {
   161     {
   157     iObjectHandle = aObjectHandle;
   162     iObjectHandle = aObjectHandle;
   158     }
   163     }
   159 
   164 
   160 CMTPImageDpObjectPropertyMgr* CMTPImageDpObjectPropertyMgr::NewL(MMTPDataProviderFramework& aFramework)
   165 CMTPImageDpObjectPropertyMgr* CMTPImageDpObjectPropertyMgr::NewL(MMTPDataProviderFramework& aFramework, CMTPImageDataProvider& aDataProvider)
   161     {
   166     {
   162     CMTPImageDpObjectPropertyMgr* self = new (ELeave) CMTPImageDpObjectPropertyMgr(aFramework);
   167     CMTPImageDpObjectPropertyMgr* self = new (ELeave) CMTPImageDpObjectPropertyMgr(aFramework, aDataProvider);
   163     CleanupStack::PushL(self);
   168     CleanupStack::PushL(self);
   164     self->ConstructL(aFramework);
   169     self->ConstructL(aFramework);
   165     CleanupStack::Pop(self);
   170     CleanupStack::Pop(self);
   166     return self;
   171     return self;
   167     }
   172     }
   168 
   173 
   169 CMTPImageDpObjectPropertyMgr::CMTPImageDpObjectPropertyMgr(MMTPDataProviderFramework& aFramework) :
   174 CMTPImageDpObjectPropertyMgr::CMTPImageDpObjectPropertyMgr(MMTPDataProviderFramework& aFramework, CMTPImageDataProvider& aDataProvider) :
       
   175     iFramework(aFramework),
       
   176     iDataProvider(aDataProvider),
   170     iFs(aFramework.Fs()),
   177     iFs(aFramework.Fs()),
   171     iObjectMgr(aFramework.ObjectMgr())
   178     iObjectMgr(aFramework.ObjectMgr())
   172     {
   179     {
   173     __FLOG_OPEN(KMTPSubsystem, KComponent);
   180     __FLOG_OPEN(KMTPSubsystem, KComponent);
   174     }
   181     }
   194     __FLOG(_L8("CMTPImageDpObjectPropertyMgr::~CMTPImageDpObjectPropertyMgr - Entry"));
   201     __FLOG(_L8("CMTPImageDpObjectPropertyMgr::~CMTPImageDpObjectPropertyMgr - Entry"));
   195     delete iPropertiesCache;
   202     delete iPropertiesCache;
   196     delete iObject;
   203     delete iObject;
   197     delete iMetaDataSession;
   204     delete iMetaDataSession;
   198     delete iActiveSchedulerWait; 
   205     delete iActiveSchedulerWait; 
       
   206     delete iThumbnailCache.iThumbnailData;
   199     __FLOG(_L8("CMTPImageDpObjectPropertyMgr::~CMTPImageDpObjectPropertyMgr - Exit"));
   207     __FLOG(_L8("CMTPImageDpObjectPropertyMgr::~CMTPImageDpObjectPropertyMgr - Exit"));
   200     __FLOG_CLOSE;
   208     __FLOG_CLOSE;
   201     }
   209     }
   202 
   210 
   203 void CMTPImageDpObjectPropertyMgr::SetCurrentObjectL(CMTPObjectMetaData& aObjectInfo, TBool aRequireForModify, TBool aSaveToCache)
   211 void CMTPImageDpObjectPropertyMgr::SetCurrentObjectL(CMTPObjectMetaData& aObjectInfo, TBool aRequireForModify, TBool aSaveToCache)
   216         if (iPropertiesCache->ObjectHandle() == iObjectInfo->Uint(CMTPObjectMetaData::EHandle))
   224         if (iPropertiesCache->ObjectHandle() == iObjectInfo->Uint(CMTPObjectMetaData::EHandle))
   217             {
   225             {
   218             iCacheHit = ETrue;
   226             iCacheHit = ETrue;
   219             }
   227             }
   220         else
   228         else
   221             {
   229             {            
   222             iCacheHit = EFalse;
   230             iCacheHit = EFalse;
       
   231 
       
   232             /**
       
   233              * if cache miss, we should clear the cache content
       
   234              */
       
   235             ClearCacheL();
   223             
   236             
   224             CMdENamespaceDef& defaultNamespace = iMetaDataSession->GetDefaultNamespaceDefL();
   237 			//need parse image file by our self if fail to get properties from MdS
   225             CMdEObjectDef& imageObjDef = defaultNamespace.GetObjectDefL( MdeConstants::Image::KImageObject );
   238             iNeedParse = ETrue;
       
   239 
       
   240 			//clear previous Mde object
   226             delete iObject;
   241             delete iObject;
   227             iObject = NULL;
   242             iObject = NULL;            
   228             
       
   229             //if we can not open MdS object for getting properties, we will not get properites which stored in MdS
       
   230             TFileName uri;
       
   231             uri.CopyLC(iObjectInfo->DesC(CMTPObjectMetaData::ESuid));
       
   232             TRAP_IGNORE((iObject = iMetaDataSession->GetObjectL(uri, imageObjDef)));            
       
   233             }        
   243             }        
   234         }    
   244         }    
   235     else
   245     else
   236         {        
   246         {        
   237         /**
   247         /**
   355               
   365               
   356     case EMTPObjectPropCodeDateModified:
   366     case EMTPObjectPropCodeDateModified:
   357         {
   367         {
   358         TTime modifiedTime;
   368         TTime modifiedTime;
   359         ConvertMTPTimeStr2TTimeL(aValue, modifiedTime);
   369         ConvertMTPTimeStr2TTimeL(aValue, modifiedTime);
   360         iFs.SetModified(iObjectInfo->DesC(CMTPObjectMetaData::ESuid), modifiedTime);     
   370         iFs.SetModified(iObjectInfo->DesC(CMTPObjectMetaData::ESuid), modifiedTime);            
   361         }
   371         }
   362         break;
   372         break;
   363       
   373       
   364     case EMTPObjectPropCodeDateCreated://MdS property
   374     case EMTPObjectPropCodeDateCreated://MdS property
   365         iPropertiesCache->SetDesCL(CMTPImageDpObjectPropertyMgr::CMTPImagePropertiesCache::EDateCreated, aValue);
   375         iPropertiesCache->SetDesCL(CMTPImageDpObjectPropertyMgr::CMTPImagePropertiesCache::EDateCreated, aValue);
   411             {
   421             {
   412             aValue = EMTPProtectionNoProtection;
   422             aValue = EMTPProtectionNoProtection;
   413             }
   423             }
   414         break;        
   424         break;        
   415     default:
   425     default:
   416         GetPropertyFromMdsL(aProperty, &aValue);
   426         aValue = 0;//initialization
       
   427         //ingore the failure if we can't get properties form MdS
       
   428         TRAP_IGNORE(GetPropertyFromMdsL(aProperty, &aValue));
   417         break;
   429         break;
   418         }
   430         }
   419     __FLOG(_L8("<< CMTPImageDpObjectPropertyMgr::GetPropertyL"));
   431     __FLOG(_L8("<< CMTPImageDpObjectPropertyMgr::GetPropertyL"));
   420     }
   432     }
   421 
   433 
   432         
   444         
   433     case EMTPObjectPropCodeParentObject:
   445     case EMTPObjectPropCodeParentObject:
   434         aValue = iObjectInfo->Uint(CMTPObjectMetaData::EParentHandle);
   446         aValue = iObjectInfo->Uint(CMTPObjectMetaData::EParentHandle);
   435         break;        
   447         break;        
   436        
   448        
   437     case EMTPObjectPropCodeRepresentativeSampleSize:
   449     case EMTPObjectPropCodeRepresentativeSampleSize: 
   438         aValue = KThumbCompressedSize;
   450         aValue = MTPImageDpUtilits::GetThumbnailSize(*iObjectInfo);
   439        break;       
   451         if (aValue == 0)
       
   452             {
       
   453             __FLOG_VA((_L16("Query smaple size from MdS - URI:%S"), &iObjectInfo->DesC(CMTPObjectMetaData::ESuid)));
       
   454             ClearThumnailCache();                                
       
   455             /**
       
   456              * try to query thumbnail from TNM, and then store thumbnail to cache
       
   457              */
       
   458             TEntry fileEntry;
       
   459             TInt err = iFs.Entry(iObjectInfo->DesC(CMTPObjectMetaData::ESuid), fileEntry);
       
   460             if (err == KErrNone)
       
   461                 {
       
   462                 iDataProvider.ThumbnailManager().GetThumbMgr()->SetFlagsL(CThumbnailManager::EDefaultFlags);
       
   463                 if(fileEntry.FileSize() > KFileSizeMax)
       
   464                     {
       
   465                     iDataProvider.ThumbnailManager().GetThumbMgr()->SetFlagsL(CThumbnailManager::EDoNotCreate);
       
   466                     }
       
   467                 
       
   468                 /**
       
   469                  * trap the leave to avoid return general error when PC get object property list
       
   470                  */
       
   471                 TRAP(err, iDataProvider.ThumbnailManager().GetThumbnailL(iObjectInfo->DesC(CMTPObjectMetaData::ESuid), iThumbnailCache.iThumbnailData, err));
       
   472                 if (err == KErrNone)
       
   473                     {
       
   474                     iThumbnailCache.iObjectHandle = iObjectInfo->Uint(CMTPObjectMetaData::EHandle);                        
       
   475                     if (iThumbnailCache.iThumbnailData != NULL)
       
   476                         {
       
   477                         aValue = static_cast<TUint32>(iThumbnailCache.iThumbnailData->Size());
       
   478                         }
       
   479                                                 
       
   480                     if (aValue > 0)
       
   481                         {
       
   482                         //update metadata column
       
   483                         MTPImageDpUtilits::UpdateObjectThumbnailSizeL(iFramework, *iObjectInfo, aValue);
       
   484                         }
       
   485                     else
       
   486                         {
       
   487                         //trigger initiator to re-query thumbnail again if the thumbnail size of response is zero
       
   488                         aValue = KThumbCompressedSize;
       
   489                         }
       
   490 
       
   491                     __FLOG_VA((_L16("Cache miss:GetThumbnailSize - URI:%S, Size:%u"), &iObjectInfo->DesC(CMTPObjectMetaData::ESuid), aValue));
       
   492                     }
       
   493                 }
       
   494             }	    
       
   495         break;       
   440        
   496        
   441     case EMTPObjectPropCodeRepresentativeSampleHeight:
   497     case EMTPObjectPropCodeRepresentativeSampleHeight:
   442         aValue = KThumbHeigth;
   498         aValue = KThumbHeigth;
   443        break;
   499         break;
   444        
   500        
   445     case EMTPObjectPropCodeRepresentativeSampleWidth:
   501     case EMTPObjectPropCodeRepresentativeSampleWidth:
   446         aValue = KThumbWidht;
   502         aValue = KThumbWidht;
   447        break;
   503         break;
   448               
   504               
   449     default:
   505     default:
   450         GetPropertyFromMdsL(aProperty, &aValue);
   506         aValue = 0;//initialization
       
   507         //ingore the failure if we can't get properties form MdS
       
   508         TRAP_IGNORE(GetPropertyFromMdsL(aProperty, &aValue));
   451         break;  
   509         break;  
   452         }
   510         }
   453     __FLOG(_L8("<< CMTPImageDpObjectPropertyMgr::GetPropertyL"));
   511     __FLOG(_L8("<< CMTPImageDpObjectPropertyMgr::GetPropertyL"));
   454     }
   512     }
   455     
   513     
   520         aValue.SetL(dateString);
   578         aValue.SetL(dateString);
   521         }
   579         }
   522         break;                 
   580         break;                 
   523         
   581         
   524     default:
   582     default:
   525         GetPropertyFromMdsL(aProperty, &aValue);
   583         //ingore the failure if we can't get properties form MdS
       
   584         TRAP_IGNORE(GetPropertyFromMdsL(aProperty, &aValue));
   526         break;
   585         break;
   527         }
   586         }
   528     __FLOG(_L8("<< CMTPImageDpObjectPropertyMgr::GetPropertyL"));
   587     __FLOG(_L8("<< CMTPImageDpObjectPropertyMgr::GetPropertyL"));
   529     }
   588     }
   530 
   589 
   531 void CMTPImageDpObjectPropertyMgr::GetPropertyFromMdsL(TMTPObjectPropertyCode aProperty, TAny* aValue)
   590 void CMTPImageDpObjectPropertyMgr::GetPropertyL(TMTPObjectPropertyCode aProperty, CMTPTypeArray& aValue)
   532     {
   591     {
   533     __FLOG(_L8(">> CMTPImageDpObjectPropertyMgr::GetPropertyFromMdsL"));
   592     __FLOG(_L8(">> CMTPImageDpObjectPropertyMgr::GetPropertyL -- SmapleData"));       
   534     
   593     
   535     TInt err = KErrNone;
   594     if (aProperty == EMTPObjectPropCodeRepresentativeSampleData)
   536     CMdENamespaceDef& defaultNamespace = iMetaDataSession->GetDefaultNamespaceDefL();
   595         {
   537     CMdEObjectDef& imageObjDef = defaultNamespace.GetObjectDefL( MdeConstants::Image::KImageObject );
   596         HBufC8* tnBuf = Thumbnail(iObjectInfo->Uint(CMTPObjectMetaData::EHandle));    
   538     CMdEProperty* mdeProperty = NULL;
   597         if (tnBuf != NULL)
   539     switch (aProperty)
   598             {    
   540         {        
   599             aValue.SetByDesL(*tnBuf);
   541     case EMTPObjectPropCodeDateCreated:
       
   542         {
       
   543         if (iCacheHit)
       
   544             {
       
   545             (*(static_cast<CMTPTypeString*>(aValue))).SetL(iPropertiesCache->DesC(CMTPImageDpObjectPropertyMgr::CMTPImagePropertiesCache::EDateCreated));
       
   546             }
   600             }
   547         else if (iObject)
   601         else
   548             {        
   602             {    
   549             CMdEPropertyDef& creationDatePropDef = imageObjDef.GetPropertyDefL(MdeConstants::Object::KCreationDateProperty);
   603             ClearThumnailCache();                                
   550             TInt err = iObject->Property( creationDatePropDef, mdeProperty );  
   604             /**
   551             if (err >= KErrNone) 
   605              * try to query thumbnail from TNM, and then store thumbnail to cache
       
   606              */
       
   607             TEntry fileEntry;
       
   608             TInt err = iFs.Entry(iObjectInfo->DesC(CMTPObjectMetaData::ESuid), fileEntry);
       
   609             if (err == KErrNone)
   552                 {
   610                 {
   553                 TBuf<KMaxTimeFormatSpec*2> timeValue;
   611                 iDataProvider.ThumbnailManager().GetThumbMgr()->SetFlagsL(CThumbnailManager::EDefaultFlags);
   554                 // locale independent YYYYMMSSThhmmss, as required by the MTP spec
   612                 if(fileEntry.FileSize() > KFileSizeMax)
   555                 _LIT(KTimeFormat, "%F%Y%M%DT%H%T%S");
   613                     {
   556                 mdeProperty->TimeValueL().FormatL(timeValue, KTimeFormat);
   614                     iDataProvider.ThumbnailManager().GetThumbMgr()->SetFlagsL(CThumbnailManager::EDoNotCreate);
   557                 (*(static_cast<CMTPTypeString*>(aValue))).SetL(timeValue);
   615                     }
       
   616                 
       
   617                 /**
       
   618                  * trap the leave to avoid return general error when PC get object property list
       
   619                  */
       
   620                 TRAP(err, iDataProvider.ThumbnailManager().GetThumbnailL(iObjectInfo->DesC(CMTPObjectMetaData::ESuid), iThumbnailCache.iThumbnailData, err));
       
   621                 if (err == KErrNone)
       
   622                     {
       
   623                     TInt size = MTPImageDpUtilits::GetThumbnailSize(*iObjectInfo);
       
   624                     iThumbnailCache.iObjectHandle = iObjectInfo->Uint(CMTPObjectMetaData::EHandle);                        
       
   625                     if (iThumbnailCache.iThumbnailData != NULL)
       
   626                         {
       
   627                         aValue.SetByDesL(*iThumbnailCache.iThumbnailData);
       
   628                         if (size == 0)
       
   629                             {
       
   630                             //update metadata column
       
   631                             MTPImageDpUtilits::UpdateObjectThumbnailSizeL(iFramework, *iObjectInfo, iThumbnailCache.iThumbnailData->Size());
       
   632                             __FLOG_VA((_L16("Cache miss:GetThumbnailSize - URI:%S, Size:%u"), &iObjectInfo->DesC(CMTPObjectMetaData::ESuid), size));
       
   633                             }
       
   634                         }                                
       
   635                     }
   558                 }
   636                 }
   559             }
   637             }
   560         }
   638         }
   561        break;  
   639     else
   562        
   640         {
   563     case EMTPObjectPropCodeWidth:
   641         User::Leave(EMTPRespCodeObjectPropNotSupported);
   564         {
   642         }
   565         if (iCacheHit)
   643     }
       
   644 
       
   645 void CMTPImageDpObjectPropertyMgr::GetPropertyFromMdsL(TMTPObjectPropertyCode aProperty, TAny* aValue)
       
   646     {
       
   647     __FLOG(_L8(">> CMTPImageDpObjectPropertyMgr::GetPropertyFromMdsL"));
       
   648     
       
   649     TInt err = KErrNone;
       
   650       
       
   651     if (iCacheHit)
       
   652         {
       
   653         /**
       
   654          * The object hit the cache, so we query properties from cache
       
   655          */
       
   656         switch (aProperty)
   566             {
   657             {
   567             *static_cast<TUint32*>(aValue) = iPropertiesCache->Uint(CMTPImageDpObjectPropertyMgr::CMTPImagePropertiesCache::EImagePixWidth);
   658         case EMTPObjectPropCodeDateCreated:
       
   659             (*(static_cast<CMTPTypeString*>(aValue))).SetL(iPropertiesCache->DesC(CMTPImageDpObjectPropertyMgr::CMTPImagePropertiesCache::EDateCreated));            
       
   660             break;
       
   661           
       
   662         case EMTPObjectPropCodeWidth:
       
   663             *static_cast<TUint32*>(aValue) = iPropertiesCache->Uint(CMTPImageDpObjectPropertyMgr::CMTPImagePropertiesCache::EImagePixWidth);            
       
   664             break;
       
   665             
       
   666         case EMTPObjectPropCodeHeight:
       
   667             *static_cast<TUint32*>(aValue) = iPropertiesCache->Uint(CMTPImageDpObjectPropertyMgr::CMTPImagePropertiesCache::EImagePixHeight);           
       
   668             break;
       
   669             
       
   670         case EMTPObjectPropCodeImageBitDepth:
       
   671             *static_cast<TUint32*>(aValue) = iPropertiesCache->Uint(CMTPImageDpObjectPropertyMgr::CMTPImagePropertiesCache::EImageBitDepth);            
       
   672             break;
       
   673             
       
   674         default:
       
   675             //nothing to do
       
   676             break;
   568             }
   677             }
   569         else if (iObject)
   678         }
       
   679     else
       
   680         {
       
   681         /**
       
   682          * The object miss cache, so we should open Mde object to query properties
       
   683          */
       
   684         OpenMdeObjectL();
       
   685         
       
   686         CMdENamespaceDef& defaultNamespace = iMetaDataSession->GetDefaultNamespaceDefL();
       
   687         CMdEObjectDef& imageObjDef = defaultNamespace.GetObjectDefL( MdeConstants::Image::KImageObject );
       
   688         CMdEProperty* mdeProperty = NULL;
       
   689         
       
   690         switch (aProperty)
       
   691             {        
       
   692         case EMTPObjectPropCodeDateCreated:
   570             {
   693             {
   571             CMdEPropertyDef& imageWidthPropDef = imageObjDef.GetPropertyDefL(MdeConstants::MediaObject::KWidthProperty);
   694             if (iObject)
   572             err = iObject->Property( imageWidthPropDef, mdeProperty );  
   695                 {        
   573             if (err >= KErrNone) 
   696                 CMdEPropertyDef& creationDatePropDef = imageObjDef.GetPropertyDefL(MdeConstants::Object::KCreationDateProperty);
       
   697                 TInt err = iObject->Property( creationDatePropDef, mdeProperty );  
       
   698                 if (err >= KErrNone) 
       
   699                     {
       
   700                     TBuf<KMaxTimeFormatSpec*2> timeValue;
       
   701                     // locale independent YYYYMMSSThhmmss, as required by the MTP spec
       
   702                     _LIT(KTimeFormat, "%F%Y%M%DT%H%T%S");
       
   703                     mdeProperty->TimeValueL().FormatL(timeValue, KTimeFormat);
       
   704                     (*(static_cast<CMTPTypeString*>(aValue))).SetL(timeValue);
       
   705                     
       
   706                     __FLOG_VA((_L16("GetPropertyFromMdsL - from MdS: URI:%S, DateCreated:%S"), &iObjectInfo->DesC(CMTPObjectMetaData::ESuid), &timeValue));
       
   707                     }
       
   708                 }
       
   709             }
       
   710            break;  
       
   711            
       
   712         case EMTPObjectPropCodeWidth:
       
   713             {
       
   714             if (iObject)
   574                 {
   715                 {
   575                 TUint16 width = mdeProperty->Uint16ValueL();
   716                 CMdEPropertyDef& imageWidthPropDef = imageObjDef.GetPropertyDefL(MdeConstants::MediaObject::KWidthProperty);
   576                 if (width > 0)
   717                 err = iObject->Property( imageWidthPropDef, mdeProperty );  
       
   718                 if (err >= KErrNone) 
   577                     {
   719                     {
   578                     *static_cast<TUint32*>(aValue) = width;
   720                     *static_cast<TUint32*>(aValue) = mdeProperty->Uint16ValueL();
   579                     }
   721                     }
   580                 else
   722                 else
   581                     {
   723                     {
   582                     *static_cast<TUint32*>(aValue) = ParseImageFileL(iObject->Uri(), EMTPObjectPropCodeWidth);
   724                     *static_cast<TUint32*>(aValue) = 0;
   583                     }
   725                     }
   584                 }
   726                 }
   585             else
   727             else
   586                 {
   728                 {
   587                 *static_cast<TUint32*>(aValue) = ParseImageFileL(iObject->Uri(), EMTPObjectPropCodeWidth);
   729                 *static_cast<TUint32*>(aValue) = 0;
   588                 }
   730                 }
   589             }
   731             }
   590         else
   732            break; 
       
   733            
       
   734         case EMTPObjectPropCodeHeight:
   591             {
   735             {
   592             *static_cast<TUint32*>(aValue) = 0;
   736             if (iObject)
   593             }
       
   594         }
       
   595        break; 
       
   596        
       
   597     case EMTPObjectPropCodeHeight:
       
   598         {
       
   599         if (iCacheHit)
       
   600             {
       
   601             *static_cast<TUint32*>(aValue) = iPropertiesCache->Uint(CMTPImageDpObjectPropertyMgr::CMTPImagePropertiesCache::EImagePixHeight);
       
   602             }
       
   603         else if (iObject)
       
   604             {
       
   605             CMdEPropertyDef& imageHeightPropDef = imageObjDef.GetPropertyDefL(MdeConstants::MediaObject::KHeightProperty);
       
   606             err = iObject->Property( imageHeightPropDef, mdeProperty );  
       
   607             if (err >= KErrNone) 
       
   608                 {
   737                 {
   609                 TUint16 height = mdeProperty->Uint16ValueL();
   738                 CMdEPropertyDef& imageHeightPropDef = imageObjDef.GetPropertyDefL(MdeConstants::MediaObject::KHeightProperty);
   610                 if (height > 0)
   739                 err = iObject->Property( imageHeightPropDef, mdeProperty );  
       
   740                 if (err >= KErrNone) 
   611                     {
   741                     {
   612                     *static_cast<TUint32*>(aValue) = height;
   742                     *static_cast<TUint32*>(aValue) = mdeProperty->Uint16ValueL();
   613                     }
   743                     }
   614                 else
   744                 else
   615                     {
   745                     {
   616                     *static_cast<TUint32*>(aValue) = ParseImageFileL(iObject->Uri(), EMTPObjectPropCodeHeight);
   746                     *static_cast<TUint32*>(aValue) = 0;
   617                     }
   747                     }
   618                 }
   748                 }
   619             else
   749             else
   620                 {
   750                 {
   621                 *static_cast<TUint32*>(aValue) = ParseImageFileL(iObject->Uri(), EMTPObjectPropCodeHeight);
   751                 *static_cast<TUint32*>(aValue) = 0;
   622                 }
   752                 }
   623             }
   753             }
   624         else
   754            break; 
       
   755            
       
   756         case EMTPObjectPropCodeImageBitDepth:
   625             {
   757             {
   626             *static_cast<TUint32*>(aValue) = 0;
   758             if (iObject)
   627             }
       
   628         }
       
   629        break; 
       
   630        
       
   631     case EMTPObjectPropCodeImageBitDepth:
       
   632         {
       
   633         if (iCacheHit)
       
   634             {
       
   635             *static_cast<TUint32*>(aValue) = iPropertiesCache->Uint(CMTPImageDpObjectPropertyMgr::CMTPImagePropertiesCache::EImageBitDepth);
       
   636             }
       
   637         else if (iObject)
       
   638             {
       
   639             CMdEPropertyDef& imageBitDepth = imageObjDef.GetPropertyDefL(MdeConstants::Image::KBitsPerSampleProperty);
       
   640             err = iObject->Property( imageBitDepth, mdeProperty );  
       
   641             if (err >= KErrNone) 
       
   642                 {
   759                 {
   643                 TUint16 bitDepth = mdeProperty->Uint16ValueL();
   760                 CMdEPropertyDef& imageBitDepth = imageObjDef.GetPropertyDefL(MdeConstants::Image::KBitsPerSampleProperty);
   644                 if (bitDepth > 0)
   761                 err = iObject->Property( imageBitDepth, mdeProperty );  
       
   762                 if (err >= KErrNone) 
   645                     {
   763                     {
   646                     *static_cast<TUint32*>(aValue) = bitDepth;
   764                     *static_cast<TUint32*>(aValue) = mdeProperty->Uint16ValueL();               
   647                     }
   765                     }
   648                 else
   766                 else
   649                     {
   767                     {
   650                     *static_cast<TUint32*>(aValue) = ParseImageFileL(iObject->Uri(), EMTPObjectPropCodeImageBitDepth);
   768                     *static_cast<TUint32*>(aValue) = 0;
   651                     }                
   769                     }  
   652                 }
   770                 }
   653             else
   771             else
   654                 {
   772                 {
   655                 *static_cast<TUint32*>(aValue) = ParseImageFileL(iObject->Uri(), EMTPObjectPropCodeImageBitDepth);
   773                 *static_cast<TUint32*>(aValue) = 0;
   656                 }  
   774                 }        
       
   775             }     
       
   776            break; 
       
   777            
       
   778         default:
       
   779             //nothing to do
       
   780             break;
   657             }
   781             }
   658         else
       
   659             {
       
   660             *static_cast<TUint32*>(aValue) = 0;
       
   661             }        
       
   662         }     
       
   663        break; 
       
   664        
       
   665     default:
       
   666         //nothing to do
       
   667         break;
       
   668         }
   782         }
   669     __FLOG(_L8("<< CMTPImageDpObjectPropertyMgr::GetPropertyFromMdsL"));
   783     __FLOG(_L8("<< CMTPImageDpObjectPropertyMgr::GetPropertyFromMdsL"));
   670     }
   784     }
   671 
   785 
   672 TBool CMTPImageDpObjectPropertyMgr::GetYear(const TDesC& aDateString, TInt& aYear) const
   786 TBool CMTPImageDpObjectPropertyMgr::GetYear(const TDesC& aDateString, TInt& aYear) const
   779            ||!GetDay(aTimeString,day)
   893            ||!GetDay(aTimeString,day)
   780            ||!GetHour(aTimeString,hour)
   894            ||!GetHour(aTimeString,hour)
   781            ||!GetMinute(aTimeString,minute)
   895            ||!GetMinute(aTimeString,minute)
   782            ||!GetSecond(aTimeString,second)
   896            ||!GetSecond(aTimeString,second)
   783            ||!GetTenthSecond(aTimeString,tenthSecond))
   897            ||!GetTenthSecond(aTimeString,tenthSecond))
   784         {
   898         {        
   785         User::Leave(KErrArgument);
   899         User::Leave(KErrArgument);
   786         }
   900         }
   787     else
   901     else
   788         {     
   902         {     
   789         TDateTime dateTime(year, month, day, hour, minute, second, tenthSecond);
   903         TDateTime dateTime(year, month, day, hour, minute, second, tenthSecond);
   801         {
   915         {
   802         aObject.RemoveProperty(index);
   916         aObject.RemoveProperty(index);
   803         }
   917         }
   804     }
   918     }
   805 
   919 
   806 TUint32 CMTPImageDpObjectPropertyMgr::ParseImageFileL(const TDesC& aUri, TMTPObjectPropertyCode aPropCode)
   920 /**
   807     {
   921  * Store thumbnail into cache
   808     TUint32 result = 0;
   922  */
   809     TInt err = KErrNone;
   923 void CMTPImageDpObjectPropertyMgr::StoreThunmnail(TUint aHandle, HBufC8* aData)
   810     const TInt K64Kb = 65536;
   924     {
   811     
   925     ClearThumnailCache();
   812     HBufC8* buffer = HBufC8::NewLC(K64Kb);
   926     
   813     TPtr8 myImagePtr = buffer->Des();
   927     iThumbnailCache.iObjectHandle = aHandle;      
   814     err = iFs.ReadFileSection(aUri, 0, myImagePtr, K64Kb);
   928     iThumbnailCache.iThumbnailData = aData;
   815     if (err != KErrNone)
   929     }
   816         {
   930 
   817         CleanupStack::PopAndDestroy(buffer);
   931 /**
   818         return result;
   932  * Get thumbnail from cache
   819         }
   933  */
   820     
   934 HBufC8* CMTPImageDpObjectPropertyMgr::Thumbnail(TUint aHandle)
   821     CBufferedImageDecoder *decoder = CBufferedImageDecoder::NewL(iFs);
   935     {
   822     CleanupStack::PushL(decoder);
   936     if (iThumbnailCache.iObjectHandle == aHandle)
   823         
   937         {
   824     decoder->OpenL(myImagePtr, CImageDecoder::TOptions( CImageDecoder::EPreferFastDecode | CImageDecoder::EOptionIgnoreExifMetaData));
   938         return iThumbnailCache.iThumbnailData;
   825     if (decoder->ValidDecoder())
   939         }
   826         {
   940     else
   827         const TFrameInfo& info = decoder->FrameInfo();
   941         {
   828         
   942         return NULL;
   829         switch (aPropCode)
   943         }
   830             {
       
   831         case EMTPObjectPropCodeWidth:
       
   832             result = info.iOverallSizeInPixels.iWidth;
       
   833             break;
       
   834             
       
   835         case EMTPObjectPropCodeHeight:
       
   836             result = info.iOverallSizeInPixels.iHeight;
       
   837             break;
       
   838             
       
   839         case EMTPObjectPropCodeImageBitDepth:
       
   840             result = info.iBitsPerPixel;
       
   841             break;
       
   842             
       
   843         default:
       
   844             // nothing to do
       
   845             break;
       
   846             }
       
   847         
       
   848         /**
       
   849          * Open MdE object for update image object properties after parsing
       
   850          */
       
   851         CMdENamespaceDef& defaultNamespace = iMetaDataSession->GetDefaultNamespaceDefL();
       
   852         CMdEObjectDef& imageObjDef = defaultNamespace.GetObjectDefL(MdeConstants::Image::KImageObject);
       
   853         CMdEPropertyDef& imageWidthPropDef = imageObjDef.GetPropertyDefL(MdeConstants::MediaObject::KWidthProperty);
       
   854         CMdEPropertyDef& imageHeightPropDef = imageObjDef.GetPropertyDefL(MdeConstants::MediaObject::KHeightProperty);
       
   855         CMdEPropertyDef& imageBitDepth = imageObjDef.GetPropertyDefL(MdeConstants::Image::KBitsPerSampleProperty);
       
   856         
       
   857         //update current object properties
       
   858         TUint16 width = info.iOverallSizeInPixels.iWidth;
       
   859         RemoveProperty(*iObject, imageWidthPropDef);
       
   860         iObject->AddUint16PropertyL(imageWidthPropDef, width);
       
   861         
       
   862         TUint16 height = info.iOverallSizeInPixels.iHeight;
       
   863         RemoveProperty(*iObject, imageHeightPropDef);
       
   864         iObject->AddUint16PropertyL(imageHeightPropDef, height);
       
   865         
       
   866         TUint16 bitsPerPixel = info.iBitsPerPixel;
       
   867         RemoveProperty(*iObject, imageBitDepth);
       
   868         iObject->AddUint16PropertyL(imageBitDepth, bitsPerPixel);
       
   869         
       
   870         CMdEObject* updateObject = NULL;
       
   871         TRAP(err, updateObject = iMetaDataSession->OpenObjectL(iObject->Id(), imageObjDef));
       
   872         if (err == KErrNone && updateObject != NULL)
       
   873             {
       
   874             CleanupStack::PushL(updateObject);
       
   875             
       
   876             RemoveProperty(*updateObject, imageWidthPropDef);                   
       
   877             updateObject->AddUint16PropertyL(imageWidthPropDef, width);    
       
   878             
       
   879             RemoveProperty(*updateObject, imageHeightPropDef);        
       
   880             updateObject->AddUint16PropertyL(imageHeightPropDef, height);
       
   881             
       
   882             RemoveProperty(*updateObject, imageBitDepth);        
       
   883             updateObject->AddUint16PropertyL(imageBitDepth, bitsPerPixel);    
       
   884                     
       
   885             iMetaDataSession->CommitObjectL(*updateObject);
       
   886             CleanupStack::PopAndDestroy(updateObject);
       
   887             }
       
   888         }
       
   889     
       
   890     CleanupStack::PopAndDestroy(2);// decoder, buffer
       
   891     
       
   892     return result;
       
   893     }
   944     }
   894 
   945 
   895 /**
   946 /**
   896  * Return the mdesession instance
   947  * Return the mdesession instance
   897  */
   948  */
   931 
   982 
   932 void CMTPImageDpObjectPropertyMgr::ClearCacheL()
   983 void CMTPImageDpObjectPropertyMgr::ClearCacheL()
   933     {
   984     {
   934     iPropertiesCache->ResetL();
   985     iPropertiesCache->ResetL();
   935     }
   986     }
       
   987 
       
   988 void CMTPImageDpObjectPropertyMgr::OpenMdeObjectL()
       
   989     {
       
   990     if (iObject == NULL)
       
   991         {
       
   992         __FLOG_VA((_L16("OpenMdeObjectL - URI = %S"), &iObjectInfo->DesC(CMTPObjectMetaData::ESuid)));
       
   993 		
       
   994         CMdENamespaceDef& defaultNamespace = iMetaDataSession->GetDefaultNamespaceDefL();
       
   995         CMdEObjectDef& imageObjDef = defaultNamespace.GetObjectDefL( MdeConstants::Image::KImageObject );
       
   996         
       
   997         //if we can not open MdS object for getting properties, we will not get properites which stored in MdS
       
   998         TFileName uri;
       
   999         uri.CopyLC(iObjectInfo->DesC(CMTPObjectMetaData::ESuid));
       
  1000         TRAP_IGNORE((iObject = iMetaDataSession->GetObjectL(uri, imageObjDef)));      
       
  1001         }
       
  1002     }
       
  1003 
       
  1004 void CMTPImageDpObjectPropertyMgr::ClearThumnailCache()
       
  1005     {
       
  1006     delete iThumbnailCache.iThumbnailData;
       
  1007     iThumbnailCache.iThumbnailData = NULL;
       
  1008     
       
  1009     iThumbnailCache.iObjectHandle = KMTPHandleNone;
       
  1010     }