playlist.cpp
来自「VLC媒体播放程序」· C++ 代码 · 共 1,339 行 · 第 1/3 页
CPP
1,339 行
} char psz_duration[MSTRTIME_MAX_SIZE]; mtime_t dur = p_item->i_duration; if( dur != -1 ) secstotimestr( psz_duration, dur/1000000 ); else memcpy( psz_duration , "-:--:--", sizeof("-:--:--") ); listview->SetItem( i, 2, wxU(psz_duration) ); /* Change the colour for the currenty played stream */ wxListItem listitem; listitem.m_itemId = i; if( i == p_playlist->i_index ) { listitem.SetTextColour( *wxRED ); } else { listitem.SetTextColour( *wxBLACK ); } listview->SetItem( listitem ); vlc_object_release(p_playlist);}/********************************************************************** * Rebuild the playlist **********************************************************************/void Playlist::Rebuild(){ playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE ); if( p_playlist == NULL ) { return; } int i_focused = listview->GetFocusedItem(); /* Clear the list... */ listview->DeleteAllItems(); /* ...and rebuild it */ vlc_mutex_lock( &p_playlist->object_lock ); for( int i = 0; i < p_playlist->i_size; i++ ) { wxString filename = wxL2U(p_playlist->pp_items[i]->psz_name); listview->InsertItem( i, filename ); UpdateItem( i ); } vlc_mutex_unlock( &p_playlist->object_lock ); if( i_focused >= 0 && i_focused < p_playlist->i_size ) { listview->Focus( i_focused ); listview->Select( i_focused ); } else if( p_playlist->i_index >= 0 ) { listview->Focus( p_playlist->i_index ); } vlc_object_release( p_playlist );}void Playlist::ShowPlaylist( bool show ){ if( show ) Rebuild(); Show( show );}void Playlist::UpdatePlaylist(){ i_update_counter++; /* If the playlist isn't show there's no need to update it */ if( !IsShown() ) return; if( this->b_need_update ) { this->b_need_update = VLC_FALSE; Rebuild(); } /* Updating the playing status every 0.5s is enough */ if( i_update_counter % 5 ) return; playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE ); if( p_playlist == NULL ) { return; } /* Update the colour of items */ int i_playlist_index = p_playlist->i_index; if( p_intf->p_sys->i_playing != i_playlist_index ) { wxListItem listitem; listitem.m_itemId = i_playlist_index; listitem.SetTextColour( *wxRED ); listview->SetItem( listitem ); if( p_intf->p_sys->i_playing != -1 ) { listitem.m_itemId = p_intf->p_sys->i_playing; listitem.SetTextColour( *wxBLACK ); listview->SetItem( listitem ); } p_intf->p_sys->i_playing = i_playlist_index; } vlc_object_release( p_playlist );}/***************************************************************************** * Private methods. *****************************************************************************/void Playlist::DeleteItem( int item ){ playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE ); if( p_playlist == NULL ) { return; } playlist_Delete( p_playlist, item ); listview->DeleteItem( item ); vlc_object_release( p_playlist );}void Playlist::OnClose( wxCommandEvent& WXUNUSED(event) ){ Hide();}void Playlist::OnSave( wxCommandEvent& WXUNUSED(event) ){ struct { char *psz_desc; char *psz_filter; char *psz_module; } formats[] = {{ _("M3U file"), "*.m3u", "export-m3u" }, { _("PLS file"), "*.pls", "export-pls" }}; wxString filter = wxT(""); for( unsigned int i = 0; i < sizeof(formats)/sizeof(formats[0]); i++) { filter.Append( wxU(formats[i].psz_desc) ); filter.Append( wxT("|") ); filter.Append( wxU(formats[i].psz_filter) ); filter.Append( wxT("|") ); } wxFileDialog dialog( this, wxU(_("Save playlist")), wxT(""), wxT(""), filter, wxSAVE ); if( dialog.ShowModal() == wxID_OK ) { playlist_t * p_playlist = (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE ); if( p_playlist ) { if( dialog.GetFilename().mb_str() ) { playlist_Export( p_playlist, dialog.GetFilename().mb_str(), formats[dialog.GetFilterIndex()].psz_module ); } } vlc_object_release( p_playlist ); }}void Playlist::OnOpen( wxCommandEvent& WXUNUSED(event) ){ playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE ); if( p_playlist == NULL ) { return; } wxFileDialog dialog( this, wxU(_("Open playlist")), wxT(""), wxT(""), wxT("All playlists|*.pls;*.m3u;*.asx;*.b4s|M3U files|*.m3u"), wxOPEN ); if( dialog.ShowModal() == wxID_OK ) { playlist_Import( p_playlist, dialog.GetPath().mb_str() ); } vlc_object_release( p_playlist );}void Playlist::OnAddFile( wxCommandEvent& WXUNUSED(event) ){ p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_FILE_SIMPLE, 0, 0 );#if 0 Rebuild();#endif}void Playlist::OnAddMRL( wxCommandEvent& WXUNUSED(event) ){ p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_FILE, 0, 0 );#if 0 Rebuild();#endif}/******************************************************************** * Move functions ********************************************************************/void Playlist::OnUp( wxCommandEvent& event ){ playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE ); if( p_playlist == NULL ) { return; } /* We use the first selected item, so find it */ long i_item = listview->GetNextItem( -1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); if( i_item > 0 && i_item < p_playlist->i_size ) { playlist_Move( p_playlist, i_item, i_item - 1 ); listview->Focus( i_item - 1 ); } vlc_object_release( p_playlist ); return;}void Playlist::OnDown( wxCommandEvent& event ){ playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE ); if( p_playlist == NULL ) { return; } /* We use the first selected item, so find it */ long i_item = listview->GetNextItem( -1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED ); if( i_item >= 0 && i_item < p_playlist->i_size - 1 ) { playlist_Move( p_playlist , i_item, i_item + 2 ); listview->Focus( i_item + 1 ); } vlc_object_release( p_playlist ); return;}/******************************************************************** * Sorting functions ********************************************************************/void Playlist::OnSort( wxCommandEvent& event ){ playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE ); if( p_playlist == NULL ) { return; } switch( event.GetId() ) { case SortTitle_Event: playlist_SortTitle( p_playlist , ORDER_NORMAL ); break; case RSortTitle_Event: playlist_SortTitle( p_playlist , ORDER_REVERSE ); break; case SortAuthor_Event: playlist_SortAuthor(p_playlist , ORDER_NORMAL ); break; case RSortAuthor_Event: playlist_SortAuthor( p_playlist , ORDER_REVERSE ); break; case SortGroup_Event: playlist_SortGroup( p_playlist , ORDER_NORMAL ); break; case RSortGroup_Event: playlist_SortGroup( p_playlist , ORDER_REVERSE ); break; case Randomize_Event: playlist_Sort( p_playlist , SORT_RANDOM, ORDER_NORMAL ); break; } vlc_object_release( p_playlist ); Rebuild(); return;}void Playlist::OnColSelect( wxListEvent& event ){ playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE ); if( p_playlist == NULL ) { return; } switch( event.GetColumn() ) { case 0: if( i_title_sorted != 1 ) { playlist_SortTitle( p_playlist, ORDER_NORMAL ); i_title_sorted = 1; } else { playlist_SortTitle( p_playlist, ORDER_REVERSE ); i_title_sorted = -1; } break; case 1: if( i_author_sorted != 1 ) { playlist_SortAuthor( p_playlist, ORDER_NORMAL ); i_author_sorted = 1; } else { playlist_SortAuthor( p_playlist, ORDER_REVERSE ); i_author_sorted = -1; } break; case 2: if( i_duration_sorted != 1 ) { playlist_Sort( p_playlist, SORT_DURATION, ORDER_NORMAL ); i_duration_sorted = 1; } else { playlist_Sort( p_playlist, SORT_DURATION, ORDER_REVERSE ); i_duration_sorted = -1; } break; case 3: if( i_group_sorted != 1 ) { playlist_SortGroup( p_playlist, ORDER_NORMAL ); i_group_sorted = 1; } else { playlist_SortGroup( p_playlist, ORDER_REVERSE ); i_group_sorted = -1; } break; default: break; } vlc_object_release( p_playlist ); Rebuild(); return;}/********************************************************************** * Search functions **********************************************************************/void Playlist::OnSearchTextChange( wxCommandEvent& WXUNUSED(event) ){ search_button->SetDefault();}void Playlist::OnSearch( wxCommandEvent& WXUNUSED(event) ){ wxString search_string = search_text->GetValue(); bool b_ok = false; int i_current; int i_first = 0 ; int i_item = -1; for( i_current = 0; i_current < listview->GetItemCount(); i_current++ ) { if( listview->GetItemState( i_current, wxLIST_STATE_SELECTED ) == wxLIST_STATE_SELECTED ) { i_first = i_current; break; } } if( i_first == listview->GetItemCount() ) { i_first = -1; } for( i_current = i_first + 1; i_current < listview->GetItemCount(); i_current++ ) { wxListItem listitem; listitem.SetId( i_current ); listview->GetItem( listitem ); if( listitem.m_text.Lower().Contains( search_string.Lower() ) ) { i_item = i_current; b_ok = true; break; } listitem.SetColumn( 1 ); listview->GetItem( listitem ); if( listitem.m_text.Lower().Contains( search_string.Lower() ) ) { i_item = i_current; b_ok = true; break; } } if( !b_ok ) { for( i_current = -1 ; i_current < i_first - 1; i_current++ ) { wxListItem listitem; listitem.SetId( i_current ); listview->GetItem( listitem ); if( listitem.m_text.Lower().Contains( search_string.Lower() ) ) { i_item = i_current; b_ok = true; break; } listitem.SetColumn( 1 ); listview->GetItem( listitem );
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?