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 PlaylistChanged( vlc_object_t *, const char *,
50 vlc_value_t, vlc_value_t, void * );
51 static int PlaylistNext( vlc_object_t *, const char *,
52 vlc_value_t, vlc_value_t, void * );
53 static int ItemAppended( vlc_object_t *p_this, const char *psz_variable,
54 vlc_value_t oval, vlc_value_t nval, void *param );
55 static int ItemDeleted( vlc_object_t *p_this, const char *psz_variable,
56 vlc_value_t oval, vlc_value_t nval, void *param );
58 /*************************************************************************
59 * Playlist model implementation
60 *************************************************************************/
63 This model is called two times, for the selector and the standard panel
65 PLModel::PLModel( playlist_t *_p_playlist, /* THEPL */
66 intf_thread_t *_p_intf, /* main Qt p_intf */
67 playlist_item_t * p_root,
68 /*playlist_GetPreferredNode( THEPL, THEPL->p_local_category );
69 and THEPL->p_root_category for SelectPL */
70 int _i_depth, /* -1 for StandPL, 1 for SelectPL */
71 QObject *parent ) /* Basic Qt parent */
72 : QAbstractItemModel( parent )
75 assert( i_depth == DEPTH_SEL || i_depth == DEPTH_PL );
77 p_playlist = _p_playlist;
79 i_cached_input_id = -1;
80 i_popup_item = i_popup_parent = -1;
83 rootItem = NULL; /* PLItem rootItem, will be set in rebuild( ) */
85 if( i_depth == DEPTH_SEL )
89 i_showflags = getSettings()->value( "qt-pl-showflags", COLUMN_DEFAULT ).toInt();
91 i_showflags = COLUMN_DEFAULT; /* reasonable default to show something */
92 else if ( i_showflags >= COLUMN_END )
93 i_showflags = COLUMN_END - 1; /* show everything */
96 /* Icons initialization */
97 #define ADD_ICON(type, x) icons[ITEM_TYPE_##type] = QIcon( QPixmap( x ) )
98 ADD_ICON( UNKNOWN , type_unknown_xpm );
99 ADD_ICON( FILE, ":/type/file" );
100 ADD_ICON( DIRECTORY, ":/type/directory" );
101 ADD_ICON( DISC, ":/type/disc" );
102 ADD_ICON( CDDA, ":/type/cdda" );
103 ADD_ICON( CARD, ":/type/capture-card" );
104 ADD_ICON( NET, ":/type/net" );
105 ADD_ICON( PLAYLIST, ":/type/playlist" );
106 ADD_ICON( NODE, ":/type/node" );
110 CONNECT( THEMIM->getIM(), metaChanged( input_item_t *),
111 this, ProcessInputItemUpdate( input_item_t *) );
112 CONNECT( THEMIM, inputChanged( input_thread_t * ),
113 this, ProcessInputItemUpdate( input_thread_t* ) );
119 getSettings()->setValue( "qt-pl-showflags", i_showflags );
124 Qt::DropActions PLModel::supportedDropActions() const
126 return Qt::CopyAction; /* Why not Qt::MoveAction */
129 Qt::ItemFlags PLModel::flags( const QModelIndex &index ) const
131 Qt::ItemFlags flags = QAbstractItemModel::flags( index );
133 PLItem *item = index.isValid() ? getItem( index ) : rootItem;
135 input_item_t *pl_input =
136 p_playlist->p_local_category ?
137 p_playlist->p_local_category->p_input : NULL;
138 input_item_t *ml_input =
139 p_playlist->p_ml_category ?
140 p_playlist->p_ml_category->p_input : NULL;
142 if( i_depth == DEPTH_SEL )
144 if( ( pl_input && item->p_input == pl_input ) ||
145 ( ml_input && item->p_input == ml_input ) )
146 flags |= Qt::ItemIsDropEnabled;
148 else if( ( pl_input && rootItem->p_input == pl_input ) ||
149 ( ml_input && rootItem->p_input == ml_input ) )
152 playlist_item_t *plItem =
153 playlist_ItemGetById( p_playlist, item->i_id );
155 if ( plItem && ( plItem->i_children > -1 ) )
156 flags |= Qt::ItemIsDropEnabled;
161 flags |= Qt::ItemIsDragEnabled;
166 /* A list of model indexes are a playlist */
167 QStringList PLModel::mimeTypes() const
170 types << "vlc/playlist-item-id";
174 QMimeData *PLModel::mimeData( const QModelIndexList &indexes ) const
176 QMimeData *mimeData = new QMimeData();
177 QByteArray encodedData;
178 QDataStream stream( &encodedData, QIODevice::WriteOnly );
179 QModelIndexList list;
181 foreach( const QModelIndex &index, indexes ) {
182 if( index.isValid() && index.column() == 0 )
188 foreach( const QModelIndex &index, list ) {
189 stream << itemId( index );
191 mimeData->setData( "vlc/playlist-item-id", encodedData );
196 bool PLModel::dropMimeData( const QMimeData *data, Qt::DropAction action,
197 int row, int column, const QModelIndex &parent )
199 if( data->hasFormat( "vlc/playlist-item-id" ) )
201 if( action == Qt::IgnoreAction )
206 playlist_item_t *p_parent;
208 if( !parent.isValid())
211 p_parent = playlist_ItemGetById( p_playlist, rootItem->i_id );
219 p_parent = playlist_ItemGetById( p_playlist, itemId ( parent ) );
221 if( !p_parent || p_parent->i_children == -1 )
229 ( p_parent->p_input == p_playlist->p_local_category->p_input
230 || p_parent->p_input == p_playlist->p_ml_category->p_input ) )
233 QByteArray encodedData = data->data( "vlc/playlist-item-id" );
234 QDataStream stream( &encodedData, QIODevice::ReadOnly );
238 while( !stream.atEnd() )
242 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, i_id );
248 input_item_t *p_input = p_item->p_input;
249 playlist_AddExt ( p_playlist,
250 p_input->psz_uri, p_input->psz_name,
251 PLAYLIST_APPEND | PLAYLIST_SPREPARSE, PLAYLIST_END,
253 p_input->i_options, p_input->ppsz_options, p_input->optflagc,
254 p_parent == p_playlist->p_local_category, true );
259 QList<playlist_item_t*> items;
260 while( !stream.atEnd() )
264 playlist_item_t *item = playlist_ItemGetById( p_playlist, id );
265 if( !item ) continue;
266 /* better not try to move a node into itself: */
267 if( item->i_children > 0 )
269 playlist_item_t *climber = p_parent;
272 if( climber == item ) break;
273 climber = climber->p_parent;
275 if( climber ) continue;
277 items.append( item );
279 int count = items.size();
282 playlist_item_t *pp_items[count];
283 for( int i = 0; i < count; i++ ) pp_items[i] = items[i];
284 playlist_TreeMoveMany( p_playlist, count, pp_items, p_parent,
285 (row == -1 ? p_parent->i_children : row) );
290 /*TODO: That's not a good idea to rebuild the playlist */
296 /* remove item with its id */
297 void PLModel::removeItem( int i_id )
299 PLItem *item = FindById( rootItem, i_id );
303 /* callbacks and slots */
304 void PLModel::addCallbacks()
306 /* Some global changes happened -> Rebuild all */
307 var_AddCallback( p_playlist, "intf-change", PlaylistChanged, this );
308 /* We went to the next item
309 var_AddCallback( p_playlist, "item-current", PlaylistNext, this );
311 /* One item has been updated */
312 var_AddCallback( p_playlist, "playlist-item-append", ItemAppended, this );
313 var_AddCallback( p_playlist, "playlist-item-deleted", ItemDeleted, this );
316 void PLModel::delCallbacks()
319 var_DelCallback( p_playlist, "item-current", PlaylistNext, this );
321 var_DelCallback( p_playlist, "intf-change", PlaylistChanged, this );
322 var_DelCallback( p_playlist, "playlist-item-append", ItemAppended, this );
323 var_DelCallback( p_playlist, "playlist-item-deleted", ItemDeleted, this );
326 void PLModel::activateItem( const QModelIndex &index )
328 assert( index.isValid() );
329 PLItem *item = getItem( index );
332 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id );
333 activateItem( p_item );
337 /* Must be entered with lock */
338 void PLModel::activateItem( playlist_item_t *p_item )
340 if( !p_item ) return;
341 playlist_item_t *p_parent = p_item;
344 if( p_parent->i_id == rootItem->i_id ) break;
345 p_parent = p_parent->p_parent;
348 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, pl_Locked,
352 /****************** Base model mandatory implementations *****************/
353 QVariant PLModel::data( const QModelIndex &index, int role ) const
355 if( !index.isValid() ) return QVariant();
356 PLItem *item = getItem( index );
357 if( role == Qt::DisplayRole )
359 if( i_depth == DEPTH_SEL )
361 vlc_mutex_lock( &item->p_input->lock );
362 QString returninfo = QString( qfu( item->p_input->psz_name ) );
363 vlc_mutex_unlock( &item->p_input->lock );
364 return QVariant(returninfo);
367 int metadata = metaColumn( index.column() );
368 if( metadata == COLUMN_END ) return QVariant();
371 if( metadata == COLUMN_NUMBER )
372 returninfo = QString::number( index.row() + 1 );
375 char *psz = psz_column_meta( item->p_input, metadata );
376 returninfo = qfu( psz );
379 return QVariant( returninfo );
381 else if( role == Qt::DecorationRole && index.column() == 0 )
383 /* Use to segfault here because i_type wasn't always initialized */
384 if( item->p_input->i_type >= 0 )
385 return QVariant( PLModel::icons[item->p_input->i_type] );
387 else if( role == Qt::FontRole )
389 if( isCurrent( index ) )
391 QFont f; f.setBold( true ); return QVariant( f );
397 bool PLModel::isCurrent( const QModelIndex &index ) const
399 if( !currentItem ) return false;
400 return getItem( index )->p_input == currentItem->p_input;
403 int PLModel::itemId( const QModelIndex &index ) const
405 return getItem( index )->i_id;
408 QVariant PLModel::headerData( int section, Qt::Orientation orientation,
411 if (orientation != Qt::Horizontal || role != Qt::DisplayRole)
414 if( i_depth == DEPTH_SEL ) return QVariant( QString("") );
416 int meta_col = metaColumn( section );
418 if( meta_col == COLUMN_END ) return QVariant();
420 return QVariant( qfu( psz_column_title( meta_col ) ) );
423 QModelIndex PLModel::index( int row, int column, const QModelIndex &parent )
426 PLItem *parentItem = parent.isValid() ? getItem( parent ) : rootItem;
428 PLItem *childItem = parentItem->child( row );
430 return createIndex( row, column, childItem );
432 return QModelIndex();
435 /* Return the index of a given item */
436 QModelIndex PLModel::index( PLItem *item, int column ) const
438 if( !item ) return QModelIndex();
439 const PLItem *parent = item->parent();
441 return createIndex( parent->children.lastIndexOf( item ),
443 return QModelIndex();
446 QModelIndex PLModel::parent( const QModelIndex &index ) const
448 if( !index.isValid() ) return QModelIndex();
450 PLItem *childItem = getItem( index );
453 msg_Err( p_playlist, "NULL CHILD" );
454 return QModelIndex();
457 PLItem *parentItem = childItem->parent();
458 if( !parentItem || parentItem == rootItem ) return QModelIndex();
459 if( !parentItem->parentItem )
461 msg_Err( p_playlist, "No parent parent, trying row 0 " );
462 msg_Err( p_playlist, "----- PLEASE REPORT THIS ------" );
463 return createIndex( 0, 0, parentItem );
465 QModelIndex ind = createIndex(parentItem->row(), 0, parentItem);
469 int PLModel::columnCount( const QModelIndex &i) const
473 if( i_depth == DEPTH_SEL ) return 1;
475 while( metadata < COLUMN_END )
477 if( metadata & i_showflags )
484 int PLModel::childrenCount( const QModelIndex &parent ) const
486 return rowCount( parent );
489 int PLModel::rowCount( const QModelIndex &parent ) const
491 PLItem *parentItem = parent.isValid() ? getItem( parent ) : rootItem;
492 return parentItem->childCount();
495 QStringList PLModel::selectedURIs()
498 for( int i = 0; i < current_selection.size(); i++ )
500 PLItem *item = getItem( current_selection[i] );
504 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id );
507 char *psz = input_item_GetURI( p_item->p_input );
520 /************************* General playlist status ***********************/
522 bool PLModel::hasRandom()
524 return var_GetBool( p_playlist, "random" );
526 bool PLModel::hasRepeat()
528 return var_GetBool( p_playlist, "repeat" );
530 bool PLModel::hasLoop()
532 return var_GetBool( p_playlist, "loop" );
534 void PLModel::setLoop( bool on )
536 var_SetBool( p_playlist, "loop", on ? true:false );
537 config_PutInt( p_playlist, "loop", on ? 1: 0 );
539 void PLModel::setRepeat( bool on )
541 var_SetBool( p_playlist, "repeat", on ? true:false );
542 config_PutInt( p_playlist, "repeat", on ? 1: 0 );
544 void PLModel::setRandom( bool on )
546 var_SetBool( p_playlist, "random", on ? true:false );
547 config_PutInt( p_playlist, "random", on ? 1: 0 );
550 /************************* Lookups *****************************/
552 PLItem *PLModel::FindById( PLItem *root, int i_id )
554 return FindInner( root, i_id, false );
557 PLItem *PLModel::FindByInput( PLItem *root, int i_id )
559 PLItem *result = FindInner( root, i_id, true );
563 #define CACHE( i, p ) { i_cached_id = i; p_cached_item = p; }
564 #define ICACHE( i, p ) { i_cached_input_id = i; p_cached_item_bi = p; }
566 PLItem * PLModel::FindInner( PLItem *root, int i_id, bool b_input )
568 if( ( !b_input && i_cached_id == i_id) ||
569 ( b_input && i_cached_input_id ==i_id ) )
571 return b_input ? p_cached_item_bi : p_cached_item;
574 if( !b_input && root->i_id == i_id )
579 else if( b_input && root->p_input->i_id == i_id )
581 ICACHE( i_id, root );
585 QList<PLItem *>::iterator it = root->children.begin();
586 while ( it != root->children.end() )
588 if( !b_input && (*it)->i_id == i_id )
590 CACHE( i_id, (*it) );
591 return p_cached_item;
593 else if( b_input && (*it)->p_input->i_id == i_id )
595 ICACHE( i_id, (*it) );
596 return p_cached_item_bi;
598 if( (*it)->children.size() )
600 PLItem *childFound = FindInner( (*it), i_id, b_input );
604 ICACHE( i_id, childFound )
606 CACHE( i_id, childFound )
617 PLItem *PLModel::getItem( QModelIndex index )
619 assert( index.isValid() );
620 return static_cast<PLItem*>( index.internalPointer() );
623 /* computes column id of meta data from visible column index */
624 int PLModel::metaColumn( int column ) const
627 int running_index = -1;
629 while( metadata < COLUMN_END )
631 if( metadata & i_showflags )
633 if( running_index == column )
638 if( running_index != column ) return COLUMN_END;
642 /************************* Updates handling *****************************/
643 void PLModel::customEvent( QEvent *event )
645 int type = event->type();
646 if( type != ItemAppend_Type &&
647 type != ItemDelete_Type && type != PLUpdate_Type )
650 PLEvent *ple = static_cast<PLEvent *>(event);
652 if( type == ItemAppend_Type )
653 ProcessItemAppend( &ple->add );
654 else if( type == ItemDelete_Type )
655 ProcessItemRemoval( ple->i_id );
660 /**** Events processing ****/
661 void PLModel::ProcessInputItemUpdate( input_thread_t *p_input )
663 if( !p_input ) return;
664 ProcessInputItemUpdate( input_GetItem( p_input ) );
665 if( p_input && !( p_input->b_dead || !vlc_object_alive( p_input ) ) )
667 PLItem *item = FindByInput( rootItem, input_GetItem( p_input )->i_id );
669 emit currentChanged( index( item, 0 ) );
676 void PLModel::ProcessInputItemUpdate( input_item_t *p_item )
678 if( !p_item || p_item->i_id <= 0 ) return;
679 PLItem *item = FindByInput( rootItem, p_item->i_id );
681 UpdateTreeItem( item, true, true);
684 void PLModel::ProcessItemRemoval( int i_id )
686 if( i_id <= 0 ) return;
687 if( i_id == i_cached_id ) i_cached_id = -1;
688 i_cached_input_id = -1;
693 void PLModel::ProcessItemAppend( const playlist_add_t *p_add )
695 playlist_item_t *p_item = NULL;
696 PLItem *newItem = NULL;
698 PLItem *nodeItem = FindById( rootItem, p_add->i_node );
699 if( !nodeItem ) return;
702 p_item = playlist_ItemGetById( p_playlist, p_add->i_item );
703 if( !p_item || p_item->i_flags & PLAYLIST_DBL_FLAG ) goto end;
704 if( i_depth == DEPTH_SEL && p_item->p_parent &&
705 p_item->p_parent->i_id != rootItem->i_id )
708 newItem = new PLItem( p_item, nodeItem );
711 beginInsertRows( index( nodeItem, 0 ), nodeItem->childCount(), nodeItem->childCount() );
712 nodeItem->appendChild( newItem );
714 UpdateTreeItem( newItem, true );
722 void PLModel::rebuild()
727 void PLModel::rebuild( playlist_item_t *p_root )
729 playlist_item_t* p_item;
730 /* Remove callbacks before locking to avoid deadlocks */
732 /* Invalidate cache */
733 i_cached_id = i_cached_input_id = -1;
735 if( rootItem ) RemoveChildren( rootItem );
741 rootItem = new PLItem( p_root );
744 /* Recreate from root */
745 UpdateChildren( rootItem );
746 if( (p_item = playlist_CurrentPlayingItem(p_playlist)) )
747 currentItem = FindByInput( rootItem, p_item->p_input->i_id );
752 /* And signal the view */
754 emit currentChanged( index( currentItem, 0 ) );
759 void PLModel::RemoveItem( PLItem *item )
762 if( currentItem && currentItem->p_input == item->p_input )
765 emit currentChanged( QModelIndex() );
767 PLItem *parent = item->parentItem;
769 int i_index = parent->children.indexOf( item );
770 parent->children.removeAt( i_index );
773 void PLModel::RemoveChildren( PLItem *root )
775 if( root->children.size() )
777 qDeleteAll( root->children );
778 root->children.clear();
782 /* This function must be entered WITH the playlist lock */
783 void PLModel::UpdateChildren( PLItem *root )
785 playlist_item_t *p_node = playlist_ItemGetById( p_playlist, root->i_id );
786 UpdateChildren( p_node, root );
789 /* This function must be entered WITH the playlist lock */
790 void PLModel::UpdateChildren( playlist_item_t *p_node, PLItem *root )
792 for( int i = 0; i < p_node->i_children ; i++ )
794 if( p_node->pp_children[i]->i_flags & PLAYLIST_DBL_FLAG ) continue;
795 PLItem *newItem = new PLItem( p_node->pp_children[i], root );
796 root->appendChild( newItem );
797 if( i_depth == DEPTH_PL && p_node->pp_children[i]->i_children != -1 )
798 UpdateChildren( p_node->pp_children[i], newItem );
802 /* Function doesn't need playlist-lock, as we don't touch playlist_item_t stuff here*/
803 void PLModel::UpdateTreeItem( PLItem *item, bool signal, bool force )
805 if ( !item || !item->p_input )
807 if( !force && i_depth == DEPTH_SEL && item->parentItem &&
808 item->parentItem->p_input != rootItem->p_input )
811 emit dataChanged( index( item, 0 ) , index( item, columnCount( QModelIndex() ) ) );
814 /************************* Actions ******************************/
817 * Deletion, here we have to do a ugly slow hack as we retrieve the full
818 * list of indexes to delete at once: when we delete a node and all of
819 * its children, we need to update the list.
820 * Todo: investigate whethere we can use ranges to be sure to delete all items?
822 void PLModel::doDelete( QModelIndexList selected )
824 for( int i = selected.size() -1 ; i >= 0; i-- )
826 QModelIndex index = selected[i];
827 if( index.column() != 0 ) continue;
828 PLItem *item = getItem( index );
831 if( item->children.size() )
832 recurseDelete( item->children, &selected );
833 doDeleteItem( item, &selected );
835 if( i > selected.size() ) i = selected.size();
839 void PLModel::recurseDelete( QList<PLItem*> children, QModelIndexList *fullList )
841 for( int i = children.size() - 1; i >= 0 ; i-- )
843 PLItem *item = children[i];
844 if( item->children.size() )
845 recurseDelete( item->children, fullList );
846 doDeleteItem( item, fullList );
850 void PLModel::doDeleteItem( PLItem *item, QModelIndexList *fullList )
852 QModelIndex deleteIndex = index( item, 0 );
853 fullList->removeAll( deleteIndex );
856 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id );
862 if( p_item->i_children == -1 )
863 playlist_DeleteFromInput( p_playlist, p_item->p_input, pl_Locked );
865 playlist_NodeDelete( p_playlist, p_item, true, false );
867 /* And finally, remove it from the tree */
868 int itemIndex = item->parentItem->children.indexOf( item );
869 beginRemoveRows( index( item->parentItem, 0), itemIndex, itemIndex );
874 /******* Volume III: Sorting and searching ********/
875 void PLModel::sort( int column, Qt::SortOrder order )
877 sort( rootItem->i_id, column, order );
880 void PLModel::sort( int i_root_id, int column, Qt::SortOrder order )
886 for( i_column = 1; i_column != COLUMN_END; i_column<<=1 )
888 if( ( shownFlags() & i_column ) )
890 if( column == i_index )
897 PLItem *item = FindById( rootItem, i_root_id );
899 QModelIndex qIndex = index( item, 0 );
900 int count = item->children.size();
903 beginRemoveRows( qIndex, 0, count - 1 );
904 RemoveChildren( item );
910 playlist_item_t *p_root = playlist_ItemGetById( p_playlist,
912 if( p_root && i_flag )
914 playlist_RecursiveNodeSort( p_playlist, p_root,
915 i_column_sorting( i_flag ),
916 order == Qt::AscendingOrder ?
917 ORDER_NORMAL : ORDER_REVERSE );
922 beginInsertRows( qIndex, 0, count - 1 );
923 UpdateChildren( item );
929 void PLModel::search( const QString& search_text )
931 /** \todo Fire the search with a small delay ? */
934 playlist_item_t *p_root = playlist_ItemGetById( p_playlist,
937 const char *psz_name = search_text.toUtf8().data();
938 playlist_LiveSearchUpdate( p_playlist , p_root, psz_name );
944 /*********** Popup *********/
945 void PLModel::popup( QModelIndex & index, QPoint &point, QModelIndexList list )
947 int i_id = index.isValid() ? itemId( index ) : rootItem->i_id;
950 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, i_id );
955 i_popup_item = index.isValid() ? p_item->i_id : -1;
956 i_popup_parent = index.isValid() ?
957 ( p_item->p_parent ? p_item->p_parent->i_id : -1 ) :
959 i_popup_column = index.column();
960 /* check whether we are in tree view */
962 playlist_item_t *p_up = p_item;
965 if ( p_up == p_playlist->p_root_category ) tree = true;
966 p_up = p_up->p_parent;
970 current_selection = list;
971 QMenu *menu = new QMenu;
972 if( i_popup_item > -1 )
974 menu->addAction( qtr(I_POP_PLAY), this, SLOT( popupPlay() ) );
975 menu->addAction( qtr(I_POP_DEL), this, SLOT( popupDel() ) );
976 menu->addSeparator();
977 menu->addAction( qtr(I_POP_STREAM), this, SLOT( popupStream() ) );
978 menu->addAction( qtr(I_POP_SAVE), this, SLOT( popupSave() ) );
979 menu->addSeparator();
980 menu->addAction( qtr(I_POP_INFO), this, SLOT( popupInfo() ) );
981 menu->addSeparator();
982 QMenu *sort_menu = menu->addMenu( qtr( "Sort by ") +
983 qfu( psz_column_title( metaColumn( index.column() ) ) ) );
984 sort_menu->addAction( qtr( "Ascending" ),
985 this, SLOT( popupSortAsc() ) );
986 sort_menu->addAction( qtr( "Descending" ),
987 this, SLOT( popupSortDesc() ) );
990 menu->addAction( qtr(I_POP_ADD), this, SLOT( popupAddNode() ) );
991 if( i_popup_item > -1 )
993 menu->addSeparator();
994 menu->addAction( qtr( I_POP_EXPLORE ), this, SLOT( popupExplore() ) );
996 menu->popup( point );
1000 void PLModel::viewchanged( int meta )
1013 index = __MIN( index, columnCount() );
1014 QModelIndex parent = createIndex( 0, 0, rootItem );
1016 if( i_showflags & meta )
1017 /* Removing columns */
1019 beginRemoveColumns( parent, index, index+1 );
1020 i_showflags &= ~( meta );
1021 getSettings()->setValue( "qt-pl-showflags", i_showflags );
1026 /* Adding columns */
1027 beginInsertColumns( parent, index, index+1 );
1028 i_showflags |= meta;
1029 getSettings()->setValue( "qt-pl-showflags", i_showflags );
1033 emit columnsChanged( meta );
1037 void PLModel::popupDel()
1039 doDelete( current_selection );
1042 void PLModel::popupPlay()
1046 playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
1048 activateItem( p_item );
1053 void PLModel::popupInfo()
1056 playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
1060 input_item_t* p_input = p_item->p_input;
1061 vlc_gc_incref( p_input );
1063 MediaInfoDialog *mid = new MediaInfoDialog( p_intf, p_input );
1064 vlc_gc_decref( p_input );
1065 mid->setParent( PlaylistDialog::getInstance( p_intf ),
1072 void PLModel::popupStream()
1074 QStringList mrls = selectedURIs();
1075 if( !mrls.isEmpty() )
1076 THEDP->streamingDialog( NULL, mrls[0], false );
1080 void PLModel::popupSave()
1082 QStringList mrls = selectedURIs();
1083 if( !mrls.isEmpty() )
1084 THEDP->streamingDialog( NULL, mrls[0] );
1088 #include <QFileInfo>
1089 #include <QDesktopServices>
1090 void PLModel::popupExplore()
1093 playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
1097 input_item_t *p_input = p_item->p_input;
1098 char *psz_meta = input_item_GetURI( p_input );
1102 const char *psz_access;
1103 const char *psz_demux;
1105 input_SplitMRL( &psz_access, &psz_demux, &psz_path, psz_meta );
1107 if( EMPTY_STR( psz_access ) ||
1108 !strncasecmp( psz_access, "file", 4 ) ||
1109 !strncasecmp( psz_access, "dire", 4 ) )
1111 QFileInfo info( qfu( psz_meta ) );
1112 QDesktopServices::openUrl(
1113 QUrl::fromLocalFile( info.absolutePath() ) );
1122 #include <QInputDialog>
1123 void PLModel::popupAddNode()
1126 QString name = QInputDialog::getText( PlaylistDialog::getInstance( p_intf ),
1127 qtr( I_POP_ADD ), qtr( "Enter name for new node:" ),
1128 QLineEdit::Normal, QString(), &ok);
1129 if( !ok || name.isEmpty() ) return;
1131 playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
1135 playlist_NodeCreate( p_playlist, qtu( name ), p_item, 0, NULL );
1140 void PLModel::popupSortAsc()
1142 sort( i_popup_parent, i_popup_column, Qt::AscendingOrder );
1145 void PLModel::popupSortDesc()
1147 sort( i_popup_parent, i_popup_column, Qt::DescendingOrder );
1149 /**********************************************************************
1150 * Playlist callbacks
1151 **********************************************************************/
1152 static int PlaylistChanged( vlc_object_t *p_this, const char *psz_variable,
1153 vlc_value_t oval, vlc_value_t nval, void *param )
1155 PLModel *p_model = (PLModel *) param;
1156 PLEvent *event = new PLEvent( PLUpdate_Type, 0 );
1157 QApplication::postEvent( p_model, event );
1161 static int PlaylistNext( vlc_object_t *p_this, const char *psz_variable,
1162 vlc_value_t oval, vlc_value_t nval, void *param )
1164 PLModel *p_model = (PLModel *) param;
1165 PLEvent *event = new PLEvent( ItemUpdate_Type, oval.i_int );
1166 QApplication::postEvent( p_model, event );
1167 event = new PLEvent( ItemUpdate_Type, nval.i_int );
1168 QApplication::postEvent( p_model, event );
1172 static int ItemDeleted( vlc_object_t *p_this, const char *psz_variable,
1173 vlc_value_t oval, vlc_value_t nval, void *param )
1175 PLModel *p_model = (PLModel *) param;
1176 PLEvent *event = new PLEvent( ItemDelete_Type, nval.i_int );
1177 QApplication::postEvent( p_model, event );
1181 static int ItemAppended( vlc_object_t *p_this, const char *psz_variable,
1182 vlc_value_t oval, vlc_value_t nval, void *param )
1184 PLModel *p_model = (PLModel *) param;
1185 const playlist_add_t *p_add = (playlist_add_t *)nval.p_address;
1186 PLEvent *event = new PLEvent( p_add );
1187 QApplication::postEvent( p_model, event );