Qt4 playlist: take 2: fix segfault and other enhancements
authorJakob Leben <jakob.leben@gmail.com>
Wed, 12 Aug 2009 12:19:49 +0000 (14:19 +0200)
committerRémi Denis-Courmont <remi@remlab.net>
Thu, 13 Aug 2009 15:04:39 +0000 (18:04 +0300)
Fix segfault when dropping more then one item onto an item in the left side selector.

Also copy instead of move items when dragging from media library to playlist and the opposite.

Signed-off-by: Rémi Denis-Courmont <remi@remlab.net>
modules/gui/qt4/components/playlist/playlist_model.cpp

index d60c078..4a0ecd4 100644 (file)
@@ -210,6 +210,12 @@ bool PLModel::dropMimeData( const QMimeData *data, Qt::DropAction action,
             return false;
         }
 
+        bool copy = false;
+        if( row == -1 &&
+            ( p_parent->p_input == p_playlist->p_local_category->p_input
+            || p_parent->p_input == p_playlist->p_ml_category->p_input ) )
+                copy = true;
+
         QByteArray encodedData = data->data( "vlc/playlist-item-id" );
         QDataStream stream( &encodedData, QIODevice::ReadOnly );
 
@@ -228,22 +234,27 @@ bool PLModel::dropMimeData( const QMimeData *data, Qt::DropAction action,
                 PL_UNLOCK;
                 return false;
             }
+            if( copy )
+            {
+                input_item_t *input = p_src->p_input;
+                playlist_AddExt ( p_playlist,
+                    p_src->p_input->psz_uri, p_src->p_input->psz_name,
+                    PLAYLIST_APPEND | PLAYLIST_SPREPARSE, PLAYLIST_END,
+                    input->i_duration,
+                    input->i_options, input->ppsz_options, input->optflagc,
+                    p_parent == p_playlist->p_local_category, true );
+                continue;
+            }
             if( !p_target )
             {
-                if(row == -1)
-                {
-                    playlist_TreeMove( p_playlist, p_src, p_parent, 0 );
-                }
-                else {
-                    playlist_TreeMove( p_playlist, p_src, p_parent, row );
-                }
+                if ( row == -1 ) row = p_parent->i_children;
+                playlist_TreeMove( p_playlist, p_src, p_parent, row );
             }
             else
             {
-                int i;
-                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 + 1 );
+                for( row = 0 ; row < p_target->p_parent->i_children ; row++ )
+                    if( p_target->p_parent->pp_children[row] == p_target ) break;
+                playlist_TreeMove( p_playlist, p_src, p_parent, row + 1 );
             }
             p_target = p_src;
         }