[vlc-commits] commit: Qt/ML: Extend Playlist model from VLCModel (Srikanth Raju )

git at videolan.org git at videolan.org
Sun Jan 9 19:53:11 CET 2011


vlc | branch: master | Srikanth Raju <srikiraju at gmail.com> | Wed Dec 29 20:07:20 2010 +0530| [00d1ebdf0d888f9b83197e58cc2bee444fb7dd59] | committer: Srikanth Raju 

Qt/ML: Extend Playlist model from VLCModel

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

 .../gui/qt4/components/playlist/playlist_item.hpp  |    4 +-
 .../gui/qt4/components/playlist/playlist_model.cpp |   53 +++++++------------
 .../gui/qt4/components/playlist/playlist_model.hpp |   32 +++++-------
 3 files changed, 36 insertions(+), 53 deletions(-)

diff --git a/modules/gui/qt4/components/playlist/playlist_item.hpp b/modules/gui/qt4/components/playlist/playlist_item.hpp
index 93f31ae..c444d2a 100644
--- a/modules/gui/qt4/components/playlist/playlist_item.hpp
+++ b/modules/gui/qt4/components/playlist/playlist_item.hpp
@@ -49,11 +49,11 @@ public:
     void removeChildren();
     void takeChildAt( int );
 
-    PLItem *child( int row ) { return children.value( row ); }
+    PLItem *child( int row ) const { return children.value( row ); }
     int childCount() const { return children.count(); }
 
     PLItem *parent() { return parentItem; }
-    input_item_t *inputItem() { return p_input; }
+    input_item_t *inputItem() const { return p_input; }
     int id() { return i_id; }
     bool operator< ( PLItem& );
 
diff --git a/modules/gui/qt4/components/playlist/playlist_model.cpp b/modules/gui/qt4/components/playlist/playlist_model.cpp
index 24bf638..7f7fe31 100644
--- a/modules/gui/qt4/components/playlist/playlist_model.cpp
+++ b/modules/gui/qt4/components/playlist/playlist_model.cpp
@@ -66,9 +66,8 @@ PLModel::PLModel( playlist_t *_p_playlist,  /* THEPL */
                   intf_thread_t *_p_intf,   /* main Qt p_intf */
                   playlist_item_t * p_root,
                   QObject *parent )         /* Basic Qt parent */
