]> git.sesse.net Git - vlc/blobdiff - modules/gui/qt4/components/playlist/playlist_model.cpp
UI: prefix/namespace resources for better maintainability
[vlc] / modules / gui / qt4 / components / playlist / playlist_model.cpp
index 3bb985c00f79e386b559c22e88acf67986331227..c101d9ab252f50cd4c55dfa8c1bcd9012d273215 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"
@@ -48,8 +49,6 @@ static int PlaylistChanged( vlc_object_t *, const char *,
                             vlc_value_t, vlc_value_t, void * );
 static int PlaylistNext( vlc_object_t *, const char *,
                          vlc_value_t, vlc_value_t, void * );
-static int ItemChanged( vlc_object_t *, const char *,
-                        vlc_value_t, vlc_value_t, void * );
 static int ItemAppended( vlc_object_t *p_this, const char *psz_variable,
                          vlc_value_t oval, vlc_value_t nval, void *param );
 static int ItemDeleted( vlc_object_t *p_this, const char *psz_variable,
@@ -84,17 +83,21 @@ PLModel::PLModel( playlist_t *_p_playlist,  /* THEPL */
     /* Icons initialization */
 #define ADD_ICON(type, x) icons[ITEM_TYPE_##type] = QIcon( QPixmap( x ) )
     ADD_ICON( UNKNOWN , type_unknown_xpm );
-    ADD_ICON( FILE, ":/type_file" );
-    ADD_ICON( DIRECTORY, ":/type_directory" );
-    ADD_ICON( DISC, ":/disc" );
-    ADD_ICON( CDDA, ":/cdda" );
-    ADD_ICON( CARD, ":/capture-card" );
-    ADD_ICON( NET, ":/type_net" );
-    ADD_ICON( PLAYLIST, ":/type_playlist" );
-    ADD_ICON( NODE, ":/type_node" );
+    ADD_ICON( FILE, ":/type/file" );
+    ADD_ICON( DIRECTORY, ":/type/directory" );
+    ADD_ICON( DISC, ":/type/disc" );
+    ADD_ICON( CDDA, ":/type/cdda" );
+    ADD_ICON( CARD, ":/type/capture-card" );
+    ADD_ICON( NET, ":/type/net" );
+    ADD_ICON( PLAYLIST, ":/type/playlist" );
+    ADD_ICON( NODE, ":/type/node" );
 #undef ADD_ICON
 
     rebuild( p_root );
+    CONNECT( THEMIM->getIM(), metaChanged( int ),
+            this, ProcessInputItemUpdate( int ) );
+    CONNECT( THEMIM, inputChanged( input_thread_t * ),
+            this, ProcessInputItemUpdate( input_thread_t* ) );
 }
 
 PLModel::~PLModel()
@@ -132,7 +135,7 @@ QMimeData *PLModel::mimeData( const QModelIndexList &indexes ) const
     QByteArray encodedData;
     QDataStream stream( &encodedData, QIODevice::WriteOnly );
 
-    foreach( QModelIndex index, indexes ) {
+    foreach( const QModelIndex &index, indexes ) {
         if( index.isValid() && index.column() == 0 )
             stream << itemId( index );
     }
@@ -149,11 +152,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 );
@@ -167,10 +170,8 @@ bool PLModel::dropMimeData( const QMimeData *data, Qt::DropAction action,
 
             PL_LOCK;
             playlist_item_t *p_target =
-                        playlist_ItemGetById( p_playlist, targetItem->i_id,
-                                              pl_Locked );
-            playlist_item_t *p_src = playlist_ItemGetById( p_playlist, srcId,
-                                                           pl_Locked );
+                        playlist_ItemGetById( p_playlist, targetItem->i_id );
+            playlist_item_t *p_src = playlist_ItemGetById( p_playlist, srcId );
 
             if( !p_target || !p_src )
             {
@@ -182,8 +183,7 @@ bool PLModel::dropMimeData( const QMimeData *data, Qt::DropAction action,
                 PLItem *parentItem = targetItem->parent();
                 assert( parentItem );
                 playlist_item_t *p_parent =
-                         playlist_ItemGetById( p_playlist, parentItem->i_id,
-                                               pl_Locked );
+                         playlist_ItemGetById( p_playlist, parentItem->i_id );
                 if( !p_parent )
                 {
                     PL_UNLOCK;
@@ -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;
 }
@@ -236,21 +222,22 @@ void PLModel::addCallbacks()
 {
     /* Some global changes happened -> Rebuild all */
     var_AddCallback( p_playlist, "intf-change", PlaylistChanged, this );
-    /* We went to the next item */
-    var_AddCallback( p_playlist, "playlist-current", PlaylistNext, this );
+    /* We went to the next item
+    var_AddCallback( p_playlist, "item-current", PlaylistNext, this );
+    */
     /* One item has been updated */
-    var_AddCallback( p_playlist, "item-change", ItemChanged, this );
-    var_AddCallback( p_playlist, "item-append", ItemAppended, this );
-    var_AddCallback( p_playlist, "item-deleted", ItemDeleted, this );
+    var_AddCallback( p_playlist, "playlist-item-append", ItemAppended, this );
+    var_AddCallback( p_playlist, "playlist-item-deleted", ItemDeleted, this );
 }
 
 void PLModel::delCallbacks()
 {
-    var_DelCallback( p_playlist, "item-change", ItemChanged, this );
-    var_DelCallback( p_playlist, "playlist-current", PlaylistNext, this );
+    /*
+    var_DelCallback( p_playlist, "item-current", PlaylistNext, this );
+    */
     var_DelCallback( p_playlist, "intf-change", PlaylistChanged, this );
-    var_DelCallback( p_playlist, "item-append", ItemAppended, this );
-    var_DelCallback( p_playlist, "item-deleted", ItemDeleted, this );
+    var_DelCallback( p_playlist, "playlist-item-append", ItemAppended, this );
+    var_DelCallback( p_playlist, "playlist-item-deleted", ItemDeleted, this );
 }
 
 void PLModel::activateItem( const QModelIndex &index )
@@ -259,8 +246,7 @@ 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,
-                                                    pl_Locked );
+    playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id );
     activateItem( p_item );
     PL_UNLOCK;
 }
@@ -405,21 +391,18 @@ QStringList PLModel::selectedURIs()
         PL_LOCK;
         PLItem *item = static_cast<PLItem*>
                     (current_selection[i].internalPointer());
-        if( !item )
-            continue;
-
-        input_item_t *p_item = input_item_GetById( p_playlist,
-                                                   item->i_input_id );
-        if( !p_item )
-            continue;
-
-        char *psz = input_item_GetURI( p_item );
-        if( !psz )
-            continue;
-        else
+        if( item )
         {
-            lst.append( QString( psz ) );
-            free( psz );
+            playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id );
+            if( p_item )
+            {
+                char *psz = input_item_GetURI( p_item->p_input );
+                if( psz )
+                {
+                    lst.append( psz );
+                    free( psz );
+                }
+            }
         }
         PL_UNLOCK;
     }
