SyncState.qml 3.3 KB

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