]> git.sesse.net Git - vlc/blobdiff - modules/gui/wxwindows/playlist.cpp
* Made the open dialog a wxDialog to be able to call it from the wizard. Please test...
[vlc] / modules / gui / wxwindows / playlist.cpp
index f8c92ec89ca1185f017a6808e6e2cd56049fb55a..73ea44750c46506736ff4701766608a244231a7c 100644 (file)
@@ -1,8 +1,8 @@
 /*****************************************************************************
  * playlist.cpp : wxWindows plugin for vlc
  *****************************************************************************
- * Copyright (C) 2000-2001, 2003 VideoLAN
- * $Id: playlist.cpp,v 1.34 2004/01/08 00:52:08 sigmunau Exp $
+ * Copyright (C) 2000-2004 VideoLAN
+ * $Id$
  *
  * Authors: Olivier Teulière <ipkiss@via.ecp.fr>
  *
 #include <vlc/intf.h>
 
 #include "wxwindows.h"
-#include <wx/listctrl.h>
 
 /* Callback prototype */
-int PlaylistChanged( vlc_object_t *p_this, const char *psz_variable,
-                     vlc_value_t old_val, vlc_value_t new_val, void *param );
-int PlaylistNext( vlc_object_t *p_this, const char *psz_variable,
-                     vlc_value_t old_val, vlc_value_t new_val, void *param );
-int ItemChanged( vlc_object_t *p_this, const char *psz_variable,
-                     vlc_value_t old_val, vlc_value_t new_val, void *param );
+static int PlaylistChanged( vlc_object_t *, const char *,
+                            vlc_value_t, vlc_value_t, void * );
+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 * );
 
 /*****************************************************************************
  * Event Table.
@@ -86,9 +85,16 @@ enum
     Search_Event,
 
     /* controls */
-    ListView_Event
+    ListView_Event,
+
+    Browse_Event,  /* For export playlist */
+
+    /* custom events */
+    UpdateItem_Event
 };
 
+DEFINE_LOCAL_EVENT_TYPE( wxEVT_PLAYLIST );
+
 BEGIN_EVENT_TABLE(Playlist, wxFrame)
     /* Menu events */
     EVT_MENU(AddFile_Event, Playlist::OnAddFile)
@@ -142,6 +148,9 @@ BEGIN_EVENT_TABLE(Playlist, wxFrame)
 
     EVT_TEXT(SearchText_Event, Playlist::OnSearchTextChange)
 
+    /* Custom events */
+    EVT_COMMAND(-1, wxEVT_PLAYLIST, Playlist::OnPlaylistEvent)
+
     /* Special events : we don't want to destroy the window when the user
      * clicks on (X) */
     EVT_CLOSE(Playlist::OnClose)
@@ -154,6 +163,7 @@ BEGIN_EVENT_TABLE(NewGroup, wxDialog)
     EVT_BUTTON( wxID_CANCEL, NewGroup::OnCancel)
 END_EVENT_TABLE()
 
+
 /*****************************************************************************
  * Constructor.
  *****************************************************************************/
@@ -161,27 +171,24 @@ Playlist::Playlist( intf_thread_t *_p_intf, wxWindow *p_parent ):
     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_author_sorted = 0;
     i_group_sorted = 0;
+    i_duration_sorted = 0;
 
-
-    var_Create( p_intf, "random", VLC_VAR_BOOL );
-    var_Change( p_intf, "random", VLC_VAR_INHERITVALUE, & val, NULL );
-    var_Create( p_intf, "loop", VLC_VAR_BOOL );
-    var_Create( p_intf, "loop", VLC_VAR_BOOL );
-    var_Change( p_intf, "repeat", VLC_VAR_INHERITVALUE, & val, NULL );
-    var_Change( p_intf, "repeat", VLC_VAR_INHERITVALUE, & val, NULL );
+    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 );;
 
     /* Create our "Manage" menu */
     wxMenu *manage_menu = new wxMenu;
@@ -199,12 +206,12 @@ Playlist::Playlist( intf_thread_t *_p_intf, wxWindow *p_parent ):
     sort_menu->Append( RSortTitle_Event, wxU(_("&Reverse sort by title")) );
     sort_menu->AppendSeparator();
     sort_menu->Append( SortAuthor_Event, wxU(_("Sort by &author")) );
