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>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
30 #include "dialogs_provider.hpp"
31 #include "components/playlist/playlist_model.hpp"
32 #include "dialogs/mediainfo.hpp"
33 #include "dialogs/playlist.hpp"
34 #include <vlc_intf_strings.h>
36 #include "pixmaps/types/type_unknown.xpm"
42 #include <QApplication>
47 QIcon PLModel::icons[ITEM_TYPE_NUMBER];
49 static int ItemAppended( vlc_object_t *p_this, const char *psz_variable,
50 vlc_value_t oval, vlc_value_t nval, void *param );
51 static int ItemDeleted( vlc_object_t *p_this, const char *psz_variable,
52 vlc_value_t oval, vlc_value_t nval, void *param );
54 /*************************************************************************
55 * Playlist model implementation
56 *************************************************************************/
59 This model is called two times, for the selector and the standard panel
61 PLModel::PLModel( playlist_t *_p_playlist, /* THEPL */
62 intf_thread_t *_p_intf, /* main Qt p_intf */
63 playlist_item_t * p_root,
64 /*playlist_GetPreferredNode( THEPL, THEPL->p_local_category );
65 and THEPL->p_root_category for SelectPL */
66 int _i_depth, /* -1 for StandPL, 1 for SelectPL */
67 QObject *parent ) /* Basic Qt parent */
68 : QAbstractItemModel( parent )
71 assert( i_depth == DEPTH_SEL || i_depth == DEPTH_PL );
73 p_playlist = _p_playlist;
75 i_cached_input_id = -1;
76 i_popup_item = i_popup_parent = -1;
79 rootItem = NULL; /* PLItem rootItem, will be set in rebuild( ) */
81 /* Icons initialization */
82 #define ADD_ICON(type, x) icons[ITEM_TYPE_##type] = QIcon( QPixmap( x ) )
83 ADD_ICON( UNKNOWN , type_unknown_xpm );
84 ADD_ICON( FILE, ":/type/file" );
85 ADD_ICON( DIRECTORY, ":/type/directory" );
86 ADD_ICON( DISC, ":/type/disc" );
87 ADD_ICON( CDDA, ":/type/cdda" );
88 ADD_ICON( CARD, ":/type/capture-card" );
89 ADD_ICON( NET, ":/type/net" );
90 ADD_ICON( PLAYLIST, ":/type/playlist" );
91 ADD_ICON( NODE, ":/type/node" );
95 CONNECT( THEMIM->getIM(), metaChanged( input_item_t *),
96 this, processInputItemUpdate( input_item_t *) );
97 CONNECT( THEMIM, inputChanged( input_thread_t * ),
98 this, processInputItemUpdate( input_thread_t* ) );
107 Qt::DropActions PLModel::supportedDropActions() const
109 return Qt::CopyAction; /* Why not Qt::MoveAction */
112 Qt::ItemFlags PLModel::flags( const QModelIndex &index ) const
114 Qt::ItemFlags flags = QAbstractItemModel::flags( index );
116 PLItem *item = index.isValid() ? getItem( index ) : rootItem;
118 input_item_t *pl_input =
119 p_playlist->p_local_category ?
120 p_playlist->p_local_category->p_input : NULL;
121 input_item_t *ml_input =
122 p_playlist->p_ml_category ?
123 p_playlist->p_ml_category->p_input : NULL;
125 if( i_depth == DEPTH_SEL )
127 if( ( pl_input && item->p_input == pl_input ) ||
128 ( ml_input && item->p_input == ml_input ) )
129 flags |= Qt::ItemIsDropEnabled;
131 else if( ( pl_input && rootItem->p_input == pl_input ) ||
132 ( ml_input && rootItem->p_input == ml_input ) )
135 playlist_item_t *plItem =
136 playlist_ItemGetById( p_playlist, item->i_id );
138 if ( plItem && ( plItem->i_children > -1 ) )
139 flags |= Qt::ItemIsDropEnabled;
144 flags |= Qt::ItemIsDragEnabled;
149 QStringList PLModel::mimeTypes() const
152 types << "vlc/qt-playlist-item";
156 QMimeData *PLModel::mimeData( const QModelIndexList &indexes ) const
158 QMimeData *mimeData = new QMimeData();
159 QByteArray encodedData;
160 QDataStream stream( &encodedData, QIODevice::WriteOnly );
161 QModelIndexList list;
163 foreach( const QModelIndex &index, indexes ) {
164 if( index.isValid() && index.column() == 0 )
170 foreach( const QModelIndex &index, list ) {
171 PLItem *item = getItem( index );
172 stream.writeRawData( (char*) &item, sizeof( PLItem* ) );
174 mimeData->setData( "vlc/qt-playlist-item", encodedData );
179 bool PLModel::dropMimeData( const QMimeData *data, Qt::DropAction action,
180 int row, int column, const QModelIndex &parent )
182 if( data->hasFormat( "vlc/qt-playlist-item" ) )
184 if( action == Qt::IgnoreAction )
187 PLItem *parentItem = parent.isValid() ? getItem( parent ) : rootItem;
190 playlist_item_t *p_parent =
191 playlist_ItemGetById( p_playlist, parentItem->i_id );
192 if( !p_parent || p_parent->i_children == -1 )
199 playlist_item_t *p_pl = p_playlist->p_local_category;
200 playlist_item_t *p_ml = p_playlist->p_ml_category;
204 ( p_pl && p_parent->p_input == p_pl->p_input ) ||
205 ( p_ml && p_parent->p_input == p_ml->p_input ) )
210 QByteArray encodedData = data->data( "vlc/qt-playlist-item" );
212 dropAppendCopy( encodedData, parentItem );
214 dropMove( encodedData, parentItem, row );
219 void PLModel::dropAppendCopy( QByteArray& data, PLItem *target )
221 QDataStream stream( &data, QIODevice::ReadOnly );
224 playlist_item_t *p_parent =
225 playlist_ItemGetById( p_playlist, target->i_id );
226 while( !stream.atEnd() )
229 stream.readRawData( (char*)&item, sizeof(PLItem*) );
230 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id );
231 if( !p_item ) continue;
232 input_item_t *p_input = p_item->p_input;
233 playlist_AddExt ( p_playlist,
234 p_input->psz_uri, p_input->psz_name,
235 PLAYLIST_APPEND | PLAYLIST_SPREPARSE, PLAYLIST_END,
237 p_input->i_options, p_input->ppsz_options, p_input->optflagc,
238 p_parent == p_playlist->p_local_category, true );
243 void PLModel::dropMove( QByteArray& data, PLItem *target, int row )
245 QDataStream stream( &data, QIODevice::ReadOnly );
246 QList<PLItem*> model_items;
248 int new_pos = row == -1 ? target->children.size() : row;
249 int model_pos = new_pos;
250 while( !stream.atEnd() )
253 stream.readRawData( (char*)&item, sizeof(PLItem*) );
255 /* better not try to move a node into itself: */
256 PLItem *climber = target;
259 if( climber == item ) break;
260 climber = climber->parentItem;
262 if( climber ) continue;
264 if( item->parentItem == target &&
265 target->children.indexOf( item ) < model_pos )
268 ids.append( item->i_id );
269 model_items.append( item );
273 int count = ids.size();
276 playlist_item_t *pp_items[count];
279 for( int i = 0; i < count; i++ )
281 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, ids[i] );
287 pp_items[i] = p_item;
289 playlist_item_t *p_parent =
290 playlist_ItemGetById( p_playlist, target->i_id );
291 playlist_TreeMoveMany( p_playlist, count, pp_items, p_parent,
295 insertChildren( target, model_items, model_pos );
299 /* remove item with its id */
300 void PLModel::removeItem( int i_id )
302 PLItem *item = findById( rootItem, i_id );
306 /* callbacks and slots */
307 void PLModel::addCallbacks()
309 /* One item has been updated */
310 var_AddCallback( p_playlist, "playlist-item-append", ItemAppended, this );
311 var_AddCallback( p_playlist, "playlist-item-deleted", ItemDeleted, this );
314 void PLModel::delCallbacks()
316 var_DelCallback( p_playlist, "playlist-item-append", ItemAppended, this );
317 var_DelCallback( p_playlist, "playlist-item-deleted", ItemDeleted, this );
320 void PLModel::activateItem( const QModelIndex &index )
322 assert( index.isValid() );
323 PLItem *item = getItem( index );
326 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id );
327 activateItem( p_item );
331 /* Must be entered with lock */
332 void PLModel::activateItem( playlist_item_t *p_item )
334 if( !p_item ) return;
335 playlist_item_t *p_parent = p_item;
338 if( p_parent->i_id == rootItem->i_id ) break;
339 p_parent = p_parent->p_parent;
342 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, pl_Locked,
346 /****************** Base model mandatory implementations *****************/
347 QVariant PLModel::data( const QModelIndex &index, int role ) const
349 if( !index.isValid() ) return QVariant();
350 PLItem *item = getItem( index );
351 if( role == Qt::DisplayRole )
353 if( i_depth == DEPTH_SEL )
355 vlc_mutex_lock( &item->p_input->lock );
356 QString returninfo = QString( qfu( item->p_input->psz_name ) );
357 vlc_mutex_unlock( &item->p_input->lock );
358 return QVariant(returninfo);
361 int metadata = columnToMeta( index.column() );
362 if( metadata == COLUMN_END ) return QVariant();
365 if( metadata == COLUMN_NUMBER )
366 returninfo = QString::number( index.row() + 1 );
369 char *psz = psz_column_meta( item->p_input, metadata );
370 returninfo = qfu( psz );
373 return QVariant( returninfo );
375 else if( role == Qt::DecorationRole && index.column() == 0 )
377 /* Use to segfault here because i_type wasn't always initialized */
378 if( item->p_input->i_type >= 0 )
379 return QVariant( PLModel::icons[item->p_input->i_type] );
381 else if( role == Qt::FontRole )
383 if( isCurrent( index ) )
385 QFont f; f.setBold( true ); return QVariant( f );
391 bool PLModel::isCurrent( const QModelIndex &index ) const
393 if( !currentItem ) return false;
394 return getItem( index )->p_input == currentItem->p_input;
397 int PLModel::itemId( const QModelIndex &index ) const
399 return getItem( index )->i_id;
402 QVariant PLModel::headerData( int section, Qt::Orientation orientation,
405 if (orientation != Qt::Horizontal || role != Qt::DisplayRole)
408 if( i_depth == DEPTH_SEL ) return QVariant( QString("") );
410 int meta_col = columnToMeta( section );
412 if( meta_col == COLUMN_END ) return QVariant();
414 return QVariant( qfu( psz_column_title( meta_col ) ) );
417 QModelIndex PLModel::index( int row, int column, const QModelIndex &parent )
420 PLItem *parentItem = parent.isValid() ? getItem( parent ) : rootItem;
422 PLItem *childItem = parentItem->child( row );
424 return createIndex( row, column, childItem );
426 return QModelIndex();
429 /* Return the index of a given item */
430 QModelIndex PLModel::index( PLItem *item, int column ) const
432 if( !item ) return QModelIndex();
433 const PLItem *parent = item->parent();
435 return createIndex( parent->children.lastIndexOf( item ),
437 return QModelIndex();
440 QModelIndex PLModel::parent( const QModelIndex &index ) const
442 if( !index.isValid() ) return QModelIndex();
444 PLItem *childItem = getItem( index );
447 msg_Err( p_playlist, "NULL CHILD" );
448 return QModelIndex();
451 PLItem *parentItem = childItem->parent();
452 if( !parentItem || parentItem == rootItem ) return QModelIndex();
453 if( !parentItem->parentItem )
455 msg_Err( p_playlist, "No parent parent, trying row 0 " );
456 msg_Err( p_playlist, "----- PLEASE REPORT THIS ------" );
457 return createIndex( 0, 0, parentItem );
459 QModelIndex ind = createIndex(parentItem->row(), 0, parentItem);
463 int PLModel::columnCount( const QModelIndex &i) const
465 return i_depth == DEPTH_SEL ? 1 : columnFromMeta( COLUMN_END );
468 int PLModel::rowCount( const QModelIndex &parent ) const
470 PLItem *parentItem = parent.isValid() ? getItem( parent ) : rootItem;
471 return parentItem->childCount();
474 QStringList PLModel::selectedURIs()
477 for( int i = 0; i < current_selection.size(); i++ )
479 PLItem *item = getItem( current_selection[i] );
483 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id );
486 char *psz = input_item_GetURI( p_item->p_input );
499 /************************* General playlist status ***********************/
501 bool PLModel::hasRandom()
503 return var_GetBool( p_playlist, "random" );
505 bool PLModel::hasRepeat()
507 return var_GetBool( p_playlist, "repeat" );
509 bool PLModel::hasLoop()
511 return var_GetBool( p_playlist, "loop" );
513 void PLModel::setLoop( bool on )
515 var_SetBool( p_playlist, "loop", on ? true:false );
516 config_PutInt( p_playlist, "loop", on ? 1: 0 );
518 void PLModel::setRepeat( bool on )
520 var_SetBool( p_playlist, "repeat", on ? true:false );
521 config_PutInt( p_playlist, "repeat", on ? 1: 0 );
523 void PLModel::setRandom( bool on )
525 var_SetBool( p_playlist, "random", on ? true:false );
526 config_PutInt( p_playlist, "random", on ? 1: 0 );
529 /************************* Lookups *****************************/
531 PLItem *PLModel::findById( PLItem *root, int i_id )
533 return findInner( root, i_id, false );
536 PLItem *PLModel::findByInput( PLItem *root, int i_id )
538 PLItem *result = findInner( root, i_id, true );
542 #define CACHE( i, p ) { i_cached_id = i; p_cached_item = p; }
543 #define ICACHE( i, p ) { i_cached_input_id = i; p_cached_item_bi = p; }
545 PLItem * PLModel::findInner( PLItem *root, int i_id, bool b_input )
547 if( ( !b_input && i_cached_id == i_id) ||
548 ( b_input && i_cached_input_id ==i_id ) )
550 return b_input ? p_cached_item_bi : p_cached_item;
553 if( !b_input && root->i_id == i_id )
558 else if( b_input && root->p_input->i_id == i_id )
560 ICACHE( i_id, root );
564 QList<PLItem *>::iterator it = root->children.begin();
565 while ( it != root->children.end() )
567 if( !b_input && (*it)->i_id == i_id )
569 CACHE( i_id, (*it) );
570 return p_cached_item;
572 else if( b_input && (*it)->p_input->i_id == i_id )
574 ICACHE( i_id, (*it) );
575 return p_cached_item_bi;
577 if( (*it)->children.size() )
579 PLItem *childFound = findInner( (*it), i_id, b_input );
583 ICACHE( i_id, childFound )
585 CACHE( i_id, childFound )
596 PLItem *PLModel::getItem( QModelIndex index )
598 assert( index.isValid() );
599 return static_cast<PLItem*>( index.internalPointer() );
602 int PLModel::columnToMeta( int _column ) const
607 while( column != _column && meta != COLUMN_END )
616 int PLModel::columnFromMeta( int meta_col ) const
621 while( meta != meta_col && meta != COLUMN_END )
630 /************************* Updates handling *****************************/
631 void PLModel::customEvent( QEvent *event )
633 int type = event->type();
634 if( type != ItemAppend_Type &&
635 type != ItemDelete_Type )
638 PLEvent *ple = static_cast<PLEvent *>(event);
640 if( type == ItemAppend_Type )
641 processItemAppend( &ple->add );
642 else if( type == ItemDelete_Type )
643 processItemRemoval( ple->i_id );
646 /**** Events processing ****/
647 void PLModel::processInputItemUpdate( input_thread_t *p_input )
649 if( !p_input ) return;
650 processInputItemUpdate( input_GetItem( p_input ) );
651 if( p_input && !( p_input->b_dead || !vlc_object_alive( p_input ) ) )
653 PLItem *item = findByInput( rootItem, input_GetItem( p_input )->i_id );
655 emit currentChanged( index( item, 0 ) );
662 void PLModel::processInputItemUpdate( input_item_t *p_item )
664 if( !p_item || p_item->i_id <= 0 ) return;
665 PLItem *item = findByInput( rootItem, p_item->i_id );
667 updateTreeItem( item, true, true);
670 void PLModel::processItemRemoval( int i_id )
672 if( i_id <= 0 ) return;
673 if( i_id == i_cached_id ) i_cached_id = -1;
674 i_cached_input_id = -1;
679 void PLModel::processItemAppend( const playlist_add_t *p_add )
681 playlist_item_t *p_item = NULL;
682 PLItem *newItem = NULL;
684 PLItem *nodeItem = findById( rootItem, p_add->i_node );
685 if( !nodeItem ) return;
688 p_item = playlist_ItemGetById( p_playlist, p_add->i_item );
689 if( !p_item || p_item->i_flags & PLAYLIST_DBL_FLAG ) goto end;
690 if( i_depth == DEPTH_SEL && p_item->p_parent &&
691 p_item->p_parent->i_id != rootItem->i_id )
694 newItem = new PLItem( p_item, nodeItem );
697 beginInsertRows( index( nodeItem, 0 ), nodeItem->childCount(), nodeItem->childCount() );
698 nodeItem->appendChild( newItem );
700 updateTreeItem( newItem, true );
708 void PLModel::rebuild()
713 void PLModel::rebuild( playlist_item_t *p_root )
715 playlist_item_t* p_item;
716 /* Remove callbacks before locking to avoid deadlocks */
718 /* Invalidate cache */
719 i_cached_id = i_cached_input_id = -1;
721 if( rootItem ) rootItem->removeChildren();
727 rootItem = new PLItem( p_root );
730 /* Recreate from root */
731 updateChildren( rootItem );
732 if( (p_item = playlist_CurrentPlayingItem(p_playlist)) )
733 currentItem = findByInput( rootItem, p_item->p_input->i_id );
738 /* And signal the view */
741 emit currentChanged( index( currentItem, 0 ) );
746 void PLModel::takeItem( PLItem *item )
749 PLItem *parent = item->parentItem;
751 int i_index = parent->children.indexOf( item );
753 beginRemoveRows( index( parent, 0 ), i_index, i_index );
754 parent->takeChildAt( i_index );
758 void PLModel::insertChildren( PLItem *node, QList<PLItem*>& items, int i_pos )
761 int count = items.size();
763 beginInsertRows( index( node, 0 ), i_pos, i_pos + count - 1 );
764 for( int i = 0; i < count; i++ )
766 node->children.insert( i_pos + i, items[i] );
767 items[i]->parentItem = node;
772 void PLModel::removeItem( PLItem *item )
775 if( currentItem == item )
778 emit currentChanged( QModelIndex() );
780 PLItem *parent = item->parentItem;
782 parent->removeChild( item );
785 /* This function must be entered WITH the playlist lock */
786 void PLModel::updateChildren( PLItem *root )
788 playlist_item_t *p_node = playlist_ItemGetById( p_playlist, root->i_id );
789 updateChildren( p_node, root );
792 /* This function must be entered WITH the playlist lock */
793 void PLModel::updateChildren( playlist_item_t *p_node, PLItem *root )
795 playlist_item_t *p_item = playlist_CurrentPlayingItem(p_playlist);
796 for( int i = 0; i < p_node->i_children ; i++ )
798 if( p_node->pp_children[i]->i_flags & PLAYLIST_DBL_FLAG ) continue;
799 PLItem *newItem = new PLItem( p_node->pp_children[i], root );
800 root->appendChild( newItem );
801 if( p_item && newItem->p_input == p_item->p_input )
803 currentItem = newItem;
804 emit currentChanged( index( currentItem, 0 ) );
806 if( i_depth == DEPTH_PL && p_node->pp_children[i]->i_children != -1 )
807 updateChildren( p_node->pp_children[i], newItem );
811 /* Function doesn't need playlist-lock, as we don't touch playlist_item_t stuff here*/
812 void PLModel::updateTreeItem( PLItem *item, bool signal, bool force )
814 if ( !item || !item->p_input )
816 if( !force && i_depth == DEPTH_SEL && item->parentItem &&
817 item->parentItem->p_input != rootItem->p_input )
820 emit dataChanged( index( item, 0 ) , index( item, columnCount( QModelIndex() ) ) );
823 /************************* Actions ******************************/
826 * Deletion, here we have to do a ugly slow hack as we retrieve the full
827 * list of indexes to delete at once: when we delete a node and all of
828 * its children, we need to update the list.
829 * Todo: investigate whethere we can use ranges to be sure to delete all items?
831 void PLModel::doDelete( QModelIndexList selected )
833 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 );
876 /* And finally, remove it from the tree */
877 int itemIndex = item->parentItem->children.indexOf( item );
878 beginRemoveRows( index( item->parentItem, 0), itemIndex, itemIndex );
883 /******* Volume III: Sorting and searching ********/
884 void PLModel::sort( int column, Qt::SortOrder order )
886 sort( rootItem->i_id, column, order );
889 void PLModel::sort( int i_root_id, int column, Qt::SortOrder order )
891 int meta = columnToMeta( column );
892 if( meta == COLUMN_END ) return;
894 PLItem *item = findById( rootItem, i_root_id );
896 QModelIndex qIndex = index( item, 0 );
897 int count = item->children.size();
900 beginRemoveRows( qIndex, 0, count - 1 );
901 item->removeChildren();
907 playlist_item_t *p_root = playlist_ItemGetById( p_playlist,
911 playlist_RecursiveNodeSort( p_playlist, p_root,
912 i_column_sorting( meta ),
913 order == Qt::AscendingOrder ?
914 ORDER_NORMAL : ORDER_REVERSE );
919 beginInsertRows( qIndex, 0, count - 1 );
920 updateChildren( item );
926 void PLModel::search( const QString& search_text )
928 /** \todo Fire the search with a small delay ? */
931 playlist_item_t *p_root = playlist_ItemGetById( p_playlist,
934 const char *psz_name = search_text.toUtf8().data();
935 playlist_LiveSearchUpdate( p_playlist , p_root, psz_name );
941 /*********** Popup *********/
942 void PLModel::popup( QModelIndex & index, QPoint &point, QModelIndexList list )
944 int i_id = index.isValid() ? itemId( index ) : rootItem->i_id;
947 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, i_id );
952 i_popup_item = index.isValid() ? p_item->i_id : -1;
953 i_popup_parent = index.isValid() ?
954 ( p_item->p_parent ? p_item->p_parent->i_id : -1 ) :
956 i_popup_column = index.column();
957 /* check whether we are in tree view */
959 playlist_item_t *p_up = p_item;
962 if ( p_up == p_playlist->p_root_category ) tree = true;
963 p_up = p_up->p_parent;
967 current_selection = list;
968 QMenu *menu = new QMenu;
969 if( i_popup_item > -1 )
971 menu->addAction( qtr(I_POP_PLAY), this, SLOT( popupPlay() ) );
972 menu->addAction( qtr(I_POP_DEL), this, SLOT( popupDel() ) );
973 menu->addSeparator();
974 menu->addAction( qtr(I_POP_STREAM), this, SLOT( popupStream() ) );
975 menu->addAction( qtr(I_POP_SAVE), this, SLOT( popupSave() ) );
976 menu->addSeparator();
977 menu->addAction( qtr(I_POP_INFO), this, SLOT( popupInfo() ) );
978 menu->addSeparator();
979 QMenu *sort_menu = menu->addMenu( qtr( "Sort by ") +
980 qfu( psz_column_title( columnToMeta( index.column() ) ) ) );
981 sort_menu->addAction( qtr( "Ascending" ),
982 this, SLOT( popupSortAsc() ) );
983 sort_menu->addAction( qtr( "Descending" ),
984 this, SLOT( popupSortDesc() ) );
987 menu->addAction( qtr(I_POP_ADD), this, SLOT( popupAddNode() ) );
988 if( i_popup_item > -1 )
990 menu->addSeparator();
991 menu->addAction( qtr( I_POP_EXPLORE ), this, SLOT( popupExplore() ) );
993 menu->popup( point );
996 void PLModel::popupDel()
998 doDelete( current_selection );
1001 void PLModel::popupPlay()
1005 playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
1007 activateItem( p_item );
1012 void PLModel::popupInfo()
1015 playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
1019 input_item_t* p_input = p_item->p_input;
1020 vlc_gc_incref( p_input );
1022 MediaInfoDialog *mid = new MediaInfoDialog( p_intf, p_input );
1023 vlc_gc_decref( p_input );
1024 mid->setParent( PlaylistDialog::getInstance( p_intf ),
1031 void PLModel::popupStream()
1033 QStringList mrls = selectedURIs();
1034 if( !mrls.isEmpty() )
1035 THEDP->streamingDialog( NULL, mrls[0], false );
1039 void PLModel::popupSave()
1041 QStringList mrls = selectedURIs();
1042 if( !mrls.isEmpty() )
1043 THEDP->streamingDialog( NULL, mrls[0] );
1047 #include <QFileInfo>
1048 #include <QDesktopServices>
1049 void PLModel::popupExplore()
1052 playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
1056 input_item_t *p_input = p_item->p_input;
1057 char *psz_meta = input_item_GetURI( p_input );
1061 const char *psz_access;
1062 const char *psz_demux;
1064 input_SplitMRL( &psz_access, &psz_demux, &psz_path, psz_meta );
1066 if( EMPTY_STR( psz_access ) ||
1067 !strncasecmp( psz_access, "file", 4 ) ||
1068 !strncasecmp( psz_access, "dire", 4 ) )
1070 QFileInfo info( qfu( psz_meta ) );
1071 QDesktopServices::openUrl(
1072 QUrl::fromLocalFile( info.absolutePath() ) );
1081 #include <QInputDialog>
1082 void PLModel::popupAddNode()
1085 QString name = QInputDialog::getText( PlaylistDialog::getInstance( p_intf ),
1086 qtr( I_POP_ADD ), qtr( "Enter name for new node:" ),
1087 QLineEdit::Normal, QString(), &ok);
1088 if( !ok || name.isEmpty() ) return;
1090 playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
1094 playlist_NodeCreate( p_playlist, qtu( name ), p_item, 0, NULL );
1099 void PLModel::popupSortAsc()
1101 sort( i_popup_parent, i_popup_column, Qt::AscendingOrder );
1104 void PLModel::popupSortDesc()
1106 sort( i_popup_parent, i_popup_column, Qt::DescendingOrder );
1108 /**********************************************************************
1109 * Playlist callbacks
1110 **********************************************************************/
1112 static int ItemDeleted( vlc_object_t *p_this, const char *psz_variable,
1113 vlc_value_t oval, vlc_value_t nval, void *param )
1115 PLModel *p_model = (PLModel *) param;
1116 PLEvent *event = new PLEvent( ItemDelete_Type, nval.i_int );
1117 QApplication::postEvent( p_model, event );
1121 static int ItemAppended( vlc_object_t *p_this, const char *psz_variable,
1122 vlc_value_t oval, vlc_value_t nval, void *param )
1124 PLModel *p_model = (PLModel *) param;
1125 const playlist_add_t *p_add = (playlist_add_t *)nval.p_address;
1126 PLEvent *event = new PLEvent( p_add );
1127 QApplication::postEvent( p_model, event );