AddPrinterByIpContent.qml 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  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", "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. addPrinterByIpScreen.hasRequestFinished = false //In case it's pressed multiple times.
  138. const address = hostnameField.text
  139. if (!networkingUtil.isValidIP(address))
  140. {
  141. hostnameField.invalidInputDetected()
  142. return
  143. }
  144. // This address is already in the discovered printer model, no need to add a manual discovery.
  145. if (CuraApplication.getDiscoveredPrintersModel().discoveredPrintersByAddress[address])
  146. {
  147. addPrinterByIpScreen.discoveredPrinter = CuraApplication.getDiscoveredPrintersModel().discoveredPrintersByAddress[address]
  148. addPrinterByIpScreen.hasRequestFinished = true
  149. return
  150. }
  151. addPrinterByIpScreen.currentRequestAddress = address
  152. CuraApplication.getDiscoveredPrintersModel().checkManualDevice(address)
  153. }
  154. busy: addPrinterByIpScreen.hasRequestInProgress
  155. }
  156. }
  157. Item
  158. {
  159. width: parent.width
  160. anchors.top: userInputFields.bottom
  161. anchors.margins: UM.Theme.getSize("default_margin").width
  162. Label
  163. {
  164. id: waitResponseLabel
  165. anchors.top: parent.top
  166. anchors.margins: UM.Theme.getSize("default_margin").width
  167. font: UM.Theme.getFont("default")
  168. color: UM.Theme.getColor("text")
  169. renderType: Text.NativeRendering
  170. visible: addPrinterByIpScreen.hasRequestInProgress || (addPrinterByIpScreen.hasRequestFinished && !addPrinterByIpScreen.isPrinterDiscovered)
  171. textFormat: Text.RichText
  172. text:
  173. {
  174. if (addPrinterByIpScreen.hasRequestFinished)
  175. {
  176. return catalog.i18nc("@label", "Could not connect to device.") + "<br /><br /><a href=\"https://ultimaker.com/en/resources/52891-set-up-a-cloud-connection\">"
  177. + catalog.i18nc("@label", "Can't connect to your Ultimaker printer?") + "</a>";
  178. }
  179. else
  180. {
  181. return catalog.i18nc("@label", "The printer at this address has not responded yet.") + "<br /><br /><a href=\"https://ultimaker.com/en/resources/52891-set-up-a-cloud-connection\">"
  182. + catalog.i18nc("@label", "Can't connect to your Ultimaker printer?") + "</a>";
  183. }
  184. }
  185. onLinkActivated: Qt.openUrlExternally(link)
  186. }
  187. Item
  188. {
  189. id: printerInfoLabels
  190. anchors.left: parent.left
  191. anchors.right: parent.right
  192. anchors.top: parent.top
  193. anchors.margins: UM.Theme.getSize("default_margin").width
  194. visible: addPrinterByIpScreen.isPrinterDiscovered
  195. Label
  196. {
  197. id: printerNameLabel
  198. anchors.top: parent.top
  199. font: UM.Theme.getFont("large")
  200. color: UM.Theme.getColor("text")
  201. renderType: Text.NativeRendering
  202. text: !addPrinterByIpScreen.isPrinterDiscovered ? "???" : addPrinterByIpScreen.discoveredPrinter.name
  203. }
  204. Label
  205. {
  206. id: printerCannotBeAddedLabel
  207. width: parent.width
  208. anchors.top: printerNameLabel.bottom
  209. anchors.topMargin: UM.Theme.getSize("default_margin").height
  210. text: catalog.i18nc("@label", "This printer cannot be added because it's an unknown printer or it's not the host of a group.")
  211. visible: addPrinterByIpScreen.hasRequestFinished && !addPrinterByIpScreen.canAddPrinter
  212. font: UM.Theme.getFont("default_bold")
  213. color: UM.Theme.getColor("text")
  214. renderType: Text.NativeRendering
  215. wrapMode: Text.WordWrap
  216. }
  217. GridLayout
  218. {
  219. id: printerInfoGrid
  220. anchors.top: printerCannotBeAddedLabel ? printerCannotBeAddedLabel.bottom : printerNameLabel.bottom
  221. anchors.margins: UM.Theme.getSize("default_margin").width
  222. columns: 2
  223. columnSpacing: UM.Theme.getSize("default_margin").width
  224. Label
  225. {
  226. text: catalog.i18nc("@label", "Type")
  227. font: UM.Theme.getFont("default")
  228. color: UM.Theme.getColor("text")
  229. renderType: Text.NativeRendering
  230. }
  231. Label
  232. {
  233. id: typeText
  234. text: !addPrinterByIpScreen.isPrinterDiscovered ? "?" : addPrinterByIpScreen.discoveredPrinter.readableMachineType
  235. font: UM.Theme.getFont("default")
  236. color: UM.Theme.getColor("text")
  237. renderType: Text.NativeRendering
  238. }
  239. Label
  240. {
  241. text: catalog.i18nc("@label", "Firmware version")
  242. font: UM.Theme.getFont("default")
  243. color: UM.Theme.getColor("text")
  244. renderType: Text.NativeRendering
  245. }
  246. Label
  247. {
  248. id: firmwareText
  249. text: !addPrinterByIpScreen.isPrinterDiscovered ? "0.0.0.0" : addPrinterByIpScreen.discoveredPrinter.device.getProperty("firmware_version")
  250. font: UM.Theme.getFont("default")
  251. color: UM.Theme.getColor("text")
  252. renderType: Text.NativeRendering
  253. }
  254. Label
  255. {
  256. text: catalog.i18nc("@label", "Address")
  257. font: UM.Theme.getFont("default")
  258. color: UM.Theme.getColor("text")
  259. renderType: Text.NativeRendering
  260. }
  261. Label
  262. {
  263. id: addressText
  264. text: !addPrinterByIpScreen.isPrinterDiscovered ? "0.0.0.0" : addPrinterByIpScreen.discoveredPrinter.address
  265. font: UM.Theme.getFont("default")
  266. color: UM.Theme.getColor("text")
  267. renderType: Text.NativeRendering
  268. }
  269. }
  270. Connections
  271. {
  272. target: CuraApplication.getDiscoveredPrintersModel()
  273. onManualDeviceRequestFinished:
  274. {
  275. var discovered_printers_model = CuraApplication.getDiscoveredPrintersModel()
  276. var printer = discovered_printers_model.discoveredPrintersByAddress[hostnameField.text]
  277. if (printer)
  278. {
  279. addPrinterByIpScreen.discoveredPrinter = printer
  280. }
  281. addPrinterByIpScreen.hasRequestFinished = true
  282. }
  283. }
  284. }
  285. }
  286. }
  287. }
  288. Cura.SecondaryButton
  289. {
  290. id: backButton
  291. anchors.left: parent.left
  292. anchors.bottom: parent.bottom
  293. text: catalog.i18nc("@button", "Back")
  294. onClicked:
  295. {
  296. CuraApplication.getDiscoveredPrintersModel().cancelCurrentManualDeviceRequest()
  297. base.showPreviousPage()
  298. }
  299. }
  300. Cura.PrimaryButton
  301. {
  302. id: connectButton
  303. anchors.right: parent.right
  304. anchors.bottom: parent.bottom
  305. text: catalog.i18nc("@button", "Connect")
  306. onClicked:
  307. {
  308. CuraApplication.getDiscoveredPrintersModel().createMachineFromDiscoveredPrinter(discoveredPrinter)
  309. base.showNextPage()
  310. }
  311. enabled: addPrinterByIpScreen.canAddPrinter
  312. }
  313. }