1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-07 06:36:55 +02:00

Refactor playlist updater system to make it more generic

Updaters aren't necessarily timer-based, and each updater provides its own
configuration widget, as a checkbox might not always make sense
This commit is contained in:
Leo Franchi
2012-04-07 00:14:42 -04:00
parent 30791e9bdc
commit cfcdbbb728
15 changed files with 174 additions and 192 deletions

View File

@@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>403</width> <width>419</width>
<height>439</height> <height>454</height>
</rect> </rect>
</property> </property>
<property name="sizePolicy"> <property name="sizePolicy">

View File

@@ -25,7 +25,7 @@ using namespace Tomahawk;
using namespace Accounts; using namespace Accounts;
Tomahawk::PlaylistUpdaterInterface* Tomahawk::PlaylistUpdaterInterface*
SpotifyUpdaterFactory::create( const Tomahawk::playlist_ptr& pl ) SpotifyUpdaterFactory::create( const Tomahawk::playlist_ptr& pl, const QString &key )
{ {
if ( !m_account ) if ( !m_account )
{ {
@@ -47,25 +47,19 @@ SpotifyUpdaterFactory::create( const Tomahawk::playlist_ptr& pl )
} }
// Register the updater with the account // Register the updater with the account
const QString spotifyId = TomahawkSettings::instance()->value( QString( "playlistupdaters/%1/spotifyId" ).arg( pl->guid() ) ).toString(); const QString spotifyId = TomahawkSettings::instance()->value( QString( "%1/spotifyId" ).arg( key ) ).toString();
const QString latestRev = TomahawkSettings::instance()->value( QString( "%1/latestrev" ).arg( key ) ).toString();
const bool sync = TomahawkSettings::instance()->value( QString( "%1/sync" ).arg( key ) ).toBool();
Q_ASSERT( !spotifyId.isEmpty() ); Q_ASSERT( !spotifyId.isEmpty() );
SpotifyPlaylistUpdater* updater = new SpotifyPlaylistUpdater( m_account.data(), pl ); SpotifyPlaylistUpdater* updater = new SpotifyPlaylistUpdater( m_account.data(), latestRev, spotifyId, pl );
updater->setSync( sync );
m_account.data()->registerUpdaterForPlaylist( spotifyId, updater ); m_account.data()->registerUpdaterForPlaylist( spotifyId, updater );
return updater; return updater;
} }
SpotifyPlaylistUpdater::SpotifyPlaylistUpdater( SpotifyAccount* acct, const playlist_ptr& pl )
: PlaylistUpdaterInterface( pl )
, m_spotify( acct )
, m_sync( false )
{
// values will be loaded from settings
init();
}
SpotifyPlaylistUpdater::SpotifyPlaylistUpdater( SpotifyAccount* acct, const QString& revid, const QString& spotifyId, const playlist_ptr& pl ) SpotifyPlaylistUpdater::SpotifyPlaylistUpdater( SpotifyAccount* acct, const QString& revid, const QString& spotifyId, const playlist_ptr& pl )
: PlaylistUpdaterInterface( pl ) : PlaylistUpdaterInterface( pl )
, m_spotify( acct ) , m_spotify( acct )
@@ -94,13 +88,6 @@ SpotifyPlaylistUpdater::~SpotifyPlaylistUpdater()
} }
void
SpotifyPlaylistUpdater::loadFromSettings( const QString& group )
{
m_latestRev = TomahawkSettings::instance()->value( QString( "%1/latestrev" ).arg( group ) ).toString();
m_sync = TomahawkSettings::instance()->value( QString( "%1/sync" ).arg( group ) ).toBool();
m_spotifyId = TomahawkSettings::instance()->value( QString( "%1/spotifyId" ).arg( group ) ).toString();
}
void void
SpotifyPlaylistUpdater::removeFromSettings( const QString& group ) const SpotifyPlaylistUpdater::removeFromSettings( const QString& group ) const

View File

