X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fgui%2Fwxwidgets%2Fdialogs%2Fplaylist.cpp;h=5d384caa35dee98fa7ac7f7f53426eaac9e82cc6;hb=38dbd37adf32cf04e1caf17ceb7888a4a5ec2f40;hp=3971ab19b31cdb396841cf3f74b35a243fd1bd30;hpb=8f973a0b05db90ef8f602ca8863563e0724e8581;p=vlc diff --git a/modules/gui/wxwidgets/dialogs/playlist.cpp b/modules/gui/wxwidgets/dialogs/playlist.cpp index 3971ab19b3..5d384caa35 100644 --- a/modules/gui/wxwidgets/dialogs/playlist.cpp +++ b/modules/gui/wxwidgets/dialogs/playlist.cpp @@ -47,7 +47,7 @@ #include #include -#include "charset.h" +#include "vlc_charset.h" #define HELP_SHUFFLE N_( "Shuffle" ) #define HELP_LOOP N_( "Repeat All" ) @@ -226,9 +226,8 @@ Playlist::Playlist( intf_thread_t *_p_intf, wxWindow *p_parent ): p_view_menu = NULL; p_sd_menu = SDMenu(); -// i_current_view = VIEW_ONELEVEL; - p_current_viewroot = p_playlist->p_root_onelevel; - p_current_treeroot = p_playlist->p_local_onelevel; + p_current_viewroot = p_playlist->p_root_category; + p_current_treeroot = NULL; i_title_sorted = 0; i_group_sorted = 0; @@ -339,9 +338,9 @@ Playlist::Playlist( intf_thread_t *_p_intf, wxWindow *p_parent ): toolbar->Realize(); /* Create teh source selector */ - source_sel = new wxListCtrl( playlist_panel, Source_Event, - wxDefaultPosition, wxDefaultSize, - wxLC_AUTOARRANGE|wxLC_SINGLE_SEL ); + source_sel = new wxListView( playlist_panel, Source_Event, + wxDefaultPosition, wxDefaultSize, + wxLC_AUTOARRANGE|wxLC_SINGLE_SEL ); /* Create the tree */ treectrl = new wxTreeCtrl( playlist_panel, TreeCtrl_Event, @@ -367,8 +366,6 @@ Playlist::Playlist( intf_thread_t *_p_intf, wxWindow *p_parent ): p_images->Add( wxIcon( type_node_xpm ) ); treectrl->AssignImageList( p_images ); - treectrl->AddRoot( wxU(_("root" )), -1, -1, NULL ); - /* Reduce font size */ wxFont font= treectrl->GetFont(); font.SetPointSize(9); @@ -408,8 +405,8 @@ Playlist::Playlist( intf_thread_t *_p_intf, wxWindow *p_parent ): var_AddCallback( p_playlist, "item-deleted", ItemDeleted, this ); /* Update the playlist */ + p_current_treeroot = p_playlist->p_local_category; Rebuild( VLC_TRUE ); - } Playlist::~Playlist() @@ -505,7 +502,7 @@ void Playlist::UpdateTreeItem( wxTreeItemId item ) if( !p_data ) return; playlist_item_t *p_item = playlist_ItemGetById( p_playlist, - ((PlaylistItem *)p_data)->i_id ); + ((PlaylistItem *)p_data)->i_id, VLC_TRUE ); if( !p_item ) { UnlockPlaylist( p_intf->p_sys, p_playlist ); @@ -515,15 +512,8 @@ void Playlist::UpdateTreeItem( wxTreeItemId item ) wxString msg; wxString duration = wxU( "" ); - char *psz_author; - if( p_item->p_input->p_meta ) - { - psz_author= p_item->p_input->p_meta->psz_artist ? - strdup( p_item->p_input->p_meta->psz_artist ) : - strdup(""); - } - else - psz_author = strdup( "" ); + char *psz_artist; + psz_artist = input_item_GetArtist( p_item->p_input ); char psz_duration[MSTRTIME_MAX_SIZE]; mtime_t dur = p_item->p_input->i_duration; @@ -535,16 +525,16 @@ void Playlist::UpdateTreeItem( wxTreeItemId item ) wxU( " )" ) ); } - if( !strcmp( psz_author, "" ) || p_item->p_input->b_fixed_name == VLC_TRUE ) + if( !strcmp( psz_artist, "" ) || p_item->p_input->b_fixed_name == VLC_TRUE ) { msg = wxString( wxU( p_item->p_input->psz_name ) ) + duration; } else { - msg = wxString(wxU( psz_author )) + wxT(" - ") + + msg = wxString(wxU( psz_artist )) + wxT(" - ") + wxString(wxU(p_item->p_input->psz_name)) + duration; } - free( psz_author ); + free( psz_artist ); treectrl->SetItemText( item , msg ); treectrl->SetItemImage( item, p_item->p_input->i_type ); @@ -581,7 +571,7 @@ void Playlist::AppendItem( wxCommandEvent& event ) node = FindItem( treectrl->GetRootItem(), p_add->i_node ); if( !node.IsOk() ) goto update; - p_item = playlist_ItemGetById( p_playlist, p_add->i_item ); + p_item = playlist_ItemGetById( p_playlist, p_add->i_item, VLC_TRUE ); if( !p_item ) goto update; if( (p_item->i_flags & PLAYLIST_DBL_FLAG ) ) goto update; @@ -744,7 +734,7 @@ int Playlist::CountItems( wxTreeItemId root ) { playlist_item_t *p_item; LockPlaylist( p_intf->p_sys, p_playlist ); - p_item = playlist_ItemGetById( p_playlist, ((PlaylistItem *)treectrl->GetItemData( item ))->i_id ); + p_item = playlist_ItemGetById( p_playlist, ((PlaylistItem *)treectrl->GetItemData( item ))->i_id, VLC_TRUE ); if( p_item && p_item->i_children == -1 ) count++; UnlockPlaylist( p_intf->p_sys, p_playlist ); @@ -799,19 +789,8 @@ void Playlist::Rebuild( vlc_bool_t b_root ) { i_items_to_append = 0; - /* We can remove the callbacks before locking, anyway, we won't - * miss anything */ - if( b_root ) - { - var_DelCallback( p_playlist, "item-change", ItemChanged, this ); - var_DelCallback( p_playlist, "playlist-current", PlaylistNext, this ); - var_DelCallback( p_playlist, "intf-change", PlaylistChanged, this ); - var_DelCallback( p_playlist, "item-append", ItemAppended, this ); - var_DelCallback( p_playlist, "item-deleted", ItemDeleted, this ); + LockPlaylist( p_intf->p_sys, p_playlist ); - /* ...and rebuild it */ - LockPlaylist( p_intf->p_sys, p_playlist ); - } /* Invalidate cache */ i_saved_id = -1; i_saved_input_id = -1; @@ -834,8 +813,6 @@ void Playlist::Rebuild( vlc_bool_t b_root ) new PlaylistItem( p_current_treeroot ) ); wxTreeItemId root = treectrl->GetRootItem(); - //UpdateNode( p_current_treeroot, root ); - //CreateNode( p_current_treeroot, root ); UpdateNodeChildren( p_current_treeroot, root ); int i_count = CountItems( treectrl->GetRootItem() ); @@ -843,17 +820,7 @@ void Playlist::Rebuild( vlc_bool_t b_root ) statusbar->SetStatusText( wxString::Format( wxU(_( "%i items in playlist")), i_count ), 0 ); - if( b_root ) - { - /* Put callbacks back online */ - var_AddCallback( p_playlist, "intf-change", PlaylistChanged, this ); - var_AddCallback( p_playlist, "playlist-current", PlaylistNext, this ); - var_AddCallback( p_playlist, "item-change", ItemChanged, this ); - var_AddCallback( p_playlist, "item-append", ItemAppended, this ); - var_AddCallback( p_playlist, "item-deleted", ItemDeleted, this ); - - UnlockPlaylist( p_intf->p_sys, p_playlist ); - } + UnlockPlaylist( p_intf->p_sys, p_playlist ); } void Playlist::ShowPlaylist( bool show ) @@ -890,7 +857,7 @@ void Playlist::DeleteTreeItem( wxTreeItemId item ) p_wxitem = (PlaylistItem *)treectrl->GetItemData( item ); LockPlaylist( p_intf->p_sys, p_playlist ); - p_item = playlist_ItemGetById( p_playlist, p_wxitem->i_id ); + p_item = playlist_ItemGetById( p_playlist, p_wxitem->i_id, VLC_TRUE ); if( !p_item ) { @@ -907,7 +874,7 @@ void Playlist::DeleteTreeItem( wxTreeItemId item ) void Playlist::DeleteItem( int item_id ) { - playlist_DeleteAllFromInput( p_playlist, item_id ); + playlist_DeleteFromInput( p_playlist, item_id, VLC_TRUE ); } void Playlist::DeleteNode( playlist_item_t *p_item ) @@ -932,13 +899,13 @@ void Playlist::OnSave( wxCommandEvent& WXUNUSED(event) ) char *psz_desc; char *psz_filter; char *psz_module; - } formats[] = {{ _("M3U file"), "*.m3u", "export-m3u" }, + } formats[] = {//{ _("M3U file"), "*.m3u", "export-m3u" }, { _("XSPF playlist"), "*.xspf", "export-xspf"} }; wxString filter = wxT(""); - if( p_playlist->i_size == 0 ) + if( playlist_IsEmpty( p_playlist ) ) { wxMessageBox( wxU(_("Playlist is empty") ), wxU(_("Can't save")), wxICON_WARNING | wxOK, this ); @@ -957,12 +924,15 @@ void Playlist::OnSave( wxCommandEvent& WXUNUSED(event) ) if( dialog.ShowModal() == wxID_OK ) { - if( dialog.GetPath().mb_str() ) + if( dialog.GetPath().mb_str(wxConvUTF8) ) { - abort(); -// playlist_Export( p_playlist, dialog.GetPath().mb_str(), -// /* ROOT */ -// formats[dialog.GetFilterIndex()].psz_module ); + /* what root should we export? */ + if( p_playlist->p_root_category->i_children > 0 ) + { + playlist_Export( p_playlist, dialog.GetPath().mb_str(wxConvUTF8), + p_playlist->p_root_category->pp_children[0], + formats[dialog.GetFilterIndex()].psz_module ); + } } } @@ -975,7 +945,7 @@ void Playlist::OnOpen( wxCommandEvent& WXUNUSED(event) ) if( dialog.ShowModal() == wxID_OK ) { - playlist_Import( p_playlist, dialog.GetPath().mb_str() ); + playlist_Import( p_playlist, dialog.GetPath().mb_str(wxConvUTF8) ); } } @@ -1010,12 +980,14 @@ void Playlist::OnSort( wxCommandEvent& event ) { case SortTitle_Event: playlist_RecursiveNodeSort( p_playlist, - playlist_ItemGetById( p_playlist, p_wxitem->i_id ), + playlist_ItemGetById( p_playlist, p_wxitem->i_id, + VLC_TRUE ), SORT_TITLE_NODES_FIRST, ORDER_NORMAL ); break; case RSortTitle_Event: playlist_RecursiveNodeSort( p_playlist, - playlist_ItemGetById( p_playlist, p_wxitem->i_id ), + playlist_ItemGetById( p_playlist, p_wxitem->i_id, + VLC_TRUE ), SORT_TITLE_NODES_FIRST, ORDER_REVERSE ); } UnlockPlaylist( p_intf->p_sys, p_playlist ); @@ -1036,7 +1008,8 @@ void Playlist::OnSearch( wxCommandEvent& WXUNUSED(event) ) wxString search_string = search_text->GetValue(); PlaylistItem *p_wxroot; p_wxroot = (PlaylistItem *)treectrl->GetItemData( treectrl->GetRootItem() ); - playlist_item_t *p_root = playlist_ItemGetById( p_playlist, p_wxroot->i_id ); + playlist_item_t *p_root = playlist_ItemGetById( p_playlist, p_wxroot->i_id, + VLC_TRUE ); assert( p_root ); char *psz_name = wxFromLocale( search_string ); @@ -1053,16 +1026,23 @@ 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() ) { - if( treectrl->ItemHasChildren( child ) ) - { - RecursiveDeleteSelection( child ); - if( treectrl->IsSelected(child ) ) DeleteTreeItem( child ); - } - else if( treectrl->IsSelected( child ) ) + nextchild = treectrl->GetNextChild( root, cookie ); + if( nextchild.IsOk() ) + nextchildIsSelected = treectrl->IsSelected( nextchild ); + if( childIsSelected ) DeleteTreeItem( child ); - child = treectrl->GetNextChild( root, cookie ); + else if( treectrl->ItemHasChildren( child ) ) + RecursiveDeleteSelection( child ); + child = nextchild; + childIsSelected = nextchildIsSelected; } } @@ -1112,7 +1092,7 @@ void Playlist::OnActivateItem( wxTreeEvent& event ) UnlockPlaylist( p_intf->p_sys, p_playlist ); return; } - p_item = playlist_ItemGetById( p_playlist, p_wxitem->i_id ); + p_item = playlist_ItemGetById( p_playlist, p_wxitem->i_id, VLC_TRUE ); p_parent = p_item; while( p_parent ) @@ -1124,7 +1104,7 @@ void Playlist::OnActivateItem( wxTreeEvent& event ) if( p_parent ) { - playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, p_parent, p_item ); + playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, VLC_TRUE, p_parent, p_item ); } UnlockPlaylist( p_intf->p_sys, p_playlist ); } @@ -1133,7 +1113,7 @@ void Playlist::OnKeyDown( wxTreeEvent& event ) { long keycode = event.GetKeyCode(); /* Delete selected items */ - if( keycode == WXK_BACK || keycode == WXK_DELETE ) + if( keycode == WXK_BACK || keycode == WXK_DELETE || keycode == WXK_NUMPAD_DELETE ) { /* We send a dummy event */ OnDeleteSelection( event ); @@ -1167,7 +1147,7 @@ void Playlist::OnDragItemEnd( wxTreeEvent& event ) if( !dest_tree_item.IsOk() ) return; - /* check that we're not trying to move a node into one of it's children */ + /* check that we're not trying to move a node into one of its children */ wxTreeItemId parent = dest_tree_item; while( parent != treectrl->GetRootItem() ) { @@ -1188,9 +1168,9 @@ void Playlist::OnDragItemEnd( wxTreeEvent& event ) } playlist_item_t *p_drageditem = - playlist_ItemGetById(p_playlist, p_wxdrageditem->i_id ); + playlist_ItemGetById(p_playlist, p_wxdrageditem->i_id, VLC_TRUE ); playlist_item_t *p_destitem = - playlist_ItemGetById(p_playlist, p_wxdestitem->i_id ); + playlist_ItemGetById(p_playlist, p_wxdestitem->i_id, VLC_TRUE ); if( !p_drageditem || !p_destitem ) { UnlockPlaylist( p_intf->p_sys, p_playlist ); @@ -1209,7 +1189,7 @@ void Playlist::OnDragItemEnd( wxTreeEvent& event ) return; } playlist_item_t *p_destitem2 = - playlist_ItemGetById( p_playlist, p_parent->i_id ); + playlist_ItemGetById( p_playlist, p_parent->i_id, VLC_TRUE ); if( !p_destitem2 ) { UnlockPlaylist( p_intf->p_sys, p_playlist ); @@ -1264,13 +1244,13 @@ bool PlaylistFileDropTarget::OnDropFiles( wxCoord x, wxCoord y, { PlaylistItem *p_plitem = (PlaylistItem *)p->treectrl->GetItemData( item ); - p_dest = playlist_ItemGetById( p->p_playlist, p_plitem->i_id ); + p_dest = playlist_ItemGetById( p->p_playlist, p_plitem->i_id, VLC_TRUE ); 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 */ + * leaf in its children list */ wxTreeItemId parent = p->treectrl->GetItemParent( item ); PlaylistItem *p_parent = (PlaylistItem *)p->treectrl->GetItemData( parent ); @@ -1280,7 +1260,7 @@ bool PlaylistFileDropTarget::OnDropFiles( wxCoord x, wxCoord y, return FALSE; } playlist_item_t *p_node = - playlist_ItemGetById( p->p_playlist, p_parent->i_id ); + playlist_ItemGetById( p->p_playlist, p_parent->i_id, VLC_TRUE ); if( !p_node ) { UnlockPlaylist( p->p_intf->p_sys, p->p_playlist ); @@ -1299,11 +1279,11 @@ bool PlaylistFileDropTarget::OnDropFiles( wxCoord x, wxCoord y, /* Put the items in the playlist node */ for( size_t i = 0; i < filenames.GetCount(); i++ ) { - const char *psz_utf8 = wxDnDFromLocale( filenames[i] ); + char *psz_utf8 = wxDnDFromLocale( filenames[i] ); input_item_t *p_input = input_ItemNew( p->p_playlist, psz_utf8, psz_utf8 ); playlist_NodeAddInput( p->p_playlist, p_input, - p_dest, PLAYLIST_PREPARSE, i_pos ); + p_dest, PLAYLIST_PREPARSE, i_pos, VLC_FALSE ); wxDnDLocaleFree( psz_utf8 ); } @@ -1429,7 +1409,7 @@ wxMenu *Playlist::SDMenu() if( !strcmp( p_parser->psz_capability, "services_discovery" ) ) i_number++; } - if( i_number ) pp_sds = (char **)calloc( i_number, sizeof(void *) ); + if( i_number ) pp_sds = (const char **)calloc( i_number, sizeof(void *) ); i_number = 0; for( int i_index = 0; i_index < p_list->i_count; i_index++ ) @@ -1483,7 +1463,7 @@ void Playlist::OnPopup( wxContextMenuEvent& event ) treectrl->SelectItem( i_wx_popup_item ); LockPlaylist( p_intf->p_sys, p_playlist ); - p_item = playlist_ItemGetById( p_playlist, i_popup_item ); + p_item = playlist_ItemGetById( p_playlist, i_popup_item, VLC_TRUE ); if( !p_item ) { @@ -1509,7 +1489,7 @@ void Playlist::OnPopupPlay( wxCommandEvent& event ) { playlist_item_t *p_popup_item, *p_popup_parent; LockPlaylist( p_intf->p_sys, p_playlist ); - p_popup_item = playlist_ItemGetById( p_playlist, i_popup_item ); + p_popup_item = playlist_ItemGetById( p_playlist, i_popup_item, VLC_TRUE ); p_popup_parent = p_popup_item; while( p_popup_parent ) @@ -1521,7 +1501,7 @@ void Playlist::OnPopupPlay( wxCommandEvent& event ) if( p_popup_parent ) { - playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, p_popup_parent, + playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, VLC_TRUE, p_popup_parent, p_popup_item ); } UnlockPlaylist( p_intf->p_sys, p_playlist ); @@ -1536,7 +1516,7 @@ void Playlist::Preparse() { playlist_item_t *p_popup_item; LockPlaylist( p_intf->p_sys, p_playlist ); - p_popup_item = playlist_ItemGetById( p_playlist, i_popup_item ); + p_popup_item = playlist_ItemGetById( p_playlist, i_popup_item, VLC_TRUE ); if( p_popup_item != NULL ) { @@ -1574,7 +1554,7 @@ void Playlist::OnPopupSort( wxCommandEvent& event ) p_wxitem = (PlaylistItem *)treectrl->GetItemData( i_wx_popup_item ); LockPlaylist( p_intf->p_sys, p_playlist ); - p_item = playlist_ItemGetById( p_playlist, p_wxitem->i_id ); + p_item = playlist_ItemGetById( p_playlist, p_wxitem->i_id, VLC_TRUE ); if( p_item->i_children >= 0 ) { playlist_RecursiveNodeSort( p_playlist, p_item, @@ -1591,7 +1571,9 @@ void Playlist::OnPopupSort( wxCommandEvent& event ) void Playlist::OnPopupInfo( wxCommandEvent& event ) { LockPlaylist( p_intf->p_sys, p_playlist ); - playlist_item_t *p_popup_item = playlist_ItemGetById( p_playlist, i_popup_item ); + playlist_item_t *p_popup_item = playlist_ItemGetById( p_playlist, + i_popup_item, + VLC_TRUE ); if( p_popup_item ) { iteminfo_dialog = new ItemInfoDialog( p_intf, p_popup_item, this ); @@ -1619,9 +1601,9 @@ void Playlist::OnPopupAddNode( wxCommandEvent& event ) p_wxitem = (PlaylistItem *)treectrl->GetItemData( i_wx_popup_item ); - p_item = playlist_ItemGetById( p_playlist, p_wxitem->i_id ); + p_item = playlist_ItemGetById( p_playlist, p_wxitem->i_id, VLC_TRUE ); - playlist_NodeCreate( p_playlist, psz_name, p_item ); + playlist_NodeCreate( p_playlist, psz_name, p_item, 0 ); UnlockPlaylist( p_intf->p_sys, p_playlist ); Rebuild( VLC_TRUE ); @@ -1633,9 +1615,10 @@ void Playlist::OnSourceSelected( wxListEvent &event ) { int i_id = event.GetData(); - if( p_current_treeroot && i_id != p_current_treeroot->i_id ) + if( !p_current_treeroot || i_id != p_current_treeroot->i_id ) { - playlist_item_t *p_item = playlist_ItemGetById( p_playlist, i_id ); + playlist_item_t *p_item = playlist_ItemGetById( p_playlist, i_id, + VLC_TRUE ); if( p_item ) p_current_treeroot = p_item; Rebuild( VLC_TRUE ); } @@ -1649,16 +1632,12 @@ void Playlist::OnPlaylistEvent( wxCommandEvent& event ) switch( event.GetId() ) { case UpdateItem_Event: - fprintf( stderr,"Update input item id %i\n", event.GetInt() ); UpdateItem( event.GetInt() ); break; case AppendItem_Event: - fprintf( stderr,"Append item id %i\n", - ((playlist_add_t*)event.GetClientData())->i_item ); AppendItem( event ); break; case RemoveItem_Event: - fprintf( stderr,"Remove item id %i\n", event.GetInt() ); RemoveItem( event.GetInt() ); break; }