mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-16 11:04:01 +02:00
factory-ize the playlist updater loading
This commit is contained in:
@@ -18,10 +18,19 @@
|
||||
|
||||
#include "PlaylistUpdaterInterface.h"
|
||||
#include "tomahawksettings.h"
|
||||
#include "XspfUpdater.h"
|
||||
|
||||
using namespace Tomahawk;
|
||||
|
||||
QMap< QString, PlaylistUpdaterFactory* > PlaylistUpdaterInterface::s_factories = QMap< QString, PlaylistUpdaterFactory* >();
|
||||
|
||||
void
|
||||
PlaylistUpdaterInterface::registerUpdaterFactory( PlaylistUpdaterFactory* f )
|
||||
{
|
||||
s_factories[ f->type() ] = f;
|
||||
}
|
||||
|
||||
|
||||
|
||||
PlaylistUpdaterInterface*
|
||||
PlaylistUpdaterInterface::loadForPlaylist( const playlist_ptr& pl )
|
||||
{
|
||||
@@ -32,10 +41,17 @@ PlaylistUpdaterInterface::loadForPlaylist( const playlist_ptr& pl )
|
||||
// Ok, we have one we can try to load
|
||||
const QString type = s->value( QString( "%1/type" ).arg( key ) ).toString();
|
||||
PlaylistUpdaterInterface* updater = 0;
|
||||
if ( type == "xspf" )
|
||||
updater = new XspfUpdater( pl );
|
||||
|
||||
// You forgot to register your new updater type with the factory above. 00ps.
|
||||
if ( !s_factories.contains( type ) )
|
||||
{
|
||||
Q_ASSERT( false );
|
||||
// You forgot to register your new updater type with the factory....
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
updater = s_factories[ type ]->create( pl );
|
||||
|
||||
if ( !updater )
|
||||
{
|
||||
Q_ASSERT( false );
|
||||
|
@@ -22,7 +22,9 @@
|
||||
#include "dllmacro.h"
|
||||
#include "typedefs.h"
|
||||
#include "playlist.h"
|
||||
|
||||
#include <QTimer>
|
||||
#include <QMutex>
|
||||
|
||||
namespace Tomahawk
|
||||
{
|
||||
@@ -32,6 +34,8 @@ namespace Tomahawk
|
||||
* Default is auto-updating.
|
||||
*/
|
||||
|
||||
class PlaylistUpdaterFactory;
|
||||
|
||||
class DLLEXPORT PlaylistUpdaterInterface : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -58,6 +62,7 @@ public:
|
||||
/// updater if one was saved
|
||||
static PlaylistUpdaterInterface* loadForPlaylist( const playlist_ptr& pl );
|
||||
|
||||
static void registerUpdaterFactory( PlaylistUpdaterFactory* f );
|
||||
public slots:
|
||||
virtual void updateNow() {}
|
||||
|
||||
@@ -73,6 +78,19 @@ private:
|
||||
QTimer* m_timer;
|
||||
bool m_autoUpdate;
|
||||
playlist_ptr m_playlist;
|
||||
|
||||
static QMap< QString, PlaylistUpdaterFactory* > s_factories;
|
||||
};
|
||||
|
||||
|
||||
class DLLEXPORT PlaylistUpdaterFactory
|
||||
{
|
||||
public:
|
||||
PlaylistUpdaterFactory() {}
|
||||
virtual ~PlaylistUpdaterFactory() {}
|
||||
|
||||
virtual QString type() const = 0;
|
||||
virtual PlaylistUpdaterInterface* create( const playlist_ptr& ) = 0;
|
||||
};
|
||||
|
||||
}
|
||||
|
@@ -20,13 +20,15 @@
|
||||
#define XSPFUPDATER_H
|
||||
|
||||
#include "PlaylistUpdaterInterface.h"
|
||||
#include "dllmacro.h"
|
||||
|
||||
class QTimer;
|
||||
|
||||
namespace Tomahawk
|
||||
{
|
||||
|
||||
class XspfUpdater : public PlaylistUpdaterInterface
|
||||
|
||||
class DLLEXPORT XspfUpdater : public PlaylistUpdaterInterface
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
@@ -52,6 +54,15 @@ private:
|
||||
QString m_url;
|
||||
};
|
||||
|
||||
class DLLEXPORT XspfUpdaterFactory : public PlaylistUpdaterFactory
|
||||
{
|
||||
public:
|
||||
XspfUpdaterFactory() {}
|
||||
|
||||
virtual QString type() const { return "type"; }
|
||||
virtual PlaylistUpdaterInterface* create( const playlist_ptr& pl ) { return new XspfUpdater( pl ); }
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // XSPFUPDATER_H
|
||||
|
@@ -41,6 +41,7 @@
|
||||
#include "playlist/dynamic/GeneratorFactory.h"
|
||||
#include "playlist/dynamic/echonest/EchonestGenerator.h"
|
||||
#include "playlist/dynamic/database/DatabaseGenerator.h"
|
||||
#include "playlist/XspfUpdater.h"
|
||||
#include "network/servent.h"
|
||||
#include "web/api_v1.h"
|
||||
#include "sourcelist.h"
|
||||
@@ -288,6 +289,9 @@ TomahawkApp::init()
|
||||
// Set up echonest catalog synchronizer
|
||||
Tomahawk::EchonestCatalogSynchronizer::instance();
|
||||
|
||||
PlaylistUpdaterInterface::registerUpdaterFactory( new XspfUpdaterFactory );
|
||||
PlaylistUpdaterInterface::registerUpdaterFactory( new SpotifyUpdaterFactory );
|
||||
|
||||
#ifndef ENABLE_HEADLESS
|
||||
// Make sure to init GAM in the gui thread
|
||||
GlobalActionManager::instance();
|
||||
|
Reference in New Issue
Block a user