mtpdataproviders/mtpimagedp/src/cmtpimagedpmdeobserver.cpp
changeset 17 aabe5387f5ce
parent 0 d0791faffa3f
child 12 8b094906a049
--- a/mtpdataproviders/mtpimagedp/src/cmtpimagedpmdeobserver.cpp	Tue Feb 02 01:11:40 2010 +0200
+++ b/mtpdataproviders/mtpimagedp/src/cmtpimagedpmdeobserver.cpp	Fri Mar 19 09:40:39 2010 +0200
@@ -71,23 +71,20 @@
     __FLOG_CLOSE;
     }
 
-void CMTPImageDpMdeObserver::CreateMetadataL(const CMdEObject& aMdeObject, CMTPObjectMetaData& aMetaData)
+void CMTPImageDpMdeObserver::CreateMetadataL(const TParsePtrC& aParse, TMTPFormatCode aFormat, TUint32 aParentHandle, CMTPObjectMetaData& aMetaData)
     {
-    const TDesC& uri = aMdeObject.Uri();
-    TParsePtrC parse(uri);  
-    TMTPFormatCode format = iDataProvider.FindFormatL(parse.Ext().Mid(1));
-    TInt32 storageId = MTPImageDpUtilits::FindStorage(iFramework, uri);
-    TUint32 parentHandle = MTPImageDpUtilits::FindParentHandleL(iFramework, iDataProvider, uri);
-    
+    TInt32 storageId = MTPImageDpUtilits::FindStorage(iFramework, aParse.FullName());
+     
+    __FLOG_VA((_L16("Addition - New Image:%S"), &aParse.FullName()));
     aMetaData.SetUint(CMTPObjectMetaData::EDataProviderId, iFramework.DataProviderId());
-    aMetaData.SetUint(CMTPObjectMetaData::EFormatCode, format);
+    aMetaData.SetUint(CMTPObjectMetaData::EFormatCode, aFormat);
     aMetaData.SetUint(CMTPObjectMetaData::EStorageId, storageId);
-    aMetaData.SetDesCL(CMTPObjectMetaData::ESuid, uri);    
-    aMetaData.SetUint(CMTPObjectMetaData::EParentHandle, parentHandle);
-    aMetaData.SetDesCL(CMTPObjectMetaData::EName, parse.Name());
+    aMetaData.SetDesCL(CMTPObjectMetaData::ESuid, aParse.FullName());    
+    aMetaData.SetUint(CMTPObjectMetaData::EParentHandle, aParentHandle);
+    aMetaData.SetDesCL(CMTPObjectMetaData::EName, aParse.Name());
     
     //Increate the new pictures variable
-    ++iNewPics;
+    ++iNewPics;  
     }
 
 void CMTPImageDpMdeObserver::ProcessMdeNotificationL(const RArray<TItemId>& aObjectIdArray, TObserverNotificationType /*aType*/)
@@ -109,26 +106,51 @@
             continue;
             }
         CleanupStack::PushL(mdeObject);
+        __FLOG_VA((_L16("Addition - ObjectId:%u, URI:%S"), aObjectIdArray[i], &mdeObject->Uri()));
         