-    sort_menu->Append( RSortAuthor_Event, wxU(_("&Reverse sort by author")) );
+    sort_menu->Append( RSortAuthor_Event, wxU(_("Reverse sort by author")) );
     sort_menu->AppendSeparator();
     sort_menu->Append( SortGroup_Event, wxU(_("Sort by &group")) );
-    sort_menu->Append( RSortGroup_Event, wxU(_("&Reverse sort by group")) );
+    sort_menu->Append( RSortGroup_Event, wxU(_("Reverse sort by group")) );
     sort_menu->AppendSeparator();
-    sort_menu->Append( Randomize_Event, wxU(_("&Randomize Playlist")) );
+    sort_menu->Append( Randomize_Event, wxU(_("&Shuffle Playlist")) );
 
     /* Create our "Selection" menu */
     wxMenu *selection_menu = new wxMenu;
@@ -212,7 +219,7 @@ Playlist::Playlist( intf_thread_t *_p_intf, wxWindow *p_parent ):
     selection_menu->Append( DisableSelection_Event, wxU(_("&Disable")) );
     selection_menu->AppendSeparator();
     selection_menu->Append( InvertSelection_Event, wxU(_("&Invert")) );
-    selection_menu->Append( DeleteSelection_Event, wxU(_("&Delete")) );
+    selection_menu->Append( DeleteSelection_Event, wxU(_("D&elete")) );
     selection_menu->Append( SelectAll_Event, wxU(_("&Select All")) );
 
     /* Create our "Group" menu */
@@ -233,10 +240,10 @@ Playlist::Playlist( intf_thread_t *_p_intf, wxWindow *p_parent ):
 
     /* Create the popup menu */
     popup_menu = new wxMenu;
-    popup_menu->Append( PopupPlay_Event, wxU(_("Play item")) );
-    popup_menu->Append( PopupDel_Event, wxU(_("Delete item")) );
-    popup_menu->Append( PopupEna_Event, wxU(_("Toggle enabled")) );
-    popup_menu->Append( PopupInfo_Event, wxU(_("Info on item")) );
+    popup_menu->Append( PopupPlay_Event, wxU(_("Play")) );
+    popup_menu->Append( PopupDel_Event, wxU(_("Delete")) );
+    popup_menu->Append( PopupEna_Event, wxU(_("Enable/Disable")) );
+    popup_menu->Append( PopupInfo_Event, wxU(_("Info")) );
 
     /* Create a panel to put everything in */
     wxPanel *playlist_panel = new wxPanel( this, -1 );
@@ -251,14 +258,14 @@ Playlist::Playlist( intf_thread_t *_p_intf, wxWindow *p_parent ):
 
     /* Create the Loop Checkbox */
     wxCheckBox *loop_checkbox =
-        new wxCheckBox( playlist_panel, Loop_Event, wxU(_("Loop")) );
+        new wxCheckBox( playlist_panel, Loop_Event, wxU(_("Repeat All")) );
     var_Get( p_intf, "loop", &val );
     int b_loop = val.b_bool ;
     loop_checkbox->SetValue( b_loop );
 
     /* Create the Repeat one checkbox */
     wxCheckBox *repeat_checkbox =
-        new wxCheckBox( playlist_panel, Repeat_Event, wxU(_("Repeat one")) );
+        new wxCheckBox( playlist_panel, Repeat_Event, wxU(_("Repeat One")) );
     var_Get( p_intf, "repeat", &val );
     int b_repeat = val.b_bool ;
     repeat_checkbox->SetValue( b_repeat );
@@ -284,8 +291,8 @@ Playlist::Playlist( intf_thread_t *_p_intf, wxWindow *p_parent ):
                                wxLC_REPORT | wxSUNKEN_BORDER );
     listview->InsertColumn( 0, wxU(_("Name")) );
     listview->InsertColumn( 1, wxU(_("Author")) );
-    listview->InsertColumn( 2, wxU(_("Group")) );
-    listview->InsertColumn( 3, wxU(_("Duration")) );
+    listview->InsertColumn( 2, wxU(_("Duration")) );
+    listview->InsertColumn( 3, wxU(_("Group")) );
     listview->SetColumnWidth( 0, 270 );
     listview->SetColumnWidth( 1, 150 );
     listview->SetColumnWidth( 2, 80 );
