DiscoverUM3Action.qml 14 KB

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