1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-10-05 01:52:28 +02:00

Fix closure call and handle redirects

This commit is contained in:
Leo Franchi
2012-09-20 22:13:07 -04:00
parent 12d36079f3
commit 831799ae10
6 changed files with 31 additions and 8 deletions

View File

@@ -25,6 +25,7 @@
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QNetworkRequest>
using namespace Tomahawk;
@@ -50,8 +51,7 @@ WebResultHintChecker::WebResultHintChecker( const query_ptr& q )
return;
}
QNetworkReply* reply = TomahawkUtils::nam()->head( QNetworkRequest( QUrl( m_url ) ) );
NewClosure( reply, SIGNAL( finished() ), this, SLOT( headFinished( QNetworkReply* ) ) );
check( m_url );
}
WebResultHintChecker::~WebResultHintChecker()
@@ -60,10 +60,28 @@ WebResultHintChecker::~WebResultHintChecker()
}
void
WebResultHintChecker::check( const QString &url )
{
QNetworkReply* reply = TomahawkUtils::nam()->head( QNetworkRequest( QUrl( url ) ) );
NewClosure( reply, SIGNAL( finished() ), this, SLOT( headFinished( QNetworkReply* ) ), reply );
}
void
WebResultHintChecker::headFinished( QNetworkReply* reply )
{
if ( reply->error() != QNetworkReply::NoError )
reply->deleteLater();
const QUrl redir = reply->attribute( QNetworkRequest::RedirectionTargetAttribute ).toUrl();
if ( redir.isValid() )
{
const QUrl url = reply->url().resolved( redir );
check( url.toString() );
return;
}
else if ( reply->error() != QNetworkReply::NoError )
{
// Error getting headers for the http resulthint, remove it from the result
// as it's definitely not playable
@@ -72,8 +90,8 @@ WebResultHintChecker::headFinished( QNetworkReply* reply )
m_query->removeResult( m_result );
if ( m_query->resultHint() == m_url )
m_query->setResultHint( QString() );
m_query->setSaveHTTPResultHint( false );
}
reply->deleteLater();
deleteLater();
}