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>
9 * Jakob Leben <jleben@videolan.org>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24 *****************************************************************************/
31 #include "dialogs_provider.hpp"
32 #include "components/playlist/playlist_model.hpp"
33 #include "dialogs/mediainfo.hpp"
34 #include "dialogs/playlist.hpp"
35 #include <vlc_intf_strings.h>
37 #include "pixmaps/types/type_unknown.xpm"
43 #include <QApplication>
48 QIcon
PLModel::icons
[ITEM_TYPE_NUMBER
];
50 /*************************************************************************
51 * Playlist model implementation
52 *************************************************************************/
54 PLModel::PLModel( playlist_t
*_p_playlist
, /* THEPL */
55 intf_thread_t
*_p_intf
, /* main Qt p_intf */
56 playlist_item_t
* p_root
,
57 QObject
*parent
) /* Basic Qt parent */
58 : QAbstractItemModel( parent
)
61 p_playlist
= _p_playlist
;
63 i_cached_input_id
= -1;
64 i_popup_item
= i_popup_parent
= -1;
66 rootItem
= NULL
; /* PLItem rootItem, will be set in rebuild( ) */
68 /* Icons initialization */
69 #define ADD_ICON(type, x) icons[ITEM_TYPE_##type] = QIcon( x )
70 ADD_ICON( UNKNOWN
, type_unknown_xpm
);
71 ADD_ICON( FILE, ":/type/file" );
72 ADD_ICON( DIRECTORY
, ":/type/directory" );
73 ADD_ICON( DISC
, ":/type/disc" );
74 ADD_ICON( CDDA
, ":/type/cdda" );
75 ADD_ICON( CARD
, ":/type/capture-card" );
76 ADD_ICON( NET
, ":/type/net" );
77 ADD_ICON( PLAYLIST
, ":/type/playlist" );
78 ADD_ICON( NODE
, ":/type/node" );
82 CONNECT( THEMIM
->getIM(), metaChanged( input_item_t
*),
83 this, processInputItemUpdate( input_item_t
*) );
84 CONNECT( THEMIM
, inputChanged( input_thread_t
* ),
85 this, processInputItemUpdate( input_thread_t
* ) );
86 CONNECT( THEMIM
, playlistItemAppended( int, int ),
87 this, processItemAppend( int, int ) );
88 CONNECT( THEMIM
, playlistItemRemoved( int ),
89 this, processItemRemoval( int ) );
97 Qt::DropActions
PLModel::supportedDropActions() const
99 return Qt::CopyAction
; /* Why not Qt::MoveAction */
102 Qt::ItemFlags
PLModel::flags( const QModelIndex
&index
) const
104 Qt::ItemFlags flags
= QAbstractItemModel::flags( index
);
106 PLItem
*item
= index
.isValid() ? getItem( index
) : rootItem
;
111 playlist_item_t
*plItem
=
112 playlist_ItemGetById( p_playlist
, item
->i_id
);
114 if ( plItem
&& ( plItem
->i_children
> -1 ) )
115 flags
|= Qt::ItemIsDropEnabled
;
120 flags
|= Qt::ItemIsDragEnabled
;
125 QStringList
PLModel::mimeTypes() const
128 types
<< "vlc/qt-playlist-item";
132 QMimeData
*PLModel::mimeData( const QModelIndexList
&indexes
) const
134 QMimeData
*mimeData
= new QMimeData();
135 QByteArray encodedData
;
136 QDataStream
stream( &encodedData
, QIODevice::WriteOnly
);
137 QModelIndexList list
;
139 foreach( const QModelIndex
&index
, indexes
) {
140 if( index
.isValid() && index
.column() == 0 )
146 foreach( const QModelIndex
&index
, list
) {
147 PLItem
*item
= getItem( index
);
148 stream
.writeRawData( (char*) &item
, sizeof( PLItem
* ) );
150 mimeData
->setData( "vlc/qt-playlist-item", encodedData
);
155 bool PLModel::dropMimeData( const QMimeData
*data
, Qt::DropAction action
,
156 int row
, int column
, const QModelIndex
&parent
)
158 if( data
->hasFormat( "vlc/qt-playlist-item" ) )
160 if( action
== Qt::IgnoreAction
)
163 PLItem
*parentItem
= parent
.isValid() ? getItem( parent
) : rootItem
;
166 playlist_item_t
*p_parent
=
167 playlist_ItemGetById( p_playlist
, parentItem
->i_id
);
168 if( !p_parent
|| p_parent
->i_children
== -1 )
175 playlist_item_t
*p_pl
= p_playlist
->p_playing
;
176 playlist_item_t
*p_ml
= p_playlist
->p_media_library
;
180 ( p_pl
&& p_parent
== p_pl
) ||
181 ( p_ml
&& p_parent
== p_ml
) )
186 QByteArray encodedData
= data
->data( "vlc/qt-playlist-item" );
188 dropAppendCopy( encodedData
, parentItem
);
190 dropMove( encodedData
, parentItem
, row
);
195 void PLModel::dropAppendCopy( QByteArray
& data
, PLItem
*target
)
197 QDataStream
stream( &data
, QIODevice::ReadOnly
);
200 playlist_item_t
*p_parent
=
201 playlist_ItemGetById( p_playlist
, target
->i_id
);
202 while( !stream
.atEnd() )
205 stream
.readRawData( (char*)&item
, sizeof(PLItem
*) );
206 playlist_item_t
*p_item
= playlist_ItemGetById( p_playlist
, item
->i_id
);
207 if( !p_item
) continue;
208 input_item_t
*p_input
= p_item
->p_input
;
209 playlist_AddExt ( p_playlist
,
210 p_input
->psz_uri
, p_input
->psz_name
,
211 PLAYLIST_APPEND
| PLAYLIST_SPREPARSE
, PLAYLIST_END
,
213 p_input
->i_options
, p_input
->ppsz_options
, p_input
->optflagc
,
214 p_parent
== p_playlist
->p_playing
,
220 void PLModel::dropMove( QByteArray
& data
, PLItem
*target
, int row
)
222 QDataStream
stream( &data
, QIODevice::ReadOnly
);
223 QList
<PLItem
*> model_items
;
225 int new_pos
= row
== -1 ? target
->children
.size() : row
;
226 int model_pos
= new_pos
;
227 while( !stream
.atEnd() )
230 stream
.readRawData( (char*)&item
, sizeof(PLItem
*) );
232 /* better not try to move a node into itself: */
233 PLItem
*climber
= target
;
236 if( climber
== item
) break;
237 climber
= climber
->parentItem
;
239 if( climber
) continue;
241 if( item
->parentItem
== target
&&
242 target
->children
.indexOf( item
) < model_pos
)
245 ids
.append( item
->i_id
);
246 model_items
.append( item
);
250 int count
= ids
.size();
253 playlist_item_t
*pp_items
[count
];
256 for( int i
= 0; i
< count
; i
++ )
258 playlist_item_t
*p_item
= playlist_ItemGetById( p_playlist
, ids
[i
] );
264 pp_items
[i
] = p_item
;
266 playlist_item_t
*p_parent
=
267 playlist_ItemGetById( p_playlist
, target
->i_id
);
268 playlist_TreeMoveMany( p_playlist
, count
, pp_items
, p_parent
,
272 insertChildren( target
, model_items
, model_pos
);
276 /* remove item with its id */
277 void PLModel::removeItem( int i_id
)
279 PLItem
*item
= findById( rootItem
, i_id
);
283 void PLModel::activateItem( const QModelIndex
&index
)
285 assert( index
.isValid() );
286 PLItem
*item
= getItem( index
);
289 playlist_item_t
*p_item
= playlist_ItemGetById( p_playlist
, item
->i_id
);
290 activateItem( p_item
);
294 /* Must be entered with lock */
295 void PLModel::activateItem( playlist_item_t
*p_item
)
297 if( !p_item
) return;
298 playlist_item_t
*p_parent
= p_item
;
301 if( p_parent
->i_id
== rootItem
->i_id
) break;
302 p_parent
= p_parent
->p_parent
;
305 playlist_Control( p_playlist
, PLAYLIST_VIEWPLAY
, pl_Locked
,
309 /****************** Base model mandatory implementations *****************/
310 QVariant
PLModel::data( const QModelIndex
&index
, int role
) const
312 if( !index
.isValid() ) return QVariant();
313 PLItem
*item
= getItem( index
);
314 if( role
== Qt::DisplayRole
)
316 int metadata
= columnToMeta( index
.column() );
317 if( metadata
== COLUMN_END
) return QVariant();
320 if( metadata
== COLUMN_NUMBER
)
321 returninfo
= QString::number( index
.row() + 1 );
324 char *psz
= psz_column_meta( item
->p_input
, metadata
);
325 returninfo
= qfu( psz
);
328 return QVariant( returninfo
);
330 else if( role
== Qt::DecorationRole
&& index
.column() == 0 )
332 /* Used to segfault here because i_type wasn't always initialized */
333 return QVariant( PLModel::icons
[item
->p_input
->i_type
] );
335 else if( role
== Qt::FontRole
)
337 if( isCurrent( index
) )
339 QFont f
; f
.setBold( true ); return QVariant( f
);
342 else if( role
== Qt::BackgroundRole
&& isCurrent( index
) )
344 return QVariant( QBrush( Qt::gray
) );
346 else if( role
== IsCurrentRole
) return QVariant( isCurrent( index
) );
351 bool PLModel::isCurrent( const QModelIndex
&index
) const
353 input_thread_t
*p_input_thread
= THEMIM
->getInput();
354 if( !p_input_thread
) return false;
355 return getItem( index
)->p_input
== input_GetItem( p_input_thread
);
358 int PLModel::itemId( const QModelIndex
&index
) const
360 return getItem( index
)->i_id
;
363 QVariant
PLModel::headerData( int section
, Qt::Orientation orientation
,
366 if (orientation
!= Qt::Horizontal
|| role
!= Qt::DisplayRole
)
369 int meta_col
= columnToMeta( section
);
371 if( meta_col
== COLUMN_END
) return QVariant();
373 return QVariant( qfu( psz_column_title( meta_col
) ) );
376 QModelIndex
PLModel::index( int row
, int column
, const QModelIndex
&parent
)
379 PLItem
*parentItem
= parent
.isValid() ? getItem( parent
) : rootItem
;
381 PLItem
*childItem
= parentItem
->child( row
);
383 return createIndex( row
, column
, childItem
);
385 return QModelIndex();
388 QModelIndex
PLModel::index( int i_id
, int c
)
390 return index( findById( rootItem
, i_id
), c
);
393 /* Return the index of a given item */
394 QModelIndex
PLModel::index( PLItem
*item
, int column
) const
396 if( !item
) return QModelIndex();
397 const PLItem
*parent
= item
->parent();
399 return createIndex( parent
->children
.lastIndexOf( item
),
401 return QModelIndex();
404 QModelIndex
PLModel::currentIndex()
406 input_thread_t
*p_input_thread
= THEMIM
->getInput();
407 if( !p_input_thread
) return QModelIndex();
408 PLItem
*item
= findByInput( rootItem
, input_GetItem( p_input_thread
)->i_id
);
409 return index( item
, 0 );
412 QModelIndex
PLModel::parent( const QModelIndex
&index
) const
414 if( !index
.isValid() ) return QModelIndex();
416 PLItem
*childItem
= getItem( index
);
419 msg_Err( p_playlist
, "NULL CHILD" );
420 return QModelIndex();
423 PLItem
*parentItem
= childItem
->parent();
424 if( !parentItem
|| parentItem
== rootItem
) return QModelIndex();
425 if( !parentItem
->parentItem
)
427 msg_Err( p_playlist
, "No parent parent, trying row 0 " );
428 msg_Err( p_playlist
, "----- PLEASE REPORT THIS ------" );
429 return createIndex( 0, 0, parentItem
);
431 QModelIndex ind
= createIndex(parentItem
->row(), 0, parentItem
);
435 int PLModel::columnCount( const QModelIndex
&i
) const
437 return columnFromMeta( COLUMN_END
);
440 int PLModel::rowCount( const QModelIndex
&parent
) const
442 PLItem
*parentItem
= parent
.isValid() ? getItem( parent
) : rootItem
;
443 return parentItem
->childCount();
446 QStringList
PLModel::selectedURIs()
449 for( int i
= 0; i
< current_selection
.size(); i
++ )
451 PLItem
*item
= getItem( current_selection
[i
] );
455 playlist_item_t
*p_item
= playlist_ItemGetById( p_playlist
, item
->i_id
);
458 char *psz
= input_item_GetURI( p_item
->p_input
);
461 lst
.append( qfu(psz
) );
472 /************************* Lookups *****************************/
474 PLItem
*PLModel::findById( PLItem
*root
, int i_id
)
476 return findInner( root
, i_id
, false );
479 PLItem
*PLModel::findByInput( PLItem
*root
, int i_id
)
481 PLItem
*result
= findInner( root
, i_id
, true );
485 #define CACHE( i, p ) { i_cached_id = i; p_cached_item = p; }
486 #define ICACHE( i, p ) { i_cached_input_id = i; p_cached_item_bi = p; }
488 PLItem
* PLModel::findInner( PLItem
*root
, int i_id
, bool b_input
)
490 if( !root
) return NULL
;
491 if( ( !b_input
&& i_cached_id
== i_id
) ||
492 ( b_input
&& i_cached_input_id
==i_id
) )
494 return b_input
? p_cached_item_bi
: p_cached_item
;
497 if( !b_input
&& root
->i_id
== i_id
)
502 else if( b_input
&& root
->p_input
->i_id
== i_id
)
504 ICACHE( i_id
, root
);
508 QList
<PLItem
*>::iterator it
= root
->children
.begin();
509 while ( it
!= root
->children
.end() )
511 if( !b_input
&& (*it
)->i_id
== i_id
)
513 CACHE( i_id
, (*it
) );
514 return p_cached_item
;
516 else if( b_input
&& (*it
)->p_input
->i_id
== i_id
)
518 ICACHE( i_id
, (*it
) );
519 return p_cached_item_bi
;
521 if( (*it
)->children
.size() )
523 PLItem
*childFound
= findInner( (*it
), i_id
, b_input
);
527 ICACHE( i_id
, childFound
)
529 CACHE( i_id
, childFound
)
540 int PLModel::columnToMeta( int _column
)
545 while( column
!= _column
&& meta
!= COLUMN_END
)
554 int PLModel::columnFromMeta( int meta_col
)
559 while( meta
!= meta_col
&& meta
!= COLUMN_END
)
568 bool PLModel::canEdit() const
573 rootItem
->p_input
== p_playlist
->p_playing
->p_input
||
575 p_playlist
->p_media_library
&&
576 rootItem
->p_input
== p_playlist
->p_media_library
->p_input
581 /************************* Updates handling *****************************/
583 /**** Events processing ****/
584 void PLModel::processInputItemUpdate( input_thread_t
*p_input
)
586 if( !p_input
) return;
587 if( p_input
&& !( p_input
->b_dead
|| !vlc_object_alive( p_input
) ) )
589 PLItem
*item
= findByInput( rootItem
, input_GetItem( p_input
)->i_id
);
590 if( item
) emit
currentChanged( index( item
, 0 ) );
592 processInputItemUpdate( input_GetItem( p_input
) );
595 void PLModel::processInputItemUpdate( input_item_t
*p_item
)
597 if( !p_item
|| p_item
->i_id
<= 0 ) return;
598 PLItem
*item
= findByInput( rootItem
, p_item
->i_id
);
600 updateTreeItem( item
);
603 void PLModel::processItemRemoval( int i_id
)
605 if( i_id
<= 0 ) return;
609 void PLModel::processItemAppend( int i_item
, int i_parent
)
611 playlist_item_t
*p_item
= NULL
;
612 PLItem
*newItem
= NULL
;
613 input_thread_t
*currentInputThread
;
616 PLItem
*nodeItem
= findById( rootItem
, i_parent
);
617 if( !nodeItem
) return;
619 foreach( PLItem
*existing
, nodeItem
->children
)
620 if( existing
->i_id
== i_item
) return;
623 p_item
= playlist_ItemGetById( p_playlist
, i_item
);
624 if( !p_item
|| p_item
->i_flags
& PLAYLIST_DBL_FLAG
) goto end
;
626 for( pos
= 0; pos
< p_item
->p_parent
->i_children
; pos
++ )
627 if( p_item
->p_parent
->pp_children
[pos
] == p_item
) break;
629 newItem
= new PLItem( p_item
, nodeItem
);
632 beginInsertRows( index( nodeItem
, 0 ), pos
, pos
);
633 nodeItem
->insertChild( newItem
, pos
);
643 void PLModel::rebuild()
648 void PLModel::rebuild( playlist_item_t
*p_root
)
650 playlist_item_t
* p_item
;
652 /* Invalidate cache */
653 i_cached_id
= i_cached_input_id
= -1;
655 if( rootItem
) rootItem
->removeChildren();
661 rootItem
= new PLItem( p_root
);
664 /* Recreate from root */
665 updateChildren( rootItem
);
668 /* And signal the view */
671 if( p_root
) emit
rootChanged();
674 void PLModel::takeItem( PLItem
*item
)
677 PLItem
*parent
= item
->parentItem
;
679 int i_index
= parent
->children
.indexOf( item
);
681 beginRemoveRows( index( parent
, 0 ), i_index
, i_index
);
682 parent
->takeChildAt( i_index
);
686 void PLModel::insertChildren( PLItem
*node
, QList
<PLItem
*>& items
, int i_pos
)
689 int count
= items
.size();
691 beginInsertRows( index( node
, 0 ), i_pos
, i_pos
+ count
- 1 );
692 for( int i
= 0; i
< count
; i
++ )
694 node
->children
.insert( i_pos
+ i
, items
[i
] );
695 items
[i
]->parentItem
= node
;
700 void PLModel::removeItem( PLItem
*item
)
704 if( item
->i_id
== i_cached_id
) i_cached_id
= -1;
705 i_cached_input_id
= -1;
707 if( item
->parentItem
) {
708 int i
= item
->parentItem
->children
.indexOf( item
);
709 beginRemoveRows( index( item
->parentItem
, 0), i
, i
);
710 item
->parentItem
->children
.removeAt(i
);
719 rebuild( p_playlist
->p_playing
);
723 /* This function must be entered WITH the playlist lock */
724 void PLModel::updateChildren( PLItem
*root
)
726 playlist_item_t
*p_node
= playlist_ItemGetById( p_playlist
, root
->i_id
);
727 updateChildren( p_node
, root
);
730 /* This function must be entered WITH the playlist lock */
731 void PLModel::updateChildren( playlist_item_t
*p_node
, PLItem
*root
)
733 for( int i
= 0; i
< p_node
->i_children
; i
++ )
735 if( p_node
->pp_children
[i
]->i_flags
& PLAYLIST_DBL_FLAG
) continue;
736 PLItem
*newItem
= new PLItem( p_node
->pp_children
[i
], root
);
737 root
->appendChild( newItem
);
738 if( p_node
->pp_children
[i
]->i_children
!= -1 )
739 updateChildren( p_node
->pp_children
[i
], newItem
);
743 /* Function doesn't need playlist-lock, as we don't touch playlist_item_t stuff here*/
744 void PLModel::updateTreeItem( PLItem
*item
)
747 emit
dataChanged( index( item
, 0 ) , index( item
, columnCount( QModelIndex() ) ) );
750 /************************* Actions ******************************/
753 * Deletion, here we have to do a ugly slow hack as we retrieve the full
754 * list of indexes to delete at once: when we delete a node and all of
755 * its children, we need to update the list.
756 * Todo: investigate whethere we can use ranges to be sure to delete all items?
758 void PLModel::doDelete( QModelIndexList selected
)
760 if( !canEdit() ) return;
762 while( !selected
.isEmpty() )
764 QModelIndex index
= selected
[0];
765 selected
.removeAt( 0 );
767 if( index
.column() != 0 ) continue;
769 PLItem
*item
= getItem( index
);
770 if( item
->children
.size() )
771 recurseDelete( item
->children
, &selected
);
774 playlist_DeleteFromInput( p_playlist
, item
->p_input
, pl_Locked
);
781 void PLModel::recurseDelete( QList
<PLItem
*> children
, QModelIndexList
*fullList
)
783 for( int i
= children
.size() - 1; i
>= 0 ; i
-- )
785 PLItem
*item
= children
[i
];
786 if( item
->children
.size() )
787 recurseDelete( item
->children
, fullList
);
788 fullList
->removeAll( index( item
, 0 ) );
792 /******* Volume III: Sorting and searching ********/
793 void PLModel::sort( int column
, Qt::SortOrder order
)
795 sort( rootItem
->i_id
, column
, order
);
798 void PLModel::sort( int i_root_id
, int column
, Qt::SortOrder order
)
800 msg_Dbg( p_intf
, "Sorting by column %i, order %i", column
, order
);
802 int meta
= columnToMeta( column
);
803 if( meta
== COLUMN_END
) return;
805 PLItem
*item
= findById( rootItem
, i_root_id
);
807 QModelIndex qIndex
= index( item
, 0 );
808 int count
= item
->children
.size();
811 beginRemoveRows( qIndex
, 0, count
- 1 );
812 item
->removeChildren();
818 playlist_item_t
*p_root
= playlist_ItemGetById( p_playlist
,
822 playlist_RecursiveNodeSort( p_playlist
, p_root
,
823 i_column_sorting( meta
),
824 order
== Qt::AscendingOrder
?
825 ORDER_NORMAL
: ORDER_REVERSE
);
829 i_cached_id
= i_cached_input_id
= -1;
833 beginInsertRows( qIndex
, 0, count
- 1 );
834 updateChildren( item
);
840 void PLModel::search( const QString
& search_text
, const QModelIndex
& idx
, bool b_recursive
)
842 /** \todo Fire the search with a small delay ? */
845 playlist_item_t
*p_root
= playlist_ItemGetById( p_playlist
,
848 const char *psz_name
= search_text
.toUtf8().data();
849 playlist_LiveSearchUpdate( p_playlist
, p_root
, psz_name
, b_recursive
);
853 PLItem
*searchRoot
= getItem( idx
);
855 beginRemoveRows( idx
, 0, searchRoot
->children
.size() - 1 );
856 searchRoot
->removeChildren();
859 beginInsertRows( idx
, 0, searchRoot
->children
.size() - 1 );
860 updateChildren( searchRoot
);
871 /*********** Popup *********/
872 bool PLModel::popup( const QModelIndex
& index
, const QPoint
&point
, const QModelIndexList
&list
)
874 int i_id
= index
.isValid() ? itemId( index
) : rootItem
->i_id
;
877 playlist_item_t
*p_item
= playlist_ItemGetById( p_playlist
, i_id
);
884 i_popup_item
= index
.isValid() ? p_item
->i_id
: -1;
885 i_popup_parent
= index
.isValid() ?
886 ( p_item
->p_parent
? p_item
->p_parent
->i_id
: -1 ) :
888 i_popup_column
= index
.column();
890 bool tree
= var_InheritBool( p_intf
, "playlist-tree" );
894 current_selection
= list
;
897 if( i_popup_item
> -1 )
899 menu
.addAction( QIcon( ":/menu/play" ), qtr(I_POP_PLAY
), this, SLOT( popupPlay() ) );
900 menu
.addAction( QIcon( ":/buttons/playlist/playlist_remove" ),
901 qtr(I_POP_DEL
), this, SLOT( popupDel() ) );
903 menu
.addAction( QIcon( ":/menu/stream" ),
904 qtr(I_POP_STREAM
), this, SLOT( popupStream() ) );
905 menu
.addAction( qtr(I_POP_SAVE
), this, SLOT( popupSave() ) );
907 menu
.addAction( QIcon( ":/menu/info" ), qtr(I_POP_INFO
), this, SLOT( popupInfo() ) );
908 menu
.addAction( QIcon( ":/type/folder-grey" ),
909 qtr( I_POP_EXPLORE
), this, SLOT( popupExplore() ) );
913 QIcon
addIcon( ":/buttons/playlist/playlist_add" );
915 if( tree
) menu
.addAction( addIcon
, qtr(I_POP_NEWFOLDER
), this, SLOT( popupAddNode() ) );
916 if( rootItem
->i_id
== THEPL
->p_playing
->i_id
)
918 menu
.addAction( addIcon
, qtr(I_PL_ADDF
), THEDP
, SLOT( simplePLAppendDialog()) );
919 menu
.addAction( addIcon
, qtr(I_PL_ADDDIR
), THEDP
, SLOT( PLAppendDir()) );
920 menu
.addAction( addIcon
, qtr(I_OP_ADVOP
), THEDP
, SLOT( PLAppendDialog()) );
922 else if( THEPL
->p_media_library
&&
923 rootItem
->i_id
== THEPL
->p_media_library
->i_id
)
925 menu
.addAction( addIcon
, qtr(I_PL_ADDF
), THEDP
, SLOT( simpleMLAppendDialog()) );
926 menu
.addAction( addIcon
, qtr(I_PL_ADDDIR
), THEDP
, SLOT( MLAppendDir() ) );
927 menu
.addAction( addIcon
, qtr(I_OP_ADVOP
), THEDP
, SLOT( MLAppendDialog() ) );
930 if( i_popup_item
> -1 )
933 QMenu
*sort_menu
= menu
.addMenu( qtr( "Sort by" ) + QString(" ") +
934 qfu( psz_column_title( columnToMeta( index
.column() ) ) ) );
935 sort_menu
->addAction( qtr( "Ascending" ),
936 this, SLOT( popupSortAsc() ) );
937 sort_menu
->addAction( qtr( "Descending" ),
938 this, SLOT( popupSortDesc() ) );
940 if( !menu
.isEmpty() )
942 menu
.exec( point
); return true;
947 void PLModel::popupDel()
949 doDelete( current_selection
);
952 void PLModel::popupPlay()
956 playlist_item_t
*p_item
= playlist_ItemGetById( p_playlist
,
958 activateItem( p_item
);
963 void PLModel::popupInfo()
966 playlist_item_t
*p_item
= playlist_ItemGetById( p_playlist
,
970 input_item_t
* p_input
= p_item
->p_input
;
971 vlc_gc_incref( p_input
);
973 MediaInfoDialog
*mid
= new MediaInfoDialog( p_intf
, p_input
);
974 vlc_gc_decref( p_input
);
975 mid
->setParent( PlaylistDialog::getInstance( p_intf
),
982 void PLModel::popupStream()
984 QStringList mrls
= selectedURIs();
985 if( !mrls
.isEmpty() )
986 THEDP
->streamingDialog( NULL
, mrls
[0], false );
990 void PLModel::popupSave()
992 QStringList mrls
= selectedURIs();
993 if( !mrls
.isEmpty() )
994 THEDP
->streamingDialog( NULL
, mrls
[0] );
999 #include <QDesktopServices>
1000 void PLModel::popupExplore()
1003 playlist_item_t
*p_item
= playlist_ItemGetById( p_playlist
,
1007 input_item_t
*p_input
= p_item
->p_input
;
1008 char *psz_meta
= input_item_GetURI( p_input
);
1012 const char *psz_access
;
1013 const char *psz_demux
;
1015 input_SplitMRL( &psz_access
, &psz_demux
, &psz_path
, psz_meta
);
1017 if( EMPTY_STR( psz_access
) ||
1018 !strncasecmp( psz_access
, "file", 4 ) ||
1019 !strncasecmp( psz_access
, "dire", 4 ) )
1021 QFileInfo
info( qfu( psz_meta
) );
1022 QDesktopServices::openUrl(
1023 QUrl::fromLocalFile( info
.absolutePath() ) );
1032 #include <QInputDialog>
1033 void PLModel::popupAddNode()
1036 QString name
= QInputDialog::getText( PlaylistDialog::getInstance( p_intf
),
1037 qtr( "Create Folder" ), qtr( "Enter name for new folder:" ),
1038 QLineEdit::Normal
, QString(), &ok
);
1039 if( !ok
|| name
.isEmpty() ) return;
1041 playlist_item_t
*p_item
= playlist_ItemGetById( p_playlist
,
1045 playlist_NodeCreate( p_playlist
, qtu( name
), p_item
, 0, NULL
);
1050 void PLModel::popupSortAsc()
1052 sort( i_popup_parent
, i_popup_column
, Qt::AscendingOrder
);
1055 void PLModel::popupSortDesc()
1057 sort( i_popup_parent
, i_popup_column
, Qt::DescendingOrder
);