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;
162 playlist_item_t *plItem =
163 playlist_ItemGetById( p_playlist, item->i_id );
164 if ( plItem && ( plItem->i_children > -1 ) &&
165 ( rootItem->p_input == pl_input ||
166 rootItem->p_input == ml_input ) )
167 flags |= Qt::ItemIsDropEnabled;
169 flags |= Qt::ItemIsDragEnabled;
175 /* A list of model indexes are a playlist */
176 QStringList PLModel::mimeTypes() const
179 types << "vlc/playlist-item-id";
183 QMimeData *PLModel::mimeData( const QModelIndexList &indexes ) const
185 QMimeData *mimeData = new QMimeData();
186 QByteArray encodedData;
187 QDataStream stream( &encodedData, QIODevice::WriteOnly );
188 QModelIndexList list;
190 foreach( const QModelIndex &index, indexes ) {
191 if( index.isValid() && index.column() == 0 )
197 foreach( const QModelIndex &index, list ) {
198 stream << itemId( index );
200 mimeData->setData( "vlc/playlist-item-id", encodedData );
205 bool PLModel::dropMimeData( const QMimeData *data, Qt::DropAction action,
206 int row, int column, const QModelIndex &parent )
208 if( data->hasFormat( "vlc/playlist-item-id" ) )
210 if( action == Qt::IgnoreAction )
215 playlist_item_t *p_parent;
217 if( !parent.isValid())
220 p_parent = playlist_ItemGetById( p_playlist, rootItem->i_id );
228 p_parent = playlist_ItemGetById( p_playlist, itemId ( parent ) );
230 if( !p_parent || p_parent->i_children == -1 )
238 ( p_parent->p_input == p_playlist->p_local_category->p_input
239 || p_parent->p_input == p_playlist->p_ml_category->p_input ) )
242 QByteArray encodedData = data->data( "vlc/playlist-item-id" );
243 QDataStream stream( &encodedData, QIODevice::ReadOnly );
247 while( !stream.atEnd() )
251 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, i_id );
257 input_item_t *p_input = p_item->p_input;
258 playlist_AddExt ( p_playlist,
259 p_input->psz_uri, p_input->psz_name,
260 PLAYLIST_APPEND | PLAYLIST_SPREPARSE, PLAYLIST_END,
262 p_input->i_options, p_input->ppsz_options, p_input->optflagc,
263 p_parent == p_playlist->p_local_category, true );
269 while( !stream.atEnd() )
275 int count = ids.size();
276 playlist_item_t *items[count];
277 for( int i = 0; i < count; i++ )
279 playlist_item_t *item = playlist_ItemGetById( p_playlist, ids[i] );
287 playlist_TreeMoveMany( p_playlist, count, items, p_parent,
288 (row == -1 ? p_parent->i_children : row) );
292 /*TODO: That's not a good idea to rebuild the playlist */
298 /* remove item with its id */
299 void PLModel::removeItem( int i_id )
301 PLItem *item = FindById( rootItem, i_id );
302 if( currentItem && item && currentItem->p_input == item->p_input ) currentItem = NULL;
303 if( item ) item->remove( item, i_depth );
306 /* callbacks and slots */
307 void PLModel::addCallbacks()
309 /* Some global changes happened -> Rebuild all */
310 var_AddCallback( p_playlist, "intf-change", PlaylistChanged, this );
311 /* We went to the next item
312 var_AddCallback( p_playlist, "item-current", PlaylistNext, this );
314 /* One item has been updated */
315 var_AddCallback( p_playlist, "playlist-item-append", ItemAppended, this );
316 var_AddCallback( p_playlist, "playlist-item-deleted", ItemDeleted, this );
319 void PLModel::delCallbacks()
322 var_DelCallback( p_playlist, "item-current", PlaylistNext, this );
324 var_DelCallback( p_playlist, "intf-change", PlaylistChanged, this );
325 var_DelCallback( p_playlist, "playlist-item-append", ItemAppended, this );
326 var_DelCallback( p_playlist, "playlist-item-deleted", ItemDeleted, this );
329 void PLModel::activateItem( const QModelIndex &index )
331 assert( index.isValid() );
332 PLItem *item = static_cast<PLItem*>(index.internalPointer());
335 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id );
336 activateItem( p_item );
340 /* Must be entered with lock */
341 void PLModel::activateItem( playlist_item_t *p_item )
343 if( !p_item ) return;
344 playlist_item_t *p_parent = p_item;
347 if( p_parent->i_id == rootItem->i_id ) break;
348 p_parent = p_parent->p_parent;
351 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, pl_Locked,
355 /****************** Base model mandatory implementations *****************/
356 QVariant PLModel::data( const QModelIndex &index, int role ) const
358 if( !index.isValid() ) return QVariant();
359 PLItem *item = static_cast<PLItem*>(index.internalPointer());
360 if( role == Qt::DisplayRole )
362 int running_index = -1;
366 if( i_depth == DEPTH_SEL )
368 vlc_mutex_lock( &item->p_input->lock );
369 QString returninfo = QString( qfu( item->p_input->psz_name ) );
370 vlc_mutex_unlock( &item->p_input->lock );
371 return QVariant(returninfo);
374 while( metadata < COLUMN_END )
376 if( i_showflags & metadata )
378 if( running_index == index.column() )
383 if( running_index != index.column() ) return QVariant();
386 if( metadata == COLUMN_NUMBER )
387 returninfo = QString::number( index.row() + 1 );
390 char *psz = psz_column_meta( item->p_input, metadata );
391 returninfo = QString( qfu( psz ) );
394 return QVariant( returninfo );
396 else if( role == Qt::DecorationRole && index.column() == 0 )
398 /* Use to segfault here because i_type wasn't always initialized */
399 if( item->p_input->i_type >= 0 )
400 return QVariant( PLModel::icons[item->p_input->i_type] );
402 else if( role == Qt::FontRole )
404 if( isCurrent( index ) )
406 QFont f; f.setBold( true ); return QVariant( f );
412 bool PLModel::isCurrent( const QModelIndex &index ) const
414 assert( index.isValid() );
415 if( !currentItem ) return false;
416 return static_cast<PLItem*>(index.internalPointer())->p_input == currentItem->p_input;
419 int PLModel::itemId( const QModelIndex &index ) const
421 assert( index.isValid() );
422 return static_cast<PLItem*>(index.internalPointer())->i_id;
425 QVariant PLModel::headerData( int section, Qt::Orientation orientation,
429 int running_index=-1;
430 if (orientation != Qt::Horizontal || role != Qt::DisplayRole)
433 if( i_depth == DEPTH_SEL ) return QVariant( QString("") );
435 while( metadata < COLUMN_END )
437 if( metadata & i_showflags )
439 if( running_index == section )
444 if( running_index != section ) return QVariant();
446 return QVariant( qfu( psz_column_title( metadata ) ) );
449 QModelIndex PLModel::index( int row, int column, const QModelIndex &parent )
453 if( !parent.isValid() )
454 parentItem = rootItem;
456 parentItem = static_cast<PLItem*>(parent.internalPointer());
458 PLItem *childItem = parentItem->child( row );
460 return createIndex( row, column, childItem );
462 return QModelIndex();
465 /* Return the index of a given item */
466 QModelIndex PLModel::index( PLItem *item, int column ) const
468 if( !item ) return QModelIndex();
469 const PLItem *parent = item->parent();
471 return createIndex( parent->children.lastIndexOf( item ),
473 return QModelIndex();
476 QModelIndex PLModel::parent( const QModelIndex &index ) const
478 if( !index.isValid() ) return QModelIndex();
480 PLItem *childItem = static_cast<PLItem*>(index.internalPointer());
483 msg_Err( p_playlist, "NULL CHILD" );
484 return QModelIndex();
487 PLItem *parentItem = childItem->parent();
488 if( !parentItem || parentItem == rootItem ) return QModelIndex();
489 if( !parentItem->parentItem )
491 msg_Err( p_playlist, "No parent parent, trying row 0 " );
492 msg_Err( p_playlist, "----- PLEASE REPORT THIS ------" );
493 return createIndex( 0, 0, parentItem );
495 QModelIndex ind = createIndex(parentItem->row(), 0, parentItem);
499 int PLModel::columnCount( const QModelIndex &i) const
503 if( i_depth == DEPTH_SEL ) return 1;
505 while( metadata < COLUMN_END )
507 if( metadata & i_showflags )
514 int PLModel::childrenCount( const QModelIndex &parent ) const
516 return rowCount( parent );
519 int PLModel::rowCount( const QModelIndex &parent ) const
523 if( !parent.isValid() )
524 parentItem = rootItem;
526 parentItem = static_cast<PLItem*>(parent.internalPointer());
528 return parentItem->childCount();
531 QStringList PLModel::selectedURIs()
534 for( int i = 0; i < current_selection.size(); i++ )
536 PLItem *item = static_cast<PLItem*>
537 (current_selection[i].internalPointer());
541 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id );
544 char *psz = input_item_GetURI( p_item->p_input );
557 /************************* General playlist status ***********************/
559 bool PLModel::hasRandom()
561 return var_GetBool( p_playlist, "random" );
563 bool PLModel::hasRepeat()
565 return var_GetBool( p_playlist, "repeat" );
567 bool PLModel::hasLoop()
569 return var_GetBool( p_playlist, "loop" );
571 void PLModel::setLoop( bool on )
573 var_SetBool( p_playlist, "loop", on ? true:false );
574 config_PutInt( p_playlist, "loop", on ? 1: 0 );
576 void PLModel::setRepeat( bool on )
578 var_SetBool( p_playlist, "repeat", on ? true:false );
579 config_PutInt( p_playlist, "repeat", on ? 1: 0 );
581 void PLModel::setRandom( bool on )
583 var_SetBool( p_playlist, "random", on ? true:false );
584 config_PutInt( p_playlist, "random", on ? 1: 0 );
587 /************************* Lookups *****************************/
589 PLItem *PLModel::FindById( PLItem *root, int i_id )
591 return FindInner( root, i_id, false );
594 PLItem *PLModel::FindByInput( PLItem *root, int i_id )
596 PLItem *result = FindInner( root, i_id, true );
600 #define CACHE( i, p ) { i_cached_id = i; p_cached_item = p; }
601 #define ICACHE( i, p ) { i_cached_input_id = i; p_cached_item_bi = p; }
603 PLItem * PLModel::FindInner( PLItem *root, int i_id, bool b_input )
605 if( ( !b_input && i_cached_id == i_id) ||
606 ( b_input && i_cached_input_id ==i_id ) )
608 return b_input ? p_cached_item_bi : p_cached_item;
611 if( !b_input && root->i_id == i_id )
616 else if( b_input && root->p_input->i_id == i_id )
618 ICACHE( i_id, root );
622 QList<PLItem *>::iterator it = root->children.begin();
623 while ( it != root->children.end() )
625 if( !b_input && (*it)->i_id == i_id )
627 CACHE( i_id, (*it) );
628 return p_cached_item;
630 else if( b_input && (*it)->p_input->i_id == i_id )
632 ICACHE( i_id, (*it) );
633 return p_cached_item_bi;
635 if( (*it)->children.size() )
637 PLItem *childFound = FindInner( (*it), i_id, b_input );
641 ICACHE( i_id, childFound )
643 CACHE( i_id, childFound )
655 /************************* Updates handling *****************************/
656 void PLModel::customEvent( QEvent *event )
658 int type = event->type();
659 if( type != ItemAppend_Type &&
660 type != ItemDelete_Type && type != PLUpdate_Type )
663 PLEvent *ple = static_cast<PLEvent *>(event);
665 if( type == ItemAppend_Type )
666 ProcessItemAppend( &ple->add );
667 else if( type == ItemDelete_Type )
668 ProcessItemRemoval( ple->i_id );
673 /**** Events processing ****/
674 void PLModel::ProcessInputItemUpdate( input_thread_t *p_input )
676 if( !p_input ) return;
677 ProcessInputItemUpdate( input_GetItem( p_input ) );
678 if( p_input && !( p_input->b_dead || !vlc_object_alive( p_input ) ) )
680 PLItem *item = FindByInput( rootItem, input_GetItem( p_input )->i_id );
682 emit currentChanged( index( item, 0 ) );
689 void PLModel::ProcessInputItemUpdate( input_item_t *p_item )
691 if( !p_item || p_item->i_id <= 0 ) return;
692 PLItem *item = FindByInput( rootItem, p_item->i_id );
694 UpdateTreeItem( item, true, true);
697 void PLModel::ProcessItemRemoval( int i_id )
699 if( i_id <= 0 ) return;
700 if( i_id == i_cached_id ) i_cached_id = -1;
701 i_cached_input_id = -1;
706 void PLModel::ProcessItemAppend( const playlist_add_t *p_add )
708 playlist_item_t *p_item = NULL;
709 PLItem *newItem = NULL;
711 PLItem *nodeItem = FindById( rootItem, p_add->i_node );
712 if( !nodeItem ) return;
715 p_item = playlist_ItemGetById( p_playlist, p_add->i_item );
716 if( !p_item || p_item->i_flags & PLAYLIST_DBL_FLAG ) goto end;
717 if( i_depth == DEPTH_SEL && p_item->p_parent &&
718 p_item->p_parent->i_id != rootItem->i_id )
721 newItem = new PLItem( p_item, nodeItem );
724 emit layoutAboutToBeChanged();
725 emit beginInsertRows( index( newItem, 0 ), nodeItem->childCount(), nodeItem->childCount()+1 );
726 nodeItem->appendChild( newItem );
727 emit endInsertRows();
728 emit layoutChanged();
729 UpdateTreeItem( newItem, true );
737 void PLModel::rebuild()
742 void PLModel::rebuild( playlist_item_t *p_root )
744 playlist_item_t* p_item;
745 /* Remove callbacks before locking to avoid deadlocks */
747 /* Invalidate cache */
748 i_cached_id = i_cached_input_id = -1;
750 emit layoutAboutToBeChanged();
755 if( rootItem->children.size() )
757 emit beginRemoveRows( index( rootItem, 0 ), 0,
758 rootItem->children.size() -1 );
759 qDeleteAll( rootItem->children );
760 rootItem->children.clear();
761 emit endRemoveRows();
768 rootItem = new PLItem( p_root );
771 /* Recreate from root */
772 UpdateNodeChildren( rootItem );
773 if( (p_item = playlist_CurrentPlayingItem(p_playlist)) )
775 currentItem = FindByInput( rootItem,
776 p_item->p_input->i_id );
779 UpdateTreeItem( currentItem, true, false );
788 /* And signal the view */
789 emit layoutChanged();
793 /* This function must be entered WITH the playlist lock */
794 void PLModel::UpdateNodeChildren( PLItem *root )
796 emit layoutAboutToBeChanged();
797 playlist_item_t *p_node = playlist_ItemGetById( p_playlist, root->i_id );
798 UpdateNodeChildren( p_node, root );
799 emit layoutChanged();
802 /* This function must be entered WITH the playlist lock */
803 void PLModel::UpdateNodeChildren( playlist_item_t *p_node, PLItem *root )
805 for( int i = 0; i < p_node->i_children ; i++ )
807 if( p_node->pp_children[i]->i_flags & PLAYLIST_DBL_FLAG ) continue;
808 PLItem *newItem = new PLItem( p_node->pp_children[i], root );
809 emit beginInsertRows( index( newItem, 0 ), root->childCount(), root->childCount()+1 );
810 root->appendChild( newItem );
811 emit endInsertRows();
812 UpdateTreeItem( newItem, true, true );
813 if( i_depth == DEPTH_PL && p_node->pp_children[i]->i_children != -1 )
814 UpdateNodeChildren( p_node->pp_children[i], newItem );
818 /* Function doesn't need playlist-lock, as we don't touch playlist_item_t stuff here*/
819 void PLModel::UpdateTreeItem( PLItem *item, bool signal, bool force )
821 if ( !item || !item->p_input )
823 if( !force && i_depth == DEPTH_SEL && item->parentItem &&
824 item->parentItem->p_input != rootItem->p_input )
827 emit dataChanged( index( item, 0 ) , index( item, columnCount( QModelIndex() ) ) );
830 /************************* Actions ******************************/
833 * Deletion, here we have to do a ugly slow hack as we retrieve the full
834 * list of indexes to delete at once: when we delete a node and all of
835 * its children, we need to update the list.
836 * Todo: investigate whethere we can use ranges to be sure to delete all items?
838 void PLModel::doDelete( QModelIndexList selected )
840 for( int i = selected.size() -1 ; i >= 0; i-- )
842 QModelIndex index = selected[i];
843 if( index.column() != 0 ) continue;
844 PLItem *item = static_cast<PLItem*>(index.internalPointer());
847 if( item->children.size() )
848 recurseDelete( item->children, &selected );
849 doDeleteItem( item, &selected );
851 if( i > selected.size() ) i = selected.size();
855 void PLModel::recurseDelete( QList<PLItem*> children, QModelIndexList *fullList )
857 for( int i = children.size() - 1; i >= 0 ; i-- )
859 PLItem *item = children[i];
860 if( item->children.size() )
861 recurseDelete( item->children, fullList );
862 doDeleteItem( item, fullList );
866 void PLModel::doDeleteItem( PLItem *item, QModelIndexList *fullList )
868 QModelIndex deleteIndex = index( item, 0 );
869 fullList->removeAll( deleteIndex );
872 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id );
878 if( p_item->i_children == -1 )
879 playlist_DeleteFromInput( p_playlist, p_item->p_input, pl_Locked );
881 playlist_NodeDelete( p_playlist, p_item, true, false );
883 /* And finally, remove it from the tree */
884 emit beginRemoveRows( index( item->parentItem, 0), item->parentItem->children.indexOf( item ),
885 item->parentItem->children.indexOf( item )+1 );
886 item->remove( item, i_depth );
887 emit endRemoveRows();
890 /******* Volume III: Sorting and searching ********/
891 void PLModel::sort( int column, Qt::SortOrder order )
897 for( i_column = 1; i_column != COLUMN_END; i_column<<=1 )
899 if( ( shownFlags() & i_column ) )
901 if( column == i_index )
912 playlist_item_t *p_root = playlist_ItemGetById( p_playlist,
914 if( p_root && i_flag )
916 playlist_RecursiveNodeSort( p_playlist, p_root,
917 i_column_sorting( i_flag ),
918 order == Qt::AscendingOrder ?
919 ORDER_NORMAL : ORDER_REVERSE );
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 assert( index.isValid() );
946 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, itemId( index ) );
949 i_popup_item = p_item->i_id;
950 i_popup_parent = p_item->p_parent ? p_item->p_parent->i_id : -1;
952 current_selection = list;
953 QMenu *menu = new QMenu;
954 menu->addAction( qtr(I_POP_PLAY), this, SLOT( popupPlay() ) );
955 menu->addAction( qtr(I_POP_DEL), this, SLOT( popupDel() ) );
956 menu->addSeparator();
957 menu->addAction( qtr(I_POP_STREAM), this, SLOT( popupStream() ) );
958 menu->addAction( qtr(I_POP_SAVE), this, SLOT( popupSave() ) );
959 menu->addSeparator();
960 menu->addAction( qtr(I_POP_INFO), this, SLOT( popupInfo() ) );
961 if( p_item->i_children > -1 )
963 menu->addSeparator();
964 menu->addAction( qtr(I_POP_SORT), this, SLOT( popupSort() ) );
965 menu->addAction( qtr(I_POP_ADD), this, SLOT( popupAdd() ) );
967 menu->addSeparator();
968 menu->addAction( qtr( I_POP_EXPLORE ), this, SLOT( popupExplore() ) );
969 menu->popup( point );
976 void PLModel::viewchanged( int meta )
989 /* UNUSED emit layoutAboutToBeChanged(); */
990 index = __MIN( index, columnCount() );
991 QModelIndex parent = createIndex( 0, 0, rootItem );
993 if( i_showflags & meta )
994 /* Removing columns */
996 emit beginRemoveColumns( parent, index, index+1 );
997 i_showflags &= ~( meta );
998 getSettings()->setValue( "qt-pl-showflags", i_showflags );
999 emit endRemoveColumns();
1003 /* Adding columns */
1004 emit beginInsertColumns( parent, index, index+1 );
1005 i_showflags |= meta;
1006 getSettings()->setValue( "qt-pl-showflags", i_showflags );
1007 emit endInsertColumns();
1009 emit columnsChanged( meta );
1014 void PLModel::popupDel()
1016 doDelete( current_selection );
1019 void PLModel::popupPlay()
1023 playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
1025 activateItem( p_item );
1030 void PLModel::popupInfo()
1033 playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
1037 input_item_t* p_input = p_item->p_input;
1038 vlc_gc_incref( p_input );
1040 MediaInfoDialog *mid = new MediaInfoDialog( p_intf, p_input );
1041 vlc_gc_decref( p_input );
1042 mid->setParent( PlaylistDialog::getInstance( p_intf ),
1049 void PLModel::popupStream()
1051 QStringList mrls = selectedURIs();
1052 if( !mrls.isEmpty() )
1053 THEDP->streamingDialog( NULL, mrls[0], false );
1057 void PLModel::popupSave()
1059 QStringList mrls = selectedURIs();
1060 if( !mrls.isEmpty() )
1061 THEDP->streamingDialog( NULL, mrls[0] );
1065 #include <QFileInfo>
1066 #include <QDesktopServices>
1067 void PLModel::popupExplore()
1070 playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
1074 input_item_t *p_input = p_item->p_input;
1075 char *psz_meta = input_item_GetURI( p_input );
1079 const char *psz_access;
1080 const char *psz_demux;
1082 input_SplitMRL( &psz_access, &psz_demux, &psz_path, psz_meta );
1084 if( EMPTY_STR( psz_access ) ||
1085 !strncasecmp( psz_access, "file", 4 ) ||
1086 !strncasecmp( psz_access, "dire", 4 ) )
1088 QFileInfo info( qfu( psz_meta ) );
1089 QDesktopServices::openUrl(
1090 QUrl::fromLocalFile( info.absolutePath() ) );
1099 /**********************************************************************
1100 * Playlist callbacks
1101 **********************************************************************/
1102 static int PlaylistChanged( vlc_object_t *p_this, const char *psz_variable,
1103 vlc_value_t oval, vlc_value_t nval, void *param )
1105 PLModel *p_model = (PLModel *) param;
1106 PLEvent *event = new PLEvent( PLUpdate_Type, 0 );
1107 QApplication::postEvent( p_model, event );
1111 static int PlaylistNext( vlc_object_t *p_this, const char *psz_variable,
1112 vlc_value_t oval, vlc_value_t nval, void *param )
1114 PLModel *p_model = (PLModel *) param;
1115 PLEvent *event = new PLEvent( ItemUpdate_Type, oval.i_int );
1116 QApplication::postEvent( p_model, event );
1117 event = new PLEvent( ItemUpdate_Type, nval.i_int );
1118 QApplication::postEvent( p_model, event );
1122 static int ItemDeleted( vlc_object_t *p_this, const char *psz_variable,
1123 vlc_value_t oval, vlc_value_t nval, void *param )
1125 PLModel *p_model = (PLModel *) param;
1126 PLEvent *event = new PLEvent( ItemDelete_Type, nval.i_int );
1127 QApplication::postEvent( p_model, event );
1131 static int ItemAppended( vlc_object_t *p_this, const char *psz_variable,
1132 vlc_value_t oval, vlc_value_t nval, void *param )
1134 PLModel *p_model = (PLModel *) param;
1135 const playlist_add_t *p_add = (playlist_add_t *)nval.p_address;
1136 PLEvent *event = new PLEvent( p_add );
1137 QApplication::postEvent( p_model, event );