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 "playlist.hpp"
36 #include <vlc_intf_strings.h>
38 #include "pixmaps/types/type_unknown.xpm"
44 #include <QApplication>
49 QIcon PLModel::icons[ITEM_TYPE_NUMBER];
51 /*************************************************************************
52 * Playlist model implementation
53 *************************************************************************/
56 This model is called two times, for the selector and the standard panel
58 PLModel::PLModel( playlist_t *_p_playlist, /* THEPL */
59 intf_thread_t *_p_intf, /* main Qt p_intf */
60 playlist_item_t * p_root,
61 /*playlist_GetPreferredNode( THEPL, THEPL->p_local_category );
62 and THEPL->p_root_category for SelectPL */
63 QObject *parent ) /* Basic Qt parent */
64 : QAbstractItemModel( parent )
67 p_playlist = _p_playlist;
68 plEM = new PlaylistEventManager( _p_playlist );
70 i_cached_input_id = -1;
71 i_popup_item = i_popup_parent = -1;
74 rootItem = NULL; /* PLItem rootItem, will be set in rebuild( ) */
76 /* Icons initialization */
77 #define ADD_ICON(type, x) icons[ITEM_TYPE_##type] = QIcon( x )
78 ADD_ICON( UNKNOWN , type_unknown_xpm );
79 ADD_ICON( FILE, ":/type/file" );
80 ADD_ICON( DIRECTORY, ":/type/directory" );
81 ADD_ICON( DISC, ":/type/disc" );
82 ADD_ICON( CDDA, ":/type/cdda" );
83 ADD_ICON( CARD, ":/type/capture-card" );
84 ADD_ICON( NET, ":/type/net" );
85 ADD_ICON( PLAYLIST, ":/type/playlist" );
86 ADD_ICON( NODE, ":/type/node" );
89 rebuild( p_root, true );
90 CONNECT( THEMIM->getIM(), metaChanged( input_item_t *),
91 this, processInputItemUpdate( input_item_t *) );
92 CONNECT( THEMIM, inputChanged( input_thread_t * ),
93 this, processInputItemUpdate( input_thread_t* ) );
94 CONNECT( plEM, itemAdded( int, int ), this, processItemAppend( int, int ) );
95 CONNECT( plEM, itemRemoved( int ), this, processItemRemoval( int ) );
104 Qt::DropActions PLModel::supportedDropActions() const
106 return Qt::CopyAction; /* Why not Qt::MoveAction */
109 Qt::ItemFlags PLModel::flags( const QModelIndex &index ) const
111 Qt::ItemFlags flags = QAbstractItemModel::flags( index );
113 PLItem *item = index.isValid() ? getItem( index ) : rootItem;
118 playlist_item_t *plItem =
119 playlist_ItemGetById( p_playlist, item->i_id );
121 if ( plItem && ( plItem->i_children > -1 ) )
122 flags |= Qt::ItemIsDropEnabled;
127 flags |= Qt::ItemIsDragEnabled;
132 QStringList PLModel::mimeTypes() const
135 types << "vlc/qt-playlist-item";
139 QMimeData *PLModel::mimeData( const QModelIndexList &indexes ) const
141 QMimeData *mimeData = new QMimeData();
142 QByteArray encodedData;
143 QDataStream stream( &encodedData, QIODevice::WriteOnly );
144 QModelIndexList list;
146 foreach( const QModelIndex &index, indexes ) {
147 if( index.isValid() && index.column() == 0 )
153 foreach( const QModelIndex &index, list ) {
154 PLItem *item = getItem( index );
155 stream.writeRawData( (char*) &item, sizeof( PLItem* ) );
157 mimeData->setData( "vlc/qt-playlist-item", encodedData );
162 bool PLModel::dropMimeData( const QMimeData *data, Qt::DropAction action,
163 int row, int column, const QModelIndex &parent )
165 if( data->hasFormat( "vlc/qt-playlist-item" ) )
167 if( action == Qt::IgnoreAction )
170 PLItem *parentItem = parent.isValid() ? getItem( parent ) : rootItem;
173 playlist_item_t *p_parent =
174 playlist_ItemGetById( p_playlist, parentItem->i_id );
175 if( !p_parent || p_parent->i_children == -1 )
182 playlist_item_t *p_pl = p_playlist->p_local_category;
183 playlist_item_t *p_ml = p_playlist->p_ml_category;
187 ( p_pl && p_parent->p_input == p_pl->p_input ) ||
188 ( p_ml && p_parent->p_input == p_ml->p_input ) )
193 QByteArray encodedData = data->data( "vlc/qt-playlist-item" );
195 dropAppendCopy( encodedData, parentItem );
197 dropMove( encodedData, parentItem, row );
202 void PLModel::dropAppendCopy( QByteArray& data, PLItem *target )
204 QDataStream stream( &data, QIODevice::ReadOnly );
207 playlist_item_t *p_parent =
208 playlist_ItemGetById( p_playlist, target->i_id );
209 while( !stream.atEnd() )
212 stream.readRawData( (char*)&item, sizeof(PLItem*) );
213 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id );
214 if( !p_item ) continue;
215 input_item_t *p_input = p_item->p_input;
216 playlist_AddExt ( p_playlist,
217 p_input->psz_uri, p_input->psz_name,
218 PLAYLIST_APPEND | PLAYLIST_SPREPARSE, PLAYLIST_END,
220 p_input->i_options, p_input->ppsz_options, p_input->optflagc,
221 ( p_parent == p_playlist->p_local_category ||
222 p_parent == p_playlist->p_local_onelevel ),
228 void PLModel::dropMove( QByteArray& data, PLItem *target, int row )
230 QDataStream stream( &data, QIODevice::ReadOnly );
231 QList<PLItem*> model_items;
233 int new_pos = row == -1 ? target->children.size() : row;
234 int model_pos = new_pos;
235 while( !stream.atEnd() )
238 stream.readRawData( (char*)&item, sizeof(PLItem*) );
240 /* better not try to move a node into itself: */
241 PLItem *climber = target;
244 if( climber == item ) break;
245 climber = climber->parentItem;
247 if( climber ) continue;
249 if( item->parentItem == target &&
250 target->children.indexOf( item ) < model_pos )
253 ids.append( item->i_id );
254 model_items.append( item );
258 int count = ids.size();
261 playlist_item_t *pp_items[count];
264 for( int i = 0; i < count; i++ )
266 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, ids[i] );
272 pp_items[i] = p_item;
274 playlist_item_t *p_parent =
275 playlist_ItemGetById( p_playlist, target->i_id );
276 playlist_TreeMoveMany( p_playlist, count, pp_items, p_parent,
280 insertChildren( target, model_items, model_pos );
284 /* remove item with its id */
285 void PLModel::removeItem( int i_id )
287 PLItem *item = findById( rootItem, i_id );
291 void PLModel::activateItem( const QModelIndex &index )
293 assert( index.isValid() );
294 PLItem *item = getItem( index );
297 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id );
298 activateItem( p_item );
302 /* Must be entered with lock */
303 void PLModel::activateItem( playlist_item_t *p_item )
305 if( !p_item ) return;
306 playlist_item_t *p_parent = p_item;
309 if( p_parent->i_id == rootItem->i_id ) break;
310 p_parent = p_parent->p_parent;
313 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, pl_Locked,
317 /****************** Base model mandatory implementations *****************/
318 QVariant PLModel::data( const QModelIndex &index, int role ) const
320 if( !index.isValid() ) return QVariant();
321 PLItem *item = getItem( index );
322 if( role == Qt::DisplayRole )
324 int metadata = columnToMeta( index.column() );
325 if( metadata == COLUMN_END ) return QVariant();
328 if( metadata == COLUMN_NUMBER )
329 returninfo = QString::number( index.row() + 1 );
332 char *psz = psz_column_meta( item->p_input, metadata );
333 returninfo = qfu( psz );
336 return QVariant( returninfo );
338 else if( role == Qt::DecorationRole && index.column() == 0 )
340 /* Use to segfault here because i_type wasn't always initialized */
341 if( item->p_input->i_type >= 0 )
342 return QVariant( PLModel::icons[item->p_input->i_type] );
344 else if( role == Qt::FontRole )
346 if( isCurrent( index ) )
348 QFont f; f.setBold( true ); return QVariant( f );
354 bool PLModel::isCurrent( const QModelIndex &index ) const
356 if( !currentItem ) return false;
357 return getItem( index )->p_input == currentItem->p_input;
360 int PLModel::itemId( const QModelIndex &index ) const
362 return getItem( index )->i_id;
365 QVariant PLModel::headerData( int section, Qt::Orientation orientation,
368 if (orientation != Qt::Horizontal || role != Qt::DisplayRole)
371 int meta_col = columnToMeta( section );
373 if( meta_col == COLUMN_END ) return QVariant();
375 return QVariant( qfu( psz_column_title( meta_col ) ) );
378 QModelIndex PLModel::index( int row, int column, const QModelIndex &parent )
381 PLItem *parentItem = parent.isValid() ? getItem( parent ) : rootItem;
383 PLItem *childItem = parentItem->child( row );
385 return createIndex( row, column, childItem );
387 return QModelIndex();
390 /* Return the index of a given item */
391 QModelIndex PLModel::index( PLItem *item, int column ) const
393 if( !item ) return QModelIndex();
394 const PLItem *parent = item->parent();
396 return createIndex( parent->children.lastIndexOf( item ),
398 return QModelIndex();
401 QModelIndex PLModel::parent( const QModelIndex &index ) const
403 if( !index.isValid() ) return QModelIndex();
405 PLItem *childItem = getItem( index );
408 msg_Err( p_playlist, "NULL CHILD" );
409 return QModelIndex();
412 PLItem *parentItem = childItem->parent();
413 if( !parentItem || parentItem == rootItem ) return QModelIndex();
414 if( !parentItem->parentItem )
416 msg_Err( p_playlist, "No parent parent, trying row 0 " );
417 msg_Err( p_playlist, "----- PLEASE REPORT THIS ------" );
418 return createIndex( 0, 0, parentItem );
420 QModelIndex ind = createIndex(parentItem->row(), 0, parentItem);
424 int PLModel::columnCount( const QModelIndex &i) const
426 return columnFromMeta( COLUMN_END );
429 int PLModel::rowCount( const QModelIndex &parent ) const
431 PLItem *parentItem = parent.isValid() ? getItem( parent ) : rootItem;
432 return parentItem->childCount();
435 QStringList PLModel::selectedURIs()
438 for( int i = 0; i < current_selection.size(); i++ )
440 PLItem *item = getItem( current_selection[i] );
444 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id );
447 char *psz = input_item_GetURI( p_item->p_input );
450 lst.append( qfu(psz) );
460 /************************* General playlist status ***********************/
462 bool PLModel::hasRandom()
464 return var_GetBool( p_playlist, "random" );
466 bool PLModel::hasRepeat()
468 return var_GetBool( p_playlist, "repeat" );
470 bool PLModel::hasLoop()
472 return var_GetBool( p_playlist, "loop" );
474 void PLModel::setLoop( bool on )
476 var_SetBool( p_playlist, "loop", on ? true:false );
477 config_PutInt( p_playlist, "loop", on ? 1: 0 );
479 void PLModel::setRepeat( bool on )
481 var_SetBool( p_playlist, "repeat", on ? true:false );
482 config_PutInt( p_playlist, "repeat", on ? 1: 0 );
484 void PLModel::setRandom( bool on )
486 var_SetBool( p_playlist, "random", on ? true:false );
487 config_PutInt( p_playlist, "random", on ? 1: 0 );
490 /************************* Lookups *****************************/
492 PLItem *PLModel::findById( PLItem *root, int i_id )
494 return findInner( root, i_id, false );
497 PLItem *PLModel::findByInput( PLItem *root, int i_id )
499 PLItem *result = findInner( root, i_id, true );
503 #define CACHE( i, p ) { i_cached_id = i; p_cached_item = p; }
504 #define ICACHE( i, p ) { i_cached_input_id = i; p_cached_item_bi = p; }
506 PLItem * PLModel::findInner( PLItem *root, int i_id, bool b_input )
508 if( !root ) return NULL;
509 if( ( !b_input && i_cached_id == i_id) ||
510 ( b_input && i_cached_input_id ==i_id ) )
512 return b_input ? p_cached_item_bi : p_cached_item;
515 if( !b_input && root->i_id == i_id )
520 else if( b_input && root->p_input->i_id == i_id )
522 ICACHE( i_id, root );
526 QList<PLItem *>::iterator it = root->children.begin();
527 while ( it != root->children.end() )
529 if( !b_input && (*it)->i_id == i_id )
531 CACHE( i_id, (*it) );
532 return p_cached_item;
534 else if( b_input && (*it)->p_input->i_id == i_id )
536 ICACHE( i_id, (*it) );
537 return p_cached_item_bi;
539 if( (*it)->children.size() )
541 PLItem *childFound = findInner( (*it), i_id, b_input );
545 ICACHE( i_id, childFound )
547 CACHE( i_id, childFound )
558 PLItem *PLModel::getItem( QModelIndex index )
560 assert( index.isValid() );
561 return static_cast<PLItem*>( index.internalPointer() );
564 int PLModel::columnToMeta( int _column ) const
569 while( column != _column && meta != COLUMN_END )
578 int PLModel::columnFromMeta( int meta_col ) const
583 while( meta != meta_col && meta != COLUMN_END )
592 bool PLModel::canEdit() const
597 rootItem->p_input == p_playlist->p_local_category->p_input ||
599 p_playlist->p_ml_category &&
600 rootItem->p_input == p_playlist->p_ml_category->p_input
605 /************************* Updates handling *****************************/
607 /**** Events processing ****/
608 void PLModel::processInputItemUpdate( input_thread_t *p_input )
610 if( !p_input ) return;
611 processInputItemUpdate( input_GetItem( p_input ) );
612 if( p_input && !( p_input->b_dead || !vlc_object_alive( p_input ) ) )
614 PLItem *item = findByInput( rootItem, input_GetItem( p_input )->i_id );
616 emit currentChanged( index( item, 0 ) );
623 void PLModel::processInputItemUpdate( input_item_t *p_item )
625 if( !p_item || p_item->i_id <= 0 ) return;
626 PLItem *item = findByInput( rootItem, p_item->i_id );
628 updateTreeItem( item );
631 void PLModel::processItemRemoval( int i_id )
633 if( i_id <= 0 ) return;
637 void PLModel::processItemAppend( int i_item, int i_parent )
639 playlist_item_t *p_item = NULL;
640 PLItem *newItem = NULL;
642 PLItem *nodeItem = findById( rootItem, i_parent );
643 if( !nodeItem ) return;
645 foreach( PLItem *existing, nodeItem->children )
646 if( existing->i_id == i_item ) return;
649 p_item = playlist_ItemGetById( p_playlist, i_item );
650 if( !p_item || p_item->i_flags & PLAYLIST_DBL_FLAG ) goto end;
652 newItem = new PLItem( p_item, nodeItem );
655 beginInsertRows( index( nodeItem, 0 ), nodeItem->childCount(), nodeItem->childCount() );
656 nodeItem->appendChild( newItem );
658 updateTreeItem( newItem );
666 void PLModel::rebuild()
668 rebuild( NULL, false );
671 void PLModel::rebuild( playlist_item_t *p_root, bool b_first )
673 playlist_item_t* p_item;
675 /* Invalidate cache */
676 i_cached_id = i_cached_input_id = -1;
678 if( rootItem ) rootItem->removeChildren();
684 rootItem = new PLItem( p_root );
687 /* Recreate from root */
688 updateChildren( rootItem );
689 if( (p_item = playlist_CurrentPlayingItem(p_playlist)) )
690 currentItem = findByInput( rootItem, p_item->p_input->i_id );
695 /* And signal the view */
698 emit currentChanged( index( currentItem, 0 ) );
701 void PLModel::takeItem( PLItem *item )
704 PLItem *parent = item->parentItem;
706 int i_index = parent->children.indexOf( item );
708 beginRemoveRows( index( parent, 0 ), i_index, i_index );
709 parent->takeChildAt( i_index );
713 void PLModel::insertChildren( PLItem *node, QList<PLItem*>& items, int i_pos )
716 int count = items.size();
718 beginInsertRows( index( node, 0 ), i_pos, i_pos + count - 1 );
719 for( int i = 0; i < count; i++ )
721 node->children.insert( i_pos + i, items[i] );
722 items[i]->parentItem = node;
727 void PLModel::removeItem( PLItem *item )
731 if( item->i_id == i_cached_id ) i_cached_id = -1;
732 i_cached_input_id = -1;
734 if( currentItem == item || rootItem == item)
737 emit currentChanged( QModelIndex() );
743 if( item->parentItem ) {
744 int i = item->parentItem->children.indexOf( item );
745 beginRemoveRows( index( item->parentItem, 0), i, i );
746 item->parentItem->children.removeAt(i);
754 /* This function must be entered WITH the playlist lock */
755 void PLModel::updateChildren( PLItem *root )
757 playlist_item_t *p_node = playlist_ItemGetById( p_playlist, root->i_id );
758 updateChildren( p_node, root );
761 /* This function must be entered WITH the playlist lock */
762 void PLModel::updateChildren( playlist_item_t *p_node, PLItem *root )
764 playlist_item_t *p_item = playlist_CurrentPlayingItem(p_playlist);
765 for( int i = 0; i < p_node->i_children ; i++ )
767 if( p_node->pp_children[i]->i_flags & PLAYLIST_DBL_FLAG ) continue;
768 PLItem *newItem = new PLItem( p_node->pp_children[i], root );
769 root->appendChild( newItem );
770 if( p_item && newItem->p_input == p_item->p_input )
772 currentItem = newItem;
773 emit currentChanged( index( currentItem, 0 ) );
775 if( p_node->pp_children[i]->i_children != -1 )
776 updateChildren( p_node->pp_children[i], newItem );
780 /* Function doesn't need playlist-lock, as we don't touch playlist_item_t stuff here*/
781 void PLModel::updateTreeItem( PLItem *item )
784 emit dataChanged( index( item, 0 ) , index( item, columnCount( QModelIndex() ) ) );
787 /************************* Actions ******************************/
790 * Deletion, here we have to do a ugly slow hack as we retrieve the full
791 * list of indexes to delete at once: when we delete a node and all of
792 * its children, we need to update the list.
793 * Todo: investigate whethere we can use ranges to be sure to delete all items?
795 void PLModel::doDelete( QModelIndexList selected )
797 if( !canEdit() ) return;
799 for( int i = selected.size() -1 ; i >= 0; i-- )
801 QModelIndex index = selected[i];
802 if( index.column() != 0 ) continue;
803 PLItem *item = getItem( index );
806 if( item->children.size() )
807 recurseDelete( item->children, &selected );
808 doDeleteItem( item, &selected );
810 if( i > selected.size() ) i = selected.size();
814 void PLModel::recurseDelete( QList<PLItem*> children, QModelIndexList *fullList )
816 for( int i = children.size() - 1; i >= 0 ; i-- )
818 PLItem *item = children[i];
819 if( item->children.size() )
820 recurseDelete( item->children, fullList );
821 doDeleteItem( item, fullList );
825 void PLModel::doDeleteItem( PLItem *item, QModelIndexList *fullList )
827 QModelIndex deleteIndex = index( item, 0 );
828 fullList->removeAll( deleteIndex );
831 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id );
837 if( p_item->i_children == -1 )
838 playlist_DeleteFromInput( p_playlist, p_item->p_input, pl_Locked );
840 playlist_NodeDelete( p_playlist, p_item, true, false );
843 /* And finally, remove it from the tree */
847 /******* Volume III: Sorting and searching ********/
848 void PLModel::sort( int column, Qt::SortOrder order )
850 sort( rootItem->i_id, column, order );
853 void PLModel::sort( int i_root_id, int column, Qt::SortOrder order )
855 int meta = columnToMeta( column );
856 if( meta == COLUMN_END ) return;
858 PLItem *item = findById( rootItem, i_root_id );
860 QModelIndex qIndex = index( item, 0 );
861 int count = item->children.size();
864 beginRemoveRows( qIndex, 0, count - 1 );
865 item->removeChildren();
871 playlist_item_t *p_root = playlist_ItemGetById( p_playlist,
875 playlist_RecursiveNodeSort( p_playlist, p_root,
876 i_column_sorting( meta ),
877 order == Qt::AscendingOrder ?
878 ORDER_NORMAL : ORDER_REVERSE );
883 beginInsertRows( qIndex, 0, count - 1 );
884 updateChildren( item );
890 void PLModel::search( const QString& search_text )
892 /** \todo Fire the search with a small delay ? */
895 playlist_item_t *p_root = playlist_ItemGetById( p_playlist,
898 const char *psz_name = search_text.toUtf8().data();
899 playlist_LiveSearchUpdate( p_playlist , p_root, psz_name );
905 /*********** Popup *********/
906 void PLModel::popup( QModelIndex & index, QPoint &point, QModelIndexList list )
908 int i_id = index.isValid() ? itemId( index ) : rootItem->i_id;
911 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, i_id );
916 i_popup_item = index.isValid() ? p_item->i_id : -1;
917 i_popup_parent = index.isValid() ?
918 ( p_item->p_parent ? p_item->p_parent->i_id : -1 ) :
920 i_popup_column = index.column();
921 /* check whether we are in tree view */
923 playlist_item_t *p_up = p_item;
926 if ( p_up == p_playlist->p_root_category ) tree = true;
927 p_up = p_up->p_parent;
931 current_selection = list;
934 if( i_popup_item > -1 )
936 menu.addAction( qtr(I_POP_PLAY), this, SLOT( popupPlay() ) );
937 menu.addAction( qtr(I_POP_DEL), this, SLOT( popupDel() ) );
939 menu.addAction( qtr(I_POP_STREAM), this, SLOT( popupStream() ) );
940 menu.addAction( qtr(I_POP_SAVE), this, SLOT( popupSave() ) );
942 menu.addAction( qtr(I_POP_INFO), this, SLOT( popupInfo() ) );
944 QMenu *sort_menu = menu.addMenu( qtr( "Sort by ") +
945 qfu( psz_column_title( columnToMeta( index.column() ) ) ) );
946 sort_menu->addAction( qtr( "Ascending" ),
947 this, SLOT( popupSortAsc() ) );
948 sort_menu->addAction( qtr( "Descending" ),
949 this, SLOT( popupSortDesc() ) );
951 if( tree && canEdit() )
952 menu.addAction( qtr(I_POP_ADD), this, SLOT( popupAddNode() ) );
953 if( i_popup_item > -1 )
956 menu.addAction( qtr( I_POP_EXPLORE ), this, SLOT( popupExplore() ) );
958 if( !menu.isEmpty() ) menu.exec( point );
961 void PLModel::popupDel()
963 doDelete( current_selection );
966 void PLModel::popupPlay()
970 playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
972 activateItem( p_item );
977 void PLModel::popupInfo()
980 playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
984 input_item_t* p_input = p_item->p_input;
985 vlc_gc_incref( p_input );
987 MediaInfoDialog *mid = new MediaInfoDialog( p_intf, p_input );
988 vlc_gc_decref( p_input );
989 mid->setParent( PlaylistDialog::getInstance( p_intf ),
996 void PLModel::popupStream()
998 QStringList mrls = selectedURIs();
999 if( !mrls.isEmpty() )
1000 THEDP->streamingDialog( NULL, mrls[0], false );
1004 void PLModel::popupSave()
1006 QStringList mrls = selectedURIs();
1007 if( !mrls.isEmpty() )
1008 THEDP->streamingDialog( NULL, mrls[0] );
1012 #include <QFileInfo>
1013 #include <QDesktopServices>
1014 void PLModel::popupExplore()
1017 playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
1021 input_item_t *p_input = p_item->p_input;
1022 char *psz_meta = input_item_GetURI( p_input );
1026 const char *psz_access;
1027 const char *psz_demux;
1029 input_SplitMRL( &psz_access, &psz_demux, &psz_path, psz_meta );
1031 if( EMPTY_STR( psz_access ) ||
1032 !strncasecmp( psz_access, "file", 4 ) ||
1033 !strncasecmp( psz_access, "dire", 4 ) )
1035 QFileInfo info( qfu( psz_meta ) );
1036 QDesktopServices::openUrl(
1037 QUrl::fromLocalFile( info.absolutePath() ) );
1046 #include <QInputDialog>
1047 void PLModel::popupAddNode()
1050 QString name = QInputDialog::getText( PlaylistDialog::getInstance( p_intf ),
1051 qtr( I_POP_ADD ), qtr( "Enter name for new node:" ),
1052 QLineEdit::Normal, QString(), &ok);
1053 if( !ok || name.isEmpty() ) return;
1055 playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
1059 playlist_NodeCreate( p_playlist, qtu( name ), p_item, 0, NULL );
1064 void PLModel::popupSortAsc()
1066 sort( i_popup_parent, i_popup_column, Qt::AscendingOrder );
1069 void PLModel::popupSortDesc()
1071 sort( i_popup_parent, i_popup_column, Qt::DescendingOrder );