]> git.sesse.net Git - vlc/commitdiff
Fix #1768
authorRémi Duraffort <ivoire@videolan.org>
Fri, 22 Aug 2008 21:50:13 +0000 (23:50 +0200)
committerRémi Duraffort <ivoire@videolan.org>
Fri, 22 Aug 2008 21:55:11 +0000 (23:55 +0200)
modules/gui/qt4/components/playlist/playlist_model.cpp
src/playlist/item.c

index 2a55d951a71967626fc0a8abf84bfb0c200d1a9a..f09a4a7abe53e0983c9722b97bd6fe5b4b523edc 100644 (file)
@@ -191,7 +191,8 @@ bool PLModel::dropMimeData( const QMimeData *data, Qt::DropAction action,
                 }
                 for( i = 0 ; i< p_parent->i_children ; i++ )
                     if( p_parent->pp_children[i] == p_target ) break;
-                playlist_TreeMove( p_playlist, p_src, p_parent, i );
+                // Move the item to the element after i
+                playlist_TreeMove( p_playlist, p_src, p_parent, i + 1 );
                 newParentItem = parentItem;
             }
             else
@@ -201,25 +202,10 @@ bool PLModel::dropMimeData( const QMimeData *data, Qt::DropAction action,
                 i = 0;
                 newParentItem = targetItem;
             }
-            /* Remove from source */
-            PLItem *srcItem = FindById( rootItem, p_src->i_id );
-            // We dropped on the source selector. Ask the dialog to forward
-            // to the main view
-            if( !srcItem )
-            {
-                emit shouldRemove( p_src->i_id );
-            }
-            else
-                srcItem->remove( srcItem );
-
-            /* Display at new destination */
-            PLItem *newItem = new PLItem( p_src, newParentItem, this );
-            newParentItem->insertChild( newItem, i, true );
-            UpdateTreeItem( p_src, newItem, true );
-            if( p_src->i_children != -1 )
-                UpdateNodeChildren( newItem );
             PL_UNLOCK;
         }
+        /*TODO: That's not a good idea to rebuild the playlist */
+        rebuild();
     }
     return true;
 }
index 70924e44428482932826de8a7bc669405e46d8f4..eba3006f69bd1a9ba68ee15741f488166b9ca632 100644 (file)
@@ -697,6 +697,13 @@ static int TreeMove( playlist_t *p_playlist, playlist_item_t *p_item,
     }
     REMOVE_ELEM( p_detach->pp_children, p_detach->i_children, j );
 
+    /* If j < i_newpos, we are moving the element from the top to the
+     * down of the playlist. So when removing the element we change have
+     * to change the position as we loose one element
+     */
+    if( j < i_newpos )
+        i_newpos--;
+
     /* Attach to new parent */
     INSERT_ELEM( p_node->pp_children, p_node->i_children, i_newpos, p_item );
     p_item->p_parent = p_node;
@@ -742,7 +749,7 @@ int playlist_TreeMove( playlist_t * p_playlist, playlist_item_t *p_item,
                                                 p_playlist->p_root_onelevel,
                                                 false );
             if( p_node_onelevel && p_item_onelevel )
-                TreeMove( p_playlist, p_item_onelevel, p_node_onelevel, 0 );
+                TreeMove( p_playlist, p_item_onelevel, p_node_onelevel, i_newpos );
         }
         {
             playlist_item_t *p_node_category;
@@ -756,7 +763,7 @@ int playlist_TreeMove( playlist_t * p_playlist, playlist_item_t *p_item,
                                                 p_playlist->p_root_category,
                                                 false );
             if( p_node_category && p_item_category )
-                TreeMove( p_playlist, p_item_category, p_node_category, 0 );
+                TreeMove( p_playlist, p_item_category, p_node_category, i_newpos );
         }
         i_ret = VLC_SUCCESS;
     }