1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-04-21 16:31:58 +02:00

Prepare querying the script collection for a download url

This commit is contained in:
Christian Muehlhaeuser 2015-03-25 00:17:20 +01:00
parent 4bf29a3ed8
commit 837505b1b1
3 changed files with 38 additions and 4 deletions

View File

@ -19,12 +19,17 @@
#include "DownloadJob.h"
#include "Track.h"
#include "Result.h"
#include "resolvers/ScriptResolver.h"
#include "resolvers/ScriptCollection.h"
#include "resolvers/ScriptObject.h"
#include "resolvers/ScriptJob.h"
#include "TomahawkSettings.h"
#include "utils/NetworkAccessManager.h"
#include "utils/Logger.h"
DownloadJob::DownloadJob( const Tomahawk::track_ptr& track, DownloadFormat format, bool tryResuming, DownloadJob::TrackState state )
DownloadJob::DownloadJob( const Tomahawk::result_ptr& result, DownloadFormat format, bool tryResuming, DownloadJob::TrackState state )
: m_state( state )
, m_retries( 0 )
, m_tryResuming( tryResuming )
@ -35,9 +40,29 @@ DownloadJob::DownloadJob( const Tomahawk::track_ptr& track, DownloadFormat forma
, m_rcvdSize( 0 )
, m_fileSize( 0 )
, m_format( format )
, m_track( track )
, m_track( result->track() )
{
m_finished = ( state == Finished );
if (result->resolvedByCollection())
{
Tomahawk::ScriptCollection* collection = qobject_cast<Tomahawk::ScriptCollection*>( result->resolvedByCollection().data() );
if(collection)
{
QVariantMap arguments;
arguments[ "url" ] = format.url;
// HACK: *shrug* WIP.
Tomahawk::ScriptJob* job = collection->scriptObject()->invoke("getStreamUrlPromise", arguments);
connect( job, SIGNAL( done(QVariantMap) ), SLOT( onUrlRetrieved(QVariantMap) ) );
job->start();
}
}
}
void DownloadJob::onUrlRetrieved(const QVariantMap& data)
{
tLog() << Q_FUNC_INFO << data;
}

View File

@ -45,7 +45,7 @@ public:
enum TrackState
{ Waiting = 0, Running, Paused, Failed, Finished, Aborted, Any };
DownloadJob( const Tomahawk::track_ptr& track, DownloadFormat format, bool tryResuming = false, DownloadJob::TrackState state = Waiting );
DownloadJob( const Tomahawk::result_ptr& result, DownloadFormat format, bool tryResuming = false, DownloadJob::TrackState state = Waiting );
~DownloadJob();
QString toString() const;
@ -85,6 +85,9 @@ private slots:
void onDownloadProgress( qint64, qint64 );
void onDownloadFinished();
void onUrlRetrieved( const QVariantMap& data );
private:
void storeState();
QString safeEncode( const QString& filename, bool removeTrailingDots = false ) const;

View File

@ -511,6 +511,12 @@ Result::setResolvedByResolver( Tomahawk::Resolver* resolver )
}
QPointer< Resolver > Result::resolvedByResolver() const
{
return m_resolver;
}
void
Result::doneEditing()
{
@ -531,7 +537,7 @@ Result::toDownloadJob( const DownloadFormat& format )
{
if ( !m_downloadJob )
{
m_downloadJob = downloadjob_ptr( new DownloadJob( track(), format ) );
m_downloadJob = downloadjob_ptr( new DownloadJob( weakRef().toStrongRef(), format ) );
connect( m_downloadJob.data(), SIGNAL( progress( int ) ), SIGNAL( updated() ) );
}