mpxplugins/viewplugins/views/waitnotedialog/src/mpxscanningdialog.cpp
branchRCL_3
changeset 13 c8156a91d13c
parent 9 13afc0e517bd
child 14 c54d95799c80
equal deleted inserted replaced
12:171e07ac910f 13:c8156a91d13c
    49 CMPXScanningWaitDialog::CMPXScanningWaitDialog( MMPXWaitNoteObserver* aObs,
    49 CMPXScanningWaitDialog::CMPXScanningWaitDialog( MMPXWaitNoteObserver* aObs,
    50                                                 TWaitNoteType aType ) : 
    50                                                 TWaitNoteType aType ) : 
    51                                              CMPXWaitNoteDialog( aObs, aType )
    51                                              CMPXWaitNoteDialog( aObs, aType )
    52     {
    52     {
    53     iNumItemsAdded = 0;
    53     iNumItemsAdded = 0;
    54     iInitialMMCCount = 0;
       
    55     iTotalNewTracks = 0;
    54     iTotalNewTracks = 0;
       
    55     iInitialCount = 0;
       
    56     isCollectionDBChanged = EFalse;
    56     }
    57     }
    57 
    58 
    58 
    59 
    59 // ---------------------------------------------------------------------------
    60 // ---------------------------------------------------------------------------
    60 // 2nd Phased constructor
    61 // 2nd Phased constructor
   160             {
   161             {
   161             iHarvesterUtil->Close();
   162             iHarvesterUtil->Close();
   162             iHarvesterUtil = NULL;
   163             iHarvesterUtil = NULL;
   163             iHarvesterUtil = CMPXHarvesterFactory::NewL(); 
   164             iHarvesterUtil = CMPXHarvesterFactory::NewL(); 
   164             }
   165             }
       
   166         
       
   167         // When stop refreshing library, prompt a process waiting dialog.
       
   168         // Inform user to wait for the updating library.
       
   169         HBufC* waitText = StringLoader::LoadLC( R_MPX_UPDATING_LIBRARY_TXT );  
       
   170         DisplayProcessWaitDialogL( R_MPX_GENERIC_WAIT_NOTE, *waitText );
       
   171         CleanupStack::PopAndDestroy( waitText );
   165         }
   172         }
   166     else if( iScanningError >= KErrNone )
   173     else if( iScanningError >= KErrNone )
   167         {
   174         {
   168         // Show completed scan note
   175         // Show completed scan note
   169         //
   176         //
   170         if( iWaitNoteType == EMPXScanningNote || 
   177         if( iWaitNoteType == EMPXScanningNote || 
   171             iWaitNoteType == EMPXCorruptScanningNote )
   178             iWaitNoteType == EMPXCorruptScanningNote )
   172             {
   179             {
   173             text = StringLoader::LoadLC( R_MPX_SCANNING_COMPLETE_TXT, 
   180             if ( isCollectionDBChanged )
   174                                          iNumItemsAdded );
   181                 { 
   175             textRsc = R_MPX_SCANNING_COMPLETE_TXT;                                         
   182                 text = StringLoader::LoadLC( R_MPX_SCANNING_COMPLETE_TXT, 
       
   183                                                      iNumItemsAdded );
       
   184                 textRsc = R_MPX_SCANNING_COMPLETE_TXT;                
       
   185                 }
       
   186             else
       
   187                 {
       
   188                 text = StringLoader::LoadLC( R_MPX_UPTODATE_TXT );
       
   189                 textRsc = R_MPX_UPTODATE_TXT;
       
   190                 }                               
   176             }
   191             }
   177         else // iWaitNoteType == EMPXRefreshNote
   192         else // iWaitNoteType == EMPXRefreshNote
   178             {
   193             {
   179             text = StringLoader::LoadLC( R_MPX_REFRESHING_DB_COMPLETE_TXT, 
   194             if ( isCollectionDBChanged )
       
   195                 {
       
   196                 text = StringLoader::LoadLC( R_MPX_REFRESHING_DB_COMPLETE_TXT, 
   180                                          iNumItemsAdded ); 
   197                                          iNumItemsAdded ); 
   181             textRsc = R_MPX_REFRESHING_DB_COMPLETE_TXT;                    
   198                 textRsc = R_MPX_REFRESHING_DB_COMPLETE_TXT;              
       
   199                 }
       
   200             else
       
   201                 {
       
   202                 text = StringLoader::LoadLC( R_MPX_UPTODATE_TXT );
       
   203                 textRsc = R_MPX_UPTODATE_TXT; 
       
   204                 }
   182             }
   205             }
   183         }
   206         }
   184     else if( iScanningError == KErrDiskFull )
   207     else if( iScanningError == KErrDiskFull )
   185         {
   208         {
   186         // If the error was disk full
   209         // If the error was disk full
   215         DisplayNoteDialogL( R_MPX_EMPTY_CLOSE_NOTE, textRsc, iNumItemsAdded,
   238         DisplayNoteDialogL( R_MPX_EMPTY_CLOSE_NOTE, textRsc, iNumItemsAdded,
   216                             *text, CAknNoteDialog::EConfirmationTone );
   239                             *text, CAknNoteDialog::EConfirmationTone );
   217         }
   240         }
   218     else
   241     else
   219         {
   242         {
       
   243         // When finish updating library, cancle the process waiting 
       
   244         // dialog and then prompt the refreshing completion dialog.
       
   245         CancelProcessWaitDialogL();
   220         DisplayNoteDialogL( R_MPX_EMPTY_CLOSE_NOTE, *text, 
   246         DisplayNoteDialogL( R_MPX_EMPTY_CLOSE_NOTE, *text, 
   221                             CAknNoteDialog::EConfirmationTone );
   247                             CAknNoteDialog::EConfirmationTone );
   222         }
   248         }
   223         CleanupStack::PopAndDestroy( text );
   249         CleanupStack::PopAndDestroy( text );
   224         }
   250         }
   265         TInt data( aMessage.ValueTObjectL<TInt>( KMPXMessageGeneralData ) );
   291         TInt data( aMessage.ValueTObjectL<TInt>( KMPXMessageGeneralData ) );
   266         
   292         
   267         if(event == TMPXCollectionMessage::EBroadcastEvent &&
   293         if(event == TMPXCollectionMessage::EBroadcastEvent &&
   268                 ((op == EMcMsgRefreshStart) || (op == EMcMsgRefreshEnd)))
   294                 ((op == EMcMsgRefreshStart) || (op == EMcMsgRefreshEnd)))
   269             {
   295             {
   270             TInt mmcCount = 0;
   296             TInt songTotal = 0;
   271             if ( iWaitNoteType == EMPXScanningNote)
   297             
   272                 { 
   298             if ( iWaitNoteType == EMPXScanningNote )
   273                 //get removable drive number
   299                 {      
   274                 TInt removableDrive( EDriveF );                            
   300                 RArray<TUid> ary;
       
   301                 CleanupClosePushL( ary );
       
   302                 ary.AppendL(TUid::Uid( EMPXCollectionPluginPodCast ) );
       
   303                 TUid podcastCollectionId = iCollection->CollectionIDL( ary.Array() );
       
   304                 ary.Reset();
       
   305                 ary.AppendL(TUid::Uid(EMPXCollectionPluginMusic));				
       
   306                 TUid musicCollectionId = iCollection->CollectionIDL( ary.Array() );
       
   307                 CleanupStack::PopAndDestroy(&ary);
       
   308 				
       
   309 				TInt removableDrive( EDriveF );                            
   275                 #ifdef RD_MULTIPLE_DRIVE
   310                 #ifdef RD_MULTIPLE_DRIVE
   276                     User::LeaveIfError( DriveInfo::GetDefaultDrive(
   311                     User::LeaveIfError( DriveInfo::GetDefaultDrive(
   277                         DriveInfo::EDefaultRemovableMassStorage,
   312                         DriveInfo::EDefaultRemovableMassStorage,
   278                         removableDrive ) );
   313                         removableDrive ) );
   279                 #endif // RD_MULTIPLE_DRIVE
   314                 #endif // RD_MULTIPLE_DRIVE 
   280  
       
   281                 //get count from music db
       
   282             
       
   283                 CMPXCommand* cmdCount = CMPXMedia::NewL();
       
   284                 CleanupStack::PushL( cmdCount );
       
   285                 cmdCount->SetTObjectValueL<TMPXCommandId>( 
       
   286                         KMPXCommandGeneralId, 
       
   287                         KMPXCommandCollectionGetCount );
       
   288                 cmdCount->SetTObjectValueL<TBool>( 
       
   289                         KMPXCommandGeneralDoSync,
       
   290                         ETrue );
       
   291                 cmdCount->SetTObjectValueL<TInt>( 
       
   292                         KMPXCommandCollectionCountDrive,
       
   293                         removableDrive);
       
   294                 
   315                 
   295                 cmdCount->SetTObjectValueL<TInt>( 
   316                 TInt massStorageDrive( EDriveE );
   296                         KMPXCommandCollectionCountTable,
   317                 User::LeaveIfError( DriveInfo::GetDefaultDrive(
   297                         EMPXCollectionCountTotal );
   318                         DriveInfo::EDefaultMassStorage,
   298                                    
   319                         massStorageDrive ) );
   299                 // Get the collection UIDs
       
   300                 RArray<TUid> ary;
       
   301                 CleanupClosePushL( ary );
       
   302                 ary.AppendL( TUid::Uid(EMPXCollectionPluginMusic) );
       
   303                 TUid musicCollectionId = 
       
   304                 iCollection->CollectionIDL( ary.Array() );
       
   305                 CleanupStack::PopAndDestroy( &ary );
       
   306                 cmdCount->SetTObjectValueL<TInt>( 
       
   307                         KMPXCommandGeneralCollectionId,
       
   308                         musicCollectionId.iUid );
       
   309     
       
   310                 TRAPD(err, iCollection->Collection().CommandL( *cmdCount ) );
       
   311                 
   320                 
   312                 if ( KErrNotFound != err )
   321                 songTotal = GetTrackCountL( removableDrive, 
   313                     {
   322                         podcastCollectionId.iUid, EMPXCollectionCountTrack );
   314                     User::LeaveIfError( err );
   323                 songTotal += GetTrackCountL( massStorageDrive,
   315                     }
   324                         podcastCollectionId.iUid, EMPXCollectionCountTrack );
   316 
   325                 
   317                 // returned command should contain count
   326                 songTotal += GetTrackCountL( removableDrive,
   318                 if ( cmdCount->IsSupported( KMPXCommandCollectionCountValue ) )
   327                         musicCollectionId.iUid, EMPXCollectionCountTotal );
   319                     {                        
   328                 songTotal += GetTrackCountL( massStorageDrive,
   320                     mmcCount = 
   329                         musicCollectionId.iUid, EMPXCollectionCountTotal );
   321                         cmdCount->ValueTObjectL<TInt>( 
   330                 
   322                                 KMPXCommandCollectionCountValue );
       
   323                     }
       
   324                 CleanupStack::PopAndDestroy( cmdCount );
       
   325                 }
   331                 }
   326             if( op == EMcMsgRefreshStart )
   332             if( op == EMcMsgRefreshStart )
   327                 {
   333                 {
       
   334                 isCollectionDBChanged = EFalse;
   328                 MPX_DEBUG1("refreshStart store the initial count");
   335                 MPX_DEBUG1("refreshStart store the initial count");
   329                 iInitialMMCCount = mmcCount;
   336                 iInitialCount = songTotal;
   330                 }
   337                 }
   331 
   338 
   332             if( op == EMcMsgRefreshEnd )                                    
   339             if( op == EMcMsgRefreshEnd )                                    
   333             {
   340             {
   334             MPX_DEBUG1("CMPXScanningWaitDialog::HandleCollectionMessageL refresh end");
   341             MPX_DEBUG1("CMPXScanningWaitDialog::HandleCollectionMessageL refresh end");
   335             // Do not reset iNumItemsAdded while KErrLocked or KErrDiskFull.
   342             // Do not reset iNumItemsAdded while KErrLocked or KErrDiskFull.
   336             if( data != KErrLocked && data != KErrDiskFull ) 
   343             if( data != KErrLocked && data != KErrDiskFull ) 
   337             	{
   344             	{
   338             	iNumItemsAdded = mmcCount;
   345             	iNumItemsAdded = songTotal ;
   339             	}
   346             	}
   340             switch ( iWaitNoteType )
   347             switch ( iWaitNoteType )
   341                 {
   348                 {
   342                 case EMPXScanningNote:
   349                 case EMPXScanningNote:
   343                     {
   350                     {
   344                     //total new tracks on external memory 
   351                      if ( iTotalNewTracks || ( iNumItemsAdded != iInitialCount ) )
   345                     TInt totalNewOnMMC = iNumItemsAdded - iInitialMMCCount;
   352                         {
   346 
   353                         isCollectionDBChanged = ETrue;
   347                     //total new tracks on internal memory 
   354                         iNumItemsAdded = songTotal ;                        
   348                     TInt newOnPhone = iTotalNewTracks - totalNewOnMMC; 
   355                         }
   349 
   356                     else
   350                     //total new tracks to dispaly 
   357                         {
   351                     iNumItemsAdded += newOnPhone;
   358                         isCollectionDBChanged = EFalse;
   352 
   359                         }  
   353                     break;
   360                     break;
   354                     }
   361                     }
   355 
   362 
   356                 case EMPXOpeningNote:
   363                 case EMPXOpeningNote:
   357                 case EMPXRefreshingNote:
   364                 case EMPXRefreshingNote:
   364                     // fall through
   371                     // fall through
   365                 default:
   372                 default:
   366                     {
   373                     {
   367                     // Synchronize the number of items added if we had no errors
   374                     // Synchronize the number of items added if we had no errors
   368                     //
   375                     //
   369                     if( data >= KErrNone )
   376                     if( data > KErrNone || iTotalNewTracks )
   370                         {
   377                         {
   371                         iNumItemsAdded = data;
   378                         isCollectionDBChanged = ETrue;
       
   379                         iNumItemsAdded = iTotalNewTracks;
   372                         }
   380                         }
       
   381                     else
       
   382                     	{
       
   383                         isCollectionDBChanged = EFalse;
       
   384                     	}
   373                     break;
   385                     break;
   374                     }
   386                     }
   375                 };
   387                 };
   376             
   388             
   377             // If cancel was pressed, iWaitDialog is NULL
   389             // If cancel was pressed, iWaitDialog is NULL
   446                     }
   458                     }
   447                 }    
   459                 }    
   448             }
   460             }
   449         } 
   461         } 
   450     }
   462     }
   451     
   463 // ---------------------------------------------------------------------------
       
   464 // Get track count for given table in the db
       
   465 // ---------------------------------------------------------------------------
       
   466 //
       
   467 TInt CMPXScanningWaitDialog::GetTrackCountL(TInt aDrive,TInt aColDbId, TInt aColTable)
       
   468     {
       
   469     MPX_DEBUG2("--->CMPXScanningWaitDialog::GetTrackCountL() aDrive = %d", aDrive );
       
   470     TInt count(0);
       
   471 
       
   472     //get count from db
       
   473     CMPXCommand* cmdCountM = CMPXMedia::NewL();
       
   474     CleanupStack::PushL(cmdCountM);
       
   475     cmdCountM->SetTObjectValueL<TMPXCommandId>( 
       
   476 	        KMPXCommandGeneralId, 
       
   477 	        KMPXCommandCollectionGetCount );
       
   478     cmdCountM->SetTObjectValueL<TBool>(
       
   479             KMPXCommandGeneralDoSync, 
       
   480             ETrue );
       
   481     cmdCountM->SetTObjectValueL<TInt>(
       
   482             KMPXCommandGeneralCollectionId,
       
   483             aColDbId );
       
   484     cmdCountM->SetTObjectValueL<TInt>(
       
   485             KMPXCommandCollectionCountDrive,
       
   486             aDrive );
       
   487     cmdCountM->SetTObjectValueL<TInt>(
       
   488             KMPXCommandCollectionCountTable,
       
   489             aColTable );
       
   490 
       
   491     TRAPD( err, iCollection->Collection().CommandL( *cmdCountM ) );
       
   492 
       
   493     // returned command should contain count
       
   494     if ( err == KErrNone && cmdCountM->IsSupported(KMPXCommandCollectionCountValue ) )
       
   495         {
       
   496         count = cmdCountM->ValueTObjectL<TInt>(KMPXCommandCollectionCountValue);
       
   497         }
       
   498     
       
   499     CleanupStack::PopAndDestroy(cmdCountM);
       
   500     MPX_DEBUG2("--->CMPXScanningWaitDialog::GetTrackCountL() count = %d", count );
       
   501 
       
   502     return count;
       
   503     }
   452 // END OF FILE
   504 // END OF FILE
   453 
   505