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>
47 #include <QDesktopServices>
48 #include <QInputDialog>
53 I_DIR_OR_FOLDER( N_("Create Directory"), N_( "Create Folder" ) )
54 #define I_NEW_DIR_NAME \
55 I_DIR_OR_FOLDER( N_( "Enter name for new directory:" ), \
56 N_( "Enter name for new folder:" ) )
58 QIcon PLModel::icons[ITEM_TYPE_NUMBER];
60 /*************************************************************************
61 * Playlist model implementation
62 *************************************************************************/
64 PLModel::PLModel( playlist_t *_p_playlist, /* THEPL */
65 intf_thread_t *_p_intf, /* main Qt p_intf */
66 playlist_item_t * p_root,
67 QObject *parent ) /* Basic Qt parent */
68 : QAbstractItemModel( parent )
71 p_playlist = _p_playlist;
73 i_cached_input_id = -1;
74 i_popup_item = i_popup_parent = -1;
77 rootItem = NULL; /* PLItem rootItem, will be set in rebuild( ) */
79 /* Icons initialization */
80 #define ADD_ICON(type, x) icons[ITEM_TYPE_##type] = QIcon( x )
81 ADD_ICON( UNKNOWN , type_unknown_xpm );
82 ADD_ICON( FILE, ":/type/file" );
83 ADD_ICON( DIRECTORY, ":/type/directory" );
84 ADD_ICON( DISC, ":/type/disc" );
85 ADD_ICON( CDDA, ":/type/cdda" );
86 ADD_ICON( CARD, ":/type/capture-card" );
87 ADD_ICON( NET, ":/type/net" );
88 ADD_ICON( PLAYLIST, ":/type/playlist" );
89 ADD_ICON( NODE, ":/type/node" );
93 DCONNECT( THEMIM->getIM(), metaChanged( input_item_t *),
94 this, processInputItemUpdate( input_item_t *) );
95 DCONNECT( THEMIM, inputChanged( input_thread_t * ),
96 this, processInputItemUpdate( input_thread_t* ) );
97 CONNECT( THEMIM, playlistItemAppended( int, int ),
98 this, processItemAppend( int, int ) );
99 CONNECT( THEMIM, playlistItemRemoved( int ),
100 this, processItemRemoval( int ) );
109 Qt::DropActions PLModel::supportedDropActions() const
111 return Qt::CopyAction; /* Why not Qt::MoveAction */
114 Qt::ItemFlags PLModel::flags( const QModelIndex &index ) const
116 Qt::ItemFlags flags = QAbstractItemModel::flags( index );
118 PLItem *item = index.isValid() ? getItem( index ) : rootItem;
123 playlist_item_t *plItem =
124 playlist_ItemGetById( p_playlist, item->i_id );
126 if ( plItem && ( plItem->i_children > -1 ) )
127 flags |= Qt::ItemIsDropEnabled;
132 flags |= Qt::ItemIsDragEnabled;
137 QStringList PLModel::mimeTypes() const
140 types << "vlc/qt-input-items";
144 bool modelIndexLessThen( const QModelIndex &i1, const QModelIndex &i2 )
146 if( !i1.isValid() || !i2.isValid() ) return false;
147 PLItem *item1 = static_cast<PLItem*>( i1.internalPointer() );
148 PLItem *item2 = static_cast<PLItem*>( i2.internalPointer() );
149 if( item1->parent() == item2->parent() ) return i1.row() < i2.row();
150 else return *item1 < *item2;
153 QMimeData *PLModel::mimeData( const QModelIndexList &indexes ) const
155 PlMimeData *plMimeData = new PlMimeData();
156 QModelIndexList list;
158 foreach( const QModelIndex &index, indexes ) {
159 if( index.isValid() && index.column() == 0 )
163 qSort(list.begin(), list.end(), modelIndexLessThen);
166 foreach( const QModelIndex &index, list ) {
169 PLItem *testee = getItem( index );
170 while( testee->parent() )
172 if( testee->parent() == item ||
173 testee->parent() == item->parent() ) break;
174 testee = testee->parent();
176 if( testee->parent() == item ) continue;
177 item = getItem( index );
180 item = getItem( index );
182 plMimeData->appendItem( item->p_input );
189 bool PLModel::dropMimeData( const QMimeData *data, Qt::DropAction action,
190 int row, int column, const QModelIndex &parent )
192 const PlMimeData *plMimeData = qobject_cast<const PlMimeData*>( data );
195 if( action == Qt::IgnoreAction )
199 playlist_item_t *p_parent =
200 playlist_ItemGetById( p_playlist, itemId( parent ) );
201 if( !p_parent || p_parent->i_children == -1 )
208 playlist_item_t *p_pl = p_playlist->p_playing;
209 playlist_item_t *p_ml = p_playlist->p_media_library;
213 ( p_pl && p_parent == p_pl ) ||
214 ( p_ml && p_parent == p_ml ) )
220 dropAppendCopy( plMimeData, getItem( parent ) );
222 dropMove( plMimeData, getItem( parent ), row );
227 void PLModel::dropAppendCopy( const PlMimeData *plMimeData, PLItem *target )
231 playlist_item_t *p_parent =
232 playlist_ItemGetByInput( p_playlist, target->p_input );
233 if( !p_parent ) return;
235 bool b_flat = p_parent == p_playlist->p_playing &&
236 !var_InheritBool( p_intf, "playlist-tree" );
238 QList<input_item_t*> inputItems = plMimeData->inputItems();
239 foreach( input_item_t* p_input, inputItems )
241 playlist_item_t *p_item = playlist_ItemGetByInput( p_playlist, p_input );
242 if( !p_item ) continue;
244 recursiveAppendCopy( p_playlist, p_item, p_parent, b_flat );
250 /* Must be entered WITH playlist lock! */
251 void PLModel::recursiveAppendCopy( playlist_t *p_playlist, playlist_item_t *source,
252 playlist_item_t *target, bool b_flat )
254 input_item_t *srcInput = source->p_input;
256 if( !(source->i_children != -1 && b_flat) )
258 vlc_mutex_lock( &srcInput->lock );
259 input_item_t *newInput =
260 input_item_NewWithType( VLC_OBJECT(p_playlist),
261 srcInput->psz_uri, srcInput->psz_name,
262 srcInput->i_options, srcInput->ppsz_options,
263 srcInput->optflagc, srcInput->i_duration,
265 vlc_mutex_unlock( &srcInput->lock );
267 if( source->i_children != -1 )
268 target = playlist_NodeCreate( p_playlist, newInput->psz_name, target, 0, newInput );
270 playlist_NodeAddInput( p_playlist, newInput, target,
271 PLAYLIST_APPEND | PLAYLIST_SPREPARSE,
272 PLAYLIST_END, pl_Locked );
274 for( int i = 0; i < source->i_children; i++ )
275 recursiveAppendCopy( p_playlist, source->pp_children[i], target, b_flat );
278 void PLModel::dropMove( const PlMimeData * plMimeData, PLItem *target, int row )
280 QList<input_item_t*> inputItems = plMimeData->inputItems();
281 QList<PLItem*> model_items;
282 playlist_item_t *pp_items[inputItems.size()];
286 playlist_item_t *p_parent =
287 playlist_ItemGetByInput( p_playlist, target->p_input );
289 if( !p_parent || row > p_parent->i_children )
294 int new_pos = row == -1 ? p_parent->i_children : row;
295 int model_pos = new_pos;
298 foreach( input_item_t *p_input, inputItems )
300 playlist_item_t *p_item = playlist_ItemGetByInput( p_playlist, p_input );
301 if( !p_item ) continue;
303 PLItem *item = findByInput( rootItem, p_input->i_id );
304 if( !item ) continue;
306 /* Better not try to move a node into itself.
307 Abort the whole operation in that case,
308 because it is ambiguous. */
309 PLItem *climber = target;
312 if( climber == item )
316 climber = climber->parentItem;
319 if( item->parentItem == target &&
320 target->children.indexOf( item ) < new_pos )
323 model_items.append( item );
324 pp_items[i] = p_item;
328 if( model_items.isEmpty() )
333 playlist_TreeMoveMany( p_playlist, i, pp_items, p_parent, new_pos );
337 foreach( PLItem *item, model_items )
340 insertChildren( target, model_items, model_pos );
343 /* remove item with its id */
344 void PLModel::removeItem( int i_id )
346 PLItem *item = findById( rootItem, i_id );
350 void PLModel::activateItem( const QModelIndex &index )
352 assert( index.isValid() );
353 PLItem *item = getItem( index );
356 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id );
357 activateItem( p_item );
361 /* Must be entered with lock */
362 void PLModel::activateItem( playlist_item_t *p_item )
364 if( !p_item ) return;
365 playlist_item_t *p_parent = p_item;
368 if( p_parent->i_id == rootItem->i_id ) break;
369 p_parent = p_parent->p_parent;
372 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, pl_Locked,
376 /****************** Base model mandatory implementations *****************/
377 QVariant PLModel::data( const QModelIndex &index, int role ) const
379 if( !index.isValid() ) return QVariant();
380 PLItem *item = getItem( index );
381 if( role == Qt::DisplayRole )
383 int metadata = columnToMeta( index.column() );
384 if( metadata == COLUMN_END ) return QVariant();
387 if( metadata == COLUMN_NUMBER )
388 returninfo = QString::number( index.row() + 1 );
391 char *psz = psz_column_meta( item->p_input, metadata );
392 returninfo = qfu( psz );
395 return QVariant( returninfo );
397 else if( role == Qt::DecorationRole && index.column() == 0 )
399 /* Used to segfault here because i_type wasn't always initialized */
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 );
409 else if( role == Qt::BackgroundRole && isCurrent( index ) )
411 return QVariant( QBrush( Qt::gray ) );
413 else if( role == IsCurrentRole ) return QVariant( isCurrent( index ) );
414 else if( role == IsLeafNodeRole )
418 playlist_item_t *plItem =
419 playlist_ItemGetById( p_playlist, item->i_id );
422 isLeaf = plItem->i_children == -1;
430 bool PLModel::isCurrent( const QModelIndex &index ) const
432 return getItem( index )->p_input == THEMIM->currentInputItem();
435 int PLModel::itemId( const QModelIndex &index ) const
437 return getItem( index )->i_id;
440 QVariant PLModel::headerData( int section, Qt::Orientation orientation,
443 if (orientation != Qt::Horizontal || role != Qt::DisplayRole)
446 int meta_col = columnToMeta( section );
448 if( meta_col == COLUMN_END ) return QVariant();
450 return QVariant( qfu( psz_column_title( meta_col ) ) );
453 QModelIndex PLModel::index( int row, int column, const QModelIndex &parent )
456 PLItem *parentItem = parent.isValid() ? getItem( parent ) : rootItem;
458 PLItem *childItem = parentItem->child( row );
460 return createIndex( row, column, childItem );
462 return QModelIndex();
465 QModelIndex PLModel::index( int i_id, int c )
467 return index( findById( rootItem, i_id ), c );
470 /* Return the index of a given item */
471 QModelIndex PLModel::index( PLItem *item, int column ) const
473 if( !item ) return QModelIndex();
474 const PLItem *parent = item->parent();
476 return createIndex( parent->children.lastIndexOf( item ),
478 return QModelIndex();
481 QModelIndex PLModel::currentIndex()
483 input_thread_t *p_input_thread = THEMIM->getInput();
484 if( !p_input_thread ) return QModelIndex();
485 PLItem *item = findByInput( rootItem, input_GetItem( p_input_thread )->i_id );
486 return index( item, 0 );
489 QModelIndex PLModel::parent( const QModelIndex &index ) const
491 if( !index.isValid() ) return QModelIndex();
493 PLItem *childItem = getItem( index );
496 msg_Err( p_playlist, "NULL CHILD" );
497 return QModelIndex();
500 PLItem *parentItem = childItem->parent();
501 if( !parentItem || parentItem == rootItem ) return QModelIndex();
502 if( !parentItem->parentItem )
504 msg_Err( p_playlist, "No parent parent, trying row 0 " );
505 msg_Err( p_playlist, "----- PLEASE REPORT THIS ------" );
506 return createIndex( 0, 0, parentItem );
508 QModelIndex ind = createIndex(parentItem->row(), 0, parentItem);
512 int PLModel::columnCount( const QModelIndex &i) const
514 return columnFromMeta( COLUMN_END );
517 int PLModel::rowCount( const QModelIndex &parent ) const
519 PLItem *parentItem = parent.isValid() ? getItem( parent ) : rootItem;
520 return parentItem->childCount();
523 QStringList PLModel::selectedURIs()
526 for( int i = 0; i < current_selection.size(); i++ )
528 PLItem *item = getItem( current_selection[i] );
532 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id );
535 char *psz = input_item_GetURI( p_item->p_input );
538 lst.append( qfu(psz) );
549 /************************* Lookups *****************************/
551 PLItem *PLModel::findById( PLItem *root, int i_id )
553 return findInner( root, i_id, false );
556 PLItem *PLModel::findByInput( PLItem *root, int i_id )
558 PLItem *result = findInner( root, i_id, true );
562 #define CACHE( i, p ) { i_cached_id = i; p_cached_item = p; }
563 #define ICACHE( i, p ) { i_cached_input_id = i; p_cached_item_bi = p; }
565 PLItem * PLModel::findInner( PLItem *root, int i_id, bool b_input )
567 if( !root ) return NULL;
568 if( ( !b_input && i_cached_id == i_id) ||
569 ( b_input && i_cached_input_id ==i_id ) )
571 return b_input ? p_cached_item_bi : p_cached_item;
574 if( !b_input && root->i_id == i_id )
579 else if( b_input && root->p_input->i_id == i_id )
581 ICACHE( i_id, root );
585 QList<PLItem *>::iterator it = root->children.begin();
586 while ( it != root->children.end() )
588 if( !b_input && (*it)->i_id == i_id )
590 CACHE( i_id, (*it) );
591 return p_cached_item;
593 else if( b_input && (*it)->p_input->i_id == i_id )
595 ICACHE( i_id, (*it) );
596 return p_cached_item_bi;
598 if( (*it)->children.size() )
600 PLItem *childFound = findInner( (*it), i_id, b_input );
604 ICACHE( i_id, childFound )
606 CACHE( i_id, childFound )
617 int PLModel::columnToMeta( int _column )
622 while( column != _column && meta != COLUMN_END )
631 int PLModel::columnFromMeta( int meta_col )
636 while( meta != meta_col && meta != COLUMN_END )
645 bool PLModel::canEdit() const
650 rootItem->p_input == p_playlist->p_playing->p_input ||
652 p_playlist->p_media_library &&
653 rootItem->p_input == p_playlist->p_media_library->p_input
658 /************************* Updates handling *****************************/
660 /**** Events processing ****/
661 void PLModel::processInputItemUpdate( input_thread_t *p_input )
663 if( !p_input ) return;
664 if( p_input && !( p_input->b_dead || !vlc_object_alive( p_input ) ) )
666 PLItem *item = findByInput( rootItem, input_GetItem( p_input )->i_id );
667 if( item ) emit currentChanged( index( item, 0 ) );
669 processInputItemUpdate( input_GetItem( p_input ) );
672 void PLModel::processInputItemUpdate( input_item_t *p_item )
674 if( !p_item || p_item->i_id <= 0 ) return;
675 PLItem *item = findByInput( rootItem, p_item->i_id );
677 updateTreeItem( item );
680 void PLModel::processItemRemoval( int i_id )
682 if( i_id <= 0 ) return;
686 void PLModel::processItemAppend( int i_item, int i_parent )
688 playlist_item_t *p_item = NULL;
689 PLItem *newItem = NULL;
690 input_thread_t *currentInputThread;
693 PLItem *nodeItem = findById( rootItem, i_parent );
694 if( !nodeItem ) return;
696 foreach( PLItem *existing, nodeItem->children )
697 if( existing->i_id == i_item ) return;
700 p_item = playlist_ItemGetById( p_playlist, i_item );
701 if( !p_item || p_item->i_flags & PLAYLIST_DBL_FLAG )
706 for( pos = 0; pos < p_item->p_parent->i_children; pos++ )
707 if( p_item->p_parent->pp_children[pos] == p_item ) break;
709 newItem = new PLItem( p_item, nodeItem );
712 beginInsertRows( index( nodeItem, 0 ), pos, pos );
713 nodeItem->insertChild( newItem, pos );
716 if( newItem->p_input == THEMIM->currentInputItem() )
717 emit currentChanged( index( newItem, 0 ) );
721 void PLModel::rebuild()
726 void PLModel::rebuild( playlist_item_t *p_root )
728 playlist_item_t* p_item;
730 /* Invalidate cache */
731 i_cached_id = i_cached_input_id = -1;
733 if( rootItem ) rootItem->removeChildren();
739 rootItem = new PLItem( p_root );
742 /* Recreate from root */
743 updateChildren( rootItem );
746 /* And signal the view */
749 if( p_root ) emit rootChanged();
752 void PLModel::takeItem( PLItem *item )
755 PLItem *parent = item->parentItem;
757 int i_index = parent->children.indexOf( item );
759 beginRemoveRows( index( parent, 0 ), i_index, i_index );
760 parent->takeChildAt( i_index );
764 void PLModel::insertChildren( PLItem *node, QList<PLItem*>& items, int i_pos )
767 int count = items.size();
769 beginInsertRows( index( node, 0 ), i_pos, i_pos + count - 1 );
770 for( int i = 0; i < count; i++ )
772 node->children.insert( i_pos + i, items[i] );
773 items[i]->parentItem = node;
778 void PLModel::removeItem( PLItem *item )
783 i_cached_input_id = -1;
785 if( item->parentItem ) {
786 int i = item->parentItem->children.indexOf( item );
787 beginRemoveRows( index( item->parentItem, 0), i, i );
788 item->parentItem->children.removeAt(i);
797 rebuild( p_playlist->p_playing );
801 /* This function must be entered WITH the playlist lock */
802 void PLModel::updateChildren( PLItem *root )
804 playlist_item_t *p_node = playlist_ItemGetById( p_playlist, root->i_id );
805 updateChildren( p_node, root );
808 /* This function must be entered WITH the playlist lock */
809 void PLModel::updateChildren( playlist_item_t *p_node, PLItem *root )
811 for( int i = 0; i < p_node->i_children ; i++ )
813 if( p_node->pp_children[i]->i_flags & PLAYLIST_DBL_FLAG ) continue;
814 PLItem *newItem = new PLItem( p_node->pp_children[i], root );
815 root->appendChild( newItem );
816 if( p_node->pp_children[i]->i_children != -1 )
817 updateChildren( p_node->pp_children[i], newItem );
821 /* Function doesn't need playlist-lock, as we don't touch playlist_item_t stuff here*/
822 void PLModel::updateTreeItem( PLItem *item )
825 emit dataChanged( index( item, 0 ) , index( item, columnCount( QModelIndex() ) ) );
828 /************************* Actions ******************************/
831 * Deletion, here we have to do a ugly slow hack as we retrieve the full
832 * list of indexes to delete at once: when we delete a node and all of
833 * its children, we need to update the list.
834 * Todo: investigate whethere we can use ranges to be sure to delete all items?
836 void PLModel::doDelete( QModelIndexList selected )
838 if( !canEdit() ) return;
840 while( !selected.isEmpty() )
842 QModelIndex index = selected[0];
843 selected.removeAt( 0 );
845 if( index.column() != 0 ) continue;
847 PLItem *item = getItem( index );
848 if( item->children.size() )
849 recurseDelete( item->children, &selected );
852 playlist_DeleteFromInput( p_playlist, item->p_input, pl_Locked );
859 void PLModel::recurseDelete( QList<PLItem*> children, QModelIndexList *fullList )
861 for( int i = children.size() - 1; i >= 0 ; i-- )
863 PLItem *item = children[i];
864 if( item->children.size() )
865 recurseDelete( item->children, fullList );
866 fullList->removeAll( index( item, 0 ) );
870 /******* Volume III: Sorting and searching ********/
871 void PLModel::sort( int column, Qt::SortOrder order )
873 sort( rootItem->i_id, column, order );
876 void PLModel::sort( int i_root_id, int column, Qt::SortOrder order )
878 msg_Dbg( p_intf, "Sorting by column %i, order %i", column, order );
880 int meta = columnToMeta( column );
881 if( meta == COLUMN_END ) return;
883 PLItem *item = findById( rootItem, i_root_id );
885 QModelIndex qIndex = index( item, 0 );
886 int count = item->children.size();
889 beginRemoveRows( qIndex, 0, count - 1 );
890 item->removeChildren();
896 playlist_item_t *p_root = playlist_ItemGetById( p_playlist,
900 playlist_RecursiveNodeSort( p_playlist, p_root,
901 i_column_sorting( meta ),
902 order == Qt::AscendingOrder ?
903 ORDER_NORMAL : ORDER_REVERSE );
907 i_cached_id = i_cached_input_id = -1;
911 beginInsertRows( qIndex, 0, count - 1 );
912 updateChildren( item );
918 void PLModel::search( const QString& search_text, const QModelIndex & idx, bool b_recursive )
920 /** \todo Fire the search with a small delay ? */
923 playlist_item_t *p_root = playlist_ItemGetById( p_playlist,
926 const char *psz_name = qtu( search_text );
927 playlist_LiveSearchUpdate( p_playlist , p_root, psz_name, b_recursive );
931 PLItem *searchRoot = getItem( idx );
933 beginRemoveRows( idx, 0, searchRoot->children.size() - 1 );
934 searchRoot->removeChildren();
937 beginInsertRows( idx, 0, searchRoot->children.size() - 1 );
938 updateChildren( searchRoot );
949 /*********** Popup *********/
950 bool PLModel::popup( const QModelIndex & index, const QPoint &point, const QModelIndexList &list )
952 int i_id = index.isValid() ? itemId( index ) : rootItem->i_id;
955 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, i_id );
962 i_popup_item = index.isValid() ? p_item->i_id : -1;
963 i_popup_parent = index.isValid() ?
964 ( p_item->p_parent ? p_item->p_parent->i_id : -1 ) :
966 i_popup_column = index.column();
968 bool tree = ( rootItem && rootItem->i_id != p_playlist->p_playing->i_id ) ||
969 var_InheritBool( p_intf, "playlist-tree" );
973 current_selection = list;
976 if( i_popup_item > -1 )
978 menu.addAction( QIcon( ":/menu/play" ), qtr(I_POP_PLAY), this, SLOT( popupPlay() ) );
979 menu.addAction( QIcon( ":/menu/stream" ),
980 qtr(I_POP_STREAM), this, SLOT( popupStream() ) );
981 menu.addAction( qtr(I_POP_SAVE), this, SLOT( popupSave() ) );
982 menu.addAction( QIcon( ":/menu/info" ), qtr(I_POP_INFO), this, SLOT( popupInfo() ) );
983 menu.addAction( QIcon( ":/type/folder-grey" ),
984 qtr( I_POP_EXPLORE ), this, SLOT( popupExplore() ) );
989 QIcon addIcon( ":/buttons/playlist/playlist_add" );
991 if( tree ) menu.addAction( addIcon, qtr(I_POP_NEWFOLDER), this, SLOT( popupAddNode() ) );
992 if( rootItem->i_id == THEPL->p_playing->i_id )
994 menu.addAction( addIcon, qtr(I_PL_ADDF), THEDP, SLOT( simplePLAppendDialog()) );
995 menu.addAction( addIcon, qtr(I_PL_ADDDIR), THEDP, SLOT( PLAppendDir()) );
996 menu.addAction( addIcon, qtr(I_OP_ADVOP), THEDP, SLOT( PLAppendDialog()) );
998 else if( THEPL->p_media_library &&
999 rootItem->i_id == THEPL->p_media_library->i_id )
1001 menu.addAction( addIcon, qtr(I_PL_ADDF), THEDP, SLOT( simpleMLAppendDialog()) );
1002 menu.addAction( addIcon, qtr(I_PL_ADDDIR), THEDP, SLOT( MLAppendDir() ) );
1003 menu.addAction( addIcon, qtr(I_OP_ADVOP), THEDP, SLOT( MLAppendDialog() ) );
1006 if( i_popup_item > -1 )
1008 menu.addAction( QIcon( ":/buttons/playlist/playlist_remove" ),
1009 qtr(I_POP_DEL), this, SLOT( popupDel() ) );
1010 menu.addSeparator();
1013 sortingMenu = new QMenu( qtr( "Sort by" ) );
1014 sortingMapper = new QSignalMapper( this );
1016 for( i = 1, j = 1; i < COLUMN_END; i <<= 1, j++ )
1018 if( i == COLUMN_NUMBER ) continue;
1019 QMenu *m = sortingMenu->addMenu( qfu( psz_column_title( i ) ) );
1020 QAction *asc = m->addAction( qtr("Ascending") );
1021 QAction *desc = m->addAction( qtr("Descending") );
1022 sortingMapper->setMapping( asc, j );
1023 sortingMapper->setMapping( desc, -j );
1024 CONNECT( asc, triggered(), sortingMapper, map() );
1025 CONNECT( desc, triggered(), sortingMapper, map() );
1027 CONNECT( sortingMapper, mapped( int ), this, popupSort( int ) );
1029 menu.addMenu( sortingMenu );
1031 if( !menu.isEmpty() )
1033 menu.exec( point ); return true;
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] );
1088 void PLModel::popupExplore()
1091 playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
1095 input_item_t *p_input = p_item->p_input;
1096 char *psz_meta = input_item_GetURI( p_input );
1100 const char *psz_access;
1101 const char *psz_demux;
1103 input_SplitMRL( &psz_access, &psz_demux, &psz_path, psz_meta );
1105 if( !EMPTY_STR( psz_access ) && (
1106 !strncasecmp( psz_access, "file", 4 ) ||
1107 !strncasecmp( psz_access, "dire", 4 ) ))
1109 QFileInfo info( qfu( decode_URI( psz_path ) ) );
1110 QDesktopServices::openUrl(
1111 QUrl::fromLocalFile( info.absolutePath() ) );
1120 void PLModel::popupAddNode()
1123 QString name = QInputDialog::getText( PlaylistDialog::getInstance( p_intf ),
1124 qtr( I_NEW_DIR ), qtr( I_NEW_DIR_NAME ),
1125 QLineEdit::Normal, QString(), &ok);
1126 if( !ok || name.isEmpty() ) return;
1128 playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
1132 playlist_NodeCreate( p_playlist, qtu( name ), p_item, 0, NULL );
1137 void PLModel::popupSort( int column )
1139 sort( i_popup_parent,
1140 column > 0 ? column - 1 : -column - 1,
1141 column > 0 ? Qt::AscendingOrder : Qt::DescendingOrder );
1144 /******************* Drag and Drop helper class ******************/
1146 PlMimeData::PlMimeData( )
1149 PlMimeData::~PlMimeData()
1151 foreach( input_item_t *p_item, _inputItems )
1152 vlc_gc_decref( p_item );
1155 void PlMimeData::appendItem( input_item_t *p_item )
1157 vlc_gc_incref( p_item );
1158 _inputItems.append( p_item );
1161 QList<input_item_t*> PlMimeData::inputItems() const
1166 QStringList PlMimeData::formats () const
1169 fmts << "vlc/qt-input-items";