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() ?
134 static_cast<PLItem*>( index.internalPointer() ) :
137 input_item_t *pl_input = p_playlist->p_local_category->p_input;
138 input_item_t *ml_input = p_playlist->p_ml_category->p_input;
140 if( rootItem->i_id == p_playlist->p_root_onelevel->i_id
141 || rootItem->i_id == p_playlist->p_root_category->i_id )
143 if( item->p_input == pl_input
144 || item->p_input == ml_input)
145 flags |= Qt::ItemIsDropEnabled;
147 else if( rootItem->p_input == pl_input ||
148 rootItem->p_input == ml_input )
151 playlist_item_t *plItem =
152 playlist_ItemGetById( p_playlist, item->i_id );
154 if ( plItem && ( plItem->i_children > -1 ) )
155 flags |= Qt::ItemIsDropEnabled;
160 flags |= Qt::ItemIsDragEnabled;
165 /* A list of model indexes are a playlist */
166 QStringList PLModel::mimeTypes() const
169 types << "vlc/playlist-item-id";
173 QMimeData *PLModel::mimeData( const QModelIndexList &indexes ) const
175 QMimeData *mimeData = new QMimeData();
176 QByteArray encodedData;
177 QDataStream stream( &encodedData, QIODevice::WriteOnly );
178 QModelIndexList list;
180 foreach( const QModelIndex &index, indexes ) {
181 if( index.isValid() && index.column() == 0 )
187 foreach( const QModelIndex &index, list ) {
188 stream << itemId( index );
190 mimeData->setData( "vlc/playlist-item-id", encodedData );
195 bool PLModel::dropMimeData( const QMimeData *data, Qt::DropAction action,
196 int row, int column, const QModelIndex &parent )
198 if( data->hasFormat( "vlc/playlist-item-id" ) )
200 if( action == Qt::IgnoreAction )
205 playlist_item_t *p_parent;
207 if( !parent.isValid())
210 p_parent = playlist_ItemGetById( p_playlist, rootItem->i_id );
218 p_parent = playlist_ItemGetById( p_playlist, itemId ( parent ) );
220 if( !p_parent || p_parent->i_children == -1 )
228 ( p_parent->p_input == p_playlist->p_local_category->p_input
229 || p_parent->p_input == p_playlist->p_ml_category->p_input ) )
232 QByteArray encodedData = data->data( "vlc/playlist-item-id" );
233 QDataStream stream( &encodedData, QIODevice::ReadOnly );
237 while( !stream.atEnd() )
241 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, i_id );
247 input_item_t *p_input = p_item->p_input;
248 playlist_AddExt ( p_playlist,
249 p_input->psz_uri, p_input->psz_name,
250 PLAYLIST_APPEND | PLAYLIST_SPREPARSE, PLAYLIST_END,
252 p_input->i_options, p_input->ppsz_options, p_input->optflagc,
253 p_parent == p_playlist->p_local_category, true );
259 while( !stream.atEnd() )
265 int count = ids.size();
266 playlist_item_t *items[count];
267 for( int i = 0; i < count; i++ )
269 playlist_item_t *item = playlist_ItemGetById( p_playlist, ids[i] );
277 playlist_TreeMoveMany( p_playlist, count, items, p_parent,
278 (row == -1 ? p_parent->i_children : row) );
282 /*TODO: That's not a good idea to rebuild the playlist */
288 /* remove item with its id */
289 void PLModel::removeItem( int i_id )
291 PLItem *item = FindById( rootItem, i_id );
292 if( currentItem && item && currentItem->p_input == item->p_input ) currentItem = NULL;
293 if( item ) item->remove( item, i_depth );
296 /* callbacks and slots */
297 void PLModel::addCallbacks()
299 /* Some global changes happened -> Rebuild all */
300 var_AddCallback( p_playlist, "intf-change", PlaylistChanged, this );
301 /* We went to the next item
302 var_AddCallback( p_playlist, "item-current", PlaylistNext, this );
304 /* One item has been updated */
305 var_AddCallback( p_playlist, "playlist-item-append", ItemAppended, this );
306 var_AddCallback( p_playlist, "playlist-item-deleted", ItemDeleted, this );
309 void PLModel::delCallbacks()
312 var_DelCallback( p_playlist, "item-current", PlaylistNext, this );
314 var_DelCallback( p_playlist, "intf-change", PlaylistChanged, this );
315 var_DelCallback( p_playlist, "playlist-item-append", ItemAppended, this );
316 var_DelCallback( p_playlist, "playlist-item-deleted", ItemDeleted, this );
319 void PLModel::activateItem( const QModelIndex &index )
321 assert( index.isValid() );
322 PLItem *item = static_cast<PLItem*>(index.internalPointer());
325 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id );
326 activateItem( p_item );
330 /* Must be entered with lock */
331 void PLModel::activateItem( playlist_item_t *p_item )
333 if( !p_item ) return;
334 playlist_item_t *p_parent = p_item;
337 if( p_parent->i_id == rootItem->i_id ) break;
338 p_parent = p_parent->p_parent;
341 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, pl_Locked,
345 /****************** Base model mandatory implementations *****************/
346 QVariant PLModel::data( const QModelIndex &index, int role ) const
348 if( !index.isValid() ) return QVariant();
349 PLItem *item = static_cast<PLItem*>(index.internalPointer());
350 if( role == Qt::DisplayRole )
352 int running_index = -1;
356 if( i_depth == DEPTH_SEL )
358 vlc_mutex_lock( &item->p_input->lock );
359 QString returninfo = QString( qfu( item->p_input->psz_name ) );
360 vlc_mutex_unlock( &item->p_input->lock );
361 return QVariant(returninfo);
364 while( metadata < COLUMN_END )
366 if( i_showflags & metadata )
368 if( running_index == index.column() )
373 if( running_index != index.column() ) return QVariant();
376 if( metadata == COLUMN_NUMBER )
377 returninfo = QString::number( index.row() + 1 );
380 char *psz = psz_column_meta( item->p_input, metadata );
381 returninfo = QString( qfu( psz ) );
384 return QVariant( returninfo );
386 else if( role == Qt::DecorationRole && index.column() == 0 )
388 /* Use to segfault here because i_type wasn't always initialized */
389 if( item->p_input->i_type >= 0 )
390 return QVariant( PLModel::icons[item->p_input->i_type] );
392 else if( role == Qt::FontRole )
394 if( isCurrent( index ) )
396 QFont f; f.setBold( true ); return QVariant( f );
402 bool PLModel::isCurrent( const QModelIndex &index ) const
404 assert( index.isValid() );
405 if( !currentItem ) return false;
406 return static_cast<PLItem*>(index.internalPointer())->p_input == currentItem->p_input;
409 int PLModel::itemId( const QModelIndex &index ) const
411 assert( index.isValid() );
412 return static_cast<PLItem*>(index.internalPointer())->i_id;
415 QVariant PLModel::headerData( int section, Qt::Orientation orientation,
419 int running_index=-1;
420 if (orientation != Qt::Horizontal || role != Qt::DisplayRole)
423 if( i_depth == DEPTH_SEL ) return QVariant( QString("") );
425 while( metadata < COLUMN_END )
427 if( metadata & i_showflags )
429 if( running_index == section )
434 if( running_index != section ) return QVariant();
436 return QVariant( qfu( psz_column_title( metadata ) ) );
439 QModelIndex PLModel::index( int row, int column, const QModelIndex &parent )
443 if( !parent.isValid() )
444 parentItem = rootItem;
446 parentItem = static_cast<PLItem*>(parent.internalPointer());
448 PLItem *childItem = parentItem->child( row );
450 return createIndex( row, column, childItem );
452 return QModelIndex();
455 /* Return the index of a given item */
456 QModelIndex PLModel::index( PLItem *item, int column ) const
458 if( !item ) return QModelIndex();
459 const PLItem *parent = item->parent();
461 return createIndex( parent->children.lastIndexOf( item ),
463 return QModelIndex();
466 QModelIndex PLModel::parent( const QModelIndex &index ) const
468 if( !index.isValid() ) return QModelIndex();
470 PLItem *childItem = static_cast<PLItem*>(index.internalPointer());
473 msg_Err( p_playlist, "NULL CHILD" );
474 return QModelIndex();
477 PLItem *parentItem = childItem->parent();
478 if( !parentItem || parentItem == rootItem ) return QModelIndex();
479 if( !parentItem->parentItem )
481 msg_Err( p_playlist, "No parent parent, trying row 0 " );
482 msg_Err( p_playlist, "----- PLEASE REPORT THIS ------" );
483 return createIndex( 0, 0, parentItem );
485 QModelIndex ind = createIndex(parentItem->row(), 0, parentItem);
489 int PLModel::columnCount( const QModelIndex &i) const
493 if( i_depth == DEPTH_SEL ) return 1;
495 while( metadata < COLUMN_END )
497 if( metadata & i_showflags )
504 int PLModel::childrenCount( const QModelIndex &parent ) const
506 return rowCount( parent );
509 int PLModel::rowCount( const QModelIndex &parent ) const
513 if( !parent.isValid() )
514 parentItem = rootItem;
516 parentItem = static_cast<PLItem*>(parent.internalPointer());
518 return parentItem->childCount();
521 QStringList PLModel::selectedURIs()
524 for( int i = 0; i < current_selection.size(); i++ )
526 PLItem *item = static_cast<PLItem*>
527 (current_selection[i].internalPointer());
531 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id );
534 char *psz = input_item_GetURI( p_item->p_input );
547 /************************* General playlist status ***********************/
549 bool PLModel::hasRandom()
551 return var_GetBool( p_playlist, "random" );
553 bool PLModel::hasRepeat()
555 return var_GetBool( p_playlist, "repeat" );
557 bool PLModel::hasLoop()
559 return var_GetBool( p_playlist, "loop" );
561 void PLModel::setLoop( bool on )
563 var_SetBool( p_playlist, "loop", on ? true:false );
564 config_PutInt( p_playlist, "loop", on ? 1: 0 );
566 void PLModel::setRepeat( bool on )
568 var_SetBool( p_playlist, "repeat", on ? true:false );
569 config_PutInt( p_playlist, "repeat", on ? 1: 0 );
571 void PLModel::setRandom( bool on )
573 var_SetBool( p_playlist, "random", on ? true:false );
574 config_PutInt( p_playlist, "random", on ? 1: 0 );
577 /************************* Lookups *****************************/
579 PLItem *PLModel::FindById( PLItem *root, int i_id )
581 return FindInner( root, i_id, false );
584 PLItem *PLModel::FindByInput( PLItem *root, int i_id )
586 PLItem *result = FindInner( root, i_id, true );
590 #define CACHE( i, p ) { i_cached_id = i; p_cached_item = p; }
591 #define ICACHE( i, p ) { i_cached_input_id = i; p_cached_item_bi = p; }
593 PLItem * PLModel::FindInner( PLItem *root, int i_id, bool b_input )
595 if( ( !b_input && i_cached_id == i_id) ||
596 ( b_input && i_cached_input_id ==i_id ) )
598 return b_input ? p_cached_item_bi : p_cached_item;
601 if( !b_input && root->i_id == i_id )
606 else if( b_input && root->p_input->i_id == i_id )
608 ICACHE( i_id, root );
612 QList<PLItem *>::iterator it = root->children.begin();
613 while ( it != root->children.end() )
615 if( !b_input && (*it)->i_id == i_id )
617 CACHE( i_id, (*it) );
618 return p_cached_item;
620 else if( b_input && (*it)->p_input->i_id == i_id )
622 ICACHE( i_id, (*it) );
623 return p_cached_item_bi;
625 if( (*it)->children.size() )
627 PLItem *childFound = FindInner( (*it), i_id, b_input );
631 ICACHE( i_id, childFound )
633 CACHE( i_id, childFound )
645 /************************* Updates handling *****************************/
646 void PLModel::customEvent( QEvent *event )
648 int type = event->type();
649 if( type != ItemAppend_Type &&
650 type != ItemDelete_Type && type != PLUpdate_Type )
653 PLEvent *ple = static_cast<PLEvent *>(event);
655 if( type == ItemAppend_Type )
656 ProcessItemAppend( &ple->add );
657 else if( type == ItemDelete_Type )
658 ProcessItemRemoval( ple->i_id );
663 /**** Events processing ****/
664 void PLModel::ProcessInputItemUpdate( input_thread_t *p_input )
666 if( !p_input ) return;
667 ProcessInputItemUpdate( input_GetItem( p_input ) );
668 if( p_input && !( p_input->b_dead || !vlc_object_alive( p_input ) ) )
670 PLItem *item = FindByInput( rootItem, input_GetItem( p_input )->i_id );
672 emit currentChanged( index( item, 0 ) );
679 void PLModel::ProcessInputItemUpdate( input_item_t *p_item )
681 if( !p_item || p_item->i_id <= 0 ) return;
682 PLItem *item = FindByInput( rootItem, p_item->i_id );
684 UpdateTreeItem( item, true, true);
687 void PLModel::ProcessItemRemoval( int i_id )
689 if( i_id <= 0 ) return;
690 if( i_id == i_cached_id ) i_cached_id = -1;
691 i_cached_input_id = -1;
696 void PLModel::ProcessItemAppend( const playlist_add_t *p_add )
698 playlist_item_t *p_item = NULL;
699 PLItem *newItem = NULL;
701 PLItem *nodeItem = FindById( rootItem, p_add->i_node );
702 if( !nodeItem ) return;
705 p_item = playlist_ItemGetById( p_playlist, p_add->i_item );
706 if( !p_item || p_item->i_flags & PLAYLIST_DBL_FLAG ) goto end;
707 if( i_depth == DEPTH_SEL && p_item->p_parent &&
708 p_item->p_parent->i_id != rootItem->i_id )
711 newItem = new PLItem( p_item, nodeItem );
714 emit layoutAboutToBeChanged();
715 emit beginInsertRows( index( newItem, 0 ), nodeItem->childCount(), nodeItem->childCount()+1 );
716 nodeItem->appendChild( newItem );
717 emit endInsertRows();
718 emit layoutChanged();
719 UpdateTreeItem( newItem, true );
727 void PLModel::rebuild()
732 void PLModel::rebuild( playlist_item_t *p_root )
734 playlist_item_t* p_item;
735 /* Remove callbacks before locking to avoid deadlocks */
737 /* Invalidate cache */
738 i_cached_id = i_cached_input_id = -1;
740 emit layoutAboutToBeChanged();
745 if( rootItem->children.size() )
747 emit beginRemoveRows( index( rootItem, 0 ), 0,
748 rootItem->children.size() -1 );
749 qDeleteAll( rootItem->children );
750 rootItem->children.clear();
751 emit endRemoveRows();
758 rootItem = new PLItem( p_root );
761 /* Recreate from root */
762 UpdateNodeChildren( rootItem );
763 if( (p_item = playlist_CurrentPlayingItem(p_playlist)) )
764 currentItem = FindByInput( rootItem, p_item->p_input->i_id );
769 /* And signal the view */
770 emit currentChanged( index( currentItem, 0 ) );
771 emit layoutChanged();
775 /* This function must be entered WITH the playlist lock */
776 void PLModel::UpdateNodeChildren( PLItem *root )
778 emit layoutAboutToBeChanged();
779 playlist_item_t *p_node = playlist_ItemGetById( p_playlist, root->i_id );
780 UpdateNodeChildren( p_node, root );
781 emit layoutChanged();
784 /* This function must be entered WITH the playlist lock */
785 void PLModel::UpdateNodeChildren( playlist_item_t *p_node, PLItem *root )
787 for( int i = 0; i < p_node->i_children ; i++ )
789 if( p_node->pp_children[i]->i_flags & PLAYLIST_DBL_FLAG ) continue;
790 PLItem *newItem = new PLItem( p_node->pp_children[i], root );
791 emit beginInsertRows( index( newItem, 0 ), root->childCount(), root->childCount()+1 );
792 root->appendChild( newItem );
793 emit endInsertRows();
794 UpdateTreeItem( newItem, true, true );
795 if( i_depth == DEPTH_PL && p_node->pp_children[i]->i_children != -1 )
796 UpdateNodeChildren( p_node->pp_children[i], newItem );
800 /* Function doesn't need playlist-lock, as we don't touch playlist_item_t stuff here*/
801 void PLModel::UpdateTreeItem( PLItem *item, bool signal, bool force )
803 if ( !item || !item->p_input )
805 if( !force && i_depth == DEPTH_SEL && item->parentItem &&
806 item->parentItem->p_input != rootItem->p_input )
809 emit dataChanged( index( item, 0 ) , index( item, columnCount( QModelIndex() ) ) );
812 /************************* Actions ******************************/
815 * Deletion, here we have to do a ugly slow hack as we retrieve the full
816 * list of indexes to delete at once: when we delete a node and all of
817 * its children, we need to update the list.
818 * Todo: investigate whethere we can use ranges to be sure to delete all items?
820 void PLModel::doDelete( QModelIndexList selected )
822 for( int i = selected.size() -1 ; i >= 0; i-- )
824 QModelIndex index = selected[i];
825 if( index.column() != 0 ) continue;
826 PLItem *item = static_cast<PLItem*>(index.internalPointer());
829 if( item->children.size() )
830 recurseDelete( item->children, &selected );
831 doDeleteItem( item, &selected );
833 if( i > selected.size() ) i = selected.size();
837 void PLModel::recurseDelete( QList<PLItem*> children, QModelIndexList *fullList )
839 for( int i = children.size() - 1; i >= 0 ; i-- )
841 PLItem *item = children[i];
842 if( item->children.size() )
843 recurseDelete( item->children, fullList );
844 doDeleteItem( item, fullList );
848 void PLModel::doDeleteItem( PLItem *item, QModelIndexList *fullList )
850 QModelIndex deleteIndex = index( item, 0 );
851 fullList->removeAll( deleteIndex );
854 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id );
860 if( p_item->i_children == -1 )
861 playlist_DeleteFromInput( p_playlist, p_item->p_input, pl_Locked );
863 playlist_NodeDelete( p_playlist, p_item, true, false );
865 /* And finally, remove it from the tree */
866 emit beginRemoveRows( index( item->parentItem, 0), item->parentItem->children.indexOf( item ),
867 item->parentItem->children.indexOf( item )+1 );
868 item->remove( item, i_depth );
869 emit endRemoveRows();
872 /******* Volume III: Sorting and searching ********/
873 void PLModel::sort( int column, Qt::SortOrder order )
875 sort( rootItem->i_id, column, order );
878 void PLModel::sort( int i_root_id, int column, Qt::SortOrder order )
884 for( i_column = 1; i_column != COLUMN_END; i_column<<=1 )
886 if( ( shownFlags() & i_column ) )
888 if( column == i_index )
899 playlist_item_t *p_root = playlist_ItemGetById( p_playlist,
901 if( p_root && i_flag )
903 playlist_RecursiveNodeSort( p_playlist, p_root,
904 i_column_sorting( i_flag ),
905 order == Qt::AscendingOrder ?
906 ORDER_NORMAL : ORDER_REVERSE );
913 void PLModel::search( const QString& search_text )
915 /** \todo Fire the search with a small delay ? */
918 playlist_item_t *p_root = playlist_ItemGetById( p_playlist,
921 const char *psz_name = search_text.toUtf8().data();
922 playlist_LiveSearchUpdate( p_playlist , p_root, psz_name );
928 /*********** Popup *********/
929 void PLModel::popup( QModelIndex & index, QPoint &point, QModelIndexList list )
932 if( index.isValid() ) i_id = itemId( index );
933 else i_id = rootItem->i_id;
934 i_popup_column = index.column();
936 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, i_id );
939 i_popup_item = p_item->i_id;
940 i_popup_parent = p_item->p_parent ? p_item->p_parent->i_id : -1;
941 bool node = p_item->i_children > -1;
945 /* check whether we are in tree view */
946 playlist_item_t *p_up = p_item;
949 if ( p_up == p_playlist->p_root_category ) tree = true;
950 p_up = p_up->p_parent;
955 current_selection = list;
956 QMenu *menu = new QMenu;
957 if( index.isValid() )
959 menu->addAction( qtr(I_POP_PLAY), this, SLOT( popupPlay() ) );
960 menu->addAction( qtr(I_POP_DEL), this, SLOT( popupDel() ) );
961 menu->addSeparator();
962 menu->addAction( qtr(I_POP_STREAM), this, SLOT( popupStream() ) );
963 menu->addAction( qtr(I_POP_SAVE), this, SLOT( popupSave() ) );
964 menu->addSeparator();
965 menu->addAction( qtr(I_POP_INFO), this, SLOT( popupInfo() ) );
968 menu->addSeparator();
969 QMenu *sort_menu = menu->addMenu( qtr(I_POP_SORT) );
970 sort_menu->addAction( qtr( "Ascending" ),
971 this, SLOT( popupSortAsc() ) );
972 sort_menu->addAction( qtr( "Descending" ),
973 this, SLOT( popupSortDesc() ) );
977 menu->addAction( qtr(I_POP_ADD), this, SLOT( popupAddNode() ) );
978 if( index.isValid() )
980 menu->addSeparator();
981 menu->addAction( qtr( I_POP_EXPLORE ), this, SLOT( popupExplore() ) );
983 menu->popup( point );
990 void PLModel::viewchanged( int meta )
1003 /* UNUSED emit layoutAboutToBeChanged(); */
1004 index = __MIN( index, columnCount() );
1005 QModelIndex parent = createIndex( 0, 0, rootItem );
1007 if( i_showflags & meta )
1008 /* Removing columns */
1010 emit beginRemoveColumns( parent, index, index+1 );
1011 i_showflags &= ~( meta );
1012 getSettings()->setValue( "qt-pl-showflags", i_showflags );
1013 emit endRemoveColumns();
1017 /* Adding columns */
1018 emit beginInsertColumns( parent, index, index+1 );
1019 i_showflags |= meta;
1020 getSettings()->setValue( "qt-pl-showflags", i_showflags );
1021 emit endInsertColumns();
1023 emit columnsChanged( meta );
1028 void PLModel::popupDel()
1030 doDelete( current_selection );
1033 void PLModel::popupPlay()
1037 playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
1039 activateItem( p_item );
1044 void PLModel::popupInfo()
1047 playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
1051 input_item_t* p_input = p_item->p_input;
1052 vlc_gc_incref( p_input );
1054 MediaInfoDialog *mid = new MediaInfoDialog( p_intf, p_input );
1055 vlc_gc_decref( p_input );
1056 mid->setParent( PlaylistDialog::getInstance( p_intf ),
1063 void PLModel::popupStream()
1065 QStringList mrls = selectedURIs();
1066 if( !mrls.isEmpty() )
1067 THEDP->streamingDialog( NULL, mrls[0], false );
1071 void PLModel::popupSave()
1073 QStringList mrls = selectedURIs();
1074 if( !mrls.isEmpty() )
1075 THEDP->streamingDialog( NULL, mrls[0] );
1079 #include <QFileInfo>
1080 #include <QDesktopServices>
1081 void PLModel::popupExplore()
1084 playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
1088 input_item_t *p_input = p_item->p_input;
1089 char *psz_meta = input_item_GetURI( p_input );
1093 const char *psz_access;
1094 const char *psz_demux;
1096 input_SplitMRL( &psz_access, &psz_demux, &psz_path, psz_meta );
1098 if( EMPTY_STR( psz_access ) ||
1099 !strncasecmp( psz_access, "file", 4 ) ||
1100 !strncasecmp( psz_access, "dire", 4 ) )
1102 QFileInfo info( qfu( psz_meta ) );
1103 QDesktopServices::openUrl(
1104 QUrl::fromLocalFile( info.absolutePath() ) );
1113 #include <QInputDialog>
1114 void PLModel::popupAddNode()
1117 QString name = QInputDialog::getText( PlaylistDialog::getInstance( p_intf ),
1118 qtr( I_POP_ADD ), qtr( "Enter name for new node:" ),
1119 QLineEdit::Normal, QString(), &ok);
1120 if( !ok || name.isEmpty() ) return;
1122 playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
1126 playlist_NodeCreate( p_playlist, qtu( name ), p_item, 0, NULL );
1131 void PLModel::popupSortAsc()
1133 sort( i_popup_item, i_popup_column, Qt::AscendingOrder );
1136 void PLModel::popupSortDesc()
1138 sort( i_popup_item, i_popup_column, Qt::DescendingOrder );
1140 /**********************************************************************
1141 * Playlist callbacks
1142 **********************************************************************/
1143 static int PlaylistChanged( vlc_object_t *p_this, const char *psz_variable,
1144 vlc_value_t oval, vlc_value_t nval, void *param )
1146 PLModel *p_model = (PLModel *) param;
1147 PLEvent *event = new PLEvent( PLUpdate_Type, 0 );
1148 QApplication::postEvent( p_model, event );
1152 static int PlaylistNext( 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( ItemUpdate_Type, oval.i_int );
1157 QApplication::postEvent( p_model, event );
1158 event = new PLEvent( ItemUpdate_Type, nval.i_int );
1159 QApplication::postEvent( p_model, event );
1163 static int ItemDeleted( vlc_object_t *p_this, const char *psz_variable,
1164 vlc_value_t oval, vlc_value_t nval, void *param )
1166 PLModel *p_model = (PLModel *) param;
1167 PLEvent *event = new PLEvent( ItemDelete_Type, nval.i_int );
1168 QApplication::postEvent( p_model, event );
1172 static int ItemAppended( 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 const playlist_add_t *p_add = (playlist_add_t *)nval.p_address;
1177 PLEvent *event = new PLEvent( p_add );
1178 QApplication::postEvent( p_model, event );