From 2455d5f12d18ac4634a47b45470503c2f72ba6be Mon Sep 17 00:00:00 2001 From: Dominik Schmidt Date: Fri, 9 Jan 2015 19:54:08 +0100 Subject: [PATCH] Remove old way of registering collections --- src/libtomahawk/Pipeline.cpp | 5 - src/libtomahawk/SourceList.cpp | 37 ------ src/libtomahawk/SourceList.h | 3 - src/libtomahawk/resolvers/ExternalResolver.h | 4 - src/libtomahawk/resolvers/JSResolver.cpp | 110 +----------------- src/libtomahawk/resolvers/JSResolver.h | 2 - .../resolvers/JSResolverHelper.cpp | 21 ---- src/libtomahawk/resolvers/ScriptResolver.cpp | 6 - 8 files changed, 4 insertions(+), 184 deletions(-) diff --git a/src/libtomahawk/Pipeline.cpp b/src/libtomahawk/Pipeline.cpp index fd7f5235b..2e1c6858c 100644 --- a/src/libtomahawk/Pipeline.cpp +++ b/src/libtomahawk/Pipeline.cpp @@ -61,11 +61,6 @@ Pipeline::Pipeline( QObject* parent ) d->temporaryQueryTimer.setInterval( CLEANUP_TIMEOUT ); 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* ) ) ); } diff --git a/src/libtomahawk/SourceList.cpp b/src/libtomahawk/SourceList.cpp index 141b76ac9..65d29878f 100644 --- a/src/libtomahawk/SourceList.cpp +++ b/src/libtomahawk/SourceList.cpp @@ -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 SourceList::addScriptCollection( const collection_ptr& collection ) { diff --git a/src/libtomahawk/SourceList.h b/src/libtomahawk/SourceList.h index c38e8cbea..cbed603ba 100644 --- a/src/libtomahawk/SourceList.h +++ b/src/libtomahawk/SourceList.h @@ -62,9 +62,6 @@ public slots: void createPlaylist( 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: void ready(); diff --git a/src/libtomahawk/resolvers/ExternalResolver.h b/src/libtomahawk/resolvers/ExternalResolver.h index ea1865324..9a553d0bd 100644 --- a/src/libtomahawk/resolvers/ExternalResolver.h +++ b/src/libtomahawk/resolvers/ExternalResolver.h @@ -96,7 +96,6 @@ public: virtual ErrorState error() const; virtual bool running() const = 0; virtual Capabilities capabilities() const = 0; - virtual QMap< QString, Tomahawk::collection_ptr > collections() { return m_collections; } // UrlLookup, sync call virtual bool canParseUrl( const QString& url, UrlType type ) = 0; @@ -110,8 +109,6 @@ public slots: signals: 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 albumsFound( const QList< Tomahawk::album_ptr >& ); @@ -120,7 +117,6 @@ signals: protected: void setFilePath( const QString& path ) { m_filePath = path; } - QMap< QString, Tomahawk::collection_ptr > m_collections; ScriptCommandQueue* m_commandQueue; // Should only be called by ScriptCommands diff --git a/src/libtomahawk/resolvers/JSResolver.cpp b/src/libtomahawk/resolvers/JSResolver.cpp index ae1dd13b4..043407f65 100644 --- a/src/libtomahawk/resolvers/JSResolver.cpp +++ b/src/libtomahawk/resolvers/JSResolver.cpp @@ -323,7 +323,7 @@ JSResolver::artists( const Tomahawk::collection_ptr& collection ) 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 { emit artistsFound( QList< Tomahawk::artist_ptr >() ); @@ -359,7 +359,7 @@ JSResolver::albums( const Tomahawk::collection_ptr& collection, const Tomahawk:: 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 { emit albumsFound( QList< Tomahawk::album_ptr >() ); @@ -396,7 +396,7 @@ JSResolver::tracks( const Tomahawk::collection_ptr& collection, const Tomahawk:: 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 { emit tracksFound( QList< Tomahawk::query_ptr >() ); @@ -602,15 +602,6 @@ JSResolver::parseResultVariantList( const QVariantList& reslist ) if ( !collectionId.isEmpty() ) { Tomahawk::collection_ptr collection = Tomahawk::collection_ptr(); - foreach ( const Tomahawk::collection_ptr& coll, collections() ) - { - Tomahawk::ScriptCollection* scriptCollection = qobject_cast( coll.data() ); - Q_ASSERT( scriptCollection ); - if ( scriptCollection->id() == collectionId ) - { - collection = coll; - } - } if ( !collection.isNull() ) { rp->setResolvedByCollection( collection ); @@ -671,10 +662,6 @@ JSResolver::stop() d->stopped = true; - foreach ( const Tomahawk::collection_ptr& collection, m_collections ) - { - emit collectionRemoved( collection ); - } Tomahawk::Pipeline::instance()->removeResolver( this ); emit stopped(); @@ -757,84 +744,6 @@ JSResolver::onCapabilitiesChanged( Tomahawk::ExternalResolver::Capabilities capa Q_D( JSResolver ); 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 ) { Tomahawk::collection_ptr collection; - collection = m_collections.value( reply->property( "collectionName" ).toString() ); + /* collection = m_collections.value( reply->property( "collectionName" ).toString() ); */ if ( !collection.isNull() ) { 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 JSResolver::callOnResolver( const QString& scriptSource ) { diff --git a/src/libtomahawk/resolvers/JSResolver.h b/src/libtomahawk/resolvers/JSResolver.h index c4fac1920..c13ba7f06 100644 --- a/src/libtomahawk/resolvers/JSResolver.h +++ b/src/libtomahawk/resolvers/JSResolver.h @@ -99,13 +99,11 @@ private: void loadUi(); void onCapabilitiesChanged( Capabilities capabilities ); - void loadCollections(); // encapsulate javascript calls QVariantMap resolverSettings(); QVariantMap resolverUserConfig(); QVariantMap resolverInit(); - QVariantMap resolverCollections(); QList< Tomahawk::result_ptr > parseResultVariantList( const QVariantList& reslist ); QList< Tomahawk::artist_ptr > parseArtistVariantList( const QVariantList& reslist ); diff --git a/src/libtomahawk/resolvers/JSResolverHelper.cpp b/src/libtomahawk/resolvers/JSResolverHelper.cpp index 5eb5e155e..684486af5 100644 --- a/src/libtomahawk/resolvers/JSResolverHelper.cpp +++ b/src/libtomahawk/resolvers/JSResolverHelper.cpp @@ -151,13 +151,6 @@ JSResolverHelper::addArtistResults( const QVariantMap& results ) 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; @@ -182,13 +175,6 @@ JSResolverHelper::addAlbumResults( const QVariantMap& results ) 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; @@ -219,13 +205,6 @@ JSResolverHelper::addAlbumTrackResults( const QVariantMap& results ) 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; diff --git a/src/libtomahawk/resolvers/ScriptResolver.cpp b/src/libtomahawk/resolvers/ScriptResolver.cpp index f7a153078..eeb5262b6 100644 --- a/src/libtomahawk/resolvers/ScriptResolver.cpp +++ b/src/libtomahawk/resolvers/ScriptResolver.cpp @@ -580,11 +580,5 @@ ScriptResolver::stop() { m_stopped = true; - foreach ( const Tomahawk::collection_ptr& collection, m_collections ) - { - emit collectionRemoved( collection ); - } - m_collections.clear(); - Tomahawk::Pipeline::instance()->removeResolver( this ); }