SyncState.qml 3.2 KB

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