on xenial help sign in
Add logic to check the versions that should be shown in the wizard
commit3356f489ffb61617a295aeec3e4bd1d0821770ac authorDalton Durst <me@daltondurst.com> dateMon 16 Jul 2018, 12:43 (8 years ago) parenteca88cb
2 files changed+75−2
plugins/Wizard/System.cpp+33−2 plugins/Wizard/System.h+42
plugins/Wizard/System.cpp+33−2
@@ -20,6 +20,7 @@
2020#include <QDBusMessage>
2121#include <QDBusConnection>
2222#include <QDBusMetaType>
23+#include <QVersionNumber>
2324#include <QDir>
2425#include <QFile>
2526#include <QLocale>
@@ -43,12 +44,42 @@ System::System()
4344QString System::wizardEnabledPath()
4445{
4546 // Uses ubuntu-system-settings namespace for historic compatibility reasons
46− return QDir::home().filePath(QStringLiteral(".config/ubuntu-system-settings/wizard-has-run"));
47+ return QDir::home().filePath(QStringLiteral(".config/ubuntu-system-settings/wizard-has-run/"));
4748}
4849
4950bool System::wizardEnabled() const
5051{
51− return !QFile::exists(wizardEnabledPath());
52+ // versionsToShow will only be empty if there are no missed wizard runs
53+ return (sizeof(this->versionsToShow()) != 0);
54+}
55+
56+std::vector<QVersionNumber> System::versionsToShow() const
57+{
58+ if (!QFile::exists(wizardEnabledPath())) {
59+ std::vector<QVersionNumber> versions = {QVersionNumber(0)};
60+ return versions;
61+ }
62+
63+ std::vector<QVersionNumber> missedVersions;
64+
65+ for(int i = 0; i < sizeof(wizardUpdates()); i++)
66+ {
67+ QVersionNumber versionToCheck = wizardUpdates()[i];
68+ QString pathToCheck = QDir(wizardEnabledPath()).filePath(versionToCheck.toString());
69+
70+ if (versionToCheck > currentVersion()) {
71+ continue;
72+ }
73+
74+ if (!QFile::exists(pathToCheck)) {
75+ continue;
76+ }
77+
78+ missedVersions.push_back(versionToCheck);
79+ }
80+
81+ return missedVersions;
82+
5283}
5384
5485void System::setWizardEnabled(bool enabled)
plugins/Wizard/System.h+42
@@ -18,6 +18,7 @@
1818#define WIZARD_SYSTEM_H
1919
2020#include <QFileSystemWatcher>
21+#include <QVersionNumber>
2122#include <QObject>
2223#include <QString>
2324
@@ -30,7 +31,48 @@ public:
3031 System();
3132 ~System() = default;
3233
34+ /**
35+ * Checks whether the wizard is enabled for first-run or otherwise
36+ */
3337 bool wizardEnabled() const;
38+
39+ /**
40+ * Returns the update version(s) that the wizard has not yet run for.
41+ * Will be empty if the current wizard version is the same version that has
42+ * already run or if the OOBE (first-time) wizard is set to run.
43+ * The special value [QVersionNumber(0)] denotes that the first-time setup
44+ * should run.
45+ * The special value [] denotes that the wizard should not be run.
46+ */
47+ std::vector<QVersionNumber> versionsToShow() const;
48+
49+ /**
50+ * Returns the possible update versions
51+ */
52+ std::vector<QVersionNumber> wizardUpdates() const
53+ {
54+ // Add a new QVersionNumber to this array for every new set of pages you
55+ // would like to add to the wizard. The wizard will check for every
56+ // version between its last run and its current version (::currentVersion())
57+ return {
58+ QVersionNumber(1, 0, 0)
59+ };
60+ }
61+
62+ /**
63+ * The update version for the Wizard in this version of Unity8. Bump this
64+ * version and add your new value to ::wizardUpdates(), then set the
65+ * showOnVersions property for the pages you would like to run on the current
66+ * update to the new value.
67+ */
68+ QVersionNumber currentVersion() const
69+ {
70+ return QVersionNumber(1, 0, 0);
71+ }
72+
73+ /**
74+ * Set that the OOBE (first-run) wizard should be run
75+ */
3476 void setWizardEnabled(bool enabled);
3577
3678public Q_SLOTS: