mmappcomponents/mmmtpdataprovider/src/cmmmtpdpmetadatavideoaccess.cpp
branchRCL_3
changeset 67 16db3449d7ba
parent 63 91d5ad76f5c6
equal deleted inserted replaced
63:91d5ad76f5c6 67:16db3449d7ba
    38 #include "mmmtpdputility.h"
    38 #include "mmmtpdputility.h"
    39 #include "tmmmtpdppanic.h"
    39 #include "tmmmtpdppanic.h"
    40 #include "mmmtpvideodbdefs.h"
    40 #include "mmmtpvideodbdefs.h"
    41 #include "tobjectdescription.h"
    41 #include "tobjectdescription.h"
    42 
    42 
    43 _LIT( KMTPNoBackupFolder, "nobackup\\" );
    43 const TInt KStorageRootMaxLength = 10;
    44 
    44 
    45 #ifdef _DEBUG
    45 #ifdef _DEBUG
    46 static const TInt KMtpMaxStringDescLength = KMtpMaxStringLength - 1;
    46 static const TInt KMtpMaxStringDescLength = KMtpMaxStringLength - 1;
    47 #endif
    47 #endif
    48 
    48 
    87     iQueryText = HBufC::NewL( KMaxQueryLength );
    87     iQueryText = HBufC::NewL( KMaxQueryLength );
    88 
    88 
    89     User::LeaveIfError( iDbsSession.Connect() );
    89     User::LeaveIfError( iDbsSession.Connect() );
    90 
    90 
    91     TInt err = DriveInfo::GetDefaultDrive( DriveInfo::EDefaultPhoneMemory, iStoreNum );
    91     TInt err = DriveInfo::GetDefaultDrive( DriveInfo::EDefaultPhoneMemory, iStoreNum );
    92     PRINT1( _L( "MM MTP <> CMmMtpDpMetadataVideoAccess::ConstructL, EDefaultPhoneMemory err = %d" ), err );
       
    93     User::LeaveIfError( err );
       
    94 
    92 
    95     err = OpenDatabase();
    93     err = OpenDatabase();
    96 
    94 
    97     if ( KErrNone != err )
    95     if ( KErrNone != err )
    98         {
    96         {
   107 //
   105 //
   108 TInt CMmMtpDpMetadataVideoAccess::OpenDatabase()
   106 TInt CMmMtpDpMetadataVideoAccess::OpenDatabase()
   109     {
   107     {
   110     PRINT( _L( "MM MTP => CMmMtpDpMetadataVideoAccess::OpenDatabase" ) );
   108     PRINT( _L( "MM MTP => CMmMtpDpMetadataVideoAccess::OpenDatabase" ) );
   111 
   109 
   112     TFileName dbFileName;
   110     iRfs.CreatePrivatePath( iStoreNum );
   113     TDriveUnit dbDrive( iStoreNum );
   111     TInt err = iRfs.SetSessionToPrivate( iStoreNum );
   114     iRfs.PrivatePath( dbFileName );
   112 
   115     dbFileName.Insert( 0, dbDrive.Name() );
   113     if ( err == KErrNone )
   116     dbFileName.Append( KMTPNoBackupFolder );
   114         {
   117     dbFileName.Append( KMtpVideoDb );
   115         TRAP( err, iFileStore = CPermanentFileStore::OpenL( iRfs, KMtpVideoDb, EFileRead | EFileWrite ) );
   118     TInt err = iRfs.MkDirAll( dbFileName );
       
   119 
       
   120     if ( err == KErrNone || err == KErrAlreadyExists )
       
   121         {
       
   122         TRAP( err, iFileStore = CPermanentFileStore::OpenL( iRfs, dbFileName, EFileRead | EFileWrite ) );
       
   123 
   116 
   124         if ( err == KErrNone )
   117         if ( err == KErrNone )
   125             TRAP( err, iFileStore->SetTypeL( iFileStore->Layout() ) );
   118             TRAP( err, iFileStore->SetTypeL( iFileStore->Layout() ) );
   126 
   119 
   127         if ( err == KErrNone )
   120         if ( err == KErrNone )
   130             PRINT1( _L( "MM MTP <> OpenDatabase RDbNamedDatabase::OpenL, err = %d" ), err );
   123             PRINT1( _L( "MM MTP <> OpenDatabase RDbNamedDatabase::OpenL, err = %d" ), err );
   131             }
   124             }
   132 
   125 
   133         if ( err != KErrNone )
   126         if ( err != KErrNone )
   134             {
   127             {
   135             iRfs.Delete( dbFileName );   // delete first before creating a new one
   128             iRfs.Delete( KMtpVideoDb );   // delete first before creating a new one
   136             TRAP( err, iFileStore = CPermanentFileStore::CreateL( iRfs, dbFileName, EFileRead | EFileWrite ) );
   129             TRAP( err, iFileStore = CPermanentFileStore::CreateL( iRfs, KMtpVideoDb, EFileRead | EFileWrite ) );
   137             PRINT1( _L( "MM MTP <> OpenDatabase RDbNamedDatabase::CreateL, err = %d" ), err );
   130             PRINT1( _L( "MM MTP <> OpenDatabase RDbNamedDatabase::CreateL, err = %d" ), err );
   138 
   131 
   139             if ( err == KErrNone )
   132             if ( err == KErrNone )
   140                 {
   133                 {
   141                 TRAP( err, iFileStore->SetTypeL( iFileStore->Layout() ) );
   134                 TRAP( err, iFileStore->SetTypeL( iFileStore->Layout() ) );
   152                     TRAP( err, CreateDatabaseTablesL() );
   145                     TRAP( err, CreateDatabaseTablesL() );
   153 
   146 
   154                 if ( KErrNone != err )
   147                 if ( KErrNone != err )
   155                     {
   148                     {
   156                     iDatabase.Close();
   149                     iDatabase.Close();
   157                     iRfs.Delete( dbFileName );
   150                     iRfs.Delete( KMtpVideoDb );
   158                     }
   151                     }
   159                 }
   152                 }
   160             }
   153             }
   161         }
   154         }
   162 
   155 
       
   156     TBuf<KStorageRootMaxLength> storeRoot;
       
   157     err = PathInfo::GetRootPath( storeRoot, iStoreNum );
       
   158     iRfs.SetSessionPath( storeRoot );
       
   159 
   163     if ( err == KErrNone )
   160     if ( err == KErrNone )
   164         {
   161         {
   165         iDbOpened = ETrue;
   162         iDbOpened = ETrue;
   166         }
   163         }
   167 
   164 
   168     PRINT1( _L( "MM MTP <= CMmMtpDpMetadataVideoAccess::OpenDatabase err = %d" ), err );
   165     PRINT( _L( "MM MTP <= CMmMtpDpMetadataVideoAccess::OpenDatabase" ) );
   169     return err;
   166     return err;
   170     }
   167     }
   171 
   168 
   172 // ---------------------------------------------------------------------------
   169 // ---------------------------------------------------------------------------
   173 // CMmMtpDpMetadataVideoAccess::OpenDatabaseL
   170 // CMmMtpDpMetadataVideoAccess::OpenDatabaseL
   350     ExecuteQueryL( KAllColumns, KMtpVideoTable, KMtpVideoDeleted, KTrue, EFalse, EFalse );
   347     ExecuteQueryL( KAllColumns, KMtpVideoTable, KMtpVideoDeleted, KTrue, EFalse, EFalse );
   351     PRINT1( _L( "MM MTP <> CleanupDbIfNecessaryL Database deleted count = %d" ), iRecordSet.CountL() );
   348     PRINT1( _L( "MM MTP <> CleanupDbIfNecessaryL Database deleted count = %d" ), iRecordSet.CountL() );
   352 
   349 
   353     for ( iRecordSet.FirstL(); iRecordSet.AtRow(); iRecordSet.NextL() )
   350     for ( iRecordSet.FirstL(); iRecordSet.AtRow(); iRecordSet.NextL() )
   354         {
   351         {
   355 #ifdef _DEBUG
       
   356         HBufC* data = ReadLongTextL( KMtpVideoLocation );
   352         HBufC* data = ReadLongTextL( KMtpVideoLocation );
       
   353         CleanupStack::PushL( data );
   357 
   354 
   358         PRINT1( _L( "MM MTP <> CleanupDbIfNecessaryL removing %S from database" ), data );
   355         PRINT1( _L( "MM MTP <> CleanupDbIfNecessaryL removing %S from database" ), data );
   359         delete data;
       
   360         data = NULL;
       
   361 #endif
       
   362         iRecordSet.DeleteL();
   356         iRecordSet.DeleteL();
       
   357         CleanupStack::PopAndDestroy( data );
   363         }
   358         }
   364 
   359 
   365     delete iColSet;
   360     delete iColSet;
   366     iColSet = NULL;
   361     iColSet = NULL;
   367     iRecordSet.Close();
   362     iRecordSet.Close();
   709     //open database if not opened
   704     //open database if not opened
   710     if ( !IsDatabaseOpened() )
   705     if ( !IsDatabaseOpened() )
   711         OpenDatabaseL();
   706         OpenDatabaseL();
   712 
   707 
   713     // File Path
   708     // File Path
   714     const TDesC& suid = aObjectMetaData.DesC( CMTPObjectMetaData::ESuid );
   709     HBufC* suid = aObjectMetaData.DesC( CMTPObjectMetaData::ESuid ).AllocLC();  // + suid
   715     SetRecordL( suid, ERecordRead );
   710     SetRecordL( *suid, ERecordRead );
       
   711     CleanupStack::PopAndDestroy( suid ); // - suid
   716 
   712 
   717     HBufC* data = NULL;
   713     HBufC* data = NULL;
   718     TDbColNo num;
   714     TDbColNo num;
   719     TUint32 uInt32 = 0;
   715     TUint32 uInt32 = 0;
   720     TUint16 uInt16 = 0;
   716     TUint16 uInt16 = 0;
   781 
   777 
   782         case EMTPObjectPropCodeDescription:
   778         case EMTPObjectPropCodeDescription:
   783             {
   779             {
   784             PRINT( _L( "MM MTP <> EMTPObjectPropCodeDescription-MD" ) );
   780             PRINT( _L( "MM MTP <> EMTPObjectPropCodeDescription-MD" ) );
   785             data = ReadLongTextL( KMtpVideoComment );
   781             data = ReadLongTextL( KMtpVideoComment );
   786             CleanupStack::PushL( data ); // + data
       
   787 
   782 
   788             TInt len = data->Length();
   783             TInt len = data->Length();
   789             PRINT1( _L( "MM MTP <> CMmMtpDpMetadataMpxAccess::GetObjectMetadataValue len = %d" ),len );
   784             PRINT1( _L( "MM MTP <> CMmMtpDpMetadataMpxAccess::GetObjectMetadataValue len = %d" ),len );
   790             for ( TInt i = 0; i < len; i++ )
   785             if ( len != 0 )
   791                 ( ( CMTPTypeArray& ) aNewData ).AppendUintL( ( *data )[i] );
   786                 {
   792 
   787                 for ( TInt i = 0; i < len; i++ )
   793             CleanupStack::PopAndDestroy( data ); // - data
   788                     ( ( CMTPTypeArray& ) aNewData ).AppendUintL( ( *data )[i] );
       
   789                 }
       
   790 
       
   791             delete data;
   794             data = NULL;
   792             data = NULL;
   795             }
   793             }
   796             break;
   794             break;
   797 
   795 
   798         case EMTPObjectPropCodeWidth:
   796         case EMTPObjectPropCodeWidth:
  1025         }
  1023         }
  1026 
  1024 
  1027     // Pack the info to aNewData
  1025     // Pack the info to aNewData
  1028     if ( data )
  1026     if ( data )
  1029         {
  1027         {
  1030         CleanupStack::PushL( data ); // + data
       
  1031 #ifdef _DEBUG
  1028 #ifdef _DEBUG
  1032         if ( data->Length() > KMtpMaxStringDescLength )   // Have to concatenate for MTP
  1029         if ( data->Length() > KMtpMaxStringDescLength )   // Have to concatenate for MTP
  1033             {
  1030             {
  1034             PRINT1( _L( "MM MTP <> Descriptor will be concatenated from length %d to KMtpMaxStringLength" ), data->Length() );
  1031             PRINT1( _L( "MM MTP <> Descriptor will be concatenated from length %d to KMtpMaxStringLength" ), data->Length() );
  1035             }
  1032             }
  1041             }
  1038             }
  1042         else
  1039         else
  1043             {
  1040             {
  1044             User::Leave( KErrArgument );
  1041             User::Leave( KErrArgument );
  1045             }
  1042             }
  1046         CleanupStack::PopAndDestroy( data ); // - data
  1043         delete data;
       
  1044         data = NULL;
  1047         }
  1045         }
  1048 
  1046 
  1049     PRINT( _L( "MM MTP <= CMmMtpDpMetadataVideoAccess::GetObjectMetadataValue" ) );
  1047     PRINT( _L( "MM MTP <= CMmMtpDpMetadataVideoAccess::GetObjectMetadataValue" ) );
  1050     }
  1048     }
  1051 
  1049