@@ -430,18 +413,15 @@ QStringList PLModel::selectedURIs()
 
 bool PLModel::hasRandom()
 {
-    if( var_GetBool( p_playlist, "random" ) ) return true;
-    return false;
+    return var_GetBool( p_playlist, "random" );
 }
 bool PLModel::hasRepeat()
 {
-    if( var_GetBool( p_playlist, "repeat" ) ) return true;
-    return false;
+    return var_GetBool( p_playlist, "repeat" );
 }
 bool PLModel::hasLoop()
 {
-    if( var_GetBool( p_playlist, "loop" ) ) return true;
-    return false;
+    return var_GetBool( p_playlist, "loop" );
 }
 void PLModel::setLoop( bool on )
 {
@@ -530,16 +510,14 @@ PLItem * PLModel::FindInner( PLItem *root, int i_id, bool b_input )
 void PLModel::customEvent( QEvent *event )
 {
     int type = event->type();
-    if( type != ItemUpdate_Type && type != ItemAppend_Type &&
+    if( type != ItemAppend_Type &&
         type != ItemDelete_Type && type != PLUpdate_Type )
         return;
 
     PLEvent *ple = static_cast<PLEvent *>(event);
 
-    if( type == ItemUpdate_Type )
-        ProcessInputItemUpdate( ple->i_id );
-    else if( type == ItemAppend_Type )
-        ProcessItemAppend( ple->p_add );
+    if( type == ItemAppend_Type )
+        ProcessItemAppend( &ple->add );
     else if( type == ItemDelete_Type )
         ProcessItemRemoval( ple->i_id );
     else
@@ -547,6 +525,11 @@ void PLModel::customEvent( QEvent *event )
 }
 
 /**** Events processing ****/
+void PLModel::ProcessInputItemUpdate( input_thread_t *p_input )
+{
+    if( !p_input ) return;
+    ProcessInputItemUpdate( input_GetItem( p_input )->i_id );
+}
 void PLModel::ProcessInputItemUpdate( int i_input_id )
 {
     if( i_input_id <= 0 ) return;
@@ -568,7 +551,7 @@ void PLModel::ProcessItemRemoval( int i_id )
     removeItem( i_id );
 }
 
-void PLModel::ProcessItemAppend( playlist_add_t *p_add )
+void PLModel::ProcessItemAppend( const playlist_add_t *p_add )
 {
     playlist_item_t *p_item = NULL;
     PLItem *newItem = NULL;
@@ -577,7 +560,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, pl_Locked );
+    p_item = playlist_ItemGetById( p_playlist, p_add->i_item );
     if( !p_item || p_item->i_flags & PLAYLIST_DBL_FLAG ) goto end;
     if( i_depth == DEPTH_SEL && p_item->p_parent &&
                         p_item->p_parent->i_id != rootItem->i_id )
@@ -599,6 +582,7 @@ void PLModel::rebuild()
 
 void PLModel::rebuild( playlist_item_t *p_root )
 {
+    playlist_item_t* p_item;
     /* Remove callbacks before locking to avoid deadlocks */
     delCallbacks();
     /* Invalidate cache */
@@ -625,13 +609,13 @@ void PLModel::rebuild( playlist_item_t *p_root )
     assert( rootItem );
     /* Recreate from root */
     UpdateNodeChildren( rootItem );
-    if( p_playlist->status.p_item )
+    if( (p_item = playlist_CurrentPlayingItem(p_playlist)) )
     {
         PLItem *currentItem = FindByInput( rootItem,
-                                     p_playlist->status.p_item->p_input->i_id );
+                                           p_item->p_input->i_id );
         if( currentItem )
         {
-            UpdateTreeItem( p_playlist->status.p_item, currentItem,
+            UpdateTreeItem( p_item, currentItem,
                             true, false );
         }
     }
@@ -645,8 +629,7 @@ 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,
-                                                    pl_Locked );
+    playlist_item_t *p_node = playlist_ItemGetById( p_playlist, root->i_id );
     UpdateNodeChildren( p_node, root );
 }
 
@@ -667,8 +650,7 @@ 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,
-                                                    pl_Locked );
+    playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id );
     UpdateTreeItem( p_item, item, signal, force );
 }
 
