1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-04-19 23:41:51 +02:00

* Don't show offline results in SuperCollection and general collection loading speed-ups.

This commit is contained in:
Christian Muehlhaeuser 2011-03-18 05:51:21 +01:00
parent b631a6b3bd
commit c9ca6b3a79
6 changed files with 25 additions and 42 deletions

View File

@ -24,27 +24,6 @@ CollectionFlatModel::~CollectionFlatModel()
}
int
CollectionFlatModel::columnCount( const QModelIndex& parent ) const
{
return TrackModel::columnCount( parent );
}
QVariant
CollectionFlatModel::data( const QModelIndex& index, int role ) const
{
return TrackModel::data( index, role );
}
QVariant
CollectionFlatModel::headerData( int section, Qt::Orientation orientation, int role ) const
{
return TrackModel::headerData( section, orientation, role );
}
void
CollectionFlatModel::addCollections( const QList< collection_ptr >& collections )
{
@ -53,7 +32,7 @@ CollectionFlatModel::addCollections( const QList< collection_ptr >& collections
{
addCollection( col );
}
// we are waiting for some to load
if( !m_loadingCollections.isEmpty() )
emit loadingStarted();
@ -72,17 +51,19 @@ CollectionFlatModel::addCollection( const collection_ptr& collection, bool sendN
connect( collection.data(), SIGNAL( tracksRemoved( QList<Tomahawk::query_ptr> ) ),
SLOT( onTracksRemoved( QList<Tomahawk::query_ptr> ) ) );
if( sendNotifications )
emit loadingStarted();
if ( collection->isLoaded() )
{
onTracksAdded( collection->tracks() );
}
else
{
collection->tracks(); // data will arrive via signals
m_loadingCollections << collection.data();
if( sendNotifications )
emit loadingStarted();
}
if ( collection->source()->isLocal() )
setTitle( tr( "Your Collection" ) );
else
@ -190,8 +171,6 @@ CollectionFlatModel::onTracksAdded( const QList<Tomahawk::query_ptr>& tracks )
// we are keeping track and are called as a slot
m_loadingCollections.removeAll( qobject_cast< Collection* >( sender() ) );
}
if( m_loadingCollections.isEmpty() )
emit loadingFinished();
bool kickOff = m_tracksToAdd.isEmpty();
m_tracksToAdd << tracks;
@ -206,7 +185,7 @@ CollectionFlatModel::onTracksAdded( const QList<Tomahawk::query_ptr>& tracks )
void
CollectionFlatModel::processTracksToAdd()
{
int chunkSize = 500000;
int chunkSize = 5000;
int maxc = qMin( chunkSize, m_tracksToAdd.count() );
int c = rowCount( QModelIndex() );
@ -218,7 +197,6 @@ CollectionFlatModel::processTracksToAdd()
for( int i = 0; i < maxc; ++i )
{
plitem = new PlItem( *iter, m_rootItem );
plitem->index = createIndex( m_rootItem->children.count() - 1, 0, plitem );
@ -229,6 +207,9 @@ CollectionFlatModel::processTracksToAdd()
m_tracksToAdd.erase( m_tracksToAdd.begin(), iter );
if ( m_tracksToAdd.isEmpty() && m_loadingCollections.isEmpty() )
emit loadingFinished();
//endResetModel();
emit endInsertRows();
qDebug() << Q_FUNC_INFO << rowCount( QModelIndex() );
@ -278,7 +259,7 @@ CollectionFlatModel::onDataChanged()
// emit itemSizeChanged( p->index );
if ( p )
emit dataChanged( p->index, p->index.sibling( p->index.row(), columnCount() - 1 ) );
emit dataChanged( p->index, p->index.sibling( p->index.row(), columnCount( QModelIndex() ) - 1 ) );
}

View File

@ -27,13 +27,8 @@ public:
explicit CollectionFlatModel( QObject* parent = 0 );
~CollectionFlatModel();
int columnCount( const QModelIndex& parent = QModelIndex() ) const;
virtual int trackCount() const { return rowCount( QModelIndex() ) + m_tracksToAdd.count(); }
QVariant data( const QModelIndex& index, int role ) const;
QVariant headerData( int section, Qt::Orientation orientation, int role ) const;
void addCollections( const QList< Tomahawk::collection_ptr >& collections );
void addCollection( const Tomahawk::collection_ptr& collection, bool sendNotifications = true );

View File

@ -56,7 +56,7 @@ PlaylistManager::PlaylistManager( QObject* parent )
m_topbar = new TopBar();
m_infobar = new InfoBar();
m_stack = new QStackedWidget();
QFrame* line = new QFrame();
line->setFrameStyle( QFrame::HLine );
line->setStyleSheet( "border: 1px solid gray;" );
@ -86,13 +86,14 @@ PlaylistManager::PlaylistManager( QObject* parent )
m_superCollectionView->setModel( m_superCollectionFlatModel );
m_superCollectionView->setFrameShape( QFrame::NoFrame );
m_superCollectionView->setAttribute( Qt::WA_MacShowFocusRect, 0 );
m_superCollectionView->proxyModel()->setShowOfflineResults( false );
m_superAlbumView = new AlbumView();
m_superAlbumModel = new AlbumModel( m_superAlbumView );
m_superAlbumView->setModel( m_superAlbumModel );
m_superAlbumView->setFrameShape( QFrame::NoFrame );
m_superAlbumView->setAttribute( Qt::WA_MacShowFocusRect, 0 );
m_stack->setContentsMargins( 0, 0, 0, 0 );
m_widget->setContentsMargins( 0, 0, 0, 0 );
m_widget->layout()->setContentsMargins( 0, 0, 0, 0 );
@ -106,10 +107,10 @@ PlaylistManager::PlaylistManager( QObject* parent )
connect( m_topbar, SIGNAL( flatMode() ),
SLOT( setTableMode() ) );
connect( m_topbar, SIGNAL( artistMode() ),
SLOT( setTreeMode() ) );
connect( m_topbar, SIGNAL( albumMode() ),
SLOT( setAlbumMode() ) );
}

View File

@ -72,6 +72,7 @@ signals:
void loadingStarted();
void loadingFinished();
public slots:
virtual void setCurrentItem( const QModelIndex& index );

View File

@ -14,6 +14,7 @@ TrackProxyModel::TrackProxyModel( QObject* parent )
, m_model( 0 )
, m_repeatMode( PlaylistInterface::NoRepeat )
, m_shuffled( false )
, m_showOfflineResults( true )
{
qsrand( QTime( 0, 0, 0 ).secsTo( QTime::currentTime() ) );
@ -146,8 +147,8 @@ TrackProxyModel::filterAcceptsRow( int sourceRow, const QModelIndex& sourceParen
if ( q->numResults() )
r = q->results().first();
// if ( !r.isNull() && !r->collection()->source()->isOnline() )
// return false;
if ( !m_showOfflineResults && !r.isNull() && !r->collection()->source()->isOnline() )
return false;
if ( filterRegExp().isEmpty() )
return true;

View File

@ -38,6 +38,9 @@ public:
virtual PlaylistInterface::RepeatMode repeatMode() const { return m_repeatMode; }
virtual bool shuffled() const { return m_shuffled; }
bool showOfflineResults() const { return m_showOfflineResults; }
void setShowOfflineResults( bool b ) { m_showOfflineResults = b; }
PlItem* itemFromIndex( const QModelIndex& index ) const { return sourceModel()->itemFromIndex( index ); }
signals:
@ -60,6 +63,7 @@ private:
TrackModel* m_model;
RepeatMode m_repeatMode;
bool m_shuffled;
bool m_showOfflineResults;
};
#endif // TRACKPROXYMODEL_H