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"
36 #include "pixmaps/type_file.xpm"
37 #include "pixmaps/type_net.xpm"
38 #include "pixmaps/type_card.xpm"
39 #include "pixmaps/type_disc.xpm"
40 #include "pixmaps/type_cdda.xpm"
41 #include "pixmaps/type_directory.xpm"
42 #include "pixmaps/type_playlist.xpm"
43 #include "pixmaps/type_node.xpm"
45 QIcon PLModel::icons[ITEM_TYPE_NUMBER];
47 static int PlaylistChanged( vlc_object_t *, const char *,
48 vlc_value_t, vlc_value_t, void * );
49 static int PlaylistNext( vlc_object_t *, const char *,
50 vlc_value_t, vlc_value_t, void * );
51 static int ItemChanged( vlc_object_t *, const char *,
52 vlc_value_t, vlc_value_t, void * );
53 static int ItemAppended( vlc_object_t *p_this, const char *psz_variable,
54 vlc_value_t oval, vlc_value_t nval, void *param );
55 static int ItemDeleted( vlc_object_t *p_this, const char *psz_variable,
56 vlc_value_t oval, vlc_value_t nval, void *param );
58 /*************************************************************************
59 * Playlist item implementation
60 *************************************************************************/
69 void PLItem::init( int _i_id, int _i_input_id, PLItem *parent, PLModel *m)
72 i_id = _i_id; i_input_id = _i_input_id;
75 if( parentItem == NULL )
77 i_showflags = config_GetInt( model->p_intf , "qt-pl-showflags" );
80 i_showflags = parentItem->i_showflags;
81 //Add empty string and update() handles data appending
86 void PLItem::updateview( void )
90 if( model->i_depth == 1 ) //left window for playlist etc.
96 for( int i_index=1; i_index <= VLC_META_ENGINE_ART_URL; i_index = i_index*2 )
98 if( i_showflags & i_index )
102 case VLC_META_ENGINE_ARTIST:
103 strings.append( qtr( VLC_META_ARTIST ) );
105 case VLC_META_ENGINE_TITLE:
106 strings.append( qtr( VLC_META_TITLE ) );
108 case VLC_META_ENGINE_DESCRIPTION:
109 strings.append( qtr( VLC_META_DESCRIPTION ) );
111 case VLC_META_ENGINE_DURATION:
112 strings.append( qtr( "Duration" ) );
114 case VLC_META_ENGINE_GENRE:
115 strings.append( qtr( VLC_META_GENRE ) );
117 case VLC_META_ENGINE_COLLECTION:
118 strings.append( qtr( VLC_META_COLLECTION ) );
120 case VLC_META_ENGINE_SEQ_NUM:
121 strings.append( qtr( VLC_META_SEQ_NUM ) );
123 case VLC_META_ENGINE_RATING:
124 strings.append( qtr( VLC_META_RATING ) );
134 PLItem::PLItem( int _i_id, int _i_input_id, PLItem *parent, PLModel *m)
136 init( _i_id, _i_input_id, parent, m );
139 PLItem::PLItem( playlist_item_t * p_item, PLItem *parent, PLModel *m )
141 init( p_item->i_id, p_item->p_input->i_id, parent, m );
146 qDeleteAll(children);
150 void PLItem::insertChild( PLItem *item, int i_pos, bool signal )
154 model->beginInsertRows( model->index( this , 0 ), i_pos, i_pos );
155 children.insert( i_pos, item );
157 model->endInsertRows();
160 void PLItem::remove( PLItem *removed )
162 assert( model && parentItem );
163 int i_index = parentItem->children.indexOf( removed );
164 model->beginRemoveRows( model->index( parentItem, 0 ), i_index, i_index );
165 parentItem->children.removeAt( i_index );
166 model->endRemoveRows();
169 int PLItem::row() const
172 return parentItem->children.indexOf(const_cast<PLItem*>(this));
176 void PLItem::update( playlist_item_t *p_item, bool iscurrent )
178 char psz_duration[MSTRTIME_MAX_SIZE];
179 assert( p_item->p_input->i_id == i_input_id );
181 type = p_item->p_input->i_type;
184 char *psz_arturl = input_item_GetArtURL( p_item->p_input );
185 if( ( current && psz_arturl ) &&
186 !strncmp( psz_arturl, "file://", 7 ) )
187 model->sendArt( qfu( psz_arturl ) ) ;
194 if( model->i_depth == 1 ) //left window for playlist etc.
196 strings.append( qfu( p_item->p_input->psz_name ) );
201 #define ADD_META( item, meta ) \
202 psz_meta = input_item_Get ## meta ( item->p_input ); \
203 strings.append( qfu( psz_meta ) ); \
206 for( int i_index=1; i_index <= VLC_META_ENGINE_ART_URL; i_index = i_index * 2 )
208 if( parentItem->i_showflags & i_index )
212 case VLC_META_ENGINE_ARTIST:
213 ADD_META( p_item, Artist );
215 case VLC_META_ENGINE_TITLE:
216 char *psz_title, *psz_name;
217 psz_title = input_item_GetTitle( p_item->p_input );
218 psz_name = input_item_GetName( p_item->p_input );
221 ADD_META( p_item, Title );
223 strings.append( qfu( psz_name ) );
228 case VLC_META_ENGINE_DESCRIPTION:
229 ADD_META( p_item, Description );
231 case VLC_META_ENGINE_DURATION:
232 secstotimestr( psz_duration,
233 input_item_GetDuration( p_item->p_input ) / 1000000 );
234 strings.append( QString( psz_duration ) );
236 case VLC_META_ENGINE_GENRE:
237 ADD_META( p_item, Genre );
239 case VLC_META_ENGINE_COLLECTION:
240 ADD_META( p_item, Album );
242 case VLC_META_ENGINE_SEQ_NUM:
243 ADD_META( p_item, TrackNum );
245 case VLC_META_ENGINE_RATING:
246 ADD_META( p_item, Rating );
256 /*************************************************************************
257 * Playlist model implementation
258 *************************************************************************/
260 PLModel::PLModel( playlist_t *_p_playlist, intf_thread_t *_p_intf,
261 playlist_item_t * p_root, int _i_depth, QObject *parent)
262 : QAbstractItemModel(parent)
265 assert( i_depth == 1 || i_depth == -1 );
267 p_playlist= _p_playlist;
268 i_items_to_append = 0;
269 b_need_update = false;
271 i_cached_input_id = -1;
272 i_popup_item = i_popup_parent = -1;
274 #define ADD_ICON(type, x) icons[ITEM_TYPE_##type] = QIcon( QPixmap( type_##x##_xpm ) );
275 ADD_ICON( UNKNOWN , unknown );
276 ADD_ICON( FILE, file );
277 ADD_ICON( DIRECTORY, directory );
278 ADD_ICON( DISC, disc );
279 ADD_ICON( CDDA, cdda );
280 ADD_ICON( CARD, card );
281 ADD_ICON( NET, net );
282 ADD_ICON( PLAYLIST, playlist );
283 ADD_ICON( NODE, node );
296 Qt::DropActions PLModel::supportedDropActions() const
298 return Qt::CopyAction;
301 Qt::ItemFlags PLModel::flags(const QModelIndex &index) const
303 Qt::ItemFlags defaultFlags = QAbstractItemModel::flags(index);
304 if( index.isValid() )
305 return Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | defaultFlags;
307 return Qt::ItemIsDropEnabled | defaultFlags;
310 QStringList PLModel::mimeTypes() const
313 types << "vlc/playlist-item-id";
317 QMimeData *PLModel::mimeData(const QModelIndexList &indexes) const
319 QMimeData *mimeData = new QMimeData();
320 QByteArray encodedData;
321 QDataStream stream(&encodedData, QIODevice::WriteOnly);
323 foreach (QModelIndex index, indexes) {
324 if (index.isValid() && index.column() == 0 )
325 stream << itemId(index);
327 mimeData->setData("vlc/playlist-item-id", encodedData);
331 bool PLModel::dropMimeData(const QMimeData *data, Qt::DropAction action,
332 int row, int column, const QModelIndex &target)
334 if ( data->hasFormat("vlc/playlist-item-id") )
336 if (action == Qt::IgnoreAction)
340 if( target.isValid() )
341 targetItem = static_cast<PLItem*>( target.internalPointer() );
343 targetItem = rootItem;
345 QByteArray encodedData = data->data("vlc/playlist-item-id");
346 QDataStream stream(&encodedData, QIODevice::ReadOnly);
348 PLItem *newParentItem;
349 while (!stream.atEnd())
356 playlist_item_t *p_target =
357 playlist_ItemGetById( p_playlist, targetItem->i_id,
359 playlist_item_t *p_src = playlist_ItemGetById( p_playlist, srcId,
362 if( !p_target || !p_src )
367 if( p_target->i_children == -1 ) /* A leaf */
369 PLItem *parentItem = targetItem->parent();
370 assert( parentItem );
371 playlist_item_t *p_parent =
372 playlist_ItemGetById( p_playlist, parentItem->i_id,
379 for( i = 0 ; i< p_parent->i_children ; i++ )
380 if( p_parent->pp_children[i] == p_target ) break;
381 playlist_TreeMove( p_playlist, p_src, p_parent, i );
382 newParentItem = parentItem;
386 /* \todo: if we drop on a top-level node, use copy instead ? */
387 playlist_TreeMove( p_playlist, p_src, p_target, 0 );
389 newParentItem = targetItem;
391 /* Remove from source */
392 PLItem *srcItem = FindById( rootItem, p_src->i_id );
393 // We dropped on the source selector. Ask the dialog to forward
397 emit shouldRemove( p_src->i_id );
400 srcItem->remove( srcItem );
402 /* Display at new destination */
403 PLItem *newItem = new PLItem( p_src, newParentItem, this );
404 newParentItem->insertChild( newItem, i, true );
405 UpdateTreeItem( p_src, newItem, true );
406 if( p_src->i_children != -1 )
407 UpdateNodeChildren( newItem );
414 void PLModel::removeItem( int i_id )
416 PLItem *item = FindById( rootItem,i_id );
417 if( item ) item->remove( item );
420 void PLModel::addCallbacks()
422 /* Some global changes happened -> Rebuild all */
423 var_AddCallback( p_playlist, "intf-change", PlaylistChanged, this );
424 /* We went to the next item */
425 var_AddCallback( p_playlist, "playlist-current", PlaylistNext, this );
426 /* One item has been updated */
427 var_AddCallback( p_playlist, "item-change", ItemChanged, this );
428 var_AddCallback( p_playlist, "item-append", ItemAppended, this );
429 var_AddCallback( p_playlist, "item-deleted", ItemDeleted, this );
432 void PLModel::delCallbacks()
434 var_DelCallback( p_playlist, "item-change", ItemChanged, this );
435 var_DelCallback( p_playlist, "playlist-current", PlaylistNext, this );
436 var_DelCallback( p_playlist, "intf-change", PlaylistChanged, this );
437 var_DelCallback( p_playlist, "item-append", ItemAppended, this );
438 var_DelCallback( p_playlist, "item-deleted", ItemDeleted, this );
441 void PLModel::activateItem( const QModelIndex &index )
443 assert( index.isValid() );
444 PLItem *item = static_cast<PLItem*>(index.internalPointer());
447 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id,
449 activateItem( p_item );
452 /* Must be entered with lock */
453 void PLModel::activateItem( playlist_item_t *p_item )
455 if( !p_item ) return;
456 playlist_item_t *p_parent = p_item;
459 if( p_parent->i_id == rootItem->i_id ) break;
460 p_parent = p_parent->p_parent;
463 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, VLC_TRUE, p_parent, p_item );
466 /****************** Base model mandatory implementations *****************/
467 QVariant PLModel::data(const QModelIndex &index, int role) const
469 if(!index.isValid() ) return QVariant();
470 PLItem *item = static_cast<PLItem*>(index.internalPointer());
471 if( role == Qt::DisplayRole )
473 return QVariant( item->columnString( index.column() ) );
475 else if( role == Qt::DecorationRole && index.column() == 0 )
477 if( item->type >= 0 )
478 return QVariant( PLModel::icons[item->type] );
480 else if( role == Qt::FontRole )
482 if( item->current == true )
484 QFont f; f.setBold( true ); return QVariant( f );
490 bool PLModel::isCurrent( const QModelIndex &index )
492 assert( index.isValid() );
493 return static_cast<PLItem*>(index.internalPointer())->current;
496 int PLModel::itemId( const QModelIndex &index ) const
498 assert( index.isValid() );
499 return static_cast<PLItem*>(index.internalPointer())->i_id;
502 QVariant PLModel::headerData( int section, Qt::Orientation orientation,
505 if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
506 return QVariant( rootItem->columnString( section ) );
510 QModelIndex PLModel::index(int row, int column, const QModelIndex &parent)
514 if (!parent.isValid())
515 parentItem = rootItem;
517 parentItem = static_cast<PLItem*>(parent.internalPointer());
519 PLItem *childItem = parentItem->child(row);
521 return createIndex(row, column, childItem);
523 return QModelIndex();
526 /* Return the index of a given item */
527 QModelIndex PLModel::index( PLItem *item, int column ) const
529 if( !item ) return QModelIndex();
530 const PLItem *parent = item->parent();
532 return createIndex( parent->children.lastIndexOf( item ),
534 return QModelIndex();
537 QModelIndex PLModel::parent(const QModelIndex &index) const
539 if( !index.isValid() ) return QModelIndex();
541 PLItem *childItem = static_cast<PLItem*>(index.internalPointer());
542 if( !childItem ) { msg_Err( p_playlist, "NULL CHILD \n" ); return QModelIndex(); }
543 PLItem *parentItem = childItem->parent();
544 if( !parentItem || parentItem == rootItem ) return QModelIndex();
545 if( ! parentItem->parentItem )
547 msg_Err( p_playlist, "No parent parent, trying row 0 " );
548 msg_Err( p_playlist, "----- PLEASE REPORT THIS ------" );
549 return createIndex( 0, 0, parentItem );
551 QModelIndex ind = createIndex(parentItem->row(), 0, parentItem);
555 int PLModel::columnCount( const QModelIndex &i) const
557 return rootItem->strings.count();
560 int PLModel::childrenCount(const QModelIndex &parent) const
562 return rowCount( parent );
565 int PLModel::rowCount(const QModelIndex &parent) const
569 if (!parent.isValid())
570 parentItem = rootItem;
572 parentItem = static_cast<PLItem*>(parent.internalPointer());
574 return parentItem->childCount();
577 /************************* General playlist status ***********************/
579 bool PLModel::hasRandom()
581 if( var_GetBool( p_playlist, "random" ) ) return true;
584 bool PLModel::hasRepeat()
586 if( var_GetBool( p_playlist, "repeat" ) ) return true;
589 bool PLModel::hasLoop()
591 if( var_GetBool( p_playlist, "loop" ) ) return true;
594 void PLModel::setLoop( bool on )
596 var_SetBool( p_playlist, "loop", on ? VLC_TRUE:VLC_FALSE );
597 config_PutInt( p_playlist, "loop", on ? 1: 0 );
599 void PLModel::setRepeat( bool on )
601 var_SetBool( p_playlist, "repeat", on ? VLC_TRUE:VLC_FALSE );
602 config_PutInt( p_playlist, "repeat", on ? 1: 0 );
604 void PLModel::setRandom( bool on )
606 var_SetBool( p_playlist, "random", on ? VLC_TRUE:VLC_FALSE );
607 config_PutInt( p_playlist, "random", on ? 1: 0 );
610 /************************* Lookups *****************************/
612 PLItem *PLModel::FindById( PLItem *root, int i_id )
614 return FindInner( root, i_id, false );
617 PLItem *PLModel::FindByInput( PLItem *root, int i_id )
619 return FindInner( root, i_id, true );
622 #define CACHE( i, p ) { i_cached_id = i; p_cached_item = p; }
623 #define ICACHE( i, p ) { i_cached_input_id = i; p_cached_item_bi = p; }
625 PLItem * PLModel::FindInner( PLItem *root, int i_id, bool b_input )
627 if( ( !b_input && i_cached_id == i_id) ||
628 ( b_input && i_cached_input_id ==i_id ) )
630 return b_input ? p_cached_item_bi : p_cached_item;
633 if( !b_input && root->i_id == i_id )
638 else if( b_input && root->i_input_id == i_id )
640 ICACHE( i_id, root );
644 QList<PLItem *>::iterator it = root->children.begin();
645 while ( it != root->children.end() )
647 if( !b_input && (*it)->i_id == i_id )
649 CACHE( i_id, (*it) );
650 return p_cached_item;
652 else if( b_input && (*it)->i_input_id == i_id )
654 ICACHE( i_id, (*it) );
655 return p_cached_item_bi;
657 if( (*it)->children.size() )
659 PLItem *childFound = FindInner( (*it), i_id, b_input );
663 ICACHE( i_id, childFound )
665 CACHE( i_id, childFound )
677 /************************* Updates handling *****************************/
678 void PLModel::customEvent( QEvent *event )
680 int type = event->type();
681 if( type != ItemUpdate_Type && type != ItemAppend_Type &&
682 type != ItemDelete_Type && type != PLUpdate_Type )
685 PLEvent *ple = static_cast<PLEvent *>(event);
687 if( type == ItemUpdate_Type )
688 ProcessInputItemUpdate( ple->i_id );
689 else if( type == ItemAppend_Type )
690 ProcessItemAppend( ple->p_add );
691 else if( type == ItemDelete_Type )
692 ProcessItemRemoval( ple->i_id );
697 /**** Events processing ****/
698 void PLModel::ProcessInputItemUpdate( int i_input_id )
700 if( i_input_id <= 0 ) return;
701 PLItem *item = FindByInput( rootItem, i_input_id );
703 UpdateTreeItem( item, true );
706 void PLModel::ProcessItemRemoval( int i_id )
708 if( i_id <= 0 ) return;
709 if( i_id == i_cached_id ) i_cached_id = -1;
710 i_cached_input_id = -1;
711 PLItem *item = FindById( rootItem, i_id );
713 item->remove( item );
716 void PLModel::ProcessItemAppend( playlist_add_t *p_add )
718 playlist_item_t *p_item = NULL;
719 PLItem *newItem = NULL;
721 if( b_need_update ) return;
723 PLItem *nodeItem = FindById( rootItem, p_add->i_node );
725 if( !nodeItem ) goto end;
727 p_item = playlist_ItemGetById( p_playlist, p_add->i_item, VLC_TRUE );
728 if( !p_item || p_item->i_flags & PLAYLIST_DBL_FLAG ) goto end;
729 if( i_depth == 1 && p_item->p_parent &&
730 p_item->p_parent->i_id != rootItem->i_id )
733 newItem = new PLItem( p_item, nodeItem, this );
734 nodeItem->appendChild( newItem );
735 UpdateTreeItem( p_item, newItem, true );
742 void PLModel::rebuild()
747 void PLModel::rebuild( playlist_item_t *p_root )
749 /* Remove callbacks before locking to avoid deadlocks */
751 /* Invalidate cache */
752 i_cached_id = i_cached_input_id = -1;
758 if( rootItem->children.size() )
760 beginRemoveRows( index( rootItem, 0 ), 0,
761 rootItem->children.size() -1 );
762 qDeleteAll( rootItem->children );
763 rootItem->children.clear();
769 //if( rootItem ) delete rootItem;
770 rootItem = new PLItem( p_root, NULL, this );
773 /* Recreate from root */
774 UpdateNodeChildren( rootItem );
775 if( p_playlist->status.p_item )
777 PLItem *currentItem = FindByInput( rootItem,
778 p_playlist->status.p_item->p_input->i_id );
781 UpdateTreeItem( p_playlist->status.p_item, currentItem,
787 /* And signal the view */
788 emit layoutChanged();
792 /* This function must be entered WITH the playlist lock */
793 void PLModel::UpdateNodeChildren( PLItem *root )
795 playlist_item_t *p_node = playlist_ItemGetById( p_playlist, root->i_id,
797 UpdateNodeChildren( p_node, root );
800 /* This function must be entered WITH the playlist lock */
801 void PLModel::UpdateNodeChildren( playlist_item_t *p_node, PLItem *root )
803 for( int i = 0; i < p_node->i_children ; i++ )
805 if( p_node->pp_children[i]->i_flags & PLAYLIST_DBL_FLAG ) continue;
806 PLItem *newItem = new PLItem( p_node->pp_children[i], root, this );
807 root->appendChild( newItem, false );
808 UpdateTreeItem( newItem, false, true );
809 if( i_depth != 1 && p_node->pp_children[i]->i_children != -1 )
810 UpdateNodeChildren( p_node->pp_children[i], newItem );
814 /* This function must be entered WITH the playlist lock */
815 void PLModel::UpdateTreeItem( PLItem *item, bool signal, bool force )
817 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id,
819 UpdateTreeItem( p_item, item, signal, force );
822 /* This function must be entered WITH the playlist lock */
823 void PLModel::UpdateTreeItem( playlist_item_t *p_item, PLItem *item,
824 bool signal, bool force )
828 if( !force && i_depth == 1 && p_item->p_parent &&
829 p_item->p_parent->i_id != rootItem->i_id )
831 item->update( p_item, p_item == p_playlist->status.p_item );
833 emit dataChanged( index( item, 0 ) , index( item, 1 ) );
836 /************************* Actions ******************************/
838 void PLModel::sendArt( QString url )
840 QString arturl = url.replace( "file://",QString("" ) );
841 emit artSet( arturl );
844 void PLModel::removeArt()
846 emit artSet( QString() );
850 * Deletion, here we have to do a ugly slow hack as we retrieve the full
851 * list of indexes to delete at once: when we delete a node and all of
852 * its children, we need to update the list.
853 * Todo: investigate whethere we can use ranges to be sure to delete all items?
855 void PLModel::doDelete( QModelIndexList selected )
857 for( int i = selected.size() -1 ; i >= 0; i-- )
859 QModelIndex index = selected[i];
860 if( index.column() != 0 ) continue;
861 PLItem *item = static_cast<PLItem*>(index.internalPointer());
864 if( item->children.size() )
865 recurseDelete( item->children, &selected );
866 doDeleteItem( item, &selected );
871 void PLModel::recurseDelete( QList<PLItem*> children, QModelIndexList *fullList)
873 for( int i = children.size() - 1; i >= 0 ; i-- )
875 PLItem *item = children[i];
876 if( item->children.size() )
877 recurseDelete( item->children, fullList );
878 doDeleteItem( item, fullList );
882 void PLModel::doDeleteItem( PLItem *item, QModelIndexList *fullList )
884 QModelIndex deleteIndex = index( item, 0 );
885 fullList->removeAll( deleteIndex );
888 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id,
894 if( p_item->i_children == -1 )
895 playlist_DeleteFromInput( p_playlist, item->i_input_id, VLC_TRUE );
897 playlist_NodeDelete( p_playlist, p_item, VLC_TRUE, VLC_FALSE );
898 /* And finally, remove it from the tree */
899 item->remove( item );
903 /******* Volume III: Sorting and searching ********/
904 void PLModel::sort( int column, Qt::SortOrder order )
908 playlist_item_t *p_root = playlist_ItemGetById( p_playlist,
914 case 0: i_mode = SORT_TITLE_NODES_FIRST;break;
915 case 1: i_mode = SORT_ARTIST;break;
916 case 2: i_mode = SORT_DURATION; break;
917 default: i_mode = SORT_TITLE_NODES_FIRST; break;
920 playlist_RecursiveNodeSort( p_playlist, p_root, i_mode,
921 order == Qt::AscendingOrder ?
922 ORDER_NORMAL : ORDER_REVERSE );
928 void PLModel::search( QString search_text )
930 /** \todo Fire the search with a small delay ? */
933 playlist_item_t *p_root = playlist_ItemGetById( p_playlist,
937 char *psz_name = search_text.toUtf8().data();
938 playlist_LiveSearchUpdate( p_playlist , p_root, psz_name );
944 /*********** Popup *********/
945 void PLModel::popup( QModelIndex & index, QPoint &point, QModelIndexList list )
947 assert( index.isValid() );
949 playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
950 itemId( index ), VLC_TRUE );
953 i_popup_item = p_item->i_id;
954 i_popup_parent = p_item->p_parent ? p_item->p_parent->i_id : -1;
956 current_selection = list;
957 QMenu *menu = new QMenu;
958 menu->addAction( qfu(I_POP_PLAY), this, SLOT( popupPlay() ) );
959 menu->addAction( qfu(I_POP_DEL), this, SLOT( popupDel() ) );
960 menu->addSeparator();
961 menu->addAction( qfu(I_POP_STREAM), this, SLOT( popupStream() ) );
962 menu->addAction( qfu(I_POP_SAVE), this, SLOT( popupSave() ) );
963 menu->addSeparator();
964 menu->addAction( qfu(I_POP_INFO), this, SLOT( popupInfo() ) );
965 if( p_item->i_children > -1 )
967 menu->addSeparator();
968 menu->addAction( qfu(I_POP_SORT), this, SLOT( popupSort() ) );
969 menu->addAction( qfu(I_POP_ADD), this, SLOT( popupAdd() ) );
972 menu->addSeparator();
973 menu->addAction( qfu( I_POP_EXPLORE ), this, SLOT( popupExplore() ) );
975 menu->popup( point );
982 void PLModel::viewchanged( int meta )
989 case VLC_META_ENGINE_TITLE:
992 case VLC_META_ENGINE_DURATION:
995 case VLC_META_ENGINE_ARTIST:
998 case VLC_META_ENGINE_GENRE:
1001 case VLC_META_ENGINE_COPYRIGHT:
1004 case VLC_META_ENGINE_COLLECTION:
1007 case VLC_META_ENGINE_SEQ_NUM:
1010 case VLC_META_ENGINE_DESCRIPTION:
1016 emit layoutAboutToBeChanged();
1017 index = __MIN( index , rootItem->strings.count() );
1018 QModelIndex parent = createIndex( 0, 0, rootItem );
1019 if( rootItem->i_showflags & meta )
1021 beginRemoveColumns( parent , index, index+1 );
1022 rootItem->i_showflags &= ~( meta );
1023 rootItem->updateview();
1028 beginInsertColumns( createIndex( 0, 0, rootItem), index, index+1 );
1029 rootItem->i_showflags |= meta;
1030 rootItem->updateview();
1034 config_PutInt( p_intf, "qt-pl-showflags", rootItem->i_showflags );
1035 config_SaveConfigFile( p_intf, NULL );
1039 void PLModel::popupDel()
1041 doDelete( current_selection );
1043 void PLModel::popupPlay()
1047 playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
1048 i_popup_item,VLC_TRUE );
1049 activateItem( p_item );
1054 void PLModel::popupInfo()
1056 playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
1057 i_popup_item,VLC_TRUE );
1060 MediaInfoDialog *mid = new MediaInfoDialog( p_intf );
1061 mid->setInput( p_item->p_input );
1066 void PLModel::popupStream()
1068 fprintf( stderr, "Stream not implemented\n" );
1070 void PLModel::popupSave()
1072 fprintf( stderr, "Save not implemented\n" );
1076 #include <shellapi.h>
1077 void PLModel::popupExplore()
1079 ShellExecuteW(NULL, L"explore", L"C:\\", NULL, NULL, SW_SHOWNORMAL );
1083 /**********************************************************************
1084 * Playlist callbacks
1085 **********************************************************************/
1086 static int PlaylistChanged( vlc_object_t *p_this, const char *psz_variable,
1087 vlc_value_t oval, vlc_value_t nval, void *param )
1089 PLModel *p_model = (PLModel *) param;
1090 PLEvent *event = new PLEvent( PLUpdate_Type, 0 );
1091 QApplication::postEvent( p_model, static_cast<QEvent*>(event) );
1095 static int PlaylistNext( vlc_object_t *p_this, const char *psz_variable,
1096 vlc_value_t oval, vlc_value_t nval, void *param )
1098 PLModel *p_model = (PLModel *) param;
1099 PLEvent *event = new PLEvent( ItemUpdate_Type, oval.i_int );
1100 QApplication::postEvent( p_model, static_cast<QEvent*>(event) );
1101 event = new PLEvent( ItemUpdate_Type, nval.i_int );
1102 QApplication::postEvent( p_model, static_cast<QEvent*>(event) );
1106 static int ItemChanged( vlc_object_t *p_this, const char *psz_variable,
1107 vlc_value_t oval, vlc_value_t nval, void *param )
1109 PLModel *p_model = (PLModel *) param;
1110 PLEvent *event = new PLEvent( ItemUpdate_Type, nval.i_int );
1111 QApplication::postEvent( p_model, static_cast<QEvent*>(event) );
1115 static int ItemDeleted( vlc_object_t *p_this, const char *psz_variable,
1116 vlc_value_t oval, vlc_value_t nval, void *param )
1118 PLModel *p_model = (PLModel *) param;
1119 PLEvent *event = new PLEvent( ItemDelete_Type, nval.i_int );
1120 QApplication::postEvent( p_model, static_cast<QEvent*>(event) );
1124 static int ItemAppended( vlc_object_t *p_this, const char *psz_variable,
1125 vlc_value_t oval, vlc_value_t nval, void *param )
1127 PLModel *p_model = (PLModel *) param;
1128 playlist_add_t *p_add = (playlist_add_t *)malloc( sizeof( playlist_add_t));
1129 memcpy( p_add, nval.p_address, sizeof( playlist_add_t ) );
1131 if( ++p_model->i_items_to_append >= 50 )
1133 // p_model->b_need_update = VLC_TRUE;
1134 // return VLC_SUCCESS;
1136 PLEvent *event = new PLEvent( p_add );
1137 QApplication::postEvent( p_model, static_cast<QEvent*>(event) );