1 /*****************************************************************************
2 * playlist_model.cpp : Manage playlist model
3 ****************************************************************************
4 * Copyright (C) 2006 the VideoLAN team
7 * Authors: Clément Stenac <zorglub@videolan.org>
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.
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.
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 #define PLI_NAME( p ) p ? p->p_input->psz_name : "null"
29 #include <QApplication>
32 #include "playlist_model.hpp"
33 #include <vlc_intf_strings.h>
35 #include "pixmaps/type_unknown.xpm"
36 #include "pixmaps/type_afile.xpm"
37 #include "pixmaps/type_vfile.xpm"
38 #include "pixmaps/type_net.xpm"
39 #include "pixmaps/type_card.xpm"
40 #include "pixmaps/type_disc.xpm"
41 #include "pixmaps/type_cdda.xpm"
42 #include "pixmaps/type_directory.xpm"
43 #include "pixmaps/type_playlist.xpm"
44 #include "pixmaps/type_node.xpm"
46 QIcon PLModel::icons[ITEM_TYPE_NUMBER];
48 static int PlaylistChanged( vlc_object_t *, const char *,
49 vlc_value_t, vlc_value_t, void * );
50 static int PlaylistNext( vlc_object_t *, const char *,
51 vlc_value_t, vlc_value_t, void * );
52 static int ItemChanged( vlc_object_t *, const char *,
53 vlc_value_t, vlc_value_t, void * );
54 static int ItemAppended( vlc_object_t *p_this, const char *psz_variable,
55 vlc_value_t oval, vlc_value_t nval, void *param );
56 static int ItemDeleted( vlc_object_t *p_this, const char *psz_variable,
57 vlc_value_t oval, vlc_value_t nval, void *param );
59 /*************************************************************************
60 * Playlist item implementation
61 *************************************************************************/
70 void PLItem::init( int _i_id, int _i_input_id, PLItem *parent, PLModel *m)
73 i_id = _i_id; i_input_id = _i_input_id;
81 PLItem::PLItem( int _i_id, int _i_input_id, PLItem *parent, PLModel *m)
83 init( _i_id, _i_input_id, parent, m );
86 PLItem::PLItem( playlist_item_t * p_item, PLItem *parent, PLModel *m )
88 init( p_item->i_id, p_item->p_input->i_id, parent, m );
97 void PLItem::insertChild( PLItem *item, int i_pos, bool signal )
101 model->beginInsertRows( model->index( this , 0 ), i_pos, i_pos );
102 children.insert( i_pos, item );
104 model->endInsertRows();
107 void PLItem::remove( PLItem *removed )
109 assert( model && parentItem );
110 int i_index = parentItem->children.indexOf( removed );
111 model->beginRemoveRows( model->index( parentItem, 0 ), i_index, i_index );
112 parentItem->children.removeAt( i_index );
113 model->endRemoveRows();
116 int PLItem::row() const
119 return parentItem->children.indexOf(const_cast<PLItem*>(this));
123 void PLItem::update( playlist_item_t *p_item, bool iscurrent )
125 char psz_duration[MSTRTIME_MAX_SIZE];
126 assert( p_item->p_input->i_id == i_input_id );
127 strings[0] = QString::fromUtf8( p_item->p_input->psz_name );
128 if( p_item->p_input->p_meta )
130 strings[1] = QString::fromUtf8( p_item->p_input->p_meta->psz_artist );
132 secstotimestr( psz_duration, p_item->p_input->i_duration / 1000000 );
133 strings[2] = QString( psz_duration );
134 type = p_item->p_input->i_type;
136 if( current && p_item->p_input->p_meta &&
137 p_item->p_input->p_meta->psz_arturl &&
138 !strncmp( p_item->p_input->p_meta->psz_arturl, "file://", 7 ) )
140 model->sendArt( qfu( p_item->p_input->p_meta->psz_arturl ) );
144 /*************************************************************************
145 * Playlist model implementation
146 *************************************************************************/
148 PLModel::PLModel( playlist_t *_p_playlist,
149 playlist_item_t * p_root, int _i_depth, QObject *parent)
150 : QAbstractItemModel(parent)
153 assert( i_depth == 1 || i_depth == -1 );
154 p_playlist= _p_playlist;
155 i_items_to_append = 0;
156 b_need_update = false;
158 i_cached_input_id = -1;
159 i_popup_item = i_popup_parent = -1;
161 #define ADD_ICON(type, x) icons[ITEM_TYPE_##type] = QIcon( QPixmap( type_##x##_xpm ) );
162 ADD_ICON( UNKNOWN , unknown );
163 ADD_ICON( AFILE,afile );
164 ADD_ICON( VFILE, vfile );
165 ADD_ICON( DIRECTORY, directory );
166 ADD_ICON( DISC, disc );
167 ADD_ICON( CDDA, cdda );
168 ADD_ICON( CARD, card );
169 ADD_ICON( NET, net );
170 ADD_ICON( PLAYLIST, playlist );
171 ADD_ICON( NODE, node );
185 Qt::DropActions PLModel::supportedDropActions() const
187 return Qt::CopyAction;
190 Qt::ItemFlags PLModel::flags(const QModelIndex &index) const
192 Qt::ItemFlags defaultFlags = QAbstractItemModel::flags(index);
193 if( index.isValid() )
194 return Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | defaultFlags;
196 return Qt::ItemIsDropEnabled | defaultFlags;
199 QStringList PLModel::mimeTypes() const
202 types << "vlc/playlist-item-id";
206 QMimeData *PLModel::mimeData(const QModelIndexList &indexes) const
208 QMimeData *mimeData = new QMimeData();
209 QByteArray encodedData;
210 QDataStream stream(&encodedData, QIODevice::WriteOnly);
212 foreach (QModelIndex index, indexes) {
213 if (index.isValid() && index.column() == 0 )
214 stream << itemId(index);
216 mimeData->setData("vlc/playlist-item-id", encodedData);
220 bool PLModel::dropMimeData(const QMimeData *data, Qt::DropAction action,
221 int row, int column, const QModelIndex &target)
223 if ( data->hasFormat("vlc/playlist-item-id") )
225 if (action == Qt::IgnoreAction)
229 if( target.isValid() )
230 targetItem = static_cast<PLItem*>( target.internalPointer() );
232 targetItem = rootItem;
234 QByteArray encodedData = data->data("vlc/playlist-item-id");
235 QDataStream stream(&encodedData, QIODevice::ReadOnly);
237 PLItem *newParentItem;
238 while (!stream.atEnd())
245 playlist_item_t *p_target =
246 playlist_ItemGetById( p_playlist, targetItem->i_id );
247 playlist_item_t *p_src = playlist_ItemGetById( p_playlist, srcId );
249 if( !p_target || !p_src )
255 if( p_target->i_children == -1 ) /* A leaf */
257 PLItem *parentItem = targetItem->parent();
258 assert( parentItem );
259 playlist_item_t *p_parent =
260 playlist_ItemGetById( p_playlist, parentItem->i_id );
266 for( i = 0 ; i< p_parent->i_children ; i++ )
267 if( p_parent->pp_children[i] == p_target ) break;
268 playlist_TreeMove( p_playlist, p_src, p_parent, i );
269 newParentItem = parentItem;
273 /* \todo: if we drop on a top-level node, use copy instead ? */
274 playlist_TreeMove( p_playlist, p_src, p_target, 0 );
276 newParentItem = targetItem;
278 /* Remove from source */
279 PLItem *srcItem = FindByInput( rootItem, p_src->p_input->i_id );
280 srcItem->remove( srcItem );
281 /* Display at new destination */
282 PLItem *newItem = new PLItem( p_src, newParentItem, this );
283 newParentItem->insertChild( newItem, i, true );
284 UpdateTreeItem( p_src, newItem, true );
285 if( p_src->i_children != -1 )
286 UpdateNodeChildren( newItem );
294 void PLModel::addCallbacks()
296 /* Some global changes happened -> Rebuild all */
297 var_AddCallback( p_playlist, "intf-change", PlaylistChanged, this );
298 /* We went to the next item */
299 var_AddCallback( p_playlist, "playlist-current", PlaylistNext, this );
300 /* One item has been updated */
301 var_AddCallback( p_playlist, "item-change", ItemChanged, this );
302 var_AddCallback( p_playlist, "item-append", ItemAppended, this );
303 var_AddCallback( p_playlist, "item-deleted", ItemDeleted, this );
306 void PLModel::delCallbacks()
308 var_DelCallback( p_playlist, "item-change", ItemChanged, this );
309 var_DelCallback( p_playlist, "playlist-current", PlaylistNext, this );
310 var_DelCallback( p_playlist, "intf-change", PlaylistChanged, this );
311 var_DelCallback( p_playlist, "item-append", ItemAppended, this );
312 var_DelCallback( p_playlist, "item-deleted", ItemDeleted, this );
315 void PLModel::activateItem( const QModelIndex &index )
317 assert( index.isValid() );
318 PLItem *item = static_cast<PLItem*>(index.internalPointer());
321 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id );
322 activateItem( p_item );
325 /* Must be entered with lock */
326 void PLModel::activateItem( playlist_item_t *p_item )
328 if( !p_item ) return;
329 playlist_item_t *p_parent = p_item;
332 if( p_parent->i_id == rootItem->i_id ) break;
333 p_parent = p_parent->p_parent;
336 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, p_parent, p_item );
339 /****************** Base model mandatory implementations *****************/
340 QVariant PLModel::data(const QModelIndex &index, int role) const
342 if(!index.isValid() ) return QVariant();
343 PLItem *item = static_cast<PLItem*>(index.internalPointer());
344 if( role == Qt::DisplayRole )
346 return QVariant( item->columnString( index.column() ) );
348 else if( role == Qt::DecorationRole && index.column() == 0 )
350 if( item->type >= 0 )
351 return QVariant( PLModel::icons[item->type] );
353 else if( role == Qt::FontRole )
355 if( item->current == true )
357 QFont f; f.setBold( true ); return QVariant( f );
363 bool PLModel::isCurrent( const QModelIndex &index )
365 assert( index.isValid() );
366 return static_cast<PLItem*>(index.internalPointer())->current;
369 int PLModel::itemId( const QModelIndex &index ) const
371 assert( index.isValid() );
372 return static_cast<PLItem*>(index.internalPointer())->i_id;
375 QVariant PLModel::headerData( int section, Qt::Orientation orientation,
378 if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
379 return QVariant( rootItem->columnString( section ) );
383 QModelIndex PLModel::index(int row, int column, const QModelIndex &parent)
387 if (!parent.isValid())
388 parentItem = rootItem;
390 parentItem = static_cast<PLItem*>(parent.internalPointer());
392 PLItem *childItem = parentItem->child(row);
394 return createIndex(row, column, childItem);
396 return QModelIndex();
399 /* Return the index of a given item */
400 QModelIndex PLModel::index( PLItem *item, int column ) const
402 if( !item ) return QModelIndex();
403 const PLItem *parent = item->parent();
405 return createIndex( parent->children.lastIndexOf( item ),
407 return QModelIndex();
410 QModelIndex PLModel::parent(const QModelIndex &index) const
412 if( !index.isValid() ) return QModelIndex();
414 PLItem *childItem = static_cast<PLItem*>(index.internalPointer());
415 if( !childItem ) { msg_Err( p_playlist, "NULL CHILD \n" ); return QModelIndex(); }
416 PLItem *parentItem = childItem->parent();
417 if( !parentItem || parentItem == rootItem ) return QModelIndex();
418 if( ! parentItem->parentItem )
420 msg_Err( p_playlist, "No parent parent, trying row 0 " );
421 msg_Err( p_playlist, "----- PLEASE REPORT THIS ------" );
422 return createIndex( 0, 0, parentItem );
424 QModelIndex ind = createIndex(parentItem->row(), 0, parentItem);
428 int PLModel::columnCount( const QModelIndex &i) const
430 if( i_depth == 1 ) return 1;
434 int PLModel::childrenCount(const QModelIndex &parent) const
436 return rowCount( parent );
439 int PLModel::rowCount(const QModelIndex &parent) const
443 if (!parent.isValid())
444 parentItem = rootItem;
446 parentItem = static_cast<PLItem*>(parent.internalPointer());
448 return parentItem->childCount();
451 /************************* General playlist status ***********************/
453 bool PLModel::hasRandom()
455 if( var_GetBool( p_playlist, "random" ) ) return true;
458 bool PLModel::hasRepeat()
460 if( var_GetBool( p_playlist, "repeat" ) ) return true;
463 bool PLModel::hasLoop()
465 if( var_GetBool( p_playlist, "loop" ) ) return true;
468 void PLModel::setLoop( bool on )
470 var_SetBool( p_playlist, "loop", on ? VLC_TRUE:VLC_FALSE );
471 config_PutInt( p_playlist, "loop", on ? 1: 0 );
473 void PLModel::setRepeat( bool on )
475 var_SetBool( p_playlist, "repeat", on ? VLC_TRUE:VLC_FALSE );
476 config_PutInt( p_playlist, "repeat", on ? 1: 0 );
478 void PLModel::setRandom( bool on )
480 var_SetBool( p_playlist, "random", on ? VLC_TRUE:VLC_FALSE );
481 config_PutInt( p_playlist, "random", on ? 1: 0 );
484 /************************* Lookups *****************************/
486 PLItem *PLModel::FindById( PLItem *root, int i_id )
488 return FindInner( root, i_id, false );
491 PLItem *PLModel::FindByInput( PLItem *root, int i_id )
493 return FindInner( root, i_id, true );
496 #define CACHE( i, p ) { i_cached_id = i; p_cached_item = p; }
497 #define ICACHE( i, p ) { i_cached_input_id = i; p_cached_item_bi = p; }
499 PLItem * PLModel::FindInner( PLItem *root, int i_id, bool b_input )
501 if( ( !b_input && i_cached_id == i_id) ||
502 ( b_input && i_cached_input_id ==i_id ) )
504 return b_input ? p_cached_item_bi : p_cached_item;
507 if( !b_input && root->i_id == i_id )
512 else if( b_input && root->i_input_id == i_id )
514 ICACHE( i_id, root );
518 QList<PLItem *>::iterator it = root->children.begin();
519 while ( it != root->children.end() )
521 if( !b_input && (*it)->i_id == i_id )
523 CACHE( i_id, (*it) );
524 return p_cached_item;
526 else if( b_input && (*it)->i_input_id == i_id )
528 ICACHE( i_id, (*it) );
529 return p_cached_item_bi;
531 if( (*it)->children.size() )
533 PLItem *childFound = FindInner( (*it), i_id, b_input );
537 ICACHE( i_id, childFound )
539 CACHE( i_id, childFound )
551 /************************* Updates handling *****************************/
552 void PLModel::customEvent( QEvent *event )
554 int type = event->type();
555 if( type != ItemUpdate_Type && type != ItemAppend_Type &&
556 type != ItemDelete_Type && type != PLUpdate_Type )
559 PLEvent *ple = static_cast<PLEvent *>(event);
561 if( type == ItemUpdate_Type )
562 ProcessInputItemUpdate( ple->i_id );
563 else if( type == ItemAppend_Type )
564 ProcessItemAppend( ple->p_add );
565 else if( type == ItemDelete_Type )
566 ProcessItemRemoval( ple->i_id );
571 /**** Events processing ****/
572 void PLModel::ProcessInputItemUpdate( int i_input_id )
574 if( i_input_id <= 0 ) return;
575 PLItem *item = FindByInput( rootItem, i_input_id );
577 UpdateTreeItem( item, true );
580 void PLModel::ProcessItemRemoval( int i_id )
582 if( i_id <= 0 ) return;
583 if( i_id == i_cached_id ) i_cached_id = -1;
584 i_cached_input_id = -1;
585 PLItem *item = FindById( rootItem, i_id );
587 item->remove( item );
590 void PLModel::ProcessItemAppend( playlist_add_t *p_add )
592 playlist_item_t *p_item = NULL;
593 PLItem *newItem = NULL;
595 if( b_need_update ) return;
597 PLItem *nodeItem = FindById( rootItem, p_add->i_node );
599 if( !nodeItem ) goto end;
601 p_item = playlist_ItemGetById( p_playlist, p_add->i_item );
602 if( !p_item || p_item->i_flags & PLAYLIST_DBL_FLAG ) goto end;
603 if( i_depth == 1 && p_item->p_parent &&
604 p_item->p_parent->i_id != rootItem->i_id )
607 newItem = new PLItem( p_item, nodeItem, this );
608 nodeItem->appendChild( newItem );
609 UpdateTreeItem( p_item, newItem, true );
616 void PLModel::rebuild()
621 void PLModel::rebuild( playlist_item_t *p_root )
623 /* Remove callbacks before locking to avoid deadlocks */
625 /* Invalidate cache */
626 i_cached_id = i_cached_input_id = -1;
632 beginRemoveRows( index( rootItem, 0 ), 0,
633 rootItem->children.size() -1 );
634 qDeleteAll( rootItem->children );
635 rootItem->children.clear();
640 //if( rootItem ) delete rootItem;
641 rootItem = new PLItem( p_root, NULL, this );
642 rootItem->strings[0] = qtr("Name");
643 rootItem->strings[1] = qtr("Artist");
644 rootItem->strings[2] = qtr("Duration");
647 /* Recreate from root */
648 UpdateNodeChildren( rootItem );
649 if( p_playlist->status.p_item )
651 PLItem *currentItem = FindByInput( rootItem,
652 p_playlist->status.p_item->p_input->i_id );
655 UpdateTreeItem( p_playlist->status.p_item, currentItem,
661 /* And signal the view */
662 emit layoutChanged();
666 /* This function must be entered WITH the playlist lock */
667 void PLModel::UpdateNodeChildren( PLItem *root )
669 playlist_item_t *p_node = playlist_ItemGetById( p_playlist, root->i_id );
670 UpdateNodeChildren( p_node, root );
673 /* This function must be entered WITH the playlist lock */
674 void PLModel::UpdateNodeChildren( playlist_item_t *p_node, PLItem *root )
676 for( int i = 0; i < p_node->i_children ; i++ )
678 if( p_node->pp_children[i]->i_flags & PLAYLIST_DBL_FLAG ) continue;
679 PLItem *newItem = new PLItem( p_node->pp_children[i], root, this );
680 root->appendChild( newItem, false );
681 UpdateTreeItem( newItem, false, true );
682 if( i_depth != 1 && p_node->pp_children[i]->i_children != -1 )
683 UpdateNodeChildren( p_node->pp_children[i], newItem );
687 /* This function must be entered WITH the playlist lock */
688 void PLModel::UpdateTreeItem( PLItem *item, bool signal, bool force )
690 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id );
691 UpdateTreeItem( p_item, item, signal, force );
694 /* This function must be entered WITH the playlist lock */
695 void PLModel::UpdateTreeItem( playlist_item_t *p_item, PLItem *item,
696 bool signal, bool force )
698 if( !force && i_depth == 1 && p_item->p_parent &&
699 p_item->p_parent->i_id != rootItem->i_id )
701 item->update( p_item, p_item == p_playlist->status.p_item );
703 emit dataChanged( index( item, 0 ) , index( item, 1 ) );
706 /************************* Actions ******************************/
708 void PLModel::sendArt( QString url )
710 QString arturl = url.replace( "file://",QString("" ) );
711 emit artSet( arturl );
715 * Deletion, here we have to do a ugly slow hack as we retrieve the full
716 * list of indexes to delete at once: when we delete a node and all of
717 * its children, we need to update the list.
718 * Todo: investigate whethere we can use ranges to be sure to delete all items?
720 void PLModel::doDelete( QModelIndexList selected )
722 for( int i = selected.size() -1 ; i >= 0; i-- )
724 QModelIndex index = selected[i];
725 if( index.column() != 0 ) continue;
726 PLItem *item = static_cast<PLItem*>(index.internalPointer());
729 if( item->children.size() )
730 recurseDelete( item->children, &selected );
731 doDeleteItem( item, &selected );
736 void PLModel::recurseDelete( QList<PLItem*> children, QModelIndexList *fullList)
738 for( int i = children.size() - 1; i >= 0 ; i-- )
740 PLItem *item = children[i];
741 if( item->children.size() )
742 recurseDelete( item->children, fullList );
743 doDeleteItem( item, fullList );
747 void PLModel::doDeleteItem( PLItem *item, QModelIndexList *fullList )
749 QModelIndex deleteIndex = index( item, 0 );
750 fullList->removeAll( deleteIndex );
753 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id );
758 if( p_item->i_children == -1 )
759 playlist_DeleteAllFromInput( p_playlist, item->i_input_id );
761 playlist_NodeDelete( p_playlist, p_item, VLC_TRUE, VLC_FALSE );
762 /* And finally, remove it from the tree */
763 item->remove( item );
767 /******* Volume III: Sorting and searching ********/
768 void PLModel::sort( int column, Qt::SortOrder order )
771 playlist_item_t *p_root = playlist_ItemGetById( p_playlist, rootItem->i_id );
775 case 0: i_mode = SORT_TITLE_NODES_FIRST;break;
776 case 1: i_mode = SORT_ARTIST;break;
777 case 2: i_mode = SORT_DURATION; break;
778 default: i_mode = SORT_TITLE_NODES_FIRST; break;
781 playlist_RecursiveNodeSort( p_playlist, p_root, i_mode,
782 order == Qt::AscendingOrder ? ORDER_NORMAL :
788 void PLModel::search( QString search_text )
790 /** \todo Fire the search with a small delay ? */
792 playlist_item_t *p_root = playlist_ItemGetById( p_playlist,rootItem->i_id );
794 char *psz_name = search_text.toUtf8().data();
795 playlist_LiveSearchUpdate( p_playlist , p_root, psz_name );
800 /*********** Popup *********/
801 void PLModel::popup( QModelIndex & index, QPoint &point, QModelIndexList list )
803 assert( index.isValid() );
805 playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
809 i_popup_item = p_item->i_id;
810 i_popup_parent = p_item->p_parent ? p_item->p_parent->i_id : -1;
812 current_selection = list;
813 QMenu *menu = new QMenu;
814 menu->addAction( qfu(I_POP_PLAY), this, SLOT( popupPlay() ) );
815 menu->addAction( qfu(I_POP_DEL), this, SLOT( popupDel() ) );
816 menu->addSeparator();
817 menu->addAction( qfu(I_POP_STREAM), this, SLOT( popupStream() ) );
818 menu->addAction( qfu(I_POP_SAVE), this, SLOT( popupSave() ) );
819 menu->addSeparator();
820 menu->addAction( qfu(I_POP_INFO), this, SLOT( popupInfo() ) );
821 if( p_item->i_children > -1 )
823 menu->addSeparator();
824 menu->addAction( qfu(I_POP_SORT), this, SLOT( popupSort() ) );
825 menu->addAction( qfu(I_POP_ADD), this, SLOT( popupAdd() ) );
827 menu->popup( point );
833 void PLModel::popupDel()
835 doDelete( current_selection );
837 void PLModel::popupPlay()
840 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, i_popup_item );
841 activateItem( p_item );
845 void PLModel::popupInfo()
847 fprintf( stderr, "Popup Info is NOT implemented\n" );
850 void PLModel::popupStream()
852 fprintf( stderr, "Stream not implemented\n" );
854 void PLModel::popupSave()
856 fprintf( stderr, "Save not implemented\n" );
859 /**********************************************************************
861 **********************************************************************/
862 static int PlaylistChanged( vlc_object_t *p_this, const char *psz_variable,
863 vlc_value_t oval, vlc_value_t nval, void *param )
865 PLModel *p_model = (PLModel *) param;
866 PLEvent *event = new PLEvent( PLUpdate_Type, 0 );
867 QApplication::postEvent( p_model, static_cast<QEvent*>(event) );
871 static int PlaylistNext( vlc_object_t *p_this, const char *psz_variable,
872 vlc_value_t oval, vlc_value_t nval, void *param )
874 PLModel *p_model = (PLModel *) param;
875 PLEvent *event = new PLEvent( ItemUpdate_Type, oval.i_int );
876 QApplication::postEvent( p_model, static_cast<QEvent*>(event) );
877 event = new PLEvent( ItemUpdate_Type, nval.i_int );
878 QApplication::postEvent( p_model, static_cast<QEvent*>(event) );
882 static int ItemChanged( vlc_object_t *p_this, const char *psz_variable,
883 vlc_value_t oval, vlc_value_t nval, void *param )
885 PLModel *p_model = (PLModel *) param;
886 PLEvent *event = new PLEvent( ItemUpdate_Type, nval.i_int );
887 QApplication::postEvent( p_model, static_cast<QEvent*>(event) );
891 static int ItemDeleted( vlc_object_t *p_this, const char *psz_variable,
892 vlc_value_t oval, vlc_value_t nval, void *param )
894 PLModel *p_model = (PLModel *) param;
895 PLEvent *event = new PLEvent( ItemDelete_Type, nval.i_int );
896 QApplication::postEvent( p_model, static_cast<QEvent*>(event) );
900 static int ItemAppended( vlc_object_t *p_this, const char *psz_variable,
901 vlc_value_t oval, vlc_value_t nval, void *param )
903 PLModel *p_model = (PLModel *) param;
904 playlist_add_t *p_add = (playlist_add_t *)malloc( sizeof( playlist_add_t));
905 memcpy( p_add, nval.p_address, sizeof( playlist_add_t ) );
907 if( ++p_model->i_items_to_append >= 50 )
909 // p_model->b_need_update = VLC_TRUE;
910 // return VLC_SUCCESS;
912 PLEvent *event = new PLEvent( p_add );
913 QApplication::postEvent( p_model, static_cast<QEvent*>(event) );