mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-05 05:37:29 +02:00
Artists fetching support in scriptcollection.
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
*
|
*
|
||||||
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
|
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
|
||||||
* Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
|
* Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
|
||||||
|
* Copyright 2013, Teo Mrnjavac <teo@kde.org>
|
||||||
*
|
*
|
||||||
* Tomahawk is free software: you can redistribute it and/or modify
|
* Tomahawk is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@@ -71,12 +72,17 @@ public:
|
|||||||
virtual ErrorState error() const;
|
virtual ErrorState error() const;
|
||||||
virtual bool running() const = 0;
|
virtual bool running() const = 0;
|
||||||
virtual Capabilities capabilities() const = 0;
|
virtual Capabilities capabilities() const = 0;
|
||||||
virtual QList< Tomahawk::collection_ptr > collections() { return m_collections; }
|
virtual QMap< QString, Tomahawk::collection_ptr > collections() { return m_collections; }
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
virtual void start() = 0;
|
virtual void start() = 0;
|
||||||
virtual void stop() = 0;
|
virtual void stop() = 0;
|
||||||
|
|
||||||
|
// For ScriptCollection
|
||||||
|
virtual void artists( const Tomahawk::collection_ptr& collection ) = 0;
|
||||||
|
virtual void albums( const Tomahawk::collection_ptr& collection, const Tomahawk::artist_ptr& artist ) = 0;
|
||||||
|
virtual void tracks( const Tomahawk::collection_ptr& collection, const Tomahawk::album_ptr& album ) = 0;
|
||||||
|
|
||||||
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 collectionAdded( const Tomahawk::collection_ptr& collection );
|
||||||
@@ -84,7 +90,7 @@ signals:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
void setFilePath( const QString& path ) { m_filePath = path; }
|
void setFilePath( const QString& path ) { m_filePath = path; }
|
||||||
QList< Tomahawk::collection_ptr > m_collections;
|
QMap< QString, Tomahawk::collection_ptr > m_collections;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString m_filePath;
|
QString m_filePath;
|
||||||
|
@@ -134,6 +134,37 @@ QtScriptResolverHelper::addTrackResults( const QVariantMap& results )
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
QtScriptResolverHelper::addArtistResults( const QVariantMap& results )
|
||||||
|
{
|
||||||
|
qDebug() << "Resolver reporting artists:" << results;
|
||||||
|
QList< Tomahawk::artist_ptr > artists = m_resolver->parseArtistVariantList( results.value("artists").toList() );
|
||||||
|
|
||||||
|
QString qid = results.value("qid").toString();
|
||||||
|
|
||||||
|
Tomahawk::collection_ptr collection = Tomahawk::collection_ptr();
|
||||||
|
foreach ( const Tomahawk::collection_ptr& coll, m_resolver->collections() )
|
||||||
|
{
|
||||||
|
if ( coll->name() == qid )
|
||||||
|
{
|
||||||
|
collection = coll;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( collection.isNull() )
|
||||||
|
return;
|
||||||
|
|
||||||
|
tDebug() << Q_FUNC_INFO << "about to push" << artists.count() << "artists";
|
||||||
|
foreach( const Tomahawk::artist_ptr& artist, artists)
|
||||||
|
tDebug() << artist->name();
|
||||||
|
QMetaObject::invokeMethod( collection.data(), "onArtistsFetched", Qt::QueuedConnection,
|
||||||
|
Q_ARG( QList< Tomahawk::artist_ptr >, artists ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
void QtScriptResolverHelper::addAlbumResults(const QVariantMap &results)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
QtScriptResolverHelper::setResolverConfig( const QVariantMap& config )
|
QtScriptResolverHelper::setResolverConfig( const QVariantMap& config )
|
||||||
{
|
{
|
||||||
@@ -389,6 +420,57 @@ QtScriptResolver::start()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
QtScriptResolver::artists( const Tomahawk::collection_ptr& collection )
|
||||||
|
{
|
||||||
|
if ( QThread::currentThread() != thread() )
|
||||||
|
{
|
||||||
|
QMetaObject::invokeMethod( this, "artists", Qt::QueuedConnection, Q_ARG( Tomahawk::collection_ptr, collection ) );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !m_collections.contains( collection->name() ) || //if the collection doesn't belong to this resolver
|
||||||
|
!capabilities().testFlag( Browsable ) ) //or this resolver doesn't even support collections
|
||||||
|
{
|
||||||
|
QMetaObject::invokeMethod( collection.data(), "onArtistsFetched", Qt::QueuedConnection,
|
||||||
|
Q_ARG( QList< Tomahawk::artist_ptr >, QList< Tomahawk::artist_ptr >() ) );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString eval = QString( "resolver.artists( '%1' );" )
|
||||||
|
.arg( collection->name().replace( "'", "\\'" ) );
|
||||||
|
|
||||||
|
QVariantMap m = m_engine->mainFrame()->evaluateJavaScript( eval ).toMap();
|
||||||
|
if ( m.isEmpty() )
|
||||||
|
{
|
||||||
|
// if the resolver doesn't return anything, async api is used
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
qDebug() << "Artists JavaScript Result:" << m;
|
||||||
|
|
||||||
|
const QString qid = collection->name();
|
||||||
|
const QVariantList reslist = m.value( "artists" ).toList();
|
||||||
|
|
||||||
|
QList< Tomahawk::artist_ptr > artists = parseArtistVariantList( reslist );
|
||||||
|
|
||||||
|
QMetaObject::invokeMethod( collection.data(), "onArtistsFetched", Qt::QueuedConnection,
|
||||||
|
Q_ARG( QList< Tomahawk::artist_ptr >, artists ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
QtScriptResolver::albums( const Tomahawk::collection_ptr& collection, const Tomahawk::artist_ptr& artist )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
QtScriptResolver::tracks( const Tomahawk::collection_ptr& collection, const Tomahawk::album_ptr& album )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Tomahawk::ExternalResolver::ErrorState
|
Tomahawk::ExternalResolver::ErrorState
|
||||||
QtScriptResolver::error() const
|
QtScriptResolver::error() const
|
||||||
{
|
{
|
||||||
@@ -503,6 +585,24 @@ QtScriptResolver::parseResultVariantList( const QVariantList& reslist )
|
|||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QList< Tomahawk::artist_ptr >
|
||||||
|
QtScriptResolver::parseArtistVariantList( const QVariantList& reslist )
|
||||||
|
{
|
||||||
|
QList< Tomahawk::artist_ptr > results;
|
||||||
|
|
||||||
|
foreach( const QVariant& rv, reslist )
|
||||||
|
{
|
||||||
|
if ( rv.toString().trimmed().isEmpty() )
|
||||||
|
continue;
|
||||||
|
|
||||||
|
Tomahawk::artist_ptr ap = Tomahawk::Artist::get( rv.toString(), false );
|
||||||
|
|
||||||
|
results << ap;
|
||||||
|
}
|
||||||
|
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
QtScriptResolver::stop()
|
QtScriptResolver::stop()
|
||||||
@@ -652,7 +752,7 @@ QtScriptResolver::loadCollections()
|
|||||||
m_collections.clear();
|
m_collections.clear();
|
||||||
// at this point we assume that all the tracks browsable through a resolver belong to the local source
|
// at this point we assume that all the tracks browsable through a resolver belong to the local source
|
||||||
Tomahawk::collection_ptr collection( new Tomahawk::ScriptCollection( SourceList::instance()->getLocal(), this ) );
|
Tomahawk::collection_ptr collection( new Tomahawk::ScriptCollection( SourceList::instance()->getLocal(), this ) );
|
||||||
m_collections.append( collection );
|
m_collections.insert( collection->name(), collection );
|
||||||
emit collectionAdded( collection );
|
emit collectionAdded( collection );
|
||||||
|
|
||||||
//TODO: implement multiple collections from a resolver
|
//TODO: implement multiple collections from a resolver
|
||||||
|
@@ -72,6 +72,9 @@ public slots:
|
|||||||
|
|
||||||
void addTrackResults( const QVariantMap& results );
|
void addTrackResults( const QVariantMap& results );
|
||||||
|
|
||||||
|
void addArtistResults( const QVariantMap& results );
|
||||||
|
void addAlbumResults( const QVariantMap& results );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString m_scriptPath, m_urlCallback;
|
QString m_scriptPath, m_urlCallback;
|
||||||
QVariantMap m_resolverConfig;
|
QVariantMap m_resolverConfig;
|
||||||
@@ -151,6 +154,11 @@ public slots:
|
|||||||
virtual void stop();
|
virtual void stop();
|
||||||
virtual void start();
|
virtual void start();
|
||||||
|
|
||||||
|
// For ScriptCollection
|
||||||
|
virtual void artists( const Tomahawk::collection_ptr& collection );
|
||||||
|
virtual void albums( const Tomahawk::collection_ptr& collection, const Tomahawk::artist_ptr& artist );
|
||||||
|
virtual void tracks( const Tomahawk::collection_ptr& collection, const Tomahawk::album_ptr& album );
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void stopped();
|
void stopped();
|
||||||
|
|
||||||
@@ -171,6 +179,7 @@ private:
|
|||||||
QVariantMap resolverCollections();
|
QVariantMap resolverCollections();
|
||||||
|
|
||||||
QList< Tomahawk::result_ptr > parseResultVariantList( const QVariantList& reslist );
|
QList< Tomahawk::result_ptr > parseResultVariantList( const QVariantList& reslist );
|
||||||
|
QList< Tomahawk::artist_ptr > parseArtistVariantList( const QVariantList& reslist );
|
||||||
|
|
||||||
ScriptEngine* m_engine;
|
ScriptEngine* m_engine;
|
||||||
|
|
||||||
|
@@ -30,10 +30,10 @@ using namespace Tomahawk;
|
|||||||
ScriptCollection::ScriptCollection( const source_ptr& source,
|
ScriptCollection::ScriptCollection( const source_ptr& source,
|
||||||
ExternalResolver* resolver,
|
ExternalResolver* resolver,
|
||||||
QObject* parent )
|
QObject* parent )
|
||||||
: Collection( source, resolver->name(), parent )
|
: Collection( source, QString( "scriptcollection:" + resolver->name() + ":" + uuid() ), parent )
|
||||||
{
|
{
|
||||||
Q_ASSERT( resolver != 0 );
|
Q_ASSERT( resolver != 0 );
|
||||||
qDebug() << Q_FUNC_INFO << resolver->name() << source->friendlyName();
|
qDebug() << Q_FUNC_INFO << resolver->name() << name();
|
||||||
|
|
||||||
m_resolver = resolver;
|
m_resolver = resolver;
|
||||||
}
|
}
|
||||||
@@ -83,8 +83,7 @@ ScriptCollection::icon() const
|
|||||||
void
|
void
|
||||||
ScriptCollection::artists()
|
ScriptCollection::artists()
|
||||||
{
|
{
|
||||||
//TODO: implement!
|
m_resolver->artists( m_resolver->collections().value( name() ) );
|
||||||
emit artistsResult( QList< Tomahawk::artist_ptr >() );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -100,3 +99,22 @@ ScriptCollection::tracks( const Tomahawk::album_ptr& album )
|
|||||||
{
|
{
|
||||||
emit tracksResult( QList< Tomahawk::query_ptr >() );
|
emit tracksResult( QList< Tomahawk::query_ptr >() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
ScriptCollection::onArtistsFetched( const QList<artist_ptr>& artists )
|
||||||
|
{
|
||||||
|
emit artistsResult( artists );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
ScriptCollection::onAlbumsFetched( const QList<album_ptr>& albums )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
ScriptCollection::onTracksFetched( const QList<query_ptr>& tracks )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
@@ -51,9 +51,13 @@ public:
|
|||||||
virtual void albums( const Tomahawk::artist_ptr& artist );
|
virtual void albums( const Tomahawk::artist_ptr& artist );
|
||||||
virtual void tracks( const Tomahawk::album_ptr& album );
|
virtual void tracks( const Tomahawk::album_ptr& album );
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void onArtistsFetched( const QList< Tomahawk::artist_ptr >& artists );
|
||||||
|
void onAlbumsFetched( const QList< Tomahawk::album_ptr >& albums );
|
||||||
|
void onTracksFetched( const QList< Tomahawk::query_ptr >& tracks );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ExternalResolver* m_resolver;
|
ExternalResolver* m_resolver;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} //ns
|
} //ns
|
||||||
|
@@ -454,7 +454,7 @@ ScriptResolver::loadCollections()
|
|||||||
m_collections.clear();
|
m_collections.clear();
|
||||||
// at this point we assume that all the tracks browsable through a resolver belong to the local source
|
// at this point we assume that all the tracks browsable through a resolver belong to the local source
|
||||||
Tomahawk::collection_ptr collection( new Tomahawk::ScriptCollection( SourceList::instance()->getLocal(), this ) );
|
Tomahawk::collection_ptr collection( new Tomahawk::ScriptCollection( SourceList::instance()->getLocal(), this ) );
|
||||||
m_collections.append( collection );
|
m_collections.insert( collection->name(), collection );
|
||||||
emit collectionAdded( collection );
|
emit collectionAdded( collection );
|
||||||
|
|
||||||
//TODO: implement multiple collections from a resolver
|
//TODO: implement multiple collections from a resolver
|
||||||
|
@@ -70,6 +70,12 @@ public slots:
|
|||||||
virtual void resolve( const Tomahawk::query_ptr& query );
|
virtual void resolve( const Tomahawk::query_ptr& query );
|
||||||
virtual void start();
|
virtual void start();
|
||||||
|
|
||||||
|
// TODO: implement. Or not. Not really an issue while Spotify doesn't do browsable personal cloud storage.
|
||||||
|
virtual void artists( const Tomahawk::collection_ptr& collection ){}
|
||||||
|
virtual void albums( const Tomahawk::collection_ptr& collection, const Tomahawk::artist_ptr& artist ) {}
|
||||||
|
virtual void tracks( const Tomahawk::collection_ptr& collection, const Tomahawk::album_ptr& album ) {}
|
||||||
|
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void readStderr();
|
void readStderr();
|
||||||
void readStdout();
|
void readStdout();
|
||||||
|
Reference in New Issue
Block a user