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 *****************************************************************************/
31 #include <QApplication>
34 #include "components/playlist/playlist_model.hpp"
35 #include "dialogs/mediainfo.hpp"
36 #include <vlc_intf_strings.h>
38 #include "pixmaps/type_unknown.xpm"
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 item implementation
57 *************************************************************************/
60 Playlist item is just a wrapper, an abstraction of the playlist_item
61 in order to be managed by PLModel
63 PLItem have a parent, and id and a input Id
67 void PLItem::init( int _i_id, int _i_input_id, PLItem *parent, PLModel *m )
69 parentItem = parent; /* Can be NULL, but only for the rootItem */
70 i_id = _i_id; /* Playlist item specific id */
71 i_input_id = _i_input_id; /* Identifier of the input */
72 model = m; /* PLModel (QAbsmodel) */
73 i_type = -1; /* Item type - Avoid segfault */
78 /* No parent, should be the main one */
79 if( parentItem == NULL )
81 i_showflags = config_GetInt( model->p_intf, "qt-pl-showflags" );
86 i_showflags = parentItem->i_showflags;
87 //Add empty string and update() handles data appending
88 item_col_strings.append( "" );
90 msg_Dbg( model->p_intf, "PLItem created of type: %i", model->i_depth );
95 Call the above function init
96 So far the first constructor isn't used...
98 PLItem::PLItem( int _i_id, int _i_input_id, PLItem *parent, PLModel *m )
100 init( _i_id, _i_input_id, parent, m );
103 PLItem::PLItem( playlist_item_t * p_item, PLItem *parent, PLModel *m )
105 init( p_item->i_id, p_item->p_input->i_id, parent, m );
110 qDeleteAll( children );
115 void PLItem::updateview()
117 item_col_strings.clear();
119 if( model->i_depth == 1 ) /* Selector Panel */
121 item_col_strings.append( "" );
125 for( int i_index=1; i_index <= VLC_META_ENGINE_ART_URL; i_index *= 2 )
127 if( i_showflags & i_index )
131 case VLC_META_ENGINE_ARTIST:
132 item_col_strings.append( qtr( VLC_META_ARTIST ) );
134 case VLC_META_ENGINE_TITLE:
135 item_col_strings.append( qtr( VLC_META_TITLE ) );
137 case VLC_META_ENGINE_DESCRIPTION:
138 item_col_strings.append( qtr( VLC_META_DESCRIPTION ) );
140 case VLC_META_ENGINE_DURATION:
141 item_col_strings.append( qtr( "Duration" ) );
143 case VLC_META_ENGINE_GENRE:
144 item_col_strings.append( qtr( VLC_META_GENRE ) );
146 case VLC_META_ENGINE_COLLECTION:
147 item_col_strings.append( qtr( VLC_META_COLLECTION ) );
149 case VLC_META_ENGINE_SEQ_NUM:
150 item_col_strings.append( qtr( VLC_META_SEQ_NUM ) );
152 case VLC_META_ENGINE_RATING:
153 item_col_strings.append( qtr( VLC_META_RATING ) );
162 /* So far signal is always true.
163 Using signal false would not call PLModel... Why ?
165 void PLItem::insertChild( PLItem *item, int i_pos, bool signal )
168 model->beginInsertRows( model->index( this , 0 ), i_pos, i_pos );
169 children.insert( i_pos, item );
171 model->endInsertRows();
174 void PLItem::remove( PLItem *removed )
176 if( model->i_depth == DEPTH_SEL || parentItem )
178 int i_index = parentItem->children.indexOf( removed );
179 model->beginRemoveRows( model->index( parentItem, 0 ),
181 parentItem->children.removeAt( i_index );
182 model->endRemoveRows();
186 /* This function is used to get one's parent's row number in the model */
187 int PLItem::row() const
190 return parentItem->children.indexOf( const_cast<PLItem*>(this) ); // Why this ? I don't think we ever inherit PLItem
194 /* update the PL Item, get the good names and so on */
195 void PLItem::update( playlist_item_t *p_item, bool iscurrent )
197 char psz_duration[MSTRTIME_MAX_SIZE];
200 assert( p_item->p_input->i_id == i_input_id );
202 i_type = p_item->p_input->i_type;
203 b_current = iscurrent;
205 item_col_strings.clear();
207 if( model->i_depth == 1 ) /* Selector Panel */
209 item_col_strings.append( qfu( p_item->p_input->psz_name ) );
213 #define ADD_META( item, meta ) \
214 psz_meta = input_item_Get ## meta ( item->p_input ); \
215 item_col_strings.append( qfu( psz_meta ) ); \
218 for( int i_index=1; i_index <= VLC_META_ENGINE_ART_URL; i_index *= 2 )
220 if( parentItem->i_showflags & i_index )
224 case VLC_META_ENGINE_ARTIST:
225 ADD_META( p_item, Artist );
227 case VLC_META_ENGINE_TITLE:
228 char *psz_title, *psz_name;
229 psz_title = input_item_GetTitle( p_item->p_input );
230 psz_name = input_item_GetName( p_item->p_input );
233 ADD_META( p_item, Title );
237 item_col_strings.append( qfu( psz_name ) );
242 case VLC_META_ENGINE_DESCRIPTION:
243 ADD_META( p_item, Description );
245 case VLC_META_ENGINE_DURATION:
246 secstotimestr( psz_duration,
247 input_item_GetDuration( p_item->p_input ) / 1000000 );
248 item_col_strings.append( QString( psz_duration ) );
250 case VLC_META_ENGINE_GENRE:
251 ADD_META( p_item, Genre );
253 case VLC_META_ENGINE_COLLECTION:
254 ADD_META( p_item, Album );
256 case VLC_META_ENGINE_SEQ_NUM:
257 ADD_META( p_item, TrackNum );
259 case VLC_META_ENGINE_RATING:
260 ADD_META( p_item, Rating );
270 /*************************************************************************
271 * Playlist model implementation
272 *************************************************************************/
275 This model is called two times, for the selector and the standard panel
277 PLModel::PLModel( playlist_t *_p_playlist, /* THEPL */
278 intf_thread_t *_p_intf, /* main Qt p_intf */
279 playlist_item_t * p_root,
280 /*playlist_GetPreferredNode( THEPL, THEPL->p_local_category );
281 and THEPL->p_root_category for SelectPL */
282 int _i_depth, /* -1 for StandPL, 1 for SelectPL */
283 QObject *parent ) /* Basic Qt parent */
284 : QAbstractItemModel( parent )
287 assert( i_depth == DEPTH_SEL || i_depth == DEPTH_PL );
289 p_playlist = _p_playlist;
290 i_items_to_append = 0;
291 b_need_update = false;
293 i_cached_input_id = -1;
294 i_popup_item = i_popup_parent = -1;
296 rootItem = NULL; /* PLItem rootItem, will be set in rebuild( ) */
298 /* Icons initialization */
299 #define ADD_ICON(type, x) icons[ITEM_TYPE_##type] = QIcon( QPixmap( x ) )
300 ADD_ICON( UNKNOWN , type_unknown_xpm );
301 ADD_ICON( FILE, ":/pixmaps/type_file.png" );
302 ADD_ICON( DIRECTORY, ":/pixmaps/type_directory.png" );
303 ADD_ICON( DISC, ":/pixmaps/disc_16px.png" );
304 ADD_ICON( CDDA, ":/pixmaps/cdda_16px.png" );
305 ADD_ICON( CARD, ":/pixmaps/capture-card_16px.png" );
306 ADD_ICON( NET, ":/pixmaps/type_net.png" );
307 ADD_ICON( PLAYLIST, ":/pixmaps/type_playlist.png" );
308 ADD_ICON( NODE, ":/pixmaps/type_node.png" );
321 Qt::DropActions PLModel::supportedDropActions() const
323 return Qt::CopyAction; /* Why not Qt::MoveAction */
326 Qt::ItemFlags PLModel::flags( const QModelIndex &index ) const
328 Qt::ItemFlags defaultFlags = QAbstractItemModel::flags( index );
329 if( index.isValid() )
330 return Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | defaultFlags;
332 return Qt::ItemIsDropEnabled | defaultFlags;
335 /* A list of model indexes are a playlist */
336 QStringList PLModel::mimeTypes() const
339 types << "vlc/playlist-item-id";
343 QMimeData *PLModel::mimeData( const QModelIndexList &indexes ) const
345 QMimeData *mimeData = new QMimeData();
346 QByteArray encodedData;
347 QDataStream stream( &encodedData, QIODevice::WriteOnly );
349 foreach( QModelIndex index, indexes ) {
350 if( index.isValid() && index.column() == 0 )
351 stream << itemId( index );
353 mimeData->setData( "vlc/playlist-item-id", encodedData );
358 bool PLModel::dropMimeData( const QMimeData *data, Qt::DropAction action,
359 int row, int column, const QModelIndex &target )
361 if( data->hasFormat( "vlc/playlist-item-id" ) )
363 if( action == Qt::IgnoreAction )
367 if( target.isValid() )
368 targetItem = static_cast<PLItem*>( target.internalPointer() );
370 targetItem = rootItem;
372 QByteArray encodedData = data->data( "vlc/playlist-item-id" );
373 QDataStream stream( &encodedData, QIODevice::ReadOnly );
375 PLItem *newParentItem;
376 while( !stream.atEnd() )
383 playlist_item_t *p_target =
384 playlist_ItemGetById( p_playlist, targetItem->i_id,
386 playlist_item_t *p_src = playlist_ItemGetById( p_playlist, srcId,
389 if( !p_target || !p_src )
394 if( p_target->i_children == -1 ) /* A leaf */
396 PLItem *parentItem = targetItem->parent();
397 assert( parentItem );
398 playlist_item_t *p_parent =
399 playlist_ItemGetById( p_playlist, parentItem->i_id,
406 for( i = 0 ; i< p_parent->i_children ; i++ )
407 if( p_parent->pp_children[i] == p_target ) break;
408 playlist_TreeMove( p_playlist, p_src, p_parent, i );
409 newParentItem = parentItem;
413 /* \todo: if we drop on a top-level node, use copy instead ? */
414 playlist_TreeMove( p_playlist, p_src, p_target, 0 );
416 newParentItem = targetItem;
418 /* Remove from source */
419 PLItem *srcItem = FindById( rootItem, p_src->i_id );
420 // We dropped on the source selector. Ask the dialog to forward
424 emit shouldRemove( p_src->i_id );
427 srcItem->remove( srcItem );
429 /* Display at new destination */
430 PLItem *newItem = new PLItem( p_src, newParentItem, this );
431 newParentItem->insertChild( newItem, i, true );
432 UpdateTreeItem( p_src, newItem, true );
433 if( p_src->i_children != -1 )
434 UpdateNodeChildren( newItem );
441 /* remove item with its id */
442 void PLModel::removeItem( int i_id )
444 PLItem *item = FindById( rootItem, i_id );
445 if( item ) item->remove( item );
448 /* callbacks and slots */
449 void PLModel::addCallbacks()
451 /* Some global changes happened -> Rebuild all */
452 var_AddCallback( p_playlist, "intf-change", PlaylistChanged, this );
453 /* We went to the next item */
454 var_AddCallback( p_playlist, "playlist-current", PlaylistNext, this );
455 /* One item has been updated */
456 var_AddCallback( p_playlist, "item-change", ItemChanged, this );
457 var_AddCallback( p_playlist, "item-append", ItemAppended, this );
458 var_AddCallback( p_playlist, "item-deleted", ItemDeleted, this );
461 void PLModel::delCallbacks()
463 var_DelCallback( p_playlist, "item-change", ItemChanged, this );
464 var_DelCallback( p_playlist, "playlist-current", PlaylistNext, this );
465 var_DelCallback( p_playlist, "intf-change", PlaylistChanged, this );
466 var_DelCallback( p_playlist, "item-append", ItemAppended, this );
467 var_DelCallback( p_playlist, "item-deleted", ItemDeleted, this );
470 void PLModel::activateItem( const QModelIndex &index )
472 assert( index.isValid() );
473 PLItem *item = static_cast<PLItem*>(index.internalPointer());
476 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id,
478 activateItem( p_item );
482 /* Must be entered with lock */
483 void PLModel::activateItem( playlist_item_t *p_item )
485 if( !p_item ) return;
486 playlist_item_t *p_parent = p_item;
489 if( p_parent->i_id == rootItem->i_id ) break;
490 p_parent = p_parent->p_parent;
493 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, VLC_TRUE,
497 /****************** Base model mandatory implementations *****************/
498 QVariant PLModel::data( const QModelIndex &index, int role ) const
500 if( !index.isValid() ) return QVariant();
501 PLItem *item = static_cast<PLItem*>(index.internalPointer());
502 if( role == Qt::DisplayRole )
504 return QVariant( item->columnString( index.column() ) );
506 else if( role == Qt::DecorationRole && index.column() == 0 )
508 /* Use to segfault here because i_type wasn't always initialized */
509 if( item->i_type >= 0 )
510 return QVariant( PLModel::icons[item->i_type] );
512 else if( role == Qt::FontRole )
514 if( item->b_current == true )
516 QFont f; f.setBold( true ); return QVariant( f );
522 bool PLModel::isCurrent( const QModelIndex &index )
524 assert( index.isValid() );
525 return static_cast<PLItem*>(index.internalPointer())->b_current;
528 int PLModel::itemId( const QModelIndex &index ) const
530 assert( index.isValid() );
531 return static_cast<PLItem*>(index.internalPointer())->i_id;
534 QVariant PLModel::headerData( int section, Qt::Orientation orientation,
537 if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
538 return QVariant( rootItem->columnString( section ) );
542 QModelIndex PLModel::index( int row, int column, const QModelIndex &parent )
546 if( !parent.isValid() )
547 parentItem = rootItem;
549 parentItem = static_cast<PLItem*>(parent.internalPointer());
551 PLItem *childItem = parentItem->child( row );
553 return createIndex( row, column, childItem );
555 return QModelIndex();
558 /* Return the index of a given item */
559 QModelIndex PLModel::index( PLItem *item, int column ) const
561 if( !item ) return QModelIndex();
562 const PLItem *parent = item->parent();
564 return createIndex( parent->children.lastIndexOf( item ),
566 return QModelIndex();
569 QModelIndex PLModel::parent( const QModelIndex &index ) const
571 if( !index.isValid() ) return QModelIndex();
573 PLItem *childItem = static_cast<PLItem*>(index.internalPointer());
576 msg_Err( p_playlist, "NULL CHILD" );
577 return QModelIndex();
580 PLItem *parentItem = childItem->parent();
581 if( !parentItem || parentItem == rootItem ) return QModelIndex();
582 if( !parentItem->parentItem )
584 msg_Err( p_playlist, "No parent parent, trying row 0 " );
585 msg_Err( p_playlist, "----- PLEASE REPORT THIS ------" );
586 return createIndex( 0, 0, parentItem );
588 QModelIndex ind = createIndex(parentItem->row(), 0, parentItem);
592 int PLModel::columnCount( const QModelIndex &i) const
594 return rootItem->item_col_strings.count();
597 int PLModel::childrenCount( const QModelIndex &parent ) const
599 return rowCount( parent );
602 int PLModel::rowCount( const QModelIndex &parent ) const
606 if( !parent.isValid() )
607 parentItem = rootItem;
609 parentItem = static_cast<PLItem*>(parent.internalPointer());
611 return parentItem->childCount();
614 /************************* General playlist status ***********************/
616 bool PLModel::hasRandom()
618 if( var_GetBool( p_playlist, "random" ) ) return true;
621 bool PLModel::hasRepeat()
623 if( var_GetBool( p_playlist, "repeat" ) ) return true;
626 bool PLModel::hasLoop()
628 if( var_GetBool( p_playlist, "loop" ) ) return true;
631 void PLModel::setLoop( bool on )
633 var_SetBool( p_playlist, "loop", on ? VLC_TRUE:VLC_FALSE );
634 config_PutInt( p_playlist, "loop", on ? 1: 0 );
636 void PLModel::setRepeat( bool on )
638 var_SetBool( p_playlist, "repeat", on ? VLC_TRUE:VLC_FALSE );
639 config_PutInt( p_playlist, "repeat", on ? 1: 0 );
641 void PLModel::setRandom( bool on )
643 var_SetBool( p_playlist, "random", on ? VLC_TRUE:VLC_FALSE );
644 config_PutInt( p_playlist, "random", on ? 1: 0 );
647 /************************* Lookups *****************************/
649 PLItem *PLModel::FindById( PLItem *root, int i_id )
651 return FindInner( root, i_id, false );
654 PLItem *PLModel::FindByInput( PLItem *root, int i_id )
656 return FindInner( root, i_id, true );
659 #define CACHE( i, p ) { i_cached_id = i; p_cached_item = p; }
660 #define ICACHE( i, p ) { i_cached_input_id = i; p_cached_item_bi = p; }
662 PLItem * PLModel::FindInner( PLItem *root, int i_id, bool b_input )
664 if( ( !b_input && i_cached_id == i_id) ||
665 ( b_input && i_cached_input_id ==i_id ) )
667 return b_input ? p_cached_item_bi : p_cached_item;
670 if( !b_input && root->i_id == i_id )
675 else if( b_input && root->i_input_id == i_id )
677 ICACHE( i_id, root );
681 QList<PLItem *>::iterator it = root->children.begin();
682 while ( it != root->children.end() )
684 if( !b_input && (*it)->i_id == i_id )
686 CACHE( i_id, (*it) );
687 return p_cached_item;
689 else if( b_input && (*it)->i_input_id == i_id )
691 ICACHE( i_id, (*it) );
692 return p_cached_item_bi;
694 if( (*it)->children.size() )
696 PLItem *childFound = FindInner( (*it), i_id, b_input );
700 ICACHE( i_id, childFound )
702 CACHE( i_id, childFound )
714 /************************* Updates handling *****************************/
715 void PLModel::customEvent( QEvent *event )
717 int type = event->type();
718 if( type != ItemUpdate_Type && type != ItemAppend_Type &&
719 type != ItemDelete_Type && type != PLUpdate_Type )
722 PLEvent *ple = static_cast<PLEvent *>(event);
724 if( type == ItemUpdate_Type )
725 ProcessInputItemUpdate( ple->i_id );
726 else if( type == ItemAppend_Type )
727 ProcessItemAppend( ple->p_add );
728 else if( type == ItemDelete_Type )
729 ProcessItemRemoval( ple->i_id );
734 /**** Events processing ****/
735 void PLModel::ProcessInputItemUpdate( int i_input_id )
737 if( i_input_id <= 0 ) return;
738 PLItem *item = FindByInput( rootItem, i_input_id );
740 UpdateTreeItem( item, true );
743 void PLModel::ProcessItemRemoval( int i_id )
745 if( i_id <= 0 ) return;
746 if( i_id == i_cached_id ) i_cached_id = -1;
747 i_cached_input_id = -1;
752 void PLModel::ProcessItemAppend( playlist_add_t *p_add )
754 playlist_item_t *p_item = NULL;
755 PLItem *newItem = NULL;
757 if( b_need_update ) return;
759 PLItem *nodeItem = FindById( rootItem, p_add->i_node );
761 if( !nodeItem ) goto end;
763 p_item = playlist_ItemGetById( p_playlist, p_add->i_item, VLC_TRUE );
764 if( !p_item || p_item->i_flags & PLAYLIST_DBL_FLAG ) goto end;
765 if( i_depth == DEPTH_SEL && p_item->p_parent &&
766 p_item->p_parent->i_id != rootItem->i_id )
769 newItem = new PLItem( p_item, nodeItem, this );
770 nodeItem->appendChild( newItem );
771 UpdateTreeItem( p_item, newItem, true );
778 void PLModel::rebuild()
783 void PLModel::rebuild( playlist_item_t *p_root )
785 /* Remove callbacks before locking to avoid deadlocks */
787 /* Invalidate cache */
788 i_cached_id = i_cached_input_id = -1;
794 if( rootItem->children.size() )
796 beginRemoveRows( index( rootItem, 0 ), 0,
797 rootItem->children.size() -1 );
798 qDeleteAll( rootItem->children );
799 rootItem->children.clear();
805 //if( rootItem ) delete rootItem;
806 rootItem = new PLItem( p_root, NULL, this );
809 /* Recreate from root */
810 UpdateNodeChildren( rootItem );
811 if( p_playlist->status.p_item )
813 PLItem *currentItem = FindByInput( rootItem,
814 p_playlist->status.p_item->p_input->i_id );
817 UpdateTreeItem( p_playlist->status.p_item, currentItem,
823 /* And signal the view */
824 emit layoutChanged();
828 /* This function must be entered WITH the playlist lock */
829 void PLModel::UpdateNodeChildren( PLItem *root )
831 playlist_item_t *p_node = playlist_ItemGetById( p_playlist, root->i_id,
833 UpdateNodeChildren( p_node, root );
836 /* This function must be entered WITH the playlist lock */
837 void PLModel::UpdateNodeChildren( playlist_item_t *p_node, PLItem *root )
839 for( int i = 0; i < p_node->i_children ; i++ )
841 if( p_node->pp_children[i]->i_flags & PLAYLIST_DBL_FLAG ) continue;
842 PLItem *newItem = new PLItem( p_node->pp_children[i], root, this );
843 root->appendChild( newItem, false );
844 UpdateTreeItem( newItem, false, true );
845 if( i_depth == DEPTH_PL && p_node->pp_children[i]->i_children != -1 )
846 UpdateNodeChildren( p_node->pp_children[i], newItem );
850 /* This function must be entered WITH the playlist lock */
851 void PLModel::UpdateTreeItem( PLItem *item, bool signal, bool force )
853 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id,
855 UpdateTreeItem( p_item, item, signal, force );
858 /* This function must be entered WITH the playlist lock */
859 void PLModel::UpdateTreeItem( playlist_item_t *p_item, PLItem *item,
860 bool signal, bool force )
864 if( !force && i_depth == DEPTH_SEL && p_item->p_parent &&
865 p_item->p_parent->i_id != rootItem->i_id )
867 item->update( p_item, p_item == p_playlist->status.p_item );
869 emit dataChanged( index( item, 0 ) , index( item, 1 ) );
872 /************************* Actions ******************************/
875 * Deletion, here we have to do a ugly slow hack as we retrieve the full
876 * list of indexes to delete at once: when we delete a node and all of
877 * its children, we need to update the list.
878 * Todo: investigate whethere we can use ranges to be sure to delete all items?
880 void PLModel::doDelete( QModelIndexList selected )
882 for( int i = selected.size() -1 ; i >= 0; i-- )
884 QModelIndex index = selected[i];
885 if( index.column() != 0 ) continue;
886 PLItem *item = static_cast<PLItem*>(index.internalPointer());
889 if( item->children.size() )
890 recurseDelete( item->children, &selected );
891 doDeleteItem( item, &selected );
896 void PLModel::recurseDelete( QList<PLItem*> children, QModelIndexList *fullList )
898 for( int i = children.size() - 1; i >= 0 ; i-- )
900 PLItem *item = children[i];
901 if( item->children.size() )
902 recurseDelete( item->children, fullList );
903 doDeleteItem( item, fullList );
907 void PLModel::doDeleteItem( PLItem *item, QModelIndexList *fullList )
909 QModelIndex deleteIndex = index( item, 0 );
910 fullList->removeAll( deleteIndex );
913 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id,
919 if( p_item->i_children == -1 )
920 playlist_DeleteFromInput( p_playlist, item->i_input_id, VLC_TRUE );
922 playlist_NodeDelete( p_playlist, p_item, VLC_TRUE, VLC_FALSE );
923 /* And finally, remove it from the tree */
924 item->remove( item );
928 /******* Volume III: Sorting and searching ********/
929 void PLModel::sort( int column, Qt::SortOrder order )
933 playlist_item_t *p_root = playlist_ItemGetById( p_playlist,
939 case 0: i_mode = SORT_TITLE_NODES_FIRST;break;
940 case 1: i_mode = SORT_ARTIST;break;
941 case 2: i_mode = SORT_DURATION; break;
942 default: i_mode = SORT_TITLE_NODES_FIRST; break;
945 playlist_RecursiveNodeSort( p_playlist, p_root, i_mode,
946 order == Qt::AscendingOrder ?
947 ORDER_NORMAL : ORDER_REVERSE );
953 void PLModel::search( QString search_text )
955 /** \todo Fire the search with a small delay ? */
958 playlist_item_t *p_root = playlist_ItemGetById( p_playlist,
962 char *psz_name = search_text.toUtf8().data();
963 playlist_LiveSearchUpdate( p_playlist , p_root, psz_name );
969 /*********** Popup *********/
970 void PLModel::popup( QModelIndex & index, QPoint &point, QModelIndexList list )
972 assert( index.isValid() );
974 playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
975 itemId( index ), VLC_TRUE );
978 i_popup_item = p_item->i_id;
979 i_popup_parent = p_item->p_parent ? p_item->p_parent->i_id : -1;
981 current_selection = list;
982 QMenu *menu = new QMenu;
983 menu->addAction( qfu(I_POP_PLAY), this, SLOT( popupPlay() ) );
984 menu->addAction( qfu(I_POP_DEL), this, SLOT( popupDel() ) );
985 menu->addSeparator();
986 menu->addAction( qfu(I_POP_STREAM), this, SLOT( popupStream() ) );
987 menu->addAction( qfu(I_POP_SAVE), this, SLOT( popupSave() ) );
988 menu->addSeparator();
989 menu->addAction( qfu(I_POP_INFO), this, SLOT( popupInfo() ) );
990 if( p_item->i_children > -1 )
992 menu->addSeparator();
993 menu->addAction( qfu(I_POP_SORT), this, SLOT( popupSort() ) );
994 menu->addAction( qfu(I_POP_ADD), this, SLOT( popupAdd() ) );
997 menu->addSeparator();
998 menu->addAction( qfu( I_POP_EXPLORE ), this, SLOT( popupExplore() ) );
1000 menu->popup( point );
1007 void PLModel::viewchanged( int meta )
1014 case VLC_META_ENGINE_TITLE:
1016 case VLC_META_ENGINE_DURATION:
1018 case VLC_META_ENGINE_ARTIST:
1020 case VLC_META_ENGINE_GENRE:
1022 case VLC_META_ENGINE_COPYRIGHT:
1024 case VLC_META_ENGINE_COLLECTION:
1026 case VLC_META_ENGINE_SEQ_NUM:
1028 case VLC_META_ENGINE_DESCRIPTION:
1033 /* UNUSED emit layoutAboutToBeChanged(); */
1034 index = __MIN( index , rootItem->item_col_strings.count() );
1035 QModelIndex parent = createIndex( 0, 0, rootItem );
1037 if( rootItem->i_showflags & meta )
1038 /* Removing columns */
1040 beginRemoveColumns( parent, index, index+1 );
1041 rootItem->i_showflags &= ~( meta );
1042 rootItem->updateview();
1047 /* Adding columns */
1048 beginInsertColumns( createIndex( 0, 0, rootItem), index, index+1 );
1049 rootItem->i_showflags |= meta;
1050 rootItem->updateview();
1054 config_PutInt( p_intf, "qt-pl-showflags", rootItem->i_showflags );
1055 config_SaveConfigFile( p_intf, NULL );
1059 void PLModel::popupDel()
1061 doDelete( current_selection );
1063 void PLModel::popupPlay()
1067 playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
1068 i_popup_item,VLC_TRUE );
1069 activateItem( p_item );
1074 void PLModel::popupInfo()
1076 playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
1081 MediaInfoDialog *mid = new MediaInfoDialog( p_intf, p_item->p_input );
1086 void PLModel::popupStream()
1088 msg_Err( p_playlist, "Stream not implemented" );
1091 void PLModel::popupSave()
1093 msg_Err( p_playlist, "Save not implemented" );
1097 #include <shellapi.h>
1098 void PLModel::popupExplore()
1100 ShellExecuteW( NULL, L"explore", L"C:\\", NULL, NULL, SW_SHOWNORMAL );
1104 /**********************************************************************
1105 * Playlist callbacks
1106 **********************************************************************/
1107 static int PlaylistChanged( 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( PLUpdate_Type, 0 );
1112 QApplication::postEvent( p_model, static_cast<QEvent*>(event) );
1116 static int PlaylistNext( 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 PLEvent *event = new PLEvent( ItemUpdate_Type, oval.i_int );
1121 QApplication::postEvent( p_model, static_cast<QEvent*>(event) );
1122 event = new PLEvent( ItemUpdate_Type, nval.i_int );
1123 QApplication::postEvent( p_model, static_cast<QEvent*>(event) );
1127 static int ItemChanged( vlc_object_t *p_this, const char *psz_variable,
1128 vlc_value_t oval, vlc_value_t nval, void *param )
1130 PLModel *p_model = (PLModel *) param;
1131 PLEvent *event = new PLEvent( ItemUpdate_Type, nval.i_int );
1132 QApplication::postEvent( p_model, static_cast<QEvent*>(event) );
1136 static int ItemDeleted( vlc_object_t *p_this, const char *psz_variable,
1137 vlc_value_t oval, vlc_value_t nval, void *param )
1139 PLModel *p_model = (PLModel *) param;
1140 PLEvent *event = new PLEvent( ItemDelete_Type, nval.i_int );
1141 QApplication::postEvent( p_model, static_cast<QEvent*>(event) );
1145 static int ItemAppended( vlc_object_t *p_this, const char *psz_variable,
1146 vlc_value_t oval, vlc_value_t nval, void *param )
1148 PLModel *p_model = (PLModel *) param;
1149 playlist_add_t *p_add = (playlist_add_t *)malloc( sizeof( playlist_add_t));
1150 memcpy( p_add, nval.p_address, sizeof( playlist_add_t ) );
1152 if( ++p_model->i_items_to_append >= 50 )
1154 // p_model->b_need_update = VLC_TRUE;
1155 // return VLC_SUCCESS;
1157 PLEvent *event = new PLEvent( p_add );
1158 QApplication::postEvent( p_model, static_cast<QEvent*>(event) );