Skip to content

Commit

Permalink
Improved compatability with Cura 5.
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-ivering committed Apr 22, 2022
1 parent c0bd7a3 commit bc61d3e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 24 deletions.
10 changes: 5 additions & 5 deletions DiscoverOctoPrintAction.py
Original file line number Diff line number Diff line change
Expand Up @@ -562,15 +562,15 @@ def _onRequestFailed(self, reply: QNetworkReply) -> None:
## Handler for all requests that have finished.
def _onRequestFinished(self, reply: QNetworkReply) -> None:

http_status_code = reply.attribute(QNetworkRequest.HttpStatusCodeAttribute)
http_status_code = reply.attribute(QNetworkRequest.Attribute.HttpStatusCodeAttribute)
if not http_status_code:
# Received no or empty reply
self._onRequestFailed(reply)
return

json_data = None

if reply.operation() == QNetworkAccessManager.PostOperation:
if reply.operation() == QNetworkAccessManager.Operation.PostOperation:
if (
"/plugin/appkeys/request" in reply.url().toString()
): # Initial AppKey request
Expand Down Expand Up @@ -620,7 +620,7 @@ def _onRequestFinished(self, reply: QNetworkReply) -> None:
)
self._appkey_request = None # type: Optional[QNetworkRequest]

if reply.operation() == QNetworkAccessManager.GetOperation:
if reply.operation() == QNetworkAccessManager.Operation.GetOperation:
if (
"/plugin/appkeys/probe" in reply.url().toString()
): # Probe for AppKey support
Expand Down Expand Up @@ -730,7 +730,7 @@ def _createRequest(
self, url: str, basic_auth_username: str = "", basic_auth_password: str = ""
) -> QNetworkRequest:
request = QNetworkRequest(url)
request.setAttribute(QNetworkRequest.FollowRedirectsAttribute, True)
# request.setAttribute(QNetworkRequest.FollowRedirectsAttribute, True)
request.setRawHeader(b"User-Agent", self._user_agent)

