1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-07 22:56:42 +02:00

add a loading animation when loading collections

This commit is contained in:
Leo Franchi
2011-03-16 19:07:19 -04:00
parent 861c08357e
commit 61a8f784d1
5 changed files with 52 additions and 4 deletions

View File

@@ -44,6 +44,22 @@ CollectionFlatModel::headerData( int section, Qt::Orientation orientation, int r
return TrackModel::headerData( section, orientation, role );
}
void
CollectionFlatModel::addCollections( const QList< collection_ptr >& collections )
{
qDebug() << Q_FUNC_INFO << "Adding collections!";
foreach( const collection_ptr& col, collections )
{
if( !col->isLoaded() )
m_loadingCollections << col.data();
addCollection( col );
}
if( m_loadingCollections.isEmpty() )
emit doneLoadingCollections();
}
void
CollectionFlatModel::addCollection( const collection_ptr& collection )
@@ -60,8 +76,12 @@ CollectionFlatModel::addCollection( const collection_ptr& collection )
if ( collection->isLoaded() )
onTracksAdded( collection->tracks() );
else
{
collection->tracks(); // data will arrive via signals
m_loadingCollections << collection.data();
}
if ( collection->source()->isLocal() )
setTitle( tr( "Your Collection" ) );
else
@@ -164,6 +184,13 @@ CollectionFlatModel::onTracksAdded( const QList<Tomahawk::query_ptr>& tracks )
{
qDebug() << Q_FUNC_INFO << tracks.count() << rowCount( QModelIndex() );
if( !m_loadingCollections.isEmpty() && sender() && qobject_cast< Collection* >( sender() ) ) { // we are keeping track and are called as a slot
m_loadingCollections.removeAll( qobject_cast< Collection* >( sender() ) );
if( m_loadingCollections.isEmpty() )
emit doneLoadingCollections();
}
bool kickOff = m_tracksToAdd.isEmpty();
m_tracksToAdd << tracks;

View File

@@ -34,6 +34,8 @@ public:
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 );
void removeCollection( const Tomahawk::collection_ptr& collection );
@@ -47,6 +49,7 @@ signals:
void itemSizeChanged( const QModelIndex& index );
void doneLoadingCollections();
private slots:
void onDataChanged();
@@ -60,6 +63,8 @@ private slots:
private:
QMap< Tomahawk::collection_ptr, QPair< int, int > > m_collectionRows;
QList<Tomahawk::query_ptr> m_tracksToAdd;
// just to keep track of what we are waiting to be loaded
QList<Tomahawk::Collection*> m_loadingCollections;
};
#endif // COLLECTIONFLATMODEL_H

View File

@@ -41,6 +41,7 @@ LoadingSpinner::LoadingSpinner( QWidget* parent )
connect( m_anim, SIGNAL( frameChanged( int ) ), this, SLOT( update() ) );
setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
hide();
}
@@ -96,6 +97,7 @@ LoadingSpinner::reposition()
int x = ( parentWidget()->width() / 2 ) - ( width() / 2 );
int y = ( parentWidget()->height() / 2 ) - ( height() / 2 );
move( x, y );
resize( 64, 64 );
}

View File

@@ -27,6 +27,7 @@
#include "widgets/welcomewidget.h"
#include "widgets/infowidgets/sourceinfowidget.h"
#include "dynamic/widgets/LoadingSpinner.h"
#define FILTER_TIMEOUT 280
@@ -47,6 +48,7 @@ PlaylistManager::PlaylistManager( QObject* parent )
, m_widget( new QWidget() )
, m_welcomeWidget( new WelcomeWidget() )
, m_currentMode( 0 )
, m_loadingSpinner( 0 )
{
s_instance = this;
@@ -99,6 +101,9 @@ PlaylistManager::PlaylistManager( QObject* parent )
m_widget->layout()->setMargin( 0 );
m_widget->layout()->setSpacing( 0 );
m_loadingSpinner = new LoadingSpinner( m_widget );
connect( m_superCollectionFlatModel, SIGNAL( doneLoadingCollections() ), m_loadingSpinner, SLOT( fadeOut() ) );
connect( &m_filterTimer, SIGNAL( timeout() ), SLOT( applyFilter() ) );
connect( m_topbar, SIGNAL( filterTextChanged( QString ) ),
@@ -252,6 +257,9 @@ PlaylistManager::show( const Tomahawk::collection_ptr& collection )
view->setAttribute( Qt::WA_MacShowFocusRect, 0 );
model->addCollection( collection );
m_loadingSpinner->fadeIn();
connect( model, SIGNAL( doneLoadingCollections() ), m_loadingSpinner, SLOT( fadeOut() ) );
m_collectionViews.insert( collection, view );
}
else
@@ -328,18 +336,20 @@ PlaylistManager::show( ViewPage* page )
bool
PlaylistManager::showSuperCollection()
{
QList< collection_ptr > toAdd;
foreach( const Tomahawk::source_ptr& source, SourceList::instance()->sources() )
{
if ( !m_superCollections.contains( source->collection() ) )
{
m_superCollections.append( source->collection() );
m_superCollectionFlatModel->addCollection( source->collection() );
toAdd << source->collection();
m_superAlbumModel->addCollection( source->collection() );
}
m_superCollectionFlatModel->setTitle( tr( "All available tracks" ) );
m_superAlbumModel->setTitle( tr( "All available albums" ) );
}
m_superCollectionFlatModel->addCollections( toAdd );
if ( m_currentMode == 0 )
{
@@ -350,6 +360,8 @@ PlaylistManager::showSuperCollection()
setPage( m_superAlbumView );
}
m_loadingSpinner->fadeIn();
emit numSourcesChanged( m_superCollections.count() );
return true;

View File

@@ -11,6 +11,7 @@
#include "dllmacro.h"
class LoadingSpinner;
class AnimatedSplitter;
class AlbumModel;
class AlbumView;
@@ -143,6 +144,7 @@ private:
CollectionFlatModel* m_superCollectionFlatModel;
CollectionView* m_superCollectionView;
WelcomeWidget* m_welcomeWidget;
LoadingSpinner* m_loadingSpinner;
QList< Tomahawk::collection_ptr > m_superCollections;