Commit f2627995 authored by Clément Stenac's avatar Clément Stenac

Some more playlist code

Fix makefile
parent 9c00cdd9
...@@ -17,7 +17,7 @@ UIH = $(TOUI:%=%.h) ...@@ -17,7 +17,7 @@ UIH = $(TOUI:%=%.h)
TOMOC = main_interface \ TOMOC = main_interface \
dialogs_provider \ dialogs_provider \
input_manager \ input_manager \
playlist_model playlist_model \
dialogs/playlist \ dialogs/playlist \
dialogs/prefs_dialog \ dialogs/prefs_dialog \
dialogs/streaminfo \ dialogs/streaminfo \
...@@ -25,6 +25,7 @@ TOMOC = main_interface \ ...@@ -25,6 +25,7 @@ TOMOC = main_interface \
components/preferences_widgets \ components/preferences_widgets \
components/preferences \ components/preferences \
components/open \ components/open \
components/playlist/panels \
util/input_slider util/input_slider
MOCCPP = $(TOMOC:%=%.moc.cpp) MOCCPP = $(TOMOC:%=%.moc.cpp)
...@@ -32,7 +33,7 @@ nodist_SOURCES_qt4 = \ ...@@ -32,7 +33,7 @@ nodist_SOURCES_qt4 = \
main_interface.moc.cpp \ main_interface.moc.cpp \
dialogs_provider.moc.cpp \ dialogs_provider.moc.cpp \
input_manager.moc.cpp \ input_manager.moc.cpp \
playlist_model.moc.cpp \ playlist_model.moc.cpp \
dialogs/playlist.moc.cpp \ dialogs/playlist.moc.cpp \
dialogs/streaminfo.moc.cpp \ dialogs/streaminfo.moc.cpp \
dialogs/prefs_dialog.moc.cpp \ dialogs/prefs_dialog.moc.cpp \
...@@ -40,6 +41,7 @@ nodist_SOURCES_qt4 = \ ...@@ -40,6 +41,7 @@ nodist_SOURCES_qt4 = \
components/preferences_widgets.moc.cpp \ components/preferences_widgets.moc.cpp \
components/preferences.moc.cpp \ components/preferences.moc.cpp \
components/open.moc.cpp \ components/open.moc.cpp \
components/playlist/panels.moc.cpp \
util/input_slider.moc.cpp util/input_slider.moc.cpp
if ENABLE_QT4 if ENABLE_QT4
...@@ -63,7 +65,7 @@ SOURCES_qt4 = qt4.cpp \ ...@@ -63,7 +65,7 @@ SOURCES_qt4 = qt4.cpp \
main_interface.cpp \ main_interface.cpp \
dialogs_provider.cpp \ dialogs_provider.cpp \
input_manager.cpp \ input_manager.cpp \
playlist_model.cpp \ playlist_model.cpp \
dialogs/playlist.cpp \ dialogs/playlist.cpp \
dialogs/prefs_dialog.cpp \ dialogs/prefs_dialog.cpp \
dialogs/streaminfo.cpp \ dialogs/streaminfo.cpp \
...@@ -71,6 +73,7 @@ SOURCES_qt4 = qt4.cpp \ ...@@ -71,6 +73,7 @@ SOURCES_qt4 = qt4.cpp \
components/preferences_widgets.cpp \ components/preferences_widgets.cpp \
components/preferences.cpp \ components/preferences.cpp \
components/open.cpp \ components/open.cpp \
components/playlist/standardpanel.cpp \
util/input_slider.cpp util/input_slider.cpp
$(NULL) $(NULL)
...@@ -79,7 +82,7 @@ EXTRA_DIST += \ ...@@ -79,7 +82,7 @@ EXTRA_DIST += \
main_interface.hpp \ main_interface.hpp \
dialogs_provider.hpp \ dialogs_provider.hpp \
input_manager.hpp \ input_manager.hpp \
playlist_model.hpp \ playlist_model.hpp \
dialogs/playlist.hpp \ dialogs/playlist.hpp \
dialogs/streaminfo.hpp \ dialogs/streaminfo.hpp \
dialogs/prefs_dialog.hpp \ dialogs/prefs_dialog.hpp \
...@@ -87,6 +90,7 @@ EXTRA_DIST += \ ...@@ -87,6 +90,7 @@ EXTRA_DIST += \
components/preferences_widgets.hpp \ components/preferences_widgets.hpp \
components/preferences.hpp \ components/preferences.hpp \
components/open.hpp \ components/open.hpp \
components/playlist/panels.hpp \
util/input_slider.hpp \ util/input_slider.hpp \
ui/input_stats.ui \ ui/input_stats.ui \
pixmaps/advanced.xpm \ pixmaps/advanced.xpm \
......
...@@ -36,7 +36,7 @@ public: ...@@ -36,7 +36,7 @@ public:
{ {
p_intf = _p_intf; p_intf = _p_intf;
} }
virtual ~PLPanel(); virtual ~PLPanel() {};
private: private:
intf_thread_t *p_intf; intf_thread_t *p_intf;
}; };
...@@ -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 * ); StandardPLPanel( QWidget *, intf_thread_t *, playlist_item_t * );
virtual ~StandardPLPanel(); virtual ~StandardPLPanel();
}; };
......
...@@ -21,14 +21,19 @@ ...@@ -21,14 +21,19 @@
* 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 "playlist_model.hpp"
#include "components/playlist/panels.hpp" #include "components/playlist/panels.hpp"
#include <QTreeView>
StandardPLPanel::StandardPLPanel( QWidget *_parent, intf_thread_t *_p_intf ): StandardPLPanel::StandardPLPanel( QWidget *_parent, intf_thread_t *_p_intf,
playlist_item_t *p_root ):
PLPanel( _parent, _p_intf ) PLPanel( _parent, _p_intf )
{ {
PLModel *model = new PLModel( p_root, -1, this );
QTreeView *view = new QTreeView( this );
view->setModel(model);
} }
StandardPLPanel::~StandardPLPanel() StandardPLPanel::~StandardPLPanel()
{} {}
#endif
...@@ -23,12 +23,15 @@ ...@@ -23,12 +23,15 @@
#include "dialogs/playlist.hpp" #include "dialogs/playlist.hpp"
#include "util/qvlcframe.hpp" #include "util/qvlcframe.hpp"
#include "qt4.hpp" #include "qt4.hpp"
#include "components/playlist/panels.hpp"
PlaylistDialog *PlaylistDialog::instance = NULL; PlaylistDialog *PlaylistDialog::instance = NULL;
PlaylistDialog::PlaylistDialog( intf_thread_t *_p_intf ) : QVLCFrame( p_intf ) PlaylistDialog::PlaylistDialog( intf_thread_t *_p_intf ) : QVLCFrame( _p_intf )
{ {
playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf,
VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
new StandardPLPanel( this, p_intf, p_playlist->p_root_category );
} }
PlaylistDialog::~PlaylistDialog() PlaylistDialog::~PlaylistDialog()
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
#include "main_interface.hpp" #include "main_interface.hpp"
#include "input_manager.hpp" #include "input_manager.hpp"
#include "util/input_slider.hpp" #include "util/input_slider.hpp"
#include "util/qvlcframe.hpp"> #include "util/qvlcframe.hpp"
#include "dialogs_provider.hpp" #include "dialogs_provider.hpp"
#include <QCloseEvent> #include <QCloseEvent>
#include <assert.h> #include <assert.h>
...@@ -66,6 +66,9 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QMainWindow(), p_intf( ...@@ -66,6 +66,9 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QMainWindow(), p_intf(
connect( ui.stopButton, SLOT( clicked() ), this, SLOT( stop() ) ); connect( ui.stopButton, SLOT( clicked() ), this, SLOT( stop() ) );
connect( ui.nextButton, SLOT( clicked() ), this, SLOT( next() ) ); connect( ui.nextButton, SLOT( clicked() ), this, SLOT( next() ) );
connect( ui.prevButton, SLOT( clicked() ), this, SLOT( prev() ) ); connect( ui.prevButton, SLOT( clicked() ), this, SLOT( prev() ) );
connect( ui.playlistButton, SLOT(clicked() ),
DialogsProvider::getInstance( p_intf ), SLOT( playlistDialog() ) );
} }
MainInterface::~MainInterface() MainInterface::~MainInterface()
......
...@@ -62,12 +62,14 @@ PLItem::~PLItem() ...@@ -62,12 +62,14 @@ PLItem::~PLItem()
qDeleteAll(children); qDeleteAll(children);
} }
void PLItem::insertChild( PLItem *item, int i_pos ) void PLItem::insertChild( PLItem *item, int i_pos, bool signal )
{ {
assert( model ); assert( model );
model->beginInsertRows( model->index( this , 0 ), i_pos, i_pos ); if( signal )
model->beginInsertRows( model->index( this , 0 ), i_pos, i_pos );
children.append( item ); children.append( item );
model->endInsertRows(); if( signal )
model->endInsertRows();
} }
int PLItem::row() const int PLItem::row() const
...@@ -92,6 +94,17 @@ PLModel::PLModel( playlist_item_t * p_root, int i_depth, QObject *parent) ...@@ -92,6 +94,17 @@ PLModel::PLModel( playlist_item_t * p_root, int i_depth, QObject *parent)
i_cached_id = -1; i_cached_id = -1;
i_cached_input_id = -1; i_cached_input_id = -1;
addCallbacks();
}
PLModel::~PLModel()
{
delCallbacks();
delete rootItem;
}
void PLModel::addCallbacks()
{
/* Some global changes happened -> Rebuild all */ /* Some global changes happened -> Rebuild all */
var_AddCallback( p_playlist, "intf-change", PlaylistChanged, this ); var_AddCallback( p_playlist, "intf-change", PlaylistChanged, this );
/* We went to the next item */ /* We went to the next item */
...@@ -102,17 +115,17 @@ PLModel::PLModel( playlist_item_t * p_root, int i_depth, QObject *parent) ...@@ -102,17 +115,17 @@ PLModel::PLModel( playlist_item_t * p_root, int i_depth, QObject *parent)
var_AddCallback( p_playlist, "item-deleted", ItemDeleted, this ); var_AddCallback( p_playlist, "item-deleted", ItemDeleted, this );
} }
PLModel::~PLModel() void PLModel::delCallbacks()
{ {
var_DelCallback( p_playlist, "item-change", ItemChanged, this ); var_DelCallback( p_playlist, "item-change", ItemChanged, this );
var_DelCallback( p_playlist, "playlist-current", PlaylistNext, this ); var_DelCallback( p_playlist, "playlist-current", PlaylistNext, this );
var_DelCallback( p_playlist, "intf-change", PlaylistChanged, this ); var_DelCallback( p_playlist, "intf-change", PlaylistChanged, this );
var_DelCallback( p_playlist, "item-append", ItemAppended, this ); var_DelCallback( p_playlist, "item-append", ItemAppended, this );
var_DelCallback( p_playlist, "item-deleted", ItemDeleted, this ); var_DelCallback( p_playlist, "item-deleted", ItemDeleted, this );
delete rootItem;
} }
/****************** Base model mandatory implementations *****************/ /****************** 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())
...@@ -180,7 +193,17 @@ QModelIndex PLModel::parent(const QModelIndex &index) const ...@@ -180,7 +193,17 @@ QModelIndex PLModel::parent(const QModelIndex &index) const
return createIndex(parentItem->row(), 0, parentItem); return createIndex(parentItem->row(), 0, parentItem);
} }
int PLModel::columnCount( const QModelIndex &i) const
{
return 1;
}
int PLModel::childrenCount(const QModelIndex &parent) const int PLModel::childrenCount(const QModelIndex &parent) const
{
return rowCount( parent );
}
int PLModel::rowCount(const QModelIndex &parent) const
{ {
PLItem *parentItem; PLItem *parentItem;
...@@ -272,10 +295,11 @@ void PLModel::customEvent( QEvent *event ) ...@@ -272,10 +295,11 @@ void PLModel::customEvent( QEvent *event )
ProcessItemRemoval( ple->i_id ); ProcessItemRemoval( ple->i_id );
} }
/**** Events processing ****/
void PLModel::ProcessInputItemUpdate( int i_input_id ) void PLModel::ProcessInputItemUpdate( int i_input_id )
{ {
assert( i_input_id >= 0 ); assert( i_input_id >= 0 );
/// \todo UpdateTreeItem( FindByInput( rootItem, i_input_id ), true );
} }
void PLModel::ProcessItemRemoval( int i_id ) void PLModel::ProcessItemRemoval( int i_id )
...@@ -301,10 +325,63 @@ void PLModel::ProcessItemAppend( playlist_add_t *p_add ) ...@@ -301,10 +325,63 @@ void PLModel::ProcessItemAppend( playlist_add_t *p_add )
nodeItem->appendChild( new PLItem( p_item, nodeItem, this ) ); nodeItem->appendChild( new PLItem( p_item, nodeItem, this ) );
end: end:
return; return;
} }
void PLModel::Rebuild()
{
/* Remove callbacks before locking to avoid deadlocks */
delCallbacks();
PL_LOCK;
/* Invalidate cache */
i_cached_id = i_cached_input_id = -1;
/* Clear the tree */
qDeleteAll( rootItem->children );
/* Recreate from root */
UpdateNodeChildren( rootItem );
/* And signal the view */
emit layoutChanged();
addCallbacks();
PL_UNLOCK;
}
void PLModel::UpdateNodeChildren( PLItem *root )
{
playlist_item_t *p_node = playlist_ItemGetById( p_playlist, root->i_id );
UpdateNodeChildren( p_node, root );
}
void PLModel::UpdateNodeChildren( playlist_item_t *p_node, PLItem *root )
{
for( int i = 0; i < p_node->i_children ; i++ )
{
PLItem *newItem = new PLItem( p_node->pp_children[i], root, this );
root->appendChild( newItem, false );
UpdateTreeItem( newItem, false );
if( p_node->pp_children[i]->i_children != -1 )
UpdateNodeChildren( p_node->pp_children[i], newItem );
}
}
void PLModel::UpdateTreeItem( PLItem *item, bool signal )
{
playlist_item_t *p_item = playlist_ItemGetById( p_playlist, rootItem->i_id );
UpdateTreeItem( p_item, item, signal );
}
void PLModel::UpdateTreeItem( playlist_item_t *p_item, PLItem *item, bool signal )
{
/// \todo
if( signal )
{ // emit
}
}
/********************************************************************** /**********************************************************************
* Playlist callbacks * Playlist callbacks
......
...@@ -40,9 +40,12 @@ public: ...@@ -40,9 +40,12 @@ public:
~PLItem(); ~PLItem();
int row() const; int row() const;
void insertChild( PLItem *, int ); void insertChild( PLItem *, int p, bool signal = true );
void appendChild( PLItem *item ) { insertChild( item, children.count() ); }; void appendChild( PLItem *item, bool signal = true )
{
insertChild( item, children.count(), signal );
};
PLItem *child( int row ) { return children.value( row ); }; PLItem *child( int row ) { return children.value( row ); };
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 ); };
...@@ -102,19 +105,29 @@ public: ...@@ -102,19 +105,29 @@ public:
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 columnCount( const QModelIndex &parent = QModelIndex() ) const;
bool b_need_update; bool b_need_update;
int i_items_to_append; int i_items_to_append;
private: private:
void addCallbacks();
void delCallbacks();
PLItem *rootItem; PLItem *rootItem;
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 );
void UpdateTreeItem( PLItem *, bool );
void UpdateTreeItem( playlist_item_t *, PLItem *, bool );
void UpdateNodeChildren( 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 );
......
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