Skip to content

Commit fe680ce

Browse files
committed
improve setting parsing
1 parent 1ea9051 commit fe680ce

File tree

4 files changed

+39
-19
lines changed

4 files changed

+39
-19
lines changed

DuetRRFOutputDevice.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,8 @@ def __init__(
6666
self._stage = OutputStage.ready
6767
self._name = name
6868

69-
if not url.endswith('/'):
70-
url += '/'
7169
self._url = url
70+
Logger.log("d", "URL set to: " + self._url)
7271

7372
self._duet_password = duet_password
7473
self._http_user = http_user

DuetRRFPlugin.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import re
12
import os.path
23
import json
34

@@ -97,9 +98,7 @@ def instanceHTTPPassword(self, name):
9798
def saveInstance(self, oldName, name, url, duet_password, http_user, http_password):
9899
manager = self.getOutputDeviceManager()
99100
if oldName and oldName != name:
100-
manager.removeOutputDevice(oldName)
101-
if oldName in self._instances:
102-
del self._instances[oldName]
101+
self.removeInstance(name)
103102
self._instances[name] = {
104103
"url": url,
105104
"duet_password": duet_password,
@@ -123,12 +122,26 @@ def removeInstance(self, name):
123122

124123
@pyqtSlot(str, str, result = bool)
125124
def validName(self, oldName, newName):
126-
# empty string isn't allowed
127125
if not newName:
126+
# empty string isn't allowed
128127
return False
129-
# if name hasn't changed, not a duplicate, just no rename
130128
if oldName == newName:
129+
# if name hasn't changed, not a duplicate, just no rename
131130
return True
132131

133132
# duplicates not allowed
134133
return (not newName in self._instances.keys())
134+
135+
@pyqtSlot(str, str, result = bool)
136+
def validUrl(self, oldName, newUrl):
137+
if newUrl.startswith('\\\\'):
138+
# no UNC paths
139+
return False
140+
if not re.match('^https?://.', newUrl):
141+
# missing https?://
142+
return False
143+
if '@' in newUrl:
144+
# @ is probably HTTP basic auth, which is a separate setting
145+
return False
146+
147+
return True

DuetRRFPlugin.qml

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,8 @@ UM.Dialog
1313
id: dialog;
1414

1515
title: catalog.i18nc("@title:window", "DuetRRF Servers");
16-
width: 450 * Screen.devicePixelRatio;
17-
height: 150 * Screen.devicePixelRatio;
18-
minimumWidth: 300 * Screen.devicePixelRatio;
19-
minimumHeight: 200 * Screen.devicePixelRatio;
16+
width: 650 * Screen.devicePixelRatio;
17+
height: 300 * Screen.devicePixelRatio;
2018

2119
property string currentName: (instanceList.currentIndex != -1 ? instanceList.currentItem.name : "");
2220
property int defaultVerticalMargin: UM.Theme.getSize("default_margin").height;
@@ -34,13 +32,14 @@ UM.Dialog
3432
iconName: "list-add";
3533
onClicked: {
3634
instanceDialog.oldName = "";
37-
instanceDialog.name = "DuetRRF";
38-
instanceDialog.url = "http://printer.local";
39-
instanceDialog.duet_password = "reprap";
35+
instanceDialog.name = "My Printer";
36+
instanceDialog.url = "http://192.168.1.42";
37+
instanceDialog.duet_password = "";
4038
instanceDialog.http_user = "";
4139
instanceDialog.http_password = "";
4240
instanceDialog.open();
4341
nameField.textChanged();
42+
urlField.textChanged();
4443
}
4544
}
4645
Button {
@@ -177,10 +176,11 @@ UM.Dialog
177176
property alias http_password: http_passwordField.text;
178177

179178
property bool validName: true;
179+
property bool validUrl: true;
180180
property real inputWidth: UM.Theme.getSize("standard_list_input").width * 1.5;
181181

182-
width: 210 * Screen.devicePixelRatio;
183-
height: 200 * Screen.devicePixelRatio;
182+
width: 420 * Screen.devicePixelRatio;
183+
height: 350 * Screen.devicePixelRatio;
184184

185185
onAccepted: {
186186
manager.saveInstance(oldName, nameField.text, urlField.text, duet_passwordField.text, http_userField.text, http_passwordField.text);
@@ -211,12 +211,15 @@ UM.Dialog
211211
}
212212

213213
Item { width: parent.width; height: displayNameLabel.height; }
214-
Label { text: catalog.i18nc("@label", "Server Address (url)"); }
214+
Label { text: catalog.i18nc("@label", "Server Address (URL)"); }
215215
TextField {
216216
id: urlField;
217217
text: "";
218218
implicitWidth: instanceDialog.inputWidth;
219219
maximumLength: 1024;
220+
onTextChanged: {
221+
instanceDialog.validUrl = manager.validUrl(instanceDialog.oldName, urlField.text);
222+
}
220223
}
221224

222225
Item { width: parent.width; height: displayNameLabel.height; }
@@ -251,6 +254,11 @@ UM.Dialog
251254
visible: !instanceDialog.validName;
252255
text: catalog.i18nc("@error", "That instance name already exists.");
253256
}
257+
Item { width: parent.width; height: displayNameLabel.height; }
258+
Label {
259+
visible: !instanceDialog.validUrl;
260+
text: catalog.i18nc("@error", "URL not valid. Example: http://192.168.1.42");
261+
}
254262
}
255263

256264
rightButtons: [
@@ -262,7 +270,7 @@ UM.Dialog
262270
id: okButton;
263271
text: catalog.i18nc("@action:button", "Ok");
264272
onClicked: instanceDialog.accept();
265-
enabled: instanceDialog.validName;
273+
enabled: instanceDialog.validName && instanceDialog.validUrl;
266274
isDefault: true;
267275
}
268276
]

plugin.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
"name": "DuetRRF",
33
"author": "Thomas Kriechbaumer",
44
"description": "Provides direct upload of gcode to DuetRRF.",
5-
"version": "0.0.9",
5+
"version": "0.0.10",
66
"api": 4
77
}

0 commit comments

Comments
 (0)