]> git.sesse.net Git - vlc/blobdiff - modules/gui/wxwidgets/dialogs/playlist.cpp
* Do not take and release the structure lock for each element of the list while
[vlc] / modules / gui / wxwidgets / dialogs / playlist.cpp
index be17e11f46261409f316072c9a96c3c3b8777506..249b51b807a6c42f40387f2fb4f6c1cb772f4ae2 100644 (file)
@@ -47,7 +47,7 @@
 #include <wx/imaglist.h>
 
 #include <vlc_meta.h>
-#include "charset.h"
+#include "vlc_charset.h"
 
 #define HELP_SHUFFLE N_( "Shuffle" )
 #define HELP_LOOP N_( "Repeat All" )
@@ -505,7 +505,7 @@ void Playlist::UpdateTreeItem( wxTreeItemId item )
     if( !p_data ) return;
 
     playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
-                                          ((PlaylistItem *)p_data)->i_id );
+                                    ((PlaylistItem *)p_data)->i_id, VLC_TRUE );
     if( !p_item )
     {
         UnlockPlaylist( p_intf->p_sys, p_playlist );
@@ -515,15 +515,15 @@ void Playlist::UpdateTreeItem( wxTreeItemId item )
     wxString msg;
     wxString duration = wxU( "" );
 
-    char *psz_author;
+    char *psz_artist;
     if( p_item->p_input->p_meta )
     {
-        psz_author= p_item->p_input->p_meta->psz_artist ?
+        psz_artist= p_item->p_input->p_meta->psz_artist ?
                         strdup( p_item->p_input->p_meta->psz_artist ) :
                         strdup("");
     }
     else
-        psz_author = strdup( "" );
+        psz_artist = strdup( "" );
 
     char psz_duration[MSTRTIME_MAX_SIZE];
     mtime_t dur = p_item->p_input->i_duration;
@@ -535,16 +535,16 @@ void Playlist::UpdateTreeItem( wxTreeItemId item )
                          wxU( " )" ) );
     }
 
-    if( !strcmp( psz_author, "" ) || p_item->p_input->b_fixed_name == VLC_TRUE )
+    if( !strcmp( psz_artist, "" ) || p_item->p_input->b_fixed_name == VLC_TRUE )
     {
         msg = wxString( wxU( p_item->p_input->psz_name ) ) + duration;
     }
     else
     {
-        msg = wxString(wxU( psz_author )) + wxT(" - ") +
+        msg = wxString(wxU( psz_artist )) + wxT(" - ") +
               wxString(wxU(p_item->p_input->psz_name)) + duration;
     }
-    free( psz_author );
+    free( psz_artist );
     treectrl->SetItemText( item , msg );
     treectrl->SetItemImage( item, p_item->p_input->i_type );
 
@@ -581,7 +581,7 @@ void Playlist::AppendItem( wxCommandEvent& event )
     node = FindItem( treectrl->GetRootItem(), p_add->i_node );
     if( !node.IsOk() ) goto update;
 
-    p_item = playlist_ItemGetById( p_playlist, p_add->i_item );
+    p_item = playlist_ItemGetById( p_playlist, p_add->i_item, VLC_TRUE );
     if( !p_item ) goto update;
     if( (p_item->i_flags & PLAYLIST_DBL_FLAG ) ) goto update;
 
