20 #include <QDBusPendingCall> 21 #include <QDBusMessage> 22 #include <QDBusConnection> 23 #include <QDBusMetaType> 36 qDBusRegisterMetaType<QMap<QString,QString>>();
38 if(!wizardEnabled()) {
39 m_fsWatcher.addPath(wizardEnabledPath());
41 connect(&m_fsWatcher, &QFileSystemWatcher::fileChanged,
this, &System::watcherFileChanged);
44 QString System::wizardEnabledPath()
47 return QDir::home().filePath(QStringLiteral(
".config/ubuntu-system-settings/wizard-has-run"));
50 QString System::currentFrameworkPath()
52 QFileInfo f(
"/usr/share/click/frameworks/current");
53 return f.canonicalFilePath();
64 bool System::wizardPathExists() {
65 return QFile::exists(wizardEnabledPath());
68 bool System::wizardEnabled()
const 70 if (!wizardPathExists()) {
76 QString System::readCurrentFramework()
78 QFile f(currentFrameworkPath());
79 if (!f.open(QFile::ReadOnly | QFile::Text))
return "";
84 QString System::readWizardEnabled()
86 QFile f(wizardEnabledPath());
87 if (!f.open(QFile::ReadOnly | QFile::Text))
return "";
92 QString System::version()
const 94 return readCurrentFramework();
97 bool System::isUpdate()
const 99 if (!wizardPathExists()) {
103 return readCurrentFramework() != readWizardEnabled();
106 void System::setWizardEnabled(
bool enabled)
108 if (wizardEnabled() == enabled && !isUpdate())
112 QFile::remove(wizardEnabledPath());
114 QDir(wizardEnabledPath()).mkpath(QStringLiteral(
".."));
115 if (QFile::exists(wizardEnabledPath())) {
116 QFile::remove(wizardEnabledPath());
119 if (QDir(wizardEnabledPath()).exists()) {
120 QDir(wizardEnabledPath()).removeRecursively();
122 if (!QFile::copy(currentFrameworkPath(), wizardEnabledPath())) {
124 QFile f(wizardEnabledPath());
125 f.open(QFile::WriteOnly);
127 m_fsWatcher.addPath(wizardEnabledPath());
128 Q_EMIT wizardEnabledChanged();
129 Q_EMIT isUpdateChanged();
133 void System::watcherFileChanged()
135 Q_EMIT wizardEnabledChanged();
136 Q_EMIT isUpdateChanged();
137 m_fsWatcher.removePath(wizardEnabledPath());
140 void System::setSessionVariable(
const QString &variable,
const QString &value)
143 QProcess::startDetached(QStringLiteral(
"initctl set-env --global %1=%2").arg(variable, value));
145 QMap<QString,QString> valueMap;
146 valueMap.insert(variable, value);
148 QDBusMessage msg = QDBusMessage::createMethodCall(QStringLiteral(
"org.freedesktop.DBus"),
149 QStringLiteral(
"/org/freedesktop/DBus"),
150 QStringLiteral(
"org.freedesktop.DBus"),
151 QStringLiteral(
"UpdateActivationEnvironment"));
153 msg << QVariant::fromValue(valueMap);
154 QDBusConnection::sessionBus().asyncCall(msg);
157 void System::updateSessionLocale(
const QString &locale)
159 const QString language = locale.split(QStringLiteral(
"."))[0];
161 setSessionVariable(QStringLiteral(
"LANGUAGE"), language);
162 setSessionVariable(QStringLiteral(
"LANG"), locale);
163 setSessionVariable(QStringLiteral(
"LC_ALL"), locale);
167 QLocale::setDefault(QLocale(locale));
170 QProcess::startDetached(QStringLiteral(
"sh -c \"initctl emit indicator-services-end; \ 171 initctl emit --no-wait indicator-services-start; \ 172 initctl restart --no-wait ubuntu-location-service-trust-stored; \ 173 initctl restart --no-wait maliit-server; \ 174 initctl restart --no-wait indicator-messages"));
177 void System::skipUntilFinishedPage()
180 settings.setValue(QStringLiteral(
"Wizard/SkipUntilFinishedPage"),
true);