videocollection/mpxmyvideoscollection/src/vcxmyvideosmdsalbums.cpp
changeset 37 4eb2df7f7cbe
parent 36 8aed59de29f9
child 38 ff53afa8ad05
equal deleted inserted replaced
36:8aed59de29f9 37:4eb2df7f7cbe
    53     CActiveScheduler::Add( this );
    53     CActiveScheduler::Add( this );
    54     
    54     
    55     if ( iObserver )
    55     if ( iObserver )
    56         {
    56         {
    57         //ENotifyAdd and ENotifyModify are not supported
    57         //ENotifyAdd and ENotifyModify are not supported
    58         iMdsDb.iMdsSession->AddRelationItemObserverL( *this, NULL,
    58         iMdsDb.MdsSessionL().AddRelationItemObserverL( *this, NULL,
    59                 ENotifyRemove, iMdsDb.iNamespaceDef );
    59                 ENotifyRemove, iMdsDb.iNamespaceDef );
    60 
    60 
    61 #if 0
    61 #if 0
    62         // We receive only IDs from here. We need to make query to get
    62         // We receive only IDs from here. We need to make query to get
    63         // relation objects-> slow to use. We use the response from
    63         // relation objects-> slow to use. We use the response from
    64         // the add operation instead. This way we don't receive
    64         // the add operation instead. This way we don't receive
    65         // add events if someone else adds videos to our albums
    65         // add events if someone else adds videos to our albums
    66         // but the performance is the best possible.
    66         // but the performance is the best possible.
    67         iMdsDb.iMdsSession->AddRelationObserverL( *this, NULL,
    67         iMdsDb.MdsSessionL().AddRelationObserverL( *this, NULL,
    68                 ENotifyAdd | ENotifyModify | ENotifyRemove );        
    68                 ENotifyAdd | ENotifyModify | ENotifyRemove );        
    69 #endif
    69 #endif
    70         }
    70         }
    71     
    71     
    72     //TODO: do we need this?
    72     //TODO: do we need this?
    73     //iMdsDb.iMdsSession->AddRelationPresentObserverL();
    73     //iMdsDb.MdsSessionL().AddRelationPresentObserverL();
    74     }
    74     }
    75 
    75 
    76 // ---------------------------------------------------------------------------
    76 // ---------------------------------------------------------------------------
    77 // Two-Phase Constructor
    77 // Two-Phase Constructor
    78 // ---------------------------------------------------------------------------
    78 // ---------------------------------------------------------------------------
   152 //
   152 //
   153 void CVcxMyVideosMdsAlbums::DoCancel()
   153 void CVcxMyVideosMdsAlbums::DoCancel()
   154     {
   154     {
   155     MPX_DEBUG1("CVcxMyVideosMdsAlbums::DoCancel() start");
   155     MPX_DEBUG1("CVcxMyVideosMdsAlbums::DoCancel() start");
   156 
   156 
   157 #if 0
   157     // MDS does not offer way to cancel these async requests
   158     // Seems like the only way to cancel these is to close session to MDS and reopen it...
       
   159     // Update: even this does not cancel the operation
       
   160     MPX_DEBUG1("CVcxMyVideosMdsAlbums:: closing mds session");
       
   161 
       
   162     delete iMdsDb.iMdsSession;
       
   163     iMdsDb.iMdsSession = NULL;
       
   164     
       
   165     MPX_DEBUG1("CVcxMyVideosMdsAlbums:: opening mds session");
       
   166     TRAP_IGNORE( iMdsDb.OpenMdsSessionL() );
       
   167     MPX_DEBUG2("CVcxMyVideosMdsAlbums:: opened mds session (%d)", iMdsDb.iMdsError);
       
   168 #endif
       
   169     
   158     
   170     MPX_DEBUG1("CVcxMyVideosMdsAlbums::DoCancel() exit");
   159     MPX_DEBUG1("CVcxMyVideosMdsAlbums::DoCancel() exit");
   171     }
   160     }
   172 
   161 
   173 // ---------------------------------------------------------------------------
   162 // ---------------------------------------------------------------------------
   226     iClient    = &aClient;
   215     iClient    = &aClient;
   227     
   216     
   228     delete iAlbumQuery;
   217     delete iAlbumQuery;
   229     iAlbumQuery = NULL;
   218     iAlbumQuery = NULL;
   230     
   219     
   231     iAlbumQuery = iMdsDb.iMdsSession->NewObjectQueryL( *iNamespaceDef, *iAlbumObjectDef, this );
   220     iAlbumQuery = iMdsDb.MdsSessionL().NewObjectQueryL( *iNamespaceDef, *iAlbumObjectDef, this );
   232 
   221 
   233     CMdELogicCondition& rootCondition = iAlbumQuery->Conditions();
   222     CMdELogicCondition& rootCondition = iAlbumQuery->Conditions();
   234     rootCondition.SetOperator( ELogicConditionOperatorOr );
   223     rootCondition.SetOperator( ELogicConditionOperatorOr );
   235     rootCondition.AddObjectConditionL( *iAlbumObjectDef );
   224     rootCondition.AddObjectConditionL( *iAlbumObjectDef );
   236     rootCondition.AddPropertyConditionL( *iTypePropertyDef,
   225     rootCondition.AddPropertyConditionL( *iTypePropertyDef,
   275     
   264     
   276     iClient       = &aClient;
   265     iClient       = &aClient;
   277     iAlbumId      = aAlbumId;
   266     iAlbumId      = aAlbumId;
   278     iAlbumContent = &aContentArray;
   267     iAlbumContent = &aContentArray;
   279     
   268     
   280     iRelationQuery = iMdsDb.iMdsSession->NewRelationQueryL( *iNamespaceDef, this );
   269     iRelationQuery = iMdsDb.MdsSessionL().NewRelationQueryL( *iNamespaceDef, this );
   281 
   270 
   282     CMdELogicCondition& rootCondition = iRelationQuery->Conditions();
   271     CMdELogicCondition& rootCondition = iRelationQuery->Conditions();
   283 
   272 
   284     //relation left side contains and...
   273     //relation left side contains and...
   285     CMdERelationCondition& relationCondition =
   274     CMdERelationCondition& relationCondition =
   335 
   324 
   336     iClient    = &aClient;
   325     iClient    = &aClient;
   337     iVideoList = &aVideoList;
   326     iVideoList = &aVideoList;
   338     iAlbumId   = aAlbumId;
   327     iAlbumId   = aAlbumId;
   339     
   328     
   340     iVideoQuery = iMdsDb.iMdsSession->NewObjectQueryL( *iNamespaceDef, *iMdsDb.iVideoObjectDef, this );
   329     iVideoQuery = iMdsDb.MdsSessionL().NewObjectQueryL( *iNamespaceDef, *iMdsDb.iVideoObjectDef, this );
   341     CMdELogicCondition& rootCondition = iVideoQuery->Conditions();
   330     CMdELogicCondition& rootCondition = iVideoQuery->Conditions();
   342     CMdERelationCondition& relationCondition = 
   331     CMdERelationCondition& relationCondition = 
   343             rootCondition.AddRelationConditionL( *iContainsRelationDef );
   332             rootCondition.AddRelationConditionL( *iContainsRelationDef );
   344 
   333 
   345     CMdELogicCondition& leftCondition = relationCondition.LeftL();
   334     CMdELogicCondition& leftCondition = relationCondition.LeftL();
       
   335     CMdELogicCondition& rightCondition = relationCondition.RightL();
   346 
   336 
   347     //...left side is an album...
   337     //...left side is an album...
   348     leftCondition.AddObjectConditionL( *iAlbumObjectDef );
   338     leftCondition.AddObjectConditionL( *iAlbumObjectDef );
   349     //...and left id is aAlbumId..
   339     //...and left id is aAlbumId..
   350     leftCondition.AddObjectConditionL( aAlbumId );
   340     leftCondition.AddObjectConditionL( aAlbumId );
   362 // CVcxMyVideosMdsAlbums::GetSchemaDefinitionsL
   352 // CVcxMyVideosMdsAlbums::GetSchemaDefinitionsL
   363 // ---------------------------------------------------------------------------
   353 // ---------------------------------------------------------------------------
   364 //
   354 //
   365 void CVcxMyVideosMdsAlbums::GetSchemaDefinitionsL()
   355 void CVcxMyVideosMdsAlbums::GetSchemaDefinitionsL()
   366     {
   356     {
   367     iNamespaceDef = &(iMdsDb.iMdsSession->GetDefaultNamespaceDefL());
   357     iNamespaceDef = &(iMdsDb.MdsSessionL().GetDefaultNamespaceDefL());
   368     
   358     
   369     _LIT( KVcxAlbumObjectName, "Album" );
   359     _LIT( KVcxAlbumObjectName, "Album" );
   370     iAlbumObjectDef = &(iNamespaceDef->GetObjectDefL( KVcxAlbumObjectName ));
   360     iAlbumObjectDef = &(iNamespaceDef->GetObjectDefL( KVcxAlbumObjectName ));
   371 
   361 
   372     _LIT( KVcxTypePropertyName, "Type" );
   362     _LIT( KVcxTypePropertyName, "Type" );
   632         CleanupStack::PushL( media ); // 1->
   622         CleanupStack::PushL( media ); // 1->
   633 
   623 
   634         iMdsDb.Object2MediaL( object, *media );
   624         iMdsDb.Object2MediaL( object, *media );
   635         
   625         
   636 #ifdef _DEBUG
   626 #ifdef _DEBUG
   637         TBuf<200> title;
   627         TBuf<256> title;
   638         title = TVcxMyVideosCollectionUtil::Title( *media );
   628         title = TVcxMyVideosCollectionUtil::Title( *media );
   639         MPX_DEBUG2("CVcxMyVideosMdsAlbums:: object title: %S", &title);
   629         MPX_DEBUG2("CVcxMyVideosMdsAlbums:: object title: %S", &title);
   640 #endif        
   630 #endif        
   641 
   631 
   642         array->AppendL( media );
   632         array->AppendL( media );
   722         {
   712         {
   723         // Filter already failed items out from the request (KErrAlreadyExists)
   713         // Filter already failed items out from the request (KErrAlreadyExists)
   724         if ( TVcxMyVideosCollectionUtil::Int32ValueL( *videoArray->AtL( i ) ) 
   714         if ( TVcxMyVideosCollectionUtil::Int32ValueL( *videoArray->AtL( i ) ) 
   725                 != KErrAlreadyExists )
   715                 != KErrAlreadyExists )
   726             {
   716             {
   727             relation = iMdsDb.iMdsSession->NewRelationL(
   717             relation = iMdsDb.MdsSessionL().NewRelationL(
   728                     *iContainsRelationDef, albumId,
   718                     *iContainsRelationDef, albumId,
   729                     TVcxMyVideosCollectionUtil::IdL( *videoArray->AtL( i ) ) );
   719                     TVcxMyVideosCollectionUtil::IdL( *videoArray->AtL( i ) ) );
   730             CleanupStack::PushL( relation );
   720             CleanupStack::PushL( relation );
   731             iItemArray.AppendL( relation );
   721             iItemArray.AppendL( relation );
   732             CleanupStack::Pop( relation );        
   722             CleanupStack::Pop( relation );        
   736     iClient = &aClient;
   726     iClient = &aClient;
   737     iMpxCmd = aCmd;
   727     iMpxCmd = aCmd;
   738 
   728 
   739     iAsyncOperation = EVcxAddVideosToAlbum;
   729     iAsyncOperation = EVcxAddVideosToAlbum;
   740 
   730 
   741     iMdsDb.iMdsSession->AddItemsAsyncL( iItemArray, iStatus, iResultBuffer );
   731     iMdsDb.MdsSessionL().AddItemsAsyncL( iItemArray, iStatus, iResultBuffer );
   742     SetActive();
   732     SetActive();
   743     }
   733     }
   744 
   734 
   745 // ---------------------------------------------------------------------------
   735 // ---------------------------------------------------------------------------
   746 // CVcxMyVideosMdsAlbums::RemoveRelationsL
   736 // CVcxMyVideosMdsAlbums::RemoveRelationsL
   777     iResultArrayUint32 = &aResults;
   767     iResultArrayUint32 = &aResults;
   778     iIdArray           = &aRelationIds;
   768     iIdArray           = &aRelationIds;
   779     
   769     
   780     iAsyncOperation = EVcxRemoveRelations;
   770     iAsyncOperation = EVcxRemoveRelations;
   781     
   771     
   782     iMdsDb.iMdsSession->RemoveRelationsAsyncL( *iIdArray, iStatus, iResultBuffer, iNamespaceDef );
   772     iMdsDb.MdsSessionL().RemoveRelationsAsyncL( *iIdArray, iStatus, iResultBuffer, iNamespaceDef );
   783     SetActive();
   773     SetActive();
   784     
   774     
   785     MPX_DEBUG1("CVcxMyVideosMdsAlbums::DoRemoveRelationsL() exit");
   775     MPX_DEBUG1("CVcxMyVideosMdsAlbums::DoRemoveRelationsL() exit");
   786     }
   776     }
   787 
   777 
   790 // ---------------------------------------------------------------------------
   780 // ---------------------------------------------------------------------------
   791 //
   781 //
   792 void CVcxMyVideosMdsAlbums::AddAlbumL( CMPXMedia& aAlbum )
   782 void CVcxMyVideosMdsAlbums::AddAlbumL( CMPXMedia& aAlbum )
   793     {
   783     {
   794     MPX_DEBUG1("CVcxMyVideosMdsAlbums::AddAlbumL() start");
   784     MPX_DEBUG1("CVcxMyVideosMdsAlbums::AddAlbumL() start");
   795     
   785              
   796     if ( !iMdsDb.iMdsSession )
   786     CMdEObject* object = iMdsDb.MdsSessionL().NewObjectLC(
   797         {
       
   798         MPX_DEBUG2("CVcxMyVideosMdsAlbums:: no mds session(%d), leaving", iMdsDb.iMdsError);
       
   799         User::Leave( iMdsDb.iMdsError );
       
   800         }
       
   801          
       
   802     CMdEObject* object = iMdsDb.iMdsSession->NewObjectLC(
       
   803             *iAlbumObjectDef, KNullDesC ); // 1->
   787             *iAlbumObjectDef, KNullDesC ); // 1->
   804 
   788 
   805     Media2ObjectL( aAlbum, *object );
   789     Media2ObjectL( aAlbum, *object );
   806     iMdsDb.SetCreationAndModifiedDatesL( *object );
   790     iMdsDb.SetCreationAndModifiedDatesL( *object );
   807 
   791 
   808     TUint32 mdsId;
   792     TUint32 mdsId;
   809 
   793 
   810 #ifdef _DEBUG
   794 #ifdef _DEBUG
   811     TRAPD( err, mdsId = iMdsDb.iMdsSession->AddObjectL( *object ) );
   795     TRAPD( err, mdsId = iMdsDb.MdsSessionL().AddObjectL( *object ) );
   812 
   796 
   813     if ( err != KErrNone )
   797     if ( err != KErrNone )
   814         {
   798         {
   815         MPX_DEBUG2( "CVcxMyVideosMdsAlbums:: iMdsDb.iMdsSession->AddObjectL leaved with error: %d", err );
   799         MPX_DEBUG2( "CVcxMyVideosMdsAlbums:: iMdsDb.MdsSessionL().AddObjectL leaved with error: %d", err );
   816         User::Leave( err );
   800         User::Leave( err );
   817         }
   801         }
   818 #else
   802 #else
   819 
   803 
   820     mdsId = iMdsDb.iMdsSession->AddObjectL( *object );
   804     mdsId = iMdsDb.MdsSessionL().AddObjectL( *object );
   821 
   805 
   822 #endif
   806 #endif
   823     
   807     
   824     if ( mdsId == KNoId )
   808     if ( mdsId == KNoId )
   825         {
   809         {
   842 //
   826 //
   843 void CVcxMyVideosMdsAlbums::SetAlbumL( CMPXMedia& aVideo )
   827 void CVcxMyVideosMdsAlbums::SetAlbumL( CMPXMedia& aVideo )
   844     {
   828     {
   845     MPX_DEBUG1("CVcxMyVideosMdsDb::SetAlbumL() start");
   829     MPX_DEBUG1("CVcxMyVideosMdsDb::SetAlbumL() start");
   846 
   830 
   847     if ( !iMdsDb.iMdsSession )
       
   848         {
       
   849         MPX_DEBUG2("CVcxMyVideosMdsAlbums:: no mds session(%d), leaving", iMdsDb.iMdsError);
       
   850         User::Leave( iMdsDb.iMdsError );
       
   851         }
       
   852 
       
   853     TMPXItemId mpxId = TVcxMyVideosCollectionUtil::IdL( aVideo );
   831     TMPXItemId mpxId = TVcxMyVideosCollectionUtil::IdL( aVideo );
   854 
   832 
   855     MPX_DEBUG2("CVcxMyVideosMdsAlbums::SetAlbumL updating object %d ", mpxId.iId1);
   833     MPX_DEBUG2("CVcxMyVideosMdsAlbums::SetAlbumL updating object %d ", mpxId.iId1);
   856     
   834     
   857     CMdEObject* object =
   835     CMdEObject* object =
   858             iMdsDb.iMdsSession->OpenObjectL( mpxId.iId1, *iAlbumObjectDef );
   836             iMdsDb.MdsSessionL().OpenObjectL( mpxId.iId1, *iAlbumObjectDef );
   859     if ( !object )
   837     if ( !object )
   860         {
   838         {
   861         // No object with this ID was found!
   839         // No object with this ID was found!
   862         MPX_DEBUG1("CVcxMyVideosMdsAlbums::SetAlbumL no object found");
   840         MPX_DEBUG1("CVcxMyVideosMdsAlbums::SetAlbumL no object found");
   863         User::Leave( KErrNotFound );
   841         User::Leave( KErrNotFound );
   870             {
   848             {
   871             CleanupStack::PushL( object ); // 1->
   849             CleanupStack::PushL( object ); // 1->
   872             
   850             
   873             Media2ObjectL( aVideo, *object );
   851             Media2ObjectL( aVideo, *object );
   874             
   852             
   875             iMdsDb.iMdsSession->CommitObjectL( *object );
   853             iMdsDb.MdsSessionL().CommitObjectL( *object );
   876 
   854 
   877             CleanupStack::PopAndDestroy( object );
   855             CleanupStack::PopAndDestroy( object );
   878             }
   856             }
   879         else
   857         else
   880             {
   858             {
   927 
   905 
   928     TVcxMyVideosCollectionUtil::GetIdsFromMediaArrayL( *mediaArray, idArray );
   906     TVcxMyVideosCollectionUtil::GetIdsFromMediaArrayL( *mediaArray, idArray );
   929     
   907     
   930     iAsyncOperation = EVcxRemoveAlbums;
   908     iAsyncOperation = EVcxRemoveAlbums;
   931     
   909     
   932     iMdsDb.iMdsSession->RemoveObjectsAsyncL( idArray, iStatus, iResultBuffer, iNamespaceDef );
   910     iMdsDb.MdsSessionL().RemoveObjectsAsyncL( idArray, iStatus, iResultBuffer, iNamespaceDef );
   933     
   911     
   934     CleanupStack::PopAndDestroy( &idArray );
   912     CleanupStack::PopAndDestroy( &idArray );
   935     SetActive();
   913     SetActive();
   936 
   914 
   937     MPX_DEBUG1("CVcxMyVideosMdsAlbums::DoRemoveAlbumsL() exit");    
   915     MPX_DEBUG1("CVcxMyVideosMdsAlbums::DoRemoveAlbumsL() exit");    
   980 //
   958 //
   981 void CVcxMyVideosMdsAlbums::HandleAddVideosToAlbumCompletedL()
   959 void CVcxMyVideosMdsAlbums::HandleAddVideosToAlbumCompletedL()
   982     {
   960     {
   983     MPX_DEBUG1("CVcxMyVideosMdsAlbums::HandleAddVideosToAlbumCompletedL() start");
   961     MPX_DEBUG1("CVcxMyVideosMdsAlbums::HandleAddVideosToAlbumCompletedL() start");
   984     
   962     
   985     iMdsDb.iMdsSession->DeserializeItemsL( iResultBuffer, iItemArray );
   963     iMdsDb.MdsSessionL().DeserializeItemsL( iResultBuffer, iItemArray );
   986     
   964     
   987     iClient->HandleAddVideosToAlbumResp( iMpxCmd, iItemArray );
   965     iClient->HandleAddVideosToAlbumResp( iMpxCmd, iItemArray );
   988     iResultBuffer.Close();
   966     iResultBuffer.Close();
   989     iItemArray.Close();    
   967     iItemArray.Close();    
   990 
   968 
   997 //
   975 //
   998 void CVcxMyVideosMdsAlbums::HandleRemoveRelationsCompletedL()
   976 void CVcxMyVideosMdsAlbums::HandleRemoveRelationsCompletedL()
   999     {
   977     {
  1000     MPX_DEBUG1("CVcxMyVideosMdsAlbums::HandleRemoveRelationsCompletedL() start");
   978     MPX_DEBUG1("CVcxMyVideosMdsAlbums::HandleRemoveRelationsCompletedL() start");
  1001     
   979     
  1002     iMdsDb.iMdsSession->DeserializeIdsL( iResultBuffer, NULL, NULL, iResultArrayUint32 );
   980     iMdsDb.MdsSessionL().DeserializeIdsL( iResultBuffer, NULL, NULL, iResultArrayUint32 );
  1003 
   981 
  1004 #ifdef _DEBUG
   982 #ifdef _DEBUG
  1005     TItemId result;
   983     TItemId result;
  1006     TInt count = iResultArrayUint32->Count();
   984     TInt count = iResultArrayUint32->Count();
  1007     for ( TInt i = 0; i < count; i++ )
   985     for ( TInt i = 0; i < count; i++ )
  1026 
  1004 
  1027     RArray<TUint32> resultArray;
  1005     RArray<TUint32> resultArray;
  1028     resultArray.Reset();
  1006     resultArray.Reset();
  1029     CleanupClosePushL( resultArray );
  1007     CleanupClosePushL( resultArray );
  1030     
  1008     
  1031     iMdsDb.iMdsSession->DeserializeIdsL( iResultBuffer, &resultArray, NULL, NULL  );
  1009     iMdsDb.MdsSessionL().DeserializeIdsL( iResultBuffer, &resultArray, NULL, NULL  );
  1032 
  1010 
  1033 #ifdef _DEBUG
  1011 #ifdef _DEBUG
  1034     TItemId result;
  1012     TItemId result;
  1035     TInt count = resultArray.Count();
  1013     TInt count = resultArray.Count();
  1036 
  1014