]> git.sesse.net Git - vlc/blobdiff - modules/gui/wxwidgets/dialogs/playlist.cpp
* Protect input item's meta through setters and getters. That allows tracking of...
[vlc] / modules / gui / wxwidgets / dialogs / playlist.cpp
index 0e802839310485f265562e2ab8fdf7b8959dd0a8..4f91dc6fc8301ddeaff6b8d10e1da6db66f1b269 100644 (file)
@@ -226,9 +226,8 @@ Playlist::Playlist( intf_thread_t *_p_intf, wxWindow *p_parent ):
     p_view_menu = NULL;
     p_sd_menu = SDMenu();
 
-//    i_current_view = VIEW_ONELEVEL;
-    p_current_viewroot = p_playlist->p_root_onelevel;
-    p_current_treeroot = p_playlist->p_local_onelevel;
+    p_current_viewroot = p_playlist->p_root_category;
+    p_current_treeroot = NULL;
 
     i_title_sorted = 0;
     i_group_sorted = 0;
@@ -367,8 +366,6 @@ Playlist::Playlist( intf_thread_t *_p_intf, wxWindow *p_parent ):
     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(9);
@@ -408,8 +405,8 @@ Playlist::Playlist( intf_thread_t *_p_intf, wxWindow *p_parent ):
     var_AddCallback( p_playlist, "item-deleted", ItemDeleted, this );
 
     /* Update the playlist */
+    p_current_treeroot = p_playlist->p_local_category;
     Rebuild( VLC_TRUE );
-
 }
 
 Playlist::~Playlist()
@@ -516,14 +513,9 @@ void Playlist::UpdateTreeItem( wxTreeItemId item )
     wxString duration = wxU( "" );
 
     char *psz_artist;
-    if( p_item->p_input->p_meta )
-    {
-        psz_artist= p_item->p_input->p_meta->psz_artist ?
-                        strdup( p_item->p_input->p_meta->psz_artist ) :
-                        strdup("");
-    }
-    else
-        psz_artist = strdup( "" );
+    psz_artist = input_item_GetArtist( p_item->p_input ) ?
+                    strdup( input_item_GetArtist( p_item->p_input ) ) :
+                    strdup("");
 
     char psz_duration[MSTRTIME_MAX_SIZE];
     mtime_t dur = p_item->p_input->i_duration;
@@ -799,19 +791,8 @@ void Playlist::Rebuild( vlc_bool_t b_root )
 {
     i_items_to_append = 0;
 
-    /* We can remove the callbacks before locking, anyway, we won't
-     * miss anything */
-    if( b_root )
-    {
-        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 );
+    LockPlaylist( p_intf->p_sys, p_playlist );
 
-        /* ...and rebuild it */
-        LockPlaylist( p_intf->p_sys, p_playlist );
-    }
     /* Invalidate cache */
     i_saved_id = -1;
     i_saved_input_id = -1;
@@ -834,8 +815,6 @@ void Playlist::Rebuild( vlc_bool_t b_root )
                          new PlaylistItem( p_current_treeroot ) );
 
     wxTreeItemId root = treectrl->GetRootItem();
-    //UpdateNode( p_current_treeroot, root );
-    //CreateNode( p_current_treeroot, root );
     UpdateNodeChildren( p_current_treeroot, root );
 
     int i_count = CountItems( treectrl->GetRootItem() );
@@ -843,17 +822,7 @@ void Playlist::Rebuild( vlc_bool_t b_root )
     statusbar->SetStatusText( wxString::Format( wxU(_(
                               "%i items in playlist")), i_count ), 0 );
 
-    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 );
-
-        UnlockPlaylist( p_intf->p_sys, p_playlist );
-    }
+    UnlockPlaylist( p_intf->p_sys, p_playlist );
 }
 
 void Playlist::ShowPlaylist( bool show )
@@ -1059,16 +1028,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;
     }
 }
 
@@ -1139,7 +1115,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 );
@@ -1309,7 +1285,7 @@ bool PlaylistFileDropTarget::OnDropFiles( wxCoord x, wxCoord y,
         input_item_t *p_input = input_ItemNew( p->p_playlist,
                                               psz_utf8, psz_utf8 );
         playlist_NodeAddInput( p->p_playlist, p_input,
-                               p_dest, PLAYLIST_PREPARSE, i_pos );
+                               p_dest, PLAYLIST_PREPARSE, i_pos, VLC_FALSE );
         wxDnDLocaleFree( psz_utf8 );
     }
 
@@ -1435,7 +1411,7 @@ wxMenu *Playlist::SDMenu()
         if( !strcmp( p_parser->psz_capability, "services_discovery" ) )
             i_number++;
     }
-    if( i_number ) pp_sds = (char **)calloc( i_number, sizeof(void *) );
+    if( i_number ) pp_sds = (const char **)calloc( i_number, sizeof(void *) );
 
     i_number = 0;
     for( int i_index = 0; i_index < p_list->i_count; i_index++ )
@@ -1629,7 +1605,7 @@ void Playlist::OnPopupAddNode( wxCommandEvent& event )
 
     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 );
@@ -1641,7 +1617,7 @@ void Playlist::OnSourceSelected( wxListEvent &event )
 {
    int i_id = event.GetData();
 
-   if( p_current_treeroot && i_id != p_current_treeroot->i_id )
+   if( !p_current_treeroot || i_id != p_current_treeroot->i_id )
    {
        playlist_item_t *p_item = playlist_ItemGetById( p_playlist, i_id,
                                                        VLC_TRUE );