]> git.sesse.net Git - vlc/blobdiff - modules/gui/qt4/playlist_model.cpp
CodingStyle fixes, use ; when using macros and do not write it in the macro definition.
[vlc] / modules / gui / qt4 / playlist_model.cpp
index 3e295310ce48ec4015cdf13074762cf5536aa244..3c1932917640ac02e2627699083c23e73b2c07b5 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * playlist_model.cpp : Manage playlist model
  ****************************************************************************
- * Copyright (C) 2006 the VideoLAN team
+ * Copyright (C) 2006-2007 the VideoLAN team
  * $Id$
  *
  * Authors: ClĂ©ment Stenac <zorglub@videolan.org>
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
+#include <assert.h>
 #include <QIcon>
 #include <QFont>
-#include "qt4.hpp"
+#include <QMenu>
 #include <QApplication>
+
+#include "qt4.hpp"
 #include "playlist_model.hpp"
-#include <assert.h>
-#include <QMenu>
+#include "dialogs/mediainfo.hpp"
 #include <vlc_intf_strings.h>
 
 #include "pixmaps/type_unknown.xpm"
-#include "pixmaps/type_afile.xpm"
-#include "pixmaps/type_vfile.xpm"
-#include "pixmaps/type_net.xpm"
-#include "pixmaps/type_card.xpm"
-#include "pixmaps/type_disc.xpm"
-#include "pixmaps/type_cdda.xpm"
-#include "pixmaps/type_directory.xpm"
-#include "pixmaps/type_playlist.xpm"
-#include "pixmaps/type_node.xpm"
 
 QIcon PLModel::icons[ITEM_TYPE_NUMBER];
 
@@ -65,18 +58,72 @@ static int ItemDeleted( vlc_object_t *p_this, const char *psz_variable,
  *      Duration
  */
 
-void PLItem::init( int _i_id, int _i_input_id, PLItem *parent, PLModel *m)
+void PLItem::init( int _i_id, int _i_input_id, PLItem *parent, PLModel *m )
 {
     parentItem = parent;
     i_id = _i_id; i_input_id = _i_input_id;
     model = m;
-    strings.append( "" );
-    strings.append( "" );
-    strings.append( "" );
-    strings.append( "" );
+
+    if( parentItem == NULL )
+    {
+        i_showflags = config_GetInt( model->p_intf , "qt-pl-showflags" );
+        updateview();
+    } else {
+        i_showflags = parentItem->i_showflags;
+        //Add empty string and update() handles data appending
+        strings.append( "" );
+    }
+}
+
+void PLItem::updateview( void )
+{
+    strings.clear();
+
+    if( model->i_depth == 1 )  //left window for playlist etc.
+    {
+        strings.append( "" );
+        return;
+    }
+
+    for( int i_index=1; i_index <= VLC_META_ENGINE_ART_URL; i_index = i_index*2 )
+    {
+        if( i_showflags & i_index )
+        {
+            switch( i_index )
+            {
+            case VLC_META_ENGINE_ARTIST:
+                strings.append( qtr( VLC_META_ARTIST ) );
+                break;
+            case VLC_META_ENGINE_TITLE:
+                strings.append( qtr( VLC_META_TITLE ) );
+                break;
+            case VLC_META_ENGINE_DESCRIPTION:
+                strings.append( qtr( VLC_META_DESCRIPTION ) );
+                break;
+            case VLC_META_ENGINE_DURATION:
+                strings.append( qtr( "Duration" ) );
+                break;
+            case VLC_META_ENGINE_GENRE:
+                strings.append( qtr( VLC_META_GENRE ) );
+                break;
+            case VLC_META_ENGINE_COLLECTION:
+                strings.append( qtr( VLC_META_COLLECTION ) );
+                break;
+            case VLC_META_ENGINE_SEQ_NUM:
+                strings.append( qtr( VLC_META_SEQ_NUM ) );
+                break;
+            case VLC_META_ENGINE_RATING:
+                strings.append( qtr( VLC_META_RATING ) );
+                break;
+            default:
+                break;
+            }
+        }
+    }
 }
 
-PLItem::PLItem( int _i_id, int _i_input_id, PLItem *parent, PLModel *m)
+
+PLItem::PLItem( int _i_id, int _i_input_id, PLItem *parent, PLModel *m )
 {
     init( _i_id, _i_input_id, parent, m );
 }
@@ -88,7 +135,7 @@ PLItem::PLItem( playlist_item_t * p_item, PLItem *parent, PLModel *m )
 
 PLItem::~PLItem()
 {
-    qDeleteAll(children);
+    qDeleteAll( children );
     children.clear();
 }
 
@@ -97,7 +144,7 @@ void PLItem::insertChild( PLItem *item, int i_pos, bool signal )
     assert( model );
     if( signal )
         model->beginInsertRows( model->index( this , 0 ), i_pos, i_pos );
-    children.append( item );
+    children.insert( i_pos, item );
     if( signal )
         model->endInsertRows();
 }
