mpxplugins/viewplugins/views/waitnotedialog/src/mpxscanningdialog.cpp
branchRCL_3
changeset 21 a1247965635c
parent 18 c54d95799c80
child 40 cb96c29156b2
equal deleted inserted replaced
18:c54d95799c80 21:a1247965635c
    52     {
    52     {
    53     iNumItemsAdded = 0;
    53     iNumItemsAdded = 0;
    54     iTotalNewTracks = 0;
    54     iTotalNewTracks = 0;
    55     iInitialCount = 0;
    55     iInitialCount = 0;
    56     isCollectionDBChanged = EFalse;
    56     isCollectionDBChanged = EFalse;
       
    57     iAsyncEvent = ECmdIdle;
       
    58 
    57     }
    59     }
    58 
    60 
    59 
    61 
    60 // ---------------------------------------------------------------------------
    62 // ---------------------------------------------------------------------------
    61 // 2nd Phased constructor
    63 // 2nd Phased constructor
    62 // ---------------------------------------------------------------------------
    64 // ---------------------------------------------------------------------------
    63 //
    65 //
    64 void CMPXScanningWaitDialog::ConstructL()
    66 void CMPXScanningWaitDialog::ConstructL()
    65     {
    67     {
    66     iHarvesterUtil = CMPXHarvesterFactory::NewL();
    68 	 MPX_DEBUG1("CMPXScanningWaitDialog::ConstructL <---");
    67     BaseConstructL();
    69     BaseConstructL();
       
    70 
       
    71 	TCallBack callback( CMPXScanningWaitDialog::AsyncCallHarvesterEventL, this );
       
    72 	iAsyncCallBack = new (ELeave) CAsyncCallBack( CActive::EPriorityHigh );
       
    73 	iAsyncCallBack->Set( callback );
       
    74     MPX_DEBUG1("CMPXScanningWaitDialog::ConstructL --->");
    68     }
    75     }
    69 
    76 
    70 
    77 
    71 // ---------------------------------------------------------------------------
    78 // ---------------------------------------------------------------------------
    72 // Two Phased constructor
    79 // Two Phased constructor
    91     {
    98     {
    92     if( iHarvesterUtil )
    99     if( iHarvesterUtil )
    93         {
   100         {
    94         iHarvesterUtil->Close();
   101         iHarvesterUtil->Close();
    95         }
   102         }
       
   103     iHarvesterUtil = NULL;
       
   104     delete iAsyncCallBack;
       
   105     iAsyncCallBack = NULL;
    96     }
   106     }
    97 
   107 
    98 // ---------------------------------------------------------------------------
   108 // ---------------------------------------------------------------------------
    99 // CMPXScanningWaitDialog::PreNoteDisplayHandleL()
   109 // CMPXScanningWaitDialog::PreNoteDisplayHandleL()
   100 // ---------------------------------------------------------------------------
   110 // ---------------------------------------------------------------------------
   134         {
   144         {
   135         HandleDatabaseCorruptionL();
   145         HandleDatabaseCorruptionL();
   136         }
   146         }
   137         
   147         
   138     // Start the scanning in harvester
   148     // Start the scanning in harvester
   139     iHarvesterUtil->ScanL();
   149     // Just to be faster, lets just create a small async callback and then
   140     iScanningError = KErrNone;
   150     // call ScanL   
       
   151     if( !iAsyncCallBack->IsActive() )
       
   152     	{
       
   153 		iAsyncEvent = ECmdScan;
       
   154 		iCancelScan = EFalse;
       
   155 		iAsyncCallBack->CallBack();
       
   156     	}
   141     }
   157     }
   142 
   158 
   143 // ---------------------------------------------------------------------------
   159 // ---------------------------------------------------------------------------
   144 // CMPXScanningWaitDialog::PostNoteHandleL()
   160 // CMPXScanningWaitDialog::PostNoteHandleL()
   145 // ---------------------------------------------------------------------------
   161 // ---------------------------------------------------------------------------
   152     TInt textRsc( KErrNotFound );
   168     TInt textRsc( KErrNotFound );
   153     
   169     
   154     HBufC* text = NULL;
   170     HBufC* text = NULL;
   155     if( aButtonId == EAknSoftkeyCancel )
   171     if( aButtonId == EAknSoftkeyCancel )
   156         {
   172         {
   157         iScanningError = KErrCancel;
   173 		// cancel scan in harvester
   158         // If harvester crashed,..... restart it.
   174 		// Just to be faster, lets just create a small async callback and then
   159         MPX_TRAPD( err, iHarvesterUtil->CancelScanL() );
   175 		// call CancelScanL   
   160         if( err != KErrNone )
   176 		if( !iAsyncCallBack->IsActive() )
   161             {
   177 			{
   162             iHarvesterUtil->Close();
   178 			iAsyncEvent = ECmdCancleScan;
   163             iHarvesterUtil = NULL;
   179 			iAsyncCallBack->CallBack();
   164             iHarvesterUtil = CMPXHarvesterFactory::NewL(); 
   180 			}      
   165             }
   181 		else
   166         
   182 			{
       
   183 		    iCancelScan = ETrue;
       
   184 			}
       
   185 
   167         // When stop refreshing library, prompt a process waiting dialog.
   186         // When stop refreshing library, prompt a process waiting dialog.
   168         // Inform user to wait for the updating library.
   187         // Inform user to wait for the updating library.
   169         HBufC* waitText = StringLoader::LoadLC( R_MPX_UPDATING_LIBRARY_TXT );  
   188         HBufC* waitText = StringLoader::LoadLC( R_MPX_UPDATING_LIBRARY_TXT );  
   170         DisplayProcessWaitDialogL( R_MPX_GENERIC_WAIT_NOTE, *waitText );
   189         DisplayProcessWaitDialogL( R_MPX_GENERIC_WAIT_NOTE, *waitText );
   171         CleanupStack::PopAndDestroy( waitText );
   190         CleanupStack::PopAndDestroy( waitText );
   270 // ---------------------------------------------------------------------------
   289 // ---------------------------------------------------------------------------
   271 //
   290 //
   272 void CMPXScanningWaitDialog::HandleDatabaseCorruptionL()
   291 void CMPXScanningWaitDialog::HandleDatabaseCorruptionL()
   273     {
   292     {
   274     // Cleanup Harvester
   293     // Cleanup Harvester
   275     iHarvesterUtil->RecreateDatabasesL();
   294 	if( iHarvesterUtil != NULL )
       
   295 		{
       
   296 	    iHarvesterUtil->RecreateDatabasesL();
       
   297 		}
   276     }
   298     }
   277 
   299 
   278 // ---------------------------------------------------------------------------
   300 // ---------------------------------------------------------------------------
   279 // MMPXCollectionObserver
   301 // MMPXCollectionObserver
   280 // ---------------------------------------------------------------------------
   302 // ---------------------------------------------------------------------------
   281 //
   303 //
   282 void CMPXScanningWaitDialog::DoHandleCollectionMessageL(
   304 void CMPXScanningWaitDialog::DoHandleCollectionMessageL(
   283     const CMPXMessage& aMessage )
   305     const CMPXMessage& aMessage )
   284     {
   306     {
   285     MPX_FUNC( "CMPXScanningWaitDialog::DoHandleCollectionMessageL" );
   307     MPX_FUNC( "CMPXScanningWaitDialog::DoHandleCollectionMessageL" );
       
   308     
   286     TMPXMessageId id( aMessage.ValueTObjectL<TMPXMessageId>( KMPXMessageGeneralId ) );
   309     TMPXMessageId id( aMessage.ValueTObjectL<TMPXMessageId>( KMPXMessageGeneralId ) );
   287     if ( KMPXMessageGeneral == id )
   310     if ( KMPXMessageGeneral == id )
   288         {
   311         {
   289         TInt event( aMessage.ValueTObjectL<TInt>( KMPXMessageGeneralEvent ) );
   312         TInt event( aMessage.ValueTObjectL<TInt>( KMPXMessageGeneralEvent ) );
   290         TInt op( aMessage.ValueTObjectL<TInt>( KMPXMessageGeneralType ) );
   313         TInt op( aMessage.ValueTObjectL<TInt>( KMPXMessageGeneralType ) );
   486     CleanupStack::PopAndDestroy(cmdCountM);
   509     CleanupStack::PopAndDestroy(cmdCountM);
   487     MPX_DEBUG2("--->CMPXScanningWaitDialog::GetTrackCountL() count = %d", count );
   510     MPX_DEBUG2("--->CMPXScanningWaitDialog::GetTrackCountL() count = %d", count );
   488 
   511 
   489     return count;
   512     return count;
   490     }
   513     }
       
   514 // ---------------------------------------------------------------------------
       
   515 // async callback 
       
   516 // ---------------------------------------------------------------------------
       
   517 //
       
   518 TInt CMPXScanningWaitDialog::AsyncCallHarvesterEventL( TAny* aSelf )
       
   519     {
       
   520 	MPX_DEBUG1("CMPXScanningWaitDialog::CallHarvesterScanL <---");
       
   521 	CMPXScanningWaitDialog* self = static_cast<CMPXScanningWaitDialog*>( aSelf );
       
   522 	if( self->iHarvesterUtil == NULL )
       
   523 		{
       
   524 	    self->iHarvesterUtil = CMPXHarvesterFactory::NewL();
       
   525 		}
       
   526 	if( self->iAsyncEvent == ECmdScan )
       
   527 		{
       
   528 	    if( !self->iCancelScan )
       
   529 	    	{
       
   530 		    self->iHarvesterUtil->ScanL();
       
   531 		    self->iScanningError = KErrNone;
       
   532 	    	}
       
   533 	    else
       
   534 	    	{
       
   535 	        self->iCancelScan = EFalse;
       
   536 	    	}
       
   537 		}
       
   538 	
       
   539 	if( self->iAsyncEvent == ECmdCancleScan || self->iCancelScan )
       
   540 		{
       
   541 	    self->iScanningError = KErrCancel; 
       
   542         // If harvester crashed,..... restart it.
       
   543 		MPX_TRAPD( err, self->iHarvesterUtil->CancelScanL() );
       
   544 		if( err != KErrNone )
       
   545 			{
       
   546 		    self->iHarvesterUtil->Close();
       
   547 		    self->iHarvesterUtil = NULL;
       
   548 		    self->iHarvesterUtil = CMPXHarvesterFactory::NewL(); 
       
   549 			}
       
   550 		}
       
   551 	self->iAsyncEvent = ECmdIdle;
       
   552     MPX_DEBUG1("CMPXScanningWaitDialog::CallHarvesterScanL --->");
       
   553     return KErrNone;
       
   554     }
   491 // END OF FILE
   555 // END OF FILE
   492 
   556