1 /*****************************************************************************
2 * playlist_model.cpp : Manage playlist model
3 ****************************************************************************
4 * Copyright (C) 2006-2007 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 *****************************************************************************/
29 #include "components/playlist/playlist_model.hpp"
30 #include "dialogs/mediainfo.hpp"
31 #include <vlc_intf_strings.h>
33 #include "pixmaps/type_unknown.xpm"
39 #include <QApplication>
42 QIcon PLModel::icons[ITEM_TYPE_NUMBER];
44 static int PlaylistChanged( vlc_object_t *, const char *,
45 vlc_value_t, vlc_value_t, void * );
46 static int PlaylistNext( vlc_object_t *, const char *,
47 vlc_value_t, vlc_value_t, void * );
48 static int ItemChanged( vlc_object_t *, const char *,
49 vlc_value_t, vlc_value_t, void * );
50 static int ItemAppended( vlc_object_t *p_this, const char *psz_variable,
51 vlc_value_t oval, vlc_value_t nval, void *param );
52 static int ItemDeleted( vlc_object_t *p_this, const char *psz_variable,
53 vlc_value_t oval, vlc_value_t nval, void *param );
55 /*************************************************************************
56 * Playlist model implementation
57 *************************************************************************/
60 This model is called two times, for the selector and the standard panel
62 PLModel::PLModel( playlist_t *_p_playlist, /* THEPL */
63 intf_thread_t *_p_intf, /* main Qt p_intf */
64 playlist_item_t * p_root,
65 /*playlist_GetPreferredNode( THEPL, THEPL->p_local_category );
66 and THEPL->p_root_category for SelectPL */
67 int _i_depth, /* -1 for StandPL, 1 for SelectPL */
68 QObject *parent ) /* Basic Qt parent */
69 : QAbstractItemModel( parent )
72 assert( i_depth == DEPTH_SEL || i_depth == DEPTH_PL );
74 p_playlist = _p_playlist;
75 i_items_to_append = 0;
76 b_need_update = false;
78 i_cached_input_id = -1;
79 i_popup_item = i_popup_parent = -1;
81 rootItem = NULL; /* PLItem rootItem, will be set in rebuild( ) */
83 /* Icons initialization */
84 #define ADD_ICON(type, x) icons[ITEM_TYPE_##type] = QIcon( QPixmap( x ) )
85 ADD_ICON( UNKNOWN , type_unknown_xpm );
86 ADD_ICON( FILE, ":/pixmaps/type_file.png" );
87 ADD_ICON( DIRECTORY, ":/pixmaps/type_directory.png" );
88 ADD_ICON( DISC, ":/pixmaps/disc_16px.png" );
89 ADD_ICON( CDDA, ":/pixmaps/cdda_16px.png" );
90 ADD_ICON( CARD, ":/pixmaps/capture-card_16px.png" );
91 ADD_ICON( NET, ":/pixmaps/type_net.png" );
92 ADD_ICON( PLAYLIST, ":/pixmaps/type_playlist.png" );
93 ADD_ICON( NODE, ":/pixmaps/type_node.png" );
102 QSettings settings( "vlc", "vlc-qt-interface" );
103 settings.setValue( "qt-pl-showflags", rootItem->i_showflags );
108 Qt::DropActions PLModel::supportedDropActions() const
110 return Qt::CopyAction; /* Why not Qt::MoveAction */
113 Qt::ItemFlags PLModel::flags( const QModelIndex &index ) const
115 Qt::ItemFlags defaultFlags = QAbstractItemModel::flags( index );
116 if( index.isValid() )
117 return Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | defaultFlags;
119 return Qt::ItemIsDropEnabled | defaultFlags;
122 /* A list of model indexes are a playlist */
123 QStringList PLModel::mimeTypes() const
126 types << "vlc/playlist-item-id";
130 QMimeData *PLModel::mimeData( const QModelIndexList &indexes ) const
132 QMimeData *mimeData = new QMimeData();
133 QByteArray encodedData;
134 QDataStream stream( &encodedData, QIODevice::WriteOnly );
136 foreach( QModelIndex index, indexes ) {
137 if( index.isValid() && index.column() == 0 )
138 stream << itemId( index );
140 mimeData->setData( "vlc/playlist-item-id", encodedData );
145 bool PLModel::dropMimeData( const QMimeData *data, Qt::DropAction action,
146 int row, int column, const QModelIndex &target )
148 if( data->hasFormat( "vlc/playlist-item-id" ) )
150 if( action == Qt::IgnoreAction )
154 if( target.isValid() )
155 targetItem = static_cast<PLItem*>( target.internalPointer() );
157 targetItem = rootItem;
159 QByteArray encodedData = data->data( "vlc/playlist-item-id" );
160 QDataStream stream( &encodedData, QIODevice::ReadOnly );
162 PLItem *newParentItem;
163 while( !stream.atEnd() )
170 playlist_item_t *p_target =
171 playlist_ItemGetById( p_playlist, targetItem->i_id,
173 playlist_item_t *p_src = playlist_ItemGetById( p_playlist, srcId,
176 if( !p_target || !p_src )
181 if( p_target->i_children == -1 ) /* A leaf */
183 PLItem *parentItem = targetItem->parent();
184 assert( parentItem );
185 playlist_item_t *p_parent =
186 playlist_ItemGetById( p_playlist, parentItem->i_id,
193 for( i = 0 ; i< p_parent->i_children ; i++ )
194 if( p_parent->pp_children[i] == p_target ) break;
195 playlist_TreeMove( p_playlist, p_src, p_parent, i );
196 newParentItem = parentItem;
200 /* \todo: if we drop on a top-level node, use copy instead ? */
201 playlist_TreeMove( p_playlist, p_src, p_target, 0 );
203 newParentItem = targetItem;
205 /* Remove from source */
206 PLItem *srcItem = FindById( rootItem, p_src->i_id );
207 // We dropped on the source selector. Ask the dialog to forward
211 emit shouldRemove( p_src->i_id );
214 srcItem->remove( srcItem );
216 /* Display at new destination */
217 PLItem *newItem = new PLItem( p_src, newParentItem, this );
218 newParentItem->insertChild( newItem, i, true );
219 UpdateTreeItem( p_src, newItem, true );
220 if( p_src->i_children != -1 )
221 UpdateNodeChildren( newItem );
228 /* remove item with its id */
229 void PLModel::removeItem( int i_id )
231 PLItem *item = FindById( rootItem, i_id );
232 if( item ) item->remove( item );
235 /* callbacks and slots */
236 void PLModel::addCallbacks()
238 /* Some global changes happened -> Rebuild all */
239 var_AddCallback( p_playlist, "intf-change", PlaylistChanged, this );
240 /* We went to the next item */
241 var_AddCallback( p_playlist, "playlist-current", PlaylistNext, this );
242 /* One item has been updated */
243 var_AddCallback( p_playlist, "item-change", ItemChanged, this );
244 var_AddCallback( p_playlist, "item-append", ItemAppended, this );
245 var_AddCallback( p_playlist, "item-deleted", ItemDeleted, this );
248 void PLModel::delCallbacks()
250 var_DelCallback( p_playlist, "item-change", ItemChanged, this );
251 var_DelCallback( p_playlist, "playlist-current", PlaylistNext, this );
252 var_DelCallback( p_playlist, "intf-change", PlaylistChanged, this );
253 var_DelCallback( p_playlist, "item-append", ItemAppended, this );
254 var_DelCallback( p_playlist, "item-deleted", ItemDeleted, this );
257 void PLModel::activateItem( const QModelIndex &index )
259 assert( index.isValid() );
260 PLItem *item = static_cast<PLItem*>(index.internalPointer());
263 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id,
265 activateItem( p_item );
269 /* Must be entered with lock */
270 void PLModel::activateItem( playlist_item_t *p_item )
272 if( !p_item ) return;
273 playlist_item_t *p_parent = p_item;
276 if( p_parent->i_id == rootItem->i_id ) break;
277 p_parent = p_parent->p_parent;
280 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, VLC_TRUE,
284 /****************** Base model mandatory implementations *****************/
285 QVariant PLModel::data( const QModelIndex &index, int role ) const
287 if( !index.isValid() ) return QVariant();
288 PLItem *item = static_cast<PLItem*>(index.internalPointer());
289 if( role == Qt::DisplayRole )
291 return QVariant( item->columnString( index.column() ) );
293 else if( role == Qt::DecorationRole && index.column() == 0 )
295 /* Use to segfault here because i_type wasn't always initialized */
296 if( item->i_type >= 0 )
297 return QVariant( PLModel::icons[item->i_type] );
299 else if( role == Qt::FontRole )
301 if( item->b_current == true )
303 QFont f; f.setBold( true ); return QVariant( f );
309 bool PLModel::isCurrent( const QModelIndex &index )
311 assert( index.isValid() );
312 return static_cast<PLItem*>(index.internalPointer())->b_current;
315 int PLModel::itemId( const QModelIndex &index ) const
317 assert( index.isValid() );
318 return static_cast<PLItem*>(index.internalPointer())->i_id;
321 QVariant PLModel::headerData( int section, Qt::Orientation orientation,
324 if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
325 return QVariant( rootItem->columnString( section ) );
329 QModelIndex PLModel::index( int row, int column, const QModelIndex &parent )
333 if( !parent.isValid() )
334 parentItem = rootItem;
336 parentItem = static_cast<PLItem*>(parent.internalPointer());
338 PLItem *childItem = parentItem->child( row );
340 return createIndex( row, column, childItem );
342 return QModelIndex();
345 /* Return the index of a given item */
346 QModelIndex PLModel::index( PLItem *item, int column ) const
348 if( !item ) return QModelIndex();
349 const PLItem *parent = item->parent();
351 return createIndex( parent->children.lastIndexOf( item ),
353 return QModelIndex();
356 QModelIndex PLModel::parent( const QModelIndex &index ) const
358 if( !index.isValid() ) return QModelIndex();
360 PLItem *childItem = static_cast<PLItem*>(index.internalPointer());
363 msg_Err( p_playlist, "NULL CHILD" );
364 return QModelIndex();
367 PLItem *parentItem = childItem->parent();
368 if( !parentItem || parentItem == rootItem ) return QModelIndex();
369 if( !parentItem->parentItem )
371 msg_Err( p_playlist, "No parent parent, trying row 0 " );
372 msg_Err( p_playlist, "----- PLEASE REPORT THIS ------" );
373 return createIndex( 0, 0, parentItem );
375 QModelIndex ind = createIndex(parentItem->row(), 0, parentItem);
379 int PLModel::columnCount( const QModelIndex &i) const
381 return rootItem->item_col_strings.count();
384 int PLModel::childrenCount( const QModelIndex &parent ) const
386 return rowCount( parent );
389 int PLModel::rowCount( const QModelIndex &parent ) const
393 if( !parent.isValid() )
394 parentItem = rootItem;
396 parentItem = static_cast<PLItem*>(parent.internalPointer());
398 return parentItem->childCount();
401 /************************* General playlist status ***********************/
403 bool PLModel::hasRandom()
405 if( var_GetBool( p_playlist, "random" ) ) return true;
408 bool PLModel::hasRepeat()
410 if( var_GetBool( p_playlist, "repeat" ) ) return true;
413 bool PLModel::hasLoop()
415 if( var_GetBool( p_playlist, "loop" ) ) return true;
418 void PLModel::setLoop( bool on )
420 var_SetBool( p_playlist, "loop", on ? VLC_TRUE:VLC_FALSE );
421 config_PutInt( p_playlist, "loop", on ? 1: 0 );
423 void PLModel::setRepeat( bool on )
425 var_SetBool( p_playlist, "repeat", on ? VLC_TRUE:VLC_FALSE );
426 config_PutInt( p_playlist, "repeat", on ? 1: 0 );
428 void PLModel::setRandom( bool on )
430 var_SetBool( p_playlist, "random", on ? VLC_TRUE:VLC_FALSE );
431 config_PutInt( p_playlist, "random", on ? 1: 0 );
434 /************************* Lookups *****************************/
436 PLItem *PLModel::FindById( PLItem *root, int i_id )
438 return FindInner( root, i_id, false );
441 PLItem *PLModel::FindByInput( PLItem *root, int i_id )
443 return FindInner( root, i_id, true );
446 #define CACHE( i, p ) { i_cached_id = i; p_cached_item = p; }
447 #define ICACHE( i, p ) { i_cached_input_id = i; p_cached_item_bi = p; }
449 PLItem * PLModel::FindInner( PLItem *root, int i_id, bool b_input )
451 if( ( !b_input && i_cached_id == i_id) ||
452 ( b_input && i_cached_input_id ==i_id ) )
454 return b_input ? p_cached_item_bi : p_cached_item;
457 if( !b_input && root->i_id == i_id )
462 else if( b_input && root->i_input_id == i_id )
464 ICACHE( i_id, root );
468 QList<PLItem *>::iterator it = root->children.begin();
469 while ( it != root->children.end() )
471 if( !b_input && (*it)->i_id == i_id )
473 CACHE( i_id, (*it) );
474 return p_cached_item;
476 else if( b_input && (*it)->i_input_id == i_id )
478 ICACHE( i_id, (*it) );
479 return p_cached_item_bi;
481 if( (*it)->children.size() )
483 PLItem *childFound = FindInner( (*it), i_id, b_input );
487 ICACHE( i_id, childFound )
489 CACHE( i_id, childFound )
501 /************************* Updates handling *****************************/
502 void PLModel::customEvent( QEvent *event )
504 int type = event->type();
505 if( type != ItemUpdate_Type && type != ItemAppend_Type &&
506 type != ItemDelete_Type && type != PLUpdate_Type )
509 PLEvent *ple = static_cast<PLEvent *>(event);
511 if( type == ItemUpdate_Type )
512 ProcessInputItemUpdate( ple->i_id );
513 else if( type == ItemAppend_Type )
514 ProcessItemAppend( ple->p_add );
515 else if( type == ItemDelete_Type )
516 ProcessItemRemoval( ple->i_id );
521 /**** Events processing ****/
522 void PLModel::ProcessInputItemUpdate( int i_input_id )
524 if( i_input_id <= 0 ) return;
525 PLItem *item = FindByInput( rootItem, i_input_id );
527 UpdateTreeItem( item, true );
530 void PLModel::ProcessItemRemoval( int i_id )
532 if( i_id <= 0 ) return;
533 if( i_id == i_cached_id ) i_cached_id = -1;
534 i_cached_input_id = -1;
539 void PLModel::ProcessItemAppend( playlist_add_t *p_add )
541 playlist_item_t *p_item = NULL;
542 PLItem *newItem = NULL;
544 if( b_need_update ) return;
546 PLItem *nodeItem = FindById( rootItem, p_add->i_node );
548 if( !nodeItem ) goto end;
550 p_item = playlist_ItemGetById( p_playlist, p_add->i_item, VLC_TRUE );
551 if( !p_item || p_item->i_flags & PLAYLIST_DBL_FLAG ) goto end;
552 if( i_depth == DEPTH_SEL && p_item->p_parent &&
553 p_item->p_parent->i_id != rootItem->i_id )
556 newItem = new PLItem( p_item, nodeItem, this );
557 nodeItem->appendChild( newItem );
558 UpdateTreeItem( p_item, newItem, true );
565 void PLModel::rebuild()
570 void PLModel::rebuild( playlist_item_t *p_root )
572 /* Remove callbacks before locking to avoid deadlocks */
574 /* Invalidate cache */
575 i_cached_id = i_cached_input_id = -1;
581 if( rootItem->children.size() )
583 beginRemoveRows( index( rootItem, 0 ), 0,
584 rootItem->children.size() -1 );
585 qDeleteAll( rootItem->children );
586 rootItem->children.clear();
592 //if( rootItem ) delete rootItem;
593 rootItem = new PLItem( p_root, NULL, this );
596 /* Recreate from root */
597 UpdateNodeChildren( rootItem );
598 if( p_playlist->status.p_item )
600 PLItem *currentItem = FindByInput( rootItem,
601 p_playlist->status.p_item->p_input->i_id );
604 UpdateTreeItem( p_playlist->status.p_item, currentItem,
610 /* And signal the view */
611 emit layoutChanged();
615 /* This function must be entered WITH the playlist lock */
616 void PLModel::UpdateNodeChildren( PLItem *root )
618 playlist_item_t *p_node = playlist_ItemGetById( p_playlist, root->i_id,
620 UpdateNodeChildren( p_node, root );
623 /* This function must be entered WITH the playlist lock */
624 void PLModel::UpdateNodeChildren( playlist_item_t *p_node, PLItem *root )
626 for( int i = 0; i < p_node->i_children ; i++ )
628 if( p_node->pp_children[i]->i_flags & PLAYLIST_DBL_FLAG ) continue;
629 PLItem *newItem = new PLItem( p_node->pp_children[i], root, this );
630 root->appendChild( newItem, false );
631 UpdateTreeItem( newItem, false, true );
632 if( i_depth == DEPTH_PL && p_node->pp_children[i]->i_children != -1 )
633 UpdateNodeChildren( p_node->pp_children[i], newItem );
637 /* This function must be entered WITH the playlist lock */
638 void PLModel::UpdateTreeItem( PLItem *item, bool signal, bool force )
640 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id,
642 UpdateTreeItem( p_item, item, signal, force );
645 /* This function must be entered WITH the playlist lock */
646 void PLModel::UpdateTreeItem( playlist_item_t *p_item, PLItem *item,
647 bool signal, bool force )
651 if( !force && i_depth == DEPTH_SEL && p_item->p_parent &&
652 p_item->p_parent->i_id != rootItem->i_id )
654 item->update( p_item, p_item == p_playlist->status.p_item );
656 emit dataChanged( index( item, 0 ) , index( item, 1 ) );
659 /************************* Actions ******************************/
662 * Deletion, here we have to do a ugly slow hack as we retrieve the full
663 * list of indexes to delete at once: when we delete a node and all of
664 * its children, we need to update the list.
665 * Todo: investigate whethere we can use ranges to be sure to delete all items?
667 void PLModel::doDelete( QModelIndexList selected )
669 for( int i = selected.size() -1 ; i >= 0; i-- )
671 QModelIndex index = selected[i];
672 if( index.column() != 0 ) continue;
673 PLItem *item = static_cast<PLItem*>(index.internalPointer());
676 if( item->children.size() )
677 recurseDelete( item->children, &selected );
678 doDeleteItem( item, &selected );
683 void PLModel::recurseDelete( QList<PLItem*> children, QModelIndexList *fullList )
685 for( int i = children.size() - 1; i >= 0 ; i-- )
687 PLItem *item = children[i];
688 if( item->children.size() )
689 recurseDelete( item->children, fullList );
690 doDeleteItem( item, fullList );
694 void PLModel::doDeleteItem( PLItem *item, QModelIndexList *fullList )
696 QModelIndex deleteIndex = index( item, 0 );
697 fullList->removeAll( deleteIndex );
700 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id,
706 if( p_item->i_children == -1 )
707 playlist_DeleteFromInput( p_playlist, item->i_input_id, VLC_TRUE );
709 playlist_NodeDelete( p_playlist, p_item, VLC_TRUE, VLC_FALSE );
710 /* And finally, remove it from the tree */
711 item->remove( item );
715 /******* Volume III: Sorting and searching ********/
716 void PLModel::sort( int column, Qt::SortOrder order )
720 playlist_item_t *p_root = playlist_ItemGetById( p_playlist,
726 case 0: i_mode = SORT_TITLE_NODES_FIRST;break;
727 case 1: i_mode = SORT_DURATION; break;
728 case 2: i_mode = SORT_ARTIST;break;
729 default: i_mode = SORT_TITLE_NODES_FIRST; break;
733 playlist_RecursiveNodeSort( p_playlist, p_root, i_mode,
734 order == Qt::AscendingOrder ?
735 ORDER_NORMAL : ORDER_REVERSE );
736 p_playlist->b_reset_currently_playing = VLC_TRUE;
743 void PLModel::search( QString search_text )
745 /** \todo Fire the search with a small delay ? */
748 playlist_item_t *p_root = playlist_ItemGetById( p_playlist,
752 char *psz_name = search_text.toUtf8().data();
753 playlist_LiveSearchUpdate( p_playlist , p_root, psz_name );
759 /*********** Popup *********/
760 void PLModel::popup( QModelIndex & index, QPoint &point, QModelIndexList list )
762 assert( index.isValid() );
764 playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
765 itemId( index ), VLC_TRUE );
768 i_popup_item = p_item->i_id;
769 i_popup_parent = p_item->p_parent ? p_item->p_parent->i_id : -1;
771 current_selection = list;
772 QMenu *menu = new QMenu;
773 menu->addAction( qfu(I_POP_PLAY), this, SLOT( popupPlay() ) );
774 menu->addAction( qfu(I_POP_DEL), this, SLOT( popupDel() ) );
775 menu->addSeparator();
776 menu->addAction( qfu(I_POP_STREAM), this, SLOT( popupStream() ) );
777 menu->addAction( qfu(I_POP_SAVE), this, SLOT( popupSave() ) );
778 menu->addSeparator();
779 menu->addAction( qfu(I_POP_INFO), this, SLOT( popupInfo() ) );
780 if( p_item->i_children > -1 )
782 menu->addSeparator();
783 menu->addAction( qfu(I_POP_SORT), this, SLOT( popupSort() ) );
784 menu->addAction( qfu(I_POP_ADD), this, SLOT( popupAdd() ) );
787 menu->addSeparator();
788 menu->addAction( qfu( I_POP_EXPLORE ), this, SLOT( popupExplore() ) );
790 menu->popup( point );
797 void PLModel::viewchanged( int meta )
804 case VLC_META_ENGINE_TITLE:
806 case VLC_META_ENGINE_DURATION:
808 case VLC_META_ENGINE_ARTIST:
810 case VLC_META_ENGINE_GENRE:
812 case VLC_META_ENGINE_COPYRIGHT:
814 case VLC_META_ENGINE_COLLECTION:
816 case VLC_META_ENGINE_SEQ_NUM:
818 case VLC_META_ENGINE_DESCRIPTION:
823 /* UNUSED emit layoutAboutToBeChanged(); */
824 index = __MIN( index, rootItem->item_col_strings.count() );
825 QModelIndex parent = createIndex( 0, 0, rootItem );
827 if( rootItem->i_showflags & meta )
828 /* Removing columns */
830 beginRemoveColumns( parent, index, index+1 );
831 rootItem->i_showflags &= ~( meta );
832 rootItem->updateColumnHeaders();
838 beginInsertColumns( createIndex( 0, 0, rootItem), index, index+1 );
839 rootItem->i_showflags |= meta;
840 rootItem->updateColumnHeaders();
847 void PLModel::popupDel()
849 doDelete( current_selection );
851 void PLModel::popupPlay()
855 playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
856 i_popup_item,VLC_TRUE );
857 activateItem( p_item );
862 void PLModel::popupInfo()
864 playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
869 MediaInfoDialog *mid = new MediaInfoDialog( p_intf, p_item->p_input );
874 void PLModel::popupStream()
876 msg_Err( p_playlist, "Stream not implemented" );
879 void PLModel::popupSave()
881 msg_Err( p_playlist, "Save not implemented" );
885 #include <shellapi.h>
886 void PLModel::popupExplore()
888 ShellExecute( NULL, "explore", "C:\\", NULL, NULL, SW_SHOWNORMAL );
892 /**********************************************************************
894 **********************************************************************/
895 static int PlaylistChanged( vlc_object_t *p_this, const char *psz_variable,
896 vlc_value_t oval, vlc_value_t nval, void *param )
898 PLModel *p_model = (PLModel *) param;
899 PLEvent *event = new PLEvent( PLUpdate_Type, 0 );
900 QApplication::postEvent( p_model, static_cast<QEvent*>(event) );
904 static int PlaylistNext( vlc_object_t *p_this, const char *psz_variable,
905 vlc_value_t oval, vlc_value_t nval, void *param )
907 PLModel *p_model = (PLModel *) param;
908 PLEvent *event = new PLEvent( ItemUpdate_Type, oval.i_int );
909 QApplication::postEvent( p_model, static_cast<QEvent*>(event) );
910 event = new PLEvent( ItemUpdate_Type, nval.i_int );
911 QApplication::postEvent( p_model, static_cast<QEvent*>(event) );
915 static int ItemChanged( vlc_object_t *p_this, const char *psz_variable,
916 vlc_value_t oval, vlc_value_t nval, void *param )
918 PLModel *p_model = (PLModel *) param;
919 PLEvent *event = new PLEvent( ItemUpdate_Type, nval.i_int );
920 QApplication::postEvent( p_model, static_cast<QEvent*>(event) );
924 static int ItemDeleted( vlc_object_t *p_this, const char *psz_variable,
925 vlc_value_t oval, vlc_value_t nval, void *param )
927 PLModel *p_model = (PLModel *) param;
928 PLEvent *event = new PLEvent( ItemDelete_Type, nval.i_int );
929 QApplication::postEvent( p_model, static_cast<QEvent*>(event) );
933 static int ItemAppended( vlc_object_t *p_this, const char *psz_variable,
934 vlc_value_t oval, vlc_value_t nval, void *param )
936 PLModel *p_model = (PLModel *) param;
937 playlist_add_t *p_add = (playlist_add_t *)malloc( sizeof( playlist_add_t));
938 memcpy( p_add, nval.p_address, sizeof( playlist_add_t ) );
940 if( ++p_model->i_items_to_append >= 50 )
942 // p_model->b_need_update = VLC_TRUE;
943 // return VLC_SUCCESS;
945 PLEvent *event = new PLEvent( p_add );
946 QApplication::postEvent( p_model, static_cast<QEvent*>(event) );