on xenial help sign in
WIP: system update page
commit9c92e2fa42f5c66a73b45cb2cf90ae97fa3f8ace authorLukáš Tinkl <lukas.tinkl@canonical.com> dateWed 13 Jul 2016, 17:45 (10 years ago) parent113dac2
7 files changed+171−9
plugins/Ubuntu/SystemImage/CMakeLists.txt+5 plugins/Ubuntu/SystemImage/SystemImage.cpp+15−2 plugins/Ubuntu/SystemImage/SystemImage.h+4−3 plugins/Ubuntu/SystemImage/plugin.cpp+1−1 qml/Wizard/Pages/77-system-update.qml+121 tests/mocks/Ubuntu/SystemImage/MockSystemImage.cpp+13−1 tests/mocks/Ubuntu/SystemImage/MockSystemImage.h+12−2
plugins/Ubuntu/SystemImage/CMakeLists.txt+5
@@ -1,3 +1,7 @@
1+include_directories(
2+ ${GLIB_INCLUDE_DIRS}
3+)
4+
15set(SYSTEMIMAGE_SOURCES
26 plugin.cpp
37 SystemImage.cpp
@@ -6,5 +10,6 @@ set(SYSTEMIMAGE_SOURCES
610add_library(SystemImage MODULE ${SYSTEMIMAGE_SOURCES})
711
812qt5_use_modules(SystemImage Qml DBus Core)
13+target_link_libraries(SystemImage ${GLIB_LIBRARIES})
914
1015add_unity8_plugin(Ubuntu.SystemImage 0.1 Ubuntu/SystemImage TARGETS SystemImage)
plugins/Ubuntu/SystemImage/SystemImage.cpp+15−2
@@ -19,6 +19,8 @@
1919#include <QDBusReply>
2020#include <QDebug>
2121
22+#include <glib.h>
23+
2224#include "SystemImage.h"
2325
2426#define SYSTEMIMAGE_SERVICE QStringLiteral("com.canonical.SystemImage")
@@ -71,7 +73,7 @@ void SystemImage::onUpdateAvailableStatus(bool is_available, bool downloading, c
7173 m_updateAvailable = is_available;
7274 m_downloading = downloading;
7375 m_availableVersion = available_version;
74− m_updateSize = update_size;
76+ m_updateSize = formatSize(update_size);
7577 m_lastUpdateDate = last_update_date;
7678 m_errorReason = error_reason;
7779 Q_EMIT updateAvailableStatus();
@@ -106,7 +108,18 @@ void SystemImage::resetUpdateStatus()
106108 m_downloading = false;
107109 m_downloaded = false;
108110 m_availableVersion.clear();
109− m_updateSize = -1;
111+ m_updateSize.clear();
110112 m_lastUpdateDate.clear();
111113 m_errorReason.clear();
112114}
115+
116+QString SystemImage::formatSize(quint64 size) const
117+{
118+ guint64 g_size = size;
119+
120+ gchar * formatted_size = g_format_size(g_size);
121+ QString q_formatted_size = QString::fromLocal8Bit(formatted_size);
122+ g_free(formatted_size);
123+
124+ return q_formatted_size;
125+}
plugins/Ubuntu/SystemImage/SystemImage.h+4−3
@@ -28,7 +28,7 @@ class SystemImage : public QObject
2828 Q_PROPERTY(bool updateAvailable READ updateAvailable NOTIFY updateAvailableStatus)
2929 Q_PROPERTY(bool updateDownloading READ updateDownloading NOTIFY updateAvailableStatus)
3030 Q_PROPERTY(QString availableVersion READ availableVersion NOTIFY updateAvailableStatus)
31− Q_PROPERTY(int updateSize READ updateSize NOTIFY updateAvailableStatus)
31+ Q_PROPERTY(QString updateSize READ updateSize NOTIFY updateAvailableStatus)
3232
3333 Q_PROPERTY(bool updateDownloaded READ updateDownloaded NOTIFY updateDownloadedChanged)
3434
@@ -39,7 +39,7 @@ public:
3939 bool updateAvailable() const { return m_updateAvailable; }
4040 bool updateDownloading() const { return m_downloading; }
4141 QString availableVersion() const { return m_availableVersion; }
42− int updateSize() const { return m_updateSize; }
42+ QString updateSize() const { return m_updateSize; }
4343
4444 bool updateDownloaded() const { return m_downloaded; }
4545
@@ -61,13 +61,14 @@ Q_SIGNALS:
6161
6262private:
6363 void resetUpdateStatus();
64+ QString formatSize(quint64 size) const;
6465
6566private:
6667 bool m_updateAvailable = false;
6768 bool m_downloading = false;
6869 bool m_downloaded = false;
6970 QString m_availableVersion;
70− int m_updateSize = -1;
71+ QString m_updateSize;
7172 QString m_lastUpdateDate;
7273 QString m_errorReason;
7374 bool m_updateDownloaded;
plugins/Ubuntu/SystemImage/plugin.cpp+1−1
@@ -1,5 +1,5 @@
11/*
2− * Copyright (C) 2014 Canonical, Ltd.
2+ * Copyright (C) 2014-2016 Canonical, Ltd.
33 *
44 * This program is free software; you can redistribute it and/or modify
55 * it under the terms of the GNU General Public License as published by
qml/Wizard/Pages/77-system-update.qmlnew file+121
@@ -0,0 +1,121 @@
1+/*
2+ * Copyright (C) 2016 Canonical, Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+import QtQuick 2.4
18+import QtQuick.Layouts 1.1
19+import Ubuntu.Components 1.3
20+import Ubuntu.SystemImage 0.1
21+import ".." as LocalComponents
22+
23+LocalComponents.Page {
24+ id: reportingPage
25+ objectName: "systemUpdatePage"
26+
27+ title: i18n.tr("Update Device")
28+ forwardButtonSourceComponent: forwardButton
29+
30+ skip: !SystemImage.updateDownloaded // skip the page when the system update is not ready to install
31+
32+ Column {
33+ id: column
34+ anchors {
35+ fill: content
36+ leftMargin: leftMargin
37+ rightMargin: rightMargin
38+ topMargin: customMargin
39+ }
40+ spacing: units.gu(3)
41+
42+ Label {
43+ anchors.left: parent.left
44+ anchors.right: parent.right
45+ anchors.leftMargin: column.anchors.leftMargin == 0 ? staticMargin : 0
46+ font.weight: Font.Light
47+ color: textColor
48+ wrapMode: Text.Wrap
49+ text: i18n.tr("There is a system update available and ready to install. Afterwards, the device will automatically restart.")
50+ }
51+
52+ GridLayout {
53+ anchors.left: parent.left
54+ anchors.right: parent.right
55+ rows: 3
56+ columns: 2
57+ rowSpacing: units.gu(1)
58+ columnSpacing: units.gu(2)
59+
60+ UbuntuShape {
61+ Layout.rowSpan: 3
62+ aspect: UbuntuShape.Flat
63+ backgroundColor: theme.palette.normal.base
64+ width: units.gu(8)
65+ height: width
66+ sourceScale: Qt.vector2d(0.5,0.5)
67+ source: Image {
68+ source: Qt.resolvedUrl("/usr/share/icons/suru/apps/scalable/ubuntu-logo-symbolic.svg")
69+ }
70+ }
71+
72+ Label {
73+ Layout.fillWidth: true
74+ color: textColor
75+ font.weight: Font.Normal
76+ text: i18n.tr("Ubuntu system")
77+ }
78+
79+ Label {
80+ font.weight: Font.Light
81+ color: textColor
82+ text: i18n.tr("Version %1").arg(SystemImage.availableVersion)
83+ }
84+
85+ Label {
86+ font.weight: Font.Light
87+ color: textColor
88+ text: SystemImage.updateSize
89+ }
90+ }
91+
92+ Label {
93+ anchors.left: parent.left
94+ anchors.right: parent.right
95+ anchors.leftMargin: column.anchors.leftMargin == 0 ? staticMargin : 0
96+ font.weight: Font.Light
97+ color: textColor
98+ wrapMode: Text.Wrap
99+ fontSize: "small"
100+ text: i18n.tr("This could take a few minutes...")
101+ }
102+
103+ Button {
104+ anchors.left: parent.left
105+ anchors.leftMargin: column.anchors.leftMargin == 0 ? staticMargin : 0
106+ text: i18n.tr("Install and restart now")
107+ onClicked: {
108+ // TODO mark the wizard to skip until the finished page for the next boot
109+ SystemImage.applyUpdate();
110+ }
111+ }
112+ }
113+
114+ Component {
115+ id: forwardButton
116+ LocalComponents.StackButton {
117+ text: i18n.tr("Skip")
118+ onClicked: pageStack.next()
119+ }
120+ }
121+}
tests/mocks/Ubuntu/SystemImage/MockSystemImage.cpp+13−1
@@ -1,5 +1,5 @@
11/*
2− * Copyright (C) 2014 Canonical, Ltd.
2+ * Copyright (C) 2014-2016 Canonical, Ltd.
33 *
44 * This program is free software; you can redistribute it and/or modify
55 * it under the terms of the GNU General Public License as published by
@@ -14,6 +14,8 @@
1414 * along with this program. If not, see <http://www.gnu.org/licenses/>.
1515 */
1616
17+#include <QDebug>
18+
1719#include "MockSystemImage.h"
1820
1921MockSystemImage::MockSystemImage(QObject *parent)
@@ -21,6 +23,16 @@ MockSystemImage::MockSystemImage(QObject *parent)
2123{
2224}
2325
26+void MockSystemImage::checkForUpdate()
27+{
28+ qDebug() << "Doing a fake system update check";
29+}
30+
31+void MockSystemImage::applyUpdate()
32+{
33+ qDebug() << "Applying a fake system update";
34+}
35+
2436void MockSystemImage::factoryReset()
2537{
2638 Q_EMIT resettingDevice();
tests/mocks/Ubuntu/SystemImage/MockSystemImage.h+12−2
@@ -24,12 +24,22 @@ class MockSystemImage : public QObject
2424 Q_OBJECT
2525 Q_DISABLE_COPY(MockSystemImage)
2626
27+ Q_PROPERTY(bool updateDownloaded READ updateDownloaded CONSTANT)
28+ Q_PROPERTY(QString availableVersion READ availableVersion CONSTANT)
29+ Q_PROPERTY(QString updateSize READ updateSize CONSTANT)
30+
2731public:
28− explicit MockSystemImage(QObject *parent = 0);
32+ explicit MockSystemImage(QObject *parent = nullptr);
2933
30− Q_INVOKABLE void checkForUpdate() {}
34+ Q_INVOKABLE void checkForUpdate();
35+ Q_INVOKABLE void applyUpdate();
3136 Q_INVOKABLE void factoryReset();
3237
38+ // these are const only in mock
39+ bool updateDownloaded() const { return true; }
40+ QString availableVersion() const { return QStringLiteral("42"); }
41+ QString updateSize() const { return QStringLiteral("4.2 MB"); }
42+
3343Q_SIGNALS:
3444 void resettingDevice(); // only for mock
3545};