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 : QAbstractItemModel( parent )
72 p_playlist = _p_playlist;
74 i_cached_input_id = -1;
75 i_popup_item = i_popup_parent = -1;
78 rootItem = NULL; /* PLItem rootItem, will be set in rebuild( ) */
80 /* Icons initialization */
81 #define ADD_ICON(type, x) icons[ITEM_TYPE_##type] = QIcon( x )
82 ADD_ICON( UNKNOWN , type_unknown_xpm );
83 ADD_ICON( FILE, ":/type/file" );
84 ADD_ICON( DIRECTORY, ":/type/directory" );
85 ADD_ICON( DISC, ":/type/disc" );
86 ADD_ICON( CDDA, ":/type/cdda" );
87 ADD_ICON( CARD, ":/type/capture-card" );
88 ADD_ICON( NET, ":/type/net" );
89 ADD_ICON( PLAYLIST, ":/type/playlist" );
90 ADD_ICON( NODE, ":/type/node" );
94 DCONNECT( THEMIM->getIM(), metaChanged( input_item_t *),
95 this, processInputItemUpdate( input_item_t *) );
96 DCONNECT( THEMIM, inputChanged( input_thread_t * ),
97 this, processInputItemUpdate( input_thread_t* ) );
98 CONNECT( THEMIM, playlistItemAppended( int, int ),
99 this, processItemAppend( int, int ) );
100 CONNECT( THEMIM, playlistItemRemoved( int ),
101 this, processItemRemoval( int ) );
110 Qt::DropActions PLModel::supportedDropActions() const
112 return Qt::CopyAction | Qt::MoveAction;
115 Qt::ItemFlags PLModel::flags( const QModelIndex &index ) const
117 Qt::ItemFlags flags = QAbstractItemModel::flags( index );
119 const PLItem *item = index.isValid() ? getItem( index ) : rootItem;
124 playlist_item_t *plItem =
125 playlist_ItemGetById( p_playlist, item->i_id );
127 if ( plItem && ( plItem->i_children > -1 ) )
128 flags |= Qt::ItemIsDropEnabled;
133 flags |= Qt::ItemIsDragEnabled;
138 QStringList PLModel::mimeTypes() const
141 types << "vlc/qt-input-items";
145 bool modelIndexLessThen( const QModelIndex &i1, const QModelIndex &i2 )
147 if( !i1.isValid() || !i2.isValid() ) return false;
148 PLItem *item1 = static_cast<PLItem*>( i1.internalPointer() );
149 PLItem *item2 = static_cast<PLItem*>( i2.internalPointer() );
150 if( item1->parent() == item2->parent() ) return i1.row() < i2.row();
151 else return *item1 < *item2;
154 QMimeData *PLModel::mimeData( const QModelIndexList &indexes ) const
156 PlMimeData *plMimeData = new PlMimeData();
157 QModelIndexList list;
159 foreach( const QModelIndex &index, indexes ) {
160 if( index.isValid() && index.column() == 0 )
164 qSort(list.begin(), list.end(), modelIndexLessThen);
167 foreach( const QModelIndex &index, list ) {
170 PLItem *testee = getItem( index );
171 while( testee->parent() )
173 if( testee->parent() == item ||
174 testee->parent() == item->parent() ) break;
175 testee = testee->parent();
177 if( testee->parent() == item ) continue;
178 item = getItem( index );
181 item = getItem( index );
183 plMimeData->appendItem( item->p_input );
190 bool PLModel::dropMimeData( const QMimeData *data, Qt::DropAction action,
191 int row, int column, const QModelIndex &parent )
193 bool copy = action == Qt::CopyAction;
194 if( !copy && action != Qt::MoveAction )
197 const PlMimeData *plMimeData = qobject_cast<const PlMimeData*>( data );
201 dropAppendCopy( plMimeData, getItem( parent ), row );
203 dropMove( plMimeData, getItem( parent ), row );
208 void PLModel::dropAppendCopy( const PlMimeData *plMimeData, PLItem *target, int pos )
212 playlist_item_t *p_parent =
213 playlist_ItemGetByInput( p_playlist, target->p_input );
214 if( !p_parent ) return;
216 if( pos == -1 ) pos = PLAYLIST_END;
218 QList<input_item_t*> inputItems = plMimeData->inputItems();
220 foreach( input_item_t* p_input, inputItems )
222 playlist_item_t *p_item = playlist_ItemGetByInput( p_playlist, p_input );
223 if( !p_item ) continue;
224 pos = playlist_NodeAddCopy( p_playlist, p_item, p_parent, pos );
230 void PLModel::dropMove( const PlMimeData * plMimeData, PLItem *target, int row )
232 QList<input_item_t*> inputItems = plMimeData->inputItems();
233 QList<PLItem*> model_items;
234 playlist_item_t *pp_items[inputItems.size()];
238 playlist_item_t *p_parent =
239 playlist_ItemGetByInput( p_playlist, target->p_input );
241 if( !p_parent || row > p_parent->i_children )
246 int new_pos = row == -1 ? p_parent->i_children : row;
247 int model_pos = new_pos;
250 foreach( input_item_t *p_input, inputItems )
252 playlist_item_t *p_item = playlist_ItemGetByInput( p_playlist, p_input );
253 if( !p_item ) continue;
255 PLItem *item = findByInput( rootItem, p_input->i_id );
256 if( !item ) continue;
258 /* Better not try to move a node into itself.
259 Abort the whole operation in that case,
260 because it is ambiguous. */
261 PLItem *climber = target;
264 if( climber == item )
268 climber = climber->parentItem;
271 if( item->parentItem == target &&
272 target->children.indexOf( item ) < new_pos )
275 model_items.append( item );
276 pp_items[i] = p_item;
280 if( model_items.isEmpty() )
285 playlist_TreeMoveMany( p_playlist, i, pp_items, p_parent, new_pos );
289 foreach( PLItem *item, model_items )
292 insertChildren( target, model_items, model_pos );
295 /* remove item with its id */
296 void PLModel::removeItem( int i_id )
298 PLItem *item = findById( rootItem, i_id );
302 void PLModel::activateItem( const QModelIndex &index )
304 assert( index.isValid() );
305 const PLItem *item = getItem( index );
308 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id );
309 activateItem( p_item );
313 /* Must be entered with lock */
314 void PLModel::activateItem( playlist_item_t *p_item )
316 if( !p_item ) return;
317 playlist_item_t *p_parent = p_item;
320 if( p_parent->i_id == rootItem->i_id ) break;
321 p_parent = p_parent->p_parent;
324 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, pl_Locked,
328 /****************** Base model mandatory implementations *****************/
329 QVariant PLModel::data( const QModelIndex &index, const int role ) const
331 if( !index.isValid() ) return QVariant();
332 const PLItem *item = getItem( index );
333 if( role == Qt::DisplayRole )
335 int metadata = columnToMeta( index.column() );
336 if( metadata == COLUMN_END ) return QVariant();
339 if( metadata == COLUMN_NUMBER )
340 returninfo = QString::number( index.row() + 1 );
343 char *psz = psz_column_meta( item->p_input, metadata );
344 returninfo = qfu( psz );
347 return QVariant( returninfo );
349 else if( role == Qt::DecorationRole && index.column() == 0 )
351 /* Used to segfault here because i_type wasn't always initialized */
352 return QVariant( PLModel::icons[item->p_input->i_type] );
354 else if( role == Qt::FontRole )
357 f.setPointSize( f.pointSize() - 1 );
358 if( isCurrent( index ) )
360 return QVariant( f );
362 else if( role == Qt::BackgroundRole && isCurrent( index ) )
364 return QVariant( QBrush( Qt::gray ) );
366 else if( role == IsCurrentRole ) return QVariant( isCurrent( index ) );
367 else if( role == IsLeafNodeRole )
371 playlist_item_t *plItem =
372 playlist_ItemGetById( p_playlist, item->i_id );
375 isLeaf = plItem->i_children == -1;
380 else if( role == IsCurrentsParentNodeRole )
382 return QVariant( isParent( index, currentIndex() ) );
387 /* Seek from current index toward the top and see if index is one of parent nodes */
388 bool PLModel::isParent( const QModelIndex &index, const QModelIndex ¤t ) const
390 if( !index.isValid() )
393 if( index == current )
396 if( !current.isValid() || !current.parent().isValid() )
399 return isParent( index, current.parent() );
402 bool PLModel::isCurrent( const QModelIndex &index ) const
404 return getItem( index )->p_input == THEMIM->currentInputItem();
407 int PLModel::itemId( const QModelIndex &index ) const
409 return getItem( index )->i_id;
412 QVariant PLModel::headerData( int section, Qt::Orientation orientation,
415 if (orientation != Qt::Horizontal || role != Qt::DisplayRole)
418 int meta_col = columnToMeta( section );
420 if( meta_col == COLUMN_END ) return QVariant();
422 return QVariant( qfu( psz_column_title( meta_col ) ) );
425 QModelIndex PLModel::index( const int row, const int column, const QModelIndex &parent )
428 PLItem *parentItem = parent.isValid() ? getItem( parent ) : rootItem;
430 PLItem *childItem = parentItem->child( row );
432 return createIndex( row, column, childItem );
434 return QModelIndex();
437 QModelIndex PLModel::index( const int i_id, const int c )
439 return index( findById( rootItem, i_id ), c );
442 /* Return the index of a given item */
443 QModelIndex PLModel::index( PLItem *item, int column ) const
445 if( !item ) return QModelIndex();
446 const PLItem *parent = item->parent();
448 return createIndex( parent->children.lastIndexOf( item ),
450 return QModelIndex();
453 QModelIndex PLModel::currentIndex() const
455 input_thread_t *p_input_thread = THEMIM->getInput();
456 if( !p_input_thread ) return QModelIndex();
457 PLItem *item = findByInput( rootItem, input_GetItem( p_input_thread )->i_id );
458 return index( item, 0 );
461 QModelIndex PLModel::parent( const QModelIndex &index ) const
463 if( !index.isValid() ) return QModelIndex();
465 PLItem *childItem = getItem( index );
468 msg_Err( p_playlist, "NULL CHILD" );
469 return QModelIndex();
472 PLItem *parentItem = childItem->parent();
473 if( !parentItem || parentItem == rootItem ) return QModelIndex();
474 if( !parentItem->parentItem )
476 msg_Err( p_playlist, "No parent parent, trying row 0 " );
477 msg_Err( p_playlist, "----- PLEASE REPORT THIS ------" );
478 return createIndex( 0, 0, parentItem );
480 return createIndex(parentItem->row(), 0, parentItem);
483 int PLModel::columnCount( const QModelIndex &i) const
485 return columnFromMeta( COLUMN_END );
488 int PLModel::rowCount( const QModelIndex &parent ) const
490 const PLItem *parentItem = parent.isValid() ? getItem( parent ) : rootItem;
491 return parentItem->childCount();
494 QStringList PLModel::selectedURIs()
497 for( int i = 0; i < current_selection.size(); i++ )
499 const PLItem *item = getItem( current_selection[i] );
503 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id );
506 char *psz = input_item_GetURI( p_item->p_input );
509 lst.append( qfu(psz) );
519 /************************* Lookups *****************************/
520 PLItem *PLModel::findById( PLItem *root, int i_id ) const
522 return findInner( root, i_id, false );
525 PLItem *PLModel::findByInput( PLItem *root, int i_id ) const
527 PLItem *result = findInner( root, i_id, true );
531 PLItem * PLModel::findInner( PLItem *root, int i_id, bool b_input ) const
533 if( !root ) return NULL;
535 if( !b_input && root->i_id == i_id )
538 else if( b_input && root->p_input->i_id == i_id )
541 QList<PLItem *>::iterator it = root->children.begin();
542 while ( it != root->children.end() )
544 if( !b_input && (*it)->i_id == i_id )
547 else if( b_input && (*it)->p_input->i_id == i_id )
550 if( (*it)->children.size() )
552 PLItem *childFound = findInner( (*it), i_id, b_input );
561 int PLModel::columnToMeta( int _column )
566 while( column != _column && meta != COLUMN_END )
575 int PLModel::columnFromMeta( int meta_col )
580 while( meta != meta_col && meta != COLUMN_END )
589 bool PLModel::canEdit() const
594 rootItem->p_input == p_playlist->p_playing->p_input ||
595 ( p_playlist->p_media_library &&
596 rootItem->p_input == p_playlist->p_media_library->p_input )
601 QString PLModel::getMeta( const QModelIndex & index, int meta )
603 return index.model()->index( index.row(),
604 PLModel::columnFromMeta( meta ),
609 QPixmap PLModel::getArtPixmap( const QModelIndex & index, const QSize & size )
611 PLItem *item = static_cast<PLItem*>( index.internalPointer() );
617 QString artUrl = InputManager::decodeArtURL( item->inputItem() );
619 /* If empty, take one of the children art URL */
620 if( artUrl.isEmpty() )
622 for( int i = 0; i < item->childCount(); i++ )
624 artUrl = InputManager::decodeArtURL( item->child( i )->inputItem() );
625 if( !artUrl.isEmpty() )
631 QString key = artUrl + QString("%1%2").arg(size.width()).arg(size.height());
633 /* Lookup in the QPixmapCache */
634 if( !QPixmapCache::find( key, artPix ))
636 if( artUrl.isEmpty() || !artPix.load( artUrl ) )
638 key = QString("noart%1%2").arg(size.width()).arg(size.height());
639 if( !QPixmapCache::find( key, artPix ) )
641 artPix = QPixmap( ":/noart" ).scaled( size,
643 Qt::SmoothTransformation );
644 QPixmapCache::insert( key, artPix );
649 artPix = artPix.scaled( size, Qt::KeepAspectRatio, Qt::SmoothTransformation );
650 QPixmapCache::insert( key, artPix );
656 /************************* Updates handling *****************************/
658 /**** Events processing ****/
659 void PLModel::processInputItemUpdate( input_thread_t *p_input )
661 if( !p_input ) return;
662 if( p_input && !( p_input->b_dead || !vlc_object_alive( p_input ) ) )
664 PLItem *item = findByInput( rootItem, input_GetItem( p_input )->i_id );
665 if( item ) emit currentChanged( index( item, 0 ) );
667 processInputItemUpdate( input_GetItem( p_input ) );
670 void PLModel::processInputItemUpdate( input_item_t *p_item )
672 if( !p_item || p_item->i_id <= 0 ) return;
673 PLItem *item = findByInput( rootItem, p_item->i_id );
675 updateTreeItem( item );
678 void PLModel::processItemRemoval( int i_id )
680 if( i_id <= 0 ) return;
684 void PLModel::processItemAppend( int i_item, int i_parent )
686 playlist_item_t *p_item = NULL;
687 PLItem *newItem = NULL;
690 /* Find the Parent */
691 PLItem *nodeParentItem = findById( rootItem, i_parent );
692 if( !nodeParentItem ) return;
694 /* Search for an already matching children */
695 foreach( const PLItem *existing, nodeParentItem->children )
696 if( existing->i_id == i_item ) return;
700 p_item = playlist_ItemGetById( p_playlist, i_item );
701 if( !p_item || p_item->i_flags & PLAYLIST_DBL_FLAG )
706 for( pos = 0; pos < p_item->p_parent->i_children; pos++ )
707 if( p_item->p_parent->pp_children[pos] == p_item ) break;
709 newItem = new PLItem( p_item, nodeParentItem );
712 /* We insert the newItem (children) inside the parent */
713 beginInsertRows( index( nodeParentItem, 0 ), pos, pos );
714 nodeParentItem->insertChild( newItem, pos );
717 if( newItem->p_input == THEMIM->currentInputItem() )
718 emit currentChanged( index( newItem, 0 ) );
721 void PLModel::rebuild()
726 void PLModel::rebuild( playlist_item_t *p_root )
728 playlist_item_t* p_item;
730 /* Invalidate cache */
731 i_cached_id = i_cached_input_id = -1;
733 if( rootItem ) rootItem->removeChildren();
739 rootItem = new PLItem( p_root );
742 /* Recreate from root */
743 updateChildren( rootItem );
746 /* And signal the view */
749 if( p_root ) emit rootChanged();
752 void PLModel::takeItem( PLItem *item )
755 PLItem *parent = item->parentItem;
757 int i_index = parent->children.indexOf( item );
759 beginRemoveRows( index( parent, 0 ), i_index, i_index );
760 parent->takeChildAt( i_index );
764 void PLModel::insertChildren( PLItem *node, QList<PLItem*>& items, int i_pos )
767 int count = items.size();
769 printf( "Here I am\n");
770 beginInsertRows( index( node, 0 ), i_pos, i_pos + count - 1 );
771 for( int i = 0; i < count; i++ )
773 node->children.insert( i_pos + i, items[i] );
774 items[i]->parentItem = node;
779 void PLModel::removeItem( PLItem *item )
784 i_cached_input_id = -1;
786 if( item->parentItem ) {
787 int i = item->parentItem->children.indexOf( item );
788 beginRemoveRows( index( item->parentItem, 0), i, i );
789 item->parentItem->children.removeAt(i);
798 rebuild( p_playlist->p_playing );
802 /* This function must be entered WITH the playlist lock */
803 void PLModel::updateChildren( PLItem *root )
805 playlist_item_t *p_node = playlist_ItemGetById( p_playlist, root->i_id );
806 updateChildren( p_node, root );
809 /* This function must be entered WITH the playlist lock */
810 void PLModel::updateChildren( playlist_item_t *p_node, PLItem *root )
812 for( int i = 0; i < p_node->i_children ; i++ )
814 if( p_node->pp_children[i]->i_flags & PLAYLIST_DBL_FLAG ) continue;
815 PLItem *newItem = new PLItem( p_node->pp_children[i], root );
816 root->appendChild( newItem );
817 if( p_node->pp_children[i]->i_children != -1 )
818 updateChildren( p_node->pp_children[i], newItem );
822 /* Function doesn't need playlist-lock, as we don't touch playlist_item_t stuff here*/
823 void PLModel::updateTreeItem( PLItem *item )
826 emit dataChanged( index( item, 0 ) , index( item, columnCount( QModelIndex() ) ) );
829 /************************* Actions ******************************/
832 * Deletion, don't delete items childrens if item is going to be
833 * delete allready, so we remove childrens from selection-list.
835 void PLModel::doDelete( QModelIndexList selected )
837 if( !canEdit() ) return;
839 while( !selected.isEmpty() )
841 QModelIndex index = selected[0];
842 selected.removeAt( 0 );
844 if( index.column() != 0 ) continue;
846 PLItem *item = getItem( index );
847 if( item->children.size() )
848 recurseDelete( item->children, &selected );
851 playlist_DeleteFromInput( p_playlist, item->p_input, pl_Locked );
858 void PLModel::recurseDelete( QList<PLItem*> children, QModelIndexList *fullList )
860 for( int i = children.size() - 1; i >= 0 ; i-- )
862 PLItem *item = children[i];
863 if( item->children.size() )
864 recurseDelete( item->children, fullList );
865 fullList->removeAll( index( item, 0 ) );
869 /******* Volume III: Sorting and searching ********/
870 void PLModel::sort( const int column, Qt::SortOrder order )
872 sort( rootItem->i_id, column, order );
875 void PLModel::sort( const int i_root_id, const int column, Qt::SortOrder order )
877 msg_Dbg( p_intf, "Sorting by column %i, order %i", column, order );
879 int meta = columnToMeta( column );
880 if( meta == COLUMN_END ) return;
882 PLItem *item = findById( rootItem, i_root_id );
884 QModelIndex qIndex = index( item, 0 );
885 int count = item->children.size();
888 beginRemoveRows( qIndex, 0, count - 1 );
889 item->removeChildren();
895 playlist_item_t *p_root = playlist_ItemGetById( p_playlist,
899 playlist_RecursiveNodeSort( p_playlist, p_root,
900 i_column_sorting( meta ),
901 order == Qt::AscendingOrder ?
902 ORDER_NORMAL : ORDER_REVERSE );
906 i_cached_id = i_cached_input_id = -1;
910 beginInsertRows( qIndex, 0, count - 1 );
911 updateChildren( item );
915 /* if we have popup item, try to make sure that you keep that item visible */
916 if( i_popup_item > -1 )
918 PLItem *popupitem = findById( rootItem, i_popup_item );
919 if( popupitem ) emit currentChanged( index( popupitem, 0 ) );
920 /* reset i_popup_item as we don't show it as selected anymore anyway */
923 else if( currentIndex().isValid() ) emit currentChanged( currentIndex() );
926 void PLModel::search( const QString& search_text, const QModelIndex & idx, bool b_recursive )
928 /** \todo Fire the search with a small delay ? */
931 playlist_item_t *p_root = playlist_ItemGetById( p_playlist,
934 const char *psz_name = qtu( search_text );
935 playlist_LiveSearchUpdate( p_playlist , p_root, psz_name, b_recursive );
939 PLItem *searchRoot = getItem( idx );
941 beginRemoveRows( idx, 0, searchRoot->children.size() - 1 );
942 searchRoot->removeChildren();
945 beginInsertRows( idx, 0, searchRoot->children.size() - 1 );
946 updateChildren( searchRoot ); // The PL_LOCK is needed here
957 /*********** Popup *********/
958 bool PLModel::popup( const QModelIndex & index, const QPoint &point, const QModelIndexList &list )
960 int i_id = index.isValid() ? itemId( index ) : rootItem->i_id;
963 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, i_id );
970 input_item_t *p_input = p_item->p_input;
971 vlc_gc_incref( p_input );
973 i_popup_item = index.isValid() ? p_item->i_id : -1;
974 i_popup_parent = index.isValid() ?
975 ( p_item->p_parent ? p_item->p_parent->i_id : -1 ) :
977 i_popup_column = index.column();
979 bool tree = ( rootItem && rootItem->i_id != p_playlist->p_playing->i_id ) ||
980 var_InheritBool( p_intf, "playlist-tree" );
984 current_selection = list;
987 if( i_popup_item > -1 )
989 menu.addAction( QIcon( ":/menu/play" ), qtr(I_POP_PLAY), this, SLOT( popupPlay() ) );
990 menu.addAction( QIcon( ":/menu/stream" ),
991 qtr(I_POP_STREAM), this, SLOT( popupStream() ) );
992 menu.addAction( qtr(I_POP_SAVE), this, SLOT( popupSave() ) );
993 menu.addAction( QIcon( ":/menu/info" ), qtr(I_POP_INFO), this, SLOT( popupInfo() ) );
994 if( !strncasecmp( p_input->psz_uri, "file://", 7 ) )
995 menu.addAction( QIcon( ":/type/folder-grey" ),
996 qtr( I_POP_EXPLORE ), this, SLOT( popupExplore() ) );
1001 QIcon addIcon( ":/buttons/playlist/playlist_add" );
1002 menu.addSeparator();
1003 if( tree ) menu.addAction( addIcon, qtr(I_POP_NEWFOLDER), this, SLOT( popupAddNode() ) );
1004 if( rootItem->i_id == THEPL->p_playing->i_id )
1006 menu.addAction( addIcon, qtr(I_PL_ADDF), THEDP, SLOT( simplePLAppendDialog()) );
1007 menu.addAction( addIcon, qtr(I_PL_ADDDIR), THEDP, SLOT( PLAppendDir()) );
1008 menu.addAction( addIcon, qtr(I_OP_ADVOP), THEDP, SLOT( PLAppendDialog()) );
1010 else if( THEPL->p_media_library &&
1011 rootItem->i_id == THEPL->p_media_library->i_id )
1013 menu.addAction( addIcon, qtr(I_PL_ADDF), THEDP, SLOT( simpleMLAppendDialog()) );
1014 menu.addAction( addIcon, qtr(I_PL_ADDDIR), THEDP, SLOT( MLAppendDir() ) );
1015 menu.addAction( addIcon, qtr(I_OP_ADVOP), THEDP, SLOT( MLAppendDialog() ) );
1018 if( i_popup_item > -1 )
1020 menu.addAction( QIcon( ":/buttons/playlist/playlist_remove" ),
1021 qtr(I_POP_DEL), this, SLOT( popupDel() ) );
1022 menu.addSeparator();
1025 sortingMenu = new QMenu( qtr( "Sort by" ) );
1026 sortingMapper = new QSignalMapper( this );
1028 for( i = 1, j = 1; i < COLUMN_END; i <<= 1, j++ )
1030 if( i == COLUMN_NUMBER ) continue;
1031 QMenu *m = sortingMenu->addMenu( qfu( psz_column_title( i ) ) );
1032 QAction *asc = m->addAction( qtr("Ascending") );
1033 QAction *desc = m->addAction( qtr("Descending") );
1034 sortingMapper->setMapping( asc, j );
1035 sortingMapper->setMapping( desc, -j );
1036 CONNECT( asc, triggered(), sortingMapper, map() );
1037 CONNECT( desc, triggered(), sortingMapper, map() );
1039 CONNECT( sortingMapper, mapped( int ), this, popupSort( int ) );
1041 menu.addMenu( sortingMenu );
1043 vlc_gc_decref( p_input );
1045 if( !menu.isEmpty() )
1047 menu.exec( point ); return true;
1052 void PLModel::popupDel()
1054 doDelete( current_selection );
1057 void PLModel::popupPlay()
1061 playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
1063 activateItem( p_item );
1068 void PLModel::popupInfo()
1071 playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
1075 input_item_t* p_input = p_item->p_input;
1076 vlc_gc_incref( p_input );
1078 MediaInfoDialog *mid = new MediaInfoDialog( p_intf, p_input );
1079 vlc_gc_decref( p_input );
1080 mid->setParent( PlaylistDialog::getInstance( p_intf ),
1087 void PLModel::popupStream()
1089 QStringList mrls = selectedURIs();
1090 if( !mrls.isEmpty() )
1091 THEDP->streamingDialog( NULL, mrls[0], false );
1095 void PLModel::popupSave()
1097 QStringList mrls = selectedURIs();
1098 if( !mrls.isEmpty() )
1099 THEDP->streamingDialog( NULL, mrls[0] );
1102 void PLModel::popupExplore()
1105 playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
1109 input_item_t *p_input = p_item->p_input;
1110 char *psz_meta = input_item_GetURI( p_input );
1114 const char *psz_access;
1115 const char *psz_demux;
1117 input_SplitMRL( &psz_access, &psz_demux, &psz_path, psz_meta );
1119 if( !EMPTY_STR( psz_access ) && (
1120 !strncasecmp( psz_access, "file", 4 ) ||
1121 !strncasecmp( psz_access, "dire", 4 ) ))
1124 /* Qt openURL doesn't know to open files that starts with a / or \ */
1125 if( psz_path[0] == '/' || psz_path[0] == '\\' )
1129 QFileInfo info( qfu( decode_URI( psz_path ) ) );
1130 QDesktopServices::openUrl(
1131 QUrl::fromLocalFile( info.absolutePath() ) );
1140 void PLModel::popupAddNode()
1143 QString name = QInputDialog::getText( PlaylistDialog::getInstance( p_intf ),
1144 qtr( I_NEW_DIR ), qtr( I_NEW_DIR_NAME ),
1145 QLineEdit::Normal, QString(), &ok);
1146 if( !ok || name.isEmpty() ) return;
1149 playlist_item_t *p_item = playlist_ItemGetById( p_playlist,
1152 playlist_NodeCreate( p_playlist, qtu( name ), p_item, PLAYLIST_END, 0, NULL );
1156 void PLModel::popupSort( int column )
1158 sort( i_popup_parent,
1159 column > 0 ? column - 1 : -column - 1,
1160 column > 0 ? Qt::AscendingOrder : Qt::DescendingOrder );
1163 /******************* Drag and Drop helper class ******************/
1165 PlMimeData::PlMimeData( )
1168 PlMimeData::~PlMimeData()
1170 foreach( input_item_t *p_item, _inputItems )
1171 vlc_gc_decref( p_item );
1174 void PlMimeData::appendItem( input_item_t *p_item )
1176 vlc_gc_incref( p_item );
1177 _inputItems.append( p_item );
1180 QList<input_item_t*> PlMimeData::inputItems() const
1185 QStringList PlMimeData::formats () const
1188 fmts << "vlc/qt-input-items";