on xenial help sign in
Improve check if update or new install logic
6c01080Marius Gripsgard
plugins/Wizard/System.cpp+48−24
@@ -20,7 +20,6 @@
20#include <QDBusMessage>
20#include <QDBusMessage>
21#include <QDBusConnection>
21#include <QDBusConnection>
22#include <QDBusMetaType>
22#include <QDBusMetaType>
23−#include <QVersionNumber>
24#include <QDir>
23#include <QDir>
25#include <QFile>
24#include <QFile>
26#include <QLocale>
25#include <QLocale>
@@ -44,53 +43,78 @@ System::System()
44QString System::wizardEnabledPath()
43QString System::wizardEnabledPath()
45{
44{
46 // Uses ubuntu-system-settings namespace for historic compatibility reasons
45 // Uses ubuntu-system-settings namespace for historic compatibility reasons
47− return QDir::home().filePath(QStringLiteral(".config/ubuntu-system-settings/wizard-has-run/"));
46+ return QDir::home().filePath(QStringLiteral(".config/ubuntu-system-settings/wizard-has-run"));
48}
47}
49
48
49+QString System::currentFrameworkPath()
50+{
51+ return QDir::home().filePath(QStringLiteral("/usr/share/click/framework/current"));
52+}
53+
54+/*
55+wizardEnabled and isUpdate logic
56+
57+if wizard-has-run does NOT exists == is new install
58+if wizard-has-run does exists but does NOT match current framework == is update
59+if wizard-has-run does exists but does match current framework == show no wizard
60+*/
61+
50bool System::wizardEnabled() const
62bool System::wizardEnabled() const
51{
63{
52− return (versionToShow() >= 0);
64+ return !QFile::exists(wizardEnabledPath());
53}
65}
54
66
55−signed int System::versionToShow() const
67+QString System::readCurrentFramework()
56{
68{
57− if (!(QFile::exists(wizardEnabledPath()))) {
69+ QFile f(currentFrameworkPath());
58− return 0;
70+ if (!f.open(QFile::ReadOnly | QFile::Text)) return "";
71+ QTextStream in(&f);
72+ return in.readAll();
59− }
73+}
60
74
61− QString pathToCheck = QDir(wizardEnabledPath()).filePath(QString::number(CURRENT_VERSION));
75+QString System::readWizardEnabled()
62−
76+{
63− if (!(QFile::exists(pathToCheck))) {
77+ QFile f(wizardEnabledPath());
64− return CURRENT_VERSION;
78+ if (!f.open(QFile::ReadOnly | QFile::Text)) return "";
79+ QTextStream in(&f);
80+ return in.readAll();
65− }
81+}
66
82
67− return -1;
83+QString System::version() const
68−
84+{
85+ return readCurrentFramework();
86+}
87+
88+bool System::isUpdate() const
89+{
90+ if (!wizardEnabled())
91+ return false;
92+
93+ return readCurrentFramework() != readWizardEnabled();
69}
94}
70
95
71void System::setWizardEnabled(bool enabled)
96void System::setWizardEnabled(bool enabled)
72{
97{
73− if (wizardEnabled() == enabled)
98+ if (wizardEnabled() == enabled && !isUpdate())
74 return;
99 return;
75
100
76 if (enabled) {
101 if (enabled) {
77− QDir(wizardEnabledPath()).removeRecursively();
102+ QFile::remove(wizardEnabledPath());
78 } else {
103 } else {
79− QDir(wizardEnabledPath()).mkpath(QStringLiteral("."));
104+ QDir(wizardEnabledPath()).mkpath(QStringLiteral(".."));
105+ if (QFile::exists(wizardEnabledPath()))
106+ QFile::remove(wizardEnabledPath());
107+ QFile::copy(currentFrameworkPath(), wizardEnabledPath());
80 m_fsWatcher.addPath(wizardEnabledPath());
108 m_fsWatcher.addPath(wizardEnabledPath());
81−
109+ Q_EMIT wizardEnabledChanged();
82− // Disable the newest non-first-run wizard, too
110+ Q_EMIT isUpdateChanged();
83− QFile(QDir(wizardEnabledPath()).filePath(QString::number(CURRENT_VERSION))).open(QIODevice::WriteOnly);
84 }
111 }
85−
86− Q_EMIT wizardEnabledChanged();
87− Q_EMIT versionToShowChanged();
88}
112}
89
113
90void System::watcherFileChanged()
114void System::watcherFileChanged()
91{
115{
92 Q_EMIT wizardEnabledChanged();
116 Q_EMIT wizardEnabledChanged();
93− Q_EMIT versionToShowChanged();
117+ Q_EMIT isUpdateChanged();
94 m_fsWatcher.removePath(wizardEnabledPath());
118 m_fsWatcher.removePath(wizardEnabledPath());
95}
119}
96
120
plugins/Wizard/System.h+9−18
@@ -26,7 +26,8 @@ class System : public QObject
26{
26{
27 Q_OBJECT
27 Q_OBJECT
28 Q_PROPERTY(bool wizardEnabled READ wizardEnabled WRITE setWizardEnabled NOTIFY wizardEnabledChanged)
28 Q_PROPERTY(bool wizardEnabled READ wizardEnabled WRITE setWizardEnabled NOTIFY wizardEnabledChanged)
29− Q_PROPERTY(int versionToShow READ versionToShow NOTIFY versionToShowChanged)
29+ Q_PROPERTY(QString version READ version NOTIFY versionChanged)
30+ Q_PROPERTY(bool isUpdate READ isUpdate NOTIFY isUpdateChanged)
30
31
31public:
32public:
32 System();
33 System();
@@ -37,22 +38,8 @@ public:
37 */
38 */
38 bool wizardEnabled() const;
39 bool wizardEnabled() const;
39
40
40− /**
41+ QString version() const;
41− * Returns the version of the wizard that should be run
42+ bool isUpdate() const;
42− * -1 denotes that no wizard should be run. 0 denotes that the first-run
43− * wizard should be run. If we determine that the first-run wizard has run
44− * but ::CURRENT_VERSION has not, we return ::CURRENT_VERSION.
45− * For example, if ::CURRENT_VERSION is 4, version 4 has not run, but the
46− * first-run wizard has run, this method will return 4
47− */
48− int versionToShow() const;
49−
50− /**
51− * The update version for the Wizard in this version of Unity8. Bump this
52− * version then set the showOnVersions property for the pages you would like
53− * to run on the current update to the new value.
54− */
55− int CURRENT_VERSION = 1;
56
43
57 void setWizardEnabled(bool enabled);
44 void setWizardEnabled(bool enabled);
58
45
@@ -65,7 +52,8 @@ public Q_SLOTS:
65
52
66Q_SIGNALS:
53Q_SIGNALS:
67 void wizardEnabledChanged();
54 void wizardEnabledChanged();
68− void versionToShowChanged();
55+ void versionChanged();
56+ void isUpdateChanged();
69
57
70private Q_SLOTS:
58private Q_SLOTS:
71 void watcherFileChanged();
59 void watcherFileChanged();
@@ -74,7 +62,10 @@ private:
74 Q_DISABLE_COPY(System)
62 Q_DISABLE_COPY(System)
75
63
76 static QString wizardEnabledPath();
64 static QString wizardEnabledPath();
65+ static QString currentFrameworkPath();
77 static void setSessionVariable(const QString &variable, const QString &value);
66 static void setSessionVariable(const QString &variable, const QString &value);
67+ static QString readCurrentFramework();
68+ static QString readWizardEnabled();
78
69
79 QFileSystemWatcher m_fsWatcher;
70 QFileSystemWatcher m_fsWatcher;
80};
71};
qml/Wizard/Page.qml+3−4
@@ -50,10 +50,9 @@ Item {
50 property bool skipValid: true
50 property bool skipValid: true
51 property bool skip: false
51 property bool skip: false
52
52
53− // Marks the wizard versions that this page should be displayed on.
53+ // Marks if should be only shown if update or install
54− // [0] marks a page to run on first-boot only. [] marks it to run on all wizard runs.
54+ property bool onlyOnUpdate: false
55− // Other valid values can be found in ../../plugins/Wizard/System.h
55+ property bool onlyOnInstall: false
56− property var showOnVersions: [0]
57
56
58 property bool hasBackButton: true
57 property bool hasBackButton: true
59 property string backButtonText: i18n.ctr("Button: Go back one page in the Wizard", "Back")
58 property string backButtonText: i18n.ctr("Button: Go back one page in the Wizard", "Back")
qml/Wizard/Pages.qml+4−12
@@ -127,7 +127,7 @@ StyledItem {
127 // impatientLoadingLabel.text = ""
127 // impatientLoadingLabel.text = ""
128 }
128 }
129 }
129 }
130− }
130+ }
131
131
132 Timer {
132 Timer {
133 id: impatientLoadingTimer
133 id: impatientLoadingTimer
@@ -195,14 +195,7 @@ StyledItem {
195 currentPage.aboutToShowSecondary(UbuntuAnimation.BriskDuration);
195 currentPage.aboutToShowSecondary(UbuntuAnimation.BriskDuration);
196 }
196 }
197 }
197 }
198−
198+
199− /**
200− * Determine if array contains item
201− */
202− function itemInArray(item, array) {
203− return array.indexOf(item) >= 0;
204− }
205−
206 function checkSkip() {
199 function checkSkip() {
207 if (!currentPage) { // may have had a parse error
200 if (!currentPage) { // may have had a parse error
208 console.warn("Wizard page skipped due to possible parse error.");
201 console.warn("Wizard page skipped due to possible parse error.");
@@ -210,9 +203,8 @@ StyledItem {
210 } else if (currentPage.skipValid) {
203 } else if (currentPage.skipValid) {
211 if (currentPage.skip) {
204 if (currentPage.skip) {
212 next();
205 next();
213− } else if ( !(itemInArray(wizard.runningWizardVersion, currentPage.showOnVersions)) &&
206+ } else if ((currentPage.onlyOnUpdate && !wizard.isUpdate) ||
214− (currentPage.showOnVersions.length > 0) ) {
207+ (currentPage.onlyOnInstall && wizard.isUpdate)) {
215− // The page is not supposed to run on this version of the wizard
216 next();
208 next();
217 } else {
209 } else {
218 impatientLoadingTimer.stop()
210 impatientLoadingTimer.stop()
qml/Wizard/Pages/10-welcome-update.qmlnew file+46
@@ -0,0 +1,46 @@
1+/*
2+ * Copyright (C) 2015-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 Ubuntu.Components 1.3
19+import AccountsService 0.1
20+import Wizard 0.1
21+import ".." as LocalComponents
22+
23+LocalComponents.Page {
24+ objectName: "welcomeUpdate"
25+ title: i18n.tr("Welcome to " + System.version)
26+
27+ forwardButtonSourceComponent: forwardButton
28+ onlyOnUpdate: true
29+
30+ Label {
31+ text: "This is where cool stuff would go"
32+ }
33+
34+ Component {
35+ id: forwardButton
36+ LocalComponents.StackButton {
37+ text: i18n.tr("Next")
38+ onClicked: {
39+ if (d.validName) {
40+ AccountsService.realName = d.validName;
41+ }
42+ pageStack.next();
43+ }
44+ }
45+ }
46+}
qml/Wizard/Pages/10-welcome.qml+1−2
@@ -27,8 +27,7 @@ LocalComponents.Page {
27
27
28 title: i18n.tr("Language")
28 title: i18n.tr("Language")
29 forwardButtonSourceComponent: forwardButton
29 forwardButtonSourceComponent: forwardButton
30−
30+ onlyOnInstall: true
31− showOnVersions: []
32
31
33 UbuntuLanguagePlugin {
32 UbuntuLanguagePlugin {
34 id: plugin
33 id: plugin
qml/Wizard/Pages/11-changelog.qml+1−2
@@ -24,8 +24,7 @@ LocalComponents.Page {
24 title: i18n.tr("What's new")
24 title: i18n.tr("What's new")
25
25
26 forwardButtonSourceComponent: forwardButton
26 forwardButtonSourceComponent: forwardButton
27−
27+ onlyOnUpdate: true
28− showOnVersions: []
29
28
30 Label {
29 Label {
31 text: "This is where cool stuff would go"
30 text: "This is where cool stuff would go"
qml/Wizard/Pages/30-wifi.qml+1−2
@@ -31,9 +31,8 @@ LocalComponents.Page {
31 title: i18n.tr("Connect to Wi‑Fi")
31 title: i18n.tr("Connect to Wi‑Fi")
32 forwardButtonSourceComponent: forwardButton
32 forwardButtonSourceComponent: forwardButton
33
33
34− showOnVersions: []
35−
36 readonly property bool connected: Connectivity.online
34 readonly property bool connected: Connectivity.online
35+ skip: connected
37
36
38 function getExtendedProperty(object, propertyName, defaultValue) {
37 function getExtendedProperty(object, propertyName, defaultValue) {
39 if (object && object.hasOwnProperty(propertyName)) {
38 if (object && object.hasOwnProperty(propertyName)) {
qml/Wizard/Pages/50-timezone.qml+1
@@ -36,6 +36,7 @@ LocalComponents.Page {
36
36
37 // for testing
37 // for testing
38 readonly property alias tdModule: timeDatePanel
38 readonly property alias tdModule: timeDatePanel
39+ onlyOnInstall: true
39
40
40 function highlightTimezone(offset) {
41 function highlightTimezone(offset) {
41 highlightImage.source = "data/timezonemap/timezone_" + offset + ".png";
42 highlightImage.source = "data/timezonemap/timezone_" + offset + ".png";
qml/Wizard/Pages/60-account.qml+1
@@ -24,6 +24,7 @@ LocalComponents.Page {
24 title: i18n.tr("Personalize Your Device")
24 title: i18n.tr("Personalize Your Device")
25
25
26 forwardButtonSourceComponent: forwardButton
26 forwardButtonSourceComponent: forwardButton
27+ onlyOnInstall: true
27
28
28 QtObject {
29 QtObject {
29 id: d
30 id: d
qml/Wizard/Pages/70-passwd-type.qml+1
@@ -44,6 +44,7 @@ LocalComponents.Page {
44 // or this isn't the first time the wizard has been run, etc). We can't
44 // or this isn't the first time the wizard has been run, etc). We can't
45 // properly set the password again, so let's not pretend we can.
45 // properly set the password again, so let's not pretend we can.
46 skip: securityPrivacy.securityType !== UbuntuSecurityPrivacyPanel.Swipe
46 skip: securityPrivacy.securityType !== UbuntuSecurityPrivacyPanel.Swipe
47+ onlyOnInstall: true
47
48
48 function indexToMethod(index) {
49 function indexToMethod(index) {
49 if (index === 0/* || index === 1*/)
50 if (index === 0/* || index === 1*/)
qml/Wizard/Pages/75-report-check.qml+1
@@ -27,6 +27,7 @@ LocalComponents.Page {
27 forwardButtonSourceComponent: !webview.visible ? forwardButton : null
27 forwardButtonSourceComponent: !webview.visible ? forwardButton : null
28 customBack: true
28 customBack: true
29 customTitle: webview.visible
29 customTitle: webview.visible
30+ onlyOnInstall: true
30
31
31 skip: !diagnostics.reportCrashes // skip the page when the system is configured not to report crashes
32 skip: !diagnostics.reportCrashes // skip the page when the system is configured not to report crashes
32
33
qml/Wizard/Pages/78-app-update.qml+1−1
@@ -42,7 +42,7 @@ LocalComponents.Page {
42 property bool online: NetworkingStatus.online
42 property bool online: NetworkingStatus.online
43 property bool authenticated: UpdateManager.authenticated
43 property bool authenticated: UpdateManager.authenticated
44
44
45− showOnVersions: [1]
45+ onlyOnUpdate: true
46
46
47 property int updatesCount: {
47 property int updatesCount: {
48 var count = 0;
48 var count = 0;
qml/Wizard/Pages/80-finished.qml+1−1
@@ -25,7 +25,7 @@ LocalComponents.Page {
25 customTitle: true
25 customTitle: true
26 lastPage: true
26 lastPage: true
27 buttonBarVisible: false
27 buttonBarVisible: false
28− showOnVersions: []
28+ onlyOnInstall: true
29
29
30 Component.onCompleted: {
30 Component.onCompleted: {
31 state = "reanchored";
31 state = "reanchored";
qml/Wizard/Wizard.qml+1−4
@@ -29,10 +29,7 @@ Showable {
29 // expected behavior of no emission on startup.
29 // expected behavior of no emission on startup.
30 readonly property bool active: loader.active
30 readonly property bool active: loader.active
31
31
32− // Hold the version of the wizard that is currently running. 0 means the
32+ property bool isUpdate: System.isUpdate
33− // first-run wizard, -1 means no wizard, a higher number signifies the
34− // wizard version that is running.
35− property int runningWizardVersion: System.versionToShow
36
33
37 // The wizard should be run at a later time if, for example, unity8 is
34 // The wizard should be run at a later time if, for example, unity8 is
38 // in greeter mode
35 // in greeter mode