* playlist.cpp : wxWindows plugin for vlc
*****************************************************************************
* Copyright (C) 2000-2004 VideoLAN
- * $Id: playlist.cpp,v 1.42 2004/02/23 12:17:24 gbazin Exp $
+ * $Id: playlist.cpp,v 1.49 2004/02/29 14:05:45 zorglub 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;
- vlc_mutex_init( p_intf, &lock );
SetIcon( *p_intf->p_sys->p_icon );
i_title_sorted = 0;
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 );
}
void Playlist::UpdatePlaylist()
{
- vlc_bool_t b_need_update = VLC_FALSE;
i_update_counter++;
/* If the playlist isn't show there's no need to update it */
if( !IsShown() ) return;
- vlc_mutex_lock( &lock );
if( this->b_need_update )
{
- b_need_update =VLC_TRUE;
this->b_need_update = VLC_FALSE;
- }
- vlc_mutex_unlock( &lock );
-
- if( b_need_update )
- {
Rebuild();
}
}
/* Update the colour of items */
-
- vlc_mutex_lock( &p_playlist->object_lock );
- if( p_intf->p_sys->i_playing != p_playlist->i_index )
+ int i_playlist_index = p_playlist->i_index;
+ if( p_intf->p_sys->i_playing != i_playlist_index )
{
wxListItem listitem;
- listitem.m_itemId = p_playlist->i_index;
+ listitem.m_itemId = i_playlist_index;
listitem.SetTextColour( *wxRED );
listview->SetItem( listitem );
listitem.SetTextColour( *wxBLACK );
listview->SetItem( listitem );
}
- p_intf->p_sys->i_playing = p_playlist->i_index;
+ p_intf->p_sys->i_playing = i_playlist_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();
+ bool b_ok = false;
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++ )
+ if( i_first == listview->GetItemCount() )
+ {
+ i_first = -1;
+ }
+
+ for( i_current = i_first + 1; i_current < listview->GetItemCount();
+ i_current++ )
{
wxListItem listitem;
listitem.SetId( i_current );
if( listitem.m_text.Lower().Contains( search_string.Lower() ) )
{
i_item = i_current;
+ b_ok = true;
break;
}
+ listitem.SetColumn( 1 );
+ listview->GetItem( listitem );
+ if( listitem.m_text.Lower().Contains( search_string.Lower() ) )
+ {
+ i_item = i_current;
+ b_ok = true;
+ break;
+ }
+ }
+ if( !b_ok )
+ {
+ for( i_current = -1 ; i_current < i_first - 1;
+ i_current++ )
+ {
+ wxListItem listitem;
+ listitem.SetId( i_current );
+ listview->GetItem( listitem );
+ if( listitem.m_text.Lower().Contains( search_string.Lower() ) )
+ {
+ i_item = i_current;
+ b_ok = true;
+ break;
+ }
+ listitem.SetColumn( 1 );
+ listview->GetItem( listitem );
+ if( listitem.m_text.Lower().Contains( search_string.Lower() ) )
+ {
+ i_item = i_current;
+ b_ok = true;
+ break;
+ }
+ }
}
+
+ if( i_item < 0 || i_item >= listview->GetItemCount() ) return;
+
for( long item = 0; item < listview->GetItemCount(); item++ )
{
listview->Select( item, FALSE );
{
return;
}
+
+ if( i_item == -1 )
+ {
+ return;
+ }
+
if( iteminfo_dialog == NULL )
{
vlc_mutex_lock( &p_playlist->object_lock);
Playlist::PopupMenu( popup_menu , ScreenToClient( wxGetMousePosition() ) );
}
-
void Playlist::OnPopupPlay( wxMenuEvent& event )
{
playlist_t *p_playlist =
vlc_value_t old_val, vlc_value_t new_val, void *param )
{
Playlist *p_playlist_dialog = (Playlist *)param;
- vlc_mutex_lock( &p_playlist_dialog->lock );
p_playlist_dialog->b_need_update = VLC_TRUE;
- vlc_mutex_unlock( &p_playlist_dialog->lock );
return VLC_SUCCESS;
}