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 *****************************************************************************/
28 #include <QApplication>
31 #include "playlist_model.hpp"
32 #include "dialogs/mediainfo.hpp"
33 #include <vlc_intf_strings.h>
35 #include "pixmaps/type_unknown.xpm"
37 QIcon PLModel::icons[ITEM_TYPE_NUMBER];
39 static int PlaylistChanged( vlc_object_t *, const char *,
40 vlc_value_t, vlc_value_t, void * );
41 static int PlaylistNext( vlc_object_t *, const char *,
42 vlc_value_t, vlc_value_t, void * );
43 static int ItemChanged( vlc_object_t *, const char *,
44 vlc_value_t, vlc_value_t, void * );
45 static int ItemAppended( vlc_object_t *p_this, const char *psz_variable,
46 vlc_value_t oval, vlc_value_t nval, void *param );
47 static int ItemDeleted( vlc_object_t *p_this, const char *psz_variable,
48 vlc_value_t oval, vlc_value_t nval, void *param );
50 /*************************************************************************
51 * Playlist item implementation
52 *************************************************************************/
61 void PLItem::init( int _i_id, int _i_input_id, PLItem *parent, PLModel *m )
64 i_id = _i_id; i_input_id = _i_input_id;
66 i_type = -1; /* Avoid segfault */
68 if( parentItem == NULL )
70 i_showflags = config_GetInt( model->p_intf , "qt-pl-showflags" );
73 i_showflags = parentItem->i_showflags;
74 //Add empty string and update() handles data appending
79 void PLItem::updateview( void )
83 if( model->i_depth == 1 ) //left window for playlist etc.
89 for( int i_index=1; i_index <= VLC_META_ENGINE_ART_URL; i_index = i_index*2 )
91 if( i_showflags & i_index )
95 case VLC_META_ENGINE_ARTIST:
96 strings.append( qtr( VLC_META_ARTIST ) );
98 case VLC_META_ENGINE_TITLE:
99 strings.append( qtr( VLC_META_TITLE ) );
101 case VLC_META_ENGINE_DESCRIPTION:
102 strings.append( qtr( VLC_META_DESCRIPTION ) );
104 case VLC_META_ENGINE_DURATION:
105 strings.append( qtr( "Duration" ) );
107 case VLC_META_ENGINE_GENRE:
108 strings.append( qtr( VLC_META_GENRE ) );
110 case VLC_META_ENGINE_COLLECTION:
111 strings.append( qtr( VLC_META_COLLECTION ) );
113 case VLC_META_ENGINE_SEQ_NUM:
114 strings.append( qtr( VLC_META_SEQ_NUM ) );
116 case VLC_META_ENGINE_RATING:
117 strings.append( qtr( VLC_META_RATING ) );
127 PLItem::PLItem( int _i_id, int _i_input_id, PLItem *parent, PLModel *m )
129 init( _i_id, _i_input_id, parent, m );
132 PLItem::PLItem( playlist_item_t * p_item, PLItem *parent, PLModel *m )
134 init( p_item->i_id, p_item->p_input->i_id, parent, m );
139 qDeleteAll( children );
143 void PLItem::insertChild( PLItem *item, int i_pos, bool signal )
147 model->beginInsertRows( model->index( this , 0 ), i_pos, i_pos );
148 children.insert( i_pos, item );
150 model->endInsertRows();
153 void PLItem::remove( PLItem *removed )
155 assert( model && parentItem );
156 int i_index = parentItem->children.indexOf( removed );
157 model->beginRemoveRows( model->index( parentItem, 0 ), i_index, i_index );
158 parentItem->children.removeAt( i_index );
159 model->endRemoveRows();
162 int PLItem::row() const
165 return parentItem->children.indexOf( const_cast<PLItem*>(this) );
169 void PLItem::update( playlist_item_t *p_item, bool iscurrent )
171 char psz_duration[MSTRTIME_MAX_SIZE];
172 assert( p_item->p_input->i_id == i_input_id );
174 i_type = p_item->p_input->i_type;
179 if( model->i_depth == 1 ) //left window for playlist etc.
181 strings.append( qfu( p_item->p_input->psz_name ) );
186 #define ADD_META( item, meta ) \
187 psz_meta = input_item_Get ## meta ( item->p_input ); \
188 strings.append( qfu( psz_meta ) ); \
191 for( int i_index=1; i_index <= VLC_META_ENGINE_ART_URL; i_index = i_index * 2 )
193 if( parentItem->i_showflags & i_index )
197 case VLC_META_ENGINE_ARTIST:
198 ADD_META( p_item, Artist );
200 case VLC_META_ENGINE_TITLE:
201 char *psz_title, *psz_name;
202 psz_title = input_item_GetTitle( p_item->p_input );
203 psz_name = input_item_GetName( p_item->p_input );
206 ADD_META( p_item, Title );
210 strings.append( qfu( psz_name ) );
215 case VLC_META_ENGINE_DESCRIPTION:
216 ADD_META( p_item, Description );
218 case VLC_META_ENGINE_DURATION:
219 secstotimestr( psz_duration,
220 input_item_GetDuration( p_item->p_input ) / 1000000 );
221 strings.append( QString( psz_duration ) );
223 case VLC_META_ENGINE_GENRE:
224 ADD_META( p_item, Genre );
226 case VLC_META_ENGINE_COLLECTION:
227 ADD_META( p_item, Album );
229 case VLC_META_ENGINE_SEQ_NUM:
230 ADD_META( p_item, TrackNum );
232 case VLC_META_ENGINE_RATING:
233 ADD_META( p_item, Rating );
243 /*************************************************************************
244 * Playlist model implementation
245 *************************************************************************/
247 PLModel::PLModel( playlist_t *_p_playlist, intf_thread_t *_p_intf,
248 playlist_item_t * p_root, int _i_depth, QObject *parent )
249 : QAbstractItemModel( parent )
252 assert( i_depth == 1 || i_depth == -1 );
254 p_playlist= _p_playlist;
255 i_items_to_append = 0;
256 b_need_update = false;
258 i_cached_input_id = -1;
259 i_popup_item = i_popup_parent = -1;
261 #define ADD_ICON(type, x) icons[ITEM_TYPE_##type] = QIcon( QPixmap( x ) )
262 ADD_ICON( UNKNOWN , type_unknown_xpm );
263 ADD_ICON( FILE, ":/pixmaps/type_file.png" );
264 ADD_ICON( DIRECTORY, ":/pixmaps/type_directory.png" );
265 ADD_ICON( DISC, ":/pixmaps/disc_16px.png" );
266 ADD_ICON( CDDA, ":/pixmaps/cdda_16px.png" );
267 ADD_ICON( CARD, ":/pixmaps/capture-card_16px.png" );
268 ADD_ICON( NET, ":/pixmaps/type_net.png" );
269 ADD_ICON( PLAYLIST, ":/pixmaps/type_playlist.png" );
270 ADD_ICON( NODE, ":/pixmaps/type_node.png" );
284 Qt::DropActions PLModel::supportedDropActions() const
286 return Qt::CopyAction;
289 Qt::ItemFlags PLModel::flags( const QModelIndex &index ) const
291 Qt::ItemFlags defaultFlags = QAbstractItemModel::flags( index );
292 if( index.isValid() )
293 return Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | defaultFlags;
295 return Qt::ItemIsDropEnabled | defaultFlags;
298 QStringList PLModel::mimeTypes() const
301 types << "vlc/playlist-item-id";
305 QMimeData *PLModel::mimeData( const QModelIndexList &indexes ) const
307 QMimeData *mimeData = new QMimeData();
308 QByteArray encodedData;
309 QDataStream stream( &encodedData, QIODevice::WriteOnly );
311 foreach( QModelIndex index, indexes ) {
312 if( index.isValid() && index.column() == 0 )
313 stream << itemId( index );
315 mimeData->setData( "vlc/playlist-item-id", encodedData );
319 bool PLModel::dropMimeData( const QMimeData *data, Qt::DropAction action,
320 int row, int column, const QModelIndex &target )
322 if( data->hasFormat( "vlc/playlist-item-id" ) )
324 if( action == Qt::IgnoreAction )
328 if( target.isValid() )
329 targetItem = static_cast<PLItem*>( target.internalPointer() );
331 targetItem = rootItem;
333 QByteArray encodedData = data->data( "vlc/playlist-item-id" );
334 QDataStream stream( &encodedData, QIODevice::ReadOnly );
336 PLItem *newParentItem;
337 while( !stream.atEnd() )
344 playlist_item_t *p_target =
345 playlist_ItemGetById( p_playlist, targetItem->i_id,
347 playlist_item_t *p_src = playlist_ItemGetById( p_playlist, srcId,
350 if( !p_target || !p_src )
355 if( p_target->i_children == -1 ) /* A leaf */
357 PLItem *parentItem = targetItem->parent();
358 assert( parentItem );
359 playlist_item_t *p_parent =
360 playlist_ItemGetById( p_playlist, parentItem->i_id,
367 for( i = 0 ; i< p_parent->i_children ; i++ )
368 if( p_parent->pp_children[i] == p_target ) break;
369 playlist_TreeMove( p_playlist, p_src, p_parent, i );
370 newParentItem = parentItem;
374 /* \todo: if we drop on a top-level node, use copy instead ? */
375 playlist_TreeMove( p_playlist, p_src, p_target, 0 );
377 newParentItem = targetItem;
379 /* Remove from source */
380 PLItem *srcItem = FindById( rootItem, p_src->i_id );
381 // We dropped on the source selector. Ask the dialog to forward
385 emit shouldRemove( p_src->i_id );
388 srcItem->remove( srcItem );
390 /* Display at new destination */
391 PLItem *newItem = new PLItem( p_src, newParentItem, this );
392 newParentItem->insertChild( newItem, i, true );
393 UpdateTreeItem( p_src, newItem, true );
394 if( p_src->i_children != -1 )
395 UpdateNodeChildren( newItem );
402 void PLModel::removeItem( int i_id )
404 PLItem *item = FindById( rootItem,i_id );
405 if( item ) item->remove( item );
408 void PLModel::addCallbacks()
410 /* Some global changes happened -> Rebuild all */
411 var_AddCallback( p_playlist, "intf-change", PlaylistChanged, this );
412 /* We went to the next item */
413 var_AddCallback( p_playlist, "playlist-current", PlaylistNext, this );
414 /* One item has been updated */
415 var_AddCallback( p_playlist, "item-change", ItemChanged, this );
416 var_AddCallback( p_playlist, "item-append", ItemAppended, this );
417 var_AddCallback( p_playlist, "item-deleted", ItemDeleted, this );
420 void PLModel::delCallbacks()
422 var_DelCallback( p_playlist, "item-change", ItemChanged, this );
423 var_DelCallback( p_playlist, "playlist-current", PlaylistNext, this );
424 var_DelCallback( p_playlist, "intf-change", PlaylistChanged, this );
425 var_DelCallback( p_playlist, "item-append", ItemAppended, this );
426 var_DelCallback( p_playlist, "item-deleted", ItemDeleted, this );
429 void PLModel::activateItem( const QModelIndex &index )
431 assert( index.isValid() );
432 PLItem *item = static_cast<PLItem*>(index.internalPointer());
435 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id,
437 activateItem( p_item );
440 /* Must be entered with lock */
441 void PLModel::activateItem( playlist_item_t *p_item )
443 if( !p_item ) return;
444 playlist_item_t *p_parent = p_item;
447 if( p_parent->i_id == rootItem->i_id ) break;
448 p_parent = p_parent->p_parent;
451 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, VLC_TRUE, p_parent, p_item );
454 /****************** Base model mandatory implementations *****************/
455 QVariant PLModel::data( const QModelIndex &index, int role ) const
457 if( !index.isValid() ) return QVariant();
458 PLItem *item = static_cast<PLItem*>(index.internalPointer());
459 if( role == Qt::DisplayRole )
461 return QVariant( item->columnString( index.column() ) );
463 else if( role == Qt::DecorationRole && index.column() == 0 )
465 /* Use to segfault here because i_type wasn't always initialized */
466 if( item->i_type >= 0 )
467 return QVariant( PLModel::icons[item->i_type] );
469 else if( role == Qt::FontRole )
471 if( item->current == true )
473 QFont f; f.setBold( true ); return QVariant( f );
479 bool PLModel::isCurrent( const QModelIndex &index )
481 assert( index.isValid() );
482 return static_cast<PLItem*>(index.internalPointer())->current;
485 int PLModel::itemId( const QModelIndex &index ) const
487 assert( index.isValid() );
488 return static_cast<PLItem*>(index.internalPointer())->i_id;
491 QVariant PLModel::headerData( int section, Qt::Orientation orientation,
494 if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
495 return QVariant( rootItem->columnString( section ) );
499 QModelIndex PLModel::index( int row, int column, const QModelIndex &parent )
503 if( !parent.isValid() )
504 parentItem = rootItem;
506 parentItem = static_cast<PLItem*>(parent.internalPointer());
508 PLItem *childItem = parentItem->child( row );
510 return createIndex( row, column, childItem );
512 return QModelIndex();
515 /* Return the index of a given item */
516 QModelIndex PLModel::index( PLItem *item, int column ) const
518 if( !item ) return QModelIndex();
519 const PLItem *parent = item->parent();
521 return createIndex( parent->children.lastIndexOf( item ),
523 return QModelIndex();
526 QModelIndex PLModel::parent( const QModelIndex &index ) const
528 if( !index.isValid() ) return QModelIndex();
530 PLItem *childItem = static_cast<PLItem*>(index.internalPointer());
531 if( !childItem ) { msg_Err( p_playlist, "NULL CHILD" ); return QModelIndex(); }
532 PLItem *parentItem = childItem->parent();
533 if( !parentItem || parentItem == rootItem ) return QModelIndex();
534 if( ! parentItem->parentItem )
536 msg_Err( p_playlist, "No parent parent, trying row 0 " );
537 msg_Err( p_playlist, "----- PLEASE REPORT THIS ------" );
538 return createIndex( 0, 0, parentItem );
540 QModelIndex ind = createIndex(parentItem->row(), 0, parentItem);
544 int PLModel::columnCount( const QModelIndex &i) const
546 return rootItem->strings.count();
549 int PLModel::childrenCount( const QModelIndex &parent ) const
551 return rowCount( parent );
554 int PLModel::rowCount( const QModelIndex &parent ) const
558 if( !parent.isValid() )
559 parentItem = rootItem;
561 parentItem = static_cast<PLItem*>(parent.internalPointer());
563 return parentItem->childCount();
566 /************************* General playlist status ***********************/
568 bool PLModel::hasRandom()
570 if( var_GetBool( p_playlist, "random" ) ) return true;
573 bool PLModel::hasRepeat()
575 if( var_GetBool( p_playlist, "repeat" ) ) return true;
578 bool PLModel::hasLoop()
580 if( var_GetBool( p_playlist, "loop" ) ) return true;
583 void PLModel::setLoop( bool on )
585 var_SetBool( p_playlist, "loop", on ? VLC_TRUE:VLC_FALSE );
586 config_PutInt( p_playlist, "loop", on ? 1: 0 );
588 void PLModel::setRepeat( bool on )
590 var_SetBool( p_playlist, "repeat", on ? VLC_TRUE:VLC_FALSE );
591 config_PutInt( p_playlist, "repeat", on ? 1: 0 );
593 void PLModel::setRandom( bool on )
595 var_SetBool( p_playlist, "random", on ? VLC_TRUE:VLC_FALSE );
596 config_PutInt( p_playlist, "random", on ? 1: 0 );
599 /************************* Lookups *****************************/
601 PLItem *PLModel::FindById( PLItem *root, int i_id )
603 return FindInner( root, i_id, false );
606 PLItem *PLModel::FindByInput( PLItem *root, int i_id )
608 return FindInner( root, i_id, true );
611 #define CACHE( i, p ) { i_cached_id = i; p_cached_item = p; }
612 #define ICACHE( i, p ) { i_cached_input_id = i; p_cached_item_bi = p; }
614 PLItem * PLModel::FindInner( PLItem *root, int i_id, bool b_input )
616 if( ( !b_input && i_cached_id == i_id) ||
617 ( b_input && i_cached_input_id ==i_id ) )
619 return b_input ? p_cached_item_bi : p_cached_item;
622 if( !b_input && root->i_id == i_id )
627 else if( b_input && root->i_input_id == i_id )
629 ICACHE( i_id, root );
633 QList<PLItem *>::iterator it = root->children.begin();
634 while ( it != root->children.end() )
636 if( !b_input && (*it)->i_id == i_id )
638 CACHE( i_id, (*it) );
639 return p_cached_item;
641 else if( b_input && (*it)->i_input_id == i_id )
643 ICACHE( i_id, (*it) );
644 return p_cached_item_bi;
646 if( (*it)->children.size() )
648 PLItem *childFound = FindInner( (*it), i_id, b_input );
652 ICACHE( i_id, childFound )
654 CACHE( i_id, childFound )
666 /************************* Updates handling *****************************/
667 void PLModel::customEvent( QEvent *event )
669 int type = event->type();
670 if( type != ItemUpdate_Type && type != ItemAppend_Type &&
671 type != ItemDelete_Type && type != PLUpdate_Type )
674 PLEvent *ple = static_cast<PLEvent *>(event);
676 if( type == ItemUpdate_Type )
677 ProcessInputItemUpdate( ple->i_id );
678 else if( type == ItemAppend_Type )
679 ProcessItemAppend( ple->p_add );
680 else if( type == ItemDelete_Type )
681 ProcessItemRemoval( ple->i_id );
686 /**** Events processing ****/
687 void PLModel::ProcessInputItemUpdate( int i_input_id )
689 if( i_input_id <= 0 ) return;
690 PLItem *item = FindByInput( rootItem, i_input_id );
692 UpdateTreeItem( item, true );
695 void PLModel::ProcessItemRemoval( int i_id )
697 if( i_id <= 0 ) return;
698 if( i_id == i_cached_id ) i_cached_id = -1;
699 i_cached_input_id = -1;
700 PLItem *item = FindById( rootItem, i_id );
702 item->remove( item );
705 void PLModel::ProcessItemAppend( playlist_add_t *p_add )
707 playlist_item_t *p_item = NULL;
708 PLItem *newItem = NULL;
710 if( b_need_update ) return;
712 PLItem *nodeItem = FindById( rootItem, p_add->i_node );
714 if( !nodeItem ) goto end;
716 p_item = playlist_ItemGetById( p_playlist, p_add->i_item, VLC_TRUE );
717 if( !p_item || p_item->i_flags & PLAYLIST_DBL_FLAG ) goto end;
718 if( i_depth == 1 && p_item->p_parent &&
719 p_item->p_parent->i_id != rootItem->i_id )
722 newItem = new PLItem( p_item, nodeItem, this );
723 nodeItem->appendChild( newItem );
724 UpdateTreeItem( p_item, newItem, true );
731 void PLModel::rebuild()
736 void PLModel::rebuild( playlist_item_t *p_root )
738 /* Remove callbacks before locking to avoid deadlocks */
740 /* Invalidate cache */
741 i_cached_id = i_cached_input_id = -1;
747 if( rootItem->children.size() )
749 beginRemoveRows( index( rootItem, 0 ), 0,
750 rootItem->children.size() -1 );
751 qDeleteAll( rootItem->children );
752 rootItem->children.clear();
758 //if( rootItem ) delete rootItem;
759 rootItem = new PLItem( p_root, NULL, this );
762 /* Recreate from root */
763 UpdateNodeChildren( rootItem );
764 if( p_playlist->status.p_item )
766 PLItem *currentItem = FindByInput( rootItem,
767 p_playlist->status.p_item->p_input->i_id );
770 UpdateTreeItem( p_playlist->status.p_item, currentItem,
776 /* And signal the view */
777 emit layoutChanged();
781 /* This function must be entered WITH the playlist lock */
782 void PLModel::UpdateNodeChildren( PLItem *root )
784 playlist_item_t *p_node = playlist_ItemGetById( p_playlist, root->i_id,
786 UpdateNodeChildren( p_node, root );
789 /* This function must be entered WITH the playlist lock */
790 void PLModel::UpdateNodeChildren( playlist_item_t *p_node, PLItem *root )
792 for( int i = 0; i < p_node->i_children ; i++ )
794 if( p_node->pp_children[i]->i_flags & PLAYLIST_DBL_FLAG ) continue;
795 PLItem *newItem = new PLItem( p_node->pp_children[i], root, this );
796 root->appendChild( newItem, false );
797 UpdateTreeItem( newItem, false, true );
798 if( i_depth != 1 && p_node->pp_children[i]->i_children != -1 )
799 UpdateNodeChildren( p_node->pp_children[i], newItem );
803 /* This function must be entered WITH the playlist lock */
804 void PLModel::UpdateTreeItem( PLItem *item, bool signal, bool force )
806 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id,
808 UpdateTreeItem( p_item, item, signal, force );
811 /* This function must be entered WITH the playlist lock */
812 void PLModel::UpdateTreeItem( playlist_item_t *p_item, PLItem *item,
813 bool signal, bool force )
817 if( !force && i_depth == 1 && p_item->p_parent &&
818 p_item->p_parent->i_id != rootItem->i_id )
820 item->update( p_item, p_item == p_playlist->status.p_item );
822 emit dataChanged( index( item, 0 ) , index( item, 1 ) );
825 /************************* Actions ******************************/
828 * Deletion, here we have to do a ugly slow hack as we retrieve the full
829 * list of indexes to delete at once: when we delete a node and all of
830 * its children, we need to update the list.
831 * Todo: investigate whethere we can use ranges to be sure to delete all items?
833 void PLModel::doDelete( QModelIndexList selected )
835 for( int i = selected.size() -1 ; i >= 0; i-- )
837 QModelIndex index = selected[i];
838 if( index.column() != 0 ) continue;
839 PLItem *item = static_cast<PLItem*>(index.internalPointer());
842 if( item->children.size() )
843 recurseDelete( item->children, &selected );
844 doDeleteItem( item, &selected );
849 void PLModel::recurseDelete( QList<PLItem*> children, QModelIndexList *fullList )
851 for( int i = children.size() - 1; i >= 0 ; i-- )
853 PLItem *item = children[i];
854 if( item->children.size() )
855 recurseDelete( item->children, fullList );
856 doDeleteItem( item, fullList );
860 void PLModel::doDeleteItem( PLItem *item, QModelIndexList *fullList )
862 QModelIndex deleteIndex = index( item, 0 );
863 fullList->removeAll( deleteIndex );
866 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id,
872 if( p_item->i_children == -1 )
873 playlist_DeleteFromInput( p_playlist, item->i_input_id, VLC_TRUE );
875 playlist_NodeDelete( p_playlist, p_item, VLC_TRUE, VLC_FALSE );
876 /* And finally, remove it from the tree */
877 item->remove( item );
881 /******* Volume III: Sorting and searching ********/
882 void PLModel::sort( int column, Qt::SortOrder order )
886 playlist_item_t *p_root = playlist_ItemGetById( p_playlist,
892 case 0: i_mode = SORT_TITLE_NODES_FIRST;break;
893 case 1: i_mode = SORT_ARTIST;break;
894 case 2: i_mode = SORT_DURATION; break;
895 default: i_mode = SORT_TITLE_NODES_FIRST; break;
898 playlist_RecursiveNodeSort( p_playlist, p_root, i_mode,
899 order == Qt::AscendingOrder ?
900 ORDER_NORMAL : ORDER_REVERSE );
906 void PLModel::search( QString search_text )
908 /** \todo Fire the search with a small delay ? */
911 playlist_item_t *p_root = playlist_ItemGetById( p_playlist,
915 char *psz_name = search_text.toUtf8().data();
916 playlist_LiveSearchUpdate( p_playlist , p_root, psz_name );
922 /*********** Popup *********/
923 void PLModel::popup( QModelIndex & index, QPoint &point, QModelIndexList list )
925 assert( index.isValid() );
927 playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
928 itemId( index ), VLC_TRUE );
931 i_popup_item = p_item->i_id;
932 i_popup_parent = p_item->p_parent ? p_item->p_parent->i_id : -1;
934 current_selection = list;
935 QMenu *menu = new QMenu;
936 menu->addAction( qfu(I_POP_PLAY), this, SLOT( popupPlay() ) );
937 menu->addAction( qfu(I_POP_DEL), this, SLOT( popupDel() ) );
938 menu->addSeparator();
939 menu->addAction( qfu(I_POP_STREAM), this, SLOT( popupStream() ) );
940 menu->addAction( qfu(I_POP_SAVE), this, SLOT( popupSave() ) );
941 menu->addSeparator();
942 menu->addAction( qfu(I_POP_INFO), this, SLOT( popupInfo() ) );
943 if( p_item->i_children > -1 )
945 menu->addSeparator();
946 menu->addAction( qfu(I_POP_SORT), this, SLOT( popupSort() ) );
947 menu->addAction( qfu(I_POP_ADD), this, SLOT( popupAdd() ) );
950 menu->addSeparator();
951 menu->addAction( qfu( I_POP_EXPLORE ), this, SLOT( popupExplore() ) );
953 menu->popup( point );
960 void PLModel::viewchanged( int meta )
967 case VLC_META_ENGINE_TITLE:
969 case VLC_META_ENGINE_DURATION:
971 case VLC_META_ENGINE_ARTIST:
973 case VLC_META_ENGINE_GENRE:
975 case VLC_META_ENGINE_COPYRIGHT:
977 case VLC_META_ENGINE_COLLECTION:
979 case VLC_META_ENGINE_SEQ_NUM:
981 case VLC_META_ENGINE_DESCRIPTION:
986 /* UNUSED emit layoutAboutToBeChanged(); */
987 index = __MIN( index , rootItem->strings.count() );
988 QModelIndex parent = createIndex( 0, 0, rootItem );
990 if( rootItem->i_showflags & meta )
991 /* Removing columns */
993 beginRemoveColumns( parent, index, index+1 );
994 rootItem->i_showflags &= ~( meta );
995 rootItem->updateview();
1000 /* Adding columns */
1001 beginInsertColumns( createIndex( 0, 0, rootItem), index, index+1 );
1002 rootItem->i_showflags |= meta;
1003 rootItem->updateview();
1007 config_PutInt( p_intf, "qt-pl-showflags", rootItem->i_showflags );
1008 config_SaveConfigFile( p_intf, NULL );
1012 void PLModel::popupDel()
1014 doDelete( current_selection );
1016 void PLModel::popupPlay()
1020 playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
1021 i_popup_item,VLC_TRUE );
1022 activateItem( p_item );
1027 void PLModel::popupInfo()
1029 playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
1034 MediaInfoDialog *mid = new MediaInfoDialog( p_intf, p_item->p_input );
1039 void PLModel::popupStream()
1041 msg_Err( p_playlist, "Stream not implemented" );
1044 void PLModel::popupSave()
1046 msg_Err( p_playlist, "Save not implemented" );
1050 #include <shellapi.h>
1051 void PLModel::popupExplore()
1053 ShellExecuteW( NULL, L"explore", L"C:\\", NULL, NULL, SW_SHOWNORMAL );
1057 /**********************************************************************
1058 * Playlist callbacks
1059 **********************************************************************/
1060 static int PlaylistChanged( vlc_object_t *p_this, const char *psz_variable,
1061 vlc_value_t oval, vlc_value_t nval, void *param )
1063 PLModel *p_model = (PLModel *) param;
1064 PLEvent *event = new PLEvent( PLUpdate_Type, 0 );
1065 QApplication::postEvent( p_model, static_cast<QEvent*>(event) );
1069 static int PlaylistNext( vlc_object_t *p_this, const char *psz_variable,
1070 vlc_value_t oval, vlc_value_t nval, void *param )
1072 PLModel *p_model = (PLModel *) param;
1073 PLEvent *event = new PLEvent( ItemUpdate_Type, oval.i_int );
1074 QApplication::postEvent( p_model, static_cast<QEvent*>(event) );
1075 event = new PLEvent( ItemUpdate_Type, nval.i_int );
1076 QApplication::postEvent( p_model, static_cast<QEvent*>(event) );
1080 static int ItemChanged( vlc_object_t *p_this, const char *psz_variable,
1081 vlc_value_t oval, vlc_value_t nval, void *param )
1083 PLModel *p_model = (PLModel *) param;
1084 PLEvent *event = new PLEvent( ItemUpdate_Type, nval.i_int );
1085 QApplication::postEvent( p_model, static_cast<QEvent*>(event) );
1089 static int ItemDeleted( vlc_object_t *p_this, const char *psz_variable,
1090 vlc_value_t oval, vlc_value_t nval, void *param )
1092 PLModel *p_model = (PLModel *) param;
1093 PLEvent *event = new PLEvent( ItemDelete_Type, nval.i_int );
1094 QApplication::postEvent( p_model, static_cast<QEvent*>(event) );
1098 static int ItemAppended( vlc_object_t *p_this, const char *psz_variable,
1099 vlc_value_t oval, vlc_value_t nval, void *param )
1101 PLModel *p_model = (PLModel *) param;
1102 playlist_add_t *p_add = (playlist_add_t *)malloc( sizeof( playlist_add_t));
1103 memcpy( p_add, nval.p_address, sizeof( playlist_add_t ) );
1105 if( ++p_model->i_items_to_append >= 50 )
1107 // p_model->b_need_update = VLC_TRUE;
1108 // return VLC_SUCCESS;
1110 PLEvent *event = new PLEvent( p_add );
1111 QApplication::postEvent( p_model, static_cast<QEvent*>(event) );