@@ -34,17 +34,17 @@ class SpotifyPlaylistUpdater : public Tomahawk::PlaylistUpdaterInterface
friend class Tomahawk::Accounts::SpotifyAccount; friend class Tomahawk::Accounts::SpotifyAccount;
public: public:
// used when creating anew
SpotifyPlaylistUpdater( Tomahawk::Accounts::SpotifyAccount* acct, const QString& revid, const QString& spotifyId, const Tomahawk::playlist_ptr& pl ); SpotifyPlaylistUpdater( Tomahawk::Accounts::SpotifyAccount* acct, const QString& revid, const QString& spotifyId, const Tomahawk::playlist_ptr& pl );
// used when inflating from config file
SpotifyPlaylistUpdater( Tomahawk::Accounts::SpotifyAccount* acct, const Tomahawk::playlist_ptr& pl );
virtual ~SpotifyPlaylistUpdater(); virtual ~SpotifyPlaylistUpdater();
virtual QString type() const; virtual QString type() const;
virtual void updateNow() {} virtual void updateNow() {}
#ifndef ENABLE_HEADLESS
virtual QWidget* configurationWidget() const { return 0; }
#endif
bool sync() const; bool sync() const;
void setSync( bool sync ); void setSync( bool sync );
@@ -56,7 +56,6 @@ public:
protected: protected:
virtual void removeFromSettings(const QString& group) const; virtual void removeFromSettings(const QString& group) const;
virtual void saveToSettings(const QString& group) const; virtual void saveToSettings(const QString& group) const;
virtual void loadFromSettings(const QString& group);
private slots: private slots:
void tomahawkTracksInserted( const QList<Tomahawk::plentry_ptr>& ,int ); void tomahawkTracksInserted( const QList<Tomahawk::plentry_ptr>& ,int );
@@ -87,7 +86,7 @@ class SpotifyUpdaterFactory : public Tomahawk::PlaylistUpdaterFactory
public: public:
SpotifyUpdaterFactory() {} SpotifyUpdaterFactory() {}
virtual Tomahawk::PlaylistUpdaterInterface* create( const Tomahawk::playlist_ptr& pl ); virtual Tomahawk::PlaylistUpdaterInterface* create( const Tomahawk::playlist_ptr& pl, const QString& key );
virtual QString type() const { return "spotify"; } virtual QString type() const { return "spotify"; }
private: private:

View File

@@ -37,6 +37,8 @@ accountTypeToString( AccountType type )
case InfoType: case InfoType:
case StatusPushType: case StatusPushType:
return QObject::tr( "Status Updaters" ); return QObject::tr( "Status Updaters" );
default:
return QString();
} }
return QString(); return QString();

View File

