AddPrinterByIpContent.qml 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  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. width: parent.width
  43. Label
  44. {
  45. id: explainLabel
  46. height: contentHeight
  47. width: parent.width
  48. anchors.top: parent.top
  49. anchors.margins: UM.Theme.getSize("default_margin").width
  50. font: UM.Theme.getFont("default")
  51. text: catalog.i18nc("@label", "Enter the IP address or hostname of your printer on the network.")
  52. }
  53. Item
  54. {
  55. id: userInputFields
  56. height: childrenRect.height
  57. width: parent.width
  58. anchors.top: explainLabel.bottom
  59. TextField
  60. {
  61. id: hostnameField
  62. anchors.verticalCenter: addPrinterButton.verticalCenter
  63. anchors.left: parent.left
  64. height: addPrinterButton.height
  65. anchors.right: addPrinterButton.left
  66. anchors.margins: UM.Theme.getSize("default_margin").width
  67. font: UM.Theme.getFont("default")
  68. selectByMouse: true
  69. validator: RegExpValidator
  70. {
  71. regExp: /[a-fA-F0-9\.\:]*/
  72. }
  73. enabled: { ! (addPrinterByIpScreen.hasSentRequest || addPrinterByIpScreen.haveConnection) }
  74. onAccepted: addPrinterButton.clicked()
  75. }
  76. Cura.PrimaryButton
  77. {
  78. id: addPrinterButton
  79. anchors.top: parent.top
  80. anchors.right: parent.right
  81. anchors.margins: UM.Theme.getSize("default_margin").width
  82. text: catalog.i18nc("@button", "Add")
  83. onClicked:
  84. {
  85. if (hostnameField.text.trim() != "")
  86. {
  87. enabled = false;
  88. addPrinterByIpScreen.deviceUnresponsive = false;
  89. UM.OutputDeviceManager.addManualDevice(hostnameField.text, hostnameField.text);
  90. }
  91. }
  92. BusyIndicator
  93. {
  94. anchors.fill: parent
  95. running:
  96. {
  97. ! parent.enabled &&
  98. ! addPrinterByIpScreen.hasSentRequest &&
  99. ! addPrinterByIpScreen.haveConnection
  100. }
  101. }
  102. Connections
  103. {
  104. target: UM.OutputDeviceManager
  105. onManualDeviceChanged: { addPrinterButton.enabled = ! UM.OutputDeviceManager.hasManualDevice }
  106. }
  107. }
  108. }
  109. Item
  110. {
  111. width: parent.width
  112. anchors.top: userInputFields.bottom
  113. anchors.margins: UM.Theme.getSize("default_margin").width
  114. Label
  115. {
  116. id: waitResponseLabel
  117. anchors.top: parent.top
  118. anchors.margins: UM.Theme.getSize("default_margin").width
  119. font: UM.Theme.getFont("default")
  120. visible:
  121. {
  122. (addPrinterByIpScreen.hasSentRequest && ! addPrinterByIpScreen.haveConnection)
  123. || addPrinterByIpScreen.deviceUnresponsive
  124. }
  125. text:
  126. {
  127. if (addPrinterByIpScreen.deviceUnresponsive)
  128. {
  129. catalog.i18nc("@label", "Could not connect to device.")
  130. }
  131. else
  132. {
  133. catalog.i18nc("@label", "The printer at this address has not responded yet.")
  134. }
  135. }
  136. }
  137. Item
  138. {
  139. id: printerInfoLabels
  140. anchors.top: parent.top
  141. anchors.margins: UM.Theme.getSize("default_margin").width
  142. visible: addPrinterByIpScreen.haveConnection && ! addPrinterByIpScreen.deviceUnresponsive
  143. Label
  144. {
  145. id: printerNameLabel
  146. anchors.top: parent.top
  147. font: UM.Theme.getFont("large")
  148. text: "???"
  149. }
  150. GridLayout
  151. {
  152. id: printerInfoGrid
  153. anchors.top: printerNameLabel.bottom
  154. anchors.margins: UM.Theme.getSize("default_margin").width
  155. columns: 2
  156. columnSpacing: UM.Theme.getSize("default_margin").width
  157. Label { font: UM.Theme.getFont("default"); text: catalog.i18nc("@label", "Type") }
  158. Label { id: typeText; font: UM.Theme.getFont("default"); text: "?" }
  159. Label { font: UM.Theme.getFont("default"); text: catalog.i18nc("@label", "Firmware version") }
  160. Label { id: firmwareText; font: UM.Theme.getFont("default"); text: "0.0.0.0" }
  161. Label { font: UM.Theme.getFont("default"); text: catalog.i18nc("@label", "Address") }
  162. Label { id: addressText; font: UM.Theme.getFont("default"); text: "0.0.0.0" }
  163. Connections
  164. {
  165. target: UM.OutputDeviceManager
  166. onManualDeviceChanged:
  167. {
  168. if (UM.OutputDeviceManager.hasManualDevice)
  169. {
  170. typeText.text = UM.OutputDeviceManager.manualDeviceProperty("printer_type")
  171. firmwareText.text = UM.OutputDeviceManager.manualDeviceProperty("firmware_version")
  172. addressText.text = UM.OutputDeviceManager.manualDeviceProperty("address")
  173. }
  174. else
  175. {
  176. typeText.text = ""
  177. firmwareText.text = ""
  178. addressText.text = ""
  179. }
  180. }
  181. }
  182. }
  183. Connections
  184. {
  185. target: UM.OutputDeviceManager
  186. onManualDeviceChanged:
  187. {
  188. if (UM.OutputDeviceManager.hasManualDevice)
  189. {
  190. printerNameLabel.text = UM.OutputDeviceManager.manualDeviceProperty("name")
  191. addPrinterByIpScreen.haveConnection = true
  192. }
  193. else
  194. {
  195. addPrinterByIpScreen.hasSentRequest = false
  196. addPrinterByIpScreen.haveConnection = false
  197. addPrinterByIpScreen.deviceUnresponsive = true
  198. }
  199. }
  200. }
  201. }
  202. }
  203. }
  204. }
  205. Cura.PrimaryButton
  206. {
  207. id: backButton
  208. anchors.left: parent.left
  209. anchors.bottom: parent.bottom
  210. text: catalog.i18nc("@button", "Cancel")
  211. onClicked: base.showPreviousPage()
  212. }
  213. Cura.PrimaryButton
  214. {
  215. id: connectButton
  216. anchors.right: parent.right
  217. anchors.bottom: parent.bottom
  218. text: catalog.i18nc("@button", "Connect")
  219. onClicked:
  220. {
  221. CuraApplication.getDiscoveredPrintersModel().createMachineFromDiscoveredPrinterAddress(
  222. UM.OutputDeviceManager.manualDeviceProperty("address"))
  223. UM.OutputDeviceManager.setActiveDevice(UM.OutputDeviceManager.manualDeviceProperty("device_id"))
  224. base.showNextPage()
  225. }
  226. enabled: addPrinterByIpScreen.haveConnection
  227. }
  228. }