Changeset 11108
- Timestamp:
- Aug 4, 2010, 1:56:51 PM (12 years ago)
- Location:
- branches/2.0x/qt
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.0x/qt/session.cc
r10868 r11108 231 231 myPrefs( prefs ), 232 232 mySession( 0 ), 233 myConfigDir( configDir ) 233 myConfigDir( configDir ), 234 myNAM( 0 ) 234 235 { 235 236 myStats.ratio = TR_RATIO_NA; … … 241 242 myCumulativeStats = myStats; 242 243 243 connect( &myNAM, SIGNAL(finished(QNetworkReply*)), this, SLOT(onFinished(QNetworkReply*)) );244 connect( &myNAM, SIGNAL(authenticationRequired(QNetworkReply*,QAuthenticator*)), this, SIGNAL(httpAuthenticationRequired()) );245 244 connect( &myPrefs, SIGNAL(changed(int)), this, SLOT(updatePref(int)) ); 246 245 } … … 249 248 { 250 249 stop( ); 250 } 251 252 QNetworkAccessManager * 253 Session :: networkAccessManager( ) 254 { 255 if( myNAM == 0 ) 256 { 257 myNAM = new QNetworkAccessManager; 258 259 connect( myNAM, SIGNAL(finished(QNetworkReply*)), 260 this, SLOT(onFinished(QNetworkReply*)) ); 261 262 connect( myNAM, SIGNAL(authenticationRequired(QNetworkReply*,QAuthenticator*)), 263 this, SIGNAL(httpAuthenticationRequired()) ); 264 } 265 266 return myNAM; 251 267 } 252 268 … … 258 274 Session :: stop( ) 259 275 { 260 foreach( Reply myReply, myReplies ) 261 myReply.networkReply->abort(); 276 if( myNAM != 0 ) 277 { 278 myNAM->deleteLater( ); 279 myNAM = 0; 280 } 281 262 282 myUrl.clear( ); 263 283 … … 281 301 if( myPrefs.get<bool>(Prefs::SESSION_IS_REMOTE) ) 282 302 { 283 const int port( myPrefs.get<int>(Prefs::SESSION_REMOTE_PORT) );284 const bool auth( myPrefs.get<bool>(Prefs::SESSION_REMOTE_AUTH) );285 const QString host( myPrefs.get<QString>(Prefs::SESSION_REMOTE_HOST) );286 const QString user( myPrefs.get<QString>(Prefs::SESSION_REMOTE_USERNAME) );287 const QString pass( myPrefs.get<QString>(Prefs::SESSION_REMOTE_PASSWORD) );288 289 303 QUrl url; 290 304 url.setScheme( "http" ); 291 url.setHost( host);292 url.setPort( port);305 url.setHost( myPrefs.get<QString>(Prefs::SESSION_REMOTE_HOST) ); 306 url.setPort( myPrefs.get<int>(Prefs::SESSION_REMOTE_PORT) ); 293 307 url.setPath( "/transmission/rpc" ); 294 if( auth ) { 295 url.setUserName( user ); 296 url.setPassword( pass ); 308 if( myPrefs.get<bool>(Prefs::SESSION_REMOTE_AUTH) ) 309 { 310 url.setUserName( myPrefs.get<QString>(Prefs::SESSION_REMOTE_USERNAME) ); 311 url.setPassword( myPrefs.get<QString>(Prefs::SESSION_REMOTE_PASSWORD) ); 297 312 } 298 313 myUrl = url; … … 584 599 } 585 600 601 #define REQUEST_DATA_PROPERTY_KEY "requestData" 602 586 603 void 587 604 Session :: exec( const char * json ) … … 600 617 request.setRawHeader( TR_RPC_SESSION_ID_HEADER, mySessionId.toAscii() ); 601 618 602 QBuffer * reqbuf = new QBuffer; 603 reqbuf->setData( QByteArray( json ) ); 604 605 QNetworkReply * reply = myNAM.post( request, reqbuf ); 619 const QByteArray requestData( json ); 620 QNetworkReply * reply = networkAccessManager()->post( request, requestData ); 621 reply->setProperty( REQUEST_DATA_PROPERTY_KEY, requestData ); 606 622 connect( reply, SIGNAL(downloadProgress(qint64,qint64)), this, SIGNAL(dataReadProgress())); 607 623 connect( reply, SIGNAL(uploadProgress(qint64,qint64)), this, SIGNAL(dataSendProgress())); 608 624 609 Reply myReply;610 myReply.networkReply = reply;611 myReply.buffer = reqbuf;612 myReplies << myReply;613 625 #ifdef DEBUG_HTTP 614 626 std::cerr << "sending " << "POST " << qPrintable( myUrl.path() ) << std::endl; … … 626 638 Session :: onFinished( QNetworkReply * reply ) 627 639 { 628 QBuffer * buffer;629 for( QList<Reply>::iterator i = myReplies.begin(); i != myReplies.end(); ++i )630 {631 if( reply == i->networkReply )632 {633 buffer = i->buffer;634 myReplies.erase( i );635 break;636 }637 }638 639 640 #ifdef DEBUG_HTTP 640 641 std::cerr << "http response header: " << std::endl; … … 653 654 // update it and resubmit the request. 654 655 mySessionId = QString( reply->rawHeader( TR_RPC_SESSION_ID_HEADER ) ); 655 exec( buffer->buffer().constData() );656 exec( reply->property( REQUEST_DATA_PROPERTY_KEY ).toByteArray( ).constData( ) ); 656 657 } 657 658 else if( reply->error() != QNetworkReply::NoError ) … … 668 669 } 669 670 670 delete buffer;671 671 reply->deleteLater(); 672 672 } -
branches/2.0x/qt/session.h
r10769 r11108 32 32 33 33 class Prefs; 34 35 struct Reply36 {37 QNetworkReply * networkReply;38 QBuffer * buffer;39 };40 typedef QList<Reply> ReplyList;41 34 42 35 class Session: public QObject … … 95 88 static void updateStats( struct tr_benc * d, struct tr_session_stats * stats ); 96 89 void refreshTorrents( const QSet<int>& torrentIds ); 90 QNetworkAccessManager * networkAccessManager( ); 97 91 98 92 public: … … 147 141 QString mySessionId; 148 142 QUrl myUrl; 149 QNetworkAccessManager myNAM; 150 ReplyList myReplies; 143 QNetworkAccessManager * myNAM; 151 144 struct tr_session_stats myStats; 152 145 struct tr_session_stats myCumulativeStats;
Note: See TracChangeset
for help on using the changeset viewer.