* playlist.cpp : wxWindows plugin for vlc
*****************************************************************************
* Copyright (C) 2000-2004 VideoLAN
- * $Id: playlist.cpp,v 1.43 2004/02/24 18:19:44 zorglub Exp $
+ * $Id: playlist.cpp,v 1.44 2004/02/26 00:23:04 gbazin Exp $
*
* Authors: Olivier Teulière <ipkiss@via.ecp.fr>
*
wxFrame( p_parent, -1, wxU(_("Playlist")), wxDefaultPosition,
wxDefaultSize, wxDEFAULT_FRAME_STYLE )
{
+ vlc_value_t val;
+
/* Initializations */
iteminfo_dialog = NULL;
p_intf = _p_intf;
- vlc_value_t val;
i_update_counter = 0;
i_sort_mode = MODE_NONE;
b_need_update = VLC_FALSE;
i_group_sorted = 0;
i_duration_sorted = 0;
-
var_Create( p_intf, "random", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
var_Create( p_intf, "loop", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
var_Create( p_intf, "repeat", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );;
top_sizer->Layout();
wxBoxSizer *bottom_sizer = new wxBoxSizer( wxHORIZONTAL );
- bottom_sizer->Add( updown_sizer, 0, wxEXPAND |wxRIGHT | wxLEFT | wxALIGN_LEFT, 4);
- bottom_sizer->Add( button_sizer , 0, wxEXPAND|wxLEFT | wxRIGHT | wxALIGN_RIGHT, 4 );
+ bottom_sizer->Add( updown_sizer, 0,
+ wxEXPAND |wxRIGHT | wxLEFT | wxALIGN_LEFT, 4 );
+ bottom_sizer->Add( button_sizer , 0,
+ wxEXPAND|wxLEFT | wxRIGHT | wxALIGN_RIGHT, 4 );
bottom_sizer->Layout();
wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL );
**********************************************************************/
void Playlist::UpdateItem( int i )
{
+ if( i < 0 ) return; /* Sanity check */
+
playlist_t *p_playlist =
(playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
FIND_ANYWHERE );
}
vlc_mutex_unlock( &p_playlist->object_lock );
- if( i_focused )
+ if( i_focused >= 0 && i_focused < p_playlist->i_size )
{
listview->Focus( i_focused );
listview->Select( i_focused );
}
- else
+ else if( p_playlist->i_index >= 0 )
{
listview->Focus( p_playlist->i_index );
}
vlc_mutex_lock( &lock );
if( this->b_need_update )
{
- b_need_update =VLC_TRUE;
+ b_need_update = VLC_TRUE;
this->b_need_update = VLC_FALSE;
}
vlc_mutex_unlock( &lock );
}
/* Update the colour of items */
-
vlc_mutex_lock( &p_playlist->object_lock );
if( p_intf->p_sys->i_playing != p_playlist->i_index )
{
p_intf->p_sys->i_playing = p_playlist->i_index;
}
vlc_mutex_unlock( &p_playlist->object_lock );
+
vlc_object_release( p_playlist );
}
return;
}
- wxFileDialog dialog( this, wxU(_("Open playlist")),
- wxT(""), wxT(""), wxT("All playlists|*.pls;*.m3u;*.asx;*.b4s|M3U files|*.m3u"), wxOPEN );
+ wxFileDialog dialog( this, wxU(_("Open playlist")), wxT(""), wxT(""),
+ wxT("All playlists|*.pls;*.m3u;*.asx;*.b4s|M3U files|*.m3u"), wxOPEN );
if( dialog.ShowModal() == wxID_OK )
{
/********************************************************************
* Move functions
********************************************************************/
-void Playlist::OnUp( wxCommandEvent& event)
+void Playlist::OnUp( wxCommandEvent& event )
{
playlist_t *p_playlist =
(playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
}
/* We use the first selected item, so find it */
- long i_item = listview->GetNextItem( i_item, wxLIST_NEXT_ALL,
+ long i_item = listview->GetNextItem( -1, wxLIST_NEXT_ALL,
wxLIST_STATE_SELECTED);
if( i_item > 0 && i_item < p_playlist->i_size )
{
- playlist_Move( p_playlist , i_item, i_item - 1);
- if( i_item > 1 )
- {
- listview->Focus( i_item - 1 );
- }
- else
- {
- listview->Focus(0);
- }
+ playlist_Move( p_playlist, i_item, i_item - 1 );
+ listview->Focus( i_item - 1 );
}
vlc_object_release( p_playlist );
return;
}
-void Playlist::OnDown( wxCommandEvent& event)
+void Playlist::OnDown( wxCommandEvent& event )
{
playlist_t *p_playlist =
(playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
}
/* We use the first selected item, so find it */
- long i_item = listview->GetNextItem( i_item, wxLIST_NEXT_ALL,
+ long i_item = listview->GetNextItem( -1, wxLIST_NEXT_ALL,
wxLIST_STATE_SELECTED );
if( i_item >= 0 && i_item < p_playlist->i_size - 1 )
{
void Playlist::OnSearch( wxCommandEvent& WXUNUSED(event) )
{
- wxString search_string= search_text->GetValue();
+ wxString search_string = search_text->GetValue();
int i_current;
int i_first = 0 ;
int i_item = -1;
- for( i_current = 0 ; i_current <= listview->GetItemCount() ; i_current++ )
+ for( i_current = 0; i_current < listview->GetItemCount(); i_current++ )
{
- if( listview->GetItemState( i_current, wxLIST_STATE_SELECTED )
- == wxLIST_STATE_SELECTED )
+ if( listview->GetItemState( i_current, wxLIST_STATE_SELECTED ) ==
+ wxLIST_STATE_SELECTED )
{
i_first = i_current;
break;
}
}
- for ( i_current = i_first + 1; i_current <= listview->GetItemCount() ;
- i_current++ )
+ for( i_current = i_first + 1; i_current < listview->GetItemCount();
+ i_current++ )
{
wxListItem listitem;
listitem.SetId( i_current );
break;
}
}
+
+ if( i_item < 0 || i_item >= listview->GetItemCount() ) return;
+
for( long item = 0; item < listview->GetItemCount(); item++ )
{
listview->Select( item, FALSE );
Playlist::PopupMenu( popup_menu , ScreenToClient( wxGetMousePosition() ) );
}
-
void Playlist::OnPopupPlay( wxMenuEvent& event )
{
playlist_t *p_playlist =
wxCommandEvent event( wxEVT_PLAYLIST, UpdateItem_Event );
event.SetInt( old_val.i_int );
- p_playlist_dialog->ProcessEvent( event );
+ p_playlist_dialog->AddPendingEvent( event );
event.SetInt( new_val.i_int );
- p_playlist_dialog->ProcessEvent( event );
+ p_playlist_dialog->AddPendingEvent( event );
return 0;
}
wxCommandEvent event( wxEVT_PLAYLIST, UpdateItem_Event );
event.SetInt( new_val.i_int );
- p_playlist_dialog->ProcessEvent( event );
+ p_playlist_dialog->AddPendingEvent( event );
return 0;
}