mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-08 07:07:05 +02:00
add a loading animation when loading collections
This commit is contained in:
@@ -44,6 +44,22 @@ CollectionFlatModel::headerData( int section, Qt::Orientation orientation, int r
|
|||||||
return TrackModel::headerData( section, orientation, role );
|
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
|
void
|
||||||
CollectionFlatModel::addCollection( const collection_ptr& collection )
|
CollectionFlatModel::addCollection( const collection_ptr& collection )
|
||||||
@@ -60,8 +76,12 @@ CollectionFlatModel::addCollection( const collection_ptr& collection )
|
|||||||
if ( collection->isLoaded() )
|
if ( collection->isLoaded() )
|
||||||
onTracksAdded( collection->tracks() );
|
onTracksAdded( collection->tracks() );
|
||||||
else
|
else
|
||||||
|
{
|
||||||
collection->tracks(); // data will arrive via signals
|
collection->tracks(); // data will arrive via signals
|
||||||
|
|
||||||
|
m_loadingCollections << collection.data();
|
||||||
|
}
|
||||||
|
|
||||||
if ( collection->source()->isLocal() )
|
if ( collection->source()->isLocal() )
|
||||||
setTitle( tr( "Your Collection" ) );
|
setTitle( tr( "Your Collection" ) );
|
||||||
else
|
else
|
||||||
@@ -164,6 +184,13 @@ CollectionFlatModel::onTracksAdded( const QList<Tomahawk::query_ptr>& tracks )
|
|||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO << tracks.count() << rowCount( QModelIndex() );
|
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();
|
bool kickOff = m_tracksToAdd.isEmpty();
|
||||||
m_tracksToAdd << tracks;
|
m_tracksToAdd << tracks;
|
||||||
|
|
||||||
|
@@ -34,6 +34,8 @@ public:
|
|||||||
QVariant data( const QModelIndex& index, int role ) const;
|
QVariant data( const QModelIndex& index, int role ) const;
|
||||||
QVariant headerData( int section, Qt::Orientation orientation, 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 addCollection( const Tomahawk::collection_ptr& collection );
|
||||||
void removeCollection( const Tomahawk::collection_ptr& collection );
|
void removeCollection( const Tomahawk::collection_ptr& collection );
|
||||||
|
|
||||||
@@ -47,6 +49,7 @@ signals:
|
|||||||
|
|
||||||
void itemSizeChanged( const QModelIndex& index );
|
void itemSizeChanged( const QModelIndex& index );
|
||||||
|
|
||||||
|
void doneLoadingCollections();
|
||||||
private slots:
|
private slots:
|
||||||
void onDataChanged();
|
void onDataChanged();
|
||||||
|
|
||||||
@@ -60,6 +63,8 @@ private slots:
|
|||||||
private:
|
private:
|
||||||
QMap< Tomahawk::collection_ptr, QPair< int, int > > m_collectionRows;
|
QMap< Tomahawk::collection_ptr, QPair< int, int > > m_collectionRows;
|
||||||
QList<Tomahawk::query_ptr> m_tracksToAdd;
|
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
|
#endif // COLLECTIONFLATMODEL_H
|
||||||
|
@@ -41,6 +41,7 @@ LoadingSpinner::LoadingSpinner( QWidget* parent )
|
|||||||
|
|
||||||
connect( m_anim, SIGNAL( frameChanged( int ) ), this, SLOT( update() ) );
|
connect( m_anim, SIGNAL( frameChanged( int ) ), this, SLOT( update() ) );
|
||||||
|
|
||||||
|
setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
|
||||||
hide();
|
hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,6 +97,7 @@ LoadingSpinner::reposition()
|
|||||||
int x = ( parentWidget()->width() / 2 ) - ( width() / 2 );
|
int x = ( parentWidget()->width() / 2 ) - ( width() / 2 );
|
||||||
int y = ( parentWidget()->height() / 2 ) - ( height() / 2 );
|
int y = ( parentWidget()->height() / 2 ) - ( height() / 2 );
|
||||||
move( x, y );
|
move( x, y );
|
||||||
|
resize( 64, 64 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -27,6 +27,7 @@
|
|||||||
|
|
||||||
#include "widgets/welcomewidget.h"
|
#include "widgets/welcomewidget.h"
|
||||||
#include "widgets/infowidgets/sourceinfowidget.h"
|
#include "widgets/infowidgets/sourceinfowidget.h"
|
||||||
|
#include "dynamic/widgets/LoadingSpinner.h"
|
||||||
|
|
||||||
#define FILTER_TIMEOUT 280
|
#define FILTER_TIMEOUT 280
|
||||||
|
|
||||||
@@ -47,6 +48,7 @@ PlaylistManager::PlaylistManager( QObject* parent )
|
|||||||
, m_widget( new QWidget() )
|
, m_widget( new QWidget() )
|
||||||
, m_welcomeWidget( new WelcomeWidget() )
|
, m_welcomeWidget( new WelcomeWidget() )
|
||||||
, m_currentMode( 0 )
|
, m_currentMode( 0 )
|
||||||
|
, m_loadingSpinner( 0 )
|
||||||
{
|
{
|
||||||
s_instance = this;
|
s_instance = this;
|
||||||
|
|
||||||
@@ -99,6 +101,9 @@ PlaylistManager::PlaylistManager( QObject* parent )
|
|||||||
m_widget->layout()->setMargin( 0 );
|
m_widget->layout()->setMargin( 0 );
|
||||||
m_widget->layout()->setSpacing( 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_filterTimer, SIGNAL( timeout() ), SLOT( applyFilter() ) );
|
||||||
|
|
||||||
connect( m_topbar, SIGNAL( filterTextChanged( QString ) ),
|
connect( m_topbar, SIGNAL( filterTextChanged( QString ) ),
|
||||||
@@ -252,6 +257,9 @@ PlaylistManager::show( const Tomahawk::collection_ptr& collection )
|
|||||||
view->setAttribute( Qt::WA_MacShowFocusRect, 0 );
|
view->setAttribute( Qt::WA_MacShowFocusRect, 0 );
|
||||||
model->addCollection( collection );
|
model->addCollection( collection );
|
||||||
|
|
||||||
|
m_loadingSpinner->fadeIn();
|
||||||
|
connect( model, SIGNAL( doneLoadingCollections() ), m_loadingSpinner, SLOT( fadeOut() ) );
|
||||||
|
|
||||||
m_collectionViews.insert( collection, view );
|
m_collectionViews.insert( collection, view );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -328,18 +336,20 @@ PlaylistManager::show( ViewPage* page )
|
|||||||
bool
|
bool
|
||||||
PlaylistManager::showSuperCollection()
|
PlaylistManager::showSuperCollection()
|
||||||
{
|
{
|
||||||
|
QList< collection_ptr > toAdd;
|
||||||
foreach( const Tomahawk::source_ptr& source, SourceList::instance()->sources() )
|
foreach( const Tomahawk::source_ptr& source, SourceList::instance()->sources() )
|
||||||
{
|
{
|
||||||
if ( !m_superCollections.contains( source->collection() ) )
|
if ( !m_superCollections.contains( source->collection() ) )
|
||||||
{
|
{
|
||||||
m_superCollections.append( source->collection() );
|
m_superCollections.append( source->collection() );
|
||||||
m_superCollectionFlatModel->addCollection( source->collection() );
|
toAdd << source->collection();
|
||||||
m_superAlbumModel->addCollection( source->collection() );
|
m_superAlbumModel->addCollection( source->collection() );
|
||||||
}
|
}
|
||||||
|
|
||||||
m_superCollectionFlatModel->setTitle( tr( "All available tracks" ) );
|
m_superCollectionFlatModel->setTitle( tr( "All available tracks" ) );
|
||||||
m_superAlbumModel->setTitle( tr( "All available albums" ) );
|
m_superAlbumModel->setTitle( tr( "All available albums" ) );
|
||||||
}
|
}
|
||||||
|
m_superCollectionFlatModel->addCollections( toAdd );
|
||||||
|
|
||||||
if ( m_currentMode == 0 )
|
if ( m_currentMode == 0 )
|
||||||
{
|
{
|
||||||
@@ -350,6 +360,8 @@ PlaylistManager::showSuperCollection()
|
|||||||
setPage( m_superAlbumView );
|
setPage( m_superAlbumView );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_loadingSpinner->fadeIn();
|
||||||
|
|
||||||
emit numSourcesChanged( m_superCollections.count() );
|
emit numSourcesChanged( m_superCollections.count() );
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
#include "dllmacro.h"
|
#include "dllmacro.h"
|
||||||
|
|
||||||
|
class LoadingSpinner;
|
||||||
class AnimatedSplitter;
|
class AnimatedSplitter;
|
||||||
class AlbumModel;
|
class AlbumModel;
|
||||||
class AlbumView;
|
class AlbumView;
|
||||||
@@ -143,6 +144,7 @@ private:
|
|||||||
CollectionFlatModel* m_superCollectionFlatModel;
|
CollectionFlatModel* m_superCollectionFlatModel;
|
||||||
CollectionView* m_superCollectionView;
|
CollectionView* m_superCollectionView;
|
||||||
WelcomeWidget* m_welcomeWidget;
|
WelcomeWidget* m_welcomeWidget;
|
||||||
|
LoadingSpinner* m_loadingSpinner;
|
||||||
|
|
||||||
QList< Tomahawk::collection_ptr > m_superCollections;
|
QList< Tomahawk::collection_ptr > m_superCollections;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user