@@ -114,7 +161,7 @@ void PLItem::remove( PLItem *removed )
 int PLItem::row() const
 {
     if( parentItem )
-        return parentItem->children.indexOf(const_cast<PLItem*>(this));
+        return parentItem->children.indexOf( const_cast<PLItem*>(this) );
     return 0;
 }
 
@@ -122,27 +169,93 @@ void PLItem::update( playlist_item_t *p_item, bool iscurrent )
 {
     char psz_duration[MSTRTIME_MAX_SIZE];
     assert( p_item->p_input->i_id == i_input_id );
-    strings[0] = QString::fromUtf8( p_item->p_input->psz_name );
-    if( p_item->p_input->p_meta )
-    {
-        strings[1] = QString::fromUtf8( p_item->p_input->p_meta->psz_artist );
-    }
-    secstotimestr( psz_duration, p_item->p_input->i_duration / 1000000 );
-    strings[2] = QString( psz_duration );
+
     type = p_item->p_input->i_type;
     current = iscurrent;
+
+    char *psz_arturl = input_item_GetArtURL( p_item->p_input );
+    if( ( current && psz_arturl ) &&
+        !strncmp( psz_arturl, "file://", 7 ) )
+        model->sendArt( qfu( psz_arturl ) ) ;
+    else if( current )
+        model->removeArt();
+    free( psz_arturl );
+
+    strings.clear();
+
+    if( model->i_depth == 1 )  //left window for playlist etc.
+    {
+        strings.append( qfu( p_item->p_input->psz_name ) );
+        return;
+    }
+
+    char *psz_meta;
+#define ADD_META( item, meta ) \
+      psz_meta = input_item_Get ## meta ( item->p_input ); \
+      strings.append( qfu( psz_meta ) ); \
+      free( psz_meta );
+
+    for( int i_index=1; i_index <= VLC_META_ENGINE_ART_URL; i_index = i_index * 2 )
+    {
+        if( parentItem->i_showflags & i_index )
+        {
+            switch( i_index )
+            {
+            case VLC_META_ENGINE_ARTIST:
+                ADD_META( p_item, Artist );
+                break;
+            case VLC_META_ENGINE_TITLE:
+                char *psz_title, *psz_name;
+                psz_title = input_item_GetTitle( p_item->p_input );
+                psz_name = input_item_GetName( p_item->p_input );
+                if( psz_title )
+                {
+                    ADD_META( p_item, Title );
+                } else {
+                    strings.append( qfu( psz_name ) );
+                }
+                free( psz_title );
+                free( psz_name );
+                break;
+            case VLC_META_ENGINE_DESCRIPTION:
+                ADD_META( p_item, Description );
+                break;
+            case VLC_META_ENGINE_DURATION:
+                secstotimestr( psz_duration,
+                    input_item_GetDuration( p_item->p_input ) / 1000000 );
+                strings.append( QString( psz_duration ) );
+                break;
+            case VLC_META_ENGINE_GENRE:
+                ADD_META( p_item, Genre );
+                break;
+            case VLC_META_ENGINE_COLLECTION:
+                ADD_META( p_item, Album );
+                break;
+            case VLC_META_ENGINE_SEQ_NUM:
+                ADD_META( p_item, TrackNum );
+                break;
+            case VLC_META_ENGINE_RATING:
+                ADD_META( p_item, Rating );
+            default:
+                break;
+            }
+        }
+
+    }
+#undef ADD_META
 }
 
 /*************************************************************************
  * Playlist model implementation
  *************************************************************************/
 
