Some more playlist code
authorClément Stenac <zorglub@videolan.org>
Mon, 26 Jun 2006 06:26:45 +0000 (06:26 +0000)
committerClément Stenac <zorglub@videolan.org>
Mon, 26 Jun 2006 06:26:45 +0000 (06:26 +0000)
Fix makefile

modules/gui/qt4/Modules.am
modules/gui/qt4/components/playlist/panels.hpp
modules/gui/qt4/components/playlist/standardpanel.cpp
modules/gui/qt4/dialogs/playlist.cpp
modules/gui/qt4/main_interface.cpp
modules/gui/qt4/playlist_model.cpp
modules/gui/qt4/playlist_model.hpp

index 3ed6b1d..32ccad7 100644 (file)
@@ -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)
 
@@ -32,7 +33,7 @@ nodist_SOURCES_qt4 = \
                main_interface.moc.cpp \
                dialogs_provider.moc.cpp \
                input_manager.moc.cpp \
-        playlist_model.moc.cpp \
+               playlist_model.moc.cpp \
                dialogs/playlist.moc.cpp \
                dialogs/streaminfo.moc.cpp \
                dialogs/prefs_dialog.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
@@ -63,7 +65,7 @@ SOURCES_qt4 =         qt4.cpp \
                main_interface.cpp \
                dialogs_provider.cpp \
                input_manager.cpp \
-        playlist_model.cpp \
+               playlist_model.cpp \
                dialogs/playlist.cpp \
                dialogs/prefs_dialog.cpp \
                dialogs/streaminfo.cpp \
@@ -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)
 
@@ -79,7 +82,7 @@ EXTRA_DIST += \
        main_interface.hpp \
        dialogs_provider.hpp \
        input_manager.hpp \
-    playlist_model.hpp \
+       playlist_model.hpp \
        dialogs/playlist.hpp \
        dialogs/streaminfo.hpp \
        dialogs/prefs_dialog.hpp \
@@ -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 \
index ada46d5..4596cfc 100644 (file)
@@ -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();
 };
 
index b5e8c68..5094a8a 100644 (file)
  * 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
index 7f27d33..5120016 100644 (file)
 #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()
index ded9e4b..8d39799 100644 (file)
@@ -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()
index f6f8f57..e87772d 100644 (file)
@@ -62,12 +62,14 @@ PLItem::~PLItem()
     qDeleteAll(children);
 }
 
-void PLItem::insertChild( PLItem *item, int i_pos )
+void PLItem::insertChild( PLItem *item, int i_pos, bool signal )
 {
     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 );
-    model->endInsertRows();
+    if( signal )
+        model->endInsertRows();
 }
 
 int PLItem::row() const
@@ -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,10 +325,63 @@ 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 
index 8bea465..5c1daea 100644 (file)
@@ -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 );