@@ -332,8 +339,10 @@ Playlist::Playlist( intf_thread_t *_p_intf, wxWindow *p_parent ):
     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 );
@@ -349,7 +358,7 @@ Playlist::Playlist( intf_thread_t *_p_intf, wxWindow *p_parent ):
     main_sizer->Layout();
     SetSizerAndFit( main_sizer );
 
-#if !defined(__WXX11__)
+#if wxUSE_DRAG_AND_DROP
     /* Associate drop targets with the playlist */
     SetDropTarget( new DragAndDrop( p_intf, VLC_TRUE ) );
 #endif
@@ -392,6 +401,8 @@ Playlist::~Playlist()
 
     delete iteminfo_dialog;
 
+    var_DelCallback( p_playlist, "item-change", ItemChanged, this );
+    var_DelCallback( p_playlist, "playlist-current", PlaylistNext, this );
     var_DelCallback( p_playlist, "intf-change", PlaylistChanged, this );
     vlc_object_release( p_playlist );
 }
@@ -401,26 +412,34 @@ Playlist::~Playlist()
  **********************************************************************/
 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 );
+
     if( p_playlist == NULL )
     {
         return;
     }
-    if( i < 0 || i > p_playlist->i_size )
+
+    playlist_item_t *p_item = playlist_ItemGetByPos( p_playlist, i );
+
+    if( !p_item )
     {
         vlc_object_release(p_playlist);
         return;
     }
-    listview->SetItem( i, 0, wxL2U(p_playlist->pp_items[i]->psz_name) );
-    listview->SetItem( i, 1, wxL2U( playlist_GetInfo( p_playlist, i,
-                                       "General" , "Author" ) ) );
-    listview->SetItem( i, 2,
-             wxL2U(playlist_FindGroup(p_playlist,p_playlist->
-                                    pp_items[i]->i_group) ) );
-
-    if( p_playlist->pp_items[i]->b_enabled == VLC_FALSE )
+
+    listview->SetItem( i, 0, wxL2U(p_item->input.psz_name) );
+    listview->SetItem( i, 1, wxU( playlist_ItemGetInfo( p_item,
+                                       _("General") , _("Author") ) ) );
+    char *psz_group = playlist_FindGroup(p_playlist,
+                                         p_item->i_group);
+    listview->SetItem( i, 3,
+             wxL2U( psz_group ? psz_group : _("Normal") ) );
+
+    if( p_item->b_enabled == VLC_FALSE )
     {
         wxListItem listitem;
         listitem.m_itemId = i;
@@ -429,10 +448,10 @@ void Playlist::UpdateItem( int i )
     }
 
     char psz_duration[MSTRTIME_MAX_SIZE];
-    mtime_t dur = p_playlist->pp_items[i]->i_duration;
+    mtime_t dur = p_item->input.i_duration;
     if( dur != -1 ) secstotimestr( psz_duration, dur/1000000 );
     else memcpy( psz_duration , "-:--:--", sizeof("-:--:--") );
-    listview->SetItem( i, 3, wxU(psz_duration) );
+    listview->SetItem( i, 2, wxU(psz_duration) );
 
     /* Change the colour for the currenty played stream */
     wxListItem listitem;
@@ -472,18 +491,18 @@ void Playlist::Rebuild()
     vlc_mutex_lock( &p_playlist->object_lock );
     for( int i = 0; i < p_playlist->i_size; i++ )
     {
-        wxString filename = wxL2U(p_playlist->pp_items[i]->psz_name);
+        wxString filename = wxL2U(p_playlist->pp_items[i]->input.psz_name);
         listview->InsertItem( i, filename );
         UpdateItem( i );
     }
     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 );
     }
@@ -499,22 +518,14 @@ void Playlist::ShowPlaylist( bool show )
 
 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();
     }
 