-PLModel::PLModel( playlist_t *_p_playlist,
-                  playlist_item_t * p_root, int _i_depth, QObject *parent)
-                                    : QAbstractItemModel(parent)
+PLModel::PLModel( playlist_t *_p_playlist, intf_thread_t *_p_intf,
+                    playlist_item_t * p_root, int _i_depth, QObject *parent )
+                                    : QAbstractItemModel( parent )
 {
     i_depth = _i_depth;
     assert( i_depth == 1 || i_depth == -1 );
+    p_intf = _p_intf;
     p_playlist= _p_playlist;
     i_items_to_append = 0;
     b_need_update     = false;
@@ -150,30 +263,152 @@ PLModel::PLModel( playlist_t *_p_playlist,
     i_cached_input_id = -1;
     i_popup_item = i_popup_parent = -1;
 
-#define ADD_ICON(type, x) icons[ITEM_TYPE_##type] = QIcon( QPixmap( type_##x##_xpm ) );
-    ADD_ICON( UNKNOWN , unknown );
-    ADD_ICON( AFILE,afile );
-    ADD_ICON( VFILE, vfile );
-    ADD_ICON( DIRECTORY, directory );
-    ADD_ICON( DISC, disc );
-    ADD_ICON( CDDA, cdda );
-    ADD_ICON( CARD, card );
-    ADD_ICON( NET, net );
-    ADD_ICON( PLAYLIST, playlist );
-    ADD_ICON( NODE, node );
+#define ADD_ICON(type, x) icons[ITEM_TYPE_##type] = QIcon( QPixmap( x ) );
+    ADD_ICON( UNKNOWN , type_unknown_xpm );
+    ADD_ICON( FILE, ":/pixmaps/type_file.png" );
+    ADD_ICON( DIRECTORY, ":/pixmaps/type_directory.png" );
+    ADD_ICON( DISC, ":/pixmaps/disc_16px.png" );
+    ADD_ICON( CDDA, ":/pixmaps/cdda_16px.png" );
+    ADD_ICON( CARD, ":/pixmaps/capture-card_16px.png" );
+    ADD_ICON( NET, ":/pixmaps/type_net.png" );
+    ADD_ICON( PLAYLIST, ":/pixmaps/type_playlist.png" );
+    ADD_ICON( NODE, ":/pixmaps/type_node.png" );
 
     rootItem = NULL;
     addCallbacks();
     rebuild( p_root );
 }
 
-
 PLModel::~PLModel()
 {
     delCallbacks();
     delete rootItem;
 }
 
+Qt::DropActions PLModel::supportedDropActions() const
+{
+    return Qt::CopyAction;
+}
+
+Qt::ItemFlags PLModel::flags( const QModelIndex &index ) const
+{
+    Qt::ItemFlags defaultFlags = QAbstractItemModel::flags( index );
+    if( index.isValid() )
+        return Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | defaultFlags;
+    else
+        return Qt::ItemIsDropEnabled | defaultFlags;
+}
+
+QStringList PLModel::mimeTypes() const
+{
+    QStringList types;
+    types << "vlc/playlist-item-id";
+    return types;
+}
+
+QMimeData *PLModel::mimeData( const QModelIndexList &indexes ) const
+{
+    QMimeData *mimeData = new QMimeData();
+    QByteArray encodedData;
+    QDataStream stream( &encodedData, QIODevice::WriteOnly );
+
+    foreach( QModelIndex index, indexes ) {
+        if( index.isValid() && index.column() == 0 )
+            stream << itemId( index );
+    }
+    mimeData->setData( "vlc/playlist-item-id", encodedData );
+    return mimeData;
+}
+
+bool PLModel::dropMimeData( const QMimeData *data, Qt::DropAction action,
+                           int row, int column, const QModelIndex &target )
+{
+    if( data->hasFormat( "vlc/playlist-item-id" ) )
+    {
+        if( action == Qt::IgnoreAction )
+            return true;
+
+        PLItem *targetItem;
+        if( target.isValid() )
+            targetItem = static_cast<PLItem*>( target.internalPointer() );
+        else
+            targetItem = rootItem;
+
+        QByteArray encodedData = data->data( "vlc/playlist-item-id" );
+        QDataStream stream( &encodedData, QIODevice::ReadOnly );
+
+        PLItem *newParentItem;
+        while( !stream.atEnd() )
+        {
+            int i;
+            int srcId;
+            stream >> srcId;
+
+            PL_LOCK;
+            playlist_item_t *p_target =
+                        playlist_ItemGetById( p_playlist, targetItem->i_id,
+                                              VLC_TRUE );
+            playlist_item_t *p_src = playlist_ItemGetById( p_playlist, srcId,
+                                                           VLC_TRUE );
+
+            if( !p_target || !p_src )
+            {
+                PL_UNLOCK;
+                return false;
+            }
+            if( p_target->i_children == -1 ) /* A leaf */
+            {
+                PLItem *parentItem = targetItem->parent();
+                assert( parentItem );
+                playlist_item_t *p_parent =
+                         playlist_ItemGetById( p_playlist, parentItem->i_id,
+                                               VLC_TRUE );
+                if( !p_parent )
+                {
+                    PL_UNLOCK;
+                    return false;
+                }
+                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 );
+                newParentItem = parentItem;
+            }
+            else
+            {
+                /* \todo: if we drop on a top-level node, use copy instead ? */
+                playlist_TreeMove( p_playlist, p_src, p_target, 0 );
+                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;
+        }
+    }
+    return true;
+}
+
+void PLModel::removeItem( int i_id )
+{
+    PLItem *item = FindById( rootItem,i_id );
+    if( item ) item->remove( item );
+}
+
 void PLModel::addCallbacks()
 {
     /* Some global changes happened -> Rebuild all */
@@ -201,7 +436,8 @@ void PLModel::activateItem( const QModelIndex &index )
     PLItem *item = static_cast<PLItem*>(index.internalPointer());
     assert( item );
     PL_LOCK;
-    playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id );
+    playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id,
+                                                    VLC_TRUE);
     activateItem( p_item );
     PL_UNLOCK;
 }