if basic_auth_username and basic_auth_password:
Expand All @@ -741,7 +741,7 @@ def _createRequest(

# ignore SSL errors (eg for self-signed certificates)
ssl_configuration = QSslConfiguration.defaultConfiguration()
ssl_configuration.setPeerVerifyMode(QSslSocket.VerifyNone)
ssl_configuration.setPeerVerifyMode(QSslSocket.PeerVerifyMode.VerifyNone)
request.setSslConfiguration(ssl_configuration)

return request
Expand Down
20 changes: 10 additions & 10 deletions OctoPrintOutputDevice.py
Original file line number Diff line number Diff line change
Expand Up @@ -913,15 +913,15 @@ def _sendCommandToApi(

## Handler for all requests that have finished.
def _onRequestFinished(self, reply: QNetworkReply) -> None:
if reply.error() == QNetworkReply.TimeoutError:
if reply.error() == QNetworkReply.NetworkError.TimeoutError:
Logger.log("w", "Received a timeout on a request to the instance")
self._connection_state_before_timeout = self._connection_state
self.setConnectionState(cast(ConnectionState, UnifiedConnectionState.Error))
return

if (
self._connection_state_before_timeout
and reply.error() == QNetworkReply.NoError
and reply.error() == QNetworkReply.NetworkError.NoError
):
# There was a timeout, but we got a correct answer again.
if self._last_response_time:
Expand All @@ -933,15 +933,15 @@ def _onRequestFinished(self, reply: QNetworkReply) -> None:
self.setConnectionState(self._connection_state_before_timeout)
self._connection_state_before_timeout = None

if reply.error() == QNetworkReply.NoError:
if reply.error() == QNetworkReply.NetworkError.NoError:
self._last_response_time = time()

http_status_code = reply.attribute(QNetworkRequest.HttpStatusCodeAttribute)
http_status_code = reply.attribute(QNetworkRequest.Attribute.HttpStatusCodeAttribute)
if not http_status_code:
# Received no or empty reply
return

if reply.operation() == QNetworkAccessManager.GetOperation:
if reply.operation() == QNetworkAccessManager.Operation.GetOperation:
if self._api_prefix + "printerprofiles" in reply.url().toString():
if http_status_code == 200:
try:
Expand Down Expand Up @@ -1780,17 +1780,17 @@ def _createEmptyRequest(
self, target: str, content_type: Optional[str] = "application/json"
) -> QNetworkRequest:
request = QNetworkRequest(QUrl(self._api_url + target))
request.setAttribute(QNetworkRequest.FollowRedirectsAttribute, True)
# request.setAttribute(QNetworkRequest.FollowRedirectsAttribute, True)

request.setRawHeader(b"X-Api-Key", self._api_key)
request.setRawHeader(b"User-Agent", self._user_agent.encode())

if content_type is not None:
request.setHeader(QNetworkRequest.ContentTypeHeader, content_type)
request.setHeader(QNetworkRequest.KnownHeaders.ContentTypeHeader, content_type)

# ignore SSL errors (eg for self-signed certificates)
ssl_configuration = QSslConfiguration.defaultConfiguration()
ssl_configuration.setPeerVerifyMode(QSslSocket.VerifyNone)
ssl_configuration.setPeerVerifyMode(QSslSocket.PeerVerifyMode.VerifyNone)
request.setSslConfiguration(ssl_configuration)

if self._basic_auth_data:
Expand All @@ -1806,9 +1806,9 @@ def _createFormPart(

if not content_header.startswith("form-data;"):
content_header = "form-data; " + content_header
part.setHeader(QNetworkRequest.ContentDispositionHeader, content_header)
part.setHeader(QNetworkRequest.KnownHeaders.ContentDispositionHeader, content_header)
if content_type is not None:
part.setHeader(QNetworkRequest.ContentTypeHeader, content_type)
part.setHeader(QNetworkRequest.KnownHeaders.ContentTypeHeader, content_type)

part.setBody(data)
return part
Expand Down
18 changes: 9 additions & 9 deletions qml/ManualInstanceDialog.qml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) 2022 Aldo Hoeben / fieldOfView
// OctoPrintPlugin is released under the terms of the AGPLv3 or higher.

import QtQuick 2.1
import QtQuick
import QtQuick.Controls 2.0

import UM 1.5 as UM
Expand Down Expand Up @@ -172,9 +172,9 @@ UM.Dialog
id: nameField
maximumLength: 20
width: manualInstanceDialog.secondColumnWidth
validator: RegExpValidator
validator: RegularExpressionValidator
{
regExp: /[a-zA-Z0-9\.\-\_\:\[\]]*/
regularExpression: /[a-zA-Z0-9\.\-\_\:\[\]]*/
}
}

Expand All @@ -189,9 +189,9 @@ UM.Dialog
id: addressField
maximumLength: 253
width: manualInstanceDialog.secondColumnWidth
validator: RegExpValidator
validator: RegularExpressionValidator
{
regExp: /[a-zA-Z0-9\.\-\_\:\/\@]*/
regularExpression: /[a-zA-Z0-9\.\-\_\:\/\@]*/
}
onTextChanged: parseAddressFieldTimer.restart()
}
Expand All @@ -207,9 +207,9 @@ UM.Dialog
id: portField
maximumLength: 5
width: manualInstanceDialog.secondColumnWidth
validator: RegExpValidator
validator: RegularExpressionValidator
{
regExp: /[0-9]*/
regularExpression: /[0-9]*/
}
onTextChanged:
{
Expand All @@ -235,9 +235,9 @@ UM.Dialog
id: pathField
maximumLength: 30
width: manualInstanceDialog.secondColumnWidth
validator: RegExpValidator
validator: RegularExpressionValidator
{
regExp: /[a-zA-Z0-9\.\-\_\/]*/
regularExpression: /[a-zA-Z0-9\.\-\_\/]*/
}
}

Expand Down

0 comments on commit bc61d3e

Please sign in to comment.