@@ -530,12 +541,11 @@ void Playlist::UpdatePlaylist()
     }
 
     /* 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 );
 
@@ -545,9 +555,9 @@ void Playlist::UpdatePlaylist()
             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 );
 }
 
@@ -577,23 +587,51 @@ void Playlist::OnClose( wxCommandEvent& WXUNUSED(event) )
 
 void Playlist::OnSave( wxCommandEvent& WXUNUSED(event) )
 {
-    playlist_t *p_playlist =
-        (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
-                                       FIND_ANYWHERE );
-    if( p_playlist == NULL )
+    struct {
+        char *psz_desc;
+        char *psz_filter;
+        char *psz_module;
+    } formats[] = {{ _("M3U file"), "*.m3u", "export-m3u" },
+                   { _("PLS file"), "*.pls", "export-pls" }};
+    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;
+    }
 
+    for( unsigned int i = 0; i < sizeof(formats)/sizeof(formats[0]); i++)
+    {
+        filter.Append( wxU(formats[i].psz_desc) );
+        filter.Append( wxT("|") );
+        filter.Append( wxU(formats[i].psz_filter) );
+        filter.Append( wxT("|") );
+    }
     wxFileDialog dialog( this, wxU(_("Save playlist")),
-                         wxT(""), wxT(""), wxT("*"), wxSAVE );
+                         wxT(""), wxT(""), filter, wxSAVE );
 
     if( dialog.ShowModal() == wxID_OK )
     {
-        playlist_SaveFile( p_playlist, dialog.GetPath().mb_str() );
+        if( dialog.GetPath().mb_str() )
+        {
+            playlist_Export( p_playlist, dialog.GetPath().mb_str(),
+                             formats[dialog.GetFilterIndex()].psz_module );
+        }
     }
 
     vlc_object_release( p_playlist );
+
 }
 
 void Playlist::OnOpen( wxCommandEvent& WXUNUSED(event) )
@@ -606,12 +644,12 @@ void Playlist::OnOpen( wxCommandEvent& WXUNUSED(event) )
         return;
     }
 
-    wxFileDialog dialog( this, wxU(_("Open playlist")),
-                         wxT(""), wxT(""), wxT("*"), 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 )
     {
-        playlist_LoadFile( p_playlist, dialog.GetPath().mb_str() );
+        playlist_Import( p_playlist, dialog.GetPath().mb_str() );
     }
 
     vlc_object_release( p_playlist );
@@ -638,7 +676,7 @@ void Playlist::OnAddMRL( wxCommandEvent& WXUNUSED(event) )
 /********************************************************************
  * 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,
@@ -649,25 +687,18 @@ void Playlist::OnUp( wxCommandEvent& event)
     }
 
     /* 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,
@@ -678,7 +709,7 @@ void Playlist::OnDown( wxCommandEvent& event)
     }
 
     /* 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 )
     {
@@ -704,25 +735,25 @@ void Playlist::OnSort( wxCommandEvent& event )
     switch( event.GetId() )
     {
         case SortTitle_Event:
-           playlist_SortTitle( p_playlist , 0 );
+           playlist_SortTitle( p_playlist , ORDER_NORMAL );
            break;
         case RSortTitle_Event:
-           playlist_SortTitle( p_playlist , 1 );
+           playlist_SortTitle( p_playlist , ORDER_REVERSE );
            break;
         case SortAuthor_Event:
-           playlist_SortAuthor(p_playlist , 0 );
+           playlist_SortAuthor(p_playlist , ORDER_NORMAL );
            break;
         case RSortAuthor_Event:
-           playlist_SortAuthor( p_playlist , 1 );
+           playlist_SortAuthor( p_playlist , ORDER_REVERSE );
            break;
         case SortGroup_Event:
-           playlist_SortGroup( p_playlist , 0 );
+           playlist_SortGroup( p_playlist , ORDER_NORMAL );
            break;
         case RSortGroup_Event:
-           playlist_SortGroup( p_playlist , 1 );
+           playlist_SortGroup( p_playlist , ORDER_REVERSE );
            break;
         case Randomize_Event:
-           playlist_Sort( p_playlist , SORT_RANDOM, SORT_NORMAL );
+           playlist_Sort( p_playlist , SORT_RANDOM, ORDER_NORMAL );
            break;
     }
     vlc_object_release( p_playlist );
@@ -746,36 +777,48 @@ void Playlist::OnColSelect( wxListEvent& event )
         case 0:
             if( i_title_sorted != 1 )
             {
-                playlist_SortTitle( p_playlist, 0 );
+                playlist_SortTitle( p_playlist, ORDER_NORMAL );
                 i_title_sorted = 1;
             }
             else
             {
-                playlist_SortTitle( p_playlist, 1 );
+                playlist_SortTitle( p_playlist, ORDER_REVERSE );
                 i_title_sorted = -1;
             }
             break;
         case 1:
             if( i_author_sorted != 1 )
             {
-                playlist_SortAuthor( p_playlist, 0 );
+                playlist_SortAuthor( p_playlist, ORDER_NORMAL );
                 i_author_sorted = 1;
             }
             else
             {
-                playlist_SortAuthor( p_playlist, 1 );
+                playlist_SortAuthor( p_playlist, ORDER_REVERSE );
                 i_author_sorted = -1;
             }
             break;
         case 2:
+            if( i_duration_sorted != 1 )
+            {
+                playlist_Sort( p_playlist, SORT_DURATION, ORDER_NORMAL );
+                i_duration_sorted = 1;
+            }
+            else
+            {
+                playlist_Sort( p_playlist, SORT_DURATION, ORDER_REVERSE );
+                i_duration_sorted = -1;
+            }
+            break;
+        case 3:
             if( i_group_sorted != 1 )
             {
-                playlist_SortGroup( p_playlist, 0 );
+                playlist_SortGroup( p_playlist, ORDER_NORMAL );
                 i_group_sorted = 1;
             }
             else
             {
-                playlist_SortGroup( p_playlist, 1 );
+                playlist_SortGroup( p_playlist, ORDER_REVERSE );
                 i_group_sorted = -1;
             }
             break;
@@ -799,24 +842,30 @@ void Playlist::OnSearchTextChange( wxCommandEvent& WXUNUSED(event) )
 
 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 );
@@ -824,9 +873,45 @@ void Playlist::OnSearch( wxCommandEvent& WXUNUSED(event) )
         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 );
@@ -879,6 +964,7 @@ void Playlist::OnEnableSelection( wxCommandEvent& WXUNUSED(event) )
     {
         if( listview->IsSelected( item ) )
         {
+            /*XXX*/
             playlist_Enable( p_playlist, item );
             UpdateItem( item );
         }
