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>
8 * Ilkka Ollakkka <ileoo (at) videolan dot org>
9 * Jakob Leben <jleben@videolan.org>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24 *****************************************************************************/
31 #include "dialogs_provider.hpp"
32 #include "components/playlist/playlist_model.hpp"
33 #include "dialogs/mediainfo.hpp"
34 #include "dialogs/playlist.hpp"
35 #include <vlc_intf_strings.h>
37 #include "pixmaps/types/type_unknown.xpm"
43 #include <QApplication>
48 QIcon PLModel::icons[ITEM_TYPE_NUMBER];
50 static int ItemAppended( vlc_object_t *p_this, const char *psz_variable,
51 vlc_value_t oval, vlc_value_t nval, void *param );
52 static int ItemDeleted( vlc_object_t *p_this, const char *psz_variable,
53 vlc_value_t oval, vlc_value_t nval, void *param );
55 /*************************************************************************
56 * Playlist model implementation
57 *************************************************************************/
60 This model is called two times, for the selector and the standard panel
62 PLModel::PLModel( playlist_t *_p_playlist, /* THEPL */
63 intf_thread_t *_p_intf, /* main Qt p_intf */
64 playlist_item_t * p_root,
65 /*playlist_GetPreferredNode( THEPL, THEPL->p_local_category );
66 and THEPL->p_root_category for SelectPL */
67 QObject *parent ) /* Basic Qt parent */
68 : QAbstractItemModel( parent )
71 p_playlist = _p_playlist;
73 i_cached_input_id = -1;
74 i_popup_item = i_popup_parent = -1;
77 rootItem = NULL; /* PLItem rootItem, will be set in rebuild( ) */
79 /* Icons initialization */
80 #define ADD_ICON(type, x) icons[ITEM_TYPE_##type] = QIcon( QPixmap( x ) )
81 ADD_ICON( UNKNOWN , type_unknown_xpm );
82 ADD_ICON( FILE, ":/type/file" );
83 ADD_ICON( DIRECTORY, ":/type/directory" );
84 ADD_ICON( DISC, ":/type/disc" );
85 ADD_ICON( CDDA, ":/type/cdda" );
86 ADD_ICON( CARD, ":/type/capture-card" );
87 ADD_ICON( NET, ":/type/net" );
88 ADD_ICON( PLAYLIST, ":/type/playlist" );
89 ADD_ICON( NODE, ":/type/node" );
92 rebuild( p_root, true );
93 CONNECT( THEMIM->getIM(), metaChanged( input_item_t *),
94 this, processInputItemUpdate( input_item_t *) );
95 CONNECT( THEMIM, inputChanged( input_thread_t * ),
96 this, processInputItemUpdate( input_thread_t* ) );
105 Qt::DropActions PLModel::supportedDropActions() const
107 return Qt::CopyAction; /* Why not Qt::MoveAction */
110 Qt::ItemFlags PLModel::flags( const QModelIndex &index ) const
112 Qt::ItemFlags flags = QAbstractItemModel::flags( index );
114 PLItem *item = index.isValid() ? getItem( index ) : rootItem;
119 playlist_item_t *plItem =
120 playlist_ItemGetById( p_playlist, item->i_id );
122 if ( plItem && ( plItem->i_children > -1 ) )
123 flags |= Qt::ItemIsDropEnabled;
128 flags |= Qt::ItemIsDragEnabled;
133 QStringList PLModel::mimeTypes() const
136 types << "vlc/qt-playlist-item";
140 QMimeData *PLModel::mimeData( const QModelIndexList &indexes ) const
142 QMimeData *mimeData = new QMimeData();
143 QByteArray encodedData;
144 QDataStream stream( &encodedData, QIODevice::WriteOnly );
145 QModelIndexList list;
147 foreach( const QModelIndex &index, indexes ) {
148 if( index.isValid() && index.column() == 0 )
154 foreach( const QModelIndex &index, list ) {
155 PLItem *item = getItem( index );
156 stream.writeRawData( (char*) &item, sizeof( PLItem* ) );
158 mimeData->setData( "vlc/qt-playlist-item", encodedData );
163 bool PLModel::dropMimeData( const QMimeData *data, Qt::DropAction action,
164 int row, int column, const QModelIndex &parent )
166 if( data->hasFormat( "vlc/qt-playlist-item" ) )
168 if( action == Qt::IgnoreAction )
171 PLItem *parentItem = parent.isValid() ? getItem( parent ) : rootItem;
174 playlist_item_t *p_parent =
175 playlist_ItemGetById( p_playlist, parentItem->i_id );
176 if( !p_parent || p_parent->i_children == -1 )
183 playlist_item_t *p_pl = p_playlist->p_local_category;
184 playlist_item_t *p_ml = p_playlist->p_ml_category;
188 ( p_pl && p_parent->p_input == p_pl->p_input ) ||
189 ( p_ml && p_parent->p_input == p_ml->p_input ) )
194 QByteArray encodedData = data->data( "vlc/qt-playlist-item" );
196 dropAppendCopy( encodedData, parentItem );
198 dropMove( encodedData, parentItem, row );
203 void PLModel::dropAppendCopy( QByteArray& data, PLItem *target )
205 QDataStream stream( &data, QIODevice::ReadOnly );
208 playlist_item_t *p_parent =
209 playlist_ItemGetById( p_playlist, target->i_id );
210 while( !stream.atEnd() )
213 stream.readRawData( (char*)&item, sizeof(PLItem*) );
214 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id );
215 if( !p_item ) continue;
216 input_item_t *p_input = p_item->p_input;
217 playlist_AddExt ( p_playlist,
218 p_input->psz_uri, p_input->psz_name,
219 PLAYLIST_APPEND | PLAYLIST_SPREPARSE, PLAYLIST_END,
221 p_input->i_options, p_input->ppsz_options, p_input->optflagc,
222 ( p_parent == p_playlist->p_local_category ||
223 p_parent == p_playlist->p_local_onelevel ),
229 void PLModel::dropMove( QByteArray& data, PLItem *target, int row )
231 QDataStream stream( &data, QIODevice::ReadOnly );
232 QList<PLItem*> model_items;
234 int new_pos = row == -1 ? target->children.size() : row;
235 int model_pos = new_pos;
236 while( !stream.atEnd() )
239 stream.readRawData( (char*)&item, sizeof(PLItem*) );
241 /* better not try to move a node into itself: */
242 PLItem *climber = target;
245 if( climber == item ) break;
246 climber = climber->parentItem;
248 if( climber ) continue;
250 if( item->parentItem == target &&
251 target->children.indexOf( item ) < model_pos )
254 ids.append( item->i_id );
255 model_items.append( item );
259 int count = ids.size();
262 playlist_item_t *pp_items[count];
265 for( int i = 0; i < count; i++ )
267 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, ids[i] );
273 pp_items[i] = p_item;
275 playlist_item_t *p_parent =
276 playlist_ItemGetById( p_playlist, target->i_id );
277 playlist_TreeMoveMany( p_playlist, count, pp_items, p_parent,
281 insertChildren( target, model_items, model_pos );
285 /* remove item with its id */
286 void PLModel::removeItem( int i_id )
288 PLItem *item = findById( rootItem, i_id );
292 /* callbacks and slots */
293 void PLModel::addCallbacks()
295 /* One item has been updated */
296 var_AddCallback( p_playlist, "playlist-item-append", ItemAppended, this );
297 var_AddCallback( p_playlist, "playlist-item-deleted", ItemDeleted, this );
300 void PLModel::delCallbacks()
302 var_DelCallback( p_playlist, "playlist-item-append", ItemAppended, this );
303 var_DelCallback( p_playlist, "playlist-item-deleted", ItemDeleted, this );
306 void PLModel::activateItem( const QModelIndex &index )
308 assert( index.isValid() );
309 PLItem *item = getItem( index );
312 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id );
313 activateItem( p_item );
317 /* Must be entered with lock */
318 void PLModel::activateItem( playlist_item_t *p_item )
320 if( !p_item ) return;
321 playlist_item_t *p_parent = p_item;
324 if( p_parent->i_id == rootItem->i_id ) break;
325 p_parent = p_parent->p_parent;
328 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, pl_Locked,
332 /****************** Base model mandatory implementations *****************/
333 QVariant PLModel::data( const QModelIndex &index, int role ) const
335 if( !index.isValid() ) return QVariant();
336 PLItem *item = getItem( index );
337 if( role == Qt::DisplayRole )
339 int metadata = columnToMeta( index.column() );
340 if( metadata == COLUMN_END ) return QVariant();
343 if( metadata == COLUMN_NUMBER )
344 returninfo = QString::number( index.row() + 1 );
347 char *psz = psz_column_meta( item->p_input, metadata );
348 returninfo = qfu( psz );
351 return QVariant( returninfo );
353 else if( role == Qt::DecorationRole && index.column() == 0 )
355 /* Use to segfault here because i_type wasn't always initialized */
356 if( item->p_input->i_type >= 0 )
357 return QVariant( PLModel::icons[item->p_input->i_type] );
359 else if( role == Qt::FontRole )
361 if( isCurrent( index ) )
363 QFont f; f.setBold( true ); return QVariant( f );
369 bool PLModel::isCurrent( const QModelIndex &index ) const
371 if( !currentItem ) return false;
372 return getItem( index )->p_input == currentItem->p_input;
375 int PLModel::itemId( const QModelIndex &index ) const
377 return getItem( index )->i_id;
380 QVariant PLModel::headerData( int section, Qt::Orientation orientation,
383 if (orientation != Qt::Horizontal || role != Qt::DisplayRole)
386 int meta_col = columnToMeta( section );
388 if( meta_col == COLUMN_END ) return QVariant();
390 return QVariant( qfu( psz_column_title( meta_col ) ) );
393 QModelIndex PLModel::index( int row, int column, const QModelIndex &parent )
396 PLItem *parentItem = parent.isValid() ? getItem( parent ) : rootItem;
398 PLItem *childItem = parentItem->child( row );
400 return createIndex( row, column, childItem );
402 return QModelIndex();
405 /* Return the index of a given item */
406 QModelIndex PLModel::index( PLItem *item, int column ) const
408 if( !item ) return QModelIndex();
409 const PLItem *parent = item->parent();
411 return createIndex( parent->children.lastIndexOf( item ),
413 return QModelIndex();
416 QModelIndex PLModel::parent( const QModelIndex &index ) const
418 if( !index.isValid() ) return QModelIndex();
420 PLItem *childItem = getItem( index );
423 msg_Err( p_playlist, "NULL CHILD" );
424 return QModelIndex();
427 PLItem *parentItem = childItem->parent();
428 if( !parentItem || parentItem == rootItem ) return QModelIndex();
429 if( !parentItem->parentItem )
431 msg_Err( p_playlist, "No parent parent, trying row 0 " );
432 msg_Err( p_playlist, "----- PLEASE REPORT THIS ------" );
433 return createIndex( 0, 0, parentItem );
435 QModelIndex ind = createIndex(parentItem->row(), 0, parentItem);
439 int PLModel::columnCount( const QModelIndex &i) const
441 return columnFromMeta( COLUMN_END );
444 int PLModel::rowCount( const QModelIndex &parent ) const
446 PLItem *parentItem = parent.isValid() ? getItem( parent ) : rootItem;
447 return parentItem->childCount();
450 QStringList PLModel::selectedURIs()
453 for( int i = 0; i < current_selection.size(); i++ )
455 PLItem *item = getItem( current_selection[i] );
459 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id );
462 char *psz = input_item_GetURI( p_item->p_input );
465 lst.append( qfu(psz) );
475 /************************* General playlist status ***********************/
477 bool PLModel::hasRandom()
479 return var_GetBool( p_playlist, "random" );
481 bool PLModel::hasRepeat()
483 return var_GetBool( p_playlist, "repeat" );
485 bool PLModel::hasLoop()
487 return var_GetBool( p_playlist, "loop" );
489 void PLModel::setLoop( bool on )
491 var_SetBool( p_playlist, "loop", on ? true:false );
492 config_PutInt( p_playlist, "loop", on ? 1: 0 );
494 void PLModel::setRepeat( bool on )
496 var_SetBool( p_playlist, "repeat", on ? true:false );
497 config_PutInt( p_playlist, "repeat", on ? 1: 0 );
499 void PLModel::setRandom( bool on )
501 var_SetBool( p_playlist, "random", on ? true:false );
502 config_PutInt( p_playlist, "random", on ? 1: 0 );
505 /************************* Lookups *****************************/
507 PLItem *PLModel::findById( PLItem *root, int i_id )
509 return findInner( root, i_id, false );
512 PLItem *PLModel::findByInput( PLItem *root, int i_id )
514 PLItem *result = findInner( root, i_id, true );
518 #define CACHE( i, p ) { i_cached_id = i; p_cached_item = p; }
519 #define ICACHE( i, p ) { i_cached_input_id = i; p_cached_item_bi = p; }
521 PLItem * PLModel::findInner( PLItem *root, int i_id, bool b_input )
523 if( !root ) return NULL;
524 if( ( !b_input && i_cached_id == i_id) ||
525 ( b_input && i_cached_input_id ==i_id ) )
527 return b_input ? p_cached_item_bi : p_cached_item;
530 if( !b_input && root->i_id == i_id )
535 else if( b_input && root->p_input->i_id == i_id )
537 ICACHE( i_id, root );
541 QList<PLItem *>::iterator it = root->children.begin();
542 while ( it != root->children.end() )
544 if( !b_input && (*it)->i_id == i_id )
546 CACHE( i_id, (*it) );
547 return p_cached_item;
549 else if( b_input && (*it)->p_input->i_id == i_id )
551 ICACHE( i_id, (*it) );
552 return p_cached_item_bi;
554 if( (*it)->children.size() )
556 PLItem *childFound = findInner( (*it), i_id, b_input );
560 ICACHE( i_id, childFound )
562 CACHE( i_id, childFound )
573 PLItem *PLModel::getItem( QModelIndex index )
575 assert( index.isValid() );
576 return static_cast<PLItem*>( index.internalPointer() );
579 int PLModel::columnToMeta( int _column ) const
584 while( column != _column && meta != COLUMN_END )
593 int PLModel::columnFromMeta( int meta_col ) const
598 while( meta != meta_col && meta != COLUMN_END )
607 bool PLModel::canEdit() const
612 rootItem->p_input == p_playlist->p_local_category->p_input ||
614 p_playlist->p_ml_category &&
615 rootItem->p_input == p_playlist->p_ml_category->p_input
620 /************************* Updates handling *****************************/
621 void PLModel::customEvent( QEvent *event )
623 int type = event->type();
624 if( type != ItemAppend_Type &&
625 type != ItemDelete_Type )
628 PLEvent *ple = static_cast<PLEvent *>(event);
630 if( type == ItemAppend_Type )
631 processItemAppend( &ple->add );
632 else if( type == ItemDelete_Type )
633 processItemRemoval( ple->i_id );
636 /**** Events processing ****/
637 void PLModel::processInputItemUpdate( input_thread_t *p_input )
639 if( !p_input ) return;
640 processInputItemUpdate( input_GetItem( p_input ) );
641 if( p_input && !( p_input->b_dead || !vlc_object_alive( p_input ) ) )
643 PLItem *item = findByInput( rootItem, input_GetItem( p_input )->i_id );
645 emit currentChanged( index( item, 0 ) );
652 void PLModel::processInputItemUpdate( input_item_t *p_item )
654 if( !p_item || p_item->i_id <= 0 ) return;
655 PLItem *item = findByInput( rootItem, p_item->i_id );
657 updateTreeItem( item );
660 void PLModel::processItemRemoval( int i_id )
662 if( i_id <= 0 ) return;
666 void PLModel::processItemAppend( const playlist_add_t *p_add )
668 playlist_item_t *p_item = NULL;
669 PLItem *newItem = NULL;
671 PLItem *nodeItem = findById( rootItem, p_add->i_node );
672 if( !nodeItem ) return;
674 foreach( PLItem *existing, nodeItem->children )
675 if( existing->i_id == p_add->i_item ) return;
678 p_item = playlist_ItemGetById( p_playlist, p_add->i_item );
679 if( !p_item || p_item->i_flags & PLAYLIST_DBL_FLAG ) goto end;
681 newItem = new PLItem( p_item, nodeItem );
684 beginInsertRows( index( nodeItem, 0 ), nodeItem->childCount(), nodeItem->childCount() );
685 nodeItem->appendChild( newItem );
687 updateTreeItem( newItem );
695 void PLModel::rebuild()
697 rebuild( NULL, false );
700 void PLModel::rebuild( playlist_item_t *p_root, bool b_first )
702 playlist_item_t* p_item;
703 /* Remove callbacks before locking to avoid deadlocks
704 The first time the callbacks are not present so
705 don't try to delete them */
709 /* Invalidate cache */
710 i_cached_id = i_cached_input_id = -1;
712 if( rootItem ) rootItem->removeChildren();
718 rootItem = new PLItem( p_root );
721 /* Recreate from root */
722 updateChildren( rootItem );
723 if( (p_item = playlist_CurrentPlayingItem(p_playlist)) )
724 currentItem = findByInput( rootItem, p_item->p_input->i_id );
729 /* And signal the view */
732 emit currentChanged( index( currentItem, 0 ) );
737 void PLModel::takeItem( PLItem *item )
740 PLItem *parent = item->parentItem;
742 int i_index = parent->children.indexOf( item );
744 beginRemoveRows( index( parent, 0 ), i_index, i_index );
745 parent->takeChildAt( i_index );
749 void PLModel::insertChildren( PLItem *node, QList<PLItem*>& items, int i_pos )
752 int count = items.size();
754 beginInsertRows( index( node, 0 ), i_pos, i_pos + count - 1 );
755 for( int i = 0; i < count; i++ )
757 node->children.insert( i_pos + i, items[i] );
758 items[i]->parentItem = node;
763 void PLModel::removeItem( PLItem *item )
767 if( item->i_id == i_cached_id ) i_cached_id = -1;
768 i_cached_input_id = -1;
770 if( currentItem == item || rootItem == item)
773 emit currentChanged( QModelIndex() );
779 if( item->parentItem ) {
780 int i = item->parentItem->children.indexOf( item );
781 beginRemoveRows( index( item->parentItem, 0), i, i );
782 item->parentItem->children.removeAt(i);
790 /* This function must be entered WITH the playlist lock */
791 void PLModel::updateChildren( PLItem *root )
793 playlist_item_t *p_node = playlist_ItemGetById( p_playlist, root->i_id );
794 updateChildren( p_node, root );
797 /* This function must be entered WITH the playlist lock */
798 void PLModel::updateChildren( playlist_item_t *p_node, PLItem *root )
800 playlist_item_t *p_item = playlist_CurrentPlayingItem(p_playlist);
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 root->appendChild( newItem );
806 if( p_item && newItem->p_input == p_item->p_input )
808 currentItem = newItem;
809 emit currentChanged( index( currentItem, 0 ) );
811 if( p_node->pp_children[i]->i_children != -1 )
812 updateChildren( p_node->pp_children[i], newItem );
816 /* Function doesn't need playlist-lock, as we don't touch playlist_item_t stuff here*/
817 void PLModel::updateTreeItem( PLItem *item )
820 emit dataChanged( index( item, 0 ) , index( item, columnCount( QModelIndex() ) ) );
823 /************************* Actions ******************************/
826 * Deletion, here we have to do a ugly slow hack as we retrieve the full
827 * list of indexes to delete at once: when we delete a node and all of
828 * its children, we need to update the list.
829 * Todo: investigate whethere we can use ranges to be sure to delete all items?
831 void PLModel::doDelete( QModelIndexList selected )
833 if( !canEdit() ) return;
835 for( int i = selected.size() -1 ; i >= 0; i-- )
837 QModelIndex index = selected[i];
838 if( index.column() != 0 ) continue;
839 PLItem *item = getItem( index );
842 if( item->children.size() )
843 recurseDelete( item->children, &selected );
844 doDeleteItem( item, &selected );
846 if( i > selected.size() ) i = selected.size();
850 void PLModel::recurseDelete( QList<PLItem*> children, QModelIndexList *fullList )
852 for( int i = children.size() - 1; i >= 0 ; i-- )
854 PLItem *item = children[i];
855 if( item->children.size() )
856 recurseDelete( item->children, fullList );
857 doDeleteItem( item, fullList );
861 void PLModel::doDeleteItem( PLItem *item, QModelIndexList *fullList )
863 QModelIndex deleteIndex = index( item, 0 );
864 fullList->removeAll( deleteIndex );
867 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id );
873 if( p_item->i_children == -1 )
874 playlist_DeleteFromInput( p_playlist, p_item->p_input, pl_Locked );
876 playlist_NodeDelete( p_playlist, p_item, true, false );
879 /* And finally, remove it from the tree */
883 /******* Volume III: Sorting and searching ********/
884 void PLModel::sort( int column, Qt::SortOrder order )
886 sort( rootItem->i_id, column, order );
889 void PLModel::sort( int i_root_id, int column, Qt::SortOrder order )
891 int meta = columnToMeta( column );
892 if( meta == COLUMN_END ) return;
894 PLItem *item = findById( rootItem, i_root_id );
896 QModelIndex qIndex = index( item, 0 );
897 int count = item->children.size();
900 beginRemoveRows( qIndex, 0, count - 1 );
901 item->removeChildren();
907 playlist_item_t *p_root = playlist_ItemGetById( p_playlist,
911 playlist_RecursiveNodeSort( p_playlist, p_root,
912 i_column_sorting( meta ),
913 order == Qt::AscendingOrder ?
914 ORDER_NORMAL : ORDER_REVERSE );
919 beginInsertRows( qIndex, 0, count - 1 );
920 updateChildren( item );
926 void PLModel::search( const QString& search_text )
928 /** \todo Fire the search with a small delay ? */
931 playlist_item_t *p_root = playlist_ItemGetById( p_playlist,
934 const char *psz_name = search_text.toUtf8().data();
935 playlist_LiveSearchUpdate( p_playlist , p_root, psz_name );
941 /*********** Popup *********/
942 void PLModel::popup( QModelIndex & index, QPoint &point, QModelIndexList list )
944 int i_id = index.isValid() ? itemId( index ) : rootItem->i_id;
947 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, i_id );
952 i_popup_item = index.isValid() ? p_item->i_id : -1;
953 i_popup_parent = index.isValid() ?
954 ( p_item->p_parent ? p_item->p_parent->i_id : -1 ) :
956 i_popup_column = index.column();
957 /* check whether we are in tree view */
959 playlist_item_t *p_up = p_item;
962 if ( p_up == p_playlist->p_root_category ) tree = true;
963 p_up = p_up->p_parent;
967 current_selection = list;
968 QMenu *menu = new QMenu;
969 if( i_popup_item > -1 )
971 menu->addAction( qtr(I_POP_PLAY), this, SLOT( popupPlay() ) );
972 menu->addAction( qtr(I_POP_DEL), this, SLOT( popupDel() ) );
973 menu->addSeparator();
974 menu->addAction( qtr(I_POP_STREAM), this, SLOT( popupStream() ) );
975 menu->addAction( qtr(I_POP_SAVE), this, SLOT( popupSave() ) );
976 menu->addSeparator();
977 menu->addAction( qtr(I_POP_INFO), this, SLOT( popupInfo() ) );
978 menu->addSeparator();
979 QMenu *sort_menu = menu->addMenu( qtr( "Sort by ") +
980 qfu( psz_column_title( columnToMeta( index.column() ) ) ) );
981 sort_menu->addAction( qtr( "Ascending" ),
982 this, SLOT( popupSortAsc() ) );
983 sort_menu->addAction( qtr( "Descending" ),
984 this, SLOT( popupSortDesc() ) );
987 menu->addAction( qtr(I_POP_ADD), this, SLOT( popupAddNode() ) );
988 if( i_popup_item > -1 )
990 menu->addSeparator();
991 menu->addAction( qtr( I_POP_EXPLORE ), this, SLOT( popupExplore() ) );
993 menu->popup( point );
996 void PLModel::popupDel()
998 doDelete( current_selection );
1001 void PLModel::popupPlay()
1005 playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
1007 activateItem( p_item );
1012 void PLModel::popupInfo()
1015 playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
1019 input_item_t* p_input = p_item->p_input;
1020 vlc_gc_incref( p_input );
1022 MediaInfoDialog *mid = new MediaInfoDialog( p_intf, p_input );
1023 vlc_gc_decref( p_input );
1024 mid->setParent( PlaylistDialog::getInstance( p_intf ),
1031 void PLModel::popupStream()
1033 QStringList mrls = selectedURIs();
1034 if( !mrls.isEmpty() )
1035 THEDP->streamingDialog( NULL, mrls[0], false );
1039 void PLModel::popupSave()
1041 QStringList mrls = selectedURIs();
1042 if( !mrls.isEmpty() )
1043 THEDP->streamingDialog( NULL, mrls[0] );
1047 #include <QFileInfo>
1048 #include <QDesktopServices>
1049 void PLModel::popupExplore()
1052 playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
1056 input_item_t *p_input = p_item->p_input;
1057 char *psz_meta = input_item_GetURI( p_input );
1061 const char *psz_access;
1062 const char *psz_demux;
1064 input_SplitMRL( &psz_access, &psz_demux, &psz_path, psz_meta );
1066 if( EMPTY_STR( psz_access ) ||
1067 !strncasecmp( psz_access, "file", 4 ) ||
1068 !strncasecmp( psz_access, "dire", 4 ) )
1070 QFileInfo info( qfu( psz_meta ) );
1071 QDesktopServices::openUrl(
1072 QUrl::fromLocalFile( info.absolutePath() ) );
1081 #include <QInputDialog>
1082 void PLModel::popupAddNode()
1085 QString name = QInputDialog::getText( PlaylistDialog::getInstance( p_intf ),
1086 qtr( I_POP_ADD ), qtr( "Enter name for new node:" ),
1087 QLineEdit::Normal, QString(), &ok);
1088 if( !ok || name.isEmpty() ) return;
1090 playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
1094 playlist_NodeCreate( p_playlist, qtu( name ), p_item, 0, NULL );
1099 void PLModel::popupSortAsc()
1101 sort( i_popup_parent, i_popup_column, Qt::AscendingOrder );
1104 void PLModel::popupSortDesc()
1106 sort( i_popup_parent, i_popup_column, Qt::DescendingOrder );
1108 /**********************************************************************
1109 * Playlist callbacks
1110 **********************************************************************/
1112 static int ItemDeleted( vlc_object_t *p_this, const char *psz_variable,
1113 vlc_value_t oval, vlc_value_t nval, void *param )
1115 PLModel *p_model = (PLModel *) param;
1116 PLEvent *event = new PLEvent( ItemDelete_Type, nval.i_int );
1117 QApplication::postEvent( p_model, event );
1121 static int ItemAppended( vlc_object_t *p_this, const char *psz_variable,
1122 vlc_value_t oval, vlc_value_t nval, void *param )
1124 PLModel *p_model = (PLModel *) param;
1125 const playlist_add_t *p_add = (playlist_add_t *)nval.p_address;
1126 PLEvent *event = new PLEvent( p_add );
1127 QApplication::postEvent( p_model, event );