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( 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" );
93 rebuild( p_root, true );
94 CONNECT( THEMIM->getIM(), metaChanged( input_item_t *),
95 this, processInputItemUpdate( input_item_t *) );
96 CONNECT( THEMIM, inputChanged( input_thread_t * ),
97 this, processInputItemUpdate( input_thread_t* ) );
106 Qt::DropActions PLModel::supportedDropActions() const
108 return Qt::CopyAction; /* Why not Qt::MoveAction */
111 Qt::ItemFlags PLModel::flags( const QModelIndex &index ) const
113 Qt::ItemFlags flags = QAbstractItemModel::flags( index );
115 PLItem *item = index.isValid() ? getItem( index ) : rootItem;
120 playlist_item_t *plItem =
121 playlist_ItemGetById( p_playlist, item->i_id );
123 if ( plItem && ( plItem->i_children > -1 ) )
124 flags |= Qt::ItemIsDropEnabled;
129 flags |= Qt::ItemIsDragEnabled;
134 QStringList PLModel::mimeTypes() const
137 types << "vlc/qt-playlist-item";
141 QMimeData *PLModel::mimeData( const QModelIndexList &indexes ) const
143 QMimeData *mimeData = new QMimeData();
144 QByteArray encodedData;
145 QDataStream stream( &encodedData, QIODevice::WriteOnly );
146 QModelIndexList list;
148 foreach( const QModelIndex &index, indexes ) {
149 if( index.isValid() && index.column() == 0 )
155 foreach( const QModelIndex &index, list ) {
156 PLItem *item = getItem( index );
157 stream.writeRawData( (char*) &item, sizeof( PLItem* ) );
159 mimeData->setData( "vlc/qt-playlist-item", encodedData );
164 bool PLModel::dropMimeData( const QMimeData *data, Qt::DropAction action,
165 int row, int column, const QModelIndex &parent )
167 if( data->hasFormat( "vlc/qt-playlist-item" ) )
169 if( action == Qt::IgnoreAction )
172 PLItem *parentItem = parent.isValid() ? getItem( parent ) : rootItem;
175 playlist_item_t *p_parent =
176 playlist_ItemGetById( p_playlist, parentItem->i_id );
177 if( !p_parent || p_parent->i_children == -1 )
184 playlist_item_t *p_pl = p_playlist->p_local_category;
185 playlist_item_t *p_ml = p_playlist->p_ml_category;
189 ( p_pl && p_parent->p_input == p_pl->p_input ) ||
190 ( p_ml && p_parent->p_input == p_ml->p_input ) )
195 QByteArray encodedData = data->data( "vlc/qt-playlist-item" );
197 dropAppendCopy( encodedData, parentItem );
199 dropMove( encodedData, parentItem, row );
204 void PLModel::dropAppendCopy( QByteArray& data, PLItem *target )
206 QDataStream stream( &data, QIODevice::ReadOnly );
209 playlist_item_t *p_parent =
210 playlist_ItemGetById( p_playlist, target->i_id );
211 while( !stream.atEnd() )
214 stream.readRawData( (char*)&item, sizeof(PLItem*) );
215 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id );
216 if( !p_item ) continue;
217 input_item_t *p_input = p_item->p_input;
218 playlist_AddExt ( p_playlist,
219 p_input->psz_uri, p_input->psz_name,
220 PLAYLIST_APPEND | PLAYLIST_SPREPARSE, PLAYLIST_END,
222 p_input->i_options, p_input->ppsz_options, p_input->optflagc,
223 ( p_parent == p_playlist->p_local_category ||
224 p_parent == p_playlist->p_local_onelevel ),
230 void PLModel::dropMove( QByteArray& data, PLItem *target, int row )
232 QDataStream stream( &data, QIODevice::ReadOnly );
233 QList<PLItem*> model_items;
235 int new_pos = row == -1 ? target->children.size() : row;
236 int model_pos = new_pos;
237 while( !stream.atEnd() )
240 stream.readRawData( (char*)&item, sizeof(PLItem*) );
242 /* better not try to move a node into itself: */
243 PLItem *climber = target;
246 if( climber == item ) break;
247 climber = climber->parentItem;
249 if( climber ) continue;
251 if( item->parentItem == target &&
252 target->children.indexOf( item ) < model_pos )
255 ids.append( item->i_id );
256 model_items.append( item );
260 int count = ids.size();
263 playlist_item_t *pp_items[count];
266 for( int i = 0; i < count; i++ )
268 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, ids[i] );
274 pp_items[i] = p_item;
276 playlist_item_t *p_parent =
277 playlist_ItemGetById( p_playlist, target->i_id );
278 playlist_TreeMoveMany( p_playlist, count, pp_items, p_parent,
282 insertChildren( target, model_items, model_pos );
286 /* remove item with its id */
287 void PLModel::removeItem( int i_id )
289 PLItem *item = findById( rootItem, i_id );
293 /* callbacks and slots */
294 void PLModel::addCallbacks()
296 /* One item has been updated */
297 var_AddCallback( p_playlist, "playlist-item-append", ItemAppended, this );
298 var_AddCallback( p_playlist, "playlist-item-deleted", ItemDeleted, this );
301 void PLModel::delCallbacks()
303 var_DelCallback( p_playlist, "playlist-item-append", ItemAppended, this );
304 var_DelCallback( p_playlist, "playlist-item-deleted", ItemDeleted, this );
307 void PLModel::activateItem( const QModelIndex &index )
309 assert( index.isValid() );
310 PLItem *item = getItem( index );
313 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id );
314 activateItem( p_item );
318 /* Must be entered with lock */
319 void PLModel::activateItem( playlist_item_t *p_item )
321 if( !p_item ) return;
322 playlist_item_t *p_parent = p_item;
325 if( p_parent->i_id == rootItem->i_id ) break;
326 p_parent = p_parent->p_parent;
329 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, pl_Locked,
333 /****************** Base model mandatory implementations *****************/
334 QVariant PLModel::data( const QModelIndex &index, int role ) const
336 if( !index.isValid() ) return QVariant();
337 PLItem *item = getItem( index );
338 if( role == Qt::DisplayRole )
340 int metadata = columnToMeta( index.column() );
341 if( metadata == COLUMN_END ) return QVariant();
344 if( metadata == COLUMN_NUMBER )
345 returninfo = QString::number( index.row() + 1 );
348 char *psz = psz_column_meta( item->p_input, metadata );
349 returninfo = qfu( psz );
352 return QVariant( returninfo );
354 else if( role == Qt::DecorationRole && index.column() == 0 )
356 /* Use to segfault here because i_type wasn't always initialized */
357 if( item->p_input->i_type >= 0 )
358 return QVariant( PLModel::icons[item->p_input->i_type] );
360 else if( role == Qt::FontRole )
362 if( isCurrent( index ) )
364 QFont f; f.setBold( true ); return QVariant( f );
370 bool PLModel::isCurrent( const QModelIndex &index ) const
372 if( !currentItem ) return false;
373 return getItem( index )->p_input == currentItem->p_input;
376 int PLModel::itemId( const QModelIndex &index ) const
378 return getItem( index )->i_id;
381 QVariant PLModel::headerData( int section, Qt::Orientation orientation,
384 if (orientation != Qt::Horizontal || role != Qt::DisplayRole)
387 int meta_col = columnToMeta( section );
389 if( meta_col == COLUMN_END ) return QVariant();
391 return QVariant( qfu( psz_column_title( meta_col ) ) );
394 QModelIndex PLModel::index( int row, int column, const QModelIndex &parent )
397 PLItem *parentItem = parent.isValid() ? getItem( parent ) : rootItem;
399 PLItem *childItem = parentItem->child( row );
401 return createIndex( row, column, childItem );
403 return QModelIndex();
406 /* Return the index of a given item */
407 QModelIndex PLModel::index( PLItem *item, int column ) const
409 if( !item ) return QModelIndex();
410 const PLItem *parent = item->parent();
412 return createIndex( parent->children.lastIndexOf( item ),
414 return QModelIndex();
417 QModelIndex PLModel::parent( const QModelIndex &index ) const
419 if( !index.isValid() ) return QModelIndex();
421 PLItem *childItem = getItem( index );
424 msg_Err( p_playlist, "NULL CHILD" );
425 return QModelIndex();
428 PLItem *parentItem = childItem->parent();
429 if( !parentItem || parentItem == rootItem ) return QModelIndex();
430 if( !parentItem->parentItem )
432 msg_Err( p_playlist, "No parent parent, trying row 0 " );
433 msg_Err( p_playlist, "----- PLEASE REPORT THIS ------" );
434 return createIndex( 0, 0, parentItem );
436 QModelIndex ind = createIndex(parentItem->row(), 0, parentItem);
440 int PLModel::columnCount( const QModelIndex &i) const
442 return columnFromMeta( COLUMN_END );
445 int PLModel::rowCount( const QModelIndex &parent ) const
447 PLItem *parentItem = parent.isValid() ? getItem( parent ) : rootItem;
448 return parentItem->childCount();
451 QStringList PLModel::selectedURIs()
454 for( int i = 0; i < current_selection.size(); i++ )
456 PLItem *item = getItem( current_selection[i] );
460 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id );
463 char *psz = input_item_GetURI( p_item->p_input );
466 lst.append( qfu(psz) );
476 /************************* General playlist status ***********************/
478 bool PLModel::hasRandom()
480 return var_GetBool( p_playlist, "random" );
482 bool PLModel::hasRepeat()
484 return var_GetBool( p_playlist, "repeat" );
486 bool PLModel::hasLoop()
488 return var_GetBool( p_playlist, "loop" );
490 void PLModel::setLoop( bool on )
492 var_SetBool( p_playlist, "loop", on ? true:false );
493 config_PutInt( p_playlist, "loop", on ? 1: 0 );
495 void PLModel::setRepeat( bool on )
497 var_SetBool( p_playlist, "repeat", on ? true:false );
498 config_PutInt( p_playlist, "repeat", on ? 1: 0 );
500 void PLModel::setRandom( bool on )
502 var_SetBool( p_playlist, "random", on ? true:false );
503 config_PutInt( p_playlist, "random", on ? 1: 0 );
506 /************************* Lookups *****************************/
508 PLItem *PLModel::findById( PLItem *root, int i_id )
510 return findInner( root, i_id, false );
513 PLItem *PLModel::findByInput( PLItem *root, int i_id )
515 PLItem *result = findInner( root, i_id, true );
519 #define CACHE( i, p ) { i_cached_id = i; p_cached_item = p; }
520 #define ICACHE( i, p ) { i_cached_input_id = i; p_cached_item_bi = p; }
522 PLItem * PLModel::findInner( PLItem *root, int i_id, bool b_input )
524 if( !root ) return NULL;
525 if( ( !b_input && i_cached_id == i_id) ||
526 ( b_input && i_cached_input_id ==i_id ) )
528 return b_input ? p_cached_item_bi : p_cached_item;
531 if( !b_input && root->i_id == i_id )
536 else if( b_input && root->p_input->i_id == i_id )
538 ICACHE( i_id, root );
542 QList<PLItem *>::iterator it = root->children.begin();
543 while ( it != root->children.end() )
545 if( !b_input && (*it)->i_id == i_id )
547 CACHE( i_id, (*it) );
548 return p_cached_item;
550 else if( b_input && (*it)->p_input->i_id == i_id )
552 ICACHE( i_id, (*it) );
553 return p_cached_item_bi;
555 if( (*it)->children.size() )
557 PLItem *childFound = findInner( (*it), i_id, b_input );
561 ICACHE( i_id, childFound )
563 CACHE( i_id, childFound )
574 PLItem *PLModel::getItem( QModelIndex index )
576 assert( index.isValid() );
577 return static_cast<PLItem*>( index.internalPointer() );
580 int PLModel::columnToMeta( int _column ) const
585 while( column != _column && meta != COLUMN_END )
594 int PLModel::columnFromMeta( int meta_col ) const
599 while( meta != meta_col && meta != COLUMN_END )
608 bool PLModel::canEdit() const
613 rootItem->p_input == p_playlist->p_local_category->p_input ||
615 p_playlist->p_ml_category &&
616 rootItem->p_input == p_playlist->p_ml_category->p_input
621 /************************* Updates handling *****************************/
622 void PLModel::customEvent( QEvent *event )
624 int type = event->type();
625 if( type != ItemAppend_Type &&
626 type != ItemDelete_Type )
629 PLEvent *ple = static_cast<PLEvent *>(event);
631 if( type == ItemAppend_Type )
632 processItemAppend( &ple->add );
633 else if( type == ItemDelete_Type )
634 processItemRemoval( ple->i_id );
637 /**** Events processing ****/
638 void PLModel::processInputItemUpdate( input_thread_t *p_input )
640 if( !p_input ) return;
641 processInputItemUpdate( input_GetItem( p_input ) );
642 if( p_input && !( p_input->b_dead || !vlc_object_alive( p_input ) ) )
644 PLItem *item = findByInput( rootItem, input_GetItem( p_input )->i_id );
646 emit currentChanged( index( item, 0 ) );
653 void PLModel::processInputItemUpdate( input_item_t *p_item )
655 if( !p_item || p_item->i_id <= 0 ) return;
656 PLItem *item = findByInput( rootItem, p_item->i_id );
658 updateTreeItem( item );
661 void PLModel::processItemRemoval( int i_id )
663 if( i_id <= 0 ) return;
667 void PLModel::processItemAppend( const playlist_add_t *p_add )
669 playlist_item_t *p_item = NULL;
670 PLItem *newItem = NULL;
672 PLItem *nodeItem = findById( rootItem, p_add->i_node );
673 if( !nodeItem ) return;
675 foreach( PLItem *existing, nodeItem->children )
676 if( existing->i_id == p_add->i_item ) return;
679 p_item = playlist_ItemGetById( p_playlist, p_add->i_item );
680 if( !p_item || p_item->i_flags & PLAYLIST_DBL_FLAG ) goto end;
682 newItem = new PLItem( p_item, nodeItem );
685 beginInsertRows( index( nodeItem, 0 ), nodeItem->childCount(), nodeItem->childCount() );
686 nodeItem->appendChild( newItem );
688 updateTreeItem( newItem );
696 void PLModel::rebuild()
698 rebuild( NULL, false );
701 void PLModel::rebuild( playlist_item_t *p_root, bool b_first )
703 playlist_item_t* p_item;
705 /* Invalidate cache */
706 i_cached_id = i_cached_input_id = -1;
708 if( rootItem ) rootItem->removeChildren();
714 rootItem = new PLItem( p_root );
717 /* Recreate from root */
718 updateChildren( rootItem );
719 if( (p_item = playlist_CurrentPlayingItem(p_playlist)) )
720 currentItem = findByInput( rootItem, p_item->p_input->i_id );
725 /* And signal the view */
728 emit currentChanged( index( currentItem, 0 ) );
731 void PLModel::takeItem( PLItem *item )
734 PLItem *parent = item->parentItem;
736 int i_index = parent->children.indexOf( item );
738 beginRemoveRows( index( parent, 0 ), i_index, i_index );
739 parent->takeChildAt( i_index );
743 void PLModel::insertChildren( PLItem *node, QList<PLItem*>& items, int i_pos )
746 int count = items.size();
748 beginInsertRows( index( node, 0 ), i_pos, i_pos + count - 1 );
749 for( int i = 0; i < count; i++ )
751 node->children.insert( i_pos + i, items[i] );
752 items[i]->parentItem = node;
757 void PLModel::removeItem( PLItem *item )
761 if( item->i_id == i_cached_id ) i_cached_id = -1;
762 i_cached_input_id = -1;
764 if( currentItem == item || rootItem == item)
767 emit currentChanged( QModelIndex() );
773 if( item->parentItem ) {
774 int i = item->parentItem->children.indexOf( item );
775 beginRemoveRows( index( item->parentItem, 0), i, i );
776 item->parentItem->children.removeAt(i);
784 /* This function must be entered WITH the playlist lock */
785 void PLModel::updateChildren( PLItem *root )
787 playlist_item_t *p_node = playlist_ItemGetById( p_playlist, root->i_id );
788 updateChildren( p_node, root );
791 /* This function must be entered WITH the playlist lock */
792 void PLModel::updateChildren( playlist_item_t *p_node, PLItem *root )
794 playlist_item_t *p_item = playlist_CurrentPlayingItem(p_playlist);
795 for( int i = 0; i < p_node->i_children ; i++ )
797 if( p_node->pp_children[i]->i_flags & PLAYLIST_DBL_FLAG ) continue;
798 PLItem *newItem = new PLItem( p_node->pp_children[i], root );
799 root->appendChild( newItem );
800 if( p_item && newItem->p_input == p_item->p_input )
802 currentItem = newItem;
803 emit currentChanged( index( currentItem, 0 ) );
805 if( p_node->pp_children[i]->i_children != -1 )
806 updateChildren( p_node->pp_children[i], newItem );
810 /* Function doesn't need playlist-lock, as we don't touch playlist_item_t stuff here*/
811 void PLModel::updateTreeItem( PLItem *item )
814 emit dataChanged( index( item, 0 ) , index( item, columnCount( QModelIndex() ) ) );
817 /************************* Actions ******************************/
820 * Deletion, here we have to do a ugly slow hack as we retrieve the full
821 * list of indexes to delete at once: when we delete a node and all of
822 * its children, we need to update the list.
823 * Todo: investigate whethere we can use ranges to be sure to delete all items?
825 void PLModel::doDelete( QModelIndexList selected )
827 if( !canEdit() ) return;
829 for( int i = selected.size() -1 ; i >= 0; i-- )
831 QModelIndex index = selected[i];
832 if( index.column() != 0 ) continue;
833 PLItem *item = getItem( index );
836 if( item->children.size() )
837 recurseDelete( item->children, &selected );
838 doDeleteItem( item, &selected );
840 if( i > selected.size() ) i = selected.size();
844 void PLModel::recurseDelete( QList<PLItem*> children, QModelIndexList *fullList )
846 for( int i = children.size() - 1; i >= 0 ; i-- )
848 PLItem *item = children[i];
849 if( item->children.size() )
850 recurseDelete( item->children, fullList );
851 doDeleteItem( item, fullList );
855 void PLModel::doDeleteItem( PLItem *item, QModelIndexList *fullList )
857 QModelIndex deleteIndex = index( item, 0 );
858 fullList->removeAll( deleteIndex );
861 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id );
867 if( p_item->i_children == -1 )
868 playlist_DeleteFromInput( p_playlist, p_item->p_input, pl_Locked );
870 playlist_NodeDelete( p_playlist, p_item, true, false );
873 /* And finally, remove it from the tree */
877 /******* Volume III: Sorting and searching ********/
878 void PLModel::sort( int column, Qt::SortOrder order )
880 sort( rootItem->i_id, column, order );
883 void PLModel::sort( int i_root_id, int column, Qt::SortOrder order )
885 int meta = columnToMeta( column );
886 if( meta == COLUMN_END ) return;
888 PLItem *item = findById( rootItem, i_root_id );
890 QModelIndex qIndex = index( item, 0 );
891 int count = item->children.size();
894 beginRemoveRows( qIndex, 0, count - 1 );
895 item->removeChildren();
901 playlist_item_t *p_root = playlist_ItemGetById( p_playlist,
905 playlist_RecursiveNodeSort( p_playlist, p_root,
906 i_column_sorting( meta ),
907 order == Qt::AscendingOrder ?
908 ORDER_NORMAL : ORDER_REVERSE );
913 beginInsertRows( qIndex, 0, count - 1 );
914 updateChildren( item );
920 void PLModel::search( const QString& search_text )
922 /** \todo Fire the search with a small delay ? */
925 playlist_item_t *p_root = playlist_ItemGetById( p_playlist,
928 const char *psz_name = search_text.toUtf8().data();
929 playlist_LiveSearchUpdate( p_playlist , p_root, psz_name );
935 /*********** Popup *********/
936 void PLModel::popup( QModelIndex & index, QPoint &point, QModelIndexList list )
938 int i_id = index.isValid() ? itemId( index ) : rootItem->i_id;
941 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, i_id );
946 i_popup_item = index.isValid() ? p_item->i_id : -1;
947 i_popup_parent = index.isValid() ?
948 ( p_item->p_parent ? p_item->p_parent->i_id : -1 ) :
950 i_popup_column = index.column();
951 /* check whether we are in tree view */
953 playlist_item_t *p_up = p_item;
956 if ( p_up == p_playlist->p_root_category ) tree = true;
957 p_up = p_up->p_parent;
961 current_selection = list;
964 if( i_popup_item > -1 )
966 menu.addAction( qtr(I_POP_PLAY), this, SLOT( popupPlay() ) );
967 menu.addAction( qtr(I_POP_DEL), this, SLOT( popupDel() ) );
969 menu.addAction( qtr(I_POP_STREAM), this, SLOT( popupStream() ) );
970 menu.addAction( qtr(I_POP_SAVE), this, SLOT( popupSave() ) );
972 menu.addAction( qtr(I_POP_INFO), this, SLOT( popupInfo() ) );
974 QMenu *sort_menu = menu.addMenu( qtr( "Sort by ") +
975 qfu( psz_column_title( columnToMeta( index.column() ) ) ) );
976 sort_menu->addAction( qtr( "Ascending" ),
977 this, SLOT( popupSortAsc() ) );
978 sort_menu->addAction( qtr( "Descending" ),
979 this, SLOT( popupSortDesc() ) );
981 if( tree && canEdit() )
982 menu.addAction( qtr(I_POP_ADD), this, SLOT( popupAddNode() ) );
983 if( i_popup_item > -1 )
986 menu.addAction( qtr( I_POP_EXPLORE ), this, SLOT( popupExplore() ) );
988 if( !menu.isEmpty() ) menu.exec( point );
991 void PLModel::popupDel()
993 doDelete( current_selection );
996 void PLModel::popupPlay()
1000 playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
1002 activateItem( p_item );
1007 void PLModel::popupInfo()
1010 playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
1014 input_item_t* p_input = p_item->p_input;
1015 vlc_gc_incref( p_input );
1017 MediaInfoDialog *mid = new MediaInfoDialog( p_intf, p_input );
1018 vlc_gc_decref( p_input );
1019 mid->setParent( PlaylistDialog::getInstance( p_intf ),
1026 void PLModel::popupStream()
1028 QStringList mrls = selectedURIs();
1029 if( !mrls.isEmpty() )
1030 THEDP->streamingDialog( NULL, mrls[0], false );
1034 void PLModel::popupSave()
1036 QStringList mrls = selectedURIs();
1037 if( !mrls.isEmpty() )
1038 THEDP->streamingDialog( NULL, mrls[0] );
1042 #include <QFileInfo>
1043 #include <QDesktopServices>
1044 void PLModel::popupExplore()
1047 playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
1051 input_item_t *p_input = p_item->p_input;
1052 char *psz_meta = input_item_GetURI( p_input );
1056 const char *psz_access;
1057 const char *psz_demux;
1059 input_SplitMRL( &psz_access, &psz_demux, &psz_path, psz_meta );
1061 if( EMPTY_STR( psz_access ) ||
1062 !strncasecmp( psz_access, "file", 4 ) ||
1063 !strncasecmp( psz_access, "dire", 4 ) )
1065 QFileInfo info( qfu( psz_meta ) );
1066 QDesktopServices::openUrl(
1067 QUrl::fromLocalFile( info.absolutePath() ) );
1076 #include <QInputDialog>
1077 void PLModel::popupAddNode()
1080 QString name = QInputDialog::getText( PlaylistDialog::getInstance( p_intf ),
1081 qtr( I_POP_ADD ), qtr( "Enter name for new node:" ),
1082 QLineEdit::Normal, QString(), &ok);
1083 if( !ok || name.isEmpty() ) return;
1085 playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
1089 playlist_NodeCreate( p_playlist, qtu( name ), p_item, 0, NULL );
1094 void PLModel::popupSortAsc()
1096 sort( i_popup_parent, i_popup_column, Qt::AscendingOrder );
1099 void PLModel::popupSortDesc()
1101 sort( i_popup_parent, i_popup_column, Qt::DescendingOrder );
1103 /**********************************************************************
1104 * Playlist callbacks
1105 **********************************************************************/
1107 static int ItemDeleted( 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 PLEvent *event = new PLEvent( ItemDelete_Type, nval.i_int );
1112 QApplication::postEvent( p_model, event );
1116 static int ItemAppended( vlc_object_t *p_this, const char *psz_variable,
1117 vlc_value_t oval, vlc_value_t nval, void *param )
1119 PLModel *p_model = (PLModel *) param;
1120 const playlist_add_t *p_add = (playlist_add_t *)nval.p_address;
1121 PLEvent *event = new PLEvent( p_add );
1122 QApplication::postEvent( p_model, event );