/*****************************************************************************
* playlist.cpp : wxWindows plugin for vlc
*****************************************************************************
- * Copyright (C) 2000-2004 VideoLAN
+ * Copyright (C) 2000-2005 VideoLAN
* $Id$
*
* Authors: Olivier Teulière <ipkiss@via.ecp.fr>
#include "bitmaps/loop.xpm"
#include "bitmaps/type_unknown.xpm"
+#include "bitmaps/type_afile.xpm"
+#include "bitmaps/type_vfile.xpm"
#include "bitmaps/type_net.xpm"
#include "bitmaps/type_card.xpm"
#include "bitmaps/type_disc.xpm"
+#include "bitmaps/type_cdda.xpm"
#include "bitmaps/type_directory.xpm"
#include "bitmaps/type_playlist.xpm"
+#include "bitmaps/type_node.xpm"
#include <wx/dynarray.h>
#include <wx/imaglist.h>
#define HELP_SHUFFLE N_( "Shuffle" )
-#define HELP_LOOP N_( "Loop" )
-#define HELP_REPEAT N_( "Repeat" )
+#define HELP_LOOP N_( "Repeat All" )
+#define HELP_REPEAT N_( "Repeat One" )
/* Callback prototype */
static int PlaylistChanged( vlc_object_t *, const char *,
static int ItemDeleted( vlc_object_t *p_this, const char *psz_variable,
vlc_value_t oval, vlc_value_t nval, void *param );
-
/*****************************************************************************
* Event Table.
*****************************************************************************/
class PlaylistItem : public wxTreeItemData
{
public:
- PlaylistItem( playlist_item_t *_p_item ) : wxTreeItemData()
+ PlaylistItem( playlist_item_t *p_item ) : wxTreeItemData()
{
- p_item = _p_item;
i_id = p_item->input.i_id;
}
protected:
- playlist_item_t *p_item;
int i_id;
friend class Playlist;
};
*****************************************************************************/
Playlist::Playlist( intf_thread_t *_p_intf, wxWindow *p_parent ):
wxFrame( p_parent, -1, wxU(_("Playlist")), wxDefaultPosition,
- wxSize(345,400), wxDEFAULT_FRAME_STYLE )
+ wxSize(500,300), wxDEFAULT_FRAME_STYLE )
{
vlc_value_t val;
i_update_counter = 0;
i_sort_mode = MODE_NONE;
b_need_update = VLC_FALSE;
+ p_playlist = (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
+ FIND_ANYWHERE );
+ if( p_playlist == NULL )
+ {
+ return;
+ }
+
SetIcon( *p_intf->p_sys->p_icon );
p_view_menu = NULL;
ViewMenu();
/* Append the freshly created menus to the menu bar */
- wxMenuBar *menubar = new wxMenuBar( wxMB_DOCKABLE );
+ wxMenuBar *menubar = new wxMenuBar();
menubar->Append( manage_menu, wxU(_("&Manage")) );
menubar->Append( sort_menu, wxU(_("S&ort")) );
menubar->Append( selection_menu, wxU(_("&Selection")) );
/* Create the toolbar */
wxToolBar *toolbar =
- CreateToolBar( wxTB_HORIZONTAL | wxTB_FLAT | wxTB_DOCKABLE );
+ CreateToolBar( wxTB_HORIZONTAL | wxTB_FLAT );
/* Create the random tool */
toolbar->AddTool( Random_Event, wxT(""), wxBitmap(shuffle_on_xpm),
/* FIXME: absolutely needs to be in the right order FIXME */
p_images->Add( wxIcon( type_unknown_xpm ) );
- p_images->Add( wxIcon( type_unknown_xpm ) );
+ p_images->Add( wxIcon( type_afile_xpm ) );
+ p_images->Add( wxIcon( type_vfile_xpm ) );
p_images->Add( wxIcon( type_directory_xpm ) );
p_images->Add( wxIcon( type_disc_xpm ) );
+ p_images->Add( wxIcon( type_cdda_xpm ) );
p_images->Add( wxIcon( type_card_xpm ) );
p_images->Add( wxIcon( type_net_xpm ) );
p_images->Add( wxIcon( type_playlist_xpm ) );
+ 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(8);
+ font.SetPointSize(9);
treectrl->SetFont( font );
wxBoxSizer *panel_sizer = new wxBoxSizer( wxVERTICAL );
SetDropTarget( new DragAndDrop( p_intf, VLC_TRUE ) );
#endif
- playlist_t *p_playlist =
- (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
- FIND_ANYWHERE );
- if( p_playlist == NULL )
- {
- return;
- }
+ i_saved_id = 0;
+
/* We want to be noticed of playlist changes */
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();
+ Rebuild( VLC_TRUE );
+
}
Playlist::~Playlist()
{
- playlist_t *p_playlist =
- (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
- FIND_ANYWHERE );
+ if( pp_sds != NULL )
+ free( pp_sds );
+
if( p_playlist == NULL )
{
return;
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 );
vlc_object_release( p_playlist );
}
**********************************************************************/
/* Update a node */
-void Playlist::UpdateNode( playlist_t *p_playlist, playlist_item_t *p_node,
- wxTreeItemId node )
+void Playlist::UpdateNode( playlist_item_t *p_node, wxTreeItemId node )
{
long cookie;
wxTreeItemId child;
if( !child.IsOk() )
{
/* Not enough children */
- CreateNode( p_playlist, p_node->pp_children[i], node );
+ CreateNode( p_node->pp_children[i], node );
/* Keep the tree pointer up to date */
child = treectrl->GetNextChild( node, cookie );
}
- else
- {
- }
}
treectrl->SetItemImage( node, p_node->input.i_type );
}
/* Creates the node p_node as last child of parent */
-void Playlist::CreateNode( playlist_t *p_playlist, playlist_item_t *p_node,
- wxTreeItemId parent )
+void Playlist::CreateNode( playlist_item_t *p_node, wxTreeItemId parent )
{
wxTreeItemId node =
treectrl->AppendItem( parent, wxL2U( p_node->input.psz_name ),
-1,-1, new PlaylistItem( p_node ) );
treectrl->SetItemImage( node, p_node->input.i_type );
- UpdateNodeChildren( p_playlist, p_node, node );
+ UpdateNodeChildren( p_node, node );
}
/* Update all children (recursively) of this node */
-void Playlist::UpdateNodeChildren( playlist_t *p_playlist,
- playlist_item_t *p_node,
+void Playlist::UpdateNodeChildren( playlist_item_t *p_node,
wxTreeItemId node )
{
wxL2U( p_node->pp_children[i]->input.psz_name ), -1,-1,
new PlaylistItem( p_node->pp_children[i]) );
- UpdateTreeItem( p_playlist, item );
-
- treectrl->SetItemImage( item,
- p_node->pp_children[i]->input.i_type );
+ UpdateTreeItem( item );
}
else
{
- CreateNode( p_playlist, p_node->pp_children[i],
- node );
+ CreateNode( p_node->pp_children[i], node );
}
}
}
-/* 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 )
+void Playlist::UpdateTreeItem( wxTreeItemId item )
{
- playlist_item_t *p_item =
- ((PlaylistItem *)treectrl->GetItemData( item ))->p_item;
+ if( ! item.IsOk() ) return;
- if( !p_item )
- {
- return;
- }
+ wxTreeItemData *p_data = treectrl->GetItemData( item );
+ if( !p_data ) return;
+
+ LockPlaylist( p_intf->p_sys, p_playlist );
+ playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
+ ((PlaylistItem *)p_data)->i_id );
+ if( !p_item ) return;
wxString msg;
- char *psz_author = playlist_ItemGetInfo( p_item, _("Meta-information"),
+ wxString duration = wxU( "" );
+ char *psz_author = vlc_input_item_GetInfo( &p_item->input,
+ _("Meta-information"),
_("Artist"));
+ if( psz_author == NULL )
+ return;
char psz_duration[MSTRTIME_MAX_SIZE];
mtime_t dur = p_item->input.i_duration;
if( dur != -1 )
+ {
secstotimestr( psz_duration, dur/1000000 );
- else
- memcpy( psz_duration, "-:--:--", sizeof("-:--:--") );
+ duration.Append( wxU( " ( " ) + wxString( wxU( psz_duration ) ) +
+ wxU( " )" ) );
+ }
if( !strcmp( psz_author, "" ) || p_item->input.b_fixed_name == VLC_TRUE )
{
- msg.Printf( wxString( wxL2U( p_item->input.psz_name ) ) + wxU( " ( ") +
- wxString(wxL2U(psz_duration ) ) + wxU( ")") );
+ msg.Printf( wxString( wxU( p_item->input.psz_name ) ) + duration );
}
else
{
msg.Printf( wxString(wxU( psz_author )) + wxT(" - ") +
- wxString(wxL2U(p_item->input.psz_name)) + wxU( " ( ") +
- wxString(wxL2U(psz_duration ) ) + wxU( ")") );
+ wxString(wxU(p_item->input.psz_name)) + duration );
}
+ free( psz_author );
treectrl->SetItemText( item , msg );
treectrl->SetItemImage( item, p_item->input.i_type );
if( p_playlist->status.p_item == p_item )
{
- SetCurrentItem( item );
+ treectrl->SetItemBold( item, true );
+ treectrl->EnsureVisible( item );
}
else
{
treectrl->SetItemBold( item, false );
}
+ UnlockPlaylist( p_intf->p_sys, p_playlist );
}
-/* Process a AppendItem request */
+/* Process a AppendIt em request */
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 );
wxTreeItemId item,node;
- if( p_playlist == NULL )
- {
- event.Skip();
- return;
- }
- if( p_add->i_view != i_current_view )
+ if( p_add->i_view != i_current_view || !p_add->p_node )
{
goto update;
}
- node = FindItem( treectrl->GetRootItem(), p_add->p_node );
+ node = FindItem( treectrl->GetRootItem(), p_add->p_node->input.i_id );
if( !node.IsOk() )
{
goto update;
if( item.IsOk() && p_add->p_item->i_children == -1 )
{
- UpdateTreeItem( p_playlist, item );
+ UpdateTreeItem( item );
}
update:
p_playlist->i_size ), 0 );
}
- vlc_object_release( p_playlist );
return;
}
void Playlist::UpdateItem( int i )
{
if( i < 0 ) return; /* Sanity check */
- playlist_item_t *p_item;
-
- playlist_t *p_playlist =
- (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
- FIND_ANYWHERE );
-
- if( p_playlist == NULL )
- {
- return;
- }
-
- p_item = playlist_ItemGetById( p_playlist, i );
-
- wxTreeItemId item = FindItem( treectrl->GetRootItem(), p_item);
+
+ wxTreeItemId item = FindItem( treectrl->GetRootItem(), i );
if( item.IsOk() )
{
- UpdateTreeItem( p_playlist, item );
+ UpdateTreeItem( item );
}
-
- vlc_object_release(p_playlist);
}
void Playlist::RemoveItem( int i )
if( item.IsOk() )
{
treectrl->Delete( item );
- }
+ }
}
/**********************************************************************
- * Search functions (internal
+ * Search functions (internal)
**********************************************************************/
-/* Find a wxItem from a playlist_item */
-wxTreeItemId Playlist::FindItem( wxTreeItemId root, playlist_item_t *p_item )
-{
- long cookie;
- PlaylistItem *p_wxcurrent;
- wxTreeItemId search;
- wxTreeItemId item = treectrl->GetFirstChild( root, cookie );
- wxTreeItemId child;
-
- p_wxcurrent = (PlaylistItem *)treectrl->GetItemData( root );
-
- if( !p_item )
- {
- wxTreeItemId dummy;
- return dummy;
- }
-
- if( p_wxcurrent->p_item == p_item )
- {
- return root;
- }
-
- while( item.IsOk() )
- {
- p_wxcurrent = (PlaylistItem *)treectrl->GetItemData( item );
- if( p_wxcurrent->p_item == p_item )
- {
- return item;
- }
- if( treectrl->ItemHasChildren( item ) )
- {
- wxTreeItemId search = FindItem( item, p_item );
- if( search.IsOk() )
- {
- return search;
- }
- }
- item = treectrl->GetNextChild( root, cookie );
- }
- /* Not found */
- wxTreeItemId dummy;
- return dummy;
-}
/* Find a wxItem from a playlist id */
wxTreeItemId Playlist::FindItem( wxTreeItemId root, int i_id )
{
long cookie;
int count = 0;
wxTreeItemId item = treectrl->GetFirstChild( root, cookie );
-
+
while( item.IsOk() )
{
if( treectrl->ItemHasChildren( item ) )
{
count += CountItems( item );
}
- else if( ( (PlaylistItem *)treectrl->GetItemData( item ) )->
- p_item->i_children == -1 )
- count++;
+ else
+ {
+ playlist_item_t *p_item;
+ LockPlaylist( p_intf->p_sys, p_playlist );
+ p_item = playlist_ItemGetById( p_playlist, ((PlaylistItem *)treectrl->GetItemData( item ))->i_id );
+ if( p_item && p_item->i_children == -1 )
+ count++;
+ UnlockPlaylist( p_intf->p_sys, p_playlist );
+ }
item = treectrl->GetNextChild( root, cookie );
}
return count;
/**********************************************************************
* Rebuild the playlist
**********************************************************************/
-void Playlist::Rebuild()
+void Playlist::Rebuild( vlc_bool_t b_root )
{
playlist_view_t *p_view;
- playlist_t *p_playlist =
- (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
- FIND_ANYWHERE );
- if( p_playlist == NULL )
- {
- return;
- }
- int i_count = CountItems( treectrl->GetRootItem()) ;
- if( i_count > p_playlist->i_size && !b_changed_view )
+ /* We can remove the callbacks before locking, anyway, we won't
+ * miss anything */
+ if( b_root )
{
- i_current_view = VIEW_CATEGORY;
- b_changed_view = VLC_TRUE;
- }
+ 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 );
+ /* ...and rebuild it */
+ LockPlaylist( p_intf->p_sys, p_playlist );
+ }
p_view = playlist_ViewFind( p_playlist, i_current_view ); /* FIXME */
/* HACK we should really get new*/
- msg_Dbg( p_intf, "rebuilding tree" );
treectrl->DeleteAllItems();
treectrl->AddRoot( wxU(_("root" )), -1, -1,
new PlaylistItem( p_view->p_root) );
wxTreeItemId root = treectrl->GetRootItem();
- UpdateNode( p_playlist, p_view->p_root, root );
+ UpdateNode( p_view->p_root, root );
- wxTreeItemId item;
- if( p_playlist->status.p_item != NULL )
- {
- item = FindItem( root, p_playlist->status.p_item );
- }
- else if( p_playlist->status.p_node != NULL )
- {
- item = FindItem( root, p_playlist->status.p_node );
- }
- else
- {
- item = root;
- }
-
- if( p_playlist->i_size )
+ int i_count = CountItems( treectrl->GetRootItem() );
+
+ if( i_count < p_playlist->i_size && !b_changed_view )
{
- SetCurrentItem( item );
+ i_current_view = VIEW_CATEGORY;
+ b_changed_view = VLC_TRUE;
+ Rebuild( VLC_FALSE );
}
-
-
- i_count = CountItems( treectrl->GetRootItem() );
- if( i_count != p_playlist->i_size )
+ else if( i_count != p_playlist->i_size )
{
statusbar->SetStatusText( wxString::Format( wxU(_(
"%i items in playlist (%i not shown)")),
p_playlist->i_size ), 0 );
}
- vlc_mutex_unlock( &p_playlist->object_lock );
+ 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 );
- vlc_object_release( p_playlist );
+ UnlockPlaylist( p_intf->p_sys, p_playlist );
+ }
}
void Playlist::ShowPlaylist( bool show )
{
- if( show ) Rebuild();
+ if( show ) Rebuild( VLC_TRUE );
Show( show );
}
if( this->b_need_update )
{
this->b_need_update = VLC_FALSE;
- Rebuild();
+ Rebuild( VLC_TRUE );
}
/* Updating the playing status every 0.5s is enough */
if( i_update_counter % 5 ) return;
-
- playlist_t *p_playlist =
- (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
- FIND_ANYWHERE );
- if( p_playlist == NULL )
- {
- return;
- }
-
- vlc_object_release( p_playlist );
}
/*****************************************************************************
*****************************************************************************/
void Playlist::DeleteItem( int item_id )
{
- playlist_t *p_playlist =
- (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
- FIND_ANYWHERE );
- if( p_playlist == NULL )
- {
- return;
- }
-
- playlist_Delete( p_playlist, item_id );
-
- vlc_object_release( p_playlist );
+ playlist_LockDelete( p_playlist, item_id );
}
void Playlist::DeleteNode( playlist_item_t *p_item )
{
- playlist_t *p_playlist =
- (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
- FIND_ANYWHERE );
- if( p_playlist == NULL )
- {
- return;
- }
-
- playlist_NodeDelete( p_playlist, p_item, VLC_TRUE );
-
- vlc_object_release( p_playlist );
+ playlist_NodeDelete( p_playlist, p_item, VLC_TRUE , VLC_FALSE );
}
-void Playlist::OnClose( wxCommandEvent& WXUNUSED(event) )
+void Playlist::OnClose( wxCloseEvent& WXUNUSED(event) )
{
Hide();
}
wxString filter = wxT("");
- playlist_t * p_playlist =
- (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
- FIND_ANYWHERE );
-
- if( ! p_playlist )
- {
- return;
- }
if( p_playlist->i_size == 0 )
{
wxMessageBox( wxU(_("Playlist is empty") ), wxU(_("Can't save")),
wxICON_WARNING | wxOK, this );
- vlc_object_release( p_playlist );
return;
}
}
}
- vlc_object_release( p_playlist );
-
}
void Playlist::OnOpen( wxCommandEvent& WXUNUSED(event) )
{
- playlist_t *p_playlist =
- (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
- FIND_ANYWHERE );
- if( p_playlist == NULL )
- {
- return;
- }
-
wxFileDialog dialog( this, wxU(_("Open playlist")), wxT(""), wxT(""),
wxT("All playlists|*.pls;*.m3u;*.asx;*.b4s|M3U files|*.m3u"), wxOPEN );
{
playlist_Import( p_playlist, dialog.GetPath().mb_str() );
}
-
- vlc_object_release( p_playlist );
}
void Playlist::OnAddFile( wxCommandEvent& WXUNUSED(event) )
********************************************************************/
void Playlist::OnSort( wxCommandEvent& event )
{
- playlist_t *p_playlist =
- (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
- FIND_ANYWHERE );
PlaylistItem *p_wxitem;
p_wxitem = (PlaylistItem *)treectrl->GetItemData( treectrl->GetRootItem() );
- if( p_playlist == NULL )
- {
- return;
- }
- vlc_mutex_lock( &p_playlist->object_lock );
+ LockPlaylist( p_intf->p_sys, p_playlist );
switch( event.GetId() )
{
case SortTitle_Event:
- playlist_RecursiveNodeSort( p_playlist, p_wxitem->p_item,
+ 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, p_wxitem->p_item,
+ playlist_RecursiveNodeSort( p_playlist, playlist_ItemGetById( p_playlist, p_wxitem->i_id ),
SORT_TITLE_NODES_FIRST, ORDER_REVERSE );
}
- vlc_mutex_unlock( &p_playlist->object_lock );
+ UnlockPlaylist( p_intf->p_sys, p_playlist );
- vlc_object_release( p_playlist );
- Rebuild();
+ Rebuild( VLC_TRUE );
}
/**********************************************************************
void Playlist::OnDeleteSelection( wxCommandEvent& WXUNUSED(event) )
{
- Rebuild();
+ Rebuild( VLC_TRUE );
}
void Playlist::OnSelectAll( wxCommandEvent& WXUNUSED(event) )
{
vlc_value_t val;
val.b_bool = event.IsChecked();
- playlist_t *p_playlist =
- (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
- FIND_ANYWHERE );
- if( p_playlist == NULL )
- {
- return;
- }
var_Set( p_playlist, "random", val);
- vlc_object_release( p_playlist );
}
void Playlist::OnLoop( wxCommandEvent& event )
{
vlc_value_t val;
val.b_bool = event.IsChecked();
- playlist_t *p_playlist =
- (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
- FIND_ANYWHERE );
- if( p_playlist == NULL )
- {
- return;
- }
var_Set( p_playlist, "loop", val);
- vlc_object_release( p_playlist );
}
void Playlist::OnRepeat( wxCommandEvent& event )
{
vlc_value_t val;
val.b_bool = event.IsChecked();
- playlist_t *p_playlist =
- (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
- FIND_ANYWHERE );
- if( p_playlist == NULL )
- {
- return;
- }
var_Set( p_playlist, "repeat", val);
- vlc_object_release( p_playlist );
}
/********************************************************************
********************************************************************/
void Playlist::OnActivateItem( wxTreeEvent& event )
{
- playlist_item_t *p_item,*p_node;
- playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf,
- VLC_OBJECT_PLAYLIST,FIND_ANYWHERE );
+ playlist_item_t *p_item,*p_node,*p_item2,*p_node2;
PlaylistItem *p_wxitem = (PlaylistItem *)treectrl->GetItemData(
event.GetItem() );
PlaylistItem *p_wxparent = (PlaylistItem *)treectrl->GetItemData( parent );
- if( p_playlist == NULL )
- {
- return;
- }
-
- if( p_wxitem->p_item->i_children == -1 )
+ LockPlaylist( p_intf->p_sys, p_playlist );
+
+ 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_wxparent->p_item;
- p_item = p_wxitem->p_item;
+ p_node = p_node2;
+ p_item = p_item2;
}
else
{
- p_node = p_wxitem->p_item;
- if( p_wxitem->p_item->i_children > 0 &&
- p_wxitem->p_item->pp_children[0]->i_children == -1)
+ p_node = p_item2;
+ if( p_node && p_node->i_children > 0 &&
+ p_node->pp_children[0]->i_children == -1)
{
- p_item = p_wxitem->p_item->pp_children[0];
+ p_item = p_node->pp_children[0];
}
else
{
playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, i_current_view,
p_node, p_item );
-
- vlc_object_release( p_playlist );
+ UnlockPlaylist( p_intf->p_sys, p_playlist );
}
void Playlist::OnKeyDown( wxTreeEvent& event )
void Playlist::OnEnDis( wxCommandEvent& event )
{
- playlist_t *p_playlist =
- (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
- FIND_ANYWHERE );
- if( p_playlist == NULL )
- {
- return;
- }
msg_Warn( p_intf, "not implemented" );
- vlc_object_release( p_playlist );
}
/**********************************************************************
void Playlist::OnMenuEvent( wxCommandEvent& event )
{
- playlist_t *p_playlist =
- (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
- FIND_ANYWHERE );
- if( p_playlist == NULL )
- {
- return;
- }
-
if( event.GetId() < FirstView_Event )
{
event.Skip();
- vlc_object_release( p_playlist );
return;
}
else if( event.GetId() < LastView_Event )
b_changed_view = VLC_TRUE;
i_current_view = i_new_view;
playlist_ViewUpdate( p_playlist, i_new_view );
- Rebuild();
- vlc_object_release( p_playlist );
+ Rebuild( VLC_TRUE );
return;
}
else if( i_new_view >= VIEW_FIRST_SORTED &&
i_current_view = i_new_view;
- Rebuild();
+ Rebuild( VLC_TRUE );
}
}
else if( event.GetId() >= FirstSD_Event && event.GetId() < LastSD_Event )
}
else
{
+ wxMutexGuiLeave();
playlist_ServicesDiscoveryRemove( p_playlist,
pp_sds[event.GetId() - FirstSD_Event] );
+ wxMutexGuiEnter();
}
}
- vlc_object_release( p_playlist );
}
wxMenu * Playlist::ViewMenu()
{
- playlist_t *p_playlist =
- (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
- FIND_ANYWHERE );
- if( p_playlist == NULL )
- {
- return NULL;
- }
-
if( !p_view_menu )
{
p_view_menu = new wxMenu;
/* FIXME : have a list of "should have" views */
p_view_menu->Append( FirstView_Event + VIEW_CATEGORY,
- wxU(_("By category") ) );
- p_view_menu->Append( FirstView_Event + VIEW_SIMPLE,
+ wxU(_("Normal") ) );
+/* p_view_menu->Append( FirstView_Event + VIEW_SIMPLE,
wxU(_("Manually added") ) );
p_view_menu->Append( FirstView_Event + VIEW_ALL,
- wxU(_("All items, unsorted") ) );
+ wxU(_("All items, unsorted") ) ); */
p_view_menu->Append( FirstView_Event + VIEW_S_AUTHOR,
- wxU(_("Sorted by author") ) );
-
- vlc_object_release( p_playlist);
+ wxU(_("Sorted by artist") ) );
return p_view_menu;
}
wxMenu *Playlist::SDMenu()
{
-
- playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf,
- VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
- if( !p_playlist )
- {
- return NULL;
- }
p_sd_menu = new wxMenu;
vlc_list_t *p_list = vlc_list_find( p_playlist, VLC_OBJECT_MODULE,
{
module_t * p_parser = (module_t *)p_list->p_values[i_index].p_object ;
+ if( !strcmp( p_parser->psz_capability, "services_discovery" ) )
+ i_number++;
+ }
+ if( i_number ) pp_sds = (char **)calloc( i_number, sizeof(void *) );
+
+ 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 ;
+
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 ) );
+ wxU( p_parser->psz_longname ? p_parser->psz_longname :
+ (p_parser->psz_shortname ?
+ p_parser->psz_shortname : p_parser->psz_object_name) ) );
if( playlist_IsServicesDiscoveryLoaded( p_playlist,
- p_parser->psz_shortname ) )
+ p_parser->psz_object_name ) )
{
p_sd_menu->Check( FirstSD_Event + i_number, TRUE );
}
- INSERT_ELEM( (void**)pp_sds, i_number, i_number,
- (void*)p_parser->psz_shortname );
+ pp_sds[i_number++] = p_parser->psz_object_name;
}
}
vlc_list_release( p_list );
- vlc_object_release( p_playlist );
return p_sd_menu;
}
void Playlist::OnPopup( wxContextMenuEvent& event )
{
wxPoint pt = event.GetPosition();
+ playlist_item_t *p_item;
- i_popup_item = treectrl->HitTest( ScreenToClient( pt ) );
- if( i_popup_item.IsOk() )
+ i_wx_popup_item = treectrl->HitTest( ScreenToClient( pt ) );
+ if( i_wx_popup_item.IsOk() )
{
PlaylistItem *p_wxitem = (PlaylistItem *)treectrl->GetItemData(
- i_popup_item );
- PlaylistItem *p_wxparent= (PlaylistItem *) treectrl->GetItemData(
- treectrl->GetItemParent( i_popup_item ) );
- p_popup_item = p_wxitem->p_item;
- p_popup_parent = p_wxparent->p_item;
- treectrl->SelectItem( i_popup_item );
- if( p_popup_item->i_children == -1 )
+ i_wx_popup_item );
+ PlaylistItem *p_wxparent= (PlaylistItem *)treectrl->GetItemData(
+ treectrl->GetItemParent( i_wx_popup_item ) );
+ i_popup_item = p_wxitem->i_id;
+ i_popup_parent = p_wxparent->i_id;
+ treectrl->SelectItem( i_wx_popup_item );
+
+ LockPlaylist( p_intf->p_sys, p_playlist );
+ p_item = playlist_ItemGetById( p_playlist, i_popup_item );
+
+ if( !p_item )
+ {
+ UnlockPlaylist( p_intf->p_sys, p_playlist );
+ return;
+ }
+ if( p_item->i_children == -1 )
+ {
+ UnlockPlaylist( p_intf->p_sys, p_playlist );
Playlist::PopupMenu( item_popup,
ScreenToClient( wxGetMousePosition() ) );
+ }
else
+ {
+ UnlockPlaylist( p_intf->p_sys, p_playlist );
Playlist::PopupMenu( node_popup,
ScreenToClient( wxGetMousePosition() ) );
-
+ }
}
}
-void Playlist::OnPopupPlay( wxMenuEvent& event )
+void Playlist::OnPopupPlay( wxCommandEvent& event )
{
- playlist_t *p_playlist =
- (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
- FIND_ANYWHERE );
- if( p_playlist == NULL )
- {
- return;
- }
+ 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_parent = playlist_ItemGetById( p_playlist, i_popup_parent );
if( p_popup_item != NULL )
{
if( p_popup_item->i_children > -1 )
}
}
}
- vlc_object_release( p_playlist );
+ UnlockPlaylist( p_intf->p_sys, p_playlist );
}
-void Playlist::OnPopupPreparse( wxMenuEvent& event )
+void Playlist::OnPopupPreparse( wxCommandEvent& event )
{
- playlist_t *p_playlist =
- (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
- FIND_ANYWHERE );
- if( p_playlist == NULL )
- {
- return;
- }
+ Preparse();
+}
+
+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 );
+
if( p_popup_item != NULL )
{
if( p_popup_item->i_children == -1 )
for( i = 0; i< p_parent->i_children ; i++ )
{
wxMenuEvent dummy;
- i_popup_item = FindItem( treectrl->GetRootItem(),
- p_parent->pp_children[i] );
- p_popup_item = p_parent->pp_children[i];
- OnPopupPreparse( dummy );
+ i_wx_popup_item = FindItem( treectrl->GetRootItem(),
+ p_parent->pp_children[i]->input.i_id );
+ i_popup_item = p_parent->pp_children[i]->input.i_id;
+ Preparse();
}
}
}
- vlc_object_release( p_playlist );
+ UnlockPlaylist( p_intf->p_sys, p_playlist );
}
-void Playlist::OnPopupDel( wxMenuEvent& event )
+void Playlist::OnPopupDel( wxCommandEvent& event )
{
PlaylistItem *p_wxitem;
+ playlist_item_t *p_item;
- p_wxitem = (PlaylistItem *)treectrl->GetItemData( i_popup_item );
-
- if( p_wxitem->p_item->i_children == -1 )
+ 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 );
+ if( !p_item )
+ {
+ UnlockPlaylist( p_intf->p_sys, p_playlist );
+ return;
+ }
+
+ if( p_item->i_children == -1 )
{
- DeleteItem( p_wxitem->p_item->input.i_id );
+ UnlockPlaylist( p_intf->p_sys, p_playlist );
+ DeleteItem( p_item->input.i_id );
}
else
{
- DeleteNode( p_wxitem->p_item );
+ UnlockPlaylist( p_intf->p_sys, p_playlist );
+ DeleteNode( p_item );
}
}
-void Playlist::OnPopupSort( wxMenuEvent& event )
+void Playlist::OnPopupSort( wxCommandEvent& event )
{
PlaylistItem *p_wxitem;
+ playlist_item_t *p_item;
- p_wxitem = (PlaylistItem *)treectrl->GetItemData( i_popup_item );
+ p_wxitem = (PlaylistItem *)treectrl->GetItemData( i_wx_popup_item );
+ LockPlaylist( p_intf->p_sys, p_playlist );
- if( p_wxitem->p_item->i_children >= 0 )
+ p_item = playlist_ItemGetById( p_playlist, p_wxitem->i_id );
+ if( p_item->i_children >= 0 )
{
- playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf,
- VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
-
- if( p_playlist )
- {
- vlc_mutex_lock( &p_playlist->object_lock );
- playlist_RecursiveNodeSort( p_playlist, p_wxitem->p_item,
- SORT_TITLE_NODES_FIRST, ORDER_NORMAL );
- vlc_mutex_unlock( &p_playlist->object_lock );
-
- treectrl->DeleteChildren( i_popup_item );
- UpdateNodeChildren( p_playlist, p_wxitem->p_item, i_popup_item );
+ playlist_RecursiveNodeSort( p_playlist, p_item,
+ SORT_TITLE_NODES_FIRST, ORDER_NORMAL );
+
+ treectrl->DeleteChildren( i_wx_popup_item );
+ UpdateNodeChildren( p_item, i_wx_popup_item );
- vlc_object_release( p_playlist );
- }
}
+ UnlockPlaylist( p_intf->p_sys, p_playlist );
}
-void Playlist::OnPopupInfo( wxMenuEvent& 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 );
if( p_popup_item )
{
iteminfo_dialog = new ItemInfoDialog( p_intf, p_popup_item, this );
if( iteminfo_dialog->ShowModal() == wxID_OK )
{
- UpdateItem( i_popup_item );
+ UpdateItem( i_wx_popup_item );
}
delete iteminfo_dialog;
}
+ UnlockPlaylist( p_intf->p_sys, p_playlist );
}
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 );