homesync/contentmanager/cmserver/cmfillmanager/src/cmfmfillrulefilleddatamngr.cpp
branchIOP_Improvements
changeset 40 08b5eae9f9ff
parent 39 6369bfd1b60d
child 41 b4d83ea1d6e2
equal deleted inserted replaced
39:6369bfd1b60d 40:08b5eae9f9ff
     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:  Fill rule and filled data processing
       
    15 *  Version     : %version: ou1s60rt#18 % << Don't touch!
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 #include <e32property.h>
       
    22 #include "upnpdlnautility.h"
       
    23 #include "cmsqlmainfactory.h"
       
    24 #include "mcmsqlmain.h"
       
    25 #include "cmdmmain.h"
       
    26 #include "cmfillrule.h"
       
    27 #include "cmfillrulecontainer.h"
       
    28 #include "cmsqlpropertyitem.h"
       
    29 #include "cmmediaserverfull.h"
       
    30 #include "cmfilllistitem.h"
       
    31 #include "cmfmmain.h"
       
    32 #include "cmfmao.h"
       
    33 #include "cmfmfillrulefilleddatamngr.h"
       
    34 #include "msdebug.h"
       
    35 
       
    36 // Constants
       
    37 const TInt KCmFmIniDownloadDataAmount = 300; // 300 kBs
       
    38 const TInt KCmFmIniDownloadTime = 1; // One second
       
    39 
       
    40 
       
    41 // ---------------------------------------------------------------------------
       
    42 // CCmFmFillRuleFilledDataMngr::NewL
       
    43 // ---------------------------------------------------------------------------
       
    44 //
       
    45 CCmFmFillRuleFilledDataMngr* CCmFmFillRuleFilledDataMngr::NewL(
       
    46     MCmFmFillRuleObserver* aObserver, CCmDmMain* aDBMngr,
       
    47     RPointerArray<CCmFillListItem>& aItems )
       
    48     {
       
    49     LOG(_L("[FILL MNGR]\t CCmFmFillRuleFilledDataMngr::NewL() start"));    
       
    50     CCmFmFillRuleFilledDataMngr* self = CCmFmFillRuleFilledDataMngr::NewLC(
       
    51         aObserver, aDBMngr, aItems );
       
    52     CleanupStack::Pop( self );
       
    53     LOG(_L("[FILL MNGR]\t CCmFmFillRuleFilledDataMngr::NewL() end")); 
       
    54     return self;
       
    55     }
       
    56 
       
    57 // ---------------------------------------------------------------------------
       
    58 // CCmFmFillRuleFilledDataMngr::NewLC
       
    59 // ---------------------------------------------------------------------------
       
    60 //    
       
    61 CCmFmFillRuleFilledDataMngr* CCmFmFillRuleFilledDataMngr::NewLC(
       
    62     MCmFmFillRuleObserver* aObserver, CCmDmMain* aDBMngr,
       
    63     RPointerArray<CCmFillListItem>& aItems )
       
    64     {
       
    65     LOG(_L("[FILL MNGR]\t CCmFmFillRuleFilledDataMngr::NewLC() start"));     
       
    66     CCmFmFillRuleFilledDataMngr* self = 
       
    67         new ( ELeave ) CCmFmFillRuleFilledDataMngr( aObserver, aDBMngr, 
       
    68                                                     aItems );
       
    69     CleanupStack::PushL( self );
       
    70     self->ConstructL();
       
    71     LOG(_L("[FILL MNGR]\t CCmFmFillRuleFilledDataMngr::NewLC() end"));     
       
    72     return self;  
       
    73     }    
       
    74 
       
    75 // ---------------------------------------------------------------------------
       
    76 // CCmFmFillRuleFilledDataMngr::~CCmFmFillRuleFilledDataMngr
       
    77 // ---------------------------------------------------------------------------
       
    78 //
       
    79 CCmFmFillRuleFilledDataMngr::~CCmFmFillRuleFilledDataMngr()
       
    80     {
       
    81     LOG(_L("[FILL MNGR]\t CCmFmFillRuleFilledDataMngr::\
       
    82         ~CCmFmFillRuleFilledDataMngr() start"));
       
    83     Cancel();
       
    84     
       
    85     if ( iWrapper )
       
    86         {
       
    87         iWrapper->Close();    
       
    88         }    
       
    89     
       
    90     if ( iAo )
       
    91         {
       
    92         delete iAo;      
       
    93         }
       
    94     
       
    95     iObserver = NULL;
       
    96     iDBManager = NULL;
       
    97     
       
    98     if ( iContainer )
       
    99         {
       
   100         delete iContainer;    
       
   101         }
       
   102     
       
   103     iRuleArray.Reset();
       
   104     iRuleArray.Close();
       
   105     
       
   106     iUpdateItems.Reset();
       
   107     iUpdateItems.Close();        
       
   108     
       
   109     iPropertys.ResetAndDestroy();
       
   110     
       
   111     iFileIds.Close();
       
   112     iMetadataServersToBeDeleted.Close();
       
   113     iOldIds.Close();
       
   114     iFs.Close();
       
   115     iFilteredProfiles.Reset();
       
   116     LOG(_L("[FILL MNGR]\t CCmFmFillRuleFilledDataMngr::\
       
   117         ~CCmFmFillRuleFilledDataMngr() end"));
       
   118     }
       
   119 
       
   120 // ---------------------------------------------------------------------------
       
   121 // CCmFmFillRuleFilledDataMngr::CCmFmFillRuleFilledDataMngr
       
   122 // ---------------------------------------------------------------------------
       
   123 //            
       
   124 CCmFmFillRuleFilledDataMngr::CCmFmFillRuleFilledDataMngr( 
       
   125     MCmFmFillRuleObserver* aObserver, CCmDmMain* aDBMngr,
       
   126     RPointerArray<CCmFillListItem>& aItems )
       
   127     :CActive( EPriorityStandard ), iObserver( aObserver ), 
       
   128     iDBManager( aDBMngr ), iItems(aItems)
       
   129     {
       
   130     LOG(_L("[FILL MNGR]\t CCmFmFillRuleFilledDataMngr::\
       
   131     CCmFmFillRuleFilledDataMngr()"));    
       
   132     
       
   133     CActiveScheduler::Add( this );
       
   134     iTransferInfo.iService = ECmServiceTransferInfoFill;
       
   135     }
       
   136 
       
   137 // ---------------------------------------------------------------------------
       
   138 // CCmFmFillRuleFilledDataMngr::ConstructL
       
   139 // ---------------------------------------------------------------------------
       
   140 //  
       
   141 void CCmFmFillRuleFilledDataMngr::ConstructL()
       
   142     {
       
   143     LOG(_L("[FILL MNGR]\t CCmFmFillRuleFilledDataMngr::ConstructL()"));   
       
   144     User::LeaveIfError( iFs.Connect() );                           
       
   145     }
       
   146 
       
   147 // ---------------------------------------------------------------------------
       
   148 // CCmFmFillRuleFilledDataMngr::OperationCompletedL
       
   149 // ---------------------------------------------------------------------------
       
   150 // 
       
   151 void CCmFmFillRuleFilledDataMngr::OperationCompletedL( TInt aStatus )
       
   152     {
       
   153     LOG(_L("[FILL MNGR]\t CCmFmFillRuleFilledDataMngr::\
       
   154     OperationCompletedL()"));
       
   155     
       
   156     iQueryFinished.HomeTime();
       
   157     TTimeIntervalMicroSeconds usecsFrom = 
       
   158         iQueryFinished.MicroSecondsFrom( iQueryStart );
       
   159     TRACE(Print(_L("[FILL MNGR]\t Query \
       
   160         took = %ld mseconds"), ( usecsFrom.Int64() / 1000 ) ));    
       
   161     
       
   162     if( KErrNone == aStatus )
       
   163         {
       
   164         switch( iProcessingState )
       
   165             {
       
   166             case ECmFmLoadingPropertys:
       
   167                 {
       
   168                 // Loading propertys ready
       
   169                 CompleteRequest( EColumnDataReady );
       
   170                 break;
       
   171                 }
       
   172             case ECmFmLoadingMetadata:
       
   173                 {
       
   174                 // Loading file metadata ready ( for one fill list )
       
   175                 iNewItemCount = iItems.Count() - iNewItemCount;              
       
   176                 CompleteRequest( EQueryCompleted );
       
   177                 break;
       
   178                 }
       
   179             case ECmFmDeletingMetadata:
       
   180                 {
       
   181                 // Metadata deleted from defined media servers
       
   182                 TRAPD( err, DeleteHashCodesL() );
       
   183                 iMetadataServersToBeDeleted.Reset();
       
   184                 iMetadataServersToBeDeleted.Close();
       
   185                 iWrapper->DeleteUnusedPropertys( );
       
   186                 if( !err )
       
   187                     {
       
   188                     CompleteRequest( EMetadataDeleted );
       
   189                     }
       
   190                 else
       
   191                     {
       
   192                     TRACE(Print(_L("[FILL MNGR]\t \
       
   193                         OperationCompletedL err %d "), err ));                    
       
   194                     }                                    
       
   195                 break;
       
   196                 }
       
   197             case ECmFmLoadingProfileIds:
       
   198                 {
       
   199                 DefineAndSetDlnaProfileIdFiltersL();
       
   200                 PreprocessListsL();
       
   201                 break;
       
   202                 }
       
   203             default:
       
   204                 {
       
   205                 LOG(_L("[FILL MNGR]\t OperationCompletedL processing \
       
   206                 state not found"));
       
   207                 break;
       
   208                 }    
       
   209             }         
       
   210         }
       
   211     else
       
   212         {        
       
   213         TRACE(Print(_L("[FILL MNGR]\t OperationCompletedL aStatus = %d"), 
       
   214             aStatus ));        
       
   215         }         
       
   216     }
       
   217 
       
   218 // ---------------------------------------------------------------------------
       
   219 // CCmFmFillRuleFilledDataMngr::LoadProfileIdsL
       
   220 // ---------------------------------------------------------------------------
       
   221 //
       
   222 void CCmFmFillRuleFilledDataMngr::LoadProfileIdsL()
       
   223     {
       
   224     LOG(_L("[FILL MNGR]\t CCmFmFillRuleFilledDataMngr::LoadProfileIdsL()"));
       
   225     // Loads all dlna profile ids from database. Profile ids are used
       
   226     // to filter out unsupported media types
       
   227     iPropertys.ResetAndDestroy();
       
   228     iProcessingState = ECmFmLoadingProfileIds;
       
   229     CreateWrapperL();
       
   230     StartObserverL();
       
   231     iWrapper->GetPropertyValuesL( iPropertys, iAo->iStatus, 
       
   232         ECmProfileId, ECmAll );
       
   233     iQueryStart.HomeTime();
       
   234     iAo->RunL();    
       
   235     }
       
   236         
       
   237 // ---------------------------------------------------------------------------
       
   238 // CCmFmFillRuleFilledDataMngr::PreprocessListsL
       
   239 // ---------------------------------------------------------------------------
       
   240 // 
       
   241 void CCmFmFillRuleFilledDataMngr::PreprocessListsL()
       
   242     {
       
   243     LOG(_L("[FILL MNGR]\t CCmFmFillRuleFilledDataMngr::PreprocessListsL()"));
       
   244     
       
   245 #ifdef _DEBUG
       
   246     TInt alloc;
       
   247     TInt cells = User::Heap().AllocSize( alloc );
       
   248     TInt size = User::Heap().Size();
       
   249     TRACE(Print(_L("[FILL MNGR]\t preprocess heap allocsize %d, \
       
   250     size %d, cells %d"), alloc, size, cells ));
       
   251 #endif
       
   252     iProcessingState = ECmFmIdle;  
       
   253     ResetData();
       
   254     // Creates sqlite wrapper and starts preprocessing of all fill lists
       
   255     TRAP_IGNORE( CreateWrapperL() );
       
   256     iTransferInfo.iTotalItems = KErrNone;
       
   257     iTransferInfo.iProcessedItems = KErrNone;        
       
   258     CompleteRequest( EPreProcessingStarted );   
       
   259     }
       
   260 
       
   261 // ---------------------------------------------------------------------------
       
   262 // CCmFmFillRuleFilledDataMngr::PreProcessListL
       
   263 // ---------------------------------------------------------------------------
       
   264 // 
       
   265 void CCmFmFillRuleFilledDataMngr::PreProcessListL( 
       
   266     const TDesC8& aFillListName )
       
   267     {
       
   268     LOG(_L("[FILL MNGR]\t CCmFmFillRuleFilledDataMngr::PreProcessListL()"));
       
   269     
       
   270     iProcessingState = ECmFmIdle;
       
   271     // Creates sqlite wrapper and starts preprocessing of 
       
   272     // one defined fill list 
       
   273     CreateWrapperL();
       
   274     ResetData();
       
   275     iContainer = CCmFillRuleContainer::NewL();     
       
   276     LoadRuleL( aFillListName );
       
   277     LoadAllFillItemsL();    
       
   278     CompleteRequest( ERandomizingStarted );
       
   279     }
       
   280 
       
   281 // ---------------------------------------------------------------------------
       
   282 // CCmFmFillRuleFilledDataMngr::GetColItemsL
       
   283 // ---------------------------------------------------------------------------
       
   284 //
       
   285 void CCmFmFillRuleFilledDataMngr::GetColItemsL( TCmMetadataField aType, 
       
   286     TCmMediaType aMedia, CCmSqlPropertyContainer& aPropertys )
       
   287     {
       
   288     LOG(_L("[FILL MNGR]\t CCmFmFillRuleFilledDataMngr::GetColItemsL()"));
       
   289     
       
   290     iPropertyContainer = NULL;
       
   291     iPropertyContainer = &aPropertys;
       
   292     iPropertys.ResetAndDestroy(); 
       
   293     iProcessingState = ECmFmLoadingPropertys;
       
   294     CreateWrapperL();
       
   295     StartObserverL();
       
   296     // starts loading defined propertys from database
       
   297     iWrapper->GetPropertyValuesL(iPropertys, iAo->iStatus, aType, aMedia );
       
   298     iQueryStart.HomeTime();
       
   299     iAo->RunL();
       
   300     }
       
   301 
       
   302 // ---------------------------------------------------------------------------
       
   303 // CCmFmFillRuleFilledDataMngr::GetMetadataItemsL
       
   304 // ---------------------------------------------------------------------------
       
   305 //
       
   306 void CCmFmFillRuleFilledDataMngr::GetMetadataItemsL(
       
   307                                     CCmSqlPropertyCollector& aPropertys )
       
   308     {
       
   309     LOG(_L("[FILL MNGR]\t CCmFmFillRuleFilledDataMngr::\
       
   310     GetMetadataItemsL()"));
       
   311     
       
   312     iPropertyCollector = NULL;
       
   313     iPropertyCollector = &aPropertys;    
       
   314     iProcessingState = ECmFmLoadingPropertys;
       
   315     CreateWrapperL();
       
   316     StartObserverL();
       
   317     // starts loading property values. Selected artists, albums, genres and 
       
   318     // tracks are used as a filtering parameter ( e.g. if some artist is 
       
   319     // selected, only albums for that defined artist are loaded.
       
   320     iWrapper->GetFilteredPropertyValuesL( *iPropertyCollector, iAo->iStatus );
       
   321     iQueryStart.HomeTime();
       
   322     iAo->RunL();
       
   323     }
       
   324     
       
   325 // ---------------------------------------------------------------------------
       
   326 // CCmFmFillRuleFilledDataMngr::UpdatePriorities
       
   327 // ---------------------------------------------------------------------------
       
   328 //    
       
   329 void CCmFmFillRuleFilledDataMngr::UpdatePriorities()
       
   330     {
       
   331     LOG(_L("[FILL MNGR]\t CCmFmFillRuleFilledDataMngr::UpdatePriorities()"));
       
   332     
       
   333     CompleteRequest( EUpdatePriorities );
       
   334     }
       
   335 
       
   336 // ---------------------------------------------------------------------------
       
   337 // CCmFmFillRuleFilledDataMngr::DoUpdatePrioritiesL
       
   338 // ---------------------------------------------------------------------------
       
   339 //
       
   340 void CCmFmFillRuleFilledDataMngr::DoUpdatePrioritiesL()
       
   341     {
       
   342     LOG(_L("[FILL MNGR]\t CCmFmFillRuleFilledDataMngr::\
       
   343     DoUpdatePrioritiesL()"));
       
   344     
       
   345     // Updating first list item priorities    
       
   346 #ifdef _DEBUG
       
   347     TInt alloc;
       
   348     TInt cells = User::Heap().AllocSize( alloc );
       
   349     TInt size = User::Heap().Size();
       
   350     TRACE(Print(_L("[FILL MNGR]\t DoUpdatePrioritiesL start heap \
       
   351     allocsize %d, size %d, cells %d"), alloc, size, cells ));    
       
   352 #endif    
       
   353     
       
   354     CCmFillRuleContainer* container = LoadAllFillRulesL();
       
   355     CleanupStack::PushL( container );
       
   356     TInt err( UpdateListItemPriorities( container ) );
       
   357     TRACE(Print(_L("[FILL MNGR]\t UpdateListItemPriorities err = %d"), 
       
   358     err ));     
       
   359     CleanupStack::PopAndDestroy(container);
       
   360     CalculateAvgTransferTimeL();
       
   361     SendAvgTransferTime();
       
   362 
       
   363 #ifdef _DEBUG    
       
   364     cells = User::Heap().AllocSize( alloc );
       
   365     size = User::Heap().Size();
       
   366     TRACE(Print(_L("[FILL MNGR]\t DoUpdatePrioritiesL end heap \
       
   367     allocsize %d, size %d, cells %d"), alloc, size, cells ));
       
   368 #endif
       
   369                   
       
   370     iObserver->FillRuleProcessingStatus( EDoUpdatePriorities );   
       
   371     }
       
   372 
       
   373 // ---------------------------------------------------------------------------
       
   374 // CCmFmFillRuleFilledDataMngr::DoUpdateReferenceIdsL
       
   375 // ---------------------------------------------------------------------------
       
   376 //
       
   377 void CCmFmFillRuleFilledDataMngr::DoUpdateReferenceIdsL()
       
   378     {
       
   379     LOG(_L("[FILL MNGR]\t CCmFmFillRuleFilledDataMngr::\
       
   380     DoUpdateReferenceIdsL()")); 
       
   381     
       
   382 #ifdef _DEBUG
       
   383     TInt alloc;
       
   384     TInt cells = User::Heap().AllocSize( alloc );
       
   385     TInt size = User::Heap().Size();
       
   386     TRACE(Print(_L("[FILL MNGR]\t DoUpdateReferenceIdsL start heap \
       
   387     allocsize %d, size %d, cells %d"), alloc, size, cells ));    
       
   388 #endif
       
   389     
       
   390     LoadAllFillItemsL();
       
   391     LOG(_L("[FILL MNGR]\t Items loaded...")); 
       
   392     
       
   393     // Processing set referense ids into duplicate items
       
   394     LOG(_L("[FILL MNGR]\t Processing ref ids..."));
       
   395 
       
   396     DoProcessReferenceValuesL();   
       
   397        
       
   398     LOG(_L("[FILL MNGR]\t Ref ids processed..."));        
       
   399     UpdateFillItems();
       
   400     iItems.ResetAndDestroy();
       
   401     iItems.Close();
       
   402 #ifdef _DEBUG    
       
   403     cells = User::Heap().AllocSize( alloc );
       
   404     size = User::Heap().Size();
       
   405     TRACE(Print(_L("[FILL MNGR]\t DoUpdateReferenceIdsL end heap \
       
   406     allocsize %d, size %d, cells %d"), alloc, size, cells ));
       
   407 #endif     
       
   408     }
       
   409 
       
   410 // ---------------------------------------------------------------------------
       
   411 // CCmFmFillRuleFilledDataMngr::DeleteMetadataL
       
   412 // ---------------------------------------------------------------------------
       
   413 //
       
   414 void CCmFmFillRuleFilledDataMngr::DeleteMetadataL()
       
   415     {
       
   416     LOG(_L("[FILL MNGR]\t CCmFmFillRuleFilledDataMngr::DeleteMetadataL()")); 
       
   417     
       
   418     iMetadataServersToBeDeleted.Reset();
       
   419     
       
   420     RPointerArray<CCmMediaServerFull> mediaServers;
       
   421     CleanupClosePushL( mediaServers );
       
   422    
       
   423     iDBManager->GetMediaServersL( mediaServers ); 
       
   424     
       
   425     TBool setSystemUpdateIDChange( EFalse );
       
   426     for( TInt i = 0; i < mediaServers.Count(); i++ )
       
   427         {
       
   428         // checks that server is either inactive or deleted
       
   429         if( mediaServers[i]->DbId() != 0 && 
       
   430             !( mediaServers[i]->FillUsage() ) )
       
   431             {
       
   432             iMetadataServersToBeDeleted.AppendL( mediaServers[i]->DbId() );
       
   433             TRACE(Print(_L("[FILL MNGR]\t DbId = %ld"), 
       
   434                 mediaServers[i]->DbId() ));            
       
   435                 
       
   436             mediaServers[i]->SetSystemUpdateID( KErrNotFound );
       
   437                 
       
   438 			setSystemUpdateIDChange = ETrue;
       
   439             }
       
   440         }
       
   441 
       
   442 	if ( setSystemUpdateIDChange )
       
   443 		{
       
   444 		iDBManager->SetMediaServersL( mediaServers ); 	
       
   445 		}
       
   446 
       
   447     mediaServers.ResetAndDestroy();
       
   448     CleanupStack::PopAndDestroy( &mediaServers );
       
   449     
       
   450     iProcessingState = ECmFmDeletingMetadata;
       
   451     CreateWrapperL();
       
   452     StartObserverL();
       
   453     iWrapper->AsyncMetadataDelete( iMetadataServersToBeDeleted, 
       
   454         iAo->iStatus );
       
   455     iQueryStart.HomeTime();
       
   456     iAo->RunL();        
       
   457     }
       
   458         
       
   459 // ---------------------------------------------------------------------------
       
   460 // CCmFmFillRuleFilledDataMngr::SetMemoryCardQuota
       
   461 // ---------------------------------------------------------------------------
       
   462 // 
       
   463 void CCmFmFillRuleFilledDataMngr::SetMemoryCardQuota( TInt64 aQuota )
       
   464     {
       
   465     LOG(_L("[FILL MNGR]\t CCmFmFillRuleFilledDataMngr::\
       
   466     SetMemoryCardQuota()")); 
       
   467     
       
   468     if( iWrapper )
       
   469         {
       
   470         iWrapper->SetQuota( aQuota );
       
   471         }
       
   472     }
       
   473     
       
   474 // ---------------------------------------------------------------------------
       
   475 // CCmFmFillRuleFilledDataMngr::CancelOperation
       
   476 // ---------------------------------------------------------------------------
       
   477 //    
       
   478 void CCmFmFillRuleFilledDataMngr::CancelOperation()
       
   479     {
       
   480     LOG(_L("[FILL MNGR]\t CCmFmFillRuleFilledDataMngr::CancelOperation()"));
       
   481     
       
   482     Cancel();    
       
   483     if( iWrapper )
       
   484         {
       
   485         iWrapper->CancelAsyncOperation();
       
   486         }
       
   487     DeleteWrapper(); 
       
   488     if( iAo )
       
   489         {
       
   490         if( iAo->IsActive() )
       
   491             {
       
   492             iAo->Cancel();
       
   493             } 
       
   494         delete iAo;
       
   495         iAo = NULL;      
       
   496         }
       
   497     LOG(_L("[FILL MNGR]\t iAo canceled..."));          
       
   498     iObserver->FillRuleProcessingStatus(EProcessingCanceled);           
       
   499     }
       
   500 
       
   501 // ---------------------------------------------------------------------------
       
   502 // CCmFmFillRuleFilledDataMngr::UpdateTransferHistoryData
       
   503 // ---------------------------------------------------------------------------
       
   504 //
       
   505 void CCmFmFillRuleFilledDataMngr::UpdateTransferHistoryData( 
       
   506     TInt64 aInterval, TInt64 aDataAmount, 
       
   507     TUint8 aServerId )
       
   508     {
       
   509     LOG(_L("[FILL MNGR]\t CCmFmFillRuleFilledDataMngr::\
       
   510     UpdateTransferHistoryData()")); 
       
   511     
       
   512     iDBManager->UpdateDownloadHistory( (TUint)aServerId, aDataAmount,
       
   513         aInterval );
       
   514     }
       
   515 
       
   516 // ---------------------------------------------------------------------------
       
   517 // CCmFmFillRuleFilledDataMngr::GetFillItemsL
       
   518 // ---------------------------------------------------------------------------
       
   519 //
       
   520 void CCmFmFillRuleFilledDataMngr::GetFillItemsL()
       
   521     {
       
   522     LOG(_L("[FILL MNGR]\t CCmFmFillRuleFilledDataMngr::GetFillItemsL()")); 
       
   523     
       
   524     iItems.ResetAndDestroy();
       
   525     iItems.Close();
       
   526     iDBManager->PrepareQueryCmdL(EAllFillFilesStatusQuery);
       
   527     iDBManager->GetAllFillFilesL( iItems, 
       
   528         ECmToBeShrinked|ECmToBeFilled|ECmFilled|ECmLocalCopy );
       
   529     }
       
   530 
       
   531 // ---------------------------------------------------------------------------
       
   532 // CCmFmFillRuleFilledDataMngr::GetToBeDeletedL
       
   533 // ---------------------------------------------------------------------------
       
   534 //
       
   535 void CCmFmFillRuleFilledDataMngr::GetToBeDeletedL(
       
   536     RPointerArray<CCmFillListItem>& aArray )
       
   537     {
       
   538     LOG(_L("[FILL MNGR]\t CCmFmFillRuleFilledDataMngr::GetToBeDeletedL()")); 
       
   539     
       
   540     iDBManager->PrepareQueryCmdL(EAllFillFilesStatusQuery);
       
   541     iDBManager->GetAllFillFilesL( aArray, ECmToBeRemoved );   
       
   542     }
       
   543 
       
   544 // ---------------------------------------------------------------------------
       
   545 // CCmFmFillRuleFilledDataMngr::UpdateFillItems
       
   546 // ---------------------------------------------------------------------------
       
   547 //    
       
   548 void CCmFmFillRuleFilledDataMngr::UpdateFillItems( TBool aCancel )
       
   549     {
       
   550     LOG(_L("[FILL MNGR]\t CCmFmFillRuleFilledDataMngr::UpdateFillItems()")); 
       
   551     
       
   552     iDBManager->DeleteFillFiles();
       
   553     if( aCancel && iUpdateItems.Count() )
       
   554         {
       
   555         iDBManager->SetFillFiles( iUpdateItems );
       
   556         }
       
   557     else
       
   558         {
       
   559         iDBManager->SetFillFiles( iItems );
       
   560         }
       
   561     iUpdateItems.Reset();
       
   562     iUpdateItems.Close();
       
   563 
       
   564     iItems.ResetAndDestroy();
       
   565     iItems.Close();
       
   566 
       
   567     TRAP_IGNORE( CalculateAvgTransferTimeL() );
       
   568     SendAvgTransferTime();    
       
   569     }
       
   570 
       
   571 // ---------------------------------------------------------------------------
       
   572 // CCmFmFillRuleFilledDataMngr::UpdateToBeDeleted
       
   573 // ---------------------------------------------------------------------------
       
   574 //    
       
   575 void CCmFmFillRuleFilledDataMngr::UpdateToBeDeleted( 
       
   576     RPointerArray<CCmFillListItem>& aArray )
       
   577     {
       
   578     LOG(_L("[FILL MNGR]\t CCmFmFillRuleFilledDataMngr::\
       
   579     UpdateToBeDeleted()")); 
       
   580     
       
   581     // This function is needed when fill is processed only partially
       
   582     // Some of the to be deleted files are still on device
       
   583     iDBManager->SetFillFiles( aArray );
       
   584     aArray.ResetAndDestroy();
       
   585     aArray.Close();
       
   586     }
       
   587 
       
   588 // ---------------------------------------------------------------------------
       
   589 // CCmFmFillRuleFilledDataMngr::GetUuidL
       
   590 // ---------------------------------------------------------------------------
       
   591 //
       
   592 TInt CCmFmFillRuleFilledDataMngr::GetUuidL( HBufC8*& aUuid, TUint8 aId )
       
   593     {
       
   594     LOG(_L("[FILL MNGR]\t CCmFmFillRuleFilledDataMngr::GetUuidL()")); 
       
   595     
       
   596     iDBManager->PrepareQueryCmdL( EMediaServerUDNQuery );
       
   597     return iDBManager->QueryMediaServerUdn(aUuid, aId);      
       
   598     }
       
   599 
       
   600 // ---------------------------------------------------------------------------
       
   601 // CCmFmFillRuleFilledDataMngr::ResetData
       
   602 // ---------------------------------------------------------------------------
       
   603 //  
       
   604 void CCmFmFillRuleFilledDataMngr::ResetData()
       
   605     {
       
   606     LOG(_L("[FILL MNGR]\t CCmFmFillRuleFilledDataMngr::ResetData()")); 
       
   607     
       
   608     iNewItemCount = KErrNone;
       
   609     
       
   610     iRuleArray.Reset();
       
   611     iRuleArray.Close();
       
   612     
       
   613     iUpdateItems.Reset();
       
   614     iUpdateItems.Close();    
       
   615 
       
   616     iItems.ResetAndDestroy();
       
   617     iItems.Close();
       
   618     
       
   619     iFileIds.Close();
       
   620     iOldIds.Close(); 
       
   621     
       
   622     if( iContainer )
       
   623         {
       
   624         delete iContainer;
       
   625         iContainer = NULL;
       
   626         }              
       
   627     }
       
   628 
       
   629 // ---------------------------------------------------------------------------
       
   630 // CCmFmFillRuleFilledDataMngr::CalculateAvgTransferTimeL
       
   631 // ---------------------------------------------------------------------------
       
   632 //
       
   633 void CCmFmFillRuleFilledDataMngr::CalculateAvgTransferTimeL()
       
   634     {
       
   635     LOG(_L("[FILL MNGR]\t CCmFmFillRuleFilledDataMngr::\
       
   636     CalculateAvgTransferTimeL()")); 
       
   637     
       
   638     TInt64 ud(KErrNone);
       
   639     TInt64 dd(KErrNone);
       
   640     TInt64 ut(KErrNone);
       
   641     TInt64 dt(KErrNone);
       
   642     TInt64 size( KErrNone );
       
   643     TInt64 shrinkTime(KErrNone);
       
   644     TInt64 transferTime(KErrNone);
       
   645     TInt ret( KErrNone );   
       
   646     RPointerArray<CCmMediaServerFull> servers;
       
   647     CleanupClosePushL( servers );
       
   648     
       
   649     iDBManager->PrepareQueryCmdL( EMediaServersAllQuery );
       
   650     while( !ret )
       
   651         {
       
   652         CCmMediaServerFull* server = CCmMediaServerFull::NewLC();
       
   653         ret = iDBManager->QueryAllMediaServersL( server );
       
   654         if( !ret )
       
   655             {
       
   656             servers.AppendL( server );
       
   657             CleanupStack::Pop( server );
       
   658             }
       
   659         else
       
   660             {
       
   661             CleanupStack::PopAndDestroy( server );
       
   662             }   
       
   663         }
       
   664     TRACE( Print( _L("[FILL MNGR]\t servers.Count() = %d"),
       
   665         servers.Count() ));             
       
   666     for( TInt i = 0; i < servers.Count(); i++ )
       
   667         {
       
   668         iDBManager->PrepareQueryCmdL(ETransferHistoryQuery);
       
   669         TPtrC8 ser( servers[i]->MediaServer() );
       
   670         if( &ser )
       
   671             {
       
   672             iDBManager->QueryTransferHistory( 
       
   673                 ser, dd, ud, dt, ut );
       
   674             size = iDBManager->KBytesToBeFilled( 
       
   675                 GetMediaServerIdL(ser), 
       
   676                 ECmToBeShrinked|ECmToBeFilled );
       
   677             TRACE( Print( _L("[FILL MNGR]\t data amount \
       
   678                 to be filled = %ld"), size ));
       
   679                 
       
   680             TRACE( Print( _L("[FILL MNGR]\t transferred data = %ld"),
       
   681                 dd )); 
       
   682                 
       
   683             TRACE( Print( _L("[FILL MNGR]\t transfer time = %ld"),
       
   684                 dt ));                                                 
       
   685             if( dd == KErrNone || dt == KErrNone )
       
   686                 {
       
   687                 dd = KCmFmIniDownloadDataAmount;
       
   688                 dt = KCmFmIniDownloadTime;
       
   689                 }
       
   690             // If server hasn't been handled    
       
   691             if( size != KErrNone )
       
   692                 {
       
   693                 transferTime = transferTime + (( dt * size ) / dd );
       
   694                 }
       
   695             TRACE( Print( _L("[FILL MNGR]\t avg transfer time = %ld"),
       
   696                 transferTime ));                            
       
   697             }
       
   698              
       
   699         }
       
   700     servers.ResetAndDestroy();
       
   701     CleanupStack::PopAndDestroy( &servers );
       
   702     
       
   703     TInt shrinkCount( iDBManager->FillFileCount(ECmToBeShrinked) );
       
   704         
       
   705     shrinkTime = (iDBManager->GetAvgImageShrinkTime() * shrinkCount);     
       
   706     
       
   707     TInt totalCount( iDBManager->FillFileCount( 
       
   708         ECmToBeShrinked|ECmToBeFilled ));
       
   709     transferTime = transferTime + ( shrinkTime / 1000 );
       
   710     if( KErrNone >= totalCount )
       
   711         {
       
   712         transferTime = KErrNone;
       
   713         }
       
   714     iDBManager->UpdateTransferInfo( ECmServiceFill, totalCount, 
       
   715         transferTime );             
       
   716     }
       
   717 
       
   718 // ---------------------------------------------------------------------------
       
   719 // CCmFmFillRuleFilledDataMngr::SendAvgTransferTime
       
   720 // ---------------------------------------------------------------------------
       
   721 //   
       
   722 void CCmFmFillRuleFilledDataMngr::SendAvgTransferTime()
       
   723     {
       
   724     LOG(_L("[FILL MNGR]\t CCmFmFillRuleFilledDataMngr::\
       
   725     SendAvgTransferTime()")); 
       
   726     
       
   727     // Load transfer information from database
       
   728     TInt err = iDBManager->GetTransferInfo( ECmServiceFill, 
       
   729         iTransferInfo.iProcessedItems, iTransferInfo.iTotalItems );
       
   730         
       
   731     TRACE( Print( _L("[FILL MNGR]\t GetTransferInfo returned %d"), err));
       
   732     
       
   733     TRACE( Print( _L(
       
   734         "[FILL MNGR]\t item count = %d, avg time = %d"),
       
   735             iTransferInfo.iProcessedItems, iTransferInfo.iTotalItems ));    
       
   736     iTransferInfo.iService = ECmServiceTransferInfoFill;
       
   737         
       
   738     TCmProgressInfoPckg transferInfoPckg( iTransferInfo );
       
   739     
       
   740     err = RProperty::Set( KCmPropertyCat, KCmProperty, 
       
   741         transferInfoPckg );
       
   742     
       
   743     TRACE( Print( _L("[FILL MNGR]\t RProperty::Set returned %d"), err));    
       
   744     }
       
   745 
       
   746 // ---------------------------------------------------------------------------
       
   747 // CCmFmFillRuleFilledDataMngr::GetMediaServerIdL
       
   748 // ---------------------------------------------------------------------------
       
   749 //     
       
   750 TInt64 CCmFmFillRuleFilledDataMngr::GetMediaServerIdL( const TDesC8& aUuid )
       
   751     {
       
   752     LOG(_L("[FILL MNGR]\t CCmFmFillRuleFilledDataMngr::\
       
   753     GetMediaServerIdL()")); 
       
   754     
       
   755     iDBManager->PrepareQueryCmdL( EMediaServerIdQuery );
       
   756     return iDBManager->QueryMediaServerId( aUuid ); 
       
   757     }
       
   758                 
       
   759 // ---------------------------------------------------------------------------
       
   760 // CCmFmFillRuleFilledDataMngr::LoadSelectedFillRulesL
       
   761 // ---------------------------------------------------------------------------
       
   762 //    
       
   763 void CCmFmFillRuleFilledDataMngr::LoadSelectedFillRulesL()
       
   764     {
       
   765     LOG(_L("[FILL MNGR]\t CCmFmFillRuleFilledDataMngr::\
       
   766         LoadSelectedFillRulesL()"));
       
   767             
       
   768     RPointerArray<HBufC8> array;
       
   769     CleanupClosePushL( array );
       
   770     
       
   771     iDBManager->PrepareQueryCmdL( ESelectedFillRuleQuery );    
       
   772     iDBManager->QuerySelectedFillRuleNamesL( array, (TInt)ECmSelected );
       
   773     // Load selected fill rules to array ( using names as a query 
       
   774     // parameter ) 
       
   775     for( TInt i = 0; i < array.Count(); i++ ) 
       
   776         {
       
   777         LoadRuleL( *array[i] );
       
   778         }
       
   779     
       
   780     // Remove random rules. When fill manager is booted up first time 
       
   781     // Do not remove random rules => need to be processed
       
   782     // If list don't have any files on the list => process list
       
   783     for( TInt j = 0; j < iRuleArray.Count(); j++ )
       
   784         {
       
   785         if( ECmRandom == iRuleArray[j]->Method() || 
       
   786             ECmRandomAlbum == iRuleArray[j]->Method() ||
       
   787             ECmRandomTrack == iRuleArray[j]->Method() )
       
   788             {
       
   789             TInt count( KErrNone );
       
   790             iDBManager->GetFillFileCount(iRuleArray[j]->Name(), 
       
   791                 ECmToBeFilled|ECmToBeShrinked|ECmFilled|ECmLocalCopy, count );
       
   792             if( KErrNone < count )
       
   793                 {
       
   794                 LOG(_L("[FILL MNGR]\t Random rule is already processed"));
       
   795                 delete iRuleArray[j];
       
   796                 iRuleArray.Remove(j);
       
   797                 j--;                
       
   798                 }
       
   799             else
       
   800                 {
       
   801                 LOG(_L("[FILL MNGR]\t Random rule is not processed"));
       
   802                 // Don't remove rule
       
   803                 }
       
   804             }
       
   805         }
       
   806     for( TInt k = 0; k < iRuleArray.Count(); k++ )
       
   807         {
       
   808         if( KErrNone == iRuleArray[k]->MediaServerCount() )
       
   809             {
       
   810             LOG(_L("[FILL MNGR]\t No Servers included in fill rule"));
       
   811             TRACE(Print(_L("[FILL MNGR]\t => Any Server rule...")));
       
   812             }
       
   813         }
       
   814         
       
   815     array.ResetAndDestroy();
       
   816     CleanupStack::PopAndDestroy( &array );
       
   817     
       
   818     CompleteRequest( EFillRulesLoaded );       
       
   819     }
       
   820 
       
   821 // ---------------------------------------------------------------------------
       
   822 // CCmFmFillRuleFilledDataMngr::LoadAllFillRulesL
       
   823 // ---------------------------------------------------------------------------
       
   824 //
       
   825 CCmFillRuleContainer* CCmFmFillRuleFilledDataMngr::LoadAllFillRulesL()
       
   826     {
       
   827     LOG(_L("[FILL MNGR]\t CCmFmFillRuleFilledDataMngr::FillRuleContainerL"));
       
   828     
       
   829     RPointerArray<HBufC8> array;
       
   830     CleanupClosePushL( array );
       
   831     
       
   832     // Query fill rule names
       
   833     iDBManager->PrepareQueryCmdL( EFillRuleNamesQuery );
       
   834     iDBManager->QueryFillRuleNamesL( array );
       
   835     TRACE(Print(_L("[FILL MNGR]\t fill rule array size is %d"), 
       
   836         array.Count()));
       
   837     
       
   838     CCmFillRuleContainer* ruleContainer = CCmFillRuleContainer::NewLC();
       
   839     for ( TInt i = 0; i < array.Count(); i++ )
       
   840         {
       
   841         // Query all fill rules
       
   842         CCmFillRule* rule = CCmFillRule::NewLC();
       
   843         rule->SetNameL( *(array[i]) );
       
   844         iDBManager->PrepareQueryCmdL( EFillRuleQuery );
       
   845         iDBManager->QueryFillRuleL( rule );
       
   846         
       
   847         ruleContainer->AddFillRuleL( rule );
       
   848         CleanupStack::Pop( rule );
       
   849         }
       
   850     CleanupStack::Pop( ruleContainer );
       
   851     
       
   852     array.ResetAndDestroy();
       
   853     CleanupStack::PopAndDestroy( &array );
       
   854     
       
   855     return ruleContainer;
       
   856     }
       
   857     
       
   858 // ---------------------------------------------------------------------------
       
   859 // CCmFmFillRuleFilledDataMngr::LoadRuleL
       
   860 // ---------------------------------------------------------------------------
       
   861 //
       
   862 void CCmFmFillRuleFilledDataMngr::LoadRuleL( const TDesC8& aFillListName )
       
   863     {
       
   864     LOG(_L("[FILL MNGR]\t CCmFmFillRuleFilledDataMngr::LoadRuleL()")); 
       
   865     
       
   866     CCmFillRule* fillRule = CCmFillRule::NewLC();
       
   867     iDBManager->PrepareQueryCmdL(EFillRuleQuery);
       
   868     fillRule->SetNameL( aFillListName );
       
   869     iDBManager->QueryFillRuleL( fillRule );
       
   870     iRuleArray.AppendL( fillRule );   
       
   871     iContainer->AddFillRuleL( fillRule );
       
   872     CleanupStack::Pop( fillRule );
       
   873     }
       
   874 
       
   875 // ---------------------------------------------------------------------------
       
   876 // CCmFmFillRuleFilledDataMngr::UpdateListItemPriorities
       
   877 // ---------------------------------------------------------------------------
       
   878 //
       
   879 TInt CCmFmFillRuleFilledDataMngr::UpdateListItemPriorities( 
       
   880     CCmFillRuleContainer* aContainer )
       
   881     {
       
   882     LOG(_L("[FILL MNGR]\t CCmFmFillRuleFilledDataMngr::\
       
   883     UpdateListItemPriorities()"));
       
   884      
       
   885     TInt err( KErrNone );
       
   886     err = iDBManager->UpdateFillListItemPriority( aContainer );            
       
   887     TRACE(Print(_L("[FILL MNGR]\t priority update err = %d"), 
       
   888         err ));            
       
   889     return err;    
       
   890     }
       
   891 
       
   892 // ---------------------------------------------------------------------------
       
   893 // CCmFmFillRuleFilledDataMngr::LoadMetadataL
       
   894 // ---------------------------------------------------------------------------
       
   895 //    
       
   896 void CCmFmFillRuleFilledDataMngr::LoadMetadataL( CCmFillRule* aFillRule )
       
   897     {
       
   898     LOG(_L("[FILL MNGR]\t CCmFmFillRuleFilledDataMngr::\
       
   899     LoadMetadataL()"));
       
   900     
       
   901     StartObserverL();    
       
   902     TRAPD( err, iWrapper->GetFillItemsL( iItems, *aFillRule, iAo->iStatus ) );
       
   903     if( !err )
       
   904         {
       
   905         iQueryStart.HomeTime();
       
   906         iAo->RunL();
       
   907         iNewItemCount = iItems.Count();
       
   908         //add the old item to list
       
   909         SelectFillListFiles( iOldIds, aFillRule->ListId() );
       
   910         iProcessingState = ECmFmLoadingMetadata;        
       
   911         }
       
   912     else
       
   913         {
       
   914         TRACE(Print(_L("[FILL MNGR]\t Metadata find err = %d"), err ));
       
   915         TRACE(Print(_L("[FILL MNGR]\t Skipping rule...")));
       
   916         iRuleArray.Remove(0);        
       
   917         iRuleArray.Compress();   
       
   918         /** Splitting long task into shorter ones */            
       
   919         CompleteRequest( ENextFillRule );       
       
   920         }        
       
   921     }
       
   922 
       
   923 // ---------------------------------------------------------------------------
       
   924 // CCmFmFillRuleFilledDataMngr::ProcessReferenceValuesL
       
   925 // ---------------------------------------------------------------------------
       
   926 // 
       
   927 void CCmFmFillRuleFilledDataMngr::ProcessReferenceValuesL()
       
   928     {
       
   929     LOG(_L("[FILL MNGR]\t CCmFmFillRuleFilledDataMngr::\
       
   930     ProcessReferenceValuesL()"));
       
   931 
       
   932     DoProcessReferenceValuesL();
       
   933     CompleteRequest( EProcessStatusValues );             
       
   934     }
       
   935 
       
   936 // ---------------------------------------------------------------------------
       
   937 // CCmFmFillRuleFilledDataMngr::DoProcessReferenceValuesL
       
   938 // ---------------------------------------------------------------------------
       
   939 // 
       
   940 void CCmFmFillRuleFilledDataMngr::DoProcessReferenceValuesL()
       
   941     {
       
   942     LOG(_L("[FILL MNGR]\t CCmFmFillRuleFilledDataMngr::\
       
   943     DoProcessReferenceValuesL()"));
       
   944     
       
   945     RArray<TInt> refIds;
       
   946     CleanupClosePushL( refIds );
       
   947     
       
   948     TBool ref( EFalse );
       
   949     // Processing set referense ids into duplicate items
       
   950     for( TInt j = 0; j < iItems.Count(); j++ )
       
   951         {                       
       
   952         for( TInt k = iItems.Count() - 1; k >= KErrNone; k-- )
       
   953             {
       
   954             if( ( KErrNone == iItems[k]->PrimaryText().Compare(
       
   955                 iItems[j]->PrimaryText() )) && (iItems[k]->Size() 
       
   956                == iItems[j]->Size() ) && ( j != k ) && 
       
   957                     ( ECmSelected == iItems[j]->Selected() || 
       
   958                     ( ECmUnSelected == iItems[j]->Selected() && 
       
   959                     ECmUnSelected == iItems[k]->Selected() ) ) )
       
   960                 {
       
   961                 if( iItems[k]->Priority() > iItems[j]->Priority() )
       
   962                     {
       
   963                     refIds.InsertInOrderL( k );
       
   964                     }
       
   965                 else if ( iItems[k]->Priority() < iItems[j]->Priority() )
       
   966                     {
       
   967                     // Some of the items are on the higher priority than
       
   968                     // iItems[ j ]
       
   969                     if( ECmUnSelected == iItems[k]->Selected() && 
       
   970                         ECmSelected == iItems[j]->Selected() )
       
   971                         {
       
   972                         refIds.InsertInOrderL( k );
       
   973                         }
       
   974                     else
       
   975                         {
       
   976                         ref = ETrue;
       
   977                         }    
       
   978                     }
       
   979                 }
       
   980             // Check if there is a match on a selected list    
       
   981             if( ( KErrNone == iItems[k]->PrimaryText().Compare(
       
   982                 iItems[j]->PrimaryText() ) ) && ( iItems[k]->Size() 
       
   983                == iItems[j]->Size() ) && ( j != k ) && 
       
   984                     ( ECmUnSelected == iItems[j]->Selected() && 
       
   985                     ECmSelected == iItems[k]->Selected() ) && ( 
       
   986                     iItems[k]->Priority() < iItems[j]->Priority() ) )
       
   987                 {
       
   988                 // Do not set ref id to zero
       
   989                 ref = ETrue;
       
   990                 }
       
   991             }
       
   992         // Updating referense ids    
       
   993         for( TInt i = 0; i < refIds.Count(); i++ )
       
   994             {
       
   995             iItems[refIds[i]]->SetRefId( iItems[j]->DbId() );
       
   996             }
       
   997         if( !ref )
       
   998             {
       
   999             iItems[j]->SetRefId( 0 );
       
  1000             }
       
  1001         ref = EFalse;    
       
  1002         refIds.Reset();    
       
  1003         }
       
  1004     
       
  1005     CleanupStack::PopAndDestroy( &refIds );                     
       
  1006     }
       
  1007 
       
  1008 // ---------------------------------------------------------------------------
       
  1009 // CCmFmFillRuleFilledDataMngr::ProcessDuplicates
       
  1010 // Processes duplicates. If same list has some item twice,
       
  1011 // newer one is removed from the list
       
  1012 // ---------------------------------------------------------------------------
       
  1013 //
       
  1014 void CCmFmFillRuleFilledDataMngr::ProcessDuplicates()
       
  1015     {
       
  1016     LOG(_L("[FILL MNGR]\t CCmFmFillRuleFilledDataMngr::\
       
  1017     ProcessDuplicates()"));
       
  1018 
       
  1019     TBool duplicateFound( EFalse );
       
  1020     
       
  1021     for( TInt i = 0; i < iFileIds.Count() - 1; i++ )
       
  1022         {
       
  1023         duplicateFound = EFalse;
       
  1024         //Compare item with following items 
       
  1025         for( TInt j = i+1; j < iFileIds.Count() && !duplicateFound; j++ )
       
  1026             {
       
  1027             if( ( iFileIds[i] < iItems.Count() ) && 
       
  1028                 ( iFileIds[j] < iItems.Count() ) )
       
  1029                 {
       
  1030                 if( i != j && ( ( KErrNone == iItems[iFileIds[i]]->
       
  1031                     PrimaryText().Compare( 
       
  1032                     iItems[iFileIds[j]]->PrimaryText() ) ) 
       
  1033                     && ( iItems[iFileIds[i]]->Size() == 
       
  1034                     iItems[iFileIds[j]]->Size() ) || 
       
  1035                     iItems[iFileIds[i]]->DbId() == 
       
  1036                     iItems[iFileIds[j]]->DbId() ) ) 
       
  1037                     {
       
  1038                     if( ( ECmImage == iItems[iFileIds[j]]->MediaType() &&
       
  1039                          ECmToBeShrinked == iItems[iFileIds[i]]->Status()) ||
       
  1040                         ( ECmImage == iItems[iFileIds[j]]->MediaType() &&
       
  1041                           ECmToBeFilled == iItems[iFileIds[i]]->Status()) )
       
  1042 	                    {
       
  1043 	                    // if the media type is image and never be filled
       
  1044 	                    //before ,so do not change the new items status value
       
  1045 	                    //in this cycle , just delete the old items 	
       
  1046 	                    }
       
  1047 	                else
       
  1048 	                    {
       
  1049 	                    iItems[iFileIds[j]]->SetStatus( 
       
  1050                             iItems[iFileIds[i]]->Status() ) ;	
       
  1051 	                    }
       
  1052                     TRAP_IGNORE( iItems[iFileIds[j]]->SetPathL( 
       
  1053                         iItems[iFileIds[i]]->Path() ) );
       
  1054                     iItems[iFileIds[j]]->SetDriveId( 
       
  1055                         iItems[iFileIds[i]]->DriveId() );
       
  1056                     iItems[iFileIds[j]]->SetDriveNumber( 
       
  1057                         iItems[iFileIds[i]]->DriveNumber() );                                           
       
  1058 
       
  1059                     duplicateFound = ETrue;
       
  1060                     }                
       
  1061                 }                           
       
  1062             }
       
  1063         //iItems[iFileIds[i]] is duplicated, should delete it
       
  1064         if( duplicateFound )
       
  1065             {
       
  1066             DoDeleteProcess( iFileIds[i] );
       
  1067             i--;
       
  1068             }
       
  1069         }  
       
  1070     iItems.Compress();
       
  1071      
       
  1072     /** Spliting long task into shorter ones */            
       
  1073     CompleteRequest( EProcessReferenceValues );
       
  1074     }
       
  1075 
       
  1076 // ---------------------------------------------------------------------------
       
  1077 // CCmFmFillRuleFilledDataMngr::SelectFillListFiles
       
  1078 // ---------------------------------------------------------------------------
       
  1079 //    
       
  1080 void CCmFmFillRuleFilledDataMngr::SelectFillListFiles( RArray<TInt>& aList,
       
  1081                                                        TUint8 aId )
       
  1082     {
       
  1083     LOG(_L("[FILL MNGR]\t CCmFmFillRuleFilledDataMngr::\
       
  1084     SelectFillListFiles()"));
       
  1085     
       
  1086     TRACE(Print(_L("[FILL MNGR]\t LIST ID = %d"), aId ));
       
  1087     aList.Reset();
       
  1088     aList.Close();
       
  1089     TInt count( iItems.Count() );
       
  1090     for( TInt i = 0; i < count; i++ )
       
  1091         {
       
  1092         if( iItems[i]->ListId() == aId )
       
  1093             {
       
  1094             aList.InsertInOrderL( i );
       
  1095             }
       
  1096         }    
       
  1097     }
       
  1098 
       
  1099 // ---------------------------------------------------------------------------
       
  1100 // CCmFmFillRuleFilledDataMngr::ProcessFileStatusValuesL
       
  1101 // ---------------------------------------------------------------------------
       
  1102 //
       
  1103 void CCmFmFillRuleFilledDataMngr::ProcessFileStatusValuesL()
       
  1104     {
       
  1105     LOG(_L("[FILL MNGR]\t CCmFmFillRuleFilledDataMngr::\
       
  1106     ProcessFileStatusValuesL()"));
       
  1107     
       
  1108     // Let's update priorities,is it possible that priority has changed
       
  1109     // And list ids
       
  1110     TInt64 ruleSize( KErrNone );
       
  1111     TInt64 realSize( KErrNone );
       
  1112     TInt err( KErrNone );
       
  1113     if( iRuleArray.Count() > 0 )
       
  1114 	    {
       
  1115 	    TRAP( err, iDBManager->SetFillListRealCountAndSizeL( 
       
  1116 	        iRuleArray[0]->ListId(), 0, 0 ) );	
       
  1117 	    }
       
  1118    
       
  1119     TRACE(Print(_L("[FILL MNGR]\t Size set err = %d"), 
       
  1120         err ));                    
       
  1121     TInt64 realCount( iFileIds.Count() );
       
  1122     for( TInt k = ( iFileIds.Count() - 1 ); k >= KErrNone && 
       
  1123         iFileIds[k] < iItems.Count() ; k-- )
       
  1124         {
       
  1125         // Update priority
       
  1126         iItems[iFileIds[k]]->SetPriority( iRuleArray[0]->Priority() );
       
  1127         // Update list id
       
  1128         iItems[iFileIds[k]]->SetListId( iRuleArray[0]->ListId() );        
       
  1129         if ( iItems[iFileIds[k]]->Status() == ECmToBeFilled || 
       
  1130             iItems[iFileIds[k]]->Status() == ECmToBeShrinked ||
       
  1131             iItems[iFileIds[k]]->Status() == ECmFilled ||
       
  1132             iItems[iFileIds[k]]->Status() == ECmLocalCopy )
       
  1133             {
       
  1134             // increases list size
       
  1135             realSize += iItems[iFileIds[k]]->Size();
       
  1136             }
       
  1137 
       
  1138         else if ( iItems[iFileIds[k]]->Status() == ECmToBeRemoved )
       
  1139             {
       
  1140             // reduces list size
       
  1141             realCount--;
       
  1142             }
       
  1143                    
       
  1144         ruleSize = ruleSize + iItems[iFileIds[k]]->Size();
       
  1145         } 
       
  1146               
       
  1147     TInt index( KErrNone );
       
  1148     RArray<TInt> delIds;
       
  1149     CleanupClosePushL( delIds );
       
  1150     
       
  1151     TRACE( Print( _L("[FILL MNGR]\t iAllItemCount = %d"), iAllItemCount ) );
       
  1152     TRACE( Print( _L("[FILL MNGR]\t iFileIds.Count() = %d"), 
       
  1153                   iFileIds.Count() ) );
       
  1154     TRACE( Print( _L("[FILL MNGR]\t iNewItemCount = %d"), 
       
  1155                   iNewItemCount ) );
       
  1156     // Let's mark to be remove extra files  
       
  1157     if( iRuleArray.Count() > 0 )
       
  1158         {
       
  1159         TRACE( Print( _L("[FILL MNGR]\t fill rule array is not empty!")));
       
  1160         if( iRuleArray[0]->LimitType() == EMbits )  
       
  1161 		    {
       
  1162 		    TRACE( Print( _L("[FILL MNGR]\t fill rule\
       
  1163 		    Limit Type is EMbits!") ) );
       
  1164 		    
       
  1165 		    // KMega=1024*1024
       
  1166 		    // The size of files to be filled should be small than
       
  1167 		    // the amount value set by user.
       
  1168 		    // When realSize be 0 , realCount should be 0 also. 
       
  1169 		    // iAllItemCount > iNewItemCount : sure that extra file be delete
       
  1170 		    while( ( (( iRuleArray[0]->Amount()*KMega ) < realSize ) &&
       
  1171 		              ( realCount>0 )) ||
       
  1172 		                iAllItemCount > iNewItemCount )
       
  1173 		        { 
       
  1174 		        // handle the fill file's count and size.         
       
  1175 		        ProcessFileSizeAndCount( delIds, index, realCount, realSize);
       
  1176 		        index++;         
       
  1177 		        iAllItemCount--;    
       
  1178 		        }  	
       
  1179 		     }
       
  1180         else
       
  1181 	        {
       
  1182 	        // when limit tyep are EUnlimited and EPieces 
       
  1183 	        // do not need to limit the size of the file that to be filled.
       
  1184 	        while( iAllItemCount > iNewItemCount )
       
  1185 	            {         
       
  1186 	            // handle the fill file's count and size.
       
  1187                 ProcessFileSizeAndCount( delIds, index, realCount, realSize );
       
  1188 	            index++;         
       
  1189 	            iAllItemCount--;    
       
  1190 	            }      	
       
  1191 	        }
       
  1192         }
       
  1193     else
       
  1194         {
       
  1195      	// if the fill rule array is empty ,just show the information.
       
  1196      	TRACE( Print( _L("[FILL MNGR]\t fill rule array is empty!")));
       
  1197         }
       
  1198     // Let's remove items which had ECmToBeFilled or ECmToShrinked status    
       
  1199     if( delIds.Count() > KErrNone )
       
  1200         {
       
  1201         index = KErrNone;
       
  1202         while( delIds.Count() != KErrNone )
       
  1203             {
       
  1204             ruleSize = ruleSize - iItems[delIds[0] - index]->Size();
       
  1205             delete iItems[delIds[0] - index];
       
  1206             iItems.Remove( delIds[0] - index );
       
  1207             delIds.Remove(0);
       
  1208             index++;
       
  1209             }        
       
  1210         }
       
  1211     
       
  1212     CleanupStack::PopAndDestroy( &delIds);
       
  1213     
       
  1214     if( iRuleArray.Count() > 0 )
       
  1215 	    {
       
  1216 	    TRAP( err, iDBManager->SetFillListRealCountAndSizeL( 
       
  1217              iRuleArray[0]->ListId(), realCount, ruleSize ) );
       
  1218             iUpdateItems.Reset();
       
  1219             for( TInt j = 0; j < iItems.Count(); j++ )
       
  1220                 {
       
  1221                 iUpdateItems.AppendL( iItems[j] );
       
  1222                 }
       
  1223 	    }
       
  1224      
       
  1225     
       
  1226     TRACE(Print(_L("FILL RULE INFORMATION UPDATE err = %d"), err ));
       
  1227     if ( iRuleArray.Count() > 0 )
       
  1228     	{
       
  1229     	iRuleArray.Remove(0);        
       
  1230     	iRuleArray.Compress();    	
       
  1231     	}
       
  1232     
       
  1233     TRACE(Print(_L("****** FILL RULE TOTAL SIZE ******")));
       
  1234     TRACE(Print(_L("FILL RULE SIZE = %ld ( Bytes )"), ruleSize ));
       
  1235     TRACE(Print(_L("****** FILL RULE TOTAL SIZE ******")));
       
  1236              
       
  1237     /** Spliting long task into shorter ones */            
       
  1238     CompleteRequest( ENextFillRule );           
       
  1239     }
       
  1240 
       
  1241 // ---------------------------------------------------------------------------
       
  1242 // CCmFmFillRuleFilledDataMngr::ProcessFileSizeAndCount
       
  1243 // ---------------------------------------------------------------------------
       
  1244 // 
       
  1245 void CCmFmFillRuleFilledDataMngr::ProcessFileSizeAndCount(
       
  1246                                         RArray<TInt>& aDelIds, TInt aIndex, 
       
  1247                                         TInt64& aRealCount,
       
  1248                                         TInt64& aRealSize )
       
  1249     {
       
  1250     LOG(_L("[FILL MNGR]\t CCmFmFillRuleFilledDataMngr::\
       
  1251     ProcessFileSizeAndCount()"));
       
  1252     
       
  1253 	TRACE( Print( _L(" realCount = %ld, aDelIds's count =%d") , aRealCount,
       
  1254 	aDelIds.Count() ));
       
  1255 	TRACE( Print( _L(" realSize = %ld ( Bytes )") , aRealSize ));
       
  1256 	
       
  1257 	// Should this status be set if priority is higher than duplicates
       
  1258     // priority
       
  1259     if( iItems[iFileIds[aIndex]]->Status() == ECmFilled )
       
  1260         {
       
  1261         iItems[iFileIds[aIndex]]->SetStatus( ECmToBeRemoved );
       
  1262         aRealCount--;
       
  1263         for( TInt i = 0; i < iItems.Count(); i++ )
       
  1264             {
       
  1265             if( iItems[i]->RefId() == iItems[iFileIds[aIndex]]->DbId() )
       
  1266                 {
       
  1267                 // Set also reference ids to status to be removed
       
  1268                 iItems[i]->SetStatus( ECmToBeRemoved );
       
  1269                 }
       
  1270             }              
       
  1271         }
       
  1272     else if( iItems[iFileIds[aIndex]]->Status() == ECmToBeFilled ||
       
  1273          iItems[iFileIds[aIndex]]->Status() == ECmToBeShrinked )
       
  1274         {
       
  1275         aRealSize -= iItems[iFileIds[aIndex]]->Size();
       
  1276         aDelIds.InsertInOrderL( iFileIds[aIndex] );
       
  1277         aRealCount--;
       
  1278         }
       
  1279     else // ECmLocalCopy
       
  1280         {
       
  1281         TRACE(Print(_L("[FILL MNGR]\t No effect on size")));
       
  1282         }    
       
  1283     }
       
  1284 
       
  1285 // ---------------------------------------------------------------------------
       
  1286 // CCmFmFillRuleFilledDataMngr::LoadAllFillItemsL
       
  1287 // ---------------------------------------------------------------------------
       
  1288 //    
       
  1289 void CCmFmFillRuleFilledDataMngr::LoadAllFillItemsL()
       
  1290     {
       
  1291     LOG(_L("[FILL MNGR]\t CCmFmFillRuleFilledDataMngr::LoadAllFillItemsL()"));
       
  1292     
       
  1293     iItems.ResetAndDestroy();
       
  1294     iItems.Close();    
       
  1295     iDBManager->PrepareQueryCmdL( EAllFillFilesQuery );
       
  1296     TInt err = iDBManager->QueryAllFillFilesL(iItems);
       
  1297     TRACE( Print( _L("[FILL MNGR]\t QueryAllFillFilesL err = %d"), err ));
       
  1298     }
       
  1299 
       
  1300 // ---------------------------------------------------------------------------
       
  1301 // CCmFmFillRuleFilledDataMngr::DefineAndSetDlnaProfileIdFiltersL
       
  1302 // ---------------------------------------------------------------------------
       
  1303 //
       
  1304 void CCmFmFillRuleFilledDataMngr::DefineAndSetDlnaProfileIdFiltersL()
       
  1305     {
       
  1306     LOG(_L("[FILL MNGR]\t CCmFmFillRuleFilledDataMngr::\
       
  1307     DefineAndSetDlnaProfileIdFiltersL()"));
       
  1308     
       
  1309     CDesC8Array* array = 
       
  1310         &UPnPDlnaUtility::GetSupportedProfilesL( UPnPDlnaUtility::EDMPMode );
       
  1311     CleanupStack::PushL( array );
       
  1312     TInt okProfile( EFalse );
       
  1313     iFilteredProfiles.Reset();
       
  1314     for( TInt i = 0 ; i < iPropertys.Count(); i++ )
       
  1315         {
       
  1316         for( TInt j = 0; j < array->Count(); j++ )
       
  1317             {
       
  1318             if( KErrNotFound != 
       
  1319                 iPropertys[i]->Name().Match( array->MdcaPoint(j) ) )
       
  1320                 {
       
  1321                 // Profile is supported
       
  1322                 okProfile = ETrue;
       
  1323                 // profile is supported, end loop
       
  1324                 j = array->Count();
       
  1325                 }
       
  1326             }
       
  1327         if( !okProfile )
       
  1328             {
       
  1329             iFilteredProfiles.InsertInSignedKeyOrder( iPropertys[i]->Id() );
       
  1330             }
       
  1331         okProfile = EFalse;            
       
  1332         }
       
  1333     iPropertys.ResetAndDestroy();    
       
  1334     CleanupStack::PopAndDestroy( array );    
       
  1335     }
       
  1336         
       
  1337 // ---------------------------------------------------------------------------
       
  1338 // CCmFmFillRuleFilledDataMngr::CompleteRequest
       
  1339 // ---------------------------------------------------------------------------
       
  1340 // 
       
  1341 void CCmFmFillRuleFilledDataMngr::CompleteRequest( 
       
  1342     TCmFmFillRuleProcessing aStatus )
       
  1343     {
       
  1344     LOG(_L("[FILL MNGR]\t CCmFmFillRuleFilledDataMngr::CompleteRequest()"));
       
  1345     
       
  1346     __ASSERT_DEBUG(!IsActive(),\
       
  1347         User::Panic( KCmFmFillManager, KErrInUse ));          
       
  1348     SetActive();        
       
  1349     TRequestStatus* pStatus = &iStatus;
       
  1350     User::RequestComplete( pStatus, aStatus );     
       
  1351     }
       
  1352 
       
  1353 // ---------------------------------------------------------------------------
       
  1354 // CCmFmFillRuleFilledDataMngr::StartObserverL
       
  1355 // ---------------------------------------------------------------------------
       
  1356 //  
       
  1357 void CCmFmFillRuleFilledDataMngr::StartObserverL()
       
  1358     {
       
  1359     LOG(_L("[FILL MNGR]\t CCmFmFillRuleFilledDataMngr::StartObserverL()"));
       
  1360     
       
  1361     if( iAo )
       
  1362         {
       
  1363         delete iAo;
       
  1364         iAo = NULL;
       
  1365         }
       
  1366     iAo = CCmFmAo::NewL( *this );    
       
  1367     }
       
  1368 
       
  1369 // ---------------------------------------------------------------------------
       
  1370 // CCmFmFillRuleFilledDataMngr::CreateWrapperL
       
  1371 // ---------------------------------------------------------------------------
       
  1372 //  
       
  1373 void CCmFmFillRuleFilledDataMngr::CreateWrapperL()
       
  1374     {
       
  1375     LOG(_L("[FILL MNGR]\t CCmFmFillRuleFilledDataMngr::CreateWrapperL()"));
       
  1376     
       
  1377     DeleteWrapper();
       
  1378     iWrapper = CCmSqlMainFactory::NewCmSqlMainL( iFs );
       
  1379 #ifndef __SERIES60_31__     
       
  1380     iWrapper->SetDlnaProfileFilters( iFilteredProfiles );
       
  1381 #endif    
       
  1382     }
       
  1383 
       
  1384 // ---------------------------------------------------------------------------
       
  1385 // CCmFmFillRuleFilledDataMngr::DeleteWrapper
       
  1386 // ---------------------------------------------------------------------------
       
  1387 //  
       
  1388 void CCmFmFillRuleFilledDataMngr::DeleteWrapper()
       
  1389     {
       
  1390     LOG(_L("[FILL MNGR]\t CCmFmFillRuleFilledDataMngr::DeleteWrapper()"));
       
  1391     
       
  1392     if( iWrapper )
       
  1393         {
       
  1394         iWrapper->Close();
       
  1395         iWrapper = NULL;
       
  1396         }
       
  1397     }
       
  1398 
       
  1399 // ---------------------------------------------------------------------------
       
  1400 // CCmFmFillRuleFilledDataMngr::CheckFillListsL
       
  1401 // ---------------------------------------------------------------------------
       
  1402 //  
       
  1403 void CCmFmFillRuleFilledDataMngr::CheckFillListsL()
       
  1404     {
       
  1405     LOG(_L("[FILL MNGR]\t CCmFmFillRuleFilledDataMngr::CheckFillListsL()"));
       
  1406     
       
  1407     delete iContainer;
       
  1408     iContainer = NULL;
       
  1409     iContainer = LoadAllFillRulesL();
       
  1410     iRuleArray.Reset();
       
  1411     for( TInt j = (iContainer->FillRuleCount() - 1 ) ; j >= 0;
       
  1412         j-- )
       
  1413         {
       
  1414         if( ECmRandom ==  iContainer->FillRule(j)->Method() ||
       
  1415             ECmRandomAlbum == iContainer->FillRule(j)->Method() || 
       
  1416             ECmRandomTrack == iContainer->FillRule(j)->Method() )
       
  1417             {
       
  1418             TInt count( KErrNone );
       
  1419             iDBManager->GetFillFileCount(
       
  1420                 iContainer->FillRule(j)->Name(), 
       
  1421                 ECmToBeFilled|ECmToBeShrinked|ECmFilled|ECmLocalCopy, 
       
  1422                 count );
       
  1423             if( KErrNone < count )
       
  1424                 {
       
  1425                 // If rule is random rule which is already processed
       
  1426                 // do not process rule automatically 
       
  1427                 LOG(_L("[FILL MNGR]\t Random rule already processed"));
       
  1428                 iContainer->DeleteFillRule( j );
       
  1429                 }
       
  1430             else
       
  1431                 {
       
  1432                 LOG(_L("[FILL MNGR]\t Random rule is not processed"));
       
  1433                 // Don't remove rule
       
  1434                 iRuleArray.AppendL( iContainer->FillRule( j ) );
       
  1435                 }                   
       
  1436             }
       
  1437         else
       
  1438             {
       
  1439             LOG(_L("[FILL MNGR]\t Rule is not random rule"));
       
  1440             iRuleArray.AppendL( iContainer->FillRule( j ) );
       
  1441             }    
       
  1442         }
       
  1443     }
       
  1444 
       
  1445 // ---------------------------------------------------------------------------
       
  1446 // CCmFmFillRuleFilledDataMngr::DeleteHashCodesL
       
  1447 // ---------------------------------------------------------------------------
       
  1448 // 
       
  1449 void CCmFmFillRuleFilledDataMngr::DeleteHashCodesL()
       
  1450     {
       
  1451     LOG(_L("[FILL MNGR]\t CCmFmFillRuleFilledDataMngr::DeleteHashCodesL()"));
       
  1452     
       
  1453     for( TInt i = 0; i < iMetadataServersToBeDeleted.Count(); i++ )
       
  1454         {
       
  1455         iDBManager->DeleteHashValuesL( iMetadataServersToBeDeleted[i], 0 );
       
  1456         }
       
  1457     }
       
  1458     
       
  1459 // ---------------------------------------------------------------------------
       
  1460 // CCmFmFillRuleFilledDataMngr::RunL
       
  1461 // ---------------------------------------------------------------------------
       
  1462 // 
       
  1463 void CCmFmFillRuleFilledDataMngr::RunL()
       
  1464     {
       
  1465     TRACE(Print(_L("[FILL MNGR]\t CCmFmFillRuleFilledDataMngr::RunL\
       
  1466          status = %d"), iStatus.Int() ));        
       
  1467     switch( iStatus.Int() )
       
  1468         {
       
  1469         case EPreProcessingStarted:
       
  1470             {
       
  1471             CheckFillListsL();
       
  1472             CompleteRequest( EFillRulesLoaded );                       
       
  1473             break;
       
  1474             }
       
  1475         case EQueryFailed:
       
  1476             {
       
  1477             // Error condition what about now...
       
  1478             TRACE(Print(_L("[FILL MNGR]\t EQueryFailed")));
       
  1479             if( KErrNone < iRuleArray.Count() )
       
  1480                 {
       
  1481                 iRuleArray.Remove(0);        
       
  1482                 iRuleArray.Compress();                
       
  1483                 }
       
  1484             TRACE(Print(_L("[FILL MNGR]\t Jump to next rule")));
       
  1485             CompleteRequest( ENextFillRule );             
       
  1486             break;
       
  1487             }
       
  1488         case EQueryCompleted:
       
  1489             {
       
  1490             // Select needed amount of Fill rules metadata objects
       
  1491             if( KErrNone < iRuleArray.Count() )
       
  1492                 {
       
  1493                 SelectFillListFiles( iFileIds, iRuleArray[0]->ListId() );
       
  1494                 iAllItemCount = iFileIds.Count();
       
  1495                 TRACE(Print(_L("[FILL MNGR]\t Already on the list = %d"), 
       
  1496                     iAllItemCount ));
       
  1497                 CompleteRequest( EProcessDuplicates );
       
  1498                 }
       
  1499             else
       
  1500                 {
       
  1501                 ResetData();
       
  1502                 DeleteWrapper();
       
  1503                 iObserver->FillRuleProcessingStatus(ENoObjectsSelected);
       
  1504                 }    
       
  1505             break;
       
  1506             }
       
  1507         case ENextFillRule:
       
  1508             {       
       
  1509             // Start processing next fill rule
       
  1510             if( KErrNone < iRuleArray.Count() )
       
  1511                 {
       
  1512                 LoadMetadataL(iRuleArray[0]);
       
  1513                 }
       
  1514             else
       
  1515                 {
       
  1516                 TRACE(Print(_L("[FILL MNGR]\t Rule array empty")));
       
  1517                 UpdateFillItems();
       
  1518                 ResetData();
       
  1519                 DeleteWrapper();                
       
  1520 #ifdef _DEBUG
       
  1521                 TInt alloc;
       
  1522                 TInt cells = User::Heap().AllocSize( alloc );
       
  1523                 TInt size = User::Heap().Size();
       
  1524                 TRACE(Print(_L("[FILL MNGR]\t preprocess end heap \
       
  1525                 allocsize %d, size %d, cells %d"), alloc, size, cells ));
       
  1526 #endif                
       
  1527                 iObserver->FillRuleProcessingStatus(EProcessingReady);
       
  1528                 }    
       
  1529             break;
       
  1530             }
       
  1531         case EFillRulesLoaded:
       
  1532             {
       
  1533             LoadAllFillItemsL();
       
  1534             CompleteRequest( EFillFilesLoaded );
       
  1535             break;
       
  1536             }
       
  1537         case EFillFilesLoaded:
       
  1538             {
       
  1539             if( KErrNone < iRuleArray.Count() )
       
  1540                 {
       
  1541                 LoadMetadataL( iRuleArray[0] );    
       
  1542                 }
       
  1543             else
       
  1544                 {
       
  1545                 TRACE(Print(_L("[FILL MNGR]\t Rule array empty")));
       
  1546                 TRAP_IGNORE( CalculateAvgTransferTimeL() );
       
  1547                 SendAvgTransferTime();
       
  1548                 ResetData();
       
  1549                 DeleteWrapper();                
       
  1550                 iObserver->FillRuleProcessingStatus(ENoRulesSelected);
       
  1551                 }
       
  1552             break;    
       
  1553             }
       
  1554         case EProcessDuplicates:
       
  1555             {
       
  1556             ProcessDuplicates();
       
  1557             break;
       
  1558             }
       
  1559         case EProcessReferenceValues:
       
  1560             {
       
  1561             ProcessReferenceValuesL();
       
  1562             break;
       
  1563             }
       
  1564         case EProcessStatusValues:
       
  1565             {
       
  1566             ProcessFileStatusValuesL()  ;
       
  1567             break;
       
  1568             }
       
  1569         case ERandomizingStarted:
       
  1570             {
       
  1571             if( KErrNone < iRuleArray.Count() )
       
  1572                 {
       
  1573                 LoadMetadataL( iRuleArray[0] );    
       
  1574                 }
       
  1575             else
       
  1576                 {
       
  1577                 TRACE(Print(_L("[FILL MNGR]\t Rule array empty")));
       
  1578                 ResetData();
       
  1579                 DeleteWrapper();
       
  1580                 iObserver->FillRuleProcessingStatus(ENoRulesSelected);
       
  1581                 }
       
  1582             break;
       
  1583             }
       
  1584         case EColumnDataReady:
       
  1585             {
       
  1586             DeleteWrapper();
       
  1587             iObserver->FillRuleProcessingStatus(EColumnDataReady);
       
  1588             break;
       
  1589             }
       
  1590         case EUpdatePriorities:
       
  1591             {
       
  1592             DoUpdatePrioritiesL();
       
  1593             break;
       
  1594             }
       
  1595         case EMetadataDeleted:
       
  1596             {
       
  1597             iObserver->FillRuleProcessingStatus( EMetadataDeleted );
       
  1598             break;
       
  1599             }
       
  1600         default:
       
  1601             {
       
  1602             LOG(_L("[FILL MNGR]\t Fill rule processing RunL default"));
       
  1603             User::Invariant();
       
  1604             break;
       
  1605             }
       
  1606         }
       
  1607     }    
       
  1608 
       
  1609 // ---------------------------------------------------------------------------
       
  1610 // CCmFmFillRuleFilledDataMngr::RunError
       
  1611 // ---------------------------------------------------------------------------
       
  1612 // 
       
  1613 #ifdef _DEBUG  
       
  1614 TInt CCmFmFillRuleFilledDataMngr::RunError( TInt aError )
       
  1615 #else
       
  1616 TInt CCmFmFillRuleFilledDataMngr::RunError( TInt /*aError*/ )
       
  1617 #endif
       
  1618     {
       
  1619     TRACE(Print(_L("[FILL MNGR]\t CCmFmFillRuleFilledDataMngr::\
       
  1620     RunError = %d"), aError ));       
       
  1621     
       
  1622     iObserver->FillRuleProcessingStatus( EProcessingFailed );
       
  1623     return KErrNone;     
       
  1624     }
       
  1625 
       
  1626 // ---------------------------------------------------------------------------
       
  1627 // CCmFmFillRuleFilledDataMngr::DoCancel
       
  1628 // ---------------------------------------------------------------------------
       
  1629 //     
       
  1630 void CCmFmFillRuleFilledDataMngr::DoCancel()
       
  1631     {
       
  1632     LOG(_L("[FILL MNGR]\t CCmFmFillRuleFilledDataMngr::DoCancel()"));
       
  1633     }
       
  1634         
       
  1635 // ---------------------------------------------------------------------------
       
  1636 // CCmFmFillRuleFilledDataMngr::DoDeleteProcess
       
  1637 // ---------------------------------------------------------------------------
       
  1638 // 
       
  1639 void CCmFmFillRuleFilledDataMngr::DoDeleteProcess( TInt aIndex )
       
  1640     {
       
  1641     LOG(_L("[FILL MNGR]\t CCmFmFillRuleFilledDataMngr::DoDeleteProcess()"));
       
  1642     TBool delNew( ETrue );
       
  1643     
       
  1644     //delete duplicated fill item
       
  1645     delete iItems[aIndex];
       
  1646     iItems.Remove( aIndex );
       
  1647 
       
  1648     //adjust iOldIds, and judge the item new item or old item
       
  1649     for( TInt i = 0; i < iOldIds.Count(); i++ )
       
  1650         {
       
  1651         if( iOldIds[i] > aIndex )
       
  1652             {
       
  1653             iOldIds[i] = iOldIds[i] - 1;
       
  1654             }
       
  1655         else if( iOldIds[i] == aIndex )
       
  1656             {
       
  1657             delNew = EFalse;
       
  1658             iOldIds.Remove(i);
       
  1659             i--;
       
  1660             }
       
  1661         }
       
  1662     
       
  1663     //adjust iFileIds
       
  1664     for( TInt i = 0; i < iFileIds.Count(); i++ )
       
  1665         {
       
  1666         if( iFileIds[i] > aIndex )
       
  1667             {
       
  1668             iFileIds[i] = iFileIds[i] - 1;
       
  1669             }
       
  1670         else if( iFileIds[i] == aIndex )
       
  1671             {
       
  1672             iFileIds.Remove(i);
       
  1673             i--;
       
  1674             }
       
  1675         }
       
  1676 
       
  1677     //count update
       
  1678     iAllItemCount--;
       
  1679     if( delNew )
       
  1680         {
       
  1681         iNewItemCount--;
       
  1682         }
       
  1683     }
       
  1684 
       
  1685 
       
  1686 // End of file