1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-01-18 06:48:23 +01:00

Support legacy collection api

This commit is contained in:
Dominik Schmidt 2015-01-10 22:34:51 +01:00
parent 893a0df845
commit 8ac87615c9
5 changed files with 42 additions and 6 deletions

View File

@ -622,9 +622,11 @@ Tomahawk.PluginManager = {
Tomahawk.unregisterScriptPlugin(type, object.id);
},
invokeSync: function (objectId, methodName, params) {
resolve: [],
invokeSync: function (requestId, objectId, methodName, params) {
var pluginManager = this;
if (!this.objects[objectId]) {
Tomahawk.log("Object not found!");
Tomahawk.log("Object not found! objectId: " + objectId + " methodName: " + methodName);
} else {
if (!this.objects[objectId][methodName]) {
Tomahawk.log("Function not found: " + methodName);
@ -632,6 +634,25 @@ Tomahawk.PluginManager = {
}
if (typeof this.objects[objectId][methodName] === 'function') {
if (!Tomahawk.resolver.instance.apiVersion || Tomahawk.resolver.instance.apiVersion < 0.9) {
if (methodName == 'artists') {
return new Promise(function (resolve, reject) {
pluginManager.resolve[requestId] = resolve;
Tomahawk.resolver.instance.artists(requestId);
});
} else if (methodName == 'albums') {
return new Promise(function (resolve, reject) {
pluginManager.resolve[requestId] = resolve;
Tomahawk.resolver.instance.albums(requestId, params.artist);
});
} else if (methodName == 'tracks') {
return new Promise(function (resolve, reject) {
pluginManager.resolve[requestId] = resolve;
Tomahawk.resolver.instance.tracks(requestId, params.artist, params.album);
});
}
}
return this.objects[objectId][methodName](params);
}
@ -639,7 +660,7 @@ Tomahawk.PluginManager = {
},
invoke: function (requestId, objectId, methodName, params ) {
Promise.resolve(this.invokeSync(objectId, methodName, params)).then(function (result) {
Promise.resolve(this.invokeSync(requestId, objectId, methodName, params)).then(function (result) {
if (typeof result === 'object') {
Tomahawk.reportScriptJobResults({
requestId: requestId,
@ -671,3 +692,17 @@ Tomahawk.ConfigTestResultType = {
PlayingElsewhere: 6,
AccountExpired: 7
};
// Legacy compability for 0.8 and before
Tomahawk.reportCapabilities = function (capabilities) {
if (capabilities & TomahawkResolverCapability.Browsable) {
Tomahawk.PluginManager.registerPlugin("collection", Tomahawk.resolver.instance);
}
Tomahawk.nativeReportCapabilities(capabilities);
};
Tomahawk.addArtistResults = Tomahawk.addAlbumResults = Tomahawk.addAlbumTrackResults = function (result) {
Tomahawk.PluginManager.resolve[result.qid](result);
};

View File

@ -155,6 +155,7 @@ JSAccount::syncInvoke( const scriptobject_ptr& scriptObject, const QString& meth
{
QString eval = QString(
"Tomahawk.PluginManager.invokeSync("
"0, " // requestId
"'%1'," // objectId
"'%2'," // methodName
"%3" // arguments

View File

@ -308,7 +308,7 @@ JSResolverHelper::addUrlResult( const QString& url, const QVariantMap& result )
void
JSResolverHelper::reportCapabilities( const QVariant& v )
JSResolverHelper::nativeReportCapabilities( const QVariant& v )
{
bool ok;
int intCap = v.toInt( &ok );

View File

@ -145,7 +145,7 @@ public slots:
void addUrlResult( const QString& url, const QVariantMap& result );
void reportCapabilities( const QVariant& capabilities );
void nativeReportCapabilities( const QVariant& capabilities );
void reportScriptJobResults( const QVariantMap& result );

View File

@ -112,7 +112,7 @@ ScriptCommand_AllTracks::onTracksJobDone( const QVariantMap& result )
QSharedPointer< ScriptCollection > collection = m_collection.objectCast< ScriptCollection >();
Q_ASSERT( !collection.isNull() );
QList< Tomahawk::result_ptr > t = collection->scriptAccount()->parseResultVariantList( result[ "tracks"].toList() );
QList< Tomahawk::result_ptr > t = collection->scriptAccount()->parseResultVariantList( result[ "results"].toList() );
QList< Tomahawk::query_ptr > queries;