@@ -216,13 +452,13 @@ void PLModel::activateItem( playlist_item_t *p_item )
         p_parent = p_parent->p_parent;
     }
     if( p_parent )
-        playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, p_parent, p_item );
+        playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, VLC_TRUE, p_parent, p_item );
 }
 
 /****************** Base model mandatory implementations *****************/
-QVariant PLModel::data(const QModelIndex &index, int role) const
+QVariant PLModel::data( const QModelIndex &index, int role ) const
 {
-    assert( index.isValid() );
+    if( !index.isValid() ) return QVariant();
     PLItem *item = static_cast<PLItem*>(index.internalPointer());
     if( role == Qt::DisplayRole )
     {
@@ -255,32 +491,26 @@ int PLModel::itemId( const QModelIndex &index ) const
     return static_cast<PLItem*>(index.internalPointer())->i_id;
 }
 
-Qt::ItemFlags PLModel::flags(const QModelIndex &index) const
-{
-    if( !index.isValid() ) return Qt::ItemIsEnabled;
-    return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
-}
-
 QVariant PLModel::headerData( int section, Qt::Orientation orientation,
-                              int role) const
+                              int role ) const
 {
     if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
             return QVariant( rootItem->columnString( section ) );
     return QVariant();
 }
 
-QModelIndex PLModel::index(int row, int column, const QModelIndex &parent)
+QModelIndex PLModel::index( int row, int column, const QModelIndex &parent )
                   const
 {
     PLItem *parentItem;
-    if (!parent.isValid())
+    if( !parent.isValid() )
         parentItem = rootItem;
     else
         parentItem = static_cast<PLItem*>(parent.internalPointer());
 
-    PLItem *childItem = parentItem->child(row);
-    if (childItem)
-        return createIndex(row, column, childItem);
+    PLItem *childItem = parentItem->child( row );
+    if( childItem )
+        return createIndex( row, column, childItem );
     else
         return QModelIndex();
 }
