SyncState.qml 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. import QtQuick 2.10
  2. import QtQuick.Controls 2.3
  3. import UM 1.5 as UM
  4. import Cura 1.1 as Cura
  5. Row // Sync state icon + message
  6. {
  7. property var syncState: Cura.API.account.syncState
  8. id: syncRow
  9. width: childrenRect.width
  10. height: childrenRect.height
  11. spacing: UM.Theme.getSize("narrow_margin").height
  12. // These are the enums from cura/API/account.py
  13. // somehow exposing these enums from python to QML doesn't work properly anymore
  14. property var _Cura_AccountSyncState_SYNCING: 0
  15. property var _Cura_AccountSyncState_SUCCESS: 1
  16. property var _Cura_AccountSyncState_ERROR: 2
  17. property var _Cura_AccountSyncState_IDLE: 3
  18. states: [
  19. State
  20. {
  21. name: "idle"
  22. when: syncState == _Cura_AccountSyncState_IDLE
  23. PropertyChanges { target: icon; source: UM.Theme.getIcon("ArrowDoubleCircleRight")}
  24. },
  25. State
  26. {
  27. name: "syncing"
  28. when: syncState == _Cura_AccountSyncState_SYNCING
  29. PropertyChanges { target: icon; source: UM.Theme.getIcon("ArrowDoubleCircleRight") }
  30. PropertyChanges { target: stateLabel; text: catalog.i18nc("@label", "Checking...")}
  31. },
  32. State
  33. {
  34. name: "up_to_date"
  35. when: syncState == _Cura_AccountSyncState_SUCCESS
  36. PropertyChanges { target: icon; source: UM.Theme.getIcon("CheckCircle") }
  37. PropertyChanges { target: stateLabel; text: catalog.i18nc("@label", "Account synced")}
  38. },
  39. State
  40. {
  41. name: "error"
  42. when: syncState == _Cura_AccountSyncState_ERROR
  43. PropertyChanges { target: icon; source: UM.Theme.getIcon("Warning") }
  44. PropertyChanges { target: stateLabel; text: catalog.i18nc("@label", "Something went wrong...")}
  45. }
  46. ]
  47. UM.ColorImage
  48. {
  49. id: icon
  50. width: 20 * screenScaleFactor
  51. height: width
  52. // source is determined by State
  53. color: UM.Theme.getColor("account_sync_state_icon")
  54. RotationAnimator
  55. {
  56. id: updateAnimator
  57. target: icon
  58. from: 0
  59. to: 360
  60. duration: 1000
  61. loops: Animation.Infinite
  62. running: syncState == Cura.AccountSyncState.SYNCING
  63. // reset rotation when stopped
  64. onRunningChanged: {
  65. if(!running)
  66. {
  67. icon.rotation = 0
  68. }
  69. }
  70. }
  71. }
  72. Column
  73. {
  74. width: childrenRect.width
  75. height: childrenRect.height
  76. UM.Label
  77. {
  78. id: stateLabel
  79. // text is determined by State
  80. font: UM.Theme.getFont("medium")
  81. anchors.leftMargin: UM.Theme.getSize("default_margin").width
  82. anchors.rightMargin: UM.Theme.getSize("default_margin").width
  83. wrapMode: Text.NoWrap
  84. height: contentHeight
  85. visible: !Cura.API.account.manualSyncEnabled && !Cura.API.account.updatePackagesEnabled
  86. }
  87. UM.Label
  88. {
  89. id: updatePackagesButton
  90. text: catalog.i18nc("@button", "Install pending updates")
  91. color: UM.Theme.getColor("text_link")
  92. font: UM.Theme.getFont("medium")
  93. height: contentHeight
  94. wrapMode: Text.NoWrap
  95. width: contentWidth + UM.Theme.getSize("default_margin").height
  96. visible: Cura.API.account.updatePackagesEnabled
  97. MouseArea
  98. {
  99. anchors.fill: parent
  100. onClicked: Cura.API.account.onUpdatePackagesClicked()
  101. hoverEnabled: true
  102. onEntered: updatePackagesButton.font.underline = true
  103. onExited: updatePackagesButton.font.underline = false
  104. }
  105. }
  106. UM.Label
  107. {
  108. id: accountSyncButton
  109. text: catalog.i18nc("@button", "Check for account updates")
  110. color: UM.Theme.getColor("text_link")
  111. font: UM.Theme.getFont("medium")
  112. wrapMode: Text.NoWrap
  113. height: contentHeight
  114. width: contentWidth + UM.Theme.getSize("default_margin").height
  115. visible: Cura.API.account.manualSyncEnabled
  116. MouseArea
  117. {
  118. anchors.fill: parent
  119. onClicked: Cura.API.account.sync(true)
  120. hoverEnabled: true
  121. onEntered: accountSyncButton.font.underline = true
  122. onExited: accountSyncButton.font.underline = false
  123. }
  124. }
  125. }
  126. }