diff --git a/src/libtomahawk/playlist/PlayableProxyModel.cpp b/src/libtomahawk/playlist/PlayableProxyModel.cpp index 25e7e112b..61db785dc 100644 --- a/src/libtomahawk/playlist/PlayableProxyModel.cpp +++ b/src/libtomahawk/playlist/PlayableProxyModel.cpp @@ -34,6 +34,7 @@ PlayableProxyModel::PlayableProxyModel( QObject* parent ) : QSortFilterProxyModel( parent ) , m_model( 0 ) , m_showOfflineResults( true ) + , m_hideDupeItems( false ) , m_maxVisibleItems( -1 ) { setFilterCaseSensitivity( Qt::CaseInsensitive ); @@ -101,6 +102,23 @@ PlayableProxyModel::filterAcceptsRow( int sourceRow, const QModelIndex& sourcePa if ( m_maxVisibleItems >= 0 && sourceRow > m_maxVisibleItems - 1 ) return false; + + if ( m_hideDupeItems ) + { + for ( int i = 0; i < sourceRow; i++ ) + { + PlayableItem* di = itemFromIndex( sourceModel()->index( i, 0, sourceParent ) ); + if ( !di ) + continue; + + bool b = ( pi->query() && pi->query()->equals( di->query() ) ) || + ( pi->album() && pi->album() == di->album() ) || + ( pi->artist() && pi->artist()->name() == di->artist()->name() ); + + if ( b && filterAcceptsRow( i, sourceParent ) ) + return false; + } + } if ( pi->query() ) { @@ -215,6 +233,22 @@ PlayableProxyModel::remove( const QList< QPersistentModelIndex >& indexes ) } +void +PlayableProxyModel::setShowOfflineResults( bool b ) +{ + m_showOfflineResults = b; + invalidateFilter(); +} + + +void +PlayableProxyModel::setHideDupeItems( bool b ) +{ + m_hideDupeItems = b; + invalidateFilter(); +} + + void PlayableProxyModel::setMaxVisibleItems( int items ) { diff --git a/src/libtomahawk/playlist/PlayableProxyModel.h b/src/libtomahawk/playlist/PlayableProxyModel.h index aad74f3e5..5a53ee566 100644 --- a/src/libtomahawk/playlist/PlayableProxyModel.h +++ b/src/libtomahawk/playlist/PlayableProxyModel.h @@ -49,8 +49,11 @@ public: virtual void remove( const QList< QPersistentModelIndex >& indexes ); virtual bool showOfflineResults() const { return m_showOfflineResults; } - virtual void setShowOfflineResults( bool b ) { m_showOfflineResults = b; } - + virtual void setShowOfflineResults( bool b ); + + virtual bool hideDupeItems() const { return m_hideDupeItems; } + virtual void setHideDupeItems( bool b ); + virtual int maxVisibleItems() const { return m_maxVisibleItems; } virtual void setMaxVisibleItems( int items ); @@ -81,6 +84,7 @@ private: PlayableModel* m_model; bool m_showOfflineResults; + bool m_hideDupeItems; int m_maxVisibleItems; };