ProgressView.qml 4.77 KB
Newer Older
1
import QtQuick 2.1
2
import QtQuick.Controls 1.1
3
import QtQuick.Controls 2.1 as QQC2
4
import QtQuick.Layouts 1.1
5
import org.kde.kquickcontrolsaddons 2.0
6
import org.kde.discover 2.0
Aleix Pol Gonzalez's avatar
Port  
Aleix Pol Gonzalez committed
7
import org.kde.kirigami 2.0 as Kirigami
8
import "navigation.js" as Navigation
9

10
Kirigami.BasicListItem {
11
    id: listItem
12 13 14
    label: TransactionModel.count ? i18n("Tasks (%1%)", TransactionModel.progress) : i18n("Tasks")
    visible: progressModel.count > 0

15 16 17 18 19 20 21 22 23 24 25 26
    background: Item {

        Rectangle {
            anchors {
                fill: parent
                rightMargin: TransactionModel.count>=1 ? listItem.width*(1-TransactionModel.progress/100) : 0
            }
            color: TransactionModel.count>=1 || listItem.hovered || listItem.highlighted || listItem.pressed || listItem.checked ? listItem.activeBackgroundColor : listItem.backgroundColor
            opacity: listItem.hovered || listItem.highlighted ? 0.2 : 1
        }
    }

27 28
    onClicked: {
        sheet.open()
29
    }
30 31 32
    onVisibleChanged: if (!visible) {
        sheet.close()
    }
33 34

    readonly property var v1: Connections {
35
        target: TransactionModel
Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
36
        onTransactionAdded: {
37
            if(listItem.enabled && trans.visible && progressModel.applicationAt(trans.resource)<0) {
38 39
                progressModel.append({ transaction: trans })
            }
Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
40
        }
41

42
        onTransactionRemoved: {
43 44
            if (trans.status == Transaction.CancelledStatus || !trans.resource) {
                var id = progressModel.applicationAt(trans.resource)
45 46 47
                if(id>=0)
                    progressModel.remove(id)
            }
Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
48 49 50
        }
    }
    
51
    readonly property var v2: ListModel {
Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
52
        id: progressModel
53
        function applicationAt(app) {
Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
54
            for(var i=0; i<progressModel.count; i++) {
55
                if(progressModel.get(i).application==app) {
Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
56 57 58 59 60 61
                    return i
                }
            }
            return -1
        }
    }
62

63 64
    readonly property var v3: Kirigami.OverlaySheet {
        id: sheet
65

66 67
        contentItem: ColumnLayout {
            spacing: 0
68 69 70 71 72 73 74 75

            Component {
                id: listenerComp
                TransactionListener {
                    onCancelled: progressModel.remove(index)
                }
            }

76 77
            Repeater {
                model: progressModel
78

79
                delegate: Kirigami.AbstractListItem {
80
                    id: del
81
                    separatorVisible: false
82
                    onClicked: {
83 84 85 86
                        if (model.application) {
                            Navigation.clearStack()
                            Navigation.openApplication(model.application)
                        }
87
                    }
88
                    readonly property QtObject listener: listenerComp.createObject(del, (model.transaction.resource ? {resource: model.transaction.resource} : {transaction: model.transaction}))
89

90 91
                    ColumnLayout {
                        width: parent.width
92

93 94
                        RowLayout {
                            Layout.fillWidth: true
Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
95

96
                            Kirigami.Icon {
97 98
                                Layout.fillHeight: true
                                Layout.minimumWidth: height
99
                                source: model.transaction.icon
100
                            }
101

102
                            QQC2.Label {
103 104 105
                                anchors.verticalCenter: parent.verticalCenter
                                Layout.fillWidth: true
                                elide: Text.ElideRight
106
                                text: listener.isActive ? i18nc("TransactioName TransactionStatus", "%1 %2", model.transaction.name, listener.statusText) : model.transaction.name
107 108 109 110 111 112 113 114
                            }
                            ToolButton {
                                iconName: "dialog-cancel"
                                visible: listener.isCancellable
                                onClicked: listener.cancel()
                            }
                            ToolButton {
                                iconName: "system-run"
115
                                visible: model.application != undefined && model.application.isInstalled && !listener.isActive && model.application.canExecute
116
                                onClicked: {
117
                                    model.application.invokeApplication()
118 119 120 121 122 123 124 125 126 127
                                    model.remove(index)
                                }
                            }
                        }
                        ProgressBar {
                            Layout.fillWidth: true
                            visible: listener.isActive
                            value: listener.progress
                            maximumValue: 100
                        }
Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
128
                    }
129
                }
130 131 132 133
            }
        }
    }
}