AddPrinterByIpContent.qml 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. // Copyright (c) 2019 Ultimaker B.V.
  2. // Cura is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.10
  4. import QtQuick.Controls 2.3
  5. import QtQuick.Layouts 1.3
  6. import UM 1.3 as UM
  7. import Cura 1.5 as Cura
  8. //
  9. // This component contains the content for the 'by IP' page of the "Add New Printer" flow of the on-boarding process.
  10. //
  11. Item
  12. {
  13. UM.I18nCatalog { id: catalog; name: "cura" }
  14. id: addPrinterByIpScreen
  15. // If there's a manual address resolve request in progress.
  16. property bool hasRequestInProgress: CuraApplication.getDiscoveredPrintersModel().hasManualDeviceRequestInProgress
  17. // Indicates if a request has finished.
  18. property bool hasRequestFinished: false
  19. property string currentRequestAddress: ""
  20. property var discoveredPrinter: null
  21. property bool isPrinterDiscovered: discoveredPrinter != null
  22. // A printer can only be added if it doesn't have an unknown type and it's the host of a group.
  23. property bool canAddPrinter: isPrinterDiscovered && !discoveredPrinter.isUnknownMachineType && discoveredPrinter.isHostOfGroup
  24. // For validating IP address
  25. property var networkingUtil: Cura.NetworkingUtil {}
  26. // CURA-6483
  27. // For a manually added UM printer, the UM3OutputDevicePlugin will first create a LegacyUM device for it. Later,
  28. // when it gets more info from the printer, it will first REMOVE the LegacyUM device and then add a ClusterUM device.
  29. // The Add-by-IP page needs to make sure that the user do not add an unknown printer or a printer that's not the
  30. // host of a group. Because of the device list change, this page needs to react upon DiscoveredPrintersChanged so
  31. // it has the correct information.
  32. Connections
  33. {
  34. target: CuraApplication.getDiscoveredPrintersModel()
  35. onDiscoveredPrintersChanged:
  36. {
  37. if (hasRequestFinished && currentRequestAddress)
  38. {
  39. var printer = CuraApplication.getDiscoveredPrintersModel().discoveredPrintersByAddress[currentRequestAddress]
  40. printer = printer ? printer : null
  41. discoveredPrinter = printer
  42. }
  43. }
  44. }
  45. // Make sure to cancel the current request when this page closes.
  46. onVisibleChanged:
  47. {
  48. if (!visible)
  49. {
  50. CuraApplication.getDiscoveredPrintersModel().cancelCurrentManualDeviceRequest()
  51. }
  52. }
  53. Label
  54. {
  55. id: titleLabel
  56. anchors.top: parent.top
  57. anchors.horizontalCenter: parent.horizontalCenter
  58. horizontalAlignment: Text.AlignHCenter
  59. text: catalog.i18nc("@label", "Add printer by IP address")
  60. color: UM.Theme.getColor("primary_button")
  61. font: UM.Theme.getFont("huge")
  62. renderType: Text.NativeRendering
  63. }
  64. Item
  65. {
  66. anchors.top: titleLabel.bottom
  67. anchors.bottom: connectButton.top
  68. anchors.topMargin: UM.Theme.getSize("default_margin").height
  69. anchors.bottomMargin: UM.Theme.getSize("default_margin").height
  70. anchors.left: parent.left
  71. anchors.right: parent.right
  72. Item
  73. {
  74. anchors.left: parent.left
  75. anchors.right: parent.right
  76. anchors.margins: UM.Theme.getSize("default_margin").width
  77. Label
  78. {
  79. id: explainLabel
  80. height: contentHeight
  81. anchors.left: parent.left
  82. anchors.right: parent.right
  83. anchors.top: parent.top
  84. font: UM.Theme.getFont("default")
  85. color: UM.Theme.getColor("text")
  86. renderType: Text.NativeRendering
  87. text: catalog.i18nc("@label", "Enter the IP address of your printer on the network.")
  88. }
  89. Item
  90. {
  91. id: userInputFields
  92. height: childrenRect.height
  93. anchors.left: parent.left
  94. anchors.right: parent.right
  95. anchors.top: explainLabel.bottom
  96. anchors.topMargin: UM.Theme.getSize("default_margin").width
  97. Cura.TextField
  98. {
  99. id: hostnameField
  100. width: (parent.width / 2) | 0
  101. height: addPrinterButton.height
  102. anchors.verticalCenter: addPrinterButton.verticalCenter
  103. anchors.left: parent.left
  104. signal invalidInputDetected()
  105. onInvalidInputDetected: invalidInputLabel.visible = true
  106. validator: RegExpValidator
  107. {
  108. regExp: /([a-fA-F0-9.:]+)?/
  109. }
  110. onTextEdited: invalidInputLabel.visible = false
  111. placeholderText: catalog.i18nc("@text", "Place enter your printer's IP address.")
  112. enabled: { ! (addPrinterByIpScreen.hasRequestInProgress || addPrinterByIpScreen.isPrinterDiscovered) }
  113. onAccepted: addPrinterButton.clicked()
  114. }
  115. Label
  116. {
  117. id: invalidInputLabel
  118. anchors.top: hostnameField.bottom
  119. anchors.topMargin: UM.Theme.getSize("default_margin").height
  120. anchors.left: parent.left
  121. visible: false
  122. text: catalog.i18nc("@text", "Please enter a valid IP address.")
  123. font: UM.Theme.getFont("default")
  124. color: UM.Theme.getColor("text")
  125. renderType: Text.NativeRendering
  126. }
  127. Cura.SecondaryButton
  128. {
  129. id: addPrinterButton
  130. anchors.top: parent.top
  131. anchors.left: hostnameField.right
  132. anchors.leftMargin: UM.Theme.getSize("default_margin").width
  133. text: catalog.i18nc("@button", "Add")
  134. enabled: !addPrinterByIpScreen.hasRequestInProgress && !addPrinterByIpScreen.isPrinterDiscovered && (hostnameField.state != "invalid" && hostnameField.text != "")
  135. onClicked:
  136. {
  137. const address = hostnameField.text
  138. if (!networkingUtil.isValidIP(address))
  139. {
  140. hostnameField.invalidInputDetected()
  141. return
  142. }
  143. // This address is already in the discovered printer model, no need to add a manual discovery.
  144. if (CuraApplication.getDiscoveredPrintersModel().discoveredPrintersByAddress[address])
  145. {
  146. addPrinterByIpScreen.discoveredPrinter = CuraApplication.getDiscoveredPrintersModel().discoveredPrintersByAddress[address]
  147. addPrinterByIpScreen.hasRequestFinished = true
  148. return
  149. }
  150. addPrinterByIpScreen.currentRequestAddress = address
  151. CuraApplication.getDiscoveredPrintersModel().checkManualDevice(address)
  152. }
  153. busy: addPrinterByIpScreen.hasRequestInProgress
  154. }
  155. }
  156. Item
  157. {
  158. width: parent.width
  159. anchors.top: userInputFields.bottom
  160. anchors.margins: UM.Theme.getSize("default_margin").width
  161. Label
  162. {
  163. id: waitResponseLabel
  164. anchors.top: parent.top
  165. anchors.margins: UM.Theme.getSize("default_margin").width
  166. font: UM.Theme.getFont("default")
  167. color: UM.Theme.getColor("text")
  168. renderType: Text.NativeRendering
  169. visible: addPrinterByIpScreen.hasRequestInProgress || (addPrinterByIpScreen.hasRequestFinished && !addPrinterByIpScreen.isPrinterDiscovered)
  170. text:
  171. {
  172. if (addPrinterByIpScreen.hasRequestFinished)
  173. {
  174. catalog.i18nc("@label", "Could not connect to device.")
  175. }
  176. else
  177. {
  178. catalog.i18nc("@label", "The printer at this address has not responded yet.")
  179. }
  180. }
  181. }
  182. Item
  183. {
  184. id: printerInfoLabels
  185. anchors.left: parent.left
  186. anchors.right: parent.right
  187. anchors.top: parent.top
  188. anchors.margins: UM.Theme.getSize("default_margin").width
  189. visible: addPrinterByIpScreen.isPrinterDiscovered
  190. Label
  191. {
  192. id: printerNameLabel
  193. anchors.top: parent.top
  194. font: UM.Theme.getFont("large")
  195. color: UM.Theme.getColor("text")
  196. renderType: Text.NativeRendering
  197. text: !addPrinterByIpScreen.isPrinterDiscovered ? "???" : addPrinterByIpScreen.discoveredPrinter.name
  198. }
  199. Label
  200. {
  201. id: printerCannotBeAddedLabel
  202. width: parent.width
  203. anchors.top: printerNameLabel.bottom
  204. anchors.topMargin: UM.Theme.getSize("default_margin").height
  205. text: catalog.i18nc("@label", "This printer cannot be added because it's an unknown printer or it's not the host of a group.")
  206. visible: addPrinterByIpScreen.hasRequestFinished && !addPrinterByIpScreen.canAddPrinter
  207. font: UM.Theme.getFont("default_bold")
  208. color: UM.Theme.getColor("text")
  209. renderType: Text.NativeRendering
  210. wrapMode: Text.WordWrap
  211. }
  212. GridLayout
  213. {
  214. id: printerInfoGrid
  215. anchors.top: printerCannotBeAddedLabel ? printerCannotBeAddedLabel.bottom : printerNameLabel.bottom
  216. anchors.margins: UM.Theme.getSize("default_margin").width
  217. columns: 2
  218. columnSpacing: UM.Theme.getSize("default_margin").width
  219. Label
  220. {
  221. text: catalog.i18nc("@label", "Type")
  222. font: UM.Theme.getFont("default")
  223. color: UM.Theme.getColor("text")
  224. renderType: Text.NativeRendering
  225. }
  226. Label
  227. {
  228. id: typeText
  229. text: !addPrinterByIpScreen.isPrinterDiscovered ? "?" : addPrinterByIpScreen.discoveredPrinter.readableMachineType
  230. font: UM.Theme.getFont("default")
  231. color: UM.Theme.getColor("text")
  232. renderType: Text.NativeRendering
  233. }
  234. Label
  235. {
  236. text: catalog.i18nc("@label", "Firmware version")
  237. font: UM.Theme.getFont("default")
  238. color: UM.Theme.getColor("text")
  239. renderType: Text.NativeRendering
  240. }
  241. Label
  242. {
  243. id: firmwareText
  244. text: !addPrinterByIpScreen.isPrinterDiscovered ? "0.0.0.0" : addPrinterByIpScreen.discoveredPrinter.device.getProperty("firmware_version")
  245. font: UM.Theme.getFont("default")
  246. color: UM.Theme.getColor("text")
  247. renderType: Text.NativeRendering
  248. }
  249. Label
  250. {
  251. text: catalog.i18nc("@label", "Address")
  252. font: UM.Theme.getFont("default")
  253. color: UM.Theme.getColor("text")
  254. renderType: Text.NativeRendering
  255. }
  256. Label
  257. {
  258. id: addressText
  259. text: !addPrinterByIpScreen.isPrinterDiscovered ? "0.0.0.0" : addPrinterByIpScreen.discoveredPrinter.address
  260. font: UM.Theme.getFont("default")
  261. color: UM.Theme.getColor("text")
  262. renderType: Text.NativeRendering
  263. }
  264. }
  265. Connections
  266. {
  267. target: CuraApplication.getDiscoveredPrintersModel()
  268. onManualDeviceRequestFinished:
  269. {
  270. var discovered_printers_model = CuraApplication.getDiscoveredPrintersModel()
  271. var printer = discovered_printers_model.discoveredPrintersByAddress[hostnameField.text]
  272. if (printer)
  273. {
  274. addPrinterByIpScreen.discoveredPrinter = printer
  275. }
  276. addPrinterByIpScreen.hasRequestFinished = true
  277. }
  278. }
  279. }
  280. }
  281. }
  282. }
  283. Cura.SecondaryButton
  284. {
  285. id: backButton
  286. anchors.left: parent.left
  287. anchors.bottom: parent.bottom
  288. text: catalog.i18nc("@button", "Back")
  289. onClicked:
  290. {
  291. CuraApplication.getDiscoveredPrintersModel().cancelCurrentManualDeviceRequest()
  292. base.showPreviousPage()
  293. }
  294. }
  295. Cura.PrimaryButton
  296. {
  297. id: connectButton
  298. anchors.right: parent.right
  299. anchors.bottom: parent.bottom
  300. text: catalog.i18nc("@button", "Connect")
  301. onClicked:
  302. {
  303. CuraApplication.getDiscoveredPrintersModel().createMachineFromDiscoveredPrinter(discoveredPrinter)
  304. base.showNextPage()
  305. }
  306. enabled: addPrinterByIpScreen.canAddPrinter
  307. }
  308. }