@@ -40,6 +40,8 @@ using namespace Tomahawk;
InfoBar::InfoBar( QWidget* parent ) InfoBar::InfoBar( QWidget* parent )
: QWidget( parent ) : QWidget( parent )
, ui( new Ui::InfoBar ) , ui( new Ui::InfoBar )
, m_updaterInterface( 0 )
, m_updaterConfiguration( 0 )
, m_queryLabel( 0 ) , m_queryLabel( 0 )
{ {
ui->setupUi( this ); ui->setupUi( this );
@@ -59,12 +61,12 @@ InfoBar::InfoBar( QWidget* parent )
regFont.setPixelSize( 11 ); regFont.setPixelSize( 11 );
ui->longDescriptionLabel->setFont( regFont ); ui->longDescriptionLabel->setFont( regFont );
QPalette whitePal = ui->captionLabel->palette(); m_whitePal = ui->captionLabel->palette();
whitePal.setColor( QPalette::Foreground, Qt::white ); m_whitePal.setColor( QPalette::Foreground, Qt::white );
ui->captionLabel->setPalette( whitePal ); ui->captionLabel->setPalette( m_whitePal );
ui->descriptionLabel->setPalette( whitePal ); ui->descriptionLabel->setPalette( m_whitePal );
ui->longDescriptionLabel->setPalette( whitePal ); ui->longDescriptionLabel->setPalette( m_whitePal );
ui->captionLabel->setMargin( 6 ); ui->captionLabel->setMargin( 6 );
ui->descriptionLabel->setMargin( 6 ); ui->descriptionLabel->setMargin( 6 );
@@ -83,14 +85,6 @@ InfoBar::InfoBar( QWidget* parent )
m_queryLabel->hide(); m_queryLabel->hide();
connect( m_queryLabel, SIGNAL( clickedArtist() ), this, SLOT( artistClicked() ) ); connect( m_queryLabel, SIGNAL( clickedArtist() ), this, SLOT( artistClicked() ) );
m_autoUpdate = new QCheckBox( this );
m_autoUpdate->setText( tr( "Automatically update" ) );
m_autoUpdate->setLayoutDirection( Qt::RightToLeft );
m_autoUpdate->setPalette( whitePal );
connect( m_autoUpdate, SIGNAL( toggled( bool ) ), this, SIGNAL( autoUpdateChanged( bool ) ) );
ui->horizontalLayout->addWidget( m_autoUpdate );
m_searchWidget = new QSearchField( this ); m_searchWidget = new QSearchField( this );
m_searchWidget->setPlaceholderText( tr( "Filter..." ) ); m_searchWidget->setPlaceholderText( tr( "Filter..." ) );
m_searchWidget->setMinimumWidth( 180 ); m_searchWidget->setMinimumWidth( 180 );
@@ -106,7 +100,6 @@ InfoBar::InfoBar( QWidget* parent )
createTile(); createTile();
connect( ViewManager::instance(), SIGNAL( filterAvailable( bool ) ), SLOT( setFilterAvailable( bool ) ) ); connect( ViewManager::instance(), SIGNAL( filterAvailable( bool ) ), SLOT( setFilterAvailable( bool ) ) );
connect( ViewManager::instance(), SIGNAL( autoUpdateAvailable( bool ) ), SLOT( setAutoUpdateAvailable( bool ) ) );
} }
@@ -207,13 +200,36 @@ InfoBar::setFilterAvailable( bool b )
m_searchWidget->setVisible( b ); m_searchWidget->setVisible( b );
} }
void
InfoBar::setAutoUpdateAvailable( bool b )
{
if ( b )
m_autoUpdate->setChecked( ViewManager::instance()->currentPage()->autoUpdate() );
m_autoUpdate->setVisible( b ); void
InfoBar::setAutoUpdateInterface( PlaylistUpdaterInterface *interface )
{
if ( m_updaterConfiguration )
m_updaterConfiguration->hide();
if ( m_updaterConfiguration && ( interface ? (m_updaterConfiguration != interface->configurationWidget()) : true ) )
ui->horizontalLayout->removeWidget( m_updaterConfiguration );
m_updaterInterface = interface;
m_updaterConfiguration = interface ? interface->configurationWidget() : 0;
if ( !m_updaterInterface || !m_updaterConfiguration )
return;
m_updaterConfiguration->setPalette( m_whitePal );
int insertIdx = -1; // Ugh, no indexOf for QSpacerItem*
for ( int i = 0; i < ui->horizontalLayout->count(); i++ )
{
if ( ui->horizontalLayout->itemAt( i )->spacerItem() == ui->horizontalSpacer_4 )
{
insertIdx = i;
break;
}
}
insertIdx++;
ui->horizontalLayout->insertWidget( insertIdx, m_updaterConfiguration );
m_updaterConfiguration->show();
} }

View File

@@ -35,6 +35,11 @@ namespace Ui
class InfoBar; class InfoBar;
} }
namespace Tomahawk
{
class PlaylistUpdaterInterface;
}
class DLLEXPORT InfoBar : public QWidget class DLLEXPORT InfoBar : public QWidget
{ {
Q_OBJECT Q_OBJECT
@@ -57,10 +62,9 @@ public slots:
void setFilter( const QString& filter ); void setFilter( const QString& filter );
void setFilterAvailable( bool b ); void setFilterAvailable( bool b );
void setAutoUpdateAvailable( bool b ); void setAutoUpdateInterface( Tomahawk::PlaylistUpdaterInterface* interface );
signals: signals:
void filterTextChanged( const QString& filter ); void filterTextChanged( const QString& filter );
void autoUpdateChanged( bool checked );
protected: protected:
void changeEvent( QEvent* e ); void changeEvent( QEvent* e );
@@ -76,9 +80,12 @@ private:
Ui::InfoBar* ui; Ui::InfoBar* ui;
QPixmap m_bgTile; QPixmap m_bgTile;
QPalette m_whitePal;
Tomahawk::PlaylistUpdaterInterface* m_updaterInterface;
QWidget* m_updaterConfiguration;
QSearchField* m_searchWidget; QSearchField* m_searchWidget;
QCheckBox* m_autoUpdate;
QueryLabel* m_queryLabel; QueryLabel* m_queryLabel;
}; };

