[vlc-devel] commit: Qt4: switch PLModel to use PlaylistEventManager (Jakob Leben )

git version control git at videolan.org
Sat Nov 7 12:04:25 CET 2009


vlc | branch: master | Jakob Leben <jleben at videolan.org> | Sat Nov  7 12:02:53 2009 +0100| [fed21848fbbdc5836c5fabe4c50ddb2b94f43ec3] | committer: Jakob Leben 

Qt4: switch PLModel to use PlaylistEventManager

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=fed21848fbbdc5836c5fabe4c50ddb2b94f43ec3
---

 modules/gui/qt4/components/playlist/playlist.hpp   |    4 +-
 .../gui/qt4/components/playlist/playlist_model.cpp |   71 +++-----------------
 .../gui/qt4/components/playlist/playlist_model.hpp |   43 +-----------
 3 files changed, 15 insertions(+), 103 deletions(-)

diff --git a/modules/gui/qt4/components/playlist/playlist.hpp b/modules/gui/qt4/components/playlist/playlist.hpp
index 6b567cd..850fea0 100644
--- a/modules/gui/qt4/components/playlist/playlist.hpp
+++ b/modules/gui/qt4/components/playlist/playlist.hpp
@@ -99,8 +99,8 @@ public:
     ~PlaylistEventManager();
 
 signals:
-    void itemAdded( int, int );
-    void itemRemoved( int );
+    void itemAdded( int i_item, int i_parent );
+    void itemRemoved( int i_id );
 
 private:
     static int itemAddedCb ( vlc_object_t *, const char *,
diff --git a/modules/gui/qt4/components/playlist/playlist_model.cpp b/modules/gui/qt4/components/playlist/playlist_model.cpp
index 235a94c..a2d90aa 100644
--- a/modules/gui/qt4/components/playlist/playlist_model.cpp
+++ b/modules/gui/qt4/components/playlist/playlist_model.cpp
@@ -32,6 +32,7 @@
 #include "components/playlist/playlist_model.hpp"
 #include "dialogs/mediainfo.hpp"
 #include "dialogs/playlist.hpp"
+#include "playlist.hpp"
 #include <vlc_intf_strings.h>
 
 #include "pixmaps/types/type_unknown.xpm"
@@ -47,11 +48,6 @@
 
 QIcon PLModel::icons[ITEM_TYPE_NUMBER];
 
-static int ItemAppended( vlc_object_t *p_this, const char *psz_variable,
-                         vlc_value_t oval, vlc_value_t nval, void *param );
-static int ItemDeleted( vlc_object_t *p_this, const char *psz_variable,
-                        vlc_value_t oval, vlc_value_t nval, void *param );
-
 /*************************************************************************
  * Playlist model implementation
  *************************************************************************/
@@ -69,6 +65,7 @@ PLModel::PLModel( playlist_t *_p_playlist,  /* THEPL */
 {
     p_intf            = _p_intf;
     p_playlist        = _p_playlist;
+    plEM              = new PlaylistEventManager( _p_playlist );
     i_cached_id       = -1;
     i_cached_input_id = -1;
     i_popup_item      = i_popup_parent = -1;
@@ -89,18 +86,19 @@ PLModel::PLModel( playlist_t *_p_playlist,  /* THEPL */
     ADD_ICON( NODE, ":/type/node" );
 #undef ADD_ICON
 
-    addCallbacks();
     rebuild( p_root, true );
     CONNECT( THEMIM->getIM(), metaChanged( input_item_t *),
             this, processInputItemUpdate( input_item_t *) );
     CONNECT( THEMIM, inputChanged( input_thread_t * ),
             this, processInputItemUpdate( input_thread_t* ) );
+    CONNECT( plEM, itemAdded( int, int ), this, processItemAppend( int, int ) );
+    CONNECT( plEM, itemRemoved( int ), this, processItemRemoval( int ) );
 }
 
 PLModel::~PLModel()
 {
-    delCallbacks();
     delete rootItem;
+    delete plEM;
 }
 
 Qt::DropActions PLModel::supportedDropActions() const
@@ -290,20 +288,6 @@ void PLModel::removeItem( int i_id )
     removeItem( item );
 }
 
-/* callbacks and slots */
-void PLModel::addCallbacks()
-{
-    /* One item has been updated */
-    var_AddCallback( p_playlist, "playlist-item-append", ItemAppended, this );
-    var_AddCallback( p_playlist, "playlist-item-deleted", ItemDeleted, this );
-}
-
-void PLModel::delCallbacks()
-{
-    var_DelCallback( p_playlist, "playlist-item-append", ItemAppended, this );
-    var_DelCallback( p_playlist, "playlist-item-deleted", ItemDeleted, this );
-}
-
 void PLModel::activateItem( const QModelIndex &index )
 {
     assert( index.isValid() );
@@ -619,20 +603,6 @@ bool PLModel::canEdit() const
   );
 }
 /************************* Updates handling *****************************/
-void PLModel::customEvent( QEvent *event )
-{
-    int type = event->type();
-    if( type != ItemAppend_Type &&
-        type != ItemDelete_Type )
-        return;
-
-    PLEvent *ple = static_cast<PLEvent *>(event);
-
-    if( type == ItemAppend_Type )
-        processItemAppend( &ple->add );
-    else if( type == ItemDelete_Type )
-        processItemRemoval( ple->i_id );
-}
 
 /**** Events processing ****/
 void PLModel::processInputItemUpdate( input_thread_t *p_input )
@@ -664,19 +634,19 @@ void PLModel::processItemRemoval( int i_id )
     removeItem( i_id );
 }
 
