Commit 00d1ebdf authored by Srikanth Raju's avatar Srikanth Raju

Qt/ML: Extend Playlist model from VLCModel

parent ed89fe73
......@@ -49,11 +49,11 @@ public:
void removeChildren();
void takeChildAt( int );
PLItem *child( int row ) { return children.value( row ); }
PLItem *child( int row ) const { return children.value( row ); }
int childCount() const { return children.count(); }
PLItem *parent() { return parentItem; }
input_item_t *inputItem() { return p_input; }
input_item_t *inputItem() const { return p_input; }
int id() { return i_id; }
bool operator< ( PLItem& );
......
......@@ -66,9 +66,8 @@ PLModel::PLModel( playlist_t *_p_playlist, /* THEPL */
intf_thread_t *_p_intf, /* main Qt p_intf */
playlist_item_t * p_root,
QObject *parent ) /* Basic Qt parent */
: QAbstractItemModel( parent )
: VLCModel( _p_intf, parent )
{
p_intf = _p_intf;
p_playlist = _p_playlist;
i_cached_id = -1;
i_cached_input_id = -1;
......@@ -338,6 +337,21 @@ QVariant PLModel::data( const QModelIndex &index, const int role ) const
QString returninfo;
if( metadata == COLUMN_NUMBER )
returninfo = QString::number( index.row() + 1 );
else if( metadata == COLUMN_COVER )
{
QString artUrl;
artUrl = InputManager::decodeArtURL( item->inputItem() );
if( artUrl.isEmpty() )
{
for( int i = 0; i < item->childCount(); i++ )
{
artUrl = InputManager::decodeArtURL( item->child( i )->inputItem() );
if( !artUrl.isEmpty() )
break;
}
}
return QVariant( artUrl );
}
else
{
char *psz = psz_column_meta( item->p_input, metadata );
......@@ -558,34 +572,6 @@ PLItem * PLModel::findInner( PLItem *root, int i_id, bool b_input ) const
return NULL;
}
int PLModel::columnToMeta( int _column )
{
int meta = 1;
int column = 0;
while( column != _column && meta != COLUMN_END )
{
meta <<= 1;
column++;
}
return meta;
}
int PLModel::columnFromMeta( int meta_col )
{
int meta = 1;
int column = 0;
while( meta != meta_col && meta != COLUMN_END )
{
meta <<= 1;
column++;
}
return column;
}
bool PLModel::canEdit() const
{
return (
......@@ -601,11 +587,12 @@ bool PLModel::canEdit() const
QString PLModel::getMeta( const QModelIndex & index, int meta )
{
return index.model()->index( index.row(),
PLModel::columnFromMeta( meta ),
index.parent() )
.data().toString();
columnFromMeta( meta ),
index.parent() )
.data().toString();
}
QPixmap PLModel::getArtPixmap( const QModelIndex & index, const QSize & size )
{
PLItem *item = static_cast<PLItem*>( index.internalPointer() );
......
......@@ -29,13 +29,14 @@
# include "config.h"
#endif
#include "qt4.hpp"
#include <vlc_input.h>
#include <vlc_playlist.h>
#include "vlc_model.hpp"
#include "playlist_item.hpp"
#include <QObject>
#include <QEvent>
#include <QSignalMapper>
#include <QMimeData>
#include <QAbstractItemModel>
#include <QVariant>
......@@ -46,20 +47,14 @@ class PLSelector;
class PlMimeData;
class QSignalMapper;
class PLModel : public QAbstractItemModel
class PLModel : public VLCModel
{
Q_OBJECT
public:
enum {
IsCurrentRole = Qt::UserRole,
IsLeafNodeRole,
IsCurrentsParentNodeRole
};
PLModel( playlist_t *, intf_thread_t *,
playlist_item_t *, QObject *parent = 0 );
~PLModel();
virtual ~PLModel();
/*** QModel subclassing ***/
......@@ -86,18 +81,16 @@ public:
QStringList selectedURIs();
QModelIndex index( PLItem *, const int c ) const;
QModelIndex index( const int i_id, const int c );
QModelIndex currentIndex() const;
virtual QModelIndex currentIndex() const;
bool isParent( const QModelIndex &index, const QModelIndex &current) const;
bool isCurrent( const QModelIndex &index ) const;
int itemId( const QModelIndex &index ) const;
static int columnFromMeta( int meta_column );
static int columnToMeta( int column );
static QString getMeta( const QModelIndex & index, int meta );
static QPixmap getArtPixmap( const QModelIndex & index, const QSize & size );
static QString getMeta( const QModelIndex & index, int meta );
/* Actions */
bool popup( const QModelIndex & index, const QPoint &point, const QModelIndexList &list );
virtual bool popup( const QModelIndex & index, const QPoint &point, const QModelIndexList &list );
void doDelete( QModelIndexList selected );
void search( const QString& search_text, const QModelIndex & root, bool b_recursive );
void sort( const int column, Qt::SortOrder order );
......@@ -111,13 +104,17 @@ public:
return static_cast<PLItem*>( index.internalPointer() );
else return rootItem;
}
virtual int getId( QModelIndex index ) const
{
return getItem( index )->id();
}
signals:
void currentChanged( const QModelIndex& );
void rootChanged();
public slots:
void activateItem( const QModelIndex &index );
virtual void activateItem( const QModelIndex &index );
void activateItem( playlist_item_t *p_item );
private:
......@@ -125,7 +122,6 @@ private:
PLItem *rootItem;
playlist_t *p_playlist;
intf_thread_t *p_intf;
static QIcon icons[ITEM_TYPE_NUMBER];
......
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