View File

@@ -49,17 +49,7 @@ PlaylistUpdaterInterface::loadForPlaylist( const playlist_ptr& pl )
return 0; return 0;
} }
updater = s_factories[ type ]->create( pl, key );
updater = s_factories[ type ]->create( pl );
if ( !updater )
{
return 0;
}
updater->setAutoUpdate( s->value( QString( "%1/autoupdate" ).arg( key ) ).toBool() );
updater->setInterval( s->value( QString( "%1/interval" ).arg( key ) ).toInt() );
updater->loadFromSettings( key );
return updater; return updater;
} }
@@ -69,8 +59,6 @@ PlaylistUpdaterInterface::loadForPlaylist( const playlist_ptr& pl )
PlaylistUpdaterInterface::PlaylistUpdaterInterface( const playlist_ptr& pl ) PlaylistUpdaterInterface::PlaylistUpdaterInterface( const playlist_ptr& pl )
: QObject( 0 ) : QObject( 0 )
, m_timer( 0 )
, m_autoUpdate( true )
, m_playlist( pl ) , m_playlist( pl )
{ {
Q_ASSERT( !m_playlist.isNull() ); Q_ASSERT( !m_playlist.isNull() );
@@ -80,21 +68,6 @@ PlaylistUpdaterInterface::PlaylistUpdaterInterface( const playlist_ptr& pl )
QTimer::singleShot( 0, this, SLOT( doSave() ) ); QTimer::singleShot( 0, this, SLOT( doSave() ) );
} }
PlaylistUpdaterInterface::PlaylistUpdaterInterface( const playlist_ptr& pl, int interval, bool autoUpdate )
: QObject( 0 )
, m_timer( new QTimer( this ) )
, m_autoUpdate( autoUpdate )
, m_playlist( pl )
{
Q_ASSERT( !m_playlist.isNull() );
m_playlist->setUpdater( this );
m_timer->setInterval( interval );
connect( m_timer, SIGNAL( timeout() ), this, SLOT( updateNow() ) );
QTimer::singleShot( 0, this, SLOT( doSave() ) );
}
void void
PlaylistUpdaterInterface::doSave() PlaylistUpdaterInterface::doSave()
@@ -104,10 +77,8 @@ PlaylistUpdaterInterface::doSave()
if ( !s->contains( QString( "%1/type" ).arg( key ) ) ) if ( !s->contains( QString( "%1/type" ).arg( key ) ) )
{ {
s->setValue( QString( "%1/type" ).arg( key ), type() ); 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 ? m_timer->interval() : -1 );
saveToSettings( key );
} }
saveToSettings( key );
} }
void void
@@ -120,51 +91,6 @@ PlaylistUpdaterInterface::remove()
const QString key = QString( "playlistupdaters/%1" ).arg( m_playlist->guid() ); const QString key = QString( "playlistupdaters/%1" ).arg( m_playlist->guid() );
removeFromSettings( key ); removeFromSettings( key );
s->remove( QString( "%1/type" ).arg( key ) ); s->remove( QString( "%1/type" ).arg( key ) );
s->remove( QString( "%1/autoupdate" ).arg( key ) );
s->remove( QString( "%1/interval" ).arg( key ) );
deleteLater(); deleteLater();
} }
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 );
// Update immediately as well
if ( m_autoUpdate )
QTimer::singleShot( 0, this, SLOT( updateNow() ) );
}
void
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

