videocollection/mpxmyvideoscollection/src/vcxmyvideosmdsdb.cpp
changeset 0 96612d01cf9f
child 2 dec420019252
equal deleted inserted replaced
-1:000000000000 0:96612d01cf9f
       
     1 /*
       
     2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:    MPX My Videos collection plugin's MDS database class*
       
    15 */
       
    16 
       
    17 
       
    18 
       
    19 
       
    20 //#include <harvesterclient.h>
       
    21 #include <mpxlog.h>
       
    22 #include <mdeconstants.h>
       
    23 #include <mdequery.h>
       
    24 #include <bautils.h>
       
    25 #include <mpxmedia.h>
       
    26 #include <vcxmyvideosdefs.h>
       
    27 #include <mpxmediacontainerdefs.h>
       
    28 #include <mpxmediageneraldefs.h>
       
    29 #include <mpxmediageneralextdefs.h>
       
    30 #include <mpxmediaarray.h>
       
    31 #include <mpxmediavideodefs.h>
       
    32 #include "vcxmyvideosmdsdb.h"
       
    33 #include "vcxmyvideoscollectionutil.h"
       
    34 
       
    35 _LIT( KVcxVideoObjectName, "Video" );
       
    36                                                               //1 (ID)
       
    37 _LIT( KVcxTitlePropertyName, "Title" );                       //2
       
    38 _LIT( KVcxDescriptionPropertyName, "Description" );           //3
       
    39                                                               //4 (file path = URI)
       
    40 _LIT( KVcxSizePropertyName, "Size" );                         //11 (5 also for compatibility)
       
    41 
       
    42 _LIT( KVcxCreationDatePropertyName, "CreationDate" );         //6 creation date is saved to 2 properties
       
    43 _LIT( KVcxTimeOffsetPropertyName, "TimeOffset" );             //6
       
    44 
       
    45 _LIT( KVcxFlagsPropertyName, "RecordingFlags" );              //7 flags are saved
       
    46 _LIT( KVcxDrmPropertyName, "DRM");                            //7 to both of these
       
    47 
       
    48 _LIT( KVcxCopyrightPropertyName, "Copyright" );               //8
       
    49 _LIT( KVcxItemTypePropertyName, "ItemType" );                 //9 (mime type)
       
    50 _LIT( KVcxLastModifiedDatePropertyName, "LastModifiedDate" ); //12
       
    51 _LIT( KVcxAgeProfilePropertyName, "AgeProfile" );             //13
       
    52 _LIT( KVcxAudioLanguagePropertyName, "AudioLanguage" );       //14
       
    53 _LIT( KVcxAuthorPropertyName, "Author" );                     //15
       
    54 _LIT( KVcxOriginPropertyName, "Origin" );                     //16
       
    55 _LIT( KVcxDurationPropertyName, "Duration" );                 //17
       
    56 _LIT( KVcxLastPlayPositionPropertyName, "LastPlayPosition" ); //10
       
    57 _LIT( KVcxDownloadIdPropertyName, "DownloadID" );             //18
       
    58 _LIT( KVcxRatingPropertyName, "Rating" );                     //19
       
    59 _LIT( KVcxBitratePropertyName, "Bitrate" );                   //20
       
    60 _LIT( KVcxAudioFourCcPropertyName, "AudioFourCC" );           //21
       
    61 _LIT( KVcxWidthPropertyName, "Width" );                       //22
       
    62 _LIT( KVcxHeightPropertyName, "Height" );                     //23
       
    63 _LIT( KVcxArtistPropertyName, "Artist" );                     //24
       
    64 
       
    65 
       
    66 // ---------------------------------------------------------------------------
       
    67 // ---------------------------------------------------------------------------
       
    68 //
       
    69 CVcxMyVideosMdsDb::CVcxMyVideosMdsDb( MVcxMyVideosMdsDbObserver* aObserver, RFs& aFs )
       
    70 : iFs( aFs ), iMdsDbObserver(aObserver) 
       
    71     {
       
    72     }
       
    73 
       
    74 // ---------------------------------------------------------------------------
       
    75 // ---------------------------------------------------------------------------
       
    76 //
       
    77 void CVcxMyVideosMdsDb::ConstructL()
       
    78     {
       
    79     MPX_FUNC( "CVcxMyVideosMdsDb::ConstructL" );
       
    80 
       
    81     iActiveSchedulerWait = new (ELeave) CActiveSchedulerWait;
       
    82     
       
    83     MPX_DEBUG1( "CVcxMyVideosMdsDb::ConstructL CMdESession::NewL" );
       
    84 
       
    85     //  Create session
       
    86     iMDSError = KErrNone;
       
    87 
       
    88     iMDSSession = CMdESession::NewL( *this );
       
    89     if (!iMDSSession)
       
    90         {
       
    91         //  Failed to create session, leave
       
    92         User::Leave( iMDSError );
       
    93         }
       
    94 
       
    95     //  Wait until session opened
       
    96     iActiveSchedulerWait->Start();
       
    97 
       
    98     MPX_DEBUG1( "CVcxMyVideosMdsDb::ConstructL iActiveSchedulerWait->Start done" );
       
    99 
       
   100     if ( iMDSError != KErrNone )
       
   101         {
       
   102         MPX_DEBUG2("Failed to create session to MDS: %d", iMDSError);
       
   103         User::LeaveIfError( iMDSError );
       
   104         }
       
   105 
       
   106     //  Get the schema definitions
       
   107     iMDSError = KErrNone;
       
   108     GetSchemaDefinitionsL();
       
   109 
       
   110     //  Is schema ok
       
   111     if ( iMDSError != KErrNone )
       
   112         {
       
   113         //  Schema not loaded, abort
       
   114         User::Leave( iMDSError );
       
   115         }
       
   116 
       
   117     MPX_DEBUG1( "CVcxMyVideosMdsDb::ConstructL Adding observers" );
       
   118 
       
   119     // We order all object notifications. If we set video condition, then we wont
       
   120     // receive remove notifications at all (mds feature). Extra notifications
       
   121     // do not bother us much since we try to fetch the item from the db
       
   122     // after the add notification anyways, and then we use video condition.
       
   123     // Eventually extra events are ignored.    
       
   124     iMDSSession->AddObjectObserverL( *this, NULL );
       
   125     
       
   126     iMDSSession->AddObjectPresentObserverL( *this );    
       
   127     }
       
   128 
       
   129 // ---------------------------------------------------------------------------
       
   130 // ---------------------------------------------------------------------------
       
   131 //
       
   132 void CVcxMyVideosMdsDb::HandleObjectPresentNotification( CMdESession& /*aSession*/,
       
   133         TBool aPresent, const RArray<TItemId>& aObjectIdArray)
       
   134     {
       
   135     MPX_DEBUG1( "CVcxMyVideosMdsDb::--------------------------------------------------------------." );
       
   136     MPX_DEBUG3( "CVcxMyVideosMdsDb::HandleObjectPresentNotification( aPresent = %1d, count = %3d) |", aPresent, aObjectIdArray.Count() );
       
   137     MPX_DEBUG1( "CVcxMyVideosMdsDb::--------------------------------------------------------------'" );
       
   138     //iMdsDbObserver->HandleObjectPresentNotification();
       
   139 
       
   140     TObserverNotificationType type;
       
   141     if ( aPresent )
       
   142         {
       
   143         type = ENotifyAdd;
       
   144         }
       
   145     else
       
   146         {
       
   147         type = ENotifyRemove;
       
   148         }
       
   149     
       
   150     TRAP_IGNORE( DoHandleObjectNotificationL( type, aObjectIdArray ) );    
       
   151     }
       
   152 
       
   153 // ---------------------------------------------------------------------------
       
   154 // ---------------------------------------------------------------------------
       
   155 //
       
   156 CVcxMyVideosMdsDb* CVcxMyVideosMdsDb::NewL( MVcxMyVideosMdsDbObserver* aObserver, RFs& aFs )
       
   157     {
       
   158     CVcxMyVideosMdsDb* self =
       
   159             CVcxMyVideosMdsDb::NewLC( aObserver, aFs );
       
   160     CleanupStack::Pop( self );
       
   161     return self;
       
   162     }
       
   163 
       
   164 
       
   165 // ---------------------------------------------------------------------------
       
   166 // ---------------------------------------------------------------------------
       
   167 //
       
   168 CVcxMyVideosMdsDb* CVcxMyVideosMdsDb::NewLC(
       
   169         MVcxMyVideosMdsDbObserver* aObserver, RFs& aFs )
       
   170     {
       
   171     CVcxMyVideosMdsDb* self = new( ELeave ) CVcxMyVideosMdsDb( aObserver, aFs );
       
   172     CleanupStack::PushL( self );
       
   173     self->ConstructL();
       
   174     return self;
       
   175     }
       
   176 
       
   177 
       
   178 // ---------------------------------------------------------------------------
       
   179 // ---------------------------------------------------------------------------
       
   180 //
       
   181 CVcxMyVideosMdsDb::~CVcxMyVideosMdsDb()
       
   182     {
       
   183     MPX_FUNC( "CVcxMyVideosMdsDb::~CVcxMyVideosMdsDb()" );
       
   184 
       
   185     if ( iMDSSession )
       
   186         {
       
   187         TRAP_IGNORE( iMDSSession->RemoveObjectObserverL( *this ) );        
       
   188         }
       
   189 
       
   190     Cancel();
       
   191     
       
   192     delete iVideoQuery;
       
   193     delete iMDSSession;
       
   194     delete iActiveSchedulerWait;
       
   195     }
       
   196 
       
   197 // ---------------------------------------------------------------------------
       
   198 // CVcxMyVideosMdsDb::Cancel
       
   199 // ---------------------------------------------------------------------------
       
   200 //
       
   201 void CVcxMyVideosMdsDb::Cancel()
       
   202     {
       
   203     MPX_FUNC("CVcxMyVideosMdsDb::Cancel()");
       
   204     
       
   205     if ( iVideoQuery )
       
   206         {
       
   207         iVideoQuery->Cancel();
       
   208         }
       
   209     iVideoListFetchingIsOngoing = EFalse;
       
   210     }
       
   211     
       
   212 // ---------------------------------------------------------------------------
       
   213 // CVcxMyVideosMdsDb::AddVideoL
       
   214 // ---------------------------------------------------------------------------
       
   215 //
       
   216 void CVcxMyVideosMdsDb::AddVideoL(
       
   217         CMPXMedia& aVideo, 
       
   218         TUint32& aMdsId )
       
   219     {
       
   220     MPX_FUNC( "CVcxMyVideosMdsDb::AddVideoL" );
       
   221 
       
   222     if ( !iMDSSession )
       
   223         {
       
   224         MPX_DEBUG2("CVcxMyVideosMdsDb:: no mds session(%d), leaving", iMDSError);
       
   225         User::Leave( iMDSError );
       
   226         }
       
   227          
       
   228     CMdEObject* object = iMDSSession->NewObjectLC(
       
   229             *iVideoObjectDef, aVideo.ValueText( KMPXMediaGeneralUri ) ); // 1->
       
   230 
       
   231     // check if the file exists and use the creation time from the file
       
   232     
       
   233     TTime time;
       
   234     time.UniversalTime();
       
   235 	TTimeIntervalSeconds timeOffset = User::UTCOffset();
       
   236 	TTime localTime = time + timeOffset;
       
   237         
       
   238     object->AddTimePropertyL( *iCreationDatePropertyDef, localTime ); 
       
   239 	object->AddInt16PropertyL( *iTimeOffsetPropertyDef, timeOffset.Int() / 60 );
       
   240     object->AddTimePropertyL( *iLastModifiedDatePropertyDef, localTime );
       
   241     object->AddUint8PropertyL( *iOriginPropertyDef,
       
   242             aVideo.ValueTObjectL<TUint8>( KVcxMediaMyVideosOrigin ) );
       
   243 
       
   244     CMdEProperty* property;
       
   245 
       
   246     //  Type can not be modified normally, so set it here
       
   247     if ( aVideo.IsSupported( KMPXMediaGeneralMimeType ) )
       
   248         {
       
   249         if (KErrNotFound != object->Property( *iItemTypePropertyDef, property, 0 ))
       
   250             {
       
   251             static_cast<CMdETextProperty*>(property)->SetValueL(
       
   252                     aVideo.ValueText( KMPXMediaGeneralMimeType ) );
       
   253             }
       
   254         else
       
   255             {
       
   256             object->AddTextPropertyL(
       
   257                 *iItemTypePropertyDef,
       
   258                 aVideo.ValueText( KMPXMediaGeneralMimeType ) );
       
   259             }
       
   260         }
       
   261 
       
   262     Media2ObjectL( aVideo, *object );
       
   263     TRAPD( err, aMdsId = iMDSSession->AddObjectL( *object ) );
       
   264 
       
   265     if ( err != KErrNone )
       
   266         {
       
   267         MPX_DEBUG2( "CVcxMyVideosMdsDb:: iMDSSession->AddObjectL leaved with error: %d", err );
       
   268         User::Leave( err );
       
   269         }
       
   270         
       
   271     if ( aMdsId == KNoId )
       
   272         {
       
   273         MPX_DEBUG1( "CVcxMyVideosMdsDb::AddVideoL could not add new video" );
       
   274         User::Leave( KErrGeneral );
       
   275         }
       
   276     else
       
   277         {
       
   278         MPX_DEBUG2( "CVcxMyVideosMdsDb::AddVideoL video created, mds id: %d", aMdsId );
       
   279         }        
       
   280 
       
   281     CleanupStack::PopAndDestroy( object ); // <-1
       
   282 
       
   283     }
       
   284 
       
   285 // ---------------------------------------------------------------------------
       
   286 // CVcxMyVideosMdsDb::RemoveVideo
       
   287 // ---------------------------------------------------------------------------
       
   288 //
       
   289 TInt CVcxMyVideosMdsDb::RemoveVideo( TUint32 aMdsId )
       
   290     {
       
   291     MPX_FUNC( "CVcxMyVideosMdsDb::RemoveVideoL" );
       
   292 
       
   293     if ( !iMDSSession )
       
   294         {
       
   295         MPX_DEBUG2("CVcxMyVideosMdsDb:: no mds session, returning %d", iMDSError);
       
   296         return iMDSError;
       
   297         }
       
   298 
       
   299     TInt retValue( KErrNone );
       
   300     TItemId id( 0 ); //init to avoid warning
       
   301 
       
   302     MPX_DEBUG2( "CVcxMyVideosMdsDb:: removing object %d", aMdsId );
       
   303     
       
   304     TRAPD( err,  id = iMDSSession->RemoveObjectL( aMdsId ) );
       
   305 
       
   306     if ( err == KErrNone )
       
   307         {
       
   308         if ( id == KNoId )
       
   309             {
       
   310             MPX_DEBUG1( "CVcxMyVideosMdsDb:: video not found" );
       
   311             retValue = KErrNotFound;
       
   312             }
       
   313         else
       
   314             {
       
   315             MPX_DEBUG1( "CVcxMyVideosMdsDb:: remove successful" );
       
   316             }
       
   317         }
       
   318     else
       
   319         {
       
   320         MPX_DEBUG2( "CVcxMyVideosMdsDb:: iMDSSession->RemoveObjectL left: %d", err );
       
   321         retValue = err;        
       
   322         }
       
   323         
       
   324     return retValue;
       
   325     }
       
   326 
       
   327 // ---------------------------------------------------------------------------
       
   328 // CVcxMyVideosMdsDb::UpdateVideoL
       
   329 // ---------------------------------------------------------------------------
       
   330 //
       
   331 void CVcxMyVideosMdsDb::UpdateVideoL( CMPXMedia& aVideo )
       
   332     {
       
   333     MPX_FUNC( "CVcxMyVideosMdsDb::UpdateVideoL" );
       
   334 
       
   335     if ( !iMDSSession )
       
   336         {
       
   337         MPX_DEBUG2("CVcxMyVideosMdsDb:: no mds session(%d), leaving", iMDSError);
       
   338         User::Leave( iMDSError );
       
   339         }
       
   340 
       
   341     TMPXItemId mpxId = aVideo.ValueTObjectL<TMPXItemId>( KMPXMediaGeneralId );
       
   342 
       
   343     MPX_DEBUG2("CVcxMyVideosMdsDb::UpdateVideoL updating object %d ", mpxId.iId1);
       
   344     
       
   345     CMdEObject* object =
       
   346             iMDSSession->OpenObjectL( mpxId.iId1, *iVideoObjectDef );
       
   347     if ( object == NULL )
       
   348         {
       
   349         // No object with this ID was found!
       
   350         MPX_DEBUG1("CVcxMyVideosMdsDb::UpdateVideoL no object found");
       
   351         User::Leave( KErrNotFound );
       
   352         }
       
   353     else
       
   354         {
       
   355         MPX_DEBUG1("CVcxMyVideosMdsDb::UpdateVideoL object found");
       
   356         
       
   357         if ( object->OpenForModifications() )
       
   358             {
       
   359             CleanupStack::PushL( object ); // 1->
       
   360             
       
   361             Media2ObjectL( aVideo, *object );
       
   362             
       
   363             iMDSSession->CommitObjectL(*object);
       
   364 
       
   365             CleanupStack::PopAndDestroy(object);
       
   366             }
       
   367         else
       
   368             {
       
   369             // Object is already locked!
       
   370             MPX_DEBUG1("CVcxMyVideosMdsDb::UpdateVideoL object was locked!");
       
   371             delete object;
       
   372             User::Leave( KErrInUse );
       
   373             }
       
   374         }
       
   375     }
       
   376 
       
   377 // ---------------------------------------------------------------------------
       
   378 // CVcxMyVideosMdsDb::CreateVideoListL
       
   379 // ---------------------------------------------------------------------------
       
   380 //
       
   381 void CVcxMyVideosMdsDb::CreateVideoListL( TVcxMyVideosSortingOrder aSortingOrder,
       
   382         TBool aAscending, TBool aFullDetails, CMPXMedia*& aVideoList )
       
   383     {
       
   384     MPX_FUNC( "CVcxMyVideosMdsDb::CreateVideoListL" );
       
   385 
       
   386     if ( !iMDSSession )
       
   387         {
       
   388         MPX_DEBUG2("CVcxMyVideosMdsDb:: no mds session(%d), leaving", iMDSError);
       
   389         User::Leave( iMDSError );
       
   390         }
       
   391         
       
   392     if ( iVideoListFetchingIsOngoing )
       
   393         {
       
   394         MPX_DEBUG1("CVcxMyVideosMdsDb:: video list fetching already going on, returning current list");
       
   395         aVideoList = iVideoList;
       
   396         }
       
   397     
       
   398     if ( !aVideoList )
       
   399         {
       
   400         aVideoList = TVcxMyVideosCollectionUtil::CreateEmptyMediaListL();
       
   401         }
       
   402                     
       
   403     CMPXMediaArray* mediaArray = aVideoList->Value<CMPXMediaArray>( KMPXMediaArrayContents );
       
   404     
       
   405     delete iVideoQuery;
       
   406     iVideoQuery = NULL;
       
   407     
       
   408     iVideoQuery = iMDSSession->NewObjectQueryL(
       
   409             *iNamespaceDef,
       
   410             *iVideoObjectDef,
       
   411             this);
       
   412 
       
   413     iVideoQuery->SetResultMode( EQueryResultModeItem );
       
   414 
       
   415     TMdESortOrder direction;
       
   416     
       
   417     if ( aAscending )
       
   418         {
       
   419         direction = ESortAscending;
       
   420         }
       
   421     else
       
   422         {
       
   423         direction = ESortDescending;
       
   424         }
       
   425         
       
   426     switch ( aSortingOrder )
       
   427         {
       
   428         case EVcxMyVideosSortingId:
       
   429             {
       
   430             MPX_DEBUG1("CVcxMyVideosMdsDb:: EVcxMyVideosSortingId"); 
       
   431             iVideoQuery->AppendOrderRuleL(
       
   432                 TMdEOrderRule( EOrderRuleTypeItemID, direction ) );
       
   433             }
       
   434             break;
       
   435             
       
   436         case EVcxMyVideosSortingCreationDate:
       
   437             {
       
   438             MPX_DEBUG1("CVcxMyVideosMdsDb:: EVcxMyVideosSortingCreationDate"); 
       
   439             iVideoQuery->AppendOrderRuleL(
       
   440                 TMdEOrderRule( *iCreationDatePropertyDef/*EOrderRuleTypeCreationTime*/, direction ) );
       
   441             }
       
   442             break;
       
   443 
       
   444         case EVcxMyVideosSortingModified:
       
   445             {
       
   446             MPX_DEBUG1("CVcxMyVideosMdsDb:: EVcxMyVideosSortingModified"); 
       
   447             iVideoQuery->AppendOrderRuleL(
       
   448                 TMdEOrderRule( *iLastModifiedDatePropertyDef/*EOrderRuleTypeLastModifiedDate*/, direction ) );
       
   449             }
       
   450             break;
       
   451 
       
   452         case EVcxMyVideosSortingName:
       
   453             {
       
   454             MPX_DEBUG1("CVcxMyVideosMdsDb:: EVcxMyVideosSortingName"); 
       
   455         
       
   456             TMdEOrderRule orderRule( *iTitlePropertyDef, direction );
       
   457             orderRule.SetCaseSensitive( EFalse /* insensitive */);
       
   458             iVideoQuery->AppendOrderRuleL( orderRule );
       
   459             }
       
   460             break;
       
   461 
       
   462         case EVcxMyVideosSortingSize:
       
   463             {
       
   464             MPX_DEBUG1("CVcxMyVideosMdsDb:: EVcxMyVideosSortingSize"); 
       
   465             iVideoQuery->AppendOrderRuleL(
       
   466                 TMdEOrderRule( *iSizePropertyDef, direction ) );
       
   467             }
       
   468             break;
       
   469         }
       
   470 
       
   471     iVideoListFetchingIsOngoing = ETrue;
       
   472 
       
   473     iFullDetails = aFullDetails;
       
   474     
       
   475     iVideoQuery->FindL(KMdEQueryDefaultMaxCount, 500);
       
   476 
       
   477     aVideoList->SetTObjectValueL<TMPXGeneralType>( KMPXMediaGeneralType, EMPXGroup );            
       
   478     aVideoList->SetTObjectValueL( KMPXMediaArrayCount, mediaArray->Count() );
       
   479 
       
   480     iVideoList = aVideoList; // lets store the pointer, ownership stays at observer
       
   481     }
       
   482 
       
   483 // ---------------------------------------------------------------------------
       
   484 // From class MMdEQueryObserver.
       
   485 // ---------------------------------------------------------------------------
       
   486 //
       
   487 void CVcxMyVideosMdsDb::HandleQueryNewResults(
       
   488         CMdEQuery& aQuery,
       
   489         TInt aFirstNewItemIndex,
       
   490         TInt aNewItemCount )
       
   491     {
       
   492     TRAPD( err, DoHandleQueryNewResultsL( aQuery, aFirstNewItemIndex, aNewItemCount ));
       
   493     if ( err != KErrNone )
       
   494         {
       
   495         MPX_DEBUG2("CVcxMyVideosMdsDb:: DoHandleQueryNewResultsL() left with error code: %d", err);
       
   496         }
       
   497     }
       
   498     
       
   499 // ---------------------------------------------------------------------------
       
   500 // Leaving version of HandleQueryNewResults.
       
   501 // ---------------------------------------------------------------------------
       
   502 //
       
   503 void CVcxMyVideosMdsDb::DoHandleQueryNewResultsL(
       
   504         CMdEQuery& /*aQuery*/,
       
   505         TInt aFirstNewItemIndex,
       
   506 #ifdef _DEBUG
       
   507         TInt aNewItemCount )
       
   508 #else
       
   509         TInt /*aNewItemCount*/ )
       
   510 #endif
       
   511     {
       
   512     MPX_FUNC("CVcxMyVideosMdsDb::HandleQueryNewResults()");
       
   513     
       
   514     if ( !iVideoList )
       
   515         {
       
   516         MPX_DEBUG1("CVcxMyVideosMdsDb:: iVideoList is NULL, should never happen");
       
   517         return;
       
   518         }
       
   519     
       
   520     MPX_DEBUG2("CVcxMyVideosMdsDb:: aFirstNewItemIndex = %d", aFirstNewItemIndex);
       
   521     MPX_DEBUG2("CVcxMyVideosMdsDb:: aNewItemCount      = %d", aNewItemCount);
       
   522         
       
   523     CMPXMediaArray* array = iVideoList->Value<CMPXMediaArray>( KMPXMediaArrayContents );
       
   524     CMPXMedia* media;    
       
   525     TInt count = iVideoQuery->Count();
       
   526     
       
   527     iVideoList->SetTObjectValueL<TInt>( KMPXMediaArrayCount, count );
       
   528     
       
   529     for ( TInt i = aFirstNewItemIndex; i < count; i++ )
       
   530         {
       
   531         CMdEObject& object = iVideoQuery->Result( i );
       
   532 
       
   533         media = CMPXMedia::NewL();
       
   534         CleanupStack::PushL( media ); // 1->
       
   535         
       
   536         Object2MediaL( object, *media, iFullDetails );
       
   537         array->AppendL( media );
       
   538 
       
   539         CleanupStack::Pop( media ); // <-1
       
   540         }
       
   541     
       
   542     iMdsDbObserver->HandleCreateVideoListResp( iVideoList, aFirstNewItemIndex,
       
   543             EFalse /* not complete yet */);
       
   544     }
       
   545 
       
   546 
       
   547             
       
   548 // ---------------------------------------------------------------------------
       
   549 // From class MMdEQueryObserver.
       
   550 // ---------------------------------------------------------------------------
       
   551 //
       
   552 void CVcxMyVideosMdsDb::HandleQueryCompleted(
       
   553 #if _DEBUG
       
   554         CMdEQuery& aQuery,
       
   555 #else
       
   556         CMdEQuery& /*aQuery*/,
       
   557 #endif
       
   558         TInt /*aError*/)
       
   559     {
       
   560     MPX_FUNC( "CVcxMyVideosMdsDb::HandleQueryCompleted" );
       
   561 
       
   562     if ( !iVideoList )
       
   563         {
       
   564         MPX_DEBUG1("CVcxMyVideosMdsDb:: iVideoList is NULL, should never happen");
       
   565         return;
       
   566         }
       
   567 
       
   568 #ifdef _DEBUG
       
   569     CMPXMediaArray* array = iVideoList->Value<CMPXMediaArray>( KMPXMediaArrayContents );
       
   570 #endif
       
   571 
       
   572     MPX_DEBUG2("CVcxMyVideosMdsDb:: query contains %d items", aQuery.Count());
       
   573     MPX_DEBUG2("CVcxMyVideosMdsDb:: iVideoList contains %d items", array->Count());
       
   574     
       
   575     if (iActiveSchedulerWait->IsStarted())
       
   576         {
       
   577         iActiveSchedulerWait->AsyncStop();
       
   578         }
       
   579     
       
   580     iVideoListFetchingIsOngoing = EFalse;
       
   581     iMdsDbObserver->HandleCreateVideoListResp( iVideoList, KErrNotFound /* KErrNotFound = no new items */,
       
   582             ETrue /* complete */);
       
   583     
       
   584     iVideoList = NULL; // not owned by us -> just clear
       
   585     }
       
   586 
       
   587 // ---------------------------------------------------------------------------
       
   588 // CVcxMyVideosMdsDb::CreateVideoL
       
   589 // ---------------------------------------------------------------------------
       
   590 //
       
   591 CMPXMedia* CVcxMyVideosMdsDb::CreateVideoL( TUint32 aId, TBool aFullDetails )
       
   592     {
       
   593     MPX_FUNC( "CVcxMyVideosMdsDb::CreateVideoL" );
       
   594 
       
   595     CMdEObject* object = ObjectL( aId );
       
   596 
       
   597     CMPXMedia* video = NULL;
       
   598 
       
   599     if ( object )
       
   600         {
       
   601         CleanupStack::PushL( object ); // 1->
       
   602 
       
   603         video = CMPXMedia::NewL( );
       
   604         CleanupStack::PushL( video ); // 2->
       
   605 
       
   606         Object2MediaL( *object, *video, aFullDetails );
       
   607 
       
   608         CleanupStack::Pop( video );            // <-2
       
   609         CleanupStack::PopAndDestroy( object ); // <-1
       
   610         }
       
   611 
       
   612     return video;
       
   613     }
       
   614 
       
   615 // ---------------------------------------------------------------------------
       
   616 // From class MMdESessionObserver.
       
   617 // ---------------------------------------------------------------------------
       
   618 //
       
   619 void CVcxMyVideosMdsDb::HandleSessionOpened(
       
   620         CMdESession& /*aSession*/,
       
   621         TInt aError)
       
   622     {
       
   623     MPX_FUNC( "CVcxMyVideosMdsDb::HandleSessionOpened" );
       
   624 
       
   625     iActiveSchedulerWait->AsyncStop();
       
   626 
       
   627     if ( aError != KErrNone )
       
   628         {
       
   629         MPX_DEBUG2( "CVcxMyVideosMdsDb::HandleSessionOpened: %d", aError );
       
   630 
       
   631         iMDSError = aError;
       
   632         delete iMDSSession;
       
   633         iMDSSession = NULL;
       
   634         }
       
   635     }
       
   636 
       
   637 // ---------------------------------------------------------------------------
       
   638 // From class MMdESessionObserver.
       
   639 // ---------------------------------------------------------------------------
       
   640 //
       
   641 void CVcxMyVideosMdsDb::HandleSessionError(
       
   642         CMdESession& /*aSession*/,
       
   643         TInt aError)
       
   644     {
       
   645     MPX_FUNC( "CVcxMyVideosMdsDb::HandleSessionError" );
       
   646 
       
   647     if (iActiveSchedulerWait->IsStarted())
       
   648         {
       
   649         MPX_DEBUG1( "CVcxMyVideosMdsDb:: Session opening was going on");
       
   650         iActiveSchedulerWait->AsyncStop();
       
   651         }
       
   652 
       
   653     if ( iVideoListFetchingIsOngoing )
       
   654         {
       
   655         MPX_DEBUG1( "CVcxMyVideosMdsDb:: Videolist fetching was going on");
       
   656         iVideoListFetchingIsOngoing = EFalse;
       
   657 //        delete iVideoQuery;
       
   658 //        iVideoQuery = NULL;
       
   659         iMdsDbObserver->HandleCreateVideoListResp( iVideoList, -1 /* -1 = no new items */,
       
   660                 ETrue /* complete */);
       
   661         }
       
   662         
       
   663     MPX_DEBUG2( "CVcxMyVideosMdsDb::HandleSessionError: %d", aError );
       
   664 
       
   665     iMDSError = aError;
       
   666     delete iMDSSession;
       
   667     iMDSSession = NULL;
       
   668     }
       
   669 
       
   670 // ---------------------------------------------------------------------------
       
   671 // CVcxMyVideosMdsDb::HandleObjectNotification
       
   672 // ---------------------------------------------------------------------------
       
   673 //
       
   674 void CVcxMyVideosMdsDb::HandleObjectNotification(
       
   675         CMdESession& /*aSession*/,
       
   676         TObserverNotificationType aType,
       
   677         const RArray<TItemId>& aObjectIdArray)
       
   678     {
       
   679     TRAP( iMDSError, DoHandleObjectNotificationL( aType, aObjectIdArray ));
       
   680     }
       
   681     
       
   682 // ---------------------------------------------------------------------------
       
   683 // CVcxMyVideosMdsDb::ObjectL
       
   684 // ---------------------------------------------------------------------------
       
   685 //
       
   686 CMdEObject* CVcxMyVideosMdsDb::ObjectL( const TItemId aId )
       
   687     {
       
   688     if ( !iMDSSession )
       
   689         {
       
   690         MPX_DEBUG2("CVcxMyVideosMdsDb:: no mds session(%d), leaving", iMDSError);
       
   691         User::Leave( iMDSError );
       
   692         }
       
   693 
       
   694     //  If the id is not valid, just return NULL, because
       
   695     //  iMDSSession->GetObjectL leaves in that case
       
   696     if ( aId == KNoId )
       
   697         {
       
   698         return NULL;
       
   699         }
       
   700 
       
   701     CMdEObject* object = iMDSSession->GetObjectL( aId, *iVideoObjectDef );
       
   702 
       
   703     if ( object )
       
   704         {
       
   705         MPX_DEBUG2( "CVcxMyVideosMdsDb::ObjectL found, id: %d", aId );
       
   706         }
       
   707     else
       
   708         {
       
   709         MPX_DEBUG2( "CVcxMyVideosMdsDb::ObjectL not found, id: %d", aId );
       
   710         }
       
   711 
       
   712     return object;
       
   713     }
       
   714 
       
   715 // ---------------------------------------------------------------------------
       
   716 // CVcxMyVideosMdsDb::Object2MediaL
       
   717 // ---------------------------------------------------------------------------
       
   718 //
       
   719 void CVcxMyVideosMdsDb::Object2MediaL(
       
   720         CMdEObject& aObject,
       
   721         CMPXMedia& aVideo,
       
   722         TBool aFullDetails )
       
   723     {    
       
   724     aVideo.SetTObjectValueL<TMPXGeneralType>(KMPXMediaGeneralType, EMPXItem );
       
   725    
       
   726     CMdEProperty* property = NULL;
       
   727 
       
   728     //1. ID, KMPXMediaGeneralId (BRIEF)
       
   729     TMPXItemId mpxId;
       
   730     mpxId.iId1 = aObject.Id();
       
   731     aVideo.SetTObjectValueL<TMPXItemId>( KMPXMediaGeneralId, mpxId );
       
   732     
       
   733     //2. TITLE (BRIEF)
       
   734     if ( aObject.Property( *iTitlePropertyDef, property, 0 ) != KErrNotFound )
       
   735         {
       
   736         aVideo.SetTextValueL( KMPXMediaGeneralTitle,
       
   737                 static_cast<CMdETextProperty*>(property)->Value());
       
   738         }
       
   739 
       
   740     //  This is a fix for setting the title always
       
   741     if ( !property || static_cast<CMdETextProperty*>(property)->Value().Length() == 0 )
       
   742         {
       
   743         TEntry entry;
       
   744         TParse parse;
       
   745 
       
   746         if ( iFs.Entry( aObject.Uri(), entry ) == KErrNone )
       
   747             {
       
   748             parse.Set( entry.iName, NULL, NULL );
       
   749             }
       
   750         else
       
   751             {
       
   752             parse.Set( aObject.Uri(), NULL, NULL );
       
   753             }
       
   754         aVideo.SetTextValueL( KMPXMediaGeneralTitle,
       
   755                 parse.Name());        
       
   756         }
       
   757 
       
   758     //3. DESCRIPTION
       
   759     if ( aObject.Property( *iDescriptionPropertyDef, property, 0 ) != KErrNotFound
       
   760          && aFullDetails )
       
   761         {
       
   762         aVideo.SetTextValueL( KMPXMediaGeneralComment,
       
   763                 static_cast<CMdETextProperty*>(property)->Value() );
       
   764         }
       
   765 
       
   766     //4. URI (= FILE PATH) (BRIEF)
       
   767     aVideo.SetTextValueL( KMPXMediaGeneralUri, aObject.Uri() );
       
   768    
       
   769     //5. FILE SIZE, KMPXMediaGeneralSize (BRIEF)    
       
   770     // With 64bit support the value will be copied after reading KMPXMediaGeneralExtSizeInt64
       
   771 #ifndef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
       
   772     if (KErrNotFound !=
       
   773             aObject.Property( *iSizePropertyDef, property, 0 ))
       
   774         {
       
   775         aVideo.SetTObjectValueL<TInt>( KMPXMediaGeneralSize,
       
   776                 static_cast<CMdEUint32Property*>(property)->Value() );
       
   777         }
       
   778         
       
   779     //  If the size was not found or it is 0, get it from the file
       
   780     if ( !(aVideo.Value<TInt>( KMPXMediaGeneralSize )) )
       
   781         {
       
   782         TEntry entry;
       
   783         TInt err = iFs.Entry( aObject.Uri(), entry );
       
   784         if ( err == KErrNone )
       
   785             {
       
   786             aVideo.SetTObjectValueL<TInt>( KMPXMediaGeneralSize, entry.iSize );
       
   787             }
       
   788         }
       
   789 #endif // SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
       
   790     
       
   791     //6. CREATION DATE, KMPXMediaGeneralDate
       
   792     if ( aObject.Property( *iCreationDatePropertyDef, property, 0 ) != KErrNotFound )
       
   793         {
       
   794         aVideo.SetTObjectValueL<TInt64>( KMPXMediaGeneralDate,
       
   795                 static_cast<CMdETimeProperty*>(property)->Value().Int64() );
       
   796         }
       
   797     
       
   798     //7. FLAGS, KMPXMediaGeneralFlags (BRIEF)
       
   799     TUint32 flags = 0;
       
   800     if ( aObject.Property( *iFlagsPropertyDef, property, 0 ) != KErrNotFound )
       
   801         {
       
   802         flags = static_cast<CMdEUint32Property*>(property)->Value();
       
   803         }
       
   804     else
       
   805         {
       
   806         // MDS didn't have flags variable set at all, so this is harvested video.
       
   807         // Set new flag on.
       
   808         flags |= EVcxMyVideosVideoNew;
       
   809         }
       
   810     if ( aObject.Property( *iDrmPropertyDef, property, 0 ) != KErrNotFound )
       
   811         {
       
   812         TBool drmProtected = static_cast<CMdEBoolProperty*>(property)->Value();
       
   813         if ( drmProtected )
       
   814             {
       
   815             flags |= EVcxMyVideosVideoDrmProtected;
       
   816             }
       
   817         }
       
   818     aVideo.SetTObjectValueL<TUint32>( KMPXMediaGeneralFlags, flags );
       
   819   
       
   820     //8. COPYRIGHT, KMPXMediaGeneralCopyright
       
   821     if ( aObject.Property( *iCopyrightPropertyDef, property, 0 ) != KErrNotFound 
       
   822          && aFullDetails )
       
   823         {
       
   824         aVideo.SetTextValueL( KMPXMediaGeneralCopyright,
       
   825                 static_cast<CMdETextProperty*>(property)->Value() );
       
   826         }
       
   827     
       
   828     //9. KMPXMediaGeneralMimeType
       
   829     if ( aObject.Property( *iItemTypePropertyDef, property, 0 ) != KErrNotFound 
       
   830          && aFullDetails )
       
   831         {
       
   832         aVideo.SetTextValueL( KMPXMediaGeneralMimeType,
       
   833                 static_cast<CMdETextProperty*>(property)->Value() );
       
   834         }
       
   835     
       
   836     //11. FILE SIZE, KMPXMediaGeneralExtSizeInt64 (BRIEF)    
       
   837 #ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
       
   838     if (KErrNotFound !=
       
   839             aObject.Property( *iSizePropertyDef, property, 0 ))
       
   840         {
       
   841         TUint32 val = static_cast<CMdEUint32Property*>(property)->Value(); 
       
   842         aVideo.SetTObjectValueL<TInt64>( KMPXMediaGeneralExtSizeInt64, val );
       
   843         // Maintains compatibility
       
   844         aVideo.SetTObjectValueL<TInt>( KMPXMediaGeneralSize, val );
       
   845         }
       
   846         
       
   847     //  If the size was not found or it is 0, get it from the file
       
   848     if ( !(aVideo.Value<TInt64>( KMPXMediaGeneralExtSizeInt64 )) )
       
   849         {
       
   850         TEntry entry;
       
   851         TInt err = iFs.Entry( aObject.Uri(), entry );
       
   852         if ( err == KErrNone )
       
   853             {
       
   854             aVideo.SetTObjectValueL<TInt64>( KMPXMediaGeneralExtSizeInt64, entry.FileSize() );
       
   855             // Maintains compatibility
       
   856             aVideo.SetTObjectValueL<TInt>( KMPXMediaGeneralSize, entry.iSize );
       
   857             }
       
   858         }
       
   859 #endif // SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
       
   860 
       
   861     //12. KVcxMediaMyVideosModifiedDate
       
   862     if ( aObject.Property( *iLastModifiedDatePropertyDef, property, 0 ) != KErrNotFound 
       
   863         && aFullDetails )
       
   864         {
       
   865         aVideo.SetTObjectValueL<TInt64>( KVcxMediaMyVideosModifiedDate,
       
   866                 static_cast<CMdETimeProperty*>(property)->Value().Int64() );
       
   867         }
       
   868     
       
   869     //13. KVcxMediaMyVideosAgeProfile (BRIEF)
       
   870     if ( aObject.Property( *iAgeProfilePropertyDef, property, 0 ) != KErrNotFound )
       
   871         {
       
   872         aVideo.SetTObjectValueL<TInt32>( KVcxMediaMyVideosAgeProfile,
       
   873             static_cast<CMdEInt32Property*>(property)->Value() );
       
   874         }
       
   875         
       
   876     //14. KVcxMediaMyVideosAudioLanguage
       
   877     if ( aObject.Property( *iAudioLanguagePropertyDef, property, 0 ) != KErrNotFound
       
   878          && aFullDetails )
       
   879         {
       
   880         aVideo.SetTextValueL( KVcxMediaMyVideosAudioLanguage,
       
   881                 static_cast<CMdETextProperty*>(property)->Value() );
       
   882         }
       
   883     
       
   884     //15. AUTHOR, KVcxMediaMyVideosAuthor
       
   885     if ( aObject.Property( *iAuthorPropertyDef, property, 0 ) != KErrNotFound
       
   886          && aFullDetails )
       
   887         {
       
   888         aVideo.SetTextValueL( KVcxMediaMyVideosAuthor,
       
   889                 static_cast<CMdETextProperty*>(property)->Value() );
       
   890         }
       
   891 
       
   892     //16. ORIGIN, KVcxMediaMyVideosOrigin
       
   893     if ( aObject.Property( *iOriginPropertyDef, property, 0 ) != KErrNotFound )
       
   894         {
       
   895         aVideo.SetTObjectValueL<TUint8>( KVcxMediaMyVideosOrigin,
       
   896                 static_cast<CMdEUint8Property*>(property)->Value() );
       
   897         }
       
   898 
       
   899     //17. DURATION, (KMPXMediaGeneralDuration can't be used since it is TInt
       
   900     //   and we need TReal32 ) (BRIEF)
       
   901     if ( aObject.Property( *iDurationPropertyDef, property, 0 ) != KErrNotFound )
       
   902         {        
       
   903         aVideo.SetTObjectValueL<TReal32>( KVcxMediaMyVideosDuration,
       
   904                 static_cast<CMdEReal32Property*>(property)->Value() );
       
   905         }
       
   906 
       
   907     //10. LAST PLAYBACK POSITION
       
   908     // KMPXMediaGeneralLastPlaybackPosition
       
   909     if ( aObject.Property( *iLastPlayPositionPropertyDef, property, 0 ) != KErrNotFound
       
   910          && aFullDetails )
       
   911         {        
       
   912         TInt pos = static_cast<CMdEReal32Property*>(property)->Value();
       
   913         
       
   914         aVideo.SetTObjectValueL<TInt>( KMPXMediaGeneralLastPlaybackPosition, pos );
       
   915         }
       
   916 
       
   917     //18. DOWNLOAD ID (BRIEF)
       
   918     if ( aObject.Property( *iDownloadIdPropertyDef, property, 0 ) != KErrNotFound )
       
   919         {
       
   920         aVideo.SetTObjectValueL<TUint32>( KVcxMediaMyVideosDownloadId,
       
   921                 static_cast<CMdEUint32Property*>(property)->Value() );
       
   922         }
       
   923     else
       
   924         {
       
   925         aVideo.SetTObjectValueL<TUint32>( KVcxMediaMyVideosDownloadId, 0 );
       
   926         }
       
   927 
       
   928     //19. RATING (FULL)
       
   929     if ( aObject.Property( *iRatingPropertyDef, property, 0 ) != KErrNotFound
       
   930             && aFullDetails )
       
   931         {
       
   932         aVideo.SetTObjectValueL<TUint8>( KVcxMediaMyVideosRating,
       
   933                 static_cast<CMdEUint8Property*>(property)->Value() );
       
   934         }
       
   935     else
       
   936         {
       
   937         aVideo.SetTObjectValueL<TUint8>( KVcxMediaMyVideosRating, 0 );
       
   938         }
       
   939     
       
   940     //20. BITRATE (FULL)
       
   941     if ( aObject.Property( *iBitratePropertyDef, property, 0 ) != KErrNotFound
       
   942             && aFullDetails )
       
   943         {
       
   944         TUint16 bitrate = static_cast<CMdEUint16Property*>(property)->Value();        
       
   945         aVideo.SetTObjectValueL<TUint16>( KMPXMediaVideoBitRate, bitrate );
       
   946         }    
       
   947 
       
   948     //21. AUDIOFOURCC (BRIEF)
       
   949     if ( aObject.Property( *iAudioFourCcPropertyDef, property, 0 ) != KErrNotFound )
       
   950         {
       
   951         aVideo.SetTObjectValueL<TUint32>( KVcxMediaMyVideosAudioFourCc,
       
   952                 static_cast<CMdEUint32Property*>(property)->Value() );
       
   953         }
       
   954     else
       
   955         {
       
   956         aVideo.SetTObjectValueL<TUint32>( KVcxMediaMyVideosAudioFourCc, 0 );
       
   957         }
       
   958     
       
   959     //22. WIDTH (FULL)
       
   960     if ( aObject.Property( *iWidthPropertyDef, property, 0 ) != KErrNotFound
       
   961             && aFullDetails )
       
   962         {    
       
   963         aVideo.SetTObjectValueL<TUint16>( KMPXMediaVideoWidth,
       
   964                 static_cast<CMdEUint16Property*>(property)->Value() );
       
   965         }    
       
   966     
       
   967     //23. Height (FULL)
       
   968     if ( aObject.Property( *iHeightPropertyDef, property, 0 ) != KErrNotFound
       
   969             && aFullDetails )
       
   970         {    
       
   971         aVideo.SetTObjectValueL<TUint16>( KMPXMediaVideoHeight,
       
   972                 static_cast<CMdEUint16Property*>(property)->Value() );
       
   973         }    
       
   974     
       
   975     //24. ARTIST (FULL)
       
   976    if ( aObject.Property( *iArtistPropertyDef, property, 0 ) != KErrNotFound
       
   977            && aFullDetails )
       
   978        {
       
   979        aVideo.SetTextValueL( KMPXMediaVideoArtist,
       
   980                static_cast<CMdETextProperty*>(property)->Value());
       
   981        }
       
   982 
       
   983     }
       
   984 
       
   985 // ---------------------------------------------------------------------------
       
   986 // CVcxMyVideosMdsDb::Media2ObjectL
       
   987 // Called by AddVideoL()
       
   988 // ---------------------------------------------------------------------------
       
   989 //
       
   990 void CVcxMyVideosMdsDb::Media2ObjectL(
       
   991         CMPXMedia& aVideo,
       
   992         CMdEObject& aObject)
       
   993     {
       
   994     CMdEProperty* property;
       
   995 
       
   996     // 1. MDS ID
       
   997     
       
   998     // 2. TITLE (NAME)
       
   999     if ( aVideo.IsSupported( KMPXMediaGeneralTitle ) )
       
  1000         {
       
  1001         if ( aObject.Property( *iTitlePropertyDef, property, 0 ) != KErrNotFound )
       
  1002             {
       
  1003             static_cast<CMdETextProperty*>(property)->SetValueL(
       
  1004                     aVideo.ValueText( KMPXMediaGeneralTitle ) );
       
  1005             }
       
  1006         else
       
  1007             {
       
  1008             aObject.AddTextPropertyL(
       
  1009                     *iTitlePropertyDef, aVideo.ValueText( KMPXMediaGeneralTitle ) );
       
  1010             }
       
  1011         }
       
  1012         
       
  1013     // 3. DESC
       
  1014     if ( aVideo.IsSupported( KMPXMediaGeneralComment ) )
       
  1015         {
       
  1016         if ( aObject.Property( *iDescriptionPropertyDef, property, 0 ) != KErrNotFound )
       
  1017             {
       
  1018             static_cast<CMdETextProperty*>(property)->SetValueL(
       
  1019                     aVideo.ValueText( KMPXMediaGeneralComment ) );
       
  1020             }
       
  1021         else
       
  1022             {
       
  1023             aObject.AddTextPropertyL(
       
  1024                     *iDescriptionPropertyDef, aVideo.ValueText( KMPXMediaGeneralComment ) );
       
  1025             }
       
  1026         }
       
  1027 
       
  1028     // 4. URI ( = file path )
       
  1029     if ( aVideo.IsSupported( KMPXMediaGeneralUri ) )
       
  1030         {
       
  1031         aObject.SetUriL( aVideo.ValueText( KMPXMediaGeneralUri ) );
       
  1032         TVolumeInfo volInfo;
       
  1033         // 4.1 MEDIA ID ( = drive number )
       
  1034         if ( iFs.Volume( volInfo, TVcxMyVideosCollectionUtil::DriveLetter2DriveNumber(
       
  1035                 aObject.Uri() ) ) == KErrNone)
       
  1036             {
       
  1037             aObject.SetMediaId( volInfo.iUniqueID );
       
  1038             }
       
  1039         }
       
  1040 
       
  1041     // 5. With 64bit support KMPXMediaGeneralSize is not used, see KMPXMediaGeneralExtSizeInt64
       
  1042 #ifndef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
       
  1043     if ( aVideo.IsSupported( KMPXMediaGeneralSize ) )
       
  1044         {
       
  1045         TUint32 size = 0;
       
  1046         TInt sizeInMediaObject = aVideo.ValueTObjectL<TInt>( KMPXMediaGeneralSize );
       
  1047         size = static_cast<TUint32>( sizeInMediaObject );
       
  1048 
       
  1049         if ( aObject.Property( *iSizePropertyDef, property, 0 ) != KErrNotFound )
       
  1050             {
       
  1051             static_cast<CMdEUint32Property*>( property )->SetValueL( size );
       
  1052             }
       
  1053         else
       
  1054             {
       
  1055             aObject.AddUint32PropertyL( *iSizePropertyDef, size );
       
  1056             }
       
  1057         }
       
  1058 #endif // SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
       
  1059 
       
  1060 #if 0    
       
  1061     // 6. KMPXMediaGeneralDate ( creation date )
       
  1062     if ( aVideo.IsSupported( KMPXMediaGeneralDate ) )
       
  1063         {
       
  1064         TInt64 creationDateInt64 = 0;
       
  1065         creationDateInt64 = aVideo.ValueTObjectL<TInt64>( KMPXMediaGeneralDate );
       
  1066         TTime creationDate( creationDateInt64 );
       
  1067         if ( aObject.Property( *iCreationDatePropertyDef, property, 0 ) != KErrNotFound )
       
  1068             {
       
  1069             static_cast<CMdETimeProperty*>(property)->SetValueL( creationDate );
       
  1070             }
       
  1071         else
       
  1072             {
       
  1073             aObject.AddTimePropertyL( *iCreationDatePropertyDef, creationDate );
       
  1074             }
       
  1075         }
       
  1076 #endif
       
  1077     
       
  1078     // 7. KMPXMediaGeneralFlags (including DRM flag)
       
  1079     if ( aVideo.IsSupported( KMPXMediaGeneralFlags ) )
       
  1080         {
       
  1081         TUint32 flags = aVideo.ValueTObjectL<TUint32>( KMPXMediaGeneralFlags );
       
  1082         if ( aObject.Property( *iFlagsPropertyDef, property, 0 ) != KErrNotFound )
       
  1083             {
       
  1084             static_cast<CMdEUint32Property*>(property)->SetValueL( flags );
       
  1085             }
       
  1086         else
       
  1087             {
       
  1088             aObject.AddUint32PropertyL( *iFlagsPropertyDef, flags );
       
  1089             }
       
  1090 
       
  1091         TBool drmProtected;
       
  1092         if ( flags & EVcxMyVideosVideoDrmProtected )
       
  1093             {
       
  1094             drmProtected = ETrue;
       
  1095             }
       
  1096         else
       
  1097             {
       
  1098             drmProtected = EFalse;
       
  1099             }
       
  1100             
       
  1101         if ( aObject.Property( *iDrmPropertyDef, property, 0 ) != KErrNotFound )
       
  1102             {
       
  1103             static_cast<CMdEBoolProperty*>(property)->SetValueL( drmProtected );
       
  1104             }
       
  1105         else
       
  1106             {
       
  1107             aObject.AddBoolPropertyL( *iDrmPropertyDef, drmProtected );
       
  1108             }
       
  1109         }
       
  1110 
       
  1111     // 8. KMPXMediaGeneralCopyright
       
  1112     if ( aVideo.IsSupported( KMPXMediaGeneralCopyright ))
       
  1113         {
       
  1114         if ( aObject.Property( *iCopyrightPropertyDef, property, 0 ) != KErrNotFound )
       
  1115             {
       
  1116             static_cast<CMdETextProperty*>(property)->SetValueL(
       
  1117                     aVideo.ValueText( KMPXMediaGeneralCopyright ) );
       
  1118             }
       
  1119         else
       
  1120             {
       
  1121             if ( aVideo.ValueText( KMPXMediaGeneralCopyright ).Length() )
       
  1122                 {
       
  1123                 aObject.AddTextPropertyL(
       
  1124                         *iCopyrightPropertyDef,
       
  1125                         aVideo.ValueText( KMPXMediaGeneralCopyright ) );
       
  1126                 }
       
  1127             }
       
  1128         }
       
  1129 
       
  1130 #if 0
       
  1131     // 9. KMPXMediaGeneralMimeType
       
  1132     if ( aVideo.IsSupported( KMPXMediaGeneralMimeType ))
       
  1133         {
       
  1134         if ( aObject.Property( *iItemTypePropertyDef, property, 0 ) != KErrNotFound )
       
  1135             {
       
  1136             static_cast<CMdETextProperty*>(property)->SetValueL(
       
  1137                     aVideo.ValueText( KMPXMediaGeneralMimeType ) );
       
  1138             }
       
  1139         else
       
  1140             {
       
  1141             aObject.AddTextPropertyL(
       
  1142                     *iItemTypePropertyDef,
       
  1143                     aVideo.ValueText( KMPXMediaGeneralMimeType ) );
       
  1144             }
       
  1145         }
       
  1146 #endif
       
  1147 
       
  1148     // 11. KMPXMediaGeneralExtSizeInt64
       
  1149 #ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
       
  1150     if ( aVideo.IsSupported( KMPXMediaGeneralExtSizeInt64 ) )
       
  1151         {
       
  1152         TUint32 size = 0;
       
  1153         TInt64 sizeInMediaObject = aVideo.ValueTObjectL<TInt64>( KMPXMediaGeneralExtSizeInt64 );
       
  1154         size = static_cast<TUint32>( sizeInMediaObject );
       
  1155 
       
  1156         if ( aObject.Property( *iSizePropertyDef, property, 0 ) != KErrNotFound )
       
  1157             {
       
  1158             static_cast<CMdEUint32Property*>( property )->SetValueL( size );
       
  1159             }
       
  1160         else
       
  1161             {
       
  1162             aObject.AddUint32PropertyL( *iSizePropertyDef, size );
       
  1163             }
       
  1164         }
       
  1165 #endif // SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
       
  1166     
       
  1167     // 12. KVcxMediaMyVideosModifiedDate
       
  1168     if ( aVideo.IsSupported( KVcxMediaMyVideosModifiedDate ) )
       
  1169         {
       
  1170         TInt64 modifiedDateInt64 = aVideo.ValueTObjectL<TInt64>( KVcxMediaMyVideosModifiedDate );
       
  1171         TTime modifiedDate( modifiedDateInt64 );
       
  1172         if ( aObject.Property( *iLastModifiedDatePropertyDef, property, 0 ) != KErrNotFound )
       
  1173             {
       
  1174             static_cast<CMdETimeProperty*>(property)->SetValueL( modifiedDate );
       
  1175             }
       
  1176         else
       
  1177             {
       
  1178             aObject.AddTimePropertyL( *iLastModifiedDatePropertyDef, modifiedDate );
       
  1179             }
       
  1180         }
       
  1181             
       
  1182     // 13. KVcxMediaMyVideosAgeProfile
       
  1183     if ( aVideo.IsSupported( KVcxMediaMyVideosAgeProfile ) )
       
  1184         {
       
  1185         TInt32 ageProfile = aVideo.ValueTObjectL<TInt32>(KVcxMediaMyVideosAgeProfile );
       
  1186         if ( aObject.Property( *iAgeProfilePropertyDef, property, 0 ) != KErrNotFound )
       
  1187             {
       
  1188             static_cast<CMdEInt32Property*>(property)->SetValueL( ageProfile );
       
  1189             }
       
  1190         else
       
  1191             {
       
  1192             aObject.AddInt32PropertyL( *iAgeProfilePropertyDef, ageProfile );
       
  1193             }
       
  1194         }
       
  1195             
       
  1196     // 14. KVcxMediaMyVideosAudioLanguage
       
  1197     if ( aVideo.IsSupported( KVcxMediaMyVideosAudioLanguage ) )
       
  1198         {
       
  1199         if ( aObject.Property( *iAudioLanguagePropertyDef, property, 0 ) != KErrNotFound )
       
  1200             {
       
  1201             static_cast<CMdETextProperty*>(property)->SetValueL(
       
  1202                     aVideo.ValueText( KVcxMediaMyVideosAudioLanguage ) );
       
  1203             }
       
  1204         else
       
  1205             {
       
  1206             aObject.AddTextPropertyL(
       
  1207                     *iAudioLanguagePropertyDef,
       
  1208                     aVideo.ValueText( KVcxMediaMyVideosAudioLanguage ) );
       
  1209             }
       
  1210         }
       
  1211         
       
  1212     // 15. KVcxMediaMyVideosAuthor
       
  1213     if ( aVideo.IsSupported( KVcxMediaMyVideosAuthor ) )
       
  1214         {
       
  1215         if ( aObject.Property( *iAuthorPropertyDef, property, 0 ) != KErrNotFound )
       
  1216             {
       
  1217             static_cast<CMdETextProperty*>(property)->SetValueL(
       
  1218                     aVideo.ValueText( KVcxMediaMyVideosAuthor ) );
       
  1219             }
       
  1220         else
       
  1221             {
       
  1222             aObject.AddTextPropertyL(
       
  1223                     *iAuthorPropertyDef,
       
  1224                     aVideo.ValueText( KVcxMediaMyVideosAuthor ) );
       
  1225             }
       
  1226         }
       
  1227         
       
  1228     // 16. KVcxMediaMyVideosOrigin
       
  1229     if ( aVideo.IsSupported( KVcxMediaMyVideosOrigin ) )
       
  1230         {
       
  1231         TUint8 origin = aVideo.ValueTObjectL<TUint8>( KVcxMediaMyVideosOrigin );
       
  1232         if ( aObject.Property( *iOriginPropertyDef, property, 0 ) != KErrNotFound )
       
  1233             {
       
  1234             static_cast<CMdEUint8Property*>(property)->SetValueL( origin );
       
  1235             }
       
  1236         else
       
  1237             {
       
  1238             aObject.AddUint8PropertyL( *iOriginPropertyDef, origin );
       
  1239             }
       
  1240         }
       
  1241     
       
  1242     // 17. KVcxMediaMyVideosDuration
       
  1243     if ( aVideo.IsSupported( KVcxMediaMyVideosDuration ))
       
  1244         {        
       
  1245         TReal32 duration = aVideo.ValueTObjectL<TReal32>( KVcxMediaMyVideosDuration );
       
  1246 
       
  1247         if ( aObject.Property( *iDurationPropertyDef, property, 0 ) != KErrNotFound )
       
  1248             {
       
  1249             static_cast<CMdEReal32Property*>(property)->SetValueL( duration );
       
  1250             }
       
  1251         else
       
  1252             {
       
  1253             aObject.AddReal32PropertyL( *iDurationPropertyDef, duration );
       
  1254             }
       
  1255         }
       
  1256 
       
  1257     // 10. KMPXMediaGeneralLastPlaybackPosition
       
  1258     if ( aVideo.IsSupported( KMPXMediaGeneralLastPlaybackPosition ))
       
  1259         {        
       
  1260         TReal32 lastPlaybackPos = aVideo.ValueTObjectL<TInt>(
       
  1261                         KMPXMediaGeneralLastPlaybackPosition );
       
  1262         
       
  1263         // Play pos is written only after playback. Reset new video flag
       
  1264         // now, so there's no need for changing the flag explitically
       
  1265         if ( aObject.Property( *iFlagsPropertyDef, property, 0 ) != KErrNotFound )
       
  1266             {
       
  1267             TUint32 flags = static_cast<CMdEUint32Property*>(property)->Value();
       
  1268             
       
  1269             flags &= ~EVcxMyVideosVideoNew;
       
  1270             
       
  1271             static_cast<CMdEUint32Property*>(property)->SetValueL( flags );
       
  1272             }
       
  1273         
       
  1274         if ( aObject.Property( *iLastPlayPositionPropertyDef, property, 0 ) != KErrNotFound )
       
  1275             {
       
  1276             static_cast<CMdEReal32Property*>(property)->SetValueL( lastPlaybackPos );
       
  1277             }
       
  1278         else
       
  1279             {
       
  1280             aObject.AddReal32PropertyL( *iLastPlayPositionPropertyDef, lastPlaybackPos );
       
  1281             }
       
  1282         }
       
  1283     
       
  1284     // 18. DOWNLOAD ID
       
  1285     if ( aVideo.IsSupported( KVcxMediaMyVideosDownloadId ) )
       
  1286         {
       
  1287         TUint32 dlId = aVideo.ValueTObjectL<TUint32>( KVcxMediaMyVideosDownloadId );
       
  1288         
       
  1289         if ( aObject.Property( *iDownloadIdPropertyDef, property, 0 ) != KErrNotFound )
       
  1290             {
       
  1291             static_cast<CMdEUint32Property*>(property)->SetValueL( dlId );
       
  1292             }
       
  1293         else
       
  1294             {
       
  1295             aObject.AddUint32PropertyL( *iDownloadIdPropertyDef, dlId );
       
  1296             }
       
  1297         }
       
  1298 
       
  1299     // 19. RATING
       
  1300     if ( aVideo.IsSupported( KVcxMediaMyVideosRating ) )
       
  1301         {
       
  1302         TUint8 rating = aVideo.ValueTObjectL<TUint8>( KVcxMediaMyVideosRating );
       
  1303         
       
  1304         if ( aObject.Property( *iRatingPropertyDef, property, 0 ) != KErrNotFound )
       
  1305             {
       
  1306             static_cast<CMdEUint8Property*>(property)->SetValueL( rating );
       
  1307             }
       
  1308         else
       
  1309             {
       
  1310             aObject.AddUint8PropertyL( *iRatingPropertyDef, rating );
       
  1311             }
       
  1312         }
       
  1313     // 20. BITRATE
       
  1314     if ( aVideo.IsSupported( KMPXMediaVideoBitRate ) )
       
  1315         {           
       
  1316         TUint16 bitrate = aVideo.ValueTObjectL<TUint16>( KMPXMediaVideoBitRate );
       
  1317         
       
  1318         if ( aObject.Property( *iBitratePropertyDef, property, 0 ) != KErrNotFound )
       
  1319             {
       
  1320             static_cast<CMdEUint16Property*>(property)->SetValueL( bitrate );
       
  1321             }
       
  1322         else
       
  1323             {
       
  1324             aObject.AddUint16PropertyL( *iBitratePropertyDef, bitrate );
       
  1325             }
       
  1326         }
       
  1327 
       
  1328     // 21. AUDIOFOURCC
       
  1329     if ( aVideo.IsSupported( KVcxMediaMyVideosAudioFourCc ) )
       
  1330         {
       
  1331         TUint32 audioFourCc = aVideo.ValueTObjectL<TUint32>( KVcxMediaMyVideosAudioFourCc );
       
  1332         
       
  1333         if ( aObject.Property( *iAudioFourCcPropertyDef, property, 0 ) != KErrNotFound )
       
  1334             {
       
  1335             static_cast<CMdEUint32Property*>(property)->SetValueL( audioFourCc );
       
  1336             }
       
  1337         else
       
  1338             {
       
  1339             aObject.AddUint32PropertyL( *iAudioFourCcPropertyDef, audioFourCc );
       
  1340             }
       
  1341         }
       
  1342     
       
  1343     //22. WIDTH (FULL)
       
  1344     if ( aVideo.IsSupported( KMPXMediaVideoWidth ) )
       
  1345        {
       
  1346        TUint16 width = aVideo.ValueTObjectL<TUint16>( KMPXMediaVideoWidth );
       
  1347        
       
  1348        if ( aObject.Property( *iWidthPropertyDef, property, 0 ) != KErrNotFound )
       
  1349            {
       
  1350            static_cast<CMdEUint16Property*>(property)->SetValueL( width );
       
  1351            }
       
  1352        else
       
  1353            {
       
  1354            aObject.AddUint16PropertyL( *iWidthPropertyDef, width );
       
  1355            }
       
  1356        }
       
  1357         
       
  1358     //23. Height (FULL)
       
  1359     if ( aVideo.IsSupported( KMPXMediaVideoHeight ) )
       
  1360        {
       
  1361        TUint16 width = aVideo.ValueTObjectL<TUint16>( KMPXMediaVideoHeight );
       
  1362        
       
  1363        if ( aObject.Property( *iHeightPropertyDef, property, 0 ) != KErrNotFound )
       
  1364            {
       
  1365            static_cast<CMdEUint16Property*>(property)->SetValueL( width );
       
  1366            }
       
  1367        else
       
  1368            {
       
  1369            aObject.AddUint16PropertyL( *iHeightPropertyDef, width );
       
  1370            }
       
  1371        }
       
  1372     
       
  1373     // 24. Artist
       
  1374     if ( aVideo.IsSupported( KMPXMediaVideoArtist ) )
       
  1375         {
       
  1376         if ( aObject.Property( *iArtistPropertyDef, property, 0 ) != KErrNotFound )
       
  1377             {
       
  1378             static_cast<CMdETextProperty*>(property)->SetValueL(
       
  1379                     aVideo.ValueText( KMPXMediaVideoArtist ) );
       
  1380             }
       
  1381         else
       
  1382             {
       
  1383             aObject.AddTextPropertyL(
       
  1384                     *iArtistPropertyDef, aVideo.ValueText( KMPXMediaVideoArtist ) );
       
  1385             }
       
  1386         }
       
  1387     }
       
  1388 
       
  1389 // ---------------------------------------------------------------------------
       
  1390 // CVcxMyVideosMdsDb::GetSchemaDefinitionsL
       
  1391 // ---------------------------------------------------------------------------
       
  1392 //
       
  1393 void CVcxMyVideosMdsDb::GetSchemaDefinitionsL()
       
  1394     {
       
  1395     MPX_FUNC( "CVcxMyVideosMdsDb::GetSchemaDefinitionsL" );
       
  1396 
       
  1397     //  Namespace
       
  1398     iNamespaceDef = &(iMDSSession->GetDefaultNamespaceDefL());
       
  1399     
       
  1400     //  Default object definitions
       
  1401     iVideoObjectDef = &(iNamespaceDef->GetObjectDefL( KVcxVideoObjectName ));
       
  1402 
       
  1403     //  Base object property definitions
       
  1404     iTitlePropertyDef = &(iVideoObjectDef->GetPropertyDefL(
       
  1405             KVcxTitlePropertyName )); //2
       
  1406     iSizePropertyDef = &(iVideoObjectDef->GetPropertyDefL(
       
  1407             KVcxSizePropertyName )); //11 (5 also)
       
  1408     iCreationDatePropertyDef = &(iVideoObjectDef->GetPropertyDefL(
       
  1409             KVcxCreationDatePropertyName )); //6
       
  1410     iTimeOffsetPropertyDef = &(iVideoObjectDef->GetPropertyDefL(
       
  1411             KVcxTimeOffsetPropertyName )); //6
       
  1412     iItemTypePropertyDef = &(iVideoObjectDef->GetPropertyDefL(
       
  1413             KVcxItemTypePropertyName )); //9
       
  1414     iLastModifiedDatePropertyDef = &(iVideoObjectDef->GetPropertyDefL(
       
  1415             KVcxLastModifiedDatePropertyName )); //12
       
  1416 
       
  1417     //  Media object property definitions
       
  1418     iDescriptionPropertyDef = &(iVideoObjectDef->GetPropertyDefL(
       
  1419             KVcxDescriptionPropertyName)); //3
       
  1420     iCopyrightPropertyDef = &(iVideoObjectDef->GetPropertyDefL(
       
  1421             KVcxCopyrightPropertyName )); //8
       
  1422     iAuthorPropertyDef = &(iVideoObjectDef->GetPropertyDefL(
       
  1423             KVcxAuthorPropertyName )); //15
       
  1424     iOriginPropertyDef = &(iVideoObjectDef->GetPropertyDefL(
       
  1425             KVcxOriginPropertyName )); //16
       
  1426     iDurationPropertyDef = &(iVideoObjectDef->GetPropertyDefL(
       
  1427             KVcxDurationPropertyName )); //17
       
  1428     iDrmPropertyDef = &(iVideoObjectDef->GetPropertyDefL(
       
  1429             KVcxDrmPropertyName )); //part of flags (7)
       
  1430     iRatingPropertyDef = &(iVideoObjectDef->GetPropertyDefL(
       
  1431             KVcxRatingPropertyName )); //19
       
  1432     iBitratePropertyDef = &(iVideoObjectDef->GetPropertyDefL(
       
  1433             KVcxBitratePropertyName )); //20
       
  1434     iAudioFourCcPropertyDef = &(iVideoObjectDef->GetPropertyDefL(
       
  1435             KVcxAudioFourCcPropertyName )); //21
       
  1436     iWidthPropertyDef = &(iVideoObjectDef->GetPropertyDefL(
       
  1437             KVcxWidthPropertyName )); //22
       
  1438     iHeightPropertyDef = &(iVideoObjectDef->GetPropertyDefL(
       
  1439             KVcxHeightPropertyName )); //23
       
  1440     iArtistPropertyDef = &(iVideoObjectDef->GetPropertyDefL(
       
  1441                 KVcxArtistPropertyName )); //24
       
  1442 
       
  1443     //  Video object property definitions
       
  1444     iLastPlayPositionPropertyDef = &(iVideoObjectDef->GetPropertyDefL(
       
  1445             KVcxLastPlayPositionPropertyName )); //10
       
  1446 
       
  1447     iFlagsPropertyDef = &(iVideoObjectDef->GetPropertyDefL(
       
  1448             KVcxFlagsPropertyName )); //7
       
  1449 
       
  1450     iAgeProfilePropertyDef = &(iVideoObjectDef->GetPropertyDefL(
       
  1451             KVcxAgeProfilePropertyName )); //13
       
  1452 
       
  1453     iAudioLanguagePropertyDef = &(iVideoObjectDef->GetPropertyDefL(
       
  1454             KVcxAudioLanguagePropertyName )); //14
       
  1455 
       
  1456     iDownloadIdPropertyDef = &(iVideoObjectDef->GetPropertyDefL(
       
  1457             KVcxDownloadIdPropertyName )); //18
       
  1458 
       
  1459     }
       
  1460 
       
  1461 // ---------------------------------------------------------------------------
       
  1462 // CVcxMyVideosMdsDb::DoHandleObjectNotificationL
       
  1463 // ---------------------------------------------------------------------------
       
  1464 //
       
  1465 void CVcxMyVideosMdsDb::DoHandleObjectNotificationL(
       
  1466         TObserverNotificationType aType,
       
  1467         const RArray<TItemId>& aObjectIdArray )
       
  1468     {
       
  1469     MPX_FUNC( "CVcxMyVideosMdsDb::DoHandleObjectNotificationL" );
       
  1470 
       
  1471     if ( iMdsDbObserver )
       
  1472         {
       
  1473         RArray<TUint32> idArray;
       
  1474         CleanupClosePushL( idArray ); // 1->
       
  1475 
       
  1476         for ( TInt i = 0; i < aObjectIdArray.Count(); i++ )
       
  1477             {
       
  1478             idArray.Append( aObjectIdArray[i] );
       
  1479             }
       
  1480             
       
  1481         if ( aType & ENotifyAdd )
       
  1482             {
       
  1483             iMdsDbObserver->HandleMyVideosDbEvent( EMPXItemInserted, idArray );
       
  1484             }        
       
  1485 	    else if ( aType & ENotifyModify )
       
  1486 	        {
       
  1487             iMdsDbObserver->HandleMyVideosDbEvent( EMPXItemModified, idArray );
       
  1488 	        }	    
       
  1489 	    else if ( aType & ENotifyRemove )
       
  1490 	        {
       
  1491             iMdsDbObserver->HandleMyVideosDbEvent( EMPXItemDeleted, idArray );
       
  1492 	        }
       
  1493 
       
  1494         CleanupStack::PopAndDestroy( &idArray ); // <-1
       
  1495         }
       
  1496             
       
  1497     }
       
  1498