]> git.sesse.net Git - vlc/blob - modules/gui/qt4/playlist_model.cpp
* Popups
[vlc] / modules / gui / qt4 / playlist_model.cpp
1 /*****************************************************************************
2  * playlist_model.cpp : Manage playlist model
3  ****************************************************************************
4  * Copyright (C) 2006 the VideoLAN team
5  * $Id$
6  *
7  * Authors: ClĂ©ment Stenac <zorglub@videolan.org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 #include <QIcon>
25 #include <QFont>
26 #include "qt4.hpp"
27 #include <QApplication>
28 #include "playlist_model.hpp"
29 #include <assert.h>
30 #include <QMenu>
31
32 #include "pixmaps/type_unknown.xpm"
33 #include "pixmaps/type_afile.xpm"
34 #include "pixmaps/type_vfile.xpm"
35 #include "pixmaps/type_net.xpm"
36 #include "pixmaps/type_card.xpm"
37 #include "pixmaps/type_disc.xpm"
38 #include "pixmaps/type_cdda.xpm"
39 #include "pixmaps/type_directory.xpm"
40 #include "pixmaps/type_playlist.xpm"
41 #include "pixmaps/type_node.xpm"
42
43 QIcon PLModel::icons[ITEM_TYPE_NUMBER];
44
45 static int PlaylistChanged( vlc_object_t *, const char *,
46                             vlc_value_t, vlc_value_t, void * );
47 static int PlaylistNext( vlc_object_t *, const char *,
48                          vlc_value_t, vlc_value_t, void * );
49 static int ItemChanged( vlc_object_t *, const char *,
50                         vlc_value_t, vlc_value_t, void * );
51 static int ItemAppended( vlc_object_t *p_this, const char *psz_variable,
52                          vlc_value_t oval, vlc_value_t nval, void *param );
53 static int ItemDeleted( vlc_object_t *p_this, const char *psz_variable,
54                         vlc_value_t oval, vlc_value_t nval, void *param );
55
56 /*************************************************************************
57  * Playlist item implementation
58  *************************************************************************/
59
60 /**
61  * Column strings
62  *      Title
63  *      Artist
64  *      Duration
65  */
66
67 void PLItem::init( int _i_id, int _i_input_id, PLItem *parent, PLModel *m)
68 {
69     parentItem = parent;
70     i_id = _i_id; i_input_id = _i_input_id;
71     model = m;
72     strings.append( "" );
73     strings.append( "" );
74     strings.append( "" );
75 }
76
77 PLItem::PLItem( int _i_id, int _i_input_id, PLItem *parent, PLModel *m)
78 {
79     init( _i_id, _i_input_id, parent, m );
80 }
81
82 PLItem::PLItem( playlist_item_t * p_item, PLItem *parent, PLModel *m )
83 {
84     init( p_item->i_id, p_item->p_input->i_id, parent, m );
85 }
86
87 PLItem::~PLItem()
88 {
89     qDeleteAll(children);
90 }
91
92 void PLItem::insertChild( PLItem *item, int i_pos, bool signal )
93 {
94     assert( model );
95     if( signal )
96         model->beginInsertRows( model->index( this , 0 ), i_pos, i_pos );
97     children.append( item );
98     if( signal )
99         model->endInsertRows();
100 }
101
102 void PLItem::remove( PLItem *removed )
103 {
104     assert( model && parentItem );
105     int i_index = parentItem->children.indexOf( removed );
106     model->beginRemoveRows( model->index( parentItem, 0 ), i_index, i_index );
107     parentItem->children.removeAt( i_index );
108     model->endRemoveRows();
109 }
110
111 int PLItem::row() const
112 {
113     if (parentItem)
114         return parentItem->children.indexOf(const_cast<PLItem*>(this));
115     return 0;
116 }
117
118 void PLItem::update( playlist_item_t *p_item, bool iscurrent )
119 {
120     assert( p_item->p_input->i_id == i_input_id );
121     strings[0] = QString::fromUtf8( p_item->p_input->psz_name );
122     if( p_item->p_input->p_meta )
123     {
124         strings[1] = QString::fromUtf8( p_item->p_input->p_meta->psz_artist );
125     }
126     type = p_item->p_input->i_type;
127     current = iscurrent;
128 }
129
130 /*************************************************************************
131  * Playlist model implementation
132  *************************************************************************/
133
134 PLModel::PLModel( playlist_t *_p_playlist,
135                   playlist_item_t * p_root, int _i_depth, QObject *parent)
136                                     : QAbstractItemModel(parent)
137 {
138     i_depth = _i_depth;
139     assert( i_depth == 1 || i_depth == -1 );
140     p_playlist= _p_playlist;
141     i_items_to_append = 0;
142     b_need_update     = false;
143     i_cached_id       = -1;
144     i_cached_input_id = -1;
145     i_popup_item = i_popup_parent = -1;
146
147 #define ADD_ICON(type, x) icons[ITEM_TYPE_##type] = QIcon( QPixmap( type_##x##_xpm ) );
148     ADD_ICON( UNKNOWN , unknown );
149     ADD_ICON( AFILE,afile );
150     ADD_ICON( VFILE, vfile );
151     ADD_ICON( DIRECTORY, directory );
152     ADD_ICON( DISC, disc );
153     ADD_ICON( CDDA, cdda );
154     ADD_ICON( CARD, card );
155     ADD_ICON( NET, net );
156     ADD_ICON( PLAYLIST, playlist );
157     ADD_ICON( NODE, node );
158
159     rootItem = NULL;
160     rebuild( p_root );
161     addCallbacks();
162 }
163
164
165 PLModel::~PLModel()
166 {
167     delCallbacks();
168     delete rootItem;
169 }
170
171 void PLModel::addCallbacks()
172 {
173     /* Some global changes happened -> Rebuild all */
174     var_AddCallback( p_playlist, "intf-change", PlaylistChanged, this );
175     /* We went to the next item */
176     var_AddCallback( p_playlist, "playlist-current", PlaylistNext, this );
177     /* One item has been updated */
178     var_AddCallback( p_playlist, "item-change", ItemChanged, this );
179     var_AddCallback( p_playlist, "item-append", ItemAppended, this );
180     var_AddCallback( p_playlist, "item-deleted", ItemDeleted, this );
181 }
182
183 void PLModel::delCallbacks()
184 {
185     var_DelCallback( p_playlist, "item-change", ItemChanged, this );
186     var_DelCallback( p_playlist, "playlist-current", PlaylistNext, this );
187     var_DelCallback( p_playlist, "intf-change", PlaylistChanged, this );
188     var_DelCallback( p_playlist, "item-append", ItemAppended, this );
189     var_DelCallback( p_playlist, "item-deleted", ItemDeleted, this );
190 }
191
192 void PLModel::activateItem( const QModelIndex &index )
193 {
194     assert( index.isValid() );
195     PLItem *item = static_cast<PLItem*>(index.internalPointer());
196     assert( item );
197     PL_LOCK;
198     playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id );
199     activateItem( p_item );
200     PL_UNLOCK;
201 }
202 /* Must be entered with lock */
203 void PLModel::activateItem( playlist_item_t *p_item )
204 {
205     if( !p_item ) return;
206     playlist_item_t *p_parent = p_item;
207     while( p_parent )
208     {
209         if( p_parent->i_id == rootItem->i_id ) break;
210         p_parent = p_parent->p_parent;
211     }
212     if( p_parent )
213         playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, p_parent, p_item );
214 }
215
216 /****************** Base model mandatory implementations *****************/
217 QVariant PLModel::data(const QModelIndex &index, int role) const
218 {
219     assert( index.isValid() );
220     PLItem *item = static_cast<PLItem*>(index.internalPointer());
221     if( role == Qt::DisplayRole )
222     {
223         return QVariant( item->columnString( index.column() ) );
224     }
225     else if( role == Qt::DecorationRole && index.column() == 0  )
226     {
227         if( item->type >= 0 )
228             return QVariant( PLModel::icons[item->type] );
229     }
230     else if( role == Qt::FontRole )
231     {
232         if( item->current == true )
233         {
234             QFont f; f.setBold( true ); return QVariant( f );
235         }
236     }
237     return QVariant();
238 }
239
240 bool PLModel::isCurrent( const QModelIndex &index )
241 {
242     assert( index.isValid() );
243     return static_cast<PLItem*>(index.internalPointer())->current;
244 }
245
246 int PLModel::itemId( const QModelIndex &index ) const
247 {
248     assert( index.isValid() );
249     return static_cast<PLItem*>(index.internalPointer())->i_id;
250 }
251
252 Qt::ItemFlags PLModel::flags(const QModelIndex &index) const
253 {
254     if( !index.isValid() ) return Qt::ItemIsEnabled;
255     return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
256 }
257
258 QVariant PLModel::headerData( int section, Qt::Orientation orientation,
259                               int role) const
260 {
261     if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
262             return QVariant( rootItem->columnString( section ) );
263     return QVariant();
264 }
265
266 QModelIndex PLModel::index(int row, int column, const QModelIndex &parent)
267                   const
268 {
269     PLItem *parentItem;
270     if (!parent.isValid())
271         parentItem = rootItem;
272     else
273         parentItem = static_cast<PLItem*>(parent.internalPointer());
274
275     PLItem *childItem = parentItem->child(row);
276     if (childItem)
277         return createIndex(row, column, childItem);
278     else
279         return QModelIndex();
280 }
281
282 /* Return the index of a given item */
283 QModelIndex PLModel::index( PLItem *item, int column ) const
284 {
285     if( !item ) return QModelIndex();
286     const PLItem *parent = item->parent();
287     if( parent )
288         return createIndex( parent->children.lastIndexOf( item ), column, item );
289     return QModelIndex();
290 }
291
292 QModelIndex PLModel::parent(const QModelIndex &index) const
293 {
294     if( !index.isValid() ) return QModelIndex();
295
296     PLItem *childItem = static_cast<PLItem*>(index.internalPointer());
297     if( !childItem ) { msg_Err( p_playlist, "NULL CHILD \n" ); return QModelIndex(); }
298     PLItem *parentItem = childItem->parent();
299     if( !parentItem || parentItem == rootItem ) return QModelIndex();
300     QModelIndex ind = createIndex(parentItem->row(), 0, parentItem);
301     return ind;
302 }
303
304 int PLModel::columnCount( const QModelIndex &i) const
305 {
306     if( i_depth == 1 ) return 1;
307     return 2;
308 }
309
310 int PLModel::childrenCount(const QModelIndex &parent) const
311 {
312     return rowCount( parent );
313 }
314
315 int PLModel::rowCount(const QModelIndex &parent) const
316 {
317     PLItem *parentItem;
318
319     if (!parent.isValid())
320         parentItem = rootItem;
321     else
322         parentItem = static_cast<PLItem*>(parent.internalPointer());
323
324     return parentItem->childCount();
325 }
326
327 /************************* General playlist status ***********************/
328
329 bool PLModel::hasRandom()
330 {
331     if( var_GetBool( p_playlist, "random" ) ) return true;
332     return false;
333 }
334 bool PLModel::hasRepeat()
335 {
336     if( var_GetBool( p_playlist, "repeat" ) ) return true;
337     return false;
338 }
339 bool PLModel::hasLoop()
340 {
341     if( var_GetBool( p_playlist, "loop" ) ) return true;
342     return false;
343 }
344 void PLModel::setLoop( bool on )
345 {
346     var_SetBool( p_playlist, "loop", on ? VLC_TRUE:VLC_FALSE );
347 }
348 void PLModel::setRepeat( bool on )
349 {
350     var_SetBool( p_playlist, "repeat", on ? VLC_TRUE:VLC_FALSE );
351 }
352 void PLModel::setRandom( bool on )
353 {
354     var_SetBool( p_playlist, "random", on ? VLC_TRUE:VLC_FALSE );
355 }
356
357 /************************* Lookups *****************************/
358
359 PLItem *PLModel::FindById( PLItem *root, int i_id )
360 {
361     return FindInner( root, i_id, false );
362 }
363
364 PLItem *PLModel::FindByInput( PLItem *root, int i_id )
365 {
366     return FindInner( root, i_id, true );
367 }
368
369 #define CACHE( i, p ) { i_cached_id = i; p_cached_item = p; }
370 #define ICACHE( i, p ) { i_cached_input_id = i; p_cached_item_bi = p; }
371
372 PLItem * PLModel::FindInner( PLItem *root, int i_id, bool b_input )
373 {
374     if( ( !b_input && i_cached_id == i_id) ||
375         ( b_input && i_cached_input_id ==i_id ) )
376     {
377         return b_input ? p_cached_item_bi : p_cached_item;
378     }
379
380     if( !b_input && root->i_id == i_id )
381     {
382         CACHE( i_id, root );
383         return root;
384     }
385     else if( b_input && root->i_input_id == i_id )
386     {
387         ICACHE( i_id, root );
388         return root;
389     }
390
391     QList<PLItem *>::iterator it = root->children.begin();
392     while ( it != root->children.end() )
393     {
394         if( !b_input && (*it)->i_id == i_id )
395         {
396             CACHE( i_id, (*it) );
397             return p_cached_item;
398         }
399         else if( b_input && (*it)->i_input_id == i_id )
400         {
401             ICACHE( i_id, (*it) );
402             return p_cached_item_bi;
403         }
404         if( (*it)->children.size() )
405         {
406             PLItem *childFound = FindInner( (*it), i_id, b_input );
407             if( childFound )
408             {
409                 if( b_input )
410                     ICACHE( i_id, childFound )
411                 else
412                     CACHE( i_id, childFound )
413                 return childFound;
414             }
415         }
416         it++;
417     }
418     return NULL;
419 }
420 #undef CACHE
421 #undef ICACHE
422
423
424 /************************* Updates handling *****************************/
425 void PLModel::customEvent( QEvent *event )
426 {
427     int type = event->type();
428     if( type != ItemUpdate_Type && type != ItemAppend_Type &&
429         type != ItemDelete_Type )
430         return;
431
432     PLEvent *ple = static_cast<PLEvent *>(event);
433
434     if( type == ItemUpdate_Type )
435         ProcessInputItemUpdate( ple->i_id );
436     else if( type == ItemAppend_Type )
437         ProcessItemAppend( ple->p_add );
438     else
439         ProcessItemRemoval( ple->i_id );
440 }
441
442 /**** Events processing ****/
443 void PLModel::ProcessInputItemUpdate( int i_input_id )
444 {
445     if( i_input_id <= 0 ) return;
446     PLItem *item = FindByInput( rootItem, i_input_id );
447     if( item )
448         UpdateTreeItem( item, true );
449 }
450
451 void PLModel::ProcessItemRemoval( int i_id )
452 {
453     if( i_id <= 0 ) return;
454     if( i_id == i_cached_id ) i_cached_id = -1;
455     i_cached_input_id = -1;
456
457     PLItem *item = FindById( rootItem, i_id );
458     if( item )
459         item->remove( item );
460 }
461
462 void PLModel::ProcessItemAppend( playlist_add_t *p_add )
463 {
464     playlist_item_t *p_item = NULL;
465     PLItem *newItem = NULL;
466     i_items_to_append--;
467     if( b_need_update ) return;
468
469     PLItem *nodeItem = FindById( rootItem, p_add->i_node );
470     if( !nodeItem ) goto end;
471
472     PL_LOCK;
473     p_item = playlist_ItemGetById( p_playlist, p_add->i_item );
474     if( !p_item || p_item->i_flags & PLAYLIST_DBL_FLAG ) goto end;
475     if( i_depth == 1 && p_item->p_parent &&
476                         p_item->p_parent->i_id != rootItem->i_id )
477         goto end;
478
479     newItem = new PLItem( p_item, nodeItem, this );
480     nodeItem->appendChild( newItem );
481     UpdateTreeItem( p_item, newItem, true );
482 end:
483     PL_UNLOCK;
484     return;
485 }
486
487
488 void PLModel::rebuild()
489 {
490     rebuild( NULL );
491 }
492
493 void PLModel::rebuild( playlist_item_t *p_root )
494 {
495     /* Remove callbacks before locking to avoid deadlocks */
496     delCallbacks();
497     /* Invalidate cache */
498     i_cached_id = i_cached_input_id = -1;
499
500     PL_LOCK;
501     /* Clear the tree */
502     if( rootItem )
503     {
504         PLItem *deleted;
505         beginRemoveRows( index( rootItem, 0 ), 0,
506                          rootItem->children.size() -1 );
507         qDeleteAll( rootItem->children );
508         endRemoveRows();
509     }
510     if( p_root )
511     {
512         //if( rootItem ) delete rootItem;
513         rootItem = new PLItem( p_root, NULL, this );
514         rootItem->strings[0] = qtr("Name");
515         rootItem->strings[1] = qtr("Artist");
516     }
517     assert( rootItem );
518     /* Recreate from root */
519     UpdateNodeChildren( rootItem );
520     if( p_playlist->status.p_item )
521     {
522         PLItem *currentItem = FindByInput( rootItem,
523                                      p_playlist->status.p_item->p_input->i_id );
524         if( currentItem )
525         {
526             UpdateTreeItem( p_playlist->status.p_item, currentItem,
527                             true, false );
528         }
529     }
530     PL_UNLOCK;
531
532     /* And signal the view */
533     emit layoutChanged();
534     addCallbacks();
535 }
536
537 /* This function must be entered WITH the playlist lock */
538 void PLModel::UpdateNodeChildren( PLItem *root )
539 {
540     playlist_item_t *p_node = playlist_ItemGetById( p_playlist, root->i_id );
541     UpdateNodeChildren( p_node, root );
542 }
543
544 /* This function must be entered WITH the playlist lock */
545 void PLModel::UpdateNodeChildren( playlist_item_t *p_node, PLItem *root )
546 {
547     for( int i = 0; i < p_node->i_children ; i++ )
548     {
549         PLItem *newItem =  new PLItem( p_node->pp_children[i], root, this );
550         root->appendChild( newItem, false );
551         UpdateTreeItem( newItem, false, true );
552         if( i_depth != 1 && p_node->pp_children[i]->i_children != -1 )
553             UpdateNodeChildren( p_node->pp_children[i], newItem );
554     }
555 }
556
557 /* This function must be entered WITH the playlist lock */
558 void PLModel::UpdateTreeItem( PLItem *item, bool signal, bool force )
559 {
560     playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id );
561     UpdateTreeItem( p_item, item, signal, force );
562 }
563
564 /* This function must be entered WITH the playlist lock */
565 void PLModel::UpdateTreeItem( playlist_item_t *p_item, PLItem *item,
566                               bool signal, bool force )
567 {
568     if( !force && i_depth == 1 && p_item->p_parent &&
569                                  p_item->p_parent->i_id != rootItem->i_id )
570         return;
571     item->update( p_item, p_item == p_playlist->status.p_item );
572     if( signal )
573         emit dataChanged( index( item, 0 ) , index( item, 1 ) );
574 }
575
576 /************************* Actions ******************************/
577
578 /**
579  * Deletion, here we have to do a ugly slow hack as we retrieve the full
580  * list of indexes to delete at once: when we delete a node and all of
581  * its children, we need to update the list.
582  * Todo: investigate whethere we can use ranges to be sure to delete all items?
583  */
584 void PLModel::doDelete( QModelIndexList selected )
585 {
586     for( int i = selected.size() -1 ; i >= 0; i-- )
587     {
588         QModelIndex index = selected[i];
589         if( index.column() != 0 ) continue;
590         PLItem *item = static_cast<PLItem*>(index.internalPointer());
591         if( item )
592         {
593             if( item->children.size() )
594                 recurseDelete( item->children, &selected );
595             doDeleteItem( item, &selected );
596         }
597     }
598 }
599
600 void PLModel::recurseDelete( QList<PLItem*> children, QModelIndexList *fullList)
601 {
602     for( int i = children.size() - 1; i >= 0 ; i-- )
603     {
604         PLItem *item = children[i];
605         if( item->children.size() )
606             recurseDelete( item->children, fullList );
607         doDeleteItem( item, fullList );
608     }
609 }
610
611 void PLModel::doDeleteItem( PLItem *item, QModelIndexList *fullList )
612 {
613     QModelIndex deleteIndex = index( item, 0 );
614     fullList->removeAll( deleteIndex );
615
616     PL_LOCK;
617     playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id );
618     if( !p_item )
619     {
620         PL_UNLOCK; return;
621     }
622     if( p_item->i_children == -1 )
623         playlist_DeleteAllFromInput( p_playlist, item->i_input_id );
624     else
625         playlist_NodeDelete( p_playlist, p_item, VLC_TRUE, VLC_FALSE );
626     /* And finally, remove it from the tree */
627     item->remove( item );
628     PL_UNLOCK;
629 }
630
631 /*********** Popup *********/
632 void PLModel::popup( QModelIndex & index, QPoint &point, QModelIndexList list )
633 {
634     assert( index.isValid() );
635     PL_LOCK;
636     playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
637                                                     itemId( index ) );
638     if( p_item )
639     {
640         i_popup_item = p_item->i_id;
641         i_popup_parent = p_item->p_parent ? p_item->p_parent->i_id : -1;
642         PL_UNLOCK;
643         current_selection = list;
644         QMenu *menu = new QMenu;
645         menu->addAction( qtr("Play"), this, SLOT( popupPlay() ) );
646         menu->addAction( qtr("Fetch information"), this,
647                              SLOT( popupPreparse() ) );
648         menu->addAction( qtr("Delete"), this, SLOT( popupDel() ) );
649         menu->addAction( qtr("Information"), this, SLOT( popupInfo() ) );
650         if( p_item->i_children > -1 )
651         {
652             menu->addSeparator();
653             menu->addAction( qtr("Sort"), this, SLOT( popupSort() ) );
654             menu->addAction( qtr("Add node"), this, SLOT( popupAdd() ) );
655         }
656         menu->popup( point );
657     }
658     else
659         PL_UNLOCK;
660 }
661
662 void PLModel::popupDel()
663 {
664     doDelete( current_selection );
665 }
666 void PLModel::popupPlay()
667 {
668     PL_LOCK;
669     playlist_item_t *p_item = playlist_ItemGetById( p_playlist, i_popup_item );
670     activateItem( p_item );
671     PL_UNLOCK;
672 }
673
674 /**********************************************************************
675  * Playlist callbacks
676  **********************************************************************/
677 static int PlaylistChanged( vlc_object_t *p_this, const char *psz_variable,
678                             vlc_value_t oval, vlc_value_t nval, void *param )
679 {
680     PLModel *p_model = (PLModel *) param;
681     p_model->b_need_update = VLC_TRUE;
682     return VLC_SUCCESS;
683 }
684
685 static int PlaylistNext( vlc_object_t *p_this, const char *psz_variable,
686                          vlc_value_t oval, vlc_value_t nval, void *param )
687 {
688     PLModel *p_model = (PLModel *) param;
689     PLEvent *event = new PLEvent( ItemUpdate_Type, oval.i_int );
690     QApplication::postEvent( p_model, static_cast<QEvent*>(event) );
691     event = new PLEvent( ItemUpdate_Type, nval.i_int );
692     QApplication::postEvent( p_model, static_cast<QEvent*>(event) );
693     return VLC_SUCCESS;
694 }
695
696 static int ItemChanged( vlc_object_t *p_this, const char *psz_variable,
697                         vlc_value_t oval, vlc_value_t nval, void *param )
698 {
699     PLModel *p_model = (PLModel *) param;
700     PLEvent *event = new PLEvent( ItemUpdate_Type, nval.i_int );
701     QApplication::postEvent( p_model, static_cast<QEvent*>(event) );
702     return VLC_SUCCESS;
703 }
704
705 static int ItemDeleted( vlc_object_t *p_this, const char *psz_variable,
706                         vlc_value_t oval, vlc_value_t nval, void *param )
707 {
708     PLModel *p_model = (PLModel *) param;
709     PLEvent *event = new PLEvent( ItemDelete_Type, nval.i_int );
710     QApplication::postEvent( p_model, static_cast<QEvent*>(event) );
711     return VLC_SUCCESS;
712 }
713
714 static int ItemAppended( vlc_object_t *p_this, const char *psz_variable,
715                          vlc_value_t oval, vlc_value_t nval, void *param )
716 {
717     PLModel *p_model = (PLModel *) param;
718     playlist_add_t *p_add = (playlist_add_t *)malloc( sizeof( playlist_add_t));
719     memcpy( p_add, nval.p_address, sizeof( playlist_add_t ) );
720
721     if( ++p_model->i_items_to_append >= 50 )
722     {
723         p_model->b_need_update = VLC_TRUE;
724         return VLC_SUCCESS;
725     }
726     PLEvent *event = new PLEvent(  p_add );
727     QApplication::postEvent( p_model, static_cast<QEvent*>(event) );
728     return VLC_SUCCESS;
729 }