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 *****************************************************************************/
23 #define PLI_NAME( p ) p ? p->p_input->psz_name : "null"
29 #include <QApplication>
32 #include "playlist_model.hpp"
33 #include "dialogs/mediainfo.hpp"
34 #include <vlc_intf_strings.h>
36 #include "pixmaps/type_unknown.xpm"
37 #include "pixmaps/type_afile.xpm"
38 #include "pixmaps/type_vfile.xpm"
39 #include "pixmaps/type_net.xpm"
40 #include "pixmaps/type_card.xpm"
41 #include "pixmaps/type_disc.xpm"
42 #include "pixmaps/type_cdda.xpm"
43 #include "pixmaps/type_directory.xpm"
44 #include "pixmaps/type_playlist.xpm"
45 #include "pixmaps/type_node.xpm"
47 QIcon PLModel::icons[ITEM_TYPE_NUMBER];
49 static int PlaylistChanged( vlc_object_t *, const char *,
50 vlc_value_t, vlc_value_t, void * );
51 static int PlaylistNext( vlc_object_t *, const char *,
52 vlc_value_t, vlc_value_t, void * );
53 static int ItemChanged( vlc_object_t *, const char *,
54 vlc_value_t, vlc_value_t, void * );
55 static int ItemAppended( vlc_object_t *p_this, const char *psz_variable,
56 vlc_value_t oval, vlc_value_t nval, void *param );
57 static int ItemDeleted( vlc_object_t *p_this, const char *psz_variable,
58 vlc_value_t oval, vlc_value_t nval, void *param );
60 /*************************************************************************
61 * Playlist item implementation
62 *************************************************************************/
71 void PLItem::init( int _i_id, int _i_input_id, PLItem *parent, PLModel *m)
74 i_id = _i_id; i_input_id = _i_input_id;
78 if( parentItem == NULL )
80 i_showflags = config_GetInt( model->p_intf , "qt-pl-showflags" );
83 i_showflags = parentItem->i_showflags;
84 //Add empty string and update() handles data appending
85 strings.append( qtr("") );
89 void PLItem::updateview( void )
93 if( model->i_depth == 1 ) //left window for playlist etc.
95 strings.append( qtr("") );
99 for( int i_index=1; i_index <= VLC_META_ENGINE_MB_TRM_ID; i_index = i_index*2 )
101 if( i_showflags & i_index )
105 case VLC_META_ENGINE_ARTIST:
106 strings.append( qtr( VLC_META_ARTIST ) );
108 case VLC_META_ENGINE_TITLE:
109 strings.append( qtr( VLC_META_TITLE ) );
111 case VLC_META_ENGINE_DESCRIPTION:
112 strings.append( qtr( VLC_META_DESCRIPTION ) );
114 case VLC_META_ENGINE_DURATION:
115 strings.append( qtr( "Duration" ) );
117 case VLC_META_ENGINE_GENRE:
118 strings.append( qtr( VLC_META_GENRE ) );
120 case VLC_META_ENGINE_COLLECTION:
121 strings.append( qtr( VLC_META_COLLECTION ) );
123 case VLC_META_ENGINE_SEQ_NUM:
124 strings.append( qtr( VLC_META_SEQ_NUM ) );
126 case VLC_META_ENGINE_RATING:
127 strings.append( qtr( VLC_META_RATING ) );
137 PLItem::PLItem( int _i_id, int _i_input_id, PLItem *parent, PLModel *m)
139 init( _i_id, _i_input_id, parent, m );
142 PLItem::PLItem( playlist_item_t * p_item, PLItem *parent, PLModel *m )
144 init( p_item->i_id, p_item->p_input->i_id, parent, m );
149 qDeleteAll(children);
153 void PLItem::insertChild( PLItem *item, int i_pos, bool signal )
157 model->beginInsertRows( model->index( this , 0 ), i_pos, i_pos );
158 children.insert( i_pos, item );
160 model->endInsertRows();
163 void PLItem::remove( PLItem *removed )
165 assert( model && parentItem );
166 int i_index = parentItem->children.indexOf( removed );
167 model->beginRemoveRows( model->index( parentItem, 0 ), i_index, i_index );
168 parentItem->children.removeAt( i_index );
169 model->endRemoveRows();
172 int PLItem::row() const
175 return parentItem->children.indexOf(const_cast<PLItem*>(this));
179 void PLItem::update( playlist_item_t *p_item, bool iscurrent )
181 char psz_duration[MSTRTIME_MAX_SIZE];
182 assert( p_item->p_input->i_id == i_input_id );
184 type = p_item->p_input->i_type;
187 if( current && input_item_GetArtURL( p_item ) &&
188 !strncmp( input_item_GetArtURL( p_item ), "file://", 7 ) )
189 model->sendArt( qfu( input_item_GetArtURL( p_item ) ) );
195 if( model->i_depth == 1 ) //left window for playlist etc.
197 strings.append( p_item->p_input->psz_name );
202 #define ADD_META( item, meta ) { \
203 strings.append( qfu( input_item_Get ## meta ( item->p_input ) ) ); \
205 for( int i_index=1; i_index <= VLC_META_ENGINE_MB_TRM_ID; i_index = i_index * 2 )
207 if( parentItem->i_showflags & i_index )
211 case VLC_META_ENGINE_ARTIST:
212 ADD_META( p_item, Artist );
214 case VLC_META_ENGINE_TITLE:
215 if( input_item_GetTitle( p_item->p_input ) )
217 ADD_META( p_item, Title );
219 strings.append( qfu( p_item->p_input->psz_name ) );
222 case VLC_META_ENGINE_DESCRIPTION:
223 ADD_META( p_item, Description );
225 case VLC_META_ENGINE_DURATION:
226 secstotimestr( psz_duration, p_item->p_input->i_duration / 1000000 );
227 strings.append( QString( psz_duration ) );
229 case VLC_META_ENGINE_GENRE:
230 ADD_META( p_item, Genre );
232 case VLC_META_ENGINE_COLLECTION:
233 ADD_META( p_item, Album );
235 case VLC_META_ENGINE_SEQ_NUM:
236 ADD_META( p_item, TrackNum );
238 case VLC_META_ENGINE_RATING:
239 ADD_META( p_item, Rating );
250 /*************************************************************************
251 * Playlist model implementation
252 *************************************************************************/
254 PLModel::PLModel( playlist_t *_p_playlist, intf_thread_t *_p_intf,
255 playlist_item_t * p_root, int _i_depth, QObject *parent)
256 : QAbstractItemModel(parent)
259 assert( i_depth == 1 || i_depth == -1 );
261 p_playlist= _p_playlist;
262 i_items_to_append = 0;
263 b_need_update = false;
265 i_cached_input_id = -1;
266 i_popup_item = i_popup_parent = -1;
268 #define ADD_ICON(type, x) icons[ITEM_TYPE_##type] = QIcon( QPixmap( type_##x##_xpm ) );
269 ADD_ICON( UNKNOWN , unknown );
270 ADD_ICON( AFILE,afile );
271 ADD_ICON( VFILE, vfile );
272 ADD_ICON( DIRECTORY, directory );
273 ADD_ICON( DISC, disc );
274 ADD_ICON( CDDA, cdda );
275 ADD_ICON( CARD, card );
276 ADD_ICON( NET, net );
277 ADD_ICON( PLAYLIST, playlist );
278 ADD_ICON( NODE, node );
292 Qt::DropActions PLModel::supportedDropActions() const
294 return Qt::CopyAction;
297 Qt::ItemFlags PLModel::flags(const QModelIndex &index) const
299 Qt::ItemFlags defaultFlags = QAbstractItemModel::flags(index);
300 if( index.isValid() )
301 return Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | defaultFlags;
303 return Qt::ItemIsDropEnabled | defaultFlags;
306 QStringList PLModel::mimeTypes() const
309 types << "vlc/playlist-item-id";
313 QMimeData *PLModel::mimeData(const QModelIndexList &indexes) const
315 QMimeData *mimeData = new QMimeData();
316 QByteArray encodedData;
317 QDataStream stream(&encodedData, QIODevice::WriteOnly);
319 foreach (QModelIndex index, indexes) {
320 if (index.isValid() && index.column() == 0 )
321 stream << itemId(index);
323 mimeData->setData("vlc/playlist-item-id", encodedData);
327 bool PLModel::dropMimeData(const QMimeData *data, Qt::DropAction action,
328 int row, int column, const QModelIndex &target)
330 if ( data->hasFormat("vlc/playlist-item-id") )
332 if (action == Qt::IgnoreAction)
336 if( target.isValid() )
337 targetItem = static_cast<PLItem*>( target.internalPointer() );
339 targetItem = rootItem;
341 QByteArray encodedData = data->data("vlc/playlist-item-id");
342 QDataStream stream(&encodedData, QIODevice::ReadOnly);
344 PLItem *newParentItem;
345 while (!stream.atEnd())
352 playlist_item_t *p_target =
353 playlist_ItemGetById( p_playlist, targetItem->i_id,
355 playlist_item_t *p_src = playlist_ItemGetById( p_playlist, srcId,
358 if( !p_target || !p_src )
363 if( p_target->i_children == -1 ) /* A leaf */
365 PLItem *parentItem = targetItem->parent();
366 assert( parentItem );
367 playlist_item_t *p_parent =
368 playlist_ItemGetById( p_playlist, parentItem->i_id,
375 for( i = 0 ; i< p_parent->i_children ; i++ )
376 if( p_parent->pp_children[i] == p_target ) break;
377 playlist_TreeMove( p_playlist, p_src, p_parent, i );
378 newParentItem = parentItem;
382 /* \todo: if we drop on a top-level node, use copy instead ? */
383 playlist_TreeMove( p_playlist, p_src, p_target, 0 );
385 newParentItem = targetItem;
387 /* Remove from source */
388 PLItem *srcItem = FindById( rootItem, p_src->i_id );
389 // We dropped on the source selector. Ask the dialog to forward
393 emit shouldRemove( p_src->i_id );
396 srcItem->remove( srcItem );
398 /* Display at new destination */
399 PLItem *newItem = new PLItem( p_src, newParentItem, this );
400 newParentItem->insertChild( newItem, i, true );
401 UpdateTreeItem( p_src, newItem, true );
402 if( p_src->i_children != -1 )
403 UpdateNodeChildren( newItem );
410 void PLModel::removeItem( int i_id )
412 PLItem *item = FindById( rootItem,i_id );
413 if( item ) item->remove( item );
416 void PLModel::addCallbacks()
418 /* Some global changes happened -> Rebuild all */
419 var_AddCallback( p_playlist, "intf-change", PlaylistChanged, this );
420 /* We went to the next item */
421 var_AddCallback( p_playlist, "playlist-current", PlaylistNext, this );
422 /* One item has been updated */
423 var_AddCallback( p_playlist, "item-change", ItemChanged, this );
424 var_AddCallback( p_playlist, "item-append", ItemAppended, this );
425 var_AddCallback( p_playlist, "item-deleted", ItemDeleted, this );
428 void PLModel::delCallbacks()
430 var_DelCallback( p_playlist, "item-change", ItemChanged, this );
431 var_DelCallback( p_playlist, "playlist-current", PlaylistNext, this );
432 var_DelCallback( p_playlist, "intf-change", PlaylistChanged, this );
433 var_DelCallback( p_playlist, "item-append", ItemAppended, this );
434 var_DelCallback( p_playlist, "item-deleted", ItemDeleted, this );
437 void PLModel::activateItem( const QModelIndex &index )
439 assert( index.isValid() );
440 PLItem *item = static_cast<PLItem*>(index.internalPointer());
443 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id,
445 activateItem( p_item );
448 /* Must be entered with lock */
449 void PLModel::activateItem( playlist_item_t *p_item )
451 if( !p_item ) return;
452 playlist_item_t *p_parent = p_item;
455 if( p_parent->i_id == rootItem->i_id ) break;
456 p_parent = p_parent->p_parent;
459 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, VLC_TRUE, p_parent, p_item );
462 /****************** Base model mandatory implementations *****************/
463 QVariant PLModel::data(const QModelIndex &index, int role) const
465 if(!index.isValid() ) return QVariant();
466 PLItem *item = static_cast<PLItem*>(index.internalPointer());
467 if( role == Qt::DisplayRole )
469 return QVariant( item->columnString( index.column() ) );
471 else if( role == Qt::DecorationRole && index.column() == 0 )
473 if( item->type >= 0 )
474 return QVariant( PLModel::icons[item->type] );
476 else if( role == Qt::FontRole )
478 if( item->current == true )
480 QFont f; f.setBold( true ); return QVariant( f );
486 bool PLModel::isCurrent( const QModelIndex &index )
488 assert( index.isValid() );
489 return static_cast<PLItem*>(index.internalPointer())->current;
492 int PLModel::itemId( const QModelIndex &index ) const
494 assert( index.isValid() );
495 return static_cast<PLItem*>(index.internalPointer())->i_id;
498 QVariant PLModel::headerData( int section, Qt::Orientation orientation,
501 if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
502 return QVariant( rootItem->columnString( section ) );
506 QModelIndex PLModel::index(int row, int column, const QModelIndex &parent)
510 if (!parent.isValid())
511 parentItem = rootItem;
513 parentItem = static_cast<PLItem*>(parent.internalPointer());
515 PLItem *childItem = parentItem->child(row);
517 return createIndex(row, column, childItem);
519 return QModelIndex();
522 /* Return the index of a given item */
523 QModelIndex PLModel::index( PLItem *item, int column ) const
525 if( !item ) return QModelIndex();
526 const PLItem *parent = item->parent();
528 return createIndex( parent->children.lastIndexOf( item ),
530 return QModelIndex();
533 QModelIndex PLModel::parent(const QModelIndex &index) const
535 if( !index.isValid() ) return QModelIndex();
537 PLItem *childItem = static_cast<PLItem*>(index.internalPointer());
538 if( !childItem ) { msg_Err( p_playlist, "NULL CHILD \n" ); return QModelIndex(); }
539 PLItem *parentItem = childItem->parent();
540 if( !parentItem || parentItem == rootItem ) return QModelIndex();
541 if( ! parentItem->parentItem )
543 msg_Err( p_playlist, "No parent parent, trying row 0 " );
544 msg_Err( p_playlist, "----- PLEASE REPORT THIS ------" );
545 return createIndex( 0, 0, parentItem );
547 QModelIndex ind = createIndex(parentItem->row(), 0, parentItem);
551 int PLModel::columnCount( const QModelIndex &i) const
553 return rootItem->strings.count();
556 int PLModel::childrenCount(const QModelIndex &parent) const
558 return rowCount( parent );
561 int PLModel::rowCount(const QModelIndex &parent) const
565 if (!parent.isValid())
566 parentItem = rootItem;
568 parentItem = static_cast<PLItem*>(parent.internalPointer());
570 return parentItem->childCount();
573 /************************* General playlist status ***********************/
575 bool PLModel::hasRandom()
577 if( var_GetBool( p_playlist, "random" ) ) return true;
580 bool PLModel::hasRepeat()
582 if( var_GetBool( p_playlist, "repeat" ) ) return true;
585 bool PLModel::hasLoop()
587 if( var_GetBool( p_playlist, "loop" ) ) return true;
590 void PLModel::setLoop( bool on )
592 var_SetBool( p_playlist, "loop", on ? VLC_TRUE:VLC_FALSE );
593 config_PutInt( p_playlist, "loop", on ? 1: 0 );
595 void PLModel::setRepeat( bool on )
597 var_SetBool( p_playlist, "repeat", on ? VLC_TRUE:VLC_FALSE );
598 config_PutInt( p_playlist, "repeat", on ? 1: 0 );
600 void PLModel::setRandom( bool on )
602 var_SetBool( p_playlist, "random", on ? VLC_TRUE:VLC_FALSE );
603 config_PutInt( p_playlist, "random", on ? 1: 0 );
606 /************************* Lookups *****************************/
608 PLItem *PLModel::FindById( PLItem *root, int i_id )
610 return FindInner( root, i_id, false );
613 PLItem *PLModel::FindByInput( PLItem *root, int i_id )
615 return FindInner( root, i_id, true );
618 #define CACHE( i, p ) { i_cached_id = i; p_cached_item = p; }
619 #define ICACHE( i, p ) { i_cached_input_id = i; p_cached_item_bi = p; }
621 PLItem * PLModel::FindInner( PLItem *root, int i_id, bool b_input )
623 if( ( !b_input && i_cached_id == i_id) ||
624 ( b_input && i_cached_input_id ==i_id ) )
626 return b_input ? p_cached_item_bi : p_cached_item;
629 if( !b_input && root->i_id == i_id )
634 else if( b_input && root->i_input_id == i_id )
636 ICACHE( i_id, root );
640 QList<PLItem *>::iterator it = root->children.begin();
641 while ( it != root->children.end() )
643 if( !b_input && (*it)->i_id == i_id )
645 CACHE( i_id, (*it) );
646 return p_cached_item;
648 else if( b_input && (*it)->i_input_id == i_id )
650 ICACHE( i_id, (*it) );
651 return p_cached_item_bi;
653 if( (*it)->children.size() )
655 PLItem *childFound = FindInner( (*it), i_id, b_input );
659 ICACHE( i_id, childFound )
661 CACHE( i_id, childFound )
673 /************************* Updates handling *****************************/
674 void PLModel::customEvent( QEvent *event )
676 int type = event->type();
677 if( type != ItemUpdate_Type && type != ItemAppend_Type &&
678 type != ItemDelete_Type && type != PLUpdate_Type )
681 PLEvent *ple = static_cast<PLEvent *>(event);
683 if( type == ItemUpdate_Type )
684 ProcessInputItemUpdate( ple->i_id );
685 else if( type == ItemAppend_Type )
686 ProcessItemAppend( ple->p_add );
687 else if( type == ItemDelete_Type )
688 ProcessItemRemoval( ple->i_id );
693 /**** Events processing ****/
694 void PLModel::ProcessInputItemUpdate( int i_input_id )
696 if( i_input_id <= 0 ) return;
697 PLItem *item = FindByInput( rootItem, i_input_id );
699 UpdateTreeItem( item, true );
702 void PLModel::ProcessItemRemoval( int i_id )
704 if( i_id <= 0 ) return;
705 if( i_id == i_cached_id ) i_cached_id = -1;
706 i_cached_input_id = -1;
707 PLItem *item = FindById( rootItem, i_id );
709 item->remove( item );
712 void PLModel::ProcessItemAppend( playlist_add_t *p_add )
714 playlist_item_t *p_item = NULL;
715 PLItem *newItem = NULL;
717 if( b_need_update ) return;
719 PLItem *nodeItem = FindById( rootItem, p_add->i_node );
721 if( !nodeItem ) goto end;
723 p_item = playlist_ItemGetById( p_playlist, p_add->i_item, VLC_TRUE );
724 if( !p_item || p_item->i_flags & PLAYLIST_DBL_FLAG ) goto end;
725 if( i_depth == 1 && p_item->p_parent &&
726 p_item->p_parent->i_id != rootItem->i_id )
729 newItem = new PLItem( p_item, nodeItem, this );
730 nodeItem->appendChild( newItem );
731 UpdateTreeItem( p_item, newItem, true );
738 void PLModel::rebuild()
743 void PLModel::rebuild( playlist_item_t *p_root )
745 /* Remove callbacks before locking to avoid deadlocks */
747 /* Invalidate cache */
748 i_cached_id = i_cached_input_id = -1;
754 if( rootItem->children.size() )
756 beginRemoveRows( index( rootItem, 0 ), 0,
757 rootItem->children.size() -1 );
758 qDeleteAll( rootItem->children );
759 rootItem->children.clear();
765 //if( rootItem ) delete rootItem;
766 rootItem = new PLItem( p_root, NULL, this );
769 /* Recreate from root */
770 UpdateNodeChildren( rootItem );
771 if( p_playlist->status.p_item )
773 PLItem *currentItem = FindByInput( rootItem,
774 p_playlist->status.p_item->p_input->i_id );
777 UpdateTreeItem( p_playlist->status.p_item, currentItem,
783 /* And signal the view */
784 emit layoutChanged();
788 /* This function must be entered WITH the playlist lock */
789 void PLModel::UpdateNodeChildren( PLItem *root )
791 playlist_item_t *p_node = playlist_ItemGetById( p_playlist, root->i_id,
793 UpdateNodeChildren( p_node, root );
796 /* This function must be entered WITH the playlist lock */
797 void PLModel::UpdateNodeChildren( playlist_item_t *p_node, PLItem *root )
799 for( int i = 0; i < p_node->i_children ; i++ )
801 if( p_node->pp_children[i]->i_flags & PLAYLIST_DBL_FLAG ) continue;
802 PLItem *newItem = new PLItem( p_node->pp_children[i], root, this );
803 root->appendChild( newItem, false );
804 UpdateTreeItem( newItem, false, true );
805 if( i_depth != 1 && p_node->pp_children[i]->i_children != -1 )
806 UpdateNodeChildren( p_node->pp_children[i], newItem );
810 /* This function must be entered WITH the playlist lock */
811 void PLModel::UpdateTreeItem( PLItem *item, bool signal, bool force )
813 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id,
815 UpdateTreeItem( p_item, item, signal, force );
818 /* This function must be entered WITH the playlist lock */
819 void PLModel::UpdateTreeItem( playlist_item_t *p_item, PLItem *item,
820 bool signal, bool force )
824 if( !force && i_depth == 1 && p_item->p_parent &&
825 p_item->p_parent->i_id != rootItem->i_id )
827 item->update( p_item, p_item == p_playlist->status.p_item );
829 emit dataChanged( index( item, 0 ) , index( item, 1 ) );
832 /************************* Actions ******************************/
834 void PLModel::sendArt( QString url )
836 QString arturl = url.replace( "file://",QString("" ) );
837 emit artSet( arturl );
840 void PLModel::removeArt()
842 emit artSet( QString() );
846 * Deletion, here we have to do a ugly slow hack as we retrieve the full
847 * list of indexes to delete at once: when we delete a node and all of
848 * its children, we need to update the list.
849 * Todo: investigate whethere we can use ranges to be sure to delete all items?
851 void PLModel::doDelete( QModelIndexList selected )
853 for( int i = selected.size() -1 ; i >= 0; i-- )
855 QModelIndex index = selected[i];
856 if( index.column() != 0 ) continue;
857 PLItem *item = static_cast<PLItem*>(index.internalPointer());
860 if( item->children.size() )
861 recurseDelete( item->children, &selected );
862 doDeleteItem( item, &selected );
867 void PLModel::recurseDelete( QList<PLItem*> children, QModelIndexList *fullList)
869 for( int i = children.size() - 1; i >= 0 ; i-- )
871 PLItem *item = children[i];
872 if( item->children.size() )
873 recurseDelete( item->children, fullList );
874 doDeleteItem( item, fullList );
878 void PLModel::doDeleteItem( PLItem *item, QModelIndexList *fullList )
880 QModelIndex deleteIndex = index( item, 0 );
881 fullList->removeAll( deleteIndex );
884 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id,
890 if( p_item->i_children == -1 )
891 playlist_DeleteFromInput( p_playlist, item->i_input_id, VLC_TRUE );
893 playlist_NodeDelete( p_playlist, p_item, VLC_TRUE, VLC_FALSE );
894 /* And finally, remove it from the tree */
895 item->remove( item );
899 /******* Volume III: Sorting and searching ********/
900 void PLModel::sort( int column, Qt::SortOrder order )
904 playlist_item_t *p_root = playlist_ItemGetById( p_playlist,
910 case 0: i_mode = SORT_TITLE_NODES_FIRST;break;
911 case 1: i_mode = SORT_ARTIST;break;
912 case 2: i_mode = SORT_DURATION; break;
913 default: i_mode = SORT_TITLE_NODES_FIRST; break;
916 playlist_RecursiveNodeSort( p_playlist, p_root, i_mode,
917 order == Qt::AscendingOrder ?
918 ORDER_NORMAL : ORDER_REVERSE );
924 void PLModel::search( QString search_text )
926 /** \todo Fire the search with a small delay ? */
929 playlist_item_t *p_root = playlist_ItemGetById( p_playlist,
933 char *psz_name = search_text.toUtf8().data();
934 playlist_LiveSearchUpdate( p_playlist , p_root, psz_name );
940 /*********** Popup *********/
941 void PLModel::popup( QModelIndex & index, QPoint &point, QModelIndexList list )
943 assert( index.isValid() );
945 playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
946 itemId( index ), VLC_TRUE );
949 i_popup_item = p_item->i_id;
950 i_popup_parent = p_item->p_parent ? p_item->p_parent->i_id : -1;
952 current_selection = list;
953 QMenu *menu = new QMenu;
954 menu->addAction( qfu(I_POP_PLAY), this, SLOT( popupPlay() ) );
955 menu->addAction( qfu(I_POP_DEL), this, SLOT( popupDel() ) );
956 menu->addSeparator();
957 menu->addAction( qfu(I_POP_STREAM), this, SLOT( popupStream() ) );
958 menu->addAction( qfu(I_POP_SAVE), this, SLOT( popupSave() ) );
959 menu->addSeparator();
960 menu->addAction( qfu(I_POP_INFO), this, SLOT( popupInfo() ) );
961 if( p_item->i_children > -1 )
963 menu->addSeparator();
964 menu->addAction( qfu(I_POP_SORT), this, SLOT( popupSort() ) );
965 menu->addAction( qfu(I_POP_ADD), this, SLOT( popupAdd() ) );
967 menu->addSeparator();
969 ContextUpdateMapper = new QSignalMapper(this);
971 QMenu *selectColMenu = new QMenu( qtr("Show columns") );
973 #define ADD_META_ACTION( meta ) { \
974 QAction* option = selectColMenu->addAction( qfu(VLC_META_##meta) ); \
975 option->setCheckable( true ); \
976 option->setChecked( rootItem->i_showflags & VLC_META_ENGINE_##meta ); \
977 ContextUpdateMapper->setMapping( option, VLC_META_ENGINE_##meta ); \
978 CONNECT( option, triggered(), ContextUpdateMapper, map() ); \
980 CONNECT(ContextUpdateMapper, mapped( int ), this, viewchanged( int ) );
982 ADD_META_ACTION( TITLE );
983 ADD_META_ACTION( ARTIST );
984 ADD_META_ACTION( DURATION );
985 ADD_META_ACTION( COLLECTION );
986 ADD_META_ACTION( GENRE );
987 ADD_META_ACTION( SEQ_NUM );
988 ADD_META_ACTION( RATING );
989 ADD_META_ACTION( DESCRIPTION );
991 #undef ADD_META_ACTION
992 menu->addMenu( selectColMenu );
993 menu->popup( point );
1000 void PLModel::viewchanged( int meta )
1007 case VLC_META_ENGINE_TITLE:
1010 case VLC_META_ENGINE_DURATION:
1013 case VLC_META_ENGINE_ARTIST:
1016 case VLC_META_ENGINE_GENRE:
1019 case VLC_META_ENGINE_COPYRIGHT:
1022 case VLC_META_ENGINE_COLLECTION:
1025 case VLC_META_ENGINE_SEQ_NUM:
1028 case VLC_META_ENGINE_DESCRIPTION:
1034 emit layoutAboutToBeChanged();
1035 index = __MIN( index , rootItem->strings.count() );
1036 QModelIndex parent = createIndex( 0, 0, rootItem );
1037 if( rootItem->i_showflags & meta )
1039 beginRemoveColumns( parent , index, index+1 );
1040 rootItem->i_showflags &= ~( meta );
1041 rootItem->updateview();
1046 beginInsertColumns( createIndex( 0, 0, rootItem), index, index+1 );
1047 rootItem->i_showflags |= meta;
1048 rootItem->updateview();
1052 config_PutInt( p_intf, "qt-pl-showflags", rootItem->i_showflags );
1053 config_SaveConfigFile( p_intf, NULL );
1057 void PLModel::popupDel()
1059 doDelete( current_selection );
1061 void PLModel::popupPlay()
1065 playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
1066 i_popup_item,VLC_TRUE );
1067 activateItem( p_item );
1072 void PLModel::popupInfo()
1074 playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
1075 i_popup_item,VLC_TRUE );
1078 MediaInfoDialog *mid = new MediaInfoDialog( p_intf );
1079 mid->setInput( p_item->p_input );
1084 void PLModel::popupStream()
1086 fprintf( stderr, "Stream not implemented\n" );
1088 void PLModel::popupSave()
1090 fprintf( stderr, "Save not implemented\n" );
1093 /**********************************************************************
1094 * Playlist callbacks
1095 **********************************************************************/
1096 static int PlaylistChanged( vlc_object_t *p_this, const char *psz_variable,
1097 vlc_value_t oval, vlc_value_t nval, void *param )
1099 PLModel *p_model = (PLModel *) param;
1100 PLEvent *event = new PLEvent( PLUpdate_Type, 0 );
1101 QApplication::postEvent( p_model, static_cast<QEvent*>(event) );
1105 static int PlaylistNext( vlc_object_t *p_this, const char *psz_variable,
1106 vlc_value_t oval, vlc_value_t nval, void *param )
1108 PLModel *p_model = (PLModel *) param;
1109 PLEvent *event = new PLEvent( ItemUpdate_Type, oval.i_int );
1110 QApplication::postEvent( p_model, static_cast<QEvent*>(event) );
1111 event = new PLEvent( ItemUpdate_Type, nval.i_int );
1112 QApplication::postEvent( p_model, static_cast<QEvent*>(event) );
1116 static int ItemChanged( 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, nval.i_int );
1121 QApplication::postEvent( p_model, static_cast<QEvent*>(event) );
1125 static int ItemDeleted( vlc_object_t *p_this, const char *psz_variable,
1126 vlc_value_t oval, vlc_value_t nval, void *param )
1128 PLModel *p_model = (PLModel *) param;
1129 PLEvent *event = new PLEvent( ItemDelete_Type, nval.i_int );
1130 QApplication::postEvent( p_model, static_cast<QEvent*>(event) );
1134 static int ItemAppended( vlc_object_t *p_this, const char *psz_variable,
1135 vlc_value_t oval, vlc_value_t nval, void *param )
1137 PLModel *p_model = (PLModel *) param;
1138 playlist_add_t *p_add = (playlist_add_t *)malloc( sizeof( playlist_add_t));
1139 memcpy( p_add, nval.p_address, sizeof( playlist_add_t ) );
1141 if( ++p_model->i_items_to_append >= 50 )
1143 // p_model->b_need_update = VLC_TRUE;
1144 // return VLC_SUCCESS;
1146 PLEvent *event = new PLEvent( p_add );
1147 QApplication::postEvent( p_model, static_cast<QEvent*>(event) );