]> git.sesse.net Git - vlc/blobdiff - modules/gui/qt4/components/playlist/playlist_model.cpp
Add a parent to avoid leaking the QVLCframe and input_items
[vlc] / modules / gui / qt4 / components / playlist / playlist_model.cpp
index 6d4fc637865ac09857597fca169b762e029ddade..8edada7dcc01c31b6270883b8264e07fc5dff47e 100644 (file)
@@ -29,6 +29,7 @@
 #include "dialogs_provider.hpp"
 #include "components/playlist/playlist_model.hpp"
 #include "dialogs/mediainfo.hpp"
+#include "dialogs/playlist.hpp"
 #include <vlc_intf_strings.h>
 
 #include "pixmaps/types/type_unknown.xpm"
@@ -149,11 +150,11 @@ bool PLModel::dropMimeData( const QMimeData *data, Qt::DropAction action,
         if( action == Qt::IgnoreAction )
             return true;
 
-        PLItem *targetItem;
-        if( target.isValid() )
-            targetItem = static_cast<PLItem*>( target.internalPointer() );
-        else
-            targetItem = rootItem;
+        if( !target.isValid() )
+            /* We don't want to move on an invalid position */
+            return true;
+
+        PLItem *targetItem = static_cast<PLItem*>( target.internalPointer() );
 
         QByteArray encodedData = data->data( "vlc/playlist-item-id" );
         QDataStream stream( &encodedData, QIODevice::ReadOnly );
@@ -191,7 +192,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 +203,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;
 }
@@ -913,6 +900,8 @@ void PLModel::popupInfo()
     if( p_item )
     {
         MediaInfoDialog *mid = new MediaInfoDialog( p_intf, p_item->p_input );
+        mid->setParent( PlaylistDialog::getInstance( p_intf ),
+                        Qt::Dialog );
         mid->show();
     }
 }
@@ -946,9 +935,19 @@ void PLModel::popupExplore()
        char *psz_meta = input_item_GetURI( p_input );
        if( psz_meta )
        {
-           /* FIXME add a MRLSplit like function */
-           QFileInfo info( qfu( psz_meta ) );
-           QDesktopServices::openUrl( QUrl::fromLocalFile( info.absolutePath() ) );
+           const char *psz_access;
+           const char *psz_demux;
+           char  *psz_path;
+           input_SplitMRL( &psz_access, &psz_demux, &psz_path, psz_meta );
+
+           if( EMPTY_STR( psz_access ) ||
+               !strncasecmp( psz_access, "file", 4 ) ||
+               !strncasecmp( psz_access, "dire", 4 ) )
+           {
+               QFileInfo info( qfu( psz_meta ) );
+               QDesktopServices::openUrl(
+                               QUrl::fromLocalFile( info.absolutePath() ) );
+           }
            free( psz_meta );
        }
     }