コード例 #1
0
ファイル: AudioEngine.cpp プロジェクト: nhtua/tomahawk
void
AudioEngine::loadTrack( const Tomahawk::result_ptr& result )
{
    Q_D( AudioEngine );
    tDebug( LOGEXTRA ) << Q_FUNC_INFO << ( result.isNull() ? QString() : result->url() );

    if ( !result )
    {
        stop();
        return;
    }

    // We do this to stop the audio as soon as a user activated another track
    // If we don't block the audioOutput signals, the state change will trigger
    // loading yet another track
    d->audioOutput->blockSignals( true );
    d->audioOutput->stop();
    d->audioOutput->blockSignals( false );

    setCurrentTrack( result );

    ScriptJob* job = result->resolvedBy()->getStreamUrl( result );
    connect( job, SIGNAL( done( QVariantMap ) ), SLOT( gotStreamUrl( QVariantMap ) ) );
    job->setProperty( "result", QVariant::fromValue( result ) );
    job->start();
}
コード例 #2
0
void
ScriptCommand_AllTracks::exec()
{
    Tomahawk::ScriptCollection* collection = qobject_cast< Tomahawk::ScriptCollection* >( m_collection.data() );
    if ( collection == 0 )
    {
        reportFailure();
        return;
    }

    ScriptJob* job;
    if( m_album )
    {
        QVariantMap arguments;
        arguments[ "artist" ] = m_album->artist()->name();
        arguments[ "album" ] = m_album->name();

        job = collection->scriptObject()->invoke( "albumTracks", arguments );
    }
    else
    {
        job = collection->scriptObject()->invoke( "tracks" );
    }


    connect( job, SIGNAL( done( QVariantMap ) ), SLOT( onTracksJobDone( QVariantMap ) ), Qt::QueuedConnection );
    job->start();
}
コード例 #3
0
void
ScriptCommand_AllTracks::onTracksJobDone( const QVariantMap& result )
{
    ScriptJob* job = qobject_cast< ScriptJob* >( sender() );
    Q_ASSERT( job );

    qDebug() << "Resolver reporting album tracks:" << result;

    if ( job->error() )
    {
        reportFailure();
        return;
    }

    QSharedPointer< ScriptCollection > collection = m_collection.objectCast< ScriptCollection >();
    Q_ASSERT( !collection.isNull() );

    QList< Tomahawk::result_ptr > t = collection->scriptAccount()->parseResultVariantList( result[ "results"].toList() );


    QList< Tomahawk::query_ptr > queries;
    foreach ( const Tomahawk::result_ptr& result, t )
    {
        result->setResolvedByCollection( m_collection );
        queries.append( result->toQuery() );
    }
コード例 #4
0
void
ScriptInfoPlugin::notInCacheSlot( Tomahawk::InfoSystem::InfoStringHash criteria, Tomahawk::InfoSystem::InfoRequestData requestData )
{
    Q_D( ScriptInfoPlugin );

    QVariantMap arguments;
    arguments[ "type" ] = requestData.type;
    arguments[ "criteria" ] = convertInfoStringHashToQVariantMap( criteria );

    ScriptJob* job = m_scriptObject->invoke( "_notInCache", arguments );
    connect( job, SIGNAL( done( QVariantMap ) ), SLOT( onNotInCacheRequestDone( QVariantMap ) ) );
    d->requestDataCache[ job->id().toInt() ] = requestData;
    d->criteriaCache[ job->id().toInt() ] = criteria;

    job->start();
}
コード例 #5
0
void
ScriptInfoPlugin::getInfo( Tomahawk::InfoSystem::InfoRequestData requestData )
{
    Q_D( ScriptInfoPlugin );


    QVariantMap arguments;
    arguments[ "type" ] = requestData.type;
    arguments[ "data" ] = convertInfoStringHashToQVariantMap( requestData.input.value<Tomahawk::InfoSystem::InfoStringHash>() );

    ScriptJob* job = m_scriptObject->invoke( "_getInfo", arguments );
    connect( job, SIGNAL( done( QVariantMap ) ), SLOT( onGetInfoRequestDone( QVariantMap ) ) );

    d->requestDataCache[ job->id().toInt() ] = requestData;
    job->start();
}
コード例 #6
0
void
ScriptCommand_AllArtists::exec()
{
    Tomahawk::ScriptCollection* collection = qobject_cast< Tomahawk::ScriptCollection* >( m_collection.data() );
    Q_ASSERT( collection );

    QVariantMap arguments;
    if ( !m_filter.isEmpty() )
    {
        arguments[ "filter" ] = m_filter;
    }

    ScriptJob* job = collection->scriptObject()->invoke( "artists", arguments );
    connect( job, SIGNAL( done( QVariantMap ) ), SLOT( onArtistsJobDone( QVariantMap ) ), Qt::QueuedConnection );
    job->start();
}
コード例 #7
0
void
ScriptCommand_AllArtists::onArtistsJobDone( const QVariantMap& result )
{
    ScriptJob* job = qobject_cast< ScriptJob* >( sender() );
    Q_ASSERT( job );

    if ( job->error() )
    {
        reportFailure();
        return;
    }

    QList< Tomahawk::artist_ptr > a = parseArtistVariantList( result[ "artists" ].toList() );
    emit artists( a );
    emit done();

    job->deleteLater();
}
コード例 #8
0
void
ScriptAccount::reportScriptJobResult( const QVariantMap& result )
{
    tLog() << Q_FUNC_INFO << result;
    const QString requestId = result[ "requestId" ].toString();
    Q_ASSERT( !requestId.isEmpty() );

    ScriptJob* job = m_jobs.value( requestId );
    Q_ASSERT( job );

    // got a successful job result
    if ( result[ "error"].isNull() )
    {
        const QVariantMap data = result[ "data" ].toMap();

        job->reportResults( data );
    }
    else
    {
        job->reportFailure( result[ "error" ].toString() );
    }
}
コード例 #9
0
void
ScriptInfoPlugin::onNotInCacheRequestDone( const QVariantMap& result )
{
    Q_ASSERT( QThread::currentThread() == thread() );

    Q_D( ScriptInfoPlugin );

    ScriptJob* job = qobject_cast< ScriptJob* >( sender() );

    // retrieve requestData from cache and delete it
    Tomahawk::InfoSystem::InfoRequestData requestData = d->requestDataCache[ job->id().toInt() ];
    d->requestDataCache.remove( job->id().toInt() );

    emit info( requestData, result[ "data" ].toMap() );

    // retrieve criteria from cache and delete it
    Tomahawk::InfoSystem::InfoStringHash criteria = d->criteriaCache[ job->id().toInt() ];
    d->criteriaCache.remove( job->id().toInt() );

    emit updateCache( criteria, result[ "maxAge" ].toLongLong(), requestData.type, result[ "data" ].toMap() );

    sender()->deleteLater();
}
コード例 #10
0
void
ScriptInfoPlugin::onGetInfoRequestDone( const QVariantMap& result )
{
    Q_ASSERT( QThread::currentThread() == thread() );

    Q_D( ScriptInfoPlugin );



    ScriptJob* job = qobject_cast< ScriptJob* >( sender() );

    if ( job->error() )
    {
        emit info( d->requestDataCache[ job->id().toInt() ], QVariantMap() );
    }
    else
    {

        emit getCachedInfo( convertQVariantMapToInfoStringHash( result[ "criteria" ].toMap() ), result[ "newMaxAge" ].toLongLong(), d->requestDataCache[ job->id().toInt() ] );
    }

    d->requestDataCache.remove( job->id().toInt() );
    sender()->deleteLater();
}