]> git.sesse.net Git - vlc/blobdiff - modules/gui/qt4/components/playlist/playlist_model.cpp
Qt4: don't do playlist_model recursive remove as core signals for those anyway
[vlc] / modules / gui / qt4 / components / playlist / playlist_model.cpp
index c3c960e16f6e6315f9965d9bfe2a05fd5d671321..c86a70108617be20425f6af4a79fe1de9c36c26a 100644 (file)
@@ -197,14 +197,14 @@ bool PLModel::dropMimeData( const QMimeData *data, Qt::DropAction action,
     if( plMimeData )
     {
         if( copy )
-            dropAppendCopy( plMimeData, getItem( parent ) );
+            dropAppendCopy( plMimeData, getItem( parent ), row );
         else
             dropMove( plMimeData, getItem( parent ), row );
     }
     return true;
 }
 
-void PLModel::dropAppendCopy( const PlMimeData *plMimeData, PLItem *target )
+void PLModel::dropAppendCopy( const PlMimeData *plMimeData, PLItem *target, int pos )
 {
     PL_LOCK;
 
@@ -212,49 +212,20 @@ void PLModel::dropAppendCopy( const PlMimeData *plMimeData, PLItem *target )
             playlist_ItemGetByInput( p_playlist, target->p_input );
     if( !p_parent ) return;
 
-    bool b_flat = p_parent == p_playlist->p_playing &&
-                  !var_InheritBool( p_intf, "playlist-tree" );
+    if( pos == -1 ) pos = PLAYLIST_END;
 
     QList<input_item_t*> inputItems = plMimeData->inputItems();
+
     foreach( input_item_t* p_input, inputItems )
     {
         playlist_item_t *p_item = playlist_ItemGetByInput( p_playlist, p_input );
         if( !p_item ) continue;
-
-        recursiveAppendCopy( p_playlist, p_item, p_parent, b_flat );
+        pos = playlist_NodeAddCopy( p_playlist, p_item, p_parent, pos );
     }
 
     PL_UNLOCK;
 }
 
-/* Must be entered WITH playlist lock! */
-void PLModel::recursiveAppendCopy( playlist_t *p_playlist, playlist_item_t *source,
-                                   playlist_item_t *target, bool b_flat )
-{
-    input_item_t *srcInput = source->p_input;
-
-    if( !(source->i_children != -1 && b_flat) )
-    {
-        vlc_mutex_lock( &srcInput->lock );
-        input_item_t *newInput =
-            input_item_NewWithType( VLC_OBJECT(p_playlist),
-                                    srcInput->psz_uri, srcInput->psz_name,
-                                    srcInput->i_options, srcInput->ppsz_options,
-                                    srcInput->optflagc, srcInput->i_duration,
-                                    srcInput->i_type );
-        vlc_mutex_unlock( &srcInput->lock );
-
-        if( source->i_children != -1 )
-            target = playlist_NodeCreate( p_playlist, newInput->psz_name, target, 0, newInput );
-        else
-            playlist_NodeAddInput( p_playlist, newInput, target,
-                                   PLAYLIST_APPEND | PLAYLIST_SPREPARSE,
-                                   PLAYLIST_END, pl_Locked );
-    }
-    for( int i = 0; i < source->i_children; i++ )
-        recursiveAppendCopy( p_playlist, source->pp_children[i], target, b_flat );
-}
-
 void PLModel::dropMove( const PlMimeData * plMimeData, PLItem *target, int row )
 {
     QList<input_item_t*> inputItems = plMimeData->inputItems();
@@ -808,10 +779,8 @@ void PLModel::updateTreeItem( PLItem *item )
 /************************* Actions ******************************/
 
 /**
- * Deletion, here we have to do a ugly slow hack as we retrieve the full
- * list of indexes to delete at once: when we delete a node and all of
- * its children, we need to update the list.
- * Todo: investigate whethere we can use ranges to be sure to delete all items?
+ * Lets not worry about nodes children, we do refersh anyway when
+ * core tells that playlist has changed, should give some more speed
  */
 void PLModel::doDelete( QModelIndexList selected )
 {
@@ -825,8 +794,6 @@ void PLModel::doDelete( QModelIndexList selected )
         if( index.column() != 0 ) continue;
 
         PLItem *item = getItem( index );
-        if( item->children.size() )
-            recurseDelete( item->children, &selected );
 
         PL_LOCK;
         playlist_DeleteFromInput( p_playlist, item->p_input, pl_Locked );
@@ -893,6 +860,15 @@ void PLModel::sort( int i_root_id, int column, Qt::SortOrder order )
         endInsertRows( );
     }
     PL_UNLOCK;
+    /* if we have popup item, try to make sure that you keep that item visible */
+    if( i_popup_item > -1 )
+    {
+        PLItem *popupitem = findById( rootItem, i_popup_item );
+        if( popupitem ) emit currentChanged( index( popupitem, 0 ) );
+        /* reset i_popup_item as we don't show it as selected anymore anyway */
+        i_popup_item = -1;
+    }
+    else if( currentIndex().isValid() ) emit currentChanged( currentIndex() );
 }
 
 void PLModel::search( const QString& search_text, const QModelIndex & idx, bool b_recursive )
@@ -1109,7 +1085,7 @@ void PLModel::popupAddNode()
                                                     i_popup_parent );
     if( p_item )
     {
-        playlist_NodeCreate( p_playlist, qtu( name ), p_item, 0, NULL );
+        playlist_NodeCreate( p_playlist, qtu( name ), p_item, PLAYLIST_END, 0, NULL );
     }
     PL_UNLOCK;
 }