@@ -681,7 +663,7 @@ void PLModel::UpdateTreeItem( playlist_item_t *p_item, PLItem *item,
     if( !force && i_depth == DEPTH_SEL && p_item->p_parent &&
                                  p_item->p_parent->i_id != rootItem->i_id )
         return;
-    item->update( p_item, p_item == p_playlist->status.p_item );
+    item->update( p_item, p_item == playlist_CurrentPlayingItem( p_playlist ) );
     if( signal )
         emit dataChanged( index( item, 0 ) , index( item, 1 ) );
 }
@@ -727,14 +709,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,
-                                                    pl_Locked );
+    playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id );
     if( !p_item )
     {
-        PL_UNLOCK; return;
+        PL_UNLOCK;
+        return;
     }
     if( p_item->i_children == -1 )
-        playlist_DeleteFromInput( p_playlist, item->i_input_id, pl_Locked );
+        playlist_DeleteFromInput( p_playlist, p_item->p_input, pl_Locked );
     else
         playlist_NodeDelete( p_playlist, p_item, true, false );
     /* And finally, remove it from the tree */
@@ -748,67 +730,45 @@ void PLModel::sort( int column, Qt::SortOrder order )
     int i_index = -1;
     int i_flag = 0;
 
-    // FIXME: Disable sorting on startup by ignoring
-    // first call of sorting caused by showing dialog
-    // see: standardpanel.cpp:65
-    static bool b_first_time = true;
-    if( b_first_time )
+    int i_column = 1;
+    for( i_column = 1; i_column != COLUMN_END; i_column<<=1 )
     {
-        b_first_time = false;
-        return;
+        if( ( shownFlags() & i_column ) )
+            i_index++;
+        if( column == i_index )
+        {
+            i_flag = i_column;
+            goto next;
+        }
     }
 
