mtpdataproviders/mtpimagedp/src/cmtpimagedp.cpp
changeset 17 aabe5387f5ce
parent 0 d0791faffa3f
child 12 8b094906a049
equal deleted inserted replaced
0:d0791faffa3f 17:aabe5387f5ce
    27 #include <mtp/mmtpdataproviderframework.h>
    27 #include <mtp/mmtpdataproviderframework.h>
    28 #include <mtp/mtpdataproviderapitypes.h>
    28 #include <mtp/mtpdataproviderapitypes.h>
    29 #include <mtp/mtpprotocolconstants.h>
    29 #include <mtp/mtpprotocolconstants.h>
    30 #include <mtp/mmtpobjectmgr.h>
    30 #include <mtp/mmtpobjectmgr.h>
    31 #include <mtp/mmtpstoragemgr.h>
    31 #include <mtp/mmtpstoragemgr.h>
       
    32 #include <mtp/cmtpobjectmetadata.h>
    32 #include <mtp/tmtptypeevent.h>
    33 #include <mtp/tmtptypeevent.h>
    33 
    34 
    34 #include "cmtpimagedp.h"
    35 #include "cmtpimagedp.h"
    35 #include "mtpimagedpconst.h"
    36 #include "mtpimagedpconst.h"
    36 #include "mtpimagedppanic.h"
    37 #include "mtpimagedppanic.h"
    38 #include "mtpimagedprequestprocessor.h"
    39 #include "mtpimagedprequestprocessor.h"
    39 #include "cmtpimagedpthumbnailcreator.h"
    40 #include "cmtpimagedpthumbnailcreator.h"
    40 #include "mtpimagedputilits.h"
    41 #include "mtpimagedputilits.h"
    41 #include "cmtpimagedpmdeobserver.h"
    42 #include "cmtpimagedpmdeobserver.h"
    42 #include "cmtpimagedprenameobject.h"
    43 #include "cmtpimagedprenameobject.h"
       
    44 #include "cmtpimagedpnewpicturesnotifier.h"
    43 
    45 
    44 __FLOG_STMT(_LIT8(KComponent,"CMTPImageDataProvider");)
    46 __FLOG_STMT(_LIT8(KComponent,"CMTPImageDataProvider");)
    45 
    47 
    46 static const TInt KArrayGranularity = 3;
    48 static const TInt KArrayGranularity = 3;
    47 static const TInt KDeleteObjectGranularity = 2;
    49 static const TInt KDeleteObjectGranularity = 2;
    78 */
    80 */
    79 CMTPImageDataProvider::CMTPImageDataProvider(TAny* aParams) :
    81 CMTPImageDataProvider::CMTPImageDataProvider(TAny* aParams) :
    80     CMTPDataProviderPlugin(aParams),
    82     CMTPDataProviderPlugin(aParams),
    81     iActiveProcessors(KArrayGranularity),
    83     iActiveProcessors(KArrayGranularity),
    82     iFormatMappings(&TBuf16Hash, &TBuf16Ident),
    84     iFormatMappings(&TBuf16Hash, &TBuf16Ident),
       
    85     iMimeMappings(&TBuf16Hash, &TBuf16Ident),
    83     iActiveProcessor(-1),
    86     iActiveProcessor(-1),
    84     iEnumerated(EFalse),
    87     iEnumerated(EFalse),
    85 	iDeleteObjectsArray(KDeleteObjectGranularity)
    88 	iDeleteObjectsArray(KDeleteObjectGranularity)
    86     {
    89     {
    87     }
    90     }
    92 void CMTPImageDataProvider::ConstructL()
    95 void CMTPImageDataProvider::ConstructL()
    93     {
    96     {
    94     __FLOG_OPEN(KMTPSubsystem, KComponent);
    97     __FLOG_OPEN(KMTPSubsystem, KComponent);
    95     __FLOG(_L8(">> CMTPImageDataProvider::ConstructL"));
    98     __FLOG(_L8(">> CMTPImageDataProvider::ConstructL"));
    96     
    99     
    97     iPropertyMgr = CMTPImageDpObjectPropertyMgr::NewL(Framework());
   100     iPropertyMgr = CMTPImageDpObjectPropertyMgr::NewL(Framework(), *this);
    98     iThumbnailManager = CMTPImageDpThumbnailCreator::NewL();
   101     iThumbnailManager = CMTPImageDpThumbnailCreator::NewL(*this);
    99     iMdeObserver = CMTPImageDpMdeObserver::NewL(Framework(), *this);
   102     iMdeObserver = CMTPImageDpMdeObserver::NewL(Framework(), *this);
   100     iMdeObserver->SubscribeForChangeNotificationL();
   103     iMdeObserver->SubscribeForChangeNotificationL();
       
   104     iNewPicNotifier = CMTPImageDpNewPicturesNotifier::NewL();
   101     
   105     
   102     //Setup central repository connection
   106     //Setup central repository connection
   103     const TUint32 KUidMTPImageRepositoryValue(0x2001FCA2);
   107     const TUint32 KUidMTPImageRepositoryValue(0x2001FCA2);
   104     const TUid KUidMTPImageRepository = {KUidMTPImageRepositoryValue};
   108     const TUid KUidMTPImageRepository = {KUidMTPImageRepositoryValue};
   105     iRepository = CRepository::NewL(KUidMTPImageRepository);    
   109     iRepository = CRepository::NewL(KUidMTPImageRepository);    
   108     TInt count(sizeof(KMTPValidCodeExtensionMappings) / sizeof(KMTPValidCodeExtensionMappings[0]));
   112     TInt count(sizeof(KMTPValidCodeExtensionMappings) / sizeof(KMTPValidCodeExtensionMappings[0]));
   109     for(TInt i(0); i<count; i++)
   113     for(TInt i(0); i<count; i++)
   110         {
   114         {
   111         iFormatMappings.Insert(KMTPValidCodeExtensionMappings[i].iExtension, KMTPValidCodeExtensionMappings[i].iFormatCode);
   115         iFormatMappings.Insert(KMTPValidCodeExtensionMappings[i].iExtension, KMTPValidCodeExtensionMappings[i].iFormatCode);
   112         }    
   116         }    
       
   117     
       
   118     //Initialize hash map of extension to mime type
       
   119     count = sizeof(KMTPExtensionMimeTypeMappings) / sizeof(KMTPExtensionMimeTypeMappings[0]);
       
   120     for(TInt i(0); i<count; i++)
       
   121         {
       
   122         iMimeMappings.Insert(KMTPExtensionMimeTypeMappings[i].iExtension, KMTPExtensionMimeTypeMappings[i].iMimeType);
       
   123         }     
   113     
   124     
   114     //Define RProperty of new pictures for status data provider
   125     //Define RProperty of new pictures for status data provider
   115     _LIT_SECURITY_POLICY_PASS(KAllowReadAll);
   126     _LIT_SECURITY_POLICY_PASS(KAllowReadAll);
   116     TInt error = RProperty::Define(TUid::Uid(KMTPServerUID), KMTPNewPicKey, RProperty::EInt, KAllowReadAll, KAllowReadAll);
   127     TInt error = RProperty::Define(TUid::Uid(KMTPServerUID), KMTPNewPicKey, RProperty::EInt, KAllowReadAll, KAllowReadAll);
   117     if (error != KErrNone && error != KErrAlreadyExists)
   128     if (error != KErrNone && error != KErrAlreadyExists)
   146         }        
   157         }        
   147     delete iThumbnailManager;
   158     delete iThumbnailManager;
   148     delete iPropertyMgr;       
   159     delete iPropertyMgr;       
   149     delete iRepository;   
   160     delete iRepository;   
   150     delete iRenameObject;
   161     delete iRenameObject;
       
   162     delete iNewPicNotifier;
   151     
   163     
   152     iFormatMappings.Close();
   164     iFormatMappings.Close();
       
   165     iMimeMappings.Close();
   153     
   166     
   154     //Try to delete objects in array
   167     //Try to delete objects in array
   155     HandleDeleteObjectsArray();
   168     HandleDeleteObjectsArray();
   156     iDeleteObjectsArray.ResetAndDestroy();
   169     iDeleteObjectsArray.ResetAndDestroy();
   157     
   170     
   261     __FLOG(_L8(">> StartObjectEnumerationL"));
   274     __FLOG(_L8(">> StartObjectEnumerationL"));
   262     
   275     
   263     if (aStorageId == KMTPStorageAll)
   276     if (aStorageId == KMTPStorageAll)
   264         {
   277         {
   265         /*
   278         /*
   266          * Query previous image object count for calculation of new pictures when MTP startup
   279          * framework notify data provider to enumerate
   267          * 
   280          * 
   268          */
   281          */
   269         iPrePictures = QueryImageObjectCountL();
       
   270         iEnumerated = ETrue;
   282         iEnumerated = ETrue;
   271         __FLOG_1(_L16("CMTPImageDpEnumerator::CompleteEnumeration - Previous Pics: %d"), iPrePictures);
       
   272         }
   283         }
   273 
   284 
   274     NotifyEnumerationCompleteL(aStorageId, KErrNone);
   285     NotifyEnumerationCompleteL(aStorageId, KErrNone);
   275     
   286     
   276     __FLOG(_L8("<< StartObjectEnumerationL"));
   287     __FLOG(_L8("<< StartObjectEnumerationL"));
   380         _LIT(KFormatExtensionJpg, "0x3801:jpg::3");//3 means file dp will enumerate all image files instead of image dp.
   391         _LIT(KFormatExtensionJpg, "0x3801:jpg::3");//3 means file dp will enumerate all image files instead of image dp.
   381         aStrings.AppendL(KFormatExtensionJpg);
   392         aStrings.AppendL(KFormatExtensionJpg);
   382         _LIT(KFormatExtensionJpe, "0x3801:jpe::3");
   393         _LIT(KFormatExtensionJpe, "0x3801:jpe::3");
   383         aStrings.AppendL(KFormatExtensionJpe);
   394         aStrings.AppendL(KFormatExtensionJpe);
   384         _LIT(KFormatExtensionJpeg, "0x3801:jpeg::3");
   395         _LIT(KFormatExtensionJpeg, "0x3801:jpeg::3");
   385         aStrings.AppendL(KFormatExtensionJpeg);   
   396         aStrings.AppendL(KFormatExtensionJpeg);
       
   397         
       
   398         /*
       
   399          * bmp files
       
   400          */
       
   401 //        _LIT(KFormatExtensionBmp, "0x3804:bmp::3");
       
   402 //        aStrings.AppendL(KFormatExtensionBmp);
       
   403         
       
   404         /*
       
   405          * gif files
       
   406          */
       
   407 //        _LIT(KFormatExtensionGif, "0x3807:gif::3");
       
   408 //        aStrings.AppendL(KFormatExtensionGif);
       
   409         
       
   410         /*
       
   411          * png files
       
   412          */
       
   413 //        _LIT(KFormatExtensionPng, "0x380B:png::3");
       
   414 //        aStrings.AppendL(KFormatExtensionPng);
       
   415         
       
   416         /*
       
   417          * tif, tiff files
       
   418          */
       
   419         /*
       
   420         _LIT(KFormatExtensionTif, "0x380D:tif::3");
       
   421         aStrings.AppendL(KFormatExtensionTif);
       
   422         _LIT(KFormatExtensionTiff, "0x380D:tiff::3");
       
   423         aStrings.AppendL(KFormatExtensionTiff);
       
   424         */                 
   386         }
   425         }
   387         break;
   426         break;
   388         
   427         
   389     default:
   428     default:
   390         // Unrecognised category, leave aArray unmodified.
   429         // Unrecognised category, leave aArray unmodified.
   528                 processor->Release();
   567                 processor->Release();
   529                 }
   568                 }
   530             }
   569             }
   531         }
   570         }
   532     
   571     
       
   572     /**
       
   573      * We clear property manager cache when receiving session close notification from framework every times
       
   574      */
       
   575     iPropertyMgr->ClearCacheL();
       
   576     
   533     __FLOG(_L8("<< SessionClosedL"));
   577     __FLOG(_L8("<< SessionClosedL"));
   534     }
   578     }
   535 
   579 
   536 /**
   580 /**
   537  Notify the data provider that the session opened
   581  Notify the data provider that the session opened
   550     if (iEnumerated)
   594     if (iEnumerated)
   551         {
   595         {
   552         /**
   596         /**
   553          * Get image object count from framework and calculate the new pictures
   597          * Get image object count from framework and calculate the new pictures
   554          */
   598          */
   555         TUint curPictures = QueryImageObjectCountL();
   599         TUint newPictures = QueryImageObjectCountL();
   556         TInt  newPictures = curPictures - iPrePictures;
   600         RProperty::Set(TUid::Uid(KMTPServerUID), KMTPNewPicKey, newPictures);
   557         
   601         iNewPicNotifier->SetNewPictures(newPictures);
   558         __FLOG_2(_L16("CMTPImageDpEnumerator::CompleteEnumeration - Previous Pics:%d, New Pics: %d"), iPrePictures, newPictures);
   602         __FLOG_1(_L16("CMTPImageDpEnumerator::CompleteEnumeration - New Pics: %d"), newPictures);        
   559         if (newPictures >= 0)
       
   560             {
       
   561             MTPImageDpUtilits::UpdateNewPicturesValue(*this, newPictures, ETrue);  
       
   562             }
       
   563         else
       
   564             {
       
   565             MTPImageDpUtilits::UpdateNewPicturesValue(*this, 0, ETrue);  
       
   566             }
       
   567         
       
   568         iEnumerated = EFalse;
   603         iEnumerated = EFalse;
   569         }
   604         }
   570     
   605     
   571     __FLOG(_L8("<< SessionOpenedL "));
   606     __FLOG(_L8("<< SessionOpenedL "));
   572     }
   607     }
   591     }
   626     }
   592 
   627 
   593 /**
   628 /**
   594  Find format code according to its extension name 
   629  Find format code according to its extension name 
   595 */
   630 */
   596 TMTPFormatCode CMTPImageDataProvider::FindFormatL(const TDesC& aExtension)
   631 TMTPFormatCode CMTPImageDataProvider::FindFormat(const TDesC& aExtension)
   597     {
   632     {
   598     TMTPFormatCode* ret = iFormatMappings.Find(aExtension);
   633     TMTPFormatCode* ret = iFormatMappings.Find(aExtension);
   599     User::LeaveIfNull(ret);
   634     if (ret == NULL)
   600     
   635         {
   601     return *ret;
   636         return EMTPFormatCodeUndefined;
       
   637         }
       
   638     else
       
   639         {
       
   640         return *ret;
       
   641         }
       
   642     }
       
   643 
       
   644 /**
       
   645  Find mime type according to its extension name 
       
   646 */
       
   647 const TDesC& CMTPImageDataProvider::FindMimeType(const TDesC& aExtension)
       
   648     {
       
   649     /**
       
   650      * copy file extension by insensitive case
       
   651      */
       
   652     TBuf<KMaxExtNameLength> extension;
       
   653     extension.CopyLC(aExtension);
       
   654     
       
   655     const TDesC* ret = iMimeMappings.Find(extension);
       
   656     if (ret == NULL)
       
   657         {
       
   658         return KNullDesC;
       
   659         }
       
   660     else
       
   661         {
       
   662         return *ret;
       
   663         }
   602     }
   664     }
   603 
   665 
   604 /**
   666 /**
   605  Query image object count from current framework 
   667  Query image object count from current framework 
   606 */
   668 */
   607 TUint CMTPImageDataProvider::QueryImageObjectCountL()
   669 TUint CMTPImageDataProvider::QueryImageObjectCountL()
   608     { 
   670     { 
   609     TMTPObjectMgrQueryParams params(KMTPStorageAll, EMTPFormatCodeEXIFJPEG, KMTPHandleNone);    
   671     RMTPObjectMgrQueryContext   context;
   610     return Framework().ObjectMgr().CountL(params);
   672     RArray<TUint>               handles;
       
   673     TMTPObjectMgrQueryParams    params(KMTPStorageAll, KMTPFormatsAll, KMTPHandleNone, Framework().DataProviderId());
       
   674     CleanupClosePushL(context);
       
   675     CleanupClosePushL(handles);    
       
   676     
       
   677     do
       
   678         {
       
   679         /*
       
   680          * Speed up query performance, avoid to duplicated copy object handle between RArrays
       
   681          */
       
   682         Framework().ObjectMgr().GetObjectHandlesL(params, context, handles);
       
   683         }
       
   684     while (!context.QueryComplete());    
       
   685     
       
   686     CMTPObjectMetaData* objMetadata = CMTPObjectMetaData::NewLC();
       
   687     
       
   688     TUint newPictures = 0;
       
   689     TInt count = handles.Count();
       
   690     for (TInt i(0); i<count; ++i)
       
   691         {
       
   692         Framework().ObjectMgr().ObjectL(handles[i], *objMetadata);
       
   693         if (MTPImageDpUtilits::IsNewPicture(*objMetadata))
       
   694             {
       
   695             ++newPictures;
       
   696             }
       
   697         }
       
   698     
       
   699     
       
   700     CleanupStack::PopAndDestroy(objMetadata);
       
   701     CleanupStack::PopAndDestroy(&handles);
       
   702     CleanupStack::PopAndDestroy(&context);
       
   703     
       
   704     return newPictures;
   611     }
   705     }
   612 
   706 
   613 TBool CMTPImageDataProvider::GetCacheParentHandle(const TDesC& aParentPath, TUint32& aParentHandle)
   707 TBool CMTPImageDataProvider::GetCacheParentHandle(const TDesC& aParentPath, TUint32& aParentHandle)
   614     {
   708     {
   615     TBool ret = EFalse;
   709     TBool ret = EFalse;
   654             delete object;
   748             delete object;
   655             object = NULL;
   749             object = NULL;
   656             }
   750             }
   657         }
   751         }
   658     }
   752     }
       
   753 
       
   754 void CMTPImageDataProvider::IncreaseNewPictures(TInt aCount)
       
   755     {
       
   756     __FLOG_VA((_L16(">> IncreaseNewPictures New Pictures: %d"), aCount));
       
   757 
       
   758     iNewPicNotifier->IncreaseCount(aCount);    
       
   759     
       
   760     __FLOG(_L8("<< IncreaseNewPictures "));    
       
   761     }
       
   762 
       
   763 void CMTPImageDataProvider::DecreaseNewPictures(TInt aCount)
       
   764     {
       
   765     __FLOG_VA((_L16(">> DecreaseNewPictures New Pictures: %d"), aCount));
       
   766 
       
   767     iNewPicNotifier->DecreaseCount(aCount);
       
   768     
       
   769     __FLOG(_L8("<< DecreaseNewPictures "));    
       
   770     }