Commit d4a2b748 authored by Francois Cartegnie's avatar Francois Cartegnie

Qt: MLModel: Use Model Indexes instead of MLItem.

(see prev commit)
parent 856d5fe0
...@@ -151,6 +151,11 @@ MLItem* MLItem::parent() const ...@@ -151,6 +151,11 @@ MLItem* MLItem::parent() const
return parentItem; return parentItem;
} }
input_item_t* MLItem::inputItem()
{
return ml_CreateInputItem( p_ml, id() );
}
/** /**
* @brief Get a QVariant representing the data on a column * @brief Get a QVariant representing the data on a column
* @param column * @param column
......
...@@ -45,11 +45,13 @@ class MLModel; ...@@ -45,11 +45,13 @@ class MLModel;
class MLItem class MLItem
{ {
friend class MLModel;
public: public:
MLItem( const MLModel *p_model, intf_thread_t *_p_intf, MLItem( const MLModel *p_model, intf_thread_t *_p_intf,
ml_media_t *p_media, MLItem *p_parent ); ml_media_t *p_media, MLItem *p_parent );
virtual ~MLItem(); virtual ~MLItem();
protected:
void addChild( MLItem *child, int row = -1 ); void addChild( MLItem *child, int row = -1 );
void delChild( int row ); void delChild( int row );
void clearChildren(); void clearChildren();
...@@ -58,6 +60,7 @@ public: ...@@ -58,6 +60,7 @@ public:
int childCount() const; int childCount() const;
MLItem* parent() const; MLItem* parent() const;
input_item_t *inputItem();
QVariant data( int column ) const; QVariant data( int column ) const;
bool setData( ml_select_e meta, const QVariant &data ); bool setData( ml_select_e meta, const QVariant &data );
......
...@@ -504,6 +504,37 @@ void MLModel::play( const QModelIndex &idx ) ...@@ -504,6 +504,37 @@ void MLModel::play( const QModelIndex &idx )
AddItemToPlaylist( item->id(), true, p_ml, true ); AddItemToPlaylist( item->id(), true, p_ml, true );
} }
QString MLModel::getURI( const QModelIndex &index ) const
{
return QString();
}
QModelIndex MLModel::rootIndex() const
{
// FIXME
return QModelIndex();
}
bool MLModel::isTree() const
{
// FIXME ?
return false;
}
bool MLModel::canEdit() const
{
/* can always insert */
return true;
}
bool MLModel::isCurrentItem( const QModelIndex &index, playLocation where ) const
{
Q_UNUSED( index );
if ( where == IN_MEDIALIBRARY )
return true;
return false;
}
bool MLModel::popup( const QModelIndex & index, const QPoint &point, const QModelIndexList &list ) bool MLModel::popup( const QModelIndex & index, const QPoint &point, const QModelIndexList &list )
{ {
current_selection = list; current_selection = list;
...@@ -586,6 +617,18 @@ void MLModel::popupSave() ...@@ -586,6 +617,18 @@ void MLModel::popupSave()
THEDP->streamingDialog( NULL, mrls[0] ); THEDP->streamingDialog( NULL, mrls[0] );
} }
QModelIndex MLModel::getIndexByMLID( int id ) const
{
for( int i = 0; i < rowCount( ); i++ )
{
QModelIndex idx = index( i, 0 );
MLItem *item = static_cast< MLItem* >( idx.internalPointer() );
if( item->id() == id )
return idx;
}
return QModelIndex();
}
static int mediaAdded( vlc_object_t *p_this, char const *psz_var, static int mediaAdded( vlc_object_t *p_this, char const *psz_var,
vlc_value_t oldval, vlc_value_t newval, vlc_value_t oldval, vlc_value_t newval,
void *data ) void *data )
...@@ -614,17 +657,7 @@ static int mediaDeleted( vlc_object_t *p_this, char const *psz_var, ...@@ -614,17 +657,7 @@ static int mediaDeleted( vlc_object_t *p_this, char const *psz_var,
VLC_UNUSED( p_this ); VLC_UNUSED( psz_var ); VLC_UNUSED( oldval ); VLC_UNUSED( p_this ); VLC_UNUSED( psz_var ); VLC_UNUSED( oldval );
MLModel* p_model = ( MLModel* )data; MLModel* p_model = ( MLModel* )data;
QModelIndex remove_idx = QModelIndex(); QModelIndex remove_idx = p_model->getIndexByMLID( newval.i_int );
for( int i = 0; i < p_model->rowCount( ); i++ )
{
QModelIndex idx = p_model->index( i, 0 );
MLItem *item = static_cast< MLItem* >( idx.internalPointer() );
if( item->id() == newval.i_int )
{
remove_idx = idx;
break;
}
}
if( remove_idx.isValid() ) if( remove_idx.isValid() )
p_model->remove( remove_idx ); p_model->remove( remove_idx );
return VLC_SUCCESS; return VLC_SUCCESS;
......
...@@ -54,12 +54,7 @@ public: ...@@ -54,12 +54,7 @@ public:
// Basic QAbstractItemModel implementation // Basic QAbstractItemModel implementation
MLModel( intf_thread_t *_p_intf, QObject *parent = NULL ); MLModel( intf_thread_t *_p_intf, QObject *parent = NULL );
virtual ~MLModel(); virtual ~MLModel();
inline MLItem *getItem( QModelIndex index ) const
{
if( index.isValid() )
return static_cast<MLItem*>( index.internalPointer() );
else return NULL;
}
virtual int itemId( const QModelIndex & ) const; virtual int itemId( const QModelIndex & ) const;
QVariant data( const QModelIndex &idx, const int role = Qt::DisplayRole ) const; QVariant data( const QModelIndex &idx, const int role = Qt::DisplayRole ) const;
...@@ -95,13 +90,18 @@ public: ...@@ -95,13 +90,18 @@ public:
bool bSignal = true ); bool bSignal = true );
virtual void doDelete( QModelIndexList list ); virtual void doDelete( QModelIndexList list );
void remove( MLItem *item );
void remove( QModelIndex idx ); void remove( QModelIndex idx );
void clear(); void clear();
virtual bool popup( const QModelIndex & index, const QPoint &point, const QModelIndexList &list ); virtual bool popup( const QModelIndex & index, const QPoint &point, const QModelIndexList &list );
void play( const QModelIndex &idx ); void play( const QModelIndex &idx );
QStringList selectedURIs(); QStringList selectedURIs();
virtual QString getURI( const QModelIndex &index ) const;
virtual QModelIndex rootIndex() const;
virtual bool isTree() const;
virtual bool canEdit() const;
virtual bool isCurrentItem( const QModelIndex &index, playLocation where ) const;
QModelIndex getIndexByMLID( int id ) const;
public slots: public slots:
void activateItem( const QModelIndex &index ); void activateItem( const QModelIndex &index );
...@@ -113,6 +113,15 @@ protected slots: ...@@ -113,6 +113,15 @@ protected slots:
void popupStream(); void popupStream();
void popupSave(); void popupSave();
protected:
void remove( MLItem *item );
inline MLItem *getItem( QModelIndex index ) const
{
if( index.isValid() )
return static_cast<MLItem*>( index.internalPointer() );
else return NULL;
}
private: private:
QList< MLItem* > items; QList< MLItem* > items;
media_library_t* p_ml; media_library_t* p_ml;
......
...@@ -510,9 +510,7 @@ QRect PictureFlowSoftwareRenderer::renderSlide(const SlideInfo &slide, int col1, ...@@ -510,9 +510,7 @@ QRect PictureFlowSoftwareRenderer::renderSlide(const SlideInfo &slide, int col1,
index = ((MLModel*)state->model)->index( slide.slideIndex, 0, QModelIndex() ); index = ((MLModel*)state->model)->index( slide.slideIndex, 0, QModelIndex() );
if( !index.isValid() ) if( !index.isValid() )
return QRect(); return QRect();
artURL = mlm->data( index, COLUMN_COVER ).toString();
MLItem *item = static_cast<MLItem*>( index.internalPointer() );
artURL = qfu( item->getMedia()->psz_cover );
} }
#endif #endif
QString key = QString("%1%2%3%4").arg(VLCModel::getMeta( index, COLUMN_TITLE )).arg( VLCModel::getMeta( index, COLUMN_ARTIST ) ).arg(index.data( VLCModel::IsCurrentRole ).toBool() ).arg( artURL ); QString key = QString("%1%2%3%4").arg(VLCModel::getMeta( index, COLUMN_TITLE )).arg( VLCModel::getMeta( index, COLUMN_ARTIST ) ).arg(index.data( VLCModel::IsCurrentRole ).toBool() ).arg( artURL );
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment