Commit 8b3d3c15 authored by zorglub's avatar zorglub

* wx : simplify some code, remove some useless duplications

       hopefully prevent deadlocks

* API : add the b_force parameter to playlist_NodeDelete. If TRUE, nodes that are marked as read-only will also be deleted. Use with care.

* SAP/DAAP : Ensure that the  node gets removed on quit
* HAL : Remove the node on quit and fix f**age of the Close function
parent e23ba242
......@@ -288,7 +288,7 @@ VLC_EXPORT( int, playlist_NodeInsert, (playlist_t *,int,playlist_item_t*,playlis
VLC_EXPORT( int, playlist_NodeRemoveItem, (playlist_t *,playlist_item_t*,playlist_item_t *) );
VLC_EXPORT( int, playlist_NodeChildrenCount, (playlist_t *,playlist_item_t* ) );
VLC_EXPORT( playlist_item_t *, playlist_ChildSearchName, (playlist_item_t*, const char* ) );
VLC_EXPORT( int, playlist_NodeDelete, ( playlist_t *, playlist_item_t *, vlc_bool_t ) );
VLC_EXPORT( int, playlist_NodeDelete, ( playlist_t *, playlist_item_t *, vlc_bool_t , vlc_bool_t ) );
VLC_EXPORT( int, playlist_NodeEmpty, ( playlist_t *, playlist_item_t *, vlc_bool_t ) );
/* Tree walking */
......
......@@ -490,7 +490,7 @@ belongs to an Apple hidden private API, and then can "disapear" at any time*/
// if current item is in selected node and is playing then stop playlist
playlist_Stop( p_playlist );
}
playlist_NodeDelete( p_playlist, p_item, VLC_TRUE);
playlist_NodeDelete( p_playlist, p_item, VLC_TRUE, VLC_FALSE );
}
else
{
......
......@@ -379,8 +379,6 @@ Playlist::Playlist( intf_thread_t *_p_intf, wxWindow *p_parent ):
p_saved_item = NULL;
/* Update the playlist */
Rebuild();
/* We want to be noticed of playlist changes */
......@@ -396,9 +394,10 @@ Playlist::Playlist( intf_thread_t *_p_intf, wxWindow *p_parent ):
var_AddCallback( p_playlist, "item-append", ItemAppended, this );
var_AddCallback( p_playlist, "item-deleted", ItemDeleted, this );
vlc_object_release( p_playlist );
/* Update the playlist */
Rebuild();
vlc_object_release( p_playlist );
}
Playlist::~Playlist()
......@@ -484,9 +483,6 @@ void Playlist::UpdateNodeChildren( playlist_t *p_playlist,
new PlaylistItem( p_node->pp_children[i]) );
UpdateTreeItem( p_playlist, item );
treectrl->SetItemImage( item,
p_node->pp_children[i]->input.i_type );
}
else
{
......@@ -496,19 +492,11 @@ void Playlist::UpdateNodeChildren( playlist_t *p_playlist,
}
}
/* Set current item */
void Playlist::SetCurrentItem( wxTreeItemId item )
{
if( item.IsOk() )
{
treectrl->SetItemBold( item, true );
treectrl->EnsureVisible( item );
}
}
/* Update an item in the tree */
void Playlist::UpdateTreeItem( playlist_t *p_playlist, wxTreeItemId item )
{
if( ! item.IsOk() ) return;
playlist_item_t *p_item =
((PlaylistItem *)treectrl->GetItemData( item ))->p_item;
......@@ -546,7 +534,8 @@ void Playlist::UpdateTreeItem( playlist_t *p_playlist, wxTreeItemId item )
if( p_playlist->status.p_item == p_item )
{
SetCurrentItem( item );
treectrl->SetItemBold( item, true );
treectrl->EnsureVisible( item );
}
else
{
......@@ -676,7 +665,7 @@ wxTreeItemId Playlist::FindItem( wxTreeItemId root, playlist_item_t *p_item )
p_wxcurrent = (PlaylistItem *)treectrl->GetItemData( root );
if( !p_item )
if( !p_item || !p_wxcurrent )
{
wxTreeItemId dummy;
return dummy;
......@@ -833,6 +822,15 @@ void Playlist::Rebuild()
{
return;
}
/* We can remove the callbacks before locking, anyway, we won't
* miss anything */
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 );
/* ...and rebuild it */
vlc_mutex_lock( &p_playlist->object_lock );
......@@ -847,6 +845,7 @@ void Playlist::Rebuild()
wxTreeItemId root = treectrl->GetRootItem();
UpdateNode( p_playlist, p_view->p_root, root );
/*
wxTreeItemId item;
if( p_playlist->status.p_item != NULL )
{
......@@ -865,7 +864,7 @@ void Playlist::Rebuild()
{
SetCurrentItem( item );
}
*/
int i_count = CountItems( treectrl->GetRootItem() );
if( i_count < p_playlist->i_size && !b_changed_view )
......@@ -890,6 +889,13 @@ void Playlist::Rebuild()
p_playlist->i_size ), 0 );
}
/* 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 );
vlc_mutex_unlock( &p_playlist->object_lock );
vlc_object_release( p_playlist );
......@@ -959,7 +965,7 @@ void Playlist::DeleteNode( playlist_item_t *p_item )
return;
}
playlist_NodeDelete( p_playlist, p_item, VLC_TRUE );
playlist_NodeDelete( p_playlist, p_item, VLC_TRUE , VLC_FALSE );
vlc_object_release( p_playlist );
}
......@@ -1334,8 +1340,10 @@ void Playlist::OnMenuEvent( wxCommandEvent& event )
}
else
{
wxMutexGuiLeave();
playlist_ServicesDiscoveryRemove( p_playlist,
pp_sds[event.GetId() - FirstSD_Event] );
wxMutexGuiEnter();
}
}
vlc_object_release( p_playlist );
......
......@@ -874,7 +874,6 @@ private:
void UpdateNodeChildren( playlist_t *, playlist_item_t*, wxTreeItemId );
void CreateNode( playlist_t *, playlist_item_t*, wxTreeItemId );
void UpdateTreeItem( playlist_t *, wxTreeItemId );
void SetCurrentItem( wxTreeItemId );
/* Search (internal) */
int CountItems( wxTreeItemId);
......
......@@ -321,7 +321,7 @@ static void Close( vlc_object_t *p_this )
if( p_playlist )
{
playlist_NodeDelete( p_playlist, p_sys->p_node, VLC_TRUE );
playlist_NodeDelete( p_playlist, p_sys->p_node, VLC_TRUE, VLC_TRUE );
vlc_object_release( p_playlist );
}
......
......@@ -99,6 +99,7 @@ static int Open( vlc_object_t *p_this )
services_discovery_sys_t *p_sys = malloc(
sizeof( services_discovery_sys_t ) );
vlc_value_t val;
playlist_t *p_playlist;
playlist_view_t *p_view;
......@@ -124,6 +125,11 @@ static int Open( vlc_object_t *p_this )
p_view = playlist_ViewFind( p_playlist, VIEW_CATEGORY );
p_sys->p_node = playlist_NodeCreate( p_playlist, VIEW_CATEGORY,
_("Devices"), p_view->p_root );
p_sys->p_node->i_flags |= PLAYLIST_RO_FLAG;
val.b_bool = VLC_TRUE;
var_Set( p_playlist, "intf-change", val );
vlc_object_release( p_playlist );
return VLC_SUCCESS;
......@@ -134,9 +140,15 @@ static int Open( vlc_object_t *p_this )
*****************************************************************************/
static void Close( vlc_object_t *p_this )
{
services_discovery_t *p_sd = ( services_discovery_t* )p_sd;
services_discovery_sys_t *p_sys = malloc(
sizeof( services_discovery_sys_t ) );
services_discovery_t *p_sd = ( services_discovery_t* )p_this;
services_discovery_sys_t *p_sys = p_sd->p_sys;
playlist_t *p_playlist = (playlist_t *) vlc_object_find( p_sd,
VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
if( p_playlist )
{
playlist_NodeDelete( p_playlist, p_sys->p_node, VLC_TRUE, VLC_TRUE );
vlc_object_release( p_playlist );
}
free( p_sys );
}
......
......@@ -481,7 +481,7 @@ static void Close( vlc_object_t *p_this )
if( p_playlist )
{
playlist_NodeDelete( p_playlist, p_sys->p_node, VLC_TRUE );
playlist_NodeDelete( p_playlist, p_sys->p_node, VLC_TRUE , VLC_TRUE );
vlc_object_release( p_playlist );
}
......
......@@ -54,11 +54,6 @@ playlist_item_t *playlist_RecursiveFindPrev( playlist_t *p_playlist,
void playlist_NodeDump( playlist_t *p_playlist, playlist_item_t *p_item,
int i_level );
int playlist_NodeDeleteInternal( playlist_t *p_playlist,
playlist_item_t *p_root,
vlc_bool_t b_delete_items, vlc_bool_t b_force );
/**********************************************************************
* Exported View management functions
**********************************************************************/
......@@ -127,8 +122,7 @@ int playlist_ViewInsert( playlist_t *p_playlist, int i_id, char *psz_name )
*/
int playlist_ViewDelete( playlist_t *p_playlist,playlist_view_t *p_view )
{
playlist_NodeDeleteInternal( p_playlist, p_view->p_root, VLC_TRUE,
VLC_TRUE );
playlist_NodeDelete( p_playlist, p_view->p_root, VLC_TRUE, VLC_TRUE );
REMOVE_ELEM( p_playlist->pp_views, p_playlist->i_views, 0 );
return VLC_SUCCESS;
}
......@@ -338,7 +332,7 @@ int playlist_NodeEmpty( playlist_t *p_playlist, playlist_item_t *p_root,
if( p_root->pp_children[i]->i_children > -1 )
{
playlist_NodeDelete( p_playlist, p_root->pp_children[i],
b_delete_items );
b_delete_items , VLC_FALSE );
}
else if( b_delete_items )
{
......@@ -358,15 +352,7 @@ int playlist_NodeEmpty( playlist_t *p_playlist, playlist_item_t *p_root,
* \return VLC_SUCCESS or an error
*/
int playlist_NodeDelete( playlist_t *p_playlist, playlist_item_t *p_root,
vlc_bool_t b_delete_items )
{
return playlist_NodeDeleteInternal( p_playlist, p_root,
b_delete_items, VLC_FALSE );
}
int playlist_NodeDeleteInternal( playlist_t *p_playlist,
playlist_item_t *p_root,
vlc_bool_t b_delete_items, vlc_bool_t b_force )
vlc_bool_t b_delete_items, vlc_bool_t b_force )
{
int i;
if( p_root->i_children == -1 )
......@@ -380,7 +366,7 @@ int playlist_NodeDeleteInternal( playlist_t *p_playlist,
if( p_root->pp_children[i]->i_children > -1 )
{
playlist_NodeDelete( p_playlist, p_root->pp_children[i],
b_delete_items );
b_delete_items , b_force );
}
else if( b_delete_items )
{
......@@ -406,7 +392,6 @@ int playlist_NodeDeleteInternal( playlist_t *p_playlist,
}
/**
* Adds an item to the childs of a node
*
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment