FirmwareUpdaterMachineAction.qml 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. // Copyright (c) 2022 Ultimaker B.V.
  2. // Cura is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.2
  4. import QtQuick.Controls 2.1
  5. import QtQuick.Layouts 1.1
  6. import QtQuick.Window 2.1
  7. import QtQuick.Dialogs 1.2 // For filedialog
  8. import UM 1.5 as UM
  9. import Cura 1.0 as Cura
  10. Cura.MachineAction
  11. {
  12. anchors.fill: parent
  13. property bool printerConnected: Cura.MachineManager.printerConnected
  14. property var activeOutputDevice: printerConnected ? Cura.MachineManager.printerOutputDevices[0] : null
  15. property bool canUpdateFirmware: activeOutputDevice ? activeOutputDevice.activePrinter.canUpdateFirmware : false
  16. Column
  17. {
  18. id: firmwareUpdaterMachineAction
  19. anchors.fill: parent;
  20. UM.I18nCatalog { id: catalog; name: "cura"}
  21. spacing: UM.Theme.getSize("default_margin").height
  22. UM.Label
  23. {
  24. width: parent.width
  25. text: catalog.i18nc("@title", "Update Firmware")
  26. font.pointSize: 18
  27. }
  28. UM.Label
  29. {
  30. width: parent.width
  31. text: catalog.i18nc("@label", "Firmware is the piece of software running directly on your 3D printer. This firmware controls the step motors, regulates the temperature and ultimately makes your printer work.")
  32. }
  33. UM.Label
  34. {
  35. width: parent.width
  36. text: catalog.i18nc("@label", "The firmware shipping with new printers works, but new versions tend to have more features and improvements.")
  37. }
  38. Row
  39. {
  40. anchors.horizontalCenter: parent.horizontalCenter
  41. width: childrenRect.width
  42. spacing: UM.Theme.getSize("default_margin").width
  43. property string firmwareName: Cura.MachineManager.activeMachine.getDefaultFirmwareName()
  44. Cura.SecondaryButton
  45. {
  46. id: autoUpgradeButton
  47. text: catalog.i18nc("@action:button", "Automatically upgrade Firmware")
  48. enabled: parent.firmwareName != "" && canUpdateFirmware
  49. onClicked:
  50. {
  51. updateProgressDialog.visible = true;
  52. activeOutputDevice.updateFirmware(parent.firmwareName);
  53. }
  54. }
  55. Cura.SecondaryButton
  56. {
  57. id: manualUpgradeButton
  58. text: catalog.i18nc("@action:button", "Upload custom Firmware")
  59. enabled: canUpdateFirmware
  60. onClicked:
  61. {
  62. customFirmwareDialog.open()
  63. }
  64. }
  65. }
  66. UM.Label
  67. {
  68. width: parent.width
  69. visible: !printerConnected && !updateProgressDialog.visible
  70. text: catalog.i18nc("@label", "Firmware can not be updated because there is no connection with the printer.")
  71. }
  72. Label
  73. {
  74. width: parent.width
  75. visible: printerConnected && !canUpdateFirmware
  76. text: catalog.i18nc("@label", "Firmware can not be updated because the connection with the printer does not support upgrading firmware.")
  77. }
  78. }
  79. FileDialog
  80. {
  81. id: customFirmwareDialog
  82. title: catalog.i18nc("@title:window", "Select custom firmware")
  83. nameFilters: "Firmware image files (*.hex)"
  84. selectExisting: true
  85. onAccepted:
  86. {
  87. updateProgressDialog.visible = true;
  88. activeOutputDevice.updateFirmware(fileUrl);
  89. }
  90. }
  91. UM.Dialog
  92. {
  93. id: updateProgressDialog
  94. width: minimumWidth
  95. minimumWidth: 500 * screenScaleFactor
  96. height: minimumHeight
  97. minimumHeight: 100 * screenScaleFactor
  98. modality: Qt.ApplicationModal
  99. title: catalog.i18nc("@title:window","Firmware Update")
  100. Column
  101. {
  102. anchors.fill: parent
  103. UM.Label
  104. {
  105. anchors
  106. {
  107. left: parent.left
  108. right: parent.right
  109. }
  110. text: {
  111. if(manager.firmwareUpdater == null)
  112. {
  113. return "";
  114. }
  115. switch (manager.firmwareUpdater.firmwareUpdateState)
  116. {
  117. case 0:
  118. return ""; //Not doing anything (eg; idling)
  119. case 1:
  120. return catalog.i18nc("@label","Updating firmware.");
  121. case 2:
  122. return catalog.i18nc("@label","Firmware update completed.");
  123. case 3:
  124. return catalog.i18nc("@label","Firmware update failed due to an unknown error.");
  125. case 4:
  126. return catalog.i18nc("@label","Firmware update failed due to an communication error.");
  127. case 5:
  128. return catalog.i18nc("@label","Firmware update failed due to an input/output error.");
  129. case 6:
  130. return catalog.i18nc("@label","Firmware update failed due to missing firmware.");
  131. }
  132. }
  133. wrapMode: Text.Wrap
  134. }
  135. UM.ProgressBar
  136. {
  137. id: prog
  138. value: (manager.firmwareUpdater != null) ? manager.firmwareUpdater.firmwareProgress / 100 : 0
  139. indeterminate:
  140. {
  141. if(manager.firmwareUpdater == null)
  142. {
  143. return false;
  144. }
  145. return manager.firmwareUpdater.firmwareProgress < 1 && manager.firmwareUpdater.firmwareProgress > 0;
  146. }
  147. anchors
  148. {
  149. left: parent.left
  150. right: parent.right
  151. }
  152. }
  153. }
  154. rightButtons: [
  155. Cura.SecondaryButton
  156. {
  157. text: catalog.i18nc("@action:button", "Close")
  158. enabled: manager.firmwareUpdater != null ? manager.firmwareUpdater.firmwareUpdateState != 1 : true
  159. onClicked: updateProgressDialog.visible = false
  160. }
  161. ]
  162. }
  163. }