Commit 5b6e15db authored by Clément Stenac's avatar Clément Stenac

Qt4 playlist dialog base stuff

parent f8663297
...@@ -28,6 +28,13 @@ ...@@ -28,6 +28,13 @@
#include <QWidget> #include <QWidget>
#include <QString> #include <QString>
class QTreeView;
class PLModel;
/**
* \todo Share a single model between views using a filterproxy
*/
class PLPanel: public QWidget class PLPanel: public QWidget
{ {
Q_OBJECT; Q_OBJECT;
...@@ -37,8 +44,10 @@ public: ...@@ -37,8 +44,10 @@ public:
p_intf = _p_intf; p_intf = _p_intf;
} }
virtual ~PLPanel() {}; virtual ~PLPanel() {};
private: protected:
intf_thread_t *p_intf; intf_thread_t *p_intf;
public slots:
virtual void setRoot( int ) = 0;
}; };
...@@ -46,8 +55,14 @@ class StandardPLPanel: public PLPanel ...@@ -46,8 +55,14 @@ class StandardPLPanel: public PLPanel
{ {
Q_OBJECT; Q_OBJECT;
public: public:
StandardPLPanel( QWidget *, intf_thread_t *, playlist_t *,playlist_item_t * ); StandardPLPanel( QWidget *, intf_thread_t *,
playlist_t *,playlist_item_t * );
virtual ~StandardPLPanel(); virtual ~StandardPLPanel();
private:
PLModel *model;
QTreeView *view;
public slots:
virtual void setRoot( int );
}; };
#endif #endif
...@@ -22,13 +22,38 @@ ...@@ -22,13 +22,38 @@
*****************************************************************************/ *****************************************************************************/
#include "components/playlist/selector.hpp" #include "components/playlist/selector.hpp"
#include "qt4.hpp"
#include <QVBoxLayout>
#include <QHeaderView>
#include <QTreeView>
PLSelector::PLSelector( QWidget *p, intf_thread_t *_p_intf ) : QWidget( p ) PLSelector::PLSelector( QWidget *p, intf_thread_t *_p_intf,
playlist_t *p_playlist ) : QWidget( p ), p_intf(_p_intf)
{ {
p_intf = _p_intf; model = new PLModel( THEPL, THEPL->p_root_category, 1, this );
model->Rebuild();
view = new QTreeView( 0 );
view->setIndentation( 0 );
view->header()->hide();
view->setModel( model );
connect( view, SIGNAL( activated( const QModelIndex& ) ),
this, SLOT( setSource( const QModelIndex& ) ) );
connect( view, SIGNAL( clicked( const QModelIndex& ) ),
this, SLOT( setSource( const QModelIndex& ) ) );
QVBoxLayout *layout = new QVBoxLayout();
layout->setSpacing( 0 ); layout->setMargin( 0 );
layout->addWidget( view );
setLayout( layout );
}
void PLSelector::setSource( const QModelIndex &index )
{
if( model )
emit activated( model->itemId( index ) );
} }
PLSelector::~PLSelector() PLSelector::~PLSelector()
{ {
} }
...@@ -27,15 +27,24 @@ ...@@ -27,15 +27,24 @@
#include <vlc/vlc.h> #include <vlc/vlc.h>
#include <QWidget> #include <QWidget>
#include <QString> #include <QString>
#include <playlist_model.hpp>
class QTreeView;
class PLSelector: public QWidget class PLSelector: public QWidget
{ {
Q_OBJECT; Q_OBJECT;
public: public:
PLSelector( QWidget *p, intf_thread_t *_p_intf ); PLSelector( QWidget *p, intf_thread_t *_p_intf, playlist_t * );
virtual ~PLSelector(); virtual ~PLSelector();
private: private:
intf_thread_t *p_intf; intf_thread_t *p_intf;
PLModel *model;
QTreeView *view;
private slots:
void setSource( const QModelIndex& );
signals:
void activated( int );
}; };
#endif #endif
...@@ -24,15 +24,36 @@ ...@@ -24,15 +24,36 @@
#include "playlist_model.hpp" #include "playlist_model.hpp"
#include "components/playlist/panels.hpp" #include "components/playlist/panels.hpp"
#include <QTreeView> #include <QTreeView>
#include <QVBoxLayout>
#include <QHeaderView>
#include "qt4.hpp"
#include <assert.h>
StandardPLPanel::StandardPLPanel( QWidget *_parent, intf_thread_t *_p_intf, StandardPLPanel::StandardPLPanel( QWidget *_parent, intf_thread_t *_p_intf,
playlist_t *p_playlist, 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_playlist, p_root, -1, this ); model = new PLModel( p_playlist, p_root, -1, this );
QTreeView *view = new QTreeView( this ); model->Rebuild();
view = new QTreeView( 0 );
view->setModel(model); view->setModel(model);
view->header()->resizeSection( 0, 300 );
connect( view, SIGNAL( activated( const QModelIndex& ) ), model,
SLOT( activateItem( const QModelIndex& ) ) );
QVBoxLayout *layout = new QVBoxLayout();
layout->setSpacing( 0 ); layout->setMargin( 0 );
layout->addWidget( view );
setLayout( layout );
}
void StandardPLPanel::setRoot( int i_root_id )
{
playlist_item_t *p_item = playlist_ItemGetById( THEPL, i_root_id );
assert( p_item );
model->rebuildRoot( p_item );
model->Rebuild(); model->Rebuild();
} }
......
...@@ -18,7 +18,8 @@ ...@@ -18,7 +18,8 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
******************************************************************************/
#include "dialogs/playlist.hpp" #include "dialogs/playlist.hpp"
#include "util/qvlcframe.hpp" #include "util/qvlcframe.hpp"
...@@ -32,17 +33,17 @@ PlaylistDialog *PlaylistDialog::instance = NULL; ...@@ -32,17 +33,17 @@ PlaylistDialog *PlaylistDialog::instance = NULL;
PlaylistDialog::PlaylistDialog( intf_thread_t *_p_intf ) : QVLCFrame( _p_intf ) PlaylistDialog::PlaylistDialog( intf_thread_t *_p_intf ) : QVLCFrame( _p_intf )
{ {
setWindowTitle( qtr( "Playlist" ) ); setWindowTitle( qtr( "Playlist" ) );
playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf, selector = new PLSelector( this, p_intf, THEPL );
VLC_OBJECT_PLAYLIST, FIND_ANYWHERE ); selector->setMaximumWidth( 150 );
QHBoxLayout *layout = new QHBoxLayout();
selector = new PLSelector( this, p_intf );
layout->addWidget( selector, 1 );
rightPanel = qobject_cast<PLPanel *>(new StandardPLPanel( this, p_intf, rightPanel = qobject_cast<PLPanel *>(new StandardPLPanel( this, p_intf,
p_playlist, p_playlist->p_root_category ) ); THEPL, THEPL->p_local_category ) );
layout->addWidget( rightPanel, 3 ); connect( selector, SIGNAL( activated( int ) ), rightPanel, SLOT( setRoot( int ) ) );
readSettings( "playlist", QSize( 500,500 ) );
QHBoxLayout *layout = new QHBoxLayout();
layout->addWidget( selector, 0 );
layout->addWidget( rightPanel, 10 );
readSettings( "playlist", QSize( 600,300 ) );
setLayout( layout ); setLayout( layout );
} }
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#ifndef _PLAYLIST_DIALOG_H_ #ifndef _PLAYLIST_DIALOG_H_
#define _PLAYLIST_DIALOG_H_ #define _PLAYLIST_DIALOG_H_
#include <QModelIndex>
#include "util/qvlcframe.hpp" #include "util/qvlcframe.hpp"
class PLSelector; class PLSelector;
...@@ -44,7 +45,6 @@ private: ...@@ -44,7 +45,6 @@ private:
PLSelector *selector; PLSelector *selector;
PLPanel *rightPanel; PLPanel *rightPanel;
public slots:
}; };
......
...@@ -82,6 +82,7 @@ void DialogsProvider::customEvent( QEvent *event ) ...@@ -82,6 +82,7 @@ void DialogsProvider::customEvent( QEvent *event )
doInteraction( de->p_arg ); break; doInteraction( de->p_arg ); break;
case INTF_DIALOG_VLM: case INTF_DIALOG_VLM:
case INTF_DIALOG_BOOKMARKS: case INTF_DIALOG_BOOKMARKS:
bookmarksDialog(); break;
case INTF_DIALOG_WIZARD: case INTF_DIALOG_WIZARD:
default: default:
msg_Warn( p_intf, "unimplemented dialog\n" ); msg_Warn( p_intf, "unimplemented dialog\n" );
......
/***************************************************************************** /*****************************************************************************
* input_manager.cpp : Manage an input and interact with its GUI elements * playlist_model.cpp : Manage playlist model
**************************************************************************** ****************************************************************************
* Copyright (C) 2006 the VideoLAN team * Copyright (C) 2006 the VideoLAN team
* $Id$ * $Id$
...@@ -21,11 +21,11 @@ ...@@ -21,11 +21,11 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/ *****************************************************************************/
#include "qt4.hpp"
#include <QApplication> #include <QApplication>
#include "playlist_model.hpp" #include "playlist_model.hpp"
#include <assert.h> #include <assert.h>
static int PlaylistChanged( vlc_object_t *, const char *, static int PlaylistChanged( vlc_object_t *, const char *,
vlc_value_t, vlc_value_t, void * ); vlc_value_t, vlc_value_t, void * );
static int PlaylistNext( vlc_object_t *, const char *, static int PlaylistNext( vlc_object_t *, const char *,
...@@ -36,7 +36,6 @@ static int ItemAppended( vlc_object_t *p_this, const char *psz_variable, ...@@ -36,7 +36,6 @@ static int ItemAppended( vlc_object_t *p_this, const char *psz_variable,
vlc_value_t oval, vlc_value_t nval, void *param ); vlc_value_t oval, vlc_value_t nval, void *param );
static int ItemDeleted( vlc_object_t *p_this, const char *psz_variable, static int ItemDeleted( vlc_object_t *p_this, const char *psz_variable,
vlc_value_t oval, vlc_value_t nval, void *param ); vlc_value_t oval, vlc_value_t nval, void *param );
/************************************************************************* /*************************************************************************
* Playlist item implementation * Playlist item implementation
...@@ -54,9 +53,9 @@ void PLItem::init( int _i_id, int _i_input_id, PLItem *parent, PLModel *m) ...@@ -54,9 +53,9 @@ 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( "" ); strings.append( "" );
strings.append( "" ); strings.append( "" );
} }
PLItem::PLItem( int _i_id, int _i_input_id, PLItem *parent, PLModel *m) PLItem::PLItem( int _i_id, int _i_input_id, PLItem *parent, PLModel *m)
...@@ -77,7 +76,6 @@ PLItem::~PLItem() ...@@ -77,7 +76,6 @@ 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 );
...@@ -96,6 +94,10 @@ void PLItem::update( playlist_item_t *p_item ) ...@@ -96,6 +94,10 @@ void PLItem::update( playlist_item_t *p_item )
{ {
assert( p_item->p_input->i_id == i_input_id ); assert( p_item->p_input->i_id == i_input_id );
strings[0] = QString::fromUtf8( p_item->p_input->psz_name ); strings[0] = QString::fromUtf8( p_item->p_input->psz_name );
if( p_item->p_input->p_meta )
{
strings[1] = QString::fromUtf8( p_item->p_input->p_meta->psz_artist );
}
} }
/************************************************************************* /*************************************************************************
...@@ -103,21 +105,30 @@ void PLItem::update( playlist_item_t *p_item ) ...@@ -103,21 +105,30 @@ void PLItem::update( playlist_item_t *p_item )
*************************************************************************/ *************************************************************************/
PLModel::PLModel( playlist_t *_p_playlist, PLModel::PLModel( playlist_t *_p_playlist,
playlist_item_t * p_root, int i_depth, QObject *parent) playlist_item_t * p_root, int _i_depth, QObject *parent)
: QAbstractItemModel(parent) : QAbstractItemModel(parent)
{ {
rootItem = NULL; i_depth = _i_depth;
rootItem = new PLItem( p_root, NULL, this ); assert( i_depth == 1 || i_depth == -1 );
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; 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;
i_cached_input_id = -1; i_cached_input_id = -1;
rootItem = NULL;
rebuildRoot( p_root );
addCallbacks(); addCallbacks();
} }
void PLModel::rebuildRoot( playlist_item_t *p_root )
{
if( rootItem ) delete rootItem;
rootItem = new PLItem( p_root, NULL, this );
rootItem->strings[0] = qtr("Name");
rootItem->strings[1] = qtr("Artist");
}
PLModel::~PLModel() PLModel::~PLModel()
{ {
delCallbacks(); delCallbacks();
...@@ -145,24 +156,43 @@ void PLModel::delCallbacks() ...@@ -145,24 +156,43 @@ void PLModel::delCallbacks()
var_DelCallback( p_playlist, "item-deleted", ItemDeleted, this ); var_DelCallback( p_playlist, "item-deleted", ItemDeleted, this );
} }
/****************** Base model mandatory implementations *****************/ void PLModel::activateItem( const QModelIndex &index )
{
assert( index.isValid() );
PLItem *item = static_cast<PLItem*>(index.internalPointer());
assert( item );
PL_LOCK;
playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id );
playlist_item_t *p_parent = p_item;
while( p_parent )
{
if( p_parent->i_id == rootItem->i_id ) break;
p_parent = p_parent->p_parent;
}
if( p_parent )
{
playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, p_parent, p_item );
}
PL_UNLOCK;
}
/****************** Base model mandatory implementations *****************/
QVariant PLModel::data(const QModelIndex &index, int role) const QVariant PLModel::data(const QModelIndex &index, int role) const
{ {
if (!index.isValid()) if ( !index.isValid() || role != Qt::DisplayRole ) return QVariant();
return QVariant();
if (role != Qt::DisplayRole)
return QVariant();
PLItem *item = static_cast<PLItem*>(index.internalPointer()); PLItem *item = static_cast<PLItem*>(index.internalPointer());
return QVariant( item->columnString( index.column() ) ); return QVariant( item->columnString( index.column() ) );
} }
Qt::ItemFlags PLModel::flags(const QModelIndex &index) const int PLModel::itemId( const QModelIndex &index ) const
{ {
if (!index.isValid()) assert( index.isValid() );
return Qt::ItemIsEnabled; return static_cast<PLItem*>(index.internalPointer())->i_id;
}
Qt::ItemFlags PLModel::flags(const QModelIndex &index) const
{
if( !index.isValid() ) return Qt::ItemIsEnabled;
return Qt::ItemIsEnabled | Qt::ItemIsSelectable; return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
} }
...@@ -191,7 +221,7 @@ QModelIndex PLModel::index(int row, int column, const QModelIndex &parent) ...@@ -191,7 +221,7 @@ QModelIndex PLModel::index(int row, int column, const QModelIndex &parent)
} }
/* Return the index of a given item */ /* Return the index of a given item */
QModelIndex PLModel::index( PLItem *item, int column ) const QModelIndex PLModel::index( PLItem *item, int column ) const
{ {
if( !item ) return QModelIndex(); if( !item ) return QModelIndex();
const PLItem *parent = item->parent(); const PLItem *parent = item->parent();
...@@ -202,21 +232,20 @@ QModelIndex PLModel::index( PLItem *item, int column ) const ...@@ -202,21 +232,20 @@ QModelIndex PLModel::index( PLItem *item, int column ) const
QModelIndex PLModel::parent(const QModelIndex &index) const QModelIndex PLModel::parent(const QModelIndex &index) const
{ {
if (!index.isValid()) if (!index.isValid()) return QModelIndex();
return QModelIndex();
PLItem *childItem = static_cast<PLItem*>(index.internalPointer()); PLItem *childItem = static_cast<PLItem*>(index.internalPointer());
PLItem *parentItem = childItem->parent(); PLItem *parentItem = childItem->parent();
if (parentItem == rootItem) if (parentItem == rootItem) return QModelIndex();
return QModelIndex();
return createIndex(parentItem->row(), 0, parentItem); return createIndex(parentItem->row(), 0, parentItem);
} }
int PLModel::columnCount( const QModelIndex &i) const int PLModel::columnCount( const QModelIndex &i) const
{ {
return 1; if( i_depth == 1 ) return 1;
return 2;
} }
int PLModel::childrenCount(const QModelIndex &parent) const int PLModel::childrenCount(const QModelIndex &parent) const
...@@ -253,7 +282,7 @@ PLItem *PLModel::FindByInput( PLItem *root, int i_id ) ...@@ -253,7 +282,7 @@ PLItem *PLModel::FindByInput( PLItem *root, int i_id )
PLItem * PLModel::FindInner( PLItem *root, int i_id, bool b_input ) PLItem * PLModel::FindInner( PLItem *root, int i_id, bool b_input )
{ {
if( ( !b_input && i_cached_id == i_id) || if( ( !b_input && i_cached_id == i_id) ||
( b_input && i_cached_input_id ==i_id ) ) ( b_input && i_cached_input_id ==i_id ) )
{ {
return b_input ? p_cached_item_bi : p_cached_item; return b_input ? p_cached_item_bi : p_cached_item;
...@@ -286,7 +315,7 @@ PLItem * PLModel::FindInner( PLItem *root, int i_id, bool b_input ) ...@@ -286,7 +315,7 @@ PLItem * PLModel::FindInner( PLItem *root, int i_id, bool b_input )
if( (*it)->children.size() ) if( (*it)->children.size() )
{ {
PLItem *childFound = FindInner( (*it), i_id, b_input ); PLItem *childFound = FindInner( (*it), i_id, b_input );
if( childFound ) if( childFound )
{ {
if( b_input ) if( b_input )
{ {
...@@ -297,11 +326,10 @@ PLItem * PLModel::FindInner( PLItem *root, int i_id, bool b_input ) ...@@ -297,11 +326,10 @@ PLItem * PLModel::FindInner( PLItem *root, int i_id, bool b_input )
CACHE( i_id, childFound ); CACHE( i_id, childFound );
} }
return childFound; return childFound;
} }
} }
it++; it++;
} }
fprintf( stderr, "Never found" );
return NULL; return NULL;
} }
#undef CACHE #undef CACHE
...@@ -331,8 +359,8 @@ void PLModel::ProcessInputItemUpdate( int i_input_id ) ...@@ -331,8 +359,8 @@ void PLModel::ProcessInputItemUpdate( int i_input_id )
{ {
if( i_input_id <= 0 ) return; if( i_input_id <= 0 ) return;
PLItem *item = FindByInput( rootItem, i_input_id ); PLItem *item = FindByInput( rootItem, i_input_id );
fprintf( stderr, "Updating %i -> %p \n", i_input_id, item ); if( item )
UpdateTreeItem( item, true ); UpdateTreeItem( item, true );
} }
void PLModel::ProcessItemRemoval( int i_id ) void PLModel::ProcessItemRemoval( int i_id )
...@@ -357,10 +385,19 @@ void PLModel::ProcessItemAppend( playlist_add_t *p_add ) ...@@ -357,10 +385,19 @@ 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;
fprintf( stderr, "Appending item %s - parent %i (root %i)\n",
p_item->p_input->psz_name, p_item->p_parent->i_id,
rootItem->i_id );
if( i_depth == 1 && p_item->p_parent &&
p_item->p_parent->i_id != rootItem->i_id )
goto end;
fprintf( stderr, "Still continuing\n" );
newItem = new PLItem( p_item, nodeItem, this ); newItem = new PLItem( p_item, nodeItem, this );
nodeItem->appendChild( newItem ); nodeItem->appendChild( newItem );
fprintf( stderr, "duh\n" );
UpdateTreeItem( p_item, newItem, true ); UpdateTreeItem( p_item, newItem, true );
end: end:
return; return;
} }
...@@ -398,32 +435,33 @@ void PLModel::UpdateNodeChildren( playlist_item_t *p_node, PLItem *root ) ...@@ -398,32 +435,33 @@ 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, true );
if( p_node->pp_children[i]->i_children != -1 ) if( i_depth != 1 && p_node->pp_children[i]->i_children != -1 )
UpdateNodeChildren( p_node->pp_children[i], newItem ); UpdateNodeChildren( p_node->pp_children[i], newItem );
} }
} }
void PLModel::UpdateTreeItem( PLItem *item, bool signal ) void PLModel::UpdateTreeItem( PLItem *item, bool signal, bool force )
{ {
playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id ); playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id );
UpdateTreeItem( p_item, item, signal ); UpdateTreeItem( p_item, item, signal, force );
} }
void PLModel::UpdateTreeItem( playlist_item_t *p_item, PLItem *item, bool signal ) void PLModel::UpdateTreeItem( playlist_item_t *p_item, PLItem *item,
bool signal, bool force )
{ {
/// \todo if( !force && i_depth == 1 && p_item->p_parent &&
fprintf( stderr, "Updating item %s\n", p_item->p_input->psz_name ); p_item->p_parent->i_id == rootItem->i_id )
return;
item->update( p_item ); item->update( p_item );
if( signal ) if( signal )
{ // emit { // emit
} }
} }
/********************************************************************** /**********************************************************************
* Playlist callbacks * Playlist callbacks
**********************************************************************/ **********************************************************************/
static int PlaylistChanged( vlc_object_t *p_this, const char *psz_variable, static int PlaylistChanged( vlc_object_t *p_this, const char *psz_variable,
vlc_value_t oval, vlc_value_t nval, void *param ) vlc_value_t oval, vlc_value_t nval, void *param )
...@@ -448,7 +486,7 @@ static int ItemChanged( vlc_object_t *p_this, const char *psz_variable, ...@@ -448,7 +486,7 @@ static int ItemChanged( vlc_object_t *p_this, const char *psz_variable,
vlc_value_t oval, vlc_value_t nval, void *param ) vlc_value_t oval, vlc_value_t nval, void *param )
{ {
PLModel *p_model = (PLModel *) param; PLModel *p_model = (PLModel *) param;
PLEvent *event = new PLEvent( ItemUpdate_Type, nval.i_int ); PLEvent *event = new PLEvent( ItemUpdate_Type, nval.i_int );
QApplication::postEvent( p_model, static_cast<QEvent*>(event) ); QApplication::postEvent( p_model, static_cast<QEvent*>(event) );
return VLC_SUCCESS; return VLC_SUCCESS;
} }
...@@ -476,5 +514,6 @@ static int ItemAppended( vlc_object_t *p_this, const char *psz_variable, ...@@ -476,5 +514,6 @@ static int ItemAppended( vlc_object_t *p_this, const char *psz_variable,
} }
PLEvent *event = new PLEvent( p_add ); PLEvent *event = new PLEvent( p_add );
QApplication::postEvent( p_model, static_cast<QEvent*>(event) ); QApplication::postEvent( p_model, static_cast<QEvent*>(event) );
fprintf( stderr, "Posted event to model\n" );
return VLC_SUCCESS; return VLC_SUCCESS;
} }
...@@ -42,7 +42,7 @@ public: ...@@ -42,7 +42,7 @@ public:
int row() const; int row() const;
void insertChild( PLItem *, int p, bool signal = true ); void insertChild( PLItem *, int p, bool signal = true );
void appendChild( PLItem *item, bool signal = true ) void appendChild( PLItem *item, bool signal = true )
{ {
insertChild( item, children.count(), signal ); insertChild( item, children.count(), signal );
}; };
...@@ -54,14 +54,13 @@ public: ...@@ -54,14 +54,13 @@ public:
void update( playlist_item_t *); void update( playlist_item_t *);
protected: protected:
QList<PLItem*> children; QList<PLItem*> children;
QList<QString> strings;
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 * ); void init( int, int, PLItem *, PLModel * );
QList<QString> strings;
PLItem *parentItem; PLItem *parentItem;
PLModel *model; PLModel *model;
}; };
...@@ -77,11 +76,10 @@ public: ...@@ -77,11 +76,10 @@ public:
PLEvent( playlist_add_t *a ) : QEvent( (QEvent::Type)(ItemAppend_Type) ) PLEvent( playlist_add_t *a ) : QEvent( (QEvent::Type)(ItemAppend_Type) )
{ p_add = a; }; { p_add = a; };
virtual ~PLEvent() {}; virtual ~PLEvent() {};
int i_id; int i_id;
playlist_add_t *p_add; playlist_add_t *p_add;
}; };
#include <QAbstractItemModel> #include <QAbstractItemModel>
#include <QModelIndex> #include <QModelIndex>
...@@ -102,10 +100,11 @@ public: ...@@ -102,10 +100,11 @@ public:
Qt::ItemFlags flags( const QModelIndex &index) const; Qt::ItemFlags flags( const QModelIndex &index) const;
QVariant headerData( int section, Qt::Orientation orientation, QVariant headerData( int section, Qt::Orientation orientation,
int role = Qt::DisplayRole) const; int role = Qt::DisplayRole) const;
QModelIndex index( int r, int c, const QModelIndex &parent ) const; QModelIndex index( int r, int c, const QModelIndex &parent ) const;
QModelIndex index( PLItem *, int c ) const; QModelIndex index( PLItem *, int c ) const;
int itemId( const QModelIndex &index ) const;
QModelIndex parent( const QModelIndex &index) const; QModelIndex parent( const QModelIndex &index) const;
int childrenCount( const QModelIndex &parent = QModelIndex() ) const; int childrenCount( const QModelIndex &parent = QModelIndex() ) const;
int rowCount( const QModelIndex &parent = QModelIndex() ) const; int rowCount( const QModelIndex &parent = QModelIndex() ) const;
...@@ -114,23 +113,25 @@ public: ...@@ -114,23 +113,25 @@ public:
bool b_need_update; bool b_need_update;
int i_items_to_append; int i_items_to_append;
void Rebuild(); void Rebuild();
void rebuildRoot( playlist_item_t * );
private: private:
void addCallbacks(); void addCallbacks();
void delCallbacks(); void delCallbacks();
PLItem *rootItem; PLItem *rootItem;
playlist_t *p_playlist; playlist_t *p_playlist;
int i_depth;
/* Update processing */ /* Update processing */
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 );
void UpdateTreeItem( PLItem *, bool ); void UpdateTreeItem( PLItem *, bool, bool force = false );
void UpdateTreeItem( playlist_item_t *, PLItem *, bool ); void UpdateTreeItem( playlist_item_t *, PLItem *, bool, bool forc = false );
void UpdateNodeChildren( PLItem * ); void UpdateNodeChildren( PLItem * );
void UpdateNodeChildren( playlist_item_t *, PLItem * ); void UpdateNodeChildren( playlist_item_t *, PLItem * );
/* Lookups */ /* Lookups */
PLItem *FindById( PLItem *, int ); PLItem *FindById( PLItem *, int );
PLItem *FindByInput( PLItem *, int ); PLItem *FindByInput( PLItem *, int );
...@@ -139,7 +140,8 @@ private: ...@@ -139,7 +140,8 @@ private:
PLItem *p_cached_item_bi; PLItem *p_cached_item_bi;
int i_cached_id; int i_cached_id;
int i_cached_input_id; int i_cached_input_id;
public slots:
void activateItem( const QModelIndex &index );
friend class PLItem; friend class PLItem;
}; };
......
...@@ -71,7 +71,7 @@ static int Open( vlc_object_t *p_this ) ...@@ -71,7 +71,7 @@ static int Open( vlc_object_t *p_this )
VLC_OBJECT_PLAYLIST, FIND_ANYWHERE ); VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
if( !p_intf->p_sys->p_playlist ) if( !p_intf->p_sys->p_playlist )
return VLC_EGENERIC; return VLC_EGENERIC;
p_intf->p_sys->p_sub = msg_Subscribe( p_intf, MSG_QUEUE_NORMAL ); p_intf->p_sys->p_sub = msg_Subscribe( p_intf, MSG_QUEUE_NORMAL );
return VLC_SUCCESS; return VLC_SUCCESS;
......
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