mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-10 16:14:40 +02:00
Remove old way of registering collections
This commit is contained in:
@@ -61,11 +61,6 @@ Pipeline::Pipeline( QObject* parent )
|
|||||||
|
|
||||||
d->temporaryQueryTimer.setInterval( CLEANUP_TIMEOUT );
|
d->temporaryQueryTimer.setInterval( CLEANUP_TIMEOUT );
|
||||||
connect( &d->temporaryQueryTimer, SIGNAL( timeout() ), SLOT( onTemporaryQueryTimer() ) );
|
connect( &d->temporaryQueryTimer, SIGNAL( timeout() ), SLOT( onTemporaryQueryTimer() ) );
|
||||||
|
|
||||||
connect( this, SIGNAL( resolverAdded( Tomahawk::Resolver* ) ),
|
|
||||||
SourceList::instance(), SLOT( onResolverAdded( Tomahawk::Resolver* ) ) );
|
|
||||||
connect( this, SIGNAL( resolverRemoved( Tomahawk::Resolver* ) ),
|
|
||||||
SourceList::instance(), SLOT( onResolverRemoved( Tomahawk::Resolver* ) ) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -272,43 +272,6 @@ SourceList::latchedOff( const source_ptr& to )
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
SourceList::onResolverAdded( Resolver* resolver )
|
|
||||||
{
|
|
||||||
ExternalResolver* r = qobject_cast< ExternalResolver* >( resolver );
|
|
||||||
if ( r == 0 )
|
|
||||||
return;
|
|
||||||
|
|
||||||
foreach ( const Tomahawk::collection_ptr& collection, r->collections() )
|
|
||||||
{
|
|
||||||
addScriptCollection( collection );
|
|
||||||
}
|
|
||||||
|
|
||||||
connect( r, SIGNAL( collectionAdded( Tomahawk::collection_ptr ) ),
|
|
||||||
this, SLOT( addScriptCollection( Tomahawk::collection_ptr ) ) );
|
|
||||||
connect( r, SIGNAL( collectionRemoved(Tomahawk::collection_ptr) ),
|
|
||||||
this, SLOT( removeScriptCollection( Tomahawk::collection_ptr ) ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
SourceList::onResolverRemoved( Resolver* resolver )
|
|
||||||
{
|
|
||||||
ExternalResolver* r = qobject_cast< ExternalResolver* >( resolver );
|
|
||||||
if ( r == 0 )
|
|
||||||
return;
|
|
||||||
|
|
||||||
foreach ( const Tomahawk::collection_ptr& collection, m_scriptCollections )
|
|
||||||
if ( qobject_cast< ScriptCollection* >( collection.data() )->resolver() == r )
|
|
||||||
removeScriptCollection( collection );
|
|
||||||
|
|
||||||
disconnect( r, SIGNAL( collectionAdded( Tomahawk::collection_ptr ) ),
|
|
||||||
this, SLOT( addScriptCollection( Tomahawk::collection_ptr ) ) );
|
|
||||||
disconnect( r, SIGNAL( collectionRemoved(Tomahawk::collection_ptr) ),
|
|
||||||
this, SLOT( removeScriptCollection( Tomahawk::collection_ptr ) ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
SourceList::addScriptCollection( const collection_ptr& collection )
|
SourceList::addScriptCollection( const collection_ptr& collection )
|
||||||
{
|
{
|
||||||
|
@@ -62,9 +62,6 @@ public slots:
|
|||||||
void createPlaylist( const Tomahawk::source_ptr& src, const QVariant& contents );
|
void createPlaylist( const Tomahawk::source_ptr& src, const QVariant& contents );
|
||||||
void createDynamicPlaylist( const Tomahawk::source_ptr& src, const QVariant& contents );
|
void createDynamicPlaylist( const Tomahawk::source_ptr& src, const QVariant& contents );
|
||||||
|
|
||||||
void onResolverAdded( Tomahawk::Resolver* resolver );
|
|
||||||
void onResolverRemoved( Tomahawk::Resolver* resolver );
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void ready();
|
void ready();
|
||||||
|
|
||||||
|
@@ -96,7 +96,6 @@ 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 QMap< QString, Tomahawk::collection_ptr > collections() { return m_collections; }
|
|
||||||
|
|
||||||
// UrlLookup, sync call
|
// UrlLookup, sync call
|
||||||
virtual bool canParseUrl( const QString& url, UrlType type ) = 0;
|
virtual bool canParseUrl( const QString& url, UrlType type ) = 0;
|
||||||
@@ -110,8 +109,6 @@ 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 );
|
|
||||||
|
|
||||||
void artistsFound( const QList< Tomahawk::artist_ptr >& );
|
void artistsFound( const QList< Tomahawk::artist_ptr >& );
|
||||||
void albumsFound( const QList< Tomahawk::album_ptr >& );
|
void albumsFound( const QList< Tomahawk::album_ptr >& );
|
||||||
@@ -120,7 +117,6 @@ signals:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
void setFilePath( const QString& path ) { m_filePath = path; }
|
void setFilePath( const QString& path ) { m_filePath = path; }
|
||||||
QMap< QString, Tomahawk::collection_ptr > m_collections;
|
|
||||||
ScriptCommandQueue* m_commandQueue;
|
ScriptCommandQueue* m_commandQueue;
|
||||||
|
|
||||||
// Should only be called by ScriptCommands
|
// Should only be called by ScriptCommands
|
||||||
|
@@ -323,7 +323,7 @@ JSResolver::artists( const Tomahawk::collection_ptr& collection )
|
|||||||
|
|
||||||
Q_D( const JSResolver );
|
Q_D( const JSResolver );
|
||||||
|
|
||||||
if ( !m_collections.contains( collection->name() ) || //if the collection doesn't belong to this resolver
|
if ( /* !m_collections.contains( collection->name() ) || */ //if the collection doesn't belong to this resolver
|
||||||
!d->capabilities.testFlag( Browsable ) ) //or this resolver doesn't even support collections
|
!d->capabilities.testFlag( Browsable ) ) //or this resolver doesn't even support collections
|
||||||
{
|
{
|
||||||
emit artistsFound( QList< Tomahawk::artist_ptr >() );
|
emit artistsFound( QList< Tomahawk::artist_ptr >() );
|
||||||
@@ -359,7 +359,7 @@ JSResolver::albums( const Tomahawk::collection_ptr& collection, const Tomahawk::
|
|||||||
|
|
||||||
Q_D( const JSResolver );
|
Q_D( const JSResolver );
|
||||||
|
|
||||||
if ( !m_collections.contains( collection->name() ) || //if the collection doesn't belong to this resolver
|
if ( /* !m_collections.contains( collection->name() ) || */ //if the collection doesn't belong to this resolver
|
||||||
!d->capabilities.testFlag( Browsable ) ) //or this resolver doesn't even support collections
|
!d->capabilities.testFlag( Browsable ) ) //or this resolver doesn't even support collections
|
||||||
{
|
{
|
||||||
emit albumsFound( QList< Tomahawk::album_ptr >() );
|
emit albumsFound( QList< Tomahawk::album_ptr >() );
|
||||||
@@ -396,7 +396,7 @@ JSResolver::tracks( const Tomahawk::collection_ptr& collection, const Tomahawk::
|
|||||||
|
|
||||||
Q_D( const JSResolver );
|
Q_D( const JSResolver );
|
||||||
|
|
||||||
if ( !m_collections.contains( collection->name() ) || //if the collection doesn't belong to this resolver
|
if ( /* !m_collections.contains( collection->name() ) || */ //if the collection doesn't belong to this resolver
|
||||||
!d->capabilities.testFlag( Browsable ) ) //or this resolver doesn't even support collections
|
!d->capabilities.testFlag( Browsable ) ) //or this resolver doesn't even support collections
|
||||||
{
|
{
|
||||||
emit tracksFound( QList< Tomahawk::query_ptr >() );
|
emit tracksFound( QList< Tomahawk::query_ptr >() );
|
||||||
@@ -602,15 +602,6 @@ JSResolver::parseResultVariantList( const QVariantList& reslist )
|
|||||||
if ( !collectionId.isEmpty() )
|
if ( !collectionId.isEmpty() )
|
||||||
{
|
{
|
||||||
Tomahawk::collection_ptr collection = Tomahawk::collection_ptr();
|
Tomahawk::collection_ptr collection = Tomahawk::collection_ptr();
|
||||||
foreach ( const Tomahawk::collection_ptr& coll, collections() )
|
|
||||||
{
|
|
||||||
Tomahawk::ScriptCollection* scriptCollection = qobject_cast<Tomahawk::ScriptCollection*>( coll.data() );
|
|
||||||
Q_ASSERT( scriptCollection );
|
|
||||||
if ( scriptCollection->id() == collectionId )
|
|
||||||
{
|
|
||||||
collection = coll;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ( !collection.isNull() )
|
if ( !collection.isNull() )
|
||||||
{
|
{
|
||||||
rp->setResolvedByCollection( collection );
|
rp->setResolvedByCollection( collection );
|
||||||
@@ -671,10 +662,6 @@ JSResolver::stop()
|
|||||||
|
|
||||||
d->stopped = true;
|
d->stopped = true;
|
||||||
|
|
||||||
foreach ( const Tomahawk::collection_ptr& collection, m_collections )
|
|
||||||
{
|
|
||||||
emit collectionRemoved( collection );
|
|
||||||
}
|
|
||||||
|
|
||||||
Tomahawk::Pipeline::instance()->removeResolver( this );
|
Tomahawk::Pipeline::instance()->removeResolver( this );
|
||||||
emit stopped();
|
emit stopped();
|
||||||
@@ -757,84 +744,6 @@ JSResolver::onCapabilitiesChanged( Tomahawk::ExternalResolver::Capabilities capa
|
|||||||
Q_D( JSResolver );
|
Q_D( JSResolver );
|
||||||
|
|
||||||
d->capabilities = capabilities;
|
d->capabilities = capabilities;
|
||||||
loadCollections();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
JSResolver::loadCollections()
|
|
||||||
{
|
|
||||||
Q_D( JSResolver );
|
|
||||||
|
|
||||||
if ( d->capabilities.testFlag( Browsable ) )
|
|
||||||
{
|
|
||||||
|
|
||||||
foreach ( Tomahawk::collection_ptr collection, m_collections )
|
|
||||||
{
|
|
||||||
emit collectionRemoved( collection );
|
|
||||||
}
|
|
||||||
|
|
||||||
const QVariantMap collectionInfo = callOnResolver( "collection()" ).toMap();
|
|
||||||
if ( collectionInfo.isEmpty() ||
|
|
||||||
!collectionInfo.contains( "prettyname" ) ||
|
|
||||||
!collectionInfo.contains( "description" ) )
|
|
||||||
return;
|
|
||||||
|
|
||||||
const QString prettyname = collectionInfo.value( "prettyname" ).toString();
|
|
||||||
const QString desc = collectionInfo.value( "description" ).toString();
|
|
||||||
|
|
||||||
m_collections.clear();
|
|
||||||
// at this point we assume that all the tracks browsable through a resolver belong to the local source
|
|
||||||
Tomahawk::ScriptCollection* sc = new Tomahawk::ScriptCollection( collectionInfo[ "id" ].toString(), SourceList::instance()->getLocal(), this );
|
|
||||||
Tomahawk::collection_ptr collection( sc );
|
|
||||||
collection->setWeakRef( collection.toWeakRef() );
|
|
||||||
|
|
||||||
sc->setServiceName( prettyname );
|
|
||||||
sc->setDescription( desc );
|
|
||||||
|
|
||||||
if ( collectionInfo.contains( "trackcount" ) ) //a resolver might not expose this
|
|
||||||
{
|
|
||||||
bool ok = false;
|
|
||||||
int trackCount = collectionInfo.value( "trackcount" ).toInt( &ok );
|
|
||||||
if ( ok )
|
|
||||||
sc->setTrackCount( trackCount );
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( collectionInfo.contains( "iconfile" ) )
|
|
||||||
{
|
|
||||||
QString iconPath = QFileInfo( filePath() ).path() + "/"
|
|
||||||
+ collectionInfo.value( "iconfile" ).toString();
|
|
||||||
|
|
||||||
QPixmap iconPixmap;
|
|
||||||
bool ok = iconPixmap.load( iconPath );
|
|
||||||
if ( ok && !iconPixmap.isNull() )
|
|
||||||
sc->setIcon( iconPixmap );
|
|
||||||
}
|
|
||||||
|
|
||||||
m_collections.insert( collection->name(), collection );
|
|
||||||
emit collectionAdded( collection );
|
|
||||||
|
|
||||||
if ( collectionInfo.contains( "iconurl" ) )
|
|
||||||
{
|
|
||||||
QString iconUrlString = collectionInfo.value( "iconurl" ).toString();
|
|
||||||
if ( !iconUrlString.isEmpty() )
|
|
||||||
{
|
|
||||||
QUrl iconUrl = QUrl::fromEncoded( iconUrlString.toLatin1() );
|
|
||||||
if ( iconUrl.isValid() )
|
|
||||||
{
|
|
||||||
QNetworkRequest req( iconUrl );
|
|
||||||
tDebug() << "Creating a QNetworkReply with url:" << req.url().toString();
|
|
||||||
QNetworkReply* reply = Tomahawk::Utils::nam()->get( req );
|
|
||||||
reply->setProperty( "collectionName", collection->name() );
|
|
||||||
|
|
||||||
connect( reply, SIGNAL( finished() ),
|
|
||||||
this, SLOT( onCollectionIconFetched() ) );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//TODO: implement multiple collections from a resolver
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -845,7 +754,7 @@ JSResolver::onCollectionIconFetched()
|
|||||||
if ( reply != 0 )
|
if ( reply != 0 )
|
||||||
{
|
{
|
||||||
Tomahawk::collection_ptr collection;
|
Tomahawk::collection_ptr collection;
|
||||||
collection = m_collections.value( reply->property( "collectionName" ).toString() );
|
/* collection = m_collections.value( reply->property( "collectionName" ).toString() ); */
|
||||||
if ( !collection.isNull() )
|
if ( !collection.isNull() )
|
||||||
{
|
{
|
||||||
if ( reply->error() == QNetworkReply::NoError )
|
if ( reply->error() == QNetworkReply::NoError )
|
||||||
@@ -883,17 +792,6 @@ JSResolver::resolverInit()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QVariantMap
|
|
||||||
JSResolver::resolverCollections()
|
|
||||||
{
|
|
||||||
return QVariantMap(); //TODO: add a way to distinguish collections
|
|
||||||
// the resolver should provide a unique ID string for each collection, and then be queriable
|
|
||||||
// against this ID. doesn't matter what kind of ID string as long as it's unique.
|
|
||||||
// Then when there's callbacks from a resolver, it sends source name, collection id
|
|
||||||
// + data.
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
QVariant
|
QVariant
|
||||||
JSResolver::callOnResolver( const QString& scriptSource )
|
JSResolver::callOnResolver( const QString& scriptSource )
|
||||||
{
|
{
|
||||||
|
@@ -99,13 +99,11 @@ private:
|
|||||||
|
|
||||||
void loadUi();
|
void loadUi();
|
||||||
void onCapabilitiesChanged( Capabilities capabilities );
|
void onCapabilitiesChanged( Capabilities capabilities );
|
||||||
void loadCollections();
|
|
||||||
|
|
||||||
// encapsulate javascript calls
|
// encapsulate javascript calls
|
||||||
QVariantMap resolverSettings();
|
QVariantMap resolverSettings();
|
||||||
QVariantMap resolverUserConfig();
|
QVariantMap resolverUserConfig();
|
||||||
QVariantMap resolverInit();
|
QVariantMap resolverInit();
|
||||||
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 );
|
QList< Tomahawk::artist_ptr > parseArtistVariantList( const QVariantList& reslist );
|
||||||
|
@@ -151,13 +151,6 @@ JSResolverHelper::addArtistResults( const QVariantMap& results )
|
|||||||
QString qid = results.value("qid").toString();
|
QString qid = results.value("qid").toString();
|
||||||
|
|
||||||
Tomahawk::collection_ptr collection = Tomahawk::collection_ptr();
|
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() )
|
if ( collection.isNull() )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -182,13 +175,6 @@ JSResolverHelper::addAlbumResults( const QVariantMap& results )
|
|||||||
QString qid = results.value("qid").toString();
|
QString qid = results.value("qid").toString();
|
||||||
|
|
||||||
Tomahawk::collection_ptr collection = Tomahawk::collection_ptr();
|
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() )
|
if ( collection.isNull() )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -219,13 +205,6 @@ JSResolverHelper::addAlbumTrackResults( const QVariantMap& results )
|
|||||||
QString qid = results.value("qid").toString();
|
QString qid = results.value("qid").toString();
|
||||||
|
|
||||||
Tomahawk::collection_ptr collection = Tomahawk::collection_ptr();
|
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() )
|
if ( collection.isNull() )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@@ -580,11 +580,5 @@ ScriptResolver::stop()
|
|||||||
{
|
{
|
||||||
m_stopped = true;
|
m_stopped = true;
|
||||||
|
|
||||||
foreach ( const Tomahawk::collection_ptr& collection, m_collections )
|
|
||||||
{
|
|
||||||
emit collectionRemoved( collection );
|
|
||||||
}
|
|
||||||
m_collections.clear();
|
|
||||||
|
|
||||||
Tomahawk::Pipeline::instance()->removeResolver( this );
|
Tomahawk::Pipeline::instance()->removeResolver( this );
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user