From cfcdbbb728fc7ef81d47c1990f174663663e3ff3 Mon Sep 17 00:00:00 2001 From: Leo Franchi Date: Sat, 7 Apr 2012 00:14:42 -0400 Subject: [PATCH] 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 --- src/accounts/spotify/SpotifyAccountConfig.ui | 4 +- .../spotify/SpotifyPlaylistUpdater.cpp | 27 ++---- src/accounts/spotify/SpotifyPlaylistUpdater.h | 11 ++- src/libtomahawk/accounts/Account.cpp | 4 +- src/libtomahawk/infobar/infobar.cpp | 56 +++++++----- src/libtomahawk/infobar/infobar.h | 13 ++- .../playlist/PlaylistUpdaterInterface.cpp | 78 +---------------- .../playlist/PlaylistUpdaterInterface.h | 19 ++-- src/libtomahawk/playlist/XspfUpdater.cpp | 86 ++++++++++++++++--- src/libtomahawk/playlist/XspfUpdater.h | 24 ++++-- src/libtomahawk/playlist/playlistview.cpp | 20 ++--- src/libtomahawk/playlist/playlistview.h | 3 +- src/libtomahawk/viewmanager.cpp | 13 +-- src/libtomahawk/viewmanager.h | 3 - src/libtomahawk/viewpage.h | 5 +- 15 files changed, 174 insertions(+), 192 deletions(-) diff --git a/src/accounts/spotify/SpotifyAccountConfig.ui b/src/accounts/spotify/SpotifyAccountConfig.ui index 5a8c900b4..24dbbaa3b 100644 --- a/src/accounts/spotify/SpotifyAccountConfig.ui +++ b/src/accounts/spotify/SpotifyAccountConfig.ui @@ -6,8 +6,8 @@ 0 0 - 403 - 439 + 419 + 454 diff --git a/src/accounts/spotify/SpotifyPlaylistUpdater.cpp b/src/accounts/spotify/SpotifyPlaylistUpdater.cpp index 822ffa10d..c59a61133 100644 --- a/src/accounts/spotify/SpotifyPlaylistUpdater.cpp +++ b/src/accounts/spotify/SpotifyPlaylistUpdater.cpp @@ -25,7 +25,7 @@ using namespace Tomahawk; using namespace Accounts; Tomahawk::PlaylistUpdaterInterface* -SpotifyUpdaterFactory::create( const Tomahawk::playlist_ptr& pl ) +SpotifyUpdaterFactory::create( const Tomahawk::playlist_ptr& pl, const QString &key ) { if ( !m_account ) { @@ -47,25 +47,19 @@ SpotifyUpdaterFactory::create( const Tomahawk::playlist_ptr& pl ) } // 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() ); - 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 ); 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 ) : PlaylistUpdaterInterface( pl ) , 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 SpotifyPlaylistUpdater::removeFromSettings( const QString& group ) const diff --git a/src/accounts/spotify/SpotifyPlaylistUpdater.h b/src/accounts/spotify/SpotifyPlaylistUpdater.h index ecc21e5c5..e41dbe5d9 100644 --- a/src/accounts/spotify/SpotifyPlaylistUpdater.h +++ b/src/accounts/spotify/SpotifyPlaylistUpdater.h @@ -34,17 +34,17 @@ class SpotifyPlaylistUpdater : public Tomahawk::PlaylistUpdaterInterface friend class Tomahawk::Accounts::SpotifyAccount; public: - // used when creating anew 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 QString type() const; virtual void updateNow() {} +#ifndef ENABLE_HEADLESS + virtual QWidget* configurationWidget() const { return 0; } +#endif + bool sync() const; void setSync( bool sync ); @@ -56,7 +56,6 @@ public: protected: virtual void removeFromSettings(const QString& group) const; virtual void saveToSettings(const QString& group) const; - virtual void loadFromSettings(const QString& group); private slots: void tomahawkTracksInserted( const QList& ,int ); @@ -87,7 +86,7 @@ class SpotifyUpdaterFactory : public Tomahawk::PlaylistUpdaterFactory public: 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"; } private: diff --git a/src/libtomahawk/accounts/Account.cpp b/src/libtomahawk/accounts/Account.cpp index e8a293c2e..eda98702f 100644 --- a/src/libtomahawk/accounts/Account.cpp +++ b/src/libtomahawk/accounts/Account.cpp @@ -37,6 +37,8 @@ accountTypeToString( AccountType type ) case InfoType: case StatusPushType: return QObject::tr( "Status Updaters" ); + default: + return QString(); } return QString(); @@ -203,4 +205,4 @@ Account::types() const } -} \ No newline at end of file +} diff --git a/src/libtomahawk/infobar/infobar.cpp b/src/libtomahawk/infobar/infobar.cpp index 9e0145290..eab478db5 100644 --- a/src/libtomahawk/infobar/infobar.cpp +++ b/src/libtomahawk/infobar/infobar.cpp @@ -40,6 +40,8 @@ using namespace Tomahawk; InfoBar::InfoBar( QWidget* parent ) : QWidget( parent ) , ui( new Ui::InfoBar ) + , m_updaterInterface( 0 ) + , m_updaterConfiguration( 0 ) , m_queryLabel( 0 ) { ui->setupUi( this ); @@ -59,12 +61,12 @@ InfoBar::InfoBar( QWidget* parent ) regFont.setPixelSize( 11 ); ui->longDescriptionLabel->setFont( regFont ); - QPalette whitePal = ui->captionLabel->palette(); - whitePal.setColor( QPalette::Foreground, Qt::white ); + m_whitePal = ui->captionLabel->palette(); + m_whitePal.setColor( QPalette::Foreground, Qt::white ); - ui->captionLabel->setPalette( whitePal ); - ui->descriptionLabel->setPalette( whitePal ); - ui->longDescriptionLabel->setPalette( whitePal ); + ui->captionLabel->setPalette( m_whitePal ); + ui->descriptionLabel->setPalette( m_whitePal ); + ui->longDescriptionLabel->setPalette( m_whitePal ); ui->captionLabel->setMargin( 6 ); ui->descriptionLabel->setMargin( 6 ); @@ -83,14 +85,6 @@ InfoBar::InfoBar( QWidget* parent ) m_queryLabel->hide(); 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->setPlaceholderText( tr( "Filter..." ) ); m_searchWidget->setMinimumWidth( 180 ); @@ -106,7 +100,6 @@ InfoBar::InfoBar( QWidget* parent ) createTile(); 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 ); } -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(); } diff --git a/src/libtomahawk/infobar/infobar.h b/src/libtomahawk/infobar/infobar.h index a5f418819..19ee2f8c9 100644 --- a/src/libtomahawk/infobar/infobar.h +++ b/src/libtomahawk/infobar/infobar.h @@ -35,6 +35,11 @@ namespace Ui class InfoBar; } +namespace Tomahawk +{ +class PlaylistUpdaterInterface; +} + class DLLEXPORT InfoBar : public QWidget { Q_OBJECT @@ -57,10 +62,9 @@ public slots: void setFilter( const QString& filter ); void setFilterAvailable( bool b ); - void setAutoUpdateAvailable( bool b ); + void setAutoUpdateInterface( Tomahawk::PlaylistUpdaterInterface* interface ); signals: void filterTextChanged( const QString& filter ); - void autoUpdateChanged( bool checked ); protected: void changeEvent( QEvent* e ); @@ -76,9 +80,12 @@ private: Ui::InfoBar* ui; QPixmap m_bgTile; + QPalette m_whitePal; + + Tomahawk::PlaylistUpdaterInterface* m_updaterInterface; + QWidget* m_updaterConfiguration; QSearchField* m_searchWidget; - QCheckBox* m_autoUpdate; QueryLabel* m_queryLabel; }; diff --git a/src/libtomahawk/playlist/PlaylistUpdaterInterface.cpp b/src/libtomahawk/playlist/PlaylistUpdaterInterface.cpp index 8b0d0b692..34cc32673 100644 --- a/src/libtomahawk/playlist/PlaylistUpdaterInterface.cpp +++ b/src/libtomahawk/playlist/PlaylistUpdaterInterface.cpp @@ -49,17 +49,7 @@ PlaylistUpdaterInterface::loadForPlaylist( const playlist_ptr& pl ) return 0; } - - 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 ); - + updater = s_factories[ type ]->create( pl, key ); return updater; } @@ -69,8 +59,6 @@ PlaylistUpdaterInterface::loadForPlaylist( const playlist_ptr& pl ) PlaylistUpdaterInterface::PlaylistUpdaterInterface( const playlist_ptr& pl ) : QObject( 0 ) - , m_timer( 0 ) - , m_autoUpdate( true ) , m_playlist( pl ) { Q_ASSERT( !m_playlist.isNull() ); @@ -80,21 +68,6 @@ PlaylistUpdaterInterface::PlaylistUpdaterInterface( const playlist_ptr& pl ) 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 PlaylistUpdaterInterface::doSave() @@ -104,10 +77,8 @@ PlaylistUpdaterInterface::doSave() if ( !s->contains( QString( "%1/type" ).arg( key ) ) ) { 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 @@ -120,51 +91,6 @@ PlaylistUpdaterInterface::remove() const QString key = QString( "playlistupdaters/%1" ).arg( m_playlist->guid() ); removeFromSettings( key ); s->remove( QString( "%1/type" ).arg( key ) ); - s->remove( QString( "%1/autoupdate" ).arg( key ) ); - s->remove( QString( "%1/interval" ).arg( key ) ); 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 ); -} - diff --git a/src/libtomahawk/playlist/PlaylistUpdaterInterface.h b/src/libtomahawk/playlist/PlaylistUpdaterInterface.h index 79f3c7986..3fb2ed2ac 100644 --- a/src/libtomahawk/playlist/PlaylistUpdaterInterface.h +++ b/src/libtomahawk/playlist/PlaylistUpdaterInterface.h @@ -40,21 +40,17 @@ 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 ); + explicit PlaylistUpdaterInterface( const playlist_ptr& pl ); virtual ~PlaylistUpdaterInterface(){} // What type you are. If you add a new updater, add the creation code as well. virtual QString type() const = 0; - bool autoUpdate() const { return m_autoUpdate; } - void setAutoUpdate( bool autoUpdate ); - - void setInterval( int intervalMsecs ) ; - int intervalMsecs() const { return m_timer->interval(); } +#ifndef ENABLE_HEADLESS + // Small widget to show in playlist header that configures the updater + virtual QWidget* configurationWidget() const = 0; +#endif void remove(); @@ -72,13 +68,10 @@ private slots: void doSave(); protected: - virtual void loadFromSettings( const QString& group ) = 0; virtual void saveToSettings( const QString& group ) const = 0; virtual void removeFromSettings( const QString& group ) const = 0; private: - QTimer* m_timer; - bool m_autoUpdate; playlist_ptr m_playlist; static QMap< QString, PlaylistUpdaterFactory* > s_factories; @@ -92,7 +85,7 @@ public: virtual ~PlaylistUpdaterFactory() {} virtual QString type() const = 0; - virtual PlaylistUpdaterInterface* create( const playlist_ptr& ) = 0; + virtual PlaylistUpdaterInterface* create( const playlist_ptr&, const QString& settingsKey ) = 0; }; } diff --git a/src/libtomahawk/playlist/XspfUpdater.cpp b/src/libtomahawk/playlist/XspfUpdater.cpp index d00991d20..9a7eaaece 100644 --- a/src/libtomahawk/playlist/XspfUpdater.cpp +++ b/src/libtomahawk/playlist/XspfUpdater.cpp @@ -26,32 +26,58 @@ #include +#ifndef ENABLE_HEADLESS +#include +#endif + using namespace Tomahawk; -XspfUpdater::XspfUpdater( const playlist_ptr& pl, const QString& xUrl ) - : PlaylistUpdaterInterface( pl ) - , m_url( xUrl ) +PlaylistUpdaterInterface* +XspfUpdaterFactory::create( const playlist_ptr &pl, const QString& settingsKey ) { + 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 ) - : PlaylistUpdaterInterface( pl, interval, autoUpdate ) + : PlaylistUpdaterInterface( pl ) + , m_timer( new QTimer( this ) ) + , m_autoUpdate( autoUpdate ) , 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 ) - : PlaylistUpdaterInterface( pl ) -{ - + connect( m_toggleCheckbox, SIGNAL( toggled( bool ) ), this, SLOT( setAutoUpdate( bool ) ) ); +#endif } XspfUpdater::~XspfUpdater() {} + +QWidget* +XspfUpdater::configurationWidget() const +{ + return m_toggleCheckbox; +} + + void XspfUpdater::updateNow() { @@ -68,6 +94,7 @@ XspfUpdater::updateNow() connect( l, SIGNAL( tracks( QList ) ), this, SLOT( playlistLoaded( QList ) ) ); } + void XspfUpdater::playlistLoaded( const QList& newEntries ) { @@ -85,20 +112,51 @@ XspfUpdater::playlistLoaded( const QList& newEntries ) playlist()->createNewRevision( uuid(), playlist()->currentrevision(), el ); } + void 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 ); } -void -XspfUpdater::loadFromSettings( const QString& group ) -{ - m_url = TomahawkSettings::instance()->value( QString( "%1/xspfurl" ).arg( group ) ).toString(); -} void 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 ) ); } + + +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 ); +} diff --git a/src/libtomahawk/playlist/XspfUpdater.h b/src/libtomahawk/playlist/XspfUpdater.h index 3ce43b729..075628a2f 100644 --- a/src/libtomahawk/playlist/XspfUpdater.h +++ b/src/libtomahawk/playlist/XspfUpdater.h @@ -23,6 +23,7 @@ #include "dllmacro.h" class QTimer; +class QCheckBox; namespace Tomahawk { @@ -32,27 +33,40 @@ class DLLEXPORT XspfUpdater : public PlaylistUpdaterInterface { Q_OBJECT public: - XspfUpdater( const playlist_ptr& pl, 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 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: void updateNow(); + void setAutoUpdate( bool autoUpdate ); protected: - void loadFromSettings( const QString& group ); void saveToSettings( const QString& group ) const; - virtual void removeFromSettings(const QString& group) const; + void removeFromSettings(const QString& group) const; private slots: void playlistLoaded( const QList & ); private: + QTimer* m_timer; + bool m_autoUpdate; QString m_url; + +#ifndef ENABLE_HEADLESS + QCheckBox* m_toggleCheckbox; +#endif }; class DLLEXPORT XspfUpdaterFactory : public PlaylistUpdaterFactory @@ -61,7 +75,7 @@ public: XspfUpdaterFactory() {} 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 ); }; } diff --git a/src/libtomahawk/playlist/playlistview.cpp b/src/libtomahawk/playlist/playlistview.cpp index 7d32c4c4d..d64371f52 100644 --- a/src/libtomahawk/playlist/playlistview.cpp +++ b/src/libtomahawk/playlist/playlistview.cpp @@ -119,23 +119,13 @@ PlaylistView::canAutoUpdate() const } -bool -PlaylistView::autoUpdate() const +PlaylistUpdaterInterface* +PlaylistView::autoUpdateInterface() const { - if ( canAutoUpdate() ) - return m_model->playlist()->updater()->autoUpdate(); + if ( !m_model->playlist().isNull() && m_model->playlist()->updater() ) + return m_model->playlist()->updater(); - return false; -} - - -void -PlaylistView::setAutoUpdate( bool autoUpdate ) -{ - if ( !canAutoUpdate() ) - return; - - m_model->playlist()->updater()->setAutoUpdate( autoUpdate ); + return 0; } diff --git a/src/libtomahawk/playlist/playlistview.h b/src/libtomahawk/playlist/playlistview.h index 1a94f6890..8f013cd52 100644 --- a/src/libtomahawk/playlist/playlistview.h +++ b/src/libtomahawk/playlist/playlistview.h @@ -44,8 +44,7 @@ public: virtual bool showFilter() const { return true; } virtual bool canAutoUpdate() const; - virtual void setAutoUpdate( bool autoUpdate ); - virtual bool autoUpdate() const; + virtual Tomahawk::PlaylistUpdaterInterface* autoUpdateInterface() const; virtual QString title() const { return playlistModel()->title(); } virtual QString description() const { return m_model->description(); } diff --git a/src/libtomahawk/viewmanager.cpp b/src/libtomahawk/viewmanager.cpp index 92eb4fba5..f9c939e45 100644 --- a/src/libtomahawk/viewmanager.cpp +++ b/src/libtomahawk/viewmanager.cpp @@ -116,7 +116,6 @@ ViewManager::ViewManager( QObject* parent ) connect( &m_filterTimer, SIGNAL( timeout() ), SLOT( applyFilter() ) ); 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_welcomeWidget, SLOT( loadData() ) ); @@ -573,13 +572,6 @@ ViewManager::applyFilter() } -void -ViewManager::autoUpdateChanged( bool toggled ) -{ - currentPage()->setAutoUpdate( toggled ); -} - - void ViewManager::setPage( ViewPage* page, bool trackHistory ) { @@ -735,8 +727,6 @@ ViewManager::updateView() emit modesAvailable( currentPage()->showModes() ); emit filterAvailable( currentPage()->showFilter() ); - emit autoUpdateAvailable( currentPage()->canAutoUpdate() ); - /* if ( !currentPage()->showStatsBar() && !currentPage()->showModes() && !currentPage()->showFilter() ) m_topbar->setVisible( false ); else @@ -744,6 +734,9 @@ ViewManager::updateView() m_infobar->setVisible( currentPage()->showInfoBar() ); m_infobar->setCaption( currentPage()->title() ); + + m_infobar->setAutoUpdateInterface( currentPage()->autoUpdateInterface() ); + switch( currentPage()->descriptionType() ) { case ViewPage::TextType: diff --git a/src/libtomahawk/viewmanager.h b/src/libtomahawk/viewmanager.h index 52a8e3ee0..a62f18f74 100644 --- a/src/libtomahawk/viewmanager.h +++ b/src/libtomahawk/viewmanager.h @@ -122,7 +122,6 @@ signals: void statsAvailable( bool b ); void modesAvailable( bool b ); void filterAvailable( bool b ); - void autoUpdateAvailable( bool b ); void modeChanged( Tomahawk::PlaylistInterface::ViewMode mode ); void playClicked(); @@ -177,8 +176,6 @@ private slots: void setFilter( const QString& filter ); void applyFilter(); - void autoUpdateChanged( bool ); - void onWidgetDestroyed( QWidget* widget ); private: diff --git a/src/libtomahawk/viewpage.h b/src/libtomahawk/viewpage.h index dbd7ecf99..c6f40aa4d 100644 --- a/src/libtomahawk/viewpage.h +++ b/src/libtomahawk/viewpage.h @@ -31,6 +31,8 @@ namespace Tomahawk { +class PlaylistUpdaterInterface; + class DLLEXPORT ViewPage { public: @@ -68,8 +70,7 @@ public: virtual bool isBeingPlayed() const { return false; } virtual bool canAutoUpdate() const { return false; } - virtual void setAutoUpdate( bool ) {} - virtual bool autoUpdate() const { return false; } + virtual PlaylistUpdaterInterface* autoUpdateInterface() const { return 0; } /** subclasses implementing ViewPage can emit the following signals: * nameChanged( const QString& )