-                  : QAbstractItemModel( parent )
+                  : VLCModel( _p_intf, parent )
 {
-    p_intf            = _p_intf;
     p_playlist        = _p_playlist;
     i_cached_id       = -1;
     i_cached_input_id = -1;
@@ -338,6 +337,21 @@ QVariant PLModel::data( const QModelIndex &index, const int role ) const
         QString returninfo;
         if( metadata == COLUMN_NUMBER )
             returninfo = QString::number( index.row() + 1 );
+        else if( metadata == COLUMN_COVER )
+        {
+            QString artUrl;
+            artUrl = InputManager::decodeArtURL( item->inputItem() );
+            if( artUrl.isEmpty() )
+            {
+                for( int i = 0; i < item->childCount(); i++ )
+                {
+                    artUrl = InputManager::decodeArtURL( item->child( i )->inputItem() );
+                    if( !artUrl.isEmpty() )
+                        break;
+                }
+            }
+            return QVariant( artUrl );
+        }
         else
         {
             char *psz = psz_column_meta( item->p_input, metadata );
@@ -558,34 +572,6 @@ PLItem * PLModel::findInner( PLItem *root, int i_id, bool b_input ) const
     return NULL;
 }
 
-int PLModel::columnToMeta( int _column )
-{
-    int meta = 1;
-    int column = 0;
-
-    while( column != _column && meta != COLUMN_END )
-    {
-        meta <<= 1;
-        column++;
-    }
-
-    return meta;
-}
-
-int PLModel::columnFromMeta( int meta_col )
-{
-    int meta = 1;
-    int column = 0;
-
-    while( meta != meta_col && meta != COLUMN_END )
-    {
-        meta <<= 1;
-        column++;
-    }
-
-    return column;
-}
-
 bool PLModel::canEdit() const
 {
     return (
@@ -601,11 +587,12 @@ bool PLModel::canEdit() const
 QString PLModel::getMeta( const QModelIndex & index, int meta )
 {
     return index.model()->index( index.row(),
-                                  PLModel::columnFromMeta( meta ),
-                                  index.parent() )
-                                .data().toString();
+            columnFromMeta( meta ),
+            index.parent() )
+            .data().toString();
 }
 
+
 QPixmap PLModel::getArtPixmap( const QModelIndex & index, const QSize & size )
 {
     PLItem *item = static_cast<PLItem*>( index.internalPointer() );
diff --git a/modules/gui/qt4/components/playlist/playlist_model.hpp b/modules/gui/qt4/components/playlist/playlist_model.hpp
index 4fb16b9..2b0f4e1 100644
--- a/modules/gui/qt4/components/playlist/playlist_model.hpp
+++ b/modules/gui/qt4/components/playlist/playlist_model.hpp
@@ -29,13 +29,14 @@
 # include "config.h"
 #endif
 
-#include "qt4.hpp"
-
 #include <vlc_input.h>
 #include <vlc_playlist.h>
-
+#include "vlc_model.hpp"
 #include "playlist_item.hpp"
 
+#include <QObject>
+#include <QEvent>
+#include <QSignalMapper>
 #include <QMimeData>
 #include <QAbstractItemModel>
 #include <QVariant>
@@ -46,20 +47,14 @@ class PLSelector;
 class PlMimeData;
 class QSignalMapper;
 
-class PLModel : public QAbstractItemModel
+class PLModel : public VLCModel
 {
     Q_OBJECT
 
 public:
-    enum {
-      IsCurrentRole = Qt::UserRole,
-      IsLeafNodeRole,
-      IsCurrentsParentNodeRole
-    };
-
     PLModel( playlist_t *, intf_thread_t *,
              playlist_item_t *, QObject *parent = 0 );
-    ~PLModel();
+    virtual ~PLModel();
 
     /*** QModel subclassing ***/
 
@@ -86,18 +81,16 @@ public:
     QStringList selectedURIs();
     QModelIndex index( PLItem *, const int c ) const;
     QModelIndex index( const int i_id, const int c );
-    QModelIndex currentIndex() const;
+    virtual QModelIndex currentIndex() const;
     bool isParent( const QModelIndex &index, const QModelIndex &current) const;
     bool isCurrent( const QModelIndex &index ) const;
     int itemId( const QModelIndex &index ) const;
-    static int columnFromMeta( int meta_column );
-    static int columnToMeta( int column );
 
-    static QString getMeta( const QModelIndex & index, int meta );
     static QPixmap getArtPixmap( const QModelIndex & index, const QSize & size );
+    static QString getMeta( const QModelIndex & index, int meta );
 
     /* Actions */
-    bool popup( const QModelIndex & index, const QPoint &point, const QModelIndexList &list );
+    virtual bool popup( const QModelIndex & index, const QPoint &point, const QModelIndexList &list );
     void doDelete( QModelIndexList selected );
     void search( const QString& search_text, const QModelIndex & root, bool b_recursive );
     void sort( const int column, Qt::SortOrder order );
@@ -111,13 +104,17 @@ public:
             return static_cast<PLItem*>( index.internalPointer() );
         else return rootItem;
     }
+    virtual int getId( QModelIndex index ) const
+    {
+        return getItem( index )->id();
+    }
 
 signals:
     void currentChanged( const QModelIndex& );
     void rootChanged();
 
 public slots:
-    void activateItem( const QModelIndex &index );
+    virtual void activateItem( const QModelIndex &index );
     void activateItem( playlist_item_t *p_item );
 
 private:
@@ -125,7 +122,6 @@ private:
     PLItem *rootItem;
 
     playlist_t *p_playlist;
-    intf_thread_t *p_intf;
 
     static QIcon icons[ITEM_TYPE_NUMBER];
 



More information about the vlc-commits mailing list