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 "components/playlist/playlist_model.hpp"
32 #include "dialogs_provider.hpp" /* THEDP */
33 #include "input_manager.hpp" /* THEMIM */
34 #include "dialogs/mediainfo.hpp" /* MediaInfo Dialog */
35 #include "dialogs/playlist.hpp" /* Playlist Dialog */
37 #include <vlc_intf_strings.h> /* I_DIR */
39 #include "pixmaps/types/type_unknown.xpm"
48 #include <QDesktopServices>
49 #include <QInputDialog>
50 #include <QSignalMapper>
51 #include <QPixmapCache>
54 I_DIR_OR_FOLDER( N_("Create Directory"), N_( "Create Folder" ) )
55 #define I_NEW_DIR_NAME \
56 I_DIR_OR_FOLDER( N_( "Enter name for new directory:" ), \
57 N_( "Enter name for new folder:" ) )
59 QIcon PLModel::icons[ITEM_TYPE_NUMBER];
61 /*************************************************************************
62 * Playlist model implementation
63 *************************************************************************/
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 QObject *parent ) /* Basic Qt parent */
69 : VLCModel( _p_intf, 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 | Qt::MoveAction;
114 Qt::ItemFlags PLModel::flags( const QModelIndex &index ) const
116 Qt::ItemFlags flags = QAbstractItemModel::flags( index );
118 const 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 bool copy = action == Qt::CopyAction;
193 if( !copy && action != Qt::MoveAction )
196 const PlMimeData *plMimeData = qobject_cast<const PlMimeData*>( data );
200 dropAppendCopy( plMimeData, getItem( parent ), row );
202 dropMove( plMimeData, getItem( parent ), row );
207 void PLModel::dropAppendCopy( const PlMimeData *plMimeData, PLItem *target, int pos )
211 playlist_item_t *p_parent =
212 playlist_ItemGetByInput( p_playlist, target->p_input );
213 if( !p_parent ) return;
215 if( pos == -1 ) pos = PLAYLIST_END;
217 QList<input_item_t*> inputItems = plMimeData->inputItems();
219 foreach( input_item_t* p_input, inputItems )
221 playlist_item_t *p_item = playlist_ItemGetByInput( p_playlist, p_input );
222 if( !p_item ) continue;
223 pos = playlist_NodeAddCopy( p_playlist, p_item, p_parent, pos );
229 void PLModel::dropMove( const PlMimeData * plMimeData, PLItem *target, int row )
231 QList<input_item_t*> inputItems = plMimeData->inputItems();
232 QList<PLItem*> model_items;
233 playlist_item_t *pp_items[inputItems.size()];
237 playlist_item_t *p_parent =
238 playlist_ItemGetByInput( p_playlist, target->p_input );
240 if( !p_parent || row > p_parent->i_children )
245 int new_pos = row == -1 ? p_parent->i_children : row;
246 int model_pos = new_pos;
249 foreach( input_item_t *p_input, inputItems )
251 playlist_item_t *p_item = playlist_ItemGetByInput( p_playlist, p_input );
252 if( !p_item ) continue;
254 PLItem *item = findByInput( rootItem, p_input->i_id );
255 if( !item ) continue;
257 /* Better not try to move a node into itself.
258 Abort the whole operation in that case,
259 because it is ambiguous. */
260 PLItem *climber = target;
263 if( climber == item )
267 climber = climber->parentItem;
270 if( item->parentItem == target &&
271 target->children.indexOf( item ) < new_pos )
274 model_items.append( item );
275 pp_items[i] = p_item;
279 if( model_items.isEmpty() )
284 playlist_TreeMoveMany( p_playlist, i, pp_items, p_parent, new_pos );
288 foreach( PLItem *item, model_items )
291 insertChildren( target, model_items, model_pos );
294 /* remove item with its id */
295 void PLModel::removeItem( int i_id )
297 PLItem *item = findById( rootItem, i_id );
301 void PLModel::activateItem( const QModelIndex &index )
303 assert( index.isValid() );
304 const PLItem *item = getItem( index );
307 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id );
308 activateItem( p_item );
312 /* Must be entered with lock */
313 void PLModel::activateItem( playlist_item_t *p_item )
315 if( !p_item ) return;
316 playlist_item_t *p_parent = p_item;
319 if( p_parent->i_id == rootItem->i_id ) break;
320 p_parent = p_parent->p_parent;
323 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, pl_Locked,
327 /****************** Base model mandatory implementations *****************/
328 QVariant PLModel::data( const QModelIndex &index, const int role ) const
330 if( !index.isValid() ) return QVariant();
331 const PLItem *item = getItem( index );
332 if( role == Qt::DisplayRole )
334 int metadata = columnToMeta( index.column() );
335 if( metadata == COLUMN_END ) return QVariant();
338 if( metadata == COLUMN_NUMBER )
339 returninfo = QString::number( index.row() + 1 );
340 else if( metadata == COLUMN_COVER )
343 artUrl = InputManager::decodeArtURL( item->inputItem() );
344 if( artUrl.isEmpty() )
346 for( int i = 0; i < item->childCount(); i++ )
348 artUrl = InputManager::decodeArtURL( item->child( i )->inputItem() );
349 if( !artUrl.isEmpty() )
353 return QVariant( artUrl );
357 char *psz = psz_column_meta( item->p_input, metadata );
358 returninfo = qfu( psz );
361 return QVariant( returninfo );
363 else if( role == Qt::DecorationRole && index.column() == 0 )
365 /* Used to segfault here because i_type wasn't always initialized */
366 return QVariant( PLModel::icons[item->p_input->i_type] );
368 else if( role == Qt::FontRole )
371 f.setPointSize( f.pointSize() - 1 );
372 if( isCurrent( index ) )
374 return QVariant( f );
376 else if( role == Qt::BackgroundRole && isCurrent( index ) )
378 return QVariant( QBrush( Qt::gray ) );
380 else if( role == IsCurrentRole ) return QVariant( isCurrent( index ) );
381 else if( role == IsLeafNodeRole )
385 playlist_item_t *plItem =
386 playlist_ItemGetById( p_playlist, item->i_id );
389 isLeaf = plItem->i_children == -1;
394 else if( role == IsCurrentsParentNodeRole )
396 return QVariant( isParent( index, currentIndex() ) );
401 /* Seek from current index toward the top and see if index is one of parent nodes */
402 bool PLModel::isParent( const QModelIndex &index, const QModelIndex ¤t ) const
404 if( !index.isValid() )
407 if( index == current )
410 if( !current.isValid() || !current.parent().isValid() )
413 return isParent( index, current.parent() );
416 bool PLModel::isCurrent( const QModelIndex &index ) const
418 return getItem( index )->p_input == THEMIM->currentInputItem();
421 int PLModel::itemId( const QModelIndex &index ) const
423 return getItem( index )->i_id;
426 QVariant PLModel::headerData( int section, Qt::Orientation orientation,
429 if (orientation != Qt::Horizontal || role != Qt::DisplayRole)
432 int meta_col = columnToMeta( section );
434 if( meta_col == COLUMN_END ) return QVariant();
436 return QVariant( qfu( psz_column_title( meta_col ) ) );
439 QModelIndex PLModel::index( const int row, const int column, const QModelIndex &parent )
442 PLItem *parentItem = parent.isValid() ? getItem( parent ) : rootItem;
444 PLItem *childItem = parentItem->child( row );
446 return createIndex( row, column, childItem );
448 return QModelIndex();
451 QModelIndex PLModel::index( const int i_id, const int c )
453 return index( findById( rootItem, i_id ), c );
456 /* Return the index of a given item */
457 QModelIndex PLModel::index( PLItem *item, int column ) const
459 if( !item ) return QModelIndex();
460 const PLItem *parent = item->parent();
462 return createIndex( parent->children.lastIndexOf( item ),
464 return QModelIndex();
467 QModelIndex PLModel::currentIndex() const
469 input_thread_t *p_input_thread = THEMIM->getInput();
470 if( !p_input_thread ) return QModelIndex();
471 PLItem *item = findByInput( rootItem, input_GetItem( p_input_thread )->i_id );
472 return index( item, 0 );
475 QModelIndex PLModel::parent( const QModelIndex &index ) const
477 if( !index.isValid() ) return QModelIndex();
479 PLItem *childItem = getItem( index );
482 msg_Err( p_playlist, "NULL CHILD" );
483 return QModelIndex();
486 PLItem *parentItem = childItem->parent();
487 if( !parentItem || parentItem == rootItem ) return QModelIndex();
488 if( !parentItem->parentItem )
490 msg_Err( p_playlist, "No parent parent, trying row 0 " );
491 msg_Err( p_playlist, "----- PLEASE REPORT THIS ------" );
492 return createIndex( 0, 0, parentItem );
494 return createIndex(parentItem->row(), 0, parentItem);
497 int PLModel::columnCount( const QModelIndex &i) const
499 return columnFromMeta( COLUMN_END );
502 int PLModel::rowCount( const QModelIndex &parent ) const
504 const PLItem *parentItem = parent.isValid() ? getItem( parent ) : rootItem;
505 return parentItem->childCount();
508 QStringList PLModel::selectedURIs()
511 for( int i = 0; i < current_selection.size(); i++ )
513 const PLItem *item = getItem( current_selection[i] );
517 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id );
520 char *psz = input_item_GetURI( p_item->p_input );
523 lst.append( qfu(psz) );
533 /************************* Lookups *****************************/
534 PLItem *PLModel::findById( PLItem *root, int i_id ) const
536 return findInner( root, i_id, false );
539 PLItem *PLModel::findByInput( PLItem *root, int i_id ) const
541 PLItem *result = findInner( root, i_id, true );
545 PLItem * PLModel::findInner( PLItem *root, int i_id, bool b_input ) const
547 if( !root ) return NULL;
549 if( !b_input && root->i_id == i_id )
552 else if( b_input && root->p_input->i_id == i_id )
555 QList<PLItem *>::iterator it = root->children.begin();
556 while ( it != root->children.end() )
558 if( !b_input && (*it)->i_id == i_id )
561 else if( b_input && (*it)->p_input->i_id == i_id )
564 if( (*it)->children.size() )
566 PLItem *childFound = findInner( (*it), i_id, b_input );
575 bool PLModel::canEdit() const
580 rootItem->p_input == p_playlist->p_playing->p_input ||
581 ( p_playlist->p_media_library &&
582 rootItem->p_input == p_playlist->p_media_library->p_input )
587 /************************* Updates handling *****************************/
589 /**** Events processing ****/
590 void PLModel::processInputItemUpdate( input_thread_t *p_input )
592 if( !p_input ) return;
593 if( p_input && !( p_input->b_dead || !vlc_object_alive( p_input ) ) )
595 PLItem *item = findByInput( rootItem, input_GetItem( p_input )->i_id );
596 if( item ) emit currentChanged( index( item, 0 ) );
598 processInputItemUpdate( input_GetItem( p_input ) );
601 void PLModel::processInputItemUpdate( input_item_t *p_item )
603 if( !p_item || p_item->i_id <= 0 ) return;
604 PLItem *item = findByInput( rootItem, p_item->i_id );
606 updateTreeItem( item );
609 void PLModel::processItemRemoval( int i_id )
611 if( i_id <= 0 ) return;
615 void PLModel::processItemAppend( int i_item, int i_parent )
617 playlist_item_t *p_item = NULL;
618 PLItem *newItem = NULL;
621 /* Find the Parent */
622 PLItem *nodeParentItem = findById( rootItem, i_parent );
623 if( !nodeParentItem ) return;
625 /* Search for an already matching children */
626 foreach( const PLItem *existing, nodeParentItem->children )
627 if( existing->i_id == i_item ) return;
631 p_item = playlist_ItemGetById( p_playlist, i_item );
632 if( !p_item || p_item->i_flags & PLAYLIST_DBL_FLAG )
637 for( pos = 0; pos < p_item->p_parent->i_children; pos++ )
638 if( p_item->p_parent->pp_children[pos] == p_item ) break;
640 newItem = new PLItem( p_item, nodeParentItem );
643 /* We insert the newItem (children) inside the parent */
644 beginInsertRows( index( nodeParentItem, 0 ), pos, pos );
645 nodeParentItem->insertChild( newItem, pos );
648 if( newItem->p_input == THEMIM->currentInputItem() )
649 emit currentChanged( index( newItem, 0 ) );
652 void PLModel::rebuild()
657 void PLModel::rebuild( playlist_item_t *p_root )
659 playlist_item_t* p_item;
661 /* Invalidate cache */
662 i_cached_id = i_cached_input_id = -1;
664 if( rootItem ) rootItem->removeChildren();
670 rootItem = new PLItem( p_root );
673 /* Recreate from root */
674 updateChildren( rootItem );
677 /* And signal the view */
680 if( p_root ) emit rootChanged();
683 void PLModel::takeItem( PLItem *item )
686 PLItem *parent = item->parentItem;
688 int i_index = parent->children.indexOf( item );
690 beginRemoveRows( index( parent, 0 ), i_index, i_index );
691 parent->takeChildAt( i_index );
695 void PLModel::insertChildren( PLItem *node, QList<PLItem*>& items, int i_pos )
698 int count = items.size();
700 printf( "Here I am\n");
701 beginInsertRows( index( node, 0 ), i_pos, i_pos + count - 1 );
702 for( int i = 0; i < count; i++ )
704 node->children.insert( i_pos + i, items[i] );
705 items[i]->parentItem = node;
710 void PLModel::removeItem( PLItem *item )
715 i_cached_input_id = -1;
717 if( item->parentItem ) {
718 int i = item->parentItem->children.indexOf( item );
719 beginRemoveRows( index( item->parentItem, 0), i, i );
720 item->parentItem->children.removeAt(i);
729 rebuild( p_playlist->p_playing );
733 /* This function must be entered WITH the playlist lock */
734 void PLModel::updateChildren( PLItem *root )
736 playlist_item_t *p_node = playlist_ItemGetById( p_playlist, root->i_id );
737 updateChildren( p_node, root );
740 /* This function must be entered WITH the playlist lock */
741 void PLModel::updateChildren( playlist_item_t *p_node, PLItem *root )
743 for( int i = 0; i < p_node->i_children ; i++ )
745 if( p_node->pp_children[i]->i_flags & PLAYLIST_DBL_FLAG ) continue;
746 PLItem *newItem = new PLItem( p_node->pp_children[i], root );
747 root->appendChild( newItem );
748 if( p_node->pp_children[i]->i_children != -1 )
749 updateChildren( p_node->pp_children[i], newItem );
753 /* Function doesn't need playlist-lock, as we don't touch playlist_item_t stuff here*/
754 void PLModel::updateTreeItem( PLItem *item )
757 emit dataChanged( index( item, 0 ) , index( item, columnCount( QModelIndex() ) ) );
760 /************************* Actions ******************************/
763 * Deletion, don't delete items childrens if item is going to be
764 * delete allready, so we remove childrens from selection-list.
766 void PLModel::doDelete( QModelIndexList selected )
768 if( !canEdit() ) return;
770 while( !selected.isEmpty() )
772 QModelIndex index = selected[0];
773 selected.removeAt( 0 );
775 if( index.column() != 0 ) continue;
777 PLItem *item = getItem( index );
778 if( item->children.size() )
779 recurseDelete( item->children, &selected );
782 playlist_DeleteFromInput( p_playlist, item->p_input, pl_Locked );
789 void PLModel::recurseDelete( QList<PLItem*> children, QModelIndexList *fullList )
791 for( int i = children.size() - 1; i >= 0 ; i-- )
793 PLItem *item = children[i];
794 if( item->children.size() )
795 recurseDelete( item->children, fullList );
796 fullList->removeAll( index( item, 0 ) );
800 /******* Volume III: Sorting and searching ********/
801 void PLModel::sort( const int column, Qt::SortOrder order )
803 sort( rootItem->i_id, column, order );
806 void PLModel::sort( const int i_root_id, const int column, Qt::SortOrder order )
808 msg_Dbg( p_intf, "Sorting by column %i, order %i", column, order );
810 int meta = columnToMeta( column );
811 if( meta == COLUMN_END ) return;
813 PLItem *item = findById( rootItem, i_root_id );
815 QModelIndex qIndex = index( item, 0 );
816 int count = item->children.size();
819 beginRemoveRows( qIndex, 0, count - 1 );
820 item->removeChildren();
826 playlist_item_t *p_root = playlist_ItemGetById( p_playlist,
830 playlist_RecursiveNodeSort( p_playlist, p_root,
831 i_column_sorting( meta ),
832 order == Qt::AscendingOrder ?
833 ORDER_NORMAL : ORDER_REVERSE );
837 i_cached_id = i_cached_input_id = -1;
841 beginInsertRows( qIndex, 0, count - 1 );
842 updateChildren( item );
846 /* if we have popup item, try to make sure that you keep that item visible */
847 if( i_popup_item > -1 )
849 PLItem *popupitem = findById( rootItem, i_popup_item );
850 if( popupitem ) emit currentChanged( index( popupitem, 0 ) );
851 /* reset i_popup_item as we don't show it as selected anymore anyway */
854 else if( currentIndex().isValid() ) emit currentChanged( currentIndex() );
857 void PLModel::search( const QString& search_text, const QModelIndex & idx, bool b_recursive )
859 /** \todo Fire the search with a small delay ? */
862 playlist_item_t *p_root = playlist_ItemGetById( p_playlist,
865 const char *psz_name = qtu( search_text );
866 playlist_LiveSearchUpdate( p_playlist , p_root, psz_name, b_recursive );
870 PLItem *searchRoot = getItem( idx );
872 beginRemoveRows( idx, 0, searchRoot->children.size() - 1 );
873 searchRoot->removeChildren();
876 beginInsertRows( idx, 0, searchRoot->children.size() - 1 );
877 updateChildren( searchRoot ); // The PL_LOCK is needed here
888 /*********** Popup *********/
889 bool PLModel::popup( const QModelIndex & index, const QPoint &point, const QModelIndexList &list )
891 int i_id = index.isValid() ? itemId( index ) : rootItem->i_id;
894 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, i_id );
901 input_item_t *p_input = p_item->p_input;
902 vlc_gc_incref( p_input );
904 i_popup_item = index.isValid() ? p_item->i_id : -1;
905 i_popup_parent = index.isValid() ?
906 ( p_item->p_parent ? p_item->p_parent->i_id : -1 ) :
908 i_popup_column = index.column();
910 bool tree = ( rootItem && rootItem->i_id != p_playlist->p_playing->i_id ) ||
911 var_InheritBool( p_intf, "playlist-tree" );
915 current_selection = list;
918 if( i_popup_item > -1 )
920 menu.addAction( QIcon( ":/menu/play" ), qtr(I_POP_PLAY), this, SLOT( popupPlay() ) );
921 menu.addAction( QIcon( ":/menu/stream" ),
922 qtr(I_POP_STREAM), this, SLOT( popupStream() ) );
923 menu.addAction( qtr(I_POP_SAVE), this, SLOT( popupSave() ) );
924 menu.addAction( QIcon( ":/menu/info" ), qtr(I_POP_INFO), this, SLOT( popupInfo() ) );
925 if( p_input->psz_uri && !strncasecmp( p_input->psz_uri, "file://", 7 ) )
927 menu.addAction( QIcon( ":/type/folder-grey" ),
928 qtr( I_POP_EXPLORE ), this, SLOT( popupExplore() ) );
932 vlc_gc_decref( p_input );
936 QIcon addIcon( ":/buttons/playlist/playlist_add" );
938 if( tree ) menu.addAction( addIcon, qtr(I_POP_NEWFOLDER), this, SLOT( popupAddNode() ) );
939 if( rootItem->i_id == THEPL->p_playing->i_id )
941 menu.addAction( addIcon, qtr(I_PL_ADDF), THEDP, SLOT( simplePLAppendDialog()) );
942 menu.addAction( addIcon, qtr(I_PL_ADDDIR), THEDP, SLOT( PLAppendDir()) );
943 menu.addAction( addIcon, qtr(I_OP_ADVOP), THEDP, SLOT( PLAppendDialog()) );
945 else if( THEPL->p_media_library &&
946 rootItem->i_id == THEPL->p_media_library->i_id )
948 menu.addAction( addIcon, qtr(I_PL_ADDF), THEDP, SLOT( simpleMLAppendDialog()) );
949 menu.addAction( addIcon, qtr(I_PL_ADDDIR), THEDP, SLOT( MLAppendDir() ) );
950 menu.addAction( addIcon, qtr(I_OP_ADVOP), THEDP, SLOT( MLAppendDialog() ) );
953 if( i_popup_item > -1 )
955 menu.addAction( QIcon( ":/buttons/playlist/playlist_remove" ),
956 qtr(I_POP_DEL), this, SLOT( popupDel() ) );
960 sortingMenu = new QMenu( qtr( "Sort by" ) );
961 sortingMapper = new QSignalMapper( this );
962 for( int i = 1, j = 1; i < COLUMN_END; i <<= 1, j++ )
964 if( i == COLUMN_NUMBER ) continue;
965 QMenu *m = sortingMenu->addMenu( qfu( psz_column_title( i ) ) );
966 QAction *asc = m->addAction( qtr("Ascending") );
967 QAction *desc = m->addAction( qtr("Descending") );
968 sortingMapper->setMapping( asc, j );
969 sortingMapper->setMapping( desc, -j );
970 CONNECT( asc, triggered(), sortingMapper, map() );
971 CONNECT( desc, triggered(), sortingMapper, map() );
973 CONNECT( sortingMapper, mapped( int ), this, popupSort( int ) );
975 menu.addMenu( sortingMenu );
978 if( !menu.isEmpty() )
980 menu.exec( point ); return true;
985 void PLModel::popupDel()
987 doDelete( current_selection );
990 void PLModel::popupPlay()
994 playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
996 activateItem( p_item );
1001 void PLModel::popupInfo()
1004 playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
1008 input_item_t* p_input = p_item->p_input;
1009 vlc_gc_incref( p_input );
1011 MediaInfoDialog *mid = new MediaInfoDialog( p_intf, p_input );
1012 vlc_gc_decref( p_input );
1013 mid->setParent( PlaylistDialog::getInstance( p_intf ),
1020 void PLModel::popupStream()
1022 QStringList mrls = selectedURIs();
1023 if( !mrls.isEmpty() )
1024 THEDP->streamingDialog( NULL, mrls[0], false );
1028 void PLModel::popupSave()
1030 QStringList mrls = selectedURIs();
1031 if( !mrls.isEmpty() )
1032 THEDP->streamingDialog( NULL, mrls[0] );
1035 void PLModel::popupExplore()
1038 playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
1042 input_item_t *p_input = p_item->p_input;
1043 char *psz_meta = input_item_GetURI( p_input );
1047 const char *psz_access;
1048 const char *psz_demux;
1050 input_SplitMRL( &psz_access, &psz_demux, &psz_path, psz_meta );
1052 if( !EMPTY_STR( psz_access ) && (
1053 !strncasecmp( psz_access, "file", 4 ) ||
1054 !strncasecmp( psz_access, "dire", 4 ) ))
1056 #if defined( WIN32 ) || defined( __OS2__ )
1057 /* Qt openURL doesn't know to open files that starts with a / or \ */
1058 if( psz_path[0] == '/' || psz_path[0] == '\\' )
1062 QFileInfo info( qfu( decode_URI( psz_path ) ) );
1063 QDesktopServices::openUrl(
1064 QUrl::fromLocalFile( info.absolutePath() ) );
1073 void PLModel::popupAddNode()
1076 QString name = QInputDialog::getText( PlaylistDialog::getInstance( p_intf ),
1077 qtr( I_NEW_DIR ), qtr( I_NEW_DIR_NAME ),
1078 QLineEdit::Normal, QString(), &ok);
1079 if( !ok || name.isEmpty() ) return;
1082 playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
1085 playlist_NodeCreate( p_playlist, qtu( name ), p_item, PLAYLIST_END, 0, NULL );
1089 void PLModel::popupSort( int column )
1091 sort( i_popup_parent,
1092 column > 0 ? column - 1 : -column - 1,
1093 column > 0 ? Qt::AscendingOrder : Qt::DescendingOrder );
1096 /******************* Drag and Drop helper class ******************/
1098 PlMimeData::PlMimeData( )
1101 PlMimeData::~PlMimeData()
1103 foreach( input_item_t *p_item, _inputItems )
1104 vlc_gc_decref( p_item );
1107 void PlMimeData::appendItem( input_item_t *p_item )
1109 vlc_gc_incref( p_item );
1110 _inputItems.append( p_item );
1113 QList<input_item_t*> PlMimeData::inputItems() const
1118 QStringList PlMimeData::formats () const
1121 fmts << "vlc/qt-input-items";