40
40
mRepositories = dict of dicts: {repoName : {"url" unicode,
41
41
"enabled" bool,
42
42
"valid" bool,
43
- "QPHttp" QPHttp ,
43
+ "QPNAME" QPNetworkAccessManager ,
44
44
"Relay" Relay, # Relay object for transmitting signals from QPHttp with adding the repoName information
45
- "xmlData" QBuffer,
45
+ "Request" QNetworkRequest,
46
+ "xmlData" QNetworkReply,
46
47
"state" int, (0 - disabled, 1-loading, 2-loaded ok, 3-error (to be retried), 4-rejected)
47
48
"error" unicode}}
48
49
@@ -169,17 +170,17 @@ def removeDir(path):
169
170
170
171
171
172
172
- # --- class QPHttp ----------------------------------------------------------------------- #
173
+ # --- class QPNetworkAccessManager ----------------------------------------------------------------------- #
173
174
# --- It's a temporary workaround for broken proxy handling in Qt ------------------------- #
174
- class QPHttp ( QHttp ):
175
+ class QPNetworkAccessManager ( QNetworkAccessManager ):
175
176
def __init__ (self ,* args ):
176
- QHttp .__init__ (self ,* args )
177
+ QNetworkAccessManager .__init__ (self ,)
177
178
settings = QSettings ()
178
179
settings .beginGroup ("proxy" )
179
180
if settings .value ("/proxyEnabled" , False , type = bool ):
180
181
self .proxy = QNetworkProxy ()
181
182
proxyType = settings .value ( "/proxyType" , "0" , type = unicode )
182
- if len (args ) > 0 and args [ 0 ] in settings .value ("/proxyExcludedUrls" ,"" , type = unicode ):
183
+ if len (args )> 0 and settings .value ("/proxyExcludedUrls" ,"" , type = unicode ). contains ( args [ 0 ] ):
183
184
proxyType = "NoProxy"
184
185
if proxyType in ["1" ,"Socks5Proxy" ]: self .proxy .setType (QNetworkProxy .Socks5Proxy )
185
186
elif proxyType in ["2" ,"NoProxy" ]: self .proxy .setType (QNetworkProxy .NoProxy )
@@ -194,7 +195,7 @@ def __init__(self,*args):
194
195
self .setProxy (self .proxy )
195
196
settings .endGroup ()
196
197
return None
197
- # --- /class QPHttp ---------------------------------------------------------------------- #
198
+ # --- /class QPNetworkAccessManager ---------------------------------------------------------------------- #
198
199
199
200
200
201
@@ -216,7 +217,7 @@ def stateChanged(self, state):
216
217
# ----------------------------------------- #
217
218
def dataReadProgress (self , done , total ):
218
219
state = 4
219
- if total :
220
+ if total > 0 :
220
221
progress = int (float (done )/ float (total )* 100 )
221
222
else :
222
223
progress = 0
@@ -379,7 +380,8 @@ def load(self):
379
380
self .mRepositories [key ]["url" ] = settings .value (key + "/url" , "" , type = unicode )
380
381
self .mRepositories [key ]["enabled" ] = settings .value (key + "/enabled" , True , type = bool )
381
382
self .mRepositories [key ]["valid" ] = settings .value (key + "/valid" , True , type = bool )
382
- self .mRepositories [key ]["QPHttp" ] = QPHttp ()
383
+ self .mRepositories [key ]["QPNAM" ] = QPNetworkAccessManager ()
384
+
383
385
self .mRepositories [key ]["Relay" ] = Relay (key )
384
386
self .mRepositories [key ]["xmlData" ] = QBuffer ()
385
387
self .mRepositories [key ]["state" ] = 0
@@ -392,21 +394,18 @@ def requestFetching(self,key):
392
394
""" start fetching the repository given by key """
393
395
self .mRepositories [key ]["state" ] = 1
394
396
url = QUrl (self .mRepositories [key ]["url" ])
395
- path = url .toPercentEncoding (url .path (), "!$&'()*+,;=:@/" )
396
- path = unicode (path )
397
397
v = str (QGis .QGIS_VERSION_INT )
398
- path += "?qgis=%d.%d" % ( int (v [0 ]), int (v [1 :3 ]) )
399
- port = url .port ()
400
- if port < 0 :
401
- port = 80
402
- self .mRepositories [key ]["QPHttp" ] = QPHttp (url .host (), port )
403
- self .mRepositories [key ]["QPHttp" ].requestFinished .connect (self .xmlDownloaded )
404
- self .mRepositories [key ]["QPHttp" ].stateChanged .connect (self .mRepositories [key ]["Relay" ].stateChanged )
405
- self .mRepositories [key ]["QPHttp" ].dataReadProgress .connect (self .mRepositories [key ]["Relay" ].dataReadProgress )
406
- self .connect (self .mRepositories [key ]["Relay" ], SIGNAL ("anythingChanged(unicode, int, int)" ), self , SIGNAL ("anythingChanged (unicode, int, int)" ))
407
- i = self .mRepositories [key ]["QPHttp" ].get (path , self .mRepositories [key ]["xmlData" ])
408
- self .httpId [i ] = key
409
398
399
+
400
+ url .addQueryItem ('qgis' , '.' .join ([str (int (s )) for s in [v [0 ], v [1 :3 ], v [3 :5 ]]]) )
401
+
402
+ self .mRepositories [key ]["QRequest" ] = QNetworkRequest (url )
403
+ self .mRepositories [key ]["QRequest" ].setAttribute ( QNetworkRequest .User , key )
404
+ self .mRepositories [key ]["xmlData" ] = self .mRepositories [key ]["QPNAM" ].get ( self .mRepositories [key ]["QRequest" ] )
405
+ self .mRepositories [key ]["xmlData" ].setProperty ( 'reposName' , key )
406
+ self .mRepositories [key ]["xmlData" ].downloadProgress .connect ( self .mRepositories [key ]["Relay" ].dataReadProgress )
407
+ self .mRepositories [key ]["QPNAM" ].finished .connect ( self .xmlDownloaded )
408
+
410
409
411
410
# ----------------------------------------- #
412
411
def fetchingInProgress (self ):
@@ -420,23 +419,22 @@ def fetchingInProgress(self):
420
419
# ----------------------------------------- #
421
420
def killConnection (self , key ):
422
421
""" kill the fetching on demand """
423
- if self .mRepositories [key ]["QPHttp" ].state ():
424
- self .mRepositories [key ]["QPHttp" ].abort ()
422
+ if self .mRepositories [key ]["xmlData" ].isRunning ():
423
+ self .mRepositories [key ]["QPNAM" ].finished .disconnect ()
424
+ self .mRepositories [key ]["xmlData" ].abort ()
425
425
426
426
427
427
# ----------------------------------------- #
428
- def xmlDownloaded (self ,nr , state ):
428
+ def xmlDownloaded (self , reply ):
429
429
""" populate the plugins object with the fetched data """
430
- if not self .httpId .has_key (nr ):
431
- return
432
- reposName = self .httpId [nr ]
433
- if state : # fetching failed
430
+ reposName = reply .property ( 'reposName' )
431
+ if reply .error () != QNetworkReply .NoError : # fetching failed
434
432
self .mRepositories [reposName ]["state" ] = 3
435
- self .mRepositories [reposName ]["error" ] = self . mRepositories [ reposName ][ "QPHttp" ]. errorString ( )
433
+ self .mRepositories [reposName ]["error" ] = str ( reply . error () )
436
434
else :
437
435
repoData = self .mRepositories [reposName ]["xmlData" ]
438
436
reposXML = QDomDocument ()
439
- reposXML .setContent (repoData .data ())
437
+ reposXML .setContent (repoData .readAll ())
440
438
pluginNodes = reposXML .elementsByTagName ("pyqgis_plugin" )
441
439
if pluginNodes .size ():
442
440
for i in range (pluginNodes .size ()):
0 commit comments