FirmwareUpdaterMachineAction.qml 6.4 KB

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