@@ -296,12 +526,12 @@ QModelIndex PLModel::index( PLItem *item, int column ) const
     return QModelIndex();
 }
 
-QModelIndex PLModel::parent(const QModelIndex &index) const
+QModelIndex PLModel::parent( const QModelIndex &index ) const
 {
     if( !index.isValid() ) return QModelIndex();
 
     PLItem *childItem = static_cast<PLItem*>(index.internalPointer());
-    if( !childItem ) { msg_Err( p_playlist, "NULL CHILD \n" ); return QModelIndex(); }
+    if( !childItem ) { msg_Err( p_playlist, "NULL CHILD" ); return QModelIndex(); }
     PLItem *parentItem = childItem->parent();
     if( !parentItem || parentItem == rootItem ) return QModelIndex();
     if( ! parentItem->parentItem )
@@ -316,20 +546,19 @@ QModelIndex PLModel::parent(const QModelIndex &index) const
 
 int PLModel::columnCount( const QModelIndex &i) const
 {
-    if( i_depth == 1 ) return 1;
-    return 3;
+    return rootItem->strings.count();
 }
 
-int PLModel::childrenCount(const QModelIndex &parent) const
+int PLModel::childrenCount( const QModelIndex &parent ) const
 {
     return rowCount( parent );
 }
 
-int PLModel::rowCount(const QModelIndex &parent) const
+int PLModel::rowCount( const QModelIndex &parent ) const
 {
     PLItem *parentItem;
 
-    if (!parent.isValid())
+    if( !parent.isValid() )
         parentItem = rootItem;
     else
         parentItem = static_cast<PLItem*>(parent.internalPointer());
@@ -357,14 +586,17 @@ bool PLModel::hasLoop()
 void PLModel::setLoop( bool on )
 {
     var_SetBool( p_playlist, "loop", on ? VLC_TRUE:VLC_FALSE );
+    config_PutInt( p_playlist, "loop", on ? 1: 0 );
 }
 void PLModel::setRepeat( bool on )
 {
     var_SetBool( p_playlist, "repeat", on ? VLC_TRUE:VLC_FALSE );
+    config_PutInt( p_playlist, "repeat", on ? 1: 0 );
 }
 void PLModel::setRandom( bool on )
 {
     var_SetBool( p_playlist, "random", on ? VLC_TRUE:VLC_FALSE );
+    config_PutInt( p_playlist, "random", on ? 1: 0 );
 }
 
 /************************* Lookups *****************************/
@@ -439,7 +671,7 @@ void PLModel::customEvent( QEvent *event )
 {
     int type = event->type();
     if( type != ItemUpdate_Type && type != ItemAppend_Type &&
-        type != ItemDelete_Type )
+        type != ItemDelete_Type && type != PLUpdate_Type )
         return;
 
     PLEvent *ple = static_cast<PLEvent *>(event);
@@ -448,8 +680,10 @@ void PLModel::customEvent( QEvent *event )
         ProcessInputItemUpdate( ple->i_id );
     else if( type == ItemAppend_Type )
         ProcessItemAppend( ple->p_add );
-    else
+    else if( type == ItemDelete_Type )
         ProcessItemRemoval( ple->i_id );
+    else
+        rebuild();
 }
 
 /**** Events processing ****/
@@ -466,7 +700,6 @@ void PLModel::ProcessItemRemoval( int i_id )
     if( i_id <= 0 ) return;
     if( i_id == i_cached_id ) i_cached_id = -1;
     i_cached_input_id = -1;
-
     PLItem *item = FindById( rootItem, i_id );
     if( item )
         item->remove( item );
@@ -483,7 +716,7 @@ void PLModel::ProcessItemAppend( playlist_add_t *p_add )
     PL_LOCK;
     if( !nodeItem ) goto end;
 
-    p_item = playlist_ItemGetById( p_playlist, p_add->i_item );
+    p_item = playlist_ItemGetById( p_playlist, p_add->i_item, VLC_TRUE );
     if( !p_item || p_item->i_flags & PLAYLIST_DBL_FLAG ) goto end;
     if( i_depth == 1 && p_item->p_parent &&
                         p_item->p_parent->i_id != rootItem->i_id )
@@ -514,19 +747,19 @@ void PLModel::rebuild( playlist_item_t *p_root )
     /* Clear the tree */
     if( rootItem )
     {
-        beginRemoveRows( index( rootItem, 0 ), 0,
-                         rootItem->children.size() -1 );
-        qDeleteAll( rootItem->children );
-        rootItem->children.clear();
-        endRemoveRows();
+        if( rootItem->children.size() )
+        {
+            beginRemoveRows( index( rootItem, 0 ), 0,
+                    rootItem->children.size() -1 );
+            qDeleteAll( rootItem->children );
+            rootItem->children.clear();
+            endRemoveRows();
+        }
     }
     if( p_root )
     {
         //if( rootItem ) delete rootItem;
         rootItem = new PLItem( p_root, NULL, this );
-        rootItem->strings[0] = qtr("Name");
-        rootItem->strings[1] = qtr("Artist");
-        rootItem->strings[2] = qtr("Duration");
     }
     assert( rootItem );
     /* Recreate from root */
@@ -551,7 +784,8 @@ void PLModel::rebuild( playlist_item_t *p_root )
 /* This function must be entered WITH the playlist lock */
 void PLModel::UpdateNodeChildren( PLItem *root )
 {
-    playlist_item_t *p_node = playlist_ItemGetById( p_playlist, root->i_id );
+    playlist_item_t *p_node = playlist_ItemGetById( p_playlist, root->i_id,
+                                                    VLC_TRUE );
     UpdateNodeChildren( p_node, root );
 }
 
@@ -572,7 +806,8 @@ void PLModel::UpdateNodeChildren( playlist_item_t *p_node, PLItem *root )
 /* This function must be entered WITH the playlist lock */
 void PLModel::UpdateTreeItem( PLItem *item, bool signal, bool force )
 {
-    playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id );
+    playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id,
+                                                    VLC_TRUE );
     UpdateTreeItem( p_item, item, signal, force );
 }
 
