homesync/contentmanager/cmserver/cmstoremanager/src/cmsmclfmngr.cpp
changeset 0 7f85d04be362
equal deleted inserted replaced
-1:000000000000 0:7f85d04be362
       
     1 /*
       
     2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "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:  Store music file processing
       
    15 *  Version     : %version: tr1ido#9.1.2 % << Don't touch!
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 #include <ContentListingFactory.h>
       
    22 #include <MCLFContentListingEngine.h>
       
    23 #include <MCLFItem.h>
       
    24 #include <MCLFSortingStyle.h>
       
    25 #include "upnpfileutility.h"
       
    26 
       
    27 #include "cmstorelistitem.h"
       
    28 #include "cmsmfilemngr.h"
       
    29 #include "cmsmclfmngr.h"
       
    30 #include "msdebug.h"
       
    31 
       
    32 // CONSTANTS
       
    33  _LIT( KCmSmIconExtension, ".fil" );
       
    34  _LIT( ROM1, "Z" );
       
    35  _LIT( ROM2, "z" );
       
    36 // Once filter maximum count;
       
    37 const TInt KFilterMaxCount = 10;
       
    38         
       
    39 // ---------------------------------------------------------------------------
       
    40 // CCmSmClfMngr::NewL
       
    41 // ---------------------------------------------------------------------------
       
    42 // 
       
    43 CCmSmClfMngr* CCmSmClfMngr::NewL( MCmSmMusicMngrObserver& aObserver, 
       
    44     CCmSmFileMngr& aFileMngr, RPointerArray<CCmStoreListItem>& aItems )
       
    45     {
       
    46     LOG(_L("[STORE MNGR]\t CCmSmClfMngr::NewL() start"));    
       
    47     CCmSmClfMngr* self = CCmSmClfMngr::NewLC(
       
    48         aObserver, aFileMngr, aItems );
       
    49     CleanupStack::Pop( self );
       
    50     LOG(_L("[STORE MNGR]\t CCmSmClfMngr::NewL() end")); 
       
    51     return self;
       
    52     }
       
    53 
       
    54 // ---------------------------------------------------------------------------
       
    55 // CCmSmClfMngr::NewLC
       
    56 // ---------------------------------------------------------------------------
       
    57 //     
       
    58 CCmSmClfMngr* CCmSmClfMngr::NewLC( MCmSmMusicMngrObserver& aObserver, 
       
    59     CCmSmFileMngr& aFileMngr, RPointerArray<CCmStoreListItem>& aItems )
       
    60     {
       
    61     LOG(_L("[STORE MNGR]\t CCmSmClfMngr::NewLC() start"));     
       
    62     CCmSmClfMngr* self = new ( ELeave ) CCmSmClfMngr(
       
    63         aObserver, aFileMngr, aItems );
       
    64     CleanupStack::PushL( self );
       
    65     self->ConstructL();
       
    66     LOG(_L("[STORE MNGR]\t CCmSmClfMngr::NewLC() end"));     
       
    67     return self;  
       
    68     }    
       
    69 
       
    70 // ---------------------------------------------------------------------------
       
    71 // CCmSmClfMngr::~CCmSmClfMngr
       
    72 // ---------------------------------------------------------------------------
       
    73 // 
       
    74 CCmSmClfMngr::~CCmSmClfMngr()
       
    75     {
       
    76     LOG(_L("[STORE MNGR]\t CCmSmClfMngr::\
       
    77         ~CCmSmClfMngr() start"));
       
    78     Cancel();
       
    79     CancelClfRefresh();
       
    80     delete iNewAudioItems;
       
    81     delete iNewImageItems;
       
    82     delete iNewVideoItems;    
       
    83     delete iEngine;
       
    84     delete iSortingStyle;    
       
    85     LOG(_L("[STORE MNGR]\t CCmSmClfMngr::\
       
    86         ~CCmSmClfMngr() end"));            
       
    87     }
       
    88 
       
    89 // ---------------------------------------------------------------------------
       
    90 // CCmSmClfMngr::CCmSmClfMngr
       
    91 // ---------------------------------------------------------------------------
       
    92 //            
       
    93 CCmSmClfMngr::CCmSmClfMngr( MCmSmMusicMngrObserver& aObserver, 
       
    94     CCmSmFileMngr& aFileMngr, RPointerArray<CCmStoreListItem>& aItems )
       
    95     :CActive( EPriorityStandard ),
       
    96     iObserver( aObserver ), iFileMngr( aFileMngr ),
       
    97     iItems( aItems )
       
    98     {
       
    99     CActiveScheduler::Add( this );
       
   100     }
       
   101 
       
   102 // ---------------------------------------------------------------------------
       
   103 // CCmSmClfMngr::ConstructL
       
   104 // ---------------------------------------------------------------------------
       
   105 //  
       
   106 void CCmSmClfMngr::ConstructL()
       
   107     {
       
   108     LOG(_L("[STORE MNGR]\t CCmSmClfMngr::ConstructL()"));
       
   109     iEngine = ContentListingFactory::NewContentListingEngineLC();
       
   110     CleanupStack::Pop();
       
   111     iNewAudioItems = iEngine->CreateListModelLC( *this );
       
   112     CleanupStack::Pop();
       
   113     
       
   114     // Creating a temporary pointer since ContentListingFactory interface 
       
   115     // forces us to use LC-method and we don't want to assign an member 
       
   116     // variable with LC-method.
       
   117     MCLFSortingStyle* sortingStyle = 
       
   118         ContentListingFactory::NewSortingStyleLC();
       
   119     CleanupStack::Pop(); // can't pop by name here
       
   120     iSortingStyle = sortingStyle;
       
   121     sortingStyle = NULL;
       
   122     
       
   123     iSortingStyle->SetOrdering( ECLFOrderingAscending );
       
   124     iSortingStyle->SetSortingDataType( ECLFItemDataTypeDesC );  
       
   125     }   
       
   126     
       
   127 // ---------------------------------------------------------------------------
       
   128 // CCmSmClfMngr::CancelClfRefresh
       
   129 // ---------------------------------------------------------------------------
       
   130 //
       
   131 void CCmSmClfMngr::CancelClfRefresh()
       
   132     {
       
   133     LOG(_L("[STORE MNGR]\t CCmSmClfMngr::CancelClfRefresh()"));
       
   134     if( iNewAudioItems )
       
   135         {
       
   136         iNewAudioItems->CancelRefresh();
       
   137         }                 
       
   138     }
       
   139 
       
   140 // ---------------------------------------------------------------------------
       
   141 // CCmSmClfMngr::CancelOperation
       
   142 // ---------------------------------------------------------------------------
       
   143 //    
       
   144 void CCmSmClfMngr::CancelOperation()
       
   145     {
       
   146     LOG(_L("[STORE MNGR]\t CCmSmClfMngr::CancelOperation"));    
       
   147     
       
   148     if ( IsActive() )
       
   149         {
       
   150         Cancel();    
       
   151         }
       
   152     CancelClfRefresh();
       
   153     iObserver.MusicReady( ECmSmProcessingCanceled );
       
   154     }
       
   155 
       
   156 // ---------------------------------------------------------------------------
       
   157 // CCmSmClfMngr::SetupCLFListModelsL
       
   158 // ---------------------------------------------------------------------------
       
   159 //    
       
   160 void CCmSmClfMngr::SetupCLFListModelsL( TCmMediaType aMediaType )
       
   161     {
       
   162     LOG(_L("[STORE MNGR]\t SetupCLFListModelsL"));
       
   163     
       
   164     RArray< TInt > mediaTypes;
       
   165     CleanupClosePushL( mediaTypes );
       
   166         
       
   167     switch(aMediaType)
       
   168         {
       
   169         case ECmAudio:
       
   170             {
       
   171             mediaTypes.AppendL( ECLFMediaTypeMusic );
       
   172             mediaTypes.AppendL( ECLFMediaTypeSound );
       
   173             iNewAudioItems->SetWantedMediaTypesL( mediaTypes.Array() );
       
   174             iNewAudioItems->SetSortingStyle( iSortingStyle );
       
   175             break;
       
   176             }                      
       
   177         default:
       
   178             {
       
   179             break;
       
   180             }    
       
   181         }
       
   182     CleanupStack::PopAndDestroy( &mediaTypes );
       
   183     }
       
   184 
       
   185 // ---------------------------------------------------------------------------
       
   186 // CCmSmClfMngr::DoRefreshL
       
   187 // ---------------------------------------------------------------------------
       
   188 //
       
   189 void CCmSmClfMngr::DoRefreshL( TCmMediaType aMediaType )
       
   190     {
       
   191     LOG(_L("[STORE MNGR]\t CCmSmClfMngr::DoRefreshL"));
       
   192     
       
   193     switch( aMediaType )
       
   194         {
       
   195         case ECmAudio:
       
   196             {
       
   197             SetupCLFListModelsL( aMediaType );
       
   198             iNewAudioItems->RefreshL();
       
   199             break;
       
   200             }      
       
   201         default:
       
   202             {
       
   203             LOG(_L("[STORE MNGR]\t DoRefreshL invariant media type"));
       
   204             User::Invariant();
       
   205             }
       
   206         }
       
   207     }
       
   208 
       
   209 // ---------------------------------------------------------------------------
       
   210 // CCmSmClfMngr::FilterItemsL
       
   211 // ---------------------------------------------------------------------------
       
   212 //    
       
   213 void CCmSmClfMngr::FilterItemsL()
       
   214     {
       
   215     LOG(_L("[STORE MNGR]\t CCmSmClfMngr::DoRefreshL"));
       
   216     TRACE(Print( _L("[STORE MNGR]\t Filter file start index = %d"), 
       
   217                                                              iFilterIndex ) );
       
   218     TCmSmFileProcessingStatus status = ECmSmNone;
       
   219     if ( iFilterIndex < iNewAudioItems->ItemCount() )
       
   220         {
       
   221         RArray<TInt>ids;
       
   222         CleanupClosePushL( ids );
       
   223         iFileMngr.MediaTypesL( ids, ECmAudio );
       
   224         FilterNewItemsL( iNewAudioItems, ids, ECmAudio );
       
   225         CleanupStack::PopAndDestroy( &ids );
       
   226         status = ECmSmContinueFiltering;
       
   227         }
       
   228     else
       
   229         { 
       
   230         status = ECmSmFilteringReady;
       
   231         }
       
   232     
       
   233     TRACE(Print( _L("[STORE MNGR]\t Filter file end index = %d"), 
       
   234                                                              iFilterIndex ) );
       
   235     CompleteRequest( status );    
       
   236     }
       
   237 
       
   238 // ---------------------------------------------------------------------------
       
   239 // CCmSmClfMngr::FilterNewItemsL
       
   240 // ---------------------------------------------------------------------------
       
   241 //
       
   242 void CCmSmClfMngr::FilterNewItemsL( MCLFItemListModel* aNewItems, 
       
   243     RArray<TInt>aDeviceIds, TCmMediaType aType )
       
   244     {
       
   245     LOG(_L("[STORE MNGR]\t Filtering defined media type items"));
       
   246     
       
   247     TInt allCount = aNewItems->ItemCount();
       
   248     
       
   249     RArray<TInt>storeIds;
       
   250     CleanupClosePushL( storeIds );
       
   251     RArray<TInt>storedIds;
       
   252     CleanupClosePushL( storedIds );
       
   253     
       
   254     // Copy all file names
       
   255     TInt count = ( iFilterIndex + KFilterMaxCount ) <= allCount ? 
       
   256                                 KFilterMaxCount : ( allCount - iFilterIndex );
       
   257     TRACE(Print( _L("[STORE MNGR]\t FilterNewItemsL file count = %d"), 
       
   258                                                                     count ) );
       
   259 
       
   260     TBool drm( EFalse );        
       
   261     for ( TInt i = 0; i < count; i++ )
       
   262         {
       
   263         storeIds.Reset();         
       
   264         
       
   265         // Copy ids into temporary array
       
   266         for( TInt ll = 0; ll < aDeviceIds.Count(); ll++ )
       
   267             {
       
   268             storeIds.Append(aDeviceIds[ll]);
       
   269             }
       
   270         
       
   271         const MCLFItem& item = aNewItems->Item( iFilterIndex );
       
   272         // Fetch protection type
       
   273         TPtrC fileName;
       
   274         TPtrC path;
       
   275         TInt32 size( 0 );
       
   276         TTime date;
       
   277         TPtrC album;
       
   278         TPtrC mediaType;
       
   279         TPtrC pathAndFileName;
       
   280         TPtrC fileExtension;
       
   281         User::LeaveIfError( item.GetField( ECLFFieldIdPath, path ));
       
   282         User::LeaveIfError( item.GetField( ECLFFieldIdFileName, fileName ));
       
   283         User::LeaveIfError( item.GetField( ECLFFieldIdFileSize, size ));
       
   284         User::LeaveIfError( item.GetField( ECLFFieldIdFileDate, date ));
       
   285         User::LeaveIfError( item.GetField( ECLFFieldIdFileNameAndPath, 
       
   286             pathAndFileName ));
       
   287         User::LeaveIfError( item.GetField( ECLFFieldIdFileExtension,
       
   288             fileExtension ) );    
       
   289         
       
   290         // Album list is needed for UI use
       
   291         TInt error( item.GetField( ECLFFieldIdAlbum, album ) );    
       
   292             
       
   293         TRACE(Print( _L("[STORE MNGR]\t %03d: %S"), i, &fileName ) );
       
   294         
       
   295         // If the items is not an DRM item and album isn't in excluded list, 
       
   296         // it is a potential candidate to be added into list of 
       
   297         // files to transfer.
       
   298         TRAP( error, drm = 
       
   299             UPnPFileUtility::IsFileProtectedL( pathAndFileName ) );
       
   300         TRACE( Print( _L("[STORE MNGR]\t IsFileProtectedL err = %d"), error));
       
   301         if ( pathAndFileName[0] != ROM1()[0] 
       
   302             && pathAndFileName[0] != ROM2()[0] 
       
   303             && !drm 
       
   304             && KErrNotFound == fileExtension.Match( KCmSmIconExtension ) )
       
   305             {
       
   306             if( iFileMngr.CheckIsFilledFileL( pathAndFileName ) )
       
   307                 {
       
   308                 storeIds.Reset();                
       
   309                 }
       
   310             iFileMngr.IsAlreadyStoreL( pathAndFileName, storedIds, storeIds );
       
   311             // If file is already stored to every wanted server
       
   312             // => no need to keep file on the list any longer    
       
   313             if( KErrNone < storeIds.Count() )
       
   314                 {
       
   315                 TCmListItemStatus status;
       
   316                 CCmStoreListItem* item = CCmStoreListItem::NewLC();                
       
   317                 item->SetPrimaryTextL( fileName );
       
   318                 item->SetPathL( pathAndFileName );
       
   319                 item->SetSize( size );
       
   320                 item->SetDate( date );
       
   321                 item->SetListId( iFileMngr.RetrieveListId( aType ) );
       
   322                 // Ms id values are binded with file status values 
       
   323                 iFileMngr.RetrieveListStatusValues( aType, status );
       
   324                 // Where item will be stored 
       
   325                 for( TInt s = 0 ; s < storeIds.Count(); s++ )
       
   326                     {
       
   327                     item->SetDevId( storeIds[s], status );    
       
   328                     }
       
   329                 // Where item has already been stored
       
   330                 for( TInt d = 0; d < storedIds.Count(); d++ )
       
   331                     {
       
   332                     item->SetDevId( storedIds[d], ECmStored );
       
   333                     }
       
   334                 iItems.AppendL( item );
       
   335                 CleanupStack::Pop( item );                
       
   336                 }
       
   337             storedIds.Reset();         
       
   338             }              
       
   339         iFilterIndex++;
       
   340         }
       
   341     
       
   342     CleanupStack::PopAndDestroy( &storedIds );
       
   343     CleanupStack::PopAndDestroy( &storeIds );         
       
   344     }
       
   345 
       
   346 // ---------------------------------------------------------------------------
       
   347 // CCmSmClfMngr::HandleOperationEventL
       
   348 // ---------------------------------------------------------------------------
       
   349 //     
       
   350 void CCmSmClfMngr::HandleOperationEventL(
       
   351     TCLFOperationEvent aOperationEvent, TInt aError )
       
   352     {
       
   353     LOG(_L("[STORE MNGR]\t CCmSmClfMngr::HandleOperationEventL"));
       
   354 
       
   355     if ( aOperationEvent == ECLFRefreshComplete )
       
   356         {
       
   357         switch ( aError )
       
   358             {
       
   359             case KErrNone:
       
   360                 {
       
   361                 CompleteRequest( ECmSmAllRefreshed );
       
   362                 break;
       
   363                 }
       
   364             case KErrCancel:
       
   365                 {
       
   366                 iObserver.MusicReady( ECmSmProcessingCanceled );
       
   367                 break;
       
   368                 }
       
   369             default:
       
   370                 {
       
   371                 // Notify observer.
       
   372                 iObserver.MusicReady( ECmSmRefreshError );
       
   373                 break;
       
   374                 }
       
   375             }
       
   376         }
       
   377     }
       
   378     
       
   379 // ---------------------------------------------------------------------------
       
   380 // CCmSmClfMngr::CompleteRequest
       
   381 // ---------------------------------------------------------------------------
       
   382 // 
       
   383 void CCmSmClfMngr::CompleteRequest( 
       
   384     TCmSmFileProcessingStatus aStatus )
       
   385     {
       
   386     LOG(_L("[STORE MNGR]\t CCmSmClfMngr::CompleteRequest"));
       
   387     
       
   388     __ASSERT_DEBUG(!IsActive(),\
       
   389         User::Panic( KCmSmManager, KErrInUse ));          
       
   390     SetActive();        
       
   391     TRequestStatus* pStatus = &iStatus;
       
   392     User::RequestComplete( pStatus, aStatus );     
       
   393     }
       
   394     
       
   395 // ---------------------------------------------------------------------------
       
   396 // CCmSmClfMngr::RunL
       
   397 // ---------------------------------------------------------------------------
       
   398 //                 
       
   399 void CCmSmClfMngr::RunL()
       
   400     {
       
   401     TRACE(Print(_L("[STORE MNGR]\t CCmSmClfMngr::RunL\
       
   402          status = %d"), iStatus.Int() ));
       
   403          
       
   404     switch( iStatus.Int() )
       
   405         {       
       
   406         case ECmSmAllRefreshed:
       
   407             {
       
   408             CompleteRequest( ECmSmStartItemFiltering );  
       
   409             break;
       
   410             }
       
   411         case ECmSmStartItemFiltering:
       
   412             {
       
   413             iFilterIndex = 0;
       
   414             TRACE(Print( _L("[STORE MNGR]\t Need filter file count = %d"), 
       
   415                                               iNewAudioItems->ItemCount() ) );
       
   416             CompleteRequest( ECmSmContinueFiltering );
       
   417             break;
       
   418             }
       
   419         case ECmSmContinueFiltering:
       
   420             {
       
   421             FilterItemsL();
       
   422             break;
       
   423             }
       
   424         case ECmSmFilteringReady:
       
   425             {
       
   426             iObserver.MusicReady( KErrNone );
       
   427             break;
       
   428             }
       
   429         default:
       
   430             {
       
   431             LOG(_L("[STORE MNGR]\t Store file processing RunL default"));
       
   432             User::Invariant();
       
   433             break;
       
   434             }
       
   435         }
       
   436     }    
       
   437 
       
   438 // ---------------------------------------------------------------------------
       
   439 // CCmSmClfMngr::DoCancel
       
   440 // ---------------------------------------------------------------------------
       
   441 //    
       
   442 void CCmSmClfMngr::DoCancel()
       
   443     {
       
   444     LOG(_L("[STORE MNGR]\t CCmSmClfMngr::DoCancel"));
       
   445     }
       
   446                         
       
   447 // End of file
       
   448 
       
   449 
       
   450