📄 playlist.cpp
字号:
RemoveItem( p_item->input.i_id ); UnlockPlaylist( p_intf->p_sys, p_playlist );}void Playlist::DeleteItem( int item_id ){ playlist_Delete( p_playlist, item_id );}void Playlist::DeleteNode( playlist_item_t *p_item ){ playlist_NodeDelete( p_playlist, p_item, VLC_TRUE , VLC_FALSE );}void Playlist::OnMenuClose( wxCommandEvent& event ){ wxCloseEvent cevent; OnClose(cevent);}void Playlist::OnClose( wxCloseEvent& 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" }, { _("XSPF playlist"), "*.xspf", "export-xspf"} }; wxString filter = wxT(""); if( p_playlist->i_size == 0 ) { wxMessageBox( wxU(_("Playlist is empty") ), wxU(_("Can't save")), wxICON_WARNING | wxOK, this ); return; } 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 ) { if( dialog.GetPath().mb_str(wxConvUTF8) ) { playlist_Export( p_playlist, dialog.GetPath().mb_str(wxConvUTF8), formats[dialog.GetFilterIndex()].psz_module ); } }}void Playlist::OnOpen( wxCommandEvent& WXUNUSED(event) ){ wxFileDialog dialog( this, wxU(_("Open playlist")), wxT(""), wxT(""), wxT("All playlists|" EXTENSIONS_PLAYLIST "|XSPF playlist|*.xspf|M3U files|*.m3u"), wxOPEN ); if( dialog.ShowModal() == wxID_OK ) { playlist_Import( p_playlist, dialog.GetPath().mb_str(wxConvUTF8) ); }}void Playlist::OnAddFile( wxCommandEvent& WXUNUSED(event) ){ p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_FILE_SIMPLE, 0, 0 );}void Playlist::OnAddDir( wxCommandEvent& WXUNUSED(event) ){ p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_DIRECTORY, 0, 0 );}void Playlist::OnAddMRL( wxCommandEvent& WXUNUSED(event) ){ p_intf->p_sys->pf_show_dialog( p_intf, INTF_DIALOG_FILE, 0, 0 );}/******************************************************************** * Sorting functions ********************************************************************/void Playlist::OnSort( wxCommandEvent& event ){ PlaylistItem *p_wxitem; p_wxitem = (PlaylistItem *)treectrl->GetItemData( treectrl->GetRootItem() ); LockPlaylist( p_intf->p_sys, p_playlist ); switch( event.GetId() ) { case SortTitle_Event: playlist_RecursiveNodeSort( p_playlist, playlist_ItemGetById( p_playlist, p_wxitem->i_id ), SORT_TITLE_NODES_FIRST, ORDER_NORMAL ); break; case RSortTitle_Event: playlist_RecursiveNodeSort( p_playlist, playlist_ItemGetById( p_playlist, p_wxitem->i_id ), SORT_TITLE_NODES_FIRST, ORDER_REVERSE ); } UnlockPlaylist( p_intf->p_sys, p_playlist ); Rebuild( VLC_TRUE );}/********************************************************************** * Search functions (user) **********************************************************************//*void Playlist::OnSearchTextChange( wxCommandEvent& WXUNUSED(event) ){ search_button->SetDefault();}*/void Playlist::OnSearch( wxCommandEvent& WXUNUSED(event) ){ wxString search_string = search_text->GetValue(); vlc_bool_t pb_found = VLC_FALSE; wxTreeItemId found = FindItemByName( treectrl->GetRootItem(), search_string, search_current, &pb_found ); if( !found.IsOk() ) { wxTreeItemId dummy; search_current = dummy; found = FindItemByName( treectrl->GetRootItem(), search_string, search_current, &pb_found ); } if( found.IsOk() ) { search_current = found; treectrl->EnsureVisible( found ); treectrl->UnselectAll(); treectrl->SelectItem( found, true ); }}/********************************************************************** * Selection functions **********************************************************************/void Playlist::RecursiveDeleteSelection( wxTreeItemId root ){ wxTreeItemIdValue cookie; wxTreeItemId child = treectrl->GetFirstChild( root, cookie ); wxTreeItemId nextchild; bool childIsSelected = FALSE; bool nextchildIsSelected = FALSE; if( child.IsOk() ) childIsSelected = treectrl->IsSelected( child ); while( child.IsOk() ) { nextchild = treectrl->GetNextChild( root, cookie ); if( nextchild.IsOk() ) nextchildIsSelected = treectrl->IsSelected( nextchild ); if( childIsSelected ) DeleteTreeItem( child ); else if( treectrl->ItemHasChildren( child ) ) RecursiveDeleteSelection( child ); child = nextchild; childIsSelected = nextchildIsSelected; }}void Playlist::OnDeleteSelection( wxCommandEvent& WXUNUSED(event) ){ RecursiveDeleteSelection( treectrl->GetRootItem() );}/********************************************************************** * Playlist mode functions **********************************************************************/void Playlist::OnRandom( wxCommandEvent& event ){ vlc_value_t val; val.b_bool = event.IsChecked(); var_Set( p_playlist, "random", val);}void Playlist::OnLoop( wxCommandEvent& event ){ vlc_value_t val; val.b_bool = event.IsChecked(); var_Set( p_playlist, "loop", val);}void Playlist::OnRepeat( wxCommandEvent& event ){ vlc_value_t val; val.b_bool = event.IsChecked(); var_Set( p_playlist, "repeat", val);}/******************************************************************** * Event ********************************************************************/void Playlist::OnActivateItem( wxTreeEvent& event ){ playlist_item_t *p_item,*p_node,*p_item2,*p_node2; PlaylistItem *p_wxitem = (PlaylistItem *)treectrl->GetItemData( event.GetItem() ); wxTreeItemId parent = treectrl->GetItemParent( event.GetItem() ); PlaylistItem *p_wxparent = (PlaylistItem *)treectrl->GetItemData( parent ); LockPlaylist( p_intf->p_sys, p_playlist ); if( !( p_wxitem && p_wxparent ) ) { UnlockPlaylist( p_intf->p_sys, p_playlist ); return; } p_item2 = playlist_ItemGetById(p_playlist, p_wxitem->i_id); p_node2 = playlist_ItemGetById(p_playlist, p_wxparent->i_id); if( p_item2 && p_item2->i_children == -1 ) { p_node = p_node2; p_item = p_item2; } else { p_node = p_item2; p_item = NULL;/* if( p_node && p_node->i_children > 0 && p_node->pp_children[0]->i_children == -1) { p_item = p_node->pp_children[0]; } else { p_item = NULL; }*/ } playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, i_current_view, p_node, p_item ); UnlockPlaylist( p_intf->p_sys, p_playlist );}void Playlist::OnKeyDown( wxTreeEvent& event ){ long keycode = event.GetKeyCode(); /* Delete selected items */ if( keycode == WXK_BACK || keycode == WXK_DELETE || keycode == WXK_NUMPAD_DELETE ) { /* We send a dummy event */ OnDeleteSelection( event ); } /* Work around wxWin32 bug */ else if( keycode == WXK_RETURN ) { wxArrayTreeItemIds items; if( treectrl->GetSelections( items ) > 0 ) { wxTreeEvent event; event.SetItem( items.Item( 0 ) ); OnActivateItem( event ); } } else { event.Skip(); }}void Playlist::OnEnDis( wxCommandEvent& event ){ msg_Warn( p_intf, "not implemented" );}void Playlist::OnDragItemBegin( wxTreeEvent& event ){ event.Allow(); draged_tree_item = event.GetItem();}void Playlist::OnDragItemEnd( wxTreeEvent& event ){ wxTreeItemId dest_tree_item = event.GetItem(); if( !dest_tree_item.IsOk() ) return; /* check that we're not trying to move a node into one of it's children */ wxTreeItemId parent = dest_tree_item; while( parent != treectrl->GetRootItem() ) { if( draged_tree_item == parent ) return; parent = treectrl->GetItemParent( parent ); } LockPlaylist( p_intf->p_sys, p_playlist ); PlaylistItem *p_wxdrageditem = (PlaylistItem *)treectrl->GetItemData( draged_tree_item ); PlaylistItem *p_wxdestitem = (PlaylistItem *)treectrl->GetItemData( dest_tree_item ); if( !p_wxdrageditem || !p_wxdestitem ) { UnlockPlaylist( p_intf->p_sys, p_playlist ); return; } playlist_item_t *p_drageditem = playlist_ItemGetById(p_playlist, p_wxdrageditem->i_id ); playlist_item_t *p_destitem = playlist_ItemGetById(p_playlist, p_wxdestitem->i_id ); if( !p_drageditem || !p_destitem ) { UnlockPlaylist( p_intf->p_sys, p_playlist ); return; } if( p_destitem->i_children == -1 ) /* this is a leaf */ { parent = treectrl->GetItemParent( dest_tree_item ); PlaylistItem *p_parent = (PlaylistItem *)treectrl->GetItemData( parent ); if( !p_parent ) { UnlockPlaylist( p_intf->p_sys, p_playlist ); return; } playlist_item_t *p_destitem2 = playlist_ItemGetById( p_playlist, p_parent->i_id ); if( !p_destitem2 ) { UnlockPlaylist( p_intf->p_sys, p_playlist ); return; } int i; for( i = 0; i < p_destitem2->i_children; i++ ) { if( p_destitem2->pp_children[i] == p_destitem ) break; } playlist_TreeMove( p_playlist, p_drageditem, p_destitem2, i, i_current_view ); } else /* this is a node */ { playlist_TreeMove( p_playlist, p_drageditem, p_destitem, 0, i_current_view ); } UnlockPlaylist( p_intf->p_sys, p_playlist ); /* FIXME: having this Rebuild() is dirty */ Rebuild( VLC_TRUE );}#if wxUSE_DRAG_AND_DROPPlaylistFileDropTarget::PlaylistFileDropTarget( Playlist *p ):p( p ){}/******************************************************************** * File Drag And Drop handling ********************************************************************/bool PlaylistFileDropTarget::OnDropFiles( wxCoord x, wxCoord y, const wxArrayString& filenames ){ int i_pos = 0; playlist_item_t *p_dest; LockPlaylist( p->p_intf->p_sys, p->p_playlist ); /* find the destination node and position in that node */ const wxPoint pt( x, y ); wxTreeItemId item = p->treectrl->HitTest( pt ); if( !item.IsOk() ) { /* We were droped below the last item so we append to the * general node */ p_dest = p->p_playlist->p_general; i_pos = PLAYLIST_END; } else { PlaylistItem *p_plitem = (PlaylistItem *)p->treectrl->GetItemData( item ); p_dest = playlist_ItemGetById( p->p_playlist, p_plitem->i_id ); if( p_dest->i_children == -1 ) { /* This is a leaf. Append right after it * We thus need to find the parrent node and the position of the * leaf in it's children list */ wxTreeItemId parent = p->treectrl->GetItemParent( item ); PlaylistItem *p_parent = (PlaylistItem *)p->treectrl->GetItemData( parent ); if( !p_parent ) { UnlockPlaylist( p->p_intf->p_sys, p->p_playlist ); return FALSE; } playlist_item_t *p_node = playlist_ItemGetById( p->p_playlist, p_parent->i_id ); if( !p_node ) { UnlockPlaylist( p->p_intf->p_sys, p->p_playlist ); return FALSE; } for( i_pos = 0; i_pos < p_node->i_children; i_pos++ ) { if( p_node->pp_children[i_pos] == p_dest ) break; } p_dest = p_node; } } UnlockPlaylist( p->p_intf->p_sys, p->p_playlist ); /* Put the items in the playlist node */ for( size_t i = 0; i < filenames.GetCount(); i++ ) { char *psz_utf8 = wxDnDFromLocale( filenames[i] ); playlist_item_t *p_item = playlist_ItemNew( p->p_playlist, psz_utf8, psz_utf8 ); playlist_NodeAddItem( p->p_playlist, p_item, p->i_current_view,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -