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 /* Must be entered with lock */
315 void PLModel::activateItem( playlist_item_t *p_item )
317 if( !p_item ) return;
318 playlist_item_t *p_parent = p_item;
321 if( p_parent->i_id == rootItem->id() ) break;
322 p_parent = p_parent->p_parent;
325 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, pl_Locked,
329 /****************** Base model mandatory implementations *****************/
330 QVariant PLModel::data( const QModelIndex &index, const int role ) const
332 if( !index.isValid() ) return QVariant();
333 const PLItem *item = getItem( index );
334 if( role == Qt::DisplayRole )
336 int metadata = columnToMeta( index.column() );
337 if( metadata == COLUMN_END ) return QVariant();
340 if( metadata == COLUMN_NUMBER )
341 returninfo = QString::number( index.row() + 1 );
342 else if( metadata == COLUMN_COVER )
345 artUrl = InputManager::decodeArtURL( item->inputItem() );
346 if( artUrl.isEmpty() )
348 for( int i = 0; i < item->childCount(); i++ )
350 artUrl = InputManager::decodeArtURL( item->child( i )->inputItem() );
351 if( !artUrl.isEmpty() )
355 return QVariant( artUrl );
359 char *psz = psz_column_meta( item->inputItem(), metadata );
360 returninfo = qfu( psz );
363 return QVariant( returninfo );
365 else if( role == Qt::DecorationRole && index.column() == 0 )
367 /* Used to segfault here because i_type wasn't always initialized */
368 return QVariant( PLModel::icons[item->inputItem()->i_type] );
370 else if( role == Qt::FontRole )
373 f.setPointSize( f.pointSize() - 1 + i_zoom );
374 if( isCurrent( index ) )
376 return QVariant( f );
378 else if( role == Qt::BackgroundRole && isCurrent( index ) )
380 return QVariant( QBrush( Qt::gray ) );
382 else if( role == IsCurrentRole ) return QVariant( isCurrent( index ) );
383 else if( role == IsLeafNodeRole )
387 playlist_item_t *plItem =
388 playlist_ItemGetById( p_playlist, item->i_id );
391 isLeaf = plItem->i_children == -1;
396 else if( role == IsCurrentsParentNodeRole )
398 return QVariant( isParent( index, currentIndex() ) );
403 /* Seek from current index toward the top and see if index is one of parent nodes */
404 bool PLModel::isParent( const QModelIndex &index, const QModelIndex ¤t ) const
406 if( !index.isValid() )
409 if( index == current )
412 if( !current.isValid() || !current.parent().isValid() )
415 return isParent( index, current.parent() );
418 bool PLModel::isCurrent( const QModelIndex &index ) const
420 return getItem( index )->inputItem() == THEMIM->currentInputItem();
423 int PLModel::itemId( const QModelIndex &index ) const
425 return getItem( index )->id();
428 QVariant PLModel::headerData( int section, Qt::Orientation orientation,
431 if (orientation != Qt::Horizontal || role != Qt::DisplayRole)
434 int meta_col = columnToMeta( section );
436 if( meta_col == COLUMN_END ) return QVariant();
438 return QVariant( qfu( psz_column_title( meta_col ) ) );
441 QModelIndex PLModel::index( const int row, const int column, const QModelIndex &parent )
444 PLItem *parentItem = parent.isValid() ? getItem( parent ) : rootItem;
446 PLItem *childItem = parentItem->child( row );
448 return createIndex( row, column, childItem );
450 return QModelIndex();
453 QModelIndex PLModel::index( const int i_id, const int c )
455 return index( findById( rootItem, i_id ), c );
458 /* Return the index of a given item */
459 QModelIndex PLModel::index( PLItem *item, int column ) const
461 if( !item ) return QModelIndex();
462 const PLItem *parent = item->parent();
464 return createIndex( parent->children.lastIndexOf( item ),
466 return QModelIndex();
469 QModelIndex PLModel::currentIndex() const
471 input_thread_t *p_input_thread = THEMIM->getInput();
472 if( !p_input_thread ) return QModelIndex();
473 PLItem *item = findByInput( rootItem, input_GetItem( p_input_thread )->i_id );
474 return index( item, 0 );
477 QModelIndex PLModel::parent( const QModelIndex &index ) const
479 if( !index.isValid() ) return QModelIndex();
481 PLItem *childItem = getItem( index );
484 msg_Err( p_playlist, "NULL CHILD" );
485 return QModelIndex();
488 PLItem *parentItem = childItem->parent();
489 if( !parentItem || parentItem == rootItem ) return QModelIndex();
490 if( !parentItem->parent() )
492 msg_Err( p_playlist, "No parent parent, trying row 0 " );
493 msg_Err( p_playlist, "----- PLEASE REPORT THIS ------" );
494 return createIndex( 0, 0, parentItem );
496 return createIndex(parentItem->row(), 0, parentItem);
499 int PLModel::columnCount( const QModelIndex &) const
501 return columnFromMeta( COLUMN_END );
504 int PLModel::rowCount( const QModelIndex &parent ) const
506 const PLItem *parentItem = parent.isValid() ? getItem( parent ) : rootItem;
507 return parentItem->childCount();
510 QStringList PLModel::selectedURIs()
513 for( int i = 0; i < current_selection.count(); i++ )
515 const PLItem *item = getItem( current_selection[i] );
519 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id );
522 char *psz = input_item_GetURI( p_item->p_input );
525 lst.append( qfu(psz) );
535 /************************* Lookups *****************************/
536 PLItem *PLModel::findById( PLItem *root, int i_id ) const
538 return findInner( root, i_id, false );
541 PLItem *PLModel::findByInput( PLItem *root, int i_id ) const
543 PLItem *result = findInner( root, i_id, true );
547 PLItem * PLModel::findInner( PLItem *root, int i_id, bool b_input ) const
549 if( !root ) return NULL;
551 if( !b_input && root->id() == i_id )
554 else if( b_input && root->inputItem()->i_id == i_id )
557 QList<PLItem *>::iterator it = root->children.begin();
558 while ( it != root->children.end() )
560 if( !b_input && (*it)->id() == i_id )
563 else if( b_input && (*it)->inputItem()->i_id == i_id )
566 if( (*it)->childCount() )
568 PLItem *childFound = findInner( (*it), i_id, b_input );
577 bool PLModel::canEdit() const
582 rootItem->inputItem() == p_playlist->p_playing->p_input ||
583 ( p_playlist->p_media_library &&
584 rootItem->inputItem() == p_playlist->p_media_library->p_input )
589 /************************* Updates handling *****************************/
591 /**** Events processing ****/
592 void PLModel::processInputItemUpdate( input_thread_t *p_input )
594 if( !p_input ) return;
595 if( p_input && !( p_input->b_dead || !vlc_object_alive( p_input ) ) )
597 PLItem *item = findByInput( rootItem, input_GetItem( p_input )->i_id );
598 if( item ) emit currentChanged( index( item, 0 ) );
600 processInputItemUpdate( input_GetItem( p_input ) );
603 void PLModel::processInputItemUpdate( input_item_t *p_item )
605 if( !p_item || p_item->i_id <= 0 ) return;
606 PLItem *item = findByInput( rootItem, p_item->i_id );
608 updateTreeItem( item );
611 void PLModel::processItemRemoval( int i_id )
613 if( i_id <= 0 ) return;
617 void PLModel::processItemAppend( int i_item, int i_parent )
619 playlist_item_t *p_item = NULL;
620 PLItem *newItem = NULL;
623 /* Find the Parent */
624 PLItem *nodeParentItem = findById( rootItem, i_parent );
625 if( !nodeParentItem ) return;
627 /* Search for an already matching children */
628 foreach( const PLItem *existing, nodeParentItem->children )
629 if( existing->i_id == i_item ) return;
633 p_item = playlist_ItemGetById( p_playlist, i_item );
634 if( !p_item || p_item->i_flags & PLAYLIST_DBL_FLAG )
639 for( pos = 0; pos < p_item->p_parent->i_children; pos++ )
640 if( p_item->p_parent->pp_children[pos] == p_item ) break;
642 newItem = new PLItem( p_item, nodeParentItem );
645 /* We insert the newItem (children) inside the parent */
646 beginInsertRows( index( nodeParentItem, 0 ), pos, pos );
647 nodeParentItem->insertChild( newItem, pos );
650 if( newItem->inputItem() == THEMIM->currentInputItem() )
651 emit currentChanged( index( newItem, 0 ) );
654 void PLModel::rebuild( playlist_item_t *p_root )
656 /* Invalidate cache */
657 i_cached_id = i_cached_input_id = -1;
659 if( rootItem ) rootItem->removeChildren();
662 if( p_root ) // Can be NULL
665 rootItem = new PLItem( p_root );
668 /* Recreate from root */
669 updateChildren( rootItem );
672 /* And signal the view */
675 if( p_root ) emit rootChanged();
678 void PLModel::takeItem( PLItem *item )
681 PLItem *parent = item->parent();
683 int i_index = parent->children.indexOf( item );
685 beginRemoveRows( index( parent, 0 ), i_index, i_index );
686 parent->takeChildAt( i_index );
690 void PLModel::insertChildren( PLItem *node, QList<PLItem*>& items, int i_pos )
693 int count = items.count();
695 printf( "Here I am\n");
696 beginInsertRows( index( node, 0 ), i_pos, i_pos + count - 1 );
697 for( int i = 0; i < count; i++ )
699 node->children.insert( i_pos + i, items[i] );
700 items[i]->parentItem = node;
705 void PLModel::removeItem( PLItem *item )
710 i_cached_input_id = -1;
712 if( item->parent() ) {
713 int i = item->parent()->children.indexOf( item );
714 beginRemoveRows( index( item->parent(), 0), i, i );
715 item->parent()->children.removeAt(i);
724 rebuild( p_playlist->p_playing );
728 /* This function must be entered WITH the playlist lock */
729 void PLModel::updateChildren( PLItem *root )
731 playlist_item_t *p_node = playlist_ItemGetById( p_playlist, root->id() );
732 updateChildren( p_node, root );
735 /* This function must be entered WITH the playlist lock */
736 void PLModel::updateChildren( playlist_item_t *p_node, PLItem *root )
738 for( int i = 0; i < p_node->i_children ; i++ )
740 if( p_node->pp_children[i]->i_flags & PLAYLIST_DBL_FLAG ) continue;
741 PLItem *newItem = new PLItem( p_node->pp_children[i], root );
742 root->appendChild( newItem );
743 if( p_node->pp_children[i]->i_children != -1 )
744 updateChildren( p_node->pp_children[i], newItem );
748 /* Function doesn't need playlist-lock, as we don't touch playlist_item_t stuff here*/
749 void PLModel::updateTreeItem( PLItem *item )
752 emit dataChanged( index( item, 0 ) , index( item, columnCount( QModelIndex() ) ) );
755 /************************* Actions ******************************/
758 * Deletion, don't delete items childrens if item is going to be
759 * delete allready, so we remove childrens from selection-list.
761 void PLModel::doDelete( QModelIndexList selected )
763 if( !canEdit() ) return;
765 while( !selected.isEmpty() )
767 QModelIndex index = selected[0];
768 selected.removeAt( 0 );
770 if( index.column() != 0 ) continue;
772 PLItem *item = getItem( index );
773 if( item->childCount() )
774 recurseDelete( item->children, &selected );
777 playlist_DeleteFromInput( p_playlist, item->inputItem(), pl_Locked );
784 void PLModel::recurseDelete( QList<PLItem*> children, QModelIndexList *fullList )
786 for( int i = children.count() - 1; i >= 0 ; i-- )
788 PLItem *item = children[i];
789 if( item->childCount() )
790 recurseDelete( item->children, fullList );
791 fullList->removeAll( index( item, 0 ) );
795 /******* Volume III: Sorting and searching ********/
796 void PLModel::sort( const int column, Qt::SortOrder order )
798 sort( rootItem->id(), column, order );
801 void PLModel::sort( const int i_root_id, const int column, Qt::SortOrder order )
803 msg_Dbg( p_intf, "Sorting by column %i, order %i", column, order );
805 int meta = columnToMeta( column );
806 if( meta == COLUMN_END ) return;
808 PLItem *item = findById( rootItem, i_root_id );
810 QModelIndex qIndex = index( item, 0 );
811 int count = item->childCount();
814 beginRemoveRows( qIndex, 0, count - 1 );
815 item->removeChildren();
821 playlist_item_t *p_root = playlist_ItemGetById( p_playlist,
825 playlist_RecursiveNodeSort( p_playlist, p_root,
826 i_column_sorting( meta ),
827 order == Qt::AscendingOrder ?
828 ORDER_NORMAL : ORDER_REVERSE );
832 i_cached_id = i_cached_input_id = -1;
836 beginInsertRows( qIndex, 0, count - 1 );
837 updateChildren( item );
841 /* if we have popup item, try to make sure that you keep that item visible */
842 if( i_popup_item > -1 )
844 PLItem *popupitem = findById( rootItem, i_popup_item );
845 if( popupitem ) emit currentChanged( index( popupitem, 0 ) );
846 /* reset i_popup_item as we don't show it as selected anymore anyway */
849 else if( currentIndex().isValid() ) emit currentChanged( currentIndex() );
852 void PLModel::search( const QString& search_text, const QModelIndex & idx, bool b_recursive )
854 /** \todo Fire the search with a small delay ? */
857 playlist_item_t *p_root = playlist_ItemGetById( p_playlist,
860 playlist_LiveSearchUpdate( p_playlist , p_root, qtu( search_text ),
864 PLItem *searchRoot = getItem( idx );
866 beginRemoveRows( idx, 0, searchRoot->childCount() - 1 );
867 searchRoot->removeChildren();
870 beginInsertRows( idx, 0, searchRoot->childCount() - 1 );
871 updateChildren( searchRoot ); // The PL_LOCK is needed here
882 /*********** Popup *********/
883 bool PLModel::popup( const QModelIndex & index, const QPoint &point, const QModelIndexList &list )
885 int i_id = index.isValid() ? itemId( index ) : rootItem->id();
888 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, i_id );
895 input_item_t *p_input = p_item->p_input;
896 vlc_gc_incref( p_input );
898 i_popup_item = index.isValid() ? p_item->i_id : -1;
899 i_popup_parent = index.isValid() ?
900 ( p_item->p_parent ? p_item->p_parent->i_id : -1 ) :
902 i_popup_column = index.column();
904 bool tree = ( rootItem && rootItem->id() != p_playlist->p_playing->i_id ) ||
905 var_InheritBool( p_intf, "playlist-tree" );
909 current_selection = list;
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 );
930 QIcon addIcon( ":/buttons/playlist/playlist_add" );
932 if( tree ) menu.addAction( addIcon, qtr(I_POP_NEWFOLDER), this, SLOT( popupAddNode() ) );
933 if( rootItem->id() == THEPL->p_playing->i_id )
935 menu.addAction( addIcon, qtr(I_PL_ADDF), THEDP, SLOT( simplePLAppendDialog()) );
936 menu.addAction( addIcon, qtr(I_PL_ADDDIR), THEDP, SLOT( PLAppendDir()) );
937 menu.addAction( addIcon, qtr(I_OP_ADVOP), THEDP, SLOT( PLAppendDialog()) );
939 else if( THEPL->p_media_library &&
940 rootItem->id() == THEPL->p_media_library->i_id )
942 menu.addAction( addIcon, qtr(I_PL_ADDF), THEDP, SLOT( simpleMLAppendDialog()) );
943 menu.addAction( addIcon, qtr(I_PL_ADDDIR), THEDP, SLOT( MLAppendDir() ) );
944 menu.addAction( addIcon, qtr(I_OP_ADVOP), THEDP, SLOT( MLAppendDialog() ) );
947 if( i_popup_item > -1 )
949 if( rootItem->id() != THEPL->p_playing->i_id )
950 menu.addAction( qtr( "Add to playlist"), this, SLOT( popupAddToPlaylist() ) );
951 menu.addAction( QIcon( ":/buttons/playlist/playlist_remove" ),
952 qtr(I_POP_DEL), this, SLOT( popupDel() ) );
956 sortingMenu = new QMenu( qtr( "Sort by" ) );
957 sortingMapper = new QSignalMapper( this );
958 for( int i = 1, j = 1; i < COLUMN_END; i <<= 1, j++ )
960 if( i == COLUMN_NUMBER ) continue;
961 QMenu *m = sortingMenu->addMenu( qfu( psz_column_title( i ) ) );
962 QAction *asc = m->addAction( qtr("Ascending") );
963 QAction *desc = m->addAction( qtr("Descending") );
964 sortingMapper->setMapping( asc, j );
965 sortingMapper->setMapping( desc, -j );
966 CONNECT( asc, triggered(), sortingMapper, map() );
967 CONNECT( desc, triggered(), sortingMapper, map() );
969 CONNECT( sortingMapper, mapped( int ), this, popupSort( int ) );
971 menu.addMenu( sortingMenu );
974 if( !menu.isEmpty() )
976 menu.exec( point ); return true;
981 void PLModel::popupDel()
983 doDelete( current_selection );
986 void PLModel::popupPlay()
990 playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
992 activateItem( p_item );
997 void PLModel::popupAddToPlaylist()
999 playlist_Lock( THEPL );
1001 foreach( QModelIndex currentIndex, current_selection )
1003 playlist_item_t *p_item = playlist_ItemGetById( THEPL, getId( currentIndex ) );
1004 if( !p_item ) continue;
1006 playlist_NodeAddCopy( THEPL, p_item,
1010 playlist_Unlock( THEPL );
1013 void PLModel::popupInfo()
1016 playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
1020 input_item_t* p_input = p_item->p_input;
1021 vlc_gc_incref( p_input );
1023 MediaInfoDialog *mid = new MediaInfoDialog( p_intf, p_input );
1024 vlc_gc_decref( p_input );
1025 mid->setParent( PlaylistDialog::getInstance( p_intf ),
1032 void PLModel::popupStream()
1034 QStringList mrls = selectedURIs();
1035 if( !mrls.isEmpty() )
1036 THEDP->streamingDialog( NULL, mrls[0], false );
1039 void PLModel::popupSave()
1041 QStringList mrls = selectedURIs();
1042 if( !mrls.isEmpty() )
1043 THEDP->streamingDialog( NULL, mrls[0] );
1046 void PLModel::popupExplore()
1049 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, i_popup_item );
1052 input_item_t *p_input = p_item->p_input;
1053 char *psz_meta = input_item_GetURI( p_input );
1057 const char *psz_access;
1058 const char *psz_demux;
1060 input_SplitMRL( &psz_access, &psz_demux, &psz_path, psz_meta );
1062 if( !EMPTY_STR( psz_access ) && (
1063 !strncasecmp( psz_access, "file", 4 ) ||
1064 !strncasecmp( psz_access, "dire", 4 ) ))
1066 #if defined( WIN32 ) || defined( __OS2__ )
1067 /* Qt openURL doesn't know to open files that starts with a / or \ */
1068 if( psz_path[0] == '/' || psz_path[0] == '\\' )
1072 QFileInfo info( qfu( decode_URI( psz_path ) ) );
1073 QDesktopServices::openUrl(
1074 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";