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, true );
227 void PLModel::dropMove( QByteArray& data, PLItem *target, int row )
229 QDataStream stream( &data, QIODevice::ReadOnly );
230 QList<PLItem*> model_items;
232 int new_pos = row == -1 ? target->children.size() : row;
233 int model_pos = new_pos;
234 while( !stream.atEnd() )
237 stream.readRawData( (char*)&item, sizeof(PLItem*) );
239 /* better not try to move a node into itself: */
240 PLItem *climber = target;
243 if( climber == item ) break;
244 climber = climber->parentItem;
246 if( climber ) continue;
248 if( item->parentItem == target &&
249 target->children.indexOf( item ) < model_pos )
252 ids.append( item->i_id );
253 model_items.append( item );
257 int count = ids.size();
260 playlist_item_t *pp_items[count];
263 for( int i = 0; i < count; i++ )
265 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, ids[i] );
271 pp_items[i] = p_item;
273 playlist_item_t *p_parent =
274 playlist_ItemGetById( p_playlist, target->i_id );
275 playlist_TreeMoveMany( p_playlist, count, pp_items, p_parent,
279 insertChildren( target, model_items, model_pos );
283 /* remove item with its id */
284 void PLModel::removeItem( int i_id )
286 PLItem *item = findById( rootItem, i_id );
290 /* callbacks and slots */
291 void PLModel::addCallbacks()
293 /* One item has been updated */
294 var_AddCallback( p_playlist, "playlist-item-append", ItemAppended, this );
295 var_AddCallback( p_playlist, "playlist-item-deleted", ItemDeleted, this );
298 void PLModel::delCallbacks()
300 var_DelCallback( p_playlist, "playlist-item-append", ItemAppended, this );
301 var_DelCallback( p_playlist, "playlist-item-deleted", ItemDeleted, this );
304 void PLModel::activateItem( const QModelIndex &index )
306 assert( index.isValid() );
307 PLItem *item = getItem( index );
310 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id );
311 activateItem( p_item );
315 /* Must be entered with lock */
316 void PLModel::activateItem( playlist_item_t *p_item )
318 if( !p_item ) return;
319 playlist_item_t *p_parent = p_item;
322 if( p_parent->i_id == rootItem->i_id ) break;
323 p_parent = p_parent->p_parent;
326 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, pl_Locked,
330 /****************** Base model mandatory implementations *****************/
331 QVariant PLModel::data( const QModelIndex &index, int role ) const
333 if( !index.isValid() ) return QVariant();
334 PLItem *item = getItem( index );
335 if( role == Qt::DisplayRole )
337 int metadata = columnToMeta( index.column() );
338 if( metadata == COLUMN_END ) return QVariant();
341 if( metadata == COLUMN_NUMBER )
342 returninfo = QString::number( index.row() + 1 );
345 char *psz = psz_column_meta( item->p_input, metadata );
346 returninfo = qfu( psz );
349 return QVariant( returninfo );
351 else if( role == Qt::DecorationRole && index.column() == 0 )
353 /* Use to segfault here because i_type wasn't always initialized */
354 if( item->p_input->i_type >= 0 )
355 return QVariant( PLModel::icons[item->p_input->i_type] );
357 else if( role == Qt::FontRole )
359 if( isCurrent( index ) )
361 QFont f; f.setBold( true ); return QVariant( f );
367 bool PLModel::isCurrent( const QModelIndex &index ) const
369 if( !currentItem ) return false;
370 return getItem( index )->p_input == currentItem->p_input;
373 int PLModel::itemId( const QModelIndex &index ) const
375 return getItem( index )->i_id;
378 QVariant PLModel::headerData( int section, Qt::Orientation orientation,
381 if (orientation != Qt::Horizontal || role != Qt::DisplayRole)
384 int meta_col = columnToMeta( section );
386 if( meta_col == COLUMN_END ) return QVariant();
388 return QVariant( qfu( psz_column_title( meta_col ) ) );
391 QModelIndex PLModel::index( int row, int column, const QModelIndex &parent )
394 PLItem *parentItem = parent.isValid() ? getItem( parent ) : rootItem;
396 PLItem *childItem = parentItem->child( row );
398 return createIndex( row, column, childItem );
400 return QModelIndex();
403 /* Return the index of a given item */
404 QModelIndex PLModel::index( PLItem *item, int column ) const
406 if( !item ) return QModelIndex();
407 const PLItem *parent = item->parent();
409 return createIndex( parent->children.lastIndexOf( item ),
411 return QModelIndex();
414 QModelIndex PLModel::parent( const QModelIndex &index ) const
416 if( !index.isValid() ) return QModelIndex();
418 PLItem *childItem = getItem( index );
421 msg_Err( p_playlist, "NULL CHILD" );
422 return QModelIndex();
425 PLItem *parentItem = childItem->parent();
426 if( !parentItem || parentItem == rootItem ) return QModelIndex();
427 if( !parentItem->parentItem )
429 msg_Err( p_playlist, "No parent parent, trying row 0 " );
430 msg_Err( p_playlist, "----- PLEASE REPORT THIS ------" );
431 return createIndex( 0, 0, parentItem );
433 QModelIndex ind = createIndex(parentItem->row(), 0, parentItem);
437 int PLModel::columnCount( const QModelIndex &i) const
439 return columnFromMeta( COLUMN_END );
442 int PLModel::rowCount( const QModelIndex &parent ) const
444 PLItem *parentItem = parent.isValid() ? getItem( parent ) : rootItem;
445 return parentItem->childCount();
448 QStringList PLModel::selectedURIs()
451 for( int i = 0; i < current_selection.size(); i++ )
453 PLItem *item = getItem( current_selection[i] );
457 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id );
460 char *psz = input_item_GetURI( p_item->p_input );
463 lst.append( qfu(psz) );
473 /************************* General playlist status ***********************/
475 bool PLModel::hasRandom()
477 return var_GetBool( p_playlist, "random" );
479 bool PLModel::hasRepeat()
481 return var_GetBool( p_playlist, "repeat" );
483 bool PLModel::hasLoop()
485 return var_GetBool( p_playlist, "loop" );
487 void PLModel::setLoop( bool on )
489 var_SetBool( p_playlist, "loop", on ? true:false );
490 config_PutInt( p_playlist, "loop", on ? 1: 0 );
492 void PLModel::setRepeat( bool on )
494 var_SetBool( p_playlist, "repeat", on ? true:false );
495 config_PutInt( p_playlist, "repeat", on ? 1: 0 );
497 void PLModel::setRandom( bool on )
499 var_SetBool( p_playlist, "random", on ? true:false );
500 config_PutInt( p_playlist, "random", on ? 1: 0 );
503 /************************* Lookups *****************************/
505 PLItem *PLModel::findById( PLItem *root, int i_id )
507 return findInner( root, i_id, false );
510 PLItem *PLModel::findByInput( PLItem *root, int i_id )
512 PLItem *result = findInner( root, i_id, true );
516 #define CACHE( i, p ) { i_cached_id = i; p_cached_item = p; }
517 #define ICACHE( i, p ) { i_cached_input_id = i; p_cached_item_bi = p; }
519 PLItem * PLModel::findInner( PLItem *root, int i_id, bool b_input )
521 if( !root ) return NULL;
522 if( ( !b_input && i_cached_id == i_id) ||
523 ( b_input && i_cached_input_id ==i_id ) )
525 return b_input ? p_cached_item_bi : p_cached_item;
528 if( !b_input && root->i_id == i_id )
533 else if( b_input && root->p_input->i_id == i_id )
535 ICACHE( i_id, root );
539 QList<PLItem *>::iterator it = root->children.begin();
540 while ( it != root->children.end() )
542 if( !b_input && (*it)->i_id == i_id )
544 CACHE( i_id, (*it) );
545 return p_cached_item;
547 else if( b_input && (*it)->p_input->i_id == i_id )
549 ICACHE( i_id, (*it) );
550 return p_cached_item_bi;
552 if( (*it)->children.size() )
554 PLItem *childFound = findInner( (*it), i_id, b_input );
558 ICACHE( i_id, childFound )
560 CACHE( i_id, childFound )
571 PLItem *PLModel::getItem( QModelIndex index )
573 assert( index.isValid() );
574 return static_cast<PLItem*>( index.internalPointer() );
577 int PLModel::columnToMeta( int _column ) const
582 while( column != _column && meta != COLUMN_END )
591 int PLModel::columnFromMeta( int meta_col ) const
596 while( meta != meta_col && meta != COLUMN_END )
605 bool PLModel::canEdit() const
610 rootItem->p_input == p_playlist->p_local_category->p_input ||
612 p_playlist->p_ml_category &&
613 rootItem->p_input == p_playlist->p_ml_category->p_input
618 /************************* Updates handling *****************************/
619 void PLModel::customEvent( QEvent *event )
621 int type = event->type();
622 if( type != ItemAppend_Type &&
623 type != ItemDelete_Type )
626 PLEvent *ple = static_cast<PLEvent *>(event);
628 if( type == ItemAppend_Type )
629 processItemAppend( &ple->add );
630 else if( type == ItemDelete_Type )
631 processItemRemoval( ple->i_id );
634 /**** Events processing ****/
635 void PLModel::processInputItemUpdate( input_thread_t *p_input )
637 if( !p_input ) return;
638 processInputItemUpdate( input_GetItem( p_input ) );
639 if( p_input && !( p_input->b_dead || !vlc_object_alive( p_input ) ) )
641 PLItem *item = findByInput( rootItem, input_GetItem( p_input )->i_id );
643 emit currentChanged( index( item, 0 ) );
650 void PLModel::processInputItemUpdate( input_item_t *p_item )
652 if( !p_item || p_item->i_id <= 0 ) return;
653 PLItem *item = findByInput( rootItem, p_item->i_id );
655 updateTreeItem( item );
658 void PLModel::processItemRemoval( int i_id )
660 if( i_id <= 0 ) return;
664 void PLModel::processItemAppend( const playlist_add_t *p_add )
666 playlist_item_t *p_item = NULL;
667 PLItem *newItem = NULL;
669 PLItem *nodeItem = findById( rootItem, p_add->i_node );
670 if( !nodeItem ) return;
672 foreach( PLItem *existing, nodeItem->children )
673 if( existing->i_id == p_add->i_item ) return;
676 p_item = playlist_ItemGetById( p_playlist, p_add->i_item );
677 if( !p_item || p_item->i_flags & PLAYLIST_DBL_FLAG ) goto end;
679 newItem = new PLItem( p_item, nodeItem );
682 beginInsertRows( index( nodeItem, 0 ), nodeItem->childCount(), nodeItem->childCount() );
683 nodeItem->appendChild( newItem );
685 updateTreeItem( newItem );
693 void PLModel::rebuild()
695 rebuild( NULL, false );
698 void PLModel::rebuild( playlist_item_t *p_root, bool b_first )
700 playlist_item_t* p_item;
701 /* Remove callbacks before locking to avoid deadlocks
702 The first time the callbacks are not present so
703 don't try to delete them */
707 /* Invalidate cache */
708 i_cached_id = i_cached_input_id = -1;
710 if( rootItem ) rootItem->removeChildren();
716 rootItem = new PLItem( p_root );
719 /* Recreate from root */
720 updateChildren( rootItem );
721 if( (p_item = playlist_CurrentPlayingItem(p_playlist)) )
722 currentItem = findByInput( rootItem, p_item->p_input->i_id );
727 /* And signal the view */
730 emit currentChanged( index( currentItem, 0 ) );
735 void PLModel::takeItem( PLItem *item )
738 PLItem *parent = item->parentItem;
740 int i_index = parent->children.indexOf( item );
742 beginRemoveRows( index( parent, 0 ), i_index, i_index );
743 parent->takeChildAt( i_index );
747 void PLModel::insertChildren( PLItem *node, QList<PLItem*>& items, int i_pos )
750 int count = items.size();
752 beginInsertRows( index( node, 0 ), i_pos, i_pos + count - 1 );
753 for( int i = 0; i < count; i++ )
755 node->children.insert( i_pos + i, items[i] );
756 items[i]->parentItem = node;
761 void PLModel::removeItem( PLItem *item )
765 if( item->i_id == i_cached_id ) i_cached_id = -1;
766 i_cached_input_id = -1;
768 if( currentItem == item || rootItem == item)
771 emit currentChanged( QModelIndex() );
777 if( item->parentItem ) {
778 int i = item->parentItem->children.indexOf( item );
779 beginRemoveRows( index( item->parentItem, 0), i, i );
780 item->parentItem->children.removeAt(i);
788 /* This function must be entered WITH the playlist lock */
789 void PLModel::updateChildren( PLItem *root )
791 playlist_item_t *p_node = playlist_ItemGetById( p_playlist, root->i_id );
792 updateChildren( p_node, root );
795 /* This function must be entered WITH the playlist lock */
796 void PLModel::updateChildren( playlist_item_t *p_node, PLItem *root )
798 playlist_item_t *p_item = playlist_CurrentPlayingItem(p_playlist);
799 for( int i = 0; i < p_node->i_children ; i++ )
801 if( p_node->pp_children[i]->i_flags & PLAYLIST_DBL_FLAG ) continue;
802 PLItem *newItem = new PLItem( p_node->pp_children[i], root );
803 root->appendChild( newItem );
804 if( p_item && newItem->p_input == p_item->p_input )
806 currentItem = newItem;
807 emit currentChanged( index( currentItem, 0 ) );
809 if( p_node->pp_children[i]->i_children != -1 )
810 updateChildren( p_node->pp_children[i], newItem );
814 /* Function doesn't need playlist-lock, as we don't touch playlist_item_t stuff here*/
815 void PLModel::updateTreeItem( PLItem *item )
818 emit dataChanged( index( item, 0 ) , index( item, columnCount( QModelIndex() ) ) );
821 /************************* Actions ******************************/
824 * Deletion, here we have to do a ugly slow hack as we retrieve the full
825 * list of indexes to delete at once: when we delete a node and all of
826 * its children, we need to update the list.
827 * Todo: investigate whethere we can use ranges to be sure to delete all items?
829 void PLModel::doDelete( QModelIndexList selected )
831 if( !canEdit() ) return;
833 for( int i = selected.size() -1 ; i >= 0; i-- )
835 QModelIndex index = selected[i];
836 if( index.column() != 0 ) continue;
837 PLItem *item = getItem( index );
840 if( item->children.size() )
841 recurseDelete( item->children, &selected );
842 doDeleteItem( item, &selected );
844 if( i > selected.size() ) i = selected.size();
848 void PLModel::recurseDelete( QList<PLItem*> children, QModelIndexList *fullList )
850 for( int i = children.size() - 1; i >= 0 ; i-- )
852 PLItem *item = children[i];
853 if( item->children.size() )
854 recurseDelete( item->children, fullList );
855 doDeleteItem( item, fullList );
859 void PLModel::doDeleteItem( PLItem *item, QModelIndexList *fullList )
861 QModelIndex deleteIndex = index( item, 0 );
862 fullList->removeAll( deleteIndex );
865 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id );
871 if( p_item->i_children == -1 )
872 playlist_DeleteFromInput( p_playlist, p_item->p_input, pl_Locked );
874 playlist_NodeDelete( p_playlist, p_item, true, false );
877 /* And finally, remove it from the tree */
881 /******* Volume III: Sorting and searching ********/
882 void PLModel::sort( int column, Qt::SortOrder order )
884 sort( rootItem->i_id, column, order );
887 void PLModel::sort( int i_root_id, int column, Qt::SortOrder order )
889 int meta = columnToMeta( column );
890 if( meta == COLUMN_END ) return;
892 PLItem *item = findById( rootItem, i_root_id );
894 QModelIndex qIndex = index( item, 0 );
895 int count = item->children.size();
898 beginRemoveRows( qIndex, 0, count - 1 );
899 item->removeChildren();
905 playlist_item_t *p_root = playlist_ItemGetById( p_playlist,
909 playlist_RecursiveNodeSort( p_playlist, p_root,
910 i_column_sorting( meta ),
911 order == Qt::AscendingOrder ?
912 ORDER_NORMAL : ORDER_REVERSE );
917 beginInsertRows( qIndex, 0, count - 1 );
918 updateChildren( item );
924 void PLModel::search( const QString& search_text )
926 /** \todo Fire the search with a small delay ? */
929 playlist_item_t *p_root = playlist_ItemGetById( p_playlist,
932 const char *psz_name = search_text.toUtf8().data();
933 playlist_LiveSearchUpdate( p_playlist , p_root, psz_name );
939 /*********** Popup *********/
940 void PLModel::popup( QModelIndex & index, QPoint &point, QModelIndexList list )
942 int i_id = index.isValid() ? itemId( index ) : rootItem->i_id;
945 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, i_id );
950 i_popup_item = index.isValid() ? p_item->i_id : -1;
951 i_popup_parent = index.isValid() ?
952 ( p_item->p_parent ? p_item->p_parent->i_id : -1 ) :
954 i_popup_column = index.column();
955 /* check whether we are in tree view */
957 playlist_item_t *p_up = p_item;
960 if ( p_up == p_playlist->p_root_category ) tree = true;
961 p_up = p_up->p_parent;
965 current_selection = list;
966 QMenu *menu = new QMenu;
967 if( i_popup_item > -1 )
969 menu->addAction( qtr(I_POP_PLAY), this, SLOT( popupPlay() ) );
970 menu->addAction( qtr(I_POP_DEL), this, SLOT( popupDel() ) );
971 menu->addSeparator();
972 menu->addAction( qtr(I_POP_STREAM), this, SLOT( popupStream() ) );
973 menu->addAction( qtr(I_POP_SAVE), this, SLOT( popupSave() ) );
974 menu->addSeparator();
975 menu->addAction( qtr(I_POP_INFO), this, SLOT( popupInfo() ) );
976 menu->addSeparator();
977 QMenu *sort_menu = menu->addMenu( qtr( "Sort by ") +
978 qfu( psz_column_title( columnToMeta( index.column() ) ) ) );
979 sort_menu->addAction( qtr( "Ascending" ),
980 this, SLOT( popupSortAsc() ) );
981 sort_menu->addAction( qtr( "Descending" ),
982 this, SLOT( popupSortDesc() ) );
985 menu->addAction( qtr(I_POP_ADD), this, SLOT( popupAddNode() ) );
986 if( i_popup_item > -1 )
988 menu->addSeparator();
989 menu->addAction( qtr( I_POP_EXPLORE ), this, SLOT( popupExplore() ) );
991 menu->popup( point );
994 void PLModel::popupDel()
996 doDelete( current_selection );
999 void PLModel::popupPlay()
1003 playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
1005 activateItem( p_item );
1010 void PLModel::popupInfo()
1013 playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
1017 input_item_t* p_input = p_item->p_input;
1018 vlc_gc_incref( p_input );
1020 MediaInfoDialog *mid = new MediaInfoDialog( p_intf, p_input );
1021 vlc_gc_decref( p_input );
1022 mid->setParent( PlaylistDialog::getInstance( p_intf ),
1029 void PLModel::popupStream()
1031 QStringList mrls = selectedURIs();
1032 if( !mrls.isEmpty() )
1033 THEDP->streamingDialog( NULL, mrls[0], false );
1037 void PLModel::popupSave()
1039 QStringList mrls = selectedURIs();
1040 if( !mrls.isEmpty() )
1041 THEDP->streamingDialog( NULL, mrls[0] );
1045 #include <QFileInfo>
1046 #include <QDesktopServices>
1047 void PLModel::popupExplore()
1050 playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
1054 input_item_t *p_input = p_item->p_input;
1055 char *psz_meta = input_item_GetURI( p_input );
1059 const char *psz_access;
1060 const char *psz_demux;
1062 input_SplitMRL( &psz_access, &psz_demux, &psz_path, psz_meta );
1064 if( EMPTY_STR( psz_access ) ||
1065 !strncasecmp( psz_access, "file", 4 ) ||
1066 !strncasecmp( psz_access, "dire", 4 ) )
1068 QFileInfo info( qfu( psz_meta ) );
1069 QDesktopServices::openUrl(
1070 QUrl::fromLocalFile( info.absolutePath() ) );
1079 #include <QInputDialog>
1080 void PLModel::popupAddNode()
1083 QString name = QInputDialog::getText( PlaylistDialog::getInstance( p_intf ),
1084 qtr( I_POP_ADD ), qtr( "Enter name for new node:" ),
1085 QLineEdit::Normal, QString(), &ok);
1086 if( !ok || name.isEmpty() ) return;
1088 playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
1092 playlist_NodeCreate( p_playlist, qtu( name ), p_item, 0, NULL );
1097 void PLModel::popupSortAsc()
1099 sort( i_popup_parent, i_popup_column, Qt::AscendingOrder );
1102 void PLModel::popupSortDesc()
1104 sort( i_popup_parent, i_popup_column, Qt::DescendingOrder );
1106 /**********************************************************************
1107 * Playlist callbacks
1108 **********************************************************************/
1110 static int ItemDeleted( vlc_object_t *p_this, const char *psz_variable,
1111 vlc_value_t oval, vlc_value_t nval, void *param )
1113 PLModel *p_model = (PLModel *) param;
1114 PLEvent *event = new PLEvent( ItemDelete_Type, nval.i_int );
1115 QApplication::postEvent( p_model, event );
1119 static int ItemAppended( vlc_object_t *p_this, const char *psz_variable,
1120 vlc_value_t oval, vlc_value_t nval, void *param )
1122 PLModel *p_model = (PLModel *) param;
1123 const playlist_add_t *p_add = (playlist_add_t *)nval.p_address;
1124 PLEvent *event = new PLEvent( p_add );
1125 QApplication::postEvent( p_model, event );