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;
76 current_index = QModelIndex();
78 rootItem = NULL; /* PLItem rootItem, will be set in rebuild( ) */
80 /* Icons initialization */
81 #define ADD_ICON(type, x) icons[ITEM_TYPE_##type] = QIcon( x )
82 ADD_ICON( UNKNOWN , type_unknown_xpm );
83 ADD_ICON( FILE, ":/type/file" );
84 ADD_ICON( DIRECTORY, ":/type/directory" );
85 ADD_ICON( DISC, ":/type/disc" );
86 ADD_ICON( CDDA, ":/type/cdda" );
87 ADD_ICON( CARD, ":/type/capture-card" );
88 ADD_ICON( NET, ":/type/net" );
89 ADD_ICON( PLAYLIST, ":/type/playlist" );
90 ADD_ICON( NODE, ":/type/node" );
94 DCONNECT( THEMIM->getIM(), metaChanged( input_item_t *),
95 this, processInputItemUpdate( input_item_t *) );
96 DCONNECT( THEMIM, inputChanged( input_thread_t * ),
97 this, processInputItemUpdate( input_thread_t* ) );
98 CONNECT( THEMIM, playlistItemAppended( int, int ),
99 this, processItemAppend( int, int ) );
100 CONNECT( THEMIM, playlistItemRemoved( int ),
101 this, processItemRemoval( int ) );
102 CONNECT( this, currentChanged( const QModelIndex &) ,
103 this, cacheCurrent( const QModelIndex &) );
112 Qt::DropActions PLModel::supportedDropActions() const
114 return Qt::CopyAction | Qt::MoveAction;
117 Qt::ItemFlags PLModel::flags( const QModelIndex &index ) const
119 Qt::ItemFlags flags = QAbstractItemModel::flags( index );
121 PLItem *item = index.isValid() ? getItem( index ) : rootItem;
126 playlist_item_t *plItem =
127 playlist_ItemGetById( p_playlist, item->i_id );
129 if ( plItem && ( plItem->i_children > -1 ) )
130 flags |= Qt::ItemIsDropEnabled;
135 flags |= Qt::ItemIsDragEnabled;
140 QStringList PLModel::mimeTypes() const
143 types << "vlc/qt-input-items";
147 bool modelIndexLessThen( const QModelIndex &i1, const QModelIndex &i2 )
149 if( !i1.isValid() || !i2.isValid() ) return false;
150 PLItem *item1 = static_cast<PLItem*>( i1.internalPointer() );
151 PLItem *item2 = static_cast<PLItem*>( i2.internalPointer() );
152 if( item1->parent() == item2->parent() ) return i1.row() < i2.row();
153 else return *item1 < *item2;
156 QMimeData *PLModel::mimeData( const QModelIndexList &indexes ) const
158 PlMimeData *plMimeData = new PlMimeData();
159 QModelIndexList list;
161 foreach( const QModelIndex &index, indexes ) {
162 if( index.isValid() && index.column() == 0 )
166 qSort(list.begin(), list.end(), modelIndexLessThen);
169 foreach( const QModelIndex &index, list ) {
172 PLItem *testee = getItem( index );
173 while( testee->parent() )
175 if( testee->parent() == item ||
176 testee->parent() == item->parent() ) break;
177 testee = testee->parent();
179 if( testee->parent() == item ) continue;
180 item = getItem( index );
183 item = getItem( index );
185 plMimeData->appendItem( item->p_input );
192 bool PLModel::dropMimeData( const QMimeData *data, Qt::DropAction action,
193 int row, int column, const QModelIndex &parent )
195 bool copy = action == Qt::CopyAction;
196 if( !copy && action != Qt::MoveAction )
199 const PlMimeData *plMimeData = qobject_cast<const PlMimeData*>( data );
203 dropAppendCopy( plMimeData, getItem( parent ), row );
205 dropMove( plMimeData, getItem( parent ), row );
210 void PLModel::dropAppendCopy( const PlMimeData *plMimeData, PLItem *target, int pos )
214 playlist_item_t *p_parent =
215 playlist_ItemGetByInput( p_playlist, target->p_input );
216 if( !p_parent ) return;
218 if( pos == -1 ) pos = PLAYLIST_END;
220 QList<input_item_t*> inputItems = plMimeData->inputItems();
222 foreach( input_item_t* p_input, inputItems )
224 playlist_item_t *p_item = playlist_ItemGetByInput( p_playlist, p_input );
225 if( !p_item ) continue;
226 pos = playlist_NodeAddCopy( p_playlist, p_item, p_parent, pos );
232 void PLModel::dropMove( const PlMimeData * plMimeData, PLItem *target, int row )
234 QList<input_item_t*> inputItems = plMimeData->inputItems();
235 QList<PLItem*> model_items;
236 playlist_item_t *pp_items[inputItems.size()];
240 playlist_item_t *p_parent =
241 playlist_ItemGetByInput( p_playlist, target->p_input );
243 if( !p_parent || row > p_parent->i_children )
248 int new_pos = row == -1 ? p_parent->i_children : row;
249 int model_pos = new_pos;
252 foreach( input_item_t *p_input, inputItems )
254 playlist_item_t *p_item = playlist_ItemGetByInput( p_playlist, p_input );
255 if( !p_item ) continue;
257 PLItem *item = findByInput( rootItem, p_input->i_id );
258 if( !item ) continue;
260 /* Better not try to move a node into itself.
261 Abort the whole operation in that case,
262 because it is ambiguous. */
263 PLItem *climber = target;
266 if( climber == item )
270 climber = climber->parentItem;
273 if( item->parentItem == target &&
274 target->children.indexOf( item ) < new_pos )
277 model_items.append( item );
278 pp_items[i] = p_item;
282 if( model_items.isEmpty() )
287 playlist_TreeMoveMany( p_playlist, i, pp_items, p_parent, new_pos );
291 foreach( PLItem *item, model_items )
294 insertChildren( target, model_items, model_pos );
297 /* remove item with its id */
298 void PLModel::removeItem( int i_id )
300 PLItem *item = findById( rootItem, i_id );
304 void PLModel::activateItem( const QModelIndex &index )
306 assert( index.isValid() );
307 PLItem *item = getItem( index );
310 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id );
311 activateItem( p_item );
315 /* Must be entered with lock */
316 void PLModel::activateItem( playlist_item_t *p_item )
318 if( !p_item ) return;
319 playlist_item_t *p_parent = p_item;
322 if( p_parent->i_id == rootItem->i_id ) break;
323 p_parent = p_parent->p_parent;
326 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, pl_Locked,
330 /****************** Base model mandatory implementations *****************/
331 QVariant PLModel::data( const QModelIndex &index, int role ) const
333 if( !index.isValid() ) return QVariant();
334 PLItem *item = getItem( index );
335 if( role == Qt::DisplayRole )
337 int metadata = columnToMeta( index.column() );
338 if( metadata == COLUMN_END ) return QVariant();
341 if( metadata == COLUMN_NUMBER )
342 returninfo = QString::number( index.row() + 1 );
345 char *psz = psz_column_meta( item->p_input, metadata );
346 returninfo = qfu( psz );
349 return QVariant( returninfo );
351 else if( role == Qt::DecorationRole && index.column() == 0 )
353 /* Used to segfault here because i_type wasn't always initialized */
354 return QVariant( PLModel::icons[item->p_input->i_type] );
356 else if( role == Qt::FontRole )
358 if( isCurrent( index ) )
360 QFont f; f.setBold( true ); return QVariant( f );
363 else if( role == Qt::BackgroundRole && isCurrent( index ) )
365 return QVariant( QBrush( Qt::gray ) );
367 else if( role == IsCurrentRole ) return QVariant( isCurrent( index ) );
368 else if( role == IsLeafNodeRole )
372 playlist_item_t *plItem =
373 playlist_ItemGetById( p_playlist, item->i_id );
376 isLeaf = plItem->i_children == -1;
381 else if( role == IsCurrentsParentNodeRole )
383 return QVariant( isParent( index, current_index ) );
388 /* Seek from current index toward the top and see if index is one of parent nodes */
389 bool PLModel::isParent( const QModelIndex &index, const QModelIndex ¤t ) const
391 if( !index.isValid() )
394 if( index == current )
397 if( !current.isValid() || !current.parent().isValid() )
400 return isParent( index, current.parent() );
403 bool PLModel::isCurrent( const QModelIndex &index ) const
405 return index == current_index;
408 int PLModel::itemId( const QModelIndex &index ) const
410 return getItem( index )->i_id;
413 QVariant PLModel::headerData( int section, Qt::Orientation orientation,
416 if (orientation != Qt::Horizontal || role != Qt::DisplayRole)
419 int meta_col = columnToMeta( section );
421 if( meta_col == COLUMN_END ) return QVariant();
423 return QVariant( qfu( psz_column_title( meta_col ) ) );
426 QModelIndex PLModel::index( int row, int column, const QModelIndex &parent )
429 PLItem *parentItem = parent.isValid() ? getItem( parent ) : rootItem;
431 PLItem *childItem = parentItem->child( row );
433 return createIndex( row, column, childItem );
435 return QModelIndex();
438 QModelIndex PLModel::index( int i_id, int c )
440 return index( findById( rootItem, i_id ), c );
443 /* Return the index of a given item */
444 QModelIndex PLModel::index( PLItem *item, int column ) const
446 if( !item ) return QModelIndex();
447 const PLItem *parent = item->parent();
449 return createIndex( parent->children.lastIndexOf( item ),
451 return QModelIndex();
454 void PLModel::cacheCurrent( const QModelIndex ¤t )
456 current_index = current;
459 QModelIndex PLModel::currentIndex()
461 return current_index;
464 QModelIndex PLModel::parent( const QModelIndex &index ) const
466 if( !index.isValid() ) return QModelIndex();
468 PLItem *childItem = getItem( index );
471 msg_Err( p_playlist, "NULL CHILD" );
472 return QModelIndex();
475 PLItem *parentItem = childItem->parent();
476 if( !parentItem || parentItem == rootItem ) return QModelIndex();
477 if( !parentItem->parentItem )
479 msg_Err( p_playlist, "No parent parent, trying row 0 " );
480 msg_Err( p_playlist, "----- PLEASE REPORT THIS ------" );
481 return createIndex( 0, 0, parentItem );
483 return createIndex(parentItem->row(), 0, parentItem);
486 int PLModel::columnCount( const QModelIndex &i) const
488 return columnFromMeta( COLUMN_END );
491 int PLModel::rowCount( const QModelIndex &parent ) const
493 PLItem *parentItem = parent.isValid() ? getItem( parent ) : rootItem;
494 return parentItem->childCount();
497 QStringList PLModel::selectedURIs()
500 for( int i = 0; i < current_selection.size(); i++ )
502 PLItem *item = getItem( current_selection[i] );
506 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id );
509 char *psz = input_item_GetURI( p_item->p_input );
512 lst.append( qfu(psz) );
523 /************************* Lookups *****************************/
525 PLItem *PLModel::findById( PLItem *root, int i_id )
527 return findInner( root, i_id, false );
530 PLItem *PLModel::findByInput( PLItem *root, int i_id )
532 PLItem *result = findInner( root, i_id, true );
536 #define CACHE( i, p ) { i_cached_id = i; p_cached_item = p; }
537 #define ICACHE( i, p ) { i_cached_input_id = i; p_cached_item_bi = p; }
539 PLItem * PLModel::findInner( PLItem *root, int i_id, bool b_input )
541 if( !root ) return NULL;
542 if( ( !b_input && i_cached_id == i_id) ||
543 ( b_input && i_cached_input_id ==i_id ) )
545 return b_input ? p_cached_item_bi : p_cached_item;
548 if( !b_input && root->i_id == i_id )
553 else if( b_input && root->p_input->i_id == i_id )
555 ICACHE( i_id, root );
559 QList<PLItem *>::iterator it = root->children.begin();
560 while ( it != root->children.end() )
562 if( !b_input && (*it)->i_id == i_id )
564 CACHE( i_id, (*it) );
565 return p_cached_item;
567 else if( b_input && (*it)->p_input->i_id == i_id )
569 ICACHE( i_id, (*it) );
570 return p_cached_item_bi;
572 if( (*it)->children.size() )
574 PLItem *childFound = findInner( (*it), i_id, b_input );
578 ICACHE( i_id, childFound )
580 CACHE( i_id, childFound )
591 int PLModel::columnToMeta( int _column )
596 while( column != _column && meta != COLUMN_END )
605 int PLModel::columnFromMeta( int meta_col )
610 while( meta != meta_col && meta != COLUMN_END )
619 bool PLModel::canEdit() const
624 rootItem->p_input == p_playlist->p_playing->p_input ||
626 p_playlist->p_media_library &&
627 rootItem->p_input == p_playlist->p_media_library->p_input
632 /************************* Updates handling *****************************/
634 /**** Events processing ****/
635 void PLModel::processInputItemUpdate( input_thread_t *p_input )
637 if( !p_input ) return;
638 if( p_input && !( p_input->b_dead || !vlc_object_alive( p_input ) ) )
640 PLItem *item = findByInput( rootItem, input_GetItem( p_input )->i_id );
641 if( item ) emit currentChanged( index( item, 0 ) );
643 processInputItemUpdate( input_GetItem( p_input ) );
646 void PLModel::processInputItemUpdate( input_item_t *p_item )
648 if( !p_item || p_item->i_id <= 0 ) return;
649 PLItem *item = findByInput( rootItem, p_item->i_id );
651 updateTreeItem( item );
654 void PLModel::processItemRemoval( int i_id )
656 if( i_id <= 0 ) return;
660 void PLModel::processItemAppend( int i_item, int i_parent )
662 playlist_item_t *p_item = NULL;
663 PLItem *newItem = NULL;
664 input_thread_t *currentInputThread;
667 PLItem *nodeItem = findById( rootItem, i_parent );
668 if( !nodeItem ) return;
670 foreach( PLItem *existing, nodeItem->children )
671 if( existing->i_id == i_item ) return;
674 p_item = playlist_ItemGetById( p_playlist, i_item );
675 if( !p_item || p_item->i_flags & PLAYLIST_DBL_FLAG )
680 for( pos = 0; pos < p_item->p_parent->i_children; pos++ )
681 if( p_item->p_parent->pp_children[pos] == p_item ) break;
683 newItem = new PLItem( p_item, nodeItem );
686 beginInsertRows( index( nodeItem, 0 ), pos, pos );
687 nodeItem->insertChild( newItem, pos );
690 if( newItem->p_input == THEMIM->currentInputItem() )
691 emit currentChanged( index( newItem, 0 ) );
695 void PLModel::rebuild()
700 void PLModel::rebuild( playlist_item_t *p_root )
702 playlist_item_t* p_item;
704 /* Invalidate cache */
705 i_cached_id = i_cached_input_id = -1;
706 current_index = QModelIndex();
708 if( rootItem ) rootItem->removeChildren();
714 rootItem = new PLItem( p_root );
717 /* Recreate from root */
718 updateChildren( rootItem );
721 /* And signal the view */
724 if( p_root ) emit rootChanged();
727 void PLModel::takeItem( PLItem *item )
730 PLItem *parent = item->parentItem;
732 int i_index = parent->children.indexOf( item );
734 beginRemoveRows( index( parent, 0 ), i_index, i_index );
735 parent->takeChildAt( i_index );
739 void PLModel::insertChildren( PLItem *node, QList<PLItem*>& items, int i_pos )
742 int count = items.size();
744 beginInsertRows( index( node, 0 ), i_pos, i_pos + count - 1 );
745 for( int i = 0; i < count; i++ )
747 node->children.insert( i_pos + i, items[i] );
748 items[i]->parentItem = node;
753 void PLModel::removeItem( PLItem *item )
758 i_cached_input_id = -1;
759 current_index = QModelIndex();
761 if( item->parentItem ) {
762 int i = item->parentItem->children.indexOf( item );
763 beginRemoveRows( index( item->parentItem, 0), i, i );
764 item->parentItem->children.removeAt(i);
773 rebuild( p_playlist->p_playing );
777 /* This function must be entered WITH the playlist lock */
778 void PLModel::updateChildren( PLItem *root )
780 playlist_item_t *p_node = playlist_ItemGetById( p_playlist, root->i_id );
781 updateChildren( p_node, root );
784 /* This function must be entered WITH the playlist lock */
785 void PLModel::updateChildren( playlist_item_t *p_node, PLItem *root )
787 for( int i = 0; i < p_node->i_children ; i++ )
789 if( p_node->pp_children[i]->i_flags & PLAYLIST_DBL_FLAG ) continue;
790 PLItem *newItem = new PLItem( p_node->pp_children[i], root );
791 root->appendChild( newItem );
792 if( p_node->pp_children[i]->i_children != -1 )
793 updateChildren( p_node->pp_children[i], newItem );
797 /* Function doesn't need playlist-lock, as we don't touch playlist_item_t stuff here*/
798 void PLModel::updateTreeItem( PLItem *item )
801 emit dataChanged( index( item, 0 ) , index( item, columnCount( QModelIndex() ) ) );
804 /************************* Actions ******************************/
807 * Deletion, don't delete items childrens if item is going to be
808 * delete allready, so we remove childrens from selection-list.
810 void PLModel::doDelete( QModelIndexList selected )
812 if( !canEdit() ) return;
814 while( !selected.isEmpty() )
816 QModelIndex index = selected[0];
817 selected.removeAt( 0 );
819 if( index.column() != 0 ) continue;
821 PLItem *item = getItem( index );
822 if( item->children.size() )
823 recurseDelete( item->children, &selected );
826 playlist_DeleteFromInput( p_playlist, item->p_input, pl_Locked );
833 void PLModel::recurseDelete( QList<PLItem*> children, QModelIndexList *fullList )
835 for( int i = children.size() - 1; i >= 0 ; i-- )
837 PLItem *item = children[i];
838 if( item->children.size() )
839 recurseDelete( item->children, fullList );
840 fullList->removeAll( index( item, 0 ) );
844 /******* Volume III: Sorting and searching ********/
845 void PLModel::sort( int column, Qt::SortOrder order )
847 sort( rootItem->i_id, column, order );
850 void PLModel::sort( int i_root_id, int column, Qt::SortOrder order )
852 msg_Dbg( p_intf, "Sorting by column %i, order %i", column, order );
854 int meta = columnToMeta( column );
855 if( meta == COLUMN_END ) return;
857 PLItem *item = findById( rootItem, i_root_id );
859 QModelIndex qIndex = index( item, 0 );
860 int count = item->children.size();
863 beginRemoveRows( qIndex, 0, count - 1 );
864 item->removeChildren();
870 playlist_item_t *p_root = playlist_ItemGetById( p_playlist,
874 playlist_RecursiveNodeSort( p_playlist, p_root,
875 i_column_sorting( meta ),
876 order == Qt::AscendingOrder ?
877 ORDER_NORMAL : ORDER_REVERSE );
881 i_cached_id = i_cached_input_id = -1;
882 current_index = QModelIndex();
886 beginInsertRows( qIndex, 0, count - 1 );
887 updateChildren( item );
891 /* if we have popup item, try to make sure that you keep that item visible */
892 if( i_popup_item > -1 )
894 PLItem *popupitem = findById( rootItem, i_popup_item );
895 if( popupitem ) emit currentChanged( index( popupitem, 0 ) );
896 /* reset i_popup_item as we don't show it as selected anymore anyway */
899 else if( currentIndex().isValid() ) emit currentChanged( currentIndex() );
902 void PLModel::search( const QString& search_text, const QModelIndex & idx, bool b_recursive )
904 /** \todo Fire the search with a small delay ? */
907 playlist_item_t *p_root = playlist_ItemGetById( p_playlist,
910 const char *psz_name = qtu( search_text );
911 playlist_LiveSearchUpdate( p_playlist , p_root, psz_name, b_recursive );
915 PLItem *searchRoot = getItem( idx );
917 beginRemoveRows( idx, 0, searchRoot->children.size() - 1 );
918 searchRoot->removeChildren();
921 beginInsertRows( idx, 0, searchRoot->children.size() - 1 );
922 updateChildren( searchRoot );
933 /*********** Popup *********/
934 bool PLModel::popup( const QModelIndex & index, const QPoint &point, const QModelIndexList &list )
936 int i_id = index.isValid() ? itemId( index ) : rootItem->i_id;
939 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, i_id );
946 i_popup_item = index.isValid() ? p_item->i_id : -1;
947 i_popup_parent = index.isValid() ?
948 ( p_item->p_parent ? p_item->p_parent->i_id : -1 ) :
950 i_popup_column = index.column();
952 bool tree = ( rootItem && rootItem->i_id != p_playlist->p_playing->i_id ) ||
953 var_InheritBool( p_intf, "playlist-tree" );
957 current_selection = list;
960 if( i_popup_item > -1 )
962 menu.addAction( QIcon( ":/menu/play" ), qtr(I_POP_PLAY), this, SLOT( popupPlay() ) );
963 menu.addAction( QIcon( ":/menu/stream" ),
964 qtr(I_POP_STREAM), this, SLOT( popupStream() ) );
965 menu.addAction( qtr(I_POP_SAVE), this, SLOT( popupSave() ) );
966 menu.addAction( QIcon( ":/menu/info" ), qtr(I_POP_INFO), this, SLOT( popupInfo() ) );
967 menu.addAction( QIcon( ":/type/folder-grey" ),
968 qtr( I_POP_EXPLORE ), this, SLOT( popupExplore() ) );
973 QIcon addIcon( ":/buttons/playlist/playlist_add" );
975 if( tree ) menu.addAction( addIcon, qtr(I_POP_NEWFOLDER), this, SLOT( popupAddNode() ) );
976 if( rootItem->i_id == THEPL->p_playing->i_id )
978 menu.addAction( addIcon, qtr(I_PL_ADDF), THEDP, SLOT( simplePLAppendDialog()) );
979 menu.addAction( addIcon, qtr(I_PL_ADDDIR), THEDP, SLOT( PLAppendDir()) );
980 menu.addAction( addIcon, qtr(I_OP_ADVOP), THEDP, SLOT( PLAppendDialog()) );
982 else if( THEPL->p_media_library &&
983 rootItem->i_id == THEPL->p_media_library->i_id )
985 menu.addAction( addIcon, qtr(I_PL_ADDF), THEDP, SLOT( simpleMLAppendDialog()) );
986 menu.addAction( addIcon, qtr(I_PL_ADDDIR), THEDP, SLOT( MLAppendDir() ) );
987 menu.addAction( addIcon, qtr(I_OP_ADVOP), THEDP, SLOT( MLAppendDialog() ) );
990 if( i_popup_item > -1 )
992 menu.addAction( QIcon( ":/buttons/playlist/playlist_remove" ),
993 qtr(I_POP_DEL), this, SLOT( popupDel() ) );
997 sortingMenu = new QMenu( qtr( "Sort by" ) );
998 sortingMapper = new QSignalMapper( this );
1000 for( i = 1, j = 1; i < COLUMN_END; i <<= 1, j++ )
1002 if( i == COLUMN_NUMBER ) continue;
1003 QMenu *m = sortingMenu->addMenu( qfu( psz_column_title( i ) ) );
1004 QAction *asc = m->addAction( qtr("Ascending") );
1005 QAction *desc = m->addAction( qtr("Descending") );
1006 sortingMapper->setMapping( asc, j );
1007 sortingMapper->setMapping( desc, -j );
1008 CONNECT( asc, triggered(), sortingMapper, map() );
1009 CONNECT( desc, triggered(), sortingMapper, map() );
1011 CONNECT( sortingMapper, mapped( int ), this, popupSort( int ) );
1013 menu.addMenu( sortingMenu );
1015 if( !menu.isEmpty() )
1017 menu.exec( point ); return true;
1022 void PLModel::popupDel()
1024 doDelete( current_selection );
1027 void PLModel::popupPlay()
1031 playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
1033 activateItem( p_item );
1038 void PLModel::popupInfo()
1041 playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
1045 input_item_t* p_input = p_item->p_input;
1046 vlc_gc_incref( p_input );
1048 MediaInfoDialog *mid = new MediaInfoDialog( p_intf, p_input );
1049 vlc_gc_decref( p_input );
1050 mid->setParent( PlaylistDialog::getInstance( p_intf ),
1057 void PLModel::popupStream()
1059 QStringList mrls = selectedURIs();
1060 if( !mrls.isEmpty() )
1061 THEDP->streamingDialog( NULL, mrls[0], false );
1065 void PLModel::popupSave()
1067 QStringList mrls = selectedURIs();
1068 if( !mrls.isEmpty() )
1069 THEDP->streamingDialog( NULL, mrls[0] );
1072 void PLModel::popupExplore()
1075 playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
1079 input_item_t *p_input = p_item->p_input;
1080 char *psz_meta = input_item_GetURI( p_input );
1084 const char *psz_access;
1085 const char *psz_demux;
1087 input_SplitMRL( &psz_access, &psz_demux, &psz_path, psz_meta );
1089 if( !EMPTY_STR( psz_access ) && (
1090 !strncasecmp( psz_access, "file", 4 ) ||
1091 !strncasecmp( psz_access, "dire", 4 ) ))
1093 QFileInfo info( qfu( decode_URI( psz_path ) ) );
1094 QDesktopServices::openUrl(
1095 QUrl::fromLocalFile( info.absolutePath() ) );
1104 void PLModel::popupAddNode()
1107 QString name = QInputDialog::getText( PlaylistDialog::getInstance( p_intf ),
1108 qtr( I_NEW_DIR ), qtr( I_NEW_DIR_NAME ),
1109 QLineEdit::Normal, QString(), &ok);
1110 if( !ok || name.isEmpty() ) return;
1112 playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
1116 playlist_NodeCreate( p_playlist, qtu( name ), p_item, PLAYLIST_END, 0, NULL );
1121 void PLModel::popupSort( int column )
1123 sort( i_popup_parent,
1124 column > 0 ? column - 1 : -column - 1,
1125 column > 0 ? Qt::AscendingOrder : Qt::DescendingOrder );
1128 /******************* Drag and Drop helper class ******************/
1130 PlMimeData::PlMimeData( )
1133 PlMimeData::~PlMimeData()
1135 foreach( input_item_t *p_item, _inputItems )
1136 vlc_gc_decref( p_item );
1139 void PlMimeData::appendItem( input_item_t *p_item )
1141 vlc_gc_incref( p_item );
1142 _inputItems.append( p_item );
1145 QList<input_item_t*> PlMimeData::inputItems() const
1150 QStringList PlMimeData::formats () const
1153 fmts << "vlc/qt-input-items";