Commit 2b819bc1 authored by zorglub's avatar zorglub

Use item-append when an item is appended to a node -> don't rebuild the whole tree

parent 79de55fd
......@@ -200,7 +200,7 @@ struct playlist_t
/* Helper to add an item */
struct playlist_add_t
{
playlist_item_t *p_parent;
playlist_item_t *p_node;
playlist_item_t *p_item;
int i_view;
int i_position;
......
......@@ -55,6 +55,9 @@ static int PlaylistNext( vlc_object_t *, const char *,
vlc_value_t, vlc_value_t, void * );
static int ItemChanged( vlc_object_t *, const char *,
vlc_value_t, vlc_value_t, void * );
static int ItemAppended( vlc_object_t *p_this, const char *psz_variable,
vlc_value_t oval, vlc_value_t nval, void *param );
/*****************************************************************************
* Event Table.
......@@ -108,6 +111,7 @@ enum
/* custom events */
UpdateItem_Event,
AppendItem_Event,
MenuDummy_Event = wxID_HIGHEST + 999,
......@@ -363,26 +367,8 @@ Playlist::Playlist( intf_thread_t *_p_intf, wxWindow *p_parent ):
font.SetPointSize(8);
treectrl->SetFont( font );
/* Create the Up-Down buttons */
#if 0
wxButton *up_button =
new wxButton( playlist_panel, Up_Event, wxU(_("Up") ) );
wxButton *down_button =
new wxButton( playlist_panel, Down_Event, wxU(_("Down") ) );
wxBoxSizer *updown_sizer = new wxBoxSizer( wxHORIZONTAL );
updown_sizer->Layout();
/* The top and bottom sizers */
wxBoxSizer *bottom_sizer = new wxBoxSizer( wxHORIZONTAL );
bottom_sizer->Add( up_button, 0, wxALIGN_LEFT | wxRIGHT, 3);
bottom_sizer->Add( down_button, 0, wxALIGN_LEFT | wxLEFT, 3);
bottom_sizer->Layout();
#endif
wxBoxSizer *panel_sizer = new wxBoxSizer( wxVERTICAL );
panel_sizer->Add( treectrl, 1, wxEXPAND | wxALL, 5 );
#if 0
panel_sizer->Add( bottom_sizer, 0, wxALL, 5);
#endif
panel_sizer->Layout();
playlist_panel->SetSizerAndFit( panel_sizer );
......@@ -411,6 +397,8 @@ Playlist::Playlist( intf_thread_t *_p_intf, wxWindow *p_parent ):
/* One item has been updated */
var_AddCallback( p_playlist, "item-change", ItemChanged, this );
var_AddCallback( p_playlist, "item-append", ItemAppended, this );
vlc_object_release( p_playlist );
/* Update the playlist */
......@@ -419,12 +407,6 @@ Playlist::Playlist( intf_thread_t *_p_intf, wxWindow *p_parent ):
void Playlist::OnSize( wxSizeEvent& event)
{
#if 0
wxSize size = GetClientSize();
if( listview )
listview->SetColumnWidth( 0, size.x - listview->GetColumnWidth(1)
- 15 /* margins */ );
#endif
event.Skip();
}
......@@ -517,6 +499,12 @@ wxTreeItemId Playlist::FindItem( wxTreeItemId root, playlist_item_t *p_item )
wxTreeItemId item = treectrl->GetFirstChild( root, cookie );
wxTreeItemId child;
if( !p_item )
{
wxTreeItemId dummy;
return dummy;
}
while( item.IsOk() )
{
p_wxcurrent = (PlaylistItem *)treectrl->GetItemData( item );
......@@ -580,6 +568,46 @@ void Playlist::SetCurrentItem( wxTreeItemId item )
}
}
void Playlist::AppendItem( wxCommandEvent& event )
{
playlist_add_t *p_add = (playlist_add_t *)event.GetClientData();
playlist_t *p_playlist =
(playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
FIND_ANYWHERE );
if( p_playlist == NULL )
{
event.Skip();
return;
}
if( p_add->i_view != i_current_view )
{
vlc_object_release( p_playlist );
event.Skip();
return;
}
wxTreeItemId node = FindItem( treectrl->GetRootItem(), p_add->p_node );
if( !node.IsOk() )
{
vlc_object_release( p_playlist );
event.Skip();
return;
}
wxTreeItemId item = treectrl->AppendItem( node,
wxL2U( p_add->p_item->input.psz_name ), -1,-1,
new PlaylistItem( p_add->p_item ) );
treectrl->SetItemImage( item, p_add->p_item->input.i_type );
if( item.IsOk() && p_add->p_item->i_children == -1 )
{
UpdateTreeItem( p_playlist, item );
}
vlc_object_release( p_playlist );
}
void Playlist::UpdateItem( int i )
{
if( i < 0 ) return; /* Sanity check */
......@@ -606,7 +634,7 @@ void Playlist::UpdateItem( int i )
vlc_object_release(p_playlist);
}
void Playlist::UpdateTreeItem( playlist_t *p_playlist ,wxTreeItemId item )
void Playlist::UpdateTreeItem( playlist_t *p_playlist, wxTreeItemId item )
{
playlist_item_t *p_item =
((PlaylistItem *)treectrl->GetItemData( item ))->p_item;
......@@ -1512,9 +1540,12 @@ void Playlist::OnPlaylistEvent( wxCommandEvent& event )
{
switch( event.GetId() )
{
case UpdateItem_Event:
UpdateItem( event.GetInt() );
break;
case UpdateItem_Event:
UpdateItem( event.GetInt() );
break;
case AppendItem_Event:
AppendItem( event );
break;
}
}
......@@ -1562,3 +1593,18 @@ static int ItemChanged( vlc_object_t *p_this, const char *psz_variable,
return 0;
}
static int ItemAppended( 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;
playlist_add_t *p_add = (playlist_add_t *)malloc(sizeof( playlist_add_t));
memcpy( p_add, nval.p_address, sizeof( playlist_add_t ) );
wxCommandEvent event( wxEVT_PLAYLIST, AppendItem_Event );
event.SetClientData( (void *)p_add );
p_playlist_dialog->AddPendingEvent( event );
return VLC_SUCCESS;
}
......@@ -779,6 +779,7 @@ public:
void UpdatePlaylist();
void ShowPlaylist( bool show );
void UpdateItem( int );
void AppendItem( wxCommandEvent& );
bool b_need_update;
......
......@@ -255,6 +255,7 @@ static int Open( vlc_object_t *p_this )
playlist_t *p_playlist;
playlist_view_t *p_view;
char *psz_addr;
vlc_value_t val;
p_sys->i_timeout = config_GetInt( p_sd,"sap-timeout" );
......@@ -320,6 +321,8 @@ 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,
_("SAP"), p_view->p_root );
val.b_bool = VLC_TRUE;
var_Set( p_playlist, "intf-change", val );
vlc_object_release( p_playlist );
......
......@@ -120,6 +120,8 @@ int playlist_AddItem( playlist_t *p_playlist, playlist_item_t *p_item,
vlc_bool_t b_end = VLC_FALSE;
playlist_view_t *p_view = NULL;
playlist_add_t *p_add = (playlist_add_t *)malloc(sizeof( playlist_add_t));
vlc_mutex_lock( &p_playlist->object_lock );
/*
......@@ -196,12 +198,19 @@ int playlist_AddItem( playlist_t *p_playlist, playlist_item_t *p_item,
{
playlist_NodeAppend( p_playlist, VIEW_CATEGORY, p_item,
p_playlist->p_general );
p_add->p_item = p_item;
p_add->p_node = p_playlist->p_general;
p_add->i_view = VIEW_CATEGORY;
val.p_address = p_add;
var_Set( p_playlist, "item-append", val );
}
else
{
playlist_NodeInsert( p_playlist, VIEW_CATEGORY, p_item,
p_playlist->p_general, i_pos );
}
p_view = playlist_ViewFind( p_playlist, VIEW_ALL );
playlist_ItemAddParent( p_item, VIEW_ALL, p_view->p_root );
......@@ -212,6 +221,12 @@ int playlist_AddItem( playlist_t *p_playlist, playlist_item_t *p_item,
{
playlist_NodeAppend( p_playlist, VIEW_SIMPLE,p_item,
p_view->p_root );
p_add->p_item = p_item;
p_add->p_node = p_view->p_root;
p_add->i_view = VIEW_SIMPLE;
val.p_address = p_add;
var_Set( p_playlist, "item-append", val );
}
else
{
......@@ -219,6 +234,7 @@ int playlist_AddItem( playlist_t *p_playlist, playlist_item_t *p_item,
p_view->p_root, i_pos );
}
/* FIXME : Update sorted views */
if( p_playlist->i_index >= i_pos )
......@@ -248,8 +264,11 @@ int playlist_AddItem( playlist_t *p_playlist, playlist_item_t *p_item,
vlc_mutex_unlock( &p_playlist->object_lock );
val.b_bool = VLC_TRUE;
var_Set( p_playlist, "intf-change", val );
if( b_end == VLC_FALSE )
{
val.b_bool = VLC_TRUE;
var_Set( p_playlist, "intf-change", val );
}
return p_item->input.i_id;
}
......@@ -275,6 +294,8 @@ int playlist_NodeAddItem( playlist_t *p_playlist, playlist_item_t *p_item,
int i_position;
playlist_view_t *p_view;
playlist_add_t *p_add = (playlist_add_t *)malloc(sizeof( playlist_add_t));
vlc_mutex_lock( &p_playlist->object_lock );
/* Sanity checks */
......@@ -327,6 +348,12 @@ int playlist_NodeAddItem( playlist_t *p_playlist, playlist_item_t *p_item,
/* TODO: Handle modes */
playlist_NodeAppend( p_playlist, i_view, p_item, p_parent );
p_add->p_item = p_item;
p_add->p_node = p_parent;
p_add->i_view = i_view;
val.p_address = p_add;
var_Set( p_playlist, "item-append", val );
/* We update the ALL view directly */
p_view = playlist_ViewFind( p_playlist, VIEW_ALL );
playlist_ItemAddParent( p_item, VIEW_ALL, p_view->p_root );
......@@ -350,7 +377,7 @@ int playlist_NodeAddItem( playlist_t *p_playlist, playlist_item_t *p_item,
vlc_mutex_unlock( &p_playlist->object_lock );
val.b_bool = VLC_TRUE;
var_Set( p_playlist, "intf-change", val );
// var_Set( p_playlist, "intf-change", val );
return p_item->input.i_id;
}
......
......@@ -82,6 +82,8 @@ playlist_t * __playlist_Create ( vlc_object_t *p_parent )
val.i_int = -1;
var_Set( p_playlist, "item-change", val );
var_Create( p_playlist, "item-append", VLC_VAR_ADDRESS );
var_Create( p_playlist, "playlist-current", VLC_VAR_INTEGER );
val.i_int = -1;
var_Set( p_playlist, "playlist-current", val );
......@@ -363,7 +365,6 @@ int playlist_vaControl( playlist_t * p_playlist, int i_query, va_list args )
}
vlc_mutex_unlock( &p_playlist->object_lock );
fprintf(stderr,"control done, request is %i\n", p_playlist->request.b_request);
return VLC_SUCCESS;
}
......
......@@ -242,6 +242,8 @@ playlist_item_t * playlist_NodeCreate( playlist_t *p_playlist, int i_view,
/* Create the item */
playlist_item_t *p_item = (playlist_item_t *)malloc(
sizeof( playlist_item_t ) );
vlc_value_t val;
playlist_add_t *p_add = (playlist_add_t*)malloc( sizeof(playlist_add_t));
vlc_input_item_Init( VLC_OBJECT(p_playlist), &p_item->input );
if( p_item == NULL )
......@@ -286,6 +288,12 @@ playlist_item_t * playlist_NodeCreate( playlist_t *p_playlist, int i_view,
playlist_NodeAppend( p_playlist, i_view, p_item, p_parent );
}
p_add->p_node = p_parent;
p_add->p_item = p_item;
p_add->i_view = i_view;
val.p_address = p_add;
var_Set( p_playlist, "item-append", val);
return p_item;
}
......
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