SyncState.qml 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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: UM.Theme.getIcon("update")
  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. }
  49. Label
  50. {
  51. id: accountSyncButton
  52. text: catalog.i18nc("@button", "Check for account updates")
  53. color: UM.Theme.getColor("secondary_button_text")
  54. font: UM.Theme.getFont("medium")
  55. renderType: Text.NativeRendering
  56. visible: Cura.API.account.manualSyncEnabled
  57. MouseArea
  58. {
  59. anchors.fill: parent
  60. onClicked: Cura.API.account.sync(true)
  61. hoverEnabled: true
  62. onEntered: accountSyncButton.font.underline = true
  63. onExited: accountSyncButton.font.underline = false
  64. }
  65. }
  66. }
  67. signal syncStateChanged(string newState)
  68. onSyncStateChanged: {
  69. if(newState == Cura.AccountSyncState.SYNCING){
  70. icon.source = UM.Theme.getIcon("update")
  71. stateLabel.text = catalog.i18nc("@label", "Checking...")
  72. } else if (newState == Cura.AccountSyncState.SUCCESS) {
  73. icon.source = UM.Theme.getIcon("checked")
  74. stateLabel.text = catalog.i18nc("@label", "You are in sync with your account")
  75. } else if (newState == Cura.AccountSyncState.ERROR) {
  76. icon.source = UM.Theme.getIcon("warning_light")
  77. stateLabel.text = catalog.i18nc("@label", "Something went wrong...")
  78. } else {
  79. print("Error: unexpected sync state: " + newState)
  80. }
  81. if(newState == Cura.AccountSyncState.SYNCING){
  82. updateAnimator.running = true
  83. } else {
  84. updateAnimator.running = false
  85. }
  86. }
  87. Component.onCompleted: Cura.API.account.syncStateChanged.connect(syncStateChanged)
  88. }