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 )
385 return QVariant( isCurrent( index ) );
387 else if( role == IsLeafNodeRole )
391 playlist_item_t *plItem =
392 playlist_ItemGetById( p_playlist, item->i_id );
395 isLeaf = plItem->i_children == -1;
400 else if( role == IsCurrentsParentNodeRole )
402 return QVariant( isParent( index, currentIndex() ) );
407 /* Seek from current index toward the top and see if index is one of parent nodes */
408 bool PLModel::isParent( const QModelIndex &index, const QModelIndex ¤t ) const
410 if( !index.isValid() )
413 if( index == current )
416 if( !current.isValid() || !current.parent().isValid() )
419 return isParent( index, current.parent() );
422 bool PLModel::isCurrent( const QModelIndex &index ) const
424 return getItem( index )->inputItem() == THEMIM->currentInputItem();
427 int PLModel::itemId( const QModelIndex &index ) const
429 return getItem( index )->id();
432 QVariant PLModel::headerData( int section, Qt::Orientation orientation,
435 if (orientation != Qt::Horizontal || role != Qt::DisplayRole)
438 int meta_col = columnToMeta( section );
440 if( meta_col == COLUMN_END ) return QVariant();
442 return QVariant( qfu( psz_column_title( meta_col ) ) );
445 QModelIndex PLModel::index( const int row, const int column, const QModelIndex &parent )
448 PLItem *parentItem = parent.isValid() ? getItem( parent ) : rootItem;
450 PLItem *childItem = parentItem->child( row );
452 return createIndex( row, column, childItem );
454 return QModelIndex();
457 QModelIndex PLModel::index( const int i_id, const int c )
459 return index( findById( rootItem, i_id ), c );
462 /* Return the index of a given item */
463 QModelIndex PLModel::index( PLItem *item, int column ) const
465 if( !item ) return QModelIndex();
466 const PLItem *parent = item->parent();
468 return createIndex( parent->children.lastIndexOf( item ),
470 return QModelIndex();
473 QModelIndex PLModel::currentIndex() const
475 input_thread_t *p_input_thread = THEMIM->getInput();
476 if( !p_input_thread ) return QModelIndex();
477 PLItem *item = findByInput( rootItem, input_GetItem( p_input_thread )->i_id );
478 return index( item, 0 );
481 QModelIndex PLModel::parent( const QModelIndex &index ) const
483 if( !index.isValid() ) return QModelIndex();
485 PLItem *childItem = getItem( index );
488 msg_Err( p_playlist, "NULL CHILD" );
489 return QModelIndex();
492 PLItem *parentItem = childItem->parent();
493 if( !parentItem || parentItem == rootItem ) return QModelIndex();
494 if( !parentItem->parent() )
496 msg_Err( p_playlist, "No parent parent, trying row 0 " );
497 msg_Err( p_playlist, "----- PLEASE REPORT THIS ------" );
498 return createIndex( 0, 0, parentItem );
500 return createIndex(parentItem->row(), 0, parentItem);
503 int PLModel::columnCount( const QModelIndex &) const
505 return columnFromMeta( COLUMN_END );
508 int PLModel::rowCount( const QModelIndex &parent ) const
510 const PLItem *parentItem = parent.isValid() ? getItem( parent ) : rootItem;
511 return parentItem->childCount();
514 QStringList PLModel::selectedURIs()
517 for( int i = 0; i < current_selection.count(); i++ )
519 const PLItem *item = getItem( current_selection[i] );
523 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id );
526 char *psz = input_item_GetURI( p_item->p_input );
529 lst.append( qfu(psz) );
539 /************************* Lookups *****************************/
540 PLItem *PLModel::findById( PLItem *root, int i_id ) const
542 return findInner( root, i_id, false );
545 PLItem *PLModel::findByInput( PLItem *root, int i_id ) const
547 PLItem *result = findInner( root, i_id, true );
551 PLItem * PLModel::findInner( PLItem *root, int i_id, bool b_input ) const
553 if( !root ) return NULL;
555 if( !b_input && root->id() == i_id )
558 else if( b_input && root->inputItem()->i_id == i_id )
561 QList<PLItem *>::iterator it = root->children.begin();
562 while ( it != root->children.end() )
564 if( !b_input && (*it)->id() == i_id )
567 else if( b_input && (*it)->inputItem()->i_id == i_id )
570 if( (*it)->childCount() )
572 PLItem *childFound = findInner( (*it), i_id, b_input );
581 bool PLModel::canEdit() const
586 rootItem->inputItem() == p_playlist->p_playing->p_input ||
587 ( p_playlist->p_media_library &&
588 rootItem->inputItem() == p_playlist->p_media_library->p_input )
593 /************************* Updates handling *****************************/
595 /**** Events processing ****/
596 void PLModel::processInputItemUpdate( input_thread_t *p_input )
598 if( !p_input ) return;
599 if( p_input && !( p_input->b_dead || !vlc_object_alive( p_input ) ) )
601 PLItem *item = findByInput( rootItem, input_GetItem( p_input )->i_id );
602 if( item ) emit currentChanged( index( item, 0 ) );
604 processInputItemUpdate( input_GetItem( p_input ) );
607 void PLModel::processInputItemUpdate( input_item_t *p_item )
609 if( !p_item || p_item->i_id <= 0 ) return;
610 PLItem *item = findByInput( rootItem, p_item->i_id );
612 updateTreeItem( item );
615 void PLModel::processItemRemoval( int i_id )
617 if( i_id <= 0 ) return;
621 void PLModel::processItemAppend( int i_item, int i_parent )
623 playlist_item_t *p_item = NULL;
624 PLItem *newItem = NULL;
627 /* Find the Parent */
628 PLItem *nodeParentItem = findById( rootItem, i_parent );
629 if( !nodeParentItem ) return;
631 /* Search for an already matching children */
632 foreach( const PLItem *existing, nodeParentItem->children )
633 if( existing->i_id == i_item ) return;
637 p_item = playlist_ItemGetById( p_playlist, i_item );
638 if( !p_item || p_item->i_flags & PLAYLIST_DBL_FLAG )
643 for( pos = 0; pos < p_item->p_parent->i_children; pos++ )
644 if( p_item->p_parent->pp_children[pos] == p_item ) break;
646 newItem = new PLItem( p_item, nodeParentItem );
649 /* We insert the newItem (children) inside the parent */
650 beginInsertRows( index( nodeParentItem, 0 ), pos, pos );
651 nodeParentItem->insertChild( newItem, pos );
654 if( newItem->inputItem() == THEMIM->currentInputItem() )
655 emit currentChanged( index( newItem, 0 ) );
658 void PLModel::rebuild( playlist_item_t *p_root )
660 /* Invalidate cache */
661 i_cached_id = i_cached_input_id = -1;
663 if( rootItem ) rootItem->removeChildren();
666 if( p_root ) // Can be NULL
669 rootItem = new PLItem( p_root );
672 /* Recreate from root */
673 updateChildren( rootItem );
676 /* And signal the view */
679 if( p_root ) emit rootChanged();
682 void PLModel::takeItem( PLItem *item )
685 PLItem *parent = item->parent();
687 int i_index = parent->children.indexOf( item );
689 beginRemoveRows( index( parent, 0 ), i_index, i_index );
690 parent->takeChildAt( i_index );
694 void PLModel::insertChildren( PLItem *node, QList<PLItem*>& items, int i_pos )
697 int count = items.count();
699 printf( "Here I am\n");
700 beginInsertRows( index( node, 0 ), i_pos, i_pos + count - 1 );
701 for( int i = 0; i < count; i++ )
703 node->children.insert( i_pos + i, items[i] );
704 items[i]->parentItem = node;
709 void PLModel::removeItem( PLItem *item )
714 i_cached_input_id = -1;
716 if( item->parent() ) {
717 int i = item->parent()->children.indexOf( item );
718 beginRemoveRows( index( item->parent(), 0), i, i );
719 item->parent()->children.removeAt(i);
728 rebuild( p_playlist->p_playing );
732 /* This function must be entered WITH the playlist lock */
733 void PLModel::updateChildren( PLItem *root )
735 playlist_item_t *p_node = playlist_ItemGetById( p_playlist, root->id() );
736 updateChildren( p_node, root );
739 /* This function must be entered WITH the playlist lock */
740 void PLModel::updateChildren( playlist_item_t *p_node, PLItem *root )
742 for( int i = 0; i < p_node->i_children ; i++ )
744 if( p_node->pp_children[i]->i_flags & PLAYLIST_DBL_FLAG ) continue;
745 PLItem *newItem = new PLItem( p_node->pp_children[i], root );
746 root->appendChild( newItem );
747 if( p_node->pp_children[i]->i_children != -1 )
748 updateChildren( p_node->pp_children[i], newItem );
752 /* Function doesn't need playlist-lock, as we don't touch playlist_item_t stuff here*/
753 void PLModel::updateTreeItem( PLItem *item )
756 emit dataChanged( index( item, 0 ) , index( item, columnCount( QModelIndex() ) ) );
759 /************************* Actions ******************************/
762 * Deletion, don't delete items childrens if item is going to be
763 * delete allready, so we remove childrens from selection-list.
765 void PLModel::doDelete( QModelIndexList selected )
767 if( !canEdit() ) return;
769 while( !selected.isEmpty() )
771 QModelIndex index = selected[0];
772 selected.removeAt( 0 );
774 if( index.column() != 0 ) continue;
776 PLItem *item = getItem( index );
777 if( item->childCount() )
778 recurseDelete( item->children, &selected );
781 playlist_DeleteFromInput( p_playlist, item->inputItem(), pl_Locked );
788 void PLModel::recurseDelete( QList<PLItem*> children, QModelIndexList *fullList )
790 for( int i = children.count() - 1; i >= 0 ; i-- )
792 PLItem *item = children[i];
793 if( item->childCount() )
794 recurseDelete( item->children, fullList );
795 fullList->removeAll( index( item, 0 ) );
799 /******* Volume III: Sorting and searching ********/
800 void PLModel::sort( const int column, Qt::SortOrder order )
802 sort( rootItem->id(), column, order );
805 void PLModel::sort( const int i_root_id, const int column, Qt::SortOrder order )
807 msg_Dbg( p_intf, "Sorting by column %i, order %i", column, order );
809 int meta = columnToMeta( column );
810 if( meta == COLUMN_END ) return;
812 PLItem *item = findById( rootItem, i_root_id );
814 QModelIndex qIndex = index( item, 0 );
815 int count = item->childCount();
818 beginRemoveRows( qIndex, 0, count - 1 );
819 item->removeChildren();
825 playlist_item_t *p_root = playlist_ItemGetById( p_playlist,
829 playlist_RecursiveNodeSort( p_playlist, p_root,
830 i_column_sorting( meta ),
831 order == Qt::AscendingOrder ?
832 ORDER_NORMAL : ORDER_REVERSE );
836 i_cached_id = i_cached_input_id = -1;
840 beginInsertRows( qIndex, 0, count - 1 );
841 updateChildren( item );
845 /* if we have popup item, try to make sure that you keep that item visible */
846 if( i_popup_item > -1 )
848 PLItem *popupitem = findById( rootItem, i_popup_item );
849 if( popupitem ) emit currentChanged( index( popupitem, 0 ) );
850 /* reset i_popup_item as we don't show it as selected anymore anyway */
853 else if( currentIndex().isValid() ) emit currentChanged( currentIndex() );
856 void PLModel::search( const QString& search_text, const QModelIndex & idx, bool b_recursive )
858 /** \todo Fire the search with a small delay ? */
861 playlist_item_t *p_root = playlist_ItemGetById( p_playlist,
864 playlist_LiveSearchUpdate( p_playlist , p_root, qtu( search_text ),
868 PLItem *searchRoot = getItem( idx );
870 beginRemoveRows( idx, 0, searchRoot->childCount() - 1 );
871 searchRoot->removeChildren();
874 beginInsertRows( idx, 0, searchRoot->childCount() - 1 );
875 updateChildren( searchRoot ); // The PL_LOCK is needed here
886 /*********** Popup *********/
887 bool PLModel::popup( const QModelIndex & index, const QPoint &point, const QModelIndexList &list )
889 int i_id = index.isValid() ? itemId( index ) : rootItem->id();
892 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, i_id );
899 i_popup_item = index.isValid() ? p_item->i_id : -1;
900 i_popup_parent = index.isValid() ?
901 ( p_item->p_parent ? p_item->p_parent->i_id : -1 ) :
904 bool tree = ( rootItem && rootItem->id() != p_playlist->p_playing->i_id ) ||
905 var_InheritBool( p_intf, "playlist-tree" );
907 input_item_t *p_input = p_item->p_input;
908 vlc_gc_incref( p_input );
914 /* Play/Stream/Info static actions */
915 if( i_popup_item > -1 )
917 menu.addAction( QIcon( ":/menu/play" ), qtr(I_POP_PLAY), this, SLOT( popupPlay() ) );
918 menu.addAction( QIcon( ":/menu/stream" ),
919 qtr(I_POP_STREAM), this, SLOT( popupStream() ) );
920 menu.addAction( qtr(I_POP_SAVE), this, SLOT( popupSave() ) );
921 menu.addAction( QIcon( ":/menu/info" ), qtr(I_POP_INFO), this, SLOT( popupInfo() ) );
922 if( p_input->psz_uri && !strncasecmp( p_input->psz_uri, "file://", 7 ) )
924 menu.addAction( QIcon( ":/type/folder-grey" ),
925 qtr( I_POP_EXPLORE ), this, SLOT( popupExplore() ) );
929 vlc_gc_decref( p_input );
931 /* In PL or ML, allow to add a file/folder */
934 QIcon addIcon( ":/buttons/playlist/playlist_add" );
936 if( tree ) menu.addAction( addIcon, qtr(I_POP_NEWFOLDER), this, SLOT( popupAddNode() ) );
937 if( rootItem->id() == THEPL->p_playing->i_id )
939 menu.addAction( addIcon, qtr(I_PL_ADDF), THEDP, SLOT( simplePLAppendDialog()) );
940 menu.addAction( addIcon, qtr(I_PL_ADDDIR), THEDP, SLOT( PLAppendDir()) );
941 menu.addAction( addIcon, qtr(I_OP_ADVOP), THEDP, SLOT( PLAppendDialog()) );
943 else if( THEPL->p_media_library &&
944 rootItem->id() == THEPL->p_media_library->i_id )
946 menu.addAction( addIcon, qtr(I_PL_ADDF), THEDP, SLOT( simpleMLAppendDialog()) );
947 menu.addAction( addIcon, qtr(I_PL_ADDDIR), THEDP, SLOT( MLAppendDir() ) );
948 menu.addAction( addIcon, qtr(I_OP_ADVOP), THEDP, SLOT( MLAppendDialog() ) );
953 if( i_popup_item > -1 )
955 if( rootItem->id() != THEPL->p_playing->i_id )
956 menu.addAction( qtr( "Add to playlist"), this, SLOT( popupAddToPlaylist() ) );
957 menu.addAction( QIcon( ":/buttons/playlist/playlist_remove" ),
958 qtr(I_POP_DEL), this, SLOT( popupDel() ) );
962 /* Playlist sorting */
965 sortingMenu = new QMenu( qtr( "Sort by" ) );
966 sortingMapper = new QSignalMapper( this );
967 /* Choose what columns to show in sorting menu, not sure if this should be configurable*/
968 QList<int> sortingColumns;
969 sortingColumns << COLUMN_TITLE << COLUMN_ARTIST << COLUMN_ALBUM << COLUMN_TRACK_NUMBER << COLUMN_URI;
970 foreach( int Column, sortingColumns )
972 QAction *asc = sortingMenu->addAction( qfu( psz_column_title( Column ) ) + " " + qtr("Ascending") );
973 QAction *desc = sortingMenu->addAction( qfu( psz_column_title( Column ) ) + " " + qtr("Descending") );
974 sortingMapper->setMapping( asc, columnFromMeta(Column) + 1 );
975 sortingMapper->setMapping( desc, -1 * (columnFromMeta(Column)+1) );
976 CONNECT( asc, triggered(), sortingMapper, map() );
977 CONNECT( desc, triggered(), sortingMapper, map() );
979 CONNECT( sortingMapper, mapped( int ), this, popupSort( int ) );
981 menu.addMenu( sortingMenu );
984 QMenu *zoomMenu = new QMenu( qtr( "Display size" ) );
985 zoomMenu->addAction( qtr( "Increase" ), this, SLOT( increaseZoom() ) );
986 zoomMenu->addAction( qtr( "Decrease" ), this, SLOT( decreaseZoom() ) );
987 menu.addMenu( zoomMenu );
989 /* Store the current selected item for popup*() methods */
990 current_selection = list;
992 /* Display and forward the result */
993 if( !menu.isEmpty() )
995 menu.exec( point ); return true;
1000 void PLModel::popupDel()
1002 doDelete( current_selection );
1005 void PLModel::popupPlay()
1009 playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
1011 activateItem( p_item );
1016 void PLModel::popupAddToPlaylist()
1018 playlist_Lock( THEPL );
1020 foreach( QModelIndex currentIndex, current_selection )
1022 playlist_item_t *p_item = playlist_ItemGetById( THEPL, itemId( currentIndex ) );
1023 if( !p_item ) continue;
1025 playlist_NodeAddCopy( THEPL, p_item,
1029 playlist_Unlock( THEPL );
1032 void PLModel::popupInfo()
1035 playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
1039 input_item_t* p_input = p_item->p_input;
1040 vlc_gc_incref( p_input );
1042 MediaInfoDialog *mid = new MediaInfoDialog( p_intf, p_input );
1043 vlc_gc_decref( p_input );
1044 mid->setParent( PlaylistDialog::getInstance( p_intf ),
1051 void PLModel::popupStream()
1053 QStringList mrls = selectedURIs();
1054 if( !mrls.isEmpty() )
1055 THEDP->streamingDialog( NULL, mrls[0], false );
1058 void PLModel::popupSave()
1060 QStringList mrls = selectedURIs();
1061 if( !mrls.isEmpty() )
1062 THEDP->streamingDialog( NULL, mrls[0] );
1065 void PLModel::popupExplore()
1067 char *uri = NULL, *path = NULL;
1070 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, i_popup_item );
1073 input_item_t *p_input = p_item->p_input;
1074 uri = input_item_GetURI( p_input );
1080 path = make_path( uri );
1086 QFileInfo info( qfu( path ) );
1089 QDesktopServices::openUrl( QUrl::fromLocalFile( info.absolutePath() ) );
1092 void PLModel::popupAddNode()
1095 QString name = QInputDialog::getText( PlaylistDialog::getInstance( p_intf ),
1096 qtr( I_NEW_DIR ), qtr( I_NEW_DIR_NAME ),
1097 QLineEdit::Normal, QString(), &ok);
1098 if( !ok || name.isEmpty() ) return;
1101 playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
1104 playlist_NodeCreate( p_playlist, qtu( name ), p_item, PLAYLIST_END, 0, NULL );
1108 void PLModel::popupSort( int column )
1110 sort( i_popup_parent,
1111 column > 0 ? column - 1 : -column - 1,
1112 column > 0 ? Qt::AscendingOrder : Qt::DescendingOrder );
1116 void PLModel::increaseZoom()
1119 emit layoutChanged();
1122 void PLModel::decreaseZoom()
1125 emit layoutChanged();
1128 /******************* Drag and Drop helper class ******************/
1129 PlMimeData::~PlMimeData()
1131 foreach( input_item_t *p_item, _inputItems )
1132 vlc_gc_decref( p_item );
1135 void PlMimeData::appendItem( input_item_t *p_item )
1137 vlc_gc_incref( p_item );
1138 _inputItems.append( p_item );
1141 QList<input_item_t*> PlMimeData::inputItems() const
1146 QStringList PlMimeData::formats () const
1149 fmts << "vlc/qt-input-items";