1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-22 05:33:32 +02:00

Don't create a timer with a 0ms timeout, that's not nice

This commit is contained in:
Leo Franchi
2012-04-06 21:22:51 -04:00
parent fd81151996
commit e4b90e6305
2 changed files with 25 additions and 9 deletions

View File

@@ -69,14 +69,13 @@ PlaylistUpdaterInterface::loadForPlaylist( const playlist_ptr& pl )
PlaylistUpdaterInterface::PlaylistUpdaterInterface( const playlist_ptr& pl )
: QObject( 0 )
, m_timer( new QTimer( this ) )
, m_timer( 0 )
, m_autoUpdate( true )
, m_playlist( pl )
{
Q_ASSERT( !m_playlist.isNull() );
m_playlist->setUpdater( this );
connect( m_timer, SIGNAL( timeout() ), this, SLOT( updateNow() ) );
QTimer::singleShot( 0, this, SLOT( doSave() ) );
}
@@ -106,7 +105,7 @@ PlaylistUpdaterInterface::doSave()
{
s->setValue( QString( "%1/type" ).arg( key ), type() );
s->setValue( QString( "%1/autoupdate" ).arg( key ), m_autoUpdate );
s->setValue( QString( "%1/interval" ).arg( key ), m_timer->interval() );
s->setValue( QString( "%1/interval" ).arg( key ), m_timer ? m_timer->interval() : -1 );
saveToSettings( key );
}
}
@@ -132,10 +131,14 @@ void
PlaylistUpdaterInterface::setAutoUpdate( bool autoUpdate )
{
m_autoUpdate = autoUpdate;
if ( m_timer )
{
if ( m_autoUpdate )
m_timer->start();
else
m_timer->stop();
}
const QString key = QString( "playlistupdaters/%1/autoupdate" ).arg( m_playlist->guid() );
TomahawkSettings::instance()->setValue( key, m_autoUpdate );
@@ -151,6 +154,17 @@ PlaylistUpdaterInterface::setInterval( int intervalMsecs )
const QString key = QString( "playlistupdaters/%1/interval" ).arg( m_playlist->guid() );
TomahawkSettings::instance()->setValue( key, intervalMsecs );
if ( intervalMsecs == -1 )
{
if ( m_timer )
delete m_timer;
return;
}
if ( !m_timer )
m_timer = new QTimer( this );
m_timer->setInterval( intervalMsecs );
}

View File

@@ -29,9 +29,9 @@
namespace Tomahawk
{
/**
* If a playlist needs periodic updating, implement a updater interface.
* If a playlist needs updating, implement a updater interface.
*
* Default is auto-updating.
* Default is auto-updating and on a periodic timer.
*/
class PlaylistUpdaterFactory;
@@ -40,7 +40,9 @@ class DLLEXPORT PlaylistUpdaterInterface : public QObject
{
Q_OBJECT
public:
// No periodic updating
PlaylistUpdaterInterface( const playlist_ptr& pl );
// Periodic updating based on interval
PlaylistUpdaterInterface( const playlist_ptr& pl, int interval, bool autoUpdate );
virtual ~PlaylistUpdaterInterface(){}