#include <QStringList>
#include <QStyle>
#include <QTextStream>
-#include <QTimer>
#include <curl/curl.h>
myPrefs( prefs ),
mySession( 0 ),
myConfigDir( QString::fromUtf8( configDir ) ),
- myNAM( 0 ),
- myResponseTimer (this)
+ myNAM( 0 )
{
myStats.ratio = TR_RATIO_NA;
myStats.uploadedBytes = 0;
connect( &myPrefs, SIGNAL(changed(int)), this, SLOT(updatePref(int)) );
- connect (&myResponseTimer, SIGNAL(timeout()), this, SLOT(onResponseTimer()));
- myResponseTimer.setSingleShot (true);
+ connect (this, SIGNAL(responseReceived(const QByteArray&)),
+ this, SLOT(onResponseReceived(const QByteArray&)));
}
Session :: ~Session( )
}
void
-Session :: localSessionCallback( tr_session * session, struct evbuffer * json, void * vself )
+Session :: localSessionCallback( tr_session * s, struct evbuffer * json, void * vself )
{
- Q_UNUSED (session);
+ Q_UNUSED (s);
Session * self = static_cast<Session*>(vself);
- self->myIdleJSON.append (QString ((const char*) evbuffer_pullup (json, -1)));
-
- if (!self->myResponseTimer.isActive())
- self->myResponseTimer.start(50);
+ /* this callback is invoked in the libtransmission thread, so we don't want
+ to process the response here... let's push it over to the Qt thread. */
+ self->responseReceived (QByteArray ((const char *)evbuffer_pullup (json, -1),
+ (int)evbuffer_get_length (json)));
}
#define REQUEST_DATA_PROPERTY_KEY "requestData"
}
void
-Session :: onResponseTimer ()
+Session :: onResponseReceived (const QByteArray& utf8)
{
- QStringList responses = myIdleJSON;
- myIdleJSON.clear();
-
- foreach (QString response, responses)
- {
- const QByteArray utf8 (response.toUtf8());
- parseResponse (utf8.constData(), utf8.length());
- }
+ parseResponse (utf8.constData(), utf8.length());
}
void
#include <QNetworkAccessManager>
#include <QString>
#include <QStringList>
-#include <QTimer>
#include <QUrl>
class QStringList;
private slots:
void onFinished( QNetworkReply * reply );
- void onResponseTimer( );
+ void onResponseReceived (const QByteArray& json);
signals:
+ void responseReceived (const QByteArray& json);
void executed( int64_t tag, const QString& result, struct tr_variant * arguments );
void sourceChanged( );
void portTested( bool isOpen );
struct tr_session_stats myStats;
struct tr_session_stats myCumulativeStats;
QString mySessionVersion;
- QTimer myResponseTimer;
};
#endif