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;
116 input_item_t *pl_input =
117 p_playlist->p_local_category ?
118 p_playlist->p_local_category->p_input : NULL;
119 input_item_t *ml_input =
120 p_playlist->p_ml_category ?
121 p_playlist->p_ml_category->p_input : NULL;
123 if( ( pl_input && rootItem->p_input == pl_input ) ||
124 ( ml_input && rootItem->p_input == ml_input ) )
127 playlist_item_t *plItem =
128 playlist_ItemGetById( p_playlist, item->i_id );
130 if ( plItem && ( plItem->i_children > -1 ) )
131 flags |= Qt::ItemIsDropEnabled;
136 flags |= Qt::ItemIsDragEnabled;
141 QStringList PLModel::mimeTypes() const
144 types << "vlc/qt-playlist-item";
148 QMimeData *PLModel::mimeData( const QModelIndexList &indexes ) const
150 QMimeData *mimeData = new QMimeData();
151 QByteArray encodedData;
152 QDataStream stream( &encodedData, QIODevice::WriteOnly );
153 QModelIndexList list;
155 foreach( const QModelIndex &index, indexes ) {
156 if( index.isValid() && index.column() == 0 )
162 foreach( const QModelIndex &index, list ) {
163 PLItem *item = getItem( index );
164 stream.writeRawData( (char*) &item, sizeof( PLItem* ) );
166 mimeData->setData( "vlc/qt-playlist-item", encodedData );
171 bool PLModel::dropMimeData( const QMimeData *data, Qt::DropAction action,
172 int row, int column, const QModelIndex &parent )
174 if( data->hasFormat( "vlc/qt-playlist-item" ) )
176 if( action == Qt::IgnoreAction )
179 PLItem *parentItem = parent.isValid() ? getItem( parent ) : rootItem;
182 playlist_item_t *p_parent =
183 playlist_ItemGetById( p_playlist, parentItem->i_id );
184 if( !p_parent || p_parent->i_children == -1 )
191 playlist_item_t *p_pl = p_playlist->p_local_category;
192 playlist_item_t *p_ml = p_playlist->p_ml_category;
196 ( p_pl && p_parent->p_input == p_pl->p_input ) ||
197 ( p_ml && p_parent->p_input == p_ml->p_input ) )
202 QByteArray encodedData = data->data( "vlc/qt-playlist-item" );
204 dropAppendCopy( encodedData, parentItem );
206 dropMove( encodedData, parentItem, row );
211 void PLModel::dropAppendCopy( QByteArray& data, PLItem *target )
213 QDataStream stream( &data, QIODevice::ReadOnly );
216 playlist_item_t *p_parent =
217 playlist_ItemGetById( p_playlist, target->i_id );
218 while( !stream.atEnd() )
221 stream.readRawData( (char*)&item, sizeof(PLItem*) );
222 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id );
223 if( !p_item ) continue;
224 input_item_t *p_input = p_item->p_input;
225 playlist_AddExt ( p_playlist,
226 p_input->psz_uri, p_input->psz_name,
227 PLAYLIST_APPEND | PLAYLIST_SPREPARSE, PLAYLIST_END,
229 p_input->i_options, p_input->ppsz_options, p_input->optflagc,
230 p_parent == p_playlist->p_local_category, true );
235 void PLModel::dropMove( QByteArray& data, PLItem *target, int row )
237 QDataStream stream( &data, QIODevice::ReadOnly );
238 QList<PLItem*> model_items;
240 int new_pos = row == -1 ? target->children.size() : row;
241 int model_pos = new_pos;
242 while( !stream.atEnd() )
245 stream.readRawData( (char*)&item, sizeof(PLItem*) );
247 /* better not try to move a node into itself: */
248 PLItem *climber = target;
251 if( climber == item ) break;
252 climber = climber->parentItem;
254 if( climber ) continue;
256 if( item->parentItem == target &&
257 target->children.indexOf( item ) < model_pos )
260 ids.append( item->i_id );
261 model_items.append( item );
265 int count = ids.size();
268 playlist_item_t *pp_items[count];
271 for( int i = 0; i < count; i++ )
273 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, ids[i] );
279 pp_items[i] = p_item;
281 playlist_item_t *p_parent =
282 playlist_ItemGetById( p_playlist, target->i_id );
283 playlist_TreeMoveMany( p_playlist, count, pp_items, p_parent,
287 insertChildren( target, model_items, model_pos );
291 /* remove item with its id */
292 void PLModel::removeItem( int i_id )
294 PLItem *item = findById( rootItem, i_id );
298 /* callbacks and slots */
299 void PLModel::addCallbacks()
301 /* One item has been updated */
302 var_AddCallback( p_playlist, "playlist-item-append", ItemAppended, this );
303 var_AddCallback( p_playlist, "playlist-item-deleted", ItemDeleted, this );
306 void PLModel::delCallbacks()
308 var_DelCallback( p_playlist, "playlist-item-append", ItemAppended, this );
309 var_DelCallback( p_playlist, "playlist-item-deleted", ItemDeleted, this );
312 void PLModel::activateItem( const QModelIndex &index )
314 assert( index.isValid() );
315 PLItem *item = getItem( index );
318 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id );
319 activateItem( p_item );
323 /* Must be entered with lock */
324 void PLModel::activateItem( playlist_item_t *p_item )
326 if( !p_item ) return;
327 playlist_item_t *p_parent = p_item;
330 if( p_parent->i_id == rootItem->i_id ) break;
331 p_parent = p_parent->p_parent;
334 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, pl_Locked,
338 /****************** Base model mandatory implementations *****************/
339 QVariant PLModel::data( const QModelIndex &index, int role ) const
341 if( !index.isValid() ) return QVariant();
342 PLItem *item = getItem( index );
343 if( role == Qt::DisplayRole )
345 int metadata = columnToMeta( index.column() );
346 if( metadata == COLUMN_END ) return QVariant();
349 if( metadata == COLUMN_NUMBER )
350 returninfo = QString::number( index.row() + 1 );
353 char *psz = psz_column_meta( item->p_input, metadata );
354 returninfo = qfu( psz );
357 return QVariant( returninfo );
359 else if( role == Qt::DecorationRole && index.column() == 0 )
361 /* Use to segfault here because i_type wasn't always initialized */
362 if( item->p_input->i_type >= 0 )
363 return QVariant( PLModel::icons[item->p_input->i_type] );
365 else if( role == Qt::FontRole )
367 if( isCurrent( index ) )
369 QFont f; f.setBold( true ); return QVariant( f );
375 bool PLModel::isCurrent( const QModelIndex &index ) const
377 if( !currentItem ) return false;
378 return getItem( index )->p_input == currentItem->p_input;
381 int PLModel::itemId( const QModelIndex &index ) const
383 return getItem( index )->i_id;
386 QVariant PLModel::headerData( int section, Qt::Orientation orientation,
389 if (orientation != Qt::Horizontal || role != Qt::DisplayRole)
392 int meta_col = columnToMeta( section );
394 if( meta_col == COLUMN_END ) return QVariant();
396 return QVariant( qfu( psz_column_title( meta_col ) ) );
399 QModelIndex PLModel::index( int row, int column, const QModelIndex &parent )
402 PLItem *parentItem = parent.isValid() ? getItem( parent ) : rootItem;
404 PLItem *childItem = parentItem->child( row );
406 return createIndex( row, column, childItem );
408 return QModelIndex();
411 /* Return the index of a given item */
412 QModelIndex PLModel::index( PLItem *item, int column ) const
414 if( !item ) return QModelIndex();
415 const PLItem *parent = item->parent();
417 return createIndex( parent->children.lastIndexOf( item ),
419 return QModelIndex();
422 QModelIndex PLModel::parent( const QModelIndex &index ) const
424 if( !index.isValid() ) return QModelIndex();
426 PLItem *childItem = getItem( index );
429 msg_Err( p_playlist, "NULL CHILD" );
430 return QModelIndex();
433 PLItem *parentItem = childItem->parent();
434 if( !parentItem || parentItem == rootItem ) return QModelIndex();
435 if( !parentItem->parentItem )
437 msg_Err( p_playlist, "No parent parent, trying row 0 " );
438 msg_Err( p_playlist, "----- PLEASE REPORT THIS ------" );
439 return createIndex( 0, 0, parentItem );
441 QModelIndex ind = createIndex(parentItem->row(), 0, parentItem);
445 int PLModel::columnCount( const QModelIndex &i) const
447 return columnFromMeta( COLUMN_END );
450 int PLModel::rowCount( const QModelIndex &parent ) const
452 PLItem *parentItem = parent.isValid() ? getItem( parent ) : rootItem;
453 return parentItem->childCount();
456 QStringList PLModel::selectedURIs()
459 for( int i = 0; i < current_selection.size(); i++ )
461 PLItem *item = getItem( current_selection[i] );
465 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id );
468 char *psz = input_item_GetURI( p_item->p_input );
481 /************************* General playlist status ***********************/
483 bool PLModel::hasRandom()
485 return var_GetBool( p_playlist, "random" );
487 bool PLModel::hasRepeat()
489 return var_GetBool( p_playlist, "repeat" );
491 bool PLModel::hasLoop()
493 return var_GetBool( p_playlist, "loop" );
495 void PLModel::setLoop( bool on )
497 var_SetBool( p_playlist, "loop", on ? true:false );
498 config_PutInt( p_playlist, "loop", on ? 1: 0 );
500 void PLModel::setRepeat( bool on )
502 var_SetBool( p_playlist, "repeat", on ? true:false );
503 config_PutInt( p_playlist, "repeat", on ? 1: 0 );
505 void PLModel::setRandom( bool on )
507 var_SetBool( p_playlist, "random", on ? true:false );
508 config_PutInt( p_playlist, "random", on ? 1: 0 );
511 /************************* Lookups *****************************/
513 PLItem *PLModel::findById( PLItem *root, int i_id )
515 return findInner( root, i_id, false );
518 PLItem *PLModel::findByInput( PLItem *root, int i_id )
520 PLItem *result = findInner( root, i_id, true );
524 #define CACHE( i, p ) { i_cached_id = i; p_cached_item = p; }
525 #define ICACHE( i, p ) { i_cached_input_id = i; p_cached_item_bi = p; }
527 PLItem * PLModel::findInner( PLItem *root, int i_id, bool b_input )
529 if( !root ) return NULL;
530 if( ( !b_input && i_cached_id == i_id) ||
531 ( b_input && i_cached_input_id ==i_id ) )
533 return b_input ? p_cached_item_bi : p_cached_item;
536 if( !b_input && root->i_id == i_id )
541 else if( b_input && root->p_input->i_id == i_id )
543 ICACHE( i_id, root );
547 QList<PLItem *>::iterator it = root->children.begin();
548 while ( it != root->children.end() )
550 if( !b_input && (*it)->i_id == i_id )
552 CACHE( i_id, (*it) );
553 return p_cached_item;
555 else if( b_input && (*it)->p_input->i_id == i_id )
557 ICACHE( i_id, (*it) );
558 return p_cached_item_bi;
560 if( (*it)->children.size() )
562 PLItem *childFound = findInner( (*it), i_id, b_input );
566 ICACHE( i_id, childFound )
568 CACHE( i_id, childFound )
579 PLItem *PLModel::getItem( QModelIndex index )
581 assert( index.isValid() );
582 return static_cast<PLItem*>( index.internalPointer() );
585 int PLModel::columnToMeta( int _column ) const
590 while( column != _column && meta != COLUMN_END )
599 int PLModel::columnFromMeta( int meta_col ) const
604 while( meta != meta_col && meta != COLUMN_END )
613 /************************* Updates handling *****************************/
614 void PLModel::customEvent( QEvent *event )
616 int type = event->type();
617 if( type != ItemAppend_Type &&
618 type != ItemDelete_Type )
621 PLEvent *ple = static_cast<PLEvent *>(event);
623 if( type == ItemAppend_Type )
624 processItemAppend( &ple->add );
625 else if( type == ItemDelete_Type )
626 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 );
638 emit currentChanged( index( item, 0 ) );
645 void PLModel::processInputItemUpdate( input_item_t *p_item )
647 if( !p_item || p_item->i_id <= 0 ) return;
648 PLItem *item = findByInput( rootItem, p_item->i_id );
650 updateTreeItem( item );
653 void PLModel::processItemRemoval( int i_id )
655 if( i_id <= 0 ) return;
656 if( i_id == i_cached_id ) i_cached_id = -1;
657 i_cached_input_id = -1;
662 void PLModel::processItemAppend( const playlist_add_t *p_add )
664 playlist_item_t *p_item = NULL;
665 PLItem *newItem = NULL;
667 PLItem *nodeItem = findById( rootItem, p_add->i_node );
668 if( !nodeItem ) return;
671 p_item = playlist_ItemGetById( p_playlist, p_add->i_item );
672 if( !p_item || p_item->i_flags & PLAYLIST_DBL_FLAG ) goto end;
674 newItem = new PLItem( p_item, nodeItem );
677 beginInsertRows( index( nodeItem, 0 ), nodeItem->childCount(), nodeItem->childCount() );
678 nodeItem->appendChild( newItem );
680 updateTreeItem( newItem );
688 void PLModel::rebuild()
690 rebuild( NULL, false );
693 void PLModel::rebuild( playlist_item_t *p_root, bool b_first )
695 playlist_item_t* p_item;
696 /* Remove callbacks before locking to avoid deadlocks
697 The first time the callbacks are not present so
698 don't try to delete them */
702 /* Invalidate cache */
703 i_cached_id = i_cached_input_id = -1;
705 if( rootItem ) rootItem->removeChildren();
711 rootItem = new PLItem( p_root );
714 /* Recreate from root */
715 updateChildren( rootItem );
716 if( (p_item = playlist_CurrentPlayingItem(p_playlist)) )
717 currentItem = findByInput( rootItem, p_item->p_input->i_id );
722 /* And signal the view */
725 emit currentChanged( index( currentItem, 0 ) );
730 void PLModel::takeItem( PLItem *item )
733 PLItem *parent = item->parentItem;
735 int i_index = parent->children.indexOf( item );
737 beginRemoveRows( index( parent, 0 ), i_index, i_index );
738 parent->takeChildAt( i_index );
742 void PLModel::insertChildren( PLItem *node, QList<PLItem*>& items, int i_pos )
745 int count = items.size();
747 beginInsertRows( index( node, 0 ), i_pos, i_pos + count - 1 );
748 for( int i = 0; i < count; i++ )
750 node->children.insert( i_pos + i, items[i] );
751 items[i]->parentItem = node;
756 void PLModel::removeItem( PLItem *item )
760 if( currentItem == item )
763 emit currentChanged( QModelIndex() );
766 if( item->parentItem ) item->parentItem->removeChild( item );
776 /* This function must be entered WITH the playlist lock */
777 void PLModel::updateChildren( PLItem *root )
779 playlist_item_t *p_node = playlist_ItemGetById( p_playlist, root->i_id );
780 updateChildren( p_node, root );
783 /* This function must be entered WITH the playlist lock */
784 void PLModel::updateChildren( playlist_item_t *p_node, PLItem *root )
786 playlist_item_t *p_item = playlist_CurrentPlayingItem(p_playlist);
787 for( int i = 0; i < p_node->i_children ; i++ )
789 if( p_node->pp_children[i]->i_flags & PLAYLIST_DBL_FLAG ) continue;
790 PLItem *newItem = new PLItem( p_node->pp_children[i], root );
791 root->appendChild( newItem );
792 if( p_item && newItem->p_input == p_item->p_input )
794 currentItem = newItem;
795 emit currentChanged( index( currentItem, 0 ) );
797 if( p_node->pp_children[i]->i_children != -1 )
798 updateChildren( p_node->pp_children[i], newItem );
802 /* Function doesn't need playlist-lock, as we don't touch playlist_item_t stuff here*/
803 void PLModel::updateTreeItem( PLItem *item )
806 emit dataChanged( index( item, 0 ) , index( item, columnCount( QModelIndex() ) ) );
809 /************************* Actions ******************************/
812 * Deletion, here we have to do a ugly slow hack as we retrieve the full
813 * list of indexes to delete at once: when we delete a node and all of
814 * its children, we need to update the list.
815 * Todo: investigate whethere we can use ranges to be sure to delete all items?
817 void PLModel::doDelete( QModelIndexList selected )
819 for( int i = selected.size() -1 ; i >= 0; i-- )
821 QModelIndex index = selected[i];
822 if( index.column() != 0 ) continue;
823 PLItem *item = getItem( index );
826 if( item->children.size() )
827 recurseDelete( item->children, &selected );
828 doDeleteItem( item, &selected );
830 if( i > selected.size() ) i = selected.size();
834 void PLModel::recurseDelete( QList<PLItem*> children, QModelIndexList *fullList )
836 for( int i = children.size() - 1; i >= 0 ; i-- )
838 PLItem *item = children[i];
839 if( item->children.size() )
840 recurseDelete( item->children, fullList );
841 doDeleteItem( item, fullList );
845 void PLModel::doDeleteItem( PLItem *item, QModelIndexList *fullList )
847 QModelIndex deleteIndex = index( item, 0 );
848 fullList->removeAll( deleteIndex );
851 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id );
857 if( p_item->i_children == -1 )
858 playlist_DeleteFromInput( p_playlist, p_item->p_input, pl_Locked );
860 playlist_NodeDelete( p_playlist, p_item, true, false );
862 /* And finally, remove it from the tree */
863 int itemIndex = item->parentItem->children.indexOf( item );
864 beginRemoveRows( index( item->parentItem, 0), itemIndex, itemIndex );
869 /******* Volume III: Sorting and searching ********/
870 void PLModel::sort( int column, Qt::SortOrder order )
872 sort( rootItem->i_id, column, order );
875 void PLModel::sort( int i_root_id, int column, Qt::SortOrder order )
877 int meta = columnToMeta( column );
878 if( meta == COLUMN_END ) return;
880 PLItem *item = findById( rootItem, i_root_id );
882 QModelIndex qIndex = index( item, 0 );
883 int count = item->children.size();
886 beginRemoveRows( qIndex, 0, count - 1 );
887 item->removeChildren();
893 playlist_item_t *p_root = playlist_ItemGetById( p_playlist,
897 playlist_RecursiveNodeSort( p_playlist, p_root,
898 i_column_sorting( meta ),
899 order == Qt::AscendingOrder ?
900 ORDER_NORMAL : ORDER_REVERSE );
905 beginInsertRows( qIndex, 0, count - 1 );
906 updateChildren( item );
912 void PLModel::search( const QString& search_text )
914 /** \todo Fire the search with a small delay ? */
917 playlist_item_t *p_root = playlist_ItemGetById( p_playlist,
920 const char *psz_name = search_text.toUtf8().data();
921 playlist_LiveSearchUpdate( p_playlist , p_root, psz_name );
927 /*********** Popup *********/
928 void PLModel::popup( QModelIndex & index, QPoint &point, QModelIndexList list )
930 int i_id = index.isValid() ? itemId( index ) : rootItem->i_id;
933 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, i_id );
938 i_popup_item = index.isValid() ? p_item->i_id : -1;
939 i_popup_parent = index.isValid() ?
940 ( p_item->p_parent ? p_item->p_parent->i_id : -1 ) :
942 i_popup_column = index.column();
943 /* check whether we are in tree view */
945 playlist_item_t *p_up = p_item;
948 if ( p_up == p_playlist->p_root_category ) tree = true;
949 p_up = p_up->p_parent;
953 current_selection = list;
954 QMenu *menu = new QMenu;
955 if( i_popup_item > -1 )
957 menu->addAction( qtr(I_POP_PLAY), this, SLOT( popupPlay() ) );
958 menu->addAction( qtr(I_POP_DEL), this, SLOT( popupDel() ) );
959 menu->addSeparator();
960 menu->addAction( qtr(I_POP_STREAM), this, SLOT( popupStream() ) );
961 menu->addAction( qtr(I_POP_SAVE), this, SLOT( popupSave() ) );
962 menu->addSeparator();
963 menu->addAction( qtr(I_POP_INFO), this, SLOT( popupInfo() ) );
964 menu->addSeparator();
965 QMenu *sort_menu = menu->addMenu( qtr( "Sort by ") +
966 qfu( psz_column_title( columnToMeta( index.column() ) ) ) );
967 sort_menu->addAction( qtr( "Ascending" ),
968 this, SLOT( popupSortAsc() ) );
969 sort_menu->addAction( qtr( "Descending" ),
970 this, SLOT( popupSortDesc() ) );
973 menu->addAction( qtr(I_POP_ADD), this, SLOT( popupAddNode() ) );
974 if( i_popup_item > -1 )
976 menu->addSeparator();
977 menu->addAction( qtr( I_POP_EXPLORE ), this, SLOT( popupExplore() ) );
979 menu->popup( point );
982 void PLModel::popupDel()
984 doDelete( current_selection );
987 void PLModel::popupPlay()
991 playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
993 activateItem( p_item );
998 void PLModel::popupInfo()
1001 playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
1005 input_item_t* p_input = p_item->p_input;
1006 vlc_gc_incref( p_input );
1008 MediaInfoDialog *mid = new MediaInfoDialog( p_intf, p_input );
1009 vlc_gc_decref( p_input );
1010 mid->setParent( PlaylistDialog::getInstance( p_intf ),
1017 void PLModel::popupStream()
1019 QStringList mrls = selectedURIs();
1020 if( !mrls.isEmpty() )
1021 THEDP->streamingDialog( NULL, mrls[0], false );
1025 void PLModel::popupSave()
1027 QStringList mrls = selectedURIs();
1028 if( !mrls.isEmpty() )
1029 THEDP->streamingDialog( NULL, mrls[0] );
1033 #include <QFileInfo>
1034 #include <QDesktopServices>
1035 void PLModel::popupExplore()
1038 playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
1042 input_item_t *p_input = p_item->p_input;
1043 char *psz_meta = input_item_GetURI( p_input );
1047 const char *psz_access;
1048 const char *psz_demux;
1050 input_SplitMRL( &psz_access, &psz_demux, &psz_path, psz_meta );
1052 if( EMPTY_STR( psz_access ) ||
1053 !strncasecmp( psz_access, "file", 4 ) ||
1054 !strncasecmp( psz_access, "dire", 4 ) )
1056 QFileInfo info( qfu( psz_meta ) );
1057 QDesktopServices::openUrl(
1058 QUrl::fromLocalFile( info.absolutePath() ) );
1067 #include <QInputDialog>
1068 void PLModel::popupAddNode()
1071 QString name = QInputDialog::getText( PlaylistDialog::getInstance( p_intf ),
1072 qtr( I_POP_ADD ), qtr( "Enter name for new node:" ),
1073 QLineEdit::Normal, QString(), &ok);
1074 if( !ok || name.isEmpty() ) return;
1076 playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
1080 playlist_NodeCreate( p_playlist, qtu( name ), p_item, 0, NULL );
1085 void PLModel::popupSortAsc()
1087 sort( i_popup_parent, i_popup_column, Qt::AscendingOrder );
1090 void PLModel::popupSortDesc()
1092 sort( i_popup_parent, i_popup_column, Qt::DescendingOrder );
1094 /**********************************************************************
1095 * Playlist callbacks
1096 **********************************************************************/
1098 static int ItemDeleted( vlc_object_t *p_this, const char *psz_variable,
1099 vlc_value_t oval, vlc_value_t nval, void *param )
1101 PLModel *p_model = (PLModel *) param;
1102 PLEvent *event = new PLEvent( ItemDelete_Type, nval.i_int );
1103 QApplication::postEvent( p_model, event );
1107 static int ItemAppended( vlc_object_t *p_this, const char *psz_variable,
1108 vlc_value_t oval, vlc_value_t nval, void *param )
1110 PLModel *p_model = (PLModel *) param;
1111 const playlist_add_t *p_add = (playlist_add_t *)nval.p_address;
1112 PLEvent *event = new PLEvent( p_add );
1113 QApplication::postEvent( p_model, event );