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* ) );
115 playlist_item_t *p_item;
116 /* Check if there's allready some item playing when playlist
117 * model is created, if so, tell model that it's currentone
119 if( (p_item = playlist_CurrentPlayingItem(p_playlist)) )
121 currentItem = FindByInput( rootItem,
122 p_item->p_input->i_id );
123 emit currentChanged( index( currentItem, 0 ) );
131 getSettings()->setValue( "qt-pl-showflags", i_showflags );
136 Qt::DropActions PLModel::supportedDropActions() const
138 return Qt::CopyAction; /* Why not Qt::MoveAction */
141 Qt::ItemFlags PLModel::flags( const QModelIndex &index ) const
143 Qt::ItemFlags flags = QAbstractItemModel::flags( index );
145 PLItem *item = index.isValid() ?
146 static_cast<PLItem*>( index.internalPointer() ) :
149 input_item_t *pl_input = p_playlist->p_local_category->p_input;
150 input_item_t *ml_input = p_playlist->p_ml_category->p_input;
152 if( rootItem->i_id == p_playlist->p_root_onelevel->i_id
153 || rootItem->i_id == p_playlist->p_root_category->i_id )
155 if( item->p_input == pl_input
156 || item->p_input == ml_input)
157 flags |= Qt::ItemIsDropEnabled;
159 else if( rootItem->p_input == pl_input ||
160 rootItem->p_input == ml_input )
163 playlist_item_t *plItem =
164 playlist_ItemGetById( p_playlist, item->i_id );
166 if ( plItem && ( plItem->i_children > -1 ) )
167 flags |= Qt::ItemIsDropEnabled;
172 flags |= Qt::ItemIsDragEnabled;
177 /* A list of model indexes are a playlist */
178 QStringList PLModel::mimeTypes() const
181 types << "vlc/playlist-item-id";
185 QMimeData *PLModel::mimeData( const QModelIndexList &indexes ) const
187 QMimeData *mimeData = new QMimeData();
188 QByteArray encodedData;
189 QDataStream stream( &encodedData, QIODevice::WriteOnly );
190 QModelIndexList list;
192 foreach( const QModelIndex &index, indexes ) {
193 if( index.isValid() && index.column() == 0 )
199 foreach( const QModelIndex &index, list ) {
200 stream << itemId( index );
202 mimeData->setData( "vlc/playlist-item-id", encodedData );
207 bool PLModel::dropMimeData( const QMimeData *data, Qt::DropAction action,
208 int row, int column, const QModelIndex &parent )
210 if( data->hasFormat( "vlc/playlist-item-id" ) )
212 if( action == Qt::IgnoreAction )
217 playlist_item_t *p_parent;
219 if( !parent.isValid())
222 p_parent = playlist_ItemGetById( p_playlist, rootItem->i_id );
230 p_parent = playlist_ItemGetById( p_playlist, itemId ( parent ) );
232 if( !p_parent || p_parent->i_children == -1 )
240 ( p_parent->p_input == p_playlist->p_local_category->p_input
241 || p_parent->p_input == p_playlist->p_ml_category->p_input ) )
244 QByteArray encodedData = data->data( "vlc/playlist-item-id" );
245 QDataStream stream( &encodedData, QIODevice::ReadOnly );
249 while( !stream.atEnd() )
253 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, i_id );
259 input_item_t *p_input = p_item->p_input;
260 playlist_AddExt ( p_playlist,
261 p_input->psz_uri, p_input->psz_name,
262 PLAYLIST_APPEND | PLAYLIST_SPREPARSE, PLAYLIST_END,
264 p_input->i_options, p_input->ppsz_options, p_input->optflagc,
265 p_parent == p_playlist->p_local_category, true );
271 while( !stream.atEnd() )
277 int count = ids.size();
278 playlist_item_t *items[count];
279 for( int i = 0; i < count; i++ )
281 playlist_item_t *item = playlist_ItemGetById( p_playlist, ids[i] );
289 playlist_TreeMoveMany( p_playlist, count, items, p_parent,
290 (row == -1 ? p_parent->i_children : row) );
294 /*TODO: That's not a good idea to rebuild the playlist */
300 /* remove item with its id */
301 void PLModel::removeItem( int i_id )
303 PLItem *item = FindById( rootItem, i_id );
304 if( currentItem && item && currentItem->p_input == item->p_input ) currentItem = NULL;
305 if( item ) item->remove( item, i_depth );
308 /* callbacks and slots */
309 void PLModel::addCallbacks()
311 /* Some global changes happened -> Rebuild all */
312 var_AddCallback( p_playlist, "intf-change", PlaylistChanged, this );
313 /* We went to the next item
314 var_AddCallback( p_playlist, "item-current", PlaylistNext, this );
316 /* One item has been updated */
317 var_AddCallback( p_playlist, "playlist-item-append", ItemAppended, this );
318 var_AddCallback( p_playlist, "playlist-item-deleted", ItemDeleted, this );
321 void PLModel::delCallbacks()
324 var_DelCallback( p_playlist, "item-current", PlaylistNext, this );
326 var_DelCallback( p_playlist, "intf-change", PlaylistChanged, this );
327 var_DelCallback( p_playlist, "playlist-item-append", ItemAppended, this );
328 var_DelCallback( p_playlist, "playlist-item-deleted", ItemDeleted, this );
331 void PLModel::activateItem( const QModelIndex &index )
333 assert( index.isValid() );
334 PLItem *item = static_cast<PLItem*>(index.internalPointer());
337 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id );
338 activateItem( p_item );
342 /* Must be entered with lock */
343 void PLModel::activateItem( playlist_item_t *p_item )
345 if( !p_item ) return;
346 playlist_item_t *p_parent = p_item;
349 if( p_parent->i_id == rootItem->i_id ) break;
350 p_parent = p_parent->p_parent;
353 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, pl_Locked,
357 /****************** Base model mandatory implementations *****************/
358 QVariant PLModel::data( const QModelIndex &index, int role ) const
360 if( !index.isValid() ) return QVariant();
361 PLItem *item = static_cast<PLItem*>(index.internalPointer());
362 if( role == Qt::DisplayRole )
364 int running_index = -1;
368 if( i_depth == DEPTH_SEL )
370 vlc_mutex_lock( &item->p_input->lock );
371 QString returninfo = QString( qfu( item->p_input->psz_name ) );
372 vlc_mutex_unlock( &item->p_input->lock );
373 return QVariant(returninfo);
376 while( metadata < COLUMN_END )
378 if( i_showflags & metadata )
380 if( running_index == index.column() )
385 if( running_index != index.column() ) return QVariant();
388 if( metadata == COLUMN_NUMBER )
389 returninfo = QString::number( index.row() + 1 );
392 char *psz = psz_column_meta( item->p_input, metadata );
393 returninfo = QString( qfu( psz ) );
396 return QVariant( returninfo );
398 else if( role == Qt::DecorationRole && index.column() == 0 )
400 /* Use to segfault here because i_type wasn't always initialized */
401 if( item->p_input->i_type >= 0 )
402 return QVariant( PLModel::icons[item->p_input->i_type] );
404 else if( role == Qt::FontRole )
406 if( isCurrent( index ) )
408 QFont f; f.setBold( true ); return QVariant( f );
414 bool PLModel::isCurrent( const QModelIndex &index ) const
416 assert( index.isValid() );
417 if( !currentItem ) return false;
418 return static_cast<PLItem*>(index.internalPointer())->p_input == currentItem->p_input;
421 int PLModel::itemId( const QModelIndex &index ) const
423 assert( index.isValid() );
424 return static_cast<PLItem*>(index.internalPointer())->i_id;
427 QVariant PLModel::headerData( int section, Qt::Orientation orientation,
431 int running_index=-1;
432 if (orientation != Qt::Horizontal || role != Qt::DisplayRole)
435 if( i_depth == DEPTH_SEL ) return QVariant( QString("") );
437 while( metadata < COLUMN_END )
439 if( metadata & i_showflags )
441 if( running_index == section )
446 if( running_index != section ) return QVariant();
448 return QVariant( qfu( psz_column_title( metadata ) ) );
451 QModelIndex PLModel::index( int row, int column, const QModelIndex &parent )
455 if( !parent.isValid() )
456 parentItem = rootItem;
458 parentItem = static_cast<PLItem*>(parent.internalPointer());
460 PLItem *childItem = parentItem->child( row );
462 return createIndex( row, column, childItem );
464 return QModelIndex();
467 /* Return the index of a given item */
468 QModelIndex PLModel::index( PLItem *item, int column ) const
470 if( !item ) return QModelIndex();
471 const PLItem *parent = item->parent();
473 return createIndex( parent->children.lastIndexOf( item ),
475 return QModelIndex();
478 QModelIndex PLModel::parent( const QModelIndex &index ) const
480 if( !index.isValid() ) return QModelIndex();
482 PLItem *childItem = static_cast<PLItem*>(index.internalPointer());
485 msg_Err( p_playlist, "NULL CHILD" );
486 return QModelIndex();
489 PLItem *parentItem = childItem->parent();
490 if( !parentItem || parentItem == rootItem ) return QModelIndex();
491 if( !parentItem->parentItem )
493 msg_Err( p_playlist, "No parent parent, trying row 0 " );
494 msg_Err( p_playlist, "----- PLEASE REPORT THIS ------" );
495 return createIndex( 0, 0, parentItem );
497 QModelIndex ind = createIndex(parentItem->row(), 0, parentItem);
501 int PLModel::columnCount( const QModelIndex &i) const
505 if( i_depth == DEPTH_SEL ) return 1;
507 while( metadata < COLUMN_END )
509 if( metadata & i_showflags )
516 int PLModel::childrenCount( const QModelIndex &parent ) const
518 return rowCount( parent );
521 int PLModel::rowCount( const QModelIndex &parent ) const
525 if( !parent.isValid() )
526 parentItem = rootItem;
528 parentItem = static_cast<PLItem*>(parent.internalPointer());
530 return parentItem->childCount();
533 QStringList PLModel::selectedURIs()
536 for( int i = 0; i < current_selection.size(); i++ )
538 PLItem *item = static_cast<PLItem*>
539 (current_selection[i].internalPointer());
543 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id );
546 char *psz = input_item_GetURI( p_item->p_input );
559 /************************* General playlist status ***********************/
561 bool PLModel::hasRandom()
563 return var_GetBool( p_playlist, "random" );
565 bool PLModel::hasRepeat()
567 return var_GetBool( p_playlist, "repeat" );
569 bool PLModel::hasLoop()
571 return var_GetBool( p_playlist, "loop" );
573 void PLModel::setLoop( bool on )
575 var_SetBool( p_playlist, "loop", on ? true:false );
576 config_PutInt( p_playlist, "loop", on ? 1: 0 );
578 void PLModel::setRepeat( bool on )
580 var_SetBool( p_playlist, "repeat", on ? true:false );
581 config_PutInt( p_playlist, "repeat", on ? 1: 0 );
583 void PLModel::setRandom( bool on )
585 var_SetBool( p_playlist, "random", on ? true:false );
586 config_PutInt( p_playlist, "random", on ? 1: 0 );
589 /************************* Lookups *****************************/
591 PLItem *PLModel::FindById( PLItem *root, int i_id )
593 return FindInner( root, i_id, false );
596 PLItem *PLModel::FindByInput( PLItem *root, int i_id )
598 PLItem *result = FindInner( root, i_id, true );
602 #define CACHE( i, p ) { i_cached_id = i; p_cached_item = p; }
603 #define ICACHE( i, p ) { i_cached_input_id = i; p_cached_item_bi = p; }
605 PLItem * PLModel::FindInner( PLItem *root, int i_id, bool b_input )
607 if( ( !b_input && i_cached_id == i_id) ||
608 ( b_input && i_cached_input_id ==i_id ) )
610 return b_input ? p_cached_item_bi : p_cached_item;
613 if( !b_input && root->i_id == i_id )
618 else if( b_input && root->p_input->i_id == i_id )
620 ICACHE( i_id, root );
624 QList<PLItem *>::iterator it = root->children.begin();
625 while ( it != root->children.end() )
627 if( !b_input && (*it)->i_id == i_id )
629 CACHE( i_id, (*it) );
630 return p_cached_item;
632 else if( b_input && (*it)->p_input->i_id == i_id )
634 ICACHE( i_id, (*it) );
635 return p_cached_item_bi;
637 if( (*it)->children.size() )
639 PLItem *childFound = FindInner( (*it), i_id, b_input );
643 ICACHE( i_id, childFound )
645 CACHE( i_id, childFound )
657 /************************* Updates handling *****************************/
658 void PLModel::customEvent( QEvent *event )
660 int type = event->type();
661 if( type != ItemAppend_Type &&
662 type != ItemDelete_Type && type != PLUpdate_Type )
665 PLEvent *ple = static_cast<PLEvent *>(event);
667 if( type == ItemAppend_Type )
668 ProcessItemAppend( &ple->add );
669 else if( type == ItemDelete_Type )
670 ProcessItemRemoval( ple->i_id );
675 /**** Events processing ****/
676 void PLModel::ProcessInputItemUpdate( input_thread_t *p_input )
678 if( !p_input ) return;
679 ProcessInputItemUpdate( input_GetItem( p_input ) );
680 if( p_input && !( p_input->b_dead || !vlc_object_alive( p_input ) ) )
682 PLItem *item = FindByInput( rootItem, input_GetItem( p_input )->i_id );
684 emit currentChanged( index( item, 0 ) );
691 void PLModel::ProcessInputItemUpdate( input_item_t *p_item )
693 if( !p_item || p_item->i_id <= 0 ) return;
694 PLItem *item = FindByInput( rootItem, p_item->i_id );
696 UpdateTreeItem( item, true, true);
699 void PLModel::ProcessItemRemoval( int i_id )
701 if( i_id <= 0 ) return;
702 if( i_id == i_cached_id ) i_cached_id = -1;
703 i_cached_input_id = -1;
708 void PLModel::ProcessItemAppend( const playlist_add_t *p_add )
710 playlist_item_t *p_item = NULL;
711 PLItem *newItem = NULL;
713 PLItem *nodeItem = FindById( rootItem, p_add->i_node );
714 if( !nodeItem ) return;
717 p_item = playlist_ItemGetById( p_playlist, p_add->i_item );
718 if( !p_item || p_item->i_flags & PLAYLIST_DBL_FLAG ) goto end;
719 if( i_depth == DEPTH_SEL && p_item->p_parent &&
720 p_item->p_parent->i_id != rootItem->i_id )
723 newItem = new PLItem( p_item, nodeItem );
726 emit layoutAboutToBeChanged();
727 emit beginInsertRows( index( newItem, 0 ), nodeItem->childCount(), nodeItem->childCount()+1 );
728 nodeItem->appendChild( newItem );
729 emit endInsertRows();
730 emit layoutChanged();
731 UpdateTreeItem( newItem, true );
739 void PLModel::rebuild()
744 void PLModel::rebuild( playlist_item_t *p_root )
746 playlist_item_t* p_item;
747 /* Remove callbacks before locking to avoid deadlocks */
749 /* Invalidate cache */
750 i_cached_id = i_cached_input_id = -1;
752 emit layoutAboutToBeChanged();
757 if( rootItem->children.size() )
759 emit beginRemoveRows( index( rootItem, 0 ), 0,
760 rootItem->children.size() -1 );
761 qDeleteAll( rootItem->children );
762 rootItem->children.clear();
763 emit endRemoveRows();
770 rootItem = new PLItem( p_root );
773 /* Recreate from root */
774 UpdateNodeChildren( rootItem );
775 if( (p_item = playlist_CurrentPlayingItem(p_playlist)) )
777 currentItem = FindByInput( rootItem,
778 p_item->p_input->i_id );
781 UpdateTreeItem( currentItem, true, false );
790 /* And signal the view */
791 emit layoutChanged();
795 /* This function must be entered WITH the playlist lock */
796 void PLModel::UpdateNodeChildren( PLItem *root )
798 emit layoutAboutToBeChanged();
799 playlist_item_t *p_node = playlist_ItemGetById( p_playlist, root->i_id );
800 UpdateNodeChildren( p_node, root );
801 emit layoutChanged();
804 /* This function must be entered WITH the playlist lock */
805 void PLModel::UpdateNodeChildren( playlist_item_t *p_node, PLItem *root )
807 for( int i = 0; i < p_node->i_children ; i++ )
809 if( p_node->pp_children[i]->i_flags & PLAYLIST_DBL_FLAG ) continue;
810 PLItem *newItem = new PLItem( p_node->pp_children[i], root );
811 emit beginInsertRows( index( newItem, 0 ), root->childCount(), root->childCount()+1 );
812 root->appendChild( newItem );
813 emit endInsertRows();
814 UpdateTreeItem( newItem, true, true );
815 if( i_depth == DEPTH_PL && p_node->pp_children[i]->i_children != -1 )
816 UpdateNodeChildren( p_node->pp_children[i], newItem );
820 /* Function doesn't need playlist-lock, as we don't touch playlist_item_t stuff here*/
821 void PLModel::UpdateTreeItem( PLItem *item, bool signal, bool force )
823 if ( !item || !item->p_input )
825 if( !force && i_depth == DEPTH_SEL && item->parentItem &&
826 item->parentItem->p_input != rootItem->p_input )
829 emit dataChanged( index( item, 0 ) , index( item, columnCount( QModelIndex() ) ) );
832 /************************* Actions ******************************/
835 * Deletion, here we have to do a ugly slow hack as we retrieve the full
836 * list of indexes to delete at once: when we delete a node and all of
837 * its children, we need to update the list.
838 * Todo: investigate whethere we can use ranges to be sure to delete all items?
840 void PLModel::doDelete( QModelIndexList selected )
842 for( int i = selected.size() -1 ; i >= 0; i-- )
844 QModelIndex index = selected[i];
845 if( index.column() != 0 ) continue;
846 PLItem *item = static_cast<PLItem*>(index.internalPointer());
849 if( item->children.size() )
850 recurseDelete( item->children, &selected );
851 doDeleteItem( item, &selected );
853 if( i > selected.size() ) i = selected.size();
857 void PLModel::recurseDelete( QList<PLItem*> children, QModelIndexList *fullList )
859 for( int i = children.size() - 1; i >= 0 ; i-- )
861 PLItem *item = children[i];
862 if( item->children.size() )
863 recurseDelete( item->children, fullList );
864 doDeleteItem( item, fullList );
868 void PLModel::doDeleteItem( PLItem *item, QModelIndexList *fullList )
870 QModelIndex deleteIndex = index( item, 0 );
871 fullList->removeAll( deleteIndex );
874 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id );
880 if( p_item->i_children == -1 )
881 playlist_DeleteFromInput( p_playlist, p_item->p_input, pl_Locked );
883 playlist_NodeDelete( p_playlist, p_item, true, false );
885 /* And finally, remove it from the tree */
886 emit beginRemoveRows( index( item->parentItem, 0), item->parentItem->children.indexOf( item ),
887 item->parentItem->children.indexOf( item )+1 );
888 item->remove( item, i_depth );
889 emit endRemoveRows();
892 /******* Volume III: Sorting and searching ********/
893 void PLModel::sort( int column, Qt::SortOrder order )
899 for( i_column = 1; i_column != COLUMN_END; i_column<<=1 )
901 if( ( shownFlags() & i_column ) )
903 if( column == i_index )
914 playlist_item_t *p_root = playlist_ItemGetById( p_playlist,
916 if( p_root && i_flag )
918 playlist_RecursiveNodeSort( p_playlist, p_root,
919 i_column_sorting( i_flag ),
920 order == Qt::AscendingOrder ?
921 ORDER_NORMAL : ORDER_REVERSE );
928 void PLModel::search( const QString& search_text )
930 /** \todo Fire the search with a small delay ? */
933 playlist_item_t *p_root = playlist_ItemGetById( p_playlist,
936 const char *psz_name = search_text.toUtf8().data();
937 playlist_LiveSearchUpdate( p_playlist , p_root, psz_name );
943 /*********** Popup *********/
944 void PLModel::popup( QModelIndex & index, QPoint &point, QModelIndexList list )
948 if( index.isValid() ) i_id = itemId( index );
949 else i_id = rootItem->i_id;
950 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, i_id );
953 i_popup_item = p_item->i_id;
954 i_popup_parent = p_item->p_parent ? p_item->p_parent->i_id : -1;
955 bool node = p_item->i_children > -1;
959 /* check whether we are in tree view */
960 playlist_item_t *p_up = p_item;
963 if ( p_up == p_playlist->p_root_category ) tree = true;
964 p_up = p_up->p_parent;
969 current_selection = list;
970 QMenu *menu = new QMenu;
971 if( index.isValid() )
973 menu->addAction( qtr(I_POP_PLAY), this, SLOT( popupPlay() ) );
974 menu->addAction( qtr(I_POP_DEL), this, SLOT( popupDel() ) );
975 menu->addSeparator();
976 menu->addAction( qtr(I_POP_STREAM), this, SLOT( popupStream() ) );
977 menu->addAction( qtr(I_POP_SAVE), this, SLOT( popupSave() ) );
978 menu->addSeparator();
979 menu->addAction( qtr(I_POP_INFO), this, SLOT( popupInfo() ) );
982 menu->addSeparator();
983 menu->addAction( qtr(I_POP_SORT), this, SLOT( popupSort() ) );
987 menu->addAction( qtr(I_POP_ADD), this, SLOT( popupAddNode() ) );
988 if( index.isValid() )
990 menu->addSeparator();
991 menu->addAction( qtr( I_POP_EXPLORE ), this, SLOT( popupExplore() ) );
993 menu->popup( point );
1000 void PLModel::viewchanged( int meta )
1013 /* UNUSED emit layoutAboutToBeChanged(); */
1014 index = __MIN( index, columnCount() );
1015 QModelIndex parent = createIndex( 0, 0, rootItem );
1017 if( i_showflags & meta )
1018 /* Removing columns */
1020 emit beginRemoveColumns( parent, index, index+1 );
1021 i_showflags &= ~( meta );
1022 getSettings()->setValue( "qt-pl-showflags", i_showflags );
1023 emit endRemoveColumns();
1027 /* Adding columns */
1028 emit beginInsertColumns( parent, index, index+1 );
1029 i_showflags |= meta;
1030 getSettings()->setValue( "qt-pl-showflags", i_showflags );
1031 emit endInsertColumns();
1033 emit columnsChanged( meta );
1038 void PLModel::popupDel()
1040 doDelete( current_selection );
1043 void PLModel::popupPlay()
1047 playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
1049 activateItem( p_item );
1054 void PLModel::popupInfo()
1057 playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
1061 input_item_t* p_input = p_item->p_input;
1062 vlc_gc_incref( p_input );
1064 MediaInfoDialog *mid = new MediaInfoDialog( p_intf, p_input );
1065 vlc_gc_decref( p_input );
1066 mid->setParent( PlaylistDialog::getInstance( p_intf ),
1073 void PLModel::popupStream()
1075 QStringList mrls = selectedURIs();
1076 if( !mrls.isEmpty() )
1077 THEDP->streamingDialog( NULL, mrls[0], false );
1081 void PLModel::popupSave()
1083 QStringList mrls = selectedURIs();
1084 if( !mrls.isEmpty() )
1085 THEDP->streamingDialog( NULL, mrls[0] );
1089 #include <QFileInfo>
1090 #include <QDesktopServices>
1091 void PLModel::popupExplore()
1094 playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
1098 input_item_t *p_input = p_item->p_input;
1099 char *psz_meta = input_item_GetURI( p_input );
1103 const char *psz_access;
1104 const char *psz_demux;
1106 input_SplitMRL( &psz_access, &psz_demux, &psz_path, psz_meta );
1108 if( EMPTY_STR( psz_access ) ||
1109 !strncasecmp( psz_access, "file", 4 ) ||
1110 !strncasecmp( psz_access, "dire", 4 ) )
1112 QFileInfo info( qfu( psz_meta ) );
1113 QDesktopServices::openUrl(
1114 QUrl::fromLocalFile( info.absolutePath() ) );
1123 #include <QInputDialog>
1124 void PLModel::popupAddNode()
1127 QString name = QInputDialog::getText( PlaylistDialog::getInstance( p_intf ),
1128 qtr( I_POP_ADD ), qtr( "Enter name for new node:" ),
1129 QLineEdit::Normal, QString(), &ok);
1130 if( !ok || name.isEmpty() ) return;
1132 playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
1136 playlist_NodeCreate( p_playlist, qtu( name ), p_item, 0, NULL );
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 );