PluginBrowser.qml 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. import UM 1.1 as UM
  2. import QtQuick 2.2
  3. import QtQuick.Dialogs 1.1
  4. import QtQuick.Window 2.2
  5. import QtQuick.Controls 1.1
  6. UM.Dialog
  7. {
  8. id: base
  9. title: catalog.i18nc("@title:window", "Find & Update plugins")
  10. width: 600 * screenScaleFactor
  11. height: 450 * screenScaleFactor
  12. minimumWidth: 350 * screenScaleFactor
  13. minimumHeight: 350 * screenScaleFactor
  14. Item
  15. {
  16. anchors.fill: parent
  17. Item
  18. {
  19. id: topBar
  20. height: childrenRect.height;
  21. width: parent.width
  22. Label
  23. {
  24. id: introText
  25. text: catalog.i18nc("@label", "Here you can find a list of Third Party plugins.")
  26. width: parent.width
  27. height: 30
  28. }
  29. Button
  30. {
  31. id: refresh
  32. text: catalog.i18nc("@action:button", "Refresh")
  33. onClicked: manager.requestPluginList()
  34. anchors.right: parent.right
  35. enabled: !manager.isDownloading
  36. }
  37. }
  38. ScrollView
  39. {
  40. width: parent.width
  41. anchors.top: topBar.bottom
  42. anchors.bottom: bottomBar.top
  43. anchors.bottomMargin: UM.Theme.getSize("default_margin").height
  44. frameVisible: true
  45. ListView
  46. {
  47. id: pluginList
  48. model: manager.pluginsModel
  49. anchors.fill: parent
  50. property var activePlugin
  51. delegate: pluginDelegate
  52. }
  53. }
  54. Item
  55. {
  56. id: bottomBar
  57. width: parent.width
  58. height: closeButton.height
  59. anchors.bottom: parent.bottom
  60. anchors.left: parent.left
  61. ProgressBar
  62. {
  63. id: progressbar
  64. anchors.bottom: parent.bottom
  65. minimumValue: 0;
  66. maximumValue: 100
  67. anchors.left:parent.left
  68. anchors.right: closeButton.left
  69. anchors.rightMargin: UM.Theme.getSize("default_margin").width
  70. value: manager.isDownloading ? manager.downloadProgress : 0
  71. }
  72. Button
  73. {
  74. id: closeButton
  75. text: catalog.i18nc("@action:button", "Close")
  76. iconName: "dialog-close"
  77. onClicked:
  78. {
  79. if (manager.isDownloading)
  80. {
  81. manager.cancelDownload()
  82. }
  83. base.close();
  84. }
  85. anchors.bottom: parent.bottom
  86. anchors.right: parent.right
  87. }
  88. }
  89. Item
  90. {
  91. SystemPalette { id: palette }
  92. Component
  93. {
  94. id: pluginDelegate
  95. Rectangle
  96. {
  97. width: pluginList.width;
  98. height: texts.height;
  99. color: index % 2 ? palette.base : palette.alternateBase
  100. Column
  101. {
  102. id: texts
  103. width: parent.width
  104. height: childrenRect.height
  105. anchors.left: parent.left
  106. anchors.leftMargin: UM.Theme.getSize("default_margin").width
  107. anchors.right: downloadButton.left
  108. anchors.rightMargin: UM.Theme.getSize("default_margin").width
  109. Label
  110. {
  111. text: "<b>" + model.name + "</b> - " + model.author
  112. width: contentWidth
  113. height: contentHeight + UM.Theme.getSize("default_margin").height
  114. verticalAlignment: Text.AlignVCenter
  115. }
  116. Label
  117. {
  118. text: model.short_description
  119. width: parent.width
  120. height: contentHeight + UM.Theme.getSize("default_margin").height
  121. wrapMode: Text.WordWrap
  122. verticalAlignment: Text.AlignVCenter
  123. }
  124. }
  125. Button
  126. {
  127. id: downloadButton
  128. text:
  129. {
  130. if (manager.isDownloading && pluginList.activePlugin == model)
  131. {
  132. return catalog.i18nc("@action:button", "Cancel");
  133. }
  134. else if (model.already_installed)
  135. {
  136. if (model.can_upgrade)
  137. {
  138. return catalog.i18nc("@action:button", "Upgrade");
  139. }
  140. return catalog.i18nc("@action:button", "Installed");
  141. }
  142. return catalog.i18nc("@action:button", "Download");
  143. }
  144. onClicked:
  145. {
  146. if(!manager.isDownloading)
  147. {
  148. pluginList.activePlugin = model;
  149. manager.downloadAndInstallPlugin(model.file_location);
  150. }
  151. else
  152. {
  153. manager.cancelDownload();
  154. }
  155. }
  156. anchors.right: parent.right
  157. anchors.rightMargin: UM.Theme.getSize("default_margin").width
  158. anchors.verticalCenter: parent.verticalCenter
  159. enabled:
  160. {
  161. if (manager.isDownloading)
  162. {
  163. return (pluginList.activePlugin == model);
  164. }
  165. else
  166. {
  167. return (!model.already_installed || model.can_upgrade);
  168. }
  169. }
  170. }
  171. }
  172. }
  173. }
  174. UM.I18nCatalog { id: catalog; name: "cura" }
  175. Connections
  176. {
  177. target: manager
  178. onShowLicenseDialog:
  179. {
  180. licenseDialog.pluginName = manager.getLicenseDialogPluginName();
  181. licenseDialog.licenseContent = manager.getLicenseDialogLicenseContent();
  182. licenseDialog.pluginFileLocation = manager.getLicenseDialogPluginFileLocation();
  183. licenseDialog.show();
  184. }
  185. }
  186. UM.Dialog
  187. {
  188. id: licenseDialog
  189. title: catalog.i18nc("@title:window", "Plugin License Agreement")
  190. minimumWidth: UM.Theme.getSize("license_window_minimum").width
  191. minimumHeight: UM.Theme.getSize("license_window_minimum").height
  192. width: minimumWidth
  193. height: minimumHeight
  194. property var pluginName;
  195. property var licenseContent;
  196. property var pluginFileLocation;
  197. Item
  198. {
  199. anchors.fill: parent
  200. Label
  201. {
  202. id: licenseTitle
  203. anchors.top: parent.top
  204. anchors.left: parent.left
  205. anchors.right: parent.right
  206. text: licenseDialog.pluginName + catalog.i18nc("@label", " plugin contains a license.\nYou need to accept this license to install this plugin.\nDo you agree with the terms below?")
  207. wrapMode: Text.Wrap
  208. }
  209. TextArea
  210. {
  211. id: licenseText
  212. anchors.top: licenseTitle.bottom
  213. anchors.bottom: parent.bottom
  214. anchors.left: parent.left
  215. anchors.right: parent.right
  216. anchors.topMargin: UM.Theme.getSize("default_margin").height
  217. readOnly: true
  218. text: licenseDialog.licenseContent != null ? licenseDialog.licenseContent : ""
  219. }
  220. }
  221. rightButtons: [
  222. Button
  223. {
  224. id: acceptButton
  225. anchors.margins: UM.Theme.getSize("default_margin").width
  226. text: catalog.i18nc("@action:button", "Accept")
  227. onClicked:
  228. {
  229. licenseDialog.close();
  230. manager.installPlugin(licenseDialog.pluginFileLocation);
  231. }
  232. },
  233. Button
  234. {
  235. id: declineButton
  236. anchors.margins: UM.Theme.getSize("default_margin").width
  237. text: catalog.i18nc("@action:button", "Decline")
  238. onClicked:
  239. {
  240. licenseDialog.close();
  241. }
  242. }
  243. ]
  244. }
  245. }
  246. }