@@ -580,6 +815,8 @@ void PLModel::UpdateTreeItem( PLItem *item, bool signal, bool force )
 void PLModel::UpdateTreeItem( playlist_item_t *p_item, PLItem *item,
                               bool signal, bool force )
 {
+    if ( !p_item )
+        return;
     if( !force && i_depth == 1 && p_item->p_parent &&
                                  p_item->p_parent->i_id != rootItem->i_id )
         return;
@@ -590,6 +827,17 @@ void PLModel::UpdateTreeItem( playlist_item_t *p_item, PLItem *item,
 
 /************************* Actions ******************************/
 
+void PLModel::sendArt( QString url )
+{
+    QString arturl = url.replace( "file://",QString("" ) );
+    emit artSet( arturl );
+}
+
+void PLModel::removeArt()
+{
+    emit artSet( QString() );
+}
+
 /**
  * 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
@@ -612,7 +860,7 @@ void PLModel::doDelete( QModelIndexList selected )
     }
 }
 
-void PLModel::recurseDelete( QList<PLItem*> children, QModelIndexList *fullList)
+void PLModel::recurseDelete( QList<PLItem*> children, QModelIndexList *fullList )
 {
     for( int i = children.size() - 1; i >= 0 ; i-- )
     {
@@ -629,13 +877,14 @@ void PLModel::doDeleteItem( PLItem *item, QModelIndexList *fullList )
     fullList->removeAll( deleteIndex );
 
     PL_LOCK;
-    playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id );
+    playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id,
+                                                    VLC_TRUE );
     if( !p_item )
     {
         PL_UNLOCK; return;
     }
     if( p_item->i_children == -1 )
-        playlist_DeleteAllFromInput( p_playlist, item->i_input_id );
+        playlist_DeleteFromInput( p_playlist, item->i_input_id, VLC_TRUE );
     else
         playlist_NodeDelete( p_playlist, p_item, VLC_TRUE, VLC_FALSE );
     /* And finally, remove it from the tree */
@@ -647,19 +896,24 @@ void PLModel::doDeleteItem( PLItem *item, QModelIndexList *fullList )
 void PLModel::sort( int column, Qt::SortOrder order )
 {
     PL_LOCK;
-    playlist_item_t *p_root = playlist_ItemGetById( p_playlist, rootItem->i_id );
-    int i_mode;
-    switch( column )
     {
-    case 0: i_mode = SORT_TITLE_NODES_FIRST;break;
-    case 1: i_mode = SORT_ARTIST;break;
-    case 2: i_mode = SORT_DURATION; break;
+        playlist_item_t *p_root = playlist_ItemGetById( p_playlist,
+                                                        rootItem->i_id,
+                                                        VLC_TRUE );
+        int i_mode;
+        switch( column )
+        {
+        case 0: i_mode = SORT_TITLE_NODES_FIRST;break;
+        case 1: i_mode = SORT_ARTIST;break;
+        case 2: i_mode = SORT_DURATION; break;
+        default: i_mode = SORT_TITLE_NODES_FIRST; break;
+        }
+        if( p_root )
+            playlist_RecursiveNodeSort( p_playlist, p_root, i_mode,
+                                        order == Qt::AscendingOrder ?
+                                            ORDER_NORMAL : ORDER_REVERSE );
     }
-    if( p_root )
-        playlist_RecursiveNodeSort( p_playlist, p_root, i_mode,
-                                    order == Qt::AscendingOrder ? ORDER_NORMAL :
-                                                            ORDER_REVERSE );
-    PL_UNLOCK
+    PL_UNLOCK;
     rebuild();
 }
 
@@ -667,10 +921,14 @@ void PLModel::search( QString search_text )
 {
     /** \todo Fire the search with a small delay ? */
     PL_LOCK;
-    playlist_item_t *p_root = playlist_ItemGetById( p_playlist,rootItem->i_id );
-    assert( p_root );
-    char *psz_name = search_text.toUtf8().data();
-    playlist_LiveSearchUpdate( p_playlist , p_root, psz_name );
+    {
+        playlist_item_t *p_root = playlist_ItemGetById( p_playlist,
+                                                        rootItem->i_id,
+                                                        VLC_TRUE );
+        assert( p_root );
+        char *psz_name = search_text.toUtf8().data();
+        playlist_LiveSearchUpdate( p_playlist , p_root, psz_name );
+    }
     PL_UNLOCK;
     rebuild();
 }
@@ -681,7 +939,7 @@ void PLModel::popup( QModelIndex & index, QPoint &point, QModelIndexList list )
     assert( index.isValid() );
     PL_LOCK;
     playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
-                                                    itemId( index ) );
+                                                    itemId( index ), VLC_TRUE );
     if( p_item )
     {
         i_popup_item = p_item->i_id;
@@ -690,8 +948,11 @@ void PLModel::popup( QModelIndex & index, QPoint &point, QModelIndexList list )
         current_selection = list;
         QMenu *menu = new QMenu;
         menu->addAction( qfu(I_POP_PLAY), this, SLOT( popupPlay() ) );
-        menu->addAction( qfu(I_POP_PREPARSE), this, SLOT( popupPreparse() ) );
         menu->addAction( qfu(I_POP_DEL), this, SLOT( popupDel() ) );
+        menu->addSeparator();
+        menu->addAction( qfu(I_POP_STREAM), this, SLOT( popupStream() ) );
+        menu->addAction( qfu(I_POP_SAVE), this, SLOT( popupSave() ) );
+        menu->addSeparator();
         menu->addAction( qfu(I_POP_INFO), this, SLOT( popupInfo() ) );
         if( p_item->i_children > -1 )
         {
@@ -699,12 +960,74 @@ void PLModel::popup( QModelIndex & index, QPoint &point, QModelIndexList list )
             menu->addAction( qfu(I_POP_SORT), this, SLOT( popupSort() ) );
             menu->addAction( qfu(I_POP_ADD), this, SLOT( popupAdd() ) );
         }
+#ifdef WIN32
+        menu->addSeparator();
+        menu->addAction( qfu( I_POP_EXPLORE ), this, SLOT( popupExplore() ) );
+#endif
         menu->popup( point );
     }
     else
         PL_UNLOCK;
 }
 
