mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-01 03:40:16 +02:00
Rework HttpIODeviceReadyHandler
This commit is contained in:
@@ -117,11 +117,11 @@ httpIODeviceFactory( const Tomahawk::result_ptr&, const QString& url,
|
|||||||
{
|
{
|
||||||
QNetworkRequest req( url );
|
QNetworkRequest req( url );
|
||||||
// Follow HTTP Redirects
|
// Follow HTTP Redirects
|
||||||
NetworkReply* reply = new NetworkReply( Tomahawk::Utils::nam()->get( req ) );
|
QSharedPointer< NetworkReply > reply( new NetworkReply( Tomahawk::Utils::nam()->get( req ) ) );
|
||||||
qRegisterMetaType<NetworkReply*>("NetworkReply*");
|
qRegisterMetaType<NetworkReply*>("NetworkReply*");
|
||||||
qRegisterMetaType<IODeviceCallback>("IODeviceCallback");
|
qRegisterMetaType<IODeviceCallback>("IODeviceCallback");
|
||||||
HttpIODeviceReadyHandler* handler = new HttpIODeviceReadyHandler( reply, callback );
|
HttpIODeviceReadyHandler* handler = new HttpIODeviceReadyHandler( reply, callback );
|
||||||
reply->connect( reply, SIGNAL( finalUrlReached() ),
|
reply->connect( reply.data(), SIGNAL( finalUrlReached() ),
|
||||||
handler, SLOT( called() ));
|
handler, SLOT( called() ));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -21,6 +21,7 @@
|
|||||||
|
|
||||||
#include "UrlHandler.h"
|
#include "UrlHandler.h"
|
||||||
|
|
||||||
|
#include "utils/Logger.h"
|
||||||
#include "utils/NetworkReply.h"
|
#include "utils/NetworkReply.h"
|
||||||
|
|
||||||
class HttpIODeviceReadyHandler : public QObject
|
class HttpIODeviceReadyHandler : public QObject
|
||||||
@@ -29,15 +30,12 @@ class HttpIODeviceReadyHandler : public QObject
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
NetworkReply* reply;
|
QSharedPointer<NetworkReply> reply;
|
||||||
IODeviceCallback callback;
|
IODeviceCallback callback;
|
||||||
QWeakPointer<HttpIODeviceReadyHandler> ref;
|
|
||||||
bool once;
|
|
||||||
|
|
||||||
HttpIODeviceReadyHandler( NetworkReply* _reply, IODeviceCallback _callback )
|
HttpIODeviceReadyHandler( const QSharedPointer<NetworkReply>& _reply, IODeviceCallback _callback )
|
||||||
: reply( _reply )
|
: reply( _reply )
|
||||||
, callback( _callback )
|
, callback( _callback )
|
||||||
, once( false )
|
|
||||||
{
|
{
|
||||||
// Do Nothing
|
// Do Nothing
|
||||||
}
|
}
|
||||||
@@ -46,14 +44,11 @@ public slots:
|
|||||||
|
|
||||||
void called()
|
void called()
|
||||||
{
|
{
|
||||||
// Sometimes Qt calls this function twice. Weird.
|
tLog() << Q_FUNC_INFO << reply->reply();
|
||||||
if (once) {
|
QSharedPointer< QNetworkReply > sp( reply->reply(), &QObject::deleteLater );
|
||||||
deleteLater();
|
reply->disconnectFromReply();
|
||||||
}
|
QSharedPointer< QIODevice > spIO = sp.staticCast< QIODevice>();
|
||||||
once = true;
|
callback( sp->url().toString(), spIO );
|
||||||
|
|
||||||
QSharedPointer< QIODevice > sp( reply->reply(), &QObject::deleteLater );
|
|
||||||
callback( reply->reply()->url().toString(), sp );
|
|
||||||
|
|
||||||
// Call once, then self-destruct
|
// Call once, then self-destruct
|
||||||
deleteLater();
|
deleteLater();
|
||||||
|
Reference in New Issue
Block a user