-#define CHECK_COLUMN( meta )                        \
-{                                                   \
-    if( ( shownFlags() & meta ) )                   \
-        i_index++;                                  \
-    if( column == i_index )                         \
-    {                                               \
-        i_flag = meta;                              \
-        goto next;                                  \
-    }                                               \
-}
-
-    CHECK_COLUMN( COLUMN_NUMBER );
-    CHECK_COLUMN( COLUMN_TITLE );
-    CHECK_COLUMN( COLUMN_DURATION );
-    CHECK_COLUMN( COLUMN_ARTIST );
-    CHECK_COLUMN( COLUMN_GENRE );
-    CHECK_COLUMN( COLUMN_ALBUM );
-    CHECK_COLUMN( COLUMN_TRACK_NUMBER );
-    CHECK_COLUMN( COLUMN_DESCRIPTION );
-
-#undef CHECK_COLUMN
 
 next:
     PL_LOCK;
     {
         playlist_item_t *p_root = playlist_ItemGetById( p_playlist,
-                                                        rootItem->i_id,
-                                                        pl_Locked );
-        if( p_root )
+                                                        rootItem->i_id );
+        if( p_root && i_flag )
         {
             playlist_RecursiveNodeSort( p_playlist, p_root,
                                         i_column_sorting( i_flag ),
                                         order == Qt::AscendingOrder ?
                                             ORDER_NORMAL : ORDER_REVERSE );
-            p_playlist->b_reset_currently_playing = true;
         }
     }
     PL_UNLOCK;
     rebuild();
 }
 
-void PLModel::search( QString search_text )
+void PLModel::search( const 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,
-                                                        pl_Locked );
+                                                        rootItem->i_id );
         assert( p_root );
-        char *psz_name = search_text.toUtf8().data();
+        const char *psz_name = search_text.toUtf8().data();
         playlist_LiveSearchUpdate( p_playlist , p_root, psz_name );
     }
     PL_UNLOCK;
@@ -820,8 +780,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 ), pl_Locked );
+    playlist_item_t *p_item = playlist_ItemGetById( p_playlist, itemId( index ) );
     if( p_item )
     {
         i_popup_item = p_item->i_id;
@@ -829,21 +788,21 @@ void PLModel::popup( QModelIndex & index, QPoint &point, QModelIndexList list )
         PL_UNLOCK;
         current_selection = list;
         QMenu *menu = new QMenu;
-        menu->addAction( qfu(I_POP_PLAY), this, SLOT( popupPlay() ) );
-        menu->addAction( qfu(I_POP_DEL), this, SLOT( popupDel() ) );
+        menu->addAction( qtr(I_POP_PLAY), this, SLOT( popupPlay() ) );
+        menu->addAction( qtr(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->addAction( qtr(I_POP_STREAM), this, SLOT( popupStream() ) );
+        menu->addAction( qtr(I_POP_SAVE), this, SLOT( popupSave() ) );
         menu->addSeparator();
-        menu->addAction( qfu(I_POP_INFO), this, SLOT( popupInfo() ) );
+        menu->addAction( qtr(I_POP_INFO), this, SLOT( popupInfo() ) );
         if( p_item->i_children > -1 )
         {
             menu->addSeparator();
-            menu->addAction( qfu(I_POP_SORT), this, SLOT( popupSort() ) );
-            menu->addAction( qfu(I_POP_ADD), this, SLOT( popupAdd() ) );
+            menu->addAction( qtr(I_POP_SORT), this, SLOT( popupSort() ) );
+            menu->addAction( qtr(I_POP_ADD), this, SLOT( popupAdd() ) );
         }
         menu->addSeparator();
-        menu->addAction( qfu( I_POP_EXPLORE ), this, SLOT( popupExplore() ) );
+        menu->addAction( qtr( I_POP_EXPLORE ), this, SLOT( popupExplore() ) );
         menu->popup( point );
     }
     else
@@ -873,6 +832,7 @@ void PLModel::viewchanged( int meta )
         {
             beginRemoveColumns( parent, index, index+1 );
             rootItem->i_showflags &= ~( meta );
+            getSettings()->setValue( "qt-pl-showflags", rootItem->i_showflags );
             rootItem->updateColumnHeaders();
             endRemoveColumns();
         }
@@ -881,6 +841,7 @@ void PLModel::viewchanged( int meta )
             /* Adding columns */
             beginInsertColumns( parent, index, index+1 );
             rootItem->i_showflags |= meta;
+            getSettings()->setValue( "qt-pl-showflags", rootItem->i_showflags );
             rootItem->updateColumnHeaders();
             endInsertColumns();
         }
@@ -898,8 +859,7 @@ void PLModel::popupPlay()
     PL_LOCK;
     {
         playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
-                                                        i_popup_item,
-                                                        pl_Locked );
+                                                        i_popup_item );
         activateItem( p_item );
     }
     PL_UNLOCK;
