Skip to content

Commit

Permalink
Fix further incompatibilities with Qt6
Browse files Browse the repository at this point in the history
  • Loading branch information
fieldOfView committed Apr 23, 2022
1 parent 4b22abd commit a861f89
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 19 deletions.
10 changes: 7 additions & 3 deletions DiscoverOctoPrintAction.py
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ def _createAdditionalComponentsView(self) -> None:
)

def _onRequestFailed(self, reply: QNetworkReply) -> None:
if reply.operation() == QNetworkAccessManager.GetOperation:
if reply.operation() == QNetworkAccessManager.Operation.GetOperation:
if (
"api/settings" in reply.url().toString()
): # OctoPrint settings dump from /settings:
Expand Down Expand Up @@ -602,7 +602,7 @@ def _onRequestFinished(self, reply: QNetworkReply) -> None:
if not self._appkey_request:
return
self._appkey_request.setUrl(
reply.header(QNetworkRequest.LocationHeader)
reply.header(QNetworkRequest.KnownHeaders.LocationHeader)
)
self._appkey_request.setRawHeader(b"Content-Type", b"")
self._appkey_poll_timer.start()
Expand Down Expand Up @@ -730,7 +730,11 @@ def _createRequest(
self, url: str, basic_auth_username: str = "", basic_auth_password: str = ""
) -> QNetworkRequest:
request = QNetworkRequest(url)
# request.setAttribute(QNetworkRequest.FollowRedirectsAttribute, True)
try:
request.setAttribute(QNetworkRequest.FollowRedirectsAttribute, True)
except AttributeError:
# in Qt6, this is no longer possible (or required), see https://doc.qt.io/qt-6/network-changes-qt6.html#redirect-policies
pass
request.setRawHeader(b"User-Agent", self._user_agent)

if basic_auth_username and basic_auth_password:
Expand Down
6 changes: 5 additions & 1 deletion NetworkMJPGImage.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,11 @@ def start(self) -> None:
self._source_url.setAuthority(authority.rsplit("@", 1)[1])

self._image_request = QNetworkRequest(self._source_url)
self._image_request.setAttribute(QNetworkRequest.FollowRedirectsAttribute, True)
try:
self._image_request.setAttribute(QNetworkRequest.FollowRedirectsAttribute, True)
except AttributeError:
# in Qt6, this is no longer possible (or required), see https://doc.qt.io/qt-6/network-changes-qt6.html#redirect-policies
pass

if auth_data:
self._image_request.setRawHeader(
Expand Down
14 changes: 9 additions & 5 deletions OctoPrintOutputDevice.py
Original file line number Diff line number Diff line change
Expand Up @@ -1362,7 +1362,7 @@ def _onRequestFinished(self, reply: QNetworkReply) -> None:
% end_point,
)

elif reply.operation() == QNetworkAccessManager.PostOperation:
elif reply.operation() == QNetworkAccessManager.Operation.PostOperation:
if (
self._api_prefix + "files" in reply.url().toString()
): # Result from /files command to start a print job:
Expand Down Expand Up @@ -1498,7 +1498,7 @@ def _onRequestFinished(self, reply: QNetworkReply) -> None:
error_string = bytes(reply.readAll()).decode("utf-8")
if not error_string:
error_string = reply.attribute(
QNetworkRequest.HttpReasonPhraseAttribute
QNetworkRequest.Attribute.HttpReasonPhraseAttribute
)

self._showErrorMessage(error_string)
Expand Down Expand Up @@ -1566,7 +1566,7 @@ def _onUploadFinished(self, reply: QNetworkReply) -> None:
error_string = bytes(reply.readAll()).decode("utf-8")
if not error_string:
error_string = reply.attribute(
QNetworkRequest.HttpReasonPhraseAttribute
QNetworkRequest.Attribute.HttpReasonPhraseAttribute
)

if error_string:
Expand All @@ -1580,7 +1580,7 @@ def _onUploadFinished(self, reply: QNetworkReply) -> None:
Logger.log("e", error_string)
return

location_url = reply.header(QNetworkRequest.LocationHeader)
location_url = reply.header(QNetworkRequest.KnownHeaders.LocationHeader)
Logger.log(
"d", "Resource created on OctoPrint instance: %s", location_url.toString()
)
Expand Down Expand Up @@ -1780,7 +1780,11 @@ def _createEmptyRequest(
self, target: str, content_type: Optional[str] = "application/json"
) -> QNetworkRequest:
request = QNetworkRequest(QUrl(self._api_url + target))
# request.setAttribute(QNetworkRequest.FollowRedirectsAttribute, True)
try:
request.setAttribute(QNetworkRequest.FollowRedirectsAttribute, True)
except AttributeError:
# in Qt6, this is no longer possible (or required), see https://doc.qt.io/qt-6/network-changes-qt6.html#redirect-policies
pass

request.setRawHeader(b"X-Api-Key", self._api_key)
request.setRawHeader(b"User-Agent", self._user_agent.encode())
Expand Down
9 changes: 6 additions & 3 deletions qml/DiscoverOctoPrintAction.qml
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ Cura.MachineAction
Connections
{
target: base
onSelectedInstanceChanged:
function onSelectedInstanceChanged()
{
if(base.selectedInstance)
{
Expand All @@ -341,7 +341,7 @@ Cura.MachineAction
Connections
{
target: manager
onAppKeyReceived:
function onAppKeyReceived()
{
apiCheckDelay.lastKey = "\0";
apiKey.text = manager.getApiKey(base.selectedInstance.getId())
Expand Down Expand Up @@ -467,7 +467,10 @@ Cura.MachineAction
Connections
{
target: manager
onInstanceAvailablePowerPluginsChanged: autoPowerControlPlugsModel.populateModel()
function onInstanceAvailablePowerPluginsChanged()
{
autoPowerControlPlugsModel.populateModel()
}
}

Cura.ComboBox
Expand Down
4 changes: 2 additions & 2 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
import QtQuick 2.15
import QtQuick.Controls 2.0

import UM 1.5 as UM
Expand Down Expand Up @@ -33,7 +33,7 @@ UM.Dialog
property int secondColumnWidth: Math.floor(width * 0.6) - 2 * margin

signal showDialog(string name, string address, string port, string path_, bool useHttps, string userName, string password)
onShowDialog:
onShowDialog: function(name, address, port, path_, useHttps, userName, password)
{
previousName = name;
nameText = name;
Expand Down
10 changes: 5 additions & 5 deletions qml/UploadOptions.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 2.15
import QtQuick.Controls 2.0

import UM 1.5 as UM
Expand Down Expand Up @@ -45,9 +45,9 @@ UM.Dialog
maximumLength: 256
width: parent.width - Math.max(pathLabel.width, fileLabel.width) - UM.Theme.getSize("default_margin").width
horizontalAlignment: TextInput.AlignLeft
validator: RegExpValidator
validator: RegularExpressionValidator
{
regExp: /.*/
regularExpression: /.*/
}
onTextChanged: manager.filePath = text
}
Expand All @@ -64,9 +64,9 @@ UM.Dialog
maximumLength: 100
width: parent.width - Math.max(pathLabel.width, fileLabel.width) - UM.Theme.getSize("default_margin").width
horizontalAlignment: TextInput.AlignLeft
validator: RegExpValidator
validator: RegularExpressionValidator
{
regExp: /[^\/]*/
regularExpression: /[^\/]*/
}
onTextChanged: manager.fileName = text
}
Expand Down

0 comments on commit a861f89

Please sign in to comment.