mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-23 01:09:42 +01:00
* Queue refreshs in RecentPlaylistsModel. Prevents nasty flickering on startup.
This commit is contained in:
parent
c0183aa359
commit
98aaec0ffd
@ -29,6 +29,8 @@
|
||||
#include "RecentlyPlayedPlaylistsModel.h"
|
||||
#include <network/servent.h>
|
||||
|
||||
#define REFRESH_TIMEOUT 1000
|
||||
|
||||
using namespace Tomahawk;
|
||||
|
||||
|
||||
@ -36,15 +38,31 @@ RecentPlaylistsModel::RecentPlaylistsModel( unsigned int maxPlaylists, QObject*
|
||||
: QAbstractListModel( parent )
|
||||
, m_maxPlaylists( maxPlaylists )
|
||||
{
|
||||
m_timer = new QTimer( this );
|
||||
|
||||
connect( m_timer, SIGNAL( timeout() ), SLOT( onRefresh() ) );
|
||||
connect( SourceList::instance(), SIGNAL( ready() ), SLOT( onReady() ) );
|
||||
|
||||
// Load recent playlists initially
|
||||
refresh();
|
||||
onRefresh();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
RecentPlaylistsModel::refresh()
|
||||
{
|
||||
if ( m_timer->isActive() )
|
||||
m_timer->stop();
|
||||
m_timer->start( REFRESH_TIMEOUT );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
RecentPlaylistsModel::onRefresh()
|
||||
{
|
||||
if ( m_timer->isActive() )
|
||||
m_timer->stop();
|
||||
|
||||
DatabaseCommand_LoadAllSortedPlaylists* cmd = new DatabaseCommand_LoadAllSortedPlaylists( source_ptr() );
|
||||
cmd->setLimit( 15 );
|
||||
cmd->setSortOrder( DatabaseCommand_LoadAllPlaylists::ModificationTime );
|
||||
@ -53,6 +71,7 @@ RecentPlaylistsModel::refresh()
|
||||
Database::instance()->enqueue( QSharedPointer< DatabaseCommand >( cmd ) );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
RecentPlaylistsModel::onReady()
|
||||
{
|
||||
@ -60,7 +79,7 @@ RecentPlaylistsModel::onReady()
|
||||
onSourceAdded( s );
|
||||
|
||||
connect( SourceList::instance(), SIGNAL( sourceAdded( Tomahawk::source_ptr ) ), this, SLOT( onSourceAdded( Tomahawk::source_ptr ) ), Qt::QueuedConnection );
|
||||
refresh();
|
||||
onRefresh();
|
||||
}
|
||||
|
||||
|
||||
@ -160,6 +179,7 @@ RecentPlaylistsModel::data( const QModelIndex& index, int role ) const
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
RecentPlaylistsModel::updatePlaylist()
|
||||
{
|
||||
@ -176,6 +196,7 @@ RecentPlaylistsModel::updatePlaylist()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
RecentPlaylistsModel::onSourceAdded( const Tomahawk::source_ptr& source )
|
||||
{
|
||||
@ -188,6 +209,7 @@ RecentPlaylistsModel::onSourceAdded( const Tomahawk::source_ptr& source )
|
||||
connect( source->collection().data(), SIGNAL( stationsDeleted(QList<Tomahawk::dynplaylist_ptr>) ), SLOT( onDynPlaylistsRemoved( QList<Tomahawk::dynplaylist_ptr> ) ) );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
RecentPlaylistsModel::sourceOnline()
|
||||
{
|
||||
@ -204,12 +226,14 @@ RecentPlaylistsModel::sourceOnline()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
RecentPlaylistsModel::onDynPlaylistsRemoved( QList< dynplaylist_ptr > playlists )
|
||||
{
|
||||
QList< playlist_ptr > pls;
|
||||
foreach( const dynplaylist_ptr& p, playlists )
|
||||
pls << p;
|
||||
|
||||
onPlaylistsRemoved( pls );
|
||||
}
|
||||
|
||||
@ -217,8 +241,10 @@ RecentPlaylistsModel::onDynPlaylistsRemoved( QList< dynplaylist_ptr > playlists
|
||||
void
|
||||
RecentPlaylistsModel::onPlaylistsRemoved( QList< playlist_ptr > playlists )
|
||||
{
|
||||
foreach( const playlist_ptr& pl, playlists ) {
|
||||
if( m_playlists.contains( pl ) ) {
|
||||
foreach( const playlist_ptr& pl, playlists )
|
||||
{
|
||||
if( m_playlists.contains( pl ) )
|
||||
{
|
||||
m_artists.remove( pl );
|
||||
|
||||
int idx = m_playlists.indexOf( pl );
|
||||
|
@ -21,6 +21,7 @@
|
||||
#define RECENTLPLAYLISTSMODEL_H
|
||||
|
||||
#include <QModelIndex>
|
||||
#include <QTimer>
|
||||
|
||||
#include "playlist.h"
|
||||
#include "database/databasecommand_loadallsortedplaylists.h"
|
||||
@ -36,12 +37,13 @@ public:
|
||||
|
||||
public slots:
|
||||
void refresh();
|
||||
void onReady();
|
||||
void onReady();
|
||||
|
||||
signals:
|
||||
void emptinessChanged( bool isEmpty );
|
||||
|
||||
private slots:
|
||||
void onRefresh();
|
||||
void playlistsLoaded( const QList<DatabaseCommand_LoadAllSortedPlaylists::SourcePlaylistPair>& playlistGuids );
|
||||
|
||||
void onPlaylistsRemoved( QList< Tomahawk::playlist_ptr > playlists );
|
||||
@ -50,10 +52,12 @@ private slots:
|
||||
|
||||
void sourceOnline();
|
||||
void onSourceAdded( const Tomahawk::source_ptr& source );
|
||||
|
||||
private:
|
||||
QList< Tomahawk::playlist_ptr > m_playlists;
|
||||
mutable QHash< Tomahawk::playlist_ptr, QString > m_artists;
|
||||
unsigned int m_maxPlaylists;
|
||||
QTimer* m_timer;
|
||||
};
|
||||
|
||||
#endif // RECENTLPLAYLISTSMODEL_H
|
||||
|
@ -73,7 +73,7 @@ SourceInfoWidget::SourceInfoWidget( const Tomahawk::source_ptr& source, QWidget*
|
||||
}
|
||||
else
|
||||
{
|
||||
m_description = tr( "Recent activity from %1" ).arg( source->friendlyName() );
|
||||
m_description = tr( "Recent activity from %1" ).arg( source->friendlyName() );
|
||||
}
|
||||
|
||||
m_pixmap.load( RESPATH "images/new-additions.png" );
|
||||
|
@ -88,7 +88,7 @@ WelcomeWidget::WelcomeWidget( QWidget* parent )
|
||||
connect( SourceList::instance(), SIGNAL( ready() ), SLOT( updateRecentTracks() ) );
|
||||
connect( SourceList::instance(), SIGNAL( sourceAdded( Tomahawk::source_ptr ) ), SLOT( onSourceAdded( Tomahawk::source_ptr ) ) );
|
||||
connect( ui->playlistWidget, SIGNAL( activated( QModelIndex ) ), SLOT( onPlaylistActivated( QModelIndex ) ) );
|
||||
connect( AudioEngine::instance() ,SIGNAL( playlistChanged( Tomahawk::PlaylistInterface* ) ), this, SLOT( updatePlaylists() ), Qt::QueuedConnection );
|
||||
connect( AudioEngine::instance() ,SIGNAL( playlistChanged( Tomahawk::PlaylistInterface* ) ), SLOT( updatePlaylists() ), Qt::QueuedConnection );
|
||||
}
|
||||
|
||||
|
||||
@ -106,6 +106,7 @@ WelcomeWidget::updateRecentTracks()
|
||||
connect( SourceList::instance()->getLocal().data(), SIGNAL( stats( QVariantMap ) ), this, SLOT( updateRecentAdditions() ) );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
WelcomeWidget::updateRecentAdditions()
|
||||
{
|
||||
@ -116,19 +117,6 @@ WelcomeWidget::updateRecentAdditions()
|
||||
void
|
||||
WelcomeWidget::updatePlaylists()
|
||||
{
|
||||
// ui->playlistWidget->clear();
|
||||
|
||||
// QList<Tomahawk::playlist_ptr> playlists = TomahawkSettings::instance()->recentlyPlayedPlaylists();
|
||||
/*
|
||||
foreach( const Tomahawk::playlist_ptr& playlist, playlists )
|
||||
{
|
||||
connect( playlist.data(), SIGNAL( revisionLoaded( Tomahawk::PlaylistRevision ) ), SLOT( refresh() ) );
|
||||
|
||||
PlaylistWidgetItem* item = new PlaylistWidgetItem( playlist );
|
||||
ui->playlistWidget->addItem( item );
|
||||
item->setData( Qt::DisplayRole, playlist->title() );
|
||||
}*/
|
||||
|
||||
int num = ui->playlistWidget->model()->rowCount( QModelIndex() );
|
||||
if ( num == 0 )
|
||||
{
|
||||
@ -150,7 +138,9 @@ WelcomeWidget::onSourceAdded( const Tomahawk::source_ptr& source )
|
||||
void
|
||||
WelcomeWidget::checkQueries()
|
||||
{
|
||||
m_timer->stop();
|
||||
if ( m_timer->isActive() )
|
||||
m_timer->stop();
|
||||
|
||||
m_tracksModel->ensureResolved();
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user