PluginEntry.qml 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486
  1. // Copyright (c) 2018 Ultimaker B.V.
  2. // PluginBrowser is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.2
  4. import QtQuick.Dialogs 1.1
  5. import QtQuick.Window 2.2
  6. import QtQuick.Controls 1.4
  7. import QtQuick.Controls.Styles 1.4
  8. // TODO: Switch to QtQuick.Controls 2.x and remove QtQuick.Controls.Styles
  9. import UM 1.1 as UM
  10. Component {
  11. id: pluginDelegate
  12. Rectangle {
  13. // Don't show required plugins as they can't be managed anyway:
  14. height: !model.required ? 84 : 0
  15. visible: !model.required ? true : false
  16. color: "transparent"
  17. anchors {
  18. left: parent.left
  19. leftMargin: UM.Theme.getSize("default_margin").width
  20. right: parent.right
  21. rightMargin: UM.Theme.getSize("default_margin").width
  22. }
  23. // Bottom border:
  24. Rectangle {
  25. color: UM.Theme.getColor("lining")
  26. width: parent.width
  27. height: 1
  28. anchors.bottom: parent.bottom
  29. }
  30. // Plugin info
  31. Column {
  32. id: pluginInfo
  33. property var color: model.enabled ? UM.Theme.getColor("text") : UM.Theme.getColor("lining")
  34. // Styling:
  35. height: parent.height
  36. anchors {
  37. left: parent.left
  38. top: parent.top
  39. topMargin: UM.Theme.getSize("default_margin").height
  40. right: authorInfo.left
  41. rightMargin: UM.Theme.getSize("default_margin").width
  42. }
  43. Label {
  44. text: model.name
  45. width: parent.width
  46. height: 24
  47. wrapMode: Text.WordWrap
  48. verticalAlignment: Text.AlignVCenter
  49. font {
  50. pixelSize: 13
  51. bold: true
  52. }
  53. color: pluginInfo.color
  54. }
  55. Text {
  56. text: model.description
  57. width: parent.width
  58. height: 36
  59. clip: true
  60. wrapMode: Text.WordWrap
  61. color: pluginInfo.color
  62. elide: Text.ElideRight
  63. }
  64. }
  65. // Author info
  66. Column {
  67. id: authorInfo
  68. width: 192
  69. height: parent.height
  70. anchors {
  71. top: parent.top
  72. topMargin: UM.Theme.getSize("default_margin").height
  73. right: pluginActions.left
  74. rightMargin: UM.Theme.getSize("default_margin").width
  75. }
  76. Label {
  77. text: "<a href=\"mailto:"+model.author_email+"?Subject=Cura: "+model.name+"\">"+model.author+"</a>"
  78. width: parent.width
  79. height: 24
  80. wrapMode: Text.WordWrap
  81. verticalAlignment: Text.AlignVCenter
  82. horizontalAlignment: Text.AlignLeft
  83. onLinkActivated: Qt.openUrlExternally("mailto:"+model.author_email+"?Subject=Cura: "+model.name+" Plugin")
  84. color: model.enabled ? UM.Theme.getColor("text") : UM.Theme.getColor("lining")
  85. }
  86. }
  87. // Plugin actions
  88. Row {
  89. id: pluginActions
  90. width: 96
  91. height: parent.height
  92. anchors {
  93. top: parent.top
  94. right: parent.right
  95. topMargin: UM.Theme.getSize("default_margin").height
  96. }
  97. layoutDirection: Qt.RightToLeft
  98. spacing: UM.Theme.getSize("default_margin").width
  99. // For 3rd-Party Plugins:
  100. Button {
  101. id: installButton
  102. text: {
  103. if ( manager.isDownloading && pluginList.activePlugin == model ) {
  104. return catalog.i18nc( "@action:button", "Cancel" );
  105. } else {
  106. if (model.can_upgrade) {
  107. return catalog.i18nc("@action:button", "Update");
  108. }
  109. return catalog.i18nc("@action:button", "Install");
  110. }
  111. }
  112. enabled:
  113. {
  114. if ( manager.isDownloading )
  115. {
  116. return pluginList.activePlugin == model ? true : false
  117. }
  118. else
  119. {
  120. return true
  121. }
  122. }
  123. opacity: enabled ? 1.0 : 0.5
  124. visible: model.external && ((model.status !== "installed") || model.can_upgrade)
  125. style: ButtonStyle {
  126. background: Rectangle {
  127. implicitWidth: 96
  128. implicitHeight: 30
  129. color: "transparent"
  130. border {
  131. width: 1
  132. color: UM.Theme.getColor("lining")
  133. }
  134. }
  135. label: Label {
  136. text: control.text
  137. color: UM.Theme.getColor("text")
  138. verticalAlignment: Text.AlignVCenter
  139. horizontalAlignment: Text.AlignHCenter
  140. }
  141. }
  142. onClicked: {
  143. if ( manager.isDownloading && pluginList.activePlugin == model ) {
  144. manager.cancelDownload();
  145. } else {
  146. pluginList.activePlugin = model;
  147. if ( model.can_upgrade ) {
  148. manager.downloadAndInstallPlugin( model.update_url );
  149. } else {
  150. manager.downloadAndInstallPlugin( model.file_location );
  151. }
  152. }
  153. }
  154. }
  155. Button {
  156. id: removeButton
  157. text: "Uninstall"
  158. visible: model.can_uninstall && model.status == "installed"
  159. enabled: !manager.isDownloading
  160. style: ButtonStyle {
  161. background: Rectangle {
  162. implicitWidth: 96
  163. implicitHeight: 30
  164. color: "transparent"
  165. border {
  166. width: 1
  167. color: UM.Theme.getColor("lining")
  168. }
  169. }
  170. label: Text {
  171. text: control.text
  172. color: UM.Theme.getColor("text")
  173. verticalAlignment: Text.AlignVCenter
  174. horizontalAlignment: Text.AlignHCenter
  175. }
  176. }
  177. onClicked: manager.removePlugin( model.id )
  178. }
  179. // For Ultimaker Plugins:
  180. Button {
  181. id: enableButton
  182. text: "Enable"
  183. visible: !model.external && model.enabled == false
  184. style: ButtonStyle {
  185. background: Rectangle {
  186. implicitWidth: 96
  187. implicitHeight: 30
  188. color: "transparent"
  189. border {
  190. width: 1
  191. color: UM.Theme.getColor("lining")
  192. }
  193. }
  194. label: Text {
  195. text: control.text
  196. color: UM.Theme.getColor("text")
  197. verticalAlignment: Text.AlignVCenter
  198. horizontalAlignment: Text.AlignHCenter
  199. }
  200. }
  201. onClicked: {
  202. manager.enablePlugin(model.id);
  203. }
  204. }
  205. Button {
  206. id: disableButton
  207. text: "Disable"
  208. visible: !model.external && model.enabled == true
  209. style: ButtonStyle {
  210. background: Rectangle {
  211. implicitWidth: 96
  212. implicitHeight: 30
  213. color: "transparent"
  214. border {
  215. width: 1
  216. color: UM.Theme.getColor("lining")
  217. }
  218. }
  219. label: Text {
  220. text: control.text
  221. color: UM.Theme.getColor("text")
  222. verticalAlignment: Text.AlignVCenter
  223. horizontalAlignment: Text.AlignHCenter
  224. }
  225. }
  226. onClicked: {
  227. manager.disablePlugin(model.id);
  228. }
  229. }
  230. /*
  231. Rectangle {
  232. id: removeControls
  233. visible: model.status == "installed" && model.enabled
  234. width: 96
  235. height: 30
  236. color: "transparent"
  237. Button {
  238. id: removeButton
  239. text: "Disable"
  240. enabled: {
  241. if ( manager.isDownloading && pluginList.activePlugin == model ) {
  242. return false;
  243. } else if ( model.required ) {
  244. return false;
  245. } else {
  246. return true;
  247. }
  248. }
  249. onClicked: {
  250. manager.disablePlugin(model.id);
  251. }
  252. style: ButtonStyle {
  253. background: Rectangle {
  254. color: "white"
  255. implicitWidth: 96
  256. implicitHeight: 30
  257. border {
  258. width: 1
  259. color: UM.Theme.getColor("lining")
  260. }
  261. }
  262. label: Text {
  263. verticalAlignment: Text.AlignVCenter
  264. color: "grey"
  265. text: control.text
  266. horizontalAlignment: Text.AlignLeft
  267. }
  268. }
  269. }
  270. Button {
  271. id: removeDropDown
  272. property bool open: false
  273. UM.RecolorImage {
  274. anchors.centerIn: parent
  275. height: 10
  276. width: 10
  277. source: UM.Theme.getIcon("arrow_bottom")
  278. color: "grey"
  279. }
  280. enabled: {
  281. if ( manager.isDownloading && pluginList.activePlugin == model ) {
  282. return false;
  283. } else if ( model.required ) {
  284. return false;
  285. } else {
  286. return true;
  287. }
  288. }
  289. anchors.right: parent.right
  290. style: ButtonStyle {
  291. background: Rectangle {
  292. color: "transparent"
  293. implicitWidth: 30
  294. implicitHeight: 30
  295. }
  296. label: Text {
  297. verticalAlignment: Text.AlignVCenter
  298. color: "grey"
  299. text: control.text
  300. horizontalAlignment: Text.AlignHCenter
  301. }
  302. }
  303. // For the disable option:
  304. // onClicked: pluginList.model.setEnabled(model.id, checked)
  305. onClicked: {
  306. if ( !removeDropDown.open ) {
  307. removeDropDown.open = true
  308. }
  309. else {
  310. removeDropDown.open = false
  311. }
  312. }
  313. }
  314. Rectangle {
  315. id: divider
  316. width: 1
  317. height: parent.height
  318. anchors.right: removeDropDown.left
  319. color: UM.Theme.getColor("lining")
  320. }
  321. Column {
  322. id: options
  323. anchors {
  324. top: removeButton.bottom
  325. left: parent.left
  326. right: parent.right
  327. }
  328. height: childrenRect.height
  329. visible: removeDropDown.open
  330. Button {
  331. id: disableButton
  332. text: "Remove"
  333. height: 30
  334. width: parent.width
  335. onClicked: {
  336. removeDropDown.open = false;
  337. manager.removePlugin( model.id );
  338. }
  339. }
  340. }
  341. }
  342. */
  343. /*
  344. Button {
  345. id: enableButton
  346. visible: !model.enabled && model.status == "installed"
  347. onClicked: manager.enablePlugin( model.id );
  348. text: "Enable"
  349. style: ButtonStyle {
  350. background: Rectangle {
  351. color: "transparent"
  352. implicitWidth: 96
  353. implicitHeight: 30
  354. border {
  355. width: 1
  356. color: UM.Theme.getColor("lining")
  357. }
  358. }
  359. label: Text {
  360. verticalAlignment: Text.AlignVCenter
  361. color: UM.Theme.getColor("text")
  362. text: control.text
  363. horizontalAlignment: Text.AlignHCenter
  364. }
  365. }
  366. }
  367. Button {
  368. id: updateButton
  369. visible: model.status == "installed" && model.can_upgrade && model.enabled
  370. // visible: model.already_installed
  371. text: {
  372. // If currently downloading:
  373. if ( manager.isDownloading && pluginList.activePlugin == model ) {
  374. return catalog.i18nc( "@action:button", "Cancel" );
  375. } else {
  376. return catalog.i18nc("@action:button", "Update");
  377. }
  378. }
  379. style: ButtonStyle {
  380. background: Rectangle {
  381. color: UM.Theme.getColor("primary")
  382. implicitWidth: 96
  383. implicitHeight: 30
  384. // radius: 4
  385. }
  386. label: Text {
  387. verticalAlignment: Text.AlignVCenter
  388. color: "white"
  389. text: control.text
  390. horizontalAlignment: Text.AlignHCenter
  391. }
  392. }
  393. }
  394. Button {
  395. id: externalControls
  396. visible: model.status == "available" ? true : false
  397. text: {
  398. // If currently downloading:
  399. if ( manager.isDownloading && pluginList.activePlugin == model ) {
  400. return catalog.i18nc( "@action:button", "Cancel" );
  401. } else {
  402. return catalog.i18nc("@action:button", "Install");
  403. }
  404. }
  405. onClicked: {
  406. if ( manager.isDownloading && pluginList.activePlugin == model ) {
  407. manager.cancelDownload();
  408. } else {
  409. pluginList.activePlugin = model;
  410. manager.downloadAndInstallPlugin( model.file_location );
  411. }
  412. }
  413. style: ButtonStyle {
  414. background: Rectangle {
  415. color: "transparent"
  416. implicitWidth: 96
  417. implicitHeight: 30
  418. border {
  419. width: 1
  420. color: UM.Theme.getColor("lining")
  421. }
  422. }
  423. label: Text {
  424. verticalAlignment: Text.AlignVCenter
  425. color: "grey"
  426. text: control.text
  427. horizontalAlignment: Text.AlignHCenter
  428. }
  429. }
  430. }
  431. */
  432. ProgressBar {
  433. id: progressbar
  434. minimumValue: 0;
  435. maximumValue: 100
  436. anchors.left: installButton.left
  437. anchors.right: installButton.right
  438. anchors.top: installButton.bottom
  439. anchors.topMargin: 4
  440. value: manager.isDownloading ? manager.downloadProgress : 0
  441. visible: manager.isDownloading && pluginList.activePlugin == model
  442. style: ProgressBarStyle {
  443. background: Rectangle {
  444. color: "lightgray"
  445. implicitHeight: 6
  446. }
  447. progress: Rectangle {
  448. color: UM.Theme.getColor("primary")
  449. }
  450. }
  451. }
  452. }
  453. }
  454. }