warehouse for ces2019
[apps/onscreenapp.git] / app / pages / ManagementPage.qml
1 /*
2  * Copyright (C) 2018 The Qt Company Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 import QtQuick 2.6
18 import QtQuick.Layouts 1.1
19 import QtQuick.Controls 2.0
20
21 Page {
22     id: root
23     property alias model: listView.model
24
25     property int nPullHeight: 300
26     
27     BusyIndicator {
28         id: busyIndicator
29         anchors.horizontalCenter: parent.horizontalCenter
30         implicitWidth: 60
31         implicitHeight: 60
32         running: false
33     }
34
35     ListView {
36         id: listView
37         anchors.fill: parent
38         anchors.margins: root.width * 0.075
39         clip: true
40         
41         delegate: MouseArea {
42             id: delegate
43             width: listView.width
44             height: width / 6
45             RowLayout {
46                 anchors.fill: parent
47                 Item {
48                     Layout.preferredWidth: 100
49                     Layout.preferredHeight: 100
50                     Image {
51                         anchors.fill: parent
52                         source: 'file://' + model.icon
53                     }
54                 }
55                 ColumnLayout {
56                     Label {
57                         Layout.fillWidth: true
58                         text: model.name.toUpperCase()
59                         color: '#00ADDC'
60                     }
61                     Label {
62                         text: 'Version: ' + model.version
63                         font.pixelSize: 16
64                         font.italic: true
65                     }
66                     Label {
67                         text: 'Description: ' + model.description
68                         font.pixelSize: 16
69                         wrapMode: Text.Wrap
70                         elide: Text.ElideRight
71                         Layout.preferredWidth: 400
72                         Layout.preferredHeight: 40
73                     }
74                 }
75                 ColumnLayout {
76                     spacing: 5
77                     Layout.alignment: Qt.AlignRight | Qt.AlignVCenter
78
79                     Button {
80                                                 x: x - 6
81                         text: 'Launch'
82                         onClicked: {
83                             if (listView.model.launch(model.id) > 1) {
84                                 homescreenHandler.tapShortcut(model.name)
85                             } else {
86                                 console.warn('app cannot be launched')
87                             }
88                         }
89                         implicitWidth: 140
90                         implicitHeight: 40
91                     }
92                     Button {
93                                                 x: x - 6
94                                                 visible: model.name.toUpperCase() != "HOMESCREEN" && model.name.toUpperCase() != "LAUNCHER"
95                         text: 'Uninstall'
96                         onClicked: {
97                             listView.model.uninstall(model.index)
98                         }
99                         implicitWidth: 140
100                         implicitHeight: 40
101                     }
102                 }
103             }
104             Image {
105                 source: 'qrc:/images/DividingLine.svg'
106                 anchors.horizontalCenter: parent.horizontalCenter
107                 anchors.top: parent.top
108                 visible: model.index > 0
109             }
110
111         }
112
113         states: [
114             State {
115                 name: "refreshState"; when: listView.contentY < -nPullHeight
116                 StateChangeScript {
117                     name: "refreshScript"
118                     script: refreshModel()
119                 }
120             }
121         ]
122     }
123
124     function refreshModel() {
125         listView.y = nPullHeight;
126
127         busyIndicator.running = true
128         refreshTimer.start();
129     }
130
131     Timer {
132         id: refreshTimer
133         interval: 1000
134         repeat: false
135         running: false
136         onTriggered: {
137             listView.model.refresh()
138             refreshAnimation.start();
139         }
140     }
141
142     NumberAnimation {
143         id: refreshAnimation
144         target: listView
145         property: "y"
146         duration: 100
147         from: nPullHeight
148         to: 0
149         onStopped: {
150             busyIndicator.running = false
151             listView.y = 0;
152         }
153     }
154    
155 }
156