@@ -0,0 +1,230 @@
1+/*
2+ * Copyright (C) 2018 The UBports project
3+ *
4+ * Written by: Marius Gripsgard <marius@ubports.com>
5+ *
6+ * This program is free software; you can redistribute it and/or modify
7+ * it under the terms of the GNU General Public License as published by
8+ * the Free Software Foundation; version 3.
9+ *
10+ * This program is distributed in the hope that it will be useful,
11+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+ * GNU General Public License for more details.
14+ *
15+ * You should have received a copy of the GNU General Public License
16+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
17+ */
18+
19+import QtQuick 2.4
20+import QtQuick.Layouts 1.1
21+import Ubuntu.Components 1.3
22+import Ubuntu.SystemImage 0.1
23+import Wizard 0.1
24+import ".." as LocalComponents
25+
26+LocalComponents.Page {
27+ id: systemUpdatePage
28+ objectName: "firmwareUpdatePage"
29+
30+ title: i18n.tr("firmware Update")
31+ forwardButtonSourceComponent: forwardButton
32+
33+ skip: !SystemImage.SupportsFirmwareUpdate() || !online
34+
35+ property bool online: NetworkingStatus.online
36+ property bool hasUpdate: false
37+ property bool isUpdating: false
38+ property bool isChecking: true
39+ property var partitions: ""
40+
41+ function check() {
42+ if (!SystemImage.SupportsFirmwareUpdate())
43+ return
44+ systemUpdatePage.isChecking = true
45+ SystemImage.checkForFirmwareUpdate()
46+ }
47+
48+ function flash() {
49+ if (!SystemImage.SupportsFirmwareUpdate())
50+ return
51+ systemUpdatePage.isUpdating = true
52+ SystemImage.updateFirmware()
53+ }
54+
55+ Connections {
56+ target: SystemImage
57+ onCheckForFirmwareUpdateDone: {
58+ var updateobj = JSON.parse(updateObj);
59+ if (Array.isArray(updateobj) && updateobj.length > 0) {
60+ for (var u in updateobj) {
61+ console.log(u)
62+ if (systemUpdatePage.partitions === "")
63+ systemUpdatePage.partitions += updateobj[u].file
64+ else
65+ systemUpdatePage.partitions += ", " + updateobj[u].file
66+ }
67+ systemUpdatePage.hasUpdate = true;
68+ }
69+ console.log(updateobj);
70+ systemUpdatePage.isChecking = false;
71+ }
72+ onUpdateFirmwareDone: {
73+ var updateobj = JSON.parse(updateObj);
74+ if (Array.isArray(updateobj) && updateobj.length === 0) {
75+ // This means success!
76+ systemUpdatePage.hasUpdate = false;
77+ systemUpdatePage.partitions = "";
78+ System.skipUntilFinishedPage();
79+ SystemImage.reboot();
80+ return;
81+ }
82+ console.log(updateobj);
83+ systemUpdatePage.isUpdating = false;
84+ }
85+ }
86+
87+ Column {
88+ id: column
89+ anchors {
90+ fill: content
91+ leftMargin: systemUpdatePage.leftMargin
92+ rightMargin: systemUpdatePage.rightMargin
93+ topMargin: systemUpdatePage.customMargin
94+ }
95+ spacing: units.gu(3)
96+ opacity: spinner.visible ? 0.5 : 1
97+ Behavior on opacity {
98+ UbuntuNumberAnimation {}
99+ }
100+
101+ Label {
102+ anchors.horizontalCenter: parent.horizontalCenter
103+ font.weight: Font.Light
104+ wrapMode: Text.Wrap
105+ textSize: Label.Medium
106+ text: systemUpdatePage.hasUpdate ? i18n.tr("There is a firmware update available!")
107+ : i18n.tr("Firmware is up to date!")
108+
109+ }
110+
111+ GridLayout {
112+ rows: 3
113+ columns: 2
114+ rowSpacing: units.gu(1)
115+ columnSpacing: units.gu(2)
116+ anchors.horizontalCenter: parent.horizontalCenter
117+ visible: hasUpdate
118+
119+ Icon {
120+ Layout.rowSpan: 3
121+ Layout.alignment: Qt.AlignVCenter | Qt.AlignHCenter
122+ width: units.gu(5)
123+ height: width
124+ name: "security-alert"
125+ }
126+
127+ Label {
128+ font.weight: Font.Normal
129+ textSize: Label.Medium
130+ text: i18n.tr("Firmware Update")
131+ }
132+
133+ Label {
134+ font.weight: Font.Light
135+ fontSize: "small"
136+ text: systemUpdatePage.partitions
137+ }
138+
139+ Label {
140+ font.weight: Font.Light
141+ fontSize: "small"
142+ text: i18n.tr("The device will automatically restart after installing is done.")
143+ }
144+ }
145+
146+ Rectangle {
147+ anchors.left: parent.left
148+ anchors.leftMargin: 3
149+ anchors.horizontalCenter: parent.horizontalCenter
150+ color: theme.palette.normal.foreground
151+ radius: units.dp(4)
152+ width: buttonLabel.paintedWidth + units.gu(3)
153+ height: buttonLabel.paintedHeight + units.gu(1.8)
154+ visible: hasUpdate
155+
156+ Label {
157+ id: buttonLabel
158+ text: i18n.tr("Install and restart now")
159+ font.weight: Font.Light
160+ anchors.horizontalCenter: parent.horizontalCenter
161+ anchors.centerIn: parent
162+ }
163+
164+ AbstractButton {
165+ id: button
166+ objectName: "installButton"
167+ anchors.fill: parent
168+ anchors.horizontalCenter: parent.horizontalCenter
169+ onClicked: {
170+ systemUpdatePage.flash()
171+ }
172+ }
173+
174+ transformOrigin: Item.Top
175+ scale: button.pressed ? 0.98 : 1.0
176+ Behavior on scale {
177+ ScaleAnimator {
178+ duration: UbuntuAnimation.SnapDuration
179+ easing.type: Easing.Linear
180+ }
181+ }
182+ }
183+ }
184+
185+ Column {
186+ id: spinner
187+ anchors.centerIn: systemUpdatePage
188+ visible: systemUpdatePage.isChecking || systemUpdatePage.isUpdating
189+
190+ ActivityIndicator {
191+ anchors.horizontalCenter: parent.horizontalCenter
192+ running: parent.visible
193+ }
194+
195+ Label {
196+ wrapMode: Text.Wrap
197+ width: systemUpdatePage.width - units.gu(3)
198+ fontSize: "small"
199+ text: i18n.tr("Downloading and Flashing firmware updates, this could take a few minutes...")
200+ visible: systemUpdatePage.isUpdating
201+ }
202+
203+ Label {
204+ wrapMode: Text.Wrap
205+ fontSize: "small"
206+ text: i18n.tr("Checking for firmware update")
207+ visible: systemUpdatePage.isChecking
208+ }
209+
210+ Component.onCompleted: systemUpdatePage.check()
211+
212+ }
213+
214+ Connections {
215+ target: NetworkingStatus
216+ onOnlineChanged: {
217+ if (online) {
218+ systemUpdatePage.check()
219+ }
220+ }
221+ }
222+
223+ Component {
224+ id: forwardButton
225+ LocalComponents.StackButton {
226+ text: systemUpdatePage.hasUpdate ? i18n.tr("Next") : i18n.tr("Skip")
227+ onClicked: pageStack.next()
228+ }
229+ }
230+}