]> git.sesse.net Git - vlc/commitdiff
Qt/ML: Move more functions into VLCModel
authorSrikanth Raju <srikiraju@gmail.com>
Mon, 17 Jan 2011 13:47:21 +0000 (19:17 +0530)
committerSrikanth Raju <srikiraju@gmail.com>
Mon, 17 Jan 2011 15:12:24 +0000 (20:42 +0530)
doDelete() should be virtual
getMeta() and getArtPixmap() helpers in VLCModel

modules/gui/qt4/components/playlist/ml_model.cpp
modules/gui/qt4/components/playlist/ml_model.hpp
modules/gui/qt4/components/playlist/playlist_model.cpp
modules/gui/qt4/components/playlist/playlist_model.hpp
modules/gui/qt4/components/playlist/views.cpp
modules/gui/qt4/components/playlist/vlc_model.cpp
modules/gui/qt4/components/playlist/vlc_model.hpp

index f4efd3a7a90686b1047d442a22df80eb8924ee90..09f6a07432d30d77f682ddf3b80f33c2eae2995a 100644 (file)
@@ -94,7 +94,7 @@ void MLModel::clear()
 QModelIndex MLModel::index( int row, int column,
                                   const QModelIndex &parent ) const
 {
-    if( parent.isValid() )
+    if( parent.isValid() || row >= items.count() )
         return QModelIndex();
     else
     {
@@ -229,10 +229,12 @@ void MLModel::remove( MLItem *item )
     remove( createIndex( row, 0 ) );
 }
 
-void MLModel::remove( QModelIndexList list )
+void MLModel::doDelete( QModelIndexList list )
 {
-    for (int i = 0; i < list.size(); ++i) {
-        remove( list.at(i) );
+    for (int i = 0; i < list.size(); ++i)
+    {
+        int id = getId( list.at(i) );
+        ml_DeleteSimple( p_ml, id );
     }
 }
 
@@ -514,9 +516,9 @@ bool MLModel::popup( const QModelIndex & index, const QPoint &point, const QMode
 
     QIcon addIcon( ":/buttons/playlist/playlist_add" );
     menu.addSeparator();
-    menu.addAction( addIcon, qtr(I_PL_ADDF), THEDP, SLOT( simpleMLAppendDialog()) );
-    menu.addAction( addIcon, qtr(I_PL_ADDDIR), THEDP, SLOT( MLAppendDir() ) );
-    menu.addAction( addIcon, qtr(I_OP_ADVOP), THEDP, SLOT( MLAppendDialog() ) );
+    //menu.addAction( addIcon, qtr(I_PL_ADDF), THEDP, SLOT( simpleMLAppendDialog()) );
+    //menu.addAction( addIcon, qtr(I_PL_ADDDIR), THEDP, SLOT( MLAppendDir() ) );
+    //menu.addAction( addIcon, qtr(I_OP_ADVOP), THEDP, SLOT( MLAppendDialog() ) );
 
     if( index.isValid() )
     {
@@ -531,15 +533,14 @@ bool MLModel::popup( const QModelIndex & index, const QPoint &point, const QMode
     else return false;
 }
 
-
-void MLModel::popupDel()
+void MLModel::popupPlay()
 {
-    remove( current_selection );
+    play( current_index );
 }
 
-void MLModel::popupPlay()
+void MLModel::popupDel()
 {
-    play( current_index );
+    doDelete( current_selection );
 }
 
 void MLModel::popupInfo()
index b06968ed187f5c62f20fbc074b4b6e806d05e087..f1c5fbe9687d6ce29f63d14d2f5ec37df6fa89ae 100644 (file)
@@ -94,8 +94,8 @@ public:
     int insertResultArray( vlc_array_t *p_result_array, int row = -1,
                            bool bSignal = true );
 
+    virtual void doDelete( QModelIndexList list );
     void remove( MLItem *item );
-    void remove( QModelIndexList list );
     void remove( QModelIndex idx );
 
     void clear();
index 7f7fe312e568173163a45147ffbdbcf7aa2e6652..13854935e2d9c37ac2de3dd6f26b9f6c94652943 100644 (file)
@@ -584,62 +584,6 @@ bool PLModel::canEdit() const
            );
 }
 
-QString PLModel::getMeta( const QModelIndex & index, int meta )
-{
-    return index.model()->index( index.row(),
-            columnFromMeta( meta ),
-            index.parent() )
-            .data().toString();
-}
-
-
-QPixmap PLModel::getArtPixmap( const QModelIndex & index, const QSize & size )
-{
-    PLItem *item = static_cast<PLItem*>( index.internalPointer() );
-    assert( item );
-
-    if( item == NULL )
-        return NULL;
-
-    QString artUrl = InputManager::decodeArtURL( item->inputItem() );
-
-    /* If empty, take one of the children art URL */
-    if( artUrl.isEmpty() )
-    {
-        for( int i = 0; i < item->childCount(); i++ )
-        {
-            artUrl = InputManager::decodeArtURL( item->child( i )->inputItem() );
-            if( !artUrl.isEmpty() )
-                break;
-        }
-    }
-
-    QPixmap artPix;
-    QString key = artUrl + QString("%1%2").arg(size.width()).arg(size.height());
-
-    /* Lookup in the QPixmapCache */
-    if( !QPixmapCache::find( key, artPix ))
-    {
-        if( artUrl.isEmpty() || !artPix.load( artUrl ) )
-        {
-            key = QString("noart%1%2").arg(size.width()).arg(size.height());
-            if( !QPixmapCache::find( key, artPix ) )
-            {
-                artPix = QPixmap( ":/noart" ).scaled( size,
-                                                      Qt::KeepAspectRatio,
-                                                      Qt::SmoothTransformation );
-                QPixmapCache::insert( key, artPix );
-            }
-        }
-        else
-        {
-            artPix = artPix.scaled( size, Qt::KeepAspectRatio, Qt::SmoothTransformation );
-            QPixmapCache::insert( key, artPix );
-        }
-    }
-
-    return artPix;
-}
 /************************* Updates handling *****************************/
 
 /**** Events processing ****/
index 2b0f4e1ce6f8e52686cec46b69102b840d866af1..9d8db22da6c46d3198c9c4e136a4e2ecc3866314 100644 (file)
@@ -86,12 +86,9 @@ public:
     bool isCurrent( const QModelIndex &index ) const;
     int itemId( const QModelIndex &index ) const;
 
-    static QPixmap getArtPixmap( const QModelIndex & index, const QSize & size );
-    static QString getMeta( const QModelIndex & index, int meta );
-
     /* Actions */
     virtual bool popup( const QModelIndex & index, const QPoint &point, const QModelIndexList &list );
-    void doDelete( QModelIndexList selected );
+    virtual void doDelete( QModelIndexList selected );
     void search( const QString& search_text, const QModelIndex & root, bool b_recursive );
     void sort( const int column, Qt::SortOrder order );
     void sort( const int i_root_id, const int column, Qt::SortOrder order );
index 2888703cdc29bc7ced9e84f5498b59b0aab6f75c..9415b4a11adb24650594380d54f4be4f9d5e494f 100644 (file)
@@ -74,8 +74,8 @@ void AbstractPlViewItemDelegate::paintBackground(
 
 void PlIconViewItemDelegate::paint( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const
 {
-    QString title = PLModel::getMeta( index, COLUMN_TITLE );
-    QString artist = PLModel::getMeta( index, COLUMN_ARTIST );
+    QString title = VLCModel::getMeta( index, COLUMN_TITLE );
+    QString artist = VLCModel::getMeta( index, COLUMN_ARTIST );
 
     QFont font( index.data( Qt::FontRole ).value<QFont>() );
     painter->setFont( font );
@@ -85,7 +85,7 @@ void PlIconViewItemDelegate::paint( QPainter * painter, const QStyleOptionViewIt
     int art_width = averagewidth * ICON_SCALER;
     int art_height = averagewidth * ICON_SCALER;
 
-    QPixmap artPix = PLModel::getArtPixmap( index, QSize( art_width, art_height) );
+    QPixmap artPix = VLCModel::getArtPixmap( index, QSize( art_width, art_height) );
 
     paintBackground( painter, option, index );
 
@@ -177,13 +177,13 @@ QSize PlIconViewItemDelegate::sizeHint ( const QStyleOptionViewItem & option, co
 
 void PlListViewItemDelegate::paint( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const
 {
-    QString title = PLModel::getMeta( index, COLUMN_TITLE );
-    QString duration = PLModel::getMeta( index, COLUMN_DURATION );
+    QString title = VLCModel::getMeta( index, COLUMN_TITLE );
+    QString duration = VLCModel::getMeta( index, COLUMN_DURATION );
     if( !duration.isEmpty() ) title += QString(" [%1]").arg( duration );
 
-    QString artist = PLModel::getMeta( index, COLUMN_ARTIST );
-    QString album = PLModel::getMeta( index, COLUMN_ALBUM );
-    QString trackNum = PLModel::getMeta( index, COLUMN_TRACK_NUMBER );
+    QString artist = VLCModel::getMeta( index, COLUMN_ARTIST );
+    QString album = VLCModel::getMeta( index, COLUMN_ALBUM );
+    QString trackNum = VLCModel::getMeta( index, COLUMN_TRACK_NUMBER );
     QString artistAlbum = artist;
     if( !album.isEmpty() )
     {
@@ -192,7 +192,7 @@ void PlListViewItemDelegate::paint( QPainter * painter, const QStyleOptionViewIt
         if( !trackNum.isEmpty() ) artistAlbum += QString( " [#%1]" ).arg( trackNum );
     }
 
-    QPixmap artPix = PLModel::getArtPixmap( index, QSize( LISTVIEW_ART_SIZE, LISTVIEW_ART_SIZE ) );
+    QPixmap artPix = VLCModel::getArtPixmap( index, QSize( LISTVIEW_ART_SIZE, LISTVIEW_ART_SIZE ) );
 
     //Draw selection rectangle and current playing item indication
     paintBackground( painter, option, index );
index 04d0ac0adb8dbb6ccf268b0fbc0d5207314abff8..718c5b26cc6eaba3b5caa34e4369ba0ab0e22a91 100644 (file)
@@ -31,3 +31,43 @@ VLCModel::VLCModel( intf_thread_t *_p_intf, QObject *parent )
 VLCModel::~VLCModel()
 {
 }
+
+QString VLCModel::getMeta( const QModelIndex & index, int meta )
+{
+    return index.model()->index( index.row(), columnFromMeta( meta ), index.parent() ).
+        data().toString();
+}
+
+QPixmap VLCModel::getArtPixmap( const QModelIndex & index, const QSize & size )
+{
+    QString artUrl;
+    artUrl = index.model()->index( index.row(),
+                                  COLUMN_COVER,
+                                  index.parent() )
+                                  .data().toString();
+    QPixmap artPix;
+
+    QString key = artUrl + QString("%1%2").arg(size.width()).arg(size.height());
+
+    if( !QPixmapCache::find( key, artPix ))
+    {
+        if( artUrl.isEmpty() || !artPix.load( artUrl ) )
+        {
+            key = QString("noart%1%2").arg(size.width()).arg(size.height());
+            if( !QPixmapCache::find( key, artPix ) )
+            {
+                artPix = QPixmap( ":/noart" ).scaled( size,
+                                                      Qt::KeepAspectRatio,
+                                                      Qt::SmoothTransformation );
+                QPixmapCache::insert( key, artPix );
+            }
+        }
+        else
+        {
+            artPix = artPix.scaled( size, Qt::KeepAspectRatio, Qt::SmoothTransformation );
+            QPixmapCache::insert( key, artPix );
+        }
+    }
+
+    return artPix;
+}
index 9f4a904f47362801ac9ea8e80c73b356e2e3a41a..520a1bd6a3350382a07e2d5eb397f50166f97ea9 100644 (file)
@@ -34,6 +34,8 @@
 #include <vlc_input.h>
 
 #include <QModelIndex>
+#include <QPixmapCache>
+#include <QSize>
 #include <QAbstractItemModel>
 
 
@@ -52,7 +54,10 @@ public:
     virtual QModelIndex currentIndex() const = 0;
     virtual bool popup( const QModelIndex & index,
             const QPoint &point, const QModelIndexList &list ) = 0;
+    virtual void doDelete( QModelIndexList ) = 0;
     virtual ~VLCModel();
+    static QString getMeta( const QModelIndex & index, int meta );
+    static QPixmap getArtPixmap( const QModelIndex & index, const QSize & size );
 
 public slots:
     virtual void activateItem( const QModelIndex &index ) = 0;