Skip to content
Permalink
Browse files

use QgsNetworkManager in plugin installer (fixes #8137)

  • Loading branch information
jef-n committed Jun 23, 2013
1 parent 444dc23 commit 4ecf3ebd0bae19f97f32bb040c9df95967135ba8
@@ -40,7 +40,6 @@
mRepositories = dict of dicts: {repoName : {"url" unicode,
"enabled" bool,
"valid" bool,
"QPNAME" QPNetworkAccessManager,
"Relay" Relay, # Relay object for transmitting signals from QPHttp with adding the repoName information
"Request" QNetworkRequest,
"xmlData" QNetworkReply,
@@ -170,43 +169,6 @@ def removeDir(path):



# --- class QPNetworkAccessManager ----------------------------------------------------------------------- #
# --- It's a temporary workaround for broken proxy handling in Qt ------------------------- #
class QPNetworkAccessManager(QNetworkAccessManager):
def __init__(self, repoUrl):
QNetworkAccessManager.__init__(self,)
settings = QSettings()
settings.beginGroup("proxy")
if settings.value("/proxyEnabled", False, type=bool):
self.proxy=QNetworkProxy()
proxyType = settings.value( "/proxyType", "0", type=unicode)
if repoUrl:
for excludedUrl in settings.value("/proxyExcludedUrls","", type=unicode).split("|"):
if repoUrl.find( excludedUrl ) > -1:
proxyType = "NoProxy"
if proxyType in ["1","Socks5Proxy"]: self.proxy.setType(QNetworkProxy.Socks5Proxy)
elif proxyType in ["2","NoProxy"]: self.proxy.setType(QNetworkProxy.NoProxy)
elif proxyType in ["3","HttpProxy"]: self.proxy.setType(QNetworkProxy.HttpProxy)
elif proxyType in ["4","HttpCachingProxy"] and QT_VERSION >= 0X040400: self.proxy.setType(QNetworkProxy.HttpCachingProxy)
elif proxyType in ["5","FtpCachingProxy"] and QT_VERSION >= 0X040400: self.proxy.setType(QNetworkProxy.FtpCachingProxy)
else: self.proxy.setType(QNetworkProxy.DefaultProxy)
self.proxy.setHostName(settings.value("/proxyHost","", type=unicode))
try:
# QSettings may contain non-int value...
self.proxy.setPort(settings.value("/proxyPort", 0, type=int))
except:
pass
self.proxy.setUser(settings.value("/proxyUser", "", type=unicode))
self.proxy.setPassword(settings.value("/proxyPassword", "", type=unicode))
self.setProxy(self.proxy)
settings.endGroup()
return None
# --- /class QPNetworkAccessManager ---------------------------------------------------------------------- #





# --- class Relay ----------------------------------------------------------------------- #
class Relay(QObject):
""" Relay object for transmitting signals from QPHttp with adding the repoName information """
@@ -395,7 +357,6 @@ def load(self):
self.mRepositories[key]["url"] = settings.value(key+"/url", "", type=unicode)
self.mRepositories[key]["enabled"] = settings.value(key+"/enabled", True, type=bool)
self.mRepositories[key]["valid"] = settings.value(key+"/valid", True, type=bool)
self.mRepositories[key]["QPNAM"] = QPNetworkAccessManager( self.mRepositories[key]["url"] )
self.mRepositories[key]["Relay"] = Relay(key)
self.mRepositories[key]["xmlData"] = None
self.mRepositories[key]["state"] = 0
@@ -413,10 +374,10 @@ def requestFetching(self,key):

self.mRepositories[key]["QRequest"] = QNetworkRequest(url)
self.mRepositories[key]["QRequest"].setAttribute( QNetworkRequest.User, key)
self.mRepositories[key]["xmlData"] = self.mRepositories[key]["QPNAM"].get( self.mRepositories[key]["QRequest"] )
self.mRepositories[key]["xmlData"] = QgsNetworkAccessManager.instance().get( self.mRepositories[key]["QRequest"] )
self.mRepositories[key]["xmlData"].setProperty( 'reposName', key)
self.mRepositories[key]["xmlData"].downloadProgress.connect( self.mRepositories[key]["Relay"].dataReadProgress )
self.mRepositories[key]["QPNAM"].finished.connect( self.xmlDownloaded )
self.mRepositories[key]["xmlData"].finished.connect( self.xmlDownloaded )


# ----------------------------------------- #
@@ -432,21 +393,21 @@ def fetchingInProgress(self):
def killConnection(self, key):
""" kill the fetching on demand """
if self.mRepositories[key]["xmlData"] and self.mRepositories[key]["xmlData"].isRunning():
self.mRepositories[key]["QPNAM"].finished.disconnect()
self.mRepositories[key]["xmlData"].finished.disconnect()
self.mRepositories[key]["xmlData"].abort()


# ----------------------------------------- #
def xmlDownloaded(self, reply):
def xmlDownloaded(self):
""" populate the plugins object with the fetched data """
reply = self.sender()
reposName = reply.property( 'reposName' )
if reply.error() != QNetworkReply.NoError: # fetching failed
self.mRepositories[reposName]["state"] = 3
self.mRepositories[reposName]["error"] = str(reply.error())
else:
repoData = self.mRepositories[reposName]["xmlData"]
reposXML = QDomDocument()
reposXML.setContent(repoData.readAll())
reposXML.setContent(reply.readAll())
pluginNodes = reposXML.elementsByTagName("pyqgis_plugin")
if pluginNodes.size():
for i in range(pluginNodes.size()):
@@ -509,6 +470,8 @@ def xmlDownloaded(self, reply):
if not self.fetchingInProgress():
self.checkingDone.emit()

del reply


# ----------------------------------------- #
def inspectionFilter(self):
@@ -27,7 +27,7 @@
from PyQt4.QtCore import *
from PyQt4.QtGui import *

from qgis.core import QgsApplication
from qgis.core import QgsApplication, QgsNetworkAccessManager

from ui_qgsplugininstallerinstallingbase import Ui_QgsPluginInstallerInstallingDialogBase
from installer_data import *
@@ -55,13 +55,10 @@ def __init__(self, parent, plugin):
tmpPath = QDir.cleanPath(tmpDir+"/"+fileName)
self.file = QFile(tmpPath)

self.nam = QPNetworkAccessManager(url.host(), )
#self.http = QPHttp(url.host(), port)
self.request = QNetworkRequest(url)
self.reply = self.nam.get( self.request )

self.reply = QgsNetworkAccessManager.instance().get( self.request )
self.reply.downloadProgress.connect( self.readProgress )
self.nam.finished.connect(self.requestFinished)
self.reply.finished.connect(self.requestFinished)

self.stateChanged(4)

@@ -83,16 +80,19 @@ def readProgress(self, done, total):
self.progressBar.setValue(done)

# ----------------------------------------- #
def requestFinished(self, reply):
def requestFinished(self):
reply = self.sender()
self.buttonBox.setEnabled(False)
if reply.error() != QNetworkReply.NoError:
self.mResult = self.http.errorString()
self.reject()
del reply
return
self.file.open(QFile.WriteOnly)
self.file.write( reply.readAll() )
self.file.close()
self.stateChanged(0)
del reply
pluginDir = QFileInfo(QgsApplication.qgisUserDbFilePath()).path() + "/python/plugins"
tmpPath = self.file.fileName()
# make sure that the parent directory exists
@@ -120,7 +120,8 @@ def requestFinished(self, reply):
# ----------------------------------------- #
def abort(self):
if self.reply.isRunning():
self.nam.finished.disconnect()
self.reply.finished.disconnect()
self.reply.abort()
del self.reply
self.mResult = self.tr("Aborted by user")
self.reject()

0 comments on commit 4ecf3eb

Please sign in to comment.
You can’t perform that action at this time.