ToolboxDetailTileActions.qml 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. // Copyright (c) 2018 Ultimaker B.V.
  2. // Toolbox is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.10
  4. import QtQuick.Controls 1.4
  5. import QtQuick.Controls.Styles 1.4
  6. import UM 1.1 as UM
  7. import Cura 1.1 as Cura
  8. Column
  9. {
  10. property bool installed: toolbox.isInstalled(model.id)
  11. property bool canUpdate: CuraApplication.getPackageManager().packagesWithUpdate.indexOf(model.id) != -1
  12. property bool loginRequired: model.login_required && !Cura.API.account.isLoggedIn
  13. property var packageData
  14. width: UM.Theme.getSize("toolbox_action_button").width
  15. spacing: UM.Theme.getSize("narrow_margin").height
  16. Item
  17. {
  18. width: installButton.width
  19. height: installButton.height
  20. ToolboxProgressButton
  21. {
  22. id: installButton
  23. active: toolbox.isDownloading && toolbox.activePackage == model
  24. onReadyAction:
  25. {
  26. toolbox.activePackage = model
  27. toolbox.startDownload(model.download_url)
  28. }
  29. onActiveAction: toolbox.cancelDownload()
  30. // Don't allow installing while another download is running
  31. enabled: installed || (!(toolbox.isDownloading && toolbox.activePackage != model) && !loginRequired)
  32. opacity: enabled ? 1.0 : 0.5
  33. visible: !updateButton.visible && !installed // Don't show when the update button is visible
  34. }
  35. Cura.SecondaryButton
  36. {
  37. id: installedButton
  38. visible: installed
  39. onClicked: toolbox.viewCategory = "installed"
  40. text: catalog.i18nc("@action:button", "Installed")
  41. fixedWidthMode: true
  42. width: installButton.width
  43. height: installButton.height
  44. }
  45. }
  46. Label
  47. {
  48. wrapMode: Text.WordWrap
  49. text: catalog.i18nc("@label:The string between <a href=> and </a> is the highlighted link", "<a href='%1'>Log in</a> is required to install or update")
  50. font: UM.Theme.getFont("default")
  51. color: UM.Theme.getColor("text")
  52. linkColor: UM.Theme.getColor("text_link")
  53. visible: loginRequired
  54. width: installButton.width
  55. renderType: Text.NativeRendering
  56. MouseArea
  57. {
  58. anchors.fill: parent
  59. onClicked: Cura.API.account.login()
  60. }
  61. }
  62. Label
  63. {
  64. property var whereToBuyUrl:
  65. {
  66. var pg_name = "whereToBuy"
  67. return (pg_name in packageData.links) ? packageData.links[pg_name] : undefined
  68. }
  69. renderType: Text.NativeRendering
  70. text: catalog.i18nc("@label:The string between <a href=> and </a> is the highlighted link", "<a href='%1'>Buy material spools</a>")
  71. linkColor: UM.Theme.getColor("text_link")
  72. visible: whereToBuyUrl != undefined
  73. font: UM.Theme.getFont("default")
  74. color: UM.Theme.getColor("text")
  75. MouseArea
  76. {
  77. anchors.fill: parent
  78. onClicked: Qt.openUrlExternally(parent.whereToBuyUrl)
  79. }
  80. }
  81. ToolboxProgressButton
  82. {
  83. id: updateButton
  84. active: toolbox.isDownloading && toolbox.activePackage == model
  85. readyLabel: catalog.i18nc("@action:button", "Update")
  86. activeLabel: catalog.i18nc("@action:button", "Updating")
  87. completeLabel: catalog.i18nc("@action:button", "Updated")
  88. onReadyAction:
  89. {
  90. toolbox.activePackage = model
  91. toolbox.update(model.id)
  92. }
  93. onActiveAction: toolbox.cancelDownload()
  94. // Don't allow installing while another download is running
  95. enabled: !(toolbox.isDownloading && toolbox.activePackage != model) && !loginRequired
  96. opacity: enabled ? 1.0 : 0.5
  97. visible: canUpdate
  98. }
  99. Connections
  100. {
  101. target: toolbox
  102. onInstallChanged: installed = toolbox.isInstalled(model.id)
  103. onFilterChanged:
  104. {
  105. installed = toolbox.isInstalled(model.id)
  106. }
  107. }
  108. }