mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-06 14:16:32 +02:00
* Queue refreshs in RecentPlaylistsModel. Prevents nasty flickering on startup.
This commit is contained in:
@@ -29,6 +29,8 @@
|
|||||||
#include "RecentlyPlayedPlaylistsModel.h"
|
#include "RecentlyPlayedPlaylistsModel.h"
|
||||||
#include <network/servent.h>
|
#include <network/servent.h>
|
||||||
|
|
||||||
|
#define REFRESH_TIMEOUT 1000
|
||||||
|
|
||||||
using namespace Tomahawk;
|
using namespace Tomahawk;
|
||||||
|
|
||||||
|
|
||||||
@@ -36,15 +38,31 @@ RecentPlaylistsModel::RecentPlaylistsModel( unsigned int maxPlaylists, QObject*
|
|||||||
: QAbstractListModel( parent )
|
: QAbstractListModel( parent )
|
||||||
, m_maxPlaylists( maxPlaylists )
|
, m_maxPlaylists( maxPlaylists )
|
||||||
{
|
{
|
||||||
|
m_timer = new QTimer( this );
|
||||||
|
|
||||||
|
connect( m_timer, SIGNAL( timeout() ), SLOT( onRefresh() ) );
|
||||||
connect( SourceList::instance(), SIGNAL( ready() ), SLOT( onReady() ) );
|
connect( SourceList::instance(), SIGNAL( ready() ), SLOT( onReady() ) );
|
||||||
|
|
||||||
// Load recent playlists initially
|
// Load recent playlists initially
|
||||||
refresh();
|
onRefresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
RecentPlaylistsModel::refresh()
|
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() );
|
DatabaseCommand_LoadAllSortedPlaylists* cmd = new DatabaseCommand_LoadAllSortedPlaylists( source_ptr() );
|
||||||
cmd->setLimit( 15 );
|
cmd->setLimit( 15 );
|
||||||
cmd->setSortOrder( DatabaseCommand_LoadAllPlaylists::ModificationTime );
|
cmd->setSortOrder( DatabaseCommand_LoadAllPlaylists::ModificationTime );
|
||||||
@@ -53,6 +71,7 @@ RecentPlaylistsModel::refresh()
|
|||||||
Database::instance()->enqueue( QSharedPointer< DatabaseCommand >( cmd ) );
|
Database::instance()->enqueue( QSharedPointer< DatabaseCommand >( cmd ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
RecentPlaylistsModel::onReady()
|
RecentPlaylistsModel::onReady()
|
||||||
{
|
{
|
||||||
@@ -60,7 +79,7 @@ RecentPlaylistsModel::onReady()
|
|||||||
onSourceAdded( s );
|
onSourceAdded( s );
|
||||||
|
|
||||||
connect( SourceList::instance(), SIGNAL( sourceAdded( Tomahawk::source_ptr ) ), this, SLOT( onSourceAdded( Tomahawk::source_ptr ) ), Qt::QueuedConnection );
|
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
|
void
|
||||||
RecentPlaylistsModel::updatePlaylist()
|
RecentPlaylistsModel::updatePlaylist()
|
||||||
{
|
{
|
||||||
@@ -176,6 +196,7 @@ RecentPlaylistsModel::updatePlaylist()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
RecentPlaylistsModel::onSourceAdded( const Tomahawk::source_ptr& source )
|
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> ) ) );
|
connect( source->collection().data(), SIGNAL( stationsDeleted(QList<Tomahawk::dynplaylist_ptr>) ), SLOT( onDynPlaylistsRemoved( QList<Tomahawk::dynplaylist_ptr> ) ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
RecentPlaylistsModel::sourceOnline()
|
RecentPlaylistsModel::sourceOnline()
|
||||||
{
|
{
|
||||||
@@ -204,12 +226,14 @@ RecentPlaylistsModel::sourceOnline()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
RecentPlaylistsModel::onDynPlaylistsRemoved( QList< dynplaylist_ptr > playlists )
|
RecentPlaylistsModel::onDynPlaylistsRemoved( QList< dynplaylist_ptr > playlists )
|
||||||
{
|
{
|
||||||
QList< playlist_ptr > pls;
|
QList< playlist_ptr > pls;
|
||||||
foreach( const dynplaylist_ptr& p, playlists )
|
foreach( const dynplaylist_ptr& p, playlists )
|
||||||
pls << p;
|
pls << p;
|
||||||
|
|
||||||
onPlaylistsRemoved( pls );
|
onPlaylistsRemoved( pls );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -217,8 +241,10 @@ RecentPlaylistsModel::onDynPlaylistsRemoved( QList< dynplaylist_ptr > playlists
|
|||||||
void
|
void
|
||||||
RecentPlaylistsModel::onPlaylistsRemoved( QList< playlist_ptr > playlists )
|
RecentPlaylistsModel::onPlaylistsRemoved( QList< playlist_ptr > playlists )
|
||||||
{
|
{
|
||||||
foreach( const playlist_ptr& pl, playlists ) {
|
foreach( const playlist_ptr& pl, playlists )
|
||||||
if( m_playlists.contains( pl ) ) {
|
{
|
||||||
|
if( m_playlists.contains( pl ) )
|
||||||
|
{
|
||||||
m_artists.remove( pl );
|
m_artists.remove( pl );
|
||||||
|
|
||||||
int idx = m_playlists.indexOf( pl );
|
int idx = m_playlists.indexOf( pl );
|
||||||
|
@@ -21,6 +21,7 @@
|
|||||||
#define RECENTLPLAYLISTSMODEL_H
|
#define RECENTLPLAYLISTSMODEL_H
|
||||||
|
|
||||||
#include <QModelIndex>
|
#include <QModelIndex>
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
#include "playlist.h"
|
#include "playlist.h"
|
||||||
#include "database/databasecommand_loadallsortedplaylists.h"
|
#include "database/databasecommand_loadallsortedplaylists.h"
|
||||||
@@ -36,12 +37,13 @@ public:
|
|||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void refresh();
|
void refresh();
|
||||||
void onReady();
|
void onReady();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void emptinessChanged( bool isEmpty );
|
void emptinessChanged( bool isEmpty );
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
void onRefresh();
|
||||||
void playlistsLoaded( const QList<DatabaseCommand_LoadAllSortedPlaylists::SourcePlaylistPair>& playlistGuids );
|
void playlistsLoaded( const QList<DatabaseCommand_LoadAllSortedPlaylists::SourcePlaylistPair>& playlistGuids );
|
||||||
|
|
||||||
void onPlaylistsRemoved( QList< Tomahawk::playlist_ptr > playlists );
|
void onPlaylistsRemoved( QList< Tomahawk::playlist_ptr > playlists );
|
||||||
@@ -50,10 +52,12 @@ private slots:
|
|||||||
|
|
||||||
void sourceOnline();
|
void sourceOnline();
|
||||||
void onSourceAdded( const Tomahawk::source_ptr& source );
|
void onSourceAdded( const Tomahawk::source_ptr& source );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QList< Tomahawk::playlist_ptr > m_playlists;
|
QList< Tomahawk::playlist_ptr > m_playlists;
|
||||||
mutable QHash< Tomahawk::playlist_ptr, QString > m_artists;
|
mutable QHash< Tomahawk::playlist_ptr, QString > m_artists;
|
||||||
unsigned int m_maxPlaylists;
|
unsigned int m_maxPlaylists;
|
||||||
|
QTimer* m_timer;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // RECENTLPLAYLISTSMODEL_H
|
#endif // RECENTLPLAYLISTSMODEL_H
|
||||||
|
@@ -73,7 +73,7 @@ SourceInfoWidget::SourceInfoWidget( const Tomahawk::source_ptr& source, QWidget*
|
|||||||
}
|
}
|
||||||
else
|
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" );
|
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( ready() ), SLOT( updateRecentTracks() ) );
|
||||||
connect( SourceList::instance(), SIGNAL( sourceAdded( Tomahawk::source_ptr ) ), SLOT( onSourceAdded( Tomahawk::source_ptr ) ) );
|
connect( SourceList::instance(), SIGNAL( sourceAdded( Tomahawk::source_ptr ) ), SLOT( onSourceAdded( Tomahawk::source_ptr ) ) );
|
||||||
connect( ui->playlistWidget, SIGNAL( activated( QModelIndex ) ), SLOT( onPlaylistActivated( QModelIndex ) ) );
|
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() ) );
|
connect( SourceList::instance()->getLocal().data(), SIGNAL( stats( QVariantMap ) ), this, SLOT( updateRecentAdditions() ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
WelcomeWidget::updateRecentAdditions()
|
WelcomeWidget::updateRecentAdditions()
|
||||||
{
|
{
|
||||||
@@ -116,19 +117,6 @@ WelcomeWidget::updateRecentAdditions()
|
|||||||
void
|
void
|
||||||
WelcomeWidget::updatePlaylists()
|
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() );
|
int num = ui->playlistWidget->model()->rowCount( QModelIndex() );
|
||||||
if ( num == 0 )
|
if ( num == 0 )
|
||||||
{
|
{
|
||||||
@@ -150,7 +138,9 @@ WelcomeWidget::onSourceAdded( const Tomahawk::source_ptr& source )
|
|||||||
void
|
void
|
||||||
WelcomeWidget::checkQueries()
|
WelcomeWidget::checkQueries()
|
||||||
{
|
{
|
||||||
m_timer->stop();
|
if ( m_timer->isActive() )
|
||||||
|
m_timer->stop();
|
||||||
|
|
||||||
m_tracksModel->ensureResolved();
|
m_tracksModel->ensureResolved();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user