@@ -900,6 +986,7 @@ void Playlist::OnDisableSelection( wxCommandEvent& WXUNUSED(event) )
     {
         if( listview->IsSelected( item ) )
         {
+            /*XXX*/
             playlist_Disable( p_playlist, item );
             UpdateItem( item );
         }
@@ -932,6 +1019,7 @@ void Playlist::OnRandom( wxCommandEvent& event )
     var_Set( p_playlist , "random", val);
     vlc_object_release( p_playlist );
 }
+
 void Playlist::OnLoop ( wxCommandEvent& event )
 {
     vlc_value_t val;
@@ -973,6 +1061,7 @@ void Playlist::OnActivateItem( wxListEvent& event )
     {
         return;
     }
+
     playlist_Goto( p_playlist, event.GetIndex() );
 
     vlc_object_release( p_playlist );
@@ -998,12 +1087,22 @@ void Playlist::ShowInfos( int i_item )
     {
         return;
     }
+   
+    if( i_item == -1 )
+    {
+        return;
+    }
     if( iteminfo_dialog == NULL )
     {
-        if( i_item >= 0 && i_item < p_playlist->i_size )
+        vlc_mutex_lock( &p_playlist->object_lock);
+        playlist_item_t *p_item = playlist_ItemGetByPos( p_playlist, i_item );
+        vlc_mutex_unlock( &p_playlist->object_lock );
+
+        if( p_item )
         {
             iteminfo_dialog = new ItemInfoDialog(
-                              p_intf, p_playlist->pp_items[i_item], this );
+                              p_intf, p_item , this );
             if( iteminfo_dialog->ShowModal()  == wxID_OK )
                 UpdateItem( i_item );
             delete iteminfo_dialog;
@@ -1039,6 +1138,7 @@ void Playlist::OnEnDis( wxCommandEvent& event )
        switch( event.GetId() )
        {
            case EnableGroup_Event:
+               /*XXX*/
                playlist_EnableGroup( p_playlist ,
                                   p_playlist->pp_items[i_item]->i_group );
                break;
@@ -1062,7 +1162,6 @@ void Playlist::OnPopup( wxListEvent& event )
     Playlist::PopupMenu( popup_menu , ScreenToClient( wxGetMousePosition() ) );
 }
 
-
 void Playlist::OnPopupPlay( wxMenuEvent& event )
 {
     playlist_t *p_playlist =
@@ -1112,48 +1211,66 @@ void Playlist::OnPopupInfo( wxMenuEvent& event )
     ShowInfos( i_popup_item );
 }
 
+/*****************************************************************************
+ * Custom events management
+ *****************************************************************************/
+void Playlist::OnPlaylistEvent( wxCommandEvent& event )
+{
+    switch( event.GetId() )
+    {
+    case UpdateItem_Event:
+        UpdateItem( event.GetInt() );
+        break;
+    }
+}
+
 /*****************************************************************************
  * PlaylistChanged: callback triggered by the intf-change playlist variable
  *  We don't rebuild the playlist directly here because we don't want the
  *  caller to block for a too long time.
  *****************************************************************************/
-int PlaylistChanged( vlc_object_t *p_this, const char *psz_variable,
-                     vlc_value_t old_val, vlc_value_t new_val, void *param )
+static int PlaylistChanged( 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;
-    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;
 }
 
 /*****************************************************************************
  * Next: callback triggered by the playlist-current playlist variable
  *****************************************************************************/
-int PlaylistNext( vlc_object_t *p_this, const char *psz_variable,
-                 vlc_value_t old_val, vlc_value_t new_val, void *param )
+static int PlaylistNext( 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;
-    p_playlist_dialog->UpdateItem( old_val.i_int );
-    p_playlist_dialog->UpdateItem( new_val.i_int );
+
+    wxCommandEvent event( wxEVT_PLAYLIST, UpdateItem_Event );
+    event.SetInt( oval.i_int );
+    p_playlist_dialog->AddPendingEvent( event );
+    event.SetInt( nval.i_int );
+    p_playlist_dialog->AddPendingEvent( event );
+
     return 0;
 }
 
-
 /*****************************************************************************
  * ItemChanged: callback triggered by the item-change playlist variable
  *****************************************************************************/
-int ItemChanged( vlc_object_t *p_this, const char *psz_variable,
-                 vlc_value_t old_val, vlc_value_t new_val, void *param )
+static int ItemChanged( vlc_object_t *p_this, const char *psz_variable,
+                        vlc_value_t old_val, vlc_value_t new_val, void *param )
 {
     Playlist *p_playlist_dialog = (Playlist *)param;
-    p_playlist_dialog->UpdateItem( new_val.i_int );
+
+    wxCommandEvent event( wxEVT_PLAYLIST, UpdateItem_Event );
+    event.SetInt( new_val.i_int );
+    p_playlist_dialog->AddPendingEvent( event );
+
     return 0;
 }
 
-
 /***************************************************************************
- * NewGroup
+ * NewGroup Class
  ***************************************************************************/
 NewGroup::NewGroup( intf_thread_t *_p_intf, wxWindow *_p_parent ):
     wxDialog( _p_parent, -1, wxU(_("New Group")), wxDefaultPosition,
@@ -1170,10 +1287,10 @@ NewGroup::NewGroup( intf_thread_t *_p_intf, wxWindow *_p_parent ):
 
     wxStaticText *group_label =
             new wxStaticText( panel , -1,
-                wxU(_("Enter a name for the new group")));
+                wxU(_("Enter a name for the new group:")));
 
     groupname = new wxTextCtrl(panel, -1, wxU(""),wxDefaultPosition,
-                               wxSize(80,27),wxTE_PROCESS_ENTER);
+                               wxSize(100,27),wxTE_PROCESS_ENTER);
 
     wxButton *ok_button = new wxButton(panel, wxID_OK, wxU(_("OK")) );
     ok_button->SetDefault();
@@ -1218,9 +1335,9 @@ void NewGroup::OnOk( wxCommandEvent& event )
         {
             psz_name = NULL;
         }
+        vlc_object_release( p_playlist );
     }
 
-    vlc_object_release( p_playlist );
     EndModal( wxID_OK );
 }