@@ -40,21 +40,17 @@ class DLLEXPORT PlaylistUpdaterInterface : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
// No periodic updating explicit PlaylistUpdaterInterface( const playlist_ptr& pl );
PlaylistUpdaterInterface( const playlist_ptr& pl );
// Periodic updating based on interval
PlaylistUpdaterInterface( const playlist_ptr& pl, int interval, bool autoUpdate );
virtual ~PlaylistUpdaterInterface(){} virtual ~PlaylistUpdaterInterface(){}
// What type you are. If you add a new updater, add the creation code as well. // What type you are. If you add a new updater, add the creation code as well.
virtual QString type() const = 0; virtual QString type() const = 0;
bool autoUpdate() const { return m_autoUpdate; } #ifndef ENABLE_HEADLESS
void setAutoUpdate( bool autoUpdate ); // Small widget to show in playlist header that configures the updater
virtual QWidget* configurationWidget() const = 0;
void setInterval( int intervalMsecs ) ; #endif
int intervalMsecs() const { return m_timer->interval(); }
void remove(); void remove();
@@ -72,13 +68,10 @@ private slots:
void doSave(); void doSave();
protected: protected:
virtual void loadFromSettings( const QString& group ) = 0;
virtual void saveToSettings( const QString& group ) const = 0; virtual void saveToSettings( const QString& group ) const = 0;
virtual void removeFromSettings( const QString& group ) const = 0; virtual void removeFromSettings( const QString& group ) const = 0;
private: private:
QTimer* m_timer;
bool m_autoUpdate;
playlist_ptr m_playlist; playlist_ptr m_playlist;
static QMap< QString, PlaylistUpdaterFactory* > s_factories; static QMap< QString, PlaylistUpdaterFactory* > s_factories;
@@ -92,7 +85,7 @@ public:
virtual ~PlaylistUpdaterFactory() {} virtual ~PlaylistUpdaterFactory() {}
virtual QString type() const = 0; virtual QString type() const = 0;
virtual PlaylistUpdaterInterface* create( const playlist_ptr& ) = 0; virtual PlaylistUpdaterInterface* create( const playlist_ptr&, const QString& settingsKey ) = 0;
}; };
} }

View File

