DiscoverUM3Action.qml 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  1. import UM 1.2 as UM
  2. import Cura 1.0 as Cura
  3. import QtQuick 2.2
  4. import QtQuick.Controls 1.1
  5. import QtQuick.Layouts 1.1
  6. import QtQuick.Window 2.1
  7. import QtQuick.Dialogs 1.2
  8. Cura.MachineAction
  9. {
  10. id: base
  11. anchors.fill: parent;
  12. property var selectedDevice: null
  13. property bool completeProperties: true
  14. Connections
  15. {
  16. target: dialog ? dialog : null
  17. ignoreUnknownSignals: true
  18. onNextClicked:
  19. {
  20. // Connect to the printer if the MachineAction is currently shown
  21. if(base.parent.wizard == dialog)
  22. {
  23. connectToPrinter();
  24. }
  25. }
  26. }
  27. function connectToPrinter()
  28. {
  29. if(base.selectedDevice && base.completeProperties)
  30. {
  31. var printerKey = base.selectedDevice.key
  32. var printerName = base.selectedDevice.name // TODO To change when the groups have a name
  33. if (manager.getStoredKey() != printerKey)
  34. {
  35. // Check if there is another instance with the same key
  36. if (!manager.existsKey(printerKey))
  37. {
  38. manager.setKey(printerKey)
  39. manager.setGroupName(printerName) // TODO To change when the groups have a name
  40. completed()
  41. }
  42. else
  43. {
  44. existingConnectionDialog.open()
  45. }
  46. }
  47. }
  48. }
  49. MessageDialog
  50. {
  51. id: existingConnectionDialog
  52. title: catalog.i18nc("@window:title", "Existing Connection")
  53. icon: StandardIcon.Information
  54. text: catalog.i18nc("@message:text", "There is an instance already connected to this group")
  55. detailedText: catalog.i18nc("@message:description", "You can't connect two instances to the same group. Please use the other instance or connect to another group.")
  56. standardButtons: StandardButton.Ok
  57. modality: Qt.ApplicationModal
  58. }
  59. Column
  60. {
  61. anchors.fill: parent;
  62. id: discoverUM3Action
  63. spacing: UM.Theme.getSize("default_margin").height
  64. SystemPalette { id: palette }
  65. UM.I18nCatalog { id: catalog; name:"cura" }
  66. Label
  67. {
  68. id: pageTitle
  69. width: parent.width
  70. text: catalog.i18nc("@title:window", "Connect to Networked Printer")
  71. wrapMode: Text.WordWrap
  72. font.pointSize: 18
  73. }
  74. Label
  75. {
  76. id: pageDescription
  77. width: parent.width
  78. wrapMode: Text.WordWrap
  79. text: catalog.i18nc("@label", "To print directly to your printer over the network, please make sure your printer is connected to the network using a network cable or by connecting your printer to your WIFI network. If you don't connect Cura with your printer, you can still use a USB drive to transfer g-code files to your printer.\n\nSelect your printer from the list below:")
  80. }
  81. Row
  82. {
  83. spacing: UM.Theme.getSize("default_lining").width
  84. Button
  85. {
  86. id: addButton
  87. text: catalog.i18nc("@action:button", "Add");
  88. onClicked:
  89. {
  90. manualPrinterDialog.showDialog("", "");
  91. }
  92. }
  93. Button
  94. {
  95. id: editButton
  96. text: catalog.i18nc("@action:button", "Edit")
  97. enabled: base.selectedDevice != null && base.selectedDevice.getProperty("manual") == "true"
  98. onClicked:
  99. {
  100. manualPrinterDialog.showDialog(base.selectedDevice.key, base.selectedDevice.ipAddress);
  101. }
  102. }
  103. Button
  104. {
  105. id: removeButton
  106. text: catalog.i18nc("@action:button", "Remove")
  107. enabled: base.selectedDevice != null && base.selectedDevice.getProperty("manual") == "true"
  108. onClicked: manager.removeManualDevice(base.selectedDevice.key, base.selectedDevice.ipAddress)
  109. }
  110. Button
  111. {
  112. id: rediscoverButton
  113. text: catalog.i18nc("@action:button", "Refresh")
  114. onClicked: manager.restartDiscovery()
  115. }
  116. }
  117. Row
  118. {
  119. id: contentRow
  120. width: parent.width
  121. spacing: UM.Theme.getSize("default_margin").width
  122. Column
  123. {
  124. width: Math.round(parent.width * 0.5)
  125. spacing: UM.Theme.getSize("default_margin").height
  126. ScrollView
  127. {
  128. id: objectListContainer
  129. frameVisible: true
  130. width: parent.width
  131. height: base.height - contentRow.y - discoveryTip.height
  132. Rectangle
  133. {
  134. parent: viewport
  135. anchors.fill: parent
  136. color: palette.light
  137. }
  138. ListView
  139. {
  140. id: listview
  141. model: manager.foundDevices
  142. onModelChanged:
  143. {
  144. var selectedKey = manager.getStoredKey();
  145. for(var i = 0; i < model.length; i++) {
  146. if(model[i].key == selectedKey)
  147. {
  148. currentIndex = i;
  149. return
  150. }
  151. }
  152. currentIndex = -1;
  153. }
  154. width: parent.width
  155. currentIndex: -1
  156. onCurrentIndexChanged:
  157. {
  158. base.selectedDevice = listview.model[currentIndex];
  159. // Only allow connecting if the printer has responded to API query since the last refresh
  160. base.completeProperties = base.selectedDevice != null && base.selectedDevice.getProperty("incomplete") != "true";
  161. }
  162. Component.onCompleted: manager.startDiscovery()
  163. delegate: Rectangle
  164. {
  165. height: childrenRect.height
  166. color: ListView.isCurrentItem ? palette.highlight : index % 2 ? palette.base : palette.alternateBase
  167. width: parent.width
  168. Label
  169. {
  170. anchors.left: parent.left
  171. anchors.leftMargin: UM.Theme.getSize("default_margin").width
  172. anchors.right: parent.right
  173. text: listview.model[index].name
  174. color: parent.ListView.isCurrentItem ? palette.highlightedText : palette.text
  175. elide: Text.ElideRight
  176. }
  177. MouseArea
  178. {
  179. anchors.fill: parent;
  180. onClicked:
  181. {
  182. if(!parent.ListView.isCurrentItem)
  183. {
  184. parent.ListView.view.currentIndex = index;
  185. }
  186. }
  187. }
  188. }
  189. }
  190. }
  191. Label
  192. {
  193. id: discoveryTip
  194. anchors.left: parent.left
  195. anchors.right: parent.right
  196. wrapMode: Text.WordWrap
  197. text: catalog.i18nc("@label", "If your printer is not listed, read the <a href='%1'>network printing troubleshooting guide</a>").arg("https://ultimaker.com/en/troubleshooting");
  198. onLinkActivated: Qt.openUrlExternally(link)
  199. }
  200. }
  201. Column
  202. {
  203. width: Math.round(parent.width * 0.5)
  204. visible: base.selectedDevice ? true : false
  205. spacing: UM.Theme.getSize("default_margin").height
  206. Label
  207. {
  208. width: parent.width
  209. wrapMode: Text.WordWrap
  210. text: base.selectedDevice ? base.selectedDevice.name : ""
  211. font: UM.Theme.getFont("large")
  212. elide: Text.ElideRight
  213. }
  214. Grid
  215. {
  216. visible: base.completeProperties
  217. width: parent.width
  218. columns: 2
  219. Label
  220. {
  221. width: Math.round(parent.width * 0.5)
  222. wrapMode: Text.WordWrap
  223. text: catalog.i18nc("@label", "Type")
  224. }
  225. Label
  226. {
  227. width: Math.round(parent.width * 0.5)
  228. wrapMode: Text.WordWrap
  229. text:
  230. {
  231. if(base.selectedDevice)
  232. {
  233. if(base.selectedDevice.printerType == "ultimaker3")
  234. {
  235. return catalog.i18nc("@label", "Ultimaker 3")
  236. } else if(base.selectedDevice.printerType == "ultimaker3_extended")
  237. {
  238. return catalog.i18nc("@label", "Ultimaker 3 Extended")
  239. } else
  240. {
  241. return catalog.i18nc("@label", "Unknown") // We have no idea what type it is. Should not happen 'in the field'
  242. }
  243. }
  244. else
  245. {
  246. return ""
  247. }
  248. }
  249. }
  250. Label
  251. {
  252. width: Math.round(parent.width * 0.5)
  253. wrapMode: Text.WordWrap
  254. text: catalog.i18nc("@label", "Firmware version")
  255. }
  256. Label
  257. {
  258. width: Math.round(parent.width * 0.5)
  259. wrapMode: Text.WordWrap
  260. text: base.selectedDevice ? base.selectedDevice.firmwareVersion : ""
  261. }
  262. Label
  263. {
  264. width: Math.round(parent.width * 0.5)
  265. wrapMode: Text.WordWrap
  266. text: catalog.i18nc("@label", "Address")
  267. }
  268. Label
  269. {
  270. width: Math.round(parent.width * 0.5)
  271. wrapMode: Text.WordWrap
  272. text: base.selectedDevice ? base.selectedDevice.ipAddress : ""
  273. }
  274. }
  275. Label
  276. {
  277. width: parent.width
  278. wrapMode: Text.WordWrap
  279. text:{
  280. // The property cluster size does not exist for older UM3 devices.
  281. if(!base.selectedDevice || base.selectedDevice.clusterSize == null || base.selectedDevice.clusterSize == 1)
  282. {
  283. return "";
  284. }
  285. else if (base.selectedDevice.clusterSize === 0)
  286. {
  287. return catalog.i18nc("@label", "This printer is not set up to host a group of Ultimaker 3 printers.");
  288. }
  289. else
  290. {
  291. return catalog.i18nc("@label", "This printer is the host for a group of %1 Ultimaker 3 printers.".arg(base.selectedDevice.clusterSize));
  292. }
  293. }
  294. }
  295. Label
  296. {
  297. width: parent.width
  298. wrapMode: Text.WordWrap
  299. visible: base.selectedDevice != null && !base.completeProperties
  300. text: catalog.i18nc("@label", "The printer at this address has not yet responded." )
  301. }
  302. Button
  303. {
  304. text: catalog.i18nc("@action:button", "Connect")
  305. enabled: (base.selectedDevice && base.completeProperties && base.selectedDevice.clusterSize > 0) ? true : false
  306. onClicked: connectToPrinter()
  307. }
  308. }
  309. }
  310. }
  311. UM.Dialog
  312. {
  313. id: manualPrinterDialog
  314. property string printerKey
  315. property alias addressText: addressField.text
  316. title: catalog.i18nc("@title:window", "Printer Address")
  317. minimumWidth: 400 * screenScaleFactor
  318. minimumHeight: 130 * screenScaleFactor
  319. width: minimumWidth
  320. height: minimumHeight
  321. signal showDialog(string key, string address)
  322. onShowDialog:
  323. {
  324. printerKey = key;
  325. addressText = address;
  326. addressField.selectAll();
  327. addressField.focus = true;
  328. manualPrinterDialog.show();
  329. }
  330. onAccepted:
  331. {
  332. manager.setManualDevice(printerKey, addressText)
  333. }
  334. Column {
  335. anchors.fill: parent
  336. spacing: UM.Theme.getSize("default_margin").height
  337. Label
  338. {
  339. text: catalog.i18nc("@alabel","Enter the IP address or hostname of your printer on the network.")
  340. width: parent.width
  341. wrapMode: Text.WordWrap
  342. }
  343. TextField
  344. {
  345. id: addressField
  346. width: parent.width
  347. maximumLength: 40
  348. validator: RegExpValidator
  349. {
  350. regExp: /[a-zA-Z0-9\.\-\_]*/
  351. }
  352. onAccepted: btnOk.clicked()
  353. }
  354. }
  355. rightButtons: [
  356. Button {
  357. text: catalog.i18nc("@action:button","Cancel")
  358. onClicked:
  359. {
  360. manualPrinterDialog.reject()
  361. manualPrinterDialog.hide()
  362. }
  363. },
  364. Button {
  365. id: btnOk
  366. text: catalog.i18nc("@action:button", "OK")
  367. onClicked:
  368. {
  369. manualPrinterDialog.accept()
  370. manualPrinterDialog.hide()
  371. }
  372. enabled: manualPrinterDialog.addressText.trim() != ""
  373. isDefault: true
  374. }
  375. ]
  376. }
  377. }