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

Qt/ML: Extend Playlist model from VLCModel

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