@@ -26,32 +26,58 @@
#include <QTimer> #include <QTimer>
#ifndef ENABLE_HEADLESS
#include <QCheckBox>
#endif
using namespace Tomahawk; using namespace Tomahawk;
XspfUpdater::XspfUpdater( const playlist_ptr& pl, const QString& xUrl ) PlaylistUpdaterInterface*
: PlaylistUpdaterInterface( pl ) XspfUpdaterFactory::create( const playlist_ptr &pl, const QString& settingsKey )
, m_url( xUrl )
{ {
const bool autoUpdate = TomahawkSettings::instance()->value( QString( "%1/autoupdate" ).arg( settingsKey ) ).toBool();
const int interval = TomahawkSettings::instance()->value( QString( "%1/interval" ).arg( settingsKey ) ).toInt();
const QString url = TomahawkSettings::instance()->value( QString( "%1/xspfurl" ).arg( settingsKey ) ).toString();
XspfUpdater* updater = new XspfUpdater( pl, interval, autoUpdate, url );
return updater;
} }
XspfUpdater::XspfUpdater( const playlist_ptr& pl, int interval, bool autoUpdate, const QString& xspfUrl ) XspfUpdater::XspfUpdater( const playlist_ptr& pl, int interval, bool autoUpdate, const QString& xspfUrl )
: PlaylistUpdaterInterface( pl, interval, autoUpdate ) : PlaylistUpdaterInterface( pl )
, m_timer( new QTimer( this ) )
, m_autoUpdate( autoUpdate )
, m_url( xspfUrl ) , m_url( xspfUrl )
{ {
m_timer->setInterval( interval );
} connect( m_timer, SIGNAL( timeout() ), this, SLOT( updateNow() ) );
#ifndef ENABLE_HEADLESS
m_toggleCheckbox = new QCheckBox( );
m_toggleCheckbox->setText( tr( "Automatically update" ) );
m_toggleCheckbox->setLayoutDirection( Qt::RightToLeft );
m_toggleCheckbox->setChecked( m_autoUpdate );
m_toggleCheckbox->hide();
XspfUpdater::XspfUpdater( const playlist_ptr& pl ) connect( m_toggleCheckbox, SIGNAL( toggled( bool ) ), this, SLOT( setAutoUpdate( bool ) ) );
: PlaylistUpdaterInterface( pl ) #endif
{
} }
XspfUpdater::~XspfUpdater() XspfUpdater::~XspfUpdater()
{} {}
QWidget*
XspfUpdater::configurationWidget() const
{
return m_toggleCheckbox;
}
void void
XspfUpdater::updateNow() XspfUpdater::updateNow()
{ {
@@ -68,6 +94,7 @@ XspfUpdater::updateNow()
connect( l, SIGNAL( tracks( QList<Tomahawk::query_ptr> ) ), this, SLOT( playlistLoaded( QList<Tomahawk::query_ptr> ) ) ); connect( l, SIGNAL( tracks( QList<Tomahawk::query_ptr> ) ), this, SLOT( playlistLoaded( QList<Tomahawk::query_ptr> ) ) );
} }
void void
XspfUpdater::playlistLoaded( const QList<Tomahawk::query_ptr>& newEntries ) XspfUpdater::playlistLoaded( const QList<Tomahawk::query_ptr>& newEntries )
{ {
@@ -85,20 +112,51 @@ XspfUpdater::playlistLoaded( const QList<Tomahawk::query_ptr>& newEntries )
playlist()->createNewRevision( uuid(), playlist()->currentrevision(), el ); playlist()->createNewRevision( uuid(), playlist()->currentrevision(), el );
} }
void void
XspfUpdater::saveToSettings( const QString& group ) const XspfUpdater::saveToSettings( const QString& group ) const
{ {
TomahawkSettings::instance()->setValue( QString( "%1/autoupdate" ).arg( group ), m_autoUpdate );
TomahawkSettings::instance()->setValue( QString( "%1/interval" ).arg( group ), m_timer->interval() );
TomahawkSettings::instance()->setValue( QString( "%1/xspfurl" ).arg( group ), m_url ); TomahawkSettings::instance()->setValue( QString( "%1/xspfurl" ).arg( group ), m_url );
} }
void
XspfUpdater::loadFromSettings( const QString& group )
{
m_url = TomahawkSettings::instance()->value( QString( "%1/xspfurl" ).arg( group ) ).toString();
}
void void
XspfUpdater::removeFromSettings( const QString& group ) const XspfUpdater::removeFromSettings( const QString& group ) const
{ {
TomahawkSettings::instance()->remove( QString( "%1/autoupdate" ).arg( group ) );
TomahawkSettings::instance()->remove( QString( "%1/interval" ).arg( group ) );
TomahawkSettings::instance()->remove( QString( "%1/xspfurl" ).arg( group ) ); TomahawkSettings::instance()->remove( QString( "%1/xspfurl" ).arg( group ) );
} }
void
XspfUpdater::setAutoUpdate( bool autoUpdate )
{
m_autoUpdate = autoUpdate;
if ( m_autoUpdate )
m_timer->start();
else
m_timer->stop();
const QString key = QString( "playlistupdaters/%1/autoupdate" ).arg( playlist()->guid() );
TomahawkSettings::instance()->setValue( key, m_autoUpdate );
// Update immediately as well
if ( m_autoUpdate )
QTimer::singleShot( 0, this, SLOT( updateNow() ) );
}
void
XspfUpdater::setInterval( int intervalMsecs )
{
const QString key = QString( "playlistupdaters/%1/interval" ).arg( playlist()->guid() );
TomahawkSettings::instance()->setValue( key, intervalMsecs );
if ( !m_timer )
m_timer = new QTimer( this );
m_timer->setInterval( intervalMsecs );
}

View File

