Fix some crashes and issues in the Toolbox when working with no

internet connection.
This commit is contained in:
Diego Prado Gesto 2018-05-11 15:23:40 +02:00
parent 675b5b1997
commit fa97d5830b
3 changed files with 52 additions and 45 deletions

View file

@ -24,7 +24,8 @@ Item
ToolboxTabButton ToolboxTabButton
{ {
text: catalog.i18nc("@title:tab", "Plugins") text: catalog.i18nc("@title:tab", "Plugins")
active: toolbox.viewCategory == "plugin" active: toolbox.viewCategory == "plugin" && enabled
enabled: toolbox.viewPage != "loading" && toolbox.viewPage != "errored"
onClicked: onClicked:
{ {
toolbox.filterModelByProp("packages", "type", "plugin") toolbox.filterModelByProp("packages", "type", "plugin")
@ -35,7 +36,8 @@ Item
ToolboxTabButton ToolboxTabButton
{ {
text: catalog.i18nc("@title:tab", "Materials") text: catalog.i18nc("@title:tab", "Materials")
active: toolbox.viewCategory == "material" active: toolbox.viewCategory == "material" && enabled
enabled: toolbox.viewPage != "loading" && toolbox.viewPage != "errored"
onClicked: onClicked:
{ {
toolbox.filterModelByProp("authors", "package_types", "material") toolbox.filterModelByProp("authors", "package_types", "material")

View file

@ -43,7 +43,7 @@ Button
return UM.Theme.getColor("topbar_button_text_inactive"); return UM.Theme.getColor("topbar_button_text_inactive");
} }
} }
font: control.active ? UM.Theme.getFont("medium_bold") : UM.Theme.getFont("medium") font: control.enabled ? (control.active ? UM.Theme.getFont("medium_bold") : UM.Theme.getFont("medium")) : UM.Theme.getFont("default_italic")
verticalAlignment: Text.AlignVCenter verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter horizontalAlignment: Text.AlignHCenter
} }

View file

@ -333,8 +333,8 @@ class Toolbox(QObject, Extension):
# Handlers for Network Events # Handlers for Network Events
# -------------------------------------------------------------------------- # --------------------------------------------------------------------------
def _onNetworkAccessibleChanged(self, accessible: int) -> None: def _onNetworkAccessibleChanged(self, network_accessibility: QNetworkAccessManager.NetworkAccessibility) -> None:
if accessible == 0: if network_accessibility == QNetworkAccessManager.NotAccessible:
self.resetDownload() self.resetDownload()
def _onRequestFinished(self, reply: QNetworkReply) -> None: def _onRequestFinished(self, reply: QNetworkReply) -> None:
@ -354,6 +354,7 @@ class Toolbox(QObject, Extension):
if reply.operation() == QNetworkAccessManager.GetOperation: if reply.operation() == QNetworkAccessManager.GetOperation:
for type, url in self._request_urls.items(): for type, url in self._request_urls.items():
if reply.url() == url: if reply.url() == url:
if reply.attribute(QNetworkRequest.HttpStatusCodeAttribute) == 200:
try: try:
json_data = json.loads(bytes(reply.readAll()).decode("utf-8")) json_data = json.loads(bytes(reply.readAll()).decode("utf-8"))
@ -398,6 +399,10 @@ class Toolbox(QObject, Extension):
except json.decoder.JSONDecodeError: except json.decoder.JSONDecodeError:
Logger.log("w", "Toolbox: Received invalid JSON for %s.", type) Logger.log("w", "Toolbox: Received invalid JSON for %s.", type)
break break
else:
self.setViewPage("errored")
self.resetDownload()
return
else: else:
# Ignore any operation that is not a get operation # Ignore any operation that is not a get operation