Warning, /plasma/discover/discover/qml/InstallApplicationButton.qml is written in an unsupported language. File is not indexed.

0001 import QtQuick 2.1
0002 import QtQuick.Controls 2.3
0003 import QtQuick.Layouts 1.1
0004 import org.kde.discover 2.0
0005 import org.kde.kirigami 2.14 as Kirigami
0006 
0007 ConditionalLoader
0008 {
0009     id: root
0010     property Component additionalItem: null
0011     property alias application: listener.resource
0012 
0013     readonly property alias isActive: listener.isActive
0014     readonly property alias progress: listener.progress
0015     readonly property bool isStateAvailable: application.state !== AbstractResource.Broken
0016     readonly property alias listener: listener
0017 
0018     TransactionListener {
0019         id: listener
0020     }
0021 
0022     readonly property Kirigami.Action action: Kirigami.Action {
0023         text: {
0024             if (!root.isStateAvailable) {
0025                 return i18nc("State being fetched", "Loading…")
0026             }
0027             if (!application.isInstalled) {
0028                 return i18n("Install");
0029             }
0030             return i18n("Remove");
0031         }
0032         icon {
0033             name: application.isInstalled ? "edit-delete" : "download"
0034             color: !enabled ? Kirigami.Theme.backgroundColor : !listener.isActive ? (application.isInstalled ? Kirigami.Theme.negativeTextColor : Kirigami.Theme.positiveTextColor) : Kirigami.Theme.backgroundColor
0035         }
0036         visible: !listener.isActive && (!application.isInstalled || application.isRemovable)
0037         enabled: !listener.isActive && root.isStateAvailable
0038         onTriggered: root.click()
0039     }
0040     readonly property Kirigami.Action cancelAction: Kirigami.Action {
0041         text: i18n("Cancel")
0042         icon.name: "dialog-cancel"
0043         enabled: listener.isCancellable
0044         tooltip: listener.statusText
0045         onTriggered: {
0046             listener.cancel()
0047             enabled = false
0048         }
0049         visible: listener.isActive
0050         onVisibleChanged: enabled = true
0051     }
0052 
0053     function click() {
0054         if (!isActive) {
0055             if(application.isInstalled)
0056                 ResourcesModel.removeApplication(application);
0057             else
0058                 ResourcesModel.installApplication(application);
0059         } else {
0060             console.warn("trying to un/install but resource still active", application.name)
0061         }
0062     }
0063 
0064     condition: listener.isActive
0065     componentTrue: RowLayout {
0066         ToolButton {
0067             Layout.fillHeight: true
0068             action: root.cancelAction
0069             text: ""
0070             ToolTip.visible: hovered
0071             ToolTip.text: root.cancelAction.text
0072         }
0073 
0074         LabelBackground {
0075             Layout.fillWidth: true
0076             text: listener.statusText
0077             progress: listener.progress/100
0078         }
0079     }
0080 
0081     componentFalse: Button {
0082         visible: !application.isInstalled || application.isRemovable
0083         enabled: application.state !== AbstractResource.Broken
0084         text: root.action.text
0085 
0086         activeFocusOnTab: false
0087         onClicked: root.click()
0088     }
0089 }