@@ -23,6 +23,7 @@
#include "dllmacro.h" #include "dllmacro.h"
class QTimer; class QTimer;
class QCheckBox;
namespace Tomahawk namespace Tomahawk
{ {
@@ -32,27 +33,40 @@ class DLLEXPORT XspfUpdater : public PlaylistUpdaterInterface
{ {
Q_OBJECT Q_OBJECT
public: public:
XspfUpdater( const playlist_ptr& pl, const QString& xspfUrl );
XspfUpdater( const playlist_ptr& pl, int interval, bool autoUpdate, const QString& xspfUrl ); XspfUpdater( const playlist_ptr& pl, int interval, bool autoUpdate, const QString& xspfUrl );
explicit XspfUpdater( const playlist_ptr& pl ); // used by factory
virtual ~XspfUpdater(); virtual ~XspfUpdater();
virtual QString type() const { return "xspf"; } virtual QString type() const { return "xspf"; }
#ifndef ENABLE_HEADLESS
virtual QWidget* configurationWidget() const;
#endif
bool autoUpdate() const { return m_autoUpdate; }
void setInterval( int intervalMsecs ) ;
int intervalMsecs() const { return m_timer->interval(); }
public slots: public slots:
void updateNow(); void updateNow();
void setAutoUpdate( bool autoUpdate );
protected: protected:
void loadFromSettings( const QString& group );
void saveToSettings( const QString& group ) const; void saveToSettings( const QString& group ) const;
virtual void removeFromSettings(const QString& group) const; void removeFromSettings(const QString& group) const;
private slots: private slots:
void playlistLoaded( const QList<Tomahawk::query_ptr> & ); void playlistLoaded( const QList<Tomahawk::query_ptr> & );
private: private:
QTimer* m_timer;
bool m_autoUpdate;
QString m_url; QString m_url;
#ifndef ENABLE_HEADLESS
QCheckBox* m_toggleCheckbox;
#endif
}; };
class DLLEXPORT XspfUpdaterFactory : public PlaylistUpdaterFactory class DLLEXPORT XspfUpdaterFactory : public PlaylistUpdaterFactory
@@ -61,7 +75,7 @@ public:
XspfUpdaterFactory() {} XspfUpdaterFactory() {}
virtual QString type() const { return "xspf"; } virtual QString type() const { return "xspf"; }
virtual PlaylistUpdaterInterface* create( const playlist_ptr& pl ) { return new XspfUpdater( pl ); } virtual PlaylistUpdaterInterface* create( const playlist_ptr& pl, const QString& settingsKey );
}; };
} }

View File

@@ -119,23 +119,13 @@ PlaylistView::canAutoUpdate() const
} }
bool PlaylistUpdaterInterface*
PlaylistView::autoUpdate() const PlaylistView::autoUpdateInterface() const
{ {
if ( canAutoUpdate() ) if ( !m_model->playlist().isNull() && m_model->playlist()->updater() )
return m_model->playlist()->updater()->autoUpdate(); return m_model->playlist()->updater();
return false; return 0;
}
void
PlaylistView::setAutoUpdate( bool autoUpdate )
{
if ( !canAutoUpdate() )
return;
m_model->playlist()->updater()->setAutoUpdate( autoUpdate );
} }

View File

@@ -44,8 +44,7 @@ public:
virtual bool showFilter() const { return true; } virtual bool showFilter() const { return true; }
virtual bool canAutoUpdate() const; virtual bool canAutoUpdate() const;
virtual void setAutoUpdate( bool autoUpdate ); virtual Tomahawk::PlaylistUpdaterInterface* autoUpdateInterface() const;
virtual bool autoUpdate() const;
virtual QString title() const { return playlistModel()->title(); } virtual QString title() const { return playlistModel()->title(); }
virtual QString description() const { return m_model->description(); } virtual QString description() const { return m_model->description(); }

View File

