X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fgui%2Fwxwidgets%2Fdialogs%2Fplaylist.cpp;h=9ca6fc98ff4a4cf1cc62e92e66a56a2cd23cddf5;hb=7ca4e3eb624251feb1f97cfc25104cce473e04a0;hp=80164094a3499b3e7529f64744d9016bd2141ccb;hpb=7cf5fbe82cc18155433046cde85e01cf218e17cd;p=vlc diff --git a/modules/gui/wxwidgets/dialogs/playlist.cpp b/modules/gui/wxwidgets/dialogs/playlist.cpp index 80164094a3..9ca6fc98ff 100644 --- a/modules/gui/wxwidgets/dialogs/playlist.cpp +++ b/modules/gui/wxwidgets/dialogs/playlist.cpp @@ -215,10 +215,9 @@ Playlist::Playlist( intf_thread_t *_p_intf, wxWindow *p_parent ): pp_sds = NULL; i_update_counter = 0; i_sort_mode = MODE_NONE; - b_need_update = VLC_FALSE; + b_need_update = false; i_items_to_append = 0; - p_playlist = (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, - FIND_ANYWHERE ); + p_playlist = pl_Yield( p_intf ); if( p_playlist == NULL ) return; SetIcon( *p_intf->p_sys->p_icon ); @@ -226,9 +225,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; @@ -367,8 +365,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,13 +404,18 @@ Playlist::Playlist( intf_thread_t *_p_intf, wxWindow *p_parent ): var_AddCallback( p_playlist, "item-deleted", ItemDeleted, this ); /* Update the playlist */ - Rebuild( VLC_TRUE ); - + p_current_treeroot = p_playlist->p_local_category; + Rebuild( true ); } Playlist::~Playlist() { - if( pp_sds != NULL ) free( pp_sds ); + if( pp_sds != NULL ) + { + char **pp_sd = pp_sds; + for( ; *pp_sd; pp_sd++ ) free( *pp_sd ); + free( pp_sds ); + } if( p_playlist == NULL ) return; @@ -505,7 +506,7 @@ void Playlist::UpdateTreeItem( wxTreeItemId item ) if( !p_data ) return; playlist_item_t *p_item = playlist_ItemGetById( p_playlist, - ((PlaylistItem *)p_data)->i_id, VLC_TRUE ); + ((PlaylistItem *)p_data)->i_id, true ); if( !p_item ) { UnlockPlaylist( p_intf->p_sys, p_playlist ); @@ -515,18 +516,11 @@ void Playlist::UpdateTreeItem( wxTreeItemId item ) wxString msg; wxString duration = wxU( "" ); - char *psz_artist; - if( p_item->p_input->p_meta ) - { - psz_artist= p_item->p_input->p_meta->psz_artist ? - strdup( p_item->p_input->p_meta->psz_artist ) : - strdup(""); - } - else - psz_artist = strdup( "" ); + char *psz_artist = input_item_GetArtist( p_item->p_input ); + char *psz_name = input_item_GetName( p_item->p_input ); char psz_duration[MSTRTIME_MAX_SIZE]; - mtime_t dur = p_item->p_input->i_duration; + mtime_t dur = input_item_GetDuration( p_item->p_input ); if( dur != -1 ) { @@ -535,16 +529,17 @@ void Playlist::UpdateTreeItem( wxTreeItemId item ) wxU( " )" ) ); } - if( !strcmp( psz_artist, "" ) || p_item->p_input->b_fixed_name == VLC_TRUE ) + if( !psz_artist || !strcmp( psz_artist, "" ) || p_item->p_input->b_fixed_name == true ) { - msg = wxString( wxU( p_item->p_input->psz_name ) ) + duration; + msg = wxString( wxU( psz_name ) ) + duration; } else { msg = wxString(wxU( psz_artist )) + wxT(" - ") + - wxString(wxU(p_item->p_input->psz_name)) + duration; + wxString(wxU(psz_name)) + duration; } free( psz_artist ); + free( psz_name ); treectrl->SetItemText( item , msg ); treectrl->SetItemImage( item, p_item->p_input->i_type ); @@ -581,7 +576,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, VLC_TRUE ); + p_item = playlist_ItemGetById( p_playlist, p_add->i_item, true ); if( !p_item ) goto update; if( (p_item->i_flags & PLAYLIST_DBL_FLAG ) ) goto update; @@ -744,7 +739,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, VLC_TRUE ); + p_item = playlist_ItemGetById( p_playlist, ((PlaylistItem *)treectrl->GetItemData( item ))->i_id, true ); if( p_item && p_item->i_children == -1 ) count++; UnlockPlaylist( p_intf->p_sys, p_playlist ); @@ -755,7 +750,7 @@ int Playlist::CountItems( wxTreeItemId root ) } /* Find a wxItem from a name (from current) */ -wxTreeItemId Playlist::FindItemByName( wxTreeItemId root, wxString search_string, wxTreeItemId current, vlc_bool_t *pb_current_found ) +wxTreeItemId Playlist::FindItemByName( wxTreeItemId root, wxString search_string, wxTreeItemId current, bool *pb_current_found ) { wxTreeItemIdValue cookie; wxTreeItemId search; @@ -767,13 +762,13 @@ wxTreeItemId Playlist::FindItemByName( wxTreeItemId root, wxString search_string if( treectrl->GetItemText( item).Lower().Contains( search_string.Lower() ) ) { - if( !current.IsOk() || *pb_current_found == VLC_TRUE ) + if( !current.IsOk() || *pb_current_found == true ) { return item; } else if( current.IsOk() && item == current ) { - *pb_current_found = VLC_TRUE; + *pb_current_found = true; } } if( treectrl->ItemHasChildren( item ) ) @@ -795,23 +790,12 @@ wxTreeItemId Playlist::FindItemByName( wxTreeItemId root, wxString search_string /********************************************************************** * Rebuild the playlist **********************************************************************/ -void Playlist::Rebuild( vlc_bool_t b_root ) +void Playlist::Rebuild( bool 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 +818,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,22 +825,12 @@ 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 ) { - if( show ) Rebuild( VLC_TRUE ); + if( show ) Rebuild( true ); Show( show ); } @@ -872,8 +844,8 @@ void Playlist::UpdatePlaylist() if( this->b_need_update ) { - this->b_need_update = VLC_FALSE; - Rebuild( VLC_TRUE ); + this->b_need_update = false; + Rebuild( true ); } /* Updating the playing status every 0.5s is enough */ @@ -890,7 +862,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, VLC_TRUE ); + p_item = playlist_ItemGetById( p_playlist, p_wxitem->i_id, true ); if( !p_item ) { @@ -907,12 +879,12 @@ void Playlist::DeleteTreeItem( wxTreeItemId item ) void Playlist::DeleteItem( int item_id ) { - playlist_DeleteFromInput( p_playlist, item_id, VLC_TRUE ); + playlist_DeleteFromInput( p_playlist, item_id, true ); } void Playlist::DeleteNode( playlist_item_t *p_item ) { - playlist_NodeDelete( p_playlist, p_item, VLC_TRUE , VLC_FALSE ); + playlist_NodeDelete( p_playlist, p_item, true , false ); } void Playlist::OnMenuClose( wxCommandEvent& event ) @@ -1014,18 +986,18 @@ void Playlist::OnSort( wxCommandEvent& event ) case SortTitle_Event: playlist_RecursiveNodeSort( p_playlist, playlist_ItemGetById( p_playlist, p_wxitem->i_id, - VLC_TRUE ), + true ), SORT_TITLE_NODES_FIRST, ORDER_NORMAL ); break; case RSortTitle_Event: playlist_RecursiveNodeSort( p_playlist, playlist_ItemGetById( p_playlist, p_wxitem->i_id, - VLC_TRUE ), + true ), SORT_TITLE_NODES_FIRST, ORDER_REVERSE ); } UnlockPlaylist( p_intf->p_sys, p_playlist ); - Rebuild( VLC_TRUE ); + Rebuild( true ); } /********************************************************************** @@ -1042,12 +1014,12 @@ void Playlist::OnSearch( wxCommandEvent& WXUNUSED(event) ) PlaylistItem *p_wxroot; p_wxroot = (PlaylistItem *)treectrl->GetItemData( treectrl->GetRootItem() ); playlist_item_t *p_root = playlist_ItemGetById( p_playlist, p_wxroot->i_id, - VLC_TRUE ); + true ); assert( p_root ); char *psz_name = wxFromLocale( search_string ); playlist_LiveSearchUpdate( p_playlist, p_root, psz_name ); - Rebuild( VLC_TRUE ); + Rebuild( true ); wxLocaleFree( psz_name ); } @@ -1125,7 +1097,7 @@ void Playlist::OnActivateItem( wxTreeEvent& event ) UnlockPlaylist( p_intf->p_sys, p_playlist ); return; } - p_item = playlist_ItemGetById( p_playlist, p_wxitem->i_id, VLC_TRUE ); + p_item = playlist_ItemGetById( p_playlist, p_wxitem->i_id, true ); p_parent = p_item; while( p_parent ) @@ -1137,7 +1109,7 @@ void Playlist::OnActivateItem( wxTreeEvent& event ) if( p_parent ) { - playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, VLC_TRUE, p_parent, p_item ); + playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, true, p_parent, p_item ); } UnlockPlaylist( p_intf->p_sys, p_playlist ); } @@ -1146,7 +1118,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 ); @@ -1201,9 +1173,9 @@ void Playlist::OnDragItemEnd( wxTreeEvent& event ) } playlist_item_t *p_drageditem = - playlist_ItemGetById(p_playlist, p_wxdrageditem->i_id, VLC_TRUE ); + playlist_ItemGetById(p_playlist, p_wxdrageditem->i_id, true ); playlist_item_t *p_destitem = - playlist_ItemGetById(p_playlist, p_wxdestitem->i_id, VLC_TRUE ); + playlist_ItemGetById(p_playlist, p_wxdestitem->i_id, true ); if( !p_drageditem || !p_destitem ) { UnlockPlaylist( p_intf->p_sys, p_playlist ); @@ -1222,7 +1194,7 @@ void Playlist::OnDragItemEnd( wxTreeEvent& event ) return; } playlist_item_t *p_destitem2 = - playlist_ItemGetById( p_playlist, p_parent->i_id, VLC_TRUE ); + playlist_ItemGetById( p_playlist, p_parent->i_id, true ); if( !p_destitem2 ) { UnlockPlaylist( p_intf->p_sys, p_playlist ); @@ -1244,7 +1216,7 @@ void Playlist::OnDragItemEnd( wxTreeEvent& event ) UnlockPlaylist( p_intf->p_sys, p_playlist ); /* FIXME: having this Rebuild() is dirty */ - Rebuild( VLC_TRUE ); + Rebuild( true ); } #if wxUSE_DRAG_AND_DROP @@ -1277,7 +1249,7 @@ 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, VLC_TRUE ); + p_dest = playlist_ItemGetById( p->p_playlist, p_plitem->i_id, true ); if( p_dest->i_children == -1 ) { @@ -1293,7 +1265,7 @@ bool PlaylistFileDropTarget::OnDropFiles( wxCoord x, wxCoord y, return FALSE; } playlist_item_t *p_node = - playlist_ItemGetById( p->p_playlist, p_parent->i_id, VLC_TRUE ); + playlist_ItemGetById( p->p_playlist, p_parent->i_id, true ); if( !p_node ) { UnlockPlaylist( p->p_intf->p_sys, p->p_playlist ); @@ -1315,13 +1287,16 @@ bool PlaylistFileDropTarget::OnDropFiles( wxCoord x, wxCoord y, 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 ); + int i_ret = ( playlist_BothAddInput( p->p_playlist, p_input, p_dest, + PLAYLIST_PREPARSE, i_pos, NULL, NULL, pl_Unlocked ) != VLC_SUCCESS ); + vlc_gc_decref( p_input ); wxDnDLocaleFree( psz_utf8 ); + if( i_ret != VLC_SUCCESS ) + return FALSE; } /* FIXME: having this Rebuild() is dirty */ - p->Rebuild( VLC_TRUE ); + p->Rebuild( true ); return TRUE; } @@ -1431,47 +1406,28 @@ wxMenu *Playlist::SDMenu() { p_sd_menu = new wxMenu; - vlc_list_t *p_list = vlc_list_find( p_playlist, VLC_OBJECT_MODULE, - FIND_ANYWHERE ); + char **ppsz_longnames; + char **ppsz_names = services_discovery_GetServicesNames( p_playlist, + &ppsz_longnames ); + if( !ppsz_names ) + return p_sd_menu; - int i_number = 0; - for( int i_index = 0; i_index < p_list->i_count; i_index++ ) - { - module_t * p_parser = (module_t *)p_list->p_values[i_index].p_object ; + char **ppsz_name = ppsz_names, **ppsz_longname = ppsz_longnames; - if( !strcmp( p_parser->psz_capability, "services_discovery" ) ) - i_number++; - } - if( i_number ) pp_sds = (char **)calloc( i_number, sizeof(void *) ); + int i_number = 0; - i_number = 0; - for( int i_index = 0; i_index < p_list->i_count; i_index++ ) + for( ; *ppsz_name; ppsz_name++, ppsz_longname++ ) { - module_t * p_parser = (module_t *)p_list->p_values[i_index].p_object ; + p_sd_menu->AppendCheckItem( FirstSD_Event + i_number++ , + wxU( *ppsz_longname ) ); - if( !strcmp( p_parser->psz_capability, "services_discovery" ) ) - { - p_sd_menu->AppendCheckItem( FirstSD_Event + i_number , - wxU( p_parser->psz_longname ? p_parser->psz_longname : - (p_parser->psz_shortname ? - p_parser->psz_shortname : p_parser->psz_object_name) ) ); - - /* hack to handle submodules properly */ - int i = -1; - while( p_parser->pp_shortcuts[++i] != NULL ); - i--; - if( playlist_IsServicesDiscoveryLoaded( p_playlist, - i>=0?p_parser->pp_shortcuts[i] - :p_parser->psz_object_name ) ) - { - p_sd_menu->Check( FirstSD_Event + i_number, TRUE ); - } + if( playlist_IsServicesDiscoveryLoaded( p_playlist, *ppsz_name ) ) + p_sd_menu->Check( FirstSD_Event + i_number, TRUE ); - pp_sds[i_number++] = i>=0?p_parser->pp_shortcuts[i] - :p_parser->psz_object_name; - } + free( *ppsz_longname ); } - vlc_list_release( p_list ); + pp_sds = ppsz_names; + free( ppsz_longnames ); return p_sd_menu; } @@ -1496,7 +1452,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, VLC_TRUE ); + p_item = playlist_ItemGetById( p_playlist, i_popup_item, true ); if( !p_item ) { @@ -1522,7 +1478,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, VLC_TRUE ); + p_popup_item = playlist_ItemGetById( p_playlist, i_popup_item, true ); p_popup_parent = p_popup_item; while( p_popup_parent ) @@ -1534,7 +1490,7 @@ void Playlist::OnPopupPlay( wxCommandEvent& event ) if( p_popup_parent ) { - playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, VLC_TRUE, p_popup_parent, + playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, true, p_popup_parent, p_popup_item ); } UnlockPlaylist( p_intf->p_sys, p_playlist ); @@ -1549,7 +1505,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, VLC_TRUE ); + p_popup_item = playlist_ItemGetById( p_playlist, i_popup_item, true ); if( p_popup_item != NULL ) { @@ -1587,7 +1543,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, VLC_TRUE ); + p_item = playlist_ItemGetById( p_playlist, p_wxitem->i_id, true ); if( p_item->i_children >= 0 ) { playlist_RecursiveNodeSort( p_playlist, p_item, @@ -1606,7 +1562,7 @@ 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, - VLC_TRUE ); + true ); if( p_popup_item ) { iteminfo_dialog = new ItemInfoDialog( p_intf, p_popup_item, this ); @@ -1634,12 +1590,12 @@ void Playlist::OnPopupAddNode( wxCommandEvent& event ) p_wxitem = (PlaylistItem *)treectrl->GetItemData( i_wx_popup_item ); - p_item = playlist_ItemGetById( p_playlist, p_wxitem->i_id, VLC_TRUE ); + p_item = playlist_ItemGetById( p_playlist, p_wxitem->i_id, true ); - playlist_NodeCreate( p_playlist, psz_name, p_item ); + playlist_NodeCreate( p_playlist, psz_name, p_item, 0, NULL ); UnlockPlaylist( p_intf->p_sys, p_playlist ); - Rebuild( VLC_TRUE ); + Rebuild( true ); wxLocaleFree( psz_name ); } @@ -1648,12 +1604,12 @@ 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, - VLC_TRUE ); + true ); if( p_item ) p_current_treeroot = p_item; - Rebuild( VLC_TRUE ); + Rebuild( true ); } } @@ -1685,7 +1641,7 @@ static int PlaylistChanged( vlc_object_t *p_this, const char *psz_variable, vlc_value_t oval, vlc_value_t nval, void *param ) { Playlist *p_playlist_dialog = (Playlist *)param; - p_playlist_dialog->b_need_update = VLC_TRUE; + p_playlist_dialog->b_need_update = true; return VLC_SUCCESS; } @@ -1744,7 +1700,7 @@ static int ItemAppended( vlc_object_t *p_this, const char *psz_variable, { /* Too many items waiting to be added, it will be quicker to rebuild * the whole playlist */ - p_playlist_dialog->b_need_update = VLC_TRUE; + p_playlist_dialog->b_need_update = true; return VLC_SUCCESS; }