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)
TOMOC = main_interface \
dialogs_provider \
input_manager \
playlist_model
playlist_model \
dialogs/playlist \
dialogs/prefs_dialog \
dialogs/streaminfo \
......@@ -25,6 +25,7 @@ TOMOC = main_interface \
components/preferences_widgets \
components/preferences \
components/open \
components/playlist/panels \
util/input_slider
MOCCPP = $(TOMOC:%=%.moc.cpp)
......@@ -40,6 +41,7 @@ nodist_SOURCES_qt4 = \
components/preferences_widgets.moc.cpp \
components/preferences.moc.cpp \
components/open.moc.cpp \
components/playlist/panels.moc.cpp \
util/input_slider.moc.cpp
if ENABLE_QT4
......@@ -71,6 +73,7 @@ SOURCES_qt4 = qt4.cpp \
components/preferences_widgets.cpp \
components/preferences.cpp \
components/open.cpp \
components/playlist/standardpanel.cpp \
util/input_slider.cpp
$(NULL)
......@@ -87,6 +90,7 @@ EXTRA_DIST += \
components/preferences_widgets.hpp \
components/preferences.hpp \
components/open.hpp \
components/playlist/panels.hpp \
util/input_slider.hpp \
ui/input_stats.ui \
pixmaps/advanced.xpm \
......
......@@ -36,7 +36,7 @@ public:
{
p_intf = _p_intf;
}
virtual ~PLPanel();
virtual ~PLPanel() {};
private:
intf_thread_t *p_intf;
};
......@@ -46,7 +46,7 @@ class StandardPLPanel: public PLPanel
{
Q_OBJECT;
public:
StandardPLPanel( QWidget *, intf_thread_t * );
StandardPLPanel( QWidget *, intf_thread_t *, playlist_item_t * );
virtual ~StandardPLPanel();
};
......
......@@ -21,14 +21,19 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#include "playlist_model.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 )
{
PLModel *model = new PLModel( p_root, -1, this );
QTreeView *view = new QTreeView( this );
view->setModel(model);
}
StandardPLPanel::~StandardPLPanel()
{}
#endif
......@@ -23,12 +23,15 @@
#include "dialogs/playlist.hpp"
#include "util/qvlcframe.hpp"
#include "qt4.hpp"
#include "components/playlist/panels.hpp"
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()
......
......@@ -23,7 +23,7 @@
#include "main_interface.hpp"
#include "input_manager.hpp"
#include "util/input_slider.hpp"
#include "util/qvlcframe.hpp">
#include "util/qvlcframe.hpp"
#include "dialogs_provider.hpp"
#include <QCloseEvent>
#include <assert.h>
......@@ -66,6 +66,9 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QMainWindow(), p_intf(
connect( ui.stopButton, SLOT( clicked() ), this, SLOT( stop() ) );
connect( ui.nextButton, SLOT( clicked() ), this, SLOT( next() ) );
connect( ui.prevButton, SLOT( clicked() ), this, SLOT( prev() ) );
connect( ui.playlistButton, SLOT(clicked() ),
DialogsProvider::getInstance( p_intf ), SLOT( playlistDialog() ) );
}
MainInterface::~MainInterface()
......
......@@ -62,11 +62,13 @@ PLItem::~PLItem()
qDeleteAll(children);
}
void PLItem::insertChild( PLItem *item, int i_pos )
void PLItem::insertChild( PLItem *item, int i_pos, bool signal )
{
assert( model );
if( signal )
model->beginInsertRows( model->index( this , 0 ), i_pos, i_pos );
children.append( item );
if( signal )
model->endInsertRows();
}
......@@ -92,6 +94,17 @@ PLModel::PLModel( playlist_item_t * p_root, int i_depth, QObject *parent)
i_cached_id = -1;
i_cached_input_id = -1;
addCallbacks();
}
PLModel::~PLModel()
{
delCallbacks();
delete rootItem;
}
void PLModel::addCallbacks()
{
/* Some global changes happened -> Rebuild all */
var_AddCallback( p_playlist, "intf-change", PlaylistChanged, this );
/* We went to the next item */
......@@ -102,17 +115,17 @@ PLModel::PLModel( playlist_item_t * p_root, int i_depth, QObject *parent)
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, "playlist-current", PlaylistNext, this );
var_DelCallback( p_playlist, "intf-change", PlaylistChanged, this );
var_DelCallback( p_playlist, "item-append", ItemAppended, this );
var_DelCallback( p_playlist, "item-deleted", ItemDeleted, this );
delete rootItem;
}
/****************** Base model mandatory implementations *****************/
QVariant PLModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid())
......@@ -180,7 +193,17 @@ QModelIndex PLModel::parent(const QModelIndex &index) const
return createIndex(parentItem->row(), 0, parentItem);
}
int PLModel::columnCount( const QModelIndex &i) const
{
return 1;
}
int PLModel::childrenCount(const QModelIndex &parent) const
{
return rowCount( parent );
}
int PLModel::rowCount(const QModelIndex &parent) const
{
PLItem *parentItem;
......@@ -272,10 +295,11 @@ void PLModel::customEvent( QEvent *event )
ProcessItemRemoval( ple->i_id );
}
/**** Events processing ****/
void PLModel::ProcessInputItemUpdate( int i_input_id )
{
assert( i_input_id >= 0 );
/// \todo
UpdateTreeItem( FindByInput( rootItem, i_input_id ), true );
}
void PLModel::ProcessItemRemoval( int i_id )
......@@ -301,11 +325,64 @@ void PLModel::ProcessItemAppend( playlist_add_t *p_add )
nodeItem->appendChild( new PLItem( p_item, nodeItem, this ) );
end:
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
**********************************************************************/
......
......@@ -40,9 +40,12 @@ public:
~PLItem();
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 ); };
int childCount() const { return children.count(); };
QString columnString( int col ) { return strings.value( col ); };
......@@ -102,19 +105,29 @@ public:
QModelIndex parent( const QModelIndex &index) 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;
int i_items_to_append;
private:
void addCallbacks();
void delCallbacks();
PLItem *rootItem;
playlist_t *p_playlist;
/* Update processing */
void Rebuild();
void ProcessInputItemUpdate( int i_input_id );
void ProcessItemRemoval( int i_id );
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 */
PLItem *FindById( 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