+
+void PLModel::viewchanged( int meta )
+{
+   if( rootItem )
+   {
+       int index=0;
+       switch( meta )
+       {
+       case VLC_META_ENGINE_TITLE:
+           index=0;
+           break;
+       case VLC_META_ENGINE_DURATION:
+           index=1;
+           break;
+       case VLC_META_ENGINE_ARTIST:
+           index=2;
+           break;
+       case VLC_META_ENGINE_GENRE:
+           index=3;
+           break;
+       case VLC_META_ENGINE_COPYRIGHT:
+           index=4;
+           break;
+       case VLC_META_ENGINE_COLLECTION:
+           index=5;
+           break;
+       case VLC_META_ENGINE_SEQ_NUM:
+           index=6;
+           break;
+       case VLC_META_ENGINE_DESCRIPTION:
+           index=7;
+           break;
+       default:
+           break;
+       }
+       emit layoutAboutToBeChanged();
+       index = __MIN( index , rootItem->strings.count() );
+       QModelIndex parent = createIndex( 0, 0, rootItem );
+       if( rootItem->i_showflags & meta )
+       {
+           beginRemoveColumns( parent , index, index+1 );
+           rootItem->i_showflags &= ~( meta );
+           rootItem->updateview();
+           endRemoveColumns();
+       }
+       else
+       {
+           beginInsertColumns( createIndex( 0, 0, rootItem), index, index+1 );
+           rootItem->i_showflags |= meta;
+           rootItem->updateview();
+           endInsertColumns();
+       }
+       rebuild();
+       config_PutInt( p_intf, "qt-pl-showflags", rootItem->i_showflags );
+       config_SaveConfigFile( p_intf, NULL );
+   }
+}
+
 void PLModel::popupDel()
 {
     doDelete( current_selection );
@@ -712,11 +1035,44 @@ void PLModel::popupDel()
 void PLModel::popupPlay()
 {
     PL_LOCK;
-    playlist_item_t *p_item = playlist_ItemGetById( p_playlist, i_popup_item );
-    activateItem( p_item );
+    {
+        playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
+                                                        i_popup_item,VLC_TRUE );
+        activateItem( p_item );
+    }
     PL_UNLOCK;
 }
 
