ToolboxDetailTileActions.qml 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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: toolbox.canUpdate(model.id)
  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. visible: installed
  38. onClicked: toolbox.viewCategory = "installed"
  39. text: catalog.i18nc("@action:button", "Installed")
  40. fixedWidthMode: true
  41. width: installButton.width
  42. height: installButton.height
  43. }
  44. }
  45. Label
  46. {
  47. wrapMode: Text.WordWrap
  48. 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")
  49. font: UM.Theme.getFont("default")
  50. color: UM.Theme.getColor("text")
  51. linkColor: UM.Theme.getColor("text_link")
  52. visible: loginRequired
  53. width: installButton.width
  54. renderType: Text.NativeRendering
  55. MouseArea
  56. {
  57. anchors.fill: parent
  58. onClicked: Cura.API.account.login()
  59. }
  60. }
  61. Label
  62. {
  63. property var whereToBuyUrl:
  64. {
  65. var pg_name = "whereToBuy"
  66. return (pg_name in packageData.links) ? packageData.links[pg_name] : undefined
  67. }
  68. renderType: Text.NativeRendering
  69. text: catalog.i18nc("@label:The string between <a href=> and </a> is the highlighted link", "<a href='%1'>Buy material spools</a>")
  70. linkColor: UM.Theme.getColor("text_link")
  71. visible: whereToBuyUrl != undefined
  72. font: UM.Theme.getFont("default")
  73. color: UM.Theme.getColor("text")
  74. MouseArea
  75. {
  76. anchors.fill: parent
  77. onClicked: Qt.openUrlExternally(parent.whereToBuyUrl)
  78. }
  79. }
  80. ToolboxProgressButton
  81. {
  82. id: updateButton
  83. active: toolbox.isDownloading && toolbox.activePackage == model
  84. readyLabel: catalog.i18nc("@action:button", "Update")
  85. activeLabel: catalog.i18nc("@action:button", "Updating")
  86. completeLabel: catalog.i18nc("@action:button", "Updated")
  87. onReadyAction:
  88. {
  89. toolbox.activePackage = model
  90. toolbox.update(model.id)
  91. }
  92. onActiveAction: toolbox.cancelDownload()
  93. // Don't allow installing while another download is running
  94. enabled: !(toolbox.isDownloading && toolbox.activePackage != model) && !loginRequired
  95. opacity: enabled ? 1.0 : 0.5
  96. visible: canUpdate
  97. }
  98. Connections
  99. {
  100. target: toolbox
  101. onInstallChanged: installed = toolbox.isInstalled(model.id)
  102. onMetadataChanged: canUpdate = toolbox.canUpdate(model.id)
  103. onFilterChanged:
  104. {
  105. installed = toolbox.isInstalled(model.id)
  106. canUpdate = toolbox.canUpdate(model.id)
  107. }
  108. }
  109. }