📄 beosmusicbrowser.cpp
字号:
}
break;
}
case MBMSG_PLAYLIST_VIEW_INVOKED:
PRINT(( "goto %d\n", message->FindInt32( "index" ) ));
m_plm->SetCurrentIndex( message->FindInt32( "index" ) );
break;
case MBMSG_EDIT_CATALOG_ITEM:
{
CatalogItem* item;
message->FindPointer( "item", (void**)&item );
if ( item )
{
EditCatalogItem( item );
}
break;
}
case MBMSG_EDIT_INFO:
{
if ( !m_selectedView ) break;
BListItem* li =
m_selectedView->ItemAt( m_selectedView->CurrentSelection() );
CatalogItem* item = dynamic_cast<CatalogItem*>( li );
if ( item )
{
EditCatalogItem( item );
}
break;
}
case MBMSG_REMOVE_ITEMS:
{
int32 index = m_playlistView->CurrentSelection();
if ( index >= 0 )
{
m_plm->RemoveItem( index );
}
break;
}
case MBMSG_MOVE_UP:
{
int32 index = m_playlistView->CurrentSelection();
MovePlaylistItem( index, index - 1 );
break;
}
case MBMSG_MOVE_DOWN:
{
int32 index = m_playlistView->CurrentSelection();
MovePlaylistItem( index, index + 1 );
break;
}
case MBMSG_SORT_PLAYLIST:
{
PlaylistSortKey key
= (PlaylistSortKey)message->FindInt32( "PlaylistSortKey" );
PRINT(( "Sorting by %ld\n", key ));
m_plm->Sort( key );
break;
}
case MBMSG_SELECTION_CHANGED:
{
BListView* lv;
if ( message->FindPointer( "source", (void**)&lv ) < B_OK ) break;
if ( m_selectedView == NULL )
{
m_selectedView = lv;
}
else if ( lv != m_selectedView && lv->CurrentSelection() >= 0 )
{
m_selectedView->DeselectAll();
m_selectedView = lv;
}
break;
}
case MBMSG_TOOLTIP_MESSAGE:
{
const char* str;
if ( message->FindString( "text", &str ) == B_OK )
{
m_placard->SetText( str );
}
break;
}
#if DEBUG_MENU
case MBMSG_DEBUG_1:
m_musicTreeView->ClearMyMusicGroup();
break;
case MBMSG_DEBUG_2:
m_musicTreeView->ClearPlaylistGroup();
break;
case MBMSG_DEBUG_3:
UpdateCatalogView();
break;
case MBMSG_DEBUG_4:
break;
#endif
default:
BWindow::MessageReceived( message );
break;
}
}
void
BeOSMusicBrowser::Quit( void )
{
if ( !m_master )
{
PRINT(( "telling musicbrowser ui to dispose of the handle pointing to me\n" ));
m_ui->EditorDone( this );
}
BWindow::Quit();
}
bool
BeOSMusicBrowser::QuitRequested( void )
{
if ( m_master )
{
Hide();
return false;
}
else
{
return true;
}
}
void
BeOSMusicBrowser::LoadPlaylist( const string& playlist )
{
if ( playlist == m_currentListName || playlist.length() == 0 ) return;
if ( m_currentListName.length() > 0 && !m_master )
{
PRINT(( "FIXME: do you want to save the current playlist?\n" ));
}
if ( strncmp( "file://", playlist.c_str(), 7 ) == 0 )
{
m_plm->ReadPlaylist( playlist.c_str() );
m_currentListName = playlist;
}
else
{
uint32 length = B_PATH_NAME_LENGTH;
char* url = new char[ length ];
if ( IsntError( FilePathToURL( playlist.c_str(), url, &length ) ) )
{
m_plm->ReadPlaylist( url );
m_currentListName = url;
}
delete[] url;
}
}
void
BeOSMusicBrowser::SaveCurrentPlaylist( const char* path )
{
if ( path != NULL )
{
m_currentListName = path;
}
if ( m_currentListName.length() == 0 ) return;
char* ext = strrchr( m_currentListName.c_str(), '.' );
if ( ext ) ext++;
PRINT(( "ext = %s\n", ext ));
int i = 0;
bool found = false;
PlaylistFormatInfo format;
while ( ext &&
m_plm->GetSupportedPlaylistFormats( &format, i ) == kError_NoErr )
{
PRINT(( "supported format ext = %s\n", format.GetExtension() ));
if ( strcmp( ext, format.GetExtension() ) == 0 )
{
found = true;
break;
}
i++;
}
if ( !found )
{
// if no format is supported, just use the first supported format.
m_plm->GetSupportedPlaylistFormats( &format, 0 );
m_currentListName += ".";
m_currentListName += format.GetExtension();
}
PRINT(( "saving as list = %s\n", m_currentListName.c_str() ));
if ( strncmp( "file://", m_currentListName.c_str(), 7 ) == 0 )
{
m_plm->WritePlaylist( m_currentListName.c_str(), &format );
m_context->catalog->AddPlaylist( m_currentListName.c_str() );
}
else
{
size_t len = m_currentListName.length() + 20;
char* writeURL = new char[ len ];
Error err = FilePathToURL( m_currentListName.c_str(), writeURL, &len );
if ( IsntError( err ) )
{
PRINT(( "Saving current playlist as %s\n", writeURL ));
m_plm->WritePlaylist( writeURL, &format );
m_context->catalog->AddPlaylist( writeURL );
}
delete[] writeURL;
}
}
// ------------------------------------------
// Edit whatever item the user has selected.
// Playlist -> Spawn new editor.
// TrackItem -> Spawn meta data editor.
// ------------------------------------------
void
BeOSMusicBrowser::EditCatalogItem( CatalogItem* item )
{
switch ( item->Type() )
{
case CatalogItem::ITEM_PLAYLIST:
{
PRINT(( "This is playlist\n" ));
PlaylistListItem* pi = dynamic_cast<PlaylistListItem*>( item );
m_ui->CreateNewEditor( string( pi->URL() ) );
break;
}
case CatalogItem::ITEM_TRACK:
{
PRINT(( "Editing the meta data\n" ));
TrackItem* ti = dynamic_cast<TrackItem*>( item );
InfoEditor* editor =
new InfoEditor( BRect( 100, 100, 400, 300 ), "Edit Info",
ti->Item() );
editor->Show();
const MetaData& md = ti->Item()->GetMetaData();
PRINT(( "%s, %s, %s\n", md.Artist().c_str(), md.Album().c_str(), md.Title().c_str() ));
break;
}
default:
break;
}
}
// ----------------------------------------------------
// Rebuild the music catalog tree view from the catalog
// ----------------------------------------------------
void
BeOSMusicBrowser::UpdateCatalogView( void )
{
MusicCatalog* catalog = m_context->catalog;
catalog->GetCatalogLock();
const vector<PlaylistItem*>* unsorted = catalog->GetUnsortedMusic();
const vector<ArtistList*>* artists = catalog->GetMusicList();
PRINT(( "there're %ld unsorted items in catalog\n", unsorted->size() ));
m_musicTreeView->ClearMyMusicGroup();
int32 artistOutlineLevel = m_musicTreeView->ArtistOutlineLevel();
vector<PlaylistItem*>::const_iterator i;
for ( i = unsorted->begin(); i != unsorted->end(); i++ )
{
TrackItem* uncatItem = new TrackItem( *i );
m_musicTreeView->AddUnderUncategorizedGroup( uncatItem );
}
vector<ArtistList*>::const_iterator artist;
for ( artist = artists->begin(); artist != artists->end(); artist++ )
{
CollectionItem* artistItem
= new CollectionItem( (*artist)->name.c_str(), artistOutlineLevel );
m_musicTreeView->AddArtistItem( artistItem );
vector<AlbumList*>* albums = (*artist)->m_albumList;
vector<AlbumList*>::iterator album;
for ( album = albums->begin(); album != albums->end(); album++ )
{
CollectionItem* albumItem
= new CollectionItem( (*album)->name.c_str() );
m_musicTreeView->AddUnder( albumItem, artistItem );
vector<PlaylistItem*>* tracks = (*album)->m_trackList;
vector<PlaylistItem*>::iterator track;
for ( track = tracks->begin(); track != tracks->end(); track++ )
{
TrackItem* item = new TrackItem( *track );
m_musicTreeView->AddUnder( item, albumItem );
TrackItem* allItem = new TrackItem( *item );
m_musicTreeView->AddUnderAllTracksGroup( allItem );
}
}
}
UpdateCatalogPlaylistGroup();
catalog->ReleaseCatalogLock();
m_musicTreeView->FindArtistGroup( "Headboard" );
}
// --------------------------------------------
// Rebuild the playlist group only
// --------------------------------------------
void
BeOSMusicBrowser::UpdateCatalogPlaylistGroup( void )
{
MusicCatalog* catalog = m_context->catalog;
catalog->GetCatalogLock(); // on beos mutex == BLocker so it can be nested.
const vector<string>* playlists = catalog->GetPlaylists();
m_musicTreeView->ClearPlaylistGroup();
// Fill playlists.
vector<string>::const_iterator pi;
for ( pi = playlists->begin(); pi != playlists->end(); pi++ )
{
PlaylistListItem* item = new PlaylistListItem( (*pi) );
m_musicTreeView->AddPlaylistListItem( item );
}
catalog->ReleaseCatalogLock();
}
// -------------------------------------------
// Rebuild the playlist view from the catalog
// -------------------------------------------
void
BeOSMusicBrowser::UpdatePlaylistView( void )
{
Lock();
BeginViewTransaction();
// Remember the selected index.
uint32 selected = m_playlistView->CurrentSelection();
// Populate the playlist view.
uint32 itemsInPlaylist = m_playlistView->CountItems();
for ( uint32 i = 0; i < m_plm->CountItems(); i++ )
{
bool addItReally = false;
PlaylistItem* item = m_plm->ItemAt( i );
if ( i < itemsInPlaylist )
{
TrackItem* oldItem = (TrackItem*)m_playlistView->ItemAt( i );
if ( *oldItem != *item )
{
delete m_playlistView->RemoveItem( i );
addItReally = true;
}
}
else
{
addItReally = true;
}
if ( addItReally )
{
TrackItem* listItem = new TrackItem( item );
m_playlistView->AddItem( listItem, i );
}
}
// If there's anything left in the playlist view, it should be removed.
int32 removeBegin = m_plm->CountItems();
int32 removeEnd = m_playlistView->CountItems();
if ( removeBegin < removeEnd )
{
m_playlistView->RemoveItems( removeBegin, removeEnd - removeBegin );
}
// Set the currently playing item.
m_playlistView->SetCurrentlyPlaying( m_plm->GetCurrentIndex() );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -