mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-23 09:19:41 +01: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:
parent
30791e9bdc
commit
cfcdbbb728
@ -6,8 +6,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>403</width>
|
||||
<height>439</height>
|
||||
<width>419</width>
|
||||
<height>454</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
|
@ -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
|
||||
|
@ -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<Tomahawk::plentry_ptr>& ,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:
|
||||
|
@ -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
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
||||
|
@ -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;
|
||||
};
|
||||
|
||||
|
@ -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 );
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -26,32 +26,58 @@
|
||||
|
||||
#include <QTimer>
|
||||
|
||||
#ifndef ENABLE_HEADLESS
|
||||
#include <QCheckBox>
|
||||
#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<Tomahawk::query_ptr> ) ), this, SLOT( playlistLoaded( QList<Tomahawk::query_ptr> ) ) );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
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 );
|
||||
}
|
||||
|
||||
|
||||
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 );
|
||||
}
|
||||
|
@ -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<Tomahawk::query_ptr> & );
|
||||
|
||||
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 );
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
@ -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(); }
|
||||
|
@ -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:
|
||||
|
@ -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:
|
||||
|
@ -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& )
|
||||
|
Loading…
x
Reference in New Issue
Block a user