@@ -907,12 +867,18 @@ void PLModel::popupPlay()
 
 void PLModel::popupInfo()
 {
+    PL_LOCK;
     playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
-                                                    i_popup_item,
-                                                    pl_Unlocked );
+                                                    i_popup_item );
     if( p_item )
     {
-        MediaInfoDialog *mid = new MediaInfoDialog( p_intf, p_item->p_input );
+        input_item_t* p_input = p_item->p_input;
+        vlc_gc_incref( p_input );
+        PL_UNLOCK;
+        MediaInfoDialog *mid = new MediaInfoDialog( p_intf, p_input );
+        vlc_gc_decref( p_input );
+        mid->setParent( PlaylistDialog::getInstance( p_intf ),
+                        Qt::Dialog );
         mid->show();
     }
 }
@@ -929,7 +895,7 @@ void PLModel::popupSave()
 {
     QStringList mrls = selectedURIs();
     if( !mrls.isEmpty() )
-        THEDP->streamingDialog( NULL, mrls[0], true );
+        THEDP->streamingDialog( NULL, mrls[0] );
 }
 
 #include <QUrl>
@@ -937,13 +903,14 @@ void PLModel::popupSave()
 #include <QDesktopServices>
 void PLModel::popupExplore()
 {
+    PL_LOCK;
     playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
-                                                    i_popup_item,
-                                                    pl_Unlocked );
+                                                    i_popup_item );
     if( p_item )
     {
        input_item_t *p_input = p_item->p_input;
        char *psz_meta = input_item_GetURI( p_input );
+       PL_UNLOCK;
        if( psz_meta )
        {
            const char *psz_access;
@@ -962,6 +929,8 @@ void PLModel::popupExplore()
            free( psz_meta );
        }
     }
+    else
+        PL_UNLOCK;
 }
 
 /**********************************************************************
@@ -972,7 +941,7 @@ static int PlaylistChanged( vlc_object_t *p_this, const char *psz_variable,
 {
     PLModel *p_model = (PLModel *) param;
     PLEvent *event = new PLEvent( PLUpdate_Type, 0 );
-    QApplication::postEvent( p_model, static_cast<QEvent*>(event) );
+    QApplication::postEvent( p_model, event );
     return VLC_SUCCESS;
 }
 
@@ -981,18 +950,9 @@ static int PlaylistNext( vlc_object_t *p_this, const char *psz_variable,
 {
     PLModel *p_model = (PLModel *) param;
     PLEvent *event = new PLEvent( ItemUpdate_Type, oval.i_int );
-    QApplication::postEvent( p_model, static_cast<QEvent*>(event) );
+    QApplication::postEvent( p_model, event );
     event = new PLEvent( ItemUpdate_Type, nval.i_int );
-    QApplication::postEvent( p_model, static_cast<QEvent*>(event) );
-    return VLC_SUCCESS;
-}
-
-static int ItemChanged( vlc_object_t *p_this, const char *psz_variable,
-                        vlc_value_t oval, vlc_value_t nval, void *param )
-{
-    PLModel *p_model = (PLModel *) param;
-    PLEvent *event = new PLEvent( ItemUpdate_Type, nval.i_int );
-    QApplication::postEvent( p_model, static_cast<QEvent*>(event) );
+    QApplication::postEvent( p_model, event );
     return VLC_SUCCESS;
 }
 
@@ -1001,7 +961,7 @@ static int ItemDeleted( vlc_object_t *p_this, const char *psz_variable,
 {
     PLModel *p_model = (PLModel *) param;
     PLEvent *event = new PLEvent( ItemDelete_Type, nval.i_int );
-    QApplication::postEvent( p_model, static_cast<QEvent*>(event) );
+    QApplication::postEvent( p_model, event );
     return VLC_SUCCESS;
 }
 
@@ -1009,11 +969,9 @@ static int ItemAppended( vlc_object_t *p_this, const char *psz_variable,
                          vlc_value_t oval, vlc_value_t nval, void *param )
 {
     PLModel *p_model = (PLModel *) param;
-    playlist_add_t *p_add = (playlist_add_t *)malloc( sizeof( playlist_add_t));
-    memcpy( p_add, nval.p_address, sizeof( playlist_add_t ) );
-
-    PLEvent *event = new PLEvent(  p_add );
-    QApplication::postEvent( p_model, static_cast<QEvent*>(event) );
+    const playlist_add_t *p_add = (playlist_add_t *)nval.p_address;
+    PLEvent *event = new PLEvent( p_add );
+    QApplication::postEvent( p_model, event );
     return VLC_SUCCESS;
 }