]> git.sesse.net Git - vlc/commitdiff
modules/gui/wxwidgets/dialogs/playlist.cpp: add some more checks. Fixes infinite...
authorAntoine Cellerier <dionoea@videolan.org>
Sat, 4 Mar 2006 18:41:08 +0000 (18:41 +0000)
committerAntoine Cellerier <dionoea@videolan.org>
Sat, 4 Mar 2006 18:41:08 +0000 (18:41 +0000)
src/playlist/item-ext.c: detach item from first matching parent node only.

modules/gui/wxwidgets/dialogs/playlist.cpp
src/playlist/item-ext.c

index a232e38329437e64fc7b9c4f620ed5745b65b235..fd9e58574793bd605ab525ec706e4cdf5534e38d 100644 (file)
@@ -1154,6 +1154,8 @@ void Playlist::OnDragItemEnd( wxTreeEvent& event )
 {
     wxTreeItemId dest_tree_item = event.GetItem();
 
+    if( !dest_tree_item.IsOk() ) return;
+
     /* check that we're not trying to move a node into one of it's children */
     wxTreeItemId parent = dest_tree_item;
     while( parent != treectrl->GetRootItem() )
@@ -1162,45 +1164,64 @@ void Playlist::OnDragItemEnd( wxTreeEvent& event )
         parent = treectrl->GetItemParent( parent );
     }
 
-    if( draged_tree_item != dest_tree_item )
-    {
-        LockPlaylist( p_intf->p_sys, p_playlist );
+    LockPlaylist( p_intf->p_sys, p_playlist );
 
-        PlaylistItem *p_wxdrageditem =
-            (PlaylistItem *)treectrl->GetItemData( draged_tree_item );
-        PlaylistItem *p_wxdestitem =
-            (PlaylistItem *)treectrl->GetItemData( dest_tree_item );
+    PlaylistItem *p_wxdrageditem =
+        (PlaylistItem *)treectrl->GetItemData( draged_tree_item );
+    PlaylistItem *p_wxdestitem =
+        (PlaylistItem *)treectrl->GetItemData( dest_tree_item );
+    if( !p_wxdrageditem || !p_wxdestitem )
+    {
+        UnlockPlaylist( p_intf->p_sys, p_playlist );
+        return;
+    }
 
-        playlist_item_t *p_drageditem =
-            playlist_ItemGetById(p_playlist, p_wxdrageditem->i_id );
-        playlist_item_t *p_destitem =
-            playlist_ItemGetById(p_playlist, p_wxdestitem->i_id );
+    playlist_item_t *p_drageditem =
+        playlist_ItemGetById(p_playlist, p_wxdrageditem->i_id );
+    playlist_item_t *p_destitem =
+        playlist_ItemGetById(p_playlist, p_wxdestitem->i_id );
+    if( !p_drageditem || !p_destitem )
+    {
+        UnlockPlaylist( p_intf->p_sys, p_playlist );
+        return;
+    }
 
-        if( p_destitem->i_children == -1 )
-        /* this is a leaf */
+    if( p_destitem->i_children == -1 )
+    /* this is a leaf */
+    {
+        parent = treectrl->GetItemParent( dest_tree_item );
+        PlaylistItem *p_parent =
+            (PlaylistItem *)treectrl->GetItemData( parent );
+        if( !p_parent )
         {
-            parent = treectrl->GetItemParent( dest_tree_item );
-            PlaylistItem *p_parent =
-                (PlaylistItem *)treectrl->GetItemData( parent );
-            playlist_item_t *p_destitem2 =
-                playlist_ItemGetById( p_playlist, p_parent->i_id );
-            int i;
-            for( i = 0; i < p_destitem2->i_children; i++ )
-            {
-                if( p_destitem2->pp_children[i] == p_destitem ) break;
-            }
-            playlist_TreeMove( p_playlist, p_drageditem, p_destitem2,
-                               i, i_current_view );
+            UnlockPlaylist( p_intf->p_sys, p_playlist );
+            return;
         }
-        else
-        /* this is a node */
+        playlist_item_t *p_destitem2 =
+            playlist_ItemGetById( p_playlist, p_parent->i_id );
+        if( !p_destitem2 )
+        {
+            UnlockPlaylist( p_intf->p_sys, p_playlist );
+            return;
+        }
+        int i;
+        for( i = 0; i < p_destitem2->i_children; i++ )
         {
-            playlist_TreeMove( p_playlist, p_drageditem, p_destitem,
-                               0, i_current_view );
+            if( p_destitem2->pp_children[i] == p_destitem ) break;
         }
-        UnlockPlaylist( p_intf->p_sys, p_playlist );
-        Rebuild( VLC_TRUE );
+        playlist_TreeMove( p_playlist, p_drageditem, p_destitem2,
+                           i, i_current_view );
     }
+    else
+    /* this is a node */
+    {
+        playlist_TreeMove( p_playlist, p_drageditem, p_destitem,
+                           0, i_current_view );
+    }
+
+    UnlockPlaylist( p_intf->p_sys, p_playlist );
+
+    Rebuild( VLC_TRUE );
 }
 
 /**********************************************************************
index 920579ec4ee0cfc4b15984d04d78b324dc64c534..17657856a9dc41f6bb76766149c5461f1640bf0b 100644 (file)
@@ -878,6 +878,8 @@ int playlist_Move( playlist_t * p_playlist, int i_pos, int i_newpos )
 /**
  * Moves an item
  *
+ * This function must be entered with the playlist lock
+ *
  * \param p_playlist the playlist
  * \param p_item the item to move
  * \param p_node the new parent of the item
@@ -907,6 +909,7 @@ int playlist_TreeMove( playlist_t * p_playlist, playlist_item_t *p_item,
             p_detach->i_serial++;
             free( p_item->pp_parents[i] );
             REMOVE_ELEM( p_item->pp_parents, p_item->i_parents, i );
+            break;
         }
     }