Commit 596ccd76 authored by Clément Stenac's avatar Clément Stenac

Some more Qt playlist code

parent f2627995
...@@ -46,7 +46,7 @@ class StandardPLPanel: public PLPanel ...@@ -46,7 +46,7 @@ class StandardPLPanel: public PLPanel
{ {
Q_OBJECT; Q_OBJECT;
public: public:
StandardPLPanel( QWidget *, intf_thread_t *, playlist_item_t * ); StandardPLPanel( QWidget *, intf_thread_t *, playlist_t *,playlist_item_t * );
virtual ~StandardPLPanel(); virtual ~StandardPLPanel();
}; };
......
...@@ -26,13 +26,16 @@ ...@@ -26,13 +26,16 @@
#include <QTreeView> #include <QTreeView>
StandardPLPanel::StandardPLPanel( QWidget *_parent, intf_thread_t *_p_intf, StandardPLPanel::StandardPLPanel( QWidget *_parent, intf_thread_t *_p_intf,
playlist_t *p_playlist,
playlist_item_t *p_root ): playlist_item_t *p_root ):
PLPanel( _parent, _p_intf ) PLPanel( _parent, _p_intf )
{ {
PLModel *model = new PLModel( p_root, -1, this ); PLModel *model = new PLModel( p_playlist, p_root, -1, this );
QTreeView *view = new QTreeView( this ); QTreeView *view = new QTreeView( 0 );
view->setModel(model); view->setModel(model);
model->Rebuild();
view->show();
} }
StandardPLPanel::~StandardPLPanel() StandardPLPanel::~StandardPLPanel()
......
...@@ -31,7 +31,7 @@ PlaylistDialog::PlaylistDialog( intf_thread_t *_p_intf ) : QVLCFrame( _p_intf ) ...@@ -31,7 +31,7 @@ PlaylistDialog::PlaylistDialog( intf_thread_t *_p_intf ) : QVLCFrame( _p_intf )
{ {
playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf, playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf,
VLC_OBJECT_PLAYLIST, FIND_ANYWHERE ); VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
new StandardPLPanel( this, p_intf, p_playlist->p_root_category ); new StandardPLPanel( this, p_intf, p_playlist, p_playlist->p_root_category );
} }
PlaylistDialog::~PlaylistDialog() PlaylistDialog::~PlaylistDialog()
......
...@@ -37,7 +37,6 @@ public: ...@@ -37,7 +37,6 @@ public:
virtual ~PlaylistDialog(); virtual ~PlaylistDialog();
private: private:
PlaylistDialog( intf_thread_t * ); PlaylistDialog( intf_thread_t * );
intf_thread_t *p_intf;
static PlaylistDialog *instance; static PlaylistDialog *instance;
public slots: public slots:
}; };
......
...@@ -42,19 +42,31 @@ static int ItemDeleted( vlc_object_t *p_this, const char *psz_variable, ...@@ -42,19 +42,31 @@ static int ItemDeleted( vlc_object_t *p_this, const char *psz_variable,
* Playlist item implementation * Playlist item implementation
*************************************************************************/ *************************************************************************/
PLItem::PLItem( int _i_id, int _i_input_id, PLItem *parent, PLModel *m) /**
* Column strings
* Title
* Artist
* Duration
*/
void PLItem::init( int _i_id, int _i_input_id, PLItem *parent, PLModel *m)
{ {
parentItem = parent; parentItem = parent;
i_id = _i_id; i_input_id = _i_input_id; i_id = _i_id; i_input_id = _i_input_id;
model = m; model = m;
strings.append( "" );
strings.append( "" );
strings.append( "" );
}
PLItem::PLItem( int _i_id, int _i_input_id, PLItem *parent, PLModel *m)
{
init( _i_id, _i_input_id, parent, m );
} }
PLItem::PLItem( playlist_item_t * p_item, PLItem *parent, PLModel *m ) PLItem::PLItem( playlist_item_t * p_item, PLItem *parent, PLModel *m )
{ {
i_id = p_item->i_id; init( p_item->i_id, p_item->p_input->i_id, parent, m );
i_input_id = p_item->p_input->i_id;
parentItem = parent;
model = m;
} }
PLItem::~PLItem() PLItem::~PLItem()
...@@ -65,6 +77,7 @@ PLItem::~PLItem() ...@@ -65,6 +77,7 @@ PLItem::~PLItem()
void PLItem::insertChild( PLItem *item, int i_pos, bool signal ) void PLItem::insertChild( PLItem *item, int i_pos, bool signal )
{ {
assert( model ); assert( model );
fprintf( stderr, "Inserting child \n" );
if( signal ) if( signal )
model->beginInsertRows( model->index( this , 0 ), i_pos, i_pos ); model->beginInsertRows( model->index( this , 0 ), i_pos, i_pos );
children.append( item ); children.append( item );
...@@ -79,16 +92,24 @@ int PLItem::row() const ...@@ -79,16 +92,24 @@ int PLItem::row() const
return 0; return 0;
} }
void PLItem::update( playlist_item_t *p_item )
{
assert( p_item->p_input->i_id == i_input_id );
strings[0] = QString::fromUtf8( p_item->p_input->psz_name );
}
/************************************************************************* /*************************************************************************
* Playlist model implementation * Playlist model implementation
*************************************************************************/ *************************************************************************/
PLModel::PLModel( playlist_item_t * p_root, int i_depth, QObject *parent) PLModel::PLModel( playlist_t *_p_playlist,
playlist_item_t * p_root, int i_depth, QObject *parent)
: QAbstractItemModel(parent) : QAbstractItemModel(parent)
{ {
rootItem = new PLItem( p_root, NULL, this ); rootItem = NULL;
rootItem = new PLItem( p_root, NULL, this );
fprintf( stderr, "%i -> %i, %i -> %i", p_root->i_id, rootItem->i_id, p_root->p_input->i_id, rootItem->i_input_id );
p_playlist= _p_playlist;
i_items_to_append = 0; i_items_to_append = 0;
b_need_update = false; b_need_update = false;
i_cached_id = -1; i_cached_id = -1;
...@@ -275,6 +296,7 @@ PLItem * PLModel::FindInner( PLItem *root, int i_id, bool b_input ) ...@@ -275,6 +296,7 @@ PLItem * PLModel::FindInner( PLItem *root, int i_id, bool b_input )
return childFound; return childFound;
} }
} }
it++;
} }
return NULL; return NULL;
} }
...@@ -298,13 +320,15 @@ void PLModel::customEvent( QEvent *event ) ...@@ -298,13 +320,15 @@ void PLModel::customEvent( QEvent *event )
/**** Events processing ****/ /**** Events processing ****/
void PLModel::ProcessInputItemUpdate( int i_input_id ) void PLModel::ProcessInputItemUpdate( int i_input_id )
{ {
assert( i_input_id >= 0 ); if( i_input_id <= 0 ) return;
UpdateTreeItem( FindByInput( rootItem, i_input_id ), true ); PLItem *item = FindByInput( rootItem, i_input_id );
fprintf( stderr, "Updating %i -> %p \n", i_input_id, item );
UpdateTreeItem( item, true );
} }
void PLModel::ProcessItemRemoval( int i_id ) void PLModel::ProcessItemRemoval( int i_id )
{ {
assert( i_id >= 0 ); if( i_id <= 0 ) return;
if( i_id == i_cached_id ) i_cached_id = -1; if( i_id == i_cached_id ) i_cached_id = -1;
i_cached_input_id = -1; i_cached_input_id = -1;
...@@ -314,6 +338,7 @@ void PLModel::ProcessItemRemoval( int i_id ) ...@@ -314,6 +338,7 @@ void PLModel::ProcessItemRemoval( int i_id )
void PLModel::ProcessItemAppend( playlist_add_t *p_add ) void PLModel::ProcessItemAppend( playlist_add_t *p_add )
{ {
playlist_item_t *p_item = NULL; playlist_item_t *p_item = NULL;
PLItem *newItem = NULL;
i_items_to_append--; i_items_to_append--;
if( b_need_update ) return; if( b_need_update ) return;
...@@ -323,7 +348,9 @@ void PLModel::ProcessItemAppend( playlist_add_t *p_add ) ...@@ -323,7 +348,9 @@ void PLModel::ProcessItemAppend( playlist_add_t *p_add )
p_item = playlist_ItemGetById( p_playlist, p_add->i_item ); p_item = playlist_ItemGetById( p_playlist, p_add->i_item );
if( !p_item || p_item->i_flags & PLAYLIST_DBL_FLAG ) goto end; if( !p_item || p_item->i_flags & PLAYLIST_DBL_FLAG ) goto end;
nodeItem->appendChild( new PLItem( p_item, nodeItem, this ) ); newItem = new PLItem( p_item, nodeItem, this );
nodeItem->appendChild( newItem );
UpdateTreeItem( p_item, newItem, true );
end: end:
return; return;
...@@ -362,6 +389,7 @@ void PLModel::UpdateNodeChildren( playlist_item_t *p_node, PLItem *root ) ...@@ -362,6 +389,7 @@ void PLModel::UpdateNodeChildren( playlist_item_t *p_node, PLItem *root )
for( int i = 0; i < p_node->i_children ; i++ ) for( int i = 0; i < p_node->i_children ; i++ )
{ {
PLItem *newItem = new PLItem( p_node->pp_children[i], root, this ); PLItem *newItem = new PLItem( p_node->pp_children[i], root, this );
fprintf( stderr, "New %p\n", newItem );
root->appendChild( newItem, false ); root->appendChild( newItem, false );
UpdateTreeItem( newItem, false ); UpdateTreeItem( newItem, false );
if( p_node->pp_children[i]->i_children != -1 ) if( p_node->pp_children[i]->i_children != -1 )
...@@ -371,13 +399,15 @@ void PLModel::UpdateNodeChildren( playlist_item_t *p_node, PLItem *root ) ...@@ -371,13 +399,15 @@ void PLModel::UpdateNodeChildren( playlist_item_t *p_node, PLItem *root )
void PLModel::UpdateTreeItem( PLItem *item, bool signal ) void PLModel::UpdateTreeItem( PLItem *item, bool signal )
{ {
playlist_item_t *p_item = playlist_ItemGetById( p_playlist, rootItem->i_id ); playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id );
UpdateTreeItem( p_item, item, signal ); UpdateTreeItem( p_item, item, signal );
} }
void PLModel::UpdateTreeItem( playlist_item_t *p_item, PLItem *item, bool signal ) void PLModel::UpdateTreeItem( playlist_item_t *p_item, PLItem *item, bool signal )
{ {
/// \todo /// \todo
fprintf( stderr, "Updating item %s\n", p_item->p_input->psz_name );
item->update( p_item );
if( signal ) if( signal )
{ // emit { // emit
} }
......
...@@ -50,12 +50,15 @@ public: ...@@ -50,12 +50,15 @@ public:
int childCount() const { return children.count(); }; int childCount() const { return children.count(); };
QString columnString( int col ) { return strings.value( col ); }; QString columnString( int col ) { return strings.value( col ); };
PLItem *parent() { return parentItem; }; PLItem *parent() { return parentItem; };
void update( playlist_item_t *);
protected: protected:
QList<PLItem*> children; QList<PLItem*> children;
int i_id; int i_id;
int i_input_id; int i_input_id;
friend class PLModel; friend class PLModel;
private: private:
void init( int, int, PLItem *, PLModel * );
QList<QString> strings; QList<QString> strings;
PLItem *parentItem; PLItem *parentItem;
...@@ -89,7 +92,7 @@ class PLModel : public QAbstractItemModel ...@@ -89,7 +92,7 @@ class PLModel : public QAbstractItemModel
Q_OBJECT Q_OBJECT
public: public:
PLModel( playlist_item_t *, int, QObject *parent = 0); PLModel( playlist_t *, playlist_item_t *, int, QObject *parent = 0);
~PLModel(); ~PLModel();
void customEvent( QEvent * ); void customEvent( QEvent * );
...@@ -110,6 +113,7 @@ public: ...@@ -110,6 +113,7 @@ public:
bool b_need_update; bool b_need_update;
int i_items_to_append; int i_items_to_append;
void Rebuild();
private: private:
void addCallbacks(); void addCallbacks();
void delCallbacks(); void delCallbacks();
...@@ -118,7 +122,6 @@ private: ...@@ -118,7 +122,6 @@ private:
playlist_t *p_playlist; playlist_t *p_playlist;
/* Update processing */ /* Update processing */
void Rebuild();
void ProcessInputItemUpdate( int i_input_id ); void ProcessInputItemUpdate( int i_input_id );
void ProcessItemRemoval( int i_id ); void ProcessItemRemoval( int i_id );
void ProcessItemAppend( playlist_add_t *p_add ); void ProcessItemAppend( playlist_add_t *p_add );
......
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