Skip loading a reply if it's not later handled.

Contributes to CURA-5670.
This commit is contained in:
Diego Prado Gesto 2018-09-03 14:30:05 +02:00
parent 988b9059b9
commit bf1d3b964f
3 changed files with 18 additions and 16 deletions

View file

@ -9,7 +9,7 @@ import UM 1.1 as UM
Item
{
property int packageCount: (toolbox.viewCategory == "material" && model.type === undefined) ? toolbox.getTotalNumberOfPackagesByAuthor(model.id) : 1
property int packageCount: (toolbox.viewCategory == "material" && model.type === undefined) ? toolbox.getTotalNumberOfMaterialPackagesByAuthor(model.id) : 1
property int installedPackages: (toolbox.viewCategory == "material" && model.type === undefined) ? toolbox.getNumberOfInstalledPackagesByAuthor(model.id) : (toolbox.isInstalled(model.id) ? 1 : 0)
height: childrenRect.height
Layout.alignment: Qt.AlignTop | Qt.AlignLeft

View file

@ -9,7 +9,7 @@ import UM 1.1 as UM
Rectangle
{
property int packageCount: toolbox.viewCategory == "material" ? toolbox.getTotalNumberOfPackagesByAuthor(model.id) : 1
property int packageCount: toolbox.viewCategory == "material" ? toolbox.getTotalNumberOfMaterialPackagesByAuthor(model.id) : 1
property int installedPackages: toolbox.viewCategory == "material" ? toolbox.getNumberOfInstalledPackagesByAuthor(model.id) : (toolbox.isInstalled(model.id) ? 1 : 0)
id: tileBase
width: UM.Theme.getSize("toolbox_thumbnail_large").width + (2 * UM.Theme.getSize("default_lining").width)

View file

@ -514,10 +514,11 @@ class Toolbox(QObject, Extension):
count += 1
return count
# This slot is only used to get the number of material packages by author, not any other type of packages.
@pyqtSlot(str, result = int)
def getTotalNumberOfPackagesByAuthor(self, author_id: str) -> int:
def getTotalNumberOfMaterialPackagesByAuthor(self, author_id: str) -> int:
count = 0
for package in self._metadata["packages"]:
for package in self._metadata["materials_available"]:
if package["author"]["author_id"] == author_id:
count += 1
return count
@ -606,8 +607,21 @@ class Toolbox(QObject, Extension):
self.resetDownload()
return
# HACK: These request are not handled independently at this moment, but together from the "packages" call
do_not_handle = [
"materials_available",
"materials_showcase",
"plugins_available",
"plugins_showcase",
]
if reply.operation() == QNetworkAccessManager.GetOperation:
for type, url in self._request_urls.items():
# HACK: Do nothing because we'll handle these from the "packages" call
if type in do_not_handle:
return
if reply.url() == url:
if reply.attribute(QNetworkRequest.HttpStatusCodeAttribute) == 200:
try:
@ -624,18 +638,6 @@ class Toolbox(QObject, Extension):
Logger.log("e", "Could not find the %s model.", type)
break
# HACK
do_not_handle = [
"materials_available",
"materials_showcase",
"plugins_available",
"plugins_showcase",
]
# Do nothing because we'll handle these from the "packages" call
if type in do_not_handle:
return
self._metadata[type] = json_data["data"]
self._models[type].setMetadata(self._metadata[type])