PluginEntry.qml 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474
  1. // Copyright (c) 2017 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. visible: model.external && ((model.status !== "installed") || model.can_upgrade)
  113. style: ButtonStyle {
  114. background: Rectangle {
  115. implicitWidth: 96
  116. implicitHeight: 30
  117. color: "transparent"
  118. border {
  119. width: 1
  120. color: UM.Theme.getColor("lining")
  121. }
  122. }
  123. label: Label {
  124. text: control.text
  125. color: UM.Theme.getColor("text")
  126. verticalAlignment: Text.AlignVCenter
  127. horizontalAlignment: Text.AlignHCenter
  128. }
  129. }
  130. onClicked: {
  131. if ( manager.isDownloading && pluginList.activePlugin == model ) {
  132. manager.cancelDownload();
  133. } else {
  134. pluginList.activePlugin = model;
  135. if ( model.can_upgrade ) {
  136. manager.downloadAndInstallPlugin( model.update_url );
  137. } else {
  138. manager.downloadAndInstallPlugin( model.file_location );
  139. }
  140. }
  141. }
  142. }
  143. Button {
  144. id: removeButton
  145. text: "Uninstall"
  146. visible: model.can_uninstall && model.status == "installed"
  147. enabled: !manager.isDownloading
  148. style: ButtonStyle {
  149. background: Rectangle {
  150. implicitWidth: 96
  151. implicitHeight: 30
  152. color: "transparent"
  153. border {
  154. width: 1
  155. color: UM.Theme.getColor("lining")
  156. }
  157. }
  158. label: Text {
  159. text: control.text
  160. color: UM.Theme.getColor("text")
  161. verticalAlignment: Text.AlignVCenter
  162. horizontalAlignment: Text.AlignHCenter
  163. }
  164. }
  165. onClicked: manager.removePlugin( model.id )
  166. }
  167. // For Ultimaker Plugins:
  168. Button {
  169. id: enableButton
  170. text: "Enable"
  171. visible: !model.external && model.enabled == false
  172. style: ButtonStyle {
  173. background: Rectangle {
  174. implicitWidth: 96
  175. implicitHeight: 30
  176. color: "transparent"
  177. border {
  178. width: 1
  179. color: UM.Theme.getColor("lining")
  180. }
  181. }
  182. label: Text {
  183. text: control.text
  184. color: UM.Theme.getColor("text")
  185. verticalAlignment: Text.AlignVCenter
  186. horizontalAlignment: Text.AlignHCenter
  187. }
  188. }
  189. onClicked: {
  190. manager.enablePlugin(model.id);
  191. }
  192. }
  193. Button {
  194. id: disableButton
  195. text: "Disable"
  196. visible: !model.external && model.enabled == true
  197. style: ButtonStyle {
  198. background: Rectangle {
  199. implicitWidth: 96
  200. implicitHeight: 30
  201. color: "transparent"
  202. border {
  203. width: 1
  204. color: UM.Theme.getColor("lining")
  205. }
  206. }
  207. label: Text {
  208. text: control.text
  209. color: UM.Theme.getColor("text")
  210. verticalAlignment: Text.AlignVCenter
  211. horizontalAlignment: Text.AlignHCenter
  212. }
  213. }
  214. onClicked: {
  215. manager.disablePlugin(model.id);
  216. }
  217. }
  218. /*
  219. Rectangle {
  220. id: removeControls
  221. visible: model.status == "installed" && model.enabled
  222. width: 96
  223. height: 30
  224. color: "transparent"
  225. Button {
  226. id: removeButton
  227. text: "Disable"
  228. enabled: {
  229. if ( manager.isDownloading && pluginList.activePlugin == model ) {
  230. return false;
  231. } else if ( model.required ) {
  232. return false;
  233. } else {
  234. return true;
  235. }
  236. }
  237. onClicked: {
  238. manager.disablePlugin(model.id);
  239. }
  240. style: ButtonStyle {
  241. background: Rectangle {
  242. color: "white"
  243. implicitWidth: 96
  244. implicitHeight: 30
  245. border {
  246. width: 1
  247. color: UM.Theme.getColor("lining")
  248. }
  249. }
  250. label: Text {
  251. verticalAlignment: Text.AlignVCenter
  252. color: "grey"
  253. text: control.text
  254. horizontalAlignment: Text.AlignLeft
  255. }
  256. }
  257. }
  258. Button {
  259. id: removeDropDown
  260. property bool open: false
  261. UM.RecolorImage {
  262. anchors.centerIn: parent
  263. height: 10
  264. width: 10
  265. source: UM.Theme.getIcon("arrow_bottom")
  266. color: "grey"
  267. }
  268. enabled: {
  269. if ( manager.isDownloading && pluginList.activePlugin == model ) {
  270. return false;
  271. } else if ( model.required ) {
  272. return false;
  273. } else {
  274. return true;
  275. }
  276. }
  277. anchors.right: parent.right
  278. style: ButtonStyle {
  279. background: Rectangle {
  280. color: "transparent"
  281. implicitWidth: 30
  282. implicitHeight: 30
  283. }
  284. label: Text {
  285. verticalAlignment: Text.AlignVCenter
  286. color: "grey"
  287. text: control.text
  288. horizontalAlignment: Text.AlignHCenter
  289. }
  290. }
  291. // For the disable option:
  292. // onClicked: pluginList.model.setEnabled(model.id, checked)
  293. onClicked: {
  294. if ( !removeDropDown.open ) {
  295. removeDropDown.open = true
  296. }
  297. else {
  298. removeDropDown.open = false
  299. }
  300. }
  301. }
  302. Rectangle {
  303. id: divider
  304. width: 1
  305. height: parent.height
  306. anchors.right: removeDropDown.left
  307. color: UM.Theme.getColor("lining")
  308. }
  309. Column {
  310. id: options
  311. anchors {
  312. top: removeButton.bottom
  313. left: parent.left
  314. right: parent.right
  315. }
  316. height: childrenRect.height
  317. visible: removeDropDown.open
  318. Button {
  319. id: disableButton
  320. text: "Remove"
  321. height: 30
  322. width: parent.width
  323. onClicked: {
  324. removeDropDown.open = false;
  325. manager.removePlugin( model.id );
  326. }
  327. }
  328. }
  329. }
  330. */
  331. /*
  332. Button {
  333. id: enableButton
  334. visible: !model.enabled && model.status == "installed"
  335. onClicked: manager.enablePlugin( model.id );
  336. text: "Enable"
  337. style: ButtonStyle {
  338. background: Rectangle {
  339. color: "transparent"
  340. implicitWidth: 96
  341. implicitHeight: 30
  342. border {
  343. width: 1
  344. color: UM.Theme.getColor("lining")
  345. }
  346. }
  347. label: Text {
  348. verticalAlignment: Text.AlignVCenter
  349. color: UM.Theme.getColor("text")
  350. text: control.text
  351. horizontalAlignment: Text.AlignHCenter
  352. }
  353. }
  354. }
  355. Button {
  356. id: updateButton
  357. visible: model.status == "installed" && model.can_upgrade && model.enabled
  358. // visible: model.already_installed
  359. text: {
  360. // If currently downloading:
  361. if ( manager.isDownloading && pluginList.activePlugin == model ) {
  362. return catalog.i18nc( "@action:button", "Cancel" );
  363. } else {
  364. return catalog.i18nc("@action:button", "Update");
  365. }
  366. }
  367. style: ButtonStyle {
  368. background: Rectangle {
  369. color: UM.Theme.getColor("primary")
  370. implicitWidth: 96
  371. implicitHeight: 30
  372. // radius: 4
  373. }
  374. label: Text {
  375. verticalAlignment: Text.AlignVCenter
  376. color: "white"
  377. text: control.text
  378. horizontalAlignment: Text.AlignHCenter
  379. }
  380. }
  381. }
  382. Button {
  383. id: externalControls
  384. visible: model.status == "available" ? true : false
  385. text: {
  386. // If currently downloading:
  387. if ( manager.isDownloading && pluginList.activePlugin == model ) {
  388. return catalog.i18nc( "@action:button", "Cancel" );
  389. } else {
  390. return catalog.i18nc("@action:button", "Install");
  391. }
  392. }
  393. onClicked: {
  394. if ( manager.isDownloading && pluginList.activePlugin == model ) {
  395. manager.cancelDownload();
  396. } else {
  397. pluginList.activePlugin = model;
  398. manager.downloadAndInstallPlugin( model.file_location );
  399. }
  400. }
  401. style: ButtonStyle {
  402. background: Rectangle {
  403. color: "transparent"
  404. implicitWidth: 96
  405. implicitHeight: 30
  406. border {
  407. width: 1
  408. color: UM.Theme.getColor("lining")
  409. }
  410. }
  411. label: Text {
  412. verticalAlignment: Text.AlignVCenter
  413. color: "grey"
  414. text: control.text
  415. horizontalAlignment: Text.AlignHCenter
  416. }
  417. }
  418. }
  419. */
  420. ProgressBar {
  421. id: progressbar
  422. minimumValue: 0;
  423. maximumValue: 100
  424. anchors.left: installButton.left
  425. anchors.right: installButton.right
  426. anchors.top: installButton.bottom
  427. anchors.topMargin: 4
  428. value: manager.isDownloading ? manager.downloadProgress : 0
  429. visible: manager.isDownloading && pluginList.activePlugin == model
  430. style: ProgressBarStyle {
  431. background: Rectangle {
  432. color: "lightgray"
  433. implicitHeight: 6
  434. }
  435. progress: Rectangle {
  436. color: UM.Theme.getColor("primary")
  437. }
  438. }
  439. }
  440. }
  441. }
  442. }