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 )
254 if( p_target->i_children == -1 ) /* A leaf */
256 PLItem *parentItem = targetItem->parent();
257 assert( parentItem );
258 playlist_item_t *p_parent =
259 playlist_ItemGetById( p_playlist, parentItem->i_id );
265 for( i = 0 ; i< p_parent->i_children ; i++ )
266 if( p_parent->pp_children[i] == p_target ) break;
267 playlist_TreeMove( p_playlist, p_src, p_parent, i );
268 newParentItem = parentItem;
272 /* \todo: if we drop on a top-level node, use copy instead ? */
273 playlist_TreeMove( p_playlist, p_src, p_target, 0 );
275 newParentItem = targetItem;
277 /* Remove from source */
278 PLItem *srcItem = FindById( rootItem, p_src->i_id );
279 // We dropped on the source selector. Ask the dialog to forward
283 emit shouldRemove( p_src->i_id );
286 srcItem->remove( srcItem );
288 /* Display at new destination */
289 PLItem *newItem = new PLItem( p_src, newParentItem, this );
290 newParentItem->insertChild( newItem, i, true );
291 UpdateTreeItem( p_src, newItem, true );
292 if( p_src->i_children != -1 )
293 UpdateNodeChildren( newItem );
300 void PLModel::removeItem( int i_id )
302 PLItem *item = FindById( rootItem,i_id );
303 if( item ) item->remove( item );
306 void PLModel::addCallbacks()
308 /* Some global changes happened -> Rebuild all */
309 var_AddCallback( p_playlist, "intf-change", PlaylistChanged, this );
310 /* We went to the next item */
311 var_AddCallback( p_playlist, "playlist-current", PlaylistNext, this );
312 /* One item has been updated */
313 var_AddCallback( p_playlist, "item-change", ItemChanged, this );
314 var_AddCallback( p_playlist, "item-append", ItemAppended, this );
315 var_AddCallback( p_playlist, "item-deleted", ItemDeleted, this );
318 void PLModel::delCallbacks()
320 var_DelCallback( p_playlist, "item-change", ItemChanged, this );
321 var_DelCallback( p_playlist, "playlist-current", PlaylistNext, this );
322 var_DelCallback( p_playlist, "intf-change", PlaylistChanged, this );
323 var_DelCallback( p_playlist, "item-append", ItemAppended, this );
324 var_DelCallback( p_playlist, "item-deleted", ItemDeleted, this );
327 void PLModel::activateItem( const QModelIndex &index )
329 assert( index.isValid() );
330 PLItem *item = static_cast<PLItem*>(index.internalPointer());
333 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id );
334 activateItem( p_item );
337 /* Must be entered with lock */
338 void PLModel::activateItem( playlist_item_t *p_item )
340 if( !p_item ) return;
341 playlist_item_t *p_parent = p_item;
344 if( p_parent->i_id == rootItem->i_id ) break;
345 p_parent = p_parent->p_parent;
348 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, p_parent, p_item );
351 /****************** Base model mandatory implementations *****************/
352 QVariant PLModel::data(const QModelIndex &index, int role) const
354 if(!index.isValid() ) return QVariant();
355 PLItem *item = static_cast<PLItem*>(index.internalPointer());
356 if( role == Qt::DisplayRole )
358 return QVariant( item->columnString( index.column() ) );
360 else if( role == Qt::DecorationRole && index.column() == 0 )
362 if( item->type >= 0 )
363 return QVariant( PLModel::icons[item->type] );
365 else if( role == Qt::FontRole )
367 if( item->current == true )
369 QFont f; f.setBold( true ); return QVariant( f );
375 bool PLModel::isCurrent( const QModelIndex &index )
377 assert( index.isValid() );
378 return static_cast<PLItem*>(index.internalPointer())->current;
381 int PLModel::itemId( const QModelIndex &index ) const
383 assert( index.isValid() );
384 return static_cast<PLItem*>(index.internalPointer())->i_id;
387 QVariant PLModel::headerData( int section, Qt::Orientation orientation,
390 if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
391 return QVariant( rootItem->columnString( section ) );
395 QModelIndex PLModel::index(int row, int column, const QModelIndex &parent)
399 if (!parent.isValid())
400 parentItem = rootItem;
402 parentItem = static_cast<PLItem*>(parent.internalPointer());
404 PLItem *childItem = parentItem->child(row);
406 return createIndex(row, column, childItem);
408 return QModelIndex();
411 /* Return the index of a given item */
412 QModelIndex PLModel::index( PLItem *item, int column ) const
414 if( !item ) return QModelIndex();
415 const PLItem *parent = item->parent();
417 return createIndex( parent->children.lastIndexOf( item ),
419 return QModelIndex();
422 QModelIndex PLModel::parent(const QModelIndex &index) const
424 if( !index.isValid() ) return QModelIndex();
426 PLItem *childItem = static_cast<PLItem*>(index.internalPointer());
427 if( !childItem ) { msg_Err( p_playlist, "NULL CHILD \n" ); return QModelIndex(); }
428 PLItem *parentItem = childItem->parent();
429 if( !parentItem || parentItem == rootItem ) return QModelIndex();
430 if( ! parentItem->parentItem )
432 msg_Err( p_playlist, "No parent parent, trying row 0 " );
433 msg_Err( p_playlist, "----- PLEASE REPORT THIS ------" );
434 return createIndex( 0, 0, parentItem );
436 QModelIndex ind = createIndex(parentItem->row(), 0, parentItem);
440 int PLModel::columnCount( const QModelIndex &i) const
442 if( i_depth == 1 ) return 1;
446 int PLModel::childrenCount(const QModelIndex &parent) const
448 return rowCount( parent );
451 int PLModel::rowCount(const QModelIndex &parent) const
455 if (!parent.isValid())
456 parentItem = rootItem;
458 parentItem = static_cast<PLItem*>(parent.internalPointer());
460 return parentItem->childCount();
463 /************************* General playlist status ***********************/
465 bool PLModel::hasRandom()
467 if( var_GetBool( p_playlist, "random" ) ) return true;
470 bool PLModel::hasRepeat()
472 if( var_GetBool( p_playlist, "repeat" ) ) return true;
475 bool PLModel::hasLoop()
477 if( var_GetBool( p_playlist, "loop" ) ) return true;
480 void PLModel::setLoop( bool on )
482 var_SetBool( p_playlist, "loop", on ? VLC_TRUE:VLC_FALSE );
483 config_PutInt( p_playlist, "loop", on ? 1: 0 );
485 void PLModel::setRepeat( bool on )
487 var_SetBool( p_playlist, "repeat", on ? VLC_TRUE:VLC_FALSE );
488 config_PutInt( p_playlist, "repeat", on ? 1: 0 );
490 void PLModel::setRandom( bool on )
492 var_SetBool( p_playlist, "random", on ? VLC_TRUE:VLC_FALSE );
493 config_PutInt( p_playlist, "random", on ? 1: 0 );
496 /************************* Lookups *****************************/
498 PLItem *PLModel::FindById( PLItem *root, int i_id )
500 return FindInner( root, i_id, false );
503 PLItem *PLModel::FindByInput( PLItem *root, int i_id )
505 return FindInner( root, i_id, true );
508 #define CACHE( i, p ) { i_cached_id = i; p_cached_item = p; }
509 #define ICACHE( i, p ) { i_cached_input_id = i; p_cached_item_bi = p; }
511 PLItem * PLModel::FindInner( PLItem *root, int i_id, bool b_input )
513 if( ( !b_input && i_cached_id == i_id) ||
514 ( b_input && i_cached_input_id ==i_id ) )
516 return b_input ? p_cached_item_bi : p_cached_item;
519 if( !b_input && root->i_id == i_id )
524 else if( b_input && root->i_input_id == i_id )
526 ICACHE( i_id, root );
530 QList<PLItem *>::iterator it = root->children.begin();
531 while ( it != root->children.end() )
533 if( !b_input && (*it)->i_id == i_id )
535 CACHE( i_id, (*it) );
536 return p_cached_item;
538 else if( b_input && (*it)->i_input_id == i_id )
540 ICACHE( i_id, (*it) );
541 return p_cached_item_bi;
543 if( (*it)->children.size() )
545 PLItem *childFound = FindInner( (*it), i_id, b_input );
549 ICACHE( i_id, childFound )
551 CACHE( i_id, childFound )
563 /************************* Updates handling *****************************/
564 void PLModel::customEvent( QEvent *event )
566 int type = event->type();
567 if( type != ItemUpdate_Type && type != ItemAppend_Type &&
568 type != ItemDelete_Type && type != PLUpdate_Type )
571 PLEvent *ple = static_cast<PLEvent *>(event);
573 if( type == ItemUpdate_Type )
574 ProcessInputItemUpdate( ple->i_id );
575 else if( type == ItemAppend_Type )
576 ProcessItemAppend( ple->p_add );
577 else if( type == ItemDelete_Type )
578 ProcessItemRemoval( ple->i_id );
583 /**** Events processing ****/
584 void PLModel::ProcessInputItemUpdate( int i_input_id )
586 if( i_input_id <= 0 ) return;
587 PLItem *item = FindByInput( rootItem, i_input_id );
589 UpdateTreeItem( item, true );
592 void PLModel::ProcessItemRemoval( int i_id )
594 if( i_id <= 0 ) return;
595 if( i_id == i_cached_id ) i_cached_id = -1;
596 i_cached_input_id = -1;
597 PLItem *item = FindById( rootItem, i_id );
599 item->remove( item );
602 void PLModel::ProcessItemAppend( playlist_add_t *p_add )
604 playlist_item_t *p_item = NULL;
605 PLItem *newItem = NULL;
607 if( b_need_update ) return;
609 PLItem *nodeItem = FindById( rootItem, p_add->i_node );
611 if( !nodeItem ) goto end;
613 p_item = playlist_ItemGetById( p_playlist, p_add->i_item );
614 if( !p_item || p_item->i_flags & PLAYLIST_DBL_FLAG ) goto end;
615 if( i_depth == 1 && p_item->p_parent &&
616 p_item->p_parent->i_id != rootItem->i_id )
619 newItem = new PLItem( p_item, nodeItem, this );
620 nodeItem->appendChild( newItem );
621 UpdateTreeItem( p_item, newItem, true );
628 void PLModel::rebuild()
633 void PLModel::rebuild( playlist_item_t *p_root )
635 /* Remove callbacks before locking to avoid deadlocks */
637 /* Invalidate cache */
638 i_cached_id = i_cached_input_id = -1;
644 beginRemoveRows( index( rootItem, 0 ), 0,
645 rootItem->children.size() -1 );
646 qDeleteAll( rootItem->children );
647 rootItem->children.clear();
652 //if( rootItem ) delete rootItem;
653 rootItem = new PLItem( p_root, NULL, this );
654 rootItem->strings[0] = qtr("Name");
655 rootItem->strings[1] = qtr("Artist");
656 rootItem->strings[2] = qtr("Duration");
659 /* Recreate from root */
660 UpdateNodeChildren( rootItem );
661 if( p_playlist->status.p_item )
663 PLItem *currentItem = FindByInput( rootItem,
664 p_playlist->status.p_item->p_input->i_id );
667 UpdateTreeItem( p_playlist->status.p_item, currentItem,
673 /* And signal the view */
674 emit layoutChanged();
678 /* This function must be entered WITH the playlist lock */
679 void PLModel::UpdateNodeChildren( PLItem *root )
681 playlist_item_t *p_node = playlist_ItemGetById( p_playlist, root->i_id );
682 UpdateNodeChildren( p_node, root );
685 /* This function must be entered WITH the playlist lock */
686 void PLModel::UpdateNodeChildren( playlist_item_t *p_node, PLItem *root )
688 for( int i = 0; i < p_node->i_children ; i++ )
690 if( p_node->pp_children[i]->i_flags & PLAYLIST_DBL_FLAG ) continue;
691 PLItem *newItem = new PLItem( p_node->pp_children[i], root, this );
692 root->appendChild( newItem, false );
693 UpdateTreeItem( newItem, false, true );
694 if( i_depth != 1 && p_node->pp_children[i]->i_children != -1 )
695 UpdateNodeChildren( p_node->pp_children[i], newItem );
699 /* This function must be entered WITH the playlist lock */
700 void PLModel::UpdateTreeItem( PLItem *item, bool signal, bool force )
702 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id );
703 UpdateTreeItem( p_item, item, signal, force );
706 /* This function must be entered WITH the playlist lock */
707 void PLModel::UpdateTreeItem( playlist_item_t *p_item, PLItem *item,
708 bool signal, bool force )
710 if( !force && i_depth == 1 && p_item->p_parent &&
711 p_item->p_parent->i_id != rootItem->i_id )
713 item->update( p_item, p_item == p_playlist->status.p_item );
715 emit dataChanged( index( item, 0 ) , index( item, 1 ) );
718 /************************* Actions ******************************/
720 void PLModel::sendArt( QString url )
722 QString arturl = url.replace( "file://",QString("" ) );
723 emit artSet( arturl );
727 * Deletion, here we have to do a ugly slow hack as we retrieve the full
728 * list of indexes to delete at once: when we delete a node and all of
729 * its children, we need to update the list.
730 * Todo: investigate whethere we can use ranges to be sure to delete all items?
732 void PLModel::doDelete( QModelIndexList selected )
734 for( int i = selected.size() -1 ; i >= 0; i-- )
736 QModelIndex index = selected[i];
737 if( index.column() != 0 ) continue;
738 PLItem *item = static_cast<PLItem*>(index.internalPointer());
741 if( item->children.size() )
742 recurseDelete( item->children, &selected );
743 doDeleteItem( item, &selected );
748 void PLModel::recurseDelete( QList<PLItem*> children, QModelIndexList *fullList)
750 for( int i = children.size() - 1; i >= 0 ; i-- )
752 PLItem *item = children[i];
753 if( item->children.size() )
754 recurseDelete( item->children, fullList );
755 doDeleteItem( item, fullList );
759 void PLModel::doDeleteItem( PLItem *item, QModelIndexList *fullList )
761 QModelIndex deleteIndex = index( item, 0 );
762 fullList->removeAll( deleteIndex );
765 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id );
770 if( p_item->i_children == -1 )
771 playlist_DeleteAllFromInput( p_playlist, item->i_input_id );
773 playlist_NodeDelete( p_playlist, p_item, VLC_TRUE, VLC_FALSE );
774 /* And finally, remove it from the tree */
775 item->remove( item );
779 /******* Volume III: Sorting and searching ********/
780 void PLModel::sort( int column, Qt::SortOrder order )
783 playlist_item_t *p_root = playlist_ItemGetById( p_playlist, rootItem->i_id );
787 case 0: i_mode = SORT_TITLE_NODES_FIRST;break;
788 case 1: i_mode = SORT_ARTIST;break;
789 case 2: i_mode = SORT_DURATION; break;
790 default: i_mode = SORT_TITLE_NODES_FIRST; break;
793 playlist_RecursiveNodeSort( p_playlist, p_root, i_mode,
794 order == Qt::AscendingOrder ? ORDER_NORMAL :
800 void PLModel::search( QString search_text )
802 /** \todo Fire the search with a small delay ? */
804 playlist_item_t *p_root = playlist_ItemGetById( p_playlist,rootItem->i_id );
806 char *psz_name = search_text.toUtf8().data();
807 playlist_LiveSearchUpdate( p_playlist , p_root, psz_name );
812 /*********** Popup *********/
813 void PLModel::popup( QModelIndex & index, QPoint &point, QModelIndexList list )
815 assert( index.isValid() );
817 playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
821 i_popup_item = p_item->i_id;
822 i_popup_parent = p_item->p_parent ? p_item->p_parent->i_id : -1;
824 current_selection = list;
825 QMenu *menu = new QMenu;
826 menu->addAction( qfu(I_POP_PLAY), this, SLOT( popupPlay() ) );
827 menu->addAction( qfu(I_POP_DEL), this, SLOT( popupDel() ) );
828 menu->addSeparator();
829 menu->addAction( qfu(I_POP_STREAM), this, SLOT( popupStream() ) );
830 menu->addAction( qfu(I_POP_SAVE), this, SLOT( popupSave() ) );
831 menu->addSeparator();
832 menu->addAction( qfu(I_POP_INFO), this, SLOT( popupInfo() ) );
833 if( p_item->i_children > -1 )
835 menu->addSeparator();
836 menu->addAction( qfu(I_POP_SORT), this, SLOT( popupSort() ) );
837 menu->addAction( qfu(I_POP_ADD), this, SLOT( popupAdd() ) );
839 menu->popup( point );
845 void PLModel::popupDel()
847 doDelete( current_selection );
849 void PLModel::popupPlay()
852 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, i_popup_item );
853 activateItem( p_item );
857 void PLModel::popupInfo()
859 fprintf( stderr, "Popup Info is NOT implemented\n" );
862 void PLModel::popupStream()
864 fprintf( stderr, "Stream not implemented\n" );
866 void PLModel::popupSave()
868 fprintf( stderr, "Save not implemented\n" );
871 /**********************************************************************
873 **********************************************************************/
874 static int PlaylistChanged( vlc_object_t *p_this, const char *psz_variable,
875 vlc_value_t oval, vlc_value_t nval, void *param )
877 PLModel *p_model = (PLModel *) param;
878 PLEvent *event = new PLEvent( PLUpdate_Type, 0 );
879 QApplication::postEvent( p_model, static_cast<QEvent*>(event) );
883 static int PlaylistNext( vlc_object_t *p_this, const char *psz_variable,
884 vlc_value_t oval, vlc_value_t nval, void *param )
886 PLModel *p_model = (PLModel *) param;
887 PLEvent *event = new PLEvent( ItemUpdate_Type, oval.i_int );
888 QApplication::postEvent( p_model, static_cast<QEvent*>(event) );
889 event = new PLEvent( ItemUpdate_Type, nval.i_int );
890 QApplication::postEvent( p_model, static_cast<QEvent*>(event) );
894 static int ItemChanged( vlc_object_t *p_this, const char *psz_variable,
895 vlc_value_t oval, vlc_value_t nval, void *param )
897 PLModel *p_model = (PLModel *) param;
898 PLEvent *event = new PLEvent( ItemUpdate_Type, nval.i_int );
899 QApplication::postEvent( p_model, static_cast<QEvent*>(event) );
903 static int ItemDeleted( vlc_object_t *p_this, const char *psz_variable,
904 vlc_value_t oval, vlc_value_t nval, void *param )
906 PLModel *p_model = (PLModel *) param;
907 PLEvent *event = new PLEvent( ItemDelete_Type, nval.i_int );
908 QApplication::postEvent( p_model, static_cast<QEvent*>(event) );
912 static int ItemAppended( vlc_object_t *p_this, const char *psz_variable,
913 vlc_value_t oval, vlc_value_t nval, void *param )
915 PLModel *p_model = (PLModel *) param;
916 playlist_add_t *p_add = (playlist_add_t *)malloc( sizeof( playlist_add_t));
917 memcpy( p_add, nval.p_address, sizeof( playlist_add_t ) );
919 if( ++p_model->i_items_to_append >= 50 )
921 // p_model->b_need_update = VLC_TRUE;
922 // return VLC_SUCCESS;
924 PLEvent *event = new PLEvent( p_add );
925 QApplication::postEvent( p_model, static_cast<QEvent*>(event) );