AddPrinterByIpContent.qml 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  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. // Whether an IP address is currently being resolved.
  16. property bool hasSentRequest: false
  17. // Whether the IP address user entered can be resolved as a recognizable printer.
  18. property bool haveConnection: false
  19. // True when a request comes back, but the device hasn't responded.
  20. property bool deviceUnresponsive: false
  21. Label
  22. {
  23. id: titleLabel
  24. anchors.top: parent.top
  25. anchors.horizontalCenter: parent.horizontalCenter
  26. horizontalAlignment: Text.AlignHCenter
  27. text: catalog.i18nc("@label", "Add printer by IP address")
  28. color: UM.Theme.getColor("primary_button")
  29. font: UM.Theme.getFont("huge")
  30. renderType: Text.NativeRendering
  31. }
  32. Item
  33. {
  34. anchors.top: titleLabel.bottom
  35. anchors.bottom: connectButton.top
  36. anchors.topMargin: UM.Theme.getSize("default_margin").height
  37. anchors.bottomMargin: UM.Theme.getSize("default_margin").height
  38. anchors.left: parent.left
  39. anchors.right: parent.right
  40. Item
  41. {
  42. anchors.left: parent.left
  43. anchors.right: parent.right
  44. anchors.margins: UM.Theme.getSize("default_margin").width
  45. Label
  46. {
  47. id: explainLabel
  48. height: contentHeight
  49. anchors.left: parent.left
  50. anchors.right: parent.right
  51. anchors.top: parent.top
  52. font: UM.Theme.getFont("default")
  53. renderType: Text.NativeRendering
  54. text: catalog.i18nc("@label", "Enter the IP address or hostname of your printer on the network.")
  55. }
  56. Item
  57. {
  58. id: userInputFields
  59. height: childrenRect.height
  60. anchors.left: parent.left
  61. anchors.right: parent.right
  62. anchors.top: explainLabel.bottom
  63. anchors.topMargin: UM.Theme.getSize("default_margin").width
  64. Cura.TextField
  65. {
  66. id: hostnameField
  67. width: (parent.width / 2) | 0
  68. height: addPrinterButton.height
  69. anchors.verticalCenter: addPrinterButton.verticalCenter
  70. anchors.left: parent.left
  71. validator: RegExpValidator
  72. {
  73. regExp: /[a-fA-F0-9\.\:]*/
  74. }
  75. enabled: { ! (addPrinterByIpScreen.hasSentRequest || addPrinterByIpScreen.haveConnection) }
  76. onAccepted: addPrinterButton.clicked()
  77. }
  78. Cura.SecondaryButton
  79. {
  80. id: addPrinterButton
  81. anchors.top: parent.top
  82. anchors.left: hostnameField.right
  83. anchors.leftMargin: UM.Theme.getSize("default_margin").width
  84. text: catalog.i18nc("@button", "Add")
  85. onClicked:
  86. {
  87. if (hostnameField.text.trim() != "")
  88. {
  89. enabled = false;
  90. addPrinterByIpScreen.deviceUnresponsive = false;
  91. UM.OutputDeviceManager.addManualDevice(hostnameField.text, hostnameField.text);
  92. }
  93. }
  94. BusyIndicator
  95. {
  96. anchors.fill: parent
  97. running:
  98. {
  99. ! parent.enabled &&
  100. ! addPrinterByIpScreen.hasSentRequest &&
  101. ! addPrinterByIpScreen.haveConnection
  102. }
  103. }
  104. Connections
  105. {
  106. target: UM.OutputDeviceManager
  107. onManualDeviceChanged: { addPrinterButton.enabled = ! UM.OutputDeviceManager.hasManualDevice }
  108. }
  109. }
  110. }
  111. Item
  112. {
  113. width: parent.width
  114. anchors.top: userInputFields.bottom
  115. anchors.margins: UM.Theme.getSize("default_margin").width
  116. Label
  117. {
  118. id: waitResponseLabel
  119. anchors.top: parent.top
  120. anchors.margins: UM.Theme.getSize("default_margin").width
  121. font: UM.Theme.getFont("default")
  122. renderType: Text.NativeRendering
  123. visible:
  124. {
  125. (addPrinterByIpScreen.hasSentRequest && ! addPrinterByIpScreen.haveConnection)
  126. || addPrinterByIpScreen.deviceUnresponsive
  127. }
  128. text:
  129. {
  130. if (addPrinterByIpScreen.deviceUnresponsive)
  131. {
  132. catalog.i18nc("@label", "Could not connect to device.")
  133. }
  134. else
  135. {
  136. catalog.i18nc("@label", "The printer at this address has not responded yet.")
  137. }
  138. }
  139. }
  140. Item
  141. {
  142. id: printerInfoLabels
  143. anchors.top: parent.top
  144. anchors.margins: UM.Theme.getSize("default_margin").width
  145. visible: addPrinterByIpScreen.haveConnection && ! addPrinterByIpScreen.deviceUnresponsive
  146. Label
  147. {
  148. id: printerNameLabel
  149. anchors.top: parent.top
  150. font: UM.Theme.getFont("large")
  151. renderType: Text.NativeRendering
  152. text: "???"
  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 { font: UM.Theme.getFont("default"); text: catalog.i18nc("@label", "Type"); renderType: Text.NativeRendering }
  162. Label { id: typeText; font: UM.Theme.getFont("default"); text: "?"; renderType: Text.NativeRendering }
  163. Label { font: UM.Theme.getFont("default"); text: catalog.i18nc("@label", "Firmware version"); renderType: Text.NativeRendering }
  164. Label { id: firmwareText; font: UM.Theme.getFont("default"); text: "0.0.0.0"; renderType: Text.NativeRendering }
  165. Label { font: UM.Theme.getFont("default"); text: catalog.i18nc("@label", "Address"); renderType: Text.NativeRendering }
  166. Label { id: addressText; font: UM.Theme.getFont("default"); text: "0.0.0.0"; renderType: Text.NativeRendering }
  167. Connections
  168. {
  169. target: UM.OutputDeviceManager
  170. onManualDeviceChanged:
  171. {
  172. if (UM.OutputDeviceManager.hasManualDevice)
  173. {
  174. const type_id = UM.OutputDeviceManager.manualDeviceProperty("printer_type")
  175. var readable_type = Cura.MachineManager.getMachineTypeNameFromId(type_id)
  176. readable_type = (readable_type != "") ? readable_type : catalog.i18nc("@label", "Unknown")
  177. typeText.text = readable_type
  178. firmwareText.text = UM.OutputDeviceManager.manualDeviceProperty("firmware_version")
  179. addressText.text = UM.OutputDeviceManager.manualDeviceProperty("address")
  180. }
  181. else
  182. {
  183. typeText.text = ""
  184. firmwareText.text = ""
  185. addressText.text = ""
  186. }
  187. }
  188. }
  189. }
  190. Connections
  191. {
  192. target: UM.OutputDeviceManager
  193. onManualDeviceChanged:
  194. {
  195. if (UM.OutputDeviceManager.hasManualDevice)
  196. {
  197. printerNameLabel.text = UM.OutputDeviceManager.manualDeviceProperty("name")
  198. addPrinterByIpScreen.haveConnection = true
  199. }
  200. else
  201. {
  202. addPrinterByIpScreen.hasSentRequest = false
  203. addPrinterByIpScreen.haveConnection = false
  204. addPrinterByIpScreen.deviceUnresponsive = true
  205. }
  206. }
  207. }
  208. }
  209. }
  210. }
  211. }
  212. Cura.PrimaryButton
  213. {
  214. id: backButton
  215. anchors.left: parent.left
  216. anchors.bottom: parent.bottom
  217. text: catalog.i18nc("@button", "Back")
  218. onClicked: base.showPreviousPage()
  219. }
  220. Cura.PrimaryButton
  221. {
  222. id: connectButton
  223. anchors.right: parent.right
  224. anchors.bottom: parent.bottom
  225. text: catalog.i18nc("@button", "Connect")
  226. onClicked:
  227. {
  228. CuraApplication.getDiscoveredPrintersModel().createMachineFromDiscoveredPrinterAddress(
  229. UM.OutputDeviceManager.manualDeviceProperty("address"))
  230. UM.OutputDeviceManager.setActiveDevice(UM.OutputDeviceManager.manualDeviceProperty("device_id"))
  231. base.showNextPage()
  232. }
  233. enabled: addPrinterByIpScreen.haveConnection
  234. }
  235. }