AddPrinterByIpContent.qml 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  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. text: catalog.i18nc("@button", "Add")
  84. onClicked:
  85. {
  86. if (hostnameField.text.trim() != "")
  87. {
  88. enabled = false;
  89. addPrinterByIpScreen.deviceUnresponsive = false;
  90. UM.OutputDeviceManager.addManualDevice(hostnameField.text, hostnameField.text);
  91. }
  92. }
  93. BusyIndicator
  94. {
  95. anchors.fill: parent
  96. running:
  97. {
  98. ! parent.enabled &&
  99. ! addPrinterByIpScreen.hasSentRequest &&
  100. ! addPrinterByIpScreen.haveConnection
  101. }
  102. }
  103. Connections
  104. {
  105. target: UM.OutputDeviceManager
  106. onManualDeviceChanged: { addPrinterButton.enabled = ! UM.OutputDeviceManager.hasManualDevice }
  107. }
  108. }
  109. }
  110. Item
  111. {
  112. width: parent.width
  113. anchors.top: userInputFields.bottom
  114. anchors.margins: UM.Theme.getSize("default_margin").width
  115. Label
  116. {
  117. id: waitResponseLabel
  118. anchors.top: parent.top
  119. anchors.margins: UM.Theme.getSize("default_margin").width
  120. font: UM.Theme.getFont("default")
  121. visible:
  122. {
  123. (addPrinterByIpScreen.hasSentRequest && ! addPrinterByIpScreen.haveConnection)
  124. || addPrinterByIpScreen.deviceUnresponsive
  125. }
  126. text:
  127. {
  128. if (addPrinterByIpScreen.deviceUnresponsive)
  129. {
  130. catalog.i18nc("@label", "Could not connect to device.")
  131. }
  132. else
  133. {
  134. catalog.i18nc("@label", "The printer at this address has not responded yet.")
  135. }
  136. }
  137. }
  138. Item
  139. {
  140. id: printerInfoLabels
  141. anchors.top: parent.top
  142. anchors.margins: UM.Theme.getSize("default_margin").width
  143. visible: addPrinterByIpScreen.haveConnection && ! addPrinterByIpScreen.deviceUnresponsive
  144. Label
  145. {
  146. id: printerNameLabel
  147. anchors.top: parent.top
  148. font: UM.Theme.getFont("large")
  149. text: "???"
  150. }
  151. GridLayout
  152. {
  153. id: printerInfoGrid
  154. anchors.top: printerNameLabel.bottom
  155. anchors.margins: UM.Theme.getSize("default_margin").width
  156. columns: 2
  157. columnSpacing: UM.Theme.getSize("default_margin").width
  158. Label { font: UM.Theme.getFont("default"); text: catalog.i18nc("@label", "Type") }
  159. Label { id: typeText; font: UM.Theme.getFont("default"); text: "?" }
  160. Label { font: UM.Theme.getFont("default"); text: catalog.i18nc("@label", "Firmware version") }
  161. Label { id: firmwareText; font: UM.Theme.getFont("default"); text: "0.0.0.0" }
  162. Label { font: UM.Theme.getFont("default"); text: catalog.i18nc("@label", "Address") }
  163. Label { id: addressText; font: UM.Theme.getFont("default"); text: "0.0.0.0" }
  164. Connections
  165. {
  166. target: UM.OutputDeviceManager
  167. onManualDeviceChanged:
  168. {
  169. if (UM.OutputDeviceManager.hasManualDevice)
  170. {
  171. typeText.text = UM.OutputDeviceManager.manualDeviceProperty("printer_type")
  172. firmwareText.text = UM.OutputDeviceManager.manualDeviceProperty("firmware_version")
  173. addressText.text = UM.OutputDeviceManager.manualDeviceProperty("address")
  174. }
  175. else
  176. {
  177. typeText.text = ""
  178. firmwareText.text = ""
  179. addressText.text = ""
  180. }
  181. }
  182. }
  183. }
  184. Connections
  185. {
  186. target: UM.OutputDeviceManager
  187. onManualDeviceChanged:
  188. {
  189. if (UM.OutputDeviceManager.hasManualDevice)
  190. {
  191. printerNameLabel.text = UM.OutputDeviceManager.manualDeviceProperty("name")
  192. addPrinterByIpScreen.haveConnection = true
  193. }
  194. else
  195. {
  196. addPrinterByIpScreen.hasSentRequest = false
  197. addPrinterByIpScreen.haveConnection = false
  198. addPrinterByIpScreen.deviceUnresponsive = true
  199. }
  200. }
  201. }
  202. }
  203. }
  204. }
  205. }
  206. Cura.PrimaryButton
  207. {
  208. id: backButton
  209. anchors.left: parent.left
  210. anchors.bottom: parent.bottom
  211. anchors.margins: UM.Theme.getSize("welcome_pages_default_margin").width
  212. text: catalog.i18nc("@button", "Cancel")
  213. onClicked: base.showPreviousPage()
  214. }
  215. Cura.PrimaryButton
  216. {
  217. id: connectButton
  218. anchors.right: parent.right
  219. anchors.bottom: parent.bottom
  220. anchors.margins: UM.Theme.getSize("welcome_pages_default_margin").width
  221. text: catalog.i18nc("@button", "Connect")
  222. onClicked:
  223. {
  224. CuraApplication.getDiscoveredPrintersModel().createMachineFromDiscoveredPrinterAddress(
  225. UM.OutputDeviceManager.manualDeviceProperty("address"))
  226. UM.OutputDeviceManager.setActiveDevice(UM.OutputDeviceManager.manualDeviceProperty("device_id"))
  227. base.showNextPage()
  228. }
  229. enabled: addPrinterByIpScreen.haveConnection
  230. }
  231. }