videocollection/mpxmyvideoscollection/src/vcxmyvideosmdsalbums.cpp
changeset 36 8aed59de29f9
parent 35 3738fe97f027
child 37 4eb2df7f7cbe
equal deleted inserted replaced
35:3738fe97f027 36:8aed59de29f9
    56         {
    56         {
    57         //ENotifyAdd and ENotifyModify are not supported
    57         //ENotifyAdd and ENotifyModify are not supported
    58         iMdsDb.iMdsSession->AddRelationItemObserverL( *this, NULL,
    58         iMdsDb.iMdsSession->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.
    91 // Destructor
    91 // Destructor
    92 // ---------------------------------------------------------------------------
    92 // ---------------------------------------------------------------------------
    93 //
    93 //
    94 CVcxMyVideosMdsAlbums::~CVcxMyVideosMdsAlbums()
    94 CVcxMyVideosMdsAlbums::~CVcxMyVideosMdsAlbums()
    95     {
    95     {
       
    96     CancelQueries();
    96     delete iAlbumQuery;
    97     delete iAlbumQuery;
    97     delete iVideoQuery;
    98     delete iVideoQuery;
    98     delete iRelationQuery;
    99     delete iRelationQuery;
    99     delete iAlbumList;
       
   100     iItemArray.Close();
   100     iItemArray.Close();
   101     iResultBuffer.Close();
   101     iResultBuffer.Close();
   102     }
   102     }
   103 
   103 
   104 // ---------------------------------------------------------------------------
   104 // ---------------------------------------------------------------------------
   105 // CVcxMyVideosMdsAlbums::Cancel
   105 // CVcxMyVideosMdsAlbums::CancelQueries
   106 // ---------------------------------------------------------------------------
   106 // ---------------------------------------------------------------------------
   107 //
   107 //
   108 void CVcxMyVideosMdsAlbums::Cancel( CVcxMyVideosMdsDb::TRequestType aType )
   108 void CVcxMyVideosMdsAlbums::CancelQueries( CVcxMyVideosMdsDb::TRequestType aType )
   109     {
   109     {
       
   110     MPX_DEBUG1("CVcxMyVideosMdsAlbums::CancelQueries() start");
       
   111 
   110     if ( aType == CVcxMyVideosMdsDb::EAll || aType == CVcxMyVideosMdsDb::EGetAlbums )
   112     if ( aType == CVcxMyVideosMdsDb::EAll || aType == CVcxMyVideosMdsDb::EGetAlbums )
   111         {
   113         {
   112         if ( iAlbumQuery )
   114         if ( iAlbumQuery )
   113             {
   115             {
   114             iAlbumQuery->Cancel();
   116             iAlbumQuery->Cancel();
   128         if ( iVideoQuery )
   130         if ( iVideoQuery )
   129             {
   131             {
   130             iVideoQuery->Cancel();
   132             iVideoQuery->Cancel();
   131             }
   133             }
   132         }
   134         }
   133     
   135 
   134     
   136     if ( aType == CVcxMyVideosMdsDb::EAll || aType == CVcxMyVideosMdsDb::EAddVideosToAlbum
   135     //TODO: cancel for "add to album"
   137             || aType == CVcxMyVideosMdsDb::ERemoveRelations
   136     
   138             || aType == CVcxMyVideosMdsDb::ERemoveAlbums )
   137     //TODO: cancel for "remove from album"
   139         {
   138     
   140         
   139     //TODO: cancel for "remove albums"
   141         // MDS does not offer cancel for these
   140     
   142         //Cancel();
       
   143         }
       
   144 
       
   145     MPX_DEBUG1("CVcxMyVideosMdsAlbums::CancelQueries() exit");
       
   146     }
       
   147 
       
   148 // ---------------------------------------------------------------------------
       
   149 // From CActive
       
   150 // CVcxMyVideosMdsAlbums::DoCancel
       
   151 // ---------------------------------------------------------------------------
       
   152 //
       
   153 void CVcxMyVideosMdsAlbums::DoCancel()
       
   154     {
       
   155     MPX_DEBUG1("CVcxMyVideosMdsAlbums::DoCancel() start");
       
   156 
       
   157 #if 0
   141     // Seems like the only way to cancel these is to close session to MDS and reopen it...
   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     
       
   170     MPX_DEBUG1("CVcxMyVideosMdsAlbums::DoCancel() exit");
   142     }
   171     }
   143 
   172 
   144 // ---------------------------------------------------------------------------
   173 // ---------------------------------------------------------------------------
   145 // CVcxMyVideosMdsAlbums::GetAlbumsL
   174 // CVcxMyVideosMdsAlbums::GetAlbumsL
   146 // ---------------------------------------------------------------------------
   175 // ---------------------------------------------------------------------------
   312     CMdELogicCondition& rootCondition = iVideoQuery->Conditions();
   341     CMdELogicCondition& rootCondition = iVideoQuery->Conditions();
   313     CMdERelationCondition& relationCondition = 
   342     CMdERelationCondition& relationCondition = 
   314             rootCondition.AddRelationConditionL( *iContainsRelationDef );
   343             rootCondition.AddRelationConditionL( *iContainsRelationDef );
   315 
   344 
   316     CMdELogicCondition& leftCondition = relationCondition.LeftL();
   345     CMdELogicCondition& leftCondition = relationCondition.LeftL();
   317     CMdELogicCondition& rightCondition = relationCondition.RightL();
       
   318 
   346 
   319     //...left side is an album...
   347     //...left side is an album...
   320     leftCondition.AddObjectConditionL( *iAlbumObjectDef );
   348     leftCondition.AddObjectConditionL( *iAlbumObjectDef );
   321     //...and left id is aAlbumId..
   349     //...and left id is aAlbumId..
   322     leftCondition.AddObjectConditionL( aAlbumId );
   350     leftCondition.AddObjectConditionL( aAlbumId );
   549         CleanupStack::PushL( media ); // 1->
   577         CleanupStack::PushL( media ); // 1->
   550 
   578 
   551         Object2MediaL( object, *media );
   579         Object2MediaL( object, *media );
   552         
   580         
   553 #ifdef _DEBUG
   581 #ifdef _DEBUG
   554         TBuf<200> title;
   582         TBuf<KVcxMvcMaxTitleLength> title;
   555         title = TVcxMyVideosCollectionUtil::Title( *media );
   583         title = TVcxMyVideosCollectionUtil::Title( *media );
   556         MPX_DEBUG2("CVcxMyVideosMdsAlbums:: object title: %S", &title);
   584         MPX_DEBUG2("CVcxMyVideosMdsAlbums:: object title: %S", &title);
   557 #endif        
   585 #endif        
   558 
   586 
   559         array->AppendL( media );
   587         array->AppendL( media );
   666     CVcxMyVideosMdsCmdAddVideosToAlbum* cmd = new (ELeave) CVcxMyVideosMdsCmdAddVideosToAlbum;
   694     CVcxMyVideosMdsCmdAddVideosToAlbum* cmd = new (ELeave) CVcxMyVideosMdsCmdAddVideosToAlbum;
   667     CleanupStack::PushL( cmd ); // 1->
   695     CleanupStack::PushL( cmd ); // 1->
   668     cmd->iCmdType  = CVcxMyVideosMdsDb::EAddVideosToAlbum;
   696     cmd->iCmdType  = CVcxMyVideosMdsDb::EAddVideosToAlbum;
   669     cmd->iClient   = &aClient;
   697     cmd->iClient   = &aClient;
   670     cmd->iMpxCmd   = aCmd;
   698     cmd->iMpxCmd   = aCmd;
   671     iMdsDb.iCmdQueue->ExecuteCmdL( cmd ); //owneship moves
   699     iMdsDb.iCmdQueue->ExecuteCmdL( cmd ); //ownership moves
   672     CleanupStack::Pop( cmd ); // <-1
   700     CleanupStack::Pop( cmd ); // <-1
   673     MPX_DEBUG1("CVcxMyVideosMdsAlbums::AddVideosToAlbumL() exit");
   701     MPX_DEBUG1("CVcxMyVideosMdsAlbums::AddVideosToAlbumL() exit");
   674     }
   702     }
   675     
   703     
   676 // ---------------------------------------------------------------------------
   704 // ---------------------------------------------------------------------------
   690     
   718     
   691     TInt count = videoArray->Count();
   719     TInt count = videoArray->Count();
   692     iItemArray.Reserve( count );
   720     iItemArray.Reserve( count );
   693     for ( TInt i = 0; i < count; i++ )
   721     for ( TInt i = 0; i < count; i++ )
   694         {
   722         {
   695         relation = iMdsDb.iMdsSession->NewRelationL(
   723         // Filter already failed items out from the request (KErrAlreadyExists)
   696                 *iContainsRelationDef, albumId,
   724         if ( TVcxMyVideosCollectionUtil::Int32ValueL( *videoArray->AtL( i ) ) 
   697                 TVcxMyVideosCollectionUtil::IdL( *videoArray->AtL( i ) ) );
   725                 != KErrAlreadyExists )
   698         CleanupStack::PushL( relation );
   726             {
   699         iItemArray.AppendL( relation );
   727             relation = iMdsDb.iMdsSession->NewRelationL(
   700         CleanupStack::Pop( relation );
   728                     *iContainsRelationDef, albumId,
       
   729                     TVcxMyVideosCollectionUtil::IdL( *videoArray->AtL( i ) ) );
       
   730             CleanupStack::PushL( relation );
       
   731             iItemArray.AppendL( relation );
       
   732             CleanupStack::Pop( relation );        
       
   733             }
   701         }
   734         }
   702     
   735     
   703     iClient = &aClient;
   736     iClient = &aClient;
   704     iMpxCmd = aCmd;
   737     iMpxCmd = aCmd;
   705 
   738 
   940     }
   973     }
   941 
   974 
   942 //TODO: implement RunError
   975 //TODO: implement RunError
   943 
   976 
   944 // ---------------------------------------------------------------------------
   977 // ---------------------------------------------------------------------------
   945 // CVcxMyVideosMdsAlbums::RunL
       
   946 // From CActive.
       
   947 // ---------------------------------------------------------------------------
       
   948 //
       
   949 void CVcxMyVideosMdsAlbums::DoCancel()
       
   950     {
       
   951     //TODO:
       
   952     }
       
   953 
       
   954 // ---------------------------------------------------------------------------
       
   955 // CVcxMyVideosMdsAlbums::HandleAddVideosToAlbumCompletedL
   978 // CVcxMyVideosMdsAlbums::HandleAddVideosToAlbumCompletedL
   956 // ---------------------------------------------------------------------------
   979 // ---------------------------------------------------------------------------
   957 //
   980 //
   958 void CVcxMyVideosMdsAlbums::HandleAddVideosToAlbumCompletedL()
   981 void CVcxMyVideosMdsAlbums::HandleAddVideosToAlbumCompletedL()
   959     {
   982     {
  1037         const RArray<TMdERelation>& aRelationArray)
  1060         const RArray<TMdERelation>& aRelationArray)
  1038     {
  1061     {
  1039     iObserver->HandleRelationEvent( aType, aRelationArray );
  1062     iObserver->HandleRelationEvent( aType, aRelationArray );
  1040     }
  1063     }
  1041 
  1064 
  1042 #if 0 //not used
  1065 #if 0
  1043 // ----------------------------------------------------------------------------
  1066 // ----------------------------------------------------------------------------
  1044 // CVcxMyVideosMdsAlbums::HandleRelationNotification
  1067 // CVcxMyVideosMdsAlbums::HandleRelationNotification
  1045 // From MMdERelationObserver
  1068 // From MMdERelationObserver
  1046 // ----------------------------------------------------------------------------
  1069 // ----------------------------------------------------------------------------
  1047 //
  1070 //
  1048 void CVcxMyVideosMdsAlbums::HandleRelationNotification(CMdESession& /*aSession*/, 
  1071 void CVcxMyVideosMdsAlbums::HandleRelationNotification(CMdESession& /*aSession*/, 
  1049         TObserverNotificationType aType,
  1072         TObserverNotificationType aType,
  1050         const RArray<TItemId>& aRelationIdArray)
  1073         const RArray<TItemId>& aRelationIdArray)
  1051     {
  1074     {    
  1052     iObserver->HandleRelationIdEvent( aType, aRelationIdArray );
       
  1053     
       
  1054     switch ( aType )
  1075     switch ( aType )
  1055         {
  1076         {
  1056         case ENotifyAdd:
  1077         case ENotifyAdd:
  1057             MPX_DEBUG1("CVcxMyVideosMdsAlbums:: ENotifyAdd");
  1078             MPX_DEBUG1("CVcxMyVideosMdsAlbums:: relation ENotifyAdd");
       
  1079             iObserver->HandleRelationIdEvent( aType, aRelationIdArray );
  1058             break;
  1080             break;
  1059         case ENotifyModify:
  1081         case ENotifyModify:
  1060             MPX_DEBUG1("CVcxMyVideosMdsAlbums:: ENotifyModify");
  1082             MPX_DEBUG1("CVcxMyVideosMdsAlbums:: ENotifyModify");
  1061             break;
  1083             break;
  1062         case ENotifyRemove:
  1084         case ENotifyRemove:
  1063             MPX_DEBUG1("CVcxMyVideosMdsAlbums:: ENotifyRemove");
  1085             //remove is handled at HandleRelationItemNotification
  1064             break;
  1086             break;
  1065         }
  1087         }
  1066     }
  1088     }
  1067 #endif
  1089 #endif
  1068 
  1090