AddPrinterByIpContent.qml 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  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.topMargin: UM.Theme.getSize("welcome_pages_default_margin").height
  26. anchors.horizontalCenter: parent.horizontalCenter
  27. horizontalAlignment: Text.AlignHCenter
  28. text: catalog.i18nc("@label", "Add printer by IP address")
  29. color: UM.Theme.getColor("primary_button")
  30. font: UM.Theme.getFont("large_bold")
  31. renderType: Text.NativeRendering
  32. }
  33. Item
  34. {
  35. anchors.top: titleLabel.bottom
  36. anchors.bottom: connectButton.top
  37. anchors.topMargin: UM.Theme.getSize("default_margin").height
  38. anchors.bottomMargin: UM.Theme.getSize("default_margin").height
  39. anchors.horizontalCenter: parent.horizontalCenter
  40. width: Math.floor(parent.width * 3 / 4)
  41. Item
  42. {
  43. width: parent.width
  44. Label
  45. {
  46. id: explainLabel
  47. height: contentHeight
  48. width: parent.width
  49. anchors.top: parent.top
  50. anchors.margins: UM.Theme.getSize("default_margin").width
  51. font: UM.Theme.getFont("default")
  52. text: catalog.i18nc("@label", "Enter the IP address or hostname of your printer on the network.")
  53. }
  54. Item
  55. {
  56. id: userInputFields
  57. height: childrenRect.height
  58. width: parent.width
  59. anchors.top: explainLabel.bottom
  60. TextField
  61. {
  62. id: hostnameField
  63. anchors.verticalCenter: addPrinterButton.verticalCenter
  64. anchors.left: parent.left
  65. height: addPrinterButton.height
  66. anchors.right: addPrinterButton.left
  67. anchors.margins: UM.Theme.getSize("default_margin").width
  68. font: UM.Theme.getFont("default")
  69. selectByMouse: true
  70. validator: RegExpValidator
  71. {
  72. regExp: /[a-fA-F0-9\.\:]*/
  73. }
  74. enabled: { ! (addPrinterByIpScreen.hasSentRequest || addPrinterByIpScreen.haveConnection) }
  75. onAccepted: addPrinterButton.clicked()
  76. }
  77. Cura.PrimaryButton
  78. {
  79. id: addPrinterButton
  80. anchors.top: parent.top
  81. anchors.right: parent.right
  82. anchors.margins: UM.Theme.getSize("default_margin").width
  83. width: UM.Theme.getSize("action_button").width
  84. fixedWidthMode: true
  85. text: catalog.i18nc("@button", "Add")
  86. onClicked:
  87. {
  88. if (hostnameField.text.trim() != "")
  89. {
  90. enabled = false;
  91. addPrinterByIpScreen.deviceUnresponsive = false;
  92. UM.OutputDeviceManager.addManualDevice(hostnameField.text, hostnameField.text);
  93. }
  94. }
  95. BusyIndicator
  96. {
  97. anchors.fill: parent
  98. running:
  99. {
  100. ! parent.enabled &&
  101. ! addPrinterByIpScreen.hasSentRequest &&
  102. ! addPrinterByIpScreen.haveConnection
  103. }
  104. }
  105. Connections
  106. {
  107. target: UM.OutputDeviceManager
  108. onManualDeviceChanged: { addPrinterButton.enabled = ! UM.OutputDeviceManager.hasManualDevice }
  109. }
  110. }
  111. }
  112. Item
  113. {
  114. width: parent.width
  115. anchors.top: userInputFields.bottom
  116. anchors.margins: UM.Theme.getSize("default_margin").width
  117. Label
  118. {
  119. id: waitResponseLabel
  120. anchors.top: parent.top
  121. anchors.margins: UM.Theme.getSize("default_margin").width
  122. font: UM.Theme.getFont("default")
  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. text: "???"
  152. }
  153. GridLayout
  154. {
  155. id: printerInfoGrid
  156. anchors.top: printerNameLabel.bottom
  157. anchors.margins: UM.Theme.getSize("default_margin").width
  158. columns: 2
  159. columnSpacing: UM.Theme.getSize("default_margin").width
  160. Label { font: UM.Theme.getFont("default"); text: catalog.i18nc("@label", "Type") }
  161. Label { id: typeText; font: UM.Theme.getFont("default"); text: "?" }
  162. Label { font: UM.Theme.getFont("default"); text: catalog.i18nc("@label", "Firmware version") }
  163. Label { id: firmwareText; font: UM.Theme.getFont("default"); text: "0.0.0.0" }
  164. Label { font: UM.Theme.getFont("default"); text: catalog.i18nc("@label", "Address") }
  165. Label { id: addressText; font: UM.Theme.getFont("default"); text: "0.0.0.0" }
  166. Connections
  167. {
  168. target: UM.OutputDeviceManager
  169. onManualDeviceChanged:
  170. {
  171. if (UM.OutputDeviceManager.hasManualDevice)
  172. {
  173. typeText.text = UM.OutputDeviceManager.manualDeviceProperty("printer_type")
  174. firmwareText.text = UM.OutputDeviceManager.manualDeviceProperty("firmware_version")
  175. addressText.text = UM.OutputDeviceManager.manualDeviceProperty("address")
  176. }
  177. else
  178. {
  179. typeText.text = ""
  180. firmwareText.text = ""
  181. addressText.text = ""
  182. }
  183. }
  184. }
  185. }
  186. Connections
  187. {
  188. target: UM.OutputDeviceManager
  189. onManualDeviceChanged:
  190. {
  191. if (UM.OutputDeviceManager.hasManualDevice)
  192. {
  193. printerNameLabel.text = UM.OutputDeviceManager.manualDeviceProperty("name")
  194. addPrinterByIpScreen.haveConnection = true
  195. }
  196. else
  197. {
  198. addPrinterByIpScreen.hasSentRequest = false
  199. addPrinterByIpScreen.haveConnection = false
  200. addPrinterByIpScreen.deviceUnresponsive = true
  201. }
  202. }
  203. }
  204. }
  205. }
  206. }
  207. }
  208. Cura.PrimaryButton
  209. {
  210. id: backButton
  211. anchors.left: parent.left
  212. anchors.bottom: parent.bottom
  213. anchors.margins: UM.Theme.getSize("welcome_pages_default_margin").width
  214. text: catalog.i18nc("@button", "Cancel")
  215. width: UM.Theme.getSize("action_button").width
  216. fixedWidthMode: true
  217. onClicked: base.goToPage("add_network_or_local_printer")
  218. }
  219. Cura.PrimaryButton
  220. {
  221. id: connectButton
  222. anchors.right: parent.right
  223. anchors.bottom: parent.bottom
  224. anchors.margins: UM.Theme.getSize("welcome_pages_default_margin").width
  225. text: catalog.i18nc("@button", "Connect")
  226. width: UM.Theme.getSize("action_button").width
  227. fixedWidthMode: true
  228. onClicked:
  229. {
  230. CuraApplication.getDiscoveredPrintersModel().createMachineFromDiscoveredPrinterAddress(
  231. UM.OutputDeviceManager.manualDeviceProperty("address"))
  232. UM.OutputDeviceManager.setActiveDevice(UM.OutputDeviceManager.manualDeviceProperty("device_id"))
  233. base.showNextPage()
  234. }
  235. enabled: addPrinterByIpScreen.haveConnection
  236. }
  237. }