mmappcomponents/mmmtpdataprovider/src/cmmmtpdpmetadatavideoaccess.cpp
changeset 0 a2952bb97e68
child 4 d45095c2f4f3
equal deleted inserted replaced
-1:000000000000 0:a2952bb97e68
       
     1 /*
       
     2 * Copyright (c) 2009 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 "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:  Meta data Video access
       
    15 *
       
    16 */
       
    17 
       
    18 #include <ContentListingFactory.h>
       
    19 #include <MCLFContentListingEngine.h>
       
    20 #include <driveinfo.h>
       
    21 #include <pathinfo.h>
       
    22 #include <bautils.h>
       
    23 
       
    24 // from Symbian MTP
       
    25 #include <mtp/tmtptypeuint16.h>
       
    26 #include <mtp/tmtptypeuint32.h>
       
    27 #include <mtp/tmtptypeuint64.h>
       
    28 #include <mtp/tmtptypeuint128.h>
       
    29 #include <mtp/cmtptypestring.h>
       
    30 #include <mtp/cmtptypearray.h>
       
    31 #include <mtp/cmtpobjectmetadata.h>
       
    32 #include <mtp/mmtpdataproviderframework.h>
       
    33 #include <mtp/mmtpreferencemgr.h>
       
    34 #include <mtp/mtpprotocolconstants.h>
       
    35 
       
    36 #include "cmmmtpdpmetadatavideoaccess.h"
       
    37 #include "mmmtpdplogger.h"
       
    38 #include "mmmtpdputility.h"
       
    39 #include "tmmmtpdppanic.h"
       
    40 #include "mmmtpvideodbdefs.h"
       
    41 
       
    42 static const TInt KMtpMaxStringLength = 255;
       
    43 static const TInt KMtpMaxDescriptionLength = 0x200;
       
    44 const TInt KStorageRootMaxLength = 10;
       
    45 
       
    46 #ifdef _DEBUG
       
    47 static const TInt KMtpMaxStringDescLength = KMtpMaxStringLength - 1;
       
    48 #endif
       
    49 
       
    50 _LIT( KEmptyText, "" );
       
    51 // Database interface
       
    52 _LIT( KSelect, "SELECT " );
       
    53 _LIT( KAllColumns, "*" );
       
    54 _LIT( KFrom, " FROM " );
       
    55 _LIT( KWhere, " WHERE " );
       
    56 _LIT( KNot, " NOT " );
       
    57 _LIT( KEquals, " = " );
       
    58 _LIT( KTrue, "1" );
       
    59 
       
    60 const TInt KMaxQueryLength = 512;
       
    61 const TInt KMtpCompactInterval = 50;  // Compact every ....
       
    62 
       
    63 CMmMtpDpMetadataVideoAccess* CMmMtpDpMetadataVideoAccess::NewL( RFs& aRfs )
       
    64     {
       
    65     CMmMtpDpMetadataVideoAccess* me = new(ELeave) CMmMtpDpMetadataVideoAccess( aRfs );
       
    66     CleanupStack::PushL(me);
       
    67     me->ConstructL();
       
    68     CleanupStack::Pop(me);
       
    69 
       
    70     return me;
       
    71     }
       
    72 
       
    73 CMmMtpDpMetadataVideoAccess::CMmMtpDpMetadataVideoAccess( RFs& aRfs ) : iRfs(aRfs),
       
    74                                                     iDbState(ENoRecord),
       
    75                                                     iDbOpened(EFalse)
       
    76     {
       
    77     
       
    78     }
       
    79 
       
    80 // ---------------------------------------------------------------------------
       
    81 // CMmMtpDpMetadataMpxAccess::ConstructL
       
    82 // Second-phase
       
    83 // ---------------------------------------------------------------------------
       
    84 //
       
    85 void CMmMtpDpMetadataVideoAccess::ConstructL()
       
    86     {
       
    87     iQueryText = HBufC::NewL( KMaxQueryLength );
       
    88 
       
    89     User::LeaveIfError( iDbsSession.Connect() );
       
    90 
       
    91     TInt err = DriveInfo::GetDefaultDrive( DriveInfo::EDefaultPhoneMemory,
       
    92         iStoreNum );
       
    93 
       
    94     err = OpenDatabase();
       
    95 
       
    96     if ( KErrNone != err )
       
    97         {
       
    98         PRINT1( _L( "CMmMtpDpMetadataVideoAccess::ConstructL OpenDatabase err = %d" ), err );
       
    99         }
       
   100     }
       
   101 
       
   102 // ---------------------------------------------------------------------------
       
   103 // CMmMtpDpMetadataMpxAccess::OpenDatabase
       
   104 // Open data base
       
   105 // ---------------------------------------------------------------------------
       
   106 //
       
   107 TInt CMmMtpDpMetadataVideoAccess::OpenDatabase()
       
   108     {
       
   109     PRINT( _L( "MM MTP => CMmMtpDpMetadataVideoAccess::OpenDatabase" ) );
       
   110 
       
   111     iRfs.CreatePrivatePath( iStoreNum );
       
   112     TInt err = iRfs.SetSessionToPrivate( iStoreNum );
       
   113 
       
   114     if ( err == KErrNone )
       
   115         {
       
   116         TRAP( err, iFileStore = CPermanentFileStore::OpenL( iRfs, KMtpVideoDb, EFileRead | EFileWrite ) );
       
   117 
       
   118         if ( err == KErrNone )
       
   119             TRAP( err, iFileStore->SetTypeL( iFileStore->Layout() ) );
       
   120 
       
   121         if ( err == KErrNone )
       
   122             {
       
   123             TRAP( err, iDatabase.OpenL( iFileStore, iFileStore->Root() ) );
       
   124             PRINT1( _L( "MM MTP <> OpenDatabase RDbNamedDatabase::OpenL, err = %d" ), err );
       
   125             }
       
   126 
       
   127         if ( err != KErrNone )
       
   128             {
       
   129             iRfs.Delete( KMtpVideoDb );   // delete first before creating a new one
       
   130             TRAP( err, iFileStore = CPermanentFileStore::CreateL( iRfs, KMtpVideoDb, EFileRead | EFileWrite ) );
       
   131             PRINT1( _L( "MM MTP <> OpenDatabase RDbNamedDatabase::CreateL, err = %d" ), err );
       
   132 
       
   133             if ( err == KErrNone )
       
   134                 {
       
   135                 TRAP( err, iFileStore->SetTypeL( iFileStore->Layout() ) );
       
   136 
       
   137                 TStreamId streamId = 0;
       
   138 
       
   139                 if ( err == KErrNone )
       
   140                     TRAP( err, streamId = iDatabase.CreateL( iFileStore ) );
       
   141 
       
   142                 if ( err == KErrNone )
       
   143                     TRAP( err, iFileStore->SetRootL( streamId ) );
       
   144 
       
   145                 if ( err == KErrNone )
       
   146                     TRAP( err, CreateDatabaseTablesL() );
       
   147 
       
   148                 if ( KErrNone != err )
       
   149                     {
       
   150                     iDatabase.Close();
       
   151                     iRfs.Delete( KMtpVideoDb );
       
   152                     }
       
   153                 }
       
   154             }
       
   155         }
       
   156 
       
   157     TBuf<KStorageRootMaxLength> storeRoot;
       
   158     err = PathInfo::GetRootPath( storeRoot, iStoreNum );
       
   159     iRfs.SetSessionPath( storeRoot );
       
   160 
       
   161     if ( err == KErrNone )
       
   162         {
       
   163         iDbOpened = ETrue;
       
   164         }
       
   165 
       
   166     PRINT( _L( "MM MTP <= CMmMtpDpMetadataVideoAccess::OpenDatabase" ) );
       
   167     return err;
       
   168     }
       
   169 
       
   170 // ---------------------------------------------------------------------------
       
   171 // CMmMtpDpMetadataMpxAccess::OpenDatabaseL
       
   172 // Open data base
       
   173 // ---------------------------------------------------------------------------
       
   174 //
       
   175 void CMmMtpDpMetadataVideoAccess::OpenDatabaseL()
       
   176     {
       
   177     PRINT( _L( "MM MTP => CMmMtpDpMetadataVideoAccess::OpenDatabaseL" ) );
       
   178     if ( OpenDatabase() != KErrNone )
       
   179         User::Leave( KErrGeneral );
       
   180     PRINT( _L( "MM MTP <= CMmMtpDpMetadataVideoAccess::OpenDatabaseL" ) );
       
   181     }
       
   182 
       
   183 // ---------------------------------------------------------------------------
       
   184 // CMmMtpDpMetadataMpxAccess::~CMmMtpDpMetadataVideoAccess
       
   185 // Destructor
       
   186 // ---------------------------------------------------------------------------
       
   187 //
       
   188 CMmMtpDpMetadataVideoAccess::~CMmMtpDpMetadataVideoAccess()
       
   189     {
       
   190     delete iQueryText;
       
   191     delete iColSet;
       
   192     iRecordSet.Close();
       
   193     iDatabase.Close();
       
   194     iDbsSession.Close();
       
   195     delete iFileStore;
       
   196     }
       
   197 
       
   198 // ---------------------------------------------------------------------------
       
   199 // CMmMtpDpMetadataMpxAccess::CreateDatabaseTablesL
       
   200 // Case where a new memory card is used and the player has not been opened
       
   201 // ---------------------------------------------------------------------------
       
   202 //
       
   203 void CMmMtpDpMetadataVideoAccess::CreateDatabaseTablesL()
       
   204     {
       
   205     PRINT( _L( "MM MTP => CMmMtpDpMetadataVideoAccess::CreateDatabaseTablesL" ) );
       
   206     // Video table
       
   207     RBuf formatBuf;
       
   208     User::LeaveIfError( formatBuf.Create( 5 * KMaxQueryLength ) );
       
   209     CleanupClosePushL( formatBuf ); // + foramtBuf
       
   210 
       
   211     formatBuf.Append( KMtpVideoStartCreateTable );
       
   212     formatBuf.Append( KMtpVideoTable );
       
   213     formatBuf.Append( KMtpVideoOpenBracket );
       
   214 
       
   215     formatBuf.Append( KMtpVideoLocation );
       
   216     formatBuf.Append( KMtpVideoLocationType );
       
   217     formatBuf.Append( KMtpVideoCommaSign );
       
   218 
       
   219     formatBuf.Append( KMtpVideoName );
       
   220     formatBuf.Append( KMtpVideoNameType );
       
   221     formatBuf.Append( KMtpVideoCommaSign );
       
   222 
       
   223     formatBuf.Append( KMtpVideoArtist );
       
   224     formatBuf.Append( KMtpVideoArtistType );
       
   225     formatBuf.Append( KMtpVideoCommaSign );
       
   226 
       
   227     formatBuf.Append( KMtpVideoTrack );
       
   228     formatBuf.Append( KMtpVideoTrackType );
       
   229     formatBuf.Append( KMtpVideoCommaSign );
       
   230 
       
   231     formatBuf.Append( KMtpVideoGenre );
       
   232     formatBuf.Append( KMtpVideoGenreType );
       
   233     formatBuf.Append( KMtpVideoCommaSign );
       
   234 
       
   235     formatBuf.Append( KMtpVideoAlbumName );
       
   236     formatBuf.Append( KMtpVideoAlbumNameType );
       
   237     formatBuf.Append( KMtpVideoCommaSign );
       
   238 
       
   239     formatBuf.Append( KMtpVideoComposer );
       
   240     formatBuf.Append( KMtpVideoComposerType );
       
   241     formatBuf.Append( KMtpVideoCommaSign );
       
   242 
       
   243     formatBuf.Append( KMtpVideoOrigReleaseDate );
       
   244     formatBuf.Append( KMtpVideoOrigReleaseDateType );
       
   245     formatBuf.Append( KMtpVideoCommaSign );
       
   246 
       
   247     formatBuf.Append( KMtpVideoComment );
       
   248     formatBuf.Append( KMtpVideoCommentType );
       
   249     formatBuf.Append( KMtpVideoCommaSign );
       
   250 
       
   251     formatBuf.Append( KMtpVideoWidth );
       
   252     formatBuf.Append( KMtpVideoWidthType );
       
   253     formatBuf.Append( KMtpVideoCommaSign );
       
   254 
       
   255     formatBuf.Append( KMtpVideoHeight );
       
   256     formatBuf.Append( KMtpVideoHeightType );
       
   257     formatBuf.Append( KMtpVideoCommaSign );
       
   258 
       
   259     formatBuf.Append( KMtpVideoDuration );
       
   260     formatBuf.Append( KMtpVideoDurationType );
       
   261     formatBuf.Append( KMtpVideoCommaSign );
       
   262 
       
   263     formatBuf.Append( KMtpVideoSampleRate );
       
   264     formatBuf.Append( KMtpVideoSampleRateType );
       
   265     formatBuf.Append( KMtpVideoCommaSign );
       
   266 
       
   267     formatBuf.Append( KMtpVideoNumberOfChannels );
       
   268     formatBuf.Append( KMtpVideoNumberOfChannelsType );
       
   269     formatBuf.Append( KMtpVideoCommaSign );
       
   270 
       
   271     formatBuf.Append( KMtpVideoAudioCodec );
       
   272     formatBuf.Append( KMtpVideoAudioCodecType );
       
   273     formatBuf.Append( KMtpVideoCommaSign );
       
   274 
       
   275     formatBuf.Append( KMtpVideoAudioBitrate );
       
   276     formatBuf.Append( KMtpVideoAudioBitrateType );
       
   277     formatBuf.Append( KMtpVideoCommaSign );
       
   278 
       
   279     formatBuf.Append( KMtpVideoVideoCodec );
       
   280     formatBuf.Append( KMtpVideoVideoCodecType );
       
   281     formatBuf.Append( KMtpVideoCommaSign );
       
   282 
       
   283     formatBuf.Append( KMtpVideoVideoBitrate );
       
   284     formatBuf.Append( KMtpVideoVideoBitrateType );
       
   285     formatBuf.Append( KMtpVideoCommaSign );
       
   286 
       
   287     formatBuf.Append( KMtpVideoFramesPer1000Sec );
       
   288     formatBuf.Append( KMtpVideoFramesPer1000SecType );
       
   289     formatBuf.Append( KMtpVideoCommaSign );
       
   290 
       
   291     formatBuf.Append( KMtpVideoKeyFrameDistance );
       
   292     formatBuf.Append( KMtpVideoKeyFrameDistanceType );
       
   293     formatBuf.Append( KMtpVideoCommaSign );
       
   294 
       
   295     formatBuf.Append( KMtpVideoScanType );
       
   296     formatBuf.Append( KMtpVideoScanTypeType );
       
   297     formatBuf.Append( KMtpVideoCommaSign );
       
   298 
       
   299     formatBuf.Append( KMtpVideoEncodingProfile );
       
   300     formatBuf.Append( KMtpVideoEncodingProfileType );
       
   301     formatBuf.Append( KMtpVideoCommaSign );
       
   302 
       
   303     formatBuf.Append( KMtpVideoParentalRating );
       
   304     formatBuf.Append( KMtpVideoParentalRatingType );
       
   305     formatBuf.Append( KMtpVideoCommaSign );
       
   306 
       
   307     formatBuf.Append( KMtpVideoUseCount );
       
   308     formatBuf.Append( KMtpVideoUseCountType );
       
   309     formatBuf.Append( KMtpVideoCommaSign );
       
   310 
       
   311     formatBuf.Append( KMtpVideoDRM );
       
   312     formatBuf.Append( KMtpVideoDRMType );
       
   313     formatBuf.Append( KMtpVideoCommaSign );
       
   314 
       
   315     formatBuf.Append( KMtpVideoDeleted );
       
   316     formatBuf.Append( KMtpVideoDeletedType );
       
   317     formatBuf.Append( KMtpVideoCloseBracket );
       
   318 
       
   319     // Execute the SQL statement.
       
   320     User::LeaveIfError( iDatabase.Execute( formatBuf ) );
       
   321     PRINT( _L( "MM MTP <> Video Table Created" ) );
       
   322 
       
   323     CleanupStack::PopAndDestroy( &formatBuf ); // - foramtBuf
       
   324     PRINT( _L( "MM MTP <= CMmMtpDpMetadataVideoAccess::CreateDatabaseTablesL" ) );
       
   325     }
       
   326 
       
   327 // For performance, better to regularly compact the MC database.
       
   328 void CMmMtpDpMetadataVideoAccess::CompactDbIfNecessaryL()
       
   329     {
       
   330     iRecordCount++;
       
   331 
       
   332     if ( iRecordCount > KMtpCompactInterval )
       
   333         {
       
   334         iRecordCount = 0;
       
   335 
       
   336         PRINT( _L( "MM MTP <> Compacting database file..." ) );
       
   337 
       
   338         if ( IsDatabaseOpened() )
       
   339             User::LeaveIfError( iDatabase.Compact() );
       
   340         }
       
   341     }
       
   342 
       
   343 // ---------------------------------------------------------------------------
       
   344 // CMmMtpDpMetadataMpxAccess::CleanupDbIfNecessaryL
       
   345 // Cleanup Database
       
   346 // ---------------------------------------------------------------------------
       
   347 //
       
   348 void CMmMtpDpMetadataVideoAccess::CleanupDbIfNecessaryL()
       
   349     {
       
   350     PRINT( _L( "MM MTP => CMmMtpDpMetadataVideoAccess::CleanupDbIfNecessaryL" ) );
       
   351 
       
   352     ExecuteQueryL( KAllColumns, KMtpVideoTable, KMtpVideoDeleted, KTrue, EFalse, EFalse );
       
   353     PRINT1( _L( "MM MTP <> CleanupDbIfNecessaryL Database deleted count = %d" ), iRecordSet.CountL() );
       
   354 
       
   355     for ( iRecordSet.FirstL(); iRecordSet.AtRow(); iRecordSet.NextL() )
       
   356         {
       
   357         HBufC* data = ReadLongTextL( KMtpVideoLocation );
       
   358         CleanupStack::PushL( data );
       
   359 
       
   360         PRINT1( _L( "MM MTP <> CleanupDbIfNecessaryL removing %S from database" ), data );
       
   361         iRecordSet.DeleteL();
       
   362         CleanupStack::PopAndDestroy( data );
       
   363         }
       
   364 
       
   365     delete iColSet;
       
   366     iColSet = NULL;
       
   367     iRecordSet.Close();
       
   368     PRINT( _L( "MM MTP <= CMmMtpDpMetadataVideoAccess::CleanupDbIfNecessaryL" ) );
       
   369     }
       
   370 
       
   371 // ---------------------------------------------------------------------------
       
   372 // CMmMtpDpMetadataMpxAccess::IdentifyDeletedFilesL
       
   373 // Identify deleted files
       
   374 // ---------------------------------------------------------------------------
       
   375 //
       
   376 void CMmMtpDpMetadataVideoAccess::IdentifyDeletedFilesL()
       
   377     {
       
   378     PRINT( _L( "MM MTP => CMmMtpDpMetadataVideoAccess::IdentifyDeletedFilesL" ) );
       
   379 
       
   380     ExecuteQueryL( KAllColumns, KMtpVideoTable, KMtpVideoLocation, KNullDesC, ETrue );
       
   381     PRINT1( _L( "MM MTP <> CleanupDbIfNecessaryL Database total count = %d" ), iRecordSet.CountL() );
       
   382 
       
   383     for ( iRecordSet.FirstL(); iRecordSet.AtRow(); iRecordSet.NextL( ))
       
   384         {
       
   385         HBufC* data = ReadLongTextL( KMtpVideoLocation );
       
   386         CleanupStack::PushL( data );
       
   387 
       
   388         if ( !FileExists( *data ) )
       
   389             {
       
   390             iRecordSet.UpdateL();
       
   391             PRINT1( _L( "MM MTP <> IdentifyDeletedFilesL marking %S as deleted" ), data );
       
   392 
       
   393             TDbColNo num = iColSet->ColNo( KMtpVideoDeleted );
       
   394 
       
   395             iRecordSet.SetColL( num, 1 );
       
   396             iRecordSet.PutL();
       
   397             }
       
   398 
       
   399         CleanupStack::PopAndDestroy( data );
       
   400         }
       
   401 
       
   402     delete iColSet;
       
   403     iColSet = NULL;
       
   404     iRecordSet.Close();
       
   405 
       
   406     PRINT( _L( "MM MTP <= CMmMtpDpMetadataVideoAccess::IdentifyDeletedFilesL" ) );
       
   407     }
       
   408 
       
   409 // ---------------------------------------------------------------------------
       
   410 // CMmMtpDpMetadataMpxAccess::ReadLongTextL
       
   411 // Read from Data base
       
   412 // ---------------------------------------------------------------------------
       
   413 //
       
   414 HBufC* CMmMtpDpMetadataVideoAccess::ReadLongTextL( const TDesC& aColumn )
       
   415     {
       
   416     TDbColNo num = iColSet->ColNo( aColumn );
       
   417 
       
   418     // The row must have previously been read into the rowset
       
   419     // using RDbRowSet::GetL().
       
   420     iRecordSet.GetL();
       
   421 
       
   422     TInt len = iRecordSet.ColLength( num );
       
   423 
       
   424     HBufC* buf = HBufC::NewLC( len ); // + buf
       
   425     TPtr value( buf->Des() );
       
   426 
       
   427     if ( len > 0 )
       
   428         {
       
   429         RDbColReadStream strm;
       
   430         strm.OpenLC( iRecordSet, num );
       
   431         strm.ReadL( value, len );
       
   432         strm.Close();
       
   433         CleanupStack::PopAndDestroy( &strm );
       
   434         }
       
   435     else
       
   436         {
       
   437         value.SetLength( 0 );
       
   438         }
       
   439 
       
   440     CleanupStack::Pop( buf ); // - buf
       
   441     PRINT2( _L( "MM MTP <> ReadLongTextL Metadata value for %S is \"%S\"" ), &aColumn, buf );
       
   442     return buf;
       
   443     }
       
   444 
       
   445 // ---------------------------------------------------------------------------
       
   446 // CMmMtpDpMetadataMpxAccess::WriteLongTextL
       
   447 // Utility to write to the database
       
   448 // ---------------------------------------------------------------------------
       
   449 //
       
   450 void CMmMtpDpMetadataVideoAccess::WriteLongTextL( const TDesC& aColumn, const TDesC& aValue )
       
   451     {
       
   452     PRINT2( _L( "MM MTP <> WriteLongTextL Metadata value for %S is \"%S\"" ), &aColumn, &aValue );
       
   453     TDbColNo num = iColSet->ColNo( aColumn );
       
   454     RDbColWriteStream strm;
       
   455     strm.OpenLC( iRecordSet, num );
       
   456     strm.WriteL( aValue );
       
   457     strm.Close();
       
   458     CleanupStack::PopAndDestroy( &strm );
       
   459     }
       
   460 
       
   461 // ---------------------------------------------------------------------------
       
   462 // CMmMtpDpMetadataMpxAccess::ExecuteQueryL
       
   463 // Executes a query on the database and sets the cursor at the start of the recordset
       
   464 // ---------------------------------------------------------------------------
       
   465 //
       
   466 void CMmMtpDpMetadataVideoAccess::ExecuteQueryL( const TDesC& aSelectThese, const TDesC& aFromTable,
       
   467                                        const TDesC& aColumnToMatch, const TDesC& aMatchCriteria,
       
   468                                        const TBool aIfNot, const TBool aNeedQuotes )
       
   469     {
       
   470     PRINT( _L( "MM MTP => CMmMtpDpMetadataVideoAccess::ExecuteQueryL" ) );
       
   471 
       
   472     delete iColSet;
       
   473     iColSet = NULL;
       
   474     iRecordSet.Close();
       
   475     //__ASSERT_DEBUG(!iColSet, _MTP_PANIC(KMtpPrtPncCat, ENullPointer)); // Must have iColSet == NULL
       
   476 
       
   477     // Make sure any quotes in the aMatchCriteria are doubled...
       
   478     HBufC* matchText = HBufC::NewLC( 2 * aMatchCriteria.Length() );
       
   479     TPtr pMatchText( matchText->Des() );
       
   480     TInt srcLen = aMatchCriteria.Length();
       
   481     TPtrC ch;
       
   482 
       
   483     for ( TInt i = 0; i < srcLen; ++i )
       
   484         {
       
   485         ch.Set( &aMatchCriteria[i], 1 );
       
   486         pMatchText.Append( ch );
       
   487 
       
   488         if ( ch.CompareF( KMtpVideoSingleQuote ) == 0 )
       
   489             {
       
   490             pMatchText.Append( ch );
       
   491             }
       
   492         }
       
   493 
       
   494     TPtr query( iQueryText->Des() );
       
   495     query.Zero();
       
   496     query.Append( KSelect );
       
   497     query.Append( aSelectThese );
       
   498     query.Append( KFrom );
       
   499     query.Append( aFromTable );
       
   500 
       
   501     if ( aColumnToMatch.Length() != 0 )
       
   502         {
       
   503         query.Append( KWhere );
       
   504 
       
   505         if ( aIfNot )
       
   506             query.Append( KNot );
       
   507 
       
   508         query.Append( aColumnToMatch );
       
   509         query.Append( KEquals );
       
   510 
       
   511         if ( aNeedQuotes )
       
   512             query.Append( KMtpVideoSingleQuote );
       
   513 
       
   514         query.Append( *matchText );
       
   515 
       
   516         if ( aNeedQuotes )
       
   517             query.Append( KMtpVideoSingleQuote );
       
   518         }
       
   519 
       
   520     TDbQuery dbQuery( query );
       
   521     PRINT1( _L( "MM MTP <> ExecuteQueryL Query is \"%S\"" ), &query );
       
   522 
       
   523     // Execute the query
       
   524     User::LeaveIfError( iRecordSet.Prepare( iDatabase, dbQuery ) );
       
   525     User::LeaveIfError( iRecordSet.EvaluateAll() );
       
   526     iRecordSet.FirstL();
       
   527     iColSet = iRecordSet.ColSetL();
       
   528     CleanupStack::PopAndDestroy( matchText );
       
   529 
       
   530     PRINT( _L( "MM MTP <= CMmMtpDpMetadataVideoAccess::ExecuteQueryL" ) );
       
   531     }
       
   532 
       
   533 // ---------------------------------------------------------------------------
       
   534 // CMmMtpDpMetadataMpxAccess::OpenSessionL
       
   535 // Called when the MTP session is initialised
       
   536 // ---------------------------------------------------------------------------
       
   537 //
       
   538 void CMmMtpDpMetadataVideoAccess::OpenSessionL()
       
   539     {
       
   540 
       
   541     }
       
   542 
       
   543 // ---------------------------------------------------------------------------
       
   544 // CMmMtpDpMetadataMpxAccess::CloseSessionL
       
   545 // Called when the MTP session is closed
       
   546 // ---------------------------------------------------------------------------
       
   547 //
       
   548 void CMmMtpDpMetadataVideoAccess::CloseSessionL()
       
   549     {
       
   550     PRINT( _L( "MM MTP => CMmMtpDpMetadataVideoAccess::CloseSessionL" ) );
       
   551 
       
   552     //open database if not opened
       
   553     if ( !IsDatabaseOpened() )
       
   554         return;
       
   555 
       
   556     // Make sure the db is commited
       
   557     SetRecordL( KNullDesC, ENoRecord );
       
   558 
       
   559     CleanupDbIfNecessaryL();
       
   560 
       
   561     PRINT( _L( "MM MTP <= CMmMtpDpMetadataVideoAccess::CloseSessionL" ) )
       
   562     }
       
   563 
       
   564 // ---------------------------------------------------------------------------
       
   565 // CMmMtpDpMetadataMpxAccess::AddVideoL
       
   566 // Adds video info to the database
       
   567 // ---------------------------------------------------------------------------
       
   568 //
       
   569 void CMmMtpDpMetadataVideoAccess::AddVideoL( const TDesC& aFullFileName )
       
   570     {
       
   571     PRINT( _L( "MM MTP => CMmMtpDpMetadataVideoAccess::AddVideoL" ) );
       
   572 
       
   573     //open database if not opened
       
   574     if ( !IsDatabaseOpened() )
       
   575         OpenDatabaseL();
       
   576 
       
   577     // Put any outstanding changes to the DB
       
   578     SetRecordL( KNullDesC, ENoRecord );
       
   579     TDbColNo num = 0;
       
   580 
       
   581     // Does a record already exist for this playlist?
       
   582     ExecuteQueryL( KAllColumns, KMtpVideoTable, KMtpVideoLocation, aFullFileName );
       
   583 
       
   584     if ( iRecordSet.CountL() == 0 )   // No record...
       
   585         {
       
   586         PRINT1( _L( "MM MTP <> AddVideoL file %S is adding to collection" ), &aFullFileName );
       
   587 
       
   588         // Create the record
       
   589         iRecordSet.InsertL();
       
   590 
       
   591         // Defaults
       
   592         num = iColSet->ColNo( KMtpVideoLocation );
       
   593         iRecordSet.SetColL( num, aFullFileName );
       
   594 
       
   595         num = iColSet->ColNo( KMtpVideoName );
       
   596         iRecordSet.SetColL( num, aFullFileName );     // Default name is the filename.
       
   597 
       
   598         num = iColSet->ColNo( KMtpVideoArtist );
       
   599         iRecordSet.SetColL( num, KNullDesC );
       
   600 
       
   601         num = iColSet->ColNo( KMtpVideoTrack );
       
   602         iRecordSet.SetColL( num, 0 );
       
   603 
       
   604         num = iColSet->ColNo( KMtpVideoGenre );
       
   605         iRecordSet.SetColL( num, KNullDesC );
       
   606 
       
   607         num = iColSet->ColNo( KMtpVideoAlbumName );
       
   608         iRecordSet.SetColL( num, KNullDesC );
       
   609 
       
   610         num = iColSet->ColNo( KMtpVideoComposer );
       
   611         iRecordSet.SetColL( num, KNullDesC );
       
   612 
       
   613         num = iColSet->ColNo( KMtpVideoOrigReleaseDate );
       
   614         iRecordSet.SetColL( num, KNullDesC );
       
   615 
       
   616         num = iColSet->ColNo( KMtpVideoComment );
       
   617         iRecordSet.SetColL( num, KNullDesC );
       
   618 
       
   619         num = iColSet->ColNo( KMtpVideoWidth );
       
   620         iRecordSet.SetColL( num, 0 );
       
   621 
       
   622         num = iColSet->ColNo( KMtpVideoHeight );
       
   623         iRecordSet.SetColL( num, 0 );
       
   624 
       
   625         num = iColSet->ColNo(KMtpVideoDuration);
       
   626         iRecordSet.SetColL(num, 0);
       
   627 
       
   628         num = iColSet->ColNo( KMtpVideoSampleRate );
       
   629         iRecordSet.SetColL( num, 0 );
       
   630 
       
   631         num = iColSet->ColNo( KMtpVideoNumberOfChannels );
       
   632         iRecordSet.SetColL( num, 0 );
       
   633 
       
   634         num = iColSet->ColNo( KMtpVideoAudioCodec );
       
   635         iRecordSet.SetColL( num, 0 );
       
   636 
       
   637         num = iColSet->ColNo( KMtpVideoAudioBitrate );
       
   638         iRecordSet.SetColL( num, 0 );
       
   639 
       
   640         num = iColSet->ColNo( KMtpVideoVideoCodec );
       
   641         iRecordSet.SetColL( num, 0 );
       
   642 
       
   643         num = iColSet->ColNo( KMtpVideoVideoBitrate );
       
   644         iRecordSet.SetColL( num, 0 );
       
   645 
       
   646         num = iColSet->ColNo(KMtpVideoFramesPer1000Sec);
       
   647         iRecordSet.SetColL(num, 0);
       
   648 
       
   649         num = iColSet->ColNo( KMtpVideoKeyFrameDistance );
       
   650         iRecordSet.SetColL( num, 0 );
       
   651 
       
   652         num = iColSet->ColNo( KMtpVideoScanType );
       
   653         iRecordSet.SetColL( num, 0 );
       
   654 
       
   655         num = iColSet->ColNo( KMtpVideoEncodingProfile );
       
   656         iRecordSet.SetColL( num, KNullDesC );
       
   657 
       
   658         num = iColSet->ColNo( KMtpVideoParentalRating );
       
   659         iRecordSet.SetColL( num, KNullDesC );
       
   660 
       
   661         num = iColSet->ColNo( KMtpVideoUseCount );
       
   662         iRecordSet.SetColL( num, 0 );
       
   663 
       
   664         num = iColSet->ColNo( KMtpVideoDRM );
       
   665         iRecordSet.SetColL( num, 0 );
       
   666         }
       
   667     else
       
   668         {
       
   669         PRINT1( _L( "MM MTP <> AddVideoL file %S is found in the collection" ), &aFullFileName );
       
   670 
       
   671         iRecordSet.FirstL();
       
   672         iRecordSet.UpdateL();
       
   673         }
       
   674 
       
   675     // reset deleted bit
       
   676     num = iColSet->ColNo( KMtpVideoDeleted );
       
   677     iRecordSet.SetColL( num, 0 );
       
   678 
       
   679     // Commit the record
       
   680     TRAPD( err, iRecordSet.PutL() );
       
   681 
       
   682     if ( KErrNone != err )
       
   683         {
       
   684         PRINT1( _L( "MM MTP <> AddVideoL Failed to add record to database with code %d" ), err );
       
   685         iRecordSet.Cancel();
       
   686         User::Leave( err );
       
   687         }
       
   688 
       
   689     delete iColSet;
       
   690     iColSet = NULL;
       
   691     iRecordSet.Close();
       
   692     CompactDbIfNecessaryL();
       
   693     PRINT( _L( "MM MTP <= CMmMtpDpMetadataVideoAccess::AddVideoL" ) );
       
   694     }
       
   695 
       
   696 // ---------------------------------------------------------------------------
       
   697 // CMmMtpDpMetadataMpxAccess::GetObjectMetadataValueL
       
   698 //  Gets a piece of metadata from the collection
       
   699 // ---------------------------------------------------------------------------
       
   700 //
       
   701 void CMmMtpDpMetadataVideoAccess::GetObjectMetadataValueL( const TUint16 aPropCode,
       
   702         MMTPType& aNewData,
       
   703         const CMTPObjectMetaData& aObjectMetaData )
       
   704     {
       
   705     PRINT1( _L( "MM MTP => CMmMtpDpMetadataVideoAccess::GetObjectMetadataValue aPropCode = 0x%x" ), aPropCode );
       
   706 
       
   707     //open database if not opened
       
   708     if ( !IsDatabaseOpened() )
       
   709         OpenDatabaseL();
       
   710 
       
   711     // File Path
       
   712     HBufC* suid = aObjectMetaData.DesC( CMTPObjectMetaData::ESuid ).AllocLC();  // + suid
       
   713     SetRecordL( *suid, ERecordRead );
       
   714     CleanupStack::PopAndDestroy( suid ); // - suid
       
   715 
       
   716     HBufC* data = NULL;
       
   717     TDbColNo num;
       
   718     TUint32 uInt32 = 0;
       
   719     TUint16 uInt16 = 0;
       
   720 
       
   721     switch (aPropCode)
       
   722         {
       
   723         case EMTPObjectPropCodeName:
       
   724             {
       
   725             PRINT( _L( "MM MTP <> EMTPObjectPropCodeName-MD" ) );
       
   726             data = ReadLongTextL( KMtpVideoName );
       
   727             }
       
   728             break;
       
   729 
       
   730         case EMTPObjectPropCodeArtist:
       
   731             {
       
   732             PRINT( _L( "MM MTP <> EMTPObjectPropCodeArtist-MD" ) );
       
   733             data = ReadLongTextL( KMtpVideoArtist );
       
   734             }
       
   735             break;
       
   736 
       
   737         case EMTPObjectPropCodeTrack:
       
   738             {
       
   739             PRINT( _L( "MM MTP <> EMTPObjectPropCodeTrack-MD" ) );
       
   740             num = iColSet->ColNo( KMtpVideoTrack );
       
   741             uInt16 = iRecordSet.ColUint16( num );
       
   742             if ( EMTPTypeUINT16 == aNewData.Type() )
       
   743                 {
       
   744                 ( ( TMTPTypeUint16 & ) aNewData ).Set( uInt16 );
       
   745                 }
       
   746             else
       
   747                 {
       
   748                 User::Leave( KErrArgument );
       
   749                 }
       
   750             }
       
   751             break;
       
   752 
       
   753         case EMTPObjectPropCodeGenre:
       
   754             {
       
   755             PRINT( _L( "MM MTP <> EMTPObjectPropCodeGenre-MD" ) );
       
   756             data = ReadLongTextL( KMtpVideoGenre );
       
   757             }
       
   758             break;
       
   759 
       
   760         case EMTPObjectPropCodeAlbumName:
       
   761             {
       
   762             PRINT( _L( "MM MTP <> EMTPObjectPropCodeAlbumName-MD" ) );
       
   763             data = ReadLongTextL( KMtpVideoAlbumName );
       
   764             }
       
   765             break;
       
   766 
       
   767         case EMTPObjectPropCodeComposer:
       
   768             {
       
   769             PRINT( _L( "MM MTP <> EMTPObjectPropCodeComposer-MD" ) );
       
   770             data = ReadLongTextL( KMtpVideoComposer );
       
   771             }
       
   772             break;
       
   773 
       
   774         case EMTPObjectPropCodeOriginalReleaseDate:
       
   775             {
       
   776             PRINT( _L( "MM MTP <> EMTPObjectPropCodeOriginalReleaseDate-MD" ) );
       
   777             data = ReadLongTextL( KMtpVideoOrigReleaseDate );
       
   778             }
       
   779             break;
       
   780 
       
   781         case EMTPObjectPropCodeDescription:
       
   782             {
       
   783             PRINT( _L( "MM MTP <> EMTPObjectPropCodeDescription-MD" ) );
       
   784             data = ReadLongTextL( KMtpVideoComment );
       
   785 
       
   786             if ( data->Length() != 0 )
       
   787                 ( ( CMTPTypeString& ) aNewData ).SetL( *data ) ;
       
   788             else
       
   789                 ( ( TMTPTypeUint32 & ) aNewData ).Set( 0 );  // return zero if description is empty
       
   790 
       
   791             delete data;
       
   792             data = NULL;
       
   793             }
       
   794             break;
       
   795 
       
   796         case EMTPObjectPropCodeWidth:
       
   797             {
       
   798             PRINT( _L( "MM MTP <> EMTPObjectPropCodeWidth-MD" ) );
       
   799             num = iColSet->ColNo( KMtpVideoWidth );
       
   800             uInt32 = iRecordSet.ColUint32( num );
       
   801             if ( EMTPTypeUINT32 == aNewData.Type() )
       
   802                 {
       
   803                 ( ( TMTPTypeUint32 & ) aNewData ).Set( uInt32 );
       
   804                 }
       
   805             else
       
   806                 {
       
   807                 User::Leave( KErrArgument );
       
   808                 }
       
   809             }
       
   810             break;
       
   811 
       
   812         case EMTPObjectPropCodeHeight:
       
   813             {
       
   814             PRINT( _L( "MM MTP <> EMTPObjectPropCodeHeight-MD" ) );
       
   815             num = iColSet->ColNo( KMtpVideoHeight );
       
   816             uInt32 = iRecordSet.ColUint32( num );
       
   817             if ( EMTPTypeUINT32 == aNewData.Type() )
       
   818                 {
       
   819                 ( ( TMTPTypeUint32 & ) aNewData ).Set( uInt32 );
       
   820                 }
       
   821             else
       
   822                 {
       
   823                 User::Leave( KErrArgument );
       
   824                 }
       
   825             }
       
   826             break;
       
   827 
       
   828         case EMTPObjectPropCodeDuration:
       
   829             {
       
   830             PRINT( _L( "MM MTP <> EMTPObjectPropCodeDuration-MD" ) );
       
   831             num = iColSet->ColNo( KMtpVideoDuration );
       
   832             uInt32 = iRecordSet.ColUint32( num );
       
   833             if ( EMTPTypeUINT32 == aNewData.Type() )
       
   834                 {
       
   835                 ( ( TMTPTypeUint32 & ) aNewData ).Set( uInt32 );
       
   836                 }
       
   837             else
       
   838                 {
       
   839                 User::Leave( KErrArgument );
       
   840                 }
       
   841             }
       
   842             break;
       
   843 
       
   844         case EMTPObjectPropCodeSampleRate:
       
   845             {
       
   846             PRINT( _L( "MM MTP <> EMTPObjectPropCodeSampleRate-MD" ) );
       
   847             num = iColSet->ColNo( KMtpVideoSampleRate );
       
   848             uInt32 = iRecordSet.ColUint32( num );
       
   849             if ( EMTPTypeUINT32 == aNewData.Type() )
       
   850                 {
       
   851                 ( ( TMTPTypeUint32 & ) aNewData ).Set( uInt32 );
       
   852                 }
       
   853             else
       
   854                 {
       
   855                 User::Leave( KErrArgument );
       
   856                 }
       
   857             }
       
   858             break;
       
   859 
       
   860         case EMTPObjectPropCodeNumberOfChannels:
       
   861             {
       
   862             PRINT( _L( "MM MTP <> EMTPObjectPropCodeNumberOfChannels-MD" ) );
       
   863             num = iColSet->ColNo( KMtpVideoNumberOfChannels );
       
   864             uInt16 = iRecordSet.ColUint16( num );
       
   865             if ( EMTPTypeUINT16 == aNewData.Type() )
       
   866                  {
       
   867                  ( ( TMTPTypeUint16 & ) aNewData ).Set( uInt16 );
       
   868                  }
       
   869              else
       
   870                  {
       
   871                  User::Leave( KErrArgument );
       
   872                  }
       
   873             }
       
   874             break;
       
   875 
       
   876         case EMTPObjectPropCodeAudioWAVECodec:
       
   877             {
       
   878             PRINT( _L( "MM MTP <> EMTPObjectPropCodeAudioWAVECodec-MD" ) );
       
   879             num = iColSet->ColNo( KMtpVideoAudioCodec );
       
   880             uInt32 = iRecordSet.ColUint32( num );
       
   881             if ( EMTPTypeUINT32 == aNewData.Type() )
       
   882                 {
       
   883                 ( ( TMTPTypeUint32 & ) aNewData ).Set( uInt32 );
       
   884                 }
       
   885             else
       
   886                 {
       
   887                 User::Leave( KErrArgument );
       
   888                 }
       
   889             }
       
   890             break;
       
   891 
       
   892         case EMTPObjectPropCodeAudioBitRate:
       
   893             {
       
   894             PRINT( _L( "MM MTP <> EMTPObjectPropCodeAudioBitRate-MD" ) );
       
   895             num = iColSet->ColNo( KMtpVideoAudioBitrate );
       
   896             uInt32 = iRecordSet.ColUint32( num );
       
   897             if ( EMTPTypeUINT32 == aNewData.Type() )
       
   898                 {
       
   899                 ( ( TMTPTypeUint32 & ) aNewData ).Set( uInt32 );
       
   900                 }
       
   901             else
       
   902                 {
       
   903                 User::Leave( KErrArgument );
       
   904                 }
       
   905             }
       
   906             break;
       
   907 
       
   908         case EMTPObjectPropCodeVideoFourCCCodec:
       
   909             {
       
   910             PRINT( _L( "MM MTP <> EMTPObjectPropCodeVideoFourCCCodec-MD" ) );
       
   911             num = iColSet->ColNo( KMtpVideoVideoCodec );
       
   912             uInt32 = iRecordSet.ColUint32( num );
       
   913             if ( EMTPTypeUINT32 == aNewData.Type() )
       
   914                 {
       
   915                 ( ( TMTPTypeUint32 & ) aNewData ).Set( uInt32 );
       
   916                 }
       
   917             else
       
   918                 {
       
   919                 User::Leave( KErrArgument );
       
   920                 }
       
   921             }
       
   922             break;
       
   923 
       
   924         case EMTPObjectPropCodeVideoBitRate:
       
   925             {
       
   926             PRINT( _L( "MM MTP <> EMTPObjectPropCodeVideoBitRate-MD" ) );
       
   927             num = iColSet->ColNo( KMtpVideoVideoBitrate );
       
   928             uInt32 = iRecordSet.ColUint32( num );
       
   929             if ( EMTPTypeUINT32 == aNewData.Type() )
       
   930                 {
       
   931                 ( ( TMTPTypeUint32 & ) aNewData ).Set( uInt32 );
       
   932                 }
       
   933             else
       
   934                 {
       
   935                 User::Leave( KErrArgument );
       
   936                 }
       
   937             }
       
   938             break;
       
   939 
       
   940         case EMTPObjectPropCodeFramesPerThousandSeconds:
       
   941             {
       
   942             PRINT( _L( "MM MTP <> EMTPObjectPropCodeFramesPerThousandSeconds-MD" ) );
       
   943             num = iColSet->ColNo( KMtpVideoFramesPer1000Sec );
       
   944             uInt32 = iRecordSet.ColUint32( num );
       
   945             if ( EMTPTypeUINT32 == aNewData.Type() )
       
   946                 {
       
   947                 ( ( TMTPTypeUint32 & ) aNewData ).Set( uInt32 );
       
   948                 }
       
   949             else
       
   950                 {
       
   951                 User::Leave( KErrArgument );
       
   952                 }
       
   953             }
       
   954             break;
       
   955 
       
   956         case EMTPObjectPropCodeKeyFrameDistance:
       
   957             {
       
   958             PRINT( _L( "MM MTP <> EMTPObjectPropCodeKeyFrameDistance-MD" ) );
       
   959             num = iColSet->ColNo( KMtpVideoKeyFrameDistance );
       
   960             uInt32 = iRecordSet.ColUint32( num );
       
   961             if ( EMTPTypeUINT32 == aNewData.Type() )
       
   962                 {
       
   963                 ( ( TMTPTypeUint32 & ) aNewData ).Set( uInt32 );
       
   964                 }
       
   965             else
       
   966                 {
       
   967                 User::Leave( KErrArgument );
       
   968                 }
       
   969             }
       
   970             break;
       
   971 
       
   972         case EMTPObjectPropCodeScanType:
       
   973             {
       
   974             PRINT( _L( "MM MTP <> EMTPObjectPropCodeScanType-MD" ) );
       
   975             num = iColSet->ColNo( KMtpVideoScanType );
       
   976             uInt16 = iRecordSet.ColUint16( num );
       
   977             if ( EMTPTypeUINT16 == aNewData.Type() )
       
   978                  {
       
   979                  ( ( TMTPTypeUint16 & ) aNewData ).Set( uInt16 );
       
   980                  }
       
   981              else
       
   982                  {
       
   983                  User::Leave( KErrArgument );
       
   984                  }
       
   985             }
       
   986             break;
       
   987 
       
   988         case EMTPObjectPropCodeEncodingProfile:
       
   989             {
       
   990             PRINT( _L( "MM MTP <> EMTPObjectPropCodeEncodingProfile-MD" ) );
       
   991             data = ReadLongTextL( KMtpVideoEncodingProfile );
       
   992             }
       
   993             break;
       
   994 
       
   995         case EMTPObjectPropCodeParentalRating:
       
   996             {
       
   997             PRINT( _L( "MM MTP <> EMTPObjectPropCodeParentalRating-MD" ) );
       
   998             data = ReadLongTextL( KMtpVideoParentalRating );
       
   999             }
       
  1000             break;
       
  1001 
       
  1002         case EMTPObjectPropCodeUseCount:
       
  1003             {
       
  1004             PRINT( _L( "MM MTP <> EMTPObjectPropCodeUseCount-MD" ) );
       
  1005             num = iColSet->ColNo( KMtpVideoUseCount );
       
  1006             uInt32 = iRecordSet.ColUint32( num );
       
  1007             if ( EMTPTypeUINT32 == aNewData.Type() )
       
  1008                 {
       
  1009                 ( ( TMTPTypeUint32 & ) aNewData ).Set( uInt32 );
       
  1010                 }
       
  1011             else
       
  1012                 {
       
  1013                 User::Leave( KErrArgument );
       
  1014                 }
       
  1015             }
       
  1016             break;
       
  1017 
       
  1018         case EMTPObjectPropCodeDRMStatus:
       
  1019             {
       
  1020             PRINT( _L( "MM MTP <> EMTPObjectPropCodeDRMStatus-MD" ) );
       
  1021             num = iColSet->ColNo( KMtpVideoDRM );
       
  1022             uInt16 = iRecordSet.ColUint16( num );
       
  1023             if ( EMTPTypeUINT16 == aNewData.Type() )
       
  1024                  {
       
  1025                  ( ( TMTPTypeUint16 & ) aNewData ).Set( uInt16 );
       
  1026                  }
       
  1027              else
       
  1028                  {
       
  1029                  User::Leave( KErrArgument );
       
  1030                  }
       
  1031             }
       
  1032             break;
       
  1033 
       
  1034         default:
       
  1035             {
       
  1036             User::Leave( KErrNotSupported );
       
  1037             }
       
  1038             break;
       
  1039         }
       
  1040 
       
  1041     // Pack the info to aNewData
       
  1042     if (data)
       
  1043         {
       
  1044 #ifdef _DEBUG
       
  1045         if ( data->Length() > KMtpMaxStringDescLength )   // Have to concatenate for MTP
       
  1046             {
       
  1047             PRINT1( _L( "MM MTP <> Descriptor will be concatenated from length %d to KMtpMaxStringLength" ), data->Length() );
       
  1048             }
       
  1049 #endif // _DEBUG
       
  1050 
       
  1051         if ( EMTPTypeString == aNewData.Type() )
       
  1052             {
       
  1053             ( ( CMTPTypeString& ) aNewData ).SetL( *data );
       
  1054             }
       
  1055         else
       
  1056             {
       
  1057             User::Leave( KErrArgument );
       
  1058             }
       
  1059         delete data;
       
  1060         data = NULL;
       
  1061         }
       
  1062 
       
  1063     PRINT( _L( "MM MTP <= CMmMtpDpMetadataVideoAccess::GetObjectMetadataValue" ) );
       
  1064     }
       
  1065 
       
  1066 // ---------------------------------------------------------------------------
       
  1067 // CMmMtpDpMetadataMpxAccess::SetObjectMetadataValueL
       
  1068 // Sets a piece of metadata in the collection
       
  1069 // ---------------------------------------------------------------------------
       
  1070 //
       
  1071 void CMmMtpDpMetadataVideoAccess::SetObjectMetadataValueL( const TUint16 aPropCode,
       
  1072     const MMTPType& aNewData,
       
  1073     const CMTPObjectMetaData& aObjectMetaData )
       
  1074     {
       
  1075     PRINT1( _L( "MM MTP => CMmMtpDpMetadataVideoAccess::SetObjectMetadataValueL aPropCode = 0x%x" ), aPropCode );
       
  1076 
       
  1077     if ( !IsDatabaseOpened() )
       
  1078         OpenDatabaseL();
       
  1079 
       
  1080     // Get file path
       
  1081     TPtrC suid( aObjectMetaData.DesC( CMTPObjectMetaData::ESuid ) );
       
  1082     TParsePtrC parse( suid );
       
  1083     SetRecordL( suid, ERecordWrite );
       
  1084     TRAPD( err, SetMetadataL( aPropCode, aNewData ) );
       
  1085 
       
  1086     if ( err < KErrNone ) // EPOC error condition
       
  1087         {
       
  1088         PRINT1( _L( "MM MTP <> Metadata write failed, with error %d" ), err );
       
  1089         SetRecordL( suid, EFailedWrite );
       
  1090         }
       
  1091 
       
  1092     if ( err != KErrNone )
       
  1093         User::Leave( err );
       
  1094 
       
  1095     PRINT( _L( "MM MTP <= CMmMtpDpMetadataVideoAccess::SetObjectMetadataValueL" ) );
       
  1096     }
       
  1097 
       
  1098 // ---------------------------------------------------------------------------
       
  1099 // CMmMtpDpMetadataMpxAccess::SetMetadataL
       
  1100 // Set meta data.
       
  1101 // ---------------------------------------------------------------------------
       
  1102 //
       
  1103 void CMmMtpDpMetadataVideoAccess::SetMetadataL( const TUint16 aObjPropCode,
       
  1104     const MMTPType& aNewData )
       
  1105     {
       
  1106     PRINT1( _L( "MM MTP => CMmMtpDpMetadataVideoAccess::SetMetadataL property Code = 0x%x" ), aObjPropCode );
       
  1107 
       
  1108     TBuf<KMtpMaxStringLength> data;
       
  1109     TDbColNo num;
       
  1110     TMTPTypeUint16 uint16Data;
       
  1111     TMTPTypeUint32 uint32Data;
       
  1112     CMTPTypeArray* desData = NULL;
       
  1113 
       
  1114     TPtrC colName( ColumnNameFromPropCodeL( aObjPropCode ) );
       
  1115     switch ( aObjPropCode )
       
  1116         {
       
  1117         case EMTPObjectPropCodeName:
       
  1118         case EMTPObjectPropCodeArtist:
       
  1119         case EMTPObjectPropCodeGenre:
       
  1120         case EMTPObjectPropCodeAlbumName:
       
  1121         case EMTPObjectPropCodeComposer:
       
  1122         case EMTPObjectPropCodeOriginalReleaseDate:
       
  1123         case EMTPObjectPropCodeEncodingProfile:
       
  1124         case EMTPObjectPropCodeParentalRating:
       
  1125             {
       
  1126             if( EMTPTypeString != aNewData.Type())
       
  1127                 {
       
  1128                 User::Leave( KErrArgument );
       
  1129                 }
       
  1130             TPtrC string( ( ( CMTPTypeString& ) aNewData ).StringChars() );
       
  1131             WriteLongTextL( colName, string );
       
  1132             PRINT2( _L( "MM MTP <> CMmMtpDpMetadataVideoAccess::SetMetadataL string = %S, length = %d" ), &string, string.Length() );
       
  1133             }
       
  1134             break;
       
  1135 
       
  1136         case EMTPObjectPropCodeDescription:
       
  1137             {
       
  1138             PRINT( _L( "MM MTP <> EMTPObjectPropCodeDescription-MD" ) );
       
  1139 #ifdef __MUSIC_ID_SUPPORT
       
  1140             //WriteMusicIdsL(*longString);
       
  1141 #else
       
  1142             desData = CMTPTypeArray::NewLC( EMTPTypeAUINT16 ); // + desData
       
  1143             MMTPType::CopyL( aNewData, *desData );
       
  1144             TUint length = desData->NumElements();
       
  1145             PRINT1( _L( "MM MTP <> CMmMtpDpMetadataMpxAccess::SetMetadataValueL length = %d" ), length );
       
  1146             if ( length != 0 )
       
  1147                 {
       
  1148                 TBuf<KMtpMaxDescriptionLength> text;
       
  1149                 text.Zero();
       
  1150                 for ( TUint i = 0; i < length; i++ )
       
  1151                     {
       
  1152                     text.Append( desData->ElementUint( i ) );
       
  1153                     }
       
  1154                 PRINT1( _L( "MM MTP <> CMmMtpDpMetadataMpxAccess::SetMetadataValueL text = %S" ),
       
  1155                     &text );
       
  1156                 WriteLongTextL( KMtpVideoComment, text );
       
  1157                 }
       
  1158             else
       
  1159                 {
       
  1160                 WriteLongTextL( KMtpVideoComment, KEmptyText );
       
  1161                 }
       
  1162             CleanupStack::PopAndDestroy( desData ); // - desData
       
  1163 #endif //__MUSIC_ID_SUPPORT
       
  1164             }
       
  1165             break;
       
  1166 
       
  1167         case EMTPObjectPropCodeWidth:
       
  1168         case EMTPObjectPropCodeHeight:
       
  1169         case EMTPObjectPropCodeDuration:
       
  1170         case EMTPObjectPropCodeSampleRate:
       
  1171         case EMTPObjectPropCodeAudioWAVECodec:
       
  1172         case EMTPObjectPropCodeAudioBitRate:
       
  1173         case EMTPObjectPropCodeVideoFourCCCodec:
       
  1174         case EMTPObjectPropCodeVideoBitRate:
       
  1175         case EMTPObjectPropCodeFramesPerThousandSeconds:
       
  1176         case EMTPObjectPropCodeKeyFrameDistance:
       
  1177         case EMTPObjectPropCodeUseCount:
       
  1178             {
       
  1179             if ( EMTPTypeUINT32 != aNewData.Type() )
       
  1180                 {
       
  1181                 User::Leave( KErrArgument );
       
  1182                 }
       
  1183             num = iColSet->ColNo( colName );
       
  1184             iRecordSet.SetColL( num, ( ( TMTPTypeUint32& ) aNewData ).Value() );
       
  1185             }
       
  1186             break;
       
  1187 
       
  1188         case EMTPObjectPropCodeTrack:
       
  1189         case EMTPObjectPropCodeNumberOfChannels:
       
  1190         case EMTPObjectPropCodeScanType:
       
  1191         case EMTPObjectPropCodeDRMStatus:
       
  1192             {
       
  1193             if ( EMTPTypeUINT16 != aNewData.Type() )
       
  1194                 {
       
  1195                 User::Leave( KErrArgument );
       
  1196                 }
       
  1197             num = iColSet->ColNo( colName );
       
  1198             iRecordSet.SetColL( num, ( ( TMTPTypeUint16& ) aNewData ).Value() );
       
  1199             }
       
  1200             break;
       
  1201 
       
  1202         default:
       
  1203             {
       
  1204             User::Leave( KErrNotSupported );
       
  1205             }
       
  1206             break;
       
  1207         }
       
  1208 
       
  1209     PRINT( _L( "MM MTP <= CMmMtpDpMetadataVideoAccess::SetMetadataL" ) );
       
  1210     }
       
  1211 
       
  1212 // ---------------------------------------------------------------------------
       
  1213 // CMmMtpDpMetadataMpxAccess::RenameRecordL
       
  1214 // Renames the file part of a record in the collection database.
       
  1215 // ---------------------------------------------------------------------------
       
  1216 //
       
  1217 void CMmMtpDpMetadataVideoAccess::RenameRecordL(const TDesC& aOldFileName, const TDesC& aNewFileName)
       
  1218     {
       
  1219     PRINT( _L( "MM MTP => CMmMtpDpMetadataVideoAccess::RenameRecordL()" ) );
       
  1220 
       
  1221     //open database if not opened
       
  1222     if ( !IsDatabaseOpened() )
       
  1223         OpenDatabaseL();
       
  1224 
       
  1225     SetRecordL( aOldFileName, ERecordWrite ); // Open the record to write
       
  1226     TDbColNo num = iColSet->ColNo( KMtpVideoLocation );
       
  1227     iRecordSet.SetColL( num, aNewFileName );
       
  1228 
       
  1229     PRINT( _L( "MM MTP <= CMmMtpDpMetadataVideoAccess::RenameRecordL()" ) );
       
  1230     }
       
  1231 
       
  1232 // ---------------------------------------------------------------------------
       
  1233 // CMmMtpDpMetadataMpxAccess::DeleteRecordL
       
  1234 // Deletes metadata information associated with the object
       
  1235 // ---------------------------------------------------------------------------
       
  1236 //
       
  1237 void CMmMtpDpMetadataVideoAccess::DeleteRecordL( const TDesC& aFullFileName )
       
  1238     {
       
  1239     PRINT( _L( "MM MTP => CMmMtpDpMetadataVideoAccess::DeleteRecordL" ) );
       
  1240 
       
  1241     //open database if not opened
       
  1242     if ( !IsDatabaseOpened() )
       
  1243         OpenDatabaseL();
       
  1244 
       
  1245     SetRecordL( KNullDesC, ENoRecord ); // Commit any other changes to the DB
       
  1246 
       
  1247     TUint format = MmMtpDpUtility::FormatFromFilename( aFullFileName );
       
  1248 
       
  1249     if ( MmMtpDpUtility::HasMetadata( format ) )
       
  1250         {
       
  1251         ExecuteQueryL( KMtpVideoLocation,
       
  1252             KMtpVideoTable,
       
  1253             KMtpVideoLocation,
       
  1254             aFullFileName );
       
  1255 
       
  1256         for ( iRecordSet.FirstL(); iRecordSet.AtRow(); iRecordSet.NextL() )
       
  1257             {
       
  1258             iRecordSet.DeleteL();
       
  1259             PRINT( _L( "MM MTP <> CMmMtpDpMetadataVideoAccess::DeleteRecordL Record deleted" ) );
       
  1260             }
       
  1261 
       
  1262         delete iColSet;
       
  1263         iColSet = NULL;
       
  1264         iRecordSet.Close();
       
  1265         }
       
  1266     PRINT( _L( "MM MTP <= CMmMtpDpMetadataVideoAccess::DeleteRecordL" ) );
       
  1267     }
       
  1268 
       
  1269 // ---------------------------------------------------------------------------
       
  1270 // CMmMtpDpMetadataMpxAccess::DeleteAllRecordsL
       
  1271 // Empties the database - used by the FormatStore command
       
  1272 // ---------------------------------------------------------------------------
       
  1273 //
       
  1274 void CMmMtpDpMetadataVideoAccess::DeleteAllRecordsL()
       
  1275     {
       
  1276     PRINT( _L( "MM MTP => CMmMtpDpMetadataVideoAccess::DeleteAllRecordsL()" ) );
       
  1277 
       
  1278     //open database if not opened
       
  1279     if (!IsDatabaseOpened())
       
  1280         OpenDatabaseL();
       
  1281 
       
  1282     SetRecordL( KNullDesC, ENoRecord );   // Commit any other changes to the DB
       
  1283 
       
  1284     PRINT( _L( "MM MTP <> Deleting music files" ) );
       
  1285     ExecuteQueryL( KAllColumns, KMtpVideoTable );
       
  1286 
       
  1287     for ( iRecordSet.FirstL(); iRecordSet.AtRow(); iRecordSet.NextL() )
       
  1288         {
       
  1289         iRecordSet.DeleteL();
       
  1290         }
       
  1291 
       
  1292     delete iColSet;
       
  1293     iColSet = NULL;
       
  1294     iRecordSet.Close();
       
  1295 
       
  1296     iDatabase.Compact();
       
  1297     PRINT( _L( "MM MTP <= CMmMtpDpMetadataVideoAccess::DeleteAllRecordsL()" ) );
       
  1298     }
       
  1299 
       
  1300 // ---------------------------------------------------------------------------
       
  1301 // CMmMtpDpMetadataMpxAccess::SetRecordL
       
  1302 // Set Record
       
  1303 // ---------------------------------------------------------------------------
       
  1304 //
       
  1305 void CMmMtpDpMetadataVideoAccess::SetRecordL( const TDesC& aFullFileName, TMtpDbState aState )
       
  1306     {
       
  1307     PRINT( _L( "MM MTP => CMmMtpDpMetadataVideoAccess::SetRecordL()" ) );
       
  1308 
       
  1309     if ( ( aState == iDbState )
       
  1310             && ( 0 == aFullFileName.Compare( iCurrentFileName ) ) )    // Already have it
       
  1311         {
       
  1312         if (iDbState == ERecordRead)
       
  1313             iRecordSet.GetL();
       
  1314 
       
  1315         PRINT1( _L( "MM MTP <> Cached recordset, filename is '%S'" ), &iCurrentFileName );
       
  1316         return;
       
  1317         }
       
  1318 
       
  1319     iCurrentFileName.Copy( aFullFileName );
       
  1320     PRINT1( _L( "MM MTP <> CMmMtpDpMetadataVideoAccess::iCurrentFileName set to '%S'" ), &iCurrentFileName );
       
  1321 
       
  1322     // We arrive here, if a new view is required.  First, need to deal with the old one.
       
  1323     switch ( iDbState )
       
  1324         {
       
  1325         case EFailedWrite:
       
  1326             // We wrote to the DB, but the op failed
       
  1327             PRINT( _L( "MM MTP <> SetRecordL EFailedWrite" ) );
       
  1328             iRecordSet.Cancel();
       
  1329 
       
  1330         case ERecordWrite:              // intentionally fallthrough
       
  1331             // We wrote some stuff to the db, now needs comitting
       
  1332             PRINT( _L( "MM MTP <> SetRecordL ERecordWrite" ) );
       
  1333             TRAPD( err, iRecordSet.PutL() );
       
  1334 
       
  1335             if (KErrNone != err)
       
  1336                 {
       
  1337                 iRecordSet.Cancel();
       
  1338                 User::Leave( err );
       
  1339                 }
       
  1340         //lint -fallthrough
       
  1341         case ENoRecord:                 // intentionally fallthrough
       
  1342             // We need to just close the open record
       
  1343             PRINT( _L( "MM MTP <> SetRecordL ENoRecord" ) );
       
  1344         //lint -fallthrough
       
  1345         case ERecordRead:               // intentionally fallthrough
       
  1346             // We need to open a row for reading
       
  1347             PRINT( _L( "MM MTP <> SetRecordL ERecordRead" ) );
       
  1348         //lint -fallthrough
       
  1349         default:                        // intentionally fallthrough
       
  1350             PRINT( _L( "MM MTP <> SetRecordL Closing recordset" ) );
       
  1351             delete iColSet;
       
  1352             iColSet = NULL;
       
  1353             iRecordSet.Close();
       
  1354             iDbState = ENoRecord;
       
  1355             break;
       
  1356         }
       
  1357 
       
  1358     if ( aState == ENoRecord )    // We are closing the session if this is the case
       
  1359         {
       
  1360         PRINT( _L( "MM MTP <> SetRecordL Record closed, no request to open" ) );
       
  1361         return;
       
  1362         }
       
  1363 
       
  1364     // if we have a music format, we can open the database...
       
  1365     TUint16 format = MmMtpDpUtility::FormatFromFilename( iCurrentFileName );
       
  1366     PRINT1( _L( "MM MTP <> SetRecordL format = 0x%x" ), format );
       
  1367 
       
  1368 
       
  1369     if ( MmMtpDpUtility::HasMetadata( format ) )
       
  1370         {
       
  1371         // Get the record
       
  1372         ExecuteQueryL( KAllColumns, KMtpVideoTable, KMtpVideoLocation, aFullFileName );
       
  1373 
       
  1374         if ( iRecordSet.CountL() == 0 ) // No match...
       
  1375             {
       
  1376             iRecordSet.Close();
       
  1377             PRINT( _L( "MM MTP <> Recordset is empty! Bailing out..." ) );
       
  1378             delete iColSet;
       
  1379             iColSet = NULL;
       
  1380             iRecordSet.Close();
       
  1381             iDbState = ENoRecord;
       
  1382             User::Leave( KErrNotFound );  // Have an object on the disk, but no metadata
       
  1383             }
       
  1384 
       
  1385         // Check that we only have one record, not many...
       
  1386         if ( iRecordSet.CountL() > 1 )
       
  1387             {
       
  1388             //LOGTEXT2("METADATA DATABASE ERROR: %d entries for the same file name!!", iRecordSet.CountL());
       
  1389             User::Leave( KErrCorrupt );
       
  1390             }
       
  1391 
       
  1392         if ( aState == ERecordWrite )
       
  1393             {
       
  1394             iRecordSet.UpdateL();    // Lock the row
       
  1395             PRINT( _L( "MM MTP <> Row locked" ) );
       
  1396             }
       
  1397         else if ( aState == ERecordRead )
       
  1398             {
       
  1399             iRecordSet.GetL();
       
  1400             }
       
  1401 
       
  1402         // Update the internal state
       
  1403         iDbState = aState;
       
  1404         }
       
  1405     else
       
  1406         User::Leave( KErrNotFound );
       
  1407 
       
  1408     PRINT( _L( "MM MTP <= CMmMtpDpMetadataVideoAccess::SetRecordL()" ) );
       
  1409     }
       
  1410 
       
  1411 // ---------------------------------------------------------------------------
       
  1412 // CMmMtpDpMetadataMpxAccess::SetImageObjPropL
       
  1413 // set image specific properties specific to videos
       
  1414 // ---------------------------------------------------------------------------
       
  1415 //
       
  1416 void CMmMtpDpMetadataVideoAccess::SetImageObjPropL( const TDesC& aFullFileName,
       
  1417     const TUint32 aWidth,
       
  1418     const TUint32 aHeight )
       
  1419     {
       
  1420     PRINT( _L( "MM MTP => CMmMtpDpMetadataVideoAccess::SetImageObjPropL()" ) );
       
  1421 
       
  1422     if ( !IsDatabaseOpened() )
       
  1423         OpenDatabaseL();
       
  1424 
       
  1425     TDbColNo num = 0;
       
  1426     TInt err = KErrNone;
       
  1427 
       
  1428     SetRecordL( aFullFileName, ERecordWrite );
       
  1429     num = iColSet->ColNo( KMtpVideoWidth );
       
  1430     TRAP( err, iRecordSet.SetColL( num, aWidth ) );
       
  1431 
       
  1432     if ( err != KErrNone )
       
  1433        {
       
  1434        SetRecordL( aFullFileName, EFailedWrite );
       
  1435        User::Leave( err );
       
  1436        }
       
  1437 
       
  1438     num = iColSet->ColNo( KMtpVideoHeight );
       
  1439     TRAP( err, iRecordSet.SetColL( num, aHeight ) );
       
  1440 
       
  1441     if ( err != KErrNone )
       
  1442        {
       
  1443        SetRecordL( aFullFileName, EFailedWrite );
       
  1444        User::Leave( err );
       
  1445        }
       
  1446     PRINT( _L( "MM MTP <= CMmMtpDpMetadataVideoAccess::SetImageObjPropL()" ) );
       
  1447     }
       
  1448 
       
  1449 // ---------------------------------------------------------------------------
       
  1450 // CMmMtpDpMetadataMpxAccess::GetImageObjPropL
       
  1451 // Get image specific properties specific to videos
       
  1452 // ---------------------------------------------------------------------------
       
  1453 //
       
  1454 void CMmMtpDpMetadataVideoAccess::GetImageObjPropL( const TDesC& aFullFileName,
       
  1455     TUint32& aWidth,
       
  1456     TUint32& aHeight )
       
  1457     {
       
  1458     PRINT( _L( "MM MTP => CMmMtpDpMetadataVideoAccess::GetImageObjPropL()" ) );
       
  1459 
       
  1460     if ( !IsDatabaseOpened() )
       
  1461         OpenDatabaseL();
       
  1462 
       
  1463     TDbColNo num = 0;
       
  1464 
       
  1465     SetRecordL( aFullFileName, ERecordRead );
       
  1466 
       
  1467     num = iColSet->ColNo( KMtpVideoWidth );
       
  1468     aWidth = iRecordSet.ColUint32( num );
       
  1469 
       
  1470     num = iColSet->ColNo( KMtpVideoHeight );
       
  1471     aHeight = iRecordSet.ColUint32( num );
       
  1472 
       
  1473     PRINT( _L( "MM MTP <= CMmMtpDpMetadataVideoAccess::GetImageObjPropL()" ) );
       
  1474     }
       
  1475 
       
  1476 const TDesC& CMmMtpDpMetadataVideoAccess::ColumnNameFromPropCodeL( const TUint16 aPropCode )
       
  1477     {
       
  1478     const TColumnNameTable KColumnTable[] =
       
  1479     {
       
  1480         { EMTPObjectPropCodeName,                    KMtpVideoName },
       
  1481         { EMTPObjectPropCodeArtist,                  KMtpVideoArtist },
       
  1482         { EMTPObjectPropCodeTrack,                   KMtpVideoTrack },
       
  1483         { EMTPObjectPropCodeGenre,                   KMtpVideoGenre },
       
  1484         { EMTPObjectPropCodeAlbumName,               KMtpVideoAlbumName },
       
  1485         { EMTPObjectPropCodeComposer,                KMtpVideoComposer },
       
  1486         { EMTPObjectPropCodeOriginalReleaseDate,     KMtpVideoOrigReleaseDate },
       
  1487         { EMTPObjectPropCodeDescription,             KMtpVideoComment },
       
  1488         { EMTPObjectPropCodeWidth,                   KMtpVideoWidth },
       
  1489         { EMTPObjectPropCodeHeight,                  KMtpVideoHeight },
       
  1490         { EMTPObjectPropCodeDuration,                KMtpVideoDuration },
       
  1491         { EMTPObjectPropCodeSampleRate,              KMtpVideoSampleRate },
       
  1492         { EMTPObjectPropCodeNumberOfChannels,        KMtpVideoNumberOfChannels },
       
  1493         { EMTPObjectPropCodeAudioBitRate,            KMtpVideoAudioBitrate },
       
  1494         { EMTPObjectPropCodeVideoFourCCCodec,        KMtpVideoVideoCodec },
       
  1495         { EMTPObjectPropCodeVideoBitRate,            KMtpVideoVideoBitrate },
       
  1496         { EMTPObjectPropCodeFramesPerThousandSeconds,KMtpVideoFramesPer1000Sec },
       
  1497         { EMTPObjectPropCodeKeyFrameDistance,        KMtpVideoKeyFrameDistance },
       
  1498         { EMTPObjectPropCodeScanType,                KMtpVideoScanType },
       
  1499         { EMTPObjectPropCodeEncodingProfile,         KMtpVideoEncodingProfile },
       
  1500         { EMTPObjectPropCodeParentalRating,          KMtpVideoParentalRating },
       
  1501         { EMTPObjectPropCodeUseCount,                KMtpVideoUseCount },
       
  1502         { EMTPObjectPropCodeAudioWAVECodec,          KMtpVideoAudioCodec },
       
  1503         { EMTPObjectPropCodeDRMStatus,               KMtpVideoDRM },
       
  1504     };
       
  1505 
       
  1506     TInt i = 0;
       
  1507     TInt count = sizeof ( KColumnTable ) / sizeof ( KColumnTable[0] );
       
  1508     while ( ( KColumnTable[i].iPropCode != aPropCode ) && ( i < count ) )
       
  1509         {
       
  1510         i++;
       
  1511         }
       
  1512 
       
  1513     if ( i == count )
       
  1514         {
       
  1515         // Not supported by MPX, shouldn't call this function
       
  1516         PRINT( _L( "MM MTP <> CMmMtpDpMetadataMpxAccess::MpxAttribFromPropL NOT SUPPORTED ATTRIBUTE" ) );
       
  1517         User::Leave( KErrNotSupported );
       
  1518         }
       
  1519     return KColumnTable[i].iDbColumnName;
       
  1520     }
       
  1521 
       
  1522 void CMmMtpDpMetadataVideoAccess::SetStorageRootL( const TDesC& aStorageRoot )
       
  1523     {
       
  1524     PRINT1( _L( "MM MTP => CMmMtpDpMetadataMpxAccess::SetStorageRoot aStoreRoot = %S" ), &aStorageRoot );
       
  1525 
       
  1526     // get the drive number
       
  1527     TParse pathParser;
       
  1528     User::LeaveIfError( pathParser.Set( aStorageRoot, NULL, NULL ) );
       
  1529     TChar driveChar( pathParser.Drive()[0] );
       
  1530 
       
  1531     User::LeaveIfError( RFs::CharToDrive( driveChar, iStoreNum ) );
       
  1532     PRINT1( _L( "MM MTP <= CMmMtpDpMetadataMpxAccess::SetStorageRoot drive number = %d" ), iStoreNum );
       
  1533     }
       
  1534 
       
  1535 void CMmMtpDpMetadataVideoAccess::CleanupDatabaseL()
       
  1536     {
       
  1537     PRINT( _L( "MM MTP => CMmMtpDpMetadataVideoAccess::CleanupDatabaseL" ) );
       
  1538 
       
  1539     //open database if not opened
       
  1540     if ( !IsDatabaseOpened() )
       
  1541         {
       
  1542         return;
       
  1543         }
       
  1544 
       
  1545     // Make sure the db is commited
       
  1546     SetRecordL( KNullDesC, ENoRecord );
       
  1547 
       
  1548     IdentifyDeletedFilesL();
       
  1549 
       
  1550     CleanupDbIfNecessaryL();
       
  1551 
       
  1552     PRINT( _L( "MM MTP <= CMmMtpDpMetadataVideoAccess::CleanupDatabaseL" ) )
       
  1553     }
       
  1554 
       
  1555 TBool CMmMtpDpMetadataVideoAccess::FileExists( const TDesC& aFullFileName )
       
  1556     {
       
  1557     return BaflUtils::FileExists( iRfs, aFullFileName );
       
  1558     }
       
  1559 
       
  1560 // end of file