QList<album_ptr> Artist::albums( ModelMode mode, const Tomahawk::collection_ptr& collection ) const { artist_ptr artist = m_ownRef.toStrongRef(); bool dbLoaded = m_albumsLoaded.value( DatabaseMode ); const bool infoLoaded = m_albumsLoaded.value( InfoSystemMode ); if ( !collection.isNull() ) dbLoaded = false; m_uuid = uuid(); tDebug() << Q_FUNC_INFO << mode; if ( ( mode == DatabaseMode || mode == Mixed ) && !dbLoaded ) { DatabaseCommand_AllAlbums* cmd = new DatabaseCommand_AllAlbums( collection, artist ); cmd->setData( QVariant( collection.isNull() ) ); connect( cmd, SIGNAL( albums( QList<Tomahawk::album_ptr>, QVariant ) ), SLOT( onAlbumsFound( QList<Tomahawk::album_ptr>, QVariant ) ) ); Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) ); } if ( ( mode == InfoSystemMode || mode == Mixed ) && !infoLoaded ) { Tomahawk::InfoSystem::InfoStringHash artistInfo; artistInfo["artist"] = name(); Tomahawk::InfoSystem::InfoRequestData requestData; requestData.caller = m_uuid; requestData.input = QVariant::fromValue< Tomahawk::InfoSystem::InfoStringHash >( artistInfo ); requestData.type = Tomahawk::InfoSystem::InfoArtistReleases; connect( Tomahawk::InfoSystem::InfoSystem::instance(), SIGNAL( info( Tomahawk::InfoSystem::InfoRequestData, QVariant ) ), SLOT( infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData, QVariant ) ), Qt::UniqueConnection ); connect( Tomahawk::InfoSystem::InfoSystem::instance(), SIGNAL( finished( QString ) ), SLOT( infoSystemFinished( QString ) ), Qt::UniqueConnection ); m_infoJobs++; Tomahawk::InfoSystem::InfoSystem::instance()->getInfo( requestData ); } if ( !collection.isNull() ) return QList<album_ptr>(); switch ( mode ) { case DatabaseMode: return m_databaseAlbums; case InfoSystemMode: return m_officialAlbums; default: return m_databaseAlbums + m_officialAlbums; } }
void QtScriptResolverHelper::addAlbumTrackResults( const QVariantMap& results ) { qDebug() << "Resolver reporting album tracks:" << results; QString artistName = results.value( "artist" ).toString(); if ( artistName.trimmed().isEmpty() ) return; QString albumName = results.value( "album" ).toString(); if ( albumName.trimmed().isEmpty() ) return; Tomahawk::artist_ptr artist = Tomahawk::Artist::get( artistName, false ); Tomahawk::album_ptr album = Tomahawk::Album::get( artist, albumName, false ); QList< Tomahawk::result_ptr > tracks = m_resolver->parseResultVariantList( results.value("results").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; QList< Tomahawk::query_ptr > queries; foreach ( const Tomahawk::result_ptr& result, tracks ) { result->setScore( 1.0 ); queries.append( result->toQuery() ); }
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(); emit m_resolver->artistsFound( artists ); }
void QtScriptResolverHelper::addAlbumResults( const QVariantMap& results ) { qDebug() << "Resolver reporting albums:" << results; QString artistName = results.value( "artist" ).toString(); if ( artistName.trimmed().isEmpty() ) return; Tomahawk::artist_ptr artist = Tomahawk::Artist::get( artistName, false ); QList< Tomahawk::album_ptr > albums = m_resolver->parseAlbumVariantList( artist, results.value( "albums" ).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" << albums.count() << "albums"; foreach( const Tomahawk::album_ptr& album, albums) tDebug() << album->name(); emit m_resolver->albumsFound( albums ); }
void Result::setResolvedByCollection( const Tomahawk::collection_ptr& collection , bool emitOnlineEvents ) { m_collection = collection; if ( emitOnlineEvents ) { Q_ASSERT( !collection.isNull() ); connect( collection.data(), SIGNAL( destroyed( QObject * ) ), SLOT( onOffline() ), Qt::QueuedConnection ); connect( collection.data(), SIGNAL( online() ), SLOT( onOnline() ), Qt::QueuedConnection ); connect( collection.data(), SIGNAL( offline() ), SLOT( onOffline() ), Qt::QueuedConnection ); } }