Skip to content

Commit

Permalink
Fix broken mapdownloader
Browse files Browse the repository at this point in the history
Map downloader was simply never connected to Qt.
Also, delete QNetworkReply.

Fixes #515
  • Loading branch information
duk3luk3 committed Nov 28, 2016
1 parent 494e334 commit a5de911
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions src/downloadManager/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from PyQt4.QtNetwork import QNetworkAccessManager, QNetworkRequest
from PyQt4.QtNetwork import QNetworkAccessManager, QNetworkRequest, QNetworkReply
from PyQt4 import QtGui, QtCore
import urllib2
import logging
Expand All @@ -15,18 +15,23 @@ class downloadManager(QtCore.QObject):
''' This class allows downloading stuff in the background'''

def __init__(self, parent = None):
QtCore.QObject.__init__(self, parent)
self.client = parent
self.nam = QNetworkAccessManager()
self.nam = QNetworkAccessManager(self)

self.nam.finished.connect(self.finishedDownload)

self.modRequests = {}
self.mapRequests = {}
self.mapRequestsItem = []

def finishedDownload(self,reply):
@QtCore.pyqtSlot(QNetworkReply)
def finishedDownload(self, reply):
''' finishing downloads '''
# mark reply for collection by Qt
reply.deleteLater()
urlstring = reply.url().toString()
logger.info("Finished download from " + urlstring)
reqlist = []
if urlstring in self.mapRequests: reqlist = self.mapRequests[urlstring]
if urlstring in self.modRequests: reqlist = self.modRequests[urlstring]
Expand Down Expand Up @@ -61,6 +66,18 @@ def finishedDownload(self,reply):
if urlstring in self.mapRequests: del self.mapRequests[urlstring]
if urlstring in self.modRequests: del self.modRequests[urlstring]

@QtCore.pyqtSlot(QNetworkReply.NetworkError)
def downloadError(self, networkError):
logger.info("Network Error")

@QtCore.pyqtSlot()
def readyRead(self):
logger.info("readyRead")

@QtCore.pyqtSlot(int, int)
def progress(self, rcv, total):
logger.info("received " + rcv + "out of" + total + " bytes")

def downloadMap(self, name, requester, item=False):
'''
Downloads a preview image from the web for the given map name
Expand All @@ -70,13 +87,12 @@ def downloadMap(self, name, requester, item=False):
if len(name) == 0:
return


url = QtCore.QUrl(VAULT_PREVIEW_ROOT + urllib2.quote(name) + ".png")
if not url.toString() in self.mapRequests:
logger.debug("Searching map preview for: " + name)
logger.info("Searching map preview for: " + name + " from " + url.toString())
self.mapRequests[url.toString()] = []
request = QNetworkRequest(url)
self.nam.get(request)
rpl = self.nam.get(request)
self.mapRequests[url.toString()].append(requester)
else :
self.mapRequests[url.toString()].append(requester)
Expand All @@ -89,5 +105,5 @@ def downloadModPreview(self, strurl, requester):
logger.debug("Searching mod preview for: " + os.path.basename(strurl).rsplit('.',1)[0])
self.modRequests[url.toString()] = []
request = QNetworkRequest(url)
self.nam.get(request)
rpl = self.nam.get(request)
self.modRequests[url.toString()].append(requester)

0 comments on commit a5de911

Please sign in to comment.