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 )
325 return QVariant( QString( qfu( item->p_input->psz_name ) ) );
327 while( metadata < COLUMN_END )
329 if( item->i_showflags & metadata )
331 if( running_index == index.column() )
336 if( running_index != index.column() ) return QVariant();
339 if( metadata == COLUMN_NUMBER )
340 returninfo = QString::number( index.row() + 1 );
343 char *psz = psz_column_meta( item->p_input, metadata );
344 returninfo = QString( qfu( psz ) );
347 return QVariant( returninfo );
349 else if( role == Qt::DecorationRole && index.column() == 0 )
351 /* Use to segfault here because i_type wasn't always initialized */
352 if( item->i_type >= 0 )
353 return QVariant( PLModel::icons[item->i_type] );
355 else if( role == Qt::FontRole )
357 if( item->b_current == true )
359 QFont f; f.setBold( true ); return QVariant( f );
365 bool PLModel::isCurrent( const QModelIndex &index )
367 assert( index.isValid() );
368 return static_cast<PLItem*>(index.internalPointer())->b_current;
371 int PLModel::itemId( const QModelIndex &index ) const
373 assert( index.isValid() );
374 return static_cast<PLItem*>(index.internalPointer())->i_id;
377 QVariant PLModel::headerData( int section, Qt::Orientation orientation,
381 int running_index=-1;
382 if (orientation != Qt::Horizontal || role != Qt::DisplayRole)
385 if( i_depth == DEPTH_SEL ) return QVariant( QString("") );
387 while( metadata < COLUMN_END )
389 if( metadata & rootItem->i_showflags )
391 if( running_index == section )
396 if( running_index != section ) return QVariant();
398 return QVariant( qfu( psz_column_title( metadata ) ) );
401 QModelIndex PLModel::index( int row, int column, const QModelIndex &parent )
405 if( !parent.isValid() )
406 parentItem = rootItem;
408 parentItem = static_cast<PLItem*>(parent.internalPointer());
410 PLItem *childItem = parentItem->child( row );
412 return createIndex( row, column, childItem );
414 return QModelIndex();
417 /* Return the index of a given item */
418 QModelIndex PLModel::index( PLItem *item, int column ) const
420 if( !item ) return QModelIndex();
421 const PLItem *parent = item->parent();
423 return createIndex( parent->children.lastIndexOf( item ),
425 return QModelIndex();
428 QModelIndex PLModel::parent( const QModelIndex &index ) const
430 if( !index.isValid() ) return QModelIndex();
432 PLItem *childItem = static_cast<PLItem*>(index.internalPointer());
435 msg_Err( p_playlist, "NULL CHILD" );
436 return QModelIndex();
439 PLItem *parentItem = childItem->parent();
440 if( !parentItem || parentItem == rootItem ) return QModelIndex();
441 if( !parentItem->parentItem )
443 msg_Err( p_playlist, "No parent parent, trying row 0 " );
444 msg_Err( p_playlist, "----- PLEASE REPORT THIS ------" );
445 return createIndex( 0, 0, parentItem );
447 QModelIndex ind = createIndex(parentItem->row(), 0, parentItem);
451 int PLModel::columnCount( const QModelIndex &i) const
455 if( i_depth == DEPTH_SEL ) return 1;
457 while( metadata < COLUMN_END )
459 if( metadata & rootItem->i_showflags )
466 int PLModel::childrenCount( const QModelIndex &parent ) const
468 return rowCount( parent );
471 int PLModel::rowCount( const QModelIndex &parent ) const
475 if( !parent.isValid() )
476 parentItem = rootItem;
478 parentItem = static_cast<PLItem*>(parent.internalPointer());
480 return parentItem->childCount();
483 QStringList PLModel::selectedURIs()
486 for( int i = 0; i < current_selection.size(); i++ )
489 PLItem *item = static_cast<PLItem*>
490 (current_selection[i].internalPointer());
493 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id );
496 char *psz = input_item_GetURI( p_item->p_input );
509 /************************* General playlist status ***********************/
511 bool PLModel::hasRandom()
513 return var_GetBool( p_playlist, "random" );
515 bool PLModel::hasRepeat()
517 return var_GetBool( p_playlist, "repeat" );
519 bool PLModel::hasLoop()
521 return var_GetBool( p_playlist, "loop" );
523 void PLModel::setLoop( bool on )
525 var_SetBool( p_playlist, "loop", on ? true:false );
526 config_PutInt( p_playlist, "loop", on ? 1: 0 );
528 void PLModel::setRepeat( bool on )
530 var_SetBool( p_playlist, "repeat", on ? true:false );
531 config_PutInt( p_playlist, "repeat", on ? 1: 0 );
533 void PLModel::setRandom( bool on )
535 var_SetBool( p_playlist, "random", on ? true:false );
536 config_PutInt( p_playlist, "random", on ? 1: 0 );
539 /************************* Lookups *****************************/
541 PLItem *PLModel::FindById( PLItem *root, int i_id )
543 return FindInner( root, i_id, false );
546 PLItem *PLModel::FindByInput( PLItem *root, int i_id )
548 return FindInner( root, i_id, true );
551 #define CACHE( i, p ) { i_cached_id = i; p_cached_item = p; }
552 #define ICACHE( i, p ) { i_cached_input_id = i; p_cached_item_bi = p; }
554 PLItem * PLModel::FindInner( PLItem *root, int i_id, bool b_input )
556 if( ( !b_input && i_cached_id == i_id) ||
557 ( b_input && i_cached_input_id ==i_id ) )
559 return b_input ? p_cached_item_bi : p_cached_item;
562 if( !b_input && root->i_id == i_id )
567 else if( b_input && root->i_input_id == i_id )
569 ICACHE( i_id, root );
573 QList<PLItem *>::iterator it = root->children.begin();
574 while ( it != root->children.end() )
576 if( !b_input && (*it)->i_id == i_id )
578 CACHE( i_id, (*it) );
579 return p_cached_item;
581 else if( b_input && (*it)->i_input_id == i_id )
583 ICACHE( i_id, (*it) );
584 return p_cached_item_bi;
586 if( (*it)->children.size() )
588 PLItem *childFound = FindInner( (*it), i_id, b_input );
592 ICACHE( i_id, childFound )
594 CACHE( i_id, childFound )
606 /************************* Updates handling *****************************/
607 void PLModel::customEvent( QEvent *event )
609 int type = event->type();
610 if( type != ItemAppend_Type &&
611 type != ItemDelete_Type && type != PLUpdate_Type )
614 PLEvent *ple = static_cast<PLEvent *>(event);
616 if( type == ItemAppend_Type )
617 ProcessItemAppend( &ple->add );
618 else if( type == ItemDelete_Type )
619 ProcessItemRemoval( ple->i_id );
624 /**** Events processing ****/
625 void PLModel::ProcessInputItemUpdate( input_thread_t *p_input )
627 if( !p_input ) return;
628 ProcessInputItemUpdate( input_GetItem( p_input ) );
629 if( p_input && !( p_input->b_dead || !vlc_object_alive( p_input ) ) )
631 PLItem *item = FindByInput( rootItem, input_GetItem( p_input )->i_id );
632 emit currentChanged( index( item, 0 ) );
635 void PLModel::ProcessInputItemUpdate( input_item_t *p_item )
637 if( !p_item || p_item->i_id <= 0 ) return;
638 PLItem *item = FindByInput( rootItem, p_item->i_id );
642 UpdateTreeItem( item, true );
647 void PLModel::ProcessItemRemoval( int i_id )
649 if( i_id <= 0 ) return;
650 if( i_id == i_cached_id ) i_cached_id = -1;
651 i_cached_input_id = -1;
656 void PLModel::ProcessItemAppend( const playlist_add_t *p_add )
658 playlist_item_t *p_item = NULL;
659 PLItem *newItem = NULL;
661 PLItem *nodeItem = FindById( rootItem, p_add->i_node );
663 if( !nodeItem ) goto end;
665 p_item = playlist_ItemGetById( p_playlist, p_add->i_item );
666 if( !p_item || p_item->i_flags & PLAYLIST_DBL_FLAG ) goto end;
667 if( i_depth == DEPTH_SEL && p_item->p_parent &&
668 p_item->p_parent->i_id != rootItem->i_id )
671 newItem = new PLItem( p_item, nodeItem, this );
672 nodeItem->appendChild( newItem );
673 UpdateTreeItem( p_item, newItem, true );
680 void PLModel::rebuild()
685 void PLModel::rebuild( playlist_item_t *p_root )
687 playlist_item_t* p_item;
688 /* Remove callbacks before locking to avoid deadlocks */
690 /* Invalidate cache */
691 i_cached_id = i_cached_input_id = -1;
697 if( rootItem->children.size() )
699 beginRemoveRows( index( rootItem, 0 ), 0,
700 rootItem->children.size() -1 );
701 qDeleteAll( rootItem->children );
702 rootItem->children.clear();
709 rootItem = new PLItem( p_root, getSettings(), this );
712 /* Recreate from root */
713 UpdateNodeChildren( rootItem );
714 if( (p_item = playlist_CurrentPlayingItem(p_playlist)) )
716 PLItem *currentItem = FindByInput( rootItem,
717 p_item->p_input->i_id );
720 UpdateTreeItem( p_item, currentItem,
726 /* And signal the view */
727 emit layoutChanged();
731 /* This function must be entered WITH the playlist lock */
732 void PLModel::UpdateNodeChildren( PLItem *root )
734 playlist_item_t *p_node = playlist_ItemGetById( p_playlist, root->i_id );
735 UpdateNodeChildren( p_node, root );
738 /* This function must be entered WITH the playlist lock */
739 void PLModel::UpdateNodeChildren( playlist_item_t *p_node, PLItem *root )
741 for( int i = 0; i < p_node->i_children ; i++ )
743 if( p_node->pp_children[i]->i_flags & PLAYLIST_DBL_FLAG ) continue;
744 PLItem *newItem = new PLItem( p_node->pp_children[i], root, this );
745 root->appendChild( newItem, false );
746 UpdateTreeItem( newItem, false, true );
747 if( i_depth == DEPTH_PL && p_node->pp_children[i]->i_children != -1 )
748 UpdateNodeChildren( p_node->pp_children[i], newItem );
752 /* This function must be entered WITH the playlist lock */
753 void PLModel::UpdateTreeItem( PLItem *item, bool signal, bool force )
755 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id );
756 UpdateTreeItem( p_item, item, signal, force );
759 /* This function must be entered WITH the playlist lock */
760 void PLModel::UpdateTreeItem( playlist_item_t *p_item, PLItem *item,
761 bool signal, bool force )
765 if( !force && i_depth == DEPTH_SEL && p_item->p_parent &&
766 p_item->p_parent->i_id != rootItem->i_id )
768 item->update( p_item, p_item == playlist_CurrentPlayingItem( p_playlist ) );
770 emit dataChanged( index( item, 0 ) , index( item, 1 ) );
773 /************************* Actions ******************************/
776 * Deletion, here we have to do a ugly slow hack as we retrieve the full
777 * list of indexes to delete at once: when we delete a node and all of
778 * its children, we need to update the list.
779 * Todo: investigate whethere we can use ranges to be sure to delete all items?
781 void PLModel::doDelete( QModelIndexList selected )
783 for( int i = selected.size() -1 ; i >= 0; i-- )
785 QModelIndex index = selected[i];
786 if( index.column() != 0 ) continue;
787 PLItem *item = static_cast<PLItem*>(index.internalPointer());
790 if( item->children.size() )
791 recurseDelete( item->children, &selected );
792 doDeleteItem( item, &selected );
794 if( i > selected.size() ) i = selected.size();
798 void PLModel::recurseDelete( QList<PLItem*> children, QModelIndexList *fullList )
800 for( int i = children.size() - 1; i >= 0 ; i-- )
802 PLItem *item = children[i];
803 if( item->children.size() )
804 recurseDelete( item->children, fullList );
805 doDeleteItem( item, fullList );
809 void PLModel::doDeleteItem( PLItem *item, QModelIndexList *fullList )
811 QModelIndex deleteIndex = index( item, 0 );
812 fullList->removeAll( deleteIndex );
815 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id );
821 if( p_item->i_children == -1 )
822 playlist_DeleteFromInput( p_playlist, p_item->p_input, pl_Locked );
824 playlist_NodeDelete( p_playlist, p_item, true, false );
825 /* And finally, remove it from the tree */
826 item->remove( item );
830 /******* Volume III: Sorting and searching ********/
831 void PLModel::sort( int column, Qt::SortOrder order )
837 for( i_column = 1; i_column != COLUMN_END; i_column<<=1 )
839 if( ( shownFlags() & i_column ) )
841 if( column == i_index )
852 playlist_item_t *p_root = playlist_ItemGetById( p_playlist,
854 if( p_root && i_flag )
856 playlist_RecursiveNodeSort( p_playlist, p_root,
857 i_column_sorting( i_flag ),
858 order == Qt::AscendingOrder ?
859 ORDER_NORMAL : ORDER_REVERSE );
866 void PLModel::search( const QString& search_text )
868 /** \todo Fire the search with a small delay ? */
871 playlist_item_t *p_root = playlist_ItemGetById( p_playlist,
874 const char *psz_name = search_text.toUtf8().data();
875 playlist_LiveSearchUpdate( p_playlist , p_root, psz_name );
881 /*********** Popup *********/
882 void PLModel::popup( QModelIndex & index, QPoint &point, QModelIndexList list )
884 assert( index.isValid() );
886 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, itemId( index ) );
889 i_popup_item = p_item->i_id;
890 i_popup_parent = p_item->p_parent ? p_item->p_parent->i_id : -1;
892 current_selection = list;
893 QMenu *menu = new QMenu;
894 menu->addAction( qtr(I_POP_PLAY), this, SLOT( popupPlay() ) );
895 menu->addAction( qtr(I_POP_DEL), this, SLOT( popupDel() ) );
896 menu->addSeparator();
897 menu->addAction( qtr(I_POP_STREAM), this, SLOT( popupStream() ) );
898 menu->addAction( qtr(I_POP_SAVE), this, SLOT( popupSave() ) );
899 menu->addSeparator();
900 menu->addAction( qtr(I_POP_INFO), this, SLOT( popupInfo() ) );
901 if( p_item->i_children > -1 )
903 menu->addSeparator();
904 menu->addAction( qtr(I_POP_SORT), this, SLOT( popupSort() ) );
905 menu->addAction( qtr(I_POP_ADD), this, SLOT( popupAdd() ) );
907 menu->addSeparator();
908 menu->addAction( qtr( I_POP_EXPLORE ), this, SLOT( popupExplore() ) );
909 menu->popup( point );
916 void PLModel::viewchanged( int meta )
929 /* UNUSED emit layoutAboutToBeChanged(); */
930 index = __MIN( index, columnCount() );
931 QModelIndex parent = createIndex( 0, 0, rootItem );
933 if( rootItem->i_showflags & meta )
934 /* Removing columns */
936 beginRemoveColumns( parent, index, index+1 );
937 rootItem->i_showflags &= ~( meta );
938 getSettings()->setValue( "qt-pl-showflags", rootItem->i_showflags );
944 beginInsertColumns( parent, index, index+1 );
945 rootItem->i_showflags |= meta;
946 getSettings()->setValue( "qt-pl-showflags", rootItem->i_showflags );
949 emit columnsChanged( meta );
954 void PLModel::popupDel()
956 doDelete( current_selection );
959 void PLModel::popupPlay()
963 playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
965 activateItem( p_item );
970 void PLModel::popupInfo()
973 playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
977 input_item_t* p_input = p_item->p_input;
978 vlc_gc_incref( p_input );
980 MediaInfoDialog *mid = new MediaInfoDialog( p_intf, p_input );
981 vlc_gc_decref( p_input );
982 mid->setParent( PlaylistDialog::getInstance( p_intf ),
988 void PLModel::popupStream()
990 QStringList mrls = selectedURIs();
991 if( !mrls.isEmpty() )
992 THEDP->streamingDialog( NULL, mrls[0], false );
996 void PLModel::popupSave()
998 QStringList mrls = selectedURIs();
999 if( !mrls.isEmpty() )
1000 THEDP->streamingDialog( NULL, mrls[0] );
1004 #include <QFileInfo>
1005 #include <QDesktopServices>
1006 void PLModel::popupExplore()
1009 playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
1013 input_item_t *p_input = p_item->p_input;
1014 char *psz_meta = input_item_GetURI( p_input );
1018 const char *psz_access;
1019 const char *psz_demux;
1021 input_SplitMRL( &psz_access, &psz_demux, &psz_path, psz_meta );
1023 if( EMPTY_STR( psz_access ) ||
1024 !strncasecmp( psz_access, "file", 4 ) ||
1025 !strncasecmp( psz_access, "dire", 4 ) )
1027 QFileInfo info( qfu( psz_meta ) );
1028 QDesktopServices::openUrl(
1029 QUrl::fromLocalFile( info.absolutePath() ) );
1038 /**********************************************************************
1039 * Playlist callbacks
1040 **********************************************************************/
1041 static int PlaylistChanged( vlc_object_t *p_this, const char *psz_variable,
1042 vlc_value_t oval, vlc_value_t nval, void *param )
1044 PLModel *p_model = (PLModel *) param;
1045 PLEvent *event = new PLEvent( PLUpdate_Type, 0 );
1046 QApplication::postEvent( p_model, event );
1050 static int PlaylistNext( vlc_object_t *p_this, const char *psz_variable,
1051 vlc_value_t oval, vlc_value_t nval, void *param )
1053 PLModel *p_model = (PLModel *) param;
1054 PLEvent *event = new PLEvent( ItemUpdate_Type, oval.i_int );
1055 QApplication::postEvent( p_model, event );
1056 event = new PLEvent( ItemUpdate_Type, nval.i_int );
1057 QApplication::postEvent( p_model, event );
1061 static int ItemDeleted( vlc_object_t *p_this, const char *psz_variable,
1062 vlc_value_t oval, vlc_value_t nval, void *param )
1064 PLModel *p_model = (PLModel *) param;
1065 PLEvent *event = new PLEvent( ItemDelete_Type, nval.i_int );
1066 QApplication::postEvent( p_model, event );
1070 static int ItemAppended( vlc_object_t *p_this, const char *psz_variable,
1071 vlc_value_t oval, vlc_value_t nval, void *param )
1073 PLModel *p_model = (PLModel *) param;
1074 const playlist_add_t *p_add = (playlist_add_t *)nval.p_address;
1075 PLEvent *event = new PLEvent( p_add );
1076 QApplication::postEvent( p_model, event );