mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-13 17:43:59 +02:00
Add capabilities support to ScriptResolver and QtScriptResolver.
This commit is contained in:
@@ -79,6 +79,14 @@ Tomahawk.extend = function(object, members) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
var TomahawkResolverCapability = {
|
||||||
|
NullCapability: 0,
|
||||||
|
Browsable: 1,
|
||||||
|
PlaylistSync: 2,
|
||||||
|
AccountFactory: 4
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
// Resolver BaseObject, inherit it to implement your own resolver
|
// Resolver BaseObject, inherit it to implement your own resolver
|
||||||
var TomahawkResolver = {
|
var TomahawkResolver = {
|
||||||
init: function()
|
init: function()
|
||||||
@@ -125,6 +133,10 @@ var TomahawkResolver = {
|
|||||||
search: function( qid, searchString )
|
search: function( qid, searchString )
|
||||||
{
|
{
|
||||||
return this.resolve( qid, "", "", searchString );
|
return this.resolve( qid, "", "", searchString );
|
||||||
|
},
|
||||||
|
capabilities: function()
|
||||||
|
{
|
||||||
|
return TomahawkResolverCapability.NullCapability;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -51,6 +51,16 @@ public:
|
|||||||
FailedToLoad
|
FailedToLoad
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum Capability
|
||||||
|
{
|
||||||
|
NullCapability = 0x0,
|
||||||
|
Browsable = 0x1, // can be represented in one or more collection tree views
|
||||||
|
PlaylistSync = 0x2, // can sync playlists
|
||||||
|
AccountFactory = 0x4 // can configure multiple accounts at the same time
|
||||||
|
};
|
||||||
|
Q_DECLARE_FLAGS( Capabilities, Capability )
|
||||||
|
Q_FLAGS( Capabilities )
|
||||||
|
|
||||||
ExternalResolver( const QString& filePath ) { m_filePath = filePath; }
|
ExternalResolver( const QString& filePath ) { m_filePath = filePath; }
|
||||||
|
|
||||||
virtual QString filePath() const { return m_filePath; }
|
virtual QString filePath() const { return m_filePath; }
|
||||||
@@ -60,6 +70,7 @@ public:
|
|||||||
virtual void reload() {} // Reloads from file (especially useful to check if file now exists)
|
virtual void reload() {} // Reloads from file (especially useful to check if file now exists)
|
||||||
virtual ErrorState error() const;
|
virtual ErrorState error() const;
|
||||||
virtual bool running() const = 0;
|
virtual bool running() const = 0;
|
||||||
|
virtual Capabilities capabilities() const = 0;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
virtual void start() = 0;
|
virtual void start() = 0;
|
||||||
@@ -67,14 +78,19 @@ public slots:
|
|||||||
|
|
||||||
signals:
|
signals:
|
||||||
void changed(); // if config widget was added/removed, name changed, etc
|
void changed(); // if config widget was added/removed, name changed, etc
|
||||||
|
void collectionAdded( const Tomahawk::collection_ptr& collection );
|
||||||
|
void collectionRemoved( const Tomahawk::collection_ptr& collection );
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void setFilePath( const QString& path ) { m_filePath = path; }
|
void setFilePath( const QString& path ) { m_filePath = path; }
|
||||||
|
QList< Tomahawk::collection_ptr > m_collections;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString m_filePath;
|
QString m_filePath;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Q_DECLARE_OPERATORS_FOR_FLAGS( ExternalResolver::Capabilities )
|
||||||
|
|
||||||
}; //ns
|
}; //ns
|
||||||
|
|
||||||
#endif // EXTERNALESOLVER_H
|
#endif // EXTERNALESOLVER_H
|
||||||
|
@@ -334,6 +334,13 @@ QtScriptResolver::init()
|
|||||||
m_timeout = m.value( "timeout", 25 ).toUInt() * 1000;
|
m_timeout = m.value( "timeout", 25 ).toUInt() * 1000;
|
||||||
bool compressed = m.value( "compressed", "false" ).toString() == "true";
|
bool compressed = m.value( "compressed", "false" ).toString() == "true";
|
||||||
|
|
||||||
|
bool ok = 0;
|
||||||
|
int intCap = m_engine->mainFrame()->evaluateJavaScript( "resolver.capabilities()" ).toInt( &ok );
|
||||||
|
if ( !ok )
|
||||||
|
m_capabilities = NullCapability;
|
||||||
|
else
|
||||||
|
m_capabilities = static_cast< Capabilities >( intCap );
|
||||||
|
|
||||||
QByteArray icoData = m.value( "icon" ).toByteArray();
|
QByteArray icoData = m.value( "icon" ).toByteArray();
|
||||||
if( compressed )
|
if( compressed )
|
||||||
icoData = qUncompress( QByteArray::fromBase64( icoData ) );
|
icoData = qUncompress( QByteArray::fromBase64( icoData ) );
|
||||||
|
@@ -129,6 +129,8 @@ public:
|
|||||||
virtual ~QtScriptResolver();
|
virtual ~QtScriptResolver();
|
||||||
static ExternalResolver* factory( const QString& scriptPath );
|
static ExternalResolver* factory( const QString& scriptPath );
|
||||||
|
|
||||||
|
virtual Capabilities capabilities() const { return m_capabilities; }
|
||||||
|
|
||||||
virtual QString name() const { return m_name; }
|
virtual QString name() const { return m_name; }
|
||||||
virtual QPixmap icon() const { return m_icon; }
|
virtual QPixmap icon() const { return m_icon; }
|
||||||
virtual unsigned int weight() const { return m_weight; }
|
virtual unsigned int weight() const { return m_weight; }
|
||||||
@@ -171,6 +173,7 @@ private:
|
|||||||
QString m_name;
|
QString m_name;
|
||||||
QPixmap m_icon;
|
QPixmap m_icon;
|
||||||
unsigned int m_weight, m_timeout;
|
unsigned int m_weight, m_timeout;
|
||||||
|
Capabilities m_capabilities;
|
||||||
|
|
||||||
bool m_ready, m_stopped;
|
bool m_ready, m_stopped;
|
||||||
ExternalResolver::ErrorState m_error;
|
ExternalResolver::ErrorState m_error;
|
||||||
|
@@ -19,16 +19,20 @@
|
|||||||
|
|
||||||
#include "ScriptCollection.h"
|
#include "ScriptCollection.h"
|
||||||
|
|
||||||
|
#include "Source.h"
|
||||||
|
|
||||||
using namespace Tomahawk;
|
using namespace Tomahawk;
|
||||||
|
|
||||||
|
|
||||||
ScriptCollection::ScriptCollection( const source_ptr& source,
|
ScriptCollection::ScriptCollection( const source_ptr& source,
|
||||||
const QString& name,
|
|
||||||
QtScriptResolver* resolver,
|
QtScriptResolver* resolver,
|
||||||
QObject* parent )
|
QObject* parent )
|
||||||
: Collection( source, name, parent )
|
: Collection( source, resolver->name(), parent )
|
||||||
{
|
{
|
||||||
|
Q_ASSERT( resolver != 0 );
|
||||||
|
qDebug() << Q_FUNC_INFO << resolver->name() << source->friendlyName();
|
||||||
|
|
||||||
|
m_resolver = resolver;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -36,14 +36,12 @@ class DLLEXPORT ScriptCollection : public Collection
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
explicit ScriptCollection( const source_ptr& source,
|
explicit ScriptCollection( const source_ptr& source,
|
||||||
const QString& name,
|
|
||||||
QtScriptResolver* resolver,
|
QtScriptResolver* resolver,
|
||||||
QObject* parent = 0 );
|
QObject* parent = 0 );
|
||||||
virtual ~ScriptCollection();
|
virtual ~ScriptCollection();
|
||||||
|
|
||||||
signals:
|
private:
|
||||||
|
QtScriptResolver* m_resolver;
|
||||||
public slots:
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -380,6 +380,13 @@ ScriptResolver::doSetup( const QVariantMap& m )
|
|||||||
m_timeout = m.value( "timeout", 5 ).toUInt() * 1000;
|
m_timeout = m.value( "timeout", 5 ).toUInt() * 1000;
|
||||||
bool compressed = m.value( "compressed", "false" ).toString() == "true";
|
bool compressed = m.value( "compressed", "false" ).toString() == "true";
|
||||||
|
|
||||||
|
bool ok = 0;
|
||||||
|
int intCap = m.value( "capabilities" ).toInt( &ok );
|
||||||
|
if ( !ok )
|
||||||
|
m_capabilities = NullCapability;
|
||||||
|
else
|
||||||
|
m_capabilities = static_cast< Capabilities >( intCap );
|
||||||
|
|
||||||
QByteArray icoData = m.value( "icon" ).toByteArray();
|
QByteArray icoData = m.value( "icon" ).toByteArray();
|
||||||
if( compressed )
|
if( compressed )
|
||||||
icoData = qUncompress( QByteArray::fromBase64( icoData ) );
|
icoData = qUncompress( QByteArray::fromBase64( icoData ) );
|
||||||
|
@@ -46,6 +46,7 @@ public:
|
|||||||
virtual unsigned int weight() const { return m_weight; }
|
virtual unsigned int weight() const { return m_weight; }
|
||||||
virtual unsigned int preference() const { return m_preference; }
|
virtual unsigned int preference() const { return m_preference; }
|
||||||
virtual unsigned int timeout() const { return m_timeout; }
|
virtual unsigned int timeout() const { return m_timeout; }
|
||||||
|
virtual Capabilities capabilities() const { return m_capabilities; }
|
||||||
|
|
||||||
virtual void setIcon( const QPixmap& icon );
|
virtual void setIcon( const QPixmap& icon );
|
||||||
|
|
||||||
@@ -87,6 +88,7 @@ private:
|
|||||||
QString m_name;
|
QString m_name;
|
||||||
QPixmap m_icon;
|
QPixmap m_icon;
|
||||||
unsigned int m_weight, m_preference, m_timeout, m_num_restarts;
|
unsigned int m_weight, m_preference, m_timeout, m_num_restarts;
|
||||||
|
Capabilities m_capabilities;
|
||||||
QPointer< AccountConfigWidget > m_configWidget;
|
QPointer< AccountConfigWidget > m_configWidget;
|
||||||
|
|
||||||
quint32 m_msgsize;
|
quint32 m_msgsize;
|
||||||
|
Reference in New Issue
Block a user