-        TUint32 handle = iFramework.ObjectMgr().HandleL(mdeObject->Uri());
-        if (handle == KMTPHandleNone)
+        //filter out all image files other jpeg files       
+        TParsePtrC parse(mdeObject->Uri());
+        TMTPFormatCode format = iDataProvider.FindFormat(parse.Ext().Mid(1));
+        if (format != EMTPFormatCodeUndefined)
             {
-            CMTPObjectMetaData* object = CMTPObjectMetaData::NewLC();
-            CreateMetadataL(*mdeObject, *object);
-            iFramework.ObjectMgr().InsertObjectL(*object);                
-            __FLOG_VA((_L16("Addition - Handle:%u, ObjectId:%u, URI:%S"), object->Uint(CMTPObjectMetaData::EHandle), aObjectIdArray[i], &mdeObject->Uri()));
-            
-            TMTPTypeEvent event;
-            event.SetUint16(TMTPTypeEvent::EEventCode, EMTPEventCodeObjectAdded);
-            event.SetUint32(TMTPTypeEvent::EEventSessionID, KMTPSessionAll);
-            event.SetUint32(TMTPTypeEvent::EEventTransactionID, KMTPTransactionIdNone);
-          
-            TUint32 handle = object->Uint(CMTPObjectMetaData::EHandle);            
-            event.SetUint32(TMTPTypeEvent::EEventParameter1, handle);                    
-            iFramework.SendEventL(event);
-            __FLOG_VA((_L8("ProcessMdeNotificationL - EMTPEventCodeObjectAdd, object handle:%u"), handle));
-            
-            CleanupStack::PopAndDestroy(object);//object 
+            TUint32 handle = iFramework.ObjectMgr().HandleL(mdeObject->Uri());
+            if (handle == KMTPHandleNone)
+                {
+                /**
+                 * Try to find parent handle of new image file
+                 * if we can't find parent handle we should issue a notification to framework, let framework to enumerate new folder if need
+                 */
+                TUint32 parentHandle = MTPImageDpUtilits::FindParentHandleL(iFramework, iDataProvider, parse.FullName());
+                if (parentHandle == KMTPHandleNone)
+                    {
+                    __FLOG_VA((_L16("Notify framework - URI:%S"), &mdeObject->Uri()));
+                    TMTPNotificationParamsFolderChange param = {mdeObject->Uri()};                                       
+                    iFramework.NotifyFrameworkL(EMTPAddFolder, &param);
+                    
+                    //try to get parent handle if framework complete it's tasks
+                    parentHandle = MTPImageDpUtilits::FindParentHandleL(iFramework, iDataProvider, parse.FullName());
+                    __FLOG_VA((_L16("Framework enumeration parent handle:%u"), parentHandle));
+                    }
+                
+                if (parentHandle != KMTPHandleNone)
+                    {
+                    CMTPObjectMetaData* object = CMTPObjectMetaData::NewLC();
+                    CreateMetadataL(parse, format, parentHandle, *object);
+                    iFramework.ObjectMgr().InsertObjectL(*object);                
+                    __FLOG_VA((_L16("Addition - New Handle:%u"), object->Uint(CMTPObjectMetaData::EHandle)));
+                    
+                    TMTPTypeEvent event;
+                    event.SetUint16(TMTPTypeEvent::EEventCode, EMTPEventCodeObjectAdded);
+                    event.SetUint32(TMTPTypeEvent::EEventSessionID, KMTPSessionAll);
+                    event.SetUint32(TMTPTypeEvent::EEventTransactionID, KMTPTransactionIdNone);
+                  
+                    TUint32 handle = object->Uint(CMTPObjectMetaData::EHandle);            
+                    event.SetUint32(TMTPTypeEvent::EEventParameter1, handle);                    
+                    iFramework.SendEventL(event);
+                    __FLOG_VA((_L8("ProcessMdeNotificationL - EMTPEventCodeObjectAdd, object handle:%u"), handle));                    
+                    CleanupStack::PopAndDestroy(object);//object                 
+                    }
+                }
             }
         
         CleanupStack::PopAndDestroy(mdeObject);//mdeObject             
@@ -165,7 +187,7 @@
     if (iNewPics > 0)
         {
         __FLOG_1(_L16("CMTPImageDpMdeObserver::CMTPImageDpMdeObserver - New Pics: %u"), iNewPics);
-        MTPImageDpUtilits::UpdateNewPicturesValue(iDataProvider, iNewPics, ETrue);
+        iDataProvider.IncreaseNewPictures(iNewPics);
         iNewPics = 0;
         }
     
@@ -188,8 +210,8 @@
         
         //Only subscribe add observer        
         CMdELogicCondition* addCondition = CMdELogicCondition::NewLC(ELogicConditionOperatorAnd);          
-        CMdEPropertyDef& itemTypePropDef = imageObjDef.GetPropertyDefL(MdeConstants::Object::KItemTypeProperty);       
-        addCondition->AddPropertyConditionL(itemTypePropDef, ETextPropertyConditionCompareEndsWith, _L("jpeg"));                       
+        CMdEPropertyDef& itemTypePropDef = imageObjDef.GetPropertyDefL(MdeConstants::Object::KItemTypeProperty);
+        addCondition->AddObjectConditionL(imageObjDef);                 
         mdeSession.AddObjectObserverL(*this, addCondition, ENotifyAdd);
         CleanupStack::Pop(addCondition);