@@ -744,7 +744,7 @@ int Playlist::CountItems( wxTreeItemId root )
         {
             playlist_item_t *p_item;
             LockPlaylist( p_intf->p_sys, p_playlist );
-            p_item = playlist_ItemGetById( p_playlist, ((PlaylistItem *)treectrl->GetItemData( item ))->i_id );
+            p_item = playlist_ItemGetById( p_playlist, ((PlaylistItem *)treectrl->GetItemData( item ))->i_id, VLC_TRUE );
             if( p_item && p_item->i_children == -1 )
                 count++;
             UnlockPlaylist( p_intf->p_sys, p_playlist );
@@ -890,7 +890,7 @@ void Playlist::DeleteTreeItem( wxTreeItemId item )
    p_wxitem = (PlaylistItem *)treectrl->GetItemData( item );
 
    LockPlaylist( p_intf->p_sys, p_playlist );
-   p_item = playlist_ItemGetById( p_playlist, p_wxitem->i_id );
+   p_item = playlist_ItemGetById( p_playlist, p_wxitem->i_id, VLC_TRUE );
 
    if( !p_item )
    {
@@ -907,7 +907,7 @@ void Playlist::DeleteTreeItem( wxTreeItemId item )
 
 void Playlist::DeleteItem( int item_id )
 {
-    playlist_DeleteAllFromInput( p_playlist, item_id );
+    playlist_DeleteFromInput( p_playlist, item_id, VLC_TRUE );
 }
 
 void Playlist::DeleteNode( playlist_item_t *p_item )
@@ -938,7 +938,7 @@ void Playlist::OnSave( wxCommandEvent& WXUNUSED(event) )
 
     wxString filter = wxT("");
 
-    if( p_playlist->i_size == 0 )
+    if( playlist_IsEmpty( p_playlist ) )
     {
         wxMessageBox( wxU(_("Playlist is empty") ), wxU(_("Can't save")),
                       wxICON_WARNING | wxOK, this );
@@ -957,12 +957,12 @@ void Playlist::OnSave( wxCommandEvent& WXUNUSED(event) )
 
     if( dialog.ShowModal() == wxID_OK )
     {
-        if( dialog.GetPath().mb_str() )
+        if( dialog.GetPath().mb_str(wxConvUTF8) )
         {
             /* what root should we export? */
             if( p_playlist->p_root_category->i_children > 0 )
             {
-                playlist_Export( p_playlist, dialog.GetPath().mb_str(),
+                playlist_Export( p_playlist, dialog.GetPath().mb_str(wxConvUTF8),
                                  p_playlist->p_root_category->pp_children[0],
                                  formats[dialog.GetFilterIndex()].psz_module );
             }
@@ -978,9 +978,7 @@ void Playlist::OnOpen( wxCommandEvent& WXUNUSED(event) )
 
     if( dialog.ShowModal() == wxID_OK )
     {
-        playlist_Import( p_playlist, dialog.GetPath().mb_str(),
-                         /*FIXME: where do we want to insert ? */
-                         p_playlist->p_local_category, VLC_TRUE );
+        playlist_Import( p_playlist, dialog.GetPath().mb_str(wxConvUTF8) );
     }
 }
 
@@ -1015,12 +1013,14 @@ void Playlist::OnSort( wxCommandEvent& event )
     {
         case SortTitle_Event:
             playlist_RecursiveNodeSort( p_playlist,
-                            playlist_ItemGetById( p_playlist, p_wxitem->i_id ),
+                            playlist_ItemGetById( p_playlist, p_wxitem->i_id,
+                                                  VLC_TRUE ),
                             SORT_TITLE_NODES_FIRST, ORDER_NORMAL );
             break;
         case RSortTitle_Event:
             playlist_RecursiveNodeSort( p_playlist,
-                            playlist_ItemGetById( p_playlist, p_wxitem->i_id ),
+                            playlist_ItemGetById( p_playlist, p_wxitem->i_id,
+                                                  VLC_TRUE ),
                             SORT_TITLE_NODES_FIRST, ORDER_REVERSE );
     }
     UnlockPlaylist( p_intf->p_sys, p_playlist );
@@ -1041,7 +1041,8 @@ void Playlist::OnSearch( wxCommandEvent& WXUNUSED(event) )
     wxString search_string = search_text->GetValue();
     PlaylistItem *p_wxroot;
     p_wxroot = (PlaylistItem *)treectrl->GetItemData( treectrl->GetRootItem() );
-    playlist_item_t *p_root = playlist_ItemGetById( p_playlist, p_wxroot->i_id );
+    playlist_item_t *p_root = playlist_ItemGetById( p_playlist, p_wxroot->i_id,
+                                                    VLC_TRUE );
 
     assert( p_root );
     char *psz_name = wxFromLocale( search_string );
@@ -1058,16 +1059,23 @@ void Playlist::RecursiveDeleteSelection(  wxTreeItemId root )
 {
     wxTreeItemIdValue cookie;
     wxTreeItemId child = treectrl->GetFirstChild( root, cookie );
+    wxTreeItemId nextchild;
+    bool childIsSelected = FALSE;
+    bool nextchildIsSelected = FALSE;
+
+    if( child.IsOk() ) childIsSelected = treectrl->IsSelected( child );
+
     while( child.IsOk() )
     {
-        if( treectrl->ItemHasChildren( child ) )
-        {
-            RecursiveDeleteSelection( child );
-            if( treectrl->IsSelected(child ) ) DeleteTreeItem( child );
-        }
-        else if( treectrl->IsSelected( child ) )
+        nextchild = treectrl->GetNextChild( root, cookie );
+        if( nextchild.IsOk() )
+            nextchildIsSelected = treectrl->IsSelected( nextchild );
+        if( childIsSelected )
             DeleteTreeItem( child );
-        child = treectrl->GetNextChild( root, cookie );
+        else if( treectrl->ItemHasChildren( child ) )
+            RecursiveDeleteSelection( child );
+        child = nextchild;
+        childIsSelected = nextchildIsSelected;
     }
 }
 
@@ -1117,7 +1125,7 @@ void Playlist::OnActivateItem( wxTreeEvent& event )
         UnlockPlaylist( p_intf->p_sys, p_playlist );
         return;
     }
-    p_item = playlist_ItemGetById( p_playlist, p_wxitem->i_id );
+    p_item = playlist_ItemGetById( p_playlist, p_wxitem->i_id, VLC_TRUE );
 
     p_parent = p_item;
     while( p_parent )
@@ -1129,7 +1137,7 @@ void Playlist::OnActivateItem( wxTreeEvent& event )
 
     if( p_parent )
     {
-        playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, p_parent, p_item );
+        playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, VLC_TRUE, p_parent, p_item );
     }
     UnlockPlaylist( p_intf->p_sys, p_playlist );
 }
@@ -1138,7 +1146,7 @@ void Playlist::OnKeyDown( wxTreeEvent& event )
 {
     long keycode = event.GetKeyCode();
     /* Delete selected items */
-    if( keycode == WXK_BACK || keycode == WXK_DELETE )
+    if( keycode == WXK_BACK || keycode == WXK_DELETE || keycode == WXK_NUMPAD_DELETE )
     {
         /* We send a dummy event */
         OnDeleteSelection( event );
@@ -1172,7 +1180,7 @@ void Playlist::OnDragItemEnd( wxTreeEvent& event )
 
     if( !dest_tree_item.IsOk() ) return;
 
-    /* check that we're not trying to move a node into one of it's children */
+    /* check that we're not trying to move a node into one of its children */
     wxTreeItemId parent = dest_tree_item;
     while( parent != treectrl->GetRootItem() )
     {
@@ -1193,9 +1201,9 @@ void Playlist::OnDragItemEnd( wxTreeEvent& event )
     }
 
     playlist_item_t *p_drageditem =
-        playlist_ItemGetById(p_playlist, p_wxdrageditem->i_id );
+        playlist_ItemGetById(p_playlist, p_wxdrageditem->i_id, VLC_TRUE );
     playlist_item_t *p_destitem =
-        playlist_ItemGetById(p_playlist, p_wxdestitem->i_id );
+        playlist_ItemGetById(p_playlist, p_wxdestitem->i_id, VLC_TRUE );
     if( !p_drageditem || !p_destitem )
     {
         UnlockPlaylist( p_intf->p_sys, p_playlist );
@@ -1214,7 +1222,7 @@ void Playlist::OnDragItemEnd( wxTreeEvent& event )
             return;
         }
         playlist_item_t *p_destitem2 =
-            playlist_ItemGetById( p_playlist, p_parent->i_id );
+            playlist_ItemGetById( p_playlist, p_parent->i_id, VLC_TRUE );
         if( !p_destitem2 )
         {
             UnlockPlaylist( p_intf->p_sys, p_playlist );
@@ -1269,13 +1277,13 @@ bool PlaylistFileDropTarget::OnDropFiles( wxCoord x, wxCoord y,
     {
         PlaylistItem *p_plitem =
             (PlaylistItem *)p->treectrl->GetItemData( item );
-        p_dest = playlist_ItemGetById( p->p_playlist, p_plitem->i_id );
+        p_dest = playlist_ItemGetById( p->p_playlist, p_plitem->i_id, VLC_TRUE );
 
         if( p_dest->i_children == -1 )
         {
             /* This is a leaf. Append right after it
              * We thus need to find the parrent node and the position of the
-             * leaf in it's children list */
+             * leaf in its children list */
             wxTreeItemId parent = p->treectrl->GetItemParent( item );
             PlaylistItem *p_parent =
                 (PlaylistItem *)p->treectrl->GetItemData( parent );
@@ -1285,7 +1293,7 @@ bool PlaylistFileDropTarget::OnDropFiles( wxCoord x, wxCoord y,
                 return FALSE;
             }
             playlist_item_t *p_node =
-                playlist_ItemGetById( p->p_playlist, p_parent->i_id );
+                playlist_ItemGetById( p->p_playlist, p_parent->i_id, VLC_TRUE );
             if( !p_node )
             {
                 UnlockPlaylist( p->p_intf->p_sys, p->p_playlist );
@@ -1488,7 +1496,7 @@ void Playlist::OnPopup( wxContextMenuEvent& event )
         treectrl->SelectItem( i_wx_popup_item );
 
         LockPlaylist( p_intf->p_sys, p_playlist );
-        p_item = playlist_ItemGetById( p_playlist, i_popup_item );
+        p_item = playlist_ItemGetById( p_playlist, i_popup_item, VLC_TRUE );
 
         if( !p_item )
         {
@@ -1514,7 +1522,7 @@ void Playlist::OnPopupPlay( wxCommandEvent& event )
 {
     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_item = playlist_ItemGetById( p_playlist, i_popup_item, VLC_TRUE );
 
     p_popup_parent = p_popup_item;
     while( p_popup_parent )
@@ -1526,7 +1534,7 @@ void Playlist::OnPopupPlay( wxCommandEvent& event )
 
     if( p_popup_parent )
     {
-        playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, p_popup_parent,
+        playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, VLC_TRUE, p_popup_parent,
                           p_popup_item );
     }
     UnlockPlaylist( p_intf->p_sys, p_playlist );
@@ -1541,7 +1549,7 @@ 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 );
+    p_popup_item = playlist_ItemGetById( p_playlist, i_popup_item, VLC_TRUE );
 
     if( p_popup_item != NULL )
     {
@@ -1579,7 +1587,7 @@ void Playlist::OnPopupSort( wxCommandEvent& event )
     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 );
+    p_item = playlist_ItemGetById( p_playlist, p_wxitem->i_id, VLC_TRUE );
     if( p_item->i_children >= 0 )
     {
         playlist_RecursiveNodeSort( p_playlist, p_item,
@@ -1596,7 +1604,9 @@ void Playlist::OnPopupSort( wxCommandEvent& 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 );
+    playlist_item_t *p_popup_item = playlist_ItemGetById( p_playlist,
+                                                          i_popup_item,
+                                                          VLC_TRUE );
     if( p_popup_item )
     {
         iteminfo_dialog = new ItemInfoDialog( p_intf, p_popup_item, this );
@@ -1624,9 +1634,9 @@ void Playlist::OnPopupAddNode( wxCommandEvent& event )
 
     p_wxitem = (PlaylistItem *)treectrl->GetItemData( i_wx_popup_item );
 
-    p_item = playlist_ItemGetById( p_playlist, p_wxitem->i_id );
+    p_item = playlist_ItemGetById( p_playlist, p_wxitem->i_id, VLC_TRUE );
 
-    playlist_NodeCreate( p_playlist, psz_name, p_item );
+    playlist_NodeCreate( p_playlist, psz_name, p_item, 0 );
 
     UnlockPlaylist( p_intf->p_sys, p_playlist );
     Rebuild( VLC_TRUE );
@@ -1640,7 +1650,8 @@ void Playlist::OnSourceSelected( wxListEvent &event )
 
    if( p_current_treeroot && i_id != p_current_treeroot->i_id )
    {
-       playlist_item_t *p_item = playlist_ItemGetById( p_playlist, i_id );
+       playlist_item_t *p_item = playlist_ItemGetById( p_playlist, i_id,
+                                                       VLC_TRUE );
        if( p_item ) p_current_treeroot = p_item;
        Rebuild( VLC_TRUE );
    }