AddPrinterByIpContent.qml 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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. Label
  20. {
  21. id: titleLabel
  22. anchors.top: parent.top
  23. anchors.topMargin: UM.Theme.getSize("default_margin").height
  24. anchors.horizontalCenter: parent.horizontalCenter
  25. horizontalAlignment: Text.AlignHCenter
  26. text: catalog.i18nc("@label", "Add printer by IP address")
  27. color: UM.Theme.getColor("primary_button")
  28. font: UM.Theme.getFont("large_bold")
  29. renderType: Text.NativeRendering
  30. }
  31. Item
  32. {
  33. anchors.top: titleLabel.bottom
  34. anchors.bottom: connectButton.top
  35. anchors.topMargin: UM.Theme.getSize("default_margin").height
  36. anchors.bottomMargin: UM.Theme.getSize("default_margin").height
  37. anchors.horizontalCenter: parent.horizontalCenter
  38. width: Math.floor(parent.width * 3 / 4)
  39. Item
  40. {
  41. width: parent.width
  42. Label
  43. {
  44. id: explainLabel
  45. height: contentHeight
  46. width: parent.width
  47. anchors.top: parent.top
  48. anchors.margins: UM.Theme.getSize("default_margin").width
  49. font: UM.Theme.getFont("default")
  50. text: catalog.i18nc("@label", "Enter the IP address or hostname of your printer on the network.")
  51. }
  52. Item
  53. {
  54. id: userInputFields
  55. height: childrenRect.height
  56. width: parent.width
  57. anchors.top: explainLabel.bottom
  58. TextField
  59. {
  60. id: hostnameField
  61. anchors.verticalCenter: addPrinterButton.verticalCenter
  62. anchors.left: parent.left
  63. height: addPrinterButton.height
  64. anchors.right: addPrinterButton.left
  65. anchors.margins: UM.Theme.getSize("default_margin").width
  66. font: UM.Theme.getFont("default")
  67. validator: RegExpValidator
  68. {
  69. regExp: /[a-fA-F0-9\.\:]*/
  70. }
  71. onAccepted: addPrinterButton.clicked()
  72. }
  73. Cura.PrimaryButton
  74. {
  75. id: addPrinterButton
  76. anchors.top: parent.top
  77. anchors.right: parent.right
  78. anchors.margins: UM.Theme.getSize("default_margin").width
  79. width: UM.Theme.getSize("action_button").width
  80. fixedWidthMode: true
  81. text: catalog.i18nc("@button", "Add")
  82. onClicked:
  83. {
  84. if (hostnameField.text.trim() != "")
  85. {
  86. enabled = false;
  87. UM.OutputDeviceManager.addManualDevice(hostnameField.text, hostnameField.text);
  88. }
  89. }
  90. BusyIndicator
  91. {
  92. anchors.fill: parent
  93. running:
  94. {
  95. ! parent.enabled &&
  96. ! addPrinterByIpScreen.hasSentRequest &&
  97. ! addPrinterByIpScreen.haveConnection
  98. }
  99. }
  100. }
  101. }
  102. Item
  103. {
  104. width: parent.width
  105. anchors.top: userInputFields.bottom
  106. anchors.margins: UM.Theme.getSize("default_margin").width
  107. Label
  108. {
  109. id: waitResponseLabel
  110. anchors.top: parent.top
  111. anchors.margins: UM.Theme.getSize("default_margin").width
  112. font: UM.Theme.getFont("default")
  113. visible: { addPrinterByIpScreen.hasSentRequest && ! addPrinterByIpScreen.haveConnection }
  114. text: catalog.i18nc("@label", "The printer at this address has not responded yet.")
  115. }
  116. Item
  117. {
  118. id: printerInfoLabels
  119. anchors.top: parent.top
  120. anchors.margins: UM.Theme.getSize("default_margin").width
  121. visible: addPrinterByIpScreen.haveConnection
  122. Label
  123. {
  124. id: printerNameLabel
  125. anchors.top: parent.top
  126. font: UM.Theme.getFont("large")
  127. text: "???"
  128. }
  129. GridLayout
  130. {
  131. id: printerInfoGrid
  132. anchors.top: printerNameLabel.bottom
  133. anchors.margins: UM.Theme.getSize("default_margin").width
  134. columns: 2
  135. columnSpacing: UM.Theme.getSize("default_margin").width
  136. Label { font: UM.Theme.getFont("default"); text: catalog.i18nc("@label", "Type") }
  137. Label { id: typeText; font: UM.Theme.getFont("default"); text: "?" }
  138. Label { font: UM.Theme.getFont("default"); text: catalog.i18nc("@label", "Firmware version") }
  139. Label { id: firmwareText; font: UM.Theme.getFont("default"); text: "0.0.0.0" }
  140. Label { font: UM.Theme.getFont("default"); text: catalog.i18nc("@label", "Address") }
  141. Label { id: addressText; font: UM.Theme.getFont("default"); text: "0.0.0.0" }
  142. Connections
  143. {
  144. target: UM.OutputDeviceManager
  145. onManualDeviceChanged:
  146. {
  147. typeText.text = UM.OutputDeviceManager.manualDeviceProperty("printer_type")
  148. firmwareText.text = UM.OutputDeviceManager.manualDeviceProperty("firmware_version")
  149. addressText.text = UM.OutputDeviceManager.manualDeviceProperty("address")
  150. }
  151. }
  152. }
  153. Connections
  154. {
  155. target: UM.OutputDeviceManager
  156. onManualDeviceChanged:
  157. {
  158. printerNameLabel.text = UM.OutputDeviceManager.manualDeviceProperty("name")
  159. addPrinterByIpScreen.haveConnection = true
  160. }
  161. }
  162. }
  163. }
  164. }
  165. }
  166. Cura.PrimaryButton
  167. {
  168. id: backButton
  169. anchors.left: parent.left
  170. anchors.bottom: parent.bottom
  171. anchors.margins: UM.Theme.getSize("default_margin").width
  172. text: catalog.i18nc("@button", "Cancel")
  173. width: UM.Theme.getSize("action_button").width
  174. fixedWidthMode: true
  175. onClicked: base.goToPage("add_network_or_local_printer")
  176. }
  177. Cura.PrimaryButton
  178. {
  179. id: connectButton
  180. anchors.right: parent.right
  181. anchors.bottom: parent.bottom
  182. anchors.margins: UM.Theme.getSize("default_margin").width
  183. text: catalog.i18nc("@button", "Connect")
  184. width: UM.Theme.getSize("action_button").width
  185. fixedWidthMode: true
  186. onClicked:
  187. {
  188. CuraApplication.getDiscoveredPrintersModel().createMachineFromDiscoveredPrinterAddress(
  189. UM.OutputDeviceManager.manualDeviceProperty("address"))
  190. UM.OutputDeviceManager.setActiveDevice(UM.OutputDeviceManager.manualDeviceProperty("device_id"))
  191. base.showNextPage()
  192. }
  193. enabled: addPrinterByIpScreen.haveConnection
  194. }
  195. }