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 *****************************************************************************/
29 #include "dialogs_provider.hpp"
30 #include "components/playlist/playlist_model.hpp"
31 #include "dialogs/mediainfo.hpp"
32 #include "dialogs/playlist.hpp"
33 #include <vlc_intf_strings.h>
35 #include "pixmaps/types/type_unknown.xpm"
41 #include <QApplication>
46 QIcon PLModel::icons[ITEM_TYPE_NUMBER];
48 static int PlaylistChanged( vlc_object_t *, const char *,
49 vlc_value_t, vlc_value_t, void * );
50 static int PlaylistNext( vlc_object_t *, const char *,
51 vlc_value_t, vlc_value_t, void * );
52 static int ItemAppended( vlc_object_t *p_this, const char *psz_variable,
53 vlc_value_t oval, vlc_value_t nval, void *param );
54 static int ItemDeleted( vlc_object_t *p_this, const char *psz_variable,
55 vlc_value_t oval, vlc_value_t nval, void *param );
57 /*************************************************************************
58 * Playlist model implementation
59 *************************************************************************/
62 This model is called two times, for the selector and the standard panel
64 PLModel::PLModel( playlist_t *_p_playlist, /* THEPL */
65 intf_thread_t *_p_intf, /* main Qt p_intf */
66 playlist_item_t * p_root,
67 /*playlist_GetPreferredNode( THEPL, THEPL->p_local_category );
68 and THEPL->p_root_category for SelectPL */
69 int _i_depth, /* -1 for StandPL, 1 for SelectPL */
70 QObject *parent ) /* Basic Qt parent */
71 : QAbstractItemModel( parent )
74 assert( i_depth == DEPTH_SEL || i_depth == DEPTH_PL );
76 p_playlist = _p_playlist;
78 i_cached_input_id = -1;
79 i_popup_item = i_popup_parent = -1;
82 rootItem = NULL; /* PLItem rootItem, will be set in rebuild( ) */
84 if( i_depth == DEPTH_SEL )
88 i_showflags = getSettings()->value( "qt-pl-showflags", COLUMN_DEFAULT ).toInt();
90 i_showflags = COLUMN_DEFAULT; /* reasonable default to show something */
91 else if ( i_showflags >= COLUMN_END )
92 i_showflags = COLUMN_END - 1; /* show everything */
95 /* Icons initialization */
96 #define ADD_ICON(type, x) icons[ITEM_TYPE_##type] = QIcon( QPixmap( x ) )
97 ADD_ICON( UNKNOWN , type_unknown_xpm );
98 ADD_ICON( FILE, ":/type/file" );
99 ADD_ICON( DIRECTORY, ":/type/directory" );
100 ADD_ICON( DISC, ":/type/disc" );
101 ADD_ICON( CDDA, ":/type/cdda" );
102 ADD_ICON( CARD, ":/type/capture-card" );
103 ADD_ICON( NET, ":/type/net" );
104 ADD_ICON( PLAYLIST, ":/type/playlist" );
105 ADD_ICON( NODE, ":/type/node" );
109 CONNECT( THEMIM->getIM(), metaChanged( input_item_t *),
110 this, ProcessInputItemUpdate( input_item_t *) );
111 CONNECT( THEMIM, inputChanged( input_thread_t * ),
112 this, ProcessInputItemUpdate( input_thread_t* ) );
114 playlist_item_t *p_item;
115 /* Check if there's allready some item playing when playlist
116 * model is created, if so, tell model that it's currentone
118 if( (p_item = playlist_CurrentPlayingItem(p_playlist)) )
120 currentItem = FindByInput( rootItem,
121 p_item->p_input->i_id );
122 emit currentChanged( index( currentItem, 0 ) );
130 getSettings()->setValue( "qt-pl-showflags", i_showflags );
135 Qt::DropActions PLModel::supportedDropActions() const
137 return Qt::CopyAction; /* Why not Qt::MoveAction */
140 Qt::ItemFlags PLModel::flags( const QModelIndex &index ) const
142 Qt::ItemFlags flags = QAbstractItemModel::flags( index );
144 PLItem *item = index.isValid() ?
145 static_cast<PLItem*>( index.internalPointer() ) :
148 input_item_t *pl_input = p_playlist->p_local_category->p_input;
149 input_item_t *ml_input = p_playlist->p_ml_category->p_input;
151 if( rootItem->i_id == p_playlist->p_root_onelevel->i_id
152 || rootItem->i_id == p_playlist->p_root_category->i_id )
154 if( item->p_input == pl_input
155 || item->p_input == ml_input)
156 flags |= Qt::ItemIsDropEnabled;
160 if ( (item->childCount() > 0) &&
161 ( rootItem->p_input == pl_input ||
162 rootItem->p_input == ml_input ) )
163 flags |= Qt::ItemIsDropEnabled;
164 flags |= Qt::ItemIsDragEnabled;
170 /* A list of model indexes are a playlist */
171 QStringList PLModel::mimeTypes() const
174 types << "vlc/playlist-item-id";
178 QMimeData *PLModel::mimeData( const QModelIndexList &indexes ) const
180 QMimeData *mimeData = new QMimeData();
181 QByteArray encodedData;
182 QDataStream stream( &encodedData, QIODevice::WriteOnly );
183 QModelIndexList list;
185 foreach( const QModelIndex &index, indexes ) {
186 if( index.isValid() && index.column() == 0 )
192 foreach( const QModelIndex &index, list ) {
193 stream << itemId( index );
195 mimeData->setData( "vlc/playlist-item-id", encodedData );
200 bool PLModel::dropMimeData( const QMimeData *data, Qt::DropAction action,
201 int row, int column, const QModelIndex &parent )
203 if( data->hasFormat( "vlc/playlist-item-id" ) )
205 if( action == Qt::IgnoreAction )
210 playlist_item_t *p_parent;
212 if( !parent.isValid())
216 // dropped into top node
217 p_parent = playlist_ItemGetById( p_playlist, rootItem->i_id );
221 // dropped outside any item
228 // dropped into/onto an item (depends on (row = -1) or (row > -1))
229 p_parent = playlist_ItemGetById( p_playlist, itemId ( parent ) );
231 if( !p_parent || p_parent->i_children == -1 )
239 ( p_parent->p_input == p_playlist->p_local_category->p_input
240 || p_parent->p_input == p_playlist->p_ml_category->p_input ) )
243 QByteArray encodedData = data->data( "vlc/playlist-item-id" );
244 QDataStream stream( &encodedData, QIODevice::ReadOnly );
246 /* easiest way to never miss the right index to move to is to
247 track the previously moved item */
248 playlist_item_t *p_target = NULL;
250 while( !stream.atEnd() )
254 playlist_item_t *p_src = playlist_ItemGetById( p_playlist, src_id );
263 input_item_t *input = p_src->p_input;
264 playlist_AddExt ( p_playlist,
265 p_src->p_input->psz_uri, p_src->p_input->psz_name,
266 PLAYLIST_APPEND | PLAYLIST_SPREPARSE, PLAYLIST_END,
268 input->i_options, input->ppsz_options, input->optflagc,
269 p_parent == p_playlist->p_local_category, true );
274 if ( row == -1 ) row = p_parent->i_children;
275 playlist_TreeMove( p_playlist, p_src, p_parent, row );
279 for( row = 0 ; row < p_target->p_parent->i_children ; row++ )
280 if( p_target->p_parent->pp_children[row] == p_target ) break;
281 playlist_TreeMove( p_playlist, p_src, p_parent, row + 1 );
286 /*TODO: That's not a good idea to rebuild the playlist */
292 /* remove item with its id */
293 void PLModel::removeItem( int i_id )
295 PLItem *item = FindById( rootItem, i_id );
296 if( currentItem && item && currentItem->p_input == item->p_input ) currentItem = NULL;
297 if( item ) item->remove( item, i_depth );
300 /* callbacks and slots */
301 void PLModel::addCallbacks()
303 /* Some global changes happened -> Rebuild all */
304 var_AddCallback( p_playlist, "intf-change", PlaylistChanged, this );
305 /* We went to the next item
306 var_AddCallback( p_playlist, "item-current", PlaylistNext, this );
308 /* One item has been updated */
309 var_AddCallback( p_playlist, "playlist-item-append", ItemAppended, this );
310 var_AddCallback( p_playlist, "playlist-item-deleted", ItemDeleted, this );
313 void PLModel::delCallbacks()
316 var_DelCallback( p_playlist, "item-current", PlaylistNext, this );
318 var_DelCallback( p_playlist, "intf-change", PlaylistChanged, this );
319 var_DelCallback( p_playlist, "playlist-item-append", ItemAppended, this );
320 var_DelCallback( p_playlist, "playlist-item-deleted", ItemDeleted, this );
323 void PLModel::activateItem( const QModelIndex &index )
325 assert( index.isValid() );
326 PLItem *item = static_cast<PLItem*>(index.internalPointer());
329 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id );
330 activateItem( p_item );
334 /* Must be entered with lock */
335 void PLModel::activateItem( playlist_item_t *p_item )
337 if( !p_item ) return;
338 playlist_item_t *p_parent = p_item;
341 if( p_parent->i_id == rootItem->i_id ) break;
342 p_parent = p_parent->p_parent;
345 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, pl_Locked,
349 /****************** Base model mandatory implementations *****************/
350 QVariant PLModel::data( const QModelIndex &index, int role ) const
352 if( !index.isValid() ) return QVariant();
353 PLItem *item = static_cast<PLItem*>(index.internalPointer());
354 if( role == Qt::DisplayRole )
356 int running_index = -1;
360 if( i_depth == DEPTH_SEL )
362 vlc_mutex_lock( &item->p_input->lock );
363 QString returninfo = QString( qfu( item->p_input->psz_name ) );
364 vlc_mutex_unlock( &item->p_input->lock );
365 return QVariant(returninfo);
368 while( metadata < COLUMN_END )
370 if( i_showflags & metadata )
372 if( running_index == index.column() )
377 if( running_index != index.column() ) return QVariant();
380 if( metadata == COLUMN_NUMBER )
381 returninfo = QString::number( index.row() + 1 );
384 char *psz = psz_column_meta( item->p_input, metadata );
385 returninfo = QString( qfu( psz ) );
388 return QVariant( returninfo );
390 else if( role == Qt::DecorationRole && index.column() == 0 )
392 /* Use to segfault here because i_type wasn't always initialized */
393 if( item->p_input->i_type >= 0 )
394 return QVariant( PLModel::icons[item->p_input->i_type] );
396 else if( role == Qt::FontRole )
398 if( isCurrent( index ) )
400 QFont f; f.setBold( true ); return QVariant( f );
406 bool PLModel::isCurrent( const QModelIndex &index ) const
408 assert( index.isValid() );
409 if( !currentItem ) return false;
410 return static_cast<PLItem*>(index.internalPointer())->p_input == currentItem->p_input;
413 int PLModel::itemId( const QModelIndex &index ) const
415 assert( index.isValid() );
416 return static_cast<PLItem*>(index.internalPointer())->i_id;
419 QVariant PLModel::headerData( int section, Qt::Orientation orientation,
423 int running_index=-1;
424 if (orientation != Qt::Horizontal || role != Qt::DisplayRole)
427 if( i_depth == DEPTH_SEL ) return QVariant( QString("") );
429 while( metadata < COLUMN_END )
431 if( metadata & i_showflags )
433 if( running_index == section )
438 if( running_index != section ) return QVariant();
440 return QVariant( qfu( psz_column_title( metadata ) ) );
443 QModelIndex PLModel::index( int row, int column, const QModelIndex &parent )
447 if( !parent.isValid() )
448 parentItem = rootItem;
450 parentItem = static_cast<PLItem*>(parent.internalPointer());
452 PLItem *childItem = parentItem->child( row );
454 return createIndex( row, column, childItem );
456 return QModelIndex();
459 /* Return the index of a given item */
460 QModelIndex PLModel::index( PLItem *item, int column ) const
462 if( !item ) return QModelIndex();
463 const PLItem *parent = item->parent();
465 return createIndex( parent->children.lastIndexOf( item ),
467 return QModelIndex();
470 QModelIndex PLModel::parent( const QModelIndex &index ) const
472 if( !index.isValid() ) return QModelIndex();
474 PLItem *childItem = static_cast<PLItem*>(index.internalPointer());
477 msg_Err( p_playlist, "NULL CHILD" );
478 return QModelIndex();
481 PLItem *parentItem = childItem->parent();
482 if( !parentItem || parentItem == rootItem ) return QModelIndex();
483 if( !parentItem->parentItem )
485 msg_Err( p_playlist, "No parent parent, trying row 0 " );
486 msg_Err( p_playlist, "----- PLEASE REPORT THIS ------" );
487 return createIndex( 0, 0, parentItem );
489 QModelIndex ind = createIndex(parentItem->row(), 0, parentItem);
493 int PLModel::columnCount( const QModelIndex &i) const
497 if( i_depth == DEPTH_SEL ) return 1;
499 while( metadata < COLUMN_END )
501 if( metadata & i_showflags )
508 int PLModel::childrenCount( const QModelIndex &parent ) const
510 return rowCount( parent );
513 int PLModel::rowCount( const QModelIndex &parent ) const
517 if( !parent.isValid() )
518 parentItem = rootItem;
520 parentItem = static_cast<PLItem*>(parent.internalPointer());
522 return parentItem->childCount();
525 QStringList PLModel::selectedURIs()
528 for( int i = 0; i < current_selection.size(); i++ )
531 PLItem *item = static_cast<PLItem*>
532 (current_selection[i].internalPointer());
535 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id );
538 char *psz = input_item_GetURI( p_item->p_input );
551 /************************* General playlist status ***********************/
553 bool PLModel::hasRandom()
555 return var_GetBool( p_playlist, "random" );
557 bool PLModel::hasRepeat()
559 return var_GetBool( p_playlist, "repeat" );
561 bool PLModel::hasLoop()
563 return var_GetBool( p_playlist, "loop" );
565 void PLModel::setLoop( bool on )
567 var_SetBool( p_playlist, "loop", on ? true:false );
568 config_PutInt( p_playlist, "loop", on ? 1: 0 );
570 void PLModel::setRepeat( bool on )
572 var_SetBool( p_playlist, "repeat", on ? true:false );
573 config_PutInt( p_playlist, "repeat", on ? 1: 0 );
575 void PLModel::setRandom( bool on )
577 var_SetBool( p_playlist, "random", on ? true:false );
578 config_PutInt( p_playlist, "random", on ? 1: 0 );
581 /************************* Lookups *****************************/
583 PLItem *PLModel::FindById( PLItem *root, int i_id )
585 return FindInner( root, i_id, false );
588 PLItem *PLModel::FindByInput( PLItem *root, int i_id )
590 PLItem *result = FindInner( root, i_id, true );
594 #define CACHE( i, p ) { i_cached_id = i; p_cached_item = p; }
595 #define ICACHE( i, p ) { i_cached_input_id = i; p_cached_item_bi = p; }
597 PLItem * PLModel::FindInner( PLItem *root, int i_id, bool b_input )
599 if( ( !b_input && i_cached_id == i_id) ||
600 ( b_input && i_cached_input_id ==i_id ) )
602 return b_input ? p_cached_item_bi : p_cached_item;
605 if( !b_input && root->i_id == i_id )
610 else if( b_input && root->p_input->i_id == i_id )
612 ICACHE( i_id, root );
616 QList<PLItem *>::iterator it = root->children.begin();
617 while ( it != root->children.end() )
619 if( !b_input && (*it)->i_id == i_id )
621 CACHE( i_id, (*it) );
622 return p_cached_item;
624 else if( b_input && (*it)->p_input->i_id == i_id )
626 ICACHE( i_id, (*it) );
627 return p_cached_item_bi;
629 if( (*it)->children.size() )
631 PLItem *childFound = FindInner( (*it), i_id, b_input );
635 ICACHE( i_id, childFound )
637 CACHE( i_id, childFound )
649 /************************* Updates handling *****************************/
650 void PLModel::customEvent( QEvent *event )
652 int type = event->type();
653 if( type != ItemAppend_Type &&
654 type != ItemDelete_Type && type != PLUpdate_Type )
657 PLEvent *ple = static_cast<PLEvent *>(event);
659 if( type == ItemAppend_Type )
660 ProcessItemAppend( &ple->add );
661 else if( type == ItemDelete_Type )
662 ProcessItemRemoval( ple->i_id );
667 /**** Events processing ****/
668 void PLModel::ProcessInputItemUpdate( input_thread_t *p_input )
670 if( !p_input ) return;
671 ProcessInputItemUpdate( input_GetItem( p_input ) );
672 if( p_input && !( p_input->b_dead || !vlc_object_alive( p_input ) ) )
674 PLItem *item = FindByInput( rootItem, input_GetItem( p_input )->i_id );
676 emit currentChanged( index( item, 0 ) );
683 void PLModel::ProcessInputItemUpdate( input_item_t *p_item )
685 if( !p_item || p_item->i_id <= 0 ) return;
686 PLItem *item = FindByInput( rootItem, p_item->i_id );
690 UpdateTreeItem( item, true );
695 void PLModel::ProcessItemRemoval( int i_id )
697 if( i_id <= 0 ) return;
698 if( i_id == i_cached_id ) i_cached_id = -1;
699 i_cached_input_id = -1;
704 void PLModel::ProcessItemAppend( const playlist_add_t *p_add )
706 playlist_item_t *p_item = NULL;
707 PLItem *newItem = NULL;
709 PLItem *nodeItem = FindById( rootItem, p_add->i_node );
711 if( !nodeItem ) goto end;
713 p_item = playlist_ItemGetById( p_playlist, p_add->i_item );
714 if( !p_item || p_item->i_flags & PLAYLIST_DBL_FLAG ) goto end;
715 if( i_depth == DEPTH_SEL && p_item->p_parent &&
716 p_item->p_parent->i_id != rootItem->i_id )
719 newItem = new PLItem( p_item, nodeItem );
720 emit layoutAboutToBeChanged();
721 emit beginInsertRows( index( newItem, 0 ), nodeItem->childCount(), nodeItem->childCount()+1 );
722 nodeItem->appendChild( newItem );
723 emit endInsertRows();
724 emit layoutChanged();
725 UpdateTreeItem( p_item, newItem, true );
732 void PLModel::rebuild()
737 void PLModel::rebuild( playlist_item_t *p_root )
739 playlist_item_t* p_item;
740 /* Remove callbacks before locking to avoid deadlocks */
742 /* Invalidate cache */
743 i_cached_id = i_cached_input_id = -1;
745 emit layoutAboutToBeChanged();
751 if( rootItem->children.size() )
753 emit beginRemoveRows( index( rootItem, 0 ), 0,
754 rootItem->children.size() -1 );
755 qDeleteAll( rootItem->children );
756 rootItem->children.clear();
757 emit endRemoveRows();
763 rootItem = new PLItem( p_root );
766 /* Recreate from root */
767 UpdateNodeChildren( rootItem );
768 if( (p_item = playlist_CurrentPlayingItem(p_playlist)) )
770 currentItem = FindByInput( rootItem,
771 p_item->p_input->i_id );
774 UpdateTreeItem( p_item, currentItem,
784 /* And signal the view */
785 emit layoutChanged();
789 /* This function must be entered WITH the playlist lock */
790 void PLModel::UpdateNodeChildren( PLItem *root )
792 emit layoutAboutToBeChanged();
793 playlist_item_t *p_node = playlist_ItemGetById( p_playlist, root->i_id );
794 UpdateNodeChildren( p_node, root );
795 emit layoutChanged();
798 /* This function must be entered WITH the playlist lock */
799 void PLModel::UpdateNodeChildren( playlist_item_t *p_node, PLItem *root )
801 for( int i = 0; i < p_node->i_children ; i++ )
803 if( p_node->pp_children[i]->i_flags & PLAYLIST_DBL_FLAG ) continue;
804 PLItem *newItem = new PLItem( p_node->pp_children[i], root );
805 emit beginInsertRows( index( newItem, 0 ), root->childCount(), root->childCount()+1 );
806 root->appendChild( newItem );
807 emit endInsertRows();
808 UpdateTreeItem( newItem, true, true );
809 if( i_depth == DEPTH_PL && 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 );
818 UpdateTreeItem( p_item, item, signal, force );
821 /* This function must be entered WITH the playlist lock */
822 void PLModel::UpdateTreeItem( playlist_item_t *p_item, PLItem *item,
823 bool signal, bool force )
827 if( !force && i_depth == DEPTH_SEL && p_item->p_parent &&
828 p_item->p_parent->i_id != rootItem->i_id )
830 item->update( p_item );
832 emit dataChanged( index( item, 0 ) , index( item, columnCount( QModelIndex() ) ) );
835 /************************* Actions ******************************/
838 * Deletion, here we have to do a ugly slow hack as we retrieve the full
839 * list of indexes to delete at once: when we delete a node and all of
840 * its children, we need to update the list.
841 * Todo: investigate whethere we can use ranges to be sure to delete all items?
843 void PLModel::doDelete( QModelIndexList selected )
845 for( int i = selected.size() -1 ; i >= 0; i-- )
847 QModelIndex index = selected[i];
848 if( index.column() != 0 ) continue;
849 PLItem *item = static_cast<PLItem*>(index.internalPointer());
852 if( item->children.size() )
853 recurseDelete( item->children, &selected );
854 doDeleteItem( item, &selected );
856 if( i > selected.size() ) i = selected.size();
860 void PLModel::recurseDelete( QList<PLItem*> children, QModelIndexList *fullList )
862 for( int i = children.size() - 1; i >= 0 ; i-- )
864 PLItem *item = children[i];
865 if( item->children.size() )
866 recurseDelete( item->children, fullList );
867 doDeleteItem( item, fullList );
871 void PLModel::doDeleteItem( PLItem *item, QModelIndexList *fullList )
873 QModelIndex deleteIndex = index( item, 0 );
874 fullList->removeAll( deleteIndex );
877 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id );
883 if( p_item->i_children == -1 )
884 playlist_DeleteFromInput( p_playlist, p_item->p_input, pl_Locked );
886 playlist_NodeDelete( p_playlist, p_item, true, false );
887 /* And finally, remove it from the tree */
888 emit beginRemoveRows( index( item->parentItem, 0), item->parentItem->children.indexOf( item ),
889 item->parentItem->children.indexOf( item )+1 );
890 item->remove( item, i_depth );
891 emit endRemoveRows();
895 /******* Volume III: Sorting and searching ********/
896 void PLModel::sort( int column, Qt::SortOrder order )
902 for( i_column = 1; i_column != COLUMN_END; i_column<<=1 )
904 if( ( shownFlags() & i_column ) )
906 if( column == i_index )
917 playlist_item_t *p_root = playlist_ItemGetById( p_playlist,
919 if( p_root && i_flag )
921 playlist_RecursiveNodeSort( p_playlist, p_root,
922 i_column_sorting( i_flag ),
923 order == Qt::AscendingOrder ?
924 ORDER_NORMAL : ORDER_REVERSE );
931 void PLModel::search( const QString& search_text )
933 /** \todo Fire the search with a small delay ? */
936 playlist_item_t *p_root = playlist_ItemGetById( p_playlist,
939 const char *psz_name = search_text.toUtf8().data();
940 playlist_LiveSearchUpdate( p_playlist , p_root, psz_name );
946 /*********** Popup *********/
947 void PLModel::popup( QModelIndex & index, QPoint &point, QModelIndexList list )
949 assert( index.isValid() );
951 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, itemId( index ) );
954 i_popup_item = p_item->i_id;
955 i_popup_parent = p_item->p_parent ? p_item->p_parent->i_id : -1;
957 current_selection = list;
958 QMenu *menu = new QMenu;
959 menu->addAction( qtr(I_POP_PLAY), this, SLOT( popupPlay() ) );
960 menu->addAction( qtr(I_POP_DEL), this, SLOT( popupDel() ) );
961 menu->addSeparator();
962 menu->addAction( qtr(I_POP_STREAM), this, SLOT( popupStream() ) );
963 menu->addAction( qtr(I_POP_SAVE), this, SLOT( popupSave() ) );
964 menu->addSeparator();
965 menu->addAction( qtr(I_POP_INFO), this, SLOT( popupInfo() ) );
966 if( p_item->i_children > -1 )
968 menu->addSeparator();
969 menu->addAction( qtr(I_POP_SORT), this, SLOT( popupSort() ) );
970 menu->addAction( qtr(I_POP_ADD), this, SLOT( popupAdd() ) );
972 menu->addSeparator();
973 menu->addAction( qtr( I_POP_EXPLORE ), this, SLOT( popupExplore() ) );
974 menu->popup( point );
981 void PLModel::viewchanged( int meta )
994 /* UNUSED emit layoutAboutToBeChanged(); */
995 index = __MIN( index, columnCount() );
996 QModelIndex parent = createIndex( 0, 0, rootItem );
998 if( i_showflags & meta )
999 /* Removing columns */
1001 emit beginRemoveColumns( parent, index, index+1 );
1002 i_showflags &= ~( meta );
1003 getSettings()->setValue( "qt-pl-showflags", i_showflags );
1004 emit endRemoveColumns();
1008 /* Adding columns */
1009 emit beginInsertColumns( parent, index, index+1 );
1010 i_showflags |= meta;
1011 getSettings()->setValue( "qt-pl-showflags", i_showflags );
1012 emit endInsertColumns();
1014 emit columnsChanged( meta );
1019 void PLModel::popupDel()
1021 doDelete( current_selection );
1024 void PLModel::popupPlay()
1028 playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
1030 activateItem( p_item );
1035 void PLModel::popupInfo()
1038 playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
1042 input_item_t* p_input = p_item->p_input;
1043 vlc_gc_incref( p_input );
1045 MediaInfoDialog *mid = new MediaInfoDialog( p_intf, p_input );
1046 vlc_gc_decref( p_input );
1047 mid->setParent( PlaylistDialog::getInstance( p_intf ),
1053 void PLModel::popupStream()
1055 QStringList mrls = selectedURIs();
1056 if( !mrls.isEmpty() )
1057 THEDP->streamingDialog( NULL, mrls[0], false );
1061 void PLModel::popupSave()
1063 QStringList mrls = selectedURIs();
1064 if( !mrls.isEmpty() )
1065 THEDP->streamingDialog( NULL, mrls[0] );
1069 #include <QFileInfo>
1070 #include <QDesktopServices>
1071 void PLModel::popupExplore()
1074 playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
1078 input_item_t *p_input = p_item->p_input;
1079 char *psz_meta = input_item_GetURI( p_input );
1083 const char *psz_access;
1084 const char *psz_demux;
1086 input_SplitMRL( &psz_access, &psz_demux, &psz_path, psz_meta );
1088 if( EMPTY_STR( psz_access ) ||
1089 !strncasecmp( psz_access, "file", 4 ) ||
1090 !strncasecmp( psz_access, "dire", 4 ) )
1092 QFileInfo info( qfu( psz_meta ) );
1093 QDesktopServices::openUrl(
1094 QUrl::fromLocalFile( info.absolutePath() ) );
1103 /**********************************************************************
1104 * Playlist callbacks
1105 **********************************************************************/
1106 static int PlaylistChanged( 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( PLUpdate_Type, 0 );
1111 QApplication::postEvent( p_model, event );
1115 static int PlaylistNext( 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( ItemUpdate_Type, oval.i_int );
1120 QApplication::postEvent( p_model, event );
1121 event = new PLEvent( ItemUpdate_Type, nval.i_int );
1122 QApplication::postEvent( p_model, event );
1126 static int ItemDeleted( vlc_object_t *p_this, const char *psz_variable,
1127 vlc_value_t oval, vlc_value_t nval, void *param )
1129 PLModel *p_model = (PLModel *) param;
1130 PLEvent *event = new PLEvent( ItemDelete_Type, nval.i_int );
1131 QApplication::postEvent( p_model, event );
1135 static int ItemAppended( vlc_object_t *p_this, const char *psz_variable,
1136 vlc_value_t oval, vlc_value_t nval, void *param )
1138 PLModel *p_model = (PLModel *) param;
1139 const playlist_add_t *p_add = (playlist_add_t *)nval.p_address;
1140 PLEvent *event = new PLEvent( p_add );
1141 QApplication::postEvent( p_model, event );