AddPrinterByIpContent.qml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  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.1 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 var discoveredPrinter: null
  20. property var isPrinterDiscovered: discoveredPrinter != null
  21. // Make sure to cancel the current request when this page closes.
  22. onVisibleChanged:
  23. {
  24. if (!visible)
  25. {
  26. CuraApplication.getDiscoveredPrintersModel().cancelCurrentManualDeviceRequest()
  27. }
  28. }
  29. Label
  30. {
  31. id: titleLabel
  32. anchors.top: parent.top
  33. anchors.horizontalCenter: parent.horizontalCenter
  34. horizontalAlignment: Text.AlignHCenter
  35. text: catalog.i18nc("@label", "Add printer by IP address")
  36. color: UM.Theme.getColor("primary_button")
  37. font: UM.Theme.getFont("huge")
  38. renderType: Text.NativeRendering
  39. }
  40. Item
  41. {
  42. anchors.top: titleLabel.bottom
  43. anchors.bottom: connectButton.top
  44. anchors.topMargin: UM.Theme.getSize("default_margin").height
  45. anchors.bottomMargin: UM.Theme.getSize("default_margin").height
  46. anchors.left: parent.left
  47. anchors.right: parent.right
  48. Item
  49. {
  50. anchors.left: parent.left
  51. anchors.right: parent.right
  52. anchors.margins: UM.Theme.getSize("default_margin").width
  53. Label
  54. {
  55. id: explainLabel
  56. height: contentHeight
  57. anchors.left: parent.left
  58. anchors.right: parent.right
  59. anchors.top: parent.top
  60. font: UM.Theme.getFont("default")
  61. color: UM.Theme.getColor("text")
  62. renderType: Text.NativeRendering
  63. text: catalog.i18nc("@label", "Enter the IP address or hostname of your printer on the network.")
  64. }
  65. Item
  66. {
  67. id: userInputFields
  68. height: childrenRect.height
  69. anchors.left: parent.left
  70. anchors.right: parent.right
  71. anchors.top: explainLabel.bottom
  72. anchors.topMargin: UM.Theme.getSize("default_margin").width
  73. Cura.TextField
  74. {
  75. id: hostnameField
  76. width: (parent.width / 2) | 0
  77. height: addPrinterButton.height
  78. anchors.verticalCenter: addPrinterButton.verticalCenter
  79. anchors.left: parent.left
  80. validator: RegExpValidator
  81. {
  82. regExp: /[a-fA-F0-9\.\:]*/
  83. }
  84. enabled: { ! (addPrinterByIpScreen.hasRequestInProgress || addPrinterByIpScreen.isPrinterDiscovered) }
  85. onAccepted: addPrinterButton.clicked()
  86. }
  87. Cura.SecondaryButton
  88. {
  89. id: addPrinterButton
  90. anchors.top: parent.top
  91. anchors.left: hostnameField.right
  92. anchors.leftMargin: UM.Theme.getSize("default_margin").width
  93. text: catalog.i18nc("@button", "Add")
  94. enabled: !addPrinterByIpScreen.hasRequestInProgress && !addPrinterByIpScreen.hasRequestFinished
  95. onClicked:
  96. {
  97. const address = hostnameField.text.trim()
  98. if (address == "")
  99. {
  100. return
  101. }
  102. // This address is already in the discovered printer model, no need to add a manual discovery.
  103. if (CuraApplication.getDiscoveredPrintersModel().discoveredPrintersByAddress[address])
  104. {
  105. addPrinterByIpScreen.discoveredPrinter = CuraApplication.getDiscoveredPrintersModel().discoveredPrintersByAddress[address]
  106. return
  107. }
  108. CuraApplication.getDiscoveredPrintersModel().checkManualDevice(address)
  109. }
  110. busy: addPrinterByIpScreen.hasRequestInProgress
  111. }
  112. }
  113. Item
  114. {
  115. width: parent.width
  116. anchors.top: userInputFields.bottom
  117. anchors.margins: UM.Theme.getSize("default_margin").width
  118. Label
  119. {
  120. id: waitResponseLabel
  121. anchors.top: parent.top
  122. anchors.margins: UM.Theme.getSize("default_margin").width
  123. font: UM.Theme.getFont("default")
  124. color: UM.Theme.getColor("text")
  125. renderType: Text.NativeRendering
  126. visible: addPrinterByIpScreen.hasRequestInProgress || (addPrinterByIpScreen.hasRequestFinished && !addPrinterByIpScreen.isPrinterDiscovered)
  127. text:
  128. {
  129. if (addPrinterByIpScreen.hasRequestFinished)
  130. {
  131. catalog.i18nc("@label", "Could not connect to device.")
  132. }
  133. else
  134. {
  135. catalog.i18nc("@label", "The printer at this address has not responded yet.")
  136. }
  137. }
  138. }
  139. Item
  140. {
  141. id: printerInfoLabels
  142. anchors.top: parent.top
  143. anchors.margins: UM.Theme.getSize("default_margin").width
  144. visible: addPrinterByIpScreen.isPrinterDiscovered
  145. Label
  146. {
  147. id: printerNameLabel
  148. anchors.top: parent.top
  149. font: UM.Theme.getFont("large")
  150. color: UM.Theme.getColor("text")
  151. renderType: Text.NativeRendering
  152. text: !addPrinterByIpScreen.isPrinterDiscovered ? "???" : addPrinterByIpScreen.discoveredPrinter.name
  153. }
  154. GridLayout
  155. {
  156. id: printerInfoGrid
  157. anchors.top: printerNameLabel.bottom
  158. anchors.margins: UM.Theme.getSize("default_margin").width
  159. columns: 2
  160. columnSpacing: UM.Theme.getSize("default_margin").width
  161. Label
  162. {
  163. text: catalog.i18nc("@label", "Type")
  164. font: UM.Theme.getFont("default")
  165. color: UM.Theme.getColor("text")
  166. renderType: Text.NativeRendering
  167. }
  168. Label
  169. {
  170. id: typeText
  171. text: !addPrinterByIpScreen.isPrinterDiscovered ? "?" : addPrinterByIpScreen.discoveredPrinter.readableMachineType
  172. font: UM.Theme.getFont("default")
  173. color: UM.Theme.getColor("text")
  174. renderType: Text.NativeRendering
  175. }
  176. Label
  177. {
  178. text: catalog.i18nc("@label", "Firmware version")
  179. font: UM.Theme.getFont("default")
  180. color: UM.Theme.getColor("text")
  181. renderType: Text.NativeRendering
  182. }
  183. Label
  184. {
  185. id: firmwareText
  186. text: !addPrinterByIpScreen.isPrinterDiscovered ? "0.0.0.0" : addPrinterByIpScreen.discoveredPrinter.device.getProperty("firmware_version")
  187. font: UM.Theme.getFont("default")
  188. color: UM.Theme.getColor("text")
  189. renderType: Text.NativeRendering
  190. }
  191. Label
  192. {
  193. text: catalog.i18nc("@label", "Address")
  194. font: UM.Theme.getFont("default")
  195. color: UM.Theme.getColor("text")
  196. renderType: Text.NativeRendering
  197. }
  198. Label
  199. {
  200. id: addressText
  201. text: !addPrinterByIpScreen.isPrinterDiscovered ? "0.0.0.0" : addPrinterByIpScreen.discoveredPrinter.address
  202. font: UM.Theme.getFont("default")
  203. color: UM.Theme.getColor("text")
  204. renderType: Text.NativeRendering
  205. }
  206. }
  207. Connections
  208. {
  209. target: CuraApplication.getDiscoveredPrintersModel()
  210. onManualDeviceRequestFinished:
  211. {
  212. var discovered_printers_model = CuraApplication.getDiscoveredPrintersModel()
  213. var printer = discovered_printers_model.discoveredPrintersByAddress[hostnameField.text]
  214. if (printer)
  215. {
  216. addPrinterByIpScreen.discoveredPrinter = printer
  217. }
  218. addPrinterByIpScreen.hasRequestFinished = true
  219. }
  220. }
  221. }
  222. }
  223. }
  224. }
  225. Cura.PrimaryButton
  226. {
  227. id: backButton
  228. anchors.left: parent.left
  229. anchors.bottom: parent.bottom
  230. text: catalog.i18nc("@button", "Back")
  231. onClicked:
  232. {
  233. CuraApplication.getDiscoveredPrintersModel().cancelCurrentManualDeviceRequest()
  234. base.showPreviousPage()
  235. }
  236. }
  237. Cura.PrimaryButton
  238. {
  239. id: connectButton
  240. anchors.right: parent.right
  241. anchors.bottom: parent.bottom
  242. text: catalog.i18nc("@button", "Connect")
  243. onClicked:
  244. {
  245. CuraApplication.getDiscoveredPrintersModel().createMachineFromDiscoveredPrinter(discoveredPrinter)
  246. base.showNextPage()
  247. }
  248. enabled: addPrinterByIpScreen.hasRequestFinished && addPrinterByIpScreen.isPrinterDiscovered
  249. }
  250. }