SyncState.qml 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. import QtQuick 2.10
  2. import QtQuick.Controls 2.3
  3. import UM 1.4 as UM
  4. import Cura 1.1 as Cura
  5. Row // sync state icon + message
  6. {
  7. property alias iconSource: icon.source
  8. property alias labelText: stateLabel.text
  9. property alias syncButtonVisible: accountSyncButton.visible
  10. property alias animateIconRotation: updateAnimator.running
  11. width: childrenRect.width
  12. height: childrenRect.height
  13. anchors.horizontalCenter: parent.horizontalCenter
  14. spacing: UM.Theme.getSize("narrow_margin").height
  15. UM.RecolorImage
  16. {
  17. id: icon
  18. width: 20 * screenScaleFactor
  19. height: width
  20. source: UM.Theme.getIcon("update")
  21. color: palette.text
  22. RotationAnimator
  23. {
  24. id: updateAnimator
  25. target: icon
  26. from: 0
  27. to: 360
  28. duration: 1000
  29. loops: Animation.Infinite
  30. running: true
  31. // reset rotation when stopped
  32. onRunningChanged: {
  33. if(!running)
  34. {
  35. icon.rotation = 0
  36. }
  37. }
  38. }
  39. }
  40. Column
  41. {
  42. width: childrenRect.width
  43. height: childrenRect.height
  44. Label
  45. {
  46. id: stateLabel
  47. text: catalog.i18nc("@state", "Checking...")
  48. color: UM.Theme.getColor("text")
  49. font: UM.Theme.getFont("medium")
  50. renderType: Text.NativeRendering
  51. }
  52. Label
  53. {
  54. id: accountSyncButton
  55. text: catalog.i18nc("@button", "Check for account updates")
  56. color: UM.Theme.getColor("secondary_button_text")
  57. font: UM.Theme.getFont("medium")
  58. renderType: Text.NativeRendering
  59. MouseArea
  60. {
  61. anchors.fill: parent
  62. onClicked: Cura.API.account.sync()
  63. hoverEnabled: true
  64. onEntered: accountSyncButton.font.underline = true
  65. onExited: accountSyncButton.font.underline = false
  66. }
  67. }
  68. }
  69. signal syncStateChanged(string newState)
  70. onSyncStateChanged: {
  71. if(newState == Cura.AccountSyncState.SYNCING){
  72. syncRow.iconSource = UM.Theme.getIcon("update")
  73. syncRow.labelText = catalog.i18nc("@label", "Checking...")
  74. } else if (newState == Cura.AccountSyncState.SUCCESS) {
  75. syncRow.iconSource = UM.Theme.getIcon("checked")
  76. syncRow.labelText = catalog.i18nc("@label", "You are up to date")
  77. } else if (newState == Cura.AccountSyncState.ERROR) {
  78. syncRow.iconSource = UM.Theme.getIcon("warning_light")
  79. syncRow.labelText = catalog.i18nc("@label", "Something went wrong...")
  80. } else {
  81. print("Error: unexpected sync state: " + newState)
  82. }
  83. if(newState == Cura.AccountSyncState.SYNCING){
  84. syncRow.animateIconRotation = true
  85. syncRow.syncButtonVisible = false
  86. } else {
  87. syncRow.animateIconRotation = false
  88. syncRow.syncButtonVisible = true
  89. }
  90. }
  91. Component.onCompleted: Cura.API.account.syncStateChanged.connect(syncStateChanged)
  92. }