|
Nokia N97 SDK Example Applications Guide |
#include <CCEMusicView.h>
Inheritance diagram for CCEMusicView:

Definition at line 41 of file CCEMusicView.h.
Public Member Functions |
|
| virtual | ~CCEMusicView () |
| void | HandleCommandL (TInt aCommand) |
| TUid | Id () const |
| void | DoActivateL (const TVwsViewId &aPrevViewId, TUid aCustomMessageId, const TDesC8 &aCustomMessage) |
| void | DoDeactivate () |
| void | HandleClientRectChange () |
| void | DynInitMenuPaneL (TInt aResourceId, CEikMenuPane *aMenuPane) |
| void | ItemsChangedL () |
| void | PopulateListBoxL () |
Static Public Member Functions |
|
| static CCEMusicView * | NewL (MCLFContentListingEngine *aEngine, MCLFItemListModel *aModel, CCEOperationObserver *aObserver) |
| static CCEMusicView * | NewLC (MCLFContentListingEngine *aEngine, MCLFItemListModel *aModel, CCEOperationObserver *aObserver) |
Private Member Functions |
|
| CCEMusicView (MCLFContentListingEngine *aEngine, MCLFItemListModel *aModel, CCEOperationObserver *aObserver) | |
| void | ConstructL () |
| void | RenameMusicFileL (const TInt aFileIndex) |
| void | SetSortingL () |
Private Attributes |
|
| CCEMusicContainer * | iContainer |
| MCLFContentListingEngine * | iEngine |
| MCLFItemListModel * | iModel |
| CCEOperationObserver * | iObserver |
| CCESoundPlayer * | iSoundPlayer |
| CCEWaitNote * | iWaitNote |
| MCLFSortingStyle * | iSortingStyle |
| MCLFSortingStyle * | iSecondarySortingStyle |
| CCECustomSorter * | iCustomSorter |
| HBufC * | iNoTagInfoItem |
| CActiveSchedulerWait | iWait |
|
|
Destructor. Definition at line 111 of file CCEMusicView.cpp. References iObserver, and CCEOperationObserver::RemoveMusicView(). 00112 { 00113 if( iObserver ) 00114 { 00115 iObserver->RemoveMusicView(); 00116 } 00117 if( iContainer ) 00118 { 00119 AppUi()->RemoveFromStack( iContainer ); 00120 delete iContainer; 00121 } 00122 00123 delete iWaitNote; 00124 delete iSecondarySortingStyle; 00125 delete iSortingStyle; 00126 delete iCustomSorter; 00127 delete iSoundPlayer; 00128 delete iNoTagInfoItem; 00129 }
|
|
||||||||||||||||
|
C++ default constructor.
Definition at line 51 of file CCEMusicView.cpp. Referenced by NewLC().
|
|
||||||||||||||||
|
Creates and returns a new instance of this class.
Definition at line 85 of file CCEMusicView.cpp. References NewLC(). 00088 { 00089 CCEMusicView* self = CCEMusicView::NewLC( aEngine, aModel, aObserver ); 00090 CleanupStack::Pop( self ); 00091 return self; 00092 }
|
|
||||||||||||||||
|
Creates and returns a new instance of this class. The returned object is left on the cleanup stack.
Definition at line 99 of file CCEMusicView.cpp. References CCEMusicView(). Referenced by CCEAppUi::ConstructL(), and NewL(). 00102 { 00103 CCEMusicView* self = 00104 new (ELeave) CCEMusicView( aEngine, aModel, aObserver ); 00105 CleanupStack::PushL( self ); 00106 self->ConstructL(); 00107 return self; 00108 }
|
|
|
Symbian 2nd phase constructor. Definition at line 65 of file CCEMusicView.cpp. References iNoTagInfoItem, iSoundPlayer, iWaitNote, CCEWaitNote::NewL(), and CCESoundPlayer::NewL(). 00066 { 00067 BaseConstructL( R_CE_MUSIC_VIEW ); 00068 00069 // Load no-tag-info list item from the resource. It will be used for 00070 // items missing artist or title tag info (file name is displayed). 00071 iNoTagInfoItem = StringLoader::LoadL( R_CE_NO_TAG_INFO_LIST_ITEM ); 00072 00073 // Create sound player for playing audio files 00074 iSoundPlayer = CCESoundPlayer::NewL(); 00075 00076 // Create a wait note 00077 iWaitNote = CCEWaitNote::NewL(); 00078 }
|
|
|
From CAknView. Handle user's commands. Definition at line 136 of file CCEMusicView.cpp. References iSoundPlayer, and CCESoundPlayer::PlayerState(). 00137 { 00138 switch( aCommand ) 00139 { 00140 case ECECmdSelect: 00141 { 00142 // Start playback if the player is not playing 00143 if( iSoundPlayer->PlayerState() != ECEPlaying ) 00144 { 00145 HandleCommandL( ECECmdPlay ); 00146 } 00147 00148 // Stop current playback if the player is playing. 00149 // After stopping, play the file that is currently selected. 00150 else if( iSoundPlayer->PlayerState() == ECEPlaying ) 00151 { 00152 HandleCommandL( ECECmdStop ); 00153 } 00154 00155 break; 00156 } 00157 00158 case ECECmdPlay: 00159 { 00160 // Which sound file is selected 00161 TInt selectedFile( iContainer->CurrentItemIndex() ); 00162 00163 // Check that there was song files in the list 00164 if( selectedFile >= 0 ) 00165 { 00166 // Get path and file name of the sound file 00167 TPtrC fileNameAndPath; 00168 TInt error( iModel->Item( selectedFile ).GetField( 00169 ECLFFieldIdFileNameAndPath, fileNameAndPath ) ); 00170 User::LeaveIfError( error ); 00171 00172 // Opens the file and starts playback 00173 iSoundPlayer->StartPlaybackL( fileNameAndPath ); 00174 } 00175 break; 00176 } 00177 00178 case ECECmdStop: 00179 { 00180 // Stop playback 00181 iSoundPlayer->StopPlayback(); 00182 break; 00183 } 00184 00185 case ECECmdSort: 00186 { 00187 // Set sorting options 00188 SetSortingL(); 00189 break; 00190 } 00191 00192 case ECECmdRename: 00193 { 00194 // Rename selected file 00195 TInt selectedFile( iContainer->CurrentItemIndex() ); 00196 if( selectedFile >= 0 ) 00197 { 00198 RenameMusicFileL( iContainer->CurrentItemIndex() ); 00199 } 00200 break; 00201 } 00202 00203 case EAknSoftkeyBack: 00204 { 00205 // Remove the changed item observer 00206 if( iObserver ) 00207 { 00208 iObserver->RemoveMusicView(); 00209 } 00210 00211 AppUi()->ActivateLocalViewL( KCEGroupViewId ); 00212 break; 00213 } 00214 00215 case EAknCmdExit: 00216 { 00217 // Remove the changed item observer 00218 if( iObserver ) 00219 { 00220 iObserver->RemoveMusicView(); 00221 } 00222 00223 // FALLTHROUGH 00224 } 00225 00226 00227 default: 00228 { 00229 AppUi()->HandleCommandL( aCommand ); 00230 break; 00231 } 00232 } 00233 }
|
|
|
From CAknView. Get Id of the view. Definition at line 240 of file CCEMusicView.cpp.
|
|
||||||||||||||||
|
From CAknView. Activate the view. Definition at line 250 of file CCEMusicView.cpp. References CCEMusicContainer::ConstructL(), and iContainer. 00253 { 00254 // Create the container for Music view 00255 if( !iContainer ) 00256 { 00257 iContainer = new (ELeave) CCEMusicContainer( this ); 00258 iContainer->SetMopParent( this ); 00259 iContainer->ConstructL(); 00260 } 00261 00262 AppUi()->AddToViewStackL( *this, iContainer ); 00263 00264 // Generate and populate the list box 00265 PopulateListBoxL(); 00266 00267 iObserver->SetMusicView( this ); 00268 }
|
|
|
From CAknView. Deactivate the view. Definition at line 275 of file CCEMusicView.cpp. References iContainer. 00276 { 00277 if( iContainer ) 00278 { 00279 AppUi()->RemoveFromStack( iContainer ); 00280 } 00281 00282 delete iContainer; 00283 iContainer = NULL; 00284 }
|
|
|
From CAknView. Handle change of rect. Definition at line 291 of file CCEMusicView.cpp. References iContainer. 00292 { 00293 if( iContainer ) 00294 { 00295 iContainer->SetRect( iAvkonAppUi->ClientRect() ); 00296 } 00297 }
|
|
||||||||||||
|
From CAknView. Dim items of the menu pane. Definition at line 304 of file CCEMusicView.cpp. References iSoundPlayer, and CCESoundPlayer::PlayerState(). 00306 { 00307 // Dim items from the options-menu 00308 if( aResourceId == R_CE_MUSIC_VIEW_MENUPANE ) 00309 { 00310 // Dim "stop" if the player is not playing 00311 if( iSoundPlayer->PlayerState() != ECEPlaying ) 00312 { 00313 aMenuPane->SetItemDimmed( ECECmdStop, ETrue ); 00314 } 00315 00316 // Dim "play" if the player is playing, or if there are 00317 // no music files in the list box 00318 else if( iSoundPlayer->PlayerState() == ECEPlaying ) 00319 { 00320 aMenuPane->SetItemDimmed( ECECmdPlay, ETrue ); 00321 } 00322 00323 // Dim "play", "sort" and "rename" if there are 00324 // no music files in the list box 00325 if ( iContainer->CurrentItemIndex() < 0 ) 00326 { 00327 aMenuPane->SetItemDimmed( ECECmdPlay, ETrue ); 00328 aMenuPane->SetItemDimmed( ECECmdSort, ETrue ); 00329 aMenuPane->SetItemDimmed( ECECmdRename, ETrue ); 00330 } 00331 } 00332 }
|
|
|
Changed item observer will call this function when some item has changed. Definition at line 339 of file CCEMusicView.cpp. References CCEWaitNote::CloseWaitNoteL(), iModel, iObserver, iWait, iWaitNote, CCEWaitNote::OpenWaitNoteL(), PopulateListBoxL(), and CCEOperationObserver::PrepareForRefresh(). 00340 { 00341 // Refresh the model and wait for refresh to complete while displaying 00342 // a wait note. After refreshing, re-generate the list box. 00343 iObserver->PrepareForRefresh( iWait ); 00344 00345 iWaitNote->OpenWaitNoteL( R_CE_WAIT_NOTE ); 00346 00347 iModel->RefreshL(); 00348 00349 iWait.Start(); 00350 PopulateListBoxL(); 00351 00352 iWaitNote->CloseWaitNoteL(); 00353 }
|
|
|
List all files from the list model to the list box. Definition at line 360 of file CCEMusicView.cpp. References iContainer, iModel, and CCEMusicContainer::ResetListBoxL(). Referenced by ItemsChangedL(), and SetSortingL(). 00361 { 00362 // Reset the list box 00363 iContainer->ResetListBoxL(); 00364 00365 // Add items from model to the list box 00366 TInt numberOfItems( iModel->ItemCount() ); 00367 for( TInt i = 0; i < numberOfItems; ++i ) 00368 { 00369 // Get the item 00370 const MCLFItem& myItem = iModel->Item( i ); 00371 00372 // Get title, artist and album tag info of the item 00373 TPtrC songTitle; 00374 TInt errorTitle( myItem.GetField( ECLFFieldIdSongName, songTitle ) ); 00375 TPtrC songArtist; 00376 TInt errorArtist( myItem.GetField( ECLFFieldIdArtist, songArtist ) ); 00377 TPtrC songAlbum; 00378 TInt errorAlbum( myItem.GetField( ECLFFieldIdAlbum, songAlbum ) ); 00379 00380 // Create text array for creating the list box item 00381 CDesCArray* textItems = 00382 new (ELeave) CDesCArraySeg( KCEArrayGranularity ); 00383 CleanupStack::PushL( textItems ); 00384 00385 // If title and artist tags were found 00386 if( errorTitle == KErrNone && errorArtist == KErrNone ) 00387 { 00388 textItems->AppendL( songTitle ); 00389 textItems->AppendL( songArtist ); 00390 00391 // If an album tag was found too 00392 if( errorAlbum == KErrNone ) 00393 { 00394 textItems->AppendL( songAlbum ); 00395 } 00396 } 00397 00398 // If title or artist tag is not found, the file name is used 00399 else 00400 { 00401 TPtrC songFileName; 00402 TInt errorFileName( iModel->Item( i ).GetField( 00403 ECLFFieldIdFileName, songFileName ) ); 00404 User::LeaveIfError( errorFileName ); 00405 00406 textItems->AppendL( songFileName ); 00407 textItems->AppendL( *iNoTagInfoItem ); 00408 } 00409 00410 // Add item to the list box 00411 iContainer->AppendListBoxItemL( textItems ); 00412 00413 CleanupStack::PopAndDestroy( textItems ); 00414 } 00415 00416 // Select the topmost item of the list box to current 00417 iContainer->SetCurrentItemIndex( 0 ); 00418 }
|
|
|
Renames selected music file.
Definition at line 425 of file CCEMusicView.cpp. References iEngine, and iModel. 00426 { 00427 // Get file name of the sound file 00428 TPtrC fileName; 00429 TInt errorName( iModel->Item( aFileIndex ).GetField( 00430 ECLFFieldIdFileNameAndPath, fileName ) ); 00431 User::LeaveIfError( errorName ); 00432 00433 // Query new file name 00434 TFileName newFileName = fileName; 00435 CAknTextQueryDialog* dlg = CAknTextQueryDialog::NewL( newFileName ); 00436 00437 if( dlg->ExecuteLD( R_CE_RENAME_QUERY ) ) 00438 { 00439 // Open connection to the file system and rename the file 00440 RFs fs; 00441 User::LeaveIfError( fs.Connect() ); 00442 CleanupClosePushL( fs ); 00443 User::LeaveIfError( fs.Rename( fileName, newFileName ) ); 00444 CleanupStack::PopAndDestroy(); // fs 00445 00446 // Request the content listing engine to refresh its file listing. 00447 // Calling method UpdateItemsL after renaming a file, will cause 00448 // changed item event to be generated. 00449 iEngine->UpdateItemsL(); 00450 } 00451 }
|
|
|
Query and set sorting options. Definition at line 458 of file CCEMusicView.cpp. References iCustomSorter, iModel, iSecondarySortingStyle, iSortingStyle, CCECustomSorter::NewL(), and PopulateListBoxL(). 00459 { 00460 // Remove old sorting styles and custom sorter if any 00461 iModel->SetSortingStyle( NULL ); 00462 iModel->SetCustomSorter( NULL ); 00463 00464 delete iSortingStyle; 00465 iSortingStyle = NULL; 00466 00467 delete iSecondarySortingStyle; 00468 iSecondarySortingStyle = NULL; 00469 00470 delete iCustomSorter; 00471 iCustomSorter = NULL; 00472 00473 // Create new sorting style for default sorting 00474 iSortingStyle = ContentListingFactory::NewSortingStyleLC(); 00475 CleanupStack::Pop(); // iSortingStyle 00476 00477 // Query for default sorting parameter 00478 TInt sortBy( 0 ); 00479 CAknListQueryDialog* dlg; 00480 dlg = new (ELeave) CAknListQueryDialog( &sortBy ); 00481 if( dlg->ExecuteLD( R_CE_DEFAULT_SORTING_PARAM_QUERY ) ) 00482 { 00483 // Set default sorting parameter 00484 switch( sortBy ) 00485 { 00486 case ECESortByAlbum: 00487 { 00488 // Sort items by album name 00489 iSortingStyle->AddFieldL( ECLFFieldIdAlbum ); 00490 00491 // You can add multiple parameters for sorting style: 00492 // In this case, if the item does not have ECLFFieldIdAlbum 00493 // then ECLFFieldIdArtist is used to sort the item 00494 iSortingStyle->AddFieldL( ECLFFieldIdArtist ); 00495 00496 // Fields are string type 00497 iSortingStyle->SetSortingDataType( ECLFItemDataTypeDesC ); 00498 break; 00499 } 00500 00501 case ECESortByArtist: 00502 { 00503 // Sort items by artist name 00504 iSortingStyle->AddFieldL( ECLFFieldIdArtist ); 00505 00506 // Field is string type 00507 iSortingStyle->SetSortingDataType( ECLFItemDataTypeDesC ); 00508 break; 00509 } 00510 00511 case ECESortByTitle: 00512 { 00513 // Sort items by song title 00514 iSortingStyle->AddFieldL( ECLFFieldIdSongName ); 00515 00516 // Field is string type 00517 iSortingStyle->SetSortingDataType( ECLFItemDataTypeDesC ); 00518 break; 00519 } 00520 00521 case ECESortByGenre: 00522 { 00523 // Sort items by genre 00524 iSortingStyle->AddFieldL( ECLFFieldIdGenre ); 00525 00526 // Field is string type 00527 iSortingStyle->SetSortingDataType( ECLFItemDataTypeDesC ); 00528 break; 00529 } 00530 00531 case ECESortByFileDate: 00532 { 00533 // Sort items by file date 00534 iSortingStyle->AddFieldL( ECLFFieldIdFileDate ); 00535 00536 // Field is TTime type 00537 iSortingStyle->SetSortingDataType( ECLFItemDataTypeTTime ); 00538 break; 00539 } 00540 00541 case ECESortByRandom: 00542 { 00543 // Create a custom sorter and set it to the model. 00544 // This custom sorter will randomize the list model. 00545 iCustomSorter = CCECustomSorter::NewL(); 00546 iModel->SetCustomSorter( iCustomSorter ); 00547 00548 // Refresh the model, wait for the refresh to complete 00549 // and re-generate the list box 00550 iModel->RefreshL( ECLFRefreshSorting | ECLFRefreshPostFilter ); 00551 PopulateListBoxL(); 00552 return; 00553 } 00554 00555 default: 00556 { 00557 return; 00558 } 00559 } 00560 } 00561 else 00562 { 00563 return; 00564 } 00565 00566 // Query for sorting order 00567 TInt sortingOrder( 0 ); 00568 dlg = new (ELeave) CAknListQueryDialog( &sortingOrder ); 00569 if( dlg->ExecuteLD( R_CE_ORDERING_SORTING_PARAM_QUERY ) ) 00570 { 00571 // Set sorting order 00572 switch( sortingOrder ) 00573 { 00574 case ECESortingOrderAscending: 00575 { 00576 iSortingStyle->SetOrdering( ECLFOrderingAscending ); 00577 break; 00578 } 00579 00580 case ECESortingOrderDescending: 00581 { 00582 iSortingStyle->SetOrdering( ECLFOrderingDescending ); 00583 break; 00584 } 00585 00586 default: 00587 { 00588 return; 00589 } 00590 } 00591 } 00592 else 00593 { 00594 return; 00595 } 00596 00597 // Query how to position items that have no tag info 00598 // for default sorting parameter. 00599 TInt sortPosition( 0 ); 00600 dlg = new (ELeave) CAknListQueryDialog( &sortPosition ); 00601 if( dlg->ExecuteLD( R_CE_POSITION_SORTING_PARAM_QUERY ) ) 00602 { 00603 switch( sortPosition ) 00604 { 00605 // Items are sent to the end of the list 00606 case ECESortPositionBottom: 00607 { 00608 iSortingStyle->SetUndefinedItemPosition( 00609 ECLFSortingStyleUndefinedEnd ); 00610 break; 00611 } 00612 00613 // Items are sent to the top of the list 00614 case ECESortPositionTop: 00615 { 00616 iSortingStyle->SetUndefinedItemPosition( 00617 ECLFSortingStyleUndefinedFirst ); 00618 break; 00619 } 00620 00621 default: 00622 { 00623 return; 00624 } 00625 } 00626 } 00627 else 00628 { 00629 return; 00630 } 00631 00632 // Set the primary sorting style to the model 00633 iModel->SetSortingStyle( iSortingStyle ); 00634 00635 // Sorting styles can be created from the resource too: 00636 // Create a resource reader for creating the secondary sorting style 00637 // from the resource 00638 TResourceReader resourceReader; 00639 iCoeEnv->CreateResourceReaderLC( 00640 resourceReader, R_CE_SECONDARY_SORTING_STYLE ); 00641 iSecondarySortingStyle = 00642 ContentListingFactory::NewSortingStyleLC( resourceReader ); 00643 CleanupStack::Pop(); // iSecondarySortingStyle 00644 00645 // Set the secondary sorting style to the model: 00646 // After sorting music files by default sorting parameter/parameters, 00647 // sort remaining files; files that did not have any of those 00648 // parameters. In this case, files that do not have any of the primary 00649 // sorting parameters, are sorted by file name. 00650 // You can add multiple secondary sorting styles too. 00651 iModel->AppendSecondarySortingStyleL( *iSecondarySortingStyle ); 00652 00653 // Refresh the model and re-generate the list box 00654 iModel->RefreshL( ECLFRefreshSorting | ECLFRefreshPostFilter ); 00655 PopulateListBoxL(); 00656 00657 CleanupStack::PopAndDestroy(); // resourceReader 00658 }
|
|
© Nokia 2009 |