1 /*****************************************************************************
2 * playlist_model.cpp : Manage playlist model
3 ****************************************************************************
4 * Copyright (C) 2006-2011 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>
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 : VLCModel( _p_intf, parent )
70 p_playlist = _p_playlist;
72 i_cached_input_id = -1;
73 i_popup_item = i_popup_parent = -1;
76 rootItem = NULL; /* PLItem rootItem, will be set in rebuild( ) */
78 /* Icons initialization */
79 #define ADD_ICON(type, x) icons[ITEM_TYPE_##type] = QIcon( x )
80 ADD_ICON( UNKNOWN , type_unknown_xpm );
81 ADD_ICON( FILE, ":/type/file" );
82 ADD_ICON( DIRECTORY, ":/type/directory" );
83 ADD_ICON( DISC, ":/type/disc" );
84 ADD_ICON( CDDA, ":/type/cdda" );
85 ADD_ICON( CARD, ":/type/capture-card" );
86 ADD_ICON( NET, ":/type/net" );
87 ADD_ICON( PLAYLIST, ":/type/playlist" );
88 ADD_ICON( NODE, ":/type/node" );
91 i_zoom = getSettings()->value( "Playlist/zoom", 0 ).toInt();
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 ) );
106 getSettings()->setValue( "Playlist/zoom", i_zoom );
111 Qt::DropActions PLModel::supportedDropActions() const
113 return Qt::CopyAction | Qt::MoveAction;
116 Qt::ItemFlags PLModel::flags( const QModelIndex &index ) const
118 Qt::ItemFlags flags = QAbstractItemModel::flags( index );
120 const PLItem *item = index.isValid() ? getItem( index ) : rootItem;
125 playlist_item_t *plItem =
126 playlist_ItemGetById( p_playlist, item->i_id );
128 if ( plItem && ( plItem->i_children > -1 ) )
129 flags |= Qt::ItemIsDropEnabled;
134 flags |= Qt::ItemIsDragEnabled;
139 QStringList PLModel::mimeTypes() const
142 types << "vlc/qt-input-items";
146 bool modelIndexLessThen( const QModelIndex &i1, const QModelIndex &i2 )
148 if( !i1.isValid() || !i2.isValid() ) return false;
149 PLItem *item1 = static_cast<PLItem*>( i1.internalPointer() );
150 PLItem *item2 = static_cast<PLItem*>( i2.internalPointer() );
151 if( item1->parent() == item2->parent() ) return i1.row() < i2.row();
152 else return *item1 < *item2;
155 QMimeData *PLModel::mimeData( const QModelIndexList &indexes ) const
157 PlMimeData *plMimeData = new PlMimeData();
158 QModelIndexList list;
160 foreach( const QModelIndex &index, indexes ) {
161 if( index.isValid() && index.column() == 0 )
165 qSort(list.begin(), list.end(), modelIndexLessThen);
168 foreach( const QModelIndex &index, list ) {
171 PLItem *testee = getItem( index );
172 while( testee->parent() )
174 if( testee->parent() == item ||
175 testee->parent() == item->parent() ) break;
176 testee = testee->parent();
178 if( testee->parent() == item ) continue;
179 item = getItem( index );
182 item = getItem( index );
184 plMimeData->appendItem( item->inputItem() );
191 bool PLModel::dropMimeData( const QMimeData *data, Qt::DropAction action,
192 int row, int, const QModelIndex &parent )
194 bool copy = action == Qt::CopyAction;
195 if( !copy && action != Qt::MoveAction )
198 const PlMimeData *plMimeData = qobject_cast<const PlMimeData*>( data );
202 dropAppendCopy( plMimeData, getItem( parent ), row );
204 dropMove( plMimeData, getItem( parent ), row );
209 void PLModel::dropAppendCopy( const PlMimeData *plMimeData, PLItem *target, int pos )
213 playlist_item_t *p_parent =
214 playlist_ItemGetByInput( p_playlist, target->inputItem() );
215 if( !p_parent ) return;
217 if( pos == -1 ) pos = PLAYLIST_END;
219 QList<input_item_t*> inputItems = plMimeData->inputItems();
221 foreach( input_item_t* p_input, inputItems )
223 playlist_item_t *p_item = playlist_ItemGetByInput( p_playlist, p_input );
224 if( !p_item ) continue;
225 pos = playlist_NodeAddCopy( p_playlist, p_item, p_parent, pos );
231 void PLModel::dropMove( const PlMimeData * plMimeData, PLItem *target, int row )
233 QList<input_item_t*> inputItems = plMimeData->inputItems();
234 QList<PLItem*> model_items;
235 playlist_item_t *pp_items[inputItems.count()];
239 playlist_item_t *p_parent =
240 playlist_ItemGetByInput( p_playlist, target->inputItem() );
242 if( !p_parent || row > p_parent->i_children )
247 int new_pos = row == -1 ? p_parent->i_children : row;
248 int model_pos = new_pos;
251 foreach( input_item_t *p_input, inputItems )
253 playlist_item_t *p_item = playlist_ItemGetByInput( p_playlist, p_input );
254 if( !p_item ) continue;
256 PLItem *item = findByInput( rootItem, p_input->i_id );
257 if( !item ) continue;
259 /* Better not try to move a node into itself.
260 Abort the whole operation in that case,
261 because it is ambiguous. */
262 PLItem *climber = target;
265 if( climber == item )
269 climber = climber->parent();
272 if( item->parent() == target &&
273 target->children.indexOf( item ) < new_pos )
276 model_items.append( item );
277 pp_items[i] = p_item;
281 if( model_items.isEmpty() )
286 playlist_TreeMoveMany( p_playlist, i, pp_items, p_parent, new_pos );
290 foreach( PLItem *item, model_items )
293 insertChildren( target, model_items, model_pos );
296 /* remove item with its id */
297 void PLModel::removeItem( int i_id )
299 PLItem *item = findById( rootItem, i_id );
303 void PLModel::activateItem( const QModelIndex &index )
305 assert( index.isValid() );
306 const PLItem *item = getItem( index );
309 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id );
310 activateItem( p_item );
314 /* Convenient overloaded private version of activateItem
315 * Must be entered with PL 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->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, const int role ) const
333 if( !index.isValid() ) return QVariant();
334 const 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 );
343 else if( metadata == COLUMN_COVER )
346 artUrl = InputManager::decodeArtURL( item->inputItem() );
347 if( artUrl.isEmpty() )
349 for( int i = 0; i < item->childCount(); i++ )
351 artUrl = InputManager::decodeArtURL( item->child( i )->inputItem() );
352 if( !artUrl.isEmpty() )
356 return QVariant( artUrl );
360 char *psz = psz_column_meta( item->inputItem(), metadata );
361 returninfo = qfu( psz );
364 return QVariant( returninfo );
366 else if( role == Qt::DecorationRole && index.column() == 0 )
368 /* Used to segfault here because i_type wasn't always initialized */
369 return QVariant( PLModel::icons[item->inputItem()->i_type] );
371 else if( role == Qt::FontRole )
374 f.setPointSize( __MAX( f.pointSize() - 1 + i_zoom, 4 ) );
375 if( isCurrent( index ) )
377 return QVariant( f );
379 else if( role == Qt::BackgroundRole && isCurrent( index ) )
381 return QVariant( QBrush( Qt::gray ) );
383 else if( role == IsCurrentRole ) return QVariant( isCurrent( index ) );
384 else if( role == IsLeafNodeRole )
388 playlist_item_t *plItem =
389 playlist_ItemGetById( p_playlist, item->i_id );
392 isLeaf = plItem->i_children == -1;
397 else if( role == IsCurrentsParentNodeRole )
399 return QVariant( isParent( index, currentIndex() ) );
404 /* Seek from current index toward the top and see if index is one of parent nodes */
405 bool PLModel::isParent( const QModelIndex &index, const QModelIndex ¤t ) const
407 if( !index.isValid() )
410 if( index == current )
413 if( !current.isValid() || !current.parent().isValid() )
416 return isParent( index, current.parent() );
419 bool PLModel::isCurrent( const QModelIndex &index ) const
421 return getItem( index )->inputItem() == THEMIM->currentInputItem();
424 int PLModel::itemId( const QModelIndex &index ) const
426 return getItem( index )->id();
429 QVariant PLModel::headerData( int section, Qt::Orientation orientation,
432 if (orientation != Qt::Horizontal || role != Qt::DisplayRole)
435 int meta_col = columnToMeta( section );
437 if( meta_col == COLUMN_END ) return QVariant();
439 return QVariant( qfu( psz_column_title( meta_col ) ) );
442 QModelIndex PLModel::index( const int row, const int column, const QModelIndex &parent )
445 PLItem *parentItem = parent.isValid() ? getItem( parent ) : rootItem;
447 PLItem *childItem = parentItem->child( row );
449 return createIndex( row, column, childItem );
451 return QModelIndex();
454 QModelIndex PLModel::index( const int i_id, const int c )
456 return index( findById( rootItem, i_id ), c );
459 /* Return the index of a given item */
460 QModelIndex PLModel::index( PLItem *item, int column ) const
462 if( !item ) return QModelIndex();
463 const PLItem *parent = item->parent();
465 return createIndex( parent->children.lastIndexOf( item ),
467 return QModelIndex();
470 QModelIndex PLModel::currentIndex() const
472 input_thread_t *p_input_thread = THEMIM->getInput();
473 if( !p_input_thread ) return QModelIndex();
474 PLItem *item = findByInput( rootItem, input_GetItem( p_input_thread )->i_id );
475 return index( item, 0 );
478 QModelIndex PLModel::parent( const QModelIndex &index ) const
480 if( !index.isValid() ) return QModelIndex();
482 PLItem *childItem = getItem( index );
485 msg_Err( p_playlist, "NULL CHILD" );
486 return QModelIndex();
489 PLItem *parentItem = childItem->parent();
490 if( !parentItem || parentItem == rootItem ) return QModelIndex();
491 if( !parentItem->parent() )
493 msg_Err( p_playlist, "No parent parent, trying row 0 " );
494 msg_Err( p_playlist, "----- PLEASE REPORT THIS ------" );
495 return createIndex( 0, 0, parentItem );
497 return createIndex(parentItem->row(), 0, parentItem);
500 int PLModel::columnCount( const QModelIndex &) const
502 return columnFromMeta( COLUMN_END );
505 int PLModel::rowCount( const QModelIndex &parent ) const
507 const PLItem *parentItem = parent.isValid() ? getItem( parent ) : rootItem;
508 return parentItem->childCount();
511 QStringList PLModel::selectedURIs()
514 for( int i = 0; i < current_selection.count(); i++ )
516 const PLItem *item = getItem( current_selection[i] );
520 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id );
523 char *psz = input_item_GetURI( p_item->p_input );
526 lst.append( qfu(psz) );
536 /************************* Lookups *****************************/
537 PLItem *PLModel::findById( PLItem *root, int i_id ) const
539 return findInner( root, i_id, false );
542 PLItem *PLModel::findByInput( PLItem *root, int i_id ) const
544 PLItem *result = findInner( root, i_id, true );
548 PLItem * PLModel::findInner( PLItem *root, int i_id, bool b_input ) const
550 if( !root ) return NULL;
552 if( !b_input && root->id() == i_id )
555 else if( b_input && root->inputItem()->i_id == i_id )
558 QList<PLItem *>::iterator it = root->children.begin();
559 while ( it != root->children.end() )
561 if( !b_input && (*it)->id() == i_id )
564 else if( b_input && (*it)->inputItem()->i_id == i_id )
567 if( (*it)->childCount() )
569 PLItem *childFound = findInner( (*it), i_id, b_input );
578 bool PLModel::canEdit() const
583 rootItem->inputItem() == p_playlist->p_playing->p_input ||
584 ( p_playlist->p_media_library &&
585 rootItem->inputItem() == p_playlist->p_media_library->p_input )
590 /************************* Updates handling *****************************/
592 /**** Events processing ****/
593 void PLModel::processInputItemUpdate( input_thread_t *p_input )
595 if( !p_input ) return;
596 if( p_input && !( p_input->b_dead || !vlc_object_alive( p_input ) ) )
598 PLItem *item = findByInput( rootItem, input_GetItem( p_input )->i_id );
599 if( item ) emit currentChanged( index( item, 0 ) );
601 processInputItemUpdate( input_GetItem( p_input ) );
604 void PLModel::processInputItemUpdate( input_item_t *p_item )
606 if( !p_item || p_item->i_id <= 0 ) return;
607 PLItem *item = findByInput( rootItem, p_item->i_id );
609 updateTreeItem( item );
612 void PLModel::processItemRemoval( int i_id )
614 if( i_id <= 0 ) return;
618 void PLModel::processItemAppend( int i_item, int i_parent )
620 playlist_item_t *p_item = NULL;
621 PLItem *newItem = NULL;
624 /* Find the Parent */
625 PLItem *nodeParentItem = findById( rootItem, i_parent );
626 if( !nodeParentItem ) return;
628 /* Search for an already matching children */
629 foreach( const PLItem *existing, nodeParentItem->children )
630 if( existing->i_id == i_item ) return;
634 p_item = playlist_ItemGetById( p_playlist, i_item );
635 if( !p_item || p_item->i_flags & PLAYLIST_DBL_FLAG )
640 for( pos = 0; pos < p_item->p_parent->i_children; pos++ )
641 if( p_item->p_parent->pp_children[pos] == p_item ) break;
643 newItem = new PLItem( p_item, nodeParentItem );
646 /* We insert the newItem (children) inside the parent */
647 beginInsertRows( index( nodeParentItem, 0 ), pos, pos );
648 nodeParentItem->insertChild( newItem, pos );
651 if( newItem->inputItem() == THEMIM->currentInputItem() )
652 emit currentChanged( index( newItem, 0 ) );
655 void PLModel::rebuild( playlist_item_t *p_root )
657 /* Invalidate cache */
658 i_cached_id = i_cached_input_id = -1;
660 if( rootItem ) rootItem->removeChildren();
663 if( p_root ) // Can be NULL
666 rootItem = new PLItem( p_root );
669 /* Recreate from root */
670 updateChildren( rootItem );
673 /* And signal the view */
676 if( p_root ) emit rootChanged();
679 void PLModel::takeItem( PLItem *item )
682 PLItem *parent = item->parent();
684 int i_index = parent->children.indexOf( item );
686 beginRemoveRows( index( parent, 0 ), i_index, i_index );
687 parent->takeChildAt( i_index );
691 void PLModel::insertChildren( PLItem *node, QList<PLItem*>& items, int i_pos )
694 int count = items.count();
696 printf( "Here I am\n");
697 beginInsertRows( index( node, 0 ), i_pos, i_pos + count - 1 );
698 for( int i = 0; i < count; i++ )
700 node->children.insert( i_pos + i, items[i] );
701 items[i]->parentItem = node;
706 void PLModel::removeItem( PLItem *item )
711 i_cached_input_id = -1;
713 if( item->parent() ) {
714 int i = item->parent()->children.indexOf( item );
715 beginRemoveRows( index( item->parent(), 0), i, i );
716 item->parent()->children.removeAt(i);
725 rebuild( p_playlist->p_playing );
729 /* This function must be entered WITH the playlist lock */
730 void PLModel::updateChildren( PLItem *root )
732 playlist_item_t *p_node = playlist_ItemGetById( p_playlist, root->id() );
733 updateChildren( p_node, root );
736 /* This function must be entered WITH the playlist lock */
737 void PLModel::updateChildren( playlist_item_t *p_node, PLItem *root )
739 for( int i = 0; i < p_node->i_children ; i++ )
741 if( p_node->pp_children[i]->i_flags & PLAYLIST_DBL_FLAG ) continue;
742 PLItem *newItem = new PLItem( p_node->pp_children[i], root );
743 root->appendChild( newItem );
744 if( p_node->pp_children[i]->i_children != -1 )
745 updateChildren( p_node->pp_children[i], newItem );
749 /* Function doesn't need playlist-lock, as we don't touch playlist_item_t stuff here*/
750 void PLModel::updateTreeItem( PLItem *item )
753 emit dataChanged( index( item, 0 ) , index( item, columnCount( QModelIndex() ) ) );
756 /************************* Actions ******************************/
759 * Deletion, don't delete items childrens if item is going to be
760 * delete allready, so we remove childrens from selection-list.
762 void PLModel::doDelete( QModelIndexList selected )
764 if( !canEdit() ) return;
766 while( !selected.isEmpty() )
768 QModelIndex index = selected[0];
769 selected.removeAt( 0 );
771 if( index.column() != 0 ) continue;
773 PLItem *item = getItem( index );
774 if( item->childCount() )
775 recurseDelete( item->children, &selected );
778 playlist_DeleteFromInput( p_playlist, item->inputItem(), pl_Locked );
785 void PLModel::recurseDelete( QList<PLItem*> children, QModelIndexList *fullList )
787 for( int i = children.count() - 1; i >= 0 ; i-- )
789 PLItem *item = children[i];
790 if( item->childCount() )
791 recurseDelete( item->children, fullList );
792 fullList->removeAll( index( item, 0 ) );
796 /******* Volume III: Sorting and searching ********/
797 void PLModel::sort( const int column, Qt::SortOrder order )
799 sort( rootItem->id(), column, order );
802 void PLModel::sort( const int i_root_id, const int column, Qt::SortOrder order )
804 msg_Dbg( p_intf, "Sorting by column %i, order %i", column, order );
806 int meta = columnToMeta( column );
807 if( meta == COLUMN_END ) return;
809 PLItem *item = findById( rootItem, i_root_id );
811 QModelIndex qIndex = index( item, 0 );
812 int count = item->childCount();
815 beginRemoveRows( qIndex, 0, count - 1 );
816 item->removeChildren();
822 playlist_item_t *p_root = playlist_ItemGetById( p_playlist,
826 playlist_RecursiveNodeSort( p_playlist, p_root,
827 i_column_sorting( meta ),
828 order == Qt::AscendingOrder ?
829 ORDER_NORMAL : ORDER_REVERSE );
833 i_cached_id = i_cached_input_id = -1;
837 beginInsertRows( qIndex, 0, count - 1 );
838 updateChildren( item );
842 /* if we have popup item, try to make sure that you keep that item visible */
843 if( i_popup_item > -1 )
845 PLItem *popupitem = findById( rootItem, i_popup_item );
846 if( popupitem ) emit currentChanged( index( popupitem, 0 ) );
847 /* reset i_popup_item as we don't show it as selected anymore anyway */
850 else if( currentIndex().isValid() ) emit currentChanged( currentIndex() );
853 void PLModel::search( const QString& search_text, const QModelIndex & idx, bool b_recursive )
855 /** \todo Fire the search with a small delay ? */
858 playlist_item_t *p_root = playlist_ItemGetById( p_playlist,
861 playlist_LiveSearchUpdate( p_playlist , p_root, qtu( search_text ),
865 PLItem *searchRoot = getItem( idx );
867 beginRemoveRows( idx, 0, searchRoot->childCount() - 1 );
868 searchRoot->removeChildren();
871 beginInsertRows( idx, 0, searchRoot->childCount() - 1 );
872 updateChildren( searchRoot ); // The PL_LOCK is needed here
883 /*********** Popup *********/
884 bool PLModel::popup( const QModelIndex & index, const QPoint &point, const QModelIndexList &list )
886 int i_id = index.isValid() ? itemId( index ) : rootItem->id();
889 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, i_id );
896 i_popup_item = index.isValid() ? p_item->i_id : -1;
897 i_popup_parent = index.isValid() ?
898 ( p_item->p_parent ? p_item->p_parent->i_id : -1 ) :
901 bool tree = ( rootItem && rootItem->id() != p_playlist->p_playing->i_id ) ||
902 var_InheritBool( p_intf, "playlist-tree" );
904 input_item_t *p_input = p_item->p_input;
905 vlc_gc_incref( p_input );
911 /* Play/Stream/Info static actions */
912 if( i_popup_item > -1 )
914 menu.addAction( QIcon( ":/menu/play" ), qtr(I_POP_PLAY), this, SLOT( popupPlay() ) );
915 menu.addAction( QIcon( ":/menu/stream" ),
916 qtr(I_POP_STREAM), this, SLOT( popupStream() ) );
917 menu.addAction( qtr(I_POP_SAVE), this, SLOT( popupSave() ) );
918 menu.addAction( QIcon( ":/menu/info" ), qtr(I_POP_INFO), this, SLOT( popupInfo() ) );
919 if( p_input->psz_uri && !strncasecmp( p_input->psz_uri, "file://", 7 ) )
921 menu.addAction( QIcon( ":/type/folder-grey" ),
922 qtr( I_POP_EXPLORE ), this, SLOT( popupExplore() ) );
926 vlc_gc_decref( p_input );
928 /* In PL or ML, allow to add a file/folder */
931 QIcon addIcon( ":/buttons/playlist/playlist_add" );
933 if( tree ) menu.addAction( addIcon, qtr(I_POP_NEWFOLDER), this, SLOT( popupAddNode() ) );
934 if( rootItem->id() == THEPL->p_playing->i_id )
936 menu.addAction( addIcon, qtr(I_PL_ADDF), THEDP, SLOT( simplePLAppendDialog()) );
937 menu.addAction( addIcon, qtr(I_PL_ADDDIR), THEDP, SLOT( PLAppendDir()) );
938 menu.addAction( addIcon, qtr(I_OP_ADVOP), THEDP, SLOT( PLAppendDialog()) );
940 else if( THEPL->p_media_library &&
941 rootItem->id() == THEPL->p_media_library->i_id )
943 menu.addAction( addIcon, qtr(I_PL_ADDF), THEDP, SLOT( simpleMLAppendDialog()) );
944 menu.addAction( addIcon, qtr(I_PL_ADDDIR), THEDP, SLOT( MLAppendDir() ) );
945 menu.addAction( addIcon, qtr(I_OP_ADVOP), THEDP, SLOT( MLAppendDialog() ) );
950 if( i_popup_item > -1 )
952 if( rootItem->id() != THEPL->p_playing->i_id )
953 menu.addAction( qtr( "Add to playlist"), this, SLOT( popupAddToPlaylist() ) );
954 menu.addAction( QIcon( ":/buttons/playlist/playlist_remove" ),
955 qtr(I_POP_DEL), this, SLOT( popupDel() ) );
959 /* Playlist sorting */
962 sortingMenu = new QMenu( qtr( "Sort by" ) );
963 sortingMapper = new QSignalMapper( this );
964 /* Choose what columns to show in sorting menu, not sure if this should be configurable*/
965 QList<int> sortingColumns;
966 sortingColumns << COLUMN_TITLE << COLUMN_ARTIST << COLUMN_ALBUM << COLUMN_TRACK_NUMBER << COLUMN_URI;
967 foreach( int Column, sortingColumns )
969 QAction *asc = sortingMenu->addAction( qfu( psz_column_title( Column ) ) + " " + qtr("Ascending") );
970 QAction *desc = sortingMenu->addAction( qfu( psz_column_title( Column ) ) + " " + qtr("Descending") );
971 sortingMapper->setMapping( asc, columnFromMeta(Column) + 1 );
972 sortingMapper->setMapping( desc, -1 * (columnFromMeta(Column)+1) );
973 CONNECT( asc, triggered(), sortingMapper, map() );
974 CONNECT( desc, triggered(), sortingMapper, map() );
976 CONNECT( sortingMapper, mapped( int ), this, popupSort( int ) );
978 menu.addMenu( sortingMenu );
980 /* Store the current selected item for popup*() methods */
981 current_selection = list;
983 /* Display and forward the result */
984 if( !menu.isEmpty() )
986 menu.exec( point ); return true;
991 void PLModel::popupDel()
993 doDelete( current_selection );
996 void PLModel::popupPlay()
1000 playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
1002 activateItem( p_item );
1007 void PLModel::popupAddToPlaylist()
1009 playlist_Lock( THEPL );
1011 foreach( QModelIndex currentIndex, current_selection )
1013 playlist_item_t *p_item = playlist_ItemGetById( THEPL, itemId( currentIndex ) );
1014 if( !p_item ) continue;
1016 playlist_NodeAddCopy( THEPL, p_item,
1020 playlist_Unlock( THEPL );
1023 void PLModel::popupInfo()
1026 playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
1030 input_item_t* p_input = p_item->p_input;
1031 vlc_gc_incref( p_input );
1033 MediaInfoDialog *mid = new MediaInfoDialog( p_intf, p_input );
1034 vlc_gc_decref( p_input );
1035 mid->setParent( PlaylistDialog::getInstance( p_intf ),
1042 void PLModel::popupStream()
1044 QStringList mrls = selectedURIs();
1045 if( !mrls.isEmpty() )
1046 THEDP->streamingDialog( NULL, mrls[0], false );
1049 void PLModel::popupSave()
1051 QStringList mrls = selectedURIs();
1052 if( !mrls.isEmpty() )
1053 THEDP->streamingDialog( NULL, mrls[0] );
1056 void PLModel::popupExplore()
1058 char *uri = NULL, *path = NULL;
1061 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, i_popup_item );
1064 input_item_t *p_input = p_item->p_input;
1065 uri = input_item_GetURI( p_input );
1071 path = make_path( uri );
1077 QFileInfo info( qfu( path ) );
1080 QDesktopServices::openUrl( QUrl::fromLocalFile( info.absolutePath() ) );
1083 void PLModel::popupAddNode()
1086 QString name = QInputDialog::getText( PlaylistDialog::getInstance( p_intf ),
1087 qtr( I_NEW_DIR ), qtr( I_NEW_DIR_NAME ),
1088 QLineEdit::Normal, QString(), &ok);
1089 if( !ok || name.isEmpty() ) return;
1092 playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
1095 playlist_NodeCreate( p_playlist, qtu( name ), p_item, PLAYLIST_END, 0, NULL );
1099 void PLModel::popupSort( int column )
1101 sort( i_popup_parent,
1102 column > 0 ? column - 1 : -column - 1,
1103 column > 0 ? Qt::AscendingOrder : Qt::DescendingOrder );
1106 /******************* Drag and Drop helper class ******************/
1107 PlMimeData::~PlMimeData()
1109 foreach( input_item_t *p_item, _inputItems )
1110 vlc_gc_decref( p_item );
1113 void PlMimeData::appendItem( input_item_t *p_item )
1115 vlc_gc_incref( p_item );
1116 _inputItems.append( p_item );
1119 QList<input_item_t*> PlMimeData::inputItems() const
1124 QStringList PlMimeData::formats () const
1127 fmts << "vlc/qt-input-items";