AddPrinterByIpContent.qml 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  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. property bool hasPushedAdd: false
  16. property bool hasSentRequest: false
  17. property bool haveConnection: false
  18. Timer
  19. {
  20. id: tempTimerButton
  21. interval: 1200
  22. running: false
  23. repeat: false
  24. onTriggered:
  25. {
  26. hasPushedAdd = true
  27. tempTimerRequest.running = true
  28. }
  29. }
  30. // TODO: Remove timers after review interface!
  31. Timer
  32. {
  33. id: tempTimerRequest
  34. interval: 1200
  35. running: false
  36. repeat: false
  37. onTriggered:
  38. {
  39. hasSentRequest = true
  40. tempTimerConnection.running = true
  41. }
  42. }
  43. // TODO: Remove timers after review interface!
  44. Timer
  45. {
  46. id: tempTimerConnection
  47. interval: 1200
  48. running: false
  49. repeat: false
  50. onTriggered: haveConnection = true
  51. }
  52. // TODO: Remove timers after review interface!
  53. Label
  54. {
  55. id: titleLabel
  56. anchors.top: parent.top
  57. anchors.topMargin: 40
  58. anchors.horizontalCenter: parent.horizontalCenter
  59. horizontalAlignment: Text.AlignHCenter
  60. text: catalog.i18nc("@label", "Add printer by IP address")
  61. color: UM.Theme.getColor("primary_button")
  62. font: UM.Theme.getFont("large_bold")
  63. renderType: Text.NativeRendering
  64. }
  65. Rectangle
  66. {
  67. anchors.top: titleLabel.bottom
  68. anchors.bottom: connectButton.top
  69. anchors.topMargin: 40
  70. anchors.bottomMargin: 40
  71. anchors.horizontalCenter: parent.horizontalCenter
  72. width: parent.width * 3 / 4
  73. Item
  74. {
  75. width: parent.width
  76. Label
  77. {
  78. id: explainLabel
  79. height: contentHeight
  80. width: parent.width
  81. anchors.top: parent.top
  82. anchors.margins: 20
  83. //anchors.bottomMargin: 20
  84. font: UM.Theme.getFont("default")
  85. text: catalog.i18nc("@label", "Enter the IP address or hostname of your printer on the network.")
  86. }
  87. Item
  88. {
  89. id: userInputFields
  90. height: childrenRect.height
  91. width: parent.width
  92. anchors.top: explainLabel.bottom
  93. TextField
  94. {
  95. id: hostnameField
  96. anchors.verticalCenter: addPrinterButton.verticalCenter
  97. anchors.left: parent.left
  98. height: addPrinterButton.height
  99. anchors.right: addPrinterButton.left
  100. anchors.margins: 20
  101. font: UM.Theme.getFont("default")
  102. text: ""
  103. validator: RegExpValidator
  104. {
  105. regExp: /[a-zA-Z0-9\.\-\_]*/
  106. }
  107. onAccepted: addPrinterButton.clicked()
  108. }
  109. Cura.PrimaryButton
  110. {
  111. id: addPrinterButton
  112. anchors.top: parent.top
  113. anchors.right: parent.right
  114. anchors.margins: 20
  115. width: 140
  116. fixedWidthMode: true
  117. text: catalog.i18nc("@button", "Add")
  118. onClicked:
  119. {
  120. // TEMP: Simulate successfull connection to printer with 127.0.0.1 or unsuccessful with anything else
  121. // TODO, alter after review interface, now it just starts the timers.
  122. if (hostnameField.text.trim() != "")
  123. {
  124. addPrinterByIpScreen.hasPushedAdd = true
  125. tempTimerRequest.running = true
  126. UM.OutputDeviceManager.addManualDevice(hostnameField.text, hostnameField.text)
  127. }
  128. }
  129. enabled: ! addPrinterByIpScreen.hasPushedAdd
  130. BusyIndicator
  131. {
  132. anchors.fill: parent
  133. running: { ! parent.enabled && ! addPrinterByIpScreen.hasSentRequest }
  134. }
  135. }
  136. }
  137. Rectangle
  138. {
  139. width: parent.width
  140. anchors.top: userInputFields.bottom
  141. anchors.margins: 20
  142. Label
  143. {
  144. id: waitResponseLabel
  145. anchors.top: parent.top
  146. anchors.margins: 20
  147. font: UM.Theme.getFont("default")
  148. visible: { addPrinterByIpScreen.hasSentRequest && ! addPrinterByIpScreen.haveConnection }
  149. text: catalog.i18nc("@label", "The printer at this address has not responded yet.")
  150. }
  151. Rectangle
  152. {
  153. id: printerInfoLabels
  154. anchors.top: parent.top
  155. anchors.margins: 20
  156. visible: addPrinterByIpScreen.haveConnection
  157. Label
  158. {
  159. id: printerNameLabel
  160. anchors.top: parent.top
  161. font: UM.Theme.getFont("large")
  162. text: "???"
  163. }
  164. GridLayout
  165. {
  166. id: printerInfoGrid
  167. anchors.top: printerNameLabel.bottom
  168. columns: 2
  169. columnSpacing: 20
  170. Text { font: UM.Theme.getFont("default"); text: catalog.i18nc("@label", "Type") }
  171. Label { id: typeText; font: UM.Theme.getFont("default"); text: "?" }
  172. Text { font: UM.Theme.getFont("default"); text: catalog.i18nc("@label", "Firmware version") }
  173. Label { id: firmwareText; font: UM.Theme.getFont("default"); text: "0.0.0.0" }
  174. Text { font: UM.Theme.getFont("default"); text: catalog.i18nc("@label", "Address") }
  175. Label { id: addressText; font: UM.Theme.getFont("default"); text: "0.0.0.0" }
  176. Connections
  177. {
  178. target: UM.OutputDeviceManager
  179. onManualDeviceChanged:
  180. {
  181. typeText.text = UM.OutputDeviceManager.manualDeviceProperty("printer_type")
  182. firmwareText.text = UM.OutputDeviceManager.manualDeviceProperty("firmware_version")
  183. addressText.text = UM.OutputDeviceManager.manualDeviceProperty("address")
  184. }
  185. }
  186. }
  187. Connections
  188. {
  189. target: UM.OutputDeviceManager
  190. onManualDeviceChanged:
  191. {
  192. printerNameLabel.text = UM.OutputDeviceManager.manualDeviceProperty("name")
  193. }
  194. }
  195. }
  196. }
  197. }
  198. }
  199. Cura.PrimaryButton
  200. {
  201. id: backButton
  202. anchors.left: parent.left
  203. anchors.bottom: parent.bottom
  204. anchors.margins: 40
  205. text: catalog.i18nc("@button", "Cancel")
  206. width: 140
  207. fixedWidthMode: true
  208. onClicked: base.showPreviousPage()
  209. enabled: true
  210. }
  211. Cura.PrimaryButton
  212. {
  213. id: connectButton
  214. anchors.right: parent.right
  215. anchors.bottom: parent.bottom
  216. anchors.margins: 40
  217. text: catalog.i18nc("@button", "Connect")
  218. width: 140
  219. fixedWidthMode: true
  220. onClicked: base.showNextPage()
  221. enabled: addPrinterByIpScreen.haveConnection
  222. }
  223. }