AddCloudPrintersView.qml 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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.7 as Cura
  8. //
  9. // This component gets activated when the user presses the "Add cloud printers" button from the "Add a Printer" page.
  10. // It contains a busy indicator that remains active until the user logs in and adds a cloud printer in his/her account.
  11. // Once a cloud printer is added in mycloud.ultimaker.com, Cura discovers it (in a time window of 30 sec) and displays
  12. // the newly added printers in this page.
  13. //
  14. Item
  15. {
  16. UM.I18nCatalog { id: catalog; name: "cura" }
  17. property bool searchingForCloudPrinters: true
  18. property var discoveredCloudPrintersModel: CuraApplication.getDiscoveredCloudPrintersModel()
  19. // The area where either the discoveredCloudPrintersScrollView or the busyIndicator will be displayed
  20. Rectangle
  21. {
  22. id: cloudPrintersContent
  23. width: parent.width
  24. height: parent.height
  25. anchors
  26. {
  27. top: parent.top
  28. left: parent.left
  29. leftMargin: UM.Theme.getSize("default_margin").width
  30. right: parent.right
  31. bottom: finishButton.top
  32. bottomMargin: UM.Theme.getSize("default_margin").height
  33. }
  34. Label
  35. {
  36. id: titleLabel
  37. anchors.top: parent.top
  38. anchors.horizontalCenter: parent.horizontalCenter
  39. horizontalAlignment: Text.AlignHCenter
  40. text: catalog.i18nc("@label", "Add a Cloud printer")
  41. color: UM.Theme.getColor("primary_button")
  42. font: UM.Theme.getFont("huge")
  43. renderType: Text.NativeRendering
  44. }
  45. // Component that contains a busy indicator and a message, while it waits for Cura to discover a cloud printer
  46. Item
  47. {
  48. id: waitingContent
  49. width: parent.width
  50. height: childrenRect.height
  51. anchors.verticalCenter: parent.verticalCenter
  52. anchors.horizontalCenter: parent.horizontalCenter
  53. BusyIndicator
  54. {
  55. id: waitingIndicator
  56. anchors.horizontalCenter: parent.horizontalCenter
  57. running: searchingForCloudPrinters
  58. }
  59. Label
  60. {
  61. id: waitingLabel
  62. anchors.top: waitingIndicator.bottom
  63. anchors.horizontalCenter: parent.horizontalCenter
  64. horizontalAlignment: Text.AlignHCenter
  65. text: catalog.i18nc("@label", "Waiting for Cloud response")
  66. font: UM.Theme.getFont("large")
  67. renderType: Text.NativeRendering
  68. }
  69. Label
  70. {
  71. id: noPrintersFoundLabel
  72. anchors.top: waitingLabel.bottom
  73. anchors.topMargin: 2 * UM.Theme.getSize("wide_margin").height
  74. anchors.horizontalCenter: parent.horizontalCenter
  75. horizontalAlignment: Text.AlignHCenter
  76. text: catalog.i18nc("@label", "No printers found in your account?")
  77. font: UM.Theme.getFont("medium")
  78. }
  79. Label
  80. {
  81. text: "Sign in with a different account"
  82. anchors.top: noPrintersFoundLabel.bottom
  83. anchors.horizontalCenter: parent.horizontalCenter
  84. font: UM.Theme.getFont("medium")
  85. color: UM.Theme.getColor("text_link")
  86. MouseArea {
  87. anchors.fill: parent;
  88. onClicked: Cura.API.account.login(true)
  89. hoverEnabled: true
  90. onEntered:
  91. {
  92. parent.font.underline = true
  93. }
  94. onExited:
  95. {
  96. parent.font.underline = false
  97. }
  98. }
  99. }
  100. visible: discoveredCloudPrintersModel.count == 0
  101. }
  102. // Label displayed when a new cloud printer is discovered
  103. Label
  104. {
  105. anchors.top: titleLabel.bottom
  106. anchors.topMargin: 2 * UM.Theme.getSize("default_margin").height
  107. id: cloudPrintersAddedTitle
  108. font: UM.Theme.getFont("medium")
  109. text: catalog.i18nc("@label", "The following printers in your account have been added in Cura:")
  110. height: contentHeight + 2 * UM.Theme.getSize("default_margin").height
  111. visible: discoveredCloudPrintersModel.count > 0
  112. }
  113. // The scrollView that contains the list of newly discovered Ultimaker Cloud printers. Visible only when
  114. // there is at least a new cloud printer.
  115. ScrollView
  116. {
  117. id: discoveredCloudPrintersScrollView
  118. width: parent.width
  119. clip : true
  120. ScrollBar.horizontal.policy: ScrollBar.AsNeeded
  121. ScrollBar.vertical.policy: ScrollBar.AsNeeded
  122. visible: discoveredCloudPrintersModel.count > 0
  123. anchors
  124. {
  125. top: cloudPrintersAddedTitle.bottom
  126. topMargin: UM.Theme.getSize("default_margin").height
  127. left: parent.left
  128. leftMargin: UM.Theme.getSize("default_margin").width
  129. right: parent.right
  130. bottom: parent.bottom
  131. }
  132. Column
  133. {
  134. id: discoveredPrintersColumn
  135. spacing: 2 * UM.Theme.getSize("default_margin").height
  136. Repeater
  137. {
  138. id: discoveredCloudPrintersRepeater
  139. model: discoveredCloudPrintersModel
  140. delegate: Item
  141. {
  142. width: discoveredCloudPrintersScrollView.width
  143. height: contentColumn.height
  144. Column
  145. {
  146. id: contentColumn
  147. Label
  148. {
  149. id: cloudPrinterNameLabel
  150. leftPadding: UM.Theme.getSize("default_margin").width
  151. text: model.name
  152. font: UM.Theme.getFont("large_bold")
  153. color: UM.Theme.getColor("text")
  154. elide: Text.ElideRight
  155. }
  156. Label
  157. {
  158. id: cloudPrinterTypeLabel
  159. leftPadding: 2 * UM.Theme.getSize("default_margin").width
  160. topPadding: UM.Theme.getSize("thin_margin").height
  161. text: {"Type: " + model.machine_type}
  162. font: UM.Theme.getFont("medium")
  163. color: UM.Theme.getColor("text")
  164. elide: Text.ElideRight
  165. }
  166. Label
  167. {
  168. id: cloudPrinterFirmwareVersionLabel
  169. leftPadding: 2 * UM.Theme.getSize("default_margin").width
  170. text: {"Firmware version: " + model.firmware_version}
  171. font: UM.Theme.getFont("medium")
  172. color: UM.Theme.getColor("text")
  173. elide: Text.ElideRight
  174. }
  175. }
  176. }
  177. }
  178. }
  179. }
  180. }
  181. Cura.SecondaryButton
  182. {
  183. id: backButton
  184. anchors.left: parent.left
  185. anchors.bottom: parent.bottom
  186. text: catalog.i18nc("@button", "Add printer manually")
  187. onClicked:
  188. {
  189. discoveredCloudPrintersModel.clear()
  190. base.showPreviousPage()
  191. }
  192. visible: discoveredCloudPrintersModel.count == 0
  193. }
  194. Cura.PrimaryButton
  195. {
  196. id: finishButton
  197. anchors.right: parent.right
  198. anchors.bottom: parent.bottom
  199. text: catalog.i18nc("@button", "Finish")
  200. onClicked:
  201. {
  202. discoveredCloudPrintersModel.clear()
  203. base.showNextPage()
  204. }
  205. enabled: !waitingContent.visible
  206. }
  207. }