@@ -20,7 +20,6 @@
2020#include <QDBusMessage>
2121#include <QDBusConnection>
2222#include <QDBusMetaType>
23−#include <QVersionNumber>
2423#include <QDir>
2524#include <QFile>
2625#include <QLocale>
@@ -44,53 +43,78 @@ System::System()
4443QString System::wizardEnabledPath()
4544{
4645 // 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"));
4847}
4948
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+
5062bool System::wizardEnabled() const
5163{
52− return (versionToShow() >= 0);
64+ return !QFile::exists(wizardEnabledPath());
5365}
5466
55−signed int System::versionToShow() const
67+QString System::readCurrentFramework()
5668{
57− if (!(QFile::exists(wizardEnabledPath()))) {
58− return 0;
59− }
69+ QFile f(currentFrameworkPath());
70+ if (!f.open(QFile::ReadOnly | QFile::Text)) return "";
71+ QTextStream in(&f);
72+ return in.readAll();
73+}
6074
61− QString pathToCheck = QDir(wizardEnabledPath()).filePath(QString::number(CURRENT_VERSION));
62−
63− if (!(QFile::exists(pathToCheck))) {
64− return CURRENT_VERSION;
65− }
75+QString System::readWizardEnabled()
76+{
77+ QFile f(wizardEnabledPath());
78+ if (!f.open(QFile::ReadOnly | QFile::Text)) return "";
79+ QTextStream in(&f);
80+ return in.readAll();
81+}
6682
67− return -1;
68−
83+QString System::version() const
84+{
85+ return readCurrentFramework();
86+}
87+
88+bool System::isUpdate() const
89+{
90+ if (!wizardEnabled())
91+ return false;
92+
93+ return readCurrentFramework() != readWizardEnabled();
6994}
7095
7196void System::setWizardEnabled(bool enabled)
7297{
73− if (wizardEnabled() == enabled)
98+ if (wizardEnabled() == enabled && !isUpdate())
7499 return;
75100
76101 if (enabled) {
77− QDir(wizardEnabledPath()).removeRecursively();
102+ QFile::remove(wizardEnabledPath());
78103 } 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());
80108 m_fsWatcher.addPath(wizardEnabledPath());
81−
82− // Disable the newest non-first-run wizard, too
83− QFile(QDir(wizardEnabledPath()).filePath(QString::number(CURRENT_VERSION))).open(QIODevice::WriteOnly);
109+ Q_EMIT wizardEnabledChanged();
110+ Q_EMIT isUpdateChanged();
84111 }
85−
86− Q_EMIT wizardEnabledChanged();
87− Q_EMIT versionToShowChanged();
88112}
89113
90114void System::watcherFileChanged()
91115{
92116 Q_EMIT wizardEnabledChanged();
93− Q_EMIT versionToShowChanged();
117+ Q_EMIT isUpdateChanged();
94118 m_fsWatcher.removePath(wizardEnabledPath());
95119}
96120