1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-05 13:47:26 +02:00

* WebResultHintChecker now uses our own NetworkReply.

This commit is contained in:
Christian Muehlhaeuser
2012-11-14 06:01:53 +01:00
parent b9191a39ee
commit 2bc2d8c0f4
2 changed files with 19 additions and 26 deletions

View File

@@ -15,22 +15,23 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>. * along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "WebResultHintChecker.h" #include "WebResultHintChecker.h"
#include <QNetworkAccessManager>
#include <QNetworkRequest>
#include <QUrl>
#include "Query.h" #include "Query.h"
#include "Result.h" #include "Result.h"
#include "Source.h" #include "Source.h"
#include "utils/Closure.h"
#include "utils/Logger.h"
#include "Pipeline.h" #include "Pipeline.h"
#include "utils/NetworkReply.h"
#include <QNetworkAccessManager> #include "utils/Logger.h"
#include <QNetworkReply>
#include <QNetworkRequest>
#include <QUrl>
using namespace Tomahawk; using namespace Tomahawk;
WebResultHintChecker::WebResultHintChecker( const query_ptr& q ) WebResultHintChecker::WebResultHintChecker( const query_ptr& q )
: QObject( 0 ) : QObject( 0 )
, m_query( q ) , m_query( q )
@@ -45,9 +46,9 @@ WebResultHintChecker::WebResultHintChecker( const query_ptr& q )
check( QUrl::fromUserInput( m_url ) ); check( QUrl::fromUserInput( m_url ) );
} }
WebResultHintChecker::~WebResultHintChecker() WebResultHintChecker::~WebResultHintChecker()
{ {
} }
@@ -62,7 +63,7 @@ WebResultHintChecker::checkQuery( const query_ptr& query )
void void
WebResultHintChecker::checkQueries( const QList< query_ptr >& queries ) WebResultHintChecker::checkQueries( const QList< query_ptr >& queries )
{ {
foreach ( const query_ptr& query, queries ) foreach ( const query_ptr& query, queries )
checkQuery( query ); checkQuery( query );
} }
@@ -89,8 +90,8 @@ WebResultHintChecker::check( const QUrl &url )
return; return;
} }
QNetworkReply* reply = TomahawkUtils::nam()->head( QNetworkRequest( url ) ); NetworkReply* reply = new NetworkReply( TomahawkUtils::nam()->head( QNetworkRequest( url ) ) );
NewClosure( reply, SIGNAL( finished() ), this, SLOT( headFinished( QNetworkReply* ) ), reply ); connect( reply, SIGNAL( finished() ), SLOT( headFinished() ) );
} }
@@ -118,19 +119,12 @@ WebResultHintChecker::removeHint()
void void
WebResultHintChecker::headFinished( QNetworkReply* reply ) WebResultHintChecker::headFinished()
{ {
reply->deleteLater(); NetworkReply* r = qobject_cast<NetworkReply*>( sender() );
r->deleteLater();
const QUrl redir = reply->attribute( QNetworkRequest::RedirectionTargetAttribute ).toUrl(); if ( r->reply()->error() != QNetworkReply::NoError )
if ( redir.isValid() )
{
const QUrl url = reply->url().resolved( redir );
check( url );
return;
}
else if ( reply->error() != QNetworkReply::NoError )
{ {
// Error getting headers for the http resulthint, remove it from the result // Error getting headers for the http resulthint, remove it from the result
// as it's definitely not playable // as it's definitely not playable

View File

@@ -22,9 +22,8 @@
#include <QObject> #include <QObject>
class QNetworkReply; namespace Tomahawk
{
namespace Tomahawk {
class WebResultHintChecker : public QObject class WebResultHintChecker : public QObject
{ {
@@ -37,7 +36,7 @@ public:
static void checkQueries( const QList< query_ptr >& queries ); static void checkQueries( const QList< query_ptr >& queries );
private slots: private slots:
void headFinished( QNetworkReply* reply ); void headFinished();
void check( const QUrl& url ); void check( const QUrl& url );