@@ -116,7 +116,6 @@ ViewManager::ViewManager( QObject* parent )
connect( &m_filterTimer, SIGNAL( timeout() ), SLOT( applyFilter() ) ); connect( &m_filterTimer, SIGNAL( timeout() ), SLOT( applyFilter() ) );
connect( m_infobar, SIGNAL( filterTextChanged( QString ) ), SLOT( setFilter( QString ) ) ); connect( m_infobar, SIGNAL( filterTextChanged( QString ) ), SLOT( setFilter( QString ) ) );
connect( m_infobar, SIGNAL( autoUpdateChanged( bool ) ), SLOT( autoUpdateChanged( bool ) ) );
connect( this, SIGNAL( tomahawkLoaded() ), m_whatsHotWidget, SLOT( fetchData() ) ); connect( this, SIGNAL( tomahawkLoaded() ), m_whatsHotWidget, SLOT( fetchData() ) );
connect( this, SIGNAL( tomahawkLoaded() ), m_welcomeWidget, SLOT( loadData() ) ); connect( this, SIGNAL( tomahawkLoaded() ), m_welcomeWidget, SLOT( loadData() ) );
@@ -573,13 +572,6 @@ ViewManager::applyFilter()
} }
void
ViewManager::autoUpdateChanged( bool toggled )
{
currentPage()->setAutoUpdate( toggled );
}
void void
ViewManager::setPage( ViewPage* page, bool trackHistory ) ViewManager::setPage( ViewPage* page, bool trackHistory )
{ {
@@ -735,8 +727,6 @@ ViewManager::updateView()
emit modesAvailable( currentPage()->showModes() ); emit modesAvailable( currentPage()->showModes() );
emit filterAvailable( currentPage()->showFilter() ); emit filterAvailable( currentPage()->showFilter() );
emit autoUpdateAvailable( currentPage()->canAutoUpdate() );
/* if ( !currentPage()->showStatsBar() && !currentPage()->showModes() && !currentPage()->showFilter() ) /* if ( !currentPage()->showStatsBar() && !currentPage()->showModes() && !currentPage()->showFilter() )
m_topbar->setVisible( false ); m_topbar->setVisible( false );
else else
@@ -744,6 +734,9 @@ ViewManager::updateView()
m_infobar->setVisible( currentPage()->showInfoBar() ); m_infobar->setVisible( currentPage()->showInfoBar() );
m_infobar->setCaption( currentPage()->title() ); m_infobar->setCaption( currentPage()->title() );
m_infobar->setAutoUpdateInterface( currentPage()->autoUpdateInterface() );
switch( currentPage()->descriptionType() ) switch( currentPage()->descriptionType() )
{ {
case ViewPage::TextType: case ViewPage::TextType:

View File

@@ -122,7 +122,6 @@ signals:
void statsAvailable( bool b ); void statsAvailable( bool b );
void modesAvailable( bool b ); void modesAvailable( bool b );
void filterAvailable( bool b ); void filterAvailable( bool b );
void autoUpdateAvailable( bool b );
void modeChanged( Tomahawk::PlaylistInterface::ViewMode mode ); void modeChanged( Tomahawk::PlaylistInterface::ViewMode mode );
void playClicked(); void playClicked();
@@ -177,8 +176,6 @@ private slots:
void setFilter( const QString& filter ); void setFilter( const QString& filter );
void applyFilter(); void applyFilter();
void autoUpdateChanged( bool );
void onWidgetDestroyed( QWidget* widget ); void onWidgetDestroyed( QWidget* widget );
private: private:

View File

@@ -31,6 +31,8 @@
namespace Tomahawk namespace Tomahawk
{ {
class PlaylistUpdaterInterface;
class DLLEXPORT ViewPage class DLLEXPORT ViewPage
{ {
public: public:
@@ -68,8 +70,7 @@ public:
virtual bool isBeingPlayed() const { return false; } virtual bool isBeingPlayed() const { return false; }
virtual bool canAutoUpdate() const { return false; } virtual bool canAutoUpdate() const { return false; }
virtual void setAutoUpdate( bool ) {} virtual PlaylistUpdaterInterface* autoUpdateInterface() const { return 0; }
virtual bool autoUpdate() const { return false; }
/** subclasses implementing ViewPage can emit the following signals: /** subclasses implementing ViewPage can emit the following signals:
* nameChanged( const QString& ) * nameChanged( const QString& )