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;
67 if( parentItem == NULL )
69 i_showflags = config_GetInt( model->p_intf , "qt-pl-showflags" );
72 i_showflags = parentItem->i_showflags;
73 //Add empty string and update() handles data appending
78 void PLItem::updateview( void )
82 if( model->i_depth == 1 ) //left window for playlist etc.
88 for( int i_index=1; i_index <= VLC_META_ENGINE_ART_URL; i_index = i_index*2 )
90 if( i_showflags & i_index )
94 case VLC_META_ENGINE_ARTIST:
95 strings.append( qtr( VLC_META_ARTIST ) );
97 case VLC_META_ENGINE_TITLE:
98 strings.append( qtr( VLC_META_TITLE ) );
100 case VLC_META_ENGINE_DESCRIPTION:
101 strings.append( qtr( VLC_META_DESCRIPTION ) );
103 case VLC_META_ENGINE_DURATION:
104 strings.append( qtr( "Duration" ) );
106 case VLC_META_ENGINE_GENRE:
107 strings.append( qtr( VLC_META_GENRE ) );
109 case VLC_META_ENGINE_COLLECTION:
110 strings.append( qtr( VLC_META_COLLECTION ) );
112 case VLC_META_ENGINE_SEQ_NUM:
113 strings.append( qtr( VLC_META_SEQ_NUM ) );
115 case VLC_META_ENGINE_RATING:
116 strings.append( qtr( VLC_META_RATING ) );
126 PLItem::PLItem( int _i_id, int _i_input_id, PLItem *parent, PLModel *m )
128 init( _i_id, _i_input_id, parent, m );
131 PLItem::PLItem( playlist_item_t * p_item, PLItem *parent, PLModel *m )
133 init( p_item->i_id, p_item->p_input->i_id, parent, m );
138 qDeleteAll( children );
142 void PLItem::insertChild( PLItem *item, int i_pos, bool signal )
146 model->beginInsertRows( model->index( this , 0 ), i_pos, i_pos );
147 children.insert( i_pos, item );
149 model->endInsertRows();
152 void PLItem::remove( PLItem *removed )
154 assert( model && parentItem );
155 int i_index = parentItem->children.indexOf( removed );
156 model->beginRemoveRows( model->index( parentItem, 0 ), i_index, i_index );
157 parentItem->children.removeAt( i_index );
158 model->endRemoveRows();
161 int PLItem::row() const
164 return parentItem->children.indexOf( const_cast<PLItem*>(this) );
168 void PLItem::update( playlist_item_t *p_item, bool iscurrent )
170 char psz_duration[MSTRTIME_MAX_SIZE];
171 assert( p_item->p_input->i_id == i_input_id );
173 type = p_item->p_input->i_type;
176 char *psz_arturl = input_item_GetArtURL( p_item->p_input );
177 if( ( current && psz_arturl ) &&
178 !strncmp( psz_arturl, "file://", 7 ) )
179 model->sendArt( qfu( psz_arturl ) ) ;
186 if( model->i_depth == 1 ) //left window for playlist etc.
188 strings.append( qfu( p_item->p_input->psz_name ) );
193 #define ADD_META( item, meta ) \
194 psz_meta = input_item_Get ## meta ( item->p_input ); \
195 strings.append( qfu( psz_meta ) ); \
198 for( int i_index=1; i_index <= VLC_META_ENGINE_ART_URL; i_index = i_index * 2 )
200 if( parentItem->i_showflags & i_index )
204 case VLC_META_ENGINE_ARTIST:
205 ADD_META( p_item, Artist );
207 case VLC_META_ENGINE_TITLE:
208 char *psz_title, *psz_name;
209 psz_title = input_item_GetTitle( p_item->p_input );
210 psz_name = input_item_GetName( p_item->p_input );
213 ADD_META( p_item, Title );
215 strings.append( qfu( psz_name ) );
220 case VLC_META_ENGINE_DESCRIPTION:
221 ADD_META( p_item, Description );
223 case VLC_META_ENGINE_DURATION:
224 secstotimestr( psz_duration,
225 input_item_GetDuration( p_item->p_input ) / 1000000 );
226 strings.append( QString( psz_duration ) );
228 case VLC_META_ENGINE_GENRE:
229 ADD_META( p_item, Genre );
231 case VLC_META_ENGINE_COLLECTION:
232 ADD_META( p_item, Album );
234 case VLC_META_ENGINE_SEQ_NUM:
235 ADD_META( p_item, TrackNum );
237 case VLC_META_ENGINE_RATING:
238 ADD_META( p_item, Rating );
248 /*************************************************************************
249 * Playlist model implementation
250 *************************************************************************/
252 PLModel::PLModel( playlist_t *_p_playlist, intf_thread_t *_p_intf,
253 playlist_item_t * p_root, int _i_depth, QObject *parent )
254 : QAbstractItemModel( parent )
257 assert( i_depth == 1 || i_depth == -1 );
259 p_playlist= _p_playlist;
260 i_items_to_append = 0;
261 b_need_update = false;
263 i_cached_input_id = -1;
264 i_popup_item = i_popup_parent = -1;
266 #define ADD_ICON(type, x) icons[ITEM_TYPE_##type] = QIcon( QPixmap( x ) );
267 ADD_ICON( UNKNOWN , type_unknown_xpm );
268 ADD_ICON( FILE, ":/pixmaps/type_file.png" );
269 ADD_ICON( DIRECTORY, ":/pixmaps/type_directory.png" );
270 ADD_ICON( DISC, ":/pixmaps/disc_16px.png" );
271 ADD_ICON( CDDA, ":/pixmaps/cdda_16px.png" );
272 ADD_ICON( CARD, ":/pixmaps/capture-card_16px.png" );
273 ADD_ICON( NET, ":/pixmaps/type_net.png" );
274 ADD_ICON( PLAYLIST, ":/pixmaps/type_playlist.png" );
275 ADD_ICON( NODE, ":/pixmaps/type_node.png" );
288 Qt::DropActions PLModel::supportedDropActions() const
290 return Qt::CopyAction;
293 Qt::ItemFlags PLModel::flags( const QModelIndex &index ) const
295 Qt::ItemFlags defaultFlags = QAbstractItemModel::flags( index );
296 if( index.isValid() )
297 return Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | defaultFlags;
299 return Qt::ItemIsDropEnabled | defaultFlags;
302 QStringList PLModel::mimeTypes() const
305 types << "vlc/playlist-item-id";
309 QMimeData *PLModel::mimeData( const QModelIndexList &indexes ) const
311 QMimeData *mimeData = new QMimeData();
312 QByteArray encodedData;
313 QDataStream stream( &encodedData, QIODevice::WriteOnly );
315 foreach( QModelIndex index, indexes ) {
316 if( index.isValid() && index.column() == 0 )
317 stream << itemId( index );
319 mimeData->setData( "vlc/playlist-item-id", encodedData );
323 bool PLModel::dropMimeData( const QMimeData *data, Qt::DropAction action,
324 int row, int column, const QModelIndex &target )
326 if( data->hasFormat( "vlc/playlist-item-id" ) )
328 if( action == Qt::IgnoreAction )
332 if( target.isValid() )
333 targetItem = static_cast<PLItem*>( target.internalPointer() );
335 targetItem = rootItem;
337 QByteArray encodedData = data->data( "vlc/playlist-item-id" );
338 QDataStream stream( &encodedData, QIODevice::ReadOnly );
340 PLItem *newParentItem;
341 while( !stream.atEnd() )
348 playlist_item_t *p_target =
349 playlist_ItemGetById( p_playlist, targetItem->i_id,
351 playlist_item_t *p_src = playlist_ItemGetById( p_playlist, srcId,
354 if( !p_target || !p_src )
359 if( p_target->i_children == -1 ) /* A leaf */
361 PLItem *parentItem = targetItem->parent();
362 assert( parentItem );
363 playlist_item_t *p_parent =
364 playlist_ItemGetById( p_playlist, parentItem->i_id,
371 for( i = 0 ; i< p_parent->i_children ; i++ )
372 if( p_parent->pp_children[i] == p_target ) break;
373 playlist_TreeMove( p_playlist, p_src, p_parent, i );
374 newParentItem = parentItem;
378 /* \todo: if we drop on a top-level node, use copy instead ? */
379 playlist_TreeMove( p_playlist, p_src, p_target, 0 );
381 newParentItem = targetItem;
383 /* Remove from source */
384 PLItem *srcItem = FindById( rootItem, p_src->i_id );
385 // We dropped on the source selector. Ask the dialog to forward
389 emit shouldRemove( p_src->i_id );
392 srcItem->remove( srcItem );
394 /* Display at new destination */
395 PLItem *newItem = new PLItem( p_src, newParentItem, this );
396 newParentItem->insertChild( newItem, i, true );
397 UpdateTreeItem( p_src, newItem, true );
398 if( p_src->i_children != -1 )
399 UpdateNodeChildren( newItem );
406 void PLModel::removeItem( int i_id )
408 PLItem *item = FindById( rootItem,i_id );
409 if( item ) item->remove( item );
412 void PLModel::addCallbacks()
414 /* Some global changes happened -> Rebuild all */
415 var_AddCallback( p_playlist, "intf-change", PlaylistChanged, this );
416 /* We went to the next item */
417 var_AddCallback( p_playlist, "playlist-current", PlaylistNext, this );
418 /* One item has been updated */
419 var_AddCallback( p_playlist, "item-change", ItemChanged, this );
420 var_AddCallback( p_playlist, "item-append", ItemAppended, this );
421 var_AddCallback( p_playlist, "item-deleted", ItemDeleted, this );
424 void PLModel::delCallbacks()
426 var_DelCallback( p_playlist, "item-change", ItemChanged, this );
427 var_DelCallback( p_playlist, "playlist-current", PlaylistNext, this );
428 var_DelCallback( p_playlist, "intf-change", PlaylistChanged, this );
429 var_DelCallback( p_playlist, "item-append", ItemAppended, this );
430 var_DelCallback( p_playlist, "item-deleted", ItemDeleted, this );
433 void PLModel::activateItem( const QModelIndex &index )
435 assert( index.isValid() );
436 PLItem *item = static_cast<PLItem*>(index.internalPointer());
439 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id,
441 activateItem( p_item );
444 /* Must be entered with lock */
445 void PLModel::activateItem( playlist_item_t *p_item )
447 if( !p_item ) return;
448 playlist_item_t *p_parent = p_item;
451 if( p_parent->i_id == rootItem->i_id ) break;
452 p_parent = p_parent->p_parent;
455 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, VLC_TRUE, p_parent, p_item );
458 /****************** Base model mandatory implementations *****************/
459 QVariant PLModel::data( const QModelIndex &index, int role ) const
461 if( !index.isValid() ) return QVariant();
462 PLItem *item = static_cast<PLItem*>(index.internalPointer());
463 if( role == Qt::DisplayRole )
465 return QVariant( item->columnString( index.column() ) );
467 else if( role == Qt::DecorationRole && index.column() == 0 )
469 if( item->type >= 0 )
470 return QVariant( PLModel::icons[item->type] );
472 else if( role == Qt::FontRole )
474 if( item->current == true )
476 QFont f; f.setBold( true ); return QVariant( f );
482 bool PLModel::isCurrent( const QModelIndex &index )
484 assert( index.isValid() );
485 return static_cast<PLItem*>(index.internalPointer())->current;
488 int PLModel::itemId( const QModelIndex &index ) const
490 assert( index.isValid() );
491 return static_cast<PLItem*>(index.internalPointer())->i_id;
494 QVariant PLModel::headerData( int section, Qt::Orientation orientation,
497 if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
498 return QVariant( rootItem->columnString( section ) );
502 QModelIndex PLModel::index( int row, int column, const QModelIndex &parent )
506 if( !parent.isValid() )
507 parentItem = rootItem;
509 parentItem = static_cast<PLItem*>(parent.internalPointer());
511 PLItem *childItem = parentItem->child( row );
513 return createIndex( row, column, childItem );
515 return QModelIndex();
518 /* Return the index of a given item */
519 QModelIndex PLModel::index( PLItem *item, int column ) const
521 if( !item ) return QModelIndex();
522 const PLItem *parent = item->parent();
524 return createIndex( parent->children.lastIndexOf( item ),
526 return QModelIndex();
529 QModelIndex PLModel::parent( const QModelIndex &index ) const
531 if( !index.isValid() ) return QModelIndex();
533 PLItem *childItem = static_cast<PLItem*>(index.internalPointer());
534 if( !childItem ) { msg_Err( p_playlist, "NULL CHILD" ); return QModelIndex(); }
535 PLItem *parentItem = childItem->parent();
536 if( !parentItem || parentItem == rootItem ) return QModelIndex();
537 if( ! parentItem->parentItem )
539 msg_Err( p_playlist, "No parent parent, trying row 0 " );
540 msg_Err( p_playlist, "----- PLEASE REPORT THIS ------" );
541 return createIndex( 0, 0, parentItem );
543 QModelIndex ind = createIndex(parentItem->row(), 0, parentItem);
547 int PLModel::columnCount( const QModelIndex &i) const
549 return rootItem->strings.count();
552 int PLModel::childrenCount( const QModelIndex &parent ) const
554 return rowCount( parent );
557 int PLModel::rowCount( const QModelIndex &parent ) const
561 if( !parent.isValid() )
562 parentItem = rootItem;
564 parentItem = static_cast<PLItem*>(parent.internalPointer());
566 return parentItem->childCount();
569 /************************* General playlist status ***********************/
571 bool PLModel::hasRandom()
573 if( var_GetBool( p_playlist, "random" ) ) return true;
576 bool PLModel::hasRepeat()
578 if( var_GetBool( p_playlist, "repeat" ) ) return true;
581 bool PLModel::hasLoop()
583 if( var_GetBool( p_playlist, "loop" ) ) return true;
586 void PLModel::setLoop( bool on )
588 var_SetBool( p_playlist, "loop", on ? VLC_TRUE:VLC_FALSE );
589 config_PutInt( p_playlist, "loop", on ? 1: 0 );
591 void PLModel::setRepeat( bool on )
593 var_SetBool( p_playlist, "repeat", on ? VLC_TRUE:VLC_FALSE );
594 config_PutInt( p_playlist, "repeat", on ? 1: 0 );
596 void PLModel::setRandom( bool on )
598 var_SetBool( p_playlist, "random", on ? VLC_TRUE:VLC_FALSE );
599 config_PutInt( p_playlist, "random", on ? 1: 0 );
602 /************************* Lookups *****************************/
604 PLItem *PLModel::FindById( PLItem *root, int i_id )
606 return FindInner( root, i_id, false );
609 PLItem *PLModel::FindByInput( PLItem *root, int i_id )
611 return FindInner( root, i_id, true );
614 #define CACHE( i, p ) { i_cached_id = i; p_cached_item = p; }
615 #define ICACHE( i, p ) { i_cached_input_id = i; p_cached_item_bi = p; }
617 PLItem * PLModel::FindInner( PLItem *root, int i_id, bool b_input )
619 if( ( !b_input && i_cached_id == i_id) ||
620 ( b_input && i_cached_input_id ==i_id ) )
622 return b_input ? p_cached_item_bi : p_cached_item;
625 if( !b_input && root->i_id == i_id )
630 else if( b_input && root->i_input_id == i_id )
632 ICACHE( i_id, root );
636 QList<PLItem *>::iterator it = root->children.begin();
637 while ( it != root->children.end() )
639 if( !b_input && (*it)->i_id == i_id )
641 CACHE( i_id, (*it) );
642 return p_cached_item;
644 else if( b_input && (*it)->i_input_id == i_id )
646 ICACHE( i_id, (*it) );
647 return p_cached_item_bi;
649 if( (*it)->children.size() )
651 PLItem *childFound = FindInner( (*it), i_id, b_input );
655 ICACHE( i_id, childFound )
657 CACHE( i_id, childFound )
669 /************************* Updates handling *****************************/
670 void PLModel::customEvent( QEvent *event )
672 int type = event->type();
673 if( type != ItemUpdate_Type && type != ItemAppend_Type &&
674 type != ItemDelete_Type && type != PLUpdate_Type )
677 PLEvent *ple = static_cast<PLEvent *>(event);
679 if( type == ItemUpdate_Type )
680 ProcessInputItemUpdate( ple->i_id );
681 else if( type == ItemAppend_Type )
682 ProcessItemAppend( ple->p_add );
683 else if( type == ItemDelete_Type )
684 ProcessItemRemoval( ple->i_id );
689 /**** Events processing ****/
690 void PLModel::ProcessInputItemUpdate( int i_input_id )
692 if( i_input_id <= 0 ) return;
693 PLItem *item = FindByInput( rootItem, i_input_id );
695 UpdateTreeItem( item, true );
698 void PLModel::ProcessItemRemoval( int i_id )
700 if( i_id <= 0 ) return;
701 if( i_id == i_cached_id ) i_cached_id = -1;
702 i_cached_input_id = -1;
703 PLItem *item = FindById( rootItem, i_id );
705 item->remove( item );
708 void PLModel::ProcessItemAppend( playlist_add_t *p_add )
710 playlist_item_t *p_item = NULL;
711 PLItem *newItem = NULL;
713 if( b_need_update ) return;
715 PLItem *nodeItem = FindById( rootItem, p_add->i_node );
717 if( !nodeItem ) goto end;
719 p_item = playlist_ItemGetById( p_playlist, p_add->i_item, VLC_TRUE );
720 if( !p_item || p_item->i_flags & PLAYLIST_DBL_FLAG ) goto end;
721 if( i_depth == 1 && p_item->p_parent &&
722 p_item->p_parent->i_id != rootItem->i_id )
725 newItem = new PLItem( p_item, nodeItem, this );
726 nodeItem->appendChild( newItem );
727 UpdateTreeItem( p_item, newItem, true );
734 void PLModel::rebuild()
739 void PLModel::rebuild( playlist_item_t *p_root )
741 /* Remove callbacks before locking to avoid deadlocks */
743 /* Invalidate cache */
744 i_cached_id = i_cached_input_id = -1;
750 if( rootItem->children.size() )
752 beginRemoveRows( index( rootItem, 0 ), 0,
753 rootItem->children.size() -1 );
754 qDeleteAll( rootItem->children );
755 rootItem->children.clear();
761 //if( rootItem ) delete rootItem;
762 rootItem = new PLItem( p_root, NULL, this );
765 /* Recreate from root */
766 UpdateNodeChildren( rootItem );
767 if( p_playlist->status.p_item )
769 PLItem *currentItem = FindByInput( rootItem,
770 p_playlist->status.p_item->p_input->i_id );
773 UpdateTreeItem( p_playlist->status.p_item, currentItem,
779 /* And signal the view */
780 emit layoutChanged();
784 /* This function must be entered WITH the playlist lock */
785 void PLModel::UpdateNodeChildren( PLItem *root )
787 playlist_item_t *p_node = playlist_ItemGetById( p_playlist, root->i_id,
789 UpdateNodeChildren( p_node, root );
792 /* This function must be entered WITH the playlist lock */
793 void PLModel::UpdateNodeChildren( playlist_item_t *p_node, PLItem *root )
795 for( int i = 0; i < p_node->i_children ; i++ )
797 if( p_node->pp_children[i]->i_flags & PLAYLIST_DBL_FLAG ) continue;
798 PLItem *newItem = new PLItem( p_node->pp_children[i], root, this );
799 root->appendChild( newItem, false );
800 UpdateTreeItem( newItem, false, true );
801 if( i_depth != 1 && p_node->pp_children[i]->i_children != -1 )
802 UpdateNodeChildren( p_node->pp_children[i], newItem );
806 /* This function must be entered WITH the playlist lock */
807 void PLModel::UpdateTreeItem( PLItem *item, bool signal, bool force )
809 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id,
811 UpdateTreeItem( p_item, item, signal, force );
814 /* This function must be entered WITH the playlist lock */
815 void PLModel::UpdateTreeItem( playlist_item_t *p_item, PLItem *item,
816 bool signal, bool force )
820 if( !force && i_depth == 1 && p_item->p_parent &&
821 p_item->p_parent->i_id != rootItem->i_id )
823 item->update( p_item, p_item == p_playlist->status.p_item );
825 emit dataChanged( index( item, 0 ) , index( item, 1 ) );
828 /************************* Actions ******************************/
830 void PLModel::sendArt( QString url )
832 QString arturl = url.replace( "file://",QString("" ) );
833 emit artSet( arturl );
836 void PLModel::removeArt()
838 emit artSet( QString() );
842 * Deletion, here we have to do a ugly slow hack as we retrieve the full
843 * list of indexes to delete at once: when we delete a node and all of
844 * its children, we need to update the list.
845 * Todo: investigate whethere we can use ranges to be sure to delete all items?
847 void PLModel::doDelete( QModelIndexList selected )
849 for( int i = selected.size() -1 ; i >= 0; i-- )
851 QModelIndex index = selected[i];
852 if( index.column() != 0 ) continue;
853 PLItem *item = static_cast<PLItem*>(index.internalPointer());
856 if( item->children.size() )
857 recurseDelete( item->children, &selected );
858 doDeleteItem( item, &selected );
863 void PLModel::recurseDelete( QList<PLItem*> children, QModelIndexList *fullList )
865 for( int i = children.size() - 1; i >= 0 ; i-- )
867 PLItem *item = children[i];
868 if( item->children.size() )
869 recurseDelete( item->children, fullList );
870 doDeleteItem( item, fullList );
874 void PLModel::doDeleteItem( PLItem *item, QModelIndexList *fullList )
876 QModelIndex deleteIndex = index( item, 0 );
877 fullList->removeAll( deleteIndex );
880 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id,
886 if( p_item->i_children == -1 )
887 playlist_DeleteFromInput( p_playlist, item->i_input_id, VLC_TRUE );
889 playlist_NodeDelete( p_playlist, p_item, VLC_TRUE, VLC_FALSE );
890 /* And finally, remove it from the tree */
891 item->remove( item );
895 /******* Volume III: Sorting and searching ********/
896 void PLModel::sort( int column, Qt::SortOrder order )
900 playlist_item_t *p_root = playlist_ItemGetById( p_playlist,
906 case 0: i_mode = SORT_TITLE_NODES_FIRST;break;
907 case 1: i_mode = SORT_ARTIST;break;
908 case 2: i_mode = SORT_DURATION; break;
909 default: i_mode = SORT_TITLE_NODES_FIRST; break;
912 playlist_RecursiveNodeSort( p_playlist, p_root, i_mode,
913 order == Qt::AscendingOrder ?
914 ORDER_NORMAL : ORDER_REVERSE );
920 void PLModel::search( QString search_text )
922 /** \todo Fire the search with a small delay ? */
925 playlist_item_t *p_root = playlist_ItemGetById( p_playlist,
929 char *psz_name = search_text.toUtf8().data();
930 playlist_LiveSearchUpdate( p_playlist , p_root, psz_name );
936 /*********** Popup *********/
937 void PLModel::popup( QModelIndex & index, QPoint &point, QModelIndexList list )
939 assert( index.isValid() );
941 playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
942 itemId( index ), VLC_TRUE );
945 i_popup_item = p_item->i_id;
946 i_popup_parent = p_item->p_parent ? p_item->p_parent->i_id : -1;
948 current_selection = list;
949 QMenu *menu = new QMenu;
950 menu->addAction( qfu(I_POP_PLAY), this, SLOT( popupPlay() ) );
951 menu->addAction( qfu(I_POP_DEL), this, SLOT( popupDel() ) );
952 menu->addSeparator();
953 menu->addAction( qfu(I_POP_STREAM), this, SLOT( popupStream() ) );
954 menu->addAction( qfu(I_POP_SAVE), this, SLOT( popupSave() ) );
955 menu->addSeparator();
956 menu->addAction( qfu(I_POP_INFO), this, SLOT( popupInfo() ) );
957 if( p_item->i_children > -1 )
959 menu->addSeparator();
960 menu->addAction( qfu(I_POP_SORT), this, SLOT( popupSort() ) );
961 menu->addAction( qfu(I_POP_ADD), this, SLOT( popupAdd() ) );
964 menu->addSeparator();
965 menu->addAction( qfu( I_POP_EXPLORE ), this, SLOT( popupExplore() ) );
967 menu->popup( point );
974 void PLModel::viewchanged( int meta )
981 case VLC_META_ENGINE_TITLE:
984 case VLC_META_ENGINE_DURATION:
987 case VLC_META_ENGINE_ARTIST:
990 case VLC_META_ENGINE_GENRE:
993 case VLC_META_ENGINE_COPYRIGHT:
996 case VLC_META_ENGINE_COLLECTION:
999 case VLC_META_ENGINE_SEQ_NUM:
1002 case VLC_META_ENGINE_DESCRIPTION:
1008 emit layoutAboutToBeChanged();
1009 index = __MIN( index , rootItem->strings.count() );
1010 QModelIndex parent = createIndex( 0, 0, rootItem );
1011 if( rootItem->i_showflags & meta )
1013 beginRemoveColumns( parent , index, index+1 );
1014 rootItem->i_showflags &= ~( meta );
1015 rootItem->updateview();
1020 beginInsertColumns( createIndex( 0, 0, rootItem), index, index+1 );
1021 rootItem->i_showflags |= meta;
1022 rootItem->updateview();
1026 config_PutInt( p_intf, "qt-pl-showflags", rootItem->i_showflags );
1027 config_SaveConfigFile( p_intf, NULL );
1031 void PLModel::popupDel()
1033 doDelete( current_selection );
1035 void PLModel::popupPlay()
1039 playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
1040 i_popup_item,VLC_TRUE );
1041 activateItem( p_item );
1046 void PLModel::popupInfo()
1048 playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
1049 i_popup_item,VLC_TRUE );
1052 MediaInfoDialog *mid = new MediaInfoDialog( p_intf );
1053 mid->setInput( p_item->p_input );
1058 void PLModel::popupStream()
1060 fprintf( stderr, "Stream not implemented\n" );
1062 void PLModel::popupSave()
1064 fprintf( stderr, "Save not implemented\n" );
1068 #include <shellapi.h>
1069 void PLModel::popupExplore()
1071 ShellExecuteW(NULL, L"explore", L"C:\\", NULL, NULL, SW_SHOWNORMAL );
1075 /**********************************************************************
1076 * Playlist callbacks
1077 **********************************************************************/
1078 static int PlaylistChanged( vlc_object_t *p_this, const char *psz_variable,
1079 vlc_value_t oval, vlc_value_t nval, void *param )
1081 PLModel *p_model = (PLModel *) param;
1082 PLEvent *event = new PLEvent( PLUpdate_Type, 0 );
1083 QApplication::postEvent( p_model, static_cast<QEvent*>(event) );
1087 static int PlaylistNext( vlc_object_t *p_this, const char *psz_variable,
1088 vlc_value_t oval, vlc_value_t nval, void *param )
1090 PLModel *p_model = (PLModel *) param;
1091 PLEvent *event = new PLEvent( ItemUpdate_Type, oval.i_int );
1092 QApplication::postEvent( p_model, static_cast<QEvent*>(event) );
1093 event = new PLEvent( ItemUpdate_Type, nval.i_int );
1094 QApplication::postEvent( p_model, static_cast<QEvent*>(event) );
1098 static int ItemChanged( 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 PLEvent *event = new PLEvent( ItemUpdate_Type, nval.i_int );
1103 QApplication::postEvent( p_model, static_cast<QEvent*>(event) );
1107 static int ItemDeleted( vlc_object_t *p_this, const char *psz_variable,
1108 vlc_value_t oval, vlc_value_t nval, void *param )
1110 PLModel *p_model = (PLModel *) param;
1111 PLEvent *event = new PLEvent( ItemDelete_Type, nval.i_int );
1112 QApplication::postEvent( p_model, static_cast<QEvent*>(event) );
1116 static int ItemAppended( vlc_object_t *p_this, const char *psz_variable,
1117 vlc_value_t oval, vlc_value_t nval, void *param )
1119 PLModel *p_model = (PLModel *) param;
1120 playlist_add_t *p_add = (playlist_add_t *)malloc( sizeof( playlist_add_t));
1121 memcpy( p_add, nval.p_address, sizeof( playlist_add_t ) );
1123 if( ++p_model->i_items_to_append >= 50 )
1125 // p_model->b_need_update = VLC_TRUE;
1126 // return VLC_SUCCESS;
1128 PLEvent *event = new PLEvent( p_add );
1129 QApplication::postEvent( p_model, static_cast<QEvent*>(event) );