QModelIndex MLModel::index( int row, int column,
const QModelIndex &parent ) const
{
- if( parent.isValid() )
+ if( parent.isValid() || row >= items.count() )
return QModelIndex();
else
{
remove( createIndex( row, 0 ) );
}
-void MLModel::remove( QModelIndexList list )
+void MLModel::doDelete( QModelIndexList list )
{
- for (int i = 0; i < list.size(); ++i) {
- remove( list.at(i) );
+ for (int i = 0; i < list.size(); ++i)
+ {
+ int id = getId( list.at(i) );
+ ml_DeleteSimple( p_ml, id );
}
}
QIcon addIcon( ":/buttons/playlist/playlist_add" );
menu.addSeparator();
- menu.addAction( addIcon, qtr(I_PL_ADDF), THEDP, SLOT( simpleMLAppendDialog()) );
- menu.addAction( addIcon, qtr(I_PL_ADDDIR), THEDP, SLOT( MLAppendDir() ) );
- menu.addAction( addIcon, qtr(I_OP_ADVOP), THEDP, SLOT( MLAppendDialog() ) );
+ //menu.addAction( addIcon, qtr(I_PL_ADDF), THEDP, SLOT( simpleMLAppendDialog()) );
+ //menu.addAction( addIcon, qtr(I_PL_ADDDIR), THEDP, SLOT( MLAppendDir() ) );
+ //menu.addAction( addIcon, qtr(I_OP_ADVOP), THEDP, SLOT( MLAppendDialog() ) );
if( index.isValid() )
{
else return false;
}
-
-void MLModel::popupDel()
+void MLModel::popupPlay()
{
- remove( current_selection );
+ play( current_index );
}
-void MLModel::popupPlay()
+void MLModel::popupDel()
{
- play( current_index );
+ doDelete( current_selection );
}
void MLModel::popupInfo()
int insertResultArray( vlc_array_t *p_result_array, int row = -1,
bool bSignal = true );
+ virtual void doDelete( QModelIndexList list );
void remove( MLItem *item );
- void remove( QModelIndexList list );
void remove( QModelIndex idx );
void clear();
);
}
-QString PLModel::getMeta( const QModelIndex & index, int meta )
-{
- return index.model()->index( index.row(),
- columnFromMeta( meta ),
- index.parent() )
- .data().toString();
-}
-
-
-QPixmap PLModel::getArtPixmap( const QModelIndex & index, const QSize & size )
-{
- PLItem *item = static_cast<PLItem*>( index.internalPointer() );
- assert( item );
-
- if( item == NULL )
- return NULL;
-
- QString artUrl = InputManager::decodeArtURL( item->inputItem() );
-
- /* If empty, take one of the children art URL */
- if( artUrl.isEmpty() )
- {
- for( int i = 0; i < item->childCount(); i++ )
- {
- artUrl = InputManager::decodeArtURL( item->child( i )->inputItem() );
- if( !artUrl.isEmpty() )
- break;
- }
- }
-
- QPixmap artPix;
- QString key = artUrl + QString("%1%2").arg(size.width()).arg(size.height());
-
- /* Lookup in the QPixmapCache */
- if( !QPixmapCache::find( key, artPix ))
- {
- if( artUrl.isEmpty() || !artPix.load( artUrl ) )
- {
- key = QString("noart%1%2").arg(size.width()).arg(size.height());
- if( !QPixmapCache::find( key, artPix ) )
- {
- artPix = QPixmap( ":/noart" ).scaled( size,
- Qt::KeepAspectRatio,
- Qt::SmoothTransformation );
- QPixmapCache::insert( key, artPix );
- }
- }
- else
- {
- artPix = artPix.scaled( size, Qt::KeepAspectRatio, Qt::SmoothTransformation );
- QPixmapCache::insert( key, artPix );
- }
- }
-
- return artPix;
-}
/************************* Updates handling *****************************/
/**** Events processing ****/
bool isCurrent( const QModelIndex &index ) const;
int itemId( const QModelIndex &index ) const;
- static QPixmap getArtPixmap( const QModelIndex & index, const QSize & size );
- static QString getMeta( const QModelIndex & index, int meta );
-
/* Actions */
virtual bool popup( const QModelIndex & index, const QPoint &point, const QModelIndexList &list );
- void doDelete( QModelIndexList selected );
+ virtual void doDelete( QModelIndexList selected );
void search( const QString& search_text, const QModelIndex & root, bool b_recursive );
void sort( const int column, Qt::SortOrder order );
void sort( const int i_root_id, const int column, Qt::SortOrder order );
void PlIconViewItemDelegate::paint( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const
{
- QString title = PLModel::getMeta( index, COLUMN_TITLE );
- QString artist = PLModel::getMeta( index, COLUMN_ARTIST );
+ QString title = VLCModel::getMeta( index, COLUMN_TITLE );
+ QString artist = VLCModel::getMeta( index, COLUMN_ARTIST );
QFont font( index.data( Qt::FontRole ).value<QFont>() );
painter->setFont( font );
int art_width = averagewidth * ICON_SCALER;
int art_height = averagewidth * ICON_SCALER;
- QPixmap artPix = PLModel::getArtPixmap( index, QSize( art_width, art_height) );
+ QPixmap artPix = VLCModel::getArtPixmap( index, QSize( art_width, art_height) );
paintBackground( painter, option, index );
void PlListViewItemDelegate::paint( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const
{
- QString title = PLModel::getMeta( index, COLUMN_TITLE );
- QString duration = PLModel::getMeta( index, COLUMN_DURATION );
+ QString title = VLCModel::getMeta( index, COLUMN_TITLE );
+ QString duration = VLCModel::getMeta( index, COLUMN_DURATION );
if( !duration.isEmpty() ) title += QString(" [%1]").arg( duration );
- QString artist = PLModel::getMeta( index, COLUMN_ARTIST );
- QString album = PLModel::getMeta( index, COLUMN_ALBUM );
- QString trackNum = PLModel::getMeta( index, COLUMN_TRACK_NUMBER );
+ QString artist = VLCModel::getMeta( index, COLUMN_ARTIST );
+ QString album = VLCModel::getMeta( index, COLUMN_ALBUM );
+ QString trackNum = VLCModel::getMeta( index, COLUMN_TRACK_NUMBER );
QString artistAlbum = artist;
if( !album.isEmpty() )
{
if( !trackNum.isEmpty() ) artistAlbum += QString( " [#%1]" ).arg( trackNum );
}
- QPixmap artPix = PLModel::getArtPixmap( index, QSize( LISTVIEW_ART_SIZE, LISTVIEW_ART_SIZE ) );
+ QPixmap artPix = VLCModel::getArtPixmap( index, QSize( LISTVIEW_ART_SIZE, LISTVIEW_ART_SIZE ) );
//Draw selection rectangle and current playing item indication
paintBackground( painter, option, index );
VLCModel::~VLCModel()
{
}
+
+QString VLCModel::getMeta( const QModelIndex & index, int meta )
+{
+ return index.model()->index( index.row(), columnFromMeta( meta ), index.parent() ).
+ data().toString();
+}
+
+QPixmap VLCModel::getArtPixmap( const QModelIndex & index, const QSize & size )
+{
+ QString artUrl;
+ artUrl = index.model()->index( index.row(),
+ COLUMN_COVER,
+ index.parent() )
+ .data().toString();
+ QPixmap artPix;
+
+ QString key = artUrl + QString("%1%2").arg(size.width()).arg(size.height());
+
+ if( !QPixmapCache::find( key, artPix ))
+ {
+ if( artUrl.isEmpty() || !artPix.load( artUrl ) )
+ {
+ key = QString("noart%1%2").arg(size.width()).arg(size.height());
+ if( !QPixmapCache::find( key, artPix ) )
+ {
+ artPix = QPixmap( ":/noart" ).scaled( size,
+ Qt::KeepAspectRatio,
+ Qt::SmoothTransformation );
+ QPixmapCache::insert( key, artPix );
+ }
+ }
+ else
+ {
+ artPix = artPix.scaled( size, Qt::KeepAspectRatio, Qt::SmoothTransformation );
+ QPixmapCache::insert( key, artPix );
+ }
+ }
+
+ return artPix;
+}
#include <vlc_input.h>
#include <QModelIndex>
+#include <QPixmapCache>
+#include <QSize>
#include <QAbstractItemModel>
virtual QModelIndex currentIndex() const = 0;
virtual bool popup( const QModelIndex & index,
const QPoint &point, const QModelIndexList &list ) = 0;
+ virtual void doDelete( QModelIndexList ) = 0;
virtual ~VLCModel();
+ static QString getMeta( const QModelIndex & index, int meta );
+ static QPixmap getArtPixmap( const QModelIndex & index, const QSize & size );
public slots:
virtual void activateItem( const QModelIndex &index ) = 0;