From e4b90e630590da435e507cb38028248bf806226c Mon Sep 17 00:00:00 2001 From: Leo Franchi Date: Fri, 6 Apr 2012 21:22:51 -0400 Subject: [PATCH] Don't create a timer with a 0ms timeout, that's not nice --- .../playlist/PlaylistUpdaterInterface.cpp | 28 ++++++++++++++----- .../playlist/PlaylistUpdaterInterface.h | 6 ++-- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/src/libtomahawk/playlist/PlaylistUpdaterInterface.cpp b/src/libtomahawk/playlist/PlaylistUpdaterInterface.cpp index 56a8a688e..8b0d0b692 100644 --- a/src/libtomahawk/playlist/PlaylistUpdaterInterface.cpp +++ b/src/libtomahawk/playlist/PlaylistUpdaterInterface.cpp @@ -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_autoUpdate ) - m_timer->start(); - else - m_timer->stop(); + + 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 ); } diff --git a/src/libtomahawk/playlist/PlaylistUpdaterInterface.h b/src/libtomahawk/playlist/PlaylistUpdaterInterface.h index c4d053fef..79f3c7986 100644 --- a/src/libtomahawk/playlist/PlaylistUpdaterInterface.h +++ b/src/libtomahawk/playlist/PlaylistUpdaterInterface.h @@ -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(){}