+void PLModel::popupInfo()
+{
+    playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
+                                                    i_popup_item,
+                                                    VLC_TRUE );
+    if( p_item )
+    {
+        MediaInfoDialog *mid = new MediaInfoDialog( p_intf, p_item->p_input );
+        mid->show();
+    }
+}
+
+void PLModel::popupStream()
+{
+     msg_Err( p_playlist, "Stream not implemented" );
+}
+
+void PLModel::popupSave()
+{
+     msg_Err( p_playlist, "Save not implemented" );
+}
+
+#ifdef WIN32
+#include <shellapi.h>
+void PLModel::popupExplore()
+{
+    ShellExecuteW(NULL, L"explore", L"C:\\", NULL, NULL, SW_SHOWNORMAL );
+}
+#endif
+
 /**********************************************************************
  * Playlist callbacks
  **********************************************************************/
@@ -724,7 +1080,8 @@ static int PlaylistChanged( vlc_object_t *p_this, const char *psz_variable,
                             vlc_value_t oval, vlc_value_t nval, void *param )
 {
     PLModel *p_model = (PLModel *) param;
-    p_model->b_need_update = VLC_TRUE;
+    PLEvent *event = new PLEvent( PLUpdate_Type, 0 );
+    QApplication::postEvent( p_model, static_cast<QEvent*>(event) );
     return VLC_SUCCESS;
 }
 
@@ -766,8 +1123,8 @@ static int ItemAppended( vlc_object_t *p_this, const char *psz_variable,
 
     if( ++p_model->i_items_to_append >= 50 )
     {
-        p_model->b_need_update = VLC_TRUE;
-        return VLC_SUCCESS;
+//        p_model->b_need_update = VLC_TRUE;
+//        return VLC_SUCCESS;
     }
     PLEvent *event = new PLEvent(  p_add );
     QApplication::postEvent( p_model, static_cast<QEvent*>(event) );