From: Jordan Lee Date: Fri, 25 Jan 2013 05:43:22 +0000 (+0000) Subject: (qt) #5252 'File-renaming causes QObject::startTimer error': probable fix. X-Git-Tag: 2.80~206 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1bedf94240f46da55087d0972fd5e7a02a60dd7b;p=transmission (qt) #5252 'File-renaming causes QObject::startTimer error': probable fix. --- diff --git a/qt/session.cc b/qt/session.cc index 19f996023..e9cf73dc2 100644 --- a/qt/session.cc +++ b/qt/session.cc @@ -27,7 +27,6 @@ #include #include #include -#include #include @@ -248,8 +247,7 @@ Session :: Session( const char * configDir, Prefs& prefs ): myPrefs( prefs ), mySession( 0 ), myConfigDir( QString::fromUtf8( configDir ) ), - myNAM( 0 ), - myResponseTimer (this) + myNAM( 0 ) { myStats.ratio = TR_RATIO_NA; myStats.uploadedBytes = 0; @@ -261,8 +259,8 @@ Session :: Session( const char * configDir, Prefs& prefs ): 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( ) @@ -656,16 +654,16 @@ Session :: exec( const tr_variant * request ) } 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(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" @@ -742,16 +740,9 @@ Session :: onFinished( QNetworkReply * reply ) } 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 diff --git a/qt/session.h b/qt/session.h index 15bb3c7ec..8daf3d9bb 100644 --- a/qt/session.h +++ b/qt/session.h @@ -20,7 +20,6 @@ #include #include #include -#include #include class QStringList; @@ -131,9 +130,10 @@ class Session: public QObject 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 ); @@ -159,7 +159,6 @@ class Session: public QObject struct tr_session_stats myStats; struct tr_session_stats myCumulativeStats; QString mySessionVersion; - QTimer myResponseTimer; }; #endif