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;
81 rootItem = NULL; /* PLItem rootItem, will be set in rebuild( ) */
83 /* Icons initialization */
84 #define ADD_ICON(type, x) icons[ITEM_TYPE_##type] = QIcon( QPixmap( x ) )
85 ADD_ICON( UNKNOWN , type_unknown_xpm );
86 ADD_ICON( FILE, ":/type/file" );
87 ADD_ICON( DIRECTORY, ":/type/directory" );
88 ADD_ICON( DISC, ":/type/disc" );
89 ADD_ICON( CDDA, ":/type/cdda" );
90 ADD_ICON( CARD, ":/type/capture-card" );
91 ADD_ICON( NET, ":/type/net" );
92 ADD_ICON( PLAYLIST, ":/type/playlist" );
93 ADD_ICON( NODE, ":/type/node" );
97 CONNECT( THEMIM->getIM(), metaChanged( input_item_t *),
98 this, ProcessInputItemUpdate( input_item_t *) );
99 CONNECT( THEMIM, inputChanged( input_thread_t * ),
100 this, ProcessInputItemUpdate( input_thread_t* ) );
106 getSettings()->setValue( "qt-pl-showflags", rootItem->i_showflags );
111 Qt::DropActions PLModel::supportedDropActions() const
113 return Qt::CopyAction; /* Why not Qt::MoveAction */
116 Qt::ItemFlags PLModel::flags( const QModelIndex &index ) const
118 Qt::ItemFlags flags = QAbstractItemModel::flags( index );
120 PLItem *item = index.isValid() ?
121 static_cast<PLItem*>( index.internalPointer() ) :
124 int pl_input_id = p_playlist->p_local_category->p_input->i_id;
125 int ml_input_id = p_playlist->p_ml_category->p_input->i_id;
127 if( rootItem->i_id == p_playlist->p_root_onelevel->i_id
128 || rootItem->i_id == p_playlist->p_root_category->i_id )
130 if( item->i_input_id == pl_input_id
131 || item->i_input_id == ml_input_id )
132 flags |= Qt::ItemIsDropEnabled;
136 if ( item->b_is_node &&
137 ( rootItem->i_input_id == pl_input_id ||
138 rootItem->i_input_id == ml_input_id ) )
139 flags |= Qt::ItemIsDropEnabled;
140 flags |= Qt::ItemIsDragEnabled;
146 /* A list of model indexes are a playlist */
147 QStringList PLModel::mimeTypes() const
150 types << "vlc/playlist-item-id";
154 QMimeData *PLModel::mimeData( const QModelIndexList &indexes ) const
156 QMimeData *mimeData = new QMimeData();
157 QByteArray encodedData;
158 QDataStream stream( &encodedData, QIODevice::WriteOnly );
159 QModelIndexList list;
161 foreach( const QModelIndex &index, indexes ) {
162 if( index.isValid() && index.column() == 0 )
168 foreach( const QModelIndex &index, list ) {
169 stream << itemId( index );
171 mimeData->setData( "vlc/playlist-item-id", encodedData );
176 bool PLModel::dropMimeData( const QMimeData *data, Qt::DropAction action,
177 int row, int column, const QModelIndex &parent )
179 if( data->hasFormat( "vlc/playlist-item-id" ) )
181 if( action == Qt::IgnoreAction )
186 playlist_item_t *p_parent;
188 if( !parent.isValid())
192 // dropped into top node
193 p_parent = playlist_ItemGetById( p_playlist, rootItem->i_id );
197 // dropped outside any item
204 // dropped into/onto an item (depends on (row = -1) or (row > -1))
205 p_parent = playlist_ItemGetById( p_playlist, itemId ( parent ) );
207 if( !p_parent || p_parent->i_children == -1 )
213 QByteArray encodedData = data->data( "vlc/playlist-item-id" );
214 QDataStream stream( &encodedData, QIODevice::ReadOnly );
216 /* easiest way to never miss the right index to move to is to
217 track the previously moved item */
218 playlist_item_t *p_target = NULL;
220 while( !stream.atEnd() )
224 playlist_item_t *p_src = playlist_ItemGetById( p_playlist, src_id );
235 playlist_TreeMove( p_playlist, p_src, p_parent, 0 );
238 playlist_TreeMove( p_playlist, p_src, p_parent, row );
244 for( i = 0 ; i< p_parent->i_children ; i++ )
245 if( p_parent->pp_children[i] == p_target ) break;
246 playlist_TreeMove( p_playlist, p_src, p_parent, i + 1 );
251 /*TODO: That's not a good idea to rebuild the playlist */
257 /* remove item with its id */
258 void PLModel::removeItem( int i_id )
260 PLItem *item = FindById( rootItem, i_id );
261 if( item ) item->remove( item );
264 /* callbacks and slots */
265 void PLModel::addCallbacks()
267 /* Some global changes happened -> Rebuild all */
268 var_AddCallback( p_playlist, "intf-change", PlaylistChanged, this );
269 /* We went to the next item
270 var_AddCallback( p_playlist, "item-current", PlaylistNext, this );
272 /* One item has been updated */
273 var_AddCallback( p_playlist, "playlist-item-append", ItemAppended, this );
274 var_AddCallback( p_playlist, "playlist-item-deleted", ItemDeleted, this );
277 void PLModel::delCallbacks()
280 var_DelCallback( p_playlist, "item-current", PlaylistNext, this );
282 var_DelCallback( p_playlist, "intf-change", PlaylistChanged, this );
283 var_DelCallback( p_playlist, "playlist-item-append", ItemAppended, this );
284 var_DelCallback( p_playlist, "playlist-item-deleted", ItemDeleted, this );
287 void PLModel::activateItem( const QModelIndex &index )
289 assert( index.isValid() );
290 PLItem *item = static_cast<PLItem*>(index.internalPointer());
293 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id );
294 activateItem( p_item );
298 /* Must be entered with lock */
299 void PLModel::activateItem( playlist_item_t *p_item )
301 if( !p_item ) return;
302 playlist_item_t *p_parent = p_item;
305 if( p_parent->i_id == rootItem->i_id ) break;
306 p_parent = p_parent->p_parent;
309 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, pl_Locked,
313 /****************** Base model mandatory implementations *****************/
314 QVariant PLModel::data( const QModelIndex &index, int role ) const
316 if( !index.isValid() ) return QVariant();
317 PLItem *item = static_cast<PLItem*>(index.internalPointer());
318 if( role == Qt::DisplayRole )
320 int running_index = -1;
324 if( item->model->i_depth == DEPTH_SEL )
326 vlc_mutex_lock( &item->p_input->lock );
327 QString returninfo = QString( qfu( item->p_input->psz_name ) );
328 vlc_mutex_unlock( &item->p_input->lock );
329 return QVariant(returninfo);
332 while( metadata < COLUMN_END )
334 if( item->i_showflags & metadata )
336 if( running_index == index.column() )
341 if( running_index != index.column() ) return QVariant();
344 if( metadata == COLUMN_NUMBER )
345 returninfo = QString::number( index.row() + 1 );
348 char *psz = psz_column_meta( item->p_input, metadata );
349 returninfo = QString( qfu( psz ) );
352 return QVariant( returninfo );
354 else if( role == Qt::DecorationRole && index.column() == 0 )
356 /* Use to segfault here because i_type wasn't always initialized */
357 if( item->i_type >= 0 )
358 return QVariant( PLModel::icons[item->i_type] );
360 else if( role == Qt::FontRole )
362 if( item->b_current == true )
364 QFont f; f.setBold( true ); return QVariant( f );
370 bool PLModel::isCurrent( const QModelIndex &index )
372 assert( index.isValid() );
373 return static_cast<PLItem*>(index.internalPointer())->b_current;
376 int PLModel::itemId( const QModelIndex &index ) const
378 assert( index.isValid() );
379 return static_cast<PLItem*>(index.internalPointer())->i_id;
382 QVariant PLModel::headerData( int section, Qt::Orientation orientation,
386 int running_index=-1;
387 if (orientation != Qt::Horizontal || role != Qt::DisplayRole)
390 if( i_depth == DEPTH_SEL ) return QVariant( QString("") );
392 while( metadata < COLUMN_END )
394 if( metadata & rootItem->i_showflags )
396 if( running_index == section )
401 if( running_index != section ) return QVariant();
403 return QVariant( qfu( psz_column_title( metadata ) ) );
406 QModelIndex PLModel::index( int row, int column, const QModelIndex &parent )
410 if( !parent.isValid() )
411 parentItem = rootItem;
413 parentItem = static_cast<PLItem*>(parent.internalPointer());
415 PLItem *childItem = parentItem->child( row );
417 return createIndex( row, column, childItem );
419 return QModelIndex();
422 /* Return the index of a given item */
423 QModelIndex PLModel::index( PLItem *item, int column ) const
425 if( !item ) return QModelIndex();
426 const PLItem *parent = item->parent();
428 return createIndex( parent->children.lastIndexOf( item ),
430 return QModelIndex();
433 QModelIndex PLModel::parent( const QModelIndex &index ) const
435 if( !index.isValid() ) return QModelIndex();
437 PLItem *childItem = static_cast<PLItem*>(index.internalPointer());
440 msg_Err( p_playlist, "NULL CHILD" );
441 return QModelIndex();
444 PLItem *parentItem = childItem->parent();
445 if( !parentItem || parentItem == rootItem ) return QModelIndex();
446 if( !parentItem->parentItem )
448 msg_Err( p_playlist, "No parent parent, trying row 0 " );
449 msg_Err( p_playlist, "----- PLEASE REPORT THIS ------" );
450 return createIndex( 0, 0, parentItem );
452 QModelIndex ind = createIndex(parentItem->row(), 0, parentItem);
456 int PLModel::columnCount( const QModelIndex &i) const
460 if( i_depth == DEPTH_SEL ) return 1;
462 while( metadata < COLUMN_END )
464 if( metadata & rootItem->i_showflags )
471 int PLModel::childrenCount( const QModelIndex &parent ) const
473 return rowCount( parent );
476 int PLModel::rowCount( const QModelIndex &parent ) const
480 if( !parent.isValid() )
481 parentItem = rootItem;
483 parentItem = static_cast<PLItem*>(parent.internalPointer());
485 return parentItem->childCount();
488 QStringList PLModel::selectedURIs()
491 for( int i = 0; i < current_selection.size(); i++ )
494 PLItem *item = static_cast<PLItem*>
495 (current_selection[i].internalPointer());
498 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id );
501 char *psz = input_item_GetURI( p_item->p_input );
514 /************************* General playlist status ***********************/
516 bool PLModel::hasRandom()
518 return var_GetBool( p_playlist, "random" );
520 bool PLModel::hasRepeat()
522 return var_GetBool( p_playlist, "repeat" );
524 bool PLModel::hasLoop()
526 return var_GetBool( p_playlist, "loop" );
528 void PLModel::setLoop( bool on )
530 var_SetBool( p_playlist, "loop", on ? true:false );
531 config_PutInt( p_playlist, "loop", on ? 1: 0 );
533 void PLModel::setRepeat( bool on )
535 var_SetBool( p_playlist, "repeat", on ? true:false );
536 config_PutInt( p_playlist, "repeat", on ? 1: 0 );
538 void PLModel::setRandom( bool on )
540 var_SetBool( p_playlist, "random", on ? true:false );
541 config_PutInt( p_playlist, "random", on ? 1: 0 );
544 /************************* Lookups *****************************/
546 PLItem *PLModel::FindById( PLItem *root, int i_id )
548 return FindInner( root, i_id, false );
551 PLItem *PLModel::FindByInput( PLItem *root, int i_id )
553 return FindInner( root, i_id, true );
556 #define CACHE( i, p ) { i_cached_id = i; p_cached_item = p; }
557 #define ICACHE( i, p ) { i_cached_input_id = i; p_cached_item_bi = p; }
559 PLItem * PLModel::FindInner( PLItem *root, int i_id, bool b_input )
561 if( ( !b_input && i_cached_id == i_id) ||
562 ( b_input && i_cached_input_id ==i_id ) )
564 return b_input ? p_cached_item_bi : p_cached_item;
567 if( !b_input && root->i_id == i_id )
572 else if( b_input && root->i_input_id == i_id )
574 ICACHE( i_id, root );
578 QList<PLItem *>::iterator it = root->children.begin();
579 while ( it != root->children.end() )
581 if( !b_input && (*it)->i_id == i_id )
583 CACHE( i_id, (*it) );
584 return p_cached_item;
586 else if( b_input && (*it)->i_input_id == i_id )
588 ICACHE( i_id, (*it) );
589 return p_cached_item_bi;
591 if( (*it)->children.size() )
593 PLItem *childFound = FindInner( (*it), i_id, b_input );
597 ICACHE( i_id, childFound )
599 CACHE( i_id, childFound )
611 /************************* Updates handling *****************************/
612 void PLModel::customEvent( QEvent *event )
614 int type = event->type();
615 if( type != ItemAppend_Type &&
616 type != ItemDelete_Type && type != PLUpdate_Type )
619 PLEvent *ple = static_cast<PLEvent *>(event);
621 if( type == ItemAppend_Type )
622 ProcessItemAppend( &ple->add );
623 else if( type == ItemDelete_Type )
624 ProcessItemRemoval( ple->i_id );
629 /**** Events processing ****/
630 void PLModel::ProcessInputItemUpdate( input_thread_t *p_input )
632 if( !p_input ) return;
633 ProcessInputItemUpdate( input_GetItem( p_input ) );
634 if( p_input && !( p_input->b_dead || !vlc_object_alive( p_input ) ) )
636 PLItem *item = FindByInput( rootItem, input_GetItem( p_input )->i_id );
637 emit currentChanged( index( item, 0 ) );
640 void PLModel::ProcessInputItemUpdate( input_item_t *p_item )
642 if( !p_item || p_item->i_id <= 0 ) return;
643 PLItem *item = FindByInput( rootItem, p_item->i_id );
647 UpdateTreeItem( item, true );
652 void PLModel::ProcessItemRemoval( int i_id )
654 if( i_id <= 0 ) return;
655 if( i_id == i_cached_id ) i_cached_id = -1;
656 i_cached_input_id = -1;
661 void PLModel::ProcessItemAppend( const playlist_add_t *p_add )
663 playlist_item_t *p_item = NULL;
664 PLItem *newItem = NULL;
666 PLItem *nodeItem = FindById( rootItem, p_add->i_node );
668 if( !nodeItem ) goto end;
670 p_item = playlist_ItemGetById( p_playlist, p_add->i_item );
671 if( !p_item || p_item->i_flags & PLAYLIST_DBL_FLAG ) goto end;
672 if( i_depth == DEPTH_SEL && p_item->p_parent &&
673 p_item->p_parent->i_id != rootItem->i_id )
676 newItem = new PLItem( p_item, nodeItem, this );
677 nodeItem->appendChild( newItem );
678 UpdateTreeItem( p_item, newItem, true );
685 void PLModel::rebuild()
690 void PLModel::rebuild( playlist_item_t *p_root )
692 playlist_item_t* p_item;
693 /* Remove callbacks before locking to avoid deadlocks */
695 /* Invalidate cache */
696 i_cached_id = i_cached_input_id = -1;
702 if( rootItem->children.size() )
704 beginRemoveRows( index( rootItem, 0 ), 0,
705 rootItem->children.size() -1 );
706 qDeleteAll( rootItem->children );
707 rootItem->children.clear();
714 rootItem = new PLItem( p_root, getSettings(), this );
717 /* Recreate from root */
718 UpdateNodeChildren( rootItem );
719 if( (p_item = playlist_CurrentPlayingItem(p_playlist)) )
721 PLItem *currentItem = FindByInput( rootItem,
722 p_item->p_input->i_id );
725 UpdateTreeItem( p_item, currentItem,
731 /* And signal the view */
732 emit layoutChanged();
736 /* This function must be entered WITH the playlist lock */
737 void PLModel::UpdateNodeChildren( PLItem *root )
739 playlist_item_t *p_node = playlist_ItemGetById( p_playlist, root->i_id );
740 UpdateNodeChildren( p_node, root );
743 /* This function must be entered WITH the playlist lock */
744 void PLModel::UpdateNodeChildren( playlist_item_t *p_node, PLItem *root )
746 for( int i = 0; i < p_node->i_children ; i++ )
748 if( p_node->pp_children[i]->i_flags & PLAYLIST_DBL_FLAG ) continue;
749 PLItem *newItem = new PLItem( p_node->pp_children[i], root, this );
750 root->appendChild( newItem, false );
751 UpdateTreeItem( newItem, false, true );
752 if( i_depth == DEPTH_PL && p_node->pp_children[i]->i_children != -1 )
753 UpdateNodeChildren( p_node->pp_children[i], newItem );
757 /* This function must be entered WITH the playlist lock */
758 void PLModel::UpdateTreeItem( PLItem *item, bool signal, bool force )
760 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id );
761 UpdateTreeItem( p_item, item, signal, force );
764 /* This function must be entered WITH the playlist lock */
765 void PLModel::UpdateTreeItem( playlist_item_t *p_item, PLItem *item,
766 bool signal, bool force )
770 if( !force && i_depth == DEPTH_SEL && p_item->p_parent &&
771 p_item->p_parent->i_id != rootItem->i_id )
773 item->update( p_item, p_item == playlist_CurrentPlayingItem( p_playlist ) );
775 emit dataChanged( index( item, 0 ) , index( item, 1 ) );
778 /************************* Actions ******************************/
781 * Deletion, here we have to do a ugly slow hack as we retrieve the full
782 * list of indexes to delete at once: when we delete a node and all of
783 * its children, we need to update the list.
784 * Todo: investigate whethere we can use ranges to be sure to delete all items?
786 void PLModel::doDelete( QModelIndexList selected )
788 for( int i = selected.size() -1 ; i >= 0; i-- )
790 QModelIndex index = selected[i];
791 if( index.column() != 0 ) continue;
792 PLItem *item = static_cast<PLItem*>(index.internalPointer());
795 if( item->children.size() )
796 recurseDelete( item->children, &selected );
797 doDeleteItem( item, &selected );
799 if( i > selected.size() ) i = selected.size();
803 void PLModel::recurseDelete( QList<PLItem*> children, QModelIndexList *fullList )
805 for( int i = children.size() - 1; i >= 0 ; i-- )
807 PLItem *item = children[i];
808 if( item->children.size() )
809 recurseDelete( item->children, fullList );
810 doDeleteItem( item, fullList );
814 void PLModel::doDeleteItem( PLItem *item, QModelIndexList *fullList )
816 QModelIndex deleteIndex = index( item, 0 );
817 fullList->removeAll( deleteIndex );
820 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id );
826 if( p_item->i_children == -1 )
827 playlist_DeleteFromInput( p_playlist, p_item->p_input, pl_Locked );
829 playlist_NodeDelete( p_playlist, p_item, true, false );
830 /* And finally, remove it from the tree */
831 item->remove( item );
835 /******* Volume III: Sorting and searching ********/
836 void PLModel::sort( int column, Qt::SortOrder order )
842 for( i_column = 1; i_column != COLUMN_END; i_column<<=1 )
844 if( ( shownFlags() & i_column ) )
846 if( column == i_index )
857 playlist_item_t *p_root = playlist_ItemGetById( p_playlist,
859 if( p_root && i_flag )
861 playlist_RecursiveNodeSort( p_playlist, p_root,
862 i_column_sorting( i_flag ),
863 order == Qt::AscendingOrder ?
864 ORDER_NORMAL : ORDER_REVERSE );
871 void PLModel::search( const QString& search_text )
873 /** \todo Fire the search with a small delay ? */
876 playlist_item_t *p_root = playlist_ItemGetById( p_playlist,
879 const char *psz_name = search_text.toUtf8().data();
880 playlist_LiveSearchUpdate( p_playlist , p_root, psz_name );
886 /*********** Popup *********/
887 void PLModel::popup( QModelIndex & index, QPoint &point, QModelIndexList list )
889 assert( index.isValid() );
891 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, itemId( index ) );
894 i_popup_item = p_item->i_id;
895 i_popup_parent = p_item->p_parent ? p_item->p_parent->i_id : -1;
897 current_selection = list;
898 QMenu *menu = new QMenu;
899 menu->addAction( qtr(I_POP_PLAY), this, SLOT( popupPlay() ) );
900 menu->addAction( qtr(I_POP_DEL), this, SLOT( popupDel() ) );
901 menu->addSeparator();
902 menu->addAction( qtr(I_POP_STREAM), this, SLOT( popupStream() ) );
903 menu->addAction( qtr(I_POP_SAVE), this, SLOT( popupSave() ) );
904 menu->addSeparator();
905 menu->addAction( qtr(I_POP_INFO), this, SLOT( popupInfo() ) );
906 if( p_item->i_children > -1 )
908 menu->addSeparator();
909 menu->addAction( qtr(I_POP_SORT), this, SLOT( popupSort() ) );
910 menu->addAction( qtr(I_POP_ADD), this, SLOT( popupAdd() ) );
912 menu->addSeparator();
913 menu->addAction( qtr( I_POP_EXPLORE ), this, SLOT( popupExplore() ) );
914 menu->popup( point );
921 void PLModel::viewchanged( int meta )
934 /* UNUSED emit layoutAboutToBeChanged(); */
935 index = __MIN( index, columnCount() );
936 QModelIndex parent = createIndex( 0, 0, rootItem );
938 if( rootItem->i_showflags & meta )
939 /* Removing columns */
941 beginRemoveColumns( parent, index, index+1 );
942 rootItem->i_showflags &= ~( meta );
943 getSettings()->setValue( "qt-pl-showflags", rootItem->i_showflags );
949 beginInsertColumns( parent, index, index+1 );
950 rootItem->i_showflags |= meta;
951 getSettings()->setValue( "qt-pl-showflags", rootItem->i_showflags );
954 emit columnsChanged( meta );
959 void PLModel::popupDel()
961 doDelete( current_selection );
964 void PLModel::popupPlay()
968 playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
970 activateItem( p_item );
975 void PLModel::popupInfo()
978 playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
982 input_item_t* p_input = p_item->p_input;
983 vlc_gc_incref( p_input );
985 MediaInfoDialog *mid = new MediaInfoDialog( p_intf, p_input );
986 vlc_gc_decref( p_input );
987 mid->setParent( PlaylistDialog::getInstance( p_intf ),
993 void PLModel::popupStream()
995 QStringList mrls = selectedURIs();
996 if( !mrls.isEmpty() )
997 THEDP->streamingDialog( NULL, mrls[0], false );
1001 void PLModel::popupSave()
1003 QStringList mrls = selectedURIs();
1004 if( !mrls.isEmpty() )
1005 THEDP->streamingDialog( NULL, mrls[0] );
1009 #include <QFileInfo>
1010 #include <QDesktopServices>
1011 void PLModel::popupExplore()
1014 playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
1018 input_item_t *p_input = p_item->p_input;
1019 char *psz_meta = input_item_GetURI( p_input );
1023 const char *psz_access;
1024 const char *psz_demux;
1026 input_SplitMRL( &psz_access, &psz_demux, &psz_path, psz_meta );
1028 if( EMPTY_STR( psz_access ) ||
1029 !strncasecmp( psz_access, "file", 4 ) ||
1030 !strncasecmp( psz_access, "dire", 4 ) )
1032 QFileInfo info( qfu( psz_meta ) );
1033 QDesktopServices::openUrl(
1034 QUrl::fromLocalFile( info.absolutePath() ) );
1043 /**********************************************************************
1044 * Playlist callbacks
1045 **********************************************************************/
1046 static int PlaylistChanged( vlc_object_t *p_this, const char *psz_variable,
1047 vlc_value_t oval, vlc_value_t nval, void *param )
1049 PLModel *p_model = (PLModel *) param;
1050 PLEvent *event = new PLEvent( PLUpdate_Type, 0 );
1051 QApplication::postEvent( p_model, event );
1055 static int PlaylistNext( vlc_object_t *p_this, const char *psz_variable,
1056 vlc_value_t oval, vlc_value_t nval, void *param )
1058 PLModel *p_model = (PLModel *) param;
1059 PLEvent *event = new PLEvent( ItemUpdate_Type, oval.i_int );
1060 QApplication::postEvent( p_model, event );
1061 event = new PLEvent( ItemUpdate_Type, nval.i_int );
1062 QApplication::postEvent( p_model, event );
1066 static int ItemDeleted( vlc_object_t *p_this, const char *psz_variable,
1067 vlc_value_t oval, vlc_value_t nval, void *param )
1069 PLModel *p_model = (PLModel *) param;
1070 PLEvent *event = new PLEvent( ItemDelete_Type, nval.i_int );
1071 QApplication::postEvent( p_model, event );
1075 static int ItemAppended( vlc_object_t *p_this, const char *psz_variable,
1076 vlc_value_t oval, vlc_value_t nval, void *param )
1078 PLModel *p_model = (PLModel *) param;
1079 const playlist_add_t *p_add = (playlist_add_t *)nval.p_address;
1080 PLEvent *event = new PLEvent( p_add );
1081 QApplication::postEvent( p_model, event );