DependenciesInstaller.qml 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import QtQuick 2.0
  2. import QtQuick.Controls 2.15
  3. Item {
  4. signal dependenciesInstalled()
  5. signal dependenciesInstallCanceled()
  6. signal dependenciesInstallError()
  7. Script {
  8. id: script
  9. readonly property int modeCheck: 0
  10. readonly property int modeInstall: 1
  11. property int mode: modeCheck
  12. onFinished: {
  13. console.log(`DEP Script finished with code: ${code}`)
  14. switch (mode) {
  15. case modeCheck:
  16. onCheckFinished(code, output)
  17. break
  18. case modeInstall:
  19. ui.log(output)
  20. onInstallFinished(code)
  21. break
  22. }
  23. }
  24. function onCheckFinished(code, output) {
  25. if (code === 127) {
  26. // script not found
  27. ui.log(qsTr("Failed to execute dependencies script"))
  28. dependenciesInstallError()
  29. } else if (code !== 0) {
  30. ui.log(qsTr("Dependencies missing:") + " " + output)
  31. textDialog.text = qsTr("Some required dependencies are missing:") + " <b>"
  32. + output + "</b> .<br/>"
  33. + qsTr("Click OK to try installing them automatically, or Cancel to install them manually")
  34. dialog.open()
  35. } else {
  36. dependenciesInstalled()
  37. }
  38. }
  39. function onInstallFinished(code) {
  40. if (code !== 0) {
  41. dependenciesInstallError()
  42. } else {
  43. dependenciesInstalled()
  44. }
  45. }
  46. function install() {
  47. ui.log(qsTr("Installing dependencies..."))
  48. mode = modeInstall
  49. script.execScript("deps", "install")
  50. }
  51. }
  52. Dialog {
  53. id: dialog
  54. anchors.centerIn: parent
  55. title: window.title
  56. modal: true
  57. focus: true
  58. standardButtons: Dialog.Ok | Dialog.Cancel
  59. TextArea {
  60. id: textDialog
  61. readOnly: true
  62. selectByMouse: true
  63. wrapMode: Text.WordWrap
  64. anchors.fill: parent
  65. implicitWidth: block * 8
  66. textFormat: "RichText"
  67. }
  68. onAccepted: script.install()
  69. onRejected: dependenciesInstallCanceled()
  70. }
  71. function check() {
  72. script.mode = script.modeCheck
  73. script.execScript("deps", "check")
  74. }
  75. }