-void PLModel::processItemAppend( const playlist_add_t *p_add )
+void PLModel::processItemAppend( int i_item, int i_parent )
 {
     playlist_item_t *p_item = NULL;
     PLItem *newItem = NULL;
 
-    PLItem *nodeItem = findById( rootItem, p_add->i_node );
+    PLItem *nodeItem = findById( rootItem, i_parent );
     if( !nodeItem ) return;
 
     foreach( PLItem *existing, nodeItem->children )
-      if( existing->i_id == p_add->i_item ) return;
+      if( existing->i_id == i_item ) return;
 
     PL_LOCK;
-    p_item = playlist_ItemGetById( p_playlist, p_add->i_item );
+    p_item = playlist_ItemGetById( p_playlist, i_item );
     if( !p_item || p_item->i_flags & PLAYLIST_DBL_FLAG ) goto end;
 
     newItem = new PLItem( p_item, nodeItem );
@@ -1100,26 +1070,3 @@ void PLModel::popupSortDesc()
 {
     sort( i_popup_parent, i_popup_column, Qt::DescendingOrder );
 }
-/**********************************************************************
- * Playlist callbacks
- **********************************************************************/
-
-static int ItemDeleted( vlc_object_t *p_this, const char *psz_variable,
-                        vlc_value_t oval, vlc_value_t nval, void *param )
-{
-    PLModel *p_model = (PLModel *) param;
-    PLEvent *event = new PLEvent( ItemDelete_Type, nval.i_int );
-    QApplication::postEvent( p_model, event );
-    return VLC_SUCCESS;
-}
-
-static int ItemAppended( vlc_object_t *p_this, const char *psz_variable,
-                         vlc_value_t oval, vlc_value_t nval, void *param )
-{
-    PLModel *p_model = (PLModel *) param;
-    const playlist_add_t *p_add = (playlist_add_t *)nval.p_address;
-    PLEvent *event = new PLEvent( p_add );
-    QApplication::postEvent( p_model, event );
-    return VLC_SUCCESS;
-}
-
diff --git a/modules/gui/qt4/components/playlist/playlist_model.hpp b/modules/gui/qt4/components/playlist/playlist_model.hpp
index 620ea81..5a50587 100644
--- a/modules/gui/qt4/components/playlist/playlist_model.hpp
+++ b/modules/gui/qt4/components/playlist/playlist_model.hpp
@@ -44,41 +44,10 @@
 #include <QAbstractItemModel>
 #include <QVariant>
 
+class PlaylistEventManager;
 class QSignalMapper;
-
 class PLItem;
 
-#define DEPTH_PL -1
-#define DEPTH_SEL 1
-
-enum {
-    ItemUpdate_Type = QEvent::User + PLEventType + 2,
-    ItemDelete_Type = QEvent::User + PLEventType + 3,
-    ItemAppend_Type = QEvent::User + PLEventType + 4,
-};
-
-class PLEvent : public QEvent
-{
-public:
-    PLEvent( int type, int id ) : QEvent( (QEvent::Type)(type) )
-    {
-        i_id = id;
-        add.i_node = -1;
-        add.i_item = -1;
-    };
-
-    PLEvent( const playlist_add_t  *a ) : QEvent( (QEvent::Type)(ItemAppend_Type) )
-    {
-        add = *a;
-    };
-
-    virtual ~PLEvent() { };
-
-    int i_id;
-    playlist_add_t add;
-};
-
-
 class PLModel : public QAbstractItemModel
 {
     Q_OBJECT
@@ -131,6 +100,7 @@ public:
 private:
 
     /* General */
+    PlaylistEventManager *plEM;
     PLItem *rootItem;
     PLItem *currentItem;
 
@@ -140,13 +110,6 @@ private:
 
     static QIcon icons[ITEM_TYPE_NUMBER];
 
-    /* Callbacks related */
-    void addCallbacks();
-    void delCallbacks();
-    void customEvent( QEvent * );
-    void processItemRemoval( int i_id );
-    void processItemAppend( const playlist_add_t *p_add );
-
     /* Actions */
     void recurseDelete( QList<PLItem*> children, QModelIndexList *fullList );
     void doDeleteItem( PLItem *item, QModelIndexList *fullList );
@@ -199,6 +162,8 @@ private slots:
     void popupSortDesc();
     void processInputItemUpdate( input_item_t *);
     void processInputItemUpdate( input_thread_t* p_input );
+    void processItemRemoval( int i_id );
+    void processItemAppend( int item, int parent );
 };
 
 #endif




More information about the vlc-devel mailing list