upnpsharing/upnpcontentserver/src/upnpcontentmetadatautility.cpp
branchnew development branch with rendering state machine and other goodies
changeset 38 5360b7ddc251
parent 0 7f85d04be362
equal deleted inserted replaced
32:3785f754ee62 38:5360b7ddc251
    27 #include <ContentListingFactory.h>
    27 #include <ContentListingFactory.h>
    28 #include <MCLFItemListModel.h>
    28 #include <MCLFItemListModel.h>
    29 #include <CLFContentListing.hrh>
    29 #include <CLFContentListing.hrh>
    30 #include <MCLFItem.h>
    30 #include <MCLFItem.h>
    31 #include <f32file.h>
    31 #include <f32file.h>
    32 
    32 // Internal
    33 // upnp stack api
       
    34 #include <upnpitem.h>
       
    35 #include <upnpcontainer.h>
       
    36 #include <upnpstring.h>
       
    37 
       
    38 // upnpframework / avcontroller helper api
       
    39 #include "upnpfileutility.h"
       
    40 
       
    41 // upnpframework / internal api's
       
    42 #include "upnpcommonutils.h"
       
    43 #include "upnpmetadatautility.h"
       
    44 
       
    45 #include "upnpdlnaprofiler.h"
       
    46 #include "upnpcdsreselementutility.h"
       
    47 
       
    48 // homeconnect internal
       
    49 #include "upnpcontentmetadatautility.h"
    33 #include "upnpcontentmetadatautility.h"
    50 #include "upnpcustomgrouper.h"
       
    51 #include "upnppostfilter.h"
       
    52 
       
    53 #include "upnpcontentserverdefs.h"
    34 #include "upnpcontentserverdefs.h"
    54 
    35 
    55 _LIT( KComponentLogfile, "contentserver.txt");
    36 _LIT( KComponentLogfile, "contentserver.txt");
    56 #include "upnplog.h"
    37 #include "upnplog.h"
    57 
    38 
    58 // CONSTANTS
    39 // CONSTANTS
    59 _LIT( KUPnPFileListSeparator, "\t" );
       
    60 const TInt KMediaTypeArrGranularity(1);
    40 const TInt KMediaTypeArrGranularity(1);
    61 
    41 
    62 using namespace UpnpContentServer;
    42 using namespace UpnpContentServer;
    63 
    43 
    64 // ============================ MEMBER FUNCTIONS ============================
    44 // ============================ MEMBER FUNCTIONS ============================
    66 // CUpnpContentMetadataUtility::CUpnpContentMetadataUtility()
    46 // CUpnpContentMetadataUtility::CUpnpContentMetadataUtility()
    67 // Default constructor
    47 // Default constructor
    68 // --------------------------------------------------------------------------
    48 // --------------------------------------------------------------------------
    69 //
    49 //
    70 CUpnpContentMetadataUtility::CUpnpContentMetadataUtility()
    50 CUpnpContentMetadataUtility::CUpnpContentMetadataUtility()
    71     : iRefreshOngoing( ETrue )
    51     {
    72     {
    52     }
    73     }
    53 
    74 
    54 // --------------------------------------------------------------------------
       
    55 // CUpnpContentMetadataUtility::ConstructL()
       
    56 // ConstructL
       
    57 // --------------------------------------------------------------------------
       
    58 //
    75 void CUpnpContentMetadataUtility::ConstructL()
    59 void CUpnpContentMetadataUtility::ConstructL()
    76     {
    60     {
    77     __LOG8_1( "%s begin.", __PRETTY_FUNCTION__ );
    61     __LOG8_1( "%s begin.", __PRETTY_FUNCTION__ );
    78     // Create Content Listing Engine and a list model
    62     
       
    63     // Create iWait
       
    64     iWait = new (ELeave) CActiveSchedulerWait;
       
    65     
       
    66     // Create Content Listing Engine 
    79     iEngine = ContentListingFactory::NewContentListingEngineLC();
    67     iEngine = ContentListingFactory::NewContentListingEngineLC();
    80     CleanupStack::Pop();   // iEngine
    68     CleanupStack::Pop(); // iEngine
       
    69 
       
    70     // Create list models
    81     iMusicModel = iEngine->CreateListModelLC( *this );
    71     iMusicModel = iEngine->CreateListModelLC( *this );
    82     CleanupStack::Pop();    // iMusicModel
    72     CleanupStack::Pop(); // iMusicModel
    83 
       
    84     iImageModel = iEngine->CreateListModelLC( *this );
    73     iImageModel = iEngine->CreateListModelLC( *this );
    85     CleanupStack::Pop();    // iImageModel
    74     CleanupStack::Pop(); // iImageModel
    86 
       
    87     iVideoModel = iEngine->CreateListModelLC( *this );
    75     iVideoModel = iEngine->CreateListModelLC( *this );
    88     CleanupStack::Pop();    // iVideoModel
    76     CleanupStack::Pop(); // iVideoModel
    89 
    77 
    90     iCollectionModel = iEngine->CreateListModelLC( *this );
       
    91     CleanupStack::Pop();    // iCollectionModel
       
    92     // Set music media type filter to CLF
    78     // Set music media type filter to CLF
    93     RArray<TInt> musicArray( KMediaTypeArrGranularity );
    79     RArray<TInt> musicArray( KMediaTypeArrGranularity );
    94 
       
    95     CleanupClosePushL( musicArray );
    80     CleanupClosePushL( musicArray );
    96     musicArray.AppendL( ECLFMediaTypeMusic );
    81     musicArray.AppendL( ECLFMediaTypeMusic );
    97     iMusicModel->SetWantedMediaTypesL( musicArray.Array() );
    82     iMusicModel->SetWantedMediaTypesL( musicArray.Array() );
    98     CleanupStack::PopAndDestroy( &musicArray );
    83     CleanupStack::PopAndDestroy( &musicArray );
    99 
    84 
   100     // Set image media type filter to CLF
    85     // Set image media type filter to CLF
   101     RArray<TInt> imageArray( KMediaTypeArrGranularity );
    86     RArray<TInt> imageArray( KMediaTypeArrGranularity );
   102 
       
   103     CleanupClosePushL( imageArray );
    87     CleanupClosePushL( imageArray );
   104     imageArray.AppendL( ECLFMediaTypeImage );
    88     imageArray.AppendL( ECLFMediaTypeImage );
   105     iImageModel->SetWantedMediaTypesL( imageArray.Array() );
    89     iImageModel->SetWantedMediaTypesL( imageArray.Array() );
   106     CleanupStack::PopAndDestroy( &imageArray );
    90     CleanupStack::PopAndDestroy( &imageArray );
   107 
    91 
   110     CleanupClosePushL( videoArray );
    94     CleanupClosePushL( videoArray );
   111     videoArray.AppendL( ECLFMediaTypeVideo );
    95     videoArray.AppendL( ECLFMediaTypeVideo );
   112     iVideoModel->SetWantedMediaTypesL( videoArray.Array() );
    96     iVideoModel->SetWantedMediaTypesL( videoArray.Array() );
   113     CleanupStack::PopAndDestroy( &videoArray );
    97     CleanupStack::PopAndDestroy( &videoArray );
   114 
    98 
   115     // Set Collection media type filter to CLF
       
   116     RArray<TInt> collectionArray( KMediaTypeArrGranularity );
       
   117 
       
   118     CleanupClosePushL( collectionArray );
       
   119     collectionArray.AppendL( ECLFMediaTypeCollection );
       
   120     iCollectionModel->SetWantedMediaTypesL( collectionArray.Array() );
       
   121     CleanupStack::PopAndDestroy( &collectionArray );
       
   122 
       
   123     // Group items by collection name
       
   124     iCustomGrouper = CUpnpCustomGrouper::NewL( ECLFFieldIdCollectionName );
       
   125     iCollectionModel->SetCustomGrouper( iCustomGrouper );
       
   126 
       
   127     // Start to refresh the music files (HandleOperationEventL
       
   128     // callback comes when finished)
       
   129     iMusicModel->RefreshL();
       
   130     
       
   131     // Create metadata utility
       
   132     iMetaDataUtility = CUPnPMetaDataUtility::NewL();
       
   133 
       
   134     __LOG8_1( "%s end.", __PRETTY_FUNCTION__ );
    99     __LOG8_1( "%s end.", __PRETTY_FUNCTION__ );
   135     }
   100     }
   136 
   101 
   137 // --------------------------------------------------------------------------
   102 // --------------------------------------------------------------------------
   138 // CUpnpContentMetadataUtility::NewL()
   103 // CUpnpContentMetadataUtility::NewL()
   145     CUpnpContentMetadataUtility* self
   110     CUpnpContentMetadataUtility* self
   146         = new( ELeave ) CUpnpContentMetadataUtility;
   111         = new( ELeave ) CUpnpContentMetadataUtility;
   147 
   112 
   148     CleanupStack::PushL( self );
   113     CleanupStack::PushL( self );
   149     self->ConstructL();
   114     self->ConstructL();
   150     CleanupStack::Pop();
   115     CleanupStack::Pop( self );
   151     __LOG8_1( "%s end.", __PRETTY_FUNCTION__ );
   116     __LOG8_1( "%s end.", __PRETTY_FUNCTION__ );
   152     return self;
   117     return self;
   153     }
   118     }
   154 
   119 
   155 // --------------------------------------------------------------------------
   120 // --------------------------------------------------------------------------
   161     {
   126     {
   162     __LOG8_1( "%s begin.", __PRETTY_FUNCTION__ );
   127     __LOG8_1( "%s begin.", __PRETTY_FUNCTION__ );
   163     delete iMusicModel;
   128     delete iMusicModel;
   164     delete iImageModel;
   129     delete iImageModel;
   165     delete iVideoModel;
   130     delete iVideoModel;
   166     delete iCollectionModel;
       
   167     delete iPostFilter;
       
   168     delete iCustomGrouper;
       
   169     delete iEngine;
   131     delete iEngine;
   170     delete iMetaDataUtility;
   132     delete iWait;
   171     __LOG8_1( "%s end.", __PRETTY_FUNCTION__ );
   133     __LOG8_1( "%s end.", __PRETTY_FUNCTION__ );
   172     }
   134     }
   173 
   135 
   174 // --------------------------------------------------------------------------
   136 // --------------------------------------------------------------------------
   175 // CUpnpContentMetadataUtility::HandleOperationEventL
   137 // CUpnpContentMetadataUtility::HandleOperationEventL
   181     TInt /*aError*/ )
   143     TInt /*aError*/ )
   182     {
   144     {
   183     __LOG8_1( "%s begin.", __PRETTY_FUNCTION__ );
   145     __LOG8_1( "%s begin.", __PRETTY_FUNCTION__ );
   184     // Waiting is stopped when an event for refresh completion is received
   146     // Waiting is stopped when an event for refresh completion is received
   185     if( aOperationEvent == ECLFRefreshComplete )
   147     if( aOperationEvent == ECLFRefreshComplete )
   186 
   148         {
   187         {
   149         // stop iWait
   188         switch ( iRefreshCounter )
   150         if ( iWait->IsStarted() )
   189             {
   151             {
   190         case 0 :
   152             iWait->AsyncStop();
       
   153             }
       
   154         }
       
   155     __LOG8_1( "%s end.", __PRETTY_FUNCTION__ );
       
   156     }
       
   157 
       
   158 // --------------------------------------------------------------------------
       
   159 // CUpnpContentMetadataUtility::MusicFiles
       
   160 // ( other items are commented in header )
       
   161 // --------------------------------------------------------------------------
       
   162 //
       
   163 const MCLFItemListModel* CUpnpContentMetadataUtility::MusicFiles()
       
   164     {
       
   165     __LOG8_1( "%s begin.", __PRETTY_FUNCTION__ );
       
   166     MCLFItemListModel* ret = iMusicModel;
       
   167     TRAPD( err, RefreshModelL( ECLFMediaTypeMusic ) );
       
   168     if ( !err )
       
   169         {
       
   170         WaitForRefreshToComplete();
       
   171         }
       
   172     else
       
   173         {
       
   174         ret = NULL;
       
   175         }
       
   176     __LOG8_1( "%s end.", __PRETTY_FUNCTION__ );
       
   177     return ret;
       
   178     }
       
   179 
       
   180 // --------------------------------------------------------------------------
       
   181 // CUpnpContentMetadataUtility::ImageFiles
       
   182 // ( other items are commented in header )
       
   183 // --------------------------------------------------------------------------
       
   184 //
       
   185 const MCLFItemListModel* CUpnpContentMetadataUtility::ImageFiles()
       
   186     {
       
   187     __LOG8_1( "%s begin.", __PRETTY_FUNCTION__ );
       
   188     MCLFItemListModel* ret = iImageModel;
       
   189     TRAPD( err, RefreshModelL( ECLFMediaTypeImage ) );
       
   190     if ( !err )
       
   191         {
       
   192         WaitForRefreshToComplete();
       
   193         }
       
   194     else
       
   195         {
       
   196         ret = NULL;
       
   197         }
       
   198     __LOG8_1( "%s end.", __PRETTY_FUNCTION__ );
       
   199     return ret;
       
   200     }
       
   201 
       
   202 // --------------------------------------------------------------------------
       
   203 // CUpnpContentMetadataUtility::VideoFiles
       
   204 // ( other items are commented in header )
       
   205 // --------------------------------------------------------------------------
       
   206 //
       
   207 const MCLFItemListModel* CUpnpContentMetadataUtility::VideoFiles()
       
   208     {
       
   209     __LOG8_1( "%s begin.", __PRETTY_FUNCTION__ );
       
   210     MCLFItemListModel* ret = iVideoModel;
       
   211     TRAPD( err, RefreshModelL( ECLFMediaTypeVideo ) );
       
   212     if ( !err )
       
   213         {
       
   214         WaitForRefreshToComplete();
       
   215         }
       
   216     else
       
   217         {
       
   218         ret = NULL;
       
   219         }
       
   220     __LOG8_1( "%s end.", __PRETTY_FUNCTION__ );
       
   221     return ret;
       
   222     }
       
   223     
       
   224 // --------------------------------------------------------------------------
       
   225 // CUpnpContentMetadataUtility::RefreshModelL
       
   226 // ( other items are commented in header )
       
   227 // --------------------------------------------------------------------------
       
   228 void CUpnpContentMetadataUtility::RefreshModelL( 
       
   229     TCLFMediaType aCLFMediaType )
       
   230     {
       
   231     __LOG8_1( "%s begin.", __PRETTY_FUNCTION__ );
       
   232     switch ( aCLFMediaType )
       
   233         {
       
   234         case ECLFMediaTypeImage:
       
   235             {
       
   236             iImageModel->RefreshL();
       
   237             break;
       
   238             }
       
   239         case ECLFMediaTypeVideo:
   191             {
   240             {
   192             iVideoModel->RefreshL();
   241             iVideoModel->RefreshL();
   193             break;
   242             break;
   194             }
   243             }
   195         case 1 :
   244         case ECLFMediaTypeMusic:
   196             {
   245             {
   197             iImageModel->RefreshL();
   246             iMusicModel->RefreshL();
   198             break;
   247             break;
   199             }
   248             }
   200         case 2 :
   249         default:
   201             {
   250             {
   202             iCollectionModel->RefreshL();
   251             User::Leave( KErrNotSupported );
   203             break;
   252             break;
   204             }
   253             }
   205         case 3 :
   254         }
   206             {
   255     __LOG8_1( "%s end.", __PRETTY_FUNCTION__ );
   207 
   256     }
   208             iRefreshOngoing = EFalse;
   257 
   209             iRefreshCounter = 0;
   258 // --------------------------------------------------------------------------
   210             if ( iHandler )
   259 // CUpnpContentMetadataUtility::WaitForRefreshToComplete
   211                 {
   260 // ( other items are commented in header )
   212                 iHandler->RefreshDoneL();
   261 // --------------------------------------------------------------------------
   213                 }
   262 void CUpnpContentMetadataUtility::WaitForRefreshToComplete()
   214             __LOG("CUpnpContentMetadataUtility::HandleOperationEventL: \
   263     {
   215 Refresh done");
   264     __LOG8_1( "%s begin.", __PRETTY_FUNCTION__ );
   216             break;
   265     
   217 
   266     // start iWait
   218             }
   267     if ( !iWait->IsStarted() )
   219         default :
   268         {
   220             {
   269         iWait->Start();
   221             __LOG("CUpnpContentMetadataUtility::HandleOperationEventL: \
   270         }
   222 default: error");
   271 
   223             break;
   272     __LOG8_1( "%s end.", __PRETTY_FUNCTION__ );
   224             }
   273     }
   225 
   274     
   226             }
       
   227         if ( iRefreshOngoing )
       
   228             {
       
   229             iRefreshCounter++;
       
   230             }
       
   231         }
       
   232     __LOG8_1( "%s end.", __PRETTY_FUNCTION__ );
       
   233     }
       
   234 
       
   235 // --------------------------------------------------------------------------
       
   236 // CUpnpContentMetadataUtility::HandleItemChangeL
       
   237 // CLF content is changed --> model needs to be refreshed
       
   238 // --------------------------------------------------------------------------
       
   239 //
       
   240 void CUpnpContentMetadataUtility::HandleItemChangeL(
       
   241     const TArray<TCLFItemId>& /*aItemIDArray*/ )
       
   242     {
       
   243     __LOG8_1( "%s begin.", __PRETTY_FUNCTION__ );
       
   244     // Start to refresh the music files (HandleOperationEventL
       
   245     // callback comes when finished)
       
   246     iRefreshOngoing = ETrue;
       
   247     iMusicModel->RefreshL();
       
   248     iImageModel->RefreshL();
       
   249     iVideoModel->RefreshL();
       
   250     __LOG8_1( "%s end.", __PRETTY_FUNCTION__ );
       
   251     }
       
   252 
       
   253 // --------------------------------------------------------------------------
       
   254 // CUpnpContentMetadataUtility::HandleError
       
   255 // Method is used to handle errors in changed item event.
       
   256 // --------------------------------------------------------------------------
       
   257 //
       
   258 void CUpnpContentMetadataUtility::HandleError( TInt /*aError*/ )
       
   259     {
       
   260     __LOG8_1( "%s begin.", __PRETTY_FUNCTION__ );
       
   261     }
       
   262 
       
   263 
       
   264 // --------------------------------------------------------------------------
       
   265 // CUpnpContentMetadataUtility::MusicFiles
       
   266 // ( other items are commented in header )
       
   267 // --------------------------------------------------------------------------
       
   268 //
       
   269 const MCLFItemListModel& CUpnpContentMetadataUtility::MusicFiles() const
       
   270     {
       
   271     __LOG8_1( "%s begin.", __PRETTY_FUNCTION__ );
       
   272     return *iMusicModel;
       
   273     }
       
   274 
       
   275 // --------------------------------------------------------------------------
       
   276 // CUpnpContentMetadataUtility::ImageFiles
       
   277 // ( other items are commented in header )
       
   278 // --------------------------------------------------------------------------
       
   279 //
       
   280 const MCLFItemListModel& CUpnpContentMetadataUtility::ImageFiles() const
       
   281     {
       
   282     __LOG8_1( "%s begin.", __PRETTY_FUNCTION__ );
       
   283     return *iImageModel;
       
   284     }
       
   285 
       
   286 
       
   287 // --------------------------------------------------------------------------
       
   288 // CUpnpContentMetadataUtility::VideoFiles
       
   289 // ( other items are commented in header )
       
   290 // --------------------------------------------------------------------------
       
   291 //
       
   292 const MCLFItemListModel& CUpnpContentMetadataUtility::VideoFiles() const
       
   293     {
       
   294     __LOG8_1( "%s begin.", __PRETTY_FUNCTION__ );
       
   295     return *iVideoModel;
       
   296     }
       
   297 
       
   298 // --------------------------------------------------------------------------
       
   299 // CUpnpContentMetadataUtility::Collections
       
   300 // ( other items are commented in header )
       
   301 // --------------------------------------------------------------------------
       
   302 //
       
   303 const MCLFItemListModel& CUpnpContentMetadataUtility::Collections() const
       
   304     {
       
   305     __LOG8_1( "%s begin.", __PRETTY_FUNCTION__ );
       
   306     return *iCollectionModel;
       
   307     }
       
   308 
       
   309 
       
   310 
       
   311 // --------------------------------------------------------------------------
       
   312 // CUpnpContentMetadataUtility::GetCollectionFileNamesL
       
   313 // ( other items are commented in header )
       
   314 // --------------------------------------------------------------------------
       
   315 //
       
   316 void CUpnpContentMetadataUtility::GetCollectionFileNamesL( 
       
   317     CDesCArray& aFileArray,
       
   318     const TDesC& aFiles ) const
       
   319     {
       
   320     __LOG8_1( "%s begin.", __PRETTY_FUNCTION__ );
       
   321 
       
   322     TInt collectionLength( aFiles.Length() );
       
   323     TInt position( 0 );
       
   324     TInt dataPos( 0 );
       
   325     do
       
   326         {
       
   327         // Put filenames from ":" separeted row to aFileArray
       
   328         TPtrC data( aFiles.Right( collectionLength - position ) );
       
   329         dataPos = data.Find( KUPnPFileListSeparator );
       
   330         if( dataPos > 0 )
       
   331             {
       
   332             ++position; // skip KUPnPFileListSeparator
       
   333             position += dataPos;
       
   334             aFileArray.AppendL( data.Left( dataPos ) );
       
   335             }
       
   336         } while ( dataPos > 0 );
       
   337     __LOG8_1( "%s end.", __PRETTY_FUNCTION__ );
       
   338     }
       
   339 
       
   340 // --------------------------------------------------------------------------
       
   341 // CUpnpContentMetadataUtility::CollectionItemsL()
       
   342 // ( other items are commented in header )
       
   343 // --------------------------------------------------------------------------
       
   344 //
       
   345 void CUpnpContentMetadataUtility::CollectionItemsL( 
       
   346     const TDesC& aNameOfCollection )
       
   347     {
       
   348     __LOG8_1( "%s begin.", __PRETTY_FUNCTION__ );
       
   349     __LOG1( "CUpnpContentMetadataUtility: collection: %S",
       
   350                   &aNameOfCollection );
       
   351 
       
   352     //clear previous filtering
       
   353     iCollectionModel->SetPostFilter( NULL );
       
   354 
       
   355     // Delete old post filter if any
       
   356 
       
   357     delete iPostFilter;
       
   358     iPostFilter = NULL;
       
   359 
       
   360     // Create and activate a post filter for collection filtering
       
   361     // so that the model will contain only files
       
   362     // from selected collection
       
   363     iPostFilter = CUpnpPostFilter::NewL( ECLFFieldIdCollectionName,
       
   364                                             aNameOfCollection, EFalse );
       
   365     iCollectionModel->SetPostFilter( iPostFilter );
       
   366 
       
   367     iCollectionModel->RefreshL( ECLFRefreshPostFilter );
       
   368     __LOG8_1( "%s end.", __PRETTY_FUNCTION__ );
       
   369     }
       
   370 
       
   371 
       
   372 // --------------------------------------------------------------------------
       
   373 // CUpnpContentMetadataUtility::CreateItemL
       
   374 // Create the item with mandatory fields
       
   375 // --------------------------------------------------------------------------
       
   376 //
       
   377 CUpnpItem* CUpnpContentMetadataUtility::CreateItemL(
       
   378     const MCLFItem& aCLFItem,
       
   379     const TDesC8& aParentId ) const
       
   380     {
       
   381     __LOG8_1( "%s begin.", __PRETTY_FUNCTION__ );
       
   382 
       
   383     TPtrC fullFileName;
       
   384     TInt err( aCLFItem.GetField( ECLFFieldIdFileNameAndPath,
       
   385                                  fullFileName ));
       
   386     
       
   387     TInt32 filesize( 0 );
       
   388     TInt err1( aCLFItem.GetField( ECLFFieldIdFileSize, filesize ) );    
       
   389  
       
   390     CUpnpItem* newItem( NULL );
       
   391     
       
   392     if ( !err && !err1 && filesize )
       
   393         {
       
   394         newItem = CreateItemL( fullFileName, aParentId );
       
   395         }
       
   396     else
       
   397         {
       
   398         __LOG8_1( "MCLFItem ECLFFieldIdFileNameAndPath err= %d", err );
       
   399         __LOG8_1( "MCLFItem ECLFFieldIdFileSize err= %d", err1 );
       
   400         }
       
   401     
       
   402     __LOG8_1( "%s end.", __PRETTY_FUNCTION__ );
       
   403     return newItem;
       
   404     }
       
   405 
       
   406 // --------------------------------------------------------------------------
       
   407 // CUpnpContentMetadataUtility::CreateItemL
       
   408 // Update the basic fields, based on list of filenames
       
   409 // --------------------------------------------------------------------------
       
   410 //
       
   411 CUpnpItem* CUpnpContentMetadataUtility::CreateItemL(
       
   412     const TDesC& aFullFilename,
       
   413     const TDesC8& aParentId
       
   414     ) const
       
   415     {
       
   416     __LOG8_1( "%s begin.", __PRETTY_FUNCTION__ );
       
   417 
       
   418     CUpnpItem* newItem( NULL );
       
   419     
       
   420     TFileName path( aFullFilename );
       
   421     TBool isProtected( EFalse );
       
   422     TRAPD( err, 
       
   423            isProtected = UPnPFileUtility::IsFileProtectedL( path ) );
       
   424 
       
   425     if ( !isProtected && !err )
       
   426         {
       
   427         // title
       
   428         HBufC8* itemName( NULL );
       
   429         iMetaDataUtility->LoadTitleL( path );
       
   430         if( iMetaDataUtility->Title().Length() > 0 )
       
   431             {
       
   432             itemName = UpnpString::FromUnicodeL( 
       
   433                     iMetaDataUtility->Title() );
       
   434             }
       
   435         else
       
   436             {
       
   437             // If does not find the title, using filename instead
       
   438             TParse fileParser;
       
   439             fileParser.Set( path, NULL, NULL );
       
   440             itemName = UpnpString::FromUnicodeL( fileParser.Name() );
       
   441             }
       
   442         
       
   443         if ( itemName )
       
   444             {
       
   445             CleanupStack::PushL( itemName );
       
   446             
       
   447             newItem = CUpnpItem::NewL();
       
   448             CleanupStack::PushL( newItem );            
       
   449             newItem->SetTitleL( *itemName );            
       
   450             newItem->SetObjectClassL( KClassItem );
       
   451             newItem->SetParentIdL( aParentId );
       
   452             CleanupStack::Pop( newItem );
       
   453 
       
   454             CleanupStack::PopAndDestroy( itemName );
       
   455             }
       
   456         }
       
   457     else
       
   458         {
       
   459         __LOG8_1( "UPnPFileUtility::IsFileProtectedL err= %d", err );
       
   460         }
       
   461     
       
   462     __LOG8_1( "%s end.", __PRETTY_FUNCTION__ );
       
   463     return newItem;
       
   464     }
       
   465 
       
   466 // --------------------------------------------------------------------------
       
   467 // CUpnpContentMetadataUtility::RefreshOngoing() const
       
   468 // Used to check if refresh is ongoing.
       
   469 // --------------------------------------------------------------------------
       
   470 //
       
   471 
       
   472 TBool CUpnpContentMetadataUtility::RefreshOngoing() const
       
   473     {
       
   474     return iRefreshOngoing;
       
   475     }
       
   476 
       
   477 // --------------------------------------------------------------------------
       
   478 // CUpnpContentMetadataUtility::UpdateMetaDataL
       
   479 // Updates meta data for the item
       
   480 // --------------------------------------------------------------------------
       
   481 //
       
   482 TBool CUpnpContentMetadataUtility::UpdateMetadataL(
       
   483     const TUpnpMediaType& aMediaType, 
       
   484     CUpnpItem* aItem, 
       
   485     const TDesC& aFileName )
       
   486     {
       
   487     __LOG8_1( "%s begin.", __PRETTY_FUNCTION__ );
       
   488 
       
   489     // 1st use correct model according to item type
       
   490     MCLFItemListModel* model = NULL;
       
   491     switch( aMediaType )
       
   492         {
       
   493     case EMusicFile :
       
   494         {
       
   495         model = iMusicModel;
       
   496         break;
       
   497         }
       
   498     case EVideoFile :
       
   499         {
       
   500         model = iVideoModel;
       
   501         break;
       
   502         }
       
   503     case EPhotoFile :
       
   504         {
       
   505         model = iImageModel;
       
   506         break;
       
   507         }
       
   508     default:
       
   509         {
       
   510         break;
       
   511         }
       
   512         }
       
   513     // Then find the CLF item and update data from it
       
   514     TBool found = EFalse;
       
   515     TBool end = EFalse;
       
   516     TInt beginLoop = iClfIndex;
       
   517 
       
   518     // increment. If passed item count, start from beginning.
       
   519         iClfIndex = 0;
       
   520         beginLoop = -1;
       
   521 
       
   522     while ( model->ItemCount() && 
       
   523             !found && 
       
   524             !end )
       
   525         {
       
   526         // Get the item
       
   527         const MCLFItem& myItem = model->Item( iClfIndex );
       
   528         TPtrC fileName;
       
   529         TInt error = myItem.GetField( ECLFFieldIdFileNameAndPath,
       
   530                                       fileName );
       
   531 
       
   532         // if there was no error and file name matched
       
   533         if ( !error && aFileName.CompareF( fileName ) == 0 )
       
   534             {
       
   535             found = ETrue;
       
   536 
       
   537             // Get the mediatype
       
   538             TInt32 mediaType;
       
   539             TInt errorType = myItem.GetField( ECLFFieldIdMediaType,
       
   540                                               mediaType );
       
   541             // If it is music file, fill the meta data for it
       
   542             if ( !errorType && mediaType == ECLFMediaTypeMusic )
       
   543                 {
       
   544                 // Get title, artist, album & genre tag info of the item
       
   545                 // Test update the class as it is in 1.x
       
   546                 aItem->SetObjectClassL( 
       
   547                     KClassAudioMusicTrack );
       
   548 
       
   549                 TPtrC songArtist;
       
   550                 TInt errorArtist( myItem.GetField( ECLFFieldIdArtist,
       
   551                                                    songArtist ) );
       
   552                 if ( !errorArtist )
       
   553                     {
       
   554                     CUpnpElement* elArtist = CUpnpElement::NewL( 
       
   555                         KElementArtist );
       
   556                     CleanupStack::PushL( elArtist );
       
   557                     HBufC8* artist = UpnpString::FromUnicodeL( 
       
   558                         songArtist );
       
   559                     CleanupStack::PushL( artist );
       
   560                     elArtist->SetValueL( *artist );
       
   561                     // UPnP stack needs filepath
       
   562                     elArtist->SetFilePathL( aFileName );
       
   563                     CleanupStack::PopAndDestroy( artist );
       
   564                     aItem->AddElementL( elArtist ); // transfer own..
       
   565                     CleanupStack::Pop( elArtist );
       
   566                     }
       
   567                 TPtrC songAlbum;
       
   568                 TInt errorAlbum( myItem.GetField( ECLFFieldIdAlbum,
       
   569                                                   songAlbum ) );
       
   570                 if ( !errorAlbum )
       
   571                     {
       
   572                     CUpnpElement* elAlbum = CUpnpElement::NewL( 
       
   573                         KElementAlbum );
       
   574                     CleanupStack::PushL( elAlbum );
       
   575                     HBufC8* album = UpnpString::FromUnicodeL( songAlbum );
       
   576 
       
   577                     CleanupStack::PushL( album );
       
   578                     elAlbum->SetValueL( *album );
       
   579                     // UPnP stack needs filepath
       
   580                     elAlbum->SetFilePathL( aFileName );
       
   581                     CleanupStack::PopAndDestroy( album );
       
   582                     aItem->AddElementL( elAlbum ); // transfer own..
       
   583                     CleanupStack::Pop( elAlbum );
       
   584                     }
       
   585                 TPtrC songGenre;
       
   586                 TInt errorGenre( myItem.GetField( ECLFFieldIdGenre,
       
   587                                                   songGenre ) );
       
   588                 if ( !errorGenre )
       
   589                     {
       
   590                     CUpnpElement* elGenre = CUpnpElement::NewL( 
       
   591                         KElementGenre );
       
   592                     CleanupStack::PushL( elGenre );
       
   593                     HBufC8* genre = UpnpString::FromUnicodeL( songGenre );
       
   594 
       
   595                     CleanupStack::PushL( genre );
       
   596                     elGenre->SetValueL( *genre );
       
   597                     // UPnP stack needs filepath
       
   598                     elGenre->SetFilePathL( aFileName );
       
   599                     CleanupStack::PopAndDestroy( genre );
       
   600                     aItem->AddElementL( elGenre ); // transfer own..
       
   601                     CleanupStack::Pop( elGenre );
       
   602 
       
   603                     }
       
   604                 }
       
   605             else if ( !errorType && mediaType == ECLFMediaTypeImage )
       
   606                 {
       
   607                 // Just set correct object class
       
   608                 aItem->SetObjectClassL( KImageItemObjectClass );
       
   609                 }
       
   610             else if ( !errorType && mediaType == ECLFMediaTypeVideo )
       
   611                 {
       
   612                 // Just set correct object class
       
   613                 aItem->SetObjectClassL( KVideoItemObjectClass );
       
   614                 }
       
   615 
       
   616             // Below this happens to ALL media types
       
   617             TTime dateTime;
       
   618             TInt errorDate( myItem.GetField( ECLFFieldIdFileDate,
       
   619                                              dateTime ) );
       
   620 
       
   621         if ( !errorDate )
       
   622                 {
       
   623                 HBufC* date = NULL;
       
   624                 TRAP( errorDate, date = 
       
   625                     UPnPCommonUtils::TTimeToUPnPDateL(dateTime));
       
   626                 
       
   627                 
       
   628                 if(date && errorDate == KErrNone)
       
   629                     {
       
   630                     CleanupStack::PushL( date );
       
   631                     
       
   632                     CUpnpElement* elDate = CUpnpElement::NewL( 
       
   633                     KElementDate );
       
   634                     CleanupStack::PushL( elDate );
       
   635                 
       
   636                     
       
   637                     HBufC8* date8 = UpnpString::FromUnicodeL( *date );
       
   638                     CleanupStack::PushL( date8 );
       
   639                     elDate->SetValueL( *date8 );
       
   640               
       
   641                     CleanupStack::PopAndDestroy( date8 );
       
   642                     
       
   643                     elDate->SetFilePathL( aFileName );
       
   644                     aItem->AddElementL( elDate ); // transfer own..
       
   645                 
       
   646                     CleanupStack::Pop( elDate );
       
   647                     CleanupStack::Pop( date );
       
   648                     }
       
   649                     
       
   650                
       
   651                 if(date)
       
   652                     {
       
   653                     delete date; 
       
   654                     date = NULL;
       
   655                     }
       
   656                 }
       
   657 
       
   658             }
       
   659         else
       
   660             {
       
   661             // The item was not found
       
   662             if ( iClfIndex != beginLoop )
       
   663                 {
       
   664                 if ( ++iClfIndex >= model->ItemCount() )
       
   665                     {
       
   666                     iClfIndex = 0;
       
   667                     end = ETrue;
       
   668                     }
       
   669                 }
       
   670             else
       
   671                 {
       
   672                 end = ETrue;
       
   673                 __LOG("end=ETRue");
       
   674                 }
       
   675             }
       
   676         } // while
       
   677     if( found )
       
   678         {
       
   679         __LOG("CUpnpContentMetadataUtility:: item found");
       
   680         }
       
   681     else
       
   682         {
       
   683         __LOG("CUpnpContentMetadataUtility:: item not found");
       
   684         }
       
   685 
       
   686     __LOG8_1( "%s end.", __PRETTY_FUNCTION__ );
       
   687     return found;
       
   688     }
       
   689 
       
   690 // --------------------------------------------------------------------------
       
   691 // CUpnpContentMetadataUtility::ClearPostFiltersL
       
   692 // ( other items are commented in header )
       
   693 // --------------------------------------------------------------------------
       
   694 void CUpnpContentMetadataUtility::ClearPostFiltersL()
       
   695     {
       
   696     __LOG8_1( "%s begin.", __PRETTY_FUNCTION__ );
       
   697     //clear previous filtering
       
   698     iCollectionModel->SetPostFilter( NULL );
       
   699 
       
   700     // Delete old post filter if any
       
   701 
       
   702     delete iPostFilter;
       
   703     iPostFilter = NULL;
       
   704     
       
   705     iCollectionModel->RefreshL( ECLFRefreshPostFilter );
       
   706 
       
   707    // Set the default postfilter
       
   708     iPostFilter = CUpnpPostFilter::NewL( ECLFFieldIdCollectionName,
       
   709                                          KNullDesC, ETrue );
       
   710     iCollectionModel->SetPostFilter( iPostFilter );
       
   711 
       
   712     iCollectionModel->RefreshL( ECLFRefreshPostFilter );
       
   713     __LOG8_1( "%s end.", __PRETTY_FUNCTION__ );
       
   714     }
       
   715 
       
   716 // --------------------------------------------------------------------------
       
   717 // CUpnpContentMetadataUtility::SetCallback
       
   718 // ( other items are commented in header )
       
   719 // --------------------------------------------------------------------------
       
   720 void CUpnpContentMetadataUtility::SetCallback( 
       
   721     MUpnpMetadataObserver* aObserver )
       
   722     {
       
   723     iHandler = aObserver;
       
   724 
       
   725     }
       